@zackbart/connecta 0.25.0 → 0.26.0

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.
Files changed (93) hide show
  1. package/AGENTS.md +6 -5
  2. package/CHANGELOG.md +271 -0
  3. package/README.md +32 -15
  4. package/SECURITY.md +6 -5
  5. package/bin/connecta.mjs +5 -1
  6. package/dist/activity.d.ts +10 -3
  7. package/dist/activity.js +10 -1
  8. package/dist/artifacts/connector.d.ts +55 -0
  9. package/dist/artifacts/connector.js +724 -0
  10. package/dist/artifacts/document.js +76 -0
  11. package/dist/artifacts/guide.js +140 -0
  12. package/dist/artifacts/html-scan.js +329 -0
  13. package/dist/artifacts/json.js +68 -0
  14. package/dist/artifacts/kv-store.d.ts +20 -0
  15. package/dist/artifacts/kv-store.js +140 -0
  16. package/dist/artifacts/markdown.js +449 -0
  17. package/dist/artifacts/module.d.ts +37 -0
  18. package/dist/artifacts/module.js +60 -0
  19. package/dist/artifacts/operations.d.ts +195 -0
  20. package/dist/artifacts/operations.js +944 -0
  21. package/dist/artifacts/refresh.d.ts +53 -0
  22. package/dist/artifacts/refresh.js +235 -0
  23. package/dist/artifacts/routes.js +194 -0
  24. package/dist/artifacts/types.d.ts +214 -0
  25. package/dist/artifacts/types.js +22 -0
  26. package/dist/artifacts/validate.d.ts +62 -0
  27. package/dist/artifacts/validate.js +652 -0
  28. package/dist/artifacts.d.ts +6 -0
  29. package/dist/artifacts.js +9 -0
  30. package/dist/catalog-service.js +39 -29
  31. package/dist/catalog.js +42 -8
  32. package/dist/connector-access.d.ts +18 -4
  33. package/dist/connector-access.js +65 -20
  34. package/dist/connector-caller.d.ts +8 -0
  35. package/dist/connector-caller.js +19 -0
  36. package/dist/connectors/remote-mcp.js +16 -2
  37. package/dist/errors.d.ts +16 -1
  38. package/dist/errors.js +28 -0
  39. package/dist/execute.js +427 -70
  40. package/dist/executor-admission.d.ts +11 -1
  41. package/dist/executor-admission.js +79 -14
  42. package/dist/executors/quickjs.js +4 -2
  43. package/dist/index.d.ts +62 -6
  44. package/dist/index.js +230 -6
  45. package/dist/invocation.js +56 -10
  46. package/dist/meta-tools.js +7 -2
  47. package/dist/module-contracts.d.ts +21 -1
  48. package/dist/operator-ui/generated.js +2 -2
  49. package/dist/operator-ui/model.d.ts +62 -5
  50. package/dist/operator-ui/view.js +94 -5
  51. package/dist/program-source.js +116 -0
  52. package/dist/registry.d.ts +42 -6
  53. package/dist/registry.js +148 -47
  54. package/dist/resumable.js +1291 -0
  55. package/dist/routes/activity.js +6 -69
  56. package/dist/routes/actor-labels.js +114 -0
  57. package/dist/routes/credentials.js +27 -5
  58. package/dist/routes/mcp.js +116 -59
  59. package/dist/routes/oauth-management.js +22 -9
  60. package/dist/routes/operator.js +1 -0
  61. package/dist/routes/shared.d.ts +23 -1
  62. package/dist/routes/shared.js +20 -2
  63. package/dist/routes/ui-data.js +2 -1
  64. package/dist/routes/ui.js +13 -4
  65. package/dist/run-journal.js +347 -0
  66. package/dist/runtime/shared-read.js +106 -0
  67. package/dist/server.js +26 -0
  68. package/dist/skills.js +27 -8
  69. package/dist/timeout.js +26 -0
  70. package/dist/tool-safety.d.ts +35 -0
  71. package/dist/tool-safety.js +31 -0
  72. package/dist/types.d.ts +18 -0
  73. package/dist/ui.d.ts +12 -5
  74. package/dist/ui.js +32 -6
  75. package/dist/version.d.ts +1 -1
  76. package/dist/version.js +1 -1
  77. package/documentation/architecture.md +196 -19
  78. package/documentation/auth.md +83 -2
  79. package/documentation/code-mode.md +221 -48
  80. package/documentation/meta-tools.md +44 -25
  81. package/ethos.md +12 -10
  82. package/examples/worker/AGENTS.md +6 -0
  83. package/examples/worker/README.md +174 -10
  84. package/examples/worker/src/d1-activity-row.ts +14 -2
  85. package/examples/worker/src/d1-activity.ts +4 -2
  86. package/examples/worker/src/index.ts +36 -1
  87. package/examples/worker/src/r2-artifact-blobs.ts +29 -0
  88. package/examples/worker/wrangler.jsonc +5 -1
  89. package/package.json +6 -2
  90. package/templates/node/AGENTS.md +9 -2
  91. package/templates/node/README.md +31 -3
  92. package/templates/node/package.json +1 -1
  93. package/templates/node/src/index.ts +27 -0
@@ -37,6 +37,12 @@ This repository is deployment configuration, not a copy of Connecta itself.
37
37
  A configured Connecta bearer cannot cross the Access edge alone. Connecta-issued
38
38
  tokens are removed. UI, vault, and activity use explicit optional imports;
