@ai-setting/roy-agent-core 1.7.55 → 1.7.57
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/config/index.js +8 -8
- package/dist/env/agent/agent-component.d.ts +41 -0
- package/dist/env/agent/index.js +15 -14
- package/dist/env/commands/index.js +8 -8
- package/dist/env/context/index.js +4 -4
- package/dist/env/debug/index.js +8 -8
- package/dist/env/environment.d.ts +7 -0
- package/dist/env/event-source/event-source-handlers.d.ts +28 -0
- package/dist/env/event-source/index.js +18 -17
- package/dist/env/hook/index.js +6 -6
- package/dist/env/index.js +45 -43
- package/dist/env/llm/adapter-ai-sdk.d.ts +6 -0
- package/dist/env/llm/adapter-pi-ai.d.ts +5 -0
- package/dist/env/llm/index.js +11 -11
- package/dist/env/llm/invoke.d.ts +33 -1
- package/dist/env/llm/llm.d.ts +13 -0
- package/dist/env/llm/outbound-defense.d.ts +140 -0
- package/dist/env/log-trace/decorator.d.ts +46 -3
- package/dist/env/log-trace/index.d.ts +1 -0
- package/dist/env/log-trace/index.js +34 -8
- package/dist/env/log-trace/opentelemetry/tracer-provider.d.ts +86 -1
- package/dist/env/log-trace/trace-filters.d.ts +127 -0
- package/dist/env/mcp/index.js +9 -9
- package/dist/env/mcp/tool/index.js +2 -2
- package/dist/env/memory/index.js +9 -9
- package/dist/env/memory/plugin/index.js +2 -2
- package/dist/env/plugin/index.js +8 -8
- package/dist/env/prompt/index.js +8 -8
- package/dist/env/session/index.js +12 -11
- package/dist/env/session/session-component.d.ts +4 -0
- package/dist/env/session/storage/index.js +6 -4
- package/dist/env/skill/index.js +8 -8
- package/dist/env/task/delegate/index.js +9 -9
- package/dist/env/task/index.js +18 -17
- package/dist/env/task/plugins/index.js +11 -10
- package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +109 -2
- package/dist/env/task/plugins/lark-card-state-store.d.ts +137 -0
- package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +154 -2
- package/dist/env/task/storage/index.js +4 -3
- package/dist/env/task/tools/index.js +4 -4
- package/dist/env/tool/built-in/index.js +5 -5
- package/dist/env/tool/index.js +12 -12
- package/dist/env/workflow/engine/index.js +13 -13
- package/dist/env/workflow/hooks/index.js +8 -8
- package/dist/env/workflow/index.js +24 -23
- package/dist/env/workflow/nodes/index.js +3 -3
- package/dist/env/workflow/plugins/index.js +9 -9
- package/dist/env/workflow/service/index.js +3 -3
- package/dist/env/workflow/storage/index.js +4 -4
- package/dist/env/workflow/tools/index.js +16 -15
- package/dist/env/workflow/utils/index.js +6 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +90 -63
- package/dist/shared/@ai-setting/{roy-agent-core-k25gv86p.js → roy-agent-core-029r8kdw.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-8s9jd2qy.js → roy-agent-core-08njdcpj.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-tdbv7ff4.js → roy-agent-core-0kn3zt1t.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-8eqngasy.js → roy-agent-core-0yn7a78e.js} +14 -14
- package/dist/shared/@ai-setting/{roy-agent-core-tbrn9wdm.js → roy-agent-core-14bq77wr.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-mxdc756a.js → roy-agent-core-1sfbs57v.js} +9 -9
- package/dist/shared/@ai-setting/{roy-agent-core-qamktze3.js → roy-agent-core-20m8je6e.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-yhsssn86.js → roy-agent-core-2ctyjy62.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9jzysq50.js → roy-agent-core-2fk8c9ax.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-2k4xffaa.js → roy-agent-core-4096f575.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-2gay3sjt.js → roy-agent-core-47s81t6g.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-w527pcpe.js → roy-agent-core-5f7myqnb.js} +45 -494
- package/dist/shared/@ai-setting/{roy-agent-core-zjttt2y4.js → roy-agent-core-7nb23tdd.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-7q4wdze2.js +7 -0
- package/dist/shared/@ai-setting/{roy-agent-core-cd62e9p1.js → roy-agent-core-84rs0c8d.js} +23 -10
- package/dist/shared/@ai-setting/{roy-agent-core-dwx9hjwx.js → roy-agent-core-84xtww7d.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-a4vzsn0g.js → roy-agent-core-89sxsrc7.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-g36jevrk.js → roy-agent-core-8bngppw0.js} +580 -83
- package/dist/shared/@ai-setting/roy-agent-core-8p63s836.js +578 -0
- package/dist/shared/@ai-setting/{roy-agent-core-7evvpfwc.js → roy-agent-core-9zhkdg6w.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-ak4dc3kg.js → roy-agent-core-baaa4wtp.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-b5ew8t0k.js → roy-agent-core-c36335nw.js} +146 -8
- package/dist/shared/@ai-setting/{roy-agent-core-7qy3nffr.js → roy-agent-core-c7w2h47a.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-j5c3chtn.js → roy-agent-core-cyefe8z5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-2bscfrr1.js → roy-agent-core-d75t8gea.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-0hq21px2.js → roy-agent-core-e1w17tht.js} +632 -36
- package/dist/shared/@ai-setting/{roy-agent-core-ne2t1pay.js → roy-agent-core-e250355z.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-ytr2w0vb.js → roy-agent-core-eanq305k.js} +69 -25
- package/dist/shared/@ai-setting/{roy-agent-core-12d2xap8.js → roy-agent-core-em4hks9t.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-6qxh4xrm.js → roy-agent-core-en2xqxs9.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-e2z1etk4.js → roy-agent-core-ewcc5qdt.js} +11 -11
- package/dist/shared/@ai-setting/{roy-agent-core-qm9jda8p.js → roy-agent-core-fbjd7bt6.js} +3 -7
- package/dist/shared/@ai-setting/{roy-agent-core-fvs48d38.js → roy-agent-core-fw6k4w1h.js} +14 -9
- package/dist/shared/@ai-setting/{roy-agent-core-2b8jtv7m.js → roy-agent-core-ge87xbas.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9csa89jx.js → roy-agent-core-geh6j7bw.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-dv714bqh.js → roy-agent-core-gksw1gjb.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-fs36xgcs.js → roy-agent-core-hefarcp0.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-t37wbysj.js → roy-agent-core-hs41gx9w.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-1cv9j4dg.js → roy-agent-core-jjhw9am6.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-978b6wfx.js → roy-agent-core-jjxdmedn.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-j2nvedt6.js → roy-agent-core-jw5ar4p0.js} +33 -38
- package/dist/shared/@ai-setting/{roy-agent-core-zvemdfx5.js → roy-agent-core-kq9pz2a7.js} +13 -6
- package/dist/shared/@ai-setting/{roy-agent-core-8t7wny6v.js → roy-agent-core-m68z3pw1.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-k8b440n3.js → roy-agent-core-m97jn2ra.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-kzg1jwt8.js → roy-agent-core-n0p0hwgd.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9h72sk1n.js → roy-agent-core-psg6f1v6.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-athdr2m0.js → roy-agent-core-q4gdfypk.js} +12 -4
- package/dist/shared/@ai-setting/{roy-agent-core-nde5gzta.js → roy-agent-core-rcgvmtms.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-8seq65bp.js → roy-agent-core-rt115qfc.js} +44 -1
- package/dist/shared/@ai-setting/{roy-agent-core-5apmk4qw.js → roy-agent-core-syyw58p9.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-tjg71zqp.js → roy-agent-core-t4x089js.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-zd3ddm4k.js → roy-agent-core-t64nmayv.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-6167phd4.js → roy-agent-core-txwptxk1.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-rnwr39b0.js → roy-agent-core-tze5596n.js} +6 -4
- package/dist/shared/@ai-setting/{roy-agent-core-skzjs973.js → roy-agent-core-vath15kt.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-vrsxhw9e.js → roy-agent-core-vgdhxbx3.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-7g03zkkb.js → roy-agent-core-vh0qzb24.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-aer5kw1j.js → roy-agent-core-w93z6a42.js} +17 -17
- package/dist/shared/@ai-setting/{roy-agent-core-rx16h2m1.js → roy-agent-core-ygn5tzt1.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-4z3rq5gw.js → roy-agent-core-yphwdm9x.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-qcspfszy.js → roy-agent-core-ytd5eztz.js} +1 -1
- package/dist/utils/temp-file-manager/index.js +2 -2
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-dsevjbck.js +0 -245
package/dist/env/llm/invoke.d.ts
CHANGED
|
@@ -88,6 +88,18 @@ export interface InvokeOptions {
|
|
|
88
88
|
name: string;
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* Prompt-cache retention preference (Task #4465).
|
|
93
|
+
*
|
|
94
|
+
* path A already honours this through `buildPiCacheOptions()`; path B (this
|
|
95
|
+
* AI SDK fallback) ignored it entirely, so every fallback request paid full
|
|
96
|
+
* input price. Forwarded to the outbound defence middleware, which emits
|
|
97
|
+
* `prompt_cache_key` / `prompt_cache_retention` on OpenAI-family protocols.
|
|
98
|
+
*
|
|
99
|
+
* Omitted → the middleware defaults to `"long"` for OpenAI-family protocols,
|
|
100
|
+
* matching path A's default for `openai-completions`.
|
|
101
|
+
*/
|
|
102
|
+
cacheRetention?: "none" | "short" | "long";
|
|
91
103
|
}
|
|
92
104
|
/**
|
|
93
105
|
* LLM Tool Context - Context for tool calls during LLM invocation
|
|
@@ -282,8 +294,28 @@ export declare function invoke(config: InvokeConfig, options: InvokeOptions, ctx
|
|
|
282
294
|
/**
|
|
283
295
|
* 创建 Provider 实例
|
|
284
296
|
* 根据 providerId 创建对应的 AI SDK Provider
|
|
297
|
+
*
|
|
298
|
+
* Task #4465: every branch that can actually reach the wire installs an
|
|
299
|
+
* outbound defence `fetch` middleware (see outbound-defense.ts). The `google`
|
|
300
|
+
* branch is deliberately excluded: `createGoogleGenerativeAI` exposes no
|
|
301
|
+
* `fetch` option, and Google needs neither the DeepSeek-family
|
|
302
|
+
* `reasoning_content` field nor OpenAI-style prompt-cache keys. Rationale:
|
|
303
|
+
*
|
|
304
|
+
* - path A (`adapter-pi-ai.ts`) has carried the `reasoning_content` defence
|
|
305
|
+
* (#4398/#4403) and the explicit prompt-cache markers (#4383) for a while;
|
|
306
|
+
* path B — this AI SDK fallback — had neither, so a single transient 429 on
|
|
307
|
+
* path A turned into a hard 400 here.
|
|
308
|
+
* - The middleware patches the serialised HTTP body, which is the only place
|
|
309
|
+
* that is protocol-agnostic: `createOpenAI().languageModel()` speaks the
|
|
310
|
+
* **responses** protocol (body key `input`), while the compatible branch
|
|
311
|
+
* speaks **chat/completions** (body key `messages`).
|
|
312
|
+
* - `fetch` is the only option all three provider factories share
|
|
313
|
+
* (`transformRequestBody` exists on `openai-compatible` alone).
|
|
314
|
+
*
|
|
315
|
+
* The middleware is fail-open: anything it cannot parse is forwarded untouched,
|
|
316
|
+
* because path B only runs once we are already in a degraded state.
|
|
285
317
|
*/
|
|
286
|
-
declare function createProviderInstance(providerId: string, apiKey: string, baseURL?: string, conversationId?: string): any;
|
|
318
|
+
declare function createProviderInstance(providerId: string, apiKey: string, baseURL?: string, conversationId?: string, cacheRetention?: "none" | "short" | "long", modelId?: string): any;
|
|
287
319
|
/**
|
|
288
320
|
* Test-only re-export of createProviderInstance so that unit tests can verify
|
|
289
321
|
* header injection behavior without booting the full invoke() stack.
|
package/dist/env/llm/llm.d.ts
CHANGED
|
@@ -188,6 +188,19 @@ export declare class LLMComponent extends BaseComponent {
|
|
|
188
188
|
* the adapter to be recreated on the next invoke().
|
|
189
189
|
*/
|
|
190
190
|
invalidateAdapterCache(): void;
|
|
191
|
+
/**
|
|
192
|
+
* ★ 2026-10-22:**入参/返回值只存摘要**(Task #4479)。
|
|
193
|
+
*
|
|
194
|
+
* 改造前本 span 平均 473KB —— 因为 `request.messages`(全量 system prompt +
|
|
195
|
+
* 对话历史)被原样序列化进 DB attributes,完整模型响应又存了两遍
|
|
196
|
+
* (`attributes.result` + `result` 列)。
|
|
197
|
+
*
|
|
198
|
+
* 现在只存摘要:模型名 / provider / 消息条数 / 总字符数 / 工具数 /
|
|
199
|
+
* finishReason / output 长度 / usage —— 排障时最常问的问题的答案,
|
|
200
|
+
* 体积 < 1KB。
|
|
201
|
+
*
|
|
202
|
+
* 需要临时全量排查时:`ROY_TRACE_FULL=1` 重启即可恢复全量(不改代码)。
|
|
203
|
+
*/
|
|
191
204
|
invoke(request: LLMInvokeRequest): Promise<LLMInvokeResult>;
|
|
192
205
|
/**
|
|
193
206
|
* Task #2719: 消费 adapter.stream() 返回的事件流,把 pi-ai AssistantMessageEvent
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HTTP outbound defence middleware for the AI SDK (path B).
|
|
3
|
+
*
|
|
4
|
+
* ── Why this file exists (Task #4457 → #4465) ──────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* roy-agent has TWO independent LLM request paths:
|
|
7
|
+
*
|
|
8
|
+
* path A `adapter-pi-ai.ts` → pi-ai `stream()` / `complete()`
|
|
9
|
+
* path B `invoke.ts` → AI SDK `streamText()` / `generateText()`
|
|
10
|
+
*
|
|
11
|
+
* path A is the normal route. path B runs when path A fails — see
|
|
12
|
+
* `llm.ts`: "adapter(pi-ai) failed, falling back to AI SDK invoke".
|
|
13
|
+
*
|
|
14
|
+
* Everything defensive was only ever wired into path A:
|
|
15
|
+
*
|
|
16
|
+
* #4398/#4403 `reasoning_content: ""` on assistant messages (via pi-ai's
|
|
17
|
+
* `onPayload` hook) — path A only
|
|
18
|
+
* #4383 `prompt_cache_key` / `prompt_cache_retention` (via pi-ai's
|
|
19
|
+
* `buildPiCacheOptions`) — path A only
|
|
20
|
+
*
|
|
21
|
+
* Byte-level packet capture of a production fallback proved the gap:
|
|
22
|
+
*
|
|
23
|
+
* | path | assistant msgs | with reasoning_content |
|
|
24
|
+
* |-------------------------|----------------|------------------------|
|
|
25
|
+
* | A `adapter.stream()` | 149 | 149 (100%) |
|
|
26
|
+
* | B `invoke()` (fallback) | 149 | 0 (0%) |
|
|
27
|
+
*
|
|
28
|
+
* Same endpoint, same conversation — the only difference was path B. The
|
|
29
|
+
* request came back `400 [invalid_request_error] The reasoning_content in the
|
|
30
|
+
* thinking mode must be passed back to the API.`
|
|
31
|
+
*
|
|
32
|
+
* The capture also showed path B sending no cache keys at all, so every
|
|
33
|
+
* fallback paid full input price.
|
|
34
|
+
*
|
|
35
|
+
* ── Why a fetch middleware, and not "patch the messages array" ─────────
|
|
36
|
+
*
|
|
37
|
+
* The obvious fix is to inject the field into the `ModelMessage[]` we hand the
|
|
38
|
+
* SDK. That approach is **silently useless** here, for two independent reasons
|
|
39
|
+
* discovered while localising this task:
|
|
40
|
+
*
|
|
41
|
+
* 1. `convertToSDKMessages()` writes cache options under the `openai`
|
|
42
|
+
* providerOptions key, but `@ai-sdk/openai-compatible` reads
|
|
43
|
+
* `openaiCompatible` / `<providerName>` and validates them against
|
|
44
|
+
* `openaiCompatibleLanguageModelChatOptions` — a schema with **no**
|
|
45
|
+
* `promptCacheKey` field at all. So the existing path B cache code has
|
|
46
|
+
* never emitted anything on the wire. (Confirmed by capture: 0 hits.)
|
|
47
|
+
*
|
|
48
|
+
* 2. The wire protocol is not always chat/completions. On
|
|
49
|
+
* `openai-responses` the top-level conversation list is `input`, not
|
|
50
|
+
* `messages`, so any messages-only patch is a no-op there.
|
|
51
|
+
*
|
|
52
|
+
* A `fetch` wrapper sits after all protocol conversion and after providerOptions
|
|
53
|
+
* validation, so it sees exactly the bytes that go on the wire — and it is the
|
|
54
|
+
* only option shared by all three provider factories (`createOpenAI`,
|
|
55
|
+
* `createOpenAICompatible`, `createAnthropic`); `transformRequestBody` exists
|
|
56
|
+
* on `openai-compatible` only.
|
|
57
|
+
*
|
|
58
|
+
* ── Cache-prefix safety (the constraint that shapes every decision here) ──
|
|
59
|
+
*
|
|
60
|
+
* Prompt caching is a PREFIX match: the bytes sent at turn N are the reusable
|
|
61
|
+
* prefix at turn N+1. Therefore:
|
|
62
|
+
*
|
|
63
|
+
* - the injected value is a constant `""`, appended at a deterministic
|
|
64
|
+
* position, on *every* assistant message of *every* turn;
|
|
65
|
+
* - the field is only added when absent (idempotent, no double-injection);
|
|
66
|
+
* - the guard is NARROW: non-DeepSeek providers never get the field, because
|
|
67
|
+
* they either reject unknown fields or hash assistant messages into their
|
|
68
|
+
* own prefix — injecting would be a pure cache regression.
|
|
69
|
+
*
|
|
70
|
+
* Both guarantees are covered by tests in `fallback-path-defense.test.ts`.
|
|
71
|
+
*/
|
|
72
|
+
/** Wire protocols we know how to patch. */
|
|
73
|
+
export type WireProtocol = "openai-chat" | "openai-responses" | "anthropic" | "other";
|
|
74
|
+
export interface OutboundDefenseTarget {
|
|
75
|
+
/** Configured provider id (may be a gateway, e.g. `opencodego`). */
|
|
76
|
+
provider?: string;
|
|
77
|
+
/** Model id actually requested — decides DeepSeek-family membership. */
|
|
78
|
+
modelId?: string;
|
|
79
|
+
/** Conversation id; becomes `prompt_cache_key` for OpenAI-family protocols. */
|
|
80
|
+
sessionId?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Cache retention preference, mirroring pi-ai's `cacheRetention`:
|
|
83
|
+
* - `"long"` → `prompt_cache_key` + `prompt_cache_retention: "24h"`
|
|
84
|
+
* - `"short"` → `prompt_cache_key` only
|
|
85
|
+
* - `"none"` → neither
|
|
86
|
+
*
|
|
87
|
+
* When omitted, OpenAI-family protocols default to `"long"` so path B
|
|
88
|
+
* matches what path A does through `buildPiCacheOptions()` (which defaults
|
|
89
|
+
* to `"long"` for `openai-completions`).
|
|
90
|
+
*/
|
|
91
|
+
cacheRetention?: "none" | "short" | "long";
|
|
92
|
+
/**
|
|
93
|
+
* Restricts which patches may be applied. Omitted → auto-detect from the
|
|
94
|
+
* body shape (permissive; used by unit tests and by callers that already
|
|
95
|
+
* know the endpoint speaks OpenAI).
|
|
96
|
+
*
|
|
97
|
+
* Production passes this explicitly so an Anthropic request can never
|
|
98
|
+
* receive OpenAI-only fields (`prompt_cache_key`) or a stray
|
|
99
|
+
* `reasoning_content` that the Messages API would reject.
|
|
100
|
+
*/
|
|
101
|
+
wireProtocol?: WireProtocol;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Apply both defences to a parsed request body, returning a NEW object.
|
|
105
|
+
*
|
|
106
|
+
* Pure and synchronous, so it can be unit-tested without any HTTP machinery.
|
|
107
|
+
* Returns the original reference when nothing changes, which keeps the
|
|
108
|
+
* "untouched for non-DeepSeek providers" guarantee cheap to assert.
|
|
109
|
+
*/
|
|
110
|
+
export declare function applyOutboundDefense(body: Record<string, unknown>, target: OutboundDefenseTarget): Record<string, unknown>;
|
|
111
|
+
/**
|
|
112
|
+
* Wrap a `fetch` implementation with the outbound defences.
|
|
113
|
+
*
|
|
114
|
+
* The wrapper is deliberately fail-open: anything it cannot understand
|
|
115
|
+
* (non-string body, unparsable JSON, unexpected shape) is forwarded to the
|
|
116
|
+
* inner fetch **completely unchanged**. A broken defence must never turn a
|
|
117
|
+
* recoverable LLM call into a hard failure — path B only runs *because* we are
|
|
118
|
+
* already in a degraded state.
|
|
119
|
+
*
|
|
120
|
+
* @param target provider/model/session of this call
|
|
121
|
+
* @param inner the fetch to delegate to (defaults to globalThis.fetch)
|
|
122
|
+
*/
|
|
123
|
+
export declare function createOutboundDefenseFetch(target: OutboundDefenseTarget, inner?: typeof fetch): typeof fetch;
|
|
124
|
+
/**
|
|
125
|
+
* Map a pi-ai `apiProtocol` (the vocabulary `resolveApiProtocol()` speaks) onto
|
|
126
|
+
* this module's wire-protocol vocabulary.
|
|
127
|
+
*
|
|
128
|
+
* Task #4465 cross-validation (C1): the initial implementation hardcoded the
|
|
129
|
+
* wire protocol per *provider id*, but path A derives it from the **endpoint**
|
|
130
|
+
* (`resolveApiProtocol(provider, baseURL)`). The two disagree for real configs —
|
|
131
|
+
* e.g. the production `minimax` provider points at
|
|
132
|
+
* `https://api.minimaxi.com/anthropic`, which path A classifies as
|
|
133
|
+
* `anthropic-messages` while a per-id table says "OpenAI chat". Injecting
|
|
134
|
+
* OpenAI-only `prompt_cache_key` onto an Anthropic-protocol endpoint would be
|
|
135
|
+
* wrong (and pointless) there.
|
|
136
|
+
*
|
|
137
|
+
* So callers should derive the protocol the same way path A does and hand the
|
|
138
|
+
* result through this mapper.
|
|
139
|
+
*/
|
|
140
|
+
export declare function wireProtocolFromApiProtocol(apiProtocol: string | undefined): WireProtocol;
|
|
@@ -8,15 +8,56 @@
|
|
|
8
8
|
export interface TracedOptions {
|
|
9
9
|
name?: string;
|
|
10
10
|
recordParams?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* ★ 2026-10-22:**result 是否写进 DB**(默认 **true** = 写)。
|
|
13
|
+
*
|
|
14
|
+
* 为什么默认是 true:单个返回值通常并不大,真正把 traces.db 撑到 169GB 的是
|
|
15
|
+
* **不断累积的入参**(每轮 LLM 请求都带完整 system prompt + 全量历史)。
|
|
16
|
+
* 所以默认保留 result(不改变既有调用方的数据可见性),瘦身交给
|
|
17
|
+
* `paramFilter` / `resultFilter`:需要截断的 span 显式声明摘要即可。
|
|
18
|
+
*
|
|
19
|
+
* 现在的语义:
|
|
20
|
+
* - 有 `resultFilter` → 存 filter 产出的摘要(filter 失效时退回本选项裁决)
|
|
21
|
+
* - `recordResultToDb: true` → 强制存**完整** result(优先于 resultFilter)
|
|
22
|
+
* - 否则按本选项:`true`(默认)存完整 result / `false` 显式不存
|
|
23
|
+
*
|
|
24
|
+
* 「日志里要不要打」由 `logResult` 单独控制,与本选项解耦。
|
|
25
|
+
*/
|
|
11
26
|
recordResult?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* ★ 2026-10-22:**强制把完整 result 写进 DB**,即使 `recordResult: false`。
|
|
29
|
+
*
|
|
30
|
+
* 背景:`recordResult` 原本只控制日志,DB 里始终存全量 result,导致
|
|
31
|
+
* traces.db 膨胀到 169GB。修复后 `recordResult: false` 意味着「不入库」,
|
|
32
|
+
* 但少数场景确实需要完整返回值(例如把 result 当业务数据读的下游)。
|
|
33
|
+
* 这些场景用本选项显式声明 —— **默认不存,需要就显式开**。
|
|
34
|
+
*/
|
|
35
|
+
recordResultToDb?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* ★ 2026-10-22:**日志里是否打印 result**(与「DB 存不存」解耦)。
|
|
38
|
+
*
|
|
39
|
+
* 背景:改造前 `recordResult` 同时控制日志与 DB。DB 瘦身时把它改成 false,
|
|
40
|
+
* 会连带让 app.log 里的 LLM 响应消失 —— DB 省了体积,排障能力也一起没了。
|
|
41
|
+
*
|
|
42
|
+
* 语义:不设时跟随 `recordResult`(向后兼容);
|
|
43
|
+
* 显式设 `true` 可实现「DB 不存完整 result,但日志照打」。
|
|
44
|
+
*/
|
|
45
|
+
logResult?: boolean;
|
|
12
46
|
recordError?: boolean;
|
|
13
47
|
log?: boolean;
|
|
14
48
|
maxLogSize?: number;
|
|
15
49
|
paramFilter?: (args: any[], argNames?: string[]) => Record<string, any>;
|
|
16
50
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
51
|
+
* result filter —— 把返回值压成一份**摘要**。
|
|
52
|
+
*
|
|
53
|
+
* 摘要的键会被摊平到 span 的顶层属性(便于 `debug trace` 直接看字段),
|
|
54
|
+
* ⚠️ **同时它就是 DB 里 `result` 列的内容** —— 也就是说这个 filter 不只是
|
|
55
|
+
* 「额外加几个属性」,它**替换**了原本要存的完整返回值。
|
|
56
|
+
*
|
|
57
|
+
* 想保留完整 result,请显式设 `recordResultToDb: true`(它优先于本 filter)。
|
|
58
|
+
*
|
|
59
|
+
* 若 filter 抛异常或没有返回可用对象,会**退回** `recordResult` 的裁决,
|
|
60
|
+
* 不会静默丢掉调用方明确要求记录的 result。
|
|
20
61
|
*/
|
|
21
62
|
resultFilter?: (result: any) => Record<string, any>;
|
|
22
63
|
/**
|
|
@@ -78,6 +119,8 @@ export declare function TracedLightweight(options?: {
|
|
|
78
119
|
export declare function wrapFunction<T extends (...args: any[]) => any>(fn: T, name: string, options?: {
|
|
79
120
|
recordParams?: boolean;
|
|
80
121
|
recordResult?: boolean;
|
|
122
|
+
recordResultToDb?: boolean;
|
|
123
|
+
logResult?: boolean;
|
|
81
124
|
recordError?: boolean;
|
|
82
125
|
log?: boolean;
|
|
83
126
|
maxLogSize?: number;
|
|
@@ -12,3 +12,4 @@ export { propagation, serialize, parse, type ExtractedContext, } from "./opentel
|
|
|
12
12
|
export { injectToEnv, injectToEnvWithContext, injectToEnvFromCarrier, getTraceparentHeader, type EnvCarrier, } from "./opentelemetry/propagation-env";
|
|
13
13
|
export { createLogger, setQuietMode, isQuietMode, setConfigComponent as setLoggerConfigComponent, getLogLevel, getLogLevels, getLogDir, getLogFile, setLogDirOverride, getLogDirOverride, simplifyFilePath, getMaxOutput, } from "./logger";
|
|
14
14
|
export { TracedAs, Traced, TracedLightweight, wrapFunction, type TracedOptions } from "./decorator";
|
|
15
|
+
export { isTraceFullMode, resetTraceFullModeCache, llmInvokeParamFilter, llmInvokeResultFilter, messagesParamFilter, toolExecParamFilter, toolInvokeParamFilter, toolExecResultFilter, envQueryParamFilter, agentRunParamFilter, recordSessionMessagesParamFilter, embedParamFilter, embedResultFilter, } from "./trace-filters";
|
|
@@ -7,19 +7,32 @@ import {
|
|
|
7
7
|
injectToEnv,
|
|
8
8
|
injectToEnvFromCarrier,
|
|
9
9
|
injectToEnvWithContext
|
|
10
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
10
|
+
} from "../../shared/@ai-setting/roy-agent-core-tze5596n.js";
|
|
11
11
|
import"../../shared/@ai-setting/roy-agent-core-7hh0brvs.js";
|
|
12
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
13
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
14
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
15
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
16
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
12
|
+
import"../../shared/@ai-setting/roy-agent-core-0kn3zt1t.js";
|
|
13
|
+
import"../../shared/@ai-setting/roy-agent-core-ytd5eztz.js";
|
|
14
|
+
import"../../shared/@ai-setting/roy-agent-core-yphwdm9x.js";
|
|
15
|
+
import"../../shared/@ai-setting/roy-agent-core-m97jn2ra.js";
|
|
16
|
+
import"../../shared/@ai-setting/roy-agent-core-syyw58p9.js";
|
|
17
17
|
import {
|
|
18
18
|
Traced,
|
|
19
19
|
TracedAs,
|
|
20
20
|
TracedLightweight,
|
|
21
|
+
agentRunParamFilter,
|
|
22
|
+
embedParamFilter,
|
|
23
|
+
embedResultFilter,
|
|
24
|
+
envQueryParamFilter,
|
|
25
|
+
isTraceFullMode,
|
|
26
|
+
llmInvokeParamFilter,
|
|
27
|
+
llmInvokeResultFilter,
|
|
28
|
+
messagesParamFilter,
|
|
29
|
+
recordSessionMessagesParamFilter,
|
|
30
|
+
resetTraceFullModeCache,
|
|
31
|
+
toolExecParamFilter,
|
|
32
|
+
toolExecResultFilter,
|
|
33
|
+
toolInvokeParamFilter,
|
|
21
34
|
wrapFunction
|
|
22
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
35
|
+
} from "../../shared/@ai-setting/roy-agent-core-8p63s836.js";
|
|
23
36
|
import {
|
|
24
37
|
OTelTracerProvider,
|
|
25
38
|
SpanKind,
|
|
@@ -41,21 +54,30 @@ import {
|
|
|
41
54
|
setLogDirOverride,
|
|
42
55
|
setQuietMode,
|
|
43
56
|
simplifyFilePath
|
|
44
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
57
|
+
} from "../../shared/@ai-setting/roy-agent-core-rt115qfc.js";
|
|
45
58
|
import {
|
|
46
59
|
SQLiteSpanStorage
|
|
47
60
|
} from "../../shared/@ai-setting/roy-agent-core-jnszp0jq.js";
|
|
48
61
|
import"../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
|
|
49
62
|
export {
|
|
50
63
|
wrapFunction,
|
|
64
|
+
toolInvokeParamFilter,
|
|
65
|
+
toolExecResultFilter,
|
|
66
|
+
toolExecParamFilter,
|
|
51
67
|
simplifyFilePath,
|
|
52
68
|
setQuietMode,
|
|
53
69
|
setConfigComponent as setLoggerConfigComponent,
|
|
54
70
|
setLogDirOverride,
|
|
55
71
|
serialize,
|
|
56
72
|
resetTracerProvider,
|
|
73
|
+
resetTraceFullModeCache,
|
|
74
|
+
recordSessionMessagesParamFilter,
|
|
57
75
|
propagation,
|
|
58
76
|
parse,
|
|
77
|
+
messagesParamFilter,
|
|
78
|
+
llmInvokeResultFilter,
|
|
79
|
+
llmInvokeParamFilter,
|
|
80
|
+
isTraceFullMode,
|
|
59
81
|
isQuietMode,
|
|
60
82
|
injectToEnvWithContext,
|
|
61
83
|
injectToEnvFromCarrier,
|
|
@@ -70,7 +92,11 @@ export {
|
|
|
70
92
|
getLogDir,
|
|
71
93
|
getDefaultSpanDbPath,
|
|
72
94
|
getDefaultLogDir,
|
|
95
|
+
envQueryParamFilter,
|
|
96
|
+
embedResultFilter,
|
|
97
|
+
embedParamFilter,
|
|
73
98
|
createLogger,
|
|
99
|
+
agentRunParamFilter,
|
|
74
100
|
TracedLightweight,
|
|
75
101
|
TracedAs,
|
|
76
102
|
Traced,
|
|
@@ -102,6 +102,35 @@ export declare class OTelTracerProvider {
|
|
|
102
102
|
private storage;
|
|
103
103
|
private initialized;
|
|
104
104
|
private globalContext;
|
|
105
|
+
/**
|
|
106
|
+
* ★ Task #4486 Phase 3: per-run trace context 作用域(AsyncLocalStorage)。
|
|
107
|
+
*
|
|
108
|
+
* 为什么需要:`globalContext` 是进程级单槽。并发多 session 时
|
|
109
|
+
* - run B 的 startSpan() 会继承 run A 刚设的 traceId(串 trace)
|
|
110
|
+
* - run A 收尾 setGlobalContext(undefined) 会把 run B 的父上下文清掉
|
|
111
|
+
*
|
|
112
|
+
* `withGlobalContext(ctx, fn)` 在异步链内覆盖读值(链外仍回落进程级单槽,
|
|
113
|
+
* 完全向后兼容既有调用方)。
|
|
114
|
+
*
|
|
115
|
+
* 用 `{ value }` 包装而不是直接存 SpanContext:需要区分
|
|
116
|
+
* "链内显式设为 undefined"(屏蔽继承)与 "链内没设置"(回落进程级)。
|
|
117
|
+
*/
|
|
118
|
+
private globalContextScope;
|
|
119
|
+
/**
|
|
120
|
+
* ★ Task #4515 (H1): 进程级 tracer currentContext 表(ALS 作用域外使用)。
|
|
121
|
+
*
|
|
122
|
+
* `instanceId → SpanContext`。取代原来 `OTelTracerImpl` 的私有单槽字段。
|
|
123
|
+
* 作用域外的读写在**同一个 map** 上做,所以既有的"同步链式嵌套"语义
|
|
124
|
+
* (root → child 自动继承)完全不变。
|
|
125
|
+
*/
|
|
126
|
+
private tracerContexts;
|
|
127
|
+
/**
|
|
128
|
+
* ★ Task #4515 (H1): 当前 ALS 作用域内的 tracer currentContext 表。
|
|
129
|
+
*
|
|
130
|
+
* `withGlobalContext()` 为每次 run 建一张**独立的 map**,所以并发 run 的
|
|
131
|
+
* `startSpan()` / `span.end()` 各改各的槽,互不可见 —— 这是 H1 的根治点。
|
|
132
|
+
*/
|
|
133
|
+
private tracerContextScope;
|
|
105
134
|
readonly instanceId: string;
|
|
106
135
|
constructor(storage?: SpanStorage, dbPath?: string);
|
|
107
136
|
/**
|
|
@@ -115,13 +144,69 @@ export declare class OTelTracerProvider {
|
|
|
115
144
|
*/
|
|
116
145
|
isInitialized(): boolean;
|
|
117
146
|
/**
|
|
118
|
-
*
|
|
147
|
+
* 获取当前 trace context。
|
|
148
|
+
*
|
|
149
|
+
* ★ Task #4486 Phase 3: 优先读 ALS 作用域(withGlobalContext 设置),
|
|
150
|
+
* 没有作用域时回落进程级单槽(旧语义)。
|
|
119
151
|
*/
|
|
120
152
|
getGlobalContext(): SpanContext | undefined;
|
|
121
153
|
/**
|
|
122
154
|
* 设置全局 context(所有 tracer 共享)
|
|
155
|
+
*
|
|
156
|
+
* ⚠️ 并发场景请优先用 `withGlobalContext()` —— 直接设置是进程级、
|
|
157
|
+
* 会被其他并发 run 观察到,且单方 set(undefined) 会连带清掉别人的父上下文。
|
|
123
158
|
*/
|
|
124
159
|
setGlobalContext(context: SpanContext | undefined): void;
|
|
160
|
+
/**
|
|
161
|
+
* ★ Task #4486 Phase 3: 在指定 trace context 作用域内执行异步函数。
|
|
162
|
+
*
|
|
163
|
+
* - 作用域内 `getGlobalContext()` 返回 `context`(即使传 undefined 也会
|
|
164
|
+
* 屏蔽进程级单槽,即"本次 run 没有父 trace")
|
|
165
|
+
* - 作用域外不受影响,也不影响其他并发 run
|
|
166
|
+
* - 嵌套调用以内层为准,退出后恢复外层
|
|
167
|
+
*
|
|
168
|
+
* @param context 本次 run 的 trace context(可为 undefined = 无父)
|
|
169
|
+
* @param fn 要执行的异步函数
|
|
170
|
+
*/
|
|
171
|
+
withGlobalContext<T>(context: SpanContext | undefined, fn: () => Promise<T>): Promise<T>;
|
|
172
|
+
/**
|
|
173
|
+
* ★ Task #4515 (H1-c): 在指定 context 的**同步**作用域内执行 `fn`。
|
|
174
|
+
*
|
|
175
|
+
* 为什么要这个:`withGlobalContext` 只接受 async 函数,而 `span.end()` 是
|
|
176
|
+
* 同步调用。如果 end() 在作用域外执行,`handleSpanEnd()` 会把恢复出的父上下文
|
|
177
|
+
* 写进**进程级**表 —— 于是下一轮 run 的 ALS 播种快照会继承上一轮的 trace,
|
|
178
|
+
* 表现为"下一轮复用了上一轮的 traceId"。
|
|
179
|
+
*
|
|
180
|
+
* 用这个把 end() 包回本 run 的作用域,写入就落在本 run 那张(随后丢弃的)表里。
|
|
181
|
+
*/
|
|
182
|
+
runInGlobalContextSync<T>(context: SpanContext | undefined, fn: () => T): T;
|
|
183
|
+
/**
|
|
184
|
+
* ★ Task #4515 (H1): 读某 tracer 实例的 currentContext。
|
|
185
|
+
*
|
|
186
|
+
* 作用域内 → 读该 run 的 map(miss 回落进程级表,兼容作用域外设的上下文);
|
|
187
|
+
* 作用域外 → 读进程级表(旧语义)。
|
|
188
|
+
*/
|
|
189
|
+
getTracerCurrentContext(instanceId: string): SpanContext | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* ★ Task #4515 (H1): 写某 tracer 实例的 currentContext。
|
|
192
|
+
*
|
|
193
|
+
* 作用域内 → 只写该 run 的 map(并发 run 互不可见);
|
|
194
|
+
* 作用域外 → 写进程级表(旧语义)。
|
|
195
|
+
*/
|
|
196
|
+
setTracerCurrentContext(instanceId: string, context: SpanContext | undefined): void;
|
|
197
|
+
/**
|
|
198
|
+
* ★ Task #4519: 清空**所有** tracer 实例的 currentContext(当前作用域内)。
|
|
199
|
+
*
|
|
200
|
+
* 为什么需要它、而不是逐个 `getTracer(name).setCurrentContext(undefined)`:
|
|
201
|
+
* 按名字清只能清掉**已实例化**的那个 tracer。而 `tracerContexts` 表是
|
|
202
|
+
* `instanceId → context`,此前其它名字的 tracer 若在进程级表里留了父上下文,
|
|
203
|
+
* 它仍会被继承(交叉复核指出:只清 "roy-tracer" 清不干净)。
|
|
204
|
+
* 这里直接清整表,保证**任何** tracer 名都不在事件之间串味。
|
|
205
|
+
*
|
|
206
|
+
* 作用域内 → 只清本 run 那张 map(不动进程级,并发 run 互不影响);
|
|
207
|
+
* 作用域外 → 清进程级表。
|
|
208
|
+
*/
|
|
209
|
+
clearAllTracerCurrentContexts(): void;
|
|
125
210
|
/**
|
|
126
211
|
* 获取 Tracer
|
|
127
212
|
*/
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Trace 参数瘦身过滤器(paramFilter / resultFilter 共享工具)
|
|
3
|
+
*
|
|
4
|
+
* ## 背景
|
|
5
|
+
*
|
|
6
|
+
* `traces.db` 曾膨胀到 169GB / 1800 万 span。根因不是 span 数量多,而是
|
|
7
|
+
* **单个 span 把全量 messages / tool result 写进了 attributes**:
|
|
8
|
+
*
|
|
9
|
+
* | span name | 平均 attributes 体积 |
|
|
10
|
+
* |------------------------------|----------------------|
|
|
11
|
+
* | `llm.component.invoke` | 473 KB |
|
|
12
|
+
* | `session.extractRecentMessages` | 878 KB |
|
|
13
|
+
* | `agent.component.executeTool` | 259 KB |
|
|
14
|
+
* | `agent.component.buildAdditionInfo` | 158 KB |
|
|
15
|
+
*
|
|
16
|
+
* 每个 LLM 调用都把「system prompt + 全量对话历史」原样序列化进 DB,
|
|
17
|
+
* 排障价值极低(DB 里只有数字,看不出内容)而体积代价极高。
|
|
18
|
+
*
|
|
19
|
+
* ## 方案:显式白名单 filter
|
|
20
|
+
*
|
|
21
|
+
* 用 `paramFilter` / `resultFilter` 把入参/返回值替换成**摘要**:
|
|
22
|
+
* 条数、长度、模型名 —— 排障时最需要的那几个数字,体积 < 1KB。
|
|
23
|
+
*
|
|
24
|
+
* 相比 `recordParams: false`(黑盒式"全丢"),filter 是**显式白名单**:
|
|
25
|
+
* 读代码就知道存了什么、没存什么;后续要加字段只改一个函数。
|
|
26
|
+
*
|
|
27
|
+
* ## 全量模式
|
|
28
|
+
*
|
|
29
|
+
* `ROY_TRACE_FULL=1` 时,所有 filter 退化为"原样保留",用于临时全量排查。
|
|
30
|
+
* 这样运维时只需重启进程 + 加环境变量,**不必改代码重新构建**。
|
|
31
|
+
*/
|
|
32
|
+
/** 强制刷新全量模式缓存(测试用) */
|
|
33
|
+
export declare function resetTraceFullModeCache(): void;
|
|
34
|
+
/**
|
|
35
|
+
* 是否处于全量模式(`ROY_TRACE_FULL=1`)。
|
|
36
|
+
*
|
|
37
|
+
* 只认 `"1"` / `"true"` / `"yes"`(大小写不敏感),避免 `ROY_TRACE_FULL=0`
|
|
38
|
+
* 这种"看起来像开了其实是关了"的歧义写法被误判为开启。
|
|
39
|
+
*/
|
|
40
|
+
export declare function isTraceFullMode(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* 通用:LLM 调用入参摘要(`llm.component.invoke` / `agent.component.invokeLLM`)。
|
|
43
|
+
*
|
|
44
|
+
* 保留的字段都是**排障时最常问的问题**的答案:
|
|
45
|
+
* - 用的是哪个模型 / provider
|
|
46
|
+
* - 这次塞了多少条消息、多大(判断是不是上下文爆炸)
|
|
47
|
+
* - 带了多少个工具
|
|
48
|
+
*/
|
|
49
|
+
export declare function llmInvokeParamFilter(args: any[]): Record<string, any>;
|
|
50
|
+
/**
|
|
51
|
+
* 通用:LLM 调用返回值摘要。
|
|
52
|
+
*
|
|
53
|
+
* 只留 `finishReason` / 输出长度 / 推理长度 / tool call 数 / usage ——
|
|
54
|
+
* 这几个是判断"这次调用是否正常、有没有被截断、烧了多少 token"的关键数字。
|
|
55
|
+
*
|
|
56
|
+
* ⚠️ 真实类型是 `LLMInvokeResult = { output: LLMOutput, ... }`,
|
|
57
|
+
* `LLMOutput = { content, reasoning?, finishReason, toolCalls?, usage? }`,
|
|
58
|
+
* **没有 `text` / `parts`**;`AgentLLMOutput` 也是 `content` 形状。
|
|
59
|
+
* 两种都兼容:`content` 优先。
|
|
60
|
+
*/
|
|
61
|
+
export declare function llmInvokeResultFilter(r: any): Record<string, any>;
|
|
62
|
+
/**
|
|
63
|
+
* 通用:消息数组入参摘要(`session.extractRecentMessages` 等)。
|
|
64
|
+
*
|
|
65
|
+
* @param args[0] 通常是消息数组本身,也可能是 `{ messages: [...] }`
|
|
66
|
+
*/
|
|
67
|
+
export declare function messagesParamFilter(args: any[]): Record<string, any>;
|
|
68
|
+
/**
|
|
69
|
+
* 通用:工具执行入参摘要(`agent.component.executeTool`)。
|
|
70
|
+
*
|
|
71
|
+
* 工具参数可能含大文件内容,所以只留"工具名 + 参数键名列表",不留参数值。
|
|
72
|
+
*/
|
|
73
|
+
export declare function toolExecParamFilter(args: any[]): Record<string, any>;
|
|
74
|
+
/**
|
|
75
|
+
* 通用:embed 入参摘要(`llm.adapter.embed` / `llm.adapter.ai_sdk.embed`)。
|
|
76
|
+
*
|
|
77
|
+
* embed 的 `texts`/`input` 是大字符串数组,**绝对不能入库**。
|
|
78
|
+
*/
|
|
79
|
+
export declare function embedParamFilter(args: any[]): Record<string, any>;
|
|
80
|
+
/**
|
|
81
|
+
* 通用:embed 返回值摘要 —— 只留维度数,不留向量本身。
|
|
82
|
+
*/
|
|
83
|
+
export declare function embedResultFilter(r: any): Record<string, any>;
|
|
84
|
+
/**
|
|
85
|
+
* 工具执行返回值摘要。
|
|
86
|
+
*
|
|
87
|
+
* 返回值里最大的两块是 `output`(stdout)和 `metadata.stdout/stderr` ——
|
|
88
|
+
* 一次 `cat` 一个大文件就能写进几 MB。同样只留长度 + 截断前缀。
|
|
89
|
+
*/
|
|
90
|
+
export declare function toolExecResultFilter(r: any): Record<string, any>;
|
|
91
|
+
/**
|
|
92
|
+
* 工具执行入参摘要(`tool.bash.execute` 的 command / `tool.component.execute` 的 args)。
|
|
93
|
+
*/
|
|
94
|
+
export declare function toolInvokeParamFilter(args: any[]): Record<string, any>;
|
|
95
|
+
/**
|
|
96
|
+
* 顶层查询入参摘要(`env.handle_query` / `env.handle_workflow_agent_query`)。
|
|
97
|
+
*
|
|
98
|
+
* 入参 `query` 是 `string | ContentPart[]` —— 多模态时是图片/文件的数组,
|
|
99
|
+
* 可能很大。只留长度与类型,不留内容。
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* 环境入口(`env.handle_query` / `env.handle_workflow_agent_query`)入参摘要。
|
|
103
|
+
*
|
|
104
|
+
* ⚠️ **两个调用点的入参形状不同**,不能共用同一套解析:
|
|
105
|
+
* - `env.handle_query(query, context?)` → args[0] 是 **query**
|
|
106
|
+
* - `env.handle_workflow_agent_query(agentName, query, agentComponent, context?)`
|
|
107
|
+
* → args[0] 是 **agentName**,args[1] 才是 query
|
|
108
|
+
*
|
|
109
|
+
* 早期版本把 args[0] 一律当 agentName,导致 `handle_query` 的
|
|
110
|
+
* **整条 query 被原样存进 `agentName` 字段** —— 过滤器等于没生效。
|
|
111
|
+
* 现在按「参数个数 + 形状」区分两种入口。
|
|
112
|
+
*/
|
|
113
|
+
export declare function envQueryParamFilter(args: any[]): Record<string, any>;
|
|
114
|
+
/**
|
|
115
|
+
* `agent.component.run` 入参摘要。
|
|
116
|
+
*
|
|
117
|
+
* 入参是 `(agentName, query, context)` —— `query` 可能是多模态数组
|
|
118
|
+
* (base64 图片能到 MB 级)。只留长度与条数。
|
|
119
|
+
*/
|
|
120
|
+
export declare function agentRunParamFilter(args: any[]): Record<string, any>;
|
|
121
|
+
/**
|
|
122
|
+
* `agent.component.recordSessionMessages` 入参摘要。
|
|
123
|
+
*
|
|
124
|
+
* ⚠️ 这是**最大的漏网之鱼**:`allMessages` 是**每一轮 ReAct 迭代的全部消息**
|
|
125
|
+
* (含工具输出),实测单 span ~200 KB / 迭代。必须只留条数与长度。
|
|
126
|
+
*/
|
|
127
|
+
export declare function recordSessionMessagesParamFilter(args: any[]): Record<string, any>;
|
package/dist/env/mcp/index.js
CHANGED
|
@@ -10,21 +10,21 @@ import {
|
|
|
10
10
|
augmentNpmEnvForPackageRunner,
|
|
11
11
|
getMcpPathPriority,
|
|
12
12
|
resolvePackageRunnerCommand
|
|
13
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
13
|
+
} from "../../shared/@ai-setting/roy-agent-core-84xtww7d.js";
|
|
14
14
|
import {
|
|
15
15
|
adaptMcpTool,
|
|
16
16
|
convertInputSchemaToZod,
|
|
17
17
|
createMcpToolsDescription
|
|
18
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
18
|
+
} from "../../shared/@ai-setting/roy-agent-core-m68z3pw1.js";
|
|
19
19
|
import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
|
|
20
20
|
import"../../shared/@ai-setting/roy-agent-core-7hh0brvs.js";
|
|
21
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
22
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
23
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
24
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
25
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
26
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
27
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
21
|
+
import"../../shared/@ai-setting/roy-agent-core-0kn3zt1t.js";
|
|
22
|
+
import"../../shared/@ai-setting/roy-agent-core-ytd5eztz.js";
|
|
23
|
+
import"../../shared/@ai-setting/roy-agent-core-yphwdm9x.js";
|
|
24
|
+
import"../../shared/@ai-setting/roy-agent-core-m97jn2ra.js";
|
|
25
|
+
import"../../shared/@ai-setting/roy-agent-core-syyw58p9.js";
|
|
26
|
+
import"../../shared/@ai-setting/roy-agent-core-8p63s836.js";
|
|
27
|
+
import"../../shared/@ai-setting/roy-agent-core-rt115qfc.js";
|
|
28
28
|
import"../../shared/@ai-setting/roy-agent-core-jnszp0jq.js";
|
|
29
29
|
import {
|
|
30
30
|
ensureFallbackNpmPrefix,
|
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
adaptMcpTool,
|
|
3
3
|
convertInputSchemaToZod,
|
|
4
4
|
createMcpToolsDescription
|
|
5
|
-
} from "../../../shared/@ai-setting/roy-agent-core-
|
|
6
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
5
|
+
} from "../../../shared/@ai-setting/roy-agent-core-m68z3pw1.js";
|
|
6
|
+
import"../../../shared/@ai-setting/roy-agent-core-rt115qfc.js";
|
|
7
7
|
import"../../../shared/@ai-setting/roy-agent-core-jnszp0jq.js";
|
|
8
8
|
import"../../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
|
|
9
9
|
export {
|