@orkestrel/agent 0.0.22 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/index.cjs +36 -19
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +19 -8
- package/dist/src/core/index.d.ts +19 -8
- package/dist/src/core/index.js +37 -20
- package/dist/src/core/index.js.map +1 -1
- package/package.json +16 -16
|
@@ -486,6 +486,14 @@ export declare type AgentEventMap = {
|
|
|
486
486
|
* - **Bounded.** Each turn arms a single cancel folded from the external `signal`, the
|
|
487
487
|
* `timeout` deadline, and the `budget` signal (through `AbortSignal.any`); any of them —
|
|
488
488
|
* or `abort()` — stops the loop and settles the result `partial: true`.
|
|
489
|
+
* Tool handlers receive that run's signal through their `ToolContext`. An agent abort,
|
|
490
|
+
* stream abort, external signal, or deadline can reach a running handler. The budget is
|
|
491
|
+
* charged during provider streaming and between turns, before tool dispatch; exhaustion
|
|
492
|
+
* ends the run without dispatching, never inside a handler. An abort before dispatch
|
|
493
|
+
* appends neither the assistant call turn nor tool messages and emits no tool chunk;
|
|
494
|
+
* streamed content remains in the partial result. Cancellation after entry is cooperative:
|
|
495
|
+
* the loop awaits a running handler even when it ignores the signal.
|
|
496
|
+
* The agent supplies no caller identity.
|
|
489
497
|
* - **Paced + capped.** The `scheduler` (when given) yields between turns; tool
|
|
490
498
|
* iteration is capped at `limit` so the loop always terminates.
|
|
491
499
|
* - **Two observation surfaces.** Pull: the {@link AgentChunk} stream (`stream().events`)
|
|
@@ -3826,7 +3834,7 @@ export declare type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
|
3826
3834
|
*
|
|
3827
3835
|
* @remarks
|
|
3828
3836
|
* The wire is strictly narrower than Message: non-JSON call arguments are refused,
|
|
3829
|
-
* and
|
|
3837
|
+
* and execution context stays local. The guard refuses extra members; the parser drops them.
|
|
3830
3838
|
*/
|
|
3831
3839
|
export declare const messageShape: ObjectShape< {
|
|
3832
3840
|
id: StringShape;
|
|
@@ -4056,7 +4064,8 @@ readonly [k: string]: JSONValue;
|
|
|
4056
4064
|
*
|
|
4057
4065
|
* @remarks
|
|
4058
4066
|
* The wire is strictly narrower than ProviderRequest: non-JSON arguments, parameters,
|
|
4059
|
-
* or schema members are refused
|
|
4067
|
+
* or schema members are refused. Execution context stays local; the guard refuses
|
|
4068
|
+
* extra members, and the parser drops them.
|
|
4060
4069
|
*/
|
|
4061
4070
|
export declare const providerRequestShape: ObjectShape< {
|
|
4062
4071
|
messages: ArrayShape<ObjectShape< {
|
|
@@ -4130,7 +4139,7 @@ total: number;
|
|
|
4130
4139
|
*
|
|
4131
4140
|
* @remarks
|
|
4132
4141
|
* The wire is strictly narrower than ProviderResult: non-JSON call arguments are
|
|
4133
|
-
* refused, and
|
|
4142
|
+
* refused. Execution context stays local; the guard refuses extra members, and the parser drops them.
|
|
4134
4143
|
*/
|
|
4135
4144
|
export declare const providerResultShape: ObjectShape< {
|
|
4136
4145
|
content: StringShape;
|
|
@@ -4284,7 +4293,8 @@ message: string;
|
|
|
4284
4293
|
*
|
|
4285
4294
|
* @remarks
|
|
4286
4295
|
* The wire is strictly narrower than RelayFrame through its result and partial
|
|
4287
|
-
* fields: non-JSON arguments are refused
|
|
4296
|
+
* fields: non-JSON arguments are refused. Execution context stays local; the guard
|
|
4297
|
+
* refuses extra members, and the parser drops them.
|
|
4288
4298
|
*/
|
|
4289
4299
|
export declare const relayFrameShape: UnionShape<readonly [ObjectShape< {
|
|
4290
4300
|
channel: LiteralShape<readonly ["content", "thinking"]>;
|
|
@@ -4353,7 +4363,8 @@ export declare interface RelayOptions {
|
|
|
4353
4363
|
* Carries provider calls over an authenticated NDJSON relay endpoint.
|
|
4354
4364
|
*
|
|
4355
4365
|
* @remarks
|
|
4356
|
-
*
|
|
4366
|
+
* Tool execution context stays local; calls carry only `id`, `name`, and `arguments`.
|
|
4367
|
+
* The wire body is an owned snapshot of
|
|
4357
4368
|
* the projection read through property descriptors, so a serializer reachable only through a
|
|
4358
4369
|
* `get` trap or a prototype is never consulted; an own function-valued property such as a
|
|
4359
4370
|
* `toJSON` method is a value outside JSON and is refused before fetching, with the clone's
|
|
@@ -4398,7 +4409,7 @@ export declare class RelayProvider extends AgentProvider {
|
|
|
4398
4409
|
* value carries is ignored rather than consulted and cannot reach the wire.
|
|
4399
4410
|
*
|
|
4400
4411
|
* @param request - The domain conversation and call configuration
|
|
4401
|
-
* @returns The validated wire request
|
|
4412
|
+
* @returns The validated wire request
|
|
4402
4413
|
* @throws {ProviderError} Thrown when the snapshot cannot be taken — a hostile read or a
|
|
4403
4414
|
* value outside JSON — carrying that failure as its `cause`, and when the snapshot the
|
|
4404
4415
|
* projection produced is not a valid wire request
|
|
@@ -5065,8 +5076,8 @@ export declare interface ThinkSplitterInterface {
|
|
|
5065
5076
|
*
|
|
5066
5077
|
* @remarks
|
|
5067
5078
|
* The wire is strictly narrower than the domain: non-JSON arguments are refused.
|
|
5068
|
-
*
|
|
5069
|
-
*
|
|
5079
|
+
* Calls carry only id, name, and arguments; execution context stays local.
|
|
5080
|
+
* The guard refuses every extra member; the contract parser drops extra members.
|
|
5070
5081
|
*/
|
|
5071
5082
|
export declare const toolCallShape: ObjectShape< {
|
|
5072
5083
|
id: StringShape;
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -486,6 +486,14 @@ export declare type AgentEventMap = {
|
|
|
486
486
|
* - **Bounded.** Each turn arms a single cancel folded from the external `signal`, the
|
|
487
487
|
* `timeout` deadline, and the `budget` signal (through `AbortSignal.any`); any of them —
|
|
488
488
|
* or `abort()` — stops the loop and settles the result `partial: true`.
|
|
489
|
+
* Tool handlers receive that run's signal through their `ToolContext`. An agent abort,
|
|
490
|
+
* stream abort, external signal, or deadline can reach a running handler. The budget is
|
|
491
|
+
* charged during provider streaming and between turns, before tool dispatch; exhaustion
|
|
492
|
+
* ends the run without dispatching, never inside a handler. An abort before dispatch
|
|
493
|
+
* appends neither the assistant call turn nor tool messages and emits no tool chunk;
|
|
494
|
+
* streamed content remains in the partial result. Cancellation after entry is cooperative:
|
|
495
|
+
* the loop awaits a running handler even when it ignores the signal.
|
|
496
|
+
* The agent supplies no caller identity.
|
|
489
497
|
* - **Paced + capped.** The `scheduler` (when given) yields between turns; tool
|
|
490
498
|
* iteration is capped at `limit` so the loop always terminates.
|
|
491
499
|
* - **Two observation surfaces.** Pull: the {@link AgentChunk} stream (`stream().events`)
|
|
@@ -3826,7 +3834,7 @@ export declare type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
|
3826
3834
|
*
|
|
3827
3835
|
* @remarks
|
|
3828
3836
|
* The wire is strictly narrower than Message: non-JSON call arguments are refused,
|
|
3829
|
-
* and
|
|
3837
|
+
* and execution context stays local. The guard refuses extra members; the parser drops them.
|
|
3830
3838
|
*/
|
|
3831
3839
|
export declare const messageShape: ObjectShape< {
|
|
3832
3840
|
id: StringShape;
|
|
@@ -4056,7 +4064,8 @@ readonly [k: string]: JSONValue;
|
|
|
4056
4064
|
*
|
|
4057
4065
|
* @remarks
|
|
4058
4066
|
* The wire is strictly narrower than ProviderRequest: non-JSON arguments, parameters,
|
|
4059
|
-
* or schema members are refused
|
|
4067
|
+
* or schema members are refused. Execution context stays local; the guard refuses
|
|
4068
|
+
* extra members, and the parser drops them.
|
|
4060
4069
|
*/
|
|
4061
4070
|
export declare const providerRequestShape: ObjectShape< {
|
|
4062
4071
|
messages: ArrayShape<ObjectShape< {
|
|
@@ -4130,7 +4139,7 @@ total: number;
|
|
|
4130
4139
|
*
|
|
4131
4140
|
* @remarks
|
|
4132
4141
|
* The wire is strictly narrower than ProviderResult: non-JSON call arguments are
|
|
4133
|
-
* refused, and
|
|
4142
|
+
* refused. Execution context stays local; the guard refuses extra members, and the parser drops them.
|
|
4134
4143
|
*/
|
|
4135
4144
|
export declare const providerResultShape: ObjectShape< {
|
|
4136
4145
|
content: StringShape;
|
|
@@ -4284,7 +4293,8 @@ message: string;
|
|
|
4284
4293
|
*
|
|
4285
4294
|
* @remarks
|
|
4286
4295
|
* The wire is strictly narrower than RelayFrame through its result and partial
|
|
4287
|
-
* fields: non-JSON arguments are refused
|
|
4296
|
+
* fields: non-JSON arguments are refused. Execution context stays local; the guard
|
|
4297
|
+
* refuses extra members, and the parser drops them.
|
|
4288
4298
|
*/
|
|
4289
4299
|
export declare const relayFrameShape: UnionShape<readonly [ObjectShape< {
|
|
4290
4300
|
channel: LiteralShape<readonly ["content", "thinking"]>;
|
|
@@ -4353,7 +4363,8 @@ export declare interface RelayOptions {
|
|
|
4353
4363
|
* Carries provider calls over an authenticated NDJSON relay endpoint.
|
|
4354
4364
|
*
|
|
4355
4365
|
* @remarks
|
|
4356
|
-
*
|
|
4366
|
+
* Tool execution context stays local; calls carry only `id`, `name`, and `arguments`.
|
|
4367
|
+
* The wire body is an owned snapshot of
|
|
4357
4368
|
* the projection read through property descriptors, so a serializer reachable only through a
|
|
4358
4369
|
* `get` trap or a prototype is never consulted; an own function-valued property such as a
|
|
4359
4370
|
* `toJSON` method is a value outside JSON and is refused before fetching, with the clone's
|
|
@@ -4398,7 +4409,7 @@ export declare class RelayProvider extends AgentProvider {
|
|
|
4398
4409
|
* value carries is ignored rather than consulted and cannot reach the wire.
|
|
4399
4410
|
*
|
|
4400
4411
|
* @param request - The domain conversation and call configuration
|
|
4401
|
-
* @returns The validated wire request
|
|
4412
|
+
* @returns The validated wire request
|
|
4402
4413
|
* @throws {ProviderError} Thrown when the snapshot cannot be taken — a hostile read or a
|
|
4403
4414
|
* value outside JSON — carrying that failure as its `cause`, and when the snapshot the
|
|
4404
4415
|
* projection produced is not a valid wire request
|
|
@@ -5065,8 +5076,8 @@ export declare interface ThinkSplitterInterface {
|
|
|
5065
5076
|
*
|
|
5066
5077
|
* @remarks
|
|
5067
5078
|
* The wire is strictly narrower than the domain: non-JSON arguments are refused.
|
|
5068
|
-
*
|
|
5069
|
-
*
|
|
5079
|
+
* Calls carry only id, name, and arguments; execution context stays local.
|
|
5080
|
+
* The guard refuses every extra member; the contract parser drops extra members.
|
|
5070
5081
|
*/
|
|
5071
5082
|
export declare const toolCallShape: ObjectShape< {
|
|
5072
5083
|
id: StringShape;
|
package/dist/src/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arrayOf, arrayShape, attempt, booleanShape, cloneJSONValue, createContract, isArray, isBoolean, isFiniteNumber, isObject, isRecord, isString, jsonShape, literalShape, numberShape, objectShape, optionalShape, parseJSONAs, parseJSONValue, rawShape, recordShape, stringShape, unionShape } from "@orkestrel/contract";
|
|
1
|
+
import { arrayOf, arrayShape, attempt, booleanShape, cloneJSONValue, createContract, isArray, isBoolean, isFiniteNumber, isInstance, isObject, isRecord, isString, jsonShape, literalShape, numberShape, objectShape, optionalShape, parseJSONAs, parseJSONValue, rawShape, recordShape, stringShape, unionShape } from "@orkestrel/contract";
|
|
2
2
|
import { createDatabase, createMemoryDriver } from "@orkestrel/database";
|
|
3
3
|
import { createQueue } from "@orkestrel/queue";
|
|
4
4
|
import { createRunner, errorToMessage } from "@orkestrel/workflow";
|
|
@@ -187,7 +187,7 @@ var ProviderAbortError = class extends Error {
|
|
|
187
187
|
* ```
|
|
188
188
|
*/
|
|
189
189
|
function isProviderAbortError(value) {
|
|
190
|
-
return value
|
|
190
|
+
return isInstance(value, ProviderAbortError);
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* Reports an {@link AgentInterface} run that ended {@link AgentResult.partial} under a
|
|
@@ -234,7 +234,7 @@ var AgentJobError = class extends Error {
|
|
|
234
234
|
* ```
|
|
235
235
|
*/
|
|
236
236
|
function isAgentJobError(value) {
|
|
237
|
-
return value
|
|
237
|
+
return isInstance(value, AgentJobError);
|
|
238
238
|
}
|
|
239
239
|
/**
|
|
240
240
|
* Reports a conversation with no {@link ConversationSummaryHandler} to fold its messages with,
|
|
@@ -278,7 +278,7 @@ var ConversationError = class extends Error {
|
|
|
278
278
|
* ```
|
|
279
279
|
*/
|
|
280
280
|
function isConversationError(value) {
|
|
281
|
-
return value
|
|
281
|
+
return isInstance(value, ConversationError);
|
|
282
282
|
}
|
|
283
283
|
/**
|
|
284
284
|
* Reports a concurrent run that would corrupt shared per-agent accounting, or a rehydration
|
|
@@ -324,7 +324,7 @@ var AgentError = class extends Error {
|
|
|
324
324
|
* ```
|
|
325
325
|
*/
|
|
326
326
|
function isAgentError(value) {
|
|
327
|
-
return value
|
|
327
|
+
return isInstance(value, AgentError);
|
|
328
328
|
}
|
|
329
329
|
/**
|
|
330
330
|
* Reports a coded provider failure with its HTTP status and underlying cause when available.
|
|
@@ -358,7 +358,7 @@ var ProviderError = class extends Error {
|
|
|
358
358
|
* ```
|
|
359
359
|
*/
|
|
360
360
|
function isProviderError(value) {
|
|
361
|
-
return value
|
|
361
|
+
return isInstance(value, ProviderError);
|
|
362
362
|
}
|
|
363
363
|
//#endregion
|
|
364
364
|
//#region src/core/shapers.ts
|
|
@@ -367,8 +367,8 @@ function isProviderError(value) {
|
|
|
367
367
|
*
|
|
368
368
|
* @remarks
|
|
369
369
|
* The wire is strictly narrower than the domain: non-JSON arguments are refused.
|
|
370
|
-
*
|
|
371
|
-
*
|
|
370
|
+
* Calls carry only id, name, and arguments; execution context stays local.
|
|
371
|
+
* The guard refuses every extra member; the contract parser drops extra members.
|
|
372
372
|
*/
|
|
373
373
|
var toolCallShape = objectShape({
|
|
374
374
|
id: stringShape(),
|
|
@@ -380,7 +380,7 @@ var toolCallShape = objectShape({
|
|
|
380
380
|
*
|
|
381
381
|
* @remarks
|
|
382
382
|
* The wire is strictly narrower than Message: non-JSON call arguments are refused,
|
|
383
|
-
* and
|
|
383
|
+
* and execution context stays local. The guard refuses extra members; the parser drops them.
|
|
384
384
|
*/
|
|
385
385
|
var messageShape = objectShape({
|
|
386
386
|
id: stringShape(),
|
|
@@ -399,7 +399,8 @@ var messageShape = objectShape({
|
|
|
399
399
|
*
|
|
400
400
|
* @remarks
|
|
401
401
|
* The wire is strictly narrower than ProviderRequest: non-JSON arguments, parameters,
|
|
402
|
-
* or schema members are refused
|
|
402
|
+
* or schema members are refused. Execution context stays local; the guard refuses
|
|
403
|
+
* extra members, and the parser drops them.
|
|
403
404
|
*/
|
|
404
405
|
var providerRequestShape = objectShape({
|
|
405
406
|
messages: arrayShape(messageShape),
|
|
@@ -418,7 +419,7 @@ var providerRequestShape = objectShape({
|
|
|
418
419
|
*
|
|
419
420
|
* @remarks
|
|
420
421
|
* The wire is strictly narrower than ProviderResult: non-JSON call arguments are
|
|
421
|
-
* refused, and
|
|
422
|
+
* refused. Execution context stays local; the guard refuses extra members, and the parser drops them.
|
|
422
423
|
*/
|
|
423
424
|
var providerResultShape = objectShape({
|
|
424
425
|
content: stringShape(),
|
|
@@ -435,7 +436,8 @@ var providerResultShape = objectShape({
|
|
|
435
436
|
*
|
|
436
437
|
* @remarks
|
|
437
438
|
* The wire is strictly narrower than RelayFrame through its result and partial
|
|
438
|
-
* fields: non-JSON arguments are refused
|
|
439
|
+
* fields: non-JSON arguments are refused. Execution context stays local; the guard
|
|
440
|
+
* refuses extra members, and the parser drops them.
|
|
439
441
|
*/
|
|
440
442
|
var relayFrameShape = unionShape(objectShape({
|
|
441
443
|
channel: literalShape(["content", "thinking"]),
|
|
@@ -723,7 +725,7 @@ function renderFencedFile(path, language, content) {
|
|
|
723
725
|
* @returns The floored count, or `0` when the value is non-finite or non-positive
|
|
724
726
|
*/
|
|
725
727
|
function sanitizeToken(value) {
|
|
726
|
-
return
|
|
728
|
+
return isFiniteNumber(value) && value > 0 ? Math.floor(value) : 0;
|
|
727
729
|
}
|
|
728
730
|
/**
|
|
729
731
|
* Sanitizes a {@link TokenUsage} into safe, non-negative integers — the guard an agent's
|
|
@@ -2162,13 +2164,19 @@ var Agent = class {
|
|
|
2162
2164
|
};
|
|
2163
2165
|
}
|
|
2164
2166
|
if (result.tools !== void 0 && result.tools.length > 0) {
|
|
2167
|
+
const authorization = this.#authorize(result.tools);
|
|
2168
|
+
if (abort.signal.aborted) {
|
|
2169
|
+
partial = true;
|
|
2170
|
+
broke = true;
|
|
2171
|
+
break;
|
|
2172
|
+
}
|
|
2165
2173
|
const assistant = this.#context.messages.add({
|
|
2166
2174
|
role: "assistant",
|
|
2167
2175
|
content: result.content,
|
|
2168
2176
|
calls: result.tools
|
|
2169
2177
|
});
|
|
2170
2178
|
messages.push(assistant);
|
|
2171
|
-
const results = await this.#
|
|
2179
|
+
const results = await this.#dispatch(tools, result.tools, abort.signal, authorization);
|
|
2172
2180
|
for (let index = 0; index < result.tools.length; index += 1) {
|
|
2173
2181
|
const call = result.tools[index];
|
|
2174
2182
|
const outcomeResult = results[index];
|
|
@@ -2228,8 +2236,8 @@ var Agent = class {
|
|
|
2228
2236
|
messages.splice(0, messages.length, ...this.#context.build(this.#provider.format));
|
|
2229
2237
|
return false;
|
|
2230
2238
|
}
|
|
2231
|
-
|
|
2232
|
-
if (this.#authority === void 0) return
|
|
2239
|
+
#authorize(calls) {
|
|
2240
|
+
if (this.#authority === void 0) return void 0;
|
|
2233
2241
|
const authority = this.#authority;
|
|
2234
2242
|
const allowed = [];
|
|
2235
2243
|
const denials = /* @__PURE__ */ new Map();
|
|
@@ -2249,7 +2257,15 @@ var Agent = class {
|
|
|
2249
2257
|
this.#emitter.emit("deny", call, decision.reason);
|
|
2250
2258
|
}
|
|
2251
2259
|
}
|
|
2252
|
-
|
|
2260
|
+
return {
|
|
2261
|
+
allowed,
|
|
2262
|
+
denials
|
|
2263
|
+
};
|
|
2264
|
+
}
|
|
2265
|
+
async #dispatch(tools, calls, signal, authorization) {
|
|
2266
|
+
if (authorization === void 0) return tools.execute(calls, { signal });
|
|
2267
|
+
const { allowed, denials } = authorization;
|
|
2268
|
+
const executed = allowed.length > 0 ? await tools.execute(allowed, { signal }) : [];
|
|
2253
2269
|
const byId = new Map(denials);
|
|
2254
2270
|
for (const result of executed) byId.set(result.id, result);
|
|
2255
2271
|
return calls.map((call) => byId.get(call.id) ?? denyCall(call, void 0));
|
|
@@ -2933,7 +2949,8 @@ var AgentProvider = class {
|
|
|
2933
2949
|
* Carries provider calls over an authenticated NDJSON relay endpoint.
|
|
2934
2950
|
*
|
|
2935
2951
|
* @remarks
|
|
2936
|
-
*
|
|
2952
|
+
* Tool execution context stays local; calls carry only `id`, `name`, and `arguments`.
|
|
2953
|
+
* The wire body is an owned snapshot of
|
|
2937
2954
|
* the projection read through property descriptors, so a serializer reachable only through a
|
|
2938
2955
|
* `get` trap or a prototype is never consulted; an own function-valued property such as a
|
|
2939
2956
|
* `toJSON` method is a value outside JSON and is refused before fetching, with the clone's
|
|
@@ -2992,7 +3009,7 @@ var RelayProvider = class extends AgentProvider {
|
|
|
2992
3009
|
* value carries is ignored rather than consulted and cannot reach the wire.
|
|
2993
3010
|
*
|
|
2994
3011
|
* @param request - The domain conversation and call configuration
|
|
2995
|
-
* @returns The validated wire request
|
|
3012
|
+
* @returns The validated wire request
|
|
2996
3013
|
* @throws {ProviderError} Thrown when the snapshot cannot be taken — a hostile read or a
|
|
2997
3014
|
* value outside JSON — carrying that failure as its `cause`, and when the snapshot the
|
|
2998
3015
|
* projection produced is not a valid wire request
|
|
@@ -3130,7 +3147,7 @@ var RelayStream = class {
|
|
|
3130
3147
|
if (step.done) this.#finish(controller);
|
|
3131
3148
|
} catch (error) {
|
|
3132
3149
|
if (this.#settled) return;
|
|
3133
|
-
const frame = error
|
|
3150
|
+
const frame = isProviderAbortError(error) ? {
|
|
3134
3151
|
channel: "abort",
|
|
3135
3152
|
partial: error.partial
|
|
3136
3153
|
} : {
|