39
39
  auth changes require code-derived shared or personal management permissions.
40
+ - Brand the operator UI in `operatorUi({ branding })`: product and owner names,
41
+ description, favicon, and `theme` (`accent`, `radius`, `fontFamily`,
42
+ `monoFamily`, `colorScheme`). Ask the deployment's owner for their brand
43
+ rather than leaving the default. The commented block above
44
+ `ui: operatorUi()` in `src/index.ts` shows the shape; README "UI and
45
+ encrypted credentials" covers the rest.
40
46
  - After configuration changes, typecheck: inside the connecta repository that
41
47
  is `npm run check:examples`; a copied deployment runs its own `tsc --noEmit`.
42
48
  After deployment, connect both Claude and ChatGPT to `<PUBLIC_URL>/mcp` and
@@ -2,7 +2,7 @@
2
2
 
3
3
  A deployable Worker that aggregates a downstream remote MCP and an in-code HTTP
4
4
  API connector, guarded by Cloudflare Access, with state in a KV namespace. Its
5
- required Worker Loader binding backs the seven-tool surface and requires the
5
+ required Worker Loader binding backs the eight-tool surface and requires the
6
6
  Workers Paid plan.
7
7
 
8
8
  This is also the **starting template for a deployment**: a real deployment
@@ -19,8 +19,17 @@ migrations, and secrets.
19
19
  | `src/d1-storage.ts` | `KVStorage` over D1 with atomic compare-and-set (optional; see below) |
20
20
  | `src/d1-activity.ts` | `ActivityStore` over D1 (deployment-owned; see below) |
21
21
  | `src/d1-activity-row.ts` | the row ↔ event mapping `d1-activity.ts` uses, including friction derived from `error_code` for rows written before that column existed |
22
+ | `src/r2-artifact-blobs.ts` | artifact bodies in an R2 bucket, beside a D1-backed `kvArtifactStore` (optional) |
22
23
  | `wrangler.jsonc` | Worker name, vars, bindings, `compatibility_flags` |
23
24
 
25
+ Keep `enable_request_signal` in `wrangler.jsonc`. On Workers it lets a live
26
+ response's client disconnect abort its request, so connecta cancels the stream
27
+ and returns the admission permit promptly. The total admitted-request bound in
28
+ `admission.requests.maxDurationMs` (default 300,000 ms) also reclaims capacity
29
+ on a later request if workerd ends one without delivering a signal or stream
30
+ cancellation. Set it above the longest authorization, tool call, and response
31
+ delivery your deployment expects to serve.
32
+
24
33
  `cloudflare-kv.ts`, `d1-storage.ts`, and `d1-activity.ts` deliberately live
25
34
  here rather than in the package: storage backends are deployment-owned, so the
26
35
  package ships only the generic `KVStorage` and `ActivityStore` contracts.
@@ -103,11 +112,106 @@ The checked-in `access.dev` block gives `wrangler dev` a local operator
103
112
  identity. Remove the block to test the missing-Access refusal. It has no effect
104
113
  on a deployed Worker's production identity.
105
114
 
