@agentrix/shared 2.0.10 → 2.0.12

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 (3) hide show
  1. package/dist/index.cjs +452 -57
  2. package/dist/index.d.cts +1376 -8574
  3. package/package.json +3 -3
package/dist/index.cjs CHANGED
@@ -54,7 +54,9 @@ const UserBasicInfoSchema = zod.z.object({
54
54
  id: IdSchema,
55
55
  username: zod.z.string(),
56
56
  email: zod.z.string().email().nullable(),
57
- avatar: zod.z.string().url().nullable()
57
+ avatar: zod.z.string().url().nullable(),
58
+ role: zod.z.string().optional()
59
+ // User role: "user", "admin", etc.
58
60
  });
59
61
  const OAuthAccountInfoSchema = zod.z.object({
60
62
  provider: zod.z.string(),
@@ -92,6 +94,11 @@ const UserProfileResponseSchema = zod.z.object({
92
94
  oauthAccounts: zod.z.array(OAuthAccountInfoSchema).optional()
93
95
  })
94
96
  });
97
+ const UpdateUserProfileRequestSchema = zod.z.object({
98
+ username: zod.z.string().min(1).optional(),
99
+ avatar: zod.z.string().nullable().optional()
100
+ });
101
+ const UpdateUserProfileResponseSchema = UserProfileResponseSchema;
95
102
  const LogoutResponseSchema = zod.z.object({
96
103
  success: zod.z.literal(true)
97
104
  });
