@theokit/sdk 4.28.0 → 4.30.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/dist/agent-7YUGJJTU.js +41 -0
- package/dist/agent-7YUGJJTU.js.map +1 -0
- package/dist/{cron-BN6JJlDw.d.ts → agent-Bzg2_uGr.d.cts} +56 -577
- package/dist/{cron-CoQREV_k.d.cts → agent-Ekv8y7_c.d.ts} +56 -577
- package/dist/agent-LD76RI74.cjs +50 -0
- package/dist/agent-LD76RI74.cjs.map +1 -0
- package/dist/{chunk-AKSBP7OO.js → chunk-5IB2UKSN.js} +5 -41
- package/dist/chunk-5IB2UKSN.js.map +1 -0
- package/dist/{chunk-PF5Y5BHG.js → chunk-5YCAR23S.js} +3 -3
- package/dist/{chunk-PF5Y5BHG.js.map → chunk-5YCAR23S.js.map} +1 -1
- package/dist/chunk-BNIFFFH3.js +129 -0
- package/dist/chunk-BNIFFFH3.js.map +1 -0
- package/dist/{chunk-LSLPF6OI.cjs → chunk-DHLZIMP6.cjs} +5 -43
- package/dist/chunk-DHLZIMP6.cjs.map +1 -0
- package/dist/chunk-FKCC2MED.js +43 -0
- package/dist/chunk-FKCC2MED.js.map +1 -0
- package/dist/{chunk-PN53WGEI.cjs → chunk-GWMQ5CS3.cjs} +633 -741
- package/dist/chunk-GWMQ5CS3.cjs.map +1 -0
- package/dist/{chunk-QUTUJ6P6.cjs → chunk-HK7ZHSAX.cjs} +25 -16
- package/dist/chunk-HK7ZHSAX.cjs.map +1 -0
- package/dist/{chunk-XW6RXVGB.js → chunk-ISZ3MBUD.js} +610 -718
- package/dist/chunk-ISZ3MBUD.js.map +1 -0
- package/dist/{chunk-MQLCZ4HJ.cjs → chunk-JLMXKTBX.cjs} +4 -4
- package/dist/{chunk-MQLCZ4HJ.cjs.map → chunk-JLMXKTBX.cjs.map} +1 -1
- package/dist/chunk-LALRCFSN.cjs +46 -0
- package/dist/chunk-LALRCFSN.cjs.map +1 -0
- package/dist/{chunk-I53QDJVI.cjs → chunk-NG6B2PMA.cjs} +5 -5
- package/dist/{chunk-I53QDJVI.cjs.map → chunk-NG6B2PMA.cjs.map} +1 -1
- package/dist/{chunk-DUK5WMKJ.js → chunk-R6ZP6KNB.js} +25 -16
- package/dist/chunk-R6ZP6KNB.js.map +1 -0
- package/dist/chunk-RZQ6E5YZ.cjs +131 -0
- package/dist/chunk-RZQ6E5YZ.cjs.map +1 -0
- package/dist/{chunk-G6GO6BXD.js → chunk-XAUBQMQU.js} +3 -3
- package/dist/{chunk-G6GO6BXD.js.map → chunk-XAUBQMQU.js.map} +1 -1
- package/dist/compact-session-OO2GD76G.js +1 -1
- package/dist/compact-session-OO7NVWPB.cjs +1 -1
- package/dist/cron-CjzvXGT2.d.cts +579 -0
- package/dist/cron-D0Z29gI-.d.ts +579 -0
- package/dist/cron.cjs +13 -11
- package/dist/cron.d.cts +2 -1
- package/dist/cron.d.ts +2 -1
- package/dist/cron.js +12 -10
- package/dist/eval.cjs +17 -15
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +13 -11
- package/dist/eval.js.map +1 -1
- package/dist/{index-manager-CB6I7XFQ.cjs → index-manager-H7HUMW52.cjs} +5 -5
- package/dist/{index-manager-CB6I7XFQ.cjs.map → index-manager-H7HUMW52.cjs.map} +1 -1
- package/dist/{index-manager-L27Q3QAC.js → index-manager-P7ZUX2RG.js} +4 -4
- package/dist/{index-manager-L27Q3QAC.js.map → index-manager-P7ZUX2RG.js.map} +1 -1
- package/dist/index.cjs +65 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.js +41 -20
- package/dist/index.js.map +1 -1
- package/dist/internal/persistence/index.cjs +10 -10
- package/dist/internal/persistence/index.js +2 -2
- package/dist/internal/persistence/jsonl.d.cts +7 -0
- package/dist/internal/persistence/jsonl.d.ts +7 -0
- package/dist/internal/persistence/session-writer.d.cts +56 -0
- package/dist/internal/persistence/session-writer.d.ts +56 -0
- package/dist/internal/persistence/transcript-ops.d.cts +71 -0
- package/dist/internal/persistence/transcript-ops.d.ts +71 -0
- package/dist/internal/plugins/types.d.cts +1 -1
- package/dist/internal/plugins/types.d.ts +1 -1
- package/dist/persistence.cjs +115 -12
- package/dist/persistence.cjs.map +1 -1
- package/dist/persistence.d.cts +2 -0
- package/dist/persistence.d.ts +2 -0
- package/dist/persistence.js +105 -3
- package/dist/persistence.js.map +1 -1
- package/dist/skills.cjs +4 -3
- package/dist/skills.js +2 -1
- package/dist/subagents-loader.cjs +19 -0
- package/dist/subagents-loader.cjs.map +1 -0
- package/dist/subagents-loader.d.cts +39 -0
- package/dist/subagents-loader.d.ts +39 -0
- package/dist/subagents-loader.js +16 -0
- package/dist/subagents-loader.js.map +1 -0
- package/dist/types/plugin.d.ts +32 -0
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.js +1 -1
- package/package.json +12 -2
- package/dist/chunk-AKSBP7OO.js.map +0 -1
- package/dist/chunk-DUK5WMKJ.js.map +0 -1
- package/dist/chunk-LSLPF6OI.cjs.map +0 -1
- package/dist/chunk-PN53WGEI.cjs.map +0 -1
- package/dist/chunk-QUTUJ6P6.cjs.map +0 -1
- package/dist/chunk-XW6RXVGB.js.map +0 -1
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkBV2MWEMV_cjs = require('./chunk-BV2MWEMV.cjs');
|
|
3
4
|
var chunkMZ5ZRORA_cjs = require('./chunk-MZ5ZRORA.cjs');
|
|
4
5
|
var chunkYU6KON2I_cjs = require('./chunk-YU6KON2I.cjs');
|
|
6
|
+
var chunk2HRYBRD7_cjs = require('./chunk-2HRYBRD7.cjs');
|
|
5
7
|
var chunk2MF3IE2D_cjs = require('./chunk-2MF3IE2D.cjs');
|
|
6
|
-
var
|
|
8
|
+
var chunkJLMXKTBX_cjs = require('./chunk-JLMXKTBX.cjs');
|
|
7
9
|
var chunkN24XBYNX_cjs = require('./chunk-N24XBYNX.cjs');
|
|
8
|
-
var
|
|
10
|
+
var chunkWPZTYOUX_cjs = require('./chunk-WPZTYOUX.cjs');
|
|
9
11
|
var chunkOIYQBUW4_cjs = require('./chunk-OIYQBUW4.cjs');
|
|
10
|
-
var chunk2HRYBRD7_cjs = require('./chunk-2HRYBRD7.cjs');
|
|
11
12
|
var chunk6JSIEDKL_cjs = require('./chunk-6JSIEDKL.cjs');
|
|
12
13
|
var chunkG2F67XUR_cjs = require('./chunk-G2F67XUR.cjs');
|
|
13
14
|
var chunkNINIJCHU_cjs = require('./chunk-NINIJCHU.cjs');
|
|
14
|
-
var
|
|
15
|
+
var chunkYPEPCZHF_cjs = require('./chunk-YPEPCZHF.cjs');
|
|
15
16
|
var chunkVJ26EKGJ_cjs = require('./chunk-VJ26EKGJ.cjs');
|
|
16
17
|
var chunkGIW4L6HY_cjs = require('./chunk-GIW4L6HY.cjs');
|
|
17
18
|
var chunkC7PICHRF_cjs = require('./chunk-C7PICHRF.cjs');
|
|
18
19
|
var chunkYLQQX5W2_cjs = require('./chunk-YLQQX5W2.cjs');
|
|
19
20
|
var chunk4SXHEZIV_cjs = require('./chunk-4SXHEZIV.cjs');
|
|
20
21
|
var chunkWJVHMTKB_cjs = require('./chunk-WJVHMTKB.cjs');
|
|
22
|
+
var chunkTIZ4TS5V_cjs = require('./chunk-TIZ4TS5V.cjs');
|
|
23
|
+
var chunkRZQ6E5YZ_cjs = require('./chunk-RZQ6E5YZ.cjs');
|
|
21
24
|
var chunkEVADEGM7_cjs = require('./chunk-EVADEGM7.cjs');
|
|
22
25
|
var chunkVYHJZVL5_cjs = require('./chunk-VYHJZVL5.cjs');
|
|
23
26
|
var chunkD42XHI4O_cjs = require('./chunk-D42XHI4O.cjs');
|
|
24
|
-
var
|
|
27
|
+
var chunkDHLZIMP6_cjs = require('./chunk-DHLZIMP6.cjs');
|
|
25
28
|
var chunkKIO7QFIV_cjs = require('./chunk-KIO7QFIV.cjs');
|
|
26
|
-
var
|
|
27
|
-
var chunkTIZ4TS5V_cjs = require('./chunk-TIZ4TS5V.cjs');
|
|
29
|
+
var chunkLALRCFSN_cjs = require('./chunk-LALRCFSN.cjs');
|
|
28
30
|
var chunkA44COQJJ_cjs = require('./chunk-A44COQJJ.cjs');
|
|
29
31
|
var chunkBEURCLDV_cjs = require('./chunk-BEURCLDV.cjs');
|
|
30
|
-
var crypto = require('crypto');
|
|
31
32
|
var promises = require('fs/promises');
|
|
33
|
+
var crypto = require('crypto');
|
|
32
34
|
var fs = require('fs');
|
|
33
35
|
var path = require('path');
|
|
34
36
|
var child_process = require('child_process');
|
|
@@ -101,506 +103,47 @@ var AgentBuilder = class {
|
|
|
101
103
|
this.opts.skills = s;
|
|
102
104
|
return this;
|
|
103
105
|
}
|
|
104
|
-
agentId(id) {
|
|
105
|
-
this.opts.agentId = id;
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Synchronous snapshot of the accumulated options. Returns a SHALLOW CLONE
|
|
110
|
-
* so external mutation of the result doesn't pollute the builder state (EC-2).
|
|
111
|
-
*/
|
|
112
|
-
build() {
|
|
113
|
-
return { ...this.opts };
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Validate + create a fresh agent. Delegates to `Agent.create` via the
|
|
117
|
-
* injected `deps.create`. Throws if the builder was instantiated without
|
|
118
|
-
* deps (i.e., direct `new AgentBuilder()` instead of `Agent.builder()`).
|
|
119
|
-
*/
|
|
120
|
-
create() {
|
|
121
|
-
if (this.deps === void 0) {
|
|
122
|
-
return Promise.reject(
|
|
123
|
-
new Error(
|
|
124
|
-
"AgentBuilder.create() requires Agent.builder() entry \u2014 direct construction has no terminals."
|
|
125
|
-
)
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
return this.deps.create(this.build());
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Resume an existing agent or create one if the ID is unknown. Delegates to
|
|
132
|
-
* `Agent.getOrCreate` via the injected `deps.getOrCreate` (ADR D22).
|
|
133
|
-
*/
|
|
134
|
-
getOrCreate(agentId) {
|
|
135
|
-
if (this.deps === void 0) {
|
|
136
|
-
return Promise.reject(
|
|
137
|
-
new Error(
|
|
138
|
-
"AgentBuilder.getOrCreate() requires Agent.builder() entry \u2014 direct construction has no terminals."
|
|
139
|
-
)
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
return this.deps.getOrCreate(agentId, this.build());
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// src/internal/env.ts
|
|
147
|
-
var API_KEY_ENV_VAR = "THEOKIT_API_KEY";
|
|
148
|
-
function resolveApiKey(explicit) {
|
|
149
|
-
if (explicit !== void 0 && explicit.length > 0) {
|
|
150
|
-
return explicit;
|
|
151
|
-
}
|
|
152
|
-
const fromEnv = process.env[API_KEY_ENV_VAR];
|
|
153
|
-
if (fromEnv !== void 0 && fromEnv.length > 0) {
|
|
154
|
-
return fromEnv;
|
|
155
|
-
}
|
|
156
|
-
return void 0;
|
|
157
|
-
}
|
|
158
|
-
var PREFIX = {
|
|
159
|
-
localAgent: "agent-",
|
|
160
|
-
cloudAgent: "bc-",
|
|
161
|
-
run: "run-",
|
|
162
|
-
call: "call-",
|
|
163
|
-
cron: "cron-",
|
|
164
|
-
request: "request-"
|
|
165
|
-
};
|
|
166
|
-
function generateLocalAgentId() {
|
|
167
|
-
return `${PREFIX.localAgent}${crypto.randomUUID()}`;
|
|
168
|
-
}
|
|
169
|
-
function generateCloudAgentId() {
|
|
170
|
-
return `${PREFIX.cloudAgent}${crypto.randomUUID()}`;
|
|
171
|
-
}
|
|
172
|
-
function generateRunId() {
|
|
173
|
-
return `${PREFIX.run}${crypto.randomUUID()}`;
|
|
174
|
-
}
|
|
175
|
-
function generateCallId() {
|
|
176
|
-
return `${PREFIX.call}${crypto.randomUUID()}`;
|
|
177
|
-
}
|
|
178
|
-
function generateCronId() {
|
|
179
|
-
return `${PREFIX.cron}${crypto.randomUUID()}`;
|
|
180
|
-
}
|
|
181
|
-
function generateRequestId() {
|
|
182
|
-
return `${PREFIX.request}${crypto.randomUUID()}`;
|
|
183
|
-
}
|
|
184
|
-
function isLocalAgentId(id) {
|
|
185
|
-
return id.startsWith(PREFIX.localAgent);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// src/define-tool.ts
|
|
189
|
-
var TOOL_SPLIT_RESOLVER = /* @__PURE__ */ Symbol("theokit.toolSplitResolver");
|
|
190
|
-
async function runValidated(spec, input, ctx) {
|
|
191
|
-
const raw = spec.sanitize ? chunk6JSIEDKL_cjs.sanitizeToolInput(input, {
|
|
192
|
-
...spec.sanitize === true ? {} : spec.sanitize,
|
|
193
|
-
schema: spec.inputSchema
|
|
194
|
-
}).value : input;
|
|
195
|
-
const parsed = spec.inputSchema.parse(raw);
|
|
196
|
-
const out = await spec.handler(parsed, ctx);
|
|
197
|
-
return spec.outputSchema === void 0 ? out : spec.outputSchema.parse(out);
|
|
198
|
-
}
|
|
199
|
-
function serializeOutput(validated) {
|
|
200
|
-
return typeof validated === "string" ? validated : JSON.stringify(validated);
|
|
201
|
-
}
|
|
202
|
-
function shapeModelOutput(spec, validated) {
|
|
203
|
-
if (spec.toModelOutput !== void 0) return spec.toModelOutput(validated);
|
|
204
|
-
return serializeOutput(validated);
|
|
205
|
-
}
|
|
206
|
-
var Tool = class {
|
|
207
|
-
constructor() {
|
|
208
|
-
}
|
|
209
|
-
static create(spec) {
|
|
210
|
-
return defineTool(spec);
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
function defineTool(spec) {
|
|
214
|
-
const inputSchema = chunkWJVHMTKB_cjs.toJsonSchema(spec.inputSchema, {
|
|
215
|
-
unrepresentable: "any"
|
|
216
|
-
});
|
|
217
|
-
const handler = async (input, ctx) => {
|
|
218
|
-
const validated = await runValidated(spec, input, ctx);
|
|
219
|
-
return shapeModelOutput(spec, validated);
|
|
220
|
-
};
|
|
221
|
-
const tool = { name: spec.name, description: spec.description, inputSchema, handler };
|
|
222
|
-
if (spec.toModelOutput !== void 0) {
|
|
223
|
-
const resolver = async (input, ctx) => {
|
|
224
|
-
const validated = await runValidated(spec, input, ctx);
|
|
225
|
-
return { model: shapeModelOutput(spec, validated), app: serializeOutput(validated) };
|
|
226
|
-
};
|
|
227
|
-
handler[TOOL_SPLIT_RESOLVER] = resolver;
|
|
228
|
-
}
|
|
229
|
-
return tool;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// src/internal/budget/usage-accumulator.ts
|
|
233
|
-
var UsageAccumulator = class {
|
|
234
|
-
input = 0;
|
|
235
|
-
output = 0;
|
|
236
|
-
cacheRead = 0;
|
|
237
|
-
cacheWrite = 0;
|
|
238
|
-
reasoning = 0;
|
|
239
|
-
requests = [];
|
|
240
|
-
add(step) {
|
|
241
|
-
const inputTokens = step.inputTokens ?? 0;
|
|
242
|
-
const outputTokens = step.outputTokens ?? 0;
|
|
243
|
-
const cacheReadTokens = step.cacheReadTokens ?? 0;
|
|
244
|
-
const cacheWriteTokens = step.cacheWriteTokens ?? 0;
|
|
245
|
-
const reasoningTokens = step.reasoningTokens ?? 0;
|
|
246
|
-
this.input += inputTokens;
|
|
247
|
-
this.output += outputTokens;
|
|
248
|
-
this.cacheRead += cacheReadTokens;
|
|
249
|
-
this.cacheWrite += cacheWriteTokens;
|
|
250
|
-
this.reasoning += reasoningTokens;
|
|
251
|
-
this.requests.push({
|
|
252
|
-
inputTokens,
|
|
253
|
-
outputTokens,
|
|
254
|
-
...cacheReadTokens > 0 ? { cacheReadTokens } : {},
|
|
255
|
-
...cacheWriteTokens > 0 ? { cacheWriteTokens } : {},
|
|
256
|
-
...reasoningTokens > 0 ? { reasoningTokens } : {},
|
|
257
|
-
totalTokens: inputTokens + outputTokens
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
/** Did we observe any usage at all? */
|
|
261
|
-
hasAny() {
|
|
262
|
-
return this.requests.length > 0;
|
|
263
|
-
}
|
|
264
|
-
toTokenUsage() {
|
|
265
|
-
return {
|
|
266
|
-
inputTokens: this.input,
|
|
267
|
-
outputTokens: this.output,
|
|
268
|
-
...this.cacheRead > 0 ? { cacheReadTokens: this.cacheRead } : {},
|
|
269
|
-
...this.cacheWrite > 0 ? { cacheWriteTokens: this.cacheWrite } : {},
|
|
270
|
-
...this.reasoning > 0 ? { reasoningTokens: this.reasoning } : {},
|
|
271
|
-
totalTokens: this.input + this.output,
|
|
272
|
-
...this.requests.length > 1 ? { requests: this.requests.slice() } : {}
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
// src/tool-error.ts
|
|
278
|
-
var ToolError = class extends chunkA44COQJJ_cjs.TheokitAgentError {
|
|
279
|
-
name = "ToolError";
|
|
280
|
-
/** The error content surfaced to the model: a string, or text/image blocks. */
|
|
281
|
-
content;
|
|
282
|
-
constructor(content, options = {}) {
|
|
283
|
-
super(renderToolErrorMessage(content), { ...options, isRetryable: false });
|
|
284
|
-
this.content = content;
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
function renderToolErrorMessage(content) {
|
|
288
|
-
if (typeof content === "string") return content;
|
|
289
|
-
return content.map((block) => block.type === "text" ? block.text : `[${block.source.media_type} image]`).join("\n");
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// src/internal/budget/pricing-data.json
|
|
293
|
-
var pricing_data_default = {
|
|
294
|
-
_meta: {
|
|
295
|
-
pricingVersion: "litellm-2026-05-snapshot"},
|
|
296
|
-
models: {
|
|
297
|
-
"anthropic/claude-opus-4-7": {
|
|
298
|
-
input: 5,
|
|
299
|
-
output: 25,
|
|
300
|
-
cacheRead: 0.5,
|
|
301
|
-
cacheWrite: 6.25
|
|
302
|
-
},
|
|
303
|
-
"anthropic/claude-opus-4-6": {
|
|
304
|
-
input: 5,
|
|
305
|
-
output: 25,
|
|
306
|
-
cacheRead: 0.5,
|
|
307
|
-
cacheWrite: 6.25
|
|
308
|
-
},
|
|
309
|
-
"anthropic/claude-opus-4-5": {
|
|
310
|
-
input: 5,
|
|
311
|
-
output: 25,
|
|
312
|
-
cacheRead: 0.5,
|
|
313
|
-
cacheWrite: 6.25
|
|
314
|
-
},
|
|
315
|
-
"anthropic/claude-sonnet-4-6": {
|
|
316
|
-
input: 3,
|
|
317
|
-
output: 15,
|
|
318
|
-
cacheRead: 0.3,
|
|
319
|
-
cacheWrite: 3.75
|
|
320
|
-
},
|
|
321
|
-
"anthropic/claude-sonnet-4-5": {
|
|
322
|
-
input: 3,
|
|
323
|
-
output: 15,
|
|
324
|
-
cacheRead: 0.3,
|
|
325
|
-
cacheWrite: 3.75
|
|
326
|
-
},
|
|
327
|
-
"anthropic/claude-haiku-4-5": {
|
|
328
|
-
input: 1,
|
|
329
|
-
output: 5,
|
|
330
|
-
cacheRead: 0.1,
|
|
331
|
-
cacheWrite: 1.25
|
|
332
|
-
},
|
|
333
|
-
"anthropic/claude-3-5-sonnet": {
|
|
334
|
-
input: 3,
|
|
335
|
-
output: 15,
|
|
336
|
-
cacheRead: 0.3,
|
|
337
|
-
cacheWrite: 3.75
|
|
338
|
-
},
|
|
339
|
-
"anthropic/claude-3-5-haiku": {
|
|
340
|
-
input: 0.8,
|
|
341
|
-
output: 4,
|
|
342
|
-
cacheRead: 0.08,
|
|
343
|
-
cacheWrite: 1
|
|
344
|
-
},
|
|
345
|
-
"anthropic/claude-3-opus": {
|
|
346
|
-
input: 15,
|
|
347
|
-
output: 75,
|
|
348
|
-
cacheRead: 1.5,
|
|
349
|
-
cacheWrite: 18.75
|
|
350
|
-
},
|
|
351
|
-
"anthropic/claude-3-haiku": {
|
|
352
|
-
input: 0.25,
|
|
353
|
-
output: 1.25,
|
|
354
|
-
cacheRead: 0.03,
|
|
355
|
-
cacheWrite: 0.3
|
|
356
|
-
},
|
|
357
|
-
"openai/gpt-4o": {
|
|
358
|
-
input: 2.5,
|
|
359
|
-
output: 10,
|
|
360
|
-
cacheRead: 1.25
|
|
361
|
-
},
|
|
362
|
-
"openai/gpt-4o-mini": {
|
|
363
|
-
input: 0.15,
|
|
364
|
-
output: 0.6,
|
|
365
|
-
cacheRead: 0.075
|
|
366
|
-
},
|
|
367
|
-
"openai/gpt-4.1": {
|
|
368
|
-
input: 2,
|
|
369
|
-
output: 8,
|
|
370
|
-
cacheRead: 0.5
|
|
371
|
-
},
|
|
372
|
-
"openai/gpt-4.1-mini": {
|
|
373
|
-
input: 0.4,
|
|
374
|
-
output: 1.6,
|
|
375
|
-
cacheRead: 0.1
|
|
376
|
-
},
|
|
377
|
-
"openai/gpt-4.1-nano": {
|
|
378
|
-
input: 0.1,
|
|
379
|
-
output: 0.4,
|
|
380
|
-
cacheRead: 0.025
|
|
381
|
-
},
|
|
382
|
-
"openai/o3": {
|
|
383
|
-
input: 2,
|
|
384
|
-
output: 8,
|
|
385
|
-
cacheRead: 0.5
|
|
386
|
-
},
|
|
387
|
-
"openai/o3-mini": {
|
|
388
|
-
input: 1.1,
|
|
389
|
-
output: 4.4,
|
|
390
|
-
cacheRead: 0.55
|
|
391
|
-
},
|
|
392
|
-
"openai/o4-mini": {
|
|
393
|
-
input: 1.1,
|
|
394
|
-
output: 4.4,
|
|
395
|
-
cacheRead: 0.275
|
|
396
|
-
},
|
|
397
|
-
"deepseek/deepseek-chat": {
|
|
398
|
-
input: 0.14,
|
|
399
|
-
output: 0.28
|
|
400
|
-
},
|
|
401
|
-
"deepseek/deepseek-reasoner": {
|
|
402
|
-
input: 0.55,
|
|
403
|
-
output: 2.19
|
|
404
|
-
},
|
|
405
|
-
"google/gemini-2.5-pro": {
|
|
406
|
-
input: 1.25,
|
|
407
|
-
output: 10
|
|
408
|
-
},
|
|
409
|
-
"google/gemini-2.5-flash": {
|
|
410
|
-
input: 0.15,
|
|
411
|
-
output: 0.6
|
|
412
|
-
},
|
|
413
|
-
"google/gemini-2.0-flash": {
|
|
414
|
-
input: 0.1,
|
|
415
|
-
output: 0.4
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
// src/internal/budget/pricing-registry.ts
|
|
421
|
-
var data = pricing_data_default;
|
|
422
|
-
function buildEntry(key, raw) {
|
|
423
|
-
const [provider, ...modelParts] = key.split("/");
|
|
424
|
-
return {
|
|
425
|
-
provider: provider ?? "unknown",
|
|
426
|
-
model: modelParts.join("/"),
|
|
427
|
-
inputCostPerMillion: raw.input,
|
|
428
|
-
outputCostPerMillion: raw.output,
|
|
429
|
-
...raw.cacheRead !== void 0 ? { cacheReadCostPerMillion: raw.cacheRead } : {},
|
|
430
|
-
...raw.cacheWrite !== void 0 ? { cacheWriteCostPerMillion: raw.cacheWrite } : {},
|
|
431
|
-
...raw.reasoning !== void 0 ? { reasoningCostPerMillion: raw.reasoning } : {},
|
|
432
|
-
pricingVersion: data._meta.pricingVersion
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
function stripDateSuffix(model) {
|
|
436
|
-
return model.replace(/-\d{4}-?\d{2}-?\d{2}$/, "");
|
|
437
|
-
}
|
|
438
|
-
function normalizeAnthropicDots(model) {
|
|
439
|
-
return model.replace(/(\d+)\.(\d+)/g, "$1-$2");
|
|
440
|
-
}
|
|
441
|
-
function stripOpenRouterPrefix(modelId) {
|
|
442
|
-
return modelId.startsWith("openrouter/") ? modelId.slice("openrouter/".length) : modelId;
|
|
443
|
-
}
|
|
444
|
-
function lookupRaw(key) {
|
|
445
|
-
return data.models[key];
|
|
446
|
-
}
|
|
447
|
-
function getPricingEntry(opts) {
|
|
448
|
-
const cleaned = stripOpenRouterPrefix(opts.model);
|
|
449
|
-
const directKey = `${opts.provider}/${cleaned}`;
|
|
450
|
-
const direct = lookupRaw(directKey);
|
|
451
|
-
if (direct !== void 0) return buildEntry(directKey, direct);
|
|
452
|
-
const noSuffix = stripDateSuffix(cleaned);
|
|
453
|
-
if (noSuffix !== cleaned) {
|
|
454
|
-
const noSuffixKey = `${opts.provider}/${noSuffix}`;
|
|
455
|
-
const found = lookupRaw(noSuffixKey);
|
|
456
|
-
if (found !== void 0) return buildEntry(noSuffixKey, found);
|
|
457
|
-
}
|
|
458
|
-
if (opts.provider === "anthropic") {
|
|
459
|
-
const normalized = normalizeAnthropicDots(stripDateSuffix(cleaned));
|
|
460
|
-
const normKey = `${opts.provider}/${normalized}`;
|
|
461
|
-
const found = lookupRaw(normKey);
|
|
462
|
-
if (found !== void 0) return buildEntry(normKey, found);
|
|
463
|
-
}
|
|
464
|
-
if (cleaned.includes("/")) {
|
|
465
|
-
const found = lookupRaw(cleaned);
|
|
466
|
-
if (found !== void 0) return buildEntry(cleaned, found);
|
|
467
|
-
const stripped = stripDateSuffix(cleaned);
|
|
468
|
-
if (stripped !== cleaned) {
|
|
469
|
-
const found2 = lookupRaw(stripped);
|
|
470
|
-
if (found2 !== void 0) return buildEntry(stripped, found2);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
const catalogEntry = catalogCostFallback(opts.provider, cleaned);
|
|
474
|
-
if (catalogEntry !== void 0) return catalogEntry;
|
|
475
|
-
return void 0;
|
|
476
|
-
}
|
|
477
|
-
function catalogCostFallback(provider, cleanedModel) {
|
|
478
|
-
const stripped = stripDateSuffix(cleanedModel);
|
|
479
|
-
const candidates = [`${provider}/${cleanedModel}`, cleanedModel];
|
|
480
|
-
if (stripped !== cleanedModel) candidates.push(`${provider}/${stripped}`, stripped);
|
|
481
|
-
for (const key of candidates) {
|
|
482
|
-
const info = chunkD42XHI4O_cjs.getCatalogModelInfo(key);
|
|
483
|
-
const cost = info?.cost;
|
|
484
|
-
if (cost === void 0) continue;
|
|
485
|
-
const [prov, ...modelParts] = key.split("/");
|
|
486
|
-
return {
|
|
487
|
-
provider: prov ?? provider,
|
|
488
|
-
model: modelParts.join("/") || cleanedModel,
|
|
489
|
-
inputCostPerMillion: cost.input,
|
|
490
|
-
outputCostPerMillion: cost.output,
|
|
491
|
-
...cost.cache_read !== void 0 ? { cacheReadCostPerMillion: cost.cache_read } : {},
|
|
492
|
-
...cost.cache_write !== void 0 ? { cacheWriteCostPerMillion: cost.cache_write } : {},
|
|
493
|
-
// M44 M5 fix — honest provenance: a key patched by the LIVE models-dev source is not "vendored".
|
|
494
|
-
pricingVersion: chunkD42XHI4O_cjs.isPatchedModelKey(key) ? "catalog-models-dev" : "catalog-vendored"
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
return void 0;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// src/internal/budget/compute-cost.ts
|
|
501
|
-
var MICROCENT = 1e6;
|
|
502
|
-
function isSubscriptionIncluded(provider) {
|
|
503
|
-
return provider === "openai-codex" || provider === "codex";
|
|
504
|
-
}
|
|
505
|
-
function pricingHasValidRates(entry) {
|
|
506
|
-
return entry.inputCostPerMillion >= 0 && entry.outputCostPerMillion >= 0 && (entry.cacheReadCostPerMillion === void 0 || entry.cacheReadCostPerMillion >= 0) && (entry.cacheWriteCostPerMillion === void 0 || entry.cacheWriteCostPerMillion >= 0) && (entry.reasoningCostPerMillion === void 0 || entry.reasoningCostPerMillion >= 0);
|
|
507
|
-
}
|
|
508
|
-
function costForTokens(tokens, perMillion) {
|
|
509
|
-
if (tokens === 0 || perMillion === 0) return 0;
|
|
510
|
-
return Math.round(tokens * perMillion * MICROCENT / 1e6) / MICROCENT;
|
|
511
|
-
}
|
|
512
|
-
function computeCost(args) {
|
|
513
|
-
if (isSubscriptionIncluded(args.provider)) {
|
|
514
|
-
return {
|
|
515
|
-
amountUsd: 0,
|
|
516
|
-
status: "included",
|
|
517
|
-
currency: "USD",
|
|
518
|
-
source: "subscription_included",
|
|
519
|
-
pricingVersion: void 0
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
const entry = getPricingEntry({
|
|
523
|
-
provider: args.provider,
|
|
524
|
-
model: args.model,
|
|
525
|
-
...args.baseUrl !== void 0 ? { baseUrl: args.baseUrl } : {}
|
|
526
|
-
});
|
|
527
|
-
if (entry === void 0) {
|
|
528
|
-
return {
|
|
529
|
-
amountUsd: void 0,
|
|
530
|
-
status: "unknown",
|
|
531
|
-
currency: "USD",
|
|
532
|
-
source: "unknown",
|
|
533
|
-
pricingVersion: void 0
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
if (!pricingHasValidRates(entry)) {
|
|
537
|
-
return {
|
|
538
|
-
amountUsd: void 0,
|
|
539
|
-
status: "unknown",
|
|
540
|
-
currency: "USD",
|
|
541
|
-
source: "unknown",
|
|
542
|
-
pricingVersion: entry.pricingVersion,
|
|
543
|
-
notes: ["pricing entry has negative rates; treated as invalid"]
|
|
544
|
-
};
|
|
106
|
+
agentId(id) {
|
|
107
|
+
this.opts.agentId = id;
|
|
108
|
+
return this;
|
|
545
109
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
detail.output = outputCost;
|
|
553
|
-
let total = inputCost + outputCost;
|
|
554
|
-
if (u.cacheReadTokens !== void 0 && u.cacheReadTokens > 0) {
|
|
555
|
-
if (entry.cacheReadCostPerMillion === void 0) {
|
|
556
|
-
return {
|
|
557
|
-
amountUsd: void 0,
|
|
558
|
-
status: "unknown",
|
|
559
|
-
currency: "USD",
|
|
560
|
-
source: "litellm_snapshot",
|
|
561
|
-
pricingVersion: entry.pricingVersion,
|
|
562
|
-
notes: ["cache-read tokens present but cacheReadCostPerMillion is undefined"]
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
const c = costForTokens(u.cacheReadTokens, entry.cacheReadCostPerMillion);
|
|
566
|
-
detail.cacheRead = c;
|
|
567
|
-
total += c;
|
|
110
|
+
/**
|
|
111
|
+
* Synchronous snapshot of the accumulated options. Returns a SHALLOW CLONE
|
|
112
|
+
* so external mutation of the result doesn't pollute the builder state (EC-2).
|
|
113
|
+
*/
|
|
114
|
+
build() {
|
|
115
|
+
return { ...this.opts };
|
|
568
116
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Validate + create a fresh agent. Delegates to `Agent.create` via the
|
|
119
|
+
* injected `deps.create`. Throws if the builder was instantiated without
|
|
120
|
+
* deps (i.e., direct `new AgentBuilder()` instead of `Agent.builder()`).
|
|
121
|
+
*/
|
|
122
|
+
create() {
|
|
123
|
+
if (this.deps === void 0) {
|
|
124
|
+
return Promise.reject(
|
|
125
|
+
new Error(
|
|
126
|
+
"AgentBuilder.create() requires Agent.builder() entry \u2014 direct construction has no terminals."
|
|
127
|
+
)
|
|
128
|
+
);
|
|
579
129
|
}
|
|
580
|
-
|
|
581
|
-
detail.cacheWrite = c;
|
|
582
|
-
total += c;
|
|
130
|
+
return this.deps.create(this.build());
|
|
583
131
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
if (
|
|
590
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Resume an existing agent or create one if the ID is unknown. Delegates to
|
|
134
|
+
* `Agent.getOrCreate` via the injected `deps.getOrCreate` (ADR D22).
|
|
135
|
+
*/
|
|
136
|
+
getOrCreate(agentId) {
|
|
137
|
+
if (this.deps === void 0) {
|
|
138
|
+
return Promise.reject(
|
|
139
|
+
new Error(
|
|
140
|
+
"AgentBuilder.getOrCreate() requires Agent.builder() entry \u2014 direct construction has no terminals."
|
|
141
|
+
)
|
|
142
|
+
);
|
|
591
143
|
}
|
|
144
|
+
return this.deps.getOrCreate(agentId, this.build());
|
|
592
145
|
}
|
|
593
|
-
|
|
594
|
-
return {
|
|
595
|
-
amountUsd,
|
|
596
|
-
status: "estimated",
|
|
597
|
-
currency: "USD",
|
|
598
|
-
source: "litellm_snapshot",
|
|
599
|
-
pricingVersion: entry.pricingVersion,
|
|
600
|
-
...notes.length > 0 ? { notes } : {},
|
|
601
|
-
detail
|
|
602
|
-
};
|
|
603
|
-
}
|
|
146
|
+
};
|
|
604
147
|
|
|
605
148
|
// src/internal/auth/api-key-validator.ts
|
|
606
149
|
var FIXTURE_KEY_PREFIX = "theo_test_";
|
|
@@ -735,6 +278,48 @@ function structurableAnswerOrThrow(result, GenerateObjectError) {
|
|
|
735
278
|
}
|
|
736
279
|
return answer;
|
|
737
280
|
}
|
|
281
|
+
|
|
282
|
+
// src/internal/env.ts
|
|
283
|
+
var API_KEY_ENV_VAR = "THEOKIT_API_KEY";
|
|
284
|
+
function resolveApiKey(explicit) {
|
|
285
|
+
if (explicit !== void 0 && explicit.length > 0) {
|
|
286
|
+
return explicit;
|
|
287
|
+
}
|
|
288
|
+
const fromEnv = process.env[API_KEY_ENV_VAR];
|
|
289
|
+
if (fromEnv !== void 0 && fromEnv.length > 0) {
|
|
290
|
+
return fromEnv;
|
|
291
|
+
}
|
|
292
|
+
return void 0;
|
|
293
|
+
}
|
|
294
|
+
var PREFIX = {
|
|
295
|
+
localAgent: "agent-",
|
|
296
|
+
cloudAgent: "bc-",
|
|
297
|
+
run: "run-",
|
|
298
|
+
call: "call-",
|
|
299
|
+
cron: "cron-",
|
|
300
|
+
request: "request-"
|
|
301
|
+
};
|
|
302
|
+
function generateLocalAgentId() {
|
|
303
|
+
return `${PREFIX.localAgent}${crypto.randomUUID()}`;
|
|
304
|
+
}
|
|
305
|
+
function generateCloudAgentId() {
|
|
306
|
+
return `${PREFIX.cloudAgent}${crypto.randomUUID()}`;
|
|
307
|
+
}
|
|
308
|
+
function generateRunId() {
|
|
309
|
+
return `${PREFIX.run}${crypto.randomUUID()}`;
|
|
310
|
+
}
|
|
311
|
+
function generateCallId() {
|
|
312
|
+
return `${PREFIX.call}${crypto.randomUUID()}`;
|
|
313
|
+
}
|
|
314
|
+
function generateCronId() {
|
|
315
|
+
return `${PREFIX.cron}${crypto.randomUUID()}`;
|
|
316
|
+
}
|
|
317
|
+
function generateRequestId() {
|
|
318
|
+
return `${PREFIX.request}${crypto.randomUUID()}`;
|
|
319
|
+
}
|
|
320
|
+
function isLocalAgentId(id) {
|
|
321
|
+
return id.startsWith(PREFIX.localAgent);
|
|
322
|
+
}
|
|
738
323
|
var FIXTURE_API_KEY_PREFIX = "theo_test_";
|
|
739
324
|
function isFixtureApiKey(apiKey) {
|
|
740
325
|
if (apiKey === void 0) return false;
|
|
@@ -1351,7 +936,7 @@ async function readLegacyFacts(jsonPath) {
|
|
|
1351
936
|
}
|
|
1352
937
|
async function writeMigratedFacts(cwd, jsonPath, facts) {
|
|
1353
938
|
try {
|
|
1354
|
-
for (const fact of facts) await
|
|
939
|
+
for (const fact of facts) await chunkJLMXKTBX_cjs.appendFactToMarkdown(cwd, fact);
|
|
1355
940
|
await promises.unlink(jsonPath).catch(() => void 0);
|
|
1356
941
|
process.stderr.write(
|
|
1357
942
|
`[theokit-sdk] migrated ${facts.length} fact(s) from ${jsonPath} to MEMORY.md
|
|
@@ -1370,11 +955,11 @@ async function migrateLegacyJson(cwd, config) {
|
|
|
1370
955
|
const key = `${cwd}::${config.namespace ?? "default"}::${config.scope ?? "agent"}::${config.userId ?? "default"}`;
|
|
1371
956
|
if (migrationRun.has(key)) return { migrated: false, factCount: 0, reason: "already-migrated" };
|
|
1372
957
|
migrationRun.add(key);
|
|
1373
|
-
const jsonPath =
|
|
958
|
+
const jsonPath = chunkJLMXKTBX_cjs.legacyMemoryJsonPath(cwd, config);
|
|
1374
959
|
if (!await fileExists(jsonPath)) {
|
|
1375
960
|
return { migrated: false, factCount: 0, reason: "no-legacy-json" };
|
|
1376
961
|
}
|
|
1377
|
-
if (await fileExists(
|
|
962
|
+
if (await fileExists(chunkJLMXKTBX_cjs.memoryMdPath(cwd))) {
|
|
1378
963
|
process.stderr.write(
|
|
1379
964
|
`[theokit-sdk] memory migration skipped: both MEMORY.md and legacy JSON exist at ${jsonPath}; leaving both intact
|
|
1380
965
|
`
|
|
@@ -1399,13 +984,13 @@ function extractMemoryFact(message) {
|
|
|
1399
984
|
async function readMemoryFacts(cwd, config) {
|
|
1400
985
|
if (!config.enabled) return [];
|
|
1401
986
|
await migrateLegacyJson(cwd, config);
|
|
1402
|
-
return
|
|
987
|
+
return chunkJLMXKTBX_cjs.readFacts(cwd, config);
|
|
1403
988
|
}
|
|
1404
989
|
async function appendMemoryFact(cwd, config, fact) {
|
|
1405
990
|
if (!config.enabled) return;
|
|
1406
991
|
await migrateLegacyJson(cwd, config);
|
|
1407
992
|
const sanitized = { text: chunkBEURCLDV_cjs.redactSecrets(fact.text) };
|
|
1408
|
-
await
|
|
993
|
+
await chunkJLMXKTBX_cjs.appendFact(cwd, config, sanitized);
|
|
1409
994
|
}
|
|
1410
995
|
|
|
1411
996
|
// src/internal/runtime/fixtures/fixture-scripts.ts
|
|
@@ -3186,7 +2771,7 @@ async function runPostRunLifecycle(inputs) {
|
|
|
3186
2771
|
if (memoryProvider?.recordSessionSummary !== void 0) {
|
|
3187
2772
|
await memoryProvider.recordSessionSummary(summaryArgs);
|
|
3188
2773
|
} else {
|
|
3189
|
-
await
|
|
2774
|
+
await chunkJLMXKTBX_cjs.writeSessionSummary(summaryArgs);
|
|
3190
2775
|
}
|
|
3191
2776
|
if (!shouldUsePortMemoryPath()) {
|
|
3192
2777
|
void memoryGlue.syncIfReady();
|
|
@@ -3385,126 +2970,52 @@ var LiveAgentRegistry = class {
|
|
|
3385
2970
|
}
|
|
3386
2971
|
};
|
|
3387
2972
|
var liveAgentRegistry = new LiveAgentRegistry();
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
}
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
}
|
|
3400
|
-
}
|
|
3401
|
-
return result;
|
|
3402
|
-
}
|
|
3403
|
-
async function readProjectSubagents(cwd) {
|
|
3404
|
-
const root = path.join(cwd, ".theokit", "agents");
|
|
3405
|
-
const entries = await chunkLSLPF6OI_cjs.readWorkspaceDir(root, "subagents_read_error", "subagents directory");
|
|
3406
|
-
const subagents = {};
|
|
3407
|
-
for (const entry of entries) {
|
|
3408
|
-
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
3409
|
-
const path$1 = path.join(root, entry.name);
|
|
3410
|
-
const raw = await promises.readFile(path$1, "utf8");
|
|
3411
|
-
const definition = parseSubagentMarkdown(raw, entry.name);
|
|
3412
|
-
subagents[definition.name] = definition.definition;
|
|
3413
|
-
}
|
|
3414
|
-
return subagents;
|
|
3415
|
-
}
|
|
3416
|
-
var ACCEPTED_FIELDS = /* @__PURE__ */ new Set([
|
|
3417
|
-
"name",
|
|
3418
|
-
"description",
|
|
3419
|
-
"model",
|
|
3420
|
-
"tools",
|
|
3421
|
-
"reasoning_effort",
|
|
3422
|
-
"mcp",
|
|
3423
|
-
"sandbox"
|
|
3424
|
-
]);
|
|
3425
|
-
function parseSubagentMarkdown(raw, filename) {
|
|
3426
|
-
const { frontmatter, body } = splitFrontmatter(raw, filename);
|
|
3427
|
-
const fields = parseFrontmatterFields(frontmatter);
|
|
3428
|
-
rejectUnknownFields(fields, filename);
|
|
3429
|
-
rejectMcp(fields, filename);
|
|
3430
|
-
const definition = {
|
|
3431
|
-
description: asString(fields.description) ?? "",
|
|
3432
|
-
prompt: body
|
|
3433
|
-
};
|
|
3434
|
-
const model = resolveModel(fields, filename);
|
|
3435
|
-
if (model !== void 0) definition.model = model;
|
|
3436
|
-
const tools = toStringList(fields.tools);
|
|
3437
|
-
if (tools.length > 0) definition.tools = tools;
|
|
3438
|
-
const sandbox = resolveSandbox(fields, filename);
|
|
3439
|
-
if (sandbox !== void 0) definition.sandbox = sandbox;
|
|
3440
|
-
const name = asString(fields.name) ?? filename.replace(/\.md$/, "");
|
|
3441
|
-
return { name, definition };
|
|
3442
|
-
}
|
|
3443
|
-
function rejectUnknownFields(fields, filename) {
|
|
3444
|
-
for (const key of Object.keys(fields)) {
|
|
3445
|
-
if (!ACCEPTED_FIELDS.has(key)) {
|
|
3446
|
-
throw new chunkA44COQJJ_cjs.ConfigurationError(
|
|
3447
|
-
`Subagent ${filename}: unknown frontmatter field "${key}" (accepted: ${[...ACCEPTED_FIELDS].join(", ")})`,
|
|
3448
|
-
{ code: "subagent_unknown_field" }
|
|
3449
|
-
);
|
|
3450
|
-
}
|
|
3451
|
-
}
|
|
2973
|
+
|
|
2974
|
+
// src/define-tool.ts
|
|
2975
|
+
var TOOL_SPLIT_RESOLVER = /* @__PURE__ */ Symbol("theokit.toolSplitResolver");
|
|
2976
|
+
async function runValidated(spec, input, ctx) {
|
|
2977
|
+
const raw = spec.sanitize ? chunk6JSIEDKL_cjs.sanitizeToolInput(input, {
|
|
2978
|
+
...spec.sanitize === true ? {} : spec.sanitize,
|
|
2979
|
+
schema: spec.inputSchema
|
|
2980
|
+
}).value : input;
|
|
2981
|
+
const parsed = spec.inputSchema.parse(raw);
|
|
2982
|
+
const out = await spec.handler(parsed, ctx);
|
|
2983
|
+
return spec.outputSchema === void 0 ? out : spec.outputSchema.parse(out);
|
|
3452
2984
|
}
|
|
3453
|
-
function
|
|
3454
|
-
|
|
3455
|
-
throw new chunkA44COQJJ_cjs.ConfigurationError(
|
|
3456
|
-
`Subagent ${filename}: per-subagent "mcp" is not yet supported on the local delegation path; declare MCP servers in .theokit/mcp.json (or the parent) instead`,
|
|
3457
|
-
{ code: "subagent_mcp_unsupported_local" }
|
|
3458
|
-
);
|
|
3459
|
-
}
|
|
2985
|
+
function serializeOutput(validated) {
|
|
2986
|
+
return typeof validated === "string" ? validated : JSON.stringify(validated);
|
|
3460
2987
|
}
|
|
3461
|
-
function
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
if (effort !== void 0 && (modelId === void 0 || modelId === "inherit")) {
|
|
3465
|
-
throw new chunkA44COQJJ_cjs.ConfigurationError(
|
|
3466
|
-
`Subagent ${filename}: reasoning_effort requires a concrete model (effort is a model parameter; an absent model or "inherit" cannot carry it)`,
|
|
3467
|
-
{ code: "subagent_reasoning_effort_without_model" }
|
|
3468
|
-
);
|
|
3469
|
-
}
|
|
3470
|
-
if (modelId === void 0) return void 0;
|
|
3471
|
-
if (modelId === "inherit") return "inherit";
|
|
3472
|
-
return effort !== void 0 ? { id: modelId, params: [{ id: "thinking", value: effort }] } : { id: modelId };
|
|
2988
|
+
function shapeModelOutput(spec, validated) {
|
|
2989
|
+
if (spec.toModelOutput !== void 0) return spec.toModelOutput(validated);
|
|
2990
|
+
return serializeOutput(validated);
|
|
3473
2991
|
}
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
if (typeof fields.sandbox !== "boolean") {
|
|
3477
|
-
throw new chunkA44COQJJ_cjs.ConfigurationError(
|
|
3478
|
-
`Subagent ${filename}: sandbox must be a boolean (got "${String(fields.sandbox)}"); granular sandbox modes are not supported by the runtime`,
|
|
3479
|
-
{ code: "subagent_sandbox_not_boolean" }
|
|
3480
|
-
);
|
|
2992
|
+
var Tool = class {
|
|
2993
|
+
constructor() {
|
|
3481
2994
|
}
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
function asString(v) {
|
|
3485
|
-
if (typeof v !== "string") return void 0;
|
|
3486
|
-
const m = /^(["'])(.*)\1$/.exec(v);
|
|
3487
|
-
return m ? m[2] : v;
|
|
3488
|
-
}
|
|
3489
|
-
function toStringList(v) {
|
|
3490
|
-
if (Array.isArray(v)) return v.map((t) => t.trim()).filter((t) => t.length > 0);
|
|
3491
|
-
if (typeof v === "string") {
|
|
3492
|
-
return v.split(/[\s,]+/).map((t) => t.trim()).filter((t) => t.length > 0);
|
|
2995
|
+
static create(spec) {
|
|
2996
|
+
return defineTool(spec);
|
|
3493
2997
|
}
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
2998
|
+
};
|
|
2999
|
+
function defineTool(spec) {
|
|
3000
|
+
const inputSchema = chunkWJVHMTKB_cjs.toJsonSchema(spec.inputSchema, {
|
|
3001
|
+
unrepresentable: "any"
|
|
3002
|
+
});
|
|
3003
|
+
const handler = async (input, ctx) => {
|
|
3004
|
+
const validated = await runValidated(spec, input, ctx);
|
|
3005
|
+
return shapeModelOutput(spec, validated);
|
|
3006
|
+
};
|
|
3007
|
+
const tool = { name: spec.name, description: spec.description, inputSchema, handler };
|
|
3008
|
+
if (spec.toModelOutput !== void 0) {
|
|
3009
|
+
const resolver = async (input, ctx) => {
|
|
3010
|
+
const validated = await runValidated(spec, input, ctx);
|
|
3011
|
+
return { model: shapeModelOutput(spec, validated), app: serializeOutput(validated) };
|
|
3012
|
+
};
|
|
3013
|
+
handler[TOOL_SPLIT_RESOLVER] = resolver;
|
|
3502
3014
|
}
|
|
3503
|
-
return
|
|
3504
|
-
}
|
|
3505
|
-
function parseFrontmatterFields(frontmatter) {
|
|
3506
|
-
return chunkLSLPF6OI_cjs.parseSimpleYaml(frontmatter);
|
|
3015
|
+
return tool;
|
|
3507
3016
|
}
|
|
3017
|
+
|
|
3018
|
+
// src/internal/runtime/reasoning/native-reasoning.ts
|
|
3508
3019
|
var NATIVE_REASONING_PARAM_IDS = /* @__PURE__ */ new Set(["thinking", "reasoning", "reasoning_effort"]);
|
|
3509
3020
|
var REASONING_PREAMBLE = "Think step by step before answering: use the `think` tool to reason through each step, validate your work, then answer. Reason about magnitude before comparing numbers.";
|
|
3510
3021
|
function createThinkTool() {
|
|
@@ -3558,7 +3069,7 @@ var SkillsManager = class {
|
|
|
3558
3069
|
}
|
|
3559
3070
|
async refresh() {
|
|
3560
3071
|
const skillsRoot = this.skillsDir ?? path.join(this.cwd, ".theokit", "skills");
|
|
3561
|
-
const discovered = await
|
|
3072
|
+
const discovered = await chunkDHLZIMP6_cjs.discoverSkills(skillsRoot, {
|
|
3562
3073
|
onInvalidSkill: (info) => {
|
|
3563
3074
|
process.stderr.write(
|
|
3564
3075
|
`[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
|
|
@@ -3586,7 +3097,7 @@ var SkillsManager = class {
|
|
|
3586
3097
|
async get(name) {
|
|
3587
3098
|
const skill = this.skills.find((s) => s.name === name);
|
|
3588
3099
|
if (skill === void 0) return void 0;
|
|
3589
|
-
const instructions = typeof skill.instructions === "string" ? skill.instructions :
|
|
3100
|
+
const instructions = typeof skill.instructions === "string" ? skill.instructions : chunkDHLZIMP6_cjs.stripSkillFrontmatter(await promises.readFile(skill.source, "utf8"));
|
|
3590
3101
|
const references = skill.references;
|
|
3591
3102
|
return {
|
|
3592
3103
|
name: skill.name,
|
|
@@ -3686,7 +3197,7 @@ var ActiveMemoryPromptProvider = class {
|
|
|
3686
3197
|
if (ctx.activeMemorySummary === void 0 || ctx.activeMemorySummary.length === 0) {
|
|
3687
3198
|
return Promise.resolve(void 0);
|
|
3688
3199
|
}
|
|
3689
|
-
const body =
|
|
3200
|
+
const body = chunkDHLZIMP6_cjs.escapeBlockBody(ctx.activeMemorySummary);
|
|
3690
3201
|
return Promise.resolve(`<active-memory>
|
|
3691
3202
|
${body}
|
|
3692
3203
|
</active-memory>`);
|
|
@@ -3739,7 +3250,7 @@ function formatSource(name, tokens) {
|
|
|
3739
3250
|
if (tokens.length === 0) {
|
|
3740
3251
|
return ` <source name="${escapeAttribute(name)}" />`;
|
|
3741
3252
|
}
|
|
3742
|
-
const body =
|
|
3253
|
+
const body = chunkDHLZIMP6_cjs.escapeBlockBody(tokens.join(" "));
|
|
3743
3254
|
return ` <source name="${escapeAttribute(name)}">
|
|
3744
3255
|
${body}
|
|
3745
3256
|
</source>`;
|
|
@@ -3755,7 +3266,7 @@ var MemoryPromptProvider = class {
|
|
|
3755
3266
|
contribute(ctx) {
|
|
3756
3267
|
if (ctx.memoryAutoInject === false) return Promise.resolve(void 0);
|
|
3757
3268
|
if (ctx.memory.length === 0) return Promise.resolve(void 0);
|
|
3758
|
-
const lines = ctx.memory.map((fact) => ` - ${
|
|
3269
|
+
const lines = ctx.memory.map((fact) => ` - ${chunkDHLZIMP6_cjs.escapeBlockBody(fact.text)}`);
|
|
3759
3270
|
return Promise.resolve(`<memory>
|
|
3760
3271
|
${lines.join("\n")}
|
|
3761
3272
|
</memory>`);
|
|
@@ -3777,7 +3288,7 @@ var SkillsPromptProvider = class {
|
|
|
3777
3288
|
priority = 20;
|
|
3778
3289
|
contribute(ctx) {
|
|
3779
3290
|
if (ctx.skillsAutoInject === false) return Promise.resolve(void 0);
|
|
3780
|
-
return Promise.resolve(
|
|
3291
|
+
return Promise.resolve(chunkDHLZIMP6_cjs.buildSkillsBlock(ctx.skills));
|
|
3781
3292
|
}
|
|
3782
3293
|
};
|
|
3783
3294
|
|
|
@@ -4039,7 +3550,7 @@ var HISTOGRAM_NAMES = {
|
|
|
4039
3550
|
};
|
|
4040
3551
|
function safeRequire(moduleName) {
|
|
4041
3552
|
try {
|
|
4042
|
-
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
3553
|
+
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-GWMQ5CS3.cjs', document.baseURI).href)));
|
|
4043
3554
|
return r(moduleName);
|
|
4044
3555
|
} catch {
|
|
4045
3556
|
return void 0;
|
|
@@ -4264,7 +3775,7 @@ var cachedOtel;
|
|
|
4264
3775
|
function loadOtel() {
|
|
4265
3776
|
if (cachedOtel === void 0) {
|
|
4266
3777
|
try {
|
|
4267
|
-
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
3778
|
+
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-GWMQ5CS3.cjs', document.baseURI).href)));
|
|
4268
3779
|
const mod = r("@opentelemetry/api");
|
|
4269
3780
|
cachedOtel = mod;
|
|
4270
3781
|
} catch {
|
|
@@ -4501,8 +4012,8 @@ async function loadMarkdownEntities(opts) {
|
|
|
4501
4012
|
await assertFileSizeUnderCap(resolved.source, errorCodePrefix);
|
|
4502
4013
|
const raw = await promises.readFile(resolved.source, "utf8").catch(() => null);
|
|
4503
4014
|
if (raw === null) continue;
|
|
4504
|
-
const split =
|
|
4505
|
-
const fields =
|
|
4015
|
+
const split = splitFrontmatter(raw, resolved.source, errorCodePrefix);
|
|
4016
|
+
const fields = chunkLALRCFSN_cjs.parseSimpleYaml(split.frontmatter);
|
|
4506
4017
|
const parsed = schema.safeParse(fields);
|
|
4507
4018
|
if (!parsed.success) {
|
|
4508
4019
|
throw new chunkA44COQJJ_cjs.ConfigurationError(
|
|
@@ -4552,7 +4063,7 @@ function resolveEntryPath(entry, pattern, dir) {
|
|
|
4552
4063
|
if (!entry.isDirectory()) return null;
|
|
4553
4064
|
return { slug: entry.name, source: path.join(dir, entry.name, "PLUGIN.md") };
|
|
4554
4065
|
}
|
|
4555
|
-
function
|
|
4066
|
+
function splitFrontmatter(raw, source, errorCodePrefix) {
|
|
4556
4067
|
const match = /^---\s*\n([\s\S]*?)\n---\s*(?:\n|$)/.exec(raw);
|
|
4557
4068
|
if (match === null) {
|
|
4558
4069
|
throw new chunkA44COQJJ_cjs.ConfigurationError(
|
|
@@ -4720,7 +4231,7 @@ function anyGlobMatches(patterns, paths) {
|
|
|
4720
4231
|
|
|
4721
4232
|
// src/internal/runtime/context/context-yaml-lite.ts
|
|
4722
4233
|
var FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
|
|
4723
|
-
function
|
|
4234
|
+
function splitFrontmatter2(content) {
|
|
4724
4235
|
const m = FRONTMATTER_RE.exec(content);
|
|
4725
4236
|
if (m === null) return { yaml: void 0, body: content };
|
|
4726
4237
|
return { yaml: m[1] ?? "", body: m[2] ?? "" };
|
|
@@ -4778,7 +4289,7 @@ var McdFrontmatterSchema = zod.z.object({
|
|
|
4778
4289
|
alwaysApply: zod.z.boolean().optional()
|
|
4779
4290
|
});
|
|
4780
4291
|
function parseMdc(content) {
|
|
4781
|
-
const { yaml, body } =
|
|
4292
|
+
const { yaml, body } = splitFrontmatter2(content);
|
|
4782
4293
|
if (yaml === void 0) {
|
|
4783
4294
|
return { frontmatter: { alwaysApply: true }, body: content };
|
|
4784
4295
|
}
|
|
@@ -4804,7 +4315,7 @@ var RulesFrontmatterSchema = zod.z.object({
|
|
|
4804
4315
|
enabled: zod.z.boolean().optional()
|
|
4805
4316
|
});
|
|
4806
4317
|
function parseRules(content) {
|
|
4807
|
-
const { yaml, body } =
|
|
4318
|
+
const { yaml, body } = splitFrontmatter2(content);
|
|
4808
4319
|
if (yaml === void 0) {
|
|
4809
4320
|
return { frontmatter: { alwaysApply: true }, body: content };
|
|
4810
4321
|
}
|
|
@@ -5188,7 +4699,7 @@ var PluginsManager = class {
|
|
|
5188
4699
|
async refresh() {
|
|
5189
4700
|
this.plugins = [];
|
|
5190
4701
|
const pluginsRoot = path.join(this.cwd, ".theokit", "plugins");
|
|
5191
|
-
const entries = await
|
|
4702
|
+
const entries = await chunkLALRCFSN_cjs.readWorkspaceDir(pluginsRoot, "plugins_read_error", "plugins directory");
|
|
5192
4703
|
for (const entry of entries) {
|
|
5193
4704
|
if (!entry.isDirectory()) continue;
|
|
5194
4705
|
const folderName = entry.name;
|
|
@@ -5632,15 +5143,60 @@ var DoomLoopTracker = class {
|
|
|
5632
5143
|
this.#count = 0;
|
|
5633
5144
|
}
|
|
5634
5145
|
};
|
|
5635
|
-
function firstDoomLoopVerdict(tracker, calls) {
|
|
5636
|
-
let escalation = { kind: "ok" };
|
|
5637
|
-
for (const call of calls) {
|
|
5638
|
-
const v = tracker.inspect(call);
|
|
5639
|
-
if (v.kind === "hard") return v;
|
|
5640
|
-
if (v.kind === "soft" && escalation.kind === "ok") escalation = v;
|
|
5641
|
-
}
|
|
5642
|
-
return escalation;
|
|
5643
|
-
}
|
|
5146
|
+
function firstDoomLoopVerdict(tracker, calls) {
|
|
5147
|
+
let escalation = { kind: "ok" };
|
|
5148
|
+
for (const call of calls) {
|
|
5149
|
+
const v = tracker.inspect(call);
|
|
5150
|
+
if (v.kind === "hard") return v;
|
|
5151
|
+
if (v.kind === "soft" && escalation.kind === "ok") escalation = v;
|
|
5152
|
+
}
|
|
5153
|
+
return escalation;
|
|
5154
|
+
}
|
|
5155
|
+
|
|
5156
|
+
// src/internal/budget/usage-accumulator.ts
|
|
5157
|
+
var UsageAccumulator = class {
|
|
5158
|
+
input = 0;
|
|
5159
|
+
output = 0;
|
|
5160
|
+
cacheRead = 0;
|
|
5161
|
+
cacheWrite = 0;
|
|
5162
|
+
reasoning = 0;
|
|
5163
|
+
requests = [];
|
|
5164
|
+
add(step) {
|
|
5165
|
+
const inputTokens = step.inputTokens ?? 0;
|
|
5166
|
+
const outputTokens = step.outputTokens ?? 0;
|
|
5167
|
+
const cacheReadTokens = step.cacheReadTokens ?? 0;
|
|
5168
|
+
const cacheWriteTokens = step.cacheWriteTokens ?? 0;
|
|
5169
|
+
const reasoningTokens = step.reasoningTokens ?? 0;
|
|
5170
|
+
this.input += inputTokens;
|
|
5171
|
+
this.output += outputTokens;
|
|
5172
|
+
this.cacheRead += cacheReadTokens;
|
|
5173
|
+
this.cacheWrite += cacheWriteTokens;
|
|
5174
|
+
this.reasoning += reasoningTokens;
|
|
5175
|
+
this.requests.push({
|
|
5176
|
+
inputTokens,
|
|
5177
|
+
outputTokens,
|
|
5178
|
+
...cacheReadTokens > 0 ? { cacheReadTokens } : {},
|
|
5179
|
+
...cacheWriteTokens > 0 ? { cacheWriteTokens } : {},
|
|
5180
|
+
...reasoningTokens > 0 ? { reasoningTokens } : {},
|
|
5181
|
+
totalTokens: inputTokens + outputTokens
|
|
5182
|
+
});
|
|
5183
|
+
}
|
|
5184
|
+
/** Did we observe any usage at all? */
|
|
5185
|
+
hasAny() {
|
|
5186
|
+
return this.requests.length > 0;
|
|
5187
|
+
}
|
|
5188
|
+
toTokenUsage() {
|
|
5189
|
+
return {
|
|
5190
|
+
inputTokens: this.input,
|
|
5191
|
+
outputTokens: this.output,
|
|
5192
|
+
...this.cacheRead > 0 ? { cacheReadTokens: this.cacheRead } : {},
|
|
5193
|
+
...this.cacheWrite > 0 ? { cacheWriteTokens: this.cacheWrite } : {},
|
|
5194
|
+
...this.reasoning > 0 ? { reasoningTokens: this.reasoning } : {},
|
|
5195
|
+
totalTokens: this.input + this.output,
|
|
5196
|
+
...this.requests.length > 1 ? { requests: this.requests.slice() } : {}
|
|
5197
|
+
};
|
|
5198
|
+
}
|
|
5199
|
+
};
|
|
5644
5200
|
|
|
5645
5201
|
// src/internal/agent-loop/message-builders.ts
|
|
5646
5202
|
function buildSystemEvent(inputs, toolNames) {
|
|
@@ -6121,6 +5677,21 @@ function coerceArgsToSchema(args, schema) {
|
|
|
6121
5677
|
return { value: out, changed };
|
|
6122
5678
|
}
|
|
6123
5679
|
|
|
5680
|
+
// src/tool-error.ts
|
|
5681
|
+
var ToolError = class extends chunkA44COQJJ_cjs.TheokitAgentError {
|
|
5682
|
+
name = "ToolError";
|
|
5683
|
+
/** The error content surfaced to the model: a string, or text/image blocks. */
|
|
5684
|
+
content;
|
|
5685
|
+
constructor(content, options = {}) {
|
|
5686
|
+
super(renderToolErrorMessage(content), { ...options, isRetryable: false });
|
|
5687
|
+
this.content = content;
|
|
5688
|
+
}
|
|
5689
|
+
};
|
|
5690
|
+
function renderToolErrorMessage(content) {
|
|
5691
|
+
if (typeof content === "string") return content;
|
|
5692
|
+
return content.map((block) => block.type === "text" ? block.text : `[${block.source.media_type} image]`).join("\n");
|
|
5693
|
+
}
|
|
5694
|
+
|
|
6124
5695
|
// src/internal/runtime/tools/shell-tool.ts
|
|
6125
5696
|
async function runShell(options) {
|
|
6126
5697
|
if (options.sandbox === true && isObviouslyUnsafe(options.command)) {
|
|
@@ -6541,101 +6112,414 @@ function finalizeSpanAndPostHook(inputs, call, callId, result, events, toolSpan)
|
|
|
6541
6112
|
);
|
|
6542
6113
|
});
|
|
6543
6114
|
return {
|
|
6544
|
-
type: "tool_result",
|
|
6545
|
-
toolUseId: call.id,
|
|
6546
|
-
// SE7 — structured content blocks (handler-returned or ToolError-carried)
|
|
6547
|
-
// are authoritative; otherwise the legacy string rendering.
|
|
6548
|
-
content: result.content !== void 0 ? result.content : renderToolResult(result),
|
|
6549
|
-
...result.exitCode !== 0 && result.exitCode !== void 0 ? { isError: true } : {}
|
|
6115
|
+
type: "tool_result",
|
|
6116
|
+
toolUseId: call.id,
|
|
6117
|
+
// SE7 — structured content blocks (handler-returned or ToolError-carried)
|
|
6118
|
+
// are authoritative; otherwise the legacy string rendering.
|
|
6119
|
+
content: result.content !== void 0 ? result.content : renderToolResult(result),
|
|
6120
|
+
...result.exitCode !== 0 && result.exitCode !== void 0 ? { isError: true } : {}
|
|
6121
|
+
};
|
|
6122
|
+
}
|
|
6123
|
+
async function emitToolLifecycleDelta(inputs, update) {
|
|
6124
|
+
if (inputs.onDelta === void 0) return;
|
|
6125
|
+
try {
|
|
6126
|
+
await inputs.onDelta({ update });
|
|
6127
|
+
} catch (err) {
|
|
6128
|
+
process.stderr.write(
|
|
6129
|
+
`[theokit-sdk] onDelta tool-lifecycle emit error (swallowed): ${err instanceof Error ? err.message : String(err)}
|
|
6130
|
+
`
|
|
6131
|
+
);
|
|
6132
|
+
}
|
|
6133
|
+
}
|
|
6134
|
+
async function safeEmitToolHook(callback, event) {
|
|
6135
|
+
if (callback === void 0) return;
|
|
6136
|
+
try {
|
|
6137
|
+
await callback(event);
|
|
6138
|
+
} catch (cause) {
|
|
6139
|
+
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
6140
|
+
process.stderr.write(`[theokit-sdk] tool lifecycle hook threw: ${msg}
|
|
6141
|
+
`);
|
|
6142
|
+
}
|
|
6143
|
+
}
|
|
6144
|
+
function buildToolUseRunning(inputs, callId, call) {
|
|
6145
|
+
return {
|
|
6146
|
+
type: "tool_call",
|
|
6147
|
+
agent_id: inputs.agentId,
|
|
6148
|
+
run_id: inputs.runId,
|
|
6149
|
+
call_id: callId,
|
|
6150
|
+
name: call.name,
|
|
6151
|
+
status: "running",
|
|
6152
|
+
args: call.input
|
|
6153
|
+
};
|
|
6154
|
+
}
|
|
6155
|
+
function buildRepairRegistry(tools) {
|
|
6156
|
+
const out = /* @__PURE__ */ new Map();
|
|
6157
|
+
for (const t of tools) {
|
|
6158
|
+
out.set(t.name, { name: t.name, inputSchema: t.inputSchema });
|
|
6159
|
+
}
|
|
6160
|
+
return out;
|
|
6161
|
+
}
|
|
6162
|
+
function buildToolUseCompleted(inputs, callId, call, result) {
|
|
6163
|
+
return {
|
|
6164
|
+
type: "tool_call",
|
|
6165
|
+
agent_id: inputs.agentId,
|
|
6166
|
+
run_id: inputs.runId,
|
|
6167
|
+
call_id: callId,
|
|
6168
|
+
name: call.name,
|
|
6169
|
+
status: "completed",
|
|
6170
|
+
args: call.input,
|
|
6171
|
+
result: {
|
|
6172
|
+
stdout: result.stdout,
|
|
6173
|
+
stderr: result.stderr,
|
|
6174
|
+
exitCode: result.exitCode ?? 0
|
|
6175
|
+
}
|
|
6176
|
+
};
|
|
6177
|
+
}
|
|
6178
|
+
|
|
6179
|
+
// src/internal/agent-loop/tool-result-guard.ts
|
|
6180
|
+
var OPEN = "<untrusted-tool-output>";
|
|
6181
|
+
var CLOSE = "</untrusted-tool-output>";
|
|
6182
|
+
var PII_PATTERNS = [
|
|
6183
|
+
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
|
|
6184
|
+
// email
|
|
6185
|
+
/\b(?:\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g
|
|
6186
|
+
// phone
|
|
6187
|
+
];
|
|
6188
|
+
function guardText(content, opts) {
|
|
6189
|
+
let out = content;
|
|
6190
|
+
if (opts.redactPii === true) {
|
|
6191
|
+
for (const re of PII_PATTERNS) out = out.replace(re, "[REDACTED]");
|
|
6192
|
+
}
|
|
6193
|
+
if (opts.delimit === true) {
|
|
6194
|
+
const safe2 = out.split(CLOSE).join("</ untrusted-tool-output>");
|
|
6195
|
+
out = `${OPEN}
|
|
6196
|
+
${safe2}
|
|
6197
|
+
${CLOSE}`;
|
|
6198
|
+
}
|
|
6199
|
+
return out;
|
|
6200
|
+
}
|
|
6201
|
+
function applyToolResultGuard(parts, opts) {
|
|
6202
|
+
if (opts.delimit !== true && opts.redactPii !== true) return parts;
|
|
6203
|
+
return parts.map(
|
|
6204
|
+
(p) => (
|
|
6205
|
+
// SE7 — guard the TEXT of a tool result (string or the text blocks of a
|
|
6206
|
+
// structured content); image blocks pass through untouched.
|
|
6207
|
+
p.type === "tool_result" ? { ...p, content: chunk2MF3IE2D_cjs.renderToolResultContentText(p.content, (t) => guardText(t, opts)) } : p
|
|
6208
|
+
)
|
|
6209
|
+
);
|
|
6210
|
+
}
|
|
6211
|
+
|
|
6212
|
+
// src/internal/budget/pricing-data.json
|
|
6213
|
+
var pricing_data_default = {
|
|
6214
|
+
_meta: {
|
|
6215
|
+
pricingVersion: "litellm-2026-05-snapshot"},
|
|
6216
|
+
models: {
|
|
6217
|
+
"anthropic/claude-opus-4-7": {
|
|
6218
|
+
input: 5,
|
|
6219
|
+
output: 25,
|
|
6220
|
+
cacheRead: 0.5,
|
|
6221
|
+
cacheWrite: 6.25
|
|
6222
|
+
},
|
|
6223
|
+
"anthropic/claude-opus-4-6": {
|
|
6224
|
+
input: 5,
|
|
6225
|
+
output: 25,
|
|
6226
|
+
cacheRead: 0.5,
|
|
6227
|
+
cacheWrite: 6.25
|
|
6228
|
+
},
|
|
6229
|
+
"anthropic/claude-opus-4-5": {
|
|
6230
|
+
input: 5,
|
|
6231
|
+
output: 25,
|
|
6232
|
+
cacheRead: 0.5,
|
|
6233
|
+
cacheWrite: 6.25
|
|
6234
|
+
},
|
|
6235
|
+
"anthropic/claude-sonnet-4-6": {
|
|
6236
|
+
input: 3,
|
|
6237
|
+
output: 15,
|
|
6238
|
+
cacheRead: 0.3,
|
|
6239
|
+
cacheWrite: 3.75
|
|
6240
|
+
},
|
|
6241
|
+
"anthropic/claude-sonnet-4-5": {
|
|
6242
|
+
input: 3,
|
|
6243
|
+
output: 15,
|
|
6244
|
+
cacheRead: 0.3,
|
|
6245
|
+
cacheWrite: 3.75
|
|
6246
|
+
},
|
|
6247
|
+
"anthropic/claude-haiku-4-5": {
|
|
6248
|
+
input: 1,
|
|
6249
|
+
output: 5,
|
|
6250
|
+
cacheRead: 0.1,
|
|
6251
|
+
cacheWrite: 1.25
|
|
6252
|
+
},
|
|
6253
|
+
"anthropic/claude-3-5-sonnet": {
|
|
6254
|
+
input: 3,
|
|
6255
|
+
output: 15,
|
|
6256
|
+
cacheRead: 0.3,
|
|
6257
|
+
cacheWrite: 3.75
|
|
6258
|
+
},
|
|
6259
|
+
"anthropic/claude-3-5-haiku": {
|
|
6260
|
+
input: 0.8,
|
|
6261
|
+
output: 4,
|
|
6262
|
+
cacheRead: 0.08,
|
|
6263
|
+
cacheWrite: 1
|
|
6264
|
+
},
|
|
6265
|
+
"anthropic/claude-3-opus": {
|
|
6266
|
+
input: 15,
|
|
6267
|
+
output: 75,
|
|
6268
|
+
cacheRead: 1.5,
|
|
6269
|
+
cacheWrite: 18.75
|
|
6270
|
+
},
|
|
6271
|
+
"anthropic/claude-3-haiku": {
|
|
6272
|
+
input: 0.25,
|
|
6273
|
+
output: 1.25,
|
|
6274
|
+
cacheRead: 0.03,
|
|
6275
|
+
cacheWrite: 0.3
|
|
6276
|
+
},
|
|
6277
|
+
"openai/gpt-4o": {
|
|
6278
|
+
input: 2.5,
|
|
6279
|
+
output: 10,
|
|
6280
|
+
cacheRead: 1.25
|
|
6281
|
+
},
|
|
6282
|
+
"openai/gpt-4o-mini": {
|
|
6283
|
+
input: 0.15,
|
|
6284
|
+
output: 0.6,
|
|
6285
|
+
cacheRead: 0.075
|
|
6286
|
+
},
|
|
6287
|
+
"openai/gpt-4.1": {
|
|
6288
|
+
input: 2,
|
|
6289
|
+
output: 8,
|
|
6290
|
+
cacheRead: 0.5
|
|
6291
|
+
},
|
|
6292
|
+
"openai/gpt-4.1-mini": {
|
|
6293
|
+
input: 0.4,
|
|
6294
|
+
output: 1.6,
|
|
6295
|
+
cacheRead: 0.1
|
|
6296
|
+
},
|
|
6297
|
+
"openai/gpt-4.1-nano": {
|
|
6298
|
+
input: 0.1,
|
|
6299
|
+
output: 0.4,
|
|
6300
|
+
cacheRead: 0.025
|
|
6301
|
+
},
|
|
6302
|
+
"openai/o3": {
|
|
6303
|
+
input: 2,
|
|
6304
|
+
output: 8,
|
|
6305
|
+
cacheRead: 0.5
|
|
6306
|
+
},
|
|
6307
|
+
"openai/o3-mini": {
|
|
6308
|
+
input: 1.1,
|
|
6309
|
+
output: 4.4,
|
|
6310
|
+
cacheRead: 0.55
|
|
6311
|
+
},
|
|
6312
|
+
"openai/o4-mini": {
|
|
6313
|
+
input: 1.1,
|
|
6314
|
+
output: 4.4,
|
|
6315
|
+
cacheRead: 0.275
|
|
6316
|
+
},
|
|
6317
|
+
"deepseek/deepseek-chat": {
|
|
6318
|
+
input: 0.14,
|
|
6319
|
+
output: 0.28
|
|
6320
|
+
},
|
|
6321
|
+
"deepseek/deepseek-reasoner": {
|
|
6322
|
+
input: 0.55,
|
|
6323
|
+
output: 2.19
|
|
6324
|
+
},
|
|
6325
|
+
"google/gemini-2.5-pro": {
|
|
6326
|
+
input: 1.25,
|
|
6327
|
+
output: 10
|
|
6328
|
+
},
|
|
6329
|
+
"google/gemini-2.5-flash": {
|
|
6330
|
+
input: 0.15,
|
|
6331
|
+
output: 0.6
|
|
6332
|
+
},
|
|
6333
|
+
"google/gemini-2.0-flash": {
|
|
6334
|
+
input: 0.1,
|
|
6335
|
+
output: 0.4
|
|
6336
|
+
}
|
|
6337
|
+
}
|
|
6338
|
+
};
|
|
6339
|
+
|
|
6340
|
+
// src/internal/budget/pricing-registry.ts
|
|
6341
|
+
var data = pricing_data_default;
|
|
6342
|
+
function buildEntry(key, raw) {
|
|
6343
|
+
const [provider, ...modelParts] = key.split("/");
|
|
6344
|
+
return {
|
|
6345
|
+
provider: provider ?? "unknown",
|
|
6346
|
+
model: modelParts.join("/"),
|
|
6347
|
+
inputCostPerMillion: raw.input,
|
|
6348
|
+
outputCostPerMillion: raw.output,
|
|
6349
|
+
...raw.cacheRead !== void 0 ? { cacheReadCostPerMillion: raw.cacheRead } : {},
|
|
6350
|
+
...raw.cacheWrite !== void 0 ? { cacheWriteCostPerMillion: raw.cacheWrite } : {},
|
|
6351
|
+
...raw.reasoning !== void 0 ? { reasoningCostPerMillion: raw.reasoning } : {},
|
|
6352
|
+
pricingVersion: data._meta.pricingVersion
|
|
6550
6353
|
};
|
|
6551
6354
|
}
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
try {
|
|
6555
|
-
await inputs.onDelta({ update });
|
|
6556
|
-
} catch (err) {
|
|
6557
|
-
process.stderr.write(
|
|
6558
|
-
`[theokit-sdk] onDelta tool-lifecycle emit error (swallowed): ${err instanceof Error ? err.message : String(err)}
|
|
6559
|
-
`
|
|
6560
|
-
);
|
|
6561
|
-
}
|
|
6355
|
+
function stripDateSuffix(model) {
|
|
6356
|
+
return model.replace(/-\d{4}-?\d{2}-?\d{2}$/, "");
|
|
6562
6357
|
}
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
try {
|
|
6566
|
-
await callback(event);
|
|
6567
|
-
} catch (cause) {
|
|
6568
|
-
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
6569
|
-
process.stderr.write(`[theokit-sdk] tool lifecycle hook threw: ${msg}
|
|
6570
|
-
`);
|
|
6571
|
-
}
|
|
6358
|
+
function normalizeAnthropicDots(model) {
|
|
6359
|
+
return model.replace(/(\d+)\.(\d+)/g, "$1-$2");
|
|
6572
6360
|
}
|
|
6573
|
-
function
|
|
6574
|
-
return
|
|
6575
|
-
type: "tool_call",
|
|
6576
|
-
agent_id: inputs.agentId,
|
|
6577
|
-
run_id: inputs.runId,
|
|
6578
|
-
call_id: callId,
|
|
6579
|
-
name: call.name,
|
|
6580
|
-
status: "running",
|
|
6581
|
-
args: call.input
|
|
6582
|
-
};
|
|
6361
|
+
function stripOpenRouterPrefix(modelId) {
|
|
6362
|
+
return modelId.startsWith("openrouter/") ? modelId.slice("openrouter/".length) : modelId;
|
|
6583
6363
|
}
|
|
6584
|
-
function
|
|
6585
|
-
|
|
6586
|
-
for (const t of tools) {
|
|
6587
|
-
out.set(t.name, { name: t.name, inputSchema: t.inputSchema });
|
|
6588
|
-
}
|
|
6589
|
-
return out;
|
|
6364
|
+
function lookupRaw(key) {
|
|
6365
|
+
return data.models[key];
|
|
6590
6366
|
}
|
|
6591
|
-
function
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6367
|
+
function getPricingEntry(opts) {
|
|
6368
|
+
const cleaned = stripOpenRouterPrefix(opts.model);
|
|
6369
|
+
const directKey = `${opts.provider}/${cleaned}`;
|
|
6370
|
+
const direct = lookupRaw(directKey);
|
|
6371
|
+
if (direct !== void 0) return buildEntry(directKey, direct);
|
|
6372
|
+
const noSuffix = stripDateSuffix(cleaned);
|
|
6373
|
+
if (noSuffix !== cleaned) {
|
|
6374
|
+
const noSuffixKey = `${opts.provider}/${noSuffix}`;
|
|
6375
|
+
const found = lookupRaw(noSuffixKey);
|
|
6376
|
+
if (found !== void 0) return buildEntry(noSuffixKey, found);
|
|
6377
|
+
}
|
|
6378
|
+
if (opts.provider === "anthropic") {
|
|
6379
|
+
const normalized = normalizeAnthropicDots(stripDateSuffix(cleaned));
|
|
6380
|
+
const normKey = `${opts.provider}/${normalized}`;
|
|
6381
|
+
const found = lookupRaw(normKey);
|
|
6382
|
+
if (found !== void 0) return buildEntry(normKey, found);
|
|
6383
|
+
}
|
|
6384
|
+
if (cleaned.includes("/")) {
|
|
6385
|
+
const found = lookupRaw(cleaned);
|
|
6386
|
+
if (found !== void 0) return buildEntry(cleaned, found);
|
|
6387
|
+
const stripped = stripDateSuffix(cleaned);
|
|
6388
|
+
if (stripped !== cleaned) {
|
|
6389
|
+
const found2 = lookupRaw(stripped);
|
|
6390
|
+
if (found2 !== void 0) return buildEntry(stripped, found2);
|
|
6604
6391
|
}
|
|
6605
|
-
}
|
|
6392
|
+
}
|
|
6393
|
+
const catalogEntry = catalogCostFallback(opts.provider, cleaned);
|
|
6394
|
+
if (catalogEntry !== void 0) return catalogEntry;
|
|
6395
|
+
return void 0;
|
|
6396
|
+
}
|
|
6397
|
+
function catalogCostFallback(provider, cleanedModel) {
|
|
6398
|
+
const stripped = stripDateSuffix(cleanedModel);
|
|
6399
|
+
const candidates = [`${provider}/${cleanedModel}`, cleanedModel];
|
|
6400
|
+
if (stripped !== cleanedModel) candidates.push(`${provider}/${stripped}`, stripped);
|
|
6401
|
+
for (const key of candidates) {
|
|
6402
|
+
const info = chunkD42XHI4O_cjs.getCatalogModelInfo(key);
|
|
6403
|
+
const cost = info?.cost;
|
|
6404
|
+
if (cost === void 0) continue;
|
|
6405
|
+
const [prov, ...modelParts] = key.split("/");
|
|
6406
|
+
return {
|
|
6407
|
+
provider: prov ?? provider,
|
|
6408
|
+
model: modelParts.join("/") || cleanedModel,
|
|
6409
|
+
inputCostPerMillion: cost.input,
|
|
6410
|
+
outputCostPerMillion: cost.output,
|
|
6411
|
+
...cost.cache_read !== void 0 ? { cacheReadCostPerMillion: cost.cache_read } : {},
|
|
6412
|
+
...cost.cache_write !== void 0 ? { cacheWriteCostPerMillion: cost.cache_write } : {},
|
|
6413
|
+
// M44 M5 fix — honest provenance: a key patched by the LIVE models-dev source is not "vendored".
|
|
6414
|
+
pricingVersion: chunkD42XHI4O_cjs.isPatchedModelKey(key) ? "catalog-models-dev" : "catalog-vendored"
|
|
6415
|
+
};
|
|
6416
|
+
}
|
|
6417
|
+
return void 0;
|
|
6606
6418
|
}
|
|
6607
6419
|
|
|
6608
|
-
// src/internal/
|
|
6609
|
-
var
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6420
|
+
// src/internal/budget/compute-cost.ts
|
|
6421
|
+
var MICROCENT = 1e6;
|
|
6422
|
+
function isSubscriptionIncluded(provider) {
|
|
6423
|
+
return provider === "openai-codex" || provider === "codex";
|
|
6424
|
+
}
|
|
6425
|
+
function pricingHasValidRates(entry) {
|
|
6426
|
+
return entry.inputCostPerMillion >= 0 && entry.outputCostPerMillion >= 0 && (entry.cacheReadCostPerMillion === void 0 || entry.cacheReadCostPerMillion >= 0) && (entry.cacheWriteCostPerMillion === void 0 || entry.cacheWriteCostPerMillion >= 0) && (entry.reasoningCostPerMillion === void 0 || entry.reasoningCostPerMillion >= 0);
|
|
6427
|
+
}
|
|
6428
|
+
function costForTokens(tokens, perMillion) {
|
|
6429
|
+
if (tokens === 0 || perMillion === 0) return 0;
|
|
6430
|
+
return Math.round(tokens * perMillion * MICROCENT / 1e6) / MICROCENT;
|
|
6431
|
+
}
|
|
6432
|
+
function computeCost(args) {
|
|
6433
|
+
if (isSubscriptionIncluded(args.provider)) {
|
|
6434
|
+
return {
|
|
6435
|
+
amountUsd: 0,
|
|
6436
|
+
status: "included",
|
|
6437
|
+
currency: "USD",
|
|
6438
|
+
source: "subscription_included",
|
|
6439
|
+
pricingVersion: void 0
|
|
6440
|
+
};
|
|
6621
6441
|
}
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6442
|
+
const entry = getPricingEntry({
|
|
6443
|
+
provider: args.provider,
|
|
6444
|
+
model: args.model,
|
|
6445
|
+
...args.baseUrl !== void 0 ? { baseUrl: args.baseUrl } : {}
|
|
6446
|
+
});
|
|
6447
|
+
if (entry === void 0) {
|
|
6448
|
+
return {
|
|
6449
|
+
amountUsd: void 0,
|
|
6450
|
+
status: "unknown",
|
|
6451
|
+
currency: "USD",
|
|
6452
|
+
source: "unknown",
|
|
6453
|
+
pricingVersion: void 0
|
|
6454
|
+
};
|
|
6627
6455
|
}
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6456
|
+
if (!pricingHasValidRates(entry)) {
|
|
6457
|
+
return {
|
|
6458
|
+
amountUsd: void 0,
|
|
6459
|
+
status: "unknown",
|
|
6460
|
+
currency: "USD",
|
|
6461
|
+
source: "unknown",
|
|
6462
|
+
pricingVersion: entry.pricingVersion,
|
|
6463
|
+
notes: ["pricing entry has negative rates; treated as invalid"]
|
|
6464
|
+
};
|
|
6465
|
+
}
|
|
6466
|
+
const notes = [];
|
|
6467
|
+
const detail = {};
|
|
6468
|
+
const u = args.usage;
|
|
6469
|
+
const inputCost = costForTokens(u.inputTokens, entry.inputCostPerMillion);
|
|
6470
|
+
const outputCost = costForTokens(u.outputTokens, entry.outputCostPerMillion);
|
|
6471
|
+
detail.input = inputCost;
|
|
6472
|
+
detail.output = outputCost;
|
|
6473
|
+
let total = inputCost + outputCost;
|
|
6474
|
+
if (u.cacheReadTokens !== void 0 && u.cacheReadTokens > 0) {
|
|
6475
|
+
if (entry.cacheReadCostPerMillion === void 0) {
|
|
6476
|
+
return {
|
|
6477
|
+
amountUsd: void 0,
|
|
6478
|
+
status: "unknown",
|
|
6479
|
+
currency: "USD",
|
|
6480
|
+
source: "litellm_snapshot",
|
|
6481
|
+
pricingVersion: entry.pricingVersion,
|
|
6482
|
+
notes: ["cache-read tokens present but cacheReadCostPerMillion is undefined"]
|
|
6483
|
+
};
|
|
6484
|
+
}
|
|
6485
|
+
const c = costForTokens(u.cacheReadTokens, entry.cacheReadCostPerMillion);
|
|
6486
|
+
detail.cacheRead = c;
|
|
6487
|
+
total += c;
|
|
6488
|
+
}
|
|
6489
|
+
if (u.cacheWriteTokens !== void 0 && u.cacheWriteTokens > 0) {
|
|
6490
|
+
if (entry.cacheWriteCostPerMillion === void 0) {
|
|
6491
|
+
return {
|
|
6492
|
+
amountUsd: void 0,
|
|
6493
|
+
status: "unknown",
|
|
6494
|
+
currency: "USD",
|
|
6495
|
+
source: "litellm_snapshot",
|
|
6496
|
+
pricingVersion: entry.pricingVersion,
|
|
6497
|
+
notes: ["cache-write tokens present but cacheWriteCostPerMillion is undefined"]
|
|
6498
|
+
};
|
|
6499
|
+
}
|
|
6500
|
+
const c = costForTokens(u.cacheWriteTokens, entry.cacheWriteCostPerMillion);
|
|
6501
|
+
detail.cacheWrite = c;
|
|
6502
|
+
total += c;
|
|
6503
|
+
}
|
|
6504
|
+
if (u.reasoningTokens !== void 0 && u.reasoningTokens > 0) {
|
|
6505
|
+
const rate = entry.reasoningCostPerMillion ?? entry.outputCostPerMillion;
|
|
6506
|
+
const c = costForTokens(u.reasoningTokens, rate);
|
|
6507
|
+
detail.reasoning = c;
|
|
6508
|
+
total += c;
|
|
6509
|
+
if (entry.reasoningCostPerMillion === void 0) {
|
|
6510
|
+
notes.push("reasoning tokens billed at output rate (no dedicated reasoning rate available)");
|
|
6511
|
+
}
|
|
6512
|
+
}
|
|
6513
|
+
const amountUsd = Math.round(total * MICROCENT) / MICROCENT;
|
|
6514
|
+
return {
|
|
6515
|
+
amountUsd,
|
|
6516
|
+
status: "estimated",
|
|
6517
|
+
currency: "USD",
|
|
6518
|
+
source: "litellm_snapshot",
|
|
6519
|
+
pricingVersion: entry.pricingVersion,
|
|
6520
|
+
...notes.length > 0 ? { notes } : {},
|
|
6521
|
+
detail
|
|
6522
|
+
};
|
|
6639
6523
|
}
|
|
6640
6524
|
|
|
6641
6525
|
// src/internal/agent-loop/usage-and-cost.ts
|
|
@@ -6901,9 +6785,12 @@ async function runIteration(inputs, ctx) {
|
|
|
6901
6785
|
async function transformLlmOutputText(inputs, text, ctx) {
|
|
6902
6786
|
return inputs.pluginManager !== void 0 ? inputs.pluginManager.runTransformLlmOutputHooks(text, ctx) : text;
|
|
6903
6787
|
}
|
|
6904
|
-
async function guardAndTransformToolResults(inputs, raw, ctx) {
|
|
6788
|
+
async function guardAndTransformToolResults(inputs, raw, ctx, toolCalls) {
|
|
6905
6789
|
const guarded = inputs.toolResultGuard !== void 0 ? applyToolResultGuard(raw, inputs.toolResultGuard) : raw;
|
|
6906
|
-
return inputs.pluginManager !== void 0 ? inputs.pluginManager.runTransformToolResultHooks(guarded,
|
|
6790
|
+
return inputs.pluginManager !== void 0 ? inputs.pluginManager.runTransformToolResultHooks(guarded, {
|
|
6791
|
+
...ctx,
|
|
6792
|
+
toolCalls: toolCalls.map((c) => ({ id: c.id, name: c.name, args: c.input }))
|
|
6793
|
+
}) : guarded;
|
|
6907
6794
|
}
|
|
6908
6795
|
async function continueOrTerminate(inputs, ctx, llmOutput) {
|
|
6909
6796
|
if (llmOutput.errored) return "error";
|
|
@@ -6926,7 +6813,12 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
|
|
|
6926
6813
|
ctx.sendSpan
|
|
6927
6814
|
// M3 #64 — nest tool.call spans under agent.send
|
|
6928
6815
|
);
|
|
6929
|
-
const toolResults = await guardAndTransformToolResults(
|
|
6816
|
+
const toolResults = await guardAndTransformToolResults(
|
|
6817
|
+
inputs,
|
|
6818
|
+
rawResults,
|
|
6819
|
+
tCtx,
|
|
6820
|
+
llmOutput.toolCalls
|
|
6821
|
+
);
|
|
6930
6822
|
ctx.messages.push({ role: "user", content: toolResults });
|
|
6931
6823
|
if (inputs.onStep !== void 0) {
|
|
6932
6824
|
const cb = inputs.onStep;
|
|
@@ -7819,7 +7711,7 @@ async function consumePending(agentId, pending, clear, refresh) {
|
|
|
7819
7711
|
}
|
|
7820
7712
|
async function persistActiveMemoryTranscript(cwd, transcript) {
|
|
7821
7713
|
try {
|
|
7822
|
-
const dir = path.join(
|
|
7714
|
+
const dir = path.join(chunkJLMXKTBX_cjs.memoryDir(cwd), "transcripts", "active-memory");
|
|
7823
7715
|
const file = path.join(dir, `${transcript.runId}.json`);
|
|
7824
7716
|
await chunkTIZ4TS5V_cjs.atomicWriteJson(file, transcript);
|
|
7825
7717
|
} catch (cause) {
|
|
@@ -8064,7 +7956,7 @@ async function createOpenAiCompatibleRuntime(cfg, options) {
|
|
|
8064
7956
|
const envBaseUrl = cfg.baseUrlEnv !== void 0 ? process.env[cfg.baseUrlEnv] : void 0;
|
|
8065
7957
|
const baseUrl = options.baseUrl ?? envBaseUrl ?? cfg.defaultBaseUrl;
|
|
8066
7958
|
const fetchImpl = options.fetch ?? fetch;
|
|
8067
|
-
const cache = options.cache ??
|
|
7959
|
+
const cache = options.cache ?? chunkJLMXKTBX_cjs.globalEmbeddingCache;
|
|
8068
7960
|
const dimension = cfg.dimensionByModel[model];
|
|
8069
7961
|
if (dimension === void 0) {
|
|
8070
7962
|
throw new chunkA44COQJJ_cjs.ConfigurationError(
|
|
@@ -8603,7 +8495,7 @@ function createMemorySearchTool(opts) {
|
|
|
8603
8495
|
};
|
|
8604
8496
|
}
|
|
8605
8497
|
function createMemoryGetTool(opts) {
|
|
8606
|
-
const memoryRoot = path.resolve(
|
|
8498
|
+
const memoryRoot = path.resolve(chunkJLMXKTBX_cjs.memoryDir(opts.cwd));
|
|
8607
8499
|
return {
|
|
8608
8500
|
name: "memory_get",
|
|
8609
8501
|
description: GET_DESCRIPTION,
|
|
@@ -8710,7 +8602,7 @@ var LocalAgentMemory = class {
|
|
|
8710
8602
|
const openOpts = { cwd: this.workspaceCwd };
|
|
8711
8603
|
if (embedding !== void 0) openOpts.embedding = embedding;
|
|
8712
8604
|
if (cfg?.backend !== void 0) openOpts.backend = cfg.backend;
|
|
8713
|
-
this.index = await
|
|
8605
|
+
this.index = await chunkJLMXKTBX_cjs.IndexManager.open(openOpts);
|
|
8714
8606
|
await this.index.sync();
|
|
8715
8607
|
this.toolsCache = [
|
|
8716
8608
|
createMemorySearchTool({ index: this.index }),
|
|
@@ -8959,7 +8851,7 @@ function createLocalAgentMemoryProvider(opts) {
|
|
|
8959
8851
|
return { facts: [], systemPromptAdditions: summary };
|
|
8960
8852
|
},
|
|
8961
8853
|
async recordSessionSummary(args) {
|
|
8962
|
-
await
|
|
8854
|
+
await chunkJLMXKTBX_cjs.writeSessionSummary(args);
|
|
8963
8855
|
},
|
|
8964
8856
|
async sync(handle) {
|
|
8965
8857
|
const state = handle[INTERNAL_LAM_KEY];
|
|
@@ -9705,7 +9597,7 @@ var LocalAgent = class {
|
|
|
9705
9597
|
if (this.pluginsManager !== void 0) await this.pluginsManager.initialize();
|
|
9706
9598
|
const codePlugins = chunkBV2MWEMV_cjs.extractCodePlugins(this.options.plugins);
|
|
9707
9599
|
await this.pluginManagerCode.initialize(codePlugins);
|
|
9708
|
-
this.resolvedSubagents = await loadSubagents(
|
|
9600
|
+
this.resolvedSubagents = await chunkRZQ6E5YZ_cjs.loadSubagents(
|
|
9709
9601
|
this.workspaceCwd,
|
|
9710
9602
|
this.settingSourcesIncludeProject,
|
|
9711
9603
|
this.options.agents
|
|
@@ -9877,7 +9769,7 @@ var LocalAgent = class {
|
|
|
9877
9769
|
if (this.context !== void 0) await this.context.refresh();
|
|
9878
9770
|
if (this.skillsManager !== void 0) await this.skillsManager.refresh();
|
|
9879
9771
|
if (this.pluginsManager !== void 0) await this.pluginsManager.refresh();
|
|
9880
|
-
this.resolvedSubagents = await loadSubagents(
|
|
9772
|
+
this.resolvedSubagents = await chunkRZQ6E5YZ_cjs.loadSubagents(
|
|
9881
9773
|
this.workspaceCwd,
|
|
9882
9774
|
this.settingSourcesIncludeProject,
|
|
9883
9775
|
this.options.agents
|
|
@@ -10586,5 +10478,5 @@ exports.isFixtureApiKey = isFixtureApiKey;
|
|
|
10586
10478
|
exports.openRouterMemoryEmbeddingProviderAdapter = openRouterMemoryEmbeddingProviderAdapter;
|
|
10587
10479
|
exports.resolveApiKey = resolveApiKey;
|
|
10588
10480
|
exports.shouldUseFixtureMode = shouldUseFixtureMode;
|
|
10589
|
-
//# sourceMappingURL=chunk-
|
|
10590
|
-
//# sourceMappingURL=chunk-
|
|
10481
|
+
//# sourceMappingURL=chunk-GWMQ5CS3.cjs.map
|
|
10482
|
+
//# sourceMappingURL=chunk-GWMQ5CS3.cjs.map
|