theokit 0.29.0 → 0.30.1
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/LICENSE +201 -0
- package/dist/{actions-virtual-module-JB5ZTS5U.js → actions-virtual-module-PBLLMJY4.js} +3 -3
- package/dist/actions-virtual-module-Z2IXNF72.js +0 -0
- package/dist/add-W6FNTAFS.js +0 -0
- package/dist/agent-I5QEOMCN.js +0 -0
- package/dist/agents-typed-client-5DCGDWFZ.js +0 -0
- package/dist/{app-typed-client-VMSRQGKL.js → app-typed-client-EXHUWPOI.js} +3 -3
- package/dist/app-typed-client-YCQC3MZ7.js +0 -0
- package/dist/aws-lambda-7GSCNLPY.js +0 -0
- package/dist/body-parser-web-FV5HWCY3.js +0 -0
- package/dist/broadcast-LUMOJIJT.js +0 -0
- package/dist/build-V2QEBE7I.js +0 -0
- package/dist/build-request-body-preview-QMWD2IXK.js +0 -0
- package/dist/bun-KP2KES6S.js +0 -0
- package/dist/check-PD2FTKMM.js +0 -0
- package/dist/chunk-2CVV6CNN.js +0 -0
- package/dist/chunk-45C3WUQ7.js +0 -0
- package/dist/chunk-5ODOE6EF.js +0 -0
- package/dist/chunk-AFVTEAES.js +0 -0
- package/dist/{chunk-R4VVXLKZ.js → chunk-EHUT4FMG.js} +10 -10
- package/dist/chunk-FOZIR3TG.js +0 -0
- package/dist/chunk-FRUEDJFX.js +0 -0
- package/dist/chunk-GDN3PXFH.js +0 -0
- package/dist/chunk-GEQJAFSV.js +0 -0
- package/dist/chunk-GSO77FSM.js +0 -0
- package/dist/chunk-HGZL5EOI.js +0 -0
- package/dist/chunk-HNBWZKIQ.js +0 -0
- package/dist/chunk-IEES3CHD.js +0 -0
- package/dist/chunk-JAIKGP3Q.js +0 -0
- package/dist/chunk-KXA37ONC.js +0 -0
- package/dist/chunk-M6NMS5LR.js +0 -0
- package/dist/chunk-P37RZRFV.js +0 -0
- package/dist/chunk-RBRDTYOO.js +470 -0
- package/dist/chunk-RBRDTYOO.js.map +1 -0
- package/dist/chunk-S7L6H3KP.js +0 -0
- package/dist/chunk-TERFLG67.js +0 -0
- package/dist/{chunk-H243MR3F.js → chunk-TGTNRUH3.js} +2 -2
- package/dist/{chunk-W4XWVTN4.js → chunk-UYFZ6DDW.js} +2 -2
- package/dist/chunk-VRVNM3QL.js +0 -0
- package/dist/{chunk-Z5IGLBWE.js → chunk-WFNLNIJX.js} +1 -1
- package/dist/chunk-WR4F4EEZ.js +0 -0
- package/dist/chunk-Y4TOVMNC.js +0 -0
- package/dist/chunk-YJWEADAW.js +0 -0
- package/dist/client/core.d.ts +294 -0
- package/dist/client/core.js +22 -0
- package/dist/client/index.d.ts +4 -251
- package/dist/client/index.js +11 -401
- package/dist/client/index.js.map +1 -1
- package/dist/cloudflare-C6E5SPAE.js +0 -0
- package/dist/configure-agent-registry-ZOBVU3MV.js +0 -0
- package/dist/db-3UNAMSFK.js +0 -0
- package/dist/deno-deploy-RFZN56X4.js +0 -0
- package/dist/dev-5ZQMWVFC.js +0 -0
- package/dist/dev-emit-EFQRBVYS.js +0 -0
- package/dist/dispatcher-EJHL6JMJ.js +0 -0
- package/dist/docker-LZZB4D5E.js +0 -0
- package/dist/generate-373DALPY.js +0 -0
- package/dist/index.js +6 -6
- package/dist/info-2OOXFTJX.js +0 -0
- package/dist/{internal-api-KPULK7ZK.js → internal-api-JIR3HRKF.js} +3 -3
- package/dist/internal-api-JIR3HRKF.js.map +1 -0
- package/dist/internal-api-Y5REPVUS.js +0 -0
- package/dist/load-config-3EAQTXPH.js +0 -0
- package/dist/mcp-VMKWB2BY.js +0 -0
- package/dist/netlify-PMLHVPN4.js +0 -0
- package/dist/node-BPJ3Z4DT.js +0 -0
- package/dist/openapi-ERYWAT3A.js +0 -0
- package/dist/registry-3NB7KOUI.js +0 -0
- package/dist/router-TLEAOFID.js +0 -0
- package/dist/routes-XNS3UM3B.js +0 -0
- package/dist/scan-7MJC6PYU.js +0 -0
- package/dist/schema-LYOLNHZ7.js +0 -0
- package/dist/server/http/index.js +2 -2
- package/dist/server/index.js +3 -3
- package/dist/server/observability/index.js +1 -1
- package/dist/server-error-to-envelope-UUXDSLAZ.js +0 -0
- package/dist/server-routes-hmr-VZXOP5YT.js +0 -0
- package/dist/services-json-Y3XODNB5.js +0 -0
- package/dist/services-typed-client-32KMTTXR.js +0 -0
- package/dist/start-IFTLTEPZ.js +0 -0
- package/dist/static-MB2CD5Y3.js +0 -0
- package/dist/storage-manager-ZSQFLEYT.js +0 -0
- package/dist/theo-cloud-DQRP6S6M.js +0 -0
- package/dist/upgrade-readiness-ACGW44JC.js +0 -0
- package/dist/vercel-J6G7ZHYQ.js +0 -0
- package/dist/vite-plugin/index.js +6 -6
- package/dist/vite-plugin-BNI7YLCD.js +0 -0
- package/package.json +14 -10
- /package/dist/{actions-virtual-module-JB5ZTS5U.js.map → actions-virtual-module-PBLLMJY4.js.map} +0 -0
- /package/dist/{app-typed-client-VMSRQGKL.js.map → app-typed-client-EXHUWPOI.js.map} +0 -0
- /package/dist/{chunk-R4VVXLKZ.js.map → chunk-EHUT4FMG.js.map} +0 -0
- /package/dist/{chunk-H243MR3F.js.map → chunk-TGTNRUH3.js.map} +0 -0
- /package/dist/{chunk-W4XWVTN4.js.map → chunk-UYFZ6DDW.js.map} +0 -0
- /package/dist/{chunk-Z5IGLBWE.js.map → chunk-WFNLNIJX.js.map} +0 -0
- /package/dist/{internal-api-KPULK7ZK.js.map → client/core.js.map} +0 -0
package/dist/client/index.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentClient,
|
|
3
|
+
ChannelTransport,
|
|
4
|
+
HttpTransport,
|
|
5
|
+
InProcessTransport,
|
|
6
|
+
consumeChunkStream,
|
|
7
|
+
consumeUIMessageStream,
|
|
8
|
+
createAgentClient,
|
|
9
|
+
responseToChunkStream
|
|
10
|
+
} from "../chunk-RBRDTYOO.js";
|
|
1
11
|
import {
|
|
2
12
|
buildUseTheoQueryConfig,
|
|
3
13
|
stableQueryKey
|
|
@@ -384,252 +394,8 @@ function createAppClient(baseUrlOrOptions, legacyFetchImpl) {
|
|
|
384
394
|
return makeProxy({ segments: [], baseUrl, fetchImpl });
|
|
385
395
|
}
|
|
386
396
|
|
|
387
|
-
// src/client/consume-ui-message-stream.ts
|
|
388
|
-
async function consumeUIMessageStream(response, onMessage) {
|
|
389
|
-
const chunkStream = await responseToChunkStream(response);
|
|
390
|
-
await consumeChunkStream(chunkStream, onMessage);
|
|
391
|
-
}
|
|
392
|
-
async function responseToChunkStream(response) {
|
|
393
|
-
if (response.body === null) {
|
|
394
|
-
return new ReadableStream({
|
|
395
|
-
start(controller) {
|
|
396
|
-
controller.close();
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
const { parseJsonEventStream, uiMessageChunkSchema } = await import("ai");
|
|
401
|
-
const parsed = parseJsonEventStream({ stream: response.body, schema: uiMessageChunkSchema });
|
|
402
|
-
return new ReadableStream({
|
|
403
|
-
async start(controller) {
|
|
404
|
-
for await (const result of parsed) {
|
|
405
|
-
if (result.success) controller.enqueue(result.value);
|
|
406
|
-
}
|
|
407
|
-
controller.close();
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
async function consumeChunkStream(stream, onMessage) {
|
|
412
|
-
const { readUIMessageStream } = await import("ai");
|
|
413
|
-
for await (const message of readUIMessageStream({ stream })) {
|
|
414
|
-
onMessage(message);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
418
397
|
// src/client/use-agent.ts
|
|
419
398
|
import { useMemo, useRef, useSyncExternalStore } from "react";
|
|
420
|
-
|
|
421
|
-
// src/client/agent-client.ts
|
|
422
|
-
function inputToText(input) {
|
|
423
|
-
if (typeof input === "object" && input !== null && typeof input.message === "string") {
|
|
424
|
-
return input.message;
|
|
425
|
-
}
|
|
426
|
-
if (typeof input === "string") return input;
|
|
427
|
-
return JSON.stringify(input);
|
|
428
|
-
}
|
|
429
|
-
function buildUserMessage(input) {
|
|
430
|
-
return {
|
|
431
|
-
id: crypto.randomUUID(),
|
|
432
|
-
role: "user",
|
|
433
|
-
parts: [{ type: "text", text: inputToText(input) }]
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
var AgentClient = class {
|
|
437
|
-
#transport;
|
|
438
|
-
#chatId = crypto.randomUUID();
|
|
439
|
-
#listeners = /* @__PURE__ */ new Set();
|
|
440
|
-
/** M43 — resolves per-request context (evaluated on every send/reconnect — dynamic, never stale). */
|
|
441
|
-
#contextResolver;
|
|
442
|
-
#messages = [];
|
|
443
|
-
#status = "idle";
|
|
444
|
-
#error;
|
|
445
|
-
#controller = null;
|
|
446
|
-
#snapshot = { messages: [], status: "idle", error: void 0 };
|
|
447
|
-
constructor(transport, contextResolver) {
|
|
448
|
-
this.#transport = transport;
|
|
449
|
-
this.#contextResolver = contextResolver;
|
|
450
|
-
}
|
|
451
|
-
/** Subscribe to state changes; returns an unsubscribe fn. */
|
|
452
|
-
subscribe = (listener) => {
|
|
453
|
-
this.#listeners.add(listener);
|
|
454
|
-
return () => {
|
|
455
|
-
this.#listeners.delete(listener);
|
|
456
|
-
};
|
|
457
|
-
};
|
|
458
|
-
/** The current immutable snapshot (stable reference until the next emit). */
|
|
459
|
-
getSnapshot = () => this.#snapshot;
|
|
460
|
-
#emit() {
|
|
461
|
-
this.#snapshot = { messages: this.#messages, status: this.#status, error: this.#error };
|
|
462
|
-
for (const listener of this.#listeners) listener();
|
|
463
|
-
}
|
|
464
|
-
#upsert(message) {
|
|
465
|
-
const next = [...this.#messages];
|
|
466
|
-
const idx = next.findIndex((existing) => existing.id === message.id);
|
|
467
|
-
if (idx >= 0) next[idx] = message;
|
|
468
|
-
else next.push(message);
|
|
469
|
-
this.#messages = next;
|
|
470
|
-
}
|
|
471
|
-
async #drive(open, controller) {
|
|
472
|
-
const aborted = () => controller.signal.aborted;
|
|
473
|
-
try {
|
|
474
|
-
const stream = await open();
|
|
475
|
-
if (aborted()) return;
|
|
476
|
-
if (stream === null) {
|
|
477
|
-
this.#status = this.#messages.length > 0 ? "done" : "idle";
|
|
478
|
-
this.#emit();
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
await consumeChunkStream(stream, (message) => {
|
|
482
|
-
if (aborted()) return;
|
|
483
|
-
this.#upsert(message);
|
|
484
|
-
this.#emit();
|
|
485
|
-
});
|
|
486
|
-
if (aborted()) return;
|
|
487
|
-
this.#status = "done";
|
|
488
|
-
this.#emit();
|
|
489
|
-
} catch (err) {
|
|
490
|
-
if (aborted()) return;
|
|
491
|
-
this.#error = err instanceof Error ? err : new Error(String(err));
|
|
492
|
-
this.#status = "error";
|
|
493
|
-
this.#emit();
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
/** Send a typed input; opens a fresh stream (replaces prior messages). */
|
|
497
|
-
send = (input) => {
|
|
498
|
-
this.abort();
|
|
499
|
-
const controller = new AbortController();
|
|
500
|
-
this.#controller = controller;
|
|
501
|
-
this.#messages = [];
|
|
502
|
-
this.#error = void 0;
|
|
503
|
-
this.#status = "streaming";
|
|
504
|
-
this.#emit();
|
|
505
|
-
const context = this.#contextResolver?.();
|
|
506
|
-
void this.#drive(
|
|
507
|
-
() => this.#transport.sendMessages({
|
|
508
|
-
trigger: "submit-message",
|
|
509
|
-
chatId: this.#chatId,
|
|
510
|
-
messageId: void 0,
|
|
511
|
-
messages: [buildUserMessage(input)],
|
|
512
|
-
abortSignal: controller.signal,
|
|
513
|
-
// Only object inputs flow as the request `body` (the turn text is always in `messages`);
|
|
514
|
-
// a primitive input is carried by the user message, never spread into the body.
|
|
515
|
-
body: typeof input === "object" && input !== null ? input : void 0,
|
|
516
|
-
// M43 — per-request context reaches every transport (headers → HTTP, metadata → in-process/channel).
|
|
517
|
-
headers: context?.headers,
|
|
518
|
-
metadata: context?.metadata
|
|
519
|
-
}),
|
|
520
|
-
controller
|
|
521
|
-
);
|
|
522
|
-
};
|
|
523
|
-
/** Resume an interrupted stream via the transport's `reconnectToStream` (no-op when unavailable). */
|
|
524
|
-
reconnect = () => {
|
|
525
|
-
const controller = new AbortController();
|
|
526
|
-
this.#controller = controller;
|
|
527
|
-
this.#status = "streaming";
|
|
528
|
-
this.#emit();
|
|
529
|
-
const context = this.#contextResolver?.();
|
|
530
|
-
void this.#drive(
|
|
531
|
-
() => this.#transport.reconnectToStream({
|
|
532
|
-
chatId: this.#chatId,
|
|
533
|
-
headers: context?.headers,
|
|
534
|
-
metadata: context?.metadata
|
|
535
|
-
}),
|
|
536
|
-
controller
|
|
537
|
-
);
|
|
538
|
-
};
|
|
539
|
-
/** Abort an in-flight stream (not an error — leaves messages as-is). */
|
|
540
|
-
abort = () => {
|
|
541
|
-
this.#controller?.abort();
|
|
542
|
-
this.#controller = null;
|
|
543
|
-
};
|
|
544
|
-
/** Clear messages + error, back to idle. */
|
|
545
|
-
reset = () => {
|
|
546
|
-
this.abort();
|
|
547
|
-
this.#messages = [];
|
|
548
|
-
this.#error = void 0;
|
|
549
|
-
this.#status = "idle";
|
|
550
|
-
this.#emit();
|
|
551
|
-
};
|
|
552
|
-
/** Settle a paused HITL approval via the transport's HITL path (HTTP POST or inline callback). */
|
|
553
|
-
approve = async (approvalId, decision) => {
|
|
554
|
-
await this.#transport.approve?.(approvalId, decision);
|
|
555
|
-
};
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
// src/client/http-transport.ts
|
|
559
|
-
function toRecord(headers) {
|
|
560
|
-
if (headers === void 0) return {};
|
|
561
|
-
if (headers instanceof Headers) return Object.fromEntries(headers.entries());
|
|
562
|
-
return headers;
|
|
563
|
-
}
|
|
564
|
-
var HttpTransport = class {
|
|
565
|
-
#api;
|
|
566
|
-
#headers;
|
|
567
|
-
#fetch;
|
|
568
|
-
/** Server-minted id of the last run (from `x-theokit-run-id`) — the reconnect key. */
|
|
569
|
-
#lastRunId;
|
|
570
|
-
constructor(options) {
|
|
571
|
-
this.#api = options.api;
|
|
572
|
-
this.#headers = options.headers ?? {};
|
|
573
|
-
this.#fetch = options.fetch ?? globalThis.fetch;
|
|
574
|
-
}
|
|
575
|
-
/** Resolve the configured headers per request (a resolver evaluates now — dynamic auth is never stale). */
|
|
576
|
-
#resolveHeaders() {
|
|
577
|
-
return (typeof this.#headers === "function" ? this.#headers() : this.#headers) ?? {};
|
|
578
|
-
}
|
|
579
|
-
async sendMessages(options) {
|
|
580
|
-
const { messages, abortSignal, headers, body } = options;
|
|
581
|
-
const extra = typeof body === "object" ? body : void 0;
|
|
582
|
-
const response = await this.#fetch(this.#api, {
|
|
583
|
-
method: "POST",
|
|
584
|
-
headers: {
|
|
585
|
-
"content-type": "application/json",
|
|
586
|
-
accept: "text/event-stream",
|
|
587
|
-
"X-Theo-Action": "1",
|
|
588
|
-
...this.#resolveHeaders(),
|
|
589
|
-
...toRecord(headers)
|
|
590
|
-
},
|
|
591
|
-
body: JSON.stringify({ ...extra, messages }),
|
|
592
|
-
signal: abortSignal
|
|
593
|
-
});
|
|
594
|
-
if (!response.ok) {
|
|
595
|
-
throw new Error(
|
|
596
|
-
`Agent request to ${this.#api} failed: ${response.status} ${response.statusText}`
|
|
597
|
-
);
|
|
598
|
-
}
|
|
599
|
-
this.#lastRunId = response.headers.get("x-theokit-run-id") ?? void 0;
|
|
600
|
-
return responseToChunkStream(response);
|
|
601
|
-
}
|
|
602
|
-
async reconnectToStream(options) {
|
|
603
|
-
if (this.#lastRunId === void 0) return null;
|
|
604
|
-
const response = await this.#fetch(`${this.#api}/runs/${this.#lastRunId}/stream`, {
|
|
605
|
-
method: "GET",
|
|
606
|
-
headers: { ...this.#resolveHeaders(), ...toRecord(options.headers) }
|
|
607
|
-
});
|
|
608
|
-
if (response.status === 404) return null;
|
|
609
|
-
if (!response.ok) {
|
|
610
|
-
throw new Error(
|
|
611
|
-
`Agent reconnect to run ${this.#lastRunId} failed: ${response.status} ${response.statusText}`
|
|
612
|
-
);
|
|
613
|
-
}
|
|
614
|
-
return responseToChunkStream(response);
|
|
615
|
-
}
|
|
616
|
-
async approve(approvalId, decision) {
|
|
617
|
-
const response = await this.#fetch(`${this.#api}/approve/${approvalId}`, {
|
|
618
|
-
method: "POST",
|
|
619
|
-
headers: {
|
|
620
|
-
"content-type": "application/json",
|
|
621
|
-
"X-Theo-Action": "1",
|
|
622
|
-
...this.#resolveHeaders()
|
|
623
|
-
},
|
|
624
|
-
body: JSON.stringify(decision)
|
|
625
|
-
});
|
|
626
|
-
if (!response.ok) {
|
|
627
|
-
throw new Error(`Approve ${approvalId} failed: ${response.status} ${response.statusText}`);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
};
|
|
631
|
-
|
|
632
|
-
// src/client/use-agent.ts
|
|
633
399
|
function useAgent(pathOrTransport, options = {}) {
|
|
634
400
|
const optionsRef = useRef(options);
|
|
635
401
|
optionsRef.current = options;
|
|
@@ -662,163 +428,6 @@ function useAgent(pathOrTransport, options = {}) {
|
|
|
662
428
|
};
|
|
663
429
|
}
|
|
664
430
|
|
|
665
|
-
// src/client/last-user-text.ts
|
|
666
|
-
function extractLastUserText(messages) {
|
|
667
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
668
|
-
const message = messages[i];
|
|
669
|
-
if (message.role !== "user") continue;
|
|
670
|
-
const text = message.parts.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
671
|
-
if (text.length > 0) return text;
|
|
672
|
-
}
|
|
673
|
-
return "";
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// src/client/in-process-transport.ts
|
|
677
|
-
function generatorToStream(gen) {
|
|
678
|
-
return new ReadableStream({
|
|
679
|
-
async pull(controller) {
|
|
680
|
-
try {
|
|
681
|
-
const result = await gen.next();
|
|
682
|
-
if (result.done === true) {
|
|
683
|
-
controller.close();
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
controller.enqueue(result.value);
|
|
687
|
-
} catch (err) {
|
|
688
|
-
controller.error(err);
|
|
689
|
-
}
|
|
690
|
-
},
|
|
691
|
-
async cancel() {
|
|
692
|
-
await gen.return(void 0);
|
|
693
|
-
}
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
var InProcessTransport = class {
|
|
697
|
-
#run;
|
|
698
|
-
/** Pending inline approvals: approvalId → resolver of the parked `awaitApproval` promise. */
|
|
699
|
-
#pending = /* @__PURE__ */ new Map();
|
|
700
|
-
constructor(options) {
|
|
701
|
-
this.#run = options.run;
|
|
702
|
-
}
|
|
703
|
-
#awaitApproval = (req) => new Promise((resolve, reject) => {
|
|
704
|
-
if (this.#pending.has(req.approvalId)) {
|
|
705
|
-
reject(new Error(`Duplicate pending approval id '${req.approvalId}' \u2014 ids must be unique.`));
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
this.#pending.set(req.approvalId, resolve);
|
|
709
|
-
});
|
|
710
|
-
sendMessages(options) {
|
|
711
|
-
const { messages, abortSignal, metadata } = options;
|
|
712
|
-
const generator = this.#run({
|
|
713
|
-
message: extractLastUserText(messages),
|
|
714
|
-
signal: abortSignal ?? void 0,
|
|
715
|
-
awaitApproval: this.#awaitApproval,
|
|
716
|
-
// M43 — forward per-request context (the seam's `metadata`) to the runner.
|
|
717
|
-
context: metadata
|
|
718
|
-
});
|
|
719
|
-
return Promise.resolve(generatorToStream(generator));
|
|
720
|
-
}
|
|
721
|
-
reconnectToStream() {
|
|
722
|
-
return Promise.resolve(null);
|
|
723
|
-
}
|
|
724
|
-
approve(approvalId, decision) {
|
|
725
|
-
const resolve = this.#pending.get(approvalId);
|
|
726
|
-
if (resolve === void 0) {
|
|
727
|
-
return Promise.reject(
|
|
728
|
-
new Error(`No pending approval '${approvalId}' (unknown or already settled).`)
|
|
729
|
-
);
|
|
730
|
-
}
|
|
731
|
-
this.#pending.delete(approvalId);
|
|
732
|
-
resolve(decision);
|
|
733
|
-
return Promise.resolve();
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
|
|
737
|
-
// src/client/channel-transport.ts
|
|
738
|
-
var ChannelTransport = class {
|
|
739
|
-
#source;
|
|
740
|
-
constructor(options) {
|
|
741
|
-
this.#source = options.source;
|
|
742
|
-
}
|
|
743
|
-
sendMessages(options) {
|
|
744
|
-
const { messages, abortSignal, metadata } = options;
|
|
745
|
-
const message = extractLastUserText(messages);
|
|
746
|
-
const source = this.#source;
|
|
747
|
-
let closed = false;
|
|
748
|
-
let teardown = () => void 0;
|
|
749
|
-
let detachAbort = () => void 0;
|
|
750
|
-
const stream = new ReadableStream({
|
|
751
|
-
start(controller) {
|
|
752
|
-
const finish = (settle) => {
|
|
753
|
-
if (closed) return;
|
|
754
|
-
closed = true;
|
|
755
|
-
detachAbort();
|
|
756
|
-
settle();
|
|
757
|
-
};
|
|
758
|
-
teardown = source.start(
|
|
759
|
-
{ message, context: metadata },
|
|
760
|
-
{
|
|
761
|
-
onLine: (line) => {
|
|
762
|
-
if (closed) return;
|
|
763
|
-
let parsed;
|
|
764
|
-
try {
|
|
765
|
-
parsed = JSON.parse(line);
|
|
766
|
-
} catch {
|
|
767
|
-
return;
|
|
768
|
-
}
|
|
769
|
-
if (typeof parsed !== "object" || parsed === null || typeof parsed.type !== "string") {
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
controller.enqueue(parsed);
|
|
773
|
-
},
|
|
774
|
-
onClose: () => {
|
|
775
|
-
finish(() => {
|
|
776
|
-
controller.close();
|
|
777
|
-
});
|
|
778
|
-
},
|
|
779
|
-
onError: (err) => {
|
|
780
|
-
finish(() => {
|
|
781
|
-
controller.error(err);
|
|
782
|
-
});
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
);
|
|
786
|
-
if (abortSignal !== void 0) {
|
|
787
|
-
const onAbort = () => {
|
|
788
|
-
finish(() => {
|
|
789
|
-
teardown();
|
|
790
|
-
controller.close();
|
|
791
|
-
});
|
|
792
|
-
};
|
|
793
|
-
if (abortSignal.aborted) onAbort();
|
|
794
|
-
else {
|
|
795
|
-
abortSignal.addEventListener("abort", onAbort);
|
|
796
|
-
detachAbort = () => {
|
|
797
|
-
abortSignal.removeEventListener("abort", onAbort);
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
},
|
|
802
|
-
cancel() {
|
|
803
|
-
if (closed) return;
|
|
804
|
-
closed = true;
|
|
805
|
-
detachAbort();
|
|
806
|
-
teardown();
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
return Promise.resolve(stream);
|
|
810
|
-
}
|
|
811
|
-
reconnectToStream() {
|
|
812
|
-
return Promise.resolve(null);
|
|
813
|
-
}
|
|
814
|
-
async approve(approvalId, decision) {
|
|
815
|
-
if (this.#source.settle === void 0) {
|
|
816
|
-
throw new Error(`This channel source has no HITL settle \u2014 cannot approve '${approvalId}'.`);
|
|
817
|
-
}
|
|
818
|
-
await this.#source.settle(approvalId, decision);
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
|
|
822
431
|
// src/client/link.tsx
|
|
823
432
|
import {
|
|
824
433
|
Link as RouterLink
|
|
@@ -969,6 +578,7 @@ export {
|
|
|
969
578
|
buildUseTheoQueryConfig,
|
|
970
579
|
consumeChunkStream,
|
|
971
580
|
consumeUIMessageStream,
|
|
581
|
+
createAgentClient,
|
|
972
582
|
createAppClient,
|
|
973
583
|
createBatcher,
|
|
974
584
|
createGuestMessageHandler,
|