@3ngram/server 1.8.7 → 1.10.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/dist/app.d.ts +8 -5
- package/dist/app.js +40 -29
- package/dist/app.js.map +1 -1
- package/dist/cursor.d.ts +34 -3
- package/dist/cursor.js +40 -3
- package/dist/cursor.js.map +1 -1
- package/dist/mcp/errors.js +20 -2
- package/dist/mcp/errors.js.map +1 -1
- package/dist/mcp/resources.d.ts +16 -0
- package/dist/mcp/resources.js +59 -2
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/server.js +5 -0
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools-admin.js +92 -21
- package/dist/mcp/tools-admin.js.map +1 -1
- package/dist/mcp/tools-search.js +6 -1
- package/dist/mcp/tools-search.js.map +1 -1
- package/dist/mcp/tools.js +18 -8
- package/dist/mcp/tools.js.map +1 -1
- package/dist/middleware/rate-limit.d.ts +14 -5
- package/dist/middleware/rate-limit.js +21 -14
- package/dist/middleware/rate-limit.js.map +1 -1
- package/dist/rate-limit-store.d.ts +11 -0
- package/dist/rate-limit-store.js +41 -0
- package/dist/rate-limit-store.js.map +1 -0
- package/dist/rest/errors.js +15 -1
- package/dist/rest/errors.js.map +1 -1
- package/dist/rest/route-helpers.d.ts +9 -1
- package/dist/rest/route-helpers.js +16 -0
- package/dist/rest/route-helpers.js.map +1 -1
- package/dist/rest/router.js +95 -27
- package/dist/rest/router.js.map +1 -1
- package/dist/rest/search-router.js +3 -0
- package/dist/rest/search-router.js.map +1 -1
- package/dist/rest/session-router.js +7 -3
- package/dist/rest/session-router.js.map +1 -1
- package/dist/rest/settings-router.d.ts +2 -0
- package/dist/rest/settings-router.js +35 -0
- package/dist/rest/settings-router.js.map +1 -0
- package/dist/routes/oauth-token.d.ts +10 -13
- package/dist/routes/oauth-token.js +93 -78
- package/dist/routes/oauth-token.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../src/middleware/rate-limit.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,
|
|
1
|
+
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../src/middleware/rate-limit.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,sEAAsE;AACtE,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,oEAAoE;AACpE,+EAA+E;AAC/E,yDAAyD;AACzD,EAAE;AACF,yEAAyE;AACzE,8EAA8E;AAC9E,+EAA+E;AAC/E,iFAAiF;AACjF,6EAA6E;AAC7E,2EAA2E;AAC3E,6EAA6E;AAC7E,+EAA+E;AAC/E,gFAAgF;AAChF,gFAAgF;AAChF,+BAA+B;AAC/B,EAAE;AACF,uEAAuE;AACvE,4EAA4E;AAC5E,iFAAiF;AACjF,kFAAkF;AAClF,iFAAiF;AACjF,8BAA8B;AAC9B,EAAE;AACF,wEAAwE;AACxE,kFAAkF;AAClF,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAGxD,OAAO,EAGL,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,uBAAuB,CAAA;AAc9B,qFAAqF;AACrF,MAAM,CAAC,MAAM,KAAK,GAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAA;AAEjD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,SAAS,GAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAA;AAEzD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,WAAW,GAAgB,CAAC,GAAG,EAAE,EAAE;IAC9C,yEAAyE;IACzE,qEAAqE;IACrE,MAAM,MAAM,GACV,GAAG,CAAC,QAAQ,KAAK,SAAS;QACxB,CAAC,CAAC,GAAG,CAAC,QAAQ;Q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,EAAE;YACF,mEAAmE;YACnE,sEAAsE;YACtE,oDAAoD;YACpD,yEAAyE;YACzE,wEAAwE;YACxE,sEAAsE;YACtE,0EAA0E;YAC1E,kDAAkD;YAClD,qBAAqB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAA;YACpF,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,+BAA+B,CAAC,CAAA;YACvF,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,EAAE,CAAA;gBACN,OAAM;YACR,CAAC;YACD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAA;QACxD,CAAC,CAAC,CAAA;IACN,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Redis } from 'ioredis';
|
|
2
|
+
import type { RateLimitStore } from './middleware/rate-limit.js';
|
|
3
|
+
export declare class MemoryRateLimitStoreInProductionError extends Error {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Pick the store from RATE_LIMIT_STORE (unset: redis iff REDIS_URL, else
|
|
8
|
+
* memory). `redis` is the already-resolved client, if any; it is reused so the
|
|
9
|
+
* process dials Redis at most once.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveRateLimitStore(redis: Redis | undefined): RateLimitStore;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Resolve the rate-limiter backing store once at boot (#315). Env validation
|
|
3
|
+
// already refuses an implicit memory store in production; this re-checks it
|
|
4
|
+
// (defence in depth) so no code path makes memory a silent production default.
|
|
5
|
+
import { loadEnv, loadRateLimitStoreConfig, log } from '@3ngram/config';
|
|
6
|
+
import { resolveRedis } from './redis.js';
|
|
7
|
+
export class MemoryRateLimitStoreInProductionError extends Error {
|
|
8
|
+
name = 'MemoryRateLimitStoreInProductionError';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Pick the store from RATE_LIMIT_STORE (unset: redis iff REDIS_URL, else
|
|
12
|
+
* memory). `redis` is the already-resolved client, if any; it is reused so the
|
|
13
|
+
* process dials Redis at most once.
|
|
14
|
+
*/
|
|
15
|
+
export function resolveRateLimitStore(redis) {
|
|
16
|
+
const { kind, explicit } = loadRateLimitStoreConfig();
|
|
17
|
+
const production = loadEnv().NODE_ENV === 'production';
|
|
18
|
+
let store;
|
|
19
|
+
if (kind === 'redis') {
|
|
20
|
+
const client = redis ?? resolveRedis();
|
|
21
|
+
// Unreachable after env validation; fail closed rather than fall back.
|
|
22
|
+
if (client === undefined)
|
|
23
|
+
throw new Error('rate-limit: redis store selected without REDIS_URL');
|
|
24
|
+
store = { kind: 'redis', client };
|
|
25
|
+
}
|
|
26
|
+
else if (kind === 'postgres') {
|
|
27
|
+
store = { kind: 'postgres' };
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (production && !explicit) {
|
|
31
|
+
throw new MemoryRateLimitStoreInProductionError('rate-limit: in-memory store refused in production; set RATE_LIMIT_STORE=postgres or REDIS_URL');
|
|
32
|
+
}
|
|
33
|
+
if (production) {
|
|
34
|
+
log().warn({ store: 'memory' }, 'rate-limit: in-memory store in production (per-replica buckets; single replica only)');
|
|
35
|
+
}
|
|
36
|
+
store = { kind: 'memory' };
|
|
37
|
+
}
|
|
38
|
+
log().info({ store: store.kind }, 'rate-limit: store resolved');
|
|
39
|
+
return store;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=rate-limit-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit-store.js","sourceRoot":"","sources":["../src/rate-limit-store.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACt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AAC,IAAI,EAAE,EAAE,4BAA4B,CAAC,CAAA;IAC/D,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/dist/rest/errors.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
// bounded ids/hashes the typed error already carries (a uuid, a content hash, an
|
|
26
26
|
// FSM state — never content).
|
|
27
27
|
import { log } from '@3ngram/config';
|
|
28
|
-
import { AccessDeniedError, AccountDeletedError, AgentSessionNotFoundError, AgentSessionParamsConflictError, AgentSessionTriageConflictError, BudgetExceededError, CommitmentExistsError, CommitmentNotFoundError, CommitmentStateChangedError, DuplicateMemoryError, EdgeConflictError, EpisodicSupersessionError, formatUnscopedRetrievalDetail, IllegalCommitmentTransitionError, InvalidCommitmentTransitionError, InvalidEmbeddingError, MemoryNotFoundError, MissingSelectorError, NotCommitmentMemoryError, PredecessorAlreadySupersededError, PredecessorNotFoundError, ProposalNotFoundError, ResourceLimitExceededError, ScopeNameConflictError, ScopeNotFoundError, SuccessorNotLiveError, UnknownSessionRunError, UnscopedRetrievalError, } from '@3ngram/core';
|
|
28
|
+
import { AccessDeniedError, AccountDeletedError, AgentSessionNotFoundError, AgentSessionParamsConflictError, AgentSessionTriageConflictError, BudgetExceededError, CommitmentExistsError, CommitmentNotFoundError, CommitmentStateChangedError, DuplicateMemoryError, EdgeConflictError, EpisodicSupersessionError, formatUnscopedRetrievalDetail, IllegalCommitmentTransitionError, InvalidCommitmentTransitionError, InvalidEmbeddingError, MemoryNotFoundError, MissingSelectorError, NotCommitmentMemoryError, PredecessorAlreadySupersededError, PredecessorNotFoundError, ProposalNotFoundError, ResolveReasonNotSupportedError, ResourceLimitExceededError, ScopeNameConflictError, ScopeNotFoundError, SuccessorNotLiveError, UnknownSessionRunError, UnscopedRetrievalError, UnscopedWriteError, } from '@3ngram/core';
|
|
29
29
|
import { ZodError } from 'zod';
|
|
30
30
|
import { CursorQueryMismatchError } from '../cursor.js';
|
|
31
31
|
import { OutputValidationError } from '../output-validation.js';
|
|
@@ -58,6 +58,20 @@ export function mapRestError(route, err) {
|
|
|
58
58
|
detail: formatUnscopedRetrievalDetail(err.registeredScopes),
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
+
// A `remember` without scope rejected by the caller's own write-scope policy
|
|
62
|
+
// (mode 'require', issue #235): 400 invalid_input, with the fixed recovery
|
|
63
|
+
// text as detail (names the fix; no content). Mirrors MCP.
|
|
64
|
+
if (err instanceof UnscopedWriteError) {
|
|
65
|
+
log().warn({ route, err: err.name }, 'rest: unscoped write rejected by policy');
|
|
66
|
+
return { status: 400, reason: 'invalid_input', detail: err.message };
|
|
67
|
+
}
|
|
68
|
+
// A blocker resolve carrying a `reason` (issue #234): blockers have no
|
|
69
|
+
// commitment row to hold one. 400 invalid_input with the fixed recovery text
|
|
70
|
+
// as detail — never the reason itself. Mirrors MCP.
|
|
71
|
+
if (err instanceof ResolveReasonNotSupportedError) {
|
|
72
|
+
log().warn({ route, err: err.name }, 'rest: resolve reason rejected for a blocker');
|
|
73
|
+
return { status: 400, reason: 'invalid_input', detail: err.message };
|
|
74
|
+
}
|
|
61
75
|
// Malformed CLIENT input — a ZodError from a boundary INPUT .parse() or a
|
|
62
76
|
// typed core validation error — is a 400, not a server fault: only the error
|
|
63
77
|
// class name is logged.
|
package/dist/rest/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/rest/errors.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,gFAAgF;AAChF,gFAAgF;AAChF,0EAA0E;AAC1E,iFAAiF;AACjF,gFAAgF;AAChF,mEAAmE;AACnE,EAAE;AACF,uDAAuD;AACvD,qFAAqF;AACrF,sFAAsF;AACtF,wFAAwF;AACxF,uEAAuE;AACvE,wEAAwE;AACxE,0DAA0D;AAC1D,0FAA0F;AAC1F,oFAAoF;AACpF,+EAA+E;AAC/E,8EAA8E;AAC9E,iFAAiF;AACjF,oCAAoC;AACpC,EAAE;AACF,gFAAgF;AAChF,iFAAiF;AACjF,iFAAiF;AACjF,8BAA8B;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EACzB,+BAA+B,EAC/B,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,2BAA2B,EAC3B,oBAAoB,EACpB,iBAAiB,EACjB,yBAAyB,EACzB,6BAA6B,EAC7B,gCAAgC,EAChC,gCAAgC,EAChC,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,iCAAiC,EACjC,wBAAwB,EACxB,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/rest/errors.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,gFAAgF;AAChF,gFAAgF;AAChF,0EAA0E;AAC1E,iFAAiF;AACjF,gFAAgF;AAChF,mEAAmE;AACnE,EAAE;AACF,uDAAuD;AACvD,qFAAqF;AACrF,sFAAsF;AACtF,wFAAwF;AACxF,uEAAuE;AACvE,wEAAwE;AACxE,0DAA0D;AAC1D,0FAA0F;AAC1F,oFAAoF;AACpF,+EAA+E;AAC/E,8EAA8E;AAC9E,iFAAiF;AACjF,oCAAoC;AACpC,EAAE;AACF,gFAAgF;AAChF,iFAAiF;AACjF,iFAAiF;AACjF,8BAA8B;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EACzB,+BAA+B,EAC/B,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,2BAA2B,EAC3B,oBAAoB,EACpB,iBAAiB,EACjB,yBAAyB,EACzB,6BAA6B,EA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MAAM,EAAE,iBAAiB,EAAE,CAAA;IACnD,CAAC;IACD,IACE,GAAG,YAAY,gCAAgC;QAC/C,GAAG,YAAY,gCAAgC,EAC/C,CAAC;QACD,GAAG,EAAE,CAAC,IAAI,CACR,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,EACpD,qCAAqC,CACtC,CAAA;QACD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAA;IACtD,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AsOfInput, type FactsRangeInput } from '@3ngram/schema';
|
|
2
2
|
import type { Request, Response } from 'express';
|
|
3
3
|
/** Drop undefined values so exact-optional core parameters remain absent. */
|
|
4
4
|
export declare function defined<T extends Record<string, unknown>>(obj: T): {
|
|
5
5
|
[K in keyof T]?: Exclude<T[K], undefined>;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Merge the revise route's URL id into its body BEFORE the single parse (the
|
|
9
|
+
* URL wins): the predecessorId of a successor or move, the one-element
|
|
10
|
+
* memoryIds batch of a disposition (issue #217). A body predecessorId on a
|
|
11
|
+
* disposition is dropped rather than rejected, since the SDK sends it for every
|
|
12
|
+
* kind and the URL governs anyway.
|
|
13
|
+
*/
|
|
14
|
+
export declare function mergeReviseTarget(body: unknown, id: string | undefined): Record<string, unknown>;
|
|
7
15
|
/** Map optional ISO coordinates to core Date values. */
|
|
8
16
|
export declare function toAsOf(asOf: AsOfInput | undefined): {
|
|
9
17
|
validAt?: Date;
|
|
@@ -3,11 +3,27 @@
|
|
|
3
3
|
// authenticated tenant access, temporal coercion, and uniform error mapping.
|
|
4
4
|
import { log } from '@3ngram/config';
|
|
5
5
|
import { crashSafeError } from '@3ngram/config/otel';
|
|
6
|
+
import { reviseDispositionKindSchema } from '@3ngram/schema';
|
|
6
7
|
import { mapRestError } from './errors.js';
|
|
7
8
|
/** Drop undefined values so exact-optional core parameters remain absent. */
|
|
8
9
|
export function defined(obj) {
|
|
9
10
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined));
|
|
10
11
|
}
|
|
12
|
+
const DISPOSITION_KINDS = new Set(reviseDispositionKindSchema.options);
|
|
13
|
+
/**
|
|
14
|
+
* Merge the revise route's URL id into its body BEFORE the single parse (the
|
|
15
|
+
* URL wins): the predecessorId of a successor or move, the one-element
|
|
16
|
+
* memoryIds batch of a disposition (issue #217). A body predecessorId on a
|
|
17
|
+
* disposition is dropped rather than rejected, since the SDK sends it for every
|
|
18
|
+
* kind and the URL governs anyway.
|
|
19
|
+
*/
|
|
20
|
+
export function mergeReviseTarget(body, id) {
|
|
21
|
+
const fields = { ...body };
|
|
22
|
+
if (!DISPOSITION_KINDS.has(fields.kind))
|
|
23
|
+
return { ...fields, predecessorId: id };
|
|
24
|
+
const { predecessorId: _urlWins, ...rest } = fields;
|
|
25
|
+
return { ...rest, memoryIds: [id] };
|
|
26
|
+
}
|
|
11
27
|
/** Map optional ISO coordinates to core Date values. */
|
|
12
28
|
export function toAsOf(asOf) {
|
|
13
29
|
if (asOf === undefined)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-helpers.js","sourceRoot":"","sources":["../../src/rest/route-helpers.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,wEAAwE;AACxE,6EAA6E;AAC7E,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"route-helpers.js","sourceRoot":"","sources":["../../src/rest/route-helpers.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,wEAAwE;AACxE,6EAA6E;AAC7E,OAAO,EAAE,GAAG,EAAE,MAAM,gB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tE,IAAI,CAAC,GAAG,CAAC,WAAW;YAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAA;IACzE,CAAC;AACH,CAAC"}
|
package/dist/rest/router.js
CHANGED
|
@@ -20,15 +20,18 @@
|
|
|
20
20
|
// PARITY: this ships a SMOKE-level parity guarantee (REST remember -> the
|
|
21
21
|
// same content found via core search); FULL REST≡MCP≡core parity comes later.
|
|
22
22
|
import { log } from '@3ngram/config';
|
|
23
|
-
import { applyProposal, archiveMemory, briefing, deleteAccount, describeEnvironment, exportUserData, getAgentSessionRun, getBudgetStatus, getCurrentUser, getFacts, getMemoryById, getMemoryHistory, getSessionTriageAttempts, listMemories, listMemoryFacets,
|
|
24
|
-
import { accountDeleteBodySchema, archiveMemoryBodySchema, briefingToolInputV3Schema, factsQueryInputV2Schema, memoriesListQuerySchema, proposalRejectBodySchema, proposalsListQuerySchema, rememberToolInputV2Schema, resolveToolInputSchema, reviseToolRequestSchema, sessionEventsQuerySchema, sessionRunIdSchema, } from '@3ngram/schema';
|
|
23
|
+
import { applyProposal, archiveMemory, briefing, deleteAccount, describeEnvironment, exportUserData, getAgentSessionRun, getBudgetStatus, getCurrentUser, getFacts, getMemoryById, getMemoryHistory, getSessionTriageAttempts, listEdgeProposalsPage, listMemories, listMemoryFacets, listScopes, listSessionEvents, rejectProposal, remember, resolveByMemoryId, resolveRetrievalPolicy, revise, reviseDisposition, } from '@3ngram/core';
|
|
24
|
+
import { accountDeleteBodySchema, archiveMemoryBodySchema, briefingToolInputV3Schema, factsQueryInputV2Schema, memoriesListQuerySchema, proposalRejectBodySchema, proposalsListQuerySchema, proposalsListResponseSchema, rememberToolInputV2Schema, resolveToolInputSchema, reviseToolRequestSchema, sessionEventsQuerySchema, sessionRunIdSchema, } from '@3ngram/schema';
|
|
25
25
|
import { Router } from 'express';
|
|
26
26
|
import { z } from 'zod';
|
|
27
|
+
import { decodeProposalsCursor, encodeProposalsCursor, proposalsFingerprint } from '../cursor.js';
|
|
27
28
|
import { apiOrSessionAuth } from '../middleware/api-or-session.js';
|
|
29
|
+
import { parseOutput } from '../output-validation.js';
|
|
28
30
|
import { SERVER_VERSION } from '../version.js';
|
|
29
|
-
import { defined, guard, tenant, toAsOf, toRange } from './route-helpers.js';
|
|
31
|
+
import { defined, guard, mergeReviseTarget, tenant, toAsOf, toRange } from './route-helpers.js';
|
|
30
32
|
import { searchRouter } from './search-router.js';
|
|
31
33
|
import { sessionRouter } from './session-router.js';
|
|
34
|
+
import { settingsRouter } from './settings-router.js';
|
|
32
35
|
// A non-UUID :id path segment can never match a stored uuid column, so treat a
|
|
33
36
|
// malformed id the same as an unknown id (404) instead of letting Postgres raise
|
|
34
37
|
// a uuid cast error that guard()'s catch surfaces as a generic 500 (mirrors the
|
|
@@ -91,10 +94,13 @@ export function restRouter(options) {
|
|
|
91
94
|
// module for the same reason search has one: these routes share a concern
|
|
92
95
|
// with each other, not with the memory mirror.
|
|
93
96
|
router.use(sessionRouter(options));
|
|
97
|
+
// Tenant settings (the judgment opt-in, issue #225).
|
|
98
|
+
router.use(settingsRouter());
|
|
94
99
|
// POST /api/v1/memories — remember (mirrors the MCP remember tool). Core
|
|
95
100
|
// remember() is THE validation boundary; we re-parse here only to echo the
|
|
96
|
-
//
|
|
97
|
-
//
|
|
101
|
+
// normalized write (null project) in the response, exactly as the MCP tool
|
|
102
|
+
// does. The echoed scope is the one core WROTE (write-scope policy, #235).
|
|
103
|
+
// Embedding is ack-before-embed: never awaited.
|
|
98
104
|
router.post('/api/v1/memories', (req, res) => {
|
|
99
105
|
void guard('memories', res, async () => {
|
|
100
106
|
const input = rememberToolInputV2Schema.parse(req.body);
|
|
@@ -118,7 +124,7 @@ export function restRouter(options) {
|
|
|
118
124
|
id: written.id,
|
|
119
125
|
memoryType: input.memoryType,
|
|
120
126
|
topic: input.topic,
|
|
121
|
-
scope:
|
|
127
|
+
scope: written.scope,
|
|
122
128
|
project: input.project ?? null,
|
|
123
129
|
},
|
|
124
130
|
embedded,
|
|
@@ -338,7 +344,14 @@ export function restRouter(options) {
|
|
|
338
344
|
// GET /api/v1/memories/:id/history — identity-only lineage + audit trail for
|
|
339
345
|
// dashboard detail. Registered before /:id for route clarity. Returns no
|
|
340
346
|
// content and no raw audit payload values: only identity fields, typed edges,
|
|
341
|
-
// event kind/actor/time, and payload
|
|
347
|
+
// event kind/actor/time, payload metadata, and ALLOWLISTED payload keys as
|
|
348
|
+
// sibling fields — today only `sessionRunId` (issue #262), projected and
|
|
349
|
+
// re-parsed in packages/db the same way the agent-sessions events route
|
|
350
|
+
// narrows it, plus `createdBySessionRunId` (the run on this memory's own
|
|
351
|
+
// native `create` event). Both are ids, not content. The one content field is
|
|
352
|
+
// `lastResolutionReason` (issue #234): the owner's reason for the latest
|
|
353
|
+
// transition of the commitment riding this memory, returned only on this
|
|
354
|
+
// authenticated, tenant-scoped read and never logged.
|
|
342
355
|
router.get('/api/v1/memories/:id/history', (req, res) => {
|
|
343
356
|
void guard('memories.history', res, async () => {
|
|
344
357
|
const id = pathIdSchema.safeParse(req.params.id);
|
|
@@ -381,8 +394,11 @@ export function restRouter(options) {
|
|
|
381
394
|
actorKind: event.actorKind,
|
|
382
395
|
createdAt: event.createdAt.toISOString(),
|
|
383
396
|
payloadMetadata: event.payloadMetadata,
|
|
397
|
+
sessionRunId: event.sessionRunId,
|
|
384
398
|
})),
|
|
385
399
|
eventsTruncated: history.eventsTruncated,
|
|
400
|
+
createdBySessionRunId: history.createdBySessionRunId,
|
|
401
|
+
lastResolutionReason: history.lastResolutionReason,
|
|
386
402
|
sections: history.sections,
|
|
387
403
|
});
|
|
388
404
|
});
|
|
@@ -534,14 +550,23 @@ export function restRouter(options) {
|
|
|
534
550
|
});
|
|
535
551
|
});
|
|
536
552
|
// POST /api/v1/memories/:id/revise — revise (mirrors the MCP revise tool). The
|
|
537
|
-
// body is the full successor write,
|
|
538
|
-
//
|
|
539
|
-
//
|
|
540
|
-
//
|
|
553
|
+
// body is the full successor write, a `kind: "move"` refile (issue #233), or
|
|
554
|
+
// a `kind: "archive"` disposition (issue #217); core is THE validation
|
|
555
|
+
// boundary.
|
|
556
|
+
// :id is the target — merged into the body BEFORE the single parse, so the URL
|
|
557
|
+
// and body cannot disagree (the URL wins): as predecessorId for a successor or
|
|
558
|
+
// move, as the one-element memoryIds batch for a disposition.
|
|
541
559
|
router.post('/api/v1/memories/:id/revise', (req, res) => {
|
|
542
560
|
void guard('revise', res, async () => {
|
|
543
|
-
const
|
|
544
|
-
|
|
561
|
+
const input = reviseToolRequestSchema.parse(mergeReviseTarget(req.body, req.params.id));
|
|
562
|
+
// Only a disposition carries `memoryIds` (same dispatch as the MCP tool).
|
|
563
|
+
if ('memoryIds' in input) {
|
|
564
|
+
const result = await reviseDisposition(tenant(req), input, 'user_api', {
|
|
565
|
+
access: options.access,
|
|
566
|
+
});
|
|
567
|
+
res.status(200).json(result);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
545
570
|
const gatewayOpts = options.gateway === undefined
|
|
546
571
|
? { access: options.access, limits: options.limits }
|
|
547
572
|
: {
|
|
@@ -572,7 +597,8 @@ export function restRouter(options) {
|
|
|
572
597
|
// POST /api/v1/memories/:id/resolve — resolve (mirrors the MCP resolve tool,
|
|
573
598
|
// keyed on the MEMORY id from D1). :id -> memoryId merged with body -> status,
|
|
574
599
|
// THEN validated against resolveToolInputSchema (single boundary). Serves
|
|
575
|
-
// resolve AND unresolve (resolved -> open) — the FSM owns legality.
|
|
600
|
+
// resolve AND unresolve (resolved -> open) — the FSM owns legality. The
|
|
601
|
+
// optional `reason` (issue #234) passes straight through to core.
|
|
576
602
|
router.post('/api/v1/memories/:id/resolve', (req, res) => {
|
|
577
603
|
void guard('resolve', res, async () => {
|
|
578
604
|
const merged = { ...req.body, memoryId: req.params.id };
|
|
@@ -581,12 +607,13 @@ export function restRouter(options) {
|
|
|
581
607
|
// allowAllAccess allows all).
|
|
582
608
|
if (options.access)
|
|
583
609
|
await options.access.assertWrite(tenant(req));
|
|
584
|
-
const result = await resolveByMemoryId(tenant(req), input.memoryId, input.status, 'user_api', input.sessionRunId);
|
|
610
|
+
const result = await resolveByMemoryId(tenant(req), input.memoryId, input.status, 'user_api', input.sessionRunId, input.reason);
|
|
585
611
|
res.status(200).json({ commitmentId: result.id, status: result.status });
|
|
586
612
|
});
|
|
587
613
|
});
|
|
588
614
|
// POST /api/v1/memories/:id/archive — archive an active memory of ANY type
|
|
589
|
-
// (
|
|
615
|
+
// (the unguarded operator form; the agent-facing form is the revise archive
|
|
616
|
+
// disposition, issue #217, which rejects blockers and live commitments). status flips
|
|
590
617
|
// 'active' -> 'archived'; valid_to stays NULL, so the row lands in the archived
|
|
591
618
|
// bucket GET /memories?status=archived and GET /stats read. Optional body
|
|
592
619
|
// carries sessionRunId; omitted body is the same as {}. A malformed uuid path
|
|
@@ -608,29 +635,40 @@ export function restRouter(options) {
|
|
|
608
635
|
res.status(200).json({ id: archived.id, status: archived.status });
|
|
609
636
|
});
|
|
610
637
|
});
|
|
611
|
-
// GET /api/v1/proposals — bounded
|
|
612
|
-
//
|
|
613
|
-
//
|
|
614
|
-
//
|
|
638
|
+
// GET /api/v1/proposals — bounded, cursor-paginated EDGE-proposal list
|
|
639
|
+
// (issue #320). status/limit/cursor arrive as query params; limit is coerced
|
|
640
|
+
// before the single parse against proposalsListQuerySchema. The cursor is
|
|
641
|
+
// bound to the REST edge-only walk, the status filter and the tenant (hashed),
|
|
642
|
+
// so an MCP cursor, a cursor for another status, or another tenant's cursor is
|
|
643
|
+
// a 400. The route shapes the records (timestamps to ISO; rationale may be
|
|
644
|
+
// null) and validates the envelope against proposalsListResponseSchema
|
|
645
|
+
// (a shape fault is a 500 invalid_output, never a silently wrong page).
|
|
615
646
|
router.get('/api/v1/proposals', (req, res) => {
|
|
616
647
|
void guard('proposals.list', res, async () => {
|
|
617
648
|
const query = proposalsListQuerySchema.parse(defined({
|
|
618
649
|
status: req.query.status,
|
|
619
650
|
limit: req.query.limit === undefined ? undefined : Number(req.query.limit),
|
|
651
|
+
cursor: req.query.cursor,
|
|
620
652
|
}));
|
|
621
653
|
// ACCESS GUARD: proposals are memory-derived (consolidation candidates over
|
|
622
654
|
// the tenant's memories), so read access is asserted BEFORE the read
|
|
623
655
|
// (self-host allowAllAccess allows all).
|
|
624
656
|
if (options.access)
|
|
625
657
|
await options.access.assertRead(tenant(req));
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
658
|
+
const fp = proposalsFingerprint({
|
|
659
|
+
surface: 'rest',
|
|
660
|
+
kinds: ['edge'],
|
|
661
|
+
status: query.status,
|
|
662
|
+
tenant: tenant(req),
|
|
663
|
+
});
|
|
664
|
+
const after = query.cursor === undefined ? undefined : decodeProposalsCursor(query.cursor, fp);
|
|
665
|
+
const page = await listEdgeProposalsPage(tenant(req), {
|
|
666
|
+
status: query.status,
|
|
629
667
|
limit: query.limit,
|
|
630
|
-
|
|
668
|
+
after,
|
|
631
669
|
});
|
|
632
|
-
|
|
633
|
-
proposals: proposals.map((proposal) => ({
|
|
670
|
+
const body = parseOutput('proposals.list', proposalsListResponseSchema, {
|
|
671
|
+
proposals: page.proposals.map((proposal) => ({
|
|
634
672
|
id: proposal.id,
|
|
635
673
|
fromId: proposal.fromId,
|
|
636
674
|
toId: proposal.toId,
|
|
@@ -642,8 +680,13 @@ export function restRouter(options) {
|
|
|
642
680
|
decidedAt: proposal.decidedAt?.toISOString() ?? null,
|
|
643
681
|
createdAt: proposal.createdAt.toISOString(),
|
|
644
682
|
})),
|
|
645
|
-
count:
|
|
683
|
+
// `count` keeps its shipped meaning: rows on THIS page, never a total.
|
|
684
|
+
count: page.proposals.length,
|
|
685
|
+
totals: page.totals,
|
|
686
|
+
hasMore: page.hasMore,
|
|
687
|
+
...(page.next === undefined ? {} : { nextCursor: encodeProposalsCursor(page.next, fp) }),
|
|
646
688
|
});
|
|
689
|
+
res.status(200).json(body);
|
|
647
690
|
});
|
|
648
691
|
});
|
|
649
692
|
// POST /api/v1/proposals/:id/apply — accept a proposal over the
|
|
@@ -809,6 +852,7 @@ export function restRouter(options) {
|
|
|
809
852
|
recordedAt: memory.recordedAt.toISOString(),
|
|
810
853
|
createdAt: memory.createdAt.toISOString(),
|
|
811
854
|
updatedAt: memory.updatedAt.toISOString(),
|
|
855
|
+
lastReviewedAt: memory.lastReviewedAt?.toISOString() ?? null,
|
|
812
856
|
})),
|
|
813
857
|
facts: data.facts.map((fact) => ({
|
|
814
858
|
id: fact.id,
|
|
@@ -831,6 +875,7 @@ export function restRouter(options) {
|
|
|
831
875
|
recurrence: commitment.recurrence ?? null,
|
|
832
876
|
nextSurfacingAt: commitment.nextSurfacingAt?.toISOString() ?? null,
|
|
833
877
|
resolvedAt: commitment.resolvedAt?.toISOString() ?? null,
|
|
878
|
+
lastResolutionReason: commitment.lastResolutionReason ?? null,
|
|
834
879
|
createdAt: commitment.createdAt.toISOString(),
|
|
835
880
|
updatedAt: commitment.updatedAt.toISOString(),
|
|
836
881
|
})),
|
|
@@ -883,6 +928,15 @@ export function restRouter(options) {
|
|
|
883
928
|
decidedAt: proposal.decidedAt?.toISOString() ?? null,
|
|
884
929
|
createdAt: proposal.createdAt.toISOString(),
|
|
885
930
|
})),
|
|
931
|
+
resolutionProposals: data.resolutionProposals.map((proposal) => ({
|
|
932
|
+
id: proposal.id,
|
|
933
|
+
memoryId: proposal.memoryId,
|
|
934
|
+
sessionRunId: proposal.sessionRunId,
|
|
935
|
+
probability: proposal.probability,
|
|
936
|
+
status: proposal.status,
|
|
937
|
+
decidedAt: proposal.decidedAt?.toISOString() ?? null,
|
|
938
|
+
createdAt: proposal.createdAt.toISOString(),
|
|
939
|
+
})),
|
|
886
940
|
agentSessions: data.agentSessions.map((session) => ({
|
|
887
941
|
id: session.id,
|
|
888
942
|
agent: session.agent,
|
|
@@ -941,6 +995,19 @@ export function restRouter(options) {
|
|
|
941
995
|
updatedAt: data.retrievalPolicy.updatedAt.toISOString(),
|
|
942
996
|
}
|
|
943
997
|
: null,
|
|
998
|
+
writeScopePolicy: data.writeScopePolicy
|
|
999
|
+
? {
|
|
1000
|
+
mode: data.writeScopePolicy.mode,
|
|
1001
|
+
defaultScope: data.writeScopePolicy.defaultScope,
|
|
1002
|
+
updatedAt: data.writeScopePolicy.updatedAt.toISOString(),
|
|
1003
|
+
}
|
|
1004
|
+
: null,
|
|
1005
|
+
judgmentPolicy: data.judgmentPolicy
|
|
1006
|
+
? {
|
|
1007
|
+
mode: data.judgmentPolicy.mode,
|
|
1008
|
+
updatedAt: data.judgmentPolicy.updatedAt.toISOString(),
|
|
1009
|
+
}
|
|
1010
|
+
: null,
|
|
944
1011
|
counts: {
|
|
945
1012
|
memories: data.memories.length,
|
|
946
1013
|
facts: data.facts.length,
|
|
@@ -950,6 +1017,7 @@ export function restRouter(options) {
|
|
|
950
1017
|
memoryEvents: data.memoryEvents.length,
|
|
951
1018
|
proposals: data.proposals.length,
|
|
952
1019
|
factProposals: data.factProposals.length,
|
|
1020
|
+
resolutionProposals: data.resolutionProposals.length,
|
|
953
1021
|
agentSessions: data.agentSessions.length,
|
|
954
1022
|
userBudgets: data.userBudgets.length,
|
|
955
1023
|
llmUsage: data.llmUsage.length,
|