@rcrsr/rill-ext-openai 0.11.0 → 0.16.0

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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- import { ExtensionConfigSchema, ExtensionResult } from '@rcrsr/rill';
3
+ import { ExtensionConfigSchema, ExtensionManifest, ExtensionResult } from '@rcrsr/rill';
4
4
 
5
5
  /**
6
6
  * Base configuration for LLM extensions
@@ -73,8 +73,9 @@ export type OpenAIExtensionConfig = LLMProviderConfig;
73
73
  * ```
74
74
  */
75
75
  export declare function createOpenAIExtension(config: OpenAIExtensionConfig): ExtensionResult;
76
- export declare const VERSION = "0.0.1";
76
+ export declare const VERSION: string;
77
77
  export declare const configSchema: ExtensionConfigSchema;
78
+ export declare const extensionManifest: ExtensionManifest;
78
79
 
79
80
  export {
80
81
  LLMProviderConfig as LLMExtensionConfig,
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ // src/index.ts
2
+ import { createRequire } from "module";
3
+
1
4
  // src/factory.ts
2
5
  import OpenAI from "openai";
3
6
  import {
@@ -5,7 +8,8 @@ import {
5
8
  emitExtensionEvent,
6
9
  createVector,
7
10
  isDict as isDict2,
8
- isVector
11
+ isVector,
12
+ rillTypeToTypeValue
9
13
  } from "@rcrsr/rill";
10
14
 
11
15
  // ../../shared/ext-llm/dist/validation.js
@@ -121,7 +125,9 @@ function buildJsonSchemaFromStructuralType(type, params) {
121
125
  if (type.type === "closure") {
122
126
  const closureParams = type.params ?? [];
123
127
  for (let i = 0; i < closureParams.length; i++) {
124
- const [paramName, paramType] = closureParams[i];
128
+ const fieldDef = closureParams[i];
129
+ const paramName = fieldDef.name ?? `param${i}`;
130
+ const paramType = fieldDef.type;
125
131
  const rillParam = params?.[i];
126
132
  const property = buildPropertyFromStructuralType(paramType);
127
133
  const description = rillParam?.annotations["description"];
@@ -220,21 +226,20 @@ async function executeToolCall(toolName, toolInput, tools, context) {
220
226
  throw new RuntimeError4("RILL-R004", `Invalid tool input for ${toolName}: tool must be application, runtime, or script callable`);
221
227
  }
222
228
  try {
223
- let args;
224
- if ((callable.kind === "application" || callable.kind === "script") && callable.params && callable.params.length > 0) {
225
- const params = callable.params;
226
- const inputDict = toolInput;
227
- args = params.map((param) => {
228
- const value = inputDict[param.name];
229
- return value !== void 0 ? value : void 0;
230
- });
231
- } else {
232
- args = [toolInput];
233
- }
229
+ const inputDict = toolInput;
234
230
  if (callable.kind === "script") {
235
231
  if (!context) {
236
232
  throw new RuntimeError4("RILL-R004", `Invalid tool input for ${toolName}: script callable requires a runtime context`);
237
233
  }
234
+ let args;
235
+ if (callable.params && callable.params.length > 0) {
236
+ args = callable.params.map((param) => {
237
+ const value = inputDict[param.name];
238
+ return value !== void 0 ? value : void 0;
239
+ });
240
+ } else {
241
+ args = [inputDict];
242
+ }
238
243
  return await invokeCallable(callable, args, context);
239
244
  }
240
245
  const ctx = context ?? {
@@ -242,7 +247,7 @@ async function executeToolCall(toolName, toolInput, tools, context) {
242
247
  variables: /* @__PURE__ */ new Map(),
243
248
  pipeValue: null
244
249
  };
245
- const result = callable.fn(args, ctx);
250
+ const result = callable.fn(inputDict, ctx);
246
251
  return result instanceof Promise ? await result : result;
247
252
  } catch (error) {
248
253
  if (error instanceof RuntimeError4) {
@@ -335,18 +340,13 @@ async function executeToolLoop(messages, tools, maxErrors, callbacks, emitEvent,
335
340
  throw new RuntimeError4("RILL-R004", `tool_loop: tool "${name}" is not a callable`);
336
341
  }
337
342
  const callable = fnValue;
338
- let description;
339
- if (callable.kind === "script") {
340
- description = callable.annotations["description"] ?? "";
341
- } else {
342
- description = callable.description ?? "";
343
- }
343
+ const description = callable.annotations?.["description"] ?? "";
344
344
  let inputSchema;
345
345
  const params = callable.kind === "application" ? callable.params ?? [] : callable.kind === "script" ? callable.params : [];
346
346
  if (params.length > 0) {
347
347
  const closureType = {
348
348
  type: "closure",
349
- params: params.map((p2) => [p2.name, p2.type ?? { type: "any" }])
349
+ params: params.map((p2) => ({ name: p2.name, type: p2.type ?? { type: "any" } }))
350
350
  };
351
351
  const builtSchema = buildJsonSchemaFromStructuralType(closureType, [...params]);
352
352
  inputSchema = {
@@ -545,13 +545,15 @@ var p = {
545
545
  * @param name - Parameter name (must be a valid identifier)
546
546
  * @param desc - Optional description
547
547
  * @param def - Optional default value
548
- * @returns RillParam with type 'dict'
548
+ * @param fields - Optional structural field definitions (RillFieldDef with type and optional defaultValue)
549
+ * @returns RillParam with type 'dict' (with fields if provided)
549
550
  */
550
- dict(name, desc, def) {
551
+ dict(name, desc, def, fields) {
551
552
  validateParamName(name);
553
+ const type = fields !== void 0 ? { type: "dict", fields } : { type: "dict" };
552
554
  return {
553
555
  name,
554
- type: { type: "dict" },
556
+ type,
555
557
  defaultValue: def,
556
558
  annotations: buildAnnotations(desc)
557
559
  };
@@ -641,13 +643,16 @@ function createOpenAIExtension(config) {
641
643
  message: {
642
644
  params: [
643
645
  p.str("text"),
644
- p.dict("options", void 0, {})
646
+ p.dict("options", void 0, {}, {
647
+ system: { type: { type: "string" }, defaultValue: "" },
648
+ max_tokens: { type: { type: "number" }, defaultValue: 0 }
649
+ })
645
650
  ],
646
651
  fn: async (args, ctx) => {
647
652
  const startTime = Date.now();
648
653
  try {
649
- const text = args[0];
650
- const options = args[1] ?? {};
654
+ const text = args["text"];
655
+ const options = args["options"] ?? {};
651
656
  if (text.trim().length === 0) {
652
657
  throw new RuntimeError6("RILL-R004", "prompt text cannot be empty");
653
658
  }
@@ -716,20 +721,33 @@ function createOpenAIExtension(config) {
716
721
  throw rillError;
717
722
  }
718
723
  },
719
- description: "Send single message to OpenAI API",
720
- returnType: { type: "dict" }
724
+ annotations: { description: "Send single message to OpenAI API" },
725
+ returnType: rillTypeToTypeValue({
726
+ type: "dict",
727
+ fields: {
728
+ content: { type: { type: "string" } },
729
+ model: { type: { type: "string" } },
730
+ usage: { type: { type: "dict", fields: { input: { type: { type: "number" } }, output: { type: { type: "number" } } } } },
731
+ stop_reason: { type: { type: "string" } },
732
+ id: { type: { type: "string" } },
733
+ messages: { type: { type: "list", element: { type: "dict" } } }
734
+ }
735
+ })
721
736
  },
722
737
  // IR-5: openai::messages
723
738
  messages: {
724
739
  params: [
725
- p.list("messages"),
726
- p.dict("options", void 0, {})
740
+ p.list("messages", { type: "dict", fields: { role: { type: { type: "string" } }, content: { type: { type: "string" } } } }),
741
+ p.dict("options", void 0, {}, {
742
+ system: { type: { type: "string" }, defaultValue: "" },
743
+ max_tokens: { type: { type: "number" }, defaultValue: 0 }
744
+ })
727
745
  ],
728
746
  fn: async (args, ctx) => {
729
747
  const startTime = Date.now();
730
748
  try {
731
- const messages = args[0];
732
- const options = args[1] ?? {};
749
+ const messages = args["messages"];
750
+ const options = args["options"] ?? {};
733
751
  if (messages.length === 0) {
734
752
  throw new RuntimeError6(
735
753
  "RILL-R004",
@@ -842,8 +860,18 @@ function createOpenAIExtension(config) {
842
860
  throw rillError;
843
861
  }
844
862
  },
845
- description: "Send multi-turn conversation to OpenAI API",
846
- returnType: { type: "dict" }
863
+ annotations: { description: "Send multi-turn conversation to OpenAI API" },
864
+ returnType: rillTypeToTypeValue({
865
+ type: "dict",
866
+ fields: {
867
+ content: { type: { type: "string" } },
868
+ model: { type: { type: "string" } },
869
+ usage: { type: { type: "dict", fields: { input: { type: { type: "number" } }, output: { type: { type: "number" } } } } },
870
+ stop_reason: { type: { type: "string" } },
871
+ id: { type: { type: "string" } },
872
+ messages: { type: { type: "list", element: { type: "dict" } } }
873
+ }
874
+ })
847
875
  },
848
876
  // IR-6: openai::embed
849
877
  embed: {
@@ -851,7 +879,7 @@ function createOpenAIExtension(config) {
851
879
  fn: async (args, ctx) => {
852
880
  const startTime = Date.now();
853
881
  try {
854
- const text = args[0];
882
+ const text = args["text"];
855
883
  validateEmbedText(text.trim());
856
884
  validateEmbedModel(factoryEmbedModel);
857
885
  const response = await client.embeddings.create({
@@ -893,8 +921,8 @@ function createOpenAIExtension(config) {
893
921
  throw rillError;
894
922
  }
895
923
  },
896
- description: "Generate embedding vector for text",
897
- returnType: { type: "vector" }
924
+ annotations: { description: "Generate embedding vector for text" },
925
+ returnType: rillTypeToTypeValue({ type: "vector" })
898
926
  },
899
927
  // IR-7: openai::embed_batch
900
928
  embed_batch: {
@@ -902,7 +930,7 @@ function createOpenAIExtension(config) {
902
930
  fn: async (args, ctx) => {
903
931
  const startTime = Date.now();
904
932
  try {
905
- const texts = args[0];
933
+ const texts = args["texts"];
906
934
  if (texts.length === 0) {
907
935
  return [];
908
936
  }
@@ -954,20 +982,27 @@ function createOpenAIExtension(config) {
954
982
  throw rillError;
955
983
  }
956
984
  },
957
- description: "Generate embedding vectors for multiple texts",
958
- returnType: { type: "list" }
985
+ annotations: { description: "Generate embedding vectors for multiple texts" },
986
+ returnType: rillTypeToTypeValue({ type: "list", element: { type: "vector" } })
959
987
  },
960
988
  // IR-8: openai::tool_loop
961
989
  tool_loop: {
962
990
  params: [
963
991
  p.str("prompt"),
964
- p.dict("options", void 0, {})
992
+ p.dict("options", void 0, {}, {
993
+ tools: { type: { type: "dict" } },
994
+ system: { type: { type: "string" }, defaultValue: "" },
995
+ max_tokens: { type: { type: "number" }, defaultValue: 0 },
996
+ max_errors: { type: { type: "number" }, defaultValue: 3 },
997
+ max_turns: { type: { type: "number" }, defaultValue: 10 },
998
+ messages: { type: { type: "list", element: { type: "dict", fields: { role: { type: { type: "string" } }, content: { type: { type: "string" } } } } }, defaultValue: [] }
999
+ })
965
1000
  ],
966
1001
  fn: async (args, ctx) => {
967
1002
  const startTime = Date.now();
968
1003
  try {
969
- const prompt = args[0];
970
- const options = args[1] ?? {};
1004
+ const prompt = args["prompt"];
1005
+ const options = args["options"] ?? {};
971
1006
  if (prompt.trim().length === 0) {
972
1007
  throw new RuntimeError6("RILL-R004", "prompt text cannot be empty");
973
1008
  }
@@ -1195,20 +1230,35 @@ function createOpenAIExtension(config) {
1195
1230
  throw rillError;
1196
1231
  }
1197
1232
  },
1198
- description: "Execute tool-use loop with OpenAI API",
1199
- returnType: { type: "dict" }
1233
+ annotations: { description: "Execute tool-use loop with OpenAI API" },
1234
+ returnType: rillTypeToTypeValue({
1235
+ type: "dict",
1236
+ fields: {
1237
+ content: { type: { type: "string" } },
1238
+ model: { type: { type: "string" } },
1239
+ usage: { type: { type: "dict", fields: { input: { type: { type: "number" } }, output: { type: { type: "number" } } } } },
1240
+ stop_reason: { type: { type: "string" } },
1241
+ turns: { type: { type: "number" } },
1242
+ messages: { type: { type: "list", element: { type: "dict" } } }
1243
+ }
1244
+ })
1200
1245
  },
1201
1246
  // IR-3: openai::generate
1202
1247
  generate: {
1203
1248
  params: [
1204
1249
  p.str("prompt"),
1205
- p.dict("options")
1250
+ p.dict("options", void 0, {}, {
1251
+ schema: { type: { type: "dict" } },
1252
+ system: { type: { type: "string" }, defaultValue: "" },
1253
+ max_tokens: { type: { type: "number" }, defaultValue: 0 },
1254
+ messages: { type: { type: "list", element: { type: "dict", fields: { role: { type: { type: "string" } }, content: { type: { type: "string" } } } } }, defaultValue: [] }
1255
+ })
1206
1256
  ],
1207
1257
  fn: async (args, ctx) => {
1208
1258
  const startTime = Date.now();
1209
1259
  try {
1210
- const prompt = args[0];
1211
- const options = args[1] ?? {};
1260
+ const prompt = args["prompt"];
1261
+ const options = args["options"] ?? {};
1212
1262
  if (!("schema" in options) || options["schema"] === null || options["schema"] === void 0) {
1213
1263
  throw new RuntimeError6(
1214
1264
  "RILL-R004",
@@ -1314,8 +1364,18 @@ function createOpenAIExtension(config) {
1314
1364
  throw rillError;
1315
1365
  }
1316
1366
  },
1317
- description: "Generate structured output from OpenAI API",
1318
- returnType: { type: "dict" }
1367
+ annotations: { description: "Generate structured output from OpenAI API" },
1368
+ returnType: rillTypeToTypeValue({
1369
+ type: "dict",
1370
+ fields: {
1371
+ data: { type: { type: "any" } },
1372
+ raw: { type: { type: "string" } },
1373
+ model: { type: { type: "string" } },
1374
+ usage: { type: { type: "dict", fields: { input: { type: { type: "number" } }, output: { type: { type: "number" } } } } },
1375
+ stop_reason: { type: { type: "string" } },
1376
+ id: { type: { type: "string" } }
1377
+ }
1378
+ })
1319
1379
  }
1320
1380
  };
1321
1381
  result.dispose = dispose;
@@ -1323,7 +1383,9 @@ function createOpenAIExtension(config) {
1323
1383
  }
1324
1384
 
1325
1385
  // src/index.ts
1326
- var VERSION = "0.0.1";
1386
+ var _require = createRequire(import.meta.url);
1387
+ var _pkg = _require("../package.json");
1388
+ var VERSION = _pkg.version;
1327
1389
  var configSchema = {
1328
1390
  api_key: { type: "string", required: true, secret: true },
1329
1391
  model: { type: "string", required: true },
@@ -1335,8 +1397,14 @@ var configSchema = {
1335
1397
  system: { type: "string" },
1336
1398
  embed_model: { type: "string" }
1337
1399
  };
1400
+ var extensionManifest = {
1401
+ factory: createOpenAIExtension,
1402
+ configSchema,
1403
+ version: VERSION
1404
+ };
1338
1405
  export {
1339
1406
  VERSION,
1340
1407
  configSchema,
1341
- createOpenAIExtension
1408
+ createOpenAIExtension,
1409
+ extensionManifest
1342
1410
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rcrsr/rill-ext-openai",
3
- "version": "0.11.0",
3
+ "version": "0.16.0",
4
4
  "description": "rill extension for OpenAI API integration",
5
5
  "license": "MIT",
6
6
  "author": "Andre Bremer",
@@ -17,10 +17,10 @@
17
17
  "scripting"
18
18
  ],
19
19
  "peerDependencies": {
20
- "@rcrsr/rill": "^0.11.0"
20
+ "@rcrsr/rill": "~0.16.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@rcrsr/rill": "^0.11.0",
23
+ "@rcrsr/rill": "~0.16.0",
24
24
  "@types/node": "^25.3.0",
25
25
  "dts-bundle-generator": "^9.5.1",
26
26
  "tsup": "^8.5.1",