@tangle-network/agent-runtime 0.89.0 → 0.90.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 +51 -18
- package/dist/agent.d.ts +53 -2
- package/dist/agent.js +168 -6
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/chunk-5QOB7H74.js +387 -0
- package/dist/chunk-5QOB7H74.js.map +1 -0
- package/dist/{chunk-4WXGK6GV.js → chunk-7ON74BQO.js} +2 -2
- package/dist/{chunk-7LO5GMAO.js → chunk-CMYMTRGA.js} +14 -5
- package/dist/chunk-CMYMTRGA.js.map +1 -0
- package/dist/{chunk-UD4BHQMI.js → chunk-IVGYLCFH.js} +2 -2
- package/dist/{chunk-UD4BHQMI.js.map → chunk-IVGYLCFH.js.map} +1 -1
- package/dist/{chunk-VNOOH22O.js → chunk-OOL3675H.js} +85 -4
- package/dist/chunk-OOL3675H.js.map +1 -0
- package/dist/{chunk-5AVV7KAH.js → chunk-QK4DV5PR.js} +2 -2
- package/dist/chunk-R2VAJGR3.js +214 -0
- package/dist/chunk-R2VAJGR3.js.map +1 -0
- package/dist/{chunk-N7EJV7N3.js → chunk-RYBVU4M3.js} +3592 -3562
- package/dist/chunk-RYBVU4M3.js.map +1 -0
- package/dist/{chunk-BQPFZE2C.js → chunk-WRUSWK4F.js} +5 -5
- package/dist/{chunk-PIPPLSOF.js → chunk-ZV4LXYCJ.js} +451 -24
- package/dist/chunk-ZV4LXYCJ.js.map +1 -0
- package/dist/{worktree-harness-CX_McRLp.d.ts → completion-gate-DkAnUmpb.d.ts} +45 -45
- package/dist/{coordination-CuDLO8wj.d.ts → coordination-rRj5hjJK.d.ts} +415 -227
- package/dist/environment-provider.d.ts +3 -3
- package/dist/index.d.ts +255 -16
- package/dist/index.js +463 -72
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +228 -84
- package/dist/intelligence.js +259 -166
- package/dist/intelligence.js.map +1 -1
- package/dist/knowledge.d.ts +120 -0
- package/dist/knowledge.js +28 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.js +2 -2
- package/dist/{local-harness-sI0S_XNA.d.ts → local-harness-dcD5WTTr.d.ts} +3 -0
- package/dist/{loop-runner-bin-hQDUL8Ld.d.ts → loop-runner-bin-DTbZVGfM.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +6 -6
- package/dist/loop-runner-bin.js +7 -7
- package/dist/loops.d.ts +34 -369
- package/dist/loops.js +31 -5
- package/dist/mcp/bin.js +5 -5
- package/dist/mcp/index.d.ts +10 -11
- package/dist/mcp/index.js +10 -10
- package/dist/{mcp-serve-verifier-FL7-ZEb_.d.ts → mcp-serve-verifier-XsX8rkB9.d.ts} +12 -1
- package/dist/{openai-tools-BnrOmGjN.d.ts → openai-tools-C4ZfUD4L.d.ts} +1 -1
- package/dist/profiles.d.ts +196 -5
- package/dist/profiles.js +8 -0
- package/dist/profiles.js.map +1 -1
- package/dist/{router-client-r8y_VFVM.d.ts → router-client-DJImUDlm.d.ts} +1 -1
- package/dist/structural-rollout-MwlpgQ-6.d.ts +446 -0
- package/dist/supervise-DPmYPk0j.d.ts +131 -0
- package/dist/{types-ESeMOj94.d.ts → types-SyuwunY_.d.ts} +1 -1
- package/dist/{types-Driepl87.d.ts → types-eMNgWgFi.d.ts} +2 -2
- package/dist/{worktree-fanout-D6xR2CIA.d.ts → worktree-fanout-BDFQIO-Y.d.ts} +234 -234
- package/package.json +12 -4
- package/skills/agent-runtime-adoption/SKILL.md +74 -24
- package/skills/build-with-agent-runtime/SKILL.md +23 -20
- package/skills/loop-writer/SKILL.md +6 -5
- package/skills/supervise/SKILL.md +2 -2
- package/dist/chunk-7LO5GMAO.js.map +0 -1
- package/dist/chunk-N7EJV7N3.js.map +0 -1
- package/dist/chunk-PIPPLSOF.js.map +0 -1
- package/dist/chunk-VNOOH22O.js.map +0 -1
- package/dist/otel-export-BKmNwiCb.d.ts +0 -180
- /package/dist/{chunk-4WXGK6GV.js.map → chunk-7ON74BQO.js.map} +0 -0
- /package/dist/{chunk-5AVV7KAH.js.map → chunk-QK4DV5PR.js.map} +0 -0
- /package/dist/{chunk-BQPFZE2C.js.map → chunk-WRUSWK4F.js.map} +0 -0
package/dist/intelligence.js
CHANGED
|
@@ -2,9 +2,147 @@ import {
|
|
|
2
2
|
buildLoopOtelSpans,
|
|
3
3
|
createOtelExporter,
|
|
4
4
|
flatOtelSpan
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-IVGYLCFH.js";
|
|
6
6
|
import "./chunk-DGUM43GV.js";
|
|
7
7
|
|
|
8
|
+
// src/intelligence/delivery.ts
|
|
9
|
+
var defaultPlaneBaseUrl = "https://intelligence.tangle.tools";
|
|
10
|
+
var defaultRefreshMs = 3e5;
|
|
11
|
+
var defaultPullTimeoutMs = 1e4;
|
|
12
|
+
function resolveIntelligenceBaseUrl(baseUrl) {
|
|
13
|
+
if (baseUrl) return baseUrl.replace(/\/+$/, "");
|
|
14
|
+
if (typeof process !== "undefined" && process.env.TANGLE_INTELLIGENCE_URL) {
|
|
15
|
+
return process.env.TANGLE_INTELLIGENCE_URL.replace(/\/+$/, "");
|
|
16
|
+
}
|
|
17
|
+
return defaultPlaneBaseUrl;
|
|
18
|
+
}
|
|
19
|
+
function resolveApiKey(apiKey) {
|
|
20
|
+
if (apiKey) return apiKey;
|
|
21
|
+
if (typeof process !== "undefined" && process.env.TANGLE_API_KEY)
|
|
22
|
+
return process.env.TANGLE_API_KEY;
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
function asRecord(value) {
|
|
26
|
+
return value && typeof value === "object" ? value : {};
|
|
27
|
+
}
|
|
28
|
+
function toDiffProvenance(value) {
|
|
29
|
+
const p = asRecord(value);
|
|
30
|
+
return {
|
|
31
|
+
version: typeof p.version === "number" ? p.version : null,
|
|
32
|
+
lift: typeof p.lift === "string" ? p.lift : null,
|
|
33
|
+
contentHash: typeof p.contentHash === "string" ? p.contentHash : "",
|
|
34
|
+
promotedAt: typeof p.promotedAt === "string" ? p.promotedAt : ""
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function normalizeCertifiedProfile(raw) {
|
|
38
|
+
const r = asRecord(raw);
|
|
39
|
+
const promptSurface = r.promptSurface ? r.promptSurface : null;
|
|
40
|
+
const artifacts = r.artifacts ?? {};
|
|
41
|
+
const agentProfileDiffs = Array.isArray(r.agentProfileDiffs) ? r.agentProfileDiffs.map((entry) => {
|
|
42
|
+
const e = asRecord(entry);
|
|
43
|
+
return { diff: e.diff, provenance: toDiffProvenance(e.provenance) };
|
|
44
|
+
}) : [];
|
|
45
|
+
const capabilities = Array.isArray(r.capabilities) ? r.capabilities : [];
|
|
46
|
+
return {
|
|
47
|
+
target: typeof r.target === "string" ? r.target : "",
|
|
48
|
+
generatedAt: typeof r.generatedAt === "string" ? r.generatedAt : "",
|
|
49
|
+
promptSurface,
|
|
50
|
+
artifacts,
|
|
51
|
+
agentProfileDiffs,
|
|
52
|
+
capabilities,
|
|
53
|
+
agentProfile: r.agentProfile ?? null
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async function pullCertified(opts) {
|
|
57
|
+
const doFetch = opts.fetchImpl ?? globalThis.fetch;
|
|
58
|
+
if (!doFetch) return { succeeded: false, error: "no fetch implementation available" };
|
|
59
|
+
const apiKey = resolveApiKey(opts.apiKey);
|
|
60
|
+
if (!apiKey) return { succeeded: false, error: "no apiKey (set TANGLE_API_KEY or opts.apiKey)" };
|
|
61
|
+
const baseUrl = resolveIntelligenceBaseUrl(opts.baseUrl);
|
|
62
|
+
const url = `${baseUrl}/v1/profiles/${encodeURIComponent(opts.target)}/composed`;
|
|
63
|
+
let res;
|
|
64
|
+
try {
|
|
65
|
+
res = await doFetch(url, {
|
|
66
|
+
headers: { authorization: `Bearer ${apiKey}` },
|
|
67
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? defaultPullTimeoutMs)
|
|
68
|
+
});
|
|
69
|
+
} catch (err) {
|
|
70
|
+
return {
|
|
71
|
+
succeeded: false,
|
|
72
|
+
error: `pull request failed: ${err instanceof Error ? err.message : String(err)}`
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (res.status === 404) {
|
|
76
|
+
return {
|
|
77
|
+
succeeded: false,
|
|
78
|
+
error: "no certified artifacts promoted for target yet",
|
|
79
|
+
status: 404
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (!res.ok) {
|
|
83
|
+
const body = await res.text().catch(() => "");
|
|
84
|
+
return {
|
|
85
|
+
succeeded: false,
|
|
86
|
+
error: `pull ${res.status}: ${body.slice(0, 200)}`,
|
|
87
|
+
status: res.status
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
return { succeeded: true, value: normalizeCertifiedProfile(await res.json()) };
|
|
92
|
+
} catch (err) {
|
|
93
|
+
return {
|
|
94
|
+
succeeded: false,
|
|
95
|
+
error: `pull response parse failed: ${err instanceof Error ? err.message : String(err)}`
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
var promptFoldTypes = ["prompt-surface", "skill", "instructions"];
|
|
100
|
+
function composeCertifiedPrompt(base, certified) {
|
|
101
|
+
if (!certified) return base;
|
|
102
|
+
const parts = [];
|
|
103
|
+
if (certified.promptSurface?.surface.trim()) parts.push(certified.promptSurface.surface.trim());
|
|
104
|
+
for (const type of promptFoldTypes) {
|
|
105
|
+
const bucket = certified.artifacts[type] ?? [];
|
|
106
|
+
for (const a of [...bucket].sort((x, y) => (x.path ?? "").localeCompare(y.path ?? ""))) {
|
|
107
|
+
if (a.content.trim()) parts.push(a.content.trim());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (parts.length === 0) return base;
|
|
111
|
+
return `${base.trim()}
|
|
112
|
+
|
|
113
|
+
## Certified guidance (Tangle Intelligence)
|
|
114
|
+
|
|
115
|
+
${parts.join("\n\n")}`;
|
|
116
|
+
}
|
|
117
|
+
function createCertifiedPromptSource(opts) {
|
|
118
|
+
const refreshMs = opts.refreshMs ?? defaultRefreshMs;
|
|
119
|
+
let certified = null;
|
|
120
|
+
let lastPullAt = 0;
|
|
121
|
+
let inflight = null;
|
|
122
|
+
async function refresh() {
|
|
123
|
+
if (Date.now() - lastPullAt < refreshMs) return;
|
|
124
|
+
if (inflight) return inflight;
|
|
125
|
+
inflight = (async () => {
|
|
126
|
+
const outcome = await pullCertified(opts);
|
|
127
|
+
lastPullAt = Date.now();
|
|
128
|
+
if (outcome.succeeded) certified = outcome.value;
|
|
129
|
+
})();
|
|
130
|
+
try {
|
|
131
|
+
await inflight;
|
|
132
|
+
} finally {
|
|
133
|
+
inflight = null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
refresh,
|
|
138
|
+
current: () => certified,
|
|
139
|
+
async compose(base) {
|
|
140
|
+
await refresh();
|
|
141
|
+
return composeCertifiedPrompt(base, certified);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
8
146
|
// src/intelligence/effort.ts
|
|
9
147
|
var presets = {
|
|
10
148
|
off: {
|
|
@@ -247,142 +385,6 @@ function isJsonSchema(v) {
|
|
|
247
385
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
248
386
|
}
|
|
249
387
|
|
|
250
|
-
// src/intelligence/delivery.ts
|
|
251
|
-
var defaultPlaneBaseUrl = "https://intelligence.tangle.tools";
|
|
252
|
-
var defaultRefreshMs = 3e5;
|
|
253
|
-
var defaultPullTimeoutMs = 1e4;
|
|
254
|
-
function resolvePlaneBaseUrl(baseUrl) {
|
|
255
|
-
if (baseUrl) return baseUrl.replace(/\/+$/, "");
|
|
256
|
-
if (typeof process !== "undefined" && process.env.TANGLE_INTELLIGENCE_URL) {
|
|
257
|
-
return process.env.TANGLE_INTELLIGENCE_URL.replace(/\/+$/, "");
|
|
258
|
-
}
|
|
259
|
-
return defaultPlaneBaseUrl;
|
|
260
|
-
}
|
|
261
|
-
function resolveApiKey(apiKey) {
|
|
262
|
-
if (apiKey) return apiKey;
|
|
263
|
-
if (typeof process !== "undefined" && process.env.TANGLE_API_KEY)
|
|
264
|
-
return process.env.TANGLE_API_KEY;
|
|
265
|
-
return "";
|
|
266
|
-
}
|
|
267
|
-
async function pullCertified(opts) {
|
|
268
|
-
const doFetch = opts.fetchImpl ?? globalThis.fetch;
|
|
269
|
-
if (!doFetch) return { succeeded: false, error: "no fetch implementation available" };
|
|
270
|
-
const apiKey = resolveApiKey(opts.apiKey);
|
|
271
|
-
if (!apiKey) return { succeeded: false, error: "no apiKey (set TANGLE_API_KEY or opts.apiKey)" };
|
|
272
|
-
const baseUrl = resolvePlaneBaseUrl(opts.baseUrl);
|
|
273
|
-
const url = `${baseUrl}/v1/profiles/${encodeURIComponent(opts.target)}/composed`;
|
|
274
|
-
let res;
|
|
275
|
-
try {
|
|
276
|
-
res = await doFetch(url, {
|
|
277
|
-
headers: { authorization: `Bearer ${apiKey}` },
|
|
278
|
-
signal: AbortSignal.timeout(opts.timeoutMs ?? defaultPullTimeoutMs)
|
|
279
|
-
});
|
|
280
|
-
} catch (err) {
|
|
281
|
-
return {
|
|
282
|
-
succeeded: false,
|
|
283
|
-
error: `pull request failed: ${err instanceof Error ? err.message : String(err)}`
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
if (res.status === 404) {
|
|
287
|
-
return {
|
|
288
|
-
succeeded: false,
|
|
289
|
-
error: "no certified artifacts promoted for target yet",
|
|
290
|
-
status: 404
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
if (!res.ok) {
|
|
294
|
-
const body = await res.text().catch(() => "");
|
|
295
|
-
return {
|
|
296
|
-
succeeded: false,
|
|
297
|
-
error: `pull ${res.status}: ${body.slice(0, 200)}`,
|
|
298
|
-
status: res.status
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
try {
|
|
302
|
-
return { succeeded: true, value: await res.json() };
|
|
303
|
-
} catch (err) {
|
|
304
|
-
return {
|
|
305
|
-
succeeded: false,
|
|
306
|
-
error: `pull response parse failed: ${err instanceof Error ? err.message : String(err)}`
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
var promptFoldTypes = ["prompt-surface", "skill", "instructions"];
|
|
311
|
-
function composeCertifiedPrompt(base, certified) {
|
|
312
|
-
if (!certified) return base;
|
|
313
|
-
const parts = [];
|
|
314
|
-
if (certified.promptSurface?.surface.trim()) parts.push(certified.promptSurface.surface.trim());
|
|
315
|
-
for (const type of promptFoldTypes) {
|
|
316
|
-
const bucket = certified.artifacts[type] ?? [];
|
|
317
|
-
for (const a of [...bucket].sort((x, y) => (x.path ?? "").localeCompare(y.path ?? ""))) {
|
|
318
|
-
if (a.content.trim()) parts.push(a.content.trim());
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
if (parts.length === 0) return base;
|
|
322
|
-
return `${base.trim()}
|
|
323
|
-
|
|
324
|
-
## Certified guidance (Tangle Intelligence)
|
|
325
|
-
|
|
326
|
-
${parts.join("\n\n")}`;
|
|
327
|
-
}
|
|
328
|
-
function createCertifiedPromptSource(opts) {
|
|
329
|
-
const refreshMs = opts.refreshMs ?? defaultRefreshMs;
|
|
330
|
-
let certified = null;
|
|
331
|
-
let lastPullAt = 0;
|
|
332
|
-
let inflight = null;
|
|
333
|
-
async function refresh() {
|
|
334
|
-
if (Date.now() - lastPullAt < refreshMs) return;
|
|
335
|
-
if (inflight) return inflight;
|
|
336
|
-
inflight = (async () => {
|
|
337
|
-
const outcome = await pullCertified(opts);
|
|
338
|
-
lastPullAt = Date.now();
|
|
339
|
-
if (outcome.succeeded) certified = outcome.value;
|
|
340
|
-
})();
|
|
341
|
-
try {
|
|
342
|
-
await inflight;
|
|
343
|
-
} finally {
|
|
344
|
-
inflight = null;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return {
|
|
348
|
-
refresh,
|
|
349
|
-
current: () => certified,
|
|
350
|
-
async compose(base) {
|
|
351
|
-
await refresh();
|
|
352
|
-
return composeCertifiedPrompt(base, certified);
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
function withCertifiedDelivery(agent, config) {
|
|
357
|
-
const client = createIntelligenceClient(config);
|
|
358
|
-
const source = createCertifiedPromptSource({
|
|
359
|
-
target: config.target ?? config.project,
|
|
360
|
-
...config.apiKey !== void 0 ? { apiKey: config.apiKey } : {},
|
|
361
|
-
...config.baseUrl !== void 0 ? { baseUrl: config.baseUrl } : {},
|
|
362
|
-
...config.timeoutMs !== void 0 ? { timeoutMs: config.timeoutMs } : {},
|
|
363
|
-
...config.fetchImpl !== void 0 ? { fetchImpl: config.fetchImpl } : {},
|
|
364
|
-
...config.refreshMs !== void 0 ? { refreshMs: config.refreshMs } : {}
|
|
365
|
-
});
|
|
366
|
-
const wrapped = (async (input) => {
|
|
367
|
-
await source.refresh();
|
|
368
|
-
const certified = source.current();
|
|
369
|
-
const applied = {
|
|
370
|
-
certified,
|
|
371
|
-
composePrompt: (base) => composeCertifiedPrompt(base, certified)
|
|
372
|
-
};
|
|
373
|
-
return client.traceRun(
|
|
374
|
-
{ input, labels: { "tangle.certified_version": certified?.promptSurface?.version ?? -1 } },
|
|
375
|
-
async (trace) => {
|
|
376
|
-
const out = await agent(input, applied);
|
|
377
|
-
trace.recordOutput(out);
|
|
378
|
-
return out;
|
|
379
|
-
}
|
|
380
|
-
);
|
|
381
|
-
});
|
|
382
|
-
wrapped.refresh = source.refresh;
|
|
383
|
-
return wrapped;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
388
|
// src/intelligence/resolver.ts
|
|
387
389
|
function emptyAccumulator() {
|
|
388
390
|
return {
|
|
@@ -415,8 +417,6 @@ async function composeCertifiedProfile(base, manifest, ctx = {}) {
|
|
|
415
417
|
await driftDropTools(acc, ctx);
|
|
416
418
|
const promptAdditions = collectPromptAdditions(manifest.promptSurface, acc.contextArtifacts);
|
|
417
419
|
const systemPrompt = composeCertifiedPrompt(base.systemPrompt, {
|
|
418
|
-
target: manifest.target,
|
|
419
|
-
generatedAt: manifest.generatedAt,
|
|
420
420
|
promptSurface: manifest.promptSurface,
|
|
421
421
|
artifacts: acc.contextArtifacts
|
|
422
422
|
});
|
|
@@ -445,8 +445,6 @@ async function composeCertifiedProfile(base, manifest, ctx = {}) {
|
|
|
445
445
|
}
|
|
446
446
|
function baseSurface(systemPrompt, promptSurface) {
|
|
447
447
|
const folded = composeCertifiedPrompt(systemPrompt, {
|
|
448
|
-
target: "",
|
|
449
|
-
generatedAt: "",
|
|
450
448
|
promptSurface,
|
|
451
449
|
artifacts: {}
|
|
452
450
|
});
|
|
@@ -762,17 +760,80 @@ async function composeCertifiedProfileFromWire(base, profile, ctx = {}) {
|
|
|
762
760
|
return composeCertifiedProfile(base, manifestFromProfile(profile), ctx);
|
|
763
761
|
}
|
|
764
762
|
|
|
763
|
+
// src/intelligence/with-intelligence.ts
|
|
764
|
+
import { applyAgentProfileDiff } from "@tangle-network/agent-interface";
|
|
765
|
+
function withIntelligence(agent, config) {
|
|
766
|
+
const client = createIntelligenceClient(config);
|
|
767
|
+
const target = config.target ?? config.project;
|
|
768
|
+
const source = createCertifiedPromptSource({
|
|
769
|
+
target,
|
|
770
|
+
...config.apiKey !== void 0 ? { apiKey: config.apiKey } : {},
|
|
771
|
+
...config.baseUrl !== void 0 ? { baseUrl: config.baseUrl } : {},
|
|
772
|
+
...config.timeoutMs !== void 0 ? { timeoutMs: config.timeoutMs } : {},
|
|
773
|
+
...config.fetchImpl !== void 0 ? { fetchImpl: config.fetchImpl } : {},
|
|
774
|
+
...config.refreshMs !== void 0 ? { refreshMs: config.refreshMs } : {}
|
|
775
|
+
});
|
|
776
|
+
const currentProposals = () => source.current()?.agentProfileDiffs ?? [];
|
|
777
|
+
let lastSignal = "";
|
|
778
|
+
function signalProposals() {
|
|
779
|
+
const proposals = currentProposals();
|
|
780
|
+
if (proposals.length === 0) return;
|
|
781
|
+
const sig = proposals.map((p) => p.provenance.contentHash).join("|");
|
|
782
|
+
if (sig === lastSignal) return;
|
|
783
|
+
lastSignal = sig;
|
|
784
|
+
config.onProposals?.(proposals);
|
|
785
|
+
}
|
|
786
|
+
async function refresh() {
|
|
787
|
+
await source.refresh();
|
|
788
|
+
signalProposals();
|
|
789
|
+
}
|
|
790
|
+
const wrapped = (async (input) => {
|
|
791
|
+
await refresh();
|
|
792
|
+
const certified = source.current();
|
|
793
|
+
const proposals = currentProposals();
|
|
794
|
+
const report = {};
|
|
795
|
+
const applied = {
|
|
796
|
+
certified,
|
|
797
|
+
composePrompt: (base) => composeCertifiedPrompt(base, certified),
|
|
798
|
+
proposals,
|
|
799
|
+
applyProfile: (base) => proposals.reduce((profile, p) => applyAgentProfileDiff(profile, p.diff), base),
|
|
800
|
+
record: (r) => Object.assign(report, r)
|
|
801
|
+
};
|
|
802
|
+
const output = await agent(input, applied);
|
|
803
|
+
const usage = {
|
|
804
|
+
inferenceUsd: report.usage?.inferenceUsd ?? report.costUsd ?? 0,
|
|
805
|
+
intelligenceUsd: report.usage?.intelligenceUsd ?? 0
|
|
806
|
+
};
|
|
807
|
+
const record = {
|
|
808
|
+
runId: client.freshRunId(),
|
|
809
|
+
traceId: client.freshTraceId(),
|
|
810
|
+
project: config.project,
|
|
811
|
+
target,
|
|
812
|
+
input,
|
|
813
|
+
output,
|
|
814
|
+
outcome: {
|
|
815
|
+
...report.success !== void 0 ? { success: report.success } : {},
|
|
816
|
+
...report.score !== void 0 ? { score: report.score } : {},
|
|
817
|
+
usage
|
|
818
|
+
},
|
|
819
|
+
...report.model !== void 0 ? { model: report.model } : {},
|
|
820
|
+
...report.provider !== void 0 ? { provider: report.provider } : {},
|
|
821
|
+
...report.loopEvents !== void 0 ? { loopEvents: report.loopEvents } : {}
|
|
822
|
+
};
|
|
823
|
+
client.exportRunRecord(record);
|
|
824
|
+
return output;
|
|
825
|
+
});
|
|
826
|
+
wrapped.refresh = refresh;
|
|
827
|
+
wrapped.proposals = currentProposals;
|
|
828
|
+
return wrapped;
|
|
829
|
+
}
|
|
830
|
+
|
|
765
831
|
// src/intelligence/index.ts
|
|
766
832
|
function resolveEffortConfig(effort) {
|
|
767
833
|
if (effort === void 0) return resolveEffort(defaultEffortTier);
|
|
768
834
|
if (typeof effort === "string") return resolveEffort(effort);
|
|
769
835
|
return resolveEffort(effort.tier, effort.overrides);
|
|
770
836
|
}
|
|
771
|
-
function resolveEndpoint(endpoint) {
|
|
772
|
-
if (endpoint) return endpoint;
|
|
773
|
-
if (typeof process === "undefined") return void 0;
|
|
774
|
-
return process.env.INTELLIGENCE_OTLP_ENDPOINT ?? process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
775
|
-
}
|
|
776
837
|
function freshTraceId() {
|
|
777
838
|
return randomHex(32);
|
|
778
839
|
}
|
|
@@ -809,16 +870,16 @@ function createIntelligenceClient(config) {
|
|
|
809
870
|
const intelligenceOff = isIntelligenceOff(effort);
|
|
810
871
|
const redactor = resolveRedactor(config.redact);
|
|
811
872
|
const apiKey = config.apiKey ?? (typeof process !== "undefined" ? process.env.TANGLE_API_KEY : void 0);
|
|
812
|
-
const
|
|
873
|
+
const otlpEndpoint = `${resolveIntelligenceBaseUrl(config.baseUrl)}/v1/otlp`;
|
|
813
874
|
let exporter;
|
|
814
875
|
let exporterResolved = false;
|
|
815
876
|
function getExporter() {
|
|
816
877
|
if (exporterResolved) return exporter;
|
|
817
878
|
exporterResolved = true;
|
|
818
|
-
if (!
|
|
879
|
+
if (!apiKey) return void 0;
|
|
819
880
|
exporter = createOtelExporter({
|
|
820
|
-
endpoint,
|
|
821
|
-
headers:
|
|
881
|
+
endpoint: otlpEndpoint,
|
|
882
|
+
headers: { authorization: `Bearer ${apiKey}` },
|
|
822
883
|
serviceName: config.project,
|
|
823
884
|
resourceAttributes: { "tangle.project": config.project }
|
|
824
885
|
});
|
|
@@ -854,9 +915,51 @@ function createIntelligenceClient(config) {
|
|
|
854
915
|
} catch {
|
|
855
916
|
}
|
|
856
917
|
}
|
|
918
|
+
function exportRunRecord(record) {
|
|
919
|
+
const ex = getExporter();
|
|
920
|
+
if (!ex) return record.traceId;
|
|
921
|
+
const intelligenceUsd = intelligenceOff ? 0 : record.outcome.usage.intelligenceUsd;
|
|
922
|
+
const labels = {
|
|
923
|
+
project: record.project,
|
|
924
|
+
"tangle.target": record.target,
|
|
925
|
+
"tangle.effort.intelligence_off": intelligenceOff,
|
|
926
|
+
"tangle.usage.inference_usd": record.outcome.usage.inferenceUsd,
|
|
927
|
+
"tangle.usage.intelligence_usd": intelligenceUsd,
|
|
928
|
+
...record.model ? { "gen_ai.request.model": record.model } : {},
|
|
929
|
+
...record.provider ? { "provider.name": record.provider } : {},
|
|
930
|
+
...typeof record.outcome.success === "boolean" ? { "tangle.outcome.success": record.outcome.success } : {},
|
|
931
|
+
...typeof record.outcome.score === "number" ? { "tangle.outcome.score": record.outcome.score } : {}
|
|
932
|
+
};
|
|
933
|
+
const redactedInput = record.input !== void 0 ? redactor(record.input) : void 0;
|
|
934
|
+
const redactedOutput = record.output !== void 0 ? redactor(record.output) : void 0;
|
|
935
|
+
if (redactedInput !== void 0) labels["tangle.input"] = previewJson(redactedInput);
|
|
936
|
+
if (redactedOutput !== void 0) labels["tangle.output"] = previewJson(redactedOutput);
|
|
937
|
+
try {
|
|
938
|
+
const runSpan = flatOtelSpan(
|
|
939
|
+
"tangle.intelligence.run",
|
|
940
|
+
{ "tangle.runId": record.runId, ...labels },
|
|
941
|
+
record.traceId,
|
|
942
|
+
Date.now()
|
|
943
|
+
);
|
|
944
|
+
ex.exportSpan(runSpan);
|
|
945
|
+
if (record.loopEvents && record.loopEvents.length > 0) {
|
|
946
|
+
const spans = buildLoopOtelSpans(
|
|
947
|
+
record.loopEvents,
|
|
948
|
+
record.traceId,
|
|
949
|
+
runSpan.spanId
|
|
950
|
+
);
|
|
951
|
+
for (const span of spans) ex.exportSpan(span);
|
|
952
|
+
}
|
|
953
|
+
} catch {
|
|
954
|
+
}
|
|
955
|
+
return record.traceId;
|
|
956
|
+
}
|
|
857
957
|
return {
|
|
858
958
|
project: config.project,
|
|
859
959
|
effort,
|
|
960
|
+
exportRunRecord,
|
|
961
|
+
freshRunId,
|
|
962
|
+
freshTraceId,
|
|
860
963
|
async traceRun(meta, fn) {
|
|
861
964
|
const runId = meta.runId ?? freshRunId();
|
|
862
965
|
const traceId = meta.traceId ?? freshTraceId();
|
|
@@ -926,7 +1029,9 @@ function createIntelligenceClient(config) {
|
|
|
926
1029
|
return {
|
|
927
1030
|
project: config.project,
|
|
928
1031
|
effort,
|
|
929
|
-
|
|
1032
|
+
// Send ships only with a tenant key — the honest "will export actually
|
|
1033
|
+
// land" signal (the base URL always resolves to the plane default).
|
|
1034
|
+
exportConfigured: Boolean(apiKey),
|
|
930
1035
|
modes: {
|
|
931
1036
|
observe: { ready: true, missing: [] },
|
|
932
1037
|
recommend: {
|
|
@@ -947,19 +1052,6 @@ function createIntelligenceClient(config) {
|
|
|
947
1052
|
}
|
|
948
1053
|
};
|
|
949
1054
|
}
|
|
950
|
-
function isClient(value) {
|
|
951
|
-
return typeof value.traceRun === "function";
|
|
952
|
-
}
|
|
953
|
-
function withTangleIntelligence(agent, clientOrConfig) {
|
|
954
|
-
const client = isClient(clientOrConfig) ? clientOrConfig : createIntelligenceClient(clientOrConfig);
|
|
955
|
-
return async (input) => {
|
|
956
|
-
return client.traceRun({ input }, async (trace) => {
|
|
957
|
-
const output = await agent(input);
|
|
958
|
-
trace.recordOutput(output);
|
|
959
|
-
return output;
|
|
960
|
-
});
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
1055
|
export {
|
|
964
1056
|
CapabilityNotAdmittedError,
|
|
965
1057
|
compileEffort,
|
|
@@ -972,10 +1064,11 @@ export {
|
|
|
972
1064
|
defaultRedactor,
|
|
973
1065
|
isIntelligenceOff,
|
|
974
1066
|
manifestFromProfile,
|
|
1067
|
+
normalizeCertifiedProfile,
|
|
975
1068
|
pullCertified,
|
|
976
1069
|
resolveEffort,
|
|
1070
|
+
resolveIntelligenceBaseUrl,
|
|
977
1071
|
resolveRedactor,
|
|
978
|
-
|
|
979
|
-
withTangleIntelligence
|
|
1072
|
+
withIntelligence
|
|
980
1073
|
};
|
|
981
1074
|
//# sourceMappingURL=intelligence.js.map
|