@tangle-network/agent-runtime 0.80.1 → 0.81.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/dist/agent.js +3 -3
- package/dist/{chunk-KNZ54YYO.js → chunk-5GCTCLKP.js} +3 -3
- package/dist/{chunk-KELG3Z5H.js → chunk-CA43KLZW.js} +2 -2
- package/dist/{chunk-XRKP3XW3.js → chunk-HUT4RXDJ.js} +2 -2
- package/dist/{chunk-XRKP3XW3.js.map → chunk-HUT4RXDJ.js.map} +1 -1
- package/dist/{chunk-3TAQW75Y.js → chunk-QWLUOITV.js} +78 -14
- package/dist/chunk-QWLUOITV.js.map +1 -0
- package/dist/{chunk-3RAXZ6LB.js → chunk-SN3XBTTH.js} +65 -195
- package/dist/chunk-SN3XBTTH.js.map +1 -0
- package/dist/{chunk-CR5MQUYO.js → chunk-Y47PMSZ7.js} +2 -2
- package/dist/index.js +5 -5
- package/dist/intelligence.js +1 -1
- package/dist/loop-runner-bin.js +4 -4
- package/dist/loops.d.ts +2 -19
- package/dist/loops.js +3 -5
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.js +5 -5
- package/package.json +1 -1
- package/dist/chunk-3RAXZ6LB.js.map +0 -1
- package/dist/chunk-3TAQW75Y.js.map +0 -1
- /package/dist/{chunk-KNZ54YYO.js.map → chunk-5GCTCLKP.js.map} +0 -0
- /package/dist/{chunk-KELG3Z5H.js.map → chunk-CA43KLZW.js.map} +0 -0
- /package/dist/{chunk-CR5MQUYO.js.map → chunk-Y47PMSZ7.js.map} +0 -0
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
settledToIteration,
|
|
15
15
|
supervise,
|
|
16
16
|
withDriverExecutor
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-QWLUOITV.js";
|
|
18
18
|
import {
|
|
19
19
|
addTokenUsage,
|
|
20
20
|
isAbortError,
|
|
@@ -555,195 +555,6 @@ ${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
|
-
|
|
562
|
-
// src/runtime/inline-sandbox-client.ts
|
|
563
|
-
function isAsyncIterable(v) {
|
|
564
|
-
return typeof v === "object" && v !== null && Symbol.asyncIterator in v;
|
|
565
|
-
}
|
|
566
|
-
async function settle(exec, task, signal) {
|
|
567
|
-
const r = exec.execute(task, signal);
|
|
568
|
-
if (isAsyncIterable(r)) {
|
|
569
|
-
for await (const _ of r) {
|
|
570
|
-
}
|
|
571
|
-
return exec.resultArtifact();
|
|
572
|
-
}
|
|
573
|
-
return r;
|
|
574
|
-
}
|
|
575
|
-
function inlineSandboxClient(factory) {
|
|
576
|
-
let seq = 0;
|
|
577
|
-
return {
|
|
578
|
-
async create(options) {
|
|
579
|
-
const id = `inline-${seq++}`;
|
|
580
|
-
const createOptions = options;
|
|
581
|
-
return {
|
|
582
|
-
id,
|
|
583
|
-
async *streamPrompt(message) {
|
|
584
|
-
const controller = new AbortController();
|
|
585
|
-
const spec = { profile: { name: id }, harness: null };
|
|
586
|
-
const exec = factory(spec, { signal: controller.signal, seams: { createOptions } });
|
|
587
|
-
try {
|
|
588
|
-
const artifact = await settle(exec, message, controller.signal);
|
|
589
|
-
const out = artifact.out;
|
|
590
|
-
const tokensIn = artifact.spent.tokens.input;
|
|
591
|
-
const tokensOut = artifact.spent.tokens.output;
|
|
592
|
-
const costUsd = artifact.spent.usd;
|
|
593
|
-
if (tokensIn || tokensOut || costUsd) {
|
|
594
|
-
yield {
|
|
595
|
-
type: "llm_call",
|
|
596
|
-
data: { tokensIn, tokensOut, costUsd }
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
yield {
|
|
600
|
-
type: "result",
|
|
601
|
-
data: {
|
|
602
|
-
finalText: out?.content ?? "",
|
|
603
|
-
tokenUsage: {
|
|
604
|
-
inputTokens: tokensIn,
|
|
605
|
-
outputTokens: tokensOut
|
|
606
|
-
},
|
|
607
|
-
costUsd
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
} finally {
|
|
611
|
-
await exec.teardown("brutalKill").catch(() => {
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
},
|
|
615
|
-
async delete() {
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
// src/runtime/cli-bridge-sandbox-client.ts
|
|
623
|
-
var DEFAULT_BRIDGE_URL = "http://127.0.0.1:3355";
|
|
624
|
-
var BRIDGE_TIMEOUT_MS = 9e5;
|
|
625
|
-
function bridgeModelId(harness, model) {
|
|
626
|
-
return model.startsWith(`${harness}/`) ? model : `${harness}/${model}`;
|
|
627
|
-
}
|
|
628
|
-
function resolveTarget(cfg, createOptions) {
|
|
629
|
-
const backend = createOptions?.backend;
|
|
630
|
-
const harness = backend?.type ?? cfg.harness;
|
|
631
|
-
const model = backend?.model?.model ?? cfg.model;
|
|
632
|
-
if (!harness)
|
|
633
|
-
throw new Error(
|
|
634
|
-
"cliBridgeSandboxClient: no harness (set cfg.harness or create({ backend: { type } }))"
|
|
635
|
-
);
|
|
636
|
-
if (!model)
|
|
637
|
-
throw new Error(
|
|
638
|
-
"cliBridgeSandboxClient: no model (set cfg.model or create({ backend: { model: { model } } }))"
|
|
639
|
-
);
|
|
640
|
-
return { harness, model };
|
|
641
|
-
}
|
|
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
|
-
}
|
|
692
|
-
);
|
|
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
|
-
});
|
|
706
|
-
}
|
|
707
|
-
function cliBridgeSandboxClient(cfg) {
|
|
708
|
-
if (!cfg.bearer) throw new Error("cliBridgeSandboxClient: bearer is required");
|
|
709
|
-
const url = cfg.url ?? DEFAULT_BRIDGE_URL;
|
|
710
|
-
let seq = 0;
|
|
711
|
-
const factory = (_spec, ctx) => {
|
|
712
|
-
const id = `cli-bridge-${seq++}`;
|
|
713
|
-
const createOptions = ctx.seams.createOptions;
|
|
714
|
-
const { harness, model } = resolveTarget(cfg, createOptions);
|
|
715
|
-
const bridgeModel = bridgeModelId(harness, model);
|
|
716
|
-
let artifact;
|
|
717
|
-
return {
|
|
718
|
-
runtime: "cli",
|
|
719
|
-
async execute(task, signal) {
|
|
720
|
-
const started = Date.now();
|
|
721
|
-
const timeout = AbortSignal.timeout(BRIDGE_TIMEOUT_MS);
|
|
722
|
-
const composed = AbortSignal.any([signal, timeout]);
|
|
723
|
-
const r = await bridgePost(url, cfg.bearer, bridgeModel, String(task), composed);
|
|
724
|
-
artifact = {
|
|
725
|
-
outRef: `cli-bridge:${id}`,
|
|
726
|
-
out: { content: r.content },
|
|
727
|
-
spent: {
|
|
728
|
-
iterations: 1,
|
|
729
|
-
tokens: { input: r.input, output: r.output },
|
|
730
|
-
usd: 0,
|
|
731
|
-
ms: Date.now() - started
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
return artifact;
|
|
735
|
-
},
|
|
736
|
-
teardown: () => Promise.resolve({ destroyed: true }),
|
|
737
|
-
resultArtifact() {
|
|
738
|
-
if (!artifact)
|
|
739
|
-
throw new Error("cliBridgeSandboxClient: resultArtifact() read before execute()");
|
|
740
|
-
return artifact;
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
};
|
|
744
|
-
return inlineSandboxClient(factory);
|
|
745
|
-
}
|
|
746
|
-
|
|
747
558
|
// src/runtime/completion.ts
|
|
748
559
|
function completionAuthorizes(v, policy) {
|
|
749
560
|
if (!v?.done) return false;
|
|
@@ -1005,7 +816,7 @@ import { mkdtempSync, rmSync } from "fs";
|
|
|
1005
816
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
1006
817
|
import { tmpdir } from "os";
|
|
1007
818
|
import { dirname, join } from "path";
|
|
1008
|
-
function
|
|
819
|
+
function isAsyncIterable(v) {
|
|
1009
820
|
return typeof v === "object" && v !== null && Symbol.asyncIterator in v;
|
|
1010
821
|
}
|
|
1011
822
|
function inProcessSandboxClient(options) {
|
|
@@ -1056,7 +867,7 @@ function inProcessSandboxClient(options) {
|
|
|
1056
867
|
const ctx = { round, workdir: boxWorkdir, signal };
|
|
1057
868
|
round += 1;
|
|
1058
869
|
const produced = await onPrompt(prompt, ctx);
|
|
1059
|
-
if (
|
|
870
|
+
if (isAsyncIterable(produced)) {
|
|
1060
871
|
for await (const ev of produced) yield ev;
|
|
1061
872
|
} else {
|
|
1062
873
|
for (const ev of produced) yield ev;
|
|
@@ -1072,6 +883,66 @@ function inProcessSandboxClient(options) {
|
|
|
1072
883
|
};
|
|
1073
884
|
}
|
|
1074
885
|
|
|
886
|
+
// src/runtime/inline-sandbox-client.ts
|
|
887
|
+
function isAsyncIterable2(v) {
|
|
888
|
+
return typeof v === "object" && v !== null && Symbol.asyncIterator in v;
|
|
889
|
+
}
|
|
890
|
+
async function settle(exec, task, signal) {
|
|
891
|
+
const r = exec.execute(task, signal);
|
|
892
|
+
if (isAsyncIterable2(r)) {
|
|
893
|
+
for await (const _ of r) {
|
|
894
|
+
}
|
|
895
|
+
return exec.resultArtifact();
|
|
896
|
+
}
|
|
897
|
+
return r;
|
|
898
|
+
}
|
|
899
|
+
function inlineSandboxClient(factory) {
|
|
900
|
+
let seq = 0;
|
|
901
|
+
return {
|
|
902
|
+
async create(options) {
|
|
903
|
+
const id = `inline-${seq++}`;
|
|
904
|
+
const createOptions = options;
|
|
905
|
+
return {
|
|
906
|
+
id,
|
|
907
|
+
async *streamPrompt(message) {
|
|
908
|
+
const controller = new AbortController();
|
|
909
|
+
const spec = { profile: { name: id }, harness: null };
|
|
910
|
+
const exec = factory(spec, { signal: controller.signal, seams: { createOptions } });
|
|
911
|
+
try {
|
|
912
|
+
const artifact = await settle(exec, message, controller.signal);
|
|
913
|
+
const out = artifact.out;
|
|
914
|
+
const tokensIn = artifact.spent.tokens.input;
|
|
915
|
+
const tokensOut = artifact.spent.tokens.output;
|
|
916
|
+
const costUsd = artifact.spent.usd;
|
|
917
|
+
if (tokensIn || tokensOut || costUsd) {
|
|
918
|
+
yield {
|
|
919
|
+
type: "llm_call",
|
|
920
|
+
data: { tokensIn, tokensOut, costUsd }
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
yield {
|
|
924
|
+
type: "result",
|
|
925
|
+
data: {
|
|
926
|
+
finalText: out?.content ?? "",
|
|
927
|
+
tokenUsage: {
|
|
928
|
+
inputTokens: tokensIn,
|
|
929
|
+
outputTokens: tokensOut
|
|
930
|
+
},
|
|
931
|
+
costUsd
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
} finally {
|
|
935
|
+
await exec.teardown("brutalKill").catch(() => {
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
},
|
|
939
|
+
async delete() {
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
|
|
1075
946
|
// src/runtime/report-usage.ts
|
|
1076
947
|
function reportLoopUsage(cost, result, source = "loop") {
|
|
1077
948
|
cost.observe(result.costUsd, source);
|
|
@@ -4755,8 +4626,6 @@ export {
|
|
|
4755
4626
|
renderPairwiseMarkdown,
|
|
4756
4627
|
renderLeaderboardSvg,
|
|
4757
4628
|
renderLeaderboardHtml,
|
|
4758
|
-
inlineSandboxClient,
|
|
4759
|
-
cliBridgeSandboxClient,
|
|
4760
4629
|
completionAuthorizes,
|
|
4761
4630
|
stopSentinel,
|
|
4762
4631
|
sentinelCompletion,
|
|
@@ -4766,6 +4635,7 @@ export {
|
|
|
4766
4635
|
renderReport,
|
|
4767
4636
|
harvestCorpus,
|
|
4768
4637
|
inProcessSandboxClient,
|
|
4638
|
+
inlineSandboxClient,
|
|
4769
4639
|
reportLoopUsage,
|
|
4770
4640
|
loopCampaignDispatch,
|
|
4771
4641
|
loopDispatch,
|
|
@@ -4834,4 +4704,4 @@ export {
|
|
|
4834
4704
|
computeFindingId,
|
|
4835
4705
|
makeFinding2 as makeFinding
|
|
4836
4706
|
};
|
|
4837
|
-
//# sourceMappingURL=chunk-
|
|
4707
|
+
//# sourceMappingURL=chunk-SN3XBTTH.js.map
|