@dsh-edge/dsh-edge-agent 0.0.0-stage → 0.1.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.
Files changed (238) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/LICENSE +21 -0
  3. package/README.md +372 -2
  4. package/config/edge.example.json +179 -0
  5. package/config/privacy-policy.json +202 -0
  6. package/cordis.desktop-safe.patch.yml +129 -0
  7. package/cordis.patch.yml +382 -0
  8. package/cordis.yml +374 -0
  9. package/lib/attestation.d.ts +2 -0
  10. package/lib/attestation.d.ts.map +1 -0
  11. package/lib/attestation.js +2 -0
  12. package/lib/audit-log.d.ts +2 -0
  13. package/lib/audit-log.d.ts.map +1 -0
  14. package/lib/audit-log.js +2 -0
  15. package/lib/client.js +87 -0
  16. package/lib/cloud-llm-adapter.d.ts +2 -0
  17. package/lib/cloud-llm-adapter.d.ts.map +1 -0
  18. package/lib/cloud-llm-adapter.js +2 -0
  19. package/lib/dsh-adapter/attestation.d.ts +42 -0
  20. package/lib/dsh-adapter/attestation.d.ts.map +1 -0
  21. package/lib/dsh-adapter/attestation.js +40 -0
  22. package/lib/dsh-adapter/audit-log.d.ts +139 -0
  23. package/lib/dsh-adapter/audit-log.d.ts.map +1 -0
  24. package/lib/dsh-adapter/audit-log.js +376 -0
  25. package/lib/dsh-adapter/cloud-egress.d.ts +181 -0
  26. package/lib/dsh-adapter/cloud-egress.d.ts.map +1 -0
  27. package/lib/dsh-adapter/cloud-egress.js +257 -0
  28. package/lib/dsh-adapter/cloud-llm-adapter.d.ts +416 -0
  29. package/lib/dsh-adapter/cloud-llm-adapter.d.ts.map +1 -0
  30. package/lib/dsh-adapter/cloud-llm-adapter.js +1472 -0
  31. package/lib/dsh-adapter/contract.d.ts +80 -0
  32. package/lib/dsh-adapter/contract.d.ts.map +1 -0
  33. package/lib/dsh-adapter/contract.js +194 -0
  34. package/lib/dsh-adapter/desktop-cookie-janitor.d.ts +214 -0
  35. package/lib/dsh-adapter/desktop-cookie-janitor.d.ts.map +1 -0
  36. package/lib/dsh-adapter/desktop-cookie-janitor.js +409 -0
  37. package/lib/dsh-adapter/dsh-edge-agent.d.ts +48 -0
  38. package/lib/dsh-adapter/dsh-edge-agent.d.ts.map +1 -0
  39. package/lib/dsh-adapter/dsh-edge-agent.js +64 -0
  40. package/lib/dsh-adapter/edge-config.d.ts +484 -0
  41. package/lib/dsh-adapter/edge-config.d.ts.map +1 -0
  42. package/lib/dsh-adapter/edge-config.js +898 -0
  43. package/lib/dsh-adapter/edge-context-view.d.ts +184 -0
  44. package/lib/dsh-adapter/edge-context-view.d.ts.map +1 -0
  45. package/lib/dsh-adapter/edge-context-view.js +483 -0
  46. package/lib/dsh-adapter/effective-model.d.ts +85 -0
  47. package/lib/dsh-adapter/effective-model.d.ts.map +1 -0
  48. package/lib/dsh-adapter/effective-model.js +171 -0
  49. package/lib/dsh-adapter/etscli-shell-guard.d.ts +244 -0
  50. package/lib/dsh-adapter/etscli-shell-guard.d.ts.map +1 -0
  51. package/lib/dsh-adapter/etscli-shell-guard.js +420 -0
  52. package/lib/dsh-adapter/etscli-tools.d.ts +112 -0
  53. package/lib/dsh-adapter/etscli-tools.d.ts.map +1 -0
  54. package/lib/dsh-adapter/etscli-tools.js +393 -0
  55. package/lib/dsh-adapter/file-logger.d.ts +294 -0
  56. package/lib/dsh-adapter/file-logger.d.ts.map +1 -0
  57. package/lib/dsh-adapter/file-logger.js +564 -0
  58. package/lib/dsh-adapter/function-call-external.d.ts +357 -0
  59. package/lib/dsh-adapter/function-call-external.d.ts.map +1 -0
  60. package/lib/dsh-adapter/function-call-external.js +1005 -0
  61. package/lib/dsh-adapter/host-egress-guard.d.ts +161 -0
  62. package/lib/dsh-adapter/host-egress-guard.d.ts.map +1 -0
  63. package/lib/dsh-adapter/host-egress-guard.js +213 -0
  64. package/lib/dsh-adapter/host-llm-trace.d.ts +198 -0
  65. package/lib/dsh-adapter/host-llm-trace.d.ts.map +1 -0
  66. package/lib/dsh-adapter/host-llm-trace.js +344 -0
  67. package/lib/dsh-adapter/http-api-routes.d.ts +61 -0
  68. package/lib/dsh-adapter/http-api-routes.d.ts.map +1 -0
  69. package/lib/dsh-adapter/http-api-routes.js +79 -0
  70. package/lib/dsh-adapter/http-api-sessions.d.ts +105 -0
  71. package/lib/dsh-adapter/http-api-sessions.d.ts.map +1 -0
  72. package/lib/dsh-adapter/http-api-sessions.js +173 -0
  73. package/lib/dsh-adapter/http-api.d.ts +221 -0
  74. package/lib/dsh-adapter/http-api.d.ts.map +1 -0
  75. package/lib/dsh-adapter/http-api.js +1811 -0
  76. package/lib/dsh-adapter/index.d.ts +62 -0
  77. package/lib/dsh-adapter/index.d.ts.map +1 -0
  78. package/lib/dsh-adapter/index.js +97 -0
  79. package/lib/dsh-adapter/input-guard-messages.d.ts +56 -0
  80. package/lib/dsh-adapter/input-guard-messages.d.ts.map +1 -0
  81. package/lib/dsh-adapter/input-guard-messages.js +136 -0
  82. package/lib/dsh-adapter/input-guard.d.ts +508 -0
  83. package/lib/dsh-adapter/input-guard.d.ts.map +1 -0
  84. package/lib/dsh-adapter/input-guard.js +2174 -0
  85. package/lib/dsh-adapter/intent-prompts.d.ts +77 -0
  86. package/lib/dsh-adapter/intent-prompts.d.ts.map +1 -0
  87. package/lib/dsh-adapter/intent-prompts.js +97 -0
  88. package/lib/dsh-adapter/intent-router.d.ts +710 -0
  89. package/lib/dsh-adapter/intent-router.d.ts.map +1 -0
  90. package/lib/dsh-adapter/intent-router.js +2802 -0
  91. package/lib/dsh-adapter/intent-signals.d.ts +208 -0
  92. package/lib/dsh-adapter/intent-signals.d.ts.map +1 -0
  93. package/lib/dsh-adapter/intent-signals.js +391 -0
  94. package/lib/dsh-adapter/invariant-install.d.ts +16 -0
  95. package/lib/dsh-adapter/invariant-install.d.ts.map +1 -0
  96. package/lib/dsh-adapter/invariant-install.js +15 -0
  97. package/lib/dsh-adapter/invariant.d.ts +16 -0
  98. package/lib/dsh-adapter/invariant.d.ts.map +1 -0
  99. package/lib/dsh-adapter/invariant.js +22 -0
  100. package/lib/dsh-adapter/llm-adapters.d.ts +19 -0
  101. package/lib/dsh-adapter/llm-adapters.d.ts.map +1 -0
  102. package/lib/dsh-adapter/llm-adapters.js +16 -0
  103. package/lib/dsh-adapter/llm-internal-caller.d.ts +92 -0
  104. package/lib/dsh-adapter/llm-internal-caller.d.ts.map +1 -0
  105. package/lib/dsh-adapter/llm-internal-caller.js +100 -0
  106. package/lib/dsh-adapter/llm-max-turns.d.ts +55 -0
  107. package/lib/dsh-adapter/llm-max-turns.d.ts.map +1 -0
  108. package/lib/dsh-adapter/llm-max-turns.js +127 -0
  109. package/lib/dsh-adapter/llm-trace-store.d.ts +131 -0
  110. package/lib/dsh-adapter/llm-trace-store.d.ts.map +1 -0
  111. package/lib/dsh-adapter/llm-trace-store.js +205 -0
  112. package/lib/dsh-adapter/llm-trace.d.ts +450 -0
  113. package/lib/dsh-adapter/llm-trace.d.ts.map +1 -0
  114. package/lib/dsh-adapter/llm-trace.js +463 -0
  115. package/lib/dsh-adapter/local-llm-adapter.d.ts +141 -0
  116. package/lib/dsh-adapter/local-llm-adapter.d.ts.map +1 -0
  117. package/lib/dsh-adapter/local-llm-adapter.js +787 -0
  118. package/lib/dsh-adapter/local-storage.d.ts +96 -0
  119. package/lib/dsh-adapter/local-storage.d.ts.map +1 -0
  120. package/lib/dsh-adapter/local-storage.js +198 -0
  121. package/lib/dsh-adapter/model-router.d.ts +79 -0
  122. package/lib/dsh-adapter/model-router.d.ts.map +1 -0
  123. package/lib/dsh-adapter/model-router.js +107 -0
  124. package/lib/dsh-adapter/ohttp-gateway.d.ts +49 -0
  125. package/lib/dsh-adapter/ohttp-gateway.d.ts.map +1 -0
  126. package/lib/dsh-adapter/ohttp-gateway.js +32 -0
  127. package/lib/dsh-adapter/openai-sse.d.ts +85 -0
  128. package/lib/dsh-adapter/openai-sse.d.ts.map +1 -0
  129. package/lib/dsh-adapter/openai-sse.js +462 -0
  130. package/lib/dsh-adapter/pii-utils.d.ts +96 -0
  131. package/lib/dsh-adapter/pii-utils.d.ts.map +1 -0
  132. package/lib/dsh-adapter/pii-utils.js +324 -0
  133. package/lib/dsh-adapter/plugin-host.d.ts +38 -0
  134. package/lib/dsh-adapter/plugin-host.d.ts.map +1 -0
  135. package/lib/dsh-adapter/plugin-host.js +38 -0
  136. package/lib/dsh-adapter/plugin.d.ts +46 -0
  137. package/lib/dsh-adapter/plugin.d.ts.map +1 -0
  138. package/lib/dsh-adapter/plugin.js +100 -0
  139. package/lib/dsh-adapter/privacy-policy.d.ts +237 -0
  140. package/lib/dsh-adapter/privacy-policy.d.ts.map +1 -0
  141. package/lib/dsh-adapter/privacy-policy.js +391 -0
  142. package/lib/dsh-adapter/prompt-guard.d.ts +152 -0
  143. package/lib/dsh-adapter/prompt-guard.d.ts.map +1 -0
  144. package/lib/dsh-adapter/prompt-guard.js +872 -0
  145. package/lib/dsh-adapter/realm-skill-bridge.d.ts +365 -0
  146. package/lib/dsh-adapter/realm-skill-bridge.d.ts.map +1 -0
  147. package/lib/dsh-adapter/realm-skill-bridge.js +1180 -0
  148. package/lib/dsh-adapter/sanitizer-pipeline.d.ts +140 -0
  149. package/lib/dsh-adapter/sanitizer-pipeline.d.ts.map +1 -0
  150. package/lib/dsh-adapter/sanitizer-pipeline.js +431 -0
  151. package/lib/dsh-adapter/secure-bridge.d.ts +47 -0
  152. package/lib/dsh-adapter/secure-bridge.d.ts.map +1 -0
  153. package/lib/dsh-adapter/secure-bridge.js +35 -0
  154. package/lib/dsh-adapter/session-attribution.d.ts +70 -0
  155. package/lib/dsh-adapter/session-attribution.d.ts.map +1 -0
  156. package/lib/dsh-adapter/session-attribution.js +76 -0
  157. package/lib/dsh-adapter/sessions.d.ts +86 -0
  158. package/lib/dsh-adapter/sessions.d.ts.map +1 -0
  159. package/lib/dsh-adapter/sessions.js +179 -0
  160. package/lib/dsh-adapter/tcm.d.ts +55 -0
  161. package/lib/dsh-adapter/tcm.d.ts.map +1 -0
  162. package/lib/dsh-adapter/tcm.js +94 -0
  163. package/lib/dsh-adapter/td-bus.d.ts +87 -0
  164. package/lib/dsh-adapter/td-bus.d.ts.map +1 -0
  165. package/lib/dsh-adapter/td-bus.js +196 -0
  166. package/lib/dsh-adapter/tool-runner.d.ts +185 -0
  167. package/lib/dsh-adapter/tool-runner.d.ts.map +1 -0
  168. package/lib/dsh-adapter/tool-runner.js +271 -0
  169. package/lib/dsh-adapter/tools.d.ts +118 -0
  170. package/lib/dsh-adapter/tools.d.ts.map +1 -0
  171. package/lib/dsh-adapter/tools.js +292 -0
  172. package/lib/dsh-adapter/types.d.ts +23 -0
  173. package/lib/dsh-adapter/types.d.ts.map +1 -0
  174. package/lib/dsh-adapter/types.js +16 -0
  175. package/lib/dsh-adapter/voice-input.d.ts +30 -0
  176. package/lib/dsh-adapter/voice-input.d.ts.map +1 -0
  177. package/lib/dsh-adapter/voice-input.js +34 -0
  178. package/lib/dsh-adapter/web-search-tavily-bocha.d.ts +152 -0
  179. package/lib/dsh-adapter/web-search-tavily-bocha.d.ts.map +1 -0
  180. package/lib/dsh-adapter/web-search-tavily-bocha.js +289 -0
  181. package/lib/http-api.d.ts +2 -0
  182. package/lib/http-api.d.ts.map +1 -0
  183. package/lib/http-api.js +2 -0
  184. package/lib/index.d.ts +48 -0
  185. package/lib/index.d.ts.map +1 -0
  186. package/lib/index.js +49 -0
  187. package/lib/intent-router.d.ts +2 -0
  188. package/lib/intent-router.d.ts.map +1 -0
  189. package/lib/intent-router.js +2 -0
  190. package/lib/llm-adapters.d.ts +2 -0
  191. package/lib/llm-adapters.d.ts.map +1 -0
  192. package/lib/llm-adapters.js +2 -0
  193. package/lib/local-llm-adapter.d.ts +2 -0
  194. package/lib/local-llm-adapter.d.ts.map +1 -0
  195. package/lib/local-llm-adapter.js +2 -0
  196. package/lib/local-storage.d.ts +2 -0
  197. package/lib/local-storage.d.ts.map +1 -0
  198. package/lib/local-storage.js +2 -0
  199. package/lib/model-router.d.ts +2 -0
  200. package/lib/model-router.d.ts.map +1 -0
  201. package/lib/model-router.js +2 -0
  202. package/lib/ohttp-gateway.d.ts +2 -0
  203. package/lib/ohttp-gateway.d.ts.map +1 -0
  204. package/lib/ohttp-gateway.js +2 -0
  205. package/lib/plugin-host.d.ts +2 -0
  206. package/lib/plugin-host.d.ts.map +1 -0
  207. package/lib/plugin-host.js +2 -0
  208. package/lib/privacy-policy.d.ts +2 -0
  209. package/lib/privacy-policy.d.ts.map +1 -0
  210. package/lib/privacy-policy.js +2 -0
  211. package/lib/prompt-guard.d.ts +2 -0
  212. package/lib/prompt-guard.d.ts.map +1 -0
  213. package/lib/prompt-guard.js +2 -0
  214. package/lib/sanitizer-pipeline.d.ts +2 -0
  215. package/lib/sanitizer-pipeline.d.ts.map +1 -0
  216. package/lib/sanitizer-pipeline.js +2 -0
  217. package/lib/secure-bridge.d.ts +2 -0
  218. package/lib/secure-bridge.d.ts.map +1 -0
  219. package/lib/secure-bridge.js +2 -0
  220. package/lib/sessions.d.ts +2 -0
  221. package/lib/sessions.d.ts.map +1 -0
  222. package/lib/sessions.js +2 -0
  223. package/lib/tcm.d.ts +2 -0
  224. package/lib/tcm.d.ts.map +1 -0
  225. package/lib/tcm.js +2 -0
  226. package/lib/td-bus.d.ts +2 -0
  227. package/lib/td-bus.d.ts.map +1 -0
  228. package/lib/td-bus.js +2 -0
  229. package/lib/tools.d.ts +2 -0
  230. package/lib/tools.d.ts.map +1 -0
  231. package/lib/tools.js +2 -0
  232. package/lib/voice-input.d.ts +2 -0
  233. package/lib/voice-input.d.ts.map +1 -0
  234. package/lib/voice-input.js +2 -0
  235. package/package.json +341 -3
  236. package/presets/agent-preset-edge.json +50 -0
  237. package/presets/edge.desktop-safe.patch.yml +503 -0
  238. package/presets/edge.patch.yml +557 -0
