@tangle-network/agent-runtime 0.80.1 → 0.81.1

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.
@@ -8,7 +8,7 @@ import {
8
8
  DELEGATION_STATUS_DESCRIPTION,
9
9
  DELEGATION_STATUS_INPUT_SCHEMA,
10
10
  DELEGATION_STATUS_TOOL_NAME
11
- } from "./chunk-3TAQW75Y.js";
11
+ } from "./chunk-VHJDS6OR.js";
12
12
 
13
13
  // src/mcp/openai-tools.ts
14
14
  function buildTool(name, description, parameters) {
@@ -45,4 +45,4 @@ export {
45
45
  mcpToolsForRuntimeMcp,
46
46
  mcpToolsForRuntimeMcpSubset
47
47
  };
48
- //# sourceMappingURL=chunk-KELG3Z5H.js.map
48
+ //# sourceMappingURL=chunk-EAGRBFQF.js.map
@@ -5,10 +5,10 @@ import {
5
5
  definePersona,
6
6
  runPersonified,
7
7
  worktreeFanout
8
- } from "./chunk-3RAXZ6LB.js";
8
+ } from "./chunk-D6GIWPKD.js";
9
9
  import {
10
10
  createExecutorRegistry
11
- } from "./chunk-3TAQW75Y.js";
11
+ } from "./chunk-VHJDS6OR.js";
12
12
  import {
13
13
  runAnalystLoop
14
14
  } from "./chunk-C2FZ6GR6.js";
@@ -196,4 +196,4 @@ export {
196
196
  runLoopRunnerCli,
197
197
  parseLoopRunnerArgv
198
198
  };
199
- //# sourceMappingURL=chunk-KNZ54YYO.js.map
199
+ //# sourceMappingURL=chunk-OUGNIHDZ.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildLoopSpanNodes
3
- } from "./chunk-XRKP3XW3.js";
3
+ } from "./chunk-BPS254IE.js";
4
4
  import {
5
5
  addTokenUsage,
6
6
  deleteBoxSafe,
@@ -2174,6 +2174,9 @@ function linkSignals(a, b) {
2174
2174
  // src/runtime/supervise/runtime.ts
2175
2175
  import { spawn as spawn3 } from "child_process";
2176
2176
  import { randomUUID as randomUUID2 } from "crypto";
2177
+ import { request as httpRequest } from "http";
2178
+ import { request as httpsRequest } from "https";
2179
+ import { Readable } from "stream";
2177
2180
  import { estimateCost as estimateCost2, isModelPriced as isModelPriced2 } from "@tangle-network/agent-eval";
2178
2181
  var routerSeamKey = "router";
2179
2182
  var sandboxSeamKey = "sandbox";
@@ -2623,8 +2626,20 @@ function killWithGrace(proc, grace) {
2623
2626
  }, grace);
2624
2627
  });
2625
2628
  }
