@theokit/sdk 4.27.0 → 4.29.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.
Files changed (99) hide show
  1. package/dist/{cron-DPUZzncH.d.ts → agent-BZz4X8ZM.d.ts} +10 -577
  2. package/dist/{cron-DzZ9TMa2.d.cts → agent-CdjSCbYz.d.cts} +10 -577
  3. package/dist/agent-FBTLZI6V.js +41 -0
  4. package/dist/agent-FBTLZI6V.js.map +1 -0
  5. package/dist/agent-LBCEK6VH.cjs +50 -0
  6. package/dist/agent-LBCEK6VH.cjs.map +1 -0
  7. package/dist/{chunk-WBBYSW3Q.cjs → chunk-54YLX4Q6.cjs} +5 -5
  8. package/dist/{chunk-WBBYSW3Q.cjs.map → chunk-54YLX4Q6.cjs.map} +1 -1
  9. package/dist/{chunk-AKSBP7OO.js → chunk-5IB2UKSN.js} +5 -41
  10. package/dist/chunk-5IB2UKSN.js.map +1 -0
  11. package/dist/chunk-BNIFFFH3.js +129 -0
  12. package/dist/chunk-BNIFFFH3.js.map +1 -0
  13. package/dist/{chunk-LSLPF6OI.cjs → chunk-DHLZIMP6.cjs} +5 -43
  14. package/dist/chunk-DHLZIMP6.cjs.map +1 -0
  15. package/dist/{chunk-OX772BEW.js → chunk-EULKRTB5.js} +3 -3
  16. package/dist/{chunk-OX772BEW.js.map → chunk-EULKRTB5.js.map} +1 -1
  17. package/dist/chunk-FKCC2MED.js +43 -0
  18. package/dist/chunk-FKCC2MED.js.map +1 -0
  19. package/dist/{chunk-QUTUJ6P6.cjs → chunk-HK7ZHSAX.cjs} +25 -16
  20. package/dist/chunk-HK7ZHSAX.cjs.map +1 -0
  21. package/dist/{chunk-MQLCZ4HJ.cjs → chunk-JLMXKTBX.cjs} +4 -4
  22. package/dist/{chunk-MQLCZ4HJ.cjs.map → chunk-JLMXKTBX.cjs.map} +1 -1
  23. package/dist/chunk-LALRCFSN.cjs +46 -0
  24. package/dist/chunk-LALRCFSN.cjs.map +1 -0
  25. package/dist/{chunk-DUK5WMKJ.js → chunk-R6ZP6KNB.js} +25 -16
  26. package/dist/chunk-R6ZP6KNB.js.map +1 -0
  27. package/dist/chunk-RZQ6E5YZ.cjs +131 -0
  28. package/dist/chunk-RZQ6E5YZ.cjs.map +1 -0
  29. package/dist/{chunk-6M76Z3AI.js → chunk-VUJ3NVDC.js} +692 -808
  30. package/dist/chunk-VUJ3NVDC.js.map +1 -0
  31. package/dist/{chunk-G6GO6BXD.js → chunk-XAUBQMQU.js} +3 -3
  32. package/dist/{chunk-G6GO6BXD.js.map → chunk-XAUBQMQU.js.map} +1 -1
  33. package/dist/{chunk-TMNS2LOS.cjs → chunk-YQAPEYUV.cjs} +715 -831
  34. package/dist/chunk-YQAPEYUV.cjs.map +1 -0
  35. package/dist/compact-session-OO2GD76G.js +1 -1
  36. package/dist/compact-session-OO7NVWPB.cjs +1 -1
  37. package/dist/cron-CIIshMs3.d.cts +579 -0
  38. package/dist/cron-dElBjDaL.d.ts +579 -0
  39. package/dist/cron.cjs +13 -11
  40. package/dist/cron.d.cts +2 -1
  41. package/dist/cron.d.ts +2 -1
  42. package/dist/cron.js +12 -10
  43. package/dist/errors.d.ts +3 -424
  44. package/dist/eval.cjs +17 -15
  45. package/dist/eval.cjs.map +1 -1
  46. package/dist/eval.js +13 -11
  47. package/dist/eval.js.map +1 -1
  48. package/dist/{index-manager-CB6I7XFQ.cjs → index-manager-H7HUMW52.cjs} +5 -5
  49. package/dist/{index-manager-CB6I7XFQ.cjs.map → index-manager-H7HUMW52.cjs.map} +1 -1
  50. package/dist/{index-manager-L27Q3QAC.js → index-manager-P7ZUX2RG.js} +4 -4
  51. package/dist/{index-manager-L27Q3QAC.js.map → index-manager-P7ZUX2RG.js.map} +1 -1
  52. package/dist/index.cjs +66 -45
  53. package/dist/index.cjs.map +1 -1
  54. package/dist/index.d.cts +18 -4
  55. package/dist/index.d.ts +18 -4
  56. package/dist/index.js +42 -21
  57. package/dist/index.js.map +1 -1
  58. package/dist/internal/persistence/index.cjs +10 -10
  59. package/dist/internal/persistence/index.js +2 -2
  60. package/dist/internal/persistence/jsonl.d.cts +7 -0
  61. package/dist/internal/persistence/jsonl.d.ts +7 -0
  62. package/dist/internal/persistence/session-writer.d.cts +56 -0
  63. package/dist/internal/persistence/session-writer.d.ts +56 -0
  64. package/dist/internal/persistence/transcript-ops.d.cts +71 -0
  65. package/dist/internal/persistence/transcript-ops.d.ts +71 -0
  66. package/dist/persistence.cjs +115 -12
  67. package/dist/persistence.cjs.map +1 -1
  68. package/dist/persistence.d.cts +2 -0
  69. package/dist/persistence.d.ts +2 -0
  70. package/dist/persistence.js +105 -3
  71. package/dist/persistence.js.map +1 -1
  72. package/dist/{run-until-K7IO7ZPQ.js → run-until-YZ2ODWOF.js} +3 -2
  73. package/dist/run-until-YZ2ODWOF.js.map +1 -0
  74. package/dist/{run-until-ZD4PRLNJ.cjs → run-until-ZZ2JLPJM.cjs} +3 -2
  75. package/dist/run-until-ZZ2JLPJM.cjs.map +1 -0
  76. package/dist/server/auth/index.d.cts +207 -11
  77. package/dist/server/auth/index.d.ts +207 -11
  78. package/dist/server/errors-envelope.d.cts +12 -6
  79. package/dist/server/errors-envelope.d.ts +12 -6
  80. package/dist/skills.cjs +4 -3
  81. package/dist/skills.js +2 -1
  82. package/dist/subagents-loader.cjs +19 -0
  83. package/dist/subagents-loader.cjs.map +1 -0
  84. package/dist/subagents-loader.d.cts +39 -0
  85. package/dist/subagents-loader.d.ts +39 -0
  86. package/dist/subagents-loader.js +16 -0
  87. package/dist/subagents-loader.js.map +1 -0
  88. package/dist/types/goal-events.d.ts +8 -0
  89. package/dist/workflow.cjs +1 -1
  90. package/dist/workflow.js +1 -1
  91. package/package.json +12 -2
  92. package/dist/chunk-6M76Z3AI.js.map +0 -1
  93. package/dist/chunk-AKSBP7OO.js.map +0 -1
  94. package/dist/chunk-DUK5WMKJ.js.map +0 -1
  95. package/dist/chunk-LSLPF6OI.cjs.map +0 -1
  96. package/dist/chunk-QUTUJ6P6.cjs.map +0 -1
  97. package/dist/chunk-TMNS2LOS.cjs.map +0 -1
  98. package/dist/run-until-K7IO7ZPQ.js.map +0 -1
  99. package/dist/run-until-ZD4PRLNJ.cjs.map +0 -1
