coding-agents-sdk 0.0.1 → 0.3.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/README.md +274 -0
- package/dist/SdkAgent-a97nkDuR.mjs +1 -0
- package/dist/adapters/claude-code-cli/index.d.mts +2 -0
- package/dist/adapters/claude-code-cli/index.mjs +2 -0
- package/dist/adapters/claude-code-sdk/index.d.mts +2 -0
- package/dist/adapters/claude-code-sdk/index.mjs +4 -0
- package/dist/adapters/codex-cli/index.d.mts +2 -0
- package/dist/adapters/codex-cli/index.mjs +2 -0
- package/dist/adapters/codex-sdk/index.d.mts +2 -0
- package/dist/adapters/codex-sdk/index.mjs +1 -0
- package/dist/adapters/gemini-cli/index.d.mts +2 -0
- package/dist/adapters/gemini-cli/index.mjs +1 -0
- package/dist/classify-error-V6x6jP_R.mjs +8 -0
- package/dist/container/index.d.mts +2 -0
- package/dist/container/index.mjs +1 -0
- package/dist/container-BY7JDOGo.mjs +1 -0
- package/dist/container-DWTITDhL.mjs +1 -0
- package/dist/container-vkn5-3Xl.mjs +1 -0
- package/dist/diff-BCfLDXNN.mjs +1 -0
- package/dist/env-Dkd8Sgjf.mjs +1 -0
- package/dist/errors-XV0frS3r.mjs +1 -0
- package/dist/events-D31_b0sA.d.mts +239 -0
- package/dist/execution-target-BJ5mWjDM.mjs +4 -0
- package/dist/index-COHwWTg_.d.mts +315 -0
- package/dist/index-CzvanLE_.d.mts +46 -0
- package/dist/index-DCaZeLrI.d.mts +51 -0
- package/dist/index-DNyKelMh.d.mts +39 -0
- package/dist/index-DP4Jxoax.d.mts +110 -0
- package/dist/index-R77YR8ak.d.mts +224 -0
- package/dist/index-jUwKDQ34.d.mts +146 -0
- package/dist/index.d.mts +17 -0
- package/dist/index.mjs +1 -0
- package/dist/oci-C_S_FKHj.mjs +1 -0
- package/dist/sandbox/index.d.mts +2 -0
- package/dist/sandbox/index.mjs +1 -0
- package/dist/sandbox-DeKpyenZ.mjs +1 -0
- package/dist/schemas/index.d.mts +2 -0
- package/dist/schemas/index.mjs +1 -0
- package/dist/schemas-BM6qORw3.mjs +1 -0
- package/dist/spawner-BJesLc8I.mjs +1 -0
- package/dist/structured-output-DEkBQ-1Z.mjs +1 -0
- package/dist/types-COlDAzs5.d.mts +162 -0
- package/dist/types-CwvWHEpy.mjs +1 -0
- package/dist/util-CGg8cK92.mjs +1 -0
- package/package.json +90 -9
- package/index.js +0 -7
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { t as AgentEvent, v as AgentCapabilities, x as JsonSchema, y as ContentPart } from "./events-D31_b0sA.mjs";
|
|
2
|
+
import { ZodType } from "zod/v4";
|
|
3
|
+
|
|
4
|
+
//#region src/core/process/types.d.ts
|
|
5
|
+
type StdioOption = "ignore" | "inherit" | "pipe" | number;
|
|
6
|
+
type ProcessSignal = NodeJS.Signals;
|
|
7
|
+
interface SpawnOptions {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
env?: Record<string, string>;
|
|
10
|
+
stdio?: [StdioOption, StdioOption, StdioOption];
|
|
11
|
+
}
|
|
12
|
+
interface ProcessResult {
|
|
13
|
+
exitCode: number | null;
|
|
14
|
+
signal: ProcessSignal | null;
|
|
15
|
+
}
|
|
16
|
+
interface AgentProcess {
|
|
17
|
+
stdout: AsyncIterable<Uint8Array> | null;
|
|
18
|
+
stderr: AsyncIterable<Uint8Array> | null;
|
|
19
|
+
stdin: {
|
|
20
|
+
write?: (chunk: Uint8Array | string) => void;
|
|
21
|
+
end: () => void;
|
|
22
|
+
} | null;
|
|
23
|
+
kill: (signal?: ProcessSignal | number) => void;
|
|
24
|
+
wait: () => Promise<ProcessResult>;
|
|
25
|
+
}
|
|
26
|
+
interface ProcessSpawner {
|
|
27
|
+
spawn: (command: string, args: string[], options?: SpawnOptions) => AgentProcess;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/core/agent/types.d.ts
|
|
31
|
+
type AgentType = "claude-code-cli" | "claude-code-sdk" | "codex-cli" | "codex-sdk" | "gemini-cli";
|
|
32
|
+
type RunStatus = "cancelled" | "completed" | "failed";
|
|
33
|
+
type StopReason = "abort" | "timeout" | "user";
|
|
34
|
+
interface RunStats {
|
|
35
|
+
durationMs?: number;
|
|
36
|
+
apiDurationMs?: number;
|
|
37
|
+
turns: number;
|
|
38
|
+
costUsd: number;
|
|
39
|
+
inputTokens?: number;
|
|
40
|
+
cacheCreationInputTokens?: number;
|
|
41
|
+
cacheReadInputTokens?: number;
|
|
42
|
+
outputTokens?: number;
|
|
43
|
+
totalTokens?: number;
|
|
44
|
+
}
|
|
45
|
+
interface RunError {
|
|
46
|
+
kind: "abort" | "parse" | "process" | "provider" | "spawn";
|
|
47
|
+
message: string;
|
|
48
|
+
}
|
|
49
|
+
interface RunRequest {
|
|
50
|
+
input: ContentPart[] | string;
|
|
51
|
+
cwd?: string;
|
|
52
|
+
model?: string;
|
|
53
|
+
systemPrompt?: string;
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}
|
|
57
|
+
interface JsonSchemaRunRequest extends RunRequest {
|
|
58
|
+
schema: JsonSchema;
|
|
59
|
+
}
|
|
60
|
+
interface ZodRunRequest<TOutput = unknown> extends RunRequest {
|
|
61
|
+
schema: ZodType<TOutput>;
|
|
62
|
+
}
|
|
63
|
+
type StructuredRunRequest<TOutput = unknown> = JsonSchemaRunRequest | ZodRunRequest<TOutput>;
|
|
64
|
+
type AnyRunRequest = RunRequest | StructuredRunRequest;
|
|
65
|
+
interface RunTiming {
|
|
66
|
+
startedAt: Date;
|
|
67
|
+
endedAt: Date;
|
|
68
|
+
durationMs: number;
|
|
69
|
+
}
|
|
70
|
+
interface RunProcessInfo {
|
|
71
|
+
exitCode: number | null;
|
|
72
|
+
signal: ProcessSignal | null;
|
|
73
|
+
stderr: string;
|
|
74
|
+
}
|
|
75
|
+
interface RunResultBase {
|
|
76
|
+
type: AgentType;
|
|
77
|
+
runId: string;
|
|
78
|
+
sessionId?: string;
|
|
79
|
+
text: string;
|
|
80
|
+
events: readonly AgentEvent[];
|
|
81
|
+
stats?: RunStats;
|
|
82
|
+
timing: RunTiming;
|
|
83
|
+
process?: RunProcessInfo;
|
|
84
|
+
}
|
|
85
|
+
interface CancelledRunResult extends RunResultBase {
|
|
86
|
+
status: "cancelled";
|
|
87
|
+
output?: undefined;
|
|
88
|
+
error: RunError;
|
|
89
|
+
cancelReason: StopReason;
|
|
90
|
+
}
|
|
91
|
+
interface FailedRunResult extends RunResultBase {
|
|
92
|
+
status: "failed";
|
|
93
|
+
output?: undefined;
|
|
94
|
+
error: RunError;
|
|
95
|
+
cancelReason?: undefined;
|
|
96
|
+
}
|
|
97
|
+
type CompletedRunResult<TOutput = never> = RunResultBase & ([TOutput] extends [never] ? {} : {
|
|
98
|
+
output: TOutput;
|
|
99
|
+
}) & {
|
|
100
|
+
status: "completed";
|
|
101
|
+
error?: undefined;
|
|
102
|
+
cancelReason?: undefined;
|
|
103
|
+
};
|
|
104
|
+
type RunResult<TOutput = never> = CancelledRunResult | CompletedRunResult<TOutput> | FailedRunResult;
|
|
105
|
+
type AnyRunResult = RunResult | RunResult<unknown>;
|
|
106
|
+
type AnyCompletedRunResult = CompletedRunResult | CompletedRunResult<unknown>;
|
|
107
|
+
type AgentRun<TRunOptions extends object = {}> = {
|
|
108
|
+
<TOutput>(request: TRunOptions & ZodRunRequest<TOutput>): Promise<RunResult<TOutput>>;
|
|
109
|
+
(request: JsonSchemaRunRequest & TRunOptions): Promise<RunResult<unknown>>;
|
|
110
|
+
(request: RunRequest & TRunOptions): Promise<RunResult>;
|
|
111
|
+
};
|
|
112
|
+
type AgentRunOrThrow<TRunOptions extends object = {}> = {
|
|
113
|
+
<TOutput>(request: TRunOptions & ZodRunRequest<TOutput>): Promise<CompletedRunResult<TOutput>>;
|
|
114
|
+
(request: JsonSchemaRunRequest & TRunOptions): Promise<CompletedRunResult<unknown>>;
|
|
115
|
+
(request: RunRequest & TRunOptions): Promise<CompletedRunResult>;
|
|
116
|
+
};
|
|
117
|
+
declare class AgentRunError<TOutput = never> extends Error {
|
|
118
|
+
readonly result: RunResult<TOutput> & {
|
|
119
|
+
status: "cancelled" | "failed";
|
|
120
|
+
};
|
|
121
|
+
constructor(result: RunResult<TOutput> & {
|
|
122
|
+
status: "cancelled" | "failed";
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
declare class AgentValidationError extends Error {
|
|
126
|
+
constructor(message: string);
|
|
127
|
+
}
|
|
128
|
+
type AgentEventHandler = (event: AgentEvent) => void;
|
|
129
|
+
interface AgentMetrics {
|
|
130
|
+
runCount: number;
|
|
131
|
+
messagesReceived: number;
|
|
132
|
+
toolCalls: number;
|
|
133
|
+
errors: number;
|
|
134
|
+
startedAt: Date;
|
|
135
|
+
lastActivityAt: Date;
|
|
136
|
+
}
|
|
137
|
+
type EffectiveKeys<T> = keyof { [K in keyof T as Required<T>[K] extends never ? never : K]: unknown };
|
|
138
|
+
type EnsureDisjoint<T extends object> = EffectiveKeys<T> & keyof RunRequest extends never ? T : never;
|
|
139
|
+
type ExclusiveExecutionTargetOptions<TContainer, TSandbox> = {
|
|
140
|
+
container?: never;
|
|
141
|
+
sandbox?: TSandbox;
|
|
142
|
+
} | {
|
|
143
|
+
container?: TContainer;
|
|
144
|
+
sandbox?: never;
|
|
145
|
+
};
|
|
146
|
+
interface BaseAgent<TRunOptions extends object = {}> {
|
|
147
|
+
readonly type: AgentType;
|
|
148
|
+
readonly capabilities: Readonly<AgentCapabilities>;
|
|
149
|
+
readonly sessionId?: string;
|
|
150
|
+
readonly isRunning: boolean;
|
|
151
|
+
readonly metrics: Readonly<AgentMetrics>;
|
|
152
|
+
run: AgentRun<TRunOptions>;
|
|
153
|
+
runOrThrow: AgentRunOrThrow<TRunOptions>;
|
|
154
|
+
stop: () => Promise<AnyRunResult | undefined>;
|
|
155
|
+
reset: () => void;
|
|
156
|
+
wait: () => Promise<AnyRunResult>;
|
|
157
|
+
dispose: () => Promise<void>;
|
|
158
|
+
[Symbol.asyncDispose]: () => Promise<void>;
|
|
159
|
+
onEvent: (handler: AgentEventHandler) => () => void;
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
export { RunTiming as C, ProcessSpawner as D, ZodRunRequest as E, RunStatus as S, StructuredRunRequest as T, RunProcessInfo as _, AgentValidationError as a, RunResultBase as b, AnyRunResult as c, CompletedRunResult as d, EnsureDisjoint as f, RunError as g, JsonSchemaRunRequest as h, AgentType as i, BaseAgent as l, FailedRunResult as m, AgentMetrics as n, AnyCompletedRunResult as o, ExclusiveExecutionTargetOptions as p, AgentRunError as r, AnyRunRequest as s, AgentEventHandler as t, CancelledRunResult as u, RunRequest as v, StopReason as w, RunStats as x, RunResult as y };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=class extends Error{result;constructor(e){super(e.error.message),this.name=`AgentRunError`,this.result=e}},t=class extends Error{constructor(e){super(e),this.name=`AgentValidationError`}};export{t as n,e as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>Array.isArray(e)?e:[e],t=e=>e instanceof Error?e.message:String(e),n=e=>typeof e==`object`&&!!e,r=(...e)=>e.reduce((e,t)=>e+(t??0),0),i=e=>{let t=e.trim();return t.startsWith("```")?t.replace(/^```[\w-]*\s*/i,``).replace(/\s*```$/i,``).trim():t},a=e=>/```[\w-]*\s*([\S\s]*?)\s*```/i.exec(e)?.[1]?.trim(),o=e=>{let t=-1,n=[],r=!1,i=!1;for(let a=0;a<e.length;a++){let o=e[a];if(o){if(t===-1){(o===`{`||o===`[`)&&(t=a,n.push(o));continue}if(r){if(i){i=!1;continue}if(o===`\\`){i=!0;continue}o===`"`&&(r=!1);continue}if(o===`"`){r=!0;continue}if(o===`{`||o===`[`){n.push(o);continue}if(o===`}`||o===`]`){let r=n.pop();if(r===`{`&&o!==`}`||r===`[`&&o!==`]`)return;if(n.length===0)return e.slice(t,a+1).trim()}}}},s=e=>{let t=e.trim(),n=[i(t),a(t),o(t)],r;for(let e of new Set(n))if(e)try{return JSON.parse(e)}catch(e){r=e}throw r instanceof Error?r:SyntaxError(`Failed to parse JSON response text.`)};export{e as a,r as i,n,s as r,t};
|
package/package.json
CHANGED
|
@@ -1,15 +1,96 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coding-agents-sdk",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"types": "./dist/index.d.mts",
|
|
6
6
|
"exports": {
|
|
7
|
-
".":
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.mts",
|
|
9
|
+
"default": "./dist/index.mjs"
|
|
10
|
+
},
|
|
11
|
+
"./schemas": {
|
|
12
|
+
"types": "./dist/schemas/index.d.mts",
|
|
13
|
+
"default": "./dist/schemas/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"./container": {
|
|
16
|
+
"types": "./dist/container/index.d.mts",
|
|
17
|
+
"default": "./dist/container/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"./sandbox": {
|
|
20
|
+
"types": "./dist/sandbox/index.d.mts",
|
|
21
|
+
"default": "./dist/sandbox/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./adapters/claude-code-cli": {
|
|
24
|
+
"types": "./dist/adapters/claude-code-cli/index.d.mts",
|
|
25
|
+
"default": "./dist/adapters/claude-code-cli/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./adapters/claude-code-sdk": {
|
|
28
|
+
"types": "./dist/adapters/claude-code-sdk/index.d.mts",
|
|
29
|
+
"default": "./dist/adapters/claude-code-sdk/index.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./adapters/codex-cli": {
|
|
32
|
+
"types": "./dist/adapters/codex-cli/index.d.mts",
|
|
33
|
+
"default": "./dist/adapters/codex-cli/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./adapters/codex-sdk": {
|
|
36
|
+
"types": "./dist/adapters/codex-sdk/index.d.mts",
|
|
37
|
+
"default": "./dist/adapters/codex-sdk/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./adapters/gemini-cli": {
|
|
40
|
+
"types": "./dist/adapters/gemini-cli/index.d.mts",
|
|
41
|
+
"default": "./dist/adapters/gemini-cli/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
11
44
|
},
|
|
12
45
|
"files": [
|
|
13
|
-
"
|
|
14
|
-
|
|
46
|
+
"dist",
|
|
47
|
+
"README.md"
|
|
48
|
+
],
|
|
49
|
+
"sideEffects": false,
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsdown && bun run test:package",
|
|
52
|
+
"start": "bun run examples/claude-code-cli/simple.ts",
|
|
53
|
+
"test": "bun test",
|
|
54
|
+
"test:agent": "bun test ./tests",
|
|
55
|
+
"test:package": "bun run test:package:runtime",
|
|
56
|
+
"test:package:runtime": "bun test ./tests/package-exports.smoke.ts",
|
|
57
|
+
"test:agent:claude-code-cli": "CODE_WORKFLOW_TEST_AGENTS=claude-code-cli bun run test:agent",
|
|
58
|
+
"test:agent:claude-code-sdk": "CODE_WORKFLOW_TEST_AGENTS=claude-code-sdk bun run test:agent",
|
|
59
|
+
"test:agent:codex-cli": "CODE_WORKFLOW_TEST_AGENTS=codex-cli bun run test:agent",
|
|
60
|
+
"test:agent:codex-sdk": "CODE_WORKFLOW_TEST_AGENTS=codex-sdk bun run test:agent",
|
|
61
|
+
"test:agent:gemini-cli": "CODE_WORKFLOW_TEST_AGENTS=gemini-cli bun run test:agent",
|
|
62
|
+
"knip": "knip",
|
|
63
|
+
"tsc": "tsc --noEmit --pretty",
|
|
64
|
+
"typecheck": "bun run tsc"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.74",
|
|
68
|
+
"@openai/codex-sdk": "^0.114.0",
|
|
69
|
+
"@types/bun": "latest",
|
|
70
|
+
"@types/node": "^25.5.0",
|
|
71
|
+
"e2b": "^2.14.1",
|
|
72
|
+
"knip": "^5.87.0",
|
|
73
|
+
"picoprint": "^1.0.6",
|
|
74
|
+
"tsdown": "^0.21.4"
|
|
75
|
+
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.74",
|
|
78
|
+
"@openai/codex-sdk": "^0.114.0",
|
|
79
|
+
"e2b": "^2.14.1",
|
|
80
|
+
"typescript": "^5"
|
|
81
|
+
},
|
|
82
|
+
"peerDependenciesMeta": {
|
|
83
|
+
"@anthropic-ai/claude-agent-sdk": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"@openai/codex-sdk": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"e2b": {
|
|
90
|
+
"optional": true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"dependencies": {
|
|
94
|
+
"zod": "^4.3.6"
|
|
95
|
+
}
|
|
15
96
|
}
|