agentbox-sdk 0.1.500 → 0.1.502
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.
package/dist/agents/index.js
CHANGED
|
@@ -1518,7 +1518,7 @@ function mapOpenCodeTools(tools) {
|
|
|
1518
1518
|
}
|
|
1519
1519
|
return Object.fromEntries(tools.map((tool) => [tool, true]));
|
|
1520
1520
|
}
|
|
1521
|
-
function buildOpenCodeSubagentConfig(subAgents) {
|
|
1521
|
+
function buildOpenCodeSubagentConfig(subAgents, permission) {
|
|
1522
1522
|
return Object.fromEntries(
|
|
1523
1523
|
(subAgents ?? []).map((subAgent) => [
|
|
1524
1524
|
subAgent.name,
|
|
@@ -1526,6 +1526,7 @@ function buildOpenCodeSubagentConfig(subAgents) {
|
|
|
1526
1526
|
mode: "subagent",
|
|
1527
1527
|
description: subAgent.description,
|
|
1528
1528
|
prompt: subAgent.instructions,
|
|
1529
|
+
...permission ? { permission } : {},
|
|
1529
1530
|
// opencode reads a per-agent `model` as a "<providerID>/<modelID>"
|
|
1530
1531
|
// string (e.g. "openrouter/deepseek/deepseek-v4-flash"). Without it,
|
|
1531
1532
|
// the sub-agent silently inherits the orchestrator's model instead of
|
|
@@ -3359,28 +3360,32 @@ async function materializeCodexImage(options, part, index) {
|
|
|
3359
3360
|
if (part.source.type === "url") {
|
|
3360
3361
|
return part.source.url;
|
|
3361
3362
|
}
|
|
3363
|
+
const data = Buffer.from(part.source.data, "base64");
|
|
3364
|
+
if (data.length === 0) {
|
|
3365
|
+
throw new Error("Cannot attach an empty image to Codex.");
|
|
3366
|
+
}
|
|
3362
3367
|
const root = agentboxRoot(AgentProvider.Codex, Boolean(options.sandbox));
|
|
3363
3368
|
const imagePath = path9.join(
|
|
3364
3369
|
root,
|
|
3365
3370
|
"inputs",
|
|
3366
|
-
`codex-image-${index}${codexImageExtension(part.mediaType)}`
|
|
3371
|
+
`codex-image-${index}-${crypto2.randomUUID()}${codexImageExtension(part.mediaType)}`
|
|
3367
3372
|
);
|
|
3368
3373
|
if (options.sandbox) {
|
|
3369
|
-
const
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
[
|
|
3373
|
-
`mkdir -p ${shellQuote(path9.posix.dirname(imagePath))}`,
|
|
3374
|
-
`(base64 --decode < ${shellQuote(encodedPath)} > ${shellQuote(imagePath)} || base64 -D < ${shellQuote(encodedPath)} > ${shellQuote(imagePath)})`,
|
|
3375
|
-
`rm -f ${shellQuote(encodedPath)}`
|
|
3376
|
-
].join(" && "),
|
|
3374
|
+
const result = await options.sandbox.uploadAndRun(
|
|
3375
|
+
[{ path: imagePath, content: data }],
|
|
3376
|
+
`test "$(wc -c < ${shellQuote(imagePath)})" -eq ${data.length}`,
|
|
3377
3377
|
{ cwd: options.cwd, env: options.env }
|
|
3378
3378
|
);
|
|
3379
|
+
if (result.exitCode !== 0) {
|
|
3380
|
+
throw new Error(
|
|
3381
|
+
`Failed to upload image attachment to Codex (exit ${result.exitCode}): the file could not be written or its size did not match.`
|
|
3382
|
+
);
|
|
3383
|
+
}
|
|
3379
3384
|
return imagePath;
|
|
3380
3385
|
}
|
|
3381
3386
|
const fs = await import("fs/promises");
|
|
3382
3387
|
await fs.mkdir(path9.dirname(imagePath), { recursive: true });
|
|
3383
|
-
await fs.writeFile(imagePath,
|
|
3388
|
+
await fs.writeFile(imagePath, data);
|
|
3384
3389
|
return imagePath;
|
|
3385
3390
|
}
|
|
3386
3391
|
function resolveCodexOpenAiBaseUrlFromOptions(options) {
|
|
@@ -4406,7 +4411,10 @@ function buildOpenCodeConfig(options, interactiveApproval) {
|
|
|
4406
4411
|
agent: {
|
|
4407
4412
|
agentbox: baseAgent,
|
|
4408
4413
|
...reasoningVariants,
|
|
4409
|
-
...buildOpenCodeSubagentConfig(
|
|
4414
|
+
...buildOpenCodeSubagentConfig(
|
|
4415
|
+
options.subAgents,
|
|
4416
|
+
buildOpenCodePermissionConfig(interactiveApproval)
|
|
4417
|
+
)
|
|
4410
4418
|
}
|
|
4411
4419
|
};
|
|
4412
4420
|
}
|
|
@@ -4887,6 +4895,33 @@ var OpenCodeAgentAdapter = class {
|
|
|
4887
4895
|
}
|
|
4888
4896
|
const announcedUserMessageIds = /* @__PURE__ */ new Set();
|
|
4889
4897
|
const foreignMessageIds = /* @__PURE__ */ new Set();
|
|
4898
|
+
const runSessionIds = /* @__PURE__ */ new Set([sessionId]);
|
|
4899
|
+
const resolveRunSession = async (candidate) => {
|
|
4900
|
+
if (runSessionIds.has(candidate)) return true;
|
|
4901
|
+
try {
|
|
4902
|
+
const sessions = await fetchJson(`${runtime.baseUrl}/session`, {
|
|
4903
|
+
headers: runtime.previewHeaders
|
|
4904
|
+
});
|
|
4905
|
+
if (!Array.isArray(sessions)) return false;
|
|
4906
|
+
const parentById = /* @__PURE__ */ new Map();
|
|
4907
|
+
for (const session of sessions) {
|
|
4908
|
+
if (typeof session?.id === "string" && typeof session?.parentID === "string") {
|
|
4909
|
+
parentById.set(session.id, session.parentID);
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
const lineage = [];
|
|
4913
|
+
let cursor = candidate;
|
|
4914
|
+
while (cursor && !runSessionIds.has(cursor) && lineage.length < 16) {
|
|
4915
|
+
lineage.push(cursor);
|
|
4916
|
+
cursor = parentById.get(cursor);
|
|
4917
|
+
}
|
|
4918
|
+
if (!cursor || !runSessionIds.has(cursor)) return false;
|
|
4919
|
+
for (const id of lineage) runSessionIds.add(id);
|
|
4920
|
+
return true;
|
|
4921
|
+
} catch {
|
|
4922
|
+
return false;
|
|
4923
|
+
}
|
|
4924
|
+
};
|
|
4890
4925
|
sseTask = (async () => {
|
|
4891
4926
|
try {
|
|
4892
4927
|
for await (const event of streamSseResilient(
|
|
@@ -4920,6 +4955,13 @@ var OpenCodeAgentAdapter = class {
|
|
|
4920
4955
|
}
|
|
4921
4956
|
sink.emitRaw(raw);
|
|
4922
4957
|
const eventType = typeof payload?.type === "string" ? String(payload.type) : event.event;
|
|
4958
|
+
if (eventType === "session.created" || eventType === "session.updated") {
|
|
4959
|
+
const properties = payload.properties;
|
|
4960
|
+
const info = properties?.info;
|
|
4961
|
+
if (info && typeof info.id === "string" && typeof info.parentID === "string" && runSessionIds.has(info.parentID)) {
|
|
4962
|
+
runSessionIds.add(info.id);
|
|
4963
|
+
}
|
|
4964
|
+
}
|
|
4923
4965
|
if (eventType === "message.updated") {
|
|
4924
4966
|
const properties = payload.properties;
|
|
4925
4967
|
const info = properties?.info;
|
|
@@ -4960,7 +5002,8 @@ var OpenCodeAgentAdapter = class {
|
|
|
4960
5002
|
}
|
|
4961
5003
|
if (eventType === "permission.asked") {
|
|
4962
5004
|
const properties = payload.properties;
|
|
4963
|
-
if (properties && typeof properties.sessionID === "string" && properties.sessionID
|
|
5005
|
+
if (properties && typeof properties.sessionID === "string" && await resolveRunSession(properties.sessionID)) {
|
|
5006
|
+
const askingSessionId = properties.sessionID;
|
|
4964
5007
|
const permissionEvent = createOpenCodePermissionEvent(
|
|
4965
5008
|
request,
|
|
4966
5009
|
raw,
|
|
@@ -4971,7 +5014,7 @@ var OpenCodeAgentAdapter = class {
|
|
|
4971
5014
|
decision: "allow"
|
|
4972
5015
|
};
|
|
4973
5016
|
await fetchJson(
|
|
4974
|
-
`${runtime.baseUrl}/session/${
|
|
5017
|
+
`${runtime.baseUrl}/session/${askingSessionId}/permissions/${permissionEvent.requestId}`,
|
|
4975
5018
|
{
|
|
4976
5019
|
method: "POST",
|
|
4977
5020
|
headers: {
|
package/dist/index.js
CHANGED