@tangle-network/agent-runtime 0.79.4 → 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/README.md +6 -0
- package/dist/agent.js +3 -3
- package/dist/{chunk-AHZ3YBL6.js → chunk-3RAXZ6LB.js} +195 -64
- package/dist/chunk-3RAXZ6LB.js.map +1 -0
- package/dist/{chunk-44CX5JU6.js → chunk-3TAQW75Y.js} +53 -5
- package/dist/chunk-3TAQW75Y.js.map +1 -0
- package/dist/{chunk-NXZEVWKP.js → chunk-CR5MQUYO.js} +2 -2
- package/dist/{chunk-RUJZK6VH.js → chunk-KELG3Z5H.js} +2 -2
- package/dist/{chunk-U6AP535M.js → chunk-KNZ54YYO.js} +3 -3
- package/dist/{chunk-IPEQ3ERC.js → chunk-XRKP3XW3.js} +2 -2
- package/dist/{chunk-IPEQ3ERC.js.map → chunk-XRKP3XW3.js.map} +1 -1
- package/dist/{coordination-BFVtgRax.d.ts → coordination-BI9tpcmF.d.ts} +12 -3
- package/dist/environment-provider.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/intelligence.d.ts +1 -1
- package/dist/intelligence.js +1 -1
- package/dist/{loop-runner-bin-CTVja8e0.d.ts → loop-runner-bin-CBkLsyFg.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +4 -4
- package/dist/loop-runner-bin.js +4 -4
- package/dist/loops.d.ts +32 -12
- package/dist/loops.js +5 -3
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +6 -6
- package/dist/mcp/index.js +5 -5
- package/dist/{router-client-Ak2IGuXq.d.ts → router-client-D6Ocf4jG.d.ts} +19 -0
- package/dist/{types-DYW0tloU.d.ts → types-By9LXllv.d.ts} +7 -0
- package/dist/{worktree-fanout-DaUDwCA_.d.ts → worktree-fanout-D9Z2dMS9.d.ts} +2 -2
- package/dist/{worktree-harness-Dt6s_m3z.d.ts → worktree-harness-Dx8XULW3.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-44CX5JU6.js.map +0 -1
- package/dist/chunk-AHZ3YBL6.js.map +0 -1
- /package/dist/{chunk-NXZEVWKP.js.map → chunk-CR5MQUYO.js.map} +0 -0
- /package/dist/{chunk-RUJZK6VH.js.map → chunk-KELG3Z5H.js.map} +0 -0
- /package/dist/{chunk-U6AP535M.js.map → chunk-KNZ54YYO.js.map} +0 -0
package/README.md
CHANGED
|
@@ -8,6 +8,12 @@ One loop, used three ways. Domain behavior (models, tools, knowledge) plugs in a
|
|
|
8
8
|
pnpm add @tangle-network/agent-runtime @tangle-network/agent-eval @tangle-network/sandbox
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
**See it run in 30 seconds** (offline, no keys) — the one move everything else builds on, a driver reading a worker's output and composing the next step from it:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm tsx examples/driver-loop/driver-loop.ts
|
|
15
|
+
```
|
|
16
|
+
|
|
11
17
|
## What you do with it
|
|
12
18
|
|
|
13
19
|
| You want to… | Call |
|
package/dist/agent.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "./chunk-
|
|
1
|
+
import "./chunk-3RAXZ6LB.js";
|
|
2
2
|
import {
|
|
3
3
|
createSandboxForSpec
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
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-
|
|
17
|
+
} from "./chunk-3TAQW75Y.js";
|
|
18
18
|
import {
|
|
19
19
|
addTokenUsage,
|
|
20
20
|
isAbortError,
|
|
@@ -555,6 +555,195 @@ ${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
|
+
|
|
558
747
|
// src/runtime/completion.ts
|
|
559
748
|
function completionAuthorizes(v, policy) {
|
|
560
749
|
if (!v?.done) return false;
|
|
@@ -816,7 +1005,7 @@ import { mkdtempSync, rmSync } from "fs";
|
|
|
816
1005
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
817
1006
|
import { tmpdir } from "os";
|
|
818
1007
|
import { dirname, join } from "path";
|
|
819
|
-
function
|
|
1008
|
+
function isAsyncIterable2(v) {
|
|
820
1009
|
return typeof v === "object" && v !== null && Symbol.asyncIterator in v;
|
|
821
1010
|
}
|
|
822
1011
|
function inProcessSandboxClient(options) {
|
|
@@ -867,7 +1056,7 @@ function inProcessSandboxClient(options) {
|
|
|
867
1056
|
const ctx = { round, workdir: boxWorkdir, signal };
|
|
868
1057
|
round += 1;
|
|
869
1058
|
const produced = await onPrompt(prompt, ctx);
|
|
870
|
-
if (
|
|
1059
|
+
if (isAsyncIterable2(produced)) {
|
|
871
1060
|
for await (const ev of produced) yield ev;
|
|
872
1061
|
} else {
|
|
873
1062
|
for (const ev of produced) yield ev;
|
|
@@ -883,65 +1072,6 @@ function inProcessSandboxClient(options) {
|
|
|
883
1072
|
};
|
|
884
1073
|
}
|
|
885
1074
|
|
|
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
|
-
return {
|
|
905
|
-
id,
|
|
906
|
-
async *streamPrompt(message) {
|
|
907
|
-
const controller = new AbortController();
|
|
908
|
-
const spec = { profile: { name: id }, harness: null };
|
|
909
|
-
const exec = factory(spec, { signal: controller.signal, seams: {} });
|
|
910
|
-
try {
|
|
911
|
-
const artifact = await settle(exec, message, controller.signal);
|
|
912
|
-
const out = artifact.out;
|
|
913
|
-
const tokensIn = artifact.spent.tokens.input;
|
|
914
|
-
const tokensOut = artifact.spent.tokens.output;
|
|
915
|
-
const costUsd = artifact.spent.usd;
|
|
916
|
-
if (tokensIn || tokensOut || costUsd) {
|
|
917
|
-
yield {
|
|
918
|
-
type: "llm_call",
|
|
919
|
-
data: { tokensIn, tokensOut, costUsd }
|
|
920
|
-
};
|
|
921
|
-
}
|
|
922
|
-
yield {
|
|
923
|
-
type: "result",
|
|
924
|
-
data: {
|
|
925
|
-
finalText: out?.content ?? "",
|
|
926
|
-
tokenUsage: {
|
|
927
|
-
inputTokens: tokensIn,
|
|
928
|
-
outputTokens: tokensOut
|
|
929
|
-
},
|
|
930
|
-
costUsd
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
} finally {
|
|
934
|
-
await exec.teardown("brutalKill").catch(() => {
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
},
|
|
938
|
-
async delete() {
|
|
939
|
-
}
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
}
|
|
944
|
-
|
|
945
1075
|
// src/runtime/report-usage.ts
|
|
946
1076
|
function reportLoopUsage(cost, result, source = "loop") {
|
|
947
1077
|
cost.observe(result.costUsd, source);
|
|
@@ -4625,6 +4755,8 @@ export {
|
|
|
4625
4755
|
renderPairwiseMarkdown,
|
|
4626
4756
|
renderLeaderboardSvg,
|
|
4627
4757
|
renderLeaderboardHtml,
|
|
4758
|
+
inlineSandboxClient,
|
|
4759
|
+
cliBridgeSandboxClient,
|
|
4628
4760
|
completionAuthorizes,
|
|
4629
4761
|
stopSentinel,
|
|
4630
4762
|
sentinelCompletion,
|
|
@@ -4634,7 +4766,6 @@ export {
|
|
|
4634
4766
|
renderReport,
|
|
4635
4767
|
harvestCorpus,
|
|
4636
4768
|
inProcessSandboxClient,
|
|
4637
|
-
inlineSandboxClient,
|
|
4638
4769
|
reportLoopUsage,
|
|
4639
4770
|
loopCampaignDispatch,
|
|
4640
4771
|
loopDispatch,
|
|
@@ -4703,4 +4834,4 @@ export {
|
|
|
4703
4834
|
computeFindingId,
|
|
4704
4835
|
makeFinding2 as makeFinding
|
|
4705
4836
|
};
|
|
4706
|
-
//# sourceMappingURL=chunk-
|
|
4837
|
+
//# sourceMappingURL=chunk-3RAXZ6LB.js.map
|