@opperai/agents 0.5.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 +58 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +288 -235
- package/dist/index.d.ts +288 -235
- package/dist/index.js +58 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -242,6 +242,7 @@ var init_context = __esm({
|
|
|
242
242
|
metadata;
|
|
243
243
|
startedAt;
|
|
244
244
|
updatedAt;
|
|
245
|
+
pendingSpanUpdates = [];
|
|
245
246
|
constructor(options) {
|
|
246
247
|
const now = Date.now();
|
|
247
248
|
this.agentName = options.agentName;
|
|
@@ -1634,7 +1635,7 @@ var mergeSchemaDefaults = (schema, value) => {
|
|
|
1634
1635
|
|
|
1635
1636
|
// package.json
|
|
1636
1637
|
var package_default = {
|
|
1637
|
-
version: "0.
|
|
1638
|
+
version: "0.7.0"};
|
|
1638
1639
|
|
|
1639
1640
|
// src/utils/version.ts
|
|
1640
1641
|
var SDK_NAME = "@opperai/agents";
|
|
@@ -2144,6 +2145,30 @@ var Agent = class extends BaseAgent {
|
|
|
2144
2145
|
}
|
|
2145
2146
|
return String(input);
|
|
2146
2147
|
}
|
|
2148
|
+
queueSpanUpdate(context, update) {
|
|
2149
|
+
context.pendingSpanUpdates.push(update);
|
|
2150
|
+
}
|
|
2151
|
+
async flushPendingSpanUpdates(context) {
|
|
2152
|
+
const updates = context.pendingSpanUpdates.splice(
|
|
2153
|
+
0,
|
|
2154
|
+
context.pendingSpanUpdates.length
|
|
2155
|
+
);
|
|
2156
|
+
if (updates.length === 0) {
|
|
2157
|
+
return;
|
|
2158
|
+
}
|
|
2159
|
+
await Promise.allSettled(
|
|
2160
|
+
updates.map((update) => {
|
|
2161
|
+
const options = {
|
|
2162
|
+
...update.error !== void 0 && { error: update.error },
|
|
2163
|
+
...update.startTime && { startTime: update.startTime },
|
|
2164
|
+
...update.endTime && { endTime: update.endTime },
|
|
2165
|
+
...update.meta && { meta: update.meta },
|
|
2166
|
+
...update.name && { name: update.name }
|
|
2167
|
+
};
|
|
2168
|
+
return this.opperClient.updateSpan(update.spanId, update.output, options);
|
|
2169
|
+
})
|
|
2170
|
+
);
|
|
2171
|
+
}
|
|
2147
2172
|
/**
|
|
2148
2173
|
* Main agent loop: think → tool execution → memory handling → repeat until complete
|
|
2149
2174
|
*/
|
|
@@ -2205,7 +2230,9 @@ var Agent = class extends BaseAgent {
|
|
|
2205
2230
|
}
|
|
2206
2231
|
}
|
|
2207
2232
|
const executionEndTime2 = /* @__PURE__ */ new Date();
|
|
2208
|
-
|
|
2233
|
+
this.queueSpanUpdate(context, {
|
|
2234
|
+
spanId: parentSpan.id,
|
|
2235
|
+
output: finalResult,
|
|
2209
2236
|
startTime: executionStartTime,
|
|
2210
2237
|
endTime: executionEndTime2,
|
|
2211
2238
|
meta: {
|
|
@@ -2260,7 +2287,9 @@ var Agent = class extends BaseAgent {
|
|
|
2260
2287
|
}
|
|
2261
2288
|
const result = await this.generateFinalResult(input, context);
|
|
2262
2289
|
const executionEndTime = /* @__PURE__ */ new Date();
|
|
2263
|
-
|
|
2290
|
+
this.queueSpanUpdate(context, {
|
|
2291
|
+
spanId: parentSpan.id,
|
|
2292
|
+
output: result,
|
|
2264
2293
|
startTime: executionStartTime,
|
|
2265
2294
|
endTime: executionEndTime,
|
|
2266
2295
|
meta: {
|
|
@@ -2270,7 +2299,8 @@ var Agent = class extends BaseAgent {
|
|
|
2270
2299
|
return result;
|
|
2271
2300
|
} catch (error) {
|
|
2272
2301
|
const executionEndTime = /* @__PURE__ */ new Date();
|
|
2273
|
-
|
|
2302
|
+
this.queueSpanUpdate(context, {
|
|
2303
|
+
spanId: parentSpan.id,
|
|
2274
2304
|
error: error instanceof Error ? error.message : String(error),
|
|
2275
2305
|
startTime: executionStartTime,
|
|
2276
2306
|
endTime: executionEndTime,
|
|
@@ -2279,6 +2309,8 @@ var Agent = class extends BaseAgent {
|
|
|
2279
2309
|
}
|
|
2280
2310
|
});
|
|
2281
2311
|
throw error;
|
|
2312
|
+
} finally {
|
|
2313
|
+
await this.flushPendingSpanUpdates(context);
|
|
2282
2314
|
}
|
|
2283
2315
|
}
|
|
2284
2316
|
/**
|
|
@@ -2322,7 +2354,8 @@ var Agent = class extends BaseAgent {
|
|
|
2322
2354
|
response
|
|
2323
2355
|
});
|
|
2324
2356
|
if (response.spanId) {
|
|
2325
|
-
|
|
2357
|
+
this.queueSpanUpdate(context, {
|
|
2358
|
+
spanId: response.spanId,
|
|
2326
2359
|
name: "think"
|
|
2327
2360
|
});
|
|
2328
2361
|
}
|
|
@@ -2433,7 +2466,8 @@ var Agent = class extends BaseAgent {
|
|
|
2433
2466
|
parsed: decision
|
|
2434
2467
|
});
|
|
2435
2468
|
if (streamSpanId) {
|
|
2436
|
-
|
|
2469
|
+
this.queueSpanUpdate(context, {
|
|
2470
|
+
spanId: streamSpanId,
|
|
2437
2471
|
name: "think"
|
|
2438
2472
|
});
|
|
2439
2473
|
}
|
|
@@ -2545,7 +2579,7 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2545
2579
|
};
|
|
2546
2580
|
});
|
|
2547
2581
|
const executionHistory = context.getLastNCycles(3).map((cycle) => {
|
|
2548
|
-
const thought = typeof cycle.thought === "object" && cycle.thought !== null ? cycle.thought
|
|
2582
|
+
const thought = typeof cycle.thought === "object" && cycle.thought !== null ? cycle.thought.reasoning || "" : String(cycle.thought || "");
|
|
2549
2583
|
const results = Array.isArray(cycle.results) ? cycle.results.map((r) => {
|
|
2550
2584
|
const result = r;
|
|
2551
2585
|
let actualOutput = result.output;
|
|
@@ -2619,13 +2653,16 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2619
2653
|
const endTime = /* @__PURE__ */ new Date();
|
|
2620
2654
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2621
2655
|
if (result.success) {
|
|
2622
|
-
|
|
2656
|
+
this.queueSpanUpdate(context, {
|
|
2657
|
+
spanId: toolSpan.id,
|
|
2658
|
+
output: result.output,
|
|
2623
2659
|
startTime,
|
|
2624
2660
|
endTime,
|
|
2625
2661
|
meta: { durationMs }
|
|
2626
2662
|
});
|
|
2627
2663
|
} else {
|
|
2628
|
-
|
|
2664
|
+
this.queueSpanUpdate(context, {
|
|
2665
|
+
spanId: toolSpan.id,
|
|
2629
2666
|
error: result.error instanceof Error ? result.error.message : String(result.error),
|
|
2630
2667
|
startTime,
|
|
2631
2668
|
endTime,
|
|
@@ -2651,7 +2688,8 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2651
2688
|
} catch (error) {
|
|
2652
2689
|
const endTime = /* @__PURE__ */ new Date();
|
|
2653
2690
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2654
|
-
|
|
2691
|
+
this.queueSpanUpdate(context, {
|
|
2692
|
+
spanId: toolSpan.id,
|
|
2655
2693
|
error: error instanceof Error ? error.message : String(error),
|
|
2656
2694
|
startTime,
|
|
2657
2695
|
endTime,
|
|
@@ -2712,7 +2750,9 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2712
2750
|
const memoryData = await this.memory.read(keys);
|
|
2713
2751
|
const endTime = /* @__PURE__ */ new Date();
|
|
2714
2752
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2715
|
-
|
|
2753
|
+
this.queueSpanUpdate(context, {
|
|
2754
|
+
spanId: memoryReadSpan.id,
|
|
2755
|
+
output: memoryData,
|
|
2716
2756
|
startTime,
|
|
2717
2757
|
endTime,
|
|
2718
2758
|
meta: { durationMs }
|
|
@@ -2779,15 +2819,13 @@ The memory you write persists across all process() calls on this agent.`;
|
|
|
2779
2819
|
}
|
|
2780
2820
|
const endTime = /* @__PURE__ */ new Date();
|
|
2781
2821
|
const durationMs = endTime.getTime() - startTime.getTime();
|
|
2782
|
-
|
|
2783
|
-
memoryWriteSpan.id,
|
|
2784
|
-
`Successfully wrote ${updateEntries.length} keys`,
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
}
|
|
2790
|
-
);
|
|
2822
|
+
this.queueSpanUpdate(context, {
|
|
2823
|
+
spanId: memoryWriteSpan.id,
|
|
2824
|
+
output: `Successfully wrote ${updateEntries.length} keys`,
|
|
2825
|
+
startTime,
|
|
2826
|
+
endTime,
|
|
2827
|
+
meta: { durationMs }
|
|
2828
|
+
});
|
|
2791
2829
|
this.log(`Wrote ${updateEntries.length} memory entries`);
|
|
2792
2830
|
summaries.push(
|
|
2793
2831
|
ToolExecutionSummarySchema.parse({
|