crosscheck-mcp 0.2.28 → 0.2.29
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/browser-ext.cjs +99 -11
- package/dist/browser-ext.cjs.map +1 -1
- package/dist/browser-ext.js +99 -11
- package/dist/browser-ext.js.map +1 -1
- package/dist/embed.cjs +303 -13
- package/dist/embed.cjs.map +1 -1
- package/dist/embed.d.cts +94 -2
- package/dist/embed.d.ts +94 -2
- package/dist/embed.js +302 -13
- package/dist/embed.js.map +1 -1
- package/dist/node-stdio.cjs +99 -11
- package/dist/node-stdio.cjs.map +1 -1
- package/dist/node-stdio.d.cts +1 -75
- package/dist/node-stdio.d.ts +1 -75
- package/dist/node-stdio.js +99 -11
- package/dist/node-stdio.js.map +1 -1
- package/dist/types-BcprisDl.d.cts +76 -0
- package/dist/types-BcprisDl.d.ts +76 -0
- package/package.json +1 -1
package/dist/embed.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/entrypoints/embed.ts
|
|
32
32
|
var embed_exports = {};
|
|
33
33
|
__export(embed_exports, {
|
|
34
|
+
ACTIVITY_TEXT_CAP: () => ACTIVITY_TEXT_CAP,
|
|
34
35
|
DEFAULT_EXCLUDED_PROVIDERS: () => DEFAULT_EXCLUDED_PROVIDERS,
|
|
35
36
|
DEFAULT_FALLBACKS: () => DEFAULT_FALLBACKS,
|
|
36
37
|
DEFAULT_MODELS: () => DEFAULT_MODELS,
|
|
@@ -49,6 +50,7 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${_
|
|
|
49
50
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
50
51
|
|
|
51
52
|
// src/entrypoints/embed.ts
|
|
53
|
+
var import_node_async_hooks2 = require("async_hooks");
|
|
52
54
|
var import_node_fs16 = require("fs");
|
|
53
55
|
var import_node_path15 = __toESM(require("path"), 1);
|
|
54
56
|
var import_node_url2 = require("url");
|
|
@@ -533,6 +535,52 @@ function rejectsDisabledThinking(model) {
|
|
|
533
535
|
const m = model.toLowerCase();
|
|
534
536
|
return ADAPTIVE_THINKING_PREFIXES.some((p) => m.startsWith(p));
|
|
535
537
|
}
|
|
538
|
+
var NO_FORCED_TOOL_PREFIXES = [
|
|
539
|
+
"claude-fable-5-1",
|
|
540
|
+
"claude-mythos-5-1",
|
|
541
|
+
"claude-opus-5-5",
|
|
542
|
+
"claude-sonnet-5-5"
|
|
543
|
+
];
|
|
544
|
+
function rejectsForcedToolUse(model) {
|
|
545
|
+
const m = model.toLowerCase();
|
|
546
|
+
return NO_FORCED_TOOL_PREFIXES.some((p) => m.startsWith(p));
|
|
547
|
+
}
|
|
548
|
+
var UNSUPPORTED_SCHEMA_KEYS = /* @__PURE__ */ new Set([
|
|
549
|
+
"minimum",
|
|
550
|
+
"maximum",
|
|
551
|
+
"exclusiveMinimum",
|
|
552
|
+
"exclusiveMaximum",
|
|
553
|
+
"multipleOf",
|
|
554
|
+
"minLength",
|
|
555
|
+
"maxLength",
|
|
556
|
+
"pattern",
|
|
557
|
+
"minItems",
|
|
558
|
+
"maxItems",
|
|
559
|
+
"uniqueItems",
|
|
560
|
+
"minProperties",
|
|
561
|
+
"maxProperties",
|
|
562
|
+
"$schema"
|
|
563
|
+
]);
|
|
564
|
+
function toStructuredOutputSchema(schema) {
|
|
565
|
+
const walk = (node) => {
|
|
566
|
+
if (Array.isArray(node)) return node.map(walk);
|
|
567
|
+
if (!node || typeof node !== "object") return node;
|
|
568
|
+
const out = {};
|
|
569
|
+
for (const [k, v] of Object.entries(node)) {
|
|
570
|
+
if (UNSUPPORTED_SCHEMA_KEYS.has(k)) continue;
|
|
571
|
+
if (k === "properties" && v && typeof v === "object") {
|
|
572
|
+
out[k] = Object.fromEntries(Object.entries(v).map(([pk, pv]) => [pk, walk(pv)]));
|
|
573
|
+
} else if (["items", "anyOf", "allOf", "oneOf", "not", "$defs", "definitions"].includes(k)) {
|
|
574
|
+
out[k] = k === "$defs" || k === "definitions" ? Object.fromEntries(Object.entries(v ?? {}).map(([dk, dv]) => [dk, walk(dv)])) : walk(v);
|
|
575
|
+
} else {
|
|
576
|
+
out[k] = v;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
if (out["type"] === "object" || "properties" in out) out["additionalProperties"] = false;
|
|
580
|
+
return out;
|
|
581
|
+
};
|
|
582
|
+
return walk(schema);
|
|
583
|
+
}
|
|
536
584
|
var ANTHROPIC_STRUCTURED_TOOL_NAME = "structured_output";
|
|
537
585
|
function applyPromptCaching(body, env = process.env) {
|
|
538
586
|
const flag = (env["CROSSCHECK_ANTHROPIC_PROMPT_CACHE"] ?? "").trim();
|
|
@@ -584,7 +632,12 @@ function buildAnthropicRequest(opts) {
|
|
|
584
632
|
body.thinking = { type: "disabled" };
|
|
585
633
|
}
|
|
586
634
|
}
|
|
587
|
-
if (opts.jsonSchema) {
|
|
635
|
+
if (opts.jsonSchema && rejectsForcedToolUse(opts.model)) {
|
|
636
|
+
body.output_config = {
|
|
637
|
+
...body.output_config ?? {},
|
|
638
|
+
format: { type: "json_schema", schema: toStructuredOutputSchema(opts.jsonSchema) }
|
|
639
|
+
};
|
|
640
|
+
} else if (opts.jsonSchema) {
|
|
588
641
|
body.tools = [{
|
|
589
642
|
name: ANTHROPIC_STRUCTURED_TOOL_NAME,
|
|
590
643
|
description: "Emit a single JSON object matching the requested schema.",
|
|
@@ -985,7 +1038,15 @@ function buildOpenAICompatibleRequest(opts) {
|
|
|
985
1038
|
json_schema: {
|
|
986
1039
|
name: "structured_output",
|
|
987
1040
|
schema: opts.jsonSchema,
|
|
988
|
-
strict:
|
|
1041
|
+
// NOT strict. Strict mode requires `additionalProperties: false` on
|
|
1042
|
+
// every object and every property listed in `required` — the
|
|
1043
|
+
// engine's schemas don't meet that, so every structured OpenAI call
|
|
1044
|
+
// (planner, judges, synthesis) was a 400, unnoticed until the canary
|
|
1045
|
+
// grew a structured check (2026-10-11). Non-strict still shapes the
|
|
1046
|
+
// reply to the schema, and structured.ts validates it against the
|
|
1047
|
+
// full schema regardless, so strictness added a failure mode and no
|
|
1048
|
+
// safety.
|
|
1049
|
+
strict: false
|
|
989
1050
|
}
|
|
990
1051
|
};
|
|
991
1052
|
}
|
|
@@ -1273,7 +1334,7 @@ var import_zod = require("zod");
|
|
|
1273
1334
|
|
|
1274
1335
|
// src/server-meta.ts
|
|
1275
1336
|
var SERVER_NAME = "crosscheck-agent";
|
|
1276
|
-
var SERVER_VERSION = true ? "0.2.
|
|
1337
|
+
var SERVER_VERSION = true ? "0.2.29" : "0.0.0-dev";
|
|
1277
1338
|
|
|
1278
1339
|
// src/tools/audit.ts
|
|
1279
1340
|
var import_node_fs4 = require("fs");
|
|
@@ -6369,6 +6430,19 @@ var import_node_perf_hooks6 = require("perf_hooks");
|
|
|
6369
6430
|
var import_node_async_hooks = require("async_hooks");
|
|
6370
6431
|
var import_node_perf_hooks5 = require("perf_hooks");
|
|
6371
6432
|
var progressStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
6433
|
+
async function withProgress(token, sendNotification, fn) {
|
|
6434
|
+
if (token === void 0 || token === null) {
|
|
6435
|
+
return fn();
|
|
6436
|
+
}
|
|
6437
|
+
const ctx = {
|
|
6438
|
+
token,
|
|
6439
|
+
wallStart: import_node_perf_hooks5.performance.now(),
|
|
6440
|
+
cpuStart: process.cpuUsage(),
|
|
6441
|
+
step: { value: 0 },
|
|
6442
|
+
sendNotification
|
|
6443
|
+
};
|
|
6444
|
+
return progressStorage.run(ctx, fn);
|
|
6445
|
+
}
|
|
6372
6446
|
async function emitProgress(message, opts) {
|
|
6373
6447
|
const ctx = progressStorage.getStore();
|
|
6374
6448
|
const wallStart = ctx ? ctx.wallStart : import_node_perf_hooks5.performance.now();
|
|
@@ -7888,6 +7962,16 @@ function buildCallContext(args) {
|
|
|
7888
7962
|
var CREATE_DOC_MAX_BYTES = 32 * 1024;
|
|
7889
7963
|
var CREATE_AUDIT_THRESHOLD = 0.7;
|
|
7890
7964
|
async function runCreate(args, opts) {
|
|
7965
|
+
const subEnvelopes = [];
|
|
7966
|
+
const tracked = (fn) => async (...a) => {
|
|
7967
|
+
const out = await fn(...a);
|
|
7968
|
+
subEnvelopes.push(out);
|
|
7969
|
+
return out;
|
|
7970
|
+
};
|
|
7971
|
+
const confer = tracked(runConfer);
|
|
7972
|
+
const orchestrate = tracked(runOrchestrate);
|
|
7973
|
+
const review = tracked(runReview);
|
|
7974
|
+
const audit = tracked(runAudit);
|
|
7891
7975
|
const instruction = typeof args["instruction"] === "string" ? args["instruction"] : String(args["instruction"] ?? "");
|
|
7892
7976
|
if (!instruction) {
|
|
7893
7977
|
return errorEnvelope6(
|
|
@@ -7924,7 +8008,7 @@ ${constraints}
|
|
|
7924
8008
|
|
|
7925
8009
|
` : "") + `DOCUMENTS (${okCount} of ${descriptors.length} ingested):
|
|
7926
8010
|
${documentsPayload}`;
|
|
7927
|
-
const scope = await
|
|
8011
|
+
const scope = await confer({
|
|
7928
8012
|
question: "We are about to orchestrate a full plan->build->review->audit lifecycle for this instruction. List 3-6 concrete sub-tasks (each with a one-line description and a difficulty: low|med|high), any critical assumptions, and any missing-information risks. Be concise and decisive \u2014 your output will be used to build the orchestration DAG.\n\nINSTRUCTION:\n" + instruction,
|
|
7929
8013
|
context: contextBlock,
|
|
7930
8014
|
...providers !== void 0 ? { providers } : {},
|
|
@@ -7951,7 +8035,7 @@ ${scopeAnswer || "(none)"}
|
|
|
7951
8035
|
};
|
|
7952
8036
|
if (providers !== void 0) orchestrateArgs["providers"] = providers;
|
|
7953
8037
|
if (planOnly) orchestrateArgs["plan_only"] = true;
|
|
7954
|
-
let orchestration = await
|
|
8038
|
+
let orchestration = await orchestrate(orchestrateArgs, {
|
|
7955
8039
|
providers: opts.providers,
|
|
7956
8040
|
allowlist: opts.allowlist ?? null,
|
|
7957
8041
|
moderator,
|
|
@@ -7980,7 +8064,7 @@ ${scopeAnswer || "(none)"}
|
|
|
7980
8064
|
}
|
|
7981
8065
|
let reviewEnvelope = null;
|
|
7982
8066
|
if (!skipReview && typeof orchestration["final"] === "string" && orchestration["final"]) {
|
|
7983
|
-
reviewEnvelope = await
|
|
8067
|
+
reviewEnvelope = await review({
|
|
7984
8068
|
snippet: orchestration["final"],
|
|
7985
8069
|
intent: `final deliverable for: ${instruction}`,
|
|
7986
8070
|
...providers !== void 0 ? { providers } : {},
|
|
@@ -8000,7 +8084,7 @@ ${scopeAnswer || "(none)"}
|
|
|
8000
8084
|
const panelExhausted = producingPanel.length > 0 && producingPanel.every(
|
|
8001
8085
|
(p) => p in opts.providers || Object.keys(opts.providers).includes(p.toLowerCase())
|
|
8002
8086
|
) && producingPanel.length >= Object.keys(opts.providers).length;
|
|
8003
|
-
auditEnvelope = await
|
|
8087
|
+
auditEnvelope = await audit({
|
|
8004
8088
|
output_to_audit: orchestration["final"],
|
|
8005
8089
|
producing_panelists: producingPanel,
|
|
8006
8090
|
...auditRubric !== void 0 ? { rubric: auditRubric } : {},
|
|
@@ -8029,7 +8113,7 @@ ${retryConstraints}
|
|
|
8029
8113
|
DOCUMENTS:
|
|
8030
8114
|
${documentsPayload}`
|
|
8031
8115
|
};
|
|
8032
|
-
const retryOrchestration = await
|
|
8116
|
+
const retryOrchestration = await orchestrate(
|
|
8033
8117
|
retryOrchestrateArgs,
|
|
8034
8118
|
{
|
|
8035
8119
|
providers: opts.providers,
|
|
@@ -8043,7 +8127,7 @@ ${documentsPayload}`
|
|
|
8043
8127
|
if (typeof retryOrchestration["final"] === "string" && retryOrchestration["final"]) {
|
|
8044
8128
|
const retryPanel = computeProducingPanel(retryOrchestration);
|
|
8045
8129
|
const retryPanelExhausted = retryPanel.length > 0 && retryPanel.length >= Object.keys(opts.providers).length;
|
|
8046
|
-
auditEnvelope = await
|
|
8130
|
+
auditEnvelope = await audit({
|
|
8047
8131
|
output_to_audit: retryOrchestration["final"],
|
|
8048
8132
|
producing_panelists: retryPanel,
|
|
8049
8133
|
...auditRubric !== void 0 ? { rubric: auditRubric } : {},
|
|
@@ -8118,9 +8202,28 @@ ${documentsPayload}`
|
|
|
8118
8202
|
["auditor", "items", "overall_score", "passed", "rubric"]
|
|
8119
8203
|
),
|
|
8120
8204
|
artifacts,
|
|
8121
|
-
warnings
|
|
8205
|
+
warnings,
|
|
8206
|
+
...combinedUsage(subEnvelopes)
|
|
8122
8207
|
};
|
|
8123
8208
|
}
|
|
8209
|
+
function combinedUsage(envelopes) {
|
|
8210
|
+
const usages = [];
|
|
8211
|
+
const byCallTiming = [];
|
|
8212
|
+
let wall = 0, cpu = 0;
|
|
8213
|
+
for (const env of envelopes) {
|
|
8214
|
+
const e = env ?? {};
|
|
8215
|
+
const calls = e["usage"]?.["by_call"] ?? [];
|
|
8216
|
+
const t = e["timing"] ?? {};
|
|
8217
|
+
const timing = Array.isArray(t["by_call"]) ? t["by_call"] : [];
|
|
8218
|
+
if (!Array.isArray(calls) || calls.length === 0) continue;
|
|
8219
|
+
usages.push(...calls);
|
|
8220
|
+
if (timing.length === calls.length) byCallTiming.push(...timing);
|
|
8221
|
+
else for (const c of calls) byCallTiming.push({ provider: c.provider, model: c.model, purpose: c.purpose ?? null, wall_ms: 0, cpu_ms: 0, cache_hit: false });
|
|
8222
|
+
wall += Number(t["wall_ms"] ?? 0) || 0;
|
|
8223
|
+
cpu += Number(t["cpu_ms"] ?? 0) || 0;
|
|
8224
|
+
}
|
|
8225
|
+
return { usage: aggregateUsage(usages), timing: { wall_ms: wall, cpu_ms: cpu, by_call: byCallTiming } };
|
|
8226
|
+
}
|
|
8124
8227
|
async function ingestDocuments(documents, sessionId, opts) {
|
|
8125
8228
|
if (documents.length === 0) return [];
|
|
8126
8229
|
const out = [];
|
|
@@ -11597,7 +11700,7 @@ var CHECK_INTERVAL_SECONDS = 3 * 24 * 60 * 60;
|
|
|
11597
11700
|
var DEFAULT_PACKAGE = "crosscheck-cli";
|
|
11598
11701
|
var FETCH_TIMEOUT_MS = 3e3;
|
|
11599
11702
|
function engineVersion() {
|
|
11600
|
-
return true ? "0.2.
|
|
11703
|
+
return true ? "0.2.29" : "0.0.0-dev";
|
|
11601
11704
|
}
|
|
11602
11705
|
function defaultUpdateCachePath() {
|
|
11603
11706
|
const base = process.env["CROSSCHECK_DATA_DIR"] || import_node_path12.default.join(import_node_os2.default.homedir() || import_node_os2.default.tmpdir(), ".crosscheck");
|
|
@@ -13388,6 +13491,107 @@ var ENGINE_TO_VAULT = { xai: "grok" };
|
|
|
13388
13491
|
function vaultId(engineName) {
|
|
13389
13492
|
return ENGINE_TO_VAULT[engineName] ?? engineName;
|
|
13390
13493
|
}
|
|
13494
|
+
var ACTIVITY_TEXT_CAP = 8e3;
|
|
13495
|
+
var ASKED_CAP = 280;
|
|
13496
|
+
var runContext = new import_node_async_hooks2.AsyncLocalStorage();
|
|
13497
|
+
var SYNTHESIS_PURPOSES = /* @__PURE__ */ new Set(["synth", "moderator", "recombine", "judge", "unify"]);
|
|
13498
|
+
function exemptFromSkip(ctx, provider, purpose) {
|
|
13499
|
+
return provider === ctx.moderator && SYNTHESIS_PURPOSES.has(purpose);
|
|
13500
|
+
}
|
|
13501
|
+
function skippedError(provider, why, limitMs) {
|
|
13502
|
+
return new ProviderError(
|
|
13503
|
+
"client",
|
|
13504
|
+
why === "timeout" ? `${provider}: stopped after ${Math.round((limitMs ?? 0) / 1e3)}s (your per-model time limit)` : `${provider}: stopped waiting (you skipped it)`,
|
|
13505
|
+
{ transient: false }
|
|
13506
|
+
);
|
|
13507
|
+
}
|
|
13508
|
+
function lastUserText(args) {
|
|
13509
|
+
const msgs = args.messages;
|
|
13510
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
13511
|
+
const m = msgs[i];
|
|
13512
|
+
if (m && m.role === "user" && typeof m.content === "string") {
|
|
13513
|
+
const t = m.content.replace(/\s+/g, " ").trim();
|
|
13514
|
+
return t.length > ASKED_CAP ? `${t.slice(0, ASKED_CAP - 1)}\u2026` : t;
|
|
13515
|
+
}
|
|
13516
|
+
}
|
|
13517
|
+
return "";
|
|
13518
|
+
}
|
|
13519
|
+
function withActivity(p) {
|
|
13520
|
+
const send = p.send.bind(p);
|
|
13521
|
+
return {
|
|
13522
|
+
name: p.name,
|
|
13523
|
+
model: p.model,
|
|
13524
|
+
...p.fallbackModels ? { fallbackModels: p.fallbackModels } : {},
|
|
13525
|
+
send: async (args) => {
|
|
13526
|
+
const ctx = runContext.getStore();
|
|
13527
|
+
if (!ctx) return send(args);
|
|
13528
|
+
const callId = ctx.nextCallId();
|
|
13529
|
+
const provider = vaultId(p.name);
|
|
13530
|
+
const model = args.modelOverride ?? p.model;
|
|
13531
|
+
const purpose = args.purpose ?? "worker";
|
|
13532
|
+
const started = Date.now();
|
|
13533
|
+
const exempt = exemptFromSkip(ctx, provider, purpose);
|
|
13534
|
+
if (!exempt && ctx.skipped.has(provider)) throw skippedError(provider, "user");
|
|
13535
|
+
ctx.emit({ type: "call.start", runId: ctx.runId, at: started, callId, provider, model, purpose, asked: lastUserText(args) });
|
|
13536
|
+
const controller = new AbortController();
|
|
13537
|
+
if (args.signal) {
|
|
13538
|
+
if (args.signal.aborted) controller.abort(args.signal.reason);
|
|
13539
|
+
else args.signal.addEventListener("abort", () => controller.abort(args.signal.reason), { once: true });
|
|
13540
|
+
}
|
|
13541
|
+
let stopped;
|
|
13542
|
+
if (!exempt) ctx.inflight.set(callId, { provider, purpose, controller });
|
|
13543
|
+
const timer = !exempt && ctx.callTimeoutMs && ctx.callTimeoutMs > 0 ? setTimeout(() => {
|
|
13544
|
+
stopped = "timeout";
|
|
13545
|
+
controller.abort("timeout");
|
|
13546
|
+
}, ctx.callTimeoutMs) : void 0;
|
|
13547
|
+
controller.signal.addEventListener("abort", () => {
|
|
13548
|
+
if (!stopped && controller.signal.reason === "skip") stopped = "user";
|
|
13549
|
+
}, { once: true });
|
|
13550
|
+
try {
|
|
13551
|
+
const res = await send({ ...args, signal: controller.signal });
|
|
13552
|
+
const text = typeof res.text === "string" ? res.text : "";
|
|
13553
|
+
ctx.emit({
|
|
13554
|
+
type: "call.done",
|
|
13555
|
+
runId: ctx.runId,
|
|
13556
|
+
at: Date.now(),
|
|
13557
|
+
callId,
|
|
13558
|
+
provider,
|
|
13559
|
+
model,
|
|
13560
|
+
purpose,
|
|
13561
|
+
ok: true,
|
|
13562
|
+
ms: Date.now() - started,
|
|
13563
|
+
text: text.slice(0, ACTIVITY_TEXT_CAP),
|
|
13564
|
+
truncated: text.length > ACTIVITY_TEXT_CAP,
|
|
13565
|
+
error: null,
|
|
13566
|
+
usage: usageOf(res)
|
|
13567
|
+
});
|
|
13568
|
+
return res;
|
|
13569
|
+
} catch (err) {
|
|
13570
|
+
const out = stopped ? skippedError(provider, stopped, ctx.callTimeoutMs) : err;
|
|
13571
|
+
ctx.emit({
|
|
13572
|
+
type: "call.done",
|
|
13573
|
+
runId: ctx.runId,
|
|
13574
|
+
at: Date.now(),
|
|
13575
|
+
callId,
|
|
13576
|
+
provider,
|
|
13577
|
+
model,
|
|
13578
|
+
purpose,
|
|
13579
|
+
ok: false,
|
|
13580
|
+
ms: Date.now() - started,
|
|
13581
|
+
text: "",
|
|
13582
|
+
truncated: false,
|
|
13583
|
+
error: out instanceof Error ? out.message : String(out),
|
|
13584
|
+
usage: null,
|
|
13585
|
+
...stopped ? { stopped } : {}
|
|
13586
|
+
});
|
|
13587
|
+
throw out;
|
|
13588
|
+
} finally {
|
|
13589
|
+
if (timer) clearTimeout(timer);
|
|
13590
|
+
ctx.inflight.delete(callId);
|
|
13591
|
+
}
|
|
13592
|
+
}
|
|
13593
|
+
};
|
|
13594
|
+
}
|
|
13391
13595
|
function usageOf(answer) {
|
|
13392
13596
|
const u = answer["usage"];
|
|
13393
13597
|
if (!u || typeof u !== "object") return null;
|
|
@@ -13423,6 +13627,8 @@ function bundledPricingPath() {
|
|
|
13423
13627
|
}
|
|
13424
13628
|
}
|
|
13425
13629
|
var runCounter = 0;
|
|
13630
|
+
var callCounter = 0;
|
|
13631
|
+
var nextCallId = () => ++callCounter;
|
|
13426
13632
|
function nextRunId() {
|
|
13427
13633
|
runCounter += 1;
|
|
13428
13634
|
return `run_${Date.now().toString(36)}_${runCounter}`;
|
|
@@ -13441,7 +13647,9 @@ function createEmbeddedEngine(opts) {
|
|
|
13441
13647
|
(p) => Boolean(p) && (0, import_node_fs16.existsSync)(p)
|
|
13442
13648
|
);
|
|
13443
13649
|
const pricing = pricingPath ? loadPricing(pricingPath) : {};
|
|
13444
|
-
const built =
|
|
13650
|
+
const built = Object.fromEntries(
|
|
13651
|
+
Object.entries(buildProviders({ env, pricing })).map(([name, p]) => [name, withActivity(p)])
|
|
13652
|
+
);
|
|
13445
13653
|
const moderator = opts.moderator ?? "anthropic";
|
|
13446
13654
|
const tools = registerCoreTools({ providers: built, pricing });
|
|
13447
13655
|
const providerIds = Object.keys(built).map(vaultId).sort();
|
|
@@ -13458,7 +13666,8 @@ function createEmbeddedEngine(opts) {
|
|
|
13458
13666
|
if (!tool) return Promise.reject(new Error(`unknown tool: ${name}`));
|
|
13459
13667
|
return Promise.resolve(tool.handler(args));
|
|
13460
13668
|
};
|
|
13461
|
-
const
|
|
13669
|
+
const liveRuns = /* @__PURE__ */ new Map();
|
|
13670
|
+
const run = async (name, args, onEvent, runOpts = {}) => {
|
|
13462
13671
|
const runId = nextRunId();
|
|
13463
13672
|
const started = Date.now();
|
|
13464
13673
|
const emit = (e) => {
|
|
@@ -13467,6 +13676,78 @@ function createEmbeddedEngine(opts) {
|
|
|
13467
13676
|
} catch {
|
|
13468
13677
|
}
|
|
13469
13678
|
};
|
|
13679
|
+
const ctx = {
|
|
13680
|
+
runId,
|
|
13681
|
+
emit,
|
|
13682
|
+
nextCallId,
|
|
13683
|
+
skipped: /* @__PURE__ */ new Set(),
|
|
13684
|
+
inflight: /* @__PURE__ */ new Map(),
|
|
13685
|
+
moderator: vaultId(moderator),
|
|
13686
|
+
...runOpts.callTimeoutMs && runOpts.callTimeoutMs > 0 ? { callTimeoutMs: runOpts.callTimeoutMs } : {}
|
|
13687
|
+
};
|
|
13688
|
+
liveRuns.set(runId, ctx);
|
|
13689
|
+
try {
|
|
13690
|
+
return await runContext.run(ctx, () => withProgress(runId, (n) => {
|
|
13691
|
+
if (n.params.message) emit({ type: "progress", runId, at: Date.now(), message: n.params.message });
|
|
13692
|
+
}, () => runInner(name, args, runId, started, emit)));
|
|
13693
|
+
} finally {
|
|
13694
|
+
liveRuns.delete(runId);
|
|
13695
|
+
}
|
|
13696
|
+
};
|
|
13697
|
+
const skip = (runId, provider) => {
|
|
13698
|
+
const ctx = liveRuns.get(runId);
|
|
13699
|
+
if (!ctx) return 0;
|
|
13700
|
+
ctx.skipped.add(provider);
|
|
13701
|
+
let stopped = 0;
|
|
13702
|
+
for (const call2 of ctx.inflight.values()) {
|
|
13703
|
+
if (call2.provider === provider && !exemptFromSkip(ctx, call2.provider, call2.purpose)) {
|
|
13704
|
+
call2.controller.abort("skip");
|
|
13705
|
+
stopped += 1;
|
|
13706
|
+
}
|
|
13707
|
+
}
|
|
13708
|
+
return stopped;
|
|
13709
|
+
};
|
|
13710
|
+
const ask = async (o) => {
|
|
13711
|
+
const engineName = Object.keys(built).find((n) => vaultId(n) === o.provider);
|
|
13712
|
+
const base = engineName ? built[engineName] : void 0;
|
|
13713
|
+
if (!base) {
|
|
13714
|
+
return { ok: false, text: "", json: null, model: o.model ?? "", error: `No ${o.provider} key is configured, so it can't be asked.` };
|
|
13715
|
+
}
|
|
13716
|
+
const provider = o.model && o.model !== base.model ? retargetProvider(base, o.model) : base;
|
|
13717
|
+
const maxTokens = o.maxTokens ?? 8e3;
|
|
13718
|
+
const doAsk = async () => {
|
|
13719
|
+
if (o.schema) {
|
|
13720
|
+
const res = await requestStructured(provider, o.messages, o.schema, { maxTokens, purpose: o.purpose, maxRetries: 1 });
|
|
13721
|
+
return {
|
|
13722
|
+
ok: res.obj !== null,
|
|
13723
|
+
text: res.answer.response ?? "",
|
|
13724
|
+
json: res.obj,
|
|
13725
|
+
error: res.obj !== null ? null : res.answer.error ?? res.errors.join("; ") ?? "invalid reply",
|
|
13726
|
+
model: provider.model
|
|
13727
|
+
};
|
|
13728
|
+
}
|
|
13729
|
+
const a = await askOne(provider, o.messages, { maxTokens, temperature: 0.3, purpose: o.purpose });
|
|
13730
|
+
return { ok: !a.error, text: a.response ?? "", json: null, error: a.error ?? null, model: provider.model };
|
|
13731
|
+
};
|
|
13732
|
+
if (!o.runId || !o.onEvent) return doAsk();
|
|
13733
|
+
const sink = o.onEvent;
|
|
13734
|
+
const emit = (e) => {
|
|
13735
|
+
try {
|
|
13736
|
+
sink(e);
|
|
13737
|
+
} catch {
|
|
13738
|
+
}
|
|
13739
|
+
};
|
|
13740
|
+
const ctx = {
|
|
13741
|
+
runId: o.runId,
|
|
13742
|
+
emit,
|
|
13743
|
+
nextCallId,
|
|
13744
|
+
skipped: /* @__PURE__ */ new Set(),
|
|
13745
|
+
inflight: /* @__PURE__ */ new Map(),
|
|
13746
|
+
moderator: o.provider
|
|
13747
|
+
};
|
|
13748
|
+
return runContext.run(ctx, doAsk);
|
|
13749
|
+
};
|
|
13750
|
+
const runInner = async (name, args, runId, started, emit) => {
|
|
13470
13751
|
emit({
|
|
13471
13752
|
type: "run.start",
|
|
13472
13753
|
runId,
|
|
@@ -13544,8 +13825,16 @@ function createEmbeddedEngine(opts) {
|
|
|
13544
13825
|
providers: providerIds,
|
|
13545
13826
|
models,
|
|
13546
13827
|
listTools: () => [...tools.keys()],
|
|
13828
|
+
requiredArgs: (name) => {
|
|
13829
|
+
const tool = tools.get(name);
|
|
13830
|
+
if (!tool) return null;
|
|
13831
|
+
const req = tool.inputSchema?.required;
|
|
13832
|
+
return Array.isArray(req) ? req.filter((x) => typeof x === "string") : [];
|
|
13833
|
+
},
|
|
13547
13834
|
call,
|
|
13548
13835
|
run,
|
|
13836
|
+
skip,
|
|
13837
|
+
ask,
|
|
13549
13838
|
close: async () => {
|
|
13550
13839
|
await flush().catch(() => {
|
|
13551
13840
|
});
|
|
@@ -13555,6 +13844,7 @@ function createEmbeddedEngine(opts) {
|
|
|
13555
13844
|
var __test_internals = { usageOf, textOf, errorOf, vaultId };
|
|
13556
13845
|
// Annotate the CommonJS export names for ESM import in node:
|
|
13557
13846
|
0 && (module.exports = {
|
|
13847
|
+
ACTIVITY_TEXT_CAP,
|
|
13558
13848
|
DEFAULT_EXCLUDED_PROVIDERS,
|
|
13559
13849
|
DEFAULT_FALLBACKS,
|
|
13560
13850
|
DEFAULT_MODELS,
|