@agent-native/dispatch 0.35.1-nightly-20260909002003 → 0.36.0-nightly-20260909010346

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.
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/db/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAsDzE,eAAO,MAAM,kBAAkB,EAAE,cAAc,EAqQ9C,CAAC"}
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/db/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAuDzE,eAAO,MAAM,kBAAkB,EAAE,cAAc,EAyT9C,CAAC"}
@@ -23,6 +23,7 @@ const dispatchTimestampColumns = {
23
23
  workspace_resources: ["created_at", "updated_at"],
24
24
  workspace_resource_grants: ["synced_at", "created_at", "updated_at"],
25
25
  identity_sso_authorization_code: ["created_at", "expires_at", "consumed_at"],
26
+ identity_sso_bootstrap: ["created_at", "expires_at", "consumed_at"],
26
27
  };
27
28
  async function widenLegacyDispatchTimestamps(exec) {
28
29
  const tables = Object.keys(dispatchTimestampColumns);
@@ -303,5 +304,57 @@ export const dispatchMigrations = [
303
304
  `,
304
305
  run: widenLegacyDispatchTimestamps,
305
306
  },
307
+ {
308
+ version: 7,
309
+ name: "identity-sso-bootstrap-handle-table",
310
+ sql: `
311
+ CREATE TABLE IF NOT EXISTS identity_sso_bootstrap (
312
+ handle_hash TEXT PRIMARY KEY,
313
+ state TEXT NOT NULL,
314
+ app_id TEXT NOT NULL,
315
+ client_id TEXT NOT NULL,
316
+ redirect_uri TEXT NOT NULL,
317
+ authority TEXT NOT NULL,
318
+ code_challenge TEXT NOT NULL,
319
+ email TEXT NOT NULL,
320
+ name TEXT,
321
+ created_at BIGINT NOT NULL,
322
+ expires_at BIGINT NOT NULL,
323
+ consumed_at BIGINT
324
+ );
325
+
326
+ CREATE INDEX IF NOT EXISTS identity_sso_bootstrap_expires_idx
327
+ ON identity_sso_bootstrap (expires_at);
328
+ `,
329
+ },
330
+ {
331
+ version: 8,
332
+ name: "identity-sso-pkce-bootstrap-activation",
333
+ sql: `
334
+ ALTER TABLE identity_sso_authorization_code
335
+ ADD COLUMN IF NOT EXISTS bootstrap_handle_hash TEXT;
336
+ ALTER TABLE identity_sso_bootstrap
337
+ ADD COLUMN IF NOT EXISTS activation_hash TEXT;
338
+ ALTER TABLE identity_sso_bootstrap
339
+ ADD COLUMN IF NOT EXISTS activation_expires_at BIGINT;
340
+ ALTER TABLE identity_sso_bootstrap
341
+ ADD COLUMN IF NOT EXISTS activated_at BIGINT;
342
+ `,
343
+ run: widenLegacyDispatchTimestamps,
344
+ },
345
+ {
346
+ version: 9,
347
+ name: "identity-sso-bootstrap-browser-binding-and-rollout-context",
348
+ sql: `
349
+ ALTER TABLE identity_sso_authorization_code
350
+ ADD COLUMN IF NOT EXISTS bootstrap_auth_provider TEXT;
351
+ ALTER TABLE identity_sso_bootstrap
352
+ ADD COLUMN IF NOT EXISTS org_id TEXT;
353
+ ALTER TABLE identity_sso_bootstrap
354
+ ADD COLUMN IF NOT EXISTS auth_provider TEXT;
355
+ ALTER TABLE identity_sso_bootstrap
356
+ ADD COLUMN IF NOT EXISTS browser_binding_hash TEXT;
357
+ `,
358
+ },
306
359
  ];
307
360
  //# sourceMappingURL=migrations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/db/migrations.ts"],"names":[],"mappings":"AAEA,MAAM,wBAAwB,GAA6B;IACzD,qBAAqB,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;IACnD,uBAAuB,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;IACrD,oBAAoB,EAAE;QACpB,YAAY;QACZ,YAAY;QACZ,YAAY;QACZ,YAAY;KACb;IACD,0BAA0B,EAAE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/core/db\";\n\nconst dispatchTimestampColumns: Record<string, string[]> = {\n dispatch_destinations: [\"created_at\", \"updated_at\"],\n dispatch_identity_links: [\"created_at\", \"updated_at\"],\n dispatch_link_tokens: [\n \"expires_at\",\n \"claimed_at\",\n \"created_at\",\n \"updated_at\",\n ],\n dispatch_approval_requests: [\"reviewed_at\", \"created_at\", \"updated_at\"],\n dispatch_audit_events: [\"created_at\"],\n dispatch_dreams: [\"started_at\", \"completed_at\", \"created_at\", \"updated_at\"],\n dispatch_dream_proposals: [\n \"applied_at\",\n \"rejected_at\",\n \"created_at\",\n \"updated_at\",\n ],\n vault_secrets: [\"created_at\", \"updated_at\"],\n vault_grants: [\"synced_at\", \"created_at\", \"updated_at\"],\n vault_requests: [\"reviewed_at\", \"created_at\", \"updated_at\"],\n vault_audit_log: [\"created_at\"],\n workspace_resources: [\"created_at\", \"updated_at\"],\n workspace_resource_grants: [\"synced_at\", \"created_at\", \"updated_at\"],\n identity_sso_authorization_code: [\"created_at\", \"expires_at\", \"consumed_at\"],\n};\n\nasync function widenLegacyDispatchTimestamps(exec: DbExec): Promise<void> {\n const tables = Object.keys(dispatchTimestampColumns);\n const { rows } = await exec.execute({\n sql: `SELECT table_name, column_name FROM information_schema.columns\n WHERE table_schema = 'public' AND data_type = 'integer'\n AND table_name IN (${tables.map(() => \"?\").join(\", \")})`,\n args: tables,\n });\n const int4Columns = new Set(\n rows.map((row) => `${String(row.table_name)}.${String(row.column_name)}`),\n );\n\n for (const [table, columns] of Object.entries(dispatchTimestampColumns)) {\n const legacyColumns = columns.filter((column) =>\n int4Columns.has(`${table}.${column}`),\n );\n if (legacyColumns.length === 0) continue;\n await exec.execute(\n `ALTER TABLE ${table} ${legacyColumns\n .map((column) => `ALTER COLUMN ${column} TYPE BIGINT`)\n .join(\", \")}`,\n );\n }\n}\n\nexport const dispatchMigrations: MigrationEntry[] = [\n {\n version: 1,\n sql: `\n CREATE TABLE IF NOT EXISTS dispatch_destinations (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n name TEXT NOT NULL,\n platform TEXT NOT NULL,\n destination TEXT NOT NULL,\n thread_ref TEXT,\n notes TEXT,\n created_by TEXT NOT NULL,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS dispatch_identity_links (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n platform TEXT NOT NULL,\n external_user_id TEXT NOT NULL,\n external_user_name TEXT,\n linked_by TEXT NOT NULL,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS dispatch_link_tokens (\n id TEXT PRIMARY KEY,\n token TEXT NOT NULL,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n platform TEXT NOT NULL,\n created_by TEXT NOT NULL,\n expires_at BIGINT NOT NULL,\n claimed_at BIGINT,\n claimed_by_external_user_id TEXT,\n claimed_by_external_user_name TEXT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS dispatch_approval_requests (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n change_type TEXT NOT NULL,\n target_type TEXT NOT NULL,\n target_id TEXT,\n status TEXT NOT NULL,\n summary TEXT NOT NULL,\n payload TEXT NOT NULL,\n before_value TEXT,\n after_value TEXT,\n requested_by TEXT NOT NULL,\n reviewed_by TEXT,\n reviewed_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS dispatch_audit_events (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n actor TEXT NOT NULL,\n action TEXT NOT NULL,\n target_type TEXT NOT NULL,\n target_id TEXT,\n summary TEXT NOT NULL,\n metadata TEXT,\n created_at BIGINT NOT NULL\n );\n `,\n },\n {\n version: 2,\n sql: `\n CREATE TABLE IF NOT EXISTS vault_secrets (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n name TEXT NOT NULL,\n credential_key TEXT NOT NULL,\n value TEXT NOT NULL,\n provider TEXT,\n description TEXT,\n created_by TEXT NOT NULL,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS vault_grants (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n secret_id TEXT NOT NULL,\n app_id TEXT NOT NULL,\n granted_by TEXT NOT NULL,\n status TEXT NOT NULL,\n synced_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS vault_requests (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n credential_key TEXT NOT NULL,\n app_id TEXT NOT NULL,\n reason TEXT,\n requested_by TEXT NOT NULL,\n status TEXT NOT NULL,\n reviewed_by TEXT,\n reviewed_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS vault_audit_log (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n secret_id TEXT,\n app_id TEXT,\n action TEXT NOT NULL,\n actor TEXT NOT NULL,\n summary TEXT NOT NULL,\n metadata TEXT,\n created_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS workspace_resources (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n kind TEXT NOT NULL,\n name TEXT NOT NULL,\n description TEXT,\n path TEXT NOT NULL,\n content TEXT NOT NULL,\n scope TEXT NOT NULL,\n created_by TEXT NOT NULL,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS workspace_resource_grants (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n resource_id TEXT NOT NULL,\n app_id TEXT NOT NULL,\n status TEXT NOT NULL,\n synced_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n `,\n },\n {\n version: 3,\n sql: `\n CREATE TABLE IF NOT EXISTS dispatch_dreams (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n source_id TEXT NOT NULL,\n title TEXT NOT NULL,\n status TEXT NOT NULL,\n query TEXT,\n report TEXT,\n summary TEXT,\n candidate_count INTEGER NOT NULL,\n inspected_thread_count INTEGER NOT NULL,\n created_by TEXT NOT NULL,\n error TEXT,\n started_at BIGINT NOT NULL,\n completed_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS dispatch_dream_proposals (\n id TEXT PRIMARY KEY,\n dream_id TEXT NOT NULL,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n target_type TEXT NOT NULL,\n target_path TEXT NOT NULL,\n title TEXT NOT NULL,\n summary TEXT NOT NULL,\n rationale TEXT NOT NULL,\n content TEXT NOT NULL,\n evidence TEXT NOT NULL,\n confidence INTEGER NOT NULL,\n risk TEXT NOT NULL,\n status TEXT NOT NULL,\n applied_by TEXT,\n applied_at BIGINT,\n rejected_by TEXT,\n rejected_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE INDEX IF NOT EXISTS dispatch_dreams_owner_updated_idx\n ON dispatch_dreams (owner_email, org_id, updated_at);\n\n CREATE INDEX IF NOT EXISTS dispatch_dream_proposals_dream_status_idx\n ON dispatch_dream_proposals (dream_id, status);\n `,\n },\n {\n version: 4,\n sql: `\n ALTER TABLE dispatch_dreams ADD COLUMN IF NOT EXISTS source_health TEXT;\n `,\n },\n {\n version: 5,\n name: \"identity-sso-authorization-code-table\",\n sql: `\n CREATE TABLE IF NOT EXISTS identity_sso_authorization_code (\n code_hash TEXT PRIMARY KEY,\n state TEXT NOT NULL,\n app_id TEXT NOT NULL,\n client_id TEXT NOT NULL,\n redirect_uri TEXT NOT NULL,\n authority TEXT NOT NULL,\n code_challenge TEXT NOT NULL,\n email TEXT NOT NULL,\n name TEXT,\n org_domain TEXT,\n jti TEXT NOT NULL,\n created_at BIGINT NOT NULL,\n expires_at BIGINT NOT NULL,\n consumed_at BIGINT,\n org_id TEXT,\n org_name TEXT,\n org_role TEXT\n );\n\n CREATE INDEX IF NOT EXISTS identity_sso_authorization_code_expires_idx\n ON identity_sso_authorization_code (expires_at);\n `,\n },\n {\n version: 6,\n name: \"dispatch-millisecond-timestamps-bigint-and-identity-sso-organization-claims\",\n sql: `\n ALTER TABLE identity_sso_authorization_code ADD COLUMN IF NOT EXISTS org_id TEXT;\n ALTER TABLE identity_sso_authorization_code ADD COLUMN IF NOT EXISTS org_name TEXT;\n ALTER TABLE identity_sso_authorization_code ADD COLUMN IF NOT EXISTS org_role TEXT;\n `,\n run: widenLegacyDispatchTimestamps,\n },\n];\n"]}
1
+ {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/db/migrations.ts"],"names":[],"mappings":"AAEA,MAAM,wBAAwB,GAA6B;IACzD,qBAAqB,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;IACnD,uBAAuB,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;IACrD,oBAAoB,EAAE;QACpB,YAAY;QACZ,YAAY;QACZ,YAAY;QACZ,YAAY;KACb;IACD,0BAA0B,EAAE,CAAC,aAAa,EAAE,YAAY,EAAE,YAAY,CAAC;IACvE,qBAAqB,EAAE,CAAC,YAAY,CAAC;IACrC,eAAe,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,CAAC;IAC3E,wBAAwB,EAAE;QACxB,YAAY;QACZ,aAAa;QACb,YAAY;QACZ,YAAY;KACb;IACD,aAAa,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;IAC3C,YAAY,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,YAA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;CACF,CAAC","sourcesContent":["import { type DbExec, type MigrationEntry } from \"@agent-native/core/db\";\n\nconst dispatchTimestampColumns: Record<string, string[]> = {\n dispatch_destinations: [\"created_at\", \"updated_at\"],\n dispatch_identity_links: [\"created_at\", \"updated_at\"],\n dispatch_link_tokens: [\n \"expires_at\",\n \"claimed_at\",\n \"created_at\",\n \"updated_at\",\n ],\n dispatch_approval_requests: [\"reviewed_at\", \"created_at\", \"updated_at\"],\n dispatch_audit_events: [\"created_at\"],\n dispatch_dreams: [\"started_at\", \"completed_at\", \"created_at\", \"updated_at\"],\n dispatch_dream_proposals: [\n \"applied_at\",\n \"rejected_at\",\n \"created_at\",\n \"updated_at\",\n ],\n vault_secrets: [\"created_at\", \"updated_at\"],\n vault_grants: [\"synced_at\", \"created_at\", \"updated_at\"],\n vault_requests: [\"reviewed_at\", \"created_at\", \"updated_at\"],\n vault_audit_log: [\"created_at\"],\n workspace_resources: [\"created_at\", \"updated_at\"],\n workspace_resource_grants: [\"synced_at\", \"created_at\", \"updated_at\"],\n identity_sso_authorization_code: [\"created_at\", \"expires_at\", \"consumed_at\"],\n identity_sso_bootstrap: [\"created_at\", \"expires_at\", \"consumed_at\"],\n};\n\nasync function widenLegacyDispatchTimestamps(exec: DbExec): Promise<void> {\n const tables = Object.keys(dispatchTimestampColumns);\n const { rows } = await exec.execute({\n sql: `SELECT table_name, column_name FROM information_schema.columns\n WHERE table_schema = 'public' AND data_type = 'integer'\n AND table_name IN (${tables.map(() => \"?\").join(\", \")})`,\n args: tables,\n });\n const int4Columns = new Set(\n rows.map((row) => `${String(row.table_name)}.${String(row.column_name)}`),\n );\n\n for (const [table, columns] of Object.entries(dispatchTimestampColumns)) {\n const legacyColumns = columns.filter((column) =>\n int4Columns.has(`${table}.${column}`),\n );\n if (legacyColumns.length === 0) continue;\n await exec.execute(\n `ALTER TABLE ${table} ${legacyColumns\n .map((column) => `ALTER COLUMN ${column} TYPE BIGINT`)\n .join(\", \")}`,\n );\n }\n}\n\nexport const dispatchMigrations: MigrationEntry[] = [\n {\n version: 1,\n sql: `\n CREATE TABLE IF NOT EXISTS dispatch_destinations (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n name TEXT NOT NULL,\n platform TEXT NOT NULL,\n destination TEXT NOT NULL,\n thread_ref TEXT,\n notes TEXT,\n created_by TEXT NOT NULL,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS dispatch_identity_links (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n platform TEXT NOT NULL,\n external_user_id TEXT NOT NULL,\n external_user_name TEXT,\n linked_by TEXT NOT NULL,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS dispatch_link_tokens (\n id TEXT PRIMARY KEY,\n token TEXT NOT NULL,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n platform TEXT NOT NULL,\n created_by TEXT NOT NULL,\n expires_at BIGINT NOT NULL,\n claimed_at BIGINT,\n claimed_by_external_user_id TEXT,\n claimed_by_external_user_name TEXT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS dispatch_approval_requests (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n change_type TEXT NOT NULL,\n target_type TEXT NOT NULL,\n target_id TEXT,\n status TEXT NOT NULL,\n summary TEXT NOT NULL,\n payload TEXT NOT NULL,\n before_value TEXT,\n after_value TEXT,\n requested_by TEXT NOT NULL,\n reviewed_by TEXT,\n reviewed_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS dispatch_audit_events (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n actor TEXT NOT NULL,\n action TEXT NOT NULL,\n target_type TEXT NOT NULL,\n target_id TEXT,\n summary TEXT NOT NULL,\n metadata TEXT,\n created_at BIGINT NOT NULL\n );\n `,\n },\n {\n version: 2,\n sql: `\n CREATE TABLE IF NOT EXISTS vault_secrets (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n name TEXT NOT NULL,\n credential_key TEXT NOT NULL,\n value TEXT NOT NULL,\n provider TEXT,\n description TEXT,\n created_by TEXT NOT NULL,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS vault_grants (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n secret_id TEXT NOT NULL,\n app_id TEXT NOT NULL,\n granted_by TEXT NOT NULL,\n status TEXT NOT NULL,\n synced_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS vault_requests (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n credential_key TEXT NOT NULL,\n app_id TEXT NOT NULL,\n reason TEXT,\n requested_by TEXT NOT NULL,\n status TEXT NOT NULL,\n reviewed_by TEXT,\n reviewed_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS vault_audit_log (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n secret_id TEXT,\n app_id TEXT,\n action TEXT NOT NULL,\n actor TEXT NOT NULL,\n summary TEXT NOT NULL,\n metadata TEXT,\n created_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS workspace_resources (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n kind TEXT NOT NULL,\n name TEXT NOT NULL,\n description TEXT,\n path TEXT NOT NULL,\n content TEXT NOT NULL,\n scope TEXT NOT NULL,\n created_by TEXT NOT NULL,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS workspace_resource_grants (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n resource_id TEXT NOT NULL,\n app_id TEXT NOT NULL,\n status TEXT NOT NULL,\n synced_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n `,\n },\n {\n version: 3,\n sql: `\n CREATE TABLE IF NOT EXISTS dispatch_dreams (\n id TEXT PRIMARY KEY,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n source_id TEXT NOT NULL,\n title TEXT NOT NULL,\n status TEXT NOT NULL,\n query TEXT,\n report TEXT,\n summary TEXT,\n candidate_count INTEGER NOT NULL,\n inspected_thread_count INTEGER NOT NULL,\n created_by TEXT NOT NULL,\n error TEXT,\n started_at BIGINT NOT NULL,\n completed_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS dispatch_dream_proposals (\n id TEXT PRIMARY KEY,\n dream_id TEXT NOT NULL,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n target_type TEXT NOT NULL,\n target_path TEXT NOT NULL,\n title TEXT NOT NULL,\n summary TEXT NOT NULL,\n rationale TEXT NOT NULL,\n content TEXT NOT NULL,\n evidence TEXT NOT NULL,\n confidence INTEGER NOT NULL,\n risk TEXT NOT NULL,\n status TEXT NOT NULL,\n applied_by TEXT,\n applied_at BIGINT,\n rejected_by TEXT,\n rejected_at BIGINT,\n created_at BIGINT NOT NULL,\n updated_at BIGINT NOT NULL\n );\n\n CREATE INDEX IF NOT EXISTS dispatch_dreams_owner_updated_idx\n ON dispatch_dreams (owner_email, org_id, updated_at);\n\n CREATE INDEX IF NOT EXISTS dispatch_dream_proposals_dream_status_idx\n ON dispatch_dream_proposals (dream_id, status);\n `,\n },\n {\n version: 4,\n sql: `\n ALTER TABLE dispatch_dreams ADD COLUMN IF NOT EXISTS source_health TEXT;\n `,\n },\n {\n version: 5,\n name: \"identity-sso-authorization-code-table\",\n sql: `\n CREATE TABLE IF NOT EXISTS identity_sso_authorization_code (\n code_hash TEXT PRIMARY KEY,\n state TEXT NOT NULL,\n app_id TEXT NOT NULL,\n client_id TEXT NOT NULL,\n redirect_uri TEXT NOT NULL,\n authority TEXT NOT NULL,\n code_challenge TEXT NOT NULL,\n email TEXT NOT NULL,\n name TEXT,\n org_domain TEXT,\n jti TEXT NOT NULL,\n created_at BIGINT NOT NULL,\n expires_at BIGINT NOT NULL,\n consumed_at BIGINT,\n org_id TEXT,\n org_name TEXT,\n org_role TEXT\n );\n\n CREATE INDEX IF NOT EXISTS identity_sso_authorization_code_expires_idx\n ON identity_sso_authorization_code (expires_at);\n `,\n },\n {\n version: 6,\n name: \"dispatch-millisecond-timestamps-bigint-and-identity-sso-organization-claims\",\n sql: `\n ALTER TABLE identity_sso_authorization_code ADD COLUMN IF NOT EXISTS org_id TEXT;\n ALTER TABLE identity_sso_authorization_code ADD COLUMN IF NOT EXISTS org_name TEXT;\n ALTER TABLE identity_sso_authorization_code ADD COLUMN IF NOT EXISTS org_role TEXT;\n `,\n run: widenLegacyDispatchTimestamps,\n },\n {\n version: 7,\n name: \"identity-sso-bootstrap-handle-table\",\n sql: `\n CREATE TABLE IF NOT EXISTS identity_sso_bootstrap (\n handle_hash TEXT PRIMARY KEY,\n state TEXT NOT NULL,\n app_id TEXT NOT NULL,\n client_id TEXT NOT NULL,\n redirect_uri TEXT NOT NULL,\n authority TEXT NOT NULL,\n code_challenge TEXT NOT NULL,\n email TEXT NOT NULL,\n name TEXT,\n created_at BIGINT NOT NULL,\n expires_at BIGINT NOT NULL,\n consumed_at BIGINT\n );\n\n CREATE INDEX IF NOT EXISTS identity_sso_bootstrap_expires_idx\n ON identity_sso_bootstrap (expires_at);\n `,\n },\n {\n version: 8,\n name: \"identity-sso-pkce-bootstrap-activation\",\n sql: `\n ALTER TABLE identity_sso_authorization_code\n ADD COLUMN IF NOT EXISTS bootstrap_handle_hash TEXT;\n ALTER TABLE identity_sso_bootstrap\n ADD COLUMN IF NOT EXISTS activation_hash TEXT;\n ALTER TABLE identity_sso_bootstrap\n ADD COLUMN IF NOT EXISTS activation_expires_at BIGINT;\n ALTER TABLE identity_sso_bootstrap\n ADD COLUMN IF NOT EXISTS activated_at BIGINT;\n `,\n run: widenLegacyDispatchTimestamps,\n },\n {\n version: 9,\n name: \"identity-sso-bootstrap-browser-binding-and-rollout-context\",\n sql: `\n ALTER TABLE identity_sso_authorization_code\n ADD COLUMN IF NOT EXISTS bootstrap_auth_provider TEXT;\n ALTER TABLE identity_sso_bootstrap\n ADD COLUMN IF NOT EXISTS org_id TEXT;\n ALTER TABLE identity_sso_bootstrap\n ADD COLUMN IF NOT EXISTS auth_provider TEXT;\n ALTER TABLE identity_sso_bootstrap\n ADD COLUMN IF NOT EXISTS browser_binding_hash TEXT;\n `,\n },\n];\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/metrics.tsx"],"names":[],"mappings":"AAsCA,wBAAgB,IAAI;;IAEnB;AAyiCD,MAAM,CAAC,OAAO,UAAU,YAAY,oDAuOnC"}
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/metrics.tsx"],"names":[],"mappings":"AAoDA,wBAAgB,IAAI;;IAEnB;AAiqCD,MAAM,CAAC,OAAO,UAAU,YAAY,oDA+RnC"}
@@ -5,7 +5,7 @@ import { useT } from "@agent-native/core/client/i18n";
5
5
  import { IconActivity, IconAlertTriangle, IconArrowUpRight, IconApps, IconChartBar, IconCoin, IconMessages, IconUsersGroup, } from "@tabler/icons-react";
6
6
  import { useMemo, useState } from "react";
7
7
  import { Link, useSearchParams } from "react-router";
8
- import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts";
8
+ import { Area, AreaChart, CartesianGrid, Line, LineChart, XAxis, YAxis, } from "recharts";
9
9
  import { DispatchShell } from "../../components/dispatch-shell.js";
10
10
  import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert.js";
11
11
  import { Badge } from "../../components/ui/badge.js";
@@ -13,12 +13,18 @@ import { Button } from "../../components/ui/button.js";
13
13
  import { ChartContainer, ChartTooltip, ChartTooltipContent, } from "../../components/ui/chart.js";
14
14
  import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, } from "../../components/ui/select.js";
15
15
  import { Skeleton } from "../../components/ui/skeleton.js";
16
+ import { Tabs, TabsContent, TabsList, TabsTrigger, } from "../../components/ui/tabs.js";
16
17
  import { UsageAlertsPanel } from "../../components/usage-alerts-panel.js";
17
18
  import { cn } from "../../lib/utils.js";
18
19
  export function meta() {
19
20
  return [{ title: "Metrics — Dispatch" }];
20
21
  }
21
22
  const RANGES = [7, 30, 90];
23
+ function selectedMetricsView(value) {
24
+ if (value === "adoption" || value === "details")
25
+ return value;
26
+ return "overview";
27
+ }
22
28
  const USD_BILLING = {
23
29
  unit: "usd",
24
30
  label: "Estimated spend",
@@ -91,7 +97,7 @@ function formatTrendDate(value) {
91
97
  day: "numeric",
92
98
  });
93
99
  }