@@ -1,15 +1,211 @@
1
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
+
1
3
  /**
2
- * @theokit/sdk/server/auth — public barrel
4
+ * @theokit/sdk/server/auth — typed error classes
3
5
  *
4
- * Per ADR D6 (sub-path export) consumers import via `@theokit/sdk/server/auth`
5
- * NOT main `@theokit/sdk` barrel. Tree-shaking + allows breaking changes in
6
- * auth surface without affecting Agent runtime consumers.
6
+ * Plan T1.2 + v1.1 EC-1 (AuthCancelledError for OAuth provider error response RFC 6749 §4.1.2.1).
7
+ */
8
+ /**
9
+ * Thrown at `defineAuth()` time when configuration is invalid
10
+ * (e.g., duplicate provider name, invalid email shape per EC-V1-12).
11
+ */
12
+ declare class AuthConfigError extends Error {
13
+ readonly name = "AuthConfigError";
14
+ readonly code: string;
15
+ constructor(code: string, message: string);
16
+ }
17
+ /**
18
+ * Thrown at `startSignIn(providerName, ...)` or `finishSignIn(providerName, ...)`
19
+ * when the named provider is not registered in `providers[]`.
20
+ */
21
+ declare class AuthProviderNotFoundError extends Error {
22
+ readonly name = "AuthProviderNotFoundError";
23
+ readonly providerName: string;
24
+ constructor(providerName: string);
25
+ }
26
+ /**
27
+ * Thrown during OAuth callback handling for state mismatches, expired
28
+ * transactions, missing query params, or provider 4xx/5xx errors.
29
+ *
30
+ * Typed `code` field lets consumers branch on cause:
31
+ * - 'oauth_transaction_expired' — cookie tx > 10min old (per ADR D5)
32
+ * - 'oauth_state_mismatch' — query state ≠ cookie state (CSRF defense per RFC 6749 §10.12)
33
+ * - 'oauth_provider_error' — non-access_denied error in callback URL
34
+ * - 'oauth_token_exchange_failed' — provider rejected code-for-tokens swap
35
+ * - 'oauth_userinfo_failed' — userinfo endpoint returned error
36
+ * - 'oauth_missing_code_or_state' — required query params absent
37
+ */
38
+ declare class AuthCallbackError extends Error {
39
+ readonly name: string;
40
+ readonly code: string;
41
+ constructor(code: string, message?: string);
42
+ }
43
+ /**
44
+ * Per v1.1 EC-1 MUST FIX — typed subclass of AuthCallbackError for the
45
+ * specific case where user declined consent at provider screen.
46
+ *
47
+ * OAuth 2.0 RFC 6749 §4.1.2.1: provider redirects with `?error=access_denied`.
48
+ * Apps can catch this distinctly from network/server errors to render
49
+ * "Login cancelled — try again" UX instead of opaque "callback failed".
50
+ */
51
+ declare class AuthCancelledError extends AuthCallbackError {
52
+ readonly name: string;
53
+ readonly errorDescription?: string;
54
+ constructor(errorDescription?: string);
55
+ }
56
+
57
+ /**
58
+ * @theokit/sdk/server/auth — orchestrator types (Caminho C Hybrid per G11)
59
+ *
60
+ * Plan: g11-auth-architecture-implementation v1.4 (sha256 4d381020...)
61
+ * Blueprint: g11-auth-architecture-decision v1.1 (SHIPPABLE 97.9)
62
+ * AUTH-DELEGATION lock (theokit/CLAUDE.md:217-225) — these types are the
63
+ * orchestrator contract; concrete OAuth/email providers ship in opt-in
64
+ * @theokit/auth-* packages (adapters layer per ADR D11).
65
+ */
66
+
67
+ /**
68
+ * SessionManager contract (matches theokit/packages/theo/src/server/auth/session.ts:49).
69
+ * Imported as type-only — runtime depends via peerDep `theokit@>=0.2.4`.
70
+ */
71
+ interface SessionManager<TSession> {
72
+ getSession(req: IncomingMessage): Promise<TSession | null>;
73
+ createSession(res: ServerResponse, data: TSession): Promise<void>;
74
+ destroySession(res: ServerResponse): void;
75
+ rotateSession(req: IncomingMessage, res: ServerResponse): Promise<TSession | null>;
76
+ }
77
+ /**
78
+ * Per ADR D5 — OAuth transaction state stored in encrypted HttpOnly cookie
79
+ * (cookie-state pattern). Expires within 10 minutes per invariant.
80
+ */
81
+ interface OAuthTransaction {
82
+ state: string;
83
+ pkceVerifier?: string;
84
+ returnTo?: string;
85
+ createdAt: number;
86
+ expiresAt: number;
87
+ }
88
+ /**
89
+ * Per ADR D9 — provider profile types are provider-specific (not unified).
90
+ * Each @theokit/auth-* package exports its own profile shape.
91
+ * Generic param TProfile lets consumers narrow via discriminated unions on providerName.
92
+ */
93
+ interface AuthResult<TProfile, TName extends string = string> {
94
+ profile: TProfile;
95
+ providerName: TName;
96
+ rawTokens?: {
97
+ accessToken: string;
98
+ refreshToken?: string;
99
+ idToken?: string;
100
+ expiresAt?: number;
101
+ };
102
+ }
103
+ /**
104
+ * Provider contract — each @theokit/auth-* package implements this.
105
+ * Per blueprint Q5 + ADR D11 (adapters layer).
106
+ */
107
+ interface AuthProvider<TProfile, TName extends string = string> {
108
+ name: TName;
109
+ createAuthorizationURL(tx: OAuthTransaction): URL | Promise<URL>;
110
+ handleCallback(req: IncomingMessage, tx: OAuthTransaction): Promise<AuthResult<TProfile, TName>>;
111
+ }
112
+ /**
113
+ * `defineAuth(opts)` configuration shape — Caminho C (Hybrid).
114
+ * `providers` optional: empty = Caminho A escape hatch (manual signIn only).
115
+ * `onSignIn` invoked after provider callback success; returns TSession to persist.
116
+ */
117
+ interface DefineAuthOptions<TSession> {
118
+ session: SessionManager<TSession>;
119
+ providers?: AuthProvider<unknown, string>[];
120
+ onSignIn?: <TProfile>(args: {
121
+ profile: TProfile;
122
+ provider: string;
123
+ }) => Promise<TSession>;
124
+ onSignOut?: (session: TSession | null) => Promise<void> | void;
125
+ }
126
+ /**
127
+ * Returned by `defineAuth<TSession>(opts)` — 5-method orchestrator surface.
128
+ *
129
+ * - startSignIn: returns Response.redirect to provider authorization URL with state cookie
130
+ * - finishSignIn: handles provider callback; verifies state; calls onSignIn; rotates session ID
131
+ * (OWASP A07:2021 per EC-10); creates session cookie; clears transaction cookie
132
+ * - signIn: Caminho A escape hatch — skip OAuth flow; directly persist session from external profile
133
+ * - signOut: destroys session cookie + invokes onSignOut callback
134
+ * - getSession: read-only passthrough to session.getSession
135
+ */
136
+ interface AuthOrchestrator<TSession> {
137
+ startSignIn(providerName: string, req: IncomingMessage, opts?: {
138
+ returnTo?: string;
139
+ }): Promise<Response>;
140
+ finishSignIn(providerName: string, req: IncomingMessage, res: ServerResponse): Promise<{
141
+ session: TSession;
142
+ returnTo?: string;
143
+ }>;
144
+ signIn<TProfile>(profile: TProfile, providerName: string, req: IncomingMessage, res: ServerResponse): Promise<TSession>;
145
+ signOut(res: ServerResponse): void | Promise<void>;
146
+ getSession(req: IncomingMessage): Promise<TSession | null>;
147
+ }
148
+
149
+ /**
150
+ * @theokit/sdk/server/auth — encrypted OAuth transaction cookie store
151
+ *
152
+ * Per ADR D5 — cookie-state pattern (no Redis/db dependency in core).
153
+ *
154
+ * Stores OAuthTransaction (state + pkceVerifier + returnTo + expiry) in a
155
+ * single signed+encrypted HttpOnly cookie. Stateless, works in edge/serverless.
156
+ *
157
+ * Cookie name: `__Host-theo_oauth_tx` (T5.3 — RFC 6265bis prefix)
158
+ * Lifetime: 10 minutes (per D5 invariant)
159
+ * Encryption: AES-256-GCM via Node's webcrypto subtle API
160
+ *
161
+ * Note: this is a minimal in-package implementation. Production deployments
162
+ * may prefer using `theokit/server/auth/crypto`'s encrypt/decrypt helpers
163
+ * via the SessionManager's existing secret rotation chain. For T1.2 we keep
164
+ * it self-contained to avoid cross-package peer-dep complexity; T2+ may
165
+ * refactor to share SessionManager's encrypt path.
166
+ */
167
+
168
+ /**
169
+ * T5.1 — Typed error thrown when an OAuth tx-cookie secret has < 32
170
+ * bytes of entropy. Surfaces the actual byte length so operators can
171
+ * diagnose mis-configured env vars without leaking the secret itself.
172
+ *
173
+ * @public
174
+ */
175
+ declare class AuthSecretTooShortError extends Error {
176
+ readonly name = "AuthSecretTooShortError";
177
+ constructor(actualBytes: number);
178
+ }
179
+
180
+ /**
181
+ * @theokit/sdk/server/auth — defineAuth orchestrator runtime (Caminho C Hybrid)
182
+ *
183
+ * Plan T1.2 implementation per blueprint Q5 § Caminho C signatures.
184
+ * Composes existing primitives + the v1.1 EC-1/EC-2/EC-10 fixes.
185
+ */
186
+
187
+ /** SE36 — `Auth.create` replaces `defineAuth` (ADR 0015). @public */
188
+ declare class Auth {
189
+ private constructor();
190
+ static create<TSession>(opts: DefineAuthOptions<TSession>): AuthOrchestrator<TSession>;
191
+ }
192
+
193
+ /**
194
+ * @theokit/sdk/server/auth — same-origin returnTo validator
195
+ *
196
+ * Per v1.1 EC-2 MUST FIX — OWASP A01:2021 open-redirect mitigation.
197
+ *
198
+ * Without this check, attacker craft `/login?returnTo=https://evil.com` would
199
+ * cause post-login redirect to attacker domain with authenticated session cookie.
7
200
  *
8
- * T1.1 shipped types-only.
9
- * T1.2 adds runtime: defineAuth() + 4 typed error classes + validateReturnTo helper.
201
+ * Rules:
202
+ * - undefined/empty returnTo default '/'
203
+ * - protocol-relative `//evil.com` → default '/' (URL parser would resolve to baseUrl protocol)
204
+ * - absolute URL with origin ≠ baseUrl.origin → default '/' (cross-origin redirect)
205
+ * - absolute URL with origin === baseUrl.origin → keep (same-origin allowed)
206
+ * - relative path starting with '/' → keep (same-app navigation)
207
+ * - relative path not starting with '/' → default '/' (defensive)
10
208
  */
