@agentrix/shared 1.0.13 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -250,6 +250,7 @@ const StartTaskResponseSchema = zod.z.object({
250
250
  repositoryId: zod.z.string().nullable(),
251
251
  baseBranch: zod.z.string().nullable(),
252
252
  title: zod.z.string().nullable(),
253
+ userCwd: zod.z.string().nullable(),
253
254
  createdAt: DateSchema,
254
255
  updatedAt: DateSchema
255
256
  });
@@ -273,6 +274,8 @@ const TaskItemSchema = zod.z.object({
273
274
  dataEncryptionKey: zod.z.string().nullable(),
274
275
  cwd: zod.z.string().nullable(),
275
276
  // Current working directory from CLI worker
277
+ userCwd: zod.z.string().nullable(),
278
+ // User-provided working directory for local mode
276
279
  repositorySourceType: zod.z.enum(["temporary", "directory", "git-server"]).nullable(),
277
280
  // Repository source type
278
281
  pullRequestNumber: zod.z.number().nullable(),
@@ -534,6 +537,12 @@ const DisplayConfigSchema = zod.z.record(zod.z.string(), DisplayConfigKeysSchema
534
537
  const AgentCustomConfigSchema = zod.z.object({
535
538
  displayConfig: DisplayConfigSchema.optional()
536
539
  });
540
+ const AgentPermissionsSchema = zod.z.object({
541
+ role: zod.z.string(),
542
+ // "all" | "low"
543
+ path: zod.z.string()
544
+ // URL/path pattern
545
+ });
537
546
  const AgentSchema = zod.z.object({
538
547
  id: IdSchema,
539
548
  name: zod.z.string(),
@@ -549,7 +558,8 @@ const AgentSchema = zod.z.object({
549
558
  gitRepoId: zod.z.string().nullable(),
550
559
  supportLocal: zod.z.boolean(),
551
560
  enable: zod.z.boolean(),
552
- config: AgentCustomConfigSchema.nullable()
561
+ config: AgentCustomConfigSchema.nullable(),
562
+ permissions: AgentPermissionsSchema.nullable()
553
563
  });
554
564
  const ListAgentsResponseSchema = zod.z.object({
555
565
  agents: zod.z.array(AgentSchema)
@@ -585,6 +595,56 @@ const DeleteAgentResponseSchema = zod.z.object({
585
595
  message: zod.z.string(),
586
596
  agentId: IdSchema
587
597
  });
598
+ const DeploymentVariableSchema = zod.z.object({
599
+ name: zod.z.string(),
600
+ type: zod.z.enum(["string", "number", "boolean", "secret"]),
601
+ description: zod.z.string().optional(),
602
+ required: zod.z.boolean().default(false),
603
+ defaultValue: zod.z.string().optional()
604
+ });
605
+ const AgentBuilderConfigSchema = zod.z.object({
606
+ // UI messages (moved from top-level Agent fields)
607
+ guildMsg: zod.z.string().default("what can I do for you today?"),
608
+ placeholderMsg: zod.z.string().default("Ask me anything..."),
609
+ // Deployment configuration (from CLI envVars)
610
+ deploymentSchema: zod.z.array(DeploymentVariableSchema).optional(),
611
+ // Display configuration (same as AgentCustomConfig)
612
+ displayConfig: DisplayConfigSchema.optional()
613
+ });
614
+ const CreateAgentBuilderRequestSchema = zod.z.object({
615
+ name: zod.z.string().min(1, "Name is required"),
616
+ agentDir: zod.z.string().min(1, "Agent directory is required"),
617
+ type: AgentTypeSchema.default("claude"),
618
+ avatar: zod.z.string().optional(),
619
+ description: zod.z.string().optional(),
620
+ userId: zod.z.string(),
621
+ taskId: zod.z.string(),
622
+ envVars: zod.z.array(DeploymentVariableSchema).optional()
623
+ // From CLI tool
624
+ });
625
+ const AgentBuilderSchema = zod.z.object({
626
+ id: IdSchema,
627
+ name: zod.z.string(),
628
+ displayName: zod.z.string(),
629
+ agentDir: zod.z.string(),
630
+ type: AgentTypeSchema,
631
+ avatar: zod.z.string().nullable(),
632
+ userId: zod.z.string(),
633
+ description: zod.z.string().nullable(),
634
+ enable: zod.z.boolean(),
635
+ config: AgentBuilderConfigSchema.nullable(),
636
+ permissions: AgentPermissionsSchema.nullable(),
637
+ publishedAgentId: zod.z.string().nullable(),
638
+ sourceTaskId: zod.z.string().nullable(),
639
+ createdAt: zod.z.string(),
640
+ updatedAt: zod.z.string()
641
+ });
642
+ const GetUserAgentsResponseSchema = zod.z.object({
643
+ agents: zod.z.array(AgentSchema),
644
+ // Published agents
645
+ builders: zod.z.array(AgentBuilderSchema)
646
+ // Draft agent-builders
647
+ });
588
648
 
589
649
  const LocalMachineSchema = zod.z.object({
590
650
  id: IdSchema,
@@ -943,6 +1003,28 @@ const GitServerSchema = zod.z.object({
943
1003
  const ListGitServersResponseSchema = zod.z.array(GitServerSchema);
944
1004
  const GetGitServerResponseSchema = GitServerSchema;
945
1005
 
1006
+ const RpcCallEventSchema = zod.z.object({
1007
+ eventId: zod.z.string(),
1008
+ taskId: zod.z.string(),
1009
+ method: zod.z.enum(["GET", "POST", "PATCH", "DELETE"]),
1010
+ path: zod.z.string(),
1011
+ // API path, e.g., "/v1/agent-builder"
1012
+ query: zod.z.record(zod.z.any()).optional(),
1013
+ // Query params for GET requests
1014
+ body: zod.z.any().optional()
1015
+ // Request body for POST/PATCH/DELETE
1016
+ });
1017
+ const RpcResponseSchema = zod.z.object({
1018
+ success: zod.z.boolean(),
1019
+ status: zod.z.number().optional(),
1020
+ // HTTP status code
1021
+ data: zod.z.any().optional(),
1022
+ error: zod.z.object({
1023
+ code: zod.z.string(),
1024
+ message: zod.z.string()
1025
+ }).optional()
1026
+ });
1027
+
946
1028
  const AskUserOptionSchema = zod.z.object({
947
1029
  label: zod.z.string(),
948
1030
  // Option label (1-5 words)
@@ -1011,6 +1093,12 @@ const WorkerInitializingSchema = EventBaseSchema.extend({
1011
1093
  timestamp: zod.z.string(),
1012
1094
  cwd: zod.z.string().optional()
1013
1095
  });
1096
+ const WorkerInitializedSchema = EventBaseSchema.extend({
1097
+ taskId: zod.z.string(),
1098
+ machineId: zod.z.string(),
1099
+ timestamp: zod.z.string(),
1100
+ cwd: zod.z.string().optional()
1101
+ });
1014
1102
  const WorkerReadySchema = EventBaseSchema.extend({
1015
1103
  taskId: zod.z.string(),
1016
1104
  machineId: zod.z.string(),
@@ -1046,10 +1134,14 @@ const baseTaskSchema = EventBaseSchema.extend({
1046
1134
  chatId: zod.z.string(),
1047
1135
  agentId: zod.z.string(),
1048
1136
  agentType: zod.z.string().optional().default("claude"),
1137
+ agentDir: zod.z.string().optional(),
1138
+ // Absolute path to agent directory (only for agent-builders)
1049
1139
  gitUrl: zod.z.string().optional(),
1050
1140
  baseBranch: zod.z.string().optional(),
1051
1141
  cwd: zod.z.string().optional(),
1052
1142
  // Current working directory for the task, only used under 'local' mode
1143
+ userCwd: zod.z.string().optional(),
1144
+ // User-provided working directory for local mode
1053
1145
  dataEncryptionKey: zod.z.string().optional(),
1054
1146
  // User's public key for encrypting sensitive data
1055
1147
  model: zod.z.string().optional(),
@@ -1156,6 +1248,39 @@ const TaskStateChangeEventSchema = EventBaseSchema.extend({
1156
1248
  updatedAt: zod.z.string()
1157
1249
  });
1158
1250
  const CreditExhaustedEventSchema = EventBaseSchema.extend({});
1251
+ const RtcIceServerSchema = zod.z.object({
1252
+ urls: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
1253
+ username: zod.z.string().optional(),
1254
+ credential: zod.z.string().optional()
1255
+ });
1256
+ const RtcIceServersRequestSchema = EventBaseSchema.extend({});
1257
+ const RtcIceServersResponseSchema = EventBaseSchema.extend({
1258
+ iceServers: zod.z.array(RtcIceServerSchema)
1259
+ });
1260
+ const MachineRtcRequestSchema = EventBaseSchema.extend({
1261
+ machineId: zod.z.string(),
1262
+ sessionId: zod.z.string(),
1263
+ role: zod.z.literal("app"),
1264
+ userId: zod.z.string().optional()
1265
+ });
1266
+ const MachineRtcResponseSchema = EventBaseSchema.extend({
1267
+ machineId: zod.z.string(),
1268
+ sessionId: zod.z.string(),
1269
+ accepted: zod.z.boolean(),
1270
+ reason: zod.z.string().optional(),
1271
+ userId: zod.z.string().optional(),
1272
+ capabilities: zod.z.object({
1273
+ dataChannel: zod.z.boolean().optional(),
1274
+ maxMessageSize: zod.z.number().optional()
1275
+ }).optional()
1276
+ });
1277
+ const RtcSignalSchema = EventBaseSchema.extend({
1278
+ machineId: zod.z.string(),
1279
+ sessionId: zod.z.string(),
1280
+ from: zod.z.enum(["app", "machine"]),
1281
+ signal: zod.z.any(),
1282
+ userId: zod.z.string().optional()
1283
+ });
1159
1284
  const WorkspaceFileRequestSchema = EventBaseSchema.extend({
1160
1285
  taskId: zod.z.string(),
1161
1286
  userId: zod.z.string(),
@@ -1290,6 +1415,7 @@ const EventSchemaMap = {
1290
1415
  "machine-alive": MachineAliveEventSchema,
1291
1416
  // Worker events
1292
1417
  "worker-initializing": WorkerInitializingSchema,
1418
+ "worker-initialized": WorkerInitializedSchema,
1293
1419
  "worker-ready": WorkerReadySchema,
1294
1420
  "worker-alive": WorkerAliveEventSchema,
1295
1421
  "worker-exit": WorkerExitSchema,
@@ -1316,14 +1442,23 @@ const EventSchemaMap = {
1316
1442
  "system-message": SystemMessageSchema,
1317
1443
  // Billing events
1318
1444
  "credit-exhausted": CreditExhaustedEventSchema,
1445
+ // RTC signaling events
1446
+ "rtc-ice-servers-request": RtcIceServersRequestSchema,
1447
+ "rtc-ice-servers-response": RtcIceServersResponseSchema,
1448
+ "machine-rtc-request": MachineRtcRequestSchema,
1449
+ "machine-rtc-response": MachineRtcResponseSchema,
1450
+ "rtc-signal": RtcSignalSchema,
1319
1451
  // Workspace file events
1320
1452
  "workspace-file-request": WorkspaceFileRequestSchema,
1321
1453
  "workspace-file-response": WorkspaceFileResponseSchema,
1454
+ // RPC events
1455
+ "rpc-call": RpcCallEventSchema,
1322
1456
  // Ack events
1323
1457
  "event-ack": EventAckSchema
1324
1458
  };
1325
1459
  const workerTaskEvents = [
1326
1460
  "worker-initializing",
1461
+ "worker-initialized",
1327
1462
  "worker-ready",
1328
1463
  "worker-running",
1329
1464
  "worker-exit",
@@ -1512,9 +1647,9 @@ function isValidPluginDirectory(pluginDir) {
1512
1647
  }
1513
1648
 
1514
1649
  async function loadAgentConfig(options) {
1515
- const { agentId, framework, validateOnly = false } = options;
1650
+ const { agentId, framework, validateOnly = false, agentDir: providedAgentDir } = options;
1516
1651
  const agentContext = getAgentContext();
1517
- const agentDir = agentContext.resolveAgentDir(agentId);
1652
+ const agentDir = providedAgentDir || agentContext.resolveAgentDir(agentId);
1518
1653
  assertAgentExists(agentDir, agentId);
1519
1654
  const validation = validateAgentDirectory(agentDir);
1520
1655
  if (!validation.valid) {
@@ -1861,14 +1996,63 @@ function decryptFileContent(encryptedContent, dataKey) {
1861
1996
  }
1862
1997
  }
1863
1998
 
1999
+ const RTC_CHUNK_HEADER_SIZE = 16;
2000
+ const RtcChunkFlags = {
2001
+ Start: 1,
2002
+ End: 2,
2003
+ Binary: 4,
2004
+ Compressed: 8
2005
+ };
2006
+ function encodeRtcChunkHeader(header) {
2007
+ const buffer = new ArrayBuffer(RTC_CHUNK_HEADER_SIZE);
2008
+ const view = new DataView(buffer);
2009
+ view.setUint32(0, header.streamId);
2010
+ view.setUint32(4, header.seq);
2011
+ view.setUint16(8, header.flags);
2012
+ view.setUint16(10, header.reserved ?? 0);
2013
+ view.setUint32(12, header.payloadLength);
2014
+ return new Uint8Array(buffer);
2015
+ }
2016
+ function decodeRtcChunkHeader(data) {
2017
+ if (data.byteLength < RTC_CHUNK_HEADER_SIZE) {
2018
+ throw new Error(`RTC chunk header requires ${RTC_CHUNK_HEADER_SIZE} bytes`);
2019
+ }
2020
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
2021
+ return {
2022
+ streamId: view.getUint32(0),
2023
+ seq: view.getUint32(4),
2024
+ flags: view.getUint16(8),
2025
+ reserved: view.getUint16(10),
2026
+ payloadLength: view.getUint32(12)
2027
+ };
2028
+ }
2029
+ function buildRtcChunkFrame(header, payload) {
2030
+ const headerBytes = encodeRtcChunkHeader({
2031
+ ...header,
2032
+ payloadLength: payload.length
2033
+ });
2034
+ const frame = new Uint8Array(RTC_CHUNK_HEADER_SIZE + payload.length);
2035
+ frame.set(headerBytes, 0);
2036
+ frame.set(payload, RTC_CHUNK_HEADER_SIZE);
2037
+ return frame;
2038
+ }
2039
+ function splitRtcChunkFrame(data) {
2040
+ const header = decodeRtcChunkHeader(data);
2041
+ const payload = data.slice(RTC_CHUNK_HEADER_SIZE, RTC_CHUNK_HEADER_SIZE + header.payloadLength);
2042
+ return { header, payload };
2043
+ }
2044
+
1864
2045
  exports.AddChatMemberRequestSchema = AddChatMemberRequestSchema;
1865
2046
  exports.AddChatMemberResponseSchema = AddChatMemberResponseSchema;
2047
+ exports.AgentBuilderConfigSchema = AgentBuilderConfigSchema;
2048
+ exports.AgentBuilderSchema = AgentBuilderSchema;
1866
2049
  exports.AgentConfigValidationError = AgentConfigValidationError;
1867
2050
  exports.AgentCustomConfigSchema = AgentCustomConfigSchema;
1868
2051
  exports.AgentError = AgentError;
1869
2052
  exports.AgentLoadError = AgentLoadError;
1870
2053
  exports.AgentMetadataSchema = AgentMetadataSchema;
1871
2054
  exports.AgentNotFoundError = AgentNotFoundError;
2055
+ exports.AgentPermissionsSchema = AgentPermissionsSchema;
1872
2056
  exports.AgentSchema = AgentSchema;
1873
2057
  exports.AgentTypeSchema = AgentTypeSchema;
1874
2058
  exports.ApiErrorSchema = ApiErrorSchema;
@@ -1905,6 +2089,7 @@ exports.CloudSchema = CloudSchema;
1905
2089
  exports.ConfirmUploadRequestSchema = ConfirmUploadRequestSchema;
1906
2090
  exports.ConfirmUploadResponseSchema = ConfirmUploadResponseSchema;
1907
2091
  exports.ConsumeTransactionSchema = ConsumeTransactionSchema;
2092
+ exports.CreateAgentBuilderRequestSchema = CreateAgentBuilderRequestSchema;
1908
2093
  exports.CreateAgentRequestSchema = CreateAgentRequestSchema;
1909
2094
  exports.CreateAgentResponseSchema = CreateAgentResponseSchema;
1910
2095
  exports.CreateChatRequestSchema = CreateChatRequestSchema;
@@ -1922,6 +2107,7 @@ exports.CreditsPackageSchema = CreditsPackageSchema;
1922
2107
  exports.DateSchema = DateSchema;
1923
2108
  exports.DeleteAgentResponseSchema = DeleteAgentResponseSchema;
1924
2109
  exports.DeleteOAuthServerResponseSchema = DeleteOAuthServerResponseSchema;
2110
+ exports.DeploymentVariableSchema = DeploymentVariableSchema;
1925
2111
  exports.DisplayConfigKeysSchema = DisplayConfigKeysSchema;
1926
2112
  exports.DisplayConfigSchema = DisplayConfigSchema;
1927
2113
  exports.EventAckSchema = EventAckSchema;
@@ -1941,6 +2127,7 @@ exports.GetOAuthServerResponseSchema = GetOAuthServerResponseSchema;
1941
2127
  exports.GetRepositoryResponseSchema = GetRepositoryResponseSchema;
1942
2128
  exports.GetUploadUrlsRequestSchema = GetUploadUrlsRequestSchema;
1943
2129
  exports.GetUploadUrlsResponseSchema = GetUploadUrlsResponseSchema;
2130
+ exports.GetUserAgentsResponseSchema = GetUserAgentsResponseSchema;
1944
2131
  exports.GitHubIssueListItemSchema = GitHubIssueListItemSchema;
1945
2132
  exports.GitHubIssueSchema = GitHubIssueSchema;
1946
2133
  exports.GitServerSchema = GitServerSchema;
@@ -1974,6 +2161,8 @@ exports.MachineApprovalStatusQuerySchema = MachineApprovalStatusQuerySchema;
1974
2161
  exports.MachineAuthAuthorizedResponseSchema = MachineAuthAuthorizedResponseSchema;
1975
2162
  exports.MachineAuthRequestSchema = MachineAuthRequestSchema;
1976
2163
  exports.MachineAuthResultQuerySchema = MachineAuthResultQuerySchema;
2164
+ exports.MachineRtcRequestSchema = MachineRtcRequestSchema;
2165
+ exports.MachineRtcResponseSchema = MachineRtcResponseSchema;
1977
2166
  exports.MergePullRequestEventSchema = MergePullRequestEventSchema;
1978
2167
  exports.MergeRequestEventSchema = MergeRequestEventSchema;
1979
2168
  exports.MissingAgentFileError = MissingAgentFileError;
@@ -1993,6 +2182,7 @@ exports.PermissionResponseResponseSchema = PermissionResponseResponseSchema;
1993
2182
  exports.ProjectDirectoryResponseSchema = ProjectDirectoryResponseSchema;
1994
2183
  exports.ProjectEntrySchema = ProjectEntrySchema;
1995
2184
  exports.QueryEventsRequestSchema = QueryEventsRequestSchema;
2185
+ exports.RTC_CHUNK_HEADER_SIZE = RTC_CHUNK_HEADER_SIZE;
1996
2186
  exports.RechargeResponseSchema = RechargeResponseSchema;
1997
2187
  exports.RemoveChatMemberRequestSchema = RemoveChatMemberRequestSchema;
1998
2188
  exports.RepositorySchema = RepositorySchema;
@@ -2000,6 +2190,13 @@ exports.ResetSecretRequestSchema = ResetSecretRequestSchema;
2000
2190
  exports.ResetSecretResponseSchema = ResetSecretResponseSchema;
2001
2191
  exports.ResumeTaskRequestSchema = ResumeTaskRequestSchema;
2002
2192
  exports.ResumeTaskResponseSchema = ResumeTaskResponseSchema;
2193
+ exports.RpcCallEventSchema = RpcCallEventSchema;
2194
+ exports.RpcResponseSchema = RpcResponseSchema;
2195
+ exports.RtcChunkFlags = RtcChunkFlags;
2196
+ exports.RtcIceServerSchema = RtcIceServerSchema;
2197
+ exports.RtcIceServersRequestSchema = RtcIceServersRequestSchema;
2198
+ exports.RtcIceServersResponseSchema = RtcIceServersResponseSchema;
2199
+ exports.RtcSignalSchema = RtcSignalSchema;
2003
2200
  exports.ShareAuthQuerySchema = ShareAuthQuerySchema;
2004
2201
  exports.ShareAuthResponseSchema = ShareAuthResponseSchema;
2005
2202
  exports.ShutdownMachineSchema = ShutdownMachineSchema;
@@ -2042,6 +2239,7 @@ exports.UserProfileResponseSchema = UserProfileResponseSchema;
2042
2239
  exports.UserWithOAuthAccountsSchema = UserWithOAuthAccountsSchema;
2043
2240
  exports.WorkerAliveEventSchema = WorkerAliveEventSchema;
2044
2241
  exports.WorkerExitSchema = WorkerExitSchema;
2242
+ exports.WorkerInitializedSchema = WorkerInitializedSchema;
2045
2243
  exports.WorkerInitializingSchema = WorkerInitializingSchema;
2046
2244
  exports.WorkerReadySchema = WorkerReadySchema;
2047
2245
  exports.WorkerRunningSchema = WorkerRunningSchema;
@@ -2051,6 +2249,7 @@ exports.WorkspaceFileResponseSchema = WorkspaceFileResponseSchema;
2051
2249
  exports.assertAgentExists = assertAgentExists;
2052
2250
  exports.assertFileExists = assertFileExists;
2053
2251
  exports.baseTaskSchema = baseTaskSchema;
2252
+ exports.buildRtcChunkFrame = buildRtcChunkFrame;
2054
2253
  exports.cancelTaskRequestSchema = cancelTaskRequestSchema;
2055
2254
  exports.cancelTaskSchema = cancelTaskSchema;
2056
2255
  exports.createEventId = createEventId;
@@ -2059,6 +2258,7 @@ exports.createKeyPairWithUit8Array = createKeyPairWithUit8Array;
2059
2258
  exports.createMergeRequestSchema = createMergeRequestSchema;
2060
2259
  exports.createTaskSchema = createTaskSchema;
2061
2260
  exports.decodeBase64 = decodeBase64;
2261
+ exports.decodeRtcChunkHeader = decodeRtcChunkHeader;
2062
2262
  exports.decryptAES = decryptAES;
2063
2263
  exports.decryptFileContent = decryptFileContent;
2064
2264
  exports.decryptMachineEncryptionKey = decryptMachineEncryptionKey;
@@ -2067,6 +2267,7 @@ exports.decryptWithEphemeralKey = decryptWithEphemeralKey;
2067
2267
  exports.discoverPlugins = discoverPlugins;
2068
2268
  exports.encodeBase64 = encodeBase64;
2069
2269
  exports.encodeBase64Url = encodeBase64Url;
2270
+ exports.encodeRtcChunkHeader = encodeRtcChunkHeader;
2070
2271
  exports.encryptAES = encryptAES;
2071
2272
  exports.encryptFileContent = encryptFileContent;
2072
2273
  exports.encryptMachineEncryptionKey = encryptMachineEncryptionKey;
@@ -2086,6 +2287,7 @@ exports.replacePromptPlaceholders = replacePromptPlaceholders;
2086
2287
  exports.resumeTaskRequestSchema = resumeTaskRequestSchema;
2087
2288
  exports.resumeTaskSchema = resumeTaskSchema;
2088
2289
  exports.setAgentContext = setAgentContext;
2290
+ exports.splitRtcChunkFrame = splitRtcChunkFrame;
2089
2291
  exports.startTaskSchema = startTaskSchema;
2090
2292
  exports.stopTaskRequestSchema = stopTaskRequestSchema;
2091
2293
  exports.userAuth = userAuth;