@anvia/core 0.14.0 → 0.16.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/index.d.ts +14 -13
- package/dist/agent/index.js +6 -6
- package/dist/{agent-ib2-Ahyi.d.ts → agent-BTiQ4RZn.d.ts} +17 -8
- package/dist/audio-generation/index.d.ts +1 -1
- package/dist/{chunk-CESSRJYD.js → chunk-3PRP2DV4.js} +6 -6
- package/dist/chunk-3PRP2DV4.js.map +1 -0
- package/dist/{chunk-YQF7QOCO.js → chunk-3QG4SFH4.js} +8 -5
- package/dist/chunk-3QG4SFH4.js.map +1 -0
- package/dist/{chunk-2XD7Z7NB.js → chunk-4PMAWIGM.js} +2 -2
- package/dist/chunk-4PMAWIGM.js.map +1 -0
- package/dist/{chunk-FBHF7WZJ.js → chunk-A7AYX6BD.js} +16 -5
- package/dist/chunk-A7AYX6BD.js.map +1 -0
- package/dist/{chunk-X2Q3AXFM.js → chunk-IT426VXL.js} +2 -2
- package/dist/{chunk-HHHNMP3V.js → chunk-K72JKDZ7.js} +16 -4
- package/dist/chunk-K72JKDZ7.js.map +1 -0
- package/dist/{chunk-BOJP4ARV.js → chunk-PJCJ45RJ.js} +142 -24
- package/dist/chunk-PJCJ45RJ.js.map +1 -0
- package/dist/{chunk-HU55YP24.js → chunk-R6QERZAB.js} +33 -2
- package/dist/chunk-R6QERZAB.js.map +1 -0
- package/dist/completion/index.d.ts +6 -5
- package/dist/completion/index.js +4 -2
- package/dist/evals/index.d.ts +8 -8
- package/dist/evals/index.js +7 -7
- package/dist/extractor/index.d.ts +8 -8
- package/dist/extractor/index.js +7 -7
- package/dist/guardrails/index.d.ts +1 -1
- package/dist/hooks/index.d.ts +3 -3
- package/dist/image-generation/index.d.ts +1 -1
- package/dist/{index-AK084cvC.d.ts → index-Du1vCw6J.d.ts} +46 -6
- package/dist/index.d.ts +12 -12
- package/dist/index.js +10 -8
- package/dist/internal/agent.d.ts +8 -8
- package/dist/internal/agent.js +5 -5
- package/dist/{json-k5r34q-F.d.ts → json-D_Ijo4lJ.d.ts} +2 -2
- package/dist/loaders/index.d.ts +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/memory/index.d.ts +3 -3
- package/dist/{middleware-C6ZuwXjf.d.ts → middleware-CsxdqqjJ.d.ts} +3 -3
- package/dist/observability/index.d.ts +3 -3
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +8 -8
- package/dist/request/index.d.ts +8 -8
- package/dist/request/index.js +4 -4
- package/dist/skills/index.d.ts +4 -4
- package/dist/skills/index.js +2 -2
- package/dist/{think-tool-D3_K8NJa.d.ts → think-tool-BTFFKn1m.d.ts} +1 -1
- package/dist/tool/index.d.ts +5 -5
- package/dist/tool/index.js +2 -2
- package/dist/{tool-DyC_XPPY.d.ts → tool-sKozRXMI.d.ts} +2 -1
- package/dist/transcription/index.d.ts +1 -1
- package/dist/{types-DBd1zAyo.d.ts → types-BT1n5oU4.d.ts} +1 -1
- package/dist/{types-D1iyZY9M.d.ts → types-BkTDw00d.d.ts} +1 -1
- package/dist/{types-CqlNB5VN.d.ts → types-CHFrSm-3.d.ts} +1 -1
- package/dist/{types-VadeVz_w.d.ts → types-DMQ8JEf8.d.ts} +1 -1
- package/dist/{types-BySyFZTT.d.ts → types-nybevqL9.d.ts} +43 -1
- package/dist/{types-t_DnP78R.d.ts → types-yf-Exga_.d.ts} +2 -2
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +2 -2
- package/dist/vector-store/index.d.ts +4 -4
- package/package.json +1 -1
- package/dist/chunk-2XD7Z7NB.js.map +0 -1
- package/dist/chunk-BOJP4ARV.js.map +0 -1
- package/dist/chunk-CESSRJYD.js.map +0 -1
- package/dist/chunk-FBHF7WZJ.js.map +0 -1
- package/dist/chunk-HHHNMP3V.js.map +0 -1
- package/dist/chunk-HU55YP24.js.map +0 -1
- package/dist/chunk-YQF7QOCO.js.map +0 -1
- /package/dist/{chunk-X2Q3AXFM.js.map → chunk-IT426VXL.js.map} +0 -0
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
parseToolArgs,
|
|
6
6
|
toolResultContentToText
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4PMAWIGM.js";
|
|
8
8
|
import {
|
|
9
9
|
runControl,
|
|
10
10
|
toolCallControl
|
|
@@ -12,15 +12,16 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
CompletionRequestBuilder,
|
|
14
14
|
isStreamingCompletionModel
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-K72JKDZ7.js";
|
|
16
16
|
import {
|
|
17
17
|
AssistantContent,
|
|
18
18
|
Message,
|
|
19
19
|
ToolContent,
|
|
20
20
|
Usage,
|
|
21
21
|
assertCompletionRequestSupported,
|
|
22
|
+
getAssistantGenerationMetadata,
|
|
22
23
|
textFromAssistantContent
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-R6QERZAB.js";
|
|
24
25
|
import {
|
|
25
26
|
mapWithConcurrency
|
|
26
27
|
} from "./chunk-OIMLU4SF.js";
|
|
@@ -293,6 +294,8 @@ var CompletionStreamAccumulator = class {
|
|
|
293
294
|
reasoningByKey = /* @__PURE__ */ new Map();
|
|
294
295
|
reasoningKeyById = /* @__PURE__ */ new Map();
|
|
295
296
|
toolCalls = /* @__PURE__ */ new Map();
|
|
297
|
+
sources = /* @__PURE__ */ new Map();
|
|
298
|
+
providerToolCalls = /* @__PURE__ */ new Map();
|
|
296
299
|
finalResponse;
|
|
297
300
|
messageId;
|
|
298
301
|
nextTextKey = 0;
|
|
@@ -313,7 +316,11 @@ var CompletionStreamAccumulator = class {
|
|
|
313
316
|
if (event.name !== void 0 && event.name.length > 0) toolCall.name = event.name;
|
|
314
317
|
if (event.signature !== void 0) toolCall.signature = event.signature;
|
|
315
318
|
if (event.argumentsDelta !== void 0) {
|
|
316
|
-
|
|
319
|
+
if (event.argumentsMode === "replace") {
|
|
320
|
+
toolCall.argumentsText = event.argumentsDelta;
|
|
321
|
+
} else {
|
|
322
|
+
toolCall.argumentsText += event.argumentsDelta;
|
|
323
|
+
}
|
|
317
324
|
}
|
|
318
325
|
return void 0;
|
|
319
326
|
}
|
|
@@ -321,6 +328,14 @@ var CompletionStreamAccumulator = class {
|
|
|
321
328
|
this.upsertToolCall(event.toolCall);
|
|
322
329
|
return { type: "tool_call", toolCall: event.toolCall };
|
|
323
330
|
}
|
|
331
|
+
if (event.type === "source") {
|
|
332
|
+
this.sources.set(sourceKey(event.source), event.source);
|
|
333
|
+
return { type: "source", source: event.source };
|
|
334
|
+
}
|
|
335
|
+
if (event.type === "provider_tool_call") {
|
|
336
|
+
this.providerToolCalls.set(event.toolCall.id, event.toolCall);
|
|
337
|
+
return { type: "provider_tool_call", toolCall: event.toolCall };
|
|
338
|
+
}
|
|
324
339
|
if (event.type === "message_id") {
|
|
325
340
|
this.messageId = event.id;
|
|
326
341
|
return void 0;
|
|
@@ -335,7 +350,7 @@ var CompletionStreamAccumulator = class {
|
|
|
335
350
|
const accumulatedResponse = this.buildAccumulatedResponse();
|
|
336
351
|
if (this.finalResponse !== void 0) {
|
|
337
352
|
if (accumulatedResponse.choice.length === 0) {
|
|
338
|
-
return this.
|
|
353
|
+
return this.withAccumulatedArtifacts(this.finalResponse, accumulatedResponse);
|
|
339
354
|
}
|
|
340
355
|
return this.mergeFinalResponse(accumulatedResponse, this.finalResponse);
|
|
341
356
|
}
|
|
@@ -373,6 +388,14 @@ var CompletionStreamAccumulator = class {
|
|
|
373
388
|
if (this.messageId !== void 0) {
|
|
374
389
|
response.messageId = this.messageId;
|
|
375
390
|
}
|
|
391
|
+
const sources = [...this.sources.values()];
|
|
392
|
+
if (sources.length > 0) {
|
|
393
|
+
response.sources = sources;
|
|
394
|
+
}
|
|
395
|
+
const providerToolCalls = [...this.providerToolCalls.values()];
|
|
396
|
+
if (providerToolCalls.length > 0) {
|
|
397
|
+
response.providerToolCalls = providerToolCalls;
|
|
398
|
+
}
|
|
376
399
|
return response;
|
|
377
400
|
}
|
|
378
401
|
upsertToolCall(toolCall) {
|
|
@@ -405,7 +428,7 @@ var CompletionStreamAccumulator = class {
|
|
|
405
428
|
if (finalResponse.messageId !== void 0) {
|
|
406
429
|
mergedResponse.messageId = finalResponse.messageId;
|
|
407
430
|
}
|
|
408
|
-
return this.
|
|
431
|
+
return this.withAccumulatedArtifacts(mergedResponse, accumulatedResponse);
|
|
409
432
|
}
|
|
410
433
|
const finalById = /* @__PURE__ */ new Map();
|
|
411
434
|
const finalByCallId = /* @__PURE__ */ new Map();
|
|
@@ -438,7 +461,7 @@ var CompletionStreamAccumulator = class {
|
|
|
438
461
|
choice.push(content);
|
|
439
462
|
}
|
|
440
463
|
}
|
|
441
|
-
return this.
|
|
464
|
+
return this.withAccumulatedArtifacts({ ...finalResponse, choice }, accumulatedResponse);
|
|
442
465
|
}
|
|
443
466
|
appendText(delta) {
|
|
444
467
|
const lastPart = this.orderedParts.at(-1);
|
|
@@ -497,6 +520,19 @@ var CompletionStreamAccumulator = class {
|
|
|
497
520
|
}
|
|
498
521
|
return { ...response, messageId: accumulatedResponse.messageId };
|
|
499
522
|
}
|
|
523
|
+
withAccumulatedArtifacts(response, accumulatedResponse) {
|
|
524
|
+
const withMessageId = this.withMessageIdFallback(response, accumulatedResponse);
|
|
525
|
+
const sources = mergeSources(accumulatedResponse.sources, response.sources);
|
|
526
|
+
const providerToolCalls = mergeProviderToolCalls(
|
|
527
|
+
accumulatedResponse.providerToolCalls,
|
|
528
|
+
response.providerToolCalls
|
|
529
|
+
);
|
|
530
|
+
return {
|
|
531
|
+
...withMessageId,
|
|
532
|
+
...sources.length === 0 ? {} : { sources },
|
|
533
|
+
...providerToolCalls.length === 0 ? {} : { providerToolCalls }
|
|
534
|
+
};
|
|
535
|
+
}
|
|
500
536
|
createTextKey() {
|
|
501
537
|
this.nextTextKey += 1;
|
|
502
538
|
return `text_${this.nextTextKey.toString()}`;
|
|
@@ -543,6 +579,23 @@ var CompletionStreamAccumulator = class {
|
|
|
543
579
|
reasoning.content.push({ type: "redacted", data: event.delta });
|
|
544
580
|
}
|
|
545
581
|
};
|
|
582
|
+
function sourceKey(source) {
|
|
583
|
+
return `${source.url}\0${source.startIndex ?? ""}\0${source.endIndex ?? ""}`;
|
|
584
|
+
}
|
|
585
|
+
function mergeSources(accumulated, final) {
|
|
586
|
+
const sources = /* @__PURE__ */ new Map();
|
|
587
|
+
for (const source of [...accumulated ?? [], ...final ?? []]) {
|
|
588
|
+
sources.set(sourceKey(source), source);
|
|
589
|
+
}
|
|
590
|
+
return [...sources.values()];
|
|
591
|
+
}
|
|
592
|
+
function mergeProviderToolCalls(accumulated, final) {
|
|
593
|
+
const toolCalls = /* @__PURE__ */ new Map();
|
|
594
|
+
for (const toolCall of [...accumulated ?? [], ...final ?? []]) {
|
|
595
|
+
toolCalls.set(toolCall.id, toolCall);
|
|
596
|
+
}
|
|
597
|
+
return [...toolCalls.values()];
|
|
598
|
+
}
|
|
546
599
|
function reasoningContent(reasoning) {
|
|
547
600
|
const content = reasoning.content === void 0 ? { type: "reasoning", text: reasoning.text } : { type: "reasoning", text: reasoning.text, content: reasoning.content };
|
|
548
601
|
return reasoning.id === void 0 ? content : { ...content, id: reasoning.id };
|
|
@@ -638,22 +691,42 @@ function addTurn(turn, event) {
|
|
|
638
691
|
if (event.signature !== void 0) mapped.signature = event.signature;
|
|
639
692
|
return mapped;
|
|
640
693
|
}
|
|
694
|
+
if (event.type === "source") {
|
|
695
|
+
return { type: "source", turn, source: event.source };
|
|
696
|
+
}
|
|
697
|
+
if (event.type === "provider_tool_call") {
|
|
698
|
+
return { type: "provider_tool_call", turn, toolCall: event.toolCall };
|
|
699
|
+
}
|
|
641
700
|
return { type: "tool_call", turn, toolCall: event.toolCall };
|
|
642
701
|
}
|
|
702
|
+
function addTurnToToolCallDelta(turn, event) {
|
|
703
|
+
const mapped = {
|
|
704
|
+
type: "tool_call_delta",
|
|
705
|
+
turn,
|
|
706
|
+
id: event.id
|
|
707
|
+
};
|
|
708
|
+
if (event.callId !== void 0) mapped.callId = event.callId;
|
|
709
|
+
if (event.name !== void 0) mapped.name = event.name;
|
|
710
|
+
if (event.argumentsDelta !== void 0) mapped.argumentsDelta = event.argumentsDelta;
|
|
711
|
+
if (event.argumentsMode !== void 0) mapped.argumentsMode = event.argumentsMode;
|
|
712
|
+
if (event.signature !== void 0) mapped.signature = event.signature;
|
|
713
|
+
return mapped;
|
|
714
|
+
}
|
|
643
715
|
function isGenerationDeltaEvent(type) {
|
|
644
|
-
return type === "text_delta" || type === "reasoning_delta" || type === "tool_call_delta" || type === "tool_call";
|
|
716
|
+
return type === "text_delta" || type === "reasoning_delta" || type === "tool_call_delta" || type === "tool_call" || type === "source" || type === "provider_tool_call";
|
|
645
717
|
}
|
|
646
718
|
|
|
647
719
|
// src/internal/prompt-runtime/tool-execution.ts
|
|
648
720
|
var MCP_TOOL_METADATA_KEY = /* @__PURE__ */ Symbol.for("anvia.mcp.tool.metadata");
|
|
649
721
|
var ToolCallExecutor = class {
|
|
650
|
-
constructor(agent, activeHook, approvals, runContext, concurrency, requestMiddlewares, cancel) {
|
|
722
|
+
constructor(agent, activeHook, approvals, runContext, concurrency, requestMiddlewares, includeToolCallDeltas, cancel) {
|
|
651
723
|
this.agent = agent;
|
|
652
724
|
this.activeHook = activeHook;
|
|
653
725
|
this.approvals = approvals;
|
|
654
726
|
this.runContext = runContext;
|
|
655
727
|
this.concurrency = concurrency;
|
|
656
728
|
this.requestMiddlewares = requestMiddlewares;
|
|
729
|
+
this.includeToolCallDeltas = includeToolCallDeltas;
|
|
657
730
|
this.cancel = cancel;
|
|
658
731
|
}
|
|
659
732
|
agent;
|
|
@@ -662,6 +735,7 @@ var ToolCallExecutor = class {
|
|
|
662
735
|
runContext;
|
|
663
736
|
concurrency;
|
|
664
737
|
requestMiddlewares;
|
|
738
|
+
includeToolCallDeltas;
|
|
665
739
|
cancel;
|
|
666
740
|
async execute(toolCalls, onResult, onStreamEvent, observation) {
|
|
667
741
|
for (const toolCall of toolCalls) {
|
|
@@ -829,7 +903,7 @@ var ToolCallExecutor = class {
|
|
|
829
903
|
}) : effectiveArgs;
|
|
830
904
|
hookArgs.args = middlewareArgs;
|
|
831
905
|
try {
|
|
832
|
-
|
|
906
|
+
const toolContext = {
|
|
833
907
|
emitStreamEvent: async (event) => {
|
|
834
908
|
const streamEventArgs = {
|
|
835
909
|
turn: observation?.turn ?? 0,
|
|
@@ -848,7 +922,9 @@ var ToolCallExecutor = class {
|
|
|
848
922
|
onStreamEvent?.(payload);
|
|
849
923
|
}
|
|
850
924
|
}
|
|
851
|
-
}
|
|
925
|
+
};
|
|
926
|
+
toolContext.includeToolCallDeltas = this.includeToolCallDeltas;
|
|
927
|
+
return await this.agent.callTool(toolCall.function.name, middlewareArgs, toolContext);
|
|
852
928
|
} catch (error) {
|
|
853
929
|
const errorAction = await this.activeHook?.onToolError?.({
|
|
854
930
|
...hookArgs,
|
|
@@ -1568,7 +1644,7 @@ var PromptRequest = class _PromptRequest {
|
|
|
1568
1644
|
const ragText = extractRagText(prompt);
|
|
1569
1645
|
const dynamicContext = await fetchDynamicContext(this.agent, ragText);
|
|
1570
1646
|
const toolDefs = await fetchToolDefinitions(this.agent, ragText);
|
|
1571
|
-
let request = new CompletionRequestBuilder(this.agent.model, prompt).instructions(this.agent.instructions).messages(historyForRequest).documents([...this.agent.staticContext, ...dynamicContext]).tools(toolDefs).temperature(this.agent.temperature).maxTokens(this.agent.maxTokens).additionalParams(this.agent.additionalParams).toolChoice(this.agent.toolChoice).outputSchema(this.agent.outputSchema).build();
|
|
1647
|
+
let request = new CompletionRequestBuilder(this.agent.model, prompt).instructions(this.agent.instructions).messages(historyForRequest).documents([...this.agent.staticContext, ...dynamicContext]).tools([...toolDefs, ...this.agent.providerTools]).temperature(this.agent.temperature).maxTokens(this.agent.maxTokens).additionalParams(this.agent.additionalParams).toolChoice(this.agent.toolChoice).outputSchema(this.agent.outputSchema).build();
|
|
1572
1648
|
request = await this.runCompletionRequestMiddlewares(
|
|
1573
1649
|
request,
|
|
1574
1650
|
currentTurns
|
|
@@ -1623,7 +1699,8 @@ var PromptRequest = class _PromptRequest {
|
|
|
1623
1699
|
usage,
|
|
1624
1700
|
messages: [...newMessages],
|
|
1625
1701
|
trace: runObservers.trace,
|
|
1626
|
-
guardrails: [...this.guardrailDecisions]
|
|
1702
|
+
guardrails: [...this.guardrailDecisions],
|
|
1703
|
+
...generationArtifacts(newMessages)
|
|
1627
1704
|
};
|
|
1628
1705
|
await this.runRunEndHook(result, newMessages);
|
|
1629
1706
|
await runObservers.end(result);
|
|
@@ -1674,11 +1751,12 @@ var PromptRequest = class _PromptRequest {
|
|
|
1674
1751
|
throw finalError;
|
|
1675
1752
|
}
|
|
1676
1753
|
}
|
|
1677
|
-
async *stream() {
|
|
1754
|
+
async *stream(options = {}) {
|
|
1678
1755
|
if (!this.agent.model.capabilities.streaming || !isStreamingCompletionModel(this.agent.model)) {
|
|
1679
1756
|
throw new Error("This completion model does not support streaming");
|
|
1680
1757
|
}
|
|
1681
1758
|
this.startRun();
|
|
1759
|
+
const includeToolCallDeltas = options.includeToolCallDeltas !== false;
|
|
1682
1760
|
const runId = globalThis.crypto.randomUUID();
|
|
1683
1761
|
const emit = async (event) => {
|
|
1684
1762
|
await this.recordAgentEvent(runId, event);
|
|
@@ -1745,7 +1823,7 @@ var PromptRequest = class _PromptRequest {
|
|
|
1745
1823
|
const ragText = extractRagText(prompt);
|
|
1746
1824
|
const dynamicContext = await fetchDynamicContext(this.agent, ragText);
|
|
1747
1825
|
const toolDefs = await fetchToolDefinitions(this.agent, ragText);
|
|
1748
|
-
let request = new CompletionRequestBuilder(this.agent.model, prompt).instructions(this.agent.instructions).messages(historyForRequest).documents([...this.agent.staticContext, ...dynamicContext]).tools(toolDefs).temperature(this.agent.temperature).maxTokens(this.agent.maxTokens).additionalParams(this.agent.additionalParams).toolChoice(this.agent.toolChoice).outputSchema(this.agent.outputSchema).build();
|
|
1826
|
+
let request = new CompletionRequestBuilder(this.agent.model, prompt).instructions(this.agent.instructions).messages(historyForRequest).documents([...this.agent.staticContext, ...dynamicContext]).tools([...toolDefs, ...this.agent.providerTools]).temperature(this.agent.temperature).maxTokens(this.agent.maxTokens).additionalParams(this.agent.additionalParams).toolChoice(this.agent.toolChoice).outputSchema(this.agent.outputSchema).build();
|
|
1749
1827
|
request = await this.runCompletionRequestMiddlewares(
|
|
1750
1828
|
request,
|
|
1751
1829
|
currentTurns
|
|
@@ -1777,6 +1855,9 @@ var PromptRequest = class _PromptRequest {
|
|
|
1777
1855
|
firstDeltaMs = Date.now() - generationStartedAt;
|
|
1778
1856
|
}
|
|
1779
1857
|
const mapped = accumulator.accept(event);
|
|
1858
|
+
if (includeToolCallDeltas && event.type === "tool_call_delta") {
|
|
1859
|
+
yield await emit(addTurnToToolCallDelta(currentTurns, event));
|
|
1860
|
+
}
|
|
1780
1861
|
if (mapped !== void 0) {
|
|
1781
1862
|
await generationObservers.update?.({ turn: currentTurns, delta: mapped });
|
|
1782
1863
|
if (mapped.type === "tool_call") {
|
|
@@ -1870,7 +1951,11 @@ var PromptRequest = class _PromptRequest {
|
|
|
1870
1951
|
pendingTurnMessages
|
|
1871
1952
|
);
|
|
1872
1953
|
if (!emittedTurnEnd && (bufferResponseEvents || bufferOutputDeltas)) {
|
|
1873
|
-
for (const event of responseStreamEvents(
|
|
1954
|
+
for (const event of responseStreamEvents(
|
|
1955
|
+
currentTurns,
|
|
1956
|
+
response,
|
|
1957
|
+
bufferResponseEvents
|
|
1958
|
+
)) {
|
|
1874
1959
|
yield await emit(event);
|
|
1875
1960
|
}
|
|
1876
1961
|
}
|
|
@@ -1882,7 +1967,8 @@ var PromptRequest = class _PromptRequest {
|
|
|
1882
1967
|
usage,
|
|
1883
1968
|
messages: [...newMessages],
|
|
1884
1969
|
trace: runObservers.trace,
|
|
1885
|
-
guardrails: [...this.guardrailDecisions]
|
|
1970
|
+
guardrails: [...this.guardrailDecisions],
|
|
1971
|
+
...generationArtifacts(newMessages)
|
|
1886
1972
|
};
|
|
1887
1973
|
await this.runRunEndHook(result, newMessages);
|
|
1888
1974
|
await runObservers.end(result);
|
|
@@ -1900,7 +1986,9 @@ var PromptRequest = class _PromptRequest {
|
|
|
1900
1986
|
usage: result.usage,
|
|
1901
1987
|
messages: result.messages,
|
|
1902
1988
|
trace: result.trace,
|
|
1903
|
-
guardrails: result.guardrails
|
|
1989
|
+
guardrails: result.guardrails,
|
|
1990
|
+
sources: result.sources,
|
|
1991
|
+
providerToolCalls: result.providerToolCalls
|
|
1904
1992
|
});
|
|
1905
1993
|
return;
|
|
1906
1994
|
}
|
|
@@ -1936,7 +2024,8 @@ var PromptRequest = class _PromptRequest {
|
|
|
1936
2024
|
{
|
|
1937
2025
|
turn: currentTurns,
|
|
1938
2026
|
runObservers,
|
|
1939
|
-
toolDefinitions: request.tools
|
|
2027
|
+
toolDefinitions: request.tools,
|
|
2028
|
+
includeToolCallDeltas
|
|
1940
2029
|
}
|
|
1941
2030
|
);
|
|
1942
2031
|
toolResultsPromise.then(
|
|
@@ -1973,8 +2062,8 @@ var PromptRequest = class _PromptRequest {
|
|
|
1973
2062
|
throw finalError;
|
|
1974
2063
|
}
|
|
1975
2064
|
}
|
|
1976
|
-
readableStream() {
|
|
1977
|
-
return toReadableStream(this.stream());
|
|
2065
|
+
readableStream(options = {}) {
|
|
2066
|
+
return toReadableStream(this.stream(options));
|
|
1978
2067
|
}
|
|
1979
2068
|
async runCompletion(request, turn, runObservers) {
|
|
1980
2069
|
assertCompletionRequestSupported(this.agent.model, request);
|
|
@@ -2016,7 +2105,9 @@ var PromptRequest = class _PromptRequest {
|
|
|
2016
2105
|
generation: {
|
|
2017
2106
|
provider: this.agent.model.provider,
|
|
2018
2107
|
model: request.model ?? this.agent.model.defaultModel,
|
|
2019
|
-
usage: { ...response.usage }
|
|
2108
|
+
usage: { ...response.usage },
|
|
2109
|
+
...response.sources === void 0 ? {} : { sources: response.sources },
|
|
2110
|
+
...response.providerToolCalls === void 0 ? {} : { providerToolCalls: response.providerToolCalls }
|
|
2020
2111
|
}
|
|
2021
2112
|
}
|
|
2022
2113
|
};
|
|
@@ -2092,6 +2183,7 @@ var PromptRequest = class _PromptRequest {
|
|
|
2092
2183
|
},
|
|
2093
2184
|
this.concurrency,
|
|
2094
2185
|
this.requestMiddlewares,
|
|
2186
|
+
observation?.includeToolCallDeltas ?? false,
|
|
2095
2187
|
(reason) => this.cancelled(newMessages, reason)
|
|
2096
2188
|
);
|
|
2097
2189
|
return executor.execute(toolCalls, onResult, onStreamEvent, observation);
|
|
@@ -2359,7 +2451,7 @@ function normalizeSteeringInput(input) {
|
|
|
2359
2451
|
}
|
|
2360
2452
|
return Array.isArray(input) ? [...input] : [input];
|
|
2361
2453
|
}
|
|
2362
|
-
function responseStreamEvents(turn, response) {
|
|
2454
|
+
function responseStreamEvents(turn, response, includeProviderArtifacts = true) {
|
|
2363
2455
|
const events = [];
|
|
2364
2456
|
for (const item of response.choice) {
|
|
2365
2457
|
if (item.type === "text") {
|
|
@@ -2391,8 +2483,34 @@ function responseStreamEvents(turn, response) {
|
|
|
2391
2483
|
events.push({ type: "tool_call", turn, toolCall: item });
|
|
2392
2484
|
}
|
|
2393
2485
|
}
|
|
2486
|
+
if (includeProviderArtifacts) {
|
|
2487
|
+
for (const source of response.sources ?? []) {
|
|
2488
|
+
events.push({ type: "source", turn, source });
|
|
2489
|
+
}
|
|
2490
|
+
for (const toolCall of response.providerToolCalls ?? []) {
|
|
2491
|
+
events.push({ type: "provider_tool_call", turn, toolCall });
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2394
2494
|
return events;
|
|
2395
2495
|
}
|
|
2496
|
+
function generationArtifacts(messages) {
|
|
2497
|
+
const sources = /* @__PURE__ */ new Map();
|
|
2498
|
+
const providerToolCalls = /* @__PURE__ */ new Map();
|
|
2499
|
+
for (const message of messages) {
|
|
2500
|
+
const metadata = getAssistantGenerationMetadata(message);
|
|
2501
|
+
for (const source of metadata?.sources ?? []) {
|
|
2502
|
+
const key = `${source.url}\0${source.startIndex ?? ""}\0${source.endIndex ?? ""}`;
|
|
2503
|
+
sources.set(key, source);
|
|
2504
|
+
}
|
|
2505
|
+
for (const toolCall of metadata?.providerToolCalls ?? []) {
|
|
2506
|
+
providerToolCalls.set(toolCall.id, toolCall);
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
return {
|
|
2510
|
+
...sources.size === 0 ? {} : { sources: [...sources.values()] },
|
|
2511
|
+
...providerToolCalls.size === 0 ? {} : { providerToolCalls: [...providerToolCalls.values()] }
|
|
2512
|
+
};
|
|
2513
|
+
}
|
|
2396
2514
|
function reasoningDeltaEvent2(turn, delta, details = {}) {
|
|
2397
2515
|
const event = {
|
|
2398
2516
|
type: "reasoning_delta",
|
|
@@ -2450,4 +2568,4 @@ export {
|
|
|
2450
2568
|
extractRagText,
|
|
2451
2569
|
PromptRequest
|
|
2452
2570
|
};
|
|
2453
|
-
//# sourceMappingURL=chunk-
|
|
2571
|
+
//# sourceMappingURL=chunk-PJCJ45RJ.js.map
|