@ai-accounts/ts-core 0.3.0-alpha.1 → 0.3.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/dist/index.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AiAccountsClient: () => AiAccountsClient,
24
+ PtySocket: () => PtySocket,
24
25
  WIRE_PROTOCOL_VERSION: () => WIRE_PROTOCOL_VERSION,
25
26
  createAccountWizard: () => createAccountWizard,
26
27
  createOnboardingFlow: () => createOnboardingFlow,
@@ -37,6 +38,7 @@ async function* parseSseLoginEvents(response) {
37
38
  const reader = response.body.getReader();
38
39
  const decoder = new TextDecoder();
39
40
  let buffer = "";
41
+ let consecutiveParseErrors = 0;
40
42
  try {
41
43
  while (true) {
42
44
  const { value, done } = await reader.read();
@@ -51,8 +53,25 @@ async function* parseSseLoginEvents(response) {
51
53
  if (!dataLine) continue;
52
54
  const payload = dataLine.slice(6);
53
55
  try {
54
- yield JSON.parse(payload);
56
+ const parsed = JSON.parse(payload);
57
+ if (parsed && typeof parsed === "object" && typeof parsed.type === "string") {
58
+ consecutiveParseErrors = 0;
59
+ yield parsed;
60
+ } else {
61
+ console.warn("[ai-accounts] SSE frame missing type field:", payload.slice(0, 200));
62
+ consecutiveParseErrors++;
63
+ }
55
64
  } catch {
65
+ console.warn("[ai-accounts] malformed SSE frame:", payload.slice(0, 200));
66
+ consecutiveParseErrors++;
67
+ }
68
+ if (consecutiveParseErrors >= 3) {
69
+ yield {
70
+ type: "failed",
71
+ code: "stream_corrupt",
72
+ message: "Multiple malformed SSE frames received"
73
+ };
74
+ return;
56
75
  }
57
76
  }
58
77
  }
@@ -61,6 +80,58 @@ async function* parseSseLoginEvents(response) {
61
80
  }
62
81
  }
63
82
 
83
+ // src/client/chat-stream.ts
84
+ async function* parseSseChatEvents(response) {
85
+ const reader = response.body.getReader();
86
+ const decoder = new TextDecoder();
87
+ let buf = "";
88
+ while (true) {
89
+ const { done, value } = await reader.read();
90
+ if (done) break;
91
+ buf += decoder.decode(value, { stream: true });
92
+ const parts = buf.split("\n\n");
93
+ buf = parts.pop() ?? "";
94
+ for (const part of parts) {
95
+ for (const line of part.split("\n")) {
96
+ if (line.startsWith("data: ")) {
97
+ const payload = line.slice(6).trim();
98
+ if (!payload) continue;
99
+ try {
100
+ yield JSON.parse(payload);
101
+ } catch {
102
+ console.warn("[ai-accounts] malformed SSE chat frame dropped:", payload.slice(0, 200));
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+
110
+ // src/client/smart-chat-stream.ts
111
+ async function* parseSseSmartChatEvents(response) {
112
+ const reader = response.body.getReader();
113
+ const decoder = new TextDecoder();
114
+ let buf = "";
115
+ while (true) {
116
+ const { done, value } = await reader.read();
117
+ if (done) break;
118
+ buf += decoder.decode(value, { stream: true });
119
+ const parts = buf.split("\n\n");
120
+ buf = parts.pop() ?? "";
121
+ for (const part of parts) {
122
+ for (const line of part.split("\n")) {
123
+ if (line.startsWith("data: ")) {
124
+ try {
125
+ yield JSON.parse(line.slice(6).trim());
126
+ } catch {
127
+ console.warn("[ai-accounts] malformed smart chat SSE frame");
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+
64
135
  // src/client/index.ts
65
136
  async function toError(r) {
66
137
  let code = "http_error";
@@ -296,6 +367,126 @@ var AiAccountsClient = class {
296
367
  if (!r.ok) throw await toError(r);
297
368
  return await r.json();
298
369
  }
370
+ // --- CLIProxyAPI Server Lifecycle ---
371
+ async cliproxyServerStart(port = 8317, apiKey = "not-needed") {
372
+ const r = await this._fetch(`${this.baseUrl}/api/v1/cliproxy/server/start`, {
373
+ method: "POST",
374
+ headers: this.headers(),
375
+ body: JSON.stringify({ port, api_key: apiKey })
376
+ });
377
+ if (!r.ok) throw await toError(r);
378
+ return await r.json();
379
+ }
380
+ async cliproxyServerStop() {
381
+ const r = await this._fetch(`${this.baseUrl}/api/v1/cliproxy/server/stop`, {
382
+ method: "POST",
383
+ headers: this.headers()
384
+ });
385
+ if (!r.ok) throw await toError(r);
386
+ return await r.json();
387
+ }
388
+ async cliproxyServerStatus() {
389
+ const r = await this._fetch(`${this.baseUrl}/api/v1/cliproxy/server/status`, {
390
+ headers: this.headers()
391
+ });
392
+ if (!r.ok) throw await toError(r);
393
+ return await r.json();
394
+ }
395
+ // --- Conversations / Chat ---
396
+ async createConversation(input) {
397
+ const r = await this._fetch(`${this.baseUrl}/api/v1/conversations/`, {
398
+ method: "POST",
399
+ headers: this.headers(),
400
+ body: JSON.stringify(input)
401
+ });
402
+ if (!r.ok) throw await toError(r);
403
+ return await r.json();
404
+ }
405
+ async listConversations(backendId) {
406
+ const qs = backendId ? `?backend_id=${encodeURIComponent(backendId)}` : "";
407
+ const r = await this._fetch(`${this.baseUrl}/api/v1/conversations/${qs}`, { headers: this.headers() });
408
+ if (!r.ok) throw await toError(r);
409
+ return await r.json();
410
+ }
411
+ async getConversation(id) {
412
+ const r = await this._fetch(`${this.baseUrl}/api/v1/conversations/${encodeURIComponent(id)}`, { headers: this.headers() });
413
+ if (!r.ok) throw await toError(r);
414
+ return await r.json();
415
+ }
416
+ async *streamChat(sessionId, content) {
417
+ const url = `${this.baseUrl}/api/v1/conversations/${encodeURIComponent(sessionId)}/messages`;
418
+ const headers = { ...this.headers(), Accept: "text/event-stream" };
419
+ const r = await this._fetch(url, { method: "POST", headers, body: JSON.stringify({ content }) });
420
+ if (!r.ok) throw await toError(r);
421
+ yield* parseSseChatEvents(r);
422
+ }
423
+ // --- Scheduler ---
424
+ async getSchedulerHealth() {
425
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/health`, { headers: this.headers() });
426
+ if (!r.ok) throw await toError(r);
427
+ return await r.json();
428
+ }
429
+ async getAccountHealth(id) {
430
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/health/${encodeURIComponent(id)}`, { headers: this.headers() });
431
+ if (!r.ok) throw await toError(r);
432
+ return await r.json();
433
+ }
434
+ async schedulerPick(kind) {
435
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/pick`, {
436
+ method: "POST",
437
+ headers: this.headers(),
438
+ body: JSON.stringify(kind ? { kind } : {})
439
+ });
440
+ if (r.status === 204) return null;
441
+ if (!r.ok) throw await toError(r);
442
+ return await r.json();
443
+ }
444
+ async getChain() {
445
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/chain`, { headers: this.headers() });
446
+ if (!r.ok) throw await toError(r);
447
+ return await r.json();
448
+ }
449
+ async setChain(entries) {
450
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/chain`, {
451
+ method: "PUT",
452
+ headers: this.headers(),
453
+ body: JSON.stringify({ entries })
454
+ });
455
+ if (!r.ok) throw await toError(r);
456
+ }
457
+ async markRateLimited(backendId, seconds, reason) {
458
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/mark-limited`, {
459
+ method: "POST",
460
+ headers: this.headers(),
461
+ body: JSON.stringify({ backend_id: backendId, cooldown_seconds: seconds, reason })
462
+ });
463
+ if (!r.ok) throw await toError(r);
464
+ }
465
+ // --- Smart Chat ---
466
+ async *sendChat(request, opts = {}) {
467
+ const url = `${this.baseUrl}/api/v1/chat/send`;
468
+ const headers = {
469
+ ...this.headers(),
470
+ Accept: "text/event-stream"
471
+ };
472
+ if (opts.lastEventId && opts.lastEventId > 0) {
473
+ headers["Last-Event-ID"] = String(opts.lastEventId);
474
+ }
475
+ const r = await this._fetch(url, {
476
+ method: "POST",
477
+ headers,
478
+ body: JSON.stringify(request),
479
+ ...opts.signal ? { signal: opts.signal } : {}
480
+ });
481
+ if (!r.ok) throw await toError(r);
482
+ yield* parseSseSmartChatEvents(r);
483
+ }
484
+ async createChatSession(backendId, model) {
485
+ return this.createConversation({ backend_id: backendId, model });
486
+ }
487
+ async listChatSessions(backendId) {
488
+ return this.listConversations(backendId);
489
+ }
299
490
  async postAction(id, action, body) {
300
491
  const r = await this._fetch(
301
492
  `${this.baseUrl}/api/v1/backends/${encodeURIComponent(id)}/${action}`,
@@ -322,6 +513,46 @@ var AiAccountsClient = class {
322
513
  }
323
514
  };
324
515
 
516
+ // src/client/pty-socket.ts
517
+ var PtySocket = class {
518
+ ws = null;
519
+ opts;
520
+ closed = false;
521
+ constructor(opts) {
522
+ this.opts = opts;
523
+ this.connect();
524
+ }
525
+ connect() {
526
+ if (this.closed) return;
527
+ this.ws = new WebSocket(this.opts.url);
528
+ this.ws.binaryType = "arraybuffer";
529
+ this.ws.onmessage = (event) => {
530
+ if (event.data instanceof ArrayBuffer) {
531
+ this.opts.onData(new Uint8Array(event.data));
532
+ }
533
+ };
534
+ this.ws.onclose = () => {
535
+ if (!this.closed && this.opts.reconnectMs) {
536
+ setTimeout(() => this.connect(), this.opts.reconnectMs);
537
+ }
538
+ this.opts.onClose?.();
539
+ };
540
+ this.ws.onerror = (e) => {
541
+ this.opts.onError?.(e);
542
+ };
543
+ }
544
+ send(data) {
545
+ if (this.ws?.readyState === WebSocket.OPEN) {
546
+ this.ws.send(data);
547
+ }
548
+ }
549
+ close() {
550
+ this.closed = true;
551
+ this.ws?.close();
552
+ this.ws = null;
553
+ }
554
+ };
555
+
325
556
  // src/machines/accountWizard.ts
326
557
  function createAccountWizard(opts) {
327
558
  const listeners = /* @__PURE__ */ new Set();
@@ -622,6 +853,7 @@ var version = "0.0.0";
622
853
  // Annotate the CommonJS export names for ESM import in node:
623
854
  0 && (module.exports = {
624
855
  AiAccountsClient,
856
+ PtySocket,
625
857
  WIRE_PROTOCOL_VERSION,
626
858
  createAccountWizard,
627
859
  createOnboardingFlow,
package/dist/index.d.cts CHANGED
@@ -73,6 +73,17 @@ type TextPrompt = {
73
73
  prompt: string;
74
74
  hidden: boolean;
75
75
  };
76
+ type MenuOptionDTO = {
77
+ number: number;
78
+ label: string;
79
+ description?: string | null;
80
+ };
81
+ type MenuPrompt = {
82
+ type: 'menu_prompt';
83
+ prompt_id: string;
84
+ prompt: string;
85
+ options: MenuOptionDTO[];
86
+ };
76
87
  type StdoutChunk = {
77
88
  type: 'stdout';
78
89
  text: string;
@@ -92,13 +103,94 @@ type LoginFailed = {
92
103
  code: string;
93
104
  message: string;
94
105
  };
95
- type LoginEvent = UrlPrompt | TextPrompt | StdoutChunk | ProgressUpdate | LoginComplete | LoginFailed;
106
+ type LoginEvent = UrlPrompt | TextPrompt | MenuPrompt | StdoutChunk | ProgressUpdate | LoginComplete | LoginFailed;
96
107
  type PromptAnswer = {
97
108
  prompt_id: string;
98
109
  answer: string;
99
110
  };
100
111
  type LoginFlowKind = 'api_key' | 'oauth_device' | 'cli_browser';
101
112
 
113
+ interface BackendResponse {
114
+ backend: string;
115
+ content: string;
116
+ status: 'streaming' | 'complete' | 'error' | 'timeout';
117
+ error?: string;
118
+ }
119
+ interface SynthesisState {
120
+ status: 'waiting' | 'streaming' | 'complete' | 'error';
121
+ content: string;
122
+ primaryBackend: string;
123
+ backendsCollected: string[];
124
+ error?: string;
125
+ }
126
+ interface BackendOption {
127
+ kind: string;
128
+ displayName: string;
129
+ accounts: string[];
130
+ models: string[];
131
+ }
132
+ type ProcessGroupType = 'tool_call' | 'reasoning' | 'code_execution';
133
+ interface ToolCallDelta {
134
+ id: string;
135
+ name?: string;
136
+ arguments?: string;
137
+ group_type?: ProcessGroupType;
138
+ }
139
+ type _WithSeq<T> = T & {
140
+ _seq?: number;
141
+ };
142
+ type SmartChatEvent = _WithSeq<{
143
+ kind: 'token';
144
+ payload: string;
145
+ } | {
146
+ kind: 'done';
147
+ payload: Record<string, unknown>;
148
+ } | {
149
+ kind: 'error';
150
+ payload: string;
151
+ } | {
152
+ kind: 'backend_delta';
153
+ backend: string;
154
+ text: string;
155
+ } | {
156
+ kind: 'backend_complete';
157
+ backend: string;
158
+ } | {
159
+ kind: 'backend_error';
160
+ backend: string;
161
+ error: string;
162
+ } | {
163
+ kind: 'backend_timeout';
164
+ backend: string;
165
+ } | {
166
+ kind: 'synthesis_start';
167
+ primary_backend: string;
168
+ backends_collected: string[];
169
+ } | {
170
+ kind: 'synthesis_delta';
171
+ text: string;
172
+ } | {
173
+ kind: 'synthesis_complete';
174
+ } | {
175
+ kind: 'synthesis_error';
176
+ error: string;
177
+ } | {
178
+ kind: 'tool_call';
179
+ id: string;
180
+ name?: string;
181
+ arguments?: string;
182
+ group_type?: ProcessGroupType;
183
+ }>;
184
+ type ChatMode = 'single' | 'all' | 'compound';
185
+ interface SendChatRequest {
186
+ session_id: string;
187
+ content: string;
188
+ mode?: ChatMode;
189
+ backend_kind?: string;
190
+ account_id?: string;
191
+ model?: string;
192
+ }
193
+
102
194
  type InstallCheck = {
103
195
  command: string[];
104
196
  version_regex: string;
@@ -170,6 +262,61 @@ type CliproxyCallbackForwardResponse = {
170
262
  message: string;
171
263
  };
172
264
 
265
+ interface ChatSessionDTO {
266
+ id: string;
267
+ backend_id: string;
268
+ model: string | null;
269
+ title: string | null;
270
+ created_at: string;
271
+ }
272
+ interface ChatMessageDTO {
273
+ id: string;
274
+ role: 'system' | 'user' | 'assistant' | 'tool';
275
+ content: string;
276
+ created_at: string;
277
+ model: string | null;
278
+ tokens_in: number | null;
279
+ tokens_out: number | null;
280
+ }
281
+ interface ChatSessionDetailDTO extends ChatSessionDTO {
282
+ messages: ChatMessageDTO[];
283
+ }
284
+ interface ChatDelta {
285
+ kind: 'token' | 'done' | 'error';
286
+ text: string | null;
287
+ finish_reason: string | null;
288
+ model: string | null;
289
+ tokens_in: number | null;
290
+ tokens_out: number | null;
291
+ }
292
+
293
+ interface UsageWindowDTO {
294
+ window_type: string;
295
+ usage_percent: number;
296
+ resets_at: string | null;
297
+ tokens_used: number | null;
298
+ tokens_limit: number | null;
299
+ }
300
+ interface AccountHealthDTO {
301
+ backend_id: string;
302
+ kind: string;
303
+ windows: UsageWindowDTO[];
304
+ rate_limited_until: string | null;
305
+ rate_limit_reason: string | null;
306
+ last_used_at: string | null;
307
+ last_polled_at: string | null;
308
+ }
309
+ interface PickResultDTO {
310
+ backend_id: string;
311
+ kind: string;
312
+ isolation_dir: string;
313
+ retry_after: string | null;
314
+ }
315
+ interface FallbackChainEntryDTO {
316
+ backend_id: string;
317
+ priority: number;
318
+ }
319
+
173
320
  /**
174
321
  * This file was auto-generated by openapi-typescript.
175
322
  * Do not make direct changes to the file.
@@ -1121,6 +1268,7 @@ interface BackendDTO {
1121
1268
  display_name: string;
1122
1269
  status: string;
1123
1270
  config: Record<string, unknown>;
1271
+ config_dir: string | null;
1124
1272
  last_error: string | null;
1125
1273
  }
1126
1274
  interface DetectResultDTO {
@@ -1204,6 +1352,50 @@ declare class AiAccountsClient {
1204
1352
  cliproxyInstall(): Promise<CliproxyInstallResult>;
1205
1353
  cliproxyLoginBegin(backendKind: string, configDir?: string): Promise<CliproxyLoginBeginResponse>;
1206
1354
  cliproxyCallbackForward(callbackUrl: string): Promise<CliproxyCallbackForwardResponse>;
1355
+ cliproxyServerStart(port?: number, apiKey?: string): Promise<{
1356
+ status: string;
1357
+ port: number;
1358
+ pid: number | null;
1359
+ message: string;
1360
+ }>;
1361
+ cliproxyServerStop(): Promise<{
1362
+ status: string;
1363
+ message: string;
1364
+ }>;
1365
+ cliproxyServerStatus(): Promise<{
1366
+ installed: boolean;
1367
+ running: boolean;
1368
+ port: number;
1369
+ version: string | null;
1370
+ }>;
1371
+ createConversation(input: {
1372
+ backend_id: string;
1373
+ model: string;
1374
+ title?: string;
1375
+ }): Promise<ChatSessionDTO>;
1376
+ listConversations(backendId?: string): Promise<{
1377
+ items: ChatSessionDTO[];
1378
+ }>;
1379
+ getConversation(id: string): Promise<ChatSessionDetailDTO>;
1380
+ streamChat(sessionId: string, content: string): AsyncIterable<ChatDelta>;
1381
+ getSchedulerHealth(): Promise<{
1382
+ items: AccountHealthDTO[];
1383
+ }>;
1384
+ getAccountHealth(id: string): Promise<AccountHealthDTO>;
1385
+ schedulerPick(kind?: string): Promise<PickResultDTO | null>;
1386
+ getChain(): Promise<{
1387
+ entries: FallbackChainEntryDTO[];
1388
+ }>;
1389
+ setChain(entries: FallbackChainEntryDTO[]): Promise<void>;
1390
+ markRateLimited(backendId: string, seconds: number, reason: string): Promise<void>;
1391
+ sendChat(request: SendChatRequest, opts?: {
1392
+ signal?: AbortSignal;
1393
+ lastEventId?: number;
1394
+ }): AsyncIterable<SmartChatEvent>;
1395
+ createChatSession(backendId: string, model: string): Promise<ChatSessionDTO>;
1396
+ listChatSessions(backendId?: string): Promise<{
1397
+ items: ChatSessionDTO[];
1398
+ }>;
1207
1399
  private postAction;
1208
1400
  private onboardingAction;
1209
1401
  }
@@ -1231,7 +1423,7 @@ type AiAccountsEvent = {
1231
1423
  } | {
1232
1424
  type: 'login.prompt';
1233
1425
  sessionId: string;
1234
- promptKind: 'url' | 'text';
1426
+ promptKind: 'url' | 'text' | 'menu';
1235
1427
  } | {
1236
1428
  type: 'login.completed';
1237
1429
  sessionId: string;
@@ -1248,6 +1440,33 @@ type AiAccountsEvent = {
1248
1440
  };
1249
1441
  type AiAccountsEventHandler = (event: AiAccountsEvent) => void;
1250
1442
 
1443
+ interface PtySessionDTO {
1444
+ session_id: string;
1445
+ }
1446
+ interface PtySpawnRequest {
1447
+ backend_id: string;
1448
+ command: string[];
1449
+ cols?: number;
1450
+ rows?: number;
1451
+ }
1452
+
1453
+ interface PtySocketOptions {
1454
+ url: string;
1455
+ onData: (data: Uint8Array) => void;
1456
+ onClose?: () => void;
1457
+ onError?: (error: Event) => void;
1458
+ reconnectMs?: number;
1459
+ }
1460
+ declare class PtySocket {
1461
+ private ws;
1462
+ private readonly opts;
1463
+ private closed;
1464
+ constructor(opts: PtySocketOptions);
1465
+ private connect;
1466
+ send(data: Uint8Array): void;
1467
+ close(): void;
1468
+ }
1469
+
1251
1470
  type WizardState = 'idle' | 'picking_kind' | 'detecting' | 'entering_credential' | 'validating' | 'done' | 'error';
1252
1471
  interface AccountWizard {
1253
1472
  readonly state: WizardState;
@@ -1297,4 +1516,4 @@ declare function createOnboardingFlow(opts: CreateOnboardingFlowOptions): Onboar
1297
1516
 
1298
1517
  declare const version = "0.0.0";
1299
1518
 
1300
- export { type AccountWizard, type paths as AiAccountsApiPaths, AiAccountsClient, type AiAccountsEvent, type AiAccountsEventHandler, type ApiError, type BackendDTO, type BackendMetadata, type ChatDoneEvent, type ChatTokenEvent, type ChatToolCallEvent, type ClientOptions, type CliproxyCallbackForwardResponse, type CliproxyInstallResult, type CliproxyLoginBeginResponse, type CliproxyStatus, type CreateAccountWizardOptions, type CreateOnboardingFlowOptions, type DetectResultDTO, type DetectResultsDTO, type ErrorEvent, type InputSpec, type InstallCheck, type InstallResult, type LoginComplete, type LoginEvent, type LoginFailed, type LoginFlowKind, type LoginFlowSpec, type LoginResponseDTO, type OAuthDeviceLoginDTO, type OnboardingFlowMachine, type OnboardingMachineState, type OnboardingStateDTO, type PlanOption, type ProgressUpdate, type PromptAnswer, type PtyExitEvent, type PtyOutputEvent, type PtyResizeEvent, type SessionEndEvent, type SessionStartEvent, type StdoutChunk, type TextPrompt, type UrlPrompt, WIRE_PROTOCOL_VERSION, type WireEvent, type WizardState, createAccountWizard, createOnboardingFlow, version };
1519
+ export { type AccountHealthDTO, type AccountWizard, type paths as AiAccountsApiPaths, AiAccountsClient, type AiAccountsEvent, type AiAccountsEventHandler, type ApiError, type BackendDTO, type BackendMetadata, type BackendOption, type BackendResponse, type ChatDelta, type ChatDoneEvent, type ChatMessageDTO, type ChatMode, type ChatSessionDTO, type ChatSessionDetailDTO, type ChatTokenEvent, type ChatToolCallEvent, type ClientOptions, type CliproxyCallbackForwardResponse, type CliproxyInstallResult, type CliproxyLoginBeginResponse, type CliproxyStatus, type CreateAccountWizardOptions, type CreateOnboardingFlowOptions, type DetectResultDTO, type DetectResultsDTO, type ErrorEvent, type FallbackChainEntryDTO, type InputSpec, type InstallCheck, type InstallResult, type LoginComplete, type LoginEvent, type LoginFailed, type LoginFlowKind, type LoginFlowSpec, type LoginResponseDTO, type MenuOptionDTO, type MenuPrompt, type OAuthDeviceLoginDTO, type OnboardingFlowMachine, type OnboardingMachineState, type OnboardingStateDTO, type PickResultDTO, type PlanOption, type ProcessGroupType, type ProgressUpdate, type PromptAnswer, type PtyExitEvent, type PtyOutputEvent, type PtyResizeEvent, type PtySessionDTO, PtySocket, type PtySocketOptions, type PtySpawnRequest, type SendChatRequest, type SessionEndEvent, type SessionStartEvent, type SmartChatEvent, type StdoutChunk, type SynthesisState, type TextPrompt, type ToolCallDelta, type UrlPrompt, type UsageWindowDTO, WIRE_PROTOCOL_VERSION, type WireEvent, type WizardState, createAccountWizard, createOnboardingFlow, version };
package/dist/index.d.ts CHANGED
@@ -73,6 +73,17 @@ type TextPrompt = {
73
73
  prompt: string;
74
74
  hidden: boolean;
75
75
  };
76
+ type MenuOptionDTO = {
77
+ number: number;
78
+ label: string;
79
+ description?: string | null;
80
+ };
81
+ type MenuPrompt = {
82
+ type: 'menu_prompt';
83
+ prompt_id: string;
84
+ prompt: string;
85
+ options: MenuOptionDTO[];
86
+ };
76
87
  type StdoutChunk = {
77
88
  type: 'stdout';
78
89
  text: string;
@@ -92,13 +103,94 @@ type LoginFailed = {
92
103
  code: string;
93
104
  message: string;
94
105
  };
95
- type LoginEvent = UrlPrompt | TextPrompt | StdoutChunk | ProgressUpdate | LoginComplete | LoginFailed;
106
+ type LoginEvent = UrlPrompt | TextPrompt | MenuPrompt | StdoutChunk | ProgressUpdate | LoginComplete | LoginFailed;
96
107
  type PromptAnswer = {
97
108
  prompt_id: string;
98
109
  answer: string;
99
110
  };
100
111
  type LoginFlowKind = 'api_key' | 'oauth_device' | 'cli_browser';
101
112
 
113
+ interface BackendResponse {
114
+ backend: string;
115
+ content: string;
116
+ status: 'streaming' | 'complete' | 'error' | 'timeout';
117
+ error?: string;
118
+ }
119
+ interface SynthesisState {
120
+ status: 'waiting' | 'streaming' | 'complete' | 'error';
121
+ content: string;
122
+ primaryBackend: string;
123
+ backendsCollected: string[];
124
+ error?: string;
125
+ }
126
+ interface BackendOption {
127
+ kind: string;
128
+ displayName: string;
129
+ accounts: string[];
130
+ models: string[];
131
+ }
132
+ type ProcessGroupType = 'tool_call' | 'reasoning' | 'code_execution';
133
+ interface ToolCallDelta {
134
+ id: string;
135
+ name?: string;
136
+ arguments?: string;
137
+ group_type?: ProcessGroupType;
138
+ }
139
+ type _WithSeq<T> = T & {
140
+ _seq?: number;
141
+ };
142
+ type SmartChatEvent = _WithSeq<{
143
+ kind: 'token';
144
+ payload: string;
145
+ } | {
146
+ kind: 'done';
147
+ payload: Record<string, unknown>;
148
+ } | {
149
+ kind: 'error';
150
+ payload: string;
151
+ } | {
152
+ kind: 'backend_delta';
153
+ backend: string;
154
+ text: string;
155
+ } | {
156
+ kind: 'backend_complete';
157
+ backend: string;
158
+ } | {
159
+ kind: 'backend_error';
160
+ backend: string;
161
+ error: string;
162
+ } | {
163
+ kind: 'backend_timeout';
164
+ backend: string;
165
+ } | {
166
+ kind: 'synthesis_start';
167
+ primary_backend: string;
168
+ backends_collected: string[];
169
+ } | {
170
+ kind: 'synthesis_delta';
171
+ text: string;
172
+ } | {
173
+ kind: 'synthesis_complete';
174
+ } | {
175
+ kind: 'synthesis_error';
176
+ error: string;
177
+ } | {
178
+ kind: 'tool_call';
179
+ id: string;
180
+ name?: string;
181
+ arguments?: string;
182
+ group_type?: ProcessGroupType;
183
+ }>;
184
+ type ChatMode = 'single' | 'all' | 'compound';
185
+ interface SendChatRequest {
186
+ session_id: string;
187
+ content: string;
188
+ mode?: ChatMode;
189
+ backend_kind?: string;
190
+ account_id?: string;
191
+ model?: string;
192
+ }
193
+
102
194
  type InstallCheck = {
103
195
  command: string[];
104
196
  version_regex: string;
@@ -170,6 +262,61 @@ type CliproxyCallbackForwardResponse = {
170
262
  message: string;
171
263
  };
172
264
 
265
+ interface ChatSessionDTO {
266
+ id: string;
267
+ backend_id: string;
268
+ model: string | null;
269
+ title: string | null;
270
+ created_at: string;
271
+ }
272
+ interface ChatMessageDTO {
273
+ id: string;
274
+ role: 'system' | 'user' | 'assistant' | 'tool';
275
+ content: string;
276
+ created_at: string;
277
+ model: string | null;
278
+ tokens_in: number | null;
279
+ tokens_out: number | null;
280
+ }
281
+ interface ChatSessionDetailDTO extends ChatSessionDTO {
282
+ messages: ChatMessageDTO[];
283
+ }
284
+ interface ChatDelta {
285
+ kind: 'token' | 'done' | 'error';
286
+ text: string | null;
287
+ finish_reason: string | null;
288
+ model: string | null;
289
+ tokens_in: number | null;
290
+ tokens_out: number | null;
291
+ }
292
+
293
+ interface UsageWindowDTO {
294
+ window_type: string;
295
+ usage_percent: number;
296
+ resets_at: string | null;
297
+ tokens_used: number | null;
298
+ tokens_limit: number | null;
299
+ }
300
+ interface AccountHealthDTO {
301
+ backend_id: string;
302
+ kind: string;
303
+ windows: UsageWindowDTO[];
304
+ rate_limited_until: string | null;
305
+ rate_limit_reason: string | null;
306
+ last_used_at: string | null;
307
+ last_polled_at: string | null;
308
+ }
309
+ interface PickResultDTO {
310
+ backend_id: string;
311
+ kind: string;
312
+ isolation_dir: string;
313
+ retry_after: string | null;
314
+ }
315
+ interface FallbackChainEntryDTO {
316
+ backend_id: string;
317
+ priority: number;
318
+ }
319
+
173
320
  /**
174
321
  * This file was auto-generated by openapi-typescript.
175
322
  * Do not make direct changes to the file.
@@ -1121,6 +1268,7 @@ interface BackendDTO {
1121
1268
  display_name: string;
1122
1269
  status: string;
1123
1270
  config: Record<string, unknown>;
1271
+ config_dir: string | null;
1124
1272
  last_error: string | null;
1125
1273
  }
1126
1274
  interface DetectResultDTO {
@@ -1204,6 +1352,50 @@ declare class AiAccountsClient {
1204
1352
  cliproxyInstall(): Promise<CliproxyInstallResult>;
1205
1353
  cliproxyLoginBegin(backendKind: string, configDir?: string): Promise<CliproxyLoginBeginResponse>;
1206
1354
  cliproxyCallbackForward(callbackUrl: string): Promise<CliproxyCallbackForwardResponse>;
1355
+ cliproxyServerStart(port?: number, apiKey?: string): Promise<{
1356
+ status: string;
1357
+ port: number;
1358
+ pid: number | null;
1359
+ message: string;
1360
+ }>;
1361
+ cliproxyServerStop(): Promise<{
1362
+ status: string;
1363
+ message: string;
1364
+ }>;
1365
+ cliproxyServerStatus(): Promise<{
1366
+ installed: boolean;
1367
+ running: boolean;
1368
+ port: number;
1369
+ version: string | null;
1370
+ }>;
1371
+ createConversation(input: {
1372
+ backend_id: string;
1373
+ model: string;
1374
+ title?: string;
1375
+ }): Promise<ChatSessionDTO>;
1376
+ listConversations(backendId?: string): Promise<{
1377
+ items: ChatSessionDTO[];
1378
+ }>;
1379
+ getConversation(id: string): Promise<ChatSessionDetailDTO>;
1380
+ streamChat(sessionId: string, content: string): AsyncIterable<ChatDelta>;
1381
+ getSchedulerHealth(): Promise<{
1382
+ items: AccountHealthDTO[];
1383
+ }>;
1384
+ getAccountHealth(id: string): Promise<AccountHealthDTO>;
1385
+ schedulerPick(kind?: string): Promise<PickResultDTO | null>;
1386
+ getChain(): Promise<{
1387
+ entries: FallbackChainEntryDTO[];
1388
+ }>;
1389
+ setChain(entries: FallbackChainEntryDTO[]): Promise<void>;
1390
+ markRateLimited(backendId: string, seconds: number, reason: string): Promise<void>;
1391
+ sendChat(request: SendChatRequest, opts?: {
1392
+ signal?: AbortSignal;
1393
+ lastEventId?: number;
1394
+ }): AsyncIterable<SmartChatEvent>;
1395
+ createChatSession(backendId: string, model: string): Promise<ChatSessionDTO>;
1396
+ listChatSessions(backendId?: string): Promise<{
1397
+ items: ChatSessionDTO[];
1398
+ }>;
1207
1399
  private postAction;
1208
1400
  private onboardingAction;
1209
1401
  }
@@ -1231,7 +1423,7 @@ type AiAccountsEvent = {
1231
1423
  } | {
1232
1424
  type: 'login.prompt';
1233
1425
  sessionId: string;
1234
- promptKind: 'url' | 'text';
1426
+ promptKind: 'url' | 'text' | 'menu';
1235
1427
  } | {
1236
1428
  type: 'login.completed';
1237
1429
  sessionId: string;
@@ -1248,6 +1440,33 @@ type AiAccountsEvent = {
1248
1440
  };
1249
1441
  type AiAccountsEventHandler = (event: AiAccountsEvent) => void;
1250
1442
 
1443
+ interface PtySessionDTO {
1444
+ session_id: string;
1445
+ }
1446
+ interface PtySpawnRequest {
1447
+ backend_id: string;
1448
+ command: string[];
1449
+ cols?: number;
1450
+ rows?: number;
1451
+ }
1452
+
1453
+ interface PtySocketOptions {
1454
+ url: string;
1455
+ onData: (data: Uint8Array) => void;
1456
+ onClose?: () => void;
1457
+ onError?: (error: Event) => void;
1458
+ reconnectMs?: number;
1459
+ }
1460
+ declare class PtySocket {
1461
+ private ws;
1462
+ private readonly opts;
1463
+ private closed;
1464
+ constructor(opts: PtySocketOptions);
1465
+ private connect;
1466
+ send(data: Uint8Array): void;
1467
+ close(): void;
1468
+ }
1469
+
1251
1470
  type WizardState = 'idle' | 'picking_kind' | 'detecting' | 'entering_credential' | 'validating' | 'done' | 'error';
1252
1471
  interface AccountWizard {
1253
1472
  readonly state: WizardState;
@@ -1297,4 +1516,4 @@ declare function createOnboardingFlow(opts: CreateOnboardingFlowOptions): Onboar
1297
1516
 
1298
1517
  declare const version = "0.0.0";
1299
1518
 
1300
- export { type AccountWizard, type paths as AiAccountsApiPaths, AiAccountsClient, type AiAccountsEvent, type AiAccountsEventHandler, type ApiError, type BackendDTO, type BackendMetadata, type ChatDoneEvent, type ChatTokenEvent, type ChatToolCallEvent, type ClientOptions, type CliproxyCallbackForwardResponse, type CliproxyInstallResult, type CliproxyLoginBeginResponse, type CliproxyStatus, type CreateAccountWizardOptions, type CreateOnboardingFlowOptions, type DetectResultDTO, type DetectResultsDTO, type ErrorEvent, type InputSpec, type InstallCheck, type InstallResult, type LoginComplete, type LoginEvent, type LoginFailed, type LoginFlowKind, type LoginFlowSpec, type LoginResponseDTO, type OAuthDeviceLoginDTO, type OnboardingFlowMachine, type OnboardingMachineState, type OnboardingStateDTO, type PlanOption, type ProgressUpdate, type PromptAnswer, type PtyExitEvent, type PtyOutputEvent, type PtyResizeEvent, type SessionEndEvent, type SessionStartEvent, type StdoutChunk, type TextPrompt, type UrlPrompt, WIRE_PROTOCOL_VERSION, type WireEvent, type WizardState, createAccountWizard, createOnboardingFlow, version };
1519
+ export { type AccountHealthDTO, type AccountWizard, type paths as AiAccountsApiPaths, AiAccountsClient, type AiAccountsEvent, type AiAccountsEventHandler, type ApiError, type BackendDTO, type BackendMetadata, type BackendOption, type BackendResponse, type ChatDelta, type ChatDoneEvent, type ChatMessageDTO, type ChatMode, type ChatSessionDTO, type ChatSessionDetailDTO, type ChatTokenEvent, type ChatToolCallEvent, type ClientOptions, type CliproxyCallbackForwardResponse, type CliproxyInstallResult, type CliproxyLoginBeginResponse, type CliproxyStatus, type CreateAccountWizardOptions, type CreateOnboardingFlowOptions, type DetectResultDTO, type DetectResultsDTO, type ErrorEvent, type FallbackChainEntryDTO, type InputSpec, type InstallCheck, type InstallResult, type LoginComplete, type LoginEvent, type LoginFailed, type LoginFlowKind, type LoginFlowSpec, type LoginResponseDTO, type MenuOptionDTO, type MenuPrompt, type OAuthDeviceLoginDTO, type OnboardingFlowMachine, type OnboardingMachineState, type OnboardingStateDTO, type PickResultDTO, type PlanOption, type ProcessGroupType, type ProgressUpdate, type PromptAnswer, type PtyExitEvent, type PtyOutputEvent, type PtyResizeEvent, type PtySessionDTO, PtySocket, type PtySocketOptions, type PtySpawnRequest, type SendChatRequest, type SessionEndEvent, type SessionStartEvent, type SmartChatEvent, type StdoutChunk, type SynthesisState, type TextPrompt, type ToolCallDelta, type UrlPrompt, type UsageWindowDTO, WIRE_PROTOCOL_VERSION, type WireEvent, type WizardState, createAccountWizard, createOnboardingFlow, version };
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ async function* parseSseLoginEvents(response) {
7
7
  const reader = response.body.getReader();
8
8
  const decoder = new TextDecoder();
9
9
  let buffer = "";
10
+ let consecutiveParseErrors = 0;
10
11
  try {
11
12
  while (true) {
12
13
  const { value, done } = await reader.read();
@@ -21,8 +22,25 @@ async function* parseSseLoginEvents(response) {
21
22
  if (!dataLine) continue;
22
23
  const payload = dataLine.slice(6);
23
24
  try {
24
- yield JSON.parse(payload);
25
+ const parsed = JSON.parse(payload);
26
+ if (parsed && typeof parsed === "object" && typeof parsed.type === "string") {
27
+ consecutiveParseErrors = 0;
28
+ yield parsed;
29
+ } else {
30
+ console.warn("[ai-accounts] SSE frame missing type field:", payload.slice(0, 200));
31
+ consecutiveParseErrors++;
32
+ }
25
33
  } catch {
34
+ console.warn("[ai-accounts] malformed SSE frame:", payload.slice(0, 200));
35
+ consecutiveParseErrors++;
36
+ }
37
+ if (consecutiveParseErrors >= 3) {
38
+ yield {
39
+ type: "failed",
40
+ code: "stream_corrupt",
41
+ message: "Multiple malformed SSE frames received"
42
+ };
43
+ return;
26
44
  }
27
45
  }
28
46
  }
@@ -31,6 +49,58 @@ async function* parseSseLoginEvents(response) {
31
49
  }
32
50
  }
33
51
 
52
+ // src/client/chat-stream.ts
53
+ async function* parseSseChatEvents(response) {
54
+ const reader = response.body.getReader();
55
+ const decoder = new TextDecoder();
56
+ let buf = "";
57
+ while (true) {
58
+ const { done, value } = await reader.read();
59
+ if (done) break;
60
+ buf += decoder.decode(value, { stream: true });
61
+ const parts = buf.split("\n\n");
62
+ buf = parts.pop() ?? "";
63
+ for (const part of parts) {
64
+ for (const line of part.split("\n")) {
65
+ if (line.startsWith("data: ")) {
66
+ const payload = line.slice(6).trim();
67
+ if (!payload) continue;
68
+ try {
69
+ yield JSON.parse(payload);
70
+ } catch {
71
+ console.warn("[ai-accounts] malformed SSE chat frame dropped:", payload.slice(0, 200));
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ // src/client/smart-chat-stream.ts
80
+ async function* parseSseSmartChatEvents(response) {
81
+ const reader = response.body.getReader();
82
+ const decoder = new TextDecoder();
83
+ let buf = "";
84
+ while (true) {
85
+ const { done, value } = await reader.read();
86
+ if (done) break;
87
+ buf += decoder.decode(value, { stream: true });
88
+ const parts = buf.split("\n\n");
89
+ buf = parts.pop() ?? "";
90
+ for (const part of parts) {
91
+ for (const line of part.split("\n")) {
92
+ if (line.startsWith("data: ")) {
93
+ try {
94
+ yield JSON.parse(line.slice(6).trim());
95
+ } catch {
96
+ console.warn("[ai-accounts] malformed smart chat SSE frame");
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+
34
104
  // src/client/index.ts
35
105
  async function toError(r) {
36
106
  let code = "http_error";
@@ -266,6 +336,126 @@ var AiAccountsClient = class {
266
336
  if (!r.ok) throw await toError(r);
267
337
  return await r.json();
268
338
  }
339
+ // --- CLIProxyAPI Server Lifecycle ---
340
+ async cliproxyServerStart(port = 8317, apiKey = "not-needed") {
341
+ const r = await this._fetch(`${this.baseUrl}/api/v1/cliproxy/server/start`, {
342
+ method: "POST",
343
+ headers: this.headers(),
344
+ body: JSON.stringify({ port, api_key: apiKey })
345
+ });
346
+ if (!r.ok) throw await toError(r);
347
+ return await r.json();
348
+ }
349
+ async cliproxyServerStop() {
350
+ const r = await this._fetch(`${this.baseUrl}/api/v1/cliproxy/server/stop`, {
351
+ method: "POST",
352
+ headers: this.headers()
353
+ });
354
+ if (!r.ok) throw await toError(r);
355
+ return await r.json();
356
+ }
357
+ async cliproxyServerStatus() {
358
+ const r = await this._fetch(`${this.baseUrl}/api/v1/cliproxy/server/status`, {
359
+ headers: this.headers()
360
+ });
361
+ if (!r.ok) throw await toError(r);
362
+ return await r.json();
363
+ }
364
+ // --- Conversations / Chat ---
365
+ async createConversation(input) {
366
+ const r = await this._fetch(`${this.baseUrl}/api/v1/conversations/`, {
367
+ method: "POST",
368
+ headers: this.headers(),
369
+ body: JSON.stringify(input)
370
+ });
371
+ if (!r.ok) throw await toError(r);
372
+ return await r.json();
373
+ }
374
+ async listConversations(backendId) {
375
+ const qs = backendId ? `?backend_id=${encodeURIComponent(backendId)}` : "";
376
+ const r = await this._fetch(`${this.baseUrl}/api/v1/conversations/${qs}`, { headers: this.headers() });
377
+ if (!r.ok) throw await toError(r);
378
+ return await r.json();
379
+ }
380
+ async getConversation(id) {
381
+ const r = await this._fetch(`${this.baseUrl}/api/v1/conversations/${encodeURIComponent(id)}`, { headers: this.headers() });
382
+ if (!r.ok) throw await toError(r);
383
+ return await r.json();
384
+ }
385
+ async *streamChat(sessionId, content) {
386
+ const url = `${this.baseUrl}/api/v1/conversations/${encodeURIComponent(sessionId)}/messages`;
387
+ const headers = { ...this.headers(), Accept: "text/event-stream" };
388
+ const r = await this._fetch(url, { method: "POST", headers, body: JSON.stringify({ content }) });
389
+ if (!r.ok) throw await toError(r);
390
+ yield* parseSseChatEvents(r);
391
+ }
392
+ // --- Scheduler ---
393
+ async getSchedulerHealth() {
394
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/health`, { headers: this.headers() });
395
+ if (!r.ok) throw await toError(r);
396
+ return await r.json();
397
+ }
398
+ async getAccountHealth(id) {
399
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/health/${encodeURIComponent(id)}`, { headers: this.headers() });
400
+ if (!r.ok) throw await toError(r);
401
+ return await r.json();
402
+ }
403
+ async schedulerPick(kind) {
404
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/pick`, {
405
+ method: "POST",
406
+ headers: this.headers(),
407
+ body: JSON.stringify(kind ? { kind } : {})
408
+ });
409
+ if (r.status === 204) return null;
410
+ if (!r.ok) throw await toError(r);
411
+ return await r.json();
412
+ }
413
+ async getChain() {
414
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/chain`, { headers: this.headers() });
415
+ if (!r.ok) throw await toError(r);
416
+ return await r.json();
417
+ }
418
+ async setChain(entries) {
419
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/chain`, {
420
+ method: "PUT",
421
+ headers: this.headers(),
422
+ body: JSON.stringify({ entries })
423
+ });
424
+ if (!r.ok) throw await toError(r);
425
+ }
426
+ async markRateLimited(backendId, seconds, reason) {
427
+ const r = await this._fetch(`${this.baseUrl}/api/v1/scheduler/mark-limited`, {
428
+ method: "POST",
429
+ headers: this.headers(),
430
+ body: JSON.stringify({ backend_id: backendId, cooldown_seconds: seconds, reason })
431
+ });
432
+ if (!r.ok) throw await toError(r);
433
+ }
434
+ // --- Smart Chat ---
435
+ async *sendChat(request, opts = {}) {
436
+ const url = `${this.baseUrl}/api/v1/chat/send`;
437
+ const headers = {
438
+ ...this.headers(),
439
+ Accept: "text/event-stream"
440
+ };
441
+ if (opts.lastEventId && opts.lastEventId > 0) {
442
+ headers["Last-Event-ID"] = String(opts.lastEventId);
443
+ }
444
+ const r = await this._fetch(url, {
445
+ method: "POST",
446
+ headers,
447
+ body: JSON.stringify(request),
448
+ ...opts.signal ? { signal: opts.signal } : {}
449
+ });
450
+ if (!r.ok) throw await toError(r);
451
+ yield* parseSseSmartChatEvents(r);
452
+ }
453
+ async createChatSession(backendId, model) {
454
+ return this.createConversation({ backend_id: backendId, model });
455
+ }
456
+ async listChatSessions(backendId) {
457
+ return this.listConversations(backendId);
458
+ }
269
459
  async postAction(id, action, body) {
270
460
  const r = await this._fetch(
271
461
  `${this.baseUrl}/api/v1/backends/${encodeURIComponent(id)}/${action}`,
@@ -292,6 +482,46 @@ var AiAccountsClient = class {
292
482
  }
293
483
  };
294
484
 
485
+ // src/client/pty-socket.ts
486
+ var PtySocket = class {
487
+ ws = null;
488
+ opts;
489
+ closed = false;
490
+ constructor(opts) {
491
+ this.opts = opts;
492
+ this.connect();
493
+ }
494
+ connect() {
495
+ if (this.closed) return;
496
+ this.ws = new WebSocket(this.opts.url);
497
+ this.ws.binaryType = "arraybuffer";
498
+ this.ws.onmessage = (event) => {
499
+ if (event.data instanceof ArrayBuffer) {
500
+ this.opts.onData(new Uint8Array(event.data));
501
+ }
502
+ };
503
+ this.ws.onclose = () => {
504
+ if (!this.closed && this.opts.reconnectMs) {
505
+ setTimeout(() => this.connect(), this.opts.reconnectMs);
506
+ }
507
+ this.opts.onClose?.();
508
+ };
509
+ this.ws.onerror = (e) => {
510
+ this.opts.onError?.(e);
511
+ };
512
+ }
513
+ send(data) {
514
+ if (this.ws?.readyState === WebSocket.OPEN) {
515
+ this.ws.send(data);
516
+ }
517
+ }
518
+ close() {
519
+ this.closed = true;
520
+ this.ws?.close();
521
+ this.ws = null;
522
+ }
523
+ };
524
+
295
525
  // src/machines/accountWizard.ts
296
526
  function createAccountWizard(opts) {
297
527
  const listeners = /* @__PURE__ */ new Set();
@@ -591,6 +821,7 @@ function createOnboardingFlow(opts) {
591
821
  var version = "0.0.0";
592
822
  export {
593
823
  AiAccountsClient,
824
+ PtySocket,
594
825
  WIRE_PROTOCOL_VERSION,
595
826
  createAccountWizard,
596
827
  createOnboardingFlow,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-accounts/ts-core",
3
- "version": "0.3.0-alpha.1",
3
+ "version": "0.3.0",
4
4
  "description": "Framework-agnostic TypeScript client and protocol for ai-accounts",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -24,4 +24,4 @@
24
24
  "lint": "eslint src",
25
25
  "typecheck": "tsc --noEmit"
26
26
  }
27
- }
27
+ }
package/LICENSE DELETED
@@ -1,202 +0,0 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright [yyyy] [name of copyright owner]
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.