@copilotkit/shared 0.5.0-mme-function-call-labels.2 → 0.5.0-mme-prerelease-demo.4

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @copilotkit/shared@0.5.0-mme-function-call-labels.2 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
2
+ > @copilotkit/shared@0.5.0-mme-prerelease-demo.4 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
3
3
  > tsup --clean
4
4
 
5
5
  CLI Building entry: src/index.ts, src/constants/copilot-protocol.ts, src/constants/index.ts, src/types/action.ts, src/types/annotated-function.ts, src/types/index.ts, src/types/openai-assistant.ts, src/utils/annotated-function.ts, src/utils/decode-chat-completion-as-text.ts, src/utils/decode-chat-completion.ts, src/utils/index.ts, src/utils/parse-chat-completion.ts, src/utils/utils.test.ts, src/utils/utils.ts
@@ -22,12 +22,12 @@
22
22
  CJS dist/utils/decode-chat-completion.js 4.42 KB
23
23
  CJS dist/utils/index.js 15.26 KB
24
24
  CJS dist/utils/parse-chat-completion.js 2.68 KB
25
- CJS dist/utils/utils.js 6.25 KB
26
25
  CJS dist/utils/utils.test.js 184.00 B
26
+ CJS dist/utils/utils.js 6.25 KB
27
27
  CJS dist/index.js.map 30.29 KB
28
28
  CJS dist/constants/copilot-protocol.js.map 261.00 B
29
29
  CJS dist/constants/index.js.map 336.00 B
30
- CJS dist/types/action.js.map 2.94 KB
30
+ CJS dist/types/action.js.map 4.59 KB
31
31
  CJS dist/types/annotated-function.js.map 871.00 B
32
32
  CJS dist/types/index.js.map 234.00 B
33
33
  CJS dist/types/openai-assistant.js.map 2.86 KB
@@ -36,9 +36,9 @@
36
36
  CJS dist/utils/decode-chat-completion.js.map 6.89 KB
37
37
  CJS dist/utils/index.js.map 30.28 KB
38
38
  CJS dist/utils/parse-chat-completion.js.map 4.15 KB
39
- CJS dist/utils/utils.js.map 12.08 KB
40
39
  CJS dist/utils/utils.test.js.map 354.00 B
41
- CJS ⚡️ Build success in 64ms
40
+ CJS dist/utils/utils.js.map 12.08 KB
41
+ CJS ⚡️ Build success in 60ms
42
42
  ESM dist/index.mjs 1.17 KB
43
43
  ESM dist/constants/copilot-protocol.mjs 166.00 B
44
44
  ESM dist/types/action.mjs 67.00 B
@@ -48,9 +48,9 @@
48
48
  ESM dist/chunk-NKEDWRKJ.mjs 3.36 KB
49
49
  ESM dist/chunk-TYZD5BQY.mjs 1.63 KB
50
50
  ESM dist/chunk-2C54HQBI.mjs 4.92 KB
51
+ ESM dist/constants/index.mjs 187.00 B
51
52
  ESM dist/chunk-2M3YVRFS.mjs 43.00 B
52
53
  ESM dist/chunk-3ZU7SB62.mjs 200.00 B
53
- ESM dist/constants/index.mjs 187.00 B
54
54
  ESM dist/types/annotated-function.mjs 79.00 B
55
55
  ESM dist/types/index.mjs 162.00 B
56
56
  ESM dist/chunk-DE5K76I2.mjs 43.00 B
@@ -62,8 +62,8 @@
62
62
  ESM dist/utils/decode-chat-completion-as-text.mjs 170.00 B
63
63
  ESM dist/utils/decode-chat-completion.mjs 150.00 B
64
64
  ESM dist/utils/index.mjs 943.00 B
65
- ESM dist/utils/utils.test.mjs 170.00 B
66
65
  ESM dist/utils/parse-chat-completion.mjs 147.00 B
