@opperai/agents 0.6.0 → 0.7.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/index.cjs +57 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +57 -19
- 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.0"};
|
|
1659
1660
|
|
|
1660
1661
|
// src/utils/version.ts
|
|
1661
1662
|
var SDK_NAME = "@opperai/agents";
|
|
@@ -2165,6 +2166,30 @@ var Agent = class extends BaseAgent {
|
|
|
2165
2166
|
}
|
|
2166
2167
|
return String(input);
|
|
2167
2168
|
}
|
|
2169
|
+
queueSpanUpdate(context, update) {
|
|
2170
|
+
context.pendingSpanUpdates.push(update);
|
|
2171
|
+
}
|
|
2172
|
+
async flushPendingSpanUpdates(context) {
|
|
2173
|
+
const updates = context.pendingSpanUpdates.splice(
|
|
2174
|
+
0,
|
|
2175
|
+
context.pendingSpanUpdates.length
|
|
2176
|
+
);
|
|
2177
|
+
if (updates.length === 0) {
|
|
2178
|
+
return;
|
|
2179
|
+
}
|
|
2180
|
+
await Promise.allSettled(
|
|
2181
|
+
updates.map((update) => {
|
|
2182
|
+
const options = {
|
|
2183
|
+
...update.error !== void 0 && { error: update.error },
|
|
2184
|
+
...update.startTime && { startTime: update.startTime },
|
|
2185
|
+
...update.endTime && { endTime: update.endTime },
|
|
2186
|
+
...update.meta && { meta: update.meta },
|
|
2187
|
+
...update.name && { name: update.name }
|
|
2188
|
+
};
|
|
2189
|
+
return this.opperClient.updateSpan(update.spanId, update.output, options);
|
|
2190
|
+
})
|
|
2191
|
+
);
|
|
2192
|
+
}
|
|
2168
2193
|
/**
|
|
2169
2194
|
* Main agent loop: think → tool execution → memory handling → repeat until complete
|
|
2170
2195
|
*/
|
|
@@ -2226,7 +2251,9 @@ var Agent = class extends BaseAgent {
|
|
|
2226
2251
|
}
|
|
2227
2252
|
}
|
|
2228
2253
|
const executionEndTime2 = /* @__PURE__ */ new Date();
|
|
2229
|
-
|
|
2254
|
+
this.queueSpanUpdate(context, {
|
|
2255
|
+
spanId: parentSpan.id,
|
|
2256
|
+
output: finalResult,
|
|
2230
2257
|
startTime: executionStartTime,
|
|
2231
2258
|
endTime: executionEndTime2,
|
|
2232
2259
|
meta: {
|
|
@@ -2281,7 +2308,9 @@ var Agent = class extends BaseAgent {
|
|
|
2281
2308
|
}
|
|
2282
2309
|
const result = await this.generateFinalResult(input, context);
|
|
2283
2310
|
const executionEndTime = /* @__PURE__ */ new Date();
|
|
2284
|
-
|
|
2311
|
+
this.queueSpanUpdate(context, {
|
|
2312
|
+
spanId: parentSpan.id,
|
|
2313
|
+
output: result,
|
|
2285
2314
|
startTime: executionStartTime,
|
|
2286
2315
|
endTime: executionEndTime,
|
|
2287
2316
|
meta: {
|
|
@@ -2291,7 +2320,8 @@ var Agent = class extends BaseAgent {
|
|
|
2291
2320
|
return result;
|
|
2292
2321
|
} catch (error) {
|
|
2293
2322
|
const executionEndTime = /* @__PURE__ */ new Date();
|
|
2294
|
-
|
|
2323
|
+
this.queueSpanUpdate(context, {
|
|
2324
|
+
spanId: parentSpan.id,
|
|
2295
2325
|
error: error instanceof Error ? error.message : String(error),
|
|
2296
2326
|
startTime: executionStartTime,
|
|
2297
2327
|
endTime: executionEndTime,
|
|
@@ -2300,6 +2330,8 @@ var Agent = class extends BaseAgent {
|
|
|
2300
2330
|
}
|
|
2301
2331
|
});
|
|
2302
2332
|
throw error;
|
|
2333
|
+
} finally {
|
|
2334
|
+
await this.flushPendingSpanUpdates(context);
|
|
2303
2335
|
}
|
|
2304
2336
|
}
|
|
2305
2337
|
/**
|
|
@@ -2343,7 +2375,8 @@ var Agent = class extends BaseAgent {
|
|
|
2343
2375
|
response
|
|
2344
2376
|
});
|
|
2345
2377
|
if (response.spanId) {
|
|
2346
|
-
|
|
2378
|
+
this.queueSpanUpdate(context, {
|
|
2379
|
+
spanId: response.spanId,
|
|
2347
2380
|
name: "think"
|
|
2348
2381
|
});
|
|
2349
2382
|
}
|
|
@@ -2454,7 +2487,8 @@ var Agent = class extends BaseAgent {
|
|
|
2454
2487
|
parsed: decision
|
|
2455
2488
|
});
|
|
2456
2489
|
if (streamSpanId) {
|
|
2457
|
-
|
|
2490
|
+
this.queueSpanUpdate(context, {
|
|
2491
|
+
spanId: streamSpanId,
|
|
2458
2492
|
name: "think"
|
|
2459
2493
|
});
|
|
2460
2494
|
}
|
|
@@ -2640,13 +2674,16 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2640
2674
|
const endTime = /* @__PURE__ */ new Date();
|
|
2641
2675
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2642
2676
|
if (result.success) {
|
|
2643
|
-
|
|
2677
|
+
this.queueSpanUpdate(context, {
|
|
2678
|
+
spanId: toolSpan.id,
|
|
2679
|
+
output: result.output,
|
|
2644
2680
|
startTime,
|
|
2645
2681
|
endTime,
|
|
2646
2682
|
meta: { durationMs }
|
|
2647
2683
|
});
|
|
2648
2684
|
} else {
|
|
2649
|
-
|
|
2685
|
+
this.queueSpanUpdate(context, {
|
|
2686
|
+
spanId: toolSpan.id,
|
|
2650
2687
|
error: result.error instanceof Error ? result.error.message : String(result.error),
|
|
2651
2688
|
startTime,
|
|
2652
2689
|
endTime,
|
|
@@ -2672,7 +2709,8 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2672
2709
|
} catch (error) {
|
|
2673
2710
|
const endTime = /* @__PURE__ */ new Date();
|
|
2674
2711
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2675
|
-
|
|
2712
|
+
this.queueSpanUpdate(context, {
|
|
2713
|
+
spanId: toolSpan.id,
|
|
2676
2714
|
error: error instanceof Error ? error.message : String(error),
|
|
2677
2715
|
startTime,
|
|
2678
2716
|
endTime,
|
|
@@ -2733,7 +2771,9 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2733
2771
|
const memoryData = await this.memory.read(keys);
|
|
2734
2772
|
const endTime = /* @__PURE__ */ new Date();
|
|
2735
2773
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2736
|
-
|
|
2774
|
+
this.queueSpanUpdate(context, {
|
|
2775
|
+
spanId: memoryReadSpan.id,
|
|
2776
|
+
output: memoryData,
|
|
2737
2777
|
startTime,
|
|
2738
2778
|
endTime,
|
|
2739
2779
|
meta: { durationMs }
|
|
@@ -2800,15 +2840,13 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2800
2840
|
}
|
|
2801
2841
|
const endTime = /* @__PURE__ */ new Date();
|
|
2802
2842
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2803
|
-
|
|
2804
|
-
memoryWriteSpan.id,
|
|
2805
|
-
`Successfully wrote ${updateEntries.length} keys`,
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
}
|
|
2811
|
-
);
|
|
2843
|
+
this.queueSpanUpdate(context, {
|
|
2844
|
+
spanId: memoryWriteSpan.id,
|
|
2845
|
+
output: `Successfully wrote ${updateEntries.length} keys`,
|
|
2846
|
+
startTime,
|
|
2847
|
+
endTime,
|
|
2848
|
+
meta: { durationMs }
|
|
2849
|
+
});
|
|
2812
2850
|
this.log(`Wrote ${updateEntries.length} memory entries`);
|
|
2813
2851
|
summaries.push(
|
|
2814
2852
|
ToolExecutionSummarySchema.parse({
|