@copilotkit/runtime 1.4.1-pre.1 → 1.4.1-pre.5
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/CHANGELOG.md +34 -2
- package/__snapshots__/schema/schema.graphql +8 -0
- package/dist/{chunk-U3SBKRZR.mjs → chunk-IEBJELNR.mjs} +2 -2
- package/dist/{chunk-G5X7YZNG.mjs → chunk-KYP35WVS.mjs} +2 -2
- package/dist/{chunk-IJAXWREA.mjs → chunk-QM5B7BZG.mjs} +25 -5
- package/dist/chunk-QM5B7BZG.mjs.map +1 -0
- package/dist/{chunk-YLEXEC6R.mjs → chunk-WNQJ5JZV.mjs} +2 -2
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-ZOC3UIQP.mjs} +30 -2
- package/dist/chunk-ZOC3UIQP.mjs.map +1 -0
- package/dist/{copilot-runtime-335a610d.d.ts → copilot-runtime-12e7ac40.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/{groq-adapter-b6c2b7ec.d.ts → groq-adapter-24abe931.d.ts} +1 -1
- package/dist/{index-83ee522f.d.ts → index-10b1c870.d.ts} +6 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +52 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/{langserve-cc06e76e.d.ts → langserve-f021ab9c.d.ts} +2 -1
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +52 -4
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +5 -5
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +19 -2
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.d.ts +3 -3
- package/dist/lib/integrations/nest/index.js +19 -2
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.d.ts +3 -3
- package/dist/lib/integrations/node-express/index.js +19 -2
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.d.ts +3 -3
- package/dist/lib/integrations/node-http/index.js +19 -2
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.d.ts +4 -4
- package/dist/service-adapters/index.js +29 -1
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/package.json +4 -4
- package/src/graphql/inputs/action.input.ts +4 -1
- package/src/graphql/resolvers/copilot.resolver.ts +4 -2
- package/src/graphql/types/enums.ts +11 -0
- package/src/lib/runtime/copilot-runtime.ts +5 -1
- package/src/service-adapters/langchain/utils.test.ts +169 -0
- package/src/service-adapters/langchain/utils.ts +33 -1
- package/dist/chunk-IJAXWREA.mjs.map +0 -1
- package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
- /package/dist/{chunk-U3SBKRZR.mjs.map → chunk-IEBJELNR.mjs.map} +0 -0
- /package/dist/{chunk-G5X7YZNG.mjs.map → chunk-KYP35WVS.mjs.map} +0 -0
- /package/dist/{chunk-YLEXEC6R.mjs.map → chunk-WNQJ5JZV.mjs.map} +0 -0
|
@@ -33,6 +33,7 @@ import { GraphQLContext } from "../integrations/shared";
|
|
|
33
33
|
import { AgentSessionInput } from "../../graphql/inputs/agent-session.input";
|
|
34
34
|
import { from } from "rxjs";
|
|
35
35
|
import { AgentStateInput } from "../../graphql/inputs/agent-state.input";
|
|
36
|
+
import { ActionInputAvailability } from "../../graphql/types/enums";
|
|
36
37
|
|
|
37
38
|
interface CopilotRuntimeRequest {
|
|
38
39
|
serviceAdapter: CopilotServiceAdapter;
|
|
@@ -195,7 +196,10 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
195
196
|
|
|
196
197
|
const actionInputs = flattenToolCallsNoDuplicates([
|
|
197
198
|
...serverSideActionsInput,
|
|
198
|
-
...clientSideActionsInput
|
|
199
|
+
...clientSideActionsInput.filter(
|
|
200
|
+
// Filter remote actions from CopilotKit core loop
|
|
201
|
+
(action) => action.available !== ActionInputAvailability.remote,
|
|
202
|
+
),
|
|
199
203
|
]);
|
|
200
204
|
|
|
201
205
|
await this.onBeforeRequest?.({
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { convertJsonSchemaToZodSchema } from "./utils";
|
|
3
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
4
|
+
|
|
5
|
+
describe("convertJsonSchemaToZodSchema", () => {
|
|
6
|
+
it("should convert a simple JSON schema to a Zod schema", () => {
|
|
7
|
+
const jsonSchema = {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
name: { type: "string" },
|
|
11
|
+
age: { type: "number" },
|
|
12
|
+
},
|
|
13
|
+
required: ["name", "age"],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const expectedSchema = z.object({
|
|
17
|
+
name: z.string(),
|
|
18
|
+
age: z.number(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
22
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
23
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
24
|
+
|
|
25
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should convert a JSON schema with nested objects to a Zod schema", () => {
|
|
29
|
+
const jsonSchema = {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
name: { type: "string" },
|
|
33
|
+
address: {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
street: { type: "string" },
|
|
37
|
+
city: { type: "string" },
|
|
38
|
+
},
|
|
39
|
+
required: ["street", "city"],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
required: ["name", "address"],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const expectedSchema = z.object({
|
|
46
|
+
name: z.string(),
|
|
47
|
+
address: z.object({
|
|
48
|
+
street: z.string(),
|
|
49
|
+
city: z.string(),
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
54
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
55
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
56
|
+
|
|
57
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should convert a JSON schema with arrays to a Zod schema", () => {
|
|
61
|
+
const jsonSchema = {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
names: {
|
|
65
|
+
type: "array",
|
|
66
|
+
items: { type: "string" },
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
required: ["names"],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const expectedSchema = z.object({
|
|
73
|
+
names: z.array(z.string()),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
77
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
78
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
79
|
+
|
|
80
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should convert a JSON schema with optional properties to a Zod schema", () => {
|
|
84
|
+
const jsonSchema = {
|
|
85
|
+
type: "object",
|
|
86
|
+
properties: {
|
|
87
|
+
name: { type: "string" },
|
|
88
|
+
age: { type: "number", required: false },
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const expectedSchema = z
|
|
93
|
+
.object({
|
|
94
|
+
name: z.string().optional(),
|
|
95
|
+
age: z.number().optional(),
|
|
96
|
+
})
|
|
97
|
+
.optional();
|
|
98
|
+
|
|
99
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, false);
|
|
100
|
+
|
|
101
|
+
console.log(convertJsonSchemaToZodSchema(jsonSchema, false));
|
|
102
|
+
|
|
103
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
104
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
105
|
+
|
|
106
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should convert a JSON schema with different types to a Zod schema", () => {
|
|
110
|
+
const jsonSchema = {
|
|
111
|
+
type: "object",
|
|
112
|
+
properties: {
|
|
113
|
+
name: { type: "string" },
|
|
114
|
+
age: { type: "number" },
|
|
115
|
+
isAdmin: { type: "boolean" },
|
|
116
|
+
},
|
|
117
|
+
required: ["name", "age", "isAdmin"],
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const expectedSchema = z.object({
|
|
121
|
+
name: z.string(),
|
|
122
|
+
age: z.number(),
|
|
123
|
+
isAdmin: z.boolean(),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
127
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
128
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
129
|
+
|
|
130
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("should handle edge case where JSON schema has no properties", () => {
|
|
134
|
+
const jsonSchema = {
|
|
135
|
+
type: "object",
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const expectedSchema = z.object({});
|
|
139
|
+
|
|
140
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, true);
|
|
141
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
142
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
143
|
+
|
|
144
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("should handle edge case where JSON schema has no required properties", () => {
|
|
148
|
+
const jsonSchema = {
|
|
149
|
+
type: "object",
|
|
150
|
+
properties: {
|
|
151
|
+
name: { type: "string" },
|
|
152
|
+
age: { type: "number" },
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const expectedSchema = z
|
|
157
|
+
.object({
|
|
158
|
+
name: z.string().optional(),
|
|
159
|
+
age: z.number().optional(),
|
|
160
|
+
})
|
|
161
|
+
.optional();
|
|
162
|
+
|
|
163
|
+
const result = convertJsonSchemaToZodSchema(jsonSchema, false);
|
|
164
|
+
const resultSchemaJson = zodToJsonSchema(result);
|
|
165
|
+
const expectedSchemaJson = zodToJsonSchema(expectedSchema);
|
|
166
|
+
|
|
167
|
+
expect(resultSchemaJson).toStrictEqual(expectedSchemaJson);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -18,7 +18,7 @@ import { z } from "zod";
|
|
|
18
18
|
import { ActionInput } from "../../graphql/inputs/action.input";
|
|
19
19
|
import { LangChainReturnType } from "./types";
|
|
20
20
|
import { RuntimeEventSubject } from "../events";
|
|
21
|
-
import { randomId
|
|
21
|
+
import { randomId } from "@copilotkit/shared";
|
|
22
22
|
|
|
23
23
|
export function convertMessageToLangChainMessage(message: Message): BaseMessage {
|
|
24
24
|
if (message.isTextMessage()) {
|
|
@@ -48,6 +48,38 @@ export function convertMessageToLangChainMessage(message: Message): BaseMessage
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
export function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean): z.ZodSchema {
|
|
52
|
+
if (jsonSchema.type === "object") {
|
|
53
|
+
const spec: { [key: string]: z.ZodSchema } = {};
|
|
54
|
+
|
|
55
|
+
if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
|
|
56
|
+
return !required ? z.object(spec).optional() : z.object(spec);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
60
|
+
spec[key] = convertJsonSchemaToZodSchema(
|
|
61
|
+
value,
|
|
62
|
+
jsonSchema.required ? jsonSchema.required.includes(key) : false,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
let schema = z.object(spec).describe(jsonSchema.description);
|
|
66
|
+
return required ? schema : schema.optional();
|
|
67
|
+
} else if (jsonSchema.type === "string") {
|
|
68
|
+
let schema = z.string().describe(jsonSchema.description);
|
|
69
|
+
return required ? schema : schema.optional();
|
|
70
|
+
} else if (jsonSchema.type === "number") {
|
|
71
|
+
let schema = z.number().describe(jsonSchema.description);
|
|
72
|
+
return required ? schema : schema.optional();
|
|
73
|
+
} else if (jsonSchema.type === "boolean") {
|
|
74
|
+
let schema = z.boolean().describe(jsonSchema.description);
|
|
75
|
+
return required ? schema : schema.optional();
|
|
76
|
+
} else if (jsonSchema.type === "array") {
|
|
77
|
+
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
|
|
78
|
+
let schema = z.array(itemSchema).describe(jsonSchema.description);
|
|
79
|
+
return required ? schema : schema.optional();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
51
83
|
export function convertActionInputToLangChainTool(actionInput: ActionInput): any {
|
|
52
84
|
return new DynamicStructuredTool({
|
|
53
85
|
name: actionInput.name,
|