Skip to content

Commit 9f61213

Browse files
committed
Fix type issues
1 parent c0e0e32 commit 9f61213

7 files changed

Lines changed: 32 additions & 9 deletions

File tree

src/browser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export function createMemoryBank(config = {}) {
138138
}, doc, options);
139139
},
140140
compact: () => compactor.compactAll(),
141+
pruneExpired: () => compactor.pruneExpired(),
141142
storage: {
142143
read: (path) => backend.read(path),
143144
resolvePath: (path) => backend.resolvePath ? backend.resolvePath(path) : Promise.resolve(null),

src/internal/llm-client/openai.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,29 +275,39 @@ function getRetryDelay(attempt, retryAfterMs = null) {
275275
return Math.min(exponential + jitter, MAX_DELAY_MS);
276276
}
277277

278+
/**
279+
* @param {number} ms
280+
* @param {AbortSignal | null} [signal]
281+
* @returns {Promise<void>}
282+
*/
278283
function sleep(ms, signal = null) {
279-
return new Promise((resolve, reject) => {
284+
const abortSignal = signal;
285+
return /** @type {Promise<void>} */ (new Promise((resolve, reject) => {
280286
const timeoutId = setTimeout(() => {
281287
cleanup();
282288
resolve();
283289
}, ms);
284290

285291
const cleanup = () => {
286292
clearTimeout(timeoutId);
287-
signal?.removeEventListener?.('abort', onAbort);
293+
if (abortSignal) {
294+
abortSignal.removeEventListener('abort', onAbort);
295+
}
288296
};
289297
const onAbort = () => {
290298
cleanup();
291299
reject(createAbortError('OpenAI API request aborted.'));
292300
};
293301

294-
if (signal?.aborted) {
302+
if (abortSignal?.aborted) {
295303
onAbort();
296304
return;
297305
}
298306

299-
signal?.addEventListener?.('abort', onAbort, { once: true });
300-
});
307+
if (abortSignal) {
308+
abortSignal.addEventListener('abort', onAbort, { once: true });
309+
}
310+
}));
301311
}
302312

303313
async function createHttpError(response, attempt = 1) {

src/internal/llm-client/tinfoil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let tinfoilModulePromise = null;
3030
* Load TinfoilAI class. If a pre-loaded module is provided (e.g. a browser
3131
* bundle), use it directly. Otherwise fall back to `import('tinfoil')`.
3232
*
33-
* @param {object} [providedModule] pre-loaded tinfoil module (must export TinfoilAI)
33+
* @param {object} [providedModule] pre-loaded tinfoil module (must export TinfoilAI)
3434
*/
3535
async function loadTinfoilAI(providedModule) {
3636
if (providedModule) {

src/internal/toolLoop.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* uses non-streaming requests for reliable tool call parsing.
99
*/
1010
/** @import { ToolLoopOptions, ToolLoopResult, ChatCompletionResponse, ToolCall, LLMMessage } from '../types.js' */
11+
/**
12+
* @typedef {Error & { isUserAbort?: boolean }} AbortableError
13+
*/
1114

1215
const DEFAULT_MAX_ITERATIONS = 10;
1316
const DEFAULT_MAX_OUTPUT_TOKENS = 500;
@@ -233,7 +236,7 @@ export async function runAgenticToolLoop(options) {
233236
}
234237

235238
function createAbortError() {
236-
const error = new Error('Tool loop aborted.');
239+
const error = /** @type {AbortableError} */ (new Error('Tool loop aborted.'));
237240
error.name = 'AbortError';
238241
error.isUserAbort = true;
239242
return error;

src/tools/compaction.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ class MemoryCompactor {
103103
if (toExpire.length === 0) continue;
104104

105105
const expireLineIndexes = new Set(toExpire.map(b => b.lineIndex));
106+
/** @type {import('../types.js').Bullet[]} */
106107
const marked = bullets.map(b =>
107-
expireLineIndexes.has(b.lineIndex) ? { ...b, status: 'expired' } : b
108+
expireLineIndexes.has(b.lineIndex) ? { ...b, status: /** @type {'expired'} */ ('expired') } : b
108109
);
109110

110111
const defaultTopic = inferTopicFromPath(file.path);

src/tools/ingestion.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* agentic loop to decide whether to create/append/update memory files.
66
*/
77
/** @import { IngestOptions, IngestResult, LLMClient, Message, StorageBackend, ToolDefinition } from '../types.js' */
8+
/**
9+
* @typedef {Error & { isUserAbort?: boolean }} AbortableError
10+
*/
811
import { runAgenticToolLoop } from '../internal/toolLoop.js';
912
import { createExtractionExecutors } from './executors.js';
1013
import { resolvePromptSet } from '../prompts/index.js';
@@ -274,7 +277,7 @@ class MemoryIngester {
274277
}
275278

276279
function createAbortError() {
277-
const error = new Error('Memory ingestion aborted.');
280+
const error = /** @type {AbortableError} */ (new Error('Memory ingestion aborted.'));
278281
error.name = 'AbortError';
279282
error.isUserAbort = true;
280283
return error;

src/types.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
/**
6666
* @typedef {object} CompactBulletsOptions
6767
* @property {string} [today]
68+
* @property {string} [now]
6869
* @property {number} [maxActivePerTopic]
6970
* @property {string} [defaultTopic]
7071
*/
@@ -220,6 +221,7 @@
220221
* @property {{ path: string; content: string }[]} files
221222
* @property {string[]} paths
222223
* @property {string | null} assembledContext
224+
* @property {string} [displayText]
223225
* @property {boolean} skipped - true when existing context already covered the query
224226
* @property {string} [skipReason] - explanation when skipped=true
225227
*/
@@ -240,6 +242,7 @@
240242
* @property {string | null} reviewPrompt
241243
* @property {string | null} apiPrompt
242244
* @property {string | null} assembledContext
245+
* @property {string} [displayText]
243246
* @property {boolean} skipped - true when existing context already covered the query
244247
* @property {string} [skipReason] - explanation when skipped=true
245248
*/
@@ -360,6 +363,7 @@
360363
* @property {string} [configRepo]
361364
* @property {string} [attestationBundleURL]
362365
* @property {'ehbp' | 'tls'} [transport]
366+
* @property {Record<string, any>} [tinfoilModule]
363367
*/
364368

365369
/**
@@ -528,6 +532,7 @@
528532
* @property {(doc: OmfDocument, options?: OmfImportOptions) => Promise<OmfImportPreview>} previewOmfImport
529533
* @property {(doc: OmfDocument, options?: OmfImportOptions) => Promise<OmfImportResult>} importOmf
530534
* @property {() => Promise<{filesChanged: number, filesTotal: number} | undefined>} compact
535+
* @property {() => Promise<{archived: number, filesChanged: number}>} pruneExpired
531536
* @property {(query: string, options?: {deep?: boolean, mode?: string}) => Promise<{status: string, deleteCalls: number, writes: Array<any>}>} [deleteContent]
532537
* @property {StorageFacade} storage
533538
* @property {() => Promise<string>} serialize

0 commit comments

Comments
 (0)