@alook/app 0.0.136 → 0.0.138

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 (119) hide show
  1. package/bundled/email-worker/index.js +17 -9
  2. package/bundled/web/.open-next/.build/durable-objects/queue.js +5 -5
  3. package/bundled/web/.open-next/assets/BUILD_ID +1 -1
  4. package/bundled/web/.open-next/assets/_next/static/chunks/{2n83te3i54x0y.js → 08owkyc3y3nuc.js} +1 -1
  5. package/bundled/web/.open-next/assets/_next/static/chunks/{0njval22g1rht.js → 0gadq1gaq7l2d.js} +1 -1
  6. package/bundled/web/.open-next/assets/_next/static/chunks/{05mvqqr0d48pd.css → 1o14pyvttt8vl.css} +1 -1
  7. package/bundled/web/.open-next/cache/{BF9psRzRPCmyYVYovM5Wd → 0jpboe0ecrihrJF2CMdwU}/_global-error.cache +1 -1
  8. package/bundled/web/.open-next/cache/{BF9psRzRPCmyYVYovM5Wd → 0jpboe0ecrihrJF2CMdwU}/_not-found.cache +1 -1
  9. package/bundled/web/.open-next/cache/{BF9psRzRPCmyYVYovM5Wd → 0jpboe0ecrihrJF2CMdwU}/device.cache +1 -1
  10. package/bundled/web/.open-next/cache/{BF9psRzRPCmyYVYovM5Wd → 0jpboe0ecrihrJF2CMdwU}/privacy.cache +1 -1
  11. package/bundled/web/.open-next/cache/{BF9psRzRPCmyYVYovM5Wd → 0jpboe0ecrihrJF2CMdwU}/sitemap.xml.cache +1 -1
  12. package/bundled/web/.open-next/cloudflare/cache-assets-manifest.sql +1 -1
  13. package/bundled/web/.open-next/cloudflare/init.js +1 -1
  14. package/bundled/web/.open-next/dynamodb-provider/dynamodb-cache.json +1 -1
  15. package/bundled/web/.open-next/middleware/handler.mjs +4 -4
  16. package/bundled/web/.open-next/server-functions/default/src/web/.next/BUILD_ID +1 -1
  17. package/bundled/web/.open-next/server-functions/default/src/web/.next/build-manifest.json +3 -3
  18. package/bundled/web/.open-next/server-functions/default/src/web/.next/prerender-manifest.json +3 -3
  19. package/bundled/web/.open-next/server-functions/default/src/web/.next/required-server-files.json +1 -1
  20. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/invite/[token]/page_client-reference-manifest.js +1 -1
  21. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/studio/new/page_client-reference-manifest.js +1 -1
  22. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/activity/page_client-reference-manifest.js +1 -1
  23. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/chat/[convId]/page_client-reference-manifest.js +1 -1
  24. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/chat/page_client-reference-manifest.js +1 -1
  25. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/email/page_client-reference-manifest.js +1 -1
  26. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/files/page_client-reference-manifest.js +1 -1
  27. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/meetings/page_client-reference-manifest.js +1 -1
  28. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/page_client-reference-manifest.js +1 -1
  29. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/new/page_client-reference-manifest.js +1 -1
  30. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/page_client-reference-manifest.js +1 -1
  31. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/calendar/page_client-reference-manifest.js +1 -1
  32. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/flags/page_client-reference-manifest.js +1 -1
  33. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/help/email-setup/page_client-reference-manifest.js +1 -1
  34. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/home/page_client-reference-manifest.js +1 -1
  35. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/issues/page_client-reference-manifest.js +1 -1
  36. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/page_client-reference-manifest.js +1 -1
  37. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/runtimes/page_client-reference-manifest.js +1 -1
  38. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/settings/page_client-reference-manifest.js +1 -1
  39. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/traces/[traceId]/page_client-reference-manifest.js +1 -1
  40. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/traces/page_client-reference-manifest.js +1 -1
  41. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/unread/page_client-reference-manifest.js +1 -1
  42. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/workspaces/page_client-reference-manifest.js +1 -1
  43. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(auth)/sign-in/page_client-reference-manifest.js +1 -1
  44. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  45. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/api/agent-links/route.js +4 -4
  46. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/api/agents/[id]/workspace/browse/route.js +5 -5
  47. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/api/agents/active-task-counts/route.js +5 -5
  48. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/api/artifacts/route.js +1 -1
  49. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/api/email/[id]/raw/route.js +1 -1
  50. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/api/tasks/[id]/retry/route.js +2 -2
  51. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/device/page_client-reference-manifest.js +1 -1
  52. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/page_client-reference-manifest.js +1 -1
  53. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/privacy/page_client-reference-manifest.js +1 -1
  54. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/templates/[id]/page_client-reference-manifest.js +1 -1
  55. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/templates/page_client-reference-manifest.js +1 -1
  56. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0255f4r._.js +1 -1
  57. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__03zvu2n._.js +1 -1
  58. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__055kbgp._.js +1 -1
  59. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__05b3ysj._.js +3 -0
  60. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__09-j82k._.js +1 -1
  61. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__09psmu_._.js +1 -1
  62. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0eaeyl_._.js +1 -1
  63. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0gkkbf4._.js +1 -1
  64. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0t2tu5g._.js +1 -1
  65. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0wd6xqg._.js +1 -1
  66. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__155l597._.js +3 -0
  67. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__18yr8rv._.js +1 -1
  68. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__1_d30qf._.js +1 -1
  69. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__1bu3ajw._.js +1 -1
  70. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__1g-mlb0._.js +1 -1
  71. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__1k1navi._.js +1 -1
  72. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__1kg1kju._.js +1 -1
  73. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__1pmcw25._.js +1 -1
  74. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[turbopack]_runtime.js +4 -4
  75. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_03r3es0._.js +1 -1
  76. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_0591v0o._.js +3 -0
  77. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_059g9--._.js +1 -1
  78. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_06fjxe_._.js +1 -1
  79. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_08gc1s_._.js +1 -1
  80. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/{_0ulry_i._.js → _0m_ehw8._.js} +2 -2
  81. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_0n8pg0d._.js +1 -1
  82. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_0p79t7w._.js +1 -1
  83. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_0r2vuif._.js +1 -1
  84. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_0v95a0y._.js +3 -3
  85. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_12qkx0d._.js +1 -1
  86. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_139j3zh._.js +3 -3
  87. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1a2lyoh._.js +1 -1
  88. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1bq9v_v._.js +1 -1
  89. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1eu061o._.js +1 -1
  90. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1i4egv6._.js +1 -1
  91. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1i9fvyt._.js +1 -1
  92. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1nfaney._.js +3 -3
  93. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1pn2do-._.js +1 -1
  94. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1tu2mle._.js +1 -1
  95. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1wx8s3g._.js +1 -1
  96. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/[root-of-the-server]__02a8jxi._.js +1 -1
  97. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/[root-of-the-server]__1nnp8st._.js +1 -1
  98. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/[turbopack]_runtime.js +4 -4
  99. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/_09v4-yk._.js +3 -3
  100. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/_0qgcnj5._.js +1 -1
  101. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/src_web_src_1kzi5ju._.js +1 -1
  102. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/middleware-build-manifest.js +3 -3
  103. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/middleware-manifest.json +5 -5
  104. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/server-reference-manifest.js +1 -1
  105. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/server-reference-manifest.json +1 -1
  106. package/bundled/web/.open-next/server-functions/default/src/web/handler.mjs +85 -85
  107. package/bundled/web/.open-next/server-functions/default/src/web/handler.mjs.meta.json +123 -123
  108. package/bundled/web/.open-next/server-functions/default/src/web/index.mjs +4 -4
  109. package/bundled/ws-do/index.js +16 -8
  110. package/dist/cli/index.js +5 -4
  111. package/dist/cli/session-runner.js +5 -4
  112. package/package.json +1 -1
  113. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0_qhrkj._.js +0 -3
  114. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0csf1z3._.js +0 -3
  115. package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_18iwzmu._.js +0 -3
  116. /package/bundled/web/.open-next/assets/_next/static/{BF9psRzRPCmyYVYovM5Wd → 0jpboe0ecrihrJF2CMdwU}/_buildManifest.js +0 -0
  117. /package/bundled/web/.open-next/assets/_next/static/{BF9psRzRPCmyYVYovM5Wd → 0jpboe0ecrihrJF2CMdwU}/_clientMiddlewareManifest.js +0 -0
  118. /package/bundled/web/.open-next/assets/_next/static/{BF9psRzRPCmyYVYovM5Wd → 0jpboe0ecrihrJF2CMdwU}/_ssgManifest.js +0 -0
  119. /package/bundled/web/.open-next/cache/{BF9psRzRPCmyYVYovM5Wd → 0jpboe0ecrihrJF2CMdwU}/robots.txt.cache +0 -0
@@ -26316,17 +26316,19 @@ async function countRunningTasks(db, agentId, workspaceId, excludeTaskId) {
26316
26316
  const rows = await db.select({ value: count3() }).from(agentTaskQueue).where(and(...conditions));
26317
26317
  return Number(rows[0]?.value ?? 0);
26318
26318
  }
26319
- async function listActiveTaskCountsByWorkspace(db, workspaceId) {
26319
+ async function listActiveTaskCountsByWorkspace(db, workspaceId, agentIds) {
26320
+ const conditions = [
26321
+ eq(agentTaskQueue.workspaceId, workspaceId),
26322
+ inArray(agentTaskQueue.status, ["queued", "dispatched", "running"]),
26323
+ ne(agentTaskQueue.type, TASK_TYPES.KILL_TASK)
26324
+ ];
26325
+ if (agentIds && agentIds.length > 0) {
26326
+ conditions.push(inArray(agentTaskQueue.agentId, agentIds));
26327
+ }
26320
26328
  return db.select({
26321
26329
  agentId: agentTaskQueue.agentId,
26322
26330
  count: count3()
26323
- }).from(agentTaskQueue).where(
26324
- and(
26325
- eq(agentTaskQueue.workspaceId, workspaceId),
26326
- inArray(agentTaskQueue.status, ["queued", "dispatched", "running"]),
26327
- ne(agentTaskQueue.type, TASK_TYPES.KILL_TASK)
26328
- )
26329
- ).groupBy(agentTaskQueue.agentId).limit(200);
26331
+ }).from(agentTaskQueue).where(and(...conditions)).groupBy(agentTaskQueue.agentId).limit(200);
26330
26332
  }
