@theokit/agents 16.3.0 → 16.5.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 +30 -0
- package/dist/a2a.d.ts +33 -1
- package/dist/a2a.js +353 -3
- package/dist/a2a.js.map +1 -1
- package/dist/{agent-compiler-JSYkHpa7.d.ts → agent-compiler-C-4X_vKz.d.ts} +1 -51
- package/dist/{agent-orchestrator-BFWg2URC.d.ts → agent-orchestrator-BHF1bS6k.d.ts} +1 -1
- package/dist/{agent-runner-BUJKNNuI.d.ts → agent-runner-BoMoOnHV.d.ts} +2 -2
- package/dist/auth.d.ts +5 -4
- package/dist/auth.js.map +1 -1
- package/dist/{bridge-entry-BNWDrPzg.d.ts → bridge-entry-DO1LjHkc.d.ts} +215 -8
- package/dist/bridge.d.ts +6 -6
- package/dist/bridge.js +25 -9
- package/dist/{chunk-A7RXWJZE.js → chunk-AZ2FOUSN.js} +450 -476
- package/dist/chunk-AZ2FOUSN.js.map +1 -0
- package/dist/{chunk-MB23MSOK.js → chunk-K4MY4CV7.js} +45 -22
- package/dist/chunk-K4MY4CV7.js.map +1 -0
- package/dist/{chunk-CJMYZKUL.js → chunk-RZWD73QG.js} +429 -14
- package/dist/chunk-RZWD73QG.js.map +1 -0
- package/dist/{chunk-SAKSZKVK.js → chunk-ZLKZOSWR.js} +39 -17
- package/dist/chunk-ZLKZOSWR.js.map +1 -0
- package/dist/code-mode-quickjs.d.ts +33 -0
- package/dist/code-mode-quickjs.js +353 -0
- package/dist/code-mode-quickjs.js.map +1 -0
- package/dist/code-mode.d.ts +110 -0
- package/dist/code-mode.js +165 -0
- package/dist/code-mode.js.map +1 -0
- package/dist/{delegation-scoring-Cn5eM4lQ.d.ts → delegation-scoring-BBPJ9eug.d.ts} +8 -2
- package/dist/evals.d.ts +2 -2
- package/dist/evals.js +3 -1
- package/dist/evals.js.map +1 -1
- package/dist/handoff.d.ts +3 -3
- package/dist/handoff.js +2 -2
- package/dist/index.d.ts +25 -10
- package/dist/index.js +31 -9
- package/dist/index.js.map +1 -1
- package/dist/persistence.d.ts +1 -1
- package/dist/persistence.js +2 -1
- package/dist/persistence.js.map +1 -1
- package/dist/sandbox.d.ts +1 -1
- package/dist/sandbox.js +2 -0
- package/dist/sandbox.js.map +1 -1
- package/dist/{sdk-adapter-DQnKx7bA.d.ts → sdk-adapter-C57SpmLH.d.ts} +3 -1
- package/dist/testing.d.ts +1 -1
- package/dist/tools.d.ts +140 -5
- package/dist/tools.js +591 -29
- package/dist/tools.js.map +1 -1
- package/docs/capability-map.md +80 -6
- package/package.json +23 -5
- package/dist/chunk-A7RXWJZE.js.map +0 -1
- package/dist/chunk-CJMYZKUL.js.map +0 -1
- package/dist/chunk-MB23MSOK.js.map +0 -1
- package/dist/chunk-SAKSZKVK.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @theokit/agents
|
|
2
2
|
|
|
3
|
+
## 16.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9de8fe7: `createOpenAICompatibleRoutes` answers `stream: true` with `chat.completion.chunk` server-sent events ending in `data: [DONE]`, and puts `usage` (`prompt_tokens`, `completion_tokens`, `total_tokens`) in the non-stream body and the final chunk. `complete` may return `{ text, usage }` and receives an `onDelta` callback while streaming. (#1518)
|
|
8
|
+
|
|
9
|
+
## 16.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- be2ce10: `@theokit/agents/a2a` serves and calls A2A's JSON-RPC `message/send`. `createA2AJsonRpcHandler({ authorize, respond, maxBodyBytes, timeoutMs })` answers a `message/send` request over Web `Request`/`Response`: an unauthorized request gets 401 before its body is read, the body is bounded, malformed requests get their JSON-RPC 2.0 error codes, and the turn is bounded by `timeoutMs` even when `respond` never settles. `createA2ATool({ protocol: 'jsonrpc' })` calls such a handler and returns the text of the `Message` or `Task` it answers; without `protocol` it sends exactly the request it sent before. `buildAgentCard` copies optional `securitySchemes` and `security` onto the card. (B-394)
|
|
14
|
+
- 42b14d3: `@theokit/agents` adds three things an agent uses inside its own turn. `@theokit/agents/code-mode` exports `createCodeMode`, moved from `theokit`. A script that calls tools as `api.<name>(input)` returns only its result to the model, and every call still passes the required permission gate. `@theokit/agents/code-mode-quickjs` exports `createQuickJsSandbox`, which runs each script in a fresh QuickJS-WASM runtime with nothing of the host visible (no `require`, `process`, `fetch` or timers). A run is bounded at 10 s wall clock (host calls included), 32 MiB of memory and 16 api calls. Every failure is a typed `CodeModeSandboxError` whose `code` is `script_error`, `timeout`, `memory_limit`, `call_limit` `unserialisable_result` or `cancelled`. A run ends with `cancelled` when the `signal` passed to `Sandbox.run(code, api, { signal })` aborts, and each host call receives a signal of its own that aborts when the run ends for any reason, so a tool still in flight after a timeout is told to stop. `createCodeMode`'s tool forwards the run's `ctx.signal` to the sandbox and to each tool a script calls. Its two VM packages, `quickjs-emscripten-core` and `@jitl/quickjs-wasmfile-release-sync` at 0.32.0, are optional peers, and no other entry point loads them. `@theokit/agents/tools` adds `createDelegateAllTool`, `delegate_all`: 1 to 4 delegations started together and answered together in input order. A refused task comes back as `{ agent, ok: false, error, message }` beside the others, and the same `defaults` apply to each task, so a `budget` bounds each task, not the call. It hands the run's `ctx.signal` to each `DelegationPort`, whose `run(message, { signal })` takes it as an optional second argument. (B-386)
|
|
15
|
+
|
|
16
|
+
`theokit/server/agent` keeps every export name. Its `code-mode` module now re-exports `@theokit/agents/code-mode`, so `createCodeMode` takes the SDK's `CustomTool` (a theokit tool is still accepted). Its `tool.handler` still resolves to a `string` (the new `CodeModeTool` type). `CodeModePermissionDeniedError` now extends `TheokitAgentError`, with `code: 'CODE_MODE_PERMISSION_DENIED'` and `isRetryable: false`. Its name and message are unchanged.
|
|
17
|
+
|
|
18
|
+
- 7e0f84c: `@theokit/agents/bridge` serves two new Web-standard HTTP surfaces (B-373). `createOpenAICompatibleRoutes({ models, complete })` answers `GET /v1/models` and a non-streaming `POST /v1/chat/completions` over a `complete` port that turns one request into the assistant's text, so the official OpenAI client can call an agent. Unknown OpenAI parameters are ignored, `stream: true` answers 400 `stream_unsupported`, an unserved model 404 `model_not_found`, and a rejected `complete` 502 `turn_failed` without the provider's message. `renderTranscript` renders the messages as one prompt. `createToolInvokeRoute({ tools, veto, validate })` answers `POST /tools/invoke` with `{tool, args}`: since a handler called directly skips the SDK's `pre_tool_call` plugins and its schema check, the caller passes a `veto` (403) and a `validate` (400 `invalid_args`), run in that order before the handler. Both read at most 1 MiB of body, counted as it streams (`readCappedBody`, `BodyTooLargeError`, `MAX_REQUEST_BODY_BYTES`). No dependency changes.
|
|
19
|
+
- bbe27df: `@theokit/agents/tools` gains scheduled runs. `createJobStore(file)` keeps jobs in one JSON file, written atomically with mode 0600, and refuses a malformed file with `ScheduleStoreError`. `createScheduler({ store, run, deliver })` registers each job as an SDK `Cron` workflow target: each fire runs the prompt with the previous answer's last 4000 characters framed as data, stores that tail, and delivers it unless the answer is `[SILENT]`. A failed run delivers one failure line, an overlapping fire is skipped, and `stop()` aborts in-flight runs, deletes this scheduler's SDK jobs, and stops the process-global SDK `Cron` timer only when no other SDK job remains. `createScheduleTools({ scheduler, platforms })` gives an owner's agent `schedule_job`, `list_scheduled_jobs` and `cancel_scheduled_job`. (B-396)
|
|
20
|
+
- 93cf651: `@theokit/agents/bridge` exports the `run.events()` timeline translator: `translateTimelineEvent`, `createToolSeen`, `flushPendingToolResults` and the `SdkTimelineEvent` type. A consumer that streams an SDK run's live text deltas translates them into the bridge's `StreamEvent`s with the code the SDK adapter uses, instead of copying it. Nothing that was exported changes. (B-376)
|
|
21
|
+
- dee3337: The `@theokit/sdk` floor is now 5.15.1, in `@theokit/agents`, `theokit` and the `create-theokit` template. 5.15.1 recovers several Gemini `<ctrl42>call` calls under one marker and keeps that text out of `text_delta` while streaming. `@theokit/agents/persistence` now re-exports `SqliteSessionStore` and `SqliteSessionStoreOptions`, and `@theokit/agents/sandbox` re-exports `DockerSandbox`, `DockerRunner`, `DockerRunResult` and `DockerSandboxConfig`, which the SDK added in 5.15.0.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- ef5a02e: Internal only, no API change: the scheduled-run preamble constant is no longer exported from its internal module (no public entry re-exported it), and the code-mode source comments stop citing ADR-0041 and ADR-0049, which were never written. (#1101, #1102)
|
|
26
|
+
- 3ad5b56: `generateAgentRoutes` chat route now reads the chat id `HttpTransport` sends as top-level `id` as the session id passed to `createRun`. `sessionId` still works and wins when both are sent; with neither, a session id is generated as before. (#1255)
|
|
27
|
+
- 2fbeb17: `@theokit/agents` code mode now reports the failures it used to drop. `createQuickJsSandbox` keeps its default for an option passed as `undefined`, and refuses a limit that cannot bound a run (a `timeoutMs` or `memoryLimitBytes` that is not a finite number above 0, a `maxCalls` that is not an integer of at least 0) when the sandbox is built, with the new `CodeModeSandboxConfigError` (`code: 'CODE_MODE_SANDBOX_CONFIG'`) exported from `@theokit/agents/code-mode-quickjs`. A run now waits up to 250 ms, after aborting them, for the host calls it started. A script that starts a host call it does not await, against a tool that ignores the abort, now fails with the new `CodeModeSandboxError` code `host_call_unsettled` instead of returning while the call still runs. (B-697)
|
|
28
|
+
- a08d373: The `@theokit/sdk` floor is now 5.14.0, in `@theokit/agents`, `theokit` and the `create-theokit` template. TheoClaw's plugin install (`installPlugin`, B-391) needs the SDK to import a trusted manifest entry, which 5.14.0 added; the bottom-of-range install now agrees with the root override.
|
|
29
|
+
- ef05872: The `@theokit/sdk` floor is now 5.15.3, in `@theokit/agents`, `theokit` and the `create-theokit` template. 5.15.3 bounds the wait for a model response's headers (30 s by default), so a request whose response never starts fails with a retryable `NetworkError` and is retried, instead of holding the turn for up to 300 s.
|
|
30
|
+
- Updated dependencies [1c3553b]
|
|
31
|
+
- @theokit/presenter@0.11.0
|
|
32
|
+
|
|
3
33
|
## 16.3.0
|
|
4
34
|
|
|
5
35
|
### Minor Changes
|
package/dist/a2a.d.ts
CHANGED
|
@@ -23,6 +23,12 @@ interface A2AToolConfig {
|
|
|
23
23
|
auth?: A2AAuth;
|
|
24
24
|
/** Injected fetch (defaults to the global). Narrowed to the call shape this client uses. */
|
|
25
25
|
fetchImpl?: (url: string, init: RequestInit) => Promise<Response>;
|
|
26
|
+
/**
|
|
27
|
+
* `'jsonrpc'` posts A2A's JSON-RPC `message/send` (the binding `createA2AJsonRpcHandler` serves)
|
|
28
|
+
* and reads its `Message` or `Task` result. Omitted, the tool posts TheoKit's `{ message }` body
|
|
29
|
+
* and reads the event stream a TheoKit agent route answers, exactly as before.
|
|
30
|
+
*/
|
|
31
|
+
protocol?: 'jsonrpc';
|
|
26
32
|
}
|
|
27
33
|
/**
|
|
28
34
|
* Create a tool that delegates to a remote A2A agent. The remote answers the `{ message }` POST with
|
|
@@ -34,4 +40,30 @@ interface A2AToolConfig {
|
|
|
34
40
|
*/
|
|
35
41
|
declare function createA2ATool(config: A2AToolConfig): CustomTool;
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
/**
|
|
44
|
+
* B-394 (OC-13) — serve A2A's JSON-RPC `message/send` over Web `Request`/`Response`.
|
|
45
|
+
*
|
|
46
|
+
* Transport only (ADR D1): this module owns the wire (auth order, body bound, JSON-RPC parsing,
|
|
47
|
+
* error codes, the result shape) and its caller owns the agent and the secrets, through
|
|
48
|
+
* `authorize` and `respond`. The pair to `createA2ATool({ protocol: 'jsonrpc' })`.
|
|
49
|
+
*
|
|
50
|
+
* Order: not POST → 405; `authorize` false → 401 with the body never read; a body over
|
|
51
|
+
* `maxBodyBytes` → 413; a body still arriving at the deadline → 408; every other answer is HTTP 200
|
|
52
|
+
* with a JSON-RPC 2.0 body. One deadline covers the read and the turn, and the handler answers
|
|
53
|
+
* -32603 when it passes whether or not `respond` has settled.
|
|
54
|
+
*/
|
|
55
|
+
/** What the caller supplies: who may call, and the agent turn that answers. */
|
|
56
|
+
interface A2AJsonRpcHandlerOptions {
|
|
57
|
+
/** Decide from the raw `Authorization` header; false answers 401 before the body is read. */
|
|
58
|
+
authorize(authorization: string | undefined): boolean;
|
|
59
|
+
/** Run one agent turn on the text of the message; abort when `signal` aborts. */
|
|
60
|
+
respond(text: string, signal: AbortSignal): Promise<string>;
|
|
61
|
+
/** The largest body read, in bytes; one more answers 413. */
|
|
62
|
+
maxBodyBytes: number;
|
|
63
|
+
/** One bound over reading the body and the turn, in milliseconds. */
|
|
64
|
+
timeoutMs: number;
|
|
65
|
+
}
|
|
66
|
+
/** Build the `message/send` handler. Each call keeps its own state; nothing is shared. */
|
|
67
|
+
declare function createA2AJsonRpcHandler(options: A2AJsonRpcHandlerOptions): (request: Request) => Promise<Response>;
|
|
68
|
+
|
|
69
|
+
export { type A2AAuth, type A2AJsonRpcHandlerOptions, type A2AToolConfig, createA2AJsonRpcHandler, createA2ATool };
|
package/dist/a2a.js
CHANGED
|
@@ -8,6 +8,10 @@ import {
|
|
|
8
8
|
} from "./chunk-Z4QWC7IK.js";
|
|
9
9
|
|
|
10
10
|
// src/a2a/a2a-client.ts
|
|
11
|
+
var JSON_RPC_HEADERS = {
|
|
12
|
+
accept: "application/json",
|
|
13
|
+
"content-type": "application/json"
|
|
14
|
+
};
|
|
11
15
|
function failure(name, reason, options) {
|
|
12
16
|
return new Error(`A2A call to "${name}" failed: ${reason}`, options);
|
|
13
17
|
}
|
|
@@ -43,6 +47,82 @@ async function readReply(name, res, signal) {
|
|
|
43
47
|
return text;
|
|
44
48
|
}
|
|
45
49
|
__name(readReply, "readReply");
|
|
50
|
+
function isRecord(value) {
|
|
51
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
__name(isRecord, "isRecord");
|
|
54
|
+
function textOfParts(parts) {
|
|
55
|
+
if (!Array.isArray(parts)) return void 0;
|
|
56
|
+
const texts = parts.flatMap((part) => isRecord(part) && part.kind === "text" && typeof part.text === "string" ? [
|
|
57
|
+
part.text
|
|
58
|
+
] : []);
|
|
59
|
+
return texts.length > 0 ? texts.join("\n") : void 0;
|
|
60
|
+
}
|
|
61
|
+
__name(textOfParts, "textOfParts");
|
|
62
|
+
function textOfTask(task) {
|
|
63
|
+
const status = isRecord(task.status) ? task.status : {};
|
|
64
|
+
const fromStatus = isRecord(status.message) ? textOfParts(status.message.parts) : void 0;
|
|
65
|
+
if (fromStatus !== void 0) return fromStatus;
|
|
66
|
+
if (!Array.isArray(task.artifacts)) return void 0;
|
|
67
|
+
const texts = task.artifacts.flatMap((artifact) => {
|
|
68
|
+
const text = isRecord(artifact) ? textOfParts(artifact.parts) : void 0;
|
|
69
|
+
return text === void 0 ? [] : [
|
|
70
|
+
text
|
|
71
|
+
];
|
|
72
|
+
});
|
|
73
|
+
return texts.length > 0 ? texts.join("\n") : void 0;
|
|
74
|
+
}
|
|
75
|
+
__name(textOfTask, "textOfTask");
|
|
76
|
+
async function readJsonRpcResult(name, res, signal) {
|
|
77
|
+
let body;
|
|
78
|
+
try {
|
|
79
|
+
body = await res.json();
|
|
80
|
+
} catch (err) {
|
|
81
|
+
signal?.throwIfAborted();
|
|
82
|
+
throw failure(name, "the answer was not JSON", {
|
|
83
|
+
cause: err
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (!isRecord(body)) throw failure(name, "the answer was not a JSON-RPC response");
|
|
87
|
+
if (isRecord(body.error)) {
|
|
88
|
+
const { code, message } = body.error;
|
|
89
|
+
const reason = [
|
|
90
|
+
typeof code === "number" ? String(code) : void 0,
|
|
91
|
+
typeof message === "string" ? message : void 0
|
|
92
|
+
].filter((part) => part !== void 0);
|
|
93
|
+
throw failure(name, reason.length > 0 ? reason.join(" ") : "the remote answered an error");
|
|
94
|
+
}
|
|
95
|
+
const result = isRecord(body.result) ? body.result : {};
|
|
96
|
+
if (result.kind === "message") return textOfParts(result.parts) ?? "";
|
|
97
|
+
if (result.kind === "task") {
|
|
98
|
+
const text = textOfTask(result);
|
|
99
|
+
if (text === void 0) throw failure(name, "the task answered no text");
|
|
100
|
+
return text;
|
|
101
|
+
}
|
|
102
|
+
throw failure(name, "the result was neither a message nor a task");
|
|
103
|
+
}
|
|
104
|
+
__name(readJsonRpcResult, "readJsonRpcResult");
|
|
105
|
+
function jsonRpcBody(message) {
|
|
106
|
+
return JSON.stringify({
|
|
107
|
+
jsonrpc: "2.0",
|
|
108
|
+
id: crypto.randomUUID(),
|
|
109
|
+
method: "message/send",
|
|
110
|
+
params: {
|
|
111
|
+
message: {
|
|
112
|
+
kind: "message",
|
|
113
|
+
role: "user",
|
|
114
|
+
messageId: crypto.randomUUID(),
|
|
115
|
+
parts: [
|
|
116
|
+
{
|
|
117
|
+
kind: "text",
|
|
118
|
+
text: message
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
__name(jsonRpcBody, "jsonRpcBody");
|
|
46
126
|
function createA2ATool(config) {
|
|
47
127
|
const { name, auth } = config;
|
|
48
128
|
const doFetch = config.fetchImpl ?? fetch;
|
|
@@ -63,14 +143,15 @@ function createA2ATool(config) {
|
|
|
63
143
|
},
|
|
64
144
|
async handler(input, ctx) {
|
|
65
145
|
const message = typeof input.message === "string" ? input.message : "";
|
|
146
|
+
const jsonRpc = config.protocol === "jsonrpc";
|
|
66
147
|
const res = await doFetch(config.url, {
|
|
67
148
|
method: "POST",
|
|
68
|
-
headers: agentRequestHeaders(AGENT_ACTION_HEADERS, config.headers, auth?.bearer ? {
|
|
149
|
+
headers: agentRequestHeaders(jsonRpc ? JSON_RPC_HEADERS : AGENT_ACTION_HEADERS, config.headers, auth?.bearer ? {
|
|
69
150
|
authorization: `Bearer ${auth.bearer}`
|
|
70
151
|
} : void 0, auth?.apiKey ? {
|
|
71
152
|
[auth.apiKey.header]: auth.apiKey.value
|
|
72
153
|
} : void 0),
|
|
73
|
-
body: JSON.stringify({
|
|
154
|
+
body: jsonRpc ? jsonRpcBody(message) : JSON.stringify({
|
|
74
155
|
message
|
|
75
156
|
}),
|
|
76
157
|
signal: ctx?.signal
|
|
@@ -79,12 +160,281 @@ function createA2ATool(config) {
|
|
|
79
160
|
await res.body?.cancel().catch(() => void 0);
|
|
80
161
|
throw failure(name, `${res.status} ${res.statusText}`);
|
|
81
162
|
}
|
|
82
|
-
return readReply(name, res, ctx?.signal);
|
|
163
|
+
return jsonRpc ? readJsonRpcResult(name, res, ctx?.signal) : readReply(name, res, ctx?.signal);
|
|
83
164
|
}
|
|
84
165
|
};
|
|
85
166
|
}
|
|
86
167
|
__name(createA2ATool, "createA2ATool");
|
|
168
|
+
|
|
169
|
+
// src/a2a/a2a-json-rpc-handler.ts
|
|
170
|
+
var JSON_HEADERS = {
|
|
171
|
+
"content-type": "application/json"
|
|
172
|
+
};
|
|
173
|
+
var PARSE_ERROR = -32700;
|
|
174
|
+
var INVALID_REQUEST = -32600;
|
|
175
|
+
var METHOD_NOT_FOUND = -32601;
|
|
176
|
+
var INVALID_PARAMS = -32602;
|
|
177
|
+
var INTERNAL_ERROR = -32603;
|
|
178
|
+
function rpcResult(id, result) {
|
|
179
|
+
return new Response(JSON.stringify({
|
|
180
|
+
jsonrpc: "2.0",
|
|
181
|
+
id,
|
|
182
|
+
result
|
|
183
|
+
}), {
|
|
184
|
+
headers: JSON_HEADERS
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
__name(rpcResult, "rpcResult");
|
|
188
|
+
function rpcError(id, code, message) {
|
|
189
|
+
return new Response(JSON.stringify({
|
|
190
|
+
jsonrpc: "2.0",
|
|
191
|
+
id,
|
|
192
|
+
error: {
|
|
193
|
+
code,
|
|
194
|
+
message
|
|
195
|
+
}
|
|
196
|
+
}), {
|
|
197
|
+
headers: JSON_HEADERS
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
__name(rpcError, "rpcError");
|
|
201
|
+
function abortOf(signal) {
|
|
202
|
+
let listener;
|
|
203
|
+
const aborted = new Promise((resolve) => {
|
|
204
|
+
if (signal.aborted) {
|
|
205
|
+
resolve();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
listener = /* @__PURE__ */ __name(() => {
|
|
209
|
+
resolve();
|
|
210
|
+
}, "listener");
|
|
211
|
+
signal.addEventListener("abort", listener, {
|
|
212
|
+
once: true
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
const off = /* @__PURE__ */ __name(() => {
|
|
216
|
+
if (listener) signal.removeEventListener("abort", listener);
|
|
217
|
+
}, "off");
|
|
218
|
+
return {
|
|
219
|
+
aborted,
|
|
220
|
+
off
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
__name(abortOf, "abortOf");
|
|
224
|
+
function hasAborted(signal) {
|
|
225
|
+
return signal.aborted;
|
|
226
|
+
}
|
|
227
|
+
__name(hasAborted, "hasAborted");
|
|
228
|
+
async function readBoundedBody(request, maxBytes, deadline) {
|
|
229
|
+
if (!request.body) return {
|
|
230
|
+
ok: true,
|
|
231
|
+
bytes: new Uint8Array()
|
|
232
|
+
};
|
|
233
|
+
const reader = request.body.getReader();
|
|
234
|
+
const chunks = [];
|
|
235
|
+
let total = 0;
|
|
236
|
+
const onAbort = /* @__PURE__ */ __name(() => {
|
|
237
|
+
reader.cancel().catch(() => void 0);
|
|
238
|
+
}, "onAbort");
|
|
239
|
+
deadline.addEventListener("abort", onAbort, {
|
|
240
|
+
once: true
|
|
241
|
+
});
|
|
242
|
+
try {
|
|
243
|
+
for (; ; ) {
|
|
244
|
+
if (hasAborted(deadline)) return {
|
|
245
|
+
ok: false,
|
|
246
|
+
status: 408
|
|
247
|
+
};
|
|
248
|
+
const { done, value } = await reader.read();
|
|
249
|
+
if (hasAborted(deadline)) return {
|
|
250
|
+
ok: false,
|
|
251
|
+
status: 408
|
|
252
|
+
};
|
|
253
|
+
if (done) break;
|
|
254
|
+
total += value.byteLength;
|
|
255
|
+
if (total > maxBytes) {
|
|
256
|
+
await reader.cancel().catch(() => void 0);
|
|
257
|
+
return {
|
|
258
|
+
ok: false,
|
|
259
|
+
status: 413
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
chunks.push(value);
|
|
263
|
+
}
|
|
264
|
+
} catch {
|
|
265
|
+
return {
|
|
266
|
+
ok: false,
|
|
267
|
+
status: hasAborted(deadline) ? 408 : 400
|
|
268
|
+
};
|
|
269
|
+
} finally {
|
|
270
|
+
deadline.removeEventListener("abort", onAbort);
|
|
271
|
+
}
|
|
272
|
+
const bytes = new Uint8Array(total);
|
|
273
|
+
let offset = 0;
|
|
274
|
+
for (const chunk of chunks) {
|
|
275
|
+
bytes.set(chunk, offset);
|
|
276
|
+
offset += chunk.byteLength;
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
ok: true,
|
|
280
|
+
bytes
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
__name(readBoundedBody, "readBoundedBody");
|
|
284
|
+
function isRecord2(value) {
|
|
285
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
286
|
+
}
|
|
287
|
+
__name(isRecord2, "isRecord");
|
|
288
|
+
function isRpcId(value) {
|
|
289
|
+
return typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
290
|
+
}
|
|
291
|
+
__name(isRpcId, "isRpcId");
|
|
292
|
+
function textPartsOf(params) {
|
|
293
|
+
if (!isRecord2(params) || !isRecord2(params.message)) return void 0;
|
|
294
|
+
const parts = params.message.parts;
|
|
295
|
+
if (!Array.isArray(parts)) return void 0;
|
|
296
|
+
const texts = parts.flatMap((part) => isRecord2(part) && part.kind === "text" && typeof part.text === "string" && part.text !== "" ? [
|
|
297
|
+
part.text
|
|
298
|
+
] : []);
|
|
299
|
+
return texts.length > 0 ? texts : void 0;
|
|
300
|
+
}
|
|
301
|
+
__name(textPartsOf, "textPartsOf");
|
|
302
|
+
function parseRequest(bytes) {
|
|
303
|
+
let body;
|
|
304
|
+
try {
|
|
305
|
+
body = JSON.parse(new TextDecoder().decode(bytes));
|
|
306
|
+
} catch {
|
|
307
|
+
return {
|
|
308
|
+
ok: false,
|
|
309
|
+
response: rpcError(null, PARSE_ERROR, "parse error")
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (!isRecord2(body) || body.jsonrpc !== "2.0" || typeof body.method !== "string") {
|
|
313
|
+
return {
|
|
314
|
+
ok: false,
|
|
315
|
+
response: rpcError(null, INVALID_REQUEST, "invalid request")
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
if (!isRpcId(body.id)) {
|
|
319
|
+
return {
|
|
320
|
+
ok: false,
|
|
321
|
+
response: rpcError(null, INVALID_REQUEST, "invalid request")
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const id = body.id;
|
|
325
|
+
if (body.method !== "message/send") {
|
|
326
|
+
return {
|
|
327
|
+
ok: false,
|
|
328
|
+
response: rpcError(id, METHOD_NOT_FOUND, `method not found: ${body.method}`)
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
const texts = textPartsOf(body.params);
|
|
332
|
+
if (!texts) {
|
|
333
|
+
return {
|
|
334
|
+
ok: false,
|
|
335
|
+
response: rpcError(id, INVALID_PARAMS, "params.message holds no non-empty text part")
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
ok: true,
|
|
340
|
+
id,
|
|
341
|
+
text: texts.join("\n")
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
__name(parseRequest, "parseRequest");
|
|
345
|
+
function nextMacrotask() {
|
|
346
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
347
|
+
}
|
|
348
|
+
__name(nextMacrotask, "nextMacrotask");
|
|
349
|
+
async function runTurn(options, id, text, deadline) {
|
|
350
|
+
const turn = Promise.resolve().then(() => options.respond(text, deadline)).then((reply) => ({
|
|
351
|
+
settled: true,
|
|
352
|
+
reply
|
|
353
|
+
}), () => ({
|
|
354
|
+
settled: false
|
|
355
|
+
}));
|
|
356
|
+
const { aborted, off } = abortOf(deadline);
|
|
357
|
+
let outcome;
|
|
358
|
+
try {
|
|
359
|
+
outcome = await Promise.race([
|
|
360
|
+
turn,
|
|
361
|
+
aborted.then(() => void 0)
|
|
362
|
+
]);
|
|
363
|
+
outcome ??= await Promise.race([
|
|
364
|
+
turn,
|
|
365
|
+
nextMacrotask().then(() => void 0)
|
|
366
|
+
]);
|
|
367
|
+
} finally {
|
|
368
|
+
off();
|
|
369
|
+
}
|
|
370
|
+
if (outcome?.settled) {
|
|
371
|
+
return rpcResult(id, {
|
|
372
|
+
kind: "message",
|
|
373
|
+
role: "agent",
|
|
374
|
+
messageId: crypto.randomUUID(),
|
|
375
|
+
parts: [
|
|
376
|
+
{
|
|
377
|
+
kind: "text",
|
|
378
|
+
text: outcome.reply
|
|
379
|
+
}
|
|
380
|
+
]
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
if (outcome === void 0 || hasAborted(deadline)) {
|
|
384
|
+
return rpcError(id, INTERNAL_ERROR, `the agent turn ran out of time after ${options.timeoutMs} ms`);
|
|
385
|
+
}
|
|
386
|
+
return rpcError(id, INTERNAL_ERROR, "the agent turn failed");
|
|
387
|
+
}
|
|
388
|
+
__name(runTurn, "runTurn");
|
|
389
|
+
async function handle(options, request, deadline) {
|
|
390
|
+
if (request.method !== "POST") {
|
|
391
|
+
return new Response(null, {
|
|
392
|
+
status: 405,
|
|
393
|
+
headers: {
|
|
394
|
+
allow: "POST"
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
if (!options.authorize(request.headers.get("authorization") ?? void 0)) {
|
|
399
|
+
return new Response(null, {
|
|
400
|
+
status: 401,
|
|
401
|
+
headers: {
|
|
402
|
+
"www-authenticate": "Bearer"
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
const read = await readBoundedBody(request, options.maxBodyBytes, deadline);
|
|
407
|
+
if (!read.ok) return new Response(null, {
|
|
408
|
+
status: read.status
|
|
409
|
+
});
|
|
410
|
+
const parsed = parseRequest(read.bytes);
|
|
411
|
+
if (!parsed.ok) return parsed.response;
|
|
412
|
+
return runTurn(options, parsed.id, parsed.text, deadline);
|
|
413
|
+
}
|
|
414
|
+
__name(handle, "handle");
|
|
415
|
+
function createA2AJsonRpcHandler(options) {
|
|
416
|
+
return async (request) => {
|
|
417
|
+
const controller = new AbortController();
|
|
418
|
+
const abort = /* @__PURE__ */ __name(() => {
|
|
419
|
+
controller.abort();
|
|
420
|
+
}, "abort");
|
|
421
|
+
const timer = setTimeout(abort, options.timeoutMs);
|
|
422
|
+
if (request.signal.aborted) abort();
|
|
423
|
+
else request.signal.addEventListener("abort", abort, {
|
|
424
|
+
once: true
|
|
425
|
+
});
|
|
426
|
+
const deadline = controller.signal;
|
|
427
|
+
try {
|
|
428
|
+
return await handle(options, request, deadline);
|
|
429
|
+
} finally {
|
|
430
|
+
clearTimeout(timer);
|
|
431
|
+
request.signal.removeEventListener("abort", abort);
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
__name(createA2AJsonRpcHandler, "createA2AJsonRpcHandler");
|
|
87
436
|
export {
|
|
437
|
+
createA2AJsonRpcHandler,
|
|
88
438
|
createA2ATool
|
|
89
439
|
};
|
|
90
440
|
//# sourceMappingURL=a2a.js.map
|
package/dist/a2a.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/a2a/a2a-client.ts"],"mappings":";;;;;;;;;;AA+CA,SAASA,QAAQC,MAAcC,QAAgBC,SAAsB;AACnE,SAAO,IAAIC,MAAM,gBAAgBH,IAAAA,aAAiBC,MAAAA,IAAUC,OAAAA;AAC9D;AAFSH;AAST,eAAeK,UAAUJ,MAAcK,KAAeC,QAAoB;AACxE,MAAIC,QAA8B,CAAA;AAClC,MAAIC;AACJ,MAAI;AACFA,cAAU,MAAMC,uBAAuBJ,KAAK,CAACK,MAAAA;AAC3CH,cAAQG,EAAEH;AAGV,YAAMI,OAAOJ,MAAMK,KAAK,CAACC,SAASA,KAAKC,UAAU,oBA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ACRvB,SAASwB,oBACPC,sBACAf,OAAOV,SACPW,MAAMe,SAAS;UAAEC,eAAe,UAAUhB,KAAKe,MAAM;QAAG,IAAIE,QAC5DjB,MAAMkB,SAAS;UAAE,CAAClB,KAAKkB,OAAOC,MAAM,GAAGnB,KAAKkB,OAAOE;QAAM,IAAIH,MAAAA;QAE/DI,MAAMC,KAAKC,UAAU;UAAExC;QAAQ,CAAA;QAC/Bb,QAAQwC,KAAKxC;MACf,CAAA;AACA,UAAI,CAACD,IAAIuD,IAAI;AAGX,cAAMvD,IAAIoD,MAAMI,OAAAA,EAASC,MAAM,MAAMT,MAAAA;AACrC,cAAMtD,QAAQC,MAAM,GAAGK,IAAI0D,MAAM,IAAI1D,IAAI2D,UAAU,EAAE;MACvD;AACA,aAAO5D,UAAUJ,MAAMK,KAAKyC,KAAKxC,MAAAA;IACnC;EACF;AACF;AAzCgB4B;","names":["failure","name","reason","options","Error","readReply","res","signal","parts","outcome","consumeUIMessageStream","m","gate","find","part","state","String","toolName","err","throwIfAborted","message","cause","chunks","chunksReceived","terminated","type","headers","get","text","map","filter","Boolean","join","dropped","framesDropped","createA2ATool","config","auth","doFetch","fetchImpl","fetch","description","inputSchema","properties","required","handler","input","ctx","url","method","agentRequestHeaders","AGENT_ACTION_HEADERS","bearer","authorization","undefined","apiKey","header","value","body","JSON","stringify","ok","cancel","catch","status","statusText"]}
|
|
1
|
+
{"version":3,"sources":["../src/a2a/a2a-client.ts","../src/a2a/a2a-json-rpc-handler.ts"],"mappings":";;;;;;;;;;AAqDA,IAAMA,mBAAqD;EACzDC,QAAQ;EACR,gBAAgB;AAClB;AAGA,SAASC,QAAQC,MAAcC,QAAgBC,SAAsB;AACnE,SAAO,IAAIC,MAAM,gBAAgBH,IAAAA,aAAiBC,MAAAA,IAAUC,OAAAA;AAC9D;AAFSH;AAST,eAAeK,UAAUJ,MAAcK,KAAeC,QAAoB;AACxE,MAAIC,QAA8B,CAAA;AAClC,MAAIC;AACJ,MAAI;AACFA,c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,OAAOtB,QAAQY,SAAS;AACjD,QAAI7D,QAAQX,OAAOE,QAASgF,OAAAA;QACvBvE,SAAQX,OAAOK,iBAAiB,SAAS6E,OAAO;MAAE5E,MAAM;IAAK,CAAA;AAClE,UAAMO,WAAWmE,WAAWhF;AAC5B,QAAI;AACF,aAAO,MAAMyE,OAAOb,SAASjD,SAASE,QAAAA;IACxC,UAAA;AACEuE,mBAAaD,KAAAA;AACbxE,cAAQX,OAAOQ,oBAAoB,SAAS0E,KAAAA;IAC9C;EACF;AACF;AAtBgBH;","names":["JSON_RPC_HEADERS","accept","failure","name","reason","options","Error","readReply","res","signal","parts","outcome","consumeUIMessageStream","m","gate","find","part","state","String","toolName","err","throwIfAborted","message","cause","chunks","chunksReceived","terminated","type","headers","get","text","map","filter","Boolean","join","dropped","framesDropped","isRecord","value","Array","isArray","textOfParts","undefined","texts","flatMap","kind","length","textOfTask","task","status","fromStatus","artifacts","artifact","readJsonRpcResult","body","json","error","code","result","jsonRpcBody","JSON","stringify","jsonrpc","id","crypto","randomUUID","method","params","role","messageId","createA2ATool","config","auth","doFetch","fetchImpl","fetch","description","inputSchema","properties","required","handler","input","ctx","jsonRpc","protocol","url","agentRequestHeaders","AGENT_ACTION_HEADERS","bearer","authorization","apiKey","header","ok","cancel","catch","statusText","JSON_HEADERS","PARSE_ERROR","INVALID_REQUEST","METHOD_NOT_FOUND","INVALID_PARAMS","INTERNAL_ERROR","rpcResult","id","result","Response","JSON","stringify","jsonrpc","headers","rpcError","code","message","error","abortOf","signal","listener","aborted","Promise","resolve","addEventListener","once","off","removeEventListener","hasAborted","readBoundedBody","request","maxBytes","deadline","body","ok","bytes","Uint8Array","reader","getReader","chunks","total","onAbort","cancel","catch","undefined","status","done","value","read","byteLength","push","offset","chunk","set","isRecord","Array","isArray","isRpcId","Number","isFinite","textPartsOf","params","parts","texts","flatMap","part","kind","text","length","parseRequest","parse","TextDecoder","decode","response","method","join","nextMacrotask","setTimeout","runTurn","options","turn","then","respond","reply","settled","outcome","race","role","messageId","crypto","randomUUID","timeoutMs","handle","allow","authorize","get","maxBodyBytes","parsed","createA2AJsonRpcHandler","controller","AbortController","abort","timer","clearTimeout"]}
|
|
@@ -228,56 +228,6 @@ interface HookApprovalRequest {
|
|
|
228
228
|
readonly sourcePath?: string;
|
|
229
229
|
readonly matcher?: string;
|
|
230
230
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Refuses when the installed SDK cannot honour a declared hook gate.
|
|
233
|
-
*
|
|
234
|
-
* ## Why this THROWS where its `compatSources` sibling only warns
|
|
235
|
-
*
|
|
236
|
-
* That one guards a configuration source: ignored, the foreign root is not read, and the agent runs
|
|
237
|
-
* with less than was asked for. This one guards a SECURITY decision. Ignored, the agent runs with
|
|
238
|
-
* MORE than was asked for — every hook spawns unreviewed — while the consumer believes it is gated
|
|
239
|
-
* and stops looking. The consumer that reported #686 asked for the refusal in those words: they
|
|
240
|
-
* would rather have no gate than a silent one, because their `doctor` would otherwise publish a
|
|
241
|
-
* guarantee that is false on `@theokit/sdk@5.0.0`.
|
|
242
|
-
*
|
|
243
|
-
* ## Why an unreadable version is a refusal and not a shrug
|
|
244
|
-
*
|
|
245
|
-
* The sibling stays silent when it cannot read the version, and that is right for a diagnostic. Here
|
|
246
|
-
* "cannot tell" and "is gated" must not collapse: unproven is not proven, and this whole issue is
|
|
247
|
-
* one instance of that confusion. A bundled SDK that hides `package.json` gets an explicit refusal
|
|
248
|
-
* naming what it could not read, which is recoverable; a silent pass is not.
|
|
249
|
-
*/
|
|
250
|
-
declare class HookGateUnsupportedError extends TheokitAgentError {
|
|
251
|
-
readonly name = "HookGateUnsupportedError";
|
|
252
|
-
constructor(version: string | undefined);
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* A narrowed `import` on an SDK that cannot read it.
|
|
256
|
-
*
|
|
257
|
-
* Refuses rather than warns, and the asymmetry with {@link warnIfSdkCannotReadCompatSources} is
|
|
258
|
-
* deliberate: an unrecognised `compatSources` shape means the foreign root is not read, so a
|
|
259
|
-
* consumer who asked for "the skills but not the hooks" silently gets NOTHING — strictly further
|
|
260
|
-
* from what they asked for than the un-narrowed form, which at least reads something. Failing loud
|
|
261
|
-
* is recoverable; a silent nothing is discovered by wondering why a skill is missing.
|
|
262
|
-
*
|
|
263
|
-
* ## The cost, which this file argues against two functions above
|
|
264
|
-
*
|
|
265
|
-
* An unreadable version is refused too, on the principle {@link assertSdkCanGateHooks} states:
|
|
266
|
-
* "cannot tell" and "is supported" must not collapse. The sibling WARNING takes the opposite view
|
|
267
|
-
* for itself — *"a bundled or vendored SDK may not resolve that subpath, and refusing to create an
|
|
268
|
-
* agent over a diagnostic would be the cure being worse than the disease."*
|
|
269
|
-
*
|
|
270
|
-
* Both are right for what they guard, and the difference is what the check IS. A diagnostic that
|
|
271
|
-
* cannot read a version should stay quiet; a GATE that cannot read one has not established the
|
|
272
|
-
* thing it exists to establish. But the cost is real and belongs here rather than in a reviewer's
|
|
273
|
-
* report: a consumer who bundles the SDK so `@theokit/sdk/package.json` does not resolve cannot
|
|
274
|
-
* create an agent with a narrowed `import`, even on 5.4.0+. Their exit is to omit `import` and read
|
|
275
|
-
* the whole root.
|
|
276
|
-
*/
|
|
277
|
-
declare class CompatImportUnsupportedError extends TheokitAgentError {
|
|
278
|
-
readonly name = "CompatImportUnsupportedError";
|
|
279
|
-
constructor(version: string | undefined);
|
|
280
|
-
}
|
|
281
231
|
|
|
282
232
|
/**
|
|
283
233
|
* M2 (theokit-ai-first) — `defineAgent`, the zero-config imperative agent surface.
|
|
@@ -695,4 +645,4 @@ interface CompiledAgentOptions {
|
|
|
695
645
|
skillsResolver?: SkillsSelection;
|
|
696
646
|
}
|
|
697
647
|
|
|
698
|
-
export { type AgentDefinition as A, type CompiledTool as C, type DefineAgentConfig as D, type Guardrail as G, type HookApprovalGate as H, type InferAgentInput as I, MalformedGuardrailResultError as M, type SkillsRequestContext as S, type ToolWalkResult as T, UnreadableTextPayloadError as U, type CompiledAgentOptions as a, AGENT_BRAND as b,
|
|
648
|
+
export { type AgentDefinition as A, type CompiledTool as C, type DefineAgentConfig as D, type Guardrail as G, type HookApprovalGate as H, type InferAgentInput as I, MalformedGuardrailResultError as M, type SkillsRequestContext as S, type ToolWalkResult as T, UnreadableTextPayloadError as U, type CompiledAgentOptions as a, AGENT_BRAND as b, CostBudgetExceededError as c, type GuardrailAction as d, GuardrailError as e, type GuardrailPhase as f, type GuardrailResult as g, GuardrailViolationError as h, type HookApprovalRequest as i, type InferAgentToolNames as j, type SkillsSelection as k, type ToolboxWalkResult as l, compileAgentDefinition as m, compileTools as n, isAgentDefinition as o, type SubagentAgentDefinition as p, type CodePlugin as q, resolveEnabledSkills as r };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PluginsSettings, ProviderRoutingSettings, AgentDefinition, BudgetTracker, CustomTool } from '@theokit/sdk';
|
|
2
2
|
import { RetryOptions } from '@theokit/sdk/retry';
|
|
3
|
-
import { a as CompiledAgentOptions, C as CompiledTool } from './agent-compiler-
|
|
3
|
+
import { a as CompiledAgentOptions, C as CompiledTool } from './agent-compiler-C-4X_vKz.js';
|
|
4
4
|
import { TheokitAgentError } from '@theokit/sdk/errors';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { M as MainLoopMeta } from './types-D5cHmSLi.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition, BudgetTracker, CustomTool } from '@theokit/sdk';
|
|
2
2
|
import { RetryOptions } from '@theokit/sdk/retry';
|
|
3
|
-
import { C as CompiledTool, a as CompiledAgentOptions } from './agent-compiler-
|
|
3
|
+
import { C as CompiledTool, a as CompiledAgentOptions } from './agent-compiler-C-4X_vKz.js';
|
|
4
4
|
import { S as StreamEvent } from './agent-sse-handler-BRp9vHrb.js';
|
|
5
|
-
import { R as RoundStreamFactory, L as LoopStrategy, b as ReflectionStrategy, D as DelegationResult } from './agent-orchestrator-
|
|
5
|
+
import { R as RoundStreamFactory, L as LoopStrategy, b as ReflectionStrategy, D as DelegationResult } from './agent-orchestrator-BHF1bS6k.js';
|
|
6
6
|
import { B as BudgetOptions, R as ReasoningEffort, M as MainLoopMeta } from './types-D5cHmSLi.js';
|
|
7
7
|
import { CompressibleMessage } from '@theokit/sdk/compaction';
|
|
8
8
|
import { z } from 'zod';
|
package/dist/auth.d.ts
CHANGED
|
@@ -27,10 +27,11 @@ type DeviceLoginHooks = Parameters<typeof openaiDeviceLogin>[2];
|
|
|
27
27
|
/** How an {@link AuthProvider} decides when a token is stale. */
|
|
28
28
|
interface AuthProviderOptions {
|
|
29
29
|
/**
|
|
30
|
-
* Refresh when the stored access token has less than this many milliseconds left
|
|
31
|
-
*
|
|
32
|
-
* for a long time (a sandboxed agent run, a batch
|
|
33
|
-
* to the value re-read under the lock, so it
|
|
30
|
+
* Refresh when the stored access token has less than this many milliseconds left plus the SDK's
|
|
31
|
+
* one-minute skew, which still applies on top, instead of only within that skew. For a consumer
|
|
32
|
+
* that hands the token to a process that keeps it for a long time (a sandboxed agent run, a batch
|
|
33
|
+
* job), so the token outlives the process. Applied to the value re-read under the lock, so it
|
|
34
|
+
* composes with the double-checked locking (#1286).
|
|
34
35
|
* Default `0`: the SDK's own skew decides, as before.
|
|
35
36
|
*/
|
|
36
37
|
readonly refreshBeforeMs?: number;
|