@mysten-incubation/memwal 0.1.8-dev.20 → 0.1.8-dev.22
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/dist/ai/middleware.d.ts.map +1 -1
- package/dist/ai/middleware.js +51 -6
- package/dist/ai/middleware.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/manual-entry.d.ts +2 -2
- package/dist/manual-entry.d.ts.map +1 -1
- package/dist/manual-entry.js +1 -1
- package/dist/manual.d.ts +21 -11
- package/dist/manual.d.ts.map +1 -1
- package/dist/manual.js +138 -92
- package/dist/manual.js.map +1 -1
- package/dist/memwal.d.ts +3 -3
- package/dist/memwal.d.ts.map +1 -1
- package/dist/memwal.js +20 -9
- package/dist/memwal.js.map +1 -1
- package/dist/mock.d.ts.map +1 -1
- package/dist/mock.js +7 -7
- package/dist/mock.js.map +1 -1
- package/dist/types.d.ts +15 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +19 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +46 -0
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/ai/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,aAAa,CAAC;AAU9D;;;;;GAKG;AAEH,KAAK,gBAAgB,GAAG,GAAG,CAAC;AAE5B,MAAM,WAAW,iBAAkB,SAAQ,YAAY;IACnD,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gFAAgF;IAChF,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC;8EAC0E;IAC1E,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CACtB,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/ai/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,aAAa,CAAC;AAU9D;;;;;GAKG;AAEH,KAAK,gBAAgB,GAAG,GAAG,CAAC;AAE5B,MAAM,WAAW,iBAAkB,SAAQ,YAAY;IACnD,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gFAAgF;IAChF,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC;8EAC0E;IAC1E,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CACtB,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,iBAAiB,OA4J7B;AA2CD,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,OAAO,EACf,aAAa,EAAE,MAAM,GACtB,OAAO,CAqCT"}
|
package/dist/ai/middleware.js
CHANGED
|
@@ -53,6 +53,9 @@ export function withMemWal(model, options) {
|
|
|
53
53
|
const pendingSaves = new Set();
|
|
54
54
|
const saveFailures = [];
|
|
55
55
|
let notingFailure = 0;
|
|
56
|
+
// Tool steps rebuild the prompt without the memory injected on step 1.
|
|
57
|
+
// Keep that recall and put it back, instead of calling recall again.
|
|
58
|
+
let cachedRecall = null;
|
|
56
59
|
function saveInBackground(userMessage) {
|
|
57
60
|
const savePromise = memwal
|
|
58
61
|
.analyze(userMessage)
|
|
@@ -86,18 +89,38 @@ export function withMemWal(model, options) {
|
|
|
86
89
|
// ============================================================
|
|
87
90
|
transformParams: async ({ params }) => {
|
|
88
91
|
try {
|
|
92
|
+
const turnKey = lastUserTurnKey(params.prompt);
|
|
93
|
+
if (!turnKey)
|
|
94
|
+
return params;
|
|
95
|
+
// Tool steps reuse this turn, including a recall that
|
|
96
|
+
// matched nothing. A user message always recalls again, so
|
|
97
|
+
// a later fact is not stuck behind the first result.
|
|
98
|
+
if (cachedRecall &&
|
|
99
|
+
cachedRecall.key === turnKey &&
|
|
100
|
+
!isPromptEndingWithUser(params.prompt)) {
|
|
101
|
+
if (!cachedRecall.context)
|
|
102
|
+
return params;
|
|
103
|
+
return {
|
|
104
|
+
...params,
|
|
105
|
+
prompt: injectMemoryContext(params.prompt, cachedRecall.context),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
89
108
|
const lastUserMessage = findLastUserMessage(params.prompt);
|
|
90
109
|
if (!lastUserMessage)
|
|
91
110
|
return params;
|
|
92
111
|
const recallResult = await memwal.recall(lastUserMessage, maxMemories);
|
|
93
|
-
// Filter by minimum relevance (distance < 1 - minRelevance)
|
|
94
112
|
const relevant = recallResult.results.filter((m) => (1 - m.distance) >= minRelevance);
|
|
95
|
-
if (relevant.length === 0)
|
|
113
|
+
if (relevant.length === 0) {
|
|
114
|
+
cachedRecall = { key: turnKey, context: "" };
|
|
96
115
|
return params;
|
|
116
|
+
}
|
|
97
117
|
const memoryContext = formatUntrustedMemories(relevant);
|
|
98
|
-
|
|
118
|
+
cachedRecall = { key: turnKey, context: memoryContext };
|
|
99
119
|
log(`🔍 Found ${relevant.length} relevant memories`);
|
|
100
|
-
return {
|
|
120
|
+
return {
|
|
121
|
+
...params,
|
|
122
|
+
prompt: injectMemoryContext(params.prompt, memoryContext),
|
|
123
|
+
};
|
|
101
124
|
}
|
|
102
125
|
catch (error) {
|
|
103
126
|
console.warn("[Walrus Memory] Recall failed during transformParams:", error);
|
|
@@ -115,7 +138,9 @@ export function withMemWal(model, options) {
|
|
|
115
138
|
// ============================================================
|
|
116
139
|
wrapGenerate: async ({ doGenerate, params }) => {
|
|
117
140
|
const result = await doGenerate();
|
|
118
|
-
|
|
141
|
+
// Only auto-save on the first step of a user turn, not on
|
|
142
|
+
// intermediate tool steps where the last message is tool/assistant.
|
|
143
|
+
if (autoSave && isPromptEndingWithUser(params.prompt)) {
|
|
119
144
|
const userMessage = findLastUserMessage(params.prompt);
|
|
120
145
|
if (userMessage) {
|
|
121
146
|
saveInBackground(userMessage);
|
|
@@ -126,7 +151,9 @@ export function withMemWal(model, options) {
|
|
|
126
151
|
// Stream variant — needed for streamText()
|
|
127
152
|
wrapStream: async ({ doStream, params }) => {
|
|
128
153
|
const result = await doStream();
|
|
129
|
-
|
|
154
|
+
// Only auto-save on the first step of a user turn, not on
|
|
155
|
+
// intermediate tool steps where the last message is tool/assistant.
|
|
156
|
+
if (autoSave && isPromptEndingWithUser(params.prompt)) {
|
|
130
157
|
const userMessage = findLastUserMessage(params.prompt);
|
|
131
158
|
if (userMessage) {
|
|
132
159
|
saveInBackground(userMessage);
|
|
@@ -173,6 +200,24 @@ function findLastUserMessage(prompt) {
|
|
|
173
200
|
}
|
|
174
201
|
return null;
|
|
175
202
|
}
|
|
203
|
+
function isPromptEndingWithUser(prompt) {
|
|
204
|
+
if (!Array.isArray(prompt) || prompt.length === 0)
|
|
205
|
+
return false;
|
|
206
|
+
const lastMsg = prompt[prompt.length - 1];
|
|
207
|
+
return lastMsg?.role === "user";
|
|
208
|
+
}
|
|
209
|
+
function lastUserTurnKey(prompt) {
|
|
210
|
+
if (!Array.isArray(prompt))
|
|
211
|
+
return null;
|
|
212
|
+
for (let i = prompt.length - 1; i >= 0; i--) {
|
|
213
|
+
const msg = prompt[i];
|
|
214
|
+
if (msg?.role !== "user")
|
|
215
|
+
continue;
|
|
216
|
+
const text = findLastUserMessage(prompt);
|
|
217
|
+
return text ? `${i}\0${text}` : null;
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
176
221
|
export function injectMemoryContext(prompt, memoryContext) {
|
|
177
222
|
if (!Array.isArray(prompt))
|
|
178
223
|
return prompt;
|
|
@@ -1 +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;AAEtC,OAAO,EACH,uBAAuB,EACvB,mCAAmC,GACtC,MAAM,uBAAuB,CAAC;AA+B/B,+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,iBAAiB,EAAE,GAAG,IAAI,CAAC;QAClE,CAAC,CAAC,GAAG,EAAE,GAAG,CA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AE,GAAG,OAAO,CAAC,OAAO,OAAO,mCAAmC,EAAE;SAC1E,CAAC;IACN,CAAC;SAAM,CAAC;QACJ,MAAM,CAAC,OAAO,CAAC;YACX,IAAI,EAAE,QAAiB;YACvB,OAAO,EAAE,mCAAmC;SAC/C,CAAC,CAAC;IACP,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -21,5 +21,5 @@ export { estimateTokens, truncateToTokenBudget, applyTokenBudget, validateMaxTok
|
|
|
21
21
|
export type { TokenCounter } from "./tokens.js";
|
|
22
22
|
export { createSponsorAuthorization, sponsorAuthorizationMessage, } from "./sponsor-auth.js";
|
|
23
23
|
export type { SponsorAuthorization, SponsorPersonalMessageSigner, } from "./sponsor-auth.js";
|
|
24
|
-
export type { MemWalConfig, RememberAcceptedResult, RememberJobStatus, RememberResult, RecallResult, RecallMemory, RecallOptions, RecallParams, RecallTokenMeta, TruncationStrategy, ScoringWeights, EmbedResult, AnalyzeOptions, AnalyzeResult, AnalyzeWaitResult, AnalyzedFact, HealthResult, RestoreResult, RememberBulkItem, RememberBulkOptions, RememberBulkAsyncOptions, RememberBulkAcceptedResult, RememberBulkStatusItem, RememberBulkStatusResult, RememberBulkResult, RememberBulkItemResult, RememberManualOptions, RememberManualResult, RecallManualOptions, RecallManualResult, RecallManualHit, MinSupportedSdk, RelayerBuildMetadata, RelayerDeprecationNotice, RelayerVersionMetadata, NamespaceSummary, NamespacesResult, ListNamespacesOptions, MemorySummary, DeletedMemorySummary, MemoriesResult, ListMemoriesOptions, } from "./types.js";
|
|
24
|
+
export type { MemWalConfig, RememberAcceptedResult, RememberJobStatus, RememberResult, RecallResult, RecallMemory, RecallOptions, RecallParams, RecallTokenMeta, TruncationStrategy, ScoringWeights, EmbedResult, AnalyzeOptions, AnalyzeResult, AnalyzeWaitResult, AnalyzedFact, HealthResult, RestoreResult, RememberBulkItem, RememberBulkOptions, RememberBulkAsyncOptions, RememberBulkAcceptedResult, RememberBulkStatusItem, RememberBulkStatusResult, RememberBulkResult, RememberBulkItemResult, RememberManualOptions, RememberManualResult, RecallManualOptions, RecallManualHitResult, RecallManualMemoryResult, RecallManualResult, RecallManualHit, MinSupportedSdk, RelayerBuildMetadata, RelayerDeprecationNotice, RelayerVersionMetadata, NamespaceSummary, NamespacesResult, ListNamespacesOptions, MemorySummary, DeletedMemorySummary, MemoriesResult, ListMemoriesOptions, } from "./types.js";
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EACH,uCAAuC,EACvC,wBAAwB,EACxB,2BAA2B,GAC9B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAG7E,OAAO,EACH,cAAc,EACd,yBAAyB,EACzB,4BAA4B,GAC/B,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EACH,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACH,0BAA0B,EAC1B,2BAA2B,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACR,oBAAoB,EACpB,4BAA4B,GAC/B,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EACR,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,mBAAmB,GACtB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EACH,uCAAuC,EACvC,wBAAwB,EACxB,2BAA2B,GAC9B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAG7E,OAAO,EACH,cAAc,EACd,yBAAyB,EACzB,4BAA4B,GAC/B,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EACH,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACH,0BAA0B,EAC1B,2BAA2B,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACR,oBAAoB,EACpB,4BAA4B,GAC/B,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EACR,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,mBAAmB,GACtB,MAAM,YAAY,CAAC"}
|
package/dist/manual-entry.d.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* @mysten-incubation/memwal/manual
|
|
3
3
|
*
|
|
4
4
|
* Manual (client-side) mode entry point.
|
|
5
|
-
* Requires: @mysten/seal, @mysten/
|
|
5
|
+
* Requires: @mysten/seal, @mysten/sui. Walrus downloads use HTTP, not @mysten/walrus.
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
* import { MemWalManual } from "@mysten-incubation/memwal/manual";
|
|
9
9
|
*/
|
|
10
10
|
export { MemWalManual } from "./manual.js";
|
|
11
11
|
export { MEMWAL_TYPESCRIPT_COMPATIBILITY_VERSION, MemWalCompatibilityError, SUPPORTED_RELAYER_API_MAJOR, } from "./compatibility.js";
|
|
12
|
-
export type { MemWalManualConfig, RelayerVersionMetadata, SealServerConfig, WalletSigner, ScoringWeights, RememberManualOptions, RememberManualResult, RecallManualOptions, MemWalManualRecallOptions, RecallManualResult, RecallManualHit, RecallManualMemory, } from "./types.js";
|
|
12
|
+
export type { MemWalManualConfig, RelayerVersionMetadata, SealServerConfig, WalletSigner, ScoringWeights, RememberManualOptions, RememberManualResult, RecallManualOptions, MemWalManualRecallOptions, RecallManualHitResult, RecallManualMemoryResult, RecallManualResult, RecallManualHit, RecallManualMemory, } from "./types.js";
|
|
13
13
|
//# sourceMappingURL=manual-entry.d.ts.map
|
|
@@ -1 +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;AAC3C,OAAO,EACH,uCAAuC,EACvC,wBAAwB,EACxB,2BAA2B,GAC9B,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACR,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,GACrB,MAAM,YAAY,CAAC"}
|
|
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;AAC3C,OAAO,EACH,uCAAuC,EACvC,wBAAwB,EACxB,2BAA2B,GAC9B,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACR,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,GACrB,MAAM,YAAY,CAAC"}
|
package/dist/manual-entry.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @mysten-incubation/memwal/manual
|
|
3
3
|
*
|
|
4
4
|
* Manual (client-side) mode entry point.
|
|
5
|
-
* Requires: @mysten/seal, @mysten/
|
|
5
|
+
* Requires: @mysten/seal, @mysten/sui. Walrus downloads use HTTP, not @mysten/walrus.
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
* import { MemWalManual } from "@mysten-incubation/memwal/manual";
|
package/dist/manual.d.ts
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* User-side flow where the SDK handles everything locally:
|
|
5
5
|
* - SEAL encrypt/decrypt via @mysten/seal (user's own Sui wallet)
|
|
6
|
-
* - Walrus upload
|
|
6
|
+
* - Walrus upload is done by the relayer; downloads use the HTTP aggregator
|
|
7
7
|
* - Embedding via OpenAI-compatible API (user's own key)
|
|
8
8
|
* - Vector registration via Walrus Memory server (Ed25519 signed)
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
12
|
-
* import { MemWalManual } from "@mysten-incubation/memwal"
|
|
12
|
+
* import { MemWalManual } from "@mysten-incubation/memwal/manual"
|
|
13
13
|
*
|
|
14
14
|
* const memwal = MemWalManual.create({
|
|
15
15
|
* key: process.env.MEMWAL_DELEGATE_KEY!, // Ed25519 delegate key
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* const result = await memwal.recallManual("food allergies")
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
import type { MemWalManualConfig, RememberManualResult,
|
|
30
|
+
import type { MemWalManualConfig, RememberManualResult, RecallManualMemoryResult, MemWalManualRecallOptions, RestoreResult, RelayerVersionMetadata } from "./types.js";
|
|
31
31
|
export declare class MemWalManual {
|
|
32
32
|
private delegatePrivateKey;
|
|
33
33
|
private delegatePublicKey;
|
|
@@ -39,15 +39,16 @@ export declare class MemWalManual {
|
|
|
39
39
|
private compatibilityPromise;
|
|
40
40
|
/** Per-round-trip budget for the compatibility preflight (WALM-598). */
|
|
41
41
|
private preflightTimeoutMs;
|
|
42
|
+
private sessionCache;
|
|
43
|
+
private sessionBuildPromise;
|
|
42
44
|
private _suiClient;
|
|
43
45
|
private _sealClient;
|
|
44
|
-
private _walrusClient;
|
|
45
46
|
private _keypair;
|
|
46
47
|
private constructor();
|
|
47
48
|
/**
|
|
48
49
|
* Create a new MemWalManual client.
|
|
49
50
|
*
|
|
50
|
-
* Requires peer dependencies: @mysten/sui, @mysten/seal
|
|
51
|
+
* Requires peer dependencies: @mysten/sui, @mysten/seal
|
|
51
52
|
*
|
|
52
53
|
* @param config.key - Ed25519 delegate private key (hex) for server auth
|
|
53
54
|
* @param config.suiPrivateKey - Sui private key (bech32) for SEAL + Walrus (OR walletSigner)
|
|
@@ -64,6 +65,13 @@ export declare class MemWalManual {
|
|
|
64
65
|
* Prevents key extraction from V8 heap dumps.
|
|
65
66
|
*/
|
|
66
67
|
destroy(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Build an ephemeral SEAL SessionKey, sign its personal message, and export
|
|
70
|
+
* it as a base64-encoded JSON envelope suitable for `x-seal-session`.
|
|
71
|
+
* Memoised until 30s before expiration (5m TTL).
|
|
72
|
+
*/
|
|
73
|
+
buildSealSession(): Promise<string>;
|
|
74
|
+
private buildSealSessionInner;
|
|
67
75
|
/**
|
|
68
76
|
* Fetch and validate the relayer compatibility contract.
|
|
69
77
|
*/
|
|
@@ -77,7 +85,6 @@ export declare class MemWalManual {
|
|
|
77
85
|
private getSealClient;
|
|
78
86
|
/** MED-10: SEAL threshold — defaults to 2, capped to configured server weight. */
|
|
79
87
|
private get sealThreshold();
|
|
80
|
-
private getWalrusClient;
|
|
81
88
|
/**
|
|
82
89
|
* Remember (hybrid flow):
|
|
83
90
|
* 1. Embed text (OpenAI/OpenRouter)
|
|
@@ -95,8 +102,8 @@ export declare class MemWalManual {
|
|
|
95
102
|
* `recallManual(query, { limit?, namespace? })` is valid.
|
|
96
103
|
* `recallManual(query, namespace)` throws `TypeError`.
|
|
97
104
|
*/
|
|
98
|
-
recallManual(query: string, options: MemWalManualRecallOptions): Promise<
|
|
99
|
-
recallManual(query: string, limit?: number, namespace?: string): Promise<
|
|
105
|
+
recallManual(query: string, options: MemWalManualRecallOptions): Promise<RecallManualMemoryResult>;
|
|
106
|
+
recallManual(query: string, limit?: number, namespace?: string): Promise<RecallManualMemoryResult>;
|
|
100
107
|
/** Create a signer adapter — either from wallet or keypair */
|
|
101
108
|
private createSigner;
|
|
102
109
|
private embed;
|
|
@@ -150,7 +157,6 @@ export declare class MemWalManual {
|
|
|
150
157
|
* back the id the blob was written under.
|
|
151
158
|
*/
|
|
152
159
|
private fetchSealIdentity;
|
|
153
|
-
private walrusUpload;
|
|
154
160
|
private walrusDownload;
|
|
155
161
|
private getDelegatePublicKey;
|
|
156
162
|
private ensureCompatibleRelayer;
|
|
@@ -165,8 +171,12 @@ export declare class MemWalManual {
|
|
|
165
171
|
*/
|
|
166
172
|
private signedRequest;
|
|
167
173
|
/**
|
|
168
|
-
* Restore a namespace
|
|
169
|
-
*
|
|
174
|
+
* Restore a namespace. The server downloads the blobs, decrypts them with
|
|
175
|
+
* the delegate key, and re-indexes them.
|
|
176
|
+
*
|
|
177
|
+
* Sends `x-seal-session` built from the delegate key, not the owner
|
|
178
|
+
* wallet. That session lets the relayer decrypt for this restore only,
|
|
179
|
+
* for the usual short TTL.
|
|
170
180
|
*
|
|
171
181
|
* @param namespace - Namespace to restore
|
|
172
182
|
* @returns RestoreResult with count of restored entries
|
package/dist/manual.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manual.d.ts","sourceRoot":"","sources":["../src/manual.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EACR,kBAAkB,EAElB,oBAAoB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AAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAsBrF;;;;;;;;;OASG;IACG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAClG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;IA4KxG,8DAA8D;YAChD,YAAY;YAuBZ,KAAK;IAqCnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;YACW,WAAW;IAqBzB;;;;;;;;;OASG;YACW,iBAAiB;YAgEjB,cAAc;YAoBd,oBAAoB;YAQpB,uBAAuB;YAUvB,0BAA0B;IAoCxC;;;;;;;OAOG;YACW,aAAa;IA4F3B;;;;;;;;;;OAUG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,OAAO,CAAC,aAAa,CAAC;CA4B/E"}
|
package/dist/manual.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* User-side flow where the SDK handles everything locally:
|
|
5
5
|
* - SEAL encrypt/decrypt via @mysten/seal (user's own Sui wallet)
|
|
6
|
-
* - Walrus upload
|
|
6
|
+
* - Walrus upload is done by the relayer; downloads use the HTTP aggregator
|
|
7
7
|
* - Embedding via OpenAI-compatible API (user's own key)
|
|
8
8
|
* - Vector registration via Walrus Memory server (Ed25519 signed)
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
12
|
-
* import { MemWalManual } from "@mysten-incubation/memwal"
|
|
12
|
+
* import { MemWalManual } from "@mysten-incubation/memwal/manual"
|
|
13
13
|
*
|
|
14
14
|
* const memwal = MemWalManual.create({
|
|
15
15
|
* key: process.env.MEMWAL_DELEGATE_KEY!, // Ed25519 delegate key
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* const result = await memwal.recallManual("food allergies")
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
import { sha256hex, hexToBytes, bytesToHex, normalizePrivateKey, u64ToLeHex, normalizeServerUrl, assertNonBlankText, sanitizeServerError, clockDriftErrorFromResponse, scoringWeightsToWire, fetchWithDeadline, DEFAULT_PREFLIGHT_TIMEOUT_MS, } from "./utils.js";
|
|
30
|
+
import { sha256hex, hexToBytes, bytesToHex, normalizePrivateKey, u64ToLeHex, normalizeServerUrl, assertNonBlankText, sanitizeServerError, clockDriftErrorFromResponse, scoringWeightsToWire, fetchWithDeadline, DEFAULT_PREFLIGHT_TIMEOUT_MS, RESTORE_REQUEST_TIMEOUT_MS, deadlineSignal, requestTimeoutError, } from "./utils.js";
|
|
31
31
|
import { assertCompatibleRelayer, compatibilityErrorFromStatus } from "./compatibility.js";
|
|
32
32
|
import { resolveLimitOrOptions } from "./recall-args.js";
|
|
33
33
|
import { createDefaultSuiClient } from "./sui-client.js";
|
|
@@ -105,6 +105,8 @@ function bytesToBase64(bytes) {
|
|
|
105
105
|
// ============================================================
|
|
106
106
|
// MemWalManual Client
|
|
107
107
|
// ============================================================
|
|
108
|
+
const SEAL_SESSION_TTL_MIN = 5;
|
|
109
|
+
const SEAL_SESSION_SAFETY_MARGIN_MS = 30_000;
|
|
108
110
|
export class MemWalManual {
|
|
109
111
|
delegatePrivateKey;
|
|
110
112
|
delegatePublicKey = null;
|
|
@@ -116,10 +118,11 @@ export class MemWalManual {
|
|
|
116
118
|
compatibilityPromise = null;
|
|
117
119
|
/** Per-round-trip budget for the compatibility preflight (WALM-598). */
|
|
118
120
|
preflightTimeoutMs;
|
|
121
|
+
sessionCache = null;
|
|
122
|
+
sessionBuildPromise = null;
|
|
119
123
|
// Lazily initialized heavy clients (typed as any to avoid peer dep compile errors)
|
|
120
124
|
_suiClient = null;
|
|
121
125
|
_sealClient = null;
|
|
122
|
-
_walrusClient = null;
|
|
123
126
|
_keypair = null;
|
|
124
127
|
constructor(config) {
|
|
125
128
|
if (!config.suiPrivateKey && !config.walletSigner) {
|
|
@@ -142,6 +145,9 @@ export class MemWalManual {
|
|
|
142
145
|
// against non-localhost hosts.
|
|
143
146
|
this.serverUrl = normalizeServerUrl(config.serverUrl ?? "https://relayer.memory.walrus.xyz");
|
|
144
147
|
this.walletSigner = config.walletSigner ?? null;
|
|
148
|
+
if (typeof config.accountId !== "string" || config.accountId.trim().length === 0) {
|
|
149
|
+
throw new TypeError(`MemWalManual.create: "accountId" is required (Walrus Memory object ID, e.g. 0x...); got ${config.accountId}`);
|
|
150
|
+
}
|
|
145
151
|
this.config = config;
|
|
146
152
|
if (config.namespace !== undefined && !config.namespace) {
|
|
147
153
|
throw new Error("namespace cannot be empty");
|
|
@@ -152,7 +158,7 @@ export class MemWalManual {
|
|
|
152
158
|
/**
|
|
153
159
|
* Create a new MemWalManual client.
|
|
154
160
|
*
|
|
155
|
-
* Requires peer dependencies: @mysten/sui, @mysten/seal
|
|
161
|
+
* Requires peer dependencies: @mysten/sui, @mysten/seal
|
|
156
162
|
*
|
|
157
163
|
* @param config.key - Ed25519 delegate private key (hex) for server auth
|
|
158
164
|
* @param config.suiPrivateKey - Sui private key (bech32) for SEAL + Walrus (OR walletSigner)
|
|
@@ -179,6 +185,66 @@ export class MemWalManual {
|
|
|
179
185
|
}
|
|
180
186
|
this.relayerVersionMetadata = null;
|
|
181
187
|
this.compatibilityPromise = null;
|
|
188
|
+
this.sessionCache = null;
|
|
189
|
+
this.sessionBuildPromise = null;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Build an ephemeral SEAL SessionKey, sign its personal message, and export
|
|
193
|
+
* it as a base64-encoded JSON envelope suitable for `x-seal-session`.
|
|
194
|
+
* Memoised until 30s before expiration (5m TTL).
|
|
195
|
+
*/
|
|
196
|
+
async buildSealSession() {
|
|
197
|
+
// Fast path: cached session still fresh.
|
|
198
|
+
if (this.sessionCache && Date.now() < this.sessionCache.expiresAt) {
|
|
199
|
+
return this.sessionCache.bytes;
|
|
200
|
+
}
|
|
201
|
+
// Single-flight: concurrent requests share one build.
|
|
202
|
+
if (this.sessionBuildPromise)
|
|
203
|
+
return this.sessionBuildPromise;
|
|
204
|
+
this.sessionBuildPromise = this.buildSealSessionInner().finally(() => {
|
|
205
|
+
this.sessionBuildPromise = null;
|
|
206
|
+
});
|
|
207
|
+
return this.sessionBuildPromise;
|
|
208
|
+
}
|
|
209
|
+
async buildSealSessionInner() {
|
|
210
|
+
// Same key MemWal uses. An owner wallet session prompts on every
|
|
211
|
+
// refresh and is broader than the delegate this client already holds.
|
|
212
|
+
// Dynamic imports: @mysten/sui and @mysten/seal are optional peers.
|
|
213
|
+
// Server-mode MemWal must still load when they are not installed.
|
|
214
|
+
const { Ed25519Keypair } = await import("@mysten/sui/keypairs/ed25519");
|
|
215
|
+
const keypair = Ed25519Keypair.fromSecretKey(this.delegatePrivateKey);
|
|
216
|
+
const suiClient = await this.getSuiClient();
|
|
217
|
+
const { SessionKey } = await import("@mysten/seal");
|
|
218
|
+
const session = await SessionKey.create({
|
|
219
|
+
address: keypair.getPublicKey().toSuiAddress(),
|
|
220
|
+
packageId: this.config.packageId,
|
|
221
|
+
ttlMin: SEAL_SESSION_TTL_MIN,
|
|
222
|
+
signer: keypair,
|
|
223
|
+
suiClient,
|
|
224
|
+
});
|
|
225
|
+
const personalMessage = session.getPersonalMessage();
|
|
226
|
+
const signResult = await keypair.signPersonalMessage(personalMessage);
|
|
227
|
+
await session.setPersonalMessageSignature(signResult.signature);
|
|
228
|
+
const exported = session.export();
|
|
229
|
+
const jsonStr = JSON.stringify({
|
|
230
|
+
address: exported.address,
|
|
231
|
+
packageId: exported.packageId,
|
|
232
|
+
mvrName: exported.mvrName,
|
|
233
|
+
creationTimeMs: exported.creationTimeMs,
|
|
234
|
+
ttlMin: exported.ttlMin,
|
|
235
|
+
personalMessageSignature: exported.personalMessageSignature,
|
|
236
|
+
sessionKey: exported.sessionKey,
|
|
237
|
+
});
|
|
238
|
+
const bytes = typeof btoa === "function"
|
|
239
|
+
? btoa(jsonStr)
|
|
240
|
+
: Buffer.from(jsonStr, "utf8").toString("base64");
|
|
241
|
+
this.sessionCache = {
|
|
242
|
+
bytes,
|
|
243
|
+
expiresAt: Date.now() +
|
|
244
|
+
SEAL_SESSION_TTL_MIN * 60_000 -
|
|
245
|
+
SEAL_SESSION_SAFETY_MARGIN_MS,
|
|
246
|
+
};
|
|
247
|
+
return bytes;
|
|
182
248
|
}
|
|
183
249
|
/**
|
|
184
250
|
* Fetch and validate the relayer compatibility contract.
|
|
@@ -253,26 +319,6 @@ export class MemWalManual {
|
|
|
253
319
|
const totalWeight = sealServerConfigTotalWeight(resolveSealServerConfigs(this.config, network));
|
|
254
320
|
return totalWeight > 0 ? Math.min(2, totalWeight) : 2;
|
|
255
321
|
}
|
|
256
|
-
async getWalrusClient() {
|
|
257
|
-
if (!this._walrusClient) {
|
|
258
|
-
// @ts-ignore — optional peer dependency
|
|
259
|
-
const { WalrusClient } = await import("@mysten/walrus");
|
|
260
|
-
const suiClient = await this.getSuiClient();
|
|
261
|
-
const network = this.config.suiNetwork ?? "mainnet";
|
|
262
|
-
const uploadRelayHost = network === "testnet"
|
|
263
|
-
? "https://upload-relay.testnet.walrus.space"
|
|
264
|
-
: "https://upload-relay.mainnet.walrus.space";
|
|
265
|
-
this._walrusClient = new WalrusClient({
|
|
266
|
-
network: network,
|
|
267
|
-
suiClient,
|
|
268
|
-
uploadRelay: {
|
|
269
|
-
host: uploadRelayHost,
|
|
270
|
-
sendTip: { max: 10_000_000 },
|
|
271
|
-
},
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
return this._walrusClient;
|
|
275
|
-
}
|
|
276
322
|
// ============================================================
|
|
277
323
|
// Core Manual API
|
|
278
324
|
// ============================================================
|
|
@@ -304,7 +350,10 @@ export class MemWalManual {
|
|
|
304
350
|
if (!query.trim())
|
|
305
351
|
throw new Error("Query cannot be empty");
|
|
306
352
|
const options = resolveLimitOrOptions("recallManual", limitOrOptions, namespace);
|
|
307
|
-
const limit = options.limit
|
|
353
|
+
const limit = options.limit !== undefined ? options.limit : 10;
|
|
354
|
+
if (typeof limit !== "number" || !Number.isInteger(limit) || limit <= 0) {
|
|
355
|
+
throw new TypeError(`limit must be a positive integer, got ${limit}`);
|
|
356
|
+
}
|
|
308
357
|
const ns = options.namespace ?? this.namespace;
|
|
309
358
|
// Step 1: Embed query
|
|
310
359
|
const vector = await this.embed(query);
|
|
@@ -604,38 +653,10 @@ export class MemWalManual {
|
|
|
604
653
|
};
|
|
605
654
|
}
|
|
606
655
|
// ============================================================
|
|
607
|
-
// Internal: Walrus
|
|
656
|
+
// Internal: Walrus download
|
|
608
657
|
// ============================================================
|
|
609
|
-
async walrusUpload(data) {
|
|
610
|
-
// Direct HTTP PUT to Walrus publisher (works in both browser and Node.js,
|
|
611
|
-
// unlike @mysten/walrus SDK which uses WASM and requires Node.js)
|
|
612
|
-
const network = this.config.suiNetwork ?? "mainnet";
|
|
613
|
-
const defaultPublisher = network === "testnet"
|
|
614
|
-
? "https://publisher.walrus-testnet.walrus.space"
|
|
615
|
-
: "https://publisher.walrus-mainnet.walrus.space";
|
|
616
|
-
const publisherUrl = this.config.walrusPublisherUrl ?? defaultPublisher;
|
|
617
|
-
const epochs = this.config.walrusEpochs ?? 50;
|
|
618
|
-
const resp = await fetch(`${publisherUrl}/v1/blobs?epochs=${epochs}&deletable=true`, {
|
|
619
|
-
method: "PUT",
|
|
620
|
-
headers: { "Content-Type": "application/octet-stream" },
|
|
621
|
-
body: data,
|
|
622
|
-
});
|
|
623
|
-
if (!resp.ok) {
|
|
624
|
-
const errText = await resp.text();
|
|
625
|
-
throw new Error(`Walrus upload failed (${resp.status}): ${errText}`);
|
|
626
|
-
}
|
|
627
|
-
const result = (await resp.json());
|
|
628
|
-
// Response can be { newlyCreated: { blobObject: { blobId } } }
|
|
629
|
-
// or { alreadyCertified: { blobId } }
|
|
630
|
-
const blobId = result.newlyCreated?.blobObject?.blobId ?? result.alreadyCertified?.blobId;
|
|
631
|
-
if (!blobId) {
|
|
632
|
-
throw new Error(`Walrus upload: unexpected response: ${JSON.stringify(result)}`);
|
|
633
|
-
}
|
|
634
|
-
return blobId;
|
|
635
|
-
}
|
|
636
658
|
async walrusDownload(blobId) {
|
|
637
|
-
// Direct HTTP fetch to Walrus aggregator
|
|
638
|
-
// unlike @mysten/walrus SDK which requires Node.js APIs)
|
|
659
|
+
// Direct HTTP fetch to the Walrus aggregator. Upload goes through the relayer.
|
|
639
660
|
const network = this.config.suiNetwork ?? "mainnet";
|
|
640
661
|
const defaultAggregator = network === "testnet"
|
|
641
662
|
? "https://aggregator.walrus-testnet.walrus.space"
|
|
@@ -699,7 +720,7 @@ export class MemWalManual {
|
|
|
699
720
|
*
|
|
700
721
|
* Headers sent: x-public-key, x-signature, x-timestamp, x-nonce, x-account-id.
|
|
701
722
|
*/
|
|
702
|
-
async signedRequest(method, path, body) {
|
|
723
|
+
async signedRequest(method, path, body, options = {}) {
|
|
703
724
|
await this.ensureCompatibleRelayer();
|
|
704
725
|
const ed = await import("@noble/ed25519");
|
|
705
726
|
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
@@ -713,58 +734,83 @@ export class MemWalManual {
|
|
|
713
734
|
const msgBytes = new TextEncoder().encode(message);
|
|
714
735
|
const signature = await ed.signAsync(msgBytes, this.delegatePrivateKey);
|
|
715
736
|
const publicKey = await this.getDelegatePublicKey();
|
|
737
|
+
const headers = {
|
|
738
|
+
"Content-Type": "application/json",
|
|
739
|
+
"x-public-key": bytesToHex(publicKey),
|
|
740
|
+
"x-signature": bytesToHex(signature),
|
|
741
|
+
"x-timestamp": timestamp,
|
|
742
|
+
"x-nonce": nonce,
|
|
743
|
+
"x-account-id": this.config.accountId,
|
|
744
|
+
};
|
|
745
|
+
if (options.includeSealSession) {
|
|
746
|
+
headers["x-seal-session"] = await this.buildSealSession();
|
|
747
|
+
}
|
|
716
748
|
const url = `${this.serverUrl}${path}`;
|
|
717
|
-
const
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
749
|
+
const deadline = options.timeoutMs ? deadlineSignal(options.timeoutMs, options.signal) : undefined;
|
|
750
|
+
try {
|
|
751
|
+
const res = await fetch(url, {
|
|
752
|
+
method,
|
|
753
|
+
headers,
|
|
754
|
+
body: bodyStr,
|
|
755
|
+
signal: deadline?.signal ?? options.signal,
|
|
756
|
+
});
|
|
757
|
+
if (!res.ok) {
|
|
758
|
+
const raw = await res.text();
|
|
759
|
+
const compatibilityError = compatibilityErrorFromStatus(res.status, raw);
|
|
760
|
+
if (compatibilityError)
|
|
761
|
+
throw compatibilityError;
|
|
762
|
+
const clockDriftError = clockDriftErrorFromResponse(res);
|
|
763
|
+
if (clockDriftError)
|
|
764
|
+
throw clockDriftError;
|
|
765
|
+
const { message: sanitized, serverCode } = sanitizeServerError(res.status, raw, res.headers.get("x-auth-error"));
|
|
766
|
+
const err = new Error(sanitized);
|
|
767
|
+
err.status = res.status;
|
|
768
|
+
if (serverCode)
|
|
769
|
+
err.serverCode = serverCode;
|
|
770
|
+
const retryAfter = Number(res.headers.get("retry-after"));
|
|
771
|
+
if (Number.isFinite(retryAfter) && retryAfter > 0) {
|
|
772
|
+
err.retryAfterSeconds = retryAfter;
|
|
773
|
+
}
|
|
774
|
+
err.cause = raw;
|
|
775
|
+
throw err;
|
|
776
|
+
}
|
|
777
|
+
return await res.json();
|
|
778
|
+
}
|
|
779
|
+
catch (err) {
|
|
780
|
+
const status = err && typeof err === "object" && "status" in err ? err.status : undefined;
|
|
781
|
+
if (deadline?.timedOut() && typeof status !== "number") {
|
|
782
|
+
throw requestTimeoutError(method, url, options.timeoutMs);
|
|
748
783
|
}
|
|
749
|
-
err.cause = raw;
|
|
750
784
|
throw err;
|
|
751
785
|
}
|
|
752
|
-
|
|
786
|
+
finally {
|
|
787
|
+
deadline?.dispose();
|
|
788
|
+
}
|
|
753
789
|
}
|
|
754
790
|
// ============================================================
|
|
755
791
|
// Restore
|
|
756
792
|
// ============================================================
|
|
757
793
|
/**
|
|
758
|
-
* Restore a namespace
|
|
759
|
-
*
|
|
794
|
+
* Restore a namespace. The server downloads the blobs, decrypts them with
|
|
795
|
+
* the delegate key, and re-indexes them.
|
|
796
|
+
*
|
|
797
|
+
* Sends `x-seal-session` built from the delegate key, not the owner
|
|
798
|
+
* wallet. That session lets the relayer decrypt for this restore only,
|
|
799
|
+
* for the usual short TTL.
|
|
760
800
|
*
|
|
761
801
|
* @param namespace - Namespace to restore
|
|
762
802
|
* @returns RestoreResult with count of restored entries
|
|
763
803
|
*/
|
|
764
804
|
async restore(namespace, limit = 10) {
|
|
805
|
+
if (typeof limit !== "number" || !Number.isInteger(limit) || limit <= 0) {
|
|
806
|
+
throw new TypeError(`limit must be a positive integer, got ${limit}`);
|
|
807
|
+
}
|
|
765
808
|
const result = await this.signedRequest("POST", "/api/restore", {
|
|
766
809
|
namespace,
|
|
767
810
|
limit,
|
|
811
|
+
}, {
|
|
812
|
+
includeSealSession: true,
|
|
813
|
+
timeoutMs: RESTORE_REQUEST_TIMEOUT_MS,
|
|
768
814
|
});
|
|
769
815
|
// Relayers older than WALM-319 omit `truncated` entirely — treat
|
|
770
816
|
// "not present" as "not known to be truncated" rather than drop
|