@lapis-notes/ai 0.1.2 → 0.1.5
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 +24 -0
- package/LICENSE.md +3 -7
- package/README.md +1 -1
- package/dist/ai-plugin.d.ts +2 -2
- package/dist/ai-plugin.js +28 -11
- package/dist/catalog/ai-catalog-panel.svelte +20 -3
- package/dist/chat/ai-chat-panel.svelte +187 -87
- package/dist/chat/ai-chat-panel.svelte.d.ts +2 -0
- package/dist/chat/ai-view-bootstrap.d.ts +1 -0
- package/dist/chat/ai-view-bootstrap.js +32 -12
- package/dist/chat/ai-view-panel.svelte +14 -0
- package/dist/chat/ai-view.d.ts +1 -1
- package/dist/chat/chat-controller.svelte.d.ts +1 -1
- package/dist/chat/chat-controller.svelte.js +94 -29
- package/dist/chat/chat-tool-display.d.ts +2 -12
- package/dist/chat/chat-tool-display.js +2 -206
- package/dist/chat/composer-model-catalog.d.ts +20 -0
- package/dist/chat/composer-model-catalog.js +44 -0
- package/dist/commands/agent.d.ts +1 -1
- package/dist/commands/agent.js +6 -1
- package/dist/conversations/context-handoff.d.ts +1 -25
- package/dist/conversations/context-handoff.js +1 -207
- package/dist/conversations/hashes.d.ts +1 -5
- package/dist/conversations/hashes.js +1 -40
- package/dist/core/types.d.ts +1 -241
- package/dist/core/types.js +1 -50
- package/dist/history/ai-history-panel.svelte +4 -1
- package/dist/host/controller-connection.d.ts +14 -0
- package/dist/host/controller-connection.js +62 -0
- package/dist/host/controller-runtime.d.ts +13 -0
- package/dist/host/controller-runtime.js +112 -0
- package/dist/host/create-host-runtimes.d.ts +2 -1
- package/dist/host/create-host-runtimes.js +5 -7
- package/dist/index.d.ts +1 -1
- package/dist/memory/candidate-extractor.d.ts +2 -25
- package/dist/memory/candidate-extractor.js +1 -191
- package/dist/memory/hashes.d.ts +1 -5
- package/dist/memory/hashes.js +1 -37
- package/dist/memory/memory-record-store.d.ts +3 -48
- package/dist/memory/memory-record-store.js +16 -220
- package/dist/memory/memory-scheduler.d.ts +1 -21
- package/dist/memory/memory-scheduler.js +1 -143
- package/dist/memory/native-memory-service.d.ts +1 -72
- package/dist/memory/native-memory-service.js +1 -1256
- package/dist/memory/paths.d.ts +1 -13
- package/dist/memory/paths.js +1 -60
- package/dist/memory/runtime-consolidation-provider.d.ts +2 -18
- package/dist/memory/runtime-consolidation-provider.js +1 -154
- package/dist/memory/types.d.ts +1 -139
- package/dist/providers/acp-model-provider.d.ts +8 -3
- package/dist/providers/acp-model-provider.js +21 -49
- package/dist/providers/model-provider.d.ts +3 -2
- package/dist/providers/model-provider.js +15 -2
- package/dist/runtime-adapters.d.ts +3 -0
- package/dist/runtime-adapters.js +2 -0
- package/dist/settings/acp-agents.d.ts +4 -1
- package/dist/settings/acp-agents.js +5 -1
- package/dist/settings/ai-settings-tab.js +8 -6
- package/dist/settings/ai-settings.d.ts +4 -4
- package/dist/settings/ai-settings.js +5 -3
- package/dist/settings/register-ai-settings.js +27 -14
- package/dist/tools/app-tool-host.d.ts +22 -2
- package/dist/tools/app-tool-host.js +51 -4
- package/dist/tools/desktop-app-tool-bridge.d.ts +4 -1
- package/dist/tools/desktop-app-tool-bridge.js +94 -157
- package/manifest.json +20 -2
- package/package.json +17 -7
- package/registry-content/overview.md +10 -0
- package/registry.json +211 -2
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ControllerRuntime, } from "@lapismd/ai-controller/runtime";
|
|
2
|
+
import { projectSkillActivationPrompt } from "../skills/activation";
|
|
3
|
+
/** Lapis supplies domain instructions and endpoint identities; the SDK owns execution. */
|
|
4
|
+
export class ControllerAgentRuntime {
|
|
5
|
+
id;
|
|
6
|
+
connections;
|
|
7
|
+
#runtimes = new WeakMap();
|
|
8
|
+
#last;
|
|
9
|
+
constructor(id, connections) {
|
|
10
|
+
this.id = id;
|
|
11
|
+
this.connections = connections;
|
|
12
|
+
}
|
|
13
|
+
capabilities() {
|
|
14
|
+
return (this.#last?.capabilities() ?? {
|
|
15
|
+
sessions: true,
|
|
16
|
+
resume: true,
|
|
17
|
+
cancel: true,
|
|
18
|
+
steer: false,
|
|
19
|
+
modelSelection: false,
|
|
20
|
+
nativeTools: true,
|
|
21
|
+
mcpTools: false,
|
|
22
|
+
preparesContext: true,
|
|
23
|
+
approvals: {
|
|
24
|
+
supported: false,
|
|
25
|
+
interactive: false,
|
|
26
|
+
persistentDecisions: false,
|
|
27
|
+
granularPermissions: false,
|
|
28
|
+
policyAmendments: false,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async supports(request) {
|
|
33
|
+
try {
|
|
34
|
+
return await (await this.#runtime(request)).supports(request);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async start(request) {
|
|
41
|
+
return (await this.#runtime(request)).start(request);
|
|
42
|
+
}
|
|
43
|
+
async resume(id, request = {}) {
|
|
44
|
+
return (await this.#runtime(request)).resume(id, request);
|
|
45
|
+
}
|
|
46
|
+
async #runtime(request) {
|
|
47
|
+
const connection = await this.connections.get(request.workspace);
|
|
48
|
+
let runtime = this.#runtimes.get(connection);
|
|
49
|
+
if (!runtime) {
|
|
50
|
+
runtime = new ControllerRuntime({
|
|
51
|
+
id: this.id,
|
|
52
|
+
client: connection.client,
|
|
53
|
+
provider: (request) => this.id === "codex-native"
|
|
54
|
+
? "codex-native"
|
|
55
|
+
: this.id === "opencode-native"
|
|
56
|
+
? "opencode-native"
|
|
57
|
+
: request.agent ?? "codex",
|
|
58
|
+
workspace: () => connection.workspace,
|
|
59
|
+
prepare: async (request, threadId) => {
|
|
60
|
+
const contextId = `lapis.instructions.${threadId}`;
|
|
61
|
+
const bootstrap = typeof request.metadata?.sessionBootstrap === "string"
|
|
62
|
+
? request.metadata.sessionBootstrap
|
|
63
|
+
: "";
|
|
64
|
+
let activation = projectSkillActivationPrompt("", request.skillActivations).trim();
|
|
65
|
+
return {
|
|
66
|
+
thread: {
|
|
67
|
+
contextSources: [contextId],
|
|
68
|
+
...(request.appToolSession?.bridgeId
|
|
69
|
+
? { toolEndpoint: request.appToolSession.bridgeId }
|
|
70
|
+
: {}),
|
|
71
|
+
...(request.appToolSession?.conversationId
|
|
72
|
+
? { externalRef: request.appToolSession.conversationId }
|
|
73
|
+
: {}),
|
|
74
|
+
},
|
|
75
|
+
endpoints: [
|
|
76
|
+
{
|
|
77
|
+
id: contextId,
|
|
78
|
+
context: true,
|
|
79
|
+
required: true,
|
|
80
|
+
handle: async (call) => {
|
|
81
|
+
if (call.operation === "context.authorize")
|
|
82
|
+
return true;
|
|
83
|
+
if (call.operation !== "context.resolve")
|
|
84
|
+
throw new Error("Unsupported instruction request.");
|
|
85
|
+
const instructions = [bootstrap, activation]
|
|
86
|
+
.filter(Boolean)
|
|
87
|
+
.join("\n\n");
|
|
88
|
+
activation = "";
|
|
89
|
+
return (instructions
|
|
90
|
+
? [
|
|
91
|
+
{
|
|
92
|
+
id: contextId,
|
|
93
|
+
revision: "1",
|
|
94
|
+
kind: "instructions",
|
|
95
|
+
trust: "instructions",
|
|
96
|
+
required: true,
|
|
97
|
+
content: instructions,
|
|
98
|
+
},
|
|
99
|
+
]
|
|
100
|
+
: []);
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
this.#runtimes.set(connection, runtime);
|
|
108
|
+
}
|
|
109
|
+
this.#last = runtime;
|
|
110
|
+
return runtime;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { AgentRuntime } from "../core/types";
|
|
2
|
-
|
|
2
|
+
import type { ControllerConnectionPool } from "./controller-connection";
|
|
3
|
+
export declare function createHostAgentRuntimes(connections: ControllerConnectionPool): AgentRuntime[];
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { hasNativeDesktopCapability } from "@lapis-notes/api/desktop-native";
|
|
2
|
-
import {
|
|
3
|
-
import { DesktopAcpRuntimeBackend } from "../runtimes/acp/desktop-acp-backend";
|
|
4
|
-
import { CodexNativeRuntime } from "../runtimes/codex/codex-runtime";
|
|
5
|
-
import { createAgentProcessHost } from "./desktop-process-host";
|
|
2
|
+
import { ControllerAgentRuntime } from "./controller-runtime";
|
|
6
3
|
import { hostLiveRuntimesEnabled } from "./host-runtime-availability";
|
|
7
|
-
export function createHostAgentRuntimes() {
|
|
4
|
+
export function createHostAgentRuntimes(connections) {
|
|
8
5
|
if (!hostLiveRuntimesEnabled(hasNativeDesktopCapability))
|
|
9
6
|
return [];
|
|
10
7
|
return [
|
|
11
|
-
new
|
|
12
|
-
new
|
|
8
|
+
new ControllerAgentRuntime("acp", connections),
|
|
9
|
+
new ControllerAgentRuntime("codex-native", connections),
|
|
10
|
+
new ControllerAgentRuntime("opencode-native", connections),
|
|
13
11
|
];
|
|
14
12
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -65,5 +65,5 @@ export { buildAgentBootstrap, buildSessionBootstrap } from "./bootstrap/build";
|
|
|
65
65
|
export { createMcpServerContributionRegistry } from "./tools/mcp-server-registry";
|
|
66
66
|
export { APP_TOOL_MCP_SERVER_NAME } from "./tools/mcp-server-registry";
|
|
67
67
|
export { AppToolApprovalBroker, AppToolExecutionError, AppToolHost, } from "./tools/app-tool-host";
|
|
68
|
-
export type { AppToolCall, AppToolExecutionErrorCode, AppToolPolicySettings, CreateAppToolSessionInput, } from "./tools/app-tool-host";
|
|
68
|
+
export type { AppToolCall, AppToolCapture, AppToolExecutionErrorCode, AppToolPolicySettings, CreateAppToolSessionInput, } from "./tools/app-tool-host";
|
|
69
69
|
export type { McpServerContributionRegistry } from "./tools/mcp-server-registry";
|
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { DurableMemoryKind } from "./types";
|
|
4
|
-
export type CandidateExtractionResult = {
|
|
5
|
-
examined: number;
|
|
6
|
-
staged: number;
|
|
7
|
-
review: number;
|
|
8
|
-
rejectedSecrets: number;
|
|
9
|
-
};
|
|
10
|
-
export type CandidateExtractionOptions = {
|
|
11
|
-
entries?: TranscriptEntry[];
|
|
12
|
-
yieldToApp?: () => Promise<void>;
|
|
13
|
-
};
|
|
14
|
-
export declare function extractDeterministicCandidates(snapshot: ConversationSnapshot, database: AppDatabase, options?: CandidateExtractionOptions): Promise<CandidateExtractionResult>;
|
|
15
|
-
declare function normalizeClaim(text: string): string;
|
|
16
|
-
declare function supersessionKey(text: string, kind: DurableMemoryKind): string | undefined;
|
|
17
|
-
declare function extractTriggers(claim: string): string[];
|
|
18
|
-
export declare function isSecretBearingMemoryText(text: string): boolean;
|
|
19
|
-
export declare const __candidateExtractorInternals: {
|
|
20
|
-
containsSecret: typeof isSecretBearingMemoryText;
|
|
21
|
-
extractTriggers: typeof extractTriggers;
|
|
22
|
-
normalizeClaim: typeof normalizeClaim;
|
|
23
|
-
supersessionKey: typeof supersessionKey;
|
|
24
|
-
};
|
|
25
|
-
export {};
|
|
1
|
+
export { extractDeterministicCandidates, isSecretBearingMemoryText, __candidateExtractorInternals, } from "@lapismd/ai-controller/memory/lapis";
|
|
2
|
+
export type { CandidateExtractionResult, CandidateExtractionOptions, } from "@lapismd/ai-controller/memory/lapis";
|
|
@@ -1,191 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { conversationMemoryScope } from "./paths";
|
|
3
|
-
const SECRET_PATTERNS = [
|
|
4
|
-
/-----BEGIN [A-Z ]*PRIVATE KEY-----/iu,
|
|
5
|
-
/\b(?:api[_ -]?key|password|passwd|secret|access[_ -]?token)\s*[:=]\s*\S+/iu,
|
|
6
|
-
/\b(?:sk|ghp|github_pat|xox[baprs])[-_][A-Za-z0-9_-]{16,}\b/u,
|
|
7
|
-
];
|
|
8
|
-
const EXPLICIT_CUE = /\b(?:remember(?:\s+that)?|i\s+prefer|we\s+decided|always\s+for\s+this\s+project)\b/iu;
|
|
9
|
-
const STABLE_CUE = /\b(?:prefer|uses?|must|should|decided|convention|workflow|constraint)\b/iu;
|
|
10
|
-
const STOP_WORDS = new Set([
|
|
11
|
-
"a",
|
|
12
|
-
"an",
|
|
13
|
-
"and",
|
|
14
|
-
"are",
|
|
15
|
-
"as",
|
|
16
|
-
"at",
|
|
17
|
-
"be",
|
|
18
|
-
"for",
|
|
19
|
-
"i",
|
|
20
|
-
"in",
|
|
21
|
-
"is",
|
|
22
|
-
"it",
|
|
23
|
-
"of",
|
|
24
|
-
"on",
|
|
25
|
-
"or",
|
|
26
|
-
"that",
|
|
27
|
-
"the",
|
|
28
|
-
"this",
|
|
29
|
-
"to",
|
|
30
|
-
"use",
|
|
31
|
-
"uses",
|
|
32
|
-
"we",
|
|
33
|
-
"with",
|
|
34
|
-
]);
|
|
35
|
-
export async function extractDeterministicCandidates(snapshot, database, options = {}) {
|
|
36
|
-
let examined = 0;
|
|
37
|
-
let staged = 0;
|
|
38
|
-
let review = 0;
|
|
39
|
-
let rejectedSecrets = 0;
|
|
40
|
-
const entries = options.entries ?? snapshot.transcript;
|
|
41
|
-
for (let index = 0; index < entries.length; index += 1) {
|
|
42
|
-
const entry = entries[index];
|
|
43
|
-
if (index > 0 && index % 200 === 0) {
|
|
44
|
-
await options.yieldToApp?.();
|
|
45
|
-
}
|
|
46
|
-
if (entry.type !== "message")
|
|
47
|
-
continue;
|
|
48
|
-
const originClass = entry.role === "user" ? "owner" : "agent";
|
|
49
|
-
if (!STABLE_CUE.test(entry.text) && !EXPLICIT_CUE.test(entry.text))
|
|
50
|
-
continue;
|
|
51
|
-
examined += 1;
|
|
52
|
-
if (isSecretBearingMemoryText(entry.text)) {
|
|
53
|
-
rejectedSecrets += 1;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const explicit = originClass === "owner" && EXPLICIT_CUE.test(entry.text);
|
|
57
|
-
const input = await candidateFromEntry(snapshot, entry, originClass, explicit);
|
|
58
|
-
const existing = (await database.queryMemoryCandidates({
|
|
59
|
-
scopeKind: input.candidate.scopeKind,
|
|
60
|
-
scopePath: input.candidate.scopePath,
|
|
61
|
-
limit: 10_000,
|
|
62
|
-
})).find((candidate) => candidate.candidate.id === input.candidate.id);
|
|
63
|
-
const origins = dedupeOrigins([
|
|
64
|
-
...(existing?.origins ?? []),
|
|
65
|
-
...input.origins,
|
|
66
|
-
]);
|
|
67
|
-
const conversations = new Set(origins.map((origin) => origin.conversationId));
|
|
68
|
-
const days = new Set(origins.map((origin) => new Date(origin.observedAt).toISOString().slice(0, 10)));
|
|
69
|
-
const qualifiesRecurring = conversations.size >= 2 && days.size >= 2;
|
|
70
|
-
const state = originClass === "agent"
|
|
71
|
-
? "review"
|
|
72
|
-
: explicit || qualifiesRecurring
|
|
73
|
-
? "staged"
|
|
74
|
-
: "review";
|
|
75
|
-
await database.upsertMemoryCandidate({
|
|
76
|
-
candidate: {
|
|
77
|
-
...(existing?.candidate ?? input.candidate),
|
|
78
|
-
lastSeenAt: Math.max(existing?.candidate.lastSeenAt ?? 0, input.candidate.lastSeenAt),
|
|
79
|
-
recurrenceCount: origins.length,
|
|
80
|
-
conversationCount: conversations.size,
|
|
81
|
-
state: existing?.candidate.state === "promoted"
|
|
82
|
-
? "promoted"
|
|
83
|
-
: state,
|
|
84
|
-
},
|
|
85
|
-
origins,
|
|
86
|
-
});
|
|
87
|
-
if (state === "staged")
|
|
88
|
-
staged += 1;
|
|
89
|
-
else
|
|
90
|
-
review += 1;
|
|
91
|
-
}
|
|
92
|
-
return { examined, staged, review, rejectedSecrets };
|
|
93
|
-
}
|
|
94
|
-
async function candidateFromEntry(snapshot, entry, originClass, explicit) {
|
|
95
|
-
const scope = candidateScope(snapshot.location.scopeDir, entry.text);
|
|
96
|
-
const normalizedClaim = normalizeClaim(entry.text);
|
|
97
|
-
const claimHash = await sha256Text(normalizedClaim.toLocaleLowerCase());
|
|
98
|
-
const scopePath = scope.kind === "project" ? scope.projectDir : "";
|
|
99
|
-
const kind = candidateKind(entry.text);
|
|
100
|
-
const id = await deterministicMemoryId("candidate", scope.kind, scopePath, kind, claimHash);
|
|
101
|
-
const observedAt = Date.parse(entry.createdAt);
|
|
102
|
-
return {
|
|
103
|
-
candidate: {
|
|
104
|
-
id,
|
|
105
|
-
scopeKind: scope.kind,
|
|
106
|
-
scopePath,
|
|
107
|
-
kind,
|
|
108
|
-
normalizedClaim,
|
|
109
|
-
claimHash,
|
|
110
|
-
...(supersessionKey(entry.text, kind)
|
|
111
|
-
? { supersessionKey: supersessionKey(entry.text, kind) }
|
|
112
|
-
: {}),
|
|
113
|
-
originClass,
|
|
114
|
-
importance: explicit ? 4 : 3,
|
|
115
|
-
triggers: extractTriggers(normalizedClaim),
|
|
116
|
-
state: originClass === "agent" ? "review" : explicit ? "staged" : "review",
|
|
117
|
-
firstSeenAt: observedAt,
|
|
118
|
-
lastSeenAt: observedAt,
|
|
119
|
-
recurrenceCount: 1,
|
|
120
|
-
conversationCount: 1,
|
|
121
|
-
},
|
|
122
|
-
origins: [
|
|
123
|
-
{
|
|
124
|
-
candidateId: id,
|
|
125
|
-
conversationId: snapshot.location.conversationId,
|
|
126
|
-
entryId: entry.id,
|
|
127
|
-
entryHash: await transcriptEntryHash(entry),
|
|
128
|
-
observedAt,
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function candidateScope(scopeDir, text) {
|
|
134
|
-
if (/\b(?:this|the)\s+project\b/iu.test(text) && scopeDir) {
|
|
135
|
-
return conversationMemoryScope(scopeDir);
|
|
136
|
-
}
|
|
137
|
-
if (/\b(?:i\s+prefer|my\s+preference)\b/iu.test(text)) {
|
|
138
|
-
return { kind: "user" };
|
|
139
|
-
}
|
|
140
|
-
return scopeDir
|
|
141
|
-
? conversationMemoryScope(scopeDir)
|
|
142
|
-
: { kind: "workspace" };
|
|
143
|
-
}
|
|
144
|
-
function normalizeClaim(text) {
|
|
145
|
-
return text
|
|
146
|
-
.replace(/^\s*(?:please\s+)?remember(?:\s+that)?\s+/iu, "")
|
|
147
|
-
.replace(/^\s*i\s+prefer\s+/iu, "Prefer ")
|
|
148
|
-
.replace(/^\s*we\s+decided\s+(?:that\s+|to\s+)?/iu, "")
|
|
149
|
-
.replace(/^\s*always\s+for\s+this\s+project[,;:]?\s*/iu, "")
|
|
150
|
-
.replace(/\s+/gu, " ")
|
|
151
|
-
.trim()
|
|
152
|
-
.replace(/[.!?]+$/u, "");
|
|
153
|
-
}
|
|
154
|
-
function candidateKind(text) {
|
|
155
|
-
if (/\bprefer(?:ence)?\b/iu.test(text))
|
|
156
|
-
return "preference";
|
|
157
|
-
if (/\bdecided\b/iu.test(text))
|
|
158
|
-
return "decision";
|
|
159
|
-
if (/\b(?:must|never|always|constraint)\b/iu.test(text))
|
|
160
|
-
return "constraint";
|
|
161
|
-
if (/\b(?:workflow|procedure|steps?|run|execute)\b/iu.test(text)) {
|
|
162
|
-
return "procedure";
|
|
163
|
-
}
|
|
164
|
-
return "fact";
|
|
165
|
-
}
|
|
166
|
-
function supersessionKey(text, kind) {
|
|
167
|
-
const normalized = normalizeClaim(text).toLocaleLowerCase();
|
|
168
|
-
const subject = /^(.{2,80}?)\s+(?:is|are|uses?|must|should)\b/u.exec(normalized)?.[1];
|
|
169
|
-
if (!subject)
|
|
170
|
-
return undefined;
|
|
171
|
-
return `${kind}:${subject.replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-|-$/gu, "")}`;
|
|
172
|
-
}
|
|
173
|
-
function extractTriggers(claim) {
|
|
174
|
-
const tokens = claim.toLocaleLowerCase().match(/[\p{L}\p{N}_-]+/gu) ?? [];
|
|
175
|
-
return [...new Set(tokens.filter((token) => token.length > 2 && !STOP_WORDS.has(token)))].slice(0, 8);
|
|
176
|
-
}
|
|
177
|
-
export function isSecretBearingMemoryText(text) {
|
|
178
|
-
return SECRET_PATTERNS.some((pattern) => pattern.test(text));
|
|
179
|
-
}
|
|
180
|
-
function dedupeOrigins(origins) {
|
|
181
|
-
return [...new Map(origins.map((origin) => [
|
|
182
|
-
`${origin.conversationId}\u0000${origin.entryId}`,
|
|
183
|
-
origin,
|
|
184
|
-
])).values()].sort((left, right) => `${left.conversationId}\u0000${left.entryId}`.localeCompare(`${right.conversationId}\u0000${right.entryId}`));
|
|
185
|
-
}
|
|
186
|
-
export const __candidateExtractorInternals = {
|
|
187
|
-
containsSecret: isSecretBearingMemoryText,
|
|
188
|
-
extractTriggers,
|
|
189
|
-
normalizeClaim,
|
|
190
|
-
supersessionKey,
|
|
191
|
-
};
|
|
1
|
+
export { extractDeterministicCandidates, isSecretBearingMemoryText, __candidateExtractorInternals, } from "@lapismd/ai-controller/memory/lapis";
|
package/dist/memory/hashes.d.ts
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function sha256Text(value: string): Promise<string>;
|
|
3
|
-
export declare function canonicalJson(value: unknown): string;
|
|
4
|
-
export declare function transcriptEntryHash(entry: TranscriptEntry): Promise<string>;
|
|
5
|
-
export declare function deterministicMemoryId(namespace: string, ...parts: string[]): Promise<string>;
|
|
1
|
+
export { sha256Text, canonicalJson, transcriptEntryHash, deterministicMemoryId, } from "@lapismd/ai-controller/memory/lapis";
|
package/dist/memory/hashes.js
CHANGED
|
@@ -1,37 +1 @@
|
|
|
1
|
-
|
|
2
|
-
if (value === null || typeof value === "boolean" || typeof value === "string") {
|
|
3
|
-
return JSON.stringify(value);
|
|
4
|
-
}
|
|
5
|
-
if (typeof value === "number") {
|
|
6
|
-
if (!Number.isFinite(value))
|
|
7
|
-
throw new Error("Cannot hash a non-finite number");
|
|
8
|
-
return JSON.stringify(value);
|
|
9
|
-
}
|
|
10
|
-
if (Array.isArray(value)) {
|
|
11
|
-
return `[${value.map(canonicalize).join(",")}]`;
|
|
12
|
-
}
|
|
13
|
-
if (typeof value === "object") {
|
|
14
|
-
const record = value;
|
|
15
|
-
return `{${Object.keys(record)
|
|
16
|
-
.filter((key) => record[key] !== undefined)
|
|
17
|
-
.sort()
|
|
18
|
-
.map((key) => `${JSON.stringify(key)}:${canonicalize(record[key])}`)
|
|
19
|
-
.join(",")}}`;
|
|
20
|
-
}
|
|
21
|
-
throw new Error(`Cannot hash ${typeof value}`);
|
|
22
|
-
}
|
|
23
|
-
export async function sha256Text(value) {
|
|
24
|
-
const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(value));
|
|
25
|
-
return [...new Uint8Array(digest)]
|
|
26
|
-
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
27
|
-
.join("");
|
|
28
|
-
}
|
|
29
|
-
export function canonicalJson(value) {
|
|
30
|
-
return canonicalize(value);
|
|
31
|
-
}
|
|
32
|
-
export function transcriptEntryHash(entry) {
|
|
33
|
-
return sha256Text(canonicalJson(entry));
|
|
34
|
-
}
|
|
35
|
-
export async function deterministicMemoryId(namespace, ...parts) {
|
|
36
|
-
return `${namespace}-${(await sha256Text(parts.join("\u0000"))).slice(0, 32)}`;
|
|
37
|
-
}
|
|
1
|
+
export { sha256Text, canonicalJson, transcriptEntryHash, deterministicMemoryId, } from "@lapismd/ai-controller/memory/lapis";
|
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
import { type Vault } from "@lapis-notes/api/vault";
|
|
2
|
-
import {
|
|
2
|
+
import { type MemoryRecordStore, type StoredMemoryRecord, type MemoryRecordWriteOptions, type DurableMemoryRecord, type MemoryScope } from "@lapismd/ai-controller/memory/lapis";
|
|
3
3
|
import type { ConversationLocation } from "../conversations/types";
|
|
4
|
-
|
|
5
|
-
export type StoredMemoryRecord
|
|
6
|
-
record: DurableMemoryRecord;
|
|
7
|
-
path: string;
|
|
8
|
-
hash: string;
|
|
9
|
-
content: string;
|
|
10
|
-
};
|
|
11
|
-
export type MemoryRecordWriteOptions = {
|
|
12
|
-
expectedCurrentHash?: string;
|
|
13
|
-
};
|
|
14
|
-
export interface MemoryRecordStore {
|
|
15
|
-
list(scope?: MemoryScope): Promise<StoredMemoryRecord[]>;
|
|
16
|
-
find(id: string): Promise<StoredMemoryRecord[]>;
|
|
17
|
-
write(record: DurableMemoryRecord, options?: MemoryRecordWriteOptions): Promise<StoredMemoryRecord>;
|
|
18
|
-
listHistory(id: string, scope: MemoryScope): Promise<DurableMemoryRecord[]>;
|
|
19
|
-
writeReview(scope: MemoryScope, jobId: string, markdown: string): Promise<string>;
|
|
20
|
-
listExcludedConversationIds(): Promise<Set<string>>;
|
|
21
|
-
writeConversationExclusion(location: ConversationLocation): Promise<string>;
|
|
22
|
-
}
|
|
23
|
-
export declare class MemoryRecordConflictError extends Error {
|
|
24
|
-
constructor(message: string);
|
|
25
|
-
}
|
|
4
|
+
export { InMemoryMemoryRecordStore, MemoryRecordConflictError, serializeMemoryRecord, validateMemoryRecord, recordPath, recordDirectory, memoryRoot, __memoryRecordStoreInternals, } from "@lapismd/ai-controller/memory/lapis";
|
|
5
|
+
export type { MemoryRecordStore, StoredMemoryRecord, MemoryRecordWriteOptions, } from "@lapismd/ai-controller/memory/lapis";
|
|
26
6
|
export declare class VaultMemoryRecordStore implements MemoryRecordStore {
|
|
27
7
|
private readonly vault;
|
|
28
8
|
constructor(vault: Vault);
|
|
@@ -35,28 +15,3 @@ export declare class VaultMemoryRecordStore implements MemoryRecordStore {
|
|
|
35
15
|
writeConversationExclusion(location: ConversationLocation): Promise<string>;
|
|
36
16
|
private writeImmutablePreimage;
|
|
37
17
|
}
|
|
38
|
-
export declare class InMemoryMemoryRecordStore implements MemoryRecordStore {
|
|
39
|
-
#private;
|
|
40
|
-
list(scope?: MemoryScope): Promise<StoredMemoryRecord[]>;
|
|
41
|
-
find(id: string): Promise<StoredMemoryRecord[]>;
|
|
42
|
-
write(record: DurableMemoryRecord, options?: MemoryRecordWriteOptions): Promise<StoredMemoryRecord>;
|
|
43
|
-
listHistory(id: string, scope: MemoryScope): Promise<DurableMemoryRecord[]>;
|
|
44
|
-
writeReview(scope: MemoryScope, jobId: string, markdown: string): Promise<string>;
|
|
45
|
-
listExcludedConversationIds(): Promise<Set<string>>;
|
|
46
|
-
writeConversationExclusion(location: ConversationLocation): Promise<string>;
|
|
47
|
-
}
|
|
48
|
-
export declare function memoryRoot(scope: MemoryScope): string;
|
|
49
|
-
export declare function recordDirectory(scope: MemoryScope): string;
|
|
50
|
-
export declare function recordPath(scope: MemoryScope, id: string): string;
|
|
51
|
-
declare function revisionDirectory(scope: MemoryScope, id: string): string;
|
|
52
|
-
export declare function serializeMemoryRecord(record: DurableMemoryRecord): string;
|
|
53
|
-
declare function parseStoredRecord(path: string, content: string): Promise<StoredMemoryRecord>;
|
|
54
|
-
export declare function validateMemoryRecord(value: unknown): DurableMemoryRecord;
|
|
55
|
-
declare function scopeKey(scope: MemoryScope): string;
|
|
56
|
-
export declare const __memoryRecordStoreInternals: {
|
|
57
|
-
parseStoredRecord: typeof parseStoredRecord;
|
|
58
|
-
revisionDirectory: typeof revisionDirectory;
|
|
59
|
-
scopeKey: typeof scopeKey;
|
|
60
|
-
canonicalJson: typeof canonicalJson;
|
|
61
|
-
};
|
|
62
|
-
export {};
|