@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.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { randomUUID,
|
|
2
|
-
import {
|
|
1
|
+
import { randomUUID, randomBytes, createHash } from 'crypto';
|
|
2
|
+
import { readFile, unlink, mkdir, open, rename, statfs, stat, rm, readdir, appendFile, access } from 'fs/promises';
|
|
3
3
|
import { join, dirname, resolve, sep, relative, isAbsolute } from 'path';
|
|
4
4
|
import { z, toJSONSchema } from 'zod';
|
|
5
|
-
import { existsSync, realpathSync, lstatSync, readlinkSync,
|
|
5
|
+
import { mkdirSync, readdirSync, existsSync, realpathSync, lstatSync, readlinkSync, readFileSync } from 'fs';
|
|
6
6
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
7
7
|
import { createRequire } from 'module';
|
|
8
8
|
import { homedir } from 'os';
|
|
@@ -20,6 +20,24 @@ var __export = (target, all) => {
|
|
|
20
20
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
// src/internal/default-retriable.ts
|
|
24
|
+
function defaultRetriableForCode(code) {
|
|
25
|
+
switch (code) {
|
|
26
|
+
case "rate_limit":
|
|
27
|
+
case "timeout":
|
|
28
|
+
case "server_error":
|
|
29
|
+
case "network":
|
|
30
|
+
case "provider_unreachable":
|
|
31
|
+
return true;
|
|
32
|
+
default:
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
var init_default_retriable = __esm({
|
|
37
|
+
"src/internal/default-retriable.ts"() {
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
23
41
|
// src/internal/security/redact.ts
|
|
24
42
|
function readEnvOnce() {
|
|
25
43
|
const raw = process.env.THEOKIT_REDACT_SECRETS;
|
|
@@ -170,7 +188,8 @@ __export(errors_exports, {
|
|
|
170
188
|
UnsupportedBudgetOperationError: () => UnsupportedBudgetOperationError,
|
|
171
189
|
UnsupportedRunOperationError: () => UnsupportedRunOperationError,
|
|
172
190
|
UnsupportedTaskOperationError: () => UnsupportedTaskOperationError,
|
|
173
|
-
coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode
|
|
191
|
+
coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode,
|
|
192
|
+
isTransientError: () => isTransientError
|
|
174
193
|
});
|
|
175
194
|
function coerceToKnownAgentRunErrorCode(code) {
|
|
176
195
|
if (code !== void 0 && KNOWN_AGENT_RUN_ERROR_CODES.has(code)) {
|
|
@@ -202,21 +221,13 @@ function safeStringify(value) {
|
|
|
202
221
|
return String(value);
|
|
203
222
|
}
|
|
204
223
|
}
|
|
205
|
-
function
|
|
206
|
-
|
|
207
|
-
case "rate_limit":
|
|
208
|
-
case "timeout":
|
|
209
|
-
case "server_error":
|
|
210
|
-
case "network":
|
|
211
|
-
case "provider_unreachable":
|
|
212
|
-
return true;
|
|
213
|
-
default:
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
224
|
+
function isTransientError(err) {
|
|
225
|
+
return err instanceof TheokitAgentError && err.isRetryable === true;
|
|
216
226
|
}
|
|
217
227
|
var KNOWN_AGENT_RUN_ERROR_CODES, TheokitAgentError, AuthenticationError, RateLimitError, ConfigurationError, IntegrationNotConnectedError, NetworkError, UnknownAgentError, AgentRunError, UnsupportedRunOperationError, CredentialPoolExhaustedError, MemoryAdapterError, InvalidTaskIdError, TaskNotFoundError, UnsupportedTaskOperationError, BudgetExceededError, AgentDisposedError, UnsupportedBudgetOperationError;
|
|
218
228
|
var init_errors = __esm({
|
|
219
229
|
"src/errors.ts"() {
|
|
230
|
+
init_default_retriable();
|
|
220
231
|
init_redact();
|
|
221
232
|
KNOWN_AGENT_RUN_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
222
233
|
"rate_limit",
|
|
@@ -583,7 +594,7 @@ var init_atomic_write = __esm({
|
|
|
583
594
|
}
|
|
584
595
|
});
|
|
585
596
|
|
|
586
|
-
// src/internal/runtime/yaml-frontmatter.ts
|
|
597
|
+
// src/internal/runtime/context/yaml-frontmatter.ts
|
|
587
598
|
function parseSimpleYaml(text) {
|
|
588
599
|
const fields = {};
|
|
589
600
|
for (const line of text.split(/\r?\n/)) {
|
|
@@ -607,7 +618,7 @@ function coerce(raw) {
|
|
|
607
618
|
return raw;
|
|
608
619
|
}
|
|
609
620
|
var init_yaml_frontmatter = __esm({
|
|
610
|
-
"src/internal/runtime/yaml-frontmatter.ts"() {
|
|
621
|
+
"src/internal/runtime/context/yaml-frontmatter.ts"() {
|
|
611
622
|
}
|
|
612
623
|
});
|
|
613
624
|
async function loadMarkdownEntities(opts) {
|
|
@@ -810,11 +821,54 @@ function checkToolWhitelist(toolName) {
|
|
|
810
821
|
}
|
|
811
822
|
var toolWhitelistStore;
|
|
812
823
|
var init_async_local_storage = __esm({
|
|
813
|
-
"src/internal/runtime/async-local-storage.ts"() {
|
|
824
|
+
"src/internal/runtime/concurrency/async-local-storage.ts"() {
|
|
814
825
|
toolWhitelistStore = new AsyncLocalStorage();
|
|
815
826
|
}
|
|
816
827
|
});
|
|
817
828
|
|
|
829
|
+
// src/internal/runtime/concurrency/async-semaphore.ts
|
|
830
|
+
function createSemaphore(permits) {
|
|
831
|
+
if (!Number.isInteger(permits) || permits < 1) {
|
|
832
|
+
throw new ConfigurationError(
|
|
833
|
+
`async-semaphore: permits must be a positive integer, got ${permits}`,
|
|
834
|
+
{ code: "invalid_concurrency" }
|
|
835
|
+
);
|
|
836
|
+
}
|
|
837
|
+
let active = 0;
|
|
838
|
+
const queue = [];
|
|
839
|
+
function tryGrant() {
|
|
840
|
+
if (active < permits && queue.length > 0) {
|
|
841
|
+
const resolve3 = queue.shift();
|
|
842
|
+
if (resolve3 !== void 0) {
|
|
843
|
+
active += 1;
|
|
844
|
+
resolve3();
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return {
|
|
849
|
+
inFlight: () => active,
|
|
850
|
+
pending: () => queue.length + active,
|
|
851
|
+
async acquire() {
|
|
852
|
+
await new Promise((resolve3) => {
|
|
853
|
+
queue.push(resolve3);
|
|
854
|
+
tryGrant();
|
|
855
|
+
});
|
|
856
|
+
let released = false;
|
|
857
|
+
return () => {
|
|
858
|
+
if (released) return;
|
|
859
|
+
released = true;
|
|
860
|
+
active -= 1;
|
|
861
|
+
tryGrant();
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
var init_async_semaphore = __esm({
|
|
867
|
+
"src/internal/runtime/concurrency/async-semaphore.ts"() {
|
|
868
|
+
init_errors();
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
|
|
818
872
|
// src/internal/llm/credential-pool-types.ts
|
|
819
873
|
var COOLDOWN_MS, DEFAULT_COOLDOWN_MS;
|
|
820
874
|
var init_credential_pool_types = __esm({
|
|
@@ -1159,7 +1213,7 @@ var init_local_agent_plugins = __esm({
|
|
|
1159
1213
|
}
|
|
1160
1214
|
});
|
|
1161
1215
|
|
|
1162
|
-
// src/internal/runtime/run-until.ts
|
|
1216
|
+
// src/internal/runtime/lifecycle/run-until.ts
|
|
1163
1217
|
var run_until_exports = {};
|
|
1164
1218
|
__export(run_until_exports, {
|
|
1165
1219
|
composeContinuation: () => composeContinuation,
|
|
@@ -1252,7 +1306,7 @@ Your last response was:
|
|
|
1252
1306
|
${lastResponse.slice(0, 1e3)}`;
|
|
1253
1307
|
}
|
|
1254
1308
|
var init_run_until = __esm({
|
|
1255
|
-
"src/internal/runtime/run-until.ts"() {
|
|
1309
|
+
"src/internal/runtime/lifecycle/run-until.ts"() {
|
|
1256
1310
|
}
|
|
1257
1311
|
});
|
|
1258
1312
|
|
|
@@ -1363,16 +1417,16 @@ var init_judge_call = __esm({
|
|
|
1363
1417
|
// src/internal/runtime/registry/agent-factory-registry.ts
|
|
1364
1418
|
var agent_factory_registry_exports = {};
|
|
1365
1419
|
__export(agent_factory_registry_exports, {
|
|
1366
|
-
|
|
1367
|
-
|
|
1420
|
+
getAgentFacade: () => getAgentFacade,
|
|
1421
|
+
setAgentFacade: () => setAgentFacade
|
|
1368
1422
|
});
|
|
1369
|
-
function
|
|
1370
|
-
registered3 =
|
|
1423
|
+
function setAgentFacade(facade) {
|
|
1424
|
+
registered3 = facade;
|
|
1371
1425
|
}
|
|
1372
|
-
function
|
|
1426
|
+
function getAgentFacade() {
|
|
1373
1427
|
if (registered3 === void 0) {
|
|
1374
1428
|
throw new Error(
|
|
1375
|
-
"internal: Agent
|
|
1429
|
+
"internal: Agent facade not registered. The `agent.ts` module must be loaded before internal subsystems (LocalAgent.runUntil/fork, eval, scorers, cron) invoke it."
|
|
1376
1430
|
);
|
|
1377
1431
|
}
|
|
1378
1432
|
return registered3;
|
|
@@ -1383,7 +1437,7 @@ var init_agent_factory_registry = __esm({
|
|
|
1383
1437
|
}
|
|
1384
1438
|
});
|
|
1385
1439
|
|
|
1386
|
-
// src/internal/runtime/fork-agent.ts
|
|
1440
|
+
// src/internal/runtime/lifecycle/fork-agent.ts
|
|
1387
1441
|
var fork_agent_exports = {};
|
|
1388
1442
|
__export(fork_agent_exports, {
|
|
1389
1443
|
filterMemoryPlugins: () => filterMemoryPlugins,
|
|
@@ -1443,7 +1497,7 @@ function extractUsage(result) {
|
|
|
1443
1497
|
};
|
|
1444
1498
|
}
|
|
1445
1499
|
var init_fork_agent = __esm({
|
|
1446
|
-
"src/internal/runtime/fork-agent.ts"() {
|
|
1500
|
+
"src/internal/runtime/lifecycle/fork-agent.ts"() {
|
|
1447
1501
|
init_async_local_storage();
|
|
1448
1502
|
init_local_agent_plugins();
|
|
1449
1503
|
}
|
|
@@ -1466,49 +1520,6 @@ var init_task = __esm({
|
|
|
1466
1520
|
}
|
|
1467
1521
|
});
|
|
1468
1522
|
|
|
1469
|
-
// src/internal/runtime/async-semaphore.ts
|
|
1470
|
-
function createSemaphore(permits) {
|
|
1471
|
-
if (!Number.isInteger(permits) || permits < 1) {
|
|
1472
|
-
throw new ConfigurationError(
|
|
1473
|
-
`async-semaphore: permits must be a positive integer, got ${permits}`,
|
|
1474
|
-
{ code: "invalid_concurrency" }
|
|
1475
|
-
);
|
|
1476
|
-
}
|
|
1477
|
-
let active = 0;
|
|
1478
|
-
const queue = [];
|
|
1479
|
-
function tryGrant() {
|
|
1480
|
-
if (active < permits && queue.length > 0) {
|
|
1481
|
-
const resolve3 = queue.shift();
|
|
1482
|
-
if (resolve3 !== void 0) {
|
|
1483
|
-
active += 1;
|
|
1484
|
-
resolve3();
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
return {
|
|
1489
|
-
inFlight: () => active,
|
|
1490
|
-
pending: () => queue.length + active,
|
|
1491
|
-
async acquire() {
|
|
1492
|
-
await new Promise((resolve3) => {
|
|
1493
|
-
queue.push(resolve3);
|
|
1494
|
-
tryGrant();
|
|
1495
|
-
});
|
|
1496
|
-
let released = false;
|
|
1497
|
-
return () => {
|
|
1498
|
-
if (released) return;
|
|
1499
|
-
released = true;
|
|
1500
|
-
active -= 1;
|
|
1501
|
-
tryGrant();
|
|
1502
|
-
};
|
|
1503
|
-
}
|
|
1504
|
-
};
|
|
1505
|
-
}
|
|
1506
|
-
var init_async_semaphore = __esm({
|
|
1507
|
-
"src/internal/runtime/async-semaphore.ts"() {
|
|
1508
|
-
init_errors();
|
|
1509
|
-
}
|
|
1510
|
-
});
|
|
1511
|
-
|
|
1512
1523
|
// src/internal/task/ring-buffer.ts
|
|
1513
1524
|
var RingBuffer;
|
|
1514
1525
|
var init_ring_buffer = __esm({
|
|
@@ -2588,9 +2599,6 @@ var init_batch = __esm({
|
|
|
2588
2599
|
}
|
|
2589
2600
|
});
|
|
2590
2601
|
|
|
2591
|
-
// src/cron.ts
|
|
2592
|
-
init_errors();
|
|
2593
|
-
|
|
2594
2602
|
// src/agent-builder.ts
|
|
2595
2603
|
var AgentBuilder = class {
|
|
2596
2604
|
opts = {};
|
|
@@ -3087,8 +3095,21 @@ function sanitizeIdentifier(input, options) {
|
|
|
3087
3095
|
}
|
|
3088
3096
|
return input.toLowerCase();
|
|
3089
3097
|
}
|
|
3098
|
+
function safeFilenameForId(id, options) {
|
|
3099
|
+
if (id.length === 0) {
|
|
3100
|
+
throw new ConfigurationError("Filename id must be a non-empty string", {
|
|
3101
|
+
code: "invalid_filename_id"
|
|
3102
|
+
});
|
|
3103
|
+
}
|
|
3104
|
+
const maxLen = options?.maxLen;
|
|
3105
|
+
const lower = id.toLowerCase();
|
|
3106
|
+
if (lower.length <= maxLen && IDENTIFIER_PATTERN.test(lower)) {
|
|
3107
|
+
return lower;
|
|
3108
|
+
}
|
|
3109
|
+
return `h-${createHash("sha256").update(id).digest("hex").slice(0, 16)}`;
|
|
3110
|
+
}
|
|
3090
3111
|
|
|
3091
|
-
// src/internal/runtime/default-model.ts
|
|
3112
|
+
// src/internal/runtime/config/default-model.ts
|
|
3092
3113
|
var DEFAULT_AGENTIC_MODEL_ID = "google/gemini-2.0-flash-001";
|
|
3093
3114
|
|
|
3094
3115
|
// src/internal/runtime/registry/agent-registry-store.ts
|
|
@@ -3409,7 +3430,7 @@ async function flushRegistrySaves(cwd) {
|
|
|
3409
3430
|
}
|
|
3410
3431
|
}
|
|
3411
3432
|
|
|
3412
|
-
// src/internal/runtime/system-prompt.ts
|
|
3433
|
+
// src/internal/runtime/system-prompt/system-prompt.ts
|
|
3413
3434
|
async function resolveSystemPrompt(agent, override, ctx) {
|
|
3414
3435
|
if (override !== void 0) return override;
|
|
3415
3436
|
if (agent === void 0) return void 0;
|
|
@@ -5792,28 +5813,6 @@ function parseDecisionFromStdout(stdout) {
|
|
|
5792
5813
|
return { decision: "allow" };
|
|
5793
5814
|
}
|
|
5794
5815
|
|
|
5795
|
-
// src/internal/runtime/memory/memory-path-selector.ts
|
|
5796
|
-
var PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
|
|
5797
|
-
function shouldUsePortMemoryPath() {
|
|
5798
|
-
const env = globalThis.process?.env;
|
|
5799
|
-
if (env === void 0) return false;
|
|
5800
|
-
const val = env[PORT_MEMORY_PATH_ENV_VAR];
|
|
5801
|
-
return val === "1" || val === "true";
|
|
5802
|
-
}
|
|
5803
|
-
function resolveMemoryProviderForLoop(consumerSupplied, defaultAdapter, portPathEnabled) {
|
|
5804
|
-
if (consumerSupplied !== void 0) return consumerSupplied;
|
|
5805
|
-
if (portPathEnabled) return defaultAdapter;
|
|
5806
|
-
return void 0;
|
|
5807
|
-
}
|
|
5808
|
-
function resolveMemoryToolsForLoop(legacyTools, portPathEnabled) {
|
|
5809
|
-
if (portPathEnabled) return void 0;
|
|
5810
|
-
return legacyTools;
|
|
5811
|
-
}
|
|
5812
|
-
function resolveActiveMemorySummaryForSend(legacySummary, portPathEnabled) {
|
|
5813
|
-
if (portPathEnabled) return void 0;
|
|
5814
|
-
return legacySummary;
|
|
5815
|
-
}
|
|
5816
|
-
|
|
5817
5816
|
// src/internal/memory/storage/session-summary-writer.ts
|
|
5818
5817
|
init_atomic_write();
|
|
5819
5818
|
var MAX_TURN_CHARS = 2e3;
|
|
@@ -5821,10 +5820,7 @@ function sessionsDir(cwd) {
|
|
|
5821
5820
|
return join(memoryDir(cwd), "sessions");
|
|
5822
5821
|
}
|
|
5823
5822
|
function sessionSummaryPath(cwd, runId) {
|
|
5824
|
-
return join(sessionsDir(cwd), `${
|
|
5825
|
-
}
|
|
5826
|
-
function sanitizeRunId(runId) {
|
|
5827
|
-
return runId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 128);
|
|
5823
|
+
return join(sessionsDir(cwd), `${safeFilenameForId(runId, { maxLen: 128 })}.md`);
|
|
5828
5824
|
}
|
|
5829
5825
|
function truncate(text) {
|
|
5830
5826
|
if (text.length <= MAX_TURN_CHARS) return text;
|
|
@@ -5857,6 +5853,28 @@ async function writeSessionSummary(input) {
|
|
|
5857
5853
|
await replaceFileAtomic(path, body);
|
|
5858
5854
|
}
|
|
5859
5855
|
|
|
5856
|
+
// src/internal/runtime/memory/memory-path-selector.ts
|
|
5857
|
+
var PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
|
|
5858
|
+
function shouldUsePortMemoryPath() {
|
|
5859
|
+
const env = globalThis.process?.env;
|
|
5860
|
+
if (env === void 0) return false;
|
|
5861
|
+
const val = env[PORT_MEMORY_PATH_ENV_VAR];
|
|
5862
|
+
return val === "1" || val === "true";
|
|
5863
|
+
}
|
|
5864
|
+
function resolveMemoryProviderForLoop(consumerSupplied, defaultAdapter, portPathEnabled) {
|
|
5865
|
+
if (consumerSupplied !== void 0) return consumerSupplied;
|
|
5866
|
+
if (portPathEnabled) return defaultAdapter;
|
|
5867
|
+
return void 0;
|
|
5868
|
+
}
|
|
5869
|
+
function resolveMemoryToolsForLoop(legacyTools, portPathEnabled) {
|
|
5870
|
+
if (portPathEnabled) return void 0;
|
|
5871
|
+
return legacyTools;
|
|
5872
|
+
}
|
|
5873
|
+
function resolveActiveMemorySummaryForSend(legacySummary, portPathEnabled) {
|
|
5874
|
+
if (portPathEnabled) return void 0;
|
|
5875
|
+
return legacySummary;
|
|
5876
|
+
}
|
|
5877
|
+
|
|
5860
5878
|
// src/internal/runtime/session/agent-session-store.ts
|
|
5861
5879
|
init_atomic_write();
|
|
5862
5880
|
var VALID_ROLES = /* @__PURE__ */ new Set([
|
|
@@ -6113,7 +6131,7 @@ function clearSession(agentId) {
|
|
|
6113
6131
|
sessions.delete(agentId);
|
|
6114
6132
|
}
|
|
6115
6133
|
|
|
6116
|
-
// src/internal/runtime/post-run-lifecycle.ts
|
|
6134
|
+
// src/internal/runtime/lifecycle/post-run-lifecycle.ts
|
|
6117
6135
|
async function runPostRunLifecycle(inputs) {
|
|
6118
6136
|
const {
|
|
6119
6137
|
run,
|
|
@@ -6345,7 +6363,7 @@ var liveAgentRegistry = new LiveAgentRegistry();
|
|
|
6345
6363
|
// src/internal/runtime/skills/subagents-loader.ts
|
|
6346
6364
|
init_errors();
|
|
6347
6365
|
|
|
6348
|
-
// src/internal/runtime/workspace-dir.ts
|
|
6366
|
+
// src/internal/runtime/config/workspace-dir.ts
|
|
6349
6367
|
init_errors();
|
|
6350
6368
|
async function readWorkspaceDir(root, errorCode, describe) {
|
|
6351
6369
|
try {
|
|
@@ -6631,7 +6649,7 @@ var SystemPromptPipeline = class _SystemPromptPipeline {
|
|
|
6631
6649
|
}
|
|
6632
6650
|
};
|
|
6633
6651
|
|
|
6634
|
-
// src/internal/runtime/validate-agent-options.ts
|
|
6652
|
+
// src/internal/runtime/validation/validate-agent-options.ts
|
|
6635
6653
|
init_errors();
|
|
6636
6654
|
function validateAgentOptions(options) {
|
|
6637
6655
|
rejectProgrammaticHooks(options);
|
|
@@ -6826,6 +6844,71 @@ function validateMemory(options) {
|
|
|
6826
6844
|
}
|
|
6827
6845
|
}
|
|
6828
6846
|
|
|
6847
|
+
// src/internal/runtime/config/providers-manager.ts
|
|
6848
|
+
var ProvidersManagerImpl = class {
|
|
6849
|
+
constructor(model, providers, plugins) {
|
|
6850
|
+
this.model = model;
|
|
6851
|
+
this.providers = providers;
|
|
6852
|
+
this.plugins = plugins;
|
|
6853
|
+
}
|
|
6854
|
+
model;
|
|
6855
|
+
providers;
|
|
6856
|
+
plugins;
|
|
6857
|
+
routes() {
|
|
6858
|
+
const resolved = [];
|
|
6859
|
+
const modelProvider = providerFromModel(this.model);
|
|
6860
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6861
|
+
if (this.providers?.routes !== void 0) {
|
|
6862
|
+
for (const route of this.providers.routes) {
|
|
6863
|
+
const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
|
|
6864
|
+
if (!seen.has(route.capability)) {
|
|
6865
|
+
seen.add(route.capability);
|
|
6866
|
+
resolved.push(resolvedRoute);
|
|
6867
|
+
}
|
|
6868
|
+
}
|
|
6869
|
+
}
|
|
6870
|
+
return Promise.resolve(resolved);
|
|
6871
|
+
}
|
|
6872
|
+
};
|
|
6873
|
+
function providerFromModel(model) {
|
|
6874
|
+
if (model === void 0) return void 0;
|
|
6875
|
+
const id = model.id;
|
|
6876
|
+
if (id.includes(":")) return id.split(":")[0];
|
|
6877
|
+
return void 0;
|
|
6878
|
+
}
|
|
6879
|
+
function resolveRoute(route, modelProvider, plugins) {
|
|
6880
|
+
if (route.capability === "chat" && modelProvider === route.provider) {
|
|
6881
|
+
const modelName = extractModelName(modelProvider, route);
|
|
6882
|
+
const base = {
|
|
6883
|
+
capability: route.capability,
|
|
6884
|
+
provider: route.provider,
|
|
6885
|
+
reason: "explicit-model-provider"
|
|
6886
|
+
};
|
|
6887
|
+
if (modelName !== void 0) base.model = modelName;
|
|
6888
|
+
return base;
|
|
6889
|
+
}
|
|
6890
|
+
if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
|
|
6891
|
+
return {
|
|
6892
|
+
capability: route.capability,
|
|
6893
|
+
provider: route.provider,
|
|
6894
|
+
reason: "first-available-plugin-provider"
|
|
6895
|
+
};
|
|
6896
|
+
}
|
|
6897
|
+
return {
|
|
6898
|
+
capability: route.capability,
|
|
6899
|
+
provider: route.provider,
|
|
6900
|
+
reason: "explicit-route"
|
|
6901
|
+
};
|
|
6902
|
+
}
|
|
6903
|
+
function extractModelName(prefix, route) {
|
|
6904
|
+
if (route.model !== void 0) return route.model;
|
|
6905
|
+
return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
|
|
6906
|
+
}
|
|
6907
|
+
function defaultModelForProvider(provider) {
|
|
6908
|
+
if (provider === "anthropic") return "claude-3-7-sonnet";
|
|
6909
|
+
return void 0;
|
|
6910
|
+
}
|
|
6911
|
+
|
|
6829
6912
|
// src/internal/runtime/context/context-manager.ts
|
|
6830
6913
|
init_errors();
|
|
6831
6914
|
init_markdown_config_loader();
|
|
@@ -7622,71 +7705,6 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
|
|
|
7622
7705
|
return metadata;
|
|
7623
7706
|
}
|
|
7624
7707
|
|
|
7625
|
-
// src/internal/runtime/providers-manager.ts
|
|
7626
|
-
var ProvidersManagerImpl = class {
|
|
7627
|
-
constructor(model, providers, plugins) {
|
|
7628
|
-
this.model = model;
|
|
7629
|
-
this.providers = providers;
|
|
7630
|
-
this.plugins = plugins;
|
|
7631
|
-
}
|
|
7632
|
-
model;
|
|
7633
|
-
providers;
|
|
7634
|
-
plugins;
|
|
7635
|
-
routes() {
|
|
7636
|
-
const resolved = [];
|
|
7637
|
-
const modelProvider = providerFromModel(this.model);
|
|
7638
|
-
const seen = /* @__PURE__ */ new Set();
|
|
7639
|
-
if (this.providers?.routes !== void 0) {
|
|
7640
|
-
for (const route of this.providers.routes) {
|
|
7641
|
-
const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
|
|
7642
|
-
if (!seen.has(route.capability)) {
|
|
7643
|
-
seen.add(route.capability);
|
|
7644
|
-
resolved.push(resolvedRoute);
|
|
7645
|
-
}
|
|
7646
|
-
}
|
|
7647
|
-
}
|
|
7648
|
-
return Promise.resolve(resolved);
|
|
7649
|
-
}
|
|
7650
|
-
};
|
|
7651
|
-
function providerFromModel(model) {
|
|
7652
|
-
if (model === void 0) return void 0;
|
|
7653
|
-
const id = model.id;
|
|
7654
|
-
if (id.includes(":")) return id.split(":")[0];
|
|
7655
|
-
return void 0;
|
|
7656
|
-
}
|
|
7657
|
-
function resolveRoute(route, modelProvider, plugins) {
|
|
7658
|
-
if (route.capability === "chat" && modelProvider === route.provider) {
|
|
7659
|
-
const modelName = extractModelName(modelProvider, route);
|
|
7660
|
-
const base = {
|
|
7661
|
-
capability: route.capability,
|
|
7662
|
-
provider: route.provider,
|
|
7663
|
-
reason: "explicit-model-provider"
|
|
7664
|
-
};
|
|
7665
|
-
if (modelName !== void 0) base.model = modelName;
|
|
7666
|
-
return base;
|
|
7667
|
-
}
|
|
7668
|
-
if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
|
|
7669
|
-
return {
|
|
7670
|
-
capability: route.capability,
|
|
7671
|
-
provider: route.provider,
|
|
7672
|
-
reason: "first-available-plugin-provider"
|
|
7673
|
-
};
|
|
7674
|
-
}
|
|
7675
|
-
return {
|
|
7676
|
-
capability: route.capability,
|
|
7677
|
-
provider: route.provider,
|
|
7678
|
-
reason: "explicit-route"
|
|
7679
|
-
};
|
|
7680
|
-
}
|
|
7681
|
-
function extractModelName(prefix, route) {
|
|
7682
|
-
if (route.model !== void 0) return route.model;
|
|
7683
|
-
return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
|
|
7684
|
-
}
|
|
7685
|
-
function defaultModelForProvider(provider) {
|
|
7686
|
-
if (provider === "anthropic") return "claude-3-7-sonnet";
|
|
7687
|
-
return void 0;
|
|
7688
|
-
}
|
|
7689
|
-
|
|
7690
7708
|
// src/internal/runtime/skills/skills-manager.ts
|
|
7691
7709
|
init_errors();
|
|
7692
7710
|
|
|
@@ -8033,7 +8051,7 @@ var IterationBudget = class {
|
|
|
8033
8051
|
}
|
|
8034
8052
|
};
|
|
8035
8053
|
|
|
8036
|
-
// src/internal/runtime/validate-response.ts
|
|
8054
|
+
// src/internal/runtime/validation/validate-response.ts
|
|
8037
8055
|
function validateResponse(response) {
|
|
8038
8056
|
const trimmed = response.content.trim();
|
|
8039
8057
|
const toolCallsArr = Array.isArray(response.toolCalls) ? response.toolCalls : [];
|
|
@@ -8419,6 +8437,27 @@ async function emitTextDeltaCallback(inputs, text) {
|
|
|
8419
8437
|
// src/internal/agent-loop/tool-dispatch.ts
|
|
8420
8438
|
init_async_local_storage();
|
|
8421
8439
|
|
|
8440
|
+
// src/internal/runtime/concurrency/map-with-concurrency.ts
|
|
8441
|
+
init_async_semaphore();
|
|
8442
|
+
var NEVER_ABORT = new AbortController().signal;
|
|
8443
|
+
async function mapWithConcurrency(items, concurrency, fn, options) {
|
|
8444
|
+
const semaphore = createSemaphore(concurrency);
|
|
8445
|
+
const signal = NEVER_ABORT;
|
|
8446
|
+
return Promise.all(
|
|
8447
|
+
items.map(async (item, index) => {
|
|
8448
|
+
const release = await semaphore.acquire();
|
|
8449
|
+
try {
|
|
8450
|
+
if (signal.aborted) {
|
|
8451
|
+
throw signal.reason instanceof Error ? signal.reason : new Error("mapWithConcurrency: aborted");
|
|
8452
|
+
}
|
|
8453
|
+
return await fn(item, index, signal);
|
|
8454
|
+
} finally {
|
|
8455
|
+
release();
|
|
8456
|
+
}
|
|
8457
|
+
})
|
|
8458
|
+
);
|
|
8459
|
+
}
|
|
8460
|
+
|
|
8422
8461
|
// src/internal/tool-dispatch/repair-middleware.ts
|
|
8423
8462
|
var DECIMAL_RE = /^-?\d+(\.\d+)?$/;
|
|
8424
8463
|
function repairToolCall(raw, registry) {
|
|
@@ -8492,7 +8531,7 @@ function coerceArgsToSchema(args, schema) {
|
|
|
8492
8531
|
return { value: out, changed };
|
|
8493
8532
|
}
|
|
8494
8533
|
|
|
8495
|
-
// src/internal/runtime/shell-tool.ts
|
|
8534
|
+
// src/internal/runtime/tools/shell-tool.ts
|
|
8496
8535
|
async function runShell(options) {
|
|
8497
8536
|
if (options.sandbox === true && isObviouslyUnsafe(options.command)) {
|
|
8498
8537
|
return {
|
|
@@ -8593,38 +8632,12 @@ ${result.stderr}`.trim();
|
|
|
8593
8632
|
// src/internal/agent-loop/tool-dispatch.ts
|
|
8594
8633
|
async function dispatchTools(inputs, tools, toolCalls, events) {
|
|
8595
8634
|
const maxConcurrent = inputs.maxConcurrentTools ?? 4;
|
|
8596
|
-
return
|
|
8597
|
-
maxConcurrent,
|
|
8635
|
+
return mapWithConcurrency(
|
|
8598
8636
|
toolCalls,
|
|
8637
|
+
maxConcurrent,
|
|
8599
8638
|
(call) => dispatchSingleCall(inputs, tools, call, events)
|
|
8600
8639
|
);
|
|
8601
8640
|
}
|
|
8602
|
-
async function boundedParallel(max, items, fn) {
|
|
8603
|
-
let running = 0;
|
|
8604
|
-
const queue = [];
|
|
8605
|
-
async function acquire() {
|
|
8606
|
-
if (running < max) {
|
|
8607
|
-
running++;
|
|
8608
|
-
return;
|
|
8609
|
-
}
|
|
8610
|
-
await new Promise((resolve3) => queue.push(resolve3));
|
|
8611
|
-
running++;
|
|
8612
|
-
}
|
|
8613
|
-
function release() {
|
|
8614
|
-
running--;
|
|
8615
|
-
if (queue.length > 0) queue.shift()();
|
|
8616
|
-
}
|
|
8617
|
-
return Promise.all(
|
|
8618
|
-
items.map(async (item) => {
|
|
8619
|
-
await acquire();
|
|
8620
|
-
try {
|
|
8621
|
-
return await fn(item);
|
|
8622
|
-
} finally {
|
|
8623
|
-
release();
|
|
8624
|
-
}
|
|
8625
|
-
})
|
|
8626
|
-
);
|
|
8627
|
-
}
|
|
8628
8641
|
async function dispatchSingleCall(inputs, tools, call, events) {
|
|
8629
8642
|
const { call: workingCall, repairs } = applyRepairAndExtractCall(tools, call);
|
|
8630
8643
|
const callId = generateCallId();
|
|
@@ -9693,10 +9706,10 @@ function registerBuiltins() {
|
|
|
9693
9706
|
registerCatalogProviders();
|
|
9694
9707
|
}
|
|
9695
9708
|
|
|
9696
|
-
// src/internal/
|
|
9709
|
+
// src/internal/error-mappers/anthropic.ts
|
|
9697
9710
|
init_errors();
|
|
9698
9711
|
|
|
9699
|
-
// src/internal/
|
|
9712
|
+
// src/internal/error-mappers/shared.ts
|
|
9700
9713
|
var RAW_MAX_BYTES = 2048;
|
|
9701
9714
|
function parseRetryAfter(headers) {
|
|
9702
9715
|
if (headers === void 0) return void 0;
|
|
@@ -9725,7 +9738,7 @@ function buildErrorMetadata(args) {
|
|
|
9725
9738
|
};
|
|
9726
9739
|
}
|
|
9727
9740
|
|
|
9728
|
-
// src/internal/
|
|
9741
|
+
// src/internal/error-mappers/anthropic.ts
|
|
9729
9742
|
function mapAnthropicError(args) {
|
|
9730
9743
|
const { status, body, headers, endpoint } = args;
|
|
9731
9744
|
const code = mapAnthropicStatusToCode(status, body);
|
|
@@ -10065,7 +10078,7 @@ function buildAnthropicBody(request) {
|
|
|
10065
10078
|
// src/internal/llm/bedrock-anthropic.ts
|
|
10066
10079
|
init_errors();
|
|
10067
10080
|
|
|
10068
|
-
// src/internal/
|
|
10081
|
+
// src/internal/error-mappers/bedrock.ts
|
|
10069
10082
|
init_errors();
|
|
10070
10083
|
function classifyBedrockError(args, awsType, message) {
|
|
10071
10084
|
if (args.status === 429 || awsType.includes("Throttling") || awsType.includes("TooManyRequests")) {
|
|
@@ -10202,7 +10215,7 @@ function buildBedrockBody(request) {
|
|
|
10202
10215
|
init_credential_pool();
|
|
10203
10216
|
init_credential_pool_context();
|
|
10204
10217
|
|
|
10205
|
-
// src/internal/
|
|
10218
|
+
// src/internal/error-mappers/openai-compatible.ts
|
|
10206
10219
|
init_errors();
|
|
10207
10220
|
function mapOpenAICompatibleError(args) {
|
|
10208
10221
|
const { providerId, status, body, headers, endpoint } = args;
|
|
@@ -10366,7 +10379,7 @@ function readOpenAiContent(body) {
|
|
|
10366
10379
|
return void 0;
|
|
10367
10380
|
}
|
|
10368
10381
|
|
|
10369
|
-
// src/internal/
|
|
10382
|
+
// src/internal/error-mappers/ollama.ts
|
|
10370
10383
|
init_errors();
|
|
10371
10384
|
function mapOllamaTransportError(args) {
|
|
10372
10385
|
if (args.providerId !== "ollama") return void 0;
|
|
@@ -11016,7 +11029,7 @@ function abortError2(signal) {
|
|
|
11016
11029
|
// src/internal/llm/vertex-anthropic.ts
|
|
11017
11030
|
init_errors();
|
|
11018
11031
|
|
|
11019
|
-
// src/internal/
|
|
11032
|
+
// src/internal/error-mappers/vertex.ts
|
|
11020
11033
|
init_errors();
|
|
11021
11034
|
var VERTEX_RULES = [
|
|
11022
11035
|
{ test: (s, e) => s === 429 || e === "RESOURCE_EXHAUSTED", code: "rate_limit" },
|
|
@@ -11558,6 +11571,16 @@ function resolveMcpCwd(configCwd) {
|
|
|
11558
11571
|
return safePathJoin(process.cwd(), configCwd);
|
|
11559
11572
|
}
|
|
11560
11573
|
|
|
11574
|
+
// src/internal/providers/register-plugin-providers.ts
|
|
11575
|
+
function registerPluginProviderProfiles(entries) {
|
|
11576
|
+
let registered4 = 0;
|
|
11577
|
+
for (const entry of entries) {
|
|
11578
|
+
registerProvider(entry.profile);
|
|
11579
|
+
registered4 += 1;
|
|
11580
|
+
}
|
|
11581
|
+
return registered4;
|
|
11582
|
+
}
|
|
11583
|
+
|
|
11561
11584
|
// src/internal/tool-registry/personality-filter.ts
|
|
11562
11585
|
init_hooks_source();
|
|
11563
11586
|
function applyPersonalityFilter(exposedTools, whitelist, opts) {
|
|
@@ -11634,12 +11657,27 @@ function createRealLocalRun(options) {
|
|
|
11634
11657
|
registerRun(handle);
|
|
11635
11658
|
return handle;
|
|
11636
11659
|
}
|
|
11637
|
-
|
|
11660
|
+
var pluginProvidersAnnounced = false;
|
|
11661
|
+
function resolveRunProvider(options) {
|
|
11638
11662
|
registerBuiltins();
|
|
11663
|
+
const profiles = options.pluginManager?.aggregated.providerProfiles ?? [];
|
|
11664
|
+
const registered4 = registerPluginProviderProfiles(profiles);
|
|
11665
|
+
if (registered4 > 0 && !pluginProvidersAnnounced) {
|
|
11666
|
+
pluginProvidersAnnounced = true;
|
|
11667
|
+
const names = profiles.map((e) => e.profile.name).join(", ");
|
|
11668
|
+
process.stderr.write(
|
|
11669
|
+
`[theokit-sdk] registered ${registered4} plugin provider profile(s): ${names}
|
|
11670
|
+
`
|
|
11671
|
+
);
|
|
11672
|
+
}
|
|
11639
11673
|
const parsedModel = parseModelId(options.model?.id);
|
|
11640
11674
|
const inferredProvider = parsedModel.provider !== void 0 && getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
|
|
11641
11675
|
const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? inferredProvider ?? detectPrimaryProvider();
|
|
11642
11676
|
const effectiveModelId = inferredProvider !== void 0 ? parsedModel.name : options.model?.id ?? "claude-sonnet-4-6";
|
|
11677
|
+
return { primary, effectiveModelId };
|
|
11678
|
+
}
|
|
11679
|
+
function buildLoopInputs(options, runId, userText) {
|
|
11680
|
+
const { primary, effectiveModelId } = resolveRunProvider(options);
|
|
11643
11681
|
const fallback = options.agentOptions.providers?.fallback;
|
|
11644
11682
|
const apiKeys = options.agentOptions.providers?.apiKeys;
|
|
11645
11683
|
const credentialPoolStrategy = options.agentOptions.providers?.credentialPoolStrategy;
|
|
@@ -12257,7 +12295,7 @@ async function embedTexts(input) {
|
|
|
12257
12295
|
pending
|
|
12258
12296
|
});
|
|
12259
12297
|
}
|
|
12260
|
-
await
|
|
12298
|
+
await embedInBoundedBatches(input, pending, results);
|
|
12261
12299
|
return results.map((v) => v ?? new Array(dimension).fill(0));
|
|
12262
12300
|
}
|
|
12263
12301
|
function classifyEntry(args) {
|
|
@@ -12276,45 +12314,34 @@ function classifyEntry(args) {
|
|
|
12276
12314
|
args.pending.push({ index: args.index, text: args.text, key });
|
|
12277
12315
|
}
|
|
12278
12316
|
var MAX_CONCURRENT_BATCHES = 3;
|
|
12279
|
-
async function
|
|
12317
|
+
async function embedInBoundedBatches(input, pending, results) {
|
|
12280
12318
|
const batches = [];
|
|
12281
12319
|
for (let offset = 0; offset < pending.length; offset += MAX_BATCH) {
|
|
12282
12320
|
batches.push(pending.slice(offset, offset + MAX_BATCH));
|
|
12283
12321
|
}
|
|
12284
|
-
|
|
12285
|
-
|
|
12286
|
-
|
|
12287
|
-
|
|
12288
|
-
|
|
12289
|
-
running++;
|
|
12290
|
-
}
|
|
12291
|
-
function release() {
|
|
12292
|
-
running--;
|
|
12293
|
-
if (queue.length > 0) queue.shift()();
|
|
12294
|
-
}
|
|
12322
|
+
await mapWithConcurrency(
|
|
12323
|
+
batches,
|
|
12324
|
+
MAX_CONCURRENT_BATCHES,
|
|
12325
|
+
(batch) => processBatch(input, batch, results)
|
|
12326
|
+
);
|
|
12295
12327
|
}
|
|
12296
|
-
async function processBatch(input, batch, results
|
|
12297
|
-
await
|
|
12298
|
-
|
|
12299
|
-
|
|
12300
|
-
|
|
12301
|
-
|
|
12302
|
-
|
|
12303
|
-
|
|
12304
|
-
|
|
12305
|
-
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
|
|
12313
|
-
results[slot.index] = vector;
|
|
12314
|
-
input.cache.set(slot.key, vector);
|
|
12315
|
-
}
|
|
12316
|
-
} finally {
|
|
12317
|
-
release();
|
|
12328
|
+
async function processBatch(input, batch, results) {
|
|
12329
|
+
const vectors = await embedBatch({
|
|
12330
|
+
apiKey: input.apiKey,
|
|
12331
|
+
baseUrl: input.baseUrl,
|
|
12332
|
+
embeddingsPath: input.embeddingsPath,
|
|
12333
|
+
model: input.model,
|
|
12334
|
+
inputs: batch.map((b) => b.text),
|
|
12335
|
+
fetchImpl: input.fetchImpl,
|
|
12336
|
+
stats: input.stats,
|
|
12337
|
+
providerId: input.providerId
|
|
12338
|
+
});
|
|
12339
|
+
for (let j = 0; j < batch.length; j++) {
|
|
12340
|
+
const slot = batch[j];
|
|
12341
|
+
const vector = vectors[j];
|
|
12342
|
+
if (slot === void 0 || vector === void 0) continue;
|
|
12343
|
+
results[slot.index] = vector;
|
|
12344
|
+
input.cache.set(slot.key, vector);
|
|
12318
12345
|
}
|
|
12319
12346
|
}
|
|
12320
12347
|
async function embedBatch(opts) {
|
|
@@ -12747,7 +12774,7 @@ function sanitizeFts5Query(query) {
|
|
|
12747
12774
|
return text.trim();
|
|
12748
12775
|
}
|
|
12749
12776
|
|
|
12750
|
-
// src/internal/
|
|
12777
|
+
// src/internal/persistence/sqlite-open.ts
|
|
12751
12778
|
init_errors();
|
|
12752
12779
|
|
|
12753
12780
|
// src/internal/persistence/sqlite-wal.ts
|
|
@@ -12775,6 +12802,57 @@ function logFallback(label, reason) {
|
|
|
12775
12802
|
);
|
|
12776
12803
|
}
|
|
12777
12804
|
|
|
12805
|
+
// src/internal/persistence/sqlite-open.ts
|
|
12806
|
+
async function openSqliteResilient(options) {
|
|
12807
|
+
await mkdir(dirname(options.filePath), { recursive: true });
|
|
12808
|
+
try {
|
|
12809
|
+
return await openConcrete(options);
|
|
12810
|
+
} catch (cause) {
|
|
12811
|
+
if (options.recoverCorrupt !== false && isCorruptionError(cause)) {
|
|
12812
|
+
await renameAside(options.filePath, options.label ?? "sqlite");
|
|
12813
|
+
return await openConcrete(options);
|
|
12814
|
+
}
|
|
12815
|
+
throw cause;
|
|
12816
|
+
}
|
|
12817
|
+
}
|
|
12818
|
+
async function openConcrete(options) {
|
|
12819
|
+
const db = await loadDriver(options.filePath);
|
|
12820
|
+
applyWalWithFallback(db, options.label ?? "sqlite");
|
|
12821
|
+
await options.onOpen?.(db);
|
|
12822
|
+
return db;
|
|
12823
|
+
}
|
|
12824
|
+
async function loadDriver(filePath) {
|
|
12825
|
+
try {
|
|
12826
|
+
const mod = await import('better-sqlite3');
|
|
12827
|
+
const Ctor = mod.default ?? mod;
|
|
12828
|
+
if (typeof Ctor !== "function") {
|
|
12829
|
+
throw new Error(`better-sqlite3 export is not a constructor (got ${typeof Ctor})`);
|
|
12830
|
+
}
|
|
12831
|
+
return new Ctor(filePath);
|
|
12832
|
+
} catch (cause) {
|
|
12833
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
12834
|
+
throw new ConfigurationError(
|
|
12835
|
+
`Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
|
|
12836
|
+
{ code: "sqlite_driver_unavailable", cause }
|
|
12837
|
+
);
|
|
12838
|
+
}
|
|
12839
|
+
}
|
|
12840
|
+
function isCorruptionError(cause) {
|
|
12841
|
+
if (!(cause instanceof Error)) return false;
|
|
12842
|
+
const msg = cause.message.toLowerCase();
|
|
12843
|
+
return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
|
|
12844
|
+
}
|
|
12845
|
+
async function renameAside(filePath, label) {
|
|
12846
|
+
const asidePath = `${filePath}.corrupt-${Date.now()}`;
|
|
12847
|
+
await rename(filePath, asidePath).catch(() => void 0);
|
|
12848
|
+
await rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
|
|
12849
|
+
await rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
|
|
12850
|
+
process.stderr.write(
|
|
12851
|
+
`[theokit-sdk] ${label} database corrupt; renamed aside to ${asidePath} and rebuilt schema
|
|
12852
|
+
`
|
|
12853
|
+
);
|
|
12854
|
+
}
|
|
12855
|
+
|
|
12778
12856
|
// src/internal/memory/index-schema.ts
|
|
12779
12857
|
var SCHEMA_STATEMENTS = [
|
|
12780
12858
|
`CREATE TABLE IF NOT EXISTS files (
|
|
@@ -12818,52 +12896,15 @@ var PRAGMA_STATEMENTS = [
|
|
|
12818
12896
|
|
|
12819
12897
|
// src/internal/memory/index-db.ts
|
|
12820
12898
|
async function openMemoryDb(opts) {
|
|
12821
|
-
|
|
12822
|
-
|
|
12823
|
-
|
|
12824
|
-
|
|
12825
|
-
|
|
12826
|
-
|
|
12827
|
-
|
|
12899
|
+
return openSqliteResilient({
|
|
12900
|
+
filePath: opts.filePath,
|
|
12901
|
+
label: "memory-index",
|
|
12902
|
+
recoverCorrupt: opts.recoverCorrupt,
|
|
12903
|
+
onOpen: (db) => {
|
|
12904
|
+
for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
|
|
12905
|
+
for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
|
|
12828
12906
|
}
|
|
12829
|
-
|
|
12830
|
-
}
|
|
12831
|
-
}
|
|
12832
|
-
async function openConcrete(filePath) {
|
|
12833
|
-
const db = await loadDriver(filePath);
|
|
12834
|
-
applyWalWithFallback(db, "memory-index");
|
|
12835
|
-
for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
|
|
12836
|
-
for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
|
|
12837
|
-
return db;
|
|
12838
|
-
}
|
|
12839
|
-
async function loadDriver(filePath) {
|
|
12840
|
-
try {
|
|
12841
|
-
const mod = await import('better-sqlite3');
|
|
12842
|
-
const Ctor = mod.default ?? mod;
|
|
12843
|
-
const db = new Ctor(filePath);
|
|
12844
|
-
return db;
|
|
12845
|
-
} catch (cause) {
|
|
12846
|
-
const message = cause instanceof Error ? cause.message : String(cause);
|
|
12847
|
-
throw new ConfigurationError(
|
|
12848
|
-
`Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
|
|
12849
|
-
{ code: "sqlite_driver_unavailable", cause }
|
|
12850
|
-
);
|
|
12851
|
-
}
|
|
12852
|
-
}
|
|
12853
|
-
function isCorruptionError(cause) {
|
|
12854
|
-
if (!(cause instanceof Error)) return false;
|
|
12855
|
-
const msg = cause.message.toLowerCase();
|
|
12856
|
-
return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
|
|
12857
|
-
}
|
|
12858
|
-
async function renameAside(filePath) {
|
|
12859
|
-
const asidePath = `${filePath}.corrupt-${Date.now()}`;
|
|
12860
|
-
await rename(filePath, asidePath).catch(() => void 0);
|
|
12861
|
-
await rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
|
|
12862
|
-
await rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
|
|
12863
|
-
process.stderr.write(
|
|
12864
|
-
`[theokit-sdk] memory index corrupt; renamed aside to ${asidePath} and rebuilt schema
|
|
12865
|
-
`
|
|
12866
|
-
);
|
|
12907
|
+
});
|
|
12867
12908
|
}
|
|
12868
12909
|
function defaultIndexPath(cwd) {
|
|
12869
12910
|
return join(cwd, ".theokit", "memory", ".index", "memory.sqlite");
|
|
@@ -14266,8 +14307,8 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
14266
14307
|
async function* wrap() {
|
|
14267
14308
|
const { runUntilImpl: runUntilImpl2 } = await Promise.resolve().then(() => (init_run_until(), run_until_exports));
|
|
14268
14309
|
const { judgeCallImpl: judgeCallImpl2 } = await Promise.resolve().then(() => (init_judge_call(), judge_call_exports));
|
|
14269
|
-
const {
|
|
14270
|
-
const create =
|
|
14310
|
+
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
14311
|
+
const create = getAgentFacade2().create;
|
|
14271
14312
|
const deps = {
|
|
14272
14313
|
judge: async (ctx, opts) => judgeCallImpl2(ctx, opts, { create })
|
|
14273
14314
|
};
|
|
@@ -14277,9 +14318,9 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
14277
14318
|
}
|
|
14278
14319
|
async function localAgentFork(parent, options) {
|
|
14279
14320
|
const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
|
|
14280
|
-
const {
|
|
14321
|
+
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
14281
14322
|
const { withPersonalityContext: withPersonalityContext2 } = await Promise.resolve().then(() => (init_context(), context_exports));
|
|
14282
|
-
const create =
|
|
14323
|
+
const create = getAgentFacade2().create;
|
|
14283
14324
|
return withPersonalityContext2(
|
|
14284
14325
|
{ slug: parent.personalitySlugSnapshot, isFork: true },
|
|
14285
14326
|
() => forkAgentImpl2(parent, options, { create })
|
|
@@ -14300,7 +14341,7 @@ async function persistMemoryFactIfWritePrompt(workspaceCwd, memoryConfig, userTe
|
|
|
14300
14341
|
// src/internal/runtime/local-agent/local-agent-send.ts
|
|
14301
14342
|
init_errors();
|
|
14302
14343
|
|
|
14303
|
-
// src/internal/runtime/abort-utils.ts
|
|
14344
|
+
// src/internal/runtime/concurrency/abort-utils.ts
|
|
14304
14345
|
function anySignal(signals) {
|
|
14305
14346
|
const filtered = signals.filter((s) => s !== void 0);
|
|
14306
14347
|
if (filtered.length === 0) {
|
|
@@ -15329,10 +15370,20 @@ async function getOrCreateUncached(agentId, options) {
|
|
|
15329
15370
|
throw err;
|
|
15330
15371
|
}
|
|
15331
15372
|
}
|
|
15332
|
-
|
|
15373
|
+
setAgentFacade({
|
|
15374
|
+
create: (options) => Agent.create(options),
|
|
15375
|
+
prompt: (message, options) => Agent.prompt(message, options),
|
|
15376
|
+
get: (agentId) => Agent.get(agentId),
|
|
15377
|
+
resume: (agentId, options) => Agent.resume(agentId, options),
|
|
15378
|
+
batch: (prompts, options) => Agent.batch(prompts, options)
|
|
15379
|
+
});
|
|
15380
|
+
|
|
15381
|
+
// src/cron.ts
|
|
15382
|
+
init_errors();
|
|
15333
15383
|
|
|
15334
15384
|
// src/internal/cron/run-job.ts
|
|
15335
15385
|
init_errors();
|
|
15386
|
+
init_agent_factory_registry();
|
|
15336
15387
|
async function runCronJob(job) {
|
|
15337
15388
|
if (job.agent !== void 0) return runWithEphemeralAgent(job.agent, job.message);
|
|
15338
15389
|
if (job.agentId !== void 0) return runWithExistingAgent(job.agentId, job.message);
|
|
@@ -15341,18 +15392,18 @@ async function runCronJob(job) {
|
|
|
15341
15392
|
});
|
|
15342
15393
|
}
|
|
15343
15394
|
async function runWithExistingAgent(agentId, message) {
|
|
15344
|
-
const info = await
|
|
15395
|
+
const info = await getAgentFacade().get(agentId).catch(() => void 0);
|
|
15345
15396
|
if (info === void 0) {
|
|
15346
15397
|
throw new UnknownAgentError(
|
|
15347
15398
|
`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.`,
|
|
15348
15399
|
{ code: "agent_not_registered" }
|
|
15349
15400
|
);
|
|
15350
15401
|
}
|
|
15351
|
-
const agent = await
|
|
15402
|
+
const agent = await getAgentFacade().resume(agentId);
|
|
15352
15403
|
return agent.send(message);
|
|
15353
15404
|
}
|
|
15354
15405
|
async function runWithEphemeralAgent(baseOptions, message) {
|
|
15355
|
-
const agent = await
|
|
15406
|
+
const agent = await getAgentFacade().create(baseOptions);
|
|
15356
15407
|
return agent.send(message);
|
|
15357
15408
|
}
|
|
15358
15409
|
|