Skip to content

Commit 6ac899b

Browse files
committed
stopWhen and regen sdk
1 parent 457f93b commit 6ac899b

File tree

293 files changed

+11087
-9349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

293 files changed

+11087
-9349
lines changed

.speakeasy/gen.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ management:
55
docVersion: 1.0.0
66
speakeasyVersion: 1.680.0
77
generationVersion: 2.788.4
8-
releaseVersion: 0.3.7
9-
configChecksum: 307fbb413f183f19cd9e45ff5e5a2212
8+
releaseVersion: 0.3.9
9+
configChecksum: 5d797923e4d4578f0ee560b2fe7abc13
1010
repoURL: https://github.com/OpenRouterTeam/typescript-sdk.git
1111
installationURL: https://github.com/OpenRouterTeam/typescript-sdk
1212
published: true
1313
persistentEdits:
14-
generation_id: 89ff75fc-55b0-4eb8-ad25-82572b9903a7
15-
pristine_commit_hash: 64d8d07c464614eda10ab00c5d6a1c1d25c943e3
16-
pristine_tree_hash: ffaecc36e84561dcf0fb0693f6a4a2318da99e0c
14+
generation_id: 588e1986-8f23-4d80-bc1c-5bcd6070be37
15+
pristine_commit_hash: 3c4d1945159ff0fb5582484d3b5d9708bc66c184
16+
pristine_tree_hash: 36ed457ade0bb24e476d3639393e2fcd24b7e9f1
1717
features:
1818
typescript:
1919
acceptHeaders: 2.81.2
@@ -1960,12 +1960,12 @@ trackedFiles:
19601960
pristine_git_object: 410efafd6a7f50d91ccb87131fedbe0c3d47e15a
19611961
jsr.json:
19621962
id: 7f6ab7767282
1963-
last_write_checksum: sha1:86b61d7f53f41cc886e34272588043abc42ce372
1964-
pristine_git_object: 33a0a439a9e1692e39a89709ac03b89f25c13f30
1963+
last_write_checksum: sha1:059fd6564be5fc2274b6382fb3e9fc66b3d68c35
1964+
pristine_git_object: a4cfcee0b2bf3d8719d6832a232eb73cbeac17f0
19651965
package.json:
19661966
id: 7030d0b2f71b
1967-
last_write_checksum: sha1:72caad1939114ecb1c01391384b6fb11e52fc19b
1968-
pristine_git_object: ac2454d305ef0d146cbf7a82ee529fe3d94af8c8
1967+
last_write_checksum: sha1:d2126878c2ecc0292dbc33d388f204ecbe6c0656
1968+
pristine_git_object: 3ff44250b668ba6980c04fc2cf5156a540233fa6
19691969
src/core.ts:
19701970
id: f431fdbcd144
19711971
last_write_checksum: sha1:5aa66b0b6a5964f3eea7f3098c2eb3c0ee9c0131
@@ -2088,8 +2088,8 @@ trackedFiles:
20882088
pristine_git_object: a187e58707bdb726ca2aff74941efe7493422d4e
20892089
src/lib/config.ts:
20902090
id: 320761608fb3
2091-
last_write_checksum: sha1:3e3d67911460cf995c91cbe540ff9de9d91ae3e0
2092-
pristine_git_object: 19e037b620a9f45fd4d3fab34a0ec04f2f384b9d
2091+
last_write_checksum: sha1:a34860d9d0346a22407061b1bba9c0a01c03f00f
2092+
pristine_git_object: fd407fc9bb4c55f8ccca09f37d27bb0e5d750532
20932093
src/lib/dlv.ts:
20942094
id: b1988214835a
20952095
last_write_checksum: sha1:eaac763b22717206a6199104e0403ed17a4e2711
@@ -2980,8 +2980,8 @@ trackedFiles:
29802980
pristine_git_object: bb38b40427200e0d63b8e5b59c7b557239ac5102
29812981
src/sdk/oauth.ts:
29822982
id: 37b7f9b2970b
2983-
last_write_checksum: sha1:9066fa7baf0b904ca1aa96b654fbc79b3d6c3236
2984-
pristine_git_object: 12f35868fad83b3b6ce20fa340d2d9f8df7bbbd1
2983+
last_write_checksum: sha1:6bb4e2c2cc93c3a091cf07bb520071417cfc4184
2984+
pristine_git_object: 726510b58fe85770461429146121e8aef773b740
29852985
src/sdk/parameters.ts:
29862986
id: 6e4ef00c29b7
29872987
last_write_checksum: sha1:7e24ad2dfe41aa7a22db6db309466433ddf8ebdb
@@ -2996,8 +2996,8 @@ trackedFiles:
29962996
pristine_git_object: fc8f29b98cfb1a5aaf4e79aa4bf6572f0ca41e53
29972997
src/sdk/sdk.ts:
29982998
id: 784571af2f69
2999-
last_write_checksum: sha1:bcdd07970af60b24f60bc596fb20d3c0dbddb31d
3000-
pristine_git_object: ec947c79916d4fb0e88b9c257b1941c6b19388cc
2999+
last_write_checksum: sha1:8665c476ce15fd94c6fd07e4c6b163a7c7619387
3000+
pristine_git_object: 7b1a640d06c0edb9bcab25af3414668259c91c3b
30013001
src/types/async.ts:
30023002
id: fac8da972f86
30033003
last_write_checksum: sha1:e2a7c53b428567587741f38e6da489f596de6227

