@capybara-hq/kernel 0.1.0-rc.97 → 0.1.0-rc.98
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/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/channels.schemas.d.ts +10 -0
- package/dist/channels/channels.schemas.js +7 -0
- package/dist/channels/connections.service.d.ts +7 -0
- package/dist/channels/connections.service.js +4 -0
- package/dist/channels/features.d.ts +18 -1
- package/dist/channels/features.js +22 -0
- package/dist/channels/outbound.d.ts +19 -0
- package/dist/channels/outbound.js +531 -18
- package/dist/channels/phrases.d.ts +10 -0
- package/dist/channels/phrases.js +4 -0
- package/dist/channels/progress.d.ts +75 -0
- package/dist/channels/progress.js +216 -0
- package/dist/conversations/event-log.d.ts +8 -2
- package/dist/conversations/events.d.ts +5 -0
- package/dist/conversations/events.js +5 -1
- package/dist/conversations/prompt-suggestions.js +2 -2
- package/dist/db/kernel-schema.d.ts +16 -0
- package/dist/evals/run-replay.js +2 -2
- package/dist/evals/step-replay.js +2 -2
- package/dist/evals/worker.js +3 -1
- package/dist/extensions/plugin-icons.d.ts +7 -0
- package/dist/extensions/plugin-icons.js +8 -0
- package/dist/models/purposes.js +2 -2
- package/dist/platform/ops/channels.ops.js +24 -5
- package/dist/runtime/model-call.d.ts +23 -2
- package/dist/runtime/model-call.js +64 -9
- package/dist/runtime/run-drafts.d.ts +46 -4
- package/dist/runtime/run-drafts.js +110 -9
- package/dist/runtime/run-steps.d.ts +2 -1
- package/dist/runtime/run-steps.js +6 -2
- package/dist/runtime/runtime.module.js +3 -0
- package/dist/runtime/stream.controller.d.ts +7 -5
- package/dist/runtime/stream.controller.js +10 -6
- package/dist/runtime/stream.js +9 -1
- package/dist/runtime/write-base.d.ts +95 -0
- package/dist/runtime/write-base.js +281 -0
- package/dist/runtime/write-base.service.d.ts +68 -0
- package/dist/runtime/write-base.service.js +184 -0
- package/dist/sandbox/kernel-read.d.ts +39 -9
- package/dist/sandbox/kernel-read.js +33 -3
- package/dist/sandbox/operation-authority.d.ts +16 -12
- package/dist/sandbox/operation-authority.js +33 -20
- package/dist/sandbox/operation-intents.d.ts +10 -4
- package/dist/sandbox/operation-intents.js +31 -11
- package/dist/sandbox/sandbox.service.d.ts +30 -7
- package/dist/sandbox/sandbox.service.js +47 -13
- package/dist/tools/builtins/agent.js +4 -0
- package/dist/tools/builtins/image/generate.js +1 -0
- package/dist/tools/builtins/sandbox/bash.js +1 -0
- package/dist/tools/builtins/sandbox/edit.js +1 -0
- package/dist/tools/builtins/sandbox/write.js +1 -0
- package/dist/tools/builtins/send-message.js +1 -0
- package/dist/tools/info.d.ts +21 -2
- package/dist/tools/info.js +55 -12
- package/dist/tools/pipeline.d.ts +3 -1
- package/dist/tools/pipeline.js +37 -3
- package/dist/tools/registry.d.ts +6 -5
- package/dist/tools/registry.js +6 -5
- package/package.json +3 -3
- package/src/migrations/0185_channel_process_display.sql +13 -0
|
@@ -320,6 +320,16 @@ export declare const CHANNEL_PHRASES: {
|
|
|
320
320
|
readonly zh: "文件 {name}:";
|
|
321
321
|
readonly en: "File {name}:";
|
|
322
322
|
};
|
|
323
|
+
/** A run started, on a channel that cannot edit messages (no progress card, spec §6.2). */
|
|
324
|
+
readonly runStarted: {
|
|
325
|
+
readonly zh: "已开始处理";
|
|
326
|
+
readonly en: "Working on it";
|
|
327
|
+
};
|
|
328
|
+
/** The merged message of a run's handoff links after its answer (`{n}`: how many). */
|
|
329
|
+
readonly handoffs: {
|
|
330
|
+
readonly zh: "需要你处理({n})";
|
|
331
|
+
readonly en: "Needs your action ({n})";
|
|
332
|
+
};
|
|
323
333
|
/** 运行被中止(收尾挂着的草稿时附在已有文本之后)。 */
|
|
324
334
|
readonly runStopped: {
|
|
325
335
|
readonly zh: "已停止。";
|
package/dist/channels/phrases.js
CHANGED
|
@@ -267,6 +267,10 @@ export const CHANNEL_PHRASES = {
|
|
|
267
267
|
* link line follows it.
|
|
268
268
|
*/
|
|
269
269
|
fileRoot: { zh: "文件 {name}:", en: "File {name}:" },
|
|
270
|
+
/** A run started, on a channel that cannot edit messages (no progress card, spec §6.2). */
|
|
271
|
+
runStarted: { zh: "已开始处理", en: "Working on it" },
|
|
272
|
+
/** The merged message of a run's handoff links after its answer (`{n}`: how many). */
|
|
273
|
+
handoffs: { zh: "需要你处理({n})", en: "Needs your action ({n})" },
|
|
270
274
|
/** 运行被中止(收尾挂着的草稿时附在已有文本之后)。 */
|
|
271
275
|
runStopped: { zh: "已停止。", en: "Stopped." },
|
|
272
276
|
/** 运行失败。 */
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ChannelCard } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { ConversationEvent } from "../conversations/events.js";
|
|
3
|
+
import type { ChannelLocale } from "./phrases.js";
|
|
4
|
+
/**
|
|
5
|
+
* The state of one run's progress card (process blocks spec §6.2, §10.1): a pure fold of the run's
|
|
6
|
+
* conversation events. Serializable on purpose: the delivery keeps it between jobs, never in
|
|
7
|
+
* process memory. Nothing here touches the database or the clock.
|
|
8
|
+
*/
|
|
9
|
+
export interface ProgressState {
|
|
10
|
+
runId: string;
|
|
11
|
+
startedAt: string;
|
|
12
|
+
endedAt?: string;
|
|
13
|
+
state: "running" | "waiting" | "finished" | "stopped" | "failed";
|
|
14
|
+
/** The latest narration: first line, at most {@link STATUS_MAX} characters. */
|
|
15
|
+
status?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The latest non-empty narration in full while no non-empty answer followed it: a run that
|
|
18
|
+
* finishes this way has it promoted to its answer ({@link promotedAnswer}).
|
|
19
|
+
*/
|
|
20
|
+
unanswered?: string;
|
|
21
|
+
/** The pinned card's Markdown text. */
|
|
22
|
+
pinned?: string;
|
|
23
|
+
/** The last {@link RECENT_MAX} tool labels, oldest first. */
|
|
24
|
+
recent: string[];
|
|
25
|
+
/** Handoff links; `titles` holds both languages so the card picks the recipient's. */
|
|
26
|
+
pending: {
|
|
27
|
+
text: string;
|
|
28
|
+
url: string;
|
|
29
|
+
titles?: {
|
|
30
|
+
zh: string;
|
|
31
|
+
en: string;
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
34
|
+
thoughts: number;
|
|
35
|
+
tools: number;
|
|
36
|
+
errors: number;
|
|
37
|
+
/** Reserved: the pinned card's head is not known to the kernel. */
|
|
38
|
+
pinnedTitle?: string;
|
|
39
|
+
pinnedBadge?: string;
|
|
40
|
+
/** Bumps when a pinned card's text changes (a milestone). */
|
|
41
|
+
pinnedVersion: number;
|
|
42
|
+
}
|
|
43
|
+
export declare function initProgress(runId: string, startedAt: string): ProgressState;
|
|
44
|
+
/**
|
|
45
|
+
* The first line of a narration (Markdown, rendered like an answer). A line longer than
|
|
46
|
+
* {@link STATUS_MAX} characters loses its inline Markdown syntax and is cut with an ellipsis, so
|
|
47
|
+
* no emphasis, code span or link is left open.
|
|
48
|
+
*/
|
|
49
|
+
export declare function statusLine(text: string): string | undefined;
|
|
50
|
+
/** The narration a finished run without an answer after it takes as its answer, else undefined. */
|
|
51
|
+
export declare function promotedAnswer(s: ProgressState): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Folds one event into the state. `label` is the tool title and key argument helper the approval
|
|
54
|
+
* card uses; `base` is the web base (absent: no links, so no pending entries).
|
|
55
|
+
*
|
|
56
|
+
* Contract: only this run's events count. An event of another run (a previous run, a sub-agent's)
|
|
57
|
+
* is ignored, and so is every event after the run ended. Any approval or question decision flips
|
|
58
|
+
* `waiting` back to `running`, even when a parallel ask is still pending (accepted behavior). A
|
|
59
|
+
* sub-agent's approval or question (`subagent_waiting`, logged on the root run) waits the same
|
|
60
|
+
* way; its decision is in the child's log, so the sub-agent's `subagent_finished` resumes.
|
|
61
|
+
*/
|
|
62
|
+
export declare function reduceProgress(s: ProgressState, e: ConversationEvent, label: (toolKey: string, input: unknown) => string, base: string | undefined): ProgressState;
|
|
63
|
+
/**
|
|
64
|
+
* The progress card for the state. A finished run is one summary line (title and meta) with its
|
|
65
|
+
* pending links; `brief` drops the steps and the status line.
|
|
66
|
+
*/
|
|
67
|
+
export declare function progressCard(s: ProgressState, opts: {
|
|
68
|
+
base: string;
|
|
69
|
+
conversationId: string;
|
|
70
|
+
locale: ChannelLocale;
|
|
71
|
+
mode: "detailed" | "brief";
|
|
72
|
+
now: number;
|
|
73
|
+
}): Extract<ChannelCard, {
|
|
74
|
+
kind: "progress";
|
|
75
|
+
}>;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { conversationUrl } from "./cards.js";
|
|
2
|
+
const STATUS_MAX = 120;
|
|
3
|
+
const RECENT_MAX = 3;
|
|
4
|
+
export function initProgress(runId, startedAt) {
|
|
5
|
+
return {
|
|
6
|
+
runId,
|
|
7
|
+
startedAt,
|
|
8
|
+
state: "running",
|
|
9
|
+
recent: [],
|
|
10
|
+
pending: [],
|
|
11
|
+
thoughts: 0,
|
|
12
|
+
tools: 0,
|
|
13
|
+
errors: 0,
|
|
14
|
+
pinnedVersion: 0,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Markdown inline syntax taken out of a line before it is cut, so the cut never lands inside
|
|
19
|
+
* emphasis, code or a link: links and images keep their text, the markers go.
|
|
20
|
+
*/
|
|
21
|
+
function plainInline(line) {
|
|
22
|
+
return line
|
|
23
|
+
.replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1")
|
|
24
|
+
.replace(/[*`~]+/g, "")
|
|
25
|
+
.replace(/(^|[^\p{L}\p{N}])_+|_+(?=[^\p{L}\p{N}]|$)/gu, "$1")
|
|
26
|
+
.replace(/\s+/g, " ")
|
|
27
|
+
.trim();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The first line of a narration (Markdown, rendered like an answer). A line longer than
|
|
31
|
+
* {@link STATUS_MAX} characters loses its inline Markdown syntax and is cut with an ellipsis, so
|
|
32
|
+
* no emphasis, code span or link is left open.
|
|
33
|
+
*/
|
|
34
|
+
export function statusLine(text) {
|
|
35
|
+
const line = text
|
|
36
|
+
.split("\n")
|
|
37
|
+
.map((l) => l.trim())
|
|
38
|
+
.find((l) => l !== "");
|
|
39
|
+
if (line === undefined)
|
|
40
|
+
return undefined;
|
|
41
|
+
if ([...line].length <= STATUS_MAX)
|
|
42
|
+
return line;
|
|
43
|
+
const chars = [...plainInline(line)];
|
|
44
|
+
return chars.length > STATUS_MAX ? `${chars.slice(0, STATUS_MAX - 1).join("")}…` : chars.join("");
|
|
45
|
+
}
|
|
46
|
+
/** The narration a finished run without an answer after it takes as its answer, else undefined. */
|
|
47
|
+
export function promotedAnswer(s) {
|
|
48
|
+
return s.state === "finished" ? s.unanswered : undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Folds one event into the state. `label` is the tool title and key argument helper the approval
|
|
52
|
+
* card uses; `base` is the web base (absent: no links, so no pending entries).
|
|
53
|
+
*
|
|
54
|
+
* Contract: only this run's events count. An event of another run (a previous run, a sub-agent's)
|
|
55
|
+
* is ignored, and so is every event after the run ended. Any approval or question decision flips
|
|
56
|
+
* `waiting` back to `running`, even when a parallel ask is still pending (accepted behavior). A
|
|
57
|
+
* sub-agent's approval or question (`subagent_waiting`, logged on the root run) waits the same
|
|
58
|
+
* way; its decision is in the child's log, so the sub-agent's `subagent_finished` resumes.
|
|
59
|
+
*/
|
|
60
|
+
export function reduceProgress(s, e, label, base) {
|
|
61
|
+
if (e.runId !== null && e.runId !== s.runId)
|
|
62
|
+
return s;
|
|
63
|
+
if (s.endedAt !== undefined)
|
|
64
|
+
return s;
|
|
65
|
+
switch (e.type) {
|
|
66
|
+
case "assistant_message": {
|
|
67
|
+
const content = e.payload.content;
|
|
68
|
+
const calls = content.filter((b) => b.type === "tool_call");
|
|
69
|
+
const thoughts = content.filter((b) => b.type === "thinking").length;
|
|
70
|
+
let status = s.status;
|
|
71
|
+
let unanswered = s.unanswered;
|
|
72
|
+
const texts = content.flatMap((b) => (b.type === "text" ? [b.text] : []));
|
|
73
|
+
const said = texts.join("").trim() !== "";
|
|
74
|
+
// narration (spec §1.1): the text of a message that also calls a tool; answer text is not
|
|
75
|
+
if (calls.length > 0) {
|
|
76
|
+
status = statusLine(texts.join("\n")) ?? status;
|
|
77
|
+
if (said)
|
|
78
|
+
unanswered = texts.join("");
|
|
79
|
+
}
|
|
80
|
+
else if (said) {
|
|
81
|
+
unanswered = undefined;
|
|
82
|
+
}
|
|
83
|
+
const recent = [...s.recent, ...calls.map((c) => label(c.name, c.input))].slice(-RECENT_MAX);
|
|
84
|
+
const { unanswered: _prev, ...rest } = s;
|
|
85
|
+
return {
|
|
86
|
+
...rest,
|
|
87
|
+
...(status !== undefined && { status }),
|
|
88
|
+
...(unanswered !== undefined && { unanswered }),
|
|
89
|
+
recent,
|
|
90
|
+
thoughts: s.thoughts + thoughts,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
case "tool_result": {
|
|
94
|
+
const p = e.payload;
|
|
95
|
+
let next = {
|
|
96
|
+
...s,
|
|
97
|
+
tools: s.tools + 1,
|
|
98
|
+
errors: s.errors + (p.isError ? 1 : 0),
|
|
99
|
+
};
|
|
100
|
+
const v = p.view;
|
|
101
|
+
if (v?.kind === "handoff" && base !== undefined) {
|
|
102
|
+
const url = v.target.type === "link"
|
|
103
|
+
? `${base}${v.target.url}`
|
|
104
|
+
: conversationUrl(base, e.conversationId);
|
|
105
|
+
next = {
|
|
106
|
+
...next,
|
|
107
|
+
pending: [...next.pending, { text: v.title.en, url, titles: v.title }],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (p.card?.placement === "pinned" && p.card.text !== undefined) {
|
|
111
|
+
if (p.card.text !== s.pinned)
|
|
112
|
+
next = { ...next, pinned: p.card.text, pinnedVersion: s.pinnedVersion + 1 };
|
|
113
|
+
}
|
|
114
|
+
return next;
|
|
115
|
+
}
|
|
116
|
+
case "approval_requested":
|
|
117
|
+
case "question_asked":
|
|
118
|
+
return { ...s, state: "waiting" };
|
|
119
|
+
// a sub-agent's approval or question waits for a person as the run's own does; a connect
|
|
120
|
+
// request is the web's (the child got the connect text as its result), not a wait
|
|
121
|
+
case "subagent_waiting":
|
|
122
|
+
return e.payload.kind === "connect" ? s : { ...s, state: "waiting" };
|
|
123
|
+
case "approval_decided":
|
|
124
|
+
case "question_answered":
|
|
125
|
+
// the sub-agent's decision is logged in its own log: its finish resumes the card here
|
|
126
|
+
case "subagent_finished":
|
|
127
|
+
return s.state === "waiting" ? { ...s, state: "running" } : s;
|
|
128
|
+
case "run_finished":
|
|
129
|
+
return { ...s, state: "finished", endedAt: e.createdAt.toISOString() };
|
|
130
|
+
case "run_failed":
|
|
131
|
+
return { ...s, state: "failed", endedAt: e.createdAt.toISOString() };
|
|
132
|
+
case "run_aborted":
|
|
133
|
+
return { ...s, state: "stopped", endedAt: e.createdAt.toISOString() };
|
|
134
|
+
default:
|
|
135
|
+
return s;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const COPY = {
|
|
139
|
+
zh: {
|
|
140
|
+
running: "处理中",
|
|
141
|
+
waiting: "等待你确认",
|
|
142
|
+
stopped: "已停止",
|
|
143
|
+
failed: "处理失败",
|
|
144
|
+
elapsed: (t) => `已用 ${t}`,
|
|
145
|
+
worked: (t) => `已处理 ${t}`,
|
|
146
|
+
tools: (n) => `${n} 个工具`,
|
|
147
|
+
errors: (n) => `${n} 个调用出错`,
|
|
148
|
+
hours: (h, m) => `${h} 小时 ${m} 分`,
|
|
149
|
+
minutes: (m, s) => `${m} 分 ${s} 秒`,
|
|
150
|
+
seconds: (s) => `${s} 秒`,
|
|
151
|
+
link: "在网页查看完整过程",
|
|
152
|
+
},
|
|
153
|
+
en: {
|
|
154
|
+
running: "Working",
|
|
155
|
+
waiting: "Waiting for your approval",
|
|
156
|
+
stopped: "Stopped",
|
|
157
|
+
failed: "Failed",
|
|
158
|
+
elapsed: (t) => `Elapsed ${t}`,
|
|
159
|
+
worked: (t) => `Worked for ${t}`,
|
|
160
|
+
tools: (n) => `${n} ${n === 1 ? "tool" : "tools"}`,
|
|
161
|
+
errors: (n) => `${n} ${n === 1 ? "call" : "calls"} failed`,
|
|
162
|
+
hours: (h, m) => `${h}h ${m}m`,
|
|
163
|
+
minutes: (m, s) => `${m}m ${s}s`,
|
|
164
|
+
seconds: (s) => `${s}s`,
|
|
165
|
+
link: "See the full process on the web",
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
/** A duration in words, e.g. `2m 43s` (zh likewise); the running meta uses `m:ss` instead. */
|
|
169
|
+
function duration(ms, t) {
|
|
170
|
+
const total = Math.max(0, Math.round(ms / 1000));
|
|
171
|
+
if (total >= 3600)
|
|
172
|
+
return t.hours(Math.floor(total / 3600), Math.floor((total % 3600) / 60));
|
|
173
|
+
if (total >= 60)
|
|
174
|
+
return t.minutes(Math.floor(total / 60), total % 60);
|
|
175
|
+
return t.seconds(total);
|
|
176
|
+
}
|
|
177
|
+
function clock(ms) {
|
|
178
|
+
const total = Math.max(0, Math.floor(ms / 1000));
|
|
179
|
+
const h = Math.floor(total / 3600);
|
|
180
|
+
const m = Math.floor((total % 3600) / 60);
|
|
181
|
+
const sec = String(total % 60).padStart(2, "0");
|
|
182
|
+
return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${sec}` : `${m}:${sec}`;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The progress card for the state. A finished run is one summary line (title and meta) with its
|
|
186
|
+
* pending links; `brief` drops the steps and the status line.
|
|
187
|
+
*/
|
|
188
|
+
export function progressCard(s, opts) {
|
|
189
|
+
const t = COPY[opts.locale];
|
|
190
|
+
const started = Date.parse(s.startedAt);
|
|
191
|
+
const ended = s.endedAt === undefined ? opts.now : Date.parse(s.endedAt);
|
|
192
|
+
const ongoing = s.state === "running" || s.state === "waiting";
|
|
193
|
+
const counts = [
|
|
194
|
+
...(s.tools > 0 ? [t.tools(s.tools)] : []),
|
|
195
|
+
...(s.errors > 0 ? [t.errors(s.errors)] : []),
|
|
196
|
+
];
|
|
197
|
+
const title = s.state === "finished" ? t.worked(duration(ended - started, t)) : t[s.state];
|
|
198
|
+
const meta = ongoing
|
|
199
|
+
? t.elapsed(clock(ended - started))
|
|
200
|
+
: counts.length > 0
|
|
201
|
+
? counts.join(" · ")
|
|
202
|
+
: undefined;
|
|
203
|
+
const live = ongoing && opts.mode === "detailed";
|
|
204
|
+
return {
|
|
205
|
+
kind: "progress",
|
|
206
|
+
state: s.state,
|
|
207
|
+
title,
|
|
208
|
+
...(meta !== undefined && { meta }),
|
|
209
|
+
...(live && s.status !== undefined && { status: s.status }),
|
|
210
|
+
...(ongoing && s.pinned !== undefined && { pinned: s.pinned }),
|
|
211
|
+
steps: live ? [...s.recent] : [],
|
|
212
|
+
pending: s.pending.map((p) => ({ text: p.titles?.[opts.locale] ?? p.text, url: p.url })),
|
|
213
|
+
url: conversationUrl(opts.base, opts.conversationId),
|
|
214
|
+
urlText: t.link,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
@@ -33,7 +33,10 @@ export declare const conversationTopic: (conversationId: string) => string;
|
|
|
33
33
|
* 最终内容以日志中的 assistant_message 为准。`offset` (text and thinking): the characters of
|
|
34
34
|
* that channel this attempt of the step streamed before the delta; a subscriber that joined midway
|
|
35
35
|
* tells by it whether it has the step's text from the start (the channel outbound only drafts
|
|
36
|
-
* complete text) and drops what a live draft already covers (spec 2026-11-07 §3.2)
|
|
36
|
+
* complete text) and drops what a live draft already covers (spec 2026-11-07 §3.2). Streamed
|
|
37
|
+
* tool calls (streaming tool input spec §4, display only): `tool_start` (`callId`, `name`),
|
|
38
|
+
* `tool_input` (`callId`, `text`, `offset` counted per call) and `tool_base` (`callId`, `text`,
|
|
39
|
+
* `sha256`: the file a streaming `Write` replaces);
|
|
37
40
|
* - `ui`:插件经 `ctx.ui.invalidate` 告知这个会话的某个界面贡献变了(不进日志、不是模型可见内容),
|
|
38
41
|
* SSE 转发为 `event: ui`,网页据此重新取视图。
|
|
39
42
|
* - `subagent_progress`: after each step of a sub-agent run, on the topic of **every ancestor**
|
|
@@ -53,9 +56,12 @@ export type ConversationBusMessage = {
|
|
|
53
56
|
kind: "delta";
|
|
54
57
|
runId: string;
|
|
55
58
|
step: number;
|
|
56
|
-
delta: "text" | "thinking" | "step_reset";
|
|
59
|
+
delta: "text" | "thinking" | "tool_start" | "tool_input" | "tool_base" | "step_reset";
|
|
57
60
|
text?: string;
|
|
58
61
|
offset?: number;
|
|
62
|
+
callId?: string;
|
|
63
|
+
name?: string;
|
|
64
|
+
sha256?: string;
|
|
59
65
|
} | {
|
|
60
66
|
kind: "ui";
|
|
61
67
|
plugin: string;
|
|
@@ -1488,6 +1488,11 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
1488
1488
|
plugin: z.ZodString;
|
|
1489
1489
|
view: z.ZodString;
|
|
1490
1490
|
key: z.ZodOptional<z.ZodString>;
|
|
1491
|
+
placement: z.ZodOptional<z.ZodEnum<{
|
|
1492
|
+
pinned: "pinned";
|
|
1493
|
+
process: "process";
|
|
1494
|
+
}>>;
|
|
1495
|
+
text: z.ZodOptional<z.ZodString>;
|
|
1491
1496
|
}, z.core.$strip>>;
|
|
1492
1497
|
media: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1493
1498
|
attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
-
import { CONTEXT_LIMITS, DOCUMENT_MEDIA_TYPES, hasControlChars, IMAGE_MEDIA_TYPES, isAttachmentId, isSkillName, MEDIA_NAME_MAX_CHARS, validateAllowHost, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { CARD_TEXT_MAX, CONTEXT_LIMITS, DOCUMENT_MEDIA_TYPES, hasControlChars, IMAGE_MEDIA_TYPES, isAttachmentId, isSkillName, MEDIA_NAME_MAX_CHARS, validateAllowHost, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { AgentDefinitionSchema, DisabledSkillRef, DisabledToolRef, ModelRef, } from "../agents/definition.js";
|
|
5
5
|
import { ORG_ROLES } from "../orgs/roles.js";
|
|
@@ -1300,6 +1300,10 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1300
1300
|
plugin: z.string().min(1).max(100),
|
|
1301
1301
|
view: z.string().min(1).max(100),
|
|
1302
1302
|
key: z.string().min(1).max(200).optional(),
|
|
1303
|
+
/** Absent means `output`. */
|
|
1304
|
+
placement: z.enum(["pinned", "process"]).optional(),
|
|
1305
|
+
/** Only with `placement: "pinned"`; at most `CARD_TEXT_MAX` characters. */
|
|
1306
|
+
text: z.string().min(1).max(CARD_TEXT_MAX).optional(),
|
|
1303
1307
|
})
|
|
1304
1308
|
.optional(),
|
|
1305
1309
|
/**
|
|
@@ -28,7 +28,7 @@ import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
|
28
28
|
import { OrgSettingsModule, OrgSettingsService } from "../orgs/settings.service.js";
|
|
29
29
|
import { resolveCompactionSettings } from "../runtime/compaction-settings.service.js";
|
|
30
30
|
import { fireObserve, hookDeniedAudit, hookDeniedEvent, hookRequestOf, } from "../runtime/hook-calls.js";
|
|
31
|
-
import { consumeModelStream } from "../runtime/model-call.js";
|
|
31
|
+
import { consumeModelStream, deltaChars } from "../runtime/model-call.js";
|
|
32
32
|
import { ProviderRegistry, ProvidersModule } from "../runtime/providers.js";
|
|
33
33
|
import { UsageReportJobs, UsageReportJobsModule } from "../runtime/usage-report-jobs.js";
|
|
34
34
|
import { AttachmentsModule } from "./attachments.module.js";
|
|
@@ -213,7 +213,7 @@ let PromptSuggestionGenerator = class PromptSuggestionGenerator {
|
|
|
213
213
|
let out;
|
|
214
214
|
try {
|
|
215
215
|
out = await consumeModelStream(provider, request, info.streamIdleTimeoutMs ?? this.config.get().runtime.streamIdleMs, signal, (ev) => {
|
|
216
|
-
streamedChars += ev
|
|
216
|
+
streamedChars += deltaChars(ev);
|
|
217
217
|
});
|
|
218
218
|
}
|
|
219
219
|
catch (err) {
|
|
@@ -834,6 +834,11 @@ export interface ChannelConnectionsTable {
|
|
|
834
834
|
status: Generated<"active" | "disabled" | "error">;
|
|
835
835
|
/** 0038_channel_inbound_mode.sql: how inbound events arrive (long connection by default). */
|
|
836
836
|
inbound_mode: Generated<"long_connection" | "webhook">;
|
|
837
|
+
/**
|
|
838
|
+
* 0185_channel_process_display.sql: how the channel shows a run's process; null follows the
|
|
839
|
+
* chat type (`processDisplayOf`).
|
|
840
|
+
*/
|
|
841
|
+
process_display: ColumnType<"detailed" | "brief" | "off" | null, "detailed" | "brief" | "off" | null | undefined, "detailed" | "brief" | "off" | null>;
|
|
837
842
|
last_error: string | null;
|
|
838
843
|
bot_user_id: string | null;
|
|
839
844
|
tenant_id: string | null;
|
|
@@ -873,6 +878,17 @@ export interface ChannelDeliveriesTable {
|
|
|
873
878
|
* outbound has the run's first post (thread key = that message's id). Null otherwise.
|
|
874
879
|
*/
|
|
875
880
|
pending_thread_account_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
881
|
+
/**
|
|
882
|
+
* 0185: the run's progress message (edited in place), the run it belongs to and when its last
|
|
883
|
+
* milestone was sent; null without one. `progress_reposted`: the card was posted again after a
|
|
884
|
+
* rejected edit (once per run). `progress_final`: the ended run's card got its final edit (or
|
|
885
|
+
* the platform refused it for good).
|
|
886
|
+
*/
|
|
887
|
+
progress_message_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
888
|
+
progress_run_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
889
|
+
milestone_at: TsNullable;
|
|
890
|
+
progress_reposted: ColumnType<boolean, boolean | undefined, boolean>;
|
|
891
|
+
progress_final: ColumnType<boolean, boolean | undefined, boolean>;
|
|
876
892
|
}
|
|
877
893
|
/** 0018_channels.sql:出站投递发出的审批 / 提问卡片对应的 IM 消息(Task 11,用于更新卡片状态)。 */
|
|
878
894
|
export interface ChannelCardMessagesTable {
|
package/dist/evals/run-replay.js
CHANGED
|
@@ -21,7 +21,7 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
|
21
21
|
import { pluginContextIdemKey } from "../runtime/context/plugin-context.js";
|
|
22
22
|
import { estimateTokens } from "../runtime/context/tokens.js";
|
|
23
23
|
import { runDeadline, tightestLimit } from "../runtime/limits.js";
|
|
24
|
-
import { RunError } from "../runtime/model-call.js";
|
|
24
|
+
import { deltaChars, RunError } from "../runtime/model-call.js";
|
|
25
25
|
import { projectRootIdemKey } from "../runtime/project/knowledge.js";
|
|
26
26
|
import { runContextIdemKey } from "../runtime/run-context.service.js";
|
|
27
27
|
import { recordedSkillForks } from "../runtime/subagents/skill-fork.js";
|
|
@@ -469,7 +469,7 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
|
|
|
469
469
|
await charge(usageTokens(ev.usage));
|
|
470
470
|
}
|
|
471
471
|
else {
|
|
472
|
-
chars += ev
|
|
472
|
+
chars += deltaChars(ev);
|
|
473
473
|
}
|
|
474
474
|
yield ev;
|
|
475
475
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sanitizeParams, } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { effectiveDefinition, NO_SELECTION, sameModel, } from "../conversations/selection.js";
|
|
3
3
|
import { estimateTokens } from "../runtime/context/tokens.js";
|
|
4
|
-
import { consumeModelStream, MediaUnavailableError, } from "../runtime/model-call.js";
|
|
4
|
+
import { consumeModelStream, deltaChars, MediaUnavailableError, } from "../runtime/model-call.js";
|
|
5
5
|
import { loadSnapshotMedia, reconstructRequest, } from "./reconstruct.js";
|
|
6
6
|
/** 键排序后的 JSON(比较参数是否相同)。 */
|
|
7
7
|
const canonical = (v) => JSON.stringify(Object.keys(v)
|
|
@@ -169,7 +169,7 @@ export async function replayStep(d, s, call, candidate, signal) {
|
|
|
169
169
|
let out;
|
|
170
170
|
try {
|
|
171
171
|
out = await consumeModelStream(provider, request, idleMs, signal, (ev) => {
|
|
172
|
-
streamedChars += ev
|
|
172
|
+
streamedChars += deltaChars(ev);
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
catch (err) {
|
package/dist/evals/worker.js
CHANGED
|
@@ -78,7 +78,9 @@ const isPluginUnloaded = (err) => err instanceof ExtensionUnloadedError ||
|
|
|
78
78
|
* recorded feeder `overrides.permissionContext`, and none at all for a recording without markers.
|
|
79
79
|
*/
|
|
80
80
|
export function replayLoopDeps(stepDeps, overrides) {
|
|
81
|
-
const { db: _snapshot, hooks: _noHooks, subagentProgress: _noProgress, compactionProgress: _noCompactionProgress, skillForks: _noForks, permissionContext: _noLivePermissionContext,
|
|
81
|
+
const { db: _snapshot, hooks: _noHooks, subagentProgress: _noProgress, compactionProgress: _noCompactionProgress, skillForks: _noForks, permissionContext: _noLivePermissionContext,
|
|
82
|
+
// a replay never reads a device for a streaming Write's base
|
|
83
|
+
writeBase: _noWriteBase, ...replayDeps } = stepDeps;
|
|
82
84
|
// the object rest above copied `db` as a value: read it through the step deps' getter
|
|
83
85
|
// instead, so the loop always resolves the context-aware handle
|
|
84
86
|
return {
|
|
@@ -57,6 +57,13 @@ export declare class PluginIcons {
|
|
|
57
57
|
constructor(db: KernelDb);
|
|
58
58
|
/** Extension (plugin) name -> its icon's URL; names without one are absent. */
|
|
59
59
|
many(names: string[], scope: PluginIconScope): Promise<Map<string, string>>;
|
|
60
|
+
/**
|
|
61
|
+
* Extension (plugin) name -> the id of its catalog item, only for names whose item has an icon the
|
|
62
|
+
* org's catalog shows (the icon is `GET /api/v1/orgs/:orgId/catalog/:itemId/icon`).
|
|
63
|
+
*/
|
|
64
|
+
itemIdsWithIcon(names: string[], scope: Extract<PluginIconScope, {
|
|
65
|
+
kind: "org";
|
|
66
|
+
}>): Promise<Map<string, string>>;
|
|
60
67
|
/** Catalog item id -> its icon's URL (a list of items); items without one are absent. */
|
|
61
68
|
ofItems(ids: string[], scope: PluginIconScope): Promise<Map<string, string>>;
|
|
62
69
|
/**
|
|
@@ -71,6 +71,14 @@ let PluginIcons = class PluginIcons {
|
|
|
71
71
|
const icons = await this.resolve("name", names, scope);
|
|
72
72
|
return new Map(icons.map((i) => [i.name, i.url]));
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Extension (plugin) name -> the id of its catalog item, only for names whose item has an icon the
|
|
76
|
+
* org's catalog shows (the icon is `GET /api/v1/orgs/:orgId/catalog/:itemId/icon`).
|
|
77
|
+
*/
|
|
78
|
+
async itemIdsWithIcon(names, scope) {
|
|
79
|
+
const icons = await this.resolve("name", names, scope);
|
|
80
|
+
return new Map(icons.map((i) => [i.name, i.id]));
|
|
81
|
+
}
|
|
74
82
|
/** Catalog item id -> its icon's URL (a list of items); items without one are absent. */
|
|
75
83
|
async ofItems(ids, scope) {
|
|
76
84
|
const icons = await this.resolve("id", ids, scope);
|
package/dist/models/purposes.js
CHANGED
|
@@ -23,7 +23,7 @@ import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
|
23
23
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
24
24
|
import { OrgLock } from "../orgs/org-lock.js";
|
|
25
25
|
import { estimateTokens } from "../runtime/context/tokens.js";
|
|
26
|
-
import { consumeModelStream } from "../runtime/model-call.js";
|
|
26
|
+
import { consumeModelStream, deltaChars } from "../runtime/model-call.js";
|
|
27
27
|
import { ProviderListError, ProviderRegistry } from "../runtime/providers.js";
|
|
28
28
|
import { StorageService } from "../storage/storage.service.js";
|
|
29
29
|
import { IMAGE_PURPOSE, imagePurposeState } from "./image-usable.js";
|
|
@@ -423,7 +423,7 @@ let ModelPurposesService = class ModelPurposesService {
|
|
|
423
423
|
let chars = 0;
|
|
424
424
|
try {
|
|
425
425
|
const out = await consumeModelStream(provider, request, idleMs, signal, (ev) => {
|
|
426
|
-
chars += ev
|
|
426
|
+
chars += deltaChars(ev);
|
|
427
427
|
});
|
|
428
428
|
return {
|
|
429
429
|
content: out.content,
|
|
@@ -23,6 +23,12 @@ import { nestedConfig, withPersonInputs } from "./person-inputs.js";
|
|
|
23
23
|
import { roleOf } from "./role.js";
|
|
24
24
|
import { named, orElse } from "./summary.js";
|
|
25
25
|
const PAGE = 50;
|
|
26
|
+
/** A process display setting as the confirmation summary names it; null is the default. */
|
|
27
|
+
const PROCESS_DISPLAY_LABELS = {
|
|
28
|
+
zh: { detailed: "详细", brief: "简洁", off: "关闭", default: "默认" },
|
|
29
|
+
en: { detailed: "Detailed", brief: "Brief", off: "Off", default: "Default" },
|
|
30
|
+
};
|
|
31
|
+
const processLabel = (v, lang) => PROCESS_DISPLAY_LABELS[lang][v ?? "default"];
|
|
26
32
|
/**
|
|
27
33
|
* A connection as the tool shows it: the settings an admin sees on the channels page. The
|
|
28
34
|
* non-secret config and whether each secret is set, never a secret value (the service view holds
|
|
@@ -36,6 +42,7 @@ const detail = (c) => ({
|
|
|
36
42
|
status: c.status,
|
|
37
43
|
unboundPolicy: c.unboundPolicy,
|
|
38
44
|
inboundMode: c.inboundMode,
|
|
45
|
+
processDisplay: c.processDisplay,
|
|
39
46
|
webhookSupported: c.webhookSupported,
|
|
40
47
|
webhookUrl: c.webhookUrl,
|
|
41
48
|
lastError: c.lastError,
|
|
@@ -139,7 +146,7 @@ let ChannelsOperations = class ChannelsOperations {
|
|
|
139
146
|
}),
|
|
140
147
|
defineOperation({
|
|
141
148
|
id: "channels.create",
|
|
142
|
-
description: "Create a channel connection (IM bot) in the org (org admins): plugin, name, the agent that answers (agentId) and values, the non-secret connection config (read the fields with channels.schema). Secret fields (app secrets, tokens) are never in values: list them in askPerson and the person types them in a secure input request (on the web); required secrets are asked even when not listed. The plugin verifies the credentials before anything is saved. Turn on webhook inbound with inboundMode webhook (only where supported);
|
|
149
|
+
description: "Create a channel connection (IM bot) in the org (org admins): plugin, name, the agent that answers (agentId) and values, the non-secret connection config (read the fields with channels.schema). Secret fields (app secrets, tokens) are never in values: list them in askPerson and the person types them in a secure input request (on the web); required secrets are asked even when not listed. The plugin verifies the credentials before anything is saved. Turn on webhook inbound with inboundMode webhook (only where supported). processDisplay sets how runs show their process in the chat (detailed, brief or off; omit for the default: detailed in direct chats, brief in groups). A setup guide, if any, is in channels.schema.",
|
|
143
150
|
input: z
|
|
144
151
|
.object({
|
|
145
152
|
plugin: ChannelCreateSchema.shape.plugin,
|
|
@@ -148,6 +155,7 @@ let ChannelsOperations = class ChannelsOperations {
|
|
|
148
155
|
values: ChannelCreateSchema.shape.config,
|
|
149
156
|
unboundPolicy: ChannelCreateSchema.shape.unboundPolicy,
|
|
150
157
|
inboundMode: ChannelCreateSchema.shape.inboundMode,
|
|
158
|
+
processDisplay: ChannelCreateSchema.shape.processDisplay,
|
|
151
159
|
askPerson: personFieldParams.askPerson,
|
|
152
160
|
})
|
|
153
161
|
.strict(),
|
|
@@ -215,12 +223,16 @@ let ChannelsOperations = class ChannelsOperations {
|
|
|
215
223
|
keys.length > 0 && `设置 ${keys.join("、")}`,
|
|
216
224
|
ask.length > 0 && `由本人填写 ${ask.map(named).join("、")}`,
|
|
217
225
|
i.inboundMode === "webhook" && "入站方式:webhook",
|
|
226
|
+
typeof i.processDisplay === "string" &&
|
|
227
|
+
`过程显示:${processLabel(i.processDisplay, "zh")}`,
|
|
218
228
|
].filter((p) => typeof p === "string");
|
|
219
229
|
const en = [
|
|
220
230
|
`Create channel connection "${named(i.name)}" with plugin ${named(i.plugin)}, answered by agent ${named(i.agentId)}`,
|
|
221
231
|
keys.length > 0 && `sets ${keys.join(", ")}`,
|
|
222
232
|
ask.length > 0 && `the person enters ${ask.map(named).join(", ")}`,
|
|
223
233
|
i.inboundMode === "webhook" && "inbound mode: webhook",
|
|
234
|
+
typeof i.processDisplay === "string" &&
|
|
235
|
+
`process display: ${processLabel(i.processDisplay, "en")}`,
|
|
224
236
|
].filter((p) => typeof p === "string");
|
|
225
237
|
return { zh: zh.join(";"), en: en.join("; ") };
|
|
226
238
|
},
|
|
@@ -232,6 +244,7 @@ let ChannelsOperations = class ChannelsOperations {
|
|
|
232
244
|
config: nestedConfig(input.values, entered, []),
|
|
233
245
|
unboundPolicy: input.unboundPolicy,
|
|
234
246
|
inboundMode: input.inboundMode,
|
|
247
|
+
processDisplay: input.processDisplay,
|
|
235
248
|
}, ctx.actorAccountId, undefined, detail));
|
|
236
249
|
const webhook = input.inboundMode === "webhook";
|
|
237
250
|
return {
|
|
@@ -311,7 +324,7 @@ let ChannelsOperations = class ChannelsOperations {
|
|
|
311
324
|
}),
|
|
312
325
|
defineOperation({
|
|
313
326
|
id: "channels.update",
|
|
314
|
-
description: "Change a channel connection's binding (org admins): its name, the agent that answers (agentId), what happens to people not yet bound to an account (unboundPolicy: bind or anonymous), active or disabled, and the
|
|
327
|
+
description: "Change a channel connection's binding (org admins): its name, the agent that answers (agentId), what happens to people not yet bound to an account (unboundPolicy: bind or anonymous), active or disabled, the inbound mode, and how runs show their process in the chat (processDisplay: detailed, brief or off; null for the default, detailed in direct chats and brief in groups). Give only what changes. Credentials and config are changed on the web.",
|
|
315
328
|
input: ChannelPatchSchema.omit({ config: true })
|
|
316
329
|
.extend(ChannelPathParams.shape)
|
|
317
330
|
.strict()
|
|
@@ -319,7 +332,10 @@ let ChannelsOperations = class ChannelsOperations {
|
|
|
319
332
|
i.agentId !== undefined ||
|
|
320
333
|
i.unboundPolicy !== undefined ||
|
|
321
334
|
i.status !== undefined ||
|
|
322
|
-
i.inboundMode !== undefined
|
|
335
|
+
i.inboundMode !== undefined ||
|
|
336
|
+
i.processDisplay !== undefined, {
|
|
337
|
+
message: "give name, agentId, unboundPolicy, status, inboundMode or processDisplay",
|
|
338
|
+
}),
|
|
323
339
|
example: { connectionId: "00000000-0000-4000-8000-000000000000", status: "disabled" },
|
|
324
340
|
authz: { orgAction: "channels.manage" },
|
|
325
341
|
mirrors: ["PATCH /api/v1/orgs/:orgId/channels/:connectionId"],
|
|
@@ -354,9 +370,12 @@ let ChannelsOperations = class ChannelsOperations {
|
|
|
354
370
|
i.status !== undefined && `status → ${i.status}`,
|
|
355
371
|
i.inboundMode !== undefined && `inbound mode → ${i.inboundMode}`,
|
|
356
372
|
].filter((p) => typeof p === "string");
|
|
373
|
+
const pd = i.processDisplay;
|
|
374
|
+
const zh = pd === undefined ? parts : [...parts, `过程显示 → ${processLabel(pd, "zh")}`];
|
|
375
|
+
const en = pd === undefined ? parts : [...parts, `process display → ${processLabel(pd, "en")}`];
|
|
357
376
|
return {
|
|
358
|
-
zh: `修改渠道连接「${name}」:${
|
|
359
|
-
en: `Update channel connection "${name}": ${
|
|
377
|
+
zh: `修改渠道连接「${name}」:${zh.join(",")}`,
|
|
378
|
+
en: `Update channel connection "${name}": ${en.join(", ")}`,
|
|
360
379
|
};
|
|
361
380
|
},
|
|
362
381
|
run: async (input, ctx) => {
|