@axiom-lattice/protocols 7.6.0 → 7.7.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.7.0",
4
4
  "description": "Unified protocol type definitions for Axiom Lattice framework",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -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
  }
@@ -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
  }
@@ -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
+ });