@theokit/agents 6.3.1 → 6.4.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.
@@ -1,5 +1,5 @@
1
1
  import { ExecutionContext } from '@theokit/http';
2
- import { SystemPromptResolver, InlineSkill, SettingSource, MemorySettings, SkillsSettings, ContextSettings, PreToolCallContext, PreToolCallDecision, PostToolCallContext, ToolResultTransformContext, TransformContext, SessionLifecycleContext, PreUserSendContext, PreUserSendResult, PostAssistantReplyContext, CustomTool, ModelSelection, PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition as AgentDefinition$1, BudgetTracker } from '@theokit/sdk';
2
+ import { McpServerConfig, SystemPromptResolver, InlineSkill, SettingSource, MemorySettings, SkillsSettings, ContextSettings, PreToolCallContext, PreToolCallDecision, PostToolCallContext, ToolResultTransformContext, TransformContext, SessionLifecycleContext, PreUserSendContext, PreUserSendResult, PostAssistantReplyContext, CustomTool, ModelSelection, PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition as AgentDefinition$1, BudgetTracker } from '@theokit/sdk';
3
3
  import { z } from 'zod';
4
4
  import { UIMessageChunk } from 'ai';
5
5
  import { RetryOptions } from '@theokit/sdk/retry';
@@ -128,17 +128,7 @@ interface HumanInTheLoopOptions {
128
128
  */
129
129
  payloadSchema?: Record<string, unknown>;
130
130
  }
131
- /** M53 — moved from the `@MCP` decorator being deleted; consumed by the bridge and the adapter. */
132
- interface McpServerConfig {
133
- /** Command to start the MCP server. */
134
- command: string;
135
- /** Arguments passed to the command. */
136
- args?: string[];
137
- /** Environment variables for the server process. */
138
- env?: Record<string, string>;
139
- /** Working directory for the server process. */
140
- cwd?: string;
141
- }
131
+
142
132
  type McpServersMap = Record<string, McpServerConfig>;
143
133
  /** M53 — moved from the `@ProjectContext` decorator being deleted; read by the compiler. */
144
134
  type IndexStrategy = 'tree-sitter' | 'regex' | 'none';
@@ -2092,6 +2082,10 @@ type McpApprovalSpec = HumanInTheLoopOptions | string;
2092
2082
  */
2093
2083
  declare function mcpToolApprovals(specs: Record<string, McpApprovalSpec>): Record<string, HumanInTheLoopOptions>;
2094
2084
 
2085
+ /** Canal por onde uma entrada omitida é NOMEADA. Sem ele, estreitar o raio viraria fail-open. */
2086
+ interface LoadMcpJsonOptions {
2087
+ onWarn?: (aviso: string) => void;
2088
+ }
2095
2089
  /**
2096
2090
  * Raised when `<cwd>/.mcp.json` exists but cannot be read, is not valid JSON, or does not match the
2097
2091
  * expected shape — never swallowed.
@@ -2114,7 +2108,7 @@ declare class McpFileError extends TheokitAgentError {
2114
2108
  *
2115
2109
  * Reading is explicit — this module has no import-time side effect.
2116
2110
  */
2117
- declare function loadMcpJson(cwd: string): McpServersMap;
2111
+ declare function loadMcpJson(cwd: string, opts?: LoadMcpJsonOptions): McpServersMap;
2118
2112
 
