@tangle-network/create-agent-app 0.60.214 → 0.60.216

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.60.214",
3
+ "version": "0.60.216",
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",
@@ -19,5 +19,8 @@ TANGLE_API_KEY=
19
19
  SANDBOX_API_KEY=
20
20
  SANDBOX_GATEWAY_URL=
21
21
 
22
+ # Optional ops webhook for platform-limit alarms (80% of a Worker, D1, box or key limit).
23
+ # SLACK_OPS_WEBHOOK_URL=
24
+
22
25
  # Model override without a redeploy (falls back to config.model.default).
23
26
  # MODEL_NAME=
@@ -37,6 +37,12 @@ Omit controls without real product data and callbacks.
37
37
  The upload adapter preserves inline/sandbox `parts`; it is not the store-backed attachment contract.
38
38
  Keep browser DOM types separate from Worker types and scan installed UI package classes in the CSS build.
39
39
 
40
+ ## Defaults
41
+
42
+ This app inherits agent-app's defaults: a trace per turn sent to Intelligence, limit alarms on D1, and the shared Worker settings.
43
+ `pnpm signoff` runs the checks in `signoff.config.mjs` and reports which defaults the app has (`agent-app-signoff defaults` prints the same report alone).
44
+ Turn a default off only with an exemption and its reason in `signoff.config.mjs`; the prewarm and placement exemptions there are temporary.
45
+
40
46
  ## Verification
41
47
 
42
48
  Run `pnpm build` and `pnpm test`.
@@ -11,7 +11,7 @@
11
11
  "dev": "wrangler dev",
12
12
  "build": "pnpm run typecheck && pnpm run build:web",
13
13
  "build:web": "vite build",
14
- "deploy": "pnpm run peer-check && wrangler deploy",
14
+ "deploy": "pnpm run peer-check && pnpm run signoff && wrangler deploy",
15
15
  "db:migrate": "wrangler d1 migrations apply __PACKAGE_NAME__ --remote",
16
16
  "db:migrate:local": "wrangler d1 migrations apply __PACKAGE_NAME__ --local",
17
17
  "peer-check": "agent-app-peer-check",
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This app's merge and deploy gate: `pnpm signoff` (and `pnpm deploy`, which runs it first).
3
+ * It verifies a clean checkout of the committed tree, then reports which agent-app defaults the app has.
4
+ * Commit `pnpm-lock.yaml` before the first run: the install is frozen.
5
+ */
6
+ export default {
7
+ install: { run: 'pnpm install --frozen-lockfile --ignore-scripts=false' },
8
+ steps: [
9
+ { name: 'typecheck', run: 'pnpm run typecheck' },
10
+ { name: 'unit tests', run: 'pnpm run test', shuffle: true },
11
+ { name: 'build', run: 'pnpm run build:web' },
12
+ ],
13
+ workerConfigs: ['wrangler.toml'],
14
+ agentApp: {
15
+ // An exemption is a default this app does not have yet, with the reason. Delete each line as it is fixed.
16
+ exemptions: {
17
+ prewarm: 'This scaffold has no workspace-open route yet; agent-app mounts the shared prewarm route by default in a later release.',
18
+ placement: 'The D1 region is unknown until `wrangler d1 create` runs; pin [placement] beside the D1 primary then, and delete this line.',
19
+ },
20
+ },
21
+ }
@@ -40,6 +40,7 @@ import {
40
40
  type ChatStore,
41
41
  } from '@tangle-network/agent-app/chat-store'
42
42
  import { guardResolution } from '@tangle-network/agent-app/platform'
43
+ import { createIntelligenceTurnTraceSink } from '@tangle-network/agent-app/turn-trace'
43
44
  import {
44
45
  createD1TurnEventStore,
45
46
  type TurnEventStore,
@@ -163,6 +164,9 @@ export function buildChatApp(env: AppEnv, overrides: ChatAppOverrides = {}): Cha
163
164
  },
164
165
  },
165
166
  projectId: appSlug,
167
+ // One trace per turn, sent to Tangle Intelligence with first_text_ms. The sink reads the Sandbox product key and
168
+ // warns in the Worker log when an export fails; pass `turnTrace: false` only with an exemption in signoff.config.mjs.
169
+ turnTrace: { sink: createIntelligenceTurnTraceSink({ project: appSlug }) },
166
170
  authorize,
167
171
  store,
168
172
  turnStore,
