@theokit/sdk 2.0.1 → 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 +18 -0
- package/dist/a2a/index.cjs +232 -171
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +232 -171
- 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-DFG9-W17.d.cts → cron-CSTqNZp9.d.cts} +1 -1
- package/dist/{cron-Bj8-Aq1O.d.ts → cron-Da6vF_2y.d.ts} +1 -1
- package/dist/cron.cjs +213 -169
- 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 +213 -169
- 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 +213 -169
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +213 -169
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +231 -171
- 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 +231 -173
- package/dist/index.js.map +1 -1
- package/dist/internal/default-retriable.d.ts +1 -0
- 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/retry/with-retry.d.ts +40 -0
- package/dist/internal/security/index.cjs +1 -0
- package/dist/internal/security/index.cjs.map +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/workflow.cjs.map +1 -1
- package/dist/workflow.js.map +1 -1
- package/package.json +21 -1
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"() {
|
|
@@ -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;
|
|
@@ -1119,6 +1141,49 @@ var init_async_local_storage = __esm({
|
|
|
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
|
});
|
|
@@ -2800,49 +2882,6 @@ var init_task = __esm({
|
|
|
2800
2882
|
}
|
|
2801
2883
|
});
|
|
2802
2884
|
|
|
2803
|
-
// src/internal/runtime/concurrency/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/concurrency/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({
|
|
@@ -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) {
|
|
@@ -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();
|
|
@@ -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) {
|
|
@@ -17702,6 +17750,16 @@ async function updateJobStatus(jobId, enabled) {
|
|
|
17702
17750
|
return updated;
|
|
17703
17751
|
}
|
|
17704
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
|
+
|
|
17705
17763
|
// src/define-tool.ts
|
|
17706
17764
|
init_to_json_schema();
|
|
17707
17765
|
function defineTool(spec) {
|
|
@@ -19232,10 +19290,12 @@ exports.createCounterBudgetTracker = createCounterBudgetTracker;
|
|
|
19232
19290
|
exports.createNoopMemoryProvider = createNoopMemoryProvider;
|
|
19233
19291
|
exports.createSquad = createSquad;
|
|
19234
19292
|
exports.definePlugin = definePlugin;
|
|
19293
|
+
exports.defineProvider = defineProvider;
|
|
19235
19294
|
exports.defineTool = defineTool;
|
|
19236
19295
|
exports.extractRawId = extractRawId;
|
|
19237
19296
|
exports.getPricingEntry = getPricingEntry;
|
|
19238
19297
|
exports.inferApiMode = inferApiMode;
|
|
19298
|
+
exports.isTransientError = isTransientError;
|
|
19239
19299
|
exports.migrateSqliteToLance = migrateSqliteToLance2;
|
|
19240
19300
|
exports.mkMemoryId = mkMemoryId;
|
|
19241
19301
|
exports.normalizeUsage = normalizeUsage;
|