aismemory 0.8.10 → 0.8.11
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 +25 -4
- package/dist/agent-key-mode.js +2 -15
- package/dist/ais-http-error.js +6 -4
- package/dist/cli/hooks.d.ts +5 -1
- package/dist/cli/hooks.js +38 -3
- package/dist/hydration.d.ts +1 -1
- package/dist/hydration.js +7 -2
- package/dist/index.js +72 -70
- package/dist/lesson-advice.d.ts +16 -0
- package/dist/lesson-advice.js +56 -0
- package/dist/lesson-tags.d.ts +6 -0
- package/dist/lesson-tags.js +7 -0
- package/dist/lessons.d.ts +2 -0
- package/dist/lessons.js +62 -0
- package/dist/library-tools.d.ts +22 -0
- package/dist/library-tools.js +72 -0
- package/dist/mcp/tools.js +11 -19
- package/dist/mcp-instructions.d.ts +1 -1
- package/dist/mcp-instructions.js +4 -1
- package/dist/pending-device-flow.js +1 -12
- package/dist/pipeline/bulk-store.d.ts +1 -0
- package/dist/pipeline/bulk-store.js +20 -0
- package/dist/run-pass-mode.js +2 -14
- package/dist/session-start.d.ts +2 -2
- package/dist/session-start.js +4 -3
- package/dist/tool-args.d.ts +16 -2
- package/dist/tool-args.js +77 -8
- package/dist/workspace-key-mode.js +2 -15
- package/package.json +1 -1
package/dist/tool-args.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Schemas mirror the JSON Schema declared in `tools` (index.ts) and AIS limits.
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
+
import { HUMAN_FACING_LESSON_TAG } from './lesson-tags.js';
|
|
6
7
|
/** Max content/query length for memories (matches AIS memory-handlers). */
|
|
7
8
|
export const MAX_MEMORY_CONTENT_LENGTH = 256 * 1024;
|
|
8
9
|
/** Max recall limit (matches AIS memory-handlers). */
|
|
@@ -60,6 +61,9 @@ export const rememberArgsSchema = z.object({
|
|
|
60
61
|
.min(REMEMBER_MIN_EXPIRES_IN, `expiresIn must be at least ${REMEMBER_MIN_EXPIRES_IN} seconds`)
|
|
61
62
|
.max(REMEMBER_MAX_EXPIRES_IN, `expiresIn must be at most ${REMEMBER_MAX_EXPIRES_IN} seconds`)
|
|
62
63
|
.optional(),
|
|
64
|
+
expiresAt: z.iso.datetime({ offset: true, error: 'expiresAt must be an ISO 8601 timestamp with a timezone' })
|
|
65
|
+
.refine((timestamp) => Date.parse(timestamp) > Date.now(), 'expiresAt must be in the future')
|
|
66
|
+
.optional(),
|
|
63
67
|
/**
|
|
64
68
|
* `true` returns the whole stored memory as AIS answered it, content
|
|
65
69
|
* included. Default: a short receipt (CORBOT-4E7001C5). Never sent to AIS.
|
|
@@ -89,6 +93,7 @@ const principalAgentIdSchema = z
|
|
|
89
93
|
.string()
|
|
90
94
|
.regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, 'principalAgentId must be a valid agent UUID');
|
|
91
95
|
export const recallArgsSchema = z.object({
|
|
96
|
+
fields: z.enum(['compact', 'verbose']).optional(),
|
|
92
97
|
principalAgentId: principalAgentIdSchema.optional(),
|
|
93
98
|
query: z
|
|
94
99
|
.string({ message: 'query is required and must be a string' })
|
|
@@ -116,6 +121,7 @@ export const recallArgsSchema = z.object({
|
|
|
116
121
|
* held to the UUID shape because it becomes a path segment.
|
|
117
122
|
*/
|
|
118
123
|
export const memoryGetArgsSchema = z.object({
|
|
124
|
+
fields: z.enum(['compact', 'verbose']).optional(),
|
|
119
125
|
id: z
|
|
120
126
|
.string({ message: 'id must be a memory UUID' })
|
|
121
127
|
.regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, 'id must be a memory UUID'),
|
|
@@ -157,6 +163,8 @@ export const agentLoadArgsSchema = z.object({
|
|
|
157
163
|
* makes no extra request, which is the answer shape before this field existed.
|
|
158
164
|
*/
|
|
159
165
|
start: z.boolean({ message: 'agent_load: start must be true or false' }).optional(),
|
|
166
|
+
/** The session harness, passed on to the loaded context as full_context does. */
|
|
167
|
+
harness: z.string().optional(),
|
|
160
168
|
});
|
|
161
169
|
/** Tools with no parameters — reject unexpected keys. */
|
|
162
170
|
export const emptyArgsSchema = z.object({}).strict();
|
|
@@ -322,6 +330,9 @@ export const inboxAckArgsSchema = z
|
|
|
322
330
|
* Pass `nowMs` in tests to fix the clock (defaults to Date.now).
|
|
323
331
|
*/
|
|
324
332
|
export function buildRememberStoreBody(args, nowMs = Date.now()) {
|
|
333
|
+
const expiresAt = args.expiresAt ?? (args.expiresIn === undefined
|
|
334
|
+
? undefined
|
|
335
|
+
: new Date(nowMs + args.expiresIn * 1000).toISOString());
|
|
325
336
|
return {
|
|
326
337
|
content: args.content,
|
|
327
338
|
type: args.type,
|
|
@@ -329,9 +340,7 @@ export function buildRememberStoreBody(args, nowMs = Date.now()) {
|
|
|
329
340
|
...(args.tags !== undefined && { tags: args.tags }),
|
|
330
341
|
...(args.supersedes !== undefined && { supersedes: args.supersedes }),
|
|
331
342
|
...(args.rollingKey !== undefined && { rollingKey: args.rollingKey }),
|
|
332
|
-
...(
|
|
333
|
-
expiresAt: new Date(nowMs + args.expiresIn * 1000).toISOString(),
|
|
334
|
-
}),
|
|
343
|
+
...(expiresAt !== undefined && { expiresAt }),
|
|
335
344
|
};
|
|
336
345
|
}
|
|
337
346
|
/** Internal hook capability; cannot be supplied through model JSON arguments. */
|
|
@@ -353,6 +362,9 @@ function parseOrThrow(schema, raw) {
|
|
|
353
362
|
}
|
|
354
363
|
export function parseRememberArgs(raw) {
|
|
355
364
|
const args = parseOrThrow(rememberArgsSchema, raw);
|
|
365
|
+
if (args.expiresAt !== undefined && args.expiresIn !== undefined) {
|
|
366
|
+
throw new Error('Use either expiresAt or expiresIn');
|
|
367
|
+
}
|
|
356
368
|
if (args.rollingKey !== undefined && args.supersedes !== undefined) {
|
|
357
369
|
throw new Error('rollingKey cannot be combined with supersedes; the key already names what this write replaces');
|
|
358
370
|
}
|
|
@@ -364,6 +376,20 @@ export function parseUpdateMemoryArgs(raw) {
|
|
|
364
376
|
export function parseRecallArgs(raw) {
|
|
365
377
|
return parseOrThrow(recallArgsSchema, raw);
|
|
366
378
|
}
|
|
379
|
+
export function buildRecallPath(agentId, args) {
|
|
380
|
+
const params = new URLSearchParams({ query: args.query, fields: args.fields ?? 'compact' });
|
|
381
|
+
if (args.limit !== undefined)
|
|
382
|
+
params.set('limit', String(args.limit));
|
|
383
|
+
if (args.type !== undefined)
|
|
384
|
+
params.set('types', args.type);
|
|
385
|
+
if (args.tags?.length)
|
|
386
|
+
params.set('tags', args.tags.join(','));
|
|
387
|
+
if (args.orderBy !== undefined)
|
|
388
|
+
params.set('orderBy', args.orderBy);
|
|
389
|
+
if (args.principalAgentId !== undefined)
|
|
390
|
+
params.set('principalAgentId', args.principalAgentId);
|
|
391
|
+
return `/v1/agents/${agentId}/memory?${params}`;
|
|
392
|
+
}
|
|
367
393
|
export function parseMemoryGetArgs(raw) {
|
|
368
394
|
return parseOrThrow(memoryGetArgsSchema, raw);
|
|
369
395
|
}
|
|
@@ -382,6 +408,35 @@ const MEMORY_GET_FIELDS = ['id', 'agentId', 'type', 'importance', 'createdAt', '
|
|
|
382
408
|
function isRecord(value) {
|
|
383
409
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
384
410
|
}
|
|
411
|
+
function compactMemory(memory, content, truncated) {
|
|
412
|
+
return {
|
|
413
|
+
id: memory['id'],
|
|
414
|
+
content,
|
|
415
|
+
createdAt: memory['createdAt'],
|
|
416
|
+
tags: memory['tags'],
|
|
417
|
+
type: memory['type'],
|
|
418
|
+
truncated,
|
|
419
|
+
trustLevel: memory['trustLevel'],
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
/** Older AIS servers ignore fields. Enforce the tool projection on their replies too. */
|
|
423
|
+
export function shapeRecallResult(raw, args) {
|
|
424
|
+
if (args.fields === 'verbose' || !isRecord(raw) || raw['success'] !== true || !isRecord(raw['data']))
|
|
425
|
+
return raw;
|
|
426
|
+
const data = raw['data'];
|
|
427
|
+
const memories = data['memories'];
|
|
428
|
+
if (!Array.isArray(memories))
|
|
429
|
+
return raw;
|
|
430
|
+
return {
|
|
431
|
+
...raw,
|
|
432
|
+
data: {
|
|
433
|
+
...data,
|
|
434
|
+
memories: memories.map((memory) => isRecord(memory)
|
|
435
|
+
? compactMemory(memory, memory['content'], memory['truncated'] === true)
|
|
436
|
+
: memory),
|
|
437
|
+
},
|
|
438
|
+
};
|
|
439
|
+
}
|
|
385
440
|
/**
|
|
386
441
|
* Turn the by-id route's answer into what an agent needs (CORBOT-023F7E5C):
|
|
387
442
|
* the text, capped at MEMORY_GET_MAX_CHARS from `offset` with the next offset
|
|
@@ -403,6 +458,15 @@ export function shapeMemoryGetResult(raw, args) {
|
|
|
403
458
|
if (end < whole.length && end - 1 > offset && last >= 0xd800 && last <= 0xdbff)
|
|
404
459
|
end -= 1;
|
|
405
460
|
const content = whole.slice(offset, end);
|
|
461
|
+
if (args.fields !== 'verbose') {
|
|
462
|
+
const truncated = end < whole.length;
|
|
463
|
+
return {
|
|
464
|
+
success: true,
|
|
465
|
+
notice: MEMORY_GET_NOTICE,
|
|
466
|
+
data: compactMemory(memory, content, truncated),
|
|
467
|
+
...(truncated && { nextOffset: end }),
|
|
468
|
+
};
|
|
469
|
+
}
|
|
406
470
|
const data = {};
|
|
407
471
|
for (const field of MEMORY_GET_FIELDS) {
|
|
408
472
|
if (memory[field] !== undefined)
|
|
@@ -425,16 +489,21 @@ export function shapeMemoryGetResult(raw, args) {
|
|
|
425
489
|
const REMEMBER_RECEIPT_FIELDS = ['id', 'agentId', 'tier', 'createdAt', 'tokenEstimate', 'supersedes', 'rollingKey', 'deduplicated', 'warning', 'flagged', 'flagReason'];
|
|
426
490
|
/**
|
|
427
491
|
* Turn AIS's store answer into a short receipt (CORBOT-4E7001C5): AIS sends
|
|
428
|
-
* the whole memory back, so a long note cost its length again.
|
|
429
|
-
*
|
|
492
|
+
* the whole memory back, so a long note cost its length again. Verbose answers
|
|
493
|
+
* keep the full memory. A newly stored human-facing lesson adds a notification
|
|
494
|
+
* flag in either form. Duplicate and error bodies pass through unchanged.
|
|
430
495
|
*/
|
|
431
496
|
export function shapeRememberResult(raw, args) {
|
|
432
|
-
if (args.verbose === true)
|
|
433
|
-
return raw;
|
|
434
497
|
if (!isRecord(raw) || raw['success'] !== true || raw['duplicate'] === true || !isRecord(raw['data']))
|
|
435
498
|
return raw;
|
|
436
499
|
const memory = raw['data'];
|
|
437
|
-
const
|
|
500
|
+
const tags = memory['tags'];
|
|
501
|
+
const surfaceToHuman = memory['type'] === 'lesson' && memory['deduplicated'] !== true
|
|
502
|
+
&& Array.isArray(tags) && tags.includes(HUMAN_FACING_LESSON_TAG);
|
|
503
|
+
if (args.verbose === true) {
|
|
504
|
+
return surfaceToHuman ? { ...raw, data: { ...memory, surfaceToHuman } } : raw;
|
|
505
|
+
}
|
|
506
|
+
const data = surfaceToHuman ? { surfaceToHuman } : {};
|
|
438
507
|
for (const field of REMEMBER_RECEIPT_FIELDS) {
|
|
439
508
|
if (memory[field] !== undefined)
|
|
440
509
|
data[field] = memory[field];
|
|
@@ -32,7 +32,7 @@ import { readInboxAndMaybeAck } from './inbox-client.js';
|
|
|
32
32
|
import { orientAgainstStoredManifest } from './cli/orientation-load.js';
|
|
33
33
|
import { AGENT_ARCHIVE_KEY_MODE_DETAIL } from './agent-archive.js';
|
|
34
34
|
import { fetchCredentialWhoami } from './credential-whoami.js';
|
|
35
|
-
import { parseEmptyToolArgs, parseRecallArgs, parseMemoryGetArgs, buildMemoryGetPath, shapeMemoryGetResult, buildFullContextQuery, parseFullContextArgs, buildRememberStoreBody, shapeRememberResult, parseRememberArgs, parseUpdateMemoryArgs, parseAgentLoadArgs, parseGoalCreateArgs, parseGoalListArgs, parseGoalUpdateProgressArgs, parseGoalActivateArgs, parseGoalCompleteArgs, parseInboxSendArgs, parseInboxReadArgs, parseInboxAckArgs, parseHandoffArgs, } from './tool-args.js';
|
|
35
|
+
import { parseEmptyToolArgs, parseRecallArgs, buildRecallPath, shapeRecallResult, parseMemoryGetArgs, buildMemoryGetPath, shapeMemoryGetResult, buildFullContextQuery, parseFullContextArgs, buildRememberStoreBody, shapeRememberResult, parseRememberArgs, parseUpdateMemoryArgs, parseAgentLoadArgs, parseGoalCreateArgs, parseGoalListArgs, parseGoalUpdateProgressArgs, parseGoalActivateArgs, parseGoalCompleteArgs, parseInboxSendArgs, parseInboxReadArgs, parseInboxAckArgs, parseHandoffArgs, } from './tool-args.js';
|
|
36
36
|
import { resolveDreamResponse } from './dream-poll.js';
|
|
37
37
|
import { forgetOwnMemory } from './memory-forget.js';
|
|
38
38
|
/** Thrown by loadWorkspaceKeyConfig when AIS_WORKSPACE_KEY is set without AIS_AGENT_ID. */
|
|
@@ -227,20 +227,7 @@ export async function dispatchToolWorkspaceKeyMode(aisUrl, config, name, rawArgs
|
|
|
227
227
|
}
|
|
228
228
|
case 'recall': {
|
|
229
229
|
const args = parseRecallArgs(rawArgs);
|
|
230
|
-
|
|
231
|
-
params.set('query', args.query);
|
|
232
|
-
if (args.limit !== undefined)
|
|
233
|
-
params.set('limit', String(args.limit));
|
|
234
|
-
if (args.type !== undefined)
|
|
235
|
-
params.set('types', args.type);
|
|
236
|
-
if (args.tags !== undefined && args.tags.length > 0)
|
|
237
|
-
params.set('tags', args.tags.join(','));
|
|
238
|
-
if (args.orderBy !== undefined)
|
|
239
|
-
params.set('orderBy', args.orderBy);
|
|
240
|
-
if (args.principalAgentId !== undefined) {
|
|
241
|
-
params.set('principalAgentId', args.principalAgentId);
|
|
242
|
-
}
|
|
243
|
-
return wksKeyGet(aisUrl, `/v1/agents/${agentId}/memory?${params}`, workspaceKey, fetchImpl);
|
|
230
|
+
return shapeRecallResult(await wksKeyGet(aisUrl, buildRecallPath(agentId, args), workspaceKey, fetchImpl), args);
|
|
244
231
|
}
|
|
245
232
|
case 'memory_get': {
|
|
246
233
|
const getArgs = parseMemoryGetArgs(rawArgs);
|
package/package.json
CHANGED