@copilotkit/react-core 0.21.0-mme-assistant-api.0 → 0.21.0-mme-experimental-actions.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/.turbo/turbo-build.log +135 -121
- package/CHANGELOG.md +13 -2
- package/dist/{chunk-WH4L73VS.mjs → chunk-55K3I3XY.mjs} +7 -3
- package/dist/chunk-55K3I3XY.mjs.map +1 -0
- package/dist/{chunk-3WKJ25L3.mjs → chunk-BQ5SSV4Z.mjs} +12 -25
- package/dist/chunk-BQ5SSV4Z.mjs.map +1 -0
- package/dist/{chunk-JVCBCB2T.mjs → chunk-FDXBLJ6Y.mjs} +2 -2
- package/dist/chunk-HGMVI4JR.mjs +13 -0
- package/dist/chunk-HGMVI4JR.mjs.map +1 -0
- package/dist/{chunk-6WZFE6II.mjs → chunk-IA65HSBF.mjs} +3 -3
- package/dist/chunk-IOP6JX34.mjs +1 -0
- package/dist/{chunk-2YF2MC22.mjs → chunk-JFUS5YVO.mjs} +4 -21
- package/dist/chunk-JFUS5YVO.mjs.map +1 -0
- package/dist/{chunk-KLGA2MES.mjs → chunk-L2IFWQP4.mjs} +5 -5
- package/dist/chunk-L2IFWQP4.mjs.map +1 -0
- package/dist/{chunk-PHK2K7UB.mjs → chunk-L4WLQMO6.mjs} +16 -24
- package/dist/chunk-L4WLQMO6.mjs.map +1 -0
- package/dist/{chunk-S7ZVOTYK.mjs → chunk-M2RCEQTX.mjs} +1 -1
- package/dist/chunk-M2RCEQTX.mjs.map +1 -0
- package/dist/{chunk-UHTJLRI6.mjs → chunk-MI6PIZOT.mjs} +6 -6
- package/dist/{chunk-2EP7VLPI.mjs → chunk-OBWBSGOG.mjs} +2 -2
- package/dist/chunk-QAIUQFOK.mjs +85 -0
- package/dist/chunk-QAIUQFOK.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.js +10 -16
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +3 -3
- package/dist/components/copilot-provider/index.js +10 -16
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +3 -3
- package/dist/components/index.js +10 -16
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +3 -3
- package/dist/context/copilot-context.d.ts +5 -5
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +105 -46
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +17 -12
- package/dist/hooks/use-chat.js +6 -33
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +2 -2
- package/dist/hooks/use-copilot-action-implementation.d.ts +6 -0
- package/dist/hooks/use-copilot-action-implementation.js +179 -0
- package/dist/hooks/use-copilot-action-implementation.js.map +1 -0
- package/dist/hooks/use-copilot-action-implementation.mjs +12 -0
- package/dist/hooks/use-copilot-action-implementation.mjs.map +1 -0
- package/dist/hooks/use-copilot-action.d.ts +5 -0
- package/dist/hooks/use-copilot-action.js +137 -0
- package/dist/hooks/use-copilot-action.js.map +1 -0
- package/dist/hooks/use-copilot-action.mjs +11 -0
- package/dist/hooks/use-copilot-action.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat.js +6 -33
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +6 -6
- package/dist/hooks/use-make-copilot-actionable.d.ts +3 -0
- package/dist/hooks/use-make-copilot-actionable.js +60 -6
- package/dist/hooks/use-make-copilot-actionable.js.map +1 -1
- package/dist/hooks/use-make-copilot-actionable.mjs +3 -2
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/hooks/use-make-copilot-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-readable.mjs +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +130 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -21
- package/dist/lib/copilot-task.d.ts +3 -3
- package/dist/lib/copilot-task.js +10 -19
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +5 -5
- package/dist/lib/index.js +10 -19
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +5 -5
- package/dist/openai-assistants/hooks/index.js.map +1 -1
- package/dist/openai-assistants/hooks/index.mjs +4 -4
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.js.map +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +4 -4
- package/dist/openai-assistants/index.js.map +1 -1
- package/dist/openai-assistants/index.mjs +4 -4
- package/dist/utils/fetch-chat-completion.js +13 -24
- package/dist/utils/fetch-chat-completion.js.map +1 -1
- package/dist/utils/fetch-chat-completion.mjs +1 -1
- package/package.json +6 -6
- package/src/components/copilot-provider/copilotkit.tsx +16 -50
- package/src/context/copilot-context.tsx +5 -7
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-chat.ts +1 -20
- package/src/hooks/use-copilot-action-implementation.ts +100 -0
- package/src/hooks/use-copilot-action.ts +44 -0
- package/src/hooks/use-make-copilot-actionable.ts +6 -1
- package/src/lib/copilot-task.ts +5 -5
- package/src/utils/fetch-chat-completion.ts +11 -25
- package/dist/chunk-2YF2MC22.mjs.map +0 -1
- package/dist/chunk-3WKJ25L3.mjs.map +0 -1
- package/dist/chunk-5UGLWBZJ.mjs +0 -1
- package/dist/chunk-KLGA2MES.mjs.map +0 -1
- package/dist/chunk-PHK2K7UB.mjs.map +0 -1
- package/dist/chunk-S7ZVOTYK.mjs.map +0 -1
- package/dist/chunk-WH4L73VS.mjs.map +0 -1
- /package/dist/{chunk-JVCBCB2T.mjs.map → chunk-FDXBLJ6Y.mjs.map} +0 -0
- /package/dist/{chunk-6WZFE6II.mjs.map → chunk-IA65HSBF.mjs.map} +0 -0
- /package/dist/{chunk-5UGLWBZJ.mjs.map → chunk-IOP6JX34.mjs.map} +0 -0
- /package/dist/{chunk-UHTJLRI6.mjs.map → chunk-MI6PIZOT.mjs.map} +0 -0
- /package/dist/{chunk-2EP7VLPI.mjs.map → chunk-OBWBSGOG.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -87,6 +87,7 @@ __export(src_exports, {
|
|
|
87
87
|
fetchAndDecodeChatCompletionAsText: () => fetchAndDecodeChatCompletionAsText,
|
|
88
88
|
fetchChatCompletion: () => fetchChatCompletion,
|
|
89
89
|
processMessageStream: () => processMessageStream,
|
|
90
|
+
useCopilotAction: () => useCopilotAction,
|
|
90
91
|
useCopilotChat: () => useCopilotChat,
|
|
91
92
|
useCopilotChatV2: () => useCopilotChatV2,
|
|
92
93
|
useCopilotContext: () => useCopilotContext,
|
|
@@ -460,31 +461,25 @@ ${nonDocumentStrings}`;
|
|
|
460
461
|
);
|
|
461
462
|
}
|
|
462
463
|
var defaultCopilotContextCategories = ["global"];
|
|
463
|
-
function
|
|
464
|
+
function entryPointsToChatCompletionFunctions(actions) {
|
|
465
|
+
return actions.map(import_shared.actionToChatCompletionFunction);
|
|
466
|
+
}
|
|
467
|
+
function entryPointsToFunctionCallHandler(actions) {
|
|
464
468
|
return (chatMessages, functionCall) => __async(this, null, function* () {
|
|
465
|
-
let
|
|
466
|
-
for (let
|
|
467
|
-
|
|
469
|
+
let actionsByFunctionName = {};
|
|
470
|
+
for (let action2 of actions) {
|
|
471
|
+
actionsByFunctionName[action2.name] = action2;
|
|
468
472
|
}
|
|
469
|
-
const
|
|
470
|
-
if (
|
|
473
|
+
const action = actionsByFunctionName[functionCall.name || ""];
|
|
474
|
+
if (action) {
|
|
471
475
|
let functionCallArguments = [];
|
|
472
476
|
if (functionCall.arguments) {
|
|
473
477
|
functionCallArguments = JSON.parse(functionCall.arguments);
|
|
474
478
|
}
|
|
475
|
-
|
|
476
|
-
for (let arg of entryPointFunction.argumentAnnotations) {
|
|
477
|
-
paramsInCorrectOrder.push(
|
|
478
|
-
functionCallArguments[arg.name]
|
|
479
|
-
);
|
|
480
|
-
}
|
|
481
|
-
yield entryPointFunction.implementation(...paramsInCorrectOrder);
|
|
479
|
+
return yield action.handler(functionCallArguments);
|
|
482
480
|
}
|
|
483
481
|
});
|
|
484
482
|
}
|
|
485
|
-
function entryPointsToChatCompletionFunctions(entryPoints) {
|
|
486
|
-
return entryPoints.map(import_shared.annotatedFunctionToChatCompletionFunction);
|
|
487
|
-
}
|
|
488
483
|
|
|
489
484
|
// src/hooks/use-copilot-chat.ts
|
|
490
485
|
var import_react6 = require("react");
|
|
@@ -507,6 +502,7 @@ function fetchChatCompletion(_0) {
|
|
|
507
502
|
body,
|
|
508
503
|
signal
|
|
509
504
|
}) {
|
|
505
|
+
var _a, _b;
|
|
510
506
|
temperature || (temperature = 0.5);
|
|
511
507
|
tools || (tools = []);
|
|
512
508
|
const cleanedMessages = messages.map((message) => {
|
|
@@ -522,47 +518,32 @@ function fetchChatCompletion(_0) {
|
|
|
522
518
|
model,
|
|
523
519
|
messages: cleanedMessages,
|
|
524
520
|
stream: true
|
|
525
|
-
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps),
|
|
521
|
+
}, tools.length ? { tools } : {}), temperature ? { temperature } : {}), tools.length != 0 ? { tool_choice: "auto" } : {}), copilotConfig.body), copilotConfig.backendOnlyProps), Object.keys((_a = copilotConfig["body"]) != null ? _a : {}).length > 0 ? { [import_shared2.EXCLUDE_FROM_FORWARD_PROPS_KEYS]: Object.keys((_b = copilotConfig["body"]) != null ? _b : {}) } : {}), body ? __spreadValues({}, body) : {})),
|
|
526
522
|
signal
|
|
527
523
|
});
|
|
528
524
|
return response;
|
|
529
525
|
});
|
|
530
526
|
}
|
|
531
|
-
function excludeBackendOnlyProps(copilotConfig) {
|
|
532
|
-
var _a;
|
|
533
|
-
const backendOnlyProps = (_a = copilotConfig.backendOnlyProps) != null ? _a : {};
|
|
534
|
-
if (Object.keys(backendOnlyProps).length > 0) {
|
|
535
|
-
return {
|
|
536
|
-
[import_shared2.EXCLUDE_FROM_FORWARD_PROPS_KEYS]: Object.keys(backendOnlyProps)
|
|
537
|
-
};
|
|
538
|
-
} else {
|
|
539
|
-
return {};
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
527
|
function fetchAndDecodeChatCompletion(params) {
|
|
543
528
|
return __async(this, null, function* () {
|
|
544
529
|
const response = yield fetchChatCompletion(params);
|
|
545
530
|
if (!response.ok || !response.body) {
|
|
546
|
-
response
|
|
547
|
-
} else {
|
|
548
|
-
const events = yield (0, import_shared2.decodeChatCompletion)((0, import_shared2.parseChatCompletion)(response.body));
|
|
549
|
-
response.events = events;
|
|
531
|
+
return __spreadProps(__spreadValues({}, response), { events: null });
|
|
550
532
|
}
|
|
551
|
-
|
|
533
|
+
const events = yield (0, import_shared2.decodeChatCompletion)((0, import_shared2.parseChatCompletion)(response.body));
|
|
534
|
+
return __spreadProps(__spreadValues({}, response), { events });
|
|
552
535
|
});
|
|
553
536
|
}
|
|
554
537
|
function fetchAndDecodeChatCompletionAsText(params) {
|
|
555
538
|
return __async(this, null, function* () {
|
|
556
539
|
const response = yield fetchChatCompletion(params);
|
|
557
540
|
if (!response.ok || !response.body) {
|
|
558
|
-
response
|
|
559
|
-
} else {
|
|
560
|
-
const events = yield (0, import_shared2.decodeChatCompletionAsText)(
|
|
561
|
-
(0, import_shared2.decodeChatCompletion)((0, import_shared2.parseChatCompletion)(response.body))
|
|
562
|
-
);
|
|
563
|
-
response.events = events;
|
|
541
|
+
return __spreadProps(__spreadValues({}, response), { events: null });
|
|
564
542
|
}
|
|
565
|
-
|
|
543
|
+
const events = yield (0, import_shared2.decodeChatCompletionAsText)(
|
|
544
|
+
(0, import_shared2.decodeChatCompletion)((0, import_shared2.parseChatCompletion)(response.body))
|
|
545
|
+
);
|
|
546
|
+
return __spreadProps(__spreadValues({}, response), { events });
|
|
566
547
|
});
|
|
567
548
|
}
|
|
568
549
|
|
|
@@ -572,8 +553,6 @@ function useChat(options) {
|
|
|
572
553
|
const [input, setInput] = (0, import_react5.useState)("");
|
|
573
554
|
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
574
555
|
const abortControllerRef = (0, import_react5.useRef)();
|
|
575
|
-
const threadIdRef = (0, import_react5.useRef)(null);
|
|
576
|
-
const runIdRef = (0, import_react5.useRef)(null);
|
|
577
556
|
const runChatCompletion = (messages2) => __async(this, null, function* () {
|
|
578
557
|
setIsLoading(true);
|
|
579
558
|
const newMessages = [
|
|
@@ -587,27 +566,14 @@ function useChat(options) {
|
|
|
587
566
|
const abortController = new AbortController();
|
|
588
567
|
abortControllerRef.current = abortController;
|
|
589
568
|
setMessages([...messages2, ...newMessages]);
|
|
590
|
-
const copilotConfigBody = options.copilotConfig.body || {};
|
|
591
|
-
if (threadIdRef.current) {
|
|
592
|
-
copilotConfigBody.threadId = threadIdRef.current;
|
|
593
|
-
}
|
|
594
|
-
if (runIdRef.current) {
|
|
595
|
-
copilotConfigBody.runId = runIdRef.current;
|
|
596
|
-
}
|
|
597
569
|
const messagesWithContext = [...options.initialMessages || [], ...messages2];
|
|
598
570
|
const response = yield fetchAndDecodeChatCompletion({
|
|
599
|
-
copilotConfig:
|
|
571
|
+
copilotConfig: options.copilotConfig,
|
|
600
572
|
messages: messagesWithContext,
|
|
601
573
|
tools: options.tools,
|
|
602
574
|
headers: options.headers,
|
|
603
575
|
signal: abortController.signal
|
|
604
576
|
});
|
|
605
|
-
if (response.headers.get("threadid")) {
|
|
606
|
-
threadIdRef.current = response.headers.get("threadid");
|
|
607
|
-
}
|
|
608
|
-
if (response.headers.get("runid")) {
|
|
609
|
-
runIdRef.current = response.headers.get("runid");
|
|
610
|
-
}
|
|
611
577
|
if (!response.events) {
|
|
612
578
|
throw new Error("Failed to fetch chat completion");
|
|
613
579
|
}
|
|
@@ -799,12 +765,90 @@ ${additionalInstructions}` : "");
|
|
|
799
765
|
}
|
|
800
766
|
|
|
801
767
|
// src/hooks/use-make-copilot-actionable.ts
|
|
768
|
+
var import_react8 = require("react");
|
|
769
|
+
var import_nanoid5 = require("nanoid");
|
|
770
|
+
|
|
771
|
+
// src/hooks/use-copilot-action-implementation.ts
|
|
802
772
|
var import_react7 = require("react");
|
|
803
773
|
var import_nanoid4 = require("nanoid");
|
|
804
|
-
function
|
|
774
|
+
function useCopilotActionImplementation(action, dependencies) {
|
|
775
|
+
const { setEntryPoint, removeEntryPoint, entryPoints } = (0, import_react7.useContext)(CopilotContext);
|
|
805
776
|
const idRef = (0, import_react7.useRef)((0, import_nanoid4.nanoid)());
|
|
806
|
-
|
|
807
|
-
|
|
777
|
+
if (dependencies === void 0) {
|
|
778
|
+
if (entryPoints[idRef.current]) {
|
|
779
|
+
entryPoints[idRef.current].handler = action.handler;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
(0, import_react7.useEffect)(() => {
|
|
783
|
+
setEntryPoint(idRef.current, action);
|
|
784
|
+
return () => {
|
|
785
|
+
removeEntryPoint(idRef.current);
|
|
786
|
+
};
|
|
787
|
+
}, [
|
|
788
|
+
setEntryPoint,
|
|
789
|
+
removeEntryPoint,
|
|
790
|
+
action.description,
|
|
791
|
+
action.name,
|
|
792
|
+
// This should be faster than deep equality checking
|
|
793
|
+
// In addition, all major JS engines guarantee the order of object keys
|
|
794
|
+
JSON.stringify(action.parameters),
|
|
795
|
+
// dependencies set by the developer
|
|
796
|
+
...dependencies || []
|
|
797
|
+
]);
|
|
798
|
+
}
|
|
799
|
+
function annotatedFunctionToAction(annotatedFunction) {
|
|
800
|
+
const parameters = annotatedFunction.argumentAnnotations.map((annotation) => {
|
|
801
|
+
switch (annotation.type) {
|
|
802
|
+
case "string":
|
|
803
|
+
case "number":
|
|
804
|
+
case "boolean":
|
|
805
|
+
case "object":
|
|
806
|
+
return {
|
|
807
|
+
name: annotation.name,
|
|
808
|
+
description: annotation.description,
|
|
809
|
+
type: annotation.type,
|
|
810
|
+
required: annotation.required
|
|
811
|
+
};
|
|
812
|
+
case "array":
|
|
813
|
+
let type;
|
|
814
|
+
if (annotation.items.type === "string") {
|
|
815
|
+
type = "string[]";
|
|
816
|
+
} else if (annotation.items.type === "number") {
|
|
817
|
+
type = "number[]";
|
|
818
|
+
} else if (annotation.items.type === "boolean") {
|
|
819
|
+
type = "boolean[]";
|
|
820
|
+
} else if (annotation.items.type === "object") {
|
|
821
|
+
type = "object[]";
|
|
822
|
+
} else {
|
|
823
|
+
type = "string[]";
|
|
824
|
+
}
|
|
825
|
+
return {
|
|
826
|
+
name: annotation.name,
|
|
827
|
+
description: annotation.description,
|
|
828
|
+
type,
|
|
829
|
+
required: annotation.required
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
return {
|
|
834
|
+
name: annotatedFunction.name,
|
|
835
|
+
description: annotatedFunction.description,
|
|
836
|
+
parameters,
|
|
837
|
+
handler: (args) => {
|
|
838
|
+
const paramsInCorrectOrder = [];
|
|
839
|
+
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
840
|
+
paramsInCorrectOrder.push(args[arg.name]);
|
|
841
|
+
}
|
|
842
|
+
return annotatedFunction.implementation(...paramsInCorrectOrder);
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// src/hooks/use-make-copilot-actionable.ts
|
|
848
|
+
function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
849
|
+
const idRef = (0, import_react8.useRef)((0, import_nanoid5.nanoid)());
|
|
850
|
+
const { setEntryPoint, removeEntryPoint } = (0, import_react8.useContext)(CopilotContext);
|
|
851
|
+
const memoizedAnnotatedFunction = (0, import_react8.useMemo)(
|
|
808
852
|
() => ({
|
|
809
853
|
name: annotatedFunction.name,
|
|
810
854
|
description: annotatedFunction.description,
|
|
@@ -813,20 +857,26 @@ function useMakeCopilotActionable(annotatedFunction, dependencies) {
|
|
|
813
857
|
}),
|
|
814
858
|
dependencies
|
|
815
859
|
);
|
|
816
|
-
(0,
|
|
817
|
-
|
|
860
|
+
(0, import_react8.useEffect)(() => {
|
|
861
|
+
const action = annotatedFunctionToAction(memoizedAnnotatedFunction);
|
|
862
|
+
setEntryPoint(idRef.current, action);
|
|
818
863
|
return () => {
|
|
819
864
|
removeEntryPoint(idRef.current);
|
|
820
865
|
};
|
|
821
866
|
}, [memoizedAnnotatedFunction, setEntryPoint, removeEntryPoint]);
|
|
822
867
|
}
|
|
823
868
|
|
|
869
|
+
// src/hooks/use-copilot-action.ts
|
|
870
|
+
function useCopilotAction(action, dependencies) {
|
|
871
|
+
return useCopilotActionImplementation(action, dependencies);
|
|
872
|
+
}
|
|
873
|
+
|
|
824
874
|
// src/hooks/use-make-copilot-readable.ts
|
|
825
|
-
var
|
|
875
|
+
var import_react9 = require("react");
|
|
826
876
|
function useMakeCopilotReadable(information, parentId, categories) {
|
|
827
|
-
const { addContext, removeContext } = (0,
|
|
828
|
-
const idRef = (0,
|
|
829
|
-
(0,
|
|
877
|
+
const { addContext, removeContext } = (0, import_react9.useContext)(CopilotContext);
|
|
878
|
+
const idRef = (0, import_react9.useRef)();
|
|
879
|
+
(0, import_react9.useEffect)(() => {
|
|
830
880
|
const id = addContext(information, parentId, categories);
|
|
831
881
|
idRef.current = id;
|
|
832
882
|
return () => {
|
|
@@ -837,11 +887,11 @@ function useMakeCopilotReadable(information, parentId, categories) {
|
|
|
837
887
|
}
|
|
838
888
|
|
|
839
889
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
840
|
-
var
|
|
890
|
+
var import_react10 = require("react");
|
|
841
891
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
842
|
-
const { addDocumentContext, removeDocumentContext } = (0,
|
|
843
|
-
const idRef = (0,
|
|
844
|
-
(0,
|
|
892
|
+
const { addDocumentContext, removeDocumentContext } = (0, import_react10.useContext)(CopilotContext);
|
|
893
|
+
const idRef = (0, import_react10.useRef)();
|
|
894
|
+
(0, import_react10.useEffect)(() => {
|
|
845
895
|
const id = addDocumentContext(document, categories);
|
|
846
896
|
idRef.current = id;
|
|
847
897
|
return () => {
|
|
@@ -852,7 +902,7 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
852
902
|
}
|
|
853
903
|
|
|
854
904
|
// src/openai-assistants/hooks/use-copilot-chat-v2.ts
|
|
855
|
-
var
|
|
905
|
+
var import_react11 = require("react");
|
|
856
906
|
|
|
857
907
|
// src/openai-assistants/utils/process-message-stream.ts
|
|
858
908
|
function processMessageStream(reader, processMessage) {
|
|
@@ -885,13 +935,13 @@ function useCopilotChatV2(options) {
|
|
|
885
935
|
getChatCompletionFunctionDescriptions,
|
|
886
936
|
getFunctionCallHandler,
|
|
887
937
|
copilotApiConfig
|
|
888
|
-
} = (0,
|
|
889
|
-
const [messages, setMessages] = (0,
|
|
890
|
-
const [input, setInput] = (0,
|
|
891
|
-
const [threadId, setThreadId] = (0,
|
|
892
|
-
const [status, setStatus] = (0,
|
|
893
|
-
const [error, setError] = (0,
|
|
894
|
-
const systemMessage = (0,
|
|
938
|
+
} = (0, import_react11.useContext)(CopilotContext);
|
|
939
|
+
const [messages, setMessages] = (0, import_react11.useState)([]);
|
|
940
|
+
const [input, setInput] = (0, import_react11.useState)("");
|
|
941
|
+
const [threadId, setThreadId] = (0, import_react11.useState)(void 0);
|
|
942
|
+
const [status, setStatus] = (0, import_react11.useState)("awaiting_message");
|
|
943
|
+
const [error, setError] = (0, import_react11.useState)(void 0);
|
|
944
|
+
const systemMessage = (0, import_react11.useMemo)(() => {
|
|
895
945
|
const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage2;
|
|
896
946
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
897
947
|
return {
|
|
@@ -998,14 +1048,14 @@ If you would like to call a function, call it without saying anything else.
|
|
|
998
1048
|
var CopilotTask = class {
|
|
999
1049
|
constructor(config) {
|
|
1000
1050
|
this.instructions = config.instructions;
|
|
1001
|
-
this.
|
|
1051
|
+
this.actions = config.actions || [];
|
|
1002
1052
|
this.includeCopilotReadable = config.includeCopilotReadable || true;
|
|
1003
1053
|
this.includeCopilotActionable = config.includeCopilotActionable || true;
|
|
1004
1054
|
}
|
|
1005
1055
|
run(context, data) {
|
|
1006
1056
|
return __async(this, null, function* () {
|
|
1007
1057
|
const entryPoints = this.includeCopilotActionable ? Object.assign({}, context.entryPoints) : {};
|
|
1008
|
-
for (const fn of this.
|
|
1058
|
+
for (const fn of this.actions) {
|
|
1009
1059
|
entryPoints[fn.name] = fn;
|
|
1010
1060
|
}
|
|
1011
1061
|
let contextString = "";
|
|
@@ -1091,6 +1141,7 @@ ${instructions}
|
|
|
1091
1141
|
fetchAndDecodeChatCompletionAsText,
|
|
1092
1142
|
fetchChatCompletion,
|
|
1093
1143
|
processMessageStream,
|
|
1144
|
+
useCopilotAction,
|
|
1094
1145
|
useCopilotChat,
|
|
1095
1146
|
useCopilotChatV2,
|
|
1096
1147
|
useCopilotContext,
|