purra-openai 0.5.1 → 1.0.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/chat.d.ts CHANGED
@@ -14,6 +14,7 @@ export declare class OpenAIChatCompletionsGateway implements ModelGateway {
14
14
  #private;
15
15
  readonly capabilities: ModelCapabilitySnapshot;
16
16
  constructor(options: OpenAIChatCompletionsOptions);
17
+ validateOutputContract(request: ModelRequest): string | undefined;
17
18
  invoke(request: ModelRequest, signal?: AbortSignal): Promise<ModelTurn>;
18
19
  stream(request: ModelRequest, signal?: AbortSignal): Promise<ModelStream>;
19
20
  }
package/dist/chat.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { validateOutput } from "./structured.js";
1
2
  import OpenAI from "openai";
2
3
  import { AgentCanceledError, AgentError } from "purra";
3
4
  function text(value) {
@@ -64,11 +65,18 @@ export class OpenAIChatCompletionsGateway {
64
65
  this.#options = { ...options };
65
66
  this.#client = (options.client ?? new OpenAI()).withOptions({ maxRetries: 0, timeout: options.timeoutMs ?? 60000 });
66
67
  }
68
+ validateOutputContract(request) {
69
+ return validateOutput(request, this.capabilities);
70
+ }
67
71
  #request(request) {
72
+ this.validateOutputContract(request);
68
73
  if (!request.outputBudget)
69
74
  throw new TypeError("OpenAI gateway requires a resolved generation budget");
70
75
  const o = this.#options;
71
76
  return { model: o.model, messages: messages(request.messages), store: false, max_completion_tokens: request.outputBudget.maxGenerationTokens,
77
+ ...(request.outputContract?.mode === "native_required" ? { response_format: { type: "json_schema", json_schema: {
78
+ name: "purra_output", strict: true, schema: JSON.parse(JSON.stringify(request.outputContract.schema)),
79
+ } } } : {}),
72
80
  ...(o.reasoningEffort === undefined ? {} : { reasoning_effort: o.reasoningEffort }),
73
81
  ...(o.temperature === undefined ? {} : { temperature: o.temperature }),
74
82
  ...(o.topP === undefined ? {} : { top_p: o.topP }),
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export declare class OpenAIResponsesGateway implements ModelGateway {
16
16
  #private;
17
17
  readonly capabilities: ModelCapabilitySnapshot;
18
18
  constructor(options: OpenAIResponsesOptions);
19
+ validateOutputContract(request: ModelRequest): string | undefined;
19
20
  invoke(request: ModelRequest, signal?: AbortSignal): Promise<ModelTurn>;
20
21
  stream(request: ModelRequest, signal?: AbortSignal): Promise<ModelStream>;
21
22
  }
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { validateOutput } from "./structured.js";
1
2
  import OpenAI from "openai";
2
3
  export { OpenAIChatCompletionsGateway } from "./chat.js";
3
4
  import { AgentCanceledError, AgentError } from "purra";
@@ -77,7 +78,11 @@ export class OpenAIResponsesGateway {
77
78
  this.#reasoning = options.reasoning;
78
79
  this.#client = (options.client ?? new OpenAI()).withOptions({ maxRetries: 0, timeout: options.timeoutMs ?? 60000 });
79
80
  }
81
+ validateOutputContract(request) {
82
+ return validateOutput(request, this.capabilities);
83
+ }
80
84
  #request(request) {
85
+ this.validateOutputContract(request);
81
86
  if (!request.outputBudget)
82
87
  throw new TypeError("OpenAI gateway requires a resolved generation budget");
83
88
  return { model: this.#model, input: input(request.messages), store: false, include: ["reasoning.encrypted_content"],
@@ -85,6 +90,9 @@ export class OpenAIResponsesGateway {
85
90
  tools: request.tools.map(t => ({ type: "function", name: t.name, description: t.description,
86
91
  parameters: JSON.parse(JSON.stringify(t.inputSchema)), strict: false })),
87
92
  tool_choice: request.tools.length ? "auto" : "none",
93
+ ...(request.outputContract?.mode === "native_required" ? { text: { format: {
94
+ type: "json_schema", name: "purra_output", strict: true, schema: JSON.parse(JSON.stringify(request.outputContract.schema)),
95
+ } } } : {}),
88
96
  ...(this.#reasoning === undefined ? {} : { reasoning: this.#reasoning }), };
89
97
  }
90
98
  async invoke(request, signal) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "purra-openai",
3
- "version": "0.5.1",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Official OpenAI Responses and Chat Completions SDK adapter for PurrA",
@@ -20,7 +20,7 @@
20
20
  "openai": "7.9.0"
21
21
  },
22
22
  "peerDependencies": {
23
- "purra": "0.5.1"
23
+ "purra": "1.0.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "purra": "file:../../../typescript",