@copilotkit/shared 1.0.0-beta.1 → 1.0.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/.turbo/turbo-build.log +47 -61
- package/CHANGELOG.md +31 -0
- package/dist/{chunk-3VA36BKL.mjs → chunk-2WEXXBTK.mjs} +1 -4
- package/dist/chunk-2WEXXBTK.mjs.map +1 -0
- package/dist/{chunk-2VLE6D3W.mjs → chunk-3AJ2GKWG.mjs} +2 -2
- package/dist/chunk-3AJ2GKWG.mjs.map +1 -0
- package/dist/chunk-DE5K76I2.mjs +1 -0
- package/dist/chunk-YJLRG5U3.mjs +1 -0
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +1 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/index.mjs +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +6 -172
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -14
- package/dist/telemetry/index.js +0 -3
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/index.mjs +1 -1
- package/dist/telemetry/telemetry-client.js +0 -3
- package/dist/telemetry/telemetry-client.js.map +1 -1
- package/dist/telemetry/telemetry-client.mjs +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +1 -2
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.js +5 -168
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +2 -10
- package/package.json +3 -3
- package/src/constants/index.ts +1 -1
- package/src/telemetry/telemetry-client.ts +0 -5
- package/src/types/index.ts +0 -1
- package/src/utils/index.ts +0 -1
- package/dist/chunk-2VLE6D3W.mjs.map +0 -1
- package/dist/chunk-3VA36BKL.mjs.map +0 -1
- package/dist/chunk-BANDZXMP.mjs +0 -1
- package/dist/chunk-CYDWEPFL.mjs +0 -1
- package/dist/chunk-S4HGLK2E.mjs +0 -163
- package/dist/chunk-S4HGLK2E.mjs.map +0 -1
- package/dist/chunk-YBHX4Y25.mjs +0 -1
- package/dist/chunk-YBHX4Y25.mjs.map +0 -1
- package/dist/types/annotated-function.d.ts +0 -24
- package/dist/types/annotated-function.js +0 -19
- package/dist/types/annotated-function.js.map +0 -1
- package/dist/types/annotated-function.mjs +0 -2
- package/dist/types/annotated-function.mjs.map +0 -1
- package/dist/utils/annotated-function.d.ts +0 -9
- package/dist/utils/annotated-function.js +0 -189
- package/dist/utils/annotated-function.js.map +0 -1
- package/dist/utils/annotated-function.mjs +0 -11
- package/dist/utils/annotated-function.mjs.map +0 -1
- package/src/types/annotated-function.ts +0 -27
- package/src/utils/annotated-function.ts +0 -179
- /package/dist/{chunk-BANDZXMP.mjs.map → chunk-DE5K76I2.mjs.map} +0 -0
- /package/dist/{chunk-CYDWEPFL.mjs.map → chunk-YJLRG5U3.mjs.map} +0 -0
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { Action, AnnotatedFunction, ToolDefinition, Parameter } from "../types";
|
|
2
|
-
|
|
3
|
-
export function annotatedFunctionToChatCompletionFunction(
|
|
4
|
-
annotatedFunction: AnnotatedFunction<any[]>,
|
|
5
|
-
): ToolDefinition {
|
|
6
|
-
// Create the parameters object based on the argumentAnnotations
|
|
7
|
-
let parameters: { [key: string]: any } = {};
|
|
8
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
9
|
-
// isolate the args we should forward inline
|
|
10
|
-
let { name, required, ...forwardedArgs } = arg;
|
|
11
|
-
parameters[arg.name] = forwardedArgs;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let requiredParameterNames: string[] = [];
|
|
15
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
16
|
-
if (arg.required) {
|
|
17
|
-
requiredParameterNames.push(arg.name);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Create the ChatCompletionFunctions object
|
|
22
|
-
let chatCompletionFunction: ToolDefinition = {
|
|
23
|
-
type: "function",
|
|
24
|
-
function: {
|
|
25
|
-
name: annotatedFunction.name,
|
|
26
|
-
description: annotatedFunction.description,
|
|
27
|
-
parameters: {
|
|
28
|
-
type: "object",
|
|
29
|
-
properties: parameters,
|
|
30
|
-
required: requiredParameterNames,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return chatCompletionFunction;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function convertAttribute(attribute: Parameter): any {
|
|
39
|
-
switch (attribute.type) {
|
|
40
|
-
case "string":
|
|
41
|
-
return {
|
|
42
|
-
type: "string",
|
|
43
|
-
description: attribute.description,
|
|
44
|
-
...(attribute.enum && { enum: attribute.enum }),
|
|
45
|
-
};
|
|
46
|
-
case "number":
|
|
47
|
-
case "boolean":
|
|
48
|
-
return {
|
|
49
|
-
type: attribute.type,
|
|
50
|
-
description: attribute.description,
|
|
51
|
-
};
|
|
52
|
-
case "object":
|
|
53
|
-
case "object[]":
|
|
54
|
-
const properties = attribute.attributes?.reduce(
|
|
55
|
-
(acc, attr) => {
|
|
56
|
-
acc[attr.name] = convertAttribute(attr);
|
|
57
|
-
return acc;
|
|
58
|
-
},
|
|
59
|
-
{} as Record<string, any>,
|
|
60
|
-
);
|
|
61
|
-
const required = attribute.attributes
|
|
62
|
-
?.filter((attr) => attr.required !== false)
|
|
63
|
-
.map((attr) => attr.name);
|
|
64
|
-
if (attribute.type === "object[]") {
|
|
65
|
-
return {
|
|
66
|
-
type: "array",
|
|
67
|
-
items: {
|
|
68
|
-
type: "object",
|
|
69
|
-
...(properties && { properties }),
|
|
70
|
-
...(required && required.length > 0 && { required }),
|
|
71
|
-
},
|
|
72
|
-
description: attribute.description,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
type: "object",
|
|
77
|
-
description: attribute.description,
|
|
78
|
-
...(properties && { properties }),
|
|
79
|
-
...(required && required.length > 0 && { required }),
|
|
80
|
-
};
|
|
81
|
-
default:
|
|
82
|
-
// Handle arrays of primitive types and undefined attribute.type
|
|
83
|
-
if (attribute.type?.endsWith("[]")) {
|
|
84
|
-
const itemType = attribute.type.slice(0, -2);
|
|
85
|
-
return {
|
|
86
|
-
type: "array",
|
|
87
|
-
items: { type: itemType },
|
|
88
|
-
description: attribute.description,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
// Fallback for undefined type or any other unexpected type
|
|
92
|
-
return {
|
|
93
|
-
type: "string",
|
|
94
|
-
description: attribute.description,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function actionToChatCompletionFunction(action: Action<any>): ToolDefinition {
|
|
100
|
-
// Create the parameters object based on the argumentAnnotations
|
|
101
|
-
let parameters: { [key: string]: any } = {};
|
|
102
|
-
for (let parameter of action.parameters || []) {
|
|
103
|
-
parameters[parameter.name] = convertAttribute(parameter);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
let requiredParameterNames: string[] = [];
|
|
107
|
-
for (let arg of action.parameters || []) {
|
|
108
|
-
if (arg.required !== false) {
|
|
109
|
-
requiredParameterNames.push(arg.name);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Create the ChatCompletionFunctions object
|
|
114
|
-
let chatCompletionFunction: ToolDefinition = {
|
|
115
|
-
type: "function",
|
|
116
|
-
function: {
|
|
117
|
-
name: action.name,
|
|
118
|
-
...(action.description && { description: action.description }),
|
|
119
|
-
parameters: {
|
|
120
|
-
type: "object",
|
|
121
|
-
properties: parameters,
|
|
122
|
-
required: requiredParameterNames,
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return chatCompletionFunction;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function annotatedFunctionToAction(
|
|
131
|
-
annotatedFunction: AnnotatedFunction<any[]>,
|
|
132
|
-
): Action<any> {
|
|
133
|
-
const parameters: Parameter[] = annotatedFunction.argumentAnnotations.map((annotation) => {
|
|
134
|
-
switch (annotation.type) {
|
|
135
|
-
case "string":
|
|
136
|
-
case "number":
|
|
137
|
-
case "boolean":
|
|
138
|
-
case "object":
|
|
139
|
-
return {
|
|
140
|
-
name: annotation.name,
|
|
141
|
-
description: annotation.description,
|
|
142
|
-
type: annotation.type,
|
|
143
|
-
required: annotation.required,
|
|
144
|
-
};
|
|
145
|
-
case "array":
|
|
146
|
-
let type;
|
|
147
|
-
if (annotation.items.type === "string") {
|
|
148
|
-
type = "string[]";
|
|
149
|
-
} else if (annotation.items.type === "number") {
|
|
150
|
-
type = "number[]";
|
|
151
|
-
} else if (annotation.items.type === "boolean") {
|
|
152
|
-
type = "boolean[]";
|
|
153
|
-
} else if (annotation.items.type === "object") {
|
|
154
|
-
type = "object[]";
|
|
155
|
-
} else {
|
|
156
|
-
type = "string[]";
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
name: annotation.name,
|
|
160
|
-
description: annotation.description,
|
|
161
|
-
type: type as any,
|
|
162
|
-
required: annotation.required,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
name: annotatedFunction.name,
|
|
169
|
-
description: annotatedFunction.description,
|
|
170
|
-
parameters: parameters,
|
|
171
|
-
handler: (args) => {
|
|
172
|
-
const paramsInCorrectOrder: any[] = [];
|
|
173
|
-
for (let arg of annotatedFunction.argumentAnnotations) {
|
|
174
|
-
paramsInCorrectOrder.push(args[arg.name]);
|
|
175
|
-
}
|
|
176
|
-
return annotatedFunction.implementation(...paramsInCorrectOrder);
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
File without changes
|
|
File without changes
|