@theokit/sdk 2.0.0 → 2.1.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/CHANGELOG.md +36 -0
- package/dist/a2a/index.cjs +384 -317
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +384 -317
- package/dist/a2a/index.js.map +1 -1
- package/dist/concurrency.cjs +86 -0
- package/dist/concurrency.cjs.map +1 -0
- package/dist/concurrency.d.cts +13 -0
- package/dist/concurrency.d.ts +13 -0
- package/dist/concurrency.js +83 -0
- package/dist/concurrency.js.map +1 -0
- package/dist/{cron-Bse1MbaE.d.cts → cron-CSTqNZp9.d.cts} +2 -2
- package/dist/{cron-Ci_NUkUj.d.ts → cron-Da6vF_2y.d.ts} +2 -2
- package/dist/cron.cjs +346 -295
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +1 -1
- package/dist/cron.d.ts +1 -1
- package/dist/cron.js +349 -298
- package/dist/cron.js.map +1 -1
- package/dist/{errors-DV9e0rcp.d.ts → errors--VP2qrGc.d.ts} +23 -1
- package/dist/{errors-ChqOmFH1.d.cts → errors-C9xkhNEF.d.cts} +23 -1
- package/dist/errors.cjs +17 -11
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +1 -1
- package/dist/errors.d.ts +22 -0
- package/dist/errors.js +17 -12
- package/dist/errors.js.map +1 -1
- package/dist/eval.cjs +345 -291
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.d.cts +1 -0
- package/dist/eval.d.ts +1 -0
- package/dist/eval.js +348 -294
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +342 -275
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +161 -119
- package/dist/index.d.ts +161 -119
- package/dist/index.js +342 -277
- package/dist/index.js.map +1 -1
- package/dist/internal/persistence/index.cjs +75 -0
- package/dist/internal/persistence/index.cjs.map +1 -1
- package/dist/internal/persistence/index.d.cts +2 -0
- package/dist/internal/persistence/index.d.ts +2 -0
- package/dist/internal/persistence/index.js +74 -1
- package/dist/internal/persistence/index.js.map +1 -1
- package/dist/internal/persistence/sqlite-open.d.cts +47 -0
- package/dist/internal/persistence/sqlite-open.d.ts +47 -0
- package/dist/internal/providers/register-plugin-providers.d.ts +22 -0
- package/dist/internal/runtime/concurrency/map-with-concurrency.d.ts +28 -0
- package/dist/internal/runtime/{fork-agent.d.ts → lifecycle/fork-agent.d.ts} +1 -1
- package/dist/internal/runtime/{run-until.d.ts → lifecycle/run-until.d.ts} +3 -3
- package/dist/internal/runtime/local-agent/local-agent-bootstrap.d.ts +1 -1
- package/dist/internal/runtime/registry/agent-factory-registry.d.ts +12 -9
- package/dist/internal/runtime/retry/with-retry.d.ts +40 -0
- package/dist/internal/runtime/validation/validate-agent-options.d.ts +1 -0
- package/dist/internal/scorers/llm-judge.d.ts +4 -4
- package/dist/internal/security/index.cjs +1 -0
- package/dist/internal/security/index.cjs.map +1 -1
- package/dist/internal/security/index.d.cts +1 -1
- package/dist/internal/security/index.d.ts +1 -1
- package/dist/internal/security/index.js +1 -0
- package/dist/internal/security/index.js.map +1 -1
- package/dist/path-safety.cjs +15 -0
- package/dist/path-safety.cjs.map +1 -1
- package/dist/path-safety.d.cts +1 -1
- package/dist/path-safety.d.ts +1 -1
- package/dist/path-safety.js +15 -1
- package/dist/path-safety.js.map +1 -1
- package/dist/retry.cjs +85 -0
- package/dist/retry.cjs.map +1 -0
- package/dist/retry.d.cts +9 -0
- package/dist/retry.d.ts +9 -0
- package/dist/retry.js +83 -0
- package/dist/retry.js.map +1 -0
- package/dist/server/errors-envelope.cjs +14 -12
- package/dist/server/errors-envelope.cjs.map +1 -1
- package/dist/server/errors-envelope.js +14 -12
- package/dist/server/errors-envelope.js.map +1 -1
- package/dist/subscription/index.cjs.map +1 -1
- package/dist/subscription/index.js.map +1 -1
- package/dist/task-store.cjs.map +1 -1
- package/dist/task-store.js.map +1 -1
- package/dist/types/fork.d.ts +1 -1
- package/dist/workflow.cjs +2 -2
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.js +2 -2
- package/dist/workflow.js.map +1 -1
- package/package.json +26 -2
- /package/dist/internal/{runtime/default-model.d.ts → default-retriable.d.ts} +0 -0
- /package/dist/internal/{errors/mappers → error-mappers}/anthropic.d.ts +0 -0
- /package/dist/internal/{errors/mappers → error-mappers}/bedrock.d.ts +0 -0
- /package/dist/internal/{errors/mappers → error-mappers}/ollama.d.ts +0 -0
- /package/dist/internal/{errors/mappers → error-mappers}/openai-compatible.d.ts +0 -0
- /package/dist/internal/{errors/mappers → error-mappers}/shared.d.ts +0 -0
- /package/dist/internal/{errors/mappers → error-mappers}/vertex.d.ts +0 -0
- /package/dist/internal/runtime/{abort-utils.d.ts → concurrency/abort-utils.d.ts} +0 -0
- /package/dist/internal/runtime/{async-local-storage.d.ts → concurrency/async-local-storage.d.ts} +0 -0
- /package/dist/internal/runtime/{async-semaphore.d.ts → concurrency/async-semaphore.d.ts} +0 -0
- /package/dist/internal/runtime/{post-run-lifecycle.d.ts → config/default-model.d.ts} +0 -0
- /package/dist/internal/runtime/{providers-manager.d.ts → config/providers-manager.d.ts} +0 -0
- /package/dist/internal/runtime/{workspace-dir.d.ts → config/workspace-dir.d.ts} +0 -0
- /package/dist/internal/runtime/{yaml-frontmatter.d.ts → context/yaml-frontmatter.d.ts} +0 -0
- /package/dist/internal/runtime/{system-prompt.d.ts → lifecycle/post-run-lifecycle.d.ts} +0 -0
- /package/dist/internal/runtime/{spawn-collect.d.ts → lifecycle/spawn-collect.d.ts} +0 -0
- /package/dist/internal/runtime/{validate-agent-options.d.ts → system-prompt/system-prompt.d.ts} +0 -0
- /package/dist/internal/runtime/{shell-tool.d.ts → tools/shell-tool.d.ts} +0 -0
- /package/dist/internal/runtime/{validate-response.d.ts → validation/validate-response.d.ts} +0 -0
package/dist/cron.cjs
CHANGED
|
@@ -23,6 +23,24 @@ var __export = (target, all) => {
|
|
|
23
23
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
// src/internal/default-retriable.ts
|
|
27
|
+
function defaultRetriableForCode(code) {
|
|
28
|
+
switch (code) {
|
|
29
|
+
case "rate_limit":
|
|
30
|
+
case "timeout":
|
|
31
|
+
case "server_error":
|
|
32
|
+
case "network":
|
|
33
|
+
case "provider_unreachable":
|
|
34
|
+
return true;
|
|
35
|
+
default:
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
var init_default_retriable = __esm({
|
|
40
|
+
"src/internal/default-retriable.ts"() {
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
26
44
|
// src/internal/security/redact.ts
|
|
27
45
|
function readEnvOnce() {
|
|
28
46
|
const raw = process.env.THEOKIT_REDACT_SECRETS;
|
|
@@ -173,7 +191,8 @@ __export(errors_exports, {
|
|
|
173
191
|
UnsupportedBudgetOperationError: () => UnsupportedBudgetOperationError,
|
|
174
192
|
UnsupportedRunOperationError: () => UnsupportedRunOperationError,
|
|
175
193
|
UnsupportedTaskOperationError: () => UnsupportedTaskOperationError,
|
|
176
|
-
coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode
|
|
194
|
+
coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode,
|
|
195
|
+
isTransientError: () => isTransientError
|
|
177
196
|
});
|
|
178
197
|
function coerceToKnownAgentRunErrorCode(code) {
|
|
179
198
|
if (code !== void 0 && KNOWN_AGENT_RUN_ERROR_CODES.has(code)) {
|
|
@@ -205,21 +224,13 @@ function safeStringify(value) {
|
|
|
205
224
|
return String(value);
|
|
206
225
|
}
|
|
207
226
|
}
|
|
208
|
-
function
|
|
209
|
-
|
|
210
|
-
case "rate_limit":
|
|
211
|
-
case "timeout":
|
|
212
|
-
case "server_error":
|
|
213
|
-
case "network":
|
|
214
|
-
case "provider_unreachable":
|
|
215
|
-
return true;
|
|
216
|
-
default:
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
227
|
+
function isTransientError(err) {
|
|
228
|
+
return err instanceof TheokitAgentError && err.isRetryable === true;
|
|
219
229
|
}
|
|
220
230
|
var KNOWN_AGENT_RUN_ERROR_CODES, TheokitAgentError, AuthenticationError, RateLimitError, ConfigurationError, IntegrationNotConnectedError, NetworkError, UnknownAgentError, AgentRunError, UnsupportedRunOperationError, CredentialPoolExhaustedError, MemoryAdapterError, InvalidTaskIdError, TaskNotFoundError, UnsupportedTaskOperationError, BudgetExceededError, AgentDisposedError, UnsupportedBudgetOperationError;
|
|
221
231
|
var init_errors = __esm({
|
|
222
232
|
"src/errors.ts"() {
|
|
233
|
+
init_default_retriable();
|
|
223
234
|
init_redact();
|
|
224
235
|
KNOWN_AGENT_RUN_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
225
236
|
"rate_limit",
|
|
@@ -586,7 +597,7 @@ var init_atomic_write = __esm({
|
|
|
586
597
|
}
|
|
587
598
|
});
|
|
588
599
|
|
|
589
|
-
// src/internal/runtime/yaml-frontmatter.ts
|
|
600
|
+
// src/internal/runtime/context/yaml-frontmatter.ts
|
|
590
601
|
function parseSimpleYaml(text) {
|
|
591
602
|
const fields = {};
|
|
592
603
|
for (const line of text.split(/\r?\n/)) {
|
|
@@ -610,7 +621,7 @@ function coerce(raw) {
|
|
|
610
621
|
return raw;
|
|
611
622
|
}
|
|
612
623
|
var init_yaml_frontmatter = __esm({
|
|
613
|
-
"src/internal/runtime/yaml-frontmatter.ts"() {
|
|
624
|
+
"src/internal/runtime/context/yaml-frontmatter.ts"() {
|
|
614
625
|
}
|
|
615
626
|
});
|
|
616
627
|
async function loadMarkdownEntities(opts) {
|
|
@@ -813,11 +824,54 @@ function checkToolWhitelist(toolName) {
|
|
|
813
824
|
}
|
|
814
825
|
var toolWhitelistStore;
|
|
815
826
|
var init_async_local_storage = __esm({
|
|
816
|
-
"src/internal/runtime/async-local-storage.ts"() {
|
|
827
|
+
"src/internal/runtime/concurrency/async-local-storage.ts"() {
|
|
817
828
|
toolWhitelistStore = new async_hooks.AsyncLocalStorage();
|
|
818
829
|
}
|
|
819
830
|
});
|
|
820
831
|
|
|
832
|
+
// src/internal/runtime/concurrency/async-semaphore.ts
|
|
833
|
+
function createSemaphore(permits) {
|
|
834
|
+
if (!Number.isInteger(permits) || permits < 1) {
|
|
835
|
+
throw new ConfigurationError(
|
|
836
|
+
`async-semaphore: permits must be a positive integer, got ${permits}`,
|
|
837
|
+
{ code: "invalid_concurrency" }
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
let active = 0;
|
|
841
|
+
const queue = [];
|
|
842
|
+
function tryGrant() {
|
|
843
|
+
if (active < permits && queue.length > 0) {
|
|
844
|
+
const resolve3 = queue.shift();
|
|
845
|
+
if (resolve3 !== void 0) {
|
|
846
|
+
active += 1;
|
|
847
|
+
resolve3();
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return {
|
|
852
|
+
inFlight: () => active,
|
|
853
|
+
pending: () => queue.length + active,
|
|
854
|
+
async acquire() {
|
|
855
|
+
await new Promise((resolve3) => {
|
|
856
|
+
queue.push(resolve3);
|
|
857
|
+
tryGrant();
|
|
858
|
+
});
|
|
859
|
+
let released = false;
|
|
860
|
+
return () => {
|
|
861
|
+
if (released) return;
|
|
862
|
+
released = true;
|
|
863
|
+
active -= 1;
|
|
864
|
+
tryGrant();
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
var init_async_semaphore = __esm({
|
|
870
|
+
"src/internal/runtime/concurrency/async-semaphore.ts"() {
|
|
871
|
+
init_errors();
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
|
|
821
875
|
// src/internal/llm/credential-pool-types.ts
|
|
822
876
|
var COOLDOWN_MS, DEFAULT_COOLDOWN_MS;
|
|
823
877
|
var init_credential_pool_types = __esm({
|
|
@@ -1162,7 +1216,7 @@ var init_local_agent_plugins = __esm({
|
|
|
1162
1216
|
}
|
|
1163
1217
|
});
|
|
1164
1218
|
|
|
1165
|
-
// src/internal/runtime/run-until.ts
|
|
1219
|
+
// src/internal/runtime/lifecycle/run-until.ts
|
|
1166
1220
|
var run_until_exports = {};
|
|
1167
1221
|
__export(run_until_exports, {
|
|
1168
1222
|
composeContinuation: () => composeContinuation,
|
|
@@ -1255,7 +1309,7 @@ Your last response was:
|
|
|
1255
1309
|
${lastResponse.slice(0, 1e3)}`;
|
|
1256
1310
|
}
|
|
1257
1311
|
var init_run_until = __esm({
|
|
1258
|
-
"src/internal/runtime/run-until.ts"() {
|
|
1312
|
+
"src/internal/runtime/lifecycle/run-until.ts"() {
|
|
1259
1313
|
}
|
|
1260
1314
|
});
|
|
1261
1315
|
|
|
@@ -1366,16 +1420,16 @@ var init_judge_call = __esm({
|
|
|
1366
1420
|
// src/internal/runtime/registry/agent-factory-registry.ts
|
|
1367
1421
|
var agent_factory_registry_exports = {};
|
|
1368
1422
|
__export(agent_factory_registry_exports, {
|
|
1369
|
-
|
|
1370
|
-
|
|
1423
|
+
getAgentFacade: () => getAgentFacade,
|
|
1424
|
+
setAgentFacade: () => setAgentFacade
|
|
1371
1425
|
});
|
|
1372
|
-
function
|
|
1373
|
-
registered3 =
|
|
1426
|
+
function setAgentFacade(facade) {
|
|
1427
|
+
registered3 = facade;
|
|
1374
1428
|
}
|
|
1375
|
-
function
|
|
1429
|
+
function getAgentFacade() {
|
|
1376
1430
|
if (registered3 === void 0) {
|
|
1377
1431
|
throw new Error(
|
|
1378
|
-
"internal: Agent
|
|
1432
|
+
"internal: Agent facade not registered. The `agent.ts` module must be loaded before internal subsystems (LocalAgent.runUntil/fork, eval, scorers, cron) invoke it."
|
|
1379
1433
|
);
|
|
1380
1434
|
}
|
|
1381
1435
|
return registered3;
|
|
@@ -1386,7 +1440,7 @@ var init_agent_factory_registry = __esm({
|
|
|
1386
1440
|
}
|
|
1387
1441
|
});
|
|
1388
1442
|
|
|
1389
|
-
// src/internal/runtime/fork-agent.ts
|
|
1443
|
+
// src/internal/runtime/lifecycle/fork-agent.ts
|
|
1390
1444
|
var fork_agent_exports = {};
|
|
1391
1445
|
__export(fork_agent_exports, {
|
|
1392
1446
|
filterMemoryPlugins: () => filterMemoryPlugins,
|
|
@@ -1446,7 +1500,7 @@ function extractUsage(result) {
|
|
|
1446
1500
|
};
|
|
1447
1501
|
}
|
|
1448
1502
|
var init_fork_agent = __esm({
|
|
1449
|
-
"src/internal/runtime/fork-agent.ts"() {
|
|
1503
|
+
"src/internal/runtime/lifecycle/fork-agent.ts"() {
|
|
1450
1504
|
init_async_local_storage();
|
|
1451
1505
|
init_local_agent_plugins();
|
|
1452
1506
|
}
|
|
@@ -1469,49 +1523,6 @@ var init_task = __esm({
|
|
|
1469
1523
|
}
|
|
1470
1524
|
});
|
|
1471
1525
|
|
|
1472
|
-
// src/internal/runtime/async-semaphore.ts
|
|
1473
|
-
function createSemaphore(permits) {
|
|
1474
|
-
if (!Number.isInteger(permits) || permits < 1) {
|
|
1475
|
-
throw new ConfigurationError(
|
|
1476
|
-
`async-semaphore: permits must be a positive integer, got ${permits}`,
|
|
1477
|
-
{ code: "invalid_concurrency" }
|
|
1478
|
-
);
|
|
1479
|
-
}
|
|
1480
|
-
let active = 0;
|
|
1481
|
-
const queue = [];
|
|
1482
|
-
function tryGrant() {
|
|
1483
|
-
if (active < permits && queue.length > 0) {
|
|
1484
|
-
const resolve3 = queue.shift();
|
|
1485
|
-
if (resolve3 !== void 0) {
|
|
1486
|
-
active += 1;
|
|
1487
|
-
resolve3();
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
return {
|
|
1492
|
-
inFlight: () => active,
|
|
1493
|
-
pending: () => queue.length + active,
|
|
1494
|
-
async acquire() {
|
|
1495
|
-
await new Promise((resolve3) => {
|
|
1496
|
-
queue.push(resolve3);
|
|
1497
|
-
tryGrant();
|
|
1498
|
-
});
|
|
1499
|
-
let released = false;
|
|
1500
|
-
return () => {
|
|
1501
|
-
if (released) return;
|
|
1502
|
-
released = true;
|
|
1503
|
-
active -= 1;
|
|
1504
|
-
tryGrant();
|
|
1505
|
-
};
|
|
1506
|
-
}
|
|
1507
|
-
};
|
|
1508
|
-
}
|
|
1509
|
-
var init_async_semaphore = __esm({
|
|
1510
|
-
"src/internal/runtime/async-semaphore.ts"() {
|
|
1511
|
-
init_errors();
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
|
-
|
|
1515
1526
|
// src/internal/task/ring-buffer.ts
|
|
1516
1527
|
var RingBuffer;
|
|
1517
1528
|
var init_ring_buffer = __esm({
|
|
@@ -2591,9 +2602,6 @@ var init_batch = __esm({
|
|
|
2591
2602
|
}
|
|
2592
2603
|
});
|
|
2593
2604
|
|
|
2594
|
-
// src/cron.ts
|
|
2595
|
-
init_errors();
|
|
2596
|
-
|
|
2597
2605
|
// src/agent-builder.ts
|
|
2598
2606
|
var AgentBuilder = class {
|
|
2599
2607
|
opts = {};
|
|
@@ -3090,8 +3098,21 @@ function sanitizeIdentifier(input, options) {
|
|
|
3090
3098
|
}
|
|
3091
3099
|
return input.toLowerCase();
|
|
3092
3100
|
}
|
|
3101
|
+
function safeFilenameForId(id, options) {
|
|
3102
|
+
if (id.length === 0) {
|
|
3103
|
+
throw new ConfigurationError("Filename id must be a non-empty string", {
|
|
3104
|
+
code: "invalid_filename_id"
|
|
3105
|
+
});
|
|
3106
|
+
}
|
|
3107
|
+
const maxLen = options?.maxLen;
|
|
3108
|
+
const lower = id.toLowerCase();
|
|
3109
|
+
if (lower.length <= maxLen && IDENTIFIER_PATTERN.test(lower)) {
|
|
3110
|
+
return lower;
|
|
3111
|
+
}
|
|
3112
|
+
return `h-${crypto.createHash("sha256").update(id).digest("hex").slice(0, 16)}`;
|
|
3113
|
+
}
|
|
3093
3114
|
|
|
3094
|
-
// src/internal/runtime/default-model.ts
|
|
3115
|
+
// src/internal/runtime/config/default-model.ts
|
|
3095
3116
|
var DEFAULT_AGENTIC_MODEL_ID = "google/gemini-2.0-flash-001";
|
|
3096
3117
|
|
|
3097
3118
|
// src/internal/runtime/registry/agent-registry-store.ts
|
|
@@ -3412,7 +3433,7 @@ async function flushRegistrySaves(cwd) {
|
|
|
3412
3433
|
}
|
|
3413
3434
|
}
|
|
3414
3435
|
|
|
3415
|
-
// src/internal/runtime/system-prompt.ts
|
|
3436
|
+
// src/internal/runtime/system-prompt/system-prompt.ts
|
|
3416
3437
|
async function resolveSystemPrompt(agent, override, ctx) {
|
|
3417
3438
|
if (override !== void 0) return override;
|
|
3418
3439
|
if (agent === void 0) return void 0;
|
|
@@ -5795,28 +5816,6 @@ function parseDecisionFromStdout(stdout) {
|
|
|
5795
5816
|
return { decision: "allow" };
|
|
5796
5817
|
}
|
|
5797
5818
|
|
|
5798
|
-
// src/internal/runtime/memory/memory-path-selector.ts
|
|
5799
|
-
var PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
|
|
5800
|
-
function shouldUsePortMemoryPath() {
|
|
5801
|
-
const env = globalThis.process?.env;
|
|
5802
|
-
if (env === void 0) return false;
|
|
5803
|
-
const val = env[PORT_MEMORY_PATH_ENV_VAR];
|
|
5804
|
-
return val === "1" || val === "true";
|
|
5805
|
-
}
|
|
5806
|
-
function resolveMemoryProviderForLoop(consumerSupplied, defaultAdapter, portPathEnabled) {
|
|
5807
|
-
if (consumerSupplied !== void 0) return consumerSupplied;
|
|
5808
|
-
if (portPathEnabled) return defaultAdapter;
|
|
5809
|
-
return void 0;
|
|
5810
|
-
}
|
|
5811
|
-
function resolveMemoryToolsForLoop(legacyTools, portPathEnabled) {
|
|
5812
|
-
if (portPathEnabled) return void 0;
|
|
5813
|
-
return legacyTools;
|
|
5814
|
-
}
|
|
5815
|
-
function resolveActiveMemorySummaryForSend(legacySummary, portPathEnabled) {
|
|
5816
|
-
if (portPathEnabled) return void 0;
|
|
5817
|
-
return legacySummary;
|
|
5818
|
-
}
|
|
5819
|
-
|
|
5820
5819
|
// src/internal/memory/storage/session-summary-writer.ts
|
|
5821
5820
|
init_atomic_write();
|
|
5822
5821
|
var MAX_TURN_CHARS = 2e3;
|
|
@@ -5824,10 +5823,7 @@ function sessionsDir(cwd) {
|
|
|
5824
5823
|
return path.join(memoryDir(cwd), "sessions");
|
|
5825
5824
|
}
|
|
5826
5825
|
function sessionSummaryPath(cwd, runId) {
|
|
5827
|
-
return path.join(sessionsDir(cwd), `${
|
|
5828
|
-
}
|
|
5829
|
-
function sanitizeRunId(runId) {
|
|
5830
|
-
return runId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 128);
|
|
5826
|
+
return path.join(sessionsDir(cwd), `${safeFilenameForId(runId, { maxLen: 128 })}.md`);
|
|
5831
5827
|
}
|
|
5832
5828
|
function truncate(text) {
|
|
5833
5829
|
if (text.length <= MAX_TURN_CHARS) return text;
|
|
@@ -5860,6 +5856,28 @@ async function writeSessionSummary(input) {
|
|
|
5860
5856
|
await replaceFileAtomic(path, body);
|
|
5861
5857
|
}
|
|
5862
5858
|
|
|
5859
|
+
// src/internal/runtime/memory/memory-path-selector.ts
|
|
5860
|
+
var PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
|
|
5861
|
+
function shouldUsePortMemoryPath() {
|
|
5862
|
+
const env = globalThis.process?.env;
|
|
5863
|
+
if (env === void 0) return false;
|
|
5864
|
+
const val = env[PORT_MEMORY_PATH_ENV_VAR];
|
|
5865
|
+
return val === "1" || val === "true";
|
|
5866
|
+
}
|
|
5867
|
+
function resolveMemoryProviderForLoop(consumerSupplied, defaultAdapter, portPathEnabled) {
|
|
5868
|
+
if (consumerSupplied !== void 0) return consumerSupplied;
|
|
5869
|
+
if (portPathEnabled) return defaultAdapter;
|
|
5870
|
+
return void 0;
|
|
5871
|
+
}
|
|
5872
|
+
function resolveMemoryToolsForLoop(legacyTools, portPathEnabled) {
|
|
5873
|
+
if (portPathEnabled) return void 0;
|
|
5874
|
+
return legacyTools;
|
|
5875
|
+
}
|
|
5876
|
+
function resolveActiveMemorySummaryForSend(legacySummary, portPathEnabled) {
|
|
5877
|
+
if (portPathEnabled) return void 0;
|
|
5878
|
+
return legacySummary;
|
|
5879
|
+
}
|
|
5880
|
+
|
|
5863
5881
|
// src/internal/runtime/session/agent-session-store.ts
|
|
5864
5882
|
init_atomic_write();
|
|
5865
5883
|
var VALID_ROLES = /* @__PURE__ */ new Set([
|
|
@@ -6116,7 +6134,7 @@ function clearSession(agentId) {
|
|
|
6116
6134
|
sessions.delete(agentId);
|
|
6117
6135
|
}
|
|
6118
6136
|
|
|
6119
|
-
// src/internal/runtime/post-run-lifecycle.ts
|
|
6137
|
+
// src/internal/runtime/lifecycle/post-run-lifecycle.ts
|
|
6120
6138
|
async function runPostRunLifecycle(inputs) {
|
|
6121
6139
|
const {
|
|
6122
6140
|
run,
|
|
@@ -6348,7 +6366,7 @@ var liveAgentRegistry = new LiveAgentRegistry();
|
|
|
6348
6366
|
// src/internal/runtime/skills/subagents-loader.ts
|
|
6349
6367
|
init_errors();
|
|
6350
6368
|
|
|
6351
|
-
// src/internal/runtime/workspace-dir.ts
|
|
6369
|
+
// src/internal/runtime/config/workspace-dir.ts
|
|
6352
6370
|
init_errors();
|
|
6353
6371
|
async function readWorkspaceDir(root, errorCode, describe) {
|
|
6354
6372
|
try {
|
|
@@ -6634,7 +6652,7 @@ var SystemPromptPipeline = class _SystemPromptPipeline {
|
|
|
6634
6652
|
}
|
|
6635
6653
|
};
|
|
6636
6654
|
|
|
6637
|
-
// src/internal/runtime/validate-agent-options.ts
|
|
6655
|
+
// src/internal/runtime/validation/validate-agent-options.ts
|
|
6638
6656
|
init_errors();
|
|
6639
6657
|
function validateAgentOptions(options) {
|
|
6640
6658
|
rejectProgrammaticHooks(options);
|
|
@@ -6829,6 +6847,71 @@ function validateMemory(options) {
|
|
|
6829
6847
|
}
|
|
6830
6848
|
}
|
|
6831
6849
|
|
|
6850
|
+
// src/internal/runtime/config/providers-manager.ts
|
|
6851
|
+
var ProvidersManagerImpl = class {
|
|
6852
|
+
constructor(model, providers, plugins) {
|
|
6853
|
+
this.model = model;
|
|
6854
|
+
this.providers = providers;
|
|
6855
|
+
this.plugins = plugins;
|
|
6856
|
+
}
|
|
6857
|
+
model;
|
|
6858
|
+
providers;
|
|
6859
|
+
plugins;
|
|
6860
|
+
routes() {
|
|
6861
|
+
const resolved = [];
|
|
6862
|
+
const modelProvider = providerFromModel(this.model);
|
|
6863
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6864
|
+
if (this.providers?.routes !== void 0) {
|
|
6865
|
+
for (const route of this.providers.routes) {
|
|
6866
|
+
const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
|
|
6867
|
+
if (!seen.has(route.capability)) {
|
|
6868
|
+
seen.add(route.capability);
|
|
6869
|
+
resolved.push(resolvedRoute);
|
|
6870
|
+
}
|
|
6871
|
+
}
|
|
6872
|
+
}
|
|
6873
|
+
return Promise.resolve(resolved);
|
|
6874
|
+
}
|
|
6875
|
+
};
|
|
6876
|
+
function providerFromModel(model) {
|
|
6877
|
+
if (model === void 0) return void 0;
|
|
6878
|
+
const id = model.id;
|
|
6879
|
+
if (id.includes(":")) return id.split(":")[0];
|
|
6880
|
+
return void 0;
|
|
6881
|
+
}
|
|
6882
|
+
function resolveRoute(route, modelProvider, plugins) {
|
|
6883
|
+
if (route.capability === "chat" && modelProvider === route.provider) {
|
|
6884
|
+
const modelName = extractModelName(modelProvider, route);
|
|
6885
|
+
const base = {
|
|
6886
|
+
capability: route.capability,
|
|
6887
|
+
provider: route.provider,
|
|
6888
|
+
reason: "explicit-model-provider"
|
|
6889
|
+
};
|
|
6890
|
+
if (modelName !== void 0) base.model = modelName;
|
|
6891
|
+
return base;
|
|
6892
|
+
}
|
|
6893
|
+
if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
|
|
6894
|
+
return {
|
|
6895
|
+
capability: route.capability,
|
|
6896
|
+
provider: route.provider,
|
|
6897
|
+
reason: "first-available-plugin-provider"
|
|
6898
|
+
};
|
|
6899
|
+
}
|
|
6900
|
+
return {
|
|
6901
|
+
capability: route.capability,
|
|
6902
|
+
provider: route.provider,
|
|
6903
|
+
reason: "explicit-route"
|
|
6904
|
+
};
|
|
6905
|
+
}
|
|
6906
|
+
function extractModelName(prefix, route) {
|
|
6907
|
+
if (route.model !== void 0) return route.model;
|
|
6908
|
+
return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
|
|
6909
|
+
}
|
|
6910
|
+
function defaultModelForProvider(provider) {
|
|
6911
|
+
if (provider === "anthropic") return "claude-3-7-sonnet";
|
|
6912
|
+
return void 0;
|
|
6913
|
+
}
|
|
6914
|
+
|
|
6832
6915
|
// src/internal/runtime/context/context-manager.ts
|
|
6833
6916
|
init_errors();
|
|
6834
6917
|
init_markdown_config_loader();
|
|
@@ -7625,71 +7708,6 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
|
|
|
7625
7708
|
return metadata;
|
|
7626
7709
|
}
|
|
7627
7710
|
|
|
7628
|
-
// src/internal/runtime/providers-manager.ts
|
|
7629
|
-
var ProvidersManagerImpl = class {
|
|
7630
|
-
constructor(model, providers, plugins) {
|
|
7631
|
-
this.model = model;
|
|
7632
|
-
this.providers = providers;
|
|
7633
|
-
this.plugins = plugins;
|
|
7634
|
-
}
|
|
7635
|
-
model;
|
|
7636
|
-
providers;
|
|
7637
|
-
plugins;
|
|
7638
|
-
routes() {
|
|
7639
|
-
const resolved = [];
|
|
7640
|
-
const modelProvider = providerFromModel(this.model);
|
|
7641
|
-
const seen = /* @__PURE__ */ new Set();
|
|
7642
|
-
if (this.providers?.routes !== void 0) {
|
|
7643
|
-
for (const route of this.providers.routes) {
|
|
7644
|
-
const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
|
|
7645
|
-
if (!seen.has(route.capability)) {
|
|
7646
|
-
seen.add(route.capability);
|
|
7647
|
-
resolved.push(resolvedRoute);
|
|
7648
|
-
}
|
|
7649
|
-
}
|
|
7650
|
-
}
|
|
7651
|
-
return Promise.resolve(resolved);
|
|
7652
|
-
}
|
|
7653
|
-
};
|
|
7654
|
-
function providerFromModel(model) {
|
|
7655
|
-
if (model === void 0) return void 0;
|
|
7656
|
-
const id = model.id;
|
|
7657
|
-
if (id.includes(":")) return id.split(":")[0];
|
|
7658
|
-
return void 0;
|
|
7659
|
-
}
|
|
7660
|
-
function resolveRoute(route, modelProvider, plugins) {
|
|
7661
|
-
if (route.capability === "chat" && modelProvider === route.provider) {
|
|
7662
|
-
const modelName = extractModelName(modelProvider, route);
|
|
7663
|
-
const base = {
|
|
7664
|
-
capability: route.capability,
|
|
7665
|
-
provider: route.provider,
|
|
7666
|
-
reason: "explicit-model-provider"
|
|
7667
|
-
};
|
|
7668
|
-
if (modelName !== void 0) base.model = modelName;
|
|
7669
|
-
return base;
|
|
7670
|
-
}
|
|
7671
|
-
if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
|
|
7672
|
-
return {
|
|
7673
|
-
capability: route.capability,
|
|
7674
|
-
provider: route.provider,
|
|
7675
|
-
reason: "first-available-plugin-provider"
|
|
7676
|
-
};
|
|
7677
|
-
}
|
|
7678
|
-
return {
|
|
7679
|
-
capability: route.capability,
|
|
7680
|
-
provider: route.provider,
|
|
7681
|
-
reason: "explicit-route"
|
|
7682
|
-
};
|
|
7683
|
-
}
|
|
7684
|
-
function extractModelName(prefix, route) {
|
|
7685
|
-
if (route.model !== void 0) return route.model;
|
|
7686
|
-
return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
|
|
7687
|
-
}
|
|
7688
|
-
function defaultModelForProvider(provider) {
|
|
7689
|
-
if (provider === "anthropic") return "claude-3-7-sonnet";
|
|
7690
|
-
return void 0;
|
|
7691
|
-
}
|
|
7692
|
-
|
|
7693
7711
|
// src/internal/runtime/skills/skills-manager.ts
|
|
7694
7712
|
init_errors();
|
|
7695
7713
|
|
|
@@ -8036,7 +8054,7 @@ var IterationBudget = class {
|
|
|
8036
8054
|
}
|
|
8037
8055
|
};
|
|
8038
8056
|
|
|
8039
|
-
// src/internal/runtime/validate-response.ts
|
|
8057
|
+
// src/internal/runtime/validation/validate-response.ts
|
|
8040
8058
|
function validateResponse(response) {
|
|
8041
8059
|
const trimmed = response.content.trim();
|
|
8042
8060
|
const toolCallsArr = Array.isArray(response.toolCalls) ? response.toolCalls : [];
|
|
@@ -8422,6 +8440,27 @@ async function emitTextDeltaCallback(inputs, text) {
|
|
|
8422
8440
|
// src/internal/agent-loop/tool-dispatch.ts
|
|
8423
8441
|
init_async_local_storage();
|
|
8424
8442
|
|
|
8443
|
+
// src/internal/runtime/concurrency/map-with-concurrency.ts
|
|
8444
|
+
init_async_semaphore();
|
|
8445
|
+
var NEVER_ABORT = new AbortController().signal;
|
|
8446
|
+
async function mapWithConcurrency(items, concurrency, fn, options) {
|
|
8447
|
+
const semaphore = createSemaphore(concurrency);
|
|
8448
|
+
const signal = NEVER_ABORT;
|
|
8449
|
+
return Promise.all(
|
|
8450
|
+
items.map(async (item, index) => {
|
|
8451
|
+
const release = await semaphore.acquire();
|
|
8452
|
+
try {
|
|
8453
|
+
if (signal.aborted) {
|
|
8454
|
+
throw signal.reason instanceof Error ? signal.reason : new Error("mapWithConcurrency: aborted");
|
|
8455
|
+
}
|
|
8456
|
+
return await fn(item, index, signal);
|
|
8457
|
+
} finally {
|
|
8458
|
+
release();
|
|
8459
|
+
}
|
|
8460
|
+
})
|
|
8461
|
+
);
|
|
8462
|
+
}
|
|
8463
|
+
|
|
8425
8464
|
// src/internal/tool-dispatch/repair-middleware.ts
|
|
8426
8465
|
var DECIMAL_RE = /^-?\d+(\.\d+)?$/;
|
|
8427
8466
|
function repairToolCall(raw, registry) {
|
|
@@ -8495,7 +8534,7 @@ function coerceArgsToSchema(args, schema) {
|
|
|
8495
8534
|
return { value: out, changed };
|
|
8496
8535
|
}
|
|
8497
8536
|
|
|
8498
|
-
// src/internal/runtime/shell-tool.ts
|
|
8537
|
+
// src/internal/runtime/tools/shell-tool.ts
|
|
8499
8538
|
async function runShell(options) {
|
|
8500
8539
|
if (options.sandbox === true && isObviouslyUnsafe(options.command)) {
|
|
8501
8540
|
return {
|
|
@@ -8596,38 +8635,12 @@ ${result.stderr}`.trim();
|
|
|
8596
8635
|
// src/internal/agent-loop/tool-dispatch.ts
|
|
8597
8636
|
async function dispatchTools(inputs, tools, toolCalls, events) {
|
|
8598
8637
|
const maxConcurrent = inputs.maxConcurrentTools ?? 4;
|
|
8599
|
-
return
|
|
8600
|
-
maxConcurrent,
|
|
8638
|
+
return mapWithConcurrency(
|
|
8601
8639
|
toolCalls,
|
|
8640
|
+
maxConcurrent,
|
|
8602
8641
|
(call) => dispatchSingleCall(inputs, tools, call, events)
|
|
8603
8642
|
);
|
|
8604
8643
|
}
|
|
8605
|
-
async function boundedParallel(max, items, fn) {
|
|
8606
|
-
let running = 0;
|
|
8607
|
-
const queue = [];
|
|
8608
|
-
async function acquire() {
|
|
8609
|
-
if (running < max) {
|
|
8610
|
-
running++;
|
|
8611
|
-
return;
|
|
8612
|
-
}
|
|
8613
|
-
await new Promise((resolve3) => queue.push(resolve3));
|
|
8614
|
-
running++;
|
|
8615
|
-
}
|
|
8616
|
-
function release() {
|
|
8617
|
-
running--;
|
|
8618
|
-
if (queue.length > 0) queue.shift()();
|
|
8619
|
-
}
|
|
8620
|
-
return Promise.all(
|
|
8621
|
-
items.map(async (item) => {
|
|
8622
|
-
await acquire();
|
|
8623
|
-
try {
|
|
8624
|
-
return await fn(item);
|
|
8625
|
-
} finally {
|
|
8626
|
-
release();
|
|
8627
|
-
}
|
|
8628
|
-
})
|
|
8629
|
-
);
|
|
8630
|
-
}
|
|
8631
8644
|
async function dispatchSingleCall(inputs, tools, call, events) {
|
|
8632
8645
|
const { call: workingCall, repairs } = applyRepairAndExtractCall(tools, call);
|
|
8633
8646
|
const callId = generateCallId();
|
|
@@ -9696,10 +9709,10 @@ function registerBuiltins() {
|
|
|
9696
9709
|
registerCatalogProviders();
|
|
9697
9710
|
}
|
|
9698
9711
|
|
|
9699
|
-
// src/internal/
|
|
9712
|
+
// src/internal/error-mappers/anthropic.ts
|
|
9700
9713
|
init_errors();
|
|
9701
9714
|
|
|
9702
|
-
// src/internal/
|
|
9715
|
+
// src/internal/error-mappers/shared.ts
|
|
9703
9716
|
var RAW_MAX_BYTES = 2048;
|
|
9704
9717
|
function parseRetryAfter(headers) {
|
|
9705
9718
|
if (headers === void 0) return void 0;
|
|
@@ -9728,7 +9741,7 @@ function buildErrorMetadata(args) {
|
|
|
9728
9741
|
};
|
|
9729
9742
|
}
|
|
9730
9743
|
|
|
9731
|
-
// src/internal/
|
|
9744
|
+
// src/internal/error-mappers/anthropic.ts
|
|
9732
9745
|
function mapAnthropicError(args) {
|
|
9733
9746
|
const { status, body, headers, endpoint } = args;
|
|
9734
9747
|
const code = mapAnthropicStatusToCode(status, body);
|
|
@@ -10068,7 +10081,7 @@ function buildAnthropicBody(request) {
|
|
|
10068
10081
|
// src/internal/llm/bedrock-anthropic.ts
|
|
10069
10082
|
init_errors();
|
|
10070
10083
|
|
|
10071
|
-
// src/internal/
|
|
10084
|
+
// src/internal/error-mappers/bedrock.ts
|
|
10072
10085
|
init_errors();
|
|
10073
10086
|
function classifyBedrockError(args, awsType, message) {
|
|
10074
10087
|
if (args.status === 429 || awsType.includes("Throttling") || awsType.includes("TooManyRequests")) {
|
|
@@ -10205,7 +10218,7 @@ function buildBedrockBody(request) {
|
|
|
10205
10218
|
init_credential_pool();
|
|
10206
10219
|
init_credential_pool_context();
|
|
10207
10220
|
|
|
10208
|
-
// src/internal/
|
|
10221
|
+
// src/internal/error-mappers/openai-compatible.ts
|
|
10209
10222
|
init_errors();
|
|
10210
10223
|
function mapOpenAICompatibleError(args) {
|
|
10211
10224
|
const { providerId, status, body, headers, endpoint } = args;
|
|
@@ -10369,7 +10382,7 @@ function readOpenAiContent(body) {
|
|
|
10369
10382
|
return void 0;
|
|
10370
10383
|
}
|
|
10371
10384
|
|
|
10372
|
-
// src/internal/
|
|
10385
|
+
// src/internal/error-mappers/ollama.ts
|
|
10373
10386
|
init_errors();
|
|
10374
10387
|
function mapOllamaTransportError(args) {
|
|
10375
10388
|
if (args.providerId !== "ollama") return void 0;
|
|
@@ -11019,7 +11032,7 @@ function abortError2(signal) {
|
|
|
11019
11032
|
// src/internal/llm/vertex-anthropic.ts
|
|
11020
11033
|
init_errors();
|
|
11021
11034
|
|
|
11022
|
-
// src/internal/
|
|
11035
|
+
// src/internal/error-mappers/vertex.ts
|
|
11023
11036
|
init_errors();
|
|
11024
11037
|
var VERTEX_RULES = [
|
|
11025
11038
|
{ test: (s, e) => s === 429 || e === "RESOURCE_EXHAUSTED", code: "rate_limit" },
|
|
@@ -11561,6 +11574,16 @@ function resolveMcpCwd(configCwd) {
|
|
|
11561
11574
|
return safePathJoin(process.cwd(), configCwd);
|
|
11562
11575
|
}
|
|
11563
11576
|
|
|
11577
|
+
// src/internal/providers/register-plugin-providers.ts
|
|
11578
|
+
function registerPluginProviderProfiles(entries) {
|
|
11579
|
+
let registered4 = 0;
|
|
11580
|
+
for (const entry of entries) {
|
|
11581
|
+
registerProvider(entry.profile);
|
|
11582
|
+
registered4 += 1;
|
|
11583
|
+
}
|
|
11584
|
+
return registered4;
|
|
11585
|
+
}
|
|
11586
|
+
|
|
11564
11587
|
// src/internal/tool-registry/personality-filter.ts
|
|
11565
11588
|
init_hooks_source();
|
|
11566
11589
|
function applyPersonalityFilter(exposedTools, whitelist, opts) {
|
|
@@ -11637,12 +11660,27 @@ function createRealLocalRun(options) {
|
|
|
11637
11660
|
registerRun(handle);
|
|
11638
11661
|
return handle;
|
|
11639
11662
|
}
|
|
11640
|
-
|
|
11663
|
+
var pluginProvidersAnnounced = false;
|
|
11664
|
+
function resolveRunProvider(options) {
|
|
11641
11665
|
registerBuiltins();
|
|
11666
|
+
const profiles = options.pluginManager?.aggregated.providerProfiles ?? [];
|
|
11667
|
+
const registered4 = registerPluginProviderProfiles(profiles);
|
|
11668
|
+
if (registered4 > 0 && !pluginProvidersAnnounced) {
|
|
11669
|
+
pluginProvidersAnnounced = true;
|
|
11670
|
+
const names = profiles.map((e) => e.profile.name).join(", ");
|
|
11671
|
+
process.stderr.write(
|
|
11672
|
+
`[theokit-sdk] registered ${registered4} plugin provider profile(s): ${names}
|
|
11673
|
+
`
|
|
11674
|
+
);
|
|
11675
|
+
}
|
|
11642
11676
|
const parsedModel = parseModelId(options.model?.id);
|
|
11643
11677
|
const inferredProvider = parsedModel.provider !== void 0 && getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
|
|
11644
11678
|
const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? inferredProvider ?? detectPrimaryProvider();
|
|
11645
11679
|
const effectiveModelId = inferredProvider !== void 0 ? parsedModel.name : options.model?.id ?? "claude-sonnet-4-6";
|
|
11680
|
+
return { primary, effectiveModelId };
|
|
11681
|
+
}
|
|
11682
|
+
function buildLoopInputs(options, runId, userText) {
|
|
11683
|
+
const { primary, effectiveModelId } = resolveRunProvider(options);
|
|
11646
11684
|
const fallback = options.agentOptions.providers?.fallback;
|
|
11647
11685
|
const apiKeys = options.agentOptions.providers?.apiKeys;
|
|
11648
11686
|
const credentialPoolStrategy = options.agentOptions.providers?.credentialPoolStrategy;
|
|
@@ -12260,7 +12298,7 @@ async function embedTexts(input) {
|
|
|
12260
12298
|
pending
|
|
12261
12299
|
});
|
|
12262
12300
|
}
|
|
12263
|
-
await
|
|
12301
|
+
await embedInBoundedBatches(input, pending, results);
|
|
12264
12302
|
return results.map((v) => v ?? new Array(dimension).fill(0));
|
|
12265
12303
|
}
|
|
12266
12304
|
function classifyEntry(args) {
|
|
@@ -12279,45 +12317,34 @@ function classifyEntry(args) {
|
|
|
12279
12317
|
args.pending.push({ index: args.index, text: args.text, key });
|
|
12280
12318
|
}
|
|
12281
12319
|
var MAX_CONCURRENT_BATCHES = 3;
|
|
12282
|
-
async function
|
|
12320
|
+
async function embedInBoundedBatches(input, pending, results) {
|
|
12283
12321
|
const batches = [];
|
|
12284
12322
|
for (let offset = 0; offset < pending.length; offset += MAX_BATCH) {
|
|
12285
12323
|
batches.push(pending.slice(offset, offset + MAX_BATCH));
|
|
12286
12324
|
}
|
|
12287
|
-
|
|
12288
|
-
|
|
12289
|
-
|
|
12290
|
-
|
|
12291
|
-
|
|
12292
|
-
running++;
|
|
12293
|
-
}
|
|
12294
|
-
function release() {
|
|
12295
|
-
running--;
|
|
12296
|
-
if (queue.length > 0) queue.shift()();
|
|
12297
|
-
}
|
|
12325
|
+
await mapWithConcurrency(
|
|
12326
|
+
batches,
|
|
12327
|
+
MAX_CONCURRENT_BATCHES,
|
|
12328
|
+
(batch) => processBatch(input, batch, results)
|
|
12329
|
+
);
|
|
12298
12330
|
}
|
|
12299
|
-
async function processBatch(input, batch, results
|
|
12300
|
-
await
|
|
12301
|
-
|
|
12302
|
-
|
|
12303
|
-
|
|
12304
|
-
|
|
12305
|
-
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
|
|
12313
|
-
|
|
12314
|
-
|
|
12315
|
-
|
|
12316
|
-
results[slot.index] = vector;
|
|
12317
|
-
input.cache.set(slot.key, vector);
|
|
12318
|
-
}
|
|
12319
|
-
} finally {
|
|
12320
|
-
release();
|
|
12331
|
+
async function processBatch(input, batch, results) {
|
|
12332
|
+
const vectors = await embedBatch({
|
|
12333
|
+
apiKey: input.apiKey,
|
|
12334
|
+
baseUrl: input.baseUrl,
|
|
12335
|
+
embeddingsPath: input.embeddingsPath,
|
|
12336
|
+
model: input.model,
|
|
12337
|
+
inputs: batch.map((b) => b.text),
|
|
12338
|
+
fetchImpl: input.fetchImpl,
|
|
12339
|
+
stats: input.stats,
|
|
12340
|
+
providerId: input.providerId
|
|
12341
|
+
});
|
|
12342
|
+
for (let j = 0; j < batch.length; j++) {
|
|
12343
|
+
const slot = batch[j];
|
|
12344
|
+
const vector = vectors[j];
|
|
12345
|
+
if (slot === void 0 || vector === void 0) continue;
|
|
12346
|
+
results[slot.index] = vector;
|
|
12347
|
+
input.cache.set(slot.key, vector);
|
|
12321
12348
|
}
|
|
12322
12349
|
}
|
|
12323
12350
|
async function embedBatch(opts) {
|
|
@@ -12750,7 +12777,7 @@ function sanitizeFts5Query(query) {
|
|
|
12750
12777
|
return text.trim();
|
|
12751
12778
|
}
|
|
12752
12779
|
|
|
12753
|
-
// src/internal/
|
|
12780
|
+
// src/internal/persistence/sqlite-open.ts
|
|
12754
12781
|
init_errors();
|
|
12755
12782
|
|
|
12756
12783
|
// src/internal/persistence/sqlite-wal.ts
|
|
@@ -12778,6 +12805,57 @@ function logFallback(label, reason) {
|
|
|
12778
12805
|
);
|
|
12779
12806
|
}
|
|
12780
12807
|
|
|
12808
|
+
// src/internal/persistence/sqlite-open.ts
|
|
12809
|
+
async function openSqliteResilient(options) {
|
|
12810
|
+
await promises.mkdir(path.dirname(options.filePath), { recursive: true });
|
|
12811
|
+
try {
|
|
12812
|
+
return await openConcrete(options);
|
|
12813
|
+
} catch (cause) {
|
|
12814
|
+
if (options.recoverCorrupt !== false && isCorruptionError(cause)) {
|
|
12815
|
+
await renameAside(options.filePath, options.label ?? "sqlite");
|
|
12816
|
+
return await openConcrete(options);
|
|
12817
|
+
}
|
|
12818
|
+
throw cause;
|
|
12819
|
+
}
|
|
12820
|
+
}
|
|
12821
|
+
async function openConcrete(options) {
|
|
12822
|
+
const db = await loadDriver(options.filePath);
|
|
12823
|
+
applyWalWithFallback(db, options.label ?? "sqlite");
|
|
12824
|
+
await options.onOpen?.(db);
|
|
12825
|
+
return db;
|
|
12826
|
+
}
|
|
12827
|
+
async function loadDriver(filePath) {
|
|
12828
|
+
try {
|
|
12829
|
+
const mod = await import('better-sqlite3');
|
|
12830
|
+
const Ctor = mod.default ?? mod;
|
|
12831
|
+
if (typeof Ctor !== "function") {
|
|
12832
|
+
throw new Error(`better-sqlite3 export is not a constructor (got ${typeof Ctor})`);
|
|
12833
|
+
}
|
|
12834
|
+
return new Ctor(filePath);
|
|
12835
|
+
} catch (cause) {
|
|
12836
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
12837
|
+
throw new ConfigurationError(
|
|
12838
|
+
`Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
|
|
12839
|
+
{ code: "sqlite_driver_unavailable", cause }
|
|
12840
|
+
);
|
|
12841
|
+
}
|
|
12842
|
+
}
|
|
12843
|
+
function isCorruptionError(cause) {
|
|
12844
|
+
if (!(cause instanceof Error)) return false;
|
|
12845
|
+
const msg = cause.message.toLowerCase();
|
|
12846
|
+
return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
|
|
12847
|
+
}
|
|
12848
|
+
async function renameAside(filePath, label) {
|
|
12849
|
+
const asidePath = `${filePath}.corrupt-${Date.now()}`;
|
|
12850
|
+
await promises.rename(filePath, asidePath).catch(() => void 0);
|
|
12851
|
+
await promises.rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
|
|
12852
|
+
await promises.rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
|
|
12853
|
+
process.stderr.write(
|
|
12854
|
+
`[theokit-sdk] ${label} database corrupt; renamed aside to ${asidePath} and rebuilt schema
|
|
12855
|
+
`
|
|
12856
|
+
);
|
|
12857
|
+
}
|
|
12858
|
+
|
|
12781
12859
|
// src/internal/memory/index-schema.ts
|
|
12782
12860
|
var SCHEMA_STATEMENTS = [
|
|
12783
12861
|
`CREATE TABLE IF NOT EXISTS files (
|
|
@@ -12821,52 +12899,15 @@ var PRAGMA_STATEMENTS = [
|
|
|
12821
12899
|
|
|
12822
12900
|
// src/internal/memory/index-db.ts
|
|
12823
12901
|
async function openMemoryDb(opts) {
|
|
12824
|
-
|
|
12825
|
-
|
|
12826
|
-
|
|
12827
|
-
|
|
12828
|
-
|
|
12829
|
-
|
|
12830
|
-
|
|
12902
|
+
return openSqliteResilient({
|
|
12903
|
+
filePath: opts.filePath,
|
|
12904
|
+
label: "memory-index",
|
|
12905
|
+
recoverCorrupt: opts.recoverCorrupt,
|
|
12906
|
+
onOpen: (db) => {
|
|
12907
|
+
for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
|
|
12908
|
+
for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
|
|
12831
12909
|
}
|
|
12832
|
-
|
|
12833
|
-
}
|
|
12834
|
-
}
|
|
12835
|
-
async function openConcrete(filePath) {
|
|
12836
|
-
const db = await loadDriver(filePath);
|
|
12837
|
-
applyWalWithFallback(db, "memory-index");
|
|
12838
|
-
for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
|
|
12839
|
-
for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
|
|
12840
|
-
return db;
|
|
12841
|
-
}
|
|
12842
|
-
async function loadDriver(filePath) {
|
|
12843
|
-
try {
|
|
12844
|
-
const mod = await import('better-sqlite3');
|
|
12845
|
-
const Ctor = mod.default ?? mod;
|
|
12846
|
-
const db = new Ctor(filePath);
|
|
12847
|
-
return db;
|
|
12848
|
-
} catch (cause) {
|
|
12849
|
-
const message = cause instanceof Error ? cause.message : String(cause);
|
|
12850
|
-
throw new ConfigurationError(
|
|
12851
|
-
`Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
|
|
12852
|
-
{ code: "sqlite_driver_unavailable", cause }
|
|
12853
|
-
);
|
|
12854
|
-
}
|
|
12855
|
-
}
|
|
12856
|
-
function isCorruptionError(cause) {
|
|
12857
|
-
if (!(cause instanceof Error)) return false;
|
|
12858
|
-
const msg = cause.message.toLowerCase();
|
|
12859
|
-
return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
|
|
12860
|
-
}
|
|
12861
|
-
async function renameAside(filePath) {
|
|
12862
|
-
const asidePath = `${filePath}.corrupt-${Date.now()}`;
|
|
12863
|
-
await promises.rename(filePath, asidePath).catch(() => void 0);
|
|
12864
|
-
await promises.rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
|
|
12865
|
-
await promises.rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
|
|
12866
|
-
process.stderr.write(
|
|
12867
|
-
`[theokit-sdk] memory index corrupt; renamed aside to ${asidePath} and rebuilt schema
|
|
12868
|
-
`
|
|
12869
|
-
);
|
|
12910
|
+
});
|
|
12870
12911
|
}
|
|
12871
12912
|
function defaultIndexPath(cwd) {
|
|
12872
12913
|
return path.join(cwd, ".theokit", "memory", ".index", "memory.sqlite");
|
|
@@ -14269,8 +14310,8 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
14269
14310
|
async function* wrap() {
|
|
14270
14311
|
const { runUntilImpl: runUntilImpl2 } = await Promise.resolve().then(() => (init_run_until(), run_until_exports));
|
|
14271
14312
|
const { judgeCallImpl: judgeCallImpl2 } = await Promise.resolve().then(() => (init_judge_call(), judge_call_exports));
|
|
14272
|
-
const {
|
|
14273
|
-
const create =
|
|
14313
|
+
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
14314
|
+
const create = getAgentFacade2().create;
|
|
14274
14315
|
const deps = {
|
|
14275
14316
|
judge: async (ctx, opts) => judgeCallImpl2(ctx, opts, { create })
|
|
14276
14317
|
};
|
|
@@ -14280,9 +14321,9 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
14280
14321
|
}
|
|
14281
14322
|
async function localAgentFork(parent, options) {
|
|
14282
14323
|
const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
|
|
14283
|
-
const {
|
|
14324
|
+
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
14284
14325
|
const { withPersonalityContext: withPersonalityContext2 } = await Promise.resolve().then(() => (init_context(), context_exports));
|
|
14285
|
-
const create =
|
|
14326
|
+
const create = getAgentFacade2().create;
|
|
14286
14327
|
return withPersonalityContext2(
|
|
14287
14328
|
{ slug: parent.personalitySlugSnapshot, isFork: true },
|
|
14288
14329
|
() => forkAgentImpl2(parent, options, { create })
|
|
@@ -14303,7 +14344,7 @@ async function persistMemoryFactIfWritePrompt(workspaceCwd, memoryConfig, userTe
|
|
|
14303
14344
|
// src/internal/runtime/local-agent/local-agent-send.ts
|
|
14304
14345
|
init_errors();
|
|
14305
14346
|
|
|
14306
|
-
// src/internal/runtime/abort-utils.ts
|
|
14347
|
+
// src/internal/runtime/concurrency/abort-utils.ts
|
|
14307
14348
|
function anySignal(signals) {
|
|
14308
14349
|
const filtered = signals.filter((s) => s !== void 0);
|
|
14309
14350
|
if (filtered.length === 0) {
|
|
@@ -15332,10 +15373,20 @@ async function getOrCreateUncached(agentId, options) {
|
|
|
15332
15373
|
throw err;
|
|
15333
15374
|
}
|
|
15334
15375
|
}
|
|
15335
|
-
|
|
15376
|
+
setAgentFacade({
|
|
15377
|
+
create: (options) => Agent.create(options),
|
|
15378
|
+
prompt: (message, options) => Agent.prompt(message, options),
|
|
15379
|
+
get: (agentId) => Agent.get(agentId),
|
|
15380
|
+
resume: (agentId, options) => Agent.resume(agentId, options),
|
|
15381
|
+
batch: (prompts, options) => Agent.batch(prompts, options)
|
|
15382
|
+
});
|
|
15383
|
+
|
|
15384
|
+
// src/cron.ts
|
|
15385
|
+
init_errors();
|
|
15336
15386
|
|
|
15337
15387
|
// src/internal/cron/run-job.ts
|
|
15338
15388
|
init_errors();
|
|
15389
|
+
init_agent_factory_registry();
|
|
15339
15390
|
async function runCronJob(job) {
|
|
15340
15391
|
if (job.agent !== void 0) return runWithEphemeralAgent(job.agent, job.message);
|
|
15341
15392
|
if (job.agentId !== void 0) return runWithExistingAgent(job.agentId, job.message);
|
|
@@ -15344,18 +15395,18 @@ async function runCronJob(job) {
|
|
|
15344
15395
|
});
|
|
15345
15396
|
}
|
|
15346
15397
|
async function runWithExistingAgent(agentId, message) {
|
|
15347
|
-
const info = await
|
|
15398
|
+
const info = await getAgentFacade().get(agentId).catch(() => void 0);
|
|
15348
15399
|
if (info === void 0) {
|
|
15349
15400
|
throw new UnknownAgentError(
|
|
15350
15401
|
`Cron job references agentId "${agentId}" but no such agent is registered. The agent may have been disposed or the process restarted without persisting the agent registry.`,
|
|
15351
15402
|
{ code: "agent_not_registered" }
|
|
15352
15403
|
);
|
|
15353
15404
|
}
|
|
15354
|
-
const agent = await
|
|
15405
|
+
const agent = await getAgentFacade().resume(agentId);
|
|
15355
15406
|
return agent.send(message);
|
|
15356
15407
|
}
|
|
15357
15408
|
async function runWithEphemeralAgent(baseOptions, message) {
|
|
15358
|
-
const agent = await
|
|
15409
|
+
const agent = await getAgentFacade().create(baseOptions);
|
|
15359
15410
|
return agent.send(message);
|
|
15360
15411
|
}
|
|
15361
15412
|
|