Every streaming loop reads `chunk.choices[0]` directly, which throws a
TypeError before any of the existing guards run when a provider emits a
chunk without a `choices` array:
TypeError: undefined is not an object (evaluating 'e.choices[0]')
The existing optional chaining does not help because it sits after the
index: `chunk.choices[0]?.delta` still throws when `choices` is absent.
In agent runtime the `if (!choice) continue` guard is likewise
unreachable for this case.
Move the optional chaining before the index so the guards that already
exist can do their job. No behavior change on well-formed chunks.
Claude-Session: https://claude.ai/code/session_013rsgamahFqrfNUZqAHceG1
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
`legacyInputSchema()` copies a tool parameter's `type` straight into the
generated JSON Schema, so an array parameter is emitted as a bare
`{ "type": "array" }` with no `items`.
`items` is required alongside `type: "array"`, and some providers reject
it rather than ignoring it. Against a local LM Studio server every agent
request fails, because the model's chat template cannot render the tool
list:
Engine protocol predict request returned 500:
While executing If at line 12, column 13 in source:
...am_spec.type == "array" -%}
{%- if param_spec['items'] -%}
Error: Function is not a bool value
The template tests `param_spec['items']`; with the key absent that
resolves to the mapping's `items` method rather than a value, which is
not a bool, so the request 500s before generation starts.
At least 19 tool parameters declare `type: 'array'`, so the agent is
effectively unusable with any provider strict about this.
`ToolParameter` carries no item type, so fall back to a permissive `{}`
rather than guessing `string` — several of these arrays hold objects.
Claude-Session: https://claude.ai/code/session_013rsgamahFqrfNUZqAHceG1
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>