@openlegion/platform 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.
Files changed (120) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1189 -2
  3. package/dist/body.d.ts +9 -0
  4. package/dist/body.js +28 -0
  5. package/dist/chat-history.d.ts +53 -0
  6. package/dist/chat-history.js +11 -0
  7. package/dist/client.d.ts +217 -0
  8. package/dist/client.js +367 -0
  9. package/dist/core.d.ts +47 -0
  10. package/dist/core.js +1 -0
  11. package/dist/crypto.d.ts +25 -0
  12. package/dist/crypto.js +81 -0
  13. package/dist/errors.d.ts +111 -0
  14. package/dist/errors.js +134 -0
  15. package/dist/events.d.ts +131 -0
  16. package/dist/events.js +5 -0
  17. package/dist/generated/api.d.ts +5505 -0
  18. package/dist/generated/api.js +446 -0
  19. package/dist/handler.d.ts +201 -0
  20. package/dist/handler.js +682 -0
  21. package/dist/index.d.ts +24 -0
  22. package/dist/index.js +12 -0
  23. package/dist/kit-agents.d.ts +95 -0
  24. package/dist/kit-agents.js +280 -0
  25. package/dist/kit-codes.d.ts +279 -0
  26. package/dist/kit-codes.js +44 -0
  27. package/dist/kit-connections.d.ts +21 -0
  28. package/dist/kit-connections.js +189 -0
  29. package/dist/kit-files.d.ts +8 -0
  30. package/dist/kit-files.js +117 -0
  31. package/dist/kit-model-keys.d.ts +8 -0
  32. package/dist/kit-model-keys.js +86 -0
  33. package/dist/kit-threads.d.ts +3 -0
  34. package/dist/kit-threads.js +92 -0
  35. package/dist/kit-tools.d.ts +21 -0
  36. package/dist/kit-tools.js +47 -0
  37. package/dist/kit.d.ts +130 -0
  38. package/dist/kit.js +155 -0
  39. package/dist/mcp-server.d.ts +27 -0
  40. package/dist/mcp-server.js +166 -0
  41. package/dist/next.d.ts +24 -0
  42. package/dist/next.js +6 -0
  43. package/dist/ol-signed.d.ts +82 -0
  44. package/dist/ol-signed.js +115 -0
  45. package/dist/react/add-server.d.ts +90 -0
  46. package/dist/react/add-server.js +183 -0
  47. package/dist/react/agent-chat.d.ts +925 -0
  48. package/dist/react/agent-chat.js +1917 -0
  49. package/dist/react/agent-editor.d.ts +133 -0
  50. package/dist/react/agent-editor.js +222 -0
  51. package/dist/react/agent-kit.d.ts +160 -0
  52. package/dist/react/agent-kit.js +279 -0
  53. package/dist/react/agent-list.d.ts +247 -0
  54. package/dist/react/agent-list.js +248 -0
  55. package/dist/react/approval-card.d.ts +272 -0
  56. package/dist/react/approval-card.js +372 -0
  57. package/dist/react/artifact-card.d.ts +38 -0
  58. package/dist/react/artifact-card.js +39 -0
  59. package/dist/react/avatar.d.ts +21 -0
  60. package/dist/react/avatar.js +33 -0
  61. package/dist/react/card-ledger.d.ts +30 -0
  62. package/dist/react/card-ledger.js +49 -0
  63. package/dist/react/chat-timing.d.ts +121 -0
  64. package/dist/react/chat-timing.js +229 -0
  65. package/dist/react/computer-view.d.ts +309 -0
  66. package/dist/react/computer-view.js +543 -0
  67. package/dist/react/computer-viewer.d.ts +175 -0
  68. package/dist/react/computer-viewer.js +555 -0
  69. package/dist/react/computer-wire.d.ts +178 -0
  70. package/dist/react/computer-wire.js +244 -0
  71. package/dist/react/connect-button.d.ts +145 -0
  72. package/dist/react/connect-button.js +212 -0
  73. package/dist/react/connection-request.d.ts +16 -0
  74. package/dist/react/connection-request.js +18 -0
  75. package/dist/react/connections-list.d.ts +90 -0
  76. package/dist/react/connections-list.js +76 -0
  77. package/dist/react/errors.d.ts +250 -0
  78. package/dist/react/errors.js +146 -0
  79. package/dist/react/files.d.ts +41 -0
  80. package/dist/react/files.js +78 -0
  81. package/dist/react/index.d.ts +35 -0
  82. package/dist/react/index.js +26 -0
  83. package/dist/react/limit-words.d.ts +80 -0
  84. package/dist/react/limit-words.js +53 -0
  85. package/dist/react/markdown.d.ts +42 -0
  86. package/dist/react/markdown.js +56 -0
  87. package/dist/react/md-parse.d.ts +106 -0
  88. package/dist/react/md-parse.js +638 -0
  89. package/dist/react/model-keys-card.d.ts +94 -0
  90. package/dist/react/model-keys-card.js +123 -0
  91. package/dist/react/reload.d.ts +211 -0
  92. package/dist/react/reload.js +339 -0
  93. package/dist/react/reveal.d.ts +17 -0
  94. package/dist/react/reveal.js +22 -0
  95. package/dist/react/schedule-editor.d.ts +107 -0
  96. package/dist/react/schedule-editor.js +172 -0
  97. package/dist/react/schedule-time.d.ts +66 -0
  98. package/dist/react/schedule-time.js +90 -0
  99. package/dist/react/styles.css +1274 -0
  100. package/dist/react/transport.d.ts +49 -0
  101. package/dist/react/transport.js +380 -0
  102. package/dist/react/use-connections.d.ts +155 -0
  103. package/dist/react/use-connections.js +231 -0
  104. package/dist/react/use-model-keys.d.ts +47 -0
  105. package/dist/react/use-model-keys.js +57 -0
  106. package/dist/react/use-threads.d.ts +63 -0
  107. package/dist/react/use-threads.js +73 -0
  108. package/dist/react/vault-form.d.ts +92 -0
  109. package/dist/react/vault-form.js +151 -0
  110. package/dist/schema.d.ts +47 -0
  111. package/dist/schema.js +16 -0
  112. package/dist/secrets.d.ts +15 -0
  113. package/dist/secrets.js +18 -0
  114. package/dist/stream.d.ts +129 -0
  115. package/dist/stream.js +192 -0
  116. package/dist/testing.d.ts +33 -0
  117. package/dist/testing.js +40 -0
  118. package/dist/webhooks.d.ts +31 -0
  119. package/dist/webhooks.js +72 -0
  120. package/package.json +85 -3
