@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/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var crypto = require('crypto');
|
|
3
4
|
var fs = require('fs');
|
|
4
5
|
var path = require('path');
|
|
5
|
-
var crypto = require('crypto');
|
|
6
6
|
var promises = require('fs/promises');
|
|
7
7
|
var zod = require('zod');
|
|
8
8
|
var async_hooks = require('async_hooks');
|
|
@@ -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;
|
|
@@ -179,7 +197,8 @@ __export(errors_exports, {
|
|
|
179
197
|
UnsupportedBudgetOperationError: () => exports.UnsupportedBudgetOperationError,
|
|
180
198
|
UnsupportedRunOperationError: () => exports.UnsupportedRunOperationError,
|
|
181
199
|
UnsupportedTaskOperationError: () => exports.UnsupportedTaskOperationError,
|
|
182
|
-
coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode
|
|
200
|
+
coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode,
|
|
201
|
+
isTransientError: () => isTransientError
|
|
183
202
|
});
|
|
184
203
|
function coerceToKnownAgentRunErrorCode(code) {
|
|
185
204
|
if (code !== void 0 && KNOWN_AGENT_RUN_ERROR_CODES.has(code)) {
|
|
@@ -211,21 +230,13 @@ function safeStringify(value) {
|
|
|
211
230
|
return String(value);
|
|
212
231
|
}
|
|
213
232
|
}
|
|
214
|
-
function
|
|
215
|
-
|
|
216
|
-
case "rate_limit":
|
|
217
|
-
case "timeout":
|
|
218
|
-
case "server_error":
|
|
219
|
-
case "network":
|
|
220
|
-
case "provider_unreachable":
|
|
221
|
-
return true;
|
|
222
|
-
default:
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
233
|
+
function isTransientError(err) {
|
|
234
|
+
return err instanceof exports.TheokitAgentError && err.isRetryable === true;
|
|
225
235
|
}
|
|
226
236
|
var KNOWN_AGENT_RUN_ERROR_CODES; exports.TheokitAgentError = void 0; exports.AuthenticationError = void 0; exports.RateLimitError = void 0; exports.ConfigurationError = void 0; exports.IntegrationNotConnectedError = void 0; exports.NetworkError = void 0; exports.UnknownAgentError = void 0; exports.AgentRunError = void 0; exports.UnsupportedRunOperationError = void 0; var CredentialPoolExhaustedError; exports.MemoryAdapterError = void 0; exports.InvalidTaskIdError = void 0; exports.TaskNotFoundError = void 0; exports.UnsupportedTaskOperationError = void 0; exports.BudgetExceededError = void 0; exports.AgentDisposedError = void 0; exports.UnsupportedBudgetOperationError = void 0;
|
|
227
237
|
var init_errors = __esm({
|
|
228
238
|
"src/errors.ts"() {
|
|
239
|
+
init_default_retriable();
|
|
229
240
|
init_redact();
|
|
230
241
|
KNOWN_AGENT_RUN_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
231
242
|
"rate_limit",
|
|
@@ -649,6 +660,19 @@ function sanitizeIdentifier(input, options) {
|
|
|
649
660
|
}
|
|
650
661
|
return input.toLowerCase();
|
|
651
662
|
}
|
|
663
|
+
function safeFilenameForId(id, options) {
|
|
664
|
+
if (id.length === 0) {
|
|
665
|
+
throw new exports.ConfigurationError("Filename id must be a non-empty string", {
|
|
666
|
+
code: "invalid_filename_id"
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
const maxLen = options?.maxLen;
|
|
670
|
+
const lower = id.toLowerCase();
|
|
671
|
+
if (lower.length <= maxLen && IDENTIFIER_PATTERN.test(lower)) {
|
|
672
|
+
return lower;
|
|
673
|
+
}
|
|
674
|
+
return `h-${crypto.createHash("sha256").update(id).digest("hex").slice(0, 16)}`;
|
|
675
|
+
}
|
|
652
676
|
var PathTraversalError, IDENTIFIER_PATTERN;
|
|
653
677
|
var init_path_guard = __esm({
|
|
654
678
|
"src/internal/security/path-guard.ts"() {
|
|
@@ -839,7 +863,7 @@ var init_markdown_store = __esm({
|
|
|
839
863
|
}
|
|
840
864
|
});
|
|
841
865
|
|
|
842
|
-
// src/internal/runtime/yaml-frontmatter.ts
|
|
866
|
+
// src/internal/runtime/context/yaml-frontmatter.ts
|
|
843
867
|
function parseSimpleYaml(text) {
|
|
844
868
|
const fields = {};
|
|
845
869
|
for (const line of text.split(/\r?\n/)) {
|
|
@@ -863,7 +887,7 @@ function coerce(raw) {
|
|
|
863
887
|
return raw;
|
|
864
888
|
}
|
|
865
889
|
var init_yaml_frontmatter = __esm({
|
|
866
|
-
"src/internal/runtime/yaml-frontmatter.ts"() {
|
|
890
|
+
"src/internal/runtime/context/yaml-frontmatter.ts"() {
|
|
867
891
|
}
|
|
868
892
|
});
|
|
869
893
|
async function loadMarkdownEntities(opts) {
|
|
@@ -1051,10 +1075,7 @@ function sessionsDir(cwd) {
|
|
|
1051
1075
|
return path.join(memoryDir(cwd), "sessions");
|
|
1052
1076
|
}
|
|
1053
1077
|
function sessionSummaryPath(cwd, runId) {
|
|
1054
|
-
return path.join(sessionsDir(cwd), `${
|
|
1055
|
-
}
|
|
1056
|
-
function sanitizeRunId(runId) {
|
|
1057
|
-
return runId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 128);
|
|
1078
|
+
return path.join(sessionsDir(cwd), `${safeFilenameForId(runId, { maxLen: 128 })}.md`);
|
|
1058
1079
|
}
|
|
1059
1080
|
function truncate(text) {
|
|
1060
1081
|
if (text.length <= MAX_TURN_CHARS) return text;
|
|
@@ -1090,6 +1111,7 @@ var MAX_TURN_CHARS;
|
|
|
1090
1111
|
var init_session_summary_writer = __esm({
|
|
1091
1112
|
"src/internal/memory/storage/session-summary-writer.ts"() {
|
|
1092
1113
|
init_atomic_write();
|
|
1114
|
+
init_path_guard();
|
|
1093
1115
|
init_types();
|
|
1094
1116
|
init_markdown_store();
|
|
1095
1117
|
MAX_TURN_CHARS = 2e3;
|
|
@@ -1114,11 +1136,54 @@ function checkToolWhitelist(toolName) {
|
|
|
1114
1136
|
}
|
|
1115
1137
|
var toolWhitelistStore;
|
|
1116
1138
|
var init_async_local_storage = __esm({
|
|
1117
|
-
"src/internal/runtime/async-local-storage.ts"() {
|
|
1139
|
+
"src/internal/runtime/concurrency/async-local-storage.ts"() {
|
|
1118
1140
|
toolWhitelistStore = new async_hooks.AsyncLocalStorage();
|
|
1119
1141
|
}
|
|
1120
1142
|
});
|
|
1121
1143
|
|
|
1144
|
+
// src/internal/runtime/concurrency/async-semaphore.ts
|
|
1145
|
+
function createSemaphore(permits) {
|
|
1146
|
+
if (!Number.isInteger(permits) || permits < 1) {
|
|
1147
|
+
throw new exports.ConfigurationError(
|
|
1148
|
+
`async-semaphore: permits must be a positive integer, got ${permits}`,
|
|
1149
|
+
{ code: "invalid_concurrency" }
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
let active = 0;
|
|
1153
|
+
const queue = [];
|
|
1154
|
+
function tryGrant() {
|
|
1155
|
+
if (active < permits && queue.length > 0) {
|
|
1156
|
+
const resolve3 = queue.shift();
|
|
1157
|
+
if (resolve3 !== void 0) {
|
|
1158
|
+
active += 1;
|
|
1159
|
+
resolve3();
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
return {
|
|
1164
|
+
inFlight: () => active,
|
|
1165
|
+
pending: () => queue.length + active,
|
|
1166
|
+
async acquire() {
|
|
1167
|
+
await new Promise((resolve3) => {
|
|
1168
|
+
queue.push(resolve3);
|
|
1169
|
+
tryGrant();
|
|
1170
|
+
});
|
|
1171
|
+
let released = false;
|
|
1172
|
+
return () => {
|
|
1173
|
+
if (released) return;
|
|
1174
|
+
released = true;
|
|
1175
|
+
active -= 1;
|
|
1176
|
+
tryGrant();
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
var init_async_semaphore = __esm({
|
|
1182
|
+
"src/internal/runtime/concurrency/async-semaphore.ts"() {
|
|
1183
|
+
init_errors();
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1122
1187
|
// src/internal/llm/credential-pool-types.ts
|
|
1123
1188
|
var COOLDOWN_MS, DEFAULT_COOLDOWN_MS;
|
|
1124
1189
|
var init_credential_pool_types = __esm({
|
|
@@ -1500,6 +1565,61 @@ var init_sqlite_wal = __esm({
|
|
|
1500
1565
|
warnedLabels = /* @__PURE__ */ new Set();
|
|
1501
1566
|
}
|
|
1502
1567
|
});
|
|
1568
|
+
async function openSqliteResilient(options) {
|
|
1569
|
+
await promises.mkdir(path.dirname(options.filePath), { recursive: true });
|
|
1570
|
+
try {
|
|
1571
|
+
return await openConcrete(options);
|
|
1572
|
+
} catch (cause) {
|
|
1573
|
+
if (options.recoverCorrupt !== false && isCorruptionError(cause)) {
|
|
1574
|
+
await renameAside(options.filePath, options.label ?? "sqlite");
|
|
1575
|
+
return await openConcrete(options);
|
|
1576
|
+
}
|
|
1577
|
+
throw cause;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
async function openConcrete(options) {
|
|
1581
|
+
const db = await loadDriver(options.filePath);
|
|
1582
|
+
applyWalWithFallback(db, options.label ?? "sqlite");
|
|
1583
|
+
await options.onOpen?.(db);
|
|
1584
|
+
return db;
|
|
1585
|
+
}
|
|
1586
|
+
async function loadDriver(filePath) {
|
|
1587
|
+
try {
|
|
1588
|
+
const mod = await import('better-sqlite3');
|
|
1589
|
+
const Ctor = mod.default ?? mod;
|
|
1590
|
+
if (typeof Ctor !== "function") {
|
|
1591
|
+
throw new Error(`better-sqlite3 export is not a constructor (got ${typeof Ctor})`);
|
|
1592
|
+
}
|
|
1593
|
+
return new Ctor(filePath);
|
|
1594
|
+
} catch (cause) {
|
|
1595
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
1596
|
+
throw new exports.ConfigurationError(
|
|
1597
|
+
`Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
|
|
1598
|
+
{ code: "sqlite_driver_unavailable", cause }
|
|
1599
|
+
);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
function isCorruptionError(cause) {
|
|
1603
|
+
if (!(cause instanceof Error)) return false;
|
|
1604
|
+
const msg = cause.message.toLowerCase();
|
|
1605
|
+
return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
|
|
1606
|
+
}
|
|
1607
|
+
async function renameAside(filePath, label) {
|
|
1608
|
+
const asidePath = `${filePath}.corrupt-${Date.now()}`;
|
|
1609
|
+
await promises.rename(filePath, asidePath).catch(() => void 0);
|
|
1610
|
+
await promises.rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
|
|
1611
|
+
await promises.rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
|
|
1612
|
+
process.stderr.write(
|
|
1613
|
+
`[theokit-sdk] ${label} database corrupt; renamed aside to ${asidePath} and rebuilt schema
|
|
1614
|
+
`
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1617
|
+
var init_sqlite_open = __esm({
|
|
1618
|
+
"src/internal/persistence/sqlite-open.ts"() {
|
|
1619
|
+
init_errors();
|
|
1620
|
+
init_sqlite_wal();
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1503
1623
|
|
|
1504
1624
|
// src/internal/memory/index-schema.ts
|
|
1505
1625
|
var SCHEMA_STATEMENTS, PRAGMA_STATEMENTS;
|
|
@@ -1547,60 +1667,22 @@ var init_index_schema = __esm({
|
|
|
1547
1667
|
}
|
|
1548
1668
|
});
|
|
1549
1669
|
async function openMemoryDb(opts) {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1670
|
+
return openSqliteResilient({
|
|
1671
|
+
filePath: opts.filePath,
|
|
1672
|
+
label: "memory-index",
|
|
1673
|
+
recoverCorrupt: opts.recoverCorrupt,
|
|
1674
|
+
onOpen: (db) => {
|
|
1675
|
+
for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
|
|
1676
|
+
for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
|
|
1557
1677
|
}
|
|
1558
|
-
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
async function openConcrete(filePath) {
|
|
1562
|
-
const db = await loadDriver(filePath);
|
|
1563
|
-
applyWalWithFallback(db, "memory-index");
|
|
1564
|
-
for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
|
|
1565
|
-
for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
|
|
1566
|
-
return db;
|
|
1567
|
-
}
|
|
1568
|
-
async function loadDriver(filePath) {
|
|
1569
|
-
try {
|
|
1570
|
-
const mod = await import('better-sqlite3');
|
|
1571
|
-
const Ctor = mod.default ?? mod;
|
|
1572
|
-
const db = new Ctor(filePath);
|
|
1573
|
-
return db;
|
|
1574
|
-
} catch (cause) {
|
|
1575
|
-
const message = cause instanceof Error ? cause.message : String(cause);
|
|
1576
|
-
throw new exports.ConfigurationError(
|
|
1577
|
-
`Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
|
|
1578
|
-
{ code: "sqlite_driver_unavailable", cause }
|
|
1579
|
-
);
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
function isCorruptionError(cause) {
|
|
1583
|
-
if (!(cause instanceof Error)) return false;
|
|
1584
|
-
const msg = cause.message.toLowerCase();
|
|
1585
|
-
return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
|
|
1586
|
-
}
|
|
1587
|
-
async function renameAside(filePath) {
|
|
1588
|
-
const asidePath = `${filePath}.corrupt-${Date.now()}`;
|
|
1589
|
-
await promises.rename(filePath, asidePath).catch(() => void 0);
|
|
1590
|
-
await promises.rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
|
|
1591
|
-
await promises.rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
|
|
1592
|
-
process.stderr.write(
|
|
1593
|
-
`[theokit-sdk] memory index corrupt; renamed aside to ${asidePath} and rebuilt schema
|
|
1594
|
-
`
|
|
1595
|
-
);
|
|
1678
|
+
});
|
|
1596
1679
|
}
|
|
1597
1680
|
function defaultIndexPath(cwd) {
|
|
1598
1681
|
return path.join(cwd, ".theokit", "memory", ".index", "memory.sqlite");
|
|
1599
1682
|
}
|
|
1600
1683
|
var init_index_db = __esm({
|
|
1601
1684
|
"src/internal/memory/index-db.ts"() {
|
|
1602
|
-
|
|
1603
|
-
init_sqlite_wal();
|
|
1685
|
+
init_sqlite_open();
|
|
1604
1686
|
init_index_schema();
|
|
1605
1687
|
}
|
|
1606
1688
|
});
|
|
@@ -2493,7 +2575,7 @@ var init_local_agent_plugins = __esm({
|
|
|
2493
2575
|
}
|
|
2494
2576
|
});
|
|
2495
2577
|
|
|
2496
|
-
// src/internal/runtime/run-until.ts
|
|
2578
|
+
// src/internal/runtime/lifecycle/run-until.ts
|
|
2497
2579
|
var run_until_exports = {};
|
|
2498
2580
|
__export(run_until_exports, {
|
|
2499
2581
|
composeContinuation: () => composeContinuation,
|
|
@@ -2586,7 +2668,7 @@ Your last response was:
|
|
|
2586
2668
|
${lastResponse.slice(0, 1e3)}`;
|
|
2587
2669
|
}
|
|
2588
2670
|
var init_run_until = __esm({
|
|
2589
|
-
"src/internal/runtime/run-until.ts"() {
|
|
2671
|
+
"src/internal/runtime/lifecycle/run-until.ts"() {
|
|
2590
2672
|
}
|
|
2591
2673
|
});
|
|
2592
2674
|
|
|
@@ -2697,16 +2779,16 @@ var init_judge_call = __esm({
|
|
|
2697
2779
|
// src/internal/runtime/registry/agent-factory-registry.ts
|
|
2698
2780
|
var agent_factory_registry_exports = {};
|
|
2699
2781
|
__export(agent_factory_registry_exports, {
|
|
2700
|
-
|
|
2701
|
-
|
|
2782
|
+
getAgentFacade: () => getAgentFacade,
|
|
2783
|
+
setAgentFacade: () => setAgentFacade
|
|
2702
2784
|
});
|
|
2703
|
-
function
|
|
2704
|
-
registered3 =
|
|
2785
|
+
function setAgentFacade(facade) {
|
|
2786
|
+
registered3 = facade;
|
|
2705
2787
|
}
|
|
2706
|
-
function
|
|
2788
|
+
function getAgentFacade() {
|
|
2707
2789
|
if (registered3 === void 0) {
|
|
2708
2790
|
throw new Error(
|
|
2709
|
-
"internal: Agent
|
|
2791
|
+
"internal: Agent facade not registered. The `agent.ts` module must be loaded before internal subsystems (LocalAgent.runUntil/fork, eval, scorers, cron) invoke it."
|
|
2710
2792
|
);
|
|
2711
2793
|
}
|
|
2712
2794
|
return registered3;
|
|
@@ -2717,7 +2799,7 @@ var init_agent_factory_registry = __esm({
|
|
|
2717
2799
|
}
|
|
2718
2800
|
});
|
|
2719
2801
|
|
|
2720
|
-
// src/internal/runtime/fork-agent.ts
|
|
2802
|
+
// src/internal/runtime/lifecycle/fork-agent.ts
|
|
2721
2803
|
var fork_agent_exports = {};
|
|
2722
2804
|
__export(fork_agent_exports, {
|
|
2723
2805
|
filterMemoryPlugins: () => filterMemoryPlugins,
|
|
@@ -2777,7 +2859,7 @@ function extractUsage(result) {
|
|
|
2777
2859
|
};
|
|
2778
2860
|
}
|
|
2779
2861
|
var init_fork_agent = __esm({
|
|
2780
|
-
"src/internal/runtime/fork-agent.ts"() {
|
|
2862
|
+
"src/internal/runtime/lifecycle/fork-agent.ts"() {
|
|
2781
2863
|
init_async_local_storage();
|
|
2782
2864
|
init_local_agent_plugins();
|
|
2783
2865
|
}
|
|
@@ -2800,49 +2882,6 @@ var init_task = __esm({
|
|
|
2800
2882
|
}
|
|
2801
2883
|
});
|
|
2802
2884
|
|
|
2803
|
-
// src/internal/runtime/async-semaphore.ts
|
|
2804
|
-
function createSemaphore(permits) {
|
|
2805
|
-
if (!Number.isInteger(permits) || permits < 1) {
|
|
2806
|
-
throw new exports.ConfigurationError(
|
|
2807
|
-
`async-semaphore: permits must be a positive integer, got ${permits}`,
|
|
2808
|
-
{ code: "invalid_concurrency" }
|
|
2809
|
-
);
|
|
2810
|
-
}
|
|
2811
|
-
let active = 0;
|
|
2812
|
-
const queue = [];
|
|
2813
|
-
function tryGrant() {
|
|
2814
|
-
if (active < permits && queue.length > 0) {
|
|
2815
|
-
const resolve3 = queue.shift();
|
|
2816
|
-
if (resolve3 !== void 0) {
|
|
2817
|
-
active += 1;
|
|
2818
|
-
resolve3();
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2821
|
-
}
|
|
2822
|
-
return {
|
|
2823
|
-
inFlight: () => active,
|
|
2824
|
-
pending: () => queue.length + active,
|
|
2825
|
-
async acquire() {
|
|
2826
|
-
await new Promise((resolve3) => {
|
|
2827
|
-
queue.push(resolve3);
|
|
2828
|
-
tryGrant();
|
|
2829
|
-
});
|
|
2830
|
-
let released = false;
|
|
2831
|
-
return () => {
|
|
2832
|
-
if (released) return;
|
|
2833
|
-
released = true;
|
|
2834
|
-
active -= 1;
|
|
2835
|
-
tryGrant();
|
|
2836
|
-
};
|
|
2837
|
-
}
|
|
2838
|
-
};
|
|
2839
|
-
}
|
|
2840
|
-
var init_async_semaphore = __esm({
|
|
2841
|
-
"src/internal/runtime/async-semaphore.ts"() {
|
|
2842
|
-
init_errors();
|
|
2843
|
-
}
|
|
2844
|
-
});
|
|
2845
|
-
|
|
2846
2885
|
// src/internal/task/ring-buffer.ts
|
|
2847
2886
|
var RingBuffer;
|
|
2848
2887
|
var init_ring_buffer = __esm({
|
|
@@ -5651,7 +5690,7 @@ init_errors();
|
|
|
5651
5690
|
init_cwd_mutex();
|
|
5652
5691
|
init_path_guard();
|
|
5653
5692
|
|
|
5654
|
-
// src/internal/runtime/default-model.ts
|
|
5693
|
+
// src/internal/runtime/config/default-model.ts
|
|
5655
5694
|
var DEFAULT_AGENTIC_MODEL_ID = "google/gemini-2.0-flash-001";
|
|
5656
5695
|
|
|
5657
5696
|
// src/internal/runtime/registry/agent-registry-store.ts
|
|
@@ -5972,7 +6011,7 @@ async function flushRegistrySaves(cwd) {
|
|
|
5972
6011
|
}
|
|
5973
6012
|
}
|
|
5974
6013
|
|
|
5975
|
-
// src/internal/runtime/system-prompt.ts
|
|
6014
|
+
// src/internal/runtime/system-prompt/system-prompt.ts
|
|
5976
6015
|
async function resolveSystemPrompt(agent, override, ctx) {
|
|
5977
6016
|
if (override !== void 0) return override;
|
|
5978
6017
|
if (agent === void 0) return void 0;
|
|
@@ -8267,6 +8306,9 @@ function parseDecisionFromStdout(stdout) {
|
|
|
8267
8306
|
return { decision: "allow" };
|
|
8268
8307
|
}
|
|
8269
8308
|
|
|
8309
|
+
// src/internal/runtime/lifecycle/post-run-lifecycle.ts
|
|
8310
|
+
init_session_summary_writer();
|
|
8311
|
+
|
|
8270
8312
|
// src/internal/runtime/memory/memory-path-selector.ts
|
|
8271
8313
|
var PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
|
|
8272
8314
|
function shouldUsePortMemoryPath() {
|
|
@@ -8289,9 +8331,6 @@ function resolveActiveMemorySummaryForSend(legacySummary, portPathEnabled) {
|
|
|
8289
8331
|
return legacySummary;
|
|
8290
8332
|
}
|
|
8291
8333
|
|
|
8292
|
-
// src/internal/runtime/post-run-lifecycle.ts
|
|
8293
|
-
init_session_summary_writer();
|
|
8294
|
-
|
|
8295
8334
|
// src/internal/runtime/session/agent-session-store.ts
|
|
8296
8335
|
init_atomic_write();
|
|
8297
8336
|
init_security();
|
|
@@ -8550,7 +8589,7 @@ function clearSession(agentId) {
|
|
|
8550
8589
|
sessions.delete(agentId);
|
|
8551
8590
|
}
|
|
8552
8591
|
|
|
8553
|
-
// src/internal/runtime/post-run-lifecycle.ts
|
|
8592
|
+
// src/internal/runtime/lifecycle/post-run-lifecycle.ts
|
|
8554
8593
|
async function runPostRunLifecycle(inputs) {
|
|
8555
8594
|
const {
|
|
8556
8595
|
run,
|
|
@@ -8782,7 +8821,7 @@ var liveAgentRegistry = new LiveAgentRegistry();
|
|
|
8782
8821
|
// src/internal/runtime/skills/subagents-loader.ts
|
|
8783
8822
|
init_errors();
|
|
8784
8823
|
|
|
8785
|
-
// src/internal/runtime/workspace-dir.ts
|
|
8824
|
+
// src/internal/runtime/config/workspace-dir.ts
|
|
8786
8825
|
init_errors();
|
|
8787
8826
|
async function readWorkspaceDir(root, errorCode, describe) {
|
|
8788
8827
|
try {
|
|
@@ -9068,7 +9107,7 @@ var SystemPromptPipeline = class _SystemPromptPipeline {
|
|
|
9068
9107
|
}
|
|
9069
9108
|
};
|
|
9070
9109
|
|
|
9071
|
-
// src/internal/runtime/validate-agent-options.ts
|
|
9110
|
+
// src/internal/runtime/validation/validate-agent-options.ts
|
|
9072
9111
|
init_errors();
|
|
9073
9112
|
function validateAgentOptions(options) {
|
|
9074
9113
|
rejectProgrammaticHooks(options);
|
|
@@ -9263,6 +9302,71 @@ function validateMemory(options) {
|
|
|
9263
9302
|
}
|
|
9264
9303
|
}
|
|
9265
9304
|
|
|
9305
|
+
// src/internal/runtime/config/providers-manager.ts
|
|
9306
|
+
var ProvidersManagerImpl = class {
|
|
9307
|
+
constructor(model, providers, plugins) {
|
|
9308
|
+
this.model = model;
|
|
9309
|
+
this.providers = providers;
|
|
9310
|
+
this.plugins = plugins;
|
|
9311
|
+
}
|
|
9312
|
+
model;
|
|
9313
|
+
providers;
|
|
9314
|
+
plugins;
|
|
9315
|
+
routes() {
|
|
9316
|
+
const resolved = [];
|
|
9317
|
+
const modelProvider = providerFromModel(this.model);
|
|
9318
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9319
|
+
if (this.providers?.routes !== void 0) {
|
|
9320
|
+
for (const route of this.providers.routes) {
|
|
9321
|
+
const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
|
|
9322
|
+
if (!seen.has(route.capability)) {
|
|
9323
|
+
seen.add(route.capability);
|
|
9324
|
+
resolved.push(resolvedRoute);
|
|
9325
|
+
}
|
|
9326
|
+
}
|
|
9327
|
+
}
|
|
9328
|
+
return Promise.resolve(resolved);
|
|
9329
|
+
}
|
|
9330
|
+
};
|
|
9331
|
+
function providerFromModel(model) {
|
|
9332
|
+
if (model === void 0) return void 0;
|
|
9333
|
+
const id = model.id;
|
|
9334
|
+
if (id.includes(":")) return id.split(":")[0];
|
|
9335
|
+
return void 0;
|
|
9336
|
+
}
|
|
9337
|
+
function resolveRoute(route, modelProvider, plugins) {
|
|
9338
|
+
if (route.capability === "chat" && modelProvider === route.provider) {
|
|
9339
|
+
const modelName = extractModelName(modelProvider, route);
|
|
9340
|
+
const base = {
|
|
9341
|
+
capability: route.capability,
|
|
9342
|
+
provider: route.provider,
|
|
9343
|
+
reason: "explicit-model-provider"
|
|
9344
|
+
};
|
|
9345
|
+
if (modelName !== void 0) base.model = modelName;
|
|
9346
|
+
return base;
|
|
9347
|
+
}
|
|
9348
|
+
if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
|
|
9349
|
+
return {
|
|
9350
|
+
capability: route.capability,
|
|
9351
|
+
provider: route.provider,
|
|
9352
|
+
reason: "first-available-plugin-provider"
|
|
9353
|
+
};
|
|
9354
|
+
}
|
|
9355
|
+
return {
|
|
9356
|
+
capability: route.capability,
|
|
9357
|
+
provider: route.provider,
|
|
9358
|
+
reason: "explicit-route"
|
|
9359
|
+
};
|
|
9360
|
+
}
|
|
9361
|
+
function extractModelName(prefix, route) {
|
|
9362
|
+
if (route.model !== void 0) return route.model;
|
|
9363
|
+
return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
|
|
9364
|
+
}
|
|
9365
|
+
function defaultModelForProvider(provider) {
|
|
9366
|
+
if (provider === "anthropic") return "claude-3-7-sonnet";
|
|
9367
|
+
return void 0;
|
|
9368
|
+
}
|
|
9369
|
+
|
|
9266
9370
|
// src/internal/runtime/context/context-manager.ts
|
|
9267
9371
|
init_errors();
|
|
9268
9372
|
init_markdown_config_loader();
|
|
@@ -10060,71 +10164,6 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
|
|
|
10060
10164
|
return metadata;
|
|
10061
10165
|
}
|
|
10062
10166
|
|
|
10063
|
-
// src/internal/runtime/providers-manager.ts
|
|
10064
|
-
var ProvidersManagerImpl = class {
|
|
10065
|
-
constructor(model, providers, plugins) {
|
|
10066
|
-
this.model = model;
|
|
10067
|
-
this.providers = providers;
|
|
10068
|
-
this.plugins = plugins;
|
|
10069
|
-
}
|
|
10070
|
-
model;
|
|
10071
|
-
providers;
|
|
10072
|
-
plugins;
|
|
10073
|
-
routes() {
|
|
10074
|
-
const resolved = [];
|
|
10075
|
-
const modelProvider = providerFromModel(this.model);
|
|
10076
|
-
const seen = /* @__PURE__ */ new Set();
|
|
10077
|
-
if (this.providers?.routes !== void 0) {
|
|
10078
|
-
for (const route of this.providers.routes) {
|
|
10079
|
-
const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
|
|
10080
|
-
if (!seen.has(route.capability)) {
|
|
10081
|
-
seen.add(route.capability);
|
|
10082
|
-
resolved.push(resolvedRoute);
|
|
10083
|
-
}
|
|
10084
|
-
}
|
|
10085
|
-
}
|
|
10086
|
-
return Promise.resolve(resolved);
|
|
10087
|
-
}
|
|
10088
|
-
};
|
|
10089
|
-
function providerFromModel(model) {
|
|
10090
|
-
if (model === void 0) return void 0;
|
|
10091
|
-
const id = model.id;
|
|
10092
|
-
if (id.includes(":")) return id.split(":")[0];
|
|
10093
|
-
return void 0;
|
|
10094
|
-
}
|
|
10095
|
-
function resolveRoute(route, modelProvider, plugins) {
|
|
10096
|
-
if (route.capability === "chat" && modelProvider === route.provider) {
|
|
10097
|
-
const modelName = extractModelName(modelProvider, route);
|
|
10098
|
-
const base = {
|
|
10099
|
-
capability: route.capability,
|
|
10100
|
-
provider: route.provider,
|
|
10101
|
-
reason: "explicit-model-provider"
|
|
10102
|
-
};
|
|
10103
|
-
if (modelName !== void 0) base.model = modelName;
|
|
10104
|
-
return base;
|
|
10105
|
-
}
|
|
10106
|
-
if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
|
|
10107
|
-
return {
|
|
10108
|
-
capability: route.capability,
|
|
10109
|
-
provider: route.provider,
|
|
10110
|
-
reason: "first-available-plugin-provider"
|
|
10111
|
-
};
|
|
10112
|
-
}
|
|
10113
|
-
return {
|
|
10114
|
-
capability: route.capability,
|
|
10115
|
-
provider: route.provider,
|
|
10116
|
-
reason: "explicit-route"
|
|
10117
|
-
};
|
|
10118
|
-
}
|
|
10119
|
-
function extractModelName(prefix, route) {
|
|
10120
|
-
if (route.model !== void 0) return route.model;
|
|
10121
|
-
return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
|
|
10122
|
-
}
|
|
10123
|
-
function defaultModelForProvider(provider) {
|
|
10124
|
-
if (provider === "anthropic") return "claude-3-7-sonnet";
|
|
10125
|
-
return void 0;
|
|
10126
|
-
}
|
|
10127
|
-
|
|
10128
10167
|
// src/internal/runtime/skills/skills-manager.ts
|
|
10129
10168
|
init_errors();
|
|
10130
10169
|
init_path_guard();
|
|
@@ -10472,7 +10511,7 @@ var IterationBudget = class {
|
|
|
10472
10511
|
}
|
|
10473
10512
|
};
|
|
10474
10513
|
|
|
10475
|
-
// src/internal/runtime/validate-response.ts
|
|
10514
|
+
// src/internal/runtime/validation/validate-response.ts
|
|
10476
10515
|
function validateResponse(response) {
|
|
10477
10516
|
const trimmed = response.content.trim();
|
|
10478
10517
|
const toolCallsArr = Array.isArray(response.toolCalls) ? response.toolCalls : [];
|
|
@@ -10858,6 +10897,27 @@ async function emitTextDeltaCallback(inputs, text) {
|
|
|
10858
10897
|
// src/internal/agent-loop/tool-dispatch.ts
|
|
10859
10898
|
init_async_local_storage();
|
|
10860
10899
|
|
|
10900
|
+
// src/internal/runtime/concurrency/map-with-concurrency.ts
|
|
10901
|
+
init_async_semaphore();
|
|
10902
|
+
var NEVER_ABORT = new AbortController().signal;
|
|
10903
|
+
async function mapWithConcurrency(items, concurrency, fn, options) {
|
|
10904
|
+
const semaphore = createSemaphore(concurrency);
|
|
10905
|
+
const signal = NEVER_ABORT;
|
|
10906
|
+
return Promise.all(
|
|
10907
|
+
items.map(async (item, index) => {
|
|
10908
|
+
const release = await semaphore.acquire();
|
|
10909
|
+
try {
|
|
10910
|
+
if (signal.aborted) {
|
|
10911
|
+
throw signal.reason instanceof Error ? signal.reason : new Error("mapWithConcurrency: aborted");
|
|
10912
|
+
}
|
|
10913
|
+
return await fn(item, index, signal);
|
|
10914
|
+
} finally {
|
|
10915
|
+
release();
|
|
10916
|
+
}
|
|
10917
|
+
})
|
|
10918
|
+
);
|
|
10919
|
+
}
|
|
10920
|
+
|
|
10861
10921
|
// src/internal/tool-dispatch/repair-middleware.ts
|
|
10862
10922
|
var DECIMAL_RE = /^-?\d+(\.\d+)?$/;
|
|
10863
10923
|
function repairToolCall(raw, registry3) {
|
|
@@ -10931,7 +10991,7 @@ function coerceArgsToSchema(args, schema) {
|
|
|
10931
10991
|
return { value: out, changed };
|
|
10932
10992
|
}
|
|
10933
10993
|
|
|
10934
|
-
// src/internal/runtime/shell-tool.ts
|
|
10994
|
+
// src/internal/runtime/tools/shell-tool.ts
|
|
10935
10995
|
async function runShell(options) {
|
|
10936
10996
|
if (options.sandbox === true && isObviouslyUnsafe(options.command)) {
|
|
10937
10997
|
return {
|
|
@@ -11032,38 +11092,12 @@ ${result.stderr}`.trim();
|
|
|
11032
11092
|
// src/internal/agent-loop/tool-dispatch.ts
|
|
11033
11093
|
async function dispatchTools(inputs, tools, toolCalls, events) {
|
|
11034
11094
|
const maxConcurrent = inputs.maxConcurrentTools ?? 4;
|
|
11035
|
-
return
|
|
11036
|
-
maxConcurrent,
|
|
11095
|
+
return mapWithConcurrency(
|
|
11037
11096
|
toolCalls,
|
|
11097
|
+
maxConcurrent,
|
|
11038
11098
|
(call) => dispatchSingleCall(inputs, tools, call, events)
|
|
11039
11099
|
);
|
|
11040
11100
|
}
|
|
11041
|
-
async function boundedParallel(max, items, fn) {
|
|
11042
|
-
let running = 0;
|
|
11043
|
-
const queue = [];
|
|
11044
|
-
async function acquire() {
|
|
11045
|
-
if (running < max) {
|
|
11046
|
-
running++;
|
|
11047
|
-
return;
|
|
11048
|
-
}
|
|
11049
|
-
await new Promise((resolve3) => queue.push(resolve3));
|
|
11050
|
-
running++;
|
|
11051
|
-
}
|
|
11052
|
-
function release() {
|
|
11053
|
-
running--;
|
|
11054
|
-
if (queue.length > 0) queue.shift()();
|
|
11055
|
-
}
|
|
11056
|
-
return Promise.all(
|
|
11057
|
-
items.map(async (item) => {
|
|
11058
|
-
await acquire();
|
|
11059
|
-
try {
|
|
11060
|
-
return await fn(item);
|
|
11061
|
-
} finally {
|
|
11062
|
-
release();
|
|
11063
|
-
}
|
|
11064
|
-
})
|
|
11065
|
-
);
|
|
11066
|
-
}
|
|
11067
11101
|
async function dispatchSingleCall(inputs, tools, call, events) {
|
|
11068
11102
|
const { call: workingCall, repairs } = applyRepairAndExtractCall(tools, call);
|
|
11069
11103
|
const callId = generateCallId();
|
|
@@ -12146,10 +12180,10 @@ function registerBuiltins() {
|
|
|
12146
12180
|
registerCatalogProviders();
|
|
12147
12181
|
}
|
|
12148
12182
|
|
|
12149
|
-
// src/internal/
|
|
12183
|
+
// src/internal/error-mappers/anthropic.ts
|
|
12150
12184
|
init_errors();
|
|
12151
12185
|
|
|
12152
|
-
// src/internal/
|
|
12186
|
+
// src/internal/error-mappers/shared.ts
|
|
12153
12187
|
init_security();
|
|
12154
12188
|
var RAW_MAX_BYTES = 2048;
|
|
12155
12189
|
function parseRetryAfter(headers) {
|
|
@@ -12179,7 +12213,7 @@ function buildErrorMetadata(args) {
|
|
|
12179
12213
|
};
|
|
12180
12214
|
}
|
|
12181
12215
|
|
|
12182
|
-
// src/internal/
|
|
12216
|
+
// src/internal/error-mappers/anthropic.ts
|
|
12183
12217
|
function mapAnthropicError(args) {
|
|
12184
12218
|
const { status, body, headers, endpoint } = args;
|
|
12185
12219
|
const code = mapAnthropicStatusToCode(status, body);
|
|
@@ -12519,7 +12553,7 @@ function buildAnthropicBody(request) {
|
|
|
12519
12553
|
// src/internal/llm/bedrock-anthropic.ts
|
|
12520
12554
|
init_errors();
|
|
12521
12555
|
|
|
12522
|
-
// src/internal/
|
|
12556
|
+
// src/internal/error-mappers/bedrock.ts
|
|
12523
12557
|
init_errors();
|
|
12524
12558
|
function classifyBedrockError(args, awsType, message) {
|
|
12525
12559
|
if (args.status === 429 || awsType.includes("Throttling") || awsType.includes("TooManyRequests")) {
|
|
@@ -12656,7 +12690,7 @@ function buildBedrockBody(request) {
|
|
|
12656
12690
|
init_credential_pool();
|
|
12657
12691
|
init_credential_pool_context();
|
|
12658
12692
|
|
|
12659
|
-
// src/internal/
|
|
12693
|
+
// src/internal/error-mappers/openai-compatible.ts
|
|
12660
12694
|
init_errors();
|
|
12661
12695
|
function mapOpenAICompatibleError(args) {
|
|
12662
12696
|
const { providerId, status, body, headers, endpoint } = args;
|
|
@@ -12820,7 +12854,7 @@ function readOpenAiContent(body) {
|
|
|
12820
12854
|
return void 0;
|
|
12821
12855
|
}
|
|
12822
12856
|
|
|
12823
|
-
// src/internal/
|
|
12857
|
+
// src/internal/error-mappers/ollama.ts
|
|
12824
12858
|
init_errors();
|
|
12825
12859
|
function mapOllamaTransportError(args) {
|
|
12826
12860
|
if (args.providerId !== "ollama") return void 0;
|
|
@@ -13470,7 +13504,7 @@ function abortError2(signal) {
|
|
|
13470
13504
|
// src/internal/llm/vertex-anthropic.ts
|
|
13471
13505
|
init_errors();
|
|
13472
13506
|
|
|
13473
|
-
// src/internal/
|
|
13507
|
+
// src/internal/error-mappers/vertex.ts
|
|
13474
13508
|
init_errors();
|
|
13475
13509
|
var VERTEX_RULES = [
|
|
13476
13510
|
{ test: (s, e) => s === 429 || e === "RESOURCE_EXHAUSTED", code: "rate_limit" },
|
|
@@ -14013,6 +14047,16 @@ function resolveMcpCwd(configCwd) {
|
|
|
14013
14047
|
return safePathJoin(process.cwd(), configCwd);
|
|
14014
14048
|
}
|
|
14015
14049
|
|
|
14050
|
+
// src/internal/providers/register-plugin-providers.ts
|
|
14051
|
+
function registerPluginProviderProfiles(entries) {
|
|
14052
|
+
let registered4 = 0;
|
|
14053
|
+
for (const entry of entries) {
|
|
14054
|
+
registerProvider(entry.profile);
|
|
14055
|
+
registered4 += 1;
|
|
14056
|
+
}
|
|
14057
|
+
return registered4;
|
|
14058
|
+
}
|
|
14059
|
+
|
|
14016
14060
|
// src/internal/tool-registry/personality-filter.ts
|
|
14017
14061
|
init_hooks_source();
|
|
14018
14062
|
function applyPersonalityFilter(exposedTools, whitelist, opts) {
|
|
@@ -14089,12 +14133,27 @@ function createRealLocalRun(options) {
|
|
|
14089
14133
|
registerRun(handle);
|
|
14090
14134
|
return handle;
|
|
14091
14135
|
}
|
|
14092
|
-
|
|
14136
|
+
var pluginProvidersAnnounced = false;
|
|
14137
|
+
function resolveRunProvider(options) {
|
|
14093
14138
|
registerBuiltins();
|
|
14139
|
+
const profiles = options.pluginManager?.aggregated.providerProfiles ?? [];
|
|
14140
|
+
const registered4 = registerPluginProviderProfiles(profiles);
|
|
14141
|
+
if (registered4 > 0 && !pluginProvidersAnnounced) {
|
|
14142
|
+
pluginProvidersAnnounced = true;
|
|
14143
|
+
const names = profiles.map((e) => e.profile.name).join(", ");
|
|
14144
|
+
process.stderr.write(
|
|
14145
|
+
`[theokit-sdk] registered ${registered4} plugin provider profile(s): ${names}
|
|
14146
|
+
`
|
|
14147
|
+
);
|
|
14148
|
+
}
|
|
14094
14149
|
const parsedModel = parseModelId(options.model?.id);
|
|
14095
14150
|
const inferredProvider = parsedModel.provider !== void 0 && getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
|
|
14096
14151
|
const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? inferredProvider ?? detectPrimaryProvider();
|
|
14097
14152
|
const effectiveModelId = inferredProvider !== void 0 ? parsedModel.name : options.model?.id ?? "claude-sonnet-4-6";
|
|
14153
|
+
return { primary, effectiveModelId };
|
|
14154
|
+
}
|
|
14155
|
+
function buildLoopInputs(options, runId, userText) {
|
|
14156
|
+
const { primary, effectiveModelId } = resolveRunProvider(options);
|
|
14098
14157
|
const fallback = options.agentOptions.providers?.fallback;
|
|
14099
14158
|
const apiKeys = options.agentOptions.providers?.apiKeys;
|
|
14100
14159
|
const credentialPoolStrategy = options.agentOptions.providers?.credentialPoolStrategy;
|
|
@@ -14684,7 +14743,7 @@ async function embedTexts(input) {
|
|
|
14684
14743
|
pending
|
|
14685
14744
|
});
|
|
14686
14745
|
}
|
|
14687
|
-
await
|
|
14746
|
+
await embedInBoundedBatches(input, pending, results);
|
|
14688
14747
|
return results.map((v) => v ?? new Array(dimension).fill(0));
|
|
14689
14748
|
}
|
|
14690
14749
|
function classifyEntry(args) {
|
|
@@ -14703,45 +14762,34 @@ function classifyEntry(args) {
|
|
|
14703
14762
|
args.pending.push({ index: args.index, text: args.text, key: key2 });
|
|
14704
14763
|
}
|
|
14705
14764
|
var MAX_CONCURRENT_BATCHES = 3;
|
|
14706
|
-
async function
|
|
14765
|
+
async function embedInBoundedBatches(input, pending, results) {
|
|
14707
14766
|
const batches = [];
|
|
14708
14767
|
for (let offset = 0; offset < pending.length; offset += MAX_BATCH) {
|
|
14709
14768
|
batches.push(pending.slice(offset, offset + MAX_BATCH));
|
|
14710
14769
|
}
|
|
14711
|
-
|
|
14712
|
-
|
|
14713
|
-
|
|
14714
|
-
|
|
14715
|
-
|
|
14716
|
-
running++;
|
|
14717
|
-
}
|
|
14718
|
-
function release() {
|
|
14719
|
-
running--;
|
|
14720
|
-
if (queue.length > 0) queue.shift()();
|
|
14721
|
-
}
|
|
14770
|
+
await mapWithConcurrency(
|
|
14771
|
+
batches,
|
|
14772
|
+
MAX_CONCURRENT_BATCHES,
|
|
14773
|
+
(batch) => processBatch(input, batch, results)
|
|
14774
|
+
);
|
|
14722
14775
|
}
|
|
14723
|
-
async function processBatch(input, batch, results
|
|
14724
|
-
await
|
|
14725
|
-
|
|
14726
|
-
|
|
14727
|
-
|
|
14728
|
-
|
|
14729
|
-
|
|
14730
|
-
|
|
14731
|
-
|
|
14732
|
-
|
|
14733
|
-
|
|
14734
|
-
|
|
14735
|
-
|
|
14736
|
-
|
|
14737
|
-
|
|
14738
|
-
|
|
14739
|
-
|
|
14740
|
-
results[slot.index] = vector;
|
|
14741
|
-
input.cache.set(slot.key, vector);
|
|
14742
|
-
}
|
|
14743
|
-
} finally {
|
|
14744
|
-
release();
|
|
14776
|
+
async function processBatch(input, batch, results) {
|
|
14777
|
+
const vectors = await embedBatch({
|
|
14778
|
+
apiKey: input.apiKey,
|
|
14779
|
+
baseUrl: input.baseUrl,
|
|
14780
|
+
embeddingsPath: input.embeddingsPath,
|
|
14781
|
+
model: input.model,
|
|
14782
|
+
inputs: batch.map((b) => b.text),
|
|
14783
|
+
fetchImpl: input.fetchImpl,
|
|
14784
|
+
stats: input.stats,
|
|
14785
|
+
providerId: input.providerId
|
|
14786
|
+
});
|
|
14787
|
+
for (let j = 0; j < batch.length; j++) {
|
|
14788
|
+
const slot = batch[j];
|
|
14789
|
+
const vector = vectors[j];
|
|
14790
|
+
if (slot === void 0 || vector === void 0) continue;
|
|
14791
|
+
results[slot.index] = vector;
|
|
14792
|
+
input.cache.set(slot.key, vector);
|
|
14745
14793
|
}
|
|
14746
14794
|
}
|
|
14747
14795
|
async function embedBatch(opts) {
|
|
@@ -15787,8 +15835,8 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
15787
15835
|
async function* wrap() {
|
|
15788
15836
|
const { runUntilImpl: runUntilImpl2 } = await Promise.resolve().then(() => (init_run_until(), run_until_exports));
|
|
15789
15837
|
const { judgeCallImpl: judgeCallImpl2 } = await Promise.resolve().then(() => (init_judge_call(), judge_call_exports));
|
|
15790
|
-
const {
|
|
15791
|
-
const create =
|
|
15838
|
+
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
15839
|
+
const create = getAgentFacade2().create;
|
|
15792
15840
|
const deps = {
|
|
15793
15841
|
judge: async (ctx, opts) => judgeCallImpl2(ctx, opts, { create })
|
|
15794
15842
|
};
|
|
@@ -15798,9 +15846,9 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
15798
15846
|
}
|
|
15799
15847
|
async function localAgentFork(parent, options) {
|
|
15800
15848
|
const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
|
|
15801
|
-
const {
|
|
15849
|
+
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
15802
15850
|
const { withPersonalityContext: withPersonalityContext2 } = await Promise.resolve().then(() => (init_context(), context_exports));
|
|
15803
|
-
const create =
|
|
15851
|
+
const create = getAgentFacade2().create;
|
|
15804
15852
|
return withPersonalityContext2(
|
|
15805
15853
|
{ slug: parent.personalitySlugSnapshot, isFork: true },
|
|
15806
15854
|
() => forkAgentImpl2(parent, options, { create })
|
|
@@ -15821,7 +15869,7 @@ async function persistMemoryFactIfWritePrompt(workspaceCwd, memoryConfig, userTe
|
|
|
15821
15869
|
// src/internal/runtime/local-agent/local-agent-send.ts
|
|
15822
15870
|
init_errors();
|
|
15823
15871
|
|
|
15824
|
-
// src/internal/runtime/abort-utils.ts
|
|
15872
|
+
// src/internal/runtime/concurrency/abort-utils.ts
|
|
15825
15873
|
function anySignal(signals) {
|
|
15826
15874
|
const filtered = signals.filter((s) => s !== void 0);
|
|
15827
15875
|
if (filtered.length === 0) {
|
|
@@ -16850,7 +16898,13 @@ async function getOrCreateUncached(agentId, options) {
|
|
|
16850
16898
|
throw err;
|
|
16851
16899
|
}
|
|
16852
16900
|
}
|
|
16853
|
-
|
|
16901
|
+
setAgentFacade({
|
|
16902
|
+
create: (options) => Agent.create(options),
|
|
16903
|
+
prompt: (message, options) => Agent.prompt(message, options),
|
|
16904
|
+
get: (agentId) => Agent.get(agentId),
|
|
16905
|
+
resume: (agentId, options) => Agent.resume(agentId, options),
|
|
16906
|
+
batch: (prompts, options) => Agent.batch(prompts, options)
|
|
16907
|
+
});
|
|
16854
16908
|
|
|
16855
16909
|
// src/agent-factory.ts
|
|
16856
16910
|
function createAgentFactory(common) {
|
|
@@ -17288,6 +17342,7 @@ init_errors();
|
|
|
17288
17342
|
|
|
17289
17343
|
// src/internal/cron/run-job.ts
|
|
17290
17344
|
init_errors();
|
|
17345
|
+
init_agent_factory_registry();
|
|
17291
17346
|
async function runCronJob(job) {
|
|
17292
17347
|
if (job.agent !== void 0) return runWithEphemeralAgent(job.agent, job.message);
|
|
17293
17348
|
if (job.agentId !== void 0) return runWithExistingAgent(job.agentId, job.message);
|
|
@@ -17296,18 +17351,18 @@ async function runCronJob(job) {
|
|
|
17296
17351
|
});
|
|
17297
17352
|
}
|
|
17298
17353
|
async function runWithExistingAgent(agentId, message) {
|
|
17299
|
-
const info = await
|
|
17354
|
+
const info = await getAgentFacade().get(agentId).catch(() => void 0);
|
|
17300
17355
|
if (info === void 0) {
|
|
17301
17356
|
throw new exports.UnknownAgentError(
|
|
17302
17357
|
`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.`,
|
|
17303
17358
|
{ code: "agent_not_registered" }
|
|
17304
17359
|
);
|
|
17305
17360
|
}
|
|
17306
|
-
const agent = await
|
|
17361
|
+
const agent = await getAgentFacade().resume(agentId);
|
|
17307
17362
|
return agent.send(message);
|
|
17308
17363
|
}
|
|
17309
17364
|
async function runWithEphemeralAgent(baseOptions, message) {
|
|
17310
|
-
const agent = await
|
|
17365
|
+
const agent = await getAgentFacade().create(baseOptions);
|
|
17311
17366
|
return agent.send(message);
|
|
17312
17367
|
}
|
|
17313
17368
|
|
|
@@ -17695,6 +17750,16 @@ async function updateJobStatus(jobId, enabled) {
|
|
|
17695
17750
|
return updated;
|
|
17696
17751
|
}
|
|
17697
17752
|
|
|
17753
|
+
// src/define-provider.ts
|
|
17754
|
+
function defineProvider(profile, opts) {
|
|
17755
|
+
return {
|
|
17756
|
+
name: profile.name,
|
|
17757
|
+
version: opts?.version ?? "1.0.0",
|
|
17758
|
+
kind: "model-provider",
|
|
17759
|
+
profile
|
|
17760
|
+
};
|
|
17761
|
+
}
|
|
17762
|
+
|
|
17698
17763
|
// src/define-tool.ts
|
|
17699
17764
|
init_to_json_schema();
|
|
17700
17765
|
function defineTool(spec) {
|
|
@@ -19225,10 +19290,12 @@ exports.createCounterBudgetTracker = createCounterBudgetTracker;
|
|
|
19225
19290
|
exports.createNoopMemoryProvider = createNoopMemoryProvider;
|
|
19226
19291
|
exports.createSquad = createSquad;
|
|
19227
19292
|
exports.definePlugin = definePlugin;
|
|
19293
|
+
exports.defineProvider = defineProvider;
|
|
19228
19294
|
exports.defineTool = defineTool;
|
|
19229
19295
|
exports.extractRawId = extractRawId;
|
|
19230
19296
|
exports.getPricingEntry = getPricingEntry;
|
|
19231
19297
|
exports.inferApiMode = inferApiMode;
|
|
19298
|
+
exports.isTransientError = isTransientError;
|
|
19232
19299
|
exports.migrateSqliteToLance = migrateSqliteToLance2;
|
|
19233
19300
|
exports.mkMemoryId = mkMemoryId;
|
|
19234
19301
|
exports.normalizeUsage = normalizeUsage;
|