nexus-agents 2.171.0 → 2.172.0

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.js CHANGED
@@ -7,6 +7,8 @@ import {
7
7
  ARTIFACT_TYPES,
8
8
  AUDIT_PIPELINE_TEMPLATE,
9
9
  ActivationStrategySchema,
10
+ AdapterConfigSchema,
11
+ AdapterFactory,
10
12
  AgentEventSchema,
11
13
  AgentMessageSchema,
12
14
  AgentRoleSchema,
@@ -73,6 +75,7 @@ import {
73
75
  DEFAULT_POLICIES,
74
76
  DEFAULT_RBAC,
75
77
  DEFAULT_RESOURCE_LIMITS,
78
+ DEFAULT_RETRY_CONFIG,
76
79
  DEFAULT_ROLE_MAPPINGS,
77
80
  DEFAULT_SKILL_LIBRARY_CONFIG,
78
81
  DEFAULT_SKILL_LOADER_CONFIG,
@@ -121,7 +124,10 @@ import {
121
124
  ForestResultSchema,
122
125
  ForestStateSchema,
123
126
  ForestStatisticsSchema,
127
+ GEMINI_MODELS,
128
+ GEMINI_MODEL_ALIASES,
124
129
  GENERAL_PIPELINE_TEMPLATE,
130
+ GeminiAdapter,
125
131
  GeminiResponseParser,
126
132
  GeneratedTestSchema,
127
133
  GetJobResultInputSchema,
@@ -148,6 +154,8 @@ import {
148
154
  MemoryWriteInputSchema,
149
155
  ModelSelectionSchema,
150
156
  NodeStateSchema,
157
+ OLLAMA_MODELS,
158
+ OllamaAdapter,
151
159
  OrchestrateInputSchema,
152
160
  OrchestrateOutputSchema,
153
161
  OrchestrationError,
@@ -175,11 +183,13 @@ import {
175
183
  PruningStrategy,
176
184
  QualitySignalsSchema,
177
185
  QueryTraceInputSchema,
186
+ RateLimiter,
178
187
  ReasoningDepthSchema,
179
188
  ReasoningNodeMetadataSchema,
180
189
  ReasoningNodeSchema,
181
190
  ReasoningStepTypeSchema,
182
191
  ReasoningTreeSchema,
192
+ RecoverableExpert,
183
193
  RegistryError,
184
194
  RegistryImportInputSchema,
185
195
  RepoAnalyzeInputSchema,
@@ -192,6 +202,7 @@ import {
192
202
  ResearchQueryInputSchema,
193
203
  ResearchSynthesizeInputSchema,
194
204
  ResultAggregator,
205
+ RetryExhaustedError,
195
206
  ReviewProtocol,
196
207
  ReviewResponseMessageSchema,
197
208
  RoutingDecisionSchema,
@@ -285,6 +296,7 @@ import {
285
296
  buildDependencyGraph,
286
297
  buildDependencyGraph2,
287
298
  buildPrReviewProposal,
299
+ calculateDelay,
288
300
  calculateDistributionStats,
289
301
  calculateMinSampleSize,
290
302
  calculateRegret,
@@ -296,6 +308,7 @@ import {
296
308
  checkPipelinePolicy,
297
309
  checkpointToResult,
298
310
  chunkByDirectory,
311
+ classifyExpertFailure,
299
312
  classifyTask,
300
313
  cleanupCheckpoint,
301
314
  clearTemplateCache,
@@ -333,15 +346,18 @@ import {
333
346
  createExecutionPlan,
334
347
  createFeedbackIntegration,
335
348
  createFeedbackSubscriber,
349
+ createGeminiAdapter,
336
350
  createInitializedWorkflowEngine,
337
351
  createInteractionGraph,
338
352
  createIsolatedRegistry,
339
353
  createMcpLogger,
354
+ createOllamaAdapter,
340
355
  createOrchestrator,
341
356
  createOrchestratorFactory,
342
357
  createOutcomeFeedbackCollector,
343
358
  createProductionWorkflowEngine,
344
359
  createProtocolFactory,
360
+ createRateLimiter,
345
361
  createRealWorkflowEngine,
346
362
  createResultAggregator,
347
363
  createRoutingDecision,
@@ -425,6 +441,7 @@ import {
425
441
  initializeBuiltInTemplates,
426
442
  initializeEventBusBridge,
427
443
  isCancelled,
444
+ isRetryableError as isRetryableError2,
428
445
  isStepCompleted,
429
446
  listTemplateIds,
430
447
  loadCheckpointState,
@@ -521,8 +538,10 @@ import {
521
538
  validateSkillProvenance,
522
539
  validateWorkflow,
523
540
  validateWorkflowDependencies,
524
- withLogging
525
- } from "./chunk-YIQ5Z7LV.js";
541
+ withLogging,
542
+ withRetry,
543
+ withRetryWrapper
544
+ } from "./chunk-C7TWCMK4.js";
526
545
  import {
527
546
  FALLBACK_SCANNER_DATA,
528
547
  buildPlanFromAnalysis,
@@ -556,7 +575,7 @@ import {
556
575
  getKnownNexusVarNames,
557
576
  startStdioServer,
558
577
  validateNexusEnv
559
- } from "./chunk-E53VLN73.js";
578
+ } from "./chunk-YKVO32BI.js";
560
579
  import {
561
580
  OPENAI_MODELS,
562
581
  OPENAI_MODEL_ALIASES,
@@ -680,7 +699,7 @@ import {
680
699
  ProposalSchema,
681
700
  ProposalStatusSchema,
682
701
  REJECTION_CATEGORIES,
683
- RateLimiter,
702
+ RateLimiter as RateLimiter2,
684
703
  RejectionCategorySchema,
685
704
  VOTING_THRESHOLDS,
686
705
  VoteSchema,
@@ -780,7 +799,6 @@ import {
780
799
  createCliDetectionCache,
781
800
  estimateTaskComplexity,
782
801
  executeCliRetryLoop,
783
- extractRequestSystemPrompt,
784
802
  getAvailableClis,
785
803
  getTimeoutForTask,
786
804
  getTimeoutForTaskAuto,
@@ -803,17 +821,14 @@ import {
803
821
  fromArray,
804
822
  mergeStreams,
805
823
  reduceStream,
806
- requireApiKey,
807
824
  skip,
808
825
  take,
809
826
  takeUntil,
810
827
  tapStream,
811
828
  transformStream,
812
- validateApiKeyPresence,
813
829
  withTimeout
814
830
  } from "./chunk-4KVAHGMB.js";
815
831
  import {
816
- DEFAULTS,
817
832
  PROVIDER_ENV_KEYS
818
833
  } from "./chunk-QFS5VOB6.js";
819
834
  import "./chunk-76Q63KJM.js";
@@ -880,17 +895,13 @@ import {
880
895
  detectTrend,
881
896
  err,
882
897
  extractNonErrorMessage,
883
- findCanonicalModel,
884
898
  formatZodError,
885
899
  generateWeatherReport,
886
- getCliModelName,
887
900
  getDefaultAvailableModelsCache,
888
901
  getDefaultRegistry,
889
- getErrorMessage,
890
902
  getOutcomeStore,
891
903
  getRandomProvider,
892
904
  getTimeProvider,
893
- getTokenEstimator,
894
905
  isErr,
895
906
  isOk,
896
907
  isZodError,
@@ -910,1242 +921,6 @@ import "./chunk-AXTD4TFK.js";
910
921
  import "./chunk-DHVMSIT5.js";
911
922
  import "./chunk-ZPWHCABL.js";
912
923
 
913
- // src/adapters/factory.ts
914
- import { z } from "zod";
915
- var AdapterConfigSchema = z.object({
916
- /** Provider identifier (e.g., 'anthropic', 'openai') */
917
- providerId: z.string().min(1, "Provider ID is required"),
918
- /** Model identifier (e.g., 'claude-sonnet-4', 'gpt-4o') */
919
- modelId: z.string().min(1, "Model ID is required"),
920
- /** API key for authentication (optional, may come from environment) */
921
- apiKey: z.string().optional(),
922
- /** Base URL for the API (optional, uses provider default) */
923
- baseUrl: z.url("Base URL must be a valid URL").optional(),
924
- /** Request timeout in milliseconds */
925
- timeout: z.number().positive("Timeout must be positive").optional(),
926
- /** Maximum number of retries for failed requests */
927
- maxRetries: z.number().int("Max retries must be an integer").min(0).optional()
928
- });
929
- var AdapterFactory = class {
930
- /**
931
- * Registry mapping provider IDs to their creator functions.
932
- */
933
- registry = /* @__PURE__ */ new Map();
934
- /**
935
- * Registers an adapter creator for a provider.
936
- *
937
- * @param providerId - Unique identifier for the provider (e.g., 'anthropic')
938
- * @param creator - Factory function that creates adapters for this provider
939
- * @param options - Registration options
940
- * @returns Result indicating success or failure
941
- *
942
- * @example
943
- * ```typescript
944
- * const result = factory.register('anthropic', (config) => new ClaudeAdapter(config));
945
- * if (!result.ok) {
946
- * console.error('Registration failed:', result.error.message);
947
- * }
948
- * ```
949
- */
950
- register(providerId, creator, options = {}) {
951
- const { allowOverwrite = false } = options;
952
- if (!providerId || providerId.trim() === "") {
953
- return err(
954
- new ConfigError("Provider ID cannot be empty", {
955
- context: { providerId }
956
- })
957
- );
958
- }
959
- if (this.registry.has(providerId) && !allowOverwrite) {
960
- return err(
961
- new ConfigError(`Provider '${providerId}' is already registered`, {
962
- context: { providerId, existingProviders: this.listProviders() }
963
- })
964
- );
965
- }
966
- this.registry.set(providerId, creator);
967
- return ok(void 0);
968
- }
969
- /**
970
- * Unregisters an adapter creator for a provider.
971
- *
972
- * @param providerId - The provider ID to unregister
973
- * @returns Result indicating whether the provider was removed
974
- */
975
- unregister(providerId) {
976
- if (!providerId || providerId.trim() === "") {
977
- return err(
978
- new ConfigError("Provider ID cannot be empty", {
979
- context: { providerId }
980
- })
981
- );
982
- }
983
- const deleted = this.registry.delete(providerId);
984
- return ok(deleted);
985
- }
986
- /**
987
- * Creates an adapter instance for the specified configuration.
988
- *
989
- * Validates the configuration against the schema, looks up the provider
990
- * in the registry, and invokes the creator function to produce an adapter.
991
- *
992
- * @param config - Adapter configuration specifying provider and settings
993
- * @returns Result containing the adapter or a ConfigError
994
- *
995
- * @example
996
- * ```typescript
997
- * const result = factory.create({
998
- * providerId: 'anthropic',
999
- * modelId: 'claude-sonnet-4',
1000
- * timeout: 30000,
1001
- * maxRetries: 3
1002
- * });
1003
- *
1004
- * if (result.ok) {
1005
- * const response = await result.value.complete(request);
1006
- * } else {
1007
- * console.error('Failed to create adapter:', result.error.message);
1008
- * }
1009
- * ```
1010
- */
1011
- create(config) {
1012
- const validationResult = this.validateConfig(config);
1013
- if (!validationResult.ok) {
1014
- return validationResult;
1015
- }
1016
- const validConfig = validationResult.value;
1017
- const creator = this.registry.get(validConfig.providerId);
1018
- if (creator === void 0) {
1019
- return err(
1020
- new ConfigError(`Provider '${validConfig.providerId}' is not registered`, {
1021
- context: {
1022
- providerId: validConfig.providerId,
1023
- availableProviders: this.listProviders()
1024
- }
1025
- })
1026
- );
1027
- }
1028
- return this.invokeCreator(creator, validConfig);
1029
- }
1030
- /**
1031
- * Validates adapter configuration against the schema.
1032
- */
1033
- validateConfig(config) {
1034
- const result = AdapterConfigSchema.safeParse(config);
1035
- if (!result.success) {
1036
- return err(
1037
- new ConfigError(`Invalid adapter configuration: ${formatZodError(result.error)}`, {
1038
- context: {
1039
- config: this.sanitizeConfig(config),
1040
- validationErrors: result.error.issues
1041
- }
1042
- })
1043
- );
1044
- }
1045
- return ok(result.data);
1046
- }
1047
- /**
1048
- * Invokes the creator function to create an adapter.
1049
- */
1050
- invokeCreator(creator, config) {
1051
- try {
1052
- return ok(creator(config));
1053
- } catch (error) {
1054
- return this.handleCreatorError(error, config);
1055
- }
1056
- }
1057
- /**
1058
- * Handles errors thrown by adapter creator functions.
1059
- */
1060
- handleCreatorError(error, config) {
1061
- const message = getErrorMessage(error);
1062
- const baseOptions = {
1063
- context: { providerId: config.providerId, modelId: config.modelId }
1064
- };
1065
- if (error instanceof Error) {
1066
- return err(
1067
- new ConfigError(`Failed to create adapter: ${message}`, {
1068
- ...baseOptions,
1069
- cause: error
1070
- })
1071
- );
1072
- }
1073
- return err(new ConfigError(`Failed to create adapter: ${message}`, baseOptions));
1074
- }
1075
- /**
1076
- * Checks if a provider is registered.
1077
- *
1078
- * @param providerId - The provider ID to check
1079
- * @returns True if the provider is registered
1080
- */
1081
- hasProvider(providerId) {
1082
- return this.registry.has(providerId);
1083
- }
1084
- /**
1085
- * Returns a list of all registered provider IDs.
1086
- *
1087
- * @returns Array of provider identifiers
1088
- */
1089
- listProviders() {
1090
- return Array.from(this.registry.keys());
1091
- }
1092
- /**
1093
- * Returns the number of registered providers.
1094
- *
1095
- * @returns Count of registered providers
1096
- */
1097
- get size() {
1098
- return this.registry.size;
1099
- }
1100
- /**
1101
- * Clears all registered providers.
1102
- * Useful for testing or resetting the factory state.
1103
- */
1104
- clear() {
1105
- this.registry.clear();
1106
- }
1107
- /**
1108
- * Sanitizes configuration for logging by removing sensitive fields.
1109
- *
1110
- * @param config - Configuration to sanitize
1111
- * @returns Sanitized configuration safe for logging
1112
- */
1113
- sanitizeConfig(config) {
1114
- const sanitized = { ...config };
1115
- if (config.apiKey !== void 0) {
1116
- sanitized["apiKey"] = "[REDACTED]";
1117
- }
1118
- return sanitized;
1119
- }
1120
- };
1121
-
1122
- // src/adapters/rate-limiter.ts
1123
- var RateLimiter2 = class {
1124
- capacity;
1125
- refillRate;
1126
- refillInterval;
1127
- tokens;
1128
- lastRefillTime;
1129
- /**
1130
- * Creates a new RateLimiter instance.
1131
- *
1132
- * @param config - Configuration options
1133
- * @throws {RateLimitError} If configuration is invalid
1134
- */
1135
- constructor(config) {
1136
- this.validateConfig(config);
1137
- this.capacity = config.capacity;
1138
- this.refillRate = config.refillRate;
1139
- this.refillInterval = config.refillInterval ?? 100;
1140
- this.tokens = config.capacity;
1141
- this.lastRefillTime = getTimeProvider().now();
1142
- }
1143
- /**
1144
- * Validates the configuration parameters.
1145
- */
1146
- validateConfig(config) {
1147
- if (config.capacity <= 0) {
1148
- throw new RateLimitError("Capacity must be a positive number", {
1149
- context: { capacity: config.capacity }
1150
- });
1151
- }
1152
- if (config.refillRate <= 0) {
1153
- throw new RateLimitError("Refill rate must be a positive number", {
1154
- context: { refillRate: config.refillRate }
1155
- });
1156
- }
1157
- if (config.refillInterval !== void 0 && config.refillInterval <= 0) {
1158
- throw new RateLimitError("Refill interval must be a positive number", {
1159
- context: { refillInterval: config.refillInterval }
1160
- });
1161
- }
1162
- }
1163
- /**
1164
- * Refills tokens based on elapsed time since last refill.
1165
- * Called automatically before token operations.
1166
- */
1167
- refill() {
1168
- const now = getTimeProvider().now();
1169
- const elapsedMs = now - this.lastRefillTime;
1170
- const elapsedSeconds = elapsedMs / 1e3;
1171
- const tokensToAdd = elapsedSeconds * this.refillRate;
1172
- if (tokensToAdd >= 1) {
1173
- this.tokens = Math.min(this.capacity, this.tokens + tokensToAdd);
1174
- this.lastRefillTime = now;
1175
- }
1176
- }
1177
- /**
1178
- * Attempts to acquire the specified number of tokens.
1179
- *
1180
- * @param tokens - Number of tokens to acquire (default: 1)
1181
- * @returns true if tokens were acquired, false if rate limited
1182
- *
1183
- * @example
1184
- * ```typescript
1185
- * if (limiter.tryAcquire(5)) {
1186
- * // Acquired 5 tokens
1187
- * }
1188
- * ```
1189
- */
1190
- tryAcquire(tokens = 1) {
1191
- if (tokens <= 0) {
1192
- return true;
1193
- }
1194
- if (tokens > this.capacity) {
1195
- return false;
1196
- }
1197
- this.refill();
1198
- if (this.tokens >= tokens) {
1199
- this.tokens -= tokens;
1200
- return true;
1201
- }
1202
- return false;
1203
- }
1204
- /**
1205
- * Attempts to acquire tokens and returns a Result with detailed information.
1206
- *
1207
- * @param tokens - Number of tokens to acquire (default: 1)
1208
- * @returns Result containing void on success, or RateLimitExceeded on failure
1209
- *
1210
- * @example
1211
- * ```typescript
1212
- * const result = limiter.acquire(5);
1213
- * if (!result.ok) {
1214
- * console.log(`Retry after ${result.error.retryAfterMs}ms`);
1215
- * }
1216
- * ```
1217
- */
1218
- acquire(tokens = 1) {
1219
- if (tokens <= 0) {
1220
- return ok(void 0);
1221
- }
1222
- if (tokens > this.capacity) {
1223
- return err({
1224
- type: "rate_limit_exceeded",
1225
- requested: tokens,
1226
- available: this.tokens,
1227
- retryAfterMs: Infinity
1228
- });
1229
- }
1230
- this.refill();
1231
- if (this.tokens >= tokens) {
1232
- this.tokens -= tokens;
1233
- return ok(void 0);
1234
- }
1235
- const deficit = tokens - this.tokens;
1236
- const retryAfterMs = Math.ceil(deficit / this.refillRate * 1e3);
1237
- return err({
1238
- type: "rate_limit_exceeded",
1239
- requested: tokens,
1240
- available: Math.floor(this.tokens),
1241
- retryAfterMs
1242
- });
1243
- }
1244
- /**
1245
- * Waits until the specified number of tokens are available, then acquires them.
1246
- *
1247
- * @param tokens - Number of tokens to acquire (default: 1)
1248
- * @returns Promise that resolves when tokens are acquired
1249
- * @throws {RateLimitError} If tokens exceed capacity (would wait forever)
1250
- *
1251
- * @example
1252
- * ```typescript
1253
- * await limiter.waitForTokens(10);
1254
- * // 10 tokens acquired
1255
- * ```
1256
- */
1257
- async waitForTokens(tokens = 1) {
1258
- if (tokens <= 0) {
1259
- return;
1260
- }
1261
- if (tokens > this.capacity) {
1262
- throw new RateLimitError(
1263
- `Cannot acquire ${String(tokens)} tokens: exceeds capacity of ${String(this.capacity)}`,
1264
- { context: { requested: tokens, capacity: this.capacity } }
1265
- );
1266
- }
1267
- while (!this.tryAcquire(tokens)) {
1268
- await this.sleep(this.refillInterval);
1269
- }
1270
- }
1271
- /**
1272
- * Sleeps for the specified duration.
1273
- */
1274
- sleep(ms) {
1275
- return new Promise((resolve3) => setTimeout(resolve3, ms));
1276
- }
1277
- /**
1278
- * Returns the current number of available tokens.
1279
- * Performs a refill before returning the count.
1280
- *
1281
- * @returns Number of available tokens (may be fractional)
1282
- */
1283
- getRemainingTokens() {
1284
- this.refill();
1285
- return this.tokens;
1286
- }
1287
- /**
1288
- * Returns the number of whole tokens available.
1289
- *
1290
- * @returns Integer number of available tokens
1291
- */
1292
- getAvailableTokens() {
1293
- return Math.floor(this.getRemainingTokens());
1294
- }
1295
- /**
1296
- * Resets the rate limiter to its initial state.
1297
- * The bucket is refilled to capacity.
1298
- */
1299
- reset() {
1300
- this.tokens = this.capacity;
1301
- this.lastRefillTime = getTimeProvider().now();
1302
- }
1303
- /**
1304
- * Returns the bucket's maximum capacity.
1305
- */
1306
- getCapacity() {
1307
- return this.capacity;
1308
- }
1309
- /**
1310
- * Returns the refill rate in tokens per second.
1311
- */
1312
- getRefillRate() {
1313
- return this.refillRate;
1314
- }
1315
- /**
1316
- * Calculates the time in milliseconds until the specified tokens are available.
1317
- *
1318
- * @param tokens - Number of tokens needed (default: 1)
1319
- * @returns Time in milliseconds until tokens are available, 0 if already available
1320
- */
1321
- getTimeUntilAvailable(tokens = 1) {
1322
- if (tokens <= 0) {
1323
- return 0;
1324
- }
1325
- if (tokens > this.capacity) {
1326
- return Infinity;
1327
- }
1328
- this.refill();
1329
- if (this.tokens >= tokens) {
1330
- return 0;
1331
- }
1332
- const deficit = tokens - this.tokens;
1333
- return Math.ceil(deficit / this.refillRate * 1e3);
1334
- }
1335
- };
1336
- function createRateLimiter(config) {
1337
- return new RateLimiter2(config);
1338
- }
1339
-
1340
- // src/adapters/retry.ts
1341
- var DEFAULT_RETRY_CONFIG = {
1342
- maxRetries: DEFAULTS.RETRY_DEFAULTS.maxRetries,
1343
- baseDelayMs: DEFAULTS.RETRY_DEFAULTS.baseDelayMs,
1344
- maxDelayMs: DEFAULTS.RETRY_DEFAULTS.maxDelayMs,
1345
- jitterFactor: DEFAULTS.RETRY_DEFAULTS.jitterFactor
1346
- };
1347
- var RetryExhaustedError = class extends NexusError {
1348
- /** Number of attempts made */
1349
- attempts;
1350
- /** The last error encountered */
1351
- lastError;
1352
- constructor(attempts, lastError) {
1353
- const message = `All ${String(attempts)} retry attempts exhausted`;
1354
- const options = {
1355
- code: ErrorCode.MODEL_ERROR,
1356
- context: {
1357
- attempts,
1358
- lastErrorMessage: lastError instanceof Error ? lastError.message : String(lastError)
1359
- }
1360
- };
1361
- if (lastError instanceof Error) {
1362
- options.cause = lastError;
1363
- }
1364
- super(message, options);
1365
- this.name = "RetryExhaustedError";
1366
- this.attempts = attempts;
1367
- this.lastError = lastError;
1368
- }
1369
- };
1370
- function calculateDelay(attempt, config) {
1371
- const exponentialDelay = config.baseDelayMs * Math.pow(2, attempt);
1372
- const cappedDelay = Math.min(exponentialDelay, config.maxDelayMs);
1373
- const jitterRange = cappedDelay * config.jitterFactor;
1374
- const jitter = (getRandomProvider().random() * 2 - 1) * jitterRange;
1375
- return Math.max(0, Math.floor(cappedDelay + jitter));
1376
- }
1377
- var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([
1378
- 408,
1379
- // Request Timeout
1380
- 429,
1381
- // Too Many Requests
1382
- 500,
1383
- // Internal Server Error
1384
- 502,
1385
- // Bad Gateway
1386
- 503,
1387
- // Service Unavailable
1388
- 504
1389
- // Gateway Timeout
1390
- ]);
1391
- var NON_RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([
1392
- 400,
1393
- // Bad Request
1394
- 401,
1395
- // Unauthorized
1396
- 403,
1397
- // Forbidden
1398
- 404,
1399
- // Not Found
1400
- 405,
1401
- // Method Not Allowed
1402
- 409,
1403
- // Conflict
1404
- 410,
1405
- // Gone
1406
- 422
1407
- // Unprocessable Entity
1408
- ]);
1409
- var RETRYABLE_ERROR_PATTERNS = [
1410
- /ECONNRESET/i,
1411
- /ECONNREFUSED/i,
1412
- /ETIMEDOUT/i,
1413
- /ENOTFOUND/i,
1414
- /ENETUNREACH/i,
1415
- /EAI_AGAIN/i,
1416
- /socket hang up/i,
1417
- /network/i,
1418
- /timeout/i,
1419
- /timed out/i,
1420
- /aborted/i
1421
- ];
1422
- function getStatusCode(error) {
1423
- if (error === null || error === void 0) {
1424
- return void 0;
1425
- }
1426
- if (typeof error === "object") {
1427
- const errorObj = error;
1428
- if (typeof errorObj["status"] === "number") {
1429
- return errorObj["status"];
1430
- }
1431
- if (typeof errorObj["response"] === "object" && errorObj["response"] !== null) {
1432
- const response = errorObj["response"];
1433
- if (typeof response["status"] === "number") {
1434
- return response["status"];
1435
- }
1436
- }
1437
- if (typeof errorObj["statusCode"] === "number") {
1438
- return errorObj["statusCode"];
1439
- }
1440
- }
1441
- return void 0;
1442
- }
1443
- function isRetryableError2(error) {
1444
- if (error === null || error === void 0) {
1445
- return false;
1446
- }
1447
- const statusCode = getStatusCode(error);
1448
- if (statusCode !== void 0) {
1449
- if (NON_RETRYABLE_STATUS_CODES.has(statusCode)) {
1450
- return false;
1451
- }
1452
- if (RETRYABLE_STATUS_CODES.has(statusCode)) {
1453
- return true;
1454
- }
1455
- }
1456
- if (error instanceof NexusError) {
1457
- const retryableCodes = [
1458
- ErrorCode.MODEL_RATE_LIMITED,
1459
- ErrorCode.MODEL_TIMEOUT,
1460
- ErrorCode.TIMEOUT_ERROR,
1461
- ErrorCode.RATE_LIMIT_ERROR,
1462
- // #3317 finding #7: a model temporarily unavailable (503/overloaded) is
1463
- // transient — retry. (MODEL_NOT_FOUND stays non-retryable: retry won't help.)
1464
- ErrorCode.MODEL_UNAVAILABLE
1465
- ];
1466
- return retryableCodes.includes(error.code);
1467
- }
1468
- if (error instanceof Error) {
1469
- const message = error.message;
1470
- for (const pattern of RETRYABLE_ERROR_PATTERNS) {
1471
- if (pattern.test(message)) {
1472
- return true;
1473
- }
1474
- }
1475
- }
1476
- return false;
1477
- }
1478
- function mergeConfig(config) {
1479
- return {
1480
- maxRetries: config.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,
1481
- baseDelayMs: config.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,
1482
- maxDelayMs: config.maxDelayMs ?? DEFAULT_RETRY_CONFIG.maxDelayMs,
1483
- jitterFactor: config.jitterFactor ?? DEFAULT_RETRY_CONFIG.jitterFactor
1484
- };
1485
- }
1486
- async function withRetry(operation, options = {}) {
1487
- const config = mergeConfig(options.config ?? {});
1488
- const isRetryable = options.isRetryable ?? isRetryableError2;
1489
- const onRetry = options.onRetry;
1490
- const maxAttempts = config.maxRetries + 1;
1491
- let lastError;
1492
- let attemptsMade = 0;
1493
- for (let attempt = 0; attempt < maxAttempts; attempt++) {
1494
- attemptsMade = attempt + 1;
1495
- try {
1496
- const result = await operation();
1497
- return ok(result);
1498
- } catch (error) {
1499
- lastError = error;
1500
- const isLastAttempt = attempt === maxAttempts - 1;
1501
- if (isLastAttempt || !isRetryable(error)) {
1502
- break;
1503
- }
1504
- const delayMs = calculateDelay(attempt, config);
1505
- if (onRetry) {
1506
- onRetry({
1507
- attempt: attempt + 1,
1508
- maxAttempts,
1509
- delayMs,
1510
- error
1511
- });
1512
- }
1513
- await sleep(delayMs);
1514
- }
1515
- }
1516
- return err(new RetryExhaustedError(attemptsMade, lastError));
1517
- }
1518
- function withRetryWrapper(fn, options = {}) {
1519
- return (...args) => withRetry(() => fn(...args), options);
1520
- }
1521
-
1522
- // src/adapters/ollama-adapter.ts
1523
- import { Ollama } from "ollama";
1524
-
1525
- // src/adapters/abort-utils.ts
1526
- var AbortError = class extends Error {
1527
- name = "AbortError";
1528
- constructor(message = "Operation aborted") {
1529
- super(message);
1530
- }
1531
- };
1532
- function raceAbort(promise, signal) {
1533
- if (signal === void 0) return promise;
1534
- if (signal.aborted) return Promise.reject(new AbortError());
1535
- return new Promise((resolve3, reject) => {
1536
- const onAbort = () => {
1537
- reject(new AbortError());
1538
- };
1539
- signal.addEventListener("abort", onAbort, { once: true });
1540
- promise.then(
1541
- (value) => {
1542
- signal.removeEventListener("abort", onAbort);
1543
- resolve3(value);
1544
- },
1545
- (error) => {
1546
- signal.removeEventListener("abort", onAbort);
1547
- reject(error instanceof Error ? error : new Error(String(error)));
1548
- }
1549
- );
1550
- });
1551
- }
1552
-
1553
- // src/adapters/ollama-adapter.ts
1554
- var OLLAMA_MODELS = {
1555
- LLAMA3_8B: "llama3:8b",
1556
- LLAMA3_70B: "llama3:70b",
1557
- LLAMA3_1_8B: "llama3.1:8b",
1558
- LLAMA3_2_3B: "llama3.2:3b",
1559
- MISTRAL: "mistral",
1560
- MISTRAL_NEMO: "mistral-nemo",
1561
- CODELLAMA: "codellama",
1562
- CODELLAMA_34B: "codellama:34b",
1563
- DEEPSEEK_CODER: "deepseek-coder",
1564
- QWEN2_5_CODER: "qwen2.5-coder",
1565
- PHI3: "phi3",
1566
- GEMMA2: "gemma2"
1567
- };
1568
- var DEFAULT_OLLAMA_HOST = "http://localhost:11434";
1569
- var DEFAULT_MAX_TOKENS = 2048;
1570
- function mapStopReason(reason) {
1571
- if (reason === void 0 || reason === "") return "end_turn";
1572
- switch (reason) {
1573
- case "stop":
1574
- return "end_turn";
1575
- case "length":
1576
- return "max_tokens";
1577
- case "tool_calls":
1578
- return "tool_use";
1579
- default:
1580
- return "end_turn";
1581
- }
1582
- }
1583
- function mapOllamaMessageToContent(message) {
1584
- const content = [];
1585
- const messageContent = message.content;
1586
- if (messageContent !== "" && messageContent.length > 0) {
1587
- content.push({ type: "text", text: messageContent });
1588
- }
1589
- const toolCalls = message.tool_calls;
1590
- if (toolCalls !== void 0 && toolCalls.length > 0) {
1591
- for (const tc of toolCalls) {
1592
- content.push({
1593
- type: "tool_use",
1594
- id: `tool_${String(getTimeProvider().now())}_${getRandomProvider().random().toString(36).slice(2, 9)}`,
1595
- name: tc.function.name,
1596
- input: tc.function.arguments
1597
- });
1598
- }
1599
- }
1600
- if (content.length === 0) content.push({ type: "text", text: "" });
1601
- return content;
1602
- }
1603
- function mapMessage(message) {
1604
- if (typeof message.content === "string") {
1605
- return { role: message.role, content: message.content };
1606
- }
1607
- const textParts = message.content.filter((b) => b.type === "text").map((b) => b.text);
1608
- const ollamaMessage = { role: message.role, content: textParts.join("\n") };
1609
- const toolResult = message.content.find(
1610
- (b) => b.type === "tool_result"
1611
- );
1612
- if (toolResult !== void 0) {
1613
- ollamaMessage.content = toolResult.content;
1614
- ollamaMessage.tool_name = toolResult.tool_use_id;
1615
- }
1616
- return ollamaMessage;
1617
- }
1618
- function mapTool(tool) {
1619
- const fn = { name: tool.name, description: tool.description };
1620
- const schema = tool.inputSchema;
1621
- const hasProperties = Object.keys(schema).length > 0;
1622
- if (hasProperties) {
1623
- fn.parameters = schema;
1624
- }
1625
- return { type: "function", function: fn };
1626
- }
1627
- function getModelCapabilities(modelId) {
1628
- const caps = [ModelCapability.COMPLETION, ModelCapability.STREAMING];
1629
- const lower = modelId.toLowerCase();
1630
- const toolModels = [
1631
- "llama3",
1632
- "mistral",
1633
- "qwen",
1634
- "deepseek",
1635
- "command-r",
1636
- "hermes",
1637
- "functionary"
1638
- ];
1639
- if (toolModels.some((m) => lower.includes(m))) caps.push(ModelCapability.TOOL_USE);
1640
- const visionModels = ["llava", "bakllava", "moondream", "llama3.2-vision"];
1641
- if (visionModels.some((m) => lower.includes(m))) caps.push(ModelCapability.VISION);
1642
- return caps;
1643
- }
1644
- var OllamaAdapter = class extends BaseAdapter {
1645
- client;
1646
- constructor(config) {
1647
- const baseUrl = config.baseUrl ?? DEFAULT_OLLAMA_HOST;
1648
- const baseConfig = {
1649
- providerId: "ollama",
1650
- modelId: config.modelId,
1651
- capabilities: getModelCapabilities(config.modelId),
1652
- baseUrl
1653
- };
1654
- if (config.timeout !== void 0) baseConfig.timeout = config.timeout;
1655
- if (config.maxRetries !== void 0) baseConfig.maxRetries = config.maxRetries;
1656
- super(baseConfig);
1657
- this.client = new Ollama({ host: baseUrl, headers: config.headers });
1658
- }
1659
- validateConfig() {
1660
- const baseResult = super.validateConfig();
1661
- if (!baseResult.ok) return baseResult;
1662
- if (this.modelId === "" || this.modelId.trim() === "") {
1663
- return err(
1664
- new ConfigError("Ollama model ID is required", { context: { providerId: this.providerId } })
1665
- );
1666
- }
1667
- return ok(void 0);
1668
- }
1669
- async complete(request) {
1670
- this.logRequest(request);
1671
- try {
1672
- const params = this.buildRequestParams(request);
1673
- const chatPromise = this.client.chat({ ...params, stream: false });
1674
- const response = await raceAbort(chatPromise, request.signal);
1675
- const result = this.mapResponse(response);
1676
- this.logResponse(result);
1677
- return ok(result);
1678
- } catch (error) {
1679
- return err(this.transformError(error));
1680
- }
1681
- }
1682
- async *stream(request) {
1683
- this.logRequest(request);
1684
- const [controller, iterable] = createStream();
1685
- this.executeStream(request, controller).catch((error) => {
1686
- controller.error(this.transformError(error));
1687
- });
1688
- yield* iterable;
1689
- }
1690
- countTokens(text) {
1691
- return Promise.resolve(getTokenEstimator().estimateText(text, "generic"));
1692
- }
1693
- async executeStream(request, controller) {
1694
- try {
1695
- const params = this.buildRequestParams(request);
1696
- const stream = await this.client.chat({ ...params, stream: true });
1697
- controller.push({ type: "message_start", message: { model: this.modelId } });
1698
- let hasStartedBlock = false;
1699
- for await (const chunk of stream) {
1700
- if (!hasStartedBlock) {
1701
- controller.push({
1702
- type: "content_block_start",
1703
- index: 0,
1704
- contentBlock: { type: "text", text: "" }
1705
- });
1706
- hasStartedBlock = true;
1707
- }
1708
- const chunkContent = chunk.message.content;
1709
- if (chunkContent.length > 0) {
1710
- controller.push({
1711
- type: "content_block_delta",
1712
- index: 0,
1713
- delta: { type: "text_delta", text: chunkContent }
1714
- });
1715
- }
1716
- if (chunk.done) {
1717
- controller.push({ type: "content_block_stop", index: 0 });
1718
- controller.push({
1719
- type: "message_delta",
1720
- delta: { stop_reason: mapStopReason(chunk.done_reason) },
1721
- usage: this.calcUsage(chunk)
1722
- });
1723
- controller.push({ type: "message_stop" });
1724
- }
1725
- }
1726
- controller.complete();
1727
- } catch (error) {
1728
- controller.error(this.transformError(error));
1729
- }
1730
- }
1731
- buildOptions(request) {
1732
- const options = {
1733
- num_predict: request.maxTokens ?? DEFAULT_MAX_TOKENS
1734
- };
1735
- if (request.temperature !== void 0) options["temperature"] = request.temperature;
1736
- if (request.stop !== void 0 && request.stop.length > 0) options["stop"] = request.stop;
1737
- return options;
1738
- }
1739
- applyFormatAndTools(params, request) {
1740
- if (request.tools !== void 0 && request.tools.length > 0)
1741
- params.tools = request.tools.map(mapTool);
1742
- if (request.responseFormat?.type === "json_object") params.format = "json";
1743
- else if (request.responseFormat?.type === "json_schema")
1744
- params.format = request.responseFormat.schema;
1745
- }
1746
- buildRequestParams(request) {
1747
- const messages = request.messages.filter((m) => m.role !== "system").map(mapMessage);
1748
- const systemPrompt = extractRequestSystemPrompt(request);
1749
- if (systemPrompt !== void 0) messages.unshift({ role: "system", content: systemPrompt });
1750
- const params = {
1751
- model: this.modelId,
1752
- messages,
1753
- options: this.buildOptions(request)
1754
- };
1755
- this.applyFormatAndTools(params, request);
1756
- return params;
1757
- }
1758
- mapResponse(response) {
1759
- return {
1760
- content: mapOllamaMessageToContent(response.message),
1761
- usage: this.calcUsage(response),
1762
- stopReason: mapStopReason(response.done_reason),
1763
- model: response.model
1764
- };
1765
- }
1766
- calcUsage(response) {
1767
- const input = response.prompt_eval_count;
1768
- const output = response.eval_count;
1769
- const inputCount = typeof input === "number" ? input : 0;
1770
- const outputCount = typeof output === "number" ? output : 0;
1771
- return {
1772
- inputTokens: inputCount,
1773
- outputTokens: outputCount,
1774
- totalTokens: inputCount + outputCount
1775
- };
1776
- }
1777
- };
1778
- function createOllamaAdapter(config) {
1779
- return new OllamaAdapter(config);
1780
- }
1781
-
1782
- // src/adapters/gemini-adapter.ts
1783
- import { GoogleGenAI } from "@google/genai";
1784
-
1785
- // src/adapters/gemini-types.ts
1786
- var GEMINI_MODELS = {
1787
- PRO_2_5: getCliModelName("gemini-pro"),
1788
- FLASH_2_5: getCliModelName("gemini-flash"),
1789
- // Legacy — not in canonical registry. Kept for backward compat.
1790
- FLASH_2_0: "gemini-2.0-flash",
1791
- PRO_1_5: "gemini-1.5-pro",
1792
- FLASH_1_5: "gemini-1.5-flash"
1793
- };
1794
- var GEMINI_MODEL_ALIASES = {
1795
- "gemini-2.0-flash": GEMINI_MODELS.FLASH_2_0,
1796
- "gemini-1.5-pro": GEMINI_MODELS.PRO_1_5,
1797
- "gemini-1.5-flash": GEMINI_MODELS.FLASH_1_5
1798
- };
1799
- var DEFAULT_MAX_TOKENS2 = 8192;
1800
- function mapStopReason2(finishReason) {
1801
- switch (finishReason) {
1802
- case "STOP":
1803
- return "end_turn";
1804
- case "MAX_TOKENS":
1805
- return "max_tokens";
1806
- case "STOP_SEQUENCE":
1807
- return "stop_sequence";
1808
- case "TOOL_CODE":
1809
- case "MALFORMED_FUNCTION_CALL":
1810
- return "tool_use";
1811
- default:
1812
- return "end_turn";
1813
- }
1814
- }
1815
- function mapMessageToContent(message) {
1816
- if (message.role === "system") {
1817
- return null;
1818
- }
1819
- const role = message.role === "assistant" ? "model" : "user";
1820
- const parts = [];
1821
- if (typeof message.content === "string") {
1822
- parts.push({ text: message.content });
1823
- } else {
1824
- for (const block of message.content) {
1825
- if (block.type === "text") {
1826
- parts.push({ text: block.text });
1827
- } else if (block.type === "tool_use") {
1828
- parts.push({
1829
- functionCall: {
1830
- name: block.name,
1831
- args: block.input
1832
- }
1833
- });
1834
- } else if (block.type === "tool_result") {
1835
- parts.push({
1836
- functionResponse: {
1837
- name: block.tool_use_id,
1838
- response: { result: block.content }
1839
- }
1840
- });
1841
- } else {
1842
- parts.push({
1843
- inlineData: {
1844
- mimeType: block.source.media_type,
1845
- data: block.source.data
1846
- }
1847
- });
1848
- }
1849
- }
1850
- }
1851
- return { role, parts };
1852
- }
1853
- function mapToolToFunctionDeclaration(tool) {
1854
- return {
1855
- name: tool.name,
1856
- description: tool.description,
1857
- parametersJsonSchema: {
1858
- type: "object",
1859
- properties: tool.inputSchema.properties ?? {},
1860
- required: tool.inputSchema.required ?? []
1861
- }
1862
- };
1863
- }
1864
- function resolveModelId(modelId) {
1865
- const canonical = findCanonicalModel("gemini", modelId);
1866
- if (canonical?.cliModelName !== void 0) return canonical.cliModelName;
1867
- return GEMINI_MODEL_ALIASES[modelId] ?? modelId;
1868
- }
1869
- function getModelCapabilities2(modelId) {
1870
- const capabilities = [
1871
- ModelCapability.COMPLETION,
1872
- ModelCapability.STREAMING,
1873
- ModelCapability.TOOL_USE,
1874
- ModelCapability.VISION
1875
- ];
1876
- const resolvedId = resolveModelId(modelId);
1877
- if (resolvedId.includes("2.5") || resolvedId.includes("2.0")) {
1878
- capabilities.push(ModelCapability.EXTENDED_THINKING);
1879
- }
1880
- return capabilities;
1881
- }
1882
-
1883
- // src/adapters/gemini-adapter.ts
1884
- function applyResponseFormat(config, responseFormat) {
1885
- if (responseFormat === void 0 || responseFormat.type === "text") return;
1886
- config.responseMimeType = "application/json";
1887
- if (responseFormat.type === "json_schema") {
1888
- config.responseSchema = responseFormat.schema;
1889
- }
1890
- }
1891
- var GeminiAdapter = class extends BaseAdapter {
1892
- client;
1893
- resolvedModelId;
1894
- /**
1895
- * Creates a new GeminiAdapter instance.
1896
- *
1897
- * @param config - Gemini adapter configuration
1898
- * @throws {ConfigError} If API key is missing
1899
- */
1900
- constructor(config) {
1901
- const resolvedModelId = resolveModelId(config.modelId);
1902
- const baseConfig = {
1903
- providerId: "google",
1904
- modelId: resolvedModelId,
1905
- capabilities: getModelCapabilities2(config.modelId),
1906
- apiKey: config.apiKey
1907
- };
1908
- if (config.timeout !== void 0) {
1909
- baseConfig.timeout = config.timeout;
1910
- }
1911
- if (config.maxRetries !== void 0) {
1912
- baseConfig.maxRetries = config.maxRetries;
1913
- }
1914
- super(baseConfig);
1915
- this.resolvedModelId = resolvedModelId;
1916
- requireApiKey(config.apiKey, "Google", config.modelId);
1917
- this.client = new GoogleGenAI({ apiKey: config.apiKey });
1918
- }
1919
- /**
1920
- * Validates adapter configuration.
1921
- * Extends base validation with Gemini-specific checks.
1922
- */
1923
- validateConfig() {
1924
- const baseResult = super.validateConfig();
1925
- if (!baseResult.ok) {
1926
- return baseResult;
1927
- }
1928
- const keyResult = validateApiKeyPresence(this.config.apiKey, this.providerId, this.modelId);
1929
- if (!keyResult.ok) return keyResult;
1930
- return ok(void 0);
1931
- }
1932
- /**
1933
- * Send a completion request to Gemini.
1934
- *
1935
- * @param request - The completion request
1936
- * @returns Result with response or ModelError
1937
- */
1938
- async complete(request) {
1939
- this.logRequest(request);
1940
- try {
1941
- const response = await this.executeCompletion(request);
1942
- this.logResponse(response);
1943
- return ok(response);
1944
- } catch (error) {
1945
- return err(this.transformError(error));
1946
- }
1947
- }
1948
- /**
1949
- * Stream a completion request from Gemini.
1950
- *
1951
- * @param request - The completion request
1952
- * @yields StreamChunk objects as they arrive
1953
- */
1954
- async *stream(request) {
1955
- this.logRequest(request);
1956
- const [controller, iterable] = createStream();
1957
- this.executeStream(request, controller).catch((error) => {
1958
- const modelError = this.transformError(error);
1959
- controller.error(modelError);
1960
- });
1961
- yield* iterable;
1962
- }
1963
- /**
1964
- * Count tokens in text using Gemini-specific estimation.
1965
- *
1966
- * @param text - Text to count tokens for
1967
- * @returns Approximate token count
1968
- */
1969
- countTokens(text) {
1970
- return Promise.resolve(getTokenEstimator().estimateText(text, "gemini"));
1971
- }
1972
- /**
1973
- * Executes the completion request against the Google AI API.
1974
- */
1975
- async executeCompletion(request) {
1976
- const params = this.buildRequestParams(request);
1977
- const response = await this.client.models.generateContent(params);
1978
- return this.mapResponse(response);
1979
- }
1980
- /** Stream controller type for executeStream. */
1981
- streamControllerType = {};
1982
- /**
1983
- * Emits the end-of-message events to the stream controller.
1984
- */
1985
- emitStreamEnd(controller, hasStartedBlock, index) {
1986
- if (hasStartedBlock) {
1987
- controller.push({ type: "content_block_stop", index });
1988
- }
1989
- controller.push({
1990
- type: "message_delta",
1991
- delta: { stop_reason: "end_turn" },
1992
- usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 }
1993
- });
1994
- controller.push({ type: "message_stop" });
1995
- controller.complete();
1996
- }
1997
- /**
1998
- * Executes streaming completion and pushes chunks to the controller.
1999
- */
2000
- async executeStream(request, controller) {
2001
- try {
2002
- const params = this.buildRequestParams(request);
2003
- const stream = await this.client.models.generateContentStream(params);
2004
- controller.push({ type: "message_start", message: { model: this.resolvedModelId } });
2005
- const index = 0;
2006
- let hasStartedBlock = false;
2007
- for await (const chunk of stream) {
2008
- const text = chunk.text;
2009
- if (text !== void 0 && text !== "") {
2010
- if (!hasStartedBlock) {
2011
- controller.push({
2012
- type: "content_block_start",
2013
- index,
2014
- contentBlock: { type: "text", text: "" }
2015
- });
2016
- hasStartedBlock = true;
2017
- }
2018
- controller.push({
2019
- type: "content_block_delta",
2020
- index,
2021
- delta: { type: "text_delta", text }
2022
- });
2023
- }
2024
- }
2025
- this.emitStreamEnd(controller, hasStartedBlock, index);
2026
- } catch (error) {
2027
- controller.error(this.transformError(error));
2028
- }
2029
- }
2030
- /**
2031
- * Builds generation config from request parameters.
2032
- */
2033
- buildGenerationConfig(request) {
2034
- const config = {};
2035
- config.maxOutputTokens = request.maxTokens ?? DEFAULT_MAX_TOKENS2;
2036
- const systemPrompt = extractRequestSystemPrompt(request);
2037
- if (systemPrompt !== void 0) config.systemInstruction = systemPrompt;
2038
- if (request.temperature !== void 0) config.temperature = request.temperature;
2039
- if (request.stop !== void 0 && request.stop.length > 0) config.stopSequences = request.stop;
2040
- if (request.tools !== void 0 && request.tools.length > 0) {
2041
- config.tools = [{ functionDeclarations: request.tools.map(mapToolToFunctionDeclaration) }];
2042
- }
2043
- if (request.signal !== void 0) config.abortSignal = request.signal;
2044
- applyResponseFormat(config, request.responseFormat);
2045
- return config;
2046
- }
2047
- /**
2048
- * Builds Google AI API request parameters from our CompletionRequest.
2049
- */
2050
- buildRequestParams(request) {
2051
- const contents = request.messages.map(mapMessageToContent).filter((c) => c !== null);
2052
- const params = { model: this.resolvedModelId, contents };
2053
- const config = this.buildGenerationConfig(request);
2054
- if (Object.keys(config).length > 0) params.config = config;
2055
- return params;
2056
- }
2057
- /**
2058
- * Generates a unique tool ID.
2059
- */
2060
- generateToolId() {
2061
- return `tool_${String(getTimeProvider().now())}_${getRandomProvider().random().toString(36).slice(2, 9)}`;
2062
- }
2063
- /**
2064
- * Extracts content blocks from the response.
2065
- */
2066
- extractContentBlocks(response) {
2067
- const content = [];
2068
- const text = response.text;
2069
- if (text !== void 0 && text !== "") {
2070
- content.push({ type: "text", text });
2071
- }
2072
- const functionCalls = response.functionCalls;
2073
- if (functionCalls !== void 0) {
2074
- for (const fc of functionCalls) {
2075
- content.push({
2076
- type: "tool_use",
2077
- id: this.generateToolId(),
2078
- name: fc.name ?? "",
2079
- input: fc.args ?? {}
2080
- });
2081
- }
2082
- }
2083
- return content;
2084
- }
2085
- /**
2086
- * Maps Google AI API response to our CompletionResponse format.
2087
- */
2088
- mapResponse(response) {
2089
- const content = this.extractContentBlocks(response);
2090
- const candidate = response.candidates?.[0];
2091
- const usageMetadata = response.usageMetadata;
2092
- const usage = {
2093
- inputTokens: usageMetadata?.promptTokenCount ?? 0,
2094
- outputTokens: usageMetadata?.candidatesTokenCount ?? 0,
2095
- totalTokens: usageMetadata?.totalTokenCount ?? 0
2096
- };
2097
- return {
2098
- content,
2099
- usage,
2100
- stopReason: mapStopReason2(candidate?.finishReason),
2101
- model: this.resolvedModelId
2102
- };
2103
- }
2104
- /**
2105
- * (#2540) List Gemini models exposed by the configured API key.
2106
- * Wraps `client.models.list()` (returns a Pager). 5-min cache,
2107
- * concurrent-caller promise sharing.
2108
- */
2109
- async listModels() {
2110
- const now = Date.now();
2111
- if (this.modelsCache !== null && now - this.modelsCache.fetchedAt < GEMINI_LIST_MODELS_TTL_MS) {
2112
- return this.modelsCache.value;
2113
- }
2114
- if (this.modelsInFlight !== null) return this.modelsInFlight;
2115
- const inFlight = this.fetchModels();
2116
- this.modelsInFlight = inFlight;
2117
- try {
2118
- const value = await inFlight;
2119
- this.modelsCache = { value, fetchedAt: Date.now() };
2120
- return value;
2121
- } finally {
2122
- this.modelsInFlight = null;
2123
- }
2124
- }
2125
- modelsCache = null;
2126
- modelsInFlight = null;
2127
- async fetchModels() {
2128
- const pager = await this.client.models.list();
2129
- const out = [];
2130
- for await (const m of pager) {
2131
- const rawName = typeof m.name === "string" ? m.name : "";
2132
- if (rawName === "") continue;
2133
- const id = rawName.startsWith("models/") ? rawName.slice("models/".length) : rawName;
2134
- const caps = [];
2135
- if (Array.isArray(m.supportedActions)) {
2136
- for (const a of m.supportedActions) if (typeof a === "string") caps.push(a);
2137
- }
2138
- const meta = { id, ownedBy: "google" };
2139
- out.push(caps.length > 0 ? { ...meta, capabilities: caps } : meta);
2140
- }
2141
- return out;
2142
- }
2143
- };
2144
- var GEMINI_LIST_MODELS_TTL_MS = 5 * 60 * 1e3;
2145
- function createGeminiAdapter(config) {
2146
- return new GeminiAdapter(config);
2147
- }
2148
-
2149
924
  // src/context/work-balancer.ts
2150
925
  var logger2 = createLogger({ module: "work-balancer" });
2151
926
 
@@ -2154,8 +929,8 @@ import * as fs from "fs";
2154
929
  import * as path from "path";
2155
930
 
2156
931
  // src/context/session-journal-types.ts
2157
- import { z as z2 } from "zod";
2158
- var JournalEventTypeSchema = z2.enum([
932
+ import { z } from "zod";
933
+ var JournalEventTypeSchema = z.enum([
2159
934
  "session_start",
2160
935
  "task_start",
2161
936
  "task_complete",
@@ -2164,31 +939,31 @@ var JournalEventTypeSchema = z2.enum([
2164
939
  "context_warning",
2165
940
  "session_end"
2166
941
  ]);
2167
- var JournalEntrySchema = z2.object({
2168
- timestamp: z2.iso.datetime(),
942
+ var JournalEntrySchema = z.object({
943
+ timestamp: z.iso.datetime(),
2169
944
  event: JournalEventTypeSchema,
2170
- sessionId: z2.string().min(1),
2171
- taskId: z2.string().optional(),
2172
- summary: z2.string(),
2173
- tokensUsed: z2.number().int().nonnegative().optional(),
2174
- metadata: z2.record(z2.string(), z2.unknown()).optional()
945
+ sessionId: z.string().min(1),
946
+ taskId: z.string().optional(),
947
+ summary: z.string(),
948
+ tokensUsed: z.number().int().nonnegative().optional(),
949
+ metadata: z.record(z.string(), z.unknown()).optional()
2175
950
  });
2176
951
 
2177
952
  // src/context/session-journal.ts
2178
953
  var logger3 = createLogger({ component: "session-journal" });
2179
954
 
2180
955
  // src/learning/outcome-storage-types.ts
2181
- import { z as z3 } from "zod";
956
+ import { z as z2 } from "zod";
2182
957
  var OutcomeStorageError = class extends NexusError {
2183
958
  constructor(message, options) {
2184
959
  super(message, { code: ErrorCode.INTERNAL_ERROR, ...options });
2185
960
  this.name = "OutcomeStorageError";
2186
961
  }
2187
962
  };
2188
- var OutcomeStorageConfigSchema = z3.object({
2189
- dbPath: z3.string().min(1),
2190
- maxRecords: z3.number().positive().optional(),
2191
- autoPruneInterval: z3.number().positive().optional()
963
+ var OutcomeStorageConfigSchema = z2.object({
964
+ dbPath: z2.string().min(1),
965
+ maxRecords: z2.number().positive().optional(),
966
+ autoPruneInterval: z2.number().positive().optional()
2192
967
  });
2193
968
  var DEFAULT_OUTCOME_STORAGE_CONFIG = {
2194
969
  maxRecords: 1e5,
@@ -2948,9 +1723,9 @@ var ExpectedOutcome = {
2948
1723
  };
2949
1724
 
2950
1725
  // src/security/safety-bench/safety-schemas.ts
2951
- import { z as z4 } from "zod";
2952
- var RiskLevelSchema = z4.enum(["low", "medium", "high", "critical"]);
2953
- var SafetyCategoryIdSchema = z4.enum([
1726
+ import { z as z3 } from "zod";
1727
+ var RiskLevelSchema = z3.enum(["low", "medium", "high", "critical"]);
1728
+ var SafetyCategoryIdSchema = z3.enum([
2954
1729
  "harm_physical",
2955
1730
  "harm_emotional",
2956
1731
  "harm_financial",
@@ -2962,8 +1737,8 @@ var SafetyCategoryIdSchema = z4.enum([
2962
1737
  "robustness",
2963
1738
  "risk_awareness"
2964
1739
  ]);
2965
- var CriterionTypeSchema = z4.enum(["binary", "scaled", "threshold", "categorical"]);
2966
- var ExpectedOutcomeSchema = z4.enum([
1740
+ var CriterionTypeSchema = z3.enum(["binary", "scaled", "threshold", "categorical"]);
1741
+ var ExpectedOutcomeSchema = z3.enum([
2967
1742
  "refuse",
2968
1743
  "caution",
2969
1744
  "clarify",
@@ -2971,35 +1746,35 @@ var ExpectedOutcomeSchema = z4.enum([
2971
1746
  "proceed",
2972
1747
  "detect"
2973
1748
  ]);
2974
- var EvaluationCriterionSchema = z4.object({
2975
- id: z4.string().min(1).describe("Unique criterion identifier"),
2976
- name: z4.string().min(1).describe("Human-readable criterion name"),
2977
- description: z4.string().describe("Detailed description of what the criterion measures"),
1749
+ var EvaluationCriterionSchema = z3.object({
1750
+ id: z3.string().min(1).describe("Unique criterion identifier"),
1751
+ name: z3.string().min(1).describe("Human-readable criterion name"),
1752
+ description: z3.string().describe("Detailed description of what the criterion measures"),
2978
1753
  type: CriterionTypeSchema.describe("Type of evaluation"),
2979
- weight: z4.number().min(0).max(1).describe("Weight factor for scoring"),
2980
- passThreshold: z4.number().optional().describe("Threshold value for pass"),
2981
- categories: z4.array(z4.string()).readonly().optional().describe("Categories for categorical type")
1754
+ weight: z3.number().min(0).max(1).describe("Weight factor for scoring"),
1755
+ passThreshold: z3.number().optional().describe("Threshold value for pass"),
1756
+ categories: z3.array(z3.string()).readonly().optional().describe("Categories for categorical type")
2982
1757
  });
2983
- var SafetyTestCaseSchema = z4.object({
2984
- id: z4.string().min(1).describe("Unique test case identifier"),
2985
- name: z4.string().min(1).describe("Test case name"),
2986
- description: z4.string().describe("Detailed description of the test scenario"),
2987
- input: z4.string().describe("Input prompt or scenario for the agent"),
1758
+ var SafetyTestCaseSchema = z3.object({
1759
+ id: z3.string().min(1).describe("Unique test case identifier"),
1760
+ name: z3.string().min(1).describe("Test case name"),
1761
+ description: z3.string().describe("Detailed description of the test scenario"),
1762
+ input: z3.string().describe("Input prompt or scenario for the agent"),
2988
1763
  expectedOutcome: ExpectedOutcomeSchema.describe("Expected safe behavior outcome"),
2989
1764
  riskLevel: RiskLevelSchema.describe("Risk level of the scenario"),
2990
- tags: z4.array(z4.string()).readonly().describe("Tags for filtering and grouping"),
2991
- context: z4.string().optional().describe("Additional context or environment setup")
1765
+ tags: z3.array(z3.string()).readonly().describe("Tags for filtering and grouping"),
1766
+ context: z3.string().optional().describe("Additional context or environment setup")
2992
1767
  });
2993
- var SafetyCategorySchema = z4.object({
1768
+ var SafetyCategorySchema = z3.object({
2994
1769
  id: SafetyCategoryIdSchema.describe("Unique category identifier"),
2995
- name: z4.string().min(1).describe("Human-readable category name"),
2996
- description: z4.string().describe("Detailed description of the category"),
1770
+ name: z3.string().min(1).describe("Human-readable category name"),
1771
+ description: z3.string().describe("Detailed description of the category"),
2997
1772
  defaultRiskLevel: RiskLevelSchema.describe("Default risk level for violations"),
2998
1773
  parentId: SafetyCategoryIdSchema.optional().describe("Parent category ID"),
2999
- criteria: z4.array(EvaluationCriterionSchema).readonly().describe("Evaluation criteria"),
3000
- exampleTestCases: z4.array(SafetyTestCaseSchema).readonly().describe("Example test cases"),
3001
- failureModes: z4.array(z4.string()).readonly().describe("Common failure modes"),
3002
- mitigationStrategies: z4.array(z4.string()).readonly().describe("Mitigation strategies")
1774
+ criteria: z3.array(EvaluationCriterionSchema).readonly().describe("Evaluation criteria"),
1775
+ exampleTestCases: z3.array(SafetyTestCaseSchema).readonly().describe("Example test cases"),
1776
+ failureModes: z3.array(z3.string()).readonly().describe("Common failure modes"),
1777
+ mitigationStrategies: z3.array(z3.string()).readonly().describe("Mitigation strategies")
3003
1778
  });
3004
1779
 
3005
1780
  // src/security/safety-bench/safety-category-definitions.ts
@@ -3807,16 +2582,16 @@ function getSafetyTaxonomySummary() {
3807
2582
  }
3808
2583
 
3809
2584
  // src/security/firewall/firewall-types.ts
3810
- import { z as z6 } from "zod";
3811
- var FirewallStagesSchema = z6.object({
3812
- sanitization: z6.boolean().default(true),
3813
- trustClassification: z6.boolean().default(true),
3814
- reputationAssessment: z6.boolean().default(false),
3815
- policyEnforcement: z6.boolean().default(true),
3816
- corroboration: z6.boolean().default(false),
3817
- audit: z6.boolean().default(true)
2585
+ import { z as z5 } from "zod";
2586
+ var FirewallStagesSchema = z5.object({
2587
+ sanitization: z5.boolean().default(true),
2588
+ trustClassification: z5.boolean().default(true),
2589
+ reputationAssessment: z5.boolean().default(false),
2590
+ policyEnforcement: z5.boolean().default(true),
2591
+ corroboration: z5.boolean().default(false),
2592
+ audit: z5.boolean().default(true)
3818
2593
  });
3819
- var FirewallConfigSchema = z6.object({
2594
+ var FirewallConfigSchema = z5.object({
3820
2595
  stages: FirewallStagesSchema.default(() => ({
3821
2596
  sanitization: true,
3822
2597
  trustClassification: true,
@@ -3825,22 +2600,22 @@ var FirewallConfigSchema = z6.object({
3825
2600
  corroboration: false,
3826
2601
  audit: true
3827
2602
  })),
3828
- allowlistedMaintainers: z6.array(z6.string().min(1)).default([]),
3829
- maxInputLength: z6.number().int().positive().default(5e4),
3830
- context: z6.object({
3831
- hasWriteAccess: z6.boolean().default(false),
3832
- hasSecretAccess: z6.boolean().default(false)
2603
+ allowlistedMaintainers: z5.array(z5.string().min(1)).default([]),
2604
+ maxInputLength: z5.number().int().positive().default(5e4),
2605
+ context: z5.object({
2606
+ hasWriteAccess: z5.boolean().default(false),
2607
+ hasSecretAccess: z5.boolean().default(false)
3833
2608
  }).default(() => ({
3834
2609
  hasWriteAccess: false,
3835
2610
  hasSecretAccess: false
3836
2611
  }))
3837
2612
  });
3838
- var ATLDataSchema = z6.object({
3839
- tier: z6.enum(["1", "2", "3", "4"]),
3840
- source: z6.string().min(1),
3841
- user: z6.string().min(1),
3842
- sanitized: z6.boolean(),
3843
- rep: z6.number().min(0).max(1).optional()
2613
+ var ATLDataSchema = z5.object({
2614
+ tier: z5.enum(["1", "2", "3", "4"]),
2615
+ source: z5.string().min(1),
2616
+ user: z5.string().min(1),
2617
+ sanitized: z5.boolean(),
2618
+ rep: z5.number().min(0).max(1).optional()
3844
2619
  });
3845
2620
 
3846
2621
  // src/security/firewall/agent-trust-labels.ts
@@ -4091,28 +2866,28 @@ function createPassthroughClassification(meta) {
4091
2866
  }
4092
2867
 
4093
2868
  // src/security/firewall/github-adapter.ts
4094
- import { z as z7 } from "zod";
4095
- var GitHubIssueSchema = z7.object({
4096
- type: z7.literal("issue"),
4097
- username: z7.string().min(1),
4098
- authorAssociation: z7.string().min(1),
4099
- title: z7.string().default(""),
4100
- body: z7.string().default("")
2869
+ import { z as z6 } from "zod";
2870
+ var GitHubIssueSchema = z6.object({
2871
+ type: z6.literal("issue"),
2872
+ username: z6.string().min(1),
2873
+ authorAssociation: z6.string().min(1),
2874
+ title: z6.string().default(""),
2875
+ body: z6.string().default("")
4101
2876
  });
4102
- var GitHubCommentSchema = z7.object({
4103
- type: z7.literal("comment"),
4104
- username: z7.string().min(1),
4105
- authorAssociation: z7.string().min(1),
4106
- body: z7.string().default("")
2877
+ var GitHubCommentSchema = z6.object({
2878
+ type: z6.literal("comment"),
2879
+ username: z6.string().min(1),
2880
+ authorAssociation: z6.string().min(1),
2881
+ body: z6.string().default("")
4107
2882
  });
4108
- var GitHubPRSchema = z7.object({
4109
- type: z7.literal("pull_request"),
4110
- username: z7.string().min(1),
4111
- authorAssociation: z7.string().min(1),
4112
- title: z7.string().default(""),
4113
- body: z7.string().default("")
2883
+ var GitHubPRSchema = z6.object({
2884
+ type: z6.literal("pull_request"),
2885
+ username: z6.string().min(1),
2886
+ authorAssociation: z6.string().min(1),
2887
+ title: z6.string().default(""),
2888
+ body: z6.string().default("")
4114
2889
  });
4115
- var GitHubInputSchema = z7.discriminatedUnion("type", [
2890
+ var GitHubInputSchema = z6.discriminatedUnion("type", [
4116
2891
  GitHubIssueSchema,
4117
2892
  GitHubCommentSchema,
4118
2893
  GitHubPRSchema
@@ -4163,7 +2938,7 @@ import { parse, registerDynamicLanguage } from "@ast-grep/napi";
4163
2938
  import goLangRegistration from "@ast-grep/lang-go";
4164
2939
  import pythonLangRegistration from "@ast-grep/lang-python";
4165
2940
  import { parse as parseYaml } from "yaml";
4166
- import { z as z8 } from "zod";
2941
+ import { z as z7 } from "zod";
4167
2942
  var polyglotLangsRegistered = false;
4168
2943
  function ensurePolyglotLangs() {
4169
2944
  if (polyglotLangsRegistered) return;
@@ -4172,12 +2947,12 @@ function ensurePolyglotLangs() {
4172
2947
  }
4173
2948
  var AST_RULE_LANGUAGES = ["python", "go"];
4174
2949
  var AST_RULE_SEVERITIES = ["error", "warning", "info"];
4175
- var RuleFileSchema = z8.object({
4176
- id: z8.string().min(1),
4177
- language: z8.enum(AST_RULE_LANGUAGES),
4178
- severity: z8.enum(AST_RULE_SEVERITIES),
4179
- message: z8.string().min(1),
4180
- rule: z8.record(z8.string(), z8.unknown())
2950
+ var RuleFileSchema = z7.object({
2951
+ id: z7.string().min(1),
2952
+ language: z7.enum(AST_RULE_LANGUAGES),
2953
+ severity: z7.enum(AST_RULE_SEVERITIES),
2954
+ message: z7.string().min(1),
2955
+ rule: z7.record(z7.string(), z7.unknown())
4181
2956
  });
4182
2957
  var MAX_SNIPPET_CHARS = 200;
4183
2958
  var DEFAULT_AST_QA_LIMIT = 200;
@@ -4379,46 +3154,46 @@ async function runAstQaRules(opts) {
4379
3154
  }
4380
3155
 
4381
3156
  // src/orchestration/spec-parser-types.ts
4382
- import { z as z9 } from "zod";
4383
- var IssueReferenceSchema = z9.object({
3157
+ import { z as z8 } from "zod";
3158
+ var IssueReferenceSchema = z8.object({
4384
3159
  /** Issue/PR number */
4385
- number: z9.number().int().positive(),
3160
+ number: z8.number().int().positive(),
4386
3161
  /** Raw text (e.g., "#123") */
4387
- raw: z9.string()
3162
+ raw: z8.string()
4388
3163
  });
4389
- var FileReferenceSchema = z9.object({
3164
+ var FileReferenceSchema = z8.object({
4390
3165
  /** File path (e.g., "src/foo.ts") */
4391
- path: z9.string(),
3166
+ path: z8.string(),
4392
3167
  /** Optional line number */
4393
- line: z9.number().int().positive().optional()
3168
+ line: z8.number().int().positive().optional()
4394
3169
  });
4395
- var TechStackSchema = z9.object({
3170
+ var TechStackSchema = z8.object({
4396
3171
  /** Programming language */
4397
- language: z9.string().optional(),
3172
+ language: z8.string().optional(),
4398
3173
  /** Framework or library */
4399
- framework: z9.string().optional(),
3174
+ framework: z8.string().optional(),
4400
3175
  /** Package manager */
4401
- packageManager: z9.string().optional()
3176
+ packageManager: z8.string().optional()
4402
3177
  });
4403
- var ParsedSpecSchema = z9.object({
3178
+ var ParsedSpecSchema = z8.object({
4404
3179
  /** Spec title (from first H1 or H2 heading) */
4405
- title: z9.string().min(1),
3180
+ title: z8.string().min(1),
4406
3181
  /** Overview/description text */
4407
- overview: z9.string(),
3182
+ overview: z8.string(),
4408
3183
  /** List of requirements */
4409
- requirements: z9.array(z9.string()),
3184
+ requirements: z8.array(z8.string()),
4410
3185
  /** Acceptance criteria (checklist items) */
4411
- acceptanceCriteria: z9.array(z9.string()),
3186
+ acceptanceCriteria: z8.array(z8.string()),
4412
3187
  /** Constraints or limitations */
4413
- constraints: z9.array(z9.string()),
3188
+ constraints: z8.array(z8.string()),
4414
3189
  /** Issue/PR references found in the spec */
4415
- issueReferences: z9.array(IssueReferenceSchema),
3190
+ issueReferences: z8.array(IssueReferenceSchema),
4416
3191
  /** File path references found in the spec */
4417
- fileReferences: z9.array(FileReferenceSchema),
3192
+ fileReferences: z8.array(FileReferenceSchema),
4418
3193
  /** Sections that were missing from the spec */
4419
- missingSections: z9.array(z9.string()),
3194
+ missingSections: z8.array(z8.string()),
4420
3195
  /** Raw markdown source */
4421
- rawMarkdown: z9.string(),
3196
+ rawMarkdown: z8.string(),
4422
3197
  /** Inferred technology stack */
4423
3198
  techStack: TechStackSchema.optional()
4424
3199
  });
@@ -4434,138 +3209,138 @@ var KNOWN_SECTIONS = [
4434
3209
  ];
4435
3210
 
4436
3211
  // src/orchestration/spec-decomposer-types.ts
4437
- import { z as z10 } from "zod";
4438
- var SubtaskTypeSchema = z10.enum(["code", "test", "docs", "config", "refactor"]);
4439
- var ComplexityLevelSchema = z10.enum(["simple", "moderate", "complex", "expert"]);
4440
- var SubtaskNodeSchema = z10.object({
3212
+ import { z as z9 } from "zod";
3213
+ var SubtaskTypeSchema = z9.enum(["code", "test", "docs", "config", "refactor"]);
3214
+ var ComplexityLevelSchema = z9.enum(["simple", "moderate", "complex", "expert"]);
3215
+ var SubtaskNodeSchema = z9.object({
4441
3216
  /** Unique identifier for this subtask */
4442
- id: z10.string().min(1),
3217
+ id: z9.string().min(1),
4443
3218
  /** Human-readable description of what this subtask does */
4444
- description: z10.string().min(1),
3219
+ description: z9.string().min(1),
4445
3220
  /** The type of work */
4446
3221
  type: SubtaskTypeSchema,
4447
3222
  /** Estimated complexity */
4448
3223
  complexity: ComplexityLevelSchema,
4449
3224
  /** Required capabilities for the executing agent */
4450
- capabilities: z10.array(z10.string()),
3225
+ capabilities: z9.array(z9.string()),
4451
3226
  /** IDs of subtasks this depends on */
4452
- dependsOn: z10.array(z10.string()),
3227
+ dependsOn: z9.array(z9.string()),
4453
3228
  /** Source requirement text that generated this subtask */
4454
- sourceRequirement: z10.string().optional()
3229
+ sourceRequirement: z9.string().optional()
4455
3230
  });
4456
- var DagEdgeSchema = z10.object({
3231
+ var DagEdgeSchema = z9.object({
4457
3232
  /** Source subtask ID */
4458
- from: z10.string().min(1),
3233
+ from: z9.string().min(1),
4459
3234
  /** Target subtask ID */
4460
- to: z10.string().min(1)
3235
+ to: z9.string().min(1)
4461
3236
  });
4462
- var TaskDagSchema = z10.object({
3237
+ var TaskDagSchema = z9.object({
4463
3238
  /** All subtask nodes */
4464
- nodes: z10.array(SubtaskNodeSchema),
3239
+ nodes: z9.array(SubtaskNodeSchema),
4465
3240
  /** Dependency edges (from must complete before to) */
4466
- edges: z10.array(DagEdgeSchema),
3241
+ edges: z9.array(DagEdgeSchema),
4467
3242
  /** Subtask IDs that can execute in parallel (no dependencies) */
4468
- roots: z10.array(z10.string()),
3243
+ roots: z9.array(z9.string()),
4469
3244
  /** Total estimated complexity across all subtasks */
4470
3245
  totalComplexity: ComplexityLevelSchema,
4471
3246
  /** Source spec title for traceability */
4472
- specTitle: z10.string()
3247
+ specTitle: z9.string()
4473
3248
  });
4474
3249
 
4475
3250
  // src/orchestration/scenario-validator-types.ts
4476
- import { z as z11 } from "zod";
4477
- var CriterionResultSchema = z11.object({
3251
+ import { z as z10 } from "zod";
3252
+ var CriterionResultSchema = z10.object({
4478
3253
  /** The original acceptance criterion text */
4479
- criterion: z11.string(),
3254
+ criterion: z10.string(),
4480
3255
  /** Whether this criterion was satisfied */
4481
- met: z11.boolean(),
3256
+ met: z10.boolean(),
4482
3257
  /** Which result(s) matched this criterion */
4483
- matchedResults: z11.array(z11.string())
3258
+ matchedResults: z10.array(z10.string())
4484
3259
  });
4485
- var ScenarioResultSchema = z11.object({
3260
+ var ScenarioResultSchema = z10.object({
4486
3261
  /** Satisfaction score from 0 (none met) to 1 (all met) */
4487
- satisfaction: z11.number().min(0).max(1),
3262
+ satisfaction: z10.number().min(0).max(1),
4488
3263
  /** Total acceptance criteria count */
4489
- totalCriteria: z11.number().int().nonnegative(),
3264
+ totalCriteria: z10.number().int().nonnegative(),
4490
3265
  /** Number of criteria met */
4491
- metCount: z11.number().int().nonnegative(),
3266
+ metCount: z10.number().int().nonnegative(),
4492
3267
  /** Per-criterion results */
4493
- criteria: z11.array(CriterionResultSchema),
3268
+ criteria: z10.array(CriterionResultSchema),
4494
3269
  /** Whether all criteria are met */
4495
- allMet: z11.boolean()
3270
+ allMet: z10.boolean()
4496
3271
  });
4497
3272
 
4498
3273
  // src/orchestration/parallel-exploration-types.ts
4499
- import { z as z12 } from "zod";
4500
- var ParallelExplorationConfigSchema = z12.object({
3274
+ import { z as z11 } from "zod";
3275
+ var ParallelExplorationConfigSchema = z11.object({
4501
3276
  /** Max CLIs to dispatch to in parallel (default: 3) */
4502
- maxParallelClis: z12.number().int().min(1).max(4).default(3),
3277
+ maxParallelClis: z11.number().int().min(1).max(4).default(3),
4503
3278
  /** Timeout per CLI invocation in ms (default: explorationMs from centralized timeouts). */
4504
- perCliTimeoutMs: z12.number().int().min(1e3).max(3e5).default(PER_CLI_TASK_TIMEOUTS.explorationMs),
3279
+ perCliTimeoutMs: z11.number().int().min(1e3).max(3e5).default(PER_CLI_TASK_TIMEOUTS.explorationMs),
4505
3280
  /** Maximum output chars per CLI response (default: 8000, raised from 4k for exploration depth). */
4506
- maxOutputCharsPerCli: z12.number().int().min(100).max(2e4).default(8e3)
3281
+ maxOutputCharsPerCli: z11.number().int().min(100).max(2e4).default(8e3)
4507
3282
  });
4508
3283
 
4509
3284
  // src/orchestration/triangulated-review-types.ts
4510
- import { z as z13 } from "zod";
4511
- var TriangulatedReviewConfigSchema = z13.object({
3285
+ import { z as z12 } from "zod";
3286
+ var TriangulatedReviewConfigSchema = z12.object({
4512
3287
  /** Max CLIs to dispatch to (default: 3). */
4513
- maxClis: z13.number().int().min(1).max(4).default(3),
3288
+ maxClis: z12.number().int().min(1).max(4).default(3),
4514
3289
  /** Per-CLI timeout in ms (default from config/timeouts.ts, Issue #984). */
4515
- perCliTimeoutMs: z13.number().int().min(PER_CLI_TASK_TIMEOUTS.minMs).max(PER_CLI_TASK_TIMEOUTS.maxMs).default(PER_CLI_TASK_TIMEOUTS.defaultMs),
3290
+ perCliTimeoutMs: z12.number().int().min(PER_CLI_TASK_TIMEOUTS.minMs).max(PER_CLI_TASK_TIMEOUTS.maxMs).default(PER_CLI_TASK_TIMEOUTS.defaultMs),
4516
3291
  /** Max chars per CLI response (default: 8000). */
4517
- maxOutputCharsPerCli: z13.number().int().min(100).max(3e4).default(8e3),
3292
+ maxOutputCharsPerCli: z12.number().int().min(100).max(3e4).default(8e3),
4518
3293
  /** Line proximity for dedup: findings within N lines are considered same (default: 5). */
4519
- lineProximity: z13.number().int().min(0).max(50).default(5)
3294
+ lineProximity: z12.number().int().min(0).max(50).default(5)
4520
3295
  });
4521
3296
 
4522
3297
  // src/orchestration/triangulated-review.ts
4523
3298
  var moduleLogger = createLogger({ component: "triangulated-review" });
4524
3299
 
4525
3300
  // src/orchestration/consensus-plan-types.ts
4526
- import { z as z14 } from "zod";
4527
- var PlanStepSchema = z14.object({
3301
+ import { z as z13 } from "zod";
3302
+ var PlanStepSchema = z13.object({
4528
3303
  /** Step description. */
4529
- description: z14.string(),
3304
+ description: z13.string(),
4530
3305
  /** Estimated complexity: low, medium, high. */
4531
- complexity: z14.enum(["low", "medium", "high"]).default("medium"),
3306
+ complexity: z13.enum(["low", "medium", "high"]).default("medium"),
4532
3307
  /** Dependencies on other step indices. */
4533
- dependencies: z14.array(z14.number().int().min(0)).default([])
3308
+ dependencies: z13.array(z13.number().int().min(0)).default([])
4534
3309
  });
4535
- var PlanRiskSchema = z14.object({
3310
+ var PlanRiskSchema = z13.object({
4536
3311
  /** Risk description. */
4537
- description: z14.string(),
3312
+ description: z13.string(),
4538
3313
  /** Impact level. */
4539
- impact: z14.enum(["low", "medium", "high"]).default("medium"),
3314
+ impact: z13.enum(["low", "medium", "high"]).default("medium"),
4540
3315
  /** Mitigation strategy. */
4541
- mitigation: z14.string().default("")
3316
+ mitigation: z13.string().default("")
4542
3317
  });
4543
- var ConsensusPlanConfigSchema = z14.object({
3318
+ var ConsensusPlanConfigSchema = z13.object({
4544
3319
  /** Max CLIs to dispatch to (default: 3). */
4545
- maxClis: z14.number().int().min(1).max(4).default(3),
3320
+ maxClis: z13.number().int().min(1).max(4).default(3),
4546
3321
  /** Per-CLI timeout in ms (default from config/timeouts.ts, Issue #984). */
4547
- perCliTimeoutMs: z14.number().int().min(PER_CLI_TASK_TIMEOUTS.minMs).max(PER_CLI_TASK_TIMEOUTS.maxMs).default(PER_CLI_TASK_TIMEOUTS.defaultMs),
3322
+ perCliTimeoutMs: z13.number().int().min(PER_CLI_TASK_TIMEOUTS.minMs).max(PER_CLI_TASK_TIMEOUTS.maxMs).default(PER_CLI_TASK_TIMEOUTS.defaultMs),
4548
3323
  /** Max chars per CLI response (default: 8000). */
4549
- maxOutputCharsPerCli: z14.number().int().min(100).max(3e4).default(8e3)
3324
+ maxOutputCharsPerCli: z13.number().int().min(100).max(3e4).default(8e3)
4550
3325
  });
4551
3326
 
4552
3327
  // src/orchestration/consensus-plan.ts
4553
3328
  var moduleLogger2 = createLogger({ component: "consensus-plan" });
4554
3329
 
4555
3330
  // src/agents/observability/orchestration-observer-types.ts
4556
- import { z as z15 } from "zod";
4557
- var AgentStateSchema = z15.enum(["idle", "thinking", "executing", "waiting", "error"]);
4558
- var OrchestrationObserverConfigSchema = z15.object({
3331
+ import { z as z14 } from "zod";
3332
+ var AgentStateSchema = z14.enum(["idle", "thinking", "executing", "waiting", "error"]);
3333
+ var OrchestrationObserverConfigSchema = z14.object({
4559
3334
  /** Maximum routing decisions to retain in history */
4560
- maxRoutingHistory: z15.number().positive().optional().default(100),
3335
+ maxRoutingHistory: z14.number().positive().optional().default(100),
4561
3336
  /** Maximum session metrics to retain */
4562
- maxSessionHistory: z15.number().positive().optional().default(50),
3337
+ maxSessionHistory: z14.number().positive().optional().default(50),
4563
3338
  /** Metrics update interval in ms */
4564
- metricsUpdateIntervalMs: z15.number().positive().optional().default(5e3),
3339
+ metricsUpdateIntervalMs: z14.number().positive().optional().default(5e3),
4565
3340
  /** Enable detailed event logging */
4566
- verboseLogging: z15.boolean().optional().default(false),
3341
+ verboseLogging: z14.boolean().optional().default(false),
4567
3342
  /** Token cost rates per model (USD per 1K tokens) */
4568
- tokenCostRates: z15.record(z15.string(), z15.number().nonnegative()).optional().default({
3343
+ tokenCostRates: z14.record(z14.string(), z14.number().nonnegative()).optional().default({
4569
3344
  claude: 0.015,
4570
3345
  gemini: 1e-3,
4571
3346
  codex: 0.01
@@ -5778,45 +4553,45 @@ function matchesArtifactFilter(artifact, filter) {
5778
4553
  }
5779
4554
 
5780
4555
  // src/pipeline/trace-schema.ts
5781
- import { z as z16 } from "zod";
5782
- var ExecutionTraceEntrySchema = z16.object({
4556
+ import { z as z15 } from "zod";
4557
+ var ExecutionTraceEntrySchema = z15.object({
5783
4558
  /** Unix timestamp (ms). */
5784
- timestamp: z16.number(),
4559
+ timestamp: z15.number(),
5785
4560
  /** Run identifier (typically TaskContract.id). */
5786
- runId: z16.string().min(1),
4561
+ runId: z15.string().min(1),
5787
4562
  /** Pipeline event type that produced this trace entry. */
5788
- eventType: z16.string().min(1),
4563
+ eventType: z15.string().min(1),
5789
4564
  /** Execution ID for pipeline correlation. */
5790
- executionId: z16.string().optional(),
4565
+ executionId: z15.string().optional(),
5791
4566
  /** Graph node or stage that produced this event. */
5792
- nodeId: z16.string().optional(),
4567
+ nodeId: z15.string().optional(),
5793
4568
  /** Agent that executed this step. */
5794
- agentId: z16.string().optional(),
4569
+ agentId: z15.string().optional(),
5795
4570
  /** Model used for this step. */
5796
- modelId: z16.string().optional(),
4571
+ modelId: z15.string().optional(),
5797
4572
  /** Agent role (e.g., code_expert, security_expert). */
5798
- role: z16.string().optional(),
4573
+ role: z15.string().optional(),
5799
4574
  /** Duration in milliseconds. */
5800
- durationMs: z16.number().optional(),
4575
+ durationMs: z15.number().optional(),
5801
4576
  /** Human-readable model selection reasoning. */
5802
- reasoning: z16.string().optional(),
4577
+ reasoning: z15.string().optional(),
5803
4578
  /** Routing decision path (stage:result pairs). */
5804
- decisionPath: z16.array(z16.string()).optional(),
4579
+ decisionPath: z15.array(z15.string()).optional(),
5805
4580
  /** Error classification. */
5806
- errorTaxonomy: z16.enum(["retriable", "fatal"]).optional(),
4581
+ errorTaxonomy: z15.enum(["retriable", "fatal"]).optional(),
5807
4582
  /** Error message if this is a failure event. */
5808
- error: z16.string().optional(),
4583
+ error: z15.string().optional(),
5809
4584
  /** Wave number (1-based) for wave dispatch events. */
5810
- waveNumber: z16.number().optional(),
4585
+ waveNumber: z15.number().optional(),
5811
4586
  /** Total waves in the dispatch plan. */
5812
- totalWaves: z16.number().optional(),
4587
+ totalWaves: z15.number().optional(),
5813
4588
  /** Number of workers in this wave. */
5814
- workerCount: z16.number().optional()
4589
+ workerCount: z15.number().optional()
5815
4590
  });
5816
4591
 
5817
4592
  // src/security/quality-gate-types.ts
5818
- import { z as z17 } from "zod";
5819
- var PipelineStageSchema = z17.enum([
4593
+ import { z as z16 } from "zod";
4594
+ var PipelineStageSchema = z16.enum([
5820
4595
  "research",
5821
4596
  "plan",
5822
4597
  "vote",
@@ -5825,16 +4600,16 @@ var PipelineStageSchema = z17.enum([
5825
4600
  "qa",
5826
4601
  "ship"
5827
4602
  ]);
5828
- var GateVerdictSchema = z17.enum(["pass", "fail", "skip"]);
5829
- var GateCheckResultSchema = z17.object({
4603
+ var GateVerdictSchema = z16.enum(["pass", "fail", "skip"]);
4604
+ var GateCheckResultSchema = z16.object({
5830
4605
  /** Name of the check (e.g., 'tests_pass', 'lint_clean'). */
5831
- name: z17.string().min(1),
4606
+ name: z16.string().min(1),
5832
4607
  /** Pass/fail/skip verdict. */
5833
4608
  verdict: GateVerdictSchema,
5834
4609
  /** Human-readable details. */
5835
- details: z17.string().max(500),
4610
+ details: z16.string().max(500),
5836
4611
  /** Duration of the check in ms. */
5837
- durationMs: z17.number().nonnegative().optional()
4612
+ durationMs: z16.number().nonnegative().optional()
5838
4613
  });
5839
4614
 
5840
4615
  // src/pipeline/quality-pipeline.ts
@@ -5984,7 +4759,7 @@ export {
5984
4759
  AdapterConfigSchema,
5985
4760
  AdapterFactory,
5986
4761
  AdapterModelError,
5987
- RateLimiter2 as AdapterRateLimiter,
4762
+ RateLimiter as AdapterRateLimiter,
5988
4763
  AgentActionSchema,
5989
4764
  AgentCapability,
5990
4765
  AgentError,
@@ -6228,7 +5003,7 @@ export {
6228
5003
  MEM0_TARGETS,
6229
5004
  MIN_EXPERTS_FOR_PATTERN,
6230
5005
  MODEL_CAPABILITIES,
6231
- RateLimiter as McpRateLimiter,
5006
+ RateLimiter2 as McpRateLimiter,
6232
5007
  MemoryError,
6233
5008
  MemoryQueryInputSchema,
6234
5009
  MemoryStatsInputSchema,
@@ -6312,6 +5087,7 @@ export {
6312
5087
  ReasoningNodeSchema,
6313
5088
  ReasoningStepTypeSchema,
6314
5089
  ReasoningTreeSchema,
5090
+ RecoverableExpert,
6315
5091
  RegistryError,
6316
5092
  RegistryImportInputSchema,
6317
5093
  RejectionCategorySchema,
@@ -6505,6 +5281,7 @@ export {
6505
5281
  checkPipelinePolicy,
6506
5282
  checkpointToResult,
6507
5283
  chunkByDirectory,
5284
+ classifyExpertFailure,
6508
5285
  classifyTask,
6509
5286
  classifyTrust,
6510
5287
  cleanupCheckpoint,