Personal Telegram developer console for GitHub
feat: add durable workspace store client
davoodmehraban89 committed
Oct 3, 2026 at 12:32 UTC
34ab9760c6bab290b0420d6e9b70baa7f41e429f
1 file changed
+102
src/core/workspace-store.js
new
+102
@@ -0,0 +1,102 @@
1
+const jsonRequest = (url, body) => new Request(url, {
2
+ method: 'POST',
3
+ headers: { 'content-type': 'application/json' },
4
+ body: JSON.stringify(body)
5
+});
6
+
7
+export class DurableWorkspaceStoreClient {
8
+ constructor({ namespace = null, now = () => Date.now() } = {}) {
9
+ this.namespace = namespace;
10
+ this.now = now;
11
+ }
12
+
13
+ isConfigured() {
14
+ return Boolean(
15
+ this.namespace &&
16
+ typeof this.namespace.idFromName === 'function' &&
17
+ typeof this.namespace.get === 'function'
18
+ );
19
+ }
20
+
21
+ async #call(ownerId, operation, payload = {}) {
22
+ if (!this.isConfigured()) throw new Error('Durable workspace store is not configured');
23
+ const owner = String(ownerId ?? '');
24
+ if (!owner) throw new Error('Workspace owner is required');
25
+ const id = this.namespace.idFromName(owner);
26
+ 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
+ }));
31
+ let body = null;
32
+ 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
+ }
36
+ return body?.result ?? null;
37
+ }
38
+
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
+ }
102
+}