@dsh-cc/side-query 0.8.0-rc.1
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/LICENSE +201 -0
- package/README.i18n.yaml +6 -0
- package/README.md +39 -0
- package/README.zh.md +39 -0
- package/lib/index.d.ts +69 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +109 -0
- package/lib/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
|
2
|
+
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
|
+
# after editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm check:readme --write
|
|
5
|
+
README.md: 411778a1c3436cbcf8d4b8a8885dbe2633d8357b
|
|
6
|
+
README.zh.md: 9e3bf6a2a4764039d4fc194e2909c24523ab549f
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @dsh-cc/side-query
|
|
2
|
+
|
|
3
|
+
English | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
The **side-query primitive**: a declarative, never-throws, non-streaming auxiliary LLM call for harness features that need a small/fast model answer off the main agent loop (design: docs/plans/2026-09-15-side-queries.md). Before this package, web_fetch's page summarizer, the session-title provider, and the permission auto-mode classifier each hand-rolled their own one-shot call with drifting timeout/failure/route semantics; `runSideQuery` is the single shared shape.
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
export interface SideQueryOptions {
|
|
11
|
+
agent: Agent // required: provider fill via agent.session.requestHeader (web-fetch precedent)
|
|
12
|
+
alias?: string // default 'haiku' (resolveAlias / ccModelRoutes lane)
|
|
13
|
+
system?: string
|
|
14
|
+
prompt: string
|
|
15
|
+
maxTokens?: number // default 512
|
|
16
|
+
timeoutMs?: number // default 8000
|
|
17
|
+
signal?: AbortSignal // caller-owned; composed with the timeout (AbortSignal.any)
|
|
18
|
+
onUnrouted?: 'inherit' | 'skip' // default 'inherit' (alias unconfigured -> parent route)
|
|
19
|
+
rejectToolCalls?: boolean // default true
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type SideQueryResult =
|
|
23
|
+
| { ok: true; text: string; inheritedRoute: boolean; durationMs: number }
|
|
24
|
+
| { ok: false; reason: 'unrouted' | 'timeout' | 'error' | 'empty'; inheritedRoute?: boolean }
|
|
25
|
+
|
|
26
|
+
export async function runSideQuery(ctx: Context, opts: SideQueryOptions): Promise<SideQueryResult>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Semantics
|
|
30
|
+
|
|
31
|
+
- **Never throws.** Every failure shape — unrouted alias, timeout, adapter error, empty text — collapses into `SideQueryResult`. The dsh-llm runtime normalizes adapter throws into terminal error chunks, so `reason: 'error'` covers both paths.
|
|
32
|
+
- Non-streaming contract: consumes `ctx.llm.stream` through the BlockAssembler pattern and awaits the full text (the `tool-web-fetch` one-shot pattern).
|
|
33
|
+
- `rejectToolCalls` (default) rejects streams that emit tool-call blocks. A side query that tries to *act* is a bug, not a capability (the memory recall-selector rogue-execution lesson).
|
|
34
|
+
- `inheritedRoute` reports whether the alias fell back to the parent route, so consumers can meter zero-savings runs (see `warnOnInherit` in `@dsh-cc/cc-model-aliases`).
|
|
35
|
+
- No retry, no cache, no persistence, no ledger — those belong to consumers (e.g. `@dsh-cc/tool-use-summary` keeps the ledger).
|
|
36
|
+
|
|
37
|
+
## Shape
|
|
38
|
+
|
|
39
|
+
Library package: no preset row, no settings namespace, no capability-manifest entry. Consumers depend on it with `workspace:^` and add a project reference in their own `tsconfig.json`.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @dsh-cc/side-query
|
|
2
|
+
|
|
3
|
+
English | [中文](README.md)
|
|
4
|
+
|
|
5
|
+
**side-query 原语**:声明式、绝不抛异常、非流式的辅助 LLM 调用,供 harness 中需要小/快模型在主 Agent 循环之外作答的特性使用(设计文档:docs/plans/2026-09-15-side-queries.md)。在本包之前,web_fetch 的页面摘要、session-title 提供器、权限 auto 模式分类器各自手写一次性调用,超时/失败/路由语义相互漂移;`runSideQuery` 是收敛后的唯一形态。
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
export interface SideQueryOptions {
|
|
11
|
+
agent: Agent // 必填:经 agent.session.requestHeader 补齐路由的 provider 半(web-fetch 先例)
|
|
12
|
+
alias?: string // 默认 'haiku'(resolveAlias / ccModelRoutes 通道)
|
|
13
|
+
system?: string
|
|
14
|
+
prompt: string
|
|
15
|
+
maxTokens?: number // 默认 512
|
|
16
|
+
timeoutMs?: number // 默认 8000
|
|
17
|
+
signal?: AbortSignal // 调用方持有;与超时组合(AbortSignal.any)
|
|
18
|
+
onUnrouted?: 'inherit' | 'skip' // 默认 'inherit'(alias 未配置 → 继承父路由)
|
|
19
|
+
rejectToolCalls?: boolean // 默认 true
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type SideQueryResult =
|
|
23
|
+
| { ok: true; text: string; inheritedRoute: boolean; durationMs: number }
|
|
24
|
+
| { ok: false; reason: 'unrouted' | 'timeout' | 'error' | 'empty'; inheritedRoute?: boolean }
|
|
25
|
+
|
|
26
|
+
export async function runSideQuery(ctx: Context, opts: SideQueryOptions): Promise<SideQueryResult>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 语义
|
|
30
|
+
|
|
31
|
+
- **绝不抛异常**。所有失败形态——alias 无路由、超时、adapter 错误、空文本——都收敛进 `SideQueryResult`。dsh-llm runtime 会把 adapter 抛错规范化为终止 error chunk,因此两条路径都映射到 `reason: 'error'`。
|
|
32
|
+
- 非流式契约:内部经 BlockAssembler 模式消费 `ctx.llm.stream` 并等待完整文本(`tool-web-fetch` 的一次性调用模式)。
|
|
33
|
+
- `rejectToolCalls`(默认开启)拒绝发出 tool-call 块的流:side query 试图"动手"是 bug 而不是能力(memory recall selector 幻影执行事故的教训)。
|
|
34
|
+
- `inheritedRoute` 报告 alias 是否回落到了父路由,供消费方计量"零节省"运行(配合 `@dsh-cc/cc-model-aliases` 的 `warnOnInherit`)。
|
|
35
|
+
- 无重试、无缓存、无持久化、无账本——这些属于消费方(如 `@dsh-cc/tool-use-summary` 自带账本)。
|
|
36
|
+
|
|
37
|
+
## 形态
|
|
38
|
+
|
|
39
|
+
纯库包:无 preset 行、无 settings 命名空间、无 capability manifest 条目。消费方以 `workspace:^` 依赖它,并在自己的 `tsconfig.json` 中加 project reference。
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First-class auxiliary-LLM primitive: a one-shot, non-streaming, fail-soft
|
|
3
|
+
* side query over a cheap-lane alias route. Library package — no listeners,
|
|
4
|
+
* no preset mount; consumers carry their own registrations.
|
|
5
|
+
*
|
|
6
|
+
* Semantics (design doc §4): never throws; tool-call blocks rejected by
|
|
7
|
+
* default; `AbortSignal.timeout(timeoutMs)` composed with the caller's signal
|
|
8
|
+
* via `AbortSignal.any` and both aborts map to `reason: 'timeout'`;
|
|
9
|
+
* unfillable route → `'unrouted'` (with the `inherit` fallback running on the
|
|
10
|
+
* parent route); empty assembled text → `'empty'`; any other failure →
|
|
11
|
+
* `'error'`.
|
|
12
|
+
*
|
|
13
|
+
* @module @dsh-cc/side-query
|
|
14
|
+
*/
|
|
15
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
16
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
17
|
+
/** Options for {@link runSideQuery}. */
|
|
18
|
+
export interface SideQueryOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Calling agent; REQUIRED. Route/provider fill follows the web-fetch
|
|
21
|
+
* precedent: a string-form alias needs the calling agent's requestHeader()
|
|
22
|
+
* to complete the provider half of the one-shot route.
|
|
23
|
+
*/
|
|
24
|
+
agent: Agent;
|
|
25
|
+
/** Model alias consulted through ccModelRoutes/resolveAlias. Default 'haiku'. */
|
|
26
|
+
alias?: string;
|
|
27
|
+
/** System prompt for the one-shot. */
|
|
28
|
+
system?: string;
|
|
29
|
+
/** User prompt content (fully assembled by the caller). */
|
|
30
|
+
prompt: string;
|
|
31
|
+
/** Hard token budget. Default 512. */
|
|
32
|
+
maxTokens?: number;
|
|
33
|
+
/** Wall-clock budget; aborts the stream. Default 8000. */
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Caller-owned abort signal (e.g. the host plugin's effect-scope disposal);
|
|
37
|
+
* composed with the internal timeout. Never a tool-scoped exec.signal.
|
|
38
|
+
*/
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
/**
|
|
41
|
+
* Behavior when the alias resolves to nothing (unconfigured + no parent
|
|
42
|
+
* route to inherit, or provider half cannot be completed). Default
|
|
43
|
+
* 'inherit'; 'skip' returns `{ ok: false, reason: 'unrouted' }` without
|
|
44
|
+
* touching the model.
|
|
45
|
+
*/
|
|
46
|
+
onUnrouted?: 'inherit' | 'skip';
|
|
47
|
+
/** Reject results whose stream emits tool-call blocks. Default true. */
|
|
48
|
+
rejectToolCalls?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/** Result of {@link runSideQuery}; every failure shape collapses into `ok: false`. */
|
|
51
|
+
export type SideQueryResult = {
|
|
52
|
+
ok: true;
|
|
53
|
+
text: string;
|
|
54
|
+
inheritedRoute: boolean;
|
|
55
|
+
durationMs: number;
|
|
56
|
+
} | {
|
|
57
|
+
ok: false;
|
|
58
|
+
reason: 'unrouted' | 'timeout' | 'error' | 'empty';
|
|
59
|
+
inheritedRoute?: boolean;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Run one non-streaming side query on the cheap lane (or the inherited parent
|
|
63
|
+
* route). Never throws.
|
|
64
|
+
* @param ctx - the host context (needs `llm` mounted; `ccModelRoutes` optional).
|
|
65
|
+
* @param opts - the side query declaration.
|
|
66
|
+
* @returns the assembled text, or a failure reason.
|
|
67
|
+
*/
|
|
68
|
+
export declare function runSideQuery(ctx: Context, opts: SideQueryOptions): Promise<SideQueryResult>;
|
|
69
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAKnD,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,KAAK,EAAE,KAAK,CAAA;IACZ,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAA;IACd,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,SAAS,GAAG,MAAM,CAAA;IAC/B,wEAAwE;IACxE,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED,sFAAsF;AACtF,MAAM,MAAM,eAAe,GACvB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACvE;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAM/F;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CA+EjG"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First-class auxiliary-LLM primitive: a one-shot, non-streaming, fail-soft
|
|
3
|
+
* side query over a cheap-lane alias route. Library package — no listeners,
|
|
4
|
+
* no preset mount; consumers carry their own registrations.
|
|
5
|
+
*
|
|
6
|
+
* Semantics (design doc §4): never throws; tool-call blocks rejected by
|
|
7
|
+
* default; `AbortSignal.timeout(timeoutMs)` composed with the caller's signal
|
|
8
|
+
* via `AbortSignal.any` and both aborts map to `reason: 'timeout'`;
|
|
9
|
+
* unfillable route → `'unrouted'` (with the `inherit` fallback running on the
|
|
10
|
+
* parent route); empty assembled text → `'empty'`; any other failure →
|
|
11
|
+
* `'error'`.
|
|
12
|
+
*
|
|
13
|
+
* @module @dsh-cc/side-query
|
|
14
|
+
*/
|
|
15
|
+
import { BlockAssembler, createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
16
|
+
import { resolveAlias, toOneShotRoute } from '@dsh-cc/model-aliases';
|
|
17
|
+
const DEFAULT_ALIAS = 'haiku';
|
|
18
|
+
const DEFAULT_MAX_TOKENS = 512;
|
|
19
|
+
const DEFAULT_TIMEOUT_MS = 8000;
|
|
20
|
+
/**
|
|
21
|
+
* Run one non-streaming side query on the cheap lane (or the inherited parent
|
|
22
|
+
* route). Never throws.
|
|
23
|
+
* @param ctx - the host context (needs `llm` mounted; `ccModelRoutes` optional).
|
|
24
|
+
* @param opts - the side query declaration.
|
|
25
|
+
* @returns the assembled text, or a failure reason.
|
|
26
|
+
*/
|
|
27
|
+
export async function runSideQuery(ctx, opts) {
|
|
28
|
+
const start = Date.now();
|
|
29
|
+
try {
|
|
30
|
+
const alias = opts.alias ?? DEFAULT_ALIAS;
|
|
31
|
+
const route = resolveAlias(ctx, alias);
|
|
32
|
+
// The calling agent's logged request header fills the provider half for a
|
|
33
|
+
// string-form (model-only) alias (web-fetch precedent).
|
|
34
|
+
const parent = opts.agent?.session?.requestHeader?.()?.config;
|
|
35
|
+
const filled = toOneShotRoute(route, parent);
|
|
36
|
+
let provider = filled?.provider;
|
|
37
|
+
let model = filled?.model;
|
|
38
|
+
// Builtin alias unconfigured → inherit the parent route (default), unless
|
|
39
|
+
// the caller opts out or no parent route exists to inherit.
|
|
40
|
+
const inherited = filled === undefined;
|
|
41
|
+
if (inherited) {
|
|
42
|
+
if (opts.onUnrouted === 'skip' || parent?.provider === undefined || parent?.model === undefined) {
|
|
43
|
+
return { ok: false, reason: 'unrouted' };
|
|
44
|
+
}
|
|
45
|
+
provider = parent.provider;
|
|
46
|
+
model = parent.model;
|
|
47
|
+
}
|
|
48
|
+
provider = provider ?? '';
|
|
49
|
+
model = model ?? '';
|
|
50
|
+
if (opts.signal?.aborted)
|
|
51
|
+
return { ok: false, reason: 'timeout' };
|
|
52
|
+
const timeoutSignal = AbortSignal.timeout(opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
53
|
+
const signal = opts.signal === undefined
|
|
54
|
+
? timeoutSignal
|
|
55
|
+
: AbortSignal.any([timeoutSignal, opts.signal]);
|
|
56
|
+
const assembler = new BlockAssembler();
|
|
57
|
+
const options = {
|
|
58
|
+
provider,
|
|
59
|
+
model,
|
|
60
|
+
maxTokens: opts.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
61
|
+
...(opts.system === undefined ? {} : { system: opts.system }),
|
|
62
|
+
messages: [createUserMessage({
|
|
63
|
+
content: [{ type: 'text', text: opts.prompt }],
|
|
64
|
+
source: { kind: 'plugin', plugin: 'side-query' },
|
|
65
|
+
})],
|
|
66
|
+
signal,
|
|
67
|
+
};
|
|
68
|
+
const consume = (async () => {
|
|
69
|
+
for await (const chunk of ctx.llm.stream(options)) {
|
|
70
|
+
assembler.push(chunk);
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
73
|
+
// Dangling-stream safety: after a timeout win the dangling consume may
|
|
74
|
+
// still reject; swallow its rejection (the abort path owns the result).
|
|
75
|
+
void consume.catch(() => { });
|
|
76
|
+
const aborted = new Promise((resolve) => {
|
|
77
|
+
if (signal.aborted)
|
|
78
|
+
resolve();
|
|
79
|
+
else
|
|
80
|
+
signal.addEventListener('abort', () => resolve(), { once: true });
|
|
81
|
+
});
|
|
82
|
+
await Promise.race([consume, aborted]);
|
|
83
|
+
if (signal.aborted)
|
|
84
|
+
return { ok: false, reason: 'timeout' };
|
|
85
|
+
// The runtime normalizes an adapter throw into a terminal `finish` chunk
|
|
86
|
+
// with kind 'error'; surface it instead of misreading it as 'empty'.
|
|
87
|
+
if (assembler.finish?.kind === 'error')
|
|
88
|
+
return { ok: false, reason: 'error' };
|
|
89
|
+
// A side query that tries to act is a bug, not a capability (recall-selector
|
|
90
|
+
// rogue-execution lesson); rejectToolCalls defaults true.
|
|
91
|
+
if ((opts.rejectToolCalls ?? true)
|
|
92
|
+
&& (assembler.finish?.kind === 'tool-calls'
|
|
93
|
+
|| assembler.blocks().some(block => block.type === 'tool-call'))) {
|
|
94
|
+
return { ok: false, reason: 'error' };
|
|
95
|
+
}
|
|
96
|
+
const text = assembler.blocks()
|
|
97
|
+
.filter(block => block.type === 'text')
|
|
98
|
+
.map(block => block.text)
|
|
99
|
+
.join(' ')
|
|
100
|
+
.trim();
|
|
101
|
+
if (text.length === 0)
|
|
102
|
+
return { ok: false, reason: 'empty' };
|
|
103
|
+
return { ok: true, text, inheritedRoute: inherited, durationMs: Date.now() - start };
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return { ok: false, reason: 'error' };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAExE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAyCpE,MAAM,aAAa,GAAG,OAAO,CAAA;AAC7B,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAC9B,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAE/B;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAY,EAAE,IAAsB;IACrE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACxB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,aAAa,CAAA;QACzC,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACtC,0EAA0E;QAC1E,wDAAwD;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAE1C,CAAA;QACb,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC5C,IAAI,QAAQ,GAAuB,MAAM,EAAE,QAAQ,CAAA;QACnD,IAAI,KAAK,GAAuB,MAAM,EAAE,KAAK,CAAA;QAC7C,0EAA0E;QAC1E,4DAA4D;QAC5D,MAAM,SAAS,GAAG,MAAM,KAAK,SAAS,CAAA;QACtC,IAAI,SAAS,EAAE,CAAC;YACd,IAA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AC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,EAAE,CAAC;YACrE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;QACvC,CAAC;QACD,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,EAAE;aAC5B,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC;aACtC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAE,KAAwC,CAAC,IAAI,CAAC;aAC5D,IAAI,CAAC,GAAG,CAAC;aACT,IAAI,EAAE,CAAA;QACT,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;QAC5D,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAA;IACtF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;IACvC,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dsh-cc/side-query",
|
|
3
|
+
"description": "First-class auxiliary-LLM primitive: one-shot, non-streaming, fail-soft side query over a cheap-lane alias route with timeout/tool-call rejection/unrouted semantics",
|
|
4
|
+
"version": "0.8.0-rc.1",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/dsh-cc/dsh-cc.git",
|
|
8
|
+
"directory": "packages/llm-tuning/side-query"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./src/*": "./src/*",
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@deepseek-ai/cordis": ">=0.1.5-rc.1",
|
|
25
|
+
"@deepseek-ai/dsh-agent": ">=0.1.5-rc.1",
|
|
26
|
+
"@deepseek-ai/dsh-llm": ">=0.1.5-rc.1",
|
|
27
|
+
"@dsh-cc/model-aliases": "^0.8.0-rc.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
|
|
31
|
+
"@deepseek-ai/dsh-agent": "link:../../../../deepseek-harness/packages/core/agent",
|
|
32
|
+
"@deepseek-ai/dsh-llm": "link:../../../../deepseek-harness/packages/llm/llm",
|
|
33
|
+
"vitest": "^4.1.8",
|
|
34
|
+
"@dsh-cc/model-aliases": "^0.8.0-rc.1"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|