115
+ ### Optional resource management with Alchemy
116
+
117
+ Keep this example's Worker on Wrangler. A copied deployment may use
118
+ [Alchemy](https://alchemy.run) to manage its KV namespace, optional D1 databases
119
+ and R2 bucket, and the Access application without adding Alchemy to connecta or
120
+ changing this template. In that deployment, install `alchemy@2.0.0-beta.79`
121
+ and `effect@4.0.0-rc.117` at exact versions. The latter is connecta's own
122
+ Effect pin; check `npm ls effect` for one resolved copy after installation.
123
+ The following `alchemy.run.ts` is a resource stack, not a Worker deployment:
124
+
125
+ ```ts
126
+ import * as Alchemy from "alchemy";
127
+ import * as Cloudflare from "alchemy/Cloudflare";
128
+ import { adopt } from "alchemy/AdoptPolicy";
129
+ import * as Effect from "effect/Effect";
130
+
131
+ // Replace this with the immutable ID of the Wrangler-deployed Worker.
132
+ const workerId = "replace-with-worker-id";
133
+
134
+ export default Alchemy.Stack(
135
+ "ConnectaResources",
136
+ { providers: Cloudflare.providers(), state: Cloudflare.state() },
137
+ Effect.gen(function* () {
138
+ const kv = yield* Cloudflare.KV.Namespace("ConnectaKV", { title: "connecta-kv" }).pipe(adopt(true));
139
+ const activity = yield* Cloudflare.D1.Database("ActivityDB", {
140
+ name: "connecta-activity", migrations: "./migrations/activity",
141
+ }).pipe(adopt(true));
142
+ const storage = yield* Cloudflare.D1.Database("StorageDB", {
143
+ name: "connecta-storage", migrations: "./migrations/storage",
144
+ }).pipe(adopt(true));
145
+ const blobs = yield* Cloudflare.R2.Bucket("ArtifactBlobs", { name: "connecta-artifacts" }).pipe(adopt(true));
146
+ const access = yield* Cloudflare.Access.Application("ConnectaAccess", {
147
+ type: "self_hosted",
148
+ name: "Connecta",
149
+ destinations: [{ type: "worker", workerId }],
150
+ policies: [{ decision: "allow", include: [{ emailDomain: "example.com" }] }],
151
+ oauthConfiguration: {
152
+ enabled: true,
153
+ dynamicClientRegistration: {
154
+ enabled: true,
155
+ allowedUris: [
156
+ "https://claude.ai/api/mcp/auth_callback",
157
+ "https://chatgpt.com/connector_platform_oauth_redirect",
158
+ "https://chatgpt.com/connector/oauth/*",
159
+ ],
160
+ },
161
+ },
162
+ }).pipe(adopt(true));
163
+ return { kvId: kv.namespaceId, activityId: activity.databaseId,
164
+ storageId: storage.databaseId, bucketName: blobs.bucketName,
165
+ accessId: access.applicationId };
166
+ }),
167
+ );
168
+ ```
169
+
170
+ Replace the Worker ID and example Access policy before applying this stack.
171
+ Keep only the resources the deployment uses: `STORAGE_DB` replaces
172
+ `CONNECTA_KV`; `ACTIVITY_DB` and R2 are optional. Copy the output IDs into the
173
+ matching `wrangler.jsonc` bindings. Keep `LOADER` in `worker_loaders` and, when
174
+ enabled, the Browser Rendering binding and cron trigger in the Wrangler-owned
175
+ Worker configuration. Configure the main and artifact hostnames as Wrangler
176
+ custom domain `routes` with `custom_domain: true`. The Worker-level Access
177
+ destination covers both hostnames; verify both against the same application
178
+ after domain setup. Continue to set secrets with `wrangler secret put` and to
179
+ deploy the Worker with Wrangler. After its initial `wrangler deploy`, use
180
+ `wrangler versions upload` and `wrangler versions deploy` for code updates;
181
+ apply route and cron changes through Wrangler too.
182
+
183
+ The `adopt(true)` calls explicitly permit taking over matching existing
184
+ resources; compare their live names, IDs, Access policy, and data before the
185
+ first Alchemy deploy. Remove adoption where a resource is new. Put the D1 SQL
186
+ from this README in the shown migration directories before deploying. With
187
+ `migrations` configured, Alchemy copies an adopted database's Wrangler
188
+ migration history once into `__alchemy_migrations`; the old history stays
189
+ frozen. Review pending SQL before handing migrations over. Remote
190
+ `Cloudflare.state()` bootstraps an account-level state-store Worker backed by a
191
+ Durable Object and Secrets Store entries for its credentials. Retain them:
192
+ deleting the state store loses Alchemy's record of what it owns.
193
+
194
+ Verification for this optional path stops at the API and types. The fenced
195
+ snippet was copied to an isolated `alchemy.run.ts` and passed `tsc --noEmit`
196
+ with TypeScript 5.9.3, Alchemy 2.0.0-beta.79, and Effect 4.0.0-rc.117; no
197
+ Alchemy deploy or adoption was run.
198
+ [Alchemy's Worker resource](https://alchemy.run/cloudflare/compute/workers/)
199
+ can declare `WorkerLoader`, domains, Browser Rendering, and cron wiring, but
200
+ those properties are coupled to its script deploy. Its current full deploy
201
+ still uses the script-upload endpoint; only a conditional gradual rollout uses
202
+ the versions API. A previous full deploy through that endpoint did not provide
203
+ `ctx.access`, so do not transfer Worker ownership until that path is verified
204
+ end to end. The [Access](https://alchemy.run/cloudflare/security/access/),
205
+ [D1](https://alchemy.run/cloudflare/data/d1/), and
206
+ [state-store](https://alchemy.run/state-store/) guides describe the resources
207
+ above; the typecheck does not prove Cloudflare will accept this particular
208
+ Access adoption or preserve production identity.
209
+
106
210
  ### Copied into its own repository
107
211
 
108
212
  The `npm install` above is the connecta repository's, which already has every
109
- dependency this file imports. A copy with its own `package.json` installs three
110
- things, because two of them are not part of connecta and never install with it:
213
+ dependency this file imports. A copy with its own `package.json` installs
214
+ Connecta and the separately installed `@cloudflare/codemode` peer:
111
215
 
112
216
  ```sh
113
217
  npm install @zackbart/connecta @cloudflare/codemode
@@ -125,7 +229,10 @@ the Clerk path in the Node template.
125
229
 
126
230
  Then point an MCP client at `<PUBLIC_URL>/mcp`. The example explicitly enables
127
231
  `ui: operatorUi()`; open `<PUBLIC_URL>/` for Connections and each connection's
128
- authentication controls. There is no separate Credentials or Tokens tab.
232
+ authentication controls. The page labels tool safety, offers fixed repair
233
+ prompts for classified failures, and shows client setup commands for endpoints
234
+ the signed-in person may use. Those commands contain no token. There is no
235
+ separate Credentials or Tokens tab.
129
236
 
130
237
  ## Select optional modules
131
238
 
@@ -166,6 +273,8 @@ Reuse the same key and KV namespace during upgrades. Without the secret, omit
166
273
  the vault; declared credential slots remain unmanageable. Keep the key outside
167
274
  KV because it protects a copied namespace. Credential replacement takes effect
168
275
  on the next call without redeploying; no liveness probe runs in the background.
276
+ With this vault, 0.25.0 seals existing downstream OAuth state on first read.
277
+ Rolling back to 0.24.x then requires reauthorizing those OAuth connectors.
169
278
 
170
279
  The shipped Notion connector uses a deployment-owned static header and echo
171
280
  needs no secret. To exercise vault controls, declare a `credential` slot on an
@@ -186,7 +295,7 @@ below. Omit the module and store wiring to record no history and show no
186
295
  Activity tab. Diagnostics remain independent; `logger: "silent"` suppresses
187
296
  them explicitly.
188
297
 
189
- Verify MCP health and the exact seven tools with:
298
+ Verify MCP health and the exact eight tools with:
190
299
 
191
300
  ```sh
192
301
  CF_ACCESS_CLIENT_ID=… CF_ACCESS_CLIENT_SECRET=… \
@@ -211,7 +320,7 @@ The required Worker Loader binding is checked into `wrangler.jsonc`:
211
320
  ```
212
321
 
213
322
  `src/index.ts` constructs `DynamicWorkerExecutor` with only `env.LOADER` and
214
- serves the seven-tool surface. Do not add `bindings`, `modules`, or
323
+ serves the eight-tool surface. Do not add `bindings`, `modules`, or
215
324
  `globalOutbound`; they grant guest code ambient authority. A copied deployment
216
325
  owns the package install — see
217
326
  [copied into its own repository](#copied-into-its-own-repository).
@@ -219,7 +328,11 @@ owns the package install — see
219
328
  ## Strongly consistent storage (optional)
220
329
 
221
330
  `KVStorage` has an optional atomic `compareAndSet`, for a subsystem that must
222
- claim a key exactly once. **Workers KV cannot provide it.** It is eventually
331
+ claim a key exactly once — resumable writes, where two `resume_execution` calls
332
+ racing for one paused program must send its writes once. **Workers KV cannot
333
+ provide it**, so on KV this example turns resumable writes off
334
+ (`execute: { resumableWrites: false }` in `src/index.ts`) and its programs
335
+ refuse writes. It is eventually
223
336
  consistent: two locations can each read a key as absent and both write, so
224
337
  `cloudflare-kv.ts` declares no `compareAndSet` rather than fake one with a read
225
338
  followed by a write. `src/d1-storage.ts` is a complete `KVStorage` over D1
@@ -256,10 +369,56 @@ of connecta state lives in one store.
256
369
  const storage = d1Storage(env.STORAGE_DB);
257
370
  ```
258
371
 
372
+ Then delete the `execute: { resumableWrites: false }` line: on D1,
373
+ resumable writes default on, and programs pause at a write until
374
+ `resume_execution` approves it.
375
+
259
376
  Switching an existing deployment starts from empty state: downstream OAuth
260
377
  connections must be re-authorized and vault credentials re-entered, because
261
378
  nothing copies them out of the KV namespace.
262
379
 
380
+ ## Artifacts (optional)
381
+
382
+ `artifacts()` from `@zackbart/connecta/artifacts` adds the built-in `artifacts`
383
+ connector: team pages whose data lives in versioned JSON documents. Every write
384
+ commits by compare-and-set, so the store needs the D1 storage above — Workers
385
+ KV is refused at construction. Artifacts share the `connecta_kv` table and need
386
+ no schema of their own. Bodies (page sources and documents) can stay in D1 rows,
387
+ which the default limits keep well under D1's row size, or go to R2 with
388
+ `src/r2-artifact-blobs.ts`:
389
+
390
+ ```ts
391
+ import { artifacts, kvArtifactStore } from "@zackbart/connecta/artifacts";
392
+ import { r2ArtifactBlobs } from "./r2-artifact-blobs.js";
393
+
394
+ createConnecta({
395
+ // …
396
+ publicUrl: env.PUBLIC_URL, // required: artifact links are shared
397
+ artifacts: artifacts({
398
+ store: kvArtifactStore(d1Storage(env.STORAGE_DB), {
399
+ blobs: r2ArtifactBlobs(env.ARTIFACTS_BUCKET), // optional
400
+ }),
401
+ }),
402
+ });
403
+ ```
404
+
405
+ For R2, create the bucket (`wrangler r2 bucket create connecta-artifacts`) and
406
+ add `"r2_buckets": [{ "binding": "ARTIFACTS_BUCKET", "bucket_name":
407
+ "connecta-artifacts" }]` to `wrangler.jsonc` and `ARTIFACTS_BUCKET: R2Bucket`
408
+ to `Env`. Nothing ever deletes a body: versions are immutable, a rollback
409
+ points back at an old one, and a body written by a write that lost a conflict
410
+ stays stored unreferenced.
411
+
412
+ To refresh pages, keep the module in a variable, pass it to `createConnecta`,
413
+ and assign it to `scheduledArtifacts.module` as shown in `src/index.ts`.
414
+ Uncomment the hourly cron in `wrangler.jsonc`. An hourly tick starts at most
415
+ 10 due pages; each page's `manual`, `daily`, or `weekly` schedule lives in its
416
+ versioned refresh configuration. Refresh programs use only shared connectors'
417
+ explicitly read-only tools within the program owner's current grants. Revoking
418
+ refresh or pool access stops future runs. D1's compare-and-set prevents two cron invocations
419
+ from claiming the same page. Failed runs keep the last good data and show a
420
+ stale banner without exposing downstream error text to readers.
421
+
263
422
  ## Activity history (optional)
264
423
 
265
424
  `src/d1-activity.ts` is a complete `ActivityStore` over D1 — keyset paging on
@@ -298,6 +457,7 @@ To enable it:
298
457
  attempts INTEGER NOT NULL,
299
458
  error_code TEXT,
300
459
  friction TEXT,
460
+ approval TEXT,
301
461
  server_name TEXT NOT NULL,
302
462
  server_version TEXT NOT NULL,
303
463
  deployment_id TEXT
@@ -307,15 +467,19 @@ To enable it:
307
467
  ON tool_call_activity (occurred_at_ms DESC, id DESC);
308
468
  ```
309
469
 
310
- **Already have this table?** `actor_namespace` and `friction` were added
311
- after the original example, and `CREATE TABLE IF NOT EXISTS` will not add
312
- them to a table that already exists. Add them as migrations:
470
+ **Already have this table?** `actor_namespace`, `friction`, and `approval`
471
+ were added after the original example, and `CREATE TABLE IF NOT EXISTS`
472
+ will not add them to a table that already exists. Add them as migrations:
313
473
 
314
474
  ```sql
315
475
  ALTER TABLE tool_call_activity ADD COLUMN actor_namespace TEXT;
316
476
  ALTER TABLE tool_call_activity ADD COLUMN friction TEXT;
477
+ ALTER TABLE tool_call_activity ADD COLUMN approval TEXT;
317
478
  ```
318
479
 
480
+ `approval` is set only on an `approved` row — the scope a resumed
481
+ program's approval covered, `call` or `tool` — and is otherwise null.
482
+
319
483
  `friction` is stored rather than derived because one of its classes belongs
320
484
  to a call that *succeeded*: a result too large to return inline is friction
321
485
  for the agent and carries no error code. Rows written before the column keep
@@ -18,8 +18,15 @@ export interface ActivityEvent {
18
18
  | "call_tool"
19
19
  | "call_destructive_tool"
20
20
  | "batch_call"
21
- | "execute_code";
22
- outcome: "success" | "error" | "timeout" | "cancelled";
21
+ | "execute_code"
22
+ | "resume_execution";
23
+ outcome:
24
+ | "success"
25
+ | "error"
26
+ | "timeout"
27
+ | "cancelled"
28
+ | "paused"
29
+ | "approved";
23
30
  durationMs: number;
24
31
  attempts: number;
25
32
  errorCode?: string;
@@ -29,6 +36,7 @@ export interface ActivityEvent {
29
36
  | "destructive_reroute"
30
37
  | "auth_required"
31
38
  | "result_too_large";
39
+ approval?: "call" | "tool";
32
40
  serverName: string;
33
41
  serverVersion: string;
34
42
  deploymentId?: string;
@@ -76,6 +84,8 @@ export interface ActivityRow {
76
84
  attempts: number;
77
85
  error_code: string | null;
78
86
  friction: ActivityEvent["friction"] | null;
87
+ /** Absent from tables created before resumable writes; read as null. */
88
+ approval?: ActivityEvent["approval"] | null;
79
89
  server_name: string;
80
90
  server_version: string;
81
91
  deployment_id: string | null;
@@ -102,6 +112,7 @@ export function activityEventToRow(
102
112
  // friction on a call that succeeded, so it has no error code to derive from
103
113
  // — and `error_code IS NOT NULL` stays an honest count of failures.
104
114
  friction: event.friction ?? null,
115
+ approval: event.approval ?? null,
105
116
  server_name: event.serverName,
106
117
  server_version: event.serverVersion,
107
118
  deployment_id: event.deploymentId ?? null,
@@ -131,6 +142,7 @@ export function activityRowToEvent(
131
142
  attempts: row.attempts,
132
143
  ...(row.error_code ? { errorCode: row.error_code } : {}),
133
144
  ...(friction ? { friction } : {}),
145
+ ...(row.approval ? { approval: row.approval } : {}),
134
146
  serverName: row.server_name,
135
147
  serverVersion: row.server_version,
136
148
  ...(row.deployment_id
@@ -50,8 +50,9 @@ export function d1ActivityStore(db: D1Database): ActivityStore {
50
50
  id, occurred_at_ms, request_id, actor_kind, actor_id,
51
51
  actor_namespace,
52
52
  connector_id, tool_name, source, outcome, duration_ms, attempts,
53
- error_code, friction, server_name, server_version, deployment_id
54
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
53
+ error_code, friction, approval, server_name, server_version,
54
+ deployment_id
55
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
55
56
  )
56
57
  .bind(
57
58
  row.id,
@@ -68,6 +69,7 @@ export function d1ActivityStore(db: D1Database): ActivityStore {
68
69
  row.attempts,
69
70
  row.error_code,
70
71
  row.friction ?? null,
72
+ row.approval ?? null,
71
73
  row.server_name,
72
74
  row.server_version,
73
75
  row.deployment_id,
@@ -8,7 +8,7 @@ import { encryptedCredentialVault } from "@zackbart/connecta/credentials";
8
8
  * by Cloudflare Access, with OAuth/cache state in a KV namespace. Access
9
9
  * authenticates the request before this Worker runs and supplies the trusted
10
10
  * identity through ctx.access. The required Worker Loader binding in
11
- * wrangler.jsonc backs the seven-tool surface.
11
+ * wrangler.jsonc backs the eight-tool surface.
12
12
  *
13
13
  * The operator surface is wired here except for activity history, which needs
14
14
  * a database this example does not create for you: sign-in and the credential
@@ -43,6 +43,8 @@ import {
43
43
  } from "@zackbart/connecta";
44
44
  import { cloudflareAccessAuth } from "@zackbart/connecta/auth/cloudflare-access";
45
45
  import { cloudflareKvStorage } from "./cloudflare-kv.js";
46
+ // import { artifacts, kvArtifactStore } from "@zackbart/connecta/artifacts";
47
+ // import { d1Storage } from "./d1-storage.js";
46
48
  // Activity history, off by default because it needs a D1 database.
47
49
  // import { d1ActivityStore } from "./d1-activity.js";
48
50
 
@@ -67,10 +69,21 @@ interface Env {
67
69
 
68
70
  function build(env: Env) {
69
71
  const storage = cloudflareKvStorage(env.CONNECTA_KV);
72
+ // Optional refreshable pages need the D1 binding, not Workers KV:
73
+ // const artifactModule = artifacts({ store: kvArtifactStore(d1Storage(env.STORAGE_DB)) });
74
+ // scheduledArtifacts.module = artifactModule;
70
75
  return createConnecta({
71
76
  publicUrl: env.PUBLIC_URL,
72
77
  storage,
73
78
  executor: new DynamicWorkerExecutor({ loader: env.LOADER }),
79
+ // Resumable writes — a program pausing at a write until resume_execution
80
+ // approves it — need storage with an atomic compareAndSet, and Workers KV
81
+ // cannot provide one. On KV they are off: programs refuse writes and
82
+ // resume_execution says there is nothing to resume. This line states that
83
+ // choice (without it connecta would warn once at startup). To let programs
84
+ // pause, switch to the D1 store in README.md § "Strongly consistent
85
+ // storage" and delete this line.
86
+ execute: { resumableWrites: false },
74
87
  auth: [
75
88
  // Access owns admission policy. A human identity may use MCP and the
76
89
  // operator pages; a service token may use MCP but cannot mutate operator
@@ -103,7 +116,24 @@ function build(env: Env) {
103
116
  // connector like `notion()`, which declares its own) and the form appears
104
117
  // on the next load.
105
118
  vault: encryptedCredentialVault(storage, env.CREDENTIAL_ENCRYPTION_KEY),
119
+ // Branding is code too: name, owner, description, favicon, and five theme
120
+ // tokens that every other color is mixed from. A value that fails its
121
+ // check falls back to the default, and the startup warning names it.
122
+ // ui: operatorUi({
123
+ // branding: {
124
+ // productName: "Acme Tools",
125
+ // ownerName: "Acme",
126
+ // theme: {
127
+ // accent: "#2f5fe0", // hex only
128
+ // radius: 10, // pixels, or a CSS length such as "0.5rem"
129
+ // fontFamily: "Inter, system-ui, sans-serif",
130
+ // monoFamily: "ui-monospace, monospace",
131
+ // colorScheme: "system", // or "light" | "dark"
132
+ // },
133
+ // },
134
+ // }),
106
135
  ui: operatorUi(),
136
+ // artifacts: artifactModule,
107
137
  identity: { credentialAdministration: () => "all", personalConnection: () => "all" },
108
138
  // Payload-free activity at /activity, off until a database exists to hold
109
139
  // it. Uncomment the `d1_databases` binding in wrangler.jsonc, apply the
@@ -162,6 +192,7 @@ function build(env: Env) {
162
192
  // Lazy per-isolate singleton: reuses the plain-data tool cache. Downstream MCP
163
193
  // clients are request-scoped internally so Worker I/O never crosses requests.
164
194
  let connecta: ReturnType<typeof build> | undefined;
195
+ const scheduledArtifacts: { module?: { runDue(): Promise<unknown> } } = {};
165
196
 
166
197
  export default {
167
198
  // Pass `ctx` through: connecta hands deferred work (activity sinks) to
@@ -175,4 +206,8 @@ export default {
175
206
  connecta ??= build(env);
176
207
  return connecta.fetch(request, env, ctx);
177
208
  },
209
+ async scheduled(_event: ScheduledController, env: Env): Promise<void> {
210
+ connecta ??= build(env);
211
+ await scheduledArtifacts.module?.runDue();
212
+ },
178
213
  };
@@ -0,0 +1,29 @@
1
+ import type { ArtifactBlobStore } from "@zackbart/connecta/artifacts";
2
+
3
+ /**
4
+ * Artifact bodies — page sources, data documents, refresh programs — in an R2
5
+ * bucket, beside a D1-backed `kvArtifactStore` that keeps the heads, versions,
6
+ * and runs. Optional: without it, bodies live in D1 rows, which the default
7
+ * limits keep well under D1's row size. Use it once pages or documents grow,
8
+ * or to keep large bodies out of the database a backup copies.
9
+ *
10
+ * Keys are content addresses, so writing one twice writes the same bytes, and
11
+ * nothing here ever deletes one: versions are immutable, and a rollback points
12
+ * back at an old body rather than copying it.
13
+ */
14
+ export function r2ArtifactBlobs(
15
+ bucket: R2Bucket,
16
+ prefix = "artifacts/blobs/",
17
+ ): ArtifactBlobStore {
18
+ return {
19
+ async put(key, body) {
20
+ await bucket.put(`${prefix}${key}`, body, {
21
+ httpMetadata: { contentType: "text/plain; charset=utf-8" },
22
+ });
23
+ },
24
+ async get(key) {
25
+ const object = await bucket.get(`${prefix}${key}`);
26
+ return object ? object.text() : null;
27
+ },
28
+ };
29
+ }
@@ -3,9 +3,13 @@
3
3
  "name": "connecta-example",
4
4
  "main": "src/index.ts",
5
5
  "compatibility_date": "2025-01-01",
6
- "compatibility_flags": ["nodejs_compat"],
6
+ "compatibility_flags": ["nodejs_compat", "enable_request_signal"],
7
7
  "observability": { "enabled": true },
8
8
 
9
+ // Uncomment with artifacts and D1 in src/index.ts. Every hourly tick runs
10
+ // at most 10 due pages; each page's own daily/weekly schedule lives in data.
11
+ // "triggers": { "crons": ["0 * * * *"] },
12
+
9
13
  // Plain vars. Secrets (CREDENTIAL_ENCRYPTION_KEY, DOWNSTREAM_TOKEN) are set with
10
14
  // `wrangler secret put <NAME>`, not here.
11
15
  "vars": {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@zackbart/connecta",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
- "description": "One MCP to rule them all — a single MCP endpoint aggregating many downstream connectors behind a code-first surface of seven meta-tools.",
6
+ "description": "One MCP to rule them all — a single MCP endpoint aggregating many downstream connectors behind a code-first surface of eight meta-tools.",
7
7
  "license": "MIT",
8
8
  "engines": {
9
9
  "node": ">=22.0.0"
@@ -110,6 +110,10 @@
110
110
  "./auth/bearer": {
111
111
  "types": "./dist/auth/bearer.d.ts",
112
112
  "import": "./dist/auth/bearer.js"
113
+ },
114
+ "./artifacts": {
115
+ "types": "./dist/artifacts.d.ts",
116
+ "import": "./dist/artifacts.js"
113
117
  }
114
118
  },
115
119
  "scripts": {
@@ -3,8 +3,9 @@
3
3
  This repository is deployment configuration, not a copy of Connecta itself.
4
4
 
5
5
  - Edit `src/index.ts` for connectors, authentication, storage, and public URL.
6
- - Keep `executor: quickJsExecutor()` for the prescribed seven-tool code-first
7
- surface.
6
+ - Keep `executor: quickJsExecutor()` for the prescribed eight-tool code-first
7
+ surface. File storage supports resumable writes, so a program pauses at a
8
+ write until `resume_execution` approves it.
8
9
  - Keep credentials in environment variables or an external secret store.
9
10
  Never commit `.env`, `.connecta-state.json`, `.connecta-activity.jsonl`,
10
11
  tokens, or credential values.
@@ -19,6 +20,12 @@ This repository is deployment configuration, not a copy of Connecta itself.
19
20
  alone never grants it. Configured bearer auth is a client option, not a human
20
21
  management identity. Connecta-issued access tokens are removed.
21
22
  `src/file-activity.ts` remains the deployment-owned history store.
23
+ - Brand the operator UI in `operatorUi({ branding })`: product and owner names,
24
+ description, favicon, and `theme` (`accent`, `radius`, `fontFamily`,
25
+ `monoFamily`, `colorScheme`). Ask the deployment's owner for their brand
26
+ rather than leaving the default. The commented block above
27
+ `ui: operatorUi()` in `src/index.ts` shows the shape; README "Select optional
28
+ modules" covers the rest.
22
29
  - Run `npm run typecheck` after configuration changes. With the server running,
23
30
  run `CONNECTA_TOKEN=... npm run doctor` before calling setup complete.
24
31
  - `Dockerfile` and `docker-compose.yml` containerize *this* source; they are
@@ -46,11 +46,32 @@ reproducible `npm ci` path.
46
46
 
47
47
  ## Select optional modules
48
48
 
49
+ For scheduled artifact pages, uncomment the `artifacts()` module and hourly
50
+ `setInterval` block in `src/index.ts`. The module uses the same CAS-capable
51
+ state file and exposes `runDue()` for the timer; core starts no job on its own.
52
+ Each tick starts at most 10 due pages. Refresh programs can call only shared
53
+ connectors' explicitly read-only tools within the program owner's current
54
+ grants. Revoking refresh or pool access stops future runs. Failed runs leave the last good data
55
+ and mark the viewer stale.
56
+
49
57
  The template explicitly enables `ui: operatorUi()` from
50
58
  `@zackbart/connecta/ui`. Open `http://localhost:8787/` and supply the configured
51
59
  bearer to inspect Connections. Omit that option and import for an API-only
52
60
  server. OAuth callbacks remain in core even with no UI.
53
61
 
62
+ The page labels whether each tool runs in programs or needs approval. For
63
+ classified connection failures it offers a fixed repair prompt, and its
64
+ endpoint section has client setup commands for `/mcp` and any pool available
65
+ to the signed-in identity. Those commands contain no bearer token.
66
+
67
+ Branding belongs in `operatorUi({ branding })`: `productName`, `ownerName`,
68
+ their URLs, `description`, `pageTitle`, `favicon`, and `theme`. The theme is
69
+ five tokens — `accent`, `radius`, `fontFamily`, `monoFamily`, and
70
+ `colorScheme` — and every other color is mixed from them, so one accent themes
71
+ the whole page. A value that fails its gate falls back to the default, and the
72
+ startup warning names it. `src/index.ts` carries the full shape commented out
73
+ above `ui: operatorUi()`.
74
+
54
75
  Connection management needs an interactive identity. A configured bearer is a
55
76
  client key and never authorizes browser credential mutations. To enable Clerk:
56
77
 
@@ -89,6 +110,12 @@ it through `await ctx.credential?.get()`, or use a provider such as `notion()`
89
110
  that declares its own slot. Authorized humans manage the slot inside that
90
111
  connection on `/`; there is no separate Credentials tab.
91
112
 
113
+ In 0.25.0, this vault also seals downstream OAuth tokens on their first read.
114
+ That is a one-way state migration for those tokens: rolling back to 0.24.x
115
+ requires authorizing each OAuth connector again. See the
116
+ [0.25.0 changelog](../../CHANGELOG.md#0250--2026-09-23) before upgrading a
117
+ deployment with existing OAuth connections.
118
+
92
119
  A saved replacement takes effect on the next call. Connecta tests credentials
93
120
  only on an explicit action and otherwise fails at use. Without a vault or UI,
94
121
  static credential recovery reports unavailable instead of offering a dead link.
@@ -132,16 +159,17 @@ npm run typecheck
132
159
  CONNECTA_TOKEN=dev-token npm run doctor
133
160
  ```
134
161
 
135
- Doctor checks health, the executor, and the exact prescribed seven-tool
162
+ Doctor checks health, the executor, and the exact prescribed eight-tool
136
163
  model-facing surface by running a harmless sandbox program. It reads the bearer
137
164
  from `CONNECTA_TOKEN`; it never accepts the secret as a command-line argument.
138
165
  Remote URLs must use HTTPS.
139
166
 
140
167
  A fully-wired deployment reports exactly the same line as a bare one —
141
- connector count, QuickJS executed, seven tools, plus any catalog drift:
168
+ connector count, QuickJS executed, eight tools, plus any catalog drift, and
169
+ a note if resumable writes are off:
142
170
 
143
171
  ```text
144
- Connecta doctor passed: 1 connector(s), QuickJS executed, prescribed seven-tool surface.
172
+ Connecta doctor passed: 1 connector(s), QuickJS executed, prescribed eight-tool surface.
145
173
  ```
146
174
 
147
175
  `QuickJS` is this deployment's sandbox, reported by the deployment itself —
@@ -15,7 +15,7 @@
15
15
  "typecheck": "tsc --noEmit"
16
16
  },
17
17
  "dependencies": {
18
- "@zackbart/connecta": "0.25.0",
18
+ "@zackbart/connecta": "0.26.0",
19
19
  "quickjs-emscripten": "0.32.0"
20
20
  },
21
21
  "devDependencies": {
@@ -27,6 +27,7 @@ import { operatorUi } from "@zackbart/connecta/ui";
27
27
  import { api, createConnecta } from "@zackbart/connecta";
28
28
  import { fileStorage, listen } from "@zackbart/connecta/node";
29
29
  import { quickJsExecutor } from "@zackbart/connecta/quickjs";
30
+ // import { artifacts, kvArtifactStore } from "@zackbart/connecta/artifacts";
30
31
  // Operator sign-in. Needs `npm install @clerk/backend` — it is an optional
31
32
  // peer, so it does not install with Connecta.
32
33
  // import { clerkAuth } from "@zackbart/connecta/auth/clerk";
@@ -45,6 +46,8 @@ const port = Number(process.env.PORT ?? 8787);
45
46
  const stateFile = process.env.CONNECTA_STATE_FILE || "./.connecta-state.json";
46
47
  const publicUrl = process.env.PUBLIC_URL || `http://localhost:${port}`;
47
48
  const storage = fileStorage(stateFile);
49
+ // Optional artifact pages and refresh jobs use the same CAS-capable state file:
50
+ // const artifactModule = artifacts({ store: kvArtifactStore(storage) });
48
51
 
49
52
  // Operator sign-in. A bearer token is a client key: it may call tools and read
50
53
  // connector status, but only a Clerk-authenticated human may write a visible
@@ -103,7 +106,25 @@ const connecta = createConnecta({
103
106
  // ),
104
107
  // deploymentId: "production",
105
108
  // }),
109
+ // The operator UI at /. Its branding is code, like everything else here:
110
+ // name, owner, description, favicon, and five theme tokens that every
111
+ // other color is mixed from. A value that fails its check falls back to the
112
+ // default, and the startup warning names it.
113
+ // ui: operatorUi({
114
+ // branding: {
115
+ // productName: "Acme Tools",
116
+ // ownerName: "Acme",
117
+ // theme: {
118
+ // accent: "#2f5fe0", // hex only
119
+ // radius: 10, // pixels, or a CSS length such as "0.5rem"
120
+ // fontFamily: "Inter, system-ui, sans-serif",
121
+ // monoFamily: "ui-monospace, monospace",
122
+ // colorScheme: "system", // or "light" | "dark"
123
+ // },
124
+ // },
125
+ // }),
106
126
  ui: operatorUi(),
127
+ // artifacts: artifactModule,
107
128
  connectors: [
108
129
  api("time", {
109
130
  description: "Time — current timestamp",
@@ -126,3 +147,9 @@ const connecta = createConnecta({
126
147
 
127
148
  listen(connecta, port);
128
149
  console.log(`connecta listening on port ${port}; MCP at ${publicUrl}/mcp`);
150
+ // The deployment owns this timer; core starts no background work. Uncomment
151
+ // with artifactModule above. Each tick starts at most 10 due pages.
152
+ // const refreshTimer = setInterval(() => {
153
+ // void artifactModule.runDue().catch((error) => console.error("artifact refresh failed", error));
154
+ // }, 60 * 60 * 1000);
155
+ // refreshTimer.unref();