@@ -195,6 +202,7 @@ const ShareAuthResponseSchema = zod.z.object({
195
202
 
196
203
  const StartTaskRequestSchema = zod.z.object({
197
204
  chatId: zod.z.string(),
205
+ customTitle: zod.z.string().min(1).max(200).optional(),
198
206
  message: zod.z.custom(
199
207
  (data) => {
200
208
  return typeof data === "object" && data !== null && "type" in data;
@@ -221,12 +229,17 @@ const StartTaskRequestSchema = zod.z.object({
221
229
  dataEncryptionKey: zod.z.string().optional(),
222
230
  // base64 sealed-box: app public key encrypted by machine public key
223
231
  // Multi-agent collaboration fields
232
+ agentId: zod.z.string().optional(),
233
+ // Agent ID to execute the task (overrides chat's first agent)
224
234
  parentTaskId: zod.z.string().optional()
225
- // Parent task ID (for creating child tasks)
226
- }).refine((data) => data.machineId || data.cloudId, {
227
- message: "Must provide either machineId or cloudId"
235
+ // Parent task ID (for creating child tasks, machineId/cloudId inherited from parent)
236
+ }).refine((data) => data.machineId || data.cloudId || data.parentTaskId, {
237
+ message: "Must provide either machineId, cloudId, or parentTaskId (for sub-tasks)"
228
238
  }).refine(
229
239
  (data) => {
240
+ if (data.parentTaskId) {
241
+ return true;
242
+ }
230
243
  if (data.machineId) {
231
244
  return !!data.encryptedMessage && !!data.dataEncryptionKey && !data.message;
232
245
  }
@@ -251,6 +264,7 @@ const StartTaskResponseSchema = zod.z.object({
251
264
  repositoryId: zod.z.string().nullable(),
252
265
  baseBranch: zod.z.string().nullable(),
253
266
  title: zod.z.string().nullable(),
267
+ customTitle: zod.z.string().nullable(),
254
268
  userCwd: zod.z.string().nullable(),
255
269
  forceUserCwd: zod.z.boolean().nullable(),
256
270
  createdAt: DateSchema,
@@ -258,6 +272,8 @@ const StartTaskResponseSchema = zod.z.object({
258
272
  });
259
273
  const TaskItemSchema = zod.z.object({
260
274
  id: IdSchema,
275
+ type: zod.z.enum(["chat", "work"]).default("work"),
276
+ // Task type: "chat" (virtual task for chat events) | "work" (real work task)
261
277
  chatId: IdSchema,
262
278
  userId: zod.z.string(),
263
279
  state: zod.z.string(),
@@ -486,7 +502,7 @@ const SendTaskMessageResponseSchema = zod.z.object({
486
502
  const ShowModalRequestSchema = zod.z.object({
487
503
  modalName: zod.z.string(),
488
504
  // Modal identifier, e.g., "configure-env-vars"
489
- modalData: zod.z.record(zod.z.any())
505
+ modalData: zod.z.record(zod.z.string(), zod.z.any())
490
506
  // Modal-specific data
491
507
  });
492
508
  const ShowModalResponseSchema = zod.z.object({
@@ -524,8 +540,13 @@ const ChatSchema = zod.z.object({
524
540
  title: zod.z.string().nullable().optional(),
525
541
  createdAt: zod.z.string(),
526
542
  // ISO 8601 string
527
- updatedAt: zod.z.string()
543
+ updatedAt: zod.z.string(),
528
544
  // ISO 8601 string
545
+ // Default context for creating sub-tasks
546
+ defaultMachineId: zod.z.string().nullable().optional(),
547
+ defaultCloudId: zod.z.string().nullable().optional(),
548
+ defaultRepositoryId: zod.z.string().nullable().optional(),
549
+ defaultBaseBranch: zod.z.string().nullable().optional()
529
550
  });
530
551
  const ChatWithMembersSchema = ChatSchema.extend({
531
552
  members: zod.z.array(ChatMemberSchema)
@@ -567,6 +588,13 @@ const RemoveChatMemberRequestSchema = zod.z.object({
567
588
  const ListChatTasksResponseSchema = zod.z.object({
568
589
  tasks: zod.z.array(TaskItemSchema)
569
590
  });
591
+ const UpdateChatContextRequestSchema = zod.z.object({
592
+ defaultMachineId: zod.z.string().nullable().optional(),
593
+ defaultCloudId: zod.z.string().nullable().optional(),
594
+ defaultRepositoryId: zod.z.string().nullable().optional(),
595
+ defaultBaseBranch: zod.z.string().nullable().optional()
596
+ });
597
+ const UpdateChatContextResponseSchema = ChatSchema;
570
598
 
571
599
  const AgentTypeSchema = zod.z.enum(["claude", "codex"]);
572
600
  const DisplayConfigKeysSchema = zod.z.object({
@@ -632,7 +660,9 @@ const CreateAgentRequestSchema = zod.z.object({
632
660
  placeholderMsg: zod.z.string().default("Ask me anything..."),
633
661
  gitRepoId: zod.z.string().optional(),
634
662
  supportLocal: zod.z.boolean().default(false),
635
- config: AgentCustomConfigSchema.nullable().optional()
663
+ config: AgentCustomConfigSchema.nullable().optional(),
664
+ isSystem: zod.z.boolean().optional()
665
+ // If true, userId will be set to 'system' (admin only)
636
666
  });
637
667
  const CreateAgentResponseSchema = AgentSchema;
638
668
  const UpdateAgentRequestSchema = zod.z.object({
@@ -1112,7 +1142,7 @@ const RpcCallEventSchema = zod.z.object({
1112
1142
  method: zod.z.enum(["GET", "POST", "PATCH", "DELETE"]),
1113
1143
  path: zod.z.string(),
1114
1144
  // API path, e.g., "/v1/draft-agent"
1115
- query: zod.z.record(zod.z.any()).optional(),
1145
+ query: zod.z.record(zod.z.string(), zod.z.any()).optional(),
1116
1146
  // Query params for GET requests
1117
1147
  body: zod.z.any().optional()
1118
1148
  // Request body for POST/PATCH/DELETE
@@ -1158,27 +1188,14 @@ const AskUserResponseMessageSchema = zod.z.object({
1158
1188
  status: AskUserResponseStatusSchema.optional(),
1159
1189
  reason: AskUserResponseReasonSchema.optional()
1160
1190
  });
1161
- const TaskArtifactsMessageSchema = zod.z.object({
1162
- type: zod.z.literal("task_artifacts_updated"),
1163
- commitHash: zod.z.string(),
1164
- timestamp: zod.z.string(),
1165
- stats: zod.z.object({
1166
- totalInsertions: zod.z.number(),
1167
- totalDeletions: zod.z.number(),
1168
- files: zod.z.array(FileStatsSchema)
1169
- })
1170
- });
1171
1191
  function isAskUserMessage(message) {
1172
1192
  return typeof message === "object" && message !== null && "type" in message && message.type === "ask_user";
1173
1193
  }
1174
1194
  function isAskUserResponseMessage(message) {
1175
1195
  return typeof message === "object" && message !== null && "type" in message && message.type === "ask_user_response";
1176
1196
  }
1177
- function isTaskArtifactsMessage(message) {
1178
- return typeof message === "object" && message !== null && "type" in message && message.type === "task_artifacts_updated";
1179
- }
1180
1197
  function isSDKMessage(message) {
1181
- return typeof message === "object" && message !== null && "type" in message && message.type !== "ask_user" && message.type !== "ask_user_response" && message.type !== "task_artifacts_updated";
1198
+ return typeof message === "object" && message !== null && "type" in message && message.type !== "ask_user" && message.type !== "ask_user_response";
1182
1199
  }
1183
1200
  const EventBaseSchema = zod.z.object({
1184
1201
  eventId: zod.z.string()
@@ -1248,6 +1265,19 @@ const WorkerStatusRequestSchema = EventBaseSchema.extend({
1248
1265
  taskId: zod.z.string(),
1249
1266
  timestamp: zod.z.string()
1250
1267
  });
1268
+ const WorkerStatusValueSchema = zod.z.enum([
1269
+ "worker-initializing",
1270
+ "worker-ready",
1271
+ "worker-running"
1272
+ ]);
1273
+ const ChatWorkersStatusRequestSchema = EventBaseSchema.extend({
1274
+ chatId: zod.z.string()
1275
+ });
1276
+ const ChatWorkersStatusResponseSchema = EventBaseSchema.extend({
1277
+ chatId: zod.z.string(),
1278
+ workers: zod.z.record(zod.z.string(), WorkerStatusValueSchema)
1279
+ // { taskId: status }
1280
+ });
1251
1281
  const baseTaskSchema = EventBaseSchema.extend({
1252
1282
  taskId: zod.z.string(),
1253
1283
  userId: zod.z.string(),
@@ -1287,8 +1317,12 @@ const baseTaskSchema = EventBaseSchema.extend({
1287
1317
  // Root task ID of the task tree
1288
1318
  parentTaskId: zod.z.string().optional(),
1289
1319
  // Parent task ID (for sub tasks)
1290
- chatAgents: zod.z.record(zod.z.string(), zod.z.string()).optional()
1320
+ chatAgents: zod.z.record(zod.z.string(), zod.z.string()).optional(),
1291
1321
  // All agents in chat: { displayName: agentId }
1322
+ taskType: zod.z.enum(["chat", "work"]).optional().default("work"),
1323
+ // Task type: 'chat' for main chat, 'work' for task execution
1324
+ customTitle: zod.z.string().min(1).max(200).optional()
1325
+ // Custom task title (set by user/tool)
1292
1326
  });
1293
1327
  const createTaskSchema = baseTaskSchema.extend({
1294
1328
  message: zod.z.custom(
@@ -1335,6 +1369,41 @@ const StopTaskSchema = EventBaseSchema.extend({
1335
1369
  taskId: zod.z.string(),
1336
1370
  reason: zod.z.string().optional()
1337
1371
  });
1372
+ const TaskArtifactsStatsSchema = zod.z.object({
1373
+ totalInsertions: zod.z.number(),
1374
+ totalDeletions: zod.z.number(),
1375
+ files: zod.z.array(FileStatsSchema)
1376
+ });
1377
+ const PreviewProjectTypeSchema = zod.z.enum([
1378
+ "html",
1379
+ "react",
1380
+ "vue",
1381
+ "vite",
1382
+ "nextjs",
1383
+ "unknown"
1384
+ ]);
1385
+ const PreviewMethodSchema = zod.z.enum([
1386
+ "simple",
1387
+ "bundled",
1388
+ "gallery",
1389
+ "none"
1390
+ ]);
1391
+ const PreviewMetadataSchema = zod.z.object({
1392
+ projectType: PreviewProjectTypeSchema,
1393
+ previewMethod: PreviewMethodSchema,
1394
+ entryFile: zod.z.string().nullable(),
1395
+ projectPath: zod.z.string(),
1396
+ // "" for single project, "apps/web" for monorepo
1397
+ dependencies: zod.z.record(zod.z.string(), zod.z.string()).optional(),
1398
+ tailwindVersion: zod.z.union([zod.z.literal(3), zod.z.literal(4), zod.z.null()]).optional(),
1399
+ isStaticFileCollection: zod.z.boolean().optional()
1400
+ });
1401
+ const TaskArtifactsSummarySchema = zod.z.object({
1402
+ commitHash: zod.z.string(),
1403
+ stats: TaskArtifactsStatsSchema,
1404
+ preview: PreviewMetadataSchema.nullable()
1405
+ // Preview metadata computed by CLI
1406
+ });
1338
1407
  const TaskMessageSchema = EventBaseSchema.extend({
1339
1408
  taskId: zod.z.string(),
1340
1409
  chatId: zod.z.string().optional(),
@@ -1355,8 +1424,10 @@ const TaskMessageSchema = EventBaseSchema.extend({
1355
1424
  // Multi-agent collaboration fields
1356
1425
  agentId: zod.z.string().optional(),
1357
1426
  // Agent ID for message attribution
1358
- rootTaskId: zod.z.string().optional()
1427
+ rootTaskId: zod.z.string().optional(),
1359
1428
  // Root task ID for event routing
1429
+ // Artifacts summary - attached to result messages for task completion
1430
+ artifacts: TaskArtifactsSummarySchema.optional()
1360
1431
  }).refine(
1361
1432
  (data) => {
1362
1433
  return !!data.message !== !!data.encryptedMessage;
@@ -1365,13 +1436,6 @@ const TaskMessageSchema = EventBaseSchema.extend({
1365
1436
  message: "Exactly one of message or encryptedMessage must be provided"
1366
1437
  }
1367
1438
  );
1368
- const TaskArtifactsUpdatedEventSchema = EventBaseSchema.extend({
1369
- taskId: zod.z.string(),
1370
- stats: zod.z.object({
1371
- totalInsertions: zod.z.number(),
1372
- totalDeletions: zod.z.number()
1373
- })
1374
- });
1375
1439
  const ShowModalEventDataSchema = EventBaseSchema.extend({
1376
1440
  taskId: zod.z.string(),
1377
1441
  chatId: zod.z.string().optional(),
@@ -1379,7 +1443,7 @@ const ShowModalEventDataSchema = EventBaseSchema.extend({
1379
1443
  timestamp: zod.z.string(),
1380
1444
  modalName: zod.z.string(),
1381
1445
  // e.g., "configure-env-vars"
1382
- modalData: zod.z.record(zod.z.any())
1446
+ modalData: zod.z.record(zod.z.string(), zod.z.any())
1383
1447
  // Modal-specific data
1384
1448
  });
1385
1449
  const ChangeTaskTitleEventSchema = EventBaseSchema.extend({
@@ -1487,7 +1551,7 @@ const UpdateTaskAgentSessionIdEventSchema = EventBaseSchema.extend({
1487
1551
  const TaskInfoUpdateEventDataSchema = EventBaseSchema.extend({
1488
1552
  taskId: zod.z.string(),
1489
1553
  chatId: zod.z.string(),
1490
- updates: zod.z.record(zod.z.any()).optional(),
1554
+ updates: zod.z.record(zod.z.string(), zod.z.any()).optional(),
1491
1555
  // Flexible updates object for any task fields
1492
1556
  updatedAt: zod.z.string()
1493
1557
  // ISO 8601 timestamp
@@ -1500,21 +1564,27 @@ const MergeRequestEventSchema = EventBaseSchema.extend({
1500
1564
  const TaskStoppedEventSchema = EventBaseSchema.extend({
1501
1565
  taskId: zod.z.string()
1502
1566
  });
1503
- const SubTaskCompletedEventSchema = EventBaseSchema.extend({
1567
+ const SubTaskResultUpdatedEventSchema = EventBaseSchema.extend({
1504
1568
  taskId: zod.z.string(),
1505
- // Completed sub task ID
1569
+ // Sub task ID
1506
1570
  parentTaskId: zod.z.string(),
1507
1571
  // Parent task ID
1508
1572
  rootTaskId: zod.z.string(),
1509
1573
  // Root task ID
1574
+ agentId: zod.z.string(),
1575
+ // Agent ID that executed the task
1510
1576
  agentName: zod.z.string(),
1511
- // Agent display name (e.g., "Test Agent")
1577
+ // Agent display name
1512
1578
  taskName: zod.z.string().optional(),
1513
- // Task title/name
1514
- sessionPath: zod.z.string().optional(),
1515
- // Session file path for analysis
1516
- cwd: zod.z.string().optional()
1517
- // Working directory containing generated results
1579
+ // Task title
1580
+ // Complete result message from SDK
1581
+ resultMessage: zod.z.object({
1582
+ type: zod.z.literal("result"),
1583
+ result: zod.z.string(),
1584
+ is_error: zod.z.boolean().optional()
1585
+ }),
1586
+ // Optional artifacts summary (for displaying in parent task chat)
1587
+ artifacts: TaskArtifactsSummarySchema.optional()
1518
1588
  });
1519
1589
  const MergePullRequestEventSchema = EventBaseSchema.extend({
1520
1590
  taskId: zod.z.string(),
@@ -1594,7 +1664,8 @@ const SystemMessageSchema = EventBaseSchema.extend({
1594
1664
  "repo-added",
1595
1665
  "repo-removed",
1596
1666
  "pr-state-changed",
1597
- "draft-agent-added"
1667
+ "draft-agent-added",
1668
+ "task-added"
1598
1669
  ]),
1599
1670
  data: zod.z.union([
1600
1671
  IdOnlySchema,
@@ -1609,8 +1680,10 @@ const SystemMessageSchema = EventBaseSchema.extend({
1609
1680
  // repo-added
1610
1681
  PrStateChangedSchema,
1611
1682
  // pr-state-changed
1612
- DraftAgentSchema
1683
+ DraftAgentSchema,
1613
1684
  // draft-agent-added
1685
+ TaskItemSchema
1686
+ // task-added
1614
1687
  ]),
1615
1688
  timestamp: zod.z.string()
1616
1689
  });
@@ -1628,6 +1701,9 @@ const EventSchemaMap = {
1628
1701
  "worker-exit": WorkerExitSchema,
1629
1702
  "worker-running": WorkerRunningSchema,
1630
1703
  "worker-status-request": WorkerStatusRequestSchema,
1704
+ // Chat workers status events
1705
+ "chat-workers-status-request": ChatWorkersStatusRequestSchema,
1706
+ "chat-workers-status-response": ChatWorkersStatusResponseSchema,
1631
1707
  // Task events
1632
1708
  "create-task": createTaskSchema,
1633
1709
  "resume-task": resumeTaskSchema,
@@ -1638,8 +1714,6 @@ const EventSchemaMap = {
1638
1714
  "task-state-change": TaskStateChangeEventSchema,
1639
1715
  "update-task-agent-session-id": UpdateTaskAgentSessionIdEventSchema,
1640
1716
  "task-info-update": TaskInfoUpdateEventDataSchema,
1641
- // Artifacts events
1642
- "task-artifacts-updated": TaskArtifactsUpdatedEventSchema,
1643
1717
  // Modal events
1644
1718
  "show-modal": ShowModalEventDataSchema,
1645
1719
  // Merge request events
@@ -1650,7 +1724,7 @@ const EventSchemaMap = {
1650
1724
  "deploy-agent-complete": DeployAgentCompleteEventSchema,
1651
1725
  // Multi-agent collaboration events
1652
1726
  "task-stopped": TaskStoppedEventSchema,
1653
- "sub-task-completed": SubTaskCompletedEventSchema,
1727
+ "sub-task-result-updated": SubTaskResultUpdatedEventSchema,
1654
1728
  // Repository association events
1655
1729
  "associate-repo": AssociateRepoEventDataSchema,
1656
1730
  // System message events
@@ -1679,7 +1753,6 @@ const workerTaskEvents = [
1679
1753
  "worker-exit",
1680
1754
  "change-task-title",
1681
1755
  "update-task-agent-session-id",
1682
- "task-artifacts-updated",
1683
1756
  "merge-request",
1684
1757
  "merge-pr",
1685
1758
  "associate-repo"
@@ -1731,7 +1804,7 @@ const ClaudeConfigSchema = zod.z.object({
1731
1804
  fallbackModel: zod.z.string().optional(),
1732
1805
  maxTurns: zod.z.number().int().positive().optional(),
1733
1806
  // SDK native extra arguments
1734
- extraArgs: zod.z.record(zod.z.string().nullable()).optional(),
1807
+ extraArgs: zod.z.record(zod.z.string(), zod.z.string().nullable()).optional(),
1735
1808
  systemPrompt: zod.z.object({
1736
1809
  path: zod.z.string(),
1737
1810
  mode: zod.z.enum(["append", "replace"]).optional().default("append")
@@ -1877,7 +1950,8 @@ async function loadAgentConfig(options) {
1877
1950
  console.warn(`[AGENT] Warnings for agent "${agentId}":`, validation.warnings);
1878
1951
  }
1879
1952
  const metadata = await loadAgentMetadata(agentDir);
1880
- const frameworkDir = node_path.join(agentDir, `.${framework}`);
1953
+ const frameworkDirName = framework === "claude" ? "claude" : `.${framework}`;
1954
+ const frameworkDir = node_path.join(agentDir, frameworkDirName);
1881
1955
  if (!node_fs.existsSync(frameworkDir)) {
1882
1956
  throw new FrameworkNotSupportedError(agentId, framework);
1883
1957
  }
@@ -1915,7 +1989,7 @@ async function loadAgentMetadata(agentDir) {
1915
1989
  }
1916
1990
  }
1917
1991
  async function loadClaudeConfiguration(agentDir, metadata) {
1918
- const claudeDir = node_path.join(agentDir, ".claude");
1992
+ const claudeDir = node_path.join(agentDir, "claude");
1919
1993
  const validation = validateFrameworkDirectory(claudeDir, "claude");
1920
1994
  if (!validation.valid) {
1921
1995
  throw new AgentConfigValidationError(
@@ -1943,7 +2017,7 @@ async function loadClaudeConfiguration(agentDir, metadata) {
1943
2017
  }
1944
2018
  async function loadClaudeConfig(claudeDir) {
1945
2019
  const configPath = node_path.join(claudeDir, "config.json");
1946
- assertFileExists(configPath, ".claude/config.json");
2020
+ assertFileExists(configPath, "claude/config.json");
1947
2021
  try {
1948
2022
  const content = node_fs.readFileSync(configPath, "utf-8");
1949
2023
  const rawConfig = JSON.parse(content);
@@ -1952,7 +2026,7 @@ async function loadClaudeConfig(claudeDir) {
1952
2026
  } catch (error) {
1953
2027
  if (error instanceof SyntaxError) {
1954
2028
  throw new AgentConfigValidationError(
1955
- "Invalid JSON in .claude/config.json"
2029
+ "Invalid JSON in claude/config.json"
1956
2030
  );
1957
2031
  }
1958
2032
  throw new AgentConfigValidationError(
@@ -1963,7 +2037,7 @@ async function loadClaudeConfig(claudeDir) {
1963
2037
  async function loadSystemPrompt(claudeDir, promptFile) {
1964
2038
  const promptPath = node_path.join(claudeDir, promptFile);
1965
2039
  if (!node_fs.existsSync(promptPath)) {
1966
- throw new MissingAgentFileError(`.claude/${promptFile}`);
2040
+ throw new MissingAgentFileError(`claude/${promptFile}`);
1967
2041
  }
1968
2042
  try {
1969
2043
  return node_fs.readFileSync(promptPath, "utf-8");
@@ -2257,6 +2331,312 @@ function splitRtcChunkFrame(data) {
2257
2331
  return { header, payload };
2258
2332
  }
2259
2333
 
2334
+ const STATIC_FILE_EXTENSIONS = {
2335
+ images: [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp", ".svg", ".ico"],
2336
+ videos: [".mp4", ".mov", ".avi", ".webm", ".mkv", ".m4v", ".flv", ".wmv"],
2337
+ documents: [".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx"],
2338
+ text: [".txt", ".md", ".markdown", ".json", ".yaml", ".yml", ".csv", ".xml"],
2339
+ html: [".html", ".htm"]
2340
+ };
2341
+ const IGNORED_DIRECTORIES = [
2342
+ "node_modules",
2343
+ ".git",
2344
+ "dist",
2345
+ "build",
2346
+ ".next",
2347
+ "out",
2348
+ "coverage",
2349
+ "__pycache__",
2350
+ ".cache",
2351
+ ".parcel-cache",
2352
+ ".turbo"
2353
+ ];
2354
+ const ENTRY_FILE_PATTERNS = {
2355
+ html: ["index.html", "src/index.html"],
2356
+ react: [
2357
+ "index.html",
2358
+ // Vite/CRA
2359
+ "public/index.html",
2360
+ // Create React App
2361
+ "src/index.tsx",
2362
+ "src/index.jsx",
2363
+ "src/index.ts",
2364
+ "src/index.js",
2365
+ "src/main.tsx",
2366
+ // Vite-specific
2367
+ "src/main.ts",
2368
+ "src/main.jsx",
2369
+ "src/main.js",
2370
+ "src/App.tsx",
2371
+ "src/App.jsx",
2372
+ "index.tsx",
2373
+ // Root-level
2374
+ "index.jsx",
2375
+ "index.js",
2376
+ "App.tsx",
2377
+ "App.jsx"
2378
+ ],
2379
+ vue: [
2380
+ "index.html",
2381
+ // Vite
2382
+ "src/main.ts",
2383
+ "src/main.js",
2384
+ "src/index.ts",
2385
+ "src/index.js",
2386
+ "src/App.vue",
2387
+ "App.vue"
2388
+ ],
2389
+ vite: [
2390
+ "index.html",
2391
+ "src/main.tsx",
2392
+ "src/main.ts",
2393
+ "src/main.jsx",
2394
+ "src/main.js",
2395
+ "src/index.tsx",
2396
+ "src/index.ts",
2397
+ "src/App.tsx",
2398
+ "src/App.jsx"
2399
+ ],
2400
+ nextjs: [
2401
+ "pages/index.tsx",
2402
+ "pages/index.jsx",
2403
+ "app/page.tsx",
2404
+ "src/pages/index.tsx",
2405
+ "src/app/page.tsx"
2406
+ ]
2407
+ };
2408
+ const CONFIG_FILES = {
2409
+ vite: ["vite.config.js", "vite.config.ts", "vite.config.mjs"],
2410
+ nextjs: ["next.config.js", "next.config.mjs", "next.config.ts"]
2411
+ };
2412
+ const RELEVANT_DEPENDENCIES = [
2413
+ "react",
2414
+ "react-dom",
2415
+ "vue",
2416
+ "vite",
2417
+ "next",
2418
+ "tailwindcss",
2419
+ "@vitejs/plugin-react",
2420
+ "@vitejs/plugin-vue"
2421
+ ];
2422
+
2423
+ async function detectPreview(fs) {
2424
+ try {
2425
+ const files = await fs.listFiles(3);
2426
+ if (files.length === 0) {
2427
+ return null;
2428
+ }
2429
+ const dependencies = await parsePackageJson(fs);
2430
+ const projectType = await detectProjectType(files, dependencies, fs);
2431
+ const isStaticFileCollection = detectStaticFileCollection(files, projectType);
2432
+ const previewMethod = getPreviewMethod(projectType, isStaticFileCollection);
2433
+ if (previewMethod === "none" && !isStaticFileCollection) {
2434
+ return null;
2435
+ }
2436
+ const entryFile = await findEntryFile(files, projectType, fs);
2437
+ const tailwindVersion = detectTailwindVersion(dependencies);
2438
+ return {
2439
+ projectType,
2440
+ previewMethod,
2441
+ entryFile,
2442
+ projectPath: "",
2443
+ dependencies: filterRelevantDependencies(dependencies),
2444
+ tailwindVersion,
2445
+ isStaticFileCollection
2446
+ };
2447
+ } catch (error) {
2448
+ console.warn("[preview/detector] Failed to detect preview:", error);
2449
+ return null;
2450
+ }
2451
+ }
2452
+ async function parsePackageJson(fs) {
2453
+ try {
2454
+ const content = await fs.readFile("package.json");
2455
+ if (!content) {
2456
+ return {};
2457
+ }
2458
+ const pkg = JSON.parse(content);
2459
+ return {
2460
+ ...pkg.dependencies || {},
2461
+ ...pkg.devDependencies || {}
2462
+ };
2463
+ } catch {
2464
+ return {};
2465
+ }
2466
+ }
2467
+ async function detectProjectType(files, dependencies, fs) {
2468
+ const rootFiles = files.filter((f) => !f.includes("/"));
2469
+ const hasNextConfig = CONFIG_FILES.nextjs.some((config) => rootFiles.includes(config));
2470
+ if (dependencies.next || hasNextConfig) {
2471
+ return "nextjs";
2472
+ }
2473
+ const hasViteConfig = CONFIG_FILES.vite.some((config) => rootFiles.includes(config));
2474
+ if (dependencies.vite || hasViteConfig) {
2475
+ const isVue = dependencies.vue || files.some((f) => f.endsWith(".vue"));
2476
+ const isReact = dependencies.react || files.some((f) => f.endsWith(".jsx") || f.endsWith(".tsx"));
2477
+ if (isVue) return "vue";
2478
+ if (isReact) return "react";
2479
+ return "vite";
2480
+ }
2481
+ if (dependencies.react || files.some((f) => f.endsWith(".jsx") || f.endsWith(".tsx"))) {
2482
+ return "react";
2483
+ }
2484
+ if (dependencies.vue || files.some((f) => f.endsWith(".vue"))) {
2485
+ return "vue";
2486
+ }
2487
+ if (files.some((f) => f === "index.html" || f === "src/index.html")) {
2488
+ return "html";
2489
+ }
2490
+ return "unknown";
2491
+ }
2492
+ function detectStaticFileCollection(files, projectType) {
2493
+ if (projectType !== "unknown") {
2494
+ return false;
2495
+ }
2496
+ const allExtensions = [
2497
+ ...STATIC_FILE_EXTENSIONS.images,
2498
+ ...STATIC_FILE_EXTENSIONS.videos,
2499
+ ...STATIC_FILE_EXTENSIONS.documents,
2500
+ ...STATIC_FILE_EXTENSIONS.text,
2501
+ ...STATIC_FILE_EXTENSIONS.html
2502
+ ];
2503
+ return files.some((file) => {
2504
+ const ext = getFileExtension(file);
2505
+ return allExtensions.includes(ext);
2506
+ });
2507
+ }
2508
+ function getPreviewMethod(projectType, isStaticFileCollection) {
2509
+ if (isStaticFileCollection) {
2510
+ return "gallery";
2511
+ }
2512
+ switch (projectType) {
2513
+ case "html":
2514
+ return "simple";
2515
+ case "react":
2516
+ case "vue":
2517
+ case "vite":
2518
+ return "bundled";
2519
+ case "nextjs":
2520
+ return "none";
2521
+ case "unknown":
2522
+ return "none";
2523
+ }
2524
+ }
2525
+ async function findEntryFile(files, projectType, fs) {
2526
+ if ((projectType === "react" || projectType === "vite") && files.includes("index.html")) {
2527
+ try {
2528
+ const content = await fs.readFile("index.html");
2529
+ if (content) {
2530
+ const scriptMatch = content.match(
2531
+ /<script[^>]*type=["']module["'][^>]*src=["']([^"']+)["']/
2532
+ );
2533
+ if (scriptMatch) {
2534
+ const jsxPath = scriptMatch[1];
2535
+ const normalizedPath = jsxPath.startsWith("/") ? jsxPath.substring(1) : jsxPath;
2536
+ if (files.includes(normalizedPath)) {
2537
+ return normalizedPath;
2538
+ }
2539
+ }
2540
+ }
2541
+ } catch {
2542
+ }
2543
+ }
2544
+ const possiblePaths = getPossibleEntryPaths(projectType);
2545
+ for (const path of possiblePaths) {
2546
+ if (files.includes(path)) {
2547
+ return path;
2548
+ }
2549
+ }
2550
+ const commonSubdirs = ["src", "app", "client", "frontend"];
2551
+ const commonEntryNames = [
2552
+ "index.html",
2553
+ "index.tsx",
2554
+ "index.ts",
2555
+ "index.jsx",
2556
+ "index.js",
2557
+ "main.tsx",
2558
+ "main.ts",
2559
+ "main.jsx",
2560
+ "main.js",
2561
+ "App.tsx",
2562
+ "App.ts",
2563
+ "App.jsx",
2564
+ "App.js"
2565
+ ];
2566
+ for (const subdir of commonSubdirs) {
2567
+ for (const entryName of commonEntryNames) {
2568
+ const path = `${subdir}/${entryName}`;
2569
+ if (files.includes(path)) {
2570
+ const isValid = isValidEntryForProjectType(path, projectType);
2571
+ if (isValid) {
2572
+ return path;
2573
+ }
2574
+ }
2575
+ }
2576
+ }
2577
+ return null;
2578
+ }
2579
+ function isValidEntryForProjectType(filePath, projectType) {
2580
+ const ext = getFileExtension(filePath);
2581
+ switch (projectType) {
2582
+ case "html":
2583
+ return ext === ".html" || ext === ".htm";
2584
+ case "react":
2585
+ return [".tsx", ".jsx", ".ts", ".js", ".html"].includes(ext);
2586
+ case "vue":
2587
+ return [".vue", ".ts", ".js", ".html"].includes(ext);
2588
+ case "vite":
2589
+ return [".tsx", ".jsx", ".ts", ".js", ".vue", ".html"].includes(ext);
2590
+ case "nextjs":
2591
+ return [".tsx", ".jsx"].includes(ext);
2592
+ case "unknown":
2593
+ return false;
2594
+ }
2595
+ }
2596
+ function getPossibleEntryPaths(projectType) {
2597
+ switch (projectType) {
2598
+ case "html":
2599
+ return ENTRY_FILE_PATTERNS.html;
2600
+ case "react":
2601
+ return ENTRY_FILE_PATTERNS.react;
2602
+ case "vue":
2603
+ return ENTRY_FILE_PATTERNS.vue;
2604
+ case "vite":
2605
+ return ENTRY_FILE_PATTERNS.vite;
2606
+ case "nextjs":
2607
+ return ENTRY_FILE_PATTERNS.nextjs;
2608
+ case "unknown":
2609
+ return [];
2610
+ }
2611
+ }
2612
+ function detectTailwindVersion(dependencies) {
2613
+ const tailwindVersion = dependencies.tailwindcss;
2614
+ if (!tailwindVersion) {
2615
+ return null;
2616
+ }
2617
+ const versionMatch = tailwindVersion.match(/^[\^~]?(\d+)/);
2618
+ const majorVersion = versionMatch ? parseInt(versionMatch[1]) : null;
2619
+ if (majorVersion === 4) return 4;
2620
+ if (majorVersion === 3) return 3;
2621
+ return null;
2622
+ }
2623
+ function filterRelevantDependencies(dependencies) {
2624
+ const filtered = {};
2625
+ for (const [name, version] of Object.entries(dependencies)) {
2626
+ if (RELEVANT_DEPENDENCIES.includes(name)) {
2627
+ filtered[name] = version;
2628
+ }
2629
+ }
2630
+ return filtered;
2631
+ }
2632
+ function getFileExtension(filePath) {
2633
+ const lastDot = filePath.lastIndexOf(".");
2634
+ if (lastDot === -1 || lastDot === filePath.length - 1) {
2635
+ return "";
2636
+ }
2637
+ return filePath.substring(lastDot).toLowerCase();
2638
+ }
2639
+
2260
2640
  exports.AddChatMemberRequestSchema = AddChatMemberRequestSchema;
2261
2641
  exports.AddChatMemberResponseSchema = AddChatMemberResponseSchema;
2262
2642
  exports.AgentConfigValidationError = AgentConfigValidationError;
@@ -2285,6 +2665,7 @@ exports.AskUserResponseStatusSchema = AskUserResponseStatusSchema;
2285
2665
  exports.AssociateRepoEventDataSchema = AssociateRepoEventDataSchema;
2286
2666
  exports.BillingStatsResponseSchema = BillingStatsResponseSchema;
2287
2667
  exports.BranchSchema = BranchSchema;
2668
+ exports.CONFIG_FILES = CONFIG_FILES;
2288
2669
  exports.CancelTaskRequestSchema = CancelTaskRequestSchema;
2289
2670
  exports.CancelTaskResponseSchema = CancelTaskResponseSchema;
2290
2671
  exports.ChangeTaskTitleEventSchema = ChangeTaskTitleEventSchema;
@@ -2294,6 +2675,8 @@ exports.ChatMemberSchema = ChatMemberSchema;
2294
2675
  exports.ChatSchema = ChatSchema;
2295
2676
  exports.ChatTypeSchema = ChatTypeSchema;
2296
2677
  exports.ChatWithMembersSchema = ChatWithMembersSchema;
2678
+ exports.ChatWorkersStatusRequestSchema = ChatWorkersStatusRequestSchema;
2679
+ exports.ChatWorkersStatusResponseSchema = ChatWorkersStatusResponseSchema;
2297
2680
  exports.ClaudeConfigSchema = ClaudeConfigSchema;
2298
2681
  exports.CloudJoinApprovalRequestSchema = CloudJoinApprovalRequestSchema;
2299
2682
  exports.CloudJoinRequestSchema = CloudJoinRequestSchema;
@@ -2328,6 +2711,7 @@ exports.DisplayConfigKeysSchema = DisplayConfigKeysSchema;
2328
2711
  exports.DisplayConfigSchema = DisplayConfigSchema;
2329
2712
  exports.DraftAgentConfigSchema = DraftAgentConfigSchema;
2330
2713
  exports.DraftAgentSchema = DraftAgentSchema;
2714
+ exports.ENTRY_FILE_PATTERNS = ENTRY_FILE_PATTERNS;
2331
2715
  exports.EnvironmentVariableSchema = EnvironmentVariableSchema;
2332
2716
  exports.EventAckSchema = EventAckSchema;
2333
2717
  exports.EventSchemaMap = EventSchemaMap;
@@ -2355,6 +2739,7 @@ exports.GetUserAgentsResponseSchema = GetUserAgentsResponseSchema;
2355
2739
  exports.GitHubIssueListItemSchema = GitHubIssueListItemSchema;
2356
2740
  exports.GitHubIssueSchema = GitHubIssueSchema;
2357
2741
  exports.GitServerSchema = GitServerSchema;
2742
+ exports.IGNORED_DIRECTORIES = IGNORED_DIRECTORIES;
2358
2743
  exports.IdSchema = IdSchema;
2359
2744
  exports.ListAgentsResponseSchema = ListAgentsResponseSchema;
2360
2745
  exports.ListBranchesResponseSchema = ListBranchesResponseSchema;
@@ -2404,11 +2789,15 @@ exports.OAuthUnbindResponseSchema = OAuthUnbindResponseSchema;
2404
2789
  exports.PaginatedResponseSchema = PaginatedResponseSchema;
2405
2790
  exports.PermissionResponseRequestSchema = PermissionResponseRequestSchema;
2406
2791
  exports.PermissionResponseResponseSchema = PermissionResponseResponseSchema;
2792
+ exports.PreviewMetadataSchema = PreviewMetadataSchema;
2793
+ exports.PreviewMethodSchema = PreviewMethodSchema;
2794
+ exports.PreviewProjectTypeSchema = PreviewProjectTypeSchema;
2407
2795
  exports.ProjectDirectoryResponseSchema = ProjectDirectoryResponseSchema;
2408
2796
  exports.ProjectEntrySchema = ProjectEntrySchema;
2409
2797
  exports.PublishDraftAgentRequestSchema = PublishDraftAgentRequestSchema;
2410
2798
  exports.PublishDraftAgentResponseSchema = PublishDraftAgentResponseSchema;
2411
2799
  exports.QueryEventsRequestSchema = QueryEventsRequestSchema;
2800
+ exports.RELEVANT_DEPENDENCIES = RELEVANT_DEPENDENCIES;
2412
2801
  exports.RTC_CHUNK_HEADER_SIZE = RTC_CHUNK_HEADER_SIZE;
2413
2802
  exports.RechargeResponseSchema = RechargeResponseSchema;
2414
2803
  exports.RemoveChatMemberRequestSchema = RemoveChatMemberRequestSchema;
@@ -2424,6 +2813,7 @@ exports.RtcIceServerSchema = RtcIceServerSchema;
2424
2813
  exports.RtcIceServersRequestSchema = RtcIceServersRequestSchema;
2425
2814
  exports.RtcIceServersResponseSchema = RtcIceServersResponseSchema;
2426
2815
  exports.RtcSignalSchema = RtcSignalSchema;
2816
+ exports.STATIC_FILE_EXTENSIONS = STATIC_FILE_EXTENSIONS;
2427
2817
  exports.SendTaskMessageRequestSchema = SendTaskMessageRequestSchema;
2428
2818
  exports.SendTaskMessageResponseSchema = SendTaskMessageResponseSchema;
2429
2819
  exports.SetEnvironmentVariablesRequestSchema = SetEnvironmentVariablesRequestSchema;
@@ -2442,13 +2832,13 @@ exports.StatsQuerySchema = StatsQuerySchema;
2442
2832
  exports.StopTaskRequestSchema = StopTaskRequestSchema;
2443
2833
  exports.StopTaskResponseSchema = StopTaskResponseSchema;
2444
2834
  exports.StopTaskSchema = StopTaskSchema;
2445
- exports.SubTaskCompletedEventSchema = SubTaskCompletedEventSchema;
2835
+ exports.SubTaskResultUpdatedEventSchema = SubTaskResultUpdatedEventSchema;
2446
2836
  exports.SyncCloudMachineResponseSchema = SyncCloudMachineResponseSchema;
2447
2837
  exports.SyncLocalMachineResponseSchema = SyncLocalMachineResponseSchema;
2448
2838
  exports.SyncMachineRequestSchema = SyncMachineRequestSchema;
2449
2839
  exports.SystemMessageSchema = SystemMessageSchema;
2450
- exports.TaskArtifactsMessageSchema = TaskArtifactsMessageSchema;
2451
- exports.TaskArtifactsUpdatedEventSchema = TaskArtifactsUpdatedEventSchema;
2840
+ exports.TaskArtifactsStatsSchema = TaskArtifactsStatsSchema;
2841
+ exports.TaskArtifactsSummarySchema = TaskArtifactsSummarySchema;
2452
2842
  exports.TaskInfoUpdateEventDataSchema = TaskInfoUpdateEventDataSchema;
2453
2843
  exports.TaskItemSchema = TaskItemSchema;
2454
2844
  exports.TaskMessageSchema = TaskMessageSchema;
@@ -2463,6 +2853,8 @@ exports.UnarchiveTaskRequestSchema = UnarchiveTaskRequestSchema;
2463
2853
  exports.UnarchiveTaskResponseSchema = UnarchiveTaskResponseSchema;
2464
2854
  exports.UpdateAgentRequestSchema = UpdateAgentRequestSchema;
2465
2855
  exports.UpdateAgentResponseSchema = UpdateAgentResponseSchema;
2856
+ exports.UpdateChatContextRequestSchema = UpdateChatContextRequestSchema;
2857
+ exports.UpdateChatContextResponseSchema = UpdateChatContextResponseSchema;
2466
2858
  exports.UpdateDraftAgentRequestSchema = UpdateDraftAgentRequestSchema;
2467
2859
  exports.UpdateDraftAgentResponseSchema = UpdateDraftAgentResponseSchema;
2468
2860
  exports.UpdateOAuthServerRequestSchema = UpdateOAuthServerRequestSchema;
@@ -2470,6 +2862,8 @@ exports.UpdateOAuthServerResponseSchema = UpdateOAuthServerResponseSchema;
2470
2862
  exports.UpdateTaskAgentSessionIdEventSchema = UpdateTaskAgentSessionIdEventSchema;
2471
2863
  exports.UpdateTaskTitleRequestSchema = UpdateTaskTitleRequestSchema;
2472
2864
  exports.UpdateTaskTitleResponseSchema = UpdateTaskTitleResponseSchema;
2865
+ exports.UpdateUserProfileRequestSchema = UpdateUserProfileRequestSchema;
2866
+ exports.UpdateUserProfileResponseSchema = UpdateUserProfileResponseSchema;
2473
2867
  exports.UploadUrlResultSchema = UploadUrlResultSchema;
2474
2868
  exports.UserBalanceResponseSchema = UserBalanceResponseSchema;
2475
2869
  exports.UserBasicInfoSchema = UserBasicInfoSchema;
@@ -2482,6 +2876,7 @@ exports.WorkerInitializingSchema = WorkerInitializingSchema;
2482
2876
  exports.WorkerReadySchema = WorkerReadySchema;
2483
2877
  exports.WorkerRunningSchema = WorkerRunningSchema;
2484
2878
  exports.WorkerStatusRequestSchema = WorkerStatusRequestSchema;
2879
+ exports.WorkerStatusValueSchema = WorkerStatusValueSchema;
2485
2880
  exports.WorkspaceFileRequestSchema = WorkspaceFileRequestSchema;
2486
2881
  exports.WorkspaceFileResponseSchema = WorkspaceFileResponseSchema;
2487
2882
  exports.assertAgentExists = assertAgentExists;
@@ -2502,6 +2897,7 @@ exports.decryptFileContent = decryptFileContent;
2502
2897
  exports.decryptMachineEncryptionKey = decryptMachineEncryptionKey;
2503
2898
  exports.decryptSdkMessage = decryptSdkMessage;
2504
2899
  exports.decryptWithEphemeralKey = decryptWithEphemeralKey;
2900
+ exports.detectPreview = detectPreview;
2505
2901
  exports.discoverPlugins = discoverPlugins;
2506
2902
  exports.encodeBase64 = encodeBase64;
2507
2903
  exports.encodeBase64Url = encodeBase64Url;
@@ -2518,7 +2914,6 @@ exports.getRandomBytes = getRandomBytes;
2518
2914
  exports.isAskUserMessage = isAskUserMessage;
2519
2915
  exports.isAskUserResponseMessage = isAskUserResponseMessage;
2520
2916
  exports.isSDKMessage = isSDKMessage;
2521
- exports.isTaskArtifactsMessage = isTaskArtifactsMessage;
2522
2917
  exports.loadAgentConfig = loadAgentConfig;
2523
2918
  exports.machineAuth = machineAuth;
2524
2919
  exports.permissionResponseRequestSchema = permissionResponseRequestSchema;