@molecule/api-ai-openai 1.0.2 → 1.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EACV,UAAU,EAGV,SAAS,EAET,UAAU,EAEX,MAAM,kBAAkB,CAAA;AAGzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAc9C;;GAEG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IACjD,QAAQ,CAAC,IAAI,YAAW;IACxB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,WAAW,CAAC,CAAqB;gBAE7B,MAAM,GAAE,YAAiB;IAkBrC;;;;;OAKG;IACI,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC;IAsKzD;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,cAAc;IA+DtB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IA6BnB,uEAAuE;IACvE,OAAO,CAAC,WAAW;IAWnB;;;;;OAKG;IACH,OAAO,CAAE,yBAAyB;IA8ClC;;;;;OAKG;YACY,sBAAsB;IA4ErC;;;;;;OAMG;IACH,OAAO,CAAE,eAAe;CA0EzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,UAAU,CAEhE"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EACV,UAAU,EAGV,SAAS,EAET,UAAU,EAEX,MAAM,kBAAkB,CAAA;AAGzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAc9C;;GAEG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IACjD,QAAQ,CAAC,IAAI,YAAW;IACxB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,WAAW,CAAC,CAAqB;gBAE7B,MAAM,GAAE,YAAiB;IAqBrC;;;;;OAKG;IACI,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC;IA2KzD;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,cAAc;IA+DtB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IA6BnB,uEAAuE;IACvE,OAAO,CAAC,WAAW;IAWnB;;;;;OAKG;IACH,OAAO,CAAE,yBAAyB;IA8ClC;;;;;OAKG;YACY,sBAAsB;IA4ErC;;;;;;OAMG;IACH,OAAO,CAAE,eAAe;CA0EzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,UAAU,CAEhE"}
package/dist/provider.js CHANGED
@@ -32,8 +32,11 @@ export class OpenaiAIProvider {
32
32
  // Fail fast with an actionable local error rather than a cryptic 401 on the
33
33
  // first request. The default `provider` export constructs lazily on first
34
34
  // use (see index.ts), so this surfaces the moment the provider is actually
35
- // used, not at bond/module-load time.
36
- if (!this.apiKey) {
35
+ // used, not at bond/module-load time. A key is required only for the
36
+ // official endpoint — a custom baseUrl may target a keyless self-hosted /
37
+ // local server (Ollama, LM Studio), where the auth header is omitted below.
38
+ const usingCustomEndpoint = Boolean(config.baseUrl ?? process.env.OPENAI_BASE_URL);
39
+ if (!this.apiKey && !usingCustomEndpoint) {
37
40
  throw new Error('OPENAI_API_KEY is not set. Add it to your environment to use the OpenAI AI provider.');
38
41
  }
39
42
  }
@@ -48,6 +51,10 @@ export class OpenaiAIProvider {
48
51
  const maxTokens = params.maxTokens ?? this.maxTokens;
49
52
  const messages = this.formatMessages(params.messages, params.system);
50
53
  const body = {
54
+ // BYO / provider-native tunables (reasoning_effort, enable_thinking, …).
55
+ // Spread FIRST so the structural fields below (model, messages,
56
+ // max_completion_tokens, tools, stream) always win and cannot be broken.
57
+ ...(params.extraBody ?? {}),
51
58
  // Abuse attribution (see ChatParams.endUserId). OpenAI DEPRECATED `user`
52
59
  // and replaced it with `safety_identifier` for exactly this purpose —
53
60
  // their guidance is a hashed, stable per-user string, which is what
@@ -98,7 +105,8 @@ export class OpenaiAIProvider {
98
105
  }
99
106
  const headers = {
100
107
  'Content-Type': 'application/json',
101
- Authorization: `Bearer ${this.apiKey}`,
108
+ // Omitted for a keyless custom endpoint (a self-hosted / local server).
109
+ ...(this.apiKey ? { Authorization: `Bearer ${this.apiKey}` } : {}),
102
110
  };
103
111
  const DEFAULT_TIMEOUT_MS = 5 * 60 * 1000;
104
112
  const signal = params.signal ?? AbortSignal.timeout(DEFAULT_TIMEOUT_MS);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-ai-openai",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -32,7 +32,7 @@
32
32
  "directory": "packages/api/bonds/ai/openai"
33
33
  },
34
34
  "devDependencies": {
35
- "@molecule/api-ai": "1.0.1",
35
+ "@molecule/api-ai": "1.1.0",
36
36
  "@molecule/api-bond": "1.0.1",
37
37
  "@types/node": "26.1.2",
38
38
  "typescript": "6.0.3",