@copilotkit/runtime 1.4.8-coagents-v0-3.1 → 1.4.8-next.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 +5 -4
- package/__snapshots__/schema/schema.graphql +10 -7
- package/dist/{chunk-FVYNRYIB.mjs → chunk-5KJYPVQJ.mjs} +307 -423
- package/dist/chunk-5KJYPVQJ.mjs.map +1 -0
- package/dist/{chunk-RFF5IIZJ.mjs → chunk-B74M7FXG.mjs} +2 -3
- package/dist/chunk-B74M7FXG.mjs.map +1 -0
- package/dist/{chunk-BACNNHHI.mjs → chunk-CGGI46KC.mjs} +2 -2
- package/dist/{chunk-YFG3Q3YH.mjs → chunk-EU52BTKR.mjs} +2 -2
- package/dist/{chunk-MQJNZYAH.mjs → chunk-KO4QCMY4.mjs} +2 -2
- package/dist/{chunk-2PK2SFRB.mjs → chunk-W7GP2EOT.mjs} +106 -221
- package/dist/chunk-W7GP2EOT.mjs.map +1 -0
- package/dist/{copilot-runtime-b15b683d.d.ts → copilot-runtime-1c5bf72b.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +1 -2
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -1
- package/dist/{groq-adapter-50aa9621.d.ts → groq-adapter-b6a40422.d.ts} +1 -1
- package/dist/{index-ff3fbc33.d.ts → index-10b1c870.d.ts} +8 -7
- package/dist/index.d.ts +5 -5
- package/dist/index.js +515 -745
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-8ec29cba.d.ts → langserve-6245df39.d.ts} +14 -52
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +442 -706
- 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 +37 -71
- 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 +37 -71
- 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 +37 -71
- 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 +37 -71
- 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 +36 -5
- package/dist/service-adapters/index.js +106 -219
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +5 -1
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +148 -140
- package/src/agents/langgraph/events.ts +1 -1
- package/src/graphql/inputs/forwarded-parameters.input.ts +3 -0
- package/src/graphql/inputs/message.input.ts +3 -15
- package/src/graphql/resolvers/copilot.resolver.ts +6 -32
- package/src/graphql/types/converted/index.ts +3 -4
- package/src/graphql/types/copilot-response.type.ts +3 -12
- package/src/graphql/types/enums.ts +11 -0
- package/src/lib/runtime/remote-action-constructors.ts +62 -60
- package/src/lib/runtime/remote-actions.ts +0 -1
- package/src/lib/runtime/remote-lg-action.ts +140 -161
- package/src/service-adapters/anthropic/anthropic-adapter.ts +6 -16
- package/src/service-adapters/conversion.ts +1 -2
- package/src/service-adapters/events.ts +52 -111
- package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +3 -7
- package/src/service-adapters/groq/groq-adapter.ts +8 -23
- package/src/service-adapters/index.ts +7 -1
- package/src/service-adapters/langchain/utils.ts +31 -49
- package/src/service-adapters/openai/openai-adapter.ts +9 -22
- package/src/service-adapters/openai/openai-assistant-adapter.ts +8 -22
- package/src/service-adapters/unify/unify-adapter.ts +11 -28
- package/dist/chunk-2PK2SFRB.mjs.map +0 -1
- package/dist/chunk-FVYNRYIB.mjs.map +0 -1
- package/dist/chunk-RFF5IIZJ.mjs.map +0 -1
- /package/dist/{chunk-BACNNHHI.mjs.map → chunk-CGGI46KC.mjs.map} +0 -0
- /package/dist/{chunk-YFG3Q3YH.mjs.map → chunk-EU52BTKR.mjs.map} +0 -0
- /package/dist/{chunk-MQJNZYAH.mjs.map → chunk-KO4QCMY4.mjs.map} +0 -0
|
@@ -276,8 +276,6 @@ 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;
|
|
281
279
|
for await (const chunk of stream) {
|
|
282
280
|
if (chunk.choices.length === 0) {
|
|
283
281
|
continue;
|
|
@@ -286,52 +284,30 @@ var OpenAIAdapter = class {
|
|
|
286
284
|
const content = chunk.choices[0].delta.content;
|
|
287
285
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
288
286
|
mode = null;
|
|
289
|
-
eventStream$.sendTextMessageEnd(
|
|
290
|
-
messageId: currentMessageId
|
|
291
|
-
});
|
|
287
|
+
eventStream$.sendTextMessageEnd();
|
|
292
288
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
293
289
|
mode = null;
|
|
294
|
-
eventStream$.sendActionExecutionEnd(
|
|
295
|
-
actionExecutionId: currentToolCallId
|
|
296
|
-
});
|
|
290
|
+
eventStream$.sendActionExecutionEnd();
|
|
297
291
|
}
|
|
298
292
|
if (mode === null) {
|
|
299
293
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
300
294
|
mode = "function";
|
|
301
|
-
|
|
302
|
-
eventStream$.sendActionExecutionStart({
|
|
303
|
-
actionExecutionId: currentToolCallId,
|
|
304
|
-
parentMessageId: chunk.id,
|
|
305
|
-
actionName: toolCall.function.name
|
|
306
|
-
});
|
|
295
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
307
296
|
} else if (content) {
|
|
308
297
|
mode = "message";
|
|
309
|
-
|
|
310
|
-
eventStream$.sendTextMessageStart({
|
|
311
|
-
messageId: currentMessageId
|
|
312
|
-
});
|
|
298
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
313
299
|
}
|
|
314
300
|
}
|
|
315
301
|
if (mode === "message" && content) {
|
|
316
|
-
eventStream$.sendTextMessageContent(
|
|
317
|
-
messageId: currentMessageId,
|
|
318
|
-
content
|
|
319
|
-
});
|
|
302
|
+
eventStream$.sendTextMessageContent(content);
|
|
320
303
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
321
|
-
eventStream$.sendActionExecutionArgs(
|
|
322
|
-
actionExecutionId: currentToolCallId,
|
|
323
|
-
args: toolCall.function.arguments
|
|
324
|
-
});
|
|
304
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
325
305
|
}
|
|
326
306
|
}
|
|
327
307
|
if (mode === "message") {
|
|
328
|
-
eventStream$.sendTextMessageEnd(
|
|
329
|
-
messageId: currentMessageId
|
|
330
|
-
});
|
|
308
|
+
eventStream$.sendTextMessageEnd();
|
|
331
309
|
} else if (mode === "function") {
|
|
332
|
-
eventStream$.sendActionExecutionEnd(
|
|
333
|
-
actionExecutionId: currentToolCallId
|
|
334
|
-
});
|
|
310
|
+
eventStream$.sendActionExecutionEnd();
|
|
335
311
|
}
|
|
336
312
|
eventStream$.complete();
|
|
337
313
|
});
|
|
@@ -399,25 +375,17 @@ function isBaseMessageChunk(message) {
|
|
|
399
375
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
400
376
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
401
377
|
if (actionExecution) {
|
|
402
|
-
eventStream$.sendActionExecutionResult(
|
|
403
|
-
actionExecutionId: actionExecution.id,
|
|
404
|
-
actionName: actionExecution.name,
|
|
405
|
-
result: "Sending a message"
|
|
406
|
-
});
|
|
378
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, "Sending a message");
|
|
407
379
|
}
|
|
408
380
|
}
|
|
409
381
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
410
382
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
411
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
|
383
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
412
384
|
if (typeof result === "string") {
|
|
413
385
|
if (!actionExecution) {
|
|
414
386
|
eventStream$.sendTextMessage(randomId2(), result);
|
|
415
387
|
} else {
|
|
416
|
-
eventStream$.sendActionExecutionResult(
|
|
417
|
-
actionExecutionId: actionExecution.id,
|
|
418
|
-
actionName: actionExecution.name,
|
|
419
|
-
result
|
|
420
|
-
});
|
|
388
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);
|
|
421
389
|
}
|
|
422
390
|
} else if (isAIMessage(result)) {
|
|
423
391
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -425,11 +393,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
425
393
|
eventStream$.sendTextMessage(randomId2(), result.content);
|
|
426
394
|
}
|
|
427
395
|
for (const toolCall of result.tool_calls) {
|
|
428
|
-
eventStream$.sendActionExecution(
|
|
429
|
-
actionExecutionId: toolCall.id || randomId2(),
|
|
430
|
-
actionName: toolCall.name,
|
|
431
|
-
args: JSON.stringify(toolCall.args)
|
|
432
|
-
});
|
|
396
|
+
eventStream$.sendActionExecution(toolCall.id || randomId2(), toolCall.name, JSON.stringify(toolCall.args));
|
|
433
397
|
}
|
|
434
398
|
} else if (isBaseMessageChunk(result)) {
|
|
435
399
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -438,18 +402,13 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
438
402
|
}
|
|
439
403
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
440
404
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
441
|
-
eventStream$.sendActionExecution(
|
|
442
|
-
actionExecutionId: toolCall.id || randomId2(),
|
|
443
|
-
actionName: toolCall.name,
|
|
444
|
-
args: JSON.stringify(toolCall.args)
|
|
445
|
-
});
|
|
405
|
+
eventStream$.sendActionExecution(toolCall.id || randomId2(), toolCall.name, JSON.stringify(toolCall.args));
|
|
446
406
|
}
|
|
447
407
|
}
|
|
448
408
|
} else if (result && "getReader" in result) {
|
|
449
409
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
450
410
|
let reader = result.getReader();
|
|
451
411
|
let mode = null;
|
|
452
|
-
let currentMessageId;
|
|
453
412
|
const toolCallDetails = {
|
|
454
413
|
name: null,
|
|
455
414
|
id: null,
|
|
@@ -488,14 +447,10 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
488
447
|
}
|
|
489
448
|
if (mode === "message" && (toolCallId || done)) {
|
|
490
449
|
mode = null;
|
|
491
|
-
eventStream$.sendTextMessageEnd(
|
|
492
|
-
messageId: currentMessageId
|
|
493
|
-
});
|
|
450
|
+
eventStream$.sendTextMessageEnd();
|
|
494
451
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
495
452
|
mode = null;
|
|
496
|
-
eventStream$.sendActionExecutionEnd(
|
|
497
|
-
actionExecutionId: toolCallId
|
|
498
|
-
});
|
|
453
|
+
eventStream$.sendActionExecutionEnd();
|
|
499
454
|
}
|
|
500
455
|
if (done) {
|
|
501
456
|
break;
|
|
@@ -503,40 +458,21 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
503
458
|
if (mode === null) {
|
|
504
459
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
505
460
|
mode = "function";
|
|
506
|
-
eventStream$.sendActionExecutionStart(
|
|
507
|
-
actionExecutionId: toolCallId,
|
|
508
|
-
actionName: toolCallName,
|
|
509
|
-
parentMessageId: (_i = value.lc_kwargs) == null ? void 0 : _i.id
|
|
510
|
-
});
|
|
461
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
511
462
|
} else if (content) {
|
|
512
463
|
mode = "message";
|
|
513
|
-
|
|
514
|
-
eventStream$.sendTextMessageStart({
|
|
515
|
-
messageId: currentMessageId
|
|
516
|
-
});
|
|
464
|
+
eventStream$.sendTextMessageStart(randomId2());
|
|
517
465
|
}
|
|
518
466
|
}
|
|
519
467
|
if (mode === "message" && content) {
|
|
520
|
-
eventStream$.sendTextMessageContent(
|
|
521
|
-
messageId: currentMessageId,
|
|
522
|
-
content: Array.isArray(content) ? ((_k = content[0]) == null ? void 0 : _k.text) ?? "" : content
|
|
523
|
-
});
|
|
468
|
+
eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
|
|
524
469
|
} else if (mode === "function" && toolCallArgs) {
|
|
525
470
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
526
|
-
eventStream$.sendActionExecutionEnd(
|
|
527
|
-
|
|
528
|
-
});
|
|
529
|
-
eventStream$.sendActionExecutionStart({
|
|
530
|
-
actionExecutionId: toolCallId,
|
|
531
|
-
actionName: toolCallName,
|
|
532
|
-
parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
|
|
533
|
-
});
|
|
471
|
+
eventStream$.sendActionExecutionEnd();
|
|
472
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
534
473
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
535
474
|
}
|
|
536
|
-
eventStream$.sendActionExecutionArgs(
|
|
537
|
-
actionExecutionId: toolCallId,
|
|
538
|
-
args: toolCallArgs
|
|
539
|
-
});
|
|
475
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
540
476
|
}
|
|
541
477
|
} catch (error) {
|
|
542
478
|
console.error("Error reading from stream", error);
|
|
@@ -544,11 +480,7 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
544
480
|
}
|
|
545
481
|
}
|
|
546
482
|
} else if (actionExecution) {
|
|
547
|
-
eventStream$.sendActionExecutionResult(
|
|
548
|
-
actionExecutionId: actionExecution.id,
|
|
549
|
-
actionName: actionExecution.name,
|
|
550
|
-
result: encodeResult(result)
|
|
551
|
-
});
|
|
483
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, encodeResult(result));
|
|
552
484
|
} else {
|
|
553
485
|
throw new Error("Invalid return type from LangChain function.");
|
|
554
486
|
}
|
|
@@ -728,33 +660,21 @@ var OpenAIAssistantAdapter = class {
|
|
|
728
660
|
eventSource.stream(async (eventStream$) => {
|
|
729
661
|
var _a, _b, _c, _d, _e, _f;
|
|
730
662
|
let inFunctionCall = false;
|
|
731
|
-
let currentMessageId;
|
|
732
|
-
let currentToolCallId;
|
|
733
663
|
for await (const chunk of stream) {
|
|
734
664
|
switch (chunk.event) {
|
|
735
665
|
case "thread.message.created":
|
|
736
666
|
if (inFunctionCall) {
|
|
737
|
-
eventStream$.sendActionExecutionEnd(
|
|
738
|
-
actionExecutionId: currentToolCallId
|
|
739
|
-
});
|
|
667
|
+
eventStream$.sendActionExecutionEnd();
|
|
740
668
|
}
|
|
741
|
-
|
|
742
|
-
eventStream$.sendTextMessageStart({
|
|
743
|
-
messageId: currentMessageId
|
|
744
|
-
});
|
|
669
|
+
eventStream$.sendTextMessageStart(chunk.data.id);
|
|
745
670
|
break;
|
|
746
671
|
case "thread.message.delta":
|
|
747
672
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
748
|
-
eventStream$.sendTextMessageContent(
|
|
749
|
-
messageId: currentMessageId,
|
|
750
|
-
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
751
|
-
});
|
|
673
|
+
eventStream$.sendTextMessageContent((_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value);
|
|
752
674
|
}
|
|
753
675
|
break;
|
|
754
676
|
case "thread.message.completed":
|
|
755
|
-
eventStream$.sendTextMessageEnd(
|
|
756
|
-
messageId: currentMessageId
|
|
757
|
-
});
|
|
677
|
+
eventStream$.sendTextMessageEnd();
|
|
758
678
|
break;
|
|
759
679
|
case "thread.run.step.delta":
|
|
760
680
|
let toolCallId;
|
|
@@ -767,30 +687,18 @@ var OpenAIAssistantAdapter = class {
|
|
|
767
687
|
}
|
|
768
688
|
if (toolCallName && toolCallId) {
|
|
769
689
|
if (inFunctionCall) {
|
|
770
|
-
eventStream$.sendActionExecutionEnd(
|
|
771
|
-
actionExecutionId: currentToolCallId
|
|
772
|
-
});
|
|
690
|
+
eventStream$.sendActionExecutionEnd();
|
|
773
691
|
}
|
|
774
692
|
inFunctionCall = true;
|
|
775
|
-
|
|
776
|
-
eventStream$.sendActionExecutionStart({
|
|
777
|
-
actionExecutionId: currentToolCallId,
|
|
778
|
-
parentMessageId: chunk.data.id,
|
|
779
|
-
actionName: toolCallName
|
|
780
|
-
});
|
|
693
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
781
694
|
} else if (toolCallArgs) {
|
|
782
|
-
eventStream$.sendActionExecutionArgs(
|
|
783
|
-
actionExecutionId: currentToolCallId,
|
|
784
|
-
args: toolCallArgs
|
|
785
|
-
});
|
|
695
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
786
696
|
}
|
|
787
697
|
break;
|
|
788
698
|
}
|
|
789
699
|
}
|
|
790
700
|
if (inFunctionCall) {
|
|
791
|
-
eventStream$.sendActionExecutionEnd(
|
|
792
|
-
actionExecutionId: currentToolCallId
|
|
793
|
-
});
|
|
701
|
+
eventStream$.sendActionExecutionEnd();
|
|
794
702
|
}
|
|
795
703
|
eventStream$.complete();
|
|
796
704
|
});
|
|
@@ -843,77 +751,46 @@ var UnifyAdapter = class {
|
|
|
843
751
|
}
|
|
844
752
|
});
|
|
845
753
|
let model = null;
|
|
846
|
-
let currentMessageId;
|
|
847
|
-
let currentToolCallId;
|
|
848
754
|
request.eventSource.stream(async (eventStream$) => {
|
|
849
755
|
var _a, _b;
|
|
850
756
|
let mode = null;
|
|
851
757
|
for await (const chunk of stream) {
|
|
852
758
|
if (this.start) {
|
|
853
759
|
model = chunk.model;
|
|
854
|
-
|
|
855
|
-
eventStream$.
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
eventStream$.sendTextMessageContent({
|
|
859
|
-
messageId: currentMessageId,
|
|
860
|
-
content: `Model used: ${model}
|
|
861
|
-
`
|
|
862
|
-
});
|
|
863
|
-
eventStream$.sendTextMessageEnd({
|
|
864
|
-
messageId: currentMessageId
|
|
865
|
-
});
|
|
760
|
+
eventStream$.sendTextMessageStart(randomId4());
|
|
761
|
+
eventStream$.sendTextMessageContent(`Model used: ${model}
|
|
762
|
+
`);
|
|
763
|
+
eventStream$.sendTextMessageEnd();
|
|
866
764
|
this.start = false;
|
|
867
765
|
}
|
|
868
766
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
869
767
|
const content = chunk.choices[0].delta.content;
|
|
870
768
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
871
769
|
mode = null;
|
|
872
|
-
eventStream$.sendTextMessageEnd(
|
|
873
|
-
messageId: currentMessageId
|
|
874
|
-
});
|
|
770
|
+
eventStream$.sendTextMessageEnd();
|
|
875
771
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
876
772
|
mode = null;
|
|
877
|
-
eventStream$.sendActionExecutionEnd(
|
|
878
|
-
actionExecutionId: currentToolCallId
|
|
879
|
-
});
|
|
773
|
+
eventStream$.sendActionExecutionEnd();
|
|
880
774
|
}
|
|
881
775
|
if (mode === null) {
|
|
882
776
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
883
777
|
mode = "function";
|
|
884
|
-
|
|
885
|
-
eventStream$.sendActionExecutionStart({
|
|
886
|
-
actionExecutionId: currentToolCallId,
|
|
887
|
-
actionName: toolCall.function.name
|
|
888
|
-
});
|
|
778
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
889
779
|
} else if (content) {
|
|
890
780
|
mode = "message";
|
|
891
|
-
|
|
892
|
-
eventStream$.sendTextMessageStart({
|
|
893
|
-
messageId: currentMessageId
|
|
894
|
-
});
|
|
781
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
895
782
|
}
|
|
896
783
|
}
|
|
897
784
|
if (mode === "message" && content) {
|
|
898
|
-
eventStream$.sendTextMessageContent(
|
|
899
|
-
messageId: currentMessageId,
|
|
900
|
-
content
|
|
901
|
-
});
|
|
785
|
+
eventStream$.sendTextMessageContent(content);
|
|
902
786
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
903
|
-
eventStream$.sendActionExecutionArgs(
|
|
904
|
-
actionExecutionId: currentToolCallId,
|
|
905
|
-
args: toolCall.function.arguments
|
|
906
|
-
});
|
|
787
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
907
788
|
}
|
|
908
789
|
}
|
|
909
790
|
if (mode === "message") {
|
|
910
|
-
eventStream$.sendTextMessageEnd(
|
|
911
|
-
messageId: currentMessageId
|
|
912
|
-
});
|
|
791
|
+
eventStream$.sendTextMessageEnd();
|
|
913
792
|
} else if (mode === "function") {
|
|
914
|
-
eventStream$.sendActionExecutionEnd(
|
|
915
|
-
actionExecutionId: currentToolCallId
|
|
916
|
-
});
|
|
793
|
+
eventStream$.sendActionExecutionEnd();
|
|
917
794
|
}
|
|
918
795
|
eventStream$.complete();
|
|
919
796
|
});
|
|
@@ -979,59 +856,35 @@ var GroqAdapter = class {
|
|
|
979
856
|
eventSource.stream(async (eventStream$) => {
|
|
980
857
|
var _a, _b;
|
|
981
858
|
let mode = null;
|
|
982
|
-
let currentMessageId;
|
|
983
|
-
let currentToolCallId;
|
|
984
859
|
for await (const chunk of stream) {
|
|
985
860
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
986
861
|
const content = chunk.choices[0].delta.content;
|
|
987
862
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
988
863
|
mode = null;
|
|
989
|
-
eventStream$.sendTextMessageEnd(
|
|
990
|
-
messageId: currentMessageId
|
|
991
|
-
});
|
|
864
|
+
eventStream$.sendTextMessageEnd();
|
|
992
865
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
993
866
|
mode = null;
|
|
994
|
-
eventStream$.sendActionExecutionEnd(
|
|
995
|
-
actionExecutionId: currentToolCallId
|
|
996
|
-
});
|
|
867
|
+
eventStream$.sendActionExecutionEnd();
|
|
997
868
|
}
|
|
998
869
|
if (mode === null) {
|
|
999
870
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
1000
871
|
mode = "function";
|
|
1001
|
-
|
|
1002
|
-
eventStream$.sendActionExecutionStart({
|
|
1003
|
-
actionExecutionId: currentToolCallId,
|
|
1004
|
-
actionName: toolCall.function.name,
|
|
1005
|
-
parentMessageId: chunk.id
|
|
1006
|
-
});
|
|
872
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
1007
873
|
} else if (content) {
|
|
1008
874
|
mode = "message";
|
|
1009
|
-
|
|
1010
|
-
eventStream$.sendTextMessageStart({
|
|
1011
|
-
messageId: currentMessageId
|
|
1012
|
-
});
|
|
875
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
1013
876
|
}
|
|
1014
877
|
}
|
|
1015
878
|
if (mode === "message" && content) {
|
|
1016
|
-
eventStream$.sendTextMessageContent(
|
|
1017
|
-
messageId: currentMessageId,
|
|
1018
|
-
content
|
|
1019
|
-
});
|
|
879
|
+
eventStream$.sendTextMessageContent(content);
|
|
1020
880
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
1021
|
-
eventStream$.sendActionExecutionArgs(
|
|
1022
|
-
actionExecutionId: currentToolCallId,
|
|
1023
|
-
args: toolCall.function.arguments
|
|
1024
|
-
});
|
|
881
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
1025
882
|
}
|
|
1026
883
|
}
|
|
1027
884
|
if (mode === "message") {
|
|
1028
|
-
eventStream$.sendTextMessageEnd(
|
|
1029
|
-
messageId: currentMessageId
|
|
1030
|
-
});
|
|
885
|
+
eventStream$.sendTextMessageEnd();
|
|
1031
886
|
} else if (mode === "function") {
|
|
1032
|
-
eventStream$.sendActionExecutionEnd(
|
|
1033
|
-
actionExecutionId: currentToolCallId
|
|
1034
|
-
});
|
|
887
|
+
eventStream$.sendActionExecutionEnd();
|
|
1035
888
|
}
|
|
1036
889
|
eventStream$.complete();
|
|
1037
890
|
});
|
|
@@ -1239,11 +1092,7 @@ var AnthropicAdapter = class {
|
|
|
1239
1092
|
mode = "message";
|
|
1240
1093
|
} else if (chunk.content_block.type === "tool_use") {
|
|
1241
1094
|
currentToolCallId = chunk.content_block.id;
|
|
1242
|
-
eventStream$.sendActionExecutionStart(
|
|
1243
|
-
actionExecutionId: currentToolCallId,
|
|
1244
|
-
actionName: chunk.content_block.name,
|
|
1245
|
-
parentMessageId: currentMessageId
|
|
1246
|
-
});
|
|
1095
|
+
eventStream$.sendActionExecutionStart(currentToolCallId, chunk.content_block.name);
|
|
1247
1096
|
mode = "function";
|
|
1248
1097
|
}
|
|
1249
1098
|
} else if (chunk.type === "content_block_delta") {
|
|
@@ -1251,33 +1100,21 @@ var AnthropicAdapter = class {
|
|
|
1251
1100
|
const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
|
|
1252
1101
|
if (text.length > 0) {
|
|
1253
1102
|
if (!didOutputText) {
|
|
1254
|
-
eventStream$.sendTextMessageStart(
|
|
1255
|
-
messageId: currentMessageId
|
|
1256
|
-
});
|
|
1103
|
+
eventStream$.sendTextMessageStart(currentMessageId);
|
|
1257
1104
|
didOutputText = true;
|
|
1258
1105
|
}
|
|
1259
|
-
eventStream$.sendTextMessageContent(
|
|
1260
|
-
messageId: currentMessageId,
|
|
1261
|
-
content: text
|
|
1262
|
-
});
|
|
1106
|
+
eventStream$.sendTextMessageContent(text);
|
|
1263
1107
|
}
|
|
1264
1108
|
} else if (chunk.delta.type === "input_json_delta") {
|
|
1265
|
-
eventStream$.sendActionExecutionArgs(
|
|
1266
|
-
actionExecutionId: currentToolCallId,
|
|
1267
|
-
args: chunk.delta.partial_json
|
|
1268
|
-
});
|
|
1109
|
+
eventStream$.sendActionExecutionArgs(chunk.delta.partial_json);
|
|
1269
1110
|
}
|
|
1270
1111
|
} else if (chunk.type === "content_block_stop") {
|
|
1271
1112
|
if (mode === "message") {
|
|
1272
1113
|
if (didOutputText) {
|
|
1273
|
-
eventStream$.sendTextMessageEnd(
|
|
1274
|
-
messageId: currentMessageId
|
|
1275
|
-
});
|
|
1114
|
+
eventStream$.sendTextMessageEnd();
|
|
1276
1115
|
}
|
|
1277
1116
|
} else if (mode === "function") {
|
|
1278
|
-
eventStream$.sendActionExecutionEnd(
|
|
1279
|
-
actionExecutionId: currentToolCallId
|
|
1280
|
-
});
|
|
1117
|
+
eventStream$.sendActionExecutionEnd();
|
|
1281
1118
|
}
|
|
1282
1119
|
}
|
|
1283
1120
|
}
|
|
@@ -1322,6 +1159,52 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
|
|
|
1322
1159
|
}
|
|
1323
1160
|
}, "FilterThinkingTextBuffer");
|
|
1324
1161
|
|
|
1162
|
+
// src/service-adapters/experimental/ollama/ollama-adapter.ts
|
|
1163
|
+
import { Ollama } from "@langchain/community/llms/ollama";
|
|
1164
|
+
import { randomId as randomId7 } from "@copilotkit/shared";
|
|
1165
|
+
var DEFAULT_MODEL4 = "llama3:latest";
|
|
1166
|
+
var ExperimentalOllamaAdapter = class {
|
|
1167
|
+
model;
|
|
1168
|
+
constructor(options) {
|
|
1169
|
+
if (options == null ? void 0 : options.model) {
|
|
1170
|
+
this.model = options.model;
|
|
1171
|
+
} else {
|
|
1172
|
+
this.model = DEFAULT_MODEL4;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
async process(request) {
|
|
1176
|
+
const { messages, actions, eventSource } = request;
|
|
1177
|
+
const ollama = new Ollama({
|
|
1178
|
+
model: this.model
|
|
1179
|
+
});
|
|
1180
|
+
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
1181
|
+
const _stream = await ollama.stream(contents);
|
|
1182
|
+
eventSource.stream(async (eventStream$) => {
|
|
1183
|
+
eventStream$.sendTextMessageStart(randomId7());
|
|
1184
|
+
for await (const chunkText of _stream) {
|
|
1185
|
+
eventStream$.sendTextMessageContent(chunkText);
|
|
1186
|
+
}
|
|
1187
|
+
eventStream$.sendTextMessageEnd();
|
|
1188
|
+
eventStream$.complete();
|
|
1189
|
+
});
|
|
1190
|
+
return {
|
|
1191
|
+
threadId: request.threadId || randomId7()
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
1196
|
+
|
|
1197
|
+
// src/service-adapters/experimental/empty/empty-adapter.ts
|
|
1198
|
+
import { randomId as randomId8 } from "@copilotkit/shared";
|
|
1199
|
+
var ExperimentalEmptyAdapter = class {
|
|
1200
|
+
async process(request) {
|
|
1201
|
+
return {
|
|
1202
|
+
threadId: request.threadId || randomId8()
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
__name(ExperimentalEmptyAdapter, "ExperimentalEmptyAdapter");
|
|
1207
|
+
|
|
1325
1208
|
export {
|
|
1326
1209
|
RemoteChain,
|
|
1327
1210
|
OpenAIAdapter,
|
|
@@ -1331,6 +1214,8 @@ export {
|
|
|
1331
1214
|
OpenAIAssistantAdapter,
|
|
1332
1215
|
UnifyAdapter,
|
|
1333
1216
|
GroqAdapter,
|
|
1334
|
-
AnthropicAdapter
|
|
1217
|
+
AnthropicAdapter,
|
|
1218
|
+
ExperimentalOllamaAdapter,
|
|
1219
|
+
ExperimentalEmptyAdapter
|
|
1335
1220
|
};
|
|
1336
|
-
//# sourceMappingURL=chunk-
|
|
1221
|
+
//# sourceMappingURL=chunk-W7GP2EOT.mjs.map
|