@copilotkit/runtime 1.5.0-tyler-reset-chat.0 → 1.5.1-custom-tag-pre.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 +150 -3
- package/__snapshots__/schema/schema.graphql +8 -9
- package/dist/{chunk-K67A6XOJ.mjs → chunk-3ECBC2K2.mjs} +462 -328
- package/dist/chunk-3ECBC2K2.mjs.map +1 -0
- package/dist/{chunk-QNQ6UT3D.mjs → chunk-5E6LOP76.mjs} +2 -2
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-CLGKEUOA.mjs} +298 -63
- package/dist/chunk-CLGKEUOA.mjs.map +1 -0
- package/dist/{chunk-ZBG4KJW5.mjs → chunk-MKDG5ZHT.mjs} +2 -2
- package/dist/{chunk-AGSBOD2T.mjs → chunk-MYZB2EKG.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-6285d897.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-15d41154.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 +852 -480
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-f021ab9c.d.ts → langserve-48e976ac.d.ts} +54 -14
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +754 -459
- 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 +78 -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 +78 -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 +78 -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 +78 -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 +298 -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/forwarded-parameters.input.ts +3 -0
- 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 +17 -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 +24 -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 +23 -9
- package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
- package/src/service-adapters/unify/unify-adapter.ts +30 -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-QNQ6UT3D.mjs.map → chunk-5E6LOP76.mjs.map} +0 -0
- /package/dist/{chunk-ZBG4KJW5.mjs.map → chunk-MKDG5ZHT.mjs.map} +0 -0
- /package/dist/{chunk-AGSBOD2T.mjs.map → chunk-MYZB2EKG.mjs.map} +0 -0
|
@@ -271,11 +271,16 @@ var OpenAIAdapter = class {
|
|
|
271
271
|
},
|
|
272
272
|
...this.disableParallelToolCalls && {
|
|
273
273
|
parallel_tool_calls: false
|
|
274
|
+
},
|
|
275
|
+
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
|
|
276
|
+
temperature: forwardedParameters.temperature
|
|
274
277
|
}
|
|
275
278
|
});
|
|
276
279
|
eventSource.stream(async (eventStream$) => {
|
|
277
280
|
var _a, _b;
|
|
278
281
|
let mode = null;
|
|
282
|
+
let currentMessageId;
|
|
283
|
+
let currentToolCallId;
|
|
279
284
|
for await (const chunk of stream) {
|
|
280
285
|
if (chunk.choices.length === 0) {
|
|
281
286
|
continue;
|
|
@@ -284,30 +289,52 @@ var OpenAIAdapter = class {
|
|
|
284
289
|
const content = chunk.choices[0].delta.content;
|
|
285
290
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
286
291
|
mode = null;
|
|
287
|
-
eventStream$.sendTextMessageEnd(
|
|
292
|
+
eventStream$.sendTextMessageEnd({
|
|
293
|
+
messageId: currentMessageId
|
|
294
|
+
});
|
|
288
295
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
289
296
|
mode = null;
|
|
290
|
-
eventStream$.sendActionExecutionEnd(
|
|
297
|
+
eventStream$.sendActionExecutionEnd({
|
|
298
|
+
actionExecutionId: currentToolCallId
|
|
299
|
+
});
|
|
291
300
|
}
|
|
292
301
|
if (mode === null) {
|
|
293
302
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
294
303
|
mode = "function";
|
|
295
|
-
|
|
304
|
+
currentToolCallId = toolCall.id;
|
|
305
|
+
eventStream$.sendActionExecutionStart({
|
|
306
|
+
actionExecutionId: currentToolCallId,
|
|
307
|
+
parentMessageId: chunk.id,
|
|
308
|
+
actionName: toolCall.function.name
|
|
309
|
+
});
|
|
296
310
|
} else if (content) {
|
|
297
311
|
mode = "message";
|
|
298
|
-
|
|
312
|
+
currentMessageId = chunk.id;
|
|
313
|
+
eventStream$.sendTextMessageStart({
|
|
314
|
+
messageId: currentMessageId
|
|
315
|
+
});
|
|
299
316
|
}
|
|
300
317
|
}
|
|
301
318
|
if (mode === "message" && content) {
|
|
302
|
-
eventStream$.sendTextMessageContent(
|
|
319
|
+
eventStream$.sendTextMessageContent({
|
|
320
|
+
messageId: currentMessageId,
|
|
321
|
+
content
|
|
322
|
+
});
|
|
303
323
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
304
|
-
eventStream$.sendActionExecutionArgs(
|
|
324
|
+
eventStream$.sendActionExecutionArgs({
|
|
325
|
+
actionExecutionId: currentToolCallId,
|
|
326
|
+
args: toolCall.function.arguments
|
|
327
|
+
});
|
|
305
328
|
}
|
|
306
329
|
}
|
|
307
330
|
if (mode === "message") {
|
|
308
|
-
eventStream$.sendTextMessageEnd(
|
|
331
|
+
eventStream$.sendTextMessageEnd({
|
|
332
|
+
messageId: currentMessageId
|
|
333
|
+
});
|
|
309
334
|
} else if (mode === "function") {
|
|
310
|
-
eventStream$.sendActionExecutionEnd(
|
|
335
|
+
eventStream$.sendActionExecutionEnd({
|
|
336
|
+
actionExecutionId: currentToolCallId
|
|
337
|
+
});
|
|
311
338
|
}
|
|
312
339
|
eventStream$.complete();
|
|
313
340
|
});
|
|
@@ -375,17 +402,25 @@ function isBaseMessageChunk(message) {
|
|
|
375
402
|
__name(isBaseMessageChunk, "isBaseMessageChunk");
|
|
376
403
|
function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
|
|
377
404
|
if (actionExecution) {
|
|
378
|
-
eventStream$.sendActionExecutionResult(
|
|
405
|
+
eventStream$.sendActionExecutionResult({
|
|
406
|
+
actionExecutionId: actionExecution.id,
|
|
407
|
+
actionName: actionExecution.name,
|
|
408
|
+
result: "Sending a message"
|
|
409
|
+
});
|
|
379
410
|
}
|
|
380
411
|
}
|
|
381
412
|
__name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
|
|
382
413
|
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
383
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
414
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
384
415
|
if (typeof result === "string") {
|
|
385
416
|
if (!actionExecution) {
|
|
386
417
|
eventStream$.sendTextMessage(randomId2(), result);
|
|
387
418
|
} else {
|
|
388
|
-
eventStream$.sendActionExecutionResult(
|
|
419
|
+
eventStream$.sendActionExecutionResult({
|
|
420
|
+
actionExecutionId: actionExecution.id,
|
|
421
|
+
actionName: actionExecution.name,
|
|
422
|
+
result
|
|
423
|
+
});
|
|
389
424
|
}
|
|
390
425
|
} else if (isAIMessage(result)) {
|
|
391
426
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -393,7 +428,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
393
428
|
eventStream$.sendTextMessage(randomId2(), result.content);
|
|
394
429
|
}
|
|
395
430
|
for (const toolCall of result.tool_calls) {
|
|
396
|
-
eventStream$.sendActionExecution(
|
|
431
|
+
eventStream$.sendActionExecution({
|
|
432
|
+
actionExecutionId: toolCall.id || randomId2(),
|
|
433
|
+
actionName: toolCall.name,
|
|
434
|
+
args: JSON.stringify(toolCall.args)
|
|
435
|
+
});
|
|
397
436
|
}
|
|
398
437
|
} else if (isBaseMessageChunk(result)) {
|
|
399
438
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
@@ -402,13 +441,18 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
402
441
|
}
|
|
403
442
|
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
404
443
|
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
405
|
-
eventStream$.sendActionExecution(
|
|
444
|
+
eventStream$.sendActionExecution({
|
|
445
|
+
actionExecutionId: toolCall.id || randomId2(),
|
|
446
|
+
actionName: toolCall.name,
|
|
447
|
+
args: JSON.stringify(toolCall.args)
|
|
448
|
+
});
|
|
406
449
|
}
|
|
407
450
|
}
|
|
408
451
|
} else if (result && "getReader" in result) {
|
|
409
452
|
maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
|
|
410
453
|
let reader = result.getReader();
|
|
411
454
|
let mode = null;
|
|
455
|
+
let currentMessageId;
|
|
412
456
|
const toolCallDetails = {
|
|
413
457
|
name: null,
|
|
414
458
|
id: null,
|
|
@@ -422,9 +466,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
422
466
|
let toolCallId = void 0;
|
|
423
467
|
let toolCallArgs = void 0;
|
|
424
468
|
let hasToolCall = false;
|
|
425
|
-
let content =
|
|
469
|
+
let content = "";
|
|
470
|
+
if (value && value.content) {
|
|
471
|
+
content = Array.isArray(value.content) ? ((_d = value.content[0]) == null ? void 0 : _d.text) ?? "" : value.content;
|
|
472
|
+
}
|
|
426
473
|
if (isAIMessageChunk(value)) {
|
|
427
|
-
let chunk = (
|
|
474
|
+
let chunk = (_e = value.tool_call_chunks) == null ? void 0 : _e[0];
|
|
428
475
|
toolCallArgs = chunk == null ? void 0 : chunk.args;
|
|
429
476
|
hasToolCall = chunk != void 0;
|
|
430
477
|
if (chunk == null ? void 0 : chunk.name)
|
|
@@ -439,18 +486,22 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
439
486
|
toolCallName = toolCallDetails.name;
|
|
440
487
|
toolCallId = toolCallDetails.id;
|
|
441
488
|
} else if (isBaseMessageChunk(value)) {
|
|
442
|
-
let chunk = (
|
|
443
|
-
toolCallName = (
|
|
489
|
+
let chunk = (_g = (_f = value.additional_kwargs) == null ? void 0 : _f.tool_calls) == null ? void 0 : _g[0];
|
|
490
|
+
toolCallName = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.name;
|
|
444
491
|
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
445
|
-
toolCallArgs = (
|
|
492
|
+
toolCallArgs = (_i = chunk == null ? void 0 : chunk.function) == null ? void 0 : _i.arguments;
|
|
446
493
|
hasToolCall = (chunk == null ? void 0 : chunk.function) != void 0;
|
|
447
494
|
}
|
|
448
495
|
if (mode === "message" && (toolCallId || done)) {
|
|
449
496
|
mode = null;
|
|
450
|
-
eventStream$.sendTextMessageEnd(
|
|
497
|
+
eventStream$.sendTextMessageEnd({
|
|
498
|
+
messageId: currentMessageId
|
|
499
|
+
});
|
|
451
500
|
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
452
501
|
mode = null;
|
|
453
|
-
eventStream$.sendActionExecutionEnd(
|
|
502
|
+
eventStream$.sendActionExecutionEnd({
|
|
503
|
+
actionExecutionId: toolCallId
|
|
504
|
+
});
|
|
454
505
|
}
|
|
455
506
|
if (done) {
|
|
456
507
|
break;
|
|
@@ -458,21 +509,40 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
458
509
|
if (mode === null) {
|
|
459
510
|
if (hasToolCall && toolCallId && toolCallName) {
|
|
460
511
|
mode = "function";
|
|
461
|
-
eventStream$.sendActionExecutionStart(
|
|
512
|
+
eventStream$.sendActionExecutionStart({
|
|
513
|
+
actionExecutionId: toolCallId,
|
|
514
|
+
actionName: toolCallName,
|
|
515
|
+
parentMessageId: (_j = value.lc_kwargs) == null ? void 0 : _j.id
|
|
516
|
+
});
|
|
462
517
|
} else if (content) {
|
|
463
518
|
mode = "message";
|
|
464
|
-
|
|
519
|
+
currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || randomId2();
|
|
520
|
+
eventStream$.sendTextMessageStart({
|
|
521
|
+
messageId: currentMessageId
|
|
522
|
+
});
|
|
465
523
|
}
|
|
466
524
|
}
|
|
467
525
|
if (mode === "message" && content) {
|
|
468
|
-
eventStream$.sendTextMessageContent(
|
|
526
|
+
eventStream$.sendTextMessageContent({
|
|
527
|
+
messageId: currentMessageId,
|
|
528
|
+
content
|
|
529
|
+
});
|
|
469
530
|
} else if (mode === "function" && toolCallArgs) {
|
|
470
531
|
if (toolCallDetails.index !== toolCallDetails.prevIndex) {
|
|
471
|
-
eventStream$.sendActionExecutionEnd(
|
|
472
|
-
|
|
532
|
+
eventStream$.sendActionExecutionEnd({
|
|
533
|
+
actionExecutionId: toolCallId
|
|
534
|
+
});
|
|
535
|
+
eventStream$.sendActionExecutionStart({
|
|
536
|
+
actionExecutionId: toolCallId,
|
|
537
|
+
actionName: toolCallName,
|
|
538
|
+
parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
|
|
539
|
+
});
|
|
473
540
|
toolCallDetails.prevIndex = toolCallDetails.index;
|
|
474
541
|
}
|
|
475
|
-
eventStream$.sendActionExecutionArgs(
|
|
542
|
+
eventStream$.sendActionExecutionArgs({
|
|
543
|
+
actionExecutionId: toolCallId,
|
|
544
|
+
args: toolCallArgs
|
|
545
|
+
});
|
|
476
546
|
}
|
|
477
547
|
} catch (error) {
|
|
478
548
|
console.error("Error reading from stream", error);
|
|
@@ -480,7 +550,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
|
|
|
480
550
|
}
|
|
481
551
|
}
|
|
482
552
|
} else if (actionExecution) {
|
|
483
|
-
eventStream$.sendActionExecutionResult(
|
|
553
|
+
eventStream$.sendActionExecutionResult({
|
|
554
|
+
actionExecutionId: actionExecution.id,
|
|
555
|
+
actionName: actionExecution.name,
|
|
556
|
+
result: encodeResult(result)
|
|
557
|
+
});
|
|
484
558
|
} else {
|
|
485
559
|
throw new Error("Invalid return type from LangChain function.");
|
|
486
560
|
}
|
|
@@ -660,21 +734,33 @@ var OpenAIAssistantAdapter = class {
|
|
|
660
734
|
eventSource.stream(async (eventStream$) => {
|
|
661
735
|
var _a, _b, _c, _d, _e, _f;
|
|
662
736
|
let inFunctionCall = false;
|
|
737
|
+
let currentMessageId;
|
|
738
|
+
let currentToolCallId;
|
|
663
739
|
for await (const chunk of stream) {
|
|
664
740
|
switch (chunk.event) {
|
|
665
741
|
case "thread.message.created":
|
|
666
742
|
if (inFunctionCall) {
|
|
667
|
-
eventStream$.sendActionExecutionEnd(
|
|
743
|
+
eventStream$.sendActionExecutionEnd({
|
|
744
|
+
actionExecutionId: currentToolCallId
|
|
745
|
+
});
|
|
668
746
|
}
|
|
669
|
-
|
|
747
|
+
currentMessageId = chunk.data.id;
|
|
748
|
+
eventStream$.sendTextMessageStart({
|
|
749
|
+
messageId: currentMessageId
|
|
750
|
+
});
|
|
670
751
|
break;
|
|
671
752
|
case "thread.message.delta":
|
|
672
753
|
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
673
|
-
eventStream$.sendTextMessageContent(
|
|
754
|
+
eventStream$.sendTextMessageContent({
|
|
755
|
+
messageId: currentMessageId,
|
|
756
|
+
content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
|
|
757
|
+
});
|
|
674
758
|
}
|
|
675
759
|
break;
|
|
676
760
|
case "thread.message.completed":
|
|
677
|
-
eventStream$.sendTextMessageEnd(
|
|
761
|
+
eventStream$.sendTextMessageEnd({
|
|
762
|
+
messageId: currentMessageId
|
|
763
|
+
});
|
|
678
764
|
break;
|
|
679
765
|
case "thread.run.step.delta":
|
|
680
766
|
let toolCallId;
|
|
@@ -687,18 +773,30 @@ var OpenAIAssistantAdapter = class {
|
|
|
687
773
|
}
|
|
688
774
|
if (toolCallName && toolCallId) {
|
|
689
775
|
if (inFunctionCall) {
|
|
690
|
-
eventStream$.sendActionExecutionEnd(
|
|
776
|
+
eventStream$.sendActionExecutionEnd({
|
|
777
|
+
actionExecutionId: currentToolCallId
|
|
778
|
+
});
|
|
691
779
|
}
|
|
692
780
|
inFunctionCall = true;
|
|
693
|
-
|
|
781
|
+
currentToolCallId = toolCallId;
|
|
782
|
+
eventStream$.sendActionExecutionStart({
|
|
783
|
+
actionExecutionId: currentToolCallId,
|
|
784
|
+
parentMessageId: chunk.data.id,
|
|
785
|
+
actionName: toolCallName
|
|
786
|
+
});
|
|
694
787
|
} else if (toolCallArgs) {
|
|
695
|
-
eventStream$.sendActionExecutionArgs(
|
|
788
|
+
eventStream$.sendActionExecutionArgs({
|
|
789
|
+
actionExecutionId: currentToolCallId,
|
|
790
|
+
args: toolCallArgs
|
|
791
|
+
});
|
|
696
792
|
}
|
|
697
793
|
break;
|
|
698
794
|
}
|
|
699
795
|
}
|
|
700
796
|
if (inFunctionCall) {
|
|
701
|
-
eventStream$.sendActionExecutionEnd(
|
|
797
|
+
eventStream$.sendActionExecutionEnd({
|
|
798
|
+
actionExecutionId: currentToolCallId
|
|
799
|
+
});
|
|
702
800
|
}
|
|
703
801
|
eventStream$.complete();
|
|
704
802
|
});
|
|
@@ -741,6 +839,7 @@ var UnifyAdapter = class {
|
|
|
741
839
|
apiKey: this.apiKey,
|
|
742
840
|
baseURL: "https://api.unify.ai/v0/"
|
|
743
841
|
});
|
|
842
|
+
const forwardedParameters = request.forwardedParameters;
|
|
744
843
|
const messages = request.messages.map(convertMessageToOpenAIMessage);
|
|
745
844
|
const stream = await openai.chat.completions.create({
|
|
746
845
|
model: this.model,
|
|
@@ -748,49 +847,83 @@ var UnifyAdapter = class {
|
|
|
748
847
|
stream: true,
|
|
749
848
|
...tools.length > 0 && {
|
|
750
849
|
tools
|
|
850
|
+
},
|
|
851
|
+
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
|
|
852
|
+
temperature: forwardedParameters.temperature
|
|
751
853
|
}
|
|
752
854
|
});
|
|
753
855
|
let model = null;
|
|
856
|
+
let currentMessageId;
|
|
857
|
+
let currentToolCallId;
|
|
754
858
|
request.eventSource.stream(async (eventStream$) => {
|
|
755
859
|
var _a, _b;
|
|
756
860
|
let mode = null;
|
|
757
861
|
for await (const chunk of stream) {
|
|
758
862
|
if (this.start) {
|
|
759
863
|
model = chunk.model;
|
|
760
|
-
|
|
761
|
-
eventStream$.
|
|
762
|
-
|
|
763
|
-
|
|
864
|
+
currentMessageId = randomId4();
|
|
865
|
+
eventStream$.sendTextMessageStart({
|
|
866
|
+
messageId: currentMessageId
|
|
867
|
+
});
|
|
868
|
+
eventStream$.sendTextMessageContent({
|
|
869
|
+
messageId: currentMessageId,
|
|
870
|
+
content: `Model used: ${model}
|
|
871
|
+
`
|
|
872
|
+
});
|
|
873
|
+
eventStream$.sendTextMessageEnd({
|
|
874
|
+
messageId: currentMessageId
|
|
875
|
+
});
|
|
764
876
|
this.start = false;
|
|
765
877
|
}
|
|
766
878
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
767
879
|
const content = chunk.choices[0].delta.content;
|
|
768
880
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
769
881
|
mode = null;
|
|
770
|
-
eventStream$.sendTextMessageEnd(
|
|
882
|
+
eventStream$.sendTextMessageEnd({
|
|
883
|
+
messageId: currentMessageId
|
|
884
|
+
});
|
|
771
885
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
772
886
|
mode = null;
|
|
773
|
-
eventStream$.sendActionExecutionEnd(
|
|
887
|
+
eventStream$.sendActionExecutionEnd({
|
|
888
|
+
actionExecutionId: currentToolCallId
|
|
889
|
+
});
|
|
774
890
|
}
|
|
775
891
|
if (mode === null) {
|
|
776
892
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
777
893
|
mode = "function";
|
|
778
|
-
|
|
894
|
+
currentToolCallId = toolCall.id;
|
|
895
|
+
eventStream$.sendActionExecutionStart({
|
|
896
|
+
actionExecutionId: currentToolCallId,
|
|
897
|
+
actionName: toolCall.function.name
|
|
898
|
+
});
|
|
779
899
|
} else if (content) {
|
|
780
900
|
mode = "message";
|
|
781
|
-
|
|
901
|
+
currentMessageId = chunk.id;
|
|
902
|
+
eventStream$.sendTextMessageStart({
|
|
903
|
+
messageId: currentMessageId
|
|
904
|
+
});
|
|
782
905
|
}
|
|
783
906
|
}
|
|
784
907
|
if (mode === "message" && content) {
|
|
785
|
-
eventStream$.sendTextMessageContent(
|
|
908
|
+
eventStream$.sendTextMessageContent({
|
|
909
|
+
messageId: currentMessageId,
|
|
910
|
+
content
|
|
911
|
+
});
|
|
786
912
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
787
|
-
eventStream$.sendActionExecutionArgs(
|
|
913
|
+
eventStream$.sendActionExecutionArgs({
|
|
914
|
+
actionExecutionId: currentToolCallId,
|
|
915
|
+
args: toolCall.function.arguments
|
|
916
|
+
});
|
|
788
917
|
}
|
|
789
918
|
}
|
|
790
919
|
if (mode === "message") {
|
|
791
|
-
eventStream$.sendTextMessageEnd(
|
|
920
|
+
eventStream$.sendTextMessageEnd({
|
|
921
|
+
messageId: currentMessageId
|
|
922
|
+
});
|
|
792
923
|
} else if (mode === "function") {
|
|
793
|
-
eventStream$.sendActionExecutionEnd(
|
|
924
|
+
eventStream$.sendActionExecutionEnd({
|
|
925
|
+
actionExecutionId: currentToolCallId
|
|
926
|
+
});
|
|
794
927
|
}
|
|
795
928
|
eventStream$.complete();
|
|
796
929
|
});
|
|
@@ -851,40 +984,67 @@ var GroqAdapter = class {
|
|
|
851
984
|
},
|
|
852
985
|
...this.disableParallelToolCalls && {
|
|
853
986
|
parallel_tool_calls: false
|
|
987
|
+
},
|
|
988
|
+
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) && {
|
|
989
|
+
temperature: forwardedParameters.temperature
|
|
854
990
|
}
|
|
855
991
|
});
|
|
856
992
|
eventSource.stream(async (eventStream$) => {
|
|
857
993
|
var _a, _b;
|
|
858
994
|
let mode = null;
|
|
995
|
+
let currentMessageId;
|
|
996
|
+
let currentToolCallId;
|
|
859
997
|
for await (const chunk of stream) {
|
|
860
998
|
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
861
999
|
const content = chunk.choices[0].delta.content;
|
|
862
1000
|
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
863
1001
|
mode = null;
|
|
864
|
-
eventStream$.sendTextMessageEnd(
|
|
1002
|
+
eventStream$.sendTextMessageEnd({
|
|
1003
|
+
messageId: currentMessageId
|
|
1004
|
+
});
|
|
865
1005
|
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
866
1006
|
mode = null;
|
|
867
|
-
eventStream$.sendActionExecutionEnd(
|
|
1007
|
+
eventStream$.sendActionExecutionEnd({
|
|
1008
|
+
actionExecutionId: currentToolCallId
|
|
1009
|
+
});
|
|
868
1010
|
}
|
|
869
1011
|
if (mode === null) {
|
|
870
1012
|
if (toolCall == null ? void 0 : toolCall.id) {
|
|
871
1013
|
mode = "function";
|
|
872
|
-
|
|
1014
|
+
currentToolCallId = toolCall.id;
|
|
1015
|
+
eventStream$.sendActionExecutionStart({
|
|
1016
|
+
actionExecutionId: currentToolCallId,
|
|
1017
|
+
actionName: toolCall.function.name,
|
|
1018
|
+
parentMessageId: chunk.id
|
|
1019
|
+
});
|
|
873
1020
|
} else if (content) {
|
|
874
1021
|
mode = "message";
|
|
875
|
-
|
|
1022
|
+
currentMessageId = chunk.id;
|
|
1023
|
+
eventStream$.sendTextMessageStart({
|
|
1024
|
+
messageId: currentMessageId
|
|
1025
|
+
});
|
|
876
1026
|
}
|
|
877
1027
|
}
|
|
878
1028
|
if (mode === "message" && content) {
|
|
879
|
-
eventStream$.sendTextMessageContent(
|
|
1029
|
+
eventStream$.sendTextMessageContent({
|
|
1030
|
+
messageId: currentMessageId,
|
|
1031
|
+
content
|
|
1032
|
+
});
|
|
880
1033
|
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
881
|
-
eventStream$.sendActionExecutionArgs(
|
|
1034
|
+
eventStream$.sendActionExecutionArgs({
|
|
1035
|
+
actionExecutionId: currentToolCallId,
|
|
1036
|
+
args: toolCall.function.arguments
|
|
1037
|
+
});
|
|
882
1038
|
}
|
|
883
1039
|
}
|
|
884
1040
|
if (mode === "message") {
|
|
885
|
-
eventStream$.sendTextMessageEnd(
|
|
1041
|
+
eventStream$.sendTextMessageEnd({
|
|
1042
|
+
messageId: currentMessageId
|
|
1043
|
+
});
|
|
886
1044
|
} else if (mode === "function") {
|
|
887
|
-
eventStream$.sendActionExecutionEnd(
|
|
1045
|
+
eventStream$.sendActionExecutionEnd({
|
|
1046
|
+
actionExecutionId: currentToolCallId
|
|
1047
|
+
});
|
|
888
1048
|
}
|
|
889
1049
|
eventStream$.complete();
|
|
890
1050
|
});
|
|
@@ -1068,6 +1228,9 @@ var AnthropicAdapter = class {
|
|
|
1068
1228
|
model: this.model,
|
|
1069
1229
|
messages: anthropicMessages,
|
|
1070
1230
|
max_tokens: (forwardedParameters == null ? void 0 : forwardedParameters.maxTokens) || 1024,
|
|
1231
|
+
...(forwardedParameters == null ? void 0 : forwardedParameters.temperature) ? {
|
|
1232
|
+
temperature: forwardedParameters.temperature
|
|
1233
|
+
} : {},
|
|
1071
1234
|
...tools.length > 0 && {
|
|
1072
1235
|
tools
|
|
1073
1236
|
},
|
|
@@ -1092,7 +1255,11 @@ var AnthropicAdapter = class {
|
|
|
1092
1255
|
mode = "message";
|
|
1093
1256
|
} else if (chunk.content_block.type === "tool_use") {
|
|
1094
1257
|
currentToolCallId = chunk.content_block.id;
|
|
1095
|
-
eventStream$.sendActionExecutionStart(
|
|
1258
|
+
eventStream$.sendActionExecutionStart({
|
|
1259
|
+
actionExecutionId: currentToolCallId,
|
|
1260
|
+
actionName: chunk.content_block.name,
|
|
1261
|
+
parentMessageId: currentMessageId
|
|
1262
|
+
});
|
|
1096
1263
|
mode = "function";
|
|
1097
1264
|
}
|
|
1098
1265
|
} else if (chunk.type === "content_block_delta") {
|
|
@@ -1100,21 +1267,33 @@ var AnthropicAdapter = class {
|
|
|
1100
1267
|
const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
|
|
1101
1268
|
if (text.length > 0) {
|
|
1102
1269
|
if (!didOutputText) {
|
|
1103
|
-
eventStream$.sendTextMessageStart(
|
|
1270
|
+
eventStream$.sendTextMessageStart({
|
|
1271
|
+
messageId: currentMessageId
|
|
1272
|
+
});
|
|
1104
1273
|
didOutputText = true;
|
|
1105
1274
|
}
|
|
1106
|
-
eventStream$.sendTextMessageContent(
|
|
1275
|
+
eventStream$.sendTextMessageContent({
|
|
1276
|
+
messageId: currentMessageId,
|
|
1277
|
+
content: text
|
|
1278
|
+
});
|
|
1107
1279
|
}
|
|
1108
1280
|
} else if (chunk.delta.type === "input_json_delta") {
|
|
1109
|
-
eventStream$.sendActionExecutionArgs(
|
|
1281
|
+
eventStream$.sendActionExecutionArgs({
|
|
1282
|
+
actionExecutionId: currentToolCallId,
|
|
1283
|
+
args: chunk.delta.partial_json
|
|
1284
|
+
});
|
|
1110
1285
|
}
|
|
1111
1286
|
} else if (chunk.type === "content_block_stop") {
|
|
1112
1287
|
if (mode === "message") {
|
|
1113
1288
|
if (didOutputText) {
|
|
1114
|
-
eventStream$.sendTextMessageEnd(
|
|
1289
|
+
eventStream$.sendTextMessageEnd({
|
|
1290
|
+
messageId: currentMessageId
|
|
1291
|
+
});
|
|
1115
1292
|
}
|
|
1116
1293
|
} else if (mode === "function") {
|
|
1117
|
-
eventStream$.sendActionExecutionEnd(
|
|
1294
|
+
eventStream$.sendActionExecutionEnd({
|
|
1295
|
+
actionExecutionId: currentToolCallId
|
|
1296
|
+
});
|
|
1118
1297
|
}
|
|
1119
1298
|
}
|
|
1120
1299
|
}
|
|
@@ -1159,6 +1338,60 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
|
|
|
1159
1338
|
}
|
|
1160
1339
|
}, "FilterThinkingTextBuffer");
|
|
1161
1340
|
|
|
1341
|
+
// src/service-adapters/experimental/ollama/ollama-adapter.ts
|
|
1342
|
+
import { Ollama } from "@langchain/community/llms/ollama";
|
|
1343
|
+
import { randomId as randomId7 } from "@copilotkit/shared";
|
|
1344
|
+
var DEFAULT_MODEL4 = "llama3:latest";
|
|
1345
|
+
var ExperimentalOllamaAdapter = class {
|
|
1346
|
+
model;
|
|
1347
|
+
constructor(options) {
|
|
1348
|
+
if (options == null ? void 0 : options.model) {
|
|
1349
|
+
this.model = options.model;
|
|
1350
|
+
} else {
|
|
1351
|
+
this.model = DEFAULT_MODEL4;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
async process(request) {
|
|
1355
|
+
const { messages, actions, eventSource } = request;
|
|
1356
|
+
const ollama = new Ollama({
|
|
1357
|
+
model: this.model
|
|
1358
|
+
});
|
|
1359
|
+
const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
|
|
1360
|
+
const _stream = await ollama.stream(contents);
|
|
1361
|
+
eventSource.stream(async (eventStream$) => {
|
|
1362
|
+
const currentMessageId = randomId7();
|
|
1363
|
+
eventStream$.sendTextMessageStart({
|
|
1364
|
+
messageId: currentMessageId
|
|
1365
|
+
});
|
|
1366
|
+
for await (const chunkText of _stream) {
|
|
1367
|
+
eventStream$.sendTextMessageContent({
|
|
1368
|
+
messageId: currentMessageId,
|
|
1369
|
+
content: chunkText
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
eventStream$.sendTextMessageEnd({
|
|
1373
|
+
messageId: currentMessageId
|
|
1374
|
+
});
|
|
1375
|
+
eventStream$.complete();
|
|
1376
|
+
});
|
|
1377
|
+
return {
|
|
1378
|
+
threadId: request.threadId || randomId7()
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
__name(ExperimentalOllamaAdapter, "ExperimentalOllamaAdapter");
|
|
1383
|
+
|
|
1384
|
+
// src/service-adapters/experimental/empty/empty-adapter.ts
|
|
1385
|
+
import { randomId as randomId8 } from "@copilotkit/shared";
|
|
1386
|
+
var ExperimentalEmptyAdapter = class {
|
|
1387
|
+
async process(request) {
|
|
1388
|
+
return {
|
|
1389
|
+
threadId: request.threadId || randomId8()
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
__name(ExperimentalEmptyAdapter, "ExperimentalEmptyAdapter");
|
|
1394
|
+
|
|
1162
1395
|
export {
|
|
1163
1396
|
RemoteChain,
|
|
1164
1397
|
OpenAIAdapter,
|
|
@@ -1168,6 +1401,8 @@ export {
|
|
|
1168
1401
|
OpenAIAssistantAdapter,
|
|
1169
1402
|
UnifyAdapter,
|
|
1170
1403
|
GroqAdapter,
|
|
1171
|
-
AnthropicAdapter
|
|
1404
|
+
AnthropicAdapter,
|
|
1405
|
+
ExperimentalOllamaAdapter,
|
|
1406
|
+
ExperimentalEmptyAdapter
|
|
1172
1407
|
};
|
|
1173
|
-
//# sourceMappingURL=chunk-
|
|
1408
|
+
//# sourceMappingURL=chunk-CLGKEUOA.mjs.map
|