@lloyal-labs/ui 0.1.0-alpha.10

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 ADDED
@@ -0,0 +1,107 @@
1
+ # Functional Source License, Version 1.1, Apache 2.0 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-Apache-2.0
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 Lloyal Labs
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publish, and distribute the
28
+ Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A "Permitted Purpose" is any purpose other than a Competing Use. A
33
+ "Competing Use" means making the Software available to others in a
34
+ commercial product or service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a Licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives
65
+ of the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND,
74
+ INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE,
75
+ MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO
78
+ THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
79
+ DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software
90
+ under the Apache License, Version 2.0 that is effective on the second
91
+ anniversary of the date we make the Software available. On or after that
92
+ date, you may use the Software under the Apache License, Version 2.0, in
93
+ which case the following will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
96
+ use this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software
103
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
104
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
105
+
106
+ See the License for the specific language governing permissions and
107
+ limitations under the License.
@@ -0,0 +1,18 @@
1
+ import type { DocumentMeta } from '@lloyal-labs/media';
2
+ export type Asset = {
3
+ kind: 'image';
4
+ } | {
5
+ kind: 'document';
6
+ meta: DocumentMeta; /** The ingest retained the original file. */
7
+ source: boolean;
8
+ };
9
+ export declare function resolveAsset(origin: string, digest: string): Promise<Asset>;
10
+ /** The kinds of the given roots, filled in as the content plane answers. */
11
+ export declare function useAssets(digests: readonly string[]): Record<string, Asset>;
12
+ /** "1, 2, 3, 7" with runs of three or more folded: "1–3, 7". */
13
+ export declare function pageList(pages: readonly number[]): string;
14
+ /** What of a document reached the model, page by page: which pages had no text
15
+ * to extract (scanned), which were extracted as text, and — when the thread
16
+ * holds their renders — which pages the model looked at. */
17
+ export declare function pageFacts(meta: DocumentMeta, viewedRenders?: ReadonlySet<string>): string[];
18
+ //# sourceMappingURL=assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,MAAM,MAAM,KAAK,GACb;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,YAAY,CAAC,CAAC,6CAA6C;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAI5G,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAcjF;AAED,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAoB3E;AAED,gEAAgE;AAChE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CASzD;AAED;;6DAE6D;AAC7D,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,aAAa,GAAE,WAAW,CAAC,MAAM,CAAa,GAAG,MAAM,EAAE,CAatG"}
package/dist/assets.js ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * What a root IS, learned from its manifest through the content plane: a
3
+ * picture, or a document with its sidecar. One resolution per digest for the
4
+ * page's lifetime — content is immutable under its address, so an answer never
5
+ * goes stale. A root whose manifest cannot be read is shown as an image, so
6
+ * the failure is visible (a broken picture) rather than silent.
7
+ *
8
+ * @category UI
9
+ */
10
+ import { useEffect, useState } from 'react';
11
+ import { asDocumentMeta, configUrl, DOCUMENT_CONFIG_TYPE, manifestUrl } from '@lloyal-labs/media';
12
+ import { useContentOrigin } from './provider.js';
13
+ const resolved = new Map();
14
+ export async function resolveAsset(origin, digest) {
15
+ try {
16
+ const manifest = (await (await fetch(manifestUrl(origin, digest))).json());
17
+ if (manifest.config?.mediaType !== DOCUMENT_CONFIG_TYPE)
18
+ return { kind: 'image' };
19
+ const meta = asDocumentMeta(await (await fetch(configUrl(origin, digest))).json());
20
+ if (!meta)
21
+ return { kind: 'image' };
22
+ const source = (manifest.layers ?? []).some((l) => l.annotations?.['ai.lloyal.role'] === 'source');
23
+ return { kind: 'document', meta, source };
24
+ }
25
+ catch {
26
+ return { kind: 'image' };
27
+ }
28
+ }
29
+ /** The kinds of the given roots, filled in as the content plane answers. */
30
+ export function useAssets(digests) {
31
+ const origin = useContentOrigin();
32
+ const [assets, setAssets] = useState({});
33
+ const key = digests.join(' ');
34
+ useEffect(() => {
35
+ if (origin === null)
36
+ return;
37
+ let live = true;
38
+ for (const digest of key ? key.split(' ') : []) {
39
+ let p = resolved.get(digest);
40
+ if (!p) {
41
+ p = resolveAsset(origin, digest);
42
+ resolved.set(digest, p);
43
+ }
44
+ void p.then((asset) => {
45
+ if (live)
46
+ setAssets((prev) => (prev[digest] ? prev : { ...prev, [digest]: asset }));
47
+ });
48
+ }
49
+ return () => { live = false; };
50
+ }, [origin, key]);
51
+ return assets;
52
+ }
53
+ /** "1, 2, 3, 7" with runs of three or more folded: "1–3, 7". */
54
+ export function pageList(pages) {
55
+ const out = [];
56
+ for (let i = 0; i < pages.length;) {
57
+ let j = i;
58
+ while (j + 1 < pages.length && pages[j + 1] === pages[j] + 1)
59
+ j++;
60
+ out.push(j - i >= 2 ? `${pages[i]}–${pages[j]}` : pages.slice(i, j + 1).join(', '));
61
+ i = j + 1;
62
+ }
63
+ return out.join(', ');
64
+ }
65
+ /** What of a document reached the model, page by page: which pages had no text
66
+ * to extract (scanned), which were extracted as text, and — when the thread
67
+ * holds their renders — which pages the model looked at. */
68
+ export function pageFacts(meta, viewedRenders = new Set()) {
69
+ const scanned = meta.pages.filter((p) => p.chars === 0).map((p) => p.page);
70
+ const viewed = meta.pages.filter((p) => p.render && viewedRenders.has(p.render.digest)).map((p) => p.page);
71
+ const n = meta.pageCount;
72
+ const lines = [
73
+ scanned.length === 0
74
+ ? `Extracted as text: all ${n} page${n === 1 ? '' : 's'}`
75
+ : scanned.length === n
76
+ ? `Scanned (image only): all ${n} page${n === 1 ? '' : 's'}`
77
+ : `Scanned: ${pageList(scanned)} · extracted as text: the rest`,
78
+ ];
79
+ if (viewed.length > 0)
80
+ lines.push(`Viewed as images: ${pageList(viewed)}`);
81
+ return lines;
82
+ }
83
+ //# sourceMappingURL=assets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAElG,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAMjD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;AAEnD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAc,EAAE,MAAc;IAC/D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAGxE,CAAC;QACF,IAAI,QAAQ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,qBAAqB,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3E,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/fold.d.ts ADDED
@@ -0,0 +1,211 @@
1
+ /**
2
+ * The generic agent fold: one agent's life on a view, folded from the bus
3
+ * events every pool emits. Framework-free — the Ink view, the desktop shell's
4
+ * own fold and the browser page all fold the same records — and it knows no
5
+ * product: which spawns get a timeline, and what an agent's task is called,
6
+ * are the application's decisions, handed in at `agent:spawn`.
7
+ *
8
+ * What it owns: the per-agent record ({@link AgentRuntime}), the `<think>`
9
+ * boundary machine (a live think block advances until the marker, then closes
10
+ * and seeds the content buffer with the tail), the timeline items — think,
11
+ * tool call, tool result, report — with their summaries, retry state, and the
12
+ * terminal transitions (`return`/`recovered` → done, `failed`, and the
13
+ * stall-break `done` that precedes a forced recovery).
14
+ *
15
+ * @packageDocumentation
16
+ * @category UI
17
+ */
18
+ /** One cited source, extracted CONSUMER-side from a tool result (the Ability
19
+ * Protocol prescribes no result schema). Web tools populate url/title/snippet;
20
+ * image and icon arrive when an ability emits them; a corpus ability fills
21
+ * whatever subset applies. */
22
+ export interface SourceMeta {
23
+ url?: string;
24
+ title?: string;
25
+ snippet?: string;
26
+ image?: string;
27
+ icon?: string;
28
+ /** Display host, derived from url when present. */
29
+ host?: string;
30
+ }
31
+ /** Per-agent chronological stream item — a renderer lays one component per
32
+ * kind. `live: true` on a think item means its body is currently streaming. */
33
+ export type TimelineItem = {
34
+ kind: 'think';
35
+ id: number;
36
+ title: string;
37
+ body: string;
38
+ live: boolean;
39
+ openedAt: number;
40
+ closedAt: number | null;
41
+ } | {
42
+ kind: 'tool_call';
43
+ id: number;
44
+ tool: string;
45
+ argsSummary: string;
46
+ } | {
47
+ kind: 'tool_result';
48
+ id: number;
49
+ tool: string;
50
+ /** The tool_call id this result pairs with, for a renderer that indents results under their call. */
51
+ callId: number | null;
52
+ byteLength: number;
53
+ preview: string | null;
54
+ hosts: string[];
55
+ resultCount: number | null;
56
+ /** Per-source citation metadata parsed from the tool's free-form result. */
57
+ sources?: SourceMeta[];
58
+ } | {
59
+ kind: 'report';
60
+ id: number;
61
+ body: string;
62
+ tokenCount: number;
63
+ };
64
+ export interface AgentRuntime {
65
+ id: number;
66
+ /** "A0", "A1", … in spawn order within the roster. */
67
+ label: string;
68
+ phase: 'idle' | 'thinking' | 'content' | 'tool' | 'done' | 'failed';
69
+ tokenCount: number;
70
+ toolCallCount: number;
71
+ /** Wall-clock spawn time (ms). */
72
+ startedAt: number;
73
+ /** Wall-clock completion time (ms), set when the agent reaches `done` or `failed`. */
74
+ endedAt: number | null;
75
+ /** The application's index for this agent's task; null for an agent that works no task of the plan (a settling pass, a probe). */
76
+ taskIndex: number | null;
77
+ taskDescription: string | null;
78
+ /** A dependency hint for a chained task ("builds on Task 1"). */
79
+ dependencyHint: string | null;
80
+ /** Id of the currently-live think item in `timeline`, or null. */
81
+ currentThinkId: number | null;
82
+ /** Id of the most recent tool_call, paired with its tool_result when one lands. */
83
+ pendingToolCallId: number | null;
84
+ /** A parked tool call: the provider was rate-limited and the pool re-executes after the delay. */
85
+ retry: {
86
+ tool: string;
87
+ retryAt: number;
88
+ attempt: number;
89
+ } | null;
90
+ /** Live post-`</think>` token buffer: the model writing its tool-call JSON, or a forced recovery's prose. */
91
+ contentBuffer: string;
92
+ /** True while the agent is being force-recovered: `agent:done` fired without a report and the pool
93
+ * streams a forced one; produce tokens go to `contentBuffer`, not a think block. */
94
+ recovering: boolean;
95
+ /** Set when the agent ended without a result: the terminal failure's reason. */
96
+ failReason: string | null;
97
+ /** Think blocks, tool rows, the report — or null for an agent tracked by its numbers only. */
98
+ timeline: TimelineItem[] | null;
99
+ }
100
+ /** What a roster holds beside its agents: the counters that keep timeline ids and labels stable. */
101
+ export interface AgentRoster {
102
+ agents: Map<number, AgentRuntime>;
103
+ nextTimelineId: number;
104
+ nextLabelIdx: number;
105
+ }
106
+ export declare const emptyRoster: () => AgentRoster;
107
+ /** The bus events the fold reads, structurally — the agents package's own
108
+ * vocabulary, versioned beside it; every field the fold touches is guarded. */
109
+ export type AgentEvent = {
110
+ type: 'agent:spawn';
111
+ agentId: number;
112
+ parentAgentId?: number;
113
+ key?: string;
114
+ after?: number[];
115
+ } | {
116
+ type: 'agent:produce';
117
+ agentId: number;
118
+ text: string;
119
+ tokenCount: number;
120
+ } | {
121
+ type: 'agent:tool_call';
122
+ agentId: number;
123
+ tool: string;
124
+ args: string;
125
+ } | {
126
+ type: 'agent:tool_retry';
127
+ agentId: number;
128
+ tool: string;
129
+ retryAfterMs: number;
130
+ attempt: number;
131
+ } | {
132
+ type: 'agent:tool_result';
133
+ agentId: number;
134
+ tool: string;
135
+ result: string;
136
+ } | {
137
+ type: 'agent:return';
138
+ agentId: number;
139
+ result: string;
140
+ } | {
141
+ type: 'agent:recovered';
142
+ agentId: number;
143
+ result: string;
144
+ } | {
145
+ type: 'agent:failed';
146
+ agentId: number;
147
+ reason: string;
148
+ } | {
149
+ type: 'agent:done';
150
+ agentId: number;
151
+ };
152
+ /** What the application decides at a spawn — two facts, not one: whether the agent keeps a timeline, and which
153
+ * task of the plan it works (null: none — a settling pass keeps a timeline and works no task; a helper the view
154
+ * never shows keeps neither). */
155
+ export interface SpawnDecision {
156
+ timeline: boolean;
157
+ taskIndex: number | null;
158
+ taskDescription?: string | null;
159
+ dependencyHint?: string | null;
160
+ }
161
+ export interface FoldAgentsOptions {
162
+ /** The application's decision at `agent:spawn`. Default: every agent is tracked by its numbers only, with no timeline and no task. */
163
+ spawn?: (ev: Extract<AgentEvent, {
164
+ type: 'agent:spawn';
165
+ }>) => SpawnDecision;
166
+ /** The tool whose call ends the turn. Its call is not a timeline row: the report streamed live and
167
+ * `agent:return` files it. */
168
+ terminal?: string;
169
+ /** The argument of the terminal tool whose text is the report, streamed as the model writes it; `null` when
170
+ * nothing is to be shown until the report is filed at `agent:return`.
171
+ * @default 'result' */
172
+ terminalField?: string | null;
173
+ /** The clock, for tests. */
174
+ now?: () => number;
175
+ }
176
+ /** The argument a terminal tool's report is read from unless the application names another. */
177
+ export declare const DEFAULT_TERMINAL_FIELD = "result";
178
+ /** Live report markdown from a raw Hermes tool-call buffer
179
+ * (`<tool_call>\n<function=TOOL>\n<parameter=FIELD>\n<markdown>\n</parameter>…`). Null until the open marker
180
+ * arrives, so a half-written call never flashes as prose. A forced recovery streams raw prose with no envelope —
181
+ * callers branch on `recovering` first.
182
+ *
183
+ * Name the terminal `tool` and only ITS call is read: an argument name says nothing about which tool it belongs
184
+ * to, and an ordinary tool may well share one (`write_file(body)` beside `finish(body)`). Without a tool, any
185
+ * call carrying the argument is read. */
186
+ export declare function extractStreamingReport(buffer: string, terminal?: {
187
+ tool?: string;
188
+ field?: string | null;
189
+ }): string | null;
190
+ /** First meaningful line of a think-block body, cleaned up for a title. */
191
+ export declare function extractTitle(body: string): string;
192
+ export declare function hostOf(url: string): string;
193
+ /** A one-line summary of a tool call's arguments: the query, pattern, url or filename it named. */
194
+ export declare function formatArgSummary(_tool: string, rawArgs: string): string;
195
+ export interface ResultSummary {
196
+ summary: string;
197
+ hosts: string[];
198
+ resultCount: number | null;
199
+ preview: string | null;
200
+ sources?: SourceMeta[];
201
+ }
202
+ /** A per-tool summary of a result, parsed from the stock abilities' result
203
+ * shapes (web search and fetch, corpus search, grep and read); anything else
204
+ * falls back to the URLs it carries, else its size. */
205
+ export declare function summarizeResult(tool: string, raw: string): ResultSummary;
206
+ /**
207
+ * Fold one agent event into the roster. Returns the same roster when the event
208
+ * changed nothing. An event for an unknown agent is dropped.
209
+ */
210
+ export declare function foldAgents(r: AgentRoster, ev: AgentEvent, opts?: FoldAgentsOptions): AgentRoster;
211
+ //# sourceMappingURL=fold.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fold.d.ts","sourceRoot":"","sources":["../src/fold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;+BAG+B;AAC/B,MAAM,WAAW,UAAU;IACzB,GAAG,C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