@ycodium-ai/plugin-api 0.2.5029 → 0.2.5093
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 +17 -1
- package/dist/_private/ycodium-executor-common/catalogModel.d.ts +9 -0
- package/dist/_private/ycodium-executor-common/catalogModel.js +39 -0
- package/dist/_private/ycodium-executor-common/eventTypes.d.ts +7 -0
- package/dist/_private/ycodium-executor-common/eventTypes.js +1 -0
- package/dist/_private/ycodium-executor-common/modelSelection.d.ts +7 -0
- package/dist/_private/ycodium-executor-common/modelSelection.js +24 -0
- package/dist/_private/ycodium-executor-common/nodeStreams.d.ts +44 -0
- package/dist/_private/ycodium-executor-common/nodeStreams.js +158 -0
- package/dist/_private/ycodium-executor-common/raceAbort.d.ts +8 -0
- package/dist/_private/ycodium-executor-common/raceAbort.js +25 -0
- package/dist/_private/ycodium-executor-common/reasoningLevelFallback.d.ts +13 -0
- package/dist/_private/ycodium-executor-common/reasoningLevelFallback.js +22 -0
- package/dist/_private/ycodium-executor-common/stderrTail.d.ts +9 -0
- package/dist/_private/ycodium-executor-common/stderrTail.js +29 -0
- package/dist/_private/ycodium-executor-common/toolPresentation.d.ts +19 -0
- package/dist/_private/ycodium-executor-common/toolPresentation.js +222 -0
- package/dist/dataPorts.gen.d.ts +689 -653
- package/dist/dataPorts.gen.d.ts.map +1 -1
- package/dist/dataPorts.gen.js.map +1 -1
- package/dist/executor.d.ts +3 -14
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +19 -47
- package/dist/executor.js.map +1 -1
- package/dist/executorEvents.d.ts +2 -1
- package/dist/executorEvents.d.ts.map +1 -1
- package/dist/executorEvents.js.map +1 -1
- package/dist/executorModelOptions.d.ts +0 -5
- package/dist/executorModelOptions.d.ts.map +1 -1
- package/dist/executorModelOptions.js +2 -16
- package/dist/executorModelOptions.js.map +1 -1
- package/dist/pluginContextCommands.d.ts +5 -3
- package/dist/pluginContextCommands.d.ts.map +1 -1
- package/dist/process-stdin.d.ts +1 -1
- package/dist/process-stdin.d.ts.map +1 -1
- package/dist/process-stdin.js +13 -124
- package/dist/process-stdin.js.map +1 -1
- package/dist/reasoningLevelFallback.d.ts +18 -0
- package/dist/reasoningLevelFallback.d.ts.map +1 -0
- package/dist/reasoningLevelFallback.js +9 -0
- package/dist/reasoningLevelFallback.js.map +1 -0
- package/dist/timeline-process.d.ts +32 -0
- package/dist/timeline-process.d.ts.map +1 -0
- package/dist/timeline-process.js +2 -0
- package/dist/timeline-process.js.map +1 -0
- package/dist/timeline-row-error.d.ts +15 -0
- package/dist/timeline-row-error.d.ts.map +1 -0
- package/dist/timeline-row-error.js +2 -0
- package/dist/timeline-row-error.js.map +1 -0
- package/dist/ui.d.ts +15 -0
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js.map +1 -1
- package/dist/version.d.ts +3 -3
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -615,7 +615,23 @@ No thread, timeout, interruption or restart cancels the call. Guard callbacks st
|
|
|
615
615
|
|
|
616
616
|
<!-- plugin-api-versions:start (generated by scripts/gen-plugin-api-version.ts from packages/plugin-api/version-history.json; edit that file) -->
|
|
617
617
|
|
|
618
|
-
The current API is **
|
|
618
|
+
The current API is **147**. This Ycodium loads plugins declaring 146 through 147.
|
|
619
|
+
|
|
620
|
+
API 147 adds the optional `peerRemote` `{ principalId, remoteThreadId }` to `communication.wakeLoops.list` entries and `communication.wakeLoops.resume` input: a pair with a session on another machine of the project now counts toward the eight-exchange wake-up limit, and the person on the home machine continues it by that peer. `work.remoteAgentPending.get` wake entries gain the optional `pausedThreads`: the member machine's sessions this wake must not start a turn for. Older hosts omit both fields; no other public type changes.
|
|
621
|
+
|
|
622
|
+
API 146 removes `ctx.work.comments.post` and its `asPerson` counterpart, and the `work.comment.post` command from what a plugin can declare: a comment on a work item is now a post, sent with `ctx.communication.posts.send({ to: { workItemId } })` (declare `communication.post.send`). `ctx.work.comments.list` and `.get` stay and read the older comments only.
|
|
623
|
+
|
|
624
|
+
API 146 adds `ctx.communication.posts.send` for plugins (declare the `communication.post.send` command; `asPerson` is accepted too): post on a work item's discussion, in a group or to a session or person. A plugin may now reply on a work item or in a group, to a post or older comment on the same work item or group (a reply elsewhere is refused with `invalid-input`, reason `other-anchor`); one-to-one replies stay refused. `communication.records.send` also takes `to: { workItemId }` and writes a post on that work item, with `mentions` naming members and `replyTo` a post or older comment on it.
|
|
625
|
+
|
|
626
|
+
API 145 adds the `offline-rejected` verb and the `offline-rejection` change to `work.history.list` entries: the home machine rejected a change a member machine had kept while the home was offline, and the item's history records which change it was (`capabilityId`, `operationId`, `sourceEnvironmentId`, `reason`, the original `input`), with the home machine's explanation as a `note`. Older hosts never write it; readers that skip unknown verbs are unaffected. No other public type changes.
|
|
627
|
+
|
|
628
|
+
API 145 adds the optional `worktreeProbePaths` flag to the machine capabilities in `machineSettings.config.get`: the machine can limit worktree status probing to the paths a client names. Older hosts leave it out. No other public type changes.
|
|
629
|
+
|
|
630
|
+
API 144 adds `ctx.projects.homeOutbox.list`: lists this machine's writes kept while the project's home machine was unreachable, with `status` `pending`, `unknown` or `rejected`. Reads only this machine; requires `work.read`. The retry and discard commands are not available to plugins (not-for-plugins).
|
|
631
|
+
|
|
632
|
+
API 144 adds the host UI primitive `TimelineRowErrorFallback` (`bridge.ui`, props `TimelineRowErrorFallbackProps`): the placeholder a timeline row shows when it fails to render. Adds `PluginUiDocumentPanelProps`, the props of the host `DocumentPanel`. Adds the host UI primitives `TimelineProcessShell`, `ProcessRowIcon`, `WorkEntryStatusDot` and `WorkEntryIcon` (props `TimelineProcessShellProps`, `ProcessRowIconProps`, `WorkEntryStatusDotProps`, `WorkEntryIconProps`, with `TimelineProcessState` and `WorkEntryIconName`): the collapsed process row of the timeline.
|
|
633
|
+
|
|
634
|
+
API 144 declares `ExecutorEventType` as an alias of the same event-type union, now defined once and shipped inside the package build together with `matchCatalogModel`'s rule; nothing plugins can call or match on changes. `raceAbort`, `nodeStreamsFromHandle`, `modelSelectionStringOption`, and `reasoningLevelFallbackWarning` (the `runtime.warning` payload whose `detail.code` is `reasoning-level-fallback`) are defined once in that same shared source and re-exported with the same signatures.
|
|
619
635
|
|
|
620
636
|
API 143 adds machineSettings.sync status reads and subscriptions, and local agent exclusion/restoration using the existing machineSettings.update permission; secret values remain unreadable
|
|
621
637
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 宿主要的型号在手的型号目录里对应哪一个取值:`@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
3
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist。
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 先精确匹配,再按最后一段唯一匹配;两个取值最后一段相同就不猜(不同 provider 的地址与凭据不同)。
|
|
7
|
+
* 对不上返回 `undefined`,调用方不设型号。完整理由见 `@ycodium-ai/plugin-api/executor` 的同名函数。
|
|
8
|
+
*/
|
|
9
|
+
export declare function matchCatalogModel(requested: string | undefined, catalog: ReadonlyArray<string>): string | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 宿主要的型号在手的型号目录里对应哪一个取值:`@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
3
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist。
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 目录里一个取值的「最后一段」:dsh 的 JSON 元组 `["deepseek-official","deepseek-flash"]`
|
|
7
|
+
* 取最后一个元素(至少两段),opencode 的 `provider/model` 取第一个斜杠之后(模型名里
|
|
8
|
+
* 可以再带斜杠,opencode 自己也只在第一个斜杠处切)。别的形状没有最后一段。
|
|
9
|
+
*/
|
|
10
|
+
function catalogModelLastSegment(value) {
|
|
11
|
+
if (value.startsWith("[")) {
|
|
12
|
+
let parsed;
|
|
13
|
+
try {
|
|
14
|
+
parsed = JSON.parse(value);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
if (!Array.isArray(parsed) || parsed.length < 2)
|
|
20
|
+
return undefined;
|
|
21
|
+
const last = parsed[parsed.length - 1];
|
|
22
|
+
return typeof last === "string" ? last : undefined;
|
|
23
|
+
}
|
|
24
|
+
const separator = value.indexOf("/");
|
|
25
|
+
return separator > 0 && separator < value.length - 1 ? value.slice(separator + 1) : undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 先精确匹配,再按最后一段唯一匹配;两个取值最后一段相同就不猜(不同 provider 的地址与凭据不同)。
|
|
29
|
+
* 对不上返回 `undefined`,调用方不设型号。完整理由见 `@ycodium-ai/plugin-api/executor` 的同名函数。
|
|
30
|
+
*/
|
|
31
|
+
export function matchCatalogModel(requested, catalog) {
|
|
32
|
+
const wanted = requested?.trim();
|
|
33
|
+
if (!wanted)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (catalog.includes(wanted))
|
|
36
|
+
return wanted;
|
|
37
|
+
const byLastSegment = catalog.filter((value) => catalogModelLastSegment(value) === wanted);
|
|
38
|
+
return byLastSegment.length === 1 ? byLastSegment[0] : undefined;
|
|
39
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 执行器事件的 `type` 闭集:`@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
3
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist;
|
|
4
|
+
* `ycodium-acp-executor` 因此仍不在运行时依赖 plugin-api,plugin-api 也仍没有运行时依赖。
|
|
5
|
+
*/
|
|
6
|
+
/** `type` 闭集与 contracts 的 `ProviderRuntimeEventType` 相同(含 `tool.denied`),不另造事件词汇。 */
|
|
7
|
+
export type ExecutorEventType = "session.started" | "session.configured" | "session.state.changed" | "session.exited" | "thread.started" | "thread.state.changed" | "thread.metadata.updated" | "thread.token-usage.updated" | "thread.realtime.started" | "thread.realtime.item-added" | "thread.realtime.audio.delta" | "thread.realtime.error" | "thread.realtime.closed" | "turn.started" | "turn.completed" | "turn.aborted" | "turn.plan.updated" | "turn.proposed.delta" | "turn.proposed.completed" | "turn.diff.updated" | "item.started" | "item.updated" | "item.completed" | "content.delta" | "request.opened" | "request.resolved" | "user-input.requested" | "user-input.resolved" | "task.started" | "task.progress" | "task.updated" | "task.completed" | "hook.started" | "hook.progress" | "hook.completed" | "tool.progress" | "tool.summary" | "tool.denied" | "auth.status" | "account.updated" | "account.rate-limits.updated" | "mcp.status.updated" | "mcp.oauth.completed" | "model.rerouted" | "config.warning" | "deprecation.notice" | "files.persisted" | "assistant.attachment.produced" | "assistant.artifact.produced" | "runtime.warning" | "runtime.error";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 从 `ModelSelection` 形状里读出某个字符串选项的值。
|
|
3
|
+
* 空串按缺席处理:界面清掉一个选项时留的是空串,发一个空值出去等于让 CLI 用空档。
|
|
4
|
+
* `@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
5
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist。
|
|
6
|
+
*/
|
|
7
|
+
export declare function modelSelectionStringOption(selection: unknown, optionId: string): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 从 `ModelSelection` 形状里读出某个字符串选项的值。
|
|
3
|
+
* 空串按缺席处理:界面清掉一个选项时留的是空串,发一个空值出去等于让 CLI 用空档。
|
|
4
|
+
* `@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
5
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist。
|
|
6
|
+
*/
|
|
7
|
+
export function modelSelectionStringOption(selection, optionId) {
|
|
8
|
+
if (typeof selection !== "object" || selection === null || Array.isArray(selection)) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
const options = selection["options"];
|
|
12
|
+
if (!Array.isArray(options))
|
|
13
|
+
return undefined;
|
|
14
|
+
for (const entry of options) {
|
|
15
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry))
|
|
16
|
+
continue;
|
|
17
|
+
const record = entry;
|
|
18
|
+
if (record["id"] !== optionId)
|
|
19
|
+
continue;
|
|
20
|
+
const value = record["value"];
|
|
21
|
+
return typeof value === "string" ? value.trim() || undefined : undefined;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as NodeStream from "node:stream";
|
|
2
|
+
/** 判「这次失败是不是因为对端没了」。真异常返回 false,交给调用方照旧处理。 */
|
|
3
|
+
export declare function isPeerClosedStdinError(error: unknown): boolean;
|
|
4
|
+
/** 对端没了导致这次写没送到。`code` 保留原始那一个,诊断不丢。 */
|
|
5
|
+
export declare class PeerClosedStdinError extends Error {
|
|
6
|
+
readonly name = "PeerClosedStdinError";
|
|
7
|
+
readonly code: string;
|
|
8
|
+
constructor(operation: "write" | "close", cause?: unknown);
|
|
9
|
+
}
|
|
10
|
+
/** 调用方要认的「对端没了」错误。不传就用本模块这份,形状与 plugin-api 的公开类相同。 */
|
|
11
|
+
export type StdinPeerErrors = {
|
|
12
|
+
readonly isPeerClosed: (error: unknown) => boolean;
|
|
13
|
+
readonly peerClosed: (operation: "write" | "close", cause?: unknown) => Error;
|
|
14
|
+
};
|
|
15
|
+
/** 宿主 `process.spawn` 句柄里与流有关的那几位;`kill` / `exited` 由调用方自己拿。 */
|
|
16
|
+
export type SpawnHandle = {
|
|
17
|
+
readonly stdout: AsyncIterable<Uint8Array>;
|
|
18
|
+
readonly stderr: AsyncIterable<Uint8Array>;
|
|
19
|
+
readonly writeStdin: (chunk: Uint8Array | string) => Promise<void>;
|
|
20
|
+
readonly closeStdin: () => Promise<void>;
|
|
21
|
+
};
|
|
22
|
+
/** 写失败同时投给回调与流;调用方必须接住 `'error'`,真异常不能吞掉。 */
|
|
23
|
+
export declare function nodeWritableFromHandle(handle: Pick<SpawnHandle, "writeStdin" | "closeStdin">, errors?: StdinPeerErrors): NodeStream.Writable;
|
|
24
|
+
/**
|
|
25
|
+
* stderr 尾巴要进给用户看的错误,先脱敏:家目录换成 `~`,配对链接、Bearer、Basic、
|
|
26
|
+
* x-api-key 与常见密钥前缀一律遮掉。
|
|
27
|
+
*/
|
|
28
|
+
export declare function redactStderrExcerpt(text: string, environment?: Readonly<Record<string, string | undefined>>): string;
|
|
29
|
+
/** 已脱敏的 stderr 只留最后不超过 `maxChars` 字。调用方先 trim 的那一步在 `lastStderrTail`。 */
|
|
30
|
+
export declare function lastStderrLines(redacted: string, maxChars: number): string;
|
|
31
|
+
/**
|
|
32
|
+
* 从启动起抽干 stderr:宿主那条队列有界,不抽会把子进程写堵死。抽的同时按 UTF-8 流式解码、留最后几 KiB;
|
|
33
|
+
* 返回的函数等它读完(最多半秒)后交出脱敏的那一段,给「启动期就退出」的错误点名原因。
|
|
34
|
+
*/
|
|
35
|
+
export declare function drainStderrTail(stderr: AsyncIterable<Uint8Array>): () => Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* 把 `host.process.spawn` 的句柄折成协议库要的 Node 流。
|
|
38
|
+
* stderr 由 `drainStderrTail` 抽干,`stderrTail()` 交出脱敏的末尾一段。
|
|
39
|
+
*/
|
|
40
|
+
export declare function nodeStreamsFromHandle(handle: SpawnHandle, errors?: StdinPeerErrors): {
|
|
41
|
+
readonly readable: NodeStream.Readable;
|
|
42
|
+
readonly writable: NodeStream.Writable;
|
|
43
|
+
readonly stderrTail: () => Promise<string>;
|
|
44
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// @effect-diagnostics globalTimers:off - 等 stderr 读完的上限只能用 setTimeout。
|
|
2
|
+
/**
|
|
3
|
+
* 把 `host.process.spawn` 的句柄折成 Node 流,并抽干 stderr 尾巴。
|
|
4
|
+
* `@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
5
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist。
|
|
6
|
+
* plugin-api 仍导出自己的 `PeerClosedStdinError`(`instanceof` 认那一份),调用时传进来。
|
|
7
|
+
*/
|
|
8
|
+
import { lastStderrTail } from "./stderrTail.js";
|
|
9
|
+
import * as NodeOS from "node:os";
|
|
10
|
+
import * as NodeStream from "node:stream";
|
|
11
|
+
/** 对端已关:Node 与 libuv 在这几个 code 上说的是同一件事。 */
|
|
12
|
+
const PEER_CLOSED_STDIN_CODES = new Set([
|
|
13
|
+
"EPIPE",
|
|
14
|
+
"ECONNRESET",
|
|
15
|
+
"EOF",
|
|
16
|
+
"ERR_STREAM_DESTROYED",
|
|
17
|
+
"ERR_STREAM_WRITE_AFTER_END",
|
|
18
|
+
"ERR_STREAM_ALREADY_FINISHED",
|
|
19
|
+
]);
|
|
20
|
+
function errorCode(value) {
|
|
21
|
+
if (typeof value !== "object" || value === null)
|
|
22
|
+
return undefined;
|
|
23
|
+
const code = value.code;
|
|
24
|
+
return typeof code === "string" ? code : undefined;
|
|
25
|
+
}
|
|
26
|
+
function asError(value) {
|
|
27
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
28
|
+
}
|
|
29
|
+
/** 判「这次失败是不是因为对端没了」。真异常返回 false,交给调用方照旧处理。 */
|
|
30
|
+
export function isPeerClosedStdinError(error) {
|
|
31
|
+
const code = errorCode(error);
|
|
32
|
+
return code !== undefined && PEER_CLOSED_STDIN_CODES.has(code);
|
|
33
|
+
}
|
|
34
|
+
/** 对端没了导致这次写没送到。`code` 保留原始那一个,诊断不丢。 */
|
|
35
|
+
export class PeerClosedStdinError extends Error {
|
|
36
|
+
name = "PeerClosedStdinError";
|
|
37
|
+
code;
|
|
38
|
+
constructor(operation, cause) {
|
|
39
|
+
super(`Child process stdin is closed; the ${operation} did not reach the peer.`, cause === undefined ? undefined : { cause });
|
|
40
|
+
this.code = errorCode(cause) ?? "ERR_STREAM_DESTROYED";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const ownErrors = {
|
|
44
|
+
isPeerClosed: isPeerClosedStdinError,
|
|
45
|
+
peerClosed: (operation, cause) => new PeerClosedStdinError(operation, cause),
|
|
46
|
+
};
|
|
47
|
+
function toStreamError(errors, operation, error) {
|
|
48
|
+
if (errors.isPeerClosed(error))
|
|
49
|
+
return errors.peerClosed(operation, error);
|
|
50
|
+
return asError(error);
|
|
51
|
+
}
|
|
52
|
+
/** 写失败同时投给回调与流;调用方必须接住 `'error'`,真异常不能吞掉。 */
|
|
53
|
+
export function nodeWritableFromHandle(handle, errors = ownErrors) {
|
|
54
|
+
return new NodeStream.Writable({
|
|
55
|
+
write(chunk, _encoding, callback) {
|
|
56
|
+
const bytes = typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk;
|
|
57
|
+
handle.writeStdin(bytes).then(() => callback(), (error) => callback(toStreamError(errors, "write", error)));
|
|
58
|
+
},
|
|
59
|
+
final(callback) {
|
|
60
|
+
handle.closeStdin().then(() => callback(),
|
|
61
|
+
// 关一条对端已经没了的流是正常收尾,不是失败;真异常照旧交出去。
|
|
62
|
+
(error) => callback(errors.isPeerClosed(error) ? undefined : toStreamError(errors, "close", error)));
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** 留给启动失败诊断的 stderr 尾巴上限(字符)。 */
|
|
67
|
+
const STDERR_TAIL_MAX_CHARS = 4_096;
|
|
68
|
+
/** 取尾巴时最多等 stderr 读完这么久。 */
|
|
69
|
+
const STDERR_SETTLE_MS = 500;
|
|
70
|
+
const PAIRING_URL_PATTERN = /https?:\/\/[^\s]*\/pair#[^\s]*/gi;
|
|
71
|
+
const BEARER_TOKEN_PATTERN = /\bBearer\s+[A-Za-z0-9._\-+=/]+/gi;
|
|
72
|
+
const BASIC_AUTH_PATTERN = /\bAuthorization:\s*Basic\s+\S+/gi;
|
|
73
|
+
const API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi;
|
|
74
|
+
const SECRET_TOKEN_PATTERN = /\b(?:sk-[A-Za-z0-9][A-Za-z0-9-]{7,}|ghp_[A-Za-z0-9]+|xox[a-zA-Z]-[A-Za-z0-9-]+)\b/g;
|
|
75
|
+
/**
|
|
76
|
+
* stderr 尾巴要进给用户看的错误,先脱敏:家目录换成 `~`,配对链接、Bearer、Basic、
|
|
77
|
+
* x-api-key 与常见密钥前缀一律遮掉。
|
|
78
|
+
*/
|
|
79
|
+
export function redactStderrExcerpt(text, environment = process.env) {
|
|
80
|
+
let result = text.replaceAll("\0", "");
|
|
81
|
+
const homes = [environment["HOME"], environment["USERPROFILE"], NodeOS.homedir()].filter((value) => typeof value === "string" && value.length > 1);
|
|
82
|
+
for (const home of new Set(homes)) {
|
|
83
|
+
result = result.split(home).join("~");
|
|
84
|
+
}
|
|
85
|
+
return result
|
|
86
|
+
.replace(PAIRING_URL_PATTERN, "[pairing-url]")
|
|
87
|
+
.replace(BEARER_TOKEN_PATTERN, "Bearer [redacted]")
|
|
88
|
+
.replace(BASIC_AUTH_PATTERN, "Authorization: Basic [redacted]")
|
|
89
|
+
.replace(API_KEY_HEADER_PATTERN, "x-api-key: [redacted]")
|
|
90
|
+
.replace(SECRET_TOKEN_PATTERN, "[redacted]")
|
|
91
|
+
.trim();
|
|
92
|
+
}
|
|
93
|
+
/** 已脱敏的 stderr 只留最后不超过 `maxChars` 字。调用方先 trim 的那一步在 `lastStderrTail`。 */
|
|
94
|
+
export function lastStderrLines(redacted, maxChars) {
|
|
95
|
+
return lastStderrTail(redacted.trim(), maxChars);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 从启动起抽干 stderr:宿主那条队列有界,不抽会把子进程写堵死。抽的同时按 UTF-8 流式解码、留最后几 KiB;
|
|
99
|
+
* 返回的函数等它读完(最多半秒)后交出脱敏的那一段,给「启动期就退出」的错误点名原因。
|
|
100
|
+
*/
|
|
101
|
+
export function drainStderrTail(stderr) {
|
|
102
|
+
let tail = "";
|
|
103
|
+
const decoder = new TextDecoder();
|
|
104
|
+
const drained = (async () => {
|
|
105
|
+
for await (const chunk of stderr) {
|
|
106
|
+
const next = tail + decoder.decode(chunk, { stream: true });
|
|
107
|
+
tail = next.length <= STDERR_TAIL_MAX_CHARS ? next : next.slice(-STDERR_TAIL_MAX_CHARS);
|
|
108
|
+
}
|
|
109
|
+
})().catch(() => undefined);
|
|
110
|
+
// 进程的别的出口到头时 stderr 未必已读完(各走各的管道):等它读完再取,但不无限等——
|
|
111
|
+
// 子进程关了别的管道却还活着时,stderr 不会到头。
|
|
112
|
+
return async () => {
|
|
113
|
+
let timer;
|
|
114
|
+
await Promise.race([
|
|
115
|
+
drained,
|
|
116
|
+
new Promise((resolve) => {
|
|
117
|
+
timer = setTimeout(resolve, STDERR_SETTLE_MS);
|
|
118
|
+
}),
|
|
119
|
+
]);
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
return redactStderrExcerpt(tail);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 把 `host.process.spawn` 的句柄折成协议库要的 Node 流。
|
|
126
|
+
* stderr 由 `drainStderrTail` 抽干,`stderrTail()` 交出脱敏的末尾一段。
|
|
127
|
+
*/
|
|
128
|
+
export function nodeStreamsFromHandle(handle, errors = ownErrors) {
|
|
129
|
+
const readable = new NodeStream.PassThrough();
|
|
130
|
+
void (async () => {
|
|
131
|
+
try {
|
|
132
|
+
for await (const chunk of handle.stdout) {
|
|
133
|
+
if (!readable.writable)
|
|
134
|
+
return;
|
|
135
|
+
if (!readable.write(chunk)) {
|
|
136
|
+
await new Promise((resolve) => {
|
|
137
|
+
const onDone = () => {
|
|
138
|
+
readable.off("drain", onDone);
|
|
139
|
+
readable.off("close", onDone);
|
|
140
|
+
resolve();
|
|
141
|
+
};
|
|
142
|
+
readable.once("drain", onDone);
|
|
143
|
+
readable.once("close", onDone);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
readable.destroy(asError(error));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (readable.writable)
|
|
153
|
+
readable.end();
|
|
154
|
+
})();
|
|
155
|
+
const settledStderrTail = drainStderrTail(handle.stderr);
|
|
156
|
+
const writable = nodeWritableFromHandle(handle, errors);
|
|
157
|
+
return { readable, writable, stderrTail: settledStderrTail };
|
|
158
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 等到 `pending` 结束;`signal` 已中止就抛 `Error("aborted")`,不再等下去。
|
|
3
|
+
* 先接住 `pending` 自己的拒绝:中止赢了这场等待之后,那支再拒绝就没人处理。
|
|
4
|
+
* 不传 `signal` 就只等 `pending`。这支不杀进程,杀进程只在宿主的 spawn。
|
|
5
|
+
* `@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
6
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist。
|
|
7
|
+
*/
|
|
8
|
+
export declare function raceAbort<T>(pending: Promise<T>, signal?: AbortSignal | undefined): Promise<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 等到 `pending` 结束;`signal` 已中止就抛 `Error("aborted")`,不再等下去。
|
|
3
|
+
* 先接住 `pending` 自己的拒绝:中止赢了这场等待之后,那支再拒绝就没人处理。
|
|
4
|
+
* 不传 `signal` 就只等 `pending`。这支不杀进程,杀进程只在宿主的 spawn。
|
|
5
|
+
* `@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
6
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist。
|
|
7
|
+
*/
|
|
8
|
+
export async function raceAbort(pending, signal) {
|
|
9
|
+
if (signal === undefined)
|
|
10
|
+
return pending;
|
|
11
|
+
void pending.catch(() => undefined);
|
|
12
|
+
if (signal.aborted)
|
|
13
|
+
throw new Error("aborted");
|
|
14
|
+
let onAbort;
|
|
15
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
16
|
+
onAbort = () => reject(new Error("aborted"));
|
|
17
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
18
|
+
});
|
|
19
|
+
try {
|
|
20
|
+
return await Promise.race([pending, aborted]);
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
signal.removeEventListener("abort", onAbort);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function reasoningLevelFallbackWarning(input: {
|
|
2
|
+
readonly model: string | undefined;
|
|
3
|
+
readonly requestedEffort: string;
|
|
4
|
+
readonly appliedEffort: string | undefined;
|
|
5
|
+
}): {
|
|
6
|
+
message: string;
|
|
7
|
+
detail: {
|
|
8
|
+
appliedEffort?: string;
|
|
9
|
+
requestedEffort: string;
|
|
10
|
+
model?: string;
|
|
11
|
+
code: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 存的推理强度当前型号不认、这一轮没用上它时发的 `runtime.warning` 载荷。客户端按 `detail.code` 用本地化文案重画;
|
|
3
|
+
* `message` 是英文兜底,只给不认这个 code 的表面。`appliedEffort` 缺席表示实际档位由 agent 定,不能说成默认档。
|
|
4
|
+
* `@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
5
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist。
|
|
6
|
+
*/
|
|
7
|
+
const REASONING_LEVEL_FALLBACK_CODE = "reasoning-level-fallback";
|
|
8
|
+
export function reasoningLevelFallbackWarning(input) {
|
|
9
|
+
const model = input.model ?? "This model";
|
|
10
|
+
const outcome = input.appliedEffort === undefined
|
|
11
|
+
? "so the agent picks this turn's level"
|
|
12
|
+
: `so this turn uses its default, "${input.appliedEffort}"`;
|
|
13
|
+
return {
|
|
14
|
+
message: `${model} does not offer the "${input.requestedEffort}" reasoning effort, ${outcome}. Your saved choice is unchanged.`,
|
|
15
|
+
detail: {
|
|
16
|
+
code: REASONING_LEVEL_FALLBACK_CODE,
|
|
17
|
+
...(input.model === undefined ? {} : { model: input.model }),
|
|
18
|
+
requestedEffort: input.requestedEffort,
|
|
19
|
+
...(input.appliedEffort === undefined ? {} : { appliedEffort: input.appliedEffort }),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 已脱敏 stderr 的末尾一段:`@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
3
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist。
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 末尾不超过 `maxChars` 字。能从整行开始就从整行开始;只有一行时照字数截,但不劈开代理对,
|
|
7
|
+
* 截点落在脱敏标记里就从标记之后开始。调用方先 trim。
|
|
8
|
+
*/
|
|
9
|
+
export declare function lastStderrTail(text: string, maxChars: number): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 已脱敏 stderr 的末尾一段:`@ycodium-ai/plugin-api` 与 `ycodium-acp-executor` 共用这一份。本包不发布,
|
|
3
|
+
* 两个发布包构建时由 scripts/lib/inline-private-packages.mjs 把它内联进各自的 dist。
|
|
4
|
+
*/
|
|
5
|
+
/** `redactStderrExcerpt` 换进去的标记:截尾时不能只留半个。 */
|
|
6
|
+
const REDACTION_MARKERS = ["[redacted]", "[pairing-url]"];
|
|
7
|
+
/**
|
|
8
|
+
* 末尾不超过 `maxChars` 字。能从整行开始就从整行开始;只有一行时照字数截,但不劈开代理对,
|
|
9
|
+
* 截点落在脱敏标记里就从标记之后开始。调用方先 trim。
|
|
10
|
+
*/
|
|
11
|
+
export function lastStderrTail(text, maxChars) {
|
|
12
|
+
if (text.length <= maxChars)
|
|
13
|
+
return text;
|
|
14
|
+
let start = text.length - maxChars;
|
|
15
|
+
if (text[start - 1] !== "\n") {
|
|
16
|
+
const lineEnd = text.indexOf("\n", start);
|
|
17
|
+
if (lineEnd !== -1 && lineEnd < text.length - 1)
|
|
18
|
+
return text.slice(lineEnd + 1);
|
|
19
|
+
const code = text.charCodeAt(start);
|
|
20
|
+
if (code >= 0xdc00 && code <= 0xdfff)
|
|
21
|
+
start += 1;
|
|
22
|
+
for (const marker of REDACTION_MARKERS) {
|
|
23
|
+
const at = text.lastIndexOf(marker, start);
|
|
24
|
+
if (at !== -1 && at < start && start < at + marker.length)
|
|
25
|
+
start = at + marker.length;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return text.slice(start);
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具活动摘要行的唯一规则:ACP 执行器与 `@ycodium/shared/toolActivity`(服务器、客户端)共用。
|
|
3
|
+
* 本包不发布;`ycodium-acp-executor` 构建时把它内联进 dist,shared 直接引源码。只依赖本模块自己。
|
|
4
|
+
*/
|
|
5
|
+
export declare function normalizeCommandValue(value: unknown): string | undefined;
|
|
6
|
+
export declare function extractToolCommand(data: Record<string, unknown> | undefined, title: string | undefined): string | undefined;
|
|
7
|
+
export type ToolActivityPresentation = {
|
|
8
|
+
readonly summary: string;
|
|
9
|
+
readonly detail?: string;
|
|
10
|
+
};
|
|
11
|
+
/** `itemType` 收宿主 `ToolLifecycleItemType` 的全集;规则只认其中三种。 */
|
|
12
|
+
export interface ToolActivityPresentationInput {
|
|
13
|
+
readonly itemType?: string | null | undefined;
|
|
14
|
+
readonly title?: string | null | undefined;
|
|
15
|
+
readonly detail?: string | null | undefined;
|
|
16
|
+
readonly data?: unknown;
|
|
17
|
+
readonly fallbackSummary?: string | null | undefined;
|
|
18
|
+
}
|
|
19
|
+
export declare function deriveToolActivityPresentation(input: ToolActivityPresentationInput): ToolActivityPresentation;
|