@theokit/sdk 4.27.0 → 4.29.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/{cron-DPUZzncH.d.ts → agent-BZz4X8ZM.d.ts} +10 -577
- package/dist/{cron-DzZ9TMa2.d.cts → agent-CdjSCbYz.d.cts} +10 -577
- package/dist/agent-FBTLZI6V.js +41 -0
- package/dist/agent-FBTLZI6V.js.map +1 -0
- package/dist/agent-LBCEK6VH.cjs +50 -0
- package/dist/agent-LBCEK6VH.cjs.map +1 -0
- package/dist/{chunk-WBBYSW3Q.cjs → chunk-54YLX4Q6.cjs} +5 -5
- package/dist/{chunk-WBBYSW3Q.cjs.map → chunk-54YLX4Q6.cjs.map} +1 -1
- package/dist/{chunk-AKSBP7OO.js → chunk-5IB2UKSN.js} +5 -41
- package/dist/chunk-5IB2UKSN.js.map +1 -0
- 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-OX772BEW.js → chunk-EULKRTB5.js} +3 -3
- package/dist/{chunk-OX772BEW.js.map → chunk-EULKRTB5.js.map} +1 -1
- package/dist/chunk-FKCC2MED.js +43 -0
- package/dist/chunk-FKCC2MED.js.map +1 -0
- package/dist/{chunk-QUTUJ6P6.cjs → chunk-HK7ZHSAX.cjs} +25 -16
- package/dist/chunk-HK7ZHSAX.cjs.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-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-6M76Z3AI.js → chunk-VUJ3NVDC.js} +692 -808
- package/dist/chunk-VUJ3NVDC.js.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/{chunk-TMNS2LOS.cjs → chunk-YQAPEYUV.cjs} +715 -831
- package/dist/chunk-YQAPEYUV.cjs.map +1 -0
- package/dist/compact-session-OO2GD76G.js +1 -1
- package/dist/compact-session-OO7NVWPB.cjs +1 -1
- package/dist/cron-CIIshMs3.d.cts +579 -0
- package/dist/cron-dElBjDaL.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/errors.d.ts +3 -424
- 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 +66 -45
- 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 +42 -21
- 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/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/{run-until-K7IO7ZPQ.js → run-until-YZ2ODWOF.js} +3 -2
- package/dist/run-until-YZ2ODWOF.js.map +1 -0
- package/dist/{run-until-ZD4PRLNJ.cjs → run-until-ZZ2JLPJM.cjs} +3 -2
- package/dist/run-until-ZZ2JLPJM.cjs.map +1 -0
- package/dist/server/auth/index.d.cts +207 -11
- package/dist/server/auth/index.d.ts +207 -11
- package/dist/server/errors-envelope.d.cts +12 -6
- package/dist/server/errors-envelope.d.ts +12 -6
- 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/goal-events.d.ts +8 -0
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.js +1 -1
- package/package.json +12 -2
- package/dist/chunk-6M76Z3AI.js.map +0 -1
- 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-QUTUJ6P6.cjs.map +0 -1
- package/dist/chunk-TMNS2LOS.cjs.map +0 -1
- package/dist/run-until-K7IO7ZPQ.js.map +0 -1
- package/dist/run-until-ZD4PRLNJ.cjs.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');
|
|
@@ -143,6 +145,140 @@ var AgentBuilder = class {
|
|
|
143
145
|
}
|
|
144
146
|
};
|
|
145
147
|
|
|
148
|
+
// src/internal/auth/api-key-validator.ts
|
|
149
|
+
var FIXTURE_KEY_PREFIX = "theo_test_";
|
|
150
|
+
var LOCAL_RUNTIME_MOCK_KEY = "local";
|
|
151
|
+
var MIN_KEY_LENGTH = 16;
|
|
152
|
+
var KNOWN_PROVIDER_PREFIXES = [
|
|
153
|
+
{ provider: "openai", prefix: "sk-" },
|
|
154
|
+
{ provider: "anthropic", prefix: "sk-ant-" },
|
|
155
|
+
{ provider: "openrouter", prefix: "sk-or-" }
|
|
156
|
+
];
|
|
157
|
+
function validateApiKeyShape(key, options = {}) {
|
|
158
|
+
const opts = typeof options === "string" ? { provider: options } : options;
|
|
159
|
+
const tier1 = checkTier1(key);
|
|
160
|
+
if (tier1.malformed) return tier1;
|
|
161
|
+
const validKey = key;
|
|
162
|
+
if (validKey.startsWith(FIXTURE_KEY_PREFIX) || validKey === LOCAL_RUNTIME_MOCK_KEY) {
|
|
163
|
+
return { malformed: false };
|
|
164
|
+
}
|
|
165
|
+
if (opts.strict === false) return { malformed: false };
|
|
166
|
+
return checkTier2(validKey, opts.provider);
|
|
167
|
+
}
|
|
168
|
+
function checkTier1(key) {
|
|
169
|
+
if (key === void 0 || key.length === 0) {
|
|
170
|
+
return { malformed: true, reason: "empty", message: "API key is empty." };
|
|
171
|
+
}
|
|
172
|
+
if (key.trim().length === 0) {
|
|
173
|
+
return {
|
|
174
|
+
malformed: true,
|
|
175
|
+
reason: "whitespace_only",
|
|
176
|
+
message: "API key contains only whitespace."
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (key.length < 4) {
|
|
180
|
+
return {
|
|
181
|
+
malformed: true,
|
|
182
|
+
reason: "too_short",
|
|
183
|
+
message: `API key must be at least 4 chars (got ${key.length}).`
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return { malformed: false };
|
|
187
|
+
}
|
|
188
|
+
function checkTier2(key, provider) {
|
|
189
|
+
if (key.length < MIN_KEY_LENGTH) {
|
|
190
|
+
return {
|
|
191
|
+
malformed: true,
|
|
192
|
+
reason: "too_short",
|
|
193
|
+
message: `API key must be at least ${MIN_KEY_LENGTH} chars (got ${key.length}).`
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (/\s/.test(key)) {
|
|
197
|
+
return {
|
|
198
|
+
malformed: true,
|
|
199
|
+
reason: "embedded_whitespace",
|
|
200
|
+
message: "API key contains embedded whitespace."
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return checkProviderPrefix(key, provider);
|
|
204
|
+
}
|
|
205
|
+
function checkProviderPrefix(key, provider) {
|
|
206
|
+
if (provider === void 0) return { malformed: false };
|
|
207
|
+
const hint = KNOWN_PROVIDER_PREFIXES.find((p) => p.provider === provider.toLowerCase());
|
|
208
|
+
if (hint === void 0) return { malformed: false };
|
|
209
|
+
if (!key.startsWith(hint.prefix)) {
|
|
210
|
+
return {
|
|
211
|
+
malformed: true,
|
|
212
|
+
reason: "missing_known_prefix",
|
|
213
|
+
message: `API key for provider "${hint.provider}" expected to start with "${hint.prefix}".`
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return { malformed: false };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/internal/runtime/config/default-model.ts
|
|
220
|
+
var DEFAULT_AGENTIC_MODEL_ID = "google/gemini-2.0-flash-001";
|
|
221
|
+
|
|
222
|
+
// src/agent-generate.ts
|
|
223
|
+
async function agentGenerate(agent, agentModel, agentApiKey, agentLocal, input, options) {
|
|
224
|
+
const { output, maxRetries, errorStrategy, ...sendOptions } = options;
|
|
225
|
+
const run = await agent.send(input, sendOptions);
|
|
226
|
+
const result = await run.wait();
|
|
227
|
+
const { generateObjectImpl, GenerateObjectError } = await import('./generate-object-H3RNAM6S.cjs');
|
|
228
|
+
const answer = structurableAnswerOrThrow(result, GenerateObjectError);
|
|
229
|
+
const { getAgentFacade } = await import('./agent-factory-registry-UU46BUMU.cjs');
|
|
230
|
+
const facade = getAgentFacade();
|
|
231
|
+
const structured = await generateObjectImpl(
|
|
232
|
+
{
|
|
233
|
+
prompt: answer,
|
|
234
|
+
schema: output,
|
|
235
|
+
// `agentModel` arrives already normalized (`this.model` passed through
|
|
236
|
+
// `normalizeModel` in the LocalAgent/CloudAgent constructor), so the widened
|
|
237
|
+
// `string | ModelSelection` field only ever receives a `ModelSelection` here.
|
|
238
|
+
model: agentModel ?? { id: DEFAULT_AGENTIC_MODEL_ID },
|
|
239
|
+
// `local` is required to keep the transient structuring agent local-only;
|
|
240
|
+
// default to the process cwd when the agent had no explicit local config.
|
|
241
|
+
local: agentLocal ?? { cwd: process.cwd() },
|
|
242
|
+
...agentApiKey !== void 0 ? { apiKey: agentApiKey } : {},
|
|
243
|
+
...maxRetries !== void 0 ? { maxRetries } : {},
|
|
244
|
+
...errorStrategy !== void 0 ? { errorStrategy } : {}
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
create: (opts) => facade.create(opts),
|
|
248
|
+
delete: (agentId) => facade.delete(agentId)
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
return {
|
|
252
|
+
object: structured.object,
|
|
253
|
+
result,
|
|
254
|
+
raw: structured.raw,
|
|
255
|
+
usage: structured.usage
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function structurableAnswerOrThrow(result, GenerateObjectError) {
|
|
259
|
+
if (result.status === "error") {
|
|
260
|
+
throw new GenerateObjectError(
|
|
261
|
+
"no_tool_call",
|
|
262
|
+
`Agent run failed before an answer could be structured: ${result.error?.message ?? "unknown error"} [${result.error?.code ?? "?"}]`,
|
|
263
|
+
result.error
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
if (result.status === "cancelled") {
|
|
267
|
+
throw new GenerateObjectError(
|
|
268
|
+
"no_tool_call",
|
|
269
|
+
"Agent run was cancelled before an answer could be structured."
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
const answer = result.result;
|
|
273
|
+
if (answer === void 0 || answer.length === 0) {
|
|
274
|
+
throw new GenerateObjectError(
|
|
275
|
+
"no_tool_call",
|
|
276
|
+
"The tool loop finished with no text answer (tool-only completion) \u2014 there is nothing to structure."
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
return answer;
|
|
280
|
+
}
|
|
281
|
+
|
|
146
282
|
// src/internal/env.ts
|
|
147
283
|
var API_KEY_ENV_VAR = "THEOKIT_API_KEY";
|
|
148
284
|
function resolveApiKey(explicit) {
|
|
@@ -184,600 +320,49 @@ function generateRequestId() {
|
|
|
184
320
|
function isLocalAgentId(id) {
|
|
185
321
|
return id.startsWith(PREFIX.localAgent);
|
|
186
322
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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);
|
|
323
|
+
var FIXTURE_API_KEY_PREFIX = "theo_test_";
|
|
324
|
+
function isFixtureApiKey(apiKey) {
|
|
325
|
+
if (apiKey === void 0) return false;
|
|
326
|
+
return apiKey.startsWith(FIXTURE_API_KEY_PREFIX);
|
|
198
327
|
}
|
|
199
|
-
function
|
|
200
|
-
|
|
328
|
+
function getConfiguredBaseUrl() {
|
|
329
|
+
const value = process.env.THEOKIT_API_BASE_URL;
|
|
330
|
+
if (value === void 0 || value.length === 0) return void 0;
|
|
331
|
+
return value;
|
|
201
332
|
}
|
|
202
|
-
function
|
|
203
|
-
if (
|
|
204
|
-
return
|
|
333
|
+
function shouldUseFixtureMode(apiKey) {
|
|
334
|
+
if (getConfiguredBaseUrl() !== void 0) return false;
|
|
335
|
+
return isFixtureApiKey(apiKey);
|
|
205
336
|
}
|
|
206
|
-
|
|
207
|
-
|
|
337
|
+
function shouldUseRealLocalRuntime(apiKey) {
|
|
338
|
+
if (isFixtureApiKey(apiKey)) return false;
|
|
339
|
+
if (apiKey === void 0 || apiKey.length === 0) return false;
|
|
340
|
+
return typeof process.env.ANTHROPIC_API_KEY === "string" && process.env.ANTHROPIC_API_KEY.length > 0 || typeof process.env.OPENAI_API_KEY === "string" && process.env.OPENAI_API_KEY.length > 0 || typeof process.env.OPENROUTER_API_KEY === "string" && process.env.OPENROUTER_API_KEY.length > 0 || isAwsBedrockAuthAvailable() || isGcpVertexAuthAvailable() || isLocalNoAuthProviderAvailable();
|
|
341
|
+
}
|
|
342
|
+
function isAwsBedrockAuthAvailable() {
|
|
343
|
+
if (typeof process.env.AWS_BEARER_TOKEN_BEDROCK === "string" && process.env.AWS_BEARER_TOKEN_BEDROCK.length > 0) {
|
|
344
|
+
return true;
|
|
208
345
|
}
|
|
209
|
-
|
|
210
|
-
return
|
|
346
|
+
if (typeof process.env.AWS_ACCESS_KEY_ID === "string" && process.env.AWS_ACCESS_KEY_ID.length > 0) {
|
|
347
|
+
return true;
|
|
211
348
|
}
|
|
212
|
-
|
|
213
|
-
|
|
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;
|
|
349
|
+
if (typeof process.env.AWS_PROFILE === "string" && process.env.AWS_PROFILE.length > 0) {
|
|
350
|
+
return true;
|
|
228
351
|
}
|
|
229
|
-
return
|
|
352
|
+
return awsCredentialsFileExists();
|
|
230
353
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
});
|
|
354
|
+
function awsCredentialsFileExists() {
|
|
355
|
+
try {
|
|
356
|
+
const home = process.env.HOME ?? process.env.USERPROFILE;
|
|
357
|
+
if (home === void 0 || home.length === 0) return false;
|
|
358
|
+
return fs.existsSync(`${home}/.aws/credentials`) || fs.existsSync(`${home}/.aws/config`);
|
|
359
|
+
} catch {
|
|
360
|
+
return false;
|
|
259
361
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
};
|
|
545
|
-
}
|
|
546
|
-
const notes = [];
|
|
547
|
-
const detail = {};
|
|
548
|
-
const u = args.usage;
|
|
549
|
-
const inputCost = costForTokens(u.inputTokens, entry.inputCostPerMillion);
|
|
550
|
-
const outputCost = costForTokens(u.outputTokens, entry.outputCostPerMillion);
|
|
551
|
-
detail.input = inputCost;
|
|
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;
|
|
568
|
-
}
|
|
569
|
-
if (u.cacheWriteTokens !== void 0 && u.cacheWriteTokens > 0) {
|
|
570
|
-
if (entry.cacheWriteCostPerMillion === void 0) {
|
|
571
|
-
return {
|
|
572
|
-
amountUsd: void 0,
|
|
573
|
-
status: "unknown",
|
|
574
|
-
currency: "USD",
|
|
575
|
-
source: "litellm_snapshot",
|
|
576
|
-
pricingVersion: entry.pricingVersion,
|
|
577
|
-
notes: ["cache-write tokens present but cacheWriteCostPerMillion is undefined"]
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
const c = costForTokens(u.cacheWriteTokens, entry.cacheWriteCostPerMillion);
|
|
581
|
-
detail.cacheWrite = c;
|
|
582
|
-
total += c;
|
|
583
|
-
}
|
|
584
|
-
if (u.reasoningTokens !== void 0 && u.reasoningTokens > 0) {
|
|
585
|
-
const rate = entry.reasoningCostPerMillion ?? entry.outputCostPerMillion;
|
|
586
|
-
const c = costForTokens(u.reasoningTokens, rate);
|
|
587
|
-
detail.reasoning = c;
|
|
588
|
-
total += c;
|
|
589
|
-
if (entry.reasoningCostPerMillion === void 0) {
|
|
590
|
-
notes.push("reasoning tokens billed at output rate (no dedicated reasoning rate available)");
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
const amountUsd = Math.round(total * MICROCENT) / MICROCENT;
|
|
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
|
-
}
|
|
604
|
-
|
|
605
|
-
// src/internal/auth/api-key-validator.ts
|
|
606
|
-
var FIXTURE_KEY_PREFIX = "theo_test_";
|
|
607
|
-
var LOCAL_RUNTIME_MOCK_KEY = "local";
|
|
608
|
-
var MIN_KEY_LENGTH = 16;
|
|
609
|
-
var KNOWN_PROVIDER_PREFIXES = [
|
|
610
|
-
{ provider: "openai", prefix: "sk-" },
|
|
611
|
-
{ provider: "anthropic", prefix: "sk-ant-" },
|
|
612
|
-
{ provider: "openrouter", prefix: "sk-or-" }
|
|
613
|
-
];
|
|
614
|
-
function validateApiKeyShape(key, options = {}) {
|
|
615
|
-
const opts = typeof options === "string" ? { provider: options } : options;
|
|
616
|
-
const tier1 = checkTier1(key);
|
|
617
|
-
if (tier1.malformed) return tier1;
|
|
618
|
-
const validKey = key;
|
|
619
|
-
if (validKey.startsWith(FIXTURE_KEY_PREFIX) || validKey === LOCAL_RUNTIME_MOCK_KEY) {
|
|
620
|
-
return { malformed: false };
|
|
621
|
-
}
|
|
622
|
-
if (opts.strict === false) return { malformed: false };
|
|
623
|
-
return checkTier2(validKey, opts.provider);
|
|
624
|
-
}
|
|
625
|
-
function checkTier1(key) {
|
|
626
|
-
if (key === void 0 || key.length === 0) {
|
|
627
|
-
return { malformed: true, reason: "empty", message: "API key is empty." };
|
|
628
|
-
}
|
|
629
|
-
if (key.trim().length === 0) {
|
|
630
|
-
return {
|
|
631
|
-
malformed: true,
|
|
632
|
-
reason: "whitespace_only",
|
|
633
|
-
message: "API key contains only whitespace."
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
if (key.length < 4) {
|
|
637
|
-
return {
|
|
638
|
-
malformed: true,
|
|
639
|
-
reason: "too_short",
|
|
640
|
-
message: `API key must be at least 4 chars (got ${key.length}).`
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
return { malformed: false };
|
|
644
|
-
}
|
|
645
|
-
function checkTier2(key, provider) {
|
|
646
|
-
if (key.length < MIN_KEY_LENGTH) {
|
|
647
|
-
return {
|
|
648
|
-
malformed: true,
|
|
649
|
-
reason: "too_short",
|
|
650
|
-
message: `API key must be at least ${MIN_KEY_LENGTH} chars (got ${key.length}).`
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
if (/\s/.test(key)) {
|
|
654
|
-
return {
|
|
655
|
-
malformed: true,
|
|
656
|
-
reason: "embedded_whitespace",
|
|
657
|
-
message: "API key contains embedded whitespace."
|
|
658
|
-
};
|
|
659
|
-
}
|
|
660
|
-
return checkProviderPrefix(key, provider);
|
|
661
|
-
}
|
|
662
|
-
function checkProviderPrefix(key, provider) {
|
|
663
|
-
if (provider === void 0) return { malformed: false };
|
|
664
|
-
const hint = KNOWN_PROVIDER_PREFIXES.find((p) => p.provider === provider.toLowerCase());
|
|
665
|
-
if (hint === void 0) return { malformed: false };
|
|
666
|
-
if (!key.startsWith(hint.prefix)) {
|
|
667
|
-
return {
|
|
668
|
-
malformed: true,
|
|
669
|
-
reason: "missing_known_prefix",
|
|
670
|
-
message: `API key for provider "${hint.provider}" expected to start with "${hint.prefix}".`
|
|
671
|
-
};
|
|
672
|
-
}
|
|
673
|
-
return { malformed: false };
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// src/internal/runtime/config/default-model.ts
|
|
677
|
-
var DEFAULT_AGENTIC_MODEL_ID = "google/gemini-2.0-flash-001";
|
|
678
|
-
|
|
679
|
-
// src/agent-generate.ts
|
|
680
|
-
async function agentGenerate(agent, agentModel, agentApiKey, agentLocal, input, options) {
|
|
681
|
-
const { output, maxRetries, errorStrategy, ...sendOptions } = options;
|
|
682
|
-
const run = await agent.send(input, sendOptions);
|
|
683
|
-
const result = await run.wait();
|
|
684
|
-
const { generateObjectImpl, GenerateObjectError } = await import('./generate-object-H3RNAM6S.cjs');
|
|
685
|
-
const answer = structurableAnswerOrThrow(result, GenerateObjectError);
|
|
686
|
-
const { getAgentFacade } = await import('./agent-factory-registry-UU46BUMU.cjs');
|
|
687
|
-
const facade = getAgentFacade();
|
|
688
|
-
const structured = await generateObjectImpl(
|
|
689
|
-
{
|
|
690
|
-
prompt: answer,
|
|
691
|
-
schema: output,
|
|
692
|
-
// `agentModel` arrives already normalized (`this.model` passed through
|
|
693
|
-
// `normalizeModel` in the LocalAgent/CloudAgent constructor), so the widened
|
|
694
|
-
// `string | ModelSelection` field only ever receives a `ModelSelection` here.
|
|
695
|
-
model: agentModel ?? { id: DEFAULT_AGENTIC_MODEL_ID },
|
|
696
|
-
// `local` is required to keep the transient structuring agent local-only;
|
|
697
|
-
// default to the process cwd when the agent had no explicit local config.
|
|
698
|
-
local: agentLocal ?? { cwd: process.cwd() },
|
|
699
|
-
...agentApiKey !== void 0 ? { apiKey: agentApiKey } : {},
|
|
700
|
-
...maxRetries !== void 0 ? { maxRetries } : {},
|
|
701
|
-
...errorStrategy !== void 0 ? { errorStrategy } : {}
|
|
702
|
-
},
|
|
703
|
-
{
|
|
704
|
-
create: (opts) => facade.create(opts),
|
|
705
|
-
delete: (agentId) => facade.delete(agentId)
|
|
706
|
-
}
|
|
707
|
-
);
|
|
708
|
-
return {
|
|
709
|
-
object: structured.object,
|
|
710
|
-
result,
|
|
711
|
-
raw: structured.raw,
|
|
712
|
-
usage: structured.usage
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
function structurableAnswerOrThrow(result, GenerateObjectError) {
|
|
716
|
-
if (result.status === "error") {
|
|
717
|
-
throw new GenerateObjectError(
|
|
718
|
-
"no_tool_call",
|
|
719
|
-
`Agent run failed before an answer could be structured: ${result.error?.message ?? "unknown error"} [${result.error?.code ?? "?"}]`,
|
|
720
|
-
result.error
|
|
721
|
-
);
|
|
722
|
-
}
|
|
723
|
-
if (result.status === "cancelled") {
|
|
724
|
-
throw new GenerateObjectError(
|
|
725
|
-
"no_tool_call",
|
|
726
|
-
"Agent run was cancelled before an answer could be structured."
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
const answer = result.result;
|
|
730
|
-
if (answer === void 0 || answer.length === 0) {
|
|
731
|
-
throw new GenerateObjectError(
|
|
732
|
-
"no_tool_call",
|
|
733
|
-
"The tool loop finished with no text answer (tool-only completion) \u2014 there is nothing to structure."
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
return answer;
|
|
737
|
-
}
|
|
738
|
-
var FIXTURE_API_KEY_PREFIX = "theo_test_";
|
|
739
|
-
function isFixtureApiKey(apiKey) {
|
|
740
|
-
if (apiKey === void 0) return false;
|
|
741
|
-
return apiKey.startsWith(FIXTURE_API_KEY_PREFIX);
|
|
742
|
-
}
|
|
743
|
-
function getConfiguredBaseUrl() {
|
|
744
|
-
const value = process.env.THEOKIT_API_BASE_URL;
|
|
745
|
-
if (value === void 0 || value.length === 0) return void 0;
|
|
746
|
-
return value;
|
|
747
|
-
}
|
|
748
|
-
function shouldUseFixtureMode(apiKey) {
|
|
749
|
-
if (getConfiguredBaseUrl() !== void 0) return false;
|
|
750
|
-
return isFixtureApiKey(apiKey);
|
|
751
|
-
}
|
|
752
|
-
function shouldUseRealLocalRuntime(apiKey) {
|
|
753
|
-
if (isFixtureApiKey(apiKey)) return false;
|
|
754
|
-
if (apiKey === void 0 || apiKey.length === 0) return false;
|
|
755
|
-
return typeof process.env.ANTHROPIC_API_KEY === "string" && process.env.ANTHROPIC_API_KEY.length > 0 || typeof process.env.OPENAI_API_KEY === "string" && process.env.OPENAI_API_KEY.length > 0 || typeof process.env.OPENROUTER_API_KEY === "string" && process.env.OPENROUTER_API_KEY.length > 0 || isAwsBedrockAuthAvailable() || isGcpVertexAuthAvailable() || isLocalNoAuthProviderAvailable();
|
|
756
|
-
}
|
|
757
|
-
function isAwsBedrockAuthAvailable() {
|
|
758
|
-
if (typeof process.env.AWS_BEARER_TOKEN_BEDROCK === "string" && process.env.AWS_BEARER_TOKEN_BEDROCK.length > 0) {
|
|
759
|
-
return true;
|
|
760
|
-
}
|
|
761
|
-
if (typeof process.env.AWS_ACCESS_KEY_ID === "string" && process.env.AWS_ACCESS_KEY_ID.length > 0) {
|
|
762
|
-
return true;
|
|
763
|
-
}
|
|
764
|
-
if (typeof process.env.AWS_PROFILE === "string" && process.env.AWS_PROFILE.length > 0) {
|
|
765
|
-
return true;
|
|
766
|
-
}
|
|
767
|
-
return awsCredentialsFileExists();
|
|
768
|
-
}
|
|
769
|
-
function awsCredentialsFileExists() {
|
|
770
|
-
try {
|
|
771
|
-
const home = process.env.HOME ?? process.env.USERPROFILE;
|
|
772
|
-
if (home === void 0 || home.length === 0) return false;
|
|
773
|
-
return fs.existsSync(`${home}/.aws/credentials`) || fs.existsSync(`${home}/.aws/config`);
|
|
774
|
-
} catch {
|
|
775
|
-
return false;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
function isGcpVertexAuthAvailable() {
|
|
779
|
-
if (typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === "string" && process.env.GOOGLE_APPLICATION_CREDENTIALS.length > 0) {
|
|
780
|
-
return true;
|
|
362
|
+
}
|
|
363
|
+
function isGcpVertexAuthAvailable() {
|
|
364
|
+
if (typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === "string" && process.env.GOOGLE_APPLICATION_CREDENTIALS.length > 0) {
|
|
365
|
+
return true;
|
|
781
366
|
}
|
|
782
367
|
if (typeof process.env.GOOGLE_CLOUD_PROJECT === "string" && process.env.GOOGLE_CLOUD_PROJECT.length > 0) {
|
|
783
368
|
return true;
|
|
@@ -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-YQAPEYUV.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-YQAPEYUV.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
|
|
@@ -7819,7 +7703,7 @@ async function consumePending(agentId, pending, clear, refresh) {
|
|
|
7819
7703
|
}
|
|
7820
7704
|
async function persistActiveMemoryTranscript(cwd, transcript) {
|
|
7821
7705
|
try {
|
|
7822
|
-
const dir = path.join(
|
|
7706
|
+
const dir = path.join(chunkJLMXKTBX_cjs.memoryDir(cwd), "transcripts", "active-memory");
|
|
7823
7707
|
const file = path.join(dir, `${transcript.runId}.json`);
|
|
7824
7708
|
await chunkTIZ4TS5V_cjs.atomicWriteJson(file, transcript);
|
|
7825
7709
|
} catch (cause) {
|
|
@@ -8064,7 +7948,7 @@ async function createOpenAiCompatibleRuntime(cfg, options) {
|
|
|
8064
7948
|
const envBaseUrl = cfg.baseUrlEnv !== void 0 ? process.env[cfg.baseUrlEnv] : void 0;
|
|
8065
7949
|
const baseUrl = options.baseUrl ?? envBaseUrl ?? cfg.defaultBaseUrl;
|
|
8066
7950
|
const fetchImpl = options.fetch ?? fetch;
|
|
8067
|
-
const cache = options.cache ??
|
|
7951
|
+
const cache = options.cache ?? chunkJLMXKTBX_cjs.globalEmbeddingCache;
|
|
8068
7952
|
const dimension = cfg.dimensionByModel[model];
|
|
8069
7953
|
if (dimension === void 0) {
|
|
8070
7954
|
throw new chunkA44COQJJ_cjs.ConfigurationError(
|
|
@@ -8603,7 +8487,7 @@ function createMemorySearchTool(opts) {
|
|
|
8603
8487
|
};
|
|
8604
8488
|
}
|
|
8605
8489
|
function createMemoryGetTool(opts) {
|
|
8606
|
-
const memoryRoot = path.resolve(
|
|
8490
|
+
const memoryRoot = path.resolve(chunkJLMXKTBX_cjs.memoryDir(opts.cwd));
|
|
8607
8491
|
return {
|
|
8608
8492
|
name: "memory_get",
|
|
8609
8493
|
description: GET_DESCRIPTION,
|
|
@@ -8710,7 +8594,7 @@ var LocalAgentMemory = class {
|
|
|
8710
8594
|
const openOpts = { cwd: this.workspaceCwd };
|
|
8711
8595
|
if (embedding !== void 0) openOpts.embedding = embedding;
|
|
8712
8596
|
if (cfg?.backend !== void 0) openOpts.backend = cfg.backend;
|
|
8713
|
-
this.index = await
|
|
8597
|
+
this.index = await chunkJLMXKTBX_cjs.IndexManager.open(openOpts);
|
|
8714
8598
|
await this.index.sync();
|
|
8715
8599
|
this.toolsCache = [
|
|
8716
8600
|
createMemorySearchTool({ index: this.index }),
|
|
@@ -8959,7 +8843,7 @@ function createLocalAgentMemoryProvider(opts) {
|
|
|
8959
8843
|
return { facts: [], systemPromptAdditions: summary };
|
|
8960
8844
|
},
|
|
8961
8845
|
async recordSessionSummary(args) {
|
|
8962
|
-
await
|
|
8846
|
+
await chunkJLMXKTBX_cjs.writeSessionSummary(args);
|
|
8963
8847
|
},
|
|
8964
8848
|
async sync(handle) {
|
|
8965
8849
|
const state = handle[INTERNAL_LAM_KEY];
|
|
@@ -9148,7 +9032,7 @@ async function localAgentUsePersonality(args) {
|
|
|
9148
9032
|
// src/internal/local-agent/local-agent-runtime-extensions.ts
|
|
9149
9033
|
function localAgentRunUntil(agent, goal, options) {
|
|
9150
9034
|
async function* wrap() {
|
|
9151
|
-
const { runUntilImpl } = await import('./run-until-
|
|
9035
|
+
const { runUntilImpl } = await import('./run-until-ZZ2JLPJM.cjs');
|
|
9152
9036
|
const buildDeps = async () => {
|
|
9153
9037
|
const { judgeCallImpl } = await import('./judge-call-2FULQ6KL.cjs');
|
|
9154
9038
|
const { getAgentFacade } = await import('./agent-factory-registry-UU46BUMU.cjs');
|
|
@@ -9705,7 +9589,7 @@ var LocalAgent = class {
|
|
|
9705
9589
|
if (this.pluginsManager !== void 0) await this.pluginsManager.initialize();
|
|
9706
9590
|
const codePlugins = chunkBV2MWEMV_cjs.extractCodePlugins(this.options.plugins);
|
|
9707
9591
|
await this.pluginManagerCode.initialize(codePlugins);
|
|
9708
|
-
this.resolvedSubagents = await loadSubagents(
|
|
9592
|
+
this.resolvedSubagents = await chunkRZQ6E5YZ_cjs.loadSubagents(
|
|
9709
9593
|
this.workspaceCwd,
|
|
9710
9594
|
this.settingSourcesIncludeProject,
|
|
9711
9595
|
this.options.agents
|
|
@@ -9877,7 +9761,7 @@ var LocalAgent = class {
|
|
|
9877
9761
|
if (this.context !== void 0) await this.context.refresh();
|
|
9878
9762
|
if (this.skillsManager !== void 0) await this.skillsManager.refresh();
|
|
9879
9763
|
if (this.pluginsManager !== void 0) await this.pluginsManager.refresh();
|
|
9880
|
-
this.resolvedSubagents = await loadSubagents(
|
|
9764
|
+
this.resolvedSubagents = await chunkRZQ6E5YZ_cjs.loadSubagents(
|
|
9881
9765
|
this.workspaceCwd,
|
|
9882
9766
|
this.settingSourcesIncludeProject,
|
|
9883
9767
|
this.options.agents
|
|
@@ -10586,5 +10470,5 @@ exports.isFixtureApiKey = isFixtureApiKey;
|
|
|
10586
10470
|
exports.openRouterMemoryEmbeddingProviderAdapter = openRouterMemoryEmbeddingProviderAdapter;
|
|
10587
10471
|
exports.resolveApiKey = resolveApiKey;
|
|
10588
10472
|
exports.shouldUseFixtureMode = shouldUseFixtureMode;
|
|
10589
|
-
//# sourceMappingURL=chunk-
|
|
10590
|
-
//# sourceMappingURL=chunk-
|
|
10473
|
+
//# sourceMappingURL=chunk-YQAPEYUV.cjs.map
|
|
10474
|
+
//# sourceMappingURL=chunk-YQAPEYUV.cjs.map
|