@nexface/chat 0.1.20 → 0.1.21-alpha.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.
Files changed (44) hide show
  1. package/dist/assistant-components.d.ts +2 -1
  2. package/dist/assistant-components.js +22 -10
  3. package/dist/assistant-runtime.js +15 -4
  4. package/dist/client.d.ts +3 -1
  5. package/dist/client.js +136 -42
  6. package/dist/config.d.ts +1 -1
  7. package/dist/default-chat.d.ts +1 -1
  8. package/dist/default-chat.js +26411 -26047
  9. package/dist/fonts/Inter-OFL.txt +93 -0
  10. package/dist/fonts/inter-medium.ttf +0 -0
  11. package/dist/protocol-messages.js +15 -16
  12. package/dist/protocol-response.js +10 -3
  13. package/dist/react.d.ts +13 -1
  14. package/dist/react.js +609 -99
  15. package/dist/session-coordinator.d.ts +23 -0
  16. package/dist/session-coordinator.js +139 -0
  17. package/dist/session-history.d.ts +29 -0
  18. package/dist/session-history.js +282 -0
  19. package/dist/shared/errors.d.ts +1 -1
  20. package/dist/shared/errors.js +2 -0
  21. package/dist/shared/tool-presentation.d.ts +17 -0
  22. package/dist/shared/tool-presentation.js +5 -0
  23. package/dist/shared/tool-proxy.d.ts +6 -0
  24. package/dist/shared/tool-proxy.js +25 -0
  25. package/dist/storage.d.ts +4 -6
  26. package/dist/storage.js +52 -43
  27. package/dist/styles.css +1491 -676
  28. package/dist/tool-confirmation-card.d.ts +5 -0
  29. package/dist/tool-confirmation-card.js +33 -0
  30. package/dist/tool-confirmation.d.ts +23 -0
  31. package/dist/tool-confirmation.js +25 -0
  32. package/dist/tool-presentation.d.ts +6 -0
  33. package/dist/tool-presentation.js +132 -0
  34. package/dist/tool-result.d.ts +5 -0
  35. package/dist/tool-result.js +31 -0
  36. package/dist/types.d.ts +3 -1
  37. package/dist/ui/home-demo/greeting.d.ts +3 -1
  38. package/dist/ui/home-demo/greeting.js +2 -2
  39. package/dist/ui/home-demo/suggestions.d.ts +2 -4
  40. package/dist/ui/home-demo/suggestions.js +5 -4
  41. package/dist/ui/home-demo/trace.js +2 -3
  42. package/dist/ui/thread-list.aui.d.ts +2 -1
  43. package/dist/ui/thread-list.aui.js +2 -2
  44. package/package.json +3 -3
