@axiom-lattice/protocols 7.6.0 → 7.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiom-lattice/protocols",
3
- "version": "7.6.0",
3
+ "version": "7.8.0",
4
4
  "description": "Unified protocol type definitions for Axiom Lattice framework",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1,6 +1,43 @@
1
1
  /** Channel types persisted by the installation store, including internal-only channels. */
2
2
  export type ChannelInstallationType = "lark" | "email" | "slack" | "wechat" | "wecom" | "room";
3
3
 
4
+ /**
5
+ * Installation config fields that must never be returned in plaintext from public
6
+ * installation APIs. Reads replace non-empty values with {@link CHANNEL_INSTALLATION_SECRET_MASK};
7
+ * writes treat the mask as "keep the stored value".
8
+ */
9
+ export const CHANNEL_INSTALLATION_SECRET_FIELDS = [
10
+ "appSecret",
11
+ "verificationToken",
12
+ "encryptKey",
13
+ "botToken",
14
+ "secret",
15
+ ] as const;
16
+
17
+ /** Placeholder returned in place of a stored channel secret. */
18
+ export const CHANNEL_INSTALLATION_SECRET_MASK = "********";
19
+
20
+ /**
21
+ * Return a copy of an installation with every non-empty secret replaced by
22
+ * {@link CHANNEL_INSTALLATION_SECRET_MASK}. Safe for public read surfaces and
23
+ * agent tools; the stored record is never mutated.
24
+ */
25
+ export function maskChannelInstallationSecrets<TConfig>(
26
+ installation: ChannelInstallation<TConfig>,
27
+ ): ChannelInstallation<TConfig> {
28
+ const config = installation.config;
29
+ if (config === null || typeof config !== "object" || Array.isArray(config)) {
30
+ return installation;
31
+ }
32
+ const masked: Record<string, unknown> = { ...(config as Record<string, unknown>) };
33
+ for (const field of CHANNEL_INSTALLATION_SECRET_FIELDS) {
34
+ if (typeof masked[field] === "string" && masked[field] !== "") {
35
+ masked[field] = CHANNEL_INSTALLATION_SECRET_MASK;
36
+ }
37
+ }
38
+ return { ...installation, config: masked as TConfig };
39
+ }
40
+
4
41
  /** Channel types exposed by the public installation management API. */
5
42
  export type PublicChannelInstallationType = Exclude<ChannelInstallationType, "room">;
6
43
 
@@ -122,7 +122,7 @@ export interface OpenAuditAppendInput {
122
122
  domain: string;
123
123
  action: string;
124
124
  args: unknown;
125
- status: "ok" | "error";
125
+ status: "ok" | "error" | "cancelled";
126
126
  errorCode?: string;
127
127
  durationMs: number;
128
128
  }