94
- function completeTrendRows(rows) {
100
+ function completeUsageTrendRows(rows) {
95
101
  if (rows.length < 2)
96
102
  return rows;
97
103
  const byDate = new Map(rows.map((row) => [row.date, row]));
@@ -106,10 +112,32 @@ function completeTrendRows(rows) {
106
112
  calls: 0,
107
113
  chatCalls: 0,
108
114
  activeUsers: 0,
115
+ dailyActiveUsers: 0,
116
+ weeklyActiveUsers: 0,
109
117
  });
110
118
  }
111
119
  return completed;
112
120
  }
121
+ function UserActivityTrend({ rows }) {
122
+ const chartData = rows.map((row) => ({
123
+ ...row,
124
+ dau: row.dailyActiveUsers,
125
+ wau: row.weeklyActiveUsers,
126
+ }));
127
+ return (_jsx(Panel, { title: "Active users trend", icon: _jsx(IconUsersGroup, { size: 16 }), action: _jsxs("div", { className: "hidden items-center gap-3 text-[11px] text-muted-foreground sm:flex", children: [_jsxs("span", { className: "flex items-center gap-1.5", children: [_jsx("span", { className: "size-2 rounded-full bg-primary" }), "DAU"] }), _jsxs("span", { className: "flex items-center gap-1.5", children: [_jsx("span", { className: "size-2 rounded-full bg-muted-foreground" }), "WAU"] })] }), children: chartData.length === 0 ? (_jsx("div", { className: "flex min-h-56 items-center justify-center rounded-md border border-dashed px-4 text-sm text-muted-foreground", children: "No active users in this window yet." })) : (_jsx(ChartContainer, { config: {
128
+ dau: {
129
+ label: "DAU",
130
+ color: "hsl(var(--dispatch-brand-blue))",
131
+ },
132
+ wau: {
133
+ label: "WAU",
134
+ color: "hsl(var(--muted-foreground))",
135
+ },
136
+ }, className: "h-[240px] w-full aspect-auto", children: _jsxs(LineChart, { data: chartData, margin: { top: 8, right: 8, left: 12, bottom: 0 }, children: [_jsx(CartesianGrid, { vertical: false, stroke: "hsl(var(--border))", strokeDasharray: "3 3" }), _jsx(XAxis, { dataKey: "date", stroke: "hsl(var(--muted-foreground))", fontSize: 11, axisLine: false, tickLine: false, tickMargin: 8, minTickGap: 28, tickFormatter: formatTrendDate }), _jsx(YAxis, { allowDecimals: false, stroke: "hsl(var(--muted-foreground))", fontSize: 11, axisLine: false, tickLine: false, tickMargin: 8, width: 34, tickFormatter: (value) => formatNumber(Number(value)) }), _jsx(ChartTooltip, { cursor: false, content: _jsx(ChartTooltipContent, { labelFormatter: (value) => formatTrendDate(String(value)), formatter: (value, name) => [
137
+ `${formatNumber(Number(value))} users`,
138
+ name === "dau" ? "DAU" : "WAU",
139
+ ] }) }), _jsx(Line, { dataKey: "dau", type: "monotone", stroke: "var(--color-dau)", strokeWidth: 2, dot: false, activeDot: { r: 4, strokeWidth: 2 }, isAnimationActive: false }), _jsx(Line, { dataKey: "wau", type: "monotone", stroke: "var(--color-wau)", strokeWidth: 1.5, dot: false, activeDot: { r: 3, strokeWidth: 2 }, isAnimationActive: false })] }) })) }));
140
+ }
113
141
  function displayApp(value) {
114
142
  const trimmed = value?.trim();
115
143
  if (!trimmed || trimmed === "unattributed")
@@ -146,7 +174,7 @@ function UserSelector({ value, users, onChange, }) {
146
174
  return (_jsxs(Select, { value: value ?? "all", onValueChange: (nextValue) => onChange(nextValue === "all" ? null : nextValue), children: [_jsx(SelectTrigger, { className: "h-8 w-[210px] text-xs", "aria-label": "Filter usage by user", children: _jsx(SelectValue, { placeholder: "All users" }) }), _jsx(SelectContent, { children: _jsxs(SelectGroup, { children: [_jsx(SelectItem, { value: "all", children: "All users" }), users.map((user) => (_jsx(SelectItem, { value: user.email, children: user.email }, user.email)))] }) })] }));
147
175
  }
148
176
  function UsageTrend({ rows, billing, }) {
149
- const chartData = completeTrendRows(rows).map((row) => ({
177
+ const chartData = completeUsageTrendRows(rows).map((row) => ({
150
178
  ...row,
151
179
  spend: displayAmountFromCostCents(row.costCents, billing),
152
180
  }));
@@ -243,8 +271,8 @@ function AppAdoptionPanel({ rows, selectedAppId, scope, backScope, }) {
243
271
  ? t("dispatch.pages.appAdoption")
244
272
  : t("dispatch.pages.yourAppActivity");
245
273
  const backHref = backScope === "workspace"
246
- ? "/admin/metrics?scope=workspace"
247
- : "/admin/metrics";
274
+ ? "/admin/metrics?scope=workspace&view=adoption"
275
+ : "/admin/metrics?view=adoption";
248
276
  if (visibleRows.length === 0) {
249
277
  return (_jsx(Panel, { title: title, icon: _jsx(IconApps, { size: 16 }), children: _jsx("div", { className: "rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground", children: t("dispatch.pages.noWorkspaceApps") }) }));
250
278
  }
@@ -252,7 +280,7 @@ function AppAdoptionPanel({ rows, selectedAppId, scope, backScope, }) {
252
280
  ? selectedRow.isOwnedByViewer
253
281
  ? t("dispatch.pages.appMetadataOwner")
254
282
  : selectedRow.ownerEmail
255
- : t("dispatch.pages.ownerUnavailable") })] }), _jsx("div", { className: "grid gap-3 sm:grid-cols-3", children: detailStats.map(([label, value]) => (_jsxs("div", { className: "rounded-md border bg-background p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: label }), _jsx("div", { className: "mt-1 text-2xl font-semibold tabular-nums text-foreground", children: formatNumber(value) })] }, String(label)))) }), _jsxs("div", { className: "border-t pt-4", children: [_jsx("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: t("dispatch.pages.trackedActionBreakdown") }), actionMetrics.length === 0 ? (_jsx("div", { className: "text-sm text-muted-foreground", children: t("dispatch.pages.noTrackedActions") })) : (_jsx("div", { className: "divide-y rounded-md border", children: actionMetrics.slice(0, 10).map((action) => (_jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2.5 text-xs", children: [_jsx("span", { className: "min-w-0 truncate font-medium text-foreground", children: action.label }), _jsxs("span", { className: "shrink-0 tabular-nums text-muted-foreground", children: [formatNumber(action.calls), " ", t("dispatch.pages.trackedActions"), " \u00B7", " ", formatNumber(action.activeUsers), " ", t("dispatch.pages.activeUsers")] })] }, action.key))) }))] })] })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "grid gap-3 md:grid-cols-2 xl:grid-cols-3", children: rowsToRender.map((row) => (_jsxs("div", { className: "rounded-md border bg-background p-3", children: [_jsxs("div", { className: "flex items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("div", { className: "truncate text-sm font-medium text-foreground", children: row.name }), _jsx("div", { className: "font-mono text-[11px] text-muted-foreground", children: row.path })] }), row.isOwnedByViewer ? (_jsx(Badge, { variant: "secondary", children: t("dispatch.pages.appMetadataOwner") })) : null] }), _jsxs("div", { className: "mt-4 grid grid-cols-2 gap-3", children: [_jsxs("div", { children: [_jsx("div", { className: "text-xs text-muted-foreground", children: t("dispatch.pages.dailyActiveUsers") }), _jsx("div", { className: "mt-1 text-lg font-semibold tabular-nums text-foreground", children: formatNumber(row.dailyActiveUsers) })] }), _jsxs("div", { children: [_jsx("div", { className: "text-xs text-muted-foreground", children: t("dispatch.pages.weeklyActiveUsers") }), _jsx("div", { className: "mt-1 text-lg font-semibold tabular-nums text-foreground", children: formatNumber(row.weeklyActiveUsers) })] })] }), _jsxs("div", { className: "mt-3 text-xs text-muted-foreground", children: [formatNumber(row.usageCalls), " ", t("dispatch.pages.trackedActions")] }), row.canViewUsage ? (_jsxs(Link, { to: `/admin/metrics?app=${encodeURIComponent(row.id)}${scope === "workspace" ? "&scope=workspace" : ""}`, className: "mt-3 inline-flex items-center gap-1 text-xs font-medium text-foreground hover:underline", children: [t("dispatch.pages.viewAppMetrics"), _jsx(IconArrowUpRight, { size: 13 })] })) : null] }, row.id))) }), visibleRows.length > 9 ? (_jsx("div", { className: "mt-4 flex justify-center", children: _jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: () => setShowAll((current) => !current), children: showAll
283
+ : t("dispatch.pages.ownerUnavailable") })] }), _jsx("div", { className: "grid gap-3 sm:grid-cols-3", children: detailStats.map(([label, value]) => (_jsxs("div", { className: "rounded-md border bg-background p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: label }), _jsx("div", { className: "mt-1 text-2xl font-semibold tabular-nums text-foreground", children: formatNumber(value) })] }, String(label)))) }), _jsxs("div", { className: "border-t pt-4", children: [_jsx("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: t("dispatch.pages.trackedActionBreakdown") }), actionMetrics.length === 0 ? (_jsx("div", { className: "text-sm text-muted-foreground", children: t("dispatch.pages.noTrackedActions") })) : (_jsx("div", { className: "divide-y rounded-md border", children: actionMetrics.slice(0, 10).map((action) => (_jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2.5 text-xs", children: [_jsx("span", { className: "min-w-0 truncate font-medium text-foreground", children: action.label }), _jsxs("span", { className: "shrink-0 tabular-nums text-muted-foreground", children: [formatNumber(action.calls), " ", t("dispatch.pages.trackedActions"), " \u00B7", " ", formatNumber(action.activeUsers), " ", t("dispatch.pages.activeUsers")] })] }, action.key))) }))] })] })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "grid gap-3 md:grid-cols-2 xl:grid-cols-3", children: rowsToRender.map((row) => (_jsxs("div", { className: "rounded-md border bg-background p-3", children: [_jsxs("div", { className: "flex items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("div", { className: "truncate text-sm font-medium text-foreground", children: row.name }), _jsx("div", { className: "font-mono text-[11px] text-muted-foreground", children: row.path })] }), row.isOwnedByViewer ? (_jsx(Badge, { variant: "secondary", children: t("dispatch.pages.appMetadataOwner") })) : null] }), _jsxs("div", { className: "mt-4 grid grid-cols-2 gap-3", children: [_jsxs("div", { children: [_jsx("div", { className: "text-xs text-muted-foreground", children: t("dispatch.pages.dailyActiveUsers") }), _jsx("div", { className: "mt-1 text-lg font-semibold tabular-nums text-foreground", children: formatNumber(row.dailyActiveUsers) })] }), _jsxs("div", { children: [_jsx("div", { className: "text-xs text-muted-foreground", children: t("dispatch.pages.weeklyActiveUsers") }), _jsx("div", { className: "mt-1 text-lg font-semibold tabular-nums text-foreground", children: formatNumber(row.weeklyActiveUsers) })] })] }), _jsxs("div", { className: "mt-3 text-xs text-muted-foreground", children: [formatNumber(row.usageCalls), " ", t("dispatch.pages.trackedActions")] }), row.canViewUsage ? (_jsxs(Link, { to: `/admin/metrics?app=${encodeURIComponent(row.id)}${scope === "workspace" ? "&scope=workspace" : ""}&view=adoption`, className: "mt-3 inline-flex items-center gap-1 text-xs font-medium text-foreground hover:underline", children: [t("dispatch.pages.viewAppMetrics"), _jsx(IconArrowUpRight, { size: 13 })] })) : null] }, row.id))) }), visibleRows.length > 9 ? (_jsx("div", { className: "mt-4 flex justify-center", children: _jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: () => setShowAll((current) => !current), children: showAll
256
284
  ? t("jobs.scheduleUnavailableFixLabelOpen")
257
285
  : t("jobs.scheduleUnavailableFixLabel") }) })) : null] })) }));
