@copilotkit/shared 0.5.0-mme-function-call-labels.2 → 0.5.0-mme-prerelease-demo.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 +12 -12
- package/CHANGELOG.md +8 -0
- package/dist/types/action.d.ts +7 -4
- package/dist/types/action.js.map +1 -1
- package/package.json +3 -3
- package/src/types/action.ts +64 -26
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @copilotkit/shared@0.5.0-mme-
|
|
2
|
+
> @copilotkit/shared@0.5.0-mme-prerelease-demo.3 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/shared
|
|
3
3
|
> tsup --clean
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m 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
|
[32mCJS[39m [1mdist/utils/decode-chat-completion.js [22m[32m4.42 KB[39m
|
|
23
23
|
[32mCJS[39m [1mdist/utils/index.js [22m[32m15.26 KB[39m
|
|
24
24
|
[32mCJS[39m [1mdist/utils/parse-chat-completion.js [22m[32m2.68 KB[39m
|
|
25
|
-
[32mCJS[39m [1mdist/utils/utils.js [22m[32m6.25 KB[39m
|
|
26
25
|
[32mCJS[39m [1mdist/utils/utils.test.js [22m[32m184.00 B[39m
|
|
26
|
+
[32mCJS[39m [1mdist/utils/utils.js [22m[32m6.25 KB[39m
|
|
27
27
|
[32mCJS[39m [1mdist/index.js.map [22m[32m30.29 KB[39m
|
|
28
28
|
[32mCJS[39m [1mdist/constants/copilot-protocol.js.map [22m[32m261.00 B[39m
|
|
29
29
|
[32mCJS[39m [1mdist/constants/index.js.map [22m[32m336.00 B[39m
|
|
30
|
-
[32mCJS[39m [1mdist/types/action.js.map [22m[
|
|
30
|
+
[32mCJS[39m [1mdist/types/action.js.map [22m[32m4.59 KB[39m
|
|
31
31
|
[32mCJS[39m [1mdist/types/annotated-function.js.map [22m[32m871.00 B[39m
|
|
32
32
|
[32mCJS[39m [1mdist/types/index.js.map [22m[32m234.00 B[39m
|
|
33
33
|
[32mCJS[39m [1mdist/types/openai-assistant.js.map [22m[32m2.86 KB[39m
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
[32mCJS[39m [1mdist/utils/decode-chat-completion.js.map [22m[32m6.89 KB[39m
|
|
37
37
|
[32mCJS[39m [1mdist/utils/index.js.map [22m[32m30.28 KB[39m
|
|
38
38
|
[32mCJS[39m [1mdist/utils/parse-chat-completion.js.map [22m[32m4.15 KB[39m
|
|
39
|
-
[32mCJS[39m [1mdist/utils/utils.js.map [22m[32m12.08 KB[39m
|
|
40
39
|
[32mCJS[39m [1mdist/utils/utils.test.js.map [22m[32m354.00 B[39m
|
|
41
|
-
[32mCJS[39m
|
|
40
|
+
[32mCJS[39m [1mdist/utils/utils.js.map [22m[32m12.08 KB[39m
|
|
41
|
+
[32mCJS[39m ⚡️ Build success in 75ms
|
|
42
42
|
[32mESM[39m [1mdist/index.mjs [22m[32m1.17 KB[39m
|
|
43
43
|
[32mESM[39m [1mdist/constants/copilot-protocol.mjs [22m[32m166.00 B[39m
|
|
44
44
|
[32mESM[39m [1mdist/types/action.mjs [22m[32m67.00 B[39m
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
[32mESM[39m [1mdist/chunk-NKEDWRKJ.mjs [22m[32m3.36 KB[39m
|
|
49
49
|
[32mESM[39m [1mdist/chunk-TYZD5BQY.mjs [22m[32m1.63 KB[39m
|
|
50
50
|
[32mESM[39m [1mdist/chunk-2C54HQBI.mjs [22m[32m4.92 KB[39m
|
|
51
|
+
[32mESM[39m [1mdist/constants/index.mjs [22m[32m187.00 B[39m
|
|
51
52
|
[32mESM[39m [1mdist/chunk-2M3YVRFS.mjs [22m[32m43.00 B[39m
|
|
52
53
|
[32mESM[39m [1mdist/chunk-3ZU7SB62.mjs [22m[32m200.00 B[39m
|
|
53
|
-
[32mESM[39m [1mdist/constants/index.mjs [22m[32m187.00 B[39m
|
|
54
54
|
[32mESM[39m [1mdist/types/annotated-function.mjs [22m[32m79.00 B[39m
|
|
55
55
|
[32mESM[39m [1mdist/types/index.mjs [22m[32m162.00 B[39m
|
|
56
56
|
[32mESM[39m [1mdist/chunk-DE5K76I2.mjs [22m[32m43.00 B[39m
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
[32mESM[39m [1mdist/utils/decode-chat-completion-as-text.mjs [22m[32m170.00 B[39m
|
|
63
63
|
[32mESM[39m [1mdist/utils/decode-chat-completion.mjs [22m[32m150.00 B[39m
|
|
64
64
|
[32mESM[39m [1mdist/utils/index.mjs [22m[32m943.00 B[39m
|
|
65
|
-
[32mESM[39m [1mdist/utils/utils.test.mjs [22m[32m170.00 B[39m
|
|
66
65
|
[32mESM[39m [1mdist/utils/parse-chat-completion.mjs [22m[32m147.00 B[39m
|
|
66
|
+
[32mESM[39m [1mdist/utils/utils.test.mjs [22m[32m170.00 B[39m
|
|
67
67
|
[32mESM[39m [1mdist/utils/utils.mjs [22m[32m439.00 B[39m
|
|
68
68
|
[32mESM[39m [1mdist/index.mjs.map [22m[32m71.00 B[39m
|
|
69
69
|
[32mESM[39m [1mdist/constants/copilot-protocol.mjs.map [22m[32m71.00 B[39m
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
[32mESM[39m [1mdist/chunk-NKEDWRKJ.mjs.map [22m[32m6.85 KB[39m
|
|
75
75
|
[32mESM[39m [1mdist/chunk-TYZD5BQY.mjs.map [22m[32m4.10 KB[39m
|
|
76
76
|
[32mESM[39m [1mdist/chunk-2C54HQBI.mjs.map [22m[32m12.00 KB[39m
|
|
77
|
+
[32mESM[39m [1mdist/constants/index.mjs.map [22m[32m71.00 B[39m
|
|
77
78
|
[32mESM[39m [1mdist/chunk-2M3YVRFS.mjs.map [22m[32m71.00 B[39m
|
|
78
79
|
[32mESM[39m [1mdist/chunk-3ZU7SB62.mjs.map [22m[32m214.00 B[39m
|
|
79
|
-
[32mESM[39m [1mdist/constants/index.mjs.map [22m[32m71.00 B[39m
|
|
80
80
|
[32mESM[39m [1mdist/types/annotated-function.mjs.map [22m[32m71.00 B[39m
|
|
81
81
|
[32mESM[39m [1mdist/types/index.mjs.map [22m[32m71.00 B[39m
|
|
82
82
|
[32mESM[39m [1mdist/chunk-DE5K76I2.mjs.map [22m[32m71.00 B[39m
|
|
@@ -88,16 +88,16 @@
|
|
|
88
88
|
[32mESM[39m [1mdist/utils/decode-chat-completion-as-text.mjs.map [22m[32m71.00 B[39m
|
|
89
89
|
[32mESM[39m [1mdist/utils/decode-chat-completion.mjs.map [22m[32m71.00 B[39m
|
|
90
90
|
[32mESM[39m [1mdist/utils/index.mjs.map [22m[32m71.00 B[39m
|
|
91
|
-
[32mESM[39m [1mdist/utils/utils.test.mjs.map [22m[32m352.00 B[39m
|
|
92
91
|
[32mESM[39m [1mdist/utils/parse-chat-completion.mjs.map [22m[32m71.00 B[39m
|
|
92
|
+
[32mESM[39m [1mdist/utils/utils.test.mjs.map [22m[32m352.00 B[39m
|
|
93
93
|
[32mESM[39m [1mdist/utils/utils.mjs.map [22m[32m71.00 B[39m
|
|
94
|
-
[32mESM[39m ⚡️ Build success in
|
|
94
|
+
[32mESM[39m ⚡️ Build success in 79ms
|
|
95
95
|
[34mDTS[39m Build start
|
|
96
|
-
[32mDTS[39m ⚡️ Build success in
|
|
96
|
+
[32mDTS[39m ⚡️ Build success in 2127ms
|
|
97
97
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.25 KB[39m
|
|
98
98
|
[32mDTS[39m [1mdist/types/openai-assistant.d.ts [22m[32m2.79 KB[39m
|
|
99
99
|
[32mDTS[39m [1mdist/types/annotated-function.d.ts [22m[32m766.00 B[39m
|
|
100
|
-
[32mDTS[39m [1mdist/types/action.d.ts [22m[
|
|
100
|
+
[32mDTS[39m [1mdist/types/action.d.ts [22m[32m2.09 KB[39m
|
|
101
101
|
[32mDTS[39m [1mdist/utils/utils.d.ts [22m[32m4.32 KB[39m
|
|
102
102
|
[32mDTS[39m [1mdist/utils/parse-chat-completion.d.ts [22m[32m805.00 B[39m
|
|
103
103
|
[32mDTS[39m [1mdist/utils/decode-chat-completion.d.ts [22m[32m955.00 B[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @copilotkit/shared
|
|
2
2
|
|
|
3
|
+
## 0.5.0-mme-prerelease-demo.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3fbee5d: OpenAIAdapter-getter
|
|
8
|
+
- 3f5ad60: OpenAIAdapter: make openai instance gettable
|
|
9
|
+
- Pre release for demos
|
|
10
|
+
|
|
3
11
|
## 0.5.0-mme-function-call-labels.2
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/dist/types/action.d.ts
CHANGED
|
@@ -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
|
|
39
|
+
} ? EnumParameterType<E, P["required"]> : P extends {
|
|
36
40
|
type: "object";
|
|
37
41
|
attributes: infer Attributes;
|
|
38
|
-
} ?
|
|
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
|
-
} ?
|
|
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;
|
package/dist/types/action.js.map
CHANGED
|
@@ -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
|
|
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-
|
|
7
|
+
"version": "0.5.0-mme-prerelease-demo.3",
|
|
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-
|
|
25
|
-
"tsconfig": "0.10.0-mme-
|
|
24
|
+
"eslint-config-custom": "0.6.0-mme-prerelease-demo.3",
|
|
25
|
+
"tsconfig": "0.10.0-mme-prerelease-demo.3"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {},
|
|
28
28
|
"scripts": {
|
package/src/types/action.ts
CHANGED
|
@@ -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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
// };
|