@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,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chucky Client
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for the Chucky SDK.
|
|
5
|
+
* Provides methods to create sessions and execute prompts.
|
|
6
|
+
*/
|
|
7
|
+
import { WebSocketTransport } from '../transport/WebSocketTransport.js';
|
|
8
|
+
import { Session } from './Session.js';
|
|
9
|
+
/**
|
|
10
|
+
* Default base URL for the Chucky service
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_BASE_URL = 'wss://box.chucky.cloud/ws';
|
|
13
|
+
/**
|
|
14
|
+
* Chucky client for interacting with the sandbox service
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { ChuckyClient } from '@chucky.cloud/sdk';
|
|
19
|
+
*
|
|
20
|
+
* const client = new ChuckyClient({
|
|
21
|
+
* token: 'your-jwt-token',
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Create a session
|
|
25
|
+
* const session = await client.createSession({
|
|
26
|
+
* model: 'claude-sonnet-4-5-20250929',
|
|
27
|
+
* systemPrompt: 'You are a helpful assistant.',
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Send messages
|
|
31
|
+
* const result = await session.send('Hello, world!');
|
|
32
|
+
* console.log(result.text);
|
|
33
|
+
*
|
|
34
|
+
* // Or use one-shot prompts
|
|
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);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export class ChuckyClient {
|
|
43
|
+
options;
|
|
44
|
+
transport = null;
|
|
45
|
+
eventHandlers = {};
|
|
46
|
+
activeSessions = new Map();
|
|
47
|
+
/**
|
|
48
|
+
* Create a new Chucky client
|
|
49
|
+
*/
|
|
50
|
+
constructor(options) {
|
|
51
|
+
this.options = {
|
|
52
|
+
baseUrl: DEFAULT_BASE_URL,
|
|
53
|
+
debug: false,
|
|
54
|
+
...options,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the current connection status
|
|
59
|
+
*/
|
|
60
|
+
get status() {
|
|
61
|
+
return this.transport?.status ?? 'disconnected';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Set event handlers
|
|
65
|
+
*/
|
|
66
|
+
on(handlers) {
|
|
67
|
+
this.eventHandlers = { ...this.eventHandlers, ...handlers };
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a new session
|
|
72
|
+
*
|
|
73
|
+
* @param options - Session configuration options
|
|
74
|
+
* @returns A new session instance
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const session = await client.createSession({
|
|
79
|
+
* model: 'claude-sonnet-4-5-20250929',
|
|
80
|
+
* 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
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
async createSession(options = {}) {
|
|
101
|
+
const transport = this.createTransport();
|
|
102
|
+
const session = new Session(transport, options, {
|
|
103
|
+
debug: this.options.debug,
|
|
104
|
+
});
|
|
105
|
+
// Track the session
|
|
106
|
+
session.on({
|
|
107
|
+
onSessionInfo: (info) => {
|
|
108
|
+
this.activeSessions.set(info.sessionId, session);
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
await session.connect();
|
|
112
|
+
return session;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Resume an existing session
|
|
116
|
+
*
|
|
117
|
+
* @param sessionId - The session ID to resume
|
|
118
|
+
* @param options - Additional session options
|
|
119
|
+
* @returns The resumed session
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const session = await client.resumeSession('session-123', {
|
|
124
|
+
* continue: true,
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
async resumeSession(sessionId, options = {}) {
|
|
129
|
+
return this.createSession({
|
|
130
|
+
...options,
|
|
131
|
+
sessionId,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Execute a one-shot prompt (stateless)
|
|
136
|
+
*
|
|
137
|
+
* @param options - Prompt configuration
|
|
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
|
|
160
|
+
*
|
|
161
|
+
* @param options - Prompt configuration
|
|
162
|
+
* @yields Stream events and final result
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* for await (const event of client.promptStream({ message: 'Tell me a story' })) {
|
|
167
|
+
* if (event.type === 'text') {
|
|
168
|
+
* process.stdout.write(event.text);
|
|
169
|
+
* }
|
|
170
|
+
* }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
async *promptStream(options) {
|
|
174
|
+
const transport = this.createTransport();
|
|
175
|
+
const session = new Session(transport, options, {
|
|
176
|
+
debug: this.options.debug,
|
|
177
|
+
oneShot: true,
|
|
178
|
+
});
|
|
179
|
+
await session.connect();
|
|
180
|
+
for await (const event of session.sendStream(options.message)) {
|
|
181
|
+
yield event;
|
|
182
|
+
}
|
|
183
|
+
// Return final result
|
|
184
|
+
return session.getResult();
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Close all active sessions and disconnect
|
|
188
|
+
*/
|
|
189
|
+
async close() {
|
|
190
|
+
for (const session of this.activeSessions.values()) {
|
|
191
|
+
await session.close();
|
|
192
|
+
}
|
|
193
|
+
this.activeSessions.clear();
|
|
194
|
+
if (this.transport) {
|
|
195
|
+
await this.transport.disconnect();
|
|
196
|
+
this.transport = null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create a new transport instance
|
|
201
|
+
*/
|
|
202
|
+
createTransport() {
|
|
203
|
+
return new WebSocketTransport({
|
|
204
|
+
url: this.options.baseUrl,
|
|
205
|
+
token: this.options.token,
|
|
206
|
+
timeout: this.options.timeout,
|
|
207
|
+
keepAliveInterval: this.options.keepAliveInterval,
|
|
208
|
+
autoReconnect: this.options.autoReconnect,
|
|
209
|
+
maxReconnectAttempts: this.options.maxReconnectAttempts,
|
|
210
|
+
debug: this.options.debug,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Create a Chucky client
|
|
216
|
+
*
|
|
217
|
+
* @param options - Client configuration
|
|
218
|
+
* @returns A new ChuckyClient instance
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* import { createClient } from '@chucky.cloud/sdk';
|
|
223
|
+
*
|
|
224
|
+
* const client = createClient({
|
|
225
|
+
* token: 'your-jwt-token',
|
|
226
|
+
* });
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
export function createClient(options) {
|
|
230
|
+
return new ChuckyClient(options);
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=ChuckyClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChuckyClient.js","sourceRoot":"","sources":["../../src/client/ChuckyClient.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;GAEG;AACH,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,YAAY;IACN,OAAO,CAC6B;IAC7C,SAAS,GAA8B,IAAI,CAAC;IAC5C,aAAa,GAAwB,EAAE,CAAC;IACxC,cAAc,GAAyB,IAAI,GAAG,EAAE,CAAC;IAEzD;;OAEG;IACH,YAAY,OAAsB;QAChC,IAAI,CAAC,OAAO,GAAG;YACb,OAAO,EAAE,gBAAgB;YACzB,KAAK,EAAE,KAAK;YACZ,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,SAAS,EAAE,MAAM,IAAI,cAAc,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,EAAE,CAAC,QAA6B;QAC9B,IAAI,CAAC,aAAa,GAAG,EAAE,GAAG,IAAI,CAAC,aAAa,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,KAAK,CAAC,aAAa,CAAC,UAA0B,EAAE;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE;YAC9C,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KA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Supports multi-turn conversations, tool execution, and streaming.
|
|
6
|
+
*/
|
|
7
|
+
import type { SessionOptions } from '../types/options.js';
|
|
8
|
+
import type { SessionResult, SessionInfo, SessionState, Message } from '../types/results.js';
|
|
9
|
+
import type { ToolResult, ToolCall } from '../types/tools.js';
|
|
10
|
+
import type { Transport } from '../transport/Transport.js';
|
|
11
|
+
import type { StreamingEvent } from './ChuckyClient.js';
|
|
12
|
+
/**
|
|
13
|
+
* Session event handlers
|
|
14
|
+
*/
|
|
15
|
+
export interface SessionEventHandlers {
|
|
16
|
+
/** Called when session info is received */
|
|
17
|
+
onSessionInfo?: (info: SessionInfo) => void;
|
|
18
|
+
/** Called when a message is received */
|
|
19
|
+
onMessage?: (message: Message) => void;
|
|
20
|
+
/** Called when streaming text is received */
|
|
21
|
+
onText?: (text: string) => void;
|
|
22
|
+
/** Called when a tool is being used */
|
|
23
|
+
onToolUse?: (toolCall: ToolCall) => void;
|
|
24
|
+
/** Called when a tool result is returned */
|
|
25
|
+
onToolResult?: (callId: string, result: ToolResult) => void;
|
|
26
|
+
/** Called when thinking is received */
|
|
27
|
+
onThinking?: (thinking: string) => void;
|
|
28
|
+
/** Called when session completes */
|
|
29
|
+
onComplete?: (result: SessionResult) => void;
|
|
30
|
+
/** Called when an error occurs */
|
|
31
|
+
onError?: (error: Error) => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Internal session configuration
|
|
35
|
+
*/
|
|
36
|
+
interface SessionConfig {
|
|
37
|
+
debug?: boolean;
|
|
38
|
+
oneShot?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Session class for managing conversations
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const session = await client.createSession({
|
|
46
|
+
* model: 'claude-sonnet-4-5-20250929',
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Simple send
|
|
50
|
+
* const result = await session.send('Hello!');
|
|
51
|
+
*
|
|
52
|
+
* // Streaming
|
|
53
|
+
* for await (const event of session.sendStream('Tell me a story')) {
|
|
54
|
+
* if (event.type === 'text') {
|
|
55
|
+
* process.stdout.write(event.text);
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* // Multi-turn
|
|
60
|
+
* await session.send('What is the capital of France?');
|
|
61
|
+
* await session.send('What about Germany?');
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare class Session {
|
|
65
|
+
private transport;
|
|
66
|
+
private options;
|
|
67
|
+
private config;
|
|
68
|
+
private eventHandlers;
|
|
69
|
+
private toolHandlers;
|
|
70
|
+
private messageBuffer;
|
|
71
|
+
private currentResult;
|
|
72
|
+
private _state;
|
|
73
|
+
private _sessionId;
|
|
74
|
+
private messageResolvers;
|
|
75
|
+
constructor(transport: Transport, options: SessionOptions, config?: SessionConfig);
|
|
76
|
+
/**
|
|
77
|
+
* Get the current session state
|
|
78
|
+
*/
|
|
79
|
+
get state(): SessionState;
|
|
80
|
+
/**
|
|
81
|
+
* Get the session ID
|
|
82
|
+
*/
|
|
83
|
+
get sessionId(): string | null;
|
|
84
|
+
/**
|
|
85
|
+
* Set event handlers
|
|
86
|
+
*/
|
|
87
|
+
on(handlers: SessionEventHandlers): this;
|
|
88
|
+
/**
|
|
89
|
+
* Connect and initialize the session
|
|
90
|
+
*/
|
|
91
|
+
connect(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Send a message and wait for complete response
|
|
94
|
+
*/
|
|
95
|
+
send(message: string): Promise<SessionResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Send a message with streaming
|
|
98
|
+
*/
|
|
99
|
+
sendStream(message: string): AsyncGenerator<StreamingEvent, void, unknown>;
|
|
100
|
+
/**
|
|
101
|
+
* Execute a one-shot prompt
|
|
102
|
+
*/
|
|
103
|
+
prompt(message: string): Promise<SessionResult>;
|
|
104
|
+
/**
|
|
105
|
+
* Get the current/last result
|
|
106
|
+
*/
|
|
107
|
+
getResult(): SessionResult | null;
|
|
108
|
+
/**
|
|
109
|
+
* Close the session
|
|
110
|
+
*/
|
|
111
|
+
close(): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Build init payload from options
|
|
114
|
+
*/
|
|
115
|
+
private buildInitPayload;
|
|
116
|
+
/**
|
|
117
|
+
* Handle incoming message
|
|
118
|
+
*/
|
|
119
|
+
private handleMessage;
|
|
120
|
+
/**
|
|
121
|
+
* Wait for session to be ready
|
|
122
|
+
*/
|
|
123
|
+
private waitForReady;
|
|
124
|
+
/**
|
|
125
|
+
* Wait for result
|
|
126
|
+
*/
|
|
127
|
+
private waitForResult;
|
|
128
|
+
/**
|
|
129
|
+
* Wait for next message
|
|
130
|
+
*/
|
|
131
|
+
private waitForNextMessage;
|
|
132
|
+
/**
|
|
133
|
+
* Handle a tool call
|
|
134
|
+
*/
|
|
135
|
+
private handleToolCall;
|
|
136
|
+
/**
|
|
137
|
+
* Convert message to streaming events
|
|
138
|
+
*/
|
|
139
|
+
private messageToStreamingEvents;
|
|
140
|
+
/**
|
|
141
|
+
* Log debug messages
|
|
142
|
+
*/
|
|
143
|
+
private log;
|
|
144
|
+
}
|
|
145
|
+
export {};
|
|
146
|
+
//# sourceMappingURL=Session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Session.d.ts","sourceRoot":"","sources":["../../src/client/Session.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC7F,OAAO,KAAK,EAAkB,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAY9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBA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