Personal Telegram developer console for GitHub

feat(cp2): sync src/core/workspace-store.js

davoodmehraban89 committed Oct 5, 2026 at 05:53 UTC 4e12fb28378e86fd508f8398cfa883f1ccb4c7ef
1 file changed +22 -75
src/core/workspace-store.js
+22 -75
@@ -11,11 +11,7 @@ export class DurableWorkspaceStoreClient {
11 }
12
13 isConfigured() {
14 - return Boolean(
15 - this.namespace &&
16 - typeof this.namespace.idFromName === 'function' &&
17 - typeof this.namespace.get === 'function'
18 - );
14 + return Boolean(this.namespace && typeof this.namespace.idFromName === 'function' && typeof this.namespace.get === 'function');
15 }
16
17 async #call(ownerId, operation, payload = {}) {
@@ -24,79 +20,30 @@ export class DurableWorkspaceStoreClient {
20 if (!owner) throw new Error('Workspace owner is required');
21 const id = this.namespace.idFromName(owner);
22 const stub = this.namespace.get(id);
27 - const response = await stub.fetch(jsonRequest(`https://workspace-store/${operation}`, {
28 - ...payload,
29 - now: Number(this.now())
30 - }));
23 + const response = await stub.fetch(jsonRequest(`https://workspace-store/${operation}`, { ...payload, now: Number(this.now()) }));
24 let body = null;
25 try { body = await response.json(); } catch { body = null; }
33 - if (!response.ok) {
34 - throw new Error(body?.error || `Durable workspace store failed (${response.status})`);
35 - }
26 + if (!response.ok) throw new Error(body?.error || `Durable workspace store failed (${response.status})`);
27 return body?.result ?? null;
28 }
29
39 - createNavigationRefs({ ownerId, refs, ttlMs = 900_000 } = {}) {
40 - return this.#call(ownerId, 'refs/create', { refs, ttlMs });
41 - }
42 -
43 - resolveNavigationRef({ ownerId, refId } = {}) {
44 - return this.#call(ownerId, 'refs/get', { refId });
45 - }
46 -
47 - createWorkspace({ ownerId, ...workspace } = {}) {
48 - return this.#call(ownerId, 'workspace/create', workspace);
49 - }
50 -
51 - getWorkspace({ ownerId, workspaceId } = {}) {
52 - return this.#call(ownerId, 'workspace/get', { workspaceId });
53 - }
54 -
55 - updateDraft({ ownerId, workspaceId, text, digest } = {}) {
56 - return this.#call(ownerId, 'workspace/draft', { workspaceId, text, digest });
57 - }
58 -
59 - setPendingInput({ ownerId, workspaceId, mode } = {}) {
60 - return this.#call(ownerId, 'pending/set', { workspaceId, mode });
61 - }
62 -
63 - getPendingInput({ ownerId } = {}) {
64 - return this.#call(ownerId, 'pending/get');
65 - }
66 -
67 - consumePendingInput({ ownerId, workspaceId, mode } = {}) {
68 - return this.#call(ownerId, 'pending/consume', { workspaceId, mode });
69 - }
70 -
71 - setCommitMessage({ ownerId, workspaceId, message, digest } = {}) {
72 - return this.#call(ownerId, 'workspace/message', { workspaceId, message, digest });
73 - }
74 -
75 - sealIntent({ ownerId, workspaceId, intent } = {}) {
76 - return this.#call(ownerId, 'intent/seal', { workspaceId, intent });
77 - }
78 -
79 - getIntent({ ownerId, intentId } = {}) {
80 - return this.#call(ownerId, 'intent/get', { intentId });
81 - }
82 -
83 - beginCommit({ ownerId, intentId } = {}) {
84 - return this.#call(ownerId, 'intent/begin', { intentId });
85 - }
86 -
87 - setCandidateCommit({ ownerId, intentId, commitSha } = {}) {
88 - return this.#call(ownerId, 'intent/candidate', { intentId, commitSha });
89 - }
90 -
91 - completeCommit({ ownerId, intentId, commitSha, branch } = {}) {
92 - return this.#call(ownerId, 'intent/complete', { intentId, commitSha, branch });
93 - }
94 -
95 - markStale({ ownerId, intentId, reason } = {}) {
96 - return this.#call(ownerId, 'intent/stale', { intentId, reason });
97 - }
98 -
99 - cancelWorkspace({ ownerId, workspaceId } = {}) {
100 - return this.#call(ownerId, 'workspace/cancel', { workspaceId });
101 - }
30 + createNavigationRefs({ ownerId, refs, ttlMs = 900_000 } = {}) { return this.#call(ownerId, 'refs/create', { refs, ttlMs }); }
31 + resolveNavigationRef({ ownerId, refId } = {}) { return this.#call(ownerId, 'refs/get', { refId }); }
32 + createWorkspace({ ownerId, ...workspace } = {}) { return this.#call(ownerId, 'workspace/create', workspace); }
33 + getWorkspace({ ownerId, workspaceId } = {}) { return this.#call(ownerId, 'workspace/get', { workspaceId }); }
34 + updateDraft({ ownerId, workspaceId, text, digest } = {}) { return this.#call(ownerId, 'workspace/draft', { workspaceId, text, digest }); }
35 + upsertWorkspaceFile({ ownerId, workspaceId, file } = {}) { return this.#call(ownerId, 'workspace/file/upsert', { workspaceId, file }); }
36 + updateWorkspaceFileDraft({ ownerId, workspaceId, path, text, digest } = {}) { return this.#call(ownerId, 'workspace/file/draft', { workspaceId, path, text, digest }); }
37 + removeWorkspaceFile({ ownerId, workspaceId, path } = {}) { return this.#call(ownerId, 'workspace/file/remove', { workspaceId, path }); }
38 + setPendingInput({ ownerId, workspaceId, mode } = {}) { return this.#call(ownerId, 'pending/set', { workspaceId, mode }); }
39 + getPendingInput({ ownerId } = {}) { return this.#call(ownerId, 'pending/get'); }
40 + consumePendingInput({ ownerId, workspaceId, mode } = {}) { return this.#call(ownerId, 'pending/consume', { workspaceId, mode }); }
41 + setCommitMessage({ ownerId, workspaceId, message, digest } = {}) { return this.#call(ownerId, 'workspace/message', { workspaceId, message, digest }); }
42 + sealIntent({ ownerId, workspaceId, intent } = {}) { return this.#call(ownerId, 'intent/seal', { workspaceId, intent }); }
43 + getIntent({ ownerId, intentId } = {}) { return this.#call(ownerId, 'intent/get', { intentId }); }
44 + beginCommit({ ownerId, intentId } = {}) { return this.#call(ownerId, 'intent/begin', { intentId }); }
45 + setCandidateCommit({ ownerId, intentId, commitSha } = {}) { return this.#call(ownerId, 'intent/candidate', { intentId, commitSha }); }
46 + completeCommit({ ownerId, intentId, commitSha, branch } = {}) { return this.#call(ownerId, 'intent/complete', { intentId, commitSha, branch }); }
47 + markStale({ ownerId, intentId, reason } = {}) { return this.#call(ownerId, 'intent/stale', { intentId, reason }); }
48 + cancelWorkspace({ ownerId, workspaceId } = {}) { return this.#call(ownerId, 'workspace/cancel', { workspaceId }); }
49 }