@ycodium-ai/agent-opencode 0.2.2729 → 0.2.2745
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/index.js +100 -24
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7917,6 +7917,57 @@ ${result.stderr}`);
|
|
|
7917
7917
|
}
|
|
7918
7918
|
}
|
|
7919
7919
|
|
|
7920
|
+
// src/mcpServers.ts
|
|
7921
|
+
function toOpenCodeMcpConfig(server) {
|
|
7922
|
+
const transport = server.transport;
|
|
7923
|
+
if (transport.type === "stdio") {
|
|
7924
|
+
return {
|
|
7925
|
+
type: "local",
|
|
7926
|
+
command: [transport.command, ...transport.args ?? []],
|
|
7927
|
+
...transport.env ? { environment: { ...transport.env } } : {}
|
|
7928
|
+
};
|
|
7929
|
+
}
|
|
7930
|
+
return {
|
|
7931
|
+
type: "remote",
|
|
7932
|
+
url: transport.url,
|
|
7933
|
+
...transport.headers ? { headers: { ...transport.headers } } : {},
|
|
7934
|
+
// 带着宿主给的凭据,别让 OpenCode 碰到 401 就去走 OAuth 发现。
|
|
7935
|
+
oauth: false
|
|
7936
|
+
};
|
|
7937
|
+
}
|
|
7938
|
+
function failureSummary(cause) {
|
|
7939
|
+
if (cause instanceof Error) return { error: cause.name, message: cause.message };
|
|
7940
|
+
if (cause !== null && typeof cause === "object") {
|
|
7941
|
+
const record = cause;
|
|
7942
|
+
return {
|
|
7943
|
+
error: typeof record.name === "string" ? record.name : "unknown",
|
|
7944
|
+
...typeof record.status === "number" ? { status: record.status } : {}
|
|
7945
|
+
};
|
|
7946
|
+
}
|
|
7947
|
+
return { error: typeof cause };
|
|
7948
|
+
}
|
|
7949
|
+
async function addOpenCodeMcpServers(input) {
|
|
7950
|
+
for (const server of input.servers ?? []) {
|
|
7951
|
+
let failure;
|
|
7952
|
+
try {
|
|
7953
|
+
const added = await input.client.mcp.add({
|
|
7954
|
+
name: server.name,
|
|
7955
|
+
config: toOpenCodeMcpConfig(server)
|
|
7956
|
+
});
|
|
7957
|
+
const status = added.data?.[server.name]?.status;
|
|
7958
|
+
if (status !== "connected") failure = status === void 0 ? {} : { status };
|
|
7959
|
+
} catch (cause) {
|
|
7960
|
+
failure = failureSummary(cause);
|
|
7961
|
+
}
|
|
7962
|
+
if (failure === void 0) continue;
|
|
7963
|
+
input.log.warn("OpenCode could not attach an MCP server; the session continues without it.", {
|
|
7964
|
+
name: server.name,
|
|
7965
|
+
transport: server.transport.type,
|
|
7966
|
+
...failure
|
|
7967
|
+
});
|
|
7968
|
+
}
|
|
7969
|
+
}
|
|
7970
|
+
|
|
7920
7971
|
// src/workspaceInventory.ts
|
|
7921
7972
|
import * as NodePath5 from "node:path";
|
|
7922
7973
|
var isInside = (directory, file) => {
|
|
@@ -8026,6 +8077,30 @@ function normalizeQuestionRequest(request) {
|
|
|
8026
8077
|
}));
|
|
8027
8078
|
}
|
|
8028
8079
|
|
|
8080
|
+
// src/sessionContext.ts
|
|
8081
|
+
function withoutActiveTurn(session) {
|
|
8082
|
+
const { activeTurnId, ...rest } = session;
|
|
8083
|
+
void activeTurnId;
|
|
8084
|
+
return rest;
|
|
8085
|
+
}
|
|
8086
|
+
function emitEvent(events, context, type3, payload, extra) {
|
|
8087
|
+
const turnId = extra?.turnId ?? context.session.activeTurnId;
|
|
8088
|
+
const event = {
|
|
8089
|
+
eventId: randomUUID(),
|
|
8090
|
+
provider: OPENCODE_DRIVER_KIND,
|
|
8091
|
+
...context.session.providerInstanceId ? { providerInstanceId: context.session.providerInstanceId } : {},
|
|
8092
|
+
threadId: context.threadId,
|
|
8093
|
+
createdAt: nowIso(),
|
|
8094
|
+
type: type3,
|
|
8095
|
+
payload,
|
|
8096
|
+
...turnId ? { turnId } : {},
|
|
8097
|
+
...extra?.itemId ? { itemId: extra.itemId } : {},
|
|
8098
|
+
...extra?.requestId ? { requestId: extra.requestId } : {},
|
|
8099
|
+
providerRefs: {}
|
|
8100
|
+
};
|
|
8101
|
+
events.push(event);
|
|
8102
|
+
}
|
|
8103
|
+
|
|
8029
8104
|
// src/textMerge.ts
|
|
8030
8105
|
function commonPrefixLength(left, right) {
|
|
8031
8106
|
let index = 0;
|
|
@@ -8178,28 +8253,6 @@ function takeTurnUsage(usageByMessageId, sessionId) {
|
|
|
8178
8253
|
}
|
|
8179
8254
|
|
|
8180
8255
|
// src/sessionEvents.ts
|
|
8181
|
-
function withoutActiveTurn(session) {
|
|
8182
|
-
const { activeTurnId, ...rest } = session;
|
|
8183
|
-
void activeTurnId;
|
|
8184
|
-
return rest;
|
|
8185
|
-
}
|
|
8186
|
-
function emitEvent(events, context, type3, payload, extra) {
|
|
8187
|
-
const turnId = extra?.turnId ?? context.session.activeTurnId;
|
|
8188
|
-
const event = {
|
|
8189
|
-
eventId: randomUUID(),
|
|
8190
|
-
provider: OPENCODE_DRIVER_KIND,
|
|
8191
|
-
...context.session.providerInstanceId ? { providerInstanceId: context.session.providerInstanceId } : {},
|
|
8192
|
-
threadId: context.threadId,
|
|
8193
|
-
createdAt: nowIso(),
|
|
8194
|
-
type: type3,
|
|
8195
|
-
payload,
|
|
8196
|
-
...turnId ? { turnId } : {},
|
|
8197
|
-
...extra?.itemId ? { itemId: extra.itemId } : {},
|
|
8198
|
-
...extra?.requestId ? { requestId: extra.requestId } : {},
|
|
8199
|
-
providerRefs: {}
|
|
8200
|
-
};
|
|
8201
|
-
events.push(event);
|
|
8202
|
-
}
|
|
8203
8256
|
function openCodeEventSessionId(event) {
|
|
8204
8257
|
const properties = event.properties;
|
|
8205
8258
|
if (!isRecord2(properties)) return void 0;
|
|
@@ -8304,6 +8357,7 @@ function emitToolLifecycle(events, context, part) {
|
|
|
8304
8357
|
function completeActiveTurn(events, context, state, extra) {
|
|
8305
8358
|
const turnId = context.session.activeTurnId;
|
|
8306
8359
|
const usage = takeTurnUsage(context.usageByMessageId, context.sessionId);
|
|
8360
|
+
context.pendingTurnError = void 0;
|
|
8307
8361
|
if (!turnId) return usage;
|
|
8308
8362
|
if (state === "interrupted") {
|
|
8309
8363
|
emitEvent(
|
|
@@ -8721,7 +8775,16 @@ async function handleSubscribedEvent(input) {
|
|
|
8721
8775
|
return;
|
|
8722
8776
|
}
|
|
8723
8777
|
if (status.type === "idle") {
|
|
8724
|
-
|
|
8778
|
+
const turnError = context.pendingTurnError;
|
|
8779
|
+
if (turnError === void 0) {
|
|
8780
|
+
completeActiveTurn(events, context, "completed");
|
|
8781
|
+
} else {
|
|
8782
|
+
completeActiveTurn(events, context, "failed", { errorMessage: turnError });
|
|
8783
|
+
emitEvent(events, context, "runtime.error", {
|
|
8784
|
+
message: turnError,
|
|
8785
|
+
class: "provider_error"
|
|
8786
|
+
});
|
|
8787
|
+
}
|
|
8725
8788
|
context.session = { ...context.session, status: "ready", updatedAt: nowIso() };
|
|
8726
8789
|
emitEvent(events, context, "session.state.changed", { state: "ready" });
|
|
8727
8790
|
}
|
|
@@ -8733,7 +8796,14 @@ async function handleSubscribedEvent(input) {
|
|
|
8733
8796
|
return;
|
|
8734
8797
|
}
|
|
8735
8798
|
const message = sessionErrorMessage(event.properties.error);
|
|
8736
|
-
|
|
8799
|
+
if (event.properties.sessionID === void 0) {
|
|
8800
|
+
emitEvent(events, context, "runtime.warning", { message });
|
|
8801
|
+
return;
|
|
8802
|
+
}
|
|
8803
|
+
if (context.session.activeTurnId !== void 0) {
|
|
8804
|
+
context.pendingTurnError ??= message;
|
|
8805
|
+
return;
|
|
8806
|
+
}
|
|
8737
8807
|
emitEvent(events, context, "runtime.error", {
|
|
8738
8808
|
message,
|
|
8739
8809
|
class: "provider_error"
|
|
@@ -9645,6 +9715,11 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9645
9715
|
if (server.external) {
|
|
9646
9716
|
const tooOld = openCodeTooOldDetail(await readOpenCodeServerVersion(client2));
|
|
9647
9717
|
if (tooOld) throw new Error(tooOld);
|
|
9718
|
+
if ((input.mcpServers?.length ?? 0) > 0) {
|
|
9719
|
+
host.log.info("OpenCode runs on an external server; Ycodium does not add MCP servers.");
|
|
9720
|
+
}
|
|
9721
|
+
} else {
|
|
9722
|
+
await addOpenCodeMcpServers({ client: client2, servers: input.mcpServers, log: host.log });
|
|
9648
9723
|
}
|
|
9649
9724
|
const nativeModeId = openCodeNativeModeFor(input.runtimeMode, input.nativeModeId);
|
|
9650
9725
|
const permission = openCodePermissionRulesForNativeMode(
|
|
@@ -9762,6 +9837,7 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9762
9837
|
completedTextParts: /* @__PURE__ */ new Set(),
|
|
9763
9838
|
startedToolItems: /* @__PURE__ */ new Set(),
|
|
9764
9839
|
compaction: void 0,
|
|
9840
|
+
pendingTurnError: void 0,
|
|
9765
9841
|
attachmentsApi: attachments,
|
|
9766
9842
|
runtimeMode: input.runtimeMode,
|
|
9767
9843
|
matchModel: createCatalogModelMatcher2(host.log)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/agent-opencode",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2745",
|
|
4
4
|
"description": "OpenCode executor: OpenCode CLI via @opencode-ai/sdk/v2.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@types/node": "24.12.4",
|
|
25
25
|
"esbuild": "0.28.1",
|
|
26
26
|
"vite-plus": "0.2.2",
|
|
27
|
-
"@ycodium-ai/plugin-api": "0.2.
|
|
27
|
+
"@ycodium-ai/plugin-api": "0.2.0",
|
|
28
28
|
"ycodium-fetch-ports": "0.0.0",
|
|
29
29
|
"ycodium-executor-testing": "0.0.0"
|
|
30
30
|
},
|