@copilotkit/react-core 0.15.0-alpha.4 → 0.15.0-alpha.5
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 +69 -73
- package/CHANGELOG.md +11 -0
- package/dist/{chunk-QFC2R4ZS.mjs → chunk-JHJ7LUTD.mjs} +5 -5
- package/dist/chunk-JHJ7LUTD.mjs.map +1 -0
- package/dist/{chunk-IZPRCKHE.mjs → chunk-OFRZZ5OF.mjs} +1 -1
- package/dist/{chunk-IZPRCKHE.mjs.map → chunk-OFRZZ5OF.mjs.map} +1 -1
- package/dist/hooks/index.mjs +1 -1
- package/dist/hooks/use-copilot-chat.mjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/openai-assistants/hooks/index.mjs +1 -1
- package/dist/openai-assistants/hooks/use-copilot-chat-v2.mjs +1 -1
- package/dist/openai-assistants/index.mjs +1 -1
- package/package.json +4 -4
- package/src/hooks/use-copilot-chat.ts +1 -1
- package/src/openai-assistants/hooks/use-copilot-chat-v2.ts +4 -1
- package/dist/chunk-QFC2R4ZS.mjs.map +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
Debugger attached.
|
|
2
1
|
|
|
3
|
-
> @copilotkit/react-core@0.15.0-alpha.
|
|
2
|
+
> @copilotkit/react-core@0.15.0-alpha.4 build /Users/ataibarkai/LocalGit/Recursively.ai/CopilotKit/CopilotKit/packages/react-core
|
|
4
3
|
> tsup --treeshake
|
|
5
4
|
|
|
6
|
-
Debugger attached.
|
|
7
5
|
CLI Building entry: src/index.tsx, src/components/index.ts, src/context/copilot-context.tsx, src/context/index.ts, src/hooks/index.ts, src/hooks/use-copilot-chat.ts, src/hooks/use-flat-category-store.ts, src/hooks/use-make-copilot-actionable.ts, src/hooks/use-make-copilot-document-readable.ts, src/hooks/use-make-copilot-readable.ts, src/hooks/use-tree.ts, src/openai-assistants/index.ts, src/types/annotated-function.ts, src/types/document-pointer.ts, src/types/index.ts, src/utils/utils.test.ts, src/utils/utils.ts, src/components/copilot-provider/copilot-provider-props.tsx, src/components/copilot-provider/copilot-provider.tsx, src/components/copilot-provider/index.ts, src/components/copilot-provider/standard-cpilot-api-config.tsx, src/openai-assistants/hooks/index.ts, src/openai-assistants/hooks/use-assistants.ts, src/openai-assistants/hooks/use-copilot-chat-v2.ts, src/openai-assistants/utils/index.ts, src/openai-assistants/utils/process-message-stream.ts
|
|
8
6
|
CLI Using tsconfig: tsconfig.json
|
|
9
7
|
CLI tsup v6.7.0
|
|
@@ -30,101 +28,101 @@ Generated an empty chunk: "chunk-YPSGKPDA".
|
|
|
30
28
|
Generated an empty chunk: "chunk-QACD2U6P".
|
|
31
29
|
Generated an empty chunk: "chunk-JD7BAH7U".
|
|
32
30
|
Generated an empty chunk: "chunk-SPCZTZCY".
|
|
33
|
-
ESM dist/types/annotated-function.mjs 80.00 B
|
|
34
|
-
ESM dist/types/document-pointer.mjs 78.00 B
|
|
35
|
-
ESM dist/utils/utils.test.mjs 202.00 B
|
|
36
|
-
ESM dist/chunk-EFZPSZWO.mjs 76.00 B
|
|
37
|
-
ESM dist/utils/utils.mjs 67.00 B
|
|
38
|
-
ESM dist/chunk-FRAKUJWH.mjs 76.00 B
|
|
39
|
-
ESM dist/chunk-SPCZTZCY.mjs 76.00 B
|
|
40
|
-
ESM dist/chunk-YPSGKPDA.mjs 76.00 B
|
|
41
31
|
ESM dist/chunk-7GFKOIO7.mjs 76.00 B
|
|
32
|
+
ESM dist/openai-assistants/index.mjs 570.00 B
|
|
33
|
+
ESM dist/types/index.mjs 98.00 B
|
|
34
|
+
ESM dist/components/index.mjs 380.00 B
|
|
35
|
+
ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B
|
|
36
|
+
ESM dist/context/copilot-context.mjs 194.00 B
|
|
42
37
|
ESM dist/chunk-BABVSMJR.mjs 76.00 B
|
|
38
|
+
ESM dist/chunk-YPSGKPDA.mjs 76.00 B
|
|
39
|
+
ESM dist/chunk-JD7BAH7U.mjs 76.00 B
|
|
43
40
|
ESM dist/chunk-6N6X7K7T.mjs 434.00 B
|
|
44
|
-
ESM dist/chunk-QACD2U6P.mjs 76.00 B
|
|
45
41
|
ESM dist/chunk-MRXNTQOX.mjs 1.92 KB
|
|
46
|
-
ESM dist/
|
|
47
|
-
ESM dist/components/copilot-provider/index.mjs 369.00 B
|
|
48
|
-
ESM dist/openai-assistants/utils/process-message-stream.mjs 183.00 B
|
|
49
|
-
ESM dist/components/copilot-provider/copilot-provider.mjs 345.00 B
|
|
50
|
-
ESM dist/components/copilot-provider/standard-cpilot-api-config.mjs 191.00 B
|
|
51
|
-
ESM dist/openai-assistants/hooks/index.mjs 547.00 B
|
|
52
|
-
ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs 548.00 B
|
|
42
|
+
ESM dist/chunk-FRAKUJWH.mjs 76.00 B
|
|
53
43
|
ESM dist/hooks/use-make-copilot-readable.mjs 214.00 B
|
|
54
|
-
ESM dist/hooks/use-make-copilot-document-readable.mjs 231.00 B
|
|
55
44
|
ESM dist/hooks/use-tree.mjs 170.00 B
|
|
56
|
-
ESM dist/types/index.mjs 98.00 B
|
|
57
45
|
ESM dist/index.mjs 984.00 B
|
|
58
|
-
ESM dist/
|
|
59
|
-
ESM dist/
|
|
60
|
-
ESM dist/context/copilot-context.mjs 194.00 B
|
|
46
|
+
ESM dist/chunk-JHJ7LUTD.mjs 4.39 KB
|
|
47
|
+
ESM dist/chunk-MZ5UN3BY.mjs 830.00 B
|
|
61
48
|
ESM dist/context/index.mjs 216.00 B
|
|
62
|
-
ESM dist/components/index.mjs 380.00 B
|
|
63
|
-
ESM dist/chunk-QFC2R4ZS.mjs 4.33 KB
|
|
64
49
|
ESM dist/hooks/index.mjs 612.00 B
|
|
50
|
+
ESM dist/chunk-QACD2U6P.mjs 76.00 B
|
|
51
|
+
ESM dist/chunk-45PUEKTG.mjs 626.00 B
|
|
52
|
+
ESM dist/chunk-OFRZZ5OF.mjs 3.00 KB
|
|
65
53
|
ESM dist/hooks/use-copilot-chat.mjs 411.00 B
|
|
54
|
+
ESM dist/chunk-SPCZTZCY.mjs 76.00 B
|
|
66
55
|
ESM dist/chunk-6LNDDH6K.mjs 677.00 B
|
|
67
|
-
ESM dist/chunk-45PUEKTG.mjs 626.00 B
|
|
68
|
-
ESM dist/chunk-VUY2K2DI.mjs 3.89 KB
|
|
69
56
|
ESM dist/hooks/use-flat-category-store.mjs 200.00 B
|
|
70
|
-
ESM dist/components/copilot-provider/copilot-provider-props.mjs 84.00 B
|
|
71
|
-
ESM dist/chunk-JD7BAH7U.mjs 76.00 B
|
|
72
|
-
ESM dist/chunk-6LKBKYRJ.mjs 5.19 KB
|
|
73
57
|
ESM dist/chunk-YULKJPY3.mjs 1.87 KB
|
|
58
|
+
ESM dist/hooks/use-make-copilot-actionable.mjs 218.00 B
|
|
74
59
|
ESM dist/chunk-E3P5YZO2.mjs 954.00 B
|
|
75
60
|
ESM dist/chunk-3MAIWZNZ.mjs 1.55 KB
|
|
76
|
-
ESM dist/
|
|
77
|
-
ESM dist/chunk-
|
|
78
|
-
ESM dist/
|
|
79
|
-
ESM dist/
|
|
80
|
-
ESM dist/utils/
|
|
81
|
-
ESM dist/
|
|
82
|
-
ESM dist/
|
|
83
|
-
ESM dist/types/
|
|
84
|
-
ESM dist/
|
|
85
|
-
ESM dist/
|
|
86
|
-
ESM dist/
|
|
61
|
+
ESM dist/chunk-VUY2K2DI.mjs 3.89 KB
|
|
62
|
+
ESM dist/chunk-EFZPSZWO.mjs 76.00 B
|
|
63
|
+
ESM dist/components/copilot-provider/copilot-provider-props.mjs 84.00 B
|
|
64
|
+
ESM dist/utils/utils.mjs 67.00 B
|
|
65
|
+
ESM dist/openai-assistants/utils/index.mjs 201.00 B
|
|
66
|
+
ESM dist/openai-assistants/hooks/index.mjs 547.00 B
|
|
67
|
+
ESM dist/types/document-pointer.mjs 78.00 B
|
|
68
|
+
ESM dist/types/annotated-function.mjs 80.00 B
|
|
69
|
+
ESM dist/components/copilot-provider/copilot-provider.mjs 345.00 B
|
|
70
|
+
ESM dist/components/copilot-provider/index.mjs 369.00 B
|
|
71
|
+
ESM dist/openai-assistants/utils/process-message-stream.mjs 183.00 B
|
|
72
|
+
ESM dist/chunk-6LKBKYRJ.mjs 5.19 KB
|
|
73
|
+
ESM dist/components/copilot-provider/standard-cpilot-api-config.mjs 191.00 B
|
|
74
|
+
ESM dist/openai-assistants/hooks/use-assistants.mjs 2.55 KB
|
|
75
|
+
ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs 548.00 B
|
|
87
76
|
ESM dist/chunk-7GFKOIO7.mjs.map 51.00 B
|
|
77
|
+
ESM dist/utils/utils.test.mjs 202.00 B
|
|
78
|
+
ESM dist/openai-assistants/index.mjs.map 51.00 B
|
|
79
|
+
ESM dist/components/index.mjs.map 51.00 B
|
|
80
|
+
ESM dist/hooks/use-make-copilot-document-readable.mjs.map 51.00 B
|
|
81
|
+
ESM dist/types/index.mjs.map 51.00 B
|
|
82
|
+
ESM dist/context/copilot-context.mjs.map 51.00 B
|
|
88
83
|
ESM dist/chunk-BABVSMJR.mjs.map 51.00 B
|
|
84
|
+
ESM dist/chunk-YPSGKPDA.mjs.map 51.00 B
|
|
85
|
+
ESM dist/chunk-JD7BAH7U.mjs.map 51.00 B
|
|
89
86
|
ESM dist/chunk-6N6X7K7T.mjs.map 1.12 KB
|
|
90
|
-
ESM dist/chunk-QACD2U6P.mjs.map 51.00 B
|
|
91
|
-
ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
|
|
92
|
-
ESM dist/openai-assistants/utils/index.mjs.map 51.00 B
|
|
93
|
-
ESM dist/openai-assistants/utils/process-message-stream.mjs.map 51.00 B
|
|
94
|
-
ESM dist/components/copilot-provider/index.mjs.map 51.00 B
|
|
95
|
-
ESM dist/components/copilot-provider/copilot-provider.mjs.map 51.00 B
|
|
96
|
-
ESM dist/components/copilot-provider/standard-cpilot-api-config.mjs.map 51.00 B
|
|
97
|
-
ESM dist/openai-assistants/hooks/index.mjs.map 51.00 B
|
|
98
|
-
ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map 51.00 B
|
|
99
87
|
ESM dist/hooks/use-make-copilot-readable.mjs.map 51.00 B
|
|
100
|
-
ESM dist/
|
|
101
|
-
ESM dist/
|
|
88
|
+
ESM dist/chunk-MRXNTQOX.mjs.map 71.00 B
|
|
89
|
+
ESM dist/context/index.mjs.map 51.00 B
|
|
90
|
+
ESM dist/chunk-FRAKUJWH.mjs.map 51.00 B
|
|
102
91
|
ESM dist/hooks/use-tree.mjs.map 51.00 B
|
|
103
|
-
ESM dist/
|
|
104
|
-
ESM dist/openai-assistants/index.mjs.map 51.00 B
|
|
105
|
-
ESM dist/openai-assistants/hooks/use-assistants.mjs.map 4.67 KB
|
|
106
|
-
ESM dist/context/copilot-context.mjs.map 51.00 B
|
|
107
|
-
ESM dist/chunk-QFC2R4ZS.mjs.map 7.87 KB
|
|
108
|
-
ESM dist/components/index.mjs.map 51.00 B
|
|
92
|
+
ESM dist/chunk-45PUEKTG.mjs.map 1.47 KB
|
|
109
93
|
ESM dist/hooks/index.mjs.map 51.00 B
|
|
94
|
+
ESM dist/chunk-QACD2U6P.mjs.map 51.00 B
|
|
95
|
+
ESM dist/index.mjs.map 51.00 B
|
|
96
|
+
ESM dist/chunk-JHJ7LUTD.mjs.map 7.97 KB
|
|
110
97
|
ESM dist/chunk-6LNDDH6K.mjs.map 1.42 KB
|
|
111
|
-
ESM dist/chunk-VUY2K2DI.mjs.map 8.27 KB
|
|
112
|
-
ESM dist/chunk-45PUEKTG.mjs.map 1.47 KB
|
|
113
98
|
ESM dist/hooks/use-flat-category-store.mjs.map 51.00 B
|
|
114
|
-
ESM dist/chunk-
|
|
115
|
-
ESM dist/components/copilot-provider/copilot-provider-props.mjs.map 51.00 B
|
|
99
|
+
ESM dist/chunk-MZ5UN3BY.mjs.map 1.26 KB
|
|
116
100
|
ESM dist/chunk-E3P5YZO2.mjs.map 1.67 KB
|
|
101
|
+
ESM dist/chunk-OFRZZ5OF.mjs.map 4.98 KB
|
|
102
|
+
ESM dist/hooks/use-copilot-chat.mjs.map 51.00 B
|
|
117
103
|
ESM dist/chunk-YULKJPY3.mjs.map 4.21 KB
|
|
118
|
-
ESM dist/chunk-3MAIWZNZ.mjs.map 4.68 KB
|
|
119
|
-
ESM dist/chunk-MZ5UN3BY.mjs.map 1.26 KB
|
|
120
104
|
ESM dist/hooks/use-make-copilot-actionable.mjs.map 51.00 B
|
|
121
|
-
ESM dist/chunk-
|
|
122
|
-
ESM dist/
|
|
123
|
-
ESM dist/chunk-
|
|
124
|
-
ESM dist/
|
|
125
|
-
ESM
|
|
105
|
+
ESM dist/chunk-VUY2K2DI.mjs.map 8.27 KB
|
|
106
|
+
ESM dist/chunk-EFZPSZWO.mjs.map 51.00 B
|
|
107
|
+
ESM dist/chunk-3MAIWZNZ.mjs.map 4.68 KB
|
|
108
|
+
ESM dist/chunk-SPCZTZCY.mjs.map 51.00 B
|
|
109
|
+
ESM dist/components/copilot-provider/copilot-provider-props.mjs.map 51.00 B
|
|
110
|
+
ESM dist/utils/utils.mjs.map 51.00 B
|
|
111
|
+
ESM dist/openai-assistants/utils/index.mjs.map 51.00 B
|
|
112
|
+
ESM dist/openai-assistants/hooks/index.mjs.map 51.00 B
|
|
113
|
+
ESM dist/types/document-pointer.mjs.map 51.00 B
|
|
114
|
+
ESM dist/types/annotated-function.mjs.map 51.00 B
|
|
115
|
+
ESM dist/components/copilot-provider/index.mjs.map 51.00 B
|
|
116
|
+
ESM dist/openai-assistants/utils/process-message-stream.mjs.map 51.00 B
|
|
117
|
+
ESM dist/components/copilot-provider/copilot-provider.mjs.map 51.00 B
|
|
118
|
+
ESM dist/chunk-6LKBKYRJ.mjs.map 10.71 KB
|
|
119
|
+
ESM dist/openai-assistants/hooks/use-assistants.mjs.map 4.67 KB
|
|
120
|
+
ESM dist/components/copilot-provider/standard-cpilot-api-config.mjs.map 51.00 B
|
|
121
|
+
ESM dist/openai-assistants/hooks/use-copilot-chat-v2.mjs.map 51.00 B
|
|
122
|
+
ESM dist/utils/utils.test.mjs.map 351.00 B
|
|
123
|
+
ESM ⚡️ Build success in 118ms
|
|
126
124
|
DTS Build start
|
|
127
|
-
DTS ⚡️ Build success in
|
|
125
|
+
DTS ⚡️ Build success in 1894ms
|
|
128
126
|
DTS dist/index.d.ts 1.29 KB
|
|
129
127
|
DTS dist/components/copilot-provider/copilot-provider.d.ts 1.17 KB
|
|
130
128
|
DTS dist/components/copilot-provider/copilot-provider-props.d.ts 1.50 KB
|
|
@@ -151,5 +149,3 @@ DTS dist/components/copilot-provider/standard-cpilot-api-config.d.ts 894.00 B
|
|
|
151
149
|
DTS dist/openai-assistants/hooks/index.d.ts 182.00 B
|
|
152
150
|
DTS dist/openai-assistants/hooks/use-assistants.d.ts 551.00 B
|
|
153
151
|
DTS dist/openai-assistants/utils/index.d.ts 68.00 B
|
|
154
|
-
Waiting for the debugger to disconnect...
|
|
155
|
-
Waiting for the debugger to disconnect...
|
package/CHANGELOG.md
CHANGED
|
@@ -39,17 +39,17 @@ function useCopilotChatV2(options) {
|
|
|
39
39
|
setMessages((messages2) => [...messages2, { id: "", role: "user", content: input }]);
|
|
40
40
|
setInput("");
|
|
41
41
|
const apiUrl = copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpointV2;
|
|
42
|
+
const functions = getChatCompletionFunctionDescriptions();
|
|
42
43
|
const result = yield fetch(apiUrl, {
|
|
43
44
|
method: "POST",
|
|
44
45
|
headers: __spreadValues(__spreadValues({
|
|
45
46
|
"Content-Type": "application/json"
|
|
46
47
|
}, copilotApiConfig.headers), options.headers),
|
|
47
|
-
body: JSON.stringify(__spreadValues(__spreadValues({
|
|
48
|
+
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues({
|
|
48
49
|
// always use user-provided threadId when available:
|
|
49
50
|
threadId: (_b = (_a = options.threadId) != null ? _a : threadId) != null ? _b : null,
|
|
50
|
-
message: input
|
|
51
|
-
|
|
52
|
-
}, copilotApiConfig.body), options.body))
|
|
51
|
+
message: input
|
|
52
|
+
}, functions.length > 0 && { functions }), copilotApiConfig.body), options.body))
|
|
53
53
|
});
|
|
54
54
|
if (result.body == null) {
|
|
55
55
|
throw new Error("The response body is empty.");
|
|
@@ -122,4 +122,4 @@ If you would like to call a function, call it without saying anything else.
|
|
|
122
122
|
|
|
123
123
|
export { defaultSystemMessage, useCopilotChatV2 };
|
|
124
124
|
//# sourceMappingURL=out.js.map
|
|
125
|
-
//# sourceMappingURL=chunk-
|
|
125
|
+
//# sourceMappingURL=chunk-JHJ7LUTD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/openai-assistants/hooks/use-copilot-chat-v2.ts"],"names":["messages","error"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,SAAS,gBAAgB;AAE9C,SAAkB,uBAAuB;AA6ClC,SAAS,iBAAiB,SAA0D;AACzF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAE7B,QAAM,CAAC,UAAU,WAAW,IAAI,SAAoB,CAAC,CAAC;AACtD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,EAAE;AACrC,QAAM,CAAC,UAAU,WAAW,IAAI,SAA6B,MAAS;AACtE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA0B,kBAAkB;AACxE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA8B,MAAS;AAEjE,QAAM,gBAAyB,QAAQ,MAAM;AAC3C,UAAM,qBAAqB,QAAQ,qBAAqB;AACxD,UAAM,gBAAgB,iBAAiB,CAAC,GAAG,+BAA+B;AAE1E,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,mBAAmB,aAAa;AAAA,MACzC,MAAM;AAAA,IACR;AAAA,EACF,GAAG,CAAC,kBAAkB,QAAQ,iBAAiB,CAAC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Aa;AACxB,oBAAM,cAAcA,UAASA,UAAS,SAAS,CAAC;AAChD,0BAAY,KAAK,MAAM;AACvB,qBAAO,CAAC,GAAGA,UAAS,MAAM,GAAGA,UAAS,SAAS,CAAC,GAAG,WAAW;AAAA,YAChE,CAAC;AAED;AAAA,UACF;AAAA,UAEA,KAAK,SAAS;AACZ,qBAAS,KAAK;AACd;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAASC,QAAP;AACA,iBAASA,MAAK;AAAA,MAChB;AAAA,IACF,CAAC;AAED,cAAU,kBAAkB;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,eAA+B;AAClE,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWF","sourcesContent":["import { useContext, useMemo, useState } from \"react\";\nimport { processMessageStream } from \"../utils\";\nimport { Message, parseStreamPart } from \"@copilotkit/shared\";\nimport { CopilotContext, copilotApiConfigExtrapolator } from \"../../context\";\nimport { defaultCopilotContextCategories } from \"../../components\";\n\nexport type AssistantStatus = \"in_progress\" | \"awaiting_message\";\n\nexport interface RequestForwardingOptions {\n /**\n * The credentials mode to be used for the fetch request.\n * Possible values are: 'omit', 'same-origin', 'include'.\n * Defaults to 'same-origin'.\n */\n credentials?: RequestCredentials;\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n /**\n * Extra body object to be sent with the API request.\n * @example\n * Send a `sessionId` to the API along with the messages.\n * ```js\n * useChat({\n * body: {\n * sessionId: '123',\n * }\n * })\n * ```\n */\n body?: object;\n}\nexport interface UseCopilotChatOptionsV2 extends RequestForwardingOptions {\n makeSystemMessage?: (contextString: string) => string;\n threadId?: string | undefined;\n}\n\nexport interface UseCopilotChatV2Result {\n messages: Message[];\n input: string;\n handleInputChange: (e: any) => void;\n submitMessage: (e: any) => Promise<void>;\n status: AssistantStatus;\n error: unknown;\n}\n\nexport function useCopilotChatV2(options: UseCopilotChatOptionsV2): UseCopilotChatV2Result {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const [messages, setMessages] = useState<Message[]>([]);\n const [input, setInput] = useState(\"\");\n const [threadId, setThreadId] = useState<string | undefined>(undefined);\n const [status, setStatus] = useState<AssistantStatus>(\"awaiting_message\");\n const [error, setError] = useState<unknown | undefined>(undefined);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage;\n const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, options.makeSystemMessage]);\n\n const handleInputChange = (e: any) => {\n setInput(e.target.value);\n };\n\n const submitMessage = async (e: any) => {\n e.preventDefault();\n\n if (input === \"\") {\n return;\n }\n\n setStatus(\"in_progress\");\n\n setMessages((messages) => [...messages, { id: \"\", role: \"user\", content: input }]);\n\n setInput(\"\");\n\n const apiUrl = copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpointV2;\n\n const functions = getChatCompletionFunctionDescriptions();\n\n const result = await fetch(apiUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotApiConfig.headers,\n ...options.headers,\n },\n body: JSON.stringify({\n // always use user-provided threadId when available:\n threadId: options.threadId ?? threadId ?? null,\n message: input,\n ...(functions.length > 0 && { functions: functions }),\n ...copilotApiConfig.body,\n ...options.body,\n }),\n });\n\n if (result.body == null) {\n throw new Error(\"The response body is empty.\");\n }\n\n await processMessageStream(result.body.getReader(), (message: string) => {\n try {\n const { type, value } = parseStreamPart(message);\n\n switch (type) {\n case \"assistant_message\": {\n // append message:\n setMessages((messages) => [\n ...messages,\n {\n id: value.id,\n role: value.role,\n content: value.content[0].text.value,\n },\n ]);\n break;\n }\n\n case \"assistant_control_data\": {\n setThreadId(value.threadId);\n\n // set id of last message:\n setMessages((messages) => {\n const lastMessage = messages[messages.length - 1];\n lastMessage.id = value.messageId;\n return [...messages.slice(0, messages.length - 1), lastMessage];\n });\n\n break;\n }\n\n case \"error\": {\n setError(value);\n break;\n }\n }\n } catch (error) {\n setError(error);\n }\n });\n\n setStatus(\"awaiting_message\");\n };\n\n return {\n messages,\n input,\n handleInputChange,\n submitMessage,\n status,\n error,\n };\n}\n\nexport function defaultSystemMessage(contextString: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\n`;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-copilot-chat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,SAAS,kBAAkB;AAMpC,SAAS,eAAe;AAuBjB,SAAS,eAAe,IAGiB;AAHjB,eAC7B;AAAA;AAAA,EA9BF,IA6B+B,IAE1B,oBAF0B,IAE1B;AAAA,IADH;AAAA;AAGA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAE7B,QAAM,gBAAyB,QAAQ,MAAM;AAC3C,UAAM,qBAAqB,qBAAqB;AAChD,UAAM,gBAAgB,iBAAiB,CAAC,GAAG,+BAA+B;AAE1E,WAAO;AAAA,MACL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AEvF,QAAM,uBAA8D,QAAQ,MAAM;AAChF,WAAO,sCAAsC;AAAA,EAC/C,GAAG,CAAC,qCAAqC,CAAC;AAE1C,QAAM,EAAE,UAAU,QAAQ,QAAQ,MAAM,WAAW,OAAO,SAAS,IAAI,QAAQ,iCAC1E,UAD0E;AAAA,IAE7E,KAAK,6BAA6B,gBAAgB,EAAE;AAAA,IACpD,IAAI,QAAQ;AAAA,IACZ,iBAAiB;AAAA,IACjB,6BAA6B,uBAAuB;AAAA,IACpD,SAAS,kCAAK,iBAAiB,UAAY,QAAQ;AAAA,IACnD,MAAM;AAAA,MACJ,IAAI,QAAQ;AAAA,OACR,qBAAqB,SAAS,KAAK,EAAE,WAAW,qBAAqB,IACtE,iBAAiB,OACjB,QAAQ;AAAA,EAEf,EAAC;AAED,QAAM,kBAAkB,SAAS;AAAA,IAC/B,CAAC,YAAY,QAAQ,SAAS,UAAU,QAAQ,SAAS;AAAA,EAC3D;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,eAA+B;AAClE,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWF","sourcesContent":["import { useMemo, useContext } from \"react\";\nimport {\n CopilotContext,\n CopilotContextParams,\n copilotApiConfigExtrapolator,\n} from \"../context/copilot-context\";\nimport { useChat } from \"ai/react\";\nimport { ChatRequestOptions, CreateMessage, Message } from \"ai\";\nimport { UseChatOptions } from \"ai\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { ChatCompletionCreateParams } from \"openai/resources/chat\";\n\nexport interface UseCopilotChatOptions extends UseChatOptions {\n makeSystemMessage?: (contextString: string) => string;\n}\n\nexport interface UseCopilotChatReturn {\n visibleMessages: Message[];\n append: (\n message: Message | CreateMessage,\n chatRequestOptions?: ChatRequestOptions,\n ) => Promise<string | null | undefined>;\n reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;\n stop: () => void;\n isLoading: boolean;\n input: string;\n setInput: React.Dispatch<React.SetStateAction<string>>;\n}\n\nexport function useCopilotChat({\n makeSystemMessage,\n ...options\n}: UseCopilotChatOptions): UseCopilotChatReturn {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = makeSystemMessage || defaultSystemMessage;\n const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, makeSystemMessage]);\n\n const initialMessagesWithContext = [systemMessage].concat(options.initialMessages || []);\n\n const functionDescriptions: ChatCompletionCreateParams.Function[] = useMemo(() => {\n return getChatCompletionFunctionDescriptions();\n }, [getChatCompletionFunctionDescriptions]);\n\n const { messages, append, reload, stop, isLoading, input, setInput } = useChat({\n ...options,\n api: copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpoint,\n id: options.id,\n initialMessages: initialMessagesWithContext,\n experimental_onFunctionCall: getFunctionCallHandler(),\n headers: { ...copilotApiConfig.headers, ...options.headers },\n body: {\n id: options.id,\n ...(functionDescriptions.length > 0 && { functions: functionDescriptions }),\n ...copilotApiConfig.body,\n ...options.body,\n },\n });\n\n const visibleMessages = messages.filter(\n (message) => message.role === \"user\" || message.role === \"assistant\",\n );\n\n return {\n visibleMessages,\n append,\n reload,\n stop,\n isLoading,\n input,\n setInput,\n };\n}\n\nexport function defaultSystemMessage(contextString: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\n`;\n}\n"]}
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../chunk-QACD2U6P.mjs';
|
|
2
2
|
export { useMakeCopilotDocumentReadable } from '../chunk-6LNDDH6K.mjs';
|
|
3
3
|
export { useMakeCopilotReadable } from '../chunk-45PUEKTG.mjs';
|
|
4
|
-
export { useCopilotChat } from '../chunk-
|
|
4
|
+
export { useCopilotChat } from '../chunk-OFRZZ5OF.mjs';
|
|
5
5
|
import '../chunk-JD7BAH7U.mjs';
|
|
6
6
|
import '../chunk-SPCZTZCY.mjs';
|
|
7
7
|
import '../chunk-6LKBKYRJ.mjs';
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './chunk-7GFKOIO7.mjs';
|
|
2
2
|
import './chunk-BABVSMJR.mjs';
|
|
3
|
-
export { useCopilotChatV2 } from './chunk-
|
|
3
|
+
export { useCopilotChatV2 } from './chunk-JHJ7LUTD.mjs';
|
|
4
4
|
import './chunk-FRAKUJWH.mjs';
|
|
5
5
|
export { processMessageStream } from './chunk-MZ5UN3BY.mjs';
|
|
6
6
|
import './chunk-EFZPSZWO.mjs';
|
|
@@ -8,7 +8,7 @@ import './chunk-YPSGKPDA.mjs';
|
|
|
8
8
|
import './chunk-QACD2U6P.mjs';
|
|
9
9
|
export { useMakeCopilotDocumentReadable } from './chunk-6LNDDH6K.mjs';
|
|
10
10
|
export { useMakeCopilotReadable } from './chunk-45PUEKTG.mjs';
|
|
11
|
-
export { useCopilotChat } from './chunk-
|
|
11
|
+
export { useCopilotChat } from './chunk-OFRZZ5OF.mjs';
|
|
12
12
|
import './chunk-JD7BAH7U.mjs';
|
|
13
13
|
import './chunk-SPCZTZCY.mjs';
|
|
14
14
|
export { CopilotProvider, defaultCopilotContextCategories } from './chunk-6LKBKYRJ.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../../chunk-BABVSMJR.mjs';
|
|
2
|
-
export { useCopilotChatV2 } from '../../chunk-
|
|
2
|
+
export { useCopilotChatV2 } from '../../chunk-JHJ7LUTD.mjs';
|
|
3
3
|
import '../../chunk-FRAKUJWH.mjs';
|
|
4
4
|
import '../../chunk-MZ5UN3BY.mjs';
|
|
5
5
|
import '../../chunk-YPSGKPDA.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { defaultSystemMessage, useCopilotChatV2 } from '../../chunk-
|
|
1
|
+
export { defaultSystemMessage, useCopilotChatV2 } from '../../chunk-JHJ7LUTD.mjs';
|
|
2
2
|
import '../../chunk-FRAKUJWH.mjs';
|
|
3
3
|
import '../../chunk-MZ5UN3BY.mjs';
|
|
4
4
|
import '../../chunk-YPSGKPDA.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '../chunk-7GFKOIO7.mjs';
|
|
2
2
|
import '../chunk-BABVSMJR.mjs';
|
|
3
|
-
export { useCopilotChatV2 } from '../chunk-
|
|
3
|
+
export { useCopilotChatV2 } from '../chunk-JHJ7LUTD.mjs';
|
|
4
4
|
import '../chunk-FRAKUJWH.mjs';
|
|
5
5
|
export { processMessageStream } from '../chunk-MZ5UN3BY.mjs';
|
|
6
6
|
import '../chunk-YPSGKPDA.mjs';
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.15.0-alpha.
|
|
7
|
+
"version": "0.15.0-alpha.5",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"module": "./dist/index.mjs",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"ts-jest": "^29.1.1",
|
|
24
24
|
"tsup": "^6.7.0",
|
|
25
25
|
"typescript": "^5.1.3",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"eslint-config-custom": "0.2.0",
|
|
27
|
+
"tsconfig": "0.6.0-alpha.5"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"ai": "^2.2.23",
|
|
31
31
|
"nanoid": "^4.0.2",
|
|
32
32
|
"openai": "^4.6.0",
|
|
33
|
-
"@copilotkit/shared": "0.1.0-alpha.
|
|
33
|
+
"@copilotkit/shared": "0.1.0-alpha.5"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsup --treeshake",
|
|
@@ -64,7 +64,7 @@ export function useCopilotChat({
|
|
|
64
64
|
headers: { ...copilotApiConfig.headers, ...options.headers },
|
|
65
65
|
body: {
|
|
66
66
|
id: options.id,
|
|
67
|
-
...(
|
|
67
|
+
...(functionDescriptions.length > 0 && { functions: functionDescriptions }),
|
|
68
68
|
...copilotApiConfig.body,
|
|
69
69
|
...options.body,
|
|
70
70
|
},
|
|
@@ -88,6 +88,9 @@ export function useCopilotChatV2(options: UseCopilotChatOptionsV2): UseCopilotCh
|
|
|
88
88
|
setInput("");
|
|
89
89
|
|
|
90
90
|
const apiUrl = copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpointV2;
|
|
91
|
+
|
|
92
|
+
const functions = getChatCompletionFunctionDescriptions();
|
|
93
|
+
|
|
91
94
|
const result = await fetch(apiUrl, {
|
|
92
95
|
method: "POST",
|
|
93
96
|
headers: {
|
|
@@ -99,7 +102,7 @@ export function useCopilotChatV2(options: UseCopilotChatOptionsV2): UseCopilotCh
|
|
|
99
102
|
// always use user-provided threadId when available:
|
|
100
103
|
threadId: options.threadId ?? threadId ?? null,
|
|
101
104
|
message: input,
|
|
102
|
-
functions:
|
|
105
|
+
...(functions.length > 0 && { functions: functions }),
|
|
103
106
|
...copilotApiConfig.body,
|
|
104
107
|
...options.body,
|
|
105
108
|
}),
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/openai-assistants/hooks/use-copilot-chat-v2.ts"],"names":["messages","error"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,SAAS,gBAAgB;AAE9C,SAAkB,uBAAuB;AA6ClC,SAAS,iBAAiB,SAA0D;AACzF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAE7B,QAAM,CAAC,UAAU,WAAW,IAAI,SAAoB,CAAC,CAAC;AACtD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,EAAE;AACrC,QAAM,CAAC,UAAU,WAAW,IAAI,SAA6B,MAAS;AACtE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA0B,kBAAkB;AACxE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA8B,MAAS;AAEjE,QAAM,gBAAyB,QAAQ,MAAM;AAC3C,UAAM,qBAAqB,QAAQ,qBAAqB;AACxD,UAAM,gBAAgB,iBAAiB,CAAC,GAAG,+BAA+B;AAE1E,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,mBAAmB,aAAa;AAAA,MACzC,MAAM;AAAA,IACR;AAAA,EACF,GAAG,CAAC,kBAAkB,QAAQ,iBAAiB,CAAC;AAEhD,QAAM,oBAAoB,CAAC,MAAW;AACpC,aAAS,EAAE,OAAO,KAAK;AAAA,EACzB;AAEA,QAAM,gBAAgB,CAAO,MAAW;AA5E1C;AA6EI,MAAE,eAAe;AAEjB,QAAI,UAAU,IAAI;AAChB;AAAA,IACF;AAEA,cAAU,aAAa;AAEvB,gBAAY,CAACA,cAAa,CAAC,GAAGA,WAAU,EAAE,IAAI,IAAI,MAAM,QAAQ,SAAS,MAAM,CAAC,CAAC;AAEjF,aAAS,EAAE;AAEX,UAAM,SAAS,6BAA6B,gBAAgB,EAAE;AAC9D,UA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,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,eAA+B;AAClE,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWF","sourcesContent":["import { useContext, useMemo, useState } from \"react\";\nimport { processMessageStream } from \"../utils\";\nimport { Message, parseStreamPart } from \"@copilotkit/shared\";\nimport { CopilotContext, copilotApiConfigExtrapolator } from \"../../context\";\nimport { defaultCopilotContextCategories } from \"../../components\";\n\nexport type AssistantStatus = \"in_progress\" | \"awaiting_message\";\n\nexport interface RequestForwardingOptions {\n /**\n * The credentials mode to be used for the fetch request.\n * Possible values are: 'omit', 'same-origin', 'include'.\n * Defaults to 'same-origin'.\n */\n credentials?: RequestCredentials;\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n /**\n * Extra body object to be sent with the API request.\n * @example\n * Send a `sessionId` to the API along with the messages.\n * ```js\n * useChat({\n * body: {\n * sessionId: '123',\n * }\n * })\n * ```\n */\n body?: object;\n}\nexport interface UseCopilotChatOptionsV2 extends RequestForwardingOptions {\n makeSystemMessage?: (contextString: string) => string;\n threadId?: string | undefined;\n}\n\nexport interface UseCopilotChatV2Result {\n messages: Message[];\n input: string;\n handleInputChange: (e: any) => void;\n submitMessage: (e: any) => Promise<void>;\n status: AssistantStatus;\n error: unknown;\n}\n\nexport function useCopilotChatV2(options: UseCopilotChatOptionsV2): UseCopilotChatV2Result {\n const {\n getContextString,\n getChatCompletionFunctionDescriptions,\n getFunctionCallHandler,\n copilotApiConfig,\n } = useContext(CopilotContext);\n\n const [messages, setMessages] = useState<Message[]>([]);\n const [input, setInput] = useState(\"\");\n const [threadId, setThreadId] = useState<string | undefined>(undefined);\n const [status, setStatus] = useState<AssistantStatus>(\"awaiting_message\");\n const [error, setError] = useState<unknown | undefined>(undefined);\n\n const systemMessage: Message = useMemo(() => {\n const systemMessageMaker = options.makeSystemMessage || defaultSystemMessage;\n const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return {\n id: \"system\",\n content: systemMessageMaker(contextString),\n role: \"system\",\n };\n }, [getContextString, options.makeSystemMessage]);\n\n const handleInputChange = (e: any) => {\n setInput(e.target.value);\n };\n\n const submitMessage = async (e: any) => {\n e.preventDefault();\n\n if (input === \"\") {\n return;\n }\n\n setStatus(\"in_progress\");\n\n setMessages((messages) => [...messages, { id: \"\", role: \"user\", content: input }]);\n\n setInput(\"\");\n\n const apiUrl = copilotApiConfigExtrapolator(copilotApiConfig).chatApiEndpointV2;\n const result = await fetch(apiUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...copilotApiConfig.headers,\n ...options.headers,\n },\n body: JSON.stringify({\n // always use user-provided threadId when available:\n threadId: options.threadId ?? threadId ?? null,\n message: input,\n functions: getChatCompletionFunctionDescriptions(),\n ...copilotApiConfig.body,\n ...options.body,\n }),\n });\n\n if (result.body == null) {\n throw new Error(\"The response body is empty.\");\n }\n\n await processMessageStream(result.body.getReader(), (message: string) => {\n try {\n const { type, value } = parseStreamPart(message);\n\n switch (type) {\n case \"assistant_message\": {\n // append message:\n setMessages((messages) => [\n ...messages,\n {\n id: value.id,\n role: value.role,\n content: value.content[0].text.value,\n },\n ]);\n break;\n }\n\n case \"assistant_control_data\": {\n setThreadId(value.threadId);\n\n // set id of last message:\n setMessages((messages) => {\n const lastMessage = messages[messages.length - 1];\n lastMessage.id = value.messageId;\n return [...messages.slice(0, messages.length - 1), lastMessage];\n });\n\n break;\n }\n\n case \"error\": {\n setError(value);\n break;\n }\n }\n } catch (error) {\n setError(error);\n }\n });\n\n setStatus(\"awaiting_message\");\n };\n\n return {\n messages,\n input,\n handleInputChange,\n submitMessage,\n status,\n error,\n };\n}\n\nexport function defaultSystemMessage(contextString: string): string {\n return `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\n`;\n}\n"]}
|