UNPKG

@openai/agents-core

Version:

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.

97 lines • 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.serializeTool = serializeTool; exports.serializeHandoff = serializeHandoff; const errors_1 = require("../errors.js"); const toolIdentity_1 = require("../toolIdentity.js"); const REQUIRED_COMPUTER_METHODS = [ 'screenshot', 'click', 'doubleClick', 'drag', 'keypress', 'move', 'scroll', 'type', 'wait', ]; function isComputerInstance(value) { if (!value || typeof value !== 'object') { return false; } const record = value; return REQUIRED_COMPUTER_METHODS.every((methodName) => typeof record[methodName] === 'function'); } function hasComputerDisplayMetadata(computer) { return (typeof computer.environment === 'string' && Array.isArray(computer.dimensions) && computer.dimensions.length === 2 && computer.dimensions.every((value) => typeof value === 'number')); } function serializeTool(tool) { if (tool.type === 'function') { const namespace = (0, toolIdentity_1.getExplicitFunctionToolNamespace)(tool); return { type: 'function', name: tool.name, description: tool.description, parameters: tool.parameters, strict: tool.strict, deferLoading: tool.deferLoading, providerData: tool.providerData, ...(tool.allowedCallers ? { allowedCallers: tool.allowedCallers } : {}), ...(tool.outputSchema ? { outputSchema: tool.outputSchema } : {}), ...(namespace ? { namespace } : {}), ...(namespace ? { namespaceDescription: (0, toolIdentity_1.getFunctionToolNamespaceDescription)(tool), } : {}), }; } if (tool.type === 'computer') { // When a computer is created lazily via an initializer, serializeTool can be called before initialization (e.g., manual serialize without running the agent). if (!isComputerInstance(tool.computer)) { throw new errors_1.UserError('Computer tool is not initialized for serialization. Call resolveComputer({ tool, runContext }) first (for example, when building a model payload outside Runner.run).'); } return { type: 'computer', name: tool.name, ...(hasComputerDisplayMetadata(tool.computer) ? { environment: tool.computer.environment, dimensions: tool.computer.dimensions, } : {}), }; } if (tool.type === 'shell') { return { type: 'shell', name: tool.name, environment: tool.environment, ...(tool.allowedCallers ? { allowedCallers: tool.allowedCallers } : {}), }; } if (tool.type === 'apply_patch') { return { type: 'apply_patch', name: tool.name, ...(tool.allowedCallers ? { allowedCallers: tool.allowedCallers } : {}), }; } return { type: 'hosted_tool', name: tool.name, providerData: tool.providerData, }; } function serializeHandoff(h) { return { toolName: h.toolName, toolDescription: h.toolDescription, inputJsonSchema: h.inputJsonSchema, strictJsonSchema: h.strictJsonSchema, }; } //# sourceMappingURL=serialize.js.map