Personal Telegram developer console for GitHub

feat/studio-g0-foundation
audit/commit-drilldown audit/finalize-workspace-menu-security audit/ops-actionability audit/pr-menu-consolidation audit/status-menu-consolidation audit/telegram-menu-e2e audit/telegram-menu-e2e-wave2 chore/actions-node24-runtime cleanup/remove-diag design/cloudflare-ops-read docs/control-plane-2-7-design docs/guide-v2-1-sync docs/menu-audit-final-sync docs/phase2-acceptance-closeout docs/phase2-multifile-design feat/bootstrap-worker feat/cloudflare-ops-read feat/cp2-multifile-final feat/cp2-multifile-workspace feat/cp3-github-write-final feat/cp4-cloudflare-ops-final feat/cp5-cicd-control-plane feat/cp6-incident-manager feat/cp7-automation-engine feat/deep-file-browser feat/final-delivery-16-20 feat/github-advanced-read feat/in-app-guide-v2 feat/navigation-recovery-ux-v2 feat/ops-console-v2-1 feat/persistent-menu-code-input feat/phase2-multifile-workspace feat/phase2-multifile-workspace-v2 feat/plugin-foundation-v1 feat/safe-github-ops feat/self-register-webhook feat/studio-g0-foundation feat/telegram-main-inline-menu feat/telegram-pr-merge feat/ux-platform-8-12 feat/v3a-readonly-copilot feat/workspace-file-upload feature/mobile-repo-browser feature/multi-file-change-set fix/approval-expiry-feedback fix/callback-resilience-and-docs fix/ci-actions-pagination fix/cloudflare-fetch-binding fix/editor-request-body-cap fix/editor-safe-file-options fix/issues-permission-release-empty-ux fix/main-menu-callback-fallback fix/phase2-file-editor-selection fix/phase2-final-ux fix/phase2-workspace-ref-persistence fix/production-auto-deploy fix/provider-write-error-feedback fix/repository-id-navigation-fallback fix/repository-pr-navigation fix/telegram-callback-updates fix/telegram-runtime-diagnostics fix/workspace-editor-flow-v2 fix/workspace-recovery-validation hardening/ci-zero-test-telegram-token hardening/pr1-destructive-totp hardening/pr2-kill-switch main multifile-workspace nexa/edit-BwJEIIY3PW nexa/edit-IPHT8irO7b nexa/edit-b4Od3BIMYd p2-multifile phase2-20261005 phase2-20261005-a phase2-20261005-b phase2-20261005-c phase2-20261005-d phase2-20261005-e phase2-20261005-f phase2-20261005-g phase2-20261005-h phase2-20261005-i phase2-20261005-j phase2-20261005-k phase2-20261005-l phase2-20261005-m phase2-20261005-n phase2-20261005-o phase2-20261005-p phase2-20261005-q phase2-20261005-r phase2-20261005-s phase2-20261005-t phase2-20261005-u phase2-20261005-v phase2-20261005-w phase2-20261005-x phase2-20261005-y phase2-20261005-z phase2-acceptance-closeout phase2-add-file-hotfix phase2-change-set phase2-design-20261005 phase2-design-final phase2-implementation phase2-multifile-implementation phase2-multifile-spec phase2-spec-final phase2-workspace phase2/multifile-workspace plan/nexa-studio-v2-reviewed security/remove-telegram-setup spec/repository-workspace-editor v3a/multifile work/multifile
js 138 lines 4.07 KB
Raw
1 const jsonRequest = (url, body) =>
2 new Request(url, {
3 method: 'POST',
4 headers: { 'content-type': 'application/json' },
5 body: JSON.stringify(body)
6 });
7
8 export class DurableWorkspaceStoreClient {
9 constructor({ namespace = null, now = () => Date.now() } = {}) {
10 this.namespace = namespace;
11 this.now = now;
12 }
13
14 isConfigured() {
15 return Boolean(
16 this.namespace &&
17 typeof this.namespace.idFromName === 'function' &&
18 typeof this.namespace.get === 'function'
19 );
20 }
21
22 async #call(ownerId, operation, payload = {}) {
23 if (!this.isConfigured())
24 throw new Error('Durable workspace store is not configured');
25 const owner = String(ownerId ?? '');
26 if (!owner) throw new Error('Workspace owner is required');
27 const id = this.namespace.idFromName(owner);
28 const stub = this.namespace.get(id);
29 const response = await stub.fetch(
30 jsonRequest(`https://workspace-store/${operation}`, {
31 ...payload,
32 now: Number(this.now())
33 })
34 );
35 let body = null;
36 try {
37 body = await response.json();
38 } catch {
39 body = null;
40 }
41 if (!response.ok) {
42 const error = new Error(
43 body?.error || `Durable workspace store failed (${response.status})`
44 );
45 error.status = response.status;
46 if (typeof body?.code === 'string') error.code = body.code;
47 throw error;
48 }
49 return body?.result ?? null;
50 }
51
52 createNavigationRefs({ ownerId, refs, ttlMs = 900_000 } = {}) {
53 return this.#call(ownerId, 'refs/create', { refs, ttlMs });
54 }
55 resolveNavigationRef({ ownerId, refId } = {}) {
56 return this.#call(ownerId, 'refs/get', { refId });
57 }
58 createWorkspace({ ownerId, ...workspace } = {}) {
59 return this.#call(ownerId, 'workspace/create', workspace);
60 }
61 getWorkspace({ ownerId, workspaceId } = {}) {
62 return this.#call(ownerId, 'workspace/get', { workspaceId });
63 }
64 updateDraft({ ownerId, workspaceId, text, digest } = {}) {
65 return this.#call(ownerId, 'workspace/draft', {
66 workspaceId,
67 text,
68 digest
69 });
70 }
71 upsertWorkspaceFile({ ownerId, workspaceId, file } = {}) {
72 return this.#call(ownerId, 'workspace/file/upsert', { workspaceId, file });
73 }
74 updateWorkspaceFileDraft({
75 ownerId,
76 workspaceId,
77 path,
78 text,
79 digest,
80 expectedRevision
81 } = {}) {
82 return this.#call(ownerId, 'workspace/file/draft', {
83 workspaceId,
84 path,
85 text,
86 digest,
87 expectedRevision
88 });
89 }
90 removeWorkspaceFile({ ownerId, workspaceId, path } = {}) {
91 return this.#call(ownerId, 'workspace/file/remove', { workspaceId, path });
92 }
93 setPendingInput({ ownerId, workspaceId, mode } = {}) {
94 return this.#call(ownerId, 'pending/set', { workspaceId, mode });
95 }
96 getPendingInput({ ownerId } = {}) {
97 return this.#call(ownerId, 'pending/get');
98 }
99 consumePendingInput({ ownerId, workspaceId, mode } = {}) {
100 return this.#call(ownerId, 'pending/consume', { workspaceId, mode });
101 }
102 setCommitMessage({ ownerId, workspaceId, message, digest } = {}) {
103 return this.#call(ownerId, 'workspace/message', {
104 workspaceId,
105 message,
106 digest
107 });
108 }
109 sealIntent({ ownerId, workspaceId, intent, expectedReview } = {}) {
110 return this.#call(ownerId, 'intent/seal', {
111 workspaceId,
112 intent,
113 expectedReview
114 });
115 }
116 getIntent({ ownerId, intentId } = {}) {
117 return this.#call(ownerId, 'intent/get', { intentId });
118 }
119 beginCommit({ ownerId, intentId } = {}) {
120 return this.#call(ownerId, 'intent/begin', { intentId });
121 }
122 setCandidateCommit({ ownerId, intentId, commitSha } = {}) {
123 return this.#call(ownerId, 'intent/candidate', { intentId, commitSha });
124 }
125 completeCommit({ ownerId, intentId, commitSha, branch } = {}) {
126 return this.#call(ownerId, 'intent/complete', {
127 intentId,
128 commitSha,
129 branch
130 });
131 }
132 markStale({ ownerId, intentId, reason } = {}) {
133 return this.#call(ownerId, 'intent/stale', { intentId, reason });
134 }
135 cancelWorkspace({ ownerId, workspaceId } = {}) {
136 return this.#call(ownerId, 'workspace/cancel', { workspaceId });
137 }
138 }