@namzu/sdk 64.3.0 → 65.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/advisory/executor.d.ts +2 -1
- package/dist/advisory/executor.d.ts.map +1 -1
- package/dist/advisory/executor.js +8 -2
- package/dist/advisory/executor.js.map +1 -1
- package/dist/agents/explore.js +1 -1
- package/dist/agents/explore.js.map +1 -1
- package/dist/agents/plan.js +1 -1
- package/dist/agents/plan.js.map +1 -1
- package/dist/compaction/context-window.d.ts.map +1 -1
- package/dist/compaction/context-window.js +9 -2
- package/dist/compaction/context-window.js.map +1 -1
- package/dist/eval/judge.d.ts.map +1 -1
- package/dist/eval/judge.js +6 -2
- package/dist/eval/judge.js.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts +1 -0
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +20 -6
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +11 -2
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +2 -2
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +39 -38
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +4 -3
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.js +1 -1
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/instrumentation.js +1 -1
- package/dist/provider/instrumentation.js.map +1 -1
- package/dist/provider/retry.js +1 -1
- package/dist/provider/retry.js.map +1 -1
- package/dist/provider/side-request-reasoning.d.ts +32 -0
- package/dist/provider/side-request-reasoning.d.ts.map +1 -0
- package/dist/provider/side-request-reasoning.js +97 -0
- package/dist/provider/side-request-reasoning.js.map +1 -0
- package/dist/public-runtime.d.ts +3 -1
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +2 -1
- package/dist/public-runtime.js.map +1 -1
- package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/classifier.js +8 -2
- package/dist/runtime/query/auto-review/classifier.js.map +1 -1
- package/dist/runtime/query/callback-inference.d.ts.map +1 -1
- package/dist/runtime/query/callback-inference.js +14 -3
- package/dist/runtime/query/callback-inference.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +17 -0
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +82 -10
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
- package/dist/runtime/query/prepare-turn.js +3 -0
- package/dist/runtime/query/prepare-turn.js.map +1 -1
- package/dist/runtime/query/repeat-call.js +2 -2
- package/dist/runtime/query/repeat-call.js.map +1 -1
- package/dist/runtime/query/turn/stall-monitor.d.ts +47 -2
- package/dist/runtime/query/turn/stall-monitor.d.ts.map +1 -1
- package/dist/runtime/query/turn/stall-monitor.js +72 -4
- package/dist/runtime/query/turn/stall-monitor.js.map +1 -1
- package/dist/turn/evidence-query.d.ts.map +1 -1
- package/dist/turn/evidence-query.js +7 -1
- package/dist/turn/evidence-query.js.map +1 -1
- package/dist/types/common/index.d.ts +14 -0
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/common/index.js +7 -0
- package/dist/types/common/index.js.map +1 -1
- package/dist/types/provider/config.d.ts +6 -0
- package/dist/types/provider/config.d.ts.map +1 -1
- package/dist/types/provider/interface.d.ts +8 -6
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/session/prepare-step.d.ts +7 -0
- package/dist/types/session/prepare-step.d.ts.map +1 -1
- package/dist/utils/cost.d.ts +14 -0
- package/dist/utils/cost.d.ts.map +1 -1
- package/dist/utils/cost.js +20 -0
- package/dist/utils/cost.js.map +1 -1
- package/package.json +1 -1
- package/src/advisory/executor.ts +13 -2
- package/src/agents/explore.ts +1 -1
- package/src/agents/plan.ts +1 -1
- package/src/compaction/context-window.ts +9 -2
- package/src/eval/judge.ts +16 -9
- package/src/manager/agent/lifecycle.ts +19 -6
- package/src/manager/session/turn-recorder.ts +12 -1
- package/src/prompt/coding-agent-doctrine.ts +40 -39
- package/src/provider/fallback.ts +4 -3
- package/src/provider/idle-timeout.ts +1 -1
- package/src/provider/instrumentation.ts +1 -1
- package/src/provider/retry.ts +1 -1
- package/src/provider/side-request-reasoning.ts +121 -0
- package/src/public-runtime.ts +7 -0
- package/src/runtime/query/auto-review/classifier.ts +17 -9
- package/src/runtime/query/callback-inference.ts +13 -3
- package/src/runtime/query/iteration/index.ts +93 -12
- package/src/runtime/query/prepare-turn.ts +2 -0
- package/src/runtime/query/repeat-call.ts +2 -2
- package/src/runtime/query/turn/stall-monitor.ts +92 -4
- package/src/turn/evidence-query.ts +8 -1
- package/src/types/common/index.ts +22 -0
- package/src/types/provider/config.ts +6 -0
- package/src/types/provider/interface.ts +8 -6
- package/src/types/session/prepare-step.ts +7 -0
- package/src/utils/cost.ts +24 -0
|
@@ -167,15 +167,17 @@ export interface LLMProvider {
|
|
|
167
167
|
* Whether `model` takes a forced tool choice (`toolChoice: 'required'` or a
|
|
168
168
|
* named function) under the thinking configuration the request will carry.
|
|
169
169
|
*
|
|
170
|
-
* The kernel asks before
|
|
171
|
-
* and when the answer is `
|
|
172
|
-
*
|
|
170
|
+
* The kernel asks before a guard requires a tool call on a step it wants to
|
|
171
|
+
* act, and sends a forced choice only when the answer is `true` and the
|
|
172
|
+
* request does not turn thinking on. Otherwise it keeps the step at low effort
|
|
173
|
+
* and asks the model in words. `effort`
|
|
173
174
|
* is the level the request will carry, for a driver where the level also
|
|
174
175
|
* decides whether thinking is on (a provider that does not need it ignores
|
|
175
176
|
* it). Optional:
|
|
176
|
-
* a provider that does not declare it is
|
|
177
|
-
*
|
|
178
|
-
* forwards it
|
|
177
|
+
* a provider that does not declare it is not sent a guard's forced choice (the
|
|
178
|
+
* words are used). A host's own `toolChoice` is sent as given. A wrapper that
|
|
179
|
+
* rebuilds a provider forwards it; a chain answers `true` only when every
|
|
180
|
+
* member does.
|
|
179
181
|
*/
|
|
180
182
|
acceptsForcedToolChoiceFor?(model: string, thinking?: import('./chat.js').ThinkingConfig, effort?: import('./chat.js').ReasoningEffort): boolean;
|
|
181
183
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/types/provider/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;;;;OAOG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,oBAAoB,CAAA;IAE5C,kGAAkG;IAClG,0BAA0B,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;IAE5E;;;;;;;;;;OAUG;IACH,qBAAqB,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;IAE9C;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,OAAO,yBAAyB,EAAE,mBAAmB,CAAC,CAAA;IAEvF;;;;;;;;;;;;;;OAcG;IACH,UAAU,CAAC,M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EAAE,OAAO,WAAW,EAAE,cAAc,EAC7C,MAAM,CAAC,EAAE,OAAO,WAAW,EAAE,eAAe,GAC1C,OAAO,CAAA;IAEV;;;;;;;;;;;;OAYG;IACH,yBAAyB,CAAC,CACzB,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,OAAO,WAAW,EAAE,cAAc,GAC3C,OAAO,WAAW,EAAE,eAAe,GAAG,SAAS,CAAA;IAElD;;;;;;OAMG;IACH,eAAe,CAAC,CACf,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,OAAO,WAAW,EAAE,cAAc,GAC3C,SAAS,OAAO,WAAW,EAAE,eAAe,EAAE,CAAA;IAEjD;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,oBAAoB,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAEvF;;;;;;;;;;;;;OAaG;IACH,kBAAkB,CAAC,CAClB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,WAAW,EAAE,eAAe,EAC5C,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;CAC9B"}
|
|
@@ -31,6 +31,13 @@ export interface PreparationTextResult {
|
|
|
31
31
|
readonly text: string;
|
|
32
32
|
readonly usage: TokenUsage;
|
|
33
33
|
readonly servedBy: StepProvenance;
|
|
34
|
+
/**
|
|
35
|
+
* Why the provider stopped. `'length'` means the answer allowance ran out,
|
|
36
|
+
* which on a reasoning model can leave `text` empty or cut off mid-way; a
|
|
37
|
+
* caller that needs complete text treats it as no answer. Absent when the
|
|
38
|
+
* provider reported none.
|
|
39
|
+
*/
|
|
40
|
+
readonly finishReason?: 'stop' | 'tool_calls' | 'length' | 'content_filter';
|
|
34
41
|
}
|
|
35
42
|
/**
|
|
36
43
|
* What the loop knows before it calls the model again.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare-step.d.ts","sourceRoot":"","sources":["../../../src/types/session/prepare-step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE/C,0FAA0F;AAC1F,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,gFAAgF;IAChF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAC7B;AAED,kFAAkF;AAClF,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;IAC1B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"prepare-step.d.ts","sourceRoot":"","sources":["../../../src/types/session/prepare-step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,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W,QAAQ;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,UAAU,GAAG,CACxB,OAAO,EAAE,kBAAkB,KACvB,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;AAEzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,SAAS,WAAW,EAAE,CAAA"}
|
package/dist/utils/cost.d.ts
CHANGED
|
@@ -68,6 +68,20 @@ export declare function accumulateCost(current: CostInfo, additionalUsage: Token
|
|
|
68
68
|
* not described by any single card.
|
|
69
69
|
*/
|
|
70
70
|
export declare function accumulateUnpricedCost(current: CostInfo, additionalUsage: TokenUsage): CostInfo;
|
|
71
|
+
/**
|
|
72
|
+
* Record a call whose cost the provider reported.
|
|
73
|
+
*
|
|
74
|
+
* The vendor's figure is what the account was charged, so it wins over a rate
|
|
75
|
+
* card: a card is an estimate of one model at one list price, while the report
|
|
76
|
+
* already includes the route that served the call, the cache discount and any
|
|
77
|
+
* tier. The rate fields go, as for unpriced tokens: no single card describes
|
|
78
|
+
* a total that holds a reported figure.
|
|
79
|
+
*/
|
|
80
|
+
export declare function accumulateReportedCost(current: CostInfo, reportedCostUsd: number): CostInfo;
|
|
81
|
+
/** Whether a usage frame carries a usable vendor-reported cost. */
|
|
82
|
+
export declare function hasReportedCost(usage: TokenUsage): usage is TokenUsage & {
|
|
83
|
+
reportedCostUsd: number;
|
|
84
|
+
};
|
|
71
85
|
export declare function formatCost(usd: number): string;
|
|
72
86
|
/**
|
|
73
87
|
* How a total should be shown, given what is and is not known about it.
|
package/dist/utils/cost.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../src/utils/cost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAw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CAMnD"}
|
package/dist/utils/cost.js
CHANGED
|
@@ -151,6 +151,26 @@ export function accumulateUnpricedCost(current, additionalUsage) {
|
|
|
151
151
|
unpricedTokens: current.unpricedTokens + additionalUsage.totalTokens,
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Record a call whose cost the provider reported.
|
|
156
|
+
*
|
|
157
|
+
* The vendor's figure is what the account was charged, so it wins over a rate
|
|
158
|
+
* card: a card is an estimate of one model at one list price, while the report
|
|
159
|
+
* already includes the route that served the call, the cache discount and any
|
|
160
|
+
* tier. The rate fields go, as for unpriced tokens: no single card describes
|
|
161
|
+
* a total that holds a reported figure.
|
|
162
|
+
*/
|
|
163
|
+
export function accumulateReportedCost(current, reportedCostUsd) {
|
|
164
|
+
return {
|
|
165
|
+
totalCost: current.totalCost + reportedCostUsd,
|
|
166
|
+
cacheDiscount: current.cacheDiscount,
|
|
167
|
+
unpricedTokens: current.unpricedTokens,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/** Whether a usage frame carries a usable vendor-reported cost. */
|
|
171
|
+
export function hasReportedCost(usage) {
|
|
172
|
+
return Number.isFinite(usage.reportedCostUsd) && usage.reportedCostUsd >= 0;
|
|
173
|
+
}
|
|
154
174
|
export function formatCost(usd) {
|
|
155
175
|
if (usd === 0)
|
|
156
176
|
return '$0.00';
|
package/dist/utils/cost.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost.js","sourceRoot":"","sources":["../../src/utils/cost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AA0DlD,OAAO,EAAE,SAAS,EAAE,CAAA;AAUpB,SAAS,UAAU,CAAC,KAAiB,EAAE,OAAqB;IAC3D,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC1C,MAAM,QAAQ,GAAG,KAAK,CAAC,iBAAiB,IAAI,CAAC,CA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,eAAe;QAC9C,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,cAAc,EAAE,OAAO,CAAC,cAAc;KACtC,CAAA;AACF,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,eAAe,CAC9B,KAAiB;IAEjB,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,IAAK,KAAK,CAAC,eAA0B,IAAI,CAAC,CAAA;AACxF,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAW;IACrC,IAAI,GAAG,KAAK,CAAC;QAAE,OAAO,OAAO,CAAA;IAC7B,IAAI,GAAG,GAAG,IAAI;QAAE,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAA;IAC3C,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAA;AAC5B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,IAAc;IAC1C,IAAI,IAAI,CAAC,cAAc,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAChE,IAAI,IAAI,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,YAAY,IAAI,CAAC,cAAc,2BAA2B,CAAA;IAClE,CAAC;IACD,OAAO,YAAY,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,cAAc,2BAA2B,CAAA;AACjG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namzu/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "65.0.0",
|
|
4
4
|
"description": "Open-source AI kernel for TypeScript: runs an agent the way an operating system runs a process, with an identity and a budget, scheduled tool calls and checkpointed turns.",
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
6
|
"engines": {
|
package/src/advisory/executor.ts
CHANGED
|
@@ -10,7 +10,12 @@ import type { AdvisoryRequest, AdvisoryResult } from '../types/advisory/result.j
|
|
|
10
10
|
import type { CostInfo, TokenUsage } from '../types/common/index.js'
|
|
11
11
|
import { type Message, createSystemMessage, createUserMessage } from '../types/message/index.js'
|
|
12
12
|
import type { LLMToolSchema } from '../types/tool/index.js'
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
accumulateReportedCost,
|
|
15
|
+
accumulateUnpricedCost,
|
|
16
|
+
calculateCost,
|
|
17
|
+
hasReportedCost,
|
|
18
|
+
} from '../utils/cost.js'
|
|
14
19
|
import { type Logger, resolveLogger } from '../utils/logger.js'
|
|
15
20
|
import { renderAdvisoryHistory } from './history.js'
|
|
16
21
|
import { ADVISORY_RESPONSE_CONTRACT, parseAdvisoryResponse } from './parse.js'
|
|
@@ -212,7 +217,8 @@ export class AdvisoryExecutor {
|
|
|
212
217
|
}
|
|
213
218
|
|
|
214
219
|
/**
|
|
215
|
-
* Cost for one call
|
|
220
|
+
* Cost for one call: the provider's reported charge, else the advisor's own
|
|
221
|
+
* pricing, else the catalogue.
|
|
216
222
|
*
|
|
217
223
|
* When neither has a rate this reports the tokens as UNPRICED rather than
|
|
218
224
|
* as a cost of zero. The previous version returned a zero rate card and a
|
|
@@ -224,6 +230,11 @@ export class AdvisoryExecutor {
|
|
|
224
230
|
* because the number happens to be unenforced.
|
|
225
231
|
*/
|
|
226
232
|
private computeCost(advisor: AdvisorDefinition, usage: TokenUsage): CostInfo {
|
|
233
|
+
// A charge the provider reported is what the account paid, so it wins over
|
|
234
|
+
// any rate card (the same order the session recorder uses).
|
|
235
|
+
if (hasReportedCost(usage)) {
|
|
236
|
+
return accumulateReportedCost(ZERO_COST, usage.reportedCostUsd)
|
|
237
|
+
}
|
|
227
238
|
const pricing = advisor.pricing ?? resolveModelPricing(advisor.provider.id, advisor.model)
|
|
228
239
|
if (!pricing) {
|
|
229
240
|
return accumulateUnpricedCost(ZERO_COST, usage)
|
package/src/agents/explore.ts
CHANGED
|
@@ -27,7 +27,7 @@ export const EXPLORE_AGENT_PROMPT = [
|
|
|
27
27
|
'You are a read-only sub-agent dispatched to find things out: where something is defined, which files reference it, how a piece of code works, what a directory contains.',
|
|
28
28
|
'You cannot see the parent conversation — work only from the prompt you were given.',
|
|
29
29
|
'You have reading and searching tools only. You cannot edit, write or run commands, and you must not describe a change as made.',
|
|
30
|
-
'Search broadly first, then read what matters. Report file paths with line numbers, quote the relevant lines, and say plainly what you did not find and what you did not read.',
|
|
30
|
+
'Search broadly first, then read what matters. Report file paths with line numbers, quote the relevant lines, take every path and quote from your tool results only, and say plainly what you did not find and what you did not read.',
|
|
31
31
|
'You are best at locating answers; prefer locating over auditing whole files, and say so when a task asks for more than you can cover.',
|
|
32
32
|
'End with a concise answer the parent can act on; do not ask the parent questions.',
|
|
33
33
|
].join('\n')
|
package/src/agents/plan.ts
CHANGED
|
@@ -26,5 +26,5 @@ export const PLAN_AGENT_PROMPT = [
|
|
|
26
26
|
'You have reading and searching tools only. You cannot edit, write or run commands, and you must not describe a change as made.',
|
|
27
27
|
'Read first: find the code the change touches, the patterns it should follow and the tests that cover it. Prefer what the code already does over a design of your own.',
|
|
28
28
|
'Return the plan in this shape: a one-paragraph approach; numbered steps in the order to do them, each naming the files it changes; the files to read or change first, as paths with line numbers where it helps; the risks and open questions, including what could break and how to check it.',
|
|
29
|
-
'
|
|
29
|
+
'Take every path and quote from your tool results only, and say plainly what you could not determine. End with the plan; do not ask the parent questions.',
|
|
30
30
|
].join('\n')
|
|
@@ -197,8 +197,8 @@ const WINDOWS: ReadonlyArray<readonly [prefix: string, tokens: number]> = [
|
|
|
197
197
|
// (a fine-tune, a distill), and nothing says it keeps the parent's window.
|
|
198
198
|
// Over-estimating ends a turn on a provider rejection; under-estimating
|
|
199
199
|
// costs a summary. So an id not named here falls to the bare `deepseek`
|
|
200
|
-
// row below, the 64k the older ids (chat, reasoner, R1 distills) had.
|
|
201
|
-
//
|
|
200
|
+
// row below, the 64k the older ids (chat, reasoner, R1 distills) had. Listed
|
|
201
|
+
// ids are matched whole (see `DEEPSEEK_ONE_MILLION_IDS`), never by
|
|
202
202
|
// substring.
|
|
203
203
|
['deepseek', 64_000],
|
|
204
204
|
]
|
|
@@ -208,6 +208,13 @@ const DEEPSEEK_ONE_MILLION_IDS: ReadonlySet<string> = new Set([
|
|
|
208
208
|
'deepseek-v4-flash',
|
|
209
209
|
'deepseek-v4-pro',
|
|
210
210
|
'deepseek-flash',
|
|
211
|
+
// The revisions and dated snapshots a gateway's model list names for the
|
|
212
|
+
// same generation. Each is listed whole: a new revision is a new row here
|
|
213
|
+
// (or is reported by the provider), never a prefix match.
|
|
214
|
+
'deepseek-v4.1-flash',
|
|
215
|
+
'deepseek-v4.1-flash-1017',
|
|
216
|
+
'deepseek-v4-flash-0731',
|
|
217
|
+
'deepseek-v4-pro-0813',
|
|
211
218
|
])
|
|
212
219
|
|
|
213
220
|
/** The id with a gateway prefix (`deepseek/`) and a `:tag` (`:free`) removed. */
|
package/src/eval/judge.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { collectChatCompletion } from '../provider/collect-chat-completion.js'
|
|
2
2
|
import { resolveStreamIdleTimeoutMs, withStreamIdleTimeout } from '../provider/idle-timeout.js'
|
|
3
|
+
import { chatStreamForSideRequest } from '../provider/side-request-reasoning.js'
|
|
3
4
|
import { chatStreamWithSamplingRepair } from '../runtime/query/iteration/side-call.js'
|
|
4
5
|
import type { LLMProvider } from '../types/provider/interface.js'
|
|
5
6
|
import type { EvalCase, EvalTurn, Score, Scorer } from './types.js'
|
|
@@ -222,15 +223,21 @@ export function judgeScorer(config: JudgeScorerConfig): Scorer {
|
|
|
222
223
|
name: config.name ?? 'judge',
|
|
223
224
|
async score(turn: EvalTurn, evalCase: EvalCase, signal?: AbortSignal): Promise<Score> {
|
|
224
225
|
const response = await collectChatCompletion(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
226
|
+
// A grade is a side request: a thinking model must not spend the
|
|
227
|
+
// whole allowance on reasoning and hand back nothing to grade.
|
|
228
|
+
chatStreamForSideRequest(
|
|
229
|
+
provider,
|
|
230
|
+
{
|
|
231
|
+
model: config.model,
|
|
232
|
+
messages: [{ role: 'user', content: buildPrompt(config, turn, evalCase, scale) }],
|
|
233
|
+
// The same turn must grade the same way twice, or a
|
|
234
|
+
// regression cannot be told from sampling noise.
|
|
235
|
+
temperature: 0,
|
|
236
|
+
maxTokens: 512,
|
|
237
|
+
...(signal ? { signal } : {}),
|
|
238
|
+
},
|
|
239
|
+
(request) => chatStreamWithSamplingRepair(provider, request),
|
|
240
|
+
),
|
|
234
241
|
)
|
|
235
242
|
|
|
236
243
|
const verdict = parseVerdict(response.message.content ?? '', scale)
|
|
@@ -323,7 +323,7 @@ export class AgentManager {
|
|
|
323
323
|
private deps: AgentManagerDeps
|
|
324
324
|
private topicManager: TopicManager
|
|
325
325
|
private readonly pendingSpawns = new Map<SessionId, PendingSpawn[]>()
|
|
326
|
-
private readonly drainingParents = new
|
|
326
|
+
private readonly drainingParents = new Map<SessionId, Promise<void>>()
|
|
327
327
|
private readonly executingTasks = new Set<TaskId>()
|
|
328
328
|
private readonly cancelingTasks = new Set<TaskId>()
|
|
329
329
|
private admissionTimer: ReturnType<typeof setTimeout> | undefined
|
|
@@ -441,14 +441,25 @@ export class AgentManager {
|
|
|
441
441
|
} catch (error) {
|
|
442
442
|
this.failAdmission(entry, error)
|
|
443
443
|
}
|
|
444
|
-
|
|
444
|
+
// Report the task as it stands once admission has had its turn: started
|
|
445
|
+
// when there was room, still pending only when the pass stopped at a
|
|
446
|
+
// capacity or budget limit. Returned earlier, every task of a burst
|
|
447
|
+
// launched at the same moment would read as waiting for a slot.
|
|
448
|
+
await this.pumpAdmissions(options.parentSessionId)
|
|
449
|
+
// A pass that was already running may have looked at the queue before this
|
|
450
|
+
// entry was ready and ended without it. One more pass admits it now; if
|
|
451
|
+
// the first pass stopped at a limit, the second stops at the same limit.
|
|
452
|
+
if (entry.ready && task.state === 'pending' && !this.disposed)
|
|
453
|
+
await this.pumpAdmissions(options.parentSessionId)
|
|
445
454
|
return task
|
|
446
455
|
}
|
|
447
456
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
this.
|
|
451
|
-
|
|
457
|
+
/** Run one admission pass; resolves when it has started what it can, never rejects. */
|
|
458
|
+
private pumpAdmissions(parentSessionId: SessionId): Promise<void> {
|
|
459
|
+
if (this.disposed) return Promise.resolve()
|
|
460
|
+
const running = this.drainingParents.get(parentSessionId)
|
|
461
|
+
if (running) return running
|
|
462
|
+
const pass = this.drainAdmissions(parentSessionId)
|
|
452
463
|
.finally(() => {
|
|
453
464
|
this.drainingParents.delete(parentSessionId)
|
|
454
465
|
// External handoffs and metadata changes have no manager event. A
|
|
@@ -467,6 +478,8 @@ export class AgentManager {
|
|
|
467
478
|
'exception.message': toErrorMessage(error),
|
|
468
479
|
}),
|
|
469
480
|
)
|
|
481
|
+
this.drainingParents.set(parentSessionId, pass)
|
|
482
|
+
return pass
|
|
470
483
|
}
|
|
471
484
|
|
|
472
485
|
private async drainAdmissions(parentSessionId: SessionId): Promise<void> {
|
|
@@ -61,7 +61,9 @@ import {
|
|
|
61
61
|
type ModelPricing,
|
|
62
62
|
ZERO_COST,
|
|
63
63
|
accumulateCost,
|
|
64
|
+
accumulateReportedCost,
|
|
64
65
|
accumulateUnpricedCost,
|
|
66
|
+
hasReportedCost,
|
|
65
67
|
} from '../../utils/cost.js'
|
|
66
68
|
import { asCheckpointId, generateAuditEventId, generateMessageId } from '../../utils/id.js'
|
|
67
69
|
import { childOutcomeRecorded, childSessionEnded } from '../agent/child-session.js'
|
|
@@ -544,7 +546,16 @@ export class TurnRecorder {
|
|
|
544
546
|
}
|
|
545
547
|
|
|
546
548
|
accumulateUsage(usage: TokenUsage, servedBy: PricingSubject): void {
|
|
547
|
-
|
|
549
|
+
// The reported charge is money, and it is recorded in `costInfo` below; the
|
|
550
|
+
// usage totals that reach the session log stay token counts.
|
|
551
|
+
const { reportedCostUsd: _charged, ...counted } = usage
|
|
552
|
+
this.#turn.tokenUsage = accumulateTokenUsage(this.#turn.tokenUsage, counted)
|
|
553
|
+
// What the provider says it charged wins over a rate card; the card is
|
|
554
|
+
// the fallback for a call that reported nothing.
|
|
555
|
+
if (hasReportedCost(usage)) {
|
|
556
|
+
this.#turn.costInfo = accumulateReportedCost(this.#turn.costInfo, usage.reportedCostUsd)
|
|
557
|
+
return
|
|
558
|
+
}
|
|
548
559
|
const pricing = this.#resolvePricing(servedBy)
|
|
549
560
|
this.#turn.costInfo =
|
|
550
561
|
pricing === undefined
|
|
@@ -36,65 +36,66 @@ import type { PromptContribution } from './contributions.js'
|
|
|
36
36
|
|
|
37
37
|
export const CODING_AGENT_WORKING_DOCTRINE = `## How you work
|
|
38
38
|
|
|
39
|
-
###
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
### Answering a question
|
|
40
|
+
- A question, or a description of a problem, gets an answer or an assessment first. Act only when asked to act, or when the answer needs a fact one look can get.
|
|
41
|
+
- Make that look one step: independent tool calls, such as every search for the fact, go in one response. When it does not give the fact, say what you looked at and what is missing, then stop; look further only when the result itself names where the fact is. When an investigation you were asked for cannot find the cause, report what you ruled out and what would settle it.
|
|
42
|
+
- Open with the answer, not with an apology or with agreement for its own sake.
|
|
43
|
+
- A step that says it will do something does it in that step, and a turn never ends on a promise of a later answer.
|
|
44
|
+
|
|
45
|
+
### Asking and proceeding
|
|
46
|
+
- Act when you have enough information. Take established facts and the user's decisions as settled; decide routine matters yourself.
|
|
47
|
+
- Ask only when you cannot name the most likely reading of the request, or when proceeding under any assumption would be unsafe or would make the work useless if wrong. Ask once, with your best guess, because ending the turn stops all work.
|
|
48
|
+
- If you find a real problem with the task as stated, say so in a sentence, then keep going under a stated assumption. If the user repeats or reaffirms a request after you raised a concern, that is their decision: say so and do the full request.
|
|
49
|
+
- After a refused or empty result, change the request or report it; do not issue the same call again.
|
|
46
50
|
|
|
47
51
|
### Reporting
|
|
48
|
-
- Report outcomes faithfully
|
|
49
|
-
- Report identifiers exactly as the evidence spells them, so
|
|
50
|
-
-
|
|
51
|
-
- Reference code as \`path:line\` so the user can jump to it.
|
|
52
|
-
- Correct an earlier statement only when the error would change the user's code, conclusions or decisions; state it once, plainly, and continue, and keep apologies and tallies of past mistakes out of it, because they spend the reader's attention on the past.
|
|
52
|
+
- Report outcomes faithfully: show failing test output, say what you skipped, and state what is done and verified.
|
|
53
|
+
- Report identifiers exactly as the evidence spells them, and reference code as \`path:line\`. Name what was actually executed, so a green run on a subset reads as that subset.
|
|
54
|
+
- Correct an earlier statement only when the error would change the user's code, conclusions or decisions; state it once, plainly, with no apology or tally of past mistakes, because they spend the reader's attention on the past.
|
|
53
55
|
|
|
54
56
|
### Using available evidence
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
57
|
+
- A successful tool result with its exact inputs is evidence of what happened, and so is content you wrote; an announced action, a failed call or another agent's unsupported claim is not. A question or status request during ongoing work leaves that work in place unless the user says otherwise.
|
|
58
|
+
- Reuse evidence still in the conversation instead of observing it again by habit, and when you do observe, ask the narrowest question that resolves the uncertainty (a known file, not a directory). Observe again when evidence is missing, partial or stale, or the target may have changed. Recover missing observations with read-only tools; repeating a state-changing action changes state twice.
|
|
59
|
+
- If a check or an exact-match edit reports a mismatch, inspect the current state and revise the action.
|
|
60
|
+
- For a question about an earlier state, use that observation or its retained original; a fresh read of a mutable source cannot show what it held earlier. When the detail is gone, say so and leave today's value out.
|
|
61
|
+
- Wait for a mutation to finish before an observation or another action that depends on it.
|
|
62
|
+
|
|
63
|
+
### When the task is to change code
|
|
64
|
+
This section applies only when you were asked to change something.
|
|
65
|
+
- Begin editing once you know the first change, and refine as you go. The requested scope is the deliverable, at the size asked.
|
|
66
|
+
- Finish the whole task, not just the easy parts. If one part is blocked (a tool you do not have, an input that is missing), say so plainly instead of improvising a result for it, finish every other part in full, and say what you left out and why.
|
|
67
|
+
- Before editing, use file content you already read or wrote; if it may be stale, read the needed portion again, and match the surrounding naming and idiom.
|
|
68
|
+
- Prefer the dedicated tools over shell equivalents (\`read\` over \`cat\`, \`grep\` over a shell grep, \`glob\` over \`find\`, \`edit\` over \`sed -i\`, \`write\` over a shell redirect); use \`bash\` for a shell.
|
|
69
|
+
- For a defect, reproduce it first with a small script or a failing test, and keep it; make the change, then rerun that reproduction. Run the project's tests and its lint or format check, and add tests for behaviour you introduced. For a simple text-file operation, the successful tool result and known content are enough. Claim only the checks you ran.
|
|
70
|
+
- Say where any throwaway file you made is, and which files outside the request you touched.
|
|
66
71
|
|
|
67
72
|
### Working with git
|
|
68
73
|
- Never push, force-push, reset, rebase, clean, or otherwise discard or rewrite history unless the user explicitly asked for that action. Approval for one push does not extend to the next.
|
|
69
74
|
- Before any command that could discard uncommitted work, run \`git status\`. If there are changes there that you did not make, stop and ask rather than stashing, committing or discarding somebody else's work.
|
|
70
|
-
- Commit only when the user asks, on the branch that is checked out
|
|
71
|
-
- After a broad \`git add\`, review what was staged before committing; a file whose name looks harmless can still carry a secret.
|
|
75
|
+
- Commit only when the user asks, on the branch that is checked out, and switch branches only when asked or the project's instructions require it, because the checked-out branch is the user's working state. After a broad \`git add\`, review what was staged.
|
|
72
76
|
- Never change git configuration or other persistent settings without asking: not \`user.name\` or \`user.email\`, hooks, remotes, credential helpers, or any \`git config\` (local or global), nor a shell profile or a tool's own config file. If a commit fails because no identity is set, stop and tell the user the command to set one; do not invent one.
|
|
73
77
|
|
|
74
78
|
### Keeping the user informed
|
|
75
|
-
-
|
|
76
|
-
-
|
|
79
|
+
- For work that takes several calls, say one short line before the first call and one more when you find something, change direction or hit a blocker, and a few words on where you are after a long stretch without one; a question that needs at most one look gets no such line, and no line goes beside each call, because the tool rows on screen show the details.
|
|
80
|
+
- When you changed something, close with what changed, what was verified and what is left. For a question the reply is the answer.`
|
|
77
81
|
|
|
78
82
|
/**
|
|
79
83
|
* Parent-only: rules about the task list and `Agent`, which a
|
|
80
84
|
* delegated sub-agent does not have. See the module comment for the split.
|
|
81
85
|
*/
|
|
82
86
|
export const CODING_AGENT_DELEGATION_DOCTRINE = `### Planning and delegating
|
|
83
|
-
- A task list is optional. For work of three or more distinct steps
|
|
84
|
-
- When the \`Agent\` tool is available, do small work, or work whose target you already know, yourself: a file you can name, one search, one edit. A fresh sub-agent starts with none of your context. Delegate work that is independent of your next step, large, or whose output would flood your context,
|
|
85
|
-
- You keep the understanding
|
|
87
|
+
- A task list is optional. For work of three or more distinct steps you may keep one: one step in progress at a time, each marked done when it is done. Do not make one for a two-step job.
|
|
88
|
+
- When the \`Agent\` tool is available, do small work, or work whose target you already know, yourself: a file you can name, one search, one edit. A fresh sub-agent starts with none of your context. Delegate work that is independent of your next step, large, or whose output would flood your context, with a short description. Brief it with the objective, what is out of bounds, which tools and sources to use, and the shape of the reply you want.
|
|
89
|
+
- You keep the understanding: pass paths, line numbers and what is already ruled out, never a conclusion for the sub-agent to confirm, and once delegated, do not do the work again yourself.
|
|
86
90
|
- A sub-agent's report is a claim, not a fact. Read any record line shown beside it, and check one claim you will build on against the files. Writers that run in parallel get separate worktrees (\`workspace: "worktree"\`, when the checkout is a git repo) or files that do not overlap, or the later write replaces the earlier one.
|
|
87
|
-
- When the \`Agent\` tool lists a \`fork\` type, use \`subagent_type: "fork"\`
|
|
88
|
-
- When delegated agents finish, tell the user what each one found in your next message
|
|
89
|
-
- Use \`subagent_type: "explore"\` to locate something small
|
|
91
|
+
- When the \`Agent\` tool lists a \`fork\` type, use \`subagent_type: "fork"\` for a side task whose output you will not need again; its prompt is only the directive. Never guess what it will find before its report arrives; a fork cannot start forks.
|
|
92
|
+
- When delegated agents finish, tell the user what each one found in your next message, because their results reach you and not the user.
|
|
93
|
+
- Use \`subagent_type: "explore"\` to locate something small; it only reads and searches, and never asks the user for permission. It is not for reviewing or auditing whole files. Reserve the default sub-agent for work that changes files or runs commands.
|
|
90
94
|
|
|
91
95
|
### Answering how work is going
|
|
92
|
-
-
|
|
93
|
-
- Give each item the state you were given for it (progressing, waiting, stalled or dead) and how long ago it last moved
|
|
94
|
-
-
|
|
95
|
-
- Name each item by what it is doing, not by its id: an id means nothing to the person, so give one only when they ask for it or need it for a command.
|
|
96
|
-
- A result exists only once its completion message has arrived, so for an unfinished item say it is still running; a predicted result reads as a fact and may be wrong.
|
|
97
|
-
- For an item reported dead, say it ended without a result and offer to run it again; starting the same work again unasked could repeat what it already did.`
|
|
96
|
+
- Read the note about running work on your request first if the host gives you one, and add one status read from the tool that started an item only when the note does not say enough. Leave the work running.
|
|
97
|
+
- Give each item the state you were given for it (progressing, waiting, stalled or dead) and how long ago it last moved; stalled means only quiet for a while. Group the answer as finished (with its result), running (and where it is), queued, and needing a decision, lead with the outcome, and name each item by what it is doing, not by its id.
|
|
98
|
+
- A result exists only once its completion message has arrived, so for an unfinished item say it is still running. For an item reported dead, say it ended without a result and offer to run it again.`
|
|
98
99
|
|
|
99
100
|
/**
|
|
100
101
|
* For a session whose permission layer refuses every mutation. Says what that
|
package/src/provider/fallback.ts
CHANGED
|
@@ -561,8 +561,9 @@ export function withProviderFallback(
|
|
|
561
561
|
const serving = members[cursor] ?? first
|
|
562
562
|
return serving.provider.supportsImageInputFor?.(serving.model ?? model) ?? true
|
|
563
563
|
},
|
|
564
|
-
// A chain takes a forced choice only if every member does: the
|
|
565
|
-
// be served by any of them, and
|
|
564
|
+
// A chain takes a forced choice only if every member says it does: the
|
|
565
|
+
// request may be served by any of them, and one that refuses (or cannot
|
|
566
|
+
// say) must not be sent a choice it may turn down.
|
|
566
567
|
acceptsForcedToolChoiceFor: (
|
|
567
568
|
model: string,
|
|
568
569
|
thinking?: ThinkingConfig,
|
|
@@ -571,7 +572,7 @@ export function withProviderFallback(
|
|
|
571
572
|
members.every(
|
|
572
573
|
(member) =>
|
|
573
574
|
member.provider.acceptsForcedToolChoiceFor?.(member.model ?? model, thinking, effort) ??
|
|
574
|
-
|
|
575
|
+
false,
|
|
575
576
|
),
|
|
576
577
|
reasoningEffortLevelsFor: (model: string, thinking?: ThinkingConfig) =>
|
|
577
578
|
commonReasoningEffortLevels(members, model, thinking),
|
|
@@ -229,7 +229,7 @@ export function withStreamIdleTimeout(
|
|
|
229
229
|
model: string,
|
|
230
230
|
thinking?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[1],
|
|
231
231
|
effort?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[2],
|
|
232
|
-
) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ??
|
|
232
|
+
) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? false,
|
|
233
233
|
}
|
|
234
234
|
: {}),
|
|
235
235
|
...(provider.reasoningEffortLevelsFor
|
|
@@ -31,7 +31,7 @@ function extractStreamUsage(usage: TokenUsage | undefined): ProviderCallUsage |
|
|
|
31
31
|
inputTokens: u.inputTokens ?? u.promptTokens,
|
|
32
32
|
outputTokens: u.outputTokens ?? u.completionTokens,
|
|
33
33
|
totalTokens: u.totalTokens,
|
|
34
|
-
costUsd: u.costUsd,
|
|
34
|
+
costUsd: u.costUsd ?? u.reportedCostUsd,
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
package/src/provider/retry.ts
CHANGED
|
@@ -441,7 +441,7 @@ export function withProviderRetry(
|
|
|
441
441
|
model: string,
|
|
442
442
|
thinking?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[1],
|
|
443
443
|
effort?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[2],
|
|
444
|
-
) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ??
|
|
444
|
+
) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? false,
|
|
445
445
|
}
|
|
446
446
|
: {}),
|
|
447
447
|
...(provider.reasoningEffortLevelsFor
|