@ai-sdk/harness-claude-code 1.0.72 → 1.0.74
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/CHANGELOG.md +14 -0
- package/dist/bridge/index.mjs +1 -0
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.js +35 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/bridge/index.ts +1 -0
- package/src/claude-code-auth.ts +45 -7
- package/src/claude-code-bridge-protocol.ts +1 -0
- package/src/claude-code-harness.ts +11 -0
- package/src/index.ts +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/harness-claude-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.74",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"ws": "^8.21.0",
|
|
30
|
-
"@ai-sdk/harness": "1.0.
|
|
30
|
+
"@ai-sdk/harness": "1.0.71",
|
|
31
31
|
"@ai-sdk/provider-utils": "5.0.27"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
package/src/bridge/index.ts
CHANGED
|
@@ -347,6 +347,7 @@ async function runTurn(start: StartMessage, turn: BridgeTurn): Promise<void> {
|
|
|
347
347
|
: {}),
|
|
348
348
|
systemPrompt: createClaudeCodeSystemPrompt(start.instructions),
|
|
349
349
|
thinking: start.thinking,
|
|
350
|
+
...(start.effort !== undefined ? { effort: start.effort } : {}),
|
|
350
351
|
includePartialMessages: true,
|
|
351
352
|
// The `PostCompact` hook carries the compaction summary, which the
|
|
352
353
|
// `compact_boundary` system message does not. Latch it for the unified
|
package/src/claude-code-auth.ts
CHANGED
|
@@ -4,7 +4,12 @@ import { homedir } from 'node:os';
|
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { getAiGatewayAuthFromEnv } from '@ai-sdk/harness/utils';
|
|
6
6
|
|
|
7
|
-
export type
|
|
7
|
+
export type ClaudeCodeAuthenticationMode = 'auto' | 'direct' | 'ai-gateway';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Passing an object to auth options is deprecated. Use a `ClaudeCodeAuthenticationMode` string value ("auto" | "direct" | "ai-gateway") instead, and pass credentials via environment variables.
|
|
11
|
+
*/
|
|
12
|
+
export type LegacyClaudeCodeAuthOptions = {
|
|
8
13
|
readonly anthropic?: {
|
|
9
14
|
readonly apiKey?: string;
|
|
10
15
|
readonly authToken?: string;
|
|
@@ -16,6 +21,10 @@ export type ClaudeCodeAuthOptions = {
|
|
|
16
21
|
};
|
|
17
22
|
};
|
|
18
23
|
|
|
24
|
+
export type ClaudeCodeAuthOptions =
|
|
25
|
+
| ClaudeCodeAuthenticationMode
|
|
26
|
+
| LegacyClaudeCodeAuthOptions;
|
|
27
|
+
|
|
19
28
|
/**
|
|
20
29
|
* Resolve the environment-variable blob the bridge needs to authenticate
|
|
21
30
|
* with Anthropic (directly or via the Vercel AI Gateway). Precedence:
|
|
@@ -42,15 +51,21 @@ export function resolveClaudeCodeEnv(
|
|
|
42
51
|
processEnv: Record<string, string | undefined> = process.env,
|
|
43
52
|
options: ResolveClaudeCodeEnvOptions = {},
|
|
44
53
|
): Record<string, string> {
|
|
54
|
+
const normalizedAuth = normalizeClaudeCodeAuthToLegacyAuth(auth);
|
|
55
|
+
|
|
45
56
|
const readApiKey = options.readApiKeyHelper ?? readApiKeyHelper;
|
|
46
|
-
if (
|
|
47
|
-
return pickAnthropic({
|
|
57
|
+
if (normalizedAuth?.anthropic) {
|
|
58
|
+
return pickAnthropic({
|
|
59
|
+
explicit: normalizedAuth.anthropic,
|
|
60
|
+
processEnv,
|
|
61
|
+
readApiKey,
|
|
62
|
+
});
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
const gatewayAuthFromEnv = getAiGatewayAuthFromEnv({ env: processEnv });
|
|
51
|
-
if (
|
|
66
|
+
if (normalizedAuth?.gateway) {
|
|
52
67
|
return pickGateway({
|
|
53
|
-
explicit:
|
|
68
|
+
explicit: normalizedAuth.gateway,
|
|
54
69
|
gatewayAuthFromEnv,
|
|
55
70
|
});
|
|
56
71
|
}
|
|
@@ -64,12 +79,35 @@ export function resolveClaudeCodeEnv(
|
|
|
64
79
|
return pickAnthropic({ processEnv, readApiKey });
|
|
65
80
|
}
|
|
66
81
|
|
|
82
|
+
function normalizeClaudeCodeAuthToLegacyAuth(
|
|
83
|
+
auth: ClaudeCodeAuthOptions | undefined,
|
|
84
|
+
): LegacyClaudeCodeAuthOptions | undefined {
|
|
85
|
+
if (auth == null || auth === 'auto') {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
if (typeof auth === 'string') {
|
|
89
|
+
switch (auth) {
|
|
90
|
+
case 'direct':
|
|
91
|
+
return { anthropic: {} };
|
|
92
|
+
case 'ai-gateway':
|
|
93
|
+
return { gateway: {} };
|
|
94
|
+
default:
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
console.warn(
|
|
100
|
+
'[claude-code] Passing an object to auth options is deprecated. Use a string mode ("auto" | "direct" | "ai-gateway") instead, and pass credentials via environment variables.',
|
|
101
|
+
);
|
|
102
|
+
return auth;
|
|
103
|
+
}
|
|
104
|
+
|
|
67
105
|
function pickAnthropic({
|
|
68
106
|
explicit,
|
|
69
107
|
processEnv,
|
|
70
108
|
readApiKey,
|
|
71
109
|
}: {
|
|
72
|
-
explicit?: NonNullable<
|
|
110
|
+
explicit?: NonNullable<LegacyClaudeCodeAuthOptions['anthropic']>;
|
|
73
111
|
processEnv: Record<string, string | undefined>;
|
|
74
112
|
readApiKey: () => string | undefined;
|
|
75
113
|
}): Record<string, string> {
|
|
@@ -125,7 +163,7 @@ function pickGateway({
|
|
|
125
163
|
explicit,
|
|
126
164
|
gatewayAuthFromEnv,
|
|
127
165
|
}: {
|
|
128
|
-
explicit: NonNullable<
|
|
166
|
+
explicit: NonNullable<LegacyClaudeCodeAuthOptions['gateway']>;
|
|
129
167
|
gatewayAuthFromEnv: ReturnType<typeof getAiGatewayAuthFromEnv>;
|
|
130
168
|
}): Record<string, string> {
|
|
131
169
|
const apiKey = explicit.apiKey ?? gatewayAuthFromEnv.apiKey;
|
|
@@ -33,6 +33,7 @@ const thinkingSchema = z.discriminatedUnion('type', [
|
|
|
33
33
|
export const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
|
|
34
34
|
instructions: z.string().optional(),
|
|
35
35
|
thinking: thinkingSchema,
|
|
36
|
+
effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
|
|
36
37
|
maxTurns: z.number().optional(),
|
|
37
38
|
env: z.record(z.string(), z.string()).optional(),
|
|
38
39
|
skills: z.array(z.string()).optional(),
|
|
@@ -89,6 +89,11 @@ export type ClaudeCodeHarnessSettings = {
|
|
|
89
89
|
* omitted. Defaults to `{ type: 'adaptive', display: 'summarized' }`.
|
|
90
90
|
*/
|
|
91
91
|
readonly thinking?: ClaudeCodeThinkingConfig;
|
|
92
|
+
/**
|
|
93
|
+
* Controls how much effort Claude applies when adaptive thinking is enabled.
|
|
94
|
+
* Unset uses the Claude Agent SDK default.
|
|
95
|
+
*/
|
|
96
|
+
readonly effort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
92
97
|
/**
|
|
93
98
|
* Override the port the bridge binds inside the sandbox. By default the
|
|
94
99
|
* adapter uses the first port the sandbox declares via `sandbox.ports`.
|
|
@@ -919,6 +924,7 @@ export function createClaudeCode(
|
|
|
919
924
|
maxTurns: settings.maxTurns,
|
|
920
925
|
env: settings.env,
|
|
921
926
|
thinking,
|
|
927
|
+
effort: settings.effort,
|
|
922
928
|
isResume: true,
|
|
923
929
|
continueOnFirstPrompt: false,
|
|
924
930
|
rerunContinue: false,
|
|
@@ -1094,6 +1100,7 @@ export function createClaudeCode(
|
|
|
1094
1100
|
maxTurns: settings.maxTurns,
|
|
1095
1101
|
env: settings.env,
|
|
1096
1102
|
thinking,
|
|
1103
|
+
effort: settings.effort,
|
|
1097
1104
|
isResume: respawnStrategy !== undefined,
|
|
1098
1105
|
continueOnFirstPrompt: respawnStrategy !== undefined,
|
|
1099
1106
|
rerunContinue: respawnStrategy === 'rerun',
|
|
@@ -1352,6 +1359,7 @@ function createSession({
|
|
|
1352
1359
|
maxTurns,
|
|
1353
1360
|
env,
|
|
1354
1361
|
thinking,
|
|
1362
|
+
effort,
|
|
1355
1363
|
isResume,
|
|
1356
1364
|
continueOnFirstPrompt,
|
|
1357
1365
|
rerunContinue,
|
|
@@ -1372,6 +1380,7 @@ function createSession({
|
|
|
1372
1380
|
maxTurns: number | undefined;
|
|
1373
1381
|
env: Readonly<Record<string, string>> | undefined;
|
|
1374
1382
|
thinking: ClaudeCodeThinkingConfig;
|
|
1383
|
+
effort: 'low' | 'medium' | 'high' | 'xhigh' | 'max' | undefined;
|
|
1375
1384
|
isResume: boolean;
|
|
1376
1385
|
continueOnFirstPrompt: boolean;
|
|
1377
1386
|
rerunContinue: boolean;
|
|
@@ -1554,6 +1563,7 @@ function createSession({
|
|
|
1554
1563
|
maxTurns,
|
|
1555
1564
|
...(env !== undefined ? { env } : {}),
|
|
1556
1565
|
thinking,
|
|
1566
|
+
...(effort !== undefined ? { effort } : {}),
|
|
1557
1567
|
...(skills.length > 0
|
|
1558
1568
|
? { skills: skills.map(skill => skill.name) }
|
|
1559
1569
|
: {}),
|
|
@@ -1611,6 +1621,7 @@ function createSession({
|
|
|
1611
1621
|
maxTurns,
|
|
1612
1622
|
...(env !== undefined ? { env } : {}),
|
|
1613
1623
|
thinking,
|
|
1624
|
+
...(effort !== undefined ? { effort } : {}),
|
|
1614
1625
|
...(skills.length > 0
|
|
1615
1626
|
? { skills: skills.map(skill => skill.name) }
|
|
1616
1627
|
: {}),
|
package/src/index.ts
CHANGED
|
@@ -10,5 +10,8 @@ export const claudeCode = createClaudeCode();
|
|
|
10
10
|
export { createClaudeCode } from './claude-code-harness';
|
|
11
11
|
export { VERSION } from './version';
|
|
12
12
|
export type { ClaudeCodeHarnessSettings } from './claude-code-harness';
|
|
13
|
-
export type {
|
|
13
|
+
export type {
|
|
14
|
+
ClaudeCodeAuthenticationMode,
|
|
15
|
+
ClaudeCodeAuthOptions,
|
|
16
|
+
} from './claude-code-auth';
|
|
14
17
|
export type { ClaudeCodeThinkingConfig } from './claude-code-thinking';
|