@howells/envelope 0.1.3 → 0.2.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 +84 -13
- package/dist/ai-sdk.d.ts +4 -4
- package/dist/ai-sdk.d.ts.map +1 -1
- package/dist/ai-sdk.js +50 -41
- package/dist/ai-sdk.js.map +1 -1
- package/dist/claude-code.d.ts +11 -1
- package/dist/claude-code.d.ts.map +1 -1
- package/dist/claude-code.js +72 -63
- package/dist/claude-code.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -7
- package/dist/client.js.map +1 -1
- package/dist/codex-cli.d.ts +3 -0
- package/dist/codex-cli.d.ts.map +1 -1
- package/dist/codex-cli.js +24 -34
- package/dist/codex-cli.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/package.json +15 -13
package/README.md
CHANGED
|
@@ -1,28 +1,68 @@
|
|
|
1
1
|
# envelope
|
|
2
2
|
|
|
3
|
-
Thin wrapper around the `claude` (Claude Code) CLI for **strict** Zod-validated input/output.
|
|
3
|
+
Thin wrapper around the `claude` (Claude Code) and `codex` (Codex CLI) for **strict** Zod-validated input/output.
|
|
4
4
|
|
|
5
5
|
This is designed for local Node apps where you want "model calls" to look like a normal API:
|
|
6
6
|
- validate inputs with Zod
|
|
7
|
-
- request structured JSON output via `--json-schema`
|
|
7
|
+
- request structured JSON output via `--json-schema` / `--output-schema`
|
|
8
8
|
- validate outputs with Zod again (defense in depth)
|
|
9
9
|
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @howells/envelope
|
|
14
|
+
```
|
|
15
|
+
|
|
10
16
|
## Requirements
|
|
11
17
|
|
|
12
18
|
- Node 20+
|
|
13
|
-
- `claude` CLI installed and authenticated (Claude Code)
|
|
19
|
+
- `claude` CLI installed and authenticated (Claude Code), or
|
|
20
|
+
- `codex` CLI installed and authenticated (Codex)
|
|
21
|
+
|
|
22
|
+
## Claude Code Options
|
|
23
|
+
|
|
24
|
+
### `createClaudeCodeClient()`
|
|
25
|
+
|
|
26
|
+
| Option | Type | Default | Description |
|
|
27
|
+
|--------|------|---------|-------------|
|
|
28
|
+
| `model` | `string` | `"opus"` | Model name passed to `--model` |
|
|
29
|
+
| `maxBudgetUsd` | `number` | `5` | Spend cap per call via `--max-budget-usd` |
|
|
30
|
+
| `timeoutMs` | `number` | `120_000` | Kill the process after this many ms |
|
|
31
|
+
| `options.claudePath` | `string` | `"claude"` | Path to the `claude` binary |
|
|
32
|
+
| `options.cwd` | `string` | `process.cwd()` | Working directory for the subprocess |
|
|
33
|
+
| `options.env` | `NodeJS.ProcessEnv` | `process.env` | Environment variables for the subprocess |
|
|
34
|
+
| `options.permissionMode` | `string` | `"dontAsk"` | One of `"default"`, `"plan"`, `"dontAsk"`, `"acceptEdits"`, `"bypassPermissions"`, `"delegate"` |
|
|
35
|
+
| `options.tools` | `string` | `""` | Tools flag; `""` disables all, `"default"` enables built-ins |
|
|
36
|
+
| `options.systemPrompt` | `string` | — | Full system prompt via `--system-prompt` |
|
|
37
|
+
| `options.appendSystemPrompt` | `string` | — | Appended system prompt via `--append-system-prompt` |
|
|
38
|
+
| `options.allowedTools` | `string[]` | `[]` | Repeated `--allowedTools` per entry |
|
|
39
|
+
| `options.disallowedTools` | `string[]` | `[]` | Repeated `--disallowedTools` per entry |
|
|
40
|
+
| `options.fallbackModel` | `string` | — | Fallback model via `--fallback-model` |
|
|
41
|
+
| `options.betas` | `string[]` | `[]` | Repeated `--betas` per entry |
|
|
42
|
+
| `options.agent` | `string` | — | Agent name via `--agent` |
|
|
43
|
+
| `options.agents` | `string` | — | Agents directory via `--agents` |
|
|
44
|
+
| `options.retries` | `number` | `1` | Retries after timeout kill (total attempts = 1 + retries) |
|
|
45
|
+
| `options.retryDelayMs` | `number` | `800` | Base delay between retries (linear backoff) |
|
|
14
46
|
|
|
15
|
-
|
|
47
|
+
Note: `total_cost_usd` is reported by the Claude Code CLI. If you're using a subscription plan, this may be an estimate and not necessarily an incremental billed amount.
|
|
16
48
|
|
|
17
|
-
|
|
18
|
-
- `model` (default `"opus"`)
|
|
19
|
-
- `maxBudgetUsd` (default `5`)
|
|
20
|
-
- `timeoutMs` (default `120_000`)
|
|
21
|
-
- `options.permissionMode` (default `"dontAsk"`)
|
|
22
|
-
- `options.tools` (default `""` to disable all tools; pass `"default"` to enable built-ins)
|
|
23
|
-
- `options.retries` (default `1`) and `options.retryDelayMs` (default `800`) for retry-on-timeout
|
|
49
|
+
## Codex Options
|
|
24
50
|
|
|
25
|
-
|
|
51
|
+
### `createCodexClient()`
|
|
52
|
+
|
|
53
|
+
| Option | Type | Default | Description |
|
|
54
|
+
|--------|------|---------|-------------|
|
|
55
|
+
| `model` | `string` | `"gpt-5.3-codex"` | Model name passed to `--model` |
|
|
56
|
+
| `timeoutMs` | `number` | `180_000` | Kill the process after this many ms |
|
|
57
|
+
| `options.codexPath` | `string` | `"codex"` | Path to the `codex` binary |
|
|
58
|
+
| `options.cwd` | `string` | `process.cwd()` | Working directory for the subprocess |
|
|
59
|
+
| `options.env` | `NodeJS.ProcessEnv` | `process.env` | Environment variables for the subprocess |
|
|
60
|
+
| `options.skipGitRepoCheck` | `boolean` | `true` | Skip git repo validation via `--skip-git-repo-check` |
|
|
61
|
+
| `options.sandbox` | `string` | `"danger-full-access"` | One of `"read-only"`, `"workspace-write"`, `"danger-full-access"` |
|
|
62
|
+
| `options.profile` | `string` | — | Profile name via `--profile` |
|
|
63
|
+
| `options.config` | `string[]` | `[]` | Repeated `--config key=value` per entry |
|
|
64
|
+
| `options.jsonlEvents` | `boolean` | `false` | Enable JSONL event output via `--json` |
|
|
65
|
+
| `options.image` | `string[]` | `[]` | Repeated `--image path` per entry |
|
|
26
66
|
|
|
27
67
|
## Usage (Zod envelope)
|
|
28
68
|
|
|
@@ -71,6 +111,37 @@ const r2 = await generateText({
|
|
|
71
111
|
});
|
|
72
112
|
```
|
|
73
113
|
|
|
114
|
+
Structured JSON output is also supported via `Output.object()`:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { generateText, Output, jsonSchema } from "ai";
|
|
118
|
+
import { claudeCode } from "@howells/envelope/ai-sdk";
|
|
119
|
+
|
|
120
|
+
const { output } = await generateText({
|
|
121
|
+
model: claudeCode("sonnet"),
|
|
122
|
+
prompt: "List three colours and their hex codes.",
|
|
123
|
+
output: Output.object({
|
|
124
|
+
schema: jsonSchema({
|
|
125
|
+
type: "object",
|
|
126
|
+
properties: {
|
|
127
|
+
colours: {
|
|
128
|
+
type: "array",
|
|
129
|
+
items: {
|
|
130
|
+
type: "object",
|
|
131
|
+
properties: {
|
|
132
|
+
name: { type: "string" },
|
|
133
|
+
hex: { type: "string" },
|
|
134
|
+
},
|
|
135
|
+
required: ["name", "hex"],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
required: ["colours"],
|
|
140
|
+
}),
|
|
141
|
+
}),
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
74
145
|
Notes:
|
|
75
|
-
-
|
|
146
|
+
- The adapter uses single-shot calls under the hood (streaming is simulated).
|
|
76
147
|
- If we want true streaming, we can extend it to use `claude --output-format stream-json`.
|
package/dist/ai-sdk.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageModelV2 } from "@ai-sdk/provider";
|
|
2
2
|
import { type CliTool } from "./client.js";
|
|
3
3
|
export declare function cliModel(args: {
|
|
4
4
|
tool: CliTool;
|
|
5
5
|
model: string;
|
|
6
6
|
clientOptions?: any;
|
|
7
|
-
}):
|
|
8
|
-
export declare function claudeCode(model: string, clientOptions?: any):
|
|
9
|
-
export declare function codex(model: string, clientOptions?: any):
|
|
7
|
+
}): LanguageModelV2;
|
|
8
|
+
export declare function claudeCode(model: string, clientOptions?: any): LanguageModelV2;
|
|
9
|
+
export declare function codex(model: string, clientOptions?: any): LanguageModelV2;
|
|
10
10
|
//# sourceMappingURL=ai-sdk.d.ts.map
|
package/dist/ai-sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk.d.ts","sourceRoot":"","sources":["../src/ai-sdk.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai-sdk.d.ts","sourceRoot":"","sources":["../src/ai-sdk.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAEV,eAAe,EAGhB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA6D,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAiCtG,wBAAgB,QAAQ,CAAC,IAAI,EAAE;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,GAAG,CAAC;CACrB,GAAG,eAAe,CAqElB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,GAAG,mBAE5D;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,GAAG,mBAEvD"}
|
package/dist/ai-sdk.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
// AI SDK adapter for CLI tools (Claude Code, Codex).
|
|
1
|
+
// AI SDK v2 adapter for CLI tools (Claude Code, Codex).
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
3
|
+
// Implements LanguageModelV2 from @ai-sdk/provider >=3, compatible with ai@6.
|
|
4
|
+
// Text-first; for JSON mode it maps responseFormat.schema to the CLI's
|
|
5
|
+
// structured-output mode.
|
|
5
6
|
import { createClaudeCodeClient, createCodexClient } from "./client.js";
|
|
6
|
-
function
|
|
7
|
+
function extractText(content) {
|
|
8
|
+
return content
|
|
9
|
+
.filter((p) => p.type === "text" && "text" in p && typeof p.text === "string")
|
|
10
|
+
.map((p) => p.text)
|
|
11
|
+
.join("");
|
|
12
|
+
}
|
|
13
|
+
function v2PromptToText(prompt) {
|
|
7
14
|
const parts = [];
|
|
8
15
|
for (const m of prompt) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
if (m.role === "system") {
|
|
17
|
+
parts.push(`system: ${m.content}`);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (!Array.isArray(m.content))
|
|
12
21
|
continue;
|
|
13
|
-
const text = content
|
|
14
|
-
.filter((p) => p && typeof p === "object" && p.type === "text" && typeof p.text === "string")
|
|
15
|
-
.map((p) => p.text)
|
|
16
|
-
.join("");
|
|
22
|
+
const text = extractText(m.content);
|
|
17
23
|
if (text) {
|
|
18
|
-
parts.push(`${role}: ${text}`);
|
|
24
|
+
parts.push(`${m.role}: ${text}`);
|
|
19
25
|
}
|
|
20
26
|
}
|
|
21
27
|
return parts.join("\n");
|
|
22
28
|
}
|
|
23
|
-
function toSchema(schema) {
|
|
24
|
-
if (!schema)
|
|
25
|
-
return null;
|
|
26
|
-
return schema;
|
|
27
|
-
}
|
|
28
29
|
function makeClient(tool, model, opts) {
|
|
29
30
|
if (tool === "codex") {
|
|
30
31
|
return createCodexClient({ model, ...(opts ?? {}) });
|
|
@@ -34,51 +35,59 @@ function makeClient(tool, model, opts) {
|
|
|
34
35
|
export function cliModel(args) {
|
|
35
36
|
const client = makeClient(args.tool, args.model, args.clientOptions);
|
|
36
37
|
return {
|
|
37
|
-
specificationVersion: "
|
|
38
|
+
specificationVersion: "v2",
|
|
38
39
|
provider: args.tool,
|
|
39
40
|
modelId: args.model,
|
|
40
|
-
|
|
41
|
-
supportsStructuredOutputs: true,
|
|
41
|
+
supportedUrls: {},
|
|
42
42
|
async doGenerate(callOptions) {
|
|
43
|
-
const promptText =
|
|
44
|
-
|
|
45
|
-
if (callOptions.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
throw new Error("object-json mode requires a JSON schema");
|
|
49
|
-
}
|
|
43
|
+
const promptText = v2PromptToText(callOptions.prompt);
|
|
44
|
+
// Structured JSON output mode
|
|
45
|
+
if (callOptions.responseFormat?.type === "json" &&
|
|
46
|
+
callOptions.responseFormat.schema) {
|
|
47
|
+
const schema = callOptions.responseFormat.schema;
|
|
50
48
|
const res = await client.structured({ prompt: promptText, jsonSchema: schema });
|
|
49
|
+
const text = JSON.stringify(res.structured ?? null);
|
|
51
50
|
return {
|
|
52
|
-
|
|
53
|
-
finishReason,
|
|
54
|
-
usage: {
|
|
55
|
-
|
|
51
|
+
content: [{ type: "text", text }],
|
|
52
|
+
finishReason: "stop",
|
|
53
|
+
usage: { inputTokens: undefined, outputTokens: undefined, totalTokens: undefined },
|
|
54
|
+
warnings: [],
|
|
56
55
|
};
|
|
57
56
|
}
|
|
57
|
+
// Plain text mode (default)
|
|
58
58
|
const res = await client.text({ prompt: promptText });
|
|
59
59
|
return {
|
|
60
|
-
text: res.text,
|
|
61
|
-
finishReason,
|
|
62
|
-
usage: {
|
|
63
|
-
|
|
60
|
+
content: [{ type: "text", text: res.text }],
|
|
61
|
+
finishReason: "stop",
|
|
62
|
+
usage: { inputTokens: undefined, outputTokens: undefined, totalTokens: undefined },
|
|
63
|
+
warnings: [],
|
|
64
64
|
};
|
|
65
65
|
},
|
|
66
66
|
async doStream(callOptions) {
|
|
67
|
-
|
|
67
|
+
// CLI tools don't truly stream, so we fake it with a single chunk.
|
|
68
|
+
const result = await this.doGenerate(callOptions);
|
|
69
|
+
const textContent = result.content.find((c) => c.type === "text");
|
|
70
|
+
const textId = "t0";
|
|
68
71
|
const stream = new ReadableStream({
|
|
69
72
|
start(controller) {
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
controller.enqueue({
|
|
74
|
+
type: "stream-start",
|
|
75
|
+
warnings: result.warnings,
|
|
76
|
+
});
|
|
77
|
+
if (textContent) {
|
|
78
|
+
controller.enqueue({ type: "text-start", id: textId });
|
|
79
|
+
controller.enqueue({ type: "text-delta", id: textId, delta: textContent.text });
|
|
80
|
+
controller.enqueue({ type: "text-end", id: textId });
|
|
72
81
|
}
|
|
73
82
|
controller.enqueue({
|
|
74
83
|
type: "finish",
|
|
75
|
-
finishReason:
|
|
76
|
-
usage:
|
|
84
|
+
finishReason: result.finishReason,
|
|
85
|
+
usage: result.usage,
|
|
77
86
|
});
|
|
78
87
|
controller.close();
|
|
79
88
|
},
|
|
80
89
|
});
|
|
81
|
-
return { stream
|
|
90
|
+
return { stream };
|
|
82
91
|
},
|
|
83
92
|
};
|
|
84
93
|
}
|
package/dist/ai-sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk.js","sourceRoot":"","sources":["../src/ai-sdk.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"ai-sdk.js","sourceRoot":"","sources":["../src/ai-sdk.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,8EAA8E;AAC9E,uEAAuE;AACvE,0BAA0B;AAQ1B,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAgC,MAAM,aAAa,CAAC;AAEtG,SAAS,WAAW,CAAC,OAAwC;IAC3D,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,CAAC,EAAuC,EAAE,CACjD,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,IAAI,CAAC,IAAI,OAAQ,CAAS,CAAC,IAAI,KAAK,QAAQ,CAAC;SACzE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SAClB,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,SAAS,cAAc,CAAC,MAA4C;IAClE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC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ses simple linear backoff by attempt.
|
|
16
16
|
*/
|
|
17
17
|
retryDelayMs?: number;
|
|
18
|
-
permissionMode?: "dontAsk" | "
|
|
18
|
+
permissionMode?: "default" | "plan" | "dontAsk" | "acceptEdits" | "bypassPermissions" | "delegate";
|
|
19
19
|
tools?: string;
|
|
20
|
+
systemPrompt?: string;
|
|
21
|
+
appendSystemPrompt?: string;
|
|
22
|
+
allowedTools?: string[];
|
|
23
|
+
disallowedTools?: string[];
|
|
24
|
+
fallbackModel?: string;
|
|
25
|
+
betas?: string[];
|
|
26
|
+
agent?: string;
|
|
27
|
+
agents?: string;
|
|
20
28
|
}
|
|
21
29
|
export interface ClaudeCodeEnvelope<TStructured> {
|
|
22
30
|
type?: string;
|
|
@@ -29,6 +37,8 @@ export interface ClaudeCodeEnvelope<TStructured> {
|
|
|
29
37
|
session_id?: string;
|
|
30
38
|
permission_denials?: unknown[];
|
|
31
39
|
}
|
|
40
|
+
export declare function defaultClaudeOptions(opts?: ClaudeCodeOptions): Required<ClaudeCodeOptions>;
|
|
41
|
+
export declare function buildBaseArgs(opts: Required<ClaudeCodeOptions>): string[];
|
|
32
42
|
export declare function claudeCodeStructured<TStructured>(args: {
|
|
33
43
|
prompt: string;
|
|
34
44
|
jsonSchema: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code.d.ts","sourceRoot":"","sources":["../src/claude-code.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB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AC;IACxB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,EAAE,CAAC;CAChC;AAmHD,wBAAgB,oBAAoB,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAqB1F;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,YAgC9D;AA2CD,wBAAsB,oBAAoB,CAAC,WAAW,EAAE,IAAI,EAAE;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC7B,4CAiCA;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC7B;;GA4BA"}
|
package/dist/claude-code.js
CHANGED
|
@@ -88,8 +88,60 @@ function spawnAsync(file, args, opts) {
|
|
|
88
88
|
});
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
return
|
|
91
|
+
export function defaultClaudeOptions(opts) {
|
|
92
|
+
return {
|
|
93
|
+
claudePath: opts?.claudePath ?? "claude",
|
|
94
|
+
cwd: opts?.cwd ?? process.cwd(),
|
|
95
|
+
env: opts?.env ?? process.env,
|
|
96
|
+
model: opts?.model ?? "opus",
|
|
97
|
+
maxBudgetUsd: opts?.maxBudgetUsd ?? 5,
|
|
98
|
+
timeoutMs: opts?.timeoutMs ?? 120_000,
|
|
99
|
+
retries: opts?.retries ?? 1,
|
|
100
|
+
retryDelayMs: opts?.retryDelayMs ?? 800,
|
|
101
|
+
permissionMode: opts?.permissionMode ?? "dontAsk",
|
|
102
|
+
tools: opts?.tools ?? "",
|
|
103
|
+
systemPrompt: opts?.systemPrompt ?? "",
|
|
104
|
+
appendSystemPrompt: opts?.appendSystemPrompt ?? "",
|
|
105
|
+
allowedTools: opts?.allowedTools ?? [],
|
|
106
|
+
disallowedTools: opts?.disallowedTools ?? [],
|
|
107
|
+
fallbackModel: opts?.fallbackModel ?? "",
|
|
108
|
+
betas: opts?.betas ?? [],
|
|
109
|
+
agent: opts?.agent ?? "",
|
|
110
|
+
agents: opts?.agents ?? "",
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export function buildBaseArgs(opts) {
|
|
114
|
+
const args = [
|
|
115
|
+
"--model", opts.model,
|
|
116
|
+
"-p",
|
|
117
|
+
"--permission-mode", opts.permissionMode,
|
|
118
|
+
"--tools", opts.tools,
|
|
119
|
+
];
|
|
120
|
+
if (opts.systemPrompt) {
|
|
121
|
+
args.push("--system-prompt", opts.systemPrompt);
|
|
122
|
+
}
|
|
123
|
+
if (opts.appendSystemPrompt) {
|
|
124
|
+
args.push("--append-system-prompt", opts.appendSystemPrompt);
|
|
125
|
+
}
|
|
126
|
+
for (const t of opts.allowedTools) {
|
|
127
|
+
args.push("--allowedTools", t);
|
|
128
|
+
}
|
|
129
|
+
for (const t of opts.disallowedTools) {
|
|
130
|
+
args.push("--disallowedTools", t);
|
|
131
|
+
}
|
|
132
|
+
if (opts.fallbackModel) {
|
|
133
|
+
args.push("--fallback-model", opts.fallbackModel);
|
|
134
|
+
}
|
|
135
|
+
for (const b of opts.betas) {
|
|
136
|
+
args.push("--betas", b);
|
|
137
|
+
}
|
|
138
|
+
if (opts.agent) {
|
|
139
|
+
args.push("--agent", opts.agent);
|
|
140
|
+
}
|
|
141
|
+
if (opts.agents) {
|
|
142
|
+
args.push("--agents", opts.agents);
|
|
143
|
+
}
|
|
144
|
+
return args;
|
|
93
145
|
}
|
|
94
146
|
function sleep(ms) {
|
|
95
147
|
return new Promise((r) => setTimeout(r, ms));
|
|
@@ -98,29 +150,7 @@ function isTimeoutKill(err) {
|
|
|
98
150
|
const e = err;
|
|
99
151
|
return Boolean(e && e.killed === true && e.signal === "SIGTERM");
|
|
100
152
|
}
|
|
101
|
-
|
|
102
|
-
const options = {
|
|
103
|
-
claudePath: args.options?.claudePath ?? "claude",
|
|
104
|
-
cwd: args.options?.cwd ?? process.cwd(),
|
|
105
|
-
env: args.options?.env ?? process.env,
|
|
106
|
-
model: args.options?.model ?? "opus",
|
|
107
|
-
maxBudgetUsd: args.options?.maxBudgetUsd ?? 5,
|
|
108
|
-
timeoutMs: args.options?.timeoutMs ?? 120_000,
|
|
109
|
-
retries: args.options?.retries ?? 1,
|
|
110
|
-
retryDelayMs: args.options?.retryDelayMs ?? 800,
|
|
111
|
-
permissionMode: args.options?.permissionMode ?? "dontAsk",
|
|
112
|
-
tools: args.options?.tools ?? "",
|
|
113
|
-
};
|
|
114
|
-
const cliArgs = [
|
|
115
|
-
...buildBaseArgs(options),
|
|
116
|
-
"--max-budget-usd",
|
|
117
|
-
String(options.maxBudgetUsd),
|
|
118
|
-
"--output-format",
|
|
119
|
-
"json",
|
|
120
|
-
"--json-schema",
|
|
121
|
-
args.jsonSchema,
|
|
122
|
-
args.prompt,
|
|
123
|
-
];
|
|
153
|
+
async function spawnWithRetry(options, cliArgs) {
|
|
124
154
|
let stdout = null;
|
|
125
155
|
let lastErr = null;
|
|
126
156
|
for (let attempt = 0; attempt <= options.retries; attempt++) {
|
|
@@ -135,8 +165,6 @@ export async function claudeCodeStructured(args) {
|
|
|
135
165
|
}
|
|
136
166
|
catch (e) {
|
|
137
167
|
lastErr = e;
|
|
138
|
-
// Retry only if it's likely transient (timeout kill). Other errors should
|
|
139
|
-
// generally be surfaced immediately to avoid masking real failures.
|
|
140
168
|
if (!isTimeoutKill(e?.cause ?? e) || attempt >= options.retries) {
|
|
141
169
|
throw e;
|
|
142
170
|
}
|
|
@@ -147,6 +175,21 @@ export async function claudeCodeStructured(args) {
|
|
|
147
175
|
if (stdout == null) {
|
|
148
176
|
throw lastErr instanceof Error ? lastErr : new Error("claude CLI failed");
|
|
149
177
|
}
|
|
178
|
+
return stdout;
|
|
179
|
+
}
|
|
180
|
+
export async function claudeCodeStructured(args) {
|
|
181
|
+
const options = defaultClaudeOptions(args.options);
|
|
182
|
+
const cliArgs = [
|
|
183
|
+
...buildBaseArgs(options),
|
|
184
|
+
"--max-budget-usd",
|
|
185
|
+
String(options.maxBudgetUsd),
|
|
186
|
+
"--output-format",
|
|
187
|
+
"json",
|
|
188
|
+
"--json-schema",
|
|
189
|
+
args.jsonSchema,
|
|
190
|
+
args.prompt,
|
|
191
|
+
];
|
|
192
|
+
const stdout = await spawnWithRetry(options, cliArgs);
|
|
150
193
|
let envelopeUnknown;
|
|
151
194
|
try {
|
|
152
195
|
envelopeUnknown = JSON.parse(stdout);
|
|
@@ -164,18 +207,7 @@ export async function claudeCodeStructured(args) {
|
|
|
164
207
|
return envelope;
|
|
165
208
|
}
|
|
166
209
|
export async function claudeCodeText(args) {
|
|
167
|
-
const options =
|
|
168
|
-
claudePath: args.options?.claudePath ?? "claude",
|
|
169
|
-
cwd: args.options?.cwd ?? process.cwd(),
|
|
170
|
-
env: args.options?.env ?? process.env,
|
|
171
|
-
model: args.options?.model ?? "opus",
|
|
172
|
-
maxBudgetUsd: args.options?.maxBudgetUsd ?? 5,
|
|
173
|
-
timeoutMs: args.options?.timeoutMs ?? 120_000,
|
|
174
|
-
retries: args.options?.retries ?? 1,
|
|
175
|
-
retryDelayMs: args.options?.retryDelayMs ?? 800,
|
|
176
|
-
permissionMode: args.options?.permissionMode ?? "dontAsk",
|
|
177
|
-
tools: args.options?.tools ?? "",
|
|
178
|
-
};
|
|
210
|
+
const options = defaultClaudeOptions(args.options);
|
|
179
211
|
const cliArgs = [
|
|
180
212
|
...buildBaseArgs(options),
|
|
181
213
|
"--max-budget-usd",
|
|
@@ -184,30 +216,7 @@ export async function claudeCodeText(args) {
|
|
|
184
216
|
"json",
|
|
185
217
|
args.prompt,
|
|
186
218
|
];
|
|
187
|
-
|
|
188
|
-
let lastErr = null;
|
|
189
|
-
for (let attempt = 0; attempt <= options.retries; attempt++) {
|
|
190
|
-
try {
|
|
191
|
-
({ stdout } = await spawnAsync(options.claudePath, cliArgs, {
|
|
192
|
-
cwd: options.cwd,
|
|
193
|
-
env: options.env,
|
|
194
|
-
timeoutMs: options.timeoutMs,
|
|
195
|
-
}));
|
|
196
|
-
lastErr = null;
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
catch (e) {
|
|
200
|
-
lastErr = e;
|
|
201
|
-
if (!isTimeoutKill(e?.cause ?? e) || attempt >= options.retries) {
|
|
202
|
-
throw e;
|
|
203
|
-
}
|
|
204
|
-
const delay = options.retryDelayMs * (attempt + 1);
|
|
205
|
-
await sleep(delay);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
if (stdout == null) {
|
|
209
|
-
throw lastErr instanceof Error ? lastErr : new Error("claude CLI failed");
|
|
210
|
-
}
|
|
219
|
+
const stdout = await spawnWithRetry(options, cliArgs);
|
|
211
220
|
let envelopeUnknown;
|
|
212
221
|
try {
|
|
213
222
|
envelopeUnknown = JSON.parse(stdout);
|
package/dist/claude-code.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code.js","sourceRoot":"","sources":["../src/claude-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"claude-code.js","sourceRoot":"","sources":["../src/claude-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAkD3C,SAAS,QAAQ,CAAC,CAAU;IAC1B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC;AAC7C,CAAC;AAED,SAAS,UAAU,CACjB,IAAY,EACZ,IAAc,EACd,IAKC;IAED,OAAO,IAAI,OAAO,CAAqC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzE,MAAM,KAAK,GAAG,KAAK,CACjB,IAAI,EACJ,IAAI,EAC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ACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,OAAO,GAAG,WAAW,CAAC,CAAC;CACrD,GAAG,SAAS,CAwBZ"}
|
package/dist/client.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toJSONSchema } from "zod/v4";
|
|
2
2
|
import { claudeCodeStructured, claudeCodeText, } from "./claude-code.js";
|
|
3
3
|
import { codexStructured, codexText } from "./codex-cli.js";
|
|
4
4
|
export function jsonSchemaFromZod(schema) {
|
|
5
|
-
|
|
6
|
-
// in a `$ref`/`definitions` envelope, which breaks Codex's `--output-schema`
|
|
7
|
-
// requirement that the root schema is `type: "object"`.
|
|
8
|
-
return zodToJsonSchema(schema, {
|
|
9
|
-
$refStrategy: "none",
|
|
10
|
-
});
|
|
5
|
+
return toJSONSchema(schema);
|
|
11
6
|
}
|
|
12
7
|
export function createClaudeCodeClient(args) {
|
|
13
8
|
const cfg = args;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EACL,oBAAoB,EACpB,cAAc,GAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,SAAS,EAAqB,MAAM,gBAAgB,CAAC;AAoB/E,MAAM,UAAU,iBAAiB,CAAC,MAAoB;IACpD,OAAO,YAAY,CAAC,MAAM,CAA2B,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAKtC;IACC,MAAM,GAAG,GAAG,IAAI,CAAC;IACjB,MAAM,KAAK,GAAG,GAAG,EAAE,K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AAK,CAAC,MAAM;gBACpB,OAAO,EAAE,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE;aAC/C,CAAC,CAAC;YACH,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;QAC5B,CAAC;QACD,KAAK,CAAC,UAAU,CAAI,KAA6B;YAC/C,MAAM,GAAG,GAAG,MAAM,eAAe,CAAI;gBACnC,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC;gBAC5C,OAAO,EAAE,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE;aAC/C,CAAC,CAAC;YACH,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/codex-cli.d.ts
CHANGED
|
@@ -10,7 +10,10 @@ export interface CodexOptions {
|
|
|
10
10
|
profile?: string;
|
|
11
11
|
config?: Array<string>;
|
|
12
12
|
jsonlEvents?: boolean;
|
|
13
|
+
image?: string[];
|
|
13
14
|
}
|
|
15
|
+
export declare function baseArgs(options: Required<CodexOptions>): string[];
|
|
16
|
+
export declare function defaultOptions(opts?: CodexOptions): Required<CodexOptions>;
|
|
14
17
|
export declare function codexText(args: {
|
|
15
18
|
prompt: string;
|
|
16
19
|
options?: CodexOptions;
|
package/dist/codex-cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-cli.d.ts","sourceRoot":"","sources":["../src/codex-cli.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;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,WAAW,EAAE,IAAI,EAAE;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;gBAgBgC,WAAW;;GAC3C"}
|
package/dist/codex-cli.js
CHANGED
|
@@ -21,7 +21,7 @@ function execFileAsync(file, args, opts) {
|
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
function baseArgs(options) {
|
|
24
|
+
export function baseArgs(options) {
|
|
25
25
|
const args = ["exec"];
|
|
26
26
|
if (options.skipGitRepoCheck) {
|
|
27
27
|
args.push("--skip-git-repo-check");
|
|
@@ -44,9 +44,12 @@ function baseArgs(options) {
|
|
|
44
44
|
if (options.jsonlEvents) {
|
|
45
45
|
args.push("--json");
|
|
46
46
|
}
|
|
47
|
+
for (const img of options.image) {
|
|
48
|
+
args.push("--image", img);
|
|
49
|
+
}
|
|
47
50
|
return args;
|
|
48
51
|
}
|
|
49
|
-
function defaultOptions(opts) {
|
|
52
|
+
export function defaultOptions(opts) {
|
|
50
53
|
return {
|
|
51
54
|
codexPath: opts?.codexPath ?? "codex",
|
|
52
55
|
cwd: opts?.cwd ?? process.cwd(),
|
|
@@ -58,63 +61,50 @@ function defaultOptions(opts) {
|
|
|
58
61
|
profile: opts?.profile ?? "",
|
|
59
62
|
config: opts?.config ?? [],
|
|
60
63
|
jsonlEvents: opts?.jsonlEvents ?? false,
|
|
64
|
+
image: opts?.image ?? [],
|
|
61
65
|
};
|
|
62
66
|
}
|
|
63
|
-
|
|
64
|
-
const options = defaultOptions(args.options);
|
|
67
|
+
async function execInTempDir(options, setup) {
|
|
65
68
|
const td = await mkdtemp(join(tmpdir(), "envelope-codex-"));
|
|
66
69
|
try {
|
|
67
70
|
const outPath = join(td, "last.txt");
|
|
71
|
+
const extraArgs = await setup(td, outPath);
|
|
68
72
|
const cliArgs = [
|
|
69
73
|
...baseArgs(options),
|
|
74
|
+
...extraArgs,
|
|
70
75
|
"--output-last-message",
|
|
71
76
|
outPath,
|
|
72
|
-
args.prompt,
|
|
73
77
|
];
|
|
74
78
|
await execFileAsync(options.codexPath, cliArgs, {
|
|
75
79
|
cwd: options.cwd,
|
|
76
80
|
env: options.env,
|
|
77
81
|
timeoutMs: options.timeoutMs,
|
|
78
82
|
});
|
|
79
|
-
|
|
80
|
-
return { text };
|
|
83
|
+
return await readFile(outPath, "utf8");
|
|
81
84
|
}
|
|
82
85
|
finally {
|
|
83
86
|
await rm(td, { recursive: true, force: true });
|
|
84
87
|
}
|
|
85
88
|
}
|
|
89
|
+
export async function codexText(args) {
|
|
90
|
+
const options = defaultOptions(args.options);
|
|
91
|
+
const text = await execInTempDir(options, async () => [args.prompt]);
|
|
92
|
+
return { text };
|
|
93
|
+
}
|
|
86
94
|
export async function codexStructured(args) {
|
|
87
95
|
const options = defaultOptions(args.options);
|
|
88
|
-
const
|
|
89
|
-
try {
|
|
96
|
+
const raw = await execInTempDir(options, async (td) => {
|
|
90
97
|
const schemaPath = join(td, "schema.json");
|
|
91
|
-
const outPath = join(td, "last.txt");
|
|
92
98
|
await writeFile(schemaPath, args.jsonSchema, "utf8");
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
outPath,
|
|
99
|
-
args.prompt,
|
|
100
|
-
];
|
|
101
|
-
await execFileAsync(options.codexPath, cliArgs, {
|
|
102
|
-
cwd: options.cwd,
|
|
103
|
-
env: options.env,
|
|
104
|
-
timeoutMs: options.timeoutMs,
|
|
105
|
-
});
|
|
106
|
-
const raw = await readFile(outPath, "utf8");
|
|
107
|
-
let parsed;
|
|
108
|
-
try {
|
|
109
|
-
parsed = JSON.parse(raw);
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
throw new Error(`codex output was not JSON. First 200 chars:\n${raw.slice(0, 200)}`);
|
|
113
|
-
}
|
|
114
|
-
return { structured: parsed, raw };
|
|
99
|
+
return ["--output-schema", schemaPath, args.prompt];
|
|
100
|
+
});
|
|
101
|
+
let parsed;
|
|
102
|
+
try {
|
|
103
|
+
parsed = JSON.parse(raw);
|
|
115
104
|
}
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
catch {
|
|
106
|
+
throw new Error(`codex output was not JSON. First 200 chars:\n${raw.slice(0, 200)}`);
|
|
118
107
|
}
|
|
108
|
+
return { structured: parsed, raw };
|
|
119
109
|
}
|
|
120
110
|
//# sourceMappingURL=codex-cli.js.map
|
package/dist/codex-cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-cli.js","sourceRoot":"","sources":["../src/codex-cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"codex-cli.js","sourceRoot":"","sources":["../src/codex-cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAkBjC,SAAS,aAAa,CACpB,IAAY,EACZ,IAAc,EACd,IAAmE;IAEnE,OAAO,IAAI,OAAO,CAAqC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzE,QAAQ,CACN,IAAI,EACJ,IAAI,EACJ;YACE,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,OAAO,EAAE,IAA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AE,MAAM,CAAC,CAAC;QACrD,OAAO,CAAC,iBAAiB,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,gDAAgD,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IACvF,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,MAAqB,EAAE,GAAG,EAAE,CAAC;AACpD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export { createEnvelope, EnvelopeError, type CreateEnvelopeArgs, } from "./envelope.js";
|
|
2
|
+
export { createClaudeCodeClient, createCodexClient, jsonSchemaFromZod, type CliClient, type CliTool, type GenerateTextArgs, type GenerateStructuredArgs, } from "./client.js";
|
|
3
|
+
export { claudeCodeStructured, claudeCodeText, type ClaudeCodeOptions, } from "./claude-code.js";
|
|
4
|
+
export { codexStructured, codexText, type CodexOptions, } from "./codex-cli.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,aAAa,EACb,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,GAC5B,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,eAAe,EACf,SAAS,EACT,KAAK,YAAY,GAClB,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
|
|
1
|
+
// Core API
|
|
2
|
+
export { createEnvelope, EnvelopeError, } from "./envelope.js";
|
|
3
|
+
export { createClaudeCodeClient, createCodexClient, jsonSchemaFromZod, } from "./client.js";
|
|
4
|
+
// CLI-level API (for power users who need direct CLI access)
|
|
5
|
+
export { claudeCodeStructured, claudeCodeText, } from "./claude-code.js";
|
|
6
|
+
export { codexStructured, codexText, } from "./codex-cli.js";
|
|
5
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,OAAO,EACL,cAAc,EACd,aAAa,GAEd,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,GAKlB,MAAM,aAAa,CAAC;AAErB,6DAA6D;AAC7D,OAAO,EACL,oBAAoB,EACpB,cAAc,GAEf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,eAAe,EACf,SAAS,GAEV,MAAM,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howells/envelope",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Strict Zod IO wrapper around local CLI LLMs (Claude Code, Codex), plus an AI SDK adapter.",
|
|
6
6
|
"type": "module",
|
|
@@ -34,12 +34,6 @@
|
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=20"
|
|
36
36
|
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "tsc -p tsconfig.json",
|
|
39
|
-
"dev": "tsc -p tsconfig.json -w",
|
|
40
|
-
"prepack": "pnpm build",
|
|
41
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
42
|
-
},
|
|
43
37
|
"keywords": [
|
|
44
38
|
"llm",
|
|
45
39
|
"cli",
|
|
@@ -49,13 +43,21 @@
|
|
|
49
43
|
"ai-sdk"
|
|
50
44
|
],
|
|
51
45
|
"dependencies": {
|
|
52
|
-
"@ai-sdk/provider": "^
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
"@ai-sdk/provider": "^3.0.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"zod": "^4.0.0"
|
|
55
50
|
},
|
|
56
51
|
"devDependencies": {
|
|
57
52
|
"@types/node": "^22.0.0",
|
|
58
|
-
"typescript": "^5.7.0"
|
|
53
|
+
"typescript": "^5.7.0",
|
|
54
|
+
"vitest": "^4.0.18",
|
|
55
|
+
"zod": "^4.3.6"
|
|
59
56
|
},
|
|
60
|
-
"
|
|
61
|
-
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsc -p tsconfig.json",
|
|
59
|
+
"dev": "tsc -p tsconfig.json -w",
|
|
60
|
+
"test": "vitest run",
|
|
61
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
62
|
+
}
|
|
63
|
+
}
|