@kb-labs/core-state-daemon 2.107.0 → 2.110.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/bin.cjs CHANGED
@@ -1675,6 +1675,89 @@ var init_dist2 = __esm({
1675
1675
  ]);
1676
1676
  }
1677
1677
  });
1678
+
1679
+ // ../../../core/retry/dist/index.js
1680
+ function asRecord(value) {
1681
+ return typeof value === "object" && value !== null ? value : void 0;
1682
+ }
1683
+ function getStatus(value) {
1684
+ const response = asRecord(value?.response);
1685
+ const status = value?.status ?? value?.statusCode ?? response?.status;
1686
+ return typeof status === "number" ? status : void 0;
1687
+ }
1688
+ function getCode(value) {
1689
+ return typeof value?.code === "string" ? value.code : void 0;
1690
+ }
1691
+ function makeFailure(input, kind, source, context, code, transient = false, retrySafety = "never") {
1692
+ const record = asRecord(input);
1693
+ const message = input instanceof Error ? input.message : String(record?.message ?? input ?? "Unknown failure");
1694
+ const retryAfterMs = typeof record?.retryAfterMs === "number" ? record.retryAfterMs : void 0;
1695
+ return {
1696
+ message,
1697
+ code: code ?? getCode(record) ?? "UNKNOWN_ERROR",
1698
+ kind,
1699
+ source,
1700
+ transient,
1701
+ retrySafety,
1702
+ phase: context.phase,
1703
+ retryAfterMs,
1704
+ details: asRecord(record?.details)
1705
+ };
1706
+ }
1707
+ function classifyFailure(input, context = {}) {
1708
+ const record = asRecord(input);
1709
+ const source = context.source ?? record?.source ?? "execution";
1710
+ const explicitKind = record?.kind;
1711
+ const explicitCode = getCode(record);
1712
+ const status = getStatus(record);
1713
+ const code = explicitCode?.toUpperCase();
1714
+ if (explicitKind && ["command", "network", "timeout", "rate_limit", "server", "validation", "configuration", "authentication", "authorization", "not_found", "cancelled", "infrastructure", "unknown"].includes(explicitKind)) {
1715
+ const transient = ["network", "timeout", "rate_limit", "server"].includes(explicitKind);
1716
+ const safe = explicitKind === "network" && (code === "ECONNREFUSED" || code === "NETWORK_UNAVAILABLE");
1717
+ return makeFailure(input, explicitKind, source, context, code, transient, safe ? "safe" : transient ? "requires_idempotency" : "never");
1718
+ }
1719
+ if (code && NETWORK_CODES.has(code)) {
1720
+ return makeFailure(input, code === "ETIMEDOUT" ? "timeout" : "network", source, context, code, true, context.phase === "dispatch" ? "safe" : "requires_idempotency");
1721
+ }
1722
+ if (status !== void 0) {
1723
+ if (status === 429) {
1724
+ return makeFailure(input, "rate_limit", source, context, "HTTP_429", true, "safe");
1725
+ }
1726
+ if (status >= 500 || status === 408 || status === 425) {
1727
+ return makeFailure(input, status === 408 ? "timeout" : "server", source, context, `HTTP_${status}`, true, "requires_idempotency");
1728
+ }
1729
+ if (status >= 400) {
1730
+ return makeFailure(input, "validation", source, context, `HTTP_${status}`, false, "never");
1731
+ }
1732
+ }
1733
+ const message = input instanceof Error ? input.message.toLowerCase() : String(record?.message ?? input ?? "").toLowerCase();
1734
+ const name = typeof record?.name === "string" ? record.name.toLowerCase() : "";
1735
+ if (message.includes("429") || message.includes("rate limit") || message.includes("too many requests") || message.includes("quota exceeded") || name.includes("ratelimit")) {
1736
+ return makeFailure(input, "rate_limit", source, context, "RATE_LIMIT", true, "safe");
1737
+ }
1738
+ if (message.includes("500") || message.includes("502") || message.includes("503") || message.includes("504") || message.includes("service unavailable") || message.includes("bad gateway")) {
1739
+ return makeFailure(input, "server", source, context, "SERVER_ERROR", true, "requires_idempotency");
1740
+ }
1741
+ if (message.includes("400") || message.includes("401") || message.includes("403") || message.includes("404") || message.includes("bad request") || message.includes("unauthorized") || message.includes("forbidden") || message.includes("not found")) {
1742
+ return makeFailure(input, "validation", source, context, "CLIENT_ERROR");
1743
+ }
1744
+ if (message.includes("timeout") || message.includes("timed out") || message.includes("etimedout") || message.includes("deadline exceeded") || name.includes("timeout") || code?.includes("TIMEOUT")) {
1745
+ return makeFailure(input, "timeout", source, context, "TIMEOUT", true, "requires_idempotency");
1746
+ }
1747
+ if (message.includes("unauthorized") || message.includes("forbidden")) {
1748
+ return makeFailure(input, "authentication", source, context, "AUTHENTICATION_FAILED");
1749
+ }
1750
+ if (message.includes("econn") || message.includes("enotfound") || message.includes("network") || message.includes("socket") || message.includes("dns") || message.includes("host not connected") || name.includes("fetch") || name.includes("network")) {
1751
+ return makeFailure(input, "network", source, context, "NETWORK_ERROR", true, "requires_idempotency");
1752
+ }
1753
+ return makeFailure(input, source === "command" ? "command" : "unknown", source, context, code ?? "UNKNOWN_ERROR");
1754
+ }
1755
+ var NETWORK_CODES;
1756
+ var init_dist3 = __esm({
1757
+ "../../../core/retry/dist/index.js"() {
1758
+ NETWORK_CODES = /* @__PURE__ */ new Set(["ECONNRESET", "ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND", "EAI_AGAIN", "EPIPE", "ECONNABORTED"]);
1759
+ }
1760
+ });
1678
1761
  function getRateLimitConfig(configOrPreset) {
1679
1762
  if (!configOrPreset) {
1680
1763
  return RATE_LIMIT_PRESETS["openai-tier-2"];
@@ -1695,58 +1778,21 @@ function estimateBatchTokens(texts) {
1695
1778
  return texts.reduce((sum, text) => sum + estimateTokens(text), 0);
1696
1779
  }
1697
1780
  function classifyError(error) {
1698
- if (!error) {
1699
- return "unknown";
1781
+ const kind = classifyFailure(error, { source: "transport" }).kind;
1782
+ if (kind === "rate_limit") {
1783
+ return "rate_limit";
1700
1784
  }
1701
- if (error instanceof Error) {
1702
- const message = error.message.toLowerCase();
1703
- const name = error.name.toLowerCase();
1704
- if (message.includes("429") || message.includes("rate limit") || message.includes("too many requests") || message.includes("quota exceeded") || name.includes("ratelimit")) {
1705
- return "rate_limit";
1706
- }
1707
- if (message.includes("timeout") || message.includes("timed out") || message.includes("etimedout") || message.includes("deadline exceeded") || name.includes("timeout")) {
1708
- return "timeout";
1709
- }
1710
- if (message.includes("econnrefused") || message.includes("econnreset") || message.includes("enotfound") || message.includes("network") || message.includes("socket") || message.includes("dns") || name.includes("fetch") || name.includes("network")) {
1711
- return "network";
1712
- }
1713
- if (message.includes("500") || message.includes("502") || message.includes("503") || message.includes("504") || message.includes("internal server") || message.includes("bad gateway") || message.includes("service unavailable") || message.includes("gateway timeout")) {
1714
- return "server_error";
1715
- }
1716
- if (message.includes("400") || message.includes("401") || message.includes("403") || message.includes("404") || message.includes("bad request") || message.includes("unauthorized") || message.includes("forbidden") || message.includes("not found")) {
1717
- return "client_error";
1718
- }
1785
+ if (kind === "timeout") {
1786
+ return "timeout";
1719
1787
  }
1720
- if (typeof error === "object" && error !== null) {
1721
- const obj = error;
1722
- const status = obj.status ?? obj.statusCode ?? obj.code;
1723
- if (typeof status === "number") {
1724
- if (status === 429) {
1725
- return "rate_limit";
1726
- }
1727
- if (status >= 500) {
1728
- return "server_error";
1729
- }
1730
- if (status >= 400) {
1731
- return "client_error";
1732
- }
1733
- }
1734
- const code = obj.code;
1735
- if (typeof code === "string") {
1736
- const lowerCode = code.toLowerCase();
1737
- if (lowerCode.includes("timeout")) {
1738
- return "timeout";
1739
- }
1740
- if (lowerCode.includes("econnrefused")) {
1741
- return "network";
1742
- }
1743
- if (lowerCode.includes("econnreset")) {
1744
- return "network";
1745
- }
1746
- if (lowerCode.includes("enotfound")) {
1747
- return "network";
1748
- }
1749
- }
1788
+ if (kind === "network") {
1789
+ return "network";
1790
+ }
1791
+ if (kind === "server") {
1792
+ return "server_error";
1793
+ }
1794
+ if (kind === "validation" || kind === "authentication" || kind === "authorization" || kind === "not_found") {
1795
+ return "client_error";
1750
1796
  }
1751
1797
  return "unknown";
1752
1798
  }
@@ -1826,8 +1872,9 @@ function createQueuedVectorStore(broker, vectorStore) {
1826
1872
  return new QueuedVectorStore(broker, vectorStore);
1827
1873
  }
1828
1874
  var DEFAULT_RETRY_CONFIG, DEFAULT_RATE_LIMIT_CONFIG, PriorityQueue, RATE_LIMIT_PRESETS, ResourceBroker, InMemoryRateLimitBackend, QueuedLLM, QueuedEmbeddings, QueuedVectorStore;
1829
- var init_dist3 = __esm({
1875
+ var init_dist4 = __esm({
1830
1876
  "../../../core/resource-broker/dist/index.js"() {
1877
+ init_dist3();
1831
1878
  DEFAULT_RETRY_CONFIG = {
1832
1879
  maxRetries: 3,
1833
1880
  baseDelay: 1e3,
@@ -10451,14 +10498,14 @@ var require_scope = __commonJS({
10451
10498
  return (0, code_1._)`${scopeName}${name.scopePath}`;
10452
10499
  });
10453
10500
  }
10454
- scopeCode(values = this._values, usedValues, getCode) {
10501
+ scopeCode(values = this._values, usedValues, getCode2) {
10455
10502
  return this._reduceValues(values, (name) => {
10456
10503
  if (name.value === void 0)
10457
10504
  throw new Error(`CodeGen: name "${name}" has no value`);
10458
10505
  return name.value.code;
10459
- }, usedValues, getCode);
10506
+ }, usedValues, getCode2);
10460
10507
  }
10461
- _reduceValues(values, valueCode, usedValues = {}, getCode) {
10508
+ _reduceValues(values, valueCode, usedValues = {}, getCode2) {
10462
10509
  let code = code_1.nil;
10463
10510
  for (const prefix in values) {
10464
10511
  const vs = values[prefix];
@@ -10473,7 +10520,7 @@ var require_scope = __commonJS({
10473
10520
  if (c) {
10474
10521
  const def = this.opts.es5 ? exports$1.varKinds.var : exports$1.varKinds.const;
10475
10522
  code = (0, code_1._)`${code}${def} ${name} = ${c};${this.opts._n}`;
10476
- } else if (c = getCode === null || getCode === void 0 ? void 0 : getCode(name)) {
10523
+ } else if (c = getCode2 === null || getCode2 === void 0 ? void 0 : getCode2(name)) {
10477
10524
  code = (0, code_1._)`${code}${c}${this.opts._n}`;
10478
10525
  } else {
10479
10526
  throw new ValueError(name);
@@ -17137,34 +17184,10 @@ function serializeError(error) {
17137
17184
  return serialize(error);
17138
17185
  }
17139
17186
  function isRetryableError2(error) {
17140
- if (error instanceof TimeoutError) {
17141
- return true;
17142
- }
17143
17187
  if (error instanceof CircuitOpenError) {
17144
17188
  return false;
17145
17189
  }
17146
- const code = error.code;
17147
- if (code) {
17148
- const retryableCodes = [
17149
- "ECONNRESET",
17150
- // Connection reset
17151
- "ECONNREFUSED",
17152
- // Connection refused
17153
- "ETIMEDOUT",
17154
- // Operation timed out
17155
- "ENOTFOUND",
17156
- // DNS lookup failed
17157
- "EAI_AGAIN"
17158
- // DNS temporary failure
17159
- ];
17160
- return retryableCodes.includes(code);
17161
- }
17162
- const e = error;
17163
- const status = e.status ?? e.statusCode;
17164
- if (status) {
17165
- return status === 503 || status === 429;
17166
- }
17167
- return false;
17190
+ return classifyFailure(error, { source: "transport", phase: "dispatch" }).transient;
17168
17191
  }
17169
17192
  function getOperationTimeout(adapter, method) {
17170
17193
  const exactKey = `${adapter}.${method}`;
@@ -17245,9 +17268,10 @@ function createProxyPlatform(options) {
17245
17268
  };
17246
17269
  }
17247
17270
  var BulkTransferHelper, DEFAULT_SOCKET_PATH, UnixSocketServer, IPCServer, ChildIPCServer, TransportError, TimeoutError, CircuitOpenError, OPERATION_TIMEOUTS, IPCTransport, UnixSocketTransport, RemoteAdapter, CacheProxy, LLMProxy, EmbeddingsProxy, VectorStoreProxy, StorageProxy, DocumentDatabaseProxy, stripSignal, KVStoreProxy, stripSignal2, ConfigProxy, EventBusProxy, LoggerProxy;
17248
- var init_dist4 = __esm({
17271
+ var init_dist5 = __esm({
17249
17272
  "../../../core/ipc/dist/index.js"() {
17250
17273
  init_serializable();
17274
+ init_dist3();
17251
17275
  BulkTransferHelper = class _BulkTransferHelper {
17252
17276
  /** Map of temp file IDs to file paths (for cleanup) */
17253
17277
  static tempFiles = /* @__PURE__ */ new Map();
@@ -19098,7 +19122,7 @@ function getProviderFromEntry(entry) {
19098
19122
  return "default";
19099
19123
  }
19100
19124
  var TierResolver, CapabilityResolver, LLMRouter;
19101
- var init_dist5 = __esm({
19125
+ var init_dist6 = __esm({
19102
19126
  "../../../core/llm-router/dist/index.js"() {
19103
19127
  init_dist2();
19104
19128
  TierResolver = class {
@@ -21706,12 +21730,12 @@ function makeAssemblyHook(getLogger) {
21706
21730
  );
21707
21731
  }
21708
21732
  var PluginError, PermissionError, TimeoutError2, AbortError, PLATFORM_CONTEXT_KEY2, platformContext2, RUNTIME_CONTEXT_KEY2, runtimeContext2, HARDCODED_DENIED_PATTERNS, ALWAYS_ALLOWED, BLOCKED_COMMANDS, ANALYTICS_EVENT, EVENT_BUS_TOPIC, NAMESPACE_SEPARATOR, KV_NAMESPACE_SEPARATOR, validateName, wrapLogger, wrapLlm, wrapEmbeddings, wrapVectorStore, wrapCache, wrapStorage, wrapNotifier, ADAPTER_REGISTRY, PIPELINE_SLOTS, SLOT_ORDER, NOOP_LIFECYCLE, ANSI_RE;
21709
- var init_dist6 = __esm({
21733
+ var init_dist7 = __esm({
21710
21734
  "../../../core/plugin-runtime/dist/index.js"() {
21711
21735
  init_dist2();
21712
- init_dist3();
21713
- init_dist5();
21714
21736
  init_dist4();
21737
+ init_dist6();
21738
+ init_dist5();
21715
21739
  PluginError = class _PluginError extends Error {
21716
21740
  /**
21717
21741
  * Error code for programmatic handling
@@ -22366,7 +22390,7 @@ function createDefaultIPCServerFactory() {
22366
22390
  return async (platform2, executionId) => {
22367
22391
  const platformContainer = ensurePlatformContainer(platform2);
22368
22392
  if (process.platform === "win32") {
22369
- const { UnixSocketServer: UnixSocketServer22, createSocketPath: createSocketPath2 } = await Promise.resolve().then(() => (init_dist4(), dist_exports));
22393
+ const { UnixSocketServer: UnixSocketServer22, createSocketPath: createSocketPath2 } = await Promise.resolve().then(() => (init_dist5(), dist_exports));
22370
22394
  const socketPath = createSocketPath2(`subprocess-${executionId}`);
22371
22395
  const authToken = crypto.randomBytes(32).toString("hex");
22372
22396
  const serverConfig = { socketPath };
@@ -22374,7 +22398,7 @@ function createDefaultIPCServerFactory() {
22374
22398
  const server = new UnixSocketServer22(platformContainer, serverConfig);
22375
22399
  return new UnixSocketIPCServer(server, socketPath, authToken);
22376
22400
  } else {
22377
- const { UnixSocketServer: UnixSocketServer22, createSocketPath: createSocketPath2 } = await Promise.resolve().then(() => (init_dist4(), dist_exports));
22401
+ const { UnixSocketServer: UnixSocketServer22, createSocketPath: createSocketPath2 } = await Promise.resolve().then(() => (init_dist5(), dist_exports));
22378
22402
  const socketPath = createSocketPath2(`subprocess-${executionId}`);
22379
22403
  const authToken = crypto.randomBytes(32).toString("hex");
22380
22404
  const serverConfig = { socketPath };
@@ -22565,12 +22589,12 @@ function buildRoutingBackend(localBackend, remoteFactory, provisionEnvironment,
22565
22589
  };
22566
22590
  }
22567
22591
  var LocalWorkspaceManager, localWorkspaceManager, KNOWN_ERROR_CODES, ExecutionLayerError, TimeoutError3, AbortError2, HandlerContractError, HandlerNotFoundError, WorkspaceError, PermissionDeniedError, ValidationError, QueueFullError, AcquireTimeoutError, WorkerCrashedError, WorkerUnhealthyError, InProcessBackend, UnixSocketIPCServer, SubprocessBackend, UnixSocketPlatformTransportFactory, PoolStatsTracker, DEFAULT_STARTUP_TIMEOUT, DEFAULT_HEALTH_CHECK_TIMEOUT, Worker, PoolLifecycleManager, PoolQueueManager, PoolExecutor, WorkerPool, __dirname$1, WorkerPoolBackend, RemoteBackend, SubprocessRunnerAdapter, PROTOCOL_VERSION, DEFAULT_WORKER_POOL_CONFIG, IPCPlatformTransportFactory;
22568
- var init_dist7 = __esm({
22592
+ var init_dist8 = __esm({
22569
22593
  "../../../core/plugin-execution-factory/dist/index.js"() {
22570
22594
  init_dist();
22571
- init_dist6();
22595
+ init_dist7();
22572
22596
  init_dist2();
22573
- init_dist4();
22597
+ init_dist5();
22574
22598
  LocalWorkspaceManager = class {
22575
22599
  async lease(config, ctx) {
22576
22600
  return {
@@ -24582,7 +24606,7 @@ function sleep2(ms) {
24582
24606
  });
24583
24607
  }
24584
24608
  var DEFAULT_BUFFER_POLICY, AdaptiveBuffer, CALL_TIMEOUT_MS, HostCallDispatcher, globalDispatcher, GatewayDispatchTransport, HOSTS_COLLECTION, TOKENS_COLLECTION, docToDescriptor, HostStore, GatewayHostResolver;
24585
- var init_dist8 = __esm({
24609
+ var init_dist9 = __esm({
24586
24610
  "../../../services/gateway/core/dist/index.js"() {
24587
24611
  DEFAULT_BUFFER_POLICY = {
24588
24612
  minTTL: 3e4,
@@ -62266,7 +62290,7 @@ function isValidLock(value) {
62266
62290
  // ../../../core/runtime/dist/index.js
62267
62291
  init_serializable();
62268
62292
  init_dist2();
62269
- init_dist3();
62293
+ init_dist4();
62270
62294
 
62271
62295
  // ../../../node_modules/.pnpm/ulid@2.4.0/node_modules/ulid/dist/index.esm.js
62272
62296
  function createError(message) {
@@ -71961,8 +71985,8 @@ async function initPlatform(config = {}, cwd = process.cwd(), uiProvider, platfo
71961
71985
  );
71962
71986
  try {
71963
71987
  if (execution.mode === "container" && execution.container) {
71964
- const { createIsolatedExecutionBackend: createIsolatedExecutionBackend2 } = await Promise.resolve().then(() => (init_dist7(), dist_exports2));
71965
- const { GatewayDispatchTransport: GatewayDispatchTransport2 } = await Promise.resolve().then(() => (init_dist8(), dist_exports3));
71988
+ const { createIsolatedExecutionBackend: createIsolatedExecutionBackend2 } = await Promise.resolve().then(() => (init_dist8(), dist_exports2));
71989
+ const { GatewayDispatchTransport: GatewayDispatchTransport2 } = await Promise.resolve().then(() => (init_dist9(), dist_exports3));
71966
71990
  const containerCfg = execution.container;
71967
71991
  const strictIsolation = {
71968
71992
  buildTransport(ctx) {
@@ -72056,8 +72080,8 @@ async function initPlatform(config = {}, cwd = process.cwd(), uiProvider, platfo
72056
72080
  dispatchUrl: containerCfg.gatewayDispatchUrl
72057
72081
  });
72058
72082
  } else if (execution.workspaceAgent?.enabled && execution.workspaceAgent.gatewayUrl) {
72059
- const { createIsolatedExecutionBackend: createIsolatedExecutionBackend2 } = await Promise.resolve().then(() => (init_dist7(), dist_exports2));
72060
- const { GatewayHostResolver: GatewayHostResolver2, GatewayDispatchTransport: GatewayDispatchTransport2 } = await Promise.resolve().then(() => (init_dist8(), dist_exports3));
72083
+ const { createIsolatedExecutionBackend: createIsolatedExecutionBackend2 } = await Promise.resolve().then(() => (init_dist8(), dist_exports2));
72084
+ const { GatewayHostResolver: GatewayHostResolver2, GatewayDispatchTransport: GatewayDispatchTransport2 } = await Promise.resolve().then(() => (init_dist9(), dist_exports3));
72061
72085
  const agentCfg = execution.workspaceAgent;
72062
72086
  const hostResolver = new GatewayHostResolver2({
72063
72087
  gatewayUrl: agentCfg.gatewayUrl,
@@ -72105,7 +72129,7 @@ async function initPlatform(config = {}, cwd = process.cwd(), uiProvider, platfo
72105
72129
  fallback: agentCfg.fallback ?? "local"
72106
72130
  });
72107
72131
  } else {
72108
- const { createExecutionBackend: createExecutionBackend2 } = await Promise.resolve().then(() => (init_dist7(), dist_exports2));
72132
+ const { createExecutionBackend: createExecutionBackend2 } = await Promise.resolve().then(() => (init_dist8(), dist_exports2));
72109
72133
  const factoryMode = execution.mode ?? "auto";
72110
72134
  const executionBackend = createExecutionBackend2({
72111
72135
  platform,
@@ -72770,7 +72794,7 @@ init_container();
72770
72794
  init_adapter_status();
72771
72795
 
72772
72796
  // src/bootstrap.ts
72773
- init_dist6();
72797
+ init_dist7();
72774
72798
  async function runDaemon(config, platformBootstrap) {
72775
72799
  const repoRoot = await findRepoRoot(process.cwd());
72776
72800
  loadEnvFromRoot(repoRoot);