2629
+ function bridgeCellModel(seamModel, ctx) {
2630
+ const create = ctx.seams.createOptions;
2631
+ const backend = create?.backend;
2632
+ const harness = backend?.type;
2633
+ const model = backend?.model?.model;
2634
+ if (!harness && !model) return seamModel;
2635
+ const h = harness ?? "";
2636
+ const m = model ?? seamModel;
2637
+ if (!h) return m;
2638
+ return m.startsWith(`${h}/`) ? m : `${h}/${m}`;
2639
+ }
2626
2640
  var bridgeExecutor = (spec, ctx) => {
2627
- const seam = readSeam(ctx, bridgeSeamKey, "bridge");
2641
+ const base = readSeam(ctx, bridgeSeamKey, "bridge");
2642
+ const seam = { ...base, model: bridgeCellModel(base.model, ctx) };
2628
2643
  if (!seam.bridgeUrl || !seam.bridgeBearer || !seam.model) {
2629
2644
  throw new ValidationError(
2630
2645
  "bridgeExecutor: BridgeSeam.bridgeUrl + bridgeBearer + model required"
@@ -2673,7 +2688,6 @@ var bridgeExecutor = (spec, ctx) => {
2673
2688
  async function* streamBridgeSession(args) {
2674
2689
  const { seam, inbox } = args;
2675
2690
  const started = Date.now();
2676
- const url = `${seam.bridgeUrl.replace(/\/$/, "")}/v1/chat/completions`;
2677
2691
  const external = mergeAbortSignals(args.signal, args.controller.signal);
2678
2692
  const tokens = zeroTokenUsage();
2679
2693
  let usd = 0;
@@ -2710,21 +2724,17 @@ ${folded}` : folded;
2710
2724
  };
2711
2725
  let res;
2712
2726
  try {
2713
- res = await fetch(url, {
2714
- method: "POST",
2715
- headers: {
2716
- "content-type": "application/json",
2717
- authorization: `Bearer ${seam.bridgeBearer}`,
2718
- "x-session-id": args.sessionId
2719
- },
2720
- body: JSON.stringify({
2727
+ res = await bridgeStreamPost(seam.bridgeUrl, {
2728
+ bearer: seam.bridgeBearer,
2729
+ sessionId: args.sessionId,
2730
+ body: {
2721
2731
  model: seam.model,
2722
2732
  stream: true,
2723
2733
  session_id: args.sessionId,
2724
2734
  ...seam.cwd ? { cwd: seam.cwd } : {},
2725
2735
  ...seam.agentProfile ? { agent_profile: seam.agentProfile } : {},
2726
2736
  messages
2727
- }),
2737
+ },
2728
2738
  signal: turnController.signal
2729
2739
  });
2730
2740
  } catch (e) {
@@ -2781,6 +2791,59 @@ ${folded}` : folded;
2781
2791
  spent
2782
2792
  });
2783
2793
  }
2794
+ function bridgeStreamPost(url, args) {
2795
+ const target = new URL(`${url.replace(/\/$/, "")}/v1/chat/completions`);
2796
+ const payload = JSON.stringify(args.body);
2797
+ const requestFn = target.protocol === "https:" ? httpsRequest : httpRequest;
2798
+ return new Promise((resolve, reject) => {
2799
+ if (args.signal.aborted) {
2800
+ reject(new DOMException("bridgeExecutor: aborted before request", "AbortError"));
2801
+ return;
2802
+ }
2803
+ const req = requestFn(
2804
+ target,
2805
+ {
2806
+ method: "POST",
2807
+ headers: {
2808
+ "content-type": "application/json",
2809
+ authorization: `Bearer ${args.bearer}`,
2810
+ "x-session-id": args.sessionId,
2811
+ "content-length": Buffer.byteLength(payload)
2812
+ },
2813
+ // No header/body idle timeout: a slow bridge is a live bridge; the abort
2814
+ // signal is the sole deadline.
2815
+ timeout: 0
2816
+ },
2817
+ (res) => {
2818
+ const status = res.statusCode ?? 0;
2819
+ const ok = status >= 200 && status < 300;
2820
+ const body = Readable.toWeb(res);
2821
+ resolve({
2822
+ ok,
2823
+ status,
2824
+ body,
2825
+ text: async () => {
2826
+ const chunks = [];
2827
+ for await (const c of res) chunks.push(c);
2828
+ return Buffer.concat(chunks).toString("utf8");
2829
+ }
2830
+ });
2831
+ }
2832
+ );
2833
+ const onAbort = () => {
2834
+ req.destroy(new DOMException("bridgeExecutor: turn aborted", "AbortError"));
2835
+ };
2836
+ if (args.signal.aborted) onAbort();
2837
+ else args.signal.addEventListener("abort", onAbort, { once: true });
2838
+ req.on("error", (e) => {
2839
+ args.signal.removeEventListener("abort", onAbort);
2840
+ reject(e);
2841
+ });
2842
+ req.on("close", () => args.signal.removeEventListener("abort", onAbort));
2843
+ req.write(payload);
2844
+ req.end();
2845
+ });
2846
+ }
2784
2847
  async function* parseSseChatStream(body) {
2785
2848
  const reader = body.getReader();
2786
2849
  const decoder = new TextDecoder();
@@ -5360,7 +5423,7 @@ import { createServer } from "http";
5360
5423
 
5361
5424
  // src/mcp/server.ts
5362
5425
  import { createInterface } from "readline";
5363
- import { Readable, Writable } from "stream";
5426
+ import { Readable as Readable2, Writable } from "stream";
5364
5427
 
5365
5428
  // src/runtime/supervise/supervise.ts
5366
5429
  function workerFromBackend(backend, deliverable) {
@@ -6248,7 +6311,7 @@ function writeResponse(output, response) {
6248
6311
  }
6249
6312
  function createInProcessTransport() {
6250
6313
  const responses = [];
6251
- const input = new Readable({ read() {
6314
+ const input = new Readable2({ read() {
6252
6315
  } });
6253
6316
  const output = new Writable({
6254
6317
  write(chunk, _enc, cb) {
@@ -6527,4 +6590,4 @@ export {
6527
6590
  createInProcessTransport,
6528
6591
  serveCoordinationMcp
6529
6592
  };
6530
- //# sourceMappingURL=chunk-3TAQW75Y.js.map
6593
+ //# sourceMappingURL=chunk-VHJDS6OR.js.map