@sema-agent/client-core 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +31 -11
  2. package/dist/adapt.d.ts +4 -2
  3. package/dist/adapt.js +225 -25
  4. package/dist/compensations.d.ts +63 -0
  5. package/dist/compensations.js +138 -0
  6. package/dist/detachWire.d.ts +141 -0
  7. package/dist/detachWire.js +182 -0
  8. package/dist/diff/patch.d.ts +29 -0
  9. package/dist/diff/patch.js +45 -0
  10. package/dist/engineSessionParam.d.ts +11 -0
  11. package/dist/engineSessionParam.js +41 -0
  12. package/dist/engineWireTarget.d.ts +14 -0
  13. package/dist/engineWireTarget.js +53 -0
  14. package/dist/finalVerifyWire.d.ts +74 -0
  15. package/dist/finalVerifyWire.js +63 -0
  16. package/dist/fleet/fleetLedger.d.ts +132 -0
  17. package/dist/fleet/fleetLedger.js +393 -0
  18. package/dist/fleet/fleetProjection.d.ts +181 -0
  19. package/dist/fleet/fleetProjection.js +258 -0
  20. package/dist/headlessPermissionModeWire.d.ts +55 -0
  21. package/dist/headlessPermissionModeWire.js +111 -0
  22. package/dist/headlessReconnectWire.d.ts +96 -0
  23. package/dist/headlessReconnectWire.js +141 -0
  24. package/dist/hooksWireCaps.d.ts +91 -0
  25. package/dist/hooksWireCaps.js +359 -0
  26. package/dist/host.d.ts +34 -2
  27. package/dist/host.js +6 -0
  28. package/dist/index.d.ts +74 -1
  29. package/dist/index.js +104 -1
  30. package/dist/interactiveToolsWire.d.ts +48 -0
  31. package/dist/interactiveToolsWire.js +86 -0
  32. package/dist/limitsWire.d.ts +89 -0
  33. package/dist/limitsWire.js +225 -0
  34. package/dist/liveInitToolFace.d.ts +53 -0
  35. package/dist/liveInitToolFace.js +251 -0
  36. package/dist/model/modelFamilies.json +63 -0
  37. package/dist/model/providerPresets.d.ts +46 -0
  38. package/dist/model/providerPresets.js +160 -0
  39. package/dist/model/providerPresets.json +1179 -0
  40. package/dist/notifications.d.ts +7 -0
  41. package/dist/notifications.js +32 -0
  42. package/dist/sandboxWire.d.ts +75 -0
  43. package/dist/sandboxWire.js +138 -0
  44. package/dist/scenarioWire.d.ts +62 -0
  45. package/dist/scenarioWire.js +115 -0
  46. package/dist/seam.d.ts +52 -5
  47. package/dist/seam.js +15 -2
  48. package/dist/subagent/engineCompactWire.d.ts +12 -0
  49. package/dist/subagent/engineCompactWire.js +176 -0
  50. package/dist/subagent/engineDelegatedPrompt.d.ts +44 -0
  51. package/dist/subagent/engineDelegatedPrompt.js +205 -0
  52. package/dist/subagent/engineRowStopGate.d.ts +18 -0
  53. package/dist/subagent/engineRowStopGate.js +54 -0
  54. package/dist/subagent/engineSubagentOutput.d.ts +15 -0
  55. package/dist/subagent/engineSubagentOutput.js +98 -0
  56. package/dist/subagent/engineSubagentSteer.d.ts +10 -0
  57. package/dist/subagent/engineSubagentSteer.js +68 -0
  58. package/dist/subagent/engineSubagentTail.d.ts +40 -0
  59. package/dist/subagent/engineSubagentTail.js +241 -0
  60. package/dist/subagent/engineTaskHandleWire.d.ts +90 -0
  61. package/dist/subagent/engineTaskHandleWire.js +212 -0
  62. package/dist/toolResult.d.ts +118 -0
  63. package/dist/toolResult.js +774 -0
  64. package/dist/workflowClient.d.ts +42 -0
  65. package/dist/workflowClient.js +467 -0
  66. package/dist/workflowMonitor.d.ts +94 -0
  67. package/dist/workflowMonitor.js +43 -0
  68. package/package.json +5 -3