11
- export { AuthCallbackError, AuthCancelledError, AuthConfigError, AuthProviderNotFoundError, } from "./errors.js";
12
- export { AuthSecretTooShortError } from "./oauth-transaction-store.js";
13
- export { Auth } from "./orchestrator.js";
14
- export type { AuthOrchestrator, AuthProvider, AuthResult, DefineAuthOptions, OAuthTransaction, SessionManager, } from "./types.js";
15
- export { validateReturnTo } from "./validate-return-to.js";
209
+ declare function validateReturnTo(returnTo: string | undefined, baseUrl: URL): string;
210
+
211
+ export { Auth, AuthCallbackError, AuthCancelledError, AuthConfigError, type AuthOrchestrator, type AuthProvider, AuthProviderNotFoundError, type AuthResult, AuthSecretTooShortError, type DefineAuthOptions, type OAuthTransaction, type SessionManager, validateReturnTo };
@@ -1,3 +1,8 @@
1
+ import { T as TheokitAgentError } from '../errors-BdL-buYn.cjs';
2
+ export { M as MemoryAdapterError } from '../errors-BdL-buYn.cjs';
3
+ import '../run-OJbGyweZ.cjs';
4
+ import 'zod';
5
+
1
6
  /**
2
7
  * @theokit/sdk/server/errors-envelope — G5 T2.2 boundary translation.
3
8
  *
@@ -12,7 +17,7 @@
12
17
  * dependency on `theokit`. Consumer code that uses both packages gets the
13
18
  * same shape via duck-typing.
14
19
  */
