@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.cjs CHANGED
@@ -18715,25 +18715,47 @@ async function migrateSqliteToLance2(options) {
18715
18715
 
18716
18716
  // src/permission-engine.ts
18717
18717
  var PermissionEngine = class {
18718
- constructor(rules) {
18718
+ constructor(rules, options = {}) {
18719
18719
  this.rules = rules;
18720
+ this.defaultAction = options.defaultAction ?? "allow";
18720
18721
  }
18721
18722
  rules;
18723
+ defaultAction;
18722
18724
  /**
18723
- * Evaluate a tool name against the rules. First match wins; default "allow".
18725
+ * Evaluate a tool name against the rules. First match wins; falls back to the
18726
+ * configured `defaultAction` (default `"allow"`) when no rule matches.
18724
18727
  */
18725
18728
  evaluate(toolName) {
18726
18729
  for (const rule of this.rules) {
18727
- if (typeof rule.tool === "string") {
18728
- if (rule.tool === toolName) return rule.action;
18729
- } else {
18730
- if (rule.tool.test(toolName)) return rule.action;
18731
- }
18730
+ const matches = typeof rule.tool === "string" ? rule.tool === toolName : rule.tool.test(toolName);
18731
+ if (matches) return rule.action;
18732
18732
  }
18733
- return "allow";
18733
+ return this.defaultAction;
18734
18734
  }
18735
18735
  };
18736
18736
 
18737
+ // src/permission-plugin.ts
18738
+ function createPermissionPlugin(engine, opts = {}) {
18739
+ return definePlugin({
18740
+ name: opts.name ?? "permission-engine",
18741
+ version: "1.0.0",
18742
+ kind: "general",
18743
+ register(ctx) {
18744
+ ctx.on("pre_tool_call", (rawCtx) => {
18745
+ const { name } = rawCtx;
18746
+ const action = engine.evaluate(name);
18747
+ if (action === "deny") {
18748
+ return { block: true, message: `denied by permission engine: ${name}` };
18749
+ }
18750
+ if (action === "ask") {
18751
+ return opts.onAsk ? opts.onAsk(name) : { block: true, message: `requires approval: ${name}` };
18752
+ }
18753
+ return void 0;
18754
+ });
18755
+ }
18756
+ });
18757
+ }
18758
+
18737
18759
  // src/security.ts
18738
18760
  init_security();
18739
18761
  var Security = class {
@@ -19523,6 +19545,7 @@ exports.computeCost = computeCost;
19523
19545
  exports.createAgentFactory = createAgentFactory;
19524
19546
  exports.createCounterBudgetTracker = createCounterBudgetTracker;
19525
19547
  exports.createNoopMemoryProvider = createNoopMemoryProvider;
19548
+ exports.createPermissionPlugin = createPermissionPlugin;
19526
19549
  exports.createSquad = createSquad;
19527
19550
  exports.definePlugin = definePlugin;
19528
19551
  exports.defineProvider = defineProvider;