@copilotkit/runtime 1.4.8-no-pino-redact.1 → 1.5.0-coagents-v0-3.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 (78) hide show
  1. package/CHANGELOG.md +20 -5
  2. package/__snapshots__/schema/schema.graphql +7 -9
  3. package/dist/{chunk-OKQVDDJ2.mjs → chunk-4AYRDPWK.mjs} +285 -63
  4. package/dist/chunk-4AYRDPWK.mjs.map +1 -0
  5. package/dist/{chunk-APVJZO3R.mjs → chunk-7BOO3OFP.mjs} +2 -2
  6. package/dist/{chunk-OSWF5QDO.mjs → chunk-GSTWFOZF.mjs} +2 -2
  7. package/dist/{chunk-M74ZTUCC.mjs → chunk-OMAAKIJQ.mjs} +2 -2
  8. package/dist/{chunk-36AYTJIE.mjs → chunk-PXS4SBRF.mjs} +447 -321
  9. package/dist/chunk-PXS4SBRF.mjs.map +1 -0
  10. package/dist/{chunk-B74M7FXG.mjs → chunk-RFF5IIZJ.mjs} +3 -2
  11. package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
  12. package/dist/{copilot-runtime-12e7ac40.d.ts → copilot-runtime-2e46a7b6.d.ts} +2 -2
  13. package/dist/graphql/types/converted/index.d.ts +1 -1
  14. package/dist/graphql/types/converted/index.js +2 -1
  15. package/dist/graphql/types/converted/index.js.map +1 -1
  16. package/dist/graphql/types/converted/index.mjs +1 -1
  17. package/dist/{groq-adapter-24abe931.d.ts → groq-adapter-7bf6824b.d.ts} +1 -1
  18. package/dist/{index-10b1c870.d.ts → index-ff3fbc33.d.ts} +7 -8
  19. package/dist/index.d.ts +5 -5
  20. package/dist/index.js +824 -473
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +10 -6
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/{langserve-f021ab9c.d.ts → langserve-f318db89.d.ts} +53 -14
  25. package/dist/lib/index.d.ts +4 -4
  26. package/dist/lib/index.js +729 -452
  27. package/dist/lib/index.js.map +1 -1
  28. package/dist/lib/index.mjs +6 -6
  29. package/dist/lib/integrations/index.d.ts +4 -4
  30. package/dist/lib/integrations/index.js +79 -31
  31. package/dist/lib/integrations/index.js.map +1 -1
  32. package/dist/lib/integrations/index.mjs +6 -6
  33. package/dist/lib/integrations/nest/index.d.ts +3 -3
  34. package/dist/lib/integrations/nest/index.js +79 -31
  35. package/dist/lib/integrations/nest/index.js.map +1 -1
  36. package/dist/lib/integrations/nest/index.mjs +4 -4
  37. package/dist/lib/integrations/node-express/index.d.ts +3 -3
  38. package/dist/lib/integrations/node-express/index.js +79 -31
  39. package/dist/lib/integrations/node-express/index.js.map +1 -1
  40. package/dist/lib/integrations/node-express/index.mjs +4 -4
  41. package/dist/lib/integrations/node-http/index.d.ts +3 -3
  42. package/dist/lib/integrations/node-http/index.js +79 -31
  43. package/dist/lib/integrations/node-http/index.js.map +1 -1
  44. package/dist/lib/integrations/node-http/index.mjs +3 -3
  45. package/dist/service-adapters/index.d.ts +36 -5
  46. package/dist/service-adapters/index.js +285 -61
  47. package/dist/service-adapters/index.js.map +1 -1
  48. package/dist/service-adapters/index.mjs +5 -1
  49. package/package.json +2 -2
  50. package/src/agents/langgraph/event-source.ts +140 -148
  51. package/src/agents/langgraph/events.ts +1 -1
  52. package/src/graphql/inputs/message.input.ts +15 -3
  53. package/src/graphql/resolvers/copilot.resolver.ts +32 -6
  54. package/src/graphql/types/converted/index.ts +4 -3
  55. package/src/graphql/types/copilot-response.type.ts +12 -3
  56. package/src/graphql/types/enums.ts +0 -11
  57. package/src/lib/logger.ts +4 -0
  58. package/src/lib/runtime/copilot-runtime.ts +1 -7
  59. package/src/lib/runtime/remote-action-constructors.ts +64 -58
  60. package/src/lib/runtime/remote-actions.ts +1 -0
  61. package/src/lib/runtime/remote-lg-action.ts +159 -140
  62. package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -6
  63. package/src/service-adapters/conversion.ts +2 -1
  64. package/src/service-adapters/events.ts +118 -54
  65. package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
  66. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
  67. package/src/service-adapters/groq/groq-adapter.ts +23 -8
  68. package/src/service-adapters/index.ts +7 -1
  69. package/src/service-adapters/langchain/utils.ts +55 -32
  70. package/src/service-adapters/openai/openai-adapter.ts +22 -9
  71. package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
  72. package/src/service-adapters/unify/unify-adapter.ts +28 -11
  73. package/dist/chunk-36AYTJIE.mjs.map +0 -1
  74. package/dist/chunk-B74M7FXG.mjs.map +0 -1
  75. package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
  76. /package/dist/{chunk-APVJZO3R.mjs.map → chunk-7BOO3OFP.mjs.map} +0 -0
  77. /package/dist/{chunk-OSWF5QDO.mjs.map → chunk-GSTWFOZF.mjs.map} +0 -0
  78. /package/dist/{chunk-M74ZTUCC.mjs.map → chunk-OMAAKIJQ.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,15 +1,30 @@
1
1
  # @copilotkit/runtime
2
2
 
3
- ## 1.4.8-no-pino-redact.1
3
+ ## 1.5.0-coagents-v0-3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Synchronize LangGraph messages with CopilotKit
4
8
 
5
9
  ### Patch Changes
6
10
 
7
- - eb5a987: - Revert "fixes paths defined in readact (#1133)"
11
+ - e66bce4: CoAgents v0.3 prerelease
12
+ - Updated dependencies
13
+ - Updated dependencies [e66bce4]
14
+ - @copilotkit/shared@1.5.0-coagents-v0-3.0
8
15
 
9
- This reverts commit 8d7992d32c56e9467d3791ac5f0572d8843e9700.
16
+ ## 1.4.8
10
17
 
11
- - removes redact from pino as it breaks in cloudflare
12
- - @copilotkit/shared@1.4.8-no-pino-redact.1
18
+ ### Patch Changes
19
+
20
+ - - Better error handling
21
+ - Introduce new "EmptyLLMAdapter" for when using CoAgents
22
+ - Improve dev console help options
23
+ - Allow CopilotKit remote endpoint without agents
24
+ - 989f159: - fix: allow CopilotKit Remote Endpoint without agents
25
+ - Apply suggestions from code review
26
+ - Updated dependencies
27
+ - @copilotkit/shared@1.4.8
13
28
 
14
29
  ## 1.4.8-next.0
15
30
 
@@ -6,7 +6,8 @@
6
6
  input ActionExecutionMessageInput {
7
7
  arguments: String!
8
8
  name: String!
9
- scope: ActionExecutionScope!
9
+ parentMessageId: String
10
+ scope: String @deprecated(reason: "This field will be removed in a future version")
10
11
  }
11
12
 
12
13
  type ActionExecutionMessageOutput implements BaseMessageOutput {
@@ -14,17 +15,11 @@ type ActionExecutionMessageOutput implements BaseMessageOutput {
14
15
  createdAt: DateTimeISO!
15
16
  id: String!
16
17
  name: String!
17
- scope: ActionExecutionScope!
18
+ parentMessageId: String
19
+ scope: String @deprecated(reason: "This field will be removed in a future version")
18
20
  status: MessageStatus!
19
21
  }
20
22
 
21
- """The scope of the action"""
22
- enum ActionExecutionScope {
23
- client
24
- passThrough
25
- server
26
- }
27
-
28
23
  input ActionInput {
29
24
  available: ActionInputAvailability
30
25
  description: String!
@@ -229,6 +224,7 @@ enum ResponseStatusCode {
229
224
  input ResultMessageInput {
230
225
  actionExecutionId: String!
231
226
  actionName: String!
227
+ parentMessageId: String
232
228
  result: String!
233
229
  }
234
230
 
@@ -251,6 +247,7 @@ type SuccessResponseStatus implements BaseResponseStatus {
251
247
 
252
248
  input TextMessageInput {
253
249
  content: String!
250
+ parentMessageId: String
254
251
  role: MessageRole!
255
252
  }
256
253
 
@@ -258,6 +255,7 @@ type TextMessageOutput implements BaseMessageOutput {
258
255
  content: [String!]!
259
256
  createdAt: DateTimeISO!
260
257
  id: String!
258
+ parentMessageId: String
261
259
  role: MessageRole!
262
260
  status: MessageStatus!
263
261
  }
@@ -276,6 +276,8 @@ var OpenAIAdapter = class {
276
276
  eventSource.stream(async (eventStream$) => {
277
277
  var _a, _b;
278
278
  let mode = null;
279
+ let currentMessageId;
280
+ let currentToolCallId;
279
281
  for await (const chunk of stream) {
280
282
  if (chunk.choices.length === 0) {
281
283
  continue;
@@ -284,30 +286,52 @@ var OpenAIAdapter = class {
284
286
  const content = chunk.choices[0].delta.content;
285
287
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
286
288
  mode = null;
287
- eventStream$.sendTextMessageEnd();
289
+ eventStream$.sendTextMessageEnd({
290
+ messageId: currentMessageId
291
+ });
288
292
  } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
289
293
  mode = null;
290
- eventStream$.sendActionExecutionEnd();
294
+ eventStream$.sendActionExecutionEnd({
295
+ actionExecutionId: currentToolCallId
296
+ });
291
297
  }
292
298
  if (mode === null) {
293
299
  if (toolCall == null ? void 0 : toolCall.id) {
294
300
  mode = "function";
295
- eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
301
+ currentToolCallId = toolCall.id;
302
+ eventStream$.sendActionExecutionStart({
303
+ actionExecutionId: currentToolCallId,
304
+ parentMessageId: chunk.id,
305
+ actionName: toolCall.function.name
306
+ });
296
307
  } else if (content) {
297
308
  mode = "message";
298
- eventStream$.sendTextMessageStart(chunk.id);
309
+ currentMessageId = chunk.id;
310
+ eventStream$.sendTextMessageStart({
311
+ messageId: currentMessageId
312
+ });
299
313
  }
300
314
  }
301
315
  if (mode === "message" && content) {
302
- eventStream$.sendTextMessageContent(content);
316
+ eventStream$.sendTextMessageContent({
317
+ messageId: currentMessageId,
318
+ content
319
+ });
303
320
  } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
304
- eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
321
+ eventStream$.sendActionExecutionArgs({
322
+ actionExecutionId: currentToolCallId,
323
+ args: toolCall.function.arguments
324
+ });
305
325
  }
306
326
  }
307
327
  if (mode === "message") {
308
- eventStream$.sendTextMessageEnd();
328
+ eventStream$.sendTextMessageEnd({
329
+ messageId: currentMessageId
330
+ });
309
331
  } else if (mode === "function") {
310
- eventStream$.sendActionExecutionEnd();
332
+ eventStream$.sendActionExecutionEnd({
333
+ actionExecutionId: currentToolCallId
334
+ });
311
335
  }
312
336
  eventStream$.complete();
313
337
  });
@@ -375,17 +399,25 @@ function isBaseMessageChunk(message) {
375
399
  __name(isBaseMessageChunk, "isBaseMessageChunk");
376
400
  function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
377
401
  if (actionExecution) {
378
- eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, "Sending a message");
402
+ eventStream$.sendActionExecutionResult({
403
+ actionExecutionId: actionExecution.id,
404
+ actionName: actionExecution.name,
405
+ result: "Sending a message"
406
+ });
379
407
  }
380
408
  }
381
409
  __name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
382
410
  async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
383
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
411
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
384
412
  if (typeof result === "string") {
385
413
  if (!actionExecution) {
386
414
  eventStream$.sendTextMessage(randomId2(), result);
387
415
  } else {
388
- eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);
416
+ eventStream$.sendActionExecutionResult({
417
+ actionExecutionId: actionExecution.id,
418
+ actionName: actionExecution.name,
419
+ result
420
+ });
389
421
  }
390
422
  } else if (isAIMessage(result)) {
391
423
  maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
@@ -393,7 +425,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
393
425
  eventStream$.sendTextMessage(randomId2(), result.content);
394
426
  }
395
427
  for (const toolCall of result.tool_calls) {
396
- eventStream$.sendActionExecution(toolCall.id || randomId2(), toolCall.name, JSON.stringify(toolCall.args));
428
+ eventStream$.sendActionExecution({
429
+ actionExecutionId: toolCall.id || randomId2(),
430
+ actionName: toolCall.name,
431
+ args: JSON.stringify(toolCall.args)
432
+ });
397
433
  }
398
434
  } else if (isBaseMessageChunk(result)) {
399
435
  maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
@@ -402,13 +438,18 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
402
438
  }
403
439
  if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
404
440
  for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
405
- eventStream$.sendActionExecution(toolCall.id || randomId2(), toolCall.name, JSON.stringify(toolCall.args));
441
+ eventStream$.sendActionExecution({
442
+ actionExecutionId: toolCall.id || randomId2(),
443
+ actionName: toolCall.name,
444
+ args: JSON.stringify(toolCall.args)
445
+ });
406
446
  }
407
447
  }
