@copilotkit/runtime 1.5.0-tyler-reset-chat.0 → 1.5.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.
- package/CHANGELOG.md +141 -3
- package/__snapshots__/schema/schema.graphql +7 -9
- package/dist/{chunk-K67A6XOJ.mjs → chunk-25G6SHWM.mjs} +458 -331
- package/dist/chunk-25G6SHWM.mjs.map +1 -0
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-4AYRDPWK.mjs} +285 -63
- package/dist/chunk-4AYRDPWK.mjs.map +1 -0
- package/dist/{chunk-ZBG4KJW5.mjs → chunk-AFKLCW76.mjs} +2 -2
- package/dist/{chunk-AGSBOD2T.mjs → chunk-D6J2N5ZQ.mjs} +2 -2
- package/dist/{chunk-QNQ6UT3D.mjs → chunk-PIUHAIBR.mjs} +2 -2
- package/dist/{chunk-B74M7FXG.mjs → chunk-RFF5IIZJ.mjs} +3 -2
- package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
- package/dist/{copilot-runtime-12e7ac40.d.ts → copilot-runtime-2e46a7b6.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-7bf6824b.d.ts} +1 -1
- package/dist/{index-10b1c870.d.ts → index-ff3fbc33.d.ts} +7 -8
- package/dist/index.d.ts +5 -5
- package/dist/index.js +832 -480
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -11
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-f021ab9c.d.ts → langserve-f318db89.d.ts} +53 -14
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +737 -459
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -7
- 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 +36 -5
- package/dist/service-adapters/index.js +285 -61
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +5 -1
- package/package.json +4 -4
- 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/copilot-runtime.ts +1 -7
- package/src/lib/runtime/remote-action-constructors.ts +64 -58
- package/src/lib/runtime/remote-actions.ts +1 -0
- package/src/lib/runtime/remote-lg-action.ts +184 -154
- package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -6
- package/src/service-adapters/conversion.ts +2 -1
- package/src/service-adapters/events.ts +118 -54
- package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
- 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/index.ts +7 -1
- package/src/service-adapters/langchain/utils.ts +55 -32
- 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-B74M7FXG.mjs.map +0 -1
- package/dist/chunk-K67A6XOJ.mjs.map +0 -1
- package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
- /package/dist/{chunk-ZBG4KJW5.mjs.map → chunk-AFKLCW76.mjs.map} +0 -0
- /package/dist/{chunk-AGSBOD2T.mjs.map → chunk-D6J2N5ZQ.mjs.map} +0 -0
- /package/dist/{chunk-QNQ6UT3D.mjs.map → chunk-PIUHAIBR.mjs.map} +0 -0
|
@@ -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
|
-
|
|
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
|
-
|
|
309
|
+
currentMessageId = chunk.id;
|
|
310
|
+
eventStream$.sendTextMessageStart({
|
|
311
|
+
messageId: currentMessageId
|
|
312
|
+
});
|
|
299
313
|
}
|
|
300
314
|
}
|
|
301
315
|
if (mode === "message" && content) {
|
|
302
|
-
eventStream$.sendTextMessageContent(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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 =
|
|
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 = (
|
|
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 = (
|
|
443
|
-
toolCallName = (
|
|
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 = (
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
761
|
-
eventStream$.
|
|
762
|
-
|
|
763
|
-
|
|
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
|
-
|
|
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
|
-
|
|
894
|
+
currentMessageId = chunk.id;
|
|
895
|
+
eventStream$.sendTextMessageStart({
|
|
896
|
+
messageId: currentMessageId
|
|
897
|
+
});
|
|
782
898
|
}
|
|
783
899
|
}
|
|
784
900
|
if (mode === "message" && content) {
|
|
785
|
-
eventStream$.sendTextMessageContent(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
1012
|
+
currentMessageId = chunk.id;
|
|
1013
|
+
eventStream$.sendTextMessageStart({
|
|
1014
|
+
messageId: currentMessageId
|
|
1015
|
+
});
|
|
876
1016
|
}
|
|
877
1017
|
}
|
|
878
1018
|
if (mode === "message" && content) {
|
|
879
|
-
eventStream$.sendTextMessageContent(
|
|
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(
|
|
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(
|
|
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(
|
|
1257
|
+
eventStream$.sendTextMessageStart({
|
|
1258
|
+
messageId: currentMessageId
|
|
1259
|
+
});
|
|
1104
1260
|
didOutputText = true;
|
|
1105
1261
|
}
|
|
1106
|
-
eventStream$.sendTextMessageContent(
|
|
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(
|
|
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-
|
|
1395
|
+
//# sourceMappingURL=chunk-4AYRDPWK.mjs.map
|