llmist 10.2.1 → 10.3.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 +37 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +37 -78
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -8356,12 +8356,10 @@ var init_stream_processor = __esm({
|
|
|
8356
8356
|
endPrefix: options.gadgetEndPrefix,
|
|
8357
8357
|
argPrefix: options.gadgetArgPrefix
|
|
8358
8358
|
});
|
|
8359
|
-
const
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
});
|
|
8364
|
-
options.onSubagentEvent?.(event);
|
|
8359
|
+
const onSubagentEvent = options.onSubagentEvent;
|
|
8360
|
+
const wrappedOnSubagentEvent = onSubagentEvent ? (event) => {
|
|
8361
|
+
onSubagentEvent(event);
|
|
8362
|
+
this.completedResultsQueue.push({ type: "subagent_event", subagentEvent: event });
|
|
8365
8363
|
} : void 0;
|
|
8366
8364
|
this.executor = new GadgetExecutor(
|
|
8367
8365
|
options.registry,
|
|
@@ -9191,11 +9189,16 @@ var init_agent = __esm({
|
|
|
9191
9189
|
// Subagent configuration
|
|
9192
9190
|
agentContextConfig;
|
|
9193
9191
|
subagentConfig;
|
|
9194
|
-
|
|
9192
|
+
/**
|
|
9193
|
+
* User-provided callback for subagent events (from withSubagentEventHandler).
|
|
9194
|
+
* Called synchronously before events are queued for streaming.
|
|
9195
|
+
*/
|
|
9195
9196
|
userSubagentEventCallback;
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9197
|
+
/**
|
|
9198
|
+
* Internal callback passed to StreamProcessor.
|
|
9199
|
+
* StreamProcessor wraps this to: (1) call userSubagentEventCallback, then (2) queue for streaming.
|
|
9200
|
+
* @see StreamProcessor.wrappedOnSubagentEvent for the unified event streaming architecture.
|
|
9201
|
+
*/
|
|
9199
9202
|
onSubagentEvent;
|
|
9200
9203
|
// Counter for generating synthetic invocation IDs for wrapped text content
|
|
9201
9204
|
syntheticInvocationCounter = 0;
|
|
@@ -9289,73 +9292,9 @@ var init_agent = __esm({
|
|
|
9289
9292
|
this.baseDepth = options.baseDepth ?? 0;
|
|
9290
9293
|
this.userSubagentEventCallback = options.onSubagentEvent;
|
|
9291
9294
|
this.onSubagentEvent = (event) => {
|
|
9292
|
-
this.pendingSubagentEvents.push(event);
|
|
9293
9295
|
this.userSubagentEventCallback?.(event);
|
|
9294
|
-
const subagentContext = {
|
|
9295
|
-
parentGadgetInvocationId: event.gadgetInvocationId,
|
|
9296
|
-
depth: event.depth
|
|
9297
|
-
};
|
|
9298
|
-
if (event.type === "llm_call_start") {
|
|
9299
|
-
const info = event.event;
|
|
9300
|
-
void this.hooks?.observers?.onLLMCallStart?.({
|
|
9301
|
-
iteration: info.iteration,
|
|
9302
|
-
options: { model: info.model, messages: [] },
|
|
9303
|
-
logger: this.logger,
|
|
9304
|
-
subagentContext
|
|
9305
|
-
});
|
|
9306
|
-
} else if (event.type === "llm_call_end") {
|
|
9307
|
-
const info = event.event;
|
|
9308
|
-
const usage = info.usage ?? (info.outputTokens ? {
|
|
9309
|
-
inputTokens: info.inputTokens ?? 0,
|
|
9310
|
-
outputTokens: info.outputTokens,
|
|
9311
|
-
totalTokens: (info.inputTokens ?? 0) + info.outputTokens
|
|
9312
|
-
} : void 0);
|
|
9313
|
-
void this.hooks?.observers?.onLLMCallComplete?.({
|
|
9314
|
-
iteration: info.iteration,
|
|
9315
|
-
options: { model: info.model, messages: [] },
|
|
9316
|
-
finishReason: info.finishReason ?? null,
|
|
9317
|
-
usage,
|
|
9318
|
-
rawResponse: "",
|
|
9319
|
-
finalMessage: "",
|
|
9320
|
-
logger: this.logger,
|
|
9321
|
-
subagentContext
|
|
9322
|
-
});
|
|
9323
|
-
} else if (event.type === "gadget_call") {
|
|
9324
|
-
const gadgetEvent = event.event;
|
|
9325
|
-
void this.hooks?.observers?.onGadgetExecutionStart?.({
|
|
9326
|
-
iteration: 0,
|
|
9327
|
-
gadgetName: gadgetEvent.call.gadgetName,
|
|
9328
|
-
invocationId: gadgetEvent.call.invocationId,
|
|
9329
|
-
parameters: gadgetEvent.call.parameters ?? {},
|
|
9330
|
-
logger: this.logger,
|
|
9331
|
-
subagentContext
|
|
9332
|
-
});
|
|
9333
|
-
} else if (event.type === "gadget_result") {
|
|
9334
|
-
const resultEvent = event.event;
|
|
9335
|
-
void this.hooks?.observers?.onGadgetExecutionComplete?.({
|
|
9336
|
-
iteration: 0,
|
|
9337
|
-
gadgetName: resultEvent.result.gadgetName ?? "unknown",
|
|
9338
|
-
invocationId: resultEvent.result.invocationId,
|
|
9339
|
-
parameters: {},
|
|
9340
|
-
executionTimeMs: resultEvent.result.executionTimeMs ?? 0,
|
|
9341
|
-
logger: this.logger,
|
|
9342
|
-
subagentContext
|
|
9343
|
-
});
|
|
9344
|
-
}
|
|
9345
9296
|
};
|
|
9346
9297
|
}
|
|
9347
|
-
/**
|
|
9348
|
-
* Flush pending subagent events as StreamEvents.
|
|
9349
|
-
* Called from run() to yield queued subagent events from subagent gadgets.
|
|
9350
|
-
*/
|
|
9351
|
-
*flushPendingSubagentEvents() {
|
|
9352
|
-
while (this.pendingSubagentEvents.length > 0) {
|
|
9353
|
-
const event = this.pendingSubagentEvents.shift();
|
|
9354
|
-
if (event) {
|
|
9355
|
-
yield { type: "subagent_event", subagentEvent: event };
|
|
9356
|
-
}
|
|
9357
|
-
}
|
|
9358
|
-
}
|
|
9359
9298
|
/**
|
|
9360
9299
|
* Get the gadget registry for this agent.
|
|
9361
9300
|
*
|
|
@@ -9632,7 +9571,6 @@ var init_agent = __esm({
|
|
|
9632
9571
|
gadgetResults.push(event);
|
|
9633
9572
|
}
|
|
9634
9573
|
yield event;
|
|
9635
|
-
yield* this.flushPendingSubagentEvents();
|
|
9636
9574
|
}
|
|
9637
9575
|
if (!streamMetadata) {
|
|
9638
9576
|
throw new Error("Stream processing completed without metadata event");
|
|
@@ -10794,7 +10732,14 @@ var init_builder = __esm({
|
|
|
10794
10732
|
observers: {
|
|
10795
10733
|
...existingHooks.observers,
|
|
10796
10734
|
onLLMCallStart: async (info) => {
|
|
10797
|
-
|
|
10735
|
+
const infoWithSubagent = {
|
|
10736
|
+
...info,
|
|
10737
|
+
subagentContext: {
|
|
10738
|
+
parentGadgetInvocationId: invocationId,
|
|
10739
|
+
depth
|
|
10740
|
+
}
|
|
10741
|
+
};
|
|
10742
|
+
await existingHooks.observers?.onLLMCallStart?.(infoWithSubagent);
|
|
10798
10743
|
ctx.onSubagentEvent({
|
|
10799
10744
|
type: "llm_call_start",
|
|
10800
10745
|
event: {
|
|
@@ -10807,7 +10752,14 @@ var init_builder = __esm({
|
|
|
10807
10752
|
});
|
|
10808
10753
|
},
|
|
10809
10754
|
onGadgetExecutionStart: async (gadgetCtx) => {
|
|
10810
|
-
|
|
10755
|
+
const ctxWithSubagent = {
|
|
10756
|
+
...gadgetCtx,
|
|
10757
|
+
subagentContext: {
|
|
10758
|
+
parentGadgetInvocationId: invocationId,
|
|
10759
|
+
depth
|
|
10760
|
+
}
|
|
10761
|
+
};
|
|
10762
|
+
await existingHooks.observers?.onGadgetExecutionStart?.(ctxWithSubagent);
|
|
10811
10763
|
ctx.onSubagentEvent({
|
|
10812
10764
|
type: "gadget_call",
|
|
10813
10765
|
event: {
|
|
@@ -10825,7 +10777,14 @@ var init_builder = __esm({
|
|
|
10825
10777
|
});
|
|
10826
10778
|
},
|
|
10827
10779
|
onLLMCallComplete: async (info) => {
|
|
10828
|
-
|
|
10780
|
+
const infoWithSubagent = {
|
|
10781
|
+
...info,
|
|
10782
|
+
subagentContext: {
|
|
10783
|
+
parentGadgetInvocationId: invocationId,
|
|
10784
|
+
depth
|
|
10785
|
+
}
|
|
10786
|
+
};
|
|
10787
|
+
await existingHooks.observers?.onLLMCallComplete?.(infoWithSubagent);
|
|
10829
10788
|
ctx.onSubagentEvent({
|
|
10830
10789
|
type: "llm_call_end",
|
|
10831
10790
|
event: {
|