@coda-console/kimi 1.4.2 → 1.4.3

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/README.md CHANGED
@@ -1,3 +1,5 @@
1
1
  # Kimi Code
2
2
 
3
3
  Kimi Code Agent:Coda 的入口在运行机的 kimi acp 与 Coda 之间转发,读 Kimi 的会话文件报出后台命令与子 Agent;资源页的「Kimi」显示账号与额度,可从 Coda 安装和登录。
4
+
5
+ 不声明 `systemPrompt`;会话指令由 Coda 后端在新会话第一次非斜杠命令的用户输入前送入单独的文本块,恢复会话不再送,插件不用处理。
package/agent/relay.mjs CHANGED
@@ -7,13 +7,11 @@ import { kimiDisplayNames } from './display.mjs';
7
7
  // The turns Kimi's ACP does not tell, its goal's and those of prompts it queued behind them, are told from its files too
8
8
  // (turns.mjs): an answer Kimi gave at once to a prompt in which it said nothing waits for that look, and is held if Kimi
9
9
  // has not run the prompt yet.
10
- // Nothing waits on a look longer than `hold`. CODA_DISABLE_RUNTIME_PATCHES=kimi leaves a plain relay, but for Coda's session
11
- // instructions, which go in front of a new session's first prompt either way (instructions.mjs). A known quota error in
10
+ // Nothing waits on a look longer than `hold`. CODA_DISABLE_RUNTIME_PATCHES=kimi leaves a plain relay. A known quota error in
12
11
  // a prompt's answer is classified at this boundary (errors.mjs), without retrying or changing other errors; an `end_turn`
13
12
  // Kimi gave to a prompt whose turn its files say failed is passed on as that failure. A Kimi whose files are not as understood
14
13
  // (another version, another layout) is relayed as it would be anyway, but said so once a session and way, to a Coda that takes
15
14
  // it (`_coda/unrecognized`, docs/agent-protocol.md「没适配的东西」): the user is told what goes unseen.
16
- import { SessionInstructions } from './instructions.mjs';
17
15
  import { classifyKimiError, failedAnswer } from './errors.mjs';
18
16
  import { SUPPORTED, kimiSession } from './observe.mjs';
19
17
  import { KimiWaits } from './waits.mjs';
@@ -36,15 +34,12 @@ export class KimiRelay {
36
34
  this.asked = new Map(); this.prompts = new Set(); this.sent = new Map();
37
35
  // Whether Coda takes what is not understood, and what it was told, by session and name.
38
36
  this.taken = false; this.told = new Set();
39
- this.version = null; this.session = null; this.waits = null; this.turns = null; this.content = []; this.instructions = new SessionInstructions();
37
+ this.version = null; this.session = null; this.waits = null; this.turns = null; this.content = [];
40
38
  // What Kimi said, passed on in order behind any message that waits for a look.
41
39
  this.queue = Promise.resolve();
42
40
  this.looking = null; this.again = false; this.lookedAt = -Infinity; this.timer = null; this.watching = null; this.closed = false;
43
41
  }
