@lifesi/genesis 0.0.0-stage → 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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,545 @@
1
+ import { GenesisClient, type GenesisOptions } from './client.js';
2
+ import type { OperationInput as In } from './types.js';
3
+ import type { components } from './generated/schema.js';
4
+ type S = components['schemas'];
5
+ export type ChatMessage = {
6
+ role: 'system' | 'user' | 'assistant' | 'tool';
7
+ content: string;
8
+ } & Record<string, unknown>;
9
+ /**
10
+ * The Genesis SDK: one client, every service.
11
+ * const genesis = new Genesis(); // GENESIS_API_KEY or `genesis login`
12
+ * await genesis.hives.projects.list();
13
+ * await genesis.foundry.chat({ model: 'x', messages: [{ role: 'user', content: 'hi' }] });
14
+ */
15
+ export declare class Genesis extends GenesisClient {
16
+ constructor(opts?: GenesisOptions);
17
+ /** Generic escape hatch: genesis.call('hives_list_projects', {...}) */
18
+ call: <K extends import("./index.js").OperationId>(operationId: K, input?: In<K>, init?: {
19
+ signal?: AbortSignal;
20
+ headers?: Record<string, string>;
21
+ }) => Promise<import("./types.js").OperationOutput<K>>;
22
+ readonly dials: {
23
+ numbers: {
24
+ list: (scope: import("./dials.js").DialsScope) => Promise<{
25
+ ok: boolean;
26
+ numbers: components["schemas"]["Dials.Number"][];
27
+ }>;
28
+ search: (scope: import("./dials.js").DialsScope, query?: {
29
+ areaCode?: string;
30
+ limit?: number;
31
+ }) => Promise<{
32
+ [key: string]: unknown;
33
+ }>;
34
+ provision: (body: In<"dials_provisionNumber">["body"]) => Promise<{
35
+ [key: string]: unknown;
36
+ }>;
37
+ assign: (body: In<"dials_assignNumber">["body"]) => Promise<{
38
+ [key: string]: unknown;
39
+ }>;
40
+ release: (body: In<"dials_releaseNumber">["body"]) => Promise<{
41
+ [key: string]: unknown;
42
+ }>;
43
+ registerEmergencyAddress: (body: import("./dials.js").DialsEmergencyAddress) => Promise<{
44
+ ok: boolean;
45
+ number: components["schemas"]["Dials.Number"];
46
+ address: components["schemas"]["Dials.EmergencyAddress"];
47
+ auditId: string;
48
+ next: string;
49
+ }>;
50
+ };
51
+ calls: {
52
+ list: (scope: import("./dials.js").DialsScope) => Promise<{
53
+ ok: boolean;
54
+ calls: components["schemas"]["Dials.Call"][];
55
+ }>;
56
+ validate: (body: import("./dials.js").DialsOutboundCall) => Promise<{
57
+ [key: string]: unknown;
58
+ }>;
59
+ create: (body: import("./dials.js").DialsOutboundCall) => Promise<{
60
+ [key: string]: unknown;
61
+ }>;
62
+ };
63
+ };
64
+ readonly henry: {
65
+ config: () => Promise<{
66
+ credential_configured: boolean;
67
+ models: {
68
+ id: string;
69
+ }[];
70
+ }>;
71
+ credential: (api_key: string) => Promise<{
72
+ credential_configured: boolean;
73
+ models: {
74
+ id: string;
75
+ }[];
76
+ }>;
77
+ runs: {
78
+ list: (page_token?: string) => Promise<{
79
+ runs: components["schemas"]["Henry.Run"][];
80
+ next_page_token?: string | null;
81
+ }>;
82
+ create: (body: NonNullable<In<"henry_createRun">["body"]>) => Promise<{
83
+ id: string;
84
+ task: string;
85
+ model: string;
86
+ status: "ready" | "running" | "acting" | "paused" | "awaiting_approval" | "completed" | "cancelled" | "failed" | "waiting_input";
87
+ created_at: string;
88
+ updated_at: string;
89
+ activity: {
90
+ id: string;
91
+ at: string;
92
+ type: string;
93
+ detail: string;
94
+ }[];
95
+ approvals: {
96
+ id: string;
97
+ action: string;
98
+ url: string;
99
+ status: string;
100
+ requested_at: string;
101
+ }[];
102
+ phases: {
103
+ id?: string;
104
+ code?: number;
105
+ receipt?: Record<string, never>;
106
+ usage?: Record<string, never> | null;
107
+ }[];
108
+ messages: ({
109
+ role: string;
110
+ content?: string | null;
111
+ } & {
112
+ [key: string]: unknown;
113
+ })[];
114
+ }>;
115
+ get: (run_id: string) => Promise<{
116
+ id: string;
117
+ task: string;
118
+ model: string;
119
+ status: "ready" | "running" | "acting" | "paused" | "awaiting_approval" | "completed" | "cancelled" | "failed" | "waiting_input";
120
+ created_at: string;
121
+ updated_at: string;
122
+ activity: {
123
+ id: string;
124
+ at: string;
125
+ type: string;
126
+ detail: string;
127
+ }[];
128
+ approvals: {
129
+ id: string;
130
+ action: string;
131
+ url: string;
132
+ status: string;
133
+ requested_at: string;
134
+ }[];
135
+ phases: {
136
+ id?: string;
137
+ code?: number;
138
+ receipt?: Record<string, never>;
139
+ usage?: Record<string, never> | null;
140
+ }[];
141
+ messages: ({
142
+ role: string;
143
+ content?: string | null;
144
+ } & {
145
+ [key: string]: unknown;
146
+ })[];
147
+ }>;
148
+ command: (run_id: string, action: "pause" | "resume" | "cancel" | "input", text?: string) => Promise<{
149
+ id: string;
150
+ task: string;
151
+ model: string;
152
+ status: "ready" | "running" | "acting" | "paused" | "awaiting_approval" | "completed" | "cancelled" | "failed" | "waiting_input";
153
+ created_at: string;
154
+ updated_at: string;
155
+ activity: {
156
+ id: string;
157
+ at: string;
158
+ type: string;
159
+ detail: string;
160
+ }[];
161
+ approvals: {
162
+ id: string;
163
+ action: string;
164
+ url: string;
165
+ status: string;
166
+ requested_at: string;
167
+ }[];
168
+ phases: {
169
+ id?: string;
170
+ code?: number;
171
+ receipt?: Record<string, never>;
172
+ usage?: Record<string, never> | null;
173
+ }[];
174
+ messages: ({
175
+ role: string;
176
+ content?: string | null;
177
+ } & {
178
+ [key: string]: unknown;
179
+ })[];
180
+ }>;
181
+ approval: (run_id: string, approval_id: string, decision: "approve" | "reject") => Promise<{
182
+ id: string;
183
+ task: string;
184
+ model: string;
185
+ status: "ready" | "running" | "acting" | "paused" | "awaiting_approval" | "completed" | "cancelled" | "failed" | "waiting_input";
186
+ created_at: string;
187
+ updated_at: string;
188
+ activity: {
189
+ id: string;
190
+ at: string;
191
+ type: string;
192
+ detail: string;
193
+ }[];
194
+ approvals: {
195
+ id: string;
196
+ action: string;
197
+ url: string;
198
+ status: string;
199
+ requested_at: string;
200
+ }[];
201
+ phases: {
202
+ id?: string;
203
+ code?: number;
204
+ receipt?: Record<string, never>;
205
+ usage?: Record<string, never> | null;
206
+ }[];
207
+ messages: ({
208
+ role: string;
209
+ content?: string | null;
210
+ } & {
211
+ [key: string]: unknown;
212
+ })[];
213
+ }>;
214
+ };
215
+ };
216
+ readonly fleets: {
217
+ connection: {
218
+ get: () => Promise<{
219
+ connected: boolean;
220
+ model: string;
221
+ updated_at?: number;
222
+ }>;
223
+ set: (api_key: string) => Promise<{
224
+ connected: boolean;
225
+ model: string;
226
+ updated_at?: number;
227
+ }>;
228
+ delete: () => Promise<{
229
+ connected: boolean;
230
+ model: string;
231
+ updated_at?: number;
232
+ }>;
233
+ };
234
+ tasks: {
235
+ list: (query?: In<"fleets_listTasks">) => Promise<{
236
+ tasks: components["schemas"]["Fleets.Summary"][];
237
+ next_before: string | null;
238
+ }>;
239
+ submit: (body: {
240
+ input: string;
241
+ timeout_seconds?: number;
242
+ idempotency_key?: string;
243
+ }) => Promise<{
244
+ task_id: string;
245
+ status: components["schemas"]["Fleets.Status"];
246
+ submitted_at: string;
247
+ started_at?: string | null;
248
+ completed_at?: string | null;
249
+ }>;
250
+ get: (task_id: string) => Promise<{
251
+ task_id: string;
252
+ status: components["schemas"]["Fleets.Status"];
253
+ submitted_at: string;
254
+ started_at?: string | null;
255
+ completed_at?: string | null;
256
+ }>;
257
+ cancel: (task_id: string) => Promise<{
258
+ task_id: string;
259
+ status: components["schemas"]["Fleets.Status"];
260
+ }>;
261
+ receipt: (task_id: string) => Promise<{
262
+ task_id: string;
263
+ status: components["schemas"]["Fleets.Status"];
264
+ submitted_at: string;
265
+ started_at?: string | null;
266
+ completed_at?: string | null;
267
+ } & {
268
+ tenant: string;
269
+ principal: string;
270
+ idempotency_key: string | null;
271
+ request_fingerprint: string;
272
+ timeout_seconds: number;
273
+ exit_code: number | null;
274
+ exit_signal: number | null;
275
+ cleanup_result: {
276
+ process_group_gone?: boolean;
277
+ workdir_removed?: boolean;
278
+ sigkill_sent?: boolean;
279
+ } | null;
280
+ henry_receipt?: {
281
+ [key: string]: unknown;
282
+ };
283
+ }>;
284
+ };
285
+ };
286
+ readonly runner: Readonly<{
287
+ catalog: (opts?: import("./runner.js").RunnerRequestOptions) => Promise<{
288
+ workspaces: {
289
+ key: components["schemas"]["Runner.SafeOpaqueRef"];
290
+ label: string;
291
+ }[];
292
+ routes: {
293
+ routeId: components["schemas"]["Runner.SafeOpaqueRef"];
294
+ kind: "external-harness" | "internal-model";
295
+ name: string;
296
+ via: string;
297
+ state: "synthetic" | "bound" | "unbound";
298
+ default: boolean;
299
+ }[];
300
+ }>;
301
+ jobs: Readonly<{
302
+ list: (opts?: import("./runner.js").RunnerRequestOptions) => Promise<{
303
+ jobs: components["schemas"]["Runner.Snapshot"][];
304
+ }>;
305
+ start: (input: import("./runner.js").RunnerStartInput, opts?: import("./runner.js").RunnerRequestOptions) => Promise<{
306
+ jobId: components["schemas"]["Runner.SafeOpaqueRef"];
307
+ snapshot: components["schemas"]["Runner.Snapshot"];
308
+ }>;
309
+ get: (jobId: string, opts?: import("./runner.js").RunnerRequestOptions) => Promise<{
310
+ snapshot: components["schemas"]["Runner.Snapshot"];
311
+ }>;
312
+ events: (jobId: string, afterSeq?: number, opts?: import("./runner.js").RunnerRequestOptions) => Promise<{
313
+ events: components["schemas"]["Runner.Event"][];
314
+ nextAfterSeq: number;
315
+ hasMore: boolean;
316
+ }>;
317
+ result: (jobId: string, opts?: import("./runner.js").RunnerRequestOptions) => Promise<{
318
+ result: components["schemas"]["Runner.ProviderResult"];
319
+ }>;
320
+ cancel: (jobId: string, opts?: import("./runner.js").RunnerRequestOptions) => Promise<{
321
+ snapshot: components["schemas"]["Runner.Snapshot"];
322
+ }>;
323
+ }>;
324
+ }>;
325
+ readonly beacons: {
326
+ devices: {
327
+ list: () => Promise<{
328
+ data?: components["schemas"]["Beacons.BridgeDevice"][];
329
+ }>;
330
+ update: (id: string, body: In<"beacons_updateBridgeDevice">["body"]) => Promise<{
331
+ id: string;
332
+ org_id: string;
333
+ name: string;
334
+ nicknames: string[];
335
+ created_at: string;
336
+ status: string;
337
+ }>;
338
+ revoke: (id: string) => Promise<import("./types.js").OperationOutput<"beacons_revokeBridgeDevice"> | undefined>;
339
+ };
340
+ };
341
+ readonly foundry: {
342
+ models: {
343
+ list: () => Promise<{
344
+ [key: string]: unknown;
345
+ }>;
346
+ };
347
+ /** OpenAI-compatible chat completion (non-streaming). */
348
+ chat: (body: {
349
+ model: string;
350
+ messages: ChatMessage[];
351
+ } & Record<string, unknown>) => Promise<{
352
+ id: string;
353
+ model?: string;
354
+ choices: {
355
+ [key: string]: unknown;
356
+ }[];
357
+ usage?: components["schemas"]["Foundry.Usage"];
358
+ foundry?: components["schemas"]["Foundry.RequestMetadata"];
359
+ } & {
360
+ [key: string]: unknown;
361
+ }>;
362
+ /** Streaming chat: yields content deltas parsed from the SSE stream. */
363
+ chatStream: (body: {
364
+ model: string;
365
+ messages: ChatMessage[];
366
+ } & Record<string, unknown>) => AsyncGenerator<string, any, any>;
367
+ embeddings: (body: In<"foundry_createEmbedding">["body"]) => Promise<{
368
+ object?: string;
369
+ model?: string;
370
+ data: {
371
+ [key: string]: unknown;
372
+ }[];
373
+ usage?: components["schemas"]["Foundry.Usage"];
374
+ } & {
375
+ [key: string]: unknown;
376
+ }>;
377
+ registry: {
378
+ models: (q?: In<"foundry_listRegistryModels">) => Promise<{
379
+ [key: string]: unknown;
380
+ }>;
381
+ model: (canonical_model_id: string) => Promise<{
382
+ [key: string]: unknown;
383
+ }>;
384
+ };
385
+ };
386
+ readonly hives: {
387
+ projects: {
388
+ list: (q?: In<"hives_list_projects">) => Promise<{
389
+ data: (Record<string, never> & {
390
+ active_instances: number;
391
+ current_version?: number | null;
392
+ requests_24h: number;
393
+ total_deployments: number;
394
+ })[];
395
+ pagination: components["schemas"]["Hives.PaginationMeta"];
396
+ }>;
397
+ get: (project_id: string) => Promise<Record<string, never> & {
398
+ active_instances: number;
399
+ current_version?: number | null;
400
+ requests_24h: number;
401
+ total_deployments: number;
402
+ }>;
403
+ create: (body: In<"hives_create_project">["body"]) => Promise<Record<string, never> & {
404
+ active_instances: number;
405
+ current_version?: number | null;
406
+ requests_24h: number;
407
+ total_deployments: number;
408
+ }>;
409
+ delete: (project_id: string) => Promise<{
410
+ id: string;
411
+ message: string;
412
+ success: boolean;
413
+ }>;
414
+ };
415
+ deployments: {
416
+ list: (project_id: string) => Promise<{
417
+ data: (Record<string, never> & {
418
+ logs_url?: string | null;
419
+ url?: string | null;
420
+ })[];
421
+ pagination: components["schemas"]["Hives.PaginationMeta"];
422
+ }>;
423
+ create: (project_id: string, body: In<"hives_create_deployment">["body"]) => Promise<Record<string, never> & {
424
+ logs_url?: string | null;
425
+ url?: string | null;
426
+ }>;
427
+ rollback: (project_id: string, body?: unknown) => Promise<Record<string, never> & {
428
+ logs_url?: string | null;
429
+ url?: string | null;
430
+ }>;
431
+ };
432
+ functions: {
433
+ list: (project_id: string) => Promise<Record<string, never>>;
434
+ invoke: (project_id: string, function_id: string, body?: unknown) => Promise<{
435
+ billed_duration_ms: number;
436
+ body: unknown;
437
+ duration_ms: number;
438
+ headers: {
439
+ [key: string]: string;
440
+ };
441
+ memory_used_mb: number;
442
+ request_id: string;
443
+ status: number;
444
+ }>;
445
+ };
446
+ regions: {
447
+ list: () => Promise<{
448
+ regions: components["schemas"]["Hives.Region"][];
449
+ }>;
450
+ };
451
+ };
452
+ readonly relays: {
453
+ zones: {
454
+ list: (q?: In<"relays_listZones">) => Promise<{
455
+ zones?: components["schemas"]["Relays.Zone"][];
456
+ meta?: components["schemas"]["Relays.Meta"];
457
+ }>;
458
+ get: (zone: string) => Promise<{
459
+ id?: number;
460
+ name?: string;
461
+ type?: "NATIVE" | "MASTER" | "SLAVE";
462
+ record_count?: number;
463
+ dnssec_enabled?: boolean;
464
+ status?: string;
465
+ serial?: number;
466
+ nameservers?: string[];
467
+ soa?: {
468
+ [key: string]: unknown;
469
+ };
470
+ created_at?: string;
471
+ updated_at?: string;
472
+ }>;
473
+ create: (body: S["Relays.CreateZone"]) => Promise<{
474
+ id?: number;
475
+ name?: string;
476
+ type?: "NATIVE" | "MASTER" | "SLAVE";
477
+ record_count?: number;
478
+ dnssec_enabled?: boolean;
479
+ status?: string;
480
+ serial?: number;
481
+ nameservers?: string[];
482
+ soa?: {
483
+ [key: string]: unknown;
484
+ };
485
+ created_at?: string;
486
+ updated_at?: string;
487
+ }>;
488
+ delete: (zone: string) => Promise<{
489
+ success?: boolean;
490
+ message?: string;
491
+ }>;
492
+ };
493
+ records: {
494
+ list: (zone: string, q?: Omit<In<"relays_listRecords">, "zone">) => Promise<{
495
+ zone?: string;
496
+ records?: components["schemas"]["Relays.Record"][];
497
+ meta?: components["schemas"]["Relays.Meta"];
498
+ }>;
499
+ create: (zone: string, body: S["Relays.RecordInput"]) => Promise<{
500
+ [key: string]: unknown;
501
+ }>;
502
+ update: (zone: string, recordId: number, body: S["Relays.RecordPatch"]) => Promise<{
503
+ name: string;
504
+ type: string;
505
+ content: string;
506
+ ttl?: number;
507
+ priority?: number;
508
+ disabled?: boolean;
509
+ comment?: string;
510
+ tags?: string[];
511
+ } & {
512
+ id?: number;
513
+ zone?: string;
514
+ created_at?: string;
515
+ updated_at?: string;
516
+ }>;
517
+ delete: (zone: string, recordId: number) => Promise<{
518
+ success?: boolean;
519
+ message?: string;
520
+ }>;
521
+ };
522
+ };
523
+ /** LifeID org API keys (WorkOS). custody 'blinds' = key goes straight to Blinds, never shown. */
524
+ readonly keys: {
525
+ list: (org_id: string) => Promise<{
526
+ object: "list";
527
+ data: components["schemas"]["Iam.ApiKeyMetadata"][];
528
+ }>;
529
+ create: (org_id: string, body: S["Iam.CreateApiKeyRequest"]) => Promise<{
530
+ id: string;
531
+ name: string;
532
+ obfuscated_value: string;
533
+ value?: string | null;
534
+ blinds_credential_ref?: string | null;
535
+ scopes: string[];
536
+ expires_at?: string | null;
537
+ created_at: string;
538
+ }>;
539
+ revoke: (key_id: string) => Promise<void>;
540
+ };
541
+ /** Who is this credential? (LifeID verify: org, principal, scopes, kind) */
542
+ whoami(): Promise<S['Iam.VerifiedPrincipal']>;
543
+ private streamChat;
544
+ }
545
+ export {};
@@ -0,0 +1,111 @@
1
+ import { beaconsModule } from './beacons.js';
2
+ import { dialsModule } from './dials.js';
3
+ import { GenesisClient } from './client.js';
4
+ import { henryModule } from './henry.js';
5
+ import { fleetsModule } from './fleets.js';
6
+ import { runnerModule } from './runner.js';
7
+ /**
8
+ * The Genesis SDK: one client, every service.
9
+ * const genesis = new Genesis(); // GENESIS_API_KEY or `genesis login`
10
+ * await genesis.hives.projects.list();
11
+ * await genesis.foundry.chat({ model: 'x', messages: [{ role: 'user', content: 'hi' }] });
12
+ */
13
+ export class Genesis extends GenesisClient {
14
+ constructor(opts = {}) { super(opts); }
15
+ /** Generic escape hatch: genesis.call('hives_list_projects', {...}) */
16
+ call = this.request.bind(this);
17
+ dials = dialsModule(this);
18
+ henry = henryModule(this);
19
+ fleets = fleetsModule(this);
20
+ runner = runnerModule(this);
21
+ beacons = beaconsModule(this);
22
+ foundry = {
23
+ models: {
24
+ list: () => this.request('foundry_listModels'),
25
+ },
26
+ /** OpenAI-compatible chat completion (non-streaming). */
27
+ chat: (body) => this.request('foundry_createChatCompletion', { body: { ...body, stream: false } }),
28
+ /** Streaming chat: yields content deltas parsed from the SSE stream. */
29
+ chatStream: (body) => this.streamChat(body),
30
+ embeddings: (body) => this.request('foundry_createEmbedding', { body }),
31
+ registry: {
32
+ models: (q = {}) => this.request('foundry_listRegistryModels', q),
33
+ model: (canonical_model_id) => this.request('foundry_getRegistryModel', { canonical_model_id }),
34
+ },
35
+ };
36
+ hives = {
37
+ projects: {
38
+ list: (q = {}) => this.request('hives_list_projects', q),
39
+ get: (project_id) => this.request('hives_get_project', { project_id }),
40
+ create: (body) => this.request('hives_create_project', { body }),
41
+ delete: (project_id) => this.request('hives_delete_project', { project_id }),
42
+ },
43
+ deployments: {
44
+ list: (project_id) => this.request('hives_list_deployments', { project_id }),
45
+ create: (project_id, body) => this.request('hives_create_deployment', { project_id, body }),
46
+ rollback: (project_id, body) => this.request('hives_rollback_deployment', { project_id, body }),
47
+ },
48
+ functions: {
49
+ list: (project_id) => this.request('hives_list_functions', { project_id }),
50
+ invoke: (project_id, function_id, body) => this.request('hives_invoke_function', { project_id, function_id, body }),
51
+ },
52
+ regions: { list: () => this.request('hives_list_regions') },
53
+ };
54
+ relays = {
55
+ zones: {
56
+ list: (q = {}) => this.request('relays_listZones', q),
57
+ get: (zone) => this.request('relays_getZone', { zone }),
58
+ create: (body) => this.request('relays_createZone', { body }),
59
+ delete: (zone) => this.request('relays_deleteZone', { zone }),
60
+ },
61
+ records: {
62
+ list: (zone, q = {}) => this.request('relays_listRecords', { zone, ...q }),
63
+ create: (zone, body) => this.request('relays_createRecord', { zone, body }),
64
+ update: (zone, recordId, body) => this.request('relays_updateRecord', { zone, recordId, body }),
65
+ delete: (zone, recordId) => this.request('relays_deleteRecord', { zone, recordId }),
66
+ },
67
+ };
68
+ /** LifeID org API keys (WorkOS). custody 'blinds' = key goes straight to Blinds, never shown. */
69
+ keys = {
70
+ list: (org_id) => this.request('iam_listOrgApiKeys', { org_id }),
71
+ create: (org_id, body) => this.request('iam_createOrgApiKey', { org_id, body }),
72
+ revoke: (key_id) => this.request('iam_revokeApiKey', { key_id }),
73
+ };
74
+ /** Who is this credential? (LifeID verify: org, principal, scopes, kind) */
75
+ async whoami() {
76
+ const credential_value = await this.credential();
77
+ if (!credential_value)
78
+ throw new Error('No Genesis credential. Run `genesis login`, or set GENESIS_API_KEY.');
79
+ return this.request('iam_verifyCredential', { body: { credential_value } });
80
+ }
81
+ async *streamChat(body) {
82
+ const res = await this.raw('foundry_createChatCompletion', { body: { ...body, stream: true } }, { headers: { accept: 'text/event-stream' } });
83
+ if (!res.body)
84
+ return;
85
+ const reader = res.body.getReader();
86
+ const dec = new TextDecoder();
87
+ let buf = '';
88
+ for (;;) {
89
+ const { done, value } = await reader.read();
90
+ if (done)
91
+ break;
92
+ buf += dec.decode(value, { stream: true });
93
+ let i;
94
+ while ((i = buf.indexOf('\n')) >= 0) {
95
+ const line = buf.slice(0, i).trim();
96
+ buf = buf.slice(i + 1);
97
+ if (!line.startsWith('data:'))
98
+ continue;
99
+ const data = line.slice(5).trim();
100
+ if (data === '[DONE]')
101
+ return;
102
+ try {
103
+ const d = JSON.parse(data).choices?.[0]?.delta?.content;
104
+ if (d)
105
+ yield d;
106
+ }
107
+ catch { /* ignore keepalives */ }
108
+ }
109
+ }
110
+ }
111
+ }