@@ -0,0 +1,77 @@
1
+ /**
2
+ * intent-prompts — the PROMPT TEMPLATES for the intent router.
3
+ *
4
+ * §7.123 (2026-10-27): these templates lived inline in `intent-router.ts`
5
+ * (2923 lines). They are pure string construction over the operator's
6
+ * taxonomy, so they belong with the strategy data (see `./intent-signals.ts`),
7
+ * not with the classifier machinery. Keeping them here makes the two prompt
8
+ * surfaces — the local LLM classifier and the Bailian decision-model —
9
+ * reviewable side by side, which matters because they MUST agree (the LOCAL
10
+ * catch-all wording is deliberately verbatim-identical in both).
11
+ *
12
+ * @module dsh-edge-agent/intent-prompts
13
+ */
14
+ import type { IntentCategory } from './privacy-policy.js';
15
+ import { LOCAL_CATCHALL_DESCRIPTION } from './intent-signals.js';
16
+ export { LOCAL_CATCHALL_DESCRIPTION };
17
+ /** The instruction shown above the category list in the LLM classifier. */
18
+ export declare const CLASSIFIER_HEADER = "\u5224\u65AD\u4EE5\u4E0B\u7528\u6237\u8BF7\u6C42\u5C5E\u4E8E\u54EA\u7C7B\uFF1A";
19
+ /**
20
+ * Confidence calibration legend.
21
+ *
22
+ * 2026-08-25: qwen3-4b tends to always output 0.98-0.99 regardless of
23
+ * actual certainty, making the 0.6 gate ineffective. The explicit legend
24
+ * teaches the model to differentiate clear vs ambiguous requests.
25
+ */
26
+ export declare const CONFIDENCE_LEGEND = "confidence \u542B\u4E49\uFF1A\n- 1.0 = \u975E\u5E38\u786E\u5B9A\uFF08\u8BF7\u6C42\u660E\u786E\u5C5E\u4E8E\u8BE5\u7C7B\u522B\uFF0C\u65E0\u6B67\u4E49\uFF09\n- 0.7 = \u8F83\u786E\u5B9A\uFF08\u8BF7\u6C42\u5927\u6982\u7387\u5C5E\u4E8E\u8BE5\u7C7B\u522B\uFF0C\u4F46\u6709\u5C11\u8BB8\u6A21\u7CCA\uFF09\n- 0.5 = \u4E0D\u786E\u5B9A\uFF08\u8BF7\u6C42\u6A21\u7CCA\uFF0C\u53EF\u80FD\u662F LOCAL \u4E5F\u53EF\u80FD\u662F CLOUD\uFF09\n- <0.5 = \u5B8C\u5168\u4E0D\u786E\u5B9A\uFF08\u65E0\u6CD5\u5224\u65AD\u7C7B\u522B\uFF09";
27
+ /** The Bailian decision-model's intent question instructions. */
28
+ export declare const JEV_INTENT_INSTRUCTIONS = "\u8FD9\u4E2A\u7528\u6237\u8BF7\u6C42\u5E94\u8BE5\u8DEF\u7531\u5230\u54EA\u4E2A\u5904\u7406\u57DF\uFF1F\u53EA\u9009\u4E00\u4E2A\u6700\u5408\u9002\u7684\u3002";
29
+ /** The Bailian decision-model's risk question instructions. */
30
+ export declare const JEV_RISK_INSTRUCTIONS = "\u8FD9\u4E2A\u8BF7\u6C42\u7684\u5371\u9669\u7A0B\u5EA6\u5982\u4F55\uFF1F";
31
+ /** The 4 danger levels the decision-model scores against (score/3 → 0..1). */
32
+ export declare const JEV_RISK_CRITERIA: readonly string[];
33
+ export interface ClassificationPromptInput {
34
+ /** The operator's taxonomy (from the privacy policy, hot-reloadable). */
35
+ categories: readonly IntentCategory[];
36
+ /** Pre-rendered recent-conversation block ('' when there is no history). */
37
+ historyBlock: string;
38
+ /** The user request to classify (already truncated to `maxInput`). */
39
+ promptText: string;
40
+ }
41
+ export interface ClassificationPrompt {
42
+ /** The full prompt handed to the local classifier model. */
43
+ prompt: string;
44
+ /** The category union the model may answer with, e.g. `LOCAL|CLOUD`. */
45
+ categoryUnion: string;
46
+ /** The rendered category lines (debug / audit visibility). */
47
+ categoryLines: string;
48
+ }
49
+ /**
50
+ * Build the local-LLM classifier prompt.
51
+ *
52
+ * §7.92.3 (2026-09-23): the category list is built from the policy's
53
+ * `categories[]` (hot-reloadable) — the LLM sees ALL of LOCAL/CLOUD/
54
+ * SANITIZED/REJECT, giving it a path to surface SANITIZED/REJECT verdicts
55
+ * without a separate rules pass. Order matches the policy file so
56
+ * operators control priority by reordering rows.
57
+ *
58
+ * §7.110 (2026-10-24): 默认本地 — the operator's taxonomy only needs to
59
+ * POSITIVELY define the exceptions (CLOUD / REJECT); LOCAL is the catch-all
60
+ * default and may ship no row at all. When the policy has no LOCAL row, a
61
+ * fixed catch-all line is appended and LOCAL is included in the output
62
+ * union so the model can express "neither of the above".
63
+ */
64
+ export declare function buildClassificationPrompt(input: ClassificationPromptInput): ClassificationPrompt;
65
+ /**
66
+ * Build the Bailian decision-model's intent criteria.
67
+ *
68
+ * §7.110 alignment (§7.115.1 fix): after the taxonomy was simplified to
69
+ * "default LOCAL", a policy without a LOCAL row would leave the
70
+ * decision-model choosing between CLOUD/REJECT only — pushing everyday
71
+ * questions into CLOUD (and, at ≥ the semantic threshold, out to the
72
+ * network). The LOCAL catch-all must therefore be present here too, with
73
+ * wording VERBATIM identical to the LLM prompt's catch-all line so the two
74
+ * backends cannot drift.
75
+ */
76
+ export declare function buildJevIntentCriteria(categories: readonly IntentCategory[]): Record<string, string>;
77
+ //# sourceMappingURL=intent-prompts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent-prompts.d.ts","sourceRoot":"","sources":["../../src/dsh-adapter/intent-prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAA;AAKhE,OAAO,EAAE,0BAA0B,EAAE,CAAA;AAErC,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,mFAAkB,CAAA;AAEhD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,kgBAIP,CAAA;AAEvB,iEAAiE;AACjE,eAAO,MAAM,uBAAuB,iKACN,CAAA;AAE9B,+DAA+D;AAC/D,eAAO,MAAM,qBAAqB,6EAAiB,CAAA;AAEnD,8EAA8E;AAC9E,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAK9C,CAAA;AAED,MAAM,WAAW,yBAAyB;IACxC,yEAAyE;IACzE,UAAU,EAAE,SAAS,cAAc,EAAE,CAAA;IACrC,4EAA4E;IAC5E,YAAY,EAAE,MAAM,CAAA;IACpB,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAA;IACd,wEAAwE;IACxE,aAAa,EAAE,MAAM,CAAA;IACrB,8DAA8D;IAC9D,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,yBAAyB,GAAG,oBAAoB,CAoBhG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,SAAS,cAAc,EAAE,GACpC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * intent-prompts — the PROMPT TEMPLATES for the intent router.
3
+ *
4
+ * §7.123 (2026-10-27): these templates lived inline in `intent-router.ts`
5
+ * (2923 lines). They are pure string construction over the operator's
6
+ * taxonomy, so they belong with the strategy data (see `./intent-signals.ts`),
7
+ * not with the classifier machinery. Keeping them here makes the two prompt
8
+ * surfaces — the local LLM classifier and the Bailian decision-model —
9
+ * reviewable side by side, which matters because they MUST agree (the LOCAL
10
+ * catch-all wording is deliberately verbatim-identical in both).
11
+ *
12
+ * @module dsh-edge-agent/intent-prompts
13
+ */
14
+ import { LOCAL_CATCHALL_DESCRIPTION } from './intent-signals.js';
15
+ // Re-exported: the catch-all wording is part of this module's public
16
+ // contract — the two prompt surfaces must use it verbatim, and a test that
17
+ // pins "both surfaces agree" needs to name it.
18
+ export { LOCAL_CATCHALL_DESCRIPTION };
19
+ /** The instruction shown above the category list in the LLM classifier. */
20
+ export const CLASSIFIER_HEADER = '判断以下用户请求属于哪类:';
21
+ /**
22
+ * Confidence calibration legend.
23
+ *
24
+ * 2026-08-25: qwen3-4b tends to always output 0.98-0.99 regardless of
25
+ * actual certainty, making the 0.6 gate ineffective. The explicit legend
26
+ * teaches the model to differentiate clear vs ambiguous requests.
27
+ */
28
+ export const CONFIDENCE_LEGEND = `confidence 含义:
29
+ - 1.0 = 非常确定(请求明确属于该类别,无歧义)
30
+ - 0.7 = 较确定(请求大概率属于该类别,但有少许模糊)
31
+ - 0.5 = 不确定(请求模糊,可能是 LOCAL 也可能是 CLOUD)
32
+ - <0.5 = 完全不确定(无法判断类别)`;
33
+ /** The Bailian decision-model's intent question instructions. */
34
+ export const JEV_INTENT_INSTRUCTIONS = '这个用户请求应该路由到哪个处理域?只选一个最合适的。';
35
+ /** The Bailian decision-model's risk question instructions. */
36
+ export const JEV_RISK_INSTRUCTIONS = '这个请求的危险程度如何?';
37
+ /** The 4 danger levels the decision-model scores against (score/3 → 0..1). */
38
+ export const JEV_RISK_CRITERIA = [
39
+ '正常请求,无风险',
40
+ '轻微可疑,需要留意',
41
+ '明显危险操作',
42
+ '高危/违法/破坏性请求',
43
+ ];
44
+ /**
45
+ * Build the local-LLM classifier prompt.
46
+ *
47
+ * §7.92.3 (2026-09-23): the category list is built from the policy's
48
+ * `categories[]` (hot-reloadable) — the LLM sees ALL of LOCAL/CLOUD/
49
+ * SANITIZED/REJECT, giving it a path to surface SANITIZED/REJECT verdicts
50
+ * without a separate rules pass. Order matches the policy file so
51
+ * operators control priority by reordering rows.
52
+ *
53
+ * §7.110 (2026-10-24): 默认本地 — the operator's taxonomy only needs to
54
+ * POSITIVELY define the exceptions (CLOUD / REJECT); LOCAL is the catch-all
55
+ * default and may ship no row at all. When the policy has no LOCAL row, a
56
+ * fixed catch-all line is appended and LOCAL is included in the output
57
+ * union so the model can express "neither of the above".
58
+ */
59
+ export function buildClassificationPrompt(input) {
60
+ const hasLocalRow = input.categories.some((c) => c.id === 'LOCAL');
61
+ const categoryLines = input.categories.map((c) => `- ${c.id}:${c.description}`).join('\n')
62
+ + (hasLocalRow ? '' : `\n- LOCAL:${LOCAL_CATCHALL_DESCRIPTION}`);
63
+ const categoryUnion = Array.from(new Set([
64
+ ...input.categories.map((c) => c.id),
65
+ 'LOCAL',
66
+ ])).join('|');
67
+ const prompt = `${CLASSIFIER_HEADER}
68
+ ${categoryLines}
69
+ ${input.historyBlock}
70
+ Respond ONLY with a single JSON object — no prose, no Markdown:
71
+ { "category": ${categoryUnion}, "confidence": <0.0-1.0> }
72
+
73
+ ${CONFIDENCE_LEGEND}
74
+
75
+ 用户请求:${input.promptText}`;
76
+ return { prompt, categoryUnion, categoryLines };
77
+ }
78
+ /**
79
+ * Build the Bailian decision-model's intent criteria.
80
+ *
81
+ * §7.110 alignment (§7.115.1 fix): after the taxonomy was simplified to
82
+ * "default LOCAL", a policy without a LOCAL row would leave the
83
+ * decision-model choosing between CLOUD/REJECT only — pushing everyday
84
+ * questions into CLOUD (and, at ≥ the semantic threshold, out to the
85
+ * network). The LOCAL catch-all must therefore be present here too, with
86
+ * wording VERBATIM identical to the LLM prompt's catch-all line so the two
87
+ * backends cannot drift.
88
+ */
89
+ export function buildJevIntentCriteria(categories) {
90
+ const criteria = {};
91
+ for (const cat of categories)
92
+ criteria[cat.id] = cat.description;
93
+ if (!categories.some((c) => c.id === 'LOCAL')) {
94
+ criteria.LOCAL = LOCAL_CATCHALL_DESCRIPTION;
95
+ }
96
+ return criteria;
97
+ }