@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.
- package/CHANGELOG.md +6 -0
- package/LICENSE.md +4 -0
- package/README.md +20 -2
- package/dist/index.d.ts +34 -0
- package/dist/index.js +43 -0
- package/dist/local-plugin-distribution.d.ts +3 -0
- package/dist/local-plugin-distribution.js +102 -0
- package/dist/native-chat/NativeChat.svelte +114 -0
- package/dist/native-chat/NativeChat.svelte.d.ts +15 -0
- package/dist/native-chat/conversation.d.ts +10 -0
- package/dist/native-chat/conversation.js +161 -0
- package/dist/native-chat/history.svelte.d.ts +14 -0
- package/dist/native-chat/history.svelte.js +18 -0
- package/dist/native-chat/index.d.ts +6 -0
- package/dist/native-chat/index.js +4 -0
- package/dist/native-chat/metadata.d.ts +14 -0
- package/dist/native-chat/metadata.js +74 -0
- package/dist/native-chat/navigation.d.ts +13 -0
- package/dist/native-chat/navigation.js +55 -0
- package/dist/native-chat/observer.d.ts +28 -0
- package/dist/native-chat/observer.js +343 -0
- package/dist/native-chat/participant-capture.d.ts +7 -0
- package/dist/native-chat/participant-capture.js +108 -0
- package/dist/native-chat/participant-observer.d.ts +24 -0
- package/dist/native-chat/participant-observer.js +125 -0
- package/dist/native-chat/participant-projection.d.ts +9 -0
- package/dist/native-chat/participant-projection.js +116 -0
- package/dist/native-chat/plugin.d.ts +5 -0
- package/dist/native-chat/plugin.js +60 -0
- package/dist/native-chat/queue-capture.d.ts +57 -0
- package/dist/native-chat/queue-capture.js +41 -0
- package/dist/native-chat/queue-observer.d.ts +16 -0
- package/dist/native-chat/queue-observer.js +190 -0
- package/dist/native-chat/queue-receipt.d.ts +3 -0
- package/dist/native-chat/queue-receipt.js +36 -0
- package/dist/native-chat/send.d.ts +11 -0
- package/dist/native-chat/send.js +42 -0
- package/dist/native-chat/session.d.ts +32 -0
- package/dist/native-chat/session.js +82 -0
- package/dist/native-chat/view.d.ts +20 -0
- package/dist/native-chat/view.js +90 -0
- package/dist/native-repository.d.ts +7 -0
- package/dist/native-repository.js +26 -0
- package/dist/plugin-browser.d.ts +3 -0
- package/dist/plugin-browser.js +55 -0
- package/dist/plugin-host-build.d.ts +12 -0
- package/dist/plugin-host-build.js +88 -0
- package/dist/workspace-session/NotesWorkspaceSession.svelte +261 -0
- package/dist/workspace-session/NotesWorkspaceSession.svelte.d.ts +8 -0
- package/dist/workspace-session/application.d.ts +9 -0
- package/dist/workspace-session/application.js +47 -0
- package/dist/workspace-session/database-status.d.ts +2 -0
- package/dist/workspace-session/database-status.js +37 -0
- package/dist/workspace-session/index.d.ts +2 -0
- package/dist/workspace-session/index.js +1 -0
- package/dist/workspace-session/leave.d.ts +9 -0
- package/dist/workspace-session/leave.js +25 -0
- package/dist/workspace-session/lifecycle.d.ts +14 -0
- package/dist/workspace-session/lifecycle.js +83 -0
- package/dist/workspace-session/types.d.ts +33 -0
- package/dist/workspace-session/types.js +1 -0
- package/package.json +98 -3
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Lapis Notes application profile
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared application composition for Lapis Notes hosts. The package owns the four
|
|
4
|
+
optional core plugins, plugin settings and browser, native Chat observation, and
|
|
5
|
+
the complete Notes workspace session. Hosts own credentials, storage, transport,
|
|
6
|
+
permissions and platform lifecycle.
|
|
7
|
+
|
|
8
|
+
Import `NotesWorkspaceSession` and its props/imperative handle from
|
|
9
|
+
`@lapis-notes/app-profile/workspace-session`. Supply an owned `VaultSession`,
|
|
10
|
+
profile, runtime, vault navigation callbacks, and optional native Chat/Repository
|
|
11
|
+
factories. Browser-only policy is injected through `NotesWorkspaceHost`.
|
|
12
|
+
|
|
13
|
+
The session loads vault/configuration/plugins/layout in order, provides Retry,
|
|
14
|
+
mounts the public `WorkspaceShell`, and protects registered writers before
|
|
15
|
+
persisting or closing. Call and await `dispose()` before replacing its session.
|
|
16
|
+
A refused leave retains the live application and permits an explicit retry.
|
|
17
|
+
A host may supply `host.dispose(app)` to close attachments after the session;
|
|
18
|
+
the compatibility lease remains installed until that awaited cleanup succeeds.
|
|
19
|
+
|
|
20
|
+
Other public entries are the default profile, `plugin-host-build`, `native-chat`
|
|
21
|
+
and `native-repository`. Every entry resolves built package output.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MarkdownPlugin } from "@lapis-notes/markdown";
|
|
2
|
+
import { SearchPlugin } from "@lapis-notes/search";
|
|
3
|
+
import { SourceEditorPlugin } from "@lapis-notes/source-editor";
|
|
4
|
+
import { registerPluginManagementSettings } from "@lapis-notes/workspace";
|
|
5
|
+
export * from "./local-plugin-distribution";
|
|
6
|
+
export { registerNotesPluginBrowser } from "./plugin-browser";
|
|
7
|
+
export declare const registerNotesPluginSettings: typeof registerPluginManagementSettings;
|
|
8
|
+
/**
|
|
9
|
+
* The application-owned default plugin profile shared by every Lapis Notes
|
|
10
|
+
* host.
|
|
11
|
+
*
|
|
12
|
+
* Plugins remain optional so a user can disable each one. CSS is registered as
|
|
13
|
+
* lifecycle-owned text instead of being imported by either host globally.
|
|
14
|
+
*/
|
|
15
|
+
export declare const notesPluginProfile: readonly [{
|
|
16
|
+
readonly plugin: typeof SourceEditorPlugin;
|
|
17
|
+
readonly required: false;
|
|
18
|
+
readonly enabledByDefault: true;
|
|
19
|
+
readonly styles: string;
|
|
20
|
+
}, {
|
|
21
|
+
readonly plugin: typeof MarkdownPlugin;
|
|
22
|
+
readonly required: false;
|
|
23
|
+
readonly enabledByDefault: true;
|
|
24
|
+
readonly styles: string;
|
|
25
|
+
}, {
|
|
26
|
+
readonly plugin: import("@lapis-notes/api").PluginConstructor;
|
|
27
|
+
readonly required: false;
|
|
28
|
+
readonly enabledByDefault: true;
|
|
29
|
+
}, {
|
|
30
|
+
readonly plugin: typeof SearchPlugin;
|
|
31
|
+
readonly required: false;
|
|
32
|
+
readonly enabledByDefault: true;
|
|
33
|
+
readonly styles: string;
|
|
34
|
+
}];
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FileExplorerPlugin } from "@lapis-notes/file-explorer";
|
|
2
|
+
import { MarkdownPlugin } from "@lapis-notes/markdown";
|
|
3
|
+
import markdownStyles from "@lapis-notes/markdown/styles.css?inline";
|
|
4
|
+
import { SearchPlugin } from "@lapis-notes/search";
|
|
5
|
+
import searchStyles from "@lapis-notes/search/styles.css?inline";
|
|
6
|
+
import { SourceEditorPlugin } from "@lapis-notes/source-editor";
|
|
7
|
+
import sourceEditorStyles from "@lapis-notes/source-editor/styles.css?inline";
|
|
8
|
+
import { registerPluginManagementSettings } from "@lapis-notes/workspace";
|
|
9
|
+
export * from "./local-plugin-distribution";
|
|
10
|
+
export { registerNotesPluginBrowser } from "./plugin-browser";
|
|
11
|
+
export const registerNotesPluginSettings = registerPluginManagementSettings;
|
|
12
|
+
/**
|
|
13
|
+
* The application-owned default plugin profile shared by every Lapis Notes
|
|
14
|
+
* host.
|
|
15
|
+
*
|
|
16
|
+
* Plugins remain optional so a user can disable each one. CSS is registered as
|
|
17
|
+
* lifecycle-owned text instead of being imported by either host globally.
|
|
18
|
+
*/
|
|
19
|
+
export const notesPluginProfile = [
|
|
20
|
+
{
|
|
21
|
+
plugin: SourceEditorPlugin,
|
|
22
|
+
required: false,
|
|
23
|
+
enabledByDefault: true,
|
|
24
|
+
styles: sourceEditorStyles,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
plugin: MarkdownPlugin,
|
|
28
|
+
required: false,
|
|
29
|
+
enabledByDefault: true,
|
|
30
|
+
styles: markdownStyles,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
plugin: FileExplorerPlugin,
|
|
34
|
+
required: false,
|
|
35
|
+
enabledByDefault: true,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
plugin: SearchPlugin,
|
|
39
|
+
required: false,
|
|
40
|
+
enabledByDefault: true,
|
|
41
|
+
styles: searchStyles,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AppPluginDistributionOptions } from "@lapis-notes/api";
|
|
2
|
+
/** Test-only trust and transport configuration; normal release builds ignore it. */
|
|
3
|
+
export declare function createConfiguredNotesLocalPluginDistribution(environment: Record<string, string | boolean | undefined>, explicit?: AppPluginDistributionOptions): AppPluginDistributionOptions | undefined;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/** Test-only trust and transport configuration; normal release builds ignore it. */
|
|
2
|
+
export function createConfiguredNotesLocalPluginDistribution(environment, explicit) {
|
|
3
|
+
if (explicit !== undefined)
|
|
4
|
+
return explicit;
|
|
5
|
+
if (environment.MODE === "production" || environment.MODE === "server") {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
if (environment.DEV !== true && environment.MODE !== "registry-acceptance") {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
const catalog = stringValue(environment.VITE_LAPIS_LOCAL_REGISTRY_URL);
|
|
12
|
+
const origin = stringValue(environment.VITE_LAPIS_LOCAL_REGISTRY_ARTIFACT_ORIGIN);
|
|
13
|
+
const keys = stringValue(environment.VITE_LAPIS_LOCAL_REGISTRY_TRUSTED_KEYS);
|
|
14
|
+
if (!catalog && !origin && !keys)
|
|
15
|
+
return undefined;
|
|
16
|
+
if (!catalog || !origin || !keys) {
|
|
17
|
+
throw new Error("Local registry URL, artifact origin and public keys must be configured together.");
|
|
18
|
+
}
|
|
19
|
+
const transport = publicUrl(catalog, "Local registry requires a loopback catalog URL.");
|
|
20
|
+
if (!["http:", "https:"].includes(transport.protocol) ||
|
|
21
|
+
!["127.0.0.1", "localhost", "[::1]"].includes(transport.hostname) ||
|
|
22
|
+
transport.search !== "" ||
|
|
23
|
+
!transport.pathname.endsWith("/index.json")) {
|
|
24
|
+
throw new Error("Local registry requires a loopback catalog URL.");
|
|
25
|
+
}
|
|
26
|
+
const artifactOrigin = publicUrl(origin, "Local registry artifacts require an exact HTTPS origin.");
|
|
27
|
+
if (artifactOrigin.protocol !== "https:" ||
|
|
28
|
+
artifactOrigin.pathname !== "/" ||
|
|
29
|
+
artifactOrigin.search !== "") {
|
|
30
|
+
throw new Error("Local registry artifacts require an exact HTTPS origin.");
|
|
31
|
+
}
|
|
32
|
+
const trustedKeys = publicKeys(keys);
|
|
33
|
+
const fetch = globalThis.fetch.bind(globalThis);
|
|
34
|
+
return {
|
|
35
|
+
registries: [
|
|
36
|
+
{
|
|
37
|
+
id: "lapis-local",
|
|
38
|
+
name: "Local plugin release fixture",
|
|
39
|
+
kind: "http",
|
|
40
|
+
url: transport.href,
|
|
41
|
+
trustTier: "official",
|
|
42
|
+
enabled: true,
|
|
43
|
+
builtin: true,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
trustedKeys,
|
|
47
|
+
fetch: (url, init) => {
|
|
48
|
+
const requested = new URL(url);
|
|
49
|
+
const target = requested.origin === artifactOrigin.origin
|
|
50
|
+
? new URL(requested.pathname + requested.search, transport.origin)
|
|
51
|
+
.href
|
|
52
|
+
: url;
|
|
53
|
+
return fetch(target, init);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function stringValue(value) {
|
|
58
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
59
|
+
}
|
|
60
|
+
function publicUrl(value, message) {
|
|
61
|
+
let url;
|
|
62
|
+
try {
|
|
63
|
+
url = new URL(value);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
throw new Error(message);
|
|
67
|
+
}
|
|
68
|
+
if (url.username || url.password || url.hash)
|
|
69
|
+
throw new Error(message);
|
|
70
|
+
return url;
|
|
71
|
+
}
|
|
72
|
+
function publicKeys(value) {
|
|
73
|
+
const message = "Local registry requires unique, valid public signing keys.";
|
|
74
|
+
let parsed;
|
|
75
|
+
try {
|
|
76
|
+
parsed = JSON.parse(value);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
throw new Error(message);
|
|
80
|
+
}
|
|
81
|
+
if (!Array.isArray(parsed) || parsed.length === 0)
|
|
82
|
+
throw new Error(message);
|
|
83
|
+
const ids = new Set();
|
|
84
|
+
const allowed = new Set(["keyId", "alg", "publicKey", "trustTier"]);
|
|
85
|
+
for (const entry of parsed) {
|
|
86
|
+
if (!entry ||
|
|
87
|
+
typeof entry !== "object" ||
|
|
88
|
+
Array.isArray(entry) ||
|
|
89
|
+
Object.keys(entry).some((key) => !allowed.has(key)) ||
|
|
90
|
+
typeof entry.keyId !== "string" ||
|
|
91
|
+
!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(entry.keyId) ||
|
|
92
|
+
ids.has(entry.keyId) ||
|
|
93
|
+
entry.alg !== "ed25519" ||
|
|
94
|
+
typeof entry.publicKey !== "string" ||
|
|
95
|
+
!/^[A-Za-z0-9+/]{43}=$/u.test(entry.publicKey) ||
|
|
96
|
+
!["official", "community", "local"].includes(entry.trustTier)) {
|
|
97
|
+
throw new Error(message);
|
|
98
|
+
}
|
|
99
|
+
ids.add(entry.keyId);
|
|
100
|
+
}
|
|
101
|
+
return parsed;
|
|
102
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy, onMount, untrack } from "svelte";
|
|
3
|
+
import { AgentUiController } from "@lapismd/agent-ui/core";
|
|
4
|
+
import { AgentChatScreen } from "@lapismd/agent-ui/chat";
|
|
5
|
+
import { AgentHistoryScreen } from "@lapismd/agent-ui/screens";
|
|
6
|
+
import { NativeChatObserver } from "./observer";
|
|
7
|
+
import type { NativeChatSession } from "./session";
|
|
8
|
+
import { NativeChatHistory } from "./history.svelte";
|
|
9
|
+
import type { NativeChatLocation } from "./navigation";
|
|
10
|
+
let {
|
|
11
|
+
session,
|
|
12
|
+
initialSession,
|
|
13
|
+
initialScope,
|
|
14
|
+
screen = "chat",
|
|
15
|
+
onSelection,
|
|
16
|
+
onHistory,
|
|
17
|
+
onConversation,
|
|
18
|
+
onDispose,
|
|
19
|
+
}: {
|
|
20
|
+
session: NativeChatSession;
|
|
21
|
+
initialSession?: string;
|
|
22
|
+
initialScope?: string;
|
|
23
|
+
screen?: "chat" | "history";
|
|
24
|
+
onSelection?(id: string, scope: string): void;
|
|
25
|
+
onHistory?(): Promise<void>;
|
|
26
|
+
onConversation?(location: NativeChatLocation): Promise<void>;
|
|
27
|
+
onDispose?(pending: Promise<void>): void;
|
|
28
|
+
} = $props();
|
|
29
|
+
const port = untrack(
|
|
30
|
+
() =>
|
|
31
|
+
new NativeChatObserver(session, {
|
|
32
|
+
initialSession,
|
|
33
|
+
initialScope,
|
|
34
|
+
target: () => controller.selectedAgent,
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
const controller: AgentUiController = untrack(
|
|
38
|
+
() =>
|
|
39
|
+
new AgentUiController(port, undefined, {
|
|
40
|
+
canComment: () => false,
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
untrack(() => {
|
|
44
|
+
controller.screen = screen;
|
|
45
|
+
});
|
|
46
|
+
const history = untrack(
|
|
47
|
+
() =>
|
|
48
|
+
new NativeChatHistory(
|
|
49
|
+
() => controller,
|
|
50
|
+
async (location) => {
|
|
51
|
+
try {
|
|
52
|
+
if (onConversation) await onConversation(location);
|
|
53
|
+
else if (location.conversationId)
|
|
54
|
+
controller.selectSession(location.conversationId);
|
|
55
|
+
else await controller.action("new_session");
|
|
56
|
+
} catch (error) {
|
|
57
|
+
session.report(error as Error);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
$effect(() => {
|
|
63
|
+
if (screen === "chat" && controller.screen === "history" && onHistory) {
|
|
64
|
+
controller.screen = "chat";
|
|
65
|
+
void untrack(onHistory).catch((error) => session.report(error as Error));
|
|
66
|
+
}
|
|
67
|
+
history.syncScope();
|
|
68
|
+
});
|
|
69
|
+
let previous = "";
|
|
70
|
+
$effect(() => {
|
|
71
|
+
const snapshot = controller.snapshot;
|
|
72
|
+
if (!snapshot) return;
|
|
73
|
+
untrack(() => {
|
|
74
|
+
controller.sessionId = port.selected;
|
|
75
|
+
if (previous !== port.selected || !controller.selectedAgent) {
|
|
76
|
+
controller.selectedAgent =
|
|
77
|
+
snapshot.agents.find(
|
|
78
|
+
(agent) => agent.id === controller.session?.agent,
|
|
79
|
+
)?.id || snapshot.agents[0]?.id || "";
|
|
80
|
+
previous = port.selected;
|
|
81
|
+
onSelection?.(
|
|
82
|
+
port.selected,
|
|
83
|
+
controller.session?.scope ?? initialScope ?? "",
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
onMount(() => {
|
|
89
|
+
void controller.refresh();
|
|
90
|
+
});
|
|
91
|
+
onDestroy(() => {
|
|
92
|
+
port.close();
|
|
93
|
+
onDispose?.(controller.close());
|
|
94
|
+
});
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
<div class="native-chat" data-testid="ai-chat-panel" data-native-chat="true">
|
|
98
|
+
{#if controller.screen === "history"}
|
|
99
|
+
<AgentHistoryScreen {history} />
|
|
100
|
+
{:else}
|
|
101
|
+
<AgentChatScreen {controller} />
|
|
102
|
+
{/if}
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<style>
|
|
106
|
+
.native-chat {
|
|
107
|
+
display: flex;
|
|
108
|
+
flex: 1;
|
|
109
|
+
width: 100%;
|
|
110
|
+
height: 100%;
|
|
111
|
+
min-width: 0;
|
|
112
|
+
min-height: 0;
|
|
113
|
+
}
|
|
114
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NativeChatSession } from "./session";
|
|
2
|
+
import type { NativeChatLocation } from "./navigation";
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
session: NativeChatSession;
|
|
5
|
+
initialSession?: string;
|
|
6
|
+
initialScope?: string;
|
|
7
|
+
screen?: "chat" | "history";
|
|
8
|
+
onSelection?(id: string, scope: string): void;
|
|
9
|
+
onHistory?(): Promise<void>;
|
|
10
|
+
onConversation?(location: NativeChatLocation): Promise<void>;
|
|
11
|
+
onDispose?(pending: Promise<void>): void;
|
|
12
|
+
};
|
|
13
|
+
declare const NativeChat: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
14
|
+
type NativeChat = ReturnType<typeof NativeChat>;
|
|
15
|
+
export default NativeChat;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TranscriptItem } from "@lapismd/design-core/chat";
|
|
2
|
+
import type { ParticipantMessage, TurnRecord, TurnSummary } from "@lapis-notes/api/native-turns";
|
|
3
|
+
import type { NativeChatSession } from "./session";
|
|
4
|
+
export declare const active: (phase: TurnSummary["phase"]) => phase is "accepted" | "running";
|
|
5
|
+
export declare function directory(record: TurnSummary): string;
|
|
6
|
+
export declare function conversation(session: NativeChatSession, summary: TurnSummary, record: TurnRecord, participants?: ParticipantMessage): Promise<{
|
|
7
|
+
title: string;
|
|
8
|
+
items: TranscriptItem[];
|
|
9
|
+
status: "archived" | "active";
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { queueReceiptItem } from "./queue-receipt";
|
|
2
|
+
import { participantEntries, participantLabels, participantReceiptItem, } from "./participant-projection";
|
|
3
|
+
export const active = (phase) => phase === "accepted" || phase === "running";
|
|
4
|
+
export function directory(record) {
|
|
5
|
+
if (!/^[0-9a-f-]{36}$/i.test(record.conversation_id) ||
|
|
6
|
+
record.scope_dir.startsWith("/") ||
|
|
7
|
+
record.scope_dir
|
|
8
|
+
.split("/")
|
|
9
|
+
.some((part) => part === "." || part === ".." || part.includes("\\")))
|
|
10
|
+
throw new Error("The native conversation scope is invalid");
|
|
11
|
+
return [record.scope_dir, ".lapis/agents/sessions", record.conversation_id]
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.join("/");
|
|
14
|
+
}
|
|
15
|
+
function blockRevision(text) {
|
|
16
|
+
// Presentation key only. It is never a file version, receipt or write authority.
|
|
17
|
+
let hash = 2166136261;
|
|
18
|
+
for (let i = 0; i < text.length; i++)
|
|
19
|
+
hash = Math.imul(hash ^ text.charCodeAt(i), 16777619);
|
|
20
|
+
return (hash >>> 0).toString(16);
|
|
21
|
+
}
|
|
22
|
+
function item(value, labels) {
|
|
23
|
+
if (value.schemaVersion !== 3)
|
|
24
|
+
throw new Error("This saved conversation format is unavailable");
|
|
25
|
+
if (value.type === "queue.outcome")
|
|
26
|
+
return queueReceiptItem(value, blockRevision);
|
|
27
|
+
if (value.type === "agent.delivery")
|
|
28
|
+
return participantReceiptItem(value, blockRevision);
|
|
29
|
+
if (value.type !== "message")
|
|
30
|
+
return;
|
|
31
|
+
if (typeof value.id !== "string" ||
|
|
32
|
+
typeof value.text !== "string" ||
|
|
33
|
+
(value.role !== "user" && value.role !== "assistant"))
|
|
34
|
+
throw new Error("This saved conversation cannot be displayed");
|
|
35
|
+
const role = value.role;
|
|
36
|
+
return {
|
|
37
|
+
id: value.id,
|
|
38
|
+
kind: "message",
|
|
39
|
+
role,
|
|
40
|
+
label: role === "user"
|
|
41
|
+
? "You"
|
|
42
|
+
: (labels.get(String(value.agentBindingId)) ?? "Agent"),
|
|
43
|
+
createdAt: typeof value.createdAt === "string" ? value.createdAt : undefined,
|
|
44
|
+
blocks: [
|
|
45
|
+
{
|
|
46
|
+
id: `${value.id}:body`,
|
|
47
|
+
revision: blockRevision(value.text),
|
|
48
|
+
kind: "markdown",
|
|
49
|
+
label: "Message",
|
|
50
|
+
text: value.text,
|
|
51
|
+
commentable: false,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export async function conversation(session, summary, record, participants) {
|
|
57
|
+
let metadata, values;
|
|
58
|
+
try {
|
|
59
|
+
const root = directory(summary);
|
|
60
|
+
const [meta, transcript] = await Promise.all([
|
|
61
|
+
session.readText(`${root}/metadata.yaml`),
|
|
62
|
+
session.readText(`${root}/transcript.jsonl`),
|
|
63
|
+
]);
|
|
64
|
+
metadata = JSON.parse(meta);
|
|
65
|
+
values = transcript
|
|
66
|
+
.split("\n")
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.map((line) => JSON.parse(line));
|
|
69
|
+
if (metadata.schemaVersion !== 3 || metadata.id !== summary.conversation_id)
|
|
70
|
+
throw new Error("This saved conversation cannot be displayed");
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
const code = error.code;
|
|
74
|
+
if (!active(record.phase) ||
|
|
75
|
+
record.input.continuation ||
|
|
76
|
+
!["ENOENT", "NOT_FOUND"].includes(code ?? ""))
|
|
77
|
+
throw error;
|
|
78
|
+
// A freshly accepted journal can precede its portable files; only observe it.
|
|
79
|
+
metadata = {};
|
|
80
|
+
values = participants
|
|
81
|
+
? []
|
|
82
|
+
: [
|
|
83
|
+
{
|
|
84
|
+
schemaVersion: 3,
|
|
85
|
+
type: "message",
|
|
86
|
+
id: record.input.request_id,
|
|
87
|
+
role: "user",
|
|
88
|
+
text: record.input.prompt,
|
|
89
|
+
},
|
|
90
|
+
...(record.output
|
|
91
|
+
? [
|
|
92
|
+
{
|
|
93
|
+
schemaVersion: 3,
|
|
94
|
+
type: "message",
|
|
95
|
+
id: `${record.input.request_id}:reply`,
|
|
96
|
+
role: "assistant",
|
|
97
|
+
text: record.output,
|
|
98
|
+
},
|
|
99
|
+
]
|
|
100
|
+
: []),
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
let labels = participantLabels([], participants);
|
|
104
|
+
if (participants || values.some((value) => value.type === "agent.delivery")) {
|
|
105
|
+
try {
|
|
106
|
+
const bindings = await session.readText(`${directory(summary)}/agents.jsonl`);
|
|
107
|
+
labels = participantLabels(bindings
|
|
108
|
+
.split("\n")
|
|
109
|
+
.filter(Boolean)
|
|
110
|
+
.map((line) => JSON.parse(line)), participants);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (!participants ||
|
|
114
|
+
record.input.continuation ||
|
|
115
|
+
!active(record.phase) ||
|
|
116
|
+
!["ENOENT", "NOT_FOUND"].includes(error.code ?? ""))
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const items = participantEntries(values, participants).flatMap((value) => {
|
|
121
|
+
const next = item(value, labels);
|
|
122
|
+
return next ? [next] : [];
|
|
123
|
+
});
|
|
124
|
+
if (!participants &&
|
|
125
|
+
["failed", "unknown", "interrupted", "cancelled"].includes(record.phase)) {
|
|
126
|
+
const text = record.phase === "cancelled"
|
|
127
|
+
? "This turn was cancelled."
|
|
128
|
+
: record.phase === "failed"
|
|
129
|
+
? "This turn did not complete. Your saved conversation is retained."
|
|
130
|
+
: "This turn has an uncertain outcome. It will not be replayed automatically.";
|
|
131
|
+
items.push({
|
|
132
|
+
id: `${record.input.request_id}:outcome`,
|
|
133
|
+
kind: "context",
|
|
134
|
+
label: "Turn status",
|
|
135
|
+
notice: record.phase === "failed" ? "error" : "warning",
|
|
136
|
+
blocks: [
|
|
137
|
+
{
|
|
138
|
+
id: `${record.input.request_id}:status`,
|
|
139
|
+
revision: record.phase,
|
|
140
|
+
kind: "markdown",
|
|
141
|
+
label: "Status",
|
|
142
|
+
text,
|
|
143
|
+
commentable: false,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const title = typeof metadata.title === "string" && metadata.title.trim()
|
|
149
|
+
? metadata.title
|
|
150
|
+
: Array.from(items.find((i) => i.role === "user")?.blocks[0]?.text ??
|
|
151
|
+
"Conversation")
|
|
152
|
+
.slice(0, 96)
|
|
153
|
+
.join("");
|
|
154
|
+
return {
|
|
155
|
+
title,
|
|
156
|
+
items,
|
|
157
|
+
status: metadata.status === "archived"
|
|
158
|
+
? "archived"
|
|
159
|
+
: "active",
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AgentHistoryController } from "@lapismd/agent-ui";
|
|
2
|
+
import type { AgentUiController } from "@lapismd/agent-ui/core";
|
|
3
|
+
import type { NativeChatLocation } from "./navigation";
|
|
4
|
+
/** The public History screen retains its own selection while the App opens chats. */
|
|
5
|
+
export declare class NativeChatHistory extends AgentHistoryController {
|
|
6
|
+
readonly open: (location: NativeChatLocation) => Promise<void>;
|
|
7
|
+
constructor(owner: () => AgentUiController, open: (location: NativeChatLocation) => Promise<void>);
|
|
8
|
+
get entries(): import("node_modules/@lapismd/agent-ui/dist/history/models").ConversationListEntry[];
|
|
9
|
+
openConversation(location: {
|
|
10
|
+
scopeDir: string;
|
|
11
|
+
conversationId: string;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
newConversation(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AgentHistoryController } from "@lapismd/agent-ui";
|
|
2
|
+
/** The public History screen retains its own selection while the App opens chats. */
|
|
3
|
+
export class NativeChatHistory extends AgentHistoryController {
|
|
4
|
+
open;
|
|
5
|
+
constructor(owner, open) {
|
|
6
|
+
super(owner);
|
|
7
|
+
this.open = open;
|
|
8
|
+
}
|
|
9
|
+
get entries() {
|
|
10
|
+
return super.entries.filter((entry) => !entry.location.conversationId.startsWith("draft:"));
|
|
11
|
+
}
|
|
12
|
+
async openConversation(location) {
|
|
13
|
+
await this.open(location);
|
|
14
|
+
}
|
|
15
|
+
async newConversation() {
|
|
16
|
+
await this.open({ scopeDir: this.selectedScope });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as NativeChat } from "./NativeChat.svelte";
|
|
2
|
+
export { createNativeChatPlugin, prepareNativeChatLeave } from "./plugin";
|
|
3
|
+
export { NativeChatSession } from "./session";
|
|
4
|
+
export type { NativeChatHost, NativeChatLeave, NativeChatQueue, } from "./session";
|
|
5
|
+
export { NativeChatObserver } from "./observer";
|
|
6
|
+
export type { NativeQueueSelection } from "./queue-capture";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TurnSummary } from "@lapis-notes/api/native-turns";
|
|
2
|
+
import type { NativeChatSession } from "./session";
|
|
3
|
+
type Metadata = {
|
|
4
|
+
title: string;
|
|
5
|
+
status: "active" | "archived";
|
|
6
|
+
};
|
|
7
|
+
/** Bounded read-only metadata projection, never a transcript or job owner. */
|
|
8
|
+
export declare class NativeChatMetadata {
|
|
9
|
+
#private;
|
|
10
|
+
readonly session: NativeChatSession;
|
|
11
|
+
constructor(session: NativeChatSession);
|
|
12
|
+
read(heads: TurnSummary[], firsts: Map<string, TurnSummary>): Promise<Map<string, Metadata>>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { active, directory } from "./conversation";
|
|
2
|
+
/** Bounded read-only metadata projection, never a transcript or job owner. */
|
|
3
|
+
export class NativeChatMetadata {
|
|
4
|
+
session;
|
|
5
|
+
#cache = new Map();
|
|
6
|
+
#titles = new Map();
|
|
7
|
+
constructor(session) {
|
|
8
|
+
this.session = session;
|
|
9
|
+
}
|
|
10
|
+
async #title(first) {
|
|
11
|
+
const cached = this.#titles.get(first.request_id);
|
|
12
|
+
if (cached)
|
|
13
|
+
return cached;
|
|
14
|
+
const value = await this.session.call({
|
|
15
|
+
kind: "read",
|
|
16
|
+
request_id: first.request_id,
|
|
17
|
+
});
|
|
18
|
+
if (value.kind !== "record" ||
|
|
19
|
+
!value.record ||
|
|
20
|
+
value.record.conversation_id !== first.conversation_id ||
|
|
21
|
+
value.record.input.scope_dir !== first.scope_dir)
|
|
22
|
+
throw new Error("This saved conversation cannot be displayed");
|
|
23
|
+
const title = Array.from(value.record.input.prompt).slice(0, 96).join("") ||
|
|
24
|
+
"Conversation";
|
|
25
|
+
this.#titles.set(first.request_id, title);
|
|
26
|
+
return title;
|
|
27
|
+
}
|
|
28
|
+
async read(heads, firsts) {
|
|
29
|
+
const result = new Map();
|
|
30
|
+
for (let offset = 0; offset < heads.length; offset += 16) {
|
|
31
|
+
await Promise.all(heads.slice(offset, offset + 16).map(async (head) => {
|
|
32
|
+
const revision = `${head.request_id}:${head.updated_at_ms}:${head.phase}`;
|
|
33
|
+
const cached = this.#cache.get(head.conversation_id);
|
|
34
|
+
if (cached?.revision === revision && cached.expires > Date.now()) {
|
|
35
|
+
result.set(head.conversation_id, cached.value);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const metadata = JSON.parse(await this.session.readText(`${directory(head)}/metadata.yaml`));
|
|
40
|
+
if (metadata.schemaVersion !== 3 ||
|
|
41
|
+
metadata.id !== head.conversation_id ||
|
|
42
|
+
(metadata.title !== undefined &&
|
|
43
|
+
typeof metadata.title !== "string"))
|
|
44
|
+
throw new Error("This saved conversation cannot be displayed");
|
|
45
|
+
const value = {
|
|
46
|
+
title: metadata.title?.trim() ||
|
|
47
|
+
(await this.#title(firsts.get(head.conversation_id))),
|
|
48
|
+
status: metadata.status === "archived" ? "archived" : "active",
|
|
49
|
+
};
|
|
50
|
+
this.#cache.set(head.conversation_id, {
|
|
51
|
+
revision,
|
|
52
|
+
expires: Date.now() + 2000,
|
|
53
|
+
value,
|
|
54
|
+
});
|
|
55
|
+
result.set(head.conversation_id, value);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (!active(head.phase) ||
|
|
59
|
+
!["ENOENT", "NOT_FOUND"].includes(error.code ?? ""))
|
|
60
|
+
throw error;
|
|
61
|
+
// First publication can follow journal acceptance. Retry on the next read.
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
for (const id of this.#cache.keys())
|
|
66
|
+
if (!result.has(id))
|
|
67
|
+
this.#cache.delete(id);
|
|
68
|
+
const retained = new Set([...firsts.values()].map((first) => first.request_id));
|
|
69
|
+
for (const id of this.#titles.keys())
|
|
70
|
+
if (!retained.has(id))
|
|
71
|
+
this.#titles.delete(id);
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
}
|