408
448
  } else if (result && "getReader" in result) {
409
449
  maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
410
450
  let reader = result.getReader();
411
451
  let mode = null;
452
+ let currentMessageId;
412
453
  const toolCallDetails = {
413
454
  name: null,
414
455
  id: null,
@@ -422,9 +463,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
422
463
  let toolCallId = void 0;
423
464
  let toolCallArgs = void 0;
424
465
  let hasToolCall = false;
425
- let content = value == null ? void 0 : value.content;
466
+ let content = "";
467
+ if (value && value.content) {
468
+ content = Array.isArray(value.content) ? ((_d = value.content[0]) == null ? void 0 : _d.text) ?? "" : value.content;
469
+ }
426
470
  if (isAIMessageChunk(value)) {
427
- let chunk = (_d = value.tool_call_chunks) == null ? void 0 : _d[0];
471
+ let chunk = (_e = value.tool_call_chunks) == null ? void 0 : _e[0];
428
472
  toolCallArgs = chunk == null ? void 0 : chunk.args;
429
473
  hasToolCall = chunk != void 0;
430
474
  if (chunk == null ? void 0 : chunk.name)
@@ -439,18 +483,22 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
439
483
  toolCallName = toolCallDetails.name;
440
484
  toolCallId = toolCallDetails.id;
441
485
  } else if (isBaseMessageChunk(value)) {
442
- let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
443
- toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
486
+ let chunk = (_g = (_f = value.additional_kwargs) == null ? void 0 : _f.tool_calls) == null ? void 0 : _g[0];
487
+ toolCallName = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.name;
444
488
  toolCallId = chunk == null ? void 0 : chunk.id;
445
- toolCallArgs = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.arguments;
489
+ toolCallArgs = (_i = chunk == null ? void 0 : chunk.function) == null ? void 0 : _i.arguments;
446
490
  hasToolCall = (chunk == null ? void 0 : chunk.function) != void 0;
447
491
  }
448
492
  if (mode === "message" && (toolCallId || done)) {
449
493
  mode = null;
450
- eventStream$.sendTextMessageEnd();
494
+ eventStream$.sendTextMessageEnd({
495
+ messageId: currentMessageId
496
+ });
451
497
  } else if (mode === "function" && (!hasToolCall || done)) {
452
498
  mode = null;
453
- eventStream$.sendActionExecutionEnd();
499
+ eventStream$.sendActionExecutionEnd({
500
+ actionExecutionId: toolCallId
501
+ });
454
502
  }
455
503
  if (done) {
456
504
  break;
@@ -458,21 +506,40 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
458
506
  if (mode === null) {
459
507
  if (hasToolCall && toolCallId && toolCallName) {
460
508
  mode = "function";
461
- eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
509
+ eventStream$.sendActionExecutionStart({
510
+ actionExecutionId: toolCallId,
511
+ actionName: toolCallName,
512
+ parentMessageId: (_j = value.lc_kwargs) == null ? void 0 : _j.id
513
+ });
462
514
  } else if (content) {
463
515
  mode = "message";
464
- eventStream$.sendTextMessageStart(randomId2());
516
+ currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || randomId2();
517
+ eventStream$.sendTextMessageStart({
518
+ messageId: currentMessageId
519
+ });
465
520
  }
466
521
  }
467
522
  if (mode === "message" && content) {
468
- eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
523
+ eventStream$.sendTextMessageContent({
524
+ messageId: currentMessageId,
525
+ content
526
+ });
469
527
  } else if (mode === "function" && toolCallArgs) {
470
528
  if (toolCallDetails.index !== toolCallDetails.prevIndex) {
471
- eventStream$.sendActionExecutionEnd();
472
- eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
529
+ eventStream$.sendActionExecutionEnd({
530
+ actionExecutionId: toolCallId
531
+ });
532
+ eventStream$.sendActionExecutionStart({
533
+ actionExecutionId: toolCallId,
534
+ actionName: toolCallName,
535
+ parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
536
+ });
473
537
  toolCallDetails.prevIndex = toolCallDetails.index;
474
538
  }
475
- eventStream$.sendActionExecutionArgs(toolCallArgs);
539
+ eventStream$.sendActionExecutionArgs({
540
+ actionExecutionId: toolCallId,
541
+ args: toolCallArgs
542
+ });
476
543
  }
477
544
  } catch (error) {
478
545
  console.error("Error reading from stream", error);
@@ -480,7 +547,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
480
547
  }
481
548
  }
482
549
  } else if (actionExecution) {
483
- eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, encodeResult(result));
550
+ eventStream$.sendActionExecutionResult({
551
+ actionExecutionId: actionExecution.id,
552
+ actionName: actionExecution.name,
553
+ result: encodeResult(result)
554
+ });
484
555
  } else {
485
556
  throw new Error("Invalid return type from LangChain function.");
486
557
  }
