openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
145 lines (144 loc) • 5.13 kB
JavaScript
import { a as drainAgentRunTerminalWrites } from "./agent-run-terminal-writes-eqeCFAOx.mjs";
import { s as executionIdentitySpawnAdmission } from "./execution-identity-admission-EuMO_R29.mjs";
import { S as createOperationalRunInstanceRef, d as prepareAgentRunAdmission } from "./admitted-run-context-D3Jvk_f_.mjs";
import { t as withPostAdmissionExecutionOwnerBinding } from "./execution-owner-binding-lVcbirDs.mjs";
//#region src/agents/agent-command-admission-facts.ts
const factsByIngress = /* @__PURE__ */ new WeakMap();
function attachAgentCommandAdmissionFacts(e, t) {
factsByIngress.set(e, t);
}
function getAgentCommandAdmissionFacts(e) {
return factsByIngress.get(e);
}
//#endregion
//#region src/agents/agent-command-execution-identity-spawn.ts
const EXECUTION_IDENTITY_SPAWN_FACTS = Symbol("executionIdentitySpawnFacts");
/** Attach authenticated spawn facts without widening the public AgentCommandOpts contract. */
function withAgentCommandExecutionIdentitySpawnFacts(e, t) {
if (!t) return e;
return {
...e,
[EXECUTION_IDENTITY_SPAWN_FACTS]: t
};
}
function readAgentCommandExecutionIdentitySpawnFacts(e) {
return e[EXECUTION_IDENTITY_SPAWN_FACTS];
}
function withoutAgentCommandExecutionIdentitySpawnFacts(e) {
return {
...e,
[EXECUTION_IDENTITY_SPAWN_FACTS]: void 0
};
}
//#endregion
//#region src/agents/command/types.ts
/** Public ingress clears the same host-owned fields its option type excludes. */
const AGENT_COMMAND_PUBLIC_INGRESS_DEFAULTS = {
clientCaps: void 0,
gatewayUiCommandTarget: void 0,
toolBindings: void 0,
taskSuggestionDeliveryMode: void 0,
runtimeContextFragments: void 0,
senderIsOwner: false,
gitContributorProfileId: void 0,
pinnedWidgetAuthoring: void 0,
operationalRunInstance: void 0,
assertSourceCurrent: void 0,
operatorAuthority: void 0,
requesterOrigin: void 0,
privateCompletion: void 0,
extraSystemPromptTurnContext: void 0,
replyExpectation: void 0,
skillLibraryAuthoring: void 0,
cronCreatorAuthorityCapability: void 0,
onAdmittedRunContext: void 0,
onPostAdmittedRunContext: void 0,
beforeTerminalDelivery: void 0,
isTerminalOutcomeObserved: void 0,
prepareAssistantTranscriptMessage: void 0,
internalDeliverySuppressErrors: void 0,
operatorDirectRoot: void 0
};
//#endregion
//#region src/agents/agent-command-execution-identity.ts
const LOCAL_CLI_ADMISSION_INGRESS = {
kind: "local-cli",
boundary: "agent-command.local",
state: "present"
};
function systemIngress(e) {
return {
kind: "system",
boundary: e,
state: "present"
};
}
function prepareAgentCommandRunAdmission(e, t) {
const n = getAgentCommandAdmissionFacts(e.operationalRunInstance) ?? { ingress: e.ingress };
const r = t?.applicableGrants;
const i = t?.assurance ?? n.assurance;
const a = t?.representedSubject ?? n.representedSubject;
return prepareAgentRunAdmission({
cfg: e.cfg,
operationalRunInstance: e.operationalRunInstance,
facts: executionIdentitySpawnAdmission({
operation: "attach",
value: {
runId: e.runId,
agentId: e.agentId,
ingress: t?.ingress ?? n.ingress,
...a ? { representedSubject: a } : {},
...t?.invoker ?? n.invoker ? { invoker: t?.invoker ?? n.invoker } : {},
...r ? { applicableGrants: r } : {},
...i ? { assurance: i } : {}
},
extra: t?.spawnAdmission
}),
...e.onAdmitted ? { onAdmitted: e.onAdmitted } : {},
assertSourceCurrent: e.assertSourceCurrent,
operatorAuthority: e.operatorAuthority
});
}
function prepareAgentCommandExecutionIdentity(e) {
const { opts: t, prepared: n } = e;
const r = t.operationalRunInstance ?? createOperationalRunInstanceRef(n.runId);
const i = getAgentCommandAdmissionFacts(e.opts.runContext ?? e.opts);
if (i) attachAgentCommandAdmissionFacts(r, i);
const a = {
agentId: n.sessionAgentId,
cfg: n.cfg,
ingress: e.ingress,
operationalRunInstance: r,
runId: n.runId,
assertSourceCurrent: t.assertSourceCurrent,
operatorAuthority: t.operatorAuthority,
onAdmitted: t.onAdmittedRunContext
};
const o = readAgentCommandExecutionIdentitySpawnFacts(t);
const s = o ? prepareAgentCommandRunAdmission(a, o) : executionIdentity.prepare(a);
const c = t.onPostAdmittedRunContext ? withPostAdmissionExecutionOwnerBinding(s, t.onPostAdmittedRunContext) : s;
return Object.freeze({
...c,
finalDeliverySource: n.sessionEntry ? {
sessionId: n.sessionEntry.sessionId,
lifecycleRevision: n.sessionEntry.lifecycleRevision,
activeWriterRunId: n.sessionEntry.activeWriterRunId
} : void 0,
finish: async () => {
await drainAgentRunTerminalWrites(c.operationalRunInstance).finally(c.close);
}
});
}
function sanitizePublicAgentCommandIngressOpts(e) {
return withoutAgentCommandExecutionIdentitySpawnFacts({
...e,
...AGENT_COMMAND_PUBLIC_INGRESS_DEFAULTS
});
}
const executionIdentity = {
localIngress: LOCAL_CLI_ADMISSION_INGRESS,
prepare: prepareAgentCommandRunAdmission,
systemIngress
};
//#endregion
export { attachAgentCommandAdmissionFacts as a, withAgentCommandExecutionIdentitySpawnFacts as i, prepareAgentCommandExecutionIdentity as n, sanitizePublicAgentCommandIngressOpts as r, executionIdentity as t };