@kangyishuai/dsh-advisor 0.1.0 → 0.3.0
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 +65 -37
- package/README.zh-CN.md +49 -27
- package/lib/adoption.js +12 -6
- package/lib/budget.js +100 -0
- package/lib/call.js +8 -3
- package/lib/catalog.js +143 -0
- package/lib/client.js +1790 -343
- package/lib/ledger.js +66 -1
- package/lib/prompt.js +21 -0
- package/lib/route.js +5 -2
- package/lib/service.js +354 -14
- package/lib/settings.js +79 -10
- package/lib/trace.js +31 -0
- package/lib/twopass.js +60 -0
- package/lib/verifier.js +107 -0
- package/locale/en.json +122 -26
- package/locale/zh.json +128 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,29 +53,46 @@ Re-run `pnpm pack` + `add` after changing the code. The plugin has a host half a
|
|
|
53
53
|
|
|
54
54
|
Settings live in one JSON file, `<DSH_HOME>/advisor.settings.json` (`DSH_HOME` defaults to `~/.dsh`; the plugin's `dataRoot` config overrides it). The host re-reads the file before each consultation (1 s cache), so editing it applies to the next call without a restart. Unknown keys are dropped, out-of-range numbers are clamped, and a corrupt file falls back to the defaults. **The default is `off`** — a plugin that spends money and sends conversation content stays opt-in.
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
56
|
+
**Settings UI.** Settings → General → Advisor. With the default `off`, the card shows only the mode, a one-line status and “Configure advisor”. Expanding or enabling it reveals:
|
|
57
|
+
|
|
58
|
+
- **Basics**: mode, provider, model, reasoning effort, daily budget, send scope, redaction.
|
|
59
|
+
- **Advanced** (folded by default): call limits, workspace limits, prices, output/input caps, advice-item cap, allowlist, auto-review, file reading, shadow dedupe, sent-content recording. The heading shows “Defaults” or “N changed”.
|
|
60
|
+
- **Status & diagnostics** (folded by default): calls/tokens/cost, last result/skip reason, send preview, diagnostics, settings and ledger paths.
|
|
61
|
+
|
|
62
|
+
The “?” next to an advanced field expands an inline help block (click or activate with the keyboard) with the description, default/range and technical key; hover is only a supplement. Click **Save** to apply changes to the next consultation.
|
|
63
|
+
|
|
64
|
+
Money fields accept decimals: budgets up to 2, unit prices up to 4.
|
|
65
|
+
|
|
66
|
+
| Key | UI label | Default | Range / values | Meaning |
|
|
67
|
+
| --------------------------- | ------------------------------ | ----------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
68
|
+
| `mode` | Mode | `"off"` | off / shadow / advisory | Whether the plugin may consult at all. Off by default; opt in explicitly. |
|
|
69
|
+
| `provider` | Provider | `""` | route name from Settings → Models, ≤300 chars | Advisor route. Empty means never call. |
|
|
70
|
+
| `model` | Model | `""` | model id under that route, ≤300 chars | Advisor model. Empty means never call. |
|
|
71
|
+
| `reasoningEffort` | Reasoning effort | `""` | a supported effort id, `""` = model default | An unsupported value is retried once without an effort. |
|
|
72
|
+
| `maxTokens` | Output limit | `4096` | 256–32000 | Maximum output tokens per consultation. |
|
|
73
|
+
| `temperature` | Randomness | `null` | 0–2, `null` = not sent | Empty lets the model decide. |
|
|
74
|
+
| `maxCallsPerTurn` | Calls per turn | `1` | 0–8, 0 = unlimited | Maximum consultations per turn. |
|
|
75
|
+
| `maxCallsPerSession` | Calls per session | `32` | 0–1000, 0 = unlimited | Maximum consultations per session. |
|
|
76
|
+
| `maxCallsPerHour` | Calls per hour | `12` | 0–500, 0 = unlimited | Sliding one-hour window. |
|
|
77
|
+
| `maxCostPerDayUsd` | Daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Daily spend ceiling in USD; only counted when prices are set. |
|
|
78
|
+
| `priceInputPerMTok` | Input price | `0` | 0–1000; up to 4 decimals | Advisor input price, USD per 1M tokens; 0 = do not price. |
|
|
79
|
+
| `priceOutputPerMTok` | Output price | `0` | 0–1000; up to 4 decimals | Output price, USD per 1M tokens. |
|
|
80
|
+
| `privacyScope` | Send scope | `"summary"` | off / summary / full | How much conversation content is sent — see Cost & privacy. |
|
|
81
|
+
| `redact` | Redact before sending | `true` | boolean | Best-effort masking of common key formats; not a guarantee. |
|
|
82
|
+
| `immuneTurns` | JSON only: Immune turns | `3` | 0–20 | Turns to stay quiet after a delivery; used by shadow delivery. |
|
|
83
|
+
| `dedupe` | Dedupe in shadow mode | `true` | boolean | In shadow mode, the same advice is recorded once; the tool path does not block on it. |
|
|
84
|
+
| `sessionCap` | Advice items per session | `24` | 0–200 | Max advice items shown per session; once reached only blockers get through. |
|
|
85
|
+
| `tiers` | JSON only: Tiers | `{}` | `"provider/model"` → number | Capability ranks for the pairing check; without an entry the pairing is unverified. |
|
|
86
|
+
| `allowedModels` | Model allowlist | `[]` | string array | Empty = no limit; accepts provider/model or a bare model id. |
|
|
87
|
+
| `confirmedHosts` | JSON/button: Confirmed hosts | `[]` | string array | Cross-provider confirmation list; the settings-card button writes it. |
|
|
88
|
+
| `pairingEnforcement` | JSON only: Pairing enforcement | `"warn"` | warn / block | When the advisor tier is lower: warn allows and warns; block refuses. |
|
|
89
|
+
| `workspaceMaxCallsPerDay` | Workspace calls per day | `200` | 0–100000, 0 = unlimited | Workspace-wide, shared across sessions, resets on the local day. |
|
|
90
|
+
| `workspaceMaxCostPerDayUsd` | Workspace daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Workspace-wide daily spend ceiling. |
|
|
91
|
+
| `postAnswer` | Auto-review after each turn | `"off"` | off / card | In advisory mode, runs once after each answer; records only, never inserts. |
|
|
92
|
+
| `advisorTools` | Let the advisor read files | `false` | boolean | Lets it read working-directory files (up to 5, read-only); costs one extra call. |
|
|
93
|
+
| `tracePrompt` | Keep sent content | `"preview"` | `preview` / `off` | Stores the first/last 2,000 chars of the text actually sent (after redaction) in the session record; `off` stores metadata only. |
|
|
94
|
+
| `timeoutMs` | JSON only: Timeout | `90000` | 5000–600000 | Per-consultation timeout; `/advisor cancel` aborts sooner. |
|
|
95
|
+
| `maxInputChars` | Input limit | `60000` | 4000–400000 | Total transcript budget; excess in the middle is elided, head/tail kept. |
|
|
79
96
|
|
|
80
97
|
> **Note on `sessionCap`, `dedupe`, `immuneTurns`:** `sessionCap` is enforced — after that many delivered items in one session only `blocker` advice is still returned. `dedupe` and `immuneTurns` are persisted and used by the shadow path, but the tool path does not suppress a consultation because of them (you asked for it explicitly). The ceilings that stop _calls_ altogether are `maxCallsPerTurn` / `maxCallsPerSession` / `maxCallsPerHour` / `maxCostPerDayUsd`.
|
|
81
98
|
|
|
@@ -91,26 +108,33 @@ Example (placeholder route and model names — use the ones the picker shows you
|
|
|
91
108
|
}
|
|
92
109
|
```
|
|
93
110
|
|
|
111
|
+
**Two-pass evidence (opt-in).** With `advisorTools: true` the advisor may answer with `needs: [{kind:"file", ref:"path"}]`. The plugin reads those files **inside the session working directory only** (≤5 files, ≤64 KiB each, `../` and symlink escapes rejected), then calls the advisor once more with the quoted evidence so it can revise. This is the "advisor can check the facts" mode; it costs one extra model call. A rejected or unreadable path is reported back as unavailable evidence instead of failing the consultation.
|
|
112
|
+
|
|
113
|
+
**Workspace budget.** Besides the per-session ceilings, a shared pool (`<DSH_HOME>/advisor/budget.json`) counts calls and estimated cost per local day across sessions (`workspaceMaxCallsPerDay`, `workspaceMaxCostPerDayUsd`).
|
|
114
|
+
|
|
94
115
|
**Evidence anchors.** Each advice item may cite `{kind, ref}` anchors (a tool-call id, a message id, a file path). The plugin checks every ref against the session and marks the item unverified when nothing matches; if **none** of the cited anchors exist, the severity is downgraded one step and the advice says so. This is how a hallucinated "that failing command" gets caught.
|
|
95
116
|
|
|
96
|
-
**Advice line and report.** Each consultation is recorded as a session plugin record (not part of the model-visible surface), so the turn gets a compact advisor line in the chat and `/advisor report` can attribute adoption over time. Attribution is deliberately conservative: no signal, no credit.
|
|
117
|
+
**Advice line and report.** Each consultation is recorded as a session plugin record (not part of the model-visible surface), so the turn gets a compact advisor line in the chat and `/advisor report` can attribute adoption over time. Attribution is deliberately conservative: no signal, no credit. Expanding the line shows the trigger, local time, advisor model, characters sent and the usage/cost summary for that consultation. When a sent-content preview was stored, the expanded line also offers a “View sent content” toggle.
|
|
97
118
|
|
|
98
119
|
**Picking a model.** `/advisor` opens a picker listing the routes and models already configured in DSH, plus _off_ and _add / configure provider_. Choosing a model switches `mode` to `advisory`. `/advisor doctor` tells you line by line what is still missing.
|
|
99
120
|
|
|
100
121
|
## Commands
|
|
101
122
|
|
|
102
|
-
| Command | What it does
|
|
103
|
-
| -------------------------------------- |
|
|
104
|
-
| `/advisor` | Opens the model picker (client half). Routes and models are re-read every time; nothing is cached across openings.
|
|
105
|
-
| `/advisor status` | Mode, chosen route, consultations this session and this turn against the limits, cumulative tokens, the last result, and why the last consultation was skipped.
|
|
106
|
-
| `/advisor on` | Sets `advisory`. Refuses with a pointer to the picker when no advisor model is configured.
|
|
107
|
-
| `/advisor off` | Sets `off`: no consultation is made, no request is sent.
|
|
108
|
-
| `/advisor shadow` | Sets `shadow`: consult after each completed turn and record it, without feeding it back.
|
|
109
|
-
| `/advisor ask` | Runs one consultation **now** and returns the advice as command output.
|
|
110
|
-
| `/advisor cancel` | Aborts the in-flight consultation — the request is aborted, not merely ignored.
|
|
111
|
-
| `/advisor
|
|
112
|
-
| `/advisor
|
|
113
|
-
| `/advisor
|
|
123
|
+
| Command | What it does |
|
|
124
|
+
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
125
|
+
| `/advisor` | Opens the model picker (client half). Routes and models are re-read every time; nothing is cached across openings. |
|
|
126
|
+
| `/advisor status` | Mode, chosen route, consultations this session and this turn against the limits, cumulative tokens, the last result, and why the last consultation was skipped. |
|
|
127
|
+
| `/advisor on` | Sets `advisory`. Refuses with a pointer to the picker when no advisor model is configured. |
|
|
128
|
+
| `/advisor off` | Sets `off`: no consultation is made, no request is sent. |
|
|
129
|
+
| `/advisor shadow` | Sets `shadow`: consult after each completed turn and record it, without feeding it back. |
|
|
130
|
+
| `/advisor ask` | Runs one consultation **now** and returns the advice as command output. |
|
|
131
|
+
| `/advisor cancel` | Aborts the in-flight consultation — the request is aborted, not merely ignored. |
|
|
132
|
+
| `/advisor preview` | **Sends nothing.** Prints exactly what the next consultation would transmit: target route, scope, character/token estimate, omitted host context, tool traffic, redaction hits, allowlist verdict, cross-provider confirmation state, price source and today's workspace usage. |
|
|
133
|
+
| `/advisor confirm` | Allows sending the conversation to the current provider when it differs from the main model's provider. |
|
|
134
|
+
| `/advisor report all` | Cross-session report from the advice ledger (`<DSH_HOME>/advisor/advice.jsonl`): totals by severity, model and day. |
|
|
135
|
+
| `/advisor report` | Per-session advice report: how many were delivered, how many were **adopted** (heuristic: a path / backticked command / anchored ref from the advice shows up in later events), and how many evidence anchors verified. |
|
|
136
|
+
| `/advisor doctor` | Self-check: host `llm` service, registered routes, route resolution and context window, supported efforts, mode, session budget, ledger state, last failure. Each line states its conclusion and, where relevant, the next step. |
|
|
137
|
+
| `/advisor <provider>/<model> [effort]` | Sets the advisor route directly, with the same validation as the picker (unknown route, missing credentials and unsupported effort are rejected with a readable reason). |
|
|
114
138
|
|
|
115
139
|
The `advisor` **tool** is separate from the command: the model calls it, not you. It takes no required arguments; its optional `focus` is one sentence naming the doubt you want settled — not the task itself, because the transcript always is.
|
|
116
140
|
|
|
@@ -125,6 +149,7 @@ This is the section to read before turning it on.
|
|
|
125
149
|
- **Conversation content leaves the machine when the advisor route is external.** The transcript — with tool calls and results, bounded by `privacyScope` and `maxInputChars` — is sent to whatever base URL that route points at. If that is another vendor, your conversation leaves this machine. Only a route pointing at a local gateway keeps it local. The plugin sends nothing else: no telemetry, no analytics, no network access besides the consultation itself.
|
|
126
150
|
- **`privacyScope` decides how much is sent.** `summary` (default): each text block up to 2,000 characters, tool arguments up to 300, tool results up to 700. `off`: user and assistant text only, up to 1,200 characters, with no tool traffic at all. `full`: text up to 4,000, tool arguments up to 1,200, tool results up to 3,500. The rendered transcript is then capped at `maxInputChars` (60,000 by default): the first 30% and the tail are kept and the middle is replaced by an elision marker.
|
|
127
151
|
- **Redaction is best-effort.** With `redact: true` (default) the plugin scrubs common token-shaped strings, `Authorization` headers, `KEY=` / `TOKEN:`-style assignments, credentials embedded in URLs and PEM private-key blocks **before** clipping. It is a heuristic filter, **not a secret scanner**: it will miss things, it cannot guarantee that a secret never leaves, and it is no substitute for deciding whether this repository may be sent to that provider at all.
|
|
152
|
+
- **The sent-content preview is written to the session record.** With `tracePrompt: "preview"` (default), the first and last 2,000 characters of the text actually sent (after redaction and `maxInputChars` clipping) are stored in the session plugin record and can be opened from the advisor line; `off` stores metadata only. With `redact` off, the preview is raw text.
|
|
128
153
|
- **Start in `shadow`.** It answers "what would it have said, and what would that have cost" without putting model output back into your session. Read the ledger for a few days, then switch to `advisory`.
|
|
129
154
|
|
|
130
155
|
## Compatibility
|
|
@@ -147,11 +172,12 @@ The plugin declares no `engines.dsh` and no `@deepseek-ai/*` peer range: DSH is
|
|
|
147
172
|
Nothing else: no workspace files, no session-log records of its own (a consultation shows up as an ordinary tool call and tool result in the transcript), no telemetry.
|
|
148
173
|
|
|
149
174
|
- **The advice is model output.** It can be wrong, vague, or confidently wrong. The plugin validates the _shape_ — a JSON object, a known verdict and severity, length caps, declared evidence anchors — not the content. Weigh it and verify it; the main model still owns the decision.
|
|
175
|
+
- **Command surface is UI-only.** `ctx.commands` is a human command registry: UI-less hosts (headless `-p`, ACP automation) provide no command adapter, so `/advisor` is unavailable there. The tool, the settings file and the RPCs still work; "three-end parity" for the command surface is not achievable by design, not a missing feature.
|
|
150
176
|
- **Semi-public host seams.** `llm.prepareCall`, `llm.resolveModelInfo`, `session.deriveMessages`, `tools.register`, `commands.register` and `session/event` on the host side, and `commandUi.decorate` (the picker) on the client side, are not a stable public API. A DSH upgrade can silently disable the tool, the picker or the command. Run `pnpm probe:runtime` after every upgrade; installation failures are logged rather than thrown, so check `/advisor doctor` and the host logs.
|
|
151
177
|
- **Pairing needs your declaration.** DSH has no cross-vendor capability catalog, so "is the advisor at least as strong as the main model" can only come from your `tiers`. Without an entry the result says **unverified** and the consultation proceeds; it never pretends the check passed. With `pairingEnforcement: "block"` a lower declared tier rejects the consultation.
|
|
152
178
|
- **Token counts can be low on an aborted call.** If a consultation is cancelled or times out, no usage chunk may arrive; the ledger then records the call with zero tokens and a cost budget can lag real spend. Treat the ledger as a good estimate, not an invoice.
|
|
153
179
|
- **The advisor route can be broken from outside this plugin** (wrong base URL, missing key, rate limit). Every failure becomes a structured tool result (`MISSING_CREDENTIAL`, `rate_limited`, `overloaded`, `prompt_too_long`, `timeout`, `aborted`, …) and never breaks the turn.
|
|
154
|
-
- **
|
|
180
|
+
- **The settings card lives at the bottom of Settings → General.** It may need scrolling; keys marked JSON-only still need the settings file, and the `/advisor` picker remains available.
|
|
155
181
|
- **Partially enforced knobs.** `sessionCap` caps delivered advice per session (blockers exempt); `dedupe` / `immuneTurns` only matter on the shadow path — see [Configure](#configure).
|
|
156
182
|
- **One attempt, not a retry loop.** A malformed advisor answer is reported as unavailable rather than retried; an unsupported thinking effort is retried exactly once without an effort.
|
|
157
183
|
- **`shadow` mode still spends quota.** It skips the injection, not the call. And while `shadow` is on, an explicit `advisor` tool call still returns its advice: the mode suppresses the automatic end-of-turn review, not a model-initiated consultation. Use `off` to stop all calls.
|
|
@@ -162,11 +188,13 @@ Nothing else: no workspace files, no session-log records of its own (a consultat
|
|
|
162
188
|
```bash
|
|
163
189
|
pnpm verify # repo-wide gates: lint, typecheck, plugin conventions, docs, unit tests
|
|
164
190
|
cd packages/advisor && pnpm test # unit tests for this plugin (node --test)
|
|
191
|
+
pnpm smoke:advisor # web end-to-end smoke in a throwaway DSH home (spends nothing)
|
|
165
192
|
pnpm smoke:advisor-desktop # desktop (Electron) read-only regression over CDP
|
|
166
193
|
pnpm smoke:agent-tool # repo-wide real-model tool smoke (needs credentials; SKIPs without them)
|
|
167
194
|
```
|
|
168
195
|
|
|
169
196
|
- `pnpm verify` is the release gate and must pass before a PR.
|
|
197
|
+
- `pnpm smoke:advisor` starts a real host in a throwaway `DSH_HOME` (one temporary workspace, no credentials needed), installs the packed plugin and asserts: the client half loads, `/` lists `advisor`, the settings card renders, and `/advisor doctor` / `preview` / `confirm` / `report all` produce output — then checks that **no ledger file was created**, i.e. it spent nothing. Command output is read from the session log because the host renders command cards collapsed.
|
|
170
198
|
- `pnpm smoke:advisor-desktop` is the desktop (Electron) read-only regression, required because the plugin has a client half. It attaches to the running app over CDP, confirms the plugin's client half actually loaded, and never triggers a paid consultation. Pass `--require` in release gates so an unreachable debug port fails instead of silently skipping. It expects the app started with `open -a "DeepSeek Harness" --args --remote-debugging-port=9222 --remote-debugging-address=127.0.0.1`.
|
|
171
199
|
- `pnpm smoke:agent-tool` exercises a registered tool with a real model in a throwaway DSH home. It needs model credentials and exits as SKIP without them — a SKIP is not a pass.
|
|
172
200
|
|
package/README.zh-CN.md
CHANGED
|
@@ -53,29 +53,46 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
|
|
|
53
53
|
|
|
54
54
|
插件设置只有一个 JSON 文件:`<DSH_HOME>/advisor.settings.json`(`DSH_HOME` 默认 `~/.dsh`,插件配置里的 `dataRoot` 可覆盖)。宿主在每次徵询前重读(1 秒缓存),所以改文件对下一次调用立即生效,不用重启。未知键会被丢弃,越界的数字会被夹紧到区间,文件损坏则回落到默认值。**默认是 `off`**——一个会花钱、会把会话内容发出去的插件必须显式开启。
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
56
|
+
**设置页。** 设置 → 通用 → 顾问。默认 `off` 时卡片只显示模式、一句状态和「配置顾问」;展开或启用后才显示:
|
|
57
|
+
|
|
58
|
+
- **基础**:模式、服务商、模型、思考档、每日预算、发送范围、发送前脱敏。
|
|
59
|
+
- **高级**(默认折叠):调用限额、工作区限额、单价、输出/输入上限、建议条数、白名单、答后复查、读文件核实、影子去重、记录发送内容;折叠标题会标出「默认值」或「N 项已修改」。
|
|
60
|
+
- **状态与诊断**(默认折叠):累计调用/token/金额、最近结果/跳过原因、发送预览、诊断、设置文件与账本路径。
|
|
61
|
+
|
|
62
|
+
高级字段旁的「?」点开或用键盘激活会显示说明、默认值与范围、技术名;悬停只是补充。改完点「保存」才对下一次徵询生效。
|
|
63
|
+
|
|
64
|
+
金额字段支持小数:预算最多 2 位,单价最多 4 位。
|
|
65
|
+
|
|
66
|
+
| 键 | 设置页名称 | 默认 | 范围 / 取值 | 说明 |
|
|
67
|
+
| --------------------------- | ----------------------------- | ----------- | ------------------------------------ | ----------------------------------------------------------------------------- |
|
|
68
|
+
| `mode` | 模式 | `"off"` | off / shadow / advisory | 是否允许徵询。默认关闭,显式开启才生效。 |
|
|
69
|
+
| `provider` | 服务商 | `""` | 设置 → 模型里的路由名,≤300 字符 | 顾问路由。留空 = 永不调用。 |
|
|
70
|
+
| `model` | 模型 | `""` | 该路由下的模型 id,≤300 字符 | 顾问模型。留空 = 永不调用。 |
|
|
71
|
+
| `reasoningEffort` | 思考档 | `""` | 模型支持的思考档 id,`""` = 模型默认 | 填了不支持的值会去掉思考档重试一次。 |
|
|
72
|
+
| `maxTokens` | 输出上限 | `4096` | 256–32000 | 单次徵询最多生成多少 token。 |
|
|
73
|
+
| `temperature` | 随机性 | `null` | 0–2,`null` = 不传 | 留空由模型决定。 |
|
|
74
|
+
| `maxCallsPerTurn` | 每回合调用上限 | `1` | 0–8,0 = 不限 | 每回合最多徵询几次。 |
|
|
75
|
+
| `maxCallsPerSession` | 每会话调用上限 | `32` | 0–1000,0 = 不限 | 每个会话最多徵询几次。 |
|
|
76
|
+
| `maxCallsPerHour` | 每小时调用上限 | `12` | 0–500,0 = 不限 | 滚动一小时内。 |
|
|
77
|
+
| `maxCostPerDayUsd` | 每日预算 | `0` | 0–10000,0 = 不限;最多 2 位小数 | 每天最多花多少美元;只有填了单价才计算金额。 |
|
|
78
|
+
| `priceInputPerMTok` | 输入单价 | `0` | 0–1000;最多 4 位小数 | 顾问模型输入价,美元 / 百万 token;0 = 不算钱。 |
|
|
79
|
+
| `priceOutputPerMTok` | 输出单价 | `0` | 0–1000;最多 4 位小数 | 输出价,美元 / 百万 token。 |
|
|
80
|
+
| `privacyScope` | 发送范围 | `"summary"` | off / summary / full | 发多少会话内容,见「成本与隐私」。 |
|
|
81
|
+
| `redact` | 发送前脱敏 | `true` | 布尔 | 尽量遮掉常见密钥格式;不能保证全部遮住。 |
|
|
82
|
+
| `immuneTurns` | 仅 JSON:免疫回合 | `3` | 0–20 | 投递后保持安静的回合数;只用于 shadow 投递。 |
|
|
83
|
+
| `dedupe` | 影子模式去重 | `true` | 布尔 | 影子模式下相同建议只记一次;工具路径不据此拦截。 |
|
|
84
|
+
| `sessionCap` | 建议条数上限 | `24` | 0–200 | 单会话最多展示几条建议;到顶后只有 blocker 继续。 |
|
|
85
|
+
| `tiers` | 仅 JSON:能力档位 | `{}` | `"provider/model"` → 数字 | 配对校验用的档位;没有条目时结论是「未校验」。 |
|
|
86
|
+
| `allowedModels` | 模型白名单 | `[]` | 字符串数组 | 留空 = 不限制;可写 provider/model 或裸 model id。 |
|
|
87
|
+
| `confirmedHosts` | 仅 JSON/按钮:已确认 provider | `[]` | 字符串数组 | 跨 provider 发送的确认名单;设置卡里的按钮会写入。 |
|
|
88
|
+
| `pairingEnforcement` | 仅 JSON:配对校验 | `"warn"` | warn / block | 顾问档位低于主模型时:warn 放行并告警,block 拒绝。 |
|
|
89
|
+
| `workspaceMaxCallsPerDay` | 工作区每日调用上限 | `200` | 0–100000,0 = 不限 | 工作区级,跨会话累计,按本地日重置。 |
|
|
90
|
+
| `workspaceMaxCostPerDayUsd` | 工作区每日预算 | `0` | 0–10000,0 = 不限;最多 2 位小数 | 工作区级每日金额上限。 |
|
|
91
|
+
| `postAnswer` | 回合结束后自动复查 | `"off"` | off / card | advisory 模式下每轮回答后自动复查一次;只记录,不插回对话。 |
|
|
92
|
+
| `advisorTools` | 允许顾问读文件核实 | `false` | 布尔 | 允许顾问读工作目录内的文件(≤5 个、只读);多一次调用。 |
|
|
93
|
+
| `tracePrompt` | 记录发送内容 | `"preview"` | `preview` / `off` | 在会话记录里保留实际发送文本的首尾各 2,000 字符(脱敏后);`off` 只记元数据。 |
|
|
94
|
+
| `timeoutMs` | 仅 JSON:超时 | `90000` | 5000–600000 | 单次徵询超时;`/advisor cancel` 可以更早中止。 |
|
|
95
|
+
| `maxInputChars` | 输入上限 | `60000` | 4000–400000 | 会话文本总预算;超出保留首尾、省略中间。 |
|
|
79
96
|
|
|
80
97
|
> **关于 `sessionCap`、`dedupe`、`immuneTurns`:** `sessionCap` 会生效——单会话投递到上限后,只有 `blocker` 级建议还会返回。`dedupe` 与 `immuneTurns` 会被保存并用于 shadow 路径,但工具路径不会因为它们跳过徵询(是模型显式要求的)。真正会拦住**调用本身**的是 `maxCallsPerTurn` / `maxCallsPerSession` / `maxCallsPerHour` / `maxCostPerDayUsd`。
|
|
81
98
|
|
|
@@ -109,6 +126,8 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
|
|
|
109
126
|
|
|
110
127
|
`advisor` **工具**和命令是两回事:工具由模型调用,不是你。它没有必填参数;可选的 `focus` 是一句话,用来说明你想让顾问解决的疑点——不是任务本身,任务永远是整段对话。
|
|
111
128
|
|
|
129
|
+
每次徵询还会在回合末尾留下一条紧凑的顾问线(不进入模型可见的 surface);展开后显示本次徵询的触发方式、本地时间、顾问模型、发送字符数与用量/成本摘要。 记录了发送内容时,展开后可以点「查看发送内容」看当时实际发送文本的首尾片段。
|
|
130
|
+
|
|
112
131
|
## 成本与隐私
|
|
113
132
|
|
|
114
133
|
这一节请在开启前读完。
|
|
@@ -120,13 +139,14 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
|
|
|
120
139
|
- **顾问路由在外部时,会话内容会离开本机。** 渲染后的会话文本(含工具调用与结果,受 `privacyScope` 和 `maxInputChars` 限制)会发到该路由指向的 baseURL。如果那是另一家厂商,你的对话就离开了这台机器;只有指向本地网关的路由才留在本机。除此之外插件什么都不发:没有遥测,没有统计,除了徵询本身不访问网络。
|
|
121
140
|
- **`privacyScope` 决定发多少。** `summary`(默认):每个文本块最多 2,000 字符,工具参数最多 300,工具结果最多 700。`off`:只发用户与助手的文本(最多 1,200 字符),完全不发工具往来。`full`:文本最多 4,000,工具参数最多 1,200,工具结果最多 3,500。渲染完再按 `maxInputChars`(默认 60,000)封顶:保留前 30% 和结尾,中间替换成省略标记。
|
|
122
141
|
- **脱敏是尽力而为。** `redact: true`(默认)会在**截断之前**清掉常见的密钥形态字符串、`Authorization` 头、`KEY=` / `TOKEN:` 形式的赋值、URL 里内嵌的凭据,以及 PEM 私钥块。它是启发式过滤,**不是密钥扫描器**:一定会漏,也无法保证密钥绝不外发;更不能替代「这个仓库是否允许发给那家 provider」这个判断。
|
|
142
|
+
- **发送预览会写入会话记录。** `tracePrompt: "preview"`(默认)会把本次实际发送文本的首尾各 2,000 字符(脱敏、按 `maxInputChars` 截断后)写进会话插件记录,展开顾问线后可查看;`off` 只记元数据。若同时关闭 `redact`,预览就是原文片段。
|
|
123
143
|
- **先开 `shadow`。** 它回答的是「它本来会说什么、本来要花多少」,但不把模型输出塞回你的会话。看几天账本,再切到 `advisory`。
|
|
124
144
|
|
|
125
145
|
## 兼容性
|
|
126
146
|
|
|
127
|
-
| 已验证的 DSH 版本 | 状态
|
|
128
|
-
| ----------------- |
|
|
129
|
-
| 0.2.2-rc.1 |
|
|
147
|
+
| 已验证的 DSH 版本 | 状态 |
|
|
148
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
149
|
+
| 0.2.2-rc.1 | 已在该版本验证:单测(81 条)与 `pnpm probe:runtime`;web 端到端冒烟 `pnpm smoke:advisor`、桌面端只读回归 `pnpm smoke:advisor-desktop`。其他 DSH 版本未验证。 |
|
|
130
150
|
|
|
131
151
|
插件不声明 `engines.dsh`,也不声明 `@deepseek-ai/*` 的 peer 范围:DSH 还在预发布阶段,semver 对预发布版本不可靠(见 [ADR 0005](../../docs/adr/0005-dsh-version-compatibility.md))。这张表就是兼容性声明。DSH 升级后请跑 `pnpm probe:runtime`、`pnpm smoke:advisor-desktop` 和单测,再看 `/advisor doctor`。
|
|
132
152
|
|
|
@@ -146,7 +166,7 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
|
|
|
146
166
|
- **配对档位需要你自己声明。** DSH 没有跨厂商的能力目录,所以「顾问是不是至少和主模型一样强」只能来自你填的 `tiers`。没有条目时结论是**未校验**,徵询照常进行;它不会假装校验通过。把 `pairingEnforcement` 设成 `"block"` 时,档位更低的顾问会被拒绝。
|
|
147
167
|
- **被中止的调用 token 可能记少。** 徵询被取消或超时时,可能收不到 usage chunk;账本会把这次记成 0 token,金额预算可能落后于真实花费。把账本当可靠估算,别当账单。
|
|
148
168
|
- **顾问路由可能因为插件之外的原因坏掉**(baseURL 写错、缺密钥、限流)。所有失败都会变成结构化的工具结果(`MISSING_CREDENTIAL`、`rate_limited`、`overloaded`、`prompt_too_long`、`timeout`、`aborted`…),不会把回合弄断。
|
|
149
|
-
-
|
|
169
|
+
- **设置卡在「设置 → 通用」的底部。** 可能需要往下滚;标了「仅 JSON」的键仍要改设置文件,或继续用 `/advisor` 选择器。
|
|
150
170
|
- **部分生效的旋钮。** `sessionCap` 会限制单会话投递条数(blocker 豁免);`dedupe` / `immuneTurns` 只在 shadow 路径上有意义——见[配置](#配置)。
|
|
151
171
|
- **只试一次,没有重试循环。** 顾问输出解析失败会报 unavailable,不重试;不支持的思考档只会去掉思考档重试一次。
|
|
152
172
|
- **`shadow` 模式照样花钱。** 它省掉的是回灌,不是调用。而且 `shadow` 期间,模型主动调用 `advisor` 工具仍会拿到建议:这个模式抑制的是回合结束后的自动复查,不是模型发起的徵询。要彻底停调用请用 `off`。
|
|
@@ -157,11 +177,13 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
|
|
|
157
177
|
```bash
|
|
158
178
|
pnpm verify # 仓库级门禁:lint、类型、插件规范、文档一致性、单测
|
|
159
179
|
cd packages/advisor && pnpm test # 本插件的单测(node --test)
|
|
180
|
+
pnpm smoke:advisor # web 端到端冒烟(一次性 DSH_HOME,不花钱)
|
|
160
181
|
pnpm smoke:advisor-desktop # 桌面版(Electron)只读回归,走 CDP
|
|
161
182
|
pnpm smoke:agent-tool # 仓库级真实模型工具冒烟(需要凭据,没有就 SKIP)
|
|
162
183
|
```
|
|
163
184
|
|
|
164
185
|
- `pnpm verify` 是发版门禁,提 PR 之前必须通过。
|
|
186
|
+
- `pnpm smoke:advisor` 在一次性 `DSH_HOME` 里起真实宿主(只放一个临时工作区、不需要凭据),装包后验证:client 半加载、`/` 菜单出现 `advisor`、设置卡渲染、`/advisor doctor`/`preview`/`confirm`/`report all` 都有输出,并断言**没有生成账本文件**(即没有花钱)。命令输出读会话日志,因为宿主的命令卡片在 DOM 里是折叠的。
|
|
165
187
|
- `pnpm smoke:advisor-desktop` 是桌面版(Electron)只读回归;插件有 client 半,所以这是硬性要求。它通过 CDP 连上正在运行的应用、确认 client 半真的加载,**不会**触发需要付费的徵询。发版门禁里加 `--require`,这样连不上调试端口会失败而不是静默跳过。它要求应用用 `open -a "DeepSeek Harness" --args --remote-debugging-port=9222 --remote-debugging-address=127.0.0.1` 启动。
|
|
166
188
|
- `pnpm smoke:agent-tool` 在一次性 DSH 目录里用真实模型驱动一个已注册工具。需要模型凭据;没有凭据时以 SKIP 退出——SKIP 不等于通过。
|
|
167
189
|
|
package/lib/adoption.js
CHANGED
|
@@ -28,32 +28,37 @@ export function signalsOf(data) {
|
|
|
28
28
|
* @param {any[]} events 会话全量事件
|
|
29
29
|
* @param {number} fromIndex 建议记录所在的事件下标
|
|
30
30
|
* @param {any} data 建议记录的数据
|
|
31
|
-
* @returns {{ verdict: "adopted"|"unknown", why: string }}
|
|
31
|
+
* @returns {{ verdict: "adopted"|"unknown", why: string, confidence: "high"|"medium"|"low" }}
|
|
32
32
|
*/
|
|
33
33
|
export function attributeAdoption(events, fromIndex, data) {
|
|
34
34
|
const signals = signalsOf(data);
|
|
35
|
-
if (signals.length === 0)
|
|
35
|
+
if (signals.length === 0)
|
|
36
|
+
return { verdict: "unknown", why: "建议里没有可追踪的信号", confidence: "low" };
|
|
36
37
|
const list = Array.isArray(events) ? events : [];
|
|
37
38
|
for (let index = fromIndex + 1; index < list.length; index += 1) {
|
|
38
39
|
const haystack = JSON.stringify(list[index]?.data ?? "");
|
|
39
40
|
for (const signal of signals) {
|
|
40
|
-
if (haystack.includes(signal))
|
|
41
|
+
if (haystack.includes(signal)) {
|
|
42
|
+
// 路径/证据 ref 比反引号命令更有区分度(命令常被复述)。
|
|
43
|
+
const specific = signal.includes("/") || signal.includes("_");
|
|
44
|
+
return { verdict: "adopted", why: signal, confidence: specific ? "high" : "medium" };
|
|
45
|
+
}
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
|
-
return { verdict: "unknown", why: "后续没有出现建议里的信号" };
|
|
48
|
+
return { verdict: "unknown", why: "后续没有出现建议里的信号", confidence: "low" };
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
52
|
* 汇总一批建议记录(供 `/advisor report` 与未来的设置页使用)。
|
|
48
53
|
* @param {any[]} events
|
|
49
54
|
* @param {Array<{ index: number, data: any }>} records
|
|
50
|
-
* @returns {{ total: number, adopted: number, unknown: number, anchorsChecked: number, anchorsVerified: number, items: Array<{ severity: string, summary: string, verdict: string, why: string, adviceId: string }> }}
|
|
55
|
+
* @returns {{ total: number, adopted: number, unknown: number, anchorsChecked: number, anchorsVerified: number, items: Array<{ severity: string, summary: string, verdict: string, why: string, confidence: string, adviceId: string }> }}
|
|
51
56
|
*/
|
|
52
57
|
export function summarizeAdoption(events, records) {
|
|
53
58
|
let adopted = 0;
|
|
54
59
|
let anchorsChecked = 0;
|
|
55
60
|
let anchorsVerified = 0;
|
|
56
|
-
/** @type {Array<{ severity: string, summary: string, verdict: string, why: string, adviceId: string }>} */
|
|
61
|
+
/** @type {Array<{ severity: string, summary: string, verdict: string, why: string, confidence: string, adviceId: string }>} */
|
|
57
62
|
const items = [];
|
|
58
63
|
for (const { index, data } of Array.isArray(records) ? records : []) {
|
|
59
64
|
const outcome = attributeAdoption(events, index, data);
|
|
@@ -67,6 +72,7 @@ export function summarizeAdoption(events, records) {
|
|
|
67
72
|
.slice(0, 80),
|
|
68
73
|
verdict: outcome.verdict,
|
|
69
74
|
why: outcome.why,
|
|
75
|
+
confidence: outcome.confidence,
|
|
70
76
|
adviceId: String(data?.adviceId ?? ""),
|
|
71
77
|
});
|
|
72
78
|
}
|
package/lib/budget.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// 工作区级共享预算池:多个会话共用一份「今天已经花掉多少」的账。
|
|
3
|
+
//
|
|
4
|
+
// 为什么需要:会话级上限挡不住「开十个会话各花满一次」,而日报表又要跨会话累计。
|
|
5
|
+
// 落盘 `<dataRoot>/advisor/budget.json`,按本地日键滚动;写入走临时文件 + rename。
|
|
6
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
|
|
9
|
+
/** 预算池文件名(位于数据根下的 advisor/ 目录)。 */
|
|
10
|
+
export const BUDGET_FILE = "budget.json";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 本地日键 YYYY-MM-DD。
|
|
14
|
+
* @param {Date} [date]
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
export function dayKey(date = new Date()) {
|
|
18
|
+
const year = date.getFullYear();
|
|
19
|
+
const month = `${date.getMonth() + 1}`.padStart(2, "0");
|
|
20
|
+
const day = `${date.getDate()}`.padStart(2, "0");
|
|
21
|
+
return `${year}-${month}-${day}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 规整预算池内容:跨日自动清零。
|
|
26
|
+
* @param {unknown} raw
|
|
27
|
+
* @param {string} today
|
|
28
|
+
* @returns {{ day: string, calls: number, costUsd: number }}
|
|
29
|
+
*/
|
|
30
|
+
export function normalizePool(raw, today) {
|
|
31
|
+
const input = raw !== null && typeof raw === "object" ? /** @type {any} */ (raw) : {};
|
|
32
|
+
if (input.day !== today) return { day: today, calls: 0, costUsd: 0 };
|
|
33
|
+
return {
|
|
34
|
+
day: today,
|
|
35
|
+
calls: Math.max(0, Math.round(Number(input.calls ?? 0) || 0)),
|
|
36
|
+
costUsd: Math.max(0, Number(input.costUsd ?? 0) || 0),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 池子是否还能容纳一次调用。
|
|
42
|
+
* @param {{ calls: number, costUsd: number }} pool
|
|
43
|
+
* @param {{ workspaceMaxCallsPerDay: number, workspaceMaxCostPerDayUsd: number }} settings
|
|
44
|
+
* @param {number} [estimatedCostUsd]
|
|
45
|
+
* @returns {{ ok: true } | { ok: false, code: "workspace_calls"|"workspace_budget", used: number, limit: number }}
|
|
46
|
+
*/
|
|
47
|
+
export function checkPool(pool, settings, estimatedCostUsd = 0) {
|
|
48
|
+
const maxCalls = Number(settings?.workspaceMaxCallsPerDay ?? 0) || 0;
|
|
49
|
+
if (maxCalls > 0 && pool.calls >= maxCalls) {
|
|
50
|
+
return { ok: false, code: "workspace_calls", used: pool.calls, limit: maxCalls };
|
|
51
|
+
}
|
|
52
|
+
const maxCost = Number(settings?.workspaceMaxCostPerDayUsd ?? 0) || 0;
|
|
53
|
+
if (maxCost > 0 && pool.costUsd + estimatedCostUsd >= maxCost) {
|
|
54
|
+
return { ok: false, code: "workspace_budget", used: pool.costUsd, limit: maxCost };
|
|
55
|
+
}
|
|
56
|
+
return { ok: true };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {{ home: string, logger?: DSH.Logger }} options
|
|
61
|
+
* @returns {{ read: () => Promise<{ day: string, calls: number, costUsd: number }>, add: (input: { calls?: number, costUsd?: number }) => Promise<{ day: string, calls: number, costUsd: number }>, path: string }}
|
|
62
|
+
*/
|
|
63
|
+
export function createBudgetPool(options) {
|
|
64
|
+
const dir = join(options.home, "advisor");
|
|
65
|
+
const path = join(dir, BUDGET_FILE);
|
|
66
|
+
|
|
67
|
+
/** @returns {Promise<{ day: string, calls: number, costUsd: number }>} */
|
|
68
|
+
const read = async () => {
|
|
69
|
+
const today = dayKey();
|
|
70
|
+
try {
|
|
71
|
+
const text = await readFile(path, "utf8");
|
|
72
|
+
return normalizePool(JSON.parse(text), today);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const code = /** @type {any} */ (error)?.code;
|
|
75
|
+
if (code !== "ENOENT") options.logger?.warn?.(`[advisor] 读取预算池失败:${String(error)}`);
|
|
76
|
+
return { day: today, calls: 0, costUsd: 0 };
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** @param {{ calls?: number, costUsd?: number }} input */
|
|
81
|
+
const add = async (input) => {
|
|
82
|
+
const current = await read();
|
|
83
|
+
const next = {
|
|
84
|
+
day: current.day,
|
|
85
|
+
calls: current.calls + Math.max(0, Math.round(Number(input?.calls ?? 0) || 0)),
|
|
86
|
+
costUsd: current.costUsd + Math.max(0, Number(input?.costUsd ?? 0) || 0),
|
|
87
|
+
};
|
|
88
|
+
try {
|
|
89
|
+
await mkdir(dir, { recursive: true });
|
|
90
|
+
const temp = `${path}.tmp`;
|
|
91
|
+
await writeFile(temp, `${JSON.stringify(next, null, 2)}\n`, "utf8");
|
|
92
|
+
await rename(temp, path);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
options.logger?.warn?.(`[advisor] 写预算池失败:${String(error)}`);
|
|
95
|
+
}
|
|
96
|
+
return next;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return { read, add, path };
|
|
100
|
+
}
|
package/lib/call.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// 一次顾问调用:prepareCall → stream → 聚合文本 / usage / 错误分类。
|
|
3
3
|
// 这是整个插件唯一会花钱的地方,所有失败都必须变成**结构化结果**,绝不向上抛。
|
|
4
4
|
import { BlockAssembler } from "@deepseek-ai/dsh-llm";
|
|
5
|
-
import {
|
|
5
|
+
import { advisorSystemPrompt, buildAdvisorInput, mintNonce } from "./prompt.js";
|
|
6
6
|
|
|
7
7
|
/** 额外调用统一打这个 purpose:也是递归防护的判据(监听器按它跳过自己)。 */
|
|
8
8
|
export const PURPOSE = "advisor";
|
|
@@ -37,6 +37,8 @@ export function classifyError(error) {
|
|
|
37
37
|
* @property {string} [focus]
|
|
38
38
|
* @property {string} [locale]
|
|
39
39
|
* @property {string} sessionId
|
|
40
|
+
* @property {string} [extra] 第二轮取证时追加的上下文
|
|
41
|
+
* @property {boolean} [canRequestEvidence]
|
|
40
42
|
* @property {AbortSignal} [signal]
|
|
41
43
|
* @property {DSH.Logger} [logger]
|
|
42
44
|
*/
|
|
@@ -76,12 +78,15 @@ export async function callAdvisor(input) {
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
const nonce = mintNonce();
|
|
79
|
-
const
|
|
81
|
+
const baseText = buildAdvisorInput({
|
|
80
82
|
transcript,
|
|
81
83
|
nonce,
|
|
82
84
|
focus: input.focus,
|
|
83
85
|
locale: input.locale,
|
|
84
86
|
});
|
|
87
|
+
const userText =
|
|
88
|
+
input.extra === undefined || input.extra === "" ? baseText : `${baseText}\n\n${input.extra}`;
|
|
89
|
+
const system = advisorSystemPrompt({ canRequestEvidence: input.canRequestEvidence === true });
|
|
85
90
|
const messages = /** @type {any} */ ([
|
|
86
91
|
{ role: "user", content: [{ type: "text", text: userText }] },
|
|
87
92
|
]);
|
|
@@ -134,7 +139,7 @@ export async function callAdvisor(input) {
|
|
|
134
139
|
for await (const chunk of prepared.stream({
|
|
135
140
|
...prepared.config,
|
|
136
141
|
messages,
|
|
137
|
-
system
|
|
142
|
+
system,
|
|
138
143
|
sessionId,
|
|
139
144
|
purpose: PURPOSE,
|
|
140
145
|
...(signal === undefined ? {} : { signal }),
|