@lapis-notes/app-profile 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 (62) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE.md +4 -0
  3. package/README.md +20 -2
  4. package/dist/index.d.ts +34 -0
  5. package/dist/index.js +43 -0
  6. package/dist/local-plugin-distribution.d.ts +3 -0
  7. package/dist/local-plugin-distribution.js +102 -0
  8. package/dist/native-chat/NativeChat.svelte +114 -0
  9. package/dist/native-chat/NativeChat.svelte.d.ts +15 -0
  10. package/dist/native-chat/conversation.d.ts +10 -0
  11. package/dist/native-chat/conversation.js +161 -0
  12. package/dist/native-chat/history.svelte.d.ts +14 -0
  13. package/dist/native-chat/history.svelte.js +18 -0
  14. package/dist/native-chat/index.d.ts +6 -0
  15. package/dist/native-chat/index.js +4 -0
  16. package/dist/native-chat/metadata.d.ts +14 -0
  17. package/dist/native-chat/metadata.js +74 -0
  18. package/dist/native-chat/navigation.d.ts +13 -0
  19. package/dist/native-chat/navigation.js +55 -0
  20. package/dist/native-chat/observer.d.ts +28 -0
  21. package/dist/native-chat/observer.js +343 -0
  22. package/dist/native-chat/participant-capture.d.ts +7 -0
  23. package/dist/native-chat/participant-capture.js +108 -0
  24. package/dist/native-chat/participant-observer.d.ts +24 -0
  25. package/dist/native-chat/participant-observer.js +125 -0
  26. package/dist/native-chat/participant-projection.d.ts +9 -0
  27. package/dist/native-chat/participant-projection.js +116 -0
  28. package/dist/native-chat/plugin.d.ts +5 -0
  29. package/dist/native-chat/plugin.js +60 -0
  30. package/dist/native-chat/queue-capture.d.ts +57 -0
  31. package/dist/native-chat/queue-capture.js +41 -0
  32. package/dist/native-chat/queue-observer.d.ts +16 -0
  33. package/dist/native-chat/queue-observer.js +190 -0
  34. package/dist/native-chat/queue-receipt.d.ts +3 -0
  35. package/dist/native-chat/queue-receipt.js +36 -0
  36. package/dist/native-chat/send.d.ts +11 -0
  37. package/dist/native-chat/send.js +42 -0
  38. package/dist/native-chat/session.d.ts +32 -0
  39. package/dist/native-chat/session.js +82 -0
  40. package/dist/native-chat/view.d.ts +20 -0
  41. package/dist/native-chat/view.js +90 -0
  42. package/dist/native-repository.d.ts +7 -0
  43. package/dist/native-repository.js +26 -0
  44. package/dist/plugin-browser.d.ts +3 -0
  45. package/dist/plugin-browser.js +55 -0
  46. package/dist/plugin-host-build.d.ts +12 -0
  47. package/dist/plugin-host-build.js +88 -0
  48. package/dist/workspace-session/NotesWorkspaceSession.svelte +261 -0
  49. package/dist/workspace-session/NotesWorkspaceSession.svelte.d.ts +8 -0
  50. package/dist/workspace-session/application.d.ts +9 -0
  51. package/dist/workspace-session/application.js +47 -0
  52. package/dist/workspace-session/database-status.d.ts +2 -0
  53. package/dist/workspace-session/database-status.js +37 -0
  54. package/dist/workspace-session/index.d.ts +2 -0
  55. package/dist/workspace-session/index.js +1 -0
  56. package/dist/workspace-session/leave.d.ts +9 -0
  57. package/dist/workspace-session/leave.js +25 -0
  58. package/dist/workspace-session/lifecycle.d.ts +14 -0
  59. package/dist/workspace-session/lifecycle.js +83 -0
  60. package/dist/workspace-session/types.d.ts +33 -0
  61. package/dist/workspace-session/types.js +1 -0
  62. package/package.json +98 -3
