@rcrsr/rill-ext-gemini 0.18.1 → 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.
Files changed (2) hide show
  1. package/dist/index.js +55 -76
  2. package/package.json +2 -2
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 buildJsonSchemaFromStructuralType(type, params) {
137
+ function buildDictSchema(dictType) {
128
138
  const properties = {};
129
139
  const required = [];
130
- if (type.kind === "closure") {
131
- const closureParams = type.params ?? [];
132
- for (let i = 0; i < closureParams.length; i++) {
133
- const fieldDef = closureParams[i];
134
- const paramName = fieldDef.name ?? `param${i}`;
135
- const paramType = fieldDef.type;
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
- return { type: "object", properties, required, additionalProperties: false };
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 buildProperty(descriptor) {
170
- if (typeof descriptor === "string") {
171
- const jsonType2 = mapRillType(descriptor);
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
- const jsonType = mapRillType(rillType);
179
- const property = { type: jsonType };
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
- if ("enum" in descriptor) {
185
- if (rillType !== "string") {
186
- throw new RuntimeError3("RILL-R004", "enum is only valid for string type");
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 enumValues = descriptor["enum"];
189
- if (Array.isArray(enumValues)) {
190
- property.enum = enumValues;
174
+ const enumAnnotation = rillParam?.annotations["enum"];
175
+ if (Array.isArray(enumAnnotation)) {
176
+ property.enum = enumAnnotation;
191
177
  }
192
- }
193
- if (rillType === "list" && "items" in descriptor) {
194
- const items = descriptor["items"];
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
- if (rillType === "dict" && "properties" in descriptor) {
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 (!("schema" in options) || options["schema"] === null || options["schema"] === void 0) {
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
- "generate requires 'schema' option"
1458
+ `generate requires a dict type as schema, got ${schemaArg.structure.kind}`
1479
1459
  );
1480
1460
  }
1481
- const rillSchema = options["schema"];
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.1",
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,7 @@
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.1",
28
+ "@rcrsr/rill-ext-llm-shared": "^0.18.3",
29
29
  "@rcrsr/rill-ext-param-shared": "0.18.1"
30
30
  },
31
31
  "files": [