@rcrsr/rill-ext-openai 0.18.2 → 0.18.4
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 +8 -8
package/dist/index.js
CHANGED
|
@@ -117,94 +117,67 @@ function buildPropertyFromStructuralType(rillType) {
|
|
|
117
117
|
return property;
|
|
118
118
|
}
|
|
119
119
|
if (rillType.kind === "dict") {
|
|
120
|
+
const dictType = rillType;
|
|
121
|
+
if (dictType.fields && Object.keys(dictType.fields).length > 0) {
|
|
122
|
+
const nested = buildDictSchema(dictType);
|
|
123
|
+
return {
|
|
124
|
+
type: "object",
|
|
125
|
+
properties: nested.properties,
|
|
126
|
+
required: nested.required,
|
|
127
|
+
additionalProperties: false
|
|
128
|
+
};
|
|
129
|
+
}
|
|
120
130
|
return { type: "object" };
|
|
121
131
|
}
|
|
122
132
|
return { type: mapRillType(rillType.kind) };
|
|
123
133
|
}
|
|
124
|
-
function
|
|
134
|
+
function buildDictSchema(dictType) {
|
|
125
135
|
const properties = {};
|
|
126
136
|
const required = [];
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const rillParam = params?.[i];
|
|
134
|
-
const property = buildPropertyFromStructuralType(paramType);
|
|
135
|
-
const description = rillParam?.annotations["description"];
|
|
136
|
-
if (typeof description === "string") {
|
|
137
|
-
property.description = description;
|
|
138
|
-
}
|
|
139
|
-
const enumAnnotation = rillParam?.annotations["enum"];
|
|
140
|
-
if (Array.isArray(enumAnnotation)) {
|
|
141
|
-
property.enum = enumAnnotation;
|
|
142
|
-
}
|
|
143
|
-
properties[paramName] = property;
|
|
144
|
-
if (rillParam === void 0 || rillParam.defaultValue === void 0) {
|
|
145
|
-
required.push(paramName);
|
|
146
|
-
}
|
|
137
|
+
const fields = dictType.fields ?? {};
|
|
138
|
+
for (const [name, fieldDef] of Object.entries(fields)) {
|
|
139
|
+
const property = buildPropertyFromStructuralType(fieldDef.type);
|
|
140
|
+
const description = fieldDef.annotations?.["description"];
|
|
141
|
+
if (typeof description === "string") {
|
|
142
|
+
property.description = description;
|
|
147
143
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
function buildJsonSchema(rillSchema) {
|
|
152
|
-
const properties = {};
|
|
153
|
-
const required = [];
|
|
154
|
-
for (const [key, value] of Object.entries(rillSchema)) {
|
|
155
|
-
if (typeof value === "string") {
|
|
156
|
-
properties[key] = buildProperty(value);
|
|
157
|
-
} else if (typeof value === "object" && value !== null) {
|
|
158
|
-
properties[key] = buildProperty(value);
|
|
159
|
-
} else {
|
|
160
|
-
throw new RuntimeError3("RILL-R004", `unsupported type: ${String(value)}`);
|
|
144
|
+
properties[name] = property;
|
|
145
|
+
if (fieldDef.defaultValue === void 0) {
|
|
146
|
+
required.push(name);
|
|
161
147
|
}
|
|
162
|
-
required.push(key);
|
|
163
148
|
}
|
|
164
149
|
return { type: "object", properties, required, additionalProperties: false };
|
|
165
150
|
}
|
|
166
|
-
function
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
return { type: jsonType2 };
|
|
170
|
-
}
|
|
171
|
-
const rillType = descriptor["type"];
|
|
172
|
-
if (typeof rillType !== "string") {
|
|
173
|
-
throw new RuntimeError3("RILL-R004", `unsupported type: ${String(rillType)}`);
|
|
151
|
+
function buildJsonSchemaFromStructuralType(type, params) {
|
|
152
|
+
if (type.kind === "dict") {
|
|
153
|
+
return buildDictSchema(type);
|
|
174
154
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const description = descriptor["description"];
|
|
178
|
-
if (typeof description === "string") {
|
|
179
|
-
property.description = description;
|
|
155
|
+
if (type.kind !== "closure") {
|
|
156
|
+
throw new RuntimeError3("RILL-R004", `unsupported schema kind: ${type.kind} (expected dict or closure)`);
|
|
180
157
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
158
|
+
const properties = {};
|
|
159
|
+
const required = [];
|
|
160
|
+
const closureParams = type.params ?? [];
|
|
161
|
+
for (let i = 0; i < closureParams.length; i++) {
|
|
162
|
+
const fieldDef = closureParams[i];
|
|
163
|
+
const paramName = fieldDef.name ?? `param${i}`;
|
|
164
|
+
const paramType = fieldDef.type;
|
|
165
|
+
const rillParam = params?.[i];
|
|
166
|
+
const property = buildPropertyFromStructuralType(paramType);
|
|
167
|
+
const description = rillParam?.annotations["description"];
|
|
168
|
+
if (typeof description === "string") {
|
|
169
|
+
property.description = description;
|
|
184
170
|
}
|
|
185
|
-
const
|
|
186
|
-
if (Array.isArray(
|
|
187
|
-
property.enum =
|
|
171
|
+
const enumAnnotation = rillParam?.annotations["enum"];
|
|
172
|
+
if (Array.isArray(enumAnnotation)) {
|
|
173
|
+
property.enum = enumAnnotation;
|
|
188
174
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (typeof items === "string") {
|
|
193
|
-
property.items = buildProperty(items);
|
|
194
|
-
} else if (typeof items === "object" && items !== null) {
|
|
195
|
-
property.items = buildProperty(items);
|
|
175
|
+
properties[paramName] = property;
|
|
176
|
+
if (rillParam === void 0 || rillParam.defaultValue === void 0) {
|
|
177
|
+
required.push(paramName);
|
|
196
178
|
}
|
|
197
179
|
}
|
|
198
|
-
|
|
199
|
-
const nestedProps = descriptor["properties"];
|
|
200
|
-
if (typeof nestedProps === "object" && nestedProps !== null) {
|
|
201
|
-
const subSchema = buildJsonSchema(nestedProps);
|
|
202
|
-
property.properties = subSchema.properties;
|
|
203
|
-
property.required = subSchema.required;
|
|
204
|
-
property.additionalProperties = false;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return property;
|
|
180
|
+
return { type: "object", properties, required, additionalProperties: false };
|
|
208
181
|
}
|
|
209
182
|
|
|
210
183
|
// ../../shared/ext-llm/dist/tool-loop.js
|
|
@@ -1399,8 +1372,8 @@ function createOpenAIExtension(config) {
|
|
|
1399
1372
|
generate: {
|
|
1400
1373
|
params: [
|
|
1401
1374
|
p.str("prompt"),
|
|
1375
|
+
{ name: "schema", type: { kind: "type" }, defaultValue: void 0, annotations: { description: "Type expression for structured output schema" } },
|
|
1402
1376
|
p.dict("options", void 0, {}, {
|
|
1403
|
-
schema: { type: { kind: "dict" } },
|
|
1404
1377
|
system: { type: { kind: "string" }, defaultValue: "" },
|
|
1405
1378
|
max_tokens: { type: { kind: "number" }, defaultValue: 0 },
|
|
1406
1379
|
messages: { type: { kind: "list", element: { kind: "dict", fields: { role: { type: { kind: "string" } }, content: { type: { kind: "string" } } } } }, defaultValue: [] }
|
|
@@ -1410,15 +1383,21 @@ function createOpenAIExtension(config) {
|
|
|
1410
1383
|
const startTime = Date.now();
|
|
1411
1384
|
try {
|
|
1412
1385
|
const prompt = args["prompt"];
|
|
1386
|
+
const schemaArg = args["schema"];
|
|
1413
1387
|
const options = args["options"] ?? {};
|
|
1414
|
-
if (!
|
|
1388
|
+
if (!schemaArg || !schemaArg.__rill_type || !schemaArg.structure) {
|
|
1389
|
+
throw new RuntimeError6(
|
|
1390
|
+
"RILL-R004",
|
|
1391
|
+
"generate requires a type expression as schema"
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
if (schemaArg.structure.kind !== "dict") {
|
|
1415
1395
|
throw new RuntimeError6(
|
|
1416
1396
|
"RILL-R004",
|
|
1417
|
-
|
|
1397
|
+
`generate requires a dict type as schema, got ${schemaArg.structure.kind}`
|
|
1418
1398
|
);
|
|
1419
1399
|
}
|
|
1420
|
-
const
|
|
1421
|
-
const jsonSchema = buildJsonSchema(rillSchema);
|
|
1400
|
+
const jsonSchema = buildJsonSchemaFromStructuralType(schemaArg.structure);
|
|
1422
1401
|
const system = typeof options["system"] === "string" ? options["system"] : factorySystem;
|
|
1423
1402
|
const maxTokens = typeof options["max_tokens"] === "number" && options["max_tokens"] > 0 ? options["max_tokens"] : factoryMaxTokens;
|
|
1424
1403
|
const apiMessages = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rcrsr/rill-ext-openai",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.4",
|
|
4
4
|
"description": "rill extension for OpenAI API integration",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Andre Bremer",
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"scripting"
|
|
18
18
|
],
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@rcrsr/rill": "~0.18.
|
|
20
|
+
"@rcrsr/rill": "~0.18.4"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@rcrsr/rill": "~0.18.
|
|
24
|
-
"@types/node": "^25.
|
|
23
|
+
"@rcrsr/rill": "~0.18.4",
|
|
24
|
+
"@types/node": "^25.5.2",
|
|
25
25
|
"dts-bundle-generator": "^9.5.1",
|
|
26
26
|
"tsup": "^8.5.1",
|
|
27
|
-
"undici-types": "^
|
|
28
|
-
"@rcrsr/rill-ext-llm-shared": "^0.18.
|
|
29
|
-
"@rcrsr/rill-ext-param-shared": "0.18.
|
|
27
|
+
"undici-types": "^8.0.2",
|
|
28
|
+
"@rcrsr/rill-ext-llm-shared": "^0.18.4",
|
|
29
|
+
"@rcrsr/rill-ext-param-shared": "0.18.4"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"dist"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"openai": "^6.
|
|
47
|
+
"openai": "^6.33.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsup && dts-bundle-generator --config dts-bundle-generator.config.cjs",
|