Skip to content

Commit 22a04f5

Browse files
committed
chore(build): fix adapter compilation
Fixed TypeScript issues uncovered while running npm run build --workspace <pkg> for core, codex-adapter, claude-adapter, and gemini-adapter. Added proper send callback types in the Codex worker, restored the Claude tsconfig base reference, tightened Claude adapter types (permission mode + prompt conversion), and added Node-readable guards for Gemini stream teardown so all four packages build cleanly.
1 parent 783f494 commit 22a04f5

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

packages/claude-adapter/src/index.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
* @fileoverview Claude Agent SDK adapter implementing the HeadlessCoder interface.
33
*/
44

5-
import { query, type SDKMessage, type Options, type Query as ClaudeQuery } from '@anthropic-ai/claude-agent-sdk';
5+
import {
6+
query,
7+
type SDKMessage,
8+
type Options,
9+
type Query as ClaudeQuery,
10+
type PermissionMode,
11+
} from '@anthropic-ai/claude-agent-sdk';
612
import { randomUUID } from 'node:crypto';
713
import { now } from '@headless-coder-sdk/core';
814
import type {
@@ -152,6 +158,8 @@ export class ClaudeAdapter implements HeadlessCoder {
152158
private buildOptions(state: ClaudeThreadState, runOpts?: RunOpts): Options {
153159
const startOpts = state.opts ?? {};
154160
const resumeId = state.resume ? state.sessionId : undefined;
161+
const permissionMode: PermissionMode | undefined =
162+
(startOpts.permissionMode as PermissionMode | undefined) ?? (startOpts.yolo ? 'bypassPermissions' : undefined);
155163
return {
156164
cwd: startOpts.workingDirectory,
157165
allowedTools: startOpts.allowedTools,
@@ -161,7 +169,7 @@ export class ClaudeAdapter implements HeadlessCoder {
161169
forkSession: startOpts.forkSession,
162170
includePartialMessages: !!runOpts?.streamPartialMessages,
163171
model: startOpts.model,
164-
permissionMode: startOpts.permissionMode ?? (startOpts.yolo ? 'bypassPermissions' : undefined),
172+
permissionMode,
165173
permissionPromptToolName: startOpts.permissionPromptToolName,
166174
};
167175
}
@@ -184,8 +192,9 @@ export class ClaudeAdapter implements HeadlessCoder {
184192
const state = thread.internal as ClaudeThreadState;
185193
this.assertIdle(state);
186194
const structuredPrompt = applyOutputSchemaPrompt(toPrompt(input), runOpts?.outputSchema);
195+
const prompt = toPrompt(structuredPrompt);
187196
const options = this.buildOptions(state, runOpts);
188-
const generator = query({ prompt: structuredPrompt, options });
197+
const generator = query({ prompt, options });
189198
const active = this.registerRun(state, generator, runOpts?.signal);
190199
let lastAssistant = '';
191200
let finalResult: any;
@@ -250,8 +259,9 @@ export class ClaudeAdapter implements HeadlessCoder {
250259
const state = thread.internal as ClaudeThreadState;
251260
this.assertIdle(state);
252261
const structuredPrompt = applyOutputSchemaPrompt(toPrompt(input), runOpts?.outputSchema);
262+
const prompt = toPrompt(structuredPrompt);
253263
const options = this.buildOptions(state, runOpts);
254-
const generator = query({ prompt: structuredPrompt, options });
264+
const generator = query({ prompt, options });
255265
const adapter = this;
256266

257267
return {

packages/claude-adapter/tsconfig.build.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"rootDir": "src"
5+
"declaration": true,
6+
"emitDeclarationOnly": false,
7+
"sourceMap": false
68
},
7-
"include": ["src"]
9+
"include": ["src/**/*"],
10+
"exclude": ["node_modules", "dist", "tests"]
811
}

packages/codex-adapter/src/worker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ function emit(message: WorkerOutboundMessage): void {
8888
async function emitAndWait(message: WorkerOutboundMessage): Promise<void> {
8989
if (typeof process.send !== 'function') return;
9090
await new Promise<void>((resolve, reject) => {
91-
process.send!(message, err => {
92-
if (err) reject(err);
93-
else resolve();
91+
process.send!(message, undefined, undefined, (err: Error | null) => {
92+
if (err) {
93+
reject(err);
94+
} else {
95+
resolve();
96+
}
9497
});
9598
});
9699
}

packages/gemini-adapter/src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,18 @@ function destroyChildStreams(child: ChildProcess): void {
614614
destroyReadable(child.stderr);
615615
}
616616

617+
type DestroyableReadable = NodeJS.ReadableStream & {
618+
destroyed?: boolean;
619+
destroy?: () => void;
620+
};
621+
617622
function destroyReadable(stream?: NodeJS.ReadableStream | null): void {
618623
if (!stream) return;
619-
stream.removeAllListeners();
620-
if (stream.destroyed) return;
624+
const destroyable = stream as DestroyableReadable;
625+
destroyable.removeAllListeners();
626+
if (destroyable.destroyed) return;
621627
try {
622-
stream.destroy();
628+
destroyable.destroy?.();
623629
} catch {
624630
// ignore
625631
}

0 commit comments

Comments
 (0)