@valerypopoff/rivet2-core 2.1.5 → 2.1.7

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/cjs/bundle.cjs +3198 -296
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/webAppRuntime.cjs +129 -4
  4. package/dist/cjs/webAppRuntime.cjs.map +2 -2
  5. package/dist/esm/api/createProcessor.js +1 -0
  6. package/dist/esm/exports.js +4 -0
  7. package/dist/esm/integrations/KnowledgeStore.js +1 -0
  8. package/dist/esm/integrations/KnowledgeStoreProvider.js +292 -0
  9. package/dist/esm/integrations/KnowledgeStoreValidation.js +428 -0
  10. package/dist/esm/integrations/ManagedKnowledgeStore.js +539 -0
  11. package/dist/esm/model/DataValue.js +22 -2
  12. package/dist/esm/model/GraphProcessor.js +14 -0
  13. package/dist/esm/model/Nodes.js +18 -0
  14. package/dist/esm/model/UiGraph.js +2 -2
  15. package/dist/esm/model/UiGraphBrowserRuntime.js +112 -1
  16. package/dist/esm/model/UiGraphRendererStyles.js +111 -9
  17. package/dist/esm/model/UiGraphRuntimeModel.js +26 -2
  18. package/dist/esm/model/chat/openAIChatRequest.js +8 -2
  19. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +8 -8
  20. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +3 -1
  21. package/dist/esm/model/chat-v2/parallelToolCalls.js +38 -0
  22. package/dist/esm/model/chat-v2/toolContinuation.js +39 -0
  23. package/dist/esm/model/nodes/BuildKnowledgeContextNode.js +157 -0
  24. package/dist/esm/model/nodes/GetKnowledgeSourceStatusNode.js +79 -0
  25. package/dist/esm/model/nodes/KnowledgeDocumentNode.js +88 -0
  26. package/dist/esm/model/nodes/KnowledgeSourceNode.js +94 -0
  27. package/dist/esm/model/nodes/PassthroughNode.js +36 -8
  28. package/dist/esm/model/nodes/SearchKnowledgeNode.js +127 -0
  29. package/dist/esm/model/nodes/StoredValueNodeUtils.js +10 -0
  30. package/dist/esm/model/nodes/SyncKnowledgeSourceNode.js +149 -0
  31. package/dist/esm/model/nodes/ToolNode.js +14 -0
  32. package/dist/esm/plugins/pinecone/PineconeKnowledgeStore.js +553 -0
  33. package/dist/esm/plugins/pinecone/plugin.js +32 -0
  34. package/dist/esm/utils/coerceType.js +24 -2
  35. package/dist/esm/utils/getPluginConfig.js +12 -6
  36. package/dist/esm/utils/serialization/serialization.js +4 -1
  37. package/dist/esm/utils/serialization/serializationUtils.js +59 -1
  38. package/dist/esm/webAppRuntime.js +1 -1
  39. package/dist/types/api/createProcessor.d.ts +2 -0
  40. package/dist/types/exports.d.ts +4 -0
  41. package/dist/types/integrations/KnowledgeStore.d.ts +131 -0
  42. package/dist/types/integrations/KnowledgeStoreProvider.d.ts +46 -0
  43. package/dist/types/integrations/KnowledgeStoreValidation.d.ts +16 -0
  44. package/dist/types/integrations/ManagedKnowledgeStore.d.ts +57 -0
  45. package/dist/types/model/DataValue.d.ts +10 -3
  46. package/dist/types/model/EditorDefinition.d.ts +7 -1
  47. package/dist/types/model/GraphProcessor.d.ts +2 -0
  48. package/dist/types/model/Nodes.d.ts +8 -2
  49. package/dist/types/model/ProcessContext.d.ts +3 -0
  50. package/dist/types/model/Project.d.ts +11 -0
  51. package/dist/types/model/UiGraph.d.ts +3 -1
  52. package/dist/types/model/UiGraphBrowserRuntime.d.ts +25 -1
  53. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  54. package/dist/types/model/chat-v2/parallelToolCalls.d.ts +9 -0
  55. package/dist/types/model/nodes/BuildKnowledgeContextNode.d.ts +23 -0
  56. package/dist/types/model/nodes/GetKnowledgeSourceStatusNode.d.ts +19 -0
  57. package/dist/types/model/nodes/KnowledgeDocumentNode.d.ts +26 -0
  58. package/dist/types/model/nodes/KnowledgeSourceNode.d.ts +25 -0
  59. package/dist/types/model/nodes/PassthroughNode.d.ts +15 -1
  60. package/dist/types/model/nodes/SearchKnowledgeNode.d.ts +25 -0
  61. package/dist/types/model/nodes/StoredValueNodeUtils.d.ts +1 -1
  62. package/dist/types/model/nodes/SyncKnowledgeSourceNode.d.ts +27 -0
  63. package/dist/types/model/nodes/ToolNode.d.ts +2 -0
  64. package/dist/types/plugins/pinecone/PineconeKnowledgeStore.d.ts +11 -0
  65. package/dist/types/utils/serialization/serializationUtils.d.ts +4 -0
  66. package/dist/types/webAppRuntime.d.ts +2 -1
  67. package/package.json +1 -1