@@ -0,0 +1,23 @@
1
+ export declare class HistoryError extends Error {
2
+ readonly code: string;
3
+ constructor(code: string, message: string);
4
+ }
5
+ export declare class SessionCoordinator {
6
+ private readonly held;
7
+ private readonly acquiring;
8
+ private channel?;
9
+ private closed;
10
+ private watchers;
11
+ private notifyLocal?;
12
+ connect(notify: () => void): void;
13
+ watch(): () => void;
14
+ get visible(): boolean;
15
+ private manager;
16
+ owns(id: string): boolean;
17
+ acquire(id: string): Promise<boolean>;
18
+ release(id: string): void;
19
+ write<T>(work: () => T | Promise<T>): Promise<T>;
20
+ occupied(): Promise<Set<string>>;
21
+ notify(): void;
22
+ close(): void;
23
+ }
@@ -0,0 +1,139 @@
1
+ const prefix = "nexface:chat:v4:";
2
+ const listeners = new Set();
3
+ export class HistoryError extends Error {
4
+ code;
5
+ constructor(code, message) {
6
+ super(message);
7
+ this.code = code;
8
+ this.name = "HistoryError";
9
+ }
10
+ }
11
+ export class SessionCoordinator {
12
+ held = new Map();
13
+ acquiring = new Map();
14
+ channel;
15
+ closed = false;
16
+ watchers = 0;
17
+ notifyLocal;
18
+ connect(notify) {
19
+ this.closed = false;
20
+ if (this.notifyLocal)
21
+ listeners.delete(this.notifyLocal);
22
+ this.channel?.close();
23
+ delete this.channel;
24
+ this.notifyLocal = notify;
25
+ listeners.add(notify);
26
+ if (typeof BroadcastChannel !== "undefined") {
27
+ this.channel = new BroadcastChannel(`${prefix}events`);
28
+ this.channel.onmessage = () => notify();
29
+ }
30
+ }
31
+ watch() {
32
+ this.watchers++;
33
+ this.notifyLocal?.();
34
+ return () => {
35
+ this.watchers--;
36
+ };
37
+ }
38
+ get visible() {
39
+ return this.watchers > 0;
40
+ }
41
+ manager() {
42
+ if (!globalThis.navigator?.locks)
43
+ throw new HistoryError("CHAT_STORAGE_UNAVAILABLE", "Chat history requires the Web Locks API in a secure browser context.");
44
+ return navigator.locks;
45
+ }
46
+ owns(id) {
47
+ return this.held.has(id);
48
+ }
49
+ acquire(id) {
50
+ if (this.closed)
51
+ return Promise.resolve(false);
52
+ if (this.owns(id))
53
+ return Promise.resolve(true);
54
+ const pending = this.acquiring.get(id);
55
+ if (pending)
56
+ return pending;
57
+ let resolve;
58
+ let reject;
59
+ const result = new Promise((yes, no) => {
60
+ resolve = yes;
61
+ reject = no;
62
+ });
63
+ this.acquiring.set(id, result);
64
+ let granted = false;
65
+ try {
66
+ void this.manager()
67
+ .request(`${prefix}session:${id}`, { ifAvailable: true }, async (lock) => {
68
+ if (!lock || this.closed) {
69
+ this.acquiring.delete(id);
70
+ resolve(false);
71
+ return;
72
+ }
73
+ await new Promise((release) => {
74
+ granted = true;
75
+ this.held.set(id, release);
76
+ this.acquiring.delete(id);
77
+ resolve(true);
78
+ this.notify();
79
+ });
80
+ })
81
+ .catch((cause) => {
82
+ this.acquiring.delete(id);
83
+ reject(cause);
84
+ })
85
+ .finally(() => {
86
+ if (granted)
87
+ setTimeout(() => this.notify(), 0);
88
+ });
89
+ }
90
+ catch (cause) {
91
+ this.acquiring.delete(id);
92
+ reject(cause);
93
+ }
94
+ return result;
95
+ }
96
+ release(id) {
97
+ const release = this.held.get(id);
98
+ if (!release)
99
+ return;
100
+ this.held.delete(id);
101
+ release();
102
+ // The request completion above notifies after actual browser lock release.
103
+ }
104
+ write(work) {
105
+ return this.manager()
106
+ .request(`${prefix}storage`, () => {
107
+ if (this.closed)
108
+ throw new HistoryError("CHAT_STORAGE_UNAVAILABLE", "The chat history owner has been closed.");
109
+ return work();
110
+ })
111
+ .then((value) => value);
112
+ }
113
+ async occupied() {
114
+ const state = await this.manager().query();
115
+ return new Set((state.held ?? [])
116
+ .flatMap((lock) => {
117
+ const name = lock.name ?? "";
118
+ return name.startsWith(`${prefix}session:`)
119
+ ? [name.slice(`${prefix}session:`.length)]
120
+ : [];
121
+ })
122
+ .filter((id) => !this.owns(id)));
123
+ }
124
+ notify() {
125
+ for (const listener of listeners)
126
+ listener();
127
+ this.channel?.postMessage({ type: "changed" });
128
+ }
129
+ close() {
130
+ this.closed = true;
131
+ if (this.notifyLocal)
132
+ listeners.delete(this.notifyLocal);
133
+ delete this.notifyLocal;
134
+ this.channel?.close();
135
+ delete this.channel;
136
+ for (const id of this.held.keys())
137
+ this.release(id);
138
+ }
139
+ }
@@ -0,0 +1,29 @@
1
+ import { type StoredSession } from "./storage.js";
2
+ import { HistoryError, SessionCoordinator } from "./session-coordinator.js";
3
+ export declare const historyMetaKey = "nexface:chat:sessions:v4:meta";
4
+ export declare const historySessionKey: (id: string) => string;
5
+ declare const locked: () => HistoryError;
6
+ export { locked as sessionLockedError };
7
+ export declare class SessionHistory {
8
+ readonly coordinator: SessionCoordinator;
9
+ private generation?;
10
+ private readonly seen;
11
+ private readonly reusable;
12
+ private readonly observed;
13
+ private readonly opened;
14
+ private readonly fresh;
15
+ private readonly baselines;
16
+ private initialized?;
17
+ onEvict?: (count: number) => void;
18
+ initialize(): Promise<void>;
19
+ list(): StoredSession[];
20
+ unchangedSinceSaved(id: string): boolean;
21
+ private snapshot;
22
+ open(id: string, fresh?: boolean): Promise<StoredSession | undefined>;
23
+ isSaved(session: StoredSession): boolean;
24
+ canReuse(id: string): boolean;
25
+ adoptRestored(session: StoredSession): void;
26
+ private commit;
27
+ save(session: StoredSession): Promise<void>;
28
+ remove(ids: string[], clearAll?: boolean): Promise<void>;
29
+ }
@@ -0,0 +1,282 @@
1
+ import { decodeChatStorage, encodeSession } from "./storage.js";
2
+ import { HistoryError, SessionCoordinator } from "./session-coordinator.js";
3
+ const prefix = "nexface:chat:sessions:v4:";
4
+ export const historyMetaKey = `${prefix}meta`;
5
+ export const historySessionKey = (id) => `${prefix}session:${id}`;
6
+ const failure = (message) => new HistoryError("CHAT_STORAGE_UNAVAILABLE", message);
7
+ const quota = (cause) => cause instanceof DOMException && cause.name === "QuotaExceededError";
8
+ const conflict = () => new HistoryError("CHAT_HISTORY_CONFLICT", "This chat history changed outside this page. Refresh before continuing.");
9
+ const locked = () => new HistoryError("CHAT_SESSION_LOCKED", "This conversation is already open in another tab.");
10
+ export { locked as sessionLockedError };
11
+ function keys() {
12
+ const found = [];
13
+ for (let i = 0; i < localStorage.length; i++) {
14
+ const key = localStorage.key(i);
15
+ if (key?.startsWith(`${prefix}session:`))
16
+ found.push(key);
17
+ }
18
+ return found;
19
+ }
20
+ function parseMeta() {
21
+ const raw = localStorage.getItem(historyMetaKey);
22
+ if (raw === null)
23
+ return;
24
+ const value = JSON.parse(raw);
25
+ if (value?.version !== 4 || typeof value.generation !== "string")
26
+ throw failure("Chat history metadata is invalid. Keep the stored data and refresh to retry.");
27
+ return value;
28
+ }
29
+ function read() {
30
+ const meta = parseMeta() ?? { version: 4, generation: "initial" };
31
+ const entries = keys().flatMap((key) => {
32
+ const raw = localStorage.getItem(key);
33
+ if (raw === null)
34
+ return [];
35
+ const entry = JSON.parse(raw);
36
+ if (entry?.version !== 4 || typeof entry.generation !== "string")
37
+ throw failure("Stored chat history is invalid.");
38
+ if (entry.generation !== meta.generation)
39
+ return [];
40
+ if (!Number.isSafeInteger(entry.revision) ||
41
+ entry.revision < 1 ||
42
+ !Number.isFinite(entry.createdAt) ||
43
+ !Number.isFinite(entry.lastUsedAt) ||
44
+ historySessionKey(entry.session?.id) !== key)
45
+ throw failure("Stored chat history is invalid.");
46
+ const decoded = decodeChatStorage(JSON.stringify({ version: 3, activeSessionId: entry.session.id, sessions: [entry.session] }));
47
+ if (!decoded)
48
+ throw failure("Stored chat history is invalid.");
49
+ return [entry];
50
+ });
51
+ entries.sort((a, b) => a.createdAt - b.createdAt || a.session.id.localeCompare(b.session.id));
52
+ return { meta, entries };
53
+ }
54
+ // Compare persisted business content independently of recency metadata.
55
+ const signature = (entry) => JSON.stringify(encodeSession(entry.session));
56
+ const fingerprint = (entry) => `${entry.revision}:${signature(entry)}`;
57
+ const restored = (session) => decodeChatStorage(JSON.stringify({ version: 3, activeSessionId: session.id, sessions: [session] })).sessions[0];
58
+ export class SessionHistory {
59
+ coordinator = new SessionCoordinator();
60
+ generation;
61
+ seen = new Map();
62
+ reusable = new Set();
63
+ observed = new Map();
64
+ opened = new Map();
65
+ fresh = new Set();
66
+ baselines = new Map();
67
+ initialized;
68
+ onEvict;
69
+ initialize() {
70
+ return (this.initialized ??= this.coordinator.write(() => {
71
+ this.generation = read().meta.generation;
72
+ }));
73
+ }
74
+ list() {
75
+ const entries = read().entries;
76
+ this.observed.clear();
77
+ for (const entry of entries)
78
+ this.observed.set(entry.session.id, fingerprint(entry));
79
+ return entries.map((entry) => restored(entry.session));
80
+ }
81
+ unchangedSinceSaved(id) {
82
+ return this.seen.has(id) && this.seen.get(id) === this.observed.get(id);
83
+ }
84
+ snapshot(fresh = false) {
85
+ const state = read();
86
+ if (this.generation !== state.meta.generation) {
87
+ if (fresh)
88
+ this.generation = state.meta.generation;
89
+ else
90
+ throw conflict();
91
+ }
92
+ return state;
93
+ }
94
+ async open(id, fresh = false) {
95
+ await this.initialize();
96
+ if (!(await this.coordinator.acquire(id)))
97
+ throw locked();
98
+ try {
99
+ return await this.coordinator.write(() => {
100
+ const state = this.snapshot(fresh);
101
+ const entry = state.entries.find((item) => item.session.id === id);
102
+ if (!entry && !fresh)
103
+ throw new HistoryError("UNKNOWN_SESSION", "This conversation was deleted. Choose another conversation.");
104
+ if (entry) {
105
+ if (this.seen.get(id) === fingerprint(entry))
106
+ this.reusable.add(id);
107
+ else
108
+ this.reusable.delete(id);
109
+ this.seen.set(id, fingerprint(entry));
110
+ this.baselines.set(id, JSON.stringify(encodeSession(restored(entry.session))));
111
+ }
112
+ else
113
+ this.fresh.add(id);
114
+ this.opened.set(id, Math.max(Date.now(), ...state.entries.map((item) => item.lastUsedAt + 1)));
115
+ if (entry) {
116
+ try {
117
+ this.commit({
118
+ ...entry,
119
+ lastUsedAt: this.opened.get(id),
120
+ session: encodeSession(entry.session),
121
+ });
122
+ }
123
+ catch {
124
+ /* Recency alone must never evict history or block opening. */
125
+ }
126
+ }
127
+ return entry ? restored(entry.session) : undefined;
128
+ });
129
+ }
130
+ catch (cause) {
131
+ this.coordinator.release(id);
132
+ throw cause;
133
+ }
134
+ }
135
+ isSaved(session) {
136
+ return (this.baselines.get(session.id) === JSON.stringify(encodeSession(session)) ||
137
+ (!session.messages.length && !session.title));
138
+ }
139
+ canReuse(id) {
140
+ return this.reusable.has(id);
141
+ }
142
+ adoptRestored(session) {
143
+ this.baselines.set(session.id, JSON.stringify(encodeSession(session)));
144
+ }
145
+ commit(entry, removed) {
146
+ if (removed)
147
+ localStorage.removeItem(historySessionKey(removed));
148
+ else if (entry)
149
+ localStorage.setItem(historySessionKey(entry.session.id), JSON.stringify(entry));
150
+ }
151
+ async save(session) {
152
+ await this.initialize();
153
+ if (!this.coordinator.owns(session.id))
154
+ throw locked();
155
+ // Encode before deleting anything. Snapshot/encoding errors must never trigger LRU.
156
+ const encoded = encodeSession(session);
157
+ const baseline = JSON.stringify(encoded);
158
+ if (this.baselines.get(session.id) === baseline)
159
+ return;
160
+ await this.coordinator.write(async () => {
161
+ if (!this.coordinator.owns(session.id))
162
+ throw locked();
163
+ let state = this.snapshot(this.fresh.has(session.id));
164
+ let existing = state.entries.find((item) => item.session.id === session.id);
165
+ if (existing ? this.seen.get(session.id) !== fingerprint(existing) : !this.fresh.has(session.id))
166
+ throw conflict();
167
+ if (!existing && !encoded.messages.length && !encoded.title)
168
+ return;
169
+ const entry = {
170
+ version: 4,
171
+ generation: state.meta.generation,
172
+ revision: (existing?.revision ?? 0) + 1,
173
+ createdAt: existing?.createdAt ??
174
+ Math.max(Date.now(), ...state.entries.map((item) => item.createdAt + 1)),
175
+ lastUsedAt: Math.max(Date.now(), this.opened.get(session.id) ?? 0, ...state.entries.map((item) => item.lastUsedAt + 1)),
176
+ session: encoded,
177
+ };
178
+ // Empty sessions and read-only mounts do not create storage records.
179
+ if (localStorage.getItem(historyMetaKey) === null)
180
+ localStorage.setItem(historyMetaKey, JSON.stringify(state.meta));
181
+ const candidates = state.entries
182
+ .filter((item) => item.session.id !== session.id)
183
+ .sort((a, b) => a.lastUsedAt - b.lastUsedAt ||
184
+ a.createdAt - b.createdAt ||
185
+ a.session.id.localeCompare(b.session.id));
186
+ let evicted = 0;
187
+ try {
188
+ for (;;) {
189
+ if (!this.coordinator.owns(session.id))
190
+ throw locked();
191
+ try {
192
+ this.commit(entry);
193
+ break;
194
+ }
195
+ catch (cause) {
196
+ if (!quota(cause))
197
+ throw cause;
198
+ let removed = false;
199
+ while (candidates.length) {
200
+ const candidate = candidates.shift();
201
+ const id = candidate.session.id;
202
+ if (this.coordinator.owns(id) || !(await this.coordinator.acquire(id)))
203
+ continue;
204
+ try {
205
+ // All writers share the storage lock; the session lock protects opening races.
206
+ state = this.snapshot();
207
+ existing = state.entries.find((item) => item.session.id === id);
208
+ if (!existing)
209
+ continue;
210
+ if (!this.coordinator.owns(session.id))
211
+ throw locked();
212
+ this.commit(undefined, id);
213
+ state.entries = state.entries.filter((item) => item.session.id !== id);
214
+ removed = true;
215
+ evicted++;
216
+ this.coordinator.notify();
217
+ break;
218
+ }
219
+ finally {
220
+ this.coordinator.release(id);
221
+ }
222
+ }
223
+ if (!removed)
224
+ throw new HistoryError("CHAT_STORAGE_FULL", "Chat history could not be saved because storage is full. Free space and retry. Older conversations may already have been removed.");
225
+ }
226
+ }
227
+ this.seen.set(session.id, fingerprint(entry));
228
+ this.baselines.set(session.id, baseline);
229
+ this.fresh.delete(session.id);
230
+ this.coordinator.notify();
231
+ }
232
+ finally {
233
+ if (evicted)
234
+ this.onEvict?.(evicted);
235
+ }
236
+ });
237
+ }
238
+ async remove(ids, clearAll = false) {
239
+ await this.initialize();
240
+ const temporary = [];
241
+ let modified = false;
242
+ try {
243
+ // Never wait for a session while holding the global writer lock.
244
+ await this.coordinator.write(async () => {
245
+ const state = this.snapshot();
246
+ const targets = clearAll
247
+ ? [...new Set([...ids, ...state.entries.map((entry) => entry.session.id)])]
248
+ : ids;
249
+ for (const id of [...targets].sort()) {
250
+ if (this.coordinator.owns(id))
251
+ continue;
252
+ if (!(await this.coordinator.acquire(id)))
253
+ throw locked();
254
+ temporary.push(id);
255
+ }
256
+ if (clearAll) {
257
+ const meta = { ...state.meta, generation: crypto.randomUUID() };
258
+ localStorage.setItem(historyMetaKey, JSON.stringify(meta));
259
+ this.generation = meta.generation;
260
+ this.baselines.clear();
261
+ modified = true;
262
+ }
263
+ for (const id of targets) {
264
+ this.commit(undefined, id);
265
+ modified = true;
266
+ state.entries = state.entries.filter((entry) => entry.session.id !== id);
267
+ }
268
+ for (const id of targets) {
269
+ this.seen.delete(id);
270
+ this.baselines.delete(id);
271
+ this.fresh.delete(id);
272
+ }
273
+ });
274
+ }
275
+ finally {
276
+ if (modified)
277
+ this.coordinator.notify();
278
+ for (const id of temporary)
279
+ this.coordinator.release(id);
280
+ }
281
+ }
282
+ }
@@ -1,4 +1,4 @@
1
- export declare const TOOL_ERROR_CODES: readonly ["EXECUTION_OUTCOME_UNKNOWN", "ACTION_IN_FLIGHT", "ACTION_NOT_HANDLED", "ACTION_TARGET_UNAVAILABLE", "BROWSER_EXECUTION_FAILED", "BROWSER_SNAPSHOT_REQUIRED", "BROWSER_TOOLS_UNAVAILABLE", "CONTRACT_MISMATCH", "DUPLICATE_BINDING", "INVALID_INPUT", "INVALID_TOOL_RUNTIME", "OPERATION_BUSY", "TOOL_CANCELLED", "TOOL_CONFIRMATION_INVALIDATED", "TOOL_CONFIRMATION_REJECTED", "TOOL_ERROR", "TOOL_REGISTRATION_TIMEOUT", "TOOL_SKIPPED", "TOOL_UNAVAILABLE", "UNKNOWN_TOOL"];
1
+ export declare const TOOL_ERROR_CODES: readonly ["EXECUTION_OUTCOME_UNKNOWN", "ACTION_IN_FLIGHT", "ACTION_NOT_HANDLED", "ACTION_TARGET_UNAVAILABLE", "BROWSER_EXECUTION_FAILED", "BROWSER_SNAPSHOT_REQUIRED", "BROWSER_TOOLS_UNAVAILABLE", "CONTRACT_MISMATCH", "DUPLICATE_BINDING", "INVALID_INPUT", "INVALID_CONFIRMATION_RESULT", "TOOL_CONFIRMATION_LIMIT", "INVALID_TOOL_RUNTIME", "OPERATION_BUSY", "TOOL_CANCELLED", "TOOL_CONFIRMATION_INVALIDATED", "TOOL_CONFIRMATION_REJECTED", "TOOL_ERROR", "TOOL_REGISTRATION_TIMEOUT", "TOOL_SKIPPED", "TOOL_UNAVAILABLE", "UNKNOWN_TOOL"];
2
2
  type AgentToolErrorCode = (typeof TOOL_ERROR_CODES)[number];
