@chucky.cloud/sdk 0.2.0 → 0.2.2
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/dist/client/ChuckyClient.d.ts +45 -91
- package/dist/client/ChuckyClient.d.ts.map +1 -1
- package/dist/client/ChuckyClient.js +65 -88
- package/dist/client/ChuckyClient.js.map +1 -1
- package/dist/client/Session.d.ts +88 -67
- package/dist/client/Session.d.ts.map +1 -1
- package/dist/client/Session.js +153 -172
- package/dist/client/Session.js.map +1 -1
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -1
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/transport/Transport.d.ts.map +1 -1
- package/dist/transport/Transport.js +6 -4
- package/dist/transport/Transport.js.map +1 -1
- package/dist/transport/WebSocketTransport.d.ts.map +1 -1
- package/dist/transport/WebSocketTransport.js +7 -2
- package/dist/transport/WebSocketTransport.js.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/messages.d.ts +225 -92
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/messages.js +78 -15
- package/dist/types/messages.js.map +1 -1
- package/dist/types/results.d.ts +6 -2
- package/dist/types/results.d.ts.map +1 -1
- package/dist/types/tools.d.ts +5 -5
- package/dist/types/tools.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Main entry point for the Chucky SDK.
|
|
5
5
|
* Provides methods to create sessions and execute prompts.
|
|
6
|
+
* Matches the official Claude Agent SDK V2 interface.
|
|
6
7
|
*/
|
|
7
|
-
import type { ClientOptions, SessionOptions,
|
|
8
|
-
import type {
|
|
9
|
-
import { Session } from './Session.js';
|
|
8
|
+
import type { ClientOptions, SessionOptions, ClientEventHandlers } from '../types/options.js';
|
|
9
|
+
import type { SDKResultMessage } from '../types/messages.js';
|
|
10
|
+
import { Session, getAssistantText, getResultText } from './Session.js';
|
|
10
11
|
/**
|
|
11
12
|
* Chucky client for interacting with the sandbox service
|
|
12
13
|
*
|
|
14
|
+
* Matches the official Claude Agent SDK V2 interface.
|
|
15
|
+
*
|
|
13
16
|
* @example
|
|
14
17
|
* ```typescript
|
|
15
18
|
* import { ChuckyClient } from '@chucky.cloud/sdk';
|
|
@@ -18,37 +21,35 @@ import { Session } from './Session.js';
|
|
|
18
21
|
* token: 'your-jwt-token',
|
|
19
22
|
* });
|
|
20
23
|
*
|
|
21
|
-
* // Create a session
|
|
22
|
-
* const session =
|
|
24
|
+
* // Create a session (V2 style)
|
|
25
|
+
* const session = client.createSession({
|
|
23
26
|
* model: 'claude-sonnet-4-5-20250929',
|
|
24
27
|
* systemPrompt: 'You are a helpful assistant.',
|
|
25
28
|
* });
|
|
26
29
|
*
|
|
27
|
-
* // Send messages
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
+
* // Send messages and stream responses
|
|
31
|
+
* await session.send('Hello, world!');
|
|
32
|
+
* for await (const msg of session.stream()) {
|
|
33
|
+
* if (msg.type === 'assistant') {
|
|
34
|
+
* const text = getAssistantText(msg);
|
|
35
|
+
* console.log(text);
|
|
36
|
+
* }
|
|
37
|
+
* if (msg.type === 'result') {
|
|
38
|
+
* console.log('Done:', msg);
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
30
41
|
*
|
|
31
|
-
*
|
|
32
|
-
* const response = await client.prompt({
|
|
33
|
-
* message: 'What is 2 + 2?',
|
|
34
|
-
* model: 'claude-sonnet-4-5-20250929',
|
|
35
|
-
* });
|
|
36
|
-
* console.log(response.text);
|
|
42
|
+
* session.close();
|
|
37
43
|
* ```
|
|
38
44
|
*/
|
|
39
45
|
export declare class ChuckyClient {
|
|
40
46
|
private readonly options;
|
|
41
|
-
private transport;
|
|
42
47
|
private eventHandlers;
|
|
43
48
|
private activeSessions;
|
|
44
49
|
/**
|
|
45
50
|
* Create a new Chucky client
|
|
46
51
|
*/
|
|
47
52
|
constructor(options: ClientOptions);
|
|
48
|
-
/**
|
|
49
|
-
* Get the current connection status
|
|
50
|
-
*/
|
|
51
|
-
get status(): ConnectionStatus;
|
|
52
53
|
/**
|
|
53
54
|
* Set event handlers
|
|
54
55
|
*/
|
|
@@ -56,34 +57,26 @@ export declare class ChuckyClient {
|
|
|
56
57
|
/**
|
|
57
58
|
* Create a new session
|
|
58
59
|
*
|
|
60
|
+
* Matches V2 SDK: createSession() returns a Session immediately.
|
|
61
|
+
* Connection happens automatically on first send().
|
|
62
|
+
*
|
|
59
63
|
* @param options - Session configuration options
|
|
60
64
|
* @returns A new session instance
|
|
61
65
|
*
|
|
62
66
|
* @example
|
|
63
67
|
* ```typescript
|
|
64
|
-
* const session =
|
|
68
|
+
* const session = client.createSession({
|
|
65
69
|
* model: 'claude-sonnet-4-5-20250929',
|
|
66
70
|
* systemPrompt: 'You are a helpful coding assistant.',
|
|
67
|
-
* tools: [
|
|
68
|
-
* {
|
|
69
|
-
* name: 'get_weather',
|
|
70
|
-
* description: 'Get the current weather',
|
|
71
|
-
* inputSchema: {
|
|
72
|
-
* type: 'object',
|
|
73
|
-
* properties: {
|
|
74
|
-
* city: { type: 'string', description: 'City name' },
|
|
75
|
-
* },
|
|
76
|
-
* required: ['city'],
|
|
77
|
-
* },
|
|
78
|
-
* handler: async ({ city }) => ({
|
|
79
|
-
* content: [{ type: 'text', text: `Weather in ${city}: Sunny, 72°F` }],
|
|
80
|
-
* }),
|
|
81
|
-
* },
|
|
82
|
-
* ],
|
|
83
71
|
* });
|
|
72
|
+
*
|
|
73
|
+
* await session.send('Hello!');
|
|
74
|
+
* for await (const msg of session.stream()) {
|
|
75
|
+
* // Handle messages
|
|
76
|
+
* }
|
|
84
77
|
* ```
|
|
85
78
|
*/
|
|
86
|
-
createSession(options?: SessionOptions):
|
|
79
|
+
createSession(options?: SessionOptions): Session;
|
|
87
80
|
/**
|
|
88
81
|
* Resume an existing session
|
|
89
82
|
*
|
|
@@ -93,81 +86,41 @@ export declare class ChuckyClient {
|
|
|
93
86
|
*
|
|
94
87
|
* @example
|
|
95
88
|
* ```typescript
|
|
96
|
-
* const session =
|
|
97
|
-
*
|
|
98
|
-
* });
|
|
89
|
+
* const session = client.resumeSession('session-123');
|
|
90
|
+
* await session.send('Continue our conversation');
|
|
99
91
|
* ```
|
|
100
92
|
*/
|
|
101
|
-
resumeSession(sessionId: string, options?: Omit<SessionOptions, 'sessionId'>):
|
|
93
|
+
resumeSession(sessionId: string, options?: Omit<SessionOptions, 'sessionId'>): Session;
|
|
102
94
|
/**
|
|
103
95
|
* Execute a one-shot prompt (stateless)
|
|
104
96
|
*
|
|
105
|
-
*
|
|
106
|
-
* @returns The prompt result
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```typescript
|
|
110
|
-
* const result = await client.prompt({
|
|
111
|
-
* message: 'Explain quantum computing in simple terms',
|
|
112
|
-
* model: 'claude-sonnet-4-5-20250929',
|
|
113
|
-
* });
|
|
114
|
-
* console.log(result.text);
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
prompt(options: PromptOptions): Promise<PromptResult>;
|
|
118
|
-
/**
|
|
119
|
-
* Execute a prompt with streaming
|
|
97
|
+
* Matches V2 SDK: prompt() for simple one-off queries.
|
|
120
98
|
*
|
|
99
|
+
* @param message - The message to send
|
|
121
100
|
* @param options - Prompt configuration
|
|
122
|
-
* @
|
|
101
|
+
* @returns The result message
|
|
123
102
|
*
|
|
124
103
|
* @example
|
|
125
104
|
* ```typescript
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
105
|
+
* const result = await client.prompt(
|
|
106
|
+
* 'Explain quantum computing in simple terms',
|
|
107
|
+
* { model: 'claude-sonnet-4-5-20250929' }
|
|
108
|
+
* );
|
|
109
|
+
* if (result.subtype === 'success') {
|
|
110
|
+
* console.log(result.result);
|
|
130
111
|
* }
|
|
131
112
|
* ```
|
|
132
113
|
*/
|
|
133
|
-
|
|
114
|
+
prompt(message: string, options?: SessionOptions): Promise<SDKResultMessage>;
|
|
134
115
|
/**
|
|
135
116
|
* Close all active sessions and disconnect
|
|
136
117
|
*/
|
|
137
|
-
close():
|
|
118
|
+
close(): void;
|
|
138
119
|
/**
|
|
139
120
|
* Create a new transport instance
|
|
140
121
|
*/
|
|
141
122
|
private createTransport;
|
|
142
123
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Streaming event types
|
|
145
|
-
*/
|
|
146
|
-
export interface StreamingTextEvent {
|
|
147
|
-
type: 'text';
|
|
148
|
-
text: string;
|
|
149
|
-
}
|
|
150
|
-
export interface StreamingToolUseEvent {
|
|
151
|
-
type: 'tool_use';
|
|
152
|
-
id: string;
|
|
153
|
-
name: string;
|
|
154
|
-
input: Record<string, unknown>;
|
|
155
|
-
}
|
|
156
|
-
export interface StreamingToolResultEvent {
|
|
157
|
-
type: 'tool_result';
|
|
158
|
-
id: string;
|
|
159
|
-
content: unknown;
|
|
160
|
-
isError?: boolean;
|
|
161
|
-
}
|
|
162
|
-
export interface StreamingThinkingEvent {
|
|
163
|
-
type: 'thinking';
|
|
164
|
-
thinking: string;
|
|
165
|
-
}
|
|
166
|
-
export interface StreamingErrorEvent {
|
|
167
|
-
type: 'error';
|
|
168
|
-
error: Error;
|
|
169
|
-
}
|
|
170
|
-
export type StreamingEvent = StreamingTextEvent | StreamingToolUseEvent | StreamingToolResultEvent | StreamingThinkingEvent | StreamingErrorEvent;
|
|
171
124
|
/**
|
|
172
125
|
* Create a Chucky client
|
|
173
126
|
*
|
|
@@ -184,4 +137,5 @@ export type StreamingEvent = StreamingTextEvent | StreamingToolUseEvent | Stream
|
|
|
184
137
|
* ```
|
|
185
138
|
*/
|
|
186
139
|
export declare function createClient(options: ClientOptions): ChuckyClient;
|
|
140
|
+
export { getAssistantText, getResultText };
|
|
187
141
|
//# sourceMappingURL=ChuckyClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChuckyClient.d.ts","sourceRoot":"","sources":["../../src/client/ChuckyClient.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ChuckyClient.d.ts","sourceRoot":"","sources":["../../src/client/ChuckyClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAOxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAC6B;IACrD,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,cAAc,CAAmC;IAEzD;;OAEG;gBACS,OAAO,EAAE,aAAa;IAQlC;;OAEG;IACH,EAAE,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI;IAKvC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO;IAkBpD;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,WAAW,CAAM,GAAG,OAAO;IAO1F;;;;;;;;;;;;;;;;;;;OAmBG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAwBtF;;OAEG;IACH,KAAK,IAAI,IAAI;IAOb;;OAEG;IACH,OAAO,CAAC,eAAe;CAWxB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CAEjE;AAGD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Main entry point for the Chucky SDK.
|
|
5
5
|
* Provides methods to create sessions and execute prompts.
|
|
6
|
+
* Matches the official Claude Agent SDK V2 interface.
|
|
6
7
|
*/
|
|
7
8
|
import { WebSocketTransport } from '../transport/WebSocketTransport.js';
|
|
8
|
-
import { Session } from './Session.js';
|
|
9
|
+
import { Session, getAssistantText, getResultText } from './Session.js';
|
|
9
10
|
/**
|
|
10
11
|
* Default base URL for the Chucky service
|
|
11
12
|
*/
|
|
@@ -13,6 +14,8 @@ const DEFAULT_BASE_URL = 'wss://conjure.chucky.cloud/ws';
|
|
|
13
14
|
/**
|
|
14
15
|
* Chucky client for interacting with the sandbox service
|
|
15
16
|
*
|
|
17
|
+
* Matches the official Claude Agent SDK V2 interface.
|
|
18
|
+
*
|
|
16
19
|
* @example
|
|
17
20
|
* ```typescript
|
|
18
21
|
* import { ChuckyClient } from '@chucky.cloud/sdk';
|
|
@@ -21,27 +24,29 @@ const DEFAULT_BASE_URL = 'wss://conjure.chucky.cloud/ws';
|
|
|
21
24
|
* token: 'your-jwt-token',
|
|
22
25
|
* });
|
|
23
26
|
*
|
|
24
|
-
* // Create a session
|
|
25
|
-
* const session =
|
|
27
|
+
* // Create a session (V2 style)
|
|
28
|
+
* const session = client.createSession({
|
|
26
29
|
* model: 'claude-sonnet-4-5-20250929',
|
|
27
30
|
* systemPrompt: 'You are a helpful assistant.',
|
|
28
31
|
* });
|
|
29
32
|
*
|
|
30
|
-
* // Send messages
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
+
* // Send messages and stream responses
|
|
34
|
+
* await session.send('Hello, world!');
|
|
35
|
+
* for await (const msg of session.stream()) {
|
|
36
|
+
* if (msg.type === 'assistant') {
|
|
37
|
+
* const text = getAssistantText(msg);
|
|
38
|
+
* console.log(text);
|
|
39
|
+
* }
|
|
40
|
+
* if (msg.type === 'result') {
|
|
41
|
+
* console.log('Done:', msg);
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
33
44
|
*
|
|
34
|
-
*
|
|
35
|
-
* const response = await client.prompt({
|
|
36
|
-
* message: 'What is 2 + 2?',
|
|
37
|
-
* model: 'claude-sonnet-4-5-20250929',
|
|
38
|
-
* });
|
|
39
|
-
* console.log(response.text);
|
|
45
|
+
* session.close();
|
|
40
46
|
* ```
|
|
41
47
|
*/
|
|
42
48
|
export class ChuckyClient {
|
|
43
49
|
options;
|
|
44
|
-
transport = null;
|
|
45
50
|
eventHandlers = {};
|
|
46
51
|
activeSessions = new Map();
|
|
47
52
|
/**
|
|
@@ -54,12 +59,6 @@ export class ChuckyClient {
|
|
|
54
59
|
...options,
|
|
55
60
|
};
|
|
56
61
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Get the current connection status
|
|
59
|
-
*/
|
|
60
|
-
get status() {
|
|
61
|
-
return this.transport?.status ?? 'disconnected';
|
|
62
|
-
}
|
|
63
62
|
/**
|
|
64
63
|
* Set event handlers
|
|
65
64
|
*/
|
|
@@ -70,34 +69,26 @@ export class ChuckyClient {
|
|
|
70
69
|
/**
|
|
71
70
|
* Create a new session
|
|
72
71
|
*
|
|
72
|
+
* Matches V2 SDK: createSession() returns a Session immediately.
|
|
73
|
+
* Connection happens automatically on first send().
|
|
74
|
+
*
|
|
73
75
|
* @param options - Session configuration options
|
|
74
76
|
* @returns A new session instance
|
|
75
77
|
*
|
|
76
78
|
* @example
|
|
77
79
|
* ```typescript
|
|
78
|
-
* const session =
|
|
80
|
+
* const session = client.createSession({
|
|
79
81
|
* model: 'claude-sonnet-4-5-20250929',
|
|
80
82
|
* systemPrompt: 'You are a helpful coding assistant.',
|
|
81
|
-
* tools: [
|
|
82
|
-
* {
|
|
83
|
-
* name: 'get_weather',
|
|
84
|
-
* description: 'Get the current weather',
|
|
85
|
-
* inputSchema: {
|
|
86
|
-
* type: 'object',
|
|
87
|
-
* properties: {
|
|
88
|
-
* city: { type: 'string', description: 'City name' },
|
|
89
|
-
* },
|
|
90
|
-
* required: ['city'],
|
|
91
|
-
* },
|
|
92
|
-
* handler: async ({ city }) => ({
|
|
93
|
-
* content: [{ type: 'text', text: `Weather in ${city}: Sunny, 72°F` }],
|
|
94
|
-
* }),
|
|
95
|
-
* },
|
|
96
|
-
* ],
|
|
97
83
|
* });
|
|
84
|
+
*
|
|
85
|
+
* await session.send('Hello!');
|
|
86
|
+
* for await (const msg of session.stream()) {
|
|
87
|
+
* // Handle messages
|
|
88
|
+
* }
|
|
98
89
|
* ```
|
|
99
90
|
*/
|
|
100
|
-
|
|
91
|
+
createSession(options = {}) {
|
|
101
92
|
const transport = this.createTransport();
|
|
102
93
|
const session = new Session(transport, options, {
|
|
103
94
|
debug: this.options.debug,
|
|
@@ -105,10 +96,11 @@ export class ChuckyClient {
|
|
|
105
96
|
// Track the session
|
|
106
97
|
session.on({
|
|
107
98
|
onSessionInfo: (info) => {
|
|
108
|
-
|
|
99
|
+
if (info.sessionId) {
|
|
100
|
+
this.activeSessions.set(info.sessionId, session);
|
|
101
|
+
}
|
|
109
102
|
},
|
|
110
103
|
});
|
|
111
|
-
await session.connect();
|
|
112
104
|
return session;
|
|
113
105
|
}
|
|
114
106
|
/**
|
|
@@ -120,12 +112,11 @@ export class ChuckyClient {
|
|
|
120
112
|
*
|
|
121
113
|
* @example
|
|
122
114
|
* ```typescript
|
|
123
|
-
* const session =
|
|
124
|
-
*
|
|
125
|
-
* });
|
|
115
|
+
* const session = client.resumeSession('session-123');
|
|
116
|
+
* await session.send('Continue our conversation');
|
|
126
117
|
* ```
|
|
127
118
|
*/
|
|
128
|
-
|
|
119
|
+
resumeSession(sessionId, options = {}) {
|
|
129
120
|
return this.createSession({
|
|
130
121
|
...options,
|
|
131
122
|
sessionId,
|
|
@@ -134,67 +125,51 @@ export class ChuckyClient {
|
|
|
134
125
|
/**
|
|
135
126
|
* Execute a one-shot prompt (stateless)
|
|
136
127
|
*
|
|
137
|
-
*
|
|
138
|
-
* @returns The prompt result
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```typescript
|
|
142
|
-
* const result = await client.prompt({
|
|
143
|
-
* message: 'Explain quantum computing in simple terms',
|
|
144
|
-
* model: 'claude-sonnet-4-5-20250929',
|
|
145
|
-
* });
|
|
146
|
-
* console.log(result.text);
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
async prompt(options) {
|
|
150
|
-
const transport = this.createTransport();
|
|
151
|
-
const session = new Session(transport, options, {
|
|
152
|
-
debug: this.options.debug,
|
|
153
|
-
oneShot: true,
|
|
154
|
-
});
|
|
155
|
-
await session.connect();
|
|
156
|
-
return session.prompt(options.message);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Execute a prompt with streaming
|
|
128
|
+
* Matches V2 SDK: prompt() for simple one-off queries.
|
|
160
129
|
*
|
|
130
|
+
* @param message - The message to send
|
|
161
131
|
* @param options - Prompt configuration
|
|
162
|
-
* @
|
|
132
|
+
* @returns The result message
|
|
163
133
|
*
|
|
164
134
|
* @example
|
|
165
135
|
* ```typescript
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
136
|
+
* const result = await client.prompt(
|
|
137
|
+
* 'Explain quantum computing in simple terms',
|
|
138
|
+
* { model: 'claude-sonnet-4-5-20250929' }
|
|
139
|
+
* );
|
|
140
|
+
* if (result.subtype === 'success') {
|
|
141
|
+
* console.log(result.result);
|
|
170
142
|
* }
|
|
171
143
|
* ```
|
|
172
144
|
*/
|
|
173
|
-
async
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
145
|
+
async prompt(message, options = {}) {
|
|
146
|
+
const session = this.createSession(options);
|
|
147
|
+
try {
|
|
148
|
+
await session.send(message);
|
|
149
|
+
let result = null;
|
|
150
|
+
for await (const msg of session.stream()) {
|
|
151
|
+
if (msg.type === 'result') {
|
|
152
|
+
result = msg;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (!result) {
|
|
157
|
+
throw new Error('No result message received');
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
session.close();
|
|
182
163
|
}
|
|
183
|
-
// Return final result
|
|
184
|
-
return session.getResult();
|
|
185
164
|
}
|
|
186
165
|
/**
|
|
187
166
|
* Close all active sessions and disconnect
|
|
188
167
|
*/
|
|
189
|
-
|
|
168
|
+
close() {
|
|
190
169
|
for (const session of this.activeSessions.values()) {
|
|
191
|
-
|
|
170
|
+
session.close();
|
|
192
171
|
}
|
|
193
172
|
this.activeSessions.clear();
|
|
194
|
-
if (this.transport) {
|
|
195
|
-
await this.transport.disconnect();
|
|
196
|
-
this.transport = null;
|
|
197
|
-
}
|
|
198
173
|
}
|
|
199
174
|
/**
|
|
200
175
|
* Create a new transport instance
|
|
@@ -229,4 +204,6 @@ export class ChuckyClient {
|
|
|
229
204
|
export function createClient(options) {
|
|
230
205
|
return new ChuckyClient(options);
|
|
231
206
|
}
|
|
207
|
+
// Re-export helpers for convenience
|
|
208
|
+
export { getAssistantText, getResultText };
|
|
232
209
|
//# sourceMappingURL=ChuckyClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChuckyClient.js","sourceRoot":"","sources":["../../src/client/ChuckyClient.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ChuckyClient.js","sourceRoot":"","sources":["../../src/client/ChuckyClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,aAAa,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