@@ -660,21 +731,33 @@ var OpenAIAssistantAdapter = class {
660
731
  eventSource.stream(async (eventStream$) => {
661
732
  var _a, _b, _c, _d, _e, _f;
662
733
  let inFunctionCall = false;
734
+ let currentMessageId;
735
+ let currentToolCallId;
663
736
  for await (const chunk of stream) {
664
737
  switch (chunk.event) {
665
738
  case "thread.message.created":
666
739
  if (inFunctionCall) {
667
- eventStream$.sendActionExecutionEnd();
740
+ eventStream$.sendActionExecutionEnd({
741
+ actionExecutionId: currentToolCallId
742
+ });
668
743
  }
669
- eventStream$.sendTextMessageStart(chunk.data.id);
744
+ currentMessageId = chunk.data.id;
745
+ eventStream$.sendTextMessageStart({
746
+ messageId: currentMessageId
747
+ });
670
748
  break;
671
749
  case "thread.message.delta":
672
750
  if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
673
- eventStream$.sendTextMessageContent((_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value);
751
+ eventStream$.sendTextMessageContent({
752
+ messageId: currentMessageId,
753
+ content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
754
+ });
674
755
  }
675
756
  break;
676
757
  case "thread.message.completed":
677
- eventStream$.sendTextMessageEnd();
758
+ eventStream$.sendTextMessageEnd({
759
+ messageId: currentMessageId
760
+ });
678
761
  break;
679
762
  case "thread.run.step.delta":
680
763
  let toolCallId;
@@ -687,18 +770,30 @@ var OpenAIAssistantAdapter = class {
687
770
  }
688
771
  if (toolCallName && toolCallId) {
689
772
  if (inFunctionCall) {
690
- eventStream$.sendActionExecutionEnd();
773
+ eventStream$.sendActionExecutionEnd({
774
+ actionExecutionId: currentToolCallId
775
+ });
691
776
  }
692
777
  inFunctionCall = true;
693
- eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
778
+ currentToolCallId = toolCallId;
779
+ eventStream$.sendActionExecutionStart({
780
+ actionExecutionId: currentToolCallId,
781
+ parentMessageId: chunk.data.id,
782
+ actionName: toolCallName
783
+ });
694
784
  } else if (toolCallArgs) {
695
- eventStream$.sendActionExecutionArgs(toolCallArgs);
785
+ eventStream$.sendActionExecutionArgs({
786
+ actionExecutionId: currentToolCallId,
787
+ args: toolCallArgs
788
+ });
696
789
  }
697
790
  break;
698
791
  }
699
792
  }
700
793
  if (inFunctionCall) {
701
- eventStream$.sendActionExecutionEnd();
794
+ eventStream$.sendActionExecutionEnd({
795
+ actionExecutionId: currentToolCallId
796
+ });
702
797
  }
703
798
  eventStream$.complete();
704
799
  });
@@ -751,46 +846,77 @@ var UnifyAdapter = class {
751
846
  }
752
847
  });
