Repository navigation
feat: TS streaming — stream let emits rt.llmStream - #29
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18ca983ccb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const prefix = model && model.includes(":") ? model.split(":")[0] : null; | ||
| if ((process.env.NUDGE_PROVIDER && process.env.NUDGE_PROVIDER !== "fake") || | ||
| (prefix && ["openai", "gemini", "groq", "mimo", "mistral", "anthropic", "ollama"].includes(prefix))) { |
There was a problem hiding this comment.
Honor the explicit fake-provider override
When NUDGE_PROVIDER=fake is set and the model has a recognized prefix such as anthropic:..., the first condition is false but the prefix condition still throws, so deterministic fake streaming cannot run with the same realistic model names used by generated programs. The explicit fake setting should suppress prefix-based real-provider detection, as it does in the Python runtime.
Useful? React with 👍 / 👎.
| format!("const {name} = {}; // warning: streaming not yet supported by the TS backend — plain call", ts(value, aliases, sigs)) | ||
| // the TS runtime now streams (fake parity): swap the | ||
| // emitted llmCall for llmStream — same opts shape | ||
| let call = ts(value, aliases, sigs).replacen("rt.llmCall(", "rt.llmStream(", 1); |
There was a problem hiding this comment.
Only rewrite a direct streamed LLM call
When a non-LLM stream let expression contains a nested LLM call, such as stream let x = (llm"""...""" with {...}) + "suffix", this string replacement converts that nested call to llmStream. The language permits non-LLM streamed bindings and defines them to degrade to a plain binding, so codegen should pattern-match Expr::LlmCall as the Python backend does rather than replacing the first emitted call anywhere in the expression.
Useful? React with 👍 / 👎.
| const text = sch ? JSON.stringify(out) : String(out); | ||
| const chunks = text.length === 0 ? 1 : Math.ceil(text.length / chunkSize); |
There was a problem hiding this comment.
Match Python JSON serialization when counting chunks
For schema-backed streams, JSON.stringify uses compact separators while Python's json.dumps inserts spaces, so the recorded chunk count is not actually deterministic across backends. For example, {a: true, b: true, c: true} serializes to 28 UTF-16 units here (2 chunks) but 33 characters in Python (3 chunks), causing otherwise equivalent fake runs to produce different chunks trace data.
Useful? React with 👍 / 👎.
What
TS parity step:
stream letno longer degrades to a plain call with a warning — the TS runtime gainsllmStreamand codegen emits it.llm_stream: deterministic 14-char chunking, additivestreamed/chunkstrace fields, replay consumes the recorded value (§6.2), branch labels compose with par lanesllmStreamrecognizes all seven provider prefixesTest
Node e2e: schema stream chunks == ceil(JSON length / 14) exactly as Python computes; string stream same; trace records carry
streamed: true✓