@wordrhyme/plugin 0.1.0-alpha.5 → 0.1.0-alpha.6

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,14 +1,14 @@
1
- import { a as PluginContext, c as PluginLogger } from './types-8P7XyoyQ.js';
2
- export { A as ApiPayload, E as EAuthModel, d as EAuthProvider, e as EAuthRefreshInput, f as EAuthRefreshResult, g as EAuthStatus, h as EAuthTokenResult, i as EAuthUpsertInput, j as EAuthUse, k as HookAbortError, H as HookContext, l as HookEmitOptions, b as HookHandlerOptions, m as HookPriority, n as HookTransaction, M as MARKETPLACE_PUBLISH_AUTH_METHODS, o as MarketplaceAttestationTargetV1, p as MarketplaceExecutionErrorCode, q as MarketplaceExecutionFailureCode, r as MarketplaceOrganizationExecutionV1, s as MarketplacePlatformReadAction, t as MarketplacePublishActor, u as MarketplacePublishAuthMethod, v as MarketplacePublisherAction, w as MarketplaceRegistrySigningCapability, O as OpaquePublisherCandidateV1, x as PluginApisCapability, y as PluginArtifactCapability, z as PluginAssetCapability, B as PluginAssetCreateOptions, C as PluginAssetInfo, D as PluginAssetQuery, F as PluginAssetUpdateData, G as PluginAssetVariant, I as PluginCurrencyCapability, J as PluginEAuthCapability, K as PluginEntityExtensionCapability, L as PluginEntityExtensionFilter, N as PluginFileCapability, Q as PluginFileInfo, R as PluginFileQuery, S as PluginFileUploadInput, T as PluginHookCapability, U as PluginJobOptions, V as PluginJobStatus, W as PluginMediaCapability, P as PluginMediaInfo, X as PluginMediaQuery, Y as PluginMediaUpdateData, Z as PluginMediaUploadInput, _ as PluginMediaVariant, $ as PluginMetricsAllowedLabels, a0 as PluginMetricsCapability, a1 as PluginNotificationActor, a2 as PluginNotificationCapability, a3 as PluginNotificationChannel, a4 as PluginNotificationEvent, a5 as PluginNotificationInput, a6 as PluginNotificationResult, a7 as PluginNotificationSendParams, a8 as PluginNotificationSendResult, a9 as PluginNotificationTarget, aa as PluginNotificationTemplate, ab as PluginOrganizationProvisioningCapability, ac as PluginPaginatedResult, ad as PluginPermissionCapability, ae as PluginPermissionCheckContext, af as PluginPermissionDef, ag as PluginQueueCapability, ah as PluginScopedDb, ai as PluginSettingEntry, aj as PluginSettingOptions, ak as PluginSettingsCapability, al as PluginStorageCapability, am as PluginStorageProvider, an as PluginStorageProviderConfig, ao as PluginStorageProviderInfo, ap as PluginStorageUploadInput, aq as PluginStorageUploadResult, ar as PluginTraceCapability, as as PluginUsageCapability, at as PluginWebCapability, au as ReadonlyPluginScopedDb, av as WebPluginHead, aw as WebPluginHeadLink, ax as WebPluginRouteHandler, ay as WebPluginRouteRequest, az as WebPluginRouteResult, aA as WebPluginSiteInfo, aB as WebPluginTenantInfo, aC as WebSlotExtensionQuery, aD as WebSlotQueryResult, aE as WebSlotRemoteExtension, aF as WebSlotRenderOptions, aG as WebSlotRenderRequest, aH as WebSlotRenderResult, aI as WebSlotRenderer } from './types-8P7XyoyQ.js';
1
+ import { a as PluginContext, d as PluginLogger, W as WebPluginSiteInfo } from './types-oPAs313y.js';
2
+ export { A as ActionContractMeta, e as ActionDescriptor, f as ActionInvokeRequest, g as AgentToolDescriptor, h as AiAliasDescriptor, i as AiBudget, j as AiModelCatalog, k as AiModelHint, l as AiModelListRequest, m as AiModelOption, n as AiObjectRequest, o as AiObjectResult, p as AiObjectSchema, q as AiRuntimeHandler, r as AiRuntimeHost, s as AiRuntimeInvocation, t as AiStreamEvent, u as AiTextRequest, v as AiTextResult, w as AiUsage, x as AiUsageAuthorization, y as AiUsageObservation, z as ApiPayload, E as EAuthModel, B as EAuthProvider, C as EAuthRefreshInput, D as EAuthRefreshResult, F as EAuthStatus, G as EAuthTokenResult, I as EAuthUpsertInput, J as EAuthUse, K as HookAbortError, H as HookContext, L as HookEmitOptions, b as HookHandlerOptions, M as HookPriority, c as HookTransaction, N as MARKETPLACE_PUBLISH_AUTH_METHODS, O as MarketplaceAttestationTargetV1, Q as MarketplaceExecutionErrorCode, R as MarketplaceExecutionFailureCode, S as MarketplaceOrganizationExecutionV1, T as MarketplacePlatformReadAction, U as MarketplacePublishActor, V as MarketplacePublishAuthMethod, X as MarketplacePublisherAction, Y as MarketplaceRegistrySigningCapability, Z as OpaquePublisherCandidateV1, _ as PluginActionInvokerCapability, $ as PluginAgentCapability, a0 as PluginAiCapability, a1 as PluginAiRuntimeCapability, a2 as PluginApisCapability, a3 as PluginArtifactCapability, a4 as PluginAssetCapability, a5 as PluginAssetCreateOptions, a6 as PluginAssetInfo, a7 as PluginAssetQuery, a8 as PluginAssetUpdateData, a9 as PluginAssetVariant, aa as PluginCurrencyCapability, ab as PluginEAuthCapability, ac as PluginEntityExtensionCapability, ad as PluginEntityExtensionFilter, ae as PluginFileCapability, af as PluginFileInfo, ag as PluginFileQuery, ah as PluginFileUploadInput, ai as PluginHookCapability, aj as PluginJobOptions, ak as PluginJobStatus, al as PluginMediaCapability, P as PluginMediaInfo, am as PluginMediaQuery, an as PluginMediaUpdateData, ao as PluginMediaUploadInput, ap as PluginMediaVariant, aq as PluginMetricsAllowedLabels, ar as PluginMetricsCapability, as as PluginNotificationActor, at as PluginNotificationCapability, au as PluginNotificationChannel, av as PluginNotificationEvent, aw as PluginNotificationInput, ax as PluginNotificationResult, ay as PluginNotificationSendParams, az as PluginNotificationSendResult, aA as PluginNotificationTarget, aB as PluginNotificationTemplate, aC as PluginOrganizationProvisioningCapability, aD as PluginPaginatedResult, aE as PluginPermissionCapability, aF as PluginPermissionCheckContext, aG as PluginPermissionDef, aH as PluginQueueCapability, aI as PluginScopedDb, aJ as PluginSettingEntry, aK as PluginSettingOptions, aL as PluginSettingsCapability, aM as PluginStorageCapability, aN as PluginStorageProvider, aO as PluginStorageProviderConfig, aP as PluginStorageProviderInfo, aQ as PluginStorageUploadInput, aR as PluginStorageUploadResult, aS as PluginTraceCapability, aT as PluginUsageCapability, aU as PluginWebCapability, aV as ReadonlyPluginScopedDb, aW as WebPluginHead, aX as WebPluginHeadLink, aY as WebPluginRouteHandler, aZ as WebPluginRouteRequest, a_ as WebPluginRouteResult, a$ as WebPluginTenantInfo, b0 as WebSlotExtensionQuery, b1 as WebSlotQueryResult, b2 as WebSlotRemoteExtension, b3 as WebSlotRenderOptions, b4 as WebSlotRenderRequest, b5 as WebSlotRenderResult, b6 as WebSlotRenderer } from './types-oPAs313y.js';
3
3
  import { z } from 'zod';