.speakeasy/gen.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ generation:
3333
skipResponseBodyAssertions: false
3434
preApplyUnionDiscriminators: true
3535
typescript:
36-
version: 0.3.7
36+
version: 0.3.9
3737
acceptHeaderEnum: false
3838
additionalDependencies:
3939
dependencies: {}

examples/callModel-typed-tool-calling.example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async function main() {
9898
model: "openai/gpt-4o-mini",
9999
input: "What's the weather like in Paris?",
100100
tools: [weatherTool] as const,
101-
maxToolRounds: 0, // Don't auto-execute, just get the tool calls
101+
stopWhen: 0, // Don't auto-execute, just get the tool calls
102102
});
103103

104104
// Tool calls are now typed based on the tool definitions!
@@ -117,7 +117,7 @@ async function main() {
117117
model: "openai/gpt-4o-mini",
118118
input: "What's the weather in Tokyo?",
119119
tools: [weatherTool] as const,
120-
maxToolRounds: 0,
120+
stopWhen: 0,
121121
});
122122

123123
// Stream tool calls with typed arguments

examples/tools-example.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
* 1. Validated using Zod schemas
77
* 2. Executed when the model calls them
88
* 3. Results sent back to the model
9-
* 4. Process repeats until no more tool calls (up to maxToolRounds)
9+
* 4. Process repeats until no more tool calls (up to stopWhen)
1010
*
1111
* The API is simple: just call callModel() with tools, and await the result.
1212
* Tools are executed transparently before getMessage() or getText() returns!
1313
*
14-
* maxToolRounds can be:
15-
* - A number: Maximum number of tool execution rounds (default: 5)
16-
* - A function: (context: TurnContext) => boolean
17-
* - Return true to allow another turn
18-
* - Return false to stop execution
19-
* - Context includes: numberOfTurns, messageHistory, model/models
14+
* stopWhen options:
15+
* - A StopCondition function: ({ steps }) => boolean
16+
* - Return true to STOP execution
17+
* - Return false to CONTINUE execution
18+
* - Helper functions: stepCountIs(n), hasToolCall(name), maxTokensUsed(n), maxCost(n)
19+
* - An array of conditions (OR logic - stops if ANY condition returns true)
20+
* - Default: stepCountIs(5) - stops after 5 steps
2021
*/
2122

2223
import * as dotenv from 'dotenv';
2324
import { z } from 'zod/v4';
24-
import { OpenRouter, ToolType } from '../src/index.js';
25+
import { OpenRouter, stepCountIs, ToolType } from '../src/index.js';
2526

2627
// Type declaration for ShadowRealm (TC39 Stage 3 proposal)
2728
// See: https://tc39.es/proposal-shadowrealm/
@@ -75,13 +76,9 @@ async function basicToolExample() {
7576
const response = client.callModel({
7677
model: 'openai/gpt-4o',
7778
input: "What's the weather like in San Francisco?",
78-
tools: [
79-
weatherTool,
80-
],
81-
// Example: limit to 3 turns using a function
82-
maxToolRounds: (context) => {
83-
return context.numberOfTurns < 3; // Allow up to 3 turns
84-
},
79+
tools: [weatherTool],
80+
// Example: limit to 3 steps using helper function
81+
stopWhen: stepCountIs(3), // Stop after 3 steps
8582
});
8683

8784
// Tools are automatically executed! Just get the final message
@@ -249,7 +246,7 @@ async function manualToolExample() {
249246
// Safely evaluate the math expression using ShadowRealm
250247
try {
251248
const _result = safeEvaluateMath(expression);
252-
} catch (_error) {}
249+
} catch (_error) { }
253250
}
254251
}
255252

@@ -375,7 +372,7 @@ async function main() {
375372
await manualToolExample();
376373
await streamingToolCallsExample();
377374
await multipleToolsExample();
378-
} catch (_error) {}
375+
} catch (_error) { }
379376
}
380377

381378
// Only run if this file is executed directly

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{
44
"name": "@openrouter/sdk",
5-
"version": "0.3.7",
5+
"version": "0.3.9",
66
"exports": {
77
".": "./src/index.ts",
88
"./models/errors": "./src/models/errors/index.ts",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openrouter/sdk",
3-
"version": "0.3.7",
3+
"version": "0.3.9",
44
"author": "OpenRouter",
55
"description": "The OpenRouter TypeScript SDK is a type-safe toolkit for building AI applications with access to 300+ language models through a unified API.",
66
"keywords": [

src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @generated-id: f431fdbcd144
44
*/
55

6-
import { ClientSDK } from "./lib/sdks.js";
6+
import { ClientSDK } from './lib/sdks.js';
77

88
/**
99
* A minimal client to use when calling standalone SDK functions. Typically, an

0 commit comments

Comments
 (0)