@papert-code/papert-code 0.3.93 → 0.3.94

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.
@@ -106342,7 +106342,7 @@ var __filename = fileURLToPath(import.meta.url);
106342
106342
  var __dirname2 = path4.dirname(__filename);
106343
106343
  async function getVersion() {
106344
106344
  const pkgJson = await getPackageJson(__dirname2);
106345
- return "0.3.93";
106345
+ return "0.3.94";
106346
106346
  }
106347
106347
  __name(getVersion, "getVersion");
106348
106348
 
@@ -108193,7 +108193,7 @@ __name(recordSubagentExecutionMetrics, "recordSubagentExecutionMetrics");
108193
108193
  init_esbuild_shims();
108194
108194
  var import_https_proxy_agent = __toESM(require_dist(), 1);
108195
108195
  import { Buffer as Buffer2 } from "buffer";
108196
- import * as https from "https";
108196
+ import * as https from "node:https";
108197
108197
 
108198
108198
  // packages/core/dist/src/utils/installationManager.js
108199
108199
  init_esbuild_shims();
@@ -110213,7 +110213,7 @@ function createContentGeneratorConfig(config, authType, generationConfig) {
110213
110213
  }
110214
110214
  __name(createContentGeneratorConfig, "createContentGeneratorConfig");
110215
110215
  async function createContentGenerator(config, gcConfig, isInitialAuth) {
110216
- const version2 = "0.3.93";
110216
+ const version2 = "0.3.94";
110217
110217
  const userAgent = `PapertCode/${version2} (${process.platform}; ${process.arch})`;
110218
110218
  const baseHeaders = {
110219
110219
  "User-Agent": userAgent
@@ -110244,12 +110244,12 @@ async function createContentGenerator(config, gcConfig, isInitialAuth) {
110244
110244
  if (!config.apiKey) {
110245
110245
  throw new Error("OpenAI API key is required");
110246
110246
  }
110247
- const { createOpenAIContentGenerator } = await import("./openaiContentGenerator-RS2GU6IS.js");
110247
+ const { createOpenAIContentGenerator } = await import("./openaiContentGenerator-EAVO6L3Y.js");
110248
110248
  return createOpenAIContentGenerator(config, gcConfig);
110249
110249
  }
110250
110250
  if (config.authType === AuthType2.PAPERT_OAUTH) {
110251
110251
  const { getPapertOAuthClient: getPapertOauthClient } = await import("./papertOAuth2-4I4JYPZW.js");
110252
- const { PapertContentGenerator } = await import("./papertContentGenerator-RYRJQVBF.js");
110252
+ const { PapertContentGenerator } = await import("./papertContentGenerator-G4SBF3DR.js");
110253
110253
  try {
110254
110254
  const papertClient = await getPapertOauthClient(gcConfig, isInitialAuth ? { requireCachedCredentials: true } : void 0);
110255
110255
  return new PapertContentGenerator(papertClient, config, gcConfig);
@@ -114,7 +114,7 @@ import {
114
114
  supportsMultimodalFunctionResponse,
115
115
  tokenLimit,
116
116
  uiTelemetryService
117
- } from "./chunk-TQNFJUNM.js";
117
+ } from "./chunk-6ZOXSA5F.js";
118
118
  import {
119
119
  escape,
120
120
  glob,
@@ -29277,12 +29277,19 @@ __name(executeToolWithHooks, "executeToolWithHooks");
29277
29277
  async function runSafetyChecks(config2, toolName, toolArgs) {
29278
29278
  if (!config2)
29279
29279
  return null;
29280
- const runner = config2.getSafetyCheckerRunner();
29281
- const rules = config2.getSafetyCheckerRules();
29280
+ const getRunner = config2.getSafetyCheckerRunner;
29281
+ const getRules = config2.getSafetyCheckerRules;
29282
+ const getApprovalMode = config2.getApprovalMode;
29283
+ const isInteractive = config2.isInteractive;
29284
+ if (typeof getRunner !== "function" || typeof getRules !== "function") {
29285
+ return null;
29286
+ }
29287
+ const runner = getRunner.call(config2);
29288
+ const rules = getRules.call(config2);
29282
29289
  if (!runner || rules.length === 0)
29283
29290
  return null;
29284
29291
  const argsString = rules.some((rule) => rule.argsPattern) ? stableStringify(toolArgs) : void 0;
29285
- const approvalMode = config2.getApprovalMode();
29292
+ const approvalMode = typeof getApprovalMode === "function" ? getApprovalMode.call(config2) : "";
29286
29293
  for (const rule of rules) {
29287
29294
  if (!safetyRuleMatches(rule, toolName, argsString, approvalMode)) {
29288
29295
  continue;
@@ -29293,7 +29300,7 @@ async function runSafetyChecks(config2, toolName, toolArgs) {
29293
29300
  continue;
29294
29301
  }
29295
29302
  const reason = result.reason ?? `Safety checker "${rule.checker.name}" blocked execution.`;
29296
- if (result.decision === SafetyCheckDecision.ASK_USER && !config2.isInteractive()) {
29303
+ if (result.decision === SafetyCheckDecision.ASK_USER && (typeof isInteractive === "function" ? !isInteractive.call(config2) : true)) {
29297
29304
  return {
29298
29305
  llmContent: `Safety check requires user confirmation, but this session is non-interactive: ${reason}`,
29299
29306
  returnDisplay: `Safety check requires user confirmation, but this session is non-interactive: ${reason}`,
@@ -67700,14 +67707,29 @@ var PolicyEngine = class {
67700
67707
  this.allowHooks = config2.allowHooks ?? true;
67701
67708
  }
67702
67709
  check(toolCall, serverName) {
67710
+ return this.getDecisionDetails(toolCall, serverName).decision;
67711
+ }
67712
+ getDecisionReason(toolCall, serverName) {
67713
+ return this.getDecisionDetails(toolCall, serverName).reason;
67714
+ }
67715
+ getDecisionDetails(toolCall, serverName) {
67703
67716
  const stringifiedArgs = toolCall.args && this.rules.some((rule) => rule.argsPattern) ? stableStringify(toolCall.args) : void 0;
67704
- for (const rule of this.rules) {
67705
- if (this.ruleMatches(rule, toolCall.name, stringifiedArgs, serverName)) {
67706
- return this.applyNonInteractiveMode(rule.decision);
67707
- }
67717
+ const matchedRule = this.rules.find((rule) => this.ruleMatches(rule, toolCall.name, stringifiedArgs, serverName));
67718
+ if (matchedRule) {
67719
+ const decision = this.applyNonInteractiveMode(matchedRule.decision);
67720
+ const deniedByNonInteractive2 = matchedRule.decision === PolicyDecision.ASK_USER && decision === PolicyDecision.DENY && this.nonInteractive;
67721
+ return {
67722
+ decision,
67723
+ reason: decision === PolicyDecision.DENY ? deniedByNonInteractive2 ? "Interactive confirmation is disabled in non-interactive mode" : this.buildDenyReason(matchedRule) : void 0
67724
+ };
67708
67725
  }
67709
67726
  debugLogger.debug(`[PolicyEngine.check] no matching rule for ${toolCall.name}, using default ${this.defaultDecision}`);
67710
- return this.applyNonInteractiveMode(this.defaultDecision);
67727
+ const fallbackDecision = this.applyNonInteractiveMode(this.defaultDecision);
67728
+ const deniedByNonInteractive = this.defaultDecision === PolicyDecision.ASK_USER && fallbackDecision === PolicyDecision.DENY && this.nonInteractive;
67729
+ return {
67730
+ decision: fallbackDecision,
67731
+ reason: fallbackDecision === PolicyDecision.DENY ? deniedByNonInteractive ? "Interactive confirmation is disabled in non-interactive mode" : "Denied by default policy decision" : void 0
67732
+ };
67711
67733
  }
67712
67734
  checkHook(context) {
67713
67735
  if (!this.allowHooks) {
@@ -67748,6 +67770,22 @@ var PolicyEngine = class {
67748
67770
  }
67749
67771
  return decision;
67750
67772
  }
67773
+ buildDenyReason(rule) {
67774
+ if (rule.reason?.trim()) {
67775
+ return rule.reason;
67776
+ }
67777
+ const parts = [];
67778
+ if (rule.toolName) {
67779
+ parts.push(`tool=${rule.toolName}`);
67780
+ }
67781
+ if (rule.argsPattern) {
67782
+ parts.push(`argsPattern=${rule.argsPattern.source}`);
67783
+ }
67784
+ if (typeof rule.priority === "number") {
67785
+ parts.push(`priority=${rule.priority}`);
67786
+ }
67787
+ return parts.length > 0 ? `Denied by matching policy rule (${parts.join(", ")})` : "Denied by matching policy rule";
67788
+ }
67751
67789
  };
67752
67790
 
67753
67791
  // packages/core/dist/src/safety/checker-runner.js
@@ -68431,14 +68469,17 @@ var MessageBus = class extends EventEmitter3 {
68431
68469
  });
68432
68470
  break;
68433
68471
  case PolicyDecision.DENY:
68472
+ const reason = this.policyEngine.getDecisionReason(message.toolCall, message.serverName);
68434
68473
  this.emitMessage({
68435
68474
  type: MessageBusType.TOOL_POLICY_REJECTION,
68436
- toolCall: message.toolCall
68475
+ toolCall: message.toolCall,
68476
+ ...reason ? { reason } : {}
68437
68477
  });
68438
68478
  this.emitMessage({
68439
68479
  type: MessageBusType.TOOL_CONFIRMATION_RESPONSE,
68440
68480
  correlationId: message.correlationId,
68441
- confirmed: false
68481
+ confirmed: false,
68482
+ ...reason ? { reason } : {}
68442
68483
  });
68443
68484
  break;
68444
68485
  case PolicyDecision.ASK_USER:
@@ -73815,10 +73856,14 @@ var DelegateInvocation = class extends BaseToolInvocation {
73815
73856
  return `Delegate to agent "${this.params.agentName}"`;
73816
73857
  }
73817
73858
  async execute() {
73818
- const message = `Delegated to agent "${this.params.agentName}" with input: ${this.params.input}`;
73859
+ const message = "The delegate_to_agent tool is not implemented yet. Configure and use subagents instead.";
73819
73860
  return {
73820
73861
  llmContent: [{ text: message }],
73821
- returnDisplay: message
73862
+ returnDisplay: message,
73863
+ error: {
73864
+ message,
73865
+ type: ToolErrorType.EXECUTION_FAILED
73866
+ }
73822
73867
  };
73823
73868
  }
73824
73869
  };
@@ -73857,10 +73902,14 @@ var SubagentInvocation = class extends BaseToolInvocation {
73857
73902
  return `Invoke subagent "${this.params.name}"`;
73858
73903
  }
73859
73904
  async execute() {
73860
- const message = `Subagent "${this.params.name}" invoked${this.params.input ? ` with input: ${this.params.input}` : ""}.`;
73905
+ const message = "The subagent_tool_wrapper tool is not implemented yet. Use configured subagents through the main orchestration flow.";
73861
73906
  return {
73862
73907
  llmContent: [{ text: message }],
73863
- returnDisplay: message
73908
+ returnDisplay: message,
73909
+ error: {
73910
+ message,
73911
+ type: ToolErrorType.EXECUTION_FAILED
73912
+ }
73864
73913
  };
73865
73914
  }
73866
73915
  };
@@ -31,7 +31,7 @@ import {
31
31
  logApiError,
32
32
  logApiResponse,
33
33
  tokenLimit
34
- } from "./chunk-TQNFJUNM.js";
34
+ } from "./chunk-6ZOXSA5F.js";
35
35
  import {
36
36
  __name,
37
37
  init_esbuild_shims
@@ -9924,8 +9924,7 @@ var DefaultRequestTokenizer = class {
9924
9924
  }
9925
9925
  }
9926
9926
  /**
9927
- * Calculate tokens for audio contents
9928
- * TODO: Implement proper audio token calculation
9927
+ * Calculate tokens for audio contents using a conservative data-size heuristic.
9929
9928
  */
9930
9929
  async calculateAudioTokens(audioContents) {
9931
9930
  if (audioContents.length === 0)
@@ -9934,7 +9933,10 @@ var DefaultRequestTokenizer = class {
9934
9933
  for (const audioContent of audioContents) {
9935
9934
  try {
9936
9935
  const dataSize = Math.floor(audioContent.data.length * 0.75);
9937
- totalTokens += Math.max(Math.ceil(dataSize / 100), 10);
9936
+ const mimeType = audioContent.mimeType.toLowerCase();
9937
+ const bytesPerToken = mimeType.includes("wav") || mimeType.includes("wave") ? 80 : 120;
9938
+ const estimatedTokens = Math.ceil(dataSize / bytesPerToken);
9939
+ totalTokens += Math.min(Math.max(estimatedTokens, 10), 16384);
9938
9940
  } catch (error) {
9939
9941
  console.warn("Error calculating audio tokens:", error);
9940
9942
  totalTokens += 10;