@lmzhen/dsh-evolution-state-domain 0.3.50 → 0.3.52
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/lib/index.js +48 -23
- package/lib/types/index.d.ts +21 -0
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { DomainError, defineDomain, domainTable } from "@deepseek-ai/dsh-storage-domain";
|
|
3
|
-
import { canClaimPending, canResolvePending, releasedStatus } from "@lmzhen/dsh-evolution-state-storage";
|
|
3
|
+
import { CURATOR_STATE_KEY, CURATOR_STATE_TABLE, PENDING_TABLE, PROVIDER_DOMAIN, REVIEW_STATE_TABLE, canClaimPending, canResolvePending, releasedStatus } from "@lmzhen/dsh-evolution-state-storage";
|
|
4
4
|
//#region lib/types/index.js
|
|
5
5
|
/**
|
|
6
6
|
* storage-domain provider for evolution state.
|
|
@@ -13,11 +13,22 @@ import { canClaimPending, canResolvePending, releasedStatus } from "@lmzhen/dsh-
|
|
|
13
13
|
*/
|
|
14
14
|
const name = "evolution-state-domain";
|
|
15
15
|
const inject = ["evolutionStateStorage", "storageDomain"];
|
|
16
|
+
/**
|
|
17
|
+
* Review-state record schema of the storage-domain table.
|
|
18
|
+
* @internal Referenced only by this package's own tests and EVOLUTION_DOMAIN
|
|
19
|
+
* below — not public API surface (audit v10 S-03); the record contract lives
|
|
20
|
+
* in `@lmzhen/dsh-evolution-state-storage` types.
|
|
21
|
+
*/
|
|
16
22
|
const reviewStateSchema = z.object({
|
|
17
23
|
turnsSinceMemory: z.number().int().nonnegative(),
|
|
18
24
|
turnsSinceSkill: z.number().int().nonnegative(),
|
|
19
25
|
lastTurn: z.number().int().nonnegative()
|
|
20
26
|
});
|
|
27
|
+
/**
|
|
28
|
+
* Curator-state record schema of the storage-domain table.
|
|
29
|
+
* @internal Referenced only by this package's own tests and EVOLUTION_DOMAIN
|
|
30
|
+
* below — not public API surface (audit v10 S-03).
|
|
31
|
+
*/
|
|
21
32
|
const curatorStateSchema = z.object({
|
|
22
33
|
/** Optional record-shape version; legacy records without it stay compatible. */
|
|
23
34
|
schemaVersion: z.number().int().nonnegative().optional(),
|
|
@@ -26,6 +37,11 @@ const curatorStateSchema = z.object({
|
|
|
26
37
|
lastSummary: z.string(),
|
|
27
38
|
paused: z.boolean()
|
|
28
39
|
});
|
|
40
|
+
/**
|
|
41
|
+
* Pending record schema of the storage-domain table.
|
|
42
|
+
* @internal Referenced only by this package's own tests and EVOLUTION_DOMAIN
|
|
43
|
+
* below — not public API surface (audit v10 S-03).
|
|
44
|
+
*/
|
|
29
45
|
const pendingSchema = z.object({
|
|
30
46
|
id: z.string(),
|
|
31
47
|
kind: z.union([
|
|
@@ -48,13 +64,18 @@ const pendingSchema = z.object({
|
|
|
48
64
|
origin: z.string().optional(),
|
|
49
65
|
sessionId: z.string().optional()
|
|
50
66
|
});
|
|
67
|
+
/**
|
|
68
|
+
* The evolution storage-domain spec: three schema-validated KV tables.
|
|
69
|
+
* @internal Referenced only by this package's own tests and `open()` — not
|
|
70
|
+
* public API surface (audit v10 S-03).
|
|
71
|
+
*/
|
|
51
72
|
const EVOLUTION_DOMAIN = defineDomain({
|
|
52
73
|
name: "evolution",
|
|
53
74
|
version: 1,
|
|
54
75
|
tables: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
76
|
+
[REVIEW_STATE_TABLE]: domainTable(reviewStateSchema),
|
|
77
|
+
[CURATOR_STATE_TABLE]: domainTable(curatorStateSchema),
|
|
78
|
+
[PENDING_TABLE]: domainTable(pendingSchema)
|
|
58
79
|
}
|
|
59
80
|
});
|
|
60
81
|
/**
|
|
@@ -93,41 +114,45 @@ function apply(ctx) {
|
|
|
93
114
|
return domain;
|
|
94
115
|
}
|
|
95
116
|
const provider = {
|
|
96
|
-
name:
|
|
117
|
+
name: PROVIDER_DOMAIN,
|
|
97
118
|
async loadReviewState(sessionId) {
|
|
98
|
-
return (await ensure()).table(
|
|
119
|
+
return (await ensure()).table(REVIEW_STATE_TABLE).get(sessionId) ?? null;
|
|
99
120
|
},
|
|
100
121
|
async saveReviewState(sessionId, record) {
|
|
101
|
-
await (await ensure()).table(
|
|
122
|
+
await (await ensure()).table(REVIEW_STATE_TABLE).put(sessionId, record);
|
|
102
123
|
},
|
|
103
124
|
async loadCuratorState() {
|
|
104
|
-
return (await ensure()).table(
|
|
125
|
+
return (await ensure()).table(CURATOR_STATE_TABLE).get(CURATOR_STATE_KEY) ?? null;
|
|
105
126
|
},
|
|
106
127
|
async saveCuratorState(record) {
|
|
107
|
-
await (await ensure()).table(
|
|
128
|
+
await (await ensure()).table(CURATOR_STATE_TABLE).put(CURATOR_STATE_KEY, record);
|
|
108
129
|
},
|
|
109
130
|
async transactCuratorState(task) {
|
|
110
|
-
const table = (await ensure()).table(
|
|
131
|
+
const table = (await ensure()).table(CURATOR_STATE_TABLE);
|
|
111
132
|
try {
|
|
112
|
-
await table.update(
|
|
133
|
+
await table.update(CURATOR_STATE_KEY, (current) => task(current) ?? current);
|
|
134
|
+
return;
|
|
113
135
|
} catch (error) {
|
|
114
|
-
if (error instanceof DomainError && error.code === "missing-key")
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
throw error;
|
|
136
|
+
if (!(error instanceof DomainError && error.code === "missing-key")) throw error;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
await table.update(CURATOR_STATE_KEY, (current) => task(current) ?? current);
|
|
140
|
+
return;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (!(error instanceof DomainError && error.code === "missing-key")) throw error;
|
|
121
143
|
}
|
|
144
|
+
const next = task(null);
|
|
145
|
+
if (next !== null) await table.put(CURATOR_STATE_KEY, next);
|
|
146
|
+
else await table.delete(CURATOR_STATE_KEY);
|
|
122
147
|
},
|
|
123
148
|
async listPending(status = "pending") {
|
|
124
|
-
return [...(await ensure()).table(
|
|
149
|
+
return [...(await ensure()).table(PENDING_TABLE).entries()].map(([, value]) => value).filter((record) => record.status === status);
|
|
125
150
|
},
|
|
126
151
|
async savePending(record) {
|
|
127
|
-
await (await ensure()).table(
|
|
152
|
+
await (await ensure()).table(PENDING_TABLE).put(record.id, record);
|
|
128
153
|
},
|
|
129
154
|
async claimPending(id, claimId) {
|
|
130
|
-
const table = (await ensure()).table(
|
|
155
|
+
const table = (await ensure()).table(PENDING_TABLE);
|
|
131
156
|
try {
|
|
132
157
|
const slot = { record: null };
|
|
133
158
|
const now = Date.now();
|
|
@@ -148,7 +173,7 @@ function apply(ctx) {
|
|
|
148
173
|
}
|
|
149
174
|
},
|
|
150
175
|
async releasePendingClaim(id, claimId) {
|
|
151
|
-
const table = (await ensure()).table(
|
|
176
|
+
const table = (await ensure()).table(PENDING_TABLE);
|
|
152
177
|
try {
|
|
153
178
|
await table.update(id, (current) => {
|
|
154
179
|
if (current.status !== "pending" && current.status !== "executing") return current;
|
|
@@ -167,7 +192,7 @@ function apply(ctx) {
|
|
|
167
192
|
}
|
|
168
193
|
},
|
|
169
194
|
async tryResolvePending(id, status) {
|
|
170
|
-
const table = (await ensure()).table(
|
|
195
|
+
const table = (await ensure()).table(PENDING_TABLE);
|
|
171
196
|
try {
|
|
172
197
|
const resolved = { record: null };
|
|
173
198
|
const rawRecord = await table.update(id, (current) => {
|
package/lib/types/index.d.ts
CHANGED
|
@@ -12,11 +12,22 @@ import { z } from 'zod';
|
|
|
12
12
|
import { type CuratorStateRecord, type PendingRecord, type ReviewStateRecord } from '@lmzhen/dsh-evolution-state-storage';
|
|
13
13
|
export declare const name = "evolution-state-domain";
|
|
14
14
|
export declare const inject: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Review-state record schema of the storage-domain table.
|
|
17
|
+
* @internal Referenced only by this package's own tests and EVOLUTION_DOMAIN
|
|
18
|
+
* below — not public API surface (audit v10 S-03); the record contract lives
|
|
19
|
+
* in `@lmzhen/dsh-evolution-state-storage` types.
|
|
20
|
+
*/
|
|
15
21
|
export declare const reviewStateSchema: z.ZodObject<{
|
|
16
22
|
turnsSinceMemory: z.ZodNumber;
|
|
17
23
|
turnsSinceSkill: z.ZodNumber;
|
|
18
24
|
lastTurn: z.ZodNumber;
|
|
19
25
|
}, z.core.$strip>;
|
|
26
|
+
/**
|
|
27
|
+
* Curator-state record schema of the storage-domain table.
|
|
28
|
+
* @internal Referenced only by this package's own tests and EVOLUTION_DOMAIN
|
|
29
|
+
* below — not public API surface (audit v10 S-03).
|
|
30
|
+
*/
|
|
20
31
|
export declare const curatorStateSchema: z.ZodObject<{
|
|
21
32
|
schemaVersion: z.ZodOptional<z.ZodNumber>;
|
|
22
33
|
lastRunAt: z.ZodNumber;
|
|
@@ -24,6 +35,11 @@ export declare const curatorStateSchema: z.ZodObject<{
|
|
|
24
35
|
lastSummary: z.ZodString;
|
|
25
36
|
paused: z.ZodBoolean;
|
|
26
37
|
}, z.core.$strip>;
|
|
38
|
+
/**
|
|
39
|
+
* Pending record schema of the storage-domain table.
|
|
40
|
+
* @internal Referenced only by this package's own tests and EVOLUTION_DOMAIN
|
|
41
|
+
* below — not public API surface (audit v10 S-03).
|
|
42
|
+
*/
|
|
27
43
|
export declare const pendingSchema: z.ZodObject<{
|
|
28
44
|
id: z.ZodString;
|
|
29
45
|
kind: z.ZodUnion<readonly [z.ZodLiteral<"memory">, z.ZodLiteral<"skill">, z.ZodLiteral<"capability">]>;
|
|
@@ -37,6 +53,11 @@ export declare const pendingSchema: z.ZodObject<{
|
|
|
37
53
|
origin: z.ZodOptional<z.ZodString>;
|
|
38
54
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
39
55
|
}, z.core.$strip>;
|
|
56
|
+
/**
|
|
57
|
+
* The evolution storage-domain spec: three schema-validated KV tables.
|
|
58
|
+
* @internal Referenced only by this package's own tests and `open()` — not
|
|
59
|
+
* public API surface (audit v10 S-03).
|
|
60
|
+
*/
|
|
40
61
|
export declare const EVOLUTION_DOMAIN: {
|
|
41
62
|
name: string;
|
|
42
63
|
version: number;
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-state-domain",
|
|
3
3
|
"description": "storage-domain provider for evolution state (community build)",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.52",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/lmzhen/dsh-evolution.git",
|
|
11
|
-
"directory": "packages/
|
|
11
|
+
"directory": "packages/evolution-state-domain"
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "lib/index.js",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
|
|
37
37
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
38
38
|
"@deepseek-ai/dsh-storage-domain": "^0.1.1-rc.2",
|
|
39
|
-
"@lmzhen/dsh-evolution-state-storage": "^0.3.
|
|
39
|
+
"@lmzhen/dsh-evolution-state-storage": "^0.3.52"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
|
|
43
43
|
"@deepseek-ai/dsh-storage-domain": "^0.1.1-rc.2",
|
|
44
44
|
"@deepseek-ai/dsh-storage": "^0.1.1-rc.2",
|
|
45
45
|
"@deepseek-ai/dsh-storage-json": "^0.1.1-rc.2",
|
|
46
|
-
"@lmzhen/dsh-evolution-state-storage": "^0.3.
|
|
46
|
+
"@lmzhen/dsh-evolution-state-storage": "^0.3.52"
|
|
47
47
|
}
|
|
48
48
|
}
|