@@ -0,0 +1,94 @@
1
+ import { type KitModelKey, type ModelKeyVendor } from "./use-model-keys.ts";
2
+ export interface ModelKeysCardLabels {
3
+ title: string;
4
+ intro: string;
5
+ /** The vendors' names. */
6
+ anthropic: string;
7
+ openai: string;
8
+ vendor: string;
9
+ key: string;
10
+ /** The field's placeholder, per vendor. */
11
+ anthropicPlaceholder: string;
12
+ openaiPlaceholder: string;
13
+ save: string;
14
+ checking: string;
15
+ /** `{vendor}`, `{tail}` (the last four characters) and `{date}`. */
16
+ saved: string;
17
+ /** A key saved while the workspace may not use one. */
18
+ notInUse: string;
19
+ /** Under the field when a key is saved: `{vendor}` is the saved key's. */
20
+ replaces: string;
21
+ remove: string;
22
+ /** `{vendor}`. */
23
+ confirm: string;
24
+ keep: string;
25
+ /** Why a key wasn't saved, by the API's code. `{vendor}` is the vendor chosen. */
26
+ /** Refused by its shape, before the vendor saw it: too short, not a key, or the other vendor's. */
27
+ malformed: string;
28
+ /** The vendor refused it. */
29
+ invalid: string;
30
+ modelMissing: string;
31
+ unchecked: string;
32
+ tooMany: string;
33
+ /** The workspace may not use a person's own key. */
34
+ notAllowed: string;
35
+ /** The first read of the workspace's key failed. */
36
+ readFailed: string;
37
+ retry: string;
38
+ }
39
+ export declare const DEFAULT_MODEL_KEYS_CARD_LABELS: ModelKeysCardLabels;
40
+ /**
41
+ * Where the card's first read stands. "ready" once read (a later refresh that failed leaves what was read).
42
+ * "hidden" for a person the API answers 403 (a member: the workspace's key is an owner's or an admin's) or one your
43
+ * `allowModelKeys` turns away (404): Try again cannot help them. "failed" for any other failure, drawn with Try
44
+ * again; "loading" before the answer.
45
+ */
46
+ export declare function modelKeysReadState(allowed: boolean | null, error: Error | null): "ready" | "loading" | "failed" | "hidden";
47
+ /** The card's sentence for a failed save or remove. Never `err.message`. */
48
+ export declare function modelKeyErrorText(err: unknown, vendor: string, labels?: Partial<ModelKeysCardLabels>): string;
49
+ export interface ModelKeysCardProps {
50
+ /** The kit's base path. Default "/api/openlegion". */
51
+ api?: string | undefined;
52
+ fetch?: typeof fetch | undefined;
53
+ labels?: Partial<ModelKeysCardLabels> | undefined;
54
+ /** Where the workspace may not use a person's own key: draw nothing (default), or say so. */
55
+ notAllowed?: "hide" | "explain" | undefined;
56
+ /** A saved key's `checked_at` as you want it shown. Default: "13 Nov", in the page's locale. */
57
+ formatDate?: ((iso: string) => string) | undefined;
58
+ /** Every failure, in full, for YOUR logs. */
59
+ onError?: ((err: Error) => void) | undefined;
60
+ /** After a key is saved: its vendor and last four characters only. */
61
+ onSaved?: ((key: KitModelKey) => void) | undefined;
62
+ onRemoved?: ((vendor: ModelKeyVendor) => void) | undefined;
63
+ className?: string | undefined;
64
+ }
65
+ export declare function ModelKeysCard(props: ModelKeysCardProps): import("react").JSX.Element | null;
66
+ export interface ModelKeysCardViewProps {
67
+ /** Null before the first read. */
68
+ allowed: boolean | null;
69
+ saved: KitModelKey | null;
70
+ vendor: ModelKeyVendor;
71
+ /** The field's value. */
72
+ value: string;
73
+ /** The vendor is checking the key. */
74
+ checking: boolean;
75
+ /** Remove is being confirmed. */
76
+ asking: boolean;
77
+ error: string | null;
78
+ /** The first read failed (`allowed` is null): its line, with Try again (`onRetry`). */
79
+ readFailed?: boolean | undefined;
80
+ /** It is being read again: Try again waits. */
81
+ retrying?: boolean | undefined;
82
+ onRetry?: (() => void) | undefined;
83
+ notAllowed?: "hide" | "explain" | undefined;
84
+ labels?: Partial<ModelKeysCardLabels> | undefined;
85
+ formatDate?: ((iso: string) => string) | undefined;
86
+ className?: string | undefined;
87
+ onVendor: (v: ModelKeyVendor) => void;
88
+ onValue: (v: string) => void;
89
+ onSave: () => void;
90
+ onAsk: (asking: boolean) => void;
91
+ onRemove: (v: ModelKeyVendor) => void;
92
+ }
93
+ /** The card as drawn: the saved key (Remove asked once), then the form, or why there is none. */
94
+ export declare function ModelKeysCardView(p: ModelKeysCardViewProps): import("react").JSX.Element | null;
@@ -0,0 +1,123 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { AgentKitError, agentKitErrorText } from "./agent-kit.js";
5
+ import { useNoteInView } from "./reveal.js";
6
+ import { MODEL_KEY_VENDORS, useModelKeys } from "./use-model-keys.js";
7
+ export const DEFAULT_MODEL_KEYS_CARD_LABELS = {
8
+ title: "Your own AI provider key",
9
+ intro: "The assistants here answer using your own Anthropic or OpenAI key, and the provider bills you for what they use.",
10
+ anthropic: "Anthropic",
11
+ openai: "OpenAI",
12
+ vendor: "Provider",
13
+ key: "API key",
14
+ anthropicPlaceholder: "sk-ant-…",
15
+ openaiPlaceholder: "sk-…",
16
+ save: "Save key",
17
+ checking: "Checking…",
18
+ saved: "{vendor} · ends in {tail} · checked {date}",
19
+ notInUse: "Not in use here",
20
+ replaces: "Saving a new key replaces the {vendor} key.",
21
+ remove: "Remove",
22
+ confirm: "Remove the {vendor} key? The assistants here stop using it.",
23
+ keep: "Keep it",
24
+ malformed: "That doesn't look like an {vendor} key. Check you copied all of it.",
25
+ invalid: "{vendor} didn't accept that key. Check it's still active in your {vendor} account, or make a new one.",
26
+ modelMissing: "That {vendor} key can't use the models the assistants here need. Check the key's project has access to them, or use another key.",
27
+ unchecked: "{vendor} didn't answer, so the key wasn't saved. Try again in a minute.",
28
+ tooMany: "Too many keys tried in the last hour. Try again later.",
29
+ notAllowed: "Using your own AI provider key isn't available here. The assistants keep working as they are.",
30
+ readFailed: "Your key settings didn't load.",
31
+ retry: "Try again",
32
+ };
33
+ export function modelKeysReadState(allowed, error) {
34
+ if (allowed !== null)
35
+ return "ready";
36
+ if (!error)
37
+ return "loading";
38
+ if (error instanceof AgentKitError && (error.code === "insufficient_role" || error.status === 403 || error.status === 404))
39
+ return "hidden";
40
+ return "failed";
41
+ }
42
+ const SENTENCE_FOR = {
43
+ model_key_malformed: "malformed",
44
+ invalid_body: "malformed",
45
+ model_key_invalid: "invalid",
46
+ model_key_model_missing: "modelMissing",
47
+ model_key_unchecked: "unchecked",
48
+ model_key_checks_exceeded: "tooMany",
49
+ model_keys_not_allowed: "notAllowed",
50
+ };
51
+ export function modelKeyErrorText(err, vendor, labels = {}) {
52
+ const l = { ...DEFAULT_MODEL_KEYS_CARD_LABELS, ...labels };
53
+ const label = err instanceof AgentKitError && Object.hasOwn(SENTENCE_FOR, err.code) ? SENTENCE_FOR[err.code] : undefined;
54
+ return (label ? l[label] : agentKitErrorText(err)).replaceAll("{vendor}", vendor);
55
+ }
56
+ const defaultFormatDate = (iso) => {
57
+ const d = new Date(iso);
58
+ return Number.isNaN(d.getTime()) ? "" : new Intl.DateTimeFormat(undefined, { day: "numeric", month: "short" }).format(d);
59
+ };
60
+ export function ModelKeysCard(props) {
61
+ const l = { ...DEFAULT_MODEL_KEYS_CARD_LABELS, ...props.labels };
62
+ const keys = useModelKeys({ api: props.api, fetch: props.fetch, onError: props.onError });
63
+ const [vendor, setVendor] = useState(null);
64
+ const [value, setValue] = useState("");
65
+ const [asking, setAsking] = useState(false);
66
+ const [error, setError] = useState(null);
67
+ const chosen = vendor ?? keys.key?.vendor ?? "anthropic";
68
+ const save = async () => {
69
+ if (value.trim() === "" || keys.saving)
70
+ return;
71
+ setError(null);
72
+ try {
73
+ const saved = await keys.save(chosen, value);
74
+ setValue("");
75
+ props.onSaved?.({ object: "model_key", vendor: saved.vendor, tail: saved.tail, checked_at: saved.checked_at, in_use: saved.in_use });
76
+ }
77
+ catch (err) {
78
+ setError(modelKeyErrorText(err, l[chosen], l));
79
+ props.onError?.(err);
80
+ }
81
+ };
82
+ const remove = async (v) => {
83
+ setError(null);
84
+ try {
85
+ await keys.remove(v);
86
+ props.onRemoved?.(v);
87
+ }
88
+ catch (err) {
89
+ setError(modelKeyErrorText(err, l[v], l));
90
+ props.onError?.(err);
91
+ await keys.refresh();
92
+ }
93
+ setAsking(false);
94
+ };
95
+ const read = modelKeysReadState(keys.allowed, keys.error);
96
+ if (read === "hidden")
97
+ return null;
98
+ return (_jsx(ModelKeysCardView, { readFailed: read === "failed", retrying: keys.loading, onRetry: () => void keys.refresh(), allowed: keys.allowed, saved: keys.key, vendor: chosen, value: value, checking: keys.saving, asking: asking, error: error, notAllowed: props.notAllowed, labels: l, formatDate: props.formatDate, className: props.className, onVendor: (v) => {
99
+ setVendor(v);
100
+ setError(null);
101
+ }, onValue: setValue, onSave: () => void save(), onAsk: setAsking, onRemove: (v) => void remove(v) }));
102
+ }
103
+ export function ModelKeysCardView(p) {
104
+ const l = { ...DEFAULT_MODEL_KEYS_CARD_LABELS, ...p.labels };
105
+ const errorInView = useNoteInView(p.error);
106
+ if (p.allowed === null && p.readFailed) {
107
+ return (_jsxs("section", { "data-ol-model-keys": true, className: p.className, "aria-label": l.title, children: [_jsx("h3", { "data-ol-model-keys-title": true, children: l.title }), _jsx("p", { "data-ol-model-keys-error": true, role: "alert", children: l.readFailed }), _jsx("button", { type: "button", "data-ol-model-keys-retry": true, disabled: p.retrying === true, onClick: () => p.onRetry?.(), children: l.retry })] }));
108
+ }
109
+ if (p.allowed === null)
110
+ return null;
111
+ if (!p.allowed && p.notAllowed !== "explain")
112
+ return null;
113
+ const formatDate = p.formatDate ?? defaultFormatDate;
114
+ const s = p.saved;
115
+ const savedName = s ? l[s.vendor] : "";
116
+ return (_jsxs("section", { "data-ol-model-keys": true, className: p.className, "aria-label": l.title, children: [_jsx("h3", { "data-ol-model-keys-title": true, children: l.title }), p.allowed ? _jsx("p", { "data-ol-model-keys-intro": true, children: l.intro }) : _jsx("p", { "data-ol-model-keys-not-allowed": true, children: l.notAllowed }), p.error ? (_jsx("p", { "data-ol-model-keys-error": true, role: "alert", ref: errorInView, children: p.error })) : null, s ? (_jsxs("div", { "data-ol-model-key": true, "data-ol-model-key-in-use": s.in_use ? "true" : "false", children: [_jsx("span", { "data-ol-model-key-summary": true, children: l.saved
117
+ .replaceAll("{vendor}", savedName)
118
+ .replaceAll("{tail}", (s.tail ?? "").replace(/^…/, ""))
119
+ .replaceAll("{date}", s.checked_at ? formatDate(s.checked_at) : "") }), s.in_use ? null : _jsx("span", { "data-ol-model-key-state": true, children: l.notInUse }), p.asking ? (_jsxs("span", { "data-ol-model-key-confirm": true, role: "group", "aria-label": l.remove, children: [_jsx("span", { children: l.confirm.replaceAll("{vendor}", savedName) }), _jsx("button", { type: "button", onClick: () => p.onRemove(s.vendor), children: l.remove }), _jsx("button", { type: "button", onClick: () => p.onAsk(false), children: l.keep })] })) : (_jsx("button", { type: "button", "data-ol-model-key-remove": true, onClick: () => p.onAsk(true), children: l.remove }))] })) : null, p.allowed ? (_jsxs("form", { "data-ol-model-keys-form": true, "aria-busy": p.checking, onSubmit: (e) => {
120
+ e.preventDefault();
121
+ p.onSave();
122
+ }, children: [_jsxs("label", { "data-ol-model-keys-field": true, children: [_jsx("span", { children: l.vendor }), _jsx("select", { "data-ol-model-keys-vendor": true, value: p.vendor, disabled: p.checking, onChange: (e) => p.onVendor(e.target.value), children: MODEL_KEY_VENDORS.map((v) => (_jsx("option", { value: v, children: l[v] }, v))) })] }), _jsxs("label", { "data-ol-model-keys-field": true, children: [_jsx("span", { children: l.key }), _jsx("input", { "data-ol-model-keys-input": true, type: "password", name: "model-key", autoComplete: "off", autoCapitalize: "off", autoCorrect: "off", spellCheck: false, "data-1p-ignore": "", "data-lpignore": "true", placeholder: p.vendor === "anthropic" ? l.anthropicPlaceholder : l.openaiPlaceholder, value: p.value, disabled: p.checking, onChange: (e) => p.onValue(e.target.value) })] }), s ? _jsx("p", { "data-ol-model-keys-replaces": true, children: l.replaces.replaceAll("{vendor}", savedName) }) : null, _jsx("button", { type: "submit", "data-ol-model-keys-save": true, disabled: p.checking || p.value.trim() === "", children: p.checking ? l.checking : l.save })] })) : null] }));
123
+ }
@@ -0,0 +1,211 @@
1
+ /**
2
+ * What `<AgentChat>` reads once, on load, about the history it was given, for what history alone cannot say:
3
+ *
4
+ * - A person's message whose run left no answer (no assistant message after it). The kit's
5
+ * `GET {base}/runs/{run}` says how the run ended: a run refused before it started, or one that failed, gets
6
+ * the end user's sentence under the message; a run that ended with tool calls and no words gets one tool
7
+ * line per action, as the live stream drew them. A run that was stopped says so. A run still queued or
8
+ * running draws nothing here (the chat's resume follows it).
9
+ * - A `data-vault-request` (an agent asking the person to save a login or a key). The kit's
10
+ * `GET {vault}?thread&message&name` says whether the item is now saved, of that kind, on every site asked.
11
+ * If so, the form is not drawn again.
12
+ *
13
+ * The same, once, for each older page the person scrolls back to (`placeEarlier`), with what is drawn below it.
14
+ *
15
+ * BOUNDED: only the messages of the page it was given, at most `MAX_READS` of each kind (the newest), at most
16
+ * `IN_FLIGHT` requests at a time, each a GET, each read once. A read that fails, or answers anything else, leaves
17
+ * the page as history drew it: no error, no retry. Nothing here ever posts (a form never saves itself).
18
+ */
19
+ import type { UIMessage } from "ai";
20
+ import { type KitLimit } from "./limit-words.ts";
21
+ /** At most this many reads of each kind on one load (the newest). */
22
+ export declare const MAX_READS = 8;
23
+ /** At most this many reads at a time. */
24
+ export declare const IN_FLIGHT = 2;
25
+ /** What a reload draws under a person's message whose run left no answer. */
26
+ export interface RunOutcome {
27
+ /** The run failed: the API's stable code (for `labels.refusals`) and the end user's sentence. */
28
+ refusal: {
29
+ code: string | null;
30
+ message: string; /** A cap's limit (RUN16 (A)), when the run carries one. */
31
+ limit?: KitLimit;
32
+ } | null;
33
+ /**
34
+ * Its tool calls, by the model's tool name, with the state the live stream would have shown. One that needed a
35
+ * person's approval carries its `approval` (apr_…), decided or not: the chat draws its card, which says where it
36
+ * stands, never "Done". One approved and not finished yet is `input-available` (in progress). `action`: its
37
+ * act_…, so a later reply that reuses the call is known as the same call.
38
+ */
39
+ tools: Array<{
40
+ tool: string;
41
+ state: "output-available" | "output-error" | "input-available";
42
+ approval?: string;
43
+ action?: string;
44
+ }>;
45
+ /** The run was stopped (cancelled) before it answered: the chat says so. */
46
+ stopped?: true;
47
+ }
48
+ /** The kit's base path beside the chat route (`/api/openlegion/chat` → `/api/openlegion`). */
49
+ export declare function kitBaseFor(api: string | undefined): string;
50
+ /**
51
+ * The person's messages on this page whose run left no answer: no assistant message comes after them before the next
52
+ * person's message. `only`: of these messages (an older page, read with what is drawn below it, so a message whose
53
+ * reply is the first one drawn is answered).
54
+ */
55
+ export declare function unansweredRuns(messages: readonly UIMessage[], only?: ReadonlySet<string>): Array<{
56
+ message: string;
57
+ run: string;
58
+ }>;
59
+ /**
60
+ * A MESSAGE THE RUN SENT AS IT WENT: a `data-message` part, `{object, id: msg_…, created, text, tainted}`, the
61
+ * moment the agent sent it (`agent_wait` with `say`, `agent_note_to_user`). The thread keeps it as its own row, same
62
+ * id, before the reply. Null for any other part, or one without a message id or words. Not said whether untrusted
63
+ * content reached it: tainted, as an assistant message is until the platform says otherwise.
64
+ */
65
+ export interface SentMessage {
66
+ id: string;
67
+ text: string;
68
+ created: string | null;
69
+ tainted: boolean;
70
+ }
71
+ export declare function sentMessageOf(part: UIMessage["parts"][number]): SentMessage | null;
72
+ /** The ids of the messages a reply carries (`sentMessageOf`), in order. */
73
+ export declare function sentMessageIds(parts: UIMessage["parts"]): Set<string>;
74
+ /**
75
+ * Whether a read of the thread holds `run`'s reply: an assistant message of that run (`settleLedger`). Not one of the
76
+ * messages it sent as it went (`sent`, the ids the live reply carried): those rows are written before the reply's.
77
+ */
78
+ export declare function runSettled(read: readonly UIMessage[], run: string, sent?: ReadonlySet<string>): boolean;
79
+ /** The run's reply in a read of the thread: its last assistant message that is not one it sent as it went. */
80
+ export declare function replyOf(read: readonly UIMessage[], run: string, sent: ReadonlySet<string>): UIMessage | null;
81
+ /**
82
+ * Whether the person's message `message` is drawn and its run still has no reply after it: only then does its run's
83
+ * outcome apply. An outcome that comes back once the thread's re-read placed the reply, or once the
84
+ * message is no longer drawn, would bring an old row back.
85
+ */
86
+ export declare function runStillUnanswered(messages: readonly UIMessage[], message: string): boolean;
87
+ /**
88
+ * The vault asks on this page: the key `<message id>:<part index>` the view hides by, and what the kit's route needs.
89
+ * `only`: of these messages (an older page).
90
+ */
91
+ export declare function historyVaultAsks(messages: readonly UIMessage[], only?: ReadonlySet<string>): Array<{
92
+ key: string;
93
+ message: string;
94
+ name: string;
95
+ }>;
96
+ /** The kit's `run_outcome`, as the view draws it; null for a run that has not ended, or anything else. */
97
+ export declare function runOutcomeOf(body: unknown): RunOutcome | null;
98
+ /**
99
+ * ONE RUN CAN ANSWER SEVERAL MESSAGES. A message sent while a reply is on its way may be answered by that same
100
+ * reply (the platform read both), and its run then resolves to the same unit of work as the run the chat
101
+ * followed: the same start. Of `waiting` (each message with its run), the ones the `followed` run also answered.
102
+ * Read through the kit's `GET {base}/runs/{run}`; a start that is missing, different or unreadable is "not this
103
+ * reply", so a failed read only ever leaves the chat doing what it did before: looking for a later answer.
104
+ */
105
+ export declare function answeredBy(load: {
106
+ base: string;
107
+ fetch: typeof fetch;
108
+ }, followed: string, waiting: ReadonlyArray<{
109
+ message: string;
110
+ run: string;
111
+ }>): Promise<ReadonlySet<string>>;
112
+ /**
113
+ * After a Reconnect: the partial reply it took off (`dropped`) goes back when the replay brought nothing (it failed
114
+ * before its first part), so a failed Reconnect loses nothing. A replay that brought a reply keeps that one.
115
+ */
116
+ export declare function afterReconnect(messages: UIMessage[], dropped: UIMessage | null): UIMessage[];
117
+ /**
118
+ * The history read again on load (`readThreadHistory`): the messages the first read missed (a reply that finished
119
+ * between the page's read and the chat's look for a running answer), appended in order. Only while the chat still
120
+ * shows just the history it was given (`initialCount`): once the person has sent, nothing changes.
121
+ */
122
+ export declare function mergeReread(current: UIMessage[], initialCount: number, read: readonly UIMessage[]): UIMessage[];
123
+ /**
124
+ * THE LOAD'S RE-READ (case B): what the first read missed (`mergeReread`), and once the person has sent in this visit,
125
+ * the replies that arrived since (`missedReplies`), so a schedule's reply that landed before the chat's first idle
126
+ * look is drawn. `current` itself when nothing is new.
127
+ */
128
+ export declare function rereadOnLoad(current: UIMessage[], initialCount: number, read: readonly UIMessage[], drawnRuns: ReadonlySet<string>, ownRun?: (id: string) => string | null): UIMessage[];
129
+ /**
130
+ * A REPLY THAT CAME AND WENT, AND A MESSAGE SENT ELSEWHERE: the thread's messages after what
131
+ * the chat shows that the chat never drew, appended as the thread holds them; else `current` itself. A reply is
132
+ * matched by id, or by run for one the chat drew under its own id: a run on a message shown, or one of `drawnRuns`,
133
+ * the runs this chat drew live to their end (a reply settled as the thread had it keeps the chat's id and carries no
134
+ * run). A person's message by id, or by its run for one the chat sent in this visit (`ownRun`, the transport's
135
+ * `runOfSend`): any other is another tab's or device's, and placed with its reply. Never by words: a reply that says
136
+ * what the one before it said is still a reply. While one of the chat's own sends has no run known, a person's
137
+ * message it does not show might be that one, and nothing is placed; nor when nothing the chat shows is in the thread.
138
+ */
139
+ export declare function missedReplies(current: UIMessage[], read: readonly UIMessage[], drawnRuns?: ReadonlySet<string>, ownRun?: (id: string) => string | null): UIMessage[];
140
+ /**
141
+ * THE THREAD IS THE TRUTH WHEN A REPLY ENDS. The live stream can leave out what the thread holds (the words an
142
+ * `agent.finish` wrote) or draw steps in another order. Once, when the followed run ends, the chat
143
+ * reads the thread and puts the reply as the thread holds it in place of the one it drew: every assistant message
144
+ * of that run, the first keeping the drawn reply's id (so nothing is mounted again). When the two already agree
145
+ * on everything drawn, the messages are returned as they are (the same array), so nothing draws again.
146
+ */
147
+ export declare function reconcileReply(current: UIMessage[], liveId: string, run: string, read: readonly UIMessage[], ownRun?: (id: string) => string | null): UIMessage[];
148
+ /**
149
+ * THE AGENT'S BROWSER AFTER A READ: the row keeps the session's newest words ("Your agent closed the browser.", never a
150
+ * stale "The browser is closed."). The thread
151
+ * places a session's ONE part at its first call, from the row as it is now; the stream sends one at each change, in
152
+ * the reply it happened in. Putting the thread's copy of a later reply in place of the drawn one would drop the later
153
+ * part and leave the first reply's drawn part, older, as all there is. So, after a read:
154
+ * - every drawn part of a session takes the newest data there is: the read's when it has one (it was read after
155
+ * everything drawn), else the newest the chat drew before the read;
156
+ * - a session the followed reply (`liveId`'s) had a part for keeps that part in it when the thread's copy of the reply
157
+ * has none: the thread places the session's one part at its first call, maybe an earlier reply, and this reply's
158
+ * part is where the chat points to that row from.
159
+ * The chat draws a session once, at its first part, with its last part's words (`<AgentChatView>`). Messages whose
160
+ * parts are unchanged are the very same objects, and with nothing changed the very same array comes back. Pure.
161
+ */
162
+ export declare function freshSessions(before: readonly UIMessage[], after: UIMessage[], read: readonly UIMessage[], liveId?: string): UIMessage[];
163
+ /** What a part list draws, as one string: the fields the view reads, never the stream's bookkeeping (ids, states of text, provider data). */
164
+ export declare function drawnAs(parts: UIMessage["parts"]): string;
165
+ /**
166
+ * AN OLDER PAGE (one ongoing conversation per agent): the kit's `GET {base}/chat/{thread}/messages?before=msg_…`, the
167
+ * messages before `before`, oldest first, and where the next page starts (`next`: null at the start of the
168
+ * conversation, or when the route named no message to read from). Null on any failure.
169
+ */
170
+ export declare function readEarlier(load: {
171
+ base: string;
172
+ threadId: string;
173
+ fetch: typeof fetch;
174
+ }, before: string): Promise<{
175
+ messages: UIMessage[];
176
+ next: string | null;
177
+ } | null>;
178
+ /** An older page above what the chat draws: the messages not drawn already, in their order; `current` itself when none. */
179
+ export declare function placeEarlier(current: UIMessage[], page: readonly UIMessage[]): UIMessage[];
180
+ /** The kit's `GET {base}/chat/{thread}/messages`: the thread's newest messages, oldest first; null on any failure. */
181
+ export declare function readThreadHistory(load: {
182
+ base: string;
183
+ threadId: string;
184
+ fetch: typeof fetch;
185
+ }): Promise<UIMessage[] | null>;
186
+ export interface HistoryLoad {
187
+ threadId: string;
188
+ /** The kit's base path (`kitBaseFor`). */
189
+ base: string;
190
+ /** The kit's vault route. */
191
+ vaultApi: string;
192
+ fetch: typeof fetch;
193
+ }
194
+ /**
195
+ * A REPLY THAT WAS CUT READS AS STOPPED. A reply that ended with the chat's Stop asked and no `abort` from
196
+ * its stream (a Stop that landed in the run's last model call): the run's own word, through the kit's
197
+ * `GET {base}/runs/{run}`. "stopped": it ended `cancelled`; "again": it has not closed yet (it closes a moment after
198
+ * its stream), worth one more read; "no": it finished, failed, or the read said nothing: never a guess.
199
+ */
200
+ export declare function runStopped(load: {
201
+ base: string;
202
+ fetch: typeof fetch;
203
+ }, run: string): Promise<"stopped" | "again" | "no">;
204
+ /**
205
+ * The reads for the page, `IN_FLIGHT` at a time. Each answer that says something goes to its callback; every
206
+ * other answer, and every failure, is dropped. Resolves once every read has settled.
207
+ */
208
+ export declare function loadHistoryState(history: readonly UIMessage[], load: HistoryLoad, on: {
209
+ outcome: (message: string, outcome: RunOutcome) => void;
210
+ saved: (key: string) => void;
211
+ }, only?: ReadonlySet<string>): Promise<void>;