@agentex/agent 0.0.1 → 0.0.3
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 +358 -78
- package/dist/index.d.ts +16 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/claude/execute.d.ts +1 -1
- package/dist/providers/claude/execute.d.ts.map +1 -1
- package/dist/providers/claude/execute.js +53 -20
- package/dist/providers/claude/execute.js.map +1 -1
- package/dist/providers/claude/index.d.ts +1 -1
- package/dist/providers/claude/index.d.ts.map +1 -1
- package/dist/providers/claude/index.js +40 -9
- package/dist/providers/claude/index.js.map +1 -1
- package/dist/providers/claude/parse.d.ts.map +1 -1
- package/dist/providers/claude/parse.js +2 -1
- package/dist/providers/claude/parse.js.map +1 -1
- package/dist/providers/claude/session.d.ts +10 -0
- package/dist/providers/claude/session.d.ts.map +1 -0
- package/dist/providers/claude/session.js +549 -0
- package/dist/providers/claude/session.js.map +1 -0
- package/dist/providers/claude/test.d.ts.map +1 -1
- package/dist/providers/claude/test.js +38 -11
- package/dist/providers/claude/test.js.map +1 -1
- package/dist/providers/codex/execute.d.ts +1 -1
- package/dist/providers/codex/execute.d.ts.map +1 -1
- package/dist/providers/codex/execute.js +114 -75
- package/dist/providers/codex/execute.js.map +1 -1
- package/dist/providers/codex/index.d.ts +1 -1
- package/dist/providers/codex/index.d.ts.map +1 -1
- package/dist/providers/codex/index.js +59 -3
- package/dist/providers/codex/index.js.map +1 -1
- package/dist/providers/codex/parse.d.ts.map +1 -1
- package/dist/providers/codex/parse.js +25 -3
- package/dist/providers/codex/parse.js.map +1 -1
- package/dist/providers/codex/session.d.ts +3 -0
- package/dist/providers/codex/session.d.ts.map +1 -0
- package/dist/providers/codex/session.js +553 -0
- package/dist/providers/codex/session.js.map +1 -0
- package/dist/providers/codex/test.d.ts.map +1 -1
- package/dist/providers/codex/test.js +28 -12
- package/dist/providers/codex/test.js.map +1 -1
- package/dist/providers/codex/usage-scanner.d.ts +18 -0
- package/dist/providers/codex/usage-scanner.d.ts.map +1 -0
- package/dist/providers/codex/usage-scanner.js +148 -0
- package/dist/providers/codex/usage-scanner.js.map +1 -0
- package/dist/providers/cursor/codec.d.ts +3 -0
- package/dist/providers/cursor/codec.d.ts.map +1 -0
- package/dist/providers/cursor/codec.js +43 -0
- package/dist/providers/cursor/codec.js.map +1 -0
- package/dist/providers/cursor/execute.d.ts +3 -0
- package/dist/providers/cursor/execute.d.ts.map +1 -0
- package/dist/providers/cursor/execute.js +248 -0
- package/dist/providers/cursor/execute.js.map +1 -0
- package/dist/providers/cursor/index.d.ts +3 -0
- package/dist/providers/cursor/index.d.ts.map +1 -0
- package/dist/providers/cursor/index.js +30 -0
- package/dist/providers/cursor/index.js.map +1 -0
- package/dist/providers/cursor/parse.d.ts +26 -0
- package/dist/providers/cursor/parse.d.ts.map +1 -0
- package/dist/providers/cursor/parse.js +224 -0
- package/dist/providers/cursor/parse.js.map +1 -0
- package/dist/providers/cursor/test.d.ts +3 -0
- package/dist/providers/cursor/test.d.ts.map +1 -0
- package/dist/providers/cursor/test.js +58 -0
- package/dist/providers/cursor/test.js.map +1 -0
- package/dist/providers/gemini/codec.d.ts +3 -0
- package/dist/providers/gemini/codec.d.ts.map +1 -0
- package/dist/providers/gemini/codec.js +47 -0
- package/dist/providers/gemini/codec.js.map +1 -0
- package/dist/providers/gemini/execute.d.ts +3 -0
- package/dist/providers/gemini/execute.d.ts.map +1 -0
- package/dist/providers/gemini/execute.js +236 -0
- package/dist/providers/gemini/execute.js.map +1 -0
- package/dist/providers/gemini/index.d.ts +3 -0
- package/dist/providers/gemini/index.d.ts.map +1 -0
- package/dist/providers/gemini/index.js +64 -0
- package/dist/providers/gemini/index.js.map +1 -0
- package/dist/providers/gemini/parse.d.ts +20 -0
- package/dist/providers/gemini/parse.d.ts.map +1 -0
- package/dist/providers/gemini/parse.js +207 -0
- package/dist/providers/gemini/parse.js.map +1 -0
- package/dist/providers/gemini/test.d.ts +3 -0
- package/dist/providers/gemini/test.d.ts.map +1 -0
- package/dist/providers/gemini/test.js +67 -0
- package/dist/providers/gemini/test.js.map +1 -0
- package/dist/providers/openclaw/execute.d.ts +1 -1
- package/dist/providers/openclaw/execute.d.ts.map +1 -1
- package/dist/providers/openclaw/execute.js +11 -6
- package/dist/providers/openclaw/execute.js.map +1 -1
- package/dist/providers/openclaw/index.d.ts +1 -1
- package/dist/providers/openclaw/index.d.ts.map +1 -1
- package/dist/providers/openclaw/index.js +13 -3
- package/dist/providers/openclaw/index.js.map +1 -1
- package/dist/providers/openclaw/test.d.ts.map +1 -1
- package/dist/providers/openclaw/test.js +4 -0
- package/dist/providers/openclaw/test.js.map +1 -1
- package/dist/providers/opencode/codec.d.ts +3 -0
- package/dist/providers/opencode/codec.d.ts.map +1 -0
- package/dist/providers/opencode/codec.js +47 -0
- package/dist/providers/opencode/codec.js.map +1 -0
- package/dist/providers/opencode/execute.d.ts +3 -0
- package/dist/providers/opencode/execute.d.ts.map +1 -0
- package/dist/providers/opencode/execute.js +225 -0
- package/dist/providers/opencode/execute.js.map +1 -0
- package/dist/providers/opencode/index.d.ts +3 -0
- package/dist/providers/opencode/index.d.ts.map +1 -0
- package/dist/providers/opencode/index.js +64 -0
- package/dist/providers/opencode/index.js.map +1 -0
- package/dist/providers/opencode/parse.d.ts +19 -0
- package/dist/providers/opencode/parse.d.ts.map +1 -0
- package/dist/providers/opencode/parse.js +145 -0
- package/dist/providers/opencode/parse.js.map +1 -0
- package/dist/providers/opencode/test.d.ts +3 -0
- package/dist/providers/opencode/test.d.ts.map +1 -0
- package/dist/providers/opencode/test.js +60 -0
- package/dist/providers/opencode/test.js.map +1 -0
- package/dist/providers/pi/codec.d.ts +7 -0
- package/dist/providers/pi/codec.d.ts.map +1 -0
- package/dist/providers/pi/codec.js +45 -0
- package/dist/providers/pi/codec.js.map +1 -0
- package/dist/providers/pi/execute.d.ts +3 -0
- package/dist/providers/pi/execute.d.ts.map +1 -0
- package/dist/providers/pi/execute.js +300 -0
- package/dist/providers/pi/execute.js.map +1 -0
- package/dist/providers/pi/index.d.ts +3 -0
- package/dist/providers/pi/index.d.ts.map +1 -0
- package/dist/providers/pi/index.js +66 -0
- package/dist/providers/pi/index.js.map +1 -0
- package/dist/providers/pi/parse.d.ts +18 -0
- package/dist/providers/pi/parse.d.ts.map +1 -0
- package/dist/providers/pi/parse.js +182 -0
- package/dist/providers/pi/parse.js.map +1 -0
- package/dist/providers/pi/test.d.ts +3 -0
- package/dist/providers/pi/test.d.ts.map +1 -0
- package/dist/providers/pi/test.js +60 -0
- package/dist/providers/pi/test.js.map +1 -0
- package/dist/providers/process/execute.d.ts +1 -1
- package/dist/providers/process/execute.d.ts.map +1 -1
- package/dist/providers/process/execute.js +46 -8
- package/dist/providers/process/execute.js.map +1 -1
- package/dist/providers/process/index.d.ts +1 -1
- package/dist/providers/process/index.d.ts.map +1 -1
- package/dist/providers/process/index.js +18 -4
- package/dist/providers/process/index.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +16 -8
- package/dist/registry.js.map +1 -1
- package/dist/types.d.ts +325 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +23 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/ask-user-question.d.ts +50 -0
- package/dist/utils/ask-user-question.d.ts.map +1 -0
- package/dist/utils/ask-user-question.js +32 -0
- package/dist/utils/ask-user-question.js.map +1 -0
- package/dist/utils/auth.d.ts +29 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +243 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/binary.d.ts.map +1 -1
- package/dist/utils/binary.js +29 -6
- package/dist/utils/binary.js.map +1 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +18 -0
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/execute-all.d.ts +20 -0
- package/dist/utils/execute-all.d.ts.map +1 -0
- package/dist/utils/execute-all.js +46 -0
- package/dist/utils/execute-all.js.map +1 -0
- package/dist/utils/instructions.d.ts +7 -0
- package/dist/utils/instructions.d.ts.map +1 -0
- package/dist/utils/instructions.js +21 -0
- package/dist/utils/instructions.js.map +1 -0
- package/dist/utils/model-cache.d.ts +11 -0
- package/dist/utils/model-cache.d.ts.map +1 -0
- package/dist/utils/model-cache.js +17 -0
- package/dist/utils/model-cache.js.map +1 -0
- package/dist/utils/process.d.ts +4 -0
- package/dist/utils/process.d.ts.map +1 -1
- package/dist/utils/process.js +46 -5
- package/dist/utils/process.js.map +1 -1
- package/dist/utils/runtime-config.d.ts +34 -0
- package/dist/utils/runtime-config.d.ts.map +1 -0
- package/dist/utils/runtime-config.js +71 -0
- package/dist/utils/runtime-config.js.map +1 -0
- package/dist/utils/runtime-homes.d.ts +13 -0
- package/dist/utils/runtime-homes.d.ts.map +1 -0
- package/dist/utils/runtime-homes.js +41 -0
- package/dist/utils/runtime-homes.js.map +1 -0
- package/dist/utils/skills.d.ts +152 -1
- package/dist/utils/skills.d.ts.map +1 -1
- package/dist/utils/skills.js +352 -0
- package/dist/utils/skills.js.map +1 -1
- package/dist/utils/workspace.d.ts +55 -0
- package/dist/utils/workspace.d.ts.map +1 -0
- package/dist/utils/workspace.js +89 -0
- package/dist/utils/workspace.js.map +1 -0
- package/package.json +5 -2
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
|
+
/** Static declaration of what a provider supports. */
|
|
2
|
+
export interface ProviderCapabilities {
|
|
3
|
+
sessions: boolean;
|
|
4
|
+
modelDiscovery: boolean;
|
|
5
|
+
quotaProbing: boolean;
|
|
6
|
+
mcp: boolean;
|
|
7
|
+
skills: boolean;
|
|
8
|
+
instructions: boolean;
|
|
9
|
+
workspace: boolean;
|
|
10
|
+
}
|
|
1
11
|
export interface ProviderModule {
|
|
2
12
|
type: string;
|
|
13
|
+
capabilities: ProviderCapabilities;
|
|
3
14
|
execute(ctx: ExecutionContext): Promise<ExecutionResult>;
|
|
15
|
+
createSession?(ctx: SessionContext): Promise<AgentSession>;
|
|
4
16
|
testEnvironment(ctx: EnvironmentTestContext): Promise<EnvironmentTestResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Enumerate every auth path this provider supports and report which are
|
|
19
|
+
* currently present. Cheap: inspects env vars and files only — does not
|
|
20
|
+
* spawn the binary. Callers should use the `hasSubscription` / `hasApiKey`
|
|
21
|
+
* / `hasBedrock` helpers rather than interpreting the report directly when
|
|
22
|
+
* they only want a yes/no for a specific billing mode.
|
|
23
|
+
*/
|
|
24
|
+
resolveAuth(ctx?: AuthResolveContext): Promise<AuthReport>;
|
|
5
25
|
sessionCodec?: SessionCodec;
|
|
6
|
-
|
|
26
|
+
/** List available models. Pass cacheTtlMs to cache results (0 = no cache, default). */
|
|
27
|
+
listModels?(options?: {
|
|
28
|
+
cacheTtlMs?: number;
|
|
29
|
+
}): Promise<ProviderModel[]>;
|
|
30
|
+
/** Check current quota/rate limit status. Not all providers support this. */
|
|
31
|
+
checkQuota?(ctx: QuotaContext): Promise<QuotaStatus>;
|
|
7
32
|
}
|
|
8
33
|
export interface ExecutionContext {
|
|
9
34
|
prompt: string;
|
|
@@ -15,6 +40,12 @@ export interface ExecutionContext {
|
|
|
15
40
|
config?: ProviderConfig;
|
|
16
41
|
onOutput?: (stream: "stdout" | "stderr", chunk: string) => void | Promise<void>;
|
|
17
42
|
onEvent?: (event: StreamEvent) => void | Promise<void>;
|
|
43
|
+
onStart?: (pid: number) => void;
|
|
44
|
+
/** AbortSignal to cancel execution. When aborted, the process receives SIGTERM
|
|
45
|
+
* followed by SIGKILL after the grace period. */
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
/** Called at key execution lifecycle phases (preparing, spawning, running, etc.). */
|
|
48
|
+
onLifecycle?: (event: LifecycleEvent) => void;
|
|
18
49
|
}
|
|
19
50
|
export interface ProviderConfig {
|
|
20
51
|
command?: string;
|
|
@@ -28,30 +59,71 @@ export interface ProviderConfig {
|
|
|
28
59
|
instructionsFile?: string;
|
|
29
60
|
mcpServers?: McpServerConfig[];
|
|
30
61
|
extraArgs?: string[];
|
|
62
|
+
search?: boolean;
|
|
63
|
+
sandbox?: boolean;
|
|
64
|
+
thinking?: string;
|
|
65
|
+
mode?: string;
|
|
66
|
+
/** Run the agent in an isolated workspace. The library creates a worktree
|
|
67
|
+
* before execution and uses it as the working directory. */
|
|
68
|
+
workspace?: {
|
|
69
|
+
strategy: "worktree";
|
|
70
|
+
baseBranch?: string;
|
|
71
|
+
branchName?: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export interface QuotaStatus {
|
|
75
|
+
/** Whether the provider currently has available capacity */
|
|
76
|
+
available: boolean;
|
|
77
|
+
/** Remaining tokens in current window, if known */
|
|
78
|
+
remainingTokens?: number;
|
|
79
|
+
/** When the current rate limit window resets, if known */
|
|
80
|
+
resetAt?: string;
|
|
81
|
+
/** Billing type detected */
|
|
82
|
+
billingType: "api" | "subscription" | "metered_api";
|
|
83
|
+
/** Additional provider-specific info */
|
|
84
|
+
detail?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
export interface QuotaContext {
|
|
87
|
+
config?: ProviderConfig;
|
|
88
|
+
env?: Record<string, string>;
|
|
31
89
|
}
|
|
90
|
+
/** Final outcome of a single-turn execution. */
|
|
91
|
+
export type ExecutionStatus = "completed" | "failed" | "aborted" | "timeout" | "blocked";
|
|
92
|
+
/** Live state of an interactive session. */
|
|
93
|
+
export type SessionState = "idle" | "thinking" | "tool_executing" | "waiting_for_approval" | "waiting_for_input" | "closed";
|
|
94
|
+
/** Token usage for a single model within a run. */
|
|
95
|
+
export interface TokenUsage {
|
|
96
|
+
inputTokens: number;
|
|
97
|
+
outputTokens: number;
|
|
98
|
+
cachedInputTokens?: number;
|
|
99
|
+
cacheCreationInputTokens?: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get aggregate usage across all models. Convenience for when you don't
|
|
103
|
+
* care about per-model breakdown.
|
|
104
|
+
*/
|
|
105
|
+
export declare function aggregateUsage(usage: Record<string, TokenUsage> | undefined): TokenUsage | null;
|
|
32
106
|
export interface ExecutionResult {
|
|
33
107
|
runId: string;
|
|
34
108
|
exitCode: number | null;
|
|
35
109
|
signal: string | null;
|
|
36
|
-
|
|
110
|
+
status: ExecutionStatus;
|
|
37
111
|
startedAt: string;
|
|
38
112
|
completedAt: string;
|
|
39
113
|
durationMs: number;
|
|
40
114
|
errorMessage: string | null;
|
|
41
115
|
errorCode: string | null;
|
|
42
|
-
usage?:
|
|
43
|
-
inputTokens: number;
|
|
44
|
-
outputTokens: number;
|
|
45
|
-
cachedInputTokens?: number;
|
|
46
|
-
};
|
|
116
|
+
usage?: Record<string, TokenUsage>;
|
|
47
117
|
costUsd: number | null;
|
|
48
118
|
model: string | null;
|
|
49
119
|
summary: string | null;
|
|
50
120
|
sessionParams: Record<string, unknown> | null;
|
|
51
121
|
sessionDisplayId: string | null;
|
|
52
122
|
clearSession: boolean;
|
|
53
|
-
billingType: "api" | "subscription" | null;
|
|
123
|
+
billingType: "api" | "subscription" | "metered_api" | null;
|
|
54
124
|
raw?: Record<string, unknown> | null;
|
|
125
|
+
/** If the run used a workspace, this contains the workspace handle for diffing/cleanup */
|
|
126
|
+
workspace?: import("./utils/workspace.js").PreparedWorkspace;
|
|
55
127
|
}
|
|
56
128
|
export type StreamEvent = {
|
|
57
129
|
type: "system";
|
|
@@ -69,6 +141,7 @@ export type StreamEvent = {
|
|
|
69
141
|
timestamp: string;
|
|
70
142
|
} | {
|
|
71
143
|
type: "tool_call";
|
|
144
|
+
callId?: string;
|
|
72
145
|
name: string;
|
|
73
146
|
input: unknown;
|
|
74
147
|
timestamp: string;
|
|
@@ -85,6 +158,25 @@ export type StreamEvent = {
|
|
|
85
158
|
isError: boolean;
|
|
86
159
|
timestamp: string;
|
|
87
160
|
};
|
|
161
|
+
export type LifecycleEvent = {
|
|
162
|
+
phase: "preparing";
|
|
163
|
+
step: "workspace" | "skills" | "auth" | "instructions" | "binary";
|
|
164
|
+
} | {
|
|
165
|
+
phase: "spawning";
|
|
166
|
+
} | {
|
|
167
|
+
phase: "running";
|
|
168
|
+
pid: number;
|
|
169
|
+
} | {
|
|
170
|
+
phase: "waiting_for_input";
|
|
171
|
+
request: UserInputRequest;
|
|
172
|
+
} | {
|
|
173
|
+
phase: "completed";
|
|
174
|
+
} | {
|
|
175
|
+
phase: "cancelled";
|
|
176
|
+
} | {
|
|
177
|
+
phase: "error";
|
|
178
|
+
message: string;
|
|
179
|
+
};
|
|
88
180
|
export interface SessionCodec {
|
|
89
181
|
deserialize(raw: unknown): Record<string, unknown> | null;
|
|
90
182
|
serialize(params: Record<string, unknown> | null): Record<string, unknown> | null;
|
|
@@ -97,6 +189,8 @@ export interface EnvironmentTestContext {
|
|
|
97
189
|
export interface EnvironmentTestResult {
|
|
98
190
|
providerType: string;
|
|
99
191
|
status: "pass" | "warn" | "fail";
|
|
192
|
+
/** Structured auth report: every supported auth path with presence state. */
|
|
193
|
+
auth: AuthReport;
|
|
100
194
|
checks: EnvironmentCheck[];
|
|
101
195
|
testedAt: string;
|
|
102
196
|
}
|
|
@@ -107,6 +201,55 @@ export interface EnvironmentCheck {
|
|
|
107
201
|
detail?: string;
|
|
108
202
|
hint?: string;
|
|
109
203
|
}
|
|
204
|
+
/** How a provider is authenticated. Determines billing behavior at runtime. */
|
|
205
|
+
export type AuthMethod = "api_key" | "bedrock" | "subscription";
|
|
206
|
+
/** Where an auth credential lives. */
|
|
207
|
+
export type AuthSource =
|
|
208
|
+
/** Single environment variable, e.g. OPENAI_API_KEY. */
|
|
209
|
+
{
|
|
210
|
+
kind: "env";
|
|
211
|
+
var: string;
|
|
212
|
+
}
|
|
213
|
+
/** Multiple env vars that together form one credential, e.g. AWS creds. */
|
|
214
|
+
| {
|
|
215
|
+
kind: "env_combo";
|
|
216
|
+
vars: string[];
|
|
217
|
+
}
|
|
218
|
+
/** A file on disk, e.g. ~/.codex/auth.json. Path is already resolved. */
|
|
219
|
+
| {
|
|
220
|
+
kind: "file";
|
|
221
|
+
path: string;
|
|
222
|
+
}
|
|
223
|
+
/** macOS keychain entry. Cannot be read silently — present will be "unknown". */
|
|
224
|
+
| {
|
|
225
|
+
kind: "keychain";
|
|
226
|
+
service: string;
|
|
227
|
+
account?: string;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* One auth path this provider supports, with its current presence state.
|
|
231
|
+
*
|
|
232
|
+
* `present` values:
|
|
233
|
+
* - `true`: the source exists / env var is set and non-empty.
|
|
234
|
+
* - `false`: the source does not exist / env var is unset or empty.
|
|
235
|
+
* - `"unknown"`: we can't check without side-effects (e.g. macOS keychain
|
|
236
|
+
* would prompt the user). Safe-by-default: sugar helpers treat this as
|
|
237
|
+
* not-present.
|
|
238
|
+
*/
|
|
239
|
+
export interface AuthOption {
|
|
240
|
+
method: AuthMethod;
|
|
241
|
+
source: AuthSource;
|
|
242
|
+
present: boolean | "unknown";
|
|
243
|
+
}
|
|
244
|
+
/** Full auth report for a provider. */
|
|
245
|
+
export interface AuthReport {
|
|
246
|
+
providerType: string;
|
|
247
|
+
options: AuthOption[];
|
|
248
|
+
}
|
|
249
|
+
/** Optional context for auth resolution (override env vars for testing). */
|
|
250
|
+
export interface AuthResolveContext {
|
|
251
|
+
env?: Record<string, string>;
|
|
252
|
+
}
|
|
110
253
|
export interface ProviderModel {
|
|
111
254
|
id: string;
|
|
112
255
|
name: string;
|
|
@@ -118,4 +261,178 @@ export interface McpServerConfig {
|
|
|
118
261
|
args?: string[];
|
|
119
262
|
env?: Record<string, string>;
|
|
120
263
|
}
|
|
264
|
+
/** Context for creating a persistent multi-turn session. */
|
|
265
|
+
export interface SessionContext {
|
|
266
|
+
cwd?: string;
|
|
267
|
+
env?: Record<string, string>;
|
|
268
|
+
config?: ProviderConfig;
|
|
269
|
+
/** Resume an existing session. If omitted, starts fresh. */
|
|
270
|
+
sessionParams?: Record<string, unknown> | null;
|
|
271
|
+
/** AbortSignal to cancel the session. When aborted, the session is closed
|
|
272
|
+
* and the underlying process is terminated. */
|
|
273
|
+
signal?: AbortSignal;
|
|
274
|
+
/** Called for every stream event across all turns. */
|
|
275
|
+
onEvent?: (event: StreamEvent) => void | Promise<void>;
|
|
276
|
+
/** Called for raw stdout/stderr output across all turns. */
|
|
277
|
+
onOutput?: (stream: "stdout" | "stderr", chunk: string) => void | Promise<void>;
|
|
278
|
+
/** Called at key execution lifecycle phases (preparing, spawning, running, etc.). */
|
|
279
|
+
onLifecycle?: (event: LifecycleEvent) => void;
|
|
280
|
+
/**
|
|
281
|
+
* Called when the agent needs confirmation or user input before proceeding
|
|
282
|
+
* with a tool call. This covers both regular tool permissions (e.g. Bash,
|
|
283
|
+
* Write) and interactive tools like AskUserQuestion.
|
|
284
|
+
*
|
|
285
|
+
* Use `parseAskUserQuestion(req)` to detect structured question prompts
|
|
286
|
+
* and return answers via `updatedInput`.
|
|
287
|
+
*
|
|
288
|
+
* Return `{ allow: true }` to proceed, `{ allow: false }` to deny.
|
|
289
|
+
* If not provided, all tool calls are auto-allowed.
|
|
290
|
+
*/
|
|
291
|
+
onUserInputRequest?: (req: UserInputRequest) => Promise<UserInputResponse>;
|
|
292
|
+
/**
|
|
293
|
+
* Called when an MCP server requests user input (form fields, multiple
|
|
294
|
+
* choice, URL, etc.). Return `{ action: "accept", content: {...} }` to
|
|
295
|
+
* provide the input, `{ action: "decline" }` to refuse, or
|
|
296
|
+
* `{ action: "cancel" }` to abort the current turn.
|
|
297
|
+
*
|
|
298
|
+
* If not provided, all elicitations are declined.
|
|
299
|
+
*/
|
|
300
|
+
onElicitation?: (req: ElicitationRequest) => Promise<ElicitationResponse>;
|
|
301
|
+
/**
|
|
302
|
+
* Called when the CLI needs the host to run a hook callback.
|
|
303
|
+
* If not provided, hook callbacks return an empty result.
|
|
304
|
+
*/
|
|
305
|
+
onHookCallback?: (req: HookCallbackRequest) => Promise<HookCallbackResponse>;
|
|
306
|
+
}
|
|
307
|
+
/** A persistent session handle for multi-turn conversations. */
|
|
308
|
+
export interface AgentSession {
|
|
309
|
+
readonly sessionId: string | null;
|
|
310
|
+
readonly state: SessionState;
|
|
311
|
+
/** Send a user message and wait for the agent's turn to complete. */
|
|
312
|
+
send(message: string): Promise<TurnResult>;
|
|
313
|
+
/** Gracefully interrupt the current turn. */
|
|
314
|
+
interrupt(): Promise<void>;
|
|
315
|
+
/** Terminate the session and kill the underlying process. */
|
|
316
|
+
close(): Promise<void>;
|
|
317
|
+
}
|
|
318
|
+
/** Result of a single turn within a session. */
|
|
319
|
+
export interface TurnResult {
|
|
320
|
+
summary: string | null;
|
|
321
|
+
usage?: Record<string, TokenUsage>;
|
|
322
|
+
costUsd: number | null;
|
|
323
|
+
status: "completed" | "failed" | "max_turns" | "max_budget" | "aborted";
|
|
324
|
+
errorCode: string | null;
|
|
325
|
+
errorMessage: string | null;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Describes a tool the agent wants to use and needs confirmation or user
|
|
329
|
+
* input before proceeding. This is the unified callback for both regular
|
|
330
|
+
* tool permissions (Bash, Write, etc.) and interactive tools like
|
|
331
|
+
* AskUserQuestion.
|
|
332
|
+
*
|
|
333
|
+
* For AskUserQuestion, use `parseAskUserQuestion(req)` to extract the
|
|
334
|
+
* structured questions and return answers via `updatedInput`.
|
|
335
|
+
*/
|
|
336
|
+
export interface UserInputRequest {
|
|
337
|
+
toolName: string;
|
|
338
|
+
input: Record<string, unknown>;
|
|
339
|
+
toolUseId: string;
|
|
340
|
+
/** Human-readable title for the tool action. */
|
|
341
|
+
title?: string;
|
|
342
|
+
/** Display name of the tool. */
|
|
343
|
+
displayName?: string;
|
|
344
|
+
/** Why the agent decided to use this tool. */
|
|
345
|
+
description?: string;
|
|
346
|
+
/** ID of the sub-agent making the request, if any. */
|
|
347
|
+
agentId?: string;
|
|
348
|
+
}
|
|
349
|
+
/** Host response to a tool request. */
|
|
350
|
+
export interface UserInputResponse {
|
|
351
|
+
allow: boolean;
|
|
352
|
+
message?: string;
|
|
353
|
+
/** Optionally modify the tool's input before execution (e.g. answers for AskUserQuestion). */
|
|
354
|
+
updatedInput?: Record<string, unknown>;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Sent when a server (typically an MCP tool-server running inside the Claude
|
|
358
|
+
* process) needs user input. The request can represent anything from a simple
|
|
359
|
+
* yes/no confirmation to a rich multi-field form combining dropdowns,
|
|
360
|
+
* checkboxes, text fields, and number inputs.
|
|
361
|
+
*
|
|
362
|
+
* The `requestedSchema` is a standard JSON Schema (type: "object") whose
|
|
363
|
+
* `properties` define the form fields. Supported property types:
|
|
364
|
+
*
|
|
365
|
+
* | Schema pattern | Renders as |
|
|
366
|
+
* |---|---|
|
|
367
|
+
* | `{ "type": "string", "oneOf": [{ "const": "a", "title": "A" }, ...] }` | Single-select dropdown / radio |
|
|
368
|
+
* | `{ "type": "string", "enum": ["x", "y"] }` | Single-select (legacy) |
|
|
369
|
+
* | `{ "type": "array", "items": { "anyOf": [{ "const": "a" }, ...] } }` | Multi-select checkboxes |
|
|
370
|
+
* | `{ "type": "string" }` | Freeform text input |
|
|
371
|
+
* | `{ "type": "string", "format": "email" \| "uri" \| "date" }` | Validated text input |
|
|
372
|
+
* | `{ "type": "integer", "minimum": 1, "maximum": 10 }` | Number input |
|
|
373
|
+
* | `{ "type": "boolean" }` | Toggle / checkbox |
|
|
374
|
+
*
|
|
375
|
+
* A single form can mix all of these — e.g., a dropdown for language, checkboxes
|
|
376
|
+
* for features, and a freeform "notes" field.
|
|
377
|
+
*
|
|
378
|
+
* **Example — multiple choice + freeform:**
|
|
379
|
+
* ```json
|
|
380
|
+
* { "type": "object", "properties": {
|
|
381
|
+
* "framework": { "type": "string", "oneOf": [
|
|
382
|
+
* { "const": "express", "title": "Express" },
|
|
383
|
+
* { "const": "fastify", "title": "Fastify" },
|
|
384
|
+
* { "const": "hono", "title": "Hono" }
|
|
385
|
+
* ]},
|
|
386
|
+
* "features": { "type": "array", "items": {
|
|
387
|
+
* "anyOf": [
|
|
388
|
+
* { "const": "auth", "title": "Authentication" },
|
|
389
|
+
* { "const": "db", "title": "Database" },
|
|
390
|
+
* { "const": "ws", "title": "WebSockets" }
|
|
391
|
+
* ]
|
|
392
|
+
* }},
|
|
393
|
+
* "notes": { "type": "string" }
|
|
394
|
+
* },
|
|
395
|
+
* "required": ["framework"]
|
|
396
|
+
* }
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
export interface ElicitationRequest {
|
|
400
|
+
/**
|
|
401
|
+
* Name of the MCP server requesting input. Maps to the `mcp_server_name`
|
|
402
|
+
* field in the Claude protocol. Display this so the user knows which
|
|
403
|
+
* server is asking for input.
|
|
404
|
+
*/
|
|
405
|
+
mcpServerName: string;
|
|
406
|
+
/** Human-readable prompt describing what input is needed. */
|
|
407
|
+
message: string;
|
|
408
|
+
/** How to present the request: "form" for inline input, "url" to open a browser. */
|
|
409
|
+
mode?: "form" | "url";
|
|
410
|
+
/** URL to open when mode is "url". */
|
|
411
|
+
url?: string;
|
|
412
|
+
/** Unique ID for this elicitation, used for deduplication. */
|
|
413
|
+
elicitationId?: string;
|
|
414
|
+
/**
|
|
415
|
+
* JSON Schema (type: "object") describing the expected input. Each property
|
|
416
|
+
* in `properties` is a form field. See the type-level JSDoc for the full
|
|
417
|
+
* list of supported property types and examples.
|
|
418
|
+
*/
|
|
419
|
+
requestedSchema?: Record<string, unknown>;
|
|
420
|
+
}
|
|
421
|
+
/** Host response to an elicitation request. */
|
|
422
|
+
export interface ElicitationResponse {
|
|
423
|
+
/** "accept" to provide content, "decline" to refuse, "cancel" to abort the turn. */
|
|
424
|
+
action: "accept" | "decline" | "cancel";
|
|
425
|
+
/** The user's input, matching the requestedSchema. Only required when action is "accept". */
|
|
426
|
+
content?: Record<string, unknown>;
|
|
427
|
+
}
|
|
428
|
+
/** Sent when the CLI needs the host to execute a hook callback. */
|
|
429
|
+
export interface HookCallbackRequest {
|
|
430
|
+
callbackId: string;
|
|
431
|
+
input: Record<string, unknown>;
|
|
432
|
+
toolUseId?: string;
|
|
433
|
+
}
|
|
434
|
+
/** Host response to a hook callback. */
|
|
435
|
+
export interface HookCallbackResponse {
|
|
436
|
+
result?: Record<string, unknown>;
|
|
437
|
+
}
|
|
121
438
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;CACpB;AAGD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,oBAAoB,CAAC;IACnC,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACzD,aAAa,CAAC,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAC3D,eAAe,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC7E;;;;;;OAMG;IACH,WAAW,CAAC,GAAG,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3D,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,uFAAuF;IACvF,UAAU,CAAC,CAAC,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CA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AAE,OAAO,CAAC,CAAC;CAC3C;AAED,+CAA+C;AAC/C,MAAM,WAAW,mBAAmB;IAClC,oFAAoF;IACpF,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IACxC,6FAA6F;IAC7F,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAMD,mEAAmE;AACnE,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wCAAwC;AACxC,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC"}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Get aggregate usage across all models. Convenience for when you don't
|
|
3
|
+
* care about per-model breakdown.
|
|
4
|
+
*/
|
|
5
|
+
export function aggregateUsage(usage) {
|
|
6
|
+
if (!usage)
|
|
7
|
+
return null;
|
|
8
|
+
const entries = Object.values(usage);
|
|
9
|
+
if (entries.length === 0)
|
|
10
|
+
return null;
|
|
11
|
+
const result = { inputTokens: 0, outputTokens: 0 };
|
|
12
|
+
for (const u of entries) {
|
|
13
|
+
result.inputTokens += u.inputTokens;
|
|
14
|
+
result.outputTokens += u.outputTokens;
|
|
15
|
+
if (u.cachedInputTokens != null) {
|
|
16
|
+
result.cachedInputTokens = (result.cachedInputTokens ?? 0) + u.cachedInputTokens;
|
|
17
|
+
}
|
|
18
|
+
if (u.cacheCreationInputTokens != null) {
|
|
19
|
+
result.cacheCreationInputTokens = (result.cacheCreationInputTokens ?? 0) + u.cacheCreationInputTokens;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
2
24
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAqIA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAA6C;IAC1E,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,MAAM,MAAM,GAAe,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;IAC/D,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,MAAM,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,CAAC;QACpC,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC;YAChC,MAAM,CAAC,iBAAiB,GAAG,CAAC,MAAM,CAAC,iBAAiB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,iBAAiB,CAAC;QACnF,CAAC;QACD,IAAI,CAAC,CAAC,wBAAwB,IAAI,IAAI,EAAE,CAAC;YACvC,MAAM,CAAC,wBAAwB,GAAG,CAAC,MAAM,CAAC,wBAAwB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,wBAAwB,CAAC;QACxG,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { UserInputRequest } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Structured option within an AskUserQuestion prompt.
|
|
4
|
+
*/
|
|
5
|
+
export interface QuestionOption {
|
|
6
|
+
label: string;
|
|
7
|
+
description: string;
|
|
8
|
+
/** Optional preview/detail content for the option. */
|
|
9
|
+
preview?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A single question from the AskUserQuestion tool.
|
|
13
|
+
*
|
|
14
|
+
* Claude uses this tool to ask the user structured questions — for example,
|
|
15
|
+
* choosing between implementation approaches in plan mode. Each question has
|
|
16
|
+
* 2-4 predefined options. Apps typically add a freeform "Other" option when
|
|
17
|
+
* rendering.
|
|
18
|
+
*/
|
|
19
|
+
export interface AskUserQuestion {
|
|
20
|
+
question: string;
|
|
21
|
+
header: string;
|
|
22
|
+
options: QuestionOption[];
|
|
23
|
+
/** When true, the user can select multiple options. */
|
|
24
|
+
multiSelect?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parse an AskUserQuestion tool call from a UserInputRequest.
|
|
28
|
+
*
|
|
29
|
+
* Returns the structured questions array if this is an AskUserQuestion request,
|
|
30
|
+
* or `null` if it's a regular tool request.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* onUserInputRequest: async (req) => {
|
|
35
|
+
* const questions = parseAskUserQuestion(req);
|
|
36
|
+
* if (questions) {
|
|
37
|
+
* // Render choices UI, collect answers
|
|
38
|
+
* const answers: Record<string, string> = {};
|
|
39
|
+
* for (const q of questions) {
|
|
40
|
+
* answers[q.question] = await showChoiceUI(q.options);
|
|
41
|
+
* }
|
|
42
|
+
* return { allow: true, updatedInput: { ...req.input, answers } };
|
|
43
|
+
* }
|
|
44
|
+
* // Handle as regular tool request
|
|
45
|
+
* return { allow: true };
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseAskUserQuestion(req: UserInputRequest): AskUserQuestion[] | null;
|
|
50
|
+
//# sourceMappingURL=ask-user-question.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-user-question.d.ts","sourceRoot":"","sources":["../../src/utils/ask-user-question.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,uDAAuD;IACvD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,gBAAgB,GAAG,eAAe,EAAE,GAAG,IAAI,CAKpF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse an AskUserQuestion tool call from a UserInputRequest.
|
|
3
|
+
*
|
|
4
|
+
* Returns the structured questions array if this is an AskUserQuestion request,
|
|
5
|
+
* or `null` if it's a regular tool request.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* onUserInputRequest: async (req) => {
|
|
10
|
+
* const questions = parseAskUserQuestion(req);
|
|
11
|
+
* if (questions) {
|
|
12
|
+
* // Render choices UI, collect answers
|
|
13
|
+
* const answers: Record<string, string> = {};
|
|
14
|
+
* for (const q of questions) {
|
|
15
|
+
* answers[q.question] = await showChoiceUI(q.options);
|
|
16
|
+
* }
|
|
17
|
+
* return { allow: true, updatedInput: { ...req.input, answers } };
|
|
18
|
+
* }
|
|
19
|
+
* // Handle as regular tool request
|
|
20
|
+
* return { allow: true };
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function parseAskUserQuestion(req) {
|
|
25
|
+
if (req.toolName !== "AskUserQuestion")
|
|
26
|
+
return null;
|
|
27
|
+
const questions = req.input["questions"];
|
|
28
|
+
if (!Array.isArray(questions) || questions.length === 0)
|
|
29
|
+
return null;
|
|
30
|
+
return questions;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ask-user-question.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-user-question.js","sourceRoot":"","sources":["../../src/utils/ask-user-question.ts"],"names":[],"mappings":"AA4BA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAqB;IACxD,IAAI,GAAG,CAAC,QAAQ,KAAK,iBAAiB;QAAE,OAAO,IAAI,CAAC;IACpD,MAAM,SAAS,GAAI,GAAG,CAAC,KAAiC,CAAC,WAAW,CAAC,CAAC;IACtE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACrE,OAAO,SAA8B,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AuthReport, AuthResolveContext, ProviderModule } from "../types.js";
|
|
2
|
+
export interface ResolvedAuth {
|
|
3
|
+
/** How the user is authenticated */
|
|
4
|
+
method: "api_key" | "bedrock" | "oauth" | "subscription";
|
|
5
|
+
/** How usage is billed */
|
|
6
|
+
billingType: "api" | "metered_api" | "subscription";
|
|
7
|
+
/** If the auth method requires model ID transformation (e.g., Bedrock), this resolves it */
|
|
8
|
+
resolveModelId?(requestedModel: string): string;
|
|
9
|
+
/** Cloud region, if applicable (Bedrock) */
|
|
10
|
+
region?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Detect authentication method for a given provider based on environment variables.
|
|
14
|
+
*/
|
|
15
|
+
export declare function detectAuth(providerType: string, env: Record<string, string>): ResolvedAuth;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the auth report for a provider by type. Providers call the matching
|
|
18
|
+
* function from their own `resolveAuth` method; callers can use the helpers
|
|
19
|
+
* below (`hasSubscription`, `hasApiKey`, `hasBedrock`) instead of this
|
|
20
|
+
* directly.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveAuthForProvider(providerType: string, ctx?: AuthResolveContext): Promise<AuthReport>;
|
|
23
|
+
/** True only if a subscription credential is confirmed present on disk. */
|
|
24
|
+
export declare function hasSubscription(provider: ProviderModule, ctx?: AuthResolveContext): Promise<boolean>;
|
|
25
|
+
/** True only if an API key is confirmed set in the env. */
|
|
26
|
+
export declare function hasApiKey(provider: ProviderModule, ctx?: AuthResolveContext): Promise<boolean>;
|
|
27
|
+
/** True only if Bedrock credentials are confirmed present in the env. */
|
|
28
|
+
export declare function hasBedrock(provider: ProviderModule, ctx?: AuthResolveContext): Promise<boolean>;
|
|
29
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/utils/auth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,UAAU,EACV,kBAAkB,EAClB,cAAc,EACf,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,cAAc,CAAC;IACzD,0BAA0B;IAC1B,WAAW,EAAE,KAAK,GAAG,aAAa,GAAG,cAAc,CAAC;IACpD,4FAA4F;IAC5F,cAAc,CAAC,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;IAChD,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA4CD;;GAEG;AACH,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAuD1F;AA0HD;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,kBAAkB,GACvB,OAAO,CAAC,UAAU,CAAC,CAiBrB;AAYD,2EAA2E;AAC3E,wBAAsB,eAAe,CACnC,QAAQ,EAAE,cAAc,EACxB,GAAG,CAAC,EAAE,kBAAkB,GACvB,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED,2DAA2D;AAC3D,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,cAAc,EACxB,GAAG,CAAC,EAAE,kBAAkB,GACvB,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED,yEAAyE;AACzE,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,cAAc,EACxB,GAAG,CAAC,EAAE,kBAAkB,GACvB,OAAO,CAAC,OAAO,CAAC,CAGlB"}
|