753
848
  let model = null;
849
+ let currentMessageId;
850
+ let currentToolCallId;
754
851
  request.eventSource.stream(async (eventStream$) => {
755
852
  var _a, _b;
756
853
  let mode = null;
757
854
  for await (const chunk of stream) {
758
855
  if (this.start) {
759
856
  model = chunk.model;
760
- eventStream$.sendTextMessageStart(randomId4());
761
- eventStream$.sendTextMessageContent(`Model used: ${model}
762
- `);
763
- eventStream$.sendTextMessageEnd();
857
+ currentMessageId = randomId4();
858
+ eventStream$.sendTextMessageStart({
859
+ messageId: currentMessageId
860
+ });
861
+ eventStream$.sendTextMessageContent({
862
+ messageId: currentMessageId,
863
+ content: `Model used: ${model}
864
+ `
865
+ });
866
+ eventStream$.sendTextMessageEnd({
867
+ messageId: currentMessageId
868
+ });
764
869
  this.start = false;
765
870
  }
766
871
  const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
767
872
  const content = chunk.choices[0].delta.content;
768
873
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
769
874
  mode = null;
770
- eventStream$.sendTextMessageEnd();
875
+ eventStream$.sendTextMessageEnd({
876
+ messageId: currentMessageId
877
+ });
771
878
  } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
772
879
  mode = null;
773
- eventStream$.sendActionExecutionEnd();
880
+ eventStream$.sendActionExecutionEnd({
881
+ actionExecutionId: currentToolCallId
882
+ });
774
883
  }
775
884
  if (mode === null) {
776
885
  if (toolCall == null ? void 0 : toolCall.id) {
777
886
  mode = "function";
778
- eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
887
+ currentToolCallId = toolCall.id;
888
+ eventStream$.sendActionExecutionStart({
889
+ actionExecutionId: currentToolCallId,
890
+ actionName: toolCall.function.name
891
+ });
779
892
  } else if (content) {
780
893
  mode = "message";
781
- eventStream$.sendTextMessageStart(chunk.id);
894
+ currentMessageId = chunk.id;
895
+ eventStream$.sendTextMessageStart({
896
+ messageId: currentMessageId
897
+ });
782
898
  }
783
899
  }
784
900
  if (mode === "message" && content) {
785
- eventStream$.sendTextMessageContent(content);
901
+ eventStream$.sendTextMessageContent({
902
+ messageId: currentMessageId,
903
+ content
904
+ });
786
905
  } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
787
- eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
906
+ eventStream$.sendActionExecutionArgs({
907
+ actionExecutionId: currentToolCallId,
908
+ args: toolCall.function.arguments
909
+ });
788
910
  }
