@tangle-network/agent-runtime 0.80.0 → 0.80.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.
package/dist/agent.js CHANGED
@@ -1,8 +1,8 @@
1
- import "./chunk-QSO2TVDS.js";
1
+ import "./chunk-3RAXZ6LB.js";
2
2
  import {
3
3
  createSandboxForSpec
4
- } from "./chunk-TPII5AU7.js";
5
- import "./chunk-3X53HYRW.js";
4
+ } from "./chunk-3TAQW75Y.js";
5
+ import "./chunk-XRKP3XW3.js";
6
6
  import "./chunk-H7IBHAFT.js";
7
7
  import {
8
8
  mapSandboxEvent
@@ -14,7 +14,7 @@ import {
14
14
  settledToIteration,
15
15
  supervise,
16
16
  withDriverExecutor
17
- } from "./chunk-TPII5AU7.js";
17
+ } from "./chunk-3TAQW75Y.js";
18
18
  import {
19
19
  addTokenUsage,
20
20
  isAbortError,
@@ -555,6 +555,10 @@ ${rows}
555
555
  </body></html>`;
556
556
  }
557
557
 
558
+ // src/runtime/cli-bridge-sandbox-client.ts
559
+ import { request as httpRequest } from "http";
560
+ import { request as httpsRequest } from "https";
561
+
558
562
  // src/runtime/inline-sandbox-client.ts
559
563
  function isAsyncIterable(v) {
560
564
  return typeof v === "object" && v !== null && Symbol.asyncIterator in v;
@@ -635,25 +639,70 @@ function resolveTarget(cfg, createOptions) {
635
639
  );
636
640
  return { harness, model };
637
641
  }
638
- async function bridgePost(url, bearer, bridgeModel, prompt, signal) {
639
- const res = await fetch(`${url}/v1/chat/completions`, {
640
- method: "POST",
641
- headers: { "content-type": "application/json", authorization: `Bearer ${bearer}` },
642
- body: JSON.stringify({ model: bridgeModel, messages: [{ role: "user", content: prompt }] }),
643
- signal
644
- });
645
- if (!res.ok) {
646
- throw new Error(
647
- `cli-bridge ${bridgeModel}: HTTP ${res.status} ${(await res.text()).slice(0, 300)}`
642
+ function bridgePost(url, bearer, bridgeModel, prompt, signal) {
643
+ const target = new URL(`${url.replace(/\/$/, "")}/v1/chat/completions`);
644
+ const body = JSON.stringify({ model: bridgeModel, messages: [{ role: "user", content: prompt }] });
645
+ const requestFn = target.protocol === "https:" ? httpsRequest : httpRequest;
646
+ return new Promise((resolve, reject) => {
647
+ if (signal.aborted) {
648
+ reject(new Error(`cli-bridge ${bridgeModel}: aborted before request`));
649
+ return;
650
+ }
651
+ const req = requestFn(
652
+ target,
653
+ {
654
+ method: "POST",
655
+ headers: {
656
+ "content-type": "application/json",
657
+ authorization: `Bearer ${bearer}`,
658
+ "content-length": Buffer.byteLength(body)
659
+ },
660
+ // No header/body idle timeout: a slow bridge is a live bridge; the abort
661
+ // signal is the sole deadline.
662
+ timeout: 0
663
+ },
664
+ (res) => {
665
+ const chunks = [];
666
+ res.on("data", (c) => chunks.push(c));
667
+ res.on("end", () => {
668
+ const text = Buffer.concat(chunks).toString("utf8");
669
+ const status = res.statusCode ?? 0;
670
+ if (status < 200 || status >= 300) {
671
+ reject(new Error(`cli-bridge ${bridgeModel}: HTTP ${status} ${text.slice(0, 300)}`));
672
+ return;
673
+ }
674
+ let j;
675
+ try {
676
+ j = JSON.parse(text);
677
+ } catch {
678
+ reject(new Error(`cli-bridge ${bridgeModel}: non-JSON body ${text.slice(0, 300)}`));
679
+ return;
680
+ }
681
+ if (j.error) {
682
+ reject(new Error(`cli-bridge ${bridgeModel}: ${j.error.message}`));
683
+ return;
684
+ }
685
+ resolve({
686
+ content: j.choices?.[0]?.message?.content ?? "",
687
+ input: j.usage?.prompt_tokens ?? 0,
688
+ output: j.usage?.completion_tokens ?? 0
689
+ });
690
+ });
691
+ }
648
692
  );
649
- }
650
- const j = await res.json();
651
- if (j.error) throw new Error(`cli-bridge ${bridgeModel}: ${j.error.message}`);
652
- return {
653
- content: j.choices?.[0]?.message?.content ?? "",
654
- input: j.usage?.prompt_tokens ?? 0,
655
- output: j.usage?.completion_tokens ?? 0
656
- };
693
+ const onAbort = () => {
694
+ req.destroy(
695
+ new Error(
696
+ `cli-bridge ${bridgeModel}: aborted (${BRIDGE_TIMEOUT_MS}ms deadline or upstream cancel)`
697
+ )
698
+ );
699
+ };
700
+ signal.addEventListener("abort", onAbort, { once: true });
701
+ req.on("error", (e) => reject(new Error(`cli-bridge ${bridgeModel}: ${e.message}`)));
702
+ req.on("close", () => signal.removeEventListener("abort", onAbort));
703
+ req.write(body);
704
+ req.end();
705
+ });
657
706
  }
658
707
  function cliBridgeSandboxClient(cfg) {
659
708
  if (!cfg.bearer) throw new Error("cliBridgeSandboxClient: bearer is required");
@@ -4785,4 +4834,4 @@ export {
4785
4834
  computeFindingId,
4786
4835
  makeFinding2 as makeFinding
4787
4836
  };
4788
- //# sourceMappingURL=chunk-QSO2TVDS.js.map
4837
+ //# sourceMappingURL=chunk-3RAXZ6LB.js.map