258
286
  }
@@ -285,6 +313,7 @@ export default function MetricsRoute() {
285
313
  const t = useT();
286
314
  const [sinceDays, setSinceDays] = useState(30);
287
315
  const [searchParams, setSearchParams] = useSearchParams();
316
+ const view = selectedMetricsView(searchParams.get("view"));
288
317
  const appId = searchParams.get("app") || null;
289
318
  const backScope = searchParams.get("scope") === "workspace" ? "workspace" : "me";
290
319
  const scope = appId
@@ -312,6 +341,14 @@ export default function MetricsRoute() {
312
341
  next.delete("user");
313
342
  setSearchParams(next, { replace: true });
314
343
  }
344
+ function setView(nextView) {
345
+ const next = new URLSearchParams(searchParams);
346
+ if (nextView === "overview")
347
+ next.delete("view");
348
+ else
349
+ next.set("view", nextView);
350
+ setSearchParams(next, { replace: true });
351
+ }
315
352
  const { data, isLoading, error } = useActionQuery("list-dispatch-usage-metrics", {
316
353
  sinceDays,
317
354
  scope,
@@ -346,13 +383,22 @@ export default function MetricsRoute() {
346
383
  : scope === "workspace"
347
384
  ? `${metrics?.access.totalUsers ?? 0} users with access`
348
385
  : metrics?.access.viewerEmail || "Signed-in account" })] }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [appId ? (_jsx(Link, { to: backScope === "workspace"
349
- ? "/admin/metrics?scope=workspace"
350
- : "/admin/metrics", className: "inline-flex h-7 items-center rounded-md border px-3 text-xs font-medium text-foreground hover:bg-muted", children: t("allApps") })) : (_jsx(ScopeSelector, { value: scope === "workspace" ? "workspace" : "me", onChange: setScope })), scope === "workspace" && metrics ? (_jsx(UserSelector, { value: metrics.selectedUserEmail ?? userEmail, users: metrics.availableUsers ?? [], onChange: setUserEmail })) : null, _jsx(RangeSelector, { value: sinceDays, onChange: setSinceDays })] })] }), error ? (_jsxs(Alert, { variant: "destructive", children: [_jsx(IconAlertTriangle, { className: "h-4 w-4" }), _jsx(AlertTitle, { children: t("dispatch.pages.metricsUnavailable") }), _jsx(AlertDescription, { children: error instanceof Error
386
+ ? "/admin/metrics?scope=workspace&view=adoption"
387
+ : "/admin/metrics?view=adoption", className: "inline-flex h-7 items-center rounded-md border px-3 text-xs font-medium text-foreground hover:bg-muted", children: t("allApps") })) : (_jsx(ScopeSelector, { value: scope === "workspace" ? "workspace" : "me", onChange: setScope })), scope === "workspace" && metrics ? (_jsx(UserSelector, { value: metrics.selectedUserEmail ?? userEmail, users: metrics.availableUsers ?? [], onChange: setUserEmail })) : null, _jsx(RangeSelector, { value: sinceDays, onChange: setSinceDays })] })] }), error ? (_jsxs(Alert, { variant: "destructive", children: [_jsx(IconAlertTriangle, { className: "h-4 w-4" }), _jsx(AlertTitle, { children: t("dispatch.pages.metricsUnavailable") }), _jsx(AlertDescription, { children: error instanceof Error
351
388
  ? error.message
352
- : t("dispatch.pages.unableToLoadUsage") })] })) : null, isLoading && !metrics ? _jsx(LoadingMetrics, {}) : null, metrics ? (_jsxs(_Fragment, { children: [_jsx(UsageTrend, { rows: metrics.daily, billing: billing }), _jsxs("div", { className: "flex items-center justify-between gap-3 border-y py-3", children: [_jsx("span", { className: "text-sm text-muted-foreground", children: "Review this usage with the agent" }), _jsx(ReviewUsageButton, { metrics: metrics, billing: billing })] }), scope !== "app" ? (_jsx(UsageAlertsPanel, { scope: scope === "workspace" ? "workspace" : "user", appOptions: metrics.byApp
353
- .filter((row) => row.key && row.key !== "unattributed")
354
- .map((row) => ({ id: row.key, label: displayApp(row.key) })) })) : null, _jsxs("div", { className: "grid gap-3 md:grid-cols-2 xl:grid-cols-5", children: [_jsx(MetricCard, { label: billing.label, value: formatSpend(metrics.totals.costCents, billing), detail: `${formatTokens(totalTokens)} total tokens`, icon: _jsx(IconCoin, { size: 17 }) }), _jsx(MetricCard, { label: t("dispatch.pages.llmCalls"), value: formatNumber(metrics.totals.calls), detail: `${formatNumber(metrics.totals.chatCalls)} chat turns`, icon: _jsx(IconActivity, { size: 17 }) }), _jsx(MetricCard, { label: t("dispatch.pages.activeUsers"), value: formatNumber(metrics.totals.activeUsers), detail: `${formatNumber(metrics.access.totalUsers)} users with access`, icon: _jsx(IconUsersGroup, { size: 17 }) }), _jsx(MetricCard, { label: t("dispatch.pages.workspaceAppsStat"), value: formatNumber(metrics.totals.workspaceApps), detail: `${formatNumber(metrics.byApp.length)} with usage`, icon: _jsx(IconApps, { size: 17 }) }), _jsx(MetricCard, { label: t("dispatch.pages.chatThreads"), value: formatNumber(metrics.totals.chatThreads), detail: `${formatNumber(metrics.totals.chatMessages)} messages`, icon: _jsx(IconMessages, { size: 17 }) })] }), _jsx(AppAdoptionPanel, { rows: metrics.appAccess, selectedAppId: metrics.selectedAppId ?? appId, scope: scope, backScope: backScope }), _jsx(Panel, { title: billing.unit === "builder-credits"
355
- ? "Credit spend by app"
356
- : "Spend by app", icon: _jsx(IconApps, { size: 16 }), children: _jsx(AppSpendRows, { rows: metrics.byApp, billing: billing }) }), _jsx(Panel, { title: "Access By App", icon: _jsx(IconApps, { size: 16 }), children: _jsx(AppAccessTable, { rows: metrics.appAccess, billing: billing }) }), scope !== "app" ? (_jsx(Panel, { title: "Users", icon: _jsx(IconUsersGroup, { size: 16 }), children: _jsx(UserTable, { rows: metrics.byUser, billing: billing }) })) : null, _jsxs("div", { className: "grid gap-4 lg:grid-cols-2", children: [_jsx(Panel, { title: "Models", icon: _jsx(IconChartBar, { size: 16 }), children: _jsx(CompactBreakdown, { rows: metrics.byModel, empty: "No model usage in this window.", billing: billing }) }), _jsx(Panel, { title: "Work Types", icon: _jsx(IconActivity, { size: 16 }), children: _jsx(CompactBreakdown, { rows: metrics.byLabel, empty: "No labeled usage in this window.", billing: billing }) })] })] })) : null] }) }));
389
+ : t("dispatch.pages.unableToLoadUsage") })] })) : null, isLoading && !metrics ? _jsx(LoadingMetrics, {}) : null, metrics ? (_jsxs(Tabs, { value: view, onValueChange: (value) => {
390
+ if (value === "overview" ||
391
+ value === "adoption" ||
392
+ value === "details") {
393
+ setView(value);
394
+ }
395
+ }, className: "flex min-w-0 flex-col gap-5", children: [_jsxs(TabsList, { className: "w-fit", children: [_jsxs(TabsTrigger, { value: "overview", children: [_jsx(IconActivity, { size: 15, className: "mr-1.5" }), t("dispatch.nav.overview")] }), _jsxs(TabsTrigger, { value: "adoption", children: [_jsx(IconApps, { size: 15, className: "mr-1.5" }), t("dispatch.pages.appAdoption")] }), _jsxs(TabsTrigger, { value: "details", children: [_jsx(IconChartBar, { size: 15, className: "mr-1.5" }), t("details")] })] }), _jsxs(TabsContent, { value: "overview", className: "mt-0 min-w-0 space-y-4", children: [metrics.dailyAvailable === false ? (_jsxs(Alert, { variant: "destructive", children: [_jsx(IconAlertTriangle, { className: "h-4 w-4" }), _jsx(AlertTitle, { children: t("dispatch.pages.metricsUnavailable") }), _jsx(AlertDescription, { children: t("dispatch.pages.unableToLoadUsage") })] })) : null, _jsx(UsageTrend, { rows: metrics.daily, billing: billing }), _jsx(UserActivityTrend, { rows: metrics.daily }), _jsxs("div", { className: "flex items-center justify-between gap-3 border-y py-3", children: [_jsx("span", { className: "text-sm text-muted-foreground", children: "Review this usage with the agent" }), _jsx(ReviewUsageButton, { metrics: metrics, billing: billing })] }), scope !== "app" ? (_jsx(UsageAlertsPanel, { scope: scope === "workspace" ? "workspace" : "user", appOptions: metrics.byApp
396
+ .filter((row) => row.key && row.key !== "unattributed")
397
+ .map((row) => ({
398
+ id: row.key,
399
+ label: displayApp(row.key),
400
+ })) })) : null, _jsxs("div", { className: "grid gap-3 md:grid-cols-2 xl:grid-cols-5", children: [_jsx(MetricCard, { label: billing.label, value: formatSpend(metrics.totals.costCents, billing), detail: `${formatTokens(totalTokens)} total tokens`, icon: _jsx(IconCoin, { size: 17 }) }), _jsx(MetricCard, { label: t("dispatch.pages.llmCalls"), value: formatNumber(metrics.totals.calls), detail: `${formatNumber(metrics.totals.chatCalls)} chat turns`, icon: _jsx(IconActivity, { size: 17 }) }), _jsx(MetricCard, { label: t("dispatch.pages.activeUsers"), value: formatNumber(metrics.totals.activeUsers), detail: `${formatNumber(metrics.access.totalUsers)} users with access`, icon: _jsx(IconUsersGroup, { size: 17 }) }), _jsx(MetricCard, { label: t("dispatch.pages.workspaceAppsStat"), value: formatNumber(metrics.totals.workspaceApps), detail: `${formatNumber(metrics.byApp.length)} with usage`, icon: _jsx(IconApps, { size: 17 }) }), _jsx(MetricCard, { label: t("dispatch.pages.chatThreads"), value: formatNumber(metrics.totals.chatThreads), detail: `${formatNumber(metrics.totals.chatMessages)} messages`, icon: _jsx(IconMessages, { size: 17 }) })] })] }), _jsx(TabsContent, { value: "adoption", className: "mt-0 min-w-0", children: _jsx(AppAdoptionPanel, { rows: metrics.appAccess, selectedAppId: metrics.selectedAppId ?? appId, scope: scope, backScope: backScope }) }), _jsxs(TabsContent, { value: "details", className: "mt-0 min-w-0 space-y-4", children: [_jsx(Panel, { title: billing.unit === "builder-credits"
401
+ ? "Credit spend by app"
402
+ : "Spend by app", icon: _jsx(IconApps, { size: 16 }), children: _jsx(AppSpendRows, { rows: metrics.byApp, billing: billing }) }), _jsx(Panel, { title: "Access By App", icon: _jsx(IconApps, { size: 16 }), children: _jsx(AppAccessTable, { rows: metrics.appAccess, billing: billing }) }), scope !== "app" ? (_jsx(Panel, { title: "Users", icon: _jsx(IconUsersGroup, { size: 16 }), children: _jsx(UserTable, { rows: metrics.byUser, billing: billing }) })) : null, _jsxs("div", { className: "grid gap-4 lg:grid-cols-2", children: [_jsx(Panel, { title: "Models", icon: _jsx(IconChartBar, { size: 16 }), children: _jsx(CompactBreakdown, { rows: metrics.byModel, empty: "No model usage in this window.", billing: billing }) }), _jsx(Panel, { title: "Work Types", icon: _jsx(IconActivity, { size: 16 }), children: _jsx(CompactBreakdown, { rows: metrics.byLabel, empty: "No labeled usage in this window.", billing: billing }) })] })] })] })) : null] }) }));
357
403
  }
358
404
  //# sourceMappingURL=metrics.js.map