789
911
  }
790
912
  if (mode === "message") {
791
- eventStream$.sendTextMessageEnd();
913
+ eventStream$.sendTextMessageEnd({
914
+ messageId: currentMessageId
915
+ });
792
916
  } else if (mode === "function") {
793
- eventStream$.sendActionExecutionEnd();
917
+ eventStream$.sendActionExecutionEnd({
918
+ actionExecutionId: currentToolCallId
919
+ });
794
920
  }
795
921
  eventStream$.complete();
796
922
  });
@@ -856,35 +982,59 @@ var GroqAdapter = class {
856
982
  eventSource.stream(async (eventStream$) => {
857
983
  var _a, _b;
858
984
  let mode = null;
985
+ let currentMessageId;
986
+ let currentToolCallId;
859
987
  for await (const chunk of stream) {
860
988
  const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
861
989
  const content = chunk.choices[0].delta.content;
862
990
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
863
991
  mode = null;
864
- eventStream$.sendTextMessageEnd();
992
+ eventStream$.sendTextMessageEnd({
993
+ messageId: currentMessageId
994
+ });
865
995
  } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
866
996
  mode = null;
867
- eventStream$.sendActionExecutionEnd();
997
+ eventStream$.sendActionExecutionEnd({
998
+ actionExecutionId: currentToolCallId
999
+ });
868
1000
  }
869
1001
  if (mode === null) {
870
1002
  if (toolCall == null ? void 0 : toolCall.id) {
871
1003
  mode = "function";
872
- eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
1004
+ currentToolCallId = toolCall.id;
1005
+ eventStream$.sendActionExecutionStart({
1006
+ actionExecutionId: currentToolCallId,
1007
+ actionName: toolCall.function.name,
1008
+ parentMessageId: chunk.id
1009
+ });
873
1010
  } else if (content) {
874
1011
  mode = "message";
875
- eventStream$.sendTextMessageStart(chunk.id);
1012
+ currentMessageId = chunk.id;
1013
+ eventStream$.sendTextMessageStart({
1014
+ messageId: currentMessageId
1015
+ });
876
1016
  }
877
1017
  }
878
1018
  if (mode === "message" && content) {
879
- eventStream$.sendTextMessageContent(content);
1019
+ eventStream$.sendTextMessageContent({
1020
+ messageId: currentMessageId,
1021
+ content
1022
+ });
880
1023
  } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
881
- eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
1024
+ eventStream$.sendActionExecutionArgs({
1025
+ actionExecutionId: currentToolCallId,
1026
+ args: toolCall.function.arguments
1027
+ });
882
1028
  }
883
1029
  }
