@tangle-network/create-agent-app 0.63.2 → 0.63.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/create-agent-app",
3
- "version": "0.63.2",
3
+ "version": "0.63.3",
4
4
  "description": "Create a tested Tangle agent application with either a tool loop or a complete chat interface.",
5
5
  "keywords": [
6
6
  "tangle",
@@ -145,3 +145,11 @@ time is insufficient), then use `/turn-stream`’s `releaseDurableTurnLock` with
145
145
  the held executionId and lockId. Its authorization remains deployment-owned.
146
146
  This is a supported typed adapter requirement, not database surgery or automatic
147
147
  resubmission. Retained operator UUIDs continue to identify their original work.
148
+
149
+
150
+ The workspace prewarm route wakes its single-flight lock on page-open and
151
+ composer focus, including Router-only turns; Router warm does not provision a
152
+ box. Apply all `migrations/`, including warm receipts, before deployment.
153
+ Set `D1_REGION` beside the database configuration to match the primary's region.
154
+ It is the one setting used by chat and prewarm for new lock channel placement;
155
+ existing channel locations and IDs do not change.
@@ -66,6 +66,8 @@ fallthrough = true
66
66
  # BETTER_AUTH_SECRET, TANGLE_API_KEY, SANDBOX_API_KEY, SANDBOX_GATEWAY_URL.
67
67
  # See .dev.vars.example for the full list.
68
68
  [vars]
69
+ # Match the primary D1 region; hints affect new lock channels only.
70
+ D1_REGION = "enam"
69
71
  # Enable only after the deployment payer reviews signup, funding and run policy.
70
72
  OPERATOR_RUN_ENABLED = "false"
71
73
  BETTER_AUTH_URL = "http://localhost:8787"
@@ -0,0 +1,8 @@
1
+ -- Shared keyed prewarm receipts; historical warm state is never inferred.
2
+ CREATE TABLE IF NOT EXISTS warm_receipts (
3
+ id TEXT PRIMARY KEY,
4
+ at INTEGER NOT NULL,
5
+ expires_at INTEGER NOT NULL,
6
+ report TEXT
7
+ );
8
+ CREATE INDEX IF NOT EXISTS warm_receipts_by_expiry ON warm_receipts (expires_at);
@@ -139,7 +139,7 @@ export function buildChatApp(env: AppEnv, overrides: ChatAppOverrides = {}): Cha
139
139
  }
140
140
 
141
141
  const durableLock = env.TURN_STREAM && env.TURN_STREAM_AUTH_SECRET
142
- ? createDurableTurnLock<void>({ namespace: env.TURN_STREAM, auth: { secret: env.TURN_STREAM_AUTH_SECRET }, scopeOf: () => 'workspace',
142
+ ? createDurableTurnLock<void>({ namespace: env.TURN_STREAM, auth: { secret: env.TURN_STREAM_AUTH_SECRET }, locationHint: env.D1_REGION, scopeOf: () => 'workspace',
143
143
  onRefused: active => Response.json({ error: { code: 'workspace_turn_in_flight', message: `Execution ${active.executionId} in thread ${active.threadId} still owns this workspace. If observation was lost, the deployment operator must verify that exact backend execution stopped and use a fenced reconciliation adapter; elapsed time or another UUID is not recovery.`, executionId: active.executionId, threadId: active.threadId } }, { status: 409 }),
144
144
  })
145
145
  : null
@@ -6,7 +6,7 @@
6
6
  * `.dev.vars.example` for the full list with comments.
7
7
  */
8
8
 
9
- import type { TurnStreamNamespaceLike } from '@tangle-network/agent-app/turn-stream'
9
+ import type { TurnStreamNamespaceLike, TurnStreamLocationHint } from '@tangle-network/agent-app/turn-stream'
10
10
 
11
11
  export interface AppEnv {
12
12
  /** Shared durable workspace single-flight lock, used by every chat entrypoint. */
@@ -16,6 +16,8 @@ export interface AppEnv {
16
16
  ASSETS?: { fetch(request: Request): Promise<Response> }
17
17
  /** D1 database — run `migrations/` against it before first boot. */
18
18
  DB: D1Database
19
+ /** Match the D1 primary region; used to place newly created lock channels. */
20
+ D1_REGION?: TurnStreamLocationHint
19
21
 
20
22
  /** Absolute origin better-auth serves from (e.g. http://localhost:8787). */
21
23
  BETTER_AUTH_URL: string
@@ -239,20 +239,27 @@ export function createHybridLane(env: AppEnv) {
239
239
 
240
240
  /**
241
241
  * Warm the open workspace's box (`POST /api/chat/prewarm`): the shared route
242
- * behind `AgentWorkspaceLayout`'s `prewarm`. The default lane answers on the
243
- * Router and starts the box only when a turn needs it, so with a Router key a
244
- * warm on open is declined and the speculator starts the box instead.
242
+ * behind `AgentWorkspaceLayout`'s `prewarm`. Every configured lane wakes its
243
+ * workspace lock. The Router lane leaves the box to its existing speculator;
244
+ * it warms only the lock on open/focus, with no paid provisioning.
245
245
  */
246
246
  export function createPrewarmRoute(env: AppEnv, requireUserId: (request: Request) => Promise<string | null>) {
247
247
  return createWorkspacePrewarmRoute<void>({
248
+ ...(env.TURN_STREAM && env.TURN_STREAM_AUTH_SECRET ? { turnStore: {
249
+ db: env.DB, region: env.D1_REGION,
250
+ lock: { namespace: env.TURN_STREAM, auth: { secret: env.TURN_STREAM_AUTH_SECRET } },
251
+ } } : {}),
248
252
  authorize: async ({ request }) => {
249
253
  const userId = await requireUserId(request)
250
254
  if (!userId) return { status: 'denied', response: Response.json({ error: 'Unauthorized' }, { status: 401 }) }
251
- if (env.TANGLE_API_KEY?.trim()) return { status: 'declined', reason: 'router_lane' }
252
- if (!env.SANDBOX_API_KEY?.trim() || !env.SANDBOX_GATEWAY_URL?.trim()) return { status: 'declined', reason: 'no_sandbox' }
255
+ if (!env.TURN_STREAM || !env.TURN_STREAM_AUTH_SECRET) return { status: 'declined', reason: 'lock_not_configured' }
256
+ if (env.TANGLE_API_KEY?.trim() || !env.SANDBOX_API_KEY?.trim() || !env.SANDBOX_GATEWAY_URL?.trim()) {
257
+ return { status: 'allowed', workspaceId: userId, steps: [] }
258
+ }
253
259
  const scope = { workspaceId: userId, userId }
254
260
  return {
255
261
  status: 'allowed',
262
+ workspaceId: scope.workspaceId,
256
263
  key: scope.workspaceId,
257
264
  warm: async () => {
258
265
  const prewarmer = createSandboxPrewarmer(createSandboxShell(env), {