@copilotkit/shared 0.9.0-mme-cloud.4 → 0.9.0-multi-feature-usecopilotreadable.3
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 +107 -114
- package/CHANGELOG.md +8 -14
- package/dist/{chunk-DBW3BY7E.mjs → chunk-2C54HQBI.mjs} +1 -1
- package/dist/{chunk-DBW3BY7E.mjs.map → chunk-2C54HQBI.mjs.map} +1 -1
- package/dist/chunk-2M3YVRFS.mjs +1 -0
- package/dist/{chunk-NKEDWRKJ.mjs → chunk-CBF2BIA7.mjs} +20 -12
- package/dist/chunk-CBF2BIA7.mjs.map +1 -0
- package/dist/chunk-DE5K76I2.mjs +1 -0
- package/dist/{chunk-TYZD5BQY.mjs → chunk-HW4V75UQ.mjs} +1 -1
- package/dist/chunk-HW4V75UQ.mjs.map +1 -0
- package/dist/{chunk-S4HGLK2E.mjs → chunk-K7TZQSAZ.mjs} +5 -8
- package/dist/chunk-K7TZQSAZ.mjs.map +1 -0
- package/dist/constants/index.d.ts +0 -6
- package/dist/constants/index.js +0 -11
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/index.mjs +1 -8
- package/dist/index.d.ts +2 -4
- package/dist/index.js +23 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -29
- package/dist/types/action.d.ts +33 -32
- package/dist/types/action.js.map +1 -1
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +1 -2
- package/dist/utils/annotated-function.js +4 -7
- package/dist/utils/annotated-function.js.map +1 -1
- package/dist/utils/annotated-function.mjs +1 -1
- package/dist/utils/decode-chat-completion.js +19 -11
- package/dist/utils/decode-chat-completion.js.map +1 -1
- package/dist/utils/decode-chat-completion.mjs +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +23 -18
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +14 -14
- package/dist/utils/parse-chat-completion.d.ts +12 -10
- package/dist/utils/parse-chat-completion.js.map +1 -1
- package/dist/utils/parse-chat-completion.mjs +1 -1
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +1 -1
- package/package.json +3 -3
- package/src/constants/index.ts +0 -3
- package/src/types/action.ts +51 -37
- package/src/types/index.ts +0 -1
- package/src/utils/annotated-function.ts +4 -7
- package/src/utils/decode-chat-completion.ts +29 -16
- package/src/utils/parse-chat-completion.ts +19 -15
- package/src/utils/utils.ts +1 -1
- package/dist/chunk-BANDZXMP.mjs +0 -1
- package/dist/chunk-FFQUB5LF.mjs +0 -11
- package/dist/chunk-FFQUB5LF.mjs.map +0 -1
- package/dist/chunk-MSUB6DGR.mjs +0 -1
- package/dist/chunk-NKEDWRKJ.mjs.map +0 -1
- package/dist/chunk-S4HGLK2E.mjs.map +0 -1
- package/dist/chunk-TYZD5BQY.mjs.map +0 -1
- package/dist/types/copilot-cloud-config.d.ts +0 -13
- package/dist/types/copilot-cloud-config.js +0 -19
- package/dist/types/copilot-cloud-config.js.map +0 -1
- package/dist/types/copilot-cloud-config.mjs +0 -2
- package/dist/types/copilot-cloud-config.mjs.map +0 -1
- package/src/types/copilot-cloud-config.ts +0 -11
- /package/dist/{chunk-BANDZXMP.mjs.map → chunk-2M3YVRFS.mjs.map} +0 -0
- /package/dist/{chunk-MSUB6DGR.mjs.map → chunk-DE5K76I2.mjs.map} +0 -0
package/src/types/action.ts
CHANGED
|
@@ -9,60 +9,74 @@ type TypeMap = {
|
|
|
9
9
|
"object[]": object[];
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
type AbstractParameter = {
|
|
13
13
|
name: string;
|
|
14
|
-
type?:
|
|
14
|
+
type?: keyof TypeMap;
|
|
15
15
|
description?: string;
|
|
16
16
|
required?: boolean;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
name: string;
|
|
19
|
+
interface StringParameter extends AbstractParameter {
|
|
21
20
|
type: "string";
|
|
22
|
-
description?: string;
|
|
23
|
-
required?: boolean;
|
|
24
21
|
enum?: string[];
|
|
25
|
-
}
|
|
22
|
+
}
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type: "object" | "object[]";
|
|
30
|
-
description?: string;
|
|
31
|
-
required?: boolean;
|
|
24
|
+
interface ObjectParameter extends AbstractParameter {
|
|
25
|
+
type: "object";
|
|
32
26
|
attributes?: Parameter[];
|
|
33
|
-
}
|
|
27
|
+
}
|
|
34
28
|
|
|
35
|
-
|
|
29
|
+
interface ObjectArrayParameter extends AbstractParameter {
|
|
30
|
+
type: "object[]";
|
|
31
|
+
attributes?: Parameter[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type SpecialParameters = StringParameter | ObjectParameter | ObjectArrayParameter;
|
|
35
|
+
interface BaseParameter extends AbstractParameter {
|
|
36
|
+
type?: Exclude<AbstractParameter["type"], SpecialParameters["type"]>;
|
|
37
|
+
}
|
|
36
38
|
|
|
37
|
-
type
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
export type Parameter = BaseParameter | SpecialParameters;
|
|
40
|
+
|
|
41
|
+
type OptionalParameterType<P extends AbstractParameter> = P["required"] extends false
|
|
42
|
+
? undefined
|
|
41
43
|
: never;
|
|
42
44
|
|
|
43
|
-
type
|
|
44
|
-
?
|
|
45
|
+
type StringParameterType<P> = P extends StringParameter
|
|
46
|
+
? P extends { enum?: Array<infer E> }
|
|
47
|
+
? E
|
|
48
|
+
: string
|
|
45
49
|
: never;
|
|
46
50
|
|
|
47
|
-
type
|
|
48
|
-
?
|
|
49
|
-
|
|
51
|
+
type ObjectParameterType<P> = P extends ObjectParameter
|
|
52
|
+
? P extends { attributes?: infer Attributes extends Parameter[] }
|
|
53
|
+
? MappedParameterTypes<Attributes>
|
|
54
|
+
: object
|
|
55
|
+
: never;
|
|
50
56
|
|
|
51
|
-
type
|
|
52
|
-
?
|
|
53
|
-
|
|
57
|
+
type ObjectArrayParameterType<P> = P extends ObjectArrayParameter
|
|
58
|
+
? P extends { attributes?: infer Attributes extends Parameter[] }
|
|
59
|
+
? MappedParameterTypes<Attributes>[]
|
|
60
|
+
: any[]
|
|
61
|
+
: never;
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
type MappedTypeOrString<T> = T extends keyof TypeMap ? TypeMap[T] : string;
|
|
64
|
+
type BaseParameterType<P extends AbstractParameter> = P extends { type: infer T }
|
|
65
|
+
? T extends BaseParameter["type"]
|
|
66
|
+
? MappedTypeOrString<T>
|
|
67
|
+
: never
|
|
68
|
+
: string;
|
|
69
|
+
|
|
70
|
+
export type MappedParameterTypes<T extends Parameter[] | [] = []> = T extends []
|
|
71
|
+
? Record<string, any>
|
|
72
|
+
: {
|
|
73
|
+
[P in T[number] as P["name"]]:
|
|
74
|
+
| OptionalParameterType<P>
|
|
75
|
+
| StringParameterType<P>
|
|
76
|
+
| ObjectParameterType<P>
|
|
77
|
+
| ObjectArrayParameterType<P>
|
|
78
|
+
| BaseParameterType<P>;
|
|
79
|
+
};
|
|
66
80
|
|
|
67
81
|
export type Action<T extends Parameter[] | [] = []> = {
|
|
68
82
|
name: string;
|
package/src/types/index.ts
CHANGED
|
@@ -51,13 +51,10 @@ function convertAttribute(attribute: Parameter): any {
|
|
|
51
51
|
};
|
|
52
52
|
case "object":
|
|
53
53
|
case "object[]":
|
|
54
|
-
const properties = attribute.attributes?.reduce(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
{} as Record<string, any>,
|
|
60
|
-
);
|
|
54
|
+
const properties = attribute.attributes?.reduce((acc, attr) => {
|
|
55
|
+
acc[attr.name] = convertAttribute(attr);
|
|
56
|
+
return acc;
|
|
57
|
+
}, {} as Record<string, any>);
|
|
61
58
|
const required = attribute.attributes
|
|
62
59
|
?.filter((attr) => attr.required !== false)
|
|
63
60
|
.map((attr) => attr.name);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChatCompletionChunk } from "./parse-chat-completion";
|
|
1
|
+
import { ChatCompletionChunk, ToolCallFunctionCall } from "./parse-chat-completion";
|
|
2
2
|
|
|
3
3
|
export interface ChatCompletionContentEvent {
|
|
4
4
|
type: "content";
|
|
@@ -35,7 +35,9 @@ export function decodeChatCompletion(
|
|
|
35
35
|
): ReadableStream<ChatCompletionEvent> {
|
|
36
36
|
const reader = stream.getReader();
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
type Mode = { type: "function"; function: ToolCallFunctionCall } | { type: "message" };
|
|
39
|
+
|
|
40
|
+
let mode: Mode | null = null;
|
|
39
41
|
let functionCallName: string = "";
|
|
40
42
|
let functionCallArguments: string = "";
|
|
41
43
|
let functionCallScope: "client" | "server" = "client";
|
|
@@ -82,19 +84,19 @@ export function decodeChatCompletion(
|
|
|
82
84
|
const { done, value } = await reader.read();
|
|
83
85
|
|
|
84
86
|
if (done) {
|
|
85
|
-
if (mode === "function") {
|
|
87
|
+
if (mode?.type === "function") {
|
|
86
88
|
flushFunctionCall();
|
|
87
89
|
}
|
|
88
90
|
await cleanup(controller);
|
|
89
91
|
return;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
// In case we are
|
|
94
|
+
// In case we are currently handling a function call but the next message is either
|
|
93
95
|
// - not a function call
|
|
94
|
-
// - another function call (
|
|
95
|
-
// => flush
|
|
96
|
+
// - or is another function call (indicated by the presence of 'name' field in the next function call object)
|
|
97
|
+
// => flush the current function call.
|
|
96
98
|
if (
|
|
97
|
-
mode === "function" &&
|
|
99
|
+
mode?.type === "function" &&
|
|
98
100
|
(!value.choices[0].delta.tool_calls?.[0]?.function ||
|
|
99
101
|
value.choices[0].delta.tool_calls?.[0]?.function.name)
|
|
100
102
|
) {
|
|
@@ -103,10 +105,15 @@ export function decodeChatCompletion(
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
const maybeFunctionCall = value.choices[0].delta.tool_calls?.[0]?.function;
|
|
109
|
+
if (maybeFunctionCall) {
|
|
110
|
+
mode = { type: "function", function: maybeFunctionCall };
|
|
111
|
+
} else {
|
|
112
|
+
mode = { type: "message" };
|
|
113
|
+
}
|
|
107
114
|
|
|
108
115
|
// if we get a message, emit the content and continue;
|
|
109
|
-
if (mode === "message") {
|
|
116
|
+
if (mode.type === "message") {
|
|
110
117
|
// if we got a result message, send a result event
|
|
111
118
|
if (value.choices[0].delta.role === "function") {
|
|
112
119
|
controller.enqueue({
|
|
@@ -125,16 +132,22 @@ export function decodeChatCompletion(
|
|
|
125
132
|
continue;
|
|
126
133
|
}
|
|
127
134
|
// if we get a function call, buffer the name and arguments, then emit a partial event.
|
|
128
|
-
else if (mode === "function") {
|
|
129
|
-
|
|
130
|
-
|
|
135
|
+
else if (mode.type === "function") {
|
|
136
|
+
const maybeFunctionCallName = mode.function.name;
|
|
137
|
+
if (maybeFunctionCallName) {
|
|
138
|
+
functionCallName = maybeFunctionCallName;
|
|
131
139
|
}
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
|
|
141
|
+
const maybeFunctionCallArguments = mode.function.arguments;
|
|
142
|
+
if (maybeFunctionCallArguments) {
|
|
143
|
+
functionCallArguments += maybeFunctionCallArguments;
|
|
134
144
|
}
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
|
|
146
|
+
const maybeFunctionCallScope = mode.function.scope;
|
|
147
|
+
if (maybeFunctionCallScope) {
|
|
148
|
+
functionCallScope = maybeFunctionCallScope;
|
|
137
149
|
}
|
|
150
|
+
|
|
138
151
|
controller.enqueue({
|
|
139
152
|
type: "partial",
|
|
140
153
|
name: functionCallName,
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { Role } from "../types/openai-assistant";
|
|
2
2
|
|
|
3
|
+
export interface ToolCallFunctionCall {
|
|
4
|
+
arguments?: string;
|
|
5
|
+
|
|
6
|
+
name?: string;
|
|
7
|
+
// TODO:
|
|
8
|
+
// Temporarily add scope to the OpenAI protocol until we
|
|
9
|
+
// have our own protocol.
|
|
10
|
+
// When scope is "server", the client will not attempt to
|
|
11
|
+
// execute the function.
|
|
12
|
+
scope?: "client" | "server";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ToolCallPayload {
|
|
16
|
+
index: number;
|
|
17
|
+
id?: string;
|
|
18
|
+
function: ToolCallFunctionCall;
|
|
19
|
+
}
|
|
20
|
+
|
|
3
21
|
export interface ChatCompletionChunk {
|
|
4
22
|
choices: {
|
|
5
23
|
delta: {
|
|
@@ -18,21 +36,7 @@ export interface ChatCompletionChunk {
|
|
|
18
36
|
name?: string;
|
|
19
37
|
arguments?: string;
|
|
20
38
|
};
|
|
21
|
-
tool_calls?:
|
|
22
|
-
index: number;
|
|
23
|
-
id?: string;
|
|
24
|
-
function: {
|
|
25
|
-
arguments?: string;
|
|
26
|
-
|
|
27
|
-
name?: string;
|
|
28
|
-
// TODO:
|
|
29
|
-
// Temporarily add scope to the OpenAI protocol until we
|
|
30
|
-
// have our own protocol.
|
|
31
|
-
// When scope is "server", the client will not attempt to
|
|
32
|
-
// execute the function.
|
|
33
|
-
scope?: "client" | "server";
|
|
34
|
-
};
|
|
35
|
-
}[];
|
|
39
|
+
tool_calls?: ToolCallPayload[];
|
|
36
40
|
};
|
|
37
41
|
}[];
|
|
38
42
|
}
|
package/src/utils/utils.ts
CHANGED
|
@@ -290,7 +290,7 @@ export const isStreamStringEqualToType = (
|
|
|
290
290
|
value.startsWith(`${StreamStringPrefixes[type]}:`) && value.endsWith("\n");
|
|
291
291
|
|
|
292
292
|
export type StreamString =
|
|
293
|
-
`${
|
|
293
|
+
`${typeof StreamStringPrefixes[keyof typeof StreamStringPrefixes]}:${string}\n`;
|
|
294
294
|
|
|
295
295
|
/**
|
|
296
296
|
* A header sent to the client so it knows how to handle parsing the stream (as a deprecated text response or using the new prefixed protocol)
|
package/dist/chunk-BANDZXMP.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-BANDZXMP.mjs.map
|
package/dist/chunk-FFQUB5LF.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// src/constants/index.ts
|
|
2
|
-
var COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
|
|
3
|
-
var COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/chat/complete`;
|
|
4
|
-
var COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
COPILOT_CLOUD_API_URL,
|
|
8
|
-
COPILOT_CLOUD_CHAT_URL,
|
|
9
|
-
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=chunk-FFQUB5LF.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants/index.ts"],"sourcesContent":["export * from \"./copilot-protocol\";\nexport const COPILOT_CLOUD_API_URL = \"https://api.cloud.copilotkit.ai\";\nexport const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/chat/complete`;\nexport const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = \"X-CopilotCloud-Public-Api-Key\";\n"],"mappings":";AACO,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB,GAAG;AAClC,IAAM,sCAAsC;","names":[]}
|
package/dist/chunk-MSUB6DGR.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-MSUB6DGR.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/decode-chat-completion.ts"],"sourcesContent":["import { ChatCompletionChunk } from \"./parse-chat-completion\";\n\nexport interface ChatCompletionContentEvent {\n type: \"content\";\n content: string;\n}\n\nexport interface ChatCompletionPartialEvent {\n type: \"partial\";\n name: string;\n arguments: string;\n}\n\nexport interface ChatCompletionFunctionEvent {\n type: \"function\";\n name: string;\n arguments: any;\n scope: \"client\" | \"server\";\n}\n\nexport interface ChatCompletionResultEvent {\n type: \"result\";\n content: string;\n name: string;\n}\n\nexport type ChatCompletionEvent =\n | ChatCompletionContentEvent\n | ChatCompletionPartialEvent\n | ChatCompletionFunctionEvent\n | ChatCompletionResultEvent;\n\nexport function decodeChatCompletion(\n stream: ReadableStream<ChatCompletionChunk>,\n): ReadableStream<ChatCompletionEvent> {\n const reader = stream.getReader();\n\n let mode: \"function\" | \"message\" | null = null;\n let functionCallName: string = \"\";\n let functionCallArguments: string = \"\";\n let functionCallScope: \"client\" | \"server\" = \"client\";\n\n async function cleanup(controller?: ReadableStreamDefaultController<any>) {\n if (controller) {\n try {\n controller.close();\n } catch (_) {}\n }\n if (reader) {\n try {\n await reader.cancel();\n } catch (_) {}\n }\n }\n\n return new ReadableStream<ChatCompletionEvent>({\n async pull(controller) {\n const flushFunctionCall = (): boolean => {\n let args: any = null;\n try {\n args = JSON.parse(functionCallArguments);\n } catch (error) {\n cleanup(controller);\n controller.error(error);\n return false;\n }\n controller.enqueue({\n type: \"function\",\n name: functionCallName,\n arguments: args,\n scope: functionCallScope,\n });\n\n mode = null;\n functionCallName = \"\";\n functionCallArguments = \"\";\n return true;\n };\n\n while (true) {\n try {\n const { done, value } = await reader.read();\n\n if (done) {\n if (mode === \"function\") {\n flushFunctionCall();\n }\n await cleanup(controller);\n return;\n }\n\n // In case we are in a function call but the next message is\n // - not a function call\n // - another function call (when name is present)\n // => flush it.\n if (\n mode === \"function\" &&\n (!value.choices[0].delta.tool_calls?.[0]?.function ||\n value.choices[0].delta.tool_calls?.[0]?.function.name)\n ) {\n if (!flushFunctionCall()) {\n return;\n }\n }\n\n mode = value.choices[0].delta.tool_calls?.[0]?.function ? \"function\" : \"message\";\n\n // if we get a message, emit the content and continue;\n if (mode === \"message\") {\n // if we got a result message, send a result event\n if (value.choices[0].delta.role === \"function\") {\n controller.enqueue({\n type: \"result\",\n content: value.choices[0].delta.content!,\n name: value.choices[0].delta.name!,\n });\n }\n // otherwise, send a content event\n else if (value.choices[0].delta.content) {\n controller.enqueue({\n type: \"content\",\n content: value.choices[0].delta.content,\n });\n }\n continue;\n }\n // if we get a function call, buffer the name and arguments, then emit a partial event.\n else if (mode === \"function\") {\n if (value.choices[0].delta.tool_calls![0].function.name) {\n functionCallName = value.choices[0].delta.tool_calls![0].function.name!;\n }\n if (value.choices[0].delta.tool_calls![0].function.arguments) {\n functionCallArguments += value.choices[0].delta.tool_calls![0].function.arguments!;\n }\n if (value.choices[0].delta.tool_calls![0].function.scope) {\n functionCallScope = value.choices[0].delta.tool_calls![0].function.scope!;\n }\n controller.enqueue({\n type: \"partial\",\n name: functionCallName,\n arguments: functionCallArguments,\n });\n continue;\n }\n } catch (error) {\n controller.error(error);\n await cleanup(controller);\n return;\n }\n }\n },\n cancel() {\n reader.cancel();\n },\n });\n}\n"],"mappings":";AAgCO,SAAS,qBACd,QACqC;AACrC,QAAM,SAAS,OAAO,UAAU;AAEhC,MAAI,OAAsC;AAC1C,MAAI,mBAA2B;AAC/B,MAAI,wBAAgC;AACpC,MAAI,oBAAyC;AAE7C,iBAAe,QAAQ,YAAmD;AACxE,QAAI,YAAY;AACd,UAAI;AACF,mBAAW,MAAM;AAAA,MACnB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AACA,QAAI,QAAQ;AACV,UAAI;AACF,cAAM,OAAO,OAAO;AAAA,MACtB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AAAA,EACF;AAEA,SAAO,IAAI,eAAoC;AAAA,IAC7C,MAAM,KAAK,YAAY;AAxD3B;AAyDM,YAAM,oBAAoB,MAAe;AACvC,YAAI,OAAY;AAChB,YAAI;AACF,iBAAO,KAAK,MA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AC5B,gBAAI,MAAM,QAAQ,CAAC,EAAE,MAAM,WAAY,CAAC,EAAE,SAAS,MAAM;AACvD,iCAAmB,MAAM,QAAQ,CAAC,EAAE,MAAM,WAAY,CAAC,EAAE,SAAS;AAAA,YACpE;AACA,gBAAI,MAAM,QAAQ,CAAC,EAAE,MAAM,WAAY,CAAC,EAAE,SAAS,WAAW;AAC5D,uCAAyB,MAAM,QAAQ,CAAC,EAAE,MAAM,WAAY,CAAC,EAAE,SAAS;AAAA,YAC1E;AACA,gBAAI,MAAM,QAAQ,CAAC,EAAE,MAAM,WAAY,CAAC,EAAE,SAAS,OAAO;AACxD,kCAAoB,MAAM,QAAQ,CAAC,EAAE,MAAM,WAAY,CAAC,EAAE,SAAS;AAAA,YACrE;AACA,uBAAW,QAAQ;AAAA,cACjB,MAAM;AAAA,cACN,MAAM;AAAA,cACN,WAAW;AAAA,YACb,CAAC;AACD;AAAA,UACF;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AACtB,gBAAM,QAAQ,UAAU;AACxB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,OAAO;AAAA,IAChB;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/annotated-function.ts"],"sourcesContent":["import { Action, AnnotatedFunction, ToolDefinition, Parameter } from \"../types\";\n\nexport function annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): ToolDefinition {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ToolDefinition = {\n type: \"function\",\n function: {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n },\n };\n\n return chatCompletionFunction;\n}\n\nfunction convertAttribute(attribute: Parameter): any {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function actionToChatCompletionFunction(action: Action<any>): ToolDefinition {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of action.parameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of action.parameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ToolDefinition = {\n type: \"function\",\n function: {\n name: action.name,\n ...(action.description && { description: action.description }),\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n },\n };\n\n return chatCompletionFunction;\n}\n\nexport function annotatedFunctionToAction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): Action<any> {\n const parameters: Parameter[] = annotatedFunction.argumentAnnotations.map((annotation) => {\n switch (annotation.type) {\n case \"string\":\n case \"number\":\n case \"boolean\":\n case \"object\":\n return {\n name: annotation.name,\n description: annotation.description,\n type: annotation.type,\n required: annotation.required,\n };\n case \"array\":\n let type;\n if (annotation.items.type === \"string\") {\n type = \"string[]\";\n } else if (annotation.items.type === \"number\") {\n type = \"number[]\";\n } else if (annotation.items.type === \"boolean\") {\n type = \"boolean[]\";\n } else if (annotation.items.type === \"object\") {\n type = \"object[]\";\n } else {\n type = \"string[]\";\n }\n return {\n name: annotation.name,\n description: annotation.description,\n type: type as any,\n required: annotation.required,\n };\n }\n });\n\n return {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: parameters,\n handler: (args) => {\n const paramsInCorrectOrder: any[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n paramsInCorrectOrder.push(args[arg.name]);\n }\n return annotatedFunction.implementation(...paramsInCorrectOrder);\n },\n };\n}\n"],"mappings":";AAEO,SAAS,0CACd,mBACgB;AAEhB,MAAI,aAAqC,CAAC;AAC1C,WAAS,OAAO,kBAAkB,qBAAqB;AAErD,QAAI,EAAE,MAAM,UAAU,GAAG,cAAc,IAAI;AAC3C,eAAW,IAAI,IAAI,IAAI;AAAA,EACzB;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,kBAAkB,qBAAqB;AACrD,QAAI,IAAI,UAAU;AAChB,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,MAAI,yBAAyC;AAAA,IAC3C,MAAM;AAAA,IACN,UAAU;AAAA,MACR,MAAM,kBAAkB;AAAA,MACxB,aAAa,kBAAkB;AAAA,MAC/B,YAAY;AAAA,QACV,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,UAAU;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;AACA,eAAO;AAAA,UACL,MAAM,WAAW;AAAA,UACjB,aAAa,WAAW;AAAA,UACxB;AAAA,UACA,UAAU,WAAW;AAAA,QACvB;AAAA,IACJ;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,MAAM,kBAAkB;AAAA,IACxB,aAAa,kBAAkB;AAAA,IAC/B;AAAA,IACA,SAAS,CAAC,SAAS;AACjB,YAAM,uBAA8B,CAAC;AACrC,eAAS,OAAO,kBAAkB,qBAAqB;AACrD,6BAAqB,KAAK,KAAK,IAAI,IAAI,CAAC;AAAA,MAC1C;AACA,aAAO,kBAAkB,eAAe,GAAG,oBAAoB;AAAA,IACjE;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/parse-chat-completion.ts"],"sourcesContent":["import { Role } from \"../types/openai-assistant\";\n\nexport interface ChatCompletionChunk {\n choices: {\n delta: {\n id?: string;\n role: Role;\n content?: string | null;\n\n // TODO:\n // Temporarily add name to the OpenAI protocol until we\n // have our own protocol.\n // When name is set, we return the result of a server-side\n // function call.\n name?: string;\n\n function_call?: {\n name?: string;\n arguments?: string;\n };\n tool_calls?: {\n index: number;\n id?: string;\n function: {\n arguments?: string;\n\n name?: string;\n // TODO:\n // Temporarily add scope to the OpenAI protocol until we\n // have our own protocol.\n // When scope is \"server\", the client will not attempt to\n // execute the function.\n scope?: \"client\" | \"server\";\n };\n }[];\n };\n }[];\n}\n\n// TODO:\n// it's possible that unicode characters could be split across chunks\n// make sure to properly handle that\nexport function parseChatCompletion(\n stream: ReadableStream<Uint8Array>,\n): ReadableStream<ChatCompletionChunk> {\n const reader = stream.getReader();\n let buffer = new Uint8Array();\n\n async function cleanup(controller?: ReadableStreamDefaultController<any>) {\n if (controller) {\n try {\n controller.close();\n } catch (_) {}\n }\n if (reader) {\n try {\n await reader.cancel();\n } catch (_) {}\n }\n }\n\n return new ReadableStream<ChatCompletionChunk>({\n async pull(controller) {\n while (true) {\n try {\n const { done, value } = await reader.read();\n\n if (done) {\n await cleanup(controller);\n return;\n }\n\n const newBuffer = new Uint8Array(buffer.length + value.length);\n newBuffer.set(buffer);\n newBuffer.set(value, buffer.length);\n buffer = newBuffer;\n\n const valueString = new TextDecoder(\"utf-8\").decode(buffer);\n const lines = valueString.split(\"\\n\").filter((line) => line.trim() !== \"\");\n\n // If the last line isn't complete, keep it in the buffer for next time\n buffer = !valueString.endsWith(\"\\n\")\n ? new TextEncoder().encode(lines.pop() || \"\")\n : new Uint8Array();\n\n for (const line of lines) {\n const cleanedLine = line.replace(/^data: /, \"\");\n\n if (cleanedLine === \"[DONE]\") {\n await cleanup(controller);\n return;\n }\n\n const json = JSON.parse(cleanedLine);\n controller.enqueue(json);\n }\n } catch (error) {\n controller.error(error);\n await cleanup(controller);\n return;\n }\n }\n },\n cancel() {\n reader.cancel();\n },\n });\n}\n"],"mappings":";AA0CO,SAAS,oBACd,QACqC;AACrC,QAAM,SAAS,OAAO,UAAU;AAChC,MAAI,SAAS,IAAI,WAAW;AAE5B,iBAAe,QAAQ,YAAmD;AACxE,QAAI,YAAY;AACd,UAAI;AACF,mBAAW,MAAM;AAAA,MACnB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AACA,QAAI,QAAQ;AACV,UAAI;AACF,cAAM,OAAO,OAAO;AAAA,MACtB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AAAA,EACF;AAEA,SAAO,IAAI,eAAoC;AAAA,IAC7C,MAAM,KAAK,YAAY;AACrB,aAAO,MAAM;AACX,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,cAAI,MAAM;AACR,kBAAM,QAAQ,UAAU;AACxB;AAAA,UACF;AAEA,gBAAM,YAAY,IAAI,WAAW,OAAO,SAAS,MAAM,MAAM;AAC7D,oBAAU,IAAI,MAAM;AACpB,oBAAU,IAAI,OAAO,OAAO,MAAM;AAClC,mBAAS;AAET,gBAAM,cAAc,IAAI,YAAY,OAAO,EAAE,OAAO,MAAM;AAC1D,gBAAM,QAAQ,YAAY,MAAM,IAAI,EAAE,OAAO,CAAC,SAAS,KAAK,KAAK,MAAM,EAAE;AAGzE,mBAAS,CAAC,YAAY,SAAS,IAAI,IAC/B,IAAI,YAAY,EAAE,OAAO,MAAM,IAAI,KAAK,EAAE,IAC1C,IAAI,WAAW;AAEnB,qBAAW,QAAQ,OAAO;AACxB,kBAAM,cAAc,KAAK,QAAQ,WAAW,EAAE;AAE9C,gBAAI,gBAAgB,UAAU;AAC5B,oBAAM,QAAQ,UAAU;AACxB;AAAA,YACF;AAEA,kBAAM,OAAO,KAAK,MAAM,WAAW;AACnC,uBAAW,QAAQ,IAAI;AAAA,UACzB;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AACtB,gBAAM,QAAQ,UAAU;AACxB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,OAAO;AAAA,IAChB;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// src/types/copilot-cloud-config.ts
|
|
17
|
-
var copilot_cloud_config_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(copilot_cloud_config_exports);
|
|
19
|
-
//# sourceMappingURL=copilot-cloud-config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/copilot-cloud-config.ts"],"sourcesContent":["export interface CopilotCloudConfig {\n guardrails: {\n input: {\n restrictToTopic: {\n enabled: boolean;\n validTopics: string[];\n invalidTopics: string[];\n };\n };\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
File without changes
|
|
File without changes
|