@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
105 lines • 3.04 kB
JavaScript
import { getToolCallParentSpanFromDetails } from "../../agentToolRunConfig.mjs";
import { SandboxConfigurationError } from "../errors.mjs";
export 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 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;
}
}
export function requireBoundSession(capabilityType, session) {
if (!session) {
throw new 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.mjs.map