@tangle-network/agent-runtime 0.21.1 → 0.23.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/README.md +116 -1
- package/dist/agent.d.ts +1 -1
- package/dist/chunk-7HN72MF3.js +200 -0
- package/dist/chunk-7HN72MF3.js.map +1 -0
- package/dist/{chunk-Z5LKAYAS.js → chunk-CBQVID7G.js} +2 -2
- package/dist/chunk-IQHYOJU3.js +427 -0
- package/dist/chunk-IQHYOJU3.js.map +1 -0
- package/dist/{chunk-EDVCVFQB.js → chunk-TZ53F7M7.js} +4 -3
- package/dist/chunk-TZ53F7M7.js.map +1 -0
- package/dist/{chunk-QDNJLAEU.js → chunk-UNQM6XQO.js} +34 -433
- package/dist/chunk-UNQM6XQO.js.map +1 -0
- package/dist/{chunk-XLWPTPRP.js → chunk-URDSRUPQ.js} +2 -2
- package/dist/{chunk-RZAOYKCO.js → chunk-XZYF3YJN.js} +9 -1
- package/dist/{chunk-RZAOYKCO.js.map → chunk-XZYF3YJN.js.map} +1 -1
- package/dist/index.d.ts +77 -4
- package/dist/index.js +209 -41
- package/dist/index.js.map +1 -1
- package/dist/loops.d.ts +4 -4
- package/dist/loops.js +3 -3
- package/dist/mcp/bin.js +6 -5
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.d.ts +54 -4
- package/dist/mcp/index.js +60 -11
- package/dist/mcp/index.js.map +1 -1
- package/dist/otel-export-B33Cy_60.d.ts +114 -0
- package/dist/profiles.d.ts +3 -3
- package/dist/profiles.js +3 -3
- package/dist/{runtime-run-B2j-hvBj.d.ts → runtime-run-D5ItCKl_.d.ts} +1 -1
- package/dist/{types-DvJIha6w.d.ts → types-BFgFD_sl.d.ts} +87 -1
- package/dist/{types-Cu-SkGa0.d.ts → types-DmkRGTBn.d.ts} +18 -1
- package/package.json +1 -1
- package/dist/chunk-EDVCVFQB.js.map +0 -1
- package/dist/chunk-QDNJLAEU.js.map +0 -1
- /package/dist/{chunk-Z5LKAYAS.js.map → chunk-CBQVID7G.js.map} +0 -0
- /package/dist/{chunk-XLWPTPRP.js.map → chunk-URDSRUPQ.js.map} +0 -0
package/dist/loops.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { AgentProfile, CreateSandboxOptions, SandboxEvent, SandboxInstance } from '@tangle-network/sandbox';
|
|
2
|
-
import { D as DefaultVerdict, a as Driver, I as Iteration, A as AgentRunSpec, O as OutputAdapter, V as Validator, E as ExecCtx, L as LoopWinner, b as LoopResult } from './types-
|
|
3
|
-
export { c as LoopDecisionPayload, d as LoopEndedPayload, e as LoopIterationDispatchPayload, f as LoopIterationEndedPayload, g as LoopIterationStartedPayload, h as LoopSandboxClient, i as LoopSandboxPlacement, j as LoopStartedPayload, k as LoopTraceEmitter, l as LoopTraceEvent, m as ValidationCtx } from './types-
|
|
4
|
-
import './runtime-run-
|
|
5
|
-
import './types-
|
|
2
|
+
import { D as DefaultVerdict, a as Driver, I as Iteration, A as AgentRunSpec, O as OutputAdapter, V as Validator, E as ExecCtx, L as LoopWinner, b as LoopResult } from './types-DmkRGTBn.js';
|
|
3
|
+
export { c as LoopDecisionPayload, d as LoopEndedPayload, e as LoopIterationDispatchPayload, f as LoopIterationEndedPayload, g as LoopIterationStartedPayload, h as LoopSandboxClient, i as LoopSandboxPlacement, j as LoopStartedPayload, k as LoopTraceEmitter, l as LoopTraceEvent, m as ValidationCtx } from './types-DmkRGTBn.js';
|
|
4
|
+
import './runtime-run-D5ItCKl_.js';
|
|
5
|
+
import './types-BFgFD_sl.js';
|
|
6
6
|
import '@tangle-network/agent-eval';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/loops.js
CHANGED
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
createRefineDriver,
|
|
3
3
|
refineWinnerIndex,
|
|
4
4
|
runLoop
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-TZ53F7M7.js";
|
|
6
6
|
import {
|
|
7
7
|
createFanoutVoteDriver,
|
|
8
8
|
scoreFanoutVoteIterations
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-URDSRUPQ.js";
|
|
10
|
+
import "./chunk-XZYF3YJN.js";
|
|
11
11
|
import "./chunk-DGUM43GV.js";
|
|
12
12
|
export {
|
|
13
13
|
createFanoutVoteDriver,
|
package/dist/mcp/bin.js
CHANGED
|
@@ -3,13 +3,14 @@ import {
|
|
|
3
3
|
createDefaultCoderDelegate,
|
|
4
4
|
createMcpServer,
|
|
5
5
|
detectExecutor
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-IQHYOJU3.js";
|
|
7
|
+
import "../chunk-UNQM6XQO.js";
|
|
7
8
|
import {
|
|
8
9
|
runLoop
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-
|
|
10
|
+
} from "../chunk-TZ53F7M7.js";
|
|
11
|
+
import "../chunk-CBQVID7G.js";
|
|
12
|
+
import "../chunk-URDSRUPQ.js";
|
|
13
|
+
import "../chunk-XZYF3YJN.js";
|
|
13
14
|
import "../chunk-DGUM43GV.js";
|
|
14
15
|
|
|
15
16
|
// src/mcp/bin.ts
|
package/dist/mcp/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mcp/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * @experimental\n *\n * `agent-runtime-mcp` — stdio MCP server entry point.\n *\n * Spins up a server with the default coder delegate (wired against the\n * real `@tangle-network/sandbox` client) and, when the optional\n * `@tangle-network/agent-knowledge` peer is installed, a researcher\n * delegate against `multiHarnessResearcherFanout`.\n *\n * Environment variables:\n * TANGLE_API_KEY required — passed to `new Sandbox({ apiKey })`\n * SANDBOX_BASE_URL optional — sandbox-SDK base URL override\n * TANGLE_FLEET_ID optional — when set, delegations dispatch\n * INTO this fleet's shared workspace instead\n * of creating sibling sandboxes. Set by the\n * parent sandbox when launching this MCP\n * server so worker diffs land on the caller's\n * filesystem with no cross-sandbox boundary.\n * TANGLE_FLEET_EXCLUDE_MACHINES optional — comma-separated machine ids to\n * skip during fleet-mode round-robin\n * (typically the coordinator machine this\n * MCP server is running on).\n * MCP_MAX_CONCURRENT_SANDBOXES default 4 — kernel maxConcurrency cap\n * MCP_CODER_FANOUT_HARNESSES comma-separated harness ids to use for variants > 1\n * MCP_DISABLE_CODER set to `1` to omit `delegate_code`\n * MCP_DISABLE_RESEARCHER set to `1` to omit `delegate_research` even when peer is present\n */\n\nimport type { LoopSandboxClient } from '../loops'\nimport { runLoop } from '../loops'\nimport { detectExecutor } from './bin-helpers'\nimport { createDefaultCoderDelegate, type ResearcherDelegate } from './delegates'\nimport type { DelegationExecutor } from './executor'\nimport { createMcpServer } from './server'\nimport type { ResearchOutputShape } from './types'\n\nasync function main(): Promise<void> {\n const fanoutHarnesses = parseHarnesses(process.env.MCP_CODER_FANOUT_HARNESSES)\n const maxConcurrency = parseConcurrency(process.env.MCP_MAX_CONCURRENT_SANDBOXES)\n const wantCoder = !process.env.MCP_DISABLE_CODER\n const wantResearcher = !process.env.MCP_DISABLE_RESEARCHER\n const fleetId = parseFleetId(process.env.TANGLE_FLEET_ID)\n\n // Skip the sandbox client load entirely when no profile delegate needs it —\n // the feedback + status + history tools are queue-bound and require no\n // sandbox. Useful for tooling that mounts the MCP server purely for\n // self-introspection.\n const needsSandbox = wantCoder || wantResearcher\n let sandboxClient: LoopSandboxClient | undefined\n let executor: DelegationExecutor | undefined\n if (needsSandbox) {\n const apiKey = process.env.TANGLE_API_KEY\n if (!apiKey && !process.env.AGENT_RUNTIME_MCP_ALLOW_NO_KEY) {\n process.stderr.write(\n 'agent-runtime-mcp: TANGLE_API_KEY is required. Set AGENT_RUNTIME_MCP_ALLOW_NO_KEY=1 to run without it for diagnostics, or MCP_DISABLE_CODER=1 MCP_DISABLE_RESEARCHER=1 to run the queue-only subset.\\n',\n )\n process.exit(2)\n }\n // Fleet mode against a diagnostic stub is meaningless — the stub can't\n // resolve a real fleet handle. Refuse rather than silently degrading,\n // otherwise a fleet-mounted MCP would behave differently than configured.\n if (fleetId && !apiKey) {\n process.stderr.write(\n 'agent-runtime-mcp: TANGLE_FLEET_ID was set but TANGLE_API_KEY is missing; cannot resolve fleet handle. Provide an api key or unset TANGLE_FLEET_ID.\\n',\n )\n process.exit(2)\n }\n sandboxClient = await loadSandboxClient(apiKey)\n executor = await detectExecutor({ sandboxClient })\n if (fleetId) {\n process.stderr.write(`agent-runtime-mcp: fleet-aware delegation: fleetId=${fleetId}\\n`)\n }\n process.stderr.write(`agent-runtime-mcp: delegation placement → ${executor.describe()}\\n`)\n }\n\n const coderDelegate =\n wantCoder && executor\n ? createDefaultCoderDelegate({\n executor,\n fanoutHarnesses,\n maxConcurrency,\n })\n : undefined\n\n const researcherDelegate =\n wantResearcher && executor\n ? await loadResearcherDelegate(executor.client, maxConcurrency)\n : undefined\n\n const server = createMcpServer({ coderDelegate, researcherDelegate })\n\n process.on('SIGINT', () => {\n server.stop()\n process.exit(0)\n })\n process.on('SIGTERM', () => {\n server.stop()\n process.exit(0)\n })\n\n await server.serve()\n}\n\nasync function loadSandboxClient(apiKey: string | undefined): Promise<LoopSandboxClient> {\n // Diagnostic mode: AGENT_RUNTIME_MCP_ALLOW_NO_KEY=1 enables tools/list + the\n // queue-bound tools (status / history / feedback) without sandbox creds.\n // Coder + researcher delegations require a real client; the stub fails loud\n // at create() so the agent observes the cause instead of silent success.\n if (!apiKey) {\n return {\n async create() {\n throw new Error(\n 'agent-runtime-mcp: TANGLE_API_KEY is unset; coder/researcher delegations are disabled in diagnostic mode. Set TANGLE_API_KEY or use MCP_DISABLE_CODER=1 MCP_DISABLE_RESEARCHER=1 to remove the unsupported tools from the tool list.',\n )\n },\n } satisfies LoopSandboxClient\n }\n // Dynamic import keeps the bin importable in environments that haven't\n // installed `@tangle-network/sandbox` yet (the runtime package lists it\n // as a peer dep, not a hard dep).\n const mod = await import('@tangle-network/sandbox').catch((err) => {\n process.stderr.write(\n `agent-runtime-mcp: failed to load @tangle-network/sandbox (${err.message}); install the peer dependency\\n`,\n )\n process.exit(2)\n })\n const SandboxCtor = (mod as { Sandbox?: new (config: unknown) => LoopSandboxClient }).Sandbox\n if (!SandboxCtor) {\n process.stderr.write(\n 'agent-runtime-mcp: @tangle-network/sandbox does not export Sandbox; cannot construct client\\n',\n )\n process.exit(2)\n }\n const baseUrl = process.env.SANDBOX_BASE_URL\n return new SandboxCtor({\n apiKey,\n ...(baseUrl ? { baseUrl } : {}),\n })\n}\n\ninterface ResearcherProfilePreset {\n agentRunSpec: Parameters<typeof runLoop>[0]['agentRun'] extends infer T ? NonNullable<T> : never\n output: Parameters<typeof runLoop>[0]['output']\n validator: Parameters<typeof runLoop>[0]['validator']\n}\n\ninterface ResearcherFanoutPreset {\n agentRuns: NonNullable<Parameters<typeof runLoop>[0]['agentRuns']>\n output: Parameters<typeof runLoop>[0]['output']\n validator: Parameters<typeof runLoop>[0]['validator']\n driver: Parameters<typeof runLoop>[0]['driver']\n}\n\nasync function loadResearcherDelegate(\n sandboxClient: LoopSandboxClient,\n maxConcurrency: number,\n): Promise<ResearcherDelegate | undefined> {\n // Optional peer — when `@tangle-network/agent-knowledge` isn't installed,\n // we silently omit the researcher tool from the advertisement. The\n // dynamic-import path is resolved at runtime; TypeScript cannot see the\n // peer, so we type the module structurally rather than via its own\n // declaration file.\n const profilesSpecifier = '@tangle-network/agent-knowledge/profiles'\n const mod = await import(profilesSpecifier).catch(() => undefined)\n if (!mod) return undefined\n type SingleFactory = (opts: { task: unknown }) => ResearcherProfilePreset\n type FanoutFactory = (opts: { task: unknown }) => ResearcherFanoutPreset\n const fanoutFactory = (mod as { multiHarnessResearcherFanout?: FanoutFactory })\n .multiHarnessResearcherFanout\n const singleFactory = (mod as { researcherProfile?: SingleFactory }).researcherProfile\n if (!fanoutFactory || !singleFactory) return undefined\n\n return async (args, ctx) => {\n const task = {\n question: args.question,\n knowledgeNamespace: args.namespace,\n scope: args.scope,\n sources: args.sources,\n recencyWindow: args.config?.recencyWindow\n ? {\n since: args.config.recencyWindow.since\n ? new Date(args.config.recencyWindow.since)\n : undefined,\n until: args.config.recencyWindow.until\n ? new Date(args.config.recencyWindow.until)\n : undefined,\n }\n : undefined,\n maxItems: args.config?.maxItems,\n minConfidence: args.config?.minConfidence,\n }\n const variants = Math.max(1, Math.trunc(args.variants ?? 1))\n ctx.report({ iteration: 0, phase: 'starting' })\n if (variants <= 1) {\n const preset = singleFactory({ task })\n const result = await runLoop({\n driver: {\n name: 'mcp-researcher-single',\n async plan(t, history) {\n return history.length === 0 ? [t] : []\n },\n decide(history) {\n return history.length > 0 ? 'pick-winner' : 'fail'\n },\n },\n agentRun: preset.agentRunSpec,\n output: preset.output,\n validator: preset.validator,\n task,\n ctx: { sandboxClient, signal: ctx.signal },\n maxIterations: 1,\n maxConcurrency,\n })\n const output = result.winner?.output\n if (!output) throw new Error('researcher delegate produced no winner')\n ctx.report({ iteration: 1, phase: 'completed' })\n return output as ResearchOutputShape\n }\n const fanout = fanoutFactory({ task })\n const result = await runLoop({\n driver: fanout.driver,\n agentRuns: fanout.agentRuns.slice(0, variants),\n output: fanout.output,\n validator: fanout.validator,\n task,\n ctx: { sandboxClient, signal: ctx.signal },\n maxIterations: variants,\n maxConcurrency: Math.min(maxConcurrency, variants),\n })\n const output = result.winner?.output\n if (!output) throw new Error('researcher delegate fanout produced no winner')\n ctx.report({ iteration: result.iterations.length, phase: 'completed' })\n return output as ResearchOutputShape\n }\n}\n\nfunction parseHarnesses(raw: string | undefined): string[] | undefined {\n if (!raw) return undefined\n const list = raw\n .split(',')\n .map((entry) => entry.trim())\n .filter(Boolean)\n return list.length > 0 ? list : undefined\n}\n\nfunction parseFleetId(raw: string | undefined): string | undefined {\n if (typeof raw !== 'string') return undefined\n const trimmed = raw.trim()\n return trimmed.length > 0 ? trimmed : undefined\n}\n\nfunction parseConcurrency(raw: string | undefined): number {\n if (!raw) return 4\n const n = Number(raw)\n if (!Number.isFinite(n) || n < 1) return 4\n return Math.min(Math.trunc(n), 32)\n}\n\nmain().catch((err) => {\n process.stderr.write(`agent-runtime-mcp: ${err instanceof Error ? err.stack : String(err)}\\n`)\n process.exit(1)\n})\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,eAAe,OAAsB;AACnC,QAAM,kBAAkB,eAAe,QAAQ,IAAI,0BAA0B;AAC7E,QAAM,iBAAiB,iBAAiB,QAAQ,IAAI,4BAA4B;AAChF,QAAM,YAAY,CAAC,QAAQ,IAAI;AAC/B,QAAM,iBAAiB,CAAC,QAAQ,IAAI;AACpC,QAAM,UAAU,aAAa,QAAQ,IAAI,eAAe;AAMxD,QAAM,eAAe,aAAa;AAClC,MAAI;AACJ,MAAI;AACJ,MAAI,cAAc;AAChB,UAAM,SAAS,QAAQ,IAAI;AAC3B,QAAI,CAAC,UAAU,CAAC,QAAQ,IAAI,gCAAgC;AAC1D,cAAQ,OAAO;AAAA,QACb;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAIA,QAAI,WAAW,CAAC,QAAQ;AACtB,cAAQ,OAAO;AAAA,QACb;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,oBAAgB,MAAM,kBAAkB,MAAM;AAC9C,eAAW,MAAM,eAAe,EAAE,cAAc,CAAC;AACjD,QAAI,SAAS;AACX,cAAQ,OAAO,MAAM,sDAAsD,OAAO;AAAA,CAAI;AAAA,IACxF;AACA,YAAQ,OAAO,MAAM,kDAA6C,SAAS,SAAS,CAAC;AAAA,CAAI;AAAA,EAC3F;AAEA,QAAM,gBACJ,aAAa,WACT,2BAA2B;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC,IACD;AAEN,QAAM,qBACJ,kBAAkB,WACd,MAAM,uBAAuB,SAAS,QAAQ,cAAc,IAC5D;AAEN,QAAM,SAAS,gBAAgB,EAA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AAA,MAC7C,QAAQ,OAAO;AAAA,MACf,WAAW,OAAO;AAAA,MAClB;AAAA,MACA,KAAK,EAAE,eAAe,QAAQ,IAAI,OAAO;AAAA,MACzC,eAAe;AAAA,MACf,gBAAgB,KAAK,IAAI,gBAAgB,QAAQ;AAAA,IACnD,CAAC;AACD,UAAM,SAAS,OAAO,QAAQ;AAC9B,QAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,+CAA+C;AAC5E,QAAI,OAAO,EAAE,WAAW,OAAO,WAAW,QAAQ,OAAO,YAAY,CAAC;AACtE,WAAO;AAAA,EACT;AACF;AAEA,SAAS,eAAe,KAA+C;AACrE,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,OAAO,IACV,MAAM,GAAG,EACT,IAAI,CAAC,UAAU,MAAM,KAAK,CAAC,EAC3B,OAAO,OAAO;AACjB,SAAO,KAAK,SAAS,IAAI,OAAO;AAClC;AAEA,SAAS,aAAa,KAA6C;AACjE,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,QAAM,UAAU,IAAI,KAAK;AACzB,SAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEA,SAAS,iBAAiB,KAAiC;AACzD,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,IAAI,OAAO,GAAG;AACpB,MAAI,CAAC,OAAO,SAAS,CAAC,KAAK,IAAI,EAAG,QAAO;AACzC,SAAO,KAAK,IAAI,KAAK,MAAM,CAAC,GAAG,EAAE;AACnC;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,OAAO,MAAM,sBAAsB,eAAe,QAAQ,IAAI,QAAQ,OAAO,GAAG,CAAC;AAAA,CAAI;AAC7F,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["result","output"]}
|
|
1
|
+
{"version":3,"sources":["../../src/mcp/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * @experimental\n *\n * `agent-runtime-mcp` — stdio MCP server entry point.\n *\n * Spins up a server with the default coder delegate (wired against the\n * real `@tangle-network/sandbox` client) and, when the optional\n * `@tangle-network/agent-knowledge` peer is installed, a researcher\n * delegate against `multiHarnessResearcherFanout`.\n *\n * Environment variables:\n * TANGLE_API_KEY required — passed to `new Sandbox({ apiKey })`\n * SANDBOX_BASE_URL optional — sandbox-SDK base URL override\n * TANGLE_FLEET_ID optional — when set, delegations dispatch\n * INTO this fleet's shared workspace instead\n * of creating sibling sandboxes. Set by the\n * parent sandbox when launching this MCP\n * server so worker diffs land on the caller's\n * filesystem with no cross-sandbox boundary.\n * TANGLE_FLEET_EXCLUDE_MACHINES optional — comma-separated machine ids to\n * skip during fleet-mode round-robin\n * (typically the coordinator machine this\n * MCP server is running on).\n * MCP_MAX_CONCURRENT_SANDBOXES default 4 — kernel maxConcurrency cap\n * MCP_CODER_FANOUT_HARNESSES comma-separated harness ids to use for variants > 1\n * MCP_DISABLE_CODER set to `1` to omit `delegate_code`\n * MCP_DISABLE_RESEARCHER set to `1` to omit `delegate_research` even when peer is present\n */\n\nimport type { LoopSandboxClient } from '../loops'\nimport { runLoop } from '../loops'\nimport { detectExecutor } from './bin-helpers'\nimport { createDefaultCoderDelegate, type ResearcherDelegate } from './delegates'\nimport type { DelegationExecutor } from './executor'\nimport { createMcpServer } from './server'\nimport type { ResearchOutputShape } from './types'\n\nasync function main(): Promise<void> {\n const fanoutHarnesses = parseHarnesses(process.env.MCP_CODER_FANOUT_HARNESSES)\n const maxConcurrency = parseConcurrency(process.env.MCP_MAX_CONCURRENT_SANDBOXES)\n const wantCoder = !process.env.MCP_DISABLE_CODER\n const wantResearcher = !process.env.MCP_DISABLE_RESEARCHER\n const fleetId = parseFleetId(process.env.TANGLE_FLEET_ID)\n\n // Skip the sandbox client load entirely when no profile delegate needs it —\n // the feedback + status + history tools are queue-bound and require no\n // sandbox. Useful for tooling that mounts the MCP server purely for\n // self-introspection.\n const needsSandbox = wantCoder || wantResearcher\n let sandboxClient: LoopSandboxClient | undefined\n let executor: DelegationExecutor | undefined\n if (needsSandbox) {\n const apiKey = process.env.TANGLE_API_KEY\n if (!apiKey && !process.env.AGENT_RUNTIME_MCP_ALLOW_NO_KEY) {\n process.stderr.write(\n 'agent-runtime-mcp: TANGLE_API_KEY is required. Set AGENT_RUNTIME_MCP_ALLOW_NO_KEY=1 to run without it for diagnostics, or MCP_DISABLE_CODER=1 MCP_DISABLE_RESEARCHER=1 to run the queue-only subset.\\n',\n )\n process.exit(2)\n }\n // Fleet mode against a diagnostic stub is meaningless — the stub can't\n // resolve a real fleet handle. Refuse rather than silently degrading,\n // otherwise a fleet-mounted MCP would behave differently than configured.\n if (fleetId && !apiKey) {\n process.stderr.write(\n 'agent-runtime-mcp: TANGLE_FLEET_ID was set but TANGLE_API_KEY is missing; cannot resolve fleet handle. Provide an api key or unset TANGLE_FLEET_ID.\\n',\n )\n process.exit(2)\n }\n sandboxClient = await loadSandboxClient(apiKey)\n executor = await detectExecutor({ sandboxClient })\n if (fleetId) {\n process.stderr.write(`agent-runtime-mcp: fleet-aware delegation: fleetId=${fleetId}\\n`)\n }\n process.stderr.write(`agent-runtime-mcp: delegation placement → ${executor.describe()}\\n`)\n }\n\n const coderDelegate =\n wantCoder && executor\n ? createDefaultCoderDelegate({\n executor,\n fanoutHarnesses,\n maxConcurrency,\n })\n : undefined\n\n const researcherDelegate =\n wantResearcher && executor\n ? await loadResearcherDelegate(executor.client, maxConcurrency)\n : undefined\n\n const server = createMcpServer({ coderDelegate, researcherDelegate })\n\n process.on('SIGINT', () => {\n server.stop()\n process.exit(0)\n })\n process.on('SIGTERM', () => {\n server.stop()\n process.exit(0)\n })\n\n await server.serve()\n}\n\nasync function loadSandboxClient(apiKey: string | undefined): Promise<LoopSandboxClient> {\n // Diagnostic mode: AGENT_RUNTIME_MCP_ALLOW_NO_KEY=1 enables tools/list + the\n // queue-bound tools (status / history / feedback) without sandbox creds.\n // Coder + researcher delegations require a real client; the stub fails loud\n // at create() so the agent observes the cause instead of silent success.\n if (!apiKey) {\n return {\n async create() {\n throw new Error(\n 'agent-runtime-mcp: TANGLE_API_KEY is unset; coder/researcher delegations are disabled in diagnostic mode. Set TANGLE_API_KEY or use MCP_DISABLE_CODER=1 MCP_DISABLE_RESEARCHER=1 to remove the unsupported tools from the tool list.',\n )\n },\n } satisfies LoopSandboxClient\n }\n // Dynamic import keeps the bin importable in environments that haven't\n // installed `@tangle-network/sandbox` yet (the runtime package lists it\n // as a peer dep, not a hard dep).\n const mod = await import('@tangle-network/sandbox').catch((err) => {\n process.stderr.write(\n `agent-runtime-mcp: failed to load @tangle-network/sandbox (${err.message}); install the peer dependency\\n`,\n )\n process.exit(2)\n })\n const SandboxCtor = (mod as { Sandbox?: new (config: unknown) => LoopSandboxClient }).Sandbox\n if (!SandboxCtor) {\n process.stderr.write(\n 'agent-runtime-mcp: @tangle-network/sandbox does not export Sandbox; cannot construct client\\n',\n )\n process.exit(2)\n }\n const baseUrl = process.env.SANDBOX_BASE_URL\n return new SandboxCtor({\n apiKey,\n ...(baseUrl ? { baseUrl } : {}),\n })\n}\n\ninterface ResearcherProfilePreset {\n agentRunSpec: Parameters<typeof runLoop>[0]['agentRun'] extends infer T ? NonNullable<T> : never\n output: Parameters<typeof runLoop>[0]['output']\n validator: Parameters<typeof runLoop>[0]['validator']\n}\n\ninterface ResearcherFanoutPreset {\n agentRuns: NonNullable<Parameters<typeof runLoop>[0]['agentRuns']>\n output: Parameters<typeof runLoop>[0]['output']\n validator: Parameters<typeof runLoop>[0]['validator']\n driver: Parameters<typeof runLoop>[0]['driver']\n}\n\nasync function loadResearcherDelegate(\n sandboxClient: LoopSandboxClient,\n maxConcurrency: number,\n): Promise<ResearcherDelegate | undefined> {\n // Optional peer — when `@tangle-network/agent-knowledge` isn't installed,\n // we silently omit the researcher tool from the advertisement. The\n // dynamic-import path is resolved at runtime; TypeScript cannot see the\n // peer, so we type the module structurally rather than via its own\n // declaration file.\n const profilesSpecifier = '@tangle-network/agent-knowledge/profiles'\n const mod = await import(profilesSpecifier).catch(() => undefined)\n if (!mod) return undefined\n type SingleFactory = (opts: { task: unknown }) => ResearcherProfilePreset\n type FanoutFactory = (opts: { task: unknown }) => ResearcherFanoutPreset\n const fanoutFactory = (mod as { multiHarnessResearcherFanout?: FanoutFactory })\n .multiHarnessResearcherFanout\n const singleFactory = (mod as { researcherProfile?: SingleFactory }).researcherProfile\n if (!fanoutFactory || !singleFactory) return undefined\n\n return async (args, ctx) => {\n const task = {\n question: args.question,\n knowledgeNamespace: args.namespace,\n scope: args.scope,\n sources: args.sources,\n recencyWindow: args.config?.recencyWindow\n ? {\n since: args.config.recencyWindow.since\n ? new Date(args.config.recencyWindow.since)\n : undefined,\n until: args.config.recencyWindow.until\n ? new Date(args.config.recencyWindow.until)\n : undefined,\n }\n : undefined,\n maxItems: args.config?.maxItems,\n minConfidence: args.config?.minConfidence,\n }\n const variants = Math.max(1, Math.trunc(args.variants ?? 1))\n ctx.report({ iteration: 0, phase: 'starting' })\n if (variants <= 1) {\n const preset = singleFactory({ task })\n const result = await runLoop({\n driver: {\n name: 'mcp-researcher-single',\n async plan(t, history) {\n return history.length === 0 ? [t] : []\n },\n decide(history) {\n return history.length > 0 ? 'pick-winner' : 'fail'\n },\n },\n agentRun: preset.agentRunSpec,\n output: preset.output,\n validator: preset.validator,\n task,\n ctx: { sandboxClient, signal: ctx.signal },\n maxIterations: 1,\n maxConcurrency,\n })\n const output = result.winner?.output\n if (!output) throw new Error('researcher delegate produced no winner')\n ctx.report({ iteration: 1, phase: 'completed' })\n return output as ResearchOutputShape\n }\n const fanout = fanoutFactory({ task })\n const result = await runLoop({\n driver: fanout.driver,\n agentRuns: fanout.agentRuns.slice(0, variants),\n output: fanout.output,\n validator: fanout.validator,\n task,\n ctx: { sandboxClient, signal: ctx.signal },\n maxIterations: variants,\n maxConcurrency: Math.min(maxConcurrency, variants),\n })\n const output = result.winner?.output\n if (!output) throw new Error('researcher delegate fanout produced no winner')\n ctx.report({ iteration: result.iterations.length, phase: 'completed' })\n return output as ResearchOutputShape\n }\n}\n\nfunction parseHarnesses(raw: string | undefined): string[] | undefined {\n if (!raw) return undefined\n const list = raw\n .split(',')\n .map((entry) => entry.trim())\n .filter(Boolean)\n return list.length > 0 ? list : undefined\n}\n\nfunction parseFleetId(raw: string | undefined): string | undefined {\n if (typeof raw !== 'string') return undefined\n const trimmed = raw.trim()\n return trimmed.length > 0 ? trimmed : undefined\n}\n\nfunction parseConcurrency(raw: string | undefined): number {\n if (!raw) return 4\n const n = Number(raw)\n if (!Number.isFinite(n) || n < 1) return 4\n return Math.min(Math.trunc(n), 32)\n}\n\nmain().catch((err) => {\n process.stderr.write(`agent-runtime-mcp: ${err instanceof Error ? err.stack : String(err)}\\n`)\n process.exit(1)\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,eAAe,OAAsB;AACnC,QAAM,kBAAkB,eAAe,QAAQ,IAAI,0BAA0B;AAC7E,QAAM,iBAAiB,iBAAiB,QAAQ,IAAI,4BAA4B;AAChF,QAAM,YAAY,CAAC,QAAQ,IAAI;AAC/B,QAAM,iBAAiB,CAAC,QAAQ,IAAI;AACpC,QAAM,UAAU,aAAa,QAAQ,IAAI,eAAe;AAMxD,QAAM,eAAe,aAAa;AAClC,MAAI;AACJ,MAAI;AACJ,MAAI,cAAc;AAChB,UAAM,SAAS,QAAQ,IAAI;AAC3B,QAAI,CAAC,UAAU,CAAC,QAAQ,IAAI,gCAAgC;AAC1D,cAAQ,OAAO;AAAA,QACb;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAIA,QAAI,WAAW,CAAC,QAAQ;AACtB,cAAQ,OAAO;AAAA,QACb;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,oBAAgB,MAAM,kBAAkB,MAAM;AAC9C,eAAW,MAAM,eAAe,EAAE,cAAc,CAAC;AACjD,QAAI,SAAS;AACX,cAAQ,OAAO,MAAM,sDAAsD,OAAO;AAAA,CAAI;AAAA,IACxF;AACA,YAAQ,OAAO,MAAM,kDAA6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,IAAI,QAAQ,OAAO,GAAG,CAAC;AAAA,CAAI;AAC7F,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["result","output"]}
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { h as LoopSandboxClient } from '../types-
|
|
1
|
+
import { h as LoopSandboxClient, k as LoopTraceEmitter } from '../types-DmkRGTBn.js';
|
|
2
2
|
import { SandboxInstance } from '@tangle-network/sandbox';
|
|
3
3
|
import { CoderOutput } from '../profiles.js';
|
|
4
|
-
import '../
|
|
5
|
-
|
|
4
|
+
import { b as OtelExporter } from '../otel-export-B33Cy_60.js';
|
|
5
|
+
export { m as mcpToolsForRuntimeMcp, e as mcpToolsForRuntimeMcpSubset } from '../otel-export-B33Cy_60.js';
|
|
6
|
+
import '../runtime-run-D5ItCKl_.js';
|
|
7
|
+
import '../types-BFgFD_sl.js';
|
|
6
8
|
import '@tangle-network/agent-eval';
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -956,4 +958,52 @@ interface DelegationStatusHandlerOptions {
|
|
|
956
958
|
/** @experimental */
|
|
957
959
|
declare function createDelegationStatusHandler(options: DelegationStatusHandlerOptions): (raw: unknown) => Promise<DelegationStatusResult>;
|
|
958
960
|
|
|
959
|
-
|
|
961
|
+
/**
|
|
962
|
+
* @experimental
|
|
963
|
+
*
|
|
964
|
+
* Trace context propagation for MCP subprocess.
|
|
965
|
+
*
|
|
966
|
+
* When the MCP server is launched as a child process by a sandbox harness,
|
|
967
|
+
* the parent passes trace context via environment variables:
|
|
968
|
+
*
|
|
969
|
+
* TRACE_ID=<current-run-trace-id>
|
|
970
|
+
* PARENT_SPAN_ID=<span-that-dispatched-the-delegation>
|
|
971
|
+
*
|
|
972
|
+
* The MCP server reads these at startup and uses them as the root of its
|
|
973
|
+
* internal trace tree. All spans emitted by `runLoop` invocations inside
|
|
974
|
+
* the MCP are children of the parent's delegation span.
|
|
975
|
+
*
|
|
976
|
+
* When these env vars are absent, the MCP generates a fresh trace root —
|
|
977
|
+
* the server operates standalone without trace joining.
|
|
978
|
+
*/
|
|
979
|
+
|
|
980
|
+
interface TraceContext {
|
|
981
|
+
/** Trace id inherited from the parent process, or a fresh one. */
|
|
982
|
+
traceId: string;
|
|
983
|
+
/** Parent span id from the delegation that launched this MCP server. */
|
|
984
|
+
parentSpanId?: string;
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Read trace context from the process environment.
|
|
988
|
+
* Returns a context with inherited ids or a freshly generated root.
|
|
989
|
+
*/
|
|
990
|
+
declare function readTraceContextFromEnv(): TraceContext;
|
|
991
|
+
/**
|
|
992
|
+
* Create a LoopTraceEmitter that:
|
|
993
|
+
* 1. Parents all spans under the inherited PARENT_SPAN_ID.
|
|
994
|
+
* 2. Exports spans to OTEL when OTEL_EXPORTER_OTLP_ENDPOINT is set.
|
|
995
|
+
*
|
|
996
|
+
* Returns both the emitter and the optional exporter handle for shutdown.
|
|
997
|
+
*/
|
|
998
|
+
declare function createPropagatingTraceEmitter(ctx: TraceContext): {
|
|
999
|
+
emitter: LoopTraceEmitter;
|
|
1000
|
+
exporter: OtelExporter | undefined;
|
|
1001
|
+
context: TraceContext;
|
|
1002
|
+
};
|
|
1003
|
+
/**
|
|
1004
|
+
* Build env vars to pass to a child MCP subprocess so it inherits the
|
|
1005
|
+
* current trace context.
|
|
1006
|
+
*/
|
|
1007
|
+
declare function traceContextToEnv(ctx: TraceContext): Record<string, string>;
|
|
1008
|
+
|
|
1009
|
+
export { type CoderDelegate, type CreateDefaultCoderDelegateOptions, DELEGATE_CODE_DESCRIPTION, DELEGATE_CODE_INPUT_SCHEMA, DELEGATE_CODE_TOOL_NAME, DELEGATE_FEEDBACK_DESCRIPTION, DELEGATE_FEEDBACK_INPUT_SCHEMA, DELEGATE_FEEDBACK_TOOL_NAME, DELEGATE_RESEARCH_DESCRIPTION, DELEGATE_RESEARCH_INPUT_SCHEMA, DELEGATE_RESEARCH_TOOL_NAME, DELEGATION_HISTORY_DESCRIPTION, DELEGATION_HISTORY_INPUT_SCHEMA, DELEGATION_HISTORY_TOOL_NAME, DELEGATION_STATUS_DESCRIPTION, DELEGATION_STATUS_INPUT_SCHEMA, DELEGATION_STATUS_TOOL_NAME, type DelegateCodeArgs, type DelegateCodeConfig, type DelegateCodeResult, type DelegateFeedbackArgs, type DelegateFeedbackResult, type DelegateResearchArgs, type DelegateResearchConfig, type DelegateResearchResult, type DelegateRunCtx, type DelegationError, type DelegationExecutor, type DelegationFeedbackSnapshot, type DelegationHistoryArgs, type DelegationHistoryEntry, type DelegationHistoryResult, type DelegationProfile, type DelegationProgress, type DelegationRecord, type DelegationResultPayload, type DelegationStatus, type DelegationStatusArgs, type DelegationStatusResult, DelegationTaskQueue, type DelegationTaskQueueOptions, type DetectExecutorArgs, type FeedbackEvent, type FeedbackRating, type FeedbackRefersTo, type FeedbackStore, type FleetHandle, type FleetWorkspaceExecutorOptions, InMemoryFeedbackStore, type JsonRpcMessage, type JsonRpcResponse, type McpServer, type McpServerOptions, type McpToolDescriptor, type McpTransport, type ResearchOutputShape, type ResearchSource, type ResearcherDelegate, type SiblingSandboxExecutorOptions, type SubmitInput, type SubmitOutput, type TraceContext, createDefaultCoderDelegate, createDelegateCodeHandler, createDelegateFeedbackHandler, createDelegateResearchHandler, createDelegationHistoryHandler, createDelegationStatusHandler, createFleetWorkspaceExecutor, createInProcessTransport, createMcpServer, createPropagatingTraceEmitter, createSiblingSandboxExecutor, detectExecutor, eventToSnapshot, hashIdempotencyInput, readTraceContextFromEnv, traceContextToEnv, validateDelegateCodeArgs, validateDelegateFeedbackArgs, validateDelegateResearchArgs, validateDelegationHistoryArgs, validateDelegationStatusArgs };
|
package/dist/mcp/index.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createOtelExporter,
|
|
3
|
+
loopEventToOtelSpan,
|
|
4
|
+
mcpToolsForRuntimeMcp,
|
|
5
|
+
mcpToolsForRuntimeMcpSubset
|
|
6
|
+
} from "../chunk-7HN72MF3.js";
|
|
7
|
+
import {
|
|
8
|
+
createDefaultCoderDelegate,
|
|
9
|
+
createFleetWorkspaceExecutor,
|
|
10
|
+
createInProcessTransport,
|
|
11
|
+
createMcpServer,
|
|
12
|
+
createSiblingSandboxExecutor,
|
|
13
|
+
detectExecutor
|
|
14
|
+
} from "../chunk-IQHYOJU3.js";
|
|
1
15
|
import {
|
|
2
16
|
DELEGATE_CODE_DESCRIPTION,
|
|
3
17
|
DELEGATE_CODE_INPUT_SCHEMA,
|
|
@@ -16,17 +30,11 @@ import {
|
|
|
16
30
|
DELEGATION_STATUS_TOOL_NAME,
|
|
17
31
|
DelegationTaskQueue,
|
|
18
32
|
InMemoryFeedbackStore,
|
|
19
|
-
createDefaultCoderDelegate,
|
|
20
33
|
createDelegateCodeHandler,
|
|
21
34
|
createDelegateFeedbackHandler,
|
|
22
35
|
createDelegateResearchHandler,
|
|
23
36
|
createDelegationHistoryHandler,
|
|
24
37
|
createDelegationStatusHandler,
|
|
25
|
-
createFleetWorkspaceExecutor,
|
|
26
|
-
createInProcessTransport,
|
|
27
|
-
createMcpServer,
|
|
28
|
-
createSiblingSandboxExecutor,
|
|
29
|
-
detectExecutor,
|
|
30
38
|
eventToSnapshot,
|
|
31
39
|
hashIdempotencyInput,
|
|
32
40
|
validateDelegateCodeArgs,
|
|
@@ -34,12 +42,48 @@ import {
|
|
|
34
42
|
validateDelegateResearchArgs,
|
|
35
43
|
validateDelegationHistoryArgs,
|
|
36
44
|
validateDelegationStatusArgs
|
|
37
|
-
} from "../chunk-
|
|
38
|
-
import "../chunk-
|
|
39
|
-
import "../chunk-
|
|
40
|
-
import "../chunk-
|
|
41
|
-
import "../chunk-
|
|
45
|
+
} from "../chunk-UNQM6XQO.js";
|
|
46
|
+
import "../chunk-TZ53F7M7.js";
|
|
47
|
+
import "../chunk-CBQVID7G.js";
|
|
48
|
+
import "../chunk-URDSRUPQ.js";
|
|
49
|
+
import "../chunk-XZYF3YJN.js";
|
|
42
50
|
import "../chunk-DGUM43GV.js";
|
|
51
|
+
|
|
52
|
+
// src/mcp/trace-propagation.ts
|
|
53
|
+
function readTraceContextFromEnv() {
|
|
54
|
+
const traceId = process.env.TRACE_ID || generateTraceId();
|
|
55
|
+
const parentSpanId = process.env.PARENT_SPAN_ID || void 0;
|
|
56
|
+
return { traceId, parentSpanId };
|
|
57
|
+
}
|
|
58
|
+
function createPropagatingTraceEmitter(ctx) {
|
|
59
|
+
const exporter = createOtelExporter();
|
|
60
|
+
const emitter = {
|
|
61
|
+
emit(event) {
|
|
62
|
+
if (!exporter) return;
|
|
63
|
+
const span = loopEventToOtelSpan(
|
|
64
|
+
event,
|
|
65
|
+
ctx.traceId,
|
|
66
|
+
ctx.parentSpanId
|
|
67
|
+
);
|
|
68
|
+
exporter.exportSpan(span);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return { emitter, exporter, context: ctx };
|
|
72
|
+
}
|
|
73
|
+
function traceContextToEnv(ctx) {
|
|
74
|
+
const env = { TRACE_ID: ctx.traceId };
|
|
75
|
+
if (ctx.parentSpanId) env.PARENT_SPAN_ID = ctx.parentSpanId;
|
|
76
|
+
return env;
|
|
77
|
+
}
|
|
78
|
+
function generateTraceId() {
|
|
79
|
+
const bytes = new Uint8Array(16);
|
|
80
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") {
|
|
81
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
82
|
+
} else {
|
|
83
|
+
for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
84
|
+
}
|
|
85
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
86
|
+
}
|
|
43
87
|
export {
|
|
44
88
|
DELEGATE_CODE_DESCRIPTION,
|
|
45
89
|
DELEGATE_CODE_INPUT_SCHEMA,
|
|
@@ -67,10 +111,15 @@ export {
|
|
|
67
111
|
createFleetWorkspaceExecutor,
|
|
68
112
|
createInProcessTransport,
|
|
69
113
|
createMcpServer,
|
|
114
|
+
createPropagatingTraceEmitter,
|
|
70
115
|
createSiblingSandboxExecutor,
|
|
71
116
|
detectExecutor,
|
|
72
117
|
eventToSnapshot,
|
|
73
118
|
hashIdempotencyInput,
|
|
119
|
+
mcpToolsForRuntimeMcp,
|
|
120
|
+
mcpToolsForRuntimeMcpSubset,
|
|
121
|
+
readTraceContextFromEnv,
|
|
122
|
+
traceContextToEnv,
|
|
74
123
|
validateDelegateCodeArgs,
|
|
75
124
|
validateDelegateFeedbackArgs,
|
|
76
125
|
validateDelegateResearchArgs,
|
package/dist/mcp/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/mcp/trace-propagation.ts"],"sourcesContent":["/**\n * @experimental\n *\n * Trace context propagation for MCP subprocess.\n *\n * When the MCP server is launched as a child process by a sandbox harness,\n * the parent passes trace context via environment variables:\n *\n * TRACE_ID=<current-run-trace-id>\n * PARENT_SPAN_ID=<span-that-dispatched-the-delegation>\n *\n * The MCP server reads these at startup and uses them as the root of its\n * internal trace tree. All spans emitted by `runLoop` invocations inside\n * the MCP are children of the parent's delegation span.\n *\n * When these env vars are absent, the MCP generates a fresh trace root —\n * the server operates standalone without trace joining.\n */\n\nimport type { LoopTraceEmitter, LoopTraceEvent } from '../loops/types'\nimport type { OtelExporter } from '../otel-export'\nimport { loopEventToOtelSpan, createOtelExporter } from '../otel-export'\n\nexport interface TraceContext {\n /** Trace id inherited from the parent process, or a fresh one. */\n traceId: string\n /** Parent span id from the delegation that launched this MCP server. */\n parentSpanId?: string\n}\n\n/**\n * Read trace context from the process environment.\n * Returns a context with inherited ids or a freshly generated root.\n */\nexport function readTraceContextFromEnv(): TraceContext {\n const traceId = process.env.TRACE_ID || generateTraceId()\n const parentSpanId = process.env.PARENT_SPAN_ID || undefined\n return { traceId, parentSpanId }\n}\n\n/**\n * Create a LoopTraceEmitter that:\n * 1. Parents all spans under the inherited PARENT_SPAN_ID.\n * 2. Exports spans to OTEL when OTEL_EXPORTER_OTLP_ENDPOINT is set.\n *\n * Returns both the emitter and the optional exporter handle for shutdown.\n */\nexport function createPropagatingTraceEmitter(ctx: TraceContext): {\n emitter: LoopTraceEmitter\n exporter: OtelExporter | undefined\n context: TraceContext\n} {\n const exporter = createOtelExporter()\n\n const emitter: LoopTraceEmitter = {\n emit(event: LoopTraceEvent) {\n if (!exporter) return\n const span = loopEventToOtelSpan(\n event,\n ctx.traceId,\n ctx.parentSpanId,\n )\n exporter.exportSpan(span)\n },\n }\n\n return { emitter, exporter, context: ctx }\n}\n\n/**\n * Build env vars to pass to a child MCP subprocess so it inherits the\n * current trace context.\n */\nexport function traceContextToEnv(ctx: TraceContext): Record<string, string> {\n const env: Record<string, string> = { TRACE_ID: ctx.traceId }\n if (ctx.parentSpanId) env.PARENT_SPAN_ID = ctx.parentSpanId\n return env\n}\n\nfunction generateTraceId(): string {\n const bytes = new Uint8Array(16)\n if (typeof globalThis.crypto?.getRandomValues === 'function') {\n globalThis.crypto.getRandomValues(bytes)\n } else {\n for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256)\n }\n return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCO,SAAS,0BAAwC;AACtD,QAAM,UAAU,QAAQ,IAAI,YAAY,gBAAgB;AACxD,QAAM,eAAe,QAAQ,IAAI,kBAAkB;AACnD,SAAO,EAAE,SAAS,aAAa;AACjC;AASO,SAAS,8BAA8B,KAI5C;AACA,QAAM,WAAW,mBAAmB;AAEpC,QAAM,UAA4B;AAAA,IAChC,KAAK,OAAuB;AAC1B,UAAI,CAAC,SAAU;AACf,YAAM,OAAO;AAAA,QACX;AAAA,QACA,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AACA,eAAS,WAAW,IAAI;AAAA,IAC1B;AAAA,EACF;AAEA,SAAO,EAAE,SAAS,UAAU,SAAS,IAAI;AAC3C;AAMO,SAAS,kBAAkB,KAA2C;AAC3E,QAAM,MAA8B,EAAE,UAAU,IAAI,QAAQ;AAC5D,MAAI,IAAI,aAAc,KAAI,iBAAiB,IAAI;AAC/C,SAAO;AACT;AAEA,SAAS,kBAA0B;AACjC,QAAM,QAAQ,IAAI,WAAW,EAAE;AAC/B,MAAI,OAAO,WAAW,QAAQ,oBAAoB,YAAY;AAC5D,eAAW,OAAO,gBAAgB,KAAK;AAAA,EACzC,OAAO;AACL,aAAS,IAAI,GAAG,IAAI,IAAI,IAAK,OAAM,CAAC,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;AAAA,EACxE;AACA,SAAO,MAAM,KAAK,KAAK,EAAE,IAAI,OAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAC5E;","names":[]}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { O as OpenAIChatTool } from './types-BFgFD_sl.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @experimental
|
|
5
|
+
*
|
|
6
|
+
* OpenAI Chat Completions `tools[]` projection of the 5 agent-runtime MCP
|
|
7
|
+
* delegation tools.
|
|
8
|
+
*
|
|
9
|
+
* Use when configuring `createOpenAICompatibleBackend({ tools: ... })` so the
|
|
10
|
+
* model can call `delegate_code`, `delegate_research`, `delegate_feedback`,
|
|
11
|
+
* `delegation_status`, and `delegation_history` through the OpenAI-compat
|
|
12
|
+
* transport (tcloud, OpenRouter, OpenAI direct, cli-bridge). The runtime
|
|
13
|
+
* surfaces tool calls as `tool_call` stream events — execution is the
|
|
14
|
+
* caller's responsibility (typically the parent sandbox runtime's MCP
|
|
15
|
+
* mount).
|
|
16
|
+
*
|
|
17
|
+
* Sandbox-SDK callers do NOT need this helper: the sandbox runtime mounts
|
|
18
|
+
* MCP servers natively and the in-sandbox harness discovers tools via the
|
|
19
|
+
* runtime, not via an OpenAI tools array.
|
|
20
|
+
*
|
|
21
|
+
* Tool name + description + JSON-schema are pulled from the canonical
|
|
22
|
+
* `DELEGATE_*` constants exported by `./tools/*` so the projection cannot
|
|
23
|
+
* drift from the server's own validators.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @experimental
|
|
28
|
+
*
|
|
29
|
+
* Returns the 5 delegation tools projected into OpenAI Chat Completions
|
|
30
|
+
* `tools[]` shape. The order is stable: `delegate_code`,
|
|
31
|
+
* `delegate_research`, `delegate_feedback`, `delegation_status`,
|
|
32
|
+
* `delegation_history`.
|
|
33
|
+
*/
|
|
34
|
+
declare function mcpToolsForRuntimeMcp(): OpenAIChatTool[];
|
|
35
|
+
/**
|
|
36
|
+
* @experimental
|
|
37
|
+
*
|
|
38
|
+
* Subset filter — return only the projected tools whose `function.name`
|
|
39
|
+
* appears in `names`. Useful for curated mounts (e.g. only the queue-bound
|
|
40
|
+
* delegation tools, omitting `delegate_feedback`). Unknown names are
|
|
41
|
+
* silently ignored; pass an empty array to get an empty result.
|
|
42
|
+
*/
|
|
43
|
+
declare function mcpToolsForRuntimeMcpSubset(names: ReadonlyArray<string>): OpenAIChatTool[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* OTEL span exporter — streams LoopTraceEvents to an OTLP/HTTP collector.
|
|
47
|
+
*
|
|
48
|
+
* Reads OTEL_EXPORTER_OTLP_ENDPOINT + OTEL_EXPORTER_OTLP_HEADERS from env
|
|
49
|
+
* when no explicit config is given. Keeps the runtime dep-free from
|
|
50
|
+
* @opentelemetry/sdk-trace-base — minimal OTLP/JSON serializer.
|
|
51
|
+
*
|
|
52
|
+
* The exporter accepts both raw OtelSpan objects and LoopTraceEvents
|
|
53
|
+
* (which get converted to OTLP spans automatically).
|
|
54
|
+
*/
|
|
55
|
+
interface OtelExportConfig {
|
|
56
|
+
/** OTLP endpoint. Reads OTEL_EXPORTER_OTLP_ENDPOINT env by default. */
|
|
57
|
+
endpoint?: string;
|
|
58
|
+
/** OTLP headers. Reads OTEL_EXPORTER_OTLP_HEADERS env by default. */
|
|
59
|
+
headers?: Record<string, string>;
|
|
60
|
+
/** Batch size before flush. Default 64. */
|
|
61
|
+
batchSize?: number;
|
|
62
|
+
/** Flush interval ms. Default 5000. */
|
|
63
|
+
flushIntervalMs?: number;
|
|
64
|
+
/** Resource attributes stamped on every export. */
|
|
65
|
+
resourceAttributes?: Record<string, string | number | boolean>;
|
|
66
|
+
/** Service name. Default 'agent-runtime'. */
|
|
67
|
+
serviceName?: string;
|
|
68
|
+
}
|
|
69
|
+
interface OtelExporter {
|
|
70
|
+
/** Export a span. */
|
|
71
|
+
exportSpan(span: OtelSpan): void;
|
|
72
|
+
/** Force flush pending spans. */
|
|
73
|
+
flush(): Promise<void>;
|
|
74
|
+
/** Shutdown cleanly. */
|
|
75
|
+
shutdown(): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
interface OtelSpan {
|
|
78
|
+
traceId: string;
|
|
79
|
+
spanId: string;
|
|
80
|
+
parentSpanId?: string;
|
|
81
|
+
name: string;
|
|
82
|
+
kind?: number;
|
|
83
|
+
startTimeUnixNano: string;
|
|
84
|
+
endTimeUnixNano: string;
|
|
85
|
+
attributes?: OtelAttribute[];
|
|
86
|
+
status?: {
|
|
87
|
+
code: number;
|
|
88
|
+
message?: string;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
interface OtelAttribute {
|
|
92
|
+
key: string;
|
|
93
|
+
value: {
|
|
94
|
+
stringValue?: string;
|
|
95
|
+
intValue?: string;
|
|
96
|
+
doubleValue?: number;
|
|
97
|
+
boolValue?: boolean;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create an OTEL exporter. Returns undefined when no endpoint is configured.
|
|
102
|
+
*/
|
|
103
|
+
declare function createOtelExporter(config?: OtelExportConfig): OtelExporter | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Convert a LoopTraceEvent into an OtelSpan for export.
|
|
106
|
+
*/
|
|
107
|
+
declare function loopEventToOtelSpan(event: {
|
|
108
|
+
kind: string;
|
|
109
|
+
runId: string;
|
|
110
|
+
timestamp: number;
|
|
111
|
+
payload: object;
|
|
112
|
+
}, traceId: string, parentSpanId?: string): OtelSpan;
|
|
113
|
+
|
|
114
|
+
export { type OtelAttribute as O, type OtelExportConfig as a, type OtelExporter as b, type OtelSpan as c, createOtelExporter as d, mcpToolsForRuntimeMcpSubset as e, loopEventToOtelSpan as l, mcpToolsForRuntimeMcp as m };
|
package/dist/profiles.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentProfile } from '@tangle-network/sandbox';
|
|
2
|
-
import { O as OutputAdapter, V as Validator, A as AgentRunSpec, a as Driver } from './types-
|
|
3
|
-
import './runtime-run-
|
|
4
|
-
import './types-
|
|
2
|
+
import { O as OutputAdapter, V as Validator, A as AgentRunSpec, a as Driver } from './types-DmkRGTBn.js';
|
|
3
|
+
import './runtime-run-D5ItCKl_.js';
|
|
4
|
+
import './types-BFgFD_sl.js';
|
|
5
5
|
import '@tangle-network/agent-eval';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/profiles.js
CHANGED
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
coderProfile,
|
|
3
3
|
createCoderValidator,
|
|
4
4
|
multiHarnessCoderFanout
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-CBQVID7G.js";
|
|
6
|
+
import "./chunk-URDSRUPQ.js";
|
|
7
|
+
import "./chunk-XZYF3YJN.js";
|
|
8
8
|
import "./chunk-DGUM43GV.js";
|
|
9
9
|
export {
|
|
10
10
|
coderProfile,
|
|
@@ -142,6 +142,71 @@ type AgentRuntimeEvent<TState = unknown, TAction = unknown, TActionResult = unkn
|
|
|
142
142
|
};
|
|
143
143
|
/** @stable */
|
|
144
144
|
type AgentRuntimeEventSink<TState = unknown, TAction = unknown, TActionResult = unknown, TEval extends ControlEvalResult = ControlEvalResult> = (event: AgentRuntimeEvent<TState, TAction, TActionResult, TEval>) => Promise<void> | void;
|
|
145
|
+
/**
|
|
146
|
+
* @stable
|
|
147
|
+
*
|
|
148
|
+
* Typed transport / backend failure detail. Carried on `backend_error` and
|
|
149
|
+
* `final` events when the backend's stream throws or the upstream HTTP call
|
|
150
|
+
* returns a non-success status. Lets consumers (a) distinguish "stream
|
|
151
|
+
* completed with no text" from "stream never reached the model" and
|
|
152
|
+
* (b) reconstruct the precise upstream signal (status + truncated body) when
|
|
153
|
+
* building a `RunRecord.error`.
|
|
154
|
+
*
|
|
155
|
+
* `body` is truncated to 2 KiB by the backend so an HTML error page from a
|
|
156
|
+
* misconfigured proxy never bloats event payloads or logs. Consumers needing
|
|
157
|
+
* the full body should inspect the underlying `BackendTransportError.body`
|
|
158
|
+
* via a custom `mapEvent` or backend wrapper.
|
|
159
|
+
*/
|
|
160
|
+
interface BackendErrorDetail {
|
|
161
|
+
/**
|
|
162
|
+
* `'transport'` — upstream HTTP / network failure with optional status code.
|
|
163
|
+
* `'backend'` — the backend's `stream()` generator threw for a non-transport
|
|
164
|
+
* reason (e.g. a custom adapter error, sandbox crash).
|
|
165
|
+
*/
|
|
166
|
+
kind: 'transport' | 'backend';
|
|
167
|
+
message: string;
|
|
168
|
+
/** Upstream HTTP status when known. `0` for connection / abort errors. */
|
|
169
|
+
status?: number;
|
|
170
|
+
/** Truncated response body (≤2 KiB). Diagnostic only — never machine-parsed. */
|
|
171
|
+
body?: string;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* @stable
|
|
175
|
+
*
|
|
176
|
+
* OpenAI Chat Completions tool descriptor. The shape mirrors the
|
|
177
|
+
* `/v1/chat/completions` `tools[]` parameter so callers can pass tool
|
|
178
|
+
* definitions through `createOpenAICompatibleBackend({ tools })` without any
|
|
179
|
+
* runtime translation. The router proxies this shape verbatim to Anthropic
|
|
180
|
+
* (translated server-side), DeepSeek, Groq, OpenAI, and Gemini — every model
|
|
181
|
+
* that the eval surface targets.
|
|
182
|
+
*
|
|
183
|
+
* Callers that build their tool list from MCP servers should run a one-shot
|
|
184
|
+
* MCP `tools/list` at config time and project the result into this shape. The
|
|
185
|
+
* runtime intentionally does NOT depend on `@modelcontextprotocol/sdk` —
|
|
186
|
+
* keeping the backend transport thin lets domain repos own MCP plumbing.
|
|
187
|
+
*/
|
|
188
|
+
interface OpenAIChatTool {
|
|
189
|
+
type: 'function';
|
|
190
|
+
function: {
|
|
191
|
+
name: string;
|
|
192
|
+
description?: string;
|
|
193
|
+
parameters?: Record<string, unknown>;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* @stable
|
|
198
|
+
*
|
|
199
|
+
* `tool_choice` parameter for OpenAI-compat chat. Same shape as the OpenAI
|
|
200
|
+
* spec: `'auto'` (default — model decides), `'none'` (disable tool calling
|
|
201
|
+
* for this turn), `'required'` (force a tool call), or a specific function
|
|
202
|
+
* pin `{ type: 'function', function: { name } }`.
|
|
203
|
+
*/
|
|
204
|
+
type OpenAIChatToolChoice = 'auto' | 'none' | 'required' | {
|
|
205
|
+
type: 'function';
|
|
206
|
+
function: {
|
|
207
|
+
name: string;
|
|
208
|
+
};
|
|
209
|
+
};
|
|
145
210
|
/** @stable */
|
|
146
211
|
type RuntimeStreamEvent = {
|
|
147
212
|
type: 'task_start';
|
|
@@ -260,6 +325,18 @@ type RuntimeStreamEvent = {
|
|
|
260
325
|
backend: string;
|
|
261
326
|
message: string;
|
|
262
327
|
recoverable: boolean;
|
|
328
|
+
/**
|
|
329
|
+
* Typed transport diagnostic. Present when the upstream returned a
|
|
330
|
+
* non-success HTTP status or every retry attempt threw. Consumers MUST
|
|
331
|
+
* surface this onto their `RunRecord.error` — silently treating a
|
|
332
|
+
* `backend_error` as "no output" hides credit exhaustion, auth failure,
|
|
333
|
+
* and upstream outages from operators.
|
|
334
|
+
* - `kind: 'transport'` — HTTP / network failure with optional `status`
|
|
335
|
+
* + truncated response `body`.
|
|
336
|
+
* - `kind: 'backend'` — the backend's `stream()` generator threw for a
|
|
337
|
+
* reason that isn't a recognized transport failure.
|
|
338
|
+
*/
|
|
339
|
+
error?: BackendErrorDetail;
|
|
263
340
|
timestamp: string;
|
|
264
341
|
} | {
|
|
265
342
|
type: 'backend_end';
|
|
@@ -281,6 +358,15 @@ type RuntimeStreamEvent = {
|
|
|
281
358
|
reason: string;
|
|
282
359
|
text?: string;
|
|
283
360
|
metadata?: Record<string, unknown>;
|
|
361
|
+
/**
|
|
362
|
+
* Typed terminal-error diagnostic. Mirrors the `backend_error.error`
|
|
363
|
+
* shape so a consumer that only listens for `final` still receives a
|
|
364
|
+
* loud, structured failure when the backend never produced output. Only
|
|
365
|
+
* set when `status !== 'completed'`. Consumers building a `RunRecord`
|
|
366
|
+
* MUST map this to `RunRecord.error` rather than recording silent
|
|
367
|
+
* `error: null` with empty `finalText`.
|
|
368
|
+
*/
|
|
369
|
+
error?: BackendErrorDetail;
|
|
284
370
|
timestamp: string;
|
|
285
371
|
};
|
|
286
372
|
/** @stable */
|
|
@@ -376,4 +462,4 @@ interface KnowledgeReadinessDecision {
|
|
|
376
462
|
nonBlockingGapIds: string[];
|
|
377
463
|
}
|
|
378
464
|
|
|
379
|
-
export type { AgentTaskSpec as A, KnowledgeReadinessDecision as K, RuntimeStreamEvent as R, AgentBackendInput as a, AgentExecutionBackend as b,
|
|
465
|
+
export type { AgentTaskSpec as A, BackendErrorDetail as B, KnowledgeReadinessDecision as K, OpenAIChatTool as O, RuntimeStreamEvent as R, AgentBackendInput as a, AgentExecutionBackend as b, OpenAIChatToolChoice as c, AgentBackendContext as d, RunAgentTaskOptions as e, AgentTaskRunResult as f, RunAgentTaskStreamOptions as g, AgentRuntimeEvent as h, AgentTaskStatus as i, RuntimeSessionStore as j, RuntimeSession as k, AgentAdapter as l, AgentKnowledgeProvider as m, AgentRuntimeEventSink as n, AgentTaskContext as o };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentProfile, CreateSandboxOptions, SandboxEvent, SandboxInstance } from '@tangle-network/sandbox';
|
|
2
|
-
import { R as RuntimeRunHandle } from './runtime-run-
|
|
2
|
+
import { R as RuntimeRunHandle } from './runtime-run-D5ItCKl_.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @experimental
|
|
@@ -31,6 +31,12 @@ interface ValidationCtx {
|
|
|
31
31
|
iteration: number;
|
|
32
32
|
/** Cooperative cancellation channel. */
|
|
33
33
|
signal: AbortSignal;
|
|
34
|
+
/**
|
|
35
|
+
* Optional trace emitter. When set, validator implementations that make
|
|
36
|
+
* LLM calls (e.g. LLM reviewer in coderProfile) emit spans into it.
|
|
37
|
+
* The kernel passes `ctx.traceEmitter` from `ExecCtx` when available.
|
|
38
|
+
*/
|
|
39
|
+
traceEmitter?: LoopTraceEmitter;
|
|
34
40
|
}
|
|
35
41
|
/** @experimental */
|
|
36
42
|
interface Validator<Output, Verdict = DefaultVerdict> {
|
|
@@ -258,6 +264,17 @@ interface ExecCtx {
|
|
|
258
264
|
runHandle?: RuntimeRunHandle;
|
|
259
265
|
/** Cooperative cancellation signal. */
|
|
260
266
|
signal?: AbortSignal;
|
|
267
|
+
/**
|
|
268
|
+
* Trace id for OTEL correlation. When set alongside `traceEmitter`, the
|
|
269
|
+
* exporter uses this as the parent trace for all emitted spans. Typically
|
|
270
|
+
* inherited from TRACE_ID env var in MCP subprocess mode.
|
|
271
|
+
*/
|
|
272
|
+
traceId?: string;
|
|
273
|
+
/**
|
|
274
|
+
* Parent span id for OTEL correlation. Loop events become children of
|
|
275
|
+
* this span. Typically inherited from PARENT_SPAN_ID env var.
|
|
276
|
+
*/
|
|
277
|
+
parentSpanId?: string;
|
|
261
278
|
}
|
|
262
279
|
|
|
263
280
|
export type { AgentRunSpec as A, DefaultVerdict as D, ExecCtx as E, Iteration as I, LoopWinner as L, OutputAdapter as O, Validator as V, Driver as a, LoopResult as b, LoopDecisionPayload as c, LoopEndedPayload as d, LoopIterationDispatchPayload as e, LoopIterationEndedPayload as f, LoopIterationStartedPayload as g, LoopSandboxClient as h, LoopSandboxPlacement as i, LoopStartedPayload as j, LoopTraceEmitter as k, LoopTraceEvent as l, ValidationCtx as m };
|
package/package.json
CHANGED