66
+ ESM dist/utils/utils.test.mjs 170.00 B
67
67
  ESM dist/utils/utils.mjs 439.00 B
68
68
  ESM dist/index.mjs.map 71.00 B
69
69
  ESM dist/constants/copilot-protocol.mjs.map 71.00 B
@@ -74,9 +74,9 @@
74
74
  ESM dist/chunk-NKEDWRKJ.mjs.map 6.85 KB
75
75
  ESM dist/chunk-TYZD5BQY.mjs.map 4.10 KB
76
76
  ESM dist/chunk-2C54HQBI.mjs.map 12.00 KB
77
+ ESM dist/constants/index.mjs.map 71.00 B
77
78
  ESM dist/chunk-2M3YVRFS.mjs.map 71.00 B
78
79
  ESM dist/chunk-3ZU7SB62.mjs.map 214.00 B
79
- ESM dist/constants/index.mjs.map 71.00 B
80
80
  ESM dist/types/annotated-function.mjs.map 71.00 B
81
81
  ESM dist/types/index.mjs.map 71.00 B
82
82
  ESM dist/chunk-DE5K76I2.mjs.map 71.00 B
@@ -88,16 +88,16 @@
88
88
  ESM dist/utils/decode-chat-completion-as-text.mjs.map 71.00 B
89
89
  ESM dist/utils/decode-chat-completion.mjs.map 71.00 B
90
90
  ESM dist/utils/index.mjs.map 71.00 B
91
- ESM dist/utils/utils.test.mjs.map 352.00 B
92
91
  ESM dist/utils/parse-chat-completion.mjs.map 71.00 B
92
+ ESM dist/utils/utils.test.mjs.map 352.00 B
93
93
  ESM dist/utils/utils.mjs.map 71.00 B
94
- ESM ⚡️ Build success in 70ms
94
+ ESM ⚡️ Build success in 64ms
95
95
  DTS Build start
96
- DTS ⚡️ Build success in 2150ms
96
+ DTS ⚡️ Build success in 2339ms
97
97
  DTS dist/index.d.ts 1.25 KB
98
98
  DTS dist/types/openai-assistant.d.ts 2.79 KB
99
99
  DTS dist/types/annotated-function.d.ts 766.00 B
100
- DTS dist/types/action.d.ts 1.86 KB
100
+ DTS dist/types/action.d.ts 2.09 KB
101
101
  DTS dist/utils/utils.d.ts 4.32 KB
102
102
  DTS dist/utils/parse-chat-completion.d.ts 805.00 B
103
103
  DTS dist/utils/decode-chat-completion.d.ts 955.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @copilotkit/shared
2
2
 
3
+ ## 0.5.0-mme-prerelease-demo.4
4
+
5
+ ### Minor Changes
6
+
7
+ - Pre: Fix instructions not updating
8
+
9
+ ## 0.5.0-mme-prerelease-demo.3
10
+
11
+ ### Minor Changes
12
+
13
+ - 3fbee5d: OpenAIAdapter-getter
14
+ - 3f5ad60: OpenAIAdapter: make openai instance gettable
15
+ - Pre release for demos
16
+
3
17
  ## 0.5.0-mme-function-call-labels.2
4
18
 
5
19
  ### Minor Changes
@@ -29,20 +29,23 @@ type ObjectParameter = {
29
29
  attributes?: Parameter[];
30
30
  };
31
31
  type Parameter = BaseParameter | StringParameter | ObjectParameter;
