Skip to content

feat(openrouter-typescript-sdk): add manual tools, approval flows, and streaming docs#7

Open
mattapperson wants to merge 10 commits intomainfrom
add-manual-tool-approval-flows
Open

feat(openrouter-typescript-sdk): add manual tools, approval flows, and streaming docs#7
mattapperson wants to merge 10 commits intomainfrom
add-manual-tool-approval-flows

Conversation

@mattapperson
Copy link
Copy Markdown
Contributor

Summary

  • Manual Tool Execution: New section documenting the full lifecycle of manual tools (execute: false) — specifically for human-in-the-loop flows where a person produces the tool call result
  • Approval Flows: New section documenting the built-in SDK approval system (requireApproval, state, approveToolCalls/rejectToolCalls) as a separate mechanism from manual tools
  • Cumulative Streams: Document getItemsStream() and getNewMessagesStream() as cumulative snapshot streams (not deltas), with isComplete flag and healed arguments/rawArguments fields per OpenRouterTeam/openrouter-web#16475
  • isComplete flag: All items from both cumulative streams carry isComplete: booleanfalse while streaming, true on final emission
  • arguments/rawArguments: function_call items in getItemsStream() expose arguments (healed parsed object, always safe) and rawArguments (raw accumulated JSON string)

Test plan

  • Read through SKILL.md and verify manual tools section does NOT reference approval flows
  • Verify approval flows section uses requireApproval and state, not execute: false
  • Verify cumulative streams section correctly documents isComplete and arguments/rawArguments
  • Verify all code examples are consistent with the documented types
  • Verify no broken markdown anchor links

… section

Document the critical behavior that when a manual tool (execute: false) is
called during a multi-turn callModel invocation, the SDK stops the loop and
returns with the model's tool-call response in finalResponse.output. Includes
patterns for approval flows, streaming detection, resuming after approval,
and mixing manual with automatic tools.
…lows

The previous commit incorrectly conflated manual tools with approval flows.
These are two distinct SDK features:

- Manual tools (execute: false): loop exits, developer handles execution
  externally, passes results back via function_call_output on next call
- Approval flows (requireApproval): built-in SDK feature where the loop
  pauses to 'awaiting_approval' status, developer provides approveToolCalls
  or rejectToolCalls on next call, state persisted via StateAccessor

Rewrites the Manual Tools subsection, replaces the combined section with
separate "Manual Tool Execution" and "Approval Flows" sections covering
the full lifecycle of each.
… emission

Add section explaining that function_call items in getItemsStream() are
emitted cumulatively — the same tool call is yielded multiple times with
progressively longer arguments. JSON.parse always succeeds because callModel
heals partial JSON in arguments and structured results.
…mulative

getNewMessagesStream() yields cumulative message snapshots, not deltas.
Each message event contains the full text up to that point. Updated the
section heading, description, and example to make this clear and warn
against appending content across events.
Merge the getNewMessagesStream() and getItemsStream() sections under a
shared "Cumulative Streams" heading. Both yield cumulative snapshots (not
deltas) — the same item is emitted multiple times as it grows. Consistent
framing, shared warning about replacing vs appending, and contrast with
delta-based streams.
…rom PR #16475

Update cumulative streams docs to match the implementation in
OpenRouterTeam/openrouter-web#16475:

- isComplete flag on all items from getItemsStream() and
  getNewMessagesStream() (false while streaming, true on final emission)
- parsedArguments on function_call items in getItemsStream() — best-effort
  parsed object from healed JSON via healJson() utility
- WithCompletion<T> type wrapper
- StreamingFunctionCallItem type with parsedArguments field
- Updated type signatures, examples, and response methods table
Rename streaming function_call fields so the healed parsed object is
the primary 'arguments' field and the raw accumulated JSON string is
'rawArguments'. This makes the common case (accessing parsed args)
the default, with the raw string available when needed.
…-the-loop only

Manual tools (execute: false) are specifically for flows where a human
produces the tool call result. Updated descriptions, examples, and
contrast with approval flows throughout. Replaced programmatic examples
(db queries, deploys) with human-in-the-loop examples (asking the user
questions, collecting preferences).
…flows

Remove misleading cross-references suggesting approval flows as an
alternative to manual tools. These are separate, independent mechanisms.
…ences/

Move detailed authentication (OAuth, key management) and type/event shape
definitions to references/ files per progressive disclosure principle.
SKILL.md retains core procedural knowledge and behavioral docs (cumulative
streams, manual tools, approval flows). Reduces SKILL.md from 1575 to 1045
lines.

New files:
- references/authentication.md — OAuth flow, key management, security
- references/types-and-events.md — message shapes, event interfaces,
  stream types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant