@copilotkit/runtime 1.4.0-pre-1-4-0.11 → 1.4.0-pre-1-4-0.12

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 (77) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/{chunk-BNQDVBQH.mjs → chunk-56IQ6PGC.mjs} +449 -75
  3. package/dist/chunk-56IQ6PGC.mjs.map +1 -0
  4. package/dist/chunk-DFOKBSIS.mjs +1 -0
  5. package/dist/chunk-DFOKBSIS.mjs.map +1 -0
  6. package/dist/{chunk-V2YEM4Z5.mjs → chunk-JFIBAURX.mjs} +4 -3
  7. package/dist/chunk-JFIBAURX.mjs.map +1 -0
  8. package/dist/{chunk-3DNY5YTL.mjs → chunk-JFLWUR62.mjs} +5 -4
  9. package/dist/chunk-JFLWUR62.mjs.map +1 -0
  10. package/dist/{chunk-677K33J7.mjs → chunk-TZ7RGXQ6.mjs} +4 -3
  11. package/dist/chunk-TZ7RGXQ6.mjs.map +1 -0
  12. package/dist/{chunk-VBGS6IWV.mjs → chunk-YZ3VKKSM.mjs} +483 -71
  13. package/dist/chunk-YZ3VKKSM.mjs.map +1 -0
  14. package/dist/{copilot-runtime-8d3f40c7.d.ts → copilot-runtime-dbe5fa02.d.ts} +4 -4
  15. package/dist/{groq-adapter-dbfba3eb.d.ts → groq-adapter-192d2413.d.ts} +1 -1
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.js +486 -169
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +22 -22
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/{langserve-f00629d2.d.ts → langserve-878c62b9.d.ts} +46 -9
  22. package/dist/lib/index.d.ts +3 -3
  23. package/dist/lib/index.js +465 -163
  24. package/dist/lib/index.js.map +1 -1
  25. package/dist/lib/index.mjs +21 -21
  26. package/dist/lib/integrations/index.d.ts +3 -3
  27. package/dist/lib/integrations/index.js +161 -85
  28. package/dist/lib/integrations/index.js.map +1 -1
  29. package/dist/lib/integrations/index.mjs +5 -5
  30. package/dist/lib/integrations/nest/index.d.ts +2 -2
  31. package/dist/lib/integrations/nest/index.js +158 -82
  32. package/dist/lib/integrations/nest/index.js.map +1 -1
  33. package/dist/lib/integrations/nest/index.mjs +3 -3
  34. package/dist/lib/integrations/node-express/index.d.ts +2 -2
  35. package/dist/lib/integrations/node-express/index.js +158 -82
  36. package/dist/lib/integrations/node-express/index.js.map +1 -1
  37. package/dist/lib/integrations/node-express/index.mjs +3 -3
  38. package/dist/lib/integrations/node-http/index.d.ts +2 -2
  39. package/dist/lib/integrations/node-http/index.js +157 -81
  40. package/dist/lib/integrations/node-http/index.js.map +1 -1
  41. package/dist/lib/integrations/node-http/index.mjs +2 -2
  42. package/dist/service-adapters/index.d.ts +3 -3
  43. package/dist/service-adapters/index.js +243 -73
  44. package/dist/service-adapters/index.js.map +1 -1
  45. package/dist/service-adapters/index.mjs +1 -2
  46. package/package.json +4 -4
  47. package/src/agents/langgraph/event-source.ts +12 -0
  48. package/src/agents/langgraph/events.ts +2 -0
  49. package/src/graphql/resolvers/copilot.resolver.ts +28 -2
  50. package/src/lib/integrations/nest/index.ts +5 -2
  51. package/src/lib/integrations/nextjs/app-router.ts +5 -2
  52. package/src/lib/integrations/nextjs/pages-router.ts +5 -2
  53. package/src/lib/integrations/node-express/index.ts +5 -2
  54. package/src/lib/integrations/node-http/index.ts +5 -2
  55. package/src/lib/runtime/copilot-runtime.ts +48 -42
  56. package/src/lib/runtime/remote-action-constructors.ts +17 -3
  57. package/src/lib/runtime/remote-lg-cloud-action.ts +41 -15
  58. package/src/lib/telemetry-client.ts +43 -0
  59. package/src/service-adapters/anthropic/anthropic-adapter.ts +15 -6
  60. package/src/service-adapters/events.ts +86 -36
  61. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
  62. package/src/service-adapters/google/google-genai-adapter.ts +2 -2
  63. package/src/service-adapters/groq/groq-adapter.ts +22 -8
  64. package/src/service-adapters/langchain/langchain-adapter.ts +22 -16
  65. package/src/service-adapters/langchain/utils.ts +47 -31
  66. package/src/service-adapters/openai/openai-adapter.ts +25 -8
  67. package/src/service-adapters/openai/openai-assistant-adapter.ts +21 -8
  68. package/src/service-adapters/unify/unify-adapter.ts +28 -11
  69. package/dist/chunk-3DNY5YTL.mjs.map +0 -1
  70. package/dist/chunk-677K33J7.mjs.map +0 -1
  71. package/dist/chunk-BNQDVBQH.mjs.map +0 -1
  72. package/dist/chunk-FL67XJAX.mjs +0 -288
  73. package/dist/chunk-FL67XJAX.mjs.map +0 -1
  74. package/dist/chunk-MXXPWWBF.mjs +0 -218
  75. package/dist/chunk-MXXPWWBF.mjs.map +0 -1
  76. package/dist/chunk-V2YEM4Z5.mjs.map +0 -1
  77. package/dist/chunk-VBGS6IWV.mjs.map +0 -1
