@mysten-incubation/memwal 0.0.1-dev.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/README.md +59 -0
- package/dist/account-entry.d.ts +14 -0
- package/dist/account-entry.d.ts.map +1 -0
- package/dist/account-entry.js +14 -0
- package/dist/account-entry.js.map +1 -0
- package/dist/account.d.ts +87 -0
- package/dist/account.d.ts.map +1 -0
- package/dist/account.js +273 -0
- package/dist/account.js.map +1 -0
- package/dist/ai/index.d.ts +3 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +2 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/middleware.d.ts +55 -0
- package/dist/ai/middleware.d.ts.map +1 -0
- package/dist/ai/middleware.js +145 -0
- package/dist/ai/middleware.js.map +1 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/manual-entry.d.ts +12 -0
- package/dist/manual-entry.d.ts.map +1 -0
- package/dist/manual-entry.js +11 -0
- package/dist/manual-entry.js.map +1 -0
- package/dist/manual.d.ts +97 -0
- package/dist/manual.d.ts.map +1 -0
- package/dist/manual.js +498 -0
- package/dist/manual.js.map +1 -0
- package/dist/memwal.d.ts +174 -0
- package/dist/memwal.d.ts.map +1 -0
- package/dist/memwal.js +283 -0
- package/dist/memwal.js.map +1 -0
- package/dist/types.d.ts +237 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +38 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +84 -0
- package/dist/utils.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MemWal AI SDK Integration — withMemWal Middleware
|
|
3
|
+
*
|
|
4
|
+
* Wraps any AI SDK model with automatic memory management.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { generateText } from "ai"
|
|
9
|
+
* import { withMemWal } from "@mysten-incubation/memwal/ai"
|
|
10
|
+
* import { openai } from "@ai-sdk/openai"
|
|
11
|
+
*
|
|
12
|
+
* const model = withMemWal(openai("gpt-4o"), {
|
|
13
|
+
* key: process.env.MEMWAL_KEY, // Ed25519 delegate key (hex)
|
|
14
|
+
* })
|
|
15
|
+
*
|
|
16
|
+
* const result = await generateText({
|
|
17
|
+
* model,
|
|
18
|
+
* messages: [{ role: "user", content: "What do you know about me?" }]
|
|
19
|
+
* })
|
|
20
|
+
* // → Automatically searches memories, injects context, saves new facts
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import { wrapLanguageModel } from "ai";
|
|
24
|
+
import { MemWal } from "../memwal.js";
|
|
25
|
+
// ============================================================
|
|
26
|
+
// Middleware
|
|
27
|
+
// ============================================================
|
|
28
|
+
/**
|
|
29
|
+
* Wrap an AI SDK model with MemWal memory management
|
|
30
|
+
*
|
|
31
|
+
* BEFORE each LLM call:
|
|
32
|
+
* - Uses the last user message as a search query
|
|
33
|
+
* - Recalls relevant memories (server: search → download → decrypt)
|
|
34
|
+
* - Injects relevant memories into the system prompt
|
|
35
|
+
*
|
|
36
|
+
* AFTER each LLM call:
|
|
37
|
+
* - Analyzes and saves important facts (server: LLM extract → embed → encrypt → Walrus → store)
|
|
38
|
+
* - Fire-and-forget — does not block the response
|
|
39
|
+
*/
|
|
40
|
+
export function withMemWal(model, options) {
|
|
41
|
+
const memwal = MemWal.create(options);
|
|
42
|
+
const maxMemories = options.maxMemories ?? 5;
|
|
43
|
+
const autoSave = options.autoSave ?? true;
|
|
44
|
+
const minRelevance = options.minRelevance ?? 0.3;
|
|
45
|
+
const debug = options.debug ?? false;
|
|
46
|
+
const log = debug
|
|
47
|
+
? (...args) => console.warn("[MemWal]", ...args)
|
|
48
|
+
: () => { };
|
|
49
|
+
return wrapLanguageModel({
|
|
50
|
+
model,
|
|
51
|
+
middleware: {
|
|
52
|
+
specificationVersion: 'v3', // Required by ai SDK v6+; ignored by v4/v5
|
|
53
|
+
// ============================================================
|
|
54
|
+
// BEFORE: Search memories + inject into prompt
|
|
55
|
+
// ============================================================
|
|
56
|
+
transformParams: async ({ params }) => {
|
|
57
|
+
try {
|
|
58
|
+
const lastUserMessage = findLastUserMessage(params.prompt);
|
|
59
|
+
if (!lastUserMessage)
|
|
60
|
+
return params;
|
|
61
|
+
const recallResult = await memwal.recall(lastUserMessage, maxMemories);
|
|
62
|
+
// Filter by minimum relevance (distance < 1 - minRelevance)
|
|
63
|
+
const relevant = recallResult.results.filter((m) => (1 - m.distance) >= minRelevance);
|
|
64
|
+
if (relevant.length === 0)
|
|
65
|
+
return params;
|
|
66
|
+
const memoryContext = formatMemories(relevant);
|
|
67
|
+
const enrichedPrompt = injectMemoryContext(params.prompt, memoryContext);
|
|
68
|
+
log(`🔍 Found ${relevant.length} relevant memories`);
|
|
69
|
+
return { ...params, prompt: enrichedPrompt };
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
log("Memory search failed:", error);
|
|
73
|
+
return params;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
// ============================================================
|
|
77
|
+
// AFTER: Analyze and save important facts (fire-and-forget)
|
|
78
|
+
// ============================================================
|
|
79
|
+
wrapGenerate: async ({ doGenerate, params }) => {
|
|
80
|
+
const result = await doGenerate();
|
|
81
|
+
if (autoSave) {
|
|
82
|
+
const userMessage = findLastUserMessage(params.prompt);
|
|
83
|
+
if (userMessage) {
|
|
84
|
+
memwal.analyze(userMessage).catch((err) => log("Auto-save failed:", err));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
},
|
|
89
|
+
// Stream variant — needed for streamText()
|
|
90
|
+
wrapStream: async ({ doStream, params }) => {
|
|
91
|
+
const result = await doStream();
|
|
92
|
+
if (autoSave) {
|
|
93
|
+
const userMessage = findLastUserMessage(params.prompt);
|
|
94
|
+
if (userMessage) {
|
|
95
|
+
memwal.analyze(userMessage).catch((err) => log("Auto-save failed:", err));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// ============================================================
|
|
104
|
+
// Helpers
|
|
105
|
+
// ============================================================
|
|
106
|
+
function findLastUserMessage(prompt) {
|
|
107
|
+
if (!Array.isArray(prompt))
|
|
108
|
+
return null;
|
|
109
|
+
for (let i = prompt.length - 1; i >= 0; i--) {
|
|
110
|
+
const msg = prompt[i];
|
|
111
|
+
if (msg.role === "user") {
|
|
112
|
+
if (typeof msg.content === "string")
|
|
113
|
+
return msg.content;
|
|
114
|
+
if (Array.isArray(msg.content)) {
|
|
115
|
+
const textParts = msg.content
|
|
116
|
+
.filter((p) => p.type === "text")
|
|
117
|
+
.map((p) => p.text);
|
|
118
|
+
return textParts.join(" ") || null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
function formatMemories(memories) {
|
|
125
|
+
const lines = memories.map((m) => `- ${m.text} (relevance: ${(1 - m.distance).toFixed(2)})`);
|
|
126
|
+
return `[Memory Context] The following are known facts about this user from their personal memory store. Use these facts to answer the user's question:\n${lines.join("\n")}`;
|
|
127
|
+
}
|
|
128
|
+
function injectMemoryContext(prompt, memoryContext) {
|
|
129
|
+
if (!Array.isArray(prompt))
|
|
130
|
+
return prompt;
|
|
131
|
+
// Insert memory as a separate system message right before the last user message
|
|
132
|
+
// This ensures the LLM sees it prominently, not buried in a long system prompt
|
|
133
|
+
const lastUserIndex = prompt.reduce((idx, m, i) => (m.role === "user" ? i : idx), -1);
|
|
134
|
+
if (lastUserIndex > 0) {
|
|
135
|
+
const result = [...prompt];
|
|
136
|
+
result.splice(lastUserIndex, 0, {
|
|
137
|
+
role: "system",
|
|
138
|
+
content: memoryContext,
|
|
139
|
+
});
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
// Fallback: prepend as system message
|
|
143
|
+
return [{ role: "system", content: memoryContext }, ...prompt];
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/ai/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AA2BtC,+DAA+D;AAC/D,aAAa;AACb,+DAA+D;AAE/D;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CACtB,KAAuB,EACvB,OAA0B;IAE1B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC;IAC1C,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,GAAG,CAAC;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;IAErC,MAAM,GAAG,GAAG,KAAK;QACb,CAAC,CAAC,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC;QAC3D,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAEhB,OAAQ,iBAAyB,CAAC;QAC9B,KAAK;QACL,UAAU,EAAE;YACR,oBAAoB,EAAE,IAAI,EAAE,2CAA2C;YACvE,+DAA+D;YAC/D,+CAA+C;YAC/C,+DAA+D;YAC/D,eAAe,EAAE,KAAK,E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AAO,EAAE,aAAa;SACzB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,sCAAsC;IACtC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAiB,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,GAAG,MAAM,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAG7E,YAAY,EACR,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,aAAa,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc;AACd,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,qDAAqD;AACrD,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mysten-incubation/memwal
|
|
3
|
+
*
|
|
4
|
+
* Privacy-first AI memory SDK.
|
|
5
|
+
* Ed25519 delegate key auth + server-side TEE processing.
|
|
6
|
+
*
|
|
7
|
+
* This is the default entry point — MemWal client + types only.
|
|
8
|
+
* Does NOT import account.js (which requires @mysten/sui).
|
|
9
|
+
*
|
|
10
|
+
* For account management, import from "@mysten-incubation/memwal/account".
|
|
11
|
+
* For manual (client-side SEAL + Walrus), import from "@mysten-incubation/memwal/manual".
|
|
12
|
+
*/
|
|
13
|
+
export { MemWal } from "./memwal.js";
|
|
14
|
+
export { delegateKeyToSuiAddress, delegateKeyToPublicKey } from "./utils.js";
|
|
15
|
+
export type { MemWalConfig, RememberResult, RecallResult, RecallMemory, EmbedResult, AnalyzeResult, AnalyzedFact, HealthResult, RestoreResult, } from "./types.js";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAG7E,YAAY,EACR,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,aAAa,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mysten-incubation/memwal
|
|
3
|
+
*
|
|
4
|
+
* Privacy-first AI memory SDK.
|
|
5
|
+
* Ed25519 delegate key auth + server-side TEE processing.
|
|
6
|
+
*
|
|
7
|
+
* This is the default entry point — MemWal client + types only.
|
|
8
|
+
* Does NOT import account.js (which requires @mysten/sui).
|
|
9
|
+
*
|
|
10
|
+
* For account management, import from "@mysten-incubation/memwal/account".
|
|
11
|
+
* For manual (client-side SEAL + Walrus), import from "@mysten-incubation/memwal/manual".
|
|
12
|
+
*/
|
|
13
|
+
// Core client (server-mode: server handles SEAL + Walrus + embedding)
|
|
14
|
+
export { MemWal } from "./memwal.js";
|
|
15
|
+
// Delegate key utilities (no @mysten/sui dependency)
|
|
16
|
+
export { delegateKeyToSuiAddress, delegateKeyToPublicKey } from "./utils.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,sEAAsE;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,qDAAqD;AACrD,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mysten-incubation/memwal/manual
|
|
3
|
+
*
|
|
4
|
+
* Manual (client-side) mode entry point.
|
|
5
|
+
* Requires: @mysten/seal, @mysten/walrus, @mysten/sui
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { MemWalManual } from "@mysten-incubation/memwal/manual";
|
|
9
|
+
*/
|
|
10
|
+
export { MemWalManual } from "./manual.js";
|
|
11
|
+
export type { MemWalManualConfig, WalletSigner, RememberManualOptions, RememberManualResult, RecallManualOptions, RecallManualResult, RecallManualHit, RecallManualMemory, } from "./types.js";
|
|
12
|
+
//# sourceMappingURL=manual-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual-entry.d.ts","sourceRoot":"","sources":["../src/manual-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,YAAY,EACR,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,GACrB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mysten-incubation/memwal/manual
|
|
3
|
+
*
|
|
4
|
+
* Manual (client-side) mode entry point.
|
|
5
|
+
* Requires: @mysten/seal, @mysten/walrus, @mysten/sui
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { MemWalManual } from "@mysten-incubation/memwal/manual";
|
|
9
|
+
*/
|
|
10
|
+
export { MemWalManual } from "./manual.js";
|
|
11
|
+
//# sourceMappingURL=manual-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual-entry.js","sourceRoot":"","sources":["../src/manual-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/manual.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memwal — Manual Client (Full Client-Side)
|
|
3
|
+
*
|
|
4
|
+
* User-side flow where the SDK handles everything locally:
|
|
5
|
+
* - SEAL encrypt/decrypt via @mysten/seal (user's own Sui wallet)
|
|
6
|
+
* - Walrus upload/download via @mysten/walrus
|
|
7
|
+
* - Embedding via OpenAI-compatible API (user's own key)
|
|
8
|
+
* - Vector registration via MemWal server (Ed25519 signed)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { MemWalManual } from "@mysten-incubation/memwal"
|
|
13
|
+
*
|
|
14
|
+
* const memwal = MemWalManual.create({
|
|
15
|
+
* key: process.env.MEMWAL_DELEGATE_KEY!, // Ed25519 delegate key
|
|
16
|
+
* suiPrivateKey: process.env.SUI_PRIVATE_KEY!, // suiprivkey1... for SEAL + Walrus
|
|
17
|
+
* embeddingApiKey: process.env.OPENAI_API_KEY!,
|
|
18
|
+
* packageId: "0x...",
|
|
19
|
+
* accountId: "0x...",
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* // Remember — all client-side: embed → SEAL encrypt → Walrus upload → register
|
|
23
|
+
* await memwal.rememberManual("I'm allergic to peanuts")
|
|
24
|
+
*
|
|
25
|
+
* // Recall — all client-side: embed → search → download → SEAL decrypt
|
|
26
|
+
* const result = await memwal.recallManual("food allergies")
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import type { MemWalManualConfig, RememberManualResult, RecallManualResult, RestoreResult } from "./types.js";
|
|
30
|
+
export declare class MemWalManual {
|
|
31
|
+
private delegatePrivateKey;
|
|
32
|
+
private delegatePublicKey;
|
|
33
|
+
private serverUrl;
|
|
34
|
+
private config;
|
|
35
|
+
private walletSigner;
|
|
36
|
+
private namespace;
|
|
37
|
+
private _suiClient;
|
|
38
|
+
private _sealClient;
|
|
39
|
+
private _walrusClient;
|
|
40
|
+
private _keypair;
|
|
41
|
+
private constructor();
|
|
42
|
+
/**
|
|
43
|
+
* Create a new MemWalManual client.
|
|
44
|
+
*
|
|
45
|
+
* Requires peer dependencies: @mysten/sui, @mysten/seal, @mysten/walrus
|
|
46
|
+
*
|
|
47
|
+
* @param config.key - Ed25519 delegate private key (hex) for server auth
|
|
48
|
+
* @param config.suiPrivateKey - Sui private key (bech32) for SEAL + Walrus (OR walletSigner)
|
|
49
|
+
* @param config.walletSigner - Connected wallet signer from dapp-kit (OR suiPrivateKey)
|
|
50
|
+
* @param config.embeddingApiKey - OpenAI/OpenRouter API key for embeddings
|
|
51
|
+
* @param config.packageId - MemWal contract package ID
|
|
52
|
+
* @param config.accountId - MemWalAccount object ID (for SEAL seal_approve)
|
|
53
|
+
*/
|
|
54
|
+
static create(config: MemWalManualConfig): MemWalManual;
|
|
55
|
+
/** Whether this client uses a connected wallet signer (vs raw keypair) */
|
|
56
|
+
get isWalletMode(): boolean;
|
|
57
|
+
private getSuiClient;
|
|
58
|
+
private getKeypair;
|
|
59
|
+
/** Get the owner address — from wallet signer or derived from keypair */
|
|
60
|
+
private getOwnerAddress;
|
|
61
|
+
/** Sign and execute a transaction — via wallet popup or programmatic keypair */
|
|
62
|
+
private signAndExecuteTransaction;
|
|
63
|
+
private getSealClient;
|
|
64
|
+
private getWalrusClient;
|
|
65
|
+
/**
|
|
66
|
+
* Remember (hybrid flow):
|
|
67
|
+
* 1. Embed text (OpenAI/OpenRouter)
|
|
68
|
+
* 2. SEAL encrypt locally (no wallet signature needed)
|
|
69
|
+
* 3. Send {encrypted_data, vector} to server — server handles Walrus upload relay
|
|
70
|
+
*/
|
|
71
|
+
rememberManual(text: string, namespace?: string): Promise<RememberManualResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Recall (manual/full client-side):
|
|
74
|
+
* 1. Embed query (OpenAI)
|
|
75
|
+
* 2. Search server for matching vectors
|
|
76
|
+
* 3. Download blobs from Walrus
|
|
77
|
+
* 4. SEAL decrypt each blob
|
|
78
|
+
*/
|
|
79
|
+
recallManual(query: string, limit?: number, namespace?: string): Promise<RecallManualResult>;
|
|
80
|
+
/** Create a signer adapter — either from wallet or keypair */
|
|
81
|
+
private createSigner;
|
|
82
|
+
private embed;
|
|
83
|
+
private sealEncrypt;
|
|
84
|
+
private walrusUpload;
|
|
85
|
+
private walrusDownload;
|
|
86
|
+
private getDelegatePublicKey;
|
|
87
|
+
private signedRequest;
|
|
88
|
+
/**
|
|
89
|
+
* Restore a namespace — server downloads all blobs from Walrus,
|
|
90
|
+
* decrypts with delegate key, re-embeds, and re-indexes.
|
|
91
|
+
*
|
|
92
|
+
* @param namespace - Namespace to restore
|
|
93
|
+
* @returns RestoreResult with count of restored entries
|
|
94
|
+
*/
|
|
95
|
+
restore(namespace: string, limit?: number): Promise<RestoreResult>;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=manual.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual.d.ts","sourceRoot":"","sources":["../src/manual.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EACR,kBAAkB,EAElB,oBAAoB,EACpB,kBAAkB,EAElB,aAAa,EAChB,MAAM,YAAY,CAAC;AAuBpB,qBAAa,YAAY;IACrB,OAAO,CAAC,kBAAkB,CAAa;IACvC,OAAO,CAAC,iBAAiB,CAA2B;IACpD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO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