@janole/ai-sdk-provider-codex-asp 0.3.0 → 0.3.2
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 +6 -0
- package/dist/index.cjs +43 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +43 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -152,7 +152,13 @@ See the [`examples/`](examples/) directory:
|
|
|
152
152
|
- [`cross-call-tools.ts`](examples/cross-call-tools.ts) — Standard AI SDK tools via Codex
|
|
153
153
|
- [`dynamic-tools.ts`](examples/dynamic-tools.ts) — Provider-level dynamic tools
|
|
154
154
|
- [`thread-continuation.ts`](examples/thread-continuation.ts) — Multi-turn thread resumption
|
|
155
|
+
- [`multi-step-thread.ts`](examples/multi-step-thread.ts) — Multi-step thread continuation with threadId verification
|
|
155
156
|
- [`approvals.ts`](examples/approvals.ts) — Command and file-change approval handling
|
|
157
|
+
- [`image-input.ts`](examples/image-input.ts) — Image input with `generateText`
|
|
158
|
+
- [`interrupt.ts`](examples/interrupt.ts) — Mid-turn interrupt via `onSessionCreated`
|
|
159
|
+
- [`list-models.ts`](examples/list-models.ts) — Discover available models via app-server protocol
|
|
160
|
+
- [`mid-turn-injection.ts`](examples/mid-turn-injection.ts) — Mid-turn message injection via `onSessionCreated`
|
|
161
|
+
- [`provider-executed-tools.ts`](examples/provider-executed-tools.ts) — Provider-executed tool calls (server-side commands)
|
|
156
162
|
|
|
157
163
|
Run any example with:
|
|
158
164
|
|
package/dist/index.cjs
CHANGED
|
@@ -280,6 +280,7 @@ var AppServerClient = class {
|
|
|
280
280
|
var PersistentTransport = class {
|
|
281
281
|
pool;
|
|
282
282
|
signal;
|
|
283
|
+
threadId;
|
|
283
284
|
worker = null;
|
|
284
285
|
pendingInitializeId = null;
|
|
285
286
|
initializeIntercepted = false;
|
|
@@ -289,9 +290,10 @@ var PersistentTransport = class {
|
|
|
289
290
|
constructor(settings) {
|
|
290
291
|
this.pool = settings.pool;
|
|
291
292
|
this.signal = settings.signal;
|
|
293
|
+
this.threadId = settings.threadId;
|
|
292
294
|
}
|
|
293
295
|
async connect() {
|
|
294
|
-
this.worker = await this.pool.acquire(stripUndefined({ signal: this.signal }));
|
|
296
|
+
this.worker = await this.pool.acquire(stripUndefined({ signal: this.signal, threadId: this.threadId }));
|
|
295
297
|
await this.worker.ensureConnected();
|
|
296
298
|
}
|
|
297
299
|
disconnect() {
|
|
@@ -663,6 +665,7 @@ var CodexWorker = class {
|
|
|
663
665
|
await this.inner.connect();
|
|
664
666
|
}
|
|
665
667
|
acquire() {
|
|
668
|
+
this.clearSessionListeners();
|
|
666
669
|
if (this.idleTimer) {
|
|
667
670
|
clearTimeout(this.idleTimer);
|
|
668
671
|
this.idleTimer = null;
|
|
@@ -747,8 +750,17 @@ var CodexWorkerPool = class {
|
|
|
747
750
|
if (this.shutdownCalled) {
|
|
748
751
|
throw new CodexProviderError("Worker pool has been shut down.");
|
|
749
752
|
}
|
|
753
|
+
if (options?.threadId) {
|
|
754
|
+
const reserved = this.workers.find(
|
|
755
|
+
(w) => (w.state === "idle" || w.state === "disconnected") && w.pendingToolCall?.threadId === options.threadId
|
|
756
|
+
);
|
|
757
|
+
if (reserved) {
|
|
758
|
+
reserved.acquire();
|
|
759
|
+
return reserved;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
750
762
|
const worker = this.workers.find(
|
|
751
|
-
(w) => w.state === "idle" || w.state === "disconnected"
|
|
763
|
+
(w) => (w.state === "idle" || w.state === "disconnected") && !w.pendingToolCall
|
|
752
764
|
);
|
|
753
765
|
if (!worker) {
|
|
754
766
|
if (options?.signal?.aborted) {
|
|
@@ -756,6 +768,7 @@ var CodexWorkerPool = class {
|
|
|
756
768
|
}
|
|
757
769
|
return new Promise((resolve, reject) => {
|
|
758
770
|
const waiter = {
|
|
771
|
+
threadId: options?.threadId,
|
|
759
772
|
resolve,
|
|
760
773
|
reject,
|
|
761
774
|
signal: options?.signal,
|
|
@@ -775,6 +788,16 @@ var CodexWorkerPool = class {
|
|
|
775
788
|
return worker;
|
|
776
789
|
}
|
|
777
790
|
release(worker) {
|
|
791
|
+
worker.clearSessionListeners();
|
|
792
|
+
if (worker.pendingToolCall) {
|
|
793
|
+
const idx = this.waiters.findIndex((w) => w.threadId === worker.pendingToolCall?.threadId);
|
|
794
|
+
if (idx >= 0) {
|
|
795
|
+
const [waiter2] = this.waiters.splice(idx, 1);
|
|
796
|
+
this.clearWaiterAbortHandler(waiter2);
|
|
797
|
+
waiter2.resolve(worker);
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
778
801
|
const waiter = this.waiters.shift();
|
|
779
802
|
if (waiter) {
|
|
780
803
|
this.clearWaiterAbortHandler(waiter);
|
|
@@ -935,7 +958,7 @@ var DynamicToolsDispatcher = class {
|
|
|
935
958
|
// package.json
|
|
936
959
|
var package_default = {
|
|
937
960
|
name: "@janole/ai-sdk-provider-codex-asp",
|
|
938
|
-
version: "0.3.
|
|
961
|
+
version: "0.3.2"};
|
|
939
962
|
|
|
940
963
|
// src/package-info.ts
|
|
941
964
|
var PACKAGE_NAME = package_default.name;
|
|
@@ -1770,10 +1793,11 @@ var CodexLanguageModel = class {
|
|
|
1770
1793
|
if (text.length === 0) {
|
|
1771
1794
|
return null;
|
|
1772
1795
|
}
|
|
1773
|
-
return {
|
|
1796
|
+
return stripUndefined({
|
|
1774
1797
|
type: "text",
|
|
1775
|
-
text
|
|
1776
|
-
|
|
1798
|
+
text,
|
|
1799
|
+
providerMetadata
|
|
1800
|
+
});
|
|
1777
1801
|
}).filter((part) => part !== null);
|
|
1778
1802
|
return stripUndefined({
|
|
1779
1803
|
content: [...textContent, ...passThroughContent],
|
|
@@ -1814,7 +1838,8 @@ var CodexLanguageModel = class {
|
|
|
1814
1838
|
});
|
|
1815
1839
|
}
|
|
1816
1840
|
doStream(options) {
|
|
1817
|
-
const
|
|
1841
|
+
const resumeThreadId = extractResumeThreadId(options.prompt);
|
|
1842
|
+
const transport = this.config.providerSettings.transportFactory ? this.config.providerSettings.transportFactory(options.abortSignal, resumeThreadId) : this.config.providerSettings.transport?.type === "websocket" ? new WebSocketTransport(this.config.providerSettings.transport.websocket) : new StdioTransport(this.config.providerSettings.transport?.stdio);
|
|
1818
1843
|
const packetLogger = this.config.providerSettings.debug?.logPackets === true ? this.config.providerSettings.debug.logger ?? ((packet) => {
|
|
1819
1844
|
if (packet.direction === "inbound") {
|
|
1820
1845
|
console.debug("[codex packet]", packet.message);
|
|
@@ -2017,7 +2042,6 @@ var CodexLanguageModel = class {
|
|
|
2017
2042
|
await client.request("initialize", initializeParams);
|
|
2018
2043
|
await client.notification("initialized");
|
|
2019
2044
|
debugLog?.("inbound", "prompt", options.prompt);
|
|
2020
|
-
const resumeThreadId = extractResumeThreadId(options.prompt);
|
|
2021
2045
|
debugLog?.("inbound", "extractResumeThreadId", { resumeThreadId });
|
|
2022
2046
|
const developerInstructions = mapSystemPrompt(options.prompt);
|
|
2023
2047
|
let threadId;
|
|
@@ -2232,6 +2256,12 @@ function acquirePersistentPool(settings) {
|
|
|
2232
2256
|
}
|
|
2233
2257
|
|
|
2234
2258
|
// src/provider.ts
|
|
2259
|
+
var poolHandleCleanup = new FinalizationRegistry(
|
|
2260
|
+
(handle) => {
|
|
2261
|
+
void handle.release().catch(() => {
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
);
|
|
2235
2265
|
function createNoSuchModelError(modelId, modelType) {
|
|
2236
2266
|
return new provider.NoSuchModelError({ modelId, modelType });
|
|
2237
2267
|
}
|
|
@@ -2252,7 +2282,7 @@ function createCodexAppServer(settings = {}) {
|
|
|
2252
2282
|
});
|
|
2253
2283
|
}
|
|
2254
2284
|
const persistentPool = persistentPoolHandle?.pool ?? null;
|
|
2255
|
-
const effectiveTransportFactory = persistentPool ? (signal) => new PersistentTransport(stripUndefined({ pool: persistentPool, signal })) : baseTransportFactory;
|
|
2285
|
+
const effectiveTransportFactory = persistentPool ? (signal, threadId) => new PersistentTransport(stripUndefined({ pool: persistentPool, signal, threadId })) : baseTransportFactory;
|
|
2256
2286
|
const resolvedSettings = Object.freeze(stripUndefined({
|
|
2257
2287
|
defaultModel: settings.defaultModel,
|
|
2258
2288
|
experimentalApi: settings.experimentalApi,
|
|
@@ -2329,11 +2359,15 @@ function createCodexAppServer(settings = {}) {
|
|
|
2329
2359
|
if (!persistentPoolHandle) {
|
|
2330
2360
|
return;
|
|
2331
2361
|
}
|
|
2362
|
+
poolHandleCleanup.unregister(provider);
|
|
2332
2363
|
const handle = persistentPoolHandle;
|
|
2333
2364
|
persistentPoolHandle = null;
|
|
2334
2365
|
await handle.release();
|
|
2335
2366
|
}
|
|
2336
2367
|
});
|
|
2368
|
+
if (persistentPoolHandle) {
|
|
2369
|
+
poolHandleCleanup.register(provider, persistentPoolHandle, provider);
|
|
2370
|
+
}
|
|
2337
2371
|
return provider;
|
|
2338
2372
|
}
|
|
2339
2373
|
var codexAppServer = createCodexAppServer();
|