@lapis-notes/ai 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 +8 -0
- package/README.md +20 -0
- package/dist/ai-plugin.d.ts +88 -0
- package/dist/ai-plugin.js +742 -0
- package/dist/bootstrap/build.d.ts +15 -0
- package/dist/bootstrap/build.js +28 -0
- package/dist/bootstrap/folder-instructions.d.ts +4 -0
- package/dist/bootstrap/folder-instructions.js +49 -0
- package/dist/bootstrap/format.d.ts +2 -0
- package/dist/bootstrap/format.js +46 -0
- package/dist/bootstrap/instructions.d.ts +1 -0
- package/dist/bootstrap/instructions.js +8 -0
- package/dist/bootstrap/types.d.ts +36 -0
- package/dist/bootstrap/types.js +3 -0
- package/dist/catalog/ai-catalog-panel.svelte +742 -0
- package/dist/catalog/ai-catalog-panel.svelte.d.ts +13 -0
- package/dist/catalog/ai-catalog-view-type.d.ts +1 -0
- package/dist/catalog/ai-catalog-view-type.js +1 -0
- package/dist/catalog/ai-catalog-view.d.ts +22 -0
- package/dist/catalog/ai-catalog-view.js +48 -0
- package/dist/catalog/filter.d.ts +3 -0
- package/dist/catalog/filter.js +24 -0
- package/dist/catalog/inventory.d.ts +21 -0
- package/dist/catalog/inventory.js +255 -0
- package/dist/catalog/tree.d.ts +12 -0
- package/dist/catalog/tree.js +60 -0
- package/dist/catalog/types.d.ts +44 -0
- package/dist/catalog/types.js +1 -0
- package/dist/chat/ai-approval-card.svelte +54 -0
- package/dist/chat/ai-approval-card.svelte.d.ts +9 -0
- package/dist/chat/ai-chat-panel.svelte +1288 -0
- package/dist/chat/ai-chat-panel.svelte.d.ts +50 -0
- package/dist/chat/ai-inventory-result.css +55 -0
- package/dist/chat/ai-inventory-result.svelte +63 -0
- package/dist/chat/ai-inventory-result.svelte.d.ts +5 -0
- package/dist/chat/ai-question-card.svelte +132 -0
- package/dist/chat/ai-question-card.svelte.d.ts +9 -0
- package/dist/chat/ai-view-bootstrap.d.ts +13 -0
- package/dist/chat/ai-view-bootstrap.js +86 -0
- package/dist/chat/ai-view-panel.svelte +89 -0
- package/dist/chat/ai-view-panel.svelte.d.ts +13 -0
- package/dist/chat/ai-view-type.d.ts +1 -0
- package/dist/chat/ai-view-type.js +1 -0
- package/dist/chat/ai-view.d.ts +60 -0
- package/dist/chat/ai-view.js +121 -0
- package/dist/chat/chat-controller.svelte.d.ts +82 -0
- package/dist/chat/chat-controller.svelte.js +1926 -0
- package/dist/chat/chat-items.d.ts +88 -0
- package/dist/chat/chat-items.js +9 -0
- package/dist/chat/chat-mentions.d.ts +15 -0
- package/dist/chat/chat-mentions.js +77 -0
- package/dist/chat/chat-result-views.d.ts +5 -0
- package/dist/chat/chat-result-views.js +15 -0
- package/dist/chat/chat-session.d.ts +28 -0
- package/dist/chat/chat-session.js +50 -0
- package/dist/chat/chat-status.d.ts +1 -0
- package/dist/chat/chat-status.js +3 -0
- package/dist/chat/chat-time.d.ts +18 -0
- package/dist/chat/chat-time.js +90 -0
- package/dist/chat/chat-tool-display.d.ts +17 -0
- package/dist/chat/chat-tool-display.js +213 -0
- package/dist/chat/chat-tool-identity.d.ts +4 -0
- package/dist/chat/chat-tool-identity.js +42 -0
- package/dist/chat/chat-trace.d.ts +6 -0
- package/dist/chat/chat-trace.js +256 -0
- package/dist/chat/live-runtime-unavailable.d.ts +1 -0
- package/dist/chat/live-runtime-unavailable.js +1 -0
- package/dist/commands/agent.d.ts +8 -0
- package/dist/commands/agent.js +38 -0
- package/dist/commands/catalog.d.ts +18 -0
- package/dist/commands/catalog.js +115 -0
- package/dist/commands/discovery.d.ts +36 -0
- package/dist/commands/discovery.js +151 -0
- package/dist/commands/groups.d.ts +16 -0
- package/dist/commands/groups.js +121 -0
- package/dist/commands/inspect.d.ts +18 -0
- package/dist/commands/inspect.js +29 -0
- package/dist/commands/markdown.d.ts +21 -0
- package/dist/commands/markdown.js +117 -0
- package/dist/commands/parser.d.ts +4 -0
- package/dist/commands/parser.js +24 -0
- package/dist/commands/reserved.d.ts +4 -0
- package/dist/commands/reserved.js +107 -0
- package/dist/commands/router.d.ts +17 -0
- package/dist/commands/router.js +170 -0
- package/dist/commands/seed.d.ts +4 -0
- package/dist/commands/seed.js +8 -0
- package/dist/commands/types.d.ts +54 -0
- package/dist/commands/types.js +1 -0
- package/dist/commands/user-agents-node.d.ts +3 -0
- package/dist/commands/user-agents-node.js +52 -0
- package/dist/commands/user-agents.d.ts +22 -0
- package/dist/commands/user-agents.js +40 -0
- package/dist/conversations/approval-grants.d.ts +20 -0
- package/dist/conversations/approval-grants.js +75 -0
- package/dist/conversations/binding-state.d.ts +6 -0
- package/dist/conversations/binding-state.js +35 -0
- package/dist/conversations/context-handoff.d.ts +25 -0
- package/dist/conversations/context-handoff.js +207 -0
- package/dist/conversations/conversation-index-coordinator.d.ts +18 -0
- package/dist/conversations/conversation-index-coordinator.js +81 -0
- package/dist/conversations/conversation-index.d.ts +16 -0
- package/dist/conversations/conversation-index.js +125 -0
- package/dist/conversations/conversation-locator.d.ts +2 -0
- package/dist/conversations/conversation-locator.js +20 -0
- package/dist/conversations/conversation-palette.d.ts +18 -0
- package/dist/conversations/conversation-palette.js +29 -0
- package/dist/conversations/conversation-repository.d.ts +39 -0
- package/dist/conversations/conversation-repository.js +213 -0
- package/dist/conversations/handoff-summary.d.ts +48 -0
- package/dist/conversations/handoff-summary.js +269 -0
- package/dist/conversations/hashes.d.ts +5 -0
- package/dist/conversations/hashes.js +40 -0
- package/dist/conversations/history-creation-scope.d.ts +12 -0
- package/dist/conversations/history-creation-scope.js +44 -0
- package/dist/conversations/jsonl.d.ts +10 -0
- package/dist/conversations/jsonl.js +41 -0
- package/dist/conversations/memory-transcript-store.d.ts +15 -0
- package/dist/conversations/memory-transcript-store.js +119 -0
- package/dist/conversations/paths.d.ts +14 -0
- package/dist/conversations/paths.js +92 -0
- package/dist/conversations/redaction.d.ts +13 -0
- package/dist/conversations/redaction.js +94 -0
- package/dist/conversations/reveal-scope.d.ts +3 -0
- package/dist/conversations/reveal-scope.js +8 -0
- package/dist/conversations/scope-resolver.d.ts +11 -0
- package/dist/conversations/scope-resolver.js +18 -0
- package/dist/conversations/scope-tree.d.ts +10 -0
- package/dist/conversations/scope-tree.js +71 -0
- package/dist/conversations/transcript-projection.d.ts +9 -0
- package/dist/conversations/transcript-projection.js +409 -0
- package/dist/conversations/transcript-store.d.ts +24 -0
- package/dist/conversations/transcript-store.js +27 -0
- package/dist/conversations/types.d.ts +224 -0
- package/dist/conversations/types.js +12 -0
- package/dist/conversations/validation.d.ts +4 -0
- package/dist/conversations/validation.js +383 -0
- package/dist/conversations/vault-transcript-store.d.ts +22 -0
- package/dist/conversations/vault-transcript-store.js +219 -0
- package/dist/core/event-queue.d.ts +6 -0
- package/dist/core/event-queue.js +39 -0
- package/dist/core/types.d.ts +241 -0
- package/dist/core/types.js +50 -0
- package/dist/history/ai-history-panel.svelte +937 -0
- package/dist/history/ai-history-panel.svelte.d.ts +17 -0
- package/dist/history/ai-history-view-type.d.ts +1 -0
- package/dist/history/ai-history-view-type.js +1 -0
- package/dist/history/ai-history-view.d.ts +26 -0
- package/dist/history/ai-history-view.js +51 -0
- package/dist/history/conversation-history-tree.d.ts +15 -0
- package/dist/history/conversation-history-tree.js +71 -0
- package/dist/host/agent-workspace.d.ts +6 -0
- package/dist/host/agent-workspace.js +16 -0
- package/dist/host/create-host-runtimes.d.ts +2 -0
- package/dist/host/create-host-runtimes.js +14 -0
- package/dist/host/desktop-process-host.d.ts +6 -0
- package/dist/host/desktop-process-host.js +74 -0
- package/dist/host/host-runtime-availability.d.ts +1 -0
- package/dist/host/host-runtime-availability.js +3 -0
- package/dist/host/process-host.d.ts +31 -0
- package/dist/host/process-host.js +6 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +49 -0
- package/dist/jsonl/ai-jsonl-preview.d.ts +27 -0
- package/dist/jsonl/ai-jsonl-preview.js +68 -0
- package/dist/jsonl/ai-jsonl-view-type.d.ts +1 -0
- package/dist/jsonl/ai-jsonl-view-type.js +1 -0
- package/dist/jsonl/ai-jsonl-view.d.ts +16 -0
- package/dist/jsonl/ai-jsonl-view.js +57 -0
- package/dist/jsonl/ai-jsonl-view.svelte +260 -0
- package/dist/jsonl/ai-jsonl-view.svelte.d.ts +9 -0
- package/dist/memory/candidate-extractor.d.ts +25 -0
- package/dist/memory/candidate-extractor.js +191 -0
- package/dist/memory/forget-confirmation.d.ts +3 -0
- package/dist/memory/forget-confirmation.js +45 -0
- package/dist/memory/hashes.d.ts +5 -0
- package/dist/memory/hashes.js +37 -0
- package/dist/memory/memory-ingestion-coordinator.d.ts +19 -0
- package/dist/memory/memory-ingestion-coordinator.js +108 -0
- package/dist/memory/memory-record-store.d.ts +62 -0
- package/dist/memory/memory-record-store.js +369 -0
- package/dist/memory/memory-scheduler.d.ts +21 -0
- package/dist/memory/memory-scheduler.js +143 -0
- package/dist/memory/memory-tools.d.ts +61 -0
- package/dist/memory/memory-tools.js +99 -0
- package/dist/memory/native-memory-service.d.ts +72 -0
- package/dist/memory/native-memory-service.js +1256 -0
- package/dist/memory/paths.d.ts +13 -0
- package/dist/memory/paths.js +60 -0
- package/dist/memory/runtime-consolidation-provider.d.ts +18 -0
- package/dist/memory/runtime-consolidation-provider.js +154 -0
- package/dist/memory/types.d.ts +139 -0
- package/dist/memory/types.js +1 -0
- package/dist/providers/acp-model-provider.d.ts +11 -0
- package/dist/providers/acp-model-provider.js +99 -0
- package/dist/providers/codex-model-catalog.d.ts +7 -0
- package/dist/providers/codex-model-catalog.js +179 -0
- package/dist/providers/codex-model-provider.d.ts +12 -0
- package/dist/providers/codex-model-provider.js +42 -0
- package/dist/providers/model-provider.d.ts +26 -0
- package/dist/providers/model-provider.js +26 -0
- package/dist/public-components.d.ts +3 -0
- package/dist/public-components.js +3 -0
- package/dist/registry/runtime-registry.d.ts +11 -0
- package/dist/registry/runtime-registry.js +71 -0
- package/dist/registry/select-runtime.d.ts +9 -0
- package/dist/registry/select-runtime.js +31 -0
- package/dist/runtime-adapters.d.ts +16 -0
- package/dist/runtime-adapters.js +9 -0
- package/dist/runtimes/acp/acp-event-mapper.d.ts +56 -0
- package/dist/runtimes/acp/acp-event-mapper.js +237 -0
- package/dist/runtimes/acp/acp-runtime.d.ts +46 -0
- package/dist/runtimes/acp/acp-runtime.js +165 -0
- package/dist/runtimes/acp/desktop-acp-backend.d.ts +16 -0
- package/dist/runtimes/acp/desktop-acp-backend.js +243 -0
- package/dist/runtimes/codex/app-server-protocol.d.ts +28 -0
- package/dist/runtimes/codex/app-server-protocol.js +274 -0
- package/dist/runtimes/codex/codex-runtime.d.ts +24 -0
- package/dist/runtimes/codex/codex-runtime.js +318 -0
- package/dist/runtimes/fake/fake-runtime.d.ts +51 -0
- package/dist/runtimes/fake/fake-runtime.js +257 -0
- package/dist/sessions/plugin-data.d.ts +8 -0
- package/dist/sessions/plugin-data.js +29 -0
- package/dist/sessions/session-store.d.ts +47 -0
- package/dist/sessions/session-store.js +117 -0
- package/dist/settings/acp-agents.d.ts +8 -0
- package/dist/settings/acp-agents.js +11 -0
- package/dist/settings/ai-settings-tab.d.ts +8 -0
- package/dist/settings/ai-settings-tab.js +249 -0
- package/dist/settings/ai-settings.d.ts +43 -0
- package/dist/settings/ai-settings.js +147 -0
- package/dist/settings/app-tool-setting-rows.d.ts +16 -0
- package/dist/settings/app-tool-setting-rows.js +30 -0
- package/dist/settings/register-ai-settings.d.ts +3 -0
- package/dist/settings/register-ai-settings.js +393 -0
- package/dist/skills/activation.d.ts +2 -0
- package/dist/skills/activation.js +20 -0
- package/dist/skills/bundled/lapis-notes.d.ts +3 -0
- package/dist/skills/bundled/lapis-notes.js +52 -0
- package/dist/skills/bundled/research.d.ts +6 -0
- package/dist/skills/bundled/research.js +29 -0
- package/dist/skills/discovery.d.ts +21 -0
- package/dist/skills/discovery.js +227 -0
- package/dist/skills/manifest.d.ts +3 -0
- package/dist/skills/manifest.js +39 -0
- package/dist/skills/parser.d.ts +12 -0
- package/dist/skills/parser.js +124 -0
- package/dist/skills/registry.d.ts +21 -0
- package/dist/skills/registry.js +89 -0
- package/dist/skills/seed.d.ts +5 -0
- package/dist/skills/seed.js +18 -0
- package/dist/skills/skill-tools.d.ts +8 -0
- package/dist/skills/skill-tools.js +113 -0
- package/dist/skills/types.d.ts +67 -0
- package/dist/skills/types.js +1 -0
- package/dist/styles.css +514 -0
- package/dist/tools/app-tool-host.d.ts +47 -0
- package/dist/tools/app-tool-host.js +419 -0
- package/dist/tools/desktop-app-tool-bridge.d.ts +23 -0
- package/dist/tools/desktop-app-tool-bridge.js +223 -0
- package/dist/tools/mcp-server-registry.d.ts +7 -0
- package/dist/tools/mcp-server-registry.js +30 -0
- package/manifest.json +34 -0
- package/package.json +83 -0
- package/styles.css +1 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { AsyncEventQueue } from "../../core/event-queue";
|
|
2
|
+
import { DEFAULT_APPROVAL_OPTIONS, } from "../../core/types";
|
|
3
|
+
export const FAKE_RICH_THINKING = "I will read the mentioned note, then summarize it.";
|
|
4
|
+
export const FAKE_RICH_TOOL = {
|
|
5
|
+
id: "tool-vault-read",
|
|
6
|
+
name: "vault.read",
|
|
7
|
+
input: { path: "Notes/alpha.md" },
|
|
8
|
+
output: "heading: Notes",
|
|
9
|
+
};
|
|
10
|
+
export const FAKE_RICH_ASSISTANT_TEXT = [
|
|
11
|
+
"## Summary",
|
|
12
|
+
"",
|
|
13
|
+
"I read **Notes/alpha.md** and found a `TODO`.",
|
|
14
|
+
"",
|
|
15
|
+
"- One heading",
|
|
16
|
+
"- A note",
|
|
17
|
+
].join("\n");
|
|
18
|
+
export class FakeAgentSession {
|
|
19
|
+
id;
|
|
20
|
+
prompts = [];
|
|
21
|
+
contextBlocks = [];
|
|
22
|
+
configurations = [];
|
|
23
|
+
cancelled = false;
|
|
24
|
+
closed = false;
|
|
25
|
+
detached = false;
|
|
26
|
+
#events = new AsyncEventQueue();
|
|
27
|
+
#pending = new Map();
|
|
28
|
+
#pendingQuestions = new Map();
|
|
29
|
+
#requireApproval;
|
|
30
|
+
#requireQuestion;
|
|
31
|
+
#trace;
|
|
32
|
+
#nativeCommands;
|
|
33
|
+
constructor(id, requireApproval, trace = "echo", requireQuestion = false, nativeCommands = []) {
|
|
34
|
+
this.id = id;
|
|
35
|
+
this.#requireApproval = requireApproval;
|
|
36
|
+
this.#requireQuestion = requireQuestion;
|
|
37
|
+
this.#trace = trace;
|
|
38
|
+
this.#nativeCommands = nativeCommands;
|
|
39
|
+
if (nativeCommands.length > 0) {
|
|
40
|
+
this.#events.push({
|
|
41
|
+
type: "commands.update",
|
|
42
|
+
commands: nativeCommands,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
events() {
|
|
47
|
+
return this.#events;
|
|
48
|
+
}
|
|
49
|
+
async send(input, options) {
|
|
50
|
+
if (this.closed)
|
|
51
|
+
throw new Error("Fake session is closed.");
|
|
52
|
+
this.prompts.push(input);
|
|
53
|
+
this.contextBlocks.push(structuredClone(options?.contextBlocks));
|
|
54
|
+
if (this.#trace === "rich") {
|
|
55
|
+
this.#events.push({
|
|
56
|
+
type: "thinking",
|
|
57
|
+
text: FAKE_RICH_THINKING,
|
|
58
|
+
kind: "reasoning",
|
|
59
|
+
});
|
|
60
|
+
this.#events.push({
|
|
61
|
+
type: "tool.start",
|
|
62
|
+
id: FAKE_RICH_TOOL.id,
|
|
63
|
+
name: FAKE_RICH_TOOL.name,
|
|
64
|
+
input: FAKE_RICH_TOOL.input,
|
|
65
|
+
});
|
|
66
|
+
this.#events.push({
|
|
67
|
+
type: "tool.end",
|
|
68
|
+
id: FAKE_RICH_TOOL.id,
|
|
69
|
+
name: FAKE_RICH_TOOL.name,
|
|
70
|
+
output: FAKE_RICH_TOOL.output,
|
|
71
|
+
});
|
|
72
|
+
this.#events.push({ type: "text", text: FAKE_RICH_ASSISTANT_TEXT });
|
|
73
|
+
this.#events.push({ type: "status", status: "session updated" });
|
|
74
|
+
this.#events.push({
|
|
75
|
+
type: "status",
|
|
76
|
+
status: "available commands updated (75)",
|
|
77
|
+
});
|
|
78
|
+
this.#events.push({
|
|
79
|
+
type: "usage",
|
|
80
|
+
usage: { used: 12_920, limit: 128_000 },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.#events.push({ type: "text", text: input });
|
|
85
|
+
}
|
|
86
|
+
if (this.#requireApproval) {
|
|
87
|
+
const request = createFakeApprovalRequest(`approval-${this.prompts.length}`);
|
|
88
|
+
this.#events.push({ type: "permission.request", request });
|
|
89
|
+
const optionId = await new Promise((resolve, reject) => {
|
|
90
|
+
this.#pending.set(request.id, { resolve, reject });
|
|
91
|
+
});
|
|
92
|
+
this.#events.push({
|
|
93
|
+
type: "status",
|
|
94
|
+
status: `approval:${request.id}:${optionId}`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (this.#requireQuestion) {
|
|
98
|
+
const request = createFakeQuestionRequest(`question-${this.prompts.length}`);
|
|
99
|
+
this.#events.push({ type: "question.request", request });
|
|
100
|
+
await new Promise((resolve, reject) => {
|
|
101
|
+
this.#pendingQuestions.set(request.id, { resolve, reject });
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
this.#events.push({ type: "completed", result: { prompt: input } });
|
|
105
|
+
}
|
|
106
|
+
async configure(input) {
|
|
107
|
+
this.configurations.push(structuredClone(input));
|
|
108
|
+
return {
|
|
109
|
+
...(input.model ? { model: { status: "applied" } } : {}),
|
|
110
|
+
...(input.thinking ? { thinking: { status: "applied" } } : {}),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async respondToApproval(requestId, optionId) {
|
|
114
|
+
const pending = this.#pending.get(requestId);
|
|
115
|
+
if (!pending) {
|
|
116
|
+
throw new Error(`Unknown approval request: ${requestId}`);
|
|
117
|
+
}
|
|
118
|
+
this.#pending.delete(requestId);
|
|
119
|
+
pending.resolve(optionId);
|
|
120
|
+
}
|
|
121
|
+
async respondToQuestion(requestId, answers) {
|
|
122
|
+
const pending = this.#pendingQuestions.get(requestId);
|
|
123
|
+
if (!pending) {
|
|
124
|
+
throw new Error(`Unknown question request: ${requestId}`);
|
|
125
|
+
}
|
|
126
|
+
this.#pendingQuestions.delete(requestId);
|
|
127
|
+
pending.resolve(answers);
|
|
128
|
+
}
|
|
129
|
+
async cancel() {
|
|
130
|
+
this.cancelled = true;
|
|
131
|
+
for (const [id, pending] of this.#pending) {
|
|
132
|
+
this.#pending.delete(id);
|
|
133
|
+
pending.reject(new Error("Session cancelled."));
|
|
134
|
+
}
|
|
135
|
+
for (const [id, pending] of this.#pendingQuestions) {
|
|
136
|
+
this.#pendingQuestions.delete(id);
|
|
137
|
+
pending.reject(new Error("Session cancelled."));
|
|
138
|
+
}
|
|
139
|
+
this.#events.push({ type: "status", status: "cancelled" });
|
|
140
|
+
}
|
|
141
|
+
async close() {
|
|
142
|
+
this.closed = true;
|
|
143
|
+
for (const [id, pending] of this.#pending) {
|
|
144
|
+
this.#pending.delete(id);
|
|
145
|
+
pending.reject(new Error("Session closed."));
|
|
146
|
+
}
|
|
147
|
+
for (const [id, pending] of this.#pendingQuestions) {
|
|
148
|
+
this.#pendingQuestions.delete(id);
|
|
149
|
+
pending.reject(new Error("Session closed."));
|
|
150
|
+
}
|
|
151
|
+
this.#events.close();
|
|
152
|
+
}
|
|
153
|
+
async detach() {
|
|
154
|
+
this.detached = true;
|
|
155
|
+
await this.close();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export class FakeAgentRuntime {
|
|
159
|
+
id;
|
|
160
|
+
sessions = [];
|
|
161
|
+
lastRequest = null;
|
|
162
|
+
#requireApproval;
|
|
163
|
+
#requireQuestion;
|
|
164
|
+
#resumeSupported;
|
|
165
|
+
#trace;
|
|
166
|
+
#nativeCommands;
|
|
167
|
+
constructor(options = {}) {
|
|
168
|
+
this.id = options.id ?? "fake";
|
|
169
|
+
this.#requireApproval = options.requireApproval ?? false;
|
|
170
|
+
this.#requireQuestion = options.requireQuestion ?? false;
|
|
171
|
+
this.#resumeSupported = options.resumeSupported ?? true;
|
|
172
|
+
this.#trace = options.trace ?? "echo";
|
|
173
|
+
this.#nativeCommands = options.nativeCommands ?? [];
|
|
174
|
+
}
|
|
175
|
+
capabilities() {
|
|
176
|
+
return {
|
|
177
|
+
sessions: true,
|
|
178
|
+
resume: this.#resumeSupported,
|
|
179
|
+
cancel: true,
|
|
180
|
+
steer: false,
|
|
181
|
+
modelSelection: true,
|
|
182
|
+
nativeTools: false,
|
|
183
|
+
mcpTools: true,
|
|
184
|
+
approvals: {
|
|
185
|
+
supported: true,
|
|
186
|
+
interactive: true,
|
|
187
|
+
persistentDecisions: true,
|
|
188
|
+
granularPermissions: false,
|
|
189
|
+
policyAmendments: false,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async supports(request) {
|
|
194
|
+
if (request.requirePolicyAmendments)
|
|
195
|
+
return false;
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
async start(request) {
|
|
199
|
+
this.lastRequest = request;
|
|
200
|
+
const session = new FakeAgentSession(`fake-${this.sessions.length + 1}`, this.#requireApproval || Boolean(request.requireApprovals), this.#trace, this.#requireQuestion, this.#nativeCommands);
|
|
201
|
+
this.sessions.push(session);
|
|
202
|
+
return session;
|
|
203
|
+
}
|
|
204
|
+
async resume(sessionId) {
|
|
205
|
+
if (!this.#resumeSupported) {
|
|
206
|
+
throw new Error("Fake runtime does not support resume.");
|
|
207
|
+
}
|
|
208
|
+
const existing = this.sessions.find((session) => session.id === sessionId);
|
|
209
|
+
if (!existing)
|
|
210
|
+
throw new Error(`Unknown fake session: ${sessionId}`);
|
|
211
|
+
if (!existing.closed)
|
|
212
|
+
return existing;
|
|
213
|
+
if (!existing.detached) {
|
|
214
|
+
throw new Error(`Unknown fake session: ${sessionId}`);
|
|
215
|
+
}
|
|
216
|
+
const resumed = new FakeAgentSession(sessionId, this.#requireApproval, this.#trace, this.#requireQuestion, this.#nativeCommands);
|
|
217
|
+
this.sessions.push(resumed);
|
|
218
|
+
return resumed;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function createFakeApprovalRequest(id) {
|
|
222
|
+
return {
|
|
223
|
+
id,
|
|
224
|
+
origin: "runtime",
|
|
225
|
+
kind: "execute",
|
|
226
|
+
title: "Allow the fake agent to continue?",
|
|
227
|
+
tool: { name: "fake.echo", input: { id } },
|
|
228
|
+
options: DEFAULT_APPROVAL_OPTIONS,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function createFakeQuestionRequest(id) {
|
|
232
|
+
return {
|
|
233
|
+
id,
|
|
234
|
+
title: "Agent needs input",
|
|
235
|
+
questions: [
|
|
236
|
+
{
|
|
237
|
+
id: "approach",
|
|
238
|
+
header: "Approach",
|
|
239
|
+
prompt: "How should I update the sample file?",
|
|
240
|
+
options: [
|
|
241
|
+
{
|
|
242
|
+
id: "approach-minimal",
|
|
243
|
+
label: "Make the smallest change",
|
|
244
|
+
description: "Keep the existing structure and edit only what is needed.",
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: "approach-refactor",
|
|
248
|
+
label: "Refactor while editing",
|
|
249
|
+
description: "Clean up the surrounding structure as part of the change.",
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
allowOther: true,
|
|
253
|
+
secret: false,
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
};
|
|
257
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type AiPluginSettings } from "../settings/ai-settings";
|
|
2
|
+
export type AiPluginData = {
|
|
3
|
+
settings: AiPluginSettings;
|
|
4
|
+
source: Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
export declare function parseAiPluginData(value: unknown): AiPluginData;
|
|
7
|
+
export declare function serializeAiPluginData(data: AiPluginData): Record<string, unknown>;
|
|
8
|
+
export declare function equalAiPluginData(left: AiPluginData, right: AiPluginData): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { mergeAiSettings, } from "../settings/ai-settings";
|
|
2
|
+
export function parseAiPluginData(value) {
|
|
3
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
4
|
+
return { settings: mergeAiSettings(null), source: {} };
|
|
5
|
+
}
|
|
6
|
+
const record = value;
|
|
7
|
+
const settingsSource = record.settings && typeof record.settings === "object"
|
|
8
|
+
? record.settings
|
|
9
|
+
: record;
|
|
10
|
+
return {
|
|
11
|
+
settings: mergeAiSettings(settingsSource),
|
|
12
|
+
source: structuredClone(record),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function serializeAiPluginData(data) {
|
|
16
|
+
const settings = structuredClone(data.settings);
|
|
17
|
+
if (settings.enabledCommunityToolPluginIds.length === 0) {
|
|
18
|
+
delete settings
|
|
19
|
+
.enabledCommunityToolPluginIds;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
...structuredClone(data.source),
|
|
23
|
+
settings,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function equalAiPluginData(left, right) {
|
|
27
|
+
return (JSON.stringify(serializeAiPluginData(left)) ===
|
|
28
|
+
JSON.stringify(serializeAiPluginData(right)));
|
|
29
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AiChatItem } from "../chat/chat-items";
|
|
2
|
+
import type { AgentUsage, AiThinkingLevel, ModelRef } from "../core/types";
|
|
3
|
+
export type StoredAgentSession = {
|
|
4
|
+
id: string;
|
|
5
|
+
runtime: string;
|
|
6
|
+
runtimeSessionId: string;
|
|
7
|
+
workspace?: string;
|
|
8
|
+
agent?: string;
|
|
9
|
+
model?: ModelRef;
|
|
10
|
+
thinking?: AiThinkingLevel;
|
|
11
|
+
usage?: AgentUsage;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
interrupted?: boolean;
|
|
15
|
+
pendingApprovalId?: string;
|
|
16
|
+
pendingQuestionId?: string;
|
|
17
|
+
items: AiChatItem[];
|
|
18
|
+
};
|
|
19
|
+
export interface AgentSessionStore {
|
|
20
|
+
list(): Promise<StoredAgentSession[]>;
|
|
21
|
+
get(id: string): Promise<StoredAgentSession | undefined>;
|
|
22
|
+
save(session: StoredAgentSession): Promise<void>;
|
|
23
|
+
remove(id: string): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function createMemorySessionStore(initial?: StoredAgentSession[]): AgentSessionStore;
|
|
26
|
+
export declare function createPersistedSessionStore(options: {
|
|
27
|
+
read(): Promise<StoredAgentSession[]>;
|
|
28
|
+
write(sessions: StoredAgentSession[]): Promise<void>;
|
|
29
|
+
}): AgentSessionStore;
|
|
30
|
+
export declare function createStoredAgentSession(input: {
|
|
31
|
+
id: string;
|
|
32
|
+
runtime: string;
|
|
33
|
+
runtimeSessionId: string;
|
|
34
|
+
workspace?: string;
|
|
35
|
+
agent?: string;
|
|
36
|
+
model?: ModelRef;
|
|
37
|
+
thinking?: AiThinkingLevel;
|
|
38
|
+
usage?: AgentUsage;
|
|
39
|
+
items?: AiChatItem[];
|
|
40
|
+
pendingApprovalId?: string;
|
|
41
|
+
pendingQuestionId?: string;
|
|
42
|
+
interrupted?: boolean;
|
|
43
|
+
}): StoredAgentSession;
|
|
44
|
+
export declare function pendingApprovalIdFromItems(items: AiChatItem[]): string | undefined;
|
|
45
|
+
export declare function pendingQuestionIdFromItems(items: AiChatItem[]): string | undefined;
|
|
46
|
+
export declare function interruptPendingApprovals(items: AiChatItem[]): AiChatItem[];
|
|
47
|
+
export declare function interruptPendingInteractions(items: AiChatItem[]): AiChatItem[];
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export function createMemorySessionStore(initial = []) {
|
|
2
|
+
const sessions = new Map(initial.map((session) => [session.id, cloneSession(session)]));
|
|
3
|
+
return {
|
|
4
|
+
async list() {
|
|
5
|
+
return [...sessions.values()]
|
|
6
|
+
.map(cloneSession)
|
|
7
|
+
.sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
|
|
8
|
+
},
|
|
9
|
+
async get(id) {
|
|
10
|
+
const session = sessions.get(id);
|
|
11
|
+
return session ? cloneSession(session) : undefined;
|
|
12
|
+
},
|
|
13
|
+
async save(session) {
|
|
14
|
+
sessions.set(session.id, cloneSession(session));
|
|
15
|
+
},
|
|
16
|
+
async remove(id) {
|
|
17
|
+
sessions.delete(id);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function createPersistedSessionStore(options) {
|
|
22
|
+
const memory = createMemorySessionStore();
|
|
23
|
+
let loaded = false;
|
|
24
|
+
async function ensureLoaded() {
|
|
25
|
+
if (loaded)
|
|
26
|
+
return;
|
|
27
|
+
for (const session of await options.read()) {
|
|
28
|
+
await memory.save(session);
|
|
29
|
+
}
|
|
30
|
+
loaded = true;
|
|
31
|
+
}
|
|
32
|
+
async function persist() {
|
|
33
|
+
await options.write(await memory.list());
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
async list() {
|
|
37
|
+
await ensureLoaded();
|
|
38
|
+
return memory.list();
|
|
39
|
+
},
|
|
40
|
+
async get(id) {
|
|
41
|
+
await ensureLoaded();
|
|
42
|
+
return memory.get(id);
|
|
43
|
+
},
|
|
44
|
+
async save(session) {
|
|
45
|
+
await ensureLoaded();
|
|
46
|
+
await memory.save(session);
|
|
47
|
+
await persist();
|
|
48
|
+
},
|
|
49
|
+
async remove(id) {
|
|
50
|
+
await ensureLoaded();
|
|
51
|
+
await memory.remove(id);
|
|
52
|
+
await persist();
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function createStoredAgentSession(input) {
|
|
57
|
+
const now = new Date().toISOString();
|
|
58
|
+
return {
|
|
59
|
+
id: input.id,
|
|
60
|
+
runtime: input.runtime,
|
|
61
|
+
runtimeSessionId: input.runtimeSessionId,
|
|
62
|
+
workspace: input.workspace,
|
|
63
|
+
agent: input.agent,
|
|
64
|
+
model: input.model,
|
|
65
|
+
thinking: input.thinking,
|
|
66
|
+
usage: input.usage ? { ...input.usage } : undefined,
|
|
67
|
+
createdAt: now,
|
|
68
|
+
updatedAt: now,
|
|
69
|
+
interrupted: input.interrupted,
|
|
70
|
+
pendingApprovalId: input.pendingApprovalId,
|
|
71
|
+
pendingQuestionId: input.pendingQuestionId,
|
|
72
|
+
items: input.items ? input.items.map(sanitizeChatItem) : [],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function pendingApprovalIdFromItems(items) {
|
|
76
|
+
const pending = items.find((item) => item.type === "approval" && item.status === "pending");
|
|
77
|
+
return pending?.request.id;
|
|
78
|
+
}
|
|
79
|
+
export function pendingQuestionIdFromItems(items) {
|
|
80
|
+
const pending = items.find((item) => item.type === "question" && item.status === "pending");
|
|
81
|
+
return pending?.request.id;
|
|
82
|
+
}
|
|
83
|
+
export function interruptPendingApprovals(items) {
|
|
84
|
+
return items.map((item) => item.type === "approval" && item.status === "pending"
|
|
85
|
+
? { ...item, status: "cancelled" }
|
|
86
|
+
: item);
|
|
87
|
+
}
|
|
88
|
+
export function interruptPendingInteractions(items) {
|
|
89
|
+
return items.map((item) => {
|
|
90
|
+
if (item.type === "approval" && item.status === "pending") {
|
|
91
|
+
return { ...item, status: "cancelled" };
|
|
92
|
+
}
|
|
93
|
+
if (item.type === "question" && item.status === "pending") {
|
|
94
|
+
return { ...item, status: "cancelled" };
|
|
95
|
+
}
|
|
96
|
+
if (item.type === "thinking" && item.state === "streaming") {
|
|
97
|
+
return { ...item, state: "done" };
|
|
98
|
+
}
|
|
99
|
+
if (item.type === "tool" && item.state === "running") {
|
|
100
|
+
return { ...item, state: "completed" };
|
|
101
|
+
}
|
|
102
|
+
return item;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function cloneSession(session) {
|
|
106
|
+
return {
|
|
107
|
+
...session,
|
|
108
|
+
usage: session.usage ? { ...session.usage } : undefined,
|
|
109
|
+
items: session.items.map(sanitizeChatItem),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function sanitizeChatItem(item) {
|
|
113
|
+
if (item.type !== "approval")
|
|
114
|
+
return { ...item };
|
|
115
|
+
const { metadata: _vendor, ...request } = item.request;
|
|
116
|
+
return { ...item, request };
|
|
117
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const ACP_AGENT_IDS: readonly ["codex", "cursor"];
|
|
2
|
+
export type AcpAgentId = (typeof ACP_AGENT_IDS)[number];
|
|
3
|
+
export declare const DEFAULT_ACP_AGENT: AcpAgentId;
|
|
4
|
+
export declare function isAcpAgentId(value: unknown): value is AcpAgentId;
|
|
5
|
+
export declare function normalizeAcpAgent(value: unknown): AcpAgentId;
|
|
6
|
+
export declare function catalogModelsForAgent<T extends {
|
|
7
|
+
provider?: string;
|
|
8
|
+
}>(agent: AcpAgentId, models: T[]): T[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const ACP_AGENT_IDS = ["codex", "cursor"];
|
|
2
|
+
export const DEFAULT_ACP_AGENT = "codex";
|
|
3
|
+
export function isAcpAgentId(value) {
|
|
4
|
+
return ACP_AGENT_IDS.some((id) => id === value);
|
|
5
|
+
}
|
|
6
|
+
export function normalizeAcpAgent(value) {
|
|
7
|
+
return isAcpAgentId(value) ? value : DEFAULT_ACP_AGENT;
|
|
8
|
+
}
|
|
9
|
+
export function catalogModelsForAgent(agent, models) {
|
|
10
|
+
return models.filter((model) => model.provider === agent || !model.provider);
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PluginSettingTab, type App } from "@lapis-notes/api";
|
|
2
|
+
import type { AiPlugin } from "../ai-plugin";
|
|
3
|
+
export declare class AiSettingsTab extends PluginSettingTab {
|
|
4
|
+
private readonly aiPlugin;
|
|
5
|
+
constructor(app: App, aiPlugin: AiPlugin);
|
|
6
|
+
display(): void;
|
|
7
|
+
private loadModels;
|
|
8
|
+
}
|