4
4
  export { CurrencyInfo, DEFAULT_CURRENCY, FormatPriceOptions, GlobalizationState, I18nTextField, LanguageInfo, PriceFormatter, TextDirection, TranslationMessages, Translator, bankersRound, buildGlobalizationUrl, convertCurrency, createPriceFormatter, createTranslator, findCurrency, formatCurrencyAmount, formatPrice, fromCents, getBaseCurrency, getI18nText, getTextDirection, normalizeCurrencies, normalizeCurrencyInfo, resolveCurrencyInfo, toCents, withGlobalizationHelpers } from './globalization.js';
5
5
  export { CLIENT_TIME_ZONE_COOKIE, CLIENT_TIME_ZONE_HEADER, DEFAULT_TIME_ZONE, DateFilterInput, DateFilterRange, DateRangeResolver, FormatDateTimeOptions, canonicalizeTimeZone, formatDateTime, getClientTimeZone, getSupportedTimeZones, isValidTimeZone, normalizeTimeZone, resolveDateFilterRange, toDateTimeLocal, toUtcDateTime, toUtcDayRange } from './time.js';
6
- import { P as PluginManifest } from './manifest-CPSCN_Ft.js';
7
- export { A as AdminTour, b as AdminTourPlacement, c as AdminTourStep, d as AggregationStrategy, e as AutoCrudAction, f as AutoCrudActionZone, g as AutoCrudActions, h as EntityExtension, i as EntityExtensionCrudConfig, a as EntityExtensionField, E as EntityExtensionFieldType, j as EntityExtensionSlot, k as EntityExtensionUse, l as PluginCapabilities, m as PluginNotificationType, n as PluginStatus, W as WebDesignAction, o as WebDesignBlock, p as WebDesignDataSource, q as WebDesignSlot, r as WebDesignSurface, s as WebDesignTemplate, t as WebExtension, u as WebExtensionQuery, v as WebExtensionTarget, w as WebPluginRoute, x as WebSsrContractVersion, y as WebSurface, z as adminExtensionSchema, B as adminTourPlacementSchema, C as adminTourSchema, D as adminTourStepSchema, F as autoCrudActionSchema, G as autoCrudActionZoneSchema, H as autoCrudActionsSchema, I as autoCrudDataSourceSchema, J as autoCrudFieldConfigSchema, K as autoCrudFieldOptionSchema, L as dashboardTargetSchema, M as entityExtensionCrudConfigSchema, N as entityExtensionFieldSchema, O as entityExtensionSchema, Q as entityExtensionSlotSchema, R as entityExtensionUseSchema, S as navGroupTargetSchema, T as navTargetSchema, U as pluginI18nSchema, V as pluginManifestSchema, X as pluginUsesSchema, Y as routeTargetSchema, Z as settingsTargetSchema, _ as targetSchema, $ as webDesignActionSchema, a0 as webDesignBlockSchema, a1 as webDesignDataSourceSchema, a2 as webDesignSlotSchema, a3 as webDesignSurfaceSchema, a4 as webDesignTemplateSchema, a5 as webExtensionQuerySchema, a6 as webExtensionSchema, a7 as webExtensionTargetSchema, a8 as webPluginRouteSchema, a9 as webSsrContractVersionSchema, aa as webSurfaceSchema } from './manifest-CPSCN_Ft.js';
6
+ import { P as PluginManifest } from './manifest-zSGjFCcJ.js';
7
+ export { A as AdminTour, b as AdminTourPlacement, c as AdminTourStep, d as AggregationStrategy, e as AutoCrudAction, f as AutoCrudActionZone, g as AutoCrudActions, h as EntityExtension, i as EntityExtensionCrudConfig, a as EntityExtensionField, E as EntityExtensionFieldType, j as EntityExtensionSlot, k as EntityExtensionUse, l as PluginCapabilities, m as PluginNotificationType, n as PluginStatus, W as WebDesignAction, o as WebDesignBlock, p as WebDesignDataSource, q as WebDesignSlot, r as WebDesignSurface, s as WebDesignTemplate, t as WebExtension, u as WebExtensionQuery, v as WebExtensionTarget, w as WebPluginRoute, x as WebSsrContractVersion, y as WebSurface, z as adminExtensionSchema, B as adminTourPlacementSchema, C as adminTourSchema, D as adminTourStepSchema, F as autoCrudActionSchema, G as autoCrudActionZoneSchema, H as autoCrudActionsSchema, I as autoCrudDataSourceSchema, J as autoCrudFieldConfigSchema, K as autoCrudFieldOptionSchema, L as dashboardTargetSchema, M as entityExtensionCrudConfigSchema, N as entityExtensionFieldSchema, O as entityExtensionSchema, Q as entityExtensionSlotSchema, R as entityExtensionUseSchema, S as navGroupTargetSchema, T as navTargetSchema, U as pluginI18nSchema, V as pluginManifestSchema, X as pluginUsesSchema, Y as routeTargetSchema, Z as settingsTargetSchema, _ as targetSchema, $ as webDesignActionSchema, a0 as webDesignBlockSchema, a1 as webDesignDataSourceSchema, a2 as webDesignSlotSchema, a3 as webDesignSurfaceSchema, a4 as webDesignTemplateSchema, a5 as webExtensionQuerySchema, a6 as webExtensionSchema, a7 as webExtensionTargetSchema, a8 as webPluginRouteSchema, a9 as webSsrContractVersionSchema, aa as webSurfaceSchema } from './manifest-zSGjFCcJ.js';
8
8
  export { c as PLUGIN_ARCHIVE_MEDIA_TYPE, d as PLUGIN_RELEASE_SCHEMA_VERSION, e as PluginRegistryCatalog, f as PluginRegistryRelease, P as PluginRelease, g as PluginReleaseFile, h as PluginSignature, i as REGISTRY_CATALOG_SIGNATURE_DOMAIN, b as RegistryCatalogPageEnvelope, R as RegistryReleaseEnvelope, a as RegistrySignature, j as canonicalRegistryCatalogPageEnvelope, k as canonicalRegistryReleaseEnvelope, p as pluginArchivePathSchema, l as pluginRegistryCatalogSchema, m as pluginRegistryReleaseSchema, n as pluginReleaseFileSchema, o as pluginReleaseSchema, q as pluginSignatureSchema, r as registryCatalogPageEnvelopeSchema, s as registryCatalogPageSignaturePayload, t as registryCatalogReleasesPayload, u as registryReleaseEnvelopeSchema, v as registryReleaseSignaturePayload, w as registrySignatureSchema } from './release-CyapqJ3z.js';
