@janole/ai-sdk-provider-codex-asp 0.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.
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/dist/index.cjs +1559 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +672 -0
- package/dist/index.d.ts +672 -0
- package/dist/index.js +1535 -0
- package/dist/index.js.map +1 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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,164 @@
|
|
|
1
|
+
# @janole/ai-sdk-provider-codex-asp
|
|
2
|
+
|
|
3
|
+
`@janole/ai-sdk-provider-codex-asp` is a [Vercel AI SDK](https://ai-sdk.dev/) v6 custom provider for the Codex App Server Protocol.
|
|
4
|
+
|
|
5
|
+
Status: POC feature-complete for language model usage.
|
|
6
|
+
|
|
7
|
+
- `LanguageModelV3` provider implementation
|
|
8
|
+
- Streaming (`streamText`) and non-streaming (`generateText`)
|
|
9
|
+
- Standard AI SDK `tool()` support via Codex dynamic tools injection
|
|
10
|
+
- `stdio` and `websocket` transports
|
|
11
|
+
- Persistent worker pool with thread management
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @janole/ai-sdk-provider-codex-asp ai
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### 1. Non-streaming (`generateText`)
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { generateText } from 'ai';
|
|
25
|
+
import { createCodexAppServer } from '@janole/ai-sdk-provider-codex-asp';
|
|
26
|
+
|
|
27
|
+
const codex = createCodexAppServer({
|
|
28
|
+
defaultModel: 'gpt-5.3-codex',
|
|
29
|
+
clientInfo: { name: 'my-app', version: '0.1.0' },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const result = await generateText({
|
|
33
|
+
model: codex.languageModel('gpt-5.3-codex'),
|
|
34
|
+
prompt: 'Write a short release note title for websocket support.',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
console.log(result.text);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Streaming (`streamText`)
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { streamText } from 'ai';
|
|
44
|
+
import { createCodexAppServer } from '@janole/ai-sdk-provider-codex-asp';
|
|
45
|
+
|
|
46
|
+
const codex = createCodexAppServer({
|
|
47
|
+
defaultModel: 'gpt-5.3-codex',
|
|
48
|
+
clientInfo: { name: 'my-app', version: '0.1.0' },
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const result = streamText({
|
|
52
|
+
model: codex('gpt-5.3-codex'),
|
|
53
|
+
prompt: 'Explain JSON-RPC in one paragraph.',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
for await (const chunk of result.textStream) {
|
|
57
|
+
process.stdout.write(chunk);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Tools
|
|
62
|
+
|
|
63
|
+
Use standard AI SDK `tool()` definitions — the provider automatically injects them into Codex as dynamic tools and routes results back. No Codex-specific API needed.
|
|
64
|
+
|
|
65
|
+
Requires a persistent transport so tool results can be fed back within the same session:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { stepCountIs, streamText, tool } from 'ai';
|
|
69
|
+
import { z } from 'zod';
|
|
70
|
+
import { createCodexAppServer } from '@janole/ai-sdk-provider-codex-asp';
|
|
71
|
+
|
|
72
|
+
const codex = createCodexAppServer({
|
|
73
|
+
persistent: { scope: 'global', poolSize: 1, idleTimeoutMs: 60_000 },
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const result = streamText({
|
|
77
|
+
model: codex('gpt-5.3-codex'),
|
|
78
|
+
prompt: 'Can you check ticket 15 and also the weather in Berlin?',
|
|
79
|
+
tools: {
|
|
80
|
+
lookup_ticket: tool({
|
|
81
|
+
description: 'Look up the current status of a support ticket by its ID.',
|
|
82
|
+
inputSchema: z.object({
|
|
83
|
+
id: z.string().describe('The ticket ID, e.g. "TICK-42".'),
|
|
84
|
+
}),
|
|
85
|
+
execute: async ({ id }) => `Ticket ${id} is open and assigned to team Alpha.`,
|
|
86
|
+
}),
|
|
87
|
+
check_weather: tool({
|
|
88
|
+
description: 'Get the current weather for a given location.',
|
|
89
|
+
inputSchema: z.object({
|
|
90
|
+
location: z.string().describe('City name or coordinates.'),
|
|
91
|
+
}),
|
|
92
|
+
execute: async ({ location }) => `Weather in ${location}: 22°C, sunny`,
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
stopWhen: stepCountIs(5),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
for await (const chunk of result.textStream) {
|
|
99
|
+
process.stdout.write(chunk);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
await codex.shutdown();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## API Reference
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const codex = createCodexAppServer({
|
|
109
|
+
defaultModel?: string,
|
|
110
|
+
clientInfo?: { name, version, title? }, // defaults to package.json
|
|
111
|
+
transport?: { type: 'stdio' | 'websocket', stdio?, websocket? },
|
|
112
|
+
persistent?: { poolSize?, idleTimeoutMs?, scope?, key? },
|
|
113
|
+
defaultThreadSettings?: { cwd?, approvalMode?, sandboxMode? },
|
|
114
|
+
approvals?: { onCommandApproval?, onFileChangeApproval? },
|
|
115
|
+
toolTimeoutMs?: number, // default: 30000
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
codex(modelId) // returns a language model instance
|
|
119
|
+
codex.languageModel(modelId) // explicit alias
|
|
120
|
+
codex.chat(modelId) // explicit alias
|
|
121
|
+
codex.shutdown() // clean up persistent workers
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
See [`src/provider.ts`](src/provider.ts) for full type definitions.
|
|
125
|
+
|
|
126
|
+
## Examples
|
|
127
|
+
|
|
128
|
+
See the [`examples/`](examples/) directory:
|
|
129
|
+
|
|
130
|
+
- [`generate-text.ts`](examples/generate-text.ts) — Non-streaming text generation
|
|
131
|
+
- [`stream-text.ts`](examples/stream-text.ts) — Streaming text generation
|
|
132
|
+
- [`cross-call-tools.ts`](examples/cross-call-tools.ts) — Standard AI SDK tools via Codex
|
|
133
|
+
- [`dynamic-tools.ts`](examples/dynamic-tools.ts) — Provider-level dynamic tools
|
|
134
|
+
- [`thread-continuation.ts`](examples/thread-continuation.ts) — Multi-turn thread resumption
|
|
135
|
+
- [`approvals.ts`](examples/approvals.ts) — Command and file-change approval handling
|
|
136
|
+
|
|
137
|
+
Run any example with:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npx tsx examples/stream-text.ts
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Troubleshooting
|
|
144
|
+
|
|
145
|
+
- `No such file or command: codex`:
|
|
146
|
+
- Install Codex CLI and ensure `codex` is in `PATH`.
|
|
147
|
+
- `WebSocket is not available in this runtime`:
|
|
148
|
+
- Use Node.js 18+ with global WebSocket support, or use `stdio` transport.
|
|
149
|
+
- Request timeouts:
|
|
150
|
+
- Increase `toolTimeoutMs` for long-running dynamic tools.
|
|
151
|
+
- Empty generated text:
|
|
152
|
+
- Verify Codex emits `item/agentMessage/delta` and `turn/completed` notifications.
|
|
153
|
+
|
|
154
|
+
## Development
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
npm install
|
|
158
|
+
npm run build # ESM + CJS + .d.ts via tsup
|
|
159
|
+
npm run qa # lint + typecheck + test (all-in-one)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT
|