884
1030
  if (mode === "message") {
885
- eventStream$.sendTextMessageEnd();
1031
+ eventStream$.sendTextMessageEnd({
1032
+ messageId: currentMessageId
1033
+ });
886
1034
  } else if (mode === "function") {
887
- eventStream$.sendActionExecutionEnd();
1035
+ eventStream$.sendActionExecutionEnd({
1036
+ actionExecutionId: currentToolCallId
1037
+ });
888
1038
  }
889
1039
  eventStream$.complete();
890
1040
  });
@@ -1092,7 +1242,11 @@ var AnthropicAdapter = class {
1092
1242
  mode = "message";
1093
1243
  } else if (chunk.content_block.type === "tool_use") {
1094
1244
  currentToolCallId = chunk.content_block.id;
1095
- eventStream$.sendActionExecutionStart(currentToolCallId, chunk.content_block.name);
1245
+ eventStream$.sendActionExecutionStart({
1246
+ actionExecutionId: currentToolCallId,
1247
+ actionName: chunk.content_block.name,
1248
+ parentMessageId: currentMessageId
1249
+ });
1096
1250
  mode = "function";
1097
1251
  }
1098
1252
  } else if (chunk.type === "content_block_delta") {
@@ -1100,21 +1254,33 @@ var AnthropicAdapter = class {
1100
1254
  const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
1101
1255
  if (text.length > 0) {
1102
1256
  if (!didOutputText) {
1103
- eventStream$.sendTextMessageStart(currentMessageId);
1257
+ eventStream$.sendTextMessageStart({
1258
+ messageId: currentMessageId
1259
+ });
1104
1260
  didOutputText = true;
1105
1261
  }
1106
- eventStream$.sendTextMessageContent(text);
1262
+ eventStream$.sendTextMessageContent({
1263
+ messageId: currentMessageId,
1264
+ content: text
1265
+ });
1107
1266
  }
1108
1267
  } else if (chunk.delta.type === "input_json_delta") {
1109
- eventStream$.sendActionExecutionArgs(chunk.delta.partial_json);
1268
+ eventStream$.sendActionExecutionArgs({
1269
+ actionExecutionId: currentToolCallId,
1270
+ args: chunk.delta.partial_json
1271
+ });
1110
1272
  }
1111
1273
  } else if (chunk.type === "content_block_stop") {
1112
1274
  if (mode === "message") {
1113
1275
  if (didOutputText) {
1114
- eventStream$.sendTextMessageEnd();
1276
+ eventStream$.sendTextMessageEnd({
1277
+ messageId: currentMessageId
1278
+ });
1115
1279
  }
1116
1280
  } else if (mode === "function") {
1117
- eventStream$.sendActionExecutionEnd();
1281
+ eventStream$.sendActionExecutionEnd({
1282
+ actionExecutionId: currentToolCallId
1283
+ });
1118
1284
  }
1119
1285
  }
