@wowyuarm/dsh-agent-team 0.1.10 → 0.1.12
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 +17 -4
- package/README.zh.md +17 -4
- package/package.json +53 -47
- package/packages/agent-team/README.md +6 -4
- package/packages/agent-team/README.zh.md +6 -4
- package/packages/agent-team/lib/context-management.js +40 -50
- package/packages/agent-team/lib/context-projection.js +15 -1
- package/packages/agent-team/lib/index.js +244 -154
- package/packages/agent-team/lib/invariant.js +38 -4
- package/packages/agent-team/lib/ledger.js +775 -383
- package/packages/agent-team/lib/member-context.js +6 -2
- package/packages/agent-team/lib/member-runtime.js +47 -9
- package/packages/agent-team/lib/member-time-context.js +20 -5
- package/packages/agent-team/lib/mentions.js +56 -0
- package/packages/agent-team/lib/pressure-policy.js +33 -9
- package/packages/agent-team/lib/session-event-cursor.js +116 -0
- package/packages/agent-team/lib/session-remediation.js +38 -26
- package/packages/agent-team/lib/spec.js +47 -34
- package/packages/agent-team/lib/stored-session-reader.js +138 -0
- package/packages/agent-team/lib/typert.host.js +157 -41
- package/packages/agent-team/lib/typert.remote-client.d.ts.map +1 -1
- package/packages/agent-team/lib/typert.remote-client.js +129 -32
- package/packages/agent-team/lib/types/context-management.d.ts +7 -0
- package/packages/agent-team/lib/types/context-management.d.ts.map +1 -1
- package/packages/agent-team/lib/types/context-projection.d.ts +8 -0
- package/packages/agent-team/lib/types/context-projection.d.ts.map +1 -1
- package/packages/agent-team/lib/types/index.d.ts +77 -7
- package/packages/agent-team/lib/types/index.d.ts.map +1 -1
- package/packages/agent-team/lib/types/invariant.d.ts.map +1 -1
- package/packages/agent-team/lib/types/ledger.d.ts +251 -20
- package/packages/agent-team/lib/types/ledger.d.ts.map +1 -1
- package/packages/agent-team/lib/types/member-context.d.ts.map +1 -1
- package/packages/agent-team/lib/types/member-runtime.d.ts +2 -1
- package/packages/agent-team/lib/types/member-runtime.d.ts.map +1 -1
- package/packages/agent-team/lib/types/member-time-context.d.ts.map +1 -1
- package/packages/agent-team/lib/types/mentions.d.ts +34 -0
- package/packages/agent-team/lib/types/mentions.d.ts.map +1 -0
- package/packages/agent-team/lib/types/pressure-policy.d.ts +18 -0
- package/packages/agent-team/lib/types/pressure-policy.d.ts.map +1 -1
- package/packages/agent-team/lib/types/session-event-cursor.d.ts +119 -0
- package/packages/agent-team/lib/types/session-event-cursor.d.ts.map +1 -0
- package/packages/agent-team/lib/types/session-remediation.d.ts +23 -0
- package/packages/agent-team/lib/types/session-remediation.d.ts.map +1 -1
- package/packages/agent-team/lib/types/spec.d.ts.map +1 -1
- package/packages/agent-team/lib/types/stored-session-reader.d.ts +92 -0
- package/packages/agent-team/lib/types/stored-session-reader.d.ts.map +1 -0
- package/packages/agent-team/lib/types/types/entities.d.ts +28 -20
- package/packages/agent-team/lib/types/types/entities.d.ts.map +1 -1
- package/packages/agent-team/lib/types/types/operations.d.ts +45 -19
- package/packages/agent-team/lib/types/types/operations.d.ts.map +1 -1
- package/packages/agent-team/lib/types/types/requests-results.d.ts +87 -4
- package/packages/agent-team/lib/types/types/requests-results.d.ts.map +1 -1
- package/packages/agent-team/preset/team-member/agent.cordis.yml +49 -7
- package/packages/client-agent-team/README.md +1 -1
- package/packages/client-agent-team/README.zh.md +1 -1
- package/packages/client-agent-team/lib/client.js +2357 -1207
- package/packages/client-agent-team/lib/client.js.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamAgentsPanel.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamAgentsPanel.js +27 -7
- package/packages/client-agent-team/lib/types/client/TeamAvatarStack.d.ts +18 -0
- package/packages/client-agent-team/lib/types/client/TeamAvatarStack.d.ts.map +1 -0
- package/packages/client-agent-team/lib/types/client/TeamAvatarStack.js +22 -0
- package/packages/client-agent-team/lib/types/client/TeamChannelPage.d.ts +3 -1
- package/packages/client-agent-team/lib/types/client/TeamChannelPage.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamChannelPage.js +167 -35
- package/packages/client-agent-team/lib/types/client/TeamChannelsPanel.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamChannelsPanel.js +23 -27
- package/packages/client-agent-team/lib/types/client/TeamComposer.d.ts +11 -5
- package/packages/client-agent-team/lib/types/client/TeamComposer.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamComposer.js +26 -26
- package/packages/client-agent-team/lib/types/client/TeamConversation.d.ts +1 -1
- package/packages/client-agent-team/lib/types/client/TeamConversation.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamConversation.js +9 -2
- package/packages/client-agent-team/lib/types/client/TeamCountBadge.d.ts +20 -0
- package/packages/client-agent-team/lib/types/client/TeamCountBadge.d.ts.map +1 -0
- package/packages/client-agent-team/lib/types/client/TeamCountBadge.js +25 -0
- package/packages/client-agent-team/lib/types/client/TeamInboxPage.d.ts +25 -0
- package/packages/client-agent-team/lib/types/client/TeamInboxPage.d.ts.map +1 -0
- package/packages/client-agent-team/lib/types/client/TeamInboxPage.js +139 -0
- package/packages/client-agent-team/lib/types/client/TeamMemberEditor.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamMemberEditor.js +8 -24
- package/packages/client-agent-team/lib/types/client/TeamMemberRow.d.ts +43 -0
- package/packages/client-agent-team/lib/types/client/TeamMemberRow.d.ts.map +1 -0
- package/packages/client-agent-team/lib/types/client/TeamMemberRow.js +27 -0
- package/packages/client-agent-team/lib/types/client/TeamMembersAction.d.ts +2 -2
- package/packages/client-agent-team/lib/types/client/TeamMembersAction.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamMembersAction.js +2 -2
- package/packages/client-agent-team/lib/types/client/TeamMessage.d.ts +9 -2
- package/packages/client-agent-team/lib/types/client/TeamMessage.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamMessage.js +11 -4
- package/packages/client-agent-team/lib/types/client/TeamPresenceDot.d.ts +8 -0
- package/packages/client-agent-team/lib/types/client/TeamPresenceDot.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamPresenceDot.js +21 -1
- package/packages/client-agent-team/lib/types/client/TeamThreadPage.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamThreadPage.js +108 -30
- package/packages/client-agent-team/lib/types/client/TeamWorkspaceBrowser.d.ts +1 -1
- package/packages/client-agent-team/lib/types/client/TeamWorkspaceBrowser.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/TeamWorkspaceBrowser.js +68 -7
- package/packages/client-agent-team/lib/types/client/index.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/index.js +19 -9
- package/packages/client-agent-team/lib/types/client/locales.d.ts +40 -2
- package/packages/client-agent-team/lib/types/client/locales.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/locales.js +40 -2
- package/packages/client-agent-team/lib/types/client/navigation.d.ts +10 -0
- package/packages/client-agent-team/lib/types/client/navigation.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/navigation.js +18 -7
- package/packages/client-agent-team/lib/types/client/scope-coverage.d.ts +41 -0
- package/packages/client-agent-team/lib/types/client/scope-coverage.d.ts.map +1 -0
- package/packages/client-agent-team/lib/types/client/scope-coverage.js +64 -0
- package/packages/client-agent-team/lib/types/client/slots.d.ts +7 -2
- package/packages/client-agent-team/lib/types/client/slots.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/team-changes.d.ts +33 -2
- package/packages/client-agent-team/lib/types/client/team-changes.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/team-changes.js +107 -25
- package/packages/client-agent-team/lib/types/client/team-dialog-save.d.ts +20 -0
- package/packages/client-agent-team/lib/types/client/team-dialog-save.d.ts.map +1 -0
- package/packages/client-agent-team/lib/types/client/team-dialog-save.js +36 -0
- package/packages/client-agent-team/lib/types/client/team-formatters.d.ts +43 -1
- package/packages/client-agent-team/lib/types/client/team-formatters.d.ts.map +1 -1
- package/packages/client-agent-team/lib/types/client/team-formatters.js +81 -6
- package/packages/tool-agent-team/README.md +2 -2
- package/packages/tool-agent-team/README.zh.md +2 -2
- package/packages/tool-agent-team/lib/context-tools.js +18 -14
- package/packages/tool-agent-team/lib/host-access.js +20 -0
- package/packages/tool-agent-team/lib/index.js +44 -32
- package/packages/tool-agent-team/lib/types/context-tools.d.ts.map +1 -1
- package/packages/tool-agent-team/lib/types/host-access.d.ts +14 -0
- package/packages/tool-agent-team/lib/types/host-access.d.ts.map +1 -0
- package/packages/tool-agent-team/lib/types/index.d.ts.map +1 -1
- package/packages/agent-team/lib/progress-nudge.js +0 -328
- package/packages/agent-team/lib/types/progress-nudge.d.ts +0 -136
- package/packages/agent-team/lib/types/progress-nudge.d.ts.map +0 -1
- package/packages/client-agent-team/lib/types/client/TeamSettings.d.ts +0 -3
- package/packages/client-agent-team/lib/types/client/TeamSettings.d.ts.map +0 -1
- package/packages/client-agent-team/lib/types/client/TeamSettings.js +0 -5
|
@@ -216,6 +216,48 @@ const claimOperation = (kind) => z.object({
|
|
|
216
216
|
inbox: inboxDeltaSchema,
|
|
217
217
|
}).strict(),
|
|
218
218
|
}).strict();
|
|
219
|
+
/**
|
|
220
|
+
* The five departure-fact collections a releasing operation persists. All four
|
|
221
|
+
* release kinds carry this snapshot under their own `kind` literal and their own
|
|
222
|
+
* identifying fields; the durable half that must stay identical lives here once,
|
|
223
|
+
* so a new release kind cannot silently drop or invent a field.
|
|
224
|
+
*/
|
|
225
|
+
const releaseSnapshotFields = {
|
|
226
|
+
claims: z.array(claimSchema),
|
|
227
|
+
activities: z.array(claimsReleasedActivitySchema),
|
|
228
|
+
tasks: z.array(taskSchema),
|
|
229
|
+
threads: z.array(threadSchema),
|
|
230
|
+
inbox: inboxDeltaSchema,
|
|
231
|
+
};
|
|
232
|
+
/** The receipt form every new read writes: the progress it made and the Inbox delta it consumed. */
|
|
233
|
+
const threadReadReceiptDataSchema = z.object({
|
|
234
|
+
workspaceId: workspaceIdSchema,
|
|
235
|
+
memberId: memberIdSchema,
|
|
236
|
+
threadRef: threadRefSchema,
|
|
237
|
+
taskRef: taskRefSchema.optional(),
|
|
238
|
+
readThroughSequence: z.number().int().nonnegative(),
|
|
239
|
+
inbox: inboxDeltaSchema,
|
|
240
|
+
}).strict().transform(omitUndefined);
|
|
241
|
+
/**
|
|
242
|
+
* The pre-receipt Thread-read snapshot. Still accepted so a ledger written
|
|
243
|
+
* before the receipt form keeps opening; both shapes are strict, so a stored
|
|
244
|
+
* record parses as exactly one of them.
|
|
245
|
+
*/
|
|
246
|
+
const threadReadSnapshotDataSchema = z.object({
|
|
247
|
+
workspaceId: workspaceIdSchema,
|
|
248
|
+
memberId: memberIdSchema,
|
|
249
|
+
task: taskSchema.optional(),
|
|
250
|
+
thread: threadSchema,
|
|
251
|
+
claims: z.array(claimSchema),
|
|
252
|
+
anchor: messageSchema,
|
|
253
|
+
anchorMentions: z.array(memberIdSchema),
|
|
254
|
+
facts: z.array(readFactSchema),
|
|
255
|
+
readThroughSequence: z.number().int().nonnegative(),
|
|
256
|
+
remainingUnreadCount: z.number().int().nonnegative(),
|
|
257
|
+
earlierFactCount: z.number().int().nonnegative().optional(),
|
|
258
|
+
attention: attentionSchema.optional(),
|
|
259
|
+
inbox: inboxDeltaSchema,
|
|
260
|
+
}).strict().transform(omitUndefined);
|
|
219
261
|
/** Closed Agent Team operation union before occurrence stamping. */
|
|
220
262
|
const storedAgentTeamOperationSchema = z.discriminatedUnion('kind', [
|
|
221
263
|
z.object({
|
|
@@ -258,11 +300,7 @@ const storedAgentTeamOperationSchema = z.discriminatedUnion('kind', [
|
|
|
258
300
|
kind: z.literal('team/member-archived'),
|
|
259
301
|
data: z.object({
|
|
260
302
|
member: memberSchema,
|
|
261
|
-
|
|
262
|
-
activities: z.array(claimsReleasedActivitySchema),
|
|
263
|
-
tasks: z.array(taskSchema),
|
|
264
|
-
threads: z.array(threadSchema),
|
|
265
|
-
inbox: inboxDeltaSchema,
|
|
303
|
+
...releaseSnapshotFields,
|
|
266
304
|
}).strict(),
|
|
267
305
|
}).strict(),
|
|
268
306
|
z.object({
|
|
@@ -324,11 +362,7 @@ const storedAgentTeamOperationSchema = z.discriminatedUnion('kind', [
|
|
|
324
362
|
workspaceId: workspaceIdSchema,
|
|
325
363
|
channelRef: channelRefSchema,
|
|
326
364
|
memberId: memberIdSchema,
|
|
327
|
-
|
|
328
|
-
activities: z.array(claimsReleasedActivitySchema),
|
|
329
|
-
tasks: z.array(taskSchema),
|
|
330
|
-
threads: z.array(threadSchema),
|
|
331
|
-
inbox: inboxDeltaSchema,
|
|
365
|
+
...releaseSnapshotFields,
|
|
332
366
|
}).strict(),
|
|
333
367
|
}).strict(),
|
|
334
368
|
z.object({
|
|
@@ -338,11 +372,7 @@ const storedAgentTeamOperationSchema = z.discriminatedUnion('kind', [
|
|
|
338
372
|
data: z.object({
|
|
339
373
|
workspaceId: workspaceIdSchema,
|
|
340
374
|
channel: channelSchema,
|
|
341
|
-
|
|
342
|
-
activities: z.array(claimsReleasedActivitySchema),
|
|
343
|
-
tasks: z.array(taskSchema),
|
|
344
|
-
threads: z.array(threadSchema),
|
|
345
|
-
inbox: inboxDeltaSchema,
|
|
375
|
+
...releaseSnapshotFields,
|
|
346
376
|
}).strict(),
|
|
347
377
|
}).strict(),
|
|
348
378
|
z.object({
|
|
@@ -419,20 +449,7 @@ const storedAgentTeamOperationSchema = z.discriminatedUnion('kind', [
|
|
|
419
449
|
...operationBase,
|
|
420
450
|
previousOperationId: operationIdSchema.nullable(),
|
|
421
451
|
kind: z.literal('team/thread-read'),
|
|
422
|
-
data: z.
|
|
423
|
-
workspaceId: workspaceIdSchema,
|
|
424
|
-
memberId: memberIdSchema,
|
|
425
|
-
task: taskSchema.optional(),
|
|
426
|
-
thread: threadSchema,
|
|
427
|
-
claims: z.array(claimSchema),
|
|
428
|
-
anchor: messageSchema,
|
|
429
|
-
anchorMentions: z.array(memberIdSchema),
|
|
430
|
-
facts: z.array(readFactSchema),
|
|
431
|
-
readThroughSequence: z.number().int().nonnegative(),
|
|
432
|
-
remainingUnreadCount: z.number().int().nonnegative(),
|
|
433
|
-
attention: attentionSchema.optional(),
|
|
434
|
-
inbox: inboxDeltaSchema,
|
|
435
|
-
}).strict().transform(omitUndefined),
|
|
452
|
+
data: z.union([threadReadReceiptDataSchema, threadReadSnapshotDataSchema]),
|
|
436
453
|
}).strict(),
|
|
437
454
|
z.object({
|
|
438
455
|
...operationBase,
|
|
@@ -440,11 +457,7 @@ const storedAgentTeamOperationSchema = z.discriminatedUnion('kind', [
|
|
|
440
457
|
kind: z.literal('team/member-removed'),
|
|
441
458
|
data: z.object({
|
|
442
459
|
member: memberSchema,
|
|
443
|
-
|
|
444
|
-
activities: z.array(claimsReleasedActivitySchema),
|
|
445
|
-
tasks: z.array(taskSchema),
|
|
446
|
-
threads: z.array(threadSchema),
|
|
447
|
-
inbox: inboxDeltaSchema,
|
|
460
|
+
...releaseSnapshotFields,
|
|
448
461
|
}).strict(),
|
|
449
462
|
}).strict(),
|
|
450
463
|
z.object({
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Team's single seam for reading stored Sessions.
|
|
3
|
+
*
|
|
4
|
+
* Every per-Session read the Host performs goes through here: one
|
|
5
|
+
* `open → read → close` cycle whose handle lifecycle is guaranteed closed,
|
|
6
|
+
* and whose failures are normalized into the five categories consumers choose
|
|
7
|
+
* policy by. Callers never touch a `SessionHandle`, an artifact path, a
|
|
8
|
+
* format generation, or Harness error message text.
|
|
9
|
+
*
|
|
10
|
+
* The reader owns reading and classification only — not Member lifecycle,
|
|
11
|
+
* Agent create/resume, UI, ledger, or remediation (which reads raw artifact
|
|
12
|
+
* bytes through its own repair path).
|
|
13
|
+
*
|
|
14
|
+
* Classification notes: the shipped JSONL backend throws its
|
|
15
|
+
* `corrupt session log` family as plain `Error`s, so corruption is detected by
|
|
16
|
+
* that stable message prefix (an upstream gap; if the text ever changes the
|
|
17
|
+
* failure degrades to `unknown`, which consumers treat conservatively —
|
|
18
|
+
* blocking rather than silently skipping). Typed refusals are also matched
|
|
19
|
+
* through `error.cause` chains because the Harness agent layer wraps
|
|
20
|
+
* persistence failures during resume.
|
|
21
|
+
* @module @wowyuarm/dsh-agent-team/stored-session-reader
|
|
22
|
+
*/
|
|
23
|
+
import { SessionFormatUnsupportedError, SessionPersistenceCorruptionError, SessionPersistenceNotFoundError, } from '@deepseek-ai/dsh-session-persistence';
|
|
24
|
+
/**
|
|
25
|
+
* A call site's session-read failure, carrying the typed classification so
|
|
26
|
+
* activation can route the diagnostic without re-matching error text.
|
|
27
|
+
*/
|
|
28
|
+
export class StoredSessionReadError extends Error {
|
|
29
|
+
failure;
|
|
30
|
+
constructor(message, failure) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.failure = failure;
|
|
33
|
+
this.name = 'StoredSessionReadError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** How deep to follow `error.cause` chains looking for a typed session failure. */
|
|
37
|
+
const MAX_CAUSE_DEPTH = 4;
|
|
38
|
+
/** The JSONL backend's stable corruption-message prefix (plain `Error`s, not typed). */
|
|
39
|
+
const CORRUPT_SESSION_LOG_TEXT = /corrupt session log/;
|
|
40
|
+
function messageOf(error) {
|
|
41
|
+
return error instanceof Error ? error.message : String(error);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The deterministic session-shaped classification of one error value:
|
|
45
|
+
* typed Harness failures plus the corruption message family. A system error
|
|
46
|
+
* code is deliberately NOT matched here — outside the reader an fs error may
|
|
47
|
+
* come from unrelated work (private memory, attachment cache), so only the
|
|
48
|
+
* reader itself, where the failed operation is known to be a session read,
|
|
49
|
+
* may classify an fs error as `io`.
|
|
50
|
+
*/
|
|
51
|
+
function sessionClassOf(error) {
|
|
52
|
+
if (error instanceof SessionPersistenceNotFoundError)
|
|
53
|
+
return { kind: 'missing' };
|
|
54
|
+
if (error instanceof SessionFormatUnsupportedError) {
|
|
55
|
+
return { kind: 'refused', ...(error.location === undefined ? {} : { location: error.location }) };
|
|
56
|
+
}
|
|
57
|
+
if (error instanceof SessionPersistenceCorruptionError)
|
|
58
|
+
return { kind: 'corrupt' };
|
|
59
|
+
if (error instanceof Error && CORRUPT_SESSION_LOG_TEXT.test(error.message))
|
|
60
|
+
return { kind: 'corrupt' };
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
/** The first session-shaped classification in an error's cause chain, with the matched error for its message. */
|
|
64
|
+
function sessionClassInChain(error) {
|
|
65
|
+
let current = error;
|
|
66
|
+
for (let depth = 0; current !== undefined && current !== null && depth <= MAX_CAUSE_DEPTH; depth += 1) {
|
|
67
|
+
const classified = sessionClassOf(current);
|
|
68
|
+
if (classified !== undefined)
|
|
69
|
+
return { classified, matched: current };
|
|
70
|
+
current = current instanceof Error ? current.cause : undefined;
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Classify any failure as a stored-Session read failure. Total: unmatched
|
|
76
|
+
* errors become `unknown`, and a direct system error code becomes `io` —
|
|
77
|
+
* call this only where the failed operation is known to be a session read.
|
|
78
|
+
*/
|
|
79
|
+
export function classifyStoredSessionFailure(error, sessionId) {
|
|
80
|
+
const inChain = sessionClassInChain(error);
|
|
81
|
+
if (inChain !== undefined) {
|
|
82
|
+
return { kind: inChain.classified.kind, sessionId, detail: messageOf(inChain.matched), ...('location' in inChain.classified ? { location: inChain.classified.location } : {}) };
|
|
83
|
+
}
|
|
84
|
+
if (error !== null && typeof error === 'object' && typeof error.code === 'string') {
|
|
85
|
+
return { kind: 'io', sessionId, detail: messageOf(error) };
|
|
86
|
+
}
|
|
87
|
+
return { kind: 'unknown', sessionId, detail: messageOf(error) };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The session-shaped failure carried by an arbitrary error, when it carries
|
|
91
|
+
* one at all: deterministic markers (typed classes, the corruption message
|
|
92
|
+
* family) are matched through the cause chain; transient fs errors are not —
|
|
93
|
+
* outside the reader they are not provably session-related. Activation uses
|
|
94
|
+
* this to route diagnostics; `undefined` means the failure is not
|
|
95
|
+
* session-shaped.
|
|
96
|
+
*/
|
|
97
|
+
export function sessionFailureOf(error, sessionId) {
|
|
98
|
+
const inChain = sessionClassInChain(error);
|
|
99
|
+
if (inChain === undefined)
|
|
100
|
+
return undefined;
|
|
101
|
+
return { kind: inChain.classified.kind, sessionId, detail: messageOf(inChain.matched), ...('location' in inChain.classified ? { location: inChain.classified.location } : {}) };
|
|
102
|
+
}
|
|
103
|
+
/** Read stored Sessions through one seam: full validated reads with normalized failures. */
|
|
104
|
+
export class StoredSessionReader {
|
|
105
|
+
ctx;
|
|
106
|
+
constructor(ctx) {
|
|
107
|
+
this.ctx = ctx;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Read one stored Session completely. The handle is closed on every path;
|
|
111
|
+
* any failure of open, read, or close is returned as its normalized
|
|
112
|
+
* category, never thrown.
|
|
113
|
+
*/
|
|
114
|
+
async read(sessionId) {
|
|
115
|
+
try {
|
|
116
|
+
const handle = await this.ctx.sessionPersistence.open(sessionId, 'read');
|
|
117
|
+
try {
|
|
118
|
+
const { events } = await handle.read();
|
|
119
|
+
return { ok: true, inspection: { header: handle.header, inheritedEventCount: handle.inheritedEventCount, events } };
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
await handle.close();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
return { ok: false, failure: classifyStoredSessionFailure(error, sessionId) };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Whether one stored Session has durable persisted content, decided through
|
|
131
|
+
* `stat`: the backend reports a still-draining session through its pending
|
|
132
|
+
* header, so this is the existence probe activation relies on. Only the
|
|
133
|
+
* missing case returns `false`; unexpected errors propagate as before.
|
|
134
|
+
*/
|
|
135
|
+
async exists(sessionId) {
|
|
136
|
+
return (await this.ctx.sessionPersistence.stat(sessionId)) !== undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|