@@ -0,0 +1,13 @@
1
+ import type { App } from "@lapis-notes/api";
2
+ export type NativeChatLocation = {
3
+ scopeDir: string;
4
+ conversationId?: string;
5
+ };
6
+ /** App-owned navigation only; opening a view never submits native work. */
7
+ export declare class NativeChatNavigation {
8
+ #private;
9
+ readonly app: App;
10
+ constructor(app: App);
11
+ history(): Promise<void>;
12
+ chat(location?: NativeChatLocation): Promise<void>;
13
+ }
@@ -0,0 +1,55 @@
1
+ /** App-owned navigation only; opening a view never submits native work. */
2
+ export class NativeChatNavigation {
3
+ app;
4
+ #tail = Promise.resolve();
5
+ constructor(app) {
6
+ this.app = app;
7
+ }
8
+ #run(operation) {
9
+ const result = this.#tail.then(operation);
10
+ this.#tail = result.catch(() => { });
11
+ return result;
12
+ }
13
+ async #reveal(leaf) {
14
+ this.app.workspace.activateLeaf(leaf, {
15
+ focusRootHost: false,
16
+ source: "api",
17
+ operation: "open-native-chat",
18
+ });
19
+ await this.app.workspace.revealLeaf(leaf);
20
+ }
21
+ history() {
22
+ return this.#run(async () => {
23
+ const workspace = this.app.workspace;
24
+ const existing = workspace.getLeavesOfType("ai-conversation-history")[0];
25
+ const leaf = existing ??
26
+ workspace.ensureSideLeaf("ai-conversation-history", "right");
27
+ if (!existing)
28
+ await leaf.setViewState({ type: "ai-conversation-history", state: {} });
29
+ await this.#reveal(leaf);
30
+ });
31
+ }
32
+ chat(location) {
33
+ return this.#run(async () => {
34
+ const workspace = this.app.workspace;
35
+ let existing;
36
+ workspace.iterateRootLeaves((leaf) => {
37
+ if (existing || leaf.view.getViewType() !== "ai")
38
+ return;
39
+ const state = leaf.view.getState();
40
+ if (!location ||
41
+ (location.conversationId &&
42
+ state.conversationId === location.conversationId &&
43
+ (state.scopeDir ?? "") === location.scopeDir))
44
+ existing = leaf;
45
+ });
46
+ const leaf = existing ?? workspace.getLeaf("tab");
47
+ if (!existing)
48
+ await leaf.setViewState({
49
+ type: "ai",
50
+ state: location ?? { scopeDir: "" },
51
+ });
52
+ await this.#reveal(leaf);
53
+ });
54
+ }
55
+ }
@@ -0,0 +1,28 @@
1
+ import type { AgentAction, AgentOutcome, AgentPort, AgentSnapshot } from "@lapismd/agent-ui/core";
2
+ import type { NativeChatSession } from "./session";
3
+ /** One view's read-only projection. Native commands retain all durable authority. */
4
+ export declare class NativeChatObserver implements AgentPort {
5
+ #private;
6
+ readonly session: NativeChatSession;
7
+ readonly options: {
8
+ target(): string;
9
+ initialSession?: string;
10
+ initialScope?: string;
11
+ };
12
+ selected: string;
13
+ constructor(session: NativeChatSession, options: {
14
+ target(): string;
15
+ initialSession?: string;
16
+ initialScope?: string;
17
+ });
18
+ resolveRecipients(input: {
19
+ selected: readonly string[];
20
+ }): readonly string[];
21
+ read(signal: AbortSignal): Promise<AgentSnapshot>;
22
+ selectSession(id: string): Promise<AgentSnapshot>;
23
+ act(action: AgentAction): Promise<AgentOutcome>;
24
+ status(id: string): Promise<AgentOutcome>;
25
+ subscribe(listener: (snapshot: AgentSnapshot) => void): () => void;
26
+ report(error: Error): void;
27
+ close(): void;
28
+ }
@@ -0,0 +1,343 @@
1
+ import { active, conversation, directory } from "./conversation";
2
+ import { NativeChatMetadata } from "./metadata";
3
+ import { NativeChatQueueObserver } from "./queue-observer";
4
+ import { NativeChatParticipantObserver } from "./participant-observer";
5
+ import { nativeSendTarget, refused } from "./send";
6
+ /** One view's read-only projection. Native commands retain all durable authority. */
7
+ export class NativeChatObserver {
8
+ session;
9
+ options;
10
+ selected;
11
+ #draft = `draft:${crypto.randomUUID()}`;
12
+ #heads = new Map();
13
+ #firsts = new Map();
14
+ #metadata;
15
+ #queue;
16
+ #participants;
17
+ #records = [];
18
+ #scope;
19
+ #closed = false;
20
+ #tail = Promise.resolve();
21
+ #listeners = new Set();
22
+ #timer;
23
+ constructor(session, options) {
24
+ this.session = session;
25
+ this.options = options;
26
+ this.selected = options.initialSession ?? this.#draft;
27
+ this.#scope = options.initialScope ?? "";
28
+ this.#metadata = new NativeChatMetadata(session);
29
+ this.#queue = new NativeChatQueueObserver(session);
30
+ this.#participants = new NativeChatParticipantObserver(session);
31
+ }
32
+ resolveRecipients(input) {
33
+ return input.selected.length ? input.selected : [this.options.target()];
34
+ }
35
+ #run(operation) {
36
+ const result = this.#tail.then(() => {
37
+ if (this.#closed)
38
+ throw new Error("The chat view is closed");
39
+ return operation();
40
+ });
41
+ this.#tail = result.then(() => { }, () => { });
42
+ return result;
43
+ }
44
+ read(signal) {
45
+ return this.#run(async () => {
46
+ if (signal.aborted)
47
+ throw new Error("Chat observation was cancelled");
48
+ return this.#snapshot();
49
+ });
50
+ }
51
+ async #snapshot() {
52
+ const [list, targets, participants] = await Promise.all([
53
+ this.session.call({ kind: "list" }),
54
+ this.session.call({ kind: "targets" }),
55
+ this.#participants.catalog(),
56
+ ]);
57
+ if (list.kind !== "records" || targets.kind !== "targets")
58
+ throw new Error("Native chat state is unavailable");
59
+ this.#records = list.records;
60
+ this.#heads.clear();
61
+ this.#firsts.clear();
62
+ for (const record of list.records) {
63
+ directory(record);
64
+ const previous = this.#heads.get(record.conversation_id);
65
+ if (!previous || record.accepted_at_ms > previous.accepted_at_ms)
66
+ this.#heads.set(record.conversation_id, record);
67
+ const first = this.#firsts.get(record.conversation_id);
68
+ if (!first || record.accepted_at_ms < first.accepted_at_ms)
69
+ this.#firsts.set(record.conversation_id, record);
70
+ }
71
+ const heads = [...this.#heads.values()].sort((a, b) => b.updated_at_ms - a.updated_at_ms);
72
+ const metadata = await this.#metadata.read(heads, this.#firsts);
73
+ const sessions = heads.map((head) => ({
74
+ id: head.conversation_id,
75
+ title: metadata.get(head.conversation_id)?.title ?? "Conversation",
76
+ agent: head.target_id,
77
+ updatedAt: new Date(head.updated_at_ms).toISOString(),
78
+ status: metadata.get(head.conversation_id)?.status ?? "active",
79
+ scope: head.scope_dir,
80
+ path: directory(head),
81
+ items: [],
82
+ }));
83
+ const head = this.#heads.get(this.selected);
84
+ const receipt = await this.#participants.read(head);
85
+ if (head) {
86
+ const value = await this.session.call({
87
+ kind: "read",
88
+ request_id: head.request_id,
89
+ });
90
+ if (value.kind !== "record" || !value.record)
91
+ throw new Error("Native conversation is unavailable");
92
+ const saved = await conversation(this.session, head, value.record, receipt);
93
+ if (receipt?.input.profiles?.[0])
94
+ sessions.find((row) => row.id === this.selected).agent =
95
+ receipt.input.profiles[0].selection.recipient.id;
96
+ Object.assign(sessions.find((row) => row.id === this.selected), saved);
97
+ }
98
+ else if (this.selected !== this.#draft) {
99
+ throw new Error("The selected native conversation is unavailable");
100
+ }
101
+ if (this.selected === this.#draft)
102
+ sessions.unshift({
103
+ id: this.#draft,
104
+ title: "New conversation",
105
+ agent: this.options.target() ||
106
+ participants[0]?.id ||
107
+ targets.targets[0]?.id ||
108
+ "",
109
+ updatedAt: "",
110
+ status: "active",
111
+ scope: this.#scope,
112
+ items: [],
113
+ });
114
+ const running = !!head &&
115
+ (this.#records.some((row) => row.conversation_id === head.conversation_id && active(row.phase)) ||
116
+ this.#participants.busy(head)), busy = this.#records.some((row) => active(row.phase));
117
+ const queue = await this.#queue.read(head);
118
+ const selectedBusy = running || !!queue.queueState?.running;
119
+ const vaultBusy = busy || !!queue.queueState?.running;
120
+ const canSend = !!targets.targets.length &&
121
+ !this.#participants.uncertain &&
122
+ !this.#queue.paused(head) &&
123
+ (!vaultBusy ||
124
+ (!!head &&
125
+ !this.#participants.declared &&
126
+ !this.#participants.has(head) &&
127
+ this.session.hasQueue &&
128
+ !!(await this.session.queueSelection(this.options.target() || head.target_id))));
129
+ const snapshot = {
130
+ sessions,
131
+ agents: participants.length
132
+ ? participants
133
+ : targets.targets.map((target) => ({
134
+ id: target.id,
135
+ name: target.label,
136
+ enabled: true,
137
+ description: "",
138
+ provider: "Native ACP",
139
+ model: "",
140
+ })),
141
+ catalog: [],
142
+ imports: [],
143
+ requests: [],
144
+ ...queue,
145
+ busy: selectedBusy,
146
+ capabilities: [
147
+ "new_session",
148
+ ...(canSend ? ["send"] : []),
149
+ ...(queue.queueState
150
+ ? ["cancel_queued", "pause_queue", "resume_queue"]
151
+ : []),
152
+ ...(selectedBusy ? ["stop"] : []),
153
+ ],
154
+ chat: {
155
+ scope: head?.scope_dir ?? this.#scope,
156
+ scopes: [...new Set([this.#scope, ...heads.map((h) => h.scope_dir)])],
157
+ files: [],
158
+ controls: { attachments: false, approvalPolicy: false, runtime: false },
159
+ },
160
+ };
161
+ if (!this.#closed)
162
+ for (const listener of this.#listeners)
163
+ listener(snapshot);
164
+ return snapshot;
165
+ }
166
+ selectSession(id) {
167
+ return this.#run(async () => {
168
+ this.selected = id;
169
+ return this.#snapshot();
170
+ });
171
+ }
172
+ act(action) {
173
+ return this.#run(() => this.#act(action));
174
+ }
175
+ async #act(action) {
176
+ if (action.kind === "new_session") {
177
+ this.#draft = `draft:${crypto.randomUUID()}`;
178
+ this.selected = this.#draft;
179
+ return { status: "acknowledged", snapshot: await this.#snapshot() };
180
+ }
181
+ if (["stop", "pause_queue", "resume_queue", "cancel_queued"].includes(action.kind)) {
182
+ const head = this.#heads.get(action.session ?? this.selected);
183
+ if (!head)
184
+ return {
185
+ status: "refused",
186
+ reason: "No native conversation is selected",
187
+ };
188
+ try {
189
+ if (action.kind === "stop" && (await this.#participants.stop(head))) {
190
+ // Native participant Stop addresses the acceptance and all its siblings.
191
+ }
192
+ else if (this.session.hasQueue && this.#queue.has(head))
193
+ await this.#queue.control(action, head);
194
+ else if (action.kind === "stop" && active(head.phase))
195
+ await this.session.call({
196
+ kind: "cancel",
197
+ request_id: head.request_id,
198
+ });
199
+ else
200
+ return {
201
+ status: "refused",
202
+ reason: "No native queue or running turn is available",
203
+ };
204
+ }
205
+ catch (error) {
206
+ return refused(error);
207
+ }
208
+ return { status: "acknowledged", snapshot: await this.#snapshot() };
209
+ }
210
+ if (action.kind !== "send")
211
+ return {
212
+ status: "refused",
213
+ reason: "This action is not available in native chat yet",
214
+ };
215
+ const head = this.#heads.get(action.session ?? this.selected);
216
+ try {
217
+ await this.#participants.catalog();
218
+ if (this.#participants.uncertain &&
219
+ !this.#participants.pending(action.id))
220
+ return {
221
+ status: "refused",
222
+ reason: "Inspect the original participant acceptance before sending another message",
223
+ };
224
+ if (this.#participants.declared ||
225
+ this.#participants.pending(action.id)) {
226
+ if (!this.#participants.pending(action.id) &&
227
+ (this.#records.some((row) => active(row.phase)) ||
228
+ this.#participants.busy(head)))
229
+ return {
230
+ status: "refused",
231
+ reason: "Wait for the current native participants to finish",
232
+ };
233
+ this.selected = await this.#participants.accept(action, head?.scope_dir ?? this.#scope, this.options.target(), head);
234
+ return { status: "acknowledged", snapshot: await this.#snapshot() };
235
+ }
236
+ }
237
+ catch (error) {
238
+ return refused(error);
239
+ }
240
+ let target;
241
+ try {
242
+ target = await nativeSendTarget(this.session, action, this.options.target());
243
+ if (head &&
244
+ !this.#participants.has(head) &&
245
+ this.session.hasQueue &&
246
+ (await this.#queue.accept(action, head, target))) {
247
+ return { status: "acknowledged", snapshot: await this.#snapshot() };
248
+ }
249
+ }
250
+ catch (error) {
251
+ return refused(error);
252
+ }
253
+ if (this.#records.some((row) => active(row.phase)))
254
+ return {
255
+ status: "refused",
256
+ reason: "Wait for the current native turn to finish",
257
+ };
258
+ const input = {
259
+ request_id: action.id,
260
+ target_id: target.id,
261
+ scope_dir: head?.scope_dir ?? this.#scope,
262
+ prompt: action.submission.text,
263
+ context: null,
264
+ options: {
265
+ mode: target.default_mode,
266
+ model: null,
267
+ effort: null,
268
+ max_duration_ms: 60_000,
269
+ },
270
+ ...(head
271
+ ? {
272
+ continuation: {
273
+ conversation_id: head.conversation_id,
274
+ after_request_id: head.request_id,
275
+ },
276
+ }
277
+ : {}),
278
+ };
279
+ try {
280
+ const accepted = await this.session.call({ kind: "submit", input });
281
+ if (accepted.kind !== "record" || !accepted.record)
282
+ return { status: "unknown" };
283
+ this.selected = accepted.record.conversation_id;
284
+ }
285
+ catch (error) {
286
+ return refused(error);
287
+ }
288
+ return { status: "acknowledged", snapshot: await this.#snapshot() };
289
+ }
290
+ status(id) {
291
+ return this.#run(async () => {
292
+ if (this.#participants.pending(id)) {
293
+ const conversation = await this.#participants.status(id);
294
+ if (!conversation)
295
+ return { status: "unknown" };
296
+ this.selected = conversation;
297
+ return { status: "acknowledged", snapshot: await this.#snapshot() };
298
+ }
299
+ if (this.#queue.pending(id)) {
300
+ const conversation = await this.#queue.status(id);
301
+ if (!conversation)
302
+ return { status: "unknown" };
303
+ this.selected = conversation;
304
+ return { status: "acknowledged", snapshot: await this.#snapshot() };
305
+ }
306
+ const value = await this.session.call({ kind: "read", request_id: id });
307
+ if (value.kind !== "record" || !value.record)
308
+ return { status: "unknown" };
309
+ this.selected = value.record.conversation_id;
310
+ return { status: "acknowledged", snapshot: await this.#snapshot() };
311
+ });
312
+ }
313
+ subscribe(listener) {
314
+ this.#listeners.add(listener);
315
+ this.#schedule();
316
+ return () => {
317
+ this.#listeners.delete(listener);
318
+ if (!this.#listeners.size)
319
+ clearTimeout(this.#timer);
320
+ };
321
+ }
322
+ #schedule() {
323
+ if (this.#closed || !this.#listeners.size)
324
+ return;
325
+ clearTimeout(this.#timer);
326
+ this.#timer = setTimeout(() => {
327
+ void this.read(new AbortController().signal)
328
+ .catch((error) => {
329
+ if (!this.#closed)
330
+ this.session.report(error);
331
+ })
332
+ .finally(() => this.#schedule());
333
+ }, 400);
334
+ }
335
+ report(error) {
336
+ this.session.report(error);
337
+ }
338
+ close() {
339
+ this.#closed = true;
340
+ clearTimeout(this.#timer);
341
+ this.#listeners.clear();
342
+ }
343
+ }
@@ -0,0 +1,7 @@
1
+ import type { AgentAction, AgentSnapshot } from "@lapismd/agent-ui/core";
2
+ import type { ParticipantMessageInput, ParticipantProfile, TurnSummary } from "@lapis-notes/api/native-turns";
3
+ /** Declared choices are presentation data; native policy retains routing authority. */
4
+ export declare function participantAgents(profiles: readonly ParticipantProfile[]): AgentSnapshot["agents"];
5
+ /** One immutable authored parent and one native request per selected logical role. */
6
+ export declare function captureNativeParticipants(action: AgentAction, profiles: readonly ParticipantProfile[], scope: string, fallback: string, head?: TurnSummary): ParticipantMessageInput;
7
+ export declare function canonicalParticipant(value: unknown): string;
@@ -0,0 +1,108 @@
1
+ import { PARTICIPANT_PROFILE_LIMIT } from "@lapis-notes/api/native-turns";
2
+ const unsupported = (message) => {
3
+ throw Object.assign(new Error(message), { code: "UNSUPPORTED" });
4
+ };
5
+ /** Declared choices are presentation data; native policy retains routing authority. */
6
+ export function participantAgents(profiles) {
7
+ const seen = new Set();
8
+ if (profiles.length > PARTICIPANT_PROFILE_LIMIT)
9
+ unsupported("The declared native participant catalog exceeds its limit");
10
+ return profiles.map(({ selection, options, target_id }) => {
11
+ const { recipient, target } = selection;
12
+ if (!target_id ||
13
+ !recipient.id ||
14
+ recipient.id !== target.id ||
15
+ !recipient.label ||
16
+ seen.has(recipient.id))
17
+ unsupported("The declared native participant identity is unavailable");
18
+ seen.add(recipient.id);
19
+ return {
20
+ id: recipient.id,
21
+ name: recipient.label,
22
+ enabled: true,
23
+ description: "",
24
+ provider: target.agent,
25
+ model: target.model?.model ?? "",
26
+ profile: {
27
+ id: recipient.id,
28
+ label: recipient.label,
29
+ agent: target.agent,
30
+ ...(target.model ? { model: target.model.model } : {}),
31
+ executionMode: options.mode,
32
+ thinking: target.thinking ?? selection.thinking ?? "default",
33
+ },
34
+ };
35
+ });
36
+ }
37
+ /** One immutable authored parent and one native request per selected logical role. */
38
+ export function captureNativeParticipants(action, profiles, scope, fallback, head) {
39
+ const text = action.submission?.text.trim();
40
+ const recipients = action.recipients?.length ? action.recipients : [fallback];
41
+ if (!text ||
42
+ text.startsWith("/") ||
43
+ action.submission?.id !== action.id ||
44
+ action.submission.comments.length ||
45
+ action.attachments?.length ||
46
+ action.agentParticipants?.length ||
47
+ (action.values && Object.keys(action.values).length) ||
48
+ recipients.length < 1 ||
49
+ recipients.length > 4 ||
50
+ new Set(recipients).size !== recipients.length)
51
+ unsupported("Native participants accept one plain text message for one to four declared roles");
52
+ const selected = recipients.map((id) => {
53
+ const matches = profiles.filter((p) => p.selection.recipient.id === id);
54
+ if (matches.length !== 1)
55
+ unsupported("The selected native participant profile is unavailable");
56
+ return structuredClone(matches[0]);
57
+ });
58
+ const parent = crypto.randomUUID(), createdAt = new Date().toISOString();
59
+ const saved = selected.map((p) => p.selection.recipient);
60
+ return {
61
+ acceptance_id: crypto.randomUUID(),
62
+ user: {
63
+ schemaVersion: 3,
64
+ id: parent,
65
+ type: "message",
66
+ role: "user",
67
+ text,
68
+ createdAt,
69
+ recipients: saved,
70
+ provenance: { originClass: "owner", sourceKind: "user-message" },
71
+ },
72
+ dispatch: {
73
+ version: 1,
74
+ id: crypto.randomUUID(),
75
+ userEntryId: parent,
76
+ startedAt: createdAt,
77
+ deliveries: saved.map((recipient) => ({
78
+ id: crypto.randomUUID(),
79
+ recipient,
80
+ state: "pending",
81
+ })),
82
+ },
83
+ turns: selected.map((profile) => ({
84
+ request_id: crypto.randomUUID(),
85
+ target_id: profile.target_id,
86
+ scope_dir: scope,
87
+ prompt: text,
88
+ context: null,
89
+ options: structuredClone(profile.options),
90
+ ...(head
91
+ ? {
92
+ continuation: {
93
+ conversation_id: head.conversation_id,
94
+ after_request_id: head.request_id,
95
+ },
96
+ }
97
+ : {}),
98
+ })),
99
+ profiles: selected,
100
+ };
101
+ }
102
+ export function canonicalParticipant(value) {
103
+ return JSON.stringify(value, (_key, next) => next && typeof next === "object" && !Array.isArray(next)
104
+ ? Object.fromEntries(Object.keys(next)
105
+ .sort()
106
+ .map((key) => [key, next[key]]))
107
+ : next);
108
+ }
@@ -0,0 +1,24 @@
1
+ import type { AgentAction } from "@lapismd/agent-ui/core";
2
+ import type { ParticipantCommand, ParticipantMessage, ParticipantProfile, ParticipantValue, TurnSummary } from "@lapis-notes/api/native-turns";
3
+ type Port = {
4
+ readonly hasParticipants: boolean;
5
+ participant(command: ParticipantCommand): Promise<ParticipantValue>;
6
+ };
7
+ /** View-local correlation only. There is no writer, dispatch loop or retry here. */
8
+ export declare class NativeChatParticipantObserver {
9
+ #private;
10
+ readonly session: Port;
11
+ profiles: ParticipantProfile[];
12
+ constructor(session: Port);
13
+ get declared(): boolean;
14
+ get uncertain(): boolean;
15
+ has(head?: TurnSummary): boolean;
16
+ catalog(): Promise<import("@lapismd/agent-ui").AgentProfile[]>;
17
+ read(head?: TurnSummary): Promise<ParticipantMessage | undefined>;
18
+ busy(head?: TurnSummary): boolean;
19
+ stop(head: TurnSummary): Promise<boolean>;
20
+ accept(action: AgentAction, scope: string, fallback: string, head?: TurnSummary): Promise<string>;
21
+ pending(id: string): boolean;
22
+ status(id: string): Promise<string | undefined>;
23
+ }
24
+ export {};