@copilotkit/runtime 1.4.7 → 1.4.8-coagents-v0-3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/__snapshots__/schema/schema.graphql +7 -9
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-2PK2SFRB.mjs} +220 -57
- package/dist/chunk-2PK2SFRB.mjs.map +1 -0
- package/dist/{chunk-XWWKPWHL.mjs → chunk-BACNNHHI.mjs} +2 -2
- package/dist/{chunk-44ICGB7P.mjs → chunk-FVYNRYIB.mjs} +420 -296
- package/dist/chunk-FVYNRYIB.mjs.map +1 -0
- package/dist/{chunk-BE5WOXMD.mjs → chunk-MQJNZYAH.mjs} +2 -2
- package/dist/{chunk-B74M7FXG.mjs → chunk-RFF5IIZJ.mjs} +3 -2
- package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
- package/dist/{chunk-DRO25ADD.mjs → chunk-YFG3Q3YH.mjs} +2 -2
- package/dist/{copilot-runtime-12e7ac40.d.ts → copilot-runtime-b15b683d.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +2 -1
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -1
- package/dist/{groq-adapter-24abe931.d.ts → groq-adapter-50aa9621.d.ts} +1 -1
- package/dist/{index-10b1c870.d.ts → index-ff3fbc33.d.ts} +7 -8
- package/dist/index.d.ts +4 -4
- package/dist/index.js +725 -437
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/{langserve-f021ab9c.d.ts → langserve-8ec29cba.d.ts} +51 -12
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +703 -431
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +71 -30
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +6 -6
- package/dist/lib/integrations/nest/index.d.ts +3 -3
- package/dist/lib/integrations/nest/index.js +71 -30
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +4 -4
- package/dist/lib/integrations/node-express/index.d.ts +3 -3
- package/dist/lib/integrations/node-express/index.js +71 -30
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +4 -4
- package/dist/lib/integrations/node-http/index.d.ts +3 -3
- package/dist/lib/integrations/node-http/index.js +71 -30
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +3 -3
- package/dist/service-adapters/index.d.ts +4 -4
- package/dist/service-adapters/index.js +219 -56
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +140 -148
- package/src/agents/langgraph/events.ts +1 -1
- package/src/graphql/inputs/message.input.ts +15 -3
- package/src/graphql/resolvers/copilot.resolver.ts +32 -6
- package/src/graphql/types/converted/index.ts +4 -3
- package/src/graphql/types/copilot-response.type.ts +12 -3
- package/src/graphql/types/enums.ts +0 -11
- package/src/lib/runtime/remote-action-constructors.ts +4 -2
- package/src/lib/runtime/remote-actions.ts +1 -0
- package/src/lib/runtime/remote-lg-action.ts +161 -140
- package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -6
- package/src/service-adapters/conversion.ts +2 -1
- package/src/service-adapters/events.ts +111 -52
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
- package/src/service-adapters/groq/groq-adapter.ts +23 -8
- package/src/service-adapters/langchain/utils.ts +49 -31
- package/src/service-adapters/openai/openai-adapter.ts +22 -9
- package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
- package/src/service-adapters/unify/unify-adapter.ts +28 -11
- package/dist/chunk-44ICGB7P.mjs.map +0 -1
- package/dist/chunk-B74M7FXG.mjs.map +0 -1
- package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
- /package/dist/{chunk-XWWKPWHL.mjs.map → chunk-BACNNHHI.mjs.map} +0 -0
- /package/dist/{chunk-BE5WOXMD.mjs.map → chunk-MQJNZYAH.mjs.map} +0 -0
- /package/dist/{chunk-DRO25ADD.mjs.map → chunk-YFG3Q3YH.mjs.map} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as CopilotServiceAdapter, c as CopilotRuntimeChatCompletionRequest, d as CopilotRuntimeChatCompletionResponse } from '../langserve-
|
|
2
|
-
export { a as RemoteChain, R as RemoteChainParameters } from '../langserve-
|
|
3
|
-
export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-
|
|
1
|
+
import { C as CopilotServiceAdapter, c as CopilotRuntimeChatCompletionRequest, d as CopilotRuntimeChatCompletionResponse } from '../langserve-8ec29cba.js';
|
|
2
|
+
export { a as RemoteChain, R as RemoteChainParameters } from '../langserve-8ec29cba.js';
|
|
3
|
+
export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from '../groq-adapter-50aa9621.js';
|
|
4
4
|
import Anthropic from '@anthropic-ai/sdk';
|
|
5
|
-
import '../index-
|
|
5
|
+
import '../index-ff3fbc33.js';
|
|
6
6
|
import '../graphql/types/base/index.js';
|
|
7
7
|
import 'rxjs';
|
|
8
8
|
import '@copilotkit/shared';
|
|
@@ -315,6 +315,8 @@ var OpenAIAdapter = class {
|
|
|
315
315
|
eventSource.stream(async (eventStream$) => {
|
|
316
316
|
var _a, _b;
|
|
317
317
|
let mode = null;
|
|
318
|
+
let currentMessageId;
|
|
319
|
+
let currentToolCallId;
|
|
318
320
|
for await (const chunk of stream) {
|
|
319
321
|
if (chunk.choices.length === 0) {
|
|
320
322
|
continue;
|
|
@@ -323,30 +325,52 @@ var OpenAIAdapter = class {
|
|
|
323
325
|
const content = chunk.choices[0].delta.content;
|
|
324
326
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
325
327
|
mode = null;
|
|
326
|
-
eventStream$.sendTextMessageEnd(
|
|
328
|
+
eventStream$.sendTextMessageEnd({
|
|
329
|
+
messageId: currentMessageId
|
|
330
|
+
});
|
|
327
331
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
328
332
|
mode = null;
|
|
329
|
-
eventStream$.sendActionExecutionEnd(
|
|
333
|
+
eventStream$.sendActionExecutionEnd({
|
|
334
|
+
actionExecutionId: currentToolCallId
|
|
335
|
+
});
|
|
330
336
|
}
|
|
331
337
|
if (mode === null) {
|
|
332
338
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
333
339
|
mode = "function";
|
|
334
|
-
|
|
340
|
+
currentToolCallId = toolCall.id;
|
|
341
|
+
eventStream$.sendActionExecutionStart({
|
|
342
|
+
actionExecutionId: currentToolCallId,
|
|
343
|
+
parentMessageId: chunk.id,
|
|
344
|
+
actionName: toolCall.function.name
|
|
345
|
+
});
|
|
335
346
|
} else if (content) {
|
|
336
347
|
mode = "message";
|
|
337
|
-
|
|
348
|
+
currentMessageId = chunk.id;
|
|
349
|
+
eventStream$.sendTextMessageStart({
|
|
350
|
+
messageId: currentMessageId
|
|
351
|
+
});
|
|
338
352
|
}
|
|
339
353
|
}
|
|
340
354
|
if (mode === "message" && content) {
|
|
341
|
-
eventStream$.sendTextMessageContent(
|
|
355
|
+
eventStream$.sendTextMessageContent({
|
|
356
|
+
messageId: currentMessageId,
|
|
357
|
+
content
|
|
358
|
+
});
|
|
342
359
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
343
|
-
eventStream$.sendActionExecutionArgs(
|
|
360
|
+
eventStream$.sendActionExecutionArgs({
|
|
361
|
+
actionExecutionId: currentToolCallId,
|
|
362
|
+
args: toolCall.function.arguments
|
|
363
|
+
});
|
|
344
364
|
}
|
|
345
365
|
}
|
|
346
366
|
if (mode === "message") {
|
|
347
|
-
eventStream$.sendTextMessageEnd(
|
|
367
|
+
eventStream$.sendTextMessageEnd({
|
|
368
|
+
messageId: currentMessageId
|
|
369
|
+
});
|
|
348
370
|
} else if (mode === "function") {
|
|
349
|
-
eventStream$.sendActionExecutionEnd(
|
|
371
|
+
eventStream$.sendActionExecutionEnd({
|
|
372
|
+
actionExecutionId: currentToolCallId
|
|
373
|
+
});
|
|
350
374
|
}
|
|
351
375
|
eventStream$.complete();
|
|
352
376
|
});
|
|
@@ -414,17 +438,25 @@ function isBaseMessageChunk(message) {
|
|
|
414
438
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
415
439
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
416
440
|
if (actionExecution) {
|
|
417
|
-
eventStream$.sendActionExecutionResult(
|
|
441
|
+
eventStream$.sendActionExecutionResult({
|
|
442
|
+
actionExecutionId: actionExecution.id,
|
|
443
|
+
actionName: actionExecution.name,
|
|
444
|
+
result: "Sending a message"
|
|
445
|
+
});
|
|
418
446
|
}
|
|
419
447
|
}
|
|
420
448
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
421
449
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
422
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
450
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
423
451
|
if (typeof result === "string") {
|
|
424
452
|
if (!actionExecution) {
|
|
425
453
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
|
|
426
454
|
} else {
|
|
427
|
-
eventStream$.sendActionExecutionResult(
|
|
455
|
+
eventStream$.sendActionExecutionResult({
|
|
456
|
+
actionExecutionId: actionExecution.id,
|
|
457
|
+
actionName: actionExecution.name,
|
|
458
|
+
result
|
|
459
|
+
});
|
|
428
460
|
}
|
|
429
461
|
} else if (isAIMessage(result)) {
|
|
430
462
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -432,7 +464,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
432
464
|
eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
|
|
433
465
|
}
|
|
434
466
|
for (const toolCall of result.tool_calls) {
|
|
435
|
-
eventStream$.sendActionExecution(
|
|
467
|
+
eventStream$.sendActionExecution({
|
|
468
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
469
|
+
actionName: toolCall.name,
|
|
470
|
+
args: JSON.stringify(toolCall.args)
|
|
471
|
+
});
|
|
436
472
|
}
|
|
437
473
|
} else if (isBaseMessageChunk(result)) {
|
|
438
474
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -441,13 +477,18 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
441
477
|
}
|
|
442
478
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
443
479
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
444
|
-
eventStream$.sendActionExecution(
|
|
480
|
+
eventStream$.sendActionExecution({
|
|
481
|
+
actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
|
|
482
|
+
actionName: toolCall.name,
|
|
483
|
+
args: JSON.stringify(toolCall.args)
|
|
484
|
+
});
|
|
445
485
|
}
|
|
446
486
|
}
|
|
447
487
|
} else if (result && "getReader" in result) {
|
|
448
488
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
449
489
|
let reader = result.getReader();
|
|
450
490
|
let mode = null;
|
|
491
|
+
let currentMessageId;
|
|
451
492
|
const toolCallDetails = {
|
|
452
493
|
name: null,
|
|
453
494
|
id: null,
|
|
@@ -486,10 +527,14 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
486
527
|
}
|
|
487
528
|
if (mode === "message" && (toolCallId || done)) {
|
|
488
529
|
mode = null;
|
|
489
|
-
eventStream$.sendTextMessageEnd(
|
|
530
|
+
eventStream$.sendTextMessageEnd({
|
|
531
|
+
messageId: currentMessageId
|
|
532
|
+
});
|
|
490
533
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
491
534
|
mode = null;
|
|
492
|
-
eventStream$.sendActionExecutionEnd(
|
|
535
|
+
eventStream$.sendActionExecutionEnd({
|
|
536
|
+
actionExecutionId: toolCallId
|
|
537
|
+
});
|
|
493
538
|
}
|
|
494
539
|
if (done) {
|
|
495
540
|
break;
|
|
@@ -497,21 +542,40 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
497
542
|
if (mode === null) {
|
|
498
543
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
499
544
|
mode = "function";
|
|
500
|
-
eventStream$.sendActionExecutionStart(
|
|
545
|
+
eventStream$.sendActionExecutionStart({
|
|
546
|
+
actionExecutionId: toolCallId,
|
|
547
|
+
actionName: toolCallName,
|
|
548
|
+
parentMessageId: (_i = value.lc_kwargs) == null ? void 0 : _i.id
|
|
549
|
+
});
|
|
501
550
|
} else if (content) {
|
|
502
551
|
mode = "message";
|
|
503
|
-
|
|
552
|
+
currentMessageId = ((_j = value.lc_kwargs) == null ? void 0 : _j.id) || (0, import_shared2.randomId)();
|
|
553
|
+
eventStream$.sendTextMessageStart({
|
|
554
|
+
messageId: currentMessageId
|
|
555
|
+
});
|
|
504
556
|
}
|
|
505
557
|
}
|
|
506
558
|
if (mode === "message" && content) {
|
|
507
|
-
eventStream$.sendTextMessageContent(
|
|
559
|
+
eventStream$.sendTextMessageContent({
|
|
560
|
+
messageId: currentMessageId,
|
|
561
|
+
content: Array.isArray(content) ? ((_k = content[0]) == null ? void 0 : _k.text) ?? "" : content
|
|
562
|
+
});
|
|
508
563
|
} else if (mode === "function" && toolCallArgs) {
|
|
509
564
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
510
|
-
eventStream$.sendActionExecutionEnd(
|
|
511
|
-
|
|
565
|
+
eventStream$.sendActionExecutionEnd({
|
|
566
|
+
actionExecutionId: toolCallId
|
|
567
|
+
});
|
|
568
|
+
eventStream$.sendActionExecutionStart({
|
|
569
|
+
actionExecutionId: toolCallId,
|
|
570
|
+
actionName: toolCallName,
|
|
571
|
+
parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
|
|
572
|
+
});
|
|
512
573
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
513
574
|
}
|
|
514
|
-
eventStream$.sendActionExecutionArgs(
|
|
575
|
+
eventStream$.sendActionExecutionArgs({
|
|
576
|
+
actionExecutionId: toolCallId,
|
|
577
|
+
args: toolCallArgs
|
|
578
|
+
});
|
|
515
579
|
}
|
|
516
580
|
} catch (error) {
|
|
517
581
|
console.error("Error reading from stream", error);
|
|
@@ -519,7 +583,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
519
583
|
}
|
|
520
584
|
}
|
|
521
585
|
} else if (actionExecution) {
|
|
522
|
-
eventStream$.sendActionExecutionResult(
|
|
586
|
+
eventStream$.sendActionExecutionResult({
|
|
587
|
+
actionExecutionId: actionExecution.id,
|
|
588
|
+
actionName: actionExecution.name,
|
|
589
|
+
result: encodeResult(result)
|
|
590
|
+
});
|
|
523
591
|
} else {
|
|
524
592
|
throw new Error("Invalid return type from LangChain function.");
|
|
525
593
|
}
|
|
@@ -699,21 +767,33 @@ var OpenAIAssistantAdapter = class {
|
|
|
699
767
|
eventSource.stream(async (eventStream$) => {
|
|
700
768
|
var _a, _b, _c, _d, _e, _f;
|
|
701
769
|
let inFunctionCall = false;
|
|
770
|
+
let currentMessageId;
|
|
771
|
+
let currentToolCallId;
|
|
702
772
|
for await (const chunk of stream) {
|
|
703
773
|
switch (chunk.event) {
|
|
704
774
|
case "thread.message.created":
|
|
705
775
|
if (inFunctionCall) {
|
|
706
|
-
eventStream$.sendActionExecutionEnd(
|
|
776
|
+
eventStream$.sendActionExecutionEnd({
|
|
777
|
+
actionExecutionId: currentToolCallId
|
|
778
|
+
});
|
|
707
779
|
}
|
|
708
|
-
|
|
780
|
+
currentMessageId = chunk.data.id;
|
|
781
|
+
eventStream$.sendTextMessageStart({
|
|
782
|
+
messageId: currentMessageId
|
|
783
|
+
});
|
|
709
784
|
break;
|
|
710
785
|
case "thread.message.delta":
|
|
711
786
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
712
|
-
eventStream$.sendTextMessageContent(
|
|
787
|
+
eventStream$.sendTextMessageContent({
|
|
788
|
+
messageId: currentMessageId,
|
|
789
|
+
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
790
|
+
});
|
|
713
791
|
}
|
|
714
792
|
break;
|
|
715
793
|
case "thread.message.completed":
|
|
716
|
-
eventStream$.sendTextMessageEnd(
|
|
794
|
+
eventStream$.sendTextMessageEnd({
|
|
795
|
+
messageId: currentMessageId
|
|
796
|
+
});
|
|
717
797
|
break;
|
|
718
798
|
case "thread.run.step.delta":
|
|
719
799
|
let toolCallId;
|
|
@@ -726,18 +806,30 @@ var OpenAIAssistantAdapter = class {
|
|
|
726
806
|
}
|
|
727
807
|
if (toolCallName && toolCallId) {
|
|
728
808
|
if (inFunctionCall) {
|
|
729
|
-
eventStream$.sendActionExecutionEnd(
|
|
809
|
+
eventStream$.sendActionExecutionEnd({
|
|
810
|
+
actionExecutionId: currentToolCallId
|
|
811
|
+
});
|
|
730
812
|
}
|
|
731
813
|
inFunctionCall = true;
|
|
732
|
-
|
|
814
|
+
currentToolCallId = toolCallId;
|
|
815
|
+
eventStream$.sendActionExecutionStart({
|
|
816
|
+
actionExecutionId: currentToolCallId,
|
|
817
|
+
parentMessageId: chunk.data.id,
|
|
818
|
+
actionName: toolCallName
|
|
819
|
+
});
|
|
733
820
|
} else if (toolCallArgs) {
|
|
734
|
-
eventStream$.sendActionExecutionArgs(
|
|
821
|
+
eventStream$.sendActionExecutionArgs({
|
|
822
|
+
actionExecutionId: currentToolCallId,
|
|
823
|
+
args: toolCallArgs
|
|
824
|
+
});
|
|
735
825
|
}
|
|
736
826
|
break;
|
|
737
827
|
}
|
|
738
828
|
}
|
|
739
829
|
if (inFunctionCall) {
|
|
740
|
-
eventStream$.sendActionExecutionEnd(
|
|
830
|
+
eventStream$.sendActionExecutionEnd({
|
|
831
|
+
actionExecutionId: currentToolCallId
|
|
832
|
+
});
|
|
741
833
|
}
|
|
742
834
|
eventStream$.complete();
|
|
743
835
|
});
|
|
@@ -790,46 +882,77 @@ var UnifyAdapter = class {
|
|
|
790
882
|
}
|
|
791
883
|
});
|
|
792
884
|
let model = null;
|
|
885
|
+
let currentMessageId;
|
|
886
|
+
let currentToolCallId;
|
|
793
887
|
request.eventSource.stream(async (eventStream$) => {
|
|
794
888
|
var _a, _b;
|
|
795
889
|
let mode = null;
|
|
796
890
|
for await (const chunk of stream) {
|
|
797
891
|
if (this.start) {
|
|
798
892
|
model = chunk.model;
|
|
799
|
-
|
|
800
|
-
eventStream$.
|
|
801
|
-
|
|
802
|
-
|
|
893
|
+
currentMessageId = (0, import_shared4.randomId)();
|
|
894
|
+
eventStream$.sendTextMessageStart({
|
|
895
|
+
messageId: currentMessageId
|
|
896
|
+
});
|
|
897
|
+
eventStream$.sendTextMessageContent({
|
|
898
|
+
messageId: currentMessageId,
|
|
899
|
+
content: `Model used: ${model}
|
|
900
|
+
`
|
|
901
|
+
});
|
|
902
|
+
eventStream$.sendTextMessageEnd({
|
|
903
|
+
messageId: currentMessageId
|
|
904
|
+
});
|
|
803
905
|
this.start = false;
|
|
804
906
|
}
|
|
805
907
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
806
908
|
const content = chunk.choices[0].delta.content;
|
|
807
909
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
808
910
|
mode = null;
|
|
809
|
-
eventStream$.sendTextMessageEnd(
|
|
911
|
+
eventStream$.sendTextMessageEnd({
|
|
912
|
+
messageId: currentMessageId
|
|
913
|
+
});
|
|
810
914
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
811
915
|
mode = null;
|
|
812
|
-
eventStream$.sendActionExecutionEnd(
|
|
916
|
+
eventStream$.sendActionExecutionEnd({
|
|
917
|
+
actionExecutionId: currentToolCallId
|
|
918
|
+
});
|
|
813
919
|
}
|
|
814
920
|
if (mode === null) {
|
|
815
921
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
816
922
|
mode = "function";
|
|
817
|
-
|
|
923
|
+
currentToolCallId = toolCall.id;
|
|
924
|
+
eventStream$.sendActionExecutionStart({
|
|
925
|
+
actionExecutionId: currentToolCallId,
|
|
926
|
+
actionName: toolCall.function.name
|
|
927
|
+
});
|
|
818
928
|
} else if (content) {
|
|
819
929
|
mode = "message";
|
|
820
|
-
|
|
930
|
+
currentMessageId = chunk.id;
|
|
931
|
+
eventStream$.sendTextMessageStart({
|
|
932
|
+
messageId: currentMessageId
|
|
933
|
+
});
|
|
821
934
|
}
|
|
822
935
|
}
|
|
823
936
|
if (mode === "message" && content) {
|
|
824
|
-
eventStream$.sendTextMessageContent(
|
|
937
|
+
eventStream$.sendTextMessageContent({
|
|
938
|
+
messageId: currentMessageId,
|
|
939
|
+
content
|
|
940
|
+
});
|
|
825
941
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
826
|
-
eventStream$.sendActionExecutionArgs(
|
|
942
|
+
eventStream$.sendActionExecutionArgs({
|
|
943
|
+
actionExecutionId: currentToolCallId,
|
|
944
|
+
args: toolCall.function.arguments
|
|
945
|
+
});
|
|
827
946
|
}
|
|
828
947
|
}
|
|
829
948
|
if (mode === "message") {
|
|
830
|
-
eventStream$.sendTextMessageEnd(
|
|
949
|
+
eventStream$.sendTextMessageEnd({
|
|
950
|
+
messageId: currentMessageId
|
|
951
|
+
});
|
|
831
952
|
} else if (mode === "function") {
|
|
832
|
-
eventStream$.sendActionExecutionEnd(
|
|
953
|
+
eventStream$.sendActionExecutionEnd({
|
|
954
|
+
actionExecutionId: currentToolCallId
|
|
955
|
+
});
|
|
833
956
|
}
|
|
834
957
|
eventStream$.complete();
|
|
835
958
|
});
|
|
@@ -895,35 +1018,59 @@ var GroqAdapter = class {
|
|
|
895
1018
|
eventSource.stream(async (eventStream$) => {
|
|
896
1019
|
var _a, _b;
|
|
897
1020
|
let mode = null;
|
|
1021
|
+
let currentMessageId;
|
|
1022
|
+
let currentToolCallId;
|
|
898
1023
|
for await (const chunk of stream) {
|
|
899
1024
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
900
1025
|
const content = chunk.choices[0].delta.content;
|
|
901
1026
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
902
1027
|
mode = null;
|
|
903
|
-
eventStream$.sendTextMessageEnd(
|
|
1028
|
+
eventStream$.sendTextMessageEnd({
|
|
1029
|
+
messageId: currentMessageId
|
|
1030
|
+
});
|
|
904
1031
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
905
1032
|
mode = null;
|
|
906
|
-
eventStream$.sendActionExecutionEnd(
|
|
1033
|
+
eventStream$.sendActionExecutionEnd({
|
|
1034
|
+
actionExecutionId: currentToolCallId
|
|
1035
|
+
});
|
|
907
1036
|
}
|
|
908
1037
|
if (mode === null) {
|
|
909
1038
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
910
1039
|
mode = "function";
|
|
911
|
-
|
|
1040
|
+
currentToolCallId = toolCall.id;
|
|
1041
|
+
eventStream$.sendActionExecutionStart({
|
|
1042
|
+
actionExecutionId: currentToolCallId,
|
|
1043
|
+
actionName: toolCall.function.name,
|
|
1044
|
+
parentMessageId: chunk.id
|
|
1045
|
+
});
|
|
912
1046
|
} else if (content) {
|
|
913
1047
|
mode = "message";
|
|
914
|
-
|
|
1048
|
+
currentMessageId = chunk.id;
|
|
1049
|
+
eventStream$.sendTextMessageStart({
|
|
1050
|
+
messageId: currentMessageId
|
|
1051
|
+
});
|
|
915
1052
|
}
|
|
916
1053
|
}
|
|
917
1054
|
if (mode === "message" && content) {
|
|
918
|
-
eventStream$.sendTextMessageContent(
|
|
1055
|
+
eventStream$.sendTextMessageContent({
|
|
1056
|
+
messageId: currentMessageId,
|
|
1057
|
+
content
|
|
1058
|
+
});
|
|
919
1059
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
920
|
-
eventStream$.sendActionExecutionArgs(
|
|
1060
|
+
eventStream$.sendActionExecutionArgs({
|
|
1061
|
+
actionExecutionId: currentToolCallId,
|
|
1062
|
+
args: toolCall.function.arguments
|
|
1063
|
+
});
|
|
921
1064
|
}
|
|
922
1065
|
}
|
|
923
1066
|
if (mode === "message") {
|
|
924
|
-
eventStream$.sendTextMessageEnd(
|
|
1067
|
+
eventStream$.sendTextMessageEnd({
|
|
1068
|
+
messageId: currentMessageId
|
|
1069
|
+
});
|
|
925
1070
|
} else if (mode === "function") {
|
|
926
|
-
eventStream$.sendActionExecutionEnd(
|
|
1071
|
+
eventStream$.sendActionExecutionEnd({
|
|
1072
|
+
actionExecutionId: currentToolCallId
|
|
1073
|
+
});
|
|
927
1074
|
}
|
|
928
1075
|
eventStream$.complete();
|
|
929
1076
|
});
|
|
@@ -1131,7 +1278,11 @@ var AnthropicAdapter = class {
|
|
|
1131
1278
|
mode = "message";
|
|
1132
1279
|
} else if (chunk.content_block.type === "tool_use") {
|
|
1133
1280
|
currentToolCallId = chunk.content_block.id;
|
|
1134
|
-
eventStream$.sendActionExecutionStart(
|
|
1281
|
+
eventStream$.sendActionExecutionStart({
|
|
1282
|
+
actionExecutionId: currentToolCallId,
|
|
1283
|
+
actionName: chunk.content_block.name,
|
|
1284
|
+
parentMessageId: currentMessageId
|
|
1285
|
+
});
|
|
1135
1286
|
mode = "function";
|
|
1136
1287
|
}
|
|
1137
1288
|
} else if (chunk.type === "content_block_delta") {
|
|
@@ -1139,21 +1290,33 @@ var AnthropicAdapter = class {
|
|
|
1139
1290
|
const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
|
|
1140
1291
|
if (text.length > 0) {
|
|
1141
1292
|
if (!didOutputText) {
|
|
1142
|
-
eventStream$.sendTextMessageStart(
|
|
1293
|
+
eventStream$.sendTextMessageStart({
|
|
1294
|
+
messageId: currentMessageId
|
|
1295
|
+
});
|
|
1143
1296
|
didOutputText = true;
|
|
1144
1297
|
}
|
|
1145
|
-
eventStream$.sendTextMessageContent(
|
|
1298
|
+
eventStream$.sendTextMessageContent({
|
|
1299
|
+
messageId: currentMessageId,
|
|
1300
|
+
content: text
|
|
1301
|
+
});
|
|
1146
1302
|
}
|
|
1147
1303
|
} else if (chunk.delta.type === "input_json_delta") {
|
|
1148
|
-
eventStream$.sendActionExecutionArgs(
|
|
1304
|
+
eventStream$.sendActionExecutionArgs({
|
|
1305
|
+
actionExecutionId: currentToolCallId,
|
|
1306
|
+
args: chunk.delta.partial_json
|
|
1307
|
+
});
|
|
1149
1308
|
}
|
|
1150
1309
|
} else if (chunk.type === "content_block_stop") {
|
|
1151
1310
|
if (mode === "message") {
|
|
1152
1311
|
if (didOutputText) {
|
|
1153
|
-
eventStream$.sendTextMessageEnd(
|
|
1312
|
+
eventStream$.sendTextMessageEnd({
|
|
1313
|
+
messageId: currentMessageId
|
|
1314
|
+
});
|
|
1154
1315
|
}
|
|
1155
1316
|
} else if (mode === "function") {
|
|
1156
|
-
eventStream$.sendActionExecutionEnd(
|
|
1317
|
+
eventStream$.sendActionExecutionEnd({
|
|
1318
|
+
actionExecutionId: currentToolCallId
|
|
1319
|
+
});
|
|
1157
1320
|
}
|
|
1158
1321
|
}
|
|
1159
1322
|
}
|