@theokit/sdk 4.19.1 → 4.19.2
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/dist/cron-Bhdyjl0B.d.ts +2582 -0
- package/dist/cron-M2Xz7lq2.d.cts +2582 -0
- package/dist/cron.cjs +40 -20
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +3 -0
- package/dist/cron.d.ts +3 -0
- package/dist/cron.js +40 -20
- package/dist/cron.js.map +1 -1
- package/dist/errors-CG2RpeW-.d.ts +516 -0
- package/dist/errors-gE8612p9.d.cts +516 -0
- package/dist/errors.d.cts +3 -0
- package/dist/eval.cjs +40 -20
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +40 -20
- package/dist/eval.js.map +1 -1
- package/dist/goal-loop.d.ts +35 -0
- package/dist/index.cjs +160 -142
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2309 -0
- package/dist/index.d.ts +2309 -0
- package/dist/index.js +160 -142
- package/dist/index.js.map +1 -1
- package/dist/internal/persistence/index.cjs +3 -1
- package/dist/internal/persistence/index.cjs.map +1 -1
- package/dist/internal/persistence/index.js +3 -1
- package/dist/internal/persistence/index.js.map +1 -1
- package/dist/internal/runtime/lifecycle/run-until.d.ts +1 -1
- package/dist/persistence.cjs +3 -1
- package/dist/persistence.cjs.map +1 -1
- package/dist/persistence.js +3 -1
- package/dist/persistence.js.map +1 -1
- package/dist/provider-catalog.json +1295 -0
- package/dist/run-DFM1H2jW.d.cts +1589 -0
- package/dist/run-DFM1H2jW.d.ts +1589 -0
- package/package.json +1 -1
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { Q as RunOperation } from './run-DFM1H2jW.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Public type contract for the Budget enforcement primitive
|
|
5
|
+
* (ADRs D375, D382-D387). The runtime facade lives in `budget.ts`.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Scope of a budget — where the charge is attributed. v1 supports
|
|
11
|
+
* `process` (shared global) only; `agent` and `call` reserved for
|
|
12
|
+
* v0.2 multi-tenant scenarios.
|
|
13
|
+
*/
|
|
14
|
+
type BudgetScope = "agent" | "call" | "process";
|
|
15
|
+
/**
|
|
16
|
+
* Time window for a budget limit (D382 — UTC calendar-aligned).
|
|
17
|
+
* - `1h` is relative (last 60 minutes).
|
|
18
|
+
* - `1d` / `1w` / `30d` / `365d` are aligned to UTC calendar
|
|
19
|
+
* boundaries (UTC midnight / monday 00:00 UTC / 1st 00:00 UTC).
|
|
20
|
+
*/
|
|
21
|
+
type BudgetWindow = "1h" | "1d" | "1w" | "30d" | "365d";
|
|
22
|
+
/**
|
|
23
|
+
* Enforcement mode (D383).
|
|
24
|
+
* - `audit`: log only, never throw, never block.
|
|
25
|
+
* - `warn`: callbacks fire at 80/95/100% thresholds; no throw.
|
|
26
|
+
* - `block`: preflightCheck throws `BudgetExceededError` BEFORE LLM call
|
|
27
|
+
* when would-exceed.
|
|
28
|
+
*/
|
|
29
|
+
type BudgetMode = "audit" | "warn" | "block";
|
|
30
|
+
/** A single limit; stacked in an array (D384, ANY exceeded blocks). */
|
|
31
|
+
interface BudgetLimit {
|
|
32
|
+
readonly window: BudgetWindow;
|
|
33
|
+
readonly limitUsd: number;
|
|
34
|
+
}
|
|
35
|
+
/** Threshold event emitted at 80% and 95% in `warn` and `block` modes. */
|
|
36
|
+
interface BudgetThresholdEvent {
|
|
37
|
+
readonly budgetName: string;
|
|
38
|
+
readonly window: BudgetWindow;
|
|
39
|
+
readonly threshold: 0.8 | 0.95;
|
|
40
|
+
readonly spentUsd: number;
|
|
41
|
+
readonly limitUsd: number;
|
|
42
|
+
}
|
|
43
|
+
/** Exceed event emitted at 100% across all modes. */
|
|
44
|
+
interface BudgetExceedEvent {
|
|
45
|
+
readonly budgetName: string;
|
|
46
|
+
readonly window: BudgetWindow;
|
|
47
|
+
readonly spentUsd: number;
|
|
48
|
+
readonly limitUsd: number;
|
|
49
|
+
readonly mode: BudgetMode;
|
|
50
|
+
}
|
|
51
|
+
/** Options for `Budget.create`. */
|
|
52
|
+
interface BudgetOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Identifier. Must match grammar `^[a-z0-9][a-z0-9_-]*$` (EC-7);
|
|
55
|
+
* empty/invalid → `ConfigurationError({ code: "invalid_budget_name" })`.
|
|
56
|
+
*/
|
|
57
|
+
readonly name: string;
|
|
58
|
+
readonly scope: BudgetScope;
|
|
59
|
+
/**
|
|
60
|
+
* Stacked limits — at least one is expected for `warn`/`block`. Empty
|
|
61
|
+
* array (EC-19) is allowed → registry-only tracking, callbacks never
|
|
62
|
+
* fire.
|
|
63
|
+
*/
|
|
64
|
+
readonly limits: ReadonlyArray<BudgetLimit>;
|
|
65
|
+
/** Default `warn` (D383). */
|
|
66
|
+
readonly mode?: BudgetMode;
|
|
67
|
+
/** Fires at 80% and 95% of any limit. Caller throws are isolated (EC-8). */
|
|
68
|
+
readonly onThreshold?: (event: BudgetThresholdEvent) => void | Promise<void>;
|
|
69
|
+
/** Fires at 100%. Caller throws are isolated (EC-8). */
|
|
70
|
+
readonly onExceed?: (event: BudgetExceedEvent) => void | Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/** Returned by `Budget.create` and `Budget.get` — read-only view. */
|
|
73
|
+
interface BudgetHandle {
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly mode: BudgetMode;
|
|
76
|
+
readonly scope: BudgetScope;
|
|
77
|
+
readonly limits: ReadonlyArray<BudgetLimit>;
|
|
78
|
+
/** Snapshot spend for the given window. */
|
|
79
|
+
spentIn(window: BudgetWindow): number;
|
|
80
|
+
/** Remaining USD before the given window's limit is reached. */
|
|
81
|
+
remainingIn(window: BudgetWindow): number;
|
|
82
|
+
}
|
|
83
|
+
/** Per-window snapshot returned by `Budget.snapshot()`. */
|
|
84
|
+
interface BudgetSnapshot {
|
|
85
|
+
readonly name: string;
|
|
86
|
+
readonly window: BudgetWindow;
|
|
87
|
+
readonly spentUsd: number;
|
|
88
|
+
readonly limitUsd: number;
|
|
89
|
+
readonly ratio: number;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Finite, machine-readable error codes for provider-originated errors
|
|
94
|
+
* (ADR D66). Consumers can `switch (err.metadata?.code)` exhaustively
|
|
95
|
+
* — adding a new variant is an explicit decision + test coverage.
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
type ErrorCode = "rate_limit" | "auth_failed" | "invalid_request" | "timeout" | "server_error" | "context_too_long" | "content_filtered" | "model_unavailable" | "network" | "quota_exceeded" | "unknown";
|
|
100
|
+
/**
|
|
101
|
+
* Codes used by {@link AgentRunError} (Production-Readiness #3, ADR D311).
|
|
102
|
+
*
|
|
103
|
+
* Superset of {@link ErrorCode} extended with codes that do NOT originate
|
|
104
|
+
* from a provider HTTP response:
|
|
105
|
+
*
|
|
106
|
+
* - `quota_exceeded` — billing limit hit (provider 402 or signalled error)
|
|
107
|
+
* - `tool_runtime_error` — custom tool handler threw inside dispatch
|
|
108
|
+
* - `aborted` — caller's `AbortSignal` fired (Phase 4)
|
|
109
|
+
* - `invalid_model` — model id rejected by provider (400 "model not found")
|
|
110
|
+
* - `safety_blocked` — provider safety filter blocked req or resp
|
|
111
|
+
* - `provider_unreachable` — DNS/TCP/timeout/5xx at transport boundary
|
|
112
|
+
*
|
|
113
|
+
* The `& {}` tail keeps the literal-union ergonomics (autocomplete) while
|
|
114
|
+
* accepting any string for forward compatibility with constructor calls
|
|
115
|
+
* that pass arbitrary code values (legacy callers).
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
/**
|
|
120
|
+
* T1.1 — closed literal union for `AgentRunError.code`. The previous
|
|
121
|
+
* `(string & {})` escape hatch let arbitrary strings slip into the type
|
|
122
|
+
* surface and defeated exhaustive `switch (code)` discrimination. This is
|
|
123
|
+
* the canonical closed form. `AgentRunErrorCode` is re-aliased below for
|
|
124
|
+
* source-level back-compat.
|
|
125
|
+
*
|
|
126
|
+
* Adding a new code: append the literal here AND audit every `switch (err.code)`
|
|
127
|
+
* in callers. Type-checker enforces the audit via the `default: assertNever(code)`
|
|
128
|
+
* convention.
|
|
129
|
+
*
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
132
|
+
type KnownAgentRunErrorCode = ErrorCode | "quota_exceeded" | "tool_runtime_error" | "aborted" | "invalid_model" | "safety_blocked" | "provider_unreachable";
|
|
133
|
+
/**
|
|
134
|
+
* Back-compat alias of {@link KnownAgentRunErrorCode}. Pre-T1.1 callers that
|
|
135
|
+
* imported `AgentRunErrorCode` keep working; new code SHOULD prefer
|
|
136
|
+
* `KnownAgentRunErrorCode` to make the closed-union intent explicit.
|
|
137
|
+
*
|
|
138
|
+
* @public
|
|
139
|
+
*/
|
|
140
|
+
type AgentRunErrorCode = KnownAgentRunErrorCode;
|
|
141
|
+
/**
|
|
142
|
+
* Structured context for errors that originated from a provider HTTP
|
|
143
|
+
* call (ADR D65). Lets callers retry with the right backoff (`retryAfter`),
|
|
144
|
+
* surface actionable diagnostics (`provider`, `endpoint`), and inspect the
|
|
145
|
+
* raw response body when needed (`raw`, capped at ~2KB by the mapper).
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
interface ErrorMetadata {
|
|
150
|
+
/** Provider canonical name (e.g., `"anthropic"`, `"openai"`, `"openrouter"`, `"gemini"`). */
|
|
151
|
+
provider: string;
|
|
152
|
+
/** HTTP endpoint that failed (e.g., `"/v1/messages"`, `"/v1/chat/completions"`). */
|
|
153
|
+
endpoint: string;
|
|
154
|
+
/** Machine-readable error code (finite enum). */
|
|
155
|
+
code: ErrorCode;
|
|
156
|
+
/** HTTP status code if applicable. */
|
|
157
|
+
statusCode?: number;
|
|
158
|
+
/** Seconds to wait before retry, per provider's `retry-after` header (numeric form only). */
|
|
159
|
+
retryAfter?: number;
|
|
160
|
+
/** Raw response body for debugging (truncated to ~2KB by the mapper). */
|
|
161
|
+
raw?: unknown;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Base class for all errors thrown by `@theokit/sdk`.
|
|
165
|
+
*
|
|
166
|
+
* Use `isRetryable` to drive retry/backoff logic. `code` and `protoErrorCode`
|
|
167
|
+
* are populated for server-originated errors when available. `metadata`
|
|
168
|
+
* (ADR D65) carries structured `{ provider, endpoint, code, ... }` when
|
|
169
|
+
* the error originated from a provider HTTP call.
|
|
170
|
+
*
|
|
171
|
+
* @public
|
|
172
|
+
*/
|
|
173
|
+
declare class TheokitAgentError extends Error {
|
|
174
|
+
readonly name: string;
|
|
175
|
+
readonly isRetryable: boolean;
|
|
176
|
+
readonly code?: string;
|
|
177
|
+
readonly protoErrorCode?: string;
|
|
178
|
+
readonly metadata?: ErrorMetadata;
|
|
179
|
+
constructor(message: string, options?: {
|
|
180
|
+
isRetryable?: boolean;
|
|
181
|
+
code?: string;
|
|
182
|
+
protoErrorCode?: string;
|
|
183
|
+
cause?: unknown;
|
|
184
|
+
metadata?: ErrorMetadata;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Invalid API key, not logged in, insufficient permissions.
|
|
189
|
+
*
|
|
190
|
+
* @public
|
|
191
|
+
*/
|
|
192
|
+
declare class AuthenticationError extends TheokitAgentError {
|
|
193
|
+
readonly name: string;
|
|
194
|
+
constructor(message: string, options?: {
|
|
195
|
+
code?: string;
|
|
196
|
+
cause?: unknown;
|
|
197
|
+
metadata?: ErrorMetadata;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Too many requests or usage limits exceeded.
|
|
202
|
+
*
|
|
203
|
+
* @public
|
|
204
|
+
*/
|
|
205
|
+
declare class RateLimitError extends TheokitAgentError {
|
|
206
|
+
readonly name: string;
|
|
207
|
+
constructor(message: string, options?: {
|
|
208
|
+
code?: string;
|
|
209
|
+
cause?: unknown;
|
|
210
|
+
metadata?: ErrorMetadata;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Invalid model, bad request parameters, malformed options.
|
|
215
|
+
*
|
|
216
|
+
* @public
|
|
217
|
+
*/
|
|
218
|
+
declare class ConfigurationError extends TheokitAgentError {
|
|
219
|
+
readonly name: string;
|
|
220
|
+
constructor(message: string, options?: {
|
|
221
|
+
code?: string;
|
|
222
|
+
cause?: unknown;
|
|
223
|
+
metadata?: ErrorMetadata;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Thrown when creating a cloud agent for a repo whose SCM provider is not
|
|
228
|
+
* connected. Use `helpUrl` to point the user at the right reconnect flow.
|
|
229
|
+
*
|
|
230
|
+
* @public
|
|
231
|
+
*/
|
|
232
|
+
declare class IntegrationNotConnectedError extends ConfigurationError {
|
|
233
|
+
readonly name: string;
|
|
234
|
+
readonly provider: string;
|
|
235
|
+
readonly helpUrl: string;
|
|
236
|
+
constructor(message: string, options: {
|
|
237
|
+
provider: string;
|
|
238
|
+
helpUrl: string;
|
|
239
|
+
code?: string;
|
|
240
|
+
cause?: unknown;
|
|
241
|
+
metadata?: ErrorMetadata;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Service unavailable, timeout, transport-level failure.
|
|
246
|
+
*
|
|
247
|
+
* @public
|
|
248
|
+
*/
|
|
249
|
+
declare class NetworkError extends TheokitAgentError {
|
|
250
|
+
readonly name: string;
|
|
251
|
+
constructor(message: string, options?: {
|
|
252
|
+
code?: string;
|
|
253
|
+
cause?: unknown;
|
|
254
|
+
metadata?: ErrorMetadata;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Catch-all for unclassified server or runtime errors.
|
|
259
|
+
*
|
|
260
|
+
* @public
|
|
261
|
+
*/
|
|
262
|
+
declare class UnknownAgentError extends TheokitAgentError {
|
|
263
|
+
readonly name: string;
|
|
264
|
+
constructor(message: string, options?: {
|
|
265
|
+
code?: string;
|
|
266
|
+
cause?: unknown;
|
|
267
|
+
metadata?: ErrorMetadata;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Thrown by `Agent.prompt` (and helpers that go through `run.wait()`) when
|
|
272
|
+
* the option `{ throwOnError: true }` is set and the run terminates with
|
|
273
|
+
* `status: 'error'`. Carries the structured `RunResult.error` fields so
|
|
274
|
+
* callers can `catch` once and branch on `code` / `provider` instead of
|
|
275
|
+
* unwrapping the run.
|
|
276
|
+
*
|
|
277
|
+
* Extends {@link TheokitAgentError} per ADR D65 — no new hierarchy.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* try {
|
|
281
|
+
* await Agent.prompt(msg, { apiKey, model, throwOnError: true });
|
|
282
|
+
* } catch (err) {
|
|
283
|
+
* if (err instanceof AgentRunError && err.code === 'auth_failed') {
|
|
284
|
+
* // bad key
|
|
285
|
+
* }
|
|
286
|
+
* }
|
|
287
|
+
*
|
|
288
|
+
* @public
|
|
289
|
+
*/
|
|
290
|
+
declare class AgentRunError extends TheokitAgentError {
|
|
291
|
+
readonly name: string;
|
|
292
|
+
readonly provider?: string;
|
|
293
|
+
readonly raw?: string;
|
|
294
|
+
/** Provider's request id (`x-request-id` / `request-id` header). Useful for support tickets. */
|
|
295
|
+
readonly requestId?: string;
|
|
296
|
+
/** SDK conversation id this error was raised inside. */
|
|
297
|
+
readonly conversationId?: string;
|
|
298
|
+
constructor(message: string, options: {
|
|
299
|
+
code: AgentRunErrorCode;
|
|
300
|
+
provider?: string;
|
|
301
|
+
raw?: string;
|
|
302
|
+
requestId?: string;
|
|
303
|
+
conversationId?: string;
|
|
304
|
+
retriable?: boolean;
|
|
305
|
+
cause?: unknown;
|
|
306
|
+
metadata?: ErrorMetadata;
|
|
307
|
+
});
|
|
308
|
+
/**
|
|
309
|
+
* Production-Readiness #3 (ADR D311): alias for `isRetryable` exposed as
|
|
310
|
+
* `retriable` to match the handoff contract. Future v2 will deprecate
|
|
311
|
+
* `isRetryable` in favor of this.
|
|
312
|
+
*/
|
|
313
|
+
get retriable(): boolean;
|
|
314
|
+
/**
|
|
315
|
+
* D312: provider's `Retry-After` header in **milliseconds**. Mappers store
|
|
316
|
+
* the header value (seconds) in `metadata.retryAfter`; this getter
|
|
317
|
+
* multiplies by 1000 so the result composes with `Date.now()`/`setTimeout`.
|
|
318
|
+
*
|
|
319
|
+
* Returns `undefined` when no hint was provided. `0` is a legitimate value
|
|
320
|
+
* — use `=== undefined` check rather than truthy check.
|
|
321
|
+
*/
|
|
322
|
+
get retryAfterMs(): number | undefined;
|
|
323
|
+
/**
|
|
324
|
+
* D313 + T1.5: alias for `metadata.raw`. Provider response body for
|
|
325
|
+
* debugging. T1.5 wraps the value in `redactSecrets` at the getter
|
|
326
|
+
* boundary so secret-shaped substrings (`sk-...`, Bearer JWTs, etc.) are
|
|
327
|
+
* stripped before reaching the caller. Available but NEVER serialized
|
|
328
|
+
* into `.message` (anti-leak invariant).
|
|
329
|
+
*/
|
|
330
|
+
get providerError(): unknown;
|
|
331
|
+
/**
|
|
332
|
+
* T1.5 — sanitized JSON form. `metadata.raw` is OMITTED by default; opt
|
|
333
|
+
* in via `THEOKIT_DEBUG_RAW_ERRORS=1` to surface the (redacted) raw
|
|
334
|
+
* payload for diagnostics. Every other field stays accessible.
|
|
335
|
+
*
|
|
336
|
+
* The single env-var gate is read each call so operators can toggle at
|
|
337
|
+
* runtime without restarting the process.
|
|
338
|
+
*/
|
|
339
|
+
toJSON(): Record<string, unknown>;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Is this error transient (worth retrying)?
|
|
343
|
+
*
|
|
344
|
+
* Returns the SDK's own retryability verdict: every {@link TheokitAgentError}
|
|
345
|
+
* subclass computes `isRetryable` at construction (rate-limit / network /
|
|
346
|
+
* credential-pool-exhausted are retryable; auth / configuration / unsupported
|
|
347
|
+
* are not), so this predicate is a single source of truth rather than a
|
|
348
|
+
* re-derivation. Non-SDK errors return `false` conservatively — wrap a foreign
|
|
349
|
+
* error in the appropriate SDK error first if you want it considered transient.
|
|
350
|
+
* It never inspects `err.message`.
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* try {
|
|
354
|
+
* await agent.send(message, { throwOnError: true });
|
|
355
|
+
* } catch (err) {
|
|
356
|
+
* if (isTransientError(err)) return retryWithBackoff();
|
|
357
|
+
* throw err;
|
|
358
|
+
* }
|
|
359
|
+
*
|
|
360
|
+
* @public
|
|
361
|
+
*/
|
|
362
|
+
declare function isTransientError(err: unknown): boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Thrown when a {@link Run} or agent operation is not available on the current
|
|
365
|
+
* runtime. Check first with `run.supports(operation)`.
|
|
366
|
+
*
|
|
367
|
+
* Extends {@link TheokitAgentError} (so error-catching code that branches on
|
|
368
|
+
* `instanceof TheokitAgentError` continues to work) but is never retryable —
|
|
369
|
+
* an unsupported operation will not become supported on retry.
|
|
370
|
+
*
|
|
371
|
+
* @public
|
|
372
|
+
*/
|
|
373
|
+
declare class UnsupportedRunOperationError extends TheokitAgentError {
|
|
374
|
+
readonly name: string;
|
|
375
|
+
readonly operation: RunOperation;
|
|
376
|
+
constructor(message: string, operation: RunOperation, options?: {
|
|
377
|
+
code?: string;
|
|
378
|
+
cause?: unknown;
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Thrown when every credential in a per-provider pool is in cooldown
|
|
383
|
+
* and no healthy key is available (ADR D133). The caller's
|
|
384
|
+
* {@link import("./internal/llm/fallback-client.js").FallbackLlmClient}
|
|
385
|
+
* catches this and tries the next provider in the fallback chain.
|
|
386
|
+
*
|
|
387
|
+
* `metadata.nextRetryAt` (epoch ms) tells callers when the soonest
|
|
388
|
+
* pool entry resumes — useful for manual retry scheduling.
|
|
389
|
+
*
|
|
390
|
+
* @public
|
|
391
|
+
*/
|
|
392
|
+
declare class CredentialPoolExhaustedError extends TheokitAgentError {
|
|
393
|
+
readonly name: string;
|
|
394
|
+
readonly provider: string;
|
|
395
|
+
readonly nextRetryAt: number | undefined;
|
|
396
|
+
constructor(message: string, options: {
|
|
397
|
+
provider: string;
|
|
398
|
+
nextRetryAt?: number;
|
|
399
|
+
code?: string;
|
|
400
|
+
cause?: unknown;
|
|
401
|
+
metadata?: ErrorMetadata;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Finite error codes specific to memory adapter operations (ADR D141).
|
|
406
|
+
*
|
|
407
|
+
* @public
|
|
408
|
+
*/
|
|
409
|
+
type MemoryAdapterErrorCode = "auth_failed" | "rate_limited" | "not_found" | "network" | "invalid_input" | "unknown";
|
|
410
|
+
/**
|
|
411
|
+
* Error raised by `@theokit-memory-*` adapters. Carries `adapterId`
|
|
412
|
+
* so callers can branch on which provider failed (ADR D141).
|
|
413
|
+
*
|
|
414
|
+
* @public
|
|
415
|
+
*/
|
|
416
|
+
declare class MemoryAdapterError extends TheokitAgentError {
|
|
417
|
+
readonly name: string;
|
|
418
|
+
readonly adapterId: string;
|
|
419
|
+
constructor(message: string, options: {
|
|
420
|
+
adapterId: string;
|
|
421
|
+
code: MemoryAdapterErrorCode;
|
|
422
|
+
cause?: unknown;
|
|
423
|
+
metadata?: ErrorMetadata;
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Thrown when a user-supplied task ID violates the grammar
|
|
428
|
+
* `^[a-z0-9][a-z0-9_-]*$` (D368) OR starts with a reserved adapter
|
|
429
|
+
* prefix (`wf-` / `b-` / `cron-`, EC-5).
|
|
430
|
+
*
|
|
431
|
+
* @public
|
|
432
|
+
*/
|
|
433
|
+
declare class InvalidTaskIdError extends TheokitAgentError {
|
|
434
|
+
readonly name: string;
|
|
435
|
+
readonly taskId: string;
|
|
436
|
+
constructor(message: string, taskId: string, options?: {
|
|
437
|
+
cause?: unknown;
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Thrown when `Task.subscribe(id)` is called for a task that has been
|
|
442
|
+
* evicted, never submitted, or evicted after retention (D373).
|
|
443
|
+
*
|
|
444
|
+
* @public
|
|
445
|
+
*/
|
|
446
|
+
declare class TaskNotFoundError extends TheokitAgentError {
|
|
447
|
+
readonly name: string;
|
|
448
|
+
readonly taskId: string;
|
|
449
|
+
constructor(taskId: string, options?: {
|
|
450
|
+
cause?: unknown;
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Thrown when `CloudAgent` is asked to wrap a task (D370). Cloud
|
|
455
|
+
* task observability is deferred until Theo PaaS GA.
|
|
456
|
+
*
|
|
457
|
+
* @public
|
|
458
|
+
*/
|
|
459
|
+
declare class UnsupportedTaskOperationError extends TheokitAgentError {
|
|
460
|
+
readonly name: string;
|
|
461
|
+
readonly operation: string;
|
|
462
|
+
constructor(operation: string, options?: {
|
|
463
|
+
cause?: unknown;
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Thrown by `Budget` enforcement (ADR D386) when a `mode: "block"`
|
|
468
|
+
* budget would be exceeded by the upcoming LLM call. Caller pega
|
|
469
|
+
* tipado para retry-after-window-reset or surface to the user.
|
|
470
|
+
*
|
|
471
|
+
* @public
|
|
472
|
+
*/
|
|
473
|
+
declare class BudgetExceededError extends TheokitAgentError {
|
|
474
|
+
readonly name: string;
|
|
475
|
+
readonly budgetName: string;
|
|
476
|
+
readonly window: BudgetWindow;
|
|
477
|
+
readonly spentUsd: number;
|
|
478
|
+
readonly limitUsd: number;
|
|
479
|
+
readonly mode: BudgetMode;
|
|
480
|
+
constructor(args: {
|
|
481
|
+
budgetName: string;
|
|
482
|
+
window: BudgetWindow;
|
|
483
|
+
spentUsd: number;
|
|
484
|
+
limitUsd: number;
|
|
485
|
+
mode: BudgetMode;
|
|
486
|
+
cause?: unknown;
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Thrown when `CloudAgent.send({ budget })` is invoked (D388). Cloud
|
|
491
|
+
* budget surface waits for Theo PaaS GA.
|
|
492
|
+
*
|
|
493
|
+
* @public
|
|
494
|
+
*/
|
|
495
|
+
/**
|
|
496
|
+
* T1.6 — Thrown when a consumer calls `agent.send()` or any method
|
|
497
|
+
* on an agent that has already been `dispose()`d. Pre-T1.6 this was
|
|
498
|
+
* a generic `new Error("Agent has been disposed")` — consumers
|
|
499
|
+
* couldn't catch it without string-matching the message.
|
|
500
|
+
*
|
|
501
|
+
* @public
|
|
502
|
+
*/
|
|
503
|
+
declare class AgentDisposedError extends TheokitAgentError {
|
|
504
|
+
readonly name: string;
|
|
505
|
+
readonly agentId: string;
|
|
506
|
+
constructor(agentId: string);
|
|
507
|
+
}
|
|
508
|
+
declare class UnsupportedBudgetOperationError extends TheokitAgentError {
|
|
509
|
+
readonly name: string;
|
|
510
|
+
readonly operation: string;
|
|
511
|
+
constructor(operation: string, options?: {
|
|
512
|
+
cause?: unknown;
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export { AgentDisposedError as A, type BudgetOptions as B, ConfigurationError as C, type ErrorMetadata as E, IntegrationNotConnectedError as I, type KnownAgentRunErrorCode as K, MemoryAdapterError as M, NetworkError as N, RateLimitError as R, TheokitAgentError as T, UnknownAgentError as U, type BudgetHandle as a, type BudgetSnapshot as b, AgentRunError as c, type AgentRunErrorCode as d, AuthenticationError as e, type BudgetExceedEvent as f, BudgetExceededError as g, type BudgetLimit as h, type BudgetMode as i, type BudgetScope as j, type BudgetThresholdEvent as k, type BudgetWindow as l, type ErrorCode as m, InvalidTaskIdError as n, type MemoryAdapterErrorCode as o, TaskNotFoundError as p, UnsupportedBudgetOperationError as q, UnsupportedRunOperationError as r, UnsupportedTaskOperationError as s, isTransientError as t, CredentialPoolExhaustedError as u };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, m as ErrorCode, E as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-gE8612p9.cjs';
|
|
2
|
+
import './run-DFM1H2jW.cjs';
|
|
3
|
+
import 'zod';
|
package/dist/eval.cjs
CHANGED
|
@@ -6005,7 +6005,9 @@ function isCompactSummary(content) {
|
|
|
6005
6005
|
function plainText(content) {
|
|
6006
6006
|
if (typeof content === "string") return content;
|
|
6007
6007
|
if (!Array.isArray(content)) return void 0;
|
|
6008
|
-
const texts = content.filter(
|
|
6008
|
+
const texts = content.filter(
|
|
6009
|
+
(p) => p !== null && typeof p === "object" && p.type === "text" && typeof p.text === "string"
|
|
6010
|
+
).map((p) => p.text);
|
|
6009
6011
|
return texts.length > 0 ? texts.join("\n") : void 0;
|
|
6010
6012
|
}
|
|
6011
6013
|
async function compactSessionTranscript(opts) {
|
|
@@ -6126,8 +6128,10 @@ async function autoCompactIfNeeded(opts) {
|
|
|
6126
6128
|
return true;
|
|
6127
6129
|
} catch (cause) {
|
|
6128
6130
|
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
6129
|
-
process.stderr.write(
|
|
6130
|
-
`)
|
|
6131
|
+
process.stderr.write(
|
|
6132
|
+
`[theokit-sdk] auto-compaction failed (left transcript untouched): ${msg}
|
|
6133
|
+
`
|
|
6134
|
+
);
|
|
6131
6135
|
return false;
|
|
6132
6136
|
}
|
|
6133
6137
|
}
|
|
@@ -6137,11 +6141,11 @@ var init_compact_session = __esm({
|
|
|
6137
6141
|
init_compaction();
|
|
6138
6142
|
init_router();
|
|
6139
6143
|
init_real_local_run_provider();
|
|
6144
|
+
init_session_transcript();
|
|
6140
6145
|
init_providers();
|
|
6141
6146
|
init_compression_model_registry();
|
|
6142
6147
|
init_compression_summarizer();
|
|
6143
6148
|
init_agent_session();
|
|
6144
|
-
init_session_transcript();
|
|
6145
6149
|
COMPACT_SUMMARY_MARKER = "[[theokit:compact-summary]]";
|
|
6146
6150
|
COMPACT_USER_MESSAGE_MAX_TOKENS = 2e4;
|
|
6147
6151
|
autoCompactAttempts = (() => {
|
|
@@ -6246,10 +6250,17 @@ var init_context = __esm({
|
|
|
6246
6250
|
}
|
|
6247
6251
|
});
|
|
6248
6252
|
|
|
6253
|
+
// src/goal-loop.ts
|
|
6254
|
+
var GOAL_CONTINUATION_MARKER;
|
|
6255
|
+
var init_goal_loop = __esm({
|
|
6256
|
+
"src/goal-loop.ts"() {
|
|
6257
|
+
GOAL_CONTINUATION_MARKER = "[[theokit:goal-continuation]]";
|
|
6258
|
+
}
|
|
6259
|
+
});
|
|
6260
|
+
|
|
6249
6261
|
// src/internal/runtime/lifecycle/run-until.ts
|
|
6250
6262
|
var run_until_exports = {};
|
|
6251
6263
|
__export(run_until_exports, {
|
|
6252
|
-
GOAL_CONTINUATION_MARKER: () => GOAL_CONTINUATION_MARKER,
|
|
6253
6264
|
composeContinuation: () => composeContinuation,
|
|
6254
6265
|
runUntilImpl: () => runUntilImpl
|
|
6255
6266
|
});
|
|
@@ -6414,10 +6425,9 @@ ${goal}
|
|
|
6414
6425
|
${lastResponse.slice(-1e3)}`
|
|
6415
6426
|
].join("\n");
|
|
6416
6427
|
}
|
|
6417
|
-
var GOAL_CONTINUATION_MARKER;
|
|
6418
6428
|
var init_run_until = __esm({
|
|
6419
6429
|
"src/internal/runtime/lifecycle/run-until.ts"() {
|
|
6420
|
-
|
|
6430
|
+
init_goal_loop();
|
|
6421
6431
|
}
|
|
6422
6432
|
});
|
|
6423
6433
|
|
|
@@ -17153,7 +17163,9 @@ async function loadDriver(filePath) {
|
|
|
17153
17163
|
}
|
|
17154
17164
|
try {
|
|
17155
17165
|
const mod = await (driverLoaderOverrides?.nodeSqlite?.() ?? Promise.resolve(
|
|
17156
|
-
process.getBuiltinModule?.(
|
|
17166
|
+
process.getBuiltinModule?.(
|
|
17167
|
+
"node:sqlite"
|
|
17168
|
+
) ?? (() => {
|
|
17157
17169
|
throw new Error("node:sqlite built-in unavailable (Node < 22.3)");
|
|
17158
17170
|
})()
|
|
17159
17171
|
));
|
|
@@ -19687,8 +19699,8 @@ async function getRegisteredAgentOrThrow(agentId) {
|
|
|
19687
19699
|
// src/agent.ts
|
|
19688
19700
|
init_errors();
|
|
19689
19701
|
init_discovery();
|
|
19690
|
-
init_agent_session();
|
|
19691
19702
|
init_agent_factory_registry();
|
|
19703
|
+
init_agent_session();
|
|
19692
19704
|
var streamObjectImport;
|
|
19693
19705
|
var Agent = class _Agent {
|
|
19694
19706
|
constructor() {
|
|
@@ -19980,7 +19992,9 @@ var Agent = class _Agent {
|
|
|
19980
19992
|
reg = getRegisteredAgent(agentId);
|
|
19981
19993
|
}
|
|
19982
19994
|
if (reg === void 0 || reg.runtime !== "local") {
|
|
19983
|
-
throw new UnknownAgentError(
|
|
19995
|
+
throw new UnknownAgentError(
|
|
19996
|
+
`No local agent "${agentId}" registered \u2014 compact targets local sessions.`
|
|
19997
|
+
);
|
|
19984
19998
|
}
|
|
19985
19999
|
const cwd = reg.cwd ?? process.cwd();
|
|
19986
20000
|
const optModel = reg.options.model;
|
|
@@ -19990,16 +20004,20 @@ var Agent = class _Agent {
|
|
|
19990
20004
|
const { defaultBaseDir: defaultBaseDir2, expandTilde: expandTilde2 } = await Promise.resolve().then(() => (init_session_transcript(), session_transcript_exports));
|
|
19991
20005
|
const baseDir = reg.options.local?.baseDir !== void 0 ? expandTilde2(reg.options.local.baseDir) : defaultBaseDir2();
|
|
19992
20006
|
const store = new FsSessionStore2({ baseDir, cwd });
|
|
19993
|
-
return enqueueSessionWrite(
|
|
19994
|
-
|
|
19995
|
-
|
|
19996
|
-
|
|
19997
|
-
|
|
19998
|
-
|
|
19999
|
-
|
|
20000
|
-
|
|
20007
|
+
return enqueueSessionWrite(
|
|
20008
|
+
cwd,
|
|
20009
|
+
agentId,
|
|
20010
|
+
() => compactSessionTranscript2({
|
|
20011
|
+
store,
|
|
20012
|
+
loc: { cwd, agentId, model },
|
|
20013
|
+
sessionId: agentId,
|
|
20014
|
+
trigger: options.trigger ?? "manual",
|
|
20015
|
+
summarize: options.summarize ?? buildDefaultSummarizer2({
|
|
20016
|
+
agentModel: model,
|
|
20017
|
+
...reg.options.apiKey !== void 0 ? { apiKey: reg.options.apiKey } : {}
|
|
20018
|
+
})
|
|
20001
20019
|
})
|
|
20002
|
-
|
|
20020
|
+
);
|
|
20003
20021
|
}
|
|
20004
20022
|
/**
|
|
20005
20023
|
* M51 — inject a SYNTHETIC user+assistant pair into a LOCAL session's persisted transcript WITHOUT
|
|
@@ -20016,7 +20034,9 @@ var Agent = class _Agent {
|
|
|
20016
20034
|
reg = getRegisteredAgent(agentId);
|
|
20017
20035
|
}
|
|
20018
20036
|
if (reg === void 0 || reg.runtime !== "local") {
|
|
20019
|
-
throw new UnknownAgentError(
|
|
20037
|
+
throw new UnknownAgentError(
|
|
20038
|
+
`No local agent "${agentId}" registered \u2014 injectSessionTurn targets local sessions.`
|
|
20039
|
+
);
|
|
20020
20040
|
}
|
|
20021
20041
|
const cwd = reg.cwd ?? process.cwd();
|
|
20022
20042
|
const optModel = reg.options.model;
|