@@ -1,8 +1,3 @@
1
- import {
2
- convertActionInputToLangChainTool,
3
- convertMessageToLangChainMessage,
4
- streamLangChainResponse
5
- } from "./chunk-MXXPWWBF.mjs";
6
1
  import {
7
2
  __name
8
3
  } from "./chunk-44O2JGUY.mjs";
@@ -281,35 +276,61 @@ var OpenAIAdapter = class {
281
276
  eventSource.stream(async (eventStream$) => {
282
277
  var _a, _b;
283
278
  let mode = null;
279
+ let currentMessageId;
280
+ let currentToolCallId;
284
281
  for await (const chunk of stream) {
282
+ if (chunk.choices.length === 0) {
283
+ continue;
284
+ }
285
285
  const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
286
286
  const content = chunk.choices[0].delta.content;
287
287
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
288
288
  mode = null;
289
- eventStream$.sendTextMessageEnd();
289
+ eventStream$.sendTextMessageEnd({
290
+ messageId: currentMessageId
291
+ });
290
292
  } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
291
293
  mode = null;
292
- eventStream$.sendActionExecutionEnd();
294
+ eventStream$.sendActionExecutionEnd({
295
+ actionExecutionId: currentToolCallId
296
+ });
293
297
  }
294
298
  if (mode === null) {
295
299
  if (toolCall == null ? void 0 : toolCall.id) {
296
300
  mode = "function";
297
- eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
301
+ currentToolCallId = toolCall.id;
302
+ eventStream$.sendActionExecutionStart({
303
+ actionExecutionId: currentToolCallId,
304
+ actionName: toolCall.function.name
305
+ });
298
306
  } else if (content) {
299
307
  mode = "message";
300
- eventStream$.sendTextMessageStart(chunk.id);
308
+ currentMessageId = chunk.id;
309
+ eventStream$.sendTextMessageStart({
310
+ messageId: currentMessageId
311
+ });
301
312
  }
302
313
  }
303
314
  if (mode === "message" && content) {
304
- eventStream$.sendTextMessageContent(content);
315
+ eventStream$.sendTextMessageContent({
316
+ messageId: currentMessageId,
317
+ content
318
+ });
305
319
  } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
306
- eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
320
+ eventStream$.sendActionExecutionArgs({
321
+ actionExecutionId: currentToolCallId,
322
+ args: toolCall.function.arguments
323
+ });
307
324
  }
308
325
  }
309
326
  if (mode === "message") {
310
- eventStream$.sendTextMessageEnd();
327
+ eventStream$.sendTextMessageEnd({
328
+ messageId: currentMessageId
329
+ });
311
330
  } else if (mode === "function") {
312
- eventStream$.sendActionExecutionEnd();
331
+ eventStream$.sendActionExecutionEnd({
332
+ actionExecutionId: currentToolCallId
333
+ });
313
334
  }
314
335
  eventStream$.complete();
315
336
  });
@@ -320,8 +341,259 @@ var OpenAIAdapter = class {
320
341
  };
321
342
  __name(OpenAIAdapter, "OpenAIAdapter");
322
343
 
323
- // src/service-adapters/langchain/langchain-adapter.ts
344
+ // src/service-adapters/langchain/utils.ts
345
+ import { AIMessage, HumanMessage, SystemMessage, ToolMessage } from "@langchain/core/messages";
346
+ import { DynamicStructuredTool } from "@langchain/core/tools";
347
+ import { z } from "zod";
324
348
  import { randomId as randomId2 } from "@copilotkit/shared";