@@ -135,8 +135,10 @@ export interface OpenAuditRecord extends OpenAuditAppendInput {
135
135
  export interface OpenAuditQuery {
136
136
  tenantId: string;
137
137
  credentialId?: string;
138
+ projectId?: string;
138
139
  domain?: string;
139
- status?: "ok" | "error";
140
+ action?: string;
141
+ status?: "ok" | "error" | "cancelled";
140
142
  /** ISO timestamps; inclusive from / exclusive to. */
141
143
  from?: string;
142
144
  to?: string;
@@ -146,6 +148,8 @@ export interface OpenAuditQuery {
146
148
 
147
149
  export interface OpenAuditStore {
148
150
  append(record: OpenAuditAppendInput): Promise<void>;
151
+ /** Tenant-scoped detail lookup. */
152
+ get(tenantId: string, id: string): Promise<OpenAuditRecord | null>;
149
153
  /** Tenant-scoped, newest-first. */
150
154
  query(params: OpenAuditQuery): Promise<OpenAuditRecord[]>;
151
155
  }
@@ -112,9 +112,21 @@ export interface PlatformRateLimitPolicyOverride {
112
112
  enabled?: boolean;
113
113
  }
114
114
 
115
+ /** Runtime session policy shared by the gateway and the console. */
116
+ export interface PlatformSessionSettings {
117
+ refreshEnabled: boolean;
118
+ accessTtlSeconds: number;
119
+ refreshIdleSeconds: number;
120
+ refreshAbsoluteSeconds: number;
121
+ refreshReuseGraceSeconds: number;
122
+ }
123
+
115
124
  /** Persisted, partial platform settings document managed by platform admins. */
116
125
  export interface PlatformSettingsDocument {
117
- auth?: { emailCompletionEnabled?: boolean };
126
+ auth?: {
127
+ emailCompletionEnabled?: boolean;
128
+ session?: Partial<PlatformSessionSettings>;
129
+ };
118
130
  invite?: { defaultExpiresInHours?: number; defaultMaxUses?: number };
119
131
  rateLimits?: {
120
132
  /** Per-policy platform overrides keyed by policy name. */
@@ -135,7 +147,7 @@ export interface PlatformSettingsRecord extends PlatformSettingsDocument {
135
147
 
136
148
  /** Fully-resolved platform settings (no optional fields). */
137
149
  export interface EffectivePlatformSettings {
138
- auth: { emailCompletionEnabled: boolean };
150
+ auth: { emailCompletionEnabled: boolean; session: PlatformSessionSettings };
139
151
  invite: { defaultExpiresInHours: number; defaultMaxUses: number };
140
152
  rateLimits: {
141
153
  openApiPerMinute: number;
@@ -192,7 +204,16 @@ export class PlatformSettingsVersionConflictError extends Error {
192
204
 
193
205
  /** Built-in fallback values used when neither platform nor env set a value. */
194
206
  export const PLATFORM_SETTINGS_DEFAULTS = {
195
- auth: { emailCompletionEnabled: false },
207
+ auth: {
208
+ emailCompletionEnabled: false,
209
+ session: {
210
+ refreshEnabled: true,
211
+ accessTtlSeconds: 86400,
212
+ refreshIdleSeconds: 604800,
213
+ refreshAbsoluteSeconds: 2592000,
214
+ refreshReuseGraceSeconds: 20,
215
+ },
216
+ },
196
217
  invite: { defaultExpiresInHours: 168, defaultMaxUses: 1 },
197
218
  rateLimits: {
198
219
  openApiPerMinute: 60_000,
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Server-side refresh sessions.
3
+ *
4
+ * A session family is created at login and rotated on every refresh. Access
5
+ * tokens remain stateless and carry a user-level `epoch`; this store backs
6
+ * refresh rotation, single-session logout, reuse detection, and device listing.
7
+ */
8
+
9
+ export interface SessionRecord {
10
+ id: string;
11
+ familyId: string;
12
+ userId: string;
13
+ tenantId?: string;
14
+ /** Snapshot of `user.authEpoch` at creation/rotation; refresh must match. */
15
+ authEpoch: string;
16
+ refreshTokenHash: string;
17
+ createdAt: Date;
18
+ lastUsedAt: Date;
19
+ idleExpiresAt: Date;
20
+ absoluteExpiresAt: Date;
21
+ revokedAt?: Date;
22
+ replacedBy?: string;
23
+ ip?: string;
24
+ userAgent?: string;
25
+ providerId: "local" | `oidc:${string}`;
26
+ /** Encrypted IdP refresh token (Phase 2). */
27
+ idpRefreshTokenEnc?: string;
28
+ idpRefreshExpiresAt?: Date;
29
+ }
30
+
31
+ export interface SessionStore {
32
+ create(record: SessionRecord): Promise<void>;
33
+ findByRefreshTokenHash(hash: string): Promise<SessionRecord | null>;
34
+ findByFamilyId(familyId: string): Promise<SessionRecord | null>;
35
+ rotate(oldId: string, next: SessionRecord): Promise<void>;
36
+ revokeFamily(familyId: string, reason: string): Promise<void>;
37
+ revokeAllForUser(userId: string, reason: string): Promise<void>;
38
+ touch(id: string, lastUsedAt: Date): Promise<void>;
39
+ listForUser(userId: string): Promise<SessionRecord[]>;
40
+ }
@@ -147,4 +147,103 @@ export interface ThreadStore {
147
147
  * @returns Expired threads ordered by `expiresAt` ascending.
148
148
  */
149
149
  listExpiredThreads(now: Date, limit: number): Promise<Thread[]>;
150
+
151
+ /**
152
+ * List persisted threads for one tenant, newest first.
153
+ *
154
+ * @param tenantId Tenant scope.
155
+ * @param query Optional kind/assistant/time filters and pagination.
156
+ * @returns Matching safe records and the unpaginated total.
157
+ */
158
+ listThreadsByTenant(
159
+ tenantId: string,
160
+ query?: ThreadMonitorQuery
161
+ ): Promise<{ records: ThreadMonitorRecord[]; total: number }>;
162
+ }
163
+
164
+ /** Derived monitor kind for a persisted thread. */
165
+ export type ThreadMonitorKind =
166
+ | "conversation"
167
+ | "room_presence"
168
+ | "task_execution"
169
+ | "open_api"
170
+ | "web_app"
171
+ | "cron"
172
+ | "channel";
173
+
174
+ /** Filters accepted by a tenant-wide thread list. */
175
+ export interface ThreadMonitorQuery {
176
+ limit?: number;
177
+ offset?: number;
178
+ kind?: ThreadMonitorKind;
179
+ assistantId?: string;
180
+ createdAfter?: string;
181
+ }
182
+
183
+ /** Safe thread projection returned by the tenant monitor. */
184
+ export interface ThreadMonitorRecord {
185
+ id: string;
186
+ tenantId: string;
187
+ assistantId: string;
188
+ kind: ThreadMonitorKind;
189
+ workspaceId?: string;
190
+ projectId?: string;
191
+ roomId?: string;
192
+ taskId?: string;
193
+ createdAt: Date;
194
+ updatedAt: Date;
195
+ expiresAt?: Date;
196
+ }
197
+
198
+ /**
199
+ * Derive the monitor kind from metadata already written by the owning flows.
200
+ *
201
+ * No stored `kind` column exists; unknown or missing metadata is
202
+ * `conversation`.
203
+ */
204
+ export function classifyThreadMetadata(
205
+ metadata: Record<string, unknown> | undefined
206
+ ): ThreadMonitorKind {
207
+ if (!metadata) return "conversation";
208
+ if (metadata.source === "project_task" && metadata.kind === "task_execution") {
209
+ return "task_execution";
210
+ }
211
+ if (metadata.source === "project_room" && metadata.kind === "room_presence") {
212
+ return "room_presence";
213
+ }
214
+ if (metadata.source === "open_api") return "open_api";
215
+ if (metadata.source === "web_app") return "web_app";
216
+ if (typeof metadata.cronId === "string" && metadata.cronId.length > 0) {
217
+ return "cron";
218
+ }
219
+ if (typeof metadata.channel === "string" && metadata.channel.length > 0) {
220
+ return "channel";
221
+ }
222
+ return "conversation";
223
+ }
224
+
225
+ /** Project a stored thread into the safe monitor shape. */
226
+ export function toThreadMonitorRecord(thread: Thread): ThreadMonitorRecord {
227
+ const metadata = thread.metadata ?? {};
228
+ const readString = (key: string): string | undefined => {
229
+ const value = metadata[key];
230
+ return typeof value === "string" && value.length > 0 ? value : undefined;
231
+ };
232
+ const workspaceId = readString("workspaceId");
233
+ const projectId = readString("projectId");
234
+ const roomId = readString("roomId");
235
+ const taskId = readString("taskId");
236
+ return {
237
+ id: thread.id,
238
+ tenantId: thread.tenantId,
239
+ assistantId: thread.assistantId,
240
+ kind: classifyThreadMetadata(metadata),
241
+ ...(workspaceId ? { workspaceId } : {}),
242
+ ...(projectId ? { projectId } : {}),
243
+ ...(roomId ? { roomId } : {}),
244
+ ...(taskId ? { taskId } : {}),
245
+ createdAt: thread.createdAt,
246
+ updatedAt: thread.updatedAt,
247
+ ...(thread.expiresAt ? { expiresAt: thread.expiresAt } : {}),
248
+ };
150
249
  }
@@ -5,6 +5,8 @@ export interface User {
5
5
  email: string;
6
6
  name: string;
7
7
  status: UserStatus;
8
+ /** Bumped on disable/password-change/logout-all to revoke outstanding access tokens. */
9
+ authEpoch?: string;
8
10
  metadata?: Record<string, any>;
9
11
  createdAt: Date;
10
12
  updatedAt: Date;
@@ -21,6 +23,7 @@ export interface UpdateUserRequest {
21
23
  email?: string;
22
24
  name?: string;
23
25
  status?: UserStatus;
26
+ authEpoch?: string;
24
27
  metadata?: Record<string, any>;
25
28
  }
26
29
 
@@ -0,0 +1,60 @@
1
+ import {
2
+ classifyThreadMetadata,
3
+ toThreadMonitorRecord,
4
+ type Thread,
5
+ } from "../ThreadStoreProtocol";
6
+
7
+ function thread(metadata?: Record<string, unknown>): Thread {
8
+ return {
9
+ id: "thread-1",
10
+ tenantId: "tenant-1",
11
+ assistantId: "agent-1",
12
+ metadata,
13
+ createdAt: new Date("2026-01-01T00:00:00.000Z"),
14
+ updatedAt: new Date("2026-01-02T00:00:00.000Z"),
15
+ };
16
+ }
17
+
18
+ describe("thread monitor classification", () => {
19
+ it.each([
20
+ [{ source: "project_task", kind: "task_execution" }, "task_execution"],
21
+ [{ source: "project_room", kind: "room_presence" }, "room_presence"],
22
+ [{ source: "open_api" }, "open_api"],
23
+ [{ source: "web_app" }, "web_app"],
24
+ [{ cronId: "cron-1" }, "cron"],
25
+ [{ channel: "lark" }, "channel"],
26
+ [{}, "conversation"],
27
+ [undefined, "conversation"],
28
+ ])("classifies %j as %s", (metadata, expected) => {
29
+ expect(classifyThreadMetadata(metadata as never)).toBe(expected);
30
+ });
31
+
32
+ it("projects only explicit monitor fields", () => {
33
+ const record = toThreadMonitorRecord(
34
+ thread({
35
+ source: "project_task",
36
+ kind: "task_execution",
37
+ workspaceId: "ws-1",
38
+ projectId: "p-1",
39
+ roomId: "room-1",
40
+ taskId: "task-1",
41
+ secret: "do-not-leak",
42
+ }),
43
+ );
44
+
45
+ expect(record).toEqual({
46
+ id: "thread-1",
47
+ tenantId: "tenant-1",
48
+ assistantId: "agent-1",
49
+ kind: "task_execution",
50
+ workspaceId: "ws-1",
51
+ projectId: "p-1",
52
+ roomId: "room-1",
53
+ taskId: "task-1",
54
+ createdAt: new Date("2026-01-01T00:00:00.000Z"),
55
+ updatedAt: new Date("2026-01-02T00:00:00.000Z"),
56
+ });
57
+ expect(record).not.toHaveProperty("metadata");
58
+ expect(record).not.toHaveProperty("secret");
59
+ });
60
+ });
package/src/index.ts CHANGED
@@ -32,6 +32,7 @@ export * from "./MetricsServerConfigStoreProtocol";
32
32
  export * from "./McpServerConfigStoreProtocol";
33
33
  export * from "./ModelProviderProtocol";
34
34
  export * from "./UserStoreProtocol";
35
+ export * from "./SessionStoreProtocol";
35
36
  export * from "./UserTenantLinkProtocol";
36
37
  export * from "./AuthProviderProtocol";
37
38
  export * from "./UserExternalIdentityStoreProtocol";