@theokit/agents 13.0.0-next.8 → 13.0.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 +1707 -0
- package/README.md +31 -0
- package/dist/{agent-compiler-C2jIZ4CZ.d.ts → agent-compiler-B0hb6HCo.d.ts} +182 -26
- package/dist/ask.d.ts +1 -0
- package/dist/auth.d.ts +148 -1
- package/dist/auth.js +36 -0
- package/dist/auth.js.map +1 -1
- package/dist/{bridge-entry-BJ86tO6e.d.ts → bridge-entry-DBkqwe6b.d.ts} +72 -6
- package/dist/bridge.d.ts +6 -4
- package/dist/bridge.js +9 -4
- package/dist/{chunk-3GQJ2BHT.js → chunk-G7QBDGZ4.js} +93 -18
- package/dist/chunk-G7QBDGZ4.js.map +1 -0
- package/dist/chunk-HGVT4VCE.js +97 -0
- package/dist/chunk-HGVT4VCE.js.map +1 -0
- package/dist/{chunk-NZTLBLHB.js → chunk-KTQID5V3.js} +560 -342
- package/dist/chunk-KTQID5V3.js.map +1 -0
- package/dist/chunk-M5J3Q6YC.js +17 -0
- package/dist/chunk-M5J3Q6YC.js.map +1 -0
- package/dist/{chunk-RKWCXVYG.js → chunk-MJ6FRILJ.js} +67 -5
- package/dist/chunk-MJ6FRILJ.js.map +1 -0
- package/dist/{chunk-X4IGZHOV.js → chunk-PMMOOXR6.js} +43 -8
- package/dist/chunk-PMMOOXR6.js.map +1 -0
- package/dist/chunk-U72XTMYB.js +7 -0
- package/dist/chunk-U72XTMYB.js.map +1 -0
- package/dist/client-react.d.ts +1 -0
- package/dist/client.d.ts +1 -0
- package/dist/config.d.ts +163 -36
- package/dist/config.js +119 -7
- package/dist/config.js.map +1 -1
- package/dist/{define-agent-WYnUlWaH.d.ts → define-agent-DhwNmdej.d.ts} +28 -153
- package/dist/{delegation-scoring-BrBQXvIp.d.ts → delegation-scoring-BzJEheml.d.ts} +1 -1
- package/dist/hooks.d.ts +0 -32
- package/dist/hooks.js +42 -14
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +191 -17
- package/dist/index.js +43 -5
- package/dist/index.js.map +1 -1
- package/dist/sandbox.js.map +1 -1
- package/dist/setting-sources-gate-DFu51i50.d.ts +278 -0
- package/dist/testing.d.ts +5 -2
- package/dist/testing.js +1 -1
- package/dist/tools.d.ts +4 -2
- package/dist/tools.js +22 -4
- package/dist/tools.js.map +1 -1
- package/dist/usage.d.ts +30 -0
- package/dist/usage.js +3 -0
- package/dist/usage.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-3GQJ2BHT.js.map +0 -1
- package/dist/chunk-NZTLBLHB.js.map +0 -1
- package/dist/chunk-RKWCXVYG.js.map +0 -1
- package/dist/chunk-X4IGZHOV.js.map +0 -1
package/README.md
CHANGED
|
@@ -90,6 +90,37 @@ shipped the symbol is the answer — every entry names the version it landed in.
|
|
|
90
90
|
- Web Standards over Node APIs inside `src/` — `Request`/`Response`, `fetch`, `crypto.randomUUID`.
|
|
91
91
|
Node APIs live in adapters.
|
|
92
92
|
|
|
93
|
+
## Who decides policy
|
|
94
|
+
|
|
95
|
+
**An operator who did not write the code can impose policy on it.** That is a decision, recorded
|
|
96
|
+
here because it is the one a team evaluating this framework for deployment needs before anything
|
|
97
|
+
else.
|
|
98
|
+
|
|
99
|
+
It was not always true. Hooks, MCP servers, permissions and skill execution were each a value the
|
|
100
|
+
*programmer* passed at build time — a constructor argument, decided in code, by whoever wrote the
|
|
101
|
+
agent. That is a defensible design for a framework and an indefensible one for anything an
|
|
102
|
+
organisation deploys: it means the person responsible for what an agent may do on a machine has no
|
|
103
|
+
way to say so.
|
|
104
|
+
|
|
105
|
+
Policy is read from disk, and the layers have a fixed precedence:
|
|
106
|
+
|
|
107
|
+
| Layer | Who writes it | Wins against |
|
|
108
|
+
|---|---|---|
|
|
109
|
+
| `managed-settings.json` | the operator / the organisation | everything below |
|
|
110
|
+
| `.claude/settings.json`, `.theokit/settings.json` | the project | the code |
|
|
111
|
+
| `defineAgent({ … })` | the programmer | nothing |
|
|
112
|
+
|
|
113
|
+
A programmer can still decide everything, and in a single-author project nothing above them exists.
|
|
114
|
+
What changed is that they are no longer the *only* one who can.
|
|
115
|
+
|
|
116
|
+
Two consequences worth stating, because they are the cost:
|
|
117
|
+
|
|
118
|
+
- A value declared in code can be **overridden by a file the programmer does not control**. That is
|
|
119
|
+
the point, and it means a build-time guarantee is not one.
|
|
120
|
+
- An operator restriction is refused loudly rather than silently narrowed. A policy that quietly
|
|
121
|
+
did less than it said would be worse than none — the failure this repository keeps finding under
|
|
122
|
+
other names.
|
|
123
|
+
|
|
93
124
|
## Licence
|
|
94
125
|
|
|
95
126
|
See `LICENSE`.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { InlineSkill, SystemPromptResolver,
|
|
1
|
+
import { InlineSkill, SystemPromptResolver, SessionStore, PermissionGate, MemorySettings, SkillsSettings, ContextSettings, TelemetrySettings } from '@theokit/sdk';
|
|
2
|
+
import { AgentDefinition } from '@theokit/sdk/subagents-loader';
|
|
2
3
|
import { TheokitAgentError } from '@theokit/sdk/errors';
|
|
3
4
|
import { R as ReasoningEffort, a as MemoryOptions, P as ProjectContextOptions, M as McpServersMap, H as HumanInTheLoopOptions, C as CheckpointOptions, T as ToolOptions, A as ApprovalOptions, B as BudgetOptions } from './types-C16Wuh9E.js';
|
|
5
|
+
import { G as GatedSettingSource, a as GatedCompatSource } from './setting-sources-gate-DFu51i50.js';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* M9 (theokit-ai-first) — guardrail contract + typed errors.
|
|
@@ -35,23 +37,87 @@ interface Guardrail {
|
|
|
35
37
|
}
|
|
36
38
|
/** Which boundary phase a violation happened in. */
|
|
37
39
|
type GuardrailPhase = 'input' | 'output';
|
|
38
|
-
/** Thrown (fail-fast) when a guard returns `action: 'block'`. Typed per error-handling.md. */
|
|
39
40
|
/**
|
|
40
|
-
*
|
|
41
|
+
* A guard declared `redact` and supplied no replacement text.
|
|
41
42
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
43
|
+
* Distinct from {@link GuardrailViolationError} on purpose: that one says the guard REFUSED
|
|
44
|
+
* something, which is a decision working as designed. This says the guard is MALFORMED — it asked
|
|
45
|
+
* for a redaction and gave nothing to redact with, so nothing was redacted.
|
|
46
|
+
*
|
|
47
|
+
* Until B-008 this condition was silent: `pipeline.ts` tested `r.text !== undefined` and moved on, so
|
|
48
|
+
* the caller received the original text and believed a guard had run on it. That is the shape this
|
|
49
|
+
* package's hook engine calls "worse than no hook at all" — a belief in a protection that is not
|
|
50
|
+
* there. Throwing is fail-fast per `rules/error-handling.md § 2`, and the alternative was leaving
|
|
51
|
+
* unredacted output to reach a model because a guard was written wrong.
|
|
52
|
+
*
|
|
53
|
+
* `''` is NOT this case. An empty replacement is a guard choosing to erase everything, which is the
|
|
54
|
+
* strongest redaction available, and treating it as absent would invert the defect.
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* The base every guardrail error shares, so the seams that must treat them alike can do so BY
|
|
58
|
+
* CONSTRUCTION rather than by remembering a list.
|
|
59
|
+
*
|
|
60
|
+
* The list is how B-020 happened. `run-reflective-loop.ts` let `GuardrailViolationError` pass
|
|
61
|
+
* through unwrapped, and its sibling in this same file was not added — so a malformed result was
|
|
62
|
+
* wrapped in a `DelegationError`, whose message interpolates its cause and whose code is on the
|
|
63
|
+
* delegate tool's message allowlist. The guard's name crossed to the model, and a guard DEFECT was
|
|
64
|
+
* reported as a delegation failure.
|
|
65
|
+
*
|
|
66
|
+
* A base is not airtight on its own: a new class can still extend `TheokitAgentError` directly.
|
|
67
|
+
* `tests/unit/a-guardrail-defect-does-not-name-its-guard.test.ts` walks this module's barrel and
|
|
68
|
+
* fails on any exported error class that skipped it. The two together are the construction; either
|
|
69
|
+
* alone is a convention.
|
|
70
|
+
*
|
|
71
|
+
* Abstract because there is nothing to throw at this level — every guardrail failure is one of the
|
|
72
|
+
* specific kinds below, and a bare `GuardrailError` would say only that something guard-shaped
|
|
73
|
+
* happened.
|
|
74
|
+
*/
|
|
75
|
+
declare abstract class GuardrailError extends TheokitAgentError {
|
|
76
|
+
}
|
|
77
|
+
declare class MalformedGuardrailResultError extends GuardrailError {
|
|
78
|
+
readonly guardName: string;
|
|
79
|
+
readonly phase: GuardrailPhase;
|
|
80
|
+
readonly name = "MalformedGuardrailResultError";
|
|
81
|
+
constructor(guardName: string, phase: GuardrailPhase);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Thrown (fail-fast) when a guard returns `action: 'block'`. Typed per error-handling.md.
|
|
85
|
+
*
|
|
86
|
+
* M80 — extends {@link TheokitAgentError}, not plain `Error`. `isTransientError` is defined over
|
|
87
|
+
* `TheokitAgentError`, so a class outside that hierarchy is INVISIBLE to it and the only recourse
|
|
88
|
+
* left to a consumer is matching on message text — a regex over an eight-level `cause` chain, which
|
|
89
|
+
* is what one actually wrote. `code` is stable across a rename of the class; `isRetryable` is
|
|
90
|
+
* DECLARED rather than defaulted, because a default would be a retry policy nobody chose.
|
|
47
91
|
*/
|
|
48
|
-
declare class GuardrailViolationError extends
|
|
92
|
+
declare class GuardrailViolationError extends GuardrailError {
|
|
49
93
|
readonly guardName: string;
|
|
50
94
|
readonly phase: GuardrailPhase;
|
|
51
95
|
readonly reason: string;
|
|
52
96
|
readonly name = "GuardrailViolationError";
|
|
53
97
|
constructor(guardName: string, phase: GuardrailPhase, reason: string);
|
|
54
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* A text-carrying event arrived with a `content` that is not text.
|
|
101
|
+
*
|
|
102
|
+
* Distinct from the two above on purpose: they say a guard REFUSED something or was WRITTEN WRONG.
|
|
103
|
+
* This says the STREAM is malformed — the event announces itself as text and carries something a
|
|
104
|
+
* guard cannot read.
|
|
105
|
+
*
|
|
106
|
+
* Until B-021 this was silent. Both extractors tested `typeof e.content === 'string'` and returned
|
|
107
|
+
* `undefined` otherwise, which `moderateOutputStream` reads as "this event carries no text" — so the
|
|
108
|
+
* payload was never accumulated, never shown to a guard, and yielded VERBATIM. The failure direction
|
|
109
|
+
* is DELIVER: a guard declared to stop that payload never saw it, and the run reported green.
|
|
110
|
+
*
|
|
111
|
+
* Refused rather than coerced. Coercing would moderate `"[object Object]"` — a guard consulted about
|
|
112
|
+
* a string the model never produced, returning a verdict about nothing, while the real payload rides
|
|
113
|
+
* along underneath. That is the redaction-computed-and-discarded shape with an extra step.
|
|
114
|
+
*/
|
|
115
|
+
declare class UnreadableTextPayloadError extends GuardrailError {
|
|
116
|
+
readonly eventType: string;
|
|
117
|
+
readonly received: unknown;
|
|
118
|
+
readonly name = "UnreadableTextPayloadError";
|
|
119
|
+
constructor(eventType: string, received: unknown);
|
|
120
|
+
}
|
|
55
121
|
/** Thrown when {@link costGuard}'s cumulative token budget is exceeded. */
|
|
56
122
|
/**
|
|
57
123
|
* M80 — extends {@link TheokitAgentError}, not plain `Error`.
|
|
@@ -62,7 +128,7 @@ declare class GuardrailViolationError extends TheokitAgentError {
|
|
|
62
128
|
* rename of the class; `isRetryable` is DECLARED rather than defaulted, because a default would be a
|
|
63
129
|
* retry policy nobody chose.
|
|
64
130
|
*/
|
|
65
|
-
declare class CostBudgetExceededError extends
|
|
131
|
+
declare class CostBudgetExceededError extends GuardrailError {
|
|
66
132
|
readonly usedTokens: number;
|
|
67
133
|
readonly maxTokens: number;
|
|
68
134
|
readonly name = "CostBudgetExceededError";
|
|
@@ -97,6 +163,18 @@ type SkillsSelection = readonly (string | InlineSkill)[] | ((ctx: SkillsRequestC
|
|
|
97
163
|
*/
|
|
98
164
|
declare function resolveEnabledSkills(selection: SkillsSelection | undefined, ctx: SkillsRequestContext): Promise<string[] | undefined>;
|
|
99
165
|
|
|
166
|
+
/**
|
|
167
|
+
* The shape this layer registers with the SDK's lifecycle-hook seam.
|
|
168
|
+
*
|
|
169
|
+
* Deliberately structural and minimal: the SDK owns the full `Plugin` contract, and restating it
|
|
170
|
+
* here would be a second declaration to drift from. What this needs to know is the one thing that
|
|
171
|
+
* tells a code plugin from a bundle reference.
|
|
172
|
+
*/
|
|
173
|
+
interface CodePlugin {
|
|
174
|
+
readonly name: string;
|
|
175
|
+
readonly register: (...args: never[]) => unknown;
|
|
176
|
+
}
|
|
177
|
+
|
|
100
178
|
/**
|
|
101
179
|
* Project the M8 fields from `CompiledAgentOptions` into `Agent.create()` arguments. Only the async
|
|
102
180
|
* `@ProjectContext` resolver is built here (it does I/O, so the compiler keeps it raw). `applied`
|
|
@@ -148,6 +226,33 @@ declare class HookGateUnsupportedError extends TheokitAgentError {
|
|
|
148
226
|
readonly name = "HookGateUnsupportedError";
|
|
149
227
|
constructor(version: string | undefined);
|
|
150
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* A narrowed `import` on an SDK that cannot read it.
|
|
231
|
+
*
|
|
232
|
+
* Refuses rather than warns, and the asymmetry with {@link warnIfSdkCannotReadCompatSources} is
|
|
233
|
+
* deliberate: an unrecognised `compatSources` shape means the foreign root is not read, so a
|
|
234
|
+
* consumer who asked for "the skills but not the hooks" silently gets NOTHING — strictly further
|
|
235
|
+
* from what they asked for than the un-narrowed form, which at least reads something. Failing loud
|
|
236
|
+
* is recoverable; a silent nothing is discovered by wondering why a skill is missing.
|
|
237
|
+
*
|
|
238
|
+
* ## The cost, which this file argues against two functions above
|
|
239
|
+
*
|
|
240
|
+
* An unreadable version is refused too, on the principle {@link assertSdkCanGateHooks} states:
|
|
241
|
+
* "cannot tell" and "is supported" must not collapse. The sibling WARNING takes the opposite view
|
|
242
|
+
* for itself — *"a bundled or vendored SDK may not resolve that subpath, and refusing to create an
|
|
243
|
+
* agent over a diagnostic would be the cure being worse than the disease."*
|
|
244
|
+
*
|
|
245
|
+
* Both are right for what they guard, and the difference is what the check IS. A diagnostic that
|
|
246
|
+
* cannot read a version should stay quiet; a GATE that cannot read one has not established the
|
|
247
|
+
* thing it exists to establish. But the cost is real and belongs here rather than in a reviewer's
|
|
248
|
+
* report: a consumer who bundles the SDK so `@theokit/sdk/package.json` does not resolve cannot
|
|
249
|
+
* create an agent with a narrowed `import`, even on 5.4.0+. Their exit is to omit `import` and read
|
|
250
|
+
* the whole root.
|
|
251
|
+
*/
|
|
252
|
+
declare class CompatImportUnsupportedError extends TheokitAgentError {
|
|
253
|
+
readonly name = "CompatImportUnsupportedError";
|
|
254
|
+
constructor(version: string | undefined);
|
|
255
|
+
}
|
|
151
256
|
|
|
152
257
|
/**
|
|
153
258
|
* Agent compiler — transforms decorator metadata into SDK calls.
|
|
@@ -208,18 +313,23 @@ interface CompiledTool {
|
|
|
208
313
|
* @param toolboxInstances - Map of Toolbox class → instantiated object (for `this` binding)
|
|
209
314
|
*/
|
|
210
315
|
declare function compileTools(toolboxes: ToolboxWalkResult[], toolboxInstances: Map<ClassToken, object>): CompiledTool[];
|
|
211
|
-
/**
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
316
|
+
/**
|
|
317
|
+
* A compiled sub-agent IS the SDK's own `AgentDefinition`, re-exported here under the name the
|
|
318
|
+
* public barrel already uses for it.
|
|
319
|
+
*
|
|
320
|
+
* It used to be a narrower local type, `CompiledSubAgent { model?, systemPrompt? }`, and ADR D3
|
|
321
|
+
* deferred projecting it: "a resolver here is carried, not invoked". **That deferral has ended** —
|
|
322
|
+
* `assembleM8CreateOptions` now projects `agents` into `Agent.create`.
|
|
323
|
+
*
|
|
324
|
+
* The narrow type could not have been projected as it stood. `AgentDefinition` requires
|
|
325
|
+
* `description` and `prompt`, and the local shape carried neither; a sub-agent with no description
|
|
326
|
+
* is one the parent model has no basis to delegate to. Every other surface already agreed on the
|
|
327
|
+
* SDK shape — `RuntimeOverrides.agents` (the per-run door that always worked) is
|
|
328
|
+
* `Record<string, AgentDefinition>`, and the same type crosses the barrel as `SubagentDefinition`.
|
|
329
|
+
* The local type was referenced in exactly two places, both of them its own declaration and the
|
|
330
|
+
* field that held it, so adopting the SDK shape removed a mismatch rather than migrating users.
|
|
331
|
+
*/
|
|
332
|
+
type CompiledSubAgent = AgentDefinition;
|
|
223
333
|
/** Compiled agent options ready for SDK Agent.create(). */
|
|
224
334
|
interface CompiledAgentOptions {
|
|
225
335
|
model?: string;
|
|
@@ -238,14 +348,14 @@ interface CompiledAgentOptions {
|
|
|
238
348
|
* Projected into `Agent.create({ local: { settingSources } })` by `assembleM8CreateOptions`
|
|
239
349
|
* (merged with `cwd`, decoupled from inline skills). Absent ⇒ inline (code) config only.
|
|
240
350
|
*/
|
|
241
|
-
settingSources?: readonly
|
|
351
|
+
settingSources?: readonly GatedSettingSource[];
|
|
242
352
|
/**
|
|
243
353
|
* Foreign configuration dialects, already authorised (usetheokit/theokit#634).
|
|
244
354
|
*
|
|
245
355
|
* Resolved at compile time by `resolveCompatSources`, exactly like `settingSources`: a value here
|
|
246
356
|
* can only hold a source some posture granted, so the adapter projects rather than decides.
|
|
247
357
|
*/
|
|
248
|
-
compatSources?: readonly
|
|
358
|
+
compatSources?: readonly GatedCompatSource[];
|
|
249
359
|
/**
|
|
250
360
|
* #686 — the consumer's pre-spawn approval gate, forwarded to `Agent.create({ local: { hooks } })`.
|
|
251
361
|
*
|
|
@@ -255,12 +365,58 @@ interface CompiledAgentOptions {
|
|
|
255
365
|
*/
|
|
256
366
|
hookApproval?: HookApprovalGate;
|
|
257
367
|
/** Code `Plugin` objects forwarded to `Agent.create({ plugins })` (lifecycle-hook seam). */
|
|
258
|
-
|
|
368
|
+
/**
|
|
369
|
+
* Code plugins — `{ name, register }` objects registered with the SDK's lifecycle-hook seam.
|
|
370
|
+
*
|
|
371
|
+
* `readonly unknown[]` is what let the WRONG shape through silently: a consumer who read the
|
|
372
|
+
* Claude Code documentation passed `[{ type: 'local', path: './p' }]`, the compiler accepted it,
|
|
373
|
+
* and the agent ran with the plugin absent. `assertCodePlugins` refuses it at the projection, and
|
|
374
|
+
* the type says what belongs here.
|
|
375
|
+
*
|
|
376
|
+
* NOT the filesystem-bundle form. A bundle is declared by living in a `plugins/` directory under
|
|
377
|
+
* `.theokit/` or `.claude/`, where its `skills/` and `agents/` are discovered.
|
|
378
|
+
*/
|
|
379
|
+
plugins?: readonly CodePlugin[];
|
|
380
|
+
/**
|
|
381
|
+
* B-060 — an external session store (Postgres / Redis / KV / durable object), used by the SDK as
|
|
382
|
+
* the PRIMARY session store and resume source.
|
|
383
|
+
*
|
|
384
|
+
* Without it a serverless deployment resumed from a filesystem that no longer exists, and a
|
|
385
|
+
* multi-pod one resumed from whichever host happened to take the request. The only way to reach
|
|
386
|
+
* it was importing `@theokit/sdk` directly — the one thing this layer's doctrine forbids, so the
|
|
387
|
+
* doctrine and the capability disagreed and the consumer paid.
|
|
388
|
+
*
|
|
389
|
+
* Typed against the SDK's own `SessionStore` rather than restated here: a hand-written copy that
|
|
390
|
+
* drifts by one method stops fitting, which the mirrored `permissionMode` field measured one item
|
|
391
|
+
* earlier.
|
|
392
|
+
*/
|
|
393
|
+
sessionStore?: SessionStore;
|
|
394
|
+
/**
|
|
395
|
+
* B-056 — the callback that sees every tool call the earlier steps did not resolve.
|
|
396
|
+
*
|
|
397
|
+
* The SDK's engine is fail-closed: an unmatched call resolves to `ask`, and an ABSENT gate blocks
|
|
398
|
+
* it. So the value of declaring one is not that unresolved calls stop being approved — they never
|
|
399
|
+
* were — it is that they reach somebody who can decide instead of being refused with nobody to
|
|
400
|
+
* consult. A tool added after the approvals were written keeps defaulting to asking.
|
|
401
|
+
*
|
|
402
|
+
* Typed against the SDK's `PermissionGate`, not restated: its decision shape is veto-or-allow, and
|
|
403
|
+
* a hand-written copy would be the place an `updatedInput` field gets invented for a seam that
|
|
404
|
+
* discards it.
|
|
405
|
+
*/
|
|
406
|
+
canUseTool?: PermissionGate;
|
|
259
407
|
tools: CompiledTool[];
|
|
260
408
|
agents: Record<string, CompiledSubAgent>;
|
|
261
409
|
memory?: MemoryOptions | MemorySettings;
|
|
262
410
|
skills?: SkillsSettings;
|
|
263
411
|
context?: ContextSettings;
|
|
412
|
+
/**
|
|
413
|
+
* B-072 — OpenTelemetry settings, projected onto `Agent.create({ telemetry })`.
|
|
414
|
+
*
|
|
415
|
+
* Typed against the SDK's `TelemetrySettings` rather than restated, for the reason `canUseTool`
|
|
416
|
+
* above gives about `PermissionGate`: a hand-written copy is where a field gets invented for a
|
|
417
|
+
* seam that discards it, and this one has six keys with real defaults behind them.
|
|
418
|
+
*/
|
|
419
|
+
telemetry?: TelemetrySettings;
|
|
264
420
|
/**
|
|
265
421
|
* M7 — run-context injected into every tool handler's `ctx.context` by the theokit adapter
|
|
266
422
|
* (`buildSdkTools` wrapper). Populated by `defineAgent({ context })` (functional surface).
|
|
@@ -298,4 +454,4 @@ interface CompiledAgentOptions {
|
|
|
298
454
|
skillsResolver?: SkillsSelection;
|
|
299
455
|
}
|
|
300
456
|
|
|
301
|
-
export { type
|
|
457
|
+
export { type CodePlugin as C, type Guardrail as G, type HookApprovalGate as H, MalformedGuardrailResultError as M, type SkillsSelection as S, type ToolWalkResult as T, UnreadableTextPayloadError as U, type CompiledAgentOptions as a, type CompiledTool as b, CompatImportUnsupportedError as c, CostBudgetExceededError as d, type GuardrailAction as e, GuardrailError as f, type GuardrailPhase as g, type GuardrailResult as h, GuardrailViolationError as i, type HookApprovalRequest as j, HookGateUnsupportedError as k, type SkillsRequestContext as l, type ToolboxWalkResult as m, compileTools as n, resolveEnabledSkills as r };
|
package/dist/ask.d.ts
CHANGED
package/dist/auth.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { OAuthProviderConfig, CredentialStoreConfig, ResolvedCredential, ensureFreshCredential, OpenAIDeviceConfig, openaiDeviceLogin, OAuthTokens, DeviceDeps } from '@theokit/sdk/auth';
|
|
2
2
|
export { CredentialError, CredentialStoreConfig, DeviceCodeGrant, DeviceDeps, DeviceOAuthConfig, OAuthProviderConfig, OAuthTokens, OpenAIDeviceConfig, ResolveCredentialOptions, ResolvedCredential, StoredCredential, StoredOAuthCredential, assertSecureModes, authFilePath, credentialHome, deviceLogin, ensureFreshCredential, extractAccountId, openaiDeviceLogin, persistOAuthTokens, pollDeviceToken, providerFromApiKeyPrefix, readAuthFile, readStoredOAuth, refreshOAuthTokens, requestDeviceCode, writeCredential } from '@theokit/sdk/auth';
|
|
3
3
|
import { TheokitAgentError } from '@theokit/sdk/errors';
|
|
4
|
+
import { PermissionMode } from '@theokit/sdk';
|
|
5
|
+
export { PermissionMode } from '@theokit/sdk';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* M60 — `AuthProvider`, the OO contract that unifies the SDK's free OAuth-lifecycle functions
|
|
@@ -443,4 +445,149 @@ declare class PermissionStore {
|
|
|
443
445
|
expired(): readonly Grant[];
|
|
444
446
|
}
|
|
445
447
|
|
|
446
|
-
|
|
448
|
+
/**
|
|
449
|
+
* Turns a {@link PermissionStore} into a `pre_tool_call` handler — the seam that can actually refuse
|
|
450
|
+
* a tool.
|
|
451
|
+
*
|
|
452
|
+
* ## Why an adapter, and not a gate of its own
|
|
453
|
+
*
|
|
454
|
+
* The store shipped with a careful key, a deny-by-default posture and no reader: measured
|
|
455
|
+
* 2026-09-10, `isGranted` had zero callers outside its own unit test, and `PermissionStore` appeared
|
|
456
|
+
* in zero files across six sibling repositories. It described a control that was not in force.
|
|
457
|
+
*
|
|
458
|
+
* What was missing was never a mechanism. `pre_tool_call` is documented in `bridge/hook-handlers.ts`
|
|
459
|
+
* as the ONLY hook with veto power, and it runs before the tool by construction — so a refusal here
|
|
460
|
+
* is a refusal before the side effect. This file is the two lines that connect the two, plus the one
|
|
461
|
+
* decision neither of them could make alone.
|
|
462
|
+
*
|
|
463
|
+
* The alternative — a required `granted` argument mirroring `BuildHookHandlersOptions.approved` —
|
|
464
|
+
* was rejected because it breaks every consumer's compile for a store none of them uses. The hook
|
|
465
|
+
* path could afford a required argument because it shipped WITH one; retrofitting is a different
|
|
466
|
+
* proposition.
|
|
467
|
+
*
|
|
468
|
+
* ## The decision only the consumer can make
|
|
469
|
+
*
|
|
470
|
+
* A `PermissionQuery` is keyed by `(tool, scope, command)`. A `PreToolCallContext` carries
|
|
471
|
+
* `{ name, args }` — no scope, and no notion of which argument IS the command, which differs per
|
|
472
|
+
* tool. So the mapping is the consumer's, and it is passed in.
|
|
473
|
+
*
|
|
474
|
+
* `classify` returns a query OR an explicit `{ governed: false }`, never a bare `undefined`. A
|
|
475
|
+
* mapper returning `undefined` would say "this tool needs no permission" and "I forgot this tool" in
|
|
476
|
+
* the same word, and the second one would silently pass — on a security gate. The discriminated
|
|
477
|
+
* result makes forgetting a compile error while keeping "not governed" expressible, which a
|
|
478
|
+
* deny-everything default would not: a gate that refuses ordinary work is a gate somebody disables.
|
|
479
|
+
*
|
|
480
|
+
* ## Composing with a `pre_tool_call` you already have
|
|
481
|
+
*
|
|
482
|
+
* `HookHandlers.pre_tool_call` is a SINGLE field, so assigning this gate over an existing handler
|
|
483
|
+
* loses one of the two, silently — the failure `bridge/delegation-hooks.ts` records for delegated
|
|
484
|
+
* hooks, *"nothing throws, nothing warns"*, and worse here because the handler that loses may be the
|
|
485
|
+
* one that refuses. Compose them explicitly:
|
|
486
|
+
*
|
|
487
|
+
* ```ts
|
|
488
|
+
* pre_tool_call: async (ctx) => (await gate(ctx)) ?? (await mine(ctx))
|
|
489
|
+
* ```
|
|
490
|
+
*
|
|
491
|
+
* First veto wins; `undefined` falls through. No helper ships for this: it is one line, and a
|
|
492
|
+
* `composePreToolCall` would be a second way to do what `??` already does.
|
|
493
|
+
*/
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Minimal shape mirrored from `@theokit/sdk`.
|
|
497
|
+
*
|
|
498
|
+
* The reason used to read "type-only, no runtime import, so the SDK peer stays optional", and that
|
|
499
|
+
* does not justify mirroring anything: `bridge/hook-handlers.ts` imports these very two SDK types
|
|
500
|
+
* (`PreToolCallContext`, `PreToolCallDecision`) with `import type` and costs the optional peer
|
|
501
|
+
* nothing. A type-only import IS type-only.
|
|
502
|
+
*
|
|
503
|
+
* The real reason is the NAME, and it is written out three paragraphs down: `@theokit/sdk` already
|
|
504
|
+
* exports `PermissionGateContext` with a different shape, so a consumer importing both would get a
|
|
505
|
+
* duplicate identifier or silently the wrong one. What is mirrored here is also a deliberate
|
|
506
|
+
* SUBSET — the fields this gate reads — rather than a copy kept in step with the SDK's.
|
|
507
|
+
*
|
|
508
|
+
* A mirror can drift into a consumer-side compile error that no gate here would see first, so the
|
|
509
|
+
* assignment this docblock instructs a consumer to make is pinned by
|
|
510
|
+
* `tests/type/the-grant-gate-fits-the-hook-it-is-for.test-d.ts`.
|
|
511
|
+
*
|
|
512
|
+
* NOT named `PermissionGateContext`: `@theokit/sdk` already exports a type by that name, with a
|
|
513
|
+
* different shape (`{ toolName, mode }`), alongside `PermissionGate`, `PermissionGateDecision`,
|
|
514
|
+
* `PermissionEngine` and `PermissionPlugin`. A consumer importing both would get a duplicate
|
|
515
|
+
* identifier, or silently the wrong shape.
|
|
516
|
+
*
|
|
517
|
+
* The rename says something true rather than merely avoiding a clash. This gates on a STANDING
|
|
518
|
+
* GRANT the operator made; the SDK's permission engine is a separate system with its own rules, and
|
|
519
|
+
* the two do not consult each other — an engine `allow` does not satisfy a missing grant, and a
|
|
520
|
+
* grant does not satisfy the engine.
|
|
521
|
+
*/
|
|
522
|
+
interface GrantGateContext {
|
|
523
|
+
readonly name: string;
|
|
524
|
+
readonly args: Record<string, unknown>;
|
|
525
|
+
readonly agentId: string;
|
|
526
|
+
readonly runId: string;
|
|
527
|
+
/**
|
|
528
|
+
* The run's resolved permission mode, carried by the real context. Mirrored so the shapes match
|
|
529
|
+
* and so its absence from the gate's logic is a decision rather than an oversight: `bypass` does
|
|
530
|
+
* NOT disable this gate, because a standing grant is the operator's, not the run's.
|
|
531
|
+
*
|
|
532
|
+
* B-057 — the SDK's own `PermissionMode`, not a bare `string` and not a union restated here. The
|
|
533
|
+
* loose type was the half that made this look like an oversight: a mirror that accepts any word
|
|
534
|
+
* mirrors nothing in particular, and `"readonly"` — what somebody writes when they mean `plan` —
|
|
535
|
+
* would have sat here looking applied.
|
|
536
|
+
*
|
|
537
|
+
* Restating the union was the first attempt and the type test refused it: this shape must fit
|
|
538
|
+
* `PreToolCallContext` structurally, and a hand-written copy that drifts by one member stops
|
|
539
|
+
* fitting. Importing the source makes it a mirror BY CONSTRUCTION — it narrows when the SDK
|
|
540
|
+
* narrows, and cannot disagree.
|
|
541
|
+
*
|
|
542
|
+
* This layer's own three-mode surface reaches these through `approvalModeToPermissionMode`, so a
|
|
543
|
+
* reader of either vocabulary meets the other.
|
|
544
|
+
*/
|
|
545
|
+
readonly permissionMode?: PermissionMode;
|
|
546
|
+
}
|
|
547
|
+
/** This tool is deliberately outside the gate's remit — distinct from "I forgot to map it". */
|
|
548
|
+
interface NotGoverned {
|
|
549
|
+
readonly governed: false;
|
|
550
|
+
}
|
|
551
|
+
/** This tool IS governed, by the grant key inside. */
|
|
552
|
+
interface Governed {
|
|
553
|
+
readonly governed: true;
|
|
554
|
+
readonly query: PermissionQuery;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* BOTH arms carry `governed`, and that is the whole point.
|
|
558
|
+
*
|
|
559
|
+
* The first version was `PermissionQuery | NotGoverned` — discriminated by whether the `governed`
|
|
560
|
+
* KEY was present. It failed open, measured against the built artifact: a consumer who writes a
|
|
561
|
+
* policy record `{ governed: true, scope }` and spreads it into the query — the most natural
|
|
562
|
+
* reading of "yes, govern this" — got `undefined` back, and an ungranted destructive command ran.
|
|
563
|
+
* `governed: undefined` did the same. TypeScript does not stop it: a fresh literal with an excess
|
|
564
|
+
* property errors, the same object through a variable or a spread does not.
|
|
565
|
+
*
|
|
566
|
+
* The presence check arrived by obeying a linter. `'governed' in c && c.governed === false` was
|
|
567
|
+
* flagged as "always true given the type", which was true of the DECLARED type and false of every
|
|
568
|
+
* value that reaches it. A type-based lint rule cannot see excess properties, and the safety of a
|
|
569
|
+
* gate is not a type-level fact.
|
|
570
|
+
*
|
|
571
|
+
* With the discriminant on both arms there is no key to be accidentally present: `governed` is
|
|
572
|
+
* declared either way, the check is on its VALUE, and `governed: true` without a `query` is a
|
|
573
|
+
* compile error rather than a silent pass.
|
|
574
|
+
*/
|
|
575
|
+
type Classification = Governed | NotGoverned;
|
|
576
|
+
/**
|
|
577
|
+
* A veto, in the shape `pre_tool_call` returns.
|
|
578
|
+
*
|
|
579
|
+
* Exported because it appears in {@link grantGate}'s public signature — an unexported type there
|
|
580
|
+
* leaves a consumer unable to name the return value. `hooks/secure-store.ts` documents the same
|
|
581
|
+
* case.
|
|
582
|
+
*/
|
|
583
|
+
interface Veto {
|
|
584
|
+
readonly block: true;
|
|
585
|
+
readonly message: string;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* @param store the grants to consult; re-read per call, so a grant made mid-run is seen
|
|
589
|
+
* @param classify maps a tool call to the grant key it needs, or declares it ungoverned
|
|
590
|
+
*/
|
|
591
|
+
declare function grantGate(store: PermissionStore, classify: (ctx: GrantGateContext) => Classification): (ctx: GrantGateContext) => Promise<Veto | undefined>;
|
|
592
|
+
|
|
593
|
+
export { type AgentCredentialInput, type AuthMethod, AuthProvider, CODEX_CLIENT_ID_ENV_VAR, CODEX_PROVIDER, type Classification, CredentialNotFoundError, type ProviderDescriptor as CredentialProviderDescriptor, type CredentialResolution, type CredentialSourcesInput, DEFAULT_PROVIDERS, DeclaredProviderError, type DeviceAuthProvider, type Governed, type Grant, type GrantGateContext, type GrantOptions, type NotGoverned, type PermissionQuery, PermissionStore, type PermissionStoreOptions, type PromptHooks, ProviderKeyMismatchError, ProviderPrefixMismatchError, type ResolveCredentialInput, type SourceOrigin, type Veto, credentialSources, grantGate, loginWithDevice, requireCredential, resolveAgentCredential, resolveCredential };
|
package/dist/auth.js
CHANGED
|
@@ -2,6 +2,9 @@ import {
|
|
|
2
2
|
readSecureJson,
|
|
3
3
|
writeSecureJson
|
|
4
4
|
} from "./chunk-D2EFYZBV.js";
|
|
5
|
+
import {
|
|
6
|
+
debugLog
|
|
7
|
+
} from "./chunk-M5J3Q6YC.js";
|
|
5
8
|
import {
|
|
6
9
|
__name
|
|
7
10
|
} from "./chunk-Z4QWC7IK.js";
|
|
@@ -572,6 +575,38 @@ var PermissionStore = class {
|
|
|
572
575
|
`);
|
|
573
576
|
}
|
|
574
577
|
};
|
|
578
|
+
|
|
579
|
+
// src/auth/permission-gate.ts
|
|
580
|
+
function grantGate(store, classify) {
|
|
581
|
+
return (ctx) => {
|
|
582
|
+
try {
|
|
583
|
+
const classification = classify(ctx);
|
|
584
|
+
if (classification.governed === false) return Promise.resolve(void 0);
|
|
585
|
+
if (store.isGranted(classification.query)) return Promise.resolve(void 0);
|
|
586
|
+
const because = store.lastReadError === void 0 ? "no standing grant matches" : "the permission store could not be read, so no grant applies";
|
|
587
|
+
debugLog("[theokit] permission gate vetoed", {
|
|
588
|
+
tool: ctx.name,
|
|
589
|
+
scope: classification.query.scope,
|
|
590
|
+
because
|
|
591
|
+
});
|
|
592
|
+
return Promise.resolve({
|
|
593
|
+
block: true,
|
|
594
|
+
message: `"${ctx.name}" is not permitted in ${classification.query.scope}: ${because}`
|
|
595
|
+
});
|
|
596
|
+
} catch (cause) {
|
|
597
|
+
const why = cause instanceof Error ? cause.message : String(cause);
|
|
598
|
+
debugLog("[theokit] permission gate could not classify", {
|
|
599
|
+
tool: ctx.name,
|
|
600
|
+
why
|
|
601
|
+
});
|
|
602
|
+
return Promise.resolve({
|
|
603
|
+
block: true,
|
|
604
|
+
message: `permission gate could not classify "${ctx.name}": ${why}`
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
__name(grantGate, "grantGate");
|
|
575
610
|
export {
|
|
576
611
|
AuthProvider,
|
|
577
612
|
CODEX_CLIENT_ID_ENV_VAR,
|
|
@@ -590,6 +625,7 @@ export {
|
|
|
590
625
|
deviceLogin,
|
|
591
626
|
ensureFreshCredential2 as ensureFreshCredential,
|
|
592
627
|
extractAccountId,
|
|
628
|
+
grantGate,
|
|
593
629
|
loginWithDevice,
|
|
594
630
|
openaiDeviceLogin3 as openaiDeviceLogin,
|
|
595
631
|
persistOAuthTokens2 as persistOAuthTokens,
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auth/auth-provider.ts","../src/auth-entry.ts","../src/auth/device-provider.ts","../src/auth/resolve-credential.ts","../src/auth/permission-store.ts"],"mappings":";;;;;;;;;AAAA,SACEA,cACAC,uBACAC,mBACAC,oBACAC,uBACK;AAQP,SAASC,oBAAoB;AAkCtB,IAAMC,iBAAN,cAA6BC,MAAAA;EAhDpC,OAgDoCA;;;;EAClC,YACEC,SAESC,WACT;AACA,UAAMD,OAAAA,GAAAA,KAFGC,YAAAA;AAGT,SAAKC,OAAO;EACd;AACF;AAMA,IAAMC,oBAAoB;EACxB;EACA;EACA;EACA;EACA;EACA;;AAIK,SAASC,uBAAuBC,KAAY;AACjD,QAAMC,OAAOD,eAAeN,QAAQ,GAAGM,IAAIH,IAAI,KAAKG,IAAIL,OAAO,KAAKO,OAAOF,GAAAA;AAC3E,MAAI,qDAAqDG,KAAKF,IAAAA,GAAO;AACnE,WAAO,IAAIR,eACT,mGACA,KAAA;EAEJ;AACA,QAAMG,YACJE,kBAAkBM,KAAK,CAACC,MAAMJ,KAAKK,SAASD,CAAAA,CAAAA,KAAO,gCAAgCF,KAAKF,IAAAA;AAC1F,SAAO,IAAIR,eACTG,YAAY,gDAAgD,qCAC5DA,SAAAA;AAEJ;AAdgBG;AAiBT,SAASQ,eAAeC,SAAiBC,SAAS,KAAKC,SAASC,KAAKD,QAAM;AAChF,QAAME,OAAOH,SAAS,KAAKD;AAC3B,SAAOG,KAAKE,MAAMD,QAAQ,OAAOF,OAAAA,IAAW,IAAE;AAChD;AAHgBH;AAKT,IAAMO,eAAN,MAAMA,cAAAA;EA/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QAAK;AACH,UAAM,EAAEK,OAAOC,MAAK,IAAKC,eACvB,KAAKlC,MACL,CAACmC,QAAAA;AACC,YAAMC,SAAkBC,KAAKC,MAAMH,GAAAA;AACnC,UAAI,CAACI,MAAMC,QAAQJ,MAAAA,EAAS,OAAM,IAAI1B,MAAM,6BAAA;AAC5C,aAAO0B;IACT,GACA,CAAA,CAAE;AAEJ,SAAKnC,gBAAgBgC;AACrB,WAAOD;EACT;EAEA,SAASb,QAAwB;AAC/BsB,oBAAgB,KAAKzC,MAAM,MAAM,GAAGqC,KAAKK,UAAUvB,QAAQ,MAAM,CAAA,CAAA;CAAM;EACzE;AACF;","names":["authFilePath","ensureFreshCredential","openaiDeviceLogin","persistOAuthTokens","readStoredOAuth","withFileLock","RefreshFailure","Error","message","transient","name","TRANSIENT_REASONS","classifyRefreshFailure","err","text","String","test","some","m","includes","waitWithJitter","attempt","baseMs","random","Math","base","round","AuthProvider","config","store","ensureFresh","resolved","deps","env","kind","ensureFreshCredential","filePath","authFilePath","inFlight","refreshInFlight","get","undefined","promise","refreshUnderLock","set","delete","Map","withFileLock","doDisco","readStoredOAuth","current","apiKey","access","expiresAt","expires","MAX_ATTEMPTS","failure","Promise","resolve","setTimeout","deviceLogin","deviceConfig","hooks","openaiDeviceLogin","persist","provider","tokens","persistOAuthTokens","assertSecureModes","authFilePath","CredentialError","credentialHome","readAuthFile","readStoredOAuth","writeCredential","deviceLogin","openaiDeviceLogin","pollDeviceToken","requestDeviceCode","ensureFreshCredential","extractAccountId","persistOAuthTokens","refreshOAuthTokens","providerFromApiKeyPrefix","openaiDeviceLogin","CODEX_CLIENT_ID","CODEX_ISSUER","CODEX_CLIENT_ID_ENV_VAR","CODEX_OAUTH","provider","clientId","process","env","authorizeEndpoint","tokenEndpoint","scopes","redirectUri","CODEX_DEVICE","deviceUsercodeEndpoint","devicePollEndpoint","verificationUri","CODEX_PROVIDER","Object","freeze","name","oauth","methods","label","type","authorize","deps","hooks","openaiDeviceLogin","comDefaults","fetch","sleep","ms","Promise","resolve","setTimeout","now","Date","loginWithDevice","method","store","opts","length","TypeError","includes","tokens","path","AuthProvider","persist","accountId","undefined","readFileSync","join","providerFromApiKeyPrefix","readAuthFile","TheokitAgentError","ProviderPrefixMismatchError","TheokitAgentError","name","provider","envKey","model","ProviderKeyMismatchError","where","expectedPrefix","code","isRetryable","DeclaredProviderError","message","CredentialNotFoundError","attempts","map","a","i","String","join","declaredNames","path","raw","readFileSync","Set","names","line","split","trimmed","trim","startsWith","withoutExport","slice","length","eq","indexOf","add","credentialSources","input","sources","providers","sort","b","priority","descriptor","store","undefined","config","push","dirName","fileName","assertKeyMatchesProvider","apiKey","inferred","providerFromApiKeyPrefix","keyPrefix","pinnedProvider","byPriority","declaredProviderEnvVar","declared","env","find","d","resolveCredential","pinned","kind","source","originOf","home","available","flatMap","claimed","claimedProvider","found","candidate","storedOAuthResolution","diagnose","console","warn","filePathOf","stored","readAuthFile","cause","Error","p","type","api_key","access","modelPrefix","varName","dotenv","has","requireCredential","resolved","DEFAULT_PROVIDERS","resolveAgentCredential","realpathSync","join","signatureOf","command","trim","replace","PermissionStore","path","lastReadError","options","join","home","now","Date","scope","realpathSync","cause","Error","message","String","isGranted","query","grant","tool","undefined","expiresAt","grants","filter","g","push","grantedAt","toISOString","ttlMs","revoke","signature","kept","list","expired","find","value","error","readSecureJson","raw","parsed","JSON","parse","Array","isArray","writeSecureJson","stringify"]}
|
|
1
|
+
{"version":3,"sources":["../src/auth/auth-provider.ts","../src/auth-entry.ts","../src/auth/device-provider.ts","../src/auth/resolve-credential.ts","../src/auth/permission-store.ts","../src/auth/permission-gate.ts"],"mappings":";;;;;;;;;;;;AAAA,SACEA,cACAC,uBACAC,mBACAC,oBACAC,uBACK;AAQP,SAASC,oBAAoB;AAkCtB,IAAMC,iBAAN,cAA6BC,MAAAA;EAhDpC,OAgDoCA;;;;EAClC,YACEC,SAESC,WACT;AACA,UAAMD,OAAAA,GAAAA,KAFGC,YAAAA;AAGT,SAAK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AAQC,MAAAA;AAC9D,UAAIP,MAAMQ,UAAUL,eAAeM,KAAK,EAAG,QAAOJ,QAAQC,QAAQC,MAAAA;AAIlE,YAAMG,UACJV,MAAMW,kBAAkBJ,SACpB,8BACA;AAQNK,eAAS,oCAAoC;QAC3CC,MAAMX,IAAIY;QACVC,OAAOZ,eAAeM,MAAMM;QAC5BL;MACF,CAAA;AACA,aAAOL,QAAQC,QAAQ;QACrBU,OAAO;QACPC,SAAS,IAAIf,IAAIY,IAAI,yBAAyBX,eAAeM,MAAMM,KAAK,KAAKL,OAAAA;MAC/E,CAAA;IACF,SAASQ,OAAO;AAGd,YAAMC,MAAMD,iBAAiBE,QAAQF,MAAMD,UAAUI,OAAOH,KAAAA;AAI5DN,eAAS,gDAAgD;QAAEC,MAAMX,IAAIY;QAAMK;MAAI,CAAA;AAC/E,aAAOd,QAAQC,QAAQ;QACrBU,OAAO;QACPC,SAAS,uCAAuCf,IAAIY,IAAI,MAAMK,GAAAA;MAChE,CAAA;IACF;EACF;AACF;AA/DgBpB;","names":["authFilePath","ensureFreshCredential","openaiDeviceLogin","persistOAuthTokens","readStoredOAuth","withFileLock","RefreshFailure","Error","message","transient","name","TRANSIENT_REASONS","classifyRefreshFailure","err","text","String","test","some","m","includes","waitWithJitter","attempt","baseMs","random","Math","base","round","AuthProvider","config","store","ensureFresh","resolved","deps","env","kind","ensureFreshCredential","filePath","authFilePath","inFlight","refreshInFlight","get","undefined","promise","refreshUnderLock","set","delete","Map","withFileLock","doDisco","readStoredOAuth","current","apiKey","access","expiresAt","expires","MAX_ATTEMPTS","failure","Promise","resolve","setTimeout","deviceLogin","deviceConfig","hooks","openaiDeviceLogin","persist","provider","tokens","persistOAuthTokens","assertSecureModes","authFilePath","CredentialError","credentialHome","readAuthFile","readStoredOAuth","writeCredential","deviceLogin","openaiDeviceLogin","pollDeviceToken","requestDeviceCode","ensureFreshCredential","extractAccountId","persistOAuthTokens","refreshOAuthTokens","providerFromApiKeyPrefix","openaiDeviceLogin","CODEX_CLIENT_ID","CODEX_ISSUER","CODEX_CLIENT_ID_ENV_VAR","CODEX_OAUTH","provider","clientId","process","env","authorizeEndpoint","tokenEndpoint","scopes","redirectUri","CODEX_DEVICE","deviceUsercodeEndpoint","devicePollEndpoint","verificationUri","CODEX_PROVIDER","Object","freeze","name","oauth","methods","label","type","authorize","deps","hooks","openaiDeviceLogin","comDefaults","fetch","sleep","ms","Promise","resolve","setTimeout","now","Date","loginWithDevice","method","store","opts","length","TypeError","includes","tokens","path","AuthProvider","persist","accountId","undefined","readFileSync","join","providerFromApiKeyPrefix","readAuthFile","TheokitAgentError","ProviderPrefixMismatchError","TheokitAgentError","name","provider","envKey","model","ProviderKeyMismatchError","where","expectedPrefix","code","isRetryable","DeclaredProviderError","message","CredentialNotFoundError","attempts","map","a","i","String","join","declaredNames","path","raw","readFileSync","Set","names","line","split","trimmed","trim","startsWith","withoutExport","slice","length","eq","indexOf","add","credentialSources","input","sources","providers","sort","b","priority","descriptor","store","undefined","config","push","dirName","fileName","assertKeyMatchesProvider","apiKey","inferred","providerFromApiKeyPrefix","keyPrefix","pinnedProvider","byPriority","declaredProviderEnvVar","declared","env","find","d","resolveCredential","pinned","kind","source","originOf","home","available","flatMap","claimed","claimedProvider","found","candidate","storedOAuthResolution","diagnose","console","warn","filePathOf","stored","readAuthFile","cause","Error","p","type","api_key","access","modelPrefix","varName","dotenv","has","requireCredential","resolved","DEFAULT_PROVIDERS","resolveAgentCredential","realpathSync","join","signatureOf","command","trim","replace","PermissionStore","path","lastReadError","options","join","home","now","Date","scope","realpathSync","cause","Error","message","String","isGranted","query","grant","tool","undefined","expiresAt","grants","filter","g","push","grantedAt","toISOString","ttlMs","revoke","signature","kept","list","expired","find","value","error","readSecureJson","raw","parsed","JSON","parse","Array","isArray","writeSecureJson","stringify","grantGate","store","classify","ctx","classification","governed","Promise","resolve","undefined","isGranted","query","because","lastReadError","debugLog","tool","name","scope","block","message","cause","why","Error","String"]}
|