@opperai/agents 0.6.0 → 0.7.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/index.cjs +61 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -703
- package/dist/index.d.ts +66 -703
- package/dist/index.js +61 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -263,6 +263,7 @@ var init_context = __esm({
|
|
|
263
263
|
metadata;
|
|
264
264
|
startedAt;
|
|
265
265
|
updatedAt;
|
|
266
|
+
pendingSpanUpdates = [];
|
|
266
267
|
constructor(options) {
|
|
267
268
|
const now = Date.now();
|
|
268
269
|
this.agentName = options.agentName;
|
|
@@ -1655,7 +1656,7 @@ var mergeSchemaDefaults = (schema, value) => {
|
|
|
1655
1656
|
|
|
1656
1657
|
// package.json
|
|
1657
1658
|
var package_default = {
|
|
1658
|
-
version: "0.
|
|
1659
|
+
version: "0.7.1"};
|
|
1659
1660
|
|
|
1660
1661
|
// src/utils/version.ts
|
|
1661
1662
|
var SDK_NAME = "@opperai/agents";
|
|
@@ -1691,7 +1692,8 @@ var extractCost = (response) => {
|
|
|
1691
1692
|
};
|
|
1692
1693
|
};
|
|
1693
1694
|
var DEFAULT_RETRY_CONFIG = {
|
|
1694
|
-
maxRetries:
|
|
1695
|
+
maxRetries: 0,
|
|
1696
|
+
// Retries are handled in the opper-node sdk
|
|
1695
1697
|
initialDelayMs: 1e3,
|
|
1696
1698
|
backoffMultiplier: 2,
|
|
1697
1699
|
maxDelayMs: 1e4
|
|
@@ -1704,7 +1706,8 @@ var OpperClient = class {
|
|
|
1704
1706
|
this.client = new opperai.Opper({
|
|
1705
1707
|
httpBearer: apiKey ?? process.env["OPPER_HTTP_BEARER"] ?? "",
|
|
1706
1708
|
userAgent: getUserAgent(),
|
|
1707
|
-
...options.baseUrl && { serverURL: options.baseUrl }
|
|
1709
|
+
...options.baseUrl && { serverURL: options.baseUrl },
|
|
1710
|
+
retryConfig: { strategy: "backoff" }
|
|
1708
1711
|
});
|
|
1709
1712
|
this.logger = options.logger ?? getDefaultLogger();
|
|
1710
1713
|
this.retryConfig = {
|
|
@@ -2165,6 +2168,30 @@ var Agent = class extends BaseAgent {
|
|
|
2165
2168
|
}
|
|
2166
2169
|
return String(input);
|
|
2167
2170
|
}
|
|
2171
|
+
queueSpanUpdate(context, update) {
|
|
2172
|
+
context.pendingSpanUpdates.push(update);
|
|
2173
|
+
}
|
|
2174
|
+
async flushPendingSpanUpdates(context) {
|
|
2175
|
+
const updates = context.pendingSpanUpdates.splice(
|
|
2176
|
+
0,
|
|
2177
|
+
context.pendingSpanUpdates.length
|
|
2178
|
+
);
|
|
2179
|
+
if (updates.length === 0) {
|
|
2180
|
+
return;
|
|
2181
|
+
}
|
|
2182
|
+
await Promise.allSettled(
|
|
2183
|
+
updates.map((update) => {
|
|
2184
|
+
const options = {
|
|
2185
|
+
...update.error !== void 0 && { error: update.error },
|
|
2186
|
+
...update.startTime && { startTime: update.startTime },
|
|
2187
|
+
...update.endTime && { endTime: update.endTime },
|
|
2188
|
+
...update.meta && { meta: update.meta },
|
|
2189
|
+
...update.name && { name: update.name }
|
|
2190
|
+
};
|
|
2191
|
+
return this.opperClient.updateSpan(update.spanId, update.output, options);
|
|
2192
|
+
})
|
|
2193
|
+
);
|
|
2194
|
+
}
|
|
2168
2195
|
/**
|
|
2169
2196
|
* Main agent loop: think → tool execution → memory handling → repeat until complete
|
|
2170
2197
|
*/
|
|
@@ -2226,7 +2253,9 @@ var Agent = class extends BaseAgent {
|
|
|
2226
2253
|
}
|
|
2227
2254
|
}
|
|
2228
2255
|
const executionEndTime2 = /* @__PURE__ */ new Date();
|
|
2229
|
-
|
|
2256
|
+
this.queueSpanUpdate(context, {
|
|
2257
|
+
spanId: parentSpan.id,
|
|
2258
|
+
output: finalResult,
|
|
2230
2259
|
startTime: executionStartTime,
|
|
2231
2260
|
endTime: executionEndTime2,
|
|
2232
2261
|
meta: {
|
|
@@ -2281,7 +2310,9 @@ var Agent = class extends BaseAgent {
|
|
|
2281
2310
|
}
|
|
2282
2311
|
const result = await this.generateFinalResult(input, context);
|
|
2283
2312
|
const executionEndTime = /* @__PURE__ */ new Date();
|
|
2284
|
-
|
|
2313
|
+
this.queueSpanUpdate(context, {
|
|
2314
|
+
spanId: parentSpan.id,
|
|
2315
|
+
output: result,
|
|
2285
2316
|
startTime: executionStartTime,
|
|
2286
2317
|
endTime: executionEndTime,
|
|
2287
2318
|
meta: {
|
|
@@ -2291,7 +2322,8 @@ var Agent = class extends BaseAgent {
|
|
|
2291
2322
|
return result;
|
|
2292
2323
|
} catch (error) {
|
|
2293
2324
|
const executionEndTime = /* @__PURE__ */ new Date();
|
|
2294
|
-
|
|
2325
|
+
this.queueSpanUpdate(context, {
|
|
2326
|
+
spanId: parentSpan.id,
|
|
2295
2327
|
error: error instanceof Error ? error.message : String(error),
|
|
2296
2328
|
startTime: executionStartTime,
|
|
2297
2329
|
endTime: executionEndTime,
|
|
@@ -2300,6 +2332,8 @@ var Agent = class extends BaseAgent {
|
|
|
2300
2332
|
}
|
|
2301
2333
|
});
|
|
2302
2334
|
throw error;
|
|
2335
|
+
} finally {
|
|
2336
|
+
await this.flushPendingSpanUpdates(context);
|
|
2303
2337
|
}
|
|
2304
2338
|
}
|
|
2305
2339
|
/**
|
|
@@ -2343,7 +2377,8 @@ var Agent = class extends BaseAgent {
|
|
|
2343
2377
|
response
|
|
2344
2378
|
});
|
|
2345
2379
|
if (response.spanId) {
|
|
2346
|
-
|
|
2380
|
+
this.queueSpanUpdate(context, {
|
|
2381
|
+
spanId: response.spanId,
|
|
2347
2382
|
name: "think"
|
|
2348
2383
|
});
|
|
2349
2384
|
}
|
|
@@ -2454,7 +2489,8 @@ var Agent = class extends BaseAgent {
|
|
|
2454
2489
|
parsed: decision
|
|
2455
2490
|
});
|
|
2456
2491
|
if (streamSpanId) {
|
|
2457
|
-
|
|
2492
|
+
this.queueSpanUpdate(context, {
|
|
2493
|
+
spanId: streamSpanId,
|
|
2458
2494
|
name: "think"
|
|
2459
2495
|
});
|
|
2460
2496
|
}
|
|
@@ -2640,13 +2676,16 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2640
2676
|
const endTime = /* @__PURE__ */ new Date();
|
|
2641
2677
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2642
2678
|
if (result.success) {
|
|
2643
|
-
|
|
2679
|
+
this.queueSpanUpdate(context, {
|
|
2680
|
+
spanId: toolSpan.id,
|
|
2681
|
+
output: result.output,
|
|
2644
2682
|
startTime,
|
|
2645
2683
|
endTime,
|
|
2646
2684
|
meta: { durationMs }
|
|
2647
2685
|
});
|
|
2648
2686
|
} else {
|
|
2649
|
-
|
|
2687
|
+
this.queueSpanUpdate(context, {
|
|
2688
|
+
spanId: toolSpan.id,
|
|
2650
2689
|
error: result.error instanceof Error ? result.error.message : String(result.error),
|
|
2651
2690
|
startTime,
|
|
2652
2691
|
endTime,
|
|
@@ -2672,7 +2711,8 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2672
2711
|
} catch (error) {
|
|
2673
2712
|
const endTime = /* @__PURE__ */ new Date();
|
|
2674
2713
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2675
|
-
|
|
2714
|
+
this.queueSpanUpdate(context, {
|
|
2715
|
+
spanId: toolSpan.id,
|
|
2676
2716
|
error: error instanceof Error ? error.message : String(error),
|
|
2677
2717
|
startTime,
|
|
2678
2718
|
endTime,
|
|
@@ -2733,7 +2773,9 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2733
2773
|
const memoryData = await this.memory.read(keys);
|
|
2734
2774
|
const endTime = /* @__PURE__ */ new Date();
|
|
2735
2775
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2736
|
-
|
|
2776
|
+
this.queueSpanUpdate(context, {
|
|
2777
|
+
spanId: memoryReadSpan.id,
|
|
2778
|
+
output: memoryData,
|
|
2737
2779
|
startTime,
|
|
2738
2780
|
endTime,
|
|
2739
2781
|
meta: { durationMs }
|
|
@@ -2800,15 +2842,13 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2800
2842
|
}
|
|
2801
2843
|
const endTime = /* @__PURE__ */ new Date();
|
|
2802
2844
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2803
|
-
|
|
2804
|
-
memoryWriteSpan.id,
|
|
2805
|
-
`Successfully wrote ${updateEntries.length} keys`,
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
}
|
|
2811
|
-
);
|
|
2845
|
+
this.queueSpanUpdate(context, {
|
|
2846
|
+
spanId: memoryWriteSpan.id,
|
|
2847
|
+
output: `Successfully wrote ${updateEntries.length} keys`,
|
|
2848
|
+
startTime,
|
|
2849
|
+
endTime,
|
|
2850
|
+
meta: { durationMs }
|
|
2851
|
+
});
|
|
2812
2852
|
this.log(`Wrote ${updateEntries.length} memory entries`);
|
|
2813
2853
|
summaries.push(
|
|
2814
2854
|
ToolExecutionSummarySchema.parse({
|