@onereach/state-machine-openai 0.0.0-stage → 1.0.0-framework.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/README.md CHANGED
@@ -1,3 +1,44 @@
1
- # Temporary Holding Version
1
+ # @onereach/state-machine-openai
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Pure adapters from state-machine functions to OpenAI function tool definitions.
4
+ No OpenAI SDK, network client, Flow SDK, runtime, or storage dependency is required.
5
+
6
+ ```ts
7
+ import {
8
+ toOpenAIChatTools,
9
+ toOpenAIResponsesTools,
10
+ } from '@onereach/state-machine-openai';
11
+
12
+ const chatTools = toOpenAIChatTools(template.functions);
13
+ const responsesTools = toOpenAIResponsesTools(template.functions);
14
+ ```
15
+
16
+ Both adapters advertise functions by default. Set
17
+ `annotations: { exposeAsTool: false }` on internal functions to exclude them.
18
+ Omission or explicit `true` includes the function. This is discovery policy, not
19
+ authorization: calls still need normal execution validation and access controls.
20
+
21
+ Chat Completions tools have `{ type: 'function', function: { ... } }` envelopes;
22
+ Responses tools have `{ type: 'function', name, ... }` envelopes. Both map only
23
+ `name`, optional `description`, and `inputSchema` (as `parameters`), and set
24
+ `strict: false` explicitly. Implementation bodies, capabilities, output schemas,
25
+ annotations, and arbitrary metadata are never advertised.
26
+
27
+ Names must contain 1–64 ASCII letters, digits, underscores, or hyphens.
28
+ Invalid or duplicate advertised names throw `TypeError`; functions are never
29
+ silently renamed or dropped. Excluded functions are not checked.
30
+
31
+ Input schemas are independently cloned on every call, not rewritten or normalized.
32
+ In particular, optional fields are not made required/nullable and object schemas
33
+ are not automatically closed. Valid framework JSON Schema does **not** guarantee
34
+ OpenAI API/model compatibility. This adapter is not a schema compiler or a
35
+ provider compatibility validator; OpenAI validates supported keywords, dialects,
36
+ references, and request limits. Use compatible, self-contained input schemas.
37
+ Strict schema conversion is not provided.
38
+
39
+ Build and test:
40
+
41
+ ```sh
42
+ pnpm exec turbo run build --filter=@onereach/state-machine-openai
43
+ pnpm --filter @onereach/state-machine-openai exec vitest run
44
+ ```
@@ -0,0 +1,37 @@
1
+ import { ReadonlyStateMachineFunctionDefinition } from "@onereach/state-machine-contracts";
2
+ //#region src/index.d.ts
3
+ /**
4
+ * Non-strict function definition shared by both OpenAI API projections.
5
+ */
6
+ interface OpenAIFunctionDefinition {
7
+ name: string;
8
+ description?: string;
9
+ parameters: Record<string, unknown>;
10
+ strict: false;
11
+ }
12
+ /**
13
+ * Function tool accepted by the Chat Completions API.
14
+ */
15
+ interface OpenAIChatTool {
16
+ type: 'function';
17
+ function: OpenAIFunctionDefinition;
18
+ }
19
+ /**
20
+ * Function tool accepted by the Responses API.
21
+ */
22
+ interface OpenAIResponsesTool extends OpenAIFunctionDefinition {
23
+ type: 'function';
24
+ }
25
+ /**
26
+ * Project eligible functions as independent Chat Completions tools without changing input schemas.
27
+ * OpenAI remains responsible for validating API/model-specific schema support.
28
+ */
29
+ declare function toOpenAIChatTools(functions: readonly ReadonlyStateMachineFunctionDefinition[]): OpenAIChatTool[];
30
+ /**
31
+ * Project eligible functions as independent Responses tools with explicit non-strict semantics.
32
+ * OpenAI remains responsible for validating API/model-specific schema support.
33
+ */
34
+ declare function toOpenAIResponsesTools(functions: readonly ReadonlyStateMachineFunctionDefinition[]): OpenAIResponsesTool[];
35
+ //#endregion
36
+ export { OpenAIChatTool, OpenAIFunctionDefinition, OpenAIResponsesTool, toOpenAIChatTools, toOpenAIResponsesTools };
37
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;UAKiB;EACf;EACA;EACA,YAAY;EACZ;;;;;UAMe;EACf;EACA,UAAU;;;;;UAMK,4BAA4B;EAC3C;;;;;;iBAmCc,kBAAkB,oBAAoB,2CAA2C;;;;;iBAQjF,uBACd,oBAAoB,2CACnB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ function e(e){let t=new Set,n=[];for(let r of e){if(r.annotations?.exposeAsTool===!1)continue;let{name:e,description:i,inputSchema:a}=r;if(!/^[a-zA-Z0-9_-]{1,64}$/u.test(e))throw TypeError(`Cannot expose function "${e}" as an OpenAI tool: expected 1–64 letters, digits, "_" or "-".`);if(t.has(e))throw TypeError(`Cannot expose duplicate OpenAI tool name "${e}".`);t.add(e);let o={name:e,parameters:structuredClone(a),strict:!1};i!==void 0&&(o.description=i),n.push(o)}return n}function t(t){return e(t).map(e=>({type:`function`,function:e}))}function n(t){return e(t).map(e=>({type:`function`,...e}))}export{t as toOpenAIChatTools,n as toOpenAIResponsesTools};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { ReadonlyStateMachineFunctionDefinition } from '@onereach/state-machine-contracts';\n\n/**\n * Non-strict function definition shared by both OpenAI API projections.\n */\nexport interface OpenAIFunctionDefinition {\n name: string;\n description?: string;\n parameters: Record<string, unknown>;\n strict: false;\n}\n\n/**\n * Function tool accepted by the Chat Completions API.\n */\nexport interface OpenAIChatTool {\n type: 'function';\n function: OpenAIFunctionDefinition;\n}\n\n/**\n * Function tool accepted by the Responses API.\n */\nexport interface OpenAIResponsesTool extends OpenAIFunctionDefinition {\n type: 'function';\n}\n\nfunction projectFunctions(functions: readonly ReadonlyStateMachineFunctionDefinition[]): OpenAIFunctionDefinition[] {\n const names = new Set<string>();\n const definitions: OpenAIFunctionDefinition[] = [];\n\n for (const definition of functions) {\n if (definition.annotations?.exposeAsTool === false) continue;\n\n const { name, description, inputSchema } = definition;\n if (!/^[a-zA-Z0-9_-]{1,64}$/u.test(name)) {\n throw new TypeError(\n `Cannot expose function \"${name}\" as an OpenAI tool: expected 1–64 letters, digits, \"_\" or \"-\".`,\n );\n }\n if (names.has(name)) throw new TypeError(`Cannot expose duplicate OpenAI tool name \"${name}\".`);\n names.add(name);\n\n const tool: OpenAIFunctionDefinition = {\n name,\n parameters: structuredClone(inputSchema),\n strict: false,\n };\n if (description !== undefined) tool.description = description;\n definitions.push(tool);\n }\n\n return definitions;\n}\n\n/**\n * Project eligible functions as independent Chat Completions tools without changing input schemas.\n * OpenAI remains responsible for validating API/model-specific schema support.\n */\nexport function toOpenAIChatTools(functions: readonly ReadonlyStateMachineFunctionDefinition[]): OpenAIChatTool[] {\n return projectFunctions(functions).map((definition) => ({ type: 'function', function: definition }));\n}\n\n/**\n * Project eligible functions as independent Responses tools with explicit non-strict semantics.\n * OpenAI remains responsible for validating API/model-specific schema support.\n */\nexport function toOpenAIResponsesTools(\n functions: readonly ReadonlyStateMachineFunctionDefinition[],\n): OpenAIResponsesTool[] {\n return projectFunctions(functions).map((definition) => ({ type: 'function', ...definition }));\n}\n"],"mappings":"AA2BA,SAAS,EAAiB,EAA0F,CAClH,IAAM,EAAQ,IAAI,IACZ,EAA0C,CAAC,EAEjD,IAAK,IAAM,KAAc,EAAW,CAClC,GAAI,EAAW,aAAa,eAAiB,GAAO,SAEpD,GAAM,CAAE,OAAM,cAAa,eAAgB,EAC3C,GAAI,CAAC,yBAAyB,KAAK,CAAI,EACrC,MAAU,UACR,2BAA2B,EAAK,gEAClC,EAEF,GAAI,EAAM,IAAI,CAAI,EAAG,MAAU,UAAU,6CAA6C,EAAK,GAAG,EAC9F,EAAM,IAAI,CAAI,EAEd,IAAM,EAAiC,CACrC,OACA,WAAY,gBAAgB,CAAW,EACvC,OAAQ,EACV,EACI,IAAgB,IAAA,KAAW,EAAK,YAAc,GAClD,EAAY,KAAK,CAAI,CACvB,CAEA,OAAO,CACT,CAMA,SAAgB,EAAkB,EAAgF,CAChH,OAAO,EAAiB,CAAS,CAAC,CAAC,IAAK,IAAgB,CAAE,KAAM,WAAY,SAAU,CAAW,EAAE,CACrG,CAMA,SAAgB,EACd,EACuB,CACvB,OAAO,EAAiB,CAAS,CAAC,CAAC,IAAK,IAAgB,CAAE,KAAM,WAAY,GAAG,CAAW,EAAE,CAC9F"}
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@onereach/state-machine-openai",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-framework.3",
4
+ "description": "Pure OpenAI tool definition adapters for State Machine functions",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "license": "Apache-2.0",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "dependencies": {
15
+ "@onereach/state-machine-contracts": "1.0.0-framework.13"
16
+ },
17
+ "devDependencies": {
18
+ "@arethetypeswrong/core": "^0.18.5",
19
+ "publint": "^0.3.24",
20
+ "tsdown": "^0.22.14",
21
+ "typescript": "^6.0.3",
22
+ "vitest": "^4.1.11"
23
+ },
24
+ "exports": {
25
+ ".": "./dist/index.mjs",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "scripts": {
29
+ "build": "tsdown --config tsdown.config.mts",
30
+ "typecheck": "tsc --noEmit --incremental --tsBuildInfoFile .cache/typecheck/source.tsbuildinfo && tsc --noEmit -p test/tsconfig.json --incremental --tsBuildInfoFile .cache/typecheck/test.tsbuildinfo",
31
+ "test": "pnpm run unit",
32
+ "unit": "vitest run",
33
+ "unit:coverage": "vitest run --coverage"
34
+ }
6
35
  }