@agentrix/shared 2.0.11 → 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 +80 -50
  2. package/dist/index.d.cts +1141 -9301
  3. package/package.json +2 -2
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
  });
@@ -495,7 +502,7 @@ const SendTaskMessageResponseSchema = zod.z.object({
495
502
  const ShowModalRequestSchema = zod.z.object({
496
503
  modalName: zod.z.string(),
497
504
  // Modal identifier, e.g., "configure-env-vars"
498
- modalData: zod.z.record(zod.z.any())
505
+ modalData: zod.z.record(zod.z.string(), zod.z.any())
499
506
  // Modal-specific data
500
507
  });
501
508
  const ShowModalResponseSchema = zod.z.object({
@@ -653,7 +660,9 @@ const CreateAgentRequestSchema = zod.z.object({
653
660
  placeholderMsg: zod.z.string().default("Ask me anything..."),
654
661
  gitRepoId: zod.z.string().optional(),
655
662
  supportLocal: zod.z.boolean().default(false),
656
- 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)
657
666
  });
658
667
  const CreateAgentResponseSchema = AgentSchema;
659
668
  const UpdateAgentRequestSchema = zod.z.object({
@@ -1133,7 +1142,7 @@ const RpcCallEventSchema = zod.z.object({
1133
1142
  method: zod.z.enum(["GET", "POST", "PATCH", "DELETE"]),
1134
1143
  path: zod.z.string(),
1135
1144
  // API path, e.g., "/v1/draft-agent"
1136
- query: zod.z.record(zod.z.any()).optional(),
1145
+ query: zod.z.record(zod.z.string(), zod.z.any()).optional(),
1137
1146
  // Query params for GET requests
1138
1147
  body: zod.z.any().optional()
1139
1148
  // Request body for POST/PATCH/DELETE
@@ -1179,27 +1188,14 @@ const AskUserResponseMessageSchema = zod.z.object({
1179
1188
  status: AskUserResponseStatusSchema.optional(),
1180
1189
  reason: AskUserResponseReasonSchema.optional()
1181
1190
  });
1182
- const TaskArtifactsMessageSchema = zod.z.object({
1183
- type: zod.z.literal("task_artifacts_updated"),
1184
- commitHash: zod.z.string(),
1185
- timestamp: zod.z.string(),
1186
- stats: zod.z.object({
1187
- totalInsertions: zod.z.number(),
1188
- totalDeletions: zod.z.number(),
1189
- files: zod.z.array(FileStatsSchema)
1190
- })
1191
- });
1192
1191
  function isAskUserMessage(message) {
1193
1192
  return typeof message === "object" && message !== null && "type" in message && message.type === "ask_user";
1194
1193
  }
1195
1194
  function isAskUserResponseMessage(message) {
1196
1195
  return typeof message === "object" && message !== null && "type" in message && message.type === "ask_user_response";
1197
1196
  }
1198
- function isTaskArtifactsMessage(message) {
1199
- return typeof message === "object" && message !== null && "type" in message && message.type === "task_artifacts_updated";
1200
- }
1201
1197
  function isSDKMessage(message) {
1202
- 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";
1203
1199
  }
1204
1200
  const EventBaseSchema = zod.z.object({
1205
1201
  eventId: zod.z.string()
@@ -1373,10 +1369,10 @@ const StopTaskSchema = EventBaseSchema.extend({
1373
1369
  taskId: zod.z.string(),
1374
1370
  reason: zod.z.string().optional()
1375
1371
  });
1376
- const SubTaskGitStatsSchema = zod.z.object({
1377
- additions: zod.z.number(),
1378
- deletions: zod.z.number(),
1379
- fileCount: zod.z.number()
1372
+ const TaskArtifactsStatsSchema = zod.z.object({
1373
+ totalInsertions: zod.z.number(),
1374
+ totalDeletions: zod.z.number(),
1375
+ files: zod.z.array(FileStatsSchema)
1380
1376
  });
1381
1377
  const PreviewProjectTypeSchema = zod.z.enum([
1382
1378
  "html",
@@ -1402,9 +1398,9 @@ const PreviewMetadataSchema = zod.z.object({
1402
1398
  tailwindVersion: zod.z.union([zod.z.literal(3), zod.z.literal(4), zod.z.null()]).optional(),
1403
1399
  isStaticFileCollection: zod.z.boolean().optional()
1404
1400
  });
1405
- const SubTaskArtifactsSummarySchema = zod.z.object({
1401
+ const TaskArtifactsSummarySchema = zod.z.object({
1406
1402
  commitHash: zod.z.string(),
1407
- gitStats: SubTaskGitStatsSchema,
1403
+ stats: TaskArtifactsStatsSchema,
1408
1404
  preview: PreviewMetadataSchema.nullable()
1409
1405
  // Preview metadata computed by CLI
1410
1406
  });
@@ -1430,8 +1426,8 @@ const TaskMessageSchema = EventBaseSchema.extend({
1430
1426
  // Agent ID for message attribution
1431
1427
  rootTaskId: zod.z.string().optional(),
1432
1428
  // Root task ID for event routing
1433
- // Artifacts summary - attached to result messages for sub-task completion
1434
- artifacts: SubTaskArtifactsSummarySchema.optional()
1429
+ // Artifacts summary - attached to result messages for task completion
1430
+ artifacts: TaskArtifactsSummarySchema.optional()
1435
1431
  }).refine(
1436
1432
  (data) => {
1437
1433
  return !!data.message !== !!data.encryptedMessage;
@@ -1440,13 +1436,6 @@ const TaskMessageSchema = EventBaseSchema.extend({
1440
1436
  message: "Exactly one of message or encryptedMessage must be provided"
1441
1437
  }
1442
1438
  );
1443
- const TaskArtifactsUpdatedEventSchema = EventBaseSchema.extend({
1444
- taskId: zod.z.string(),
1445
- stats: zod.z.object({
1446
- totalInsertions: zod.z.number(),
1447
- totalDeletions: zod.z.number()
1448
- })
1449
- });
1450
1439
  const ShowModalEventDataSchema = EventBaseSchema.extend({
1451
1440
  taskId: zod.z.string(),
1452
1441
  chatId: zod.z.string().optional(),
@@ -1454,7 +1443,7 @@ const ShowModalEventDataSchema = EventBaseSchema.extend({
1454
1443
  timestamp: zod.z.string(),
1455
1444
  modalName: zod.z.string(),
1456
1445
  // e.g., "configure-env-vars"
1457
- modalData: zod.z.record(zod.z.any())
1446
+ modalData: zod.z.record(zod.z.string(), zod.z.any())
1458
1447
  // Modal-specific data
1459
1448
  });
1460
1449
  const ChangeTaskTitleEventSchema = EventBaseSchema.extend({
@@ -1562,7 +1551,7 @@ const UpdateTaskAgentSessionIdEventSchema = EventBaseSchema.extend({
1562
1551
  const TaskInfoUpdateEventDataSchema = EventBaseSchema.extend({
1563
1552
  taskId: zod.z.string(),
1564
1553
  chatId: zod.z.string(),
1565
- updates: zod.z.record(zod.z.any()).optional(),
1554
+ updates: zod.z.record(zod.z.string(), zod.z.any()).optional(),
1566
1555
  // Flexible updates object for any task fields
1567
1556
  updatedAt: zod.z.string()
1568
1557
  // ISO 8601 timestamp
@@ -1595,7 +1584,7 @@ const SubTaskResultUpdatedEventSchema = EventBaseSchema.extend({
1595
1584
  is_error: zod.z.boolean().optional()
1596
1585
  }),
1597
1586
  // Optional artifacts summary (for displaying in parent task chat)
1598
- artifacts: SubTaskArtifactsSummarySchema.optional()
1587
+ artifacts: TaskArtifactsSummarySchema.optional()
1599
1588
  });
1600
1589
  const MergePullRequestEventSchema = EventBaseSchema.extend({
1601
1590
  taskId: zod.z.string(),
@@ -1725,8 +1714,6 @@ const EventSchemaMap = {
1725
1714
  "task-state-change": TaskStateChangeEventSchema,
1726
1715
  "update-task-agent-session-id": UpdateTaskAgentSessionIdEventSchema,
1727
1716
  "task-info-update": TaskInfoUpdateEventDataSchema,
1728
- // Artifacts events
1729
- "task-artifacts-updated": TaskArtifactsUpdatedEventSchema,
1730
1717
  // Modal events
1731
1718
  "show-modal": ShowModalEventDataSchema,
1732
1719
  // Merge request events
@@ -1766,7 +1753,6 @@ const workerTaskEvents = [
1766
1753
  "worker-exit",
1767
1754
  "change-task-title",
1768
1755
  "update-task-agent-session-id",
1769
- "task-artifacts-updated",
1770
1756
  "merge-request",
1771
1757
  "merge-pr",
1772
1758
  "associate-repo"
@@ -1818,7 +1804,7 @@ const ClaudeConfigSchema = zod.z.object({
1818
1804
  fallbackModel: zod.z.string().optional(),
1819
1805
  maxTurns: zod.z.number().int().positive().optional(),
1820
1806
  // SDK native extra arguments
1821
- extraArgs: zod.z.record(zod.z.string().nullable()).optional(),
1807
+ extraArgs: zod.z.record(zod.z.string(), zod.z.string().nullable()).optional(),
1822
1808
  systemPrompt: zod.z.object({
1823
1809
  path: zod.z.string(),
1824
1810
  mode: zod.z.enum(["append", "replace"]).optional().default("append")
@@ -1964,7 +1950,8 @@ async function loadAgentConfig(options) {
1964
1950
  console.warn(`[AGENT] Warnings for agent "${agentId}":`, validation.warnings);
1965
1951
  }
1966
1952
  const metadata = await loadAgentMetadata(agentDir);
1967
- const frameworkDir = node_path.join(agentDir, `.${framework}`);
1953
+ const frameworkDirName = framework === "claude" ? "claude" : `.${framework}`;
1954
+ const frameworkDir = node_path.join(agentDir, frameworkDirName);
1968
1955
  if (!node_fs.existsSync(frameworkDir)) {
1969
1956
  throw new FrameworkNotSupportedError(agentId, framework);
1970
1957
  }
@@ -2002,7 +1989,7 @@ async function loadAgentMetadata(agentDir) {
2002
1989
  }
2003
1990
  }
2004
1991
  async function loadClaudeConfiguration(agentDir, metadata) {
2005
- const claudeDir = node_path.join(agentDir, ".claude");
1992
+ const claudeDir = node_path.join(agentDir, "claude");
2006
1993
  const validation = validateFrameworkDirectory(claudeDir, "claude");
2007
1994
  if (!validation.valid) {
2008
1995
  throw new AgentConfigValidationError(
@@ -2030,7 +2017,7 @@ async function loadClaudeConfiguration(agentDir, metadata) {
2030
2017
  }
2031
2018
  async function loadClaudeConfig(claudeDir) {
2032
2019
  const configPath = node_path.join(claudeDir, "config.json");
2033
- assertFileExists(configPath, ".claude/config.json");
2020
+ assertFileExists(configPath, "claude/config.json");
2034
2021
  try {
2035
2022
  const content = node_fs.readFileSync(configPath, "utf-8");
2036
2023
  const rawConfig = JSON.parse(content);
@@ -2039,7 +2026,7 @@ async function loadClaudeConfig(claudeDir) {
2039
2026
  } catch (error) {
2040
2027
  if (error instanceof SyntaxError) {
2041
2028
  throw new AgentConfigValidationError(
2042
- "Invalid JSON in .claude/config.json"
2029
+ "Invalid JSON in claude/config.json"
2043
2030
  );
2044
2031
  }
2045
2032
  throw new AgentConfigValidationError(
@@ -2050,7 +2037,7 @@ async function loadClaudeConfig(claudeDir) {
2050
2037
  async function loadSystemPrompt(claudeDir, promptFile) {
2051
2038
  const promptPath = node_path.join(claudeDir, promptFile);
2052
2039
  if (!node_fs.existsSync(promptPath)) {
2053
- throw new MissingAgentFileError(`.claude/${promptFile}`);
2040
+ throw new MissingAgentFileError(`claude/${promptFile}`);
2054
2041
  }
2055
2042
  try {
2056
2043
  return node_fs.readFileSync(promptPath, "utf-8");
@@ -2560,8 +2547,52 @@ async function findEntryFile(files, projectType, fs) {
2560
2547
  return path;
2561
2548
  }
2562
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
+ }
2563
2577
  return null;
2564
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
+ }
2565
2596
  function getPossibleEntryPaths(projectType) {
2566
2597
  switch (projectType) {
2567
2598
  case "html":
@@ -2801,15 +2832,13 @@ exports.StatsQuerySchema = StatsQuerySchema;
2801
2832
  exports.StopTaskRequestSchema = StopTaskRequestSchema;
2802
2833
  exports.StopTaskResponseSchema = StopTaskResponseSchema;
2803
2834
  exports.StopTaskSchema = StopTaskSchema;
2804
- exports.SubTaskArtifactsSummarySchema = SubTaskArtifactsSummarySchema;
2805
- exports.SubTaskGitStatsSchema = SubTaskGitStatsSchema;
2806
2835
  exports.SubTaskResultUpdatedEventSchema = SubTaskResultUpdatedEventSchema;
2807
2836
  exports.SyncCloudMachineResponseSchema = SyncCloudMachineResponseSchema;
2808
2837
  exports.SyncLocalMachineResponseSchema = SyncLocalMachineResponseSchema;
2809
2838
  exports.SyncMachineRequestSchema = SyncMachineRequestSchema;
2810
2839
  exports.SystemMessageSchema = SystemMessageSchema;
2811
- exports.TaskArtifactsMessageSchema = TaskArtifactsMessageSchema;
2812
- exports.TaskArtifactsUpdatedEventSchema = TaskArtifactsUpdatedEventSchema;
2840
+ exports.TaskArtifactsStatsSchema = TaskArtifactsStatsSchema;
2841
+ exports.TaskArtifactsSummarySchema = TaskArtifactsSummarySchema;
2813
2842
  exports.TaskInfoUpdateEventDataSchema = TaskInfoUpdateEventDataSchema;
2814
2843
  exports.TaskItemSchema = TaskItemSchema;
2815
2844
  exports.TaskMessageSchema = TaskMessageSchema;
@@ -2833,6 +2862,8 @@ exports.UpdateOAuthServerResponseSchema = UpdateOAuthServerResponseSchema;
2833
2862
  exports.UpdateTaskAgentSessionIdEventSchema = UpdateTaskAgentSessionIdEventSchema;
2834
2863
  exports.UpdateTaskTitleRequestSchema = UpdateTaskTitleRequestSchema;
2835
2864
  exports.UpdateTaskTitleResponseSchema = UpdateTaskTitleResponseSchema;
2865
+ exports.UpdateUserProfileRequestSchema = UpdateUserProfileRequestSchema;
2866
+ exports.UpdateUserProfileResponseSchema = UpdateUserProfileResponseSchema;
2836
2867
  exports.UploadUrlResultSchema = UploadUrlResultSchema;
2837
2868
  exports.UserBalanceResponseSchema = UserBalanceResponseSchema;
2838
2869
  exports.UserBasicInfoSchema = UserBasicInfoSchema;
@@ -2883,7 +2914,6 @@ exports.getRandomBytes = getRandomBytes;
2883
2914
  exports.isAskUserMessage = isAskUserMessage;
2884
2915
  exports.isAskUserResponseMessage = isAskUserResponseMessage;
2885
2916
  exports.isSDKMessage = isSDKMessage;
2886
- exports.isTaskArtifactsMessage = isTaskArtifactsMessage;
2887
2917
  exports.loadAgentConfig = loadAgentConfig;
2888
2918
  exports.machineAuth = machineAuth;
2889
2919
  exports.permissionResponseRequestSchema = permissionResponseRequestSchema;