@ycodium-ai/agent-kimi 0.2.2800 → 0.2.2834
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 +80 -66
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -23966,22 +23966,28 @@ function createAcpConnection(options) {
|
|
|
23966
23966
|
options.readable.on("end", onEnd);
|
|
23967
23967
|
options.readable.on("error", onError);
|
|
23968
23968
|
options.writable.once("error", onWritableError);
|
|
23969
|
-
const
|
|
23969
|
+
const begin = (method, params) => {
|
|
23970
23970
|
failIfClosed();
|
|
23971
23971
|
const id = nextRequestId;
|
|
23972
23972
|
nextRequestId += 1;
|
|
23973
23973
|
const { promise: promise2, resolve: resolve3, reject } = Promise.withResolvers();
|
|
23974
23974
|
pending.set(String(id), { method, resolve: resolve3, reject });
|
|
23975
23975
|
const message = params === void 0 ? { jsonrpc: "2.0", id, method } : { jsonrpc: "2.0", id, method, params };
|
|
23976
|
-
|
|
23977
|
-
|
|
23978
|
-
|
|
23979
|
-
|
|
23980
|
-
|
|
23976
|
+
const written = Promise.race([writeMessage(message), promise2]).then(
|
|
23977
|
+
() => void 0,
|
|
23978
|
+
(error62) => {
|
|
23979
|
+
if (pending.delete(String(id))) {
|
|
23980
|
+
reject(error62);
|
|
23981
|
+
}
|
|
23982
|
+
throw error62;
|
|
23981
23983
|
}
|
|
23982
|
-
|
|
23983
|
-
}
|
|
23984
|
-
|
|
23984
|
+
);
|
|
23985
|
+
return { written, response: promise2 };
|
|
23986
|
+
};
|
|
23987
|
+
const request = (async (method, params) => {
|
|
23988
|
+
const { written, response } = begin(method, params);
|
|
23989
|
+
await written;
|
|
23990
|
+
return response;
|
|
23985
23991
|
});
|
|
23986
23992
|
const notify = async (method, params) => {
|
|
23987
23993
|
failIfClosed();
|
|
@@ -24002,6 +24008,7 @@ function createAcpConnection(options) {
|
|
|
24002
24008
|
const close = (error62) => shutdown(error62 ?? new AcpConnectionClosedError());
|
|
24003
24009
|
return {
|
|
24004
24010
|
request,
|
|
24011
|
+
begin,
|
|
24005
24012
|
notify,
|
|
24006
24013
|
awaitInboundIdle,
|
|
24007
24014
|
close,
|
|
@@ -25367,6 +25374,13 @@ function modelSelectionStateFromSetup(setup) {
|
|
|
25367
25374
|
};
|
|
25368
25375
|
}
|
|
25369
25376
|
|
|
25377
|
+
// ../../packages/ycodium-acp-executor/src/user-input-pending.ts
|
|
25378
|
+
var userInputAnswerOptionId = (question, answers) => {
|
|
25379
|
+
const answer = answers[question.id];
|
|
25380
|
+
const selected = typeof answer === "string" ? answer : Array.isArray(answer) && answer.length === 1 && typeof answer[0] === "string" ? answer[0] : void 0;
|
|
25381
|
+
return selected !== void 0 && question.options.some((option) => option.id === selected) ? selected : void 0;
|
|
25382
|
+
};
|
|
25383
|
+
|
|
25370
25384
|
// ../../packages/ycodium-acp-executor/src/vendor-hooks.ts
|
|
25371
25385
|
var defaultVendorHooks = {
|
|
25372
25386
|
completedStopReason: (response) => response.stopReason
|
|
@@ -25374,11 +25388,6 @@ var defaultVendorHooks = {
|
|
|
25374
25388
|
|
|
25375
25389
|
// ../../packages/ycodium-acp-executor/src/executor.ts
|
|
25376
25390
|
var DEFAULT_CANCEL_GRACE_MS = 5e3;
|
|
25377
|
-
var userInputAnswerOptionId = (question, answers) => {
|
|
25378
|
-
const answer = answers[question.id];
|
|
25379
|
-
const selected = typeof answer === "string" ? answer : Array.isArray(answer) && answer.length === 1 && typeof answer[0] === "string" ? answer[0] : void 0;
|
|
25380
|
-
return selected !== void 0 && question.options.some((option) => option.id === selected) ? selected : void 0;
|
|
25381
|
-
};
|
|
25382
25391
|
function defaultNowIso() {
|
|
25383
25392
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
25384
25393
|
}
|
|
@@ -26202,7 +26211,7 @@ function createAcpExecutor(options) {
|
|
|
26202
26211
|
};
|
|
26203
26212
|
const settleTurn = (input2) => {
|
|
26204
26213
|
if (!isLive(input2.expectedGeneration)) {
|
|
26205
|
-
return;
|
|
26214
|
+
return false;
|
|
26206
26215
|
}
|
|
26207
26216
|
if (!acpPromptSettlementBelongsToContext({
|
|
26208
26217
|
liveAcpSessionId: sessionId ?? "",
|
|
@@ -26211,37 +26220,40 @@ function createAcpExecutor(options) {
|
|
|
26211
26220
|
liveSessionActiveTurnId: activeTurnId,
|
|
26212
26221
|
turnId: input2.turnId
|
|
26213
26222
|
})) {
|
|
26214
|
-
return;
|
|
26223
|
+
return false;
|
|
26215
26224
|
}
|
|
26216
26225
|
closeActiveAssistantSegment(input2.turnId);
|
|
26217
26226
|
promptsInFlight = Math.max(0, promptsInFlight - 1);
|
|
26218
|
-
if (promptsInFlight
|
|
26219
|
-
|
|
26220
|
-
|
|
26221
|
-
|
|
26222
|
-
}
|
|
26223
|
-
emit({
|
|
26224
|
-
type: "turn.completed",
|
|
26225
|
-
...stamp(),
|
|
26226
|
-
provider: options.provider,
|
|
26227
|
-
threadId: options.threadId,
|
|
26228
|
-
turnId: input2.turnId,
|
|
26229
|
-
payload: {
|
|
26230
|
-
state: input2.state,
|
|
26231
|
-
stopReason: input2.stopReason
|
|
26232
|
-
}
|
|
26233
|
-
});
|
|
26234
|
-
interruptedTurnIds.delete(input2.turnId);
|
|
26227
|
+
if (promptsInFlight !== 0 || activeTurnId !== input2.turnId) return false;
|
|
26228
|
+
activeTurnId = void 0;
|
|
26229
|
+
if (status !== "disposed") {
|
|
26230
|
+
status = "ready";
|
|
26235
26231
|
}
|
|
26232
|
+
emit({
|
|
26233
|
+
type: "turn.completed",
|
|
26234
|
+
...stamp(),
|
|
26235
|
+
provider: options.provider,
|
|
26236
|
+
threadId: options.threadId,
|
|
26237
|
+
turnId: input2.turnId,
|
|
26238
|
+
payload: {
|
|
26239
|
+
state: input2.state,
|
|
26240
|
+
stopReason: input2.stopReason,
|
|
26241
|
+
...input2.errorMessage === void 0 ? {} : { errorMessage: input2.errorMessage }
|
|
26242
|
+
}
|
|
26243
|
+
});
|
|
26244
|
+
interruptedTurnIds.delete(input2.turnId);
|
|
26245
|
+
return true;
|
|
26236
26246
|
};
|
|
26237
|
-
const sendPromptRpc = async (sessionId2, promptParts) => {
|
|
26247
|
+
const sendPromptRpc = async (sessionId2, promptParts, onWritten) => {
|
|
26238
26248
|
const settlementHooks = hooks.promptSettlement;
|
|
26239
26249
|
const promptKey = settlementHooks === void 0 ? void 0 : randomId();
|
|
26240
|
-
const
|
|
26250
|
+
const pending = connection.begin("session/prompt", {
|
|
26241
26251
|
sessionId: sessionId2,
|
|
26242
26252
|
prompt: promptParts,
|
|
26243
26253
|
...settlementHooks !== void 0 && promptKey !== void 0 ? settlementHooks.requestFields(promptKey) : {}
|
|
26244
26254
|
});
|
|
26255
|
+
void pending.written.then(onWritten, () => void 0);
|
|
26256
|
+
const promptRpc = pending.response;
|
|
26245
26257
|
if (settlementHooks === void 0 || promptKey === void 0) {
|
|
26246
26258
|
return await promptRpc;
|
|
26247
26259
|
} else {
|
|
@@ -26267,6 +26279,11 @@ function createAcpExecutor(options) {
|
|
|
26267
26279
|
const prompt = async (input2) => {
|
|
26268
26280
|
failIfDisposed();
|
|
26269
26281
|
const started = requireStarted();
|
|
26282
|
+
const settle2 = (rest) => settleTurn({
|
|
26283
|
+
expectedGeneration: started.generation,
|
|
26284
|
+
expectedSessionId: started.sessionId,
|
|
26285
|
+
...rest
|
|
26286
|
+
});
|
|
26270
26287
|
let turnId;
|
|
26271
26288
|
await threadMutex.acquire();
|
|
26272
26289
|
try {
|
|
@@ -26294,13 +26311,7 @@ function createAcpExecutor(options) {
|
|
|
26294
26311
|
try {
|
|
26295
26312
|
failIfDisposed();
|
|
26296
26313
|
if (interruptedTurnIds.has(turnId)) {
|
|
26297
|
-
|
|
26298
|
-
expectedGeneration: started.generation,
|
|
26299
|
-
expectedSessionId: started.sessionId,
|
|
26300
|
-
turnId,
|
|
26301
|
-
stopReason: "cancelled",
|
|
26302
|
-
state: "cancelled"
|
|
26303
|
-
});
|
|
26314
|
+
settle2({ turnId, stopReason: "cancelled", state: "cancelled" });
|
|
26304
26315
|
return {
|
|
26305
26316
|
threadId: options.threadId,
|
|
26306
26317
|
turnId,
|
|
@@ -26314,12 +26325,24 @@ function createAcpExecutor(options) {
|
|
|
26314
26325
|
expectedGeneration: started.generation
|
|
26315
26326
|
});
|
|
26316
26327
|
closeActiveAssistantSegment(turnId);
|
|
26328
|
+
let written = false;
|
|
26317
26329
|
try {
|
|
26318
|
-
response = await sendPromptRpc(started.sessionId, promptParts)
|
|
26330
|
+
response = await sendPromptRpc(started.sessionId, promptParts, () => {
|
|
26331
|
+
written = true;
|
|
26332
|
+
input2.onDispatched?.(turnId);
|
|
26333
|
+
});
|
|
26319
26334
|
} catch (error62) {
|
|
26320
26335
|
if (disposed) {
|
|
26321
26336
|
throw new AcpExecutorDisposedError();
|
|
26322
26337
|
}
|
|
26338
|
+
if (written && input2.onDispatched !== void 0 && !interruptedTurnIds.has(turnId)) {
|
|
26339
|
+
const errorMessage = error62 instanceof Error && error62.message.trim() || "ACP prompt failed";
|
|
26340
|
+
if (settle2({ turnId, stopReason: "error", state: "failed", errorMessage }))
|
|
26341
|
+
options.log?.warn?.("turn failed after dispatch", {
|
|
26342
|
+
threadId: options.threadId,
|
|
26343
|
+
failure: errorMessage
|
|
26344
|
+
});
|
|
26345
|
+
}
|
|
26323
26346
|
throw error62;
|
|
26324
26347
|
}
|
|
26325
26348
|
await connection.awaitInboundIdle();
|
|
@@ -26350,13 +26373,7 @@ function createAcpExecutor(options) {
|
|
|
26350
26373
|
}
|
|
26351
26374
|
const finishPrompt = () => {
|
|
26352
26375
|
if (interruptedTurnIds.has(settledTurnId)) {
|
|
26353
|
-
|
|
26354
|
-
expectedGeneration: started.generation,
|
|
26355
|
-
expectedSessionId: started.sessionId,
|
|
26356
|
-
turnId: settledTurnId,
|
|
26357
|
-
stopReason: "cancelled",
|
|
26358
|
-
state: "cancelled"
|
|
26359
|
-
});
|
|
26376
|
+
settle2({ turnId: settledTurnId, stopReason: "cancelled", state: "cancelled" });
|
|
26360
26377
|
return {
|
|
26361
26378
|
threadId: options.threadId,
|
|
26362
26379
|
turnId: settledTurnId,
|
|
@@ -26379,9 +26396,7 @@ function createAcpExecutor(options) {
|
|
|
26379
26396
|
}
|
|
26380
26397
|
});
|
|
26381
26398
|
}
|
|
26382
|
-
|
|
26383
|
-
expectedGeneration: started.generation,
|
|
26384
|
-
expectedSessionId: started.sessionId,
|
|
26399
|
+
settle2({
|
|
26385
26400
|
turnId: settledTurnId,
|
|
26386
26401
|
stopReason,
|
|
26387
26402
|
state: response.stopReason === "cancelled" ? "cancelled" : "completed"
|
|
@@ -26639,6 +26654,17 @@ function createAcpExecutor(options) {
|
|
|
26639
26654
|
};
|
|
26640
26655
|
}
|
|
26641
26656
|
|
|
26657
|
+
// ../../packages/ycodium-acp-executor/src/prompt-dispatch.ts
|
|
26658
|
+
var dispatchAcpPrompt = (executor, input2) => {
|
|
26659
|
+
const { promise: dispatched, resolve: resolve3 } = Promise.withResolvers();
|
|
26660
|
+
const finished = executor.prompt({ ...input2, onDispatched: resolve3 });
|
|
26661
|
+
return Promise.race([
|
|
26662
|
+
dispatched.then((turnId) => ({ turnId })),
|
|
26663
|
+
// 写入之前就落定:成功(写入前被取消)带 turnId;拒绝原样交给调用方,那是起轮失败。
|
|
26664
|
+
finished.then((result) => ({ turnId: result.turnId }))
|
|
26665
|
+
]);
|
|
26666
|
+
};
|
|
26667
|
+
|
|
26642
26668
|
// ../../packages/ycodium-acp-executor/src/mcp-servers.ts
|
|
26643
26669
|
function toAcpMcpServers(entries) {
|
|
26644
26670
|
return (entries ?? []).map(
|
|
@@ -27793,26 +27819,14 @@ var createKimiInstance = (config2, host) => {
|
|
|
27793
27819
|
void booked.executor.cancel(input2.expectedTurnId).catch(() => void 0);
|
|
27794
27820
|
};
|
|
27795
27821
|
signal?.addEventListener("abort", onAbort);
|
|
27796
|
-
booked.session = {
|
|
27797
|
-
...booked.session,
|
|
27798
|
-
status: "running",
|
|
27799
|
-
updatedAt: nowIso()
|
|
27800
|
-
};
|
|
27801
27822
|
try {
|
|
27802
27823
|
const requestedModelId = modelIdFromSelection(input2.modelSelection);
|
|
27803
|
-
const turn = await booked.executor
|
|
27824
|
+
const turn = await dispatchAcpPrompt(booked.executor, {
|
|
27804
27825
|
text: input2.input ?? "",
|
|
27805
27826
|
...input2.expectedTurnId === void 0 ? {} : { turnId: input2.expectedTurnId },
|
|
27806
27827
|
...requestedModelId === void 0 ? {} : { requestedModelId }
|
|
27807
27828
|
});
|
|
27808
|
-
await yieldTick();
|
|
27809
27829
|
booked.turns.push({ id: turn.turnId, items: [] });
|
|
27810
|
-
booked.session = {
|
|
27811
|
-
...booked.session,
|
|
27812
|
-
status: "idle",
|
|
27813
|
-
updatedAt: nowIso(),
|
|
27814
|
-
...booked.executor.modelId === void 0 ? {} : { model: booked.executor.modelId }
|
|
27815
|
-
};
|
|
27816
27830
|
return {
|
|
27817
27831
|
threadId: input2.threadId,
|
|
27818
27832
|
turnId: turn.turnId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/agent-kimi",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2834",
|
|
4
4
|
"description": "Kimi Code executor: runs `kimi acp` over Agent Client Protocol stdio.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"@types/node": "24.12.4",
|
|
22
22
|
"esbuild": "0.28.1",
|
|
23
23
|
"vite-plus": "0.2.2",
|
|
24
|
-
"
|
|
25
|
-
"ycodium-
|
|
26
|
-
"ycodium-
|
|
24
|
+
"ycodium-acp-executor": "0.2.2834",
|
|
25
|
+
"ycodium-executor-testing": "0.0.0",
|
|
26
|
+
"@ycodium-ai/plugin-api": "0.2.2834"
|
|
27
27
|
},
|
|
28
28
|
"ycodium": {
|
|
29
29
|
"plugin": "./dist/index.js",
|