@lmzhen/dsh-evolution-state-domain 0.3.16 → 0.3.17

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 CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { DomainError, defineDomain, domainTable } from "@deepseek-ai/dsh-storage-domain";
3
+ import { CLAIM_EXPIRY_MS, canClaimPending, canResolvePending, releasedStatus } from "@lmzhen/dsh-evolution-state-storage";
3
4
  //#region lib/types/index.js
4
5
  /**
5
6
  * storage-domain provider for evolution state.
@@ -30,7 +31,6 @@ const pendingSchema = z.object({
30
31
  kind: z.union([
31
32
  z.literal("memory"),
32
33
  z.literal("skill"),
33
- z.literal("skill_batch"),
34
34
  z.literal("capability")
35
35
  ]),
36
36
  summary: z.string(),
@@ -38,6 +38,7 @@ const pendingSchema = z.object({
38
38
  createdAt: z.string(),
39
39
  status: z.union([
40
40
  z.literal("pending"),
41
+ z.literal("executing"),
41
42
  z.literal("approved"),
42
43
  z.literal("rejected")
43
44
  ]),
@@ -115,11 +116,12 @@ function apply(ctx) {
115
116
  const slot = { record: null };
116
117
  const now = Date.now();
117
118
  await table.update(id, (current) => {
118
- if (current.status !== "pending") return current;
119
+ if (!canClaimPending(current.status)) return current;
119
120
  const claimedAt = typeof current.claimedAt === "string" ? Date.parse(current.claimedAt) : 0;
120
- if (current.claimedBy !== void 0 && Number.isFinite(claimedAt) && now - claimedAt < 10 * 6e4) return current;
121
+ if (current.claimedBy !== void 0 && Number.isFinite(claimedAt) && now - claimedAt < CLAIM_EXPIRY_MS) return current;
121
122
  slot.record = {
122
123
  ...current,
124
+ status: "executing",
123
125
  claimedBy: claimId,
124
126
  claimedAt: new Date(now).toISOString()
125
127
  };
@@ -133,13 +135,15 @@ function apply(ctx) {
133
135
  },
134
136
  async releasePendingClaim(id, claimId) {
135
137
  await (await ensure()).table("pending").update(id, (current) => {
136
- if (current.status === "pending" && current.claimedBy === claimId) {
137
- const released = { ...current };
138
- delete released.claimedBy;
139
- delete released.claimedAt;
140
- return released;
141
- }
142
- return current;
138
+ if (current.status !== "pending" && current.status !== "executing") return current;
139
+ if (current.claimedBy !== claimId) return current;
140
+ const released = {
141
+ ...current,
142
+ status: releasedStatus(current.status)
143
+ };
144
+ delete released.claimedBy;
145
+ delete released.claimedAt;
146
+ return released;
143
147
  });
144
148
  },
145
149
  async tryResolvePending(id, status) {
@@ -147,7 +151,7 @@ function apply(ctx) {
147
151
  try {
148
152
  const resolved = { record: null };
149
153
  const record = await table.update(id, (current) => {
150
- if (current.status !== "pending") return current;
154
+ if (!canResolvePending(current.status)) return current;
151
155
  resolved.record = {
152
156
  ...current,
153
157
  status,
@@ -156,7 +160,7 @@ function apply(ctx) {
156
160
  return resolved.record;
157
161
  });
158
162
  if (resolved.record === null) return {
159
- record: record.status === status ? record : null,
163
+ record,
160
164
  applied: false
161
165
  };
162
166
  return {
@@ -176,6 +180,7 @@ function apply(ctx) {
176
180
  const dispose = ctx.evolutionStateStorage.registerProvider(provider);
177
181
  return async () => {
178
182
  dispose();
183
+ if (opening) await opening.catch(() => null);
179
184
  if (domain) await domain.close();
180
185
  domain = null;
181
186
  opening = null;
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import type { Context } from '@deepseek-ai/cordis';
11
11
  import { z } from 'zod';
12
- import type { CuratorStateRecord, PendingRecord, ReviewStateRecord } from '@deepseek-ai/dsh-evolution-state-storage';
12
+ import { type CuratorStateRecord, type PendingRecord, type ReviewStateRecord } from '@deepseek-ai/dsh-evolution-state-storage';
13
13
  export declare const name = "evolution-state-domain";
14
14
  export declare const inject: string[];
15
15
  export declare const reviewStateSchema: z.ZodObject<{
@@ -26,11 +26,11 @@ export declare const curatorStateSchema: z.ZodObject<{
26
26
  }, z.core.$strip>;
27
27
  export declare const pendingSchema: z.ZodObject<{
28
28
  id: z.ZodString;
29
- kind: z.ZodUnion<readonly [z.ZodLiteral<"memory">, z.ZodLiteral<"skill">, z.ZodLiteral<"skill_batch">, z.ZodLiteral<"capability">]>;
29
+ kind: z.ZodUnion<readonly [z.ZodLiteral<"memory">, z.ZodLiteral<"skill">, z.ZodLiteral<"capability">]>;
30
30
  summary: z.ZodString;
31
31
  args: z.ZodUnknown;
32
32
  createdAt: z.ZodString;
33
- status: z.ZodUnion<readonly [z.ZodLiteral<"pending">, z.ZodLiteral<"approved">, z.ZodLiteral<"rejected">]>;
33
+ status: z.ZodUnion<readonly [z.ZodLiteral<"pending">, z.ZodLiteral<"executing">, z.ZodLiteral<"approved">, z.ZodLiteral<"rejected">]>;
34
34
  resolvedAt: z.ZodOptional<z.ZodString>;
35
35
  claimedBy: z.ZodOptional<z.ZodString>;
36
36
  claimedAt: z.ZodOptional<z.ZodString>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
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.16",
4
+ "version": "0.3.17",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -38,11 +38,11 @@
38
38
  "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
39
39
  "@deepseek-ai/cordis": "^4.0.1",
40
40
  "@deepseek-ai/dsh-storage-domain": "^0.1.1-rc.2",
41
- "@lmzhen/dsh-evolution-state-storage": "^0.3.16"
41
+ "@lmzhen/dsh-evolution-state-storage": "^0.3.17"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
45
45
  "@deepseek-ai/dsh-storage-domain": "^0.1.1-rc.2",
46
- "@lmzhen/dsh-evolution-state-storage": "^0.3.16"
46
+ "@lmzhen/dsh-evolution-state-storage": "^0.3.17"
47
47
  }
48
48
  }