@theokit/sdk 2.4.0 → 2.5.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.cts CHANGED
@@ -1428,8 +1428,9 @@ declare function migrateSqliteToLance(options: MigrateOptions): Promise<MigrateR
1428
1428
  /**
1429
1429
  * `PermissionEngine` — first-match permission rules for tool invocations.
1430
1430
  *
1431
- * Evaluates a tool name against an ordered list of rules.
1432
- * First matching rule wins; default is "allow" when no rule matches.
1431
+ * Evaluates a tool name against an ordered list of rules. First matching rule
1432
+ * wins; when no rule matches the `defaultAction` is returned (M7-4 default
1433
+ * `"allow"`, opt into default-deny via `{ defaultAction: "deny" }`).
1433
1434
  */
1434
1435
  type PermissionAction = "allow" | "deny" | "ask";
1435
1436
  interface PermissionRule {
@@ -1438,15 +1439,49 @@ interface PermissionRule {
1438
1439
  /** Action to take when rule matches. */
1439
1440
  action: PermissionAction;
1440
1441
  }
1442
+ /** Options for {@link PermissionEngine}. */
1443
+ interface PermissionEngineOptions {
1444
+ /** Action when no rule matches. Default `"allow"` (backward-compatible). M7-4. */
1445
+ readonly defaultAction?: PermissionAction;
1446
+ }
1441
1447
  declare class PermissionEngine {
1442
1448
  private readonly rules;
1443
- constructor(rules: PermissionRule[]);
1449
+ private readonly defaultAction;
1450
+ constructor(rules: PermissionRule[], options?: PermissionEngineOptions);
1444
1451
  /**
1445
- * Evaluate a tool name against the rules. First match wins; default "allow".
1452
+ * Evaluate a tool name against the rules. First match wins; falls back to the
1453
+ * configured `defaultAction` (default `"allow"`) when no rule matches.
1446
1454
  */
1447
1455
  evaluate(toolName: string): PermissionAction;
1448
1456
  }
1449
1457
 
1458
+ /**
1459
+ * M7-5 — `createPermissionPlugin`: wire a {@link PermissionEngine} into the
1460
+ * `definePlugin` `pre_tool_call` veto seam. This is the canonical exemplar that
1461
+ * gives `PermissionEngine` a real caller (it was previously exported-but-unwired):
1462
+ * on each tool call the engine's verdict maps to the veto contract —
1463
+ * `"deny"` -> block, `"ask"` -> the caller's `onAsk` resolver (or block, fail-closed),
1464
+ * `"allow"` -> pass.
1465
+ *
1466
+ * @public
1467
+ */
1468
+
1469
+ /** Options for {@link createPermissionPlugin}. */
1470
+ interface PermissionPluginOptions {
1471
+ /** Plugin name (default `"permission-engine"`). */
1472
+ readonly name?: string;
1473
+ /**
1474
+ * Resolver for the `"ask"` verdict. Returns a veto (`{block,message}`) to deny
1475
+ * or `undefined` to allow. Default: fail-closed (block with "requires approval").
1476
+ */
1477
+ readonly onAsk?: (toolName: string) => PreToolCallDecision | undefined;
1478
+ }
1479
+ /**
1480
+ * Build a `general` plugin that vetoes tool calls per the engine's verdict.
1481
+ * Register it on an agent's plugin manager (same as the ACP permission plugin).
1482
+ */
1483
+ declare function createPermissionPlugin(engine: PermissionEngine, opts?: PermissionPluginOptions): Plugin;
1484
+
1450
1485
  /**
1451
1486
  * Public security namespace (T2.1, ADR D68).
1452
1487
  *
@@ -2151,4 +2186,4 @@ declare function toShareGptTrajectory(result: BatchResult, options?: {
2151
2186
  model?: string;
2152
2187
  }): ShareGptTrajectory | null;
2153
2188
 
2154
- export { Agent, AgentBuilder, AgentDefinition, type AgentFactory, AgentOperationOptions, AgentOptions, type AgentPromptResult, type AgentRegistryOptions, type BatchItem, type BatchOptions, type BatchProgress, type BatchResult, Budget, BudgetHandle, BudgetOptions, BudgetSnapshot, BudgetTracker, CloudOptions, ContextSettings, ConversationStorageAdapter, type CounterBudgetTrackerOptions, CustomTool, type DeepPartial, type DefineProviderOptions, type DefineToolSpec, type DreamingSweepOptions, type DreamingSweepResult, EventBus, type EvictReason, FileSystemConversationStorage, GenerateObjectError, type GenerateObjectOptions, type GenerateObjectResult, GetAgentOptions, GetRunOptions, type HookName, InMemoryConversationStorage, JobQueue, ListAgentsOptions, ListResult, ListRunsOptions, LiveAgentRegistry, LocalOptions, McpServerConfig, Memory, MemoryContext, MemoryId, MemoryProvider, MemorySettings, type MigrateOptions, type MigrateResult, type ModelListItem, type ModelParameterDefinition, ModelSelection, type ModelVariant, PermissionEngine, type Plugin, type PluginContext, PluginsSettings, type PostAssistantReplyContext, type PreToolCallContext, type PreToolCallDecision, type PreUserSendContext, type PreUserSendResult, type ProviderProfile, ProviderRoutingSettings, type ReplayHistoryOptions, Run, RunResult, SDKAgent, SDKAgentInfo, SDKMessage, type SDKModel, SDKProvider, type SDKRepository, type SDKUser, Security, type ShareGptMessage, type ShareGptTrajectory, SkillsSettings, type Squad, type SquadOptions, type SquadRun, StoredMessage, StreamObjectError, type StreamObjectEvent, type StreamObjectOptions, SystemPromptResolver, TASK_RESERVED_PREFIXES, Task, type TaskCancelResult, type TaskConfigureOptions, type TaskEvent, type TaskFilter, type TaskHandle, type TaskKind, type TaskState, type TaskStoreOptions, type TaskSubmitOptions, type TaskWorkContext, type TaskWorkFn, Theokit, TheokitAgentError, type TheokitRequestOptions, UsageAccumulator, buildReplayHistory, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createSquad, definePlugin, defineProvider, defineTool, extractRawId, getPricingEntry, inferApiMode, isValidTaskId, migrateSqliteToLance, mkMemoryId, normalizeUsage, preflightCheck, toShareGptTrajectory, withCwdMutex };
2189
+ export { Agent, AgentBuilder, AgentDefinition, type AgentFactory, AgentOperationOptions, AgentOptions, type AgentPromptResult, type AgentRegistryOptions, type BatchItem, type BatchOptions, type BatchProgress, type BatchResult, Budget, BudgetHandle, BudgetOptions, BudgetSnapshot, BudgetTracker, CloudOptions, ContextSettings, ConversationStorageAdapter, type CounterBudgetTrackerOptions, CustomTool, type DeepPartial, type DefineProviderOptions, type DefineToolSpec, type DreamingSweepOptions, type DreamingSweepResult, EventBus, type EvictReason, FileSystemConversationStorage, GenerateObjectError, type GenerateObjectOptions, type GenerateObjectResult, GetAgentOptions, GetRunOptions, type HookName, InMemoryConversationStorage, JobQueue, ListAgentsOptions, ListResult, ListRunsOptions, LiveAgentRegistry, LocalOptions, McpServerConfig, Memory, MemoryContext, MemoryId, MemoryProvider, MemorySettings, type MigrateOptions, type MigrateResult, type ModelListItem, type ModelParameterDefinition, ModelSelection, type ModelVariant, type PermissionAction, PermissionEngine, type PermissionEngineOptions, type PermissionPluginOptions, type PermissionRule, type Plugin, type PluginContext, PluginsSettings, type PostAssistantReplyContext, type PreToolCallContext, type PreToolCallDecision, type PreUserSendContext, type PreUserSendResult, type ProviderProfile, ProviderRoutingSettings, type ReplayHistoryOptions, Run, RunResult, SDKAgent, SDKAgentInfo, SDKMessage, type SDKModel, SDKProvider, type SDKRepository, type SDKUser, Security, type ShareGptMessage, type ShareGptTrajectory, SkillsSettings, type Squad, type SquadOptions, type SquadRun, StoredMessage, StreamObjectError, type StreamObjectEvent, type StreamObjectOptions, SystemPromptResolver, TASK_RESERVED_PREFIXES, Task, type TaskCancelResult, type TaskConfigureOptions, type TaskEvent, type TaskFilter, type TaskHandle, type TaskKind, type TaskState, type TaskStoreOptions, type TaskSubmitOptions, type TaskWorkContext, type TaskWorkFn, Theokit, TheokitAgentError, type TheokitRequestOptions, UsageAccumulator, buildReplayHistory, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createPermissionPlugin, createSquad, definePlugin, defineProvider, defineTool, extractRawId, getPricingEntry, inferApiMode, isValidTaskId, migrateSqliteToLance, mkMemoryId, normalizeUsage, preflightCheck, toShareGptTrajectory, withCwdMutex };
package/dist/index.d.ts CHANGED
@@ -1428,8 +1428,9 @@ declare function migrateSqliteToLance(options: MigrateOptions): Promise<MigrateR
1428
1428
  /**
1429
1429
  * `PermissionEngine` — first-match permission rules for tool invocations.
1430
1430
  *
1431
- * Evaluates a tool name against an ordered list of rules.
1432
- * First matching rule wins; default is "allow" when no rule matches.
1431
+ * Evaluates a tool name against an ordered list of rules. First matching rule
1432
+ * wins; when no rule matches the `defaultAction` is returned (M7-4 default
1433
+ * `"allow"`, opt into default-deny via `{ defaultAction: "deny" }`).
1433
1434
  */
1434
1435
  type PermissionAction = "allow" | "deny" | "ask";
1435
1436
  interface PermissionRule {
@@ -1438,15 +1439,49 @@ interface PermissionRule {
1438
1439
  /** Action to take when rule matches. */
1439
1440
  action: PermissionAction;
1440
1441
  }
1442
+ /** Options for {@link PermissionEngine}. */
1443
+ interface PermissionEngineOptions {
1444
+ /** Action when no rule matches. Default `"allow"` (backward-compatible). M7-4. */
1445
+ readonly defaultAction?: PermissionAction;
1446
+ }
1441
1447
  declare class PermissionEngine {
1442
1448
  private readonly rules;
1443
- constructor(rules: PermissionRule[]);
1449
+ private readonly defaultAction;
1450
+ constructor(rules: PermissionRule[], options?: PermissionEngineOptions);
1444
1451
  /**
1445
- * Evaluate a tool name against the rules. First match wins; default "allow".
1452
+ * Evaluate a tool name against the rules. First match wins; falls back to the
1453
+ * configured `defaultAction` (default `"allow"`) when no rule matches.
1446
1454
  */
1447
1455
  evaluate(toolName: string): PermissionAction;
1448
1456
  }
1449
1457
 
1458
+ /**
1459
+ * M7-5 — `createPermissionPlugin`: wire a {@link PermissionEngine} into the
1460
+ * `definePlugin` `pre_tool_call` veto seam. This is the canonical exemplar that
1461
+ * gives `PermissionEngine` a real caller (it was previously exported-but-unwired):
1462
+ * on each tool call the engine's verdict maps to the veto contract —
1463
+ * `"deny"` -> block, `"ask"` -> the caller's `onAsk` resolver (or block, fail-closed),
1464
+ * `"allow"` -> pass.
1465
+ *
1466
+ * @public
1467
+ */
1468
+
1469
+ /** Options for {@link createPermissionPlugin}. */
1470
+ interface PermissionPluginOptions {
1471
+ /** Plugin name (default `"permission-engine"`). */
1472
+ readonly name?: string;
1473
+ /**
1474
+ * Resolver for the `"ask"` verdict. Returns a veto (`{block,message}`) to deny
1475
+ * or `undefined` to allow. Default: fail-closed (block with "requires approval").
1476
+ */
1477
+ readonly onAsk?: (toolName: string) => PreToolCallDecision | undefined;
1478
+ }
1479
+ /**
1480
+ * Build a `general` plugin that vetoes tool calls per the engine's verdict.
1481
+ * Register it on an agent's plugin manager (same as the ACP permission plugin).
1482
+ */
1483
+ declare function createPermissionPlugin(engine: PermissionEngine, opts?: PermissionPluginOptions): Plugin;
1484
+
1450
1485
  /**
1451
1486
  * Public security namespace (T2.1, ADR D68).
1452
1487
  *
@@ -2151,4 +2186,4 @@ declare function toShareGptTrajectory(result: BatchResult, options?: {
2151
2186
  model?: string;
2152
2187
  }): ShareGptTrajectory | null;
2153
2188
 
2154
- export { Agent, AgentBuilder, AgentDefinition, type AgentFactory, AgentOperationOptions, AgentOptions, type AgentPromptResult, type AgentRegistryOptions, type BatchItem, type BatchOptions, type BatchProgress, type BatchResult, Budget, BudgetHandle, BudgetOptions, BudgetSnapshot, BudgetTracker, CloudOptions, ContextSettings, ConversationStorageAdapter, type CounterBudgetTrackerOptions, CustomTool, type DeepPartial, type DefineProviderOptions, type DefineToolSpec, type DreamingSweepOptions, type DreamingSweepResult, EventBus, type EvictReason, FileSystemConversationStorage, GenerateObjectError, type GenerateObjectOptions, type GenerateObjectResult, GetAgentOptions, GetRunOptions, type HookName, InMemoryConversationStorage, JobQueue, ListAgentsOptions, ListResult, ListRunsOptions, LiveAgentRegistry, LocalOptions, McpServerConfig, Memory, MemoryContext, MemoryId, MemoryProvider, MemorySettings, type MigrateOptions, type MigrateResult, type ModelListItem, type ModelParameterDefinition, ModelSelection, type ModelVariant, PermissionEngine, type Plugin, type PluginContext, PluginsSettings, type PostAssistantReplyContext, type PreToolCallContext, type PreToolCallDecision, type PreUserSendContext, type PreUserSendResult, type ProviderProfile, ProviderRoutingSettings, type ReplayHistoryOptions, Run, RunResult, SDKAgent, SDKAgentInfo, SDKMessage, type SDKModel, SDKProvider, type SDKRepository, type SDKUser, Security, type ShareGptMessage, type ShareGptTrajectory, SkillsSettings, type Squad, type SquadOptions, type SquadRun, StoredMessage, StreamObjectError, type StreamObjectEvent, type StreamObjectOptions, SystemPromptResolver, TASK_RESERVED_PREFIXES, Task, type TaskCancelResult, type TaskConfigureOptions, type TaskEvent, type TaskFilter, type TaskHandle, type TaskKind, type TaskState, type TaskStoreOptions, type TaskSubmitOptions, type TaskWorkContext, type TaskWorkFn, Theokit, TheokitAgentError, type TheokitRequestOptions, UsageAccumulator, buildReplayHistory, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createSquad, definePlugin, defineProvider, defineTool, extractRawId, getPricingEntry, inferApiMode, isValidTaskId, migrateSqliteToLance, mkMemoryId, normalizeUsage, preflightCheck, toShareGptTrajectory, withCwdMutex };
2189
+ export { Agent, AgentBuilder, AgentDefinition, type AgentFactory, AgentOperationOptions, AgentOptions, type AgentPromptResult, type AgentRegistryOptions, type BatchItem, type BatchOptions, type BatchProgress, type BatchResult, Budget, BudgetHandle, BudgetOptions, BudgetSnapshot, BudgetTracker, CloudOptions, ContextSettings, ConversationStorageAdapter, type CounterBudgetTrackerOptions, CustomTool, type DeepPartial, type DefineProviderOptions, type DefineToolSpec, type DreamingSweepOptions, type DreamingSweepResult, EventBus, type EvictReason, FileSystemConversationStorage, GenerateObjectError, type GenerateObjectOptions, type GenerateObjectResult, GetAgentOptions, GetRunOptions, type HookName, InMemoryConversationStorage, JobQueue, ListAgentsOptions, ListResult, ListRunsOptions, LiveAgentRegistry, LocalOptions, McpServerConfig, Memory, MemoryContext, MemoryId, MemoryProvider, MemorySettings, type MigrateOptions, type MigrateResult, type ModelListItem, type ModelParameterDefinition, ModelSelection, type ModelVariant, type PermissionAction, PermissionEngine, type PermissionEngineOptions, type PermissionPluginOptions, type PermissionRule, type Plugin, type PluginContext, PluginsSettings, type PostAssistantReplyContext, type PreToolCallContext, type PreToolCallDecision, type PreUserSendContext, type PreUserSendResult, type ProviderProfile, ProviderRoutingSettings, type ReplayHistoryOptions, Run, RunResult, SDKAgent, SDKAgentInfo, SDKMessage, type SDKModel, SDKProvider, type SDKRepository, type SDKUser, Security, type ShareGptMessage, type ShareGptTrajectory, SkillsSettings, type Squad, type SquadOptions, type SquadRun, StoredMessage, StreamObjectError, type StreamObjectEvent, type StreamObjectOptions, SystemPromptResolver, TASK_RESERVED_PREFIXES, Task, type TaskCancelResult, type TaskConfigureOptions, type TaskEvent, type TaskFilter, type TaskHandle, type TaskKind, type TaskState, type TaskStoreOptions, type TaskSubmitOptions, type TaskWorkContext, type TaskWorkFn, Theokit, TheokitAgentError, type TheokitRequestOptions, UsageAccumulator, buildReplayHistory, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createPermissionPlugin, createSquad, definePlugin, defineProvider, defineTool, extractRawId, getPricingEntry, inferApiMode, isValidTaskId, migrateSqliteToLance, mkMemoryId, normalizeUsage, preflightCheck, toShareGptTrajectory, withCwdMutex };
package/dist/index.js CHANGED
@@ -18712,25 +18712,47 @@ async function migrateSqliteToLance2(options) {
18712
18712
 
18713
18713
  // src/permission-engine.ts
18714
18714
  var PermissionEngine = class {
18715
- constructor(rules) {
18715
+ constructor(rules, options = {}) {
18716
18716
  this.rules = rules;
18717
+ this.defaultAction = options.defaultAction ?? "allow";
18717
18718
  }
18718
18719
  rules;
18720
+ defaultAction;
18719
18721
  /**
18720
- * Evaluate a tool name against the rules. First match wins; default "allow".
18722
+ * Evaluate a tool name against the rules. First match wins; falls back to the
18723
+ * configured `defaultAction` (default `"allow"`) when no rule matches.
18721
18724
  */
18722
18725
  evaluate(toolName) {
18723
18726
  for (const rule of this.rules) {
18724
- if (typeof rule.tool === "string") {
18725
- if (rule.tool === toolName) return rule.action;
18726
- } else {
18727
- if (rule.tool.test(toolName)) return rule.action;
18728
- }
18727
+ const matches = typeof rule.tool === "string" ? rule.tool === toolName : rule.tool.test(toolName);
18728
+ if (matches) return rule.action;
18729
18729
  }
18730
- return "allow";
18730
+ return this.defaultAction;
18731
18731
  }
18732
18732
  };
18733
18733
 
18734
+ // src/permission-plugin.ts
18735
+ function createPermissionPlugin(engine, opts = {}) {
18736
+ return definePlugin({
18737
+ name: opts.name ?? "permission-engine",
18738
+ version: "1.0.0",
18739
+ kind: "general",
18740
+ register(ctx) {
18741
+ ctx.on("pre_tool_call", (rawCtx) => {
18742
+ const { name } = rawCtx;
18743
+ const action = engine.evaluate(name);
18744
+ if (action === "deny") {
18745
+ return { block: true, message: `denied by permission engine: ${name}` };
18746
+ }
18747
+ if (action === "ask") {
18748
+ return opts.onAsk ? opts.onAsk(name) : { block: true, message: `requires approval: ${name}` };
18749
+ }
18750
+ return void 0;
18751
+ });
18752
+ }
18753
+ });
18754
+ }
18755
+
18734
18756
  // src/security.ts
18735
18757
  init_security();
18736
18758
  var Security = class {
@@ -19500,6 +19522,6 @@ function safeStringify2(v) {
19500
19522
  }
19501
19523
  }
19502
19524
 
19503
- export { Agent, AgentBuilder, AgentDisposedError, AgentRunError, AuthenticationError, Budget, BudgetExceededError, ConfigurationError, Cron, EventBus, FileSystemConversationStorage, GenerateObjectError, InMemoryConversationStorage, IntegrationNotConnectedError, InvalidTaskIdError, JobQueue, Memory, MemoryAdapterError, NetworkError, PermissionEngine, RateLimitError, Security, StreamObjectError, Task, TaskNotFoundError, Theokit, TheokitAgentError, UnknownAgentError, UnsupportedBudgetOperationError, UnsupportedRunOperationError, UnsupportedTaskOperationError, UsageAccumulator, buildReplayHistory, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createSquad, definePlugin, defineProvider, defineTool, extractRawId, getPricingEntry, inferApiMode, isTransientError, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeUsage, preflightCheck, toShareGptTrajectory, withCwdMutex };
19525
+ export { Agent, AgentBuilder, AgentDisposedError, AgentRunError, AuthenticationError, Budget, BudgetExceededError, ConfigurationError, Cron, EventBus, FileSystemConversationStorage, GenerateObjectError, InMemoryConversationStorage, IntegrationNotConnectedError, InvalidTaskIdError, JobQueue, Memory, MemoryAdapterError, NetworkError, PermissionEngine, RateLimitError, Security, StreamObjectError, Task, TaskNotFoundError, Theokit, TheokitAgentError, UnknownAgentError, UnsupportedBudgetOperationError, UnsupportedRunOperationError, UnsupportedTaskOperationError, UsageAccumulator, buildReplayHistory, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createPermissionPlugin, createSquad, definePlugin, defineProvider, defineTool, extractRawId, getPricingEntry, inferApiMode, isTransientError, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeUsage, preflightCheck, toShareGptTrajectory, withCwdMutex };
19504
19526
  //# sourceMappingURL=index.js.map
19505
19527
  //# sourceMappingURL=index.js.map