dsh-working-activity 0.2.0 → 0.2.2
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/LICENSE +28 -28
- package/README.md +122 -120
- package/README.zh.md +3 -1
- package/cordis.patch.yml +19 -19
- package/lib/client.js +7 -7
- package/lib/client.js.map +1 -1
- package/lib/types/index.d.ts +7 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +2 -2
- package/package.json +106 -92
- package/src/client/WorkingLine.module.css +74 -74
- package/src/client/WorkingLine.tsx +37 -37
- package/src/client/activity.ts +50 -50
- package/src/client/css-modules.d.ts +6 -6
- package/src/client/index.ts +42 -42
- package/src/events.ts +45 -45
- package/src/index.ts +217 -211
- package/src/invariant.ts +69 -69
- package/src/status.ts +501 -501
package/src/invariant.ts
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Package-owned `activity/status` snapshot invariants.
|
|
3
|
-
* @module dsh-working-activity/invariant
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Context } from '@deepseek-ai/cordis'
|
|
7
|
-
import type { Session, SessionEvent } from '@deepseek-ai/dsh-session'
|
|
8
|
-
import type { InvariantFailure, InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
|
9
|
-
|
|
10
|
-
/** Cordis companion plugin name. */
|
|
11
|
-
export const name = 'working-activity-invariant'
|
|
12
|
-
/** Service required before the companion can reserve package ownership. */
|
|
13
|
-
export const inject = ['invariants']
|
|
14
|
-
|
|
15
|
-
const PACKAGE_NAME = 'dsh-working-activity'
|
|
16
|
-
const PHASES = new Set(['idle', 'waiting', 'thinking', 'tool', 'done'])
|
|
17
|
-
|
|
18
|
-
/** Validate one published activity snapshot before it reaches the durable log. */
|
|
19
|
-
function validateStatus(data: unknown, fail: InvariantFailure): void {
|
|
20
|
-
const record = data as Record<string, unknown> | null
|
|
21
|
-
if (record === null || typeof record !== 'object' || Array.isArray(record)) {
|
|
22
|
-
fail('activity/status data must be an object')
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
if (typeof record.phase !== 'string' || !PHASES.has(record.phase)) {
|
|
26
|
-
fail(`activity/status carries unknown phase ${JSON.stringify(record.phase)}`)
|
|
27
|
-
}
|
|
28
|
-
if (typeof record.line !== 'string' || record.line.length === 0) {
|
|
29
|
-
fail('activity/status line must be a non-empty string')
|
|
30
|
-
}
|
|
31
|
-
for (const key of ['toolCount', 'turnElapsedMs', 'phaseStartedAt']) {
|
|
32
|
-
const value = record[key]
|
|
33
|
-
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
34
|
-
fail(`activity/status ${key} must be a non-negative finite number`)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
for (const key of ['label', 'detail', 'phrase']) {
|
|
38
|
-
if (record[key] !== undefined && typeof record[key] !== 'string') {
|
|
39
|
-
fail(`activity/status ${key} must be a string when present`)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/* jscpd:ignore-start -- package companions share replay and dispatch plumbing */
|
|
45
|
-
/** Validate the package-owned event shape and ignore unrelated events. */
|
|
46
|
-
function validateEvent(event: SessionEvent, fail: InvariantFailure): void {
|
|
47
|
-
if (event.type === 'activity/status') validateStatus(event.data, fail)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Install validation for loaded and newly appended activity snapshots. */
|
|
51
|
-
const install: InvariantInstaller = Object.assign((ctx: Context, fail: InvariantFailure) => {
|
|
52
|
-
for (const session of ctx.sessions.list()) {
|
|
53
|
-
for (const event of session.events) validateEvent(event, fail)
|
|
54
|
-
}
|
|
55
|
-
ctx.on('internal/dispatch', (_mode, eventName, args) => {
|
|
56
|
-
if (eventName !== 'session/event') return
|
|
57
|
-
const event = (args as [Session, SessionEvent])[1]
|
|
58
|
-
validateEvent(event, fail)
|
|
59
|
-
}, { global: true })
|
|
60
|
-
}, { inject: ['sessions'] })
|
|
61
|
-
/* jscpd:ignore-end */
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Register the working-activity invariant companion.
|
|
65
|
-
* @param ctx - Cordis context carrying the invariant service.
|
|
66
|
-
* @returns the installed registration's disposer after setup succeeds.
|
|
67
|
-
*/
|
|
68
|
-
export const apply = (ctx: Context): Promise<() => void> =>
|
|
69
|
-
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned `activity/status` snapshot invariants.
|
|
3
|
+
* @module dsh-working-activity/invariant
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
7
|
+
import type { Session, SessionEvent } from '@deepseek-ai/dsh-session'
|
|
8
|
+
import type { InvariantFailure, InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
|
9
|
+
|
|
10
|
+
/** Cordis companion plugin name. */
|
|
11
|
+
export const name = 'working-activity-invariant'
|
|
12
|
+
/** Service required before the companion can reserve package ownership. */
|
|
13
|
+
export const inject = ['invariants']
|
|
14
|
+
|
|
15
|
+
const PACKAGE_NAME = 'dsh-working-activity'
|
|
16
|
+
const PHASES = new Set(['idle', 'waiting', 'thinking', 'tool', 'done'])
|
|
17
|
+
|
|
18
|
+
/** Validate one published activity snapshot before it reaches the durable log. */
|
|
19
|
+
function validateStatus(data: unknown, fail: InvariantFailure): void {
|
|
20
|
+
const record = data as Record<string, unknown> | null
|
|
21
|
+
if (record === null || typeof record !== 'object' || Array.isArray(record)) {
|
|
22
|
+
fail('activity/status data must be an object')
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
if (typeof record.phase !== 'string' || !PHASES.has(record.phase)) {
|
|
26
|
+
fail(`activity/status carries unknown phase ${JSON.stringify(record.phase)}`)
|
|
27
|
+
}
|
|
28
|
+
if (typeof record.line !== 'string' || record.line.length === 0) {
|
|
29
|
+
fail('activity/status line must be a non-empty string')
|
|
30
|
+
}
|
|
31
|
+
for (const key of ['toolCount', 'turnElapsedMs', 'phaseStartedAt']) {
|
|
32
|
+
const value = record[key]
|
|
33
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
34
|
+
fail(`activity/status ${key} must be a non-negative finite number`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const key of ['label', 'detail', 'phrase']) {
|
|
38
|
+
if (record[key] !== undefined && typeof record[key] !== 'string') {
|
|
39
|
+
fail(`activity/status ${key} must be a string when present`)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* jscpd:ignore-start -- package companions share replay and dispatch plumbing */
|
|
45
|
+
/** Validate the package-owned event shape and ignore unrelated events. */
|
|
46
|
+
function validateEvent(event: SessionEvent, fail: InvariantFailure): void {
|
|
47
|
+
if (event.type === 'activity/status') validateStatus(event.data, fail)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Install validation for loaded and newly appended activity snapshots. */
|
|
51
|
+
const install: InvariantInstaller = Object.assign((ctx: Context, fail: InvariantFailure) => {
|
|
52
|
+
for (const session of ctx.sessions.list()) {
|
|
53
|
+
for (const event of session.events) validateEvent(event, fail)
|
|
54
|
+
}
|
|
55
|
+
ctx.on('internal/dispatch', (_mode, eventName, args) => {
|
|
56
|
+
if (eventName !== 'session/event') return
|
|
57
|
+
const event = (args as [Session, SessionEvent])[1]
|
|
58
|
+
validateEvent(event, fail)
|
|
59
|
+
}, { global: true })
|
|
60
|
+
}, { inject: ['sessions'] })
|
|
61
|
+
/* jscpd:ignore-end */
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Register the working-activity invariant companion.
|
|
65
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
66
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
67
|
+
*/
|
|
68
|
+
export const apply = (ctx: Context): Promise<() => void> =>
|
|
69
|
+
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|