@@ -0,0 +1,160 @@
1
+ /**
2
+ * ⇄ B6 批搬迁(2026-07-27,设计稿 §3 B6 · B4「四残件」之 model 数据表):cli
3
+ * `src/sema/onboard/providerPresets.{ts,json}` + `modelFamilies.json` 整搬(零依赖、纯查表)。
4
+ *
5
+ * 🔴 **为什么数据表必须进包**:`modelBudgetRule.defaultMaxTokensFor()`(B2 已搬)的封顶① 参数
6
+ * `perModelCap` 只有一个来源 —— `inferFamily()` 第①层精确命中。表留在壳里 ⇒ 库里那条中央规则
7
+ * 在 web/桌面上**永远拿不到 cap**,`defaultMaxTokensFor(ctx)` 恒走 min(base, ctx/4),
8
+ * 对 deepseek-chat(cap 8192)这类模型直接超发 ⇒ 网关 400。这不是「少个装饰」。
9
+ *
10
+ * 🔴 **两份副本的漂移锁**:搬迁期壳树那两个 JSON 还在(壳侧 shim 批之前 onboard 全族在读它),
11
+ * 所以 pure 门加了一条 **byte-identity 断言**:本包 `src/model/*.json` 与壳树
12
+ * `src/sema/onboard/*.json` 必须**逐字节相等**,任一侧加一行 provider 而另一侧没加即当场红。
13
+ * 壳侧 shim 落地(那两个 JSON 删除、providerPresets.ts 改 re-export 本包)之后,该断言
14
+ * 自动降为 SKIP(壳树缺席 = 搬完了),不会变成陈旧的假红。
15
+ *
16
+ * ── 以下为原文件的领域说明(逐字保留)────────────────────────────────────────────────────────
17
+ *
18
+ * providerPresets.ts — typed accessors over the static preset data tables for
19
+ * `sema onboard` (GUIDE-ONBOARD-DESIGN §3a/§3b, clay 拍板 2026-07-03).
20
+ *
21
+ * DATA lives in the sibling JSON files (providerPresets.json /
22
+ * modelFamilies.json) — adding a provider or family is a table row, no code
23
+ * change (维护性原则: new source = one module + one table row). Shapes align
24
+ * with openclaw's plugin-manifest `modelCatalog.providers` / CenterModel so
25
+ * translators stay ~free, but centralized (sema has no plugin system).
26
+ *
27
+ * All numbers are best-effort defaults (待核 official docs); qwen/glm values
28
+ * were read from clay's real ~/.openclaw catalog.
29
+ */
30
+ import presetData from './providerPresets.json' with { type: 'json' };
31
+ import familyData from './modelFamilies.json' with { type: 'json' };
32
+ export const PROVIDER_PRESETS = presetData.presets;
33
+ export const MODEL_FAMILIES = familyData.families;
34
+ // ── 模型自动匹配 v2(clay 07-06:预填要"较为准确的推荐",真实测例驱动,verify/_infer-family-test)──
35
+ // 四层:①preset 大表精确命中(46 provider 的真实 models,最强证据)②容量后缀/名内提示([1m]、-128k)
36
+ // ③家族主干匹配(部署前缀/参数量/量化后缀容忍)④family 表前缀兜底。
37
+ /** 尾部变体词(主干提取时剥):不承载 ctx 信息的营销/角色/量化/参数量后缀。 */
38
+ const VARIANT_TAIL = /(-(plus|pro|max|flash|turbo|mini|lite|chat|coder?|code|instruct|thinking|reasoner|next|preview|latest|fp8|fp16|awq|int[48]|gptq|\d+b))+$/;
39
+ let presetIndexCache = null;
40
+ function presetIndex() {
41
+ if (presetIndexCache)
42
+ return presetIndexCache;
43
+ const exact = new Map();
44
+ const stems = [];
45
+ for (const p of PROVIDER_PRESETS) {
46
+ for (const m of p.models ?? []) {
47
+ if (!m?.id || !m.contextWindow)
48
+ continue;
49
+ const hit = {
50
+ id: m.id.toLowerCase(),
51
+ contextWindow: m.contextWindow,
52
+ maxTokens: m.maxTokens ?? 32768,
53
+ famId: p.id,
54
+ };
55
+ if (!exact.has(hit.id))
56
+ exact.set(hit.id, hit);
57
+ stems.push(hit);
58
+ }
59
+ }
60
+ presetIndexCache = { exact, stems };
61
+ return presetIndexCache;
62
+ }
63
+ function normalizeId(raw) {
64
+ let id = raw.trim().toLowerCase();
65
+ const slash = id.lastIndexOf('/');
66
+ if (slash >= 0)
67
+ id = id.slice(slash + 1); // org/model → model
68
+ id = id.replace(/\[[0-9]+[km]\]$/, ''); // [1m] 容量后缀在第②层单独消费
69
+ return id;
70
+ }
71
+ /** Infer context/max from a model id — four evidence tiers, strongest first. */
72
+ export function inferFamily(modelId) {
73
+ const raw = modelId.trim().toLowerCase();
74
+ if (!raw)
75
+ return undefined;
76
+ const idx = presetIndex();
77
+ // ② 前置:显式容量标注恒赢([1m]/[200k] CC 惯例后缀)——用户/工具已声明,别猜。
78
+ const capSuffix = raw.match(/\[(\d+)([km])\]$/);
79
+ if (capSuffix) {
80
+ const n = Number(capSuffix[1]);
81
+ const ctx = capSuffix[2] === 'm' ? n * 1000000 : n * 1024;
82
+ const base = inferFamily(raw.replace(/\[[0-9]+[km]\]$/, ''));
83
+ // perModelCap 透传:后缀只声明 ctx,不改该模型的确证输出 cap(deepseek-chat[1m] 仍 cap 8192)
84
+ return { id: base?.id ?? 'cap-suffix', name: base?.name ?? 'capacity suffix', match: '', contextWindow: ctx, maxTokens: base?.maxTokens ?? 64000, vision: base?.vision, perModelCap: base?.perModelCap };
85
+ }
86
+ const id = normalizeId(raw);
87
+ // ① preset 大表精确(含剥变体尾巴后再试)——精确命中才带 perModelCap(F2 裁决封顶① 证据位;
88
+ // ③ 层主干匹配拿的是家族参考行,不是该模型的确证 cap)
89
+ const hitOf = (m, exact = false) => ({ id: m.famId, name: m.famId, match: '', contextWindow: m.contextWindow, maxTokens: m.maxTokens, ...(exact ? { perModelCap: m.maxTokens } : {}) });
90
+ const exact = idx.exact.get(id);
91
+ if (exact)
92
+ return hitOf(exact, true);
93
+ const stripped = id.replace(VARIANT_TAIL, '');
94
+ if (stripped !== id) {
95
+ const e2 = idx.exact.get(stripped);
96
+ if (e2)
97
+ return hitOf(e2, true);
98
+ }
99
+ // ② 名内容量提示(moonshot-v1-128k / *-32k):k=×1024
100
+ const inline = id.match(/-(\d+)([km])\b/);
101
+ if (inline) {
102
+ const n = Number(inline[1]);
103
+ if ((inline[2] === 'k' && n >= 8) || inline[2] === 'm') {
104
+ const ctx = inline[2] === 'm' ? n * 1000000 : n * 1024;
105
+ return { id: 'inline-cap', name: 'capacity in id', match: '', contextWindow: ctx, maxTokens: Math.min(ctx, 65536) };
106
+ }
107
+ }
108
+ // ③ 家族主干:候选主干=preset model id 剥变体尾;主干出现在待匹配 id 中,取最长主干
109
+ let best = null;
110
+ let bestLen = 0;
111
+ for (const m of idx.stems) {
112
+ const stem = m.id.replace(VARIANT_TAIL, '');
113
+ if (stem.length >= 6 && id.includes(stem)) {
114
+ // 同长命中取 ctx 最小=家族原生保守值(服务档扩展如 DashScope 1M 让用户在档位里升,
115
+ // 预填错大比错小危险——超发请求直接被网关拒)
116
+ if (stem.length > bestLen || (stem.length === bestLen && best && m.contextWindow < best.contextWindow)) {
117
+ best = m;
118
+ bestLen = stem.length;
119
+ }
120
+ }
121
+ }
122
+ if (best)
123
+ return hitOf(best);
124
+ // ④ family 表前缀(anchored → unanchored)
125
+ for (const fam of MODEL_FAMILIES) {
126
+ if (fam.match && new RegExp(fam.match, 'i').test(id))
127
+ return fam;
128
+ }
129
+ for (const fam of MODEL_FAMILIES) {
130
+ if (fam.match && new RegExp(fam.match.replace(/\^/g, ''), 'i').test(id))
131
+ return fam;
132
+ }
133
+ return undefined;
134
+ }
135
+ /** Format token counts like "1m" / "384k". */
136
+ export function fmtTokens(n) {
137
+ // token 界惯例=二进制 K(clay 07-06:32768 显示 33K 是错的,就是 32K;262144=256K)。
138
+ // 1024 整除走二进制;否则十进制圆整(200000→200k、202800→203k);M 档十进制(1000000→1m)。
139
+ // #29⑤(prelaunch audit):十进制整千先判 —— 128000 是十进制圆数,必须渲 128k,不是 125k
140
+ // (128000%1024==0 曾把它劫进二进制档;其它入口全都叫 128K)。32768/262144/393216 不整除 1000,不受影响。
141
+ if (n >= 1000000 && n % 100000 === 0)
142
+ return `${n / 1000000}m`;
143
+ if (n >= 1000 && n % 1000 === 0)
144
+ return `${n / 1000}k`;
145
+ if (n >= 1024 && n % 1024 === 0)
146
+ return `${n / 1024}k`;
147
+ if (n >= 1000)
148
+ return `${Math.round(n / 1000)}k`;
149
+ return String(n);
150
+ }
151
+ /** "1m ctx / 384k out" style short metric text. */
152
+ export function fmtCtxOut(ctx, out) {
153
+ return `${fmtTokens(ctx)} ctx / ${fmtTokens(out)} out`;
154
+ }
155
+ /** Screen-4 execution-slot recommendation: cheapHint first, else a cheap-sounding sibling. */
156
+ export function pickCheapCandidate(models, defaultId) {
157
+ const others = models.filter(m => m.id !== defaultId);
158
+ return (others.find(m => m.cheapHint) ??
159
+ others.find(m => /flash|mini|lite|turbo|air|haiku|small/i.test(m.id)));
160
+ }