Skip to content

Commit 68ecdab

Browse files
committed
fix(js): Export RessourcePartSchema through genkit-tools
1 parent cb73bb0 commit 68ecdab

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

genkit-tools/common/src/types/document.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const EmptyPartSchema = z.object({
2828
metadata: z.record(z.unknown()).optional(),
2929
custom: z.record(z.unknown()).optional(),
3030
reasoning: z.never().optional(),
31+
resource: z.never().optional(),
3132
});
3233

3334
/**
@@ -147,6 +148,20 @@ export const CustomPartSchema = EmptyPartSchema.extend({
147148
*/
148149
export type CustomPart = z.infer<typeof CustomPartSchema>;
149150

151+
/**
152+
* Zod schema of a resource part.
153+
*/
154+
export const ResourcePartSchema = EmptyPartSchema.extend({
155+
resource: z.object({
156+
uri: z.string(),
157+
}),
158+
});
159+
160+
/**
161+
* Resource part.
162+
*/
163+
export type ResourcePart = z.infer<typeof ResourcePartSchema>;
164+
150165
// Disclaimer: genkit/js/ai/document.ts defines the following schema, type pair
151166
// as PartSchema and Part, respectively. genkit-tools cannot retain those names
152167
// due to it clashing with similar schema in model.ts, and genkit-tools

genkit-tools/common/src/types/model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ import {
2323
TextPartSchema,
2424
ToolRequestPartSchema,
2525
ToolResponsePartSchema,
26+
ResourcePartSchema,
2627
type CustomPart,
2728
type DataPart,
2829
type MediaPart,
2930
type TextPart,
3031
type ToolRequestPart,
3132
type ToolResponsePart,
33+
type ResourcePart,
3234
} from './document';
3335
export {
3436
CustomPartSchema,
@@ -37,12 +39,14 @@ export {
3739
TextPartSchema,
3840
ToolRequestPartSchema,
3941
ToolResponsePartSchema,
42+
ResourcePartSchema,
4043
type CustomPart,
4144
type DataPart,
4245
type MediaPart,
4346
type TextPart,
4447
type ToolRequestPart,
4548
type ToolResponsePart,
49+
type ResourcePart,
4650
};
4751

4852
//
@@ -77,6 +81,7 @@ export const PartSchema = z.union([
7781
DataPartSchema,
7882
CustomPartSchema,
7983
ReasoningPartSchema,
84+
ResourcePartSchema
8085
]);
8186

8287
/**

genkit-tools/genkit-schema.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
},
2828
"reasoning": {
2929
"not": {}
30+
},
31+
"resource": {
32+
"not": {}
3033
}
3134
},
3235
"required": [
@@ -59,6 +62,9 @@
5962
},
6063
"reasoning": {
6164
"$ref": "#/$defs/CustomPart/properties/reasoning"
65+
},
66+
"resource": {
67+
"$ref": "#/$defs/CustomPart/properties/resource"
6268
}
6369
},
6470
"additionalProperties": false
@@ -118,6 +124,9 @@
118124
},
119125
"reasoning": {
120126
"$ref": "#/$defs/CustomPart/properties/reasoning"
127+
},
128+
"resource": {
129+
"$ref": "#/$defs/CustomPart/properties/resource"
121130
}
122131
},
123132
"required": [
@@ -166,13 +175,61 @@
166175
},
167176
"reasoning": {
168177
"type": "string"
178+
},
179+
"resource": {
180+
"$ref": "#/$defs/CustomPart/properties/resource"
169181
}
170182
},
171183
"required": [
172184
"reasoning"
173185
],
174186
"additionalProperties": false
175187
},
188+
"ResourcePart": {
189+
"type": "object",
190+
"properties": {
191+
"text": {
192+
"$ref": "#/$defs/CustomPart/properties/text"
193+
},
194+
"media": {
195+
"$ref": "#/$defs/CustomPart/properties/media"
196+
},
197+
"toolRequest": {
198+
"$ref": "#/$defs/CustomPart/properties/toolRequest"
199+
},
200+
"toolResponse": {
201+
"$ref": "#/$defs/CustomPart/properties/toolResponse"
202+
},
203+
"data": {
204+
"$ref": "#/$defs/CustomPart/properties/data"
205+
},
206+
"metadata": {
207+
"$ref": "#/$defs/CustomPart/properties/metadata"
208+
},
209+
"custom": {
210+
"$ref": "#/$defs/DataPart/properties/custom"
211+
},
212+
"reasoning": {
213+
"$ref": "#/$defs/CustomPart/properties/reasoning"
214+
},
215+
"resource": {
216+
"type": "object",
217+
"properties": {
218+
"uri": {
219+
"type": "string"
220+
}
221+
},
222+
"required": [
223+
"uri"
224+
],
225+
"additionalProperties": false
226+
}
227+
},
228+
"required": [
229+
"resource"
230+
],
231+
"additionalProperties": false
232+
},
176233
"TextPart": {
177234
"type": "object",
178235
"properties": {
@@ -199,6 +256,9 @@
199256
},
200257
"reasoning": {
201258
"$ref": "#/$defs/CustomPart/properties/reasoning"
259+
},
260+
"resource": {
261+
"$ref": "#/$defs/CustomPart/properties/resource"
202262
}
203263
},
204264
"required": [
@@ -232,6 +292,9 @@
232292
},
233293
"reasoning": {
234294
"$ref": "#/$defs/CustomPart/properties/reasoning"
295+
},
296+
"resource": {
297+
"$ref": "#/$defs/CustomPart/properties/resource"
235298
}
236299
},
237300
"required": [
@@ -281,6 +344,9 @@
281344
},
282345
"reasoning": {
283346
"$ref": "#/$defs/CustomPart/properties/reasoning"
347+
},
348+
"resource": {
349+
"$ref": "#/$defs/CustomPart/properties/resource"
284350
}
285351
},
286352
"required": [
@@ -1138,6 +1204,9 @@
11381204
},
11391205
{
11401206
"$ref": "#/$defs/ReasoningPart"
1207+
},
1208+
{
1209+
"$ref": "#/$defs/ResourcePart"
11411210
}
11421211
]
11431212
},

0 commit comments

Comments
 (0)