@chucky.cloud/sdk 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 +330 -0
- package/dist/browser.d.ts +8 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +12 -0
- package/dist/browser.js.map +1 -0
- package/dist/client/ChuckyClient.d.ts +187 -0
- package/dist/client/ChuckyClient.d.ts.map +1 -0
- package/dist/client/ChuckyClient.js +232 -0
- package/dist/client/ChuckyClient.js.map +1 -0
- package/dist/client/Session.d.ts +146 -0
- package/dist/client/Session.d.ts.map +1 -0
- package/dist/client/Session.js +405 -0
- package/dist/client/Session.js.map +1 -0
- package/dist/client/index.d.ts +10 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +8 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +8 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +11 -0
- package/dist/node.js.map +1 -0
- package/dist/tools/McpServer.d.ts +117 -0
- package/dist/tools/McpServer.d.ts.map +1 -0
- package/dist/tools/McpServer.js +142 -0
- package/dist/tools/McpServer.js.map +1 -0
- package/dist/tools/index.d.ts +9 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +8 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/tool.d.ts +146 -0
- package/dist/tools/tool.d.ts.map +1 -0
- package/dist/tools/tool.js +232 -0
- package/dist/tools/tool.js.map +1 -0
- package/dist/transport/Transport.d.ts +82 -0
- package/dist/transport/Transport.d.ts.map +1 -0
- package/dist/transport/Transport.js +45 -0
- package/dist/transport/Transport.js.map +1 -0
- package/dist/transport/WebSocketTransport.d.ts +78 -0
- package/dist/transport/WebSocketTransport.d.ts.map +1 -0
- package/dist/transport/WebSocketTransport.js +253 -0
- package/dist/transport/WebSocketTransport.js.map +1 -0
- package/dist/transport/index.d.ts +10 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +8 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/messages.d.ts +195 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/messages.js +70 -0
- package/dist/types/messages.js.map +1 -0
- package/dist/types/options.d.ts +210 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/options.js +8 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/results.d.ts +182 -0
- package/dist/types/results.d.ts.map +1 -0
- package/dist/types/results.js +7 -0
- package/dist/types/results.js.map +1 -0
- package/dist/types/token.d.ts +124 -0
- package/dist/types/token.d.ts.map +1 -0
- package/dist/types/token.js +7 -0
- package/dist/types/token.js.map +1 -0
- package/dist/types/tools.d.ts +160 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +8 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/utils/errors.d.ts +80 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +158 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/token.d.ts +93 -0
- package/dist/utils/token.d.ts.map +1 -0
- package/dist/utils/token.js +195 -0
- package/dist/utils/token.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket Message Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the envelope format and message types for communication
|
|
5
|
+
* between the SDK client and the Chucky server.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolCall, ToolResult } from './tools.js';
|
|
8
|
+
import type { SessionOptions, PromptOptions } from './options.js';
|
|
9
|
+
/**
|
|
10
|
+
* WebSocket envelope types
|
|
11
|
+
*/
|
|
12
|
+
export type WsEnvelopeType = 'init' | 'prompt' | 'sdk_message' | 'control' | 'error' | 'ping' | 'pong' | 'tool_call' | 'tool_result' | 'result';
|
|
13
|
+
/**
|
|
14
|
+
* Base envelope structure
|
|
15
|
+
*/
|
|
16
|
+
export interface WsEnvelope<T = unknown> {
|
|
17
|
+
/** Message type */
|
|
18
|
+
type: WsEnvelopeType;
|
|
19
|
+
/** Message payload */
|
|
20
|
+
payload: T;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Init message payload (session initialization)
|
|
24
|
+
*/
|
|
25
|
+
export interface InitPayload extends Omit<SessionOptions, 'tools' | 'mcpServers'> {
|
|
26
|
+
/** Serialized tool definitions */
|
|
27
|
+
tools?: unknown[];
|
|
28
|
+
/** Serialized MCP server definitions */
|
|
29
|
+
mcpServers?: unknown[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Prompt message payload (one-shot prompt)
|
|
33
|
+
*/
|
|
34
|
+
export interface PromptPayload extends Omit<PromptOptions, 'tools' | 'mcpServers'> {
|
|
35
|
+
/** Serialized tool definitions */
|
|
36
|
+
tools?: unknown[];
|
|
37
|
+
/** Serialized MCP server definitions */
|
|
38
|
+
mcpServers?: unknown[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Control message actions
|
|
42
|
+
*/
|
|
43
|
+
export type ControlAction = 'ready' | 'session_info' | 'end_input' | 'close';
|
|
44
|
+
/**
|
|
45
|
+
* Control message payload
|
|
46
|
+
*/
|
|
47
|
+
export interface ControlPayload {
|
|
48
|
+
/** Control action */
|
|
49
|
+
action: ControlAction;
|
|
50
|
+
/** Additional data */
|
|
51
|
+
data?: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Error message payload
|
|
55
|
+
*/
|
|
56
|
+
export interface ErrorPayload {
|
|
57
|
+
/** Error message */
|
|
58
|
+
message: string;
|
|
59
|
+
/** Error code */
|
|
60
|
+
code?: string;
|
|
61
|
+
/** Additional error details */
|
|
62
|
+
details?: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Ping/Pong message payload
|
|
66
|
+
*/
|
|
67
|
+
export interface PingPongPayload {
|
|
68
|
+
/** Timestamp */
|
|
69
|
+
timestamp: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Tool call message payload
|
|
73
|
+
*/
|
|
74
|
+
export interface ToolCallPayload extends ToolCall {
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Tool result message payload
|
|
78
|
+
*/
|
|
79
|
+
export interface ToolResultPayload {
|
|
80
|
+
/** Call ID */
|
|
81
|
+
callId: string;
|
|
82
|
+
/** Tool result */
|
|
83
|
+
result: ToolResult;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Result message payload (final response)
|
|
87
|
+
*/
|
|
88
|
+
export interface ResultPayload {
|
|
89
|
+
/** Result type */
|
|
90
|
+
type: 'result';
|
|
91
|
+
/** Result subtype */
|
|
92
|
+
subtype?: string;
|
|
93
|
+
/** Response text */
|
|
94
|
+
text?: string;
|
|
95
|
+
/** Total cost in USD */
|
|
96
|
+
total_cost_usd?: number;
|
|
97
|
+
/** Duration in seconds */
|
|
98
|
+
duration_secs?: number;
|
|
99
|
+
/** Number of turns */
|
|
100
|
+
turn_count?: number;
|
|
101
|
+
/** Additional result data */
|
|
102
|
+
[key: string]: unknown;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* SDK message payload (native Claude Agent SDK messages)
|
|
106
|
+
*/
|
|
107
|
+
export interface SdkMessagePayload {
|
|
108
|
+
/** Message type from SDK */
|
|
109
|
+
type: string;
|
|
110
|
+
/** Message data */
|
|
111
|
+
[key: string]: unknown;
|
|
112
|
+
}
|
|
113
|
+
export interface InitEnvelope extends WsEnvelope<InitPayload> {
|
|
114
|
+
type: 'init';
|
|
115
|
+
}
|
|
116
|
+
export interface PromptEnvelope extends WsEnvelope<PromptPayload> {
|
|
117
|
+
type: 'prompt';
|
|
118
|
+
}
|
|
119
|
+
export interface SdkMessageEnvelope extends WsEnvelope<SdkMessagePayload> {
|
|
120
|
+
type: 'sdk_message';
|
|
121
|
+
}
|
|
122
|
+
export interface ControlEnvelope extends WsEnvelope<ControlPayload> {
|
|
123
|
+
type: 'control';
|
|
124
|
+
}
|
|
125
|
+
export interface ErrorEnvelope extends WsEnvelope<ErrorPayload> {
|
|
126
|
+
type: 'error';
|
|
127
|
+
}
|
|
128
|
+
export interface PingEnvelope extends WsEnvelope<PingPongPayload> {
|
|
129
|
+
type: 'ping';
|
|
130
|
+
}
|
|
131
|
+
export interface PongEnvelope extends WsEnvelope<PingPongPayload> {
|
|
132
|
+
type: 'pong';
|
|
133
|
+
}
|
|
134
|
+
export interface ToolCallEnvelope extends WsEnvelope<ToolCallPayload> {
|
|
135
|
+
type: 'tool_call';
|
|
136
|
+
}
|
|
137
|
+
export interface ToolResultEnvelope extends WsEnvelope<ToolResultPayload> {
|
|
138
|
+
type: 'tool_result';
|
|
139
|
+
}
|
|
140
|
+
export interface ResultEnvelope extends WsEnvelope<ResultPayload> {
|
|
141
|
+
type: 'result';
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Union type for all outgoing messages (client -> server)
|
|
145
|
+
*/
|
|
146
|
+
export type OutgoingMessage = InitEnvelope | PromptEnvelope | SdkMessageEnvelope | ControlEnvelope | PingEnvelope | ToolResultEnvelope;
|
|
147
|
+
/**
|
|
148
|
+
* Union type for all incoming messages (server -> client)
|
|
149
|
+
*/
|
|
150
|
+
export type IncomingMessage = SdkMessageEnvelope | ControlEnvelope | ErrorEnvelope | PongEnvelope | ToolCallEnvelope | ResultEnvelope;
|
|
151
|
+
/**
|
|
152
|
+
* Union type for all messages
|
|
153
|
+
*/
|
|
154
|
+
export type AnyMessage = OutgoingMessage | IncomingMessage;
|
|
155
|
+
/**
|
|
156
|
+
* Create an init message
|
|
157
|
+
*/
|
|
158
|
+
export declare function createInitMessage(payload: InitPayload): InitEnvelope;
|
|
159
|
+
/**
|
|
160
|
+
* Create a prompt message
|
|
161
|
+
*/
|
|
162
|
+
export declare function createPromptMessage(payload: PromptPayload): PromptEnvelope;
|
|
163
|
+
/**
|
|
164
|
+
* Create an SDK message
|
|
165
|
+
*/
|
|
166
|
+
export declare function createSdkMessage(payload: SdkMessagePayload): SdkMessageEnvelope;
|
|
167
|
+
/**
|
|
168
|
+
* Create a control message
|
|
169
|
+
*/
|
|
170
|
+
export declare function createControlMessage(action: ControlAction, data?: Record<string, unknown>): ControlEnvelope;
|
|
171
|
+
/**
|
|
172
|
+
* Create a ping message
|
|
173
|
+
*/
|
|
174
|
+
export declare function createPingMessage(): PingEnvelope;
|
|
175
|
+
/**
|
|
176
|
+
* Create a tool result message
|
|
177
|
+
*/
|
|
178
|
+
export declare function createToolResultMessage(callId: string, result: ToolResult): ToolResultEnvelope;
|
|
179
|
+
/**
|
|
180
|
+
* Check if a message is a result message
|
|
181
|
+
*/
|
|
182
|
+
export declare function isResultMessage(message: AnyMessage): message is ResultEnvelope;
|
|
183
|
+
/**
|
|
184
|
+
* Check if a message is a tool call message
|
|
185
|
+
*/
|
|
186
|
+
export declare function isToolCallMessage(message: AnyMessage): message is ToolCallEnvelope;
|
|
187
|
+
/**
|
|
188
|
+
* Check if a message is a control message
|
|
189
|
+
*/
|
|
190
|
+
export declare function isControlMessage(message: AnyMessage): message is ControlEnvelope;
|
|
191
|
+
/**
|
|
192
|
+
* Check if a message is an error message
|
|
193
|
+
*/
|
|
194
|
+
export declare function isErrorMessage(message: AnyMessage): message is ErrorEnvelope;
|
|
195
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/types/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,O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,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,eAAe,CAEjB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,YAAY,CAEhD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,UAAU,GACjB,kBAAkB,CAEpB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,IAAI,cAAc,CAE9E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,IAAI,gBAAgB,CAElF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,IAAI,eAAe,CAEhF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,IAAI,aAAa,CAE5E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket Message Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the envelope format and message types for communication
|
|
5
|
+
* between the SDK client and the Chucky server.
|
|
6
|
+
*/
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Message Helpers
|
|
9
|
+
// ============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* Create an init message
|
|
12
|
+
*/
|
|
13
|
+
export function createInitMessage(payload) {
|
|
14
|
+
return { type: 'init', payload };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a prompt message
|
|
18
|
+
*/
|
|
19
|
+
export function createPromptMessage(payload) {
|
|
20
|
+
return { type: 'prompt', payload };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create an SDK message
|
|
24
|
+
*/
|
|
25
|
+
export function createSdkMessage(payload) {
|
|
26
|
+
return { type: 'sdk_message', payload };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a control message
|
|
30
|
+
*/
|
|
31
|
+
export function createControlMessage(action, data) {
|
|
32
|
+
return { type: 'control', payload: { action, data } };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a ping message
|
|
36
|
+
*/
|
|
37
|
+
export function createPingMessage() {
|
|
38
|
+
return { type: 'ping', payload: { timestamp: Date.now() } };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a tool result message
|
|
42
|
+
*/
|
|
43
|
+
export function createToolResultMessage(callId, result) {
|
|
44
|
+
return { type: 'tool_result', payload: { callId, result } };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if a message is a result message
|
|
48
|
+
*/
|
|
49
|
+
export function isResultMessage(message) {
|
|
50
|
+
return message.type === 'result';
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if a message is a tool call message
|
|
54
|
+
*/
|
|
55
|
+
export function isToolCallMessage(message) {
|
|
56
|
+
return message.type === 'tool_call';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if a message is a control message
|
|
60
|
+
*/
|
|
61
|
+
export function isControlMessage(message) {
|
|
62
|
+
return message.type === 'control';
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if a message is an error message
|
|
66
|
+
*/
|
|
67
|
+
export function isErrorMessage(message) {
|
|
68
|
+
return message.type === 'error';
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/types/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6MH,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAoB;IACpD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAsB;IACxD,OAAO,EA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configuration options for sessions and prompts.
|
|
5
|
+
* Designed for both browser and Node.js environments.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolDefinition, McpServerDefinition } from './tools.js';
|
|
8
|
+
/**
|
|
9
|
+
* Available Claude models
|
|
10
|
+
*/
|
|
11
|
+
export type Model = 'claude-sonnet-4-5-20250929' | 'claude-opus-4-5-20251101' | 'claude-3-5-sonnet-20241022' | 'claude-3-5-haiku-20241022' | 'claude-3-opus-20240229' | (string & {});
|
|
12
|
+
/**
|
|
13
|
+
* System prompt configuration
|
|
14
|
+
*/
|
|
15
|
+
export type SystemPrompt = string | {
|
|
16
|
+
/** Use a preset system prompt */
|
|
17
|
+
type: 'preset';
|
|
18
|
+
/** The preset name */
|
|
19
|
+
preset: 'claude_code';
|
|
20
|
+
/** Additional text to append to the preset */
|
|
21
|
+
append?: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Output format configuration for structured outputs
|
|
25
|
+
*/
|
|
26
|
+
export interface OutputFormat {
|
|
27
|
+
/** Output format type */
|
|
28
|
+
type: 'json_schema';
|
|
29
|
+
/** JSON Schema definition for the expected output */
|
|
30
|
+
schema: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Agent definition for sub-agents
|
|
34
|
+
*/
|
|
35
|
+
export interface AgentDefinition {
|
|
36
|
+
/** Agent name */
|
|
37
|
+
name: string;
|
|
38
|
+
/** Agent description */
|
|
39
|
+
description?: string;
|
|
40
|
+
/** Model to use for this agent */
|
|
41
|
+
model?: Model;
|
|
42
|
+
/** System prompt for this agent */
|
|
43
|
+
systemPrompt?: SystemPrompt;
|
|
44
|
+
/** Tools available to this agent */
|
|
45
|
+
tools?: string[];
|
|
46
|
+
/** Maximum turns for this agent */
|
|
47
|
+
maxTurns?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Base options shared between sessions and prompts
|
|
51
|
+
*/
|
|
52
|
+
export interface BaseOptions {
|
|
53
|
+
/**
|
|
54
|
+
* The model to use for generation
|
|
55
|
+
* @default 'claude-sonnet-4-5-20250929'
|
|
56
|
+
*/
|
|
57
|
+
model?: Model;
|
|
58
|
+
/**
|
|
59
|
+
* Fallback model if primary model is unavailable
|
|
60
|
+
*/
|
|
61
|
+
fallbackModel?: Model;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum number of conversation turns
|
|
64
|
+
*/
|
|
65
|
+
maxTurns?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Maximum budget in USD for this session/prompt
|
|
68
|
+
*/
|
|
69
|
+
maxBudgetUsd?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Maximum thinking tokens (for extended thinking)
|
|
72
|
+
*/
|
|
73
|
+
maxThinkingTokens?: number;
|
|
74
|
+
/**
|
|
75
|
+
* System prompt or preset configuration
|
|
76
|
+
*/
|
|
77
|
+
systemPrompt?: SystemPrompt;
|
|
78
|
+
/**
|
|
79
|
+
* Tool definitions for this session/prompt
|
|
80
|
+
*/
|
|
81
|
+
tools?: ToolDefinition[];
|
|
82
|
+
/**
|
|
83
|
+
* List of tool names that are allowed
|
|
84
|
+
*/
|
|
85
|
+
allowedTools?: string[];
|
|
86
|
+
/**
|
|
87
|
+
* List of tool names that are blocked
|
|
88
|
+
*/
|
|
89
|
+
disallowedTools?: string[];
|
|
90
|
+
/**
|
|
91
|
+
* MCP server definitions
|
|
92
|
+
*/
|
|
93
|
+
mcpServers?: McpServerDefinition[];
|
|
94
|
+
/**
|
|
95
|
+
* Sub-agent definitions
|
|
96
|
+
*/
|
|
97
|
+
agents?: Record<string, AgentDefinition>;
|
|
98
|
+
/**
|
|
99
|
+
* Beta features to enable
|
|
100
|
+
*/
|
|
101
|
+
betas?: string[];
|
|
102
|
+
/**
|
|
103
|
+
* Permission mode for sandbox operations
|
|
104
|
+
*/
|
|
105
|
+
permissionMode?: 'default' | 'plan' | 'bypassPermissions';
|
|
106
|
+
/**
|
|
107
|
+
* Allow dangerous operations (use with caution)
|
|
108
|
+
*/
|
|
109
|
+
allowDangerouslySkipPermissions?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Custom environment variables
|
|
112
|
+
*/
|
|
113
|
+
env?: Record<string, string>;
|
|
114
|
+
/**
|
|
115
|
+
* Output format for structured responses
|
|
116
|
+
*/
|
|
117
|
+
outputFormat?: OutputFormat;
|
|
118
|
+
/**
|
|
119
|
+
* Include partial messages in the stream
|
|
120
|
+
*/
|
|
121
|
+
includePartialMessages?: boolean;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Session-specific options
|
|
125
|
+
*/
|
|
126
|
+
export interface SessionOptions extends BaseOptions {
|
|
127
|
+
/**
|
|
128
|
+
* Session ID for resuming an existing session
|
|
129
|
+
*/
|
|
130
|
+
sessionId?: string;
|
|
131
|
+
/**
|
|
132
|
+
* Fork from an existing session instead of resuming
|
|
133
|
+
*/
|
|
134
|
+
forkSession?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Resume session at a specific conversation ID
|
|
137
|
+
*/
|
|
138
|
+
resumeSessionAt?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Continue from where the session left off
|
|
141
|
+
*/
|
|
142
|
+
continue?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Settings sources for configuration
|
|
145
|
+
*/
|
|
146
|
+
settingSources?: Array<'user' | 'project' | 'local'>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Prompt-specific options (stateless, one-shot)
|
|
150
|
+
*/
|
|
151
|
+
export interface PromptOptions extends BaseOptions {
|
|
152
|
+
/**
|
|
153
|
+
* The prompt message to send
|
|
154
|
+
*/
|
|
155
|
+
message: string;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Client configuration options
|
|
159
|
+
*/
|
|
160
|
+
export interface ClientOptions {
|
|
161
|
+
/**
|
|
162
|
+
* Base URL for the Chucky service
|
|
163
|
+
* @default 'wss://box.chucky.cloud'
|
|
164
|
+
*/
|
|
165
|
+
baseUrl?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Authentication token (JWT)
|
|
168
|
+
*/
|
|
169
|
+
token: string;
|
|
170
|
+
/**
|
|
171
|
+
* Enable debug logging
|
|
172
|
+
*/
|
|
173
|
+
debug?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Connection timeout in milliseconds
|
|
176
|
+
* @default 30000
|
|
177
|
+
*/
|
|
178
|
+
timeout?: number;
|
|
179
|
+
/**
|
|
180
|
+
* Keep-alive interval in milliseconds
|
|
181
|
+
* @default 300000 (5 minutes)
|
|
182
|
+
*/
|
|
183
|
+
keepAliveInterval?: number;
|
|
184
|
+
/**
|
|
185
|
+
* Auto-reconnect on disconnect
|
|
186
|
+
* @default true
|
|
187
|
+
*/
|
|
188
|
+
autoReconnect?: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Maximum reconnect attempts
|
|
191
|
+
* @default 5
|
|
192
|
+
*/
|
|
193
|
+
maxReconnectAttempts?: number;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Connection status
|
|
197
|
+
*/
|
|
198
|
+
export type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'error';
|
|
199
|
+
/**
|
|
200
|
+
* Event handlers for client events
|
|
201
|
+
*/
|
|
202
|
+
export interface ClientEventHandlers {
|
|
203
|
+
/** Called when connection status changes */
|
|
204
|
+
onStatusChange?: (status: ConnectionStatus) => void;
|
|
205
|
+
/** Called when a raw message is sent or received (for debugging) */
|
|
206
|
+
onRawMessage?: (direction: 'in' | 'out', message: unknown) => void;
|
|
207
|
+
/** Called when an error occurs */
|
|
208
|
+
onError?: (error: Error) => void;
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EA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Ed;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,cAAc,GACd,YAAY,GACZ,WAAW,GACX,cAAc,GACd,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,4CAA4C;IAC5C,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAEpD,oEAAoE;IACpE,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,GAAG,KAAK,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAEnE,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result Types
|
|
3
|
+
*
|
|
4
|
+
* Types for responses from sessions and prompts.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Message role
|
|
8
|
+
*/
|
|
9
|
+
export type MessageRole = 'user' | 'assistant' | 'system';
|
|
10
|
+
/**
|
|
11
|
+
* Content block types
|
|
12
|
+
*/
|
|
13
|
+
export type ContentBlockType = 'text' | 'tool_use' | 'tool_result' | 'thinking' | 'image';
|
|
14
|
+
/**
|
|
15
|
+
* Text content block
|
|
16
|
+
*/
|
|
17
|
+
export interface TextBlock {
|
|
18
|
+
type: 'text';
|
|
19
|
+
text: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Tool use content block
|
|
23
|
+
*/
|
|
24
|
+
export interface ToolUseBlock {
|
|
25
|
+
type: 'tool_use';
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
input: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Tool result content block
|
|
32
|
+
*/
|
|
33
|
+
export interface ToolResultBlock {
|
|
34
|
+
type: 'tool_result';
|
|
35
|
+
tool_use_id: string;
|
|
36
|
+
content: string | Array<{
|
|
37
|
+
type: 'text';
|
|
38
|
+
text: string;
|
|
39
|
+
}>;
|
|
40
|
+
is_error?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Thinking content block (extended thinking)
|
|
44
|
+
*/
|
|
45
|
+
export interface ThinkingBlock {
|
|
46
|
+
type: 'thinking';
|
|
47
|
+
thinking: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Image content block
|
|
51
|
+
*/
|
|
52
|
+
export interface ImageBlock {
|
|
53
|
+
type: 'image';
|
|
54
|
+
source: {
|
|
55
|
+
type: 'base64';
|
|
56
|
+
media_type: string;
|
|
57
|
+
data: string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Union type for all content blocks
|
|
62
|
+
*/
|
|
63
|
+
export type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock | ThinkingBlock | ImageBlock;
|
|
64
|
+
/**
|
|
65
|
+
* A message in the conversation
|
|
66
|
+
*/
|
|
67
|
+
export interface Message {
|
|
68
|
+
/** Message role */
|
|
69
|
+
role: MessageRole;
|
|
70
|
+
/** Message content */
|
|
71
|
+
content: ContentBlock[] | string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Usage statistics
|
|
75
|
+
*/
|
|
76
|
+
export interface Usage {
|
|
77
|
+
/** Input tokens used */
|
|
78
|
+
input_tokens: number;
|
|
79
|
+
/** Output tokens generated */
|
|
80
|
+
output_tokens: number;
|
|
81
|
+
/** Cache creation input tokens */
|
|
82
|
+
cache_creation_input_tokens?: number;
|
|
83
|
+
/** Cache read input tokens */
|
|
84
|
+
cache_read_input_tokens?: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Cost breakdown
|
|
88
|
+
*/
|
|
89
|
+
export interface CostBreakdown {
|
|
90
|
+
/** Input cost in USD */
|
|
91
|
+
input_cost_usd: number;
|
|
92
|
+
/** Output cost in USD */
|
|
93
|
+
output_cost_usd: number;
|
|
94
|
+
/** Total cost in USD */
|
|
95
|
+
total_cost_usd: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Session result (returned when session completes)
|
|
99
|
+
*/
|
|
100
|
+
export interface SessionResult {
|
|
101
|
+
/** Result type */
|
|
102
|
+
type: 'result';
|
|
103
|
+
/** Result subtype */
|
|
104
|
+
subtype?: 'success' | 'error' | 'interrupted';
|
|
105
|
+
/** Final response text */
|
|
106
|
+
text?: string;
|
|
107
|
+
/** Conversation messages */
|
|
108
|
+
messages?: Message[];
|
|
109
|
+
/** Total cost in USD */
|
|
110
|
+
total_cost_usd?: number;
|
|
111
|
+
/** Session duration in seconds */
|
|
112
|
+
duration_secs?: number;
|
|
113
|
+
/** Number of conversation turns */
|
|
114
|
+
turn_count?: number;
|
|
115
|
+
/** Usage statistics */
|
|
116
|
+
usage?: Usage;
|
|
117
|
+
/** Session ID (for resuming) */
|
|
118
|
+
session_id?: string;
|
|
119
|
+
/** Error message (if subtype is 'error') */
|
|
120
|
+
error?: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Prompt result (returned from one-shot prompts)
|
|
124
|
+
*/
|
|
125
|
+
export interface PromptResult {
|
|
126
|
+
/** Result type */
|
|
127
|
+
type: 'result';
|
|
128
|
+
/** Result subtype */
|
|
129
|
+
subtype?: 'success' | 'error';
|
|
130
|
+
/** Response text */
|
|
131
|
+
text?: string;
|
|
132
|
+
/** Structured output (if outputFormat was specified) */
|
|
133
|
+
output?: unknown;
|
|
134
|
+
/** Total cost in USD */
|
|
135
|
+
total_cost_usd?: number;
|
|
136
|
+
/** Duration in seconds */
|
|
137
|
+
duration_secs?: number;
|
|
138
|
+
/** Usage statistics */
|
|
139
|
+
usage?: Usage;
|
|
140
|
+
/** Error message (if subtype is 'error') */
|
|
141
|
+
error?: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Streaming message event
|
|
145
|
+
*/
|
|
146
|
+
export interface StreamEvent {
|
|
147
|
+
/** Event type */
|
|
148
|
+
type: 'message_start' | 'content_block_start' | 'content_block_delta' | 'content_block_stop' | 'message_delta' | 'message_stop' | 'tool_use' | 'tool_result' | 'error';
|
|
149
|
+
/** Event data */
|
|
150
|
+
data: unknown;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Partial message (during streaming)
|
|
154
|
+
*/
|
|
155
|
+
export interface PartialMessage {
|
|
156
|
+
/** Message role */
|
|
157
|
+
role: MessageRole;
|
|
158
|
+
/** Partial content accumulated so far */
|
|
159
|
+
content: ContentBlock[];
|
|
160
|
+
/** Whether the message is complete */
|
|
161
|
+
complete: boolean;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Session state
|
|
165
|
+
*/
|
|
166
|
+
export type SessionState = 'idle' | 'initializing' | 'ready' | 'processing' | 'waiting_tool' | 'completed' | 'error';
|
|
167
|
+
/**
|
|
168
|
+
* Session info (returned when connecting/resuming)
|
|
169
|
+
*/
|
|
170
|
+
export interface SessionInfo {
|
|
171
|
+
/** Session ID */
|
|
172
|
+
sessionId: string;
|
|
173
|
+
/** Current state */
|
|
174
|
+
state: SessionState;
|
|
175
|
+
/** Number of messages in conversation */
|
|
176
|
+
messageCount?: number;
|
|
177
|
+
/** Session creation time (ISO 8601) */
|
|
178
|
+
createdAt?: string;
|
|
179
|
+
/** Last activity time (ISO 8601) */
|
|
180
|
+
lastActivityAt?: string;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=results.d.ts.map
|