@@ -88,6 +88,18 @@ import { vectorStoreNode } from './nodes/VectorStoreNode.js';
88
88
  export * from './nodes/VectorStoreNode.js';
89
89
  import { vectorNearestNeighborsNode } from './nodes/VectorNearestNeighborsNode.js';
90
90
  export * from './nodes/VectorNearestNeighborsNode.js';
91
+ import { knowledgeSourceNode } from './nodes/KnowledgeSourceNode.js';
92
+ export * from './nodes/KnowledgeSourceNode.js';
93
+ import { knowledgeDocumentNode } from './nodes/KnowledgeDocumentNode.js';
94
+ export * from './nodes/KnowledgeDocumentNode.js';
95
+ import { syncKnowledgeSourceNode } from './nodes/SyncKnowledgeSourceNode.js';
96
+ export * from './nodes/SyncKnowledgeSourceNode.js';
97
+ import { getKnowledgeSourceStatusNode } from './nodes/GetKnowledgeSourceStatusNode.js';
98
+ export * from './nodes/GetKnowledgeSourceStatusNode.js';
99
+ import { searchKnowledgeNode } from './nodes/SearchKnowledgeNode.js';
100
+ export * from './nodes/SearchKnowledgeNode.js';
101
+ import { buildKnowledgeContextNode } from './nodes/BuildKnowledgeContextNode.js';
102
+ export * from './nodes/BuildKnowledgeContextNode.js';
91
103
  import { hashNode } from './nodes/HashNode.js';
92
104
  export * from './nodes/HashNode.js';
93
105
  import { abortGraphNode } from './nodes/AbortGraphNode.js';
@@ -234,6 +246,12 @@ export const registerBuiltInNodes = (registry) => {
234
246
  .register(getEmbeddingNode)
235
247
  .register(vectorStoreNode)
236
248
  .register(vectorNearestNeighborsNode)
249
+ .register(knowledgeSourceNode)
250
+ .register(knowledgeDocumentNode)
251
+ .register(syncKnowledgeSourceNode)
252
+ .register(getKnowledgeSourceStatusNode)
253
+ .register(searchKnowledgeNode)
254
+ .register(buildKnowledgeContextNode)
237
255
  .register(hashNode)
238
256
  .register(abortGraphNode)
239
257
  .register(raceInputsNode)
@@ -163,7 +163,7 @@ export function createUiGraphChatHistoryFlushStatePatch(componentId) {
163
163
  [getUiGraphChatPinsStateKey(componentId)]: [],
164
164
  };
165
165
  }
