@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
110 lines • 3.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Capability = void 0;
exports.requireBoundSession = requireBoundSession;
const agentToolRunConfig_1 = require("../../agentToolRunConfig.js");
const errors_1 = require("../errors.js");
class Capability {
_session;
_runAs;
_modelInstance;
_tracingParent;
_workspaceScope;
clone() {
const cloned = Object.create(Object.getPrototypeOf(this));
for (const [key, value] of Object.entries(this)) {
if (key === '_session' ||
key === '_runAs' ||
key === '_modelInstance' ||
key === '_tracingParent' ||
key === '_workspaceScope') {
continue;
}
cloned[key] = cloneCapabilityValue(value);
}
return cloned;
}
bind(session) {
this._session = session;
return this;
}
bindRunAs(runAs) {
this._runAs = typeof runAs === 'string' ? runAs : runAs?.name;
return this;
}
bindModel(_model, modelInstance) {
this._modelInstance = modelInstance;
return this;
}
bindTracingParent(parent) {
this._tracingParent = parent;
return this;
}
bindWorkspaceScope(scope) {
this._workspaceScope = scope;
return this;
}
modelResourcePath(manifest, path) {
return this._workspaceScope?.modelResourcePath(manifest.root, path) ?? path;
}
tracingParent(details) {
return (0, agentToolRunConfig_1.getToolCallParentSpanFromDetails)(details) ?? this._tracingParent;
}
requiredCapabilityTypes() {
return new Set();
}
tools() {
return [];
}
processManifest(manifest) {
return manifest;
}
instructions(_manifest) {
return null;
}
samplingParams(_samplingParams) {
return {};
}
processContext(context) {
return context;
}
}
exports.Capability = Capability;
function requireBoundSession(capabilityType, session) {
if (!session) {
throw new errors_1.SandboxConfigurationError(`${capitalize(capabilityType)} capability is not bound to a SandboxSession`, { capability: capabilityType });
}
return session;
}
function cloneCapabilityValue(value) {
if (Array.isArray(value)) {
return value.map((item) => cloneCapabilityValue(item));
}
if (value instanceof Uint8Array) {
return new Uint8Array(value);
}
if (value instanceof Map) {
return new Map(value);
}
if (value instanceof Set) {
return new Set(value);
}
if (isPlainRecord(value)) {
return Object.fromEntries(Object.entries(value).map(([key, childValue]) => [
key,
cloneCapabilityValue(childValue),
]));
}
return value;
}
function isPlainRecord(value) {
if (typeof value !== 'object' || value === null) {
return false;
}
const prototype = Object.getPrototypeOf(value);
return prototype === Object.prototype || prototype === null;
}
function capitalize(value) {
return value.charAt(0).toUpperCase() + value.slice(1);
}
//# sourceMappingURL=base.js.map