2119
2113
  /**
2120
2114
  * Agent manifest generator — build-time JSON describing all agents, tools, guards, policies.
package/dist/bridge.d.ts CHANGED
@@ -1,4 +1,4 @@
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 McpFileError, ak as McpRegistryConfig, al as McpRequestContext, am as McpSelection, an as PartialToolCallEvent, ap as ProcessInputContext, at as RunStartedEvent, au as ScoreVerdict, av as ScoredDelegation, aw as Scorer, ax as SdkAgentHandle, ay as SdkMessage, az as SdkSendOptions, aA as SdkTurnHandle, aB as Segment, aE as StateUpdateEvent, S as StreamEvent, aF as TextDeltaEvent, aG as ThinkingEvent, aI as ToolCallEvent, aJ as ToolCallVeto, aK as ToolHooks, aL as ToolHooksPlugin, aM as ToolResultEvent, aN as ToolWalkResult, aP as ToolboxWalkResult, aQ as agentsPlugin, aR as buildModelSelection, aS as compileAgentDefinition, aT as compileAgentModule, aU as compileContextWindow, aV as compileProjectContext, aW as compileSkills, aX as compileTools, aY as createAgentExecutionContext, aZ as createApiErrorHandler, a_ as createSdkAgentStream, a$ as createThinkTagExtractor, b0 as createToolHooksPlugin, b1 as delegate, b2 as delegateBackground, b3 as delegateWithScoring, b4 as extractThinkTagStream, b5 as generateAgentManifest, b6 as generateAgentRoutes, b7 as isAgentContext, b8 as isAgentDefinition, b9 as isApprovalRequired, ba as isDone, bb as isError, bc as isPartialToolCall, bd as isTextDelta, be as isToolCall, bf as isToolResult, bh as loadMcpJson, bj as mcpRegistry, bk as mcpToolApprovals, bm as presentUIMessageStream, bn as projectContextMetadataOnlyKnobs, bo as reasoningEffortOf, bs as resolveMcpServers, bt as runWithApiErrorHandling, bu as streamAgentResponse, s as streamAgentUIMessages, bv as toAgentFactory, bw as translateSdkEvent } from './bridge-entry-BlKfMDWb.js';
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 McpFileError, ak as McpRegistryConfig, al as McpRequestContext, am as McpSelection, an as PartialToolCallEvent, ap as ProcessInputContext, at as RunStartedEvent, au as ScoreVerdict, av as ScoredDelegation, aw as Scorer, ax as SdkAgentHandle, ay as SdkMessage, az as SdkSendOptions, aA as SdkTurnHandle, aB as Segment, aE as StateUpdateEvent, S as StreamEvent, aF as TextDeltaEvent, aG as ThinkingEvent, aI as ToolCallEvent, aJ as ToolCallVeto, aK as ToolHooks, aL as ToolHooksPlugin, aM as ToolResultEvent, aN as ToolWalkResult, aP as ToolboxWalkResult, aQ as agentsPlugin, aR as buildModelSelection, aS as compileAgentDefinition, aT as compileAgentModule, aU as compileContextWindow, aV as compileProjectContext, aW as compileSkills, aX as compileTools, aY as createAgentExecutionContext, aZ as createApiErrorHandler, a_ as createSdkAgentStream, a$ as createThinkTagExtractor, b0 as createToolHooksPlugin, b1 as delegate, b2 as delegateBackground, b3 as delegateWithScoring, b4 as extractThinkTagStream, b5 as generateAgentManifest, b6 as generateAgentRoutes, b7 as isAgentContext, b8 as isAgentDefinition, b9 as isApprovalRequired, ba as isDone, bb as isError, bc as isPartialToolCall, bd as isTextDelta, be as isToolCall, bf as isToolResult, bh as loadMcpJson, bj as mcpRegistry, bk as mcpToolApprovals, bm as presentUIMessageStream, bn as projectContextMetadataOnlyKnobs, bo as reasoningEffortOf, bs as resolveMcpServers, bt as runWithApiErrorHandling, bu as streamAgentResponse, s as streamAgentUIMessages, bv as toAgentFactory, bw as translateSdkEvent } from './bridge-entry-ok33yXie.js';
2
2
  import '@theokit/http';
3
3
  import '@theokit/sdk';
4
4
  import 'zod';
package/dist/bridge.js CHANGED
@@ -47,7 +47,7 @@ import {
47
47
  streamAgentUIMessages,
48
48
  toAgentFactory,
49
49
  translateSdkEvent
50
- } from "./chunk-MDFEPVAN.js";
50
+ } from "./chunk-C5RUE4DB.js";
51
51
  import "./chunk-7QVYU63E.js";
52
52
  export {
53
53
  AGENT_BRAND,
@@ -3425,7 +3425,7 @@ var McpFileError = class extends TheokitAgentError {
3425
3425
  }
3426
3426
  };
3427
3427
  var MCP_FILENAME = ".mcp.json";
3428
- function loadMcpJson(cwd) {
3428
+ function loadMcpJson(cwd, opts = {}) {
3429
3429
  const path = join(cwd, MCP_FILENAME);
3430
3430
  if (!existsSync(path)) return {};
3431
3431
  let text;
@@ -3440,10 +3440,10 @@ function loadMcpJson(cwd) {
3440
3440
  } catch (err) {
3441
3441
  throw new McpFileError(`${path} is not valid JSON: ${descrever(err)}`);
3442
3442
  }
3443
- return parseMcpJson(parsed, path);
3443
+ return parseMcpJson(parsed, path, opts.onWarn);
3444
3444
  }
3445
3445
  __name(loadMcpJson, "loadMcpJson");
3446
- function parseMcpJson(raw, source) {
3446
+ function parseMcpJson(raw, source, onWarn) {
3447
3447
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
3448
3448
  throw new McpFileError(`${source}: root must be a JSON object with an "mcpServers" key.`);
3449
3449
  }
@@ -3454,37 +3454,59 @@ function parseMcpJson(raw, source) {
3454
3454
  }
3455
3455
  const out = {};
3456
3456
  for (const [name, entryRaw] of Object.entries(serversRaw)) {
3457
- out[name] = parseServerEntry(name, entryRaw, source);
3457
+ const motivo = validarEntrada(name, entryRaw);
3458
+ if (motivo !== void 0) {
3459
+ onWarn?.(`${source}: server "${name}" ignorado \u2014 ${motivo}`);
3460
+ continue;
3461
+ }
3462
+ out[name] = entryRaw;
3458
3463
  }
3459
3464
  return out;
3460
3465
  }
3461
3466
  __name(parseMcpJson, "parseMcpJson");
3462
- function parseServerEntry(name, entryRaw, source) {
3467
+ function validarEntrada(name, entryRaw) {
3463
3468
  if (typeof entryRaw !== "object" || entryRaw === null || Array.isArray(entryRaw)) {
3464
- throw new McpFileError(`${source}: server "${name}" must be an object.`);
3469
+ return "a entrada deve ser um objeto.";
3465
3470
  }
3466
3471
  const entry = entryRaw;
3472
+ const temUrl = entry.url !== void 0;
3473
+ const temCommand = entry.command !== void 0;
3474
+ if (temUrl && temCommand) return 'declara "command" e "url" ao mesmo tempo \u2014 escolha um transporte.';
3475
+ if (!temUrl && !temCommand) return 'requer "command" (stdio) ou "url" (http/sse).';
3476
+ return temUrl ? validarRemoto(entry) : validarStdio(entry);
3477
+ }
3478
+ __name(validarEntrada, "validarEntrada");
3479
+ function validarStdio(entry) {
3467
3480
  if (typeof entry.command !== "string" || entry.command.length === 0) {
3468
- throw new McpFileError(`${source}: server "${name}" requires a non-empty "command" string.`);
3481
+ return 'campo "command" deve ser uma string n\xE3o vazia.';
3482
+ }
3483
+ if (entry.args !== void 0 && !isStringArray(entry.args)) return 'campo "args" deve ser array de strings.';
3484
+ if (entry.env !== void 0 && !isStringRecord(entry.env)) return 'campo "env" deve ser um mapa de strings.';
3485
+ if (entry.cwd !== void 0 && typeof entry.cwd !== "string") return 'campo "cwd" deve ser string.';
3486
+ return void 0;
3487
+ }
3488
+ __name(validarStdio, "validarStdio");
3489
+ function validarRemoto(entry) {
3490
+ if (typeof entry.url !== "string" || entry.url.length === 0) {
3491
+ return 'campo "url" deve ser uma string n\xE3o vazia.';
3469
3492
  }
3470
- if (entry.args !== void 0 && !isStringArray(entry.args)) {
3471
- throw new McpFileError(`${source}: server "${name}" field "args" must be a string array.`);
3493
+ try {
3494
+ new URL(entry.url);
3495
+ } catch {
3496
+ return 'campo "url" n\xE3o \xE9 uma URL v\xE1lida.';
3472
3497
  }
3473
- if (entry.env !== void 0 && !isStringRecord(entry.env)) {
3474
- throw new McpFileError(`${source}: server "${name}" field "env" must be a string map.`);
3498
+ if (entry.type !== void 0 && entry.type !== "http" && entry.type !== "sse") {
3499
+ return 'campo "type" deve ser "http" ou "sse".';
3475
3500
  }
3476
- if (entry.cwd !== void 0 && typeof entry.cwd !== "string") {
3477
- throw new McpFileError(`${source}: server "${name}" field "cwd" must be a string.`);
3501
+ if (entry.headers !== void 0 && !isStringRecord(entry.headers)) {
3502
+ return 'campo "headers" deve ser um mapa de strings.';
3478
3503
  }
3479
- const built = {
3480
- command: entry.command
3481
- };
3482
- if (entry.args !== void 0) built.args = entry.args;
3483
- if (entry.env !== void 0) built.env = entry.env;
3484
- if (entry.cwd !== void 0) built.cwd = entry.cwd;
3485
- return built;
3504
+ if (entry.requestTimeoutMs !== void 0 && typeof entry.requestTimeoutMs !== "number") {
3505
+ return 'campo "requestTimeoutMs" deve ser n\xFAmero.';
3506
+ }
3507
+ return void 0;
3486
3508
  }
3487
- __name(parseServerEntry, "parseServerEntry");
3509
+ __name(validarRemoto, "validarRemoto");
3488
3510
  function descrever(err) {
3489
3511
  return err instanceof Error ? err.message : String(err);
3490
3512
  }
@@ -3710,4 +3732,4 @@ export {
3710
3732
  generateAgentManifest,
3711
3733
  agentsPlugin
3712
3734
  };
3713
- //# sourceMappingURL=chunk-MDFEPVAN.js.map
3735
+ //# sourceMappingURL=chunk-C5RUE4DB.js.map