@tangle-network/agent-runtime 0.14.0 → 0.15.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.d.ts +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +120 -17
- package/dist/index.js.map +1 -1
- package/dist/{types-jr_EFhrD.d.ts → types-CYxfw14J.d.ts} +9 -0
- package/package.json +1 -1
package/dist/agent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _tangle_network_agent_eval from '@tangle-network/agent-eval';
|
|
2
2
|
import { FindingSubject, TraceAnalystKindSpec, AnalystFinding, TraceStore, RunCompleteHook, FeedbackLabel, FeedbackTrajectoryStore } from '@tangle-network/agent-eval';
|
|
3
|
-
import { R as RuntimeStreamEvent } from './types-
|
|
3
|
+
import { R as RuntimeStreamEvent } from './types-CYxfw14J.js';
|
|
4
4
|
import { I as ImprovementAdapter, K as KnowledgeAdapter, a as RunAnalystLoopResult } from './types-D_MXrmJP.js';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentEvalError, KnowledgeReadinessReport, ControlEvalResult, KnowledgeRequirement, TraceEvent } from '@tangle-network/agent-eval';
|
|
2
2
|
export { AgentEvalError, AgentEvalErrorCode, CaptureIntegrityError, ConfigError, ControlBudget, ControlDecision, ControlEvalResult, ControlRunResult, ControlStep, DataAcquisitionPlan, JudgeError, KnowledgeReadinessReport, KnowledgeRequirement, NotFoundError, ReplayError, RunRecord, UserQuestion, ValidationError, VerificationError } from '@tangle-network/agent-eval';
|
|
3
|
-
import { A as AgentBackendInput, a as AgentExecutionBackend, b as AgentBackendContext, R as RuntimeStreamEvent, c as AgentTaskSpec, K as KnowledgeReadinessDecision, d as RunAgentTaskOptions, e as AgentTaskRunResult, f as RunAgentTaskStreamOptions, g as AgentTaskRunSummary, h as AgentRuntimeEvent, i as AgentTaskStatus, j as RuntimeSessionStore, k as RuntimeSession } from './types-
|
|
4
|
-
export { l as AgentAdapter, m as AgentKnowledgeProvider, n as AgentRuntimeEventSink, o as AgentTaskContext } from './types-
|
|
3
|
+
import { A as AgentBackendInput, a as AgentExecutionBackend, b as AgentBackendContext, R as RuntimeStreamEvent, c as AgentTaskSpec, K as KnowledgeReadinessDecision, d as RunAgentTaskOptions, e as AgentTaskRunResult, f as RunAgentTaskStreamOptions, g as AgentTaskRunSummary, h as AgentRuntimeEvent, i as AgentTaskStatus, j as RuntimeSessionStore, k as RuntimeSession } from './types-CYxfw14J.js';
|
|
4
|
+
export { l as AgentAdapter, m as AgentKnowledgeProvider, n as AgentRuntimeEventSink, o as AgentTaskContext } from './types-CYxfw14J.js';
|
|
5
5
|
import { AgentProfilePrompt, AgentProfileResources, AgentSubagentProfile, AgentProfile, SandboxInstance } from '@tangle-network/sandbox';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -59,6 +59,14 @@ interface BackendRetryPolicy {
|
|
|
59
59
|
jitter?: number;
|
|
60
60
|
/** Status codes that trigger a retry. Default: 408, 425, 429, 500, 502, 503, 504. */
|
|
61
61
|
retryStatuses?: ReadonlyArray<number>;
|
|
62
|
+
/**
|
|
63
|
+
* Per-attempt wall-clock deadline in ms. If a single fetch attempt does
|
|
64
|
+
* not return headers within this window the attempt is aborted and
|
|
65
|
+
* retried. Default 120000 (2 min). Without this a hung upstream blocks
|
|
66
|
+
* the attempt indefinitely — observed in production as a 15-minute
|
|
67
|
+
* `fetch failed` that burned an entire eval persona. Set to 0 to disable.
|
|
68
|
+
*/
|
|
69
|
+
requestTimeoutMs?: number;
|
|
62
70
|
}
|
|
63
71
|
declare function createOpenAICompatibleBackend<TInput extends AgentBackendInput = AgentBackendInput>(options: {
|
|
64
72
|
apiKey: string;
|
package/dist/index.js
CHANGED
|
@@ -113,6 +113,32 @@ function pickRetryDelayMs(attempt, policy) {
|
|
|
113
113
|
const jitter = capped * policy.jitter * (Math.random() * 2 - 1);
|
|
114
114
|
return Math.max(0, Math.round(capped + jitter));
|
|
115
115
|
}
|
|
116
|
+
function withTimeout(callerSignal, timeoutMs) {
|
|
117
|
+
if (timeoutMs <= 0) {
|
|
118
|
+
return { signal: callerSignal ?? new AbortController().signal, dispose: () => void 0 };
|
|
119
|
+
}
|
|
120
|
+
const controller = new AbortController();
|
|
121
|
+
const timer = setTimeout(
|
|
122
|
+
() => controller.abort(new Error(`request timed out after ${timeoutMs}ms`)),
|
|
123
|
+
timeoutMs
|
|
124
|
+
);
|
|
125
|
+
if (typeof timer.unref === "function") {
|
|
126
|
+
;
|
|
127
|
+
timer.unref();
|
|
128
|
+
}
|
|
129
|
+
const onCallerAbort = () => controller.abort(callerSignal?.reason ?? new Error("aborted"));
|
|
130
|
+
if (callerSignal) {
|
|
131
|
+
if (callerSignal.aborted) onCallerAbort();
|
|
132
|
+
else callerSignal.addEventListener("abort", onCallerAbort, { once: true });
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
signal: controller.signal,
|
|
136
|
+
dispose: () => {
|
|
137
|
+
clearTimeout(timer);
|
|
138
|
+
callerSignal?.removeEventListener("abort", onCallerAbort);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
116
142
|
function sleep(ms, signal) {
|
|
117
143
|
return new Promise((resolve, reject) => {
|
|
118
144
|
if (signal?.aborted) {
|
|
@@ -138,7 +164,8 @@ function createOpenAICompatibleBackend(options) {
|
|
|
138
164
|
initialBackoffMs: options.retry?.initialBackoffMs ?? 1e3,
|
|
139
165
|
maxBackoffMs: options.retry?.maxBackoffMs ?? 3e4,
|
|
140
166
|
jitter: options.retry?.jitter ?? 0.25,
|
|
141
|
-
retryStatuses: options.retry?.retryStatuses ?? DEFAULT_RETRY_STATUSES
|
|
167
|
+
retryStatuses: options.retry?.retryStatuses ?? DEFAULT_RETRY_STATUSES,
|
|
168
|
+
requestTimeoutMs: options.retry?.requestTimeoutMs ?? 12e4
|
|
142
169
|
};
|
|
143
170
|
return {
|
|
144
171
|
kind,
|
|
@@ -146,24 +173,40 @@ function createOpenAICompatibleBackend(options) {
|
|
|
146
173
|
return newRuntimeSession(kind, context.requestedSessionId);
|
|
147
174
|
},
|
|
148
175
|
async *stream(input, context) {
|
|
176
|
+
const url = `${options.baseUrl.replace(/\/$/, "")}/chat/completions`;
|
|
177
|
+
const requestBody = JSON.stringify({
|
|
178
|
+
model: options.model,
|
|
179
|
+
stream: true,
|
|
180
|
+
messages: input.messages ?? [
|
|
181
|
+
{ role: "user", content: input.message ?? context.task.intent }
|
|
182
|
+
]
|
|
183
|
+
});
|
|
149
184
|
let response;
|
|
150
185
|
let lastStatus = 0;
|
|
186
|
+
let lastThrown;
|
|
151
187
|
for (let attempt = 1; attempt <= retryPolicy.maxAttempts; attempt++) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
188
|
+
lastThrown = void 0;
|
|
189
|
+
const attemptSignal = withTimeout(context.signal, retryPolicy.requestTimeoutMs);
|
|
190
|
+
try {
|
|
191
|
+
response = await fetcher(url, {
|
|
192
|
+
method: "POST",
|
|
193
|
+
headers: {
|
|
194
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
195
|
+
"Content-Type": "application/json"
|
|
196
|
+
},
|
|
197
|
+
body: requestBody,
|
|
198
|
+
signal: attemptSignal.signal
|
|
199
|
+
});
|
|
200
|
+
} catch (err) {
|
|
201
|
+
attemptSignal.dispose();
|
|
202
|
+
if (context.signal?.aborted) throw err;
|
|
203
|
+
lastThrown = err;
|
|
204
|
+
response = void 0;
|
|
205
|
+
if (attempt === retryPolicy.maxAttempts) break;
|
|
206
|
+
await sleep(pickRetryDelayMs(attempt, retryPolicy), context.signal);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
attemptSignal.dispose();
|
|
167
210
|
if (response.ok) break;
|
|
168
211
|
lastStatus = response.status;
|
|
169
212
|
if (!retryPolicy.retryStatuses.includes(response.status)) break;
|
|
@@ -175,7 +218,15 @@ function createOpenAICompatibleBackend(options) {
|
|
|
175
218
|
const delayMs = pickRetryDelayMs(attempt, retryPolicy);
|
|
176
219
|
await sleep(delayMs, context.signal);
|
|
177
220
|
}
|
|
178
|
-
if (!response
|
|
221
|
+
if (!response) {
|
|
222
|
+
const reason = lastThrown instanceof Error ? lastThrown.message : String(lastThrown);
|
|
223
|
+
throw new BackendTransportError(
|
|
224
|
+
kind,
|
|
225
|
+
`chat backend unreachable after ${retryPolicy.maxAttempts} attempts: ${reason}`,
|
|
226
|
+
{ status: 0 }
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (!response.ok) {
|
|
179
230
|
throw new BackendTransportError(kind, `chat backend returned ${lastStatus || "unknown"}`, {
|
|
180
231
|
status: lastStatus || 0
|
|
181
232
|
});
|
|
@@ -242,6 +293,36 @@ function mapCommonBackendEvent(event, context) {
|
|
|
242
293
|
timestamp: nowIso()
|
|
243
294
|
};
|
|
244
295
|
}
|
|
296
|
+
if (type === "artifact") {
|
|
297
|
+
const artifactId = stringValue(data.artifactId) ?? stringValue(data.id) ?? stringValue(record.artifactId);
|
|
298
|
+
if (!artifactId) return void 0;
|
|
299
|
+
return {
|
|
300
|
+
type: "artifact",
|
|
301
|
+
task: context.task,
|
|
302
|
+
session: context.session,
|
|
303
|
+
artifactId,
|
|
304
|
+
name: stringValue(data.name) ?? stringValue(record.name),
|
|
305
|
+
mimeType: stringValue(data.mimeType) ?? stringValue(record.mimeType),
|
|
306
|
+
uri: stringValue(data.uri) ?? stringValue(record.uri),
|
|
307
|
+
content: stringValue(data.content) ?? stringValue(data.body) ?? stringValue(record.content),
|
|
308
|
+
metadata: data.metadata && typeof data.metadata === "object" ? data.metadata : void 0,
|
|
309
|
+
timestamp: nowIso()
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (type === "proposal_created" || type === "proposal" || type === "filing") {
|
|
313
|
+
const proposalId = stringValue(data.proposalId) ?? stringValue(data.id) ?? stringValue(record.proposalId);
|
|
314
|
+
if (!proposalId) return void 0;
|
|
315
|
+
const status = stringValue(data.status) ?? stringValue(record.status);
|
|
316
|
+
return {
|
|
317
|
+
type: "proposal_created",
|
|
318
|
+
task: context.task,
|
|
319
|
+
session: context.session,
|
|
320
|
+
proposalId,
|
|
321
|
+
title: stringValue(data.title) ?? stringValue(record.title) ?? proposalId,
|
|
322
|
+
status: status === "pending" || status === "approved" || status === "rejected" ? status : void 0,
|
|
323
|
+
timestamp: nowIso()
|
|
324
|
+
};
|
|
325
|
+
}
|
|
245
326
|
if (type === "result" || type === "final") {
|
|
246
327
|
const text = stringValue(data.finalText) ?? stringValue(data.text) ?? stringValue(record.text);
|
|
247
328
|
return text ? {
|
|
@@ -2675,9 +2756,21 @@ function sanitizeRuntimeStreamEvent(event, options = {}) {
|
|
|
2675
2756
|
name: event.name,
|
|
2676
2757
|
mimeType: event.mimeType,
|
|
2677
2758
|
uri: options.includeEvidenceIds ? event.uri : void 0,
|
|
2759
|
+
content: options.includeControlPayloads ? event.content : void 0,
|
|
2678
2760
|
metadata: options.includeMetadata ? event.metadata : void 0
|
|
2679
2761
|
};
|
|
2680
2762
|
}
|
|
2763
|
+
if (event.type === "proposal_created") {
|
|
2764
|
+
return {
|
|
2765
|
+
type: event.type,
|
|
2766
|
+
...withTask,
|
|
2767
|
+
...withSession,
|
|
2768
|
+
timestamp: event.timestamp,
|
|
2769
|
+
proposalId: event.proposalId,
|
|
2770
|
+
title: options.includeControlPayloads ? event.title : void 0,
|
|
2771
|
+
status: event.status
|
|
2772
|
+
};
|
|
2773
|
+
}
|
|
2681
2774
|
if (event.type === "final") {
|
|
2682
2775
|
return {
|
|
2683
2776
|
type: event.type,
|
|
@@ -3051,6 +3144,16 @@ function projectToTraceEvent(event) {
|
|
|
3051
3144
|
mimeType: event.mimeType
|
|
3052
3145
|
}
|
|
3053
3146
|
};
|
|
3147
|
+
case "proposal_created":
|
|
3148
|
+
return {
|
|
3149
|
+
kind: "state_mutation",
|
|
3150
|
+
payload: {
|
|
3151
|
+
phase: "proposal_created",
|
|
3152
|
+
proposalId: event.proposalId,
|
|
3153
|
+
title: event.title,
|
|
3154
|
+
status: event.status
|
|
3155
|
+
}
|
|
3156
|
+
};
|
|
3054
3157
|
case "task_end":
|
|
3055
3158
|
return {
|
|
3056
3159
|
kind: event.status === "failed" || event.status === "aborted" ? "error" : "log",
|