replicas-engine 0.1.699 → 0.1.700

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/README.md CHANGED
@@ -138,5 +138,6 @@ Outgoing endpoints:
138
138
  - `POST /v1/engine/chat-turn-activity`
139
139
  - `POST /v1/engine/skill-activity`
140
140
  - `POST /v1/engine/mcp-activity`
141
+ - `POST /v1/engine/token-usage`
141
142
 
142
143
  The previous `chat-turn-usage`, `skill-usage`, and `mcp-usage` paths remain accepted for older engine versions.
@@ -297,6 +297,9 @@ var ASTER_MODEL_LABELS = {
297
297
  function isRecord(value) {
298
298
  return typeof value === "object" && value !== null && !Array.isArray(value);
299
299
  }
300
+ function isNonEmptyString(value) {
301
+ return typeof value === "string" && value.trim().length > 0;
302
+ }
300
303
 
301
304
  // ../shared/src/engine/types.ts
302
305
  var DEFAULT_CHAT_TITLES = {
@@ -675,8 +678,11 @@ var AGENT_CREDENTIAL_METHODS_IN_ORDER = {
675
678
  };
676
679
 
677
680
  // ../shared/src/analytics/types.ts
681
+ function hasAgentChatActivityFields(value) {
682
+ return isRecord(value) && typeof value.chatId === "string" && typeof value.model === "string" && (value.credentialMethod === void 0 || isAuthMethod(value.credentialMethod)) && (value.credentialScope === void 0 || isCredentialScope(value.credentialScope)) && value.credentialMethod === void 0 === (value.credentialScope === void 0) && (value.senderUserId === void 0 || typeof value.senderUserId === "string") && typeof value.occurredAt === "string";
683
+ }
678
684
  function isAgentChatActivityRecord(value) {
679
- return isRecord(value) && typeof value.chatId === "string" && typeof value.provider === "string" && isValidAgentProvider(value.provider) && typeof value.model === "string" && (value.credentialMethod === void 0 || isAuthMethod(value.credentialMethod)) && (value.credentialScope === void 0 || isCredentialScope(value.credentialScope)) && value.credentialMethod === void 0 === (value.credentialScope === void 0) && (value.senderUserId === void 0 || typeof value.senderUserId === "string") && typeof value.occurredAt === "string";
685
+ return hasAgentChatActivityFields(value) && typeof value.provider === "string" && isValidAgentProvider(value.provider);
680
686
  }
681
687
  var agentCredentialSnapshotSchema = z2.object({
682
688
  method: z2.enum(CREDENTIAL_METHOD),
@@ -706,6 +712,16 @@ function isAgentChatSkillActivityRecord(value) {
706
712
  function isAgentChatMcpActivityRecord(value) {
707
713
  return isNamedAgentChatActivityRecord(value, "mcpName");
708
714
  }
715
+ var TOKEN_USAGE_PATH = "/v1/engine/token-usage";
716
+ function isTokenCount(value) {
717
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
718
+ }
719
+ function isTokenUsageCounts(value) {
720
+ return isRecord(value) && isTokenCount(value.inputTokens) && isTokenCount(value.outputTokens) && isTokenCount(value.cacheReadInputTokens) && isTokenCount(value.cacheWriteInputTokens);
721
+ }
722
+ function isTokenUsageUploadRecord(value) {
723
+ return hasAgentChatActivityFields(value) && isNonEmptyString(value.harness) && isNonEmptyString(value.chatId) && isNonEmptyString(value.model) && isNonEmptyString(value.occurredAt) && Number.isFinite(Date.parse(value.occurredAt)) && (value.automationId === void 0 || isNonEmptyString(value.automationId)) && isNonEmptyString(value.environmentId) && (value.eventId === void 0 || isNonEmptyString(value.eventId)) && (value.pricingProvider === void 0 || isNonEmptyString(value.pricingProvider)) && (value.reportedCostUsd === void 0 || typeof value.reportedCostUsd === "number" && Number.isFinite(value.reportedCostUsd) && value.reportedCostUsd >= 0) && isTokenUsageCounts(value);
724
+ }
709
725
 
710
726
  // ../shared/src/event.ts
711
727
  var CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE = "claude-partial-message";
@@ -810,41 +826,43 @@ var createChatRequestSchema = z3.object({
810
826
  clientRequestId: z3.string().min(1).max(128).optional()
811
827
  });
812
828
  var sendChatMessageRequestSchema = z3.object({
813
- messageId: z3.string().optional(),
814
- submittedAt: z3.string().optional(),
815
- message: z3.string(),
829
+ messageId: z3.string().min(1).optional(),
830
+ submittedAt: z3.string().datetime().optional(),
831
+ message: z3.string().min(1),
816
832
  model: z3.string().optional(),
817
833
  customInstructions: z3.string().optional(),
818
834
  planMode: z3.boolean().optional(),
819
835
  images: z3.array(z3.object({
820
836
  type: z3.literal("image"),
821
837
  source: z3.discriminatedUnion("type", [
822
- z3.object({ type: z3.literal("base64"), media_type: z3.enum(IMAGE_MEDIA_TYPES), data: z3.string() }),
823
- z3.object({ type: z3.literal("url"), url: z3.string() })
838
+ z3.object({ type: z3.literal("base64"), media_type: z3.enum(IMAGE_MEDIA_TYPES), data: z3.string().min(1) }),
839
+ z3.object({ type: z3.literal("url"), url: z3.string().url() })
824
840
  ])
825
841
  })).optional(),
826
842
  thinkingLevel: z3.enum(VALID_THINKING_LEVELS).optional(),
827
843
  goalMode: z3.boolean().optional(),
828
844
  fastMode: z3.boolean().optional(),
829
845
  enableInteractiveTools: z3.boolean().optional(),
830
- type: z3.string().optional(),
846
+ type: z3.string().min(1).optional(),
831
847
  merge: z3.boolean().optional(),
832
- idempotencyKey: z3.string().optional(),
848
+ idempotencyKey: z3.string().min(1).max(128).optional(),
849
+ automationId: z3.string().optional(),
850
+ environmentId: z3.string().min(1).optional(),
833
851
  senderUserId: z3.string().optional(),
834
852
  senderEmail: z3.string().optional(),
835
853
  senderDisplayName: z3.string().optional(),
836
854
  senderAvatarUrl: z3.string().optional(),
837
855
  errorNotificationTarget: z3.discriminatedUnion("type", [
838
856
  z3.object({ type: z3.literal("slack") }),
839
- z3.object({ type: z3.literal("linear"), sessionId: z3.string() }),
857
+ z3.object({ type: z3.literal("linear"), sessionId: z3.string().min(1) }),
840
858
  z3.object({
841
859
  type: z3.literal("code_host"),
842
860
  provider: z3.enum(["github", "gitlab"]),
843
861
  resource: z3.enum(["issue", "pull_request"]),
844
- repositoryId: z3.string(),
845
- resourceNumber: z3.number()
862
+ repositoryId: z3.string().min(1),
863
+ resourceNumber: z3.number().int().positive()
846
864
  }),
847
- z3.object({ type: z3.literal("automation"), executionId: z3.string() })
865
+ z3.object({ type: z3.literal("automation"), executionId: z3.string().min(1) })
848
866
  ]).optional()
849
867
  }).passthrough();
850
868
  function isChatMessageSender(value) {
@@ -1388,6 +1406,45 @@ var PLANS = {
1388
1406
  var TEAM_PLAN = PLANS.team;
1389
1407
  var ENTERPRISE_PLAN = PLANS.enterprise;
1390
1408
 
1409
+ // ../shared/src/models-dev.ts
1410
+ import { z as z4 } from "zod";
1411
+ var MODELS_DEV_API_URL = "https://models.dev/api.json";
1412
+ var MODELS_DEV_CACHE_MS = 5 * 6e4;
1413
+ var modelsDevCatalogSchema = z4.record(z4.string(), z4.object({
1414
+ models: z4.record(z4.string(), z4.object({
1415
+ id: z4.string().optional(),
1416
+ name: z4.string(),
1417
+ description: z4.string().optional(),
1418
+ status: z4.enum(["alpha", "beta", "deprecated"]).optional(),
1419
+ cost: z4.object({
1420
+ input: z4.number().finite().nonnegative().optional(),
1421
+ output: z4.number().finite().nonnegative().optional(),
1422
+ cache_read: z4.number().finite().nonnegative().optional(),
1423
+ cache_write: z4.number().finite().nonnegative().optional()
1424
+ }).optional()
1425
+ }))
1426
+ }));
1427
+ var catalogCache;
1428
+ var catalogRequest;
1429
+ async function fetchModelsDevCatalog() {
1430
+ if (catalogCache && catalogCache.expiresAt > Date.now()) return catalogCache.catalog;
1431
+ catalogRequest ??= (async () => {
1432
+ const response = await fetch(MODELS_DEV_API_URL, { signal: AbortSignal.timeout(5e3) });
1433
+ if (!response.ok) throw new Error(`Failed to load models.dev catalog (${response.status})`);
1434
+ return modelsDevCatalogSchema.parse(await response.json());
1435
+ })();
1436
+ try {
1437
+ const catalog = await catalogRequest;
1438
+ catalogCache = { catalog, expiresAt: Date.now() + MODELS_DEV_CACHE_MS };
1439
+ return catalog;
1440
+ } catch (error) {
1441
+ if (catalogCache) return catalogCache.catalog;
1442
+ throw error;
1443
+ } finally {
1444
+ catalogRequest = void 0;
1445
+ }
1446
+ }
1447
+
1391
1448
  // ../shared/src/egress.ts
1392
1449
  var EGRESS_CIPHER = "2022-blake3-aes-256-gcm";
1393
1450
  var EGRESS_KEY_BYTES = 32;
@@ -3312,6 +3369,11 @@ function parseReplicasConfigString(content, filename) {
3312
3369
  return parseReplicasConfig(parsed, filename);
3313
3370
  }
3314
3371
 
3372
+ // ../shared/src/uuid.ts
3373
+ function createUuidFromHex(value) {
3374
+ return `${value.slice(0, 8)}-${value.slice(8, 12)}-5${value.slice(13, 16)}-${(Number.parseInt(value.slice(16, 17), 16) & 3 | 8).toString(16)}${value.slice(17, 20)}-${value.slice(20, 32)}`;
3375
+ }
3376
+
3315
3377
  // ../shared/src/errors.ts
3316
3378
  var TRANSIENT_NETWORK_ERROR_PATTERNS = [
3317
3379
  /socket connection was closed unexpectedly/,
@@ -3908,46 +3970,46 @@ var DEFAULT_WORKSPACE_FILTERS = {
3908
3970
  var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
3909
3971
 
3910
3972
  // ../shared/src/routes/workspace-events.ts
3911
- import { z as z4 } from "zod";
3912
- var workspaceChangedEventSchema = z4.discriminatedUnion("type", [
3913
- z4.object({
3914
- type: z4.literal("workspace.changed"),
3915
- workspaceId: z4.string(),
3916
- completion: z4.object({
3917
- workspaceName: z4.string(),
3918
- completedAt: z4.string(),
3919
- processing: z4.boolean().optional()
3973
+ import { z as z5 } from "zod";
3974
+ var workspaceChangedEventSchema = z5.discriminatedUnion("type", [
3975
+ z5.object({
3976
+ type: z5.literal("workspace.changed"),
3977
+ workspaceId: z5.string(),
3978
+ completion: z5.object({
3979
+ workspaceName: z5.string(),
3980
+ completedAt: z5.string(),
3981
+ processing: z5.boolean().optional()
3920
3982
  }).optional(),
3921
- ts: z4.string()
3983
+ ts: z5.string()
3922
3984
  }),
3923
- z4.object({
3924
- type: z4.literal("workspace.chat.changed"),
3925
- workspaceId: z4.string(),
3926
- chatId: z4.string(),
3927
- ts: z4.string()
3985
+ z5.object({
3986
+ type: z5.literal("workspace.chat.changed"),
3987
+ workspaceId: z5.string(),
3988
+ chatId: z5.string(),
3989
+ ts: z5.string()
3928
3990
  }),
3929
- z4.object({ type: z4.literal("presence.changed"), ts: z4.string() }),
3930
- z4.object({
3931
- type: z4.literal("mobile-testing.changed"),
3932
- workspaceId: z4.string(),
3933
- ts: z4.string()
3991
+ z5.object({ type: z5.literal("presence.changed"), ts: z5.string() }),
3992
+ z5.object({
3993
+ type: z5.literal("mobile-testing.changed"),
3994
+ workspaceId: z5.string(),
3995
+ ts: z5.string()
3934
3996
  })
3935
3997
  ]);
3936
3998
 
3937
3999
  // ../shared/src/routes/presence.ts
3938
- import { z as z5 } from "zod";
3939
- var presenceStatusSchema = z5.enum(["online", "typing"]);
3940
- var presenceLocationSchema = z5.object({
3941
- environmentId: z5.string().optional(),
3942
- workspaceId: z5.string().optional()
4000
+ import { z as z6 } from "zod";
4001
+ var presenceStatusSchema = z6.enum(["online", "typing"]);
4002
+ var presenceLocationSchema = z6.object({
4003
+ environmentId: z6.string().optional(),
4004
+ workspaceId: z6.string().optional()
3943
4005
  });
3944
- var presenceEntrySchema = z5.object({
3945
- userId: z5.string(),
4006
+ var presenceEntrySchema = z6.object({
4007
+ userId: z6.string(),
3946
4008
  status: presenceStatusSchema,
3947
4009
  location: presenceLocationSchema,
3948
- ts: z5.string()
4010
+ ts: z6.string()
3949
4011
  });
3950
- var updatePresenceRequestSchema = z5.object({
4012
+ var updatePresenceRequestSchema = z6.object({
3951
4013
  status: presenceStatusSchema,
3952
4014
  location: presenceLocationSchema.optional()
3953
4015
  });
@@ -6473,32 +6535,32 @@ function parseChatTranscriptArtifact(value) {
6473
6535
  }
6474
6536
 
6475
6537
  // ../shared/src/memory.ts
6476
- import { z as z6 } from "zod";
6538
+ import { z as z7 } from "zod";
6477
6539
  var MEMORY_ROOT = `${SANDBOX_PATHS.REPLICAS_DIR}/memories`;
6478
6540
  var MEMORY_SUMMARY_FILENAME = "memory_summary.md";
6479
6541
  var MEMORY_INDEX_FILENAME = "MEMORY.md";
6480
6542
  var MEMORY_BUNDLE_FILENAME = "memory.tar.gz";
6481
- var memoryExtractionResultSchema = z6.object({
6482
- seatSummary: z6.string().nullable(),
6483
- organizationSummary: z6.string().nullable()
6543
+ var memoryExtractionResultSchema = z7.object({
6544
+ seatSummary: z7.string().nullable(),
6545
+ organizationSummary: z7.string().nullable()
6484
6546
  });
6485
- var { $schema: _, ...MEMORY_EXTRACTION_SCHEMA } = z6.toJSONSchema(memoryExtractionResultSchema);
6486
- var memoryGenerationManifestSchema = z6.object({
6487
- domainId: z6.string(),
6488
- generation: z6.number().int().nonnegative(),
6489
- previousManifestKey: z6.string().nullable(),
6490
- createdAt: z6.string(),
6491
- promptVersion: z6.string(),
6492
- harness: z6.enum(["claude", "codex", "none"]),
6493
- model: z6.string(),
6494
- bundle: z6.object({
6495
- path: z6.literal(MEMORY_BUNDLE_FILENAME),
6496
- sha256: z6.string().regex(/^[a-f0-9]{64}$/),
6497
- sizeBytes: z6.number().int().positive()
6547
+ var { $schema: _, ...MEMORY_EXTRACTION_SCHEMA } = z7.toJSONSchema(memoryExtractionResultSchema);
6548
+ var memoryGenerationManifestSchema = z7.object({
6549
+ domainId: z7.string(),
6550
+ generation: z7.number().int().nonnegative(),
6551
+ previousManifestKey: z7.string().nullable(),
6552
+ createdAt: z7.string(),
6553
+ promptVersion: z7.string(),
6554
+ harness: z7.enum(["claude", "codex", "none"]),
6555
+ model: z7.string(),
6556
+ bundle: z7.object({
6557
+ path: z7.literal(MEMORY_BUNDLE_FILENAME),
6558
+ sha256: z7.string().regex(/^[a-f0-9]{64}$/),
6559
+ sizeBytes: z7.number().int().positive()
6498
6560
  }).nullable(),
6499
- files: z6.record(z6.string(), z6.string()),
6500
- rollouts: z6.record(z6.string(), z6.string()),
6501
- rolloutSources: z6.record(z6.string(), z6.string()).optional()
6561
+ files: z7.record(z7.string(), z7.string()),
6562
+ rollouts: z7.record(z7.string(), z7.string()),
6563
+ rolloutSources: z7.record(z7.string(), z7.string()).optional()
6502
6564
  });
6503
6565
 
6504
6566
  // ../shared/src/skill-registry.ts
@@ -6775,7 +6837,7 @@ var DEFAULT_CODEX_ARGS = [
6775
6837
  var MIN_CODEX_CLI_VERSION = "0.144.6";
6776
6838
  var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
6777
6839
  var codexCliVersionEnsured = null;
6778
- var ENGINE_PACKAGE_VERSION = "0.1.699";
6840
+ var ENGINE_PACKAGE_VERSION = "0.1.700";
6779
6841
  var INITIALIZE_METHOD = "initialize";
6780
6842
  var INITIALIZED_NOTIFICATION = "initialized";
6781
6843
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -7009,6 +7071,7 @@ var FILE_CHANGE_OUTPUT_DELTA_METHOD = "item/fileChange/outputDelta";
7009
7071
  var ACCOUNT_RATE_LIMITS_UPDATED_METHOD = "account/rateLimits/updated";
7010
7072
  var THREAD_TOKEN_USAGE_UPDATED_METHOD = "thread/tokenUsage/updated";
7011
7073
  var THREAD_COMPACTED_METHOD = "thread/compacted";
7074
+ var MODEL_REROUTED_METHOD = "model/rerouted";
7012
7075
  function dispatchAspNotification(notification, handlers) {
7013
7076
  const handler = handlers[notification.method];
7014
7077
  if (!handler) return;
@@ -7031,6 +7094,7 @@ function recoverCompletedTurn(turn, completedItems, agentMessageDeltas) {
7031
7094
 
7032
7095
  export {
7033
7096
  isRecord,
7097
+ isNonEmptyString,
7034
7098
  TIMEOUT,
7035
7099
  raceWithTimeout,
7036
7100
  createSuccessResult,
@@ -7046,6 +7110,9 @@ export {
7046
7110
  isAgentChatTurnActivityRecord,
7047
7111
  isAgentChatSkillActivityRecord,
7048
7112
  isAgentChatMcpActivityRecord,
7113
+ TOKEN_USAGE_PATH,
7114
+ isTokenUsageCounts,
7115
+ isTokenUsageUploadRecord,
7049
7116
  CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE,
7050
7117
  getClaudePartialMessageStreamId,
7051
7118
  ACCEPTED_USER_MESSAGE_SOURCE,
@@ -7104,6 +7171,7 @@ export {
7104
7171
  normalizeAutoCompactThreshold,
7105
7172
  clampTokensToWindow,
7106
7173
  buildCodexTokenUsageContextUsagePayload,
7174
+ fetchModelsDevCatalog,
7107
7175
  SANDBOX_PATHS,
7108
7176
  REPLICAS_RUNTIME_ENV_ALIASES,
7109
7177
  readReplicasRuntimeEnv,
@@ -7133,6 +7201,7 @@ export {
7133
7201
  resolveWarmHookConfig,
7134
7202
  REPLICAS_CONFIG_FILENAMES,
7135
7203
  parseReplicasConfigString,
7204
+ createUuidFromHex,
7136
7205
  headlessAgentRequestSchema,
7137
7206
  extractErrorText,
7138
7207
  isTransientErrorText,
@@ -7145,6 +7214,7 @@ export {
7145
7214
  ENGINE_HEALTH_WAIT_QUERY_PARAM,
7146
7215
  ENGINE_HEALTH_MAX_WAIT_MS,
7147
7216
  createChatRequestSchema,
7217
+ sendChatMessageRequestSchema,
7148
7218
  isChatMessageSender,
7149
7219
  normalizeCodexAspTranscriptStatus,
7150
7220
  imageContentToUserMessageImages,
@@ -7224,6 +7294,7 @@ export {
7224
7294
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
7225
7295
  THREAD_TOKEN_USAGE_UPDATED_METHOD,
7226
7296
  THREAD_COMPACTED_METHOD,
7297
+ MODEL_REROUTED_METHOD,
7227
7298
  dispatchAspNotification,
7228
7299
  recoverCompletedTurn
7229
7300
  };
@@ -7,7 +7,7 @@ import {
7
7
  headlessAgentRequestSchema,
8
8
  putPresignedFile,
9
9
  recoverCompletedTurn
10
- } from "./chunk-UTGTXG54.js";
10
+ } from "./chunk-HMWJSWP2.js";
11
11
 
12
12
  // src/headless-agent.ts
13
13
  import { createHash } from "crypto";