@theokit/agents 4.30.2 → 6.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/dist/{bridge-entry-BL74g1Em.d.ts → bridge-entry-DD_j60GX.d.ts} +78 -42
- package/dist/bridge.d.ts +1 -1
- package/dist/bridge.js +1 -1
- package/dist/{chunk-GGB5WXHS.js → chunk-JXR45RAW.js} +166 -101
- package/dist/chunk-JXR45RAW.js.map +1 -0
- package/dist/index.d.ts +25 -6
- package/dist/index.js +36 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-GGB5WXHS.js.map +0 -1
|
@@ -721,6 +721,79 @@ interface AgentRouteContext {
|
|
|
721
721
|
/** Generate HTTP routes for a single agent. Returns Web Standard handlers. */
|
|
722
722
|
declare function generateAgentRoutes(ctx: AgentRouteContext): AgentRoute[];
|
|
723
723
|
|
|
724
|
+
/**
|
|
725
|
+
* M4 (theokit-ai-first) — the HITL producer: a `pre_tool_call` plugin that pauses the SDK run
|
|
726
|
+
* for a human-in-the-loop tool approval.
|
|
727
|
+
*
|
|
728
|
+
* ADR 0038: this is the ADAPTER seam — it makes the shipped-but-dead `@HumanInTheLoop` decorator
|
|
729
|
+
* FUNCTIONAL by wiring the SDK's OWN async `pre_tool_call` veto hook (which the SDK loop `await`s,
|
|
730
|
+
* so returning a pending Promise genuinely PAUSES the run) to a human approval. It calls no LLM,
|
|
731
|
+
* dispatches no tool, and runs no second loop — the SDK owns all of that.
|
|
732
|
+
*
|
|
733
|
+
* Flow: gated tool about to run → emit an `ApprovalRequiredEvent` (which the translator maps to
|
|
734
|
+
* the ai-sdk `tool-approval-request` chunk) → `await awaitApproval(approvalId)` (resolved by the
|
|
735
|
+
* out-of-band approve route) → allow (`undefined`) or veto (`{ block, message }`, which the SDK
|
|
736
|
+
* surfaces as a tool result the model self-corrects on).
|
|
737
|
+
*/
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* M20 — a settled HITL decision. Structural mirror of the harness's `ApprovalDecision` (the agents
|
|
741
|
+
* package must not import from `theokit` — dependency direction). `awaitApproval` may resolve a bare
|
|
742
|
+
* boolean (legacy) OR this object; the plugin normalizes both.
|
|
743
|
+
*/
|
|
744
|
+
interface HitlDecision {
|
|
745
|
+
approved: boolean;
|
|
746
|
+
reason?: string;
|
|
747
|
+
payload?: unknown;
|
|
748
|
+
}
|
|
749
|
+
/** Injected wiring — the harness (mount-agent) supplies these; the plugin stays pure. */
|
|
750
|
+
interface HitlWiring {
|
|
751
|
+
/** Tool name → its `@HumanInTheLoop` config. A tool absent here is NOT gated. */
|
|
752
|
+
gated: Map<string, HumanInTheLoopOptions>;
|
|
753
|
+
/** Push the approval-required event into the agent stream (the translator emits the chunk). */
|
|
754
|
+
emit: (event: ApprovalRequiredEvent) => void;
|
|
755
|
+
/**
|
|
756
|
+
* Await the human decision for `approvalId`; resolves approve/deny (or timeout). M20 — may resolve
|
|
757
|
+
* a bare boolean (legacy) OR a {@link HitlDecision} carrying an approver `reason` + `payload`.
|
|
758
|
+
*/
|
|
759
|
+
awaitApproval: (approvalId: string, opts: HumanInTheLoopOptions, toolName: string) => Promise<boolean | HitlDecision>;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* O que esta superfície faz quando uma tool gateada pede aprovação. Quatro variantes, nenhuma delas
|
|
764
|
+
* "omissão" — cada uma com um consumidor concreto e uma razão escrita.
|
|
765
|
+
*/
|
|
766
|
+
type ApprovalPosture = {
|
|
767
|
+
/** Há humano: o pedido é EMITIDO e a execução pausa até a decisão chegar. */
|
|
768
|
+
kind: 'interactive';
|
|
769
|
+
/**
|
|
770
|
+
* Empurra o `ApprovalRequiredEvent` para o stream da superfície. OBRIGATÓRIO: `toAgentFactory`
|
|
771
|
+
* devolve um handle cru, sem stream nem translator, então o sink vem de quem passa a postura —
|
|
772
|
+
* que é justamente a superfície dona do stream. Um default no-op devolveria o descarte
|
|
773
|
+
* silencioso pela porta dos fundos: o pedido seria "emitido" para lugar nenhum.
|
|
774
|
+
*/
|
|
775
|
+
emit: (event: ApprovalRequiredEvent) => void;
|
|
776
|
+
/** Resolve a decisão humana; a execução fica pausada até isto resolver. */
|
|
777
|
+
awaitApproval: (approvalId: string, opts: HumanInTheLoopOptions, toolName: string) => Promise<boolean | HitlDecision>;
|
|
778
|
+
} | {
|
|
779
|
+
/** Ninguém pergunta e a tool roda. Legítimo quando outra coisa confina a execução. */
|
|
780
|
+
kind: 'auto-approve';
|
|
781
|
+
reason: string;
|
|
782
|
+
} | {
|
|
783
|
+
/** Ninguém pergunta e a tool NÃO roda — a leitura segura da omissão (codex `GranularApprovalConfig`). */
|
|
784
|
+
kind: 'auto-reject';
|
|
785
|
+
reason: string;
|
|
786
|
+
} | {
|
|
787
|
+
/**
|
|
788
|
+
* O gate é conduzido pela SUPERFÍCIE servidora (o cliente ACP, pelo próprio protocolo), então
|
|
789
|
+
* a camada não instala plugin nenhum. É um bypass — mas um bypass NOMEADO, com razão escrita,
|
|
790
|
+
* que aparece no `match`, aparece em log e pode ser contado por um gate. O que ele substitui é
|
|
791
|
+
* pior: hoje o mesmo efeito acontece por omissão, sem nada disso.
|
|
792
|
+
*/
|
|
793
|
+
kind: 'owned-by-surface';
|
|
794
|
+
reason: string;
|
|
795
|
+
};
|
|
796
|
+
|
|
724
797
|
/**
|
|
725
798
|
* M82 — the typed shape of `AgentBuilder.create().hooks({...})`.
|
|
726
799
|
*
|
|
@@ -1057,12 +1130,13 @@ interface SdkAgentHandle {
|
|
|
1057
1130
|
* model / `assembleM8CreateOptions`), so the served agent has identical tools, model, system prompt,
|
|
1058
1131
|
* skills, and `mcpServers`. Keyed per `sessionId` via `Agent.getOrCreate` (matches the run path).
|
|
1059
1132
|
*
|
|
1060
|
-
*
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1133
|
+
* M96 — a superfície DECLARA sua {@link ApprovalPosture} e o factory instala o plugin que a variante
|
|
1134
|
+
* exige. Antes, o mapa `compiled.hitl` era compilado e DESCARTADO aqui. Rationale em
|
|
1135
|
+
* `./approval-posture.ts`.
|
|
1063
1136
|
*/
|
|
1064
1137
|
declare function toAgentFactory(def: DefinicaoOuThunk, opts: {
|
|
1065
1138
|
apiKey: string | (() => string | Promise<string>);
|
|
1139
|
+
approvals: ApprovalPosture;
|
|
1066
1140
|
overrides?: RuntimeOverrides;
|
|
1067
1141
|
}): (sessionId: string) => Promise<SdkAgentHandle>;
|
|
1068
1142
|
|
|
@@ -1342,44 +1416,6 @@ declare const AgentBuilder: {
|
|
|
1342
1416
|
create(): AgentBuilder;
|
|
1343
1417
|
};
|
|
1344
1418
|
|
|
1345
|
-
/**
|
|
1346
|
-
* M4 (theokit-ai-first) — the HITL producer: a `pre_tool_call` plugin that pauses the SDK run
|
|
1347
|
-
* for a human-in-the-loop tool approval.
|
|
1348
|
-
*
|
|
1349
|
-
* ADR 0038: this is the ADAPTER seam — it makes the shipped-but-dead `@HumanInTheLoop` decorator
|
|
1350
|
-
* FUNCTIONAL by wiring the SDK's OWN async `pre_tool_call` veto hook (which the SDK loop `await`s,
|
|
1351
|
-
* so returning a pending Promise genuinely PAUSES the run) to a human approval. It calls no LLM,
|
|
1352
|
-
* dispatches no tool, and runs no second loop — the SDK owns all of that.
|
|
1353
|
-
*
|
|
1354
|
-
* Flow: gated tool about to run → emit an `ApprovalRequiredEvent` (which the translator maps to
|
|
1355
|
-
* the ai-sdk `tool-approval-request` chunk) → `await awaitApproval(approvalId)` (resolved by the
|
|
1356
|
-
* out-of-band approve route) → allow (`undefined`) or veto (`{ block, message }`, which the SDK
|
|
1357
|
-
* surfaces as a tool result the model self-corrects on).
|
|
1358
|
-
*/
|
|
1359
|
-
|
|
1360
|
-
/**
|
|
1361
|
-
* M20 — a settled HITL decision. Structural mirror of the harness's `ApprovalDecision` (the agents
|
|
1362
|
-
* package must not import from `theokit` — dependency direction). `awaitApproval` may resolve a bare
|
|
1363
|
-
* boolean (legacy) OR this object; the plugin normalizes both.
|
|
1364
|
-
*/
|
|
1365
|
-
interface HitlDecision {
|
|
1366
|
-
approved: boolean;
|
|
1367
|
-
reason?: string;
|
|
1368
|
-
payload?: unknown;
|
|
1369
|
-
}
|
|
1370
|
-
/** Injected wiring — the harness (mount-agent) supplies these; the plugin stays pure. */
|
|
1371
|
-
interface HitlWiring {
|
|
1372
|
-
/** Tool name → its `@HumanInTheLoop` config. A tool absent here is NOT gated. */
|
|
1373
|
-
gated: Map<string, HumanInTheLoopOptions>;
|
|
1374
|
-
/** Push the approval-required event into the agent stream (the translator emits the chunk). */
|
|
1375
|
-
emit: (event: ApprovalRequiredEvent) => void;
|
|
1376
|
-
/**
|
|
1377
|
-
* Await the human decision for `approvalId`; resolves approve/deny (or timeout). M20 — may resolve
|
|
1378
|
-
* a bare boolean (legacy) OR a {@link HitlDecision} carrying an approver `reason` + `payload`.
|
|
1379
|
-
*/
|
|
1380
|
-
awaitApproval: (approvalId: string, opts: HumanInTheLoopOptions, toolName: string) => Promise<boolean | HitlDecision>;
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
1419
|
/**
|
|
1384
1420
|
* M2 (theokit-ai-first) — the file-convention runtime bridge.
|
|
1385
1421
|
*
|
|
@@ -2182,4 +2218,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
|
|
|
2182
2218
|
register(app: PluginApp): void;
|
|
2183
2219
|
};
|
|
2184
2220
|
|
|
2185
|
-
export {
|
|
2221
|
+
export { type DelegateOptions as $, type ApprovalOptions as A, type ApiErrorDecision as B, type CompiledAgentOptions as C, type DelegationResult as D, type ApiErrorPolicy as E, type ApprovalRequiredEvent as F, type Guardrail as G, type HumanInTheLoopOptions as H, type ArtifactChunkEvent as I, type ArtifactStartEvent as J, type BackgroundDelegation as K, type LoopStrategy as L, type MainLoopMeta as M, type BeforeToolCallContext as N, BudgetExceededError as O, type BudgetOptions as P, type CheckpointSavedEvent as Q, type ReflectionStrategy as R, type StreamEvent as S, type ToolOptions as T, type CompiledContextWindow as U, ContextualTool as V, CostBudgetExceededError as W, DEFAULT_MAX_ITERATIONS as X, type DefineAgentConfig as Y, type DefinicaoOuThunk as Z, type DelegateFn as _, type CompiledTool as a, createToolHooksPlugin as a$, DelegationBudgetExceededError as a0, DelegationError as a1, type DoneEvent as a2, type ErrorEvent as a3, type FileEditEvent as a4, type GuardrailAction as a5, type GuardrailPhase as a6, type GuardrailResult as a7, GuardrailViolationError as a8, type HookHandlers as a9, type Segment as aA, type SkillsRequestContext as aB, type SkillsSelection as aC, type StateUpdateEvent as aD, type TextDeltaEvent as aE, type ThinkingEvent as aF, type TimeoutAction as aG, type ToolCallEvent as aH, type ToolCallVeto as aI, type ToolHooks as aJ, type ToolHooksPlugin as aK, type ToolResultEvent as aL, type ToolWalkResult as aM, type ToolboxOptions as aN, type ToolboxWalkResult as aO, agentsPlugin as aP, buildModelSelection as aQ, compileAgentDefinition as aR, compileAgentModule as aS, compileContextWindow as aT, compileProjectContext as aU, compileSkills as aV, compileTools as aW, createAgentExecutionContext as aX, createApiErrorHandler as aY, createSdkAgentStream as aZ, createThinkTagExtractor as a_, type InferAgentInput as aa, type InferAgentToolNames as ab, type IterationEvent as ac, type LLMCallContext as ad, type LoopFinishReason as ae, type LoopOutcome as af, type LoopStrategyConfig as ag, type MainLoopOptions as ah, type McpApprovalSpec as ai, type McpRegistryConfig as aj, type McpRequestContext as ak, type McpSelection as al, type PartialToolCallEvent as am, type PolicyHandler as an, type ProcessInputContext as ao, type ReflectionContext as ap, type ReflectionResult as aq, type ReflectionStrategyConfig as ar, type RunStartedEvent as as, type ScoreVerdict as at, type ScoredDelegation as au, type Scorer as av, type SdkAgentHandle as aw, type SdkMessage as ax, type SdkSendOptions as ay, type SdkTurnHandle as az, type ReasoningEffort as b, delegate as b0, delegateBackground as b1, delegateWithScoring as b2, extractThinkTagStream as b3, generateAgentManifest as b4, generateAgentRoutes as b5, isAgentContext as b6, isAgentDefinition as b7, isApprovalRequired as b8, isDone as b9, isError as ba, isPartialToolCall as bb, isTextDelta as bc, isToolCall as bd, isToolResult as be, ladderReflectionStrategy as bf, loopStrategyConfigSchema as bg, mcpRegistry as bh, mcpToolApprovals as bi, noopReflectionStrategy as bj, presentUIMessageStream as bk, projectContextMetadataOnlyKnobs as bl, reflectionStrategyConfigSchema as bm, resolveEnabledSkills as bn, resolveLoopStrategy as bo, resolveMcpServers as bp, runWithApiErrorHandling as bq, streamAgentResponse as br, toAgentFactory as bs, translateSdkEvent as bt, type RoundStreamFactory as c, type ContextWindowOptions as d, type SkillsOptions as e, type AgentManifestEntry as f, type HitlDecision as g, type ApprovalPosture as h, AGENT_BRAND as i, type AfterToolCallContext as j, AgentBuilder as k, type AgentDefinition as l, AgentDefinitionError as m, type AgentExecutionContext as n, type AgentManifest as o, type AgentManifestSource as p, type AgentManifestTool as q, type AgentOptions as r, streamAgentUIMessages as s, type AgentRoute as t, type AgentRouteContext as u, type AgentRunInfo as v, type AgentStreamEvent as w, type AgentTurnMetadata as x, type AgentsPluginOptions as y, type ApiErrorContext as z };
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { i as AGENT_BRAND, j as AfterToolCallContext, k as AgentBuilder, l as AgentDefinition, m as AgentDefinitionError, n as AgentExecutionContext, o as AgentManifest, f as AgentManifestEntry, p as AgentManifestSource, q as AgentManifestTool, t as AgentRoute, u as AgentRouteContext, v as AgentRunInfo, w as AgentStreamEvent, x as AgentTurnMetadata, y as AgentsPluginOptions, z as ApiErrorContext, B as ApiErrorDecision, E as ApiErrorPolicy, h as ApprovalPosture, F as ApprovalRequiredEvent, I as ArtifactChunkEvent, J as ArtifactStartEvent, K as BackgroundDelegation, N as BeforeToolCallContext, O as BudgetExceededError, Q as CheckpointSavedEvent, C as CompiledAgentOptions, U as CompiledContextWindow, a as CompiledTool, V as ContextualTool, Y as DefineAgentConfig, Z as DefinicaoOuThunk, _ as DelegateFn, $ as DelegateOptions, a0 as DelegationBudgetExceededError, a1 as DelegationError, D as DelegationResult, a2 as DoneEvent, a3 as ErrorEvent, a4 as FileEditEvent, aa as InferAgentInput, ab as InferAgentToolNames, ac as IterationEvent, ad as LLMCallContext, ai as McpApprovalSpec, aj as McpRegistryConfig, ak as McpRequestContext, al as McpSelection, am as PartialToolCallEvent, ao as ProcessInputContext, as as RunStartedEvent, at as ScoreVerdict, au as ScoredDelegation, av as Scorer, aw as SdkAgentHandle, ax as SdkMessage, ay as SdkSendOptions, az as SdkTurnHandle, aA as Segment, aD as StateUpdateEvent, S as StreamEvent, aE as TextDeltaEvent, aF as ThinkingEvent, aH as ToolCallEvent, aI as ToolCallVeto, aJ as ToolHooks, aK as ToolHooksPlugin, aL as ToolResultEvent, aM as ToolWalkResult, aO as ToolboxWalkResult, aP as agentsPlugin, aQ as buildModelSelection, aR as compileAgentDefinition, aS as compileAgentModule, aT as compileContextWindow, aU as compileProjectContext, aV as compileSkills, aW as compileTools, aX as createAgentExecutionContext, aY as createApiErrorHandler, aZ as createSdkAgentStream, a_ as createThinkTagExtractor, a$ as createToolHooksPlugin, b0 as delegate, b1 as delegateBackground, b2 as delegateWithScoring, b3 as extractThinkTagStream, b4 as generateAgentManifest, b5 as generateAgentRoutes, b6 as isAgentContext, b7 as isAgentDefinition, b8 as isApprovalRequired, b9 as isDone, ba as isError, bb as isPartialToolCall, bc as isTextDelta, bd as isToolCall, be as isToolResult, bh as mcpRegistry, bi as mcpToolApprovals, bk as presentUIMessageStream, bl as projectContextMetadataOnlyKnobs, bp as resolveMcpServers, bq as runWithApiErrorHandling, br as streamAgentResponse, s as streamAgentUIMessages, bs as toAgentFactory, bt as translateSdkEvent } from './bridge-entry-DD_j60GX.js';
|
|
2
2
|
import '@theokit/http';
|
|
3
3
|
import '@theokit/sdk';
|
|
4
4
|
import 'zod';
|
package/dist/bridge.js
CHANGED
|
@@ -455,6 +455,59 @@ function generateAgentRoutes(ctx) {
|
|
|
455
455
|
}
|
|
456
456
|
__name(generateAgentRoutes, "generateAgentRoutes");
|
|
457
457
|
|
|
458
|
+
// src/bridge/tool-hooks-plugin.ts
|
|
459
|
+
function createToolHooksPlugin(hooks) {
|
|
460
|
+
return {
|
|
461
|
+
name: "theokit-tool-hooks",
|
|
462
|
+
version: "1.0.0",
|
|
463
|
+
// `kind: 'general'` is load-bearing — without it the SDK's isCodePlugin() drops this plugin and
|
|
464
|
+
// no hook fires (M10/M19 latent bug, proven via a real OpenRouter run).
|
|
465
|
+
kind: "general",
|
|
466
|
+
register(ctx) {
|
|
467
|
+
const { beforeToolCall, afterToolCall, beforeLLMCall, afterLLMCall, processInput } = hooks;
|
|
468
|
+
if (beforeToolCall) {
|
|
469
|
+
ctx.on("pre_tool_call", (c) => beforeToolCall({
|
|
470
|
+
name: c.name ?? "",
|
|
471
|
+
args: c.args ?? {}
|
|
472
|
+
}));
|
|
473
|
+
}
|
|
474
|
+
if (afterToolCall) {
|
|
475
|
+
ctx.on("post_tool_call", (c) => afterToolCall({
|
|
476
|
+
name: c.name ?? "",
|
|
477
|
+
result: c.result
|
|
478
|
+
}));
|
|
479
|
+
}
|
|
480
|
+
if (beforeLLMCall) {
|
|
481
|
+
ctx.on("pre_llm_call", (c) => beforeLLMCall({
|
|
482
|
+
agentId: c.agentId,
|
|
483
|
+
runId: c.runId,
|
|
484
|
+
iteration: c.iteration
|
|
485
|
+
}));
|
|
486
|
+
}
|
|
487
|
+
if (afterLLMCall) {
|
|
488
|
+
ctx.on("post_llm_call", (c) => afterLLMCall({
|
|
489
|
+
agentId: c.agentId,
|
|
490
|
+
runId: c.runId,
|
|
491
|
+
iteration: c.iteration
|
|
492
|
+
}));
|
|
493
|
+
}
|
|
494
|
+
if (processInput) {
|
|
495
|
+
ctx.on("pre_user_send", async (c) => {
|
|
496
|
+
const injected = await processInput({
|
|
497
|
+
prompt: c.prompt ?? "",
|
|
498
|
+
agentId: c.agentId,
|
|
499
|
+
runId: c.runId
|
|
500
|
+
});
|
|
501
|
+
return injected !== void 0 && injected.length > 0 ? {
|
|
502
|
+
recalledContext: injected
|
|
503
|
+
} : void 0;
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
__name(createToolHooksPlugin, "createToolHooksPlugin");
|
|
510
|
+
|
|
458
511
|
// src/bridge/event-translator.ts
|
|
459
512
|
function asString(value, fallback) {
|
|
460
513
|
if (typeof value === "string") return value;
|
|
@@ -766,6 +819,116 @@ function debugLog(marker, data) {
|
|
|
766
819
|
}
|
|
767
820
|
__name(debugLog, "debugLog");
|
|
768
821
|
|
|
822
|
+
// src/bridge/hitl-plugin.ts
|
|
823
|
+
function createHitlPlugin(wiring) {
|
|
824
|
+
return {
|
|
825
|
+
name: "theokit-hitl",
|
|
826
|
+
version: "1.0.0",
|
|
827
|
+
// `kind: 'general'` is load-bearing — without it the SDK's isCodePlugin() drops this plugin and
|
|
828
|
+
// the HITL veto never fires (the run would proceed WITHOUT waiting for human approval).
|
|
829
|
+
kind: "general",
|
|
830
|
+
register(ctx) {
|
|
831
|
+
ctx.on("pre_tool_call", async (c) => {
|
|
832
|
+
const opts = wiring.gated.get(c.name);
|
|
833
|
+
if (!opts) return void 0;
|
|
834
|
+
const approvalId = crypto.randomUUID();
|
|
835
|
+
wiring.emit({
|
|
836
|
+
type: "approval_required",
|
|
837
|
+
callId: approvalId,
|
|
838
|
+
toolName: c.name,
|
|
839
|
+
question: opts.question,
|
|
840
|
+
input: c.args,
|
|
841
|
+
callbackUrl: `approve/${approvalId}`,
|
|
842
|
+
timeoutMs: opts.timeout ?? 3e5,
|
|
843
|
+
// M20 — carry the declared custom-payload schema so the UI knows what to collect.
|
|
844
|
+
...opts.payloadSchema !== void 0 ? {
|
|
845
|
+
payloadSchema: opts.payloadSchema
|
|
846
|
+
} : {}
|
|
847
|
+
});
|
|
848
|
+
const raw = await wiring.awaitApproval(approvalId, opts, c.name);
|
|
849
|
+
const decision = typeof raw === "boolean" ? {
|
|
850
|
+
approved: raw
|
|
851
|
+
} : raw;
|
|
852
|
+
if (decision.approved) return void 0;
|
|
853
|
+
let message = `Tool '${c.name}' denied by human approver`;
|
|
854
|
+
if (decision.reason) message += `: ${decision.reason}`;
|
|
855
|
+
if (decision.payload !== void 0) {
|
|
856
|
+
message += ` (payload: ${JSON.stringify(decision.payload)})`;
|
|
857
|
+
}
|
|
858
|
+
return {
|
|
859
|
+
block: true,
|
|
860
|
+
message
|
|
861
|
+
};
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
__name(createHitlPlugin, "createHitlPlugin");
|
|
867
|
+
|
|
868
|
+
// src/bridge/approval-posture.ts
|
|
869
|
+
function razaoDe(postura) {
|
|
870
|
+
return postura.kind === "interactive" ? "human approver on this surface" : postura.reason;
|
|
871
|
+
}
|
|
872
|
+
__name(razaoDe, "razaoDe");
|
|
873
|
+
function aplicarPostura(extra, m8, postura, gated) {
|
|
874
|
+
const daPostura = pluginsDaPostura(postura, gated);
|
|
875
|
+
if (daPostura.length === 0) return;
|
|
876
|
+
const atuais = extra.plugins ?? m8.plugins;
|
|
877
|
+
if (atuais !== void 0 && !Array.isArray(atuais)) {
|
|
878
|
+
throw new Error(`[@theokit/agents] approval posture "${postura.kind}" needs to install a plugin, but \`plugins\` was supplied in the legacy object form, which cannot carry both. Pass \`plugins\` as an array so the approval gate is not dropped.`);
|
|
879
|
+
}
|
|
880
|
+
extra.plugins = [
|
|
881
|
+
...atuais ?? [],
|
|
882
|
+
...daPostura
|
|
883
|
+
];
|
|
884
|
+
}
|
|
885
|
+
__name(aplicarPostura, "aplicarPostura");
|
|
886
|
+
function pluginsDaPostura(postura, gated) {
|
|
887
|
+
debugLog("[theokit] approval posture", {
|
|
888
|
+
kind: postura.kind,
|
|
889
|
+
reason: razaoDe(postura)
|
|
890
|
+
});
|
|
891
|
+
if (gated === void 0 || gated.size === 0) return [];
|
|
892
|
+
switch (postura.kind) {
|
|
893
|
+
case "interactive":
|
|
894
|
+
return [
|
|
895
|
+
createHitlPlugin({
|
|
896
|
+
gated,
|
|
897
|
+
emit: postura.emit,
|
|
898
|
+
awaitApproval: postura.awaitApproval
|
|
899
|
+
})
|
|
900
|
+
];
|
|
901
|
+
case "auto-approve":
|
|
902
|
+
return [
|
|
903
|
+
createToolHooksPlugin({
|
|
904
|
+
beforeToolCall: /* @__PURE__ */ __name((ctx) => {
|
|
905
|
+
if (gated.has(ctx.name)) {
|
|
906
|
+
debugLog("[theokit] gated tool auto-approved", {
|
|
907
|
+
tool: ctx.name,
|
|
908
|
+
reason: postura.reason
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
return void 0;
|
|
912
|
+
}, "beforeToolCall")
|
|
913
|
+
})
|
|
914
|
+
];
|
|
915
|
+
case "auto-reject":
|
|
916
|
+
return [
|
|
917
|
+
createToolHooksPlugin({
|
|
918
|
+
// Só as tools GATEADAS são recusadas: a postura descreve o gate, não um bloqueio universal.
|
|
919
|
+
// Recusar tudo quebraria todo agente que tem uma tool livre ao lado de uma gateada.
|
|
920
|
+
beforeToolCall: /* @__PURE__ */ __name((ctx) => gated.has(ctx.name) ? {
|
|
921
|
+
block: true,
|
|
922
|
+
message: `Tool '${ctx.name}' requires human approval, and this surface has no approver (approval posture: auto-reject \u2014 ${postura.reason}). Refused (fail-closed).`
|
|
923
|
+
} : void 0, "beforeToolCall")
|
|
924
|
+
})
|
|
925
|
+
];
|
|
926
|
+
case "owned-by-surface":
|
|
927
|
+
return [];
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
__name(pluginsDaPostura, "pluginsDaPostura");
|
|
931
|
+
|
|
769
932
|
// src/bridge/definicao-ou-thunk.ts
|
|
770
933
|
function projetar(def, overrides) {
|
|
771
934
|
const compiled = compileAgentDefinition(def);
|
|
@@ -1342,6 +1505,7 @@ function toAgentFactory(def, opts) {
|
|
|
1342
1505
|
baseDir: overrides.baseDir
|
|
1343
1506
|
};
|
|
1344
1507
|
const extra = buildExtraCreateOptions(overrides, compiled);
|
|
1508
|
+
aplicarPostura(extra, m8, opts.approvals, compiled.hitl);
|
|
1345
1509
|
const agent = await rt.Agent.getOrCreate(sessionId, {
|
|
1346
1510
|
apiKey: await resolverApiKey(opts.apiKey),
|
|
1347
1511
|
model: buildModelSelection(model, reasoningEffort),
|
|
@@ -2098,52 +2262,6 @@ var AgentBuilder = {
|
|
|
2098
2262
|
}
|
|
2099
2263
|
};
|
|
2100
2264
|
|
|
2101
|
-
// src/bridge/hitl-plugin.ts
|
|
2102
|
-
function createHitlPlugin(wiring) {
|
|
2103
|
-
return {
|
|
2104
|
-
name: "theokit-hitl",
|
|
2105
|
-
version: "1.0.0",
|
|
2106
|
-
// `kind: 'general'` is load-bearing — without it the SDK's isCodePlugin() drops this plugin and
|
|
2107
|
-
// the HITL veto never fires (the run would proceed WITHOUT waiting for human approval).
|
|
2108
|
-
kind: "general",
|
|
2109
|
-
register(ctx) {
|
|
2110
|
-
ctx.on("pre_tool_call", async (c) => {
|
|
2111
|
-
const opts = wiring.gated.get(c.name);
|
|
2112
|
-
if (!opts) return void 0;
|
|
2113
|
-
const approvalId = crypto.randomUUID();
|
|
2114
|
-
wiring.emit({
|
|
2115
|
-
type: "approval_required",
|
|
2116
|
-
callId: approvalId,
|
|
2117
|
-
toolName: c.name,
|
|
2118
|
-
question: opts.question,
|
|
2119
|
-
input: c.args,
|
|
2120
|
-
callbackUrl: `approve/${approvalId}`,
|
|
2121
|
-
timeoutMs: opts.timeout ?? 3e5,
|
|
2122
|
-
// M20 — carry the declared custom-payload schema so the UI knows what to collect.
|
|
2123
|
-
...opts.payloadSchema !== void 0 ? {
|
|
2124
|
-
payloadSchema: opts.payloadSchema
|
|
2125
|
-
} : {}
|
|
2126
|
-
});
|
|
2127
|
-
const raw = await wiring.awaitApproval(approvalId, opts, c.name);
|
|
2128
|
-
const decision = typeof raw === "boolean" ? {
|
|
2129
|
-
approved: raw
|
|
2130
|
-
} : raw;
|
|
2131
|
-
if (decision.approved) return void 0;
|
|
2132
|
-
let message = `Tool '${c.name}' denied by human approver`;
|
|
2133
|
-
if (decision.reason) message += `: ${decision.reason}`;
|
|
2134
|
-
if (decision.payload !== void 0) {
|
|
2135
|
-
message += ` (payload: ${JSON.stringify(decision.payload)})`;
|
|
2136
|
-
}
|
|
2137
|
-
return {
|
|
2138
|
-
block: true,
|
|
2139
|
-
message
|
|
2140
|
-
};
|
|
2141
|
-
});
|
|
2142
|
-
}
|
|
2143
|
-
};
|
|
2144
|
-
}
|
|
2145
|
-
__name(createHitlPlugin, "createHitlPlugin");
|
|
2146
|
-
|
|
2147
2265
|
// src/bridge/agent-endpoint.ts
|
|
2148
2266
|
var AgentDefinitionError = class extends Error {
|
|
2149
2267
|
static {
|
|
@@ -3140,59 +3258,6 @@ async function delegate(spec, message, opts = {}) {
|
|
|
3140
3258
|
}
|
|
3141
3259
|
__name(delegate, "delegate");
|
|
3142
3260
|
|
|
3143
|
-
// src/bridge/tool-hooks-plugin.ts
|
|
3144
|
-
function createToolHooksPlugin(hooks) {
|
|
3145
|
-
return {
|
|
3146
|
-
name: "theokit-tool-hooks",
|
|
3147
|
-
version: "1.0.0",
|
|
3148
|
-
// `kind: 'general'` is load-bearing — without it the SDK's isCodePlugin() drops this plugin and
|
|
3149
|
-
// no hook fires (M10/M19 latent bug, proven via a real OpenRouter run).
|
|
3150
|
-
kind: "general",
|
|
3151
|
-
register(ctx) {
|
|
3152
|
-
const { beforeToolCall, afterToolCall, beforeLLMCall, afterLLMCall, processInput } = hooks;
|
|
3153
|
-
if (beforeToolCall) {
|
|
3154
|
-
ctx.on("pre_tool_call", (c) => beforeToolCall({
|
|
3155
|
-
name: c.name ?? "",
|
|
3156
|
-
args: c.args ?? {}
|
|
3157
|
-
}));
|
|
3158
|
-
}
|
|
3159
|
-
if (afterToolCall) {
|
|
3160
|
-
ctx.on("post_tool_call", (c) => afterToolCall({
|
|
3161
|
-
name: c.name ?? "",
|
|
3162
|
-
result: c.result
|
|
3163
|
-
}));
|
|
3164
|
-
}
|
|
3165
|
-
if (beforeLLMCall) {
|
|
3166
|
-
ctx.on("pre_llm_call", (c) => beforeLLMCall({
|
|
3167
|
-
agentId: c.agentId,
|
|
3168
|
-
runId: c.runId,
|
|
3169
|
-
iteration: c.iteration
|
|
3170
|
-
}));
|
|
3171
|
-
}
|
|
3172
|
-
if (afterLLMCall) {
|
|
3173
|
-
ctx.on("post_llm_call", (c) => afterLLMCall({
|
|
3174
|
-
agentId: c.agentId,
|
|
3175
|
-
runId: c.runId,
|
|
3176
|
-
iteration: c.iteration
|
|
3177
|
-
}));
|
|
3178
|
-
}
|
|
3179
|
-
if (processInput) {
|
|
3180
|
-
ctx.on("pre_user_send", async (c) => {
|
|
3181
|
-
const injected = await processInput({
|
|
3182
|
-
prompt: c.prompt ?? "",
|
|
3183
|
-
agentId: c.agentId,
|
|
3184
|
-
runId: c.runId
|
|
3185
|
-
});
|
|
3186
|
-
return injected !== void 0 && injected.length > 0 ? {
|
|
3187
|
-
recalledContext: injected
|
|
3188
|
-
} : void 0;
|
|
3189
|
-
});
|
|
3190
|
-
}
|
|
3191
|
-
}
|
|
3192
|
-
};
|
|
3193
|
-
}
|
|
3194
|
-
__name(createToolHooksPlugin, "createToolHooksPlugin");
|
|
3195
|
-
|
|
3196
3261
|
// src/bridge/api-error-handler.ts
|
|
3197
3262
|
var DEFAULT_MAX_ATTEMPTS = 3;
|
|
3198
3263
|
async function runWithApiErrorHandling(thunk, policy) {
|
|
@@ -3497,6 +3562,7 @@ export {
|
|
|
3497
3562
|
isError,
|
|
3498
3563
|
isApprovalRequired,
|
|
3499
3564
|
generateAgentRoutes,
|
|
3565
|
+
createToolHooksPlugin,
|
|
3500
3566
|
translateSdkEvent,
|
|
3501
3567
|
buildModelSelection,
|
|
3502
3568
|
createThinkTagExtractor,
|
|
@@ -3538,7 +3604,6 @@ export {
|
|
|
3538
3604
|
GoalRunner,
|
|
3539
3605
|
JudgeCredentialError,
|
|
3540
3606
|
delegate,
|
|
3541
|
-
createToolHooksPlugin,
|
|
3542
3607
|
runWithApiErrorHandling,
|
|
3543
3608
|
createApiErrorHandler,
|
|
3544
3609
|
delegateBackground,
|
|
@@ -3549,4 +3614,4 @@ export {
|
|
|
3549
3614
|
generateAgentManifest,
|
|
3550
3615
|
agentsPlugin
|
|
3551
3616
|
};
|
|
3552
|
-
//# sourceMappingURL=chunk-
|
|
3617
|
+
//# sourceMappingURL=chunk-JXR45RAW.js.map
|