@rcrsr/rill-ext-gemini 0.18.0 → 0.18.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/dist/index.js +55 -76
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -120,94 +120,67 @@ function buildPropertyFromStructuralType(rillType) {
|
|
|
120
120
|
return property;
|
|
121
121
|
}
|
|
122
122
|
if (rillType.kind === "dict") {
|
|
123
|
+
const dictType = rillType;
|
|
124
|
+
if (dictType.fields && Object.keys(dictType.fields).length > 0) {
|
|
125
|
+
const nested = buildDictSchema(dictType);
|
|
126
|
+
return {
|
|
127
|
+
type: "object",
|
|
128
|
+
properties: nested.properties,
|
|
129
|
+
required: nested.required,
|
|
130
|
+
additionalProperties: false
|
|
131
|
+
};
|
|
132
|
+
}
|
|
123
133
|
return { type: "object" };
|
|
124
134
|
}
|
|
125
135
|
return { type: mapRillType(rillType.kind) };
|
|
126
136
|
}
|
|
127
|
-
function
|
|
137
|
+
function buildDictSchema(dictType) {
|
|
128
138
|
const properties = {};
|
|
129
139
|
const required = [];
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const rillParam = params?.[i];
|
|
137
|
-
const property = buildPropertyFromStructuralType(paramType);
|
|
138
|
-
const description = rillParam?.annotations["description"];
|
|
139
|
-
if (typeof description === "string") {
|
|
140
|
-
property.description = description;
|
|
141
|
-
}
|
|
142
|
-
const enumAnnotation = rillParam?.annotations["enum"];
|
|
143
|
-
if (Array.isArray(enumAnnotation)) {
|
|
144
|
-
property.enum = enumAnnotation;
|
|
145
|
-
}
|
|
146
|
-
properties[paramName] = property;
|
|
147
|
-
if (rillParam === void 0 || rillParam.defaultValue === void 0) {
|
|
148
|
-
required.push(paramName);
|
|
149
|
-
}
|
|
140
|
+
const fields = dictType.fields ?? {};
|
|
141
|
+
for (const [name, fieldDef] of Object.entries(fields)) {
|
|
142
|
+
const property = buildPropertyFromStructuralType(fieldDef.type);
|
|
143
|
+
const description = fieldDef.annotations?.["description"];
|
|
144
|
+
if (typeof description === "string") {
|
|
145
|
+
property.description = description;
|
|
150
146
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
function buildJsonSchema(rillSchema) {
|
|
155
|
-
const properties = {};
|
|
156
|
-
const required = [];
|
|
157
|
-
for (const [key, value] of Object.entries(rillSchema)) {
|
|
158
|
-
if (typeof value === "string") {
|
|
159
|
-
properties[key] = buildProperty(value);
|
|
160
|
-
} else if (typeof value === "object" && value !== null) {
|
|
161
|
-
properties[key] = buildProperty(value);
|
|
162
|
-
} else {
|
|
163
|
-
throw new RuntimeError3("RILL-R004", `unsupported type: ${String(value)}`);
|
|
147
|
+
properties[name] = property;
|
|
148
|
+
if (fieldDef.defaultValue === void 0) {
|
|
149
|
+
required.push(name);
|
|
164
150
|
}
|
|
165
|
-
required.push(key);
|
|
166
151
|
}
|
|
167
152
|
return { type: "object", properties, required, additionalProperties: false };
|
|
168
153
|
}
|
|
169
|
-
function
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
return { type: jsonType2 };
|
|
173
|
-
}
|
|
174
|
-
const rillType = descriptor["type"];
|
|
175
|
-
if (typeof rillType !== "string") {
|
|
176
|
-
throw new RuntimeError3("RILL-R004", `unsupported type: ${String(rillType)}`);
|
|
154
|
+
function buildJsonSchemaFromStructuralType(type, params) {
|
|
155
|
+
if (type.kind === "dict") {
|
|
156
|
+
return buildDictSchema(type);
|
|
177
157
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const description = descriptor["description"];
|
|
181
|
-
if (typeof description === "string") {
|
|
182
|
-
property.description = description;
|
|
158
|
+
if (type.kind !== "closure") {
|
|
159
|
+
throw new RuntimeError3("RILL-R004", `unsupported schema kind: ${type.kind} (expected dict or closure)`);
|
|
183
160
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
161
|
+
const properties = {};
|
|
162
|
+
const required = [];
|
|
163
|
+
const closureParams = type.params ?? [];
|
|
164
|
+
for (let i = 0; i < closureParams.length; i++) {
|
|
165
|
+
const fieldDef = closureParams[i];
|
|
166
|
+
const paramName = fieldDef.name ?? `param${i}`;
|
|
167
|
+
const paramType = fieldDef.type;
|
|
168
|
+
const rillParam = params?.[i];
|
|
169
|
+
const property = buildPropertyFromStructuralType(paramType);
|
|
170
|
+
const description = rillParam?.annotations["description"];
|
|
171
|
+
if (typeof description === "string") {
|
|
172
|
+
property.description = description;
|
|
187
173
|
}
|
|
188
|
-
const
|
|
189
|
-
if (Array.isArray(
|
|
190
|
-
property.enum =
|
|
174
|
+
const enumAnnotation = rillParam?.annotations["enum"];
|
|
175
|
+
if (Array.isArray(enumAnnotation)) {
|
|
176
|
+
property.enum = enumAnnotation;
|
|
191
177
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (typeof items === "string") {
|
|
196
|
-
property.items = buildProperty(items);
|
|
197
|
-
} else if (typeof items === "object" && items !== null) {
|
|
198
|
-
property.items = buildProperty(items);
|
|
178
|
+
properties[paramName] = property;
|
|
179
|
+
if (rillParam === void 0 || rillParam.defaultValue === void 0) {
|
|
180
|
+
required.push(paramName);
|
|
199
181
|
}
|
|
200
182
|
}
|
|
201
|
-
|
|
202
|
-
const nestedProps = descriptor["properties"];
|
|
203
|
-
if (typeof nestedProps === "object" && nestedProps !== null) {
|
|
204
|
-
const subSchema = buildJsonSchema(nestedProps);
|
|
205
|
-
property.properties = subSchema.properties;
|
|
206
|
-
property.required = subSchema.required;
|
|
207
|
-
property.additionalProperties = false;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return property;
|
|
183
|
+
return { type: "object", properties, required, additionalProperties: false };
|
|
211
184
|
}
|
|
212
185
|
|
|
213
186
|
// ../../shared/ext-llm/dist/tool-loop.js
|
|
@@ -1460,8 +1433,8 @@ function createGeminiExtension(config) {
|
|
|
1460
1433
|
generate: {
|
|
1461
1434
|
params: [
|
|
1462
1435
|
p.str("prompt"),
|
|
1436
|
+
{ name: "schema", type: { kind: "type" }, defaultValue: void 0, annotations: { description: "Type expression for structured output schema" } },
|
|
1463
1437
|
p.dict("options", void 0, {}, {
|
|
1464
|
-
schema: { type: { kind: "dict" } },
|
|
1465
1438
|
system: { type: { kind: "string" }, defaultValue: "" },
|
|
1466
1439
|
max_tokens: { type: { kind: "number" }, defaultValue: 0 },
|
|
1467
1440
|
messages: { type: { kind: "list", element: { kind: "dict", fields: { role: { type: { kind: "string" } }, content: { type: { kind: "string" } } } } }, defaultValue: [] }
|
|
@@ -1471,15 +1444,21 @@ function createGeminiExtension(config) {
|
|
|
1471
1444
|
const startTime = Date.now();
|
|
1472
1445
|
try {
|
|
1473
1446
|
const prompt = args["prompt"];
|
|
1447
|
+
const schemaArg = args["schema"];
|
|
1474
1448
|
const options = args["options"] ?? {};
|
|
1475
|
-
if (!
|
|
1449
|
+
if (!schemaArg || !schemaArg.__rill_type || !schemaArg.structure) {
|
|
1450
|
+
throw new RuntimeError6(
|
|
1451
|
+
"RILL-R004",
|
|
1452
|
+
"generate requires a type expression as schema"
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
if (schemaArg.structure.kind !== "dict") {
|
|
1476
1456
|
throw new RuntimeError6(
|
|
1477
1457
|
"RILL-R004",
|
|
1478
|
-
|
|
1458
|
+
`generate requires a dict type as schema, got ${schemaArg.structure.kind}`
|
|
1479
1459
|
);
|
|
1480
1460
|
}
|
|
1481
|
-
const
|
|
1482
|
-
const jsonSchema = buildJsonSchema(rillSchema);
|
|
1461
|
+
const jsonSchema = buildJsonSchemaFromStructuralType(schemaArg.structure);
|
|
1483
1462
|
const geminiProperties = {};
|
|
1484
1463
|
for (const [key, prop] of Object.entries(jsonSchema.properties)) {
|
|
1485
1464
|
geminiProperties[key] = toGeminiSchema(prop);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rcrsr/rill-ext-gemini",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.3",
|
|
4
4
|
"description": "rill extension for Google Gemini API integration",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Andre Bremer",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"dts-bundle-generator": "^9.5.1",
|
|
26
26
|
"tsup": "^8.5.1",
|
|
27
27
|
"undici-types": "^7.22.0",
|
|
28
|
-
"@rcrsr/rill-ext-llm-shared": "^0.18.
|
|
28
|
+
"@rcrsr/rill-ext-llm-shared": "^0.18.3",
|
|
29
|
+
"@rcrsr/rill-ext-param-shared": "0.18.1"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
31
32
|
"dist"
|
|
@@ -43,8 +44,7 @@
|
|
|
43
44
|
"access": "public"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@google/genai": "^1.42.0"
|
|
47
|
-
"@rcrsr/rill-ext-param-shared": "0.18.0"
|
|
47
|
+
"@google/genai": "^1.42.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsup && dts-bundle-generator --config dts-bundle-generator.config.cjs",
|