@core-ai/openai-compat 0.14.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Omnifact (https://omnifact.ai)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # @core-ai/openai-compat
2
+
3
+ OpenAI-compatible Chat Completions provider for `@core-ai/core-ai`.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @core-ai/core-ai @core-ai/openai-compat zod
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { generate } from '@core-ai/core-ai';
15
+ import { createOpenAICompat } from '@core-ai/openai-compat';
16
+
17
+ const provider = createOpenAICompat({
18
+ apiKey: process.env.API_KEY,
19
+ baseURL: 'https://gateway.example.com/v1',
20
+ });
21
+
22
+ const result = await generate({
23
+ model: provider.chatModel('qwen3-235b'),
24
+ messages: [{ role: 'user', content: 'Hello!' }],
25
+ });
26
+
27
+ console.log(result.content);
28
+ ```
29
+
30
+ Known OpenAI models map `maxTokens` to the parameter required by Chat
31
+ Completions. Unknown model IDs default to `max_tokens`. Set a provider-wide
32
+ compatibility default when an endpoint requires `max_completion_tokens`:
33
+
34
+ ```ts
35
+ const provider = createOpenAICompat({
36
+ apiKey: process.env.API_KEY,
37
+ baseURL: 'https://gateway.example.com/v1',
38
+ maxTokensParameter: 'max_completion_tokens',
39
+ });
40
+
41
+ await generate({
42
+ model: provider.chatModel('custom-reasoning-model'),
43
+ messages: [{ role: 'user', content: 'Hello!' }],
44
+ maxTokens: 1024,
45
+ });
46
+ ```
47
+
48
+ This provider only exposes Chat Completions models. It accepts known
49
+ nonstandard response fields used by OpenAI-compatible gateways, including
50
+ `reasoning_content` and `reasoning`. Set `reasoning: false` when those fields
51
+ should not be interpreted as reasoning output.
52
+
53
+ Structured output uses a forced function tool by default for broad endpoint
54
+ compatibility. If the endpoint supports strict JSON Schema response formats,
55
+ opt in with `structuredOutputMode: 'native'`:
56
+
57
+ ```ts
58
+ const provider = createOpenAICompat({
59
+ apiKey: process.env.API_KEY,
60
+ baseURL: 'https://gateway.example.com/v1',
61
+ structuredOutputMode: 'native',
62
+ });
63
+ ```
@@ -0,0 +1,23 @@
1
+ import { ChatModel } from '@core-ai/core-ai';
2
+ import { OpenAIProviderBaseOptions, OpenAIStructuredOutputMode, OpenAICompatibilityOptions } from '@core-ai/openai';
3
+
4
+ type OpenAICompatProviderOptions = OpenAIProviderBaseOptions & {
5
+ /** Whether to extract nonstandard reasoning response fields. Defaults to `true`. */
6
+ reasoning?: boolean;
7
+ /**
8
+ * Structured output transport. Defaults to `tool` for broad compatibility.
9
+ * Use `native` when the endpoint supports strict JSON Schema response formats.
10
+ */
11
+ structuredOutputMode?: OpenAIStructuredOutputMode;
12
+ /**
13
+ * Request parameter used for `maxTokens`. When unset, known OpenAI models
14
+ * use their registered capability and unknown models use `max_tokens`.
15
+ */
16
+ maxTokensParameter?: OpenAICompatibilityOptions['maxTokensParameter'];
17
+ };
18
+ type OpenAICompatProvider = {
19
+ chatModel(modelId: string): ChatModel;
20
+ };
21
+ declare function createOpenAICompat(options?: OpenAICompatProviderOptions): OpenAICompatProvider;
22
+
23
+ export { type OpenAICompatProvider, type OpenAICompatProviderOptions, createOpenAICompat };
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ // src/provider.ts
2
+ import {
3
+ createOpenAIProvider
4
+ } from "@core-ai/openai";
5
+ function createOpenAICompat(options = {}) {
6
+ const provider = createOpenAIProvider(options, {
7
+ providerId: "openai-compat",
8
+ defaultApi: "chat-completions",
9
+ compatibility: {
10
+ reasoning: options.reasoning,
11
+ structuredOutputMode: options.structuredOutputMode,
12
+ maxTokensParameter: options.maxTokensParameter
13
+ }
14
+ });
15
+ return {
16
+ chatModel: provider.chatModel
17
+ };
18
+ }
19
+ export {
20
+ createOpenAICompat
21
+ };
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@core-ai/openai-compat",
3
+ "version": "0.14.0",
4
+ "description": "OpenAI-compatible Chat Completions provider for @core-ai/core-ai",
5
+ "license": "MIT",
6
+ "author": "Omnifact (https://omnifact.ai)",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/agdevhq/core-ai.git",
10
+ "directory": "packages/openai-compat"
11
+ },
12
+ "keywords": [
13
+ "llm",
14
+ "ai",
15
+ "openai",
16
+ "openai-compatible",
17
+ "provider",
18
+ "sdk"
19
+ ],
20
+ "type": "module",
21
+ "main": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js",
27
+ "require": "./dist/index.js",
28
+ "default": "./dist/index.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "provenance": true
39
+ },
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "lint": "eslint src/ --max-warnings 0",
43
+ "check-types": "tsc --noEmit",
44
+ "test": "vitest run",
45
+ "test:watch": "vitest"
46
+ },
47
+ "dependencies": {
48
+ "@core-ai/core-ai": "^0.14.0",
49
+ "@core-ai/openai": "^0.14.0"
50
+ },
51
+ "peerDependencies": {
52
+ "zod": "^4.0.0"
53
+ },
54
+ "devDependencies": {
55
+ "@core-ai/eslint-config": "*",
56
+ "@core-ai/testing": "*",
57
+ "@core-ai/typescript-config": "*",
58
+ "typescript": "^5.7.3",
59
+ "vitest": "^3.2.4"
60
+ }
61
+ }