@tangle-network/agent-app 0.13.0 → 0.15.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/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export { AppToolRuntimeExecutor, CapabilityTokenOptions, DispatchOptions, ExpiringCapabilityTokenOptions, HandleToolRequestOptions, RuntimeExecutorOptions, ToolInputError, createAppToolRuntimeExecutor, createCapabilityToken, createExpiringCapabilityToken, dispatchAppTool, handleAppToolRequest, outcomeStatus, verifyCapabilityToken, verifyExpiringCapabilityToken } from './tools/index.js';
2
- export { A as APP_TOOL_NAMES, a as AppToolMcpServer, b as AppToolName, c as AuthenticateOptions, B as BuildHttpMcpServerOptions, d as BuildMcpServerOptions, D as DEFAULT_APP_TOOL_PATHS, e as DEFAULT_HEADER_NAMES, O as OpenAIFunctionTool, T as ToolAuthResult, f as ToolHeaderNames, g as authenticateToolRequest, h as buildAppToolMcpServer, i as buildAppToolOpenAITools, j as buildHttpMcpServer, k as isAppToolName, r as readToolArgs } from './mcp-CIupfjxV.js';
1
+ export { AppToolRuntimeExecutor, CapabilityTokenOptions, DispatchOptions, ExpiringCapabilityTokenOptions, HandleToolRequestOptions, ResolveToolCapabilitiesOptions, ResolvedToolCapabilities, RuntimeExecutorOptions, ToolCapability, ToolInputError, createAppToolRuntimeExecutor, createCapabilityToken, createExpiringCapabilityToken, dispatchAppTool, handleAppToolRequest, outcomeStatus, resolveToolCapabilities, restrictTaxonomy, verifyCapabilityToken, verifyExpiringCapabilityToken } from './tools/index.js';
2
+ export { A as APP_TOOL_NAMES, a as AppToolMcpServer, b as AppToolName, c as AuthenticateOptions, B as BuildHttpMcpServerOptions, d as BuildMcpServerOptions, D as DEFAULT_APP_TOOL_PATHS, e as DEFAULT_HEADER_NAMES, O as OpenAIFunctionTool, T as ToolAuthResult, f as ToolHeaderNames, g as authenticateToolRequest, h as buildAppToolMcpServer, i as buildAppToolOpenAITools, j as buildHttpMcpServer, k as isAppToolName, r as readToolArgs } from './mcp-eZCmkgCF.js';
3
3
  export { C as CreateMcpToolHandlerOptions, M as MCP_PROTOCOL_VERSIONS, a as McpProtocolVersion, b as McpServerInfo, c as McpToolDefinition, d as createMcpToolHandler } from './mcp-rpc-DLw_r9PQ.js';
4
- export { A as AddCitationArgs, a as AddCitationResult, b as AppToolContext, c as AppToolHandlers, d as AppToolOutcome, e as AppToolProducedEvent, f as AppToolTaxonomy, R as RenderUiArgs, g as RenderUiResult, S as ScheduleFollowupArgs, h as ScheduleFollowupResult, i as SubmitProposalArgs, j as SubmitProposalResult } from './types-By4B3K37.js';
4
+ export { A as AddCitationArgs, a as AddCitationResult, b as AppToolContext, c as AppToolHandlers, d as AppToolOutcome, e as AppToolProducedEvent, f as AppToolTaxonomy, R as RenderUiArgs, g as RenderUiResult, S as ScheduleFollowupArgs, h as ScheduleFollowupResult, i as SubmitProposalArgs, j as SubmitProposalResult } from './types-2rOJo8Hc.js';
5
5
  export { BuildDelegationOptions, DELEGATION_MCP_SERVER_KEY, DELEGATION_TOOLS, DelegationMcpServer, buildDelegationMcpServer, delegationMcpForConfig } from './delegation/index.js';
6
6
  export { BrokerToken, BrokerTokenMinter, BrokerTokenProvider, BrokerTokenProviderOptions, ConsentUrlInput, buildConsentUrl, createBrokerTokenProvider } from './tangle/index.js';
7
- export { AgentRuntime, AgentRuntimeModelConfig, AgentTurnOptions, AnySurfaceKind, AppToolLoopOptions, CreateAgentRuntimeOptions, LoopAssistantToolCall, LoopEvent, LoopMessage, LoopToolCall, OpenAICompatStreamTurnOptions, OpenAIStreamChunk, StreamAppToolLoopOptions, StreamLoopYield, SurfaceKindDefinition, SurfaceMcpServer, SurfaceMergeBase, SurfaceOverlay, SurfacePermissionValue, SurfaceRegistry, ToolLoopResult, ToolLoopStopReason, createAgentRuntime, createOpenAICompatStreamTurn, createSurfaceRegistry, defineSurfaceKind, mergeSurfaceOverlay, runAppToolLoop, streamAppToolLoop, toLoopEvents } from './runtime/index.js';
7
+ export { AgentRuntime, AgentRuntimeModelConfig, AgentTurnOptions, AnySurfaceKind, CreateAgentRuntimeOptions, LoopEvent, OpenAICompatStreamTurnOptions, OpenAIStreamChunk, SurfaceKindDefinition, SurfaceMcpServer, SurfaceMergeBase, SurfaceOverlay, SurfacePermissionValue, SurfaceRegistry, createAgentRuntime, createOpenAICompatStreamTurn, createSurfaceRegistry, defineSurfaceKind, mergeSurfaceOverlay, toLoopEvents } from './runtime/index.js';
8
8
  export { createTokenRecallChecker, producedFromToolEvents } from './eval/index.js';
9
9
  export { KnowledgeRequirementSpec, KnowledgeSignal, KnowledgeStateAccessor, SatisfiedByRule, buildKnowledgeRequirements, deriveSignals } from './knowledge/index.js';
10
10
  export { CreateKnowledgeLoopDeps, KnowledgeCandidate, KnowledgeDecider, KnowledgeDeciderInput, KnowledgeDecision, KnowledgeGateVerdict, KnowledgeLoop, KnowledgeLoopDriver, createKnowledgeLoop, createReviewerDecider, reviewCandidate } from './knowledge-loop/index.js';