3
3
  export declare class AgentToolError extends Error {
4
4
  readonly code: AgentToolErrorCode;
@@ -10,6 +10,8 @@ export const TOOL_ERROR_CODES = [
10
10
  "CONTRACT_MISMATCH",
11
11
  "DUPLICATE_BINDING",
12
12
  "INVALID_INPUT",
13
+ "INVALID_CONFIRMATION_RESULT",
14
+ "TOOL_CONFIRMATION_LIMIT",
13
15
  "INVALID_TOOL_RUNTIME",
14
16
  "OPERATION_BUSY",
15
17
  "TOOL_CANCELLED",
@@ -0,0 +1,17 @@
1
+ import type { ToolRuntime } from "@nexface/tools";
2
+ export interface ToolRenderContext<TInput = unknown, TResult = unknown> {
3
+ input: TInput;
4
+ status: "running" | "success" | "error" | "cancelled";
5
+ result?: TResult;
6
+ }
7
+ export interface ToolPresentation {
8
+ definition: ReturnType<ToolRuntime["getTools"]>[number]["definition"];
9
+ confirmationProtocol?: true;
10
+ render(context: ToolRenderContext): unknown;
11
+ }
12
+ export interface ToolPresentationController {
13
+ get(name: string): ToolPresentation | undefined;
14
+ subscribe(listener: () => void): () => void;
15
+ }
16
+ export declare const toolPresentationSymbol: unique symbol;
17
+ export declare function getToolPresentationController(runtime: ToolRuntime): ToolPresentationController | undefined;
@@ -0,0 +1,5 @@
1
+ // Generated from shared/tool-presentation.ts. Do not edit manually.
2
+ export const toolPresentationSymbol = Symbol.for("@nexface/tools/tool-presentation");
3
+ export function getToolPresentationController(runtime) {
4
+ return runtime[toolPresentationSymbol];
5
+ }
@@ -0,0 +1,6 @@
1
+ /** Decode the proxy envelope without changing business arguments. */
2
+ export declare function decodeToolProxy(value: Record<string, unknown>): {
3
+ name: string;
4
+ arguments: Record<string, unknown>;
5
+ progressLabel?: string;
6
+ };
@@ -0,0 +1,25 @@
1
+ // Generated from shared/tool-proxy.ts. Do not edit manually.
2
+ /** Decode the proxy envelope without changing business arguments. */
3
+ export function decodeToolProxy(value) {
4
+ if (typeof value.name !== "string" || !value.name.trim())
5
+ throw new Error("nxf_callAppTool needs a non-empty string name.");
6
+ const keys = Object.keys(value).filter((key) => !["name", "arguments", "input", "progressLabel"].includes(key));
7
+ if (keys.length)
8
+ throw new Error(`nxf_callAppTool received unexpected fields: ${keys.join(", ")}.`);
9
+ const modern = Object.hasOwn(value, "arguments");
10
+ const legacy = Object.hasOwn(value, "input");
11
+ if (modern === legacy)
12
+ throw new Error("nxf_callAppTool requires exactly one of arguments or legacy input.");
13
+ const args = modern ? value.arguments : value.input;
14
+ if (!args || typeof args !== "object" || Array.isArray(args))
15
+ throw new Error(`nxf_callAppTool arguments for "${value.name}" must be an object.`);
16
+ if (value.progressLabel !== undefined && typeof value.progressLabel !== "string")
17
+ throw new Error("nxf_callAppTool progressLabel must be a string.");
18
+ return {
19
+ name: value.name,
20
+ arguments: args,
21
+ ...(typeof value.progressLabel === "string" && value.progressLabel.trim()
22
+ ? { progressLabel: value.progressLabel.trim() }
23
+ : {}),
24
+ };
25
+ }
package/dist/storage.d.ts CHANGED
@@ -1,19 +1,17 @@
1
1
  import type { AgentMessage } from "@nexface/agent";
2
2
  import type { UIMessage } from "./react.js";
3
3
  export declare const chatStorageKey = "nexface:chat:sessions:v3";
4
- interface StoredSession {
4
+ export interface StoredSession {
5
5
  id: string;
6
6
  title?: string;
7
+ appendOnly?: boolean;
7
8
  messages: UIMessage[];
8
9
  }
9
10
  interface StoredChat {
10
11
  sessions: StoredSession[];
11
12
  activeSessionId: string;
12
13
  }
13
- export interface ChatStorageVersion {
14
- value: string | null;
15
- }
16
- export declare function readChatStorage(key: string, version?: ChatStorageVersion): StoredChat | undefined;
17
- export declare function writeChatStorage(key: string, state: StoredChat, version: ChatStorageVersion): "saved" | "unchanged" | "conflict" | "unavailable";
14
+ export declare function decodeChatStorage(raw: string | null): StoredChat | undefined;
15
+ export declare function encodeSession(session: StoredSession): StoredSession;
18
16
  export declare function conversationFromMessages(messages: readonly UIMessage[]): AgentMessage[];
19
17
  export {};