166
- export function createUiGraphChatSubmissionStatePatch(componentId, state) {
166
+ export function createUiGraphChatSubmissionStatePatch(componentId, state, timestamp = new Date().toISOString()) {
167
167
  const draftStateKey = getUiGraphChatDraftStateKey(componentId);
168
168
  const content = `${state[draftStateKey] ?? ''}`.trim();
169
169
  if (!content) {
@@ -173,7 +173,7 @@ export function createUiGraphChatSubmissionStatePatch(componentId, state) {
173
173
  [draftStateKey]: '',
174
174
  [getUiGraphChatMessagesStateKey(componentId)]: [
175
175
  ...getUiGraphChatMessages(componentId, state),
176
- { role: 'user', content },
176
+ { role: 'user', content, timestamp },
177
177
  ],
178
178
  };
179
179
  }
@@ -36,6 +36,63 @@ const getDefaultUiGraphStorageLocation = () => {
36
36
  return undefined;
37
37
  }
38
38
  };
39
+ /**
40
+ * Formats persisted Chat timestamps in the current browser locale and timezone.
41
+ * Undated or malformed legacy messages deliberately remain present without time
42
+ * metadata rather than being assigned a fabricated date.
43
+ */
44
+ export function getUiGraphChatMessagePresentations(messages, options = {}) {
45
+ const { locales, timeZone } = options;
46
+ const timeFormatter = new Intl.DateTimeFormat(locales, {
47
+ hour: '2-digit',
48
+ hourCycle: 'h23',
49
+ minute: '2-digit',
50
+ ...(timeZone ? { timeZone } : {}),
51
+ });
52
+ const dateFormatter = new Intl.DateTimeFormat(locales, {
53
+ day: 'numeric',
54
+ month: 'long',
55
+ year: 'numeric',
56
+ ...(timeZone ? { timeZone } : {}),
57
+ });
58
+ const dateKeyFormatter = new Intl.DateTimeFormat('en-CA', {
59
+ day: '2-digit',
60
+ month: '2-digit',
61
+ year: 'numeric',
62
+ ...(timeZone ? { timeZone } : {}),
63
+ });
64
+ const entries = messages.map((message) => {
65
+ const timestamp = parseUiGraphChatTimestamp(message.timestamp);
66
+ if (!timestamp)
67
+ return undefined;
68
+ return {
69
+ dateKey: dateKeyFormatter.format(timestamp),
70
+ dateTime: timestamp.toISOString(),
71
+ dateLabel: dateFormatter.format(timestamp),
72
+ timeLabel: timeFormatter.format(timestamp),
73
+ };
74
+ });
75
+ const hasMultipleDates = new Set(entries.flatMap((entry) => (entry ? [entry.dateKey] : []))).size > 1;
76
+ let previousDateKey;
77
+ return entries.map((entry) => {
78
+ if (!entry)
79
+ return {};
80
+ const dateSeparator = hasMultipleDates && previousDateKey != null && previousDateKey !== entry.dateKey
81
+ ? { dateTime: entry.dateTime, label: entry.dateLabel }
82
+ : undefined;
83
+ previousDateKey = entry.dateKey;
84
+ return {
85
+ ...(dateSeparator ? { dateSeparator } : {}),
86
+ timestamp: { dateTime: entry.dateTime, label: entry.timeLabel },
87
+ };
88
+ });
89
+ }
90
+ const parseUiGraphChatTimestamp = (value) => {
91
+ if (typeof value !== 'string')
92
+ return undefined;
93
+ const timestamp = new Date(value);
94
+ return Number.isNaN(timestamp.getTime()) ? undefined : timestamp;
95
+ };
39
96
  /** Returns the browser-local key for one app URL and one persisted UI graph. */
40
97
  export function getUiGraphChatStorageKey(uiGraph, location = getDefaultUiGraphStorageLocation()) {
41
98
  if (!location?.origin) {
@@ -292,6 +349,60 @@ export function downloadUiGraphJsonOutput(value, appName) {
292
349
  globalThis.setTimeout(() => URL.revokeObjectURL(url), 0);
293
350
  }
294
351
  }
352
+ /**
353
+ * Adds Rivet-owned Copy and Download controls to sanitized fenced JSON blocks.
354
+ * The Markdown renderer must run first: this helper never accepts or inserts
355
+ * author-provided interactive markup.
356
+ */
357
+ export function enhanceUiGraphChatJsonCodeBlocks(root, appName) {
358
+ const codeBlocks = root.querySelectorAll('pre > code.language-json');
359
+ root.classList.toggle('rivet-web-app-chat-markdown-has-json', codeBlocks.length > 0);
360
+ for (const code of codeBlocks) {
361
+ const pre = code.parentElement;
362
+ const existingWrapper = pre?.parentElement;
363
+ if (!pre) {
364
+ continue;
365
+ }
366
+ if (existingWrapper?.classList.contains('rivet-web-app-chat-json-block')) {
367
+ existingWrapper.dataset.rivetChatJsonAppName = appName;
368
+ continue;
369
+ }
370
+ const value = code.textContent ?? '';
371
+ const document = root.ownerDocument;
372
+ const wrapper = document.createElement('div');
373
+ wrapper.className = 'rivet-web-app-chat-json-block';
374
+ wrapper.dataset.rivetChatJsonAppName = appName;
375
+ const actions = document.createElement('div');
376
+ actions.className = 'rivet-web-app-chat-json-actions';
377
+ actions.dataset.rivetChatSearchIgnore = 'true';
378
+ const copyButton = document.createElement('button');
379
+ copyButton.type = 'button';
380
+ copyButton.className = 'rivet-web-app-output-action-button rivet-web-app-output-copy-button';
381
+ copyButton.title = 'Copy JSON';
382
+ copyButton.setAttribute('aria-label', 'Copy JSON');
383
+ copyButton.addEventListener('click', (event) => {
384
+ event.stopPropagation();
385
+ void copyUiGraphText(value);
386
+ });
387
+ const downloadButton = document.createElement('button');
388
+ downloadButton.type = 'button';
389
+ downloadButton.className = 'rivet-web-app-output-action-button rivet-web-app-output-download-button';
390
+ downloadButton.title = 'Download JSON';
391
+ downloadButton.setAttribute('aria-label', 'Download JSON');
392
+ downloadButton.addEventListener('click', (event) => {
393
+ event.stopPropagation();
394
+ downloadUiGraphJsonOutput(value, wrapper.dataset.rivetChatJsonAppName ?? appName);
395
+ });
396
+ actions.append(copyButton, downloadButton);
397
+ pre.replaceWith(wrapper);
398
+ wrapper.append(pre, actions);
399
+ const syncScrollableState = () => {
400
+ wrapper.classList.toggle('rivet-web-app-chat-json-block-scrollable', pre.scrollHeight > pre.clientHeight);
401
+ };
402
+ syncScrollableState();
403
+ root.ownerDocument.defaultView?.requestAnimationFrame(syncScrollableState);
404
+ }
405
+ }
295
406
  /**
296
407
  * Replaces visible chat-message text matches with safe `<mark>` elements. This
297
408
  * operates on rendered Markdown DOM rather than source Markdown, so search
@@ -308,7 +419,7 @@ export function highlightUiGraphChatSearchMatches(messagesElement, query, reques
308
419
  const walker = document.createTreeWalker(messagesElement, 4);
309
420
  let node = walker.nextNode();
310
421
  while (node) {
311
- if (node.parentElement?.closest('script, style, textarea')) {
422
+ if (node.parentElement?.closest('script, style, textarea, [data-rivet-chat-search-ignore]')) {
312
423
  node = walker.nextNode();
313
424
  continue;
314
425
  }
@@ -599,13 +599,14 @@ export const RIVET_WEB_APP_RENDERER_CSS = `
599
599
  }
600
600
 
601
601
  .rivet-web-app-chat-pin {
602
+ position: relative;
602
603
  display: grid;
603
604
  width: 100%;
604
605
  gap: 4px;
605
606
  border: 0;
606
607
  background: transparent;
607
608
  color: var(--rivet-web-app-foreground);
608
- cursor: pointer;
609
+ cursor: default;
609
610
  font: inherit;
610
611
  padding: 8px 14px;
611
612
  text-align: left;
@@ -620,19 +621,33 @@ export const RIVET_WEB_APP_RENDERER_CSS = `
620
621
  background: var(--rivet-web-app-control-hover-background);
621
622
  }
622
623
 
623
- .rivet-web-app-chat-pin:focus-visible {
624
+ .rivet-web-app-chat-pin:focus-within {
624
625
  border-radius: 6px;
625
626
  background: var(--rivet-web-app-control-hover-background);
626
627
  outline: 1px solid color-mix(in srgb, var(--rivet-web-app-foreground) 42%, transparent);
627
628
  outline-offset: -2px;
628
629
  }
629
630
 
631
+ .rivet-web-app-chat-pin-reveal {
632
+ position: absolute;
633
+ inset: 0;
634
+ z-index: 0;
635
+ width: 100%;
636
+ border: 0;
637
+ border-radius: 6px;
638
+ background: transparent;
639
+ cursor: pointer;
640
+ }
641
+
630
642
  .rivet-web-app-chat-pin-exchange {
643
+ position: relative;
644
+ z-index: 1;
631
645
  display: grid;
632
646
  grid-template-columns: 72px minmax(0, 1fr);
633
647
  column-gap: 6px;
634
648
  align-items: start;
635
649
  min-width: 0;
650
+ pointer-events: none;
636
651
  }
637
652
 
638
653
  .rivet-web-app-chat-pin-exchange + .rivet-web-app-chat-pin-exchange {
@@ -735,7 +750,7 @@ export const RIVET_WEB_APP_RENDERER_CSS = `
735
750
  .rivet-web-app-chat > .rivet-web-app-progress {
736
751
  border-top: 1px solid var(--rivet-web-app-card-border);
737
752
  font-size: inherit;
738
- padding: 10px 14px 0;
753
+ padding: 10px 14px 12px;
739
754
  }
740
755
 
741
756
  .rivet-web-app-chat-messages {
@@ -770,6 +785,9 @@ export const RIVET_WEB_APP_RENDERER_CSS = `
770
785
  .rivet-web-app-chat-message {
771
786
  --rivet-web-app-chat-message-background: var(--rivet-web-app-control-background);
772
787
  --rivet-web-app-chat-message-foreground: var(--rivet-web-app-foreground);
788
+ display: flex;
789
+ align-items: flex-end;
790
+ gap: 8px;
773
791
  width: fit-content;
774
792
  max-width: min(82%, 620px);
775
793
  border: 1px solid var(--rivet-web-app-card-border);
@@ -782,9 +800,43 @@ export const RIVET_WEB_APP_RENDERER_CSS = `
782
800
  }
783
801
 
784
802
  .rivet-web-app-chat-message-markdown {
803
+ flex: 1 1 auto;
804
+ min-width: 0;
785
805
  white-space: normal;
786
806
  }
787
807
 
808
+ .rivet-web-app-chat-message-time {
809
+ flex: 0 0 auto;
810
+ margin-bottom: 1px;
811
+ color: color-mix(in srgb, currentColor 62%, transparent);
812
+ font-size: 0.8em;
813
+ line-height: 1;
814
+ white-space: nowrap;
815
+ }
816
+
817
+ .rivet-web-app-chat-date-separator {
818
+ display: flex;
819
+ align-items: center;
820
+ align-self: stretch;
821
+ gap: 10px;
822
+ color: var(--rivet-web-app-foreground-muted);
823
+ font-size: 12px;
824
+ line-height: 1;
825
+ text-align: center;
826
+ }
827
+
828
+ .rivet-web-app-chat-date-separator::before,
829
+ .rivet-web-app-chat-date-separator::after {
830
+ height: 1px;
831
+ flex: 1 1 auto;
832
+ background: var(--rivet-web-app-card-border);
833
+ content: '';
834
+ }
835
+
836
+ .rivet-web-app-chat-date-separator time {
837
+ flex: 0 0 auto;
838
+ }
839
+
788
840
  .rivet-web-app-chat-message-user {
789
841
  --rivet-web-app-chat-message-background: color-mix(in srgb, var(--rivet-web-app-button-background) 72%, var(--rivet-web-app-card-background));
790
842
  --rivet-web-app-chat-message-foreground: var(--rivet-web-app-button-foreground);
@@ -920,6 +972,7 @@ export const RIVET_WEB_APP_RENDERER_CSS = `
920
972
  align-items: flex-end;
921
973
  gap: 10px;
922
974
  border-top: 1px solid var(--rivet-web-app-card-border);
975
+ margin: 0;
923
976
  padding: 14px;
924
977
  }
925
978
 
@@ -956,13 +1009,15 @@ export const RIVET_WEB_APP_RENDERER_CSS = `
956
1009
  background: var(--rivet-web-app-button-background);
957
1010
  color: var(--rivet-web-app-button-foreground);
958
1011
  cursor: pointer;
959
- font: inherit;
960
- font-size: 21px;
961
- font-weight: 700;
962
- line-height: 1;
963
1012
  padding: 0;
964
1013
  }
965
1014
 
1015
+ .rivet-web-app-chat-send > svg {
1016
+ width: 18px;
1017
+ height: 18px;
1018
+ transform: translateY(-1px);
1019
+ }
1020
+
966
1021
  .rivet-web-app-chat-send:hover:not(:disabled),
967
1022
  .rivet-web-app-chat-send:focus-visible:not(:disabled) {
968
1023
  filter: brightness(1.08);
@@ -1254,8 +1309,8 @@ button.rivet-web-app-output-header:focus-visible {
1254
1309
 
1255
1310
  .rivet-web-app-chat-message-markdown.markdown-body {
1256
1311
  min-width: 0;
1257
- background: var(--rivet-web-app-chat-message-background);
1258
- color: var(--rivet-web-app-chat-message-foreground);
1312
+ background: transparent;
1313
+ color: inherit;
1259
1314
  font-family: inherit;
1260
1315
  }
1261
1316
 
@@ -1310,6 +1365,53 @@ button.rivet-web-app-output-header:focus-visible {
1310
1365
  white-space: pre-wrap;
1311
1366
  }
1312
1367
 
1368
+ .rivet-web-app-chat-json-block {
1369
+ --rivet-web-app-chat-json-background: color-mix(
1370
+ in srgb,
1371
+ var(--rivet-web-app-control-background) 78%,
1372
+ var(--rivet-web-app-chat-message-foreground) 5%
1373
+ );
1374
+ position: relative;
1375
+ min-width: 0;
1376
+ margin: 8px 0;
1377
+ overflow: hidden;
1378
+ border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
1379
+ border-radius: 8px;
1380
+ background: var(--rivet-web-app-chat-json-background);
1381
+ }
1382
+
1383
+ .rivet-web-app-chat-message-markdown.markdown-body .rivet-web-app-chat-json-block > pre {
1384
+ margin: 0;
1385
+ overflow: auto;
1386
+ max-height: calc(20 * 1.45em + 24px);
1387
+ padding: 12px 72px 12px 12px;
1388
+ line-height: 1.45;
1389
+ }
1390
+
1391
+ .rivet-web-app-chat-message-markdown.markdown-body .rivet-web-app-chat-json-block > pre > code {
1392
+ display: block;
1393
+ border-radius: 0;
1394
+ background: transparent;
1395
+ padding: 0;
1396
+ }
1397
+
1398
+ .rivet-web-app-chat-json-actions {
1399
+ position: absolute;
1400
+ top: 4px;
1401
+ right: 4px;
1402
+ z-index: 2;
1403
+ display: flex;
1404
+ gap: 2px;
1405
+ }
1406
+
1407
+ .rivet-web-app-chat-json-block-scrollable .rivet-web-app-chat-json-actions {
1408
+ right: calc(4px + 1em);
1409
+ }
1410
+
1411
+ .rivet-web-app-chat-json-block .rivet-web-app-output-copy-button::after {
1412
+ background: var(--rivet-web-app-chat-json-background);
1413
+ }
1414
+
1313
1415
  .rivet-web-app-markdown > :first-child,
1314
1416
  .rivet-web-app-output-markdown > :first-child,
1315
1417
  .rivet-web-app-chat-message-markdown > :first-child {
@@ -1,4 +1,4 @@
1
- import { getUiGraphChatDraftStateKey, getUiGraphChatMessages, getUiGraphChatPins, getUiGraphComponentActionOutputStateKeys, getUiGraphComponentActionState, getUiGraphInitialState, } from './UiGraph.js';
1
+ import { getUiGraphChatDraftStateKey, getUiGraphChatMessages, getUiGraphChatMessagesStateKey, getUiGraphChatPins, getUiGraphComponentActionOutputStateKeys, getUiGraphComponentActionState, getUiGraphInitialState, } from './UiGraph.js';
2
2
  import { normalizeGraphProgress } from './GraphProgress.js';
3
3
  const IMAGE_DATA_URL_PATTERN = /^data:(image\/(?:avif|bmp|gif|jpe?g|png|webp));base64,([\s\S]+)$/i;
4
4
  const IMAGE_URL_PATTERN = /^(?:https?:\/\/|blob:|\/\/|\/|\.\.?\/)/i;
@@ -201,6 +201,30 @@ export function createUiGraphInteractionController(initialUiGraph, options = {})
201
201
  }
202
202
  }
203
203
  };
204
+ const stampChatResponseAtBrowserReceipt = (component, statePatch) => {
205
+ if (component.type !== 'chat' || !statePatch) {
206
+ return statePatch;
207
+ }
208
+ const messagesStateKey = getUiGraphChatMessagesStateKey(component.id);
209
+ const messages = statePatch[messagesStateKey];
210
+ if (!Array.isArray(messages) || messages.length === 0) {
211
+ return statePatch;
212
+ }
213
+ const lastMessage = messages[messages.length - 1];
214
+ if (!lastMessage ||
215
+ typeof lastMessage !== 'object' ||
216
+ lastMessage.role !== 'assistant' ||
217
+ typeof lastMessage.content !== 'string') {
218
+ return statePatch;
219
+ }
220
+ return {
221
+ ...statePatch,
222
+ [messagesStateKey]: [
223
+ ...messages.slice(0, -1),
224
+ { ...lastMessage, timestamp: new Date().toISOString() },
225
+ ],
226
+ };
227
+ };
204
228
  updateSnapshot();
205
229
  return {
206
230
  abortActions() {
@@ -261,7 +285,7 @@ export function createUiGraphInteractionController(initialUiGraph, options = {})
261
285
  if (!actionController.isCurrent(execution)) {
262
286
  return;
263
287
  }
264
- const statePatch = actionController.resolveStatePatch(execution, result.statePatch);
288
+ const statePatch = actionController.resolveStatePatch(execution, stampChatResponseAtBrowserReceipt(component, result.statePatch));
265
289
  if (statePatch) {
266
290
  const nextState = applyUiGraphStatePatch(state, statePatch);
267
291
  expandOutputsForUpdatedState(Object.keys(statePatch), nextState);
@@ -53,7 +53,8 @@ export function resolveAdditionalHeaders(data, inputs) {
53
53
  return acc;
54
54
  }, {});
55
55
  return data.useHeadersInput
56
- ? coerceTypeOptional(inputs['headers'], 'object') ?? headersFromData
56
+ ? coerceTypeOptional(inputs['headers'], 'object') ??
57
+ headersFromData
57
58
  : headersFromData;
58
59
  }
59
60
  export function resolveAdditionalParameters(data, inputs) {
@@ -69,7 +70,12 @@ export function resolveAdditionalParameters(data, inputs) {
69
70
  export function resolveChatTools(inputs) {
70
71
  const functions = coerceTypeOptional(inputs['functions'], 'gpt-function[]');
71
72
  return (functions ?? []).map((fn) => ({
72
- function: fn,
73
+ function: {
74
+ name: fn.name,
75
+ description: fn.description,
76
+ parameters: fn.parameters,
77
+ strict: fn.strict,
78
+ },
73
79
  type: 'function',
74
80
  }));
75
81
  }
@@ -3,6 +3,7 @@ import { createOpenAI } from '@ai-sdk/openai';
3
3
  import { coerceTypeOptional } from '../../utils/coerceType.js';
4
4
  import { cleanHeaders, getInputOrData } from '../../utils/inputs.js';
5
5
  import { resolveChatV2Credential } from './chatV2ProviderProfile.js';
6
+ import { applyLLMChatV2ParallelToolCallProviderOptions } from './parallelToolCalls.js';
6
7
  export function resolveLLMChatV2Headers(data, inputs) {
7
8
  const resolvedHeaders = data.useHeadersInput && inputs['headers'] != null
8
9
  ? coerceTypeOptional(inputs['headers'], 'object')
@@ -123,14 +124,13 @@ function resolveProviderOptions(data, inputs) {
123
124
  return Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
124
125
  }
125
126
  export function resolveLLMChatV2RuntimeProviderOptions(data, inputs) {
126
- const providerOptions = resolveProviderOptions(data, inputs) ?? {};
127
- if (data.provider === 'openai' && data.useToolCalling) {
128
- providerOptions.openai = {
129
- ...(providerOptions.openai ?? {}),
130
- parallelToolCalls: !!data.parallelToolCalls,
131
- };
132
- }
133
- return Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
127
+ const providerOptions = applyLLMChatV2ParallelToolCallProviderOptions({
128
+ provider: data.provider,
129
+ useToolCalling: data.useToolCalling,
130
+ parallelToolCalls: data.parallelToolCalls,
131
+ providerOptions: resolveProviderOptions(data, inputs),
132
+ });
133
+ return providerOptions != null && Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
134
134
  }
135
135
  export function resolveLLMChatV2ToolChoice(data) {
136
136
  if (!data.useToolCalling || !data.toolChoice) {
@@ -1,5 +1,6 @@
1
1
  import { DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS, DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES, } from './chatV2Retry.js';
2
2
  import { anthropicCacheControlTtlOptions, anthropicEffortOptions, anthropicThinkingModeOptions, chatV2ProviderOptions, getChatV2ModelOptions, googleThinkingLevelOptions, openAIReasoningEffortOptions, openAIWebSearchContextSizeOptions, } from './providerOptions.js';
3
+ import { LLM_CHAT_V2_PARALLEL_TOOL_CALLS_HELPER_MESSAGE, supportsLLMChatV2ParallelToolCalls, } from './parallelToolCalls.js';
3
4
  const hideUnlessProvider = (provider) => (data) => data.provider !== provider;
4
5
  function group(label, editors, defaultOpen) {
5
6
  return {
@@ -380,7 +381,8 @@ function getToolEditors() {
380
381
  type: 'toggle',
381
382
  label: 'Allow parallel toolcalls',
382
383
  dataKey: 'parallelToolCalls',
383
- hideIf: (data) => !data.useToolCalling || data.provider === 'custom',
384
+ helperMessage: LLM_CHAT_V2_PARALLEL_TOOL_CALLS_HELPER_MESSAGE,
385
+ hideIf: (data) => !data.useToolCalling || !supportsLLMChatV2ParallelToolCalls(data.provider),
384
386
  },
385
387
  {
386
388
  type: 'toggle',
@@ -0,0 +1,38 @@
1
+ export const LLM_CHAT_V2_PARALLEL_TOOL_CALLS_HELPER_MESSAGE = 'Supported by OpenAI, Anthropic, and compatible Custom providers. Custom providers receive parallel_tool_calls only when enabled; otherwise their default applies unless Extra provider options supplies the field.';
2
+ export function supportsLLMChatV2ParallelToolCalls(provider) {
3
+ return provider === 'openai' || provider === 'anthropic' || provider === 'custom';
4
+ }
5
+ function mergeProviderOptions(providerOptions, provider, options) {
6
+ return {
7
+ ...providerOptions,
8
+ [provider]: {
9
+ ...(providerOptions?.[provider] ?? {}),
10
+ ...options,
11
+ },
12
+ };
13
+ }
14
+ export function applyLLMChatV2ParallelToolCallProviderOptions(params) {
15
+ const { provider, useToolCalling, parallelToolCalls, providerOptions } = params;
16
+ if (!useToolCalling) {
17
+ return providerOptions;
18
+ }
19
+ switch (provider) {
20
+ case 'openai':
21
+ return mergeProviderOptions(providerOptions, provider, {
22
+ parallelToolCalls: !!parallelToolCalls,
23
+ });
24
+ case 'anthropic':
25
+ return mergeProviderOptions(providerOptions, provider, {
26
+ disableParallelToolUse: !parallelToolCalls,
27
+ });
28
+ case 'custom':
29
+ // OpenAI-compatible endpoints vary widely. Do not send an unsupported
30
+ // field to existing/default Custom-provider graphs unless the user
31
+ // explicitly opts in to requesting parallel calls.
32
+ return parallelToolCalls
33
+ ? mergeProviderOptions(providerOptions, provider, { parallel_tool_calls: true })
34
+ : providerOptions;
35
+ case 'google':
36
+ return providerOptions;
37
+ }
38
+ }
@@ -5,6 +5,19 @@ function getToolNames(functions) {
5
5
  function canAutoContinue(functionCalls, toolNames) {
6
6
  return functionCalls.length > 0 && functionCalls.every((call) => toolNames.has(call.name));
7
7
  }
8
+ function shouldReturnToolResultDirectly(functionCalls, functions) {
9
+ if (functionCalls.length !== 1) {
10
+ return false;
11
+ }
12
+ let tool;
13
+ for (const candidate of functions ?? []) {
14
+ if (candidate.name === functionCalls[0].name) {
15
+ // Provider tool maps use the last declaration for duplicate names.
16
+ tool = candidate;
17
+ }
18
+ }
19
+ return tool?.resultHandling === 'return-direct';
20
+ }
8
21
  function addUsage(accumulated, usage) {
9
22
  if (usage == null) {
10
23
  return accumulated;
@@ -100,6 +113,32 @@ export async function runChatV2PipelineWithToolContinuation(options) {
100
113
  delegatedToolCalls.push(...toolResultMessages
101
114
  .map((message) => message.delegatedToolCall)
102
115
  .filter((record) => record != null));
116
+ if (shouldReturnToolResultDirectly(result.functionCalls, functions)) {
117
+ const directResultMessage = toolResultMessages[0]?.value;
118
+ if (directResultMessage?.type !== 'function' || typeof directResultMessage.message !== 'string') {
119
+ throw new Error('Return directly requires the delegated tool handler to return a string output.');
120
+ }
121
+ result.response = directResultMessage.message;
122
+ result.allMessages = [...result.allMessages, directResultMessage];
123
+ result.functionCalls = [];
124
+ result.commonOutputs['response'] = {
125
+ type: 'string',
126
+ value: result.response,
127
+ };
128
+ result.commonOutputs['all-messages'] = {
129
+ type: 'chat-message[]',
130
+ value: result.allMessages,
131
+ };
132
+ if (pipelineOptions.includeFunctionCalls) {
133
+ result.commonOutputs['function-calls'] = {
134
+ type: 'object[]',
135
+ value: delegatedToolCalls,
136
+ };
137
+ }
138
+ applyAccumulatedUsage(result, accumulatedUsage, pipelineOptions.outputUsage);
139
+ applyAccumulatedReasoning(result, reasoningRounds, pipelineOptions.outputReasoning);
140
+ return result;
141
+ }
103
142
  currentPrompt = {
104
143
  type: 'chat-message[]',
105
144
  value: [...result.allMessages, ...toolResultMessages.map((message) => message.value)],