@@ -32,6 +32,9 @@ export interface AppEnv {
32
32
  /** Tangle Router base URL; omit for the platform default. */
33
33
  TANGLE_ROUTER_URL?: string
34
34
 
35
+ /** Ops webhook for platform-limit alarms; without it they go to the Worker log only. */
36
+ SLACK_OPS_WEBHOOK_URL?: string
37
+
35
38
  /** Sandbox gateway credentials. Without them every turn fails loud with a
36
39
  * clear error — there is no mock fallback. */
37
40
  SANDBOX_API_KEY?: string
@@ -0,0 +1,28 @@
1
+ /**
2
+ * src/limit-alarms.ts — platform-limit alarms on this Worker's D1 reads.
3
+ *
4
+ * Every resource starts from agent-app's defaults (128 MB Worker memory, 250,000 D1 rows per query, a 10 GB box
5
+ * disk, 25 snapshots, 60 key requests per minute) and alarms at 80% to the Worker log and, when
6
+ * `SLACK_OPS_WEBHOOK_URL` is set, the ops webhook. Pass `overrides` only for a limit this product measured
7
+ * differently. See docs/launch-invariants.md in @tangle-network/agent-app.
8
+ */
9
+
10
+ import { createProductLimitAlarms, withD1LimitAlarms } from '@tangle-network/agent-app/launch-invariants'
11
+ import type { AppEnv } from './env'
12
+ import { appSlug } from './sandbox'
13
+
14
+ const watched = new WeakMap<object, AppEnv>()
15
+
16
+ /**
17
+ * The Worker's env with its D1 binding observed: rows read and response size on every query. One wrapper per env,
18
+ * and every other binding is read live from the original.
19
+ */
20
+ export function withLimitAlarms(env: AppEnv): AppEnv {
21
+ if (!env.DB) return env
22
+ const existing = watched.get(env)
23
+ if (existing) return existing
24
+ const database = withD1LimitAlarms(env.DB, createProductLimitAlarms({ product: appSlug, webhookUrl: env.SLACK_OPS_WEBHOOK_URL }))
25
+ const next = new Proxy(env, { get: (target, key) => (key === 'DB' ? database : Reflect.get(target, key)) })
26
+ watched.set(env, next)
27
+ return next
28
+ }
@@ -33,6 +33,7 @@ import {
33
33
  streamSandboxPrompt,
34
34
  type SandboxRuntimeConfig,
35
35
  } from '@tangle-network/agent-app/sandbox'
36
+ import type { TurnTrace } from '@tangle-network/agent-app/turn-trace'
36
37
  import type { AppEnv } from './env'
37
38
 
38
39
  /** Lowercased, non-alphanumerics collapsed: box names + projectId. */
@@ -84,12 +85,13 @@ async function ensureForegroundWorkspaceSandbox(
84
85
  env: AppEnv,
85
86
  shell: SandboxRuntimeConfig,
86
87
  scope: { workspaceId: string; userId: string },
88
+ trace?: TurnTrace,
87
89
  ) {
88
90
  return runForegroundSandboxSingleFlight({
89
91
  claim: createD1PrewarmClaimStore(env.DB),
90
92
  workspaceId: scope.workspaceId,
91
93
  harness: config.harness,
92
- provision: () => ensureWorkspaceSandbox(shell, { ...scope, harness: config.harness }),
94
+ provision: () => ensureWorkspaceSandbox(shell, { ...scope, harness: config.harness, ...(trace ? { trace } : {}) }),
93
95
  peek: () => peekWorkspaceSandbox(shell, scope),
94
96
  adopt: ({ box }) => box,
95
97
  })
@@ -108,11 +110,12 @@ export function createSandboxProduce(env: AppEnv) {
108
110
  prompt,
109
111
  executionId,
110
112
  executionLimits,
113
+ trace,
111
114
  }: ChatTurnProduceArgs<void>): Promise<ChatTurnRouteProducer> => {
112
115
  const box = await ensureForegroundWorkspaceSandbox(env, shell, {
113
116
  workspaceId: identity.tenantId,
114
117
  userId: identity.userId,
115
- })
118
+ }, trace)
116
119
  const model = body.model ?? env.MODEL_NAME ?? config.model.default
117
120
  return createSandboxChatProducer({
118
121
  model,
@@ -127,6 +130,7 @@ export function createSandboxProduce(env: AppEnv) {
127
130
  turnId: executionId,
128
131
  model: attemptModel,
129
132
  signal,
133
+ ...(trace ? { trace } : {}),
130
134
  // A zero reasoning allowance maps to the profile's supported
131
135
  // no-reasoning control. Positive limits use token ceilings below.
132
136
  effort: executionLimits?.maxReasoningTokens === 0
@@ -27,6 +27,7 @@ import type { peekWorkspaceSandbox } from '@tangle-network/agent-app/sandbox'
27
27
  import { config } from '../agent.config'
28
28
  import { buildChatApp, type ChatApp } from './chat'
29
29
  import type { AppEnv } from './env'
30
+ import { withLimitAlarms } from './limit-alarms'
30
31
  import {
31
32
  buildGatewayApp,
32
33
  type GatewayAppOptions,
@@ -82,7 +83,8 @@ export function createWorker(assembly: WorkerAssembly = defaultAssembly): Export
82
83
  }
83
84
 
84
85
  return {
85
- async fetch(request: Request, env: AppEnv, ctx: ExecutionContext): Promise<Response> {
86
+ async fetch(request: Request, rawEnv: AppEnv, ctx: ExecutionContext): Promise<Response> {
87
+ const env = withLimitAlarms(rawEnv)
86
88
  const surfaces = agentSurfaces(new URL(env.BETTER_AUTH_URL).origin, env.OPERATOR_RUN_ENABLED === 'true')
87
89
  const surface = surfaces.handle(request)
88
90
  if (surface) return surface