26331
26333
  async function listActiveTasksByWorkspace(db, workspaceId, agentIds) {
26332
26334
  const conditions = [
@@ -28514,6 +28516,7 @@ var agent_link_exports = {};
28514
28516
  __export(agent_link_exports, {
28515
28517
  create: () => create,
28516
28518
  getAllColleaguesForWorkspace: () => getAllColleaguesForWorkspace,
28519
+ getById: () => getById,
28517
28520
  getByPair: () => getByPair,
28518
28521
  getColleaguesForAgent: () => getColleaguesForAgent,
28519
28522
  getColleaguesForAgents: () => getColleaguesForAgents,
@@ -28581,6 +28584,10 @@ async function upsertByPair(db, data) {
28581
28584
  const created = await create(db, data);
28582
28585
  return { row: created, created: true };
28583
28586
  }
28587
+ async function getById(db, id, workspaceId) {
28588
+ const rows = await db.select().from(agentLink).where(and(eq(agentLink.id, id), eq(agentLink.workspaceId, workspaceId)));
28589
+ return rows[0] ?? null;
28590
+ }
28584
28591
  async function update(db, id, workspaceId, data) {
28585
28592
  const rows = await db.update(agentLink).set({
28586
28593
  instruction: data.instruction,
@@ -28693,6 +28700,7 @@ var init_agent_link = __esm({
28693
28700
  __name(create, "create");
28694
28701
  __name(getByPair, "getByPair");
28695
28702
  __name(upsertByPair, "upsertByPair");
28703
+ __name(getById, "getById");
28696
28704
  __name(update, "update");
28697
28705
  __name(remove, "remove");
28698
28706
  __name(getColleaguesForAgent, "getColleaguesForAgent");
@@ -29466,7 +29474,7 @@ var init_db_errors = __esm({
29466
29474
 
29467
29475
  // ../shared/src/utils/slug.ts
29468
29476
  function generateWorkspaceSlug() {
29469
- return `studio-${nanoid(8)}`;
29477
+ return `company-${nanoid(8)}`;
29470
29478
  }
29471
29479
  var init_slug = __esm({
29472
29480
  "../shared/src/utils/slug.ts"() {
@@ -156,7 +156,7 @@ var DOQueueHandler = class extends DurableObject {
156
156
  method: "HEAD",
157
157
  headers: {
158
158
  // This is defined during build
159
- "x-prerender-revalidate": "a9d0a325be3f96eec176aa825acd7673",
159
+ "x-prerender-revalidate": "bcce64bbd7f781cf60322f5d27947e07",
160
160
  "x-isr": "1"
161
161
  },
162
162
  // This one is kind of problematic, it will always show the wall time of the revalidation to `this.revalidationTimeout`
@@ -180,7 +180,7 @@ var DOQueueHandler = class extends DurableObject {
180
180
  "INSERT OR REPLACE INTO sync (id, lastSuccess, buildId) VALUES (?, unixepoch(), ?)",
181
181
  // We cannot use the deduplication id because it's not unique per route - every time a route is revalidated, the deduplication id is different.
182
182
  `${host}${url}`,
183
- "BF9psRzRPCmyYVYovM5Wd"
183
+ "0jpboe0ecrihrJF2CMdwU"
184
184
  );
185
185
  }
186
186
  this.routeInFailedState.delete(msg.MessageDeduplicationId);
@@ -232,7 +232,7 @@ var DOQueueHandler = class extends DurableObject {
232
232
  }
233
233
  this.routeInFailedState.set(msg.MessageDeduplicationId, updatedFailedState);
234
234
  if (!this.disableSQLite) {
235
- this.sql.exec("INSERT OR REPLACE INTO failed_state (id, data, buildId) VALUES (?, ?, ?)", msg.MessageDeduplicationId, JSON.stringify(updatedFailedState), "BF9psRzRPCmyYVYovM5Wd");
235
+ this.sql.exec("INSERT OR REPLACE INTO failed_state (id, data, buildId) VALUES (?, ?, ?)", msg.MessageDeduplicationId, JSON.stringify(updatedFailedState), "0jpboe0ecrihrJF2CMdwU");
236
236
  }
237
237
  await this.addAlarm();
238
238
  }
@@ -256,8 +256,8 @@ var DOQueueHandler = class extends DurableObject {
256
256
  return;
257
257
  this.sql.exec("CREATE TABLE IF NOT EXISTS failed_state (id TEXT PRIMARY KEY, data TEXT, buildId TEXT)");
258
258
  this.sql.exec("CREATE TABLE IF NOT EXISTS sync (id TEXT PRIMARY KEY, lastSuccess INTEGER, buildId TEXT)");
259
- this.sql.exec("DELETE FROM failed_state WHERE buildId != ?", "BF9psRzRPCmyYVYovM5Wd");
260
- this.sql.exec("DELETE FROM sync WHERE buildId != ?", "BF9psRzRPCmyYVYovM5Wd");
259
+ this.sql.exec("DELETE FROM failed_state WHERE buildId != ?", "0jpboe0ecrihrJF2CMdwU");
260
+ this.sql.exec("DELETE FROM sync WHERE buildId != ?", "0jpboe0ecrihrJF2CMdwU");
261
261
  const failedStateCursor = this.sql.exec("SELECT * FROM failed_state");
262
262
  for (const row of failedStateCursor) {
263
263
  this.routeInFailedState.set(row.id, JSON.parse(row.data));
@@ -1 +1 @@
1
- BF9psRzRPCmyYVYovM5Wd
1
+ 0jpboe0ecrihrJF2CMdwU
@@ -1 +1 @@
1
- (globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,716032,e=>{"use strict";e.i(811374);var s=e.i(653772),t=e.i(511043),a=e.i(255334),r=e.i(613349),i=e.i(516266),n=e.i(126942),l=e.i(500324),c=e.i(23055),d=e.i(222862),o=e.i(186339),m=e.i(903477),u=e.i(473131),x=e.i(728886),h=e.i(553617),p=e.i(205189);function f(){let{workspaceId:e,slug:a}=(0,l.useWorkspace)(),r=(0,c.useSession)(),f=(0,n.useRouter)(),[g,j]=(0,t.useState)(""),[v,N]=(0,t.useState)(!0),[b,y]=(0,t.useState)(""),[k,w]=(0,t.useState)(""),[C,T]=(0,t.useState)(""),[S,E]=(0,t.useState)(""),[_,M]=(0,t.useState)(!1),[P,z]=(0,t.useState)({}),[I,O]=(0,t.useState)(""),[R,$]=(0,t.useState)(!1),F=(0,t.useCallback)(async()=>{N(!0);try{let s=r.data?.user?.id,[t,a]=await Promise.all([(0,d.listMembers)(e),(0,d.listWorkspaces)()]),i=t.find(e=>e.user_id===s);j(i?.role??"");let n=a.find(s=>s.id===e);n&&(y(n.name),w(n.slug),T(n.name),E(n.slug))}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to load workspace info")}finally{N(!1)}},[e,r.data?.user?.id]);(0,t.useEffect)(()=>{r.data&&F()},[F,r.data]);let A=b!==C||k!==S,D=async()=>{let s=(0,h.validateWorkspaceForm)({name:b,slug:k});if(z(s),!(0,h.hasWorkspaceFormErrors)(s)){M(!0);try{let s=await (0,d.updateWorkspace)(e,{name:b.trim(),slug:k.trim()});(0,p.trackSettingsUpdated)({setting_tab:"general"}),T(s.name),E(s.slug),i.toast.success("Workspace updated"),s.slug!==a&&f.replace(`/w/${s.slug}/settings`)}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to update workspace")}finally{M(!1)}}},L=async()=>{if(I===C){$(!0);try{await (0,d.deleteWorkspace)(e,C),i.toast.success("Workspace deleted"),f.replace("/workspaces")}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to delete workspace")}finally{$(!1)}}};return v?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)(x.Skeleton,{className:"h-4 w-32"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"})]}):"owner"!==g?(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Only workspace owners can edit workspace settings."}):(0,s.jsxs)("div",{className:"space-y-10",children:[(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Workspace"}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(u.Label,{htmlFor:"workspace-name",children:"Name"}),(0,s.jsx)(m.Input,{id:"workspace-name",value:b,onChange:e=>{let s=e.target.value;y(s),P.name&&s.trim()&&z(e=>({...e,name:void 0}))},placeholder:"Workspace name","aria-invalid":!!P.name,"aria-describedby":P.name?"workspace-name-error":void 0}),P.name&&(0,s.jsx)("p",{id:"workspace-name-error",className:"text-xs text-destructive",children:P.name})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(u.Label,{htmlFor:"workspace-slug",children:"Slug"}),(0,s.jsx)(m.Input,{id:"workspace-slug",value:k,onChange:e=>{let s=e.target.value;w(s),P.slug&&s.trim()&&z(e=>({...e,slug:void 0}))},placeholder:"workspace-slug","aria-invalid":!!P.slug,"aria-describedby":P.slug?"workspace-slug-error":void 0}),P.slug&&(0,s.jsx)("p",{id:"workspace-slug-error",className:"text-xs text-destructive",children:P.slug}),(0,s.jsxs)("p",{className:"text-xs text-muted-foreground/70",children:["Used in URLs: /w/",k,"/"]})]})]}),(0,s.jsx)(o.Button,{size:"sm",onClick:D,disabled:!A||_,children:_?"Saving…":"Save"})]}),(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsx)("h2",{className:"text-sm font-medium text-destructive",children:"Danger Zone"}),(0,s.jsxs)("div",{className:"rounded-md border border-destructive/30 p-4 space-y-3",children:[(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Deleting this workspace is permanent and cannot be undone. All agents, conversations, and data will be lost."}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsxs)(u.Label,{htmlFor:"delete-confirm",className:"text-xs",children:["Type ",(0,s.jsx)("span",{className:"font-medium text-foreground",children:C})," to confirm"]}),(0,s.jsx)(m.Input,{id:"delete-confirm",value:I,onChange:e=>O(e.target.value),placeholder:C})]}),(0,s.jsx)(o.Button,{size:"sm",variant:"destructive",onClick:L,disabled:I!==C||R,children:R?"Deleting…":"Delete Workspace"})]})]})]})}var g=e.i(740513);function j({ratio:e,size:t=16,stroke:a=1.5}){let i=(t-a)/2,n=2*Math.PI*i,l=(e<=0?0:e>=1?1:Math.log1p(99*e)/Math.log(100))*n;return(0,s.jsxs)("svg",{width:t,height:t,className:"shrink-0 -rotate-90","aria-hidden":!0,children:[(0,s.jsx)("circle",{cx:t/2,cy:t/2,r:i,fill:"none",stroke:"currentColor",strokeWidth:a,className:"text-border"}),(0,s.jsx)("circle",{cx:t/2,cy:t/2,r:i,fill:"none",stroke:"currentColor",strokeWidth:a,strokeDasharray:`${l} ${n-l}`,strokeLinecap:"round",className:(0,r.cn)("transition-all duration-300",e>.9?"text-destructive/70":e>.7?"text-yellow-500/50":"text-muted-foreground/30")})]})}function v(){let{workspaceId:e}=(0,l.useWorkspace)(),[a,r]=(0,t.useState)(""),[n,c]=(0,t.useState)(""),[o,m]=(0,t.useState)(!0),u=(0,t.useRef)(a);(0,t.useEffect)(()=>{u.current=a},[a]);let h=(0,t.useRef)(n);(0,t.useEffect)(()=>{h.current=n},[n]);let p=(0,t.useRef)(null),f=(0,t.useRef)(!1),v=(0,t.useCallback)(async()=>{m(!0);try{let s=await (0,d.getMemberMe)(e);r(s.global_instruction),c(s.global_instruction)}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to load settings")}finally{m(!1)}},[e]);(0,t.useEffect)(()=>{v()},[v]);let N=(0,t.useRef)(()=>{}),b=(0,t.useCallback)(async()=>{if(f.current)return;let s=u.current;if(s!==h.current){f.current=!0;try{let t=await (0,d.updateMemberMe)(e,s);c(t.global_instruction)}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to save")}finally{f.current=!1,u.current!==h.current&&N.current()}}},[e]),y=(0,t.useCallback)(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(b,500)},[b]);(0,t.useEffect)(()=>{N.current=y},[y]);let k=(0,t.useCallback)(e=>{r(e),y()},[y]);(0,t.useEffect)(()=>{let s=()=>{if(p.current&&clearTimeout(p.current),u.current!==h.current){let s=new URLSearchParams({workspace_id:e});fetch(`/api/members/me?${s}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({global_instruction:u.current}),keepalive:!0})}};return window.addEventListener("beforeunload",s),()=>window.removeEventListener("beforeunload",s)},[e]),(0,t.useEffect)(()=>()=>{if(p.current&&clearTimeout(p.current),u.current!==h.current){let s=new URLSearchParams({workspace_id:e});fetch(`/api/members/me?${s}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({global_instruction:u.current}),keepalive:!0})}},[e]);let w=a.length/5e4;return o?(0,s.jsxs)("div",{className:"px-6 py-6 space-y-4",children:[(0,s.jsx)(x.Skeleton,{className:"h-4 w-48"}),(0,s.jsx)(x.Skeleton,{className:"h-40 w-full"})]}):(0,s.jsxs)("div",{className:"flex flex-col h-full",children:[(0,s.jsx)("div",{className:"flex-1 px-6 pt-4 pb-4",children:(0,s.jsx)(g.MarkdownEditor,{value:a,onChange:k,placeholder:"Write instructions that every agent you own will follow...",minHeight:"calc(100vh - 240px)",contentType:"markdown",variant:"seamless"})}),(0,s.jsxs)("div",{className:"flex items-center gap-2 px-6 py-3",children:[(0,s.jsx)(j,{ratio:w}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"This instruction is prepended to every agent's individual instruction."})]})]})}var N=e.i(330746),b=e.i(813141),y=e.i(947308),k=e.i(419412);let w=(0,k.default)("user-minus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);var C=e.i(329686);function T(e){return`${window.location.origin}/invite/${e}`}function S(){let{workspaceId:e}=(0,l.useWorkspace)(),a=(0,c.useSession)(),n=a.data?.user?.id,[m,u]=(0,t.useState)([]),[h,f]=(0,t.useState)([]),[g,j]=(0,t.useState)(!0),[v,k]=(0,t.useState)(!1),S=m.find(e=>e.user_id===n)?.role==="owner",E=(0,t.useCallback)(async()=>{j(!0);try{let[s,t]=await Promise.all([(0,d.listMembers)(e),(0,d.listInvites)(e).catch(()=>[])]);u(s),f(t)}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to load members")}finally{j(!1)}},[e]);(0,t.useEffect)(()=>{E()},[E]);let _=async()=>{k(!0);try{let s=await (0,d.createInvite)(e);(0,p.trackTeamMemberInvited)({workspace_id:e}),f(e=>[...e,s]);let t=T(s.token);await navigator.clipboard.writeText(t),i.toast.success("Invite link copied to clipboard")}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to generate invite")}finally{k(!1)}},M=async e=>{let s=T(e);try{await navigator.clipboard.writeText(s),i.toast.success("Invite link copied")}catch{i.toast.error("Failed to copy link")}},P=async s=>{try{await (0,d.revokeInvite)(e,s),f(e=>e.filter(e=>e.id!==s)),i.toast.success("Invite revoked")}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to revoke invite")}},z=async s=>{try{await (0,d.removeMember)(e,s),u(e=>e.filter(e=>e.id!==s)),i.toast.success("Member removed")}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to remove member")}};return g?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)(x.Skeleton,{className:"h-4 w-24"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"}),(0,s.jsx)(x.Skeleton,{className:"h-4 w-24 mt-6"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"})]}):(0,s.jsxs)("div",{className:"space-y-8",children:[S&&(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Pending Invites"}),(0,s.jsxs)(o.Button,{size:"sm",variant:"outline",onClick:_,disabled:v,children:[(0,s.jsx)(y.Plus,{className:"size-3.5 mr-1"}),v?"Generating…":"Generate invite link"]})]}),0===h.length?(0,s.jsx)("p",{className:"text-xs text-muted-foreground py-2",children:"No active invite links. Generate one to invite someone to this workspace."}):(0,s.jsx)("div",{className:"space-y-1.5",children:h.map(e=>{let t=new Date(e.expires_at),a=t<new Date;return(0,s.jsxs)("div",{className:"flex items-center justify-between rounded-md border border-border/50 px-3 py-2 text-xs",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("p",{className:(0,r.cn)("font-mono truncate",a&&"text-muted-foreground line-through"),children:["/invite/",e.token.slice(0,12),"…"]}),(0,s.jsx)("p",{className:(0,r.cn)("text-muted-foreground/70 mt-0.5",a&&"text-destructive/70"),children:a?"Expired":`Expires ${t.toLocaleDateString()}`})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 ml-2 shrink-0",children:[!a&&(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)(o.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>M(e.token)}),children:(0,s.jsx)(N.Copy,{className:"size-3.5"})}),(0,s.jsx)(C.TooltipContent,{children:"Copy invite link"})]}),(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)(o.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",onClick:()=>P(e.id)}),children:(0,s.jsx)(b.Trash2,{className:"size-3.5"})}),(0,s.jsx)(C.TooltipContent,{children:"Revoke invite"})]})]})]},e.id)})})]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Members"}),(0,s.jsx)("div",{className:"space-y-1.5",children:m.map(e=>{let t=e.user_id===n,a=e.name?e.name.split(" ").map(e=>e[0]).join("").slice(0,2).toUpperCase():e.email.slice(0,2).toUpperCase();return(0,s.jsxs)("div",{className:"flex items-center gap-3 rounded-md border border-border/50 px-3 py-2",children:[(0,s.jsx)("div",{className:"size-7 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground shrink-0 overflow-hidden",children:e.image?(0,s.jsx)("img",{src:e.image,alt:e.name,className:"size-full object-cover"}):a}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("p",{className:"text-sm font-medium truncate leading-tight",children:[e.name||e.email,t&&(0,s.jsx)("span",{className:"ml-1.5 text-xs text-muted-foreground font-normal",children:"(you)"})]}),e.name&&(0,s.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:e.email})]}),(0,s.jsx)("span",{className:(0,r.cn)("text-xs px-1.5 py-0.5 rounded shrink-0","owner"===e.role?"bg-primary/10 text-primary":"bg-muted text-muted-foreground"),children:e.role}),S&&!t&&(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)(o.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-muted-foreground hover:text-destructive shrink-0",onClick:()=>z(e.id)}),children:(0,s.jsx)(w,{className:"size-3.5"})}),(0,s.jsx)(C.TooltipContent,{children:"Remove member"})]})]},e.id)})})]})]})}var E=e.i(885515),_=e.i(254618),M=e.i(899746);function P(){let[e,a]=(0,t.useState)(!1),[r,n]=(0,t.useState)([...M.NOTIFICATION_EVENTS]),[l,c]=(0,t.useState)(!0),[d,o]=(0,t.useState)(!1);(0,t.useEffect)(()=>{c((0,M.isNotificationSupported)()),a((0,M.getNotificationEnabled)()),n((0,M.getNotificationEvents)()),(0,M.isNotificationSupported)()&&o("denied"===Notification.permission)},[]);let m=async e=>{if(!e){a(!1),(0,M.setNotificationEnabled)(!1);return}await (0,M.requestNotificationPermission)()?(a(!0),(0,M.setNotificationEnabled)(!0)):(o(!0),i.toast.error("Notification permission denied. Please enable it in browser settings."))};return l?(0,s.jsx)("div",{className:"space-y-6",children:(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Browser Notifications"}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"space-y-0.5",children:[(0,s.jsx)("p",{className:"text-sm",children:"Enable notifications"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Get notified when tasks finish while the tab is in the background"})]}),(0,s.jsx)(_.Switch,{checked:e,onCheckedChange:m,disabled:d&&!e})]}),d&&!e&&(0,s.jsx)("p",{className:"text-xs text-destructive",children:"Notification permission was denied. Please allow it in your browser settings."}),e&&(0,s.jsxs)("div",{className:"space-y-2 pl-0.5",children:[(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Notify me when:"}),M.NOTIFICATION_EVENTS.map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-2 text-sm cursor-pointer select-none",children:[(0,s.jsx)(E.Checkbox,{checked:r.includes(e),onCheckedChange:()=>{n(s=>{let t=s.includes(e)?s.filter(s=>s!==e):[...s,e];return(0,M.setNotificationEvents)(t),t})}}),M.NOTIFICATION_EVENT_LABELS[e]]},e))]})]})]})}):(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Your browser does not support notifications."})}let z=(0,k.default)("sparkles",[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]]);var I=e.i(399561),O=e.i(460520),R=e.i(961909),$=e.i(790961);function F(){let[e,a]=(0,t.useState)(!1),[i,n]=(0,t.useState)(I.CLOUD_CODE_MONSTER_PET_PRESETS[0].id),l=(0,I.getCloudCodeMonsterPreset)(i);return(0,t.useEffect)(()=>{a((0,$.readHomePetSettings)().enabled),n((0,I.readCloudCodeMonsterPetPresetId)());let e=e=>{let s=e.detail?.presetId;n(s?(0,I.getCloudCodeMonsterPreset)(s).id:(0,I.readCloudCodeMonsterPetPresetId)())};return window.addEventListener(O.CLOUD_CODE_MONSTER_PRESET_CHANGED_EVENT,e),()=>{window.removeEventListener(O.CLOUD_CODE_MONSTER_PRESET_CHANGED_EVENT,e)}},[]),(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Pet"}),(0,s.jsx)("div",{className:"space-y-4",children:(0,s.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,s.jsxs)("div",{className:"space-y-0.5",children:[(0,s.jsx)(u.Label,{htmlFor:"pet-enabled",className:"text-sm",children:"Enable pet"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Off by default. Turn it on when you want the workspace companion."})]}),(0,s.jsx)(_.Switch,{id:"pet-enabled",checked:e,onCheckedChange:e=>{a(e),(0,$.writeHomePetSettings)({enabled:e})}})]})})]}),e?(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Preset"}),(0,s.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:l.name})]}),(0,s.jsx)("div",{className:"grid size-14 place-items-center rounded-md bg-card ring-1 ring-border/60",children:(0,s.jsx)(R.CloudCodeMonsterPresetPreview,{preset:l,className:"size-11"})})]}),(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:I.CLOUD_CODE_MONSTER_PET_PRESETS.map(e=>{let t=e.id===l.id;return(0,s.jsxs)("button",{type:"button","aria-pressed":t,onClick:()=>{n((0,I.writeCloudCodeMonsterPetPresetId)(e.id))},className:(0,r.cn)("group grid h-28 min-w-0 grid-rows-[1fr_auto] rounded-md border bg-card/60 p-2 text-left transition-all hover:border-foreground/20 hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",t?"border-primary/50 bg-accent text-foreground":"border-border/50 text-muted-foreground"),children:[(0,s.jsx)("div",{className:"grid place-items-center rounded bg-background/70 ring-1 ring-border/35",children:(0,s.jsx)(R.CloudCodeMonsterPresetPreview,{preset:e,className:"size-14 transition-transform duration-200 group-hover:scale-105"})}),(0,s.jsxs)("div",{className:"mt-1.5 flex min-w-0 items-center justify-between gap-1 text-[10px] leading-none",children:[(0,s.jsx)("span",{className:"truncate font-medium text-foreground",children:e.name}),t?(0,s.jsx)(z,{className:"size-3 shrink-0 text-primary"}):(0,s.jsx)("span",{className:"shrink-0 text-muted-foreground",children:e.id.replace("pet-","#")})]})]},e.id)})})]}):null]})}var A=e.i(355578),D=e.i(934351),L=e.i(875061);let W=(0,k.default)("bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]);var U=e.i(896210),B=e.i(392277);let H=(0,k.default)("users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]]);var q=e.i(646769);let G=(0,k.default)("zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]);function V({icon:e,label:t,value:a,sub:r}){return(0,s.jsx)(D.Card,{size:"sm",children:(0,s.jsxs)(D.CardContent,{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"flex size-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary",children:(0,s.jsx)(e,{className:"size-4"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-1",children:[(0,s.jsx)("p",{className:"text-2xl font-semibold leading-none tracking-tight",children:a}),r&&(0,s.jsx)(L.Badge,{variant:"secondary",className:"text-[10px] px-1.5 h-4 font-normal",children:r})]}),(0,s.jsx)("p",{className:"mt-1 text-xs text-muted-foreground truncate",children:t})]})]})})}function J({agents:e,runtimes:t,activeTaskCounts:a,overview:r}){let i=new Map;for(let e of t){let s=e.daemon_id??e.id;i.set(s,i.get(s)||"online"===e.status)}let n=i.size,l=[...i.values()].filter(Boolean).length,c=Object.values(a).reduce((e,s)=>e+s,0),d=e.filter(e=>{let s=t.find(s=>s.id===e.runtime_id);return s?.status==="online"}).length;return(0,s.jsxs)("div",{className:"grid gap-3 grid-cols-2 sm:grid-cols-3 lg:grid-cols-6",children:[(0,s.jsx)(V,{icon:q.Monitor,label:"Machines",value:`${l}/${n}`,sub:"online"}),(0,s.jsx)(V,{icon:W,label:"Agents",value:e.length,sub:`${d} online`}),(0,s.jsx)(V,{icon:H,label:"Members",value:r.members.length,sub:r.pending_invites>0?`${r.pending_invites} pending`:void 0}),(0,s.jsx)(V,{icon:G,label:"Active Tasks",value:c,sub:r.task_stats.queued>0?`${r.task_stats.queued} queued`:void 0}),(0,s.jsx)(V,{icon:B.Send,label:"Emails Sent",value:r.email_stats.outbound,sub:`${r.email_stats.unread} unread`}),(0,s.jsx)(V,{icon:U.Mail,label:"Custom Emails",value:r.email_accounts.length})]})}function K({overview:e}){let{completed:t,failed:a,cancelled:r,queued:i,stale:n}=e.task_stats,l=t+a,c=l>0?(a/l*100).toFixed(1):"0";return(0,s.jsxs)(D.Card,{children:[(0,s.jsx)(D.CardHeader,{children:(0,s.jsx)(D.CardTitle,{children:"Task Health (Today)"})}),(0,s.jsx)(D.CardContent,{children:(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,s.jsx)(Q,{label:"Completed",value:t}),(0,s.jsx)(Q,{label:"Failed",value:a,className:a>0?"text-destructive":void 0}),(0,s.jsx)(Q,{label:"Cancelled",value:r}),(0,s.jsx)(Q,{label:"Failure Rate",value:`${c}%`,className:Number(c)>10?"text-destructive":void 0}),(0,s.jsx)(Q,{label:"Queue Backlog",value:i,className:i>10?"text-amber-500":void 0}),(0,s.jsx)(Q,{label:"Stale Tasks",value:n,className:n>0?"text-destructive":void 0})]})})]})}function Q({label:e,value:t,className:a}){return(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:`text-xl font-semibold ${a??""}`,children:t}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:e})]})}function Y({overview:e,agents:t}){let{inbound:a,outbound:r,unread:i,rejected:n}=e.email_stats,l=new Map(t.map(e=>[e.id,e.name]));return(0,s.jsxs)(D.Card,{children:[(0,s.jsx)(D.CardHeader,{children:(0,s.jsx)(D.CardTitle,{children:"Email Summary"})}),(0,s.jsxs)(D.CardContent,{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xl font-semibold",children:a}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Received"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xl font-semibold",children:r}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Sent"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:`text-xl font-semibold ${i>0?"text-primary":""}`,children:i}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Unread"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:`text-xl font-semibold ${n>0?"text-amber-500":""}`,children:n}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Untrust"})]})]}),e.email_accounts.length>0&&(0,s.jsxs)("div",{className:"space-y-2 pt-2 border-t border-border/50",children:[(0,s.jsx)("p",{className:"text-xs font-medium text-muted-foreground",children:"Custom Mailboxes"}),e.email_accounts.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 text-xs",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)("span",{className:`size-1.5 shrink-0 rounded-full ${"active"===e.status?"bg-emerald-500":"bg-destructive"}`})}),(0,s.jsx)(C.TooltipContent,{side:"top",children:"active"===e.status?"Active":`Error: ${e.error_message||"inactive"}`})]}),(0,s.jsx)("span",{className:"truncate",children:e.email_address})]}),(0,s.jsx)("span",{className:"text-muted-foreground shrink-0",children:l.get(e.agent_id)??"—"})]},e.id))]})]})]})}var Z=e.i(345262);function X({runtimes:e,agents:t}){let a=(0,n.useRouter)(),{slug:r}=(0,l.useWorkspace)(),i=new Map;for(let s of e){let e=s.daemon_id??s.id;i.has(e)||i.set(e,{runtimes:[],deviceInfo:s.device_info??""}),i.get(e).runtimes.push(s)}let c=[...i.entries()];return 0===c.length?(0,s.jsxs)(D.Card,{children:[(0,s.jsxs)(D.CardHeader,{children:[(0,s.jsx)(D.CardTitle,{children:"Machines"}),(0,s.jsx)(D.CardAction,{children:(0,s.jsx)("button",{type:"button",onClick:()=>a.push(`/w/${r}/runtimes`),className:"text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:(0,s.jsx)(Z.ArrowUpRight,{className:"size-4"})})})]}),(0,s.jsx)(D.CardContent,{children:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"No machines connected."})})]}):(0,s.jsxs)(D.Card,{children:[(0,s.jsx)(D.CardHeader,{children:(0,s.jsx)(D.CardTitle,{children:"Machines"})}),(0,s.jsx)(D.CardContent,{className:"space-y-3",children:c.map(([e,a])=>{let r=a.runtimes.some(e=>"online"===e.status),i=a.runtimes.map(e=>e.last_seen_at).filter(Boolean).sort().reverse()[0],n=t.filter(e=>a.runtimes.some(s=>s.id===e.runtime_id)),l=a.runtimes.some(e=>e.pending_update_version),c=a.runtimes.find(e=>e.pending_update_version)?.pending_update_version;return(0,s.jsxs)("div",{className:"flex items-start gap-3 text-xs",children:[(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)("span",{className:`mt-1 size-2 shrink-0 rounded-full ${r?"bg-emerald-500":"bg-muted-foreground/30"}`})}),(0,s.jsx)(C.TooltipContent,{side:"top",children:r?"Online":"Offline"})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium truncate",children:a.deviceInfo||e.slice(0,12)}),l&&(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)("span",{children:(0,s.jsx)(L.Badge,{variant:"outline",className:"text-[10px] px-1.5 py-0 text-amber-500 border-amber-500/30",children:"update"})})}),(0,s.jsxs)(C.TooltipContent,{side:"top",children:["Pending update to v",c]})]})]}),(0,s.jsxs)("div",{className:"text-muted-foreground mt-0.5",children:[n.length>0?n.map(e=>e.name).join(", "):"No agents"," · ",function(e){if(!e)return"never";let s=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(s<60)return`${s}s ago`;let t=Math.floor(s/60);if(t<60)return`${t}m ago`;let a=Math.floor(t/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}(i??null)]})]})]},e)})})]})}function ee({overview:e}){let t=(0,n.useRouter)(),{slug:a}=(0,l.useWorkspace)(),{members:r,pending_invites:i}=e;return(0,s.jsxs)(D.Card,{children:[(0,s.jsxs)(D.CardHeader,{children:[(0,s.jsx)(D.CardAction,{children:(0,s.jsx)("button",{type:"button",onClick:()=>t.push(`/w/${a}/settings`),className:"text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:(0,s.jsx)(Z.ArrowUpRight,{className:"size-4"})})}),(0,s.jsxs)(D.CardTitle,{children:["Team",i>0&&(0,s.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground font-normal",children:["(",i," pending invite",i>1?"s":"",")"]})]})]}),(0,s.jsx)(D.CardContent,{className:"p-0",children:(0,s.jsx)("div",{className:"divide-y divide-border/50",children:[...r].sort((e,s)=>"owner"===e.role?-1:+("owner"===s.role)).map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2.5",children:[e.image?(0,s.jsx)("img",{src:e.image,alt:e.name,className:"size-7 rounded-full shrink-0"}):(0,s.jsx)("div",{className:"flex size-7 shrink-0 items-center justify-center rounded-full bg-secondary text-xs font-medium",children:(e.name||e.email).charAt(0).toUpperCase()}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("span",{className:"text-sm font-medium truncate block",children:e.name||e.email}),e.name&&(0,s.jsx)("span",{className:"text-xs text-muted-foreground truncate block",children:e.email})]}),(0,s.jsx)(L.Badge,{variant:"owner"===e.role?"default":"secondary",className:"text-[10px] px-1.5 py-0 shrink-0",children:e.role})]},e.id))})})]})}function es(){let{agents:e,runtimes:a,loading:r,activeTaskCounts:i}=(0,A.useAgentContext)(),{workspaceId:n}=(0,l.useWorkspace)(),[c,o]=(0,t.useState)(null),[m,u]=(0,t.useState)(!1);return((0,t.useEffect)(()=>{if(r)return;let e=!1;return u(!0),(0,d.getWorkspaceOverview)(n).then(s=>{e||o(s)}).catch(()=>{}).finally(()=>{e||u(!1)}),()=>{e=!0}},[r,n]),m||!c)?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)(x.Skeleton,{className:"h-44 rounded-xl"}),(0,s.jsx)(x.Skeleton,{className:"h-44 rounded-xl"}),(0,s.jsx)(x.Skeleton,{className:"h-44 rounded-xl"}),(0,s.jsx)(x.Skeleton,{className:"h-44 rounded-xl"})]}):(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)(J,{agents:e,runtimes:a,activeTaskCounts:i,overview:c}),(0,s.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,s.jsx)(K,{overview:c}),(0,s.jsx)(Y,{overview:c,agents:e})]}),(0,s.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,s.jsx)(X,{runtimes:a,agents:e}),(0,s.jsx)(ee,{overview:c})]})]})}let et=[{id:"general",label:"General"},{id:"pet",label:"Pet"},{id:"instruction",label:"Global Instruction"},{id:"notifications",label:"Notifications"},{id:"members",label:"Members"},{id:"usages",label:"Usages"}];e.s(["default",0,function(){let[e,i]=(0,t.useState)("general");return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex items-center justify-between border-b border-border/50 px-3 md:px-5 py-2.5 gap-3",children:(0,s.jsx)("div",{className:"flex items-center gap-3 min-w-0",children:(0,s.jsx)("h1",{className:"text-sm font-medium",children:"Settings"})})}),(0,s.jsxs)("div",{className:"flex flex-1 min-h-0",children:[(0,s.jsxs)("nav",{className:"w-48 shrink-0 border-r border-border/50 py-3 px-2 hidden md:flex md:flex-col",children:[(0,s.jsx)("div",{className:"flex-1",children:et.map(t=>(0,s.jsx)("button",{onClick:()=>i(t.id),className:(0,r.cn)("w-full rounded-md px-2.5 py-1.5 text-left text-sm transition-colors",e===t.id?"bg-accent text-foreground font-medium":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:t.label},t.id))}),(0,s.jsxs)("div",{className:"px-2.5 pt-3 border-t border-border/50 text-[11px] text-muted-foreground/60",children:["v","0.0.136"]})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,s.jsx)("div",{className:"px-4 pt-2 md:hidden",children:(0,s.jsx)(a.Tabs,{className:"items-center",value:e,onValueChange:e=>i(e),children:(0,s.jsx)(a.TabsList,{className:"h-auto gap-1",children:et.map(e=>(0,s.jsx)(a.TabsTrigger,{value:e.id,children:e.label},e.id))})})}),(0,s.jsx)("div",{className:(0,r.cn)("flex-1 overflow-y-auto thin-scrollbar","instruction"!==e&&"px-5 py-5"),children:"instruction"===e?(0,s.jsx)(v,{}):"usages"===e?(0,s.jsx)(es,{}):(0,s.jsxs)("div",{className:"mx-auto max-w-md",children:["general"===e&&(0,s.jsx)(f,{}),"pet"===e&&(0,s.jsx)(F,{}),"notifications"===e&&(0,s.jsx)(P,{}),"members"===e&&(0,s.jsx)(S,{})]})}),(0,s.jsxs)("div",{className:"px-4 py-2 text-[11px] text-muted-foreground/60 md:hidden",children:["v","0.0.136"]})]})]})]})}],716032)}]);
1
+ (globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,716032,e=>{"use strict";e.i(811374);var s=e.i(653772),t=e.i(511043),a=e.i(255334),r=e.i(613349),i=e.i(516266),n=e.i(126942),l=e.i(500324),c=e.i(23055),d=e.i(222862),o=e.i(186339),m=e.i(903477),u=e.i(473131),x=e.i(728886),h=e.i(553617),p=e.i(205189);function f(){let{workspaceId:e,slug:a}=(0,l.useWorkspace)(),r=(0,c.useSession)(),f=(0,n.useRouter)(),[g,j]=(0,t.useState)(""),[v,N]=(0,t.useState)(!0),[b,y]=(0,t.useState)(""),[k,w]=(0,t.useState)(""),[C,T]=(0,t.useState)(""),[S,E]=(0,t.useState)(""),[_,M]=(0,t.useState)(!1),[P,z]=(0,t.useState)({}),[I,O]=(0,t.useState)(""),[R,$]=(0,t.useState)(!1),F=(0,t.useCallback)(async()=>{N(!0);try{let s=r.data?.user?.id,[t,a]=await Promise.all([(0,d.listMembers)(e),(0,d.listWorkspaces)()]),i=t.find(e=>e.user_id===s);j(i?.role??"");let n=a.find(s=>s.id===e);n&&(y(n.name),w(n.slug),T(n.name),E(n.slug))}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to load workspace info")}finally{N(!1)}},[e,r.data?.user?.id]);(0,t.useEffect)(()=>{r.data&&F()},[F,r.data]);let A=b!==C||k!==S,D=async()=>{let s=(0,h.validateWorkspaceForm)({name:b,slug:k});if(z(s),!(0,h.hasWorkspaceFormErrors)(s)){M(!0);try{let s=await (0,d.updateWorkspace)(e,{name:b.trim(),slug:k.trim()});(0,p.trackSettingsUpdated)({setting_tab:"general"}),T(s.name),E(s.slug),i.toast.success("Workspace updated"),s.slug!==a&&f.replace(`/w/${s.slug}/settings`)}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to update workspace")}finally{M(!1)}}},L=async()=>{if(I===C){$(!0);try{await (0,d.deleteWorkspace)(e,C),i.toast.success("Workspace deleted"),f.replace("/workspaces")}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to delete workspace")}finally{$(!1)}}};return v?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)(x.Skeleton,{className:"h-4 w-32"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"})]}):"owner"!==g?(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Only workspace owners can edit workspace settings."}):(0,s.jsxs)("div",{className:"space-y-10",children:[(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Workspace"}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(u.Label,{htmlFor:"workspace-name",children:"Name"}),(0,s.jsx)(m.Input,{id:"workspace-name",value:b,onChange:e=>{let s=e.target.value;y(s),P.name&&s.trim()&&z(e=>({...e,name:void 0}))},placeholder:"Workspace name","aria-invalid":!!P.name,"aria-describedby":P.name?"workspace-name-error":void 0}),P.name&&(0,s.jsx)("p",{id:"workspace-name-error",className:"text-xs text-destructive",children:P.name})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(u.Label,{htmlFor:"workspace-slug",children:"Slug"}),(0,s.jsx)(m.Input,{id:"workspace-slug",value:k,onChange:e=>{let s=e.target.value;w(s),P.slug&&s.trim()&&z(e=>({...e,slug:void 0}))},placeholder:"workspace-slug","aria-invalid":!!P.slug,"aria-describedby":P.slug?"workspace-slug-error":void 0}),P.slug&&(0,s.jsx)("p",{id:"workspace-slug-error",className:"text-xs text-destructive",children:P.slug}),(0,s.jsxs)("p",{className:"text-xs text-muted-foreground/70",children:["Used in URLs: /w/",k,"/"]})]})]}),(0,s.jsx)(o.Button,{size:"sm",onClick:D,disabled:!A||_,children:_?"Saving…":"Save"})]}),(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsx)("h2",{className:"text-sm font-medium text-destructive",children:"Danger Zone"}),(0,s.jsxs)("div",{className:"rounded-md border border-destructive/30 p-4 space-y-3",children:[(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Deleting this workspace is permanent and cannot be undone. All agents, conversations, and data will be lost."}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsxs)(u.Label,{htmlFor:"delete-confirm",className:"text-xs",children:["Type ",(0,s.jsx)("span",{className:"font-medium text-foreground",children:C})," to confirm"]}),(0,s.jsx)(m.Input,{id:"delete-confirm",value:I,onChange:e=>O(e.target.value),placeholder:C})]}),(0,s.jsx)(o.Button,{size:"sm",variant:"destructive",onClick:L,disabled:I!==C||R,children:R?"Deleting…":"Delete Workspace"})]})]})]})}var g=e.i(740513);function j({ratio:e,size:t=16,stroke:a=1.5}){let i=(t-a)/2,n=2*Math.PI*i,l=(e<=0?0:e>=1?1:Math.log1p(99*e)/Math.log(100))*n;return(0,s.jsxs)("svg",{width:t,height:t,className:"shrink-0 -rotate-90","aria-hidden":!0,children:[(0,s.jsx)("circle",{cx:t/2,cy:t/2,r:i,fill:"none",stroke:"currentColor",strokeWidth:a,className:"text-border"}),(0,s.jsx)("circle",{cx:t/2,cy:t/2,r:i,fill:"none",stroke:"currentColor",strokeWidth:a,strokeDasharray:`${l} ${n-l}`,strokeLinecap:"round",className:(0,r.cn)("transition-all duration-300",e>.9?"text-destructive/70":e>.7?"text-yellow-500/50":"text-muted-foreground/30")})]})}function v(){let{workspaceId:e}=(0,l.useWorkspace)(),[a,r]=(0,t.useState)(""),[n,c]=(0,t.useState)(""),[o,m]=(0,t.useState)(!0),u=(0,t.useRef)(a);(0,t.useEffect)(()=>{u.current=a},[a]);let h=(0,t.useRef)(n);(0,t.useEffect)(()=>{h.current=n},[n]);let p=(0,t.useRef)(null),f=(0,t.useRef)(!1),v=(0,t.useCallback)(async()=>{m(!0);try{let s=await (0,d.getMemberMe)(e);r(s.global_instruction),c(s.global_instruction)}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to load settings")}finally{m(!1)}},[e]);(0,t.useEffect)(()=>{v()},[v]);let N=(0,t.useRef)(()=>{}),b=(0,t.useCallback)(async()=>{if(f.current)return;let s=u.current;if(s!==h.current){f.current=!0;try{let t=await (0,d.updateMemberMe)(e,s);c(t.global_instruction)}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to save")}finally{f.current=!1,u.current!==h.current&&N.current()}}},[e]),y=(0,t.useCallback)(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(b,500)},[b]);(0,t.useEffect)(()=>{N.current=y},[y]);let k=(0,t.useCallback)(e=>{r(e),y()},[y]);(0,t.useEffect)(()=>{let s=()=>{if(p.current&&clearTimeout(p.current),u.current!==h.current){let s=new URLSearchParams({workspace_id:e});fetch(`/api/members/me?${s}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({global_instruction:u.current}),keepalive:!0})}};return window.addEventListener("beforeunload",s),()=>window.removeEventListener("beforeunload",s)},[e]),(0,t.useEffect)(()=>()=>{if(p.current&&clearTimeout(p.current),u.current!==h.current){let s=new URLSearchParams({workspace_id:e});fetch(`/api/members/me?${s}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({global_instruction:u.current}),keepalive:!0})}},[e]);let w=a.length/5e4;return o?(0,s.jsxs)("div",{className:"px-6 py-6 space-y-4",children:[(0,s.jsx)(x.Skeleton,{className:"h-4 w-48"}),(0,s.jsx)(x.Skeleton,{className:"h-40 w-full"})]}):(0,s.jsxs)("div",{className:"flex flex-col h-full",children:[(0,s.jsx)("div",{className:"flex-1 px-6 pt-4 pb-4",children:(0,s.jsx)(g.MarkdownEditor,{value:a,onChange:k,placeholder:"Write instructions that every agent you own will follow...",minHeight:"calc(100vh - 240px)",contentType:"markdown",variant:"seamless"})}),(0,s.jsxs)("div",{className:"flex items-center gap-2 px-6 py-3",children:[(0,s.jsx)(j,{ratio:w}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"This instruction is prepended to every agent's individual instruction."})]})]})}var N=e.i(330746),b=e.i(813141),y=e.i(947308),k=e.i(419412);let w=(0,k.default)("user-minus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);var C=e.i(329686);function T(e){return`${window.location.origin}/invite/${e}`}function S(){let{workspaceId:e}=(0,l.useWorkspace)(),a=(0,c.useSession)(),n=a.data?.user?.id,[m,u]=(0,t.useState)([]),[h,f]=(0,t.useState)([]),[g,j]=(0,t.useState)(!0),[v,k]=(0,t.useState)(!1),S=m.find(e=>e.user_id===n)?.role==="owner",E=(0,t.useCallback)(async()=>{j(!0);try{let[s,t]=await Promise.all([(0,d.listMembers)(e),(0,d.listInvites)(e).catch(()=>[])]);u(s),f(t)}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to load members")}finally{j(!1)}},[e]);(0,t.useEffect)(()=>{E()},[E]);let _=async()=>{k(!0);try{let s=await (0,d.createInvite)(e);(0,p.trackTeamMemberInvited)({workspace_id:e}),f(e=>[...e,s]);let t=T(s.token);await navigator.clipboard.writeText(t),i.toast.success("Invite link copied to clipboard")}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to generate invite")}finally{k(!1)}},M=async e=>{let s=T(e);try{await navigator.clipboard.writeText(s),i.toast.success("Invite link copied")}catch{i.toast.error("Failed to copy link")}},P=async s=>{try{await (0,d.revokeInvite)(e,s),f(e=>e.filter(e=>e.id!==s)),i.toast.success("Invite revoked")}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to revoke invite")}},z=async s=>{try{await (0,d.removeMember)(e,s),u(e=>e.filter(e=>e.id!==s)),i.toast.success("Member removed")}catch(e){i.toast.error(e instanceof Error?e.message:"Failed to remove member")}};return g?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)(x.Skeleton,{className:"h-4 w-24"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"}),(0,s.jsx)(x.Skeleton,{className:"h-4 w-24 mt-6"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"}),(0,s.jsx)(x.Skeleton,{className:"h-10 w-full"})]}):(0,s.jsxs)("div",{className:"space-y-8",children:[S&&(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Pending Invites"}),(0,s.jsxs)(o.Button,{size:"sm",variant:"outline",onClick:_,disabled:v,children:[(0,s.jsx)(y.Plus,{className:"size-3.5 mr-1"}),v?"Generating…":"Generate invite link"]})]}),0===h.length?(0,s.jsx)("p",{className:"text-xs text-muted-foreground py-2",children:"No active invite links. Generate one to invite someone to this workspace."}):(0,s.jsx)("div",{className:"space-y-1.5",children:h.map(e=>{let t=new Date(e.expires_at),a=t<new Date;return(0,s.jsxs)("div",{className:"flex items-center justify-between rounded-md border border-border/50 px-3 py-2 text-xs",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("p",{className:(0,r.cn)("font-mono truncate",a&&"text-muted-foreground line-through"),children:["/invite/",e.token.slice(0,12),"…"]}),(0,s.jsx)("p",{className:(0,r.cn)("text-muted-foreground/70 mt-0.5",a&&"text-destructive/70"),children:a?"Expired":`Expires ${t.toLocaleDateString()}`})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 ml-2 shrink-0",children:[!a&&(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)(o.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>M(e.token)}),children:(0,s.jsx)(N.Copy,{className:"size-3.5"})}),(0,s.jsx)(C.TooltipContent,{children:"Copy invite link"})]}),(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)(o.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",onClick:()=>P(e.id)}),children:(0,s.jsx)(b.Trash2,{className:"size-3.5"})}),(0,s.jsx)(C.TooltipContent,{children:"Revoke invite"})]})]})]},e.id)})})]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Members"}),(0,s.jsx)("div",{className:"space-y-1.5",children:m.map(e=>{let t=e.user_id===n,a=e.name?e.name.split(" ").map(e=>e[0]).join("").slice(0,2).toUpperCase():e.email.slice(0,2).toUpperCase();return(0,s.jsxs)("div",{className:"flex items-center gap-3 rounded-md border border-border/50 px-3 py-2",children:[(0,s.jsx)("div",{className:"size-7 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground shrink-0 overflow-hidden",children:e.image?(0,s.jsx)("img",{src:e.image,alt:e.name,className:"size-full object-cover"}):a}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("p",{className:"text-sm font-medium truncate leading-tight",children:[e.name||e.email,t&&(0,s.jsx)("span",{className:"ml-1.5 text-xs text-muted-foreground font-normal",children:"(you)"})]}),e.name&&(0,s.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:e.email})]}),(0,s.jsx)("span",{className:(0,r.cn)("text-xs px-1.5 py-0.5 rounded shrink-0","owner"===e.role?"bg-primary/10 text-primary":"bg-muted text-muted-foreground"),children:e.role}),S&&!t&&(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)(o.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-muted-foreground hover:text-destructive shrink-0",onClick:()=>z(e.id)}),children:(0,s.jsx)(w,{className:"size-3.5"})}),(0,s.jsx)(C.TooltipContent,{children:"Remove member"})]})]},e.id)})})]})]})}var E=e.i(885515),_=e.i(254618),M=e.i(899746);function P(){let[e,a]=(0,t.useState)(!1),[r,n]=(0,t.useState)([...M.NOTIFICATION_EVENTS]),[l,c]=(0,t.useState)(!0),[d,o]=(0,t.useState)(!1);(0,t.useEffect)(()=>{c((0,M.isNotificationSupported)()),a((0,M.getNotificationEnabled)()),n((0,M.getNotificationEvents)()),(0,M.isNotificationSupported)()&&o("denied"===Notification.permission)},[]);let m=async e=>{if(!e){a(!1),(0,M.setNotificationEnabled)(!1);return}await (0,M.requestNotificationPermission)()?(a(!0),(0,M.setNotificationEnabled)(!0)):(o(!0),i.toast.error("Notification permission denied. Please enable it in browser settings."))};return l?(0,s.jsx)("div",{className:"space-y-6",children:(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Browser Notifications"}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"space-y-0.5",children:[(0,s.jsx)("p",{className:"text-sm",children:"Enable notifications"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Get notified when tasks finish while the tab is in the background"})]}),(0,s.jsx)(_.Switch,{checked:e,onCheckedChange:m,disabled:d&&!e})]}),d&&!e&&(0,s.jsx)("p",{className:"text-xs text-destructive",children:"Notification permission was denied. Please allow it in your browser settings."}),e&&(0,s.jsxs)("div",{className:"space-y-2 pl-0.5",children:[(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Notify me when:"}),M.NOTIFICATION_EVENTS.map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-2 text-sm cursor-pointer select-none",children:[(0,s.jsx)(E.Checkbox,{checked:r.includes(e),onCheckedChange:()=>{n(s=>{let t=s.includes(e)?s.filter(s=>s!==e):[...s,e];return(0,M.setNotificationEvents)(t),t})}}),M.NOTIFICATION_EVENT_LABELS[e]]},e))]})]})]})}):(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Your browser does not support notifications."})}let z=(0,k.default)("sparkles",[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]]);var I=e.i(399561),O=e.i(460520),R=e.i(961909),$=e.i(790961);function F(){let[e,a]=(0,t.useState)(!1),[i,n]=(0,t.useState)(I.CLOUD_CODE_MONSTER_PET_PRESETS[0].id),l=(0,I.getCloudCodeMonsterPreset)(i);return(0,t.useEffect)(()=>{a((0,$.readHomePetSettings)().enabled),n((0,I.readCloudCodeMonsterPetPresetId)());let e=e=>{let s=e.detail?.presetId;n(s?(0,I.getCloudCodeMonsterPreset)(s).id:(0,I.readCloudCodeMonsterPetPresetId)())};return window.addEventListener(O.CLOUD_CODE_MONSTER_PRESET_CHANGED_EVENT,e),()=>{window.removeEventListener(O.CLOUD_CODE_MONSTER_PRESET_CHANGED_EVENT,e)}},[]),(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Pet"}),(0,s.jsx)("div",{className:"space-y-4",children:(0,s.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,s.jsxs)("div",{className:"space-y-0.5",children:[(0,s.jsx)(u.Label,{htmlFor:"pet-enabled",className:"text-sm",children:"Enable pet"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Off by default. Turn it on when you want the workspace companion."})]}),(0,s.jsx)(_.Switch,{id:"pet-enabled",checked:e,onCheckedChange:e=>{a(e),(0,$.writeHomePetSettings)({enabled:e})}})]})})]}),e?(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-medium",children:"Preset"}),(0,s.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:l.name})]}),(0,s.jsx)("div",{className:"grid size-14 place-items-center rounded-md bg-card ring-1 ring-border/60",children:(0,s.jsx)(R.CloudCodeMonsterPresetPreview,{preset:l,className:"size-11"})})]}),(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:I.CLOUD_CODE_MONSTER_PET_PRESETS.map(e=>{let t=e.id===l.id;return(0,s.jsxs)("button",{type:"button","aria-pressed":t,onClick:()=>{n((0,I.writeCloudCodeMonsterPetPresetId)(e.id))},className:(0,r.cn)("group grid h-28 min-w-0 grid-rows-[1fr_auto] rounded-md border bg-card/60 p-2 text-left transition-all hover:border-foreground/20 hover:bg-accent/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",t?"border-primary/50 bg-accent text-foreground":"border-border/50 text-muted-foreground"),children:[(0,s.jsx)("div",{className:"grid place-items-center rounded bg-background/70 ring-1 ring-border/35",children:(0,s.jsx)(R.CloudCodeMonsterPresetPreview,{preset:e,className:"size-14 transition-transform duration-200 group-hover:scale-105"})}),(0,s.jsxs)("div",{className:"mt-1.5 flex min-w-0 items-center justify-between gap-1 text-[10px] leading-none",children:[(0,s.jsx)("span",{className:"truncate font-medium text-foreground",children:e.name}),t?(0,s.jsx)(z,{className:"size-3 shrink-0 text-primary"}):(0,s.jsx)("span",{className:"shrink-0 text-muted-foreground",children:e.id.replace("pet-","#")})]})]},e.id)})})]}):null]})}var A=e.i(355578),D=e.i(934351),L=e.i(875061);let W=(0,k.default)("bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]);var U=e.i(896210),B=e.i(392277);let H=(0,k.default)("users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]]);var q=e.i(646769);let G=(0,k.default)("zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]);function V({icon:e,label:t,value:a,sub:r}){return(0,s.jsx)(D.Card,{size:"sm",children:(0,s.jsxs)(D.CardContent,{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"flex size-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary",children:(0,s.jsx)(e,{className:"size-4"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-1",children:[(0,s.jsx)("p",{className:"text-2xl font-semibold leading-none tracking-tight",children:a}),r&&(0,s.jsx)(L.Badge,{variant:"secondary",className:"text-[10px] px-1.5 h-4 font-normal",children:r})]}),(0,s.jsx)("p",{className:"mt-1 text-xs text-muted-foreground truncate",children:t})]})]})})}function J({agents:e,runtimes:t,activeTaskCounts:a,overview:r}){let i=new Map;for(let e of t){let s=e.daemon_id??e.id;i.set(s,i.get(s)||"online"===e.status)}let n=i.size,l=[...i.values()].filter(Boolean).length,c=Object.values(a).reduce((e,s)=>e+s,0),d=e.filter(e=>{let s=t.find(s=>s.id===e.runtime_id);return s?.status==="online"}).length;return(0,s.jsxs)("div",{className:"grid gap-3 grid-cols-2 sm:grid-cols-3 lg:grid-cols-6",children:[(0,s.jsx)(V,{icon:q.Monitor,label:"Machines",value:`${l}/${n}`,sub:"online"}),(0,s.jsx)(V,{icon:W,label:"Agents",value:e.length,sub:`${d} online`}),(0,s.jsx)(V,{icon:H,label:"Members",value:r.members.length,sub:r.pending_invites>0?`${r.pending_invites} pending`:void 0}),(0,s.jsx)(V,{icon:G,label:"Active Tasks",value:c,sub:r.task_stats.queued>0?`${r.task_stats.queued} queued`:void 0}),(0,s.jsx)(V,{icon:B.Send,label:"Emails Sent",value:r.email_stats.outbound,sub:`${r.email_stats.unread} unread`}),(0,s.jsx)(V,{icon:U.Mail,label:"Custom Emails",value:r.email_accounts.length})]})}function K({overview:e}){let{completed:t,failed:a,cancelled:r,queued:i,stale:n}=e.task_stats,l=t+a,c=l>0?(a/l*100).toFixed(1):"0";return(0,s.jsxs)(D.Card,{children:[(0,s.jsx)(D.CardHeader,{children:(0,s.jsx)(D.CardTitle,{children:"Task Health (Today)"})}),(0,s.jsx)(D.CardContent,{children:(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,s.jsx)(Q,{label:"Completed",value:t}),(0,s.jsx)(Q,{label:"Failed",value:a,className:a>0?"text-destructive":void 0}),(0,s.jsx)(Q,{label:"Cancelled",value:r}),(0,s.jsx)(Q,{label:"Failure Rate",value:`${c}%`,className:Number(c)>10?"text-destructive":void 0}),(0,s.jsx)(Q,{label:"Queue Backlog",value:i,className:i>10?"text-amber-500":void 0}),(0,s.jsx)(Q,{label:"Stale Tasks",value:n,className:n>0?"text-destructive":void 0})]})})]})}function Q({label:e,value:t,className:a}){return(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:`text-xl font-semibold ${a??""}`,children:t}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:e})]})}function Y({overview:e,agents:t}){let{inbound:a,outbound:r,unread:i,rejected:n}=e.email_stats,l=new Map(t.map(e=>[e.id,e.name]));return(0,s.jsxs)(D.Card,{children:[(0,s.jsx)(D.CardHeader,{children:(0,s.jsx)(D.CardTitle,{children:"Email Summary"})}),(0,s.jsxs)(D.CardContent,{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xl font-semibold",children:a}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Received"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xl font-semibold",children:r}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Sent"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:`text-xl font-semibold ${i>0?"text-primary":""}`,children:i}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Unread"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:`text-xl font-semibold ${n>0?"text-amber-500":""}`,children:n}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Untrust"})]})]}),e.email_accounts.length>0&&(0,s.jsxs)("div",{className:"space-y-2 pt-2 border-t border-border/50",children:[(0,s.jsx)("p",{className:"text-xs font-medium text-muted-foreground",children:"Custom Mailboxes"}),e.email_accounts.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 text-xs",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)("span",{className:`size-1.5 shrink-0 rounded-full ${"active"===e.status?"bg-emerald-500":"bg-destructive"}`})}),(0,s.jsx)(C.TooltipContent,{side:"top",children:"active"===e.status?"Active":`Error: ${e.error_message||"inactive"}`})]}),(0,s.jsx)("span",{className:"truncate",children:e.email_address})]}),(0,s.jsx)("span",{className:"text-muted-foreground shrink-0",children:l.get(e.agent_id)??"—"})]},e.id))]})]})]})}var Z=e.i(345262);function X({runtimes:e,agents:t}){let a=(0,n.useRouter)(),{slug:r}=(0,l.useWorkspace)(),i=new Map;for(let s of e){let e=s.daemon_id??s.id;i.has(e)||i.set(e,{runtimes:[],deviceInfo:s.device_info??""}),i.get(e).runtimes.push(s)}let c=[...i.entries()];return 0===c.length?(0,s.jsxs)(D.Card,{children:[(0,s.jsxs)(D.CardHeader,{children:[(0,s.jsx)(D.CardTitle,{children:"Machines"}),(0,s.jsx)(D.CardAction,{children:(0,s.jsx)("button",{type:"button",onClick:()=>a.push(`/w/${r}/runtimes`),className:"text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:(0,s.jsx)(Z.ArrowUpRight,{className:"size-4"})})})]}),(0,s.jsx)(D.CardContent,{children:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"No machines connected."})})]}):(0,s.jsxs)(D.Card,{children:[(0,s.jsx)(D.CardHeader,{children:(0,s.jsx)(D.CardTitle,{children:"Machines"})}),(0,s.jsx)(D.CardContent,{className:"space-y-3",children:c.map(([e,a])=>{let r=a.runtimes.some(e=>"online"===e.status),i=a.runtimes.map(e=>e.last_seen_at).filter(Boolean).sort().reverse()[0],n=t.filter(e=>a.runtimes.some(s=>s.id===e.runtime_id)),l=a.runtimes.some(e=>e.pending_update_version),c=a.runtimes.find(e=>e.pending_update_version)?.pending_update_version;return(0,s.jsxs)("div",{className:"flex items-start gap-3 text-xs",children:[(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)("span",{className:`mt-1 size-2 shrink-0 rounded-full ${r?"bg-emerald-500":"bg-muted-foreground/30"}`})}),(0,s.jsx)(C.TooltipContent,{side:"top",children:r?"Online":"Offline"})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium truncate",children:a.deviceInfo||e.slice(0,12)}),l&&(0,s.jsxs)(C.Tooltip,{children:[(0,s.jsx)(C.TooltipTrigger,{render:(0,s.jsx)("span",{children:(0,s.jsx)(L.Badge,{variant:"outline",className:"text-[10px] px-1.5 py-0 text-amber-500 border-amber-500/30",children:"update"})})}),(0,s.jsxs)(C.TooltipContent,{side:"top",children:["Pending update to v",c]})]})]}),(0,s.jsxs)("div",{className:"text-muted-foreground mt-0.5",children:[n.length>0?n.map(e=>e.name).join(", "):"No agents"," · ",function(e){if(!e)return"never";let s=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(s<60)return`${s}s ago`;let t=Math.floor(s/60);if(t<60)return`${t}m ago`;let a=Math.floor(t/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}(i??null)]})]})]},e)})})]})}function ee({overview:e}){let t=(0,n.useRouter)(),{slug:a}=(0,l.useWorkspace)(),{members:r,pending_invites:i}=e;return(0,s.jsxs)(D.Card,{children:[(0,s.jsxs)(D.CardHeader,{children:[(0,s.jsx)(D.CardAction,{children:(0,s.jsx)("button",{type:"button",onClick:()=>t.push(`/w/${a}/settings`),className:"text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:(0,s.jsx)(Z.ArrowUpRight,{className:"size-4"})})}),(0,s.jsxs)(D.CardTitle,{children:["Team",i>0&&(0,s.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground font-normal",children:["(",i," pending invite",i>1?"s":"",")"]})]})]}),(0,s.jsx)(D.CardContent,{className:"p-0",children:(0,s.jsx)("div",{className:"divide-y divide-border/50",children:[...r].sort((e,s)=>"owner"===e.role?-1:+("owner"===s.role)).map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2.5",children:[e.image?(0,s.jsx)("img",{src:e.image,alt:e.name,className:"size-7 rounded-full shrink-0"}):(0,s.jsx)("div",{className:"flex size-7 shrink-0 items-center justify-center rounded-full bg-secondary text-xs font-medium",children:(e.name||e.email).charAt(0).toUpperCase()}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("span",{className:"text-sm font-medium truncate block",children:e.name||e.email}),e.name&&(0,s.jsx)("span",{className:"text-xs text-muted-foreground truncate block",children:e.email})]}),(0,s.jsx)(L.Badge,{variant:"owner"===e.role?"default":"secondary",className:"text-[10px] px-1.5 py-0 shrink-0",children:e.role})]},e.id))})})]})}function es(){let{agents:e,runtimes:a,loading:r,activeTaskCounts:i}=(0,A.useAgentContext)(),{workspaceId:n}=(0,l.useWorkspace)(),[c,o]=(0,t.useState)(null),[m,u]=(0,t.useState)(!1);return((0,t.useEffect)(()=>{if(r)return;let e=!1;return u(!0),(0,d.getWorkspaceOverview)(n).then(s=>{e||o(s)}).catch(()=>{}).finally(()=>{e||u(!1)}),()=>{e=!0}},[r,n]),m||!c)?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)(x.Skeleton,{className:"h-44 rounded-xl"}),(0,s.jsx)(x.Skeleton,{className:"h-44 rounded-xl"}),(0,s.jsx)(x.Skeleton,{className:"h-44 rounded-xl"}),(0,s.jsx)(x.Skeleton,{className:"h-44 rounded-xl"})]}):(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)(J,{agents:e,runtimes:a,activeTaskCounts:i,overview:c}),(0,s.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,s.jsx)(K,{overview:c}),(0,s.jsx)(Y,{overview:c,agents:e})]}),(0,s.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,s.jsx)(X,{runtimes:a,agents:e}),(0,s.jsx)(ee,{overview:c})]})]})}let et=[{id:"general",label:"General"},{id:"pet",label:"Pet"},{id:"instruction",label:"Global Instruction"},{id:"notifications",label:"Notifications"},{id:"members",label:"Members"},{id:"usages",label:"Usages"}];e.s(["default",0,function(){let[e,i]=(0,t.useState)("general");return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex items-center justify-between border-b border-border/50 px-3 md:px-5 py-2.5 gap-3",children:(0,s.jsx)("div",{className:"flex items-center gap-3 min-w-0",children:(0,s.jsx)("h1",{className:"text-sm font-medium",children:"Settings"})})}),(0,s.jsxs)("div",{className:"flex flex-1 min-h-0",children:[(0,s.jsxs)("nav",{className:"w-48 shrink-0 border-r border-border/50 py-3 px-2 hidden md:flex md:flex-col",children:[(0,s.jsx)("div",{className:"flex-1",children:et.map(t=>(0,s.jsx)("button",{onClick:()=>i(t.id),className:(0,r.cn)("w-full rounded-md px-2.5 py-1.5 text-left text-sm transition-colors",e===t.id?"bg-accent text-foreground font-medium":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:t.label},t.id))}),(0,s.jsxs)("div",{className:"px-2.5 pt-3 border-t border-border/50 text-[11px] text-muted-foreground/60",children:["v","0.0.138"]})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,s.jsx)("div",{className:"px-4 pt-2 md:hidden",children:(0,s.jsx)(a.Tabs,{className:"items-center",value:e,onValueChange:e=>i(e),children:(0,s.jsx)(a.TabsList,{className:"h-auto gap-1",children:et.map(e=>(0,s.jsx)(a.TabsTrigger,{value:e.id,children:e.label},e.id))})})}),(0,s.jsx)("div",{className:(0,r.cn)("flex-1 overflow-y-auto thin-scrollbar","instruction"!==e&&"px-5 py-5"),children:"instruction"===e?(0,s.jsx)(v,{}):"usages"===e?(0,s.jsx)(es,{}):(0,s.jsxs)("div",{className:"mx-auto max-w-md",children:["general"===e&&(0,s.jsx)(f,{}),"pet"===e&&(0,s.jsx)(F,{}),"notifications"===e&&(0,s.jsx)(P,{}),"members"===e&&(0,s.jsx)(S,{})]})}),(0,s.jsxs)("div",{className:"px-4 py-2 text-[11px] text-muted-foreground/60 md:hidden",children:["v","0.0.138"]})]})]})]})}],716032)}]);
@@ -61,4 +61,4 @@ Read more: https://nextjs.org/docs/messages/next-image-unconfigured-localpattern
61
61
  - Every interaction builds trust. Be empathetic, accurate, and efficient — resolve on first response when possible.
62
62
  - Lead with acknowledgment, then solution or clear next steps. Use simple language.
63
63
  - If you can't resolve immediately, set realistic expectations: what you'll do, by when.
64
- - Track open issues proactively. Escalate complex or sensitive cases with full context.`,relationship:"Delegate support tasks with: customer issue summary, urgency level, prior interaction context, and resolution approach.\n\nReport back with: response drafted or sent, resolution status, follow-up schedule, and recurring patterns to flag."}]},{id:"custom",label:"Custom",description:"Build your own team from scratch",icon:"✨",members:[{role:"leader",description:"Coordinates work and replies to you",instructions:y}]}];function b(e){let t=new Set,s=[];for(let r=0;r<e;r++){let e,r=0;do e=(0,g.uniqueNamesGenerator)({dictionaries:[g.names],length:1,style:"capital"}),r++;while(t.has(e)&&r<100)t.add(e),s.push({name:e,avatarUrl:(0,x.serializeAvatarConfig)((0,x.randomConfig)())})}return s}function w({selected:e,onSelect:s,onBrowseTemplates:r}){return(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("h2",{className:"text-base font-semibold tracking-tight",children:"What will your company focus on?"}),r&&(0,t.jsxs)("button",{type:"button",onClick:r,className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2",children:["Browse templates ",(0,t.jsx)("span",{"aria-hidden":"true",children:"›"})]})]}),(0,t.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:v.map(r=>(0,t.jsxs)("button",{onClick:()=>s(r.id),className:(0,f.cn)("flex flex-col items-start gap-1 rounded-lg border p-4 text-left transition-all hover:border-foreground/30",e===r.id?"border-foreground/50 bg-muted/50":"border-border"),children:[(0,t.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,t.jsx)("span",{className:"text-lg",children:r.icon}),(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:[r.members.length," agent",r.members.length>1?"s":""]})]}),(0,t.jsx)("span",{className:"text-sm font-medium",children:r.label}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground leading-tight",children:r.description})]},r.id))})]})}var j=e.i(934351),C=e.i(758870),k=e.i(89110),N=e.i(855372);e.i(954194);var S=e.i(439769);let P={leader:"Lead",researcher:"Researcher",engineer:"Engineer",assistant:"Assistant"};function _({members:e,runtimes:s,onShuffle:r,onAssignRuntime:i}){let n=s.length>1&&i;return(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("h2",{className:"text-base font-semibold tracking-tight",children:"Your company"}),(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",onClick:r,className:"h-7 text-xs gap-1.5",children:[(0,t.jsx)(C.RefreshCw,{className:"size-3"}),"Shuffle"]})]}),(0,t.jsx)("div",{className:(0,f.cn)("grid gap-3 grid-cols-1",2===e.length&&"sm:grid-cols-2",3===e.length&&"sm:grid-cols-2 md:grid-cols-3",e.length>=4&&"sm:grid-cols-2 md:grid-cols-4"),children:e.map((e,r)=>{let a,o=e.avatarUrl?(0,x.parseAvatarUrl)(e.avatarUrl):null;return(0,t.jsxs)(j.Card,{size:"sm",className:"flex flex-col px-3 py-4 gap-2 h-full",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2.5",children:[o?(0,t.jsx)(x.AvatarRenderer,{config:o,size:36,className:"rounded-xl shrink-0"}):(0,t.jsx)("div",{className:"size-9 rounded-xl bg-muted flex items-center justify-center text-sm font-semibold shrink-0",children:e.name.charAt(0)}),(0,t.jsxs)("div",{className:"flex flex-col items-start gap-0.5",children:[(0,t.jsx)("span",{className:"text-sm font-medium",children:e.name}),(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground bg-muted/60 px-1.5 py-0.5 rounded",children:P[e.role]})]})]}),(0,t.jsx)("p",{className:"text-[10px] text-muted-foreground/70 font-mono truncate",children:(0,S.toAlookAddress)(e.emailHandle||e.name.toLowerCase())}),(0,t.jsx)("p",{className:"text-[11px] text-muted-foreground leading-snug flex-1",children:e.description}),n&&(a=s.find(t=>t.id===e.runtimeId),(0,t.jsx)("div",{className:"mt-1",children:(0,t.jsxs)(k.Select,{value:e.runtimeId,onValueChange:e=>{e&&i(r,e)},children:[(0,t.jsx)(k.SelectTrigger,{className:"h-7 text-[11px]",children:(0,t.jsxs)("div",{className:"flex items-center gap-1.5 truncate",children:[a&&(0,t.jsx)(N.ProviderLogo,{provider:a.provider||"",className:"size-3 shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:a?.provider||a?.runtime_mode||"Select"})]})}),(0,t.jsx)(k.SelectContent,{children:s.map(e=>(0,t.jsx)(k.SelectItem,{value:e.id,children:e.provider||e.runtime_mode},e.id))})]})}))]},r)})})]})}var z=e.i(824863),O=e.i(222862),R=e.i(642342),A=e.i(371406);e.s(["StudioOnboardingClient",0,function({workspaceId:e,workspaceSlug:f,workspaceName:g,initialTemplate:x}){let y=(0,r.useRouter)(),[j,C]=(0,s.useState)([]),[k,N]=(0,s.useState)(!0),[S,P]=(0,s.useState)(x?x.baseScenario:null),[L,M]=(0,s.useState)([]),[I,E]=(0,s.useState)(!1),[D,F]=(0,s.useState)(""),[B,H]=(0,s.useState)(!1),[T,U]=(0,s.useState)(!1),[Y,V]=(0,s.useState)(!1),q=(0,z.isTauri)()&&(0,z.isDesktop)(),G=j.filter(e=>"online"===e.status),$=G.length>0;(0,s.useEffect)(()=>{(0,O.listRuntimes)(e).then(e=>{C(e),e.some(e=>"online"===e.status)&&(U(!0),V(!0))}).catch(()=>{}).finally(()=>N(!1))},[e]);let X=(0,s.useCallback)(t=>{"runtime.registered"===t.type&&t.workspaceId===e?(U(!0),V(!0),(0,O.listRuntimes)(e).then(C).catch(()=>{})):"runtime.status"===t.type&&t.workspaceId===e&&(U(!0),"online"===t.status?V(!0):V(!1))},[e]);(0,R.useUserWs)(X);let W=(0,s.useCallback)(async()=>{H(!0);try{let t=await (0,O.createMachineToken)("cli",e);if(F(t.token),q){let s=await (0,z.tauriInvoke)("register_cli",{token:t.token});s.success?(U(!0),V(!0),(0,O.listRuntimes)(e).then(C).catch(()=>{})):d.toast.error(s.message||"Auto-registration failed")}}catch{d.toast.error("Failed to generate token")}finally{H(!1)}},[e,q]);(0,s.useEffect)(()=>{let e=G[0]?.id;e&&M(t=>0!==t.length&&t.some(e=>!e.runtimeId)?t.map(t=>t.runtimeId?t:{...t,runtimeId:e}):t)},[G]);let K=(0,s.useCallback)(async e=>{try{let t=await fetch("/api/studios/check-handles",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({names:e})});if(!t.ok)return null;return await t.json()}catch{return null}},[]);(0,s.useEffect)(()=>{if(!x||k||L.length>0)return;let e=b(x.members.length),t=G[0]?.id||"",s=x.members.map((s,r)=>({name:e[r].name,role:s.role,description:s.description,instructions:s.instructions,avatarUrl:e[r].avatarUrl,runtimeId:t,relationship:s.relationship}));M(s),K(s.map(e=>e.name)).then(e=>{e&&M(t=>t.map(t=>{let s=e.find(e=>e.name===t.name);return s?{...t,emailHandle:s.handle}:t}))})},[x,k]);let Z=async e=>{P(e);let t=v.find(t=>t.id===e),s=b(t.members.length),r=G[0]?.id||"",a=t.members.map((e,t)=>({name:s[t].name,role:e.role,description:e.description,instructions:e.instructions,avatarUrl:s[t].avatarUrl,runtimeId:r,relationship:e.relationship}));M(a);let i=await K(a.map(e=>e.name));i&&M(e=>e.map(e=>{let t=i.find(t=>t.name===e.name);return t?{...e,emailHandle:t.handle}:e}))},J=async()=>{let e=b(L.length),t=L.map((t,s)=>({...t,name:e[s].name,avatarUrl:e[s].avatarUrl,emailHandle:void 0}));M(t);let s=await K(t.map(e=>e.name));s&&M(e=>e.map(e=>{let t=s.find(t=>t.name===e.name);return t?{...e,emailHandle:t.handle}:e}))},Q=async()=>{E(!0);try{let t=await fetch("/api/studios",{method:"POST",headers:{"Content-Type":"application/json","X-Workspace-ID":e},body:JSON.stringify({name:void 0,scenario:S,members:L.map(e=>({name:e.name,role:e.role,runtime_id:e.runtimeId,description:e.description,instructions:e.instructions,avatar_url:e.avatarUrl||null,email_handle:e.emailHandle||void 0,relationship:e.relationship||void 0}))})});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to create company")}let s=await t.json();await fetch(`/api/workspaces/${e}/onboarded`,{method:"POST"}).catch(()=>{}),(0,p.trackWorkspaceCreated)("onboarding"),(0,p.trackOnboardingCompleted)({template_used:S??void 0,agent_count:L.length});for(let e=0;e<L.length;e++)(0,p.trackAgentCreated)({is_first_agent:0===e,has_email:!!L[e].emailHandle});d.toast.success("Company created!"),y.push(`/w/${s.workspace.slug}/agents/${s.leader_agent_id}`)}catch(e){d.toast.error(e instanceof Error?e.message:"Failed to create company"),E(!1)}},ee=S&&L.length>0&&L.every(e=>e.runtimeId)&&($||T&&Y||q);return S?(0,t.jsx)(h.PublicLayout,{leftSlot:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:()=>y.push("/workspaces"),children:[(0,t.jsx)(c.LayoutGrid,{className:"size-3 mr-1.5"}),"Workspaces"]}),(0,t.jsx)("span",{className:"text-muted-foreground/40",children:"/"}),(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:()=>P(null),children:[(0,t.jsx)(l.ArrowLeft,{className:"size-3 mr-1.5"}),"Back"]})]}),rightSlot:(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:async()=>{await (0,m.clearAllCache)(),(0,u.signOut)({fetchOptions:{onSuccess:()=>y.push("/sign-in")}})},children:[(0,t.jsx)(o.LogOut,{className:"size-3 mr-1.5"}),"Sign out"]}),children:(0,t.jsxs)("div",{className:"mx-auto w-full max-w-3xl space-y-10 px-6 py-14",children:[(0,t.jsx)("div",{className:"text-center",children:(0,t.jsx)("h1",{className:"text-2xl font-semibold tracking-tight",style:{fontFamily:"var(--font-news)"},children:"Build your company"})}),k?(0,t.jsx)("div",{className:"flex justify-center py-8",children:(0,t.jsx)(i.Loader2,{className:"size-5 animate-spin text-muted-foreground"})}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(_,{members:L,runtimes:G,onShuffle:J,onAssignRuntime:(e,t)=>{M(s=>s.map((s,r)=>r===e?{...s,runtimeId:t}:s))}}),!q&&(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("h2",{className:"text-base font-semibold tracking-tight",children:"Connect a computer"}),$||T&&Y?(0,t.jsxs)("p",{className:"text-xs text-emerald-600 flex items-center gap-1",children:[(0,t.jsx)(n.CheckCircle2,{className:"size-3"})," Computer connected"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Your company needs a connected computer to run tasks."}),(0,t.jsx)("div",{className:"rounded-xl bg-muted/40 p-5",children:(0,t.jsx)(A.ConnectMachineSteps,{generatedToken:D,generatingToken:B,onGenerateToken:W,registered:T,daemonOnline:Y})})]})]}),(0,t.jsx)(a.Button,{onClick:Q,disabled:!ee||I,className:"w-full",size:"lg",children:I?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(i.Loader2,{className:"size-4 animate-spin mr-2"}),"Launching..."]}):"Launch company"})]})]})}):(0,t.jsx)(h.PublicLayout,{leftSlot:(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:()=>y.push("/workspaces"),children:[(0,t.jsx)(c.LayoutGrid,{className:"size-3 mr-1.5"}),"Workspaces"]}),rightSlot:(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:async()=>{await (0,m.clearAllCache)(),(0,u.signOut)({fetchOptions:{onSuccess:()=>y.push("/sign-in")}})},children:[(0,t.jsx)(o.LogOut,{className:"size-3 mr-1.5"}),"Sign out"]}),mainClassName:"flex items-center justify-center",children:(0,t.jsxs)("div",{className:"w-full max-w-3xl space-y-8 px-6 py-6",children:[(0,t.jsxs)("div",{className:"text-center space-y-2",children:[(0,t.jsx)("h1",{className:"text-2xl font-semibold tracking-tight",style:{fontFamily:"var(--font-news)"},children:"What will your company do?"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Pick a focus area. You can always add more agents later."})]}),(0,t.jsx)(w,{selected:S,onSelect:Z,onBrowseTemplates:()=>y.push(`/templates?workspace_id=${e}`)}),(0,t.jsx)("div",{className:"flex justify-center pt-2",children:(0,t.jsx)("button",{type:"button",onClick:async()=>{await fetch(`/api/workspaces/${e}/onboarded`,{method:"POST"}).catch(()=>{}),y.push(`/w/${f}/home`)},className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"Skip for now"})})]})})}],319755)}]);
64
+ - Track open issues proactively. Escalate complex or sensitive cases with full context.`,relationship:"Delegate support tasks with: customer issue summary, urgency level, prior interaction context, and resolution approach.\n\nReport back with: response drafted or sent, resolution status, follow-up schedule, and recurring patterns to flag."}]},{id:"custom",label:"Custom",description:"Build your own team from scratch",icon:"✨",members:[{role:"leader",description:"Coordinates work and replies to you",instructions:y}]}];function b(e){let t=new Set,s=[];for(let r=0;r<e;r++){let e,r=0;do e=(0,g.uniqueNamesGenerator)({dictionaries:[g.names],length:1,style:"capital"}),r++;while(t.has(e)&&r<100)t.add(e),s.push({name:e,avatarUrl:(0,x.serializeAvatarConfig)((0,x.randomConfig)())})}return s}function w({selected:e,onSelect:s,onBrowseTemplates:r}){return(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("h2",{className:"text-base font-semibold tracking-tight",children:"What will your company focus on?"}),r&&(0,t.jsxs)("button",{type:"button",onClick:r,className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2",children:["Browse templates ",(0,t.jsx)("span",{"aria-hidden":"true",children:"›"})]})]}),(0,t.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:v.map(r=>(0,t.jsxs)("button",{onClick:()=>s(r.id),className:(0,f.cn)("flex flex-col items-start gap-1 rounded-lg border p-4 text-left transition-all hover:border-foreground/30",e===r.id?"border-foreground/50 bg-muted/50":"border-border"),children:[(0,t.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,t.jsx)("span",{className:"text-lg",children:r.icon}),(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:[r.members.length," agent",r.members.length>1?"s":""]})]}),(0,t.jsx)("span",{className:"text-sm font-medium",children:r.label}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground leading-tight",children:r.description})]},r.id))})]})}var j=e.i(934351),C=e.i(758870),k=e.i(89110),N=e.i(855372);e.i(954194);var S=e.i(439769);let P={leader:"Lead",researcher:"Researcher",engineer:"Engineer",assistant:"Assistant"};function _({members:e,runtimes:s,onShuffle:r,onAssignRuntime:i}){let n=s.length>1&&i;return(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("h2",{className:"text-base font-semibold tracking-tight",children:"Your company"}),(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",onClick:r,className:"h-7 text-xs gap-1.5",children:[(0,t.jsx)(C.RefreshCw,{className:"size-3"}),"Shuffle"]})]}),(0,t.jsx)("div",{className:(0,f.cn)("grid gap-3 grid-cols-1",2===e.length&&"sm:grid-cols-2",3===e.length&&"sm:grid-cols-2 md:grid-cols-3",e.length>=4&&"sm:grid-cols-2 md:grid-cols-4"),children:e.map((e,r)=>{let a,o=e.avatarUrl?(0,x.parseAvatarUrl)(e.avatarUrl):null;return(0,t.jsxs)(j.Card,{size:"sm",className:"flex flex-col px-3 py-4 gap-2 h-full",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2.5",children:[o?(0,t.jsx)(x.AvatarRenderer,{config:o,size:36,className:"rounded-xl shrink-0"}):(0,t.jsx)("div",{className:"size-9 rounded-xl bg-muted flex items-center justify-center text-sm font-semibold shrink-0",children:e.name.charAt(0)}),(0,t.jsxs)("div",{className:"flex flex-col items-start gap-0.5",children:[(0,t.jsx)("span",{className:"text-sm font-medium",children:e.name}),(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground bg-muted/60 px-1.5 py-0.5 rounded",children:P[e.role]})]})]}),(0,t.jsx)("p",{className:"text-[10px] text-muted-foreground/70 font-mono truncate",children:(0,S.toAlookAddress)(e.emailHandle||e.name.toLowerCase())}),(0,t.jsx)("p",{className:"text-[11px] text-muted-foreground leading-snug flex-1",children:e.description}),n&&(a=s.find(t=>t.id===e.runtimeId),(0,t.jsx)("div",{className:"mt-1",children:(0,t.jsxs)(k.Select,{value:e.runtimeId,onValueChange:e=>{e&&i(r,e)},children:[(0,t.jsx)(k.SelectTrigger,{className:"h-7 text-[11px]",children:(0,t.jsxs)("div",{className:"flex items-center gap-1.5 truncate",children:[a&&(0,t.jsx)(N.ProviderLogo,{provider:a.provider||"",className:"size-3 shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:a?.provider||a?.runtime_mode||"Select"})]})}),(0,t.jsx)(k.SelectContent,{children:s.map(e=>(0,t.jsx)(k.SelectItem,{value:e.id,children:e.provider||e.runtime_mode},e.id))})]})}))]},r)})})]})}var z=e.i(824863),O=e.i(222862),R=e.i(642342),A=e.i(371406);e.s(["StudioOnboardingClient",0,function({workspaceId:e,workspaceSlug:f,initialTemplate:g}){let x=(0,r.useRouter)(),[y,j]=(0,s.useState)([]),[C,k]=(0,s.useState)(!0),[N,S]=(0,s.useState)(g?g.baseScenario:null),[P,L]=(0,s.useState)([]),[M,I]=(0,s.useState)(!1),[E,D]=(0,s.useState)(""),[F,B]=(0,s.useState)(!1),[H,T]=(0,s.useState)(!1),[U,Y]=(0,s.useState)(!1),V=(0,z.isTauri)()&&(0,z.isDesktop)(),q=y.filter(e=>"online"===e.status),G=q.length>0;(0,s.useEffect)(()=>{(0,O.listRuntimes)(e).then(e=>{j(e),e.some(e=>"online"===e.status)&&(T(!0),Y(!0))}).catch(()=>{}).finally(()=>k(!1))},[e]);let $=(0,s.useCallback)(t=>{"runtime.registered"===t.type&&t.workspaceId===e?(T(!0),Y(!0),(0,O.listRuntimes)(e).then(j).catch(()=>{})):"runtime.status"===t.type&&t.workspaceId===e&&(T(!0),"online"===t.status?Y(!0):Y(!1))},[e]);(0,R.useUserWs)($);let X=(0,s.useCallback)(async()=>{B(!0);try{let t=await (0,O.createMachineToken)("cli",e);if(D(t.token),V){let s=await (0,z.tauriInvoke)("register_cli",{token:t.token});s.success?(T(!0),Y(!0),(0,O.listRuntimes)(e).then(j).catch(()=>{})):d.toast.error(s.message||"Auto-registration failed")}}catch{d.toast.error("Failed to generate token")}finally{B(!1)}},[e,V]);(0,s.useEffect)(()=>{let e=q[0]?.id;e&&L(t=>0!==t.length&&t.some(e=>!e.runtimeId)?t.map(t=>t.runtimeId?t:{...t,runtimeId:e}):t)},[q]);let W=(0,s.useCallback)(async e=>{try{let t=await fetch("/api/studios/check-handles",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({names:e})});if(!t.ok)return null;return await t.json()}catch{return null}},[]);(0,s.useEffect)(()=>{if(!g||C||P.length>0)return;let e=b(g.members.length),t=q[0]?.id||"",s=g.members.map((s,r)=>({name:e[r].name,role:s.role,description:s.description,instructions:s.instructions,avatarUrl:e[r].avatarUrl,runtimeId:t,relationship:s.relationship}));L(s),W(s.map(e=>e.name)).then(e=>{e&&L(t=>t.map(t=>{let s=e.find(e=>e.name===t.name);return s?{...t,emailHandle:s.handle}:t}))})},[g,C]);let K=async e=>{S(e);let t=v.find(t=>t.id===e),s=b(t.members.length),r=q[0]?.id||"",a=t.members.map((e,t)=>({name:s[t].name,role:e.role,description:e.description,instructions:e.instructions,avatarUrl:s[t].avatarUrl,runtimeId:r,relationship:e.relationship}));L(a);let i=await W(a.map(e=>e.name));i&&L(e=>e.map(e=>{let t=i.find(t=>t.name===e.name);return t?{...e,emailHandle:t.handle}:e}))},Z=async()=>{let e=b(P.length),t=P.map((t,s)=>({...t,name:e[s].name,avatarUrl:e[s].avatarUrl,emailHandle:void 0}));L(t);let s=await W(t.map(e=>e.name));s&&L(e=>e.map(e=>{let t=s.find(t=>t.name===e.name);return t?{...e,emailHandle:t.handle}:e}))},J=async()=>{I(!0);try{let t=await fetch("/api/studios",{method:"POST",headers:{"Content-Type":"application/json","X-Workspace-ID":e},body:JSON.stringify({name:void 0,scenario:N,members:P.map(e=>({name:e.name,role:e.role,runtime_id:e.runtimeId,description:e.description,instructions:e.instructions,avatar_url:e.avatarUrl||null,email_handle:e.emailHandle||void 0,relationship:e.relationship||void 0}))})});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to create company")}let s=await t.json();await fetch(`/api/workspaces/${e}/onboarded`,{method:"POST"}).catch(()=>{}),(0,p.trackWorkspaceCreated)("onboarding"),(0,p.trackOnboardingCompleted)({template_used:N??void 0,agent_count:P.length});for(let e=0;e<P.length;e++)(0,p.trackAgentCreated)({is_first_agent:0===e,has_email:!!P[e].emailHandle});d.toast.success("Company created!"),x.push(`/w/${s.workspace.slug}/agents/${s.leader_agent_id}`)}catch(e){d.toast.error(e instanceof Error?e.message:"Failed to create company"),I(!1)}},Q=N&&P.length>0&&P.every(e=>e.runtimeId)&&(G||H&&U||V);return N?(0,t.jsx)(h.PublicLayout,{leftSlot:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:()=>x.push("/workspaces"),children:[(0,t.jsx)(c.LayoutGrid,{className:"size-3 mr-1.5"}),"Workspaces"]}),(0,t.jsx)("span",{className:"text-muted-foreground/40",children:"/"}),(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:()=>S(null),children:[(0,t.jsx)(l.ArrowLeft,{className:"size-3 mr-1.5"}),"Back"]})]}),rightSlot:(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:async()=>{await (0,m.clearAllCache)(),(0,u.signOut)({fetchOptions:{onSuccess:()=>x.push("/sign-in")}})},children:[(0,t.jsx)(o.LogOut,{className:"size-3 mr-1.5"}),"Sign out"]}),children:(0,t.jsxs)("div",{className:"mx-auto w-full max-w-3xl space-y-10 px-6 py-14",children:[(0,t.jsx)("div",{className:"text-center",children:(0,t.jsx)("h1",{className:"text-2xl font-semibold tracking-tight",style:{fontFamily:"var(--font-news)"},children:"Build your company"})}),C?(0,t.jsx)("div",{className:"flex justify-center py-8",children:(0,t.jsx)(i.Loader2,{className:"size-5 animate-spin text-muted-foreground"})}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(_,{members:P,runtimes:q,onShuffle:Z,onAssignRuntime:(e,t)=>{L(s=>s.map((s,r)=>r===e?{...s,runtimeId:t}:s))}}),!V&&(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("h2",{className:"text-base font-semibold tracking-tight",children:"Connect a computer"}),G||H&&U?(0,t.jsxs)("p",{className:"text-xs text-emerald-600 flex items-center gap-1",children:[(0,t.jsx)(n.CheckCircle2,{className:"size-3"})," Computer connected"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Your company needs a connected computer to run tasks."}),(0,t.jsx)("div",{className:"rounded-xl bg-muted/40 p-5",children:(0,t.jsx)(A.ConnectMachineSteps,{generatedToken:E,generatingToken:F,onGenerateToken:X,registered:H,daemonOnline:U})})]})]}),(0,t.jsx)(a.Button,{onClick:J,disabled:!Q||M,className:"w-full",size:"lg",children:M?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(i.Loader2,{className:"size-4 animate-spin mr-2"}),"Launching..."]}):"Launch company"})]})]})}):(0,t.jsx)(h.PublicLayout,{leftSlot:(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:()=>x.push("/workspaces"),children:[(0,t.jsx)(c.LayoutGrid,{className:"size-3 mr-1.5"}),"Workspaces"]}),rightSlot:(0,t.jsxs)(a.Button,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:async()=>{await (0,m.clearAllCache)(),(0,u.signOut)({fetchOptions:{onSuccess:()=>x.push("/sign-in")}})},children:[(0,t.jsx)(o.LogOut,{className:"size-3 mr-1.5"}),"Sign out"]}),mainClassName:"flex items-center justify-center",children:(0,t.jsxs)("div",{className:"w-full max-w-3xl space-y-8 px-6 py-6",children:[(0,t.jsxs)("div",{className:"text-center space-y-2",children:[(0,t.jsx)("h1",{className:"text-2xl font-semibold tracking-tight",style:{fontFamily:"var(--font-news)"},children:"What will your company do?"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Pick a focus area. You can always add more agents later."})]}),(0,t.jsx)(w,{selected:N,onSelect:K,onBrowseTemplates:()=>x.push(`/templates?workspace_id=${e}`)}),(0,t.jsx)("div",{className:"flex justify-center pt-2",children:(0,t.jsx)("button",{type:"button",onClick:async()=>{await fetch(`/api/workspaces/${e}/onboarded`,{method:"POST"}).catch(()=>{}),x.push(`/w/${f}/home`)},className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"Skip for now"})})]})})}],319755)}]);