@zuora/agent-toolkit 0.1.0-alpha.0 → 0.1.0-alpha.1

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.
@@ -1,6 +1,6 @@
1
1
  import { tool } from '@openai/agents';
2
2
  import { ToolkitCore } from '../shared/toolkit-core.js';
3
- import { Z as ZuoraToolDefinition, a as ZuoraAgentToolkitConfigInput, T as ToolSelection } from '../async-jobs-DJ_GygII.js';
3
+ import { b as ZuoraToolExecutionResult, Z as ZuoraToolDefinition, a as ZuoraAgentToolkitConfigInput, T as ToolSelection } from '../async-jobs-DJ_GygII.js';
4
4
  import { Z as ZuoraOpenAIAgentToolkit } from '../toolkit-Bjw46goJ.js';
5
5
  import 'openai/resources/chat/completions';
6
6
 
@@ -22,6 +22,35 @@ type AgentsFunctionTool = ReturnType<typeof tool>;
22
22
  * automatically inside `convertTools()` — callers do not need to know about it.
23
23
  */
24
24
  declare class ZuoraOpenAIAgentsToolkit extends ToolkitCore<AgentsFunctionTool> {
25
+ /** Maps sanitized adapter tool names back to their original ZuoraToolDefinition. */
26
+ private sanitizedToolMap;
27
+ /**
28
+ * Look up a ZuoraToolDefinition by its sanitized adapter tool name.
29
+ *
30
+ * The OpenAI Agents SDK registers tools with sanitized names (see convertTools),
31
+ * but external code may reference tools by their original MCP names. This method
32
+ * provides resolution in both directions.
33
+ */
34
+ private resolveToolName;
35
+ /**
36
+ * Resolve a tool name that may be either sanitized or original MCP format.
37
+ *
38
+ * This provides additional name normalization to handle cases where:
39
+ * - A tool name contains unsanitized characters (like dots)
40
+ * - A tool name was learned from descriptions or logs
41
+ *
42
+ * We attempt to find a match with relaxed sanitization rules before giving up.
43
+ */
44
+ private normalizeToolName;
45
+ /**
46
+ * Override callTool to provide flexible name resolution.
47
+ *
48
+ * The OpenAI Agents SDK may receive tool calls with names that were learned
49
+ * from descriptions or other sources (not directly from tool registration).
50
+ * This override allows us to handle both sanitized and original tool names
51
+ * by falling back to name normalization when the direct lookup fails.
52
+ */
53
+ callTool(operationName: string, input: Record<string, unknown>): Promise<ZuoraToolExecutionResult>;
25
54
  /**
26
55
  * Serialises the agent tool response, emits an `agent.tool.response`
27
56
  * observability event (with the response in `metadata` when
@@ -4183,8 +4183,17 @@ var createHttpMcpClientConfig = (config) => {
4183
4183
  };
4184
4184
  var isTenantAuthConnection = (connection) => connection?.tenantAuth?.enabled === true;
4185
4185
  var filterCatalogTools = (tools, policy) => tools.filter((tool2) => {
4186
- if (policy.mode === SafetyMode.ReadOnly && tool2.meta.access === "write") {
4187
- return false;
4186
+ if (policy.mode === SafetyMode.ReadOnly) {
4187
+ if (tool2.meta.operationAccess) {
4188
+ const hasReadOperation = Object.values(tool2.meta.operationAccess).some(
4189
+ (access) => access === "read"
4190
+ );
4191
+ if (!hasReadOperation) {
4192
+ return false;
4193
+ }
4194
+ } else if (tool2.meta.access === "write") {
4195
+ return false;
4196
+ }
4188
4197
  }
4189
4198
  if (policy.bundles.size > 0 && !policy.bundles.has(tool2.meta.bundle)) {
4190
4199
  return false;
@@ -4346,18 +4355,18 @@ var ToolkitCore = class {
4346
4355
  });
4347
4356
  }
4348
4357
  const mode = this.config.configuration?.mode ?? SafetyMode.ReadOnly;
4349
- if (mode === SafetyMode.ReadOnly && tool2.meta.access === "write") {
4350
- throw new ZuoraAgentToolkitError({
4351
- code: "TOOL_EXECUTION_ERROR",
4352
- message: `Write tool "${operationName}" is disabled in readOnly mode.`,
4353
- category: "tool_execution"
4354
- });
4355
- }
4356
4358
  const nativeRuntimeTool = this.nativeToolRegistry?.get(operationName);
4357
4359
  const nativeApprovalMetadata = nativeRuntimeTool?.approvalMetadata(input);
4358
4360
  const invokedOperation = tool2.meta.operationSelector ? String(input[tool2.meta.operationSelector] ?? "") : void 0;
4359
4361
  const effectiveAccess = (invokedOperation ? tool2.meta.operationAccess?.[invokedOperation] : void 0) ?? tool2.meta.access;
4360
4362
  const effectiveRiskLevel = (invokedOperation ? tool2.meta.operationRiskLevel?.[invokedOperation] : void 0) ?? tool2.meta.riskLevel;
4363
+ if (mode === SafetyMode.ReadOnly && effectiveAccess === "write") {
4364
+ throw new ZuoraAgentToolkitError({
4365
+ code: "TOOL_EXECUTION_ERROR",
4366
+ message: `Write operation "${invokedOperation ?? operationName}" is disabled in readOnly mode.`,
4367
+ category: "tool_execution"
4368
+ });
4369
+ }
4361
4370
  const effectiveTool = effectiveAccess === tool2.meta.access && effectiveRiskLevel === tool2.meta.riskLevel ? tool2 : { ...tool2, meta: { ...tool2.meta, access: effectiveAccess, riskLevel: effectiveRiskLevel } };
4362
4371
  await enforceApproval(
4363
4372
  effectiveTool,
@@ -4975,6 +4984,79 @@ var strictifySchema = (schema) => {
4975
4984
 
4976
4985
  // src/openai-agents/toolkit.ts
4977
4986
  var ZuoraOpenAIAgentsToolkit = class extends ToolkitCore {
4987
+ /** Maps sanitized adapter tool names back to their original ZuoraToolDefinition. */
4988
+ sanitizedToolMap = /* @__PURE__ */ new Map();
4989
+ /**
4990
+ * Look up a ZuoraToolDefinition by its sanitized adapter tool name.
4991
+ *
4992
+ * The OpenAI Agents SDK registers tools with sanitized names (see convertTools),
4993
+ * but external code may reference tools by their original MCP names. This method
4994
+ * provides resolution in both directions.
4995
+ */
4996
+ resolveToolName(name) {
4997
+ if (this.sanitizedToolMap.has(name)) {
4998
+ return name;
4999
+ }
5000
+ for (const [sanitized, def] of this.sanitizedToolMap) {
5001
+ if (def.name === name) {
5002
+ return sanitized;
5003
+ }
5004
+ }
5005
+ return void 0;
5006
+ }
5007
+ /**
5008
+ * Resolve a tool name that may be either sanitized or original MCP format.
5009
+ *
5010
+ * This provides additional name normalization to handle cases where:
5011
+ * - A tool name contains unsanitized characters (like dots)
5012
+ * - A tool name was learned from descriptions or logs
5013
+ *
5014
+ * We attempt to find a match with relaxed sanitization rules before giving up.
5015
+ */
5016
+ normalizeToolName(name) {
5017
+ const directMatch = this.resolveToolName(name);
5018
+ if (directMatch) {
5019
+ return directMatch;
5020
+ }
5021
+ const normalized = name.replace(/\./g, "_");
5022
+ const normalizedMatch = this.resolveToolName(normalized);
5023
+ if (normalizedMatch) {
5024
+ return normalizedMatch;
5025
+ }
5026
+ for (const [sanitized, def] of this.sanitizedToolMap) {
5027
+ if (def.name === normalized) {
5028
+ return sanitized;
5029
+ }
5030
+ }
5031
+ return void 0;
5032
+ }
5033
+ /**
5034
+ * Override callTool to provide flexible name resolution.
5035
+ *
5036
+ * The OpenAI Agents SDK may receive tool calls with names that were learned
5037
+ * from descriptions or other sources (not directly from tool registration).
5038
+ * This override allows us to handle both sanitized and original tool names
5039
+ * by falling back to name normalization when the direct lookup fails.
5040
+ */
5041
+ async callTool(operationName, input) {
5042
+ try {
5043
+ return await super.callTool(operationName, input);
5044
+ } catch (error) {
5045
+ if (error instanceof Error && (error.message.includes("Unknown Zuora tool") || error.message.includes("TOOL_NOT_FOUND"))) {
5046
+ const sanitized = this.normalizeToolName(operationName);
5047
+ if (sanitized) {
5048
+ const def = this.sanitizedToolMap.get(sanitized);
5049
+ if (def) {
5050
+ console.warn(
5051
+ `[zuora-agent-toolkit] Tool name normalized: "${operationName}" -> "${def.name}" (sanitized: "${sanitized}")`
5052
+ );
5053
+ return await super.callTool(def.name, input);
5054
+ }
5055
+ }
5056
+ }
5057
+ throw error;
5058
+ }
5059
+ }
4978
5060
  /**
4979
5061
  * Serialises the agent tool response, emits an `agent.tool.response`
4980
5062
  * observability event (with the response in `metadata` when
@@ -4998,6 +5080,7 @@ var ZuoraOpenAIAgentsToolkit = class extends ToolkitCore {
4998
5080
  convertTools(tools) {
4999
5081
  return tools.map((def) => {
5000
5082
  const sanitizedName = sanitizeAdapterToolName(def.name);
5083
+ this.sanitizedToolMap.set(sanitizedName, def);
5001
5084
  return tool({
5002
5085
  name: sanitizedName,
5003
5086
  description: def.description,