349
+ function convertMessageToLangChainMessage(message) {
350
+ if (message.isTextMessage()) {
351
+ if (message.role == "user") {
352
+ return new HumanMessage(message.content);
353
+ } else if (message.role == "assistant") {
354
+ return new AIMessage(message.content);
355
+ } else if (message.role === "system") {
356
+ return new SystemMessage(message.content);
357
+ }
358
+ } else if (message.isActionExecutionMessage()) {
359
+ return new AIMessage({
360
+ content: "",
361
+ tool_calls: [
362
+ {
363
+ id: message.id,
364
+ args: message.arguments,
365
+ name: message.name
366
+ }
367
+ ]
368
+ });
369
+ } else if (message.isResultMessage()) {
370
+ return new ToolMessage({
371
+ content: message.result,
372
+ tool_call_id: message.actionExecutionId
373
+ });
374
+ }
375
+ }
376
+ __name(convertMessageToLangChainMessage, "convertMessageToLangChainMessage");
377
+ function convertJsonSchemaToZodSchema(jsonSchema, required) {
378
+ if (jsonSchema.type === "object") {
379
+ const spec = {};
380
+ if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
381
+ return !required ? z.object(spec).optional() : z.object(spec);
382
+ }
383
+ for (const [key, value] of Object.entries(jsonSchema.properties)) {
384
+ spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);
385
+ }
386
+ let schema = z.object(spec).describe(jsonSchema.description);
387
+ return required ? schema : schema.optional();
388
+ } else if (jsonSchema.type === "string") {
389
+ let schema = z.string().describe(jsonSchema.description);
390
+ return required ? schema : schema.optional();
391
+ } else if (jsonSchema.type === "number") {
392
+ let schema = z.number().describe(jsonSchema.description);
393
+ return required ? schema : schema.optional();
394
+ } else if (jsonSchema.type === "boolean") {
395
+ let schema = z.boolean().describe(jsonSchema.description);
396
+ return required ? schema : schema.optional();
397
+ } else if (jsonSchema.type === "array") {
398
+ let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
399
+ let schema = z.array(itemSchema).describe(jsonSchema.description);
400
+ return required ? schema : schema.optional();
401
+ }
402
+ }
403
+ __name(convertJsonSchemaToZodSchema, "convertJsonSchemaToZodSchema");
404
+ function convertActionInputToLangChainTool(actionInput) {
405
+ return new DynamicStructuredTool({
406
+ name: actionInput.name,
407
+ description: actionInput.description,
408
+ schema: convertJsonSchemaToZodSchema(JSON.parse(actionInput.jsonSchema), true),
409
+ func: async () => {
410
+ return "";
411
+ }
412
+ });
413
+ }
414
+ __name(convertActionInputToLangChainTool, "convertActionInputToLangChainTool");
415
+ function isAIMessage(message) {
416
+ return Object.prototype.toString.call(message) === "[object AIMessage]";
417
+ }
418
+ __name(isAIMessage, "isAIMessage");
419
+ function isAIMessageChunk(message) {
420
+ return Object.prototype.toString.call(message) === "[object AIMessageChunk]";
421
+ }
422
+ __name(isAIMessageChunk, "isAIMessageChunk");
423
+ function isBaseMessageChunk(message) {
424
+ return Object.prototype.toString.call(message) === "[object BaseMessageChunk]";
425
+ }
426
+ __name(isBaseMessageChunk, "isBaseMessageChunk");
427
+ function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
428
+ if (actionExecution) {
429
+ eventStream$.sendActionExecutionResult({
430
+ actionExecutionId: actionExecution.id,
431
+ actionName: actionExecution.name,
432
+ result: "Sending a message"
433
+ });
434
+ }
435
+ }
436
+ __name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
437
+ async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
438
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
439
+ if (typeof result === "string") {
440
+ if (!actionExecution) {
441
+ eventStream$.sendTextMessage(randomId2(), result);
442
+ } else {
443
+ eventStream$.sendActionExecutionResult({
444
+ actionExecutionId: actionExecution.id,
445
+ actionName: actionExecution.name,
446
+ result
447
+ });
448
+ }
449
+ } else if (isAIMessage(result)) {
450
+ maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
451
+ if (result.content) {
452
+ eventStream$.sendTextMessage(randomId2(), result.content);
453
+ }
454
+ for (const toolCall of result.tool_calls) {
455
+ eventStream$.sendActionExecution({
456
+ actionExecutionId: toolCall.id || randomId2(),
457
+ actionName: toolCall.name,
458
+ args: JSON.stringify(toolCall.args)
459
+ });
460
+ }
461
+ } else if (isBaseMessageChunk(result)) {
462
+ maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
463
+ if ((_a = result.lc_kwargs) == null ? void 0 : _a.content) {
464
+ eventStream$.sendTextMessage(randomId2(), result.content);
465
+ }
466
+ if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
467
+ for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
468
+ eventStream$.sendActionExecution({
469
+ actionExecutionId: toolCall.id || randomId2(),
470
+ actionName: toolCall.name,
471
+ args: JSON.stringify(toolCall.args)
472
+ });
473
+ }
474
+ }
475
+ } else if (result && "getReader" in result) {
476
+ maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
477
+ let reader = result.getReader();
478
+ let mode = null;
479
+ const toolCallDetails = {
480
+ name: null,
481
+ id: null,
482
+ index: null,
483
+ prevIndex: null
484
+ };
485
+ while (true) {
486
+ try {
487
+ const { done, value } = await reader.read();
488
+ let toolCallName = void 0;
489
+ let toolCallId = void 0;
490
+ let currentMessageId;
491
+ let toolCallArgs = void 0;
492
+ let hasToolCall = false;
493
+ let content = value == null ? void 0 : value.content;
494
+ if (isAIMessageChunk(value)) {
495
+ let chunk = (_d = value.tool_call_chunks) == null ? void 0 : _d[0];
496
+ toolCallArgs = chunk == null ? void 0 : chunk.args;
497
+ hasToolCall = chunk != void 0;
498
+ if (chunk == null ? void 0 : chunk.name)
499
+ toolCallDetails.name = chunk.name;
500
+ if ((chunk == null ? void 0 : chunk.index) != null) {
501
+ toolCallDetails.index = chunk.index;
502
+ if (toolCallDetails.prevIndex == null)
503
+ toolCallDetails.prevIndex = chunk.index;
504
+ }
505
+ if (chunk == null ? void 0 : chunk.id)
506
+ toolCallDetails.id = chunk.index != null ? `${chunk.id}-idx-${chunk.index}` : chunk.id;
507
+ toolCallName = toolCallDetails.name;
508
+ toolCallId = toolCallDetails.id;
509
+ } else if (isBaseMessageChunk(value)) {
510
+ let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
511
+ toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
512
+ toolCallId = chunk == null ? void 0 : chunk.id;
513
+ toolCallArgs = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.arguments;
514
+ hasToolCall = (chunk == null ? void 0 : chunk.function) != void 0;
515
+ }
516
+ if (mode === "message" && (toolCallId || done)) {
517
+ mode = null;
518
+ eventStream$.sendTextMessageEnd({
519
+ messageId: currentMessageId
520
+ });
521
+ } else if (mode === "function" && (!hasToolCall || done)) {
522
+ mode = null;
523
+ eventStream$.sendActionExecutionEnd({
524
+ actionExecutionId: toolCallId
525
+ });
526
+ }
527
+ if (done) {
528
+ break;
529
+ }
530
+ if (mode === null) {
531
+ if (hasToolCall && toolCallId && toolCallName) {
532
+ mode = "function";
533
+ eventStream$.sendActionExecutionStart({
534
+ actionExecutionId: toolCallId,
535
+ actionName: toolCallName
536
+ });
537
+ } else if (content) {
538
+ mode = "message";
539
+ currentMessageId = randomId2();
540
+ eventStream$.sendTextMessageStart({
541
+ messageId: currentMessageId
542
+ });
543
+ }
544
+ }
545
+ if (mode === "message" && content) {
546
+ eventStream$.sendTextMessageContent({
547
+ messageId: currentMessageId,
548
+ content: Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content
549
+ });
550
+ } else if (mode === "function" && toolCallArgs) {
551
+ if (toolCallDetails.index !== toolCallDetails.prevIndex) {
552
+ eventStream$.sendActionExecutionEnd({
553
+ actionExecutionId: toolCallId
554
+ });
555
+ eventStream$.sendActionExecutionStart({
556
+ actionExecutionId: toolCallId,
557
+ actionName: toolCallName
558
+ });
559
+ toolCallDetails.prevIndex = toolCallDetails.index;
560
+ }
561
+ eventStream$.sendActionExecutionArgs({
562
+ actionExecutionId: toolCallId,
563
+ args: toolCallArgs
564
+ });
565
+ }
566
+ } catch (error) {
567
+ console.error("Error reading from stream", error);
568
+ break;
569
+ }
570
+ }
571
+ } else if (actionExecution) {
572
+ eventStream$.sendActionExecutionResult({
573
+ actionExecutionId: actionExecution.id,
574
+ actionName: actionExecution.name,
575
+ result: encodeResult(result)
576
+ });
577
+ } else {
578
+ throw new Error("Invalid return type from LangChain function.");
579
+ }
580
+ eventStream$.complete();
581
+ }
582
+ __name(streamLangChainResponse, "streamLangChainResponse");
583
+ function encodeResult(result) {
584
+ if (result === void 0) {
585
+ return "";
586
+ } else if (typeof result === "string") {
587
+ return result;
588
+ } else {
589
+ return JSON.stringify(result);
590
+ }
591
+ }
592
+ __name(encodeResult, "encodeResult");
593
+
594
+ // src/service-adapters/langchain/langchain-adapter.ts
595
+ import { randomId as randomId3 } from "@copilotkit/shared";
596
+ import { awaitAllCallbacks } from "@langchain/core/callbacks/promises";
325
597
  var LangChainAdapter = class {
326
598
  options;
327
599
  /**
@@ -331,23 +603,28 @@ var LangChainAdapter = class {
331
603
  this.options = options;
332
604
  }
333
605
  async process(request) {
334
- const { eventSource, model, actions, messages, threadId, runId } = request;
335
- const result = await this.options.chainFn({
336
- messages: messages.map(convertMessageToLangChainMessage),
337
- tools: actions.map(convertActionInputToLangChainTool),
338
- model,
339
- threadId,
340
- runId
341
- });
342
- eventSource.stream(async (eventStream$) => {
343
- await streamLangChainResponse({
344
- result,
345
- eventStream$
606
+ try {
607
+ const { eventSource, model, actions, messages, runId } = request;
608
+ const threadId = request.threadId ?? randomId3();
609
+ const result = await this.options.chainFn({
610
+ messages: messages.map(convertMessageToLangChainMessage),
611
+ tools: actions.map(convertActionInputToLangChainTool),
612
+ model,
613
+ threadId,
614
+ runId
346
615
  });
347
- });
348
- return {
349
- threadId: threadId || randomId2()
350
- };
616
+ eventSource.stream(async (eventStream$) => {
617
+ await streamLangChainResponse({
618
+ result,
619
+ eventStream$
620
+ });
621
+ });
622
+ return {
623
+ threadId
624
+ };
625
+ } finally {
626
+ await awaitAllCallbacks();
627
+ }
351
628
  }
352
629
  };
353
630
  __name(LangChainAdapter, "LangChainAdapter");
@@ -357,12 +634,16 @@ import { ChatGoogle } from "@langchain/google-gauth";
357
634
  var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
358
635
  constructor(options) {
359
636
  super({
360
- chainFn: async ({ messages, tools }) => {
637
+ chainFn: async ({ messages, tools, threadId }) => {
361
638
  const model = new ChatGoogle({
362
639
  modelName: (options == null ? void 0 : options.model) ?? "gemini-1.5-pro",
363
640
  apiVersion: "v1beta"
364
641
  }).bindTools(tools);
365
- return model.stream(messages);
642
+ return model.stream(messages, {
643
+ metadata: {
644
+ conversation_id: threadId
645
+ }
646
+ });
366
647
  }
367
648
  });
368
649
  }
@@ -472,21 +753,33 @@ var OpenAIAssistantAdapter = class {
472
753
  eventSource.stream(async (eventStream$) => {
473
754
  var _a, _b, _c, _d, _e, _f;
474
755
  let inFunctionCall = false;
756
+ let currentMessageId;
757
+ let currentToolCallId;
475
758
  for await (const chunk of stream) {
476
759
  switch (chunk.event) {
477
760
  case "thread.message.created":
478
761
  if (inFunctionCall) {
479
- eventStream$.sendActionExecutionEnd();
762
+ eventStream$.sendActionExecutionEnd({
763
+ actionExecutionId: currentToolCallId
764
+ });
480
765
  }
481
- eventStream$.sendTextMessageStart(chunk.data.id);
766
+ currentMessageId = chunk.data.id;
767
+ eventStream$.sendTextMessageStart({
768
+ messageId: currentMessageId
769
+ });
482
770
  break;
483
771
  case "thread.message.delta":
484
772
  if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
485
- eventStream$.sendTextMessageContent((_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value);
773
+ eventStream$.sendTextMessageContent({
774
+ messageId: currentMessageId,
775
+ content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
776
+ });
486
777
  }
487
778
  break;
488
779
  case "thread.message.completed":
489
- eventStream$.sendTextMessageEnd();
780
+ eventStream$.sendTextMessageEnd({
781
+ messageId: currentMessageId
782
+ });
490
783
  break;
491
784
  case "thread.run.step.delta":
492
785
  let toolCallId;
@@ -499,18 +792,29 @@ var OpenAIAssistantAdapter = class {
499
792
  }
500
793
  if (toolCallName && toolCallId) {
501
794
  if (inFunctionCall) {
502
- eventStream$.sendActionExecutionEnd();
795
+ eventStream$.sendActionExecutionEnd({
796
+ actionExecutionId: currentToolCallId
797
+ });
503
798
  }
504
799
  inFunctionCall = true;
505
- eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
800
+ currentToolCallId = toolCallId;
801
+ eventStream$.sendActionExecutionStart({
802
+ actionExecutionId: currentToolCallId,
803
+ actionName: toolCallName
804
+ });
506
805
  } else if (toolCallArgs) {
507
- eventStream$.sendActionExecutionArgs(toolCallArgs);
806
+ eventStream$.sendActionExecutionArgs({
807
+ actionExecutionId: currentToolCallId,
808
+ args: toolCallArgs
809
+ });
508
810
  }
509
811
  break;
510
812
  }
511
813
  }
512
814
  if (inFunctionCall) {
513
- eventStream$.sendActionExecutionEnd();
815
+ eventStream$.sendActionExecutionEnd({
816
+ actionExecutionId: currentToolCallId
817
+ });
514
818
  }
515
819
  eventStream$.complete();
516
820
  });
@@ -533,7 +837,7 @@ __name(getRunIdFromStream, "getRunIdFromStream");
533
837
 
534
838
  // src/service-adapters/unify/unify-adapter.ts
535
839
  import OpenAI3 from "openai";
536
- import { randomId as randomId3 } from "@copilotkit/shared";
840
+ import { randomId as randomId4 } from "@copilotkit/shared";
537
841
  var UnifyAdapter = class {
538
842
  apiKey;
539
843
  model;
@@ -563,51 +867,82 @@ var UnifyAdapter = class {
563
867
  }
564
868
  });
565
869
  let model = null;
870
+ let currentMessageId;
871
+ let currentToolCallId;
566
872
  request.eventSource.stream(async (eventStream$) => {
567
873
  var _a, _b;
568
874
  let mode = null;
569
875
  for await (const chunk of stream) {
570
876
  if (this.start) {
571
877
  model = chunk.model;
572
- eventStream$.sendTextMessageStart(randomId3());
573
- eventStream$.sendTextMessageContent(`Model used: ${model}
574
- `);
575
- eventStream$.sendTextMessageEnd();
878
+ currentMessageId = randomId4();
879
+ eventStream$.sendTextMessageStart({
880
+ messageId: currentMessageId
881
+ });
882
+ eventStream$.sendTextMessageContent({
883
+ messageId: currentMessageId,
884
+ content: `Model used: ${model}
885
+ `
886
+ });
887
+ eventStream$.sendTextMessageEnd({
888
+ messageId: currentMessageId
889
+ });
576
890
  this.start = false;
577
891
  }
578
892
  const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
579
893
  const content = chunk.choices[0].delta.content;
580
894
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
581
895
  mode = null;
582
- eventStream$.sendTextMessageEnd();
896
+ eventStream$.sendTextMessageEnd({
897
+ messageId: currentMessageId
898
+ });
583
899
  } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
584
900
  mode = null;
585
- eventStream$.sendActionExecutionEnd();
901
+ eventStream$.sendActionExecutionEnd({
902
+ actionExecutionId: currentToolCallId
903
+ });
586
904
  }
587
905
  if (mode === null) {
588
906
  if (toolCall == null ? void 0 : toolCall.id) {
589
907
  mode = "function";
590
- eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
908
+ currentToolCallId = toolCall.id;
909
+ eventStream$.sendActionExecutionStart({
910
+ actionExecutionId: currentToolCallId,
911
+ actionName: toolCall.function.name
912
+ });
591
913
  } else if (content) {
592
914
  mode = "message";
593
- eventStream$.sendTextMessageStart(chunk.id);
915
+ currentMessageId = chunk.id;
916
+ eventStream$.sendTextMessageStart({
917
+ messageId: currentMessageId
918
+ });
594
919
  }
595
920
  }
596
921
  if (mode === "message" && content) {
597
- eventStream$.sendTextMessageContent(content);
922
+ eventStream$.sendTextMessageContent({
923
+ messageId: currentMessageId,
924
+ content
925
+ });
598
926
  } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
599
- eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
927
+ eventStream$.sendActionExecutionArgs({
928
+ actionExecutionId: currentToolCallId,
929
+ args: toolCall.function.arguments
930
+ });
600
931
  }
601
932
  }
602
933
  if (mode === "message") {
603
- eventStream$.sendTextMessageEnd();
934
+ eventStream$.sendTextMessageEnd({
935
+ messageId: currentMessageId
936
+ });
604
937
  } else if (mode === "function") {
605
- eventStream$.sendActionExecutionEnd();
938
+ eventStream$.sendActionExecutionEnd({
939
+ actionExecutionId: currentToolCallId
940
+ });
606
941
  }
607
942
  eventStream$.complete();
608
943
  });
609
944
  return {
610
- threadId: request.threadId || randomId3()
945
+ threadId: request.threadId || randomId4()
611
946
  };
612
947
  }
613
948
  };
@@ -615,7 +950,7 @@ __name(UnifyAdapter, "UnifyAdapter");
615
950
 
616
951
  // src/service-adapters/groq/groq-adapter.ts
617
952
  import { Groq } from "groq-sdk";
618
- import { randomId as randomId4 } from "@copilotkit/shared";
953
+ import { randomId as randomId5 } from "@copilotkit/shared";
619
954
  var DEFAULT_MODEL2 = "llama3-groq-70b-8192-tool-use-preview";
620
955
  var GroqAdapter = class {
621
956
  model = DEFAULT_MODEL2;
@@ -668,40 +1003,63 @@ var GroqAdapter = class {
668
1003
  eventSource.stream(async (eventStream$) => {
669
1004
  var _a, _b;
670
1005
  let mode = null;
1006
+ let currentMessageId;
1007
+ let currentToolCallId;
671
1008
  for await (const chunk of stream) {
672
1009
  const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
673
1010
  const content = chunk.choices[0].delta.content;
674
1011
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
675
1012
  mode = null;
676
- eventStream$.sendTextMessageEnd();
1013
+ eventStream$.sendTextMessageEnd({
1014
+ messageId: currentMessageId
1015
+ });
677
1016
  } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
678
1017
  mode = null;
679
- eventStream$.sendActionExecutionEnd();
1018
+ eventStream$.sendActionExecutionEnd({
1019
+ actionExecutionId: currentToolCallId
1020
+ });
680
1021
  }
681
1022
  if (mode === null) {
682
1023
  if (toolCall == null ? void 0 : toolCall.id) {
683
1024
  mode = "function";
684
- eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
1025
+ currentToolCallId = toolCall.id;
1026
+ eventStream$.sendActionExecutionStart({
1027
+ actionExecutionId: currentToolCallId,
1028
+ actionName: toolCall.function.name
1029
+ });
685
1030
  } else if (content) {
686
1031
  mode = "message";
687
- eventStream$.sendTextMessageStart(chunk.id);
1032
+ currentMessageId = chunk.id;
1033
+ eventStream$.sendTextMessageStart({
1034
+ messageId: currentMessageId
1035
+ });
688
1036
  }
689
1037
  }
690
1038
  if (mode === "message" && content) {
691
- eventStream$.sendTextMessageContent(content);
1039
+ eventStream$.sendTextMessageContent({
1040
+ messageId: currentMessageId,
1041
+ content
1042
+ });
692
1043
  } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
693
- eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
1044
+ eventStream$.sendActionExecutionArgs({
1045
+ actionExecutionId: currentToolCallId,
1046
+ args: toolCall.function.arguments
1047
+ });
694
1048
  }
695
1049
  }
696
1050
  if (mode === "message") {
697
- eventStream$.sendTextMessageEnd();
1051
+ eventStream$.sendTextMessageEnd({
1052
+ messageId: currentMessageId
1053
+ });
698
1054
  } else if (mode === "function") {
699
- eventStream$.sendActionExecutionEnd();
1055
+ eventStream$.sendActionExecutionEnd({
1056
+ actionExecutionId: currentToolCallId
1057
+ });
700
1058
  }
701
1059
  eventStream$.complete();
702
1060
  });
703
1061
  return {
704
- threadId: threadId || randomId4()
1062
+ threadId: threadId || randomId5()
705
1063
  };
706
1064
  }
707
1065
  };
@@ -843,7 +1201,7 @@ function groupAnthropicMessagesByRole(messageParams) {
843
1201
  __name(groupAnthropicMessagesByRole, "groupAnthropicMessagesByRole");
844
1202
 
845
1203
  // src/service-adapters/anthropic/anthropic-adapter.ts
846
- import { randomId as randomId5 } from "@copilotkit/shared";
1204
+ import { randomId as randomId6 } from "@copilotkit/shared";
847
1205
  var DEFAULT_MODEL3 = "claude-3-sonnet-20240229";
848
1206
  var AnthropicAdapter = class {
849
1207
  model = DEFAULT_MODEL3;
@@ -891,8 +1249,8 @@ var AnthropicAdapter = class {
891
1249
  eventSource.stream(async (eventStream$) => {
892
1250
  let mode = null;
893
1251
  let didOutputText = false;
894
- let currentMessageId = randomId5();
895
- let currentToolCallId = randomId5();
1252
+ let currentMessageId = randomId6();
1253
+ let currentToolCallId = randomId6();
896
1254
  let filterThinkingTextBuffer = new FilterThinkingTextBuffer();
897
1255
  for await (const chunk of await stream) {
898
1256
  if (chunk.type === "message_start") {
@@ -904,7 +1262,10 @@ var AnthropicAdapter = class {
904
1262
  mode = "message";
905
1263
  } else if (chunk.content_block.type === "tool_use") {
906
1264
  currentToolCallId = chunk.content_block.id;
907
- eventStream$.sendActionExecutionStart(currentToolCallId, chunk.content_block.name);
1265
+ eventStream$.sendActionExecutionStart({
1266
+ actionExecutionId: currentToolCallId,
1267
+ actionName: chunk.content_block.name
1268
+ });
908
1269
  mode = "function";
909
1270
  }
910
1271
  } else if (chunk.type === "content_block_delta") {
@@ -912,28 +1273,40 @@ var AnthropicAdapter = class {
912
1273
  const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
913
1274
  if (text.length > 0) {
914
1275
  if (!didOutputText) {
915
- eventStream$.sendTextMessageStart(currentMessageId);
1276
+ eventStream$.sendTextMessageStart({
1277
+ messageId: currentMessageId
1278
+ });
916
1279
  didOutputText = true;
917
1280
  }
918
- eventStream$.sendTextMessageContent(text);
1281
+ eventStream$.sendTextMessageContent({
1282
+ messageId: currentMessageId,
1283
+ content: text
1284
+ });
919
1285
  }
920
1286
  } else if (chunk.delta.type === "input_json_delta") {
921
- eventStream$.sendActionExecutionArgs(chunk.delta.partial_json);
1287
+ eventStream$.sendActionExecutionArgs({
1288
+ actionExecutionId: currentToolCallId,
1289
+ args: chunk.delta.partial_json
1290
+ });
922
1291
  }
923
1292
  } else if (chunk.type === "content_block_stop") {
924
1293
  if (mode === "message") {
925
1294
  if (didOutputText) {
926
- eventStream$.sendTextMessageEnd();
1295
+ eventStream$.sendTextMessageEnd({
1296
+ messageId: currentMessageId
1297
+ });
927
1298
  }
928
1299
  } else if (mode === "function") {
929
- eventStream$.sendActionExecutionEnd();
1300
+ eventStream$.sendActionExecutionEnd({
1301
+ actionExecutionId: currentToolCallId
1302
+ });
930
1303
  }
931
1304
  }
932
1305
  }
933
1306
  eventStream$.complete();
934
1307
  });
935
1308
  return {
936
- threadId: threadId || randomId5()
1309
+ threadId: threadId || randomId6()
937
1310
  };
938
1311
  }
939
1312
  };
@@ -974,6 +1347,7 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
974
1347
  export {
975
1348
  RemoteChain,
976
1349
  OpenAIAdapter,
1350
+ streamLangChainResponse,
977
1351
  LangChainAdapter,
978
1352
  GoogleGenerativeAIAdapter,
979
1353
  OpenAIAssistantAdapter,
@@ -981,4 +1355,4 @@ export {
981
1355
  GroqAdapter,
982
1356
  AnthropicAdapter
983
1357
  };
984
- //# sourceMappingURL=chunk-BNQDVBQH.mjs.map
1358
+ //# sourceMappingURL=chunk-56IQ6PGC.mjs.map