@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.
Files changed (56) hide show
  1. package/.turbo/turbo-build.log +47 -61
  2. package/CHANGELOG.md +31 -0
  3. package/dist/{chunk-3VA36BKL.mjs → chunk-2WEXXBTK.mjs} +1 -4
  4. package/dist/chunk-2WEXXBTK.mjs.map +1 -0
  5. package/dist/{chunk-2VLE6D3W.mjs → chunk-3AJ2GKWG.mjs} +2 -2
  6. package/dist/chunk-3AJ2GKWG.mjs.map +1 -0
  7. package/dist/chunk-DE5K76I2.mjs +1 -0
  8. package/dist/chunk-YJLRG5U3.mjs +1 -0
  9. package/dist/constants/index.d.ts +1 -1
  10. package/dist/constants/index.js +1 -1
  11. package/dist/constants/index.js.map +1 -1
  12. package/dist/constants/index.mjs +1 -1
  13. package/dist/index.d.ts +0 -2
  14. package/dist/index.js +6 -172
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +5 -14
  17. package/dist/telemetry/index.js +0 -3
  18. package/dist/telemetry/index.js.map +1 -1
  19. package/dist/telemetry/index.mjs +1 -1
  20. package/dist/telemetry/telemetry-client.js +0 -3
  21. package/dist/telemetry/telemetry-client.js.map +1 -1
  22. package/dist/telemetry/telemetry-client.mjs +1 -1
  23. package/dist/types/index.d.ts +0 -1
  24. package/dist/types/index.js.map +1 -1
  25. package/dist/types/index.mjs +1 -2
  26. package/dist/utils/index.d.ts +0 -3
  27. package/dist/utils/index.js +5 -168
  28. package/dist/utils/index.js.map +1 -1
  29. package/dist/utils/index.mjs +2 -10
  30. package/package.json +3 -3
  31. package/src/constants/index.ts +1 -1
  32. package/src/telemetry/telemetry-client.ts +0 -5
  33. package/src/types/index.ts +0 -1
  34. package/src/utils/index.ts +0 -1
  35. package/dist/chunk-2VLE6D3W.mjs.map +0 -1
  36. package/dist/chunk-3VA36BKL.mjs.map +0 -1
  37. package/dist/chunk-BANDZXMP.mjs +0 -1
  38. package/dist/chunk-CYDWEPFL.mjs +0 -1
  39. package/dist/chunk-S4HGLK2E.mjs +0 -163
  40. package/dist/chunk-S4HGLK2E.mjs.map +0 -1
  41. package/dist/chunk-YBHX4Y25.mjs +0 -1
  42. package/dist/chunk-YBHX4Y25.mjs.map +0 -1
  43. package/dist/types/annotated-function.d.ts +0 -24
  44. package/dist/types/annotated-function.js +0 -19
  45. package/dist/types/annotated-function.js.map +0 -1
  46. package/dist/types/annotated-function.mjs +0 -2
  47. package/dist/types/annotated-function.mjs.map +0 -1
  48. package/dist/utils/annotated-function.d.ts +0 -9
  49. package/dist/utils/annotated-function.js +0 -189
  50. package/dist/utils/annotated-function.js.map +0 -1
  51. package/dist/utils/annotated-function.mjs +0 -11
  52. package/dist/utils/annotated-function.mjs.map +0 -1
  53. package/src/types/annotated-function.ts +0 -27
  54. package/src/utils/annotated-function.ts +0 -179
  55. /package/dist/{chunk-BANDZXMP.mjs.map → chunk-DE5K76I2.mjs.map} +0 -0
  56. /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
- }