@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.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { createHash, randomUUID, randomBytes } from 'crypto';
|
|
1
2
|
import { existsSync, rmSync, mkdirSync, renameSync, readFileSync, realpathSync, lstatSync, readlinkSync, readdirSync } from 'fs';
|
|
2
3
|
import { join, dirname, relative, resolve, sep, isAbsolute } from 'path';
|
|
3
|
-
import {
|
|
4
|
-
import { readFile, stat, rm, readdir, mkdir, appendFile, rename, open, unlink, statfs, access } from 'fs/promises';
|
|
4
|
+
import { readFile, stat, rm, readdir, mkdir, appendFile, open, rename, unlink, statfs, access } from 'fs/promises';
|
|
5
5
|
import { z, toJSONSchema } from 'zod';
|
|
6
6
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
7
7
|
import { createRequire } from 'module';
|
|
@@ -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;
|
|
@@ -176,7 +194,8 @@ __export(errors_exports, {
|
|
|
176
194
|
UnsupportedBudgetOperationError: () => UnsupportedBudgetOperationError,
|
|
177
195
|
UnsupportedRunOperationError: () => UnsupportedRunOperationError,
|
|
178
196
|
UnsupportedTaskOperationError: () => UnsupportedTaskOperationError,
|
|
179
|
-
coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode
|
|
197
|
+
coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode,
|
|
198
|
+
isTransientError: () => isTransientError
|
|
180
199
|
});
|
|
181
200
|
function coerceToKnownAgentRunErrorCode(code) {
|
|
182
201
|
if (code !== void 0 && KNOWN_AGENT_RUN_ERROR_CODES.has(code)) {
|
|
@@ -208,21 +227,13 @@ function safeStringify(value) {
|
|
|
208
227
|
return String(value);
|
|
209
228
|
}
|
|
210
229
|
}
|
|
211
|
-
function
|
|
212
|
-
|
|
213
|
-
case "rate_limit":
|
|
214
|
-
case "timeout":
|
|
215
|
-
case "server_error":
|
|
216
|
-
case "network":
|
|
217
|
-
case "provider_unreachable":
|
|
218
|
-
return true;
|
|
219
|
-
default:
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
230
|
+
function isTransientError(err) {
|
|
231
|
+
return err instanceof TheokitAgentError && err.isRetryable === true;
|
|
222
232
|
}
|
|
223
233
|
var KNOWN_AGENT_RUN_ERROR_CODES, TheokitAgentError, AuthenticationError, RateLimitError, ConfigurationError, IntegrationNotConnectedError, NetworkError, UnknownAgentError, AgentRunError, UnsupportedRunOperationError, CredentialPoolExhaustedError, MemoryAdapterError, InvalidTaskIdError, TaskNotFoundError, UnsupportedTaskOperationError, BudgetExceededError, AgentDisposedError, UnsupportedBudgetOperationError;
|
|
224
234
|
var init_errors = __esm({
|
|
225
235
|
"src/errors.ts"() {
|
|
236
|
+
init_default_retriable();
|
|
226
237
|
init_redact();
|
|
227
238
|
KNOWN_AGENT_RUN_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
228
239
|
"rate_limit",
|
|
@@ -646,6 +657,19 @@ function sanitizeIdentifier(input, options) {
|
|
|
646
657
|
}
|
|
647
658
|
return input.toLowerCase();
|
|
648
659
|
}
|
|
660
|
+
function safeFilenameForId(id, options) {
|
|
661
|
+
if (id.length === 0) {
|
|
662
|
+
throw new ConfigurationError("Filename id must be a non-empty string", {
|
|
663
|
+
code: "invalid_filename_id"
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
const maxLen = options?.maxLen;
|
|
667
|
+
const lower = id.toLowerCase();
|
|
668
|
+
if (lower.length <= maxLen && IDENTIFIER_PATTERN.test(lower)) {
|
|
669
|
+
return lower;
|
|
670
|
+
}
|
|
671
|
+
return `h-${createHash("sha256").update(id).digest("hex").slice(0, 16)}`;
|
|
672
|
+
}
|
|
649
673
|
var PathTraversalError, IDENTIFIER_PATTERN;
|
|
650
674
|
var init_path_guard = __esm({
|
|
651
675
|
"src/internal/security/path-guard.ts"() {
|
|
@@ -1048,10 +1072,7 @@ function sessionsDir(cwd) {
|
|
|
1048
1072
|
return join(memoryDir(cwd), "sessions");
|
|
1049
1073
|
}
|
|
1050
1074
|
function sessionSummaryPath(cwd, runId) {
|
|
1051
|
-
return join(sessionsDir(cwd), `${
|
|
1052
|
-
}
|
|
1053
|
-
function sanitizeRunId(runId) {
|
|
1054
|
-
return runId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 128);
|
|
1075
|
+
return join(sessionsDir(cwd), `${safeFilenameForId(runId, { maxLen: 128 })}.md`);
|
|
1055
1076
|
}
|
|
1056
1077
|
function truncate(text) {
|
|
1057
1078
|
if (text.length <= MAX_TURN_CHARS) return text;
|
|
@@ -1087,6 +1108,7 @@ var MAX_TURN_CHARS;
|
|
|
1087
1108
|
var init_session_summary_writer = __esm({
|
|
1088
1109
|
"src/internal/memory/storage/session-summary-writer.ts"() {
|
|
1089
1110
|
init_atomic_write();
|
|
1111
|
+
init_path_guard();
|
|
1090
1112
|
init_types();
|
|
1091
1113
|
init_markdown_store();
|
|
1092
1114
|
MAX_TURN_CHARS = 2e3;
|
|
@@ -1116,6 +1138,49 @@ var init_async_local_storage = __esm({
|
|
|
1116
1138
|
}
|
|
1117
1139
|
});
|
|
1118
1140
|
|
|
1141
|
+
// src/internal/runtime/concurrency/async-semaphore.ts
|
|
1142
|
+
function createSemaphore(permits) {
|
|
1143
|
+
if (!Number.isInteger(permits) || permits < 1) {
|
|
1144
|
+
throw new ConfigurationError(
|
|
1145
|
+
`async-semaphore: permits must be a positive integer, got ${permits}`,
|
|
1146
|
+
{ code: "invalid_concurrency" }
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1149
|
+
let active = 0;
|
|
1150
|
+
const queue = [];
|
|
1151
|
+
function tryGrant() {
|
|
1152
|
+
if (active < permits && queue.length > 0) {
|
|
1153
|
+
const resolve3 = queue.shift();
|
|
1154
|
+
if (resolve3 !== void 0) {
|
|
1155
|
+
active += 1;
|
|
1156
|
+
resolve3();
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return {
|
|
1161
|
+
inFlight: () => active,
|
|
1162
|
+
pending: () => queue.length + active,
|
|
1163
|
+
async acquire() {
|
|
1164
|
+
await new Promise((resolve3) => {
|
|
1165
|
+
queue.push(resolve3);
|
|
1166
|
+
tryGrant();
|
|
1167
|
+
});
|
|
1168
|
+
let released = false;
|
|
1169
|
+
return () => {
|
|
1170
|
+
if (released) return;
|
|
1171
|
+
released = true;
|
|
1172
|
+
active -= 1;
|
|
1173
|
+
tryGrant();
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
var init_async_semaphore = __esm({
|
|
1179
|
+
"src/internal/runtime/concurrency/async-semaphore.ts"() {
|
|
1180
|
+
init_errors();
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1119
1184
|
// src/internal/llm/credential-pool-types.ts
|
|
1120
1185
|
var COOLDOWN_MS, DEFAULT_COOLDOWN_MS;
|
|
1121
1186
|
var init_credential_pool_types = __esm({
|
|
@@ -1497,6 +1562,61 @@ var init_sqlite_wal = __esm({
|
|
|
1497
1562
|
warnedLabels = /* @__PURE__ */ new Set();
|
|
1498
1563
|
}
|
|
1499
1564
|
});
|
|
1565
|
+
async function openSqliteResilient(options) {
|
|
1566
|
+
await mkdir(dirname(options.filePath), { recursive: true });
|
|
1567
|
+
try {
|
|
1568
|
+
return await openConcrete(options);
|
|
1569
|
+
} catch (cause) {
|
|
1570
|
+
if (options.recoverCorrupt !== false && isCorruptionError(cause)) {
|
|
1571
|
+
await renameAside(options.filePath, options.label ?? "sqlite");
|
|
1572
|
+
return await openConcrete(options);
|
|
1573
|
+
}
|
|
1574
|
+
throw cause;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
async function openConcrete(options) {
|
|
1578
|
+
const db = await loadDriver(options.filePath);
|
|
1579
|
+
applyWalWithFallback(db, options.label ?? "sqlite");
|
|
1580
|
+
await options.onOpen?.(db);
|
|
1581
|
+
return db;
|
|
1582
|
+
}
|
|
1583
|
+
async function loadDriver(filePath) {
|
|
1584
|
+
try {
|
|
1585
|
+
const mod = await import('better-sqlite3');
|
|
1586
|
+
const Ctor = mod.default ?? mod;
|
|
1587
|
+
if (typeof Ctor !== "function") {
|
|
1588
|
+
throw new Error(`better-sqlite3 export is not a constructor (got ${typeof Ctor})`);
|
|
1589
|
+
}
|
|
1590
|
+
return new Ctor(filePath);
|
|
1591
|
+
} catch (cause) {
|
|
1592
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
1593
|
+
throw new ConfigurationError(
|
|
1594
|
+
`Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
|
|
1595
|
+
{ code: "sqlite_driver_unavailable", cause }
|
|
1596
|
+
);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
function isCorruptionError(cause) {
|
|
1600
|
+
if (!(cause instanceof Error)) return false;
|
|
1601
|
+
const msg = cause.message.toLowerCase();
|
|
1602
|
+
return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
|
|
1603
|
+
}
|
|
1604
|
+
async function renameAside(filePath, label) {
|
|
1605
|
+
const asidePath = `${filePath}.corrupt-${Date.now()}`;
|
|
1606
|
+
await rename(filePath, asidePath).catch(() => void 0);
|
|
1607
|
+
await rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
|
|
1608
|
+
await rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
|
|
1609
|
+
process.stderr.write(
|
|
1610
|
+
`[theokit-sdk] ${label} database corrupt; renamed aside to ${asidePath} and rebuilt schema
|
|
1611
|
+
`
|
|
1612
|
+
);
|
|
1613
|
+
}
|
|
1614
|
+
var init_sqlite_open = __esm({
|
|
1615
|
+
"src/internal/persistence/sqlite-open.ts"() {
|
|
1616
|
+
init_errors();
|
|
1617
|
+
init_sqlite_wal();
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1500
1620
|
|
|
1501
1621
|
// src/internal/memory/index-schema.ts
|
|
1502
1622
|
var SCHEMA_STATEMENTS, PRAGMA_STATEMENTS;
|
|
@@ -1544,60 +1664,22 @@ var init_index_schema = __esm({
|
|
|
1544
1664
|
}
|
|
1545
1665
|
});
|
|
1546
1666
|
async function openMemoryDb(opts) {
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1667
|
+
return openSqliteResilient({
|
|
1668
|
+
filePath: opts.filePath,
|
|
1669
|
+
label: "memory-index",
|
|
1670
|
+
recoverCorrupt: opts.recoverCorrupt,
|
|
1671
|
+
onOpen: (db) => {
|
|
1672
|
+
for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
|
|
1673
|
+
for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
|
|
1554
1674
|
}
|
|
1555
|
-
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
async function openConcrete(filePath) {
|
|
1559
|
-
const db = await loadDriver(filePath);
|
|
1560
|
-
applyWalWithFallback(db, "memory-index");
|
|
1561
|
-
for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
|
|
1562
|
-
for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
|
|
1563
|
-
return db;
|
|
1564
|
-
}
|
|
1565
|
-
async function loadDriver(filePath) {
|
|
1566
|
-
try {
|
|
1567
|
-
const mod = await import('better-sqlite3');
|
|
1568
|
-
const Ctor = mod.default ?? mod;
|
|
1569
|
-
const db = new Ctor(filePath);
|
|
1570
|
-
return db;
|
|
1571
|
-
} catch (cause) {
|
|
1572
|
-
const message = cause instanceof Error ? cause.message : String(cause);
|
|
1573
|
-
throw new ConfigurationError(
|
|
1574
|
-
`Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
|
|
1575
|
-
{ code: "sqlite_driver_unavailable", cause }
|
|
1576
|
-
);
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
function isCorruptionError(cause) {
|
|
1580
|
-
if (!(cause instanceof Error)) return false;
|
|
1581
|
-
const msg = cause.message.toLowerCase();
|
|
1582
|
-
return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
|
|
1583
|
-
}
|
|
1584
|
-
async function renameAside(filePath) {
|
|
1585
|
-
const asidePath = `${filePath}.corrupt-${Date.now()}`;
|
|
1586
|
-
await rename(filePath, asidePath).catch(() => void 0);
|
|
1587
|
-
await rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
|
|
1588
|
-
await rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
|
|
1589
|
-
process.stderr.write(
|
|
1590
|
-
`[theokit-sdk] memory index corrupt; renamed aside to ${asidePath} and rebuilt schema
|
|
1591
|
-
`
|
|
1592
|
-
);
|
|
1675
|
+
});
|
|
1593
1676
|
}
|
|
1594
1677
|
function defaultIndexPath(cwd) {
|
|
1595
1678
|
return join(cwd, ".theokit", "memory", ".index", "memory.sqlite");
|
|
1596
1679
|
}
|
|
1597
1680
|
var init_index_db = __esm({
|
|
1598
1681
|
"src/internal/memory/index-db.ts"() {
|
|
1599
|
-
|
|
1600
|
-
init_sqlite_wal();
|
|
1682
|
+
init_sqlite_open();
|
|
1601
1683
|
init_index_schema();
|
|
1602
1684
|
}
|
|
1603
1685
|
});
|
|
@@ -2797,49 +2879,6 @@ var init_task = __esm({
|
|
|
2797
2879
|
}
|
|
2798
2880
|
});
|
|
2799
2881
|
|
|
2800
|
-
// src/internal/runtime/concurrency/async-semaphore.ts
|
|
2801
|
-
function createSemaphore(permits) {
|
|
2802
|
-
if (!Number.isInteger(permits) || permits < 1) {
|
|
2803
|
-
throw new ConfigurationError(
|
|
2804
|
-
`async-semaphore: permits must be a positive integer, got ${permits}`,
|
|
2805
|
-
{ code: "invalid_concurrency" }
|
|
2806
|
-
);
|
|
2807
|
-
}
|
|
2808
|
-
let active = 0;
|
|
2809
|
-
const queue = [];
|
|
2810
|
-
function tryGrant() {
|
|
2811
|
-
if (active < permits && queue.length > 0) {
|
|
2812
|
-
const resolve3 = queue.shift();
|
|
2813
|
-
if (resolve3 !== void 0) {
|
|
2814
|
-
active += 1;
|
|
2815
|
-
resolve3();
|
|
2816
|
-
}
|
|
2817
|
-
}
|
|
2818
|
-
}
|
|
2819
|
-
return {
|
|
2820
|
-
inFlight: () => active,
|
|
2821
|
-
pending: () => queue.length + active,
|
|
2822
|
-
async acquire() {
|
|
2823
|
-
await new Promise((resolve3) => {
|
|
2824
|
-
queue.push(resolve3);
|
|
2825
|
-
tryGrant();
|
|
2826
|
-
});
|
|
2827
|
-
let released = false;
|
|
2828
|
-
return () => {
|
|
2829
|
-
if (released) return;
|
|
2830
|
-
released = true;
|
|
2831
|
-
active -= 1;
|
|
2832
|
-
tryGrant();
|
|
2833
|
-
};
|
|
2834
|
-
}
|
|
2835
|
-
};
|
|
2836
|
-
}
|
|
2837
|
-
var init_async_semaphore = __esm({
|
|
2838
|
-
"src/internal/runtime/concurrency/async-semaphore.ts"() {
|
|
2839
|
-
init_errors();
|
|
2840
|
-
}
|
|
2841
|
-
});
|
|
2842
|
-
|
|
2843
2882
|
// src/internal/task/ring-buffer.ts
|
|
2844
2883
|
var RingBuffer;
|
|
2845
2884
|
var init_ring_buffer = __esm({
|
|
@@ -10855,6 +10894,27 @@ async function emitTextDeltaCallback(inputs, text) {
|
|
|
10855
10894
|
// src/internal/agent-loop/tool-dispatch.ts
|
|
10856
10895
|
init_async_local_storage();
|
|
10857
10896
|
|
|
10897
|
+
// src/internal/runtime/concurrency/map-with-concurrency.ts
|
|
10898
|
+
init_async_semaphore();
|
|
10899
|
+
var NEVER_ABORT = new AbortController().signal;
|
|
10900
|
+
async function mapWithConcurrency(items, concurrency, fn, options) {
|
|
10901
|
+
const semaphore = createSemaphore(concurrency);
|
|
10902
|
+
const signal = NEVER_ABORT;
|
|
10903
|
+
return Promise.all(
|
|
10904
|
+
items.map(async (item, index) => {
|
|
10905
|
+
const release = await semaphore.acquire();
|
|
10906
|
+
try {
|
|
10907
|
+
if (signal.aborted) {
|
|
10908
|
+
throw signal.reason instanceof Error ? signal.reason : new Error("mapWithConcurrency: aborted");
|
|
10909
|
+
}
|
|
10910
|
+
return await fn(item, index, signal);
|
|
10911
|
+
} finally {
|
|
10912
|
+
release();
|
|
10913
|
+
}
|
|
10914
|
+
})
|
|
10915
|
+
);
|
|
10916
|
+
}
|
|
10917
|
+
|
|
10858
10918
|
// src/internal/tool-dispatch/repair-middleware.ts
|
|
10859
10919
|
var DECIMAL_RE = /^-?\d+(\.\d+)?$/;
|
|
10860
10920
|
function repairToolCall(raw, registry3) {
|
|
@@ -11029,38 +11089,12 @@ ${result.stderr}`.trim();
|
|
|
11029
11089
|
// src/internal/agent-loop/tool-dispatch.ts
|
|
11030
11090
|
async function dispatchTools(inputs, tools, toolCalls, events) {
|
|
11031
11091
|
const maxConcurrent = inputs.maxConcurrentTools ?? 4;
|
|
11032
|
-
return
|
|
11033
|
-
maxConcurrent,
|
|
11092
|
+
return mapWithConcurrency(
|
|
11034
11093
|
toolCalls,
|
|
11094
|
+
maxConcurrent,
|
|
11035
11095
|
(call) => dispatchSingleCall(inputs, tools, call, events)
|
|
11036
11096
|
);
|
|
11037
11097
|
}
|
|
11038
|
-
async function boundedParallel(max, items, fn) {
|
|
11039
|
-
let running = 0;
|
|
11040
|
-
const queue = [];
|
|
11041
|
-
async function acquire() {
|
|
11042
|
-
if (running < max) {
|
|
11043
|
-
running++;
|
|
11044
|
-
return;
|
|
11045
|
-
}
|
|
11046
|
-
await new Promise((resolve3) => queue.push(resolve3));
|
|
11047
|
-
running++;
|
|
11048
|
-
}
|
|
11049
|
-
function release() {
|
|
11050
|
-
running--;
|
|
11051
|
-
if (queue.length > 0) queue.shift()();
|
|
11052
|
-
}
|
|
11053
|
-
return Promise.all(
|
|
11054
|
-
items.map(async (item) => {
|
|
11055
|
-
await acquire();
|
|
11056
|
-
try {
|
|
11057
|
-
return await fn(item);
|
|
11058
|
-
} finally {
|
|
11059
|
-
release();
|
|
11060
|
-
}
|
|
11061
|
-
})
|
|
11062
|
-
);
|
|
11063
|
-
}
|
|
11064
11098
|
async function dispatchSingleCall(inputs, tools, call, events) {
|
|
11065
11099
|
const { call: workingCall, repairs } = applyRepairAndExtractCall(tools, call);
|
|
11066
11100
|
const callId = generateCallId();
|
|
@@ -14010,6 +14044,16 @@ function resolveMcpCwd(configCwd) {
|
|
|
14010
14044
|
return safePathJoin(process.cwd(), configCwd);
|
|
14011
14045
|
}
|
|
14012
14046
|
|
|
14047
|
+
// src/internal/providers/register-plugin-providers.ts
|
|
14048
|
+
function registerPluginProviderProfiles(entries) {
|
|
14049
|
+
let registered4 = 0;
|
|
14050
|
+
for (const entry of entries) {
|
|
14051
|
+
registerProvider(entry.profile);
|
|
14052
|
+
registered4 += 1;
|
|
14053
|
+
}
|
|
14054
|
+
return registered4;
|
|
14055
|
+
}
|
|
14056
|
+
|
|
14013
14057
|
// src/internal/tool-registry/personality-filter.ts
|
|
14014
14058
|
init_hooks_source();
|
|
14015
14059
|
function applyPersonalityFilter(exposedTools, whitelist, opts) {
|
|
@@ -14086,12 +14130,27 @@ function createRealLocalRun(options) {
|
|
|
14086
14130
|
registerRun(handle);
|
|
14087
14131
|
return handle;
|
|
14088
14132
|
}
|
|
14089
|
-
|
|
14133
|
+
var pluginProvidersAnnounced = false;
|
|
14134
|
+
function resolveRunProvider(options) {
|
|
14090
14135
|
registerBuiltins();
|
|
14136
|
+
const profiles = options.pluginManager?.aggregated.providerProfiles ?? [];
|
|
14137
|
+
const registered4 = registerPluginProviderProfiles(profiles);
|
|
14138
|
+
if (registered4 > 0 && !pluginProvidersAnnounced) {
|
|
14139
|
+
pluginProvidersAnnounced = true;
|
|
14140
|
+
const names = profiles.map((e) => e.profile.name).join(", ");
|
|
14141
|
+
process.stderr.write(
|
|
14142
|
+
`[theokit-sdk] registered ${registered4} plugin provider profile(s): ${names}
|
|
14143
|
+
`
|
|
14144
|
+
);
|
|
14145
|
+
}
|
|
14091
14146
|
const parsedModel = parseModelId(options.model?.id);
|
|
14092
14147
|
const inferredProvider = parsedModel.provider !== void 0 && getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
|
|
14093
14148
|
const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? inferredProvider ?? detectPrimaryProvider();
|
|
14094
14149
|
const effectiveModelId = inferredProvider !== void 0 ? parsedModel.name : options.model?.id ?? "claude-sonnet-4-6";
|
|
14150
|
+
return { primary, effectiveModelId };
|
|
14151
|
+
}
|
|
14152
|
+
function buildLoopInputs(options, runId, userText) {
|
|
14153
|
+
const { primary, effectiveModelId } = resolveRunProvider(options);
|
|
14095
14154
|
const fallback = options.agentOptions.providers?.fallback;
|
|
14096
14155
|
const apiKeys = options.agentOptions.providers?.apiKeys;
|
|
14097
14156
|
const credentialPoolStrategy = options.agentOptions.providers?.credentialPoolStrategy;
|
|
@@ -14681,7 +14740,7 @@ async function embedTexts(input) {
|
|
|
14681
14740
|
pending
|
|
14682
14741
|
});
|
|
14683
14742
|
}
|
|
14684
|
-
await
|
|
14743
|
+
await embedInBoundedBatches(input, pending, results);
|
|
14685
14744
|
return results.map((v) => v ?? new Array(dimension).fill(0));
|
|
14686
14745
|
}
|
|
14687
14746
|
function classifyEntry(args) {
|
|
@@ -14700,45 +14759,34 @@ function classifyEntry(args) {
|
|
|
14700
14759
|
args.pending.push({ index: args.index, text: args.text, key: key2 });
|
|
14701
14760
|
}
|
|
14702
14761
|
var MAX_CONCURRENT_BATCHES = 3;
|
|
14703
|
-
async function
|
|
14762
|
+
async function embedInBoundedBatches(input, pending, results) {
|
|
14704
14763
|
const batches = [];
|
|
14705
14764
|
for (let offset = 0; offset < pending.length; offset += MAX_BATCH) {
|
|
14706
14765
|
batches.push(pending.slice(offset, offset + MAX_BATCH));
|
|
14707
14766
|
}
|
|
14708
|
-
|
|
14709
|
-
|
|
14710
|
-
|
|
14711
|
-
|
|
14712
|
-
|
|
14713
|
-
running++;
|
|
14714
|
-
}
|
|
14715
|
-
function release() {
|
|
14716
|
-
running--;
|
|
14717
|
-
if (queue.length > 0) queue.shift()();
|
|
14718
|
-
}
|
|
14767
|
+
await mapWithConcurrency(
|
|
14768
|
+
batches,
|
|
14769
|
+
MAX_CONCURRENT_BATCHES,
|
|
14770
|
+
(batch) => processBatch(input, batch, results)
|
|
14771
|
+
);
|
|
14719
14772
|
}
|
|
14720
|
-
async function processBatch(input, batch, results
|
|
14721
|
-
await
|
|
14722
|
-
|
|
14723
|
-
|
|
14724
|
-
|
|
14725
|
-
|
|
14726
|
-
|
|
14727
|
-
|
|
14728
|
-
|
|
14729
|
-
|
|
14730
|
-
|
|
14731
|
-
|
|
14732
|
-
|
|
14733
|
-
|
|
14734
|
-
|
|
14735
|
-
|
|
14736
|
-
|
|
14737
|
-
results[slot.index] = vector;
|
|
14738
|
-
input.cache.set(slot.key, vector);
|
|
14739
|
-
}
|
|
14740
|
-
} finally {
|
|
14741
|
-
release();
|
|
14773
|
+
async function processBatch(input, batch, results) {
|
|
14774
|
+
const vectors = await embedBatch({
|
|
14775
|
+
apiKey: input.apiKey,
|
|
14776
|
+
baseUrl: input.baseUrl,
|
|
14777
|
+
embeddingsPath: input.embeddingsPath,
|
|
14778
|
+
model: input.model,
|
|
14779
|
+
inputs: batch.map((b) => b.text),
|
|
14780
|
+
fetchImpl: input.fetchImpl,
|
|
14781
|
+
stats: input.stats,
|
|
14782
|
+
providerId: input.providerId
|
|
14783
|
+
});
|
|
14784
|
+
for (let j = 0; j < batch.length; j++) {
|
|
14785
|
+
const slot = batch[j];
|
|
14786
|
+
const vector = vectors[j];
|
|
14787
|
+
if (slot === void 0 || vector === void 0) continue;
|
|
14788
|
+
results[slot.index] = vector;
|
|
14789
|
+
input.cache.set(slot.key, vector);
|
|
14742
14790
|
}
|
|
14743
14791
|
}
|
|
14744
14792
|
async function embedBatch(opts) {
|
|
@@ -17699,6 +17747,16 @@ async function updateJobStatus(jobId, enabled) {
|
|
|
17699
17747
|
return updated;
|
|
17700
17748
|
}
|
|
17701
17749
|
|
|
17750
|
+
// src/define-provider.ts
|
|
17751
|
+
function defineProvider(profile, opts) {
|
|
17752
|
+
return {
|
|
17753
|
+
name: profile.name,
|
|
17754
|
+
version: opts?.version ?? "1.0.0",
|
|
17755
|
+
kind: "model-provider",
|
|
17756
|
+
profile
|
|
17757
|
+
};
|
|
17758
|
+
}
|
|
17759
|
+
|
|
17702
17760
|
// src/define-tool.ts
|
|
17703
17761
|
init_to_json_schema();
|
|
17704
17762
|
function defineTool(spec) {
|
|
@@ -19208,6 +19266,6 @@ function safeStringify2(v) {
|
|
|
19208
19266
|
}
|
|
19209
19267
|
}
|
|
19210
19268
|
|
|
19211
|
-
export { Agent, AgentBuilder, AgentDisposedError, AgentRunError, AuthenticationError, Budget, BudgetExceededError, ConfigurationError, Cron, EventBus, FileSystemConversationStorage, GenerateObjectError, InMemoryConversationStorage, IntegrationNotConnectedError, InvalidTaskIdError, JobQueue, Memory, MemoryAdapterError, NetworkError, PermissionEngine, RateLimitError, Security, StreamObjectError, Task, TaskNotFoundError, Theokit, TheokitAgentError, UnknownAgentError, UnsupportedBudgetOperationError, UnsupportedRunOperationError, UnsupportedTaskOperationError, UsageAccumulator, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createSquad, definePlugin, defineTool, extractRawId, getPricingEntry, inferApiMode, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeUsage, preflightCheck, toShareGptTrajectory, withCwdMutex };
|
|
19269
|
+
export { Agent, AgentBuilder, AgentDisposedError, AgentRunError, AuthenticationError, Budget, BudgetExceededError, ConfigurationError, Cron, EventBus, FileSystemConversationStorage, GenerateObjectError, InMemoryConversationStorage, IntegrationNotConnectedError, InvalidTaskIdError, JobQueue, Memory, MemoryAdapterError, NetworkError, PermissionEngine, RateLimitError, Security, StreamObjectError, Task, TaskNotFoundError, Theokit, TheokitAgentError, UnknownAgentError, UnsupportedBudgetOperationError, UnsupportedRunOperationError, UnsupportedTaskOperationError, UsageAccumulator, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createSquad, definePlugin, defineProvider, defineTool, extractRawId, getPricingEntry, inferApiMode, isTransientError, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeUsage, preflightCheck, toShareGptTrajectory, withCwdMutex };
|
|
19212
19270
|
//# sourceMappingURL=index.js.map
|
|
19213
19271
|
//# sourceMappingURL=index.js.map
|