1120
1286
  }
@@ -1159,6 +1325,60 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
1159
1325
  }
1160
1326
  }, "FilterThinkingTextBuffer");
1161
1327
 
1328
+ // src/service-adapters/experimental/ollama/ollama-adapter.ts
1329
+ import { Ollama } from "@langchain/community/llms/ollama";
1330
+ import { randomId as randomId7 } from "@copilotkit/shared";
1331
+ var DEFAULT_MODEL4 = "llama3:latest";
1332
+ var ExperimentalOllamaAdapter = class {
1333
+ model;
1334
+ constructor(options) {
1335
+ if (options == null ? void 0 : options.model) {
1336
+ this.model = options.model;
1337
+ } else {
1338
+ this.model = DEFAULT_MODEL4;
1339
+ }
1340
+ }
1341
+ async process(request) {
1342
+ const { messages, actions, eventSource } = request;
1343
+ const ollama = new Ollama({
1344
+ model: this.model
1345
+ });
1346
+ const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
1347
+ const _stream = await ollama.stream(contents);
1348
+ eventSource.stream(async (eventStream$) => {
1349
+ const currentMessageId = randomId7();
1350
+ eventStream$.sendTextMessageStart({
1351
+ messageId: currentMessageId
1352
+ });
1353
+ for await (const chunkText of _stream) {
1354
+ eventStream$.sendTextMessageContent({
1355
+ messageId: currentMessageId,
1356
+ content: chunkText
1357
+ });
1358
+ }
1359
+ eventStream$.sendTextMessageEnd({
1360
+ messageId: currentMessageId
1361
+ });
1362
+ eventStream$.complete();
1363
+ });
1364
+ return {
1365
+ threadId: request.threadId || randomId7()
1366
+ };
1367
+ }
1368
+ };
1369
+ __name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
1370
+
1371
+ // src/service-adapters/experimental/empty/empty-adapter.ts
1372
+ import { randomId as randomId8 } from "@copilotkit/shared";
1373
+ var ExperimentalEmptyAdapter = class {
1374
+ async process(request) {
1375
+ return {
1376
+ threadId: request.threadId || randomId8()
1377
+ };
1378
+ }
1379
+ };
1380
+ __name(ExperimentalEmptyAdapter, "ExperimentalEmptyAdapter");
1381
+
1162
1382
  export {
1163
1383
  RemoteChain,
1164
1384
  OpenAIAdapter,
@@ -1168,6 +1388,8 @@ export {
1168
1388
  OpenAIAssistantAdapter,
1169
1389
  UnifyAdapter,
1170
1390
  GroqAdapter,
1171
- AnthropicAdapter
1391
+ AnthropicAdapter,
1392
+ ExperimentalOllamaAdapter,
1393
+ ExperimentalEmptyAdapter
1172
1394
  };
1173
- //# sourceMappingURL=chunk-OKQVDDJ2.mjs.map
1395
+ //# sourceMappingURL=chunk-4AYRDPWK.mjs.map