@ycodium-ai/agent-opencode 0.2.2167 → 0.2.2488
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 +321 -236
- package/locales/en.json +24 -0
- package/locales/zh-CN.json +24 -0
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -538,7 +538,6 @@ import { definePlugin } from "@ycodium-ai/plugin-api";
|
|
|
538
538
|
|
|
539
539
|
// src/card.ts
|
|
540
540
|
var OPENCODE_DRIVER_KIND = "opencode";
|
|
541
|
-
var OPENCODE_BINDING_PROVIDER_ID = "ycodium";
|
|
542
541
|
var OPENCODE_CARD = {
|
|
543
542
|
driverKind: OPENCODE_DRIVER_KIND,
|
|
544
543
|
displayName: "OpenCode",
|
|
@@ -565,9 +564,6 @@ var OPENCODE_CARD = {
|
|
|
565
564
|
defaultTextGenerationModel: "openai/gpt-5",
|
|
566
565
|
customModelIdExample: "openai/gpt-5",
|
|
567
566
|
modelSlugAliases: {},
|
|
568
|
-
modelsDevProviderIds: [],
|
|
569
|
-
modelsDevSlugPrefixed: true,
|
|
570
|
-
modelSlugPrefix: "",
|
|
571
567
|
mcpTransports: ["stdio", "http"],
|
|
572
568
|
pluginManaged: true,
|
|
573
569
|
verifiedSkills: true,
|
|
@@ -586,14 +582,47 @@ var OPENCODE_CARD = {
|
|
|
586
582
|
// OpenCode 凭据由 CLI 自己管在 XDG 目录,probe 从已连接 provider 推断,不读 auth.json。
|
|
587
583
|
credentialSources: [],
|
|
588
584
|
diagnostics: [],
|
|
585
|
+
// 设置表单照这份画:带 x-ycodium-form 的属性才进表单(enabled、customModels 等另有入口,不在此列),
|
|
586
|
+
// 顺序看 x-ycodium-form-order;文案键在本插件 locales/<locale>.json 里解析,宿主不兜底。
|
|
589
587
|
configSchema: {
|
|
590
588
|
type: "object",
|
|
589
|
+
"x-ycodium-form-order": ["binaryPath", "serverUrl", "serverPassword", "homePath"],
|
|
591
590
|
properties: {
|
|
592
591
|
enabled: { type: "boolean" },
|
|
593
|
-
binaryPath: {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
592
|
+
binaryPath: {
|
|
593
|
+
type: "string",
|
|
594
|
+
"x-ycodium-form": {
|
|
595
|
+
titleKey: "form.binaryPath.title",
|
|
596
|
+
descriptionKey: "form.binaryPath.description",
|
|
597
|
+
placeholderKey: "form.binaryPath.placeholder",
|
|
598
|
+
control: "executable-path"
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
serverUrl: {
|
|
602
|
+
type: "string",
|
|
603
|
+
"x-ycodium-form": {
|
|
604
|
+
titleKey: "form.serverUrl.title",
|
|
605
|
+
descriptionKey: "form.serverUrl.description",
|
|
606
|
+
placeholderKey: "form.serverUrl.placeholder"
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
serverPassword: {
|
|
610
|
+
type: "string",
|
|
611
|
+
"x-ycodium-form": {
|
|
612
|
+
titleKey: "form.serverPassword.title",
|
|
613
|
+
descriptionKey: "form.serverPassword.description",
|
|
614
|
+
placeholderKey: "form.serverPassword.placeholder",
|
|
615
|
+
control: "password"
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
homePath: {
|
|
619
|
+
type: "string",
|
|
620
|
+
"x-ycodium-form": {
|
|
621
|
+
titleKey: "form.homePath.title",
|
|
622
|
+
descriptionKey: "form.homePath.description",
|
|
623
|
+
placeholderKey: "form.homePath.placeholder"
|
|
624
|
+
}
|
|
625
|
+
},
|
|
597
626
|
customModels: { type: "array" },
|
|
598
627
|
driver: { type: "string" },
|
|
599
628
|
config: { type: "object" },
|
|
@@ -602,29 +631,26 @@ var OPENCODE_CARD = {
|
|
|
602
631
|
additionalProperties: true
|
|
603
632
|
},
|
|
604
633
|
modelConnectivity: {
|
|
605
|
-
//
|
|
606
|
-
// `/chat/completions
|
|
607
|
-
// 不算——投递不换这一栏。别家的脑经宿主翻译接上;打到别的路由的请求,本机端点按那一笔
|
|
608
|
-
// 的路径另挑翻译对。
|
|
634
|
+
// 只报下面那段配置说的格式:它把 `npm` 定死成 openai-compatible,后缀是
|
|
635
|
+
// `/chat/completions`,请求说 chat。换 `@ai-sdk/anthropic` 能说 messages 不算。
|
|
609
636
|
dialects: ["openai-chat-completions"],
|
|
610
637
|
acceptsExternalEndpoints: true,
|
|
611
638
|
supportsNativeSubscription: true,
|
|
612
639
|
// opencode 不认「地址一个变量、凭据一个变量」——它读的是
|
|
613
|
-
// `provider.<id>.options.{baseURL,apiKey}
|
|
640
|
+
// `provider.<id>.options.{baseURL,apiKey}`,而给这份配置最干净的路是
|
|
614
641
|
// `OPENCODE_CONFIG_CONTENT`(内联 JSON,压过磁盘上的全局与项目配置)。插件本来就在
|
|
615
|
-
// 设这个变量(`cliParse.ts` 的 `resolveOpenCodeConfigContent`),默认 `{}
|
|
642
|
+
// 设这个变量(`cliParse.ts` 的 `resolveOpenCodeConfigContent`),默认 `{}`,
|
|
643
|
+
// 机器环境里已有的值不覆盖。
|
|
616
644
|
//
|
|
617
645
|
// `npm: "@ai-sdk/openai-compatible"` 定死它说 chat-completions;换成
|
|
618
|
-
// `@ai-sdk/anthropic` 就是 messages——那时后缀与 `dialects`
|
|
619
|
-
// 认手说的方言,兼容判定据此挑直通还是翻译。
|
|
646
|
+
// `@ai-sdk/anthropic` 就是 messages——那时后缀与 `dialects` 要跟着一起换。
|
|
620
647
|
//
|
|
621
|
-
// **还有三层压在这个变量之上**:org 远程配置、`/etc/opencode/`、macOS MDM
|
|
622
|
-
// 代理时宿主会 logWarning(`provider.proxy.never-reached`)。
|
|
648
|
+
// **还有三层压在这个变量之上**:org 远程配置、`/etc/opencode/`、macOS MDM。
|
|
623
649
|
nativePathSuffix: "/chat/completions",
|
|
624
650
|
extraEnv: [
|
|
625
651
|
{
|
|
626
652
|
name: "OPENCODE_CONFIG_CONTENT",
|
|
627
|
-
value:
|
|
653
|
+
value: '{"provider":{"ycodium":{"npm":"@ai-sdk/openai-compatible","name":"Ycodium","options":{"baseURL":"$baseUrl","apiKey":"$credential"},"models":{"$model":{"name":"$model"}}}},"model":"ycodium/$model"}'
|
|
628
654
|
}
|
|
629
655
|
]
|
|
630
656
|
}
|
|
@@ -1194,7 +1220,7 @@ function isOpenCodeDefaultTitle(title) {
|
|
|
1194
1220
|
return OPENCODE_DEFAULT_TITLE_PATTERN.test(title);
|
|
1195
1221
|
}
|
|
1196
1222
|
function parseGenericCliVersion(output) {
|
|
1197
|
-
const match = output.match(/\
|
|
1223
|
+
const match = output.match(/\bv?(\d+\.\d+\.\d+)\b/);
|
|
1198
1224
|
return match?.[1] ?? null;
|
|
1199
1225
|
}
|
|
1200
1226
|
function compareSemverVersions(left, right) {
|
|
@@ -1263,12 +1289,6 @@ function modelIdFromSelection(selection) {
|
|
|
1263
1289
|
return typeof model === "string" ? model.trim() || void 0 : void 0;
|
|
1264
1290
|
}
|
|
1265
1291
|
function chooseOpenCodeModel(input) {
|
|
1266
|
-
if (input.boundModelId !== void 0) {
|
|
1267
|
-
const bound = input.match(input.requested, [
|
|
1268
|
-
`${OPENCODE_BINDING_PROVIDER_ID}/${input.boundModelId}`
|
|
1269
|
-
]);
|
|
1270
|
-
return parseOpenCodeModelSlug(bound) ?? void 0;
|
|
1271
|
-
}
|
|
1272
1292
|
const own = parseOpenCodeModelSlug(input.requested);
|
|
1273
1293
|
if (own) return own;
|
|
1274
1294
|
input.match(input.requested, []);
|
|
@@ -1375,6 +1395,22 @@ function openCodeProbeModels(inventory) {
|
|
|
1375
1395
|
...model.capabilities.optionDescriptors.length > 0 ? { capabilities: model.capabilities } : {}
|
|
1376
1396
|
}));
|
|
1377
1397
|
}
|
|
1398
|
+
function flattenOpenCodeSkills(skills) {
|
|
1399
|
+
const flattened = [];
|
|
1400
|
+
for (const skill of skills ?? []) {
|
|
1401
|
+
const name = nonEmptyTrimmed(skill.name);
|
|
1402
|
+
const path = nonEmptyTrimmed(skill.location);
|
|
1403
|
+
if (!name || !path) continue;
|
|
1404
|
+
const description = nonEmptyTrimmed(skill.description);
|
|
1405
|
+
flattened.push({
|
|
1406
|
+
name,
|
|
1407
|
+
path,
|
|
1408
|
+
enabled: true,
|
|
1409
|
+
...description ? { description, shortDescription: description } : {}
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
return flattened.toSorted((left, right) => left.name.localeCompare(right.name));
|
|
1413
|
+
}
|
|
1378
1414
|
function formatOpenCodeProbeError(input) {
|
|
1379
1415
|
const raw = toMessage(input.cause, String(input.cause));
|
|
1380
1416
|
const detail = hideGenericEffectText(raw);
|
|
@@ -1532,6 +1568,7 @@ function mapPermissionDecision(reply) {
|
|
|
1532
1568
|
}
|
|
1533
1569
|
|
|
1534
1570
|
// src/probe.ts
|
|
1571
|
+
import * as NodeOS4 from "node:os";
|
|
1535
1572
|
import {
|
|
1536
1573
|
ExecutorSpawnRefusedError as ExecutorSpawnRefusedError2
|
|
1537
1574
|
} from "@ycodium-ai/plugin-api/executor";
|
|
@@ -6946,8 +6983,7 @@ var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
|
6946
6983
|
// src/server.ts
|
|
6947
6984
|
import {
|
|
6948
6985
|
ExecutorSpawnRefusedError,
|
|
6949
|
-
mergeLaunchEnv
|
|
6950
|
-
brainSlotEnvKeys
|
|
6986
|
+
mergeLaunchEnv
|
|
6951
6987
|
} from "@ycodium-ai/plugin-api/executor";
|
|
6952
6988
|
|
|
6953
6989
|
// src/cliParse.ts
|
|
@@ -6959,8 +6995,8 @@ var OPENCODE_EMPTY_CONFIG_CONTENT = "{}";
|
|
|
6959
6995
|
var SLUG_LINE_RE = /^(\S+\/\S+)\s*$/;
|
|
6960
6996
|
var AGENT_HEADER_RE = /^(.+)\s+\((\S+)\)\s*$/;
|
|
6961
6997
|
var KNOWN_HIDDEN_AGENTS = /* @__PURE__ */ new Set(["compaction", "summary", "title"]);
|
|
6962
|
-
function resolveOpenCodeConfigContent(
|
|
6963
|
-
return
|
|
6998
|
+
function resolveOpenCodeConfigContent(inheritedEnvironment) {
|
|
6999
|
+
return inheritedEnvironment.OPENCODE_CONFIG_CONTENT ?? OPENCODE_EMPTY_CONFIG_CONTENT;
|
|
6964
7000
|
}
|
|
6965
7001
|
function parseServerUrlFromOutput(output) {
|
|
6966
7002
|
for (const line of output.split("\n")) {
|
|
@@ -7105,19 +7141,14 @@ async function findAvailablePort() {
|
|
|
7105
7141
|
});
|
|
7106
7142
|
});
|
|
7107
7143
|
}
|
|
7108
|
-
function buildSpawnEnv(
|
|
7109
|
-
const xdgHome = makeOpenCodeEnvironment(
|
|
7144
|
+
function buildSpawnEnv(recipe) {
|
|
7145
|
+
const xdgHome = makeOpenCodeEnvironment(recipe.homePath, {});
|
|
7110
7146
|
return mergeLaunchEnv({
|
|
7111
|
-
brainSlots: brainSlotEnvKeys(OPENCODE_CARD),
|
|
7112
7147
|
accountHome: xdgHome,
|
|
7113
|
-
instanceTable:
|
|
7148
|
+
instanceTable: recipe.environment,
|
|
7114
7149
|
handOverrides: {
|
|
7115
|
-
OPENCODE_CONFIG_CONTENT: resolveOpenCodeConfigContent(
|
|
7116
|
-
|
|
7117
|
-
input.processEnv ?? process.env
|
|
7118
|
-
)
|
|
7119
|
-
},
|
|
7120
|
-
launch: input.processEnv
|
|
7150
|
+
OPENCODE_CONFIG_CONTENT: resolveOpenCodeConfigContent(process.env)
|
|
7151
|
+
}
|
|
7121
7152
|
});
|
|
7122
7153
|
}
|
|
7123
7154
|
async function terminateOwnedProcess(handle) {
|
|
@@ -7125,12 +7156,13 @@ async function terminateOwnedProcess(handle) {
|
|
|
7125
7156
|
await handle.kill("SIGTERM");
|
|
7126
7157
|
} catch {
|
|
7127
7158
|
}
|
|
7159
|
+
let timer;
|
|
7128
7160
|
const timed = await Promise.race([
|
|
7129
7161
|
handle.exited.then(() => "exited"),
|
|
7130
7162
|
new Promise((resolve2) => {
|
|
7131
|
-
setTimeout(() => resolve2("timeout"), 2e3);
|
|
7163
|
+
timer = setTimeout(() => resolve2("timeout"), 2e3);
|
|
7132
7164
|
})
|
|
7133
|
-
]);
|
|
7165
|
+
]).finally(() => clearTimeout(timer));
|
|
7134
7166
|
if (timed === "timeout") {
|
|
7135
7167
|
try {
|
|
7136
7168
|
await handle.kill("SIGKILL");
|
|
@@ -7142,13 +7174,13 @@ async function terminateOwnedProcess(handle) {
|
|
|
7142
7174
|
} catch {
|
|
7143
7175
|
}
|
|
7144
7176
|
}
|
|
7145
|
-
await handle.exited
|
|
7177
|
+
await handle.exited;
|
|
7146
7178
|
}
|
|
7147
7179
|
}
|
|
7148
7180
|
async function spawnOpenCodeServer(input) {
|
|
7149
7181
|
const port = await findAvailablePort();
|
|
7150
7182
|
const hostname = DEFAULT_HOSTNAME;
|
|
7151
|
-
const env = buildSpawnEnv(
|
|
7183
|
+
const env = buildSpawnEnv(input.recipe);
|
|
7152
7184
|
const spawned = await input.host.process.spawn({
|
|
7153
7185
|
program: input.program,
|
|
7154
7186
|
args: ["serve", `--hostname=${hostname}`, `--port=${port}`],
|
|
@@ -7161,6 +7193,7 @@ async function spawnOpenCodeServer(input) {
|
|
|
7161
7193
|
kill: spawned.kill,
|
|
7162
7194
|
exited: spawned.exited
|
|
7163
7195
|
};
|
|
7196
|
+
input.onSpawn?.({ external: false, process: processHandle });
|
|
7164
7197
|
const timeoutMs = input.timeoutMs ?? DEFAULT_OPENCODE_SERVER_TIMEOUT_MS;
|
|
7165
7198
|
let stdoutText = "";
|
|
7166
7199
|
let settled = false;
|
|
@@ -7168,7 +7201,7 @@ async function spawnOpenCodeServer(input) {
|
|
|
7168
7201
|
const fail = (cause) => {
|
|
7169
7202
|
if (settled) return;
|
|
7170
7203
|
settled = true;
|
|
7171
|
-
|
|
7204
|
+
clearTimeout(timer);
|
|
7172
7205
|
reject(cause instanceof Error ? cause : new Error(String(cause)));
|
|
7173
7206
|
};
|
|
7174
7207
|
const timer = setTimeout(() => {
|
|
@@ -7181,14 +7214,13 @@ async function spawnOpenCodeServer(input) {
|
|
|
7181
7214
|
void (async () => {
|
|
7182
7215
|
try {
|
|
7183
7216
|
for await (const chunk of spawned.stdout) {
|
|
7217
|
+
if (settled) continue;
|
|
7184
7218
|
stdoutText += Buffer.from(chunk).toString("utf8");
|
|
7185
7219
|
const parsed = parseServerUrlFromOutput(stdoutText);
|
|
7186
7220
|
if (parsed) {
|
|
7187
|
-
if (settled) return;
|
|
7188
7221
|
settled = true;
|
|
7189
7222
|
clearTimeout(timer);
|
|
7190
7223
|
resolve2(parsed);
|
|
7191
|
-
return;
|
|
7192
7224
|
}
|
|
7193
7225
|
}
|
|
7194
7226
|
fail(
|
|
@@ -7198,11 +7230,21 @@ async function spawnOpenCodeServer(input) {
|
|
|
7198
7230
|
fail(cause);
|
|
7199
7231
|
}
|
|
7200
7232
|
})();
|
|
7201
|
-
void
|
|
7202
|
-
|
|
7203
|
-
|
|
7233
|
+
void (async () => {
|
|
7234
|
+
try {
|
|
7235
|
+
for await (const chunk of spawned.stderr) {
|
|
7236
|
+
void chunk;
|
|
7237
|
+
}
|
|
7238
|
+
} catch (cause) {
|
|
7239
|
+
fail(cause);
|
|
7204
7240
|
}
|
|
7205
|
-
});
|
|
7241
|
+
})();
|
|
7242
|
+
void spawned.exited.then((code) => {
|
|
7243
|
+
fail(new Error(`OpenCode server exited with code ${code}. stdout=${stdoutText.trim()}`));
|
|
7244
|
+
}, fail);
|
|
7245
|
+
}).catch(async (cause) => {
|
|
7246
|
+
await terminateOwnedProcess(processHandle);
|
|
7247
|
+
throw cause;
|
|
7206
7248
|
});
|
|
7207
7249
|
return {
|
|
7208
7250
|
url,
|
|
@@ -7230,9 +7272,9 @@ async function connectToOpenCodeServer(input) {
|
|
|
7230
7272
|
return spawnOpenCodeServer({
|
|
7231
7273
|
host: input.host,
|
|
7232
7274
|
recipe: input.recipe,
|
|
7233
|
-
processEnv: input.processEnv,
|
|
7234
7275
|
directory: input.directory,
|
|
7235
|
-
program
|
|
7276
|
+
program,
|
|
7277
|
+
...input.onSpawn === void 0 ? {} : { onSpawn: input.onSpawn }
|
|
7236
7278
|
});
|
|
7237
7279
|
}
|
|
7238
7280
|
async function closeOpenCodeServer(handle) {
|
|
@@ -7253,7 +7295,7 @@ function createOpenCodeSdkClient(input) {
|
|
|
7253
7295
|
});
|
|
7254
7296
|
}
|
|
7255
7297
|
async function runOpenCodeCommand(input) {
|
|
7256
|
-
const env = buildSpawnEnv(
|
|
7298
|
+
const env = buildSpawnEnv(input.recipe);
|
|
7257
7299
|
const spawned = await input.host.process.spawn({
|
|
7258
7300
|
program: input.program,
|
|
7259
7301
|
args: [...input.args],
|
|
@@ -7292,13 +7334,12 @@ function inventoryFromCli(models, agents, skills) {
|
|
|
7292
7334
|
};
|
|
7293
7335
|
}
|
|
7294
7336
|
async function loadInventoryFromCli(input) {
|
|
7295
|
-
const run = (args, maxOutputBytes) => runOpenCodeCommand({
|
|
7337
|
+
const run = (args, maxOutputBytes, cwd = input.cwd) => runOpenCodeCommand({
|
|
7296
7338
|
host: input.host,
|
|
7297
7339
|
recipe: input.recipe,
|
|
7298
|
-
...input.processEnv ? { processEnv: input.processEnv } : {},
|
|
7299
7340
|
program: input.program,
|
|
7300
7341
|
args,
|
|
7301
|
-
...
|
|
7342
|
+
...cwd ? { cwd } : {},
|
|
7302
7343
|
...maxOutputBytes !== void 0 ? { maxOutputBytes } : {}
|
|
7303
7344
|
});
|
|
7304
7345
|
const modelsRun = async () => {
|
|
@@ -7331,7 +7372,11 @@ async function loadInventoryFromCli(input) {
|
|
|
7331
7372
|
const skillsRun = async () => {
|
|
7332
7373
|
try {
|
|
7333
7374
|
const result = await withOneSecondRetry(async () => {
|
|
7334
|
-
const command = await run(
|
|
7375
|
+
const command = await run(
|
|
7376
|
+
["debug", "skill"],
|
|
7377
|
+
OPENCODE_SKILL_DISCOVERY_MAX_OUTPUT_BYTES,
|
|
7378
|
+
input.skillsCwd ?? input.cwd
|
|
7379
|
+
);
|
|
7335
7380
|
if (command.exitCode !== 0) {
|
|
7336
7381
|
throw new Error(`opencode debug skill exited ${command.exitCode}`);
|
|
7337
7382
|
}
|
|
@@ -7346,7 +7391,7 @@ async function loadInventoryFromCli(input) {
|
|
|
7346
7391
|
const [models, agents, skills] = await Promise.all([modelsRun(), agentsRun(), skillsRun()]);
|
|
7347
7392
|
return inventoryFromCli(models, agents, skills);
|
|
7348
7393
|
}
|
|
7349
|
-
async function loadOpenCodeInventory(client2) {
|
|
7394
|
+
async function loadOpenCodeInventory(client2, skillsClient = client2) {
|
|
7350
7395
|
const listed = await client2.provider.list();
|
|
7351
7396
|
const providerList = listed.data;
|
|
7352
7397
|
if (!providerList) {
|
|
@@ -7361,7 +7406,7 @@ async function loadOpenCodeInventory(client2) {
|
|
|
7361
7406
|
}
|
|
7362
7407
|
let skills = [];
|
|
7363
7408
|
try {
|
|
7364
|
-
const listedSkills = await
|
|
7409
|
+
const listedSkills = await skillsClient.app.skills();
|
|
7365
7410
|
skills = (listedSkills.data ?? []).map((skill) => ({
|
|
7366
7411
|
name: skill.name,
|
|
7367
7412
|
...skill.description !== void 0 ? { description: skill.description } : {},
|
|
@@ -7421,7 +7466,6 @@ async function probeOpenCode(input) {
|
|
|
7421
7466
|
const result = await runOpenCodeCommand({
|
|
7422
7467
|
host: input.host,
|
|
7423
7468
|
recipe: input.recipe,
|
|
7424
|
-
...input.processEnv ? { processEnv: input.processEnv } : {},
|
|
7425
7469
|
program,
|
|
7426
7470
|
args: ["--version"]
|
|
7427
7471
|
});
|
|
@@ -7447,7 +7491,6 @@ ${result.stderr}`);
|
|
|
7447
7491
|
const handle = await connectToOpenCodeServer({
|
|
7448
7492
|
host: input.host,
|
|
7449
7493
|
recipe: input.recipe,
|
|
7450
|
-
processEnv: input.processEnv ?? void 0,
|
|
7451
7494
|
directory: "."
|
|
7452
7495
|
});
|
|
7453
7496
|
try {
|
|
@@ -7456,7 +7499,13 @@ ${result.stderr}`);
|
|
|
7456
7499
|
directory: ".",
|
|
7457
7500
|
password: handle.password
|
|
7458
7501
|
});
|
|
7459
|
-
const
|
|
7502
|
+
const skillsClient = createOpenCodeSdkClient({
|
|
7503
|
+
url: handle.url,
|
|
7504
|
+
directory: NodeOS4.homedir(),
|
|
7505
|
+
password: handle.password
|
|
7506
|
+
});
|
|
7507
|
+
const inventory2 = await loadOpenCodeInventory(client2, skillsClient);
|
|
7508
|
+
const skills2 = flattenOpenCodeSkills(inventory2.skills);
|
|
7460
7509
|
const connectedCount2 = inventory2.providerList.connected.length;
|
|
7461
7510
|
if (connectedCount2 > 0) {
|
|
7462
7511
|
return {
|
|
@@ -7465,6 +7514,7 @@ ${result.stderr}`);
|
|
|
7465
7514
|
readiness: "ready",
|
|
7466
7515
|
auth: { status: "authenticated", type: "opencode" },
|
|
7467
7516
|
models: openCodeProbeModels(inventory2),
|
|
7517
|
+
skills: skills2,
|
|
7468
7518
|
...OPENCODE_NATIVE_MODE_REPORT
|
|
7469
7519
|
};
|
|
7470
7520
|
}
|
|
@@ -7473,6 +7523,7 @@ ${result.stderr}`);
|
|
|
7473
7523
|
version,
|
|
7474
7524
|
readiness: "error",
|
|
7475
7525
|
auth: { status: "unauthenticated" },
|
|
7526
|
+
skills: skills2,
|
|
7476
7527
|
...OPENCODE_NATIVE_MODE_REPORT
|
|
7477
7528
|
};
|
|
7478
7529
|
} finally {
|
|
@@ -7482,9 +7533,10 @@ ${result.stderr}`);
|
|
|
7482
7533
|
const inventory = await loadInventoryFromCli({
|
|
7483
7534
|
host: input.host,
|
|
7484
7535
|
recipe: input.recipe,
|
|
7485
|
-
|
|
7486
|
-
|
|
7536
|
+
program,
|
|
7537
|
+
skillsCwd: NodeOS4.homedir()
|
|
7487
7538
|
});
|
|
7539
|
+
const skills = flattenOpenCodeSkills(inventory.skills);
|
|
7488
7540
|
const connectedCount = inventory.providerList.connected.length;
|
|
7489
7541
|
if (connectedCount > 0) {
|
|
7490
7542
|
return {
|
|
@@ -7493,6 +7545,7 @@ ${result.stderr}`);
|
|
|
7493
7545
|
readiness: "ready",
|
|
7494
7546
|
auth: { status: "authenticated", type: "opencode" },
|
|
7495
7547
|
models: openCodeProbeModels(inventory),
|
|
7548
|
+
skills,
|
|
7496
7549
|
...OPENCODE_NATIVE_MODE_REPORT
|
|
7497
7550
|
};
|
|
7498
7551
|
}
|
|
@@ -7501,6 +7554,7 @@ ${result.stderr}`);
|
|
|
7501
7554
|
version,
|
|
7502
7555
|
readiness: "error",
|
|
7503
7556
|
auth: { status: "unauthenticated" },
|
|
7557
|
+
skills,
|
|
7504
7558
|
...OPENCODE_NATIVE_MODE_REPORT
|
|
7505
7559
|
};
|
|
7506
7560
|
} catch (cause) {
|
|
@@ -8540,7 +8594,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8540
8594
|
const handle = await connectToOpenCodeServer({
|
|
8541
8595
|
host,
|
|
8542
8596
|
recipe,
|
|
8543
|
-
processEnv: input.processEnv,
|
|
8544
8597
|
directory: input.cwd
|
|
8545
8598
|
});
|
|
8546
8599
|
shared.handle = handle;
|
|
@@ -8563,7 +8616,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8563
8616
|
const handle = await connectToOpenCodeServer({
|
|
8564
8617
|
host,
|
|
8565
8618
|
recipe,
|
|
8566
|
-
processEnv: input.processEnv,
|
|
8567
8619
|
directory: input.cwd,
|
|
8568
8620
|
program
|
|
8569
8621
|
});
|
|
@@ -8589,15 +8641,10 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8589
8641
|
const runOpenCodeJson = async (input) => {
|
|
8590
8642
|
const agent = getModelSelectionStringOptionValue(input.modelSelection, "agent");
|
|
8591
8643
|
const variant = getModelSelectionStringOptionValue(input.modelSelection, "variant");
|
|
8592
|
-
const client2 = await acquireClient({
|
|
8593
|
-
cwd: input.cwd,
|
|
8594
|
-
...input.launch?.processEnv ? { processEnv: input.launch.processEnv } : {}
|
|
8595
|
-
});
|
|
8644
|
+
const client2 = await acquireClient({ cwd: input.cwd });
|
|
8596
8645
|
try {
|
|
8597
|
-
const boundModelId = input.launch?.requestedModelId?.trim() || void 0;
|
|
8598
8646
|
const model = chooseOpenCodeModel({
|
|
8599
|
-
requested:
|
|
8600
|
-
boundModelId,
|
|
8647
|
+
requested: modelIdFromSelection(input.modelSelection) ?? "openai/gpt-5",
|
|
8601
8648
|
match: matchModel
|
|
8602
8649
|
});
|
|
8603
8650
|
if (input.signal?.aborted) {
|
|
@@ -8654,7 +8701,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8654
8701
|
prompt,
|
|
8655
8702
|
schemaKeys: includeBranch ? ["subject", "body", "branch"] : ["subject", "body"],
|
|
8656
8703
|
modelSelection: input["modelSelection"],
|
|
8657
|
-
...isRecord2(input["launch"]) ? { launch: input["launch"] } : {},
|
|
8658
8704
|
...signal === void 0 ? {} : { signal }
|
|
8659
8705
|
});
|
|
8660
8706
|
return {
|
|
@@ -8684,7 +8730,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8684
8730
|
prompt,
|
|
8685
8731
|
schemaKeys: ["title", "body"],
|
|
8686
8732
|
modelSelection: input["modelSelection"],
|
|
8687
|
-
...isRecord2(input["launch"]) ? { launch: input["launch"] } : {},
|
|
8688
8733
|
...signal === void 0 ? {} : { signal }
|
|
8689
8734
|
});
|
|
8690
8735
|
return {
|
|
@@ -8709,7 +8754,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8709
8754
|
prompt,
|
|
8710
8755
|
schemaKeys: ["branch"],
|
|
8711
8756
|
modelSelection: input["modelSelection"],
|
|
8712
|
-
...isRecord2(input["launch"]) ? { launch: input["launch"] } : {},
|
|
8713
8757
|
...signal === void 0 ? {} : { signal }
|
|
8714
8758
|
});
|
|
8715
8759
|
return { branch: sanitizeBranchFragment(readString3(generated["branch"])) };
|
|
@@ -8732,7 +8776,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8732
8776
|
prompt,
|
|
8733
8777
|
schemaKeys: ["title"],
|
|
8734
8778
|
modelSelection: input["modelSelection"],
|
|
8735
|
-
...isRecord2(input["launch"]) ? { launch: input["launch"] } : {},
|
|
8736
8779
|
...signal === void 0 ? {} : { signal }
|
|
8737
8780
|
});
|
|
8738
8781
|
return { title: sanitizeThreadTitle(readString3(generated["title"])) };
|
|
@@ -8752,7 +8795,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8752
8795
|
prompt,
|
|
8753
8796
|
schemaKeys: ["summary"],
|
|
8754
8797
|
modelSelection: input["modelSelection"],
|
|
8755
|
-
...isRecord2(input["launch"]) ? { launch: input["launch"] } : {},
|
|
8756
8798
|
...signal === void 0 ? {} : { signal }
|
|
8757
8799
|
});
|
|
8758
8800
|
return { summary: readString3(generated["summary"]).trim() };
|
|
@@ -8778,9 +8820,31 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
8778
8820
|
const recipe = parseOpenCodeInstanceConfig(config);
|
|
8779
8821
|
const events = new EventBus();
|
|
8780
8822
|
const sessions = /* @__PURE__ */ new Map();
|
|
8823
|
+
const pendingServers = /* @__PURE__ */ new Map();
|
|
8824
|
+
const stops = /* @__PURE__ */ new WeakMap();
|
|
8825
|
+
const rememberPendingServer = (threadId, server) => {
|
|
8826
|
+
const pending = pendingServers.get(threadId) ?? /* @__PURE__ */ new Set();
|
|
8827
|
+
pending.add(server);
|
|
8828
|
+
pendingServers.set(threadId, pending);
|
|
8829
|
+
};
|
|
8830
|
+
const forgetPendingServer = (threadId, server) => {
|
|
8831
|
+
const pending = pendingServers.get(threadId);
|
|
8832
|
+
pending?.delete(server);
|
|
8833
|
+
if (pending?.size === 0) pendingServers.delete(threadId);
|
|
8834
|
+
};
|
|
8835
|
+
const closePendingServer = async (threadId, server) => {
|
|
8836
|
+
await closeOpenCodeServer(server);
|
|
8837
|
+
forgetPendingServer(threadId, server);
|
|
8838
|
+
};
|
|
8839
|
+
const closePendingServers = async (threadId) => {
|
|
8840
|
+
for (const server of [...pendingServers.get(threadId) ?? []]) {
|
|
8841
|
+
await closePendingServer(threadId, server);
|
|
8842
|
+
}
|
|
8843
|
+
};
|
|
8781
8844
|
const declineRelay = makeDeclineReasonRelay();
|
|
8782
8845
|
const boundInstanceId = host.instanceId;
|
|
8783
8846
|
let disposed = false;
|
|
8847
|
+
let disposal;
|
|
8784
8848
|
let textGeneration;
|
|
8785
8849
|
const requireSession = (threadId) => {
|
|
8786
8850
|
const context = sessions.get(threadId);
|
|
@@ -8800,28 +8864,38 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
8800
8864
|
await closeOpenCodeServer(context.server);
|
|
8801
8865
|
};
|
|
8802
8866
|
const stopContext = async (context, reason, message) => {
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8867
|
+
const pending = stops.get(context);
|
|
8868
|
+
if (pending) return pending;
|
|
8869
|
+
const work = (async () => {
|
|
8870
|
+
context.stopped = true;
|
|
8871
|
+
context.eventAbort.abort();
|
|
8872
|
+
try {
|
|
8873
|
+
await context.client.session.abort({
|
|
8874
|
+
sessionID: context.sessionId,
|
|
8875
|
+
directory: context.directory
|
|
8876
|
+
});
|
|
8877
|
+
} catch {
|
|
8878
|
+
}
|
|
8879
|
+
await closeOpenCodeServer(context.server);
|
|
8880
|
+
await context.pump?.catch(() => void 0);
|
|
8881
|
+
await context.serverWatch?.catch(() => void 0);
|
|
8882
|
+
if (reason === "graceful") {
|
|
8883
|
+
emitEvent(events, context, "session.exited", {
|
|
8884
|
+
reason: message ?? "Session stopped.",
|
|
8885
|
+
recoverable: false,
|
|
8886
|
+
exitKind: "graceful"
|
|
8887
|
+
});
|
|
8888
|
+
context.session = { ...context.session, status: "stopped", updatedAt: nowIso() };
|
|
8889
|
+
} else {
|
|
8890
|
+
emitUnexpectedExit(events, context, new Error(message ?? "OpenCode session failed."));
|
|
8891
|
+
}
|
|
8892
|
+
})();
|
|
8893
|
+
stops.set(context, work);
|
|
8806
8894
|
try {
|
|
8807
|
-
await
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
} catch {
|
|
8812
|
-
}
|
|
8813
|
-
await closeOpenCodeServer(context.server);
|
|
8814
|
-
await context.pump?.catch(() => void 0);
|
|
8815
|
-
await context.serverWatch?.catch(() => void 0);
|
|
8816
|
-
if (reason === "graceful") {
|
|
8817
|
-
emitEvent(events, context, "session.exited", {
|
|
8818
|
-
reason: message ?? "Session stopped.",
|
|
8819
|
-
recoverable: false,
|
|
8820
|
-
exitKind: "graceful"
|
|
8821
|
-
});
|
|
8822
|
-
context.session = { ...context.session, status: "stopped", updatedAt: nowIso() };
|
|
8823
|
-
} else {
|
|
8824
|
-
emitUnexpectedExit(events, context, new Error(message ?? "OpenCode session failed."));
|
|
8895
|
+
await work;
|
|
8896
|
+
} catch (cause) {
|
|
8897
|
+
stops.delete(context);
|
|
8898
|
+
throw cause;
|
|
8825
8899
|
}
|
|
8826
8900
|
};
|
|
8827
8901
|
const instance = {
|
|
@@ -8837,65 +8911,84 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
8837
8911
|
await stopContext(existing, "graceful", "Replaced by a new session.");
|
|
8838
8912
|
sessions.delete(input.threadId);
|
|
8839
8913
|
}
|
|
8914
|
+
await closePendingServers(input.threadId);
|
|
8840
8915
|
const directory = requireCwd(input, host);
|
|
8916
|
+
let startingServer;
|
|
8841
8917
|
const server = await connectToOpenCodeServer({
|
|
8842
8918
|
host,
|
|
8843
8919
|
recipe,
|
|
8844
|
-
processEnv: input.launch.processEnv,
|
|
8845
8920
|
directory,
|
|
8846
|
-
program: recipe.binaryPath
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
|
|
8851
|
-
password: server.password
|
|
8921
|
+
program: recipe.binaryPath,
|
|
8922
|
+
onSpawn: (resource) => {
|
|
8923
|
+
startingServer = resource;
|
|
8924
|
+
rememberPendingServer(input.threadId, resource);
|
|
8925
|
+
}
|
|
8852
8926
|
});
|
|
8853
|
-
|
|
8854
|
-
|
|
8855
|
-
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
|
|
8859
|
-
|
|
8860
|
-
|
|
8861
|
-
|
|
8862
|
-
|
|
8863
|
-
|
|
8864
|
-
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
if (await isSameOpenCodeDirectory(storedDirectory, directory)) {
|
|
8871
|
-
await client2.session.update({
|
|
8872
|
-
sessionID: info.id,
|
|
8873
|
-
directory,
|
|
8874
|
-
permission
|
|
8875
|
-
});
|
|
8876
|
-
sessionId = info.id;
|
|
8877
|
-
} else {
|
|
8878
|
-
const forked = await client2.session.fork({
|
|
8879
|
-
sessionID: info.id,
|
|
8927
|
+
if (startingServer !== void 0) forgetPendingServer(input.threadId, startingServer);
|
|
8928
|
+
try {
|
|
8929
|
+
const client2 = createOpenCodeSdkClient({
|
|
8930
|
+
url: server.url,
|
|
8931
|
+
directory,
|
|
8932
|
+
password: server.password
|
|
8933
|
+
});
|
|
8934
|
+
const nativeModeId = openCodeNativeModeFor(input.runtimeMode, input.nativeModeId);
|
|
8935
|
+
const permission = openCodePermissionRulesForNativeMode(nativeModeId);
|
|
8936
|
+
const resume = input.discardResumeCursor === true ? void 0 : parseOpenCodeResume(input.resumeCursor);
|
|
8937
|
+
let sessionId;
|
|
8938
|
+
let createdSession = false;
|
|
8939
|
+
const requestedTitle = input.title?.trim();
|
|
8940
|
+
if (resume) {
|
|
8941
|
+
try {
|
|
8942
|
+
const existingSession = await client2.session.get({
|
|
8943
|
+
sessionID: resume.sessionId,
|
|
8880
8944
|
directory
|
|
8881
8945
|
});
|
|
8882
|
-
const
|
|
8883
|
-
if (!
|
|
8884
|
-
throw new Error("OpenCode session.
|
|
8946
|
+
const info = existingSession.data;
|
|
8947
|
+
if (!info) {
|
|
8948
|
+
throw new Error("OpenCode session.get returned no data.");
|
|
8949
|
+
}
|
|
8950
|
+
const storedDirectory = info.directory ?? info.path ?? directory;
|
|
8951
|
+
if (await isSameOpenCodeDirectory(storedDirectory, directory)) {
|
|
8952
|
+
await client2.session.update({
|
|
8953
|
+
sessionID: info.id,
|
|
8954
|
+
directory,
|
|
8955
|
+
permission
|
|
8956
|
+
});
|
|
8957
|
+
sessionId = info.id;
|
|
8958
|
+
} else {
|
|
8959
|
+
const forked = await client2.session.fork({
|
|
8960
|
+
sessionID: info.id,
|
|
8961
|
+
directory
|
|
8962
|
+
});
|
|
8963
|
+
const forkedInfo = forked.data;
|
|
8964
|
+
if (!forkedInfo) {
|
|
8965
|
+
throw new Error("OpenCode session.fork returned no data.");
|
|
8966
|
+
}
|
|
8967
|
+
await client2.session.update({
|
|
8968
|
+
sessionID: forkedInfo.id,
|
|
8969
|
+
directory,
|
|
8970
|
+
permission
|
|
8971
|
+
});
|
|
8972
|
+
sessionId = forkedInfo.id;
|
|
8973
|
+
createdSession = true;
|
|
8974
|
+
}
|
|
8975
|
+
} catch (cause) {
|
|
8976
|
+
if (!isOpenCodeNotFound(cause)) {
|
|
8977
|
+
throw cause;
|
|
8885
8978
|
}
|
|
8886
|
-
await client2.session.
|
|
8887
|
-
sessionID: forkedInfo.id,
|
|
8979
|
+
const created = await client2.session.create({
|
|
8888
8980
|
directory,
|
|
8889
|
-
permission
|
|
8981
|
+
permission,
|
|
8982
|
+
...requestedTitle ? { title: requestedTitle } : {}
|
|
8890
8983
|
});
|
|
8891
|
-
|
|
8984
|
+
const info = created.data;
|
|
8985
|
+
if (!info) {
|
|
8986
|
+
throw new Error("OpenCode session.create returned no data.", { cause });
|
|
8987
|
+
}
|
|
8988
|
+
sessionId = info.id;
|
|
8892
8989
|
createdSession = true;
|
|
8893
8990
|
}
|
|
8894
|
-
}
|
|
8895
|
-
if (!isOpenCodeNotFound(cause)) {
|
|
8896
|
-
await closeOpenCodeServer(server);
|
|
8897
|
-
throw cause;
|
|
8898
|
-
}
|
|
8991
|
+
} else {
|
|
8899
8992
|
const created = await client2.session.create({
|
|
8900
8993
|
directory,
|
|
8901
8994
|
permission,
|
|
@@ -8903,90 +8996,79 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
8903
8996
|
});
|
|
8904
8997
|
const info = created.data;
|
|
8905
8998
|
if (!info) {
|
|
8906
|
-
|
|
8907
|
-
throw new Error("OpenCode session.create returned no data.", { cause });
|
|
8999
|
+
throw new Error("OpenCode session.create returned no data.");
|
|
8908
9000
|
}
|
|
8909
9001
|
sessionId = info.id;
|
|
8910
9002
|
createdSession = true;
|
|
8911
9003
|
}
|
|
8912
|
-
|
|
8913
|
-
const
|
|
9004
|
+
const createdAt = nowIso();
|
|
9005
|
+
const resumeCursor = makeOpenCodeResumeCursor(sessionId);
|
|
9006
|
+
const initialModel = modelIdFromSelection(input.modelSelection) ?? readString2(input.modelSelection?.model);
|
|
9007
|
+
const session = {
|
|
9008
|
+
provider: OPENCODE_DRIVER_KIND,
|
|
9009
|
+
providerInstanceId: boundInstanceId,
|
|
9010
|
+
status: "ready",
|
|
9011
|
+
runtimeMode: input.runtimeMode,
|
|
9012
|
+
nativeModeId,
|
|
9013
|
+
cwd: directory,
|
|
9014
|
+
threadId: input.threadId,
|
|
9015
|
+
resumeCursor,
|
|
9016
|
+
createdAt,
|
|
9017
|
+
updatedAt: createdAt,
|
|
9018
|
+
...initialModel ? { model: initialModel } : {}
|
|
9019
|
+
};
|
|
9020
|
+
const context = {
|
|
9021
|
+
threadId: input.threadId,
|
|
9022
|
+
session,
|
|
9023
|
+
sessionId,
|
|
8914
9024
|
directory,
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
|
|
8942
|
-
|
|
8943
|
-
|
|
8944
|
-
|
|
8945
|
-
sessionId,
|
|
8946
|
-
directory,
|
|
8947
|
-
client: client2,
|
|
8948
|
-
server,
|
|
8949
|
-
createdSession,
|
|
8950
|
-
eventAbort: new AbortController(),
|
|
8951
|
-
pump: void 0,
|
|
8952
|
-
serverWatch: void 0,
|
|
8953
|
-
stopped: false,
|
|
8954
|
-
pendingPermissions: /* @__PURE__ */ new Map(),
|
|
8955
|
-
pendingQuestions: /* @__PURE__ */ new Map(),
|
|
8956
|
-
declineReasons: /* @__PURE__ */ new Map(),
|
|
8957
|
-
usageByMessageId: /* @__PURE__ */ new Map(),
|
|
8958
|
-
messageRoleById: /* @__PURE__ */ new Map(),
|
|
8959
|
-
assistantTextByPartId: /* @__PURE__ */ new Map(),
|
|
8960
|
-
partTypeById: /* @__PURE__ */ new Map(),
|
|
8961
|
-
completedTextParts: /* @__PURE__ */ new Set(),
|
|
8962
|
-
startedToolItems: /* @__PURE__ */ new Set(),
|
|
8963
|
-
compaction: void 0,
|
|
8964
|
-
attachmentsApi: attachments,
|
|
8965
|
-
runtimeMode: input.runtimeMode,
|
|
8966
|
-
boundModelId: input.launch.requestedModelId?.trim() || void 0,
|
|
8967
|
-
matchModel: createCatalogModelMatcher2(host.log)
|
|
8968
|
-
};
|
|
8969
|
-
const winner = sessions.get(input.threadId);
|
|
8970
|
-
if (winner) {
|
|
8971
|
-
if (createdSession) {
|
|
8972
|
-
await abortCreatedSession(context);
|
|
8973
|
-
} else {
|
|
8974
|
-
context.eventAbort.abort();
|
|
8975
|
-
await closeOpenCodeServer(server);
|
|
9025
|
+
client: client2,
|
|
9026
|
+
server,
|
|
9027
|
+
createdSession,
|
|
9028
|
+
eventAbort: new AbortController(),
|
|
9029
|
+
pump: void 0,
|
|
9030
|
+
serverWatch: void 0,
|
|
9031
|
+
stopped: false,
|
|
9032
|
+
pendingPermissions: /* @__PURE__ */ new Map(),
|
|
9033
|
+
pendingQuestions: /* @__PURE__ */ new Map(),
|
|
9034
|
+
declineReasons: /* @__PURE__ */ new Map(),
|
|
9035
|
+
usageByMessageId: /* @__PURE__ */ new Map(),
|
|
9036
|
+
messageRoleById: /* @__PURE__ */ new Map(),
|
|
9037
|
+
assistantTextByPartId: /* @__PURE__ */ new Map(),
|
|
9038
|
+
partTypeById: /* @__PURE__ */ new Map(),
|
|
9039
|
+
completedTextParts: /* @__PURE__ */ new Set(),
|
|
9040
|
+
startedToolItems: /* @__PURE__ */ new Set(),
|
|
9041
|
+
compaction: void 0,
|
|
9042
|
+
attachmentsApi: attachments,
|
|
9043
|
+
runtimeMode: input.runtimeMode,
|
|
9044
|
+
matchModel: createCatalogModelMatcher2(host.log)
|
|
9045
|
+
};
|
|
9046
|
+
const winner = sessions.get(input.threadId);
|
|
9047
|
+
if (winner) {
|
|
9048
|
+
if (createdSession) {
|
|
9049
|
+
await abortCreatedSession(context);
|
|
9050
|
+
} else {
|
|
9051
|
+
context.eventAbort.abort();
|
|
9052
|
+
await closeOpenCodeServer(server);
|
|
9053
|
+
}
|
|
9054
|
+
return sessionFromContext(winner);
|
|
8976
9055
|
}
|
|
8977
|
-
|
|
9056
|
+
sessions.set(input.threadId, context);
|
|
9057
|
+
emitEvent(
|
|
9058
|
+
events,
|
|
9059
|
+
context,
|
|
9060
|
+
"session.started",
|
|
9061
|
+
input.resumeCursor !== void 0 ? { resume: input.resumeCursor } : {}
|
|
9062
|
+
);
|
|
9063
|
+
emitEvent(events, context, "thread.started", { providerThreadId: sessionId });
|
|
9064
|
+
emitEvent(events, context, "session.state.changed", { state: "ready" });
|
|
9065
|
+
startEventPump({ events, context, declineRelay });
|
|
9066
|
+
return sessionFromContext(context);
|
|
9067
|
+
} catch (cause) {
|
|
9068
|
+
rememberPendingServer(input.threadId, server);
|
|
9069
|
+
await closePendingServer(input.threadId, server);
|
|
9070
|
+
throw cause;
|
|
8978
9071
|
}
|
|
8979
|
-
sessions.set(input.threadId, context);
|
|
8980
|
-
emitEvent(
|
|
8981
|
-
events,
|
|
8982
|
-
context,
|
|
8983
|
-
"session.started",
|
|
8984
|
-
input.resumeCursor !== void 0 ? { resume: input.resumeCursor } : {}
|
|
8985
|
-
);
|
|
8986
|
-
emitEvent(events, context, "thread.started", { providerThreadId: sessionId });
|
|
8987
|
-
emitEvent(events, context, "session.state.changed", { state: "ready" });
|
|
8988
|
-
startEventPump({ events, context, declineRelay });
|
|
8989
|
-
return sessionFromContext(context);
|
|
8990
9072
|
},
|
|
8991
9073
|
sendTurn: async (input) => {
|
|
8992
9074
|
const context = requireSession(input.threadId);
|
|
@@ -9002,7 +9084,6 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9002
9084
|
const requestedModel = modelIdFromSelection(input.modelSelection) ?? readString2(input.modelSelection?.model) ?? context.session.model;
|
|
9003
9085
|
const parsedSlug = chooseOpenCodeModel({
|
|
9004
9086
|
requested: requestedModel,
|
|
9005
|
-
boundModelId: context.boundModelId,
|
|
9006
9087
|
match: context.matchModel
|
|
9007
9088
|
});
|
|
9008
9089
|
const queuedDecline = declineRelay.take(input.threadId);
|
|
@@ -9137,13 +9218,11 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9137
9218
|
},
|
|
9138
9219
|
stopSession: async (threadId) => {
|
|
9139
9220
|
const context = sessions.get(threadId);
|
|
9140
|
-
if (
|
|
9141
|
-
sessions.delete(threadId);
|
|
9142
|
-
try {
|
|
9221
|
+
if (context) {
|
|
9143
9222
|
await stopContext(context, "graceful");
|
|
9144
|
-
|
|
9145
|
-
sessions.delete(threadId);
|
|
9223
|
+
if (sessions.get(threadId) === context) sessions.delete(threadId);
|
|
9146
9224
|
}
|
|
9225
|
+
await closePendingServers(threadId);
|
|
9147
9226
|
},
|
|
9148
9227
|
readThread: async (threadId) => {
|
|
9149
9228
|
const context = requireSession(threadId);
|
|
@@ -9166,14 +9245,20 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9166
9245
|
events,
|
|
9167
9246
|
continuationKey: makeOpenCodeContinuationGroupKey(recipe),
|
|
9168
9247
|
dispose: async () => {
|
|
9169
|
-
if (
|
|
9248
|
+
if (disposal) return disposal;
|
|
9170
9249
|
disposed = true;
|
|
9171
|
-
const
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
);
|
|
9176
|
-
|
|
9250
|
+
const work = (async () => {
|
|
9251
|
+
const remaining = /* @__PURE__ */ new Set([...sessions.keys(), ...pendingServers.keys()]);
|
|
9252
|
+
await Promise.all([...remaining].map((threadId) => instance.stopSession(threadId)));
|
|
9253
|
+
events.close();
|
|
9254
|
+
})();
|
|
9255
|
+
disposal = work;
|
|
9256
|
+
try {
|
|
9257
|
+
await work;
|
|
9258
|
+
} catch (cause) {
|
|
9259
|
+
disposal = void 0;
|
|
9260
|
+
throw cause;
|
|
9261
|
+
}
|
|
9177
9262
|
},
|
|
9178
9263
|
get textGeneration() {
|
|
9179
9264
|
textGeneration ??= createOpenCodeTextGeneration(recipe, host);
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"form": {
|
|
3
|
+
"binaryPath": {
|
|
4
|
+
"title": "Program path",
|
|
5
|
+
"description": "Path to the OpenCode program this provider runs.",
|
|
6
|
+
"placeholder": "opencode"
|
|
7
|
+
},
|
|
8
|
+
"serverUrl": {
|
|
9
|
+
"title": "Server URL",
|
|
10
|
+
"description": "Leave blank to let Ycodium spawn the server when needed.",
|
|
11
|
+
"placeholder": "http://127.0.0.1:4096"
|
|
12
|
+
},
|
|
13
|
+
"serverPassword": {
|
|
14
|
+
"title": "Server password",
|
|
15
|
+
"description": "Stored in plain text on disk.",
|
|
16
|
+
"placeholder": "Optional"
|
|
17
|
+
},
|
|
18
|
+
"homePath": {
|
|
19
|
+
"title": "Account directory",
|
|
20
|
+
"description": "Where this account's login and history live. Leave empty to use the CLI's default.",
|
|
21
|
+
"placeholder": "e.g. ~/.opencode-work"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"form": {
|
|
3
|
+
"binaryPath": {
|
|
4
|
+
"title": "程序路径",
|
|
5
|
+
"description": "此 provider 运行的 OpenCode 程序的路径。",
|
|
6
|
+
"placeholder": "opencode"
|
|
7
|
+
},
|
|
8
|
+
"serverUrl": {
|
|
9
|
+
"title": "服务器 URL",
|
|
10
|
+
"description": "留空则由 Ycodium 在需要时启动服务器。",
|
|
11
|
+
"placeholder": "http://127.0.0.1:4096"
|
|
12
|
+
},
|
|
13
|
+
"serverPassword": {
|
|
14
|
+
"title": "服务器密码",
|
|
15
|
+
"description": "以明文保存在磁盘上。",
|
|
16
|
+
"placeholder": "可选"
|
|
17
|
+
},
|
|
18
|
+
"homePath": {
|
|
19
|
+
"title": "账户目录",
|
|
20
|
+
"description": "此账户的登录信息与历史记录所在的目录。留空则使用该命令行工具的默认目录。",
|
|
21
|
+
"placeholder": "例如 ~/.opencode-work"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
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.2488",
|
|
4
4
|
"description": "OpenCode executor: OpenCode CLI via @opencode-ai/sdk/v2.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
12
|
"assets",
|
|
13
|
+
"locales",
|
|
13
14
|
"README.md"
|
|
14
15
|
],
|
|
15
16
|
"type": "module",
|
|
@@ -23,7 +24,8 @@
|
|
|
23
24
|
"@types/node": "24.12.4",
|
|
24
25
|
"esbuild": "0.28.1",
|
|
25
26
|
"vite-plus": "0.2.2",
|
|
26
|
-
"@ycodium-ai/plugin-api": "0.2.
|
|
27
|
+
"@ycodium-ai/plugin-api": "0.2.2488",
|
|
28
|
+
"ycodium-executor-testing": "0.0.0"
|
|
27
29
|
},
|
|
28
30
|
"ycodium": {
|
|
29
31
|
"plugin": "./dist/index.js",
|