@lmzhen/dsh-evolution-state-domain 0.1.0-rc.1
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 +26 -0
- package/lib/index.js +158 -0
- package/lib/invariant.js +8 -0
- package/lib/types/index.d.ts +47 -0
- package/lib/types/invariant.d.ts +5 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @deepseek-ai/dsh-evolution-state-domain
|
|
2
|
+
|
|
3
|
+
storage-domain provider for evolution state
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Model Experience
|
|
7
|
+
|
|
8
|
+
### Indirect model surface
|
|
9
|
+
|
|
10
|
+
#### What the model sees
|
|
11
|
+
|
|
12
|
+
`@deepseek-ai/dsh-evolution-state-domain` registers no direct prompt or tool schema itself. Model-visible effects are owned by the packages that consume this service.
|
|
13
|
+
|
|
14
|
+
#### Token effect
|
|
15
|
+
|
|
16
|
+
Zero direct token effect from this package; consumers add any model-visible tokens.
|
|
17
|
+
|
|
18
|
+
#### KV Cache effect
|
|
19
|
+
|
|
20
|
+
Independent of request-prefix construction. This package does not alter the assembled prompt or tool list.
|
|
21
|
+
|
|
22
|
+
## Known Limitations and Deferred Work
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
- - Requires the host-plane `storage-domain` facility. The bundle row stays dormant when it is absent.
|
|
26
|
+
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { defineDomain, domainTable } from "@deepseek-ai/dsh-storage-domain";
|
|
3
|
+
//#region lib/types/index.js
|
|
4
|
+
/**
|
|
5
|
+
* storage-domain provider for evolution state.
|
|
6
|
+
*
|
|
7
|
+
* When this provider is mounted, review/curator/pending records live in the
|
|
8
|
+
* DSH storage-domain data form: schema-validated, change-emitting, durable KV
|
|
9
|
+
* with whatever backend the domain facility routes (`json`, `sqlite`, remote
|
|
10
|
+
* RPC, …). The provider is one of several implementations of the same seam.
|
|
11
|
+
* @module @lmzhen/dsh-evolution-state-domain
|
|
12
|
+
*/
|
|
13
|
+
const name = "evolution-state-domain";
|
|
14
|
+
const inject = ["evolutionStateStorage", "storageDomain"];
|
|
15
|
+
const reviewStateSchema = z.object({
|
|
16
|
+
turnsSinceMemory: z.number().int().nonnegative(),
|
|
17
|
+
turnsSinceSkill: z.number().int().nonnegative(),
|
|
18
|
+
lastTurn: z.number().int().nonnegative()
|
|
19
|
+
});
|
|
20
|
+
const curatorStateSchema = z.object({
|
|
21
|
+
lastRunAt: z.number().nonnegative(),
|
|
22
|
+
runCount: z.number().int().nonnegative(),
|
|
23
|
+
lastSummary: z.string(),
|
|
24
|
+
paused: z.boolean()
|
|
25
|
+
});
|
|
26
|
+
const pendingSchema = z.object({
|
|
27
|
+
id: z.string(),
|
|
28
|
+
kind: z.union([
|
|
29
|
+
z.literal("memory"),
|
|
30
|
+
z.literal("skill"),
|
|
31
|
+
z.literal("skill_batch"),
|
|
32
|
+
z.literal("capability")
|
|
33
|
+
]),
|
|
34
|
+
summary: z.string(),
|
|
35
|
+
args: z.unknown(),
|
|
36
|
+
createdAt: z.string(),
|
|
37
|
+
status: z.union([
|
|
38
|
+
z.literal("pending"),
|
|
39
|
+
z.literal("approved"),
|
|
40
|
+
z.literal("rejected")
|
|
41
|
+
]),
|
|
42
|
+
resolvedAt: z.string().optional(),
|
|
43
|
+
claimedBy: z.string().optional(),
|
|
44
|
+
claimedAt: z.string().optional()
|
|
45
|
+
});
|
|
46
|
+
const EVOLUTION_DOMAIN = defineDomain({
|
|
47
|
+
name: "evolution",
|
|
48
|
+
version: 1,
|
|
49
|
+
tables: {
|
|
50
|
+
review_state: domainTable(reviewStateSchema),
|
|
51
|
+
curator_state: domainTable(curatorStateSchema),
|
|
52
|
+
pending: domainTable(pendingSchema)
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
function apply(ctx) {
|
|
56
|
+
let domain = null;
|
|
57
|
+
let opening = null;
|
|
58
|
+
async function ensure() {
|
|
59
|
+
if (domain) return domain;
|
|
60
|
+
const facility = ctx.get("storageDomain");
|
|
61
|
+
if (!facility) throw new Error("evolution-state-domain requires @deepseek-ai/dsh-storage-domain");
|
|
62
|
+
opening ??= facility.open(EVOLUTION_DOMAIN);
|
|
63
|
+
domain = await opening;
|
|
64
|
+
return domain;
|
|
65
|
+
}
|
|
66
|
+
const provider = {
|
|
67
|
+
name: "domain",
|
|
68
|
+
async loadReviewState(sessionId) {
|
|
69
|
+
return (await ensure()).table("review_state").get(sessionId) ?? null;
|
|
70
|
+
},
|
|
71
|
+
async saveReviewState(sessionId, record) {
|
|
72
|
+
await (await ensure()).table("review_state").put(sessionId, record);
|
|
73
|
+
},
|
|
74
|
+
async loadCuratorState() {
|
|
75
|
+
return (await ensure()).table("curator_state").get("primary") ?? null;
|
|
76
|
+
},
|
|
77
|
+
async saveCuratorState(record) {
|
|
78
|
+
await (await ensure()).table("curator_state").put("primary", record);
|
|
79
|
+
},
|
|
80
|
+
async listPending(status = "pending") {
|
|
81
|
+
return [...(await ensure()).table("pending").entries()].map(([, value]) => value).filter((record) => record.status === status);
|
|
82
|
+
},
|
|
83
|
+
async savePending(record) {
|
|
84
|
+
await (await ensure()).table("pending").put(record.id, record);
|
|
85
|
+
},
|
|
86
|
+
async claimPending(id, claimId) {
|
|
87
|
+
const table = (await ensure()).table("pending");
|
|
88
|
+
try {
|
|
89
|
+
const slot = { record: null };
|
|
90
|
+
const now = Date.now();
|
|
91
|
+
await table.update(id, (current) => {
|
|
92
|
+
if (current.status !== "pending") return current;
|
|
93
|
+
const claimedAt = typeof current.claimedAt === "string" ? Date.parse(current.claimedAt) : 0;
|
|
94
|
+
if (current.claimedBy !== void 0 && Number.isFinite(claimedAt) && now - claimedAt < 10 * 6e4) return current;
|
|
95
|
+
slot.record = {
|
|
96
|
+
...current,
|
|
97
|
+
claimedBy: claimId,
|
|
98
|
+
claimedAt: new Date(now).toISOString()
|
|
99
|
+
};
|
|
100
|
+
return slot.record;
|
|
101
|
+
});
|
|
102
|
+
return slot.record;
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
async releasePendingClaim(id, claimId) {
|
|
108
|
+
await (await ensure()).table("pending").update(id, (current) => {
|
|
109
|
+
if (current.status === "pending" && current.claimedBy === claimId) {
|
|
110
|
+
const released = { ...current };
|
|
111
|
+
delete released.claimedBy;
|
|
112
|
+
delete released.claimedAt;
|
|
113
|
+
return released;
|
|
114
|
+
}
|
|
115
|
+
return current;
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
async tryResolvePending(id, status) {
|
|
119
|
+
const table = (await ensure()).table("pending");
|
|
120
|
+
try {
|
|
121
|
+
const resolved = { record: null };
|
|
122
|
+
const record = await table.update(id, (current) => {
|
|
123
|
+
if (current.status !== "pending") return current;
|
|
124
|
+
resolved.record = {
|
|
125
|
+
...current,
|
|
126
|
+
status,
|
|
127
|
+
resolvedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
128
|
+
};
|
|
129
|
+
return resolved.record;
|
|
130
|
+
});
|
|
131
|
+
if (resolved.record === null) return {
|
|
132
|
+
record: record.status === status ? record : null,
|
|
133
|
+
applied: false
|
|
134
|
+
};
|
|
135
|
+
return {
|
|
136
|
+
record: resolved.record,
|
|
137
|
+
applied: true
|
|
138
|
+
};
|
|
139
|
+
} catch {
|
|
140
|
+
return {
|
|
141
|
+
record: null,
|
|
142
|
+
applied: false
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
ctx.effect(() => {
|
|
148
|
+
const dispose = ctx.evolutionStateStorage.registerProvider(provider);
|
|
149
|
+
return async () => {
|
|
150
|
+
dispose();
|
|
151
|
+
if (domain) await domain.close();
|
|
152
|
+
domain = null;
|
|
153
|
+
opening = null;
|
|
154
|
+
};
|
|
155
|
+
}, "evolution-state-domain.provider");
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
export { EVOLUTION_DOMAIN, apply, curatorStateSchema, inject, name, pendingSchema, reviewStateSchema };
|
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
const PACKAGE_NAME = "@deepseek-ai/dsh-evolution-state-domain";
|
|
3
|
+
const name = "evolution-state-domain-invariant";
|
|
4
|
+
const inject = ["invariants"];
|
|
5
|
+
const install = () => {};
|
|
6
|
+
const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
7
|
+
//#endregion
|
|
8
|
+
export { apply, inject, name };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* storage-domain provider for evolution state.
|
|
3
|
+
*
|
|
4
|
+
* When this provider is mounted, review/curator/pending records live in the
|
|
5
|
+
* DSH storage-domain data form: schema-validated, change-emitting, durable KV
|
|
6
|
+
* with whatever backend the domain facility routes (`json`, `sqlite`, remote
|
|
7
|
+
* RPC, …). The provider is one of several implementations of the same seam.
|
|
8
|
+
* @module @deepseek-ai/dsh-evolution-state-domain
|
|
9
|
+
*/
|
|
10
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import type { CuratorStateRecord, PendingRecord, ReviewStateRecord } from '@deepseek-ai/dsh-evolution-state-storage';
|
|
13
|
+
export declare const name = "evolution-state-domain";
|
|
14
|
+
export declare const inject: string[];
|
|
15
|
+
export declare const reviewStateSchema: z.ZodObject<{
|
|
16
|
+
turnsSinceMemory: z.ZodNumber;
|
|
17
|
+
turnsSinceSkill: z.ZodNumber;
|
|
18
|
+
lastTurn: z.ZodNumber;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
export declare const curatorStateSchema: z.ZodObject<{
|
|
21
|
+
lastRunAt: z.ZodNumber;
|
|
22
|
+
runCount: z.ZodNumber;
|
|
23
|
+
lastSummary: z.ZodString;
|
|
24
|
+
paused: z.ZodBoolean;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
export declare const pendingSchema: z.ZodObject<{
|
|
27
|
+
id: z.ZodString;
|
|
28
|
+
kind: z.ZodUnion<readonly [z.ZodLiteral<"memory">, z.ZodLiteral<"skill">, z.ZodLiteral<"skill_batch">, z.ZodLiteral<"capability">]>;
|
|
29
|
+
summary: z.ZodString;
|
|
30
|
+
args: z.ZodUnknown;
|
|
31
|
+
createdAt: z.ZodString;
|
|
32
|
+
status: z.ZodUnion<readonly [z.ZodLiteral<"pending">, z.ZodLiteral<"approved">, z.ZodLiteral<"rejected">]>;
|
|
33
|
+
resolvedAt: z.ZodOptional<z.ZodString>;
|
|
34
|
+
claimedBy: z.ZodOptional<z.ZodString>;
|
|
35
|
+
claimedAt: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
export declare const EVOLUTION_DOMAIN: {
|
|
38
|
+
name: string;
|
|
39
|
+
version: number;
|
|
40
|
+
tables: {
|
|
41
|
+
review_state: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, ReviewStateRecord>;
|
|
42
|
+
curator_state: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, CuratorStateRecord>;
|
|
43
|
+
pending: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, PendingRecord>;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export declare function apply(ctx: Context): void;
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lmzhen/dsh-evolution-state-domain",
|
|
3
|
+
"description": "storage-domain provider for evolution state (community build)",
|
|
4
|
+
"version": "0.1.0-rc.1",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/lmzhen/dsh-evolution.git",
|
|
11
|
+
"directory": "packages/dsh-evolution-state-domain"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./invariant": {
|
|
22
|
+
"types": "./lib/types/invariant.d.ts",
|
|
23
|
+
"default": "./lib/invariant.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"lib/index.js",
|
|
29
|
+
"lib/invariant.js",
|
|
30
|
+
"lib/types/**/*.d.ts",
|
|
31
|
+
"lib/types/invariant.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"zod": "^3.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
|
|
39
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
40
|
+
"@deepseek-ai/dsh-storage-domain": "^0.1.0-rc.6",
|
|
41
|
+
"@lmzhen/dsh-evolution-state-storage": "^0.1.0-rc.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
|
|
45
|
+
"@deepseek-ai/dsh-storage-domain": "^0.1.0-rc.6",
|
|
46
|
+
"@lmzhen/dsh-evolution-state-storage": "^0.1.0-rc.1"
|
|
47
|
+
}
|
|
48
|
+
}
|