@anvia/core 0.15.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.
Files changed (67) hide show
  1. package/dist/agent/index.d.ts +14 -13
  2. package/dist/agent/index.js +6 -6
  3. package/dist/{agent-C1yoidvI.d.ts → agent-BTiQ4RZn.d.ts} +9 -7
  4. package/dist/audio-generation/index.d.ts +1 -1
  5. package/dist/{chunk-BPU264XB.js → chunk-3PRP2DV4.js} +6 -6
  6. package/dist/chunk-3PRP2DV4.js.map +1 -0
  7. package/dist/{chunk-GCZIIYZW.js → chunk-3QG4SFH4.js} +6 -4
  8. package/dist/chunk-3QG4SFH4.js.map +1 -0
  9. package/dist/{chunk-BIYXGG33.js → chunk-4PMAWIGM.js} +2 -2
  10. package/dist/{chunk-7NULHGAO.js → chunk-A7AYX6BD.js} +16 -5
  11. package/dist/chunk-A7AYX6BD.js.map +1 -0
  12. package/dist/{chunk-MEUZ4NBO.js → chunk-IT426VXL.js} +2 -2
  13. package/dist/{chunk-QTZHDPQX.js → chunk-K72JKDZ7.js} +16 -4
  14. package/dist/chunk-K72JKDZ7.js.map +1 -0
  15. package/dist/{chunk-CNANX5OL.js → chunk-PJCJ45RJ.js} +107 -16
  16. package/dist/chunk-PJCJ45RJ.js.map +1 -0
  17. package/dist/{chunk-TIV3WFSR.js → chunk-R6QERZAB.js} +33 -2
  18. package/dist/chunk-R6QERZAB.js.map +1 -0
  19. package/dist/completion/index.d.ts +6 -5
  20. package/dist/completion/index.js +4 -2
  21. package/dist/evals/index.d.ts +8 -8
  22. package/dist/evals/index.js +7 -7
  23. package/dist/extractor/index.d.ts +8 -8
  24. package/dist/extractor/index.js +7 -7
  25. package/dist/guardrails/index.d.ts +1 -1
  26. package/dist/hooks/index.d.ts +3 -3
  27. package/dist/image-generation/index.d.ts +1 -1
  28. package/dist/{index-VH93vDXo.d.ts → index-Du1vCw6J.d.ts} +22 -2
  29. package/dist/index.d.ts +12 -12
  30. package/dist/index.js +10 -8
  31. package/dist/internal/agent.d.ts +8 -8
  32. package/dist/internal/agent.js +5 -5
  33. package/dist/{json-CaCUxJqG.d.ts → json-D_Ijo4lJ.d.ts} +2 -2
  34. package/dist/loaders/index.d.ts +1 -1
  35. package/dist/mcp/index.d.ts +4 -4
  36. package/dist/memory/index.d.ts +3 -3
  37. package/dist/{middleware-CGEYQndv.d.ts → middleware-CsxdqqjJ.d.ts} +3 -3
  38. package/dist/observability/index.d.ts +3 -3
  39. package/dist/observability/index.js.map +1 -1
  40. package/dist/pipeline/index.d.ts +8 -8
  41. package/dist/request/index.d.ts +8 -8
  42. package/dist/request/index.js +4 -4
  43. package/dist/skills/index.d.ts +4 -4
  44. package/dist/skills/index.js +2 -2
  45. package/dist/{think-tool-DABDgW_E.d.ts → think-tool-BTFFKn1m.d.ts} +1 -1
  46. package/dist/tool/index.d.ts +5 -5
  47. package/dist/tool/index.js +2 -2
  48. package/dist/{tool-tHPNeWMR.d.ts → tool-sKozRXMI.d.ts} +1 -1
  49. package/dist/transcription/index.d.ts +1 -1
  50. package/dist/{types-DW1Va3vx.d.ts → types-BT1n5oU4.d.ts} +1 -1
  51. package/dist/{types-BHxJcHMk.d.ts → types-BkTDw00d.d.ts} +1 -1
  52. package/dist/{types-D78Vnorg.d.ts → types-CHFrSm-3.d.ts} +1 -1
  53. package/dist/{types-DPYoqg8M.d.ts → types-DMQ8JEf8.d.ts} +1 -1
  54. package/dist/{types-Byo50mwr.d.ts → types-nybevqL9.d.ts} +41 -1
  55. package/dist/{types-BbLcbRqM.d.ts → types-yf-Exga_.d.ts} +2 -2
  56. package/dist/ui/index.d.ts +1 -1
  57. package/dist/ui/index.js +2 -2
  58. package/dist/vector-store/index.d.ts +4 -4
  59. package/package.json +1 -1
  60. package/dist/chunk-7NULHGAO.js.map +0 -1
  61. package/dist/chunk-BPU264XB.js.map +0 -1
  62. package/dist/chunk-CNANX5OL.js.map +0 -1
  63. package/dist/chunk-GCZIIYZW.js.map +0 -1
  64. package/dist/chunk-QTZHDPQX.js.map +0 -1
  65. package/dist/chunk-TIV3WFSR.js.map +0 -1
  66. /package/dist/{chunk-BIYXGG33.js.map → chunk-4PMAWIGM.js.map} +0 -0
  67. /package/dist/{chunk-MEUZ4NBO.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-BIYXGG33.js";
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-QTZHDPQX.js";
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-TIV3WFSR.js";
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;
@@ -325,6 +328,14 @@ var CompletionStreamAccumulator = class {
325
328
  this.upsertToolCall(event.toolCall);
326
329
  return { type: "tool_call", toolCall: event.toolCall };
327
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
+ }
328
339
  if (event.type === "message_id") {
329
340
  this.messageId = event.id;
330
341
  return void 0;
@@ -339,7 +350,7 @@ var CompletionStreamAccumulator = class {
339
350
  const accumulatedResponse = this.buildAccumulatedResponse();
340
351
  if (this.finalResponse !== void 0) {
341
352
  if (accumulatedResponse.choice.length === 0) {
342
- return this.withMessageIdFallback(this.finalResponse, accumulatedResponse);
353
+ return this.withAccumulatedArtifacts(this.finalResponse, accumulatedResponse);
343
354
  }
344
355
  return this.mergeFinalResponse(accumulatedResponse, this.finalResponse);
345
356
  }
@@ -377,6 +388,14 @@ var CompletionStreamAccumulator = class {
377
388
  if (this.messageId !== void 0) {
378
389
  response.messageId = this.messageId;
379
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
+ }
380
399
  return response;
381
400
  }
382
401
  upsertToolCall(toolCall) {
@@ -409,7 +428,7 @@ var CompletionStreamAccumulator = class {
409
428
  if (finalResponse.messageId !== void 0) {
410
429
  mergedResponse.messageId = finalResponse.messageId;
411
430
  }
412
- return this.withMessageIdFallback(mergedResponse, accumulatedResponse);
431
+ return this.withAccumulatedArtifacts(mergedResponse, accumulatedResponse);
413
432
  }
414
433
  const finalById = /* @__PURE__ */ new Map();
415
434
  const finalByCallId = /* @__PURE__ */ new Map();
@@ -442,7 +461,7 @@ var CompletionStreamAccumulator = class {
442
461
  choice.push(content);
443
462
  }
444
463
  }
445
- return this.withMessageIdFallback({ ...finalResponse, choice }, accumulatedResponse);
464
+ return this.withAccumulatedArtifacts({ ...finalResponse, choice }, accumulatedResponse);
446
465
  }
447
466
  appendText(delta) {
448
467
  const lastPart = this.orderedParts.at(-1);
@@ -501,6 +520,19 @@ var CompletionStreamAccumulator = class {
501
520
  }
502
521
  return { ...response, messageId: accumulatedResponse.messageId };
503
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
+ }
504
536
  createTextKey() {
505
537
  this.nextTextKey += 1;
506
538
  return `text_${this.nextTextKey.toString()}`;
@@ -547,6 +579,23 @@ var CompletionStreamAccumulator = class {
547
579
  reasoning.content.push({ type: "redacted", data: event.delta });
548
580
  }
549
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
+ }
550
599
  function reasoningContent(reasoning) {
551
600
  const content = reasoning.content === void 0 ? { type: "reasoning", text: reasoning.text } : { type: "reasoning", text: reasoning.text, content: reasoning.content };
552
601
  return reasoning.id === void 0 ? content : { ...content, id: reasoning.id };
@@ -642,6 +691,12 @@ function addTurn(turn, event) {
642
691
  if (event.signature !== void 0) mapped.signature = event.signature;
643
692
  return mapped;
644
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
+ }
645
700
  return { type: "tool_call", turn, toolCall: event.toolCall };
646
701
  }
647
702
  function addTurnToToolCallDelta(turn, event) {
@@ -658,7 +713,7 @@ function addTurnToToolCallDelta(turn, event) {
658
713
  return mapped;
659
714
  }
660
715
  function isGenerationDeltaEvent(type) {
661
- 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";
662
717
  }
663
718
 
664
719
  // src/internal/prompt-runtime/tool-execution.ts
@@ -1589,7 +1644,7 @@ var PromptRequest = class _PromptRequest {
1589
1644
  const ragText = extractRagText(prompt);
1590
1645
  const dynamicContext = await fetchDynamicContext(this.agent, ragText);
1591
1646
  const toolDefs = await fetchToolDefinitions(this.agent, ragText);
1592
- 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();
1593
1648
  request = await this.runCompletionRequestMiddlewares(
1594
1649
  request,
1595
1650
  currentTurns
@@ -1644,7 +1699,8 @@ var PromptRequest = class _PromptRequest {
1644
1699
  usage,
1645
1700
  messages: [...newMessages],
1646
1701
  trace: runObservers.trace,
1647
- guardrails: [...this.guardrailDecisions]
1702
+ guardrails: [...this.guardrailDecisions],
1703
+ ...generationArtifacts(newMessages)
1648
1704
  };
1649
1705
  await this.runRunEndHook(result, newMessages);
1650
1706
  await runObservers.end(result);
@@ -1767,7 +1823,7 @@ var PromptRequest = class _PromptRequest {
1767
1823
  const ragText = extractRagText(prompt);
1768
1824
  const dynamicContext = await fetchDynamicContext(this.agent, ragText);
1769
1825
  const toolDefs = await fetchToolDefinitions(this.agent, ragText);
1770
- 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();
1771
1827
  request = await this.runCompletionRequestMiddlewares(
1772
1828
  request,
1773
1829
  currentTurns
@@ -1895,7 +1951,11 @@ var PromptRequest = class _PromptRequest {
1895
1951
  pendingTurnMessages
1896
1952
  );
1897
1953
  if (!emittedTurnEnd && (bufferResponseEvents || bufferOutputDeltas)) {
1898
- for (const event of responseStreamEvents(currentTurns, response)) {
1954
+ for (const event of responseStreamEvents(
1955
+ currentTurns,
1956
+ response,
1957
+ bufferResponseEvents
1958
+ )) {
1899
1959
  yield await emit(event);
1900
1960
  }
1901
1961
  }
@@ -1907,7 +1967,8 @@ var PromptRequest = class _PromptRequest {
1907
1967
  usage,
1908
1968
  messages: [...newMessages],
1909
1969
  trace: runObservers.trace,
1910
- guardrails: [...this.guardrailDecisions]
1970
+ guardrails: [...this.guardrailDecisions],
1971
+ ...generationArtifacts(newMessages)
1911
1972
  };
1912
1973
  await this.runRunEndHook(result, newMessages);
1913
1974
  await runObservers.end(result);
@@ -1925,7 +1986,9 @@ var PromptRequest = class _PromptRequest {
1925
1986
  usage: result.usage,
1926
1987
  messages: result.messages,
1927
1988
  trace: result.trace,
1928
- guardrails: result.guardrails
1989
+ guardrails: result.guardrails,
1990
+ sources: result.sources,
1991
+ providerToolCalls: result.providerToolCalls
1929
1992
  });
1930
1993
  return;
1931
1994
  }
@@ -2042,7 +2105,9 @@ var PromptRequest = class _PromptRequest {
2042
2105
  generation: {
2043
2106
  provider: this.agent.model.provider,
2044
2107
  model: request.model ?? this.agent.model.defaultModel,
2045
- usage: { ...response.usage }
2108
+ usage: { ...response.usage },
2109
+ ...response.sources === void 0 ? {} : { sources: response.sources },
2110
+ ...response.providerToolCalls === void 0 ? {} : { providerToolCalls: response.providerToolCalls }
2046
2111
  }
2047
2112
  }
2048
2113
  };
@@ -2386,7 +2451,7 @@ function normalizeSteeringInput(input) {
2386
2451
  }
2387
2452
  return Array.isArray(input) ? [...input] : [input];
2388
2453
  }
2389
- function responseStreamEvents(turn, response) {
2454
+ function responseStreamEvents(turn, response, includeProviderArtifacts = true) {
2390
2455
  const events = [];
2391
2456
  for (const item of response.choice) {
2392
2457
  if (item.type === "text") {
@@ -2418,8 +2483,34 @@ function responseStreamEvents(turn, response) {
2418
2483
  events.push({ type: "tool_call", turn, toolCall: item });
2419
2484
  }
2420
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
+ }
2421
2494
  return events;
2422
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
+ }
2423
2514
  function reasoningDeltaEvent2(turn, delta, details = {}) {
2424
2515
  const event = {
2425
2516
  type: "reasoning_delta",
@@ -2477,4 +2568,4 @@ export {
2477
2568
  extractRagText,
2478
2569
  PromptRequest
2479
2570
  };
2480
- //# sourceMappingURL=chunk-CNANX5OL.js.map
2571
+ //# sourceMappingURL=chunk-PJCJ45RJ.js.map