@@ -28,6 +28,7 @@ export { B as Bounds, E as EllipseElement, G as GroupElement, I as ImageElement,
28
28
  export { A as AddElementOperation, a as AddPageOperation, b as ApplyDataOperation, B as BindSlotOperation, C as CHANNEL_PRESETS, c as ChannelPreset, d as ChannelPresetId, e as ChannelScaleResult, D as DeleteElementOperation, f as DeletePageOperation, g as DuplicatePageOperation, E as EXPORT_PRESETS, h as ExportCropRect, i as ExportFormat, j as ExportPreset, G as GroupElementsOperation, R as ReorderElementOperation, k as ReorderPageOperation, S as SCENE_OPERATION_TYPES, l as SIZE_PRESETS, m as SceneAttrsPatch, n as SceneOperation, o as SceneOperationType, p as ScenePlan, q as SetAttrsOperation, r as SetDocumentTitleOperation, s as SetPageGuidesOperation, t as SetPagePropsOperation, u as SizePreset, U as UngroupElementOperation, v as bleedAwareExportBounds, w as bleedAwareExportRect, x as findPreset, y as matchPreset, z as requireChannelPreset, F as scaleForPreset, H as scalePageForChannelPreset } from './export-presets-Dl5Aa5xj.js';
29
29
  export { N as NewSceneDecision, S as SceneDecision, a as SceneDocumentRecord, b as SceneExportFormat, c as SceneExportRecord, d as SceneStore, e as SceneStoreScope } from './store-CUStmtdH.js';
30
30
  export { ApplySceneOptions, BuildDesignCanvasMcpServerEntryOptions, CANVAS_ELEMENT_KINDS, CANVAS_MCP_TOOLS, CANVAS_MCP_TOOL_NAMES, CreateDesignCanvasMcpHandlerOptions, DEFAULT_DESIGN_CANVAS_MCP_DESCRIPTION, DesignCanvasMcpServerInfo, DesignCanvasMcpToolEnv, InstantiateOptions, SceneApplyResult, SlotFillKind, TemplateSlot, applyBindingsToDocument, applySceneOperation, applySceneOperations, buildDesignCanvasMcpServerEntry, createDesignCanvasMcpHandler, findCanvasMcpTool, instantiateTemplate, listTemplateSlots, storeApplyScenePlan, validateBindings, validateSceneOperation, validateSceneOperations, validateSlotValue } from './design-canvas/index.js';
31
+ export { RunToolLoopOptions as AppToolLoopOptions, ToolLoopAssistantToolCall as LoopAssistantToolCall, ToolLoopMessage as LoopMessage, ToolLoopCall as LoopToolCall, StreamToolLoopOptions as StreamAppToolLoopOptions, StreamToolLoopYield as StreamLoopYield, ToolLoopEvent, ToolLoopResult, ToolLoopStopReason, runToolLoop as runAppToolLoop, streamToolLoop as streamAppToolLoop } from '@tangle-network/agent-runtime';
31
32
  export { C as CatalogModel, M as ModelCatalog, R as RouterModel, _ as __resetCatalogCache, b as buildCatalog, f as fetchModelCatalog, n as normalizeModelId } from './model-catalog-BEAEVDaa.js';
32
33
  export { CompletionRequirement, CompletionVerdict, CorrectnessChecker, ProducedState, RuntimeEventLike, SatisfiedBy, TaskGold, createLlmCorrectnessChecker, extractProducedState, verifyCompletion, weightedComposite } from '@tangle-network/agent-eval';
33
34
  export { C as CreateTangleRouterModelConfigOptions, D as DEFAULT_TANGLE_BILLING_ENFORCEMENT_ENV_VAR, a as DEFAULT_TANGLE_ROUTER_BASE_URL, R as ResolveModelOptions, b as ResolveUserTangleExecutionKeyForUserOptions, c as ResolveUserTangleExecutionKeyOptions, d as ResolvedTangleExecutionKey, T as TangleBillingEnforcementOptions, e as TangleExecutionEnvironment, f as TangleExecutionKeyError, g as TangleExecutionKeyErrorCode, h as TangleExecutionKeyHttpError, i as TangleExecutionKeySource, j as TangleModelConfig, k as createTangleRouterModelConfig, l as isTangleBillingEnforcementDisabled, m as isTangleExecutionKeyError, r as resolveTangleExecutionEnvironment, n as resolveTangleModelConfig, o as resolveUserTangleExecutionKey, p as resolveUserTangleExecutionKeyForUser, t as tangleExecutionKeyHttpError } from './model-CKzniMMr.js';
package/dist/index.js CHANGED
@@ -245,9 +245,11 @@ import {
245
245
  createCapabilityToken,
246
246
  createExpiringCapabilityToken,
247
247
  handleAppToolRequest,
248
+ resolveToolCapabilities,
249
+ restrictTaxonomy,
248
250
  verifyCapabilityToken,
249
251
  verifyExpiringCapabilityToken
250
- } from "./chunk-ABGSFUJQ.js";
252
+ } from "./chunk-MH6AVXQ7.js";
251
253
  import {
252
254
  DEFAULT_APP_TOOL_PATHS,
253
255
  DEFAULT_HEADER_NAMES,
@@ -278,10 +280,10 @@ import {
278
280
  fetchModelCatalog,
279
281
  mergeSurfaceOverlay,
280
282
  normalizeModelId,
281
- runAppToolLoop,
282
- streamAppToolLoop,
283
+ runToolLoop,
284
+ streamToolLoop,
283
285
  toLoopEvents
284
- } from "./chunk-ETX4O4BB.js";
286
+ } from "./chunk-HD4NFA4U.js";
285
287
  import {
286
288
  DEFAULT_TANGLE_BILLING_ENFORCEMENT_ENV_VAR,
287
289
  DEFAULT_TANGLE_ROUTER_BASE_URL,
@@ -303,7 +305,7 @@ import {
303
305
  dispatchAppTool,
304
306
  isAppToolName,
305
307
  outcomeStatus
306
- } from "./chunk-QAQBR6KQ.js";
308
+ } from "./chunk-JZZ6AWF4.js";
307
309
  import {
308
310
  createLlmCorrectnessChecker,
309
311
  createTokenRecallChecker,
@@ -311,7 +313,7 @@ import {
311
313
  producedFromToolEvents,
312
314
  verifyCompletion,
313
315
  weightedComposite
314
- } from "./chunk-4NXVI7PW.js";
316
+ } from "./chunk-FA4XR66Y.js";
315
317
  import {
316
318
  buildKnowledgeRequirements,
317
319
  deriveSignals
@@ -535,13 +537,15 @@ export {
535
537
  resolveSessionHarness,
536
538
  resolveTangleExecutionEnvironment,
537
539
  resolveTangleModelConfig,
540
+ resolveToolCapabilities,
538
541
  resolveToolId,
539
542
  resolveToolName,
540
543
  resolveUserTangleExecutionKey,
541
544
  resolveUserTangleExecutionKeyForUser,
545
+ restrictTaxonomy,
542
546
  revealSpan,
543
547
  reviewCandidate,
544
- runAppToolLoop,
548
+ runToolLoop as runAppToolLoop,
545
549
  safeParseAssetSpec,
546
550
  scaleForPreset,
547
551
  scalePageForChannelPreset,
@@ -552,7 +556,7 @@ export {
552
556
  stepAgentActivity,
553
557
  stepGateProposalId,
554
558
  storeApplyScenePlan,
555
- streamAppToolLoop,
559
+ streamToolLoop as streamAppToolLoop,
556
560
  summarize,
557
561
  tangleExecutionKeyHttpError,
558
562
  timedEventsFromLines,
@@ -1,4 +1,4 @@
1
- import { f as AppToolTaxonomy, b as AppToolContext } from './types-By4B3K37.js';
1
+ import { f as AppToolTaxonomy, b as AppToolContext } from './types-2rOJo8Hc.js';
2
2
 
3
3
  /** The four canonical app-tool names. Stable identifiers the model calls in
4
4
  * both the sandbox (MCP server name) and runtime (function-tool name) paths. */
@@ -1,6 +1,6 @@
1
1
  import { KeyProvisioner, KeyCrypto, WorkspaceKeyManager, WorkspaceKeyStore } from '../billing/index.js';
2
2
  import { KnowledgeStateAccessor } from '../knowledge/index.js';
3
- import { c as AppToolHandlers } from '../types-By4B3K37.js';
3
+ import { c as AppToolHandlers } from '../types-2rOJo8Hc.js';
4
4
  import { KvLike } from '../web/index.js';
5
5
  import '@tangle-network/agent-eval';
6
6
 
@@ -1,7 +1,10 @@
1
+ import * as _tangle_network_agent_runtime from '@tangle-network/agent-runtime';
2
+ import { ToolLoopMessage, ToolLoopResult, StreamToolLoopYield, ToolLoopCall } from '@tangle-network/agent-runtime';
3
+ export { RunToolLoopOptions as AppToolLoopOptions, ToolLoopAssistantToolCall as LoopAssistantToolCall, ToolLoopMessage as LoopMessage, ToolLoopCall as LoopToolCall, StreamToolLoopOptions as StreamAppToolLoopOptions, StreamToolLoopYield as StreamLoopYield, ToolLoopEvent, ToolLoopResult, ToolLoopStopReason, runToolLoop as runAppToolLoop, streamToolLoop as streamAppToolLoop } from '@tangle-network/agent-runtime';
1
4
  export { C as CatalogModel, M as ModelCatalog, R as RouterModel, _ as __resetCatalogCache, b as buildCatalog, f as fetchModelCatalog, n as normalizeModelId } from '../model-catalog-BEAEVDaa.js';
2
5
  export { C as CreateTangleRouterModelConfigOptions, D as DEFAULT_TANGLE_BILLING_ENFORCEMENT_ENV_VAR, a as DEFAULT_TANGLE_ROUTER_BASE_URL, R as ResolveModelOptions, b as ResolveUserTangleExecutionKeyForUserOptions, c as ResolveUserTangleExecutionKeyOptions, d as ResolvedTangleExecutionKey, T as TangleBillingEnforcementOptions, e as TangleExecutionEnvironment, f as TangleExecutionKeyError, g as TangleExecutionKeyErrorCode, h as TangleExecutionKeyHttpError, i as TangleExecutionKeySource, j as TangleModelConfig, k as createTangleRouterModelConfig, l as isTangleBillingEnforcementDisabled, m as isTangleExecutionKeyError, r as resolveTangleExecutionEnvironment, n as resolveTangleModelConfig, o as resolveUserTangleExecutionKey, p as resolveUserTangleExecutionKeyForUser, t as tangleExecutionKeyHttpError } from '../model-CKzniMMr.js';
3
- import { b as AppToolContext, e as AppToolProducedEvent, f as AppToolTaxonomy, c as AppToolHandlers, d as AppToolOutcome } from '../types-By4B3K37.js';
4
- import { a as AppToolMcpServer } from '../mcp-CIupfjxV.js';
6
+ import { b as AppToolContext, e as AppToolProducedEvent, f as AppToolTaxonomy, c as AppToolHandlers, d as AppToolOutcome } from '../types-2rOJo8Hc.js';
7
+ import { a as AppToolMcpServer } from '../mcp-eZCmkgCF.js';
5
8
 
6
9
  /**
7
10
  * OpenAI-compatible stream → `LoopEvent` adapter, for NON-sandbox copilots.
@@ -75,7 +78,7 @@ interface OpenAICompatStreamTurnOptions {
75
78
  * const cfg = resolveTangleModelConfig() // or { baseUrl, apiKey, model }
76
79
  * streamAppToolLoop({ streamTurn: createOpenAICompatStreamTurn({ ...cfg, tools }), executeToolCall, ... })
77
80
  */
78
- declare function createOpenAICompatStreamTurn(opts: OpenAICompatStreamTurnOptions): (messages: LoopMessage[]) => AsyncIterable<LoopEvent>;
81
+ declare function createOpenAICompatStreamTurn(opts: OpenAICompatStreamTurnOptions): (messages: ToolLoopMessage[]) => AsyncIterable<LoopEvent>;
79
82
 
80
83
  /**
81
84
  * `createAgentRuntime` — the in-process agent core, assembled.
@@ -138,7 +141,7 @@ interface CreateAgentRuntimeOptions {
138
141
  extraTools?: unknown[];
139
142
  /** Execute a tool that is NOT one of the four app tools (e.g. an integration
140
143
  * action). Only consulted for names {@link isOtherExecutableTool} accepts. */
141
- executeOtherTool?: (call: LoopToolCall, ctx: AppToolContext) => Promise<AppToolOutcome>;
144
+ executeOtherTool?: (call: ToolLoopCall, ctx: AppToolContext) => Promise<AppToolOutcome>;
142
145
  /** Which non-app tool names are executable here. Required if {@link executeOtherTool} is set. */
143
146
  isOtherExecutableTool?: (toolName: string) => boolean;
144
147
  }
@@ -161,7 +164,7 @@ interface AgentRuntime {
161
164
  run(userMessage: string, turn: AgentTurnOptions): Promise<ToolLoopResult>;
162
165
  /** Stream the bounded tool loop: yields each raw model event and each executed
163
166
  * tool result as it happens (for SSE re-emission + telemetry). */
164
- stream(userMessage: string, turn: AgentTurnOptions): AsyncGenerator<StreamLoopYield<LoopEvent>, void, unknown>;
167
+ stream(userMessage: string, turn: AgentTurnOptions): AsyncGenerator<StreamToolLoopYield<LoopEvent>, void, unknown>;
165
168
  }
166
169
  /**
167
170
  * Create an in-process agent runtime for one agent. See the module doc for the
@@ -277,46 +280,17 @@ interface SurfaceMergeBase {
277
280
  */
278
281
  declare function mergeSurfaceOverlay<TBase extends SurfaceMergeBase>(base: TBase, overlay: SurfaceOverlay): TBase & SurfaceMergeBase;
279
282
 
280
- interface LoopToolCall {
281
- toolCallId?: string;
282
- toolName: string;
283
- args: Record<string, unknown>;
284
- }
285
- /** One OpenAI-shaped tool-call entry on an assistant message. */
286
- interface LoopAssistantToolCall {
287
- id: string;
288
- type: 'function';
289
- function: {
290
- name: string;
291
- arguments: string;
292
- };
293
- }
294
283
  /**
295
- * A message in the running conversation the loop sends to `streamTurn`.
296
- *
297
- * The base `{ role, content }` covers `system` / `user` / plain `assistant`
298
- * turns. Two optional fields carry the OpenAI function-calling contract so the
299
- * model reads its own tool use back correctly instead of re-issuing it:
284
+ * Events the app's OpenAI-compat stream adapter ({@link toLoopEvents}) yields.
300
285
  *
301
- * - an assistant turn that emitted tool calls carries `tool_calls`, and its
302
- * `content` is `null` when the turn was tool-only;
303
- * - each tool result is its own `{ role: 'tool', tool_call_id, content }`
304
- * message keyed to the call that produced it.
305
- *
306
- * Widening is additive: a `streamTurn` that reads only `role` + `content` still
307
- * works; one that forwards the whole message to an OpenAI-compatible endpoint
308
- * now gets correct tool history. */
309
- interface LoopMessage {
310
- role: string;
311
- content: string | null;
312
- tool_calls?: LoopAssistantToolCall[];
313
- tool_call_id?: string;
314
- }
315
- /** Events a turn stream yields. `text` accumulates into the final answer;
316
- * `tool_call` is collected for dispatch; `reasoning` and `usage` pass through
317
- * for UIs that render thinking sections and per-message token/cost metrics.
318
- * Extra event types pass through untouched (the caller re-emits them to its
319
- * own UI stream). */
286
+ * This is the app's own `Raw` event type for the streaming loop — the canonical
287
+ * `streamToolLoop<Raw>` is generic over it. It widens the substrate's
288
+ * tool-loop event with `reasoning` (DeepSeek/router `reasoning_content` /
289
+ * `thinking` deltas, rendered as thinking sections) and `usage` (per-message
290
+ * token accounting) — neither belongs in the substrate's loop contract, so they
291
+ * stay here. The adapter maps each into the `streamTurn` seam; `text` and
292
+ * `tool_call` drive the loop, `reasoning` / `usage` pass through to the UI.
293
+ */
320
294
  type LoopEvent = {
321
295
  type: 'text';
322
296
  text: string;
@@ -325,7 +299,7 @@ type LoopEvent = {
325
299
  text: string;
326
300
  } | {
327
301
  type: 'tool_call';
328
- call: LoopToolCall;
302
+ call: _tangle_network_agent_runtime.ToolLoopCall;
329
303
  } | {
330
304
  type: 'usage';
331
305
  usage: {
@@ -336,121 +310,5 @@ type LoopEvent = {
336
310
  type: 'other';
337
311
  event: unknown;
338
312
  };
339
- /** Why the loop stopped. `completed` = model finished naturally; `stuck-loop` =
340
- * ≥3 consecutive identical tool calls (same tool + args); `backstop` = hit the
341
- * runaway-backstop cap (200 by default); `deadline` = wall-clock deadlineMs
342
- * exceeded; `budget` = maxCostUsd exhausted. Non-`completed` stops are infra /
343
- * resource outcomes — eval scoring must distinguish them from capability failure. */
344
- type ToolLoopStopReason = 'completed' | 'stuck-loop' | 'backstop' | 'deadline' | 'budget';
345
- interface ToolLoopResult {
346
- /** The model's final text across the loop. */
347
- finalText: string;
348
- /** Every tool call executed, with its outcome, in order. */
349
- toolResults: Array<{
350
- call: LoopToolCall;
351
- label: string;
352
- outcome: AppToolOutcome;
353
- }>;
354
- /** Number of model turns run (1 + tool-driven re-runs). */
355
- turns: number;
356
- /** Why the loop stopped. */
357
- stopReason: ToolLoopStopReason;
358
- /** @deprecated Use `stopReason !== 'completed'` instead. */
359
- cappedOut: boolean;
360
- }
361
- interface AppToolLoopOptions {
362
- systemPrompt: string;
363
- userMessage: string;
364
- priorMessages?: Array<{
365
- role: string;
366
- content: string;
367
- }>;
368
- /** Stream one model turn over the running message list. The app wraps its
369
- * backend here. Messages follow {@link LoopMessage}: a tool-calling assistant
370
- * turn carries `tool_calls`, and each tool result is a `role: 'tool'` message.
371
- * A backend that reads only `role` + `content` is unaffected. */
372
- streamTurn: (messages: LoopMessage[]) => AsyncIterable<LoopEvent>;
373
- /** Execute one tool call. The app routes to its integration executor / app-tool
374
- * executor and returns the outcome. */
375
- executeToolCall: (call: LoopToolCall) => Promise<AppToolOutcome>;
376
- /** Which emitted tool names are executable (others are ignored — e.g. a UI-only
377
- * tool the app renders but doesn't run here). */
378
- isExecutableTool: (toolName: string) => boolean;
379
- /** Runaway-backstop cap. Default 200 — set far above any legitimate workflow.
380
- * For per-workflow limits use `maxCostUsd` or `deadlineMs` instead. */
381
- maxToolTurns?: number;
382
- /** Wall-clock deadline in ms since epoch (Date.now()-based). When exceeded the
383
- * loop stops with stopReason `deadline`. */
384
- deadlineMs?: number;
385
- /** Maximum total cost in USD. Requires `costOf` to meter each tool call. */
386
- maxCostUsd?: number;
387
- /** Return the USD cost of one outcome. Required for `maxCostUsd` to work. */
388
- costOf?: (call: LoopToolCall, outcome: AppToolOutcome) => number;
389
- /** Render one tool outcome as the `content` of its `role: 'tool'` message.
390
- * Default is a compact `<label> → ok/failed: …`. */
391
- renderResult?: (label: string, outcome: AppToolOutcome) => string;
392
- /** Map a tool call to the label its result is keyed under (default: toolName). */
393
- labelFor?: (call: LoopToolCall) => string;
394
- }
395
- /**
396
- * Run the bounded tool loop and return the final text + every executed tool
397
- * outcome. Yields nothing — it's an awaitable driver; callers that need to
398
- * re-emit events to a UI stream should do so inside `streamTurn`. (A streaming
399
- * variant can wrap this later; keeping the core awaitable makes it trivially
400
- * testable.)
401
- */
402
- declare function runAppToolLoop(opts: AppToolLoopOptions): Promise<ToolLoopResult>;
403
- type StreamLoopYield<Raw> = {
404
- kind: 'event';
405
- event: Raw;
406
- } | {
407
- kind: 'tool_result';
408
- toolName: string;
409
- toolCallId?: string;
410
- label: string;
411
- outcome: AppToolOutcome;
412
- } | {
413
- kind: 'capped';
414
- pending: number;
415
- stopReason: Exclude<ToolLoopStopReason, 'completed'>;
416
- };
417
- interface StreamAppToolLoopOptions<Raw> {
418
- systemPrompt: string;
419
- userMessage: string;
420
- priorMessages?: Array<{
421
- role: string;
422
- content: string;
423
- }>;
424
- /** Stream one model turn (the app wraps its backend / runAgentTaskStream).
425
- * Messages follow {@link LoopMessage}: a tool-calling assistant turn carries
426
- * `tool_calls`, and each tool result is a `role: 'tool'` message. */
427
- streamTurn: (messages: LoopMessage[]) => AsyncIterable<Raw>;
428
- /** Text contribution of a raw event, '' if none — used to record the
429
- * assistant's turn so the next turn has its context. */
430
- extractText: (event: Raw) => string;
431
- /** The tool call a raw event represents, or null. */
432
- extractToolCall: (event: Raw) => LoopToolCall | null;
433
- /** Which tool names are executable here (others pass through, unexecuted). */
434
- isExecutableTool: (toolName: string) => boolean;
435
- /** Execute one call — the app routes to its integration / app-tool executor. */
436
- executeToolCall: (call: LoopToolCall) => Promise<AppToolOutcome>;
437
- /** Runaway-backstop cap. Default 200 — set far above any legitimate workflow. */
438
- maxToolTurns?: number;
439
- /** Wall-clock deadline in ms since epoch (Date.now()-based). */
440
- deadlineMs?: number;
441
- /** Maximum total cost in USD. Requires `costOf` to meter each tool call. */
442
- maxCostUsd?: number;
443
- /** Return the USD cost of one outcome. Required for `maxCostUsd` to work. */
444
- costOf?: (call: LoopToolCall, outcome: AppToolOutcome) => number;
445
- renderResult?: (label: string, outcome: AppToolOutcome) => string;
446
- labelFor?: (call: LoopToolCall) => string;
447
- }
448
- /**
449
- * The streaming bounded tool loop. Yields `event` for each raw turn event and
450
- * `tool_result` for each executed tool; emits a single `capped` (with stopReason)
451
- * when it stops for any non-completed reason. The app drives telemetry + UI
452
- * emission off the yielded items.
453
- */
454
- declare function streamAppToolLoop<Raw>(opts: StreamAppToolLoopOptions<Raw>): AsyncGenerator<StreamLoopYield<Raw>, void, unknown>;
455
313
 
456
- export { type AgentRuntime, type AgentRuntimeModelConfig, type AgentTurnOptions, type AnySurfaceKind, type AppToolLoopOptions, type CreateAgentRuntimeOptions, type LoopAssistantToolCall, type LoopEvent, type LoopMessage, type LoopToolCall, type OpenAICompatStreamTurnOptions, type OpenAIStreamChunk, type StreamAppToolLoopOptions, type StreamLoopYield, type SurfaceKindDefinition, type SurfaceMcpServer, type SurfaceMergeBase, type SurfaceOverlay, type SurfacePermissionValue, type SurfaceRegistry, type ToolLoopResult, type ToolLoopStopReason, createAgentRuntime, createOpenAICompatStreamTurn, createSurfaceRegistry, defineSurfaceKind, mergeSurfaceOverlay, runAppToolLoop, streamAppToolLoop, toLoopEvents };
314
+ export { type AgentRuntime, type AgentRuntimeModelConfig, type AgentTurnOptions, type AnySurfaceKind, type CreateAgentRuntimeOptions, type LoopEvent, type OpenAICompatStreamTurnOptions, type OpenAIStreamChunk, type SurfaceKindDefinition, type SurfaceMcpServer, type SurfaceMergeBase, type SurfaceOverlay, type SurfacePermissionValue, type SurfaceRegistry, createAgentRuntime, createOpenAICompatStreamTurn, createSurfaceRegistry, defineSurfaceKind, mergeSurfaceOverlay, toLoopEvents };
@@ -8,10 +8,10 @@ import {
8
8
  fetchModelCatalog,
9
9
  mergeSurfaceOverlay,
10
10
  normalizeModelId,
11
- runAppToolLoop,
12
- streamAppToolLoop,
11
+ runToolLoop,
12
+ streamToolLoop,
13
13
  toLoopEvents
14
- } from "../chunk-ETX4O4BB.js";
14
+ } from "../chunk-HD4NFA4U.js";
15
15
  import {
16
16
  DEFAULT_TANGLE_BILLING_ENFORCEMENT_ENV_VAR,
17
17
  DEFAULT_TANGLE_ROUTER_BASE_URL,
@@ -25,7 +25,7 @@ import {
25
25
  resolveUserTangleExecutionKeyForUser,
26
26
  tangleExecutionKeyHttpError
27
27
  } from "../chunk-EHPK7GKR.js";
28
- import "../chunk-QAQBR6KQ.js";
28
+ import "../chunk-JZZ6AWF4.js";
29
29
  export {
30
30
  DEFAULT_TANGLE_BILLING_ENFORCEMENT_ENV_VAR,
31
31
  DEFAULT_TANGLE_ROUTER_BASE_URL,
@@ -46,8 +46,8 @@ export {
46
46
  resolveTangleModelConfig,
47
47
  resolveUserTangleExecutionKey,
48
48
  resolveUserTangleExecutionKeyForUser,
49
- runAppToolLoop,
50
- streamAppToolLoop,
49
+ runToolLoop as runAppToolLoop,
50
+ streamToolLoop as streamAppToolLoop,
51
51
  tangleExecutionKeyHttpError,
52
52
  toLoopEvents
53
53
  };
@@ -1,8 +1,8 @@
1
1
  import { j as SequenceMediaKind, o as SequenceTimeline, r as TimelineInterval, m as SequenceStore } from '../store-gckrNq-g.js';
2
2
  export { M as MIN_SEQUENCE_CLIP_FRAMES, N as NewSequenceClip, a as NewSequenceDecision, b as NewSequenceTrack, S as SequenceClip, c as SequenceClipMedia, d as SequenceClipPatch, e as SequenceDecision, f as SequenceExportFormat, g as SequenceExportRecord, h as SequenceExportStatus, i as SequenceFrameSnapshot, k as SequenceMeta, l as SequenceStatus, n as SequenceStoreScope, p as SequenceTrack, q as SequenceTrackKind, T as TimelineClipBounds, s as assertClipFitsSequence, t as chooseCaptionPlacement, u as clampClipDuration, v as clampClipStart, w as formatSeconds, x as formatTimecode, y as framesToSeconds, z as secondsToFrames, A as snapshotFrame, B as trackIntervals } from '../store-gckrNq-g.js';
3
3
  export { A as AddCaptionOperation, C as CaptionTargetResolution, a as CreateTrackOperation, D as DeleteClipOperation, E as ExtendSequenceOperation, M as MoveClipOperation, P as PlaceClipOperation, Q as QueueExportOperation, S as SEQUENCE_OPERATION_TYPES, b as SequenceApplyResult, c as SequenceOperation, d as SequenceOperationContext, e as SequenceOperationType, f as SequencePlan, g as SetClipDisabledOperation, h as SetClipTextOperation, i as SplitClipOperation, T as TrimClipOperation, j as applySequenceOperation, k as applySequenceOperations, l as assertSequenceMediaUrl, m as captionTrackNameForLanguage, n as lastClipEndFrame, p as parseSequenceOperations, r as resolveCaptionPlacement, o as resolveCaptionTarget, q as resolvePlaceClipTrack, v as validateAddCaption, s as validateCreateTrack, t as validateDeleteClip, u as validateExtendSequence, w as validateMoveClip, x as validatePlaceClip, y as validateQueueExport, z as validateSequenceOperation, B as validateSequenceOperations, F as validateSetClipDisabled, G as validateSetClipText, H as validateSplitClip, I as validateTrimClip } from '../apply-Cp8c3K9D.js';
4
- import { f as ToolHeaderNames, a as AppToolMcpServer } from '../mcp-CIupfjxV.js';
5
- import { b as AppToolContext } from '../types-By4B3K37.js';
4
+ import { f as ToolHeaderNames, a as AppToolMcpServer } from '../mcp-eZCmkgCF.js';
5
+ import { b as AppToolContext } from '../types-2rOJo8Hc.js';
6
6
 
7
7
  /**
8
8
  * Pure interchange-format builders over `SequenceTimeline` — SRT, WebVTT,
@@ -1,7 +1,7 @@
1
- import { b as AppToolName, f as ToolHeaderNames } from '../mcp-CIupfjxV.js';
2
- export { A as APP_TOOL_NAMES, a as AppToolMcpServer, c as AuthenticateOptions, B as BuildHttpMcpServerOptions, d as BuildMcpServerOptions, D as DEFAULT_APP_TOOL_PATHS, e as DEFAULT_HEADER_NAMES, O as OpenAIFunctionTool, T as ToolAuthResult, g as authenticateToolRequest, h as buildAppToolMcpServer, i as buildAppToolOpenAITools, j as buildHttpMcpServer, k as isAppToolName, r as readToolArgs } from '../mcp-CIupfjxV.js';
3
- import { c as AppToolHandlers, f as AppToolTaxonomy, b as AppToolContext, e as AppToolProducedEvent, d as AppToolOutcome } from '../types-By4B3K37.js';
4
- export { A as AddCitationArgs, a as AddCitationResult, R as RenderUiArgs, g as RenderUiResult, S as ScheduleFollowupArgs, h as ScheduleFollowupResult, i as SubmitProposalArgs, j as SubmitProposalResult } from '../types-By4B3K37.js';
1
+ import { b as AppToolName, f as ToolHeaderNames } from '../mcp-eZCmkgCF.js';
2
+ export { A as APP_TOOL_NAMES, a as AppToolMcpServer, c as AuthenticateOptions, B as BuildHttpMcpServerOptions, d as BuildMcpServerOptions, D as DEFAULT_APP_TOOL_PATHS, e as DEFAULT_HEADER_NAMES, O as OpenAIFunctionTool, T as ToolAuthResult, g as authenticateToolRequest, h as buildAppToolMcpServer, i as buildAppToolOpenAITools, j as buildHttpMcpServer, k as isAppToolName, r as readToolArgs } from '../mcp-eZCmkgCF.js';
3
+ import { f as AppToolTaxonomy, c as AppToolHandlers, b as AppToolContext, e as AppToolProducedEvent, d as AppToolOutcome } from '../types-2rOJo8Hc.js';
4
+ export { A as AddCitationArgs, a as AddCitationResult, R as RenderUiArgs, g as RenderUiResult, S as ScheduleFollowupArgs, h as ScheduleFollowupResult, i as SubmitProposalArgs, j as SubmitProposalResult } from '../types-2rOJo8Hc.js';
5
5
  export { C as CreateMcpToolHandlerOptions, M as MCP_PROTOCOL_VERSIONS, a as McpProtocolVersion, b as McpServerInfo, c as McpToolDefinition, d as createMcpToolHandler } from '../mcp-rpc-DLw_r9PQ.js';
6
6
 
7
7
  /** A correctable bad-input error a tool handler throws; the HTTP layer maps it
@@ -66,6 +66,67 @@ declare function verifyExpiringCapabilityToken(subject: string, token: string, o
66
66
  now?: () => number;
67
67
  }): Promise<boolean>;
68
68
 
69
+ /**
70
+ * Capability gating — compose an agent session's tool surface from a
71
+ * product-defined capability registry.
72
+ *
73
+ * Products that let users pick what an agent can do (a "Studio" agent with the
74
+ * full build toolset vs a clean "Assistant" with none) all need the same
75
+ * mechanics: a registry of named capabilities, each unlocking proposal types
76
+ * and/or named tool groups, resolved against the product's
77
+ * {@link AppToolTaxonomy} into the concrete tools to expose. The mechanics are
78
+ * generic and live here; the capability VOCABULARY (ids, labels, which
79
+ * proposal types, which tool groups) is the product's.
80
+ */
81
+
82
+ /** One toggleable tool group in a product's capability registry. */
83
+ interface ToolCapability {
84
+ id: string;
85
+ label: string;
86
+ description: string;
87
+ /** Proposal types this capability unlocks (intersected with the taxonomy,
88
+ * so a capability can never widen the product's proposal surface). */
89
+ proposalTypes?: readonly string[];
90
+ /** Unlocks every taxonomy proposal type beyond the base set — the domain's
91
+ * specialized long tail (risk_assessment, vuln_report, …). */
92
+ domainActions?: boolean;
93
+ /** Named product tool groups (e.g. 'sandbox', 'integrations') this
94
+ * capability unlocks. The vocabulary is the product's; the resolver only
95
+ * unions them. */
96
+ toolGroups?: readonly string[];
97
+ }
98
+ interface ResolveToolCapabilitiesOptions {
99
+ taxonomy: AppToolTaxonomy;
100
+ /** The product's full capability registry. */
101
+ capabilities: readonly ToolCapability[];
102
+ /** Enabled capability ids. `undefined` means full access (legacy callers
103
+ * that don't send a capability set); an explicit `[]` means a pure chat
104
+ * agent with no tools. Unknown ids are ignored. */
105
+ enabled: readonly string[] | undefined;
106
+ /** The shared base proposal types `domainActions` excludes. Defaults to
107
+ * every type some capability names explicitly via `proposalTypes` — i.e.
108
+ * "domain actions" are the taxonomy types no capability claims. */
109
+ baseProposalTypes?: readonly string[];
110
+ }
111
+ interface ResolvedToolCapabilities {
112
+ /** Proposal types to keep — feed to {@link restrictTaxonomy}. */
113
+ proposalTypes: string[];
114
+ /** Product tool groups to expose (deduped union across enabled caps). */
115
+ toolGroups: string[];
116
+ }
117
+ /**
118
+ * Resolve an enabled capability-id set against a taxonomy into the concrete
119
+ * tool surface. Fail-closed: only types present in the taxonomy survive, and
120
+ * an empty `enabled` set yields no tools at all.
121
+ */
122
+ declare function resolveToolCapabilities(opts: ResolveToolCapabilitiesOptions): ResolvedToolCapabilities;
123
+ /**
124
+ * Restrict a taxonomy to a subset of proposal types, intersecting the
125
+ * regulated subset too — the regulated label survives restriction, so a
126
+ * narrowed agent can never launder a regulated type into an unregulated one.
127
+ */
128
+ declare function restrictTaxonomy(taxonomy: AppToolTaxonomy, allowed: readonly string[]): AppToolTaxonomy;
129
+
69
130
  interface DispatchOptions {
70
131
  handlers: AppToolHandlers;
71
132
  taxonomy: AppToolTaxonomy;
@@ -135,4 +196,4 @@ interface HandleToolRequestOptions extends DispatchOptions {
135
196
  */
136
197
  declare function handleAppToolRequest(request: Request, opts: HandleToolRequestOptions): Promise<Response>;
137
198
 
138
- export { AppToolContext, AppToolHandlers, AppToolName, AppToolOutcome, AppToolProducedEvent, type AppToolRuntimeExecutor, AppToolTaxonomy, type CapabilityTokenOptions, type DispatchOptions, type ExpiringCapabilityTokenOptions, type HandleToolRequestOptions, type RuntimeExecutorOptions, ToolHeaderNames, ToolInputError, createAppToolRuntimeExecutor, createCapabilityToken, createExpiringCapabilityToken, dispatchAppTool, handleAppToolRequest, outcomeStatus, verifyCapabilityToken, verifyExpiringCapabilityToken };
199
+ export { AppToolContext, AppToolHandlers, AppToolName, AppToolOutcome, AppToolProducedEvent, type AppToolRuntimeExecutor, AppToolTaxonomy, type CapabilityTokenOptions, type DispatchOptions, type ExpiringCapabilityTokenOptions, type HandleToolRequestOptions, type ResolveToolCapabilitiesOptions, type ResolvedToolCapabilities, type RuntimeExecutorOptions, type ToolCapability, ToolHeaderNames, ToolInputError, createAppToolRuntimeExecutor, createCapabilityToken, createExpiringCapabilityToken, dispatchAppTool, handleAppToolRequest, outcomeStatus, resolveToolCapabilities, restrictTaxonomy, verifyCapabilityToken, verifyExpiringCapabilityToken };
@@ -2,9 +2,11 @@ import {
2
2
  createCapabilityToken,
3
3
  createExpiringCapabilityToken,
4
4
  handleAppToolRequest,
5
+ resolveToolCapabilities,
6
+ restrictTaxonomy,
5
7
  verifyCapabilityToken,
6
8
  verifyExpiringCapabilityToken
7
- } from "../chunk-ABGSFUJQ.js";
9
+ } from "../chunk-MH6AVXQ7.js";
8
10
  import {
9
11
  DEFAULT_APP_TOOL_PATHS,
10
12
  DEFAULT_HEADER_NAMES,
@@ -23,7 +25,7 @@ import {
23
25
  dispatchAppTool,
24
26
  isAppToolName,
25
27
  outcomeStatus
26
- } from "../chunk-QAQBR6KQ.js";
28
+ } from "../chunk-JZZ6AWF4.js";
27
29
  export {
28
30
  APP_TOOL_NAMES,
29
31
  DEFAULT_APP_TOOL_PATHS,
@@ -43,6 +45,8 @@ export {
43
45
  isAppToolName,
44
46
  outcomeStatus,
45
47
  readToolArgs,
48
+ resolveToolCapabilities,
49
+ restrictTaxonomy,
46
50
  verifyCapabilityToken,
47
51
  verifyExpiringCapabilityToken
48
52
  };
@@ -110,14 +110,17 @@ type AppToolProducedEvent = {
110
110
  proposalId: string;
111
111
  title: string;
112
112
  status: 'pending' | 'executed';
113
+ content?: string;
113
114
  } | {
114
115
  type: 'artifact';
115
116
  path: string;
116
117
  content: string;
117
118
  };
118
- /** Outcome of one tool dispatch — structurally compatible with the integration
119
- * tool-outcome union the agent-runtime chat loop already folds into a
120
- * tool_result. */
119
+ /** Outcome of one tool dispatch — structurally identical to the agent-runtime
120
+ * tool-loop's `ToolCallOutcome`, so a dispatched outcome folds straight into
121
+ * the loop's `role: 'tool'` result message. Defined here (not imported) to keep
122
+ * the `tools/` module substrate-free: it depends only on Web `Request`/
123
+ * `Response`, never on the agent runtime. */
121
124
  type AppToolOutcome = {
122
125
  ok: true;
123
126
  result: unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-app",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "packageManager": "pnpm@10.33.4",
5
5
  "description": "Application-shell framework for Tangle agent products: a bounded tool loop, the structured agent\u2192app tool side channel, integration-hub client, per-workspace billing, and crypto \u2014 composed over the Tangle agent substrate through typed seams.",
6
6
  "keywords": [
@@ -192,8 +192,9 @@
192
192
  "typecheck": "tsc --noEmit"
193
193
  },
194
194
  "devDependencies": {
195
- "@tangle-network/agent-eval": "^0.82.0",
195
+ "@tangle-network/agent-eval": "^0.83.0",
196
196
  "@tangle-network/agent-integrations": "^0.32.0",
197
+ "@tangle-network/agent-runtime": "^0.52.0",
197
198
  "@tangle-network/agent-knowledge": "^1.5.2",
198
199
  "@testing-library/dom": "^10.4.1",
199
200
  "@testing-library/react": "^16.3.2",
@@ -214,10 +215,10 @@
214
215
  },
215
216
  "peerDependencies": {
216
217
  "@huggingface/transformers": ">=3",
217
- "@tangle-network/agent-eval": ">=0.82.0",
218
+ "@tangle-network/agent-eval": ">=0.83.0",
218
219
  "@tangle-network/agent-integrations": ">=0.32.0",
219
220
  "@tangle-network/agent-knowledge": ">=1.5.0",
220
- "@tangle-network/agent-runtime": ">=0.21.0",
221
+ "@tangle-network/agent-runtime": ">=0.52.0",
221
222
  "drizzle-orm": ">=0.36",
222
223
  "react": ">=18",
223
224
  "konva": ">=9",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/eval/index.ts"],"sourcesContent":["/**\n * Eval — the app-shell BRIDGE to `@tangle-network/agent-eval`, not a reimpl.\n *\n * The completion/scoring ENGINE lives in agent-eval (a peer dependency):\n * `verifyCompletion`, `extractProducedState`, `weightedComposite`,\n * `createLlmCorrectnessChecker`, and the `CompletionRequirement` / `TaskGold` /\n * `ProducedState` types — all re-exported here so a consumer has one import\n * root. This module adds only what agent-eval doesn't have and what is\n * app-shell-specific:\n *\n * 1. {@link producedFromToolEvents} — the bridge: turn the structured app-tool\n * side channel's `AppToolProducedEvent`s (from a tool runtime executor's\n * `onProduced`) into the `RuntimeEventLike`s agent-eval's\n * `extractProducedState` consumes. This is the one piece that knows about\n * the app-tool channel, so it belongs here, not in the engine.\n * 2. {@link createTokenRecallChecker} — a deterministic, no-LLM\n * `CorrectnessChecker` (agent-eval ships only the LLM one). For apps/tests\n * that gate completion without a judge call.\n *\n * Full campaigns (persona simulation, traces, scorecards, held-out gates) are\n * agent-eval's `runEvalCampaign` / `AgentDriver` / `BenchmarkRunner` — use them\n * directly; this module composes with them.\n */\nimport type { RuntimeEventLike, CompletionRequirement } from '@tangle-network/agent-eval'\nimport type { AppToolProducedEvent } from '../tools/types'\n\n// Re-export the engine so consumers import completion + scoring from one place.\nexport { verifyCompletion, extractProducedState, weightedComposite, createLlmCorrectnessChecker } from '@tangle-network/agent-eval'\nexport type {\n CompletionRequirement,\n TaskGold,\n ProducedState,\n SatisfiedBy,\n CompletionVerdict,\n CorrectnessChecker,\n RuntimeEventLike,\n} from '@tangle-network/agent-eval'\n\n/**\n * Bridge the app-tool side channel's produced events into the runtime-event\n * shape agent-eval's `extractProducedState` reads. Pipe it:\n * `verifyCompletion(taskGold, extractProducedState(producedFromToolEvents(events)), checker)`\n */\nexport function producedFromToolEvents(events: readonly AppToolProducedEvent[]): RuntimeEventLike[] {\n return events.map((e) =>\n e.type === 'proposal_created'\n ? { type: 'proposal_created', proposalId: e.proposalId, title: e.title, status: e.status }\n : { type: 'artifact', artifactId: `vault:${e.path}`, name: e.path, uri: `vault://${e.path}`, mimeType: 'text/markdown', content: e.content },\n )\n}\n\nconst STOPWORDS = new Set(['the', 'a', 'an', 'and', 'or', 'for', 'to', 'of', 'in', 'on', 'with', 'review', 'update', 'new', 'proposed'])\n\n/**\n * A deterministic `CorrectnessChecker` (agent-eval exports only\n * `createLlmCorrectnessChecker`). A produced item fulfils a requirement when\n * its content is substantive and recalls ≥ `minRecall` of the requirement\n * title's significant tokens. No network — the default gate for apps/tests\n * without an LLM judge. Pass to `verifyCompletion` as the checker.\n */\nexport function createTokenRecallChecker(opts: { minRecall?: number; minContentLength?: number } = {}): (\n requirement: CompletionRequirement,\n content: string,\n) => Promise<{ correct: boolean; reason: string }> {\n const minRecall = opts.minRecall ?? 0.5\n const minLen = opts.minContentLength ?? 120\n return async (requirement, content) => {\n const body = content.trim()\n if (body.length < minLen) return { correct: false, reason: `content too thin (${body.length} chars) to be the deliverable` }\n const tokens = requirement.title.toLowerCase().split(/[^a-z0-9]+/).filter((t) => t.length > 2 && !STOPWORDS.has(t))\n if (tokens.length === 0) return { correct: true, reason: 'requirement title has no significant tokens — structural match accepted' }\n const lower = body.toLowerCase()\n const hits = tokens.filter((t) => lower.includes(t)).length\n const recall = hits / tokens.length\n return recall >= minRecall\n ? { correct: true, reason: `content recalls ${hits}/${tokens.length} requirement tokens` }\n : { correct: false, reason: `content recalls only ${hits}/${tokens.length} requirement tokens` }\n }\n}\n"],"mappings":";AA2BA,SAAS,kBAAkB,sBAAsB,mBAAmB,mCAAmC;AAgBhG,SAAS,uBAAuB,QAA6D;AAClG,SAAO,OAAO;AAAA,IAAI,CAAC,MACjB,EAAE,SAAS,qBACP,EAAE,MAAM,oBAAoB,YAAY,EAAE,YAAY,OAAO,EAAE,OAAO,QAAQ,EAAE,OAAO,IACvF,EAAE,MAAM,YAAY,YAAY,SAAS,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,KAAK,WAAW,EAAE,IAAI,IAAI,UAAU,iBAAiB,SAAS,EAAE,QAAQ;AAAA,EAC/I;AACF;AAEA,IAAM,YAAY,oBAAI,IAAI,CAAC,OAAO,KAAK,MAAM,OAAO,MAAM,OAAO,MAAM,MAAM,MAAM,MAAM,QAAQ,UAAU,UAAU,OAAO,UAAU,CAAC;AAShI,SAAS,yBAAyB,OAA0D,CAAC,GAGjD;AACjD,QAAM,YAAY,KAAK,aAAa;AACpC,QAAM,SAAS,KAAK,oBAAoB;AACxC,SAAO,OAAO,aAAa,YAAY;AACrC,UAAM,OAAO,QAAQ,KAAK;AAC1B,QAAI,KAAK,SAAS,OAAQ,QAAO,EAAE,SAAS,OAAO,QAAQ,qBAAqB,KAAK,MAAM,gCAAgC;AAC3H,UAAM,SAAS,YAAY,MAAM,YAAY,EAAE,MAAM,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC;AAClH,QAAI,OAAO,WAAW,EAAG,QAAO,EAAE,SAAS,MAAM,QAAQ,+EAA0E;AACnI,UAAM,QAAQ,KAAK,YAAY;AAC/B,UAAM,OAAO,OAAO,OAAO,CAAC,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE;AACrD,UAAM,SAAS,OAAO,OAAO;AAC7B,WAAO,UAAU,YACb,EAAE,SAAS,MAAM,QAAQ,mBAAmB,IAAI,IAAI,OAAO,MAAM,sBAAsB,IACvF,EAAE,SAAS,OAAO,QAAQ,wBAAwB,IAAI,IAAI,OAAO,MAAM,sBAAsB;AAAA,EACnG;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/tools/capability.ts","../src/tools/http.ts"],"sourcesContent":["/**\n * Per-user capability token — the sandbox→app auth primitive behind the\n * `verifyToken` seam in {@link authenticateToolRequest}.\n *\n * An app-agent runs inside the sandbox and reaches the host app back over HTTP\n * (the app tools, the integration-invoke bridge). The route must act AS the\n * connecting user without trusting any model-supplied identity, so the turn\n * mints a short HMAC token bound to the user id and bakes it into the per-turn\n * MCP server header; the route verifies it to recover the user.\n *\n * `HMAC-SHA256(secret, \"user:<userId>\")`, base64url, with an app-chosen prefix.\n * The token encodes no scopes — the hub's policy engine authorizes per action.\n * Fail-closed: with no secret, no token is minted (the caller MUST omit the MCP\n * server rather than fake an authorized call). WebCrypto only — runs on\n * Workers, Node, and the browser with no Node `crypto` dependency.\n */\n\nexport interface CapabilityTokenOptions {\n /** Shared HMAC secret. When absent, mint returns undefined / verify returns false. */\n secret?: string\n /** Token prefix (namespaces the credential; lets verify reject foreign tokens\n * cheaply). Default `cap_`. */\n prefix?: string\n}\n\n/** Mint a capability token for `userId`, or `undefined` when no secret is\n * configured (fail-closed — the caller omits the MCP server rather than fake it). */\nexport async function createCapabilityToken(userId: string, opts: CapabilityTokenOptions): Promise<string | undefined> {\n const secret = opts.secret?.trim()\n if (!secret) return undefined\n const prefix = opts.prefix ?? 'cap_'\n return `${prefix}${await sign(userId, secret)}`\n}\n\n/** Verify a capability token against `userId`. Returns false (never throws) for\n * an unconfigured secret, a wrong prefix, a malformed token, or a mismatch. */\nexport async function verifyCapabilityToken(userId: string, token: string, opts: CapabilityTokenOptions): Promise<boolean> {\n const secret = opts.secret?.trim()\n const prefix = opts.prefix ?? 'cap_'\n if (!secret || !token.startsWith(prefix)) return false\n const expected = `${prefix}${await sign(userId, secret)}`\n return timingSafeEqual(token, expected)\n}\n\nexport interface ExpiringCapabilityTokenOptions extends CapabilityTokenOptions {\n /** Token lifetime. Expired tokens verify false regardless of signature. */\n expiresInMs: number\n /** Clock injection for tests; defaults to Date.now. */\n now?: () => number\n}\n\n/**\n * Mint an EXPIRING capability token: `<prefix><base64url(payload)>.<sig>` where\n * the payload carries `{ sub, exp, n }` (subject, epoch-ms expiry, random\n * nonce) and the signature is HMAC-SHA256 over the encoded payload. Use this\n * for user-initiated scoped channels (e.g. a per-sequence MCP endpoint) where\n * a captured token must not stay valid past its window; the bare\n * {@link createCapabilityToken} remains for turn-scoped tool bridges whose\n * mint+verify happen inside one request cycle. Fail-closed like the bare\n * variant: no secret → no token.\n */\nexport async function createExpiringCapabilityToken(subject: string, opts: ExpiringCapabilityTokenOptions): Promise<string | undefined> {\n const secret = opts.secret?.trim()\n if (!secret) return undefined\n if (!Number.isFinite(opts.expiresInMs) || opts.expiresInMs <= 0) throw new Error('expiresInMs must be a positive number')\n const prefix = opts.prefix ?? 'cap_'\n const now = opts.now ?? Date.now\n const payload = base64urlText(JSON.stringify({ sub: subject, exp: now() + opts.expiresInMs, n: crypto.randomUUID() }))\n return `${prefix}${payload}.${await signText(payload, secret)}`\n}\n\n/** Verify an expiring token against `subject`: prefix, payload integrity,\n * subject match, and expiry all checked; returns false (never throws) on any\n * failure including a malformed payload. */\nexport async function verifyExpiringCapabilityToken(subject: string, token: string, opts: CapabilityTokenOptions & { now?: () => number }): Promise<boolean> {\n const secret = opts.secret?.trim()\n const prefix = opts.prefix ?? 'cap_'\n if (!secret || !token.startsWith(prefix)) return false\n const body = token.slice(prefix.length)\n const dot = body.lastIndexOf('.')\n if (dot <= 0 || dot === body.length - 1) return false\n const payload = body.slice(0, dot)\n const sig = body.slice(dot + 1)\n if (!timingSafeEqual(sig, await signText(payload, secret))) return false\n let parsed: { sub?: unknown; exp?: unknown }\n try {\n parsed = JSON.parse(textFromBase64url(payload)) as { sub?: unknown; exp?: unknown }\n } catch {\n return false\n }\n if (parsed.sub !== subject) return false\n if (typeof parsed.exp !== 'number') return false\n const now = opts.now ?? Date.now\n return parsed.exp > now()\n}\n\nasync function sign(userId: string, secret: string): Promise<string> {\n return signText(`user:${userId}`, secret)\n}\n\nasync function signText(message: string, secret: string): Promise<string> {\n const enc = new TextEncoder()\n const key = await crypto.subtle.importKey('raw', enc.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])\n const sig = await crypto.subtle.sign('HMAC', key, enc.encode(message))\n return base64url(new Uint8Array(sig))\n}\n\nfunction base64urlText(text: string): string {\n return base64url(new TextEncoder().encode(text))\n}\n\nfunction textFromBase64url(value: string): string {\n const b64 = value.replace(/-/g, '+').replace(/_/g, '/')\n const bin = atob(b64)\n const bytes = new Uint8Array(bin.length)\n for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i)\n return new TextDecoder().decode(bytes)\n}\n\nfunction base64url(bytes: Uint8Array): string {\n let s = ''\n for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]!)\n return btoa(s).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n}\n\n/** Length-independent-leak-free compare for two same-charset strings. */\nfunction timingSafeEqual(a: string, b: string): boolean {\n if (a.length !== b.length) return false\n let diff = 0\n for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i)\n return diff === 0\n}\n","import { authenticateToolRequest, type ToolHeaderNames } from './auth'\nimport { dispatchAppTool, outcomeStatus, type DispatchOptions } from './dispatch'\nimport type { AppToolName } from './openai'\n\nexport interface HandleToolRequestOptions extends DispatchOptions {\n /** Which app tool this route serves. */\n tool: AppToolName\n /** Verify the bearer capability token belongs to the header user. */\n verifyToken: (userId: string, bearer: string) => Promise<boolean>\n headerNames?: ToolHeaderNames\n /** Optional success-message builder for a friendlier tool result. */\n message?: (result: unknown) => string\n}\n\n/**\n * Handle one app-tool HTTP request end to end — the sandbox MCP path. The\n * agent's per-turn HTTP MCP server POSTs here; this authenticates (header user\n * + capability token), reads the args (MCP-alias tolerant), dispatches to the\n * product handler, and returns a JSON Response. A product's route file becomes\n * a one-liner: `export const action = ({ request }) => handleAppToolRequest(request, cfg)`.\n */\nexport async function handleAppToolRequest(request: Request, opts: HandleToolRequestOptions): Promise<Response> {\n if (request.method !== 'POST') return Response.json({ error: 'Method not allowed' }, { status: 405 })\n\n const auth = await authenticateToolRequest(request, { verifyToken: opts.verifyToken, headerNames: opts.headerNames })\n if (!auth.ok) return auth.response\n\n let body: { args?: Record<string, unknown>; arguments?: Record<string, unknown> } & Record<string, unknown>\n try {\n body = (await request.json()) as typeof body\n } catch {\n return Response.json({ error: 'Invalid JSON' }, { status: 400 })\n }\n const args = (body.args ?? body.arguments ?? body) as Record<string, unknown>\n\n const outcome = await dispatchAppTool(opts.tool, args, auth.ctx, opts)\n if (!outcome.ok) {\n return Response.json({ error: outcome.code, message: outcome.message }, { status: outcomeStatus(outcome) })\n }\n const payload = outcome.result as Record<string, unknown>\n return Response.json({ ok: true, ...payload, ...(opts.message ? { message: opts.message(outcome.result) } : {}) })\n}\n"],"mappings":"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","names":[]}