9
- export { E as ENTITY_EXTENSION_VALUES_SAVE_HOOK_ID, a as EXTENSION_PROJECT_SAVE_HOOK_ID, b as EntityExtensionProjectionValue, c as EntityExtensionValueSaveHandler, d as EntityExtensionValueSavePayload, e as EntityExtensionValueSaveResult, f as entityExtensions, r as registerEntityExtensionValueSaver } from './entity-extensions-B5BbZH-m.js';
9
+ export { E as ENTITY_EXTENSION_VALUES_SAVE_HOOK_ID, a as EXTENSION_PROJECT_SAVE_HOOK_ID, b as EntityExtensionProjectionValue, c as EntityExtensionValueSaveHandler, d as EntityExtensionValueSavePayload, e as EntityExtensionValueSaveResult, f as entityExtensions, r as registerEntityExtensionValueSaver } from './entity-extensions-D09rvNgi.js';
10
10
  export { getPluginDevPort, getPluginDevRemoteEntry, getPluginMfName } from './dev-utils.js';
11
- export { D as DashboardTarget, E as ExtensionComponentMap, G as GenericTarget, N as NavGroupTarget, a as NavTarget, R as RouteTarget, S as SettingsTarget, b as SlotContext, T as Target, c as ToolbarHandlerMap, U as UIExtensionDef, d as dashboardExtension, e as defineExtension, m as multiSlotExtension, n as navExtension, r as routeExtension, s as settingsExtension } from './client-WXWbuuvd.js';
11
+ export { D as DashboardTarget, E as ExtensionComponentMap, G as GenericTarget, N as NavGroupTarget, a as NavTarget, R as RouteTarget, S as SettingsTarget, b as SlotContext, T as Target, c as ToolbarHandlerMap, U as UIExtensionDef, d as dashboardExtension, e as defineExtension, m as multiSlotExtension, n as navExtension, r as routeExtension, s as settingsExtension } from './client-BJju2aT7.js';
12
12
  import 'decimal.js';
