theokit 0.1.0-alpha.11 → 0.1.0-alpha.12
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/cli/index.js +1 -1
- package/dist/{dist-UZV7J3YI.js → dist-IZY2ZRTK.js} +221 -72
- package/dist/dist-IZY2ZRTK.js.map +1 -0
- package/dist/{start-CSLJQXV3.js → start-7O423RHL.js} +3 -3
- package/package.json +1 -1
- package/dist/dist-UZV7J3YI.js.map +0 -1
- /package/dist/{start-CSLJQXV3.js.map → start-7O423RHL.js.map} +0 -0
package/dist/cli/index.js
CHANGED
|
@@ -23,7 +23,7 @@ cli.command("build", "Build for production").option("--target <target>", "Deploy
|
|
|
23
23
|
});
|
|
24
24
|
cli.command("start", "Start production server").option("--port <port>", "Port number").action(async (options) => {
|
|
25
25
|
try {
|
|
26
|
-
const { startCommand } = await import("../start-
|
|
26
|
+
const { startCommand } = await import("../start-7O423RHL.js");
|
|
27
27
|
await startCommand({ port: options.port ? Number(options.port) : void 0 });
|
|
28
28
|
} catch (err) {
|
|
29
29
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -2319,6 +2319,57 @@ var init_registry = __esm({
|
|
|
2319
2319
|
});
|
|
2320
2320
|
}
|
|
2321
2321
|
});
|
|
2322
|
+
function toJsonSchema(schema, options = { unrepresentable: "any" }) {
|
|
2323
|
+
const native = tryNativeZod4(schema, options);
|
|
2324
|
+
if (native !== void 0) return native;
|
|
2325
|
+
const fallback = tryFallbackLib(schema);
|
|
2326
|
+
if (fallback !== void 0) return fallback;
|
|
2327
|
+
throw new Error(
|
|
2328
|
+
'Zod \u2192 JSON Schema conversion failed: neither Zod 4\'s native `z.toJSONSchema` nor the `zod-to-json-schema` peer dep are available. On Zod 4: ensure `zod >= 4.0.0` is installed. On Zod 3: add `"zod-to-json-schema": "^3.24.0"` to your package.json.'
|
|
2329
|
+
);
|
|
2330
|
+
}
|
|
2331
|
+
function tryNativeZod4(schema, options) {
|
|
2332
|
+
if (cachedZodHasNativeApi === false) return void 0;
|
|
2333
|
+
let z12;
|
|
2334
|
+
try {
|
|
2335
|
+
z12 = requireSdk("zod");
|
|
2336
|
+
} catch {
|
|
2337
|
+
cachedZodHasNativeApi = false;
|
|
2338
|
+
return void 0;
|
|
2339
|
+
}
|
|
2340
|
+
if (typeof z12.toJSONSchema !== "function") {
|
|
2341
|
+
cachedZodHasNativeApi = false;
|
|
2342
|
+
return void 0;
|
|
2343
|
+
}
|
|
2344
|
+
cachedZodHasNativeApi = true;
|
|
2345
|
+
return z12.toJSONSchema(schema, options);
|
|
2346
|
+
}
|
|
2347
|
+
function tryFallbackLib(schema) {
|
|
2348
|
+
if (cachedFallbackLib !== void 0) {
|
|
2349
|
+
return cachedFallbackLib(schema);
|
|
2350
|
+
}
|
|
2351
|
+
if (triedFallback) return void 0;
|
|
2352
|
+
triedFallback = true;
|
|
2353
|
+
try {
|
|
2354
|
+
const mod = requireSdk("zod-to-json-schema");
|
|
2355
|
+
const fn2 = typeof mod.zodToJsonSchema === "function" ? mod.zodToJsonSchema : typeof mod.default === "function" ? mod.default : void 0;
|
|
2356
|
+
if (fn2 === void 0) return void 0;
|
|
2357
|
+
cachedFallbackLib = fn2;
|
|
2358
|
+
return fn2(schema);
|
|
2359
|
+
} catch {
|
|
2360
|
+
return void 0;
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
var requireSdk;
|
|
2364
|
+
var cachedZodHasNativeApi;
|
|
2365
|
+
var cachedFallbackLib;
|
|
2366
|
+
var triedFallback;
|
|
2367
|
+
var init_to_json_schema = __esm({
|
|
2368
|
+
"src/internal/zod/to-json-schema.ts"() {
|
|
2369
|
+
requireSdk = createRequire(import.meta.url);
|
|
2370
|
+
triedFallback = false;
|
|
2371
|
+
}
|
|
2372
|
+
});
|
|
2322
2373
|
function requireZod() {
|
|
2323
2374
|
if (cachedZ !== void 0) return cachedZ;
|
|
2324
2375
|
const r = createRequire(import.meta.url);
|
|
@@ -2369,9 +2420,7 @@ Respond by calling the \`output\` tool with the structured answer that matches t
|
|
|
2369
2420
|
}
|
|
2370
2421
|
function setupStructuredOutput(schema, maxRetries) {
|
|
2371
2422
|
const z12 = requireZod();
|
|
2372
|
-
const jsonSchema =
|
|
2373
|
-
unrepresentable: "any"
|
|
2374
|
-
});
|
|
2423
|
+
const jsonSchema = toJsonSchema(schema, { unrepresentable: "any" });
|
|
2375
2424
|
return {
|
|
2376
2425
|
z: z12,
|
|
2377
2426
|
jsonSchema,
|
|
@@ -2390,6 +2439,7 @@ var cachedZ;
|
|
|
2390
2439
|
var init_structured_output_helpers = __esm({
|
|
2391
2440
|
"src/internal/structured-output-helpers.ts"() {
|
|
2392
2441
|
init_errors();
|
|
2442
|
+
init_to_json_schema();
|
|
2393
2443
|
}
|
|
2394
2444
|
});
|
|
2395
2445
|
var generate_object_exports = {};
|
|
@@ -3169,7 +3219,7 @@ function buildHandoffTool(parentAgentId, descriptor, maxHandoffDepth) {
|
|
|
3169
3219
|
const inputZod = descriptor.options.inputType ?? z.object({
|
|
3170
3220
|
reason: z.string().optional().describe("Brief reason for the transfer (one short sentence).")
|
|
3171
3221
|
});
|
|
3172
|
-
const inputSchema =
|
|
3222
|
+
const inputSchema = toJsonSchema(inputZod);
|
|
3173
3223
|
return {
|
|
3174
3224
|
name: descriptor.resolvedToolName,
|
|
3175
3225
|
description,
|
|
@@ -3204,6 +3254,7 @@ function buildHandoffTool(parentAgentId, descriptor, maxHandoffDepth) {
|
|
|
3204
3254
|
var init_tool_injector = __esm({
|
|
3205
3255
|
"src/internal/handoff/tool-injector.ts"() {
|
|
3206
3256
|
init_handoff();
|
|
3257
|
+
init_to_json_schema();
|
|
3207
3258
|
init_dispatcher();
|
|
3208
3259
|
init_registry2();
|
|
3209
3260
|
}
|
|
@@ -10316,6 +10367,167 @@ function buildBedrockBody(request) {
|
|
|
10316
10367
|
init_credential_pool();
|
|
10317
10368
|
init_credential_pool_context();
|
|
10318
10369
|
init_errors();
|
|
10370
|
+
function mapOpenAICompatibleError(args) {
|
|
10371
|
+
const { providerId, status, body, headers, endpoint } = args;
|
|
10372
|
+
const code = mapOpenAiStatusToCode(status, body);
|
|
10373
|
+
const message = formatMessage2(providerId, status, code);
|
|
10374
|
+
const metadata = buildErrorMetadata({
|
|
10375
|
+
provider: providerId,
|
|
10376
|
+
endpoint,
|
|
10377
|
+
code,
|
|
10378
|
+
status,
|
|
10379
|
+
headers,
|
|
10380
|
+
body
|
|
10381
|
+
});
|
|
10382
|
+
if (status === 401 || status === 403) {
|
|
10383
|
+
return new AuthenticationError(message, { code: `${providerId}_auth_failed`, metadata });
|
|
10384
|
+
}
|
|
10385
|
+
if (status === 429) {
|
|
10386
|
+
return new RateLimitError(message, { code: `${providerId}_rate_limit`, metadata });
|
|
10387
|
+
}
|
|
10388
|
+
if (status === 400) {
|
|
10389
|
+
return new ConfigurationError(message, { code: `${providerId}_${code}`, metadata });
|
|
10390
|
+
}
|
|
10391
|
+
if (status === 408) {
|
|
10392
|
+
return new NetworkError(message, { code: `${providerId}_timeout`, metadata });
|
|
10393
|
+
}
|
|
10394
|
+
if (status >= 500 && status < 600) {
|
|
10395
|
+
return new NetworkError(message, { code: `${providerId}_server_error`, metadata });
|
|
10396
|
+
}
|
|
10397
|
+
return new UnknownAgentError(message, { code: `${providerId}_unknown`, metadata });
|
|
10398
|
+
}
|
|
10399
|
+
function extractOpenAiErrorCode(body) {
|
|
10400
|
+
if (body === null || typeof body !== "object") return void 0;
|
|
10401
|
+
const err = body.error;
|
|
10402
|
+
if (err === void 0 || err === null) return void 0;
|
|
10403
|
+
if (typeof err.code === "string") return err.code;
|
|
10404
|
+
if (typeof err.type === "string") return err.type;
|
|
10405
|
+
return void 0;
|
|
10406
|
+
}
|
|
10407
|
+
function mapOpenAiStatusToCode(status, body) {
|
|
10408
|
+
const rawCode = extractOpenAiErrorCode(body)?.toLowerCase() ?? "";
|
|
10409
|
+
if (rawCode.includes("context_length") || rawCode.includes("context_window") || rawCode.includes("too_many_tokens") || rawCode.includes("max_tokens")) {
|
|
10410
|
+
return "context_too_long";
|
|
10411
|
+
}
|
|
10412
|
+
if (rawCode.includes("content_filter") || rawCode.includes("content_policy") || rawCode.includes("safety")) {
|
|
10413
|
+
return "content_filtered";
|
|
10414
|
+
}
|
|
10415
|
+
if (rawCode.includes("model_not_found") || rawCode.includes("model_unavailable") || rawCode.includes("invalid_model")) {
|
|
10416
|
+
return "model_unavailable";
|
|
10417
|
+
}
|
|
10418
|
+
if (status === 402 || rawCode.includes("insufficient_quota") || rawCode.includes("quota_exceeded")) {
|
|
10419
|
+
return "invalid_request";
|
|
10420
|
+
}
|
|
10421
|
+
if (status === 401 || status === 403) return "auth_failed";
|
|
10422
|
+
if (status === 429) return "rate_limit";
|
|
10423
|
+
if (status === 408) return "timeout";
|
|
10424
|
+
if (status === 400) return "invalid_request";
|
|
10425
|
+
if (status >= 500 && status < 600) return "server_error";
|
|
10426
|
+
return "unknown";
|
|
10427
|
+
}
|
|
10428
|
+
function formatMessage2(providerId, status, code) {
|
|
10429
|
+
return `${providerId} API error: ${code} (HTTP ${status})`;
|
|
10430
|
+
}
|
|
10431
|
+
var ENV_GATE_KEY = "NODE_ENV";
|
|
10432
|
+
var ENV_GATE_VALUE = "test";
|
|
10433
|
+
var ENV_OVERRIDE_KEY = "THEOKIT_TEST_RESPONSE_OVERRIDE";
|
|
10434
|
+
function maybeWrapWithFaultInjection(client) {
|
|
10435
|
+
if (!isGateOn()) return client;
|
|
10436
|
+
return new FaultInjectingLlmClient(client);
|
|
10437
|
+
}
|
|
10438
|
+
var FaultInjectingLlmClient = class {
|
|
10439
|
+
name;
|
|
10440
|
+
/**
|
|
10441
|
+
* Inner (real) client. Exposed so layered transport assertions (router
|
|
10442
|
+
* pool-wiring tests, telemetry inspectors) can walk one level deep —
|
|
10443
|
+
* same pattern PoolAwareLlmClient uses for its inner transport.
|
|
10444
|
+
*/
|
|
10445
|
+
inner;
|
|
10446
|
+
constructor(inner) {
|
|
10447
|
+
this.inner = inner;
|
|
10448
|
+
this.name = inner.name;
|
|
10449
|
+
}
|
|
10450
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: explicit gate → parse → branch is clearer than splitting
|
|
10451
|
+
async *stream(request, signal) {
|
|
10452
|
+
if (!isGateOn()) {
|
|
10453
|
+
return yield* this.inner.stream(request, signal);
|
|
10454
|
+
}
|
|
10455
|
+
const parsed = parseOverrideOrWarnOnce();
|
|
10456
|
+
if (parsed === void 0) {
|
|
10457
|
+
return yield* this.inner.stream(request, signal);
|
|
10458
|
+
}
|
|
10459
|
+
if (parsed.status >= 400) {
|
|
10460
|
+
throw mapOpenAICompatibleError({
|
|
10461
|
+
providerId: this.name,
|
|
10462
|
+
status: parsed.status,
|
|
10463
|
+
body: parsed.body,
|
|
10464
|
+
headers: void 0,
|
|
10465
|
+
endpoint: "/v1/chat/completions"
|
|
10466
|
+
});
|
|
10467
|
+
}
|
|
10468
|
+
const text = extractText(parsed.body);
|
|
10469
|
+
yield { type: "text_delta", text };
|
|
10470
|
+
yield { type: "stop", reason: "end_turn" };
|
|
10471
|
+
return {
|
|
10472
|
+
stopReason: "end_turn",
|
|
10473
|
+
text,
|
|
10474
|
+
toolCalls: [],
|
|
10475
|
+
inputTokens: 0,
|
|
10476
|
+
outputTokens: 0
|
|
10477
|
+
};
|
|
10478
|
+
}
|
|
10479
|
+
};
|
|
10480
|
+
function isGateOn() {
|
|
10481
|
+
return process.env[ENV_GATE_KEY] === ENV_GATE_VALUE;
|
|
10482
|
+
}
|
|
10483
|
+
var warnedInvalidJson = false;
|
|
10484
|
+
function parseOverrideOrWarnOnce() {
|
|
10485
|
+
const raw = process.env[ENV_OVERRIDE_KEY];
|
|
10486
|
+
if (raw === void 0 || raw.length === 0) return void 0;
|
|
10487
|
+
let candidate;
|
|
10488
|
+
try {
|
|
10489
|
+
candidate = JSON.parse(raw);
|
|
10490
|
+
} catch (_err) {
|
|
10491
|
+
warnInvalidJsonOnce();
|
|
10492
|
+
return void 0;
|
|
10493
|
+
}
|
|
10494
|
+
if (candidate === null || typeof candidate !== "object") {
|
|
10495
|
+
warnInvalidJsonOnce();
|
|
10496
|
+
return void 0;
|
|
10497
|
+
}
|
|
10498
|
+
const obj = candidate;
|
|
10499
|
+
if (typeof obj.status !== "number" || !Number.isFinite(obj.status)) {
|
|
10500
|
+
warnInvalidJsonOnce();
|
|
10501
|
+
return void 0;
|
|
10502
|
+
}
|
|
10503
|
+
return { status: obj.status, body: obj.body };
|
|
10504
|
+
}
|
|
10505
|
+
function warnInvalidJsonOnce(_raw) {
|
|
10506
|
+
if (warnedInvalidJson) return;
|
|
10507
|
+
warnedInvalidJson = true;
|
|
10508
|
+
process.stderr.write(
|
|
10509
|
+
`[theokit-sdk] ${ENV_OVERRIDE_KEY} is set but value is not valid JSON of shape \`{"status": number, "body": object | string}\`. Falling back to real LLM call. This warning is shown once per process.
|
|
10510
|
+
`
|
|
10511
|
+
);
|
|
10512
|
+
}
|
|
10513
|
+
function extractText(body) {
|
|
10514
|
+
if (typeof body === "string") return body;
|
|
10515
|
+
if (body === null || typeof body !== "object") return "";
|
|
10516
|
+
const fromOpenAi = readOpenAiContent(body);
|
|
10517
|
+
if (fromOpenAi !== void 0) return fromOpenAi;
|
|
10518
|
+
const obj = body;
|
|
10519
|
+
if (typeof obj.text === "string") return obj.text;
|
|
10520
|
+
return "";
|
|
10521
|
+
}
|
|
10522
|
+
function readOpenAiContent(body) {
|
|
10523
|
+
const obj = body;
|
|
10524
|
+
if (!Array.isArray(obj.choices) || obj.choices.length === 0) return void 0;
|
|
10525
|
+
const first = obj.choices[0];
|
|
10526
|
+
const content = first?.message?.content;
|
|
10527
|
+
if (typeof content === "string") return content;
|
|
10528
|
+
return void 0;
|
|
10529
|
+
}
|
|
10530
|
+
init_errors();
|
|
10319
10531
|
function mapOllamaTransportError(args) {
|
|
10320
10532
|
if (args.providerId !== "ollama") return void 0;
|
|
10321
10533
|
const causeCode = extractCauseCode(args.cause);
|
|
@@ -10614,68 +10826,6 @@ function toOllamaTools(tools) {
|
|
|
10614
10826
|
}
|
|
10615
10827
|
}));
|
|
10616
10828
|
}
|
|
10617
|
-
init_errors();
|
|
10618
|
-
function mapOpenAICompatibleError(args) {
|
|
10619
|
-
const { providerId, status, body, headers, endpoint } = args;
|
|
10620
|
-
const code = mapOpenAiStatusToCode(status, body);
|
|
10621
|
-
const message = formatMessage2(providerId, status, code);
|
|
10622
|
-
const metadata = buildErrorMetadata({
|
|
10623
|
-
provider: providerId,
|
|
10624
|
-
endpoint,
|
|
10625
|
-
code,
|
|
10626
|
-
status,
|
|
10627
|
-
headers,
|
|
10628
|
-
body
|
|
10629
|
-
});
|
|
10630
|
-
if (status === 401 || status === 403) {
|
|
10631
|
-
return new AuthenticationError(message, { code: `${providerId}_auth_failed`, metadata });
|
|
10632
|
-
}
|
|
10633
|
-
if (status === 429) {
|
|
10634
|
-
return new RateLimitError(message, { code: `${providerId}_rate_limit`, metadata });
|
|
10635
|
-
}
|
|
10636
|
-
if (status === 400) {
|
|
10637
|
-
return new ConfigurationError(message, { code: `${providerId}_${code}`, metadata });
|
|
10638
|
-
}
|
|
10639
|
-
if (status === 408) {
|
|
10640
|
-
return new NetworkError(message, { code: `${providerId}_timeout`, metadata });
|
|
10641
|
-
}
|
|
10642
|
-
if (status >= 500 && status < 600) {
|
|
10643
|
-
return new NetworkError(message, { code: `${providerId}_server_error`, metadata });
|
|
10644
|
-
}
|
|
10645
|
-
return new UnknownAgentError(message, { code: `${providerId}_unknown`, metadata });
|
|
10646
|
-
}
|
|
10647
|
-
function extractOpenAiErrorCode(body) {
|
|
10648
|
-
if (body === null || typeof body !== "object") return void 0;
|
|
10649
|
-
const err = body.error;
|
|
10650
|
-
if (err === void 0 || err === null) return void 0;
|
|
10651
|
-
if (typeof err.code === "string") return err.code;
|
|
10652
|
-
if (typeof err.type === "string") return err.type;
|
|
10653
|
-
return void 0;
|
|
10654
|
-
}
|
|
10655
|
-
function mapOpenAiStatusToCode(status, body) {
|
|
10656
|
-
const rawCode = extractOpenAiErrorCode(body)?.toLowerCase() ?? "";
|
|
10657
|
-
if (rawCode.includes("context_length") || rawCode.includes("context_window") || rawCode.includes("too_many_tokens") || rawCode.includes("max_tokens")) {
|
|
10658
|
-
return "context_too_long";
|
|
10659
|
-
}
|
|
10660
|
-
if (rawCode.includes("content_filter") || rawCode.includes("content_policy") || rawCode.includes("safety")) {
|
|
10661
|
-
return "content_filtered";
|
|
10662
|
-
}
|
|
10663
|
-
if (rawCode.includes("model_not_found") || rawCode.includes("model_unavailable") || rawCode.includes("invalid_model")) {
|
|
10664
|
-
return "model_unavailable";
|
|
10665
|
-
}
|
|
10666
|
-
if (status === 402 || rawCode.includes("insufficient_quota") || rawCode.includes("quota_exceeded")) {
|
|
10667
|
-
return "invalid_request";
|
|
10668
|
-
}
|
|
10669
|
-
if (status === 401 || status === 403) return "auth_failed";
|
|
10670
|
-
if (status === 429) return "rate_limit";
|
|
10671
|
-
if (status === 408) return "timeout";
|
|
10672
|
-
if (status === 400) return "invalid_request";
|
|
10673
|
-
if (status >= 500 && status < 600) return "server_error";
|
|
10674
|
-
return "unknown";
|
|
10675
|
-
}
|
|
10676
|
-
function formatMessage2(providerId, status, code) {
|
|
10677
|
-
return `${providerId} API error: ${code} (HTTP ${status})`;
|
|
10678
|
-
}
|
|
10679
10829
|
var OpenAIClient = class {
|
|
10680
10830
|
constructor(options) {
|
|
10681
10831
|
this.options = options;
|
|
@@ -11217,7 +11367,7 @@ function buildChain(options) {
|
|
|
11217
11367
|
if (seen.has(lowered)) return;
|
|
11218
11368
|
seen.add(lowered);
|
|
11219
11369
|
const client = buildClient(lowered, options);
|
|
11220
|
-
if (client !== void 0) clients.push(client);
|
|
11370
|
+
if (client !== void 0) clients.push(maybeWrapWithFaultInjection(client));
|
|
11221
11371
|
};
|
|
11222
11372
|
addClient(options.primary);
|
|
11223
11373
|
for (const fallback of options.fallback ?? []) addClient(fallback);
|
|
@@ -16679,6 +16829,7 @@ async function updateJobStatus(jobId, enabled) {
|
|
|
16679
16829
|
}
|
|
16680
16830
|
return updated;
|
|
16681
16831
|
}
|
|
16832
|
+
init_to_json_schema();
|
|
16682
16833
|
var cachedZ2;
|
|
16683
16834
|
function requireZod2() {
|
|
16684
16835
|
if (cachedZ2 !== void 0) return cachedZ2;
|
|
@@ -16695,10 +16846,8 @@ function requireZod2() {
|
|
|
16695
16846
|
return cachedZ2;
|
|
16696
16847
|
}
|
|
16697
16848
|
function defineTool(spec) {
|
|
16698
|
-
|
|
16699
|
-
const inputSchema =
|
|
16700
|
-
unrepresentable: "any"
|
|
16701
|
-
});
|
|
16849
|
+
requireZod2();
|
|
16850
|
+
const inputSchema = toJsonSchema(spec.inputSchema, { unrepresentable: "any" });
|
|
16702
16851
|
return {
|
|
16703
16852
|
name: spec.name,
|
|
16704
16853
|
description: spec.description,
|
|
@@ -18634,4 +18783,4 @@ export {
|
|
|
18634
18783
|
preflightCheck,
|
|
18635
18784
|
toShareGptTrajectory
|
|
18636
18785
|
};
|
|
18637
|
-
//# sourceMappingURL=dist-
|
|
18786
|
+
//# sourceMappingURL=dist-IZY2ZRTK.js.map
|