44
42
  fromCoda(message) {
45
- const { agent, coda } = this.instructions.fromCoda(message);
46
- if (coda) { this.queue = this.queue.then(() => this.say(coda)); return; }
47
- message = agent;
48
43
  if (!this.plain && 'id' in message && typeof message.method === 'string') {
49
44
  if (message.method === 'initialize') {
50
45
  this.asked.set(message.id, { initialize: true });
@@ -62,7 +57,7 @@ export class KimiRelay {
62
57
  }
63
58
  fromAgent(message) {
64
59
  if (!record(message)) return;
65
- message = kimiDisplayNames(this.instructions.fromAgent(message));
60
+ message = kimiDisplayNames(message);
66
61
  const answer = 'id' in message && !('method' in message), asked = answer ? this.asked.get(message.id) : undefined;
67
62
  if (asked) this.asked.delete(message.id);
68
63
  if (asked?.initialize && record(message.result)) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "id": "kimi",
4
4
  "displayName": "Kimi Code",
5
5
  "description": "用 Kimi Code 跑会话",
6
- "version": "1.4.2",
6
+ "version": "1.4.3",
7
7
  "categories": [
8
8
  "Agent"
9
9
  ],
@@ -1,68 +0,0 @@
1
- // Coda's session instructions (docs/agent-protocol.md「会话指令」) for an agent whose own ACP does not take `systemPrompt`: the
2
- // entry declares that it does, keeps the parameter from the agent, and puts the text in front of the first prompt of a
3
- // session the agent opened new, as a part of its own; a session it loaded has had them. A slash command is the agent's to
4
- // read as one: the instructions wait for the next prompt. Kept the same in every plugin that relays a CLI's ACP.
5
- const record = value => value && typeof value === 'object' && !Array.isArray(value);
6
-
7
- // ACP's `systemPrompt`: its text, '' when there is none; throws on anything but text appended to the agent's own.
8
- export function sessionInstructions(systemPrompt) {
9
- if (systemPrompt === undefined || systemPrompt === null) return '';
10
- if (systemPrompt.mode !== 'append') throw new Error('会话指令只支持 append 模式');
11
- const { content } = systemPrompt;
12
- if (!Array.isArray(content) || content.some(block => block?.type !== 'text' || typeof block.text !== 'string')) throw new Error('会话指令只接受文本块');
13
- return content.map(block => block.text).join('\n\n');
14
- }
15
-
16
- // The part in front of the user's input: delimited, and said to be the client's, not the user's.
17
- const OPENING = '<coda-session-instructions>';
18
- export const instructionsBlock = text => ({ type: 'text', text: `${OPENING}\n`
19
- + 'Instructions from Coda, the client this session runs in, for the whole session. They are not part of the user\'s message.\n\n'
20
- + `${text}\n</coda-session-instructions>\n` });
21
-
22
- export class SessionInstructions {
23
- // Coda's requests whose answers are read here, by id; the instructions of a session yet to have its first prompt.
24
- constructor() { this.asked = new Map(); this.waiting = new Map(); }
25
- // What Coda says: `agent`, what the agent is told, or `coda`, Coda's answer given here instead.
26
- fromCoda(message) {
27
- const { id, method, params } = message;
28
- if (!record(params)) return { agent: message };
29
- if (method === 'initialize' && id !== undefined) this.asked.set(id, { initialize: true });
30
- if (method === 'session/new' || method === 'session/load') {
31
- let text;
32
- try { text = sessionInstructions(params.systemPrompt); }
33
- catch (error) { return { coda: { jsonrpc: '2.0', id, error: { code: -32602, message: error.message } } }; }
34
- const { systemPrompt, ...rest } = params;
35
- if (method === 'session/new' && text && id !== undefined) this.asked.set(id, { text });
36
- return { agent: { ...message, params: rest } };
37
- }
38
- if (method === 'session/prompt' && Array.isArray(params.prompt) && this.waiting.has(params.sessionId)) {
39
- const first = params.prompt.find(block => block?.type === 'text');
40
- if (typeof first?.text === 'string' && first.text.trimStart().startsWith('/')) return { agent: message };
41
- const text = this.waiting.get(params.sessionId);
42
- this.waiting.delete(params.sessionId);
43
- return { agent: { ...message, params: { ...params, prompt: [instructionsBlock(text), ...params.prompt] } } };
44
- }
45
- return { agent: message };
46
- }
47
- // What the agent says, as said to Coda. A title the agent took from the first prompt's text begins with the instructions,
48
- // not with what the user asked: it is left out, and the session keeps the title Coda gives it.
49
- fromAgent(message) {
50
- const update = message?.method === 'session/update' && record(message.params) ? message.params.update : null;
51
- if (record(update) && update.sessionUpdate === 'session_info_update' && typeof update.title === 'string' && update.title.trimStart().startsWith(OPENING)) {
52
- const { title, ...rest } = update;
53
- return { ...message, params: { ...message.params, update: rest } };
54
- }
55
- if (!record(message) || !('id' in message) || 'method' in message) return message;
56
- const asked = this.asked.get(message.id);
57
- if (!asked) return message;
58
- this.asked.delete(message.id);
59
- if (!record(message.result)) return message;
60
- if (asked.text) {
61
- if (typeof message.result.sessionId === 'string') this.waiting.set(message.result.sessionId, asked.text);
62
- return message;
63
- }
64
- const capabilities = record(message.result.agentCapabilities) ? message.result.agentCapabilities : {};
65
- const sessions = record(capabilities.sessionCapabilities) ? capabilities.sessionCapabilities : {};
66
- return { ...message, result: { ...message.result, agentCapabilities: { ...capabilities, sessionCapabilities: { ...sessions, systemPrompt: {} } } } };
67
- }
68
- }