13
13
 
14
14
  declare const MARKETPLACE_PUBLISH_SOURCES: readonly ["web", "cli", "github-actions"];
@@ -313,4 +313,343 @@ declare function requirePermission(ctx: PluginContext, capability: string): Prom
313
313
  */
314
314
  declare function hasCapability(ctx: PluginContext, capability: string): boolean;
315
315
 
316
- export { MARKETPLACE_PUBLISH_SOURCES, MARKETPLACE_SUBMISSION_STATUSES, type MarketplaceOwnedPlugin, type MarketplaceOwnedPluginInput, type MarketplaceOwnedPluginResponse, type MarketplaceOwnedPluginsResponse, type MarketplacePublishSource, type MarketplacePublisherError, type MarketplacePublisherProfile, type MarketplacePublisherProfileInput, type MarketplacePublisherProfileResponse, type MarketplaceReleaseAcceptedResponse, type MarketplaceSubmission, type MarketplaceSubmissionCursor, type MarketplaceSubmissionStatus, type MarketplaceSubmissionsResponse, PluginContext, PluginLogger, PluginManifest, checkPermission, createLogger, definePlugin, hasCapability, marketplaceOwnedPluginInputSchema, marketplaceOwnedPluginResponseSchema, marketplaceOwnedPluginSchema, marketplaceOwnedPluginsResponseSchema, marketplacePublishSourceSchema, marketplacePublisherErrorSchema, marketplacePublisherProfileInputSchema, marketplacePublisherProfileResponseSchema, marketplacePublisherProfileSchema, marketplaceReleaseAcceptedResponseSchema, marketplaceSubmissionCursorSchema, marketplaceSubmissionSchema, marketplaceSubmissionStatusSchema, marketplaceSubmissionsResponseSchema, requirePermission };
316
+ type WebUrlSearchValue = boolean | number | string | null | undefined;
317
+ type WebUrlSearchParams = URLSearchParams | Record<string, WebUrlSearchValue>;
318
+ /**
319
+ * Builds an absolute URL for a public Web route without assuming how the site
320
+ * is hosted. Custom domains and platform subdomains use an empty basePath;
321
+ * platform-path sites provide a basePath such as `/s/acme`.
322
+ */
323
+ declare function buildWebUrl(site: Pick<WebPluginSiteInfo, 'basePath' | 'publicOrigin'> | null | undefined, href: string, searchParams?: WebUrlSearchParams): string | null;
324
+
325
+ /**
326
+ * Agent tool assembly + pre-call governance (AI Action Gateway, Phase 1).
327
+ *
328
+ * Translates the governed Action Catalog into the tool shape an LLM runtime
329
+ * consumes, and enforces the rules that must hold BEFORE a model-proposed call
330
+ * reaches the invoker. Kept in the SDK so any agent-host plugin gets identical
331
+ * semantics rather than re-deriving them.
332
+ *
333
+ * Two rules carry most of the weight (plan §9):
334
+ *
335
+ * - **The model never picks a procedure path.** Tools are named after stable
336
+ * `actionId`s; the Host resolves the binding. A hallucinated tool name is a
337
+ * miss, not an arbitrary call.
338
+ * - **The model cannot talk its way past a confirmation.** Risk comes from the
339
+ * curated contract, never from tool output or model reasoning, and high-risk
340
+ * calls are refused here unless an approval token is already present.
341
+ *
342
+ * Both rules assume the tool name arrived as protocol data. `ToolChannel` is
343
+ * where that assumption is made explicit and enforced.
344
+ */
345
+ /**
346
+ * How a tool call reached us.
347
+ *
348
+ * `native` — the provider returned a structured tool call over its own protocol,
349
+ * so the tool name is a protocol fact and maps to a curated `actionId`.
350
+ *
351
+ * `text-recovered` — the call was parsed out of the model's prose, the way
352
+ * text-mode runtimes recover DeepSeek DSML markup and similar. There the tool
353
+ * name *is* model-authored free text, which collapses the boundary the two rules
354
+ * above rest on: prose becomes the source of the action to run. Such a channel
355
+ * therefore carries `query` actions only — a channel that cannot be trusted to
356
+ * name an action cannot be trusted to change data.
357
+ */
358
+ type ToolChannel = "native" | "text-recovered";
359
+ /** Minimal shape of a catalog entry; mirrors ActionDescriptor without importing it. */
360
+ interface AgentToolSource {
361
+ actionId: string;
362
+ revision: number;
363
+ kind: "query" | "command";
364
+ risk: "low" | "medium" | "high";
365
+ summary?: string | undefined;
366
+ }
367
+ /** JSON-Schema-shaped tool definition, the lingua franca of tool-calling APIs. */
368
+ interface AgentToolDefinition {
369
+ name: string;
370
+ description: string;
371
+ inputSchema: {
372
+ type: "object";
373
+ properties: Record<string, unknown>;
374
+ required?: string[];
375
+ additionalProperties: boolean;
376
+ };
377
+ /** Curated metadata; NOT model-supplied and NOT to be trusted from tool output. */
378
+ metadata: {
379
+ actionId: string;
380
+ revision: number;
381
+ kind: "query" | "command";
382
+ risk: "low" | "medium" | "high";
383
+ requiresApproval: boolean;
384
+ };
385
+ }
386
+ interface AssembleOptions {
387
+ /** Argument schemas by actionId, when the host can supply them. */
388
+ argumentSchemas?: Record<string, {
389
+ properties: Record<string, unknown>;
390
+ required?: string[];
391
+ }>;
392
+ /** Drop actions above this risk level from what the model can even see. */
393
+ maxRisk?: "low" | "medium" | "high";
394
+ /**
395
+ * The channel these tools will be offered on. A `text-recovered` channel is
396
+ * assembled without commands, so the model is never shown a write the gate
397
+ * would refuse anyway. Defaults to `native`: this is a pure helper, and the
398
+ * callers that hold a real channel (`runAgent`, the host endpoints) are the
399
+ * ones that treat an undeclared channel as untrusted.
400
+ */
401
+ channel?: ToolChannel;
402
+ }
403
+ /** Tool names must survive provider naming rules (letters, digits, _, -). */
404
+ declare function toolNameFor(actionId: string): string;
405
+ declare function requiresApprovalFor(risk: AgentToolSource["risk"]): boolean;
406
+ /**
407
+ * Build the tool list exposed to a model.
408
+ *
409
+ * Descriptions state the governance consequence explicitly: models behave better
410
+ * when told a call will pause for a human than when silently refused later.
411
+ */
412
+ declare function assembleTools(sources: readonly AgentToolSource[], options?: AssembleOptions): AgentToolDefinition[];
413
+ type ToolCallDecision = {
414
+ allow: true;
415
+ actionId: string;
416
+ revision: number;
417
+ } | {
418
+ allow: false;
419
+ reason: ToolCallRefusal;
420
+ message: string;
421
+ };
422
+ type ToolCallRefusal = "UNKNOWN_TOOL" | "APPROVAL_REQUIRED" | "BUDGET_EXHAUSTED" | "TENANT_PAUSED" | "CHANNEL_READ_ONLY";
423
+ interface ToolCallGateInput {
424
+ toolName: string;
425
+ tools: readonly AgentToolDefinition[];
426
+ /** Present when the caller already holds a human approval for this call. */
427
+ approvalToken?: string | undefined;
428
+ /** Remaining tool calls in this run; `undefined` means unbounded. */
429
+ remainingCalls?: number | undefined;
430
+ /** Tenant-level kill switch for AI writes (plan §9 resource exhaustion). */
431
+ writesPaused?: boolean;
432
+ /** How this call reached us; a `text-recovered` channel carries reads only. */
433
+ channel?: ToolChannel;
434
+ }
435
+ /**
436
+ * Decide whether a model-proposed tool call may proceed.
437
+ *
438
+ * Runs before the invoker so refusals cost nothing and can be fed back to the
439
+ * model as a normal tool result — a refused call should steer the model, not
440
+ * crash the run.
441
+ */
442
+ declare function gateToolCall(input: ToolCallGateInput): ToolCallDecision;
443
+ /**
444
+ * Wrap a tool result before it re-enters the model context.
445
+ *
446
+ * Tool output is untrusted input (plan §9 malicious tool output): it is fenced
447
+ * and labelled so the model cannot pass it off as an instruction, and it can
448
+ * never carry governance metadata of its own.
449
+ */
450
+ declare function encodeToolResult(actionId: string, result: unknown): string;
451
+
452
+ /**
453
+ * Governed agent run loop (AI Action Gateway, Phase 1).
454
+ *
455
+ * The multi-turn loop that sits between a model and the governed action
456
+ * surface. It is deliberately **model-agnostic**: the LLM is reached through a
457
+ * narrow `ModelClient` seam, so the chosen runtime (Pi — see
458
+ * `docs/architecture/adr/2026-07-27-agent-runtime-pi.md`) is one implementation
459
+ * rather than a structural dependency, and the whole governance path is
460
+ * testable without a network or API key.
461
+ *
462
+ * What the loop guarantees, regardless of what the model does:
463
+ *
464
+ * - **Budgets are hard.** Turn and tool-call ceilings are enforced by the loop,
465
+ * not requested of the model. A runaway loop stops.
466
+ * - **Refusals steer, they don't crash.** A gated call returns a tool result
467
+ * explaining why, so the model can adapt; only infrastructure faults throw.
468
+ * - **Tool output is data.** Results are fenced and labelled before re-entering
469
+ * the context, and can never redirect which action runs next — the actionId
470
+ * always comes from the curated catalog via the tool name.
471
+ * - **Prose cannot become a command.** That last guarantee holds only while the
472
+ * tool name is protocol data, so a client that recovers calls from model text
473
+ * (`channel: 'text-recovered'`) is confined to read-only actions.
474
+ * - **High-risk work pauses.** A call needing approval suspends the run with
475
+ * everything the caller needs to raise a confirmation, instead of guessing.
476
+ */
477
+
478
+ interface ModelToolCall {
479
+ id: string;
480
+ /** Tool name as emitted by the model; resolved against the catalog, never trusted as a path. */
481
+ name: string;
482
+ arguments?: unknown;
483
+ }
484
+ interface ModelMessage {
485
+ role: "system" | "user" | "assistant" | "tool";
486
+ content: string;
487
+ toolCalls?: ModelToolCall[];
488
+ toolCallId?: string;
489
+ }
490
+ interface ModelResponse {
491
+ text?: string;
492
+ toolCalls?: ModelToolCall[];
493
+ usage?: {
494
+ inputTokens?: number;
495
+ outputTokens?: number;
496
+ costUsd?: number;
497
+ };
498
+ }
499
+ interface ModelClient {
500
+ /**
501
+ * How this client surfaces tool calls. An adapter that parses them out of the
502
+ * model's prose rather than reading them off the wire MUST declare
503
+ * `text-recovered`; the loop then withholds every command action.
504
+ *
505
+ * Required so the choice is made by whoever writes the adapter, who is the
506
+ * only one who knows. An absent value is treated as `text-recovered` — the
507
+ * restrictive reading — because reaching that line means the declaration was
508
+ * bypassed rather than considered.
509
+ */
510
+ readonly channel: ToolChannel;
511
+ complete(input: {
512
+ messages: ModelMessage[];
513
+ tools: AgentToolDefinition[];
514
+ signal?: AbortSignal;
515
+ }): Promise<ModelResponse>;
516
+ }
517
+ /** Executes an accepted call. Implemented by the host over `ctx.actions.invoke`. */
518
+ type ActionExecutor = (call: {
519
+ actionId: string;
520
+ revision: number;
521
+ args: unknown;
522
+ }) => Promise<unknown>;
523
+ type AgentRunEvent = {
524
+ type: "turn.started";
525
+ turn: number;
526
+ } | {
527
+ type: "message.completed";
528
+ text: string;
529
+ } | {
530
+ type: "tool.started";
531
+ toolName: string;
532
+ actionId: string;
533
+ } | {
534
+ type: "tool.completed";
535
+ actionId: string;
536
+ } | {
537
+ type: "tool.refused";
538
+ toolName: string;
539
+ reason: ToolCallRefusal;
540
+ } | {
541
+ type: "tool.approval_required";
542
+ toolName: string;
543
+ actionId: string;
544
+ args: unknown;
545
+ } | {
546
+ type: "run.completed";
547
+ reason: RunStopReason;
548
+ } | {
549
+ type: "run.failed";
550
+ error: string;
551
+ };
552
+ type RunStopReason = "completed" | "turn_budget" | "tool_budget" | "approval_required" | "aborted";
553
+ interface AgentRunOptions {
554
+ model: ModelClient;
555
+ tools: AgentToolDefinition[];
556
+ execute: ActionExecutor;
557
+ messages: ModelMessage[];
558
+ maxTurns?: number;
559
+ maxToolCalls?: number;
560
+ /** Tenant kill switch for AI writes; reads continue. */
561
+ writesPaused?: boolean;
562
+ /** Approval tokens already held, keyed by actionId. */
563
+ approvals?: Record<string, string>;
564
+ onEvent?: (event: AgentRunEvent) => void;
565
+ signal?: AbortSignal;
566
+ }
567
+ interface AgentRunResult {
568
+ stopReason: RunStopReason;
569
+ messages: ModelMessage[];
570
+ text: string;
571
+ toolCallsUsed: number;
572
+ turnsUsed: number;
573
+ usage: {
574
+ inputTokens: number;
575
+ outputTokens: number;
576
+ costUsd: number;
577
+ };
578
+ /** Set when `stopReason === 'approval_required'`. */
579
+ pendingApproval?: {
580
+ toolName: string;
581
+ actionId: string;
582
+ revision: number;
583
+ args: unknown;
584
+ };
585
+ }
586
+ declare function runAgent(options: AgentRunOptions): Promise<AgentRunResult>;
587
+
588
+ /**
589
+ * WordRhyme Connector — one codebase, two transports (AI Action Gateway, Phase 0 segment 3).
590
+ *
591
+ * `local` — invokes governed actions in-process through `ctx.actions`
592
+ * (ActionInvokerCapability); identity comes from the live request.
593
+ * `remote` — invokes the SAME action surface on ANOTHER WordRhyme instance over
594
+ * HTTP `POST {baseUrl}/trpc/<path>` with `x-api-key`.
595
+ *
596
+ * Both transports share the `invoke(actionId, revision, args)` shape, so callers
597
+ * cannot tell them apart — that is the point of the segment-3 spike.
598
+ *
599
+ * Security posture (all fail closed):
600
+ * - remote base URLs must be explicitly allowlisted; private/loopback hosts are
601
+ * rejected unless the allowlist entry itself is loopback (dev/tests)
602
+ * - redirects are never followed (`redirect: 'error'`) — no redirect-to-private-net
603
+ * - the remote instance pins the organization to its API token; this client
604
+ * therefore never sends an organizationId, and refuses to accept one
605
+ * - `onBehalfOf` is delegation CONTEXT FOR AUDIT ONLY, never a permission source;
606
+ * the remote side authorizes as the token's own principal
607
+ */
608
+ /** Actions surface the local transport delegates to (subset of PluginActionInvokerCapability). */
609
+ interface ConnectorLocalActions {
610
+ invoke(request: {
611
+ actionId: string;
612
+ revision: number;
613
+ args?: unknown;
614
+ }): Promise<unknown>;
615
+ }
616
+ interface ConnectorInvokeRequest {
617
+ actionId: string;
618
+ revision: number;
619
+ args?: unknown;
620
+ /** Audit-only delegation context. Never widens permissions on either side. */
621
+ onBehalfOf?: string;
622
+ }
623
+ interface WordRhymeConnector {
624
+ readonly transport: "local" | "remote";
625
+ invoke(request: ConnectorInvokeRequest): Promise<unknown>;
626
+ }
627
+ interface LocalConnectorOptions {
628
+ transport: "local";
629
+ actions: ConnectorLocalActions;
630
+ }
631
+ interface RemoteConnectorOptions {
632
+ transport: "remote";
633
+ baseUrl: string;
634
+ apiKey: string;
635
+ /** Exact origins this connector may call. Empty ⇒ nothing is allowed. */
636
+ allowedOrigins: string[];
637
+ /** Action ids this connector may invoke remotely. Empty ⇒ nothing is allowed. */
638
+ allowedActions: string[];
639
+ /** Injected for tests; defaults to global fetch. */
640
+ fetchImpl?: typeof fetch;
641
+ }
642
+ type ConnectorOptions = LocalConnectorOptions | RemoteConnectorOptions;
643
+ declare class ConnectorError extends Error {
644
+ readonly code: string;
645
+ constructor(code: string, message: string);
646
+ }
647
+ /**
648
+ * Resolve a remote base URL against the allowlist.
649
+ * Private/loopback targets are only permitted when explicitly allowlisted,
650
+ * which keeps dev and tests usable without opening SSRF in production configs.
651
+ */
652
+ declare function resolveRemoteOrigin(baseUrl: string, allowedOrigins: string[]): string;
653
+ declare function createWordRhymeConnector(options: ConnectorOptions): WordRhymeConnector;
654
+
655
+ export { type ActionExecutor, type AgentRunEvent, type AgentRunOptions, type AgentRunResult, type AgentToolDefinition, type AgentToolSource, type AssembleOptions, ConnectorError, type ConnectorInvokeRequest, type ConnectorLocalActions, type ConnectorOptions, type LocalConnectorOptions, MARKETPLACE_PUBLISH_SOURCES, MARKETPLACE_SUBMISSION_STATUSES, type MarketplaceOwnedPlugin, type MarketplaceOwnedPluginInput, type MarketplaceOwnedPluginResponse, type MarketplaceOwnedPluginsResponse, type MarketplacePublishSource, type MarketplacePublisherError, type MarketplacePublisherProfile, type MarketplacePublisherProfileInput, type MarketplacePublisherProfileResponse, type MarketplaceReleaseAcceptedResponse, type MarketplaceSubmission, type MarketplaceSubmissionCursor, type MarketplaceSubmissionStatus, type MarketplaceSubmissionsResponse, type ModelClient, type ModelMessage, type ModelResponse, type ModelToolCall, PluginContext, PluginLogger, PluginManifest, type RemoteConnectorOptions, type RunStopReason, type ToolCallDecision, type ToolCallGateInput, type ToolCallRefusal, type ToolChannel, WebPluginSiteInfo, type WebUrlSearchParams, type WebUrlSearchValue, type WordRhymeConnector, assembleTools, buildWebUrl, checkPermission, createLogger, createWordRhymeConnector, definePlugin, encodeToolResult, gateToolCall, hasCapability, marketplaceOwnedPluginInputSchema, marketplaceOwnedPluginResponseSchema, marketplaceOwnedPluginSchema, marketplaceOwnedPluginsResponseSchema, marketplacePublishSourceSchema, marketplacePublisherErrorSchema, marketplacePublisherProfileInputSchema, marketplacePublisherProfileResponseSchema, marketplacePublisherProfileSchema, marketplaceReleaseAcceptedResponseSchema, marketplaceSubmissionCursorSchema, marketplaceSubmissionSchema, marketplaceSubmissionStatusSchema, marketplaceSubmissionsResponseSchema, requirePermission, requiresApprovalFor, resolveRemoteOrigin, runAgent, toolNameFor };