32
+ type EnumParameterType<E, Required> = E extends string ? Required extends false ? E | undefined : E : never;
33
+ type ObjectTypeParameter<Attributes> = Attributes extends Parameter[] ? MappedParameterTypes<Attributes> : never;
34
+ type ObjectArrayTypeParameter<Attributes> = Attributes extends Parameter[] ? MappedParameterTypes<Attributes>[] : any[];
35
+ type OtherParameterType<Type, Required> = Required extends false ? TypeMap[Type extends keyof TypeMap ? Type : "string"] | undefined : TypeMap[Type extends keyof TypeMap ? Type : "string"];
32
36
  type MappedParameterTypes<T extends Parameter[]> = {
33
37
  [P in T[number] as P["name"]]: P extends {
34
38
  enum: Array<infer E>;
35
- } ? E extends string ? P["required"] extends false ? E | undefined : E : never : P extends {
39
+ } ? EnumParameterType<E, P["required"]> : P extends {
36
40
  type: "object";
37
41
  attributes: infer Attributes;
38
- } ? Attributes extends Parameter[] ? MappedParameterTypes<Attributes> : never : P extends {
42
+ } ? ObjectTypeParameter<Attributes> : P extends {
39
43
  type: "object[]";
40
44
  attributes?: never;
41
45
  } ? any[] : P extends {
42
46
  type: "object[]";
43
47
  attributes: infer Attributes;
44
- } ? Attributes extends Parameter[] ? MappedParameterTypes<Attributes>[] : any[] : P["required"] extends false ? // Include 'undefined' for optional parameters
45
- TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"] | undefined : TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"];
48
+ } ? ObjectArrayTypeParameter<Attributes> : OtherParameterType<P["type"], P["required"]>;
46
49
  };
47
50
  type Action<T extends Parameter[] | [] = []> = {
48
51
  name: string;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/action.ts"],"sourcesContent":["type TypeMap = {\n string: string;\n number: number;\n boolean: boolean;\n object: object;\n \"string[]\": string[];\n \"number[]\": number[];\n \"boolean[]\": boolean[];\n \"object[]\": object[];\n};\n\nexport type BaseParameter = {\n name: string;\n type?: Exclude<keyof TypeMap, \"string\" | \"object\" | \"object[]\">; // Exclude object types for BaseParameter\n description?: string;\n required?: boolean;\n};\n\nexport type StringParameter = {\n name: string;\n type: \"string\";\n description?: string;\n required?: boolean;\n enum?: string[];\n};\n\nexport type ObjectParameter = {\n name: string;\n type: \"object\" | \"object[]\";\n description?: string;\n required?: boolean;\n attributes?: Parameter[];\n};\n\nexport type Parameter = BaseParameter | StringParameter | ObjectParameter;\n\nexport type MappedParameterTypes<T extends Parameter[]> = {\n // Check if the parameter has an 'enum' defined\n [P in T[number] as P[\"name\"]]: P extends { enum: Array<infer E> }\n ? E extends string // Ensure the enum values are strings\n ? P[\"required\"] extends false // Check if the parameter is optional\n ? E | undefined // If so, include 'undefined' in the type\n : E // Otherwise, use the enum type directly\n : never // This case should not occur since 'enum' implies string values\n : // Handle parameters defined as 'object' with specified attributes\n P extends { type: \"object\"; attributes: infer Attributes }\n ? Attributes extends Parameter[]\n ? MappedParameterTypes<Attributes> // Recursively map the attributes of the object\n : never // If 'attributes' is not an array of Parameters, this is invalid\n : // Handle parameters defined as 'object[]' without specified attributes\n P extends { type: \"object[]\"; attributes?: never }\n ? any[] // Default to 'any[]' for arrays of objects without specific attributes\n : // Handle parameters defined as 'object[]' with specified attributes\n P extends { type: \"object[]\"; attributes: infer Attributes }\n ? Attributes extends Parameter[]\n ? MappedParameterTypes<Attributes>[] // Recursively map each object in the array\n : any[] // Default to 'any[]' if attributes are not properly defined\n : // Handle all other parameter types\n P[\"required\"] extends false\n ? // Include 'undefined' for optional parameters\n TypeMap[P[\"type\"] extends keyof TypeMap ? P[\"type\"] : \"string\"] | undefined\n : // Use the direct mapping from 'TypeMap' for the parameter's type\n TypeMap[P[\"type\"] extends keyof TypeMap ? P[\"type\"] : \"string\"];\n};\n\nexport type Action<T extends Parameter[] | [] = []> = {\n name: string;\n description?: string;\n parameters?: T;\n handler: T extends []\n ? () => any | Promise<any>\n : (args: MappedParameterTypes<T>) => any | Promise<any>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/types/action.ts"],"sourcesContent":["type TypeMap = {\n string: string;\n number: number;\n boolean: boolean;\n object: object;\n \"string[]\": string[];\n \"number[]\": number[];\n \"boolean[]\": boolean[];\n \"object[]\": object[];\n};\n\nexport type BaseParameter = {\n name: string;\n type?: Exclude<keyof TypeMap, \"string\" | \"object\" | \"object[]\">; // Exclude object types for BaseParameter\n description?: string;\n required?: boolean;\n};\n\nexport type StringParameter = {\n name: string;\n type: \"string\";\n description?: string;\n required?: boolean;\n enum?: string[];\n};\n\nexport type ObjectParameter = {\n name: string;\n type: \"object\" | \"object[]\";\n description?: string;\n required?: boolean;\n attributes?: Parameter[];\n};\n\nexport type Parameter = BaseParameter | StringParameter | ObjectParameter;\n\ntype EnumParameterType<E, Required> = E extends string\n ? Required extends false\n ? E | undefined\n : E\n : never;\n\ntype ObjectTypeParameter<Attributes> = Attributes extends Parameter[]\n ? MappedParameterTypes<Attributes>\n : never;\n\ntype ObjectArrayTypeParameter<Attributes> = Attributes extends Parameter[]\n ? MappedParameterTypes<Attributes>[]\n : any[];\n\ntype OtherParameterType<Type, Required> = Required extends false\n ? TypeMap[Type extends keyof TypeMap ? Type : \"string\"] | undefined\n : TypeMap[Type extends keyof TypeMap ? Type : \"string\"];\n\n// prettier-ignore\nexport type MappedParameterTypes<T extends Parameter[]> = {\n [P in T[number] as P[\"name\"]]: P extends { enum: Array<infer E> } ? EnumParameterType<E, P[\"required\"]>\n : P extends { type: \"object\"; attributes: infer Attributes } ? ObjectTypeParameter<Attributes>\n : P extends { type: \"object[]\"; attributes?: never } ? any[]\n : P extends { type: \"object[]\"; attributes: infer Attributes } ? ObjectArrayTypeParameter<Attributes>\n : OtherParameterType<P[\"type\"], P[\"required\"]>;\n};\n\nexport type Action<T extends Parameter[] | [] = []> = {\n name: string;\n description?: string;\n parameters?: T;\n handler: T extends []\n ? () => any | Promise<any>\n : (args: MappedParameterTypes<T>) => any | Promise<any>;\n};\n\n// This is the original \"ceiling is being raised\" version of MappedParameterTypes.\n//\n// ceiling is being raised. cursor's copilot helped us write \"superhuman code\"\n// for a critical feature. We can read this code, but VERY few engineers out\n// there could write it from scratch.\n// Took lots of convincing too. \"come on, this must be possible, try harder\".\n// and obviously- done in parts.\n//\n// - https://twitter.com/ataiiam/status/1765089261374914957\n// (Mar 5, 2024)\n//\n// export type MappedParameterTypes<T extends Parameter[]> = {\n// // Check if the parameter has an 'enum' defined\n// [P in T[number] as P[\"name\"]]: P extends { enum: Array<infer E> }\n// ? E extends string // Ensure the enum values are strings\n// ? P[\"required\"] extends false // Check if the parameter is optional\n// ? E | undefined // If so, include 'undefined' in the type\n// : E // Otherwise, use the enum type directly\n// : never // This case should not occur since 'enum' implies string values\n// : // Handle parameters defined as 'object' with specified attributes\n// P extends { type: \"object\"; attributes: infer Attributes }\n// ? Attributes extends Parameter[]\n// ? MappedParameterTypes<Attributes> // Recursively map the attributes of the object\n// : never // If 'attributes' is not an array of Parameters, this is invalid\n// : // Handle parameters defined as 'object[]' without specified attributes\n// P extends { type: \"object[]\"; attributes?: never }\n// ? any[] // Default to 'any[]' for arrays of objects without specific attributes\n// : // Handle parameters defined as 'object[]' with specified attributes\n// P extends { type: \"object[]\"; attributes: infer Attributes }\n// ? Attributes extends Parameter[]\n// ? MappedParameterTypes<Attributes>[] // Recursively map each object in the array\n// : any[] // Default to 'any[]' if attributes are not properly defined\n// : // Handle all other parameter types\n// P[\"required\"] extends false\n// ? // Include 'undefined' for optional parameters\n// TypeMap[P[\"type\"] extends keyof TypeMap ? P[\"type\"] : \"string\"] | undefined\n// : // Use the direct mapping from 'TypeMap' for the parameter's type\n// TypeMap[P[\"type\"] extends keyof TypeMap ? P[\"type\"] : \"string\"];\n// };\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.5.0-mme-function-call-labels.2",
7
+ "version": "0.5.0-mme-prerelease-demo.4",
8
8
  "sideEffects": false,
9
9
  "main": "./dist/index.js",
10
10
  "module": "./dist/index.mjs",
@@ -21,8 +21,8 @@
21
21
  "ts-jest": "^29.1.1",
22
22
  "tsup": "^6.7.0",
23
23
  "typescript": "^5.2.3",
24
- "eslint-config-custom": "0.6.0-mme-function-call-labels.2",
25
- "tsconfig": "0.10.0-mme-function-call-labels.2"
24
+ "eslint-config-custom": "0.6.0-mme-prerelease-demo.4",
25
+ "tsconfig": "0.10.0-mme-prerelease-demo.4"
26
26
  },
27
27
  "dependencies": {},
28
28
  "scripts": {
@@ -34,33 +34,31 @@ export type ObjectParameter = {
34
34
 
35
35
  export type Parameter = BaseParameter | StringParameter | ObjectParameter;
36
36
 
37
+ type EnumParameterType<E, Required> = E extends string
38
+ ? Required extends false
39
+ ? E | undefined
40
+ : E
41
+ : never;
42
+
43
+ type ObjectTypeParameter<Attributes> = Attributes extends Parameter[]
44
+ ? MappedParameterTypes<Attributes>
45
+ : never;
46
+
47
+ type ObjectArrayTypeParameter<Attributes> = Attributes extends Parameter[]
48
+ ? MappedParameterTypes<Attributes>[]
49
+ : any[];
50
+
51
+ type OtherParameterType<Type, Required> = Required extends false
52
+ ? TypeMap[Type extends keyof TypeMap ? Type : "string"] | undefined
53
+ : TypeMap[Type extends keyof TypeMap ? Type : "string"];
54
+
55
+ // prettier-ignore
37
56
  export type MappedParameterTypes<T extends Parameter[]> = {
38
- // Check if the parameter has an 'enum' defined
39
- [P in T[number] as P["name"]]: P extends { enum: Array<infer E> }
40
- ? E extends string // Ensure the enum values are strings
41
- ? P["required"] extends false // Check if the parameter is optional
42
- ? E | undefined // If so, include 'undefined' in the type
43
- : E // Otherwise, use the enum type directly
44
- : never // This case should not occur since 'enum' implies string values
45
- : // Handle parameters defined as 'object' with specified attributes
46
- P extends { type: "object"; attributes: infer Attributes }
47
- ? Attributes extends Parameter[]
48
- ? MappedParameterTypes<Attributes> // Recursively map the attributes of the object
49
- : never // If 'attributes' is not an array of Parameters, this is invalid
50
- : // Handle parameters defined as 'object[]' without specified attributes
51
- P extends { type: "object[]"; attributes?: never }
52
- ? any[] // Default to 'any[]' for arrays of objects without specific attributes
53
- : // Handle parameters defined as 'object[]' with specified attributes
54
- P extends { type: "object[]"; attributes: infer Attributes }
55
- ? Attributes extends Parameter[]
56
- ? MappedParameterTypes<Attributes>[] // Recursively map each object in the array
57
- : any[] // Default to 'any[]' if attributes are not properly defined
58
- : // Handle all other parameter types
59
- P["required"] extends false
60
- ? // Include 'undefined' for optional parameters
61
- TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"] | undefined
62
- : // Use the direct mapping from 'TypeMap' for the parameter's type
63
- TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"];
57
+ [P in T[number] as P["name"]]: P extends { enum: Array<infer E> } ? EnumParameterType<E, P["required"]>
58
+ : P extends { type: "object"; attributes: infer Attributes } ? ObjectTypeParameter<Attributes>
59
+ : P extends { type: "object[]"; attributes?: never } ? any[]
60
+ : P extends { type: "object[]"; attributes: infer Attributes } ? ObjectArrayTypeParameter<Attributes>
61
+ : OtherParameterType<P["type"], P["required"]>;
64
62
  };
65
63
 
66
64
  export type Action<T extends Parameter[] | [] = []> = {
@@ -71,3 +69,43 @@ export type Action<T extends Parameter[] | [] = []> = {
71
69
  ? () => any | Promise<any>
72
70
  : (args: MappedParameterTypes<T>) => any | Promise<any>;
73
71
  };
72
+
73
+ // This is the original "ceiling is being raised" version of MappedParameterTypes.
74
+ //
75
+ // ceiling is being raised. cursor's copilot helped us write "superhuman code"
76
+ // for a critical feature. We can read this code, but VERY few engineers out
77
+ // there could write it from scratch.
78
+ // Took lots of convincing too. "come on, this must be possible, try harder".
79
+ // and obviously- done in parts.
80
+ //
81
+ // - https://twitter.com/ataiiam/status/1765089261374914957
82
+ // (Mar 5, 2024)
83
+ //
84
+ // export type MappedParameterTypes<T extends Parameter[]> = {
85
+ // // Check if the parameter has an 'enum' defined
86
+ // [P in T[number] as P["name"]]: P extends { enum: Array<infer E> }
87
+ // ? E extends string // Ensure the enum values are strings
88
+ // ? P["required"] extends false // Check if the parameter is optional
89
+ // ? E | undefined // If so, include 'undefined' in the type
90
+ // : E // Otherwise, use the enum type directly
91
+ // : never // This case should not occur since 'enum' implies string values
92
+ // : // Handle parameters defined as 'object' with specified attributes
93
+ // P extends { type: "object"; attributes: infer Attributes }
94
+ // ? Attributes extends Parameter[]
95
+ // ? MappedParameterTypes<Attributes> // Recursively map the attributes of the object
96
+ // : never // If 'attributes' is not an array of Parameters, this is invalid
97
+ // : // Handle parameters defined as 'object[]' without specified attributes
98
+ // P extends { type: "object[]"; attributes?: never }
99
+ // ? any[] // Default to 'any[]' for arrays of objects without specific attributes
100
+ // : // Handle parameters defined as 'object[]' with specified attributes
101
+ // P extends { type: "object[]"; attributes: infer Attributes }
102
+ // ? Attributes extends Parameter[]
103
+ // ? MappedParameterTypes<Attributes>[] // Recursively map each object in the array
104
+ // : any[] // Default to 'any[]' if attributes are not properly defined
105
+ // : // Handle all other parameter types
106
+ // P["required"] extends false
107
+ // ? // Include 'undefined' for optional parameters
108
+ // TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"] | undefined
109
+ // : // Use the direct mapping from 'TypeMap' for the parameter's type
110
+ // TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"];
111
+ // };