@papert-code/sdk-typescript 0.1.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 +372 -0
- package/dist/LICENSE +203 -0
- package/dist/agent.d.ts +47 -0
- package/dist/cli/cli.js +77 -0
- package/dist/cli/sandbox-macos-permissive-closed.sb +32 -0
- package/dist/cli/sandbox-macos-permissive-open.sb +25 -0
- package/dist/cli/sandbox-macos-permissive-proxied.sb +37 -0
- package/dist/cli/sandbox-macos-restrictive-closed.sb +93 -0
- package/dist/cli/sandbox-macos-restrictive-open.sb +96 -0
- package/dist/cli/sandbox-macos-restrictive-proxied.sb +98 -0
- package/dist/cli/vendor/ripgrep/COPYING +3 -0
- package/dist/cli/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/dist/cli/vendor/ripgrep/arm64-linux/rg +0 -0
- package/dist/cli/vendor/ripgrep/x64-darwin/rg +0 -0
- package/dist/cli/vendor/ripgrep/x64-linux/rg +0 -0
- package/dist/cli/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/dist/client.d.ts +32 -0
- package/dist/index.cjs +20 -0
- package/dist/index.d.ts +839 -0
- package/dist/index.mjs +20 -0
- package/package.json +76 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,839 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export interface Annotation {
|
|
4
|
+
type: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Usage {
|
|
8
|
+
input_tokens: number;
|
|
9
|
+
output_tokens: number;
|
|
10
|
+
cache_creation_input_tokens?: number;
|
|
11
|
+
cache_read_input_tokens?: number;
|
|
12
|
+
total_tokens?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ExtendedUsage extends Usage {
|
|
15
|
+
server_tool_use?: {
|
|
16
|
+
web_search_requests: number;
|
|
17
|
+
};
|
|
18
|
+
service_tier?: string;
|
|
19
|
+
cache_creation?: {
|
|
20
|
+
ephemeral_1h_input_tokens: number;
|
|
21
|
+
ephemeral_5m_input_tokens: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface ModelUsage {
|
|
25
|
+
inputTokens: number;
|
|
26
|
+
outputTokens: number;
|
|
27
|
+
cacheReadInputTokens: number;
|
|
28
|
+
cacheCreationInputTokens: number;
|
|
29
|
+
webSearchRequests: number;
|
|
30
|
+
contextWindow: number;
|
|
31
|
+
}
|
|
32
|
+
export interface CLIPermissionDenial {
|
|
33
|
+
tool_name: string;
|
|
34
|
+
tool_use_id: string;
|
|
35
|
+
tool_input: unknown;
|
|
36
|
+
}
|
|
37
|
+
export interface TextBlock {
|
|
38
|
+
type: "text";
|
|
39
|
+
text: string;
|
|
40
|
+
annotations?: Annotation[];
|
|
41
|
+
}
|
|
42
|
+
export interface ThinkingBlock {
|
|
43
|
+
type: "thinking";
|
|
44
|
+
thinking: string;
|
|
45
|
+
signature?: string;
|
|
46
|
+
annotations?: Annotation[];
|
|
47
|
+
}
|
|
48
|
+
export interface ToolUseBlock {
|
|
49
|
+
type: "tool_use";
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
input: unknown;
|
|
53
|
+
annotations?: Annotation[];
|
|
54
|
+
}
|
|
55
|
+
export interface ToolResultBlock {
|
|
56
|
+
type: "tool_result";
|
|
57
|
+
tool_use_id: string;
|
|
58
|
+
content?: string | ContentBlock[];
|
|
59
|
+
is_error?: boolean;
|
|
60
|
+
annotations?: Annotation[];
|
|
61
|
+
}
|
|
62
|
+
export type ContentBlock = TextBlock | ThinkingBlock | ToolUseBlock | ToolResultBlock;
|
|
63
|
+
export interface APIUserMessage {
|
|
64
|
+
role: "user";
|
|
65
|
+
content: string | ContentBlock[];
|
|
66
|
+
}
|
|
67
|
+
export interface APIAssistantMessage {
|
|
68
|
+
id: string;
|
|
69
|
+
type: "message";
|
|
70
|
+
role: "assistant";
|
|
71
|
+
model: string;
|
|
72
|
+
content: ContentBlock[];
|
|
73
|
+
stop_reason?: string | null;
|
|
74
|
+
usage: Usage;
|
|
75
|
+
}
|
|
76
|
+
export interface SDKUserMessage {
|
|
77
|
+
type: "user";
|
|
78
|
+
uuid?: string;
|
|
79
|
+
session_id: string;
|
|
80
|
+
message: APIUserMessage;
|
|
81
|
+
parent_tool_use_id: string | null;
|
|
82
|
+
options?: Record<string, unknown>;
|
|
83
|
+
}
|
|
84
|
+
export interface SDKAssistantMessage {
|
|
85
|
+
type: "assistant";
|
|
86
|
+
uuid: string;
|
|
87
|
+
session_id: string;
|
|
88
|
+
message: APIAssistantMessage;
|
|
89
|
+
parent_tool_use_id: string | null;
|
|
90
|
+
}
|
|
91
|
+
export interface SDKSystemMessage {
|
|
92
|
+
type: "system";
|
|
93
|
+
subtype: string;
|
|
94
|
+
uuid: string;
|
|
95
|
+
session_id: string;
|
|
96
|
+
data?: unknown;
|
|
97
|
+
cwd?: string;
|
|
98
|
+
tools?: string[];
|
|
99
|
+
mcp_servers?: Array<{
|
|
100
|
+
name: string;
|
|
101
|
+
status: string;
|
|
102
|
+
}>;
|
|
103
|
+
model?: string;
|
|
104
|
+
permission_mode?: string;
|
|
105
|
+
slash_commands?: string[];
|
|
106
|
+
papert_code_version?: string;
|
|
107
|
+
output_style?: string;
|
|
108
|
+
agents?: string[];
|
|
109
|
+
skills?: string[];
|
|
110
|
+
capabilities?: Record<string, unknown>;
|
|
111
|
+
compact_metadata?: {
|
|
112
|
+
trigger: "manual" | "auto";
|
|
113
|
+
pre_tokens: number;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export interface SDKResultMessageSuccess {
|
|
117
|
+
type: "result";
|
|
118
|
+
subtype: "success";
|
|
119
|
+
uuid: string;
|
|
120
|
+
session_id: string;
|
|
121
|
+
is_error: false;
|
|
122
|
+
duration_ms: number;
|
|
123
|
+
duration_api_ms: number;
|
|
124
|
+
num_turns: number;
|
|
125
|
+
result: string;
|
|
126
|
+
usage: ExtendedUsage;
|
|
127
|
+
modelUsage?: Record<string, ModelUsage>;
|
|
128
|
+
permission_denials: CLIPermissionDenial[];
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
}
|
|
131
|
+
export interface SDKResultMessageError {
|
|
132
|
+
type: "result";
|
|
133
|
+
subtype: "error_max_turns" | "error_during_execution";
|
|
134
|
+
uuid: string;
|
|
135
|
+
session_id: string;
|
|
136
|
+
is_error: true;
|
|
137
|
+
duration_ms: number;
|
|
138
|
+
duration_api_ms: number;
|
|
139
|
+
num_turns: number;
|
|
140
|
+
usage: ExtendedUsage;
|
|
141
|
+
modelUsage?: Record<string, ModelUsage>;
|
|
142
|
+
permission_denials: CLIPermissionDenial[];
|
|
143
|
+
error?: {
|
|
144
|
+
type?: string;
|
|
145
|
+
message: string;
|
|
146
|
+
[key: string]: unknown;
|
|
147
|
+
};
|
|
148
|
+
[key: string]: unknown;
|
|
149
|
+
}
|
|
150
|
+
export type SDKResultMessage = SDKResultMessageSuccess | SDKResultMessageError;
|
|
151
|
+
export interface MessageStartStreamEvent {
|
|
152
|
+
type: "message_start";
|
|
153
|
+
message: {
|
|
154
|
+
id: string;
|
|
155
|
+
role: "assistant";
|
|
156
|
+
model: string;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export interface ContentBlockStartEvent {
|
|
160
|
+
type: "content_block_start";
|
|
161
|
+
index: number;
|
|
162
|
+
content_block: ContentBlock;
|
|
163
|
+
}
|
|
164
|
+
export type ContentBlockDelta = {
|
|
165
|
+
type: "text_delta";
|
|
166
|
+
text: string;
|
|
167
|
+
} | {
|
|
168
|
+
type: "thinking_delta";
|
|
169
|
+
thinking: string;
|
|
170
|
+
} | {
|
|
171
|
+
type: "input_json_delta";
|
|
172
|
+
partial_json: string;
|
|
173
|
+
};
|
|
174
|
+
export interface ContentBlockDeltaEvent {
|
|
175
|
+
type: "content_block_delta";
|
|
176
|
+
index: number;
|
|
177
|
+
delta: ContentBlockDelta;
|
|
178
|
+
}
|
|
179
|
+
export interface ContentBlockStopEvent {
|
|
180
|
+
type: "content_block_stop";
|
|
181
|
+
index: number;
|
|
182
|
+
}
|
|
183
|
+
export interface MessageStopStreamEvent {
|
|
184
|
+
type: "message_stop";
|
|
185
|
+
}
|
|
186
|
+
export type StreamEvent = MessageStartStreamEvent | ContentBlockStartEvent | ContentBlockDeltaEvent | ContentBlockStopEvent | MessageStopStreamEvent;
|
|
187
|
+
export interface SDKPartialAssistantMessage {
|
|
188
|
+
type: "stream_event";
|
|
189
|
+
uuid: string;
|
|
190
|
+
session_id: string;
|
|
191
|
+
event: StreamEvent;
|
|
192
|
+
parent_tool_use_id: string | null;
|
|
193
|
+
}
|
|
194
|
+
export type PermissionMode = "default" | "plan" | "auto-edit" | "yolo";
|
|
195
|
+
/**
|
|
196
|
+
* TODO: Align with `ToolCallConfirmationDetails`
|
|
197
|
+
*/
|
|
198
|
+
export interface PermissionSuggestion {
|
|
199
|
+
type: "allow" | "deny" | "modify";
|
|
200
|
+
label: string;
|
|
201
|
+
description?: string;
|
|
202
|
+
modifiedInput?: unknown;
|
|
203
|
+
}
|
|
204
|
+
export interface HookRegistration {
|
|
205
|
+
event: string;
|
|
206
|
+
callback_id: string;
|
|
207
|
+
}
|
|
208
|
+
export interface CLIControlInterruptRequest {
|
|
209
|
+
subtype: "interrupt";
|
|
210
|
+
}
|
|
211
|
+
export interface CLIControlPermissionRequest {
|
|
212
|
+
subtype: "can_use_tool";
|
|
213
|
+
tool_name: string;
|
|
214
|
+
tool_use_id: string;
|
|
215
|
+
input: unknown;
|
|
216
|
+
permission_suggestions: PermissionSuggestion[] | null;
|
|
217
|
+
blocked_path: string | null;
|
|
218
|
+
}
|
|
219
|
+
declare enum AuthProviderType {
|
|
220
|
+
DYNAMIC_DISCOVERY = "dynamic_discovery",
|
|
221
|
+
GOOGLE_CREDENTIALS = "google_credentials",
|
|
222
|
+
SERVICE_ACCOUNT_IMPERSONATION = "service_account_impersonation"
|
|
223
|
+
}
|
|
224
|
+
export interface MCPServerConfig {
|
|
225
|
+
command?: string;
|
|
226
|
+
args?: string[];
|
|
227
|
+
env?: Record<string, string>;
|
|
228
|
+
cwd?: string;
|
|
229
|
+
url?: string;
|
|
230
|
+
httpUrl?: string;
|
|
231
|
+
headers?: Record<string, string>;
|
|
232
|
+
tcp?: string;
|
|
233
|
+
timeout?: number;
|
|
234
|
+
trust?: boolean;
|
|
235
|
+
description?: string;
|
|
236
|
+
includeTools?: string[];
|
|
237
|
+
excludeTools?: string[];
|
|
238
|
+
extensionName?: string;
|
|
239
|
+
oauth?: Record<string, unknown>;
|
|
240
|
+
authProviderType?: AuthProviderType;
|
|
241
|
+
targetAudience?: string;
|
|
242
|
+
targetServiceAccount?: string;
|
|
243
|
+
}
|
|
244
|
+
export interface CLIControlInitializeRequest {
|
|
245
|
+
subtype: "initialize";
|
|
246
|
+
hooks?: HookRegistration[] | null;
|
|
247
|
+
sdkMcpServers?: Record<string, MCPServerConfig>;
|
|
248
|
+
mcpServers?: Record<string, MCPServerConfig>;
|
|
249
|
+
agents?: SubagentConfig[];
|
|
250
|
+
}
|
|
251
|
+
export interface CLIControlSetPermissionModeRequest {
|
|
252
|
+
subtype: "set_permission_mode";
|
|
253
|
+
mode: PermissionMode;
|
|
254
|
+
}
|
|
255
|
+
export interface CLIHookCallbackRequest {
|
|
256
|
+
subtype: "hook_callback";
|
|
257
|
+
callback_id: string;
|
|
258
|
+
input: unknown;
|
|
259
|
+
tool_use_id: string | null;
|
|
260
|
+
}
|
|
261
|
+
export interface CLIControlMcpMessageRequest {
|
|
262
|
+
subtype: "mcp_message";
|
|
263
|
+
server_name: string;
|
|
264
|
+
message: {
|
|
265
|
+
jsonrpc?: string;
|
|
266
|
+
method: string;
|
|
267
|
+
params?: Record<string, unknown>;
|
|
268
|
+
id?: string | number | null;
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
export interface CLIControlSetModelRequest {
|
|
272
|
+
subtype: "set_model";
|
|
273
|
+
model: string;
|
|
274
|
+
}
|
|
275
|
+
export interface CLIControlMcpStatusRequest {
|
|
276
|
+
subtype: "mcp_server_status";
|
|
277
|
+
}
|
|
278
|
+
export interface CLIControlSupportedCommandsRequest {
|
|
279
|
+
subtype: "supported_commands";
|
|
280
|
+
}
|
|
281
|
+
export interface CLIControlSchedulerListRequest {
|
|
282
|
+
subtype: "scheduler_list";
|
|
283
|
+
cwd?: string;
|
|
284
|
+
include_disabled?: boolean;
|
|
285
|
+
}
|
|
286
|
+
export interface CLIControlSchedulerStatusRequest {
|
|
287
|
+
subtype: "scheduler_status";
|
|
288
|
+
cwd?: string;
|
|
289
|
+
}
|
|
290
|
+
export interface CLIControlSchedulerAddRequest {
|
|
291
|
+
subtype: "scheduler_add";
|
|
292
|
+
cwd?: string;
|
|
293
|
+
job: Record<string, unknown>;
|
|
294
|
+
}
|
|
295
|
+
export interface CLIControlSchedulerUpdateRequest {
|
|
296
|
+
subtype: "scheduler_update";
|
|
297
|
+
cwd?: string;
|
|
298
|
+
id: string;
|
|
299
|
+
patch: Record<string, unknown>;
|
|
300
|
+
}
|
|
301
|
+
export interface CLIControlSchedulerRemoveRequest {
|
|
302
|
+
subtype: "scheduler_remove";
|
|
303
|
+
cwd?: string;
|
|
304
|
+
id: string;
|
|
305
|
+
}
|
|
306
|
+
export interface CLIControlSchedulerRunRequest {
|
|
307
|
+
subtype: "scheduler_run";
|
|
308
|
+
cwd?: string;
|
|
309
|
+
id: string;
|
|
310
|
+
mode?: "due" | "force";
|
|
311
|
+
}
|
|
312
|
+
export interface CLIControlSchedulerRunsRequest {
|
|
313
|
+
subtype: "scheduler_runs";
|
|
314
|
+
cwd?: string;
|
|
315
|
+
id: string;
|
|
316
|
+
limit?: number;
|
|
317
|
+
}
|
|
318
|
+
export interface CLIControlSchedulerStartRequest {
|
|
319
|
+
subtype: "scheduler_start";
|
|
320
|
+
cwd?: string;
|
|
321
|
+
max_concurrent?: number;
|
|
322
|
+
queue_policy?: "queue" | "skip";
|
|
323
|
+
}
|
|
324
|
+
export interface CLIControlSchedulerStopRequest {
|
|
325
|
+
subtype: "scheduler_stop";
|
|
326
|
+
cwd?: string;
|
|
327
|
+
}
|
|
328
|
+
export type ControlRequestPayload = CLIControlInterruptRequest | CLIControlPermissionRequest | CLIControlInitializeRequest | CLIControlSetPermissionModeRequest | CLIHookCallbackRequest | CLIControlMcpMessageRequest | CLIControlSetModelRequest | CLIControlMcpStatusRequest | CLIControlSupportedCommandsRequest | CLIControlSchedulerListRequest | CLIControlSchedulerStatusRequest | CLIControlSchedulerAddRequest | CLIControlSchedulerUpdateRequest | CLIControlSchedulerRemoveRequest | CLIControlSchedulerRunRequest | CLIControlSchedulerRunsRequest | CLIControlSchedulerStartRequest | CLIControlSchedulerStopRequest;
|
|
329
|
+
export interface CLIControlRequest {
|
|
330
|
+
type: "control_request";
|
|
331
|
+
request_id: string;
|
|
332
|
+
request: ControlRequestPayload;
|
|
333
|
+
}
|
|
334
|
+
export interface ControlResponse {
|
|
335
|
+
subtype: "success";
|
|
336
|
+
request_id: string;
|
|
337
|
+
response: unknown;
|
|
338
|
+
}
|
|
339
|
+
export interface ControlErrorResponse {
|
|
340
|
+
subtype: "error";
|
|
341
|
+
request_id: string;
|
|
342
|
+
error: string | {
|
|
343
|
+
message: string;
|
|
344
|
+
[key: string]: unknown;
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
export interface CLIControlResponse {
|
|
348
|
+
type: "control_response";
|
|
349
|
+
response: ControlResponse | ControlErrorResponse;
|
|
350
|
+
}
|
|
351
|
+
export interface ControlCancelRequest {
|
|
352
|
+
type: "control_cancel_request";
|
|
353
|
+
request_id?: string;
|
|
354
|
+
}
|
|
355
|
+
export type ControlMessage = CLIControlRequest | CLIControlResponse | ControlCancelRequest;
|
|
356
|
+
/**
|
|
357
|
+
* Union of all SDK message types
|
|
358
|
+
*/
|
|
359
|
+
export type SDKMessage = SDKUserMessage | SDKAssistantMessage | SDKSystemMessage | SDKResultMessage | SDKPartialAssistantMessage;
|
|
360
|
+
export declare function isSDKUserMessage(msg: any): msg is SDKUserMessage;
|
|
361
|
+
export declare function isSDKAssistantMessage(msg: any): msg is SDKAssistantMessage;
|
|
362
|
+
export declare function isSDKSystemMessage(msg: any): msg is SDKSystemMessage;
|
|
363
|
+
export declare function isSDKResultMessage(msg: any): msg is SDKResultMessage;
|
|
364
|
+
export declare function isSDKPartialAssistantMessage(msg: any): msg is SDKPartialAssistantMessage;
|
|
365
|
+
export declare function isControlRequest(msg: any): msg is CLIControlRequest;
|
|
366
|
+
export declare function isControlResponse(msg: any): msg is CLIControlResponse;
|
|
367
|
+
export declare function isControlCancel(msg: any): msg is ControlCancelRequest;
|
|
368
|
+
export type SubagentLevel = "session";
|
|
369
|
+
export interface ModelConfig {
|
|
370
|
+
model?: string;
|
|
371
|
+
temp?: number;
|
|
372
|
+
top_p?: number;
|
|
373
|
+
}
|
|
374
|
+
export interface RunConfig {
|
|
375
|
+
max_time_minutes?: number;
|
|
376
|
+
max_turns?: number;
|
|
377
|
+
}
|
|
378
|
+
export interface SubagentConfig {
|
|
379
|
+
name: string;
|
|
380
|
+
description: string;
|
|
381
|
+
tools?: string[];
|
|
382
|
+
systemPrompt: string;
|
|
383
|
+
level: SubagentLevel;
|
|
384
|
+
filePath?: string;
|
|
385
|
+
modelConfig?: Partial<ModelConfig>;
|
|
386
|
+
runConfig?: Partial<RunConfig>;
|
|
387
|
+
color?: string;
|
|
388
|
+
readonly isBuiltin?: boolean;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Transport interface for SDK-CLI communication
|
|
392
|
+
*
|
|
393
|
+
* The Transport abstraction enables communication between SDK and CLI via different mechanisms:
|
|
394
|
+
* - ProcessTransport: Local subprocess via stdin/stdout (initial implementation)
|
|
395
|
+
* - HttpTransport: Remote CLI via HTTP (future)
|
|
396
|
+
* - WebSocketTransport: Remote CLI via WebSocket (future)
|
|
397
|
+
*/
|
|
398
|
+
export interface Transport {
|
|
399
|
+
close(): Promise<void>;
|
|
400
|
+
waitForExit(): Promise<void>;
|
|
401
|
+
write(message: string): void;
|
|
402
|
+
readMessages(): AsyncGenerator<unknown, void, unknown>;
|
|
403
|
+
readonly isReady: boolean;
|
|
404
|
+
readonly exitError: Error | null;
|
|
405
|
+
}
|
|
406
|
+
export type ToolInput = Record<string, unknown>;
|
|
407
|
+
export type CanUseTool = (toolName: string, input: ToolInput, options: {
|
|
408
|
+
signal: AbortSignal;
|
|
409
|
+
suggestions?: PermissionSuggestion[] | null;
|
|
410
|
+
}) => Promise<PermissionResult>;
|
|
411
|
+
export type PermissionResult = {
|
|
412
|
+
behavior: "allow";
|
|
413
|
+
updatedInput: ToolInput;
|
|
414
|
+
} | {
|
|
415
|
+
behavior: "deny";
|
|
416
|
+
message: string;
|
|
417
|
+
interrupt?: boolean;
|
|
418
|
+
};
|
|
419
|
+
export interface ExternalMcpServerConfig {
|
|
420
|
+
command: string;
|
|
421
|
+
args?: string[];
|
|
422
|
+
env?: Record<string, string>;
|
|
423
|
+
}
|
|
424
|
+
export interface SdkMcpServerConfig {
|
|
425
|
+
connect: (transport: unknown) => Promise<void>;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Configuration options for creating a query session with the Papert CLI.
|
|
429
|
+
*/
|
|
430
|
+
export interface QueryOptions {
|
|
431
|
+
/**
|
|
432
|
+
* The working directory for the query session.
|
|
433
|
+
* This determines the context in which file operations and commands are executed.
|
|
434
|
+
* @default process.cwd()
|
|
435
|
+
*/
|
|
436
|
+
cwd?: string;
|
|
437
|
+
/**
|
|
438
|
+
* The AI model to use for the query session.
|
|
439
|
+
* This takes precedence over the environment variables `OPENAI_MODEL` and `PAPERT_MODEL`
|
|
440
|
+
* @example 'papert-max', 'papert-plus', 'papert-turbo'
|
|
441
|
+
*/
|
|
442
|
+
model?: string;
|
|
443
|
+
/**
|
|
444
|
+
* Path to the Papert CLI executable or runtime specification.
|
|
445
|
+
*
|
|
446
|
+
* Supports multiple formats:
|
|
447
|
+
* - 'papert' -> native binary (auto-detected from PATH)
|
|
448
|
+
* - '/path/to/papert' -> native binary (explicit path)
|
|
449
|
+
* - '/path/to/cli.js' -> Node.js bundle (default for .js files)
|
|
450
|
+
* - '/path/to/index.ts' -> TypeScript source (requires tsx)
|
|
451
|
+
* - 'bun:/path/to/cli.js' -> Force Bun runtime
|
|
452
|
+
* - 'node:/path/to/cli.js' -> Force Node.js runtime
|
|
453
|
+
* - 'tsx:/path/to/index.ts' -> Force tsx runtime
|
|
454
|
+
* - 'deno:/path/to/cli.ts' -> Force Deno runtime
|
|
455
|
+
*
|
|
456
|
+
* If not provided, the SDK will auto-detect the CLI in this order:
|
|
457
|
+
* 1. Bundled CLI inside the SDK package (dist/cli/cli.js)
|
|
458
|
+
* 2. PAPERT_CODE_CLI_PATH environment variable
|
|
459
|
+
* 3. ~/.volta/bin/papert
|
|
460
|
+
* 4. ~/.npm-global/bin/papert
|
|
461
|
+
* 5. /usr/local/bin/papert
|
|
462
|
+
* 6. ~/.local/bin/papert
|
|
463
|
+
* 7. ~/node_modules/.bin/papert
|
|
464
|
+
* 8. ~/.yarn/bin/papert
|
|
465
|
+
*
|
|
466
|
+
* The .ts files are only supported for debugging purposes.
|
|
467
|
+
*
|
|
468
|
+
* @example 'papert'
|
|
469
|
+
* @example '/usr/local/bin/papert'
|
|
470
|
+
* @example 'tsx:/path/to/packages/cli/src/index.ts'
|
|
471
|
+
*/
|
|
472
|
+
pathToPapertExecutable?: string;
|
|
473
|
+
/**
|
|
474
|
+
* Environment variables to pass to the Papert CLI process.
|
|
475
|
+
* These variables will be merged with the current process environment.
|
|
476
|
+
*/
|
|
477
|
+
env?: Record<string, string>;
|
|
478
|
+
/**
|
|
479
|
+
* Additional skills directories to load. The CLI will scan these paths for skills.
|
|
480
|
+
* Accepts a single path or a list of paths.
|
|
481
|
+
*/
|
|
482
|
+
skillsPath?: string | string[];
|
|
483
|
+
/**
|
|
484
|
+
* Permission mode controlling how the SDK handles tool execution approval.
|
|
485
|
+
*
|
|
486
|
+
* - 'default': Write tools are denied unless approved via `canUseTool` callback or in `allowedTools`.
|
|
487
|
+
* Read-only tools execute without confirmation.
|
|
488
|
+
* - 'plan': Blocks all write tools, instructing AI to present a plan first.
|
|
489
|
+
* Read-only tools execute normally.
|
|
490
|
+
* - 'auto-edit': Auto-approve edit tools (edit, write_file) while other tools require confirmation.
|
|
491
|
+
* - 'yolo': All tools execute automatically without confirmation.
|
|
492
|
+
*
|
|
493
|
+
* **Priority Chain (highest to lowest):**
|
|
494
|
+
* 1. `excludeTools` - Blocks tools completely (returns permission error)
|
|
495
|
+
* 2. `permissionMode: 'plan'` - Blocks non-read-only tools (except exit_plan_mode)
|
|
496
|
+
* 3. `permissionMode: 'yolo'` - Auto-approves all tools
|
|
497
|
+
* 4. `allowedTools` - Auto-approves matching tools
|
|
498
|
+
* 5. `canUseTool` callback - Custom approval logic
|
|
499
|
+
* 6. Default behavior - Auto-deny in SDK mode
|
|
500
|
+
*
|
|
501
|
+
* @default 'default'
|
|
502
|
+
* @see canUseTool For custom permission handling
|
|
503
|
+
* @see allowedTools For auto-approving specific tools
|
|
504
|
+
* @see excludeTools For blocking specific tools
|
|
505
|
+
*/
|
|
506
|
+
permissionMode?: "default" | "plan" | "auto-edit" | "yolo";
|
|
507
|
+
/**
|
|
508
|
+
* Custom permission handler for tool execution approval.
|
|
509
|
+
*
|
|
510
|
+
* This callback is invoked when a tool requires confirmation and allows you to
|
|
511
|
+
* programmatically approve or deny execution. It acts as a fallback after
|
|
512
|
+
* `allowedTools` check but before default denial.
|
|
513
|
+
*
|
|
514
|
+
* **When is this called?**
|
|
515
|
+
* - Only for tools requiring confirmation (write operations, shell commands, etc.)
|
|
516
|
+
* - After `excludeTools` and `allowedTools` checks
|
|
517
|
+
* - Not called in 'yolo' mode or 'plan' mode
|
|
518
|
+
* - Not called for tools already in `allowedTools`
|
|
519
|
+
*
|
|
520
|
+
* **Usage with permissionMode:**
|
|
521
|
+
* - 'default': Invoked for all write tools not in `allowedTools`; if not provided, auto-denied.
|
|
522
|
+
* - 'auto-edit': Invoked for non-edit tools (edit/write_file auto-approved); if not provided, auto-denied.
|
|
523
|
+
* - 'plan': Not invoked; write tools are blocked by plan mode.
|
|
524
|
+
* - 'yolo': Not invoked; all tools auto-approved.
|
|
525
|
+
*
|
|
526
|
+
* @see allowedTools For auto-approving tools without callback
|
|
527
|
+
*/
|
|
528
|
+
canUseTool?: CanUseTool;
|
|
529
|
+
/**
|
|
530
|
+
* External MCP (Model Context Protocol) servers to connect to.
|
|
531
|
+
* Each server is identified by a unique name and configured with command, args, and environment.
|
|
532
|
+
* @example { 'my-server': { command: 'node', args: ['server.js'], env: { PORT: '3000' } } }
|
|
533
|
+
*/
|
|
534
|
+
mcpServers?: Record<string, ExternalMcpServerConfig>;
|
|
535
|
+
/**
|
|
536
|
+
* AbortController to cancel the query session.
|
|
537
|
+
* Call abortController.abort() to terminate the session and cleanup resources.
|
|
538
|
+
* Remember to handle the AbortError when the session is aborted.
|
|
539
|
+
*/
|
|
540
|
+
abortController?: AbortController;
|
|
541
|
+
/**
|
|
542
|
+
* Enable debug mode for verbose logging.
|
|
543
|
+
* When true, additional diagnostic information will be output.
|
|
544
|
+
* Use this with `logLevel` to control the verbosity of the logs.
|
|
545
|
+
* @default false
|
|
546
|
+
*/
|
|
547
|
+
debug?: boolean;
|
|
548
|
+
/**
|
|
549
|
+
* Custom handler for stderr output from the Papert CLI process.
|
|
550
|
+
* Use this to capture and process error messages or diagnostic output.
|
|
551
|
+
*/
|
|
552
|
+
stderr?: (message: string) => void;
|
|
553
|
+
/**
|
|
554
|
+
* Logging level for the SDK.
|
|
555
|
+
* Controls the verbosity of log messages output by the SDK.
|
|
556
|
+
* @default 'info'
|
|
557
|
+
*/
|
|
558
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
559
|
+
/**
|
|
560
|
+
* Maximum number of conversation turns before the session automatically terminates.
|
|
561
|
+
* A turn consists of a user message and an assistant response.
|
|
562
|
+
* @default -1 (unlimited)
|
|
563
|
+
*/
|
|
564
|
+
maxSessionTurns?: number;
|
|
565
|
+
/**
|
|
566
|
+
* Equivalent to `tool.core` in settings.json.
|
|
567
|
+
* List of core tools to enable for the session.
|
|
568
|
+
* If specified, only these tools will be available to the AI.
|
|
569
|
+
* @example ['read_file', 'write_file', 'run_terminal_cmd']
|
|
570
|
+
*/
|
|
571
|
+
coreTools?: string[];
|
|
572
|
+
/**
|
|
573
|
+
* Equivalent to `tool.exclude` in settings.json.
|
|
574
|
+
* List of tools to exclude from the session.
|
|
575
|
+
*
|
|
576
|
+
* **Behavior:**
|
|
577
|
+
* - Excluded tools return a permission error immediately when invoked
|
|
578
|
+
* - Takes highest priority - overrides all other permission settings
|
|
579
|
+
* - Tools will not be available to the AI, even if in `coreTools` or `allowedTools`
|
|
580
|
+
*
|
|
581
|
+
* **Pattern matching:**
|
|
582
|
+
* - Tool name: `'write_file'`, `'run_shell_command'`
|
|
583
|
+
* - Tool class: `'WriteTool'`, `'ShellTool'`
|
|
584
|
+
* - Shell command prefix: `'ShellTool(git commit)'` (matches commands starting with "git commit")
|
|
585
|
+
*
|
|
586
|
+
* @example ['run_terminal_cmd', 'delete_file', 'ShellTool(rm )']
|
|
587
|
+
* @see allowedTools For allowing specific tools
|
|
588
|
+
*/
|
|
589
|
+
excludeTools?: string[];
|
|
590
|
+
/**
|
|
591
|
+
* Equivalent to `tool.allowed` in settings.json.
|
|
592
|
+
* List of tools that are allowed to run without confirmation.
|
|
593
|
+
*
|
|
594
|
+
* **Behavior:**
|
|
595
|
+
* - Matching tools bypass `canUseTool` callback and execute automatically
|
|
596
|
+
* - Only applies when tool requires confirmation (write operations, shell commands)
|
|
597
|
+
* - Checked after `excludeTools` but before `canUseTool` callback
|
|
598
|
+
* - Does not override `permissionMode: 'plan'` (plan mode blocks all write tools)
|
|
599
|
+
* - Has no effect in `permissionMode: 'yolo'` (already auto-approved)
|
|
600
|
+
*
|
|
601
|
+
* **Pattern matching:**
|
|
602
|
+
* - Tool name: `'write_file'`, `'run_shell_command'`
|
|
603
|
+
* - Tool class: `'WriteTool'`, `'ShellTool'`
|
|
604
|
+
* - Shell command prefix: `'ShellTool(git status)'` (matches commands starting with "git status")
|
|
605
|
+
*
|
|
606
|
+
* **Use cases:**
|
|
607
|
+
* - Auto-approve safe shell commands: `['ShellTool(git status)', 'ShellTool(ls)']`
|
|
608
|
+
* - Auto-approve specific tools: `['write_file', 'edit']`
|
|
609
|
+
* - Combine with `permissionMode: 'default'` to selectively auto-approve tools
|
|
610
|
+
*
|
|
611
|
+
* @example ['read_file', 'ShellTool(git status)', 'ShellTool(npm test)']
|
|
612
|
+
* @see canUseTool For custom approval logic
|
|
613
|
+
* @see excludeTools For blocking specific tools
|
|
614
|
+
*/
|
|
615
|
+
allowedTools?: string[];
|
|
616
|
+
/**
|
|
617
|
+
* Authentication type for the AI service.
|
|
618
|
+
* - 'openai': Use OpenAI-compatible authentication
|
|
619
|
+
* - 'papert-oauth': Use Papert OAuth authentication
|
|
620
|
+
*
|
|
621
|
+
* Though we support 'papert-oauth', it's not recommended to use it in the SDK.
|
|
622
|
+
* Because the credentials are stored in `~/.papert` and may need to refresh periodically.
|
|
623
|
+
*/
|
|
624
|
+
authType?: "openai" | "papert-oauth";
|
|
625
|
+
/**
|
|
626
|
+
* Configuration for subagents that can be invoked during the session.
|
|
627
|
+
* Subagents are specialized AI agents that can handle specific tasks or domains.
|
|
628
|
+
* The invocation is marked as a `task` tool use with the name of agent and a tool_use_id.
|
|
629
|
+
* The tool use of these agent is marked with the parent_tool_use_id of the `task` tool use.
|
|
630
|
+
*/
|
|
631
|
+
agents?: SubagentConfig[];
|
|
632
|
+
/**
|
|
633
|
+
* Include partial messages in the response stream.
|
|
634
|
+
* When true, the SDK will emit incomplete messages as they are being generated,
|
|
635
|
+
* allowing for real-time streaming of the AI's response.
|
|
636
|
+
* @default false
|
|
637
|
+
*/
|
|
638
|
+
includePartialMessages?: boolean;
|
|
639
|
+
}
|
|
640
|
+
export declare class Query implements AsyncIterable<SDKMessage> {
|
|
641
|
+
private transport;
|
|
642
|
+
private options;
|
|
643
|
+
private sessionId;
|
|
644
|
+
private inputStream;
|
|
645
|
+
private sdkMessages;
|
|
646
|
+
private abortController;
|
|
647
|
+
private pendingControlRequests;
|
|
648
|
+
private sdkMcpTransports;
|
|
649
|
+
readonly initialized: Promise<void>;
|
|
650
|
+
private closed;
|
|
651
|
+
private messageRouterStarted;
|
|
652
|
+
private firstResultReceivedPromise?;
|
|
653
|
+
private firstResultReceivedResolve?;
|
|
654
|
+
private readonly isSingleTurn;
|
|
655
|
+
constructor(transport: Transport, options: QueryOptions, singleTurn?: boolean);
|
|
656
|
+
private initialize;
|
|
657
|
+
private startMessageRouter;
|
|
658
|
+
private routeMessage;
|
|
659
|
+
private handleControlRequest;
|
|
660
|
+
private handlePermissionRequest;
|
|
661
|
+
private handleMcpMessage;
|
|
662
|
+
private handleMcpRequest;
|
|
663
|
+
private handleControlResponse;
|
|
664
|
+
private handleControlCancelRequest;
|
|
665
|
+
private sendControlRequest;
|
|
666
|
+
private sendControlResponse;
|
|
667
|
+
close(): Promise<void>;
|
|
668
|
+
private readSdkMessages;
|
|
669
|
+
next(...args: [
|
|
670
|
+
] | [
|
|
671
|
+
unknown
|
|
672
|
+
]): Promise<IteratorResult<SDKMessage>>;
|
|
673
|
+
return(value?: unknown): Promise<IteratorResult<SDKMessage>>;
|
|
674
|
+
throw(e?: unknown): Promise<IteratorResult<SDKMessage>>;
|
|
675
|
+
[Symbol.asyncIterator](): AsyncIterator<SDKMessage>;
|
|
676
|
+
streamInput(messages: AsyncIterable<SDKUserMessage>): Promise<void>;
|
|
677
|
+
endInput(): void;
|
|
678
|
+
interrupt(): Promise<void>;
|
|
679
|
+
setPermissionMode(mode: string): Promise<void>;
|
|
680
|
+
setModel(model: string): Promise<void>;
|
|
681
|
+
/**
|
|
682
|
+
* Get list of control commands supported by the CLI
|
|
683
|
+
*
|
|
684
|
+
* @returns Promise resolving to list of supported command names
|
|
685
|
+
* @throws Error if query is closed
|
|
686
|
+
*/
|
|
687
|
+
supportedCommands(): Promise<Record<string, unknown> | null>;
|
|
688
|
+
/**
|
|
689
|
+
* Get the status of MCP servers
|
|
690
|
+
*
|
|
691
|
+
* @returns Promise resolving to MCP server status information
|
|
692
|
+
* @throws Error if query is closed
|
|
693
|
+
*/
|
|
694
|
+
mcpServerStatus(): Promise<Record<string, unknown> | null>;
|
|
695
|
+
getSessionId(): string;
|
|
696
|
+
isClosed(): boolean;
|
|
697
|
+
}
|
|
698
|
+
export declare function query({ prompt, options, }: {
|
|
699
|
+
/**
|
|
700
|
+
* The prompt to send to the Papert Code CLI process.
|
|
701
|
+
* - `string` for single-turn query,
|
|
702
|
+
* - `AsyncIterable<SDKUserMessage>` for multi-turn query.
|
|
703
|
+
*
|
|
704
|
+
* The transport will remain open until the prompt is done.
|
|
705
|
+
*/
|
|
706
|
+
prompt: string | AsyncIterable<SDKUserMessage>;
|
|
707
|
+
/**
|
|
708
|
+
* Configuration options for the query.
|
|
709
|
+
*/
|
|
710
|
+
options?: QueryOptions;
|
|
711
|
+
}): Query;
|
|
712
|
+
export declare class AbortError extends Error {
|
|
713
|
+
constructor(message?: string);
|
|
714
|
+
}
|
|
715
|
+
export declare function isAbortError(error: unknown): error is AbortError;
|
|
716
|
+
export interface CreateSessionOptions {
|
|
717
|
+
sessionId?: string;
|
|
718
|
+
options?: QueryOptions;
|
|
719
|
+
}
|
|
720
|
+
export declare class PapertClient {
|
|
721
|
+
private readonly options;
|
|
722
|
+
private readonly sessions;
|
|
723
|
+
constructor(options?: QueryOptions);
|
|
724
|
+
createSession({ sessionId, options, }?: CreateSessionOptions): PapertClientSession;
|
|
725
|
+
getSession(sessionId: string): PapertClientSession | undefined;
|
|
726
|
+
getDefaultOptions(): QueryOptions;
|
|
727
|
+
unregisterSession(sessionId: string): void;
|
|
728
|
+
close(): Promise<void>;
|
|
729
|
+
}
|
|
730
|
+
export declare class PapertClientSession {
|
|
731
|
+
private readonly sessionId;
|
|
732
|
+
private readonly client;
|
|
733
|
+
private readonly options;
|
|
734
|
+
private readonly activeQueries;
|
|
735
|
+
private closed;
|
|
736
|
+
constructor(sessionId: string, client: PapertClient, options?: QueryOptions);
|
|
737
|
+
getSessionId(): string;
|
|
738
|
+
isClosed(): boolean;
|
|
739
|
+
stream(prompt: string, options?: QueryOptions): Query;
|
|
740
|
+
send(prompt: string, options?: QueryOptions): Promise<SDKMessage[]>;
|
|
741
|
+
close(): Promise<void>;
|
|
742
|
+
private createPromptStream;
|
|
743
|
+
}
|
|
744
|
+
export declare function createClient(options?: QueryOptions): PapertClient;
|
|
745
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
746
|
+
export interface LoggerConfig {
|
|
747
|
+
debug?: boolean;
|
|
748
|
+
stderr?: (message: string) => void;
|
|
749
|
+
logLevel?: LogLevel;
|
|
750
|
+
}
|
|
751
|
+
export interface ScopedLogger {
|
|
752
|
+
debug(message: string, ...args: unknown[]): void;
|
|
753
|
+
info(message: string, ...args: unknown[]): void;
|
|
754
|
+
warn(message: string, ...args: unknown[]): void;
|
|
755
|
+
error(message: string, ...args: unknown[]): void;
|
|
756
|
+
}
|
|
757
|
+
export declare class SdkLogger {
|
|
758
|
+
private static config;
|
|
759
|
+
private static effectiveLevel;
|
|
760
|
+
static configure(config: LoggerConfig): void;
|
|
761
|
+
private static determineLogLevel;
|
|
762
|
+
private static isValidLogLevel;
|
|
763
|
+
private static shouldLog;
|
|
764
|
+
private static formatTimestamp;
|
|
765
|
+
private static formatMessage;
|
|
766
|
+
private static log;
|
|
767
|
+
static createLogger(scope: string): ScopedLogger;
|
|
768
|
+
static getEffectiveLevel(): LogLevel;
|
|
769
|
+
}
|
|
770
|
+
export type ApprovalMode = "default" | "yolo" | "auto-edit";
|
|
771
|
+
export interface PapertAgentOptions {
|
|
772
|
+
/**
|
|
773
|
+
* Path to the papert-code CLI entrypoint. Defaults to the package entry
|
|
774
|
+
* resolved from Node (equivalent to `require.resolve('@papert-code/papert-code')`).
|
|
775
|
+
*/
|
|
776
|
+
cliBinaryPath?: string;
|
|
777
|
+
/**
|
|
778
|
+
* CLI arguments to seed the agent with (mirrors CLI flags).
|
|
779
|
+
*/
|
|
780
|
+
cliArgs?: {
|
|
781
|
+
model?: string;
|
|
782
|
+
approvalMode?: ApprovalMode;
|
|
783
|
+
baseUrl?: string;
|
|
784
|
+
apiKey?: string;
|
|
785
|
+
cwd?: string;
|
|
786
|
+
extraArgs?: string[];
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
export interface RunPromptOptions {
|
|
790
|
+
/**
|
|
791
|
+
* Additional CLI flags to append just for this prompt.
|
|
792
|
+
*/
|
|
793
|
+
extraArgs?: string[];
|
|
794
|
+
/**
|
|
795
|
+
* AbortSignal to terminate the underlying process.
|
|
796
|
+
*/
|
|
797
|
+
signal?: AbortSignal;
|
|
798
|
+
}
|
|
799
|
+
export interface PapertAgent {
|
|
800
|
+
runPrompt: (prompt: string, options?: RunPromptOptions) => Promise<{
|
|
801
|
+
stdout: string;
|
|
802
|
+
stderr: string;
|
|
803
|
+
exitCode: number | null;
|
|
804
|
+
}>;
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* Lightweight programmatic wrapper around the papert-code CLI.
|
|
808
|
+
*
|
|
809
|
+
* Example:
|
|
810
|
+
* const agent = await createPapertAgent({
|
|
811
|
+
* cliArgs: { model: 'gemini-3-pro', approvalMode: 'auto_edit' },
|
|
812
|
+
* });
|
|
813
|
+
* const result = await agent.runPrompt('Summarize outstanding TODOs');
|
|
814
|
+
*/
|
|
815
|
+
export declare function createPapertAgent(options?: PapertAgentOptions): Promise<PapertAgent>;
|
|
816
|
+
export type HttpSseTransportOptions = {
|
|
817
|
+
baseUrl: string;
|
|
818
|
+
/** Token required to create a session (server token). */
|
|
819
|
+
serverToken: string;
|
|
820
|
+
/** Optional override; defaults to process.cwd() on the server. */
|
|
821
|
+
workspaceRoot?: string;
|
|
822
|
+
};
|
|
823
|
+
export declare class HttpSseTransport implements Transport {
|
|
824
|
+
private readonly options;
|
|
825
|
+
private _exitError;
|
|
826
|
+
private _isReady;
|
|
827
|
+
private session;
|
|
828
|
+
private pendingWrites;
|
|
829
|
+
constructor(options: HttpSseTransportOptions);
|
|
830
|
+
get isReady(): boolean;
|
|
831
|
+
get exitError(): Error | null;
|
|
832
|
+
close(): Promise<void>;
|
|
833
|
+
waitForExit(): Promise<void>;
|
|
834
|
+
write(message: string): void;
|
|
835
|
+
readMessages(): AsyncGenerator<unknown, void, unknown>;
|
|
836
|
+
private createSession;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
export {};
|