15
- import { MemoryAdapterError, TheokitAgentError } from "../errors.js";
20
+
16
21
  /**
17
22
  * Canonical envelope code union for cross-layer SDK boundary. Subset of the
18
23
  * full `TheoErrorCode` (theokit/server) covering codes the SDK actually emits.
@@ -21,13 +26,13 @@ import { MemoryAdapterError, TheokitAgentError } from "../errors.js";
21
26
  *
22
27
  * @public
23
28
  */
24
- export type TheokitErrorCode = "UNAUTHORIZED" | "RATE_LIMITED" | "INTERNAL_SERVER_ERROR" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "AGENT_RUN_ERROR" | "PROVIDER_KEY_MISSING" | "BUDGET_EXCEEDED" | "CREDENTIAL_POOL_EXHAUSTED";
29
+ type TheokitErrorCode = "UNAUTHORIZED" | "RATE_LIMITED" | "INTERNAL_SERVER_ERROR" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "AGENT_RUN_ERROR" | "PROVIDER_KEY_MISSING" | "BUDGET_EXCEEDED" | "CREDENTIAL_POOL_EXHAUSTED";
25
30
  /**
26
31
  * Envelope shape — structurally identical to theokit/server `TheoErrorEnvelope`.
27
32
  *
28
33
  * @public
29
34
  */
30
- export interface TheokitErrorEnvelope<TExt = unknown> {
35
+ interface TheokitErrorEnvelope<TExt = unknown> {
31
36
  readonly code: TheokitErrorCode;
32
37
  readonly message: string;
33
38
  readonly cause?: unknown;
@@ -49,7 +54,7 @@ export interface TheokitErrorEnvelope<TExt = unknown> {
49
54
  *
50
55
  * @public
51
56
  */
52
- export declare function toEnvelope(value: unknown): TheokitErrorEnvelope;
57
+ declare function toEnvelope(value: unknown): TheokitErrorEnvelope;
53
58
  /**
54
59
  * Hydrate an envelope back into the SDK class hierarchy. Use at the inbound
55
60
  * boundary (e.g., on a worker process receiving an envelope from the main
@@ -57,5 +62,6 @@ export declare function toEnvelope(value: unknown): TheokitErrorEnvelope;
57
62
  *
58
63
  * @public
59
64
  */
60
- export declare function fromEnvelope(env: TheokitErrorEnvelope): TheokitAgentError;
61
- export { MemoryAdapterError };
65
+ declare function fromEnvelope(env: TheokitErrorEnvelope): TheokitAgentError;
66
+
67
+ export { type TheokitErrorCode, type TheokitErrorEnvelope, fromEnvelope, toEnvelope };
@@ -1,3 +1,8 @@
1
+ import { T as TheokitAgentError } from '../errors-DHZtSNnj.js';
2
+ export { M as MemoryAdapterError } from '../errors-DHZtSNnj.js';
3
+ import '../run-OJbGyweZ.js';
4
+ import 'zod';
5
+
1
6
  /**
2
7
  * @theokit/sdk/server/errors-envelope — G5 T2.2 boundary translation.
3
8
  *
@@ -12,7 +17,7 @@
12
17
  * dependency on `theokit`. Consumer code that uses both packages gets the
13
18
  * same shape via duck-typing.
14
19
  */
15
- import { MemoryAdapterError, TheokitAgentError } from "../errors.js";
20
+
16
21
  /**
17
22
  * Canonical envelope code union for cross-layer SDK boundary. Subset of the
18
23
  * full `TheoErrorCode` (theokit/server) covering codes the SDK actually emits.
@@ -21,13 +26,13 @@ import { MemoryAdapterError, TheokitAgentError } from "../errors.js";
21
26
  *
22
27
  * @public
23
28
  */
24
- export type TheokitErrorCode = "UNAUTHORIZED" | "RATE_LIMITED" | "INTERNAL_SERVER_ERROR" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "AGENT_RUN_ERROR" | "PROVIDER_KEY_MISSING" | "BUDGET_EXCEEDED" | "CREDENTIAL_POOL_EXHAUSTED";
29
+ type TheokitErrorCode = "UNAUTHORIZED" | "RATE_LIMITED" | "INTERNAL_SERVER_ERROR" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "AGENT_RUN_ERROR" | "PROVIDER_KEY_MISSING" | "BUDGET_EXCEEDED" | "CREDENTIAL_POOL_EXHAUSTED";
25
30
  /**
26
31
  * Envelope shape — structurally identical to theokit/server `TheoErrorEnvelope`.
27
32
  *
28
33
  * @public
29
34
  */
30
- export interface TheokitErrorEnvelope<TExt = unknown> {
35
+ interface TheokitErrorEnvelope<TExt = unknown> {
31
36
  readonly code: TheokitErrorCode;
32
37
  readonly message: string;
33
38
  readonly cause?: unknown;
@@ -49,7 +54,7 @@ export interface TheokitErrorEnvelope<TExt = unknown> {
49
54
  *
50
55
  * @public
51
56
  */
52
- export declare function toEnvelope(value: unknown): TheokitErrorEnvelope;
57
+ declare function toEnvelope(value: unknown): TheokitErrorEnvelope;
53
58
  /**
54
59
  * Hydrate an envelope back into the SDK class hierarchy. Use at the inbound
55
60
  * boundary (e.g., on a worker process receiving an envelope from the main
@@ -57,5 +62,6 @@ export declare function toEnvelope(value: unknown): TheokitErrorEnvelope;
57
62
  *
58
63
  * @public
59
64
  */
60
- export declare function fromEnvelope(env: TheokitErrorEnvelope): TheokitAgentError;
61
- export { MemoryAdapterError };
65
+ declare function fromEnvelope(env: TheokitErrorEnvelope): TheokitAgentError;
66
+
67
+ export { type TheokitErrorCode, type TheokitErrorEnvelope, fromEnvelope, toEnvelope };
package/dist/skills.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkLSLPF6OI_cjs = require('./chunk-LSLPF6OI.cjs');
3
+ var chunkDHLZIMP6_cjs = require('./chunk-DHLZIMP6.cjs');
4
4
  require('./chunk-KIO7QFIV.cjs');
5
+ require('./chunk-LALRCFSN.cjs');
5
6
  require('./chunk-A44COQJJ.cjs');
6
7
  require('./chunk-BEURCLDV.cjs');
7
8
 
@@ -9,11 +10,11 @@ require('./chunk-BEURCLDV.cjs');
9
10
 
10
11
  Object.defineProperty(exports, "buildSkillsBlock", {
11
12
  enumerable: true,
12
- get: function () { return chunkLSLPF6OI_cjs.buildSkillsBlock; }
13
+ get: function () { return chunkDHLZIMP6_cjs.buildSkillsBlock; }
13
14
  });
14
15
  Object.defineProperty(exports, "discoverSkills", {
15
16
  enumerable: true,
16
- get: function () { return chunkLSLPF6OI_cjs.discoverSkills; }
17
+ get: function () { return chunkDHLZIMP6_cjs.discoverSkills; }
17
18
  });
18
19
  //# sourceMappingURL=skills.cjs.map
19
20
  //# sourceMappingURL=skills.cjs.map
package/dist/skills.js CHANGED
@@ -1,5 +1,6 @@
1
- export { buildSkillsBlock, discoverSkills } from './chunk-AKSBP7OO.js';
1
+ export { buildSkillsBlock, discoverSkills } from './chunk-5IB2UKSN.js';
2
2
  import './chunk-POQT2OIF.js';
3
+ import './chunk-FKCC2MED.js';
3
4
  import './chunk-WLKFWQSJ.js';
4
5
  import './chunk-JTFYYKDT.js';
5
6
  //# sourceMappingURL=skills.js.map
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var chunkRZQ6E5YZ_cjs = require('./chunk-RZQ6E5YZ.cjs');
4
+ require('./chunk-LALRCFSN.cjs');
5
+ require('./chunk-A44COQJJ.cjs');
6
+ require('./chunk-BEURCLDV.cjs');
7
+
8
+ // src/subagents-loader.ts
9
+ async function discoverSubagents(cwd) {
10
+ return chunkRZQ6E5YZ_cjs.loadSubagents(cwd, true, void 0);
11
+ }
12
+ async function loadSubagentDefinition(name, cwd) {
13
+ return (await discoverSubagents(cwd))[name];
14
+ }
15
+
16
+ exports.discoverSubagents = discoverSubagents;
17
+ exports.loadSubagentDefinition = loadSubagentDefinition;
18
+ //# sourceMappingURL=subagents-loader.cjs.map
19
+ //# sourceMappingURL=subagents-loader.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/subagents-loader.ts"],"names":["loadSubagents"],"mappings":";;;;;;;;AA4BA,eAAsB,kBAAkB,GAAA,EAAuD;AAC7F,EAAA,OAAOA,+BAAA,CAAc,GAAA,EAAK,IAAA,EAAM,MAAS,CAAA;AAC3C;AAQA,eAAsB,sBAAA,CACpB,MACA,GAAA,EACsC;AACtC,EAAA,OAAA,CAAQ,MAAM,iBAAA,CAAkB,GAAG,CAAA,EAAG,IAAI,CAAA;AAC5C","file":"subagents-loader.cjs","sourcesContent":["/**\n * M81 — `.theokit/agents` discovery, exposed so a consumer can read the on-disk subagent\n * definitions with one import instead of hand-rolling a second parser.\n *\n * ## Why this file exists\n *\n * `src/skills.ts` already exposed `discoverSkills` for the sibling domain. Subagents had the same\n * loader — `internal/runtime/skills/subagents-loader.ts` — with no public door. A consumer behind\n * the layer boundary (the agent-builder never imports `@theokit/sdk*` directly) could not reach it,\n * so re-implementing was the only legal option. It re-implemented, and then wrote a test whose only\n * job was to watch the two parsers for drift. That test is the cleanest possible evidence that the\n * duplication should not exist.\n *\n * ## What crosses is the PARSED config\n *\n * The return is `AgentDefinition` — already interpreted — never the `.md` text or the frontmatter\n * shape. Exporting the file format would freeze an internal detail as public API; exporting the\n * parsed value leaves the format free to change.\n */\n\nimport { loadSubagents } from \"./internal/runtime/skills/subagents-loader.js\";\nimport type { AgentDefinition } from \"./types/agent.js\";\n\n/**\n * Discover the subagents defined under `<cwd>/.theokit/agents/*.md`.\n *\n * An absent directory yields `{}` — a project without subagents is the common case, not an error.\n */\nexport async function discoverSubagents(cwd: string): Promise<Record<string, AgentDefinition>> {\n return loadSubagents(cwd, true, undefined);\n}\n\n/**\n * Load ONE subagent definition by name, or `undefined` when it is not defined on disk.\n *\n * A thin selector over {@link discoverSubagents} rather than a second reader: one parser is the\n * whole point of this module.\n */\nexport async function loadSubagentDefinition(\n name: string,\n cwd: string,\n): Promise<AgentDefinition | undefined> {\n return (await discoverSubagents(cwd))[name];\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import { a as AgentDefinition } from './agent-CdjSCbYz.cjs';
2
+ import './run-OJbGyweZ.cjs';
3
+ import 'zod';
4
+
5
+ /**
6
+ * M81 — `.theokit/agents` discovery, exposed so a consumer can read the on-disk subagent
7
+ * definitions with one import instead of hand-rolling a second parser.
8
+ *
9
+ * ## Why this file exists
10
+ *
11
+ * `src/skills.ts` already exposed `discoverSkills` for the sibling domain. Subagents had the same
12
+ * loader — `internal/runtime/skills/subagents-loader.ts` — with no public door. A consumer behind
13
+ * the layer boundary (the agent-builder never imports `@theokit/sdk*` directly) could not reach it,
14
+ * so re-implementing was the only legal option. It re-implemented, and then wrote a test whose only
15
+ * job was to watch the two parsers for drift. That test is the cleanest possible evidence that the
16
+ * duplication should not exist.
17
+ *
18
+ * ## What crosses is the PARSED config
19
+ *
20
+ * The return is `AgentDefinition` — already interpreted — never the `.md` text or the frontmatter
21
+ * shape. Exporting the file format would freeze an internal detail as public API; exporting the
22
+ * parsed value leaves the format free to change.
23
+ */
24
+
25
+ /**
26
+ * Discover the subagents defined under `<cwd>/.theokit/agents/*.md`.
27
+ *
28
+ * An absent directory yields `{}` — a project without subagents is the common case, not an error.
29
+ */
30
+ declare function discoverSubagents(cwd: string): Promise<Record<string, AgentDefinition>>;
31
+ /**
32
+ * Load ONE subagent definition by name, or `undefined` when it is not defined on disk.
33
+ *
34
+ * A thin selector over {@link discoverSubagents} rather than a second reader: one parser is the
35
+ * whole point of this module.
36
+ */
37
+ declare function loadSubagentDefinition(name: string, cwd: string): Promise<AgentDefinition | undefined>;
38
+
39
+ export { discoverSubagents, loadSubagentDefinition };
@@ -0,0 +1,39 @@
1
+ import { a as AgentDefinition } from './agent-BZz4X8ZM.js';
2
+ import './run-OJbGyweZ.js';
3
+ import 'zod';
4
+
5
+ /**
6
+ * M81 — `.theokit/agents` discovery, exposed so a consumer can read the on-disk subagent
7
+ * definitions with one import instead of hand-rolling a second parser.
8
+ *
9
+ * ## Why this file exists
10
+ *
11
+ * `src/skills.ts` already exposed `discoverSkills` for the sibling domain. Subagents had the same
12
+ * loader — `internal/runtime/skills/subagents-loader.ts` — with no public door. A consumer behind
13
+ * the layer boundary (the agent-builder never imports `@theokit/sdk*` directly) could not reach it,
14
+ * so re-implementing was the only legal option. It re-implemented, and then wrote a test whose only
15
+ * job was to watch the two parsers for drift. That test is the cleanest possible evidence that the
16
+ * duplication should not exist.
17
+ *
18
+ * ## What crosses is the PARSED config
19
+ *
20
+ * The return is `AgentDefinition` — already interpreted — never the `.md` text or the frontmatter
21
+ * shape. Exporting the file format would freeze an internal detail as public API; exporting the
22
+ * parsed value leaves the format free to change.
23
+ */
24
+
25
+ /**
26
+ * Discover the subagents defined under `<cwd>/.theokit/agents/*.md`.
27
+ *
28
+ * An absent directory yields `{}` — a project without subagents is the common case, not an error.
29
+ */
30
+ declare function discoverSubagents(cwd: string): Promise<Record<string, AgentDefinition>>;
31
+ /**
32
+ * Load ONE subagent definition by name, or `undefined` when it is not defined on disk.
33
+ *
34
+ * A thin selector over {@link discoverSubagents} rather than a second reader: one parser is the
35
+ * whole point of this module.
36
+ */
37
+ declare function loadSubagentDefinition(name: string, cwd: string): Promise<AgentDefinition | undefined>;
38
+
39
+ export { discoverSubagents, loadSubagentDefinition };
@@ -0,0 +1,16 @@
1
+ import { loadSubagents } from './chunk-BNIFFFH3.js';
2
+ import './chunk-FKCC2MED.js';
3
+ import './chunk-WLKFWQSJ.js';
4
+ import './chunk-JTFYYKDT.js';
5
+
6
+ // src/subagents-loader.ts
7
+ async function discoverSubagents(cwd) {
8
+ return loadSubagents(cwd, true, void 0);
9
+ }
10
+ async function loadSubagentDefinition(name, cwd) {
11
+ return (await discoverSubagents(cwd))[name];
12
+ }
13
+
14
+ export { discoverSubagents, loadSubagentDefinition };
15
+ //# sourceMappingURL=subagents-loader.js.map
16
+ //# sourceMappingURL=subagents-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/subagents-loader.ts"],"names":[],"mappings":";;;;;;AA4BA,eAAsB,kBAAkB,GAAA,EAAuD;AAC7F,EAAA,OAAO,aAAA,CAAc,GAAA,EAAK,IAAA,EAAM,MAAS,CAAA;AAC3C;AAQA,eAAsB,sBAAA,CACpB,MACA,GAAA,EACsC;AACtC,EAAA,OAAA,CAAQ,MAAM,iBAAA,CAAkB,GAAG,CAAA,EAAG,IAAI,CAAA;AAC5C","file":"subagents-loader.js","sourcesContent":["/**\n * M81 — `.theokit/agents` discovery, exposed so a consumer can read the on-disk subagent\n * definitions with one import instead of hand-rolling a second parser.\n *\n * ## Why this file exists\n *\n * `src/skills.ts` already exposed `discoverSkills` for the sibling domain. Subagents had the same\n * loader — `internal/runtime/skills/subagents-loader.ts` — with no public door. A consumer behind\n * the layer boundary (the agent-builder never imports `@theokit/sdk*` directly) could not reach it,\n * so re-implementing was the only legal option. It re-implemented, and then wrote a test whose only\n * job was to watch the two parsers for drift. That test is the cleanest possible evidence that the\n * duplication should not exist.\n *\n * ## What crosses is the PARSED config\n *\n * The return is `AgentDefinition` — already interpreted — never the `.md` text or the frontmatter\n * shape. Exporting the file format would freeze an internal detail as public API; exporting the\n * parsed value leaves the format free to change.\n */\n\nimport { loadSubagents } from \"./internal/runtime/skills/subagents-loader.js\";\nimport type { AgentDefinition } from \"./types/agent.js\";\n\n/**\n * Discover the subagents defined under `<cwd>/.theokit/agents/*.md`.\n *\n * An absent directory yields `{}` — a project without subagents is the common case, not an error.\n */\nexport async function discoverSubagents(cwd: string): Promise<Record<string, AgentDefinition>> {\n return loadSubagents(cwd, true, undefined);\n}\n\n/**\n * Load ONE subagent definition by name, or `undefined` when it is not defined on disk.\n *\n * A thin selector over {@link discoverSubagents} rather than a second reader: one parser is the\n * whole point of this module.\n */\nexport async function loadSubagentDefinition(\n name: string,\n cwd: string,\n): Promise<AgentDefinition | undefined> {\n return (await discoverSubagents(cwd))[name];\n}\n"]}
@@ -125,6 +125,14 @@ export interface GoalOptions {
125
125
  judgeModel?: string;
126
126
  /** Override env for the judge auxiliary agent. Default `OPENROUTER_API_KEY` (EC-A). */
127
127
  judgeApiKey?: string;
128
+ /**
129
+ * M80 — o modelo do agente CONDUZIDO, base da derivação do judge quando `judgeModel` é omitido.
130
+ *
131
+ * Existe porque o default fixo (`openai/gpt-4o-mini`) só resolve em OpenRouter: com chave
132
+ * Anthropic dá 404, com bearer OAuth dá 401, e o goal queimava 3 turnos antes de falhar com razão
133
+ * enganosa. Um judge que roda no mesmo modelo do chat funciona onde o chat funciona.
134
+ */
135
+ agentModel?: string;
128
136
  /** Optional subgoals fed to the judge prompt. */
129
137
  subgoals?: string[];
130
138
  /**
package/dist/workflow.cjs CHANGED
@@ -4,8 +4,8 @@ var chunkZ2OC3UIW_cjs = require('./chunk-Z2OC3UIW.cjs');
4
4
  var chunkBWT67BI4_cjs = require('./chunk-BWT67BI4.cjs');
5
5
  require('./chunk-PNVDQL5Y.cjs');
6
6
  require('./chunk-WJVHMTKB.cjs');
7
- require('./chunk-KIO7QFIV.cjs');
8
7
  require('./chunk-TIZ4TS5V.cjs');
8
+ require('./chunk-KIO7QFIV.cjs');
9
9
  require('./chunk-A44COQJJ.cjs');
10
10
  require('./chunk-BEURCLDV.cjs');
11
11
 
package/dist/workflow.js CHANGED
@@ -2,8 +2,8 @@ export { Workflow, WorkflowBuilder, WorkflowToolError, agentStep, cloneWorkflow,
2
2
  export { WorkflowAlreadyRunningError, WorkflowCompensateNotImplementedError, WorkflowDuplicateStepIdError, WorkflowInputError, WorkflowMaxIterationsExceededError, WorkflowNestedError, WorkflowNotSerializableError, WorkflowOutputError, WorkflowParallelError, WorkflowResumeStepNotFoundError, WorkflowSnapshotNotFoundError, WorkflowStateError, __resetSnapshotStoresForTests } from './chunk-UVNG67DG.js';
3
3
  import './chunk-CAH3G4IS.js';
4
4
  import './chunk-4VPXM6UU.js';
5
- import './chunk-POQT2OIF.js';
6
5
  import './chunk-S2BBRVQX.js';
6
+ import './chunk-POQT2OIF.js';
7
7
  import './chunk-WLKFWQSJ.js';
8
8
  import './chunk-JTFYYKDT.js';
9
9
  //# sourceMappingURL=workflow.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theokit/sdk",
3
- "version": "4.27.0",
3
+ "version": "4.29.0",
4
4
  "description": "TypeScript SDK for the Theo agent harness — same surface, local or cloud.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/usetheodev/theokit-sdk#readme",
@@ -298,7 +298,17 @@
298
298
  "default": "./dist/interactive/index.cjs"
299
299
  }
300
300
  },
301
- "./package.json": "./package.json"
301
+ "./package.json": "./package.json",
302
+ "./subagents-loader": {
303
+ "import": {
304
+ "types": "./dist/subagents-loader.d.ts",
305
+ "default": "./dist/subagents-loader.js"
306
+ },
307
+ "require": {
308
+ "types": "./dist/subagents-loader.d.cts",
309
+ "default": "./dist/subagents-loader.cjs"
310
+ }
311
+ }
302
312
  },
303
313
  "files": [
304
314
  "dist",