@steerable/agent-shell-web 0.9.1 → 0.10.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.
@@ -51,6 +51,11 @@ export interface OrchestrationChildNode {
51
51
  error?: string;
52
52
  spawnActionIndex?: number;
53
53
  waitActionIndex?: number;
54
+ /**
55
+ * Loop nesting depth from the child's lineage (`0.1.2` is 2). Absent when
56
+ * the only source was a tool result, which does not carry it.
57
+ */
58
+ depth?: number;
54
59
  }
55
60
 
56
61
  export interface OrchestrationFlowData {
@@ -189,6 +194,7 @@ export function extractOrchestrationFlow(
189
194
  task: c.task || '',
190
195
  status: toNodeStatus(c.status),
191
196
  recordId: c.recordId,
197
+ ...(c.depth !== undefined ? { depth: c.depth } : {}),
192
198
  steers: [],
193
199
  });
194
200
  }
@@ -368,6 +374,43 @@ function actionsFromTimeline(blocks?: ReadonlyArray<{ type: string; actions?: un
368
374
  return actions;
369
375
  }
370
376
 
377
+ /**
378
+ * Group nodes into layers by depth, for a flow that shows the tree shape.
379
+ *
380
+ * Depth is a permission ("who may spawn whom"), so the layout has to make it
381
+ * visible: siblings on one row, grandchildren one layer down. A node whose
382
+ * depth is unknown is derived from its lineage id (`0.1.2` → 2), which is the
383
+ * one place that number exists when only a tool result was seen.
384
+ *
385
+ * @param nodes The flow's child nodes.
386
+ * @returns Layers ordered by depth, each ordered as the input was.
387
+ */
388
+ export function layerByDepth(
389
+ nodes: readonly OrchestrationChildNode[],
390
+ ): OrchestrationChildNode[][] {
391
+ const byDepth = new Map<number, OrchestrationChildNode[]>();
392
+ for (const node of nodes) {
393
+ const depth = node.depth ?? depthFromLineage(node.childId);
394
+ const layer = byDepth.get(depth);
395
+ if (layer) layer.push(node);
396
+ else byDepth.set(depth, [node]);
397
+ }
398
+ return [...byDepth.entries()]
399
+ .sort(([a], [b]) => a - b)
400
+ .map(([, layer]) => layer);
401
+ }
402
+
403
+ /**
404
+ * Nesting depth from a lineage id: `0.1` is a child, `0.1.2` a grandchild.
405
+ *
406
+ * @param childId The lineage id (`0`, `0.3`, `0.3.1`).
407
+ * @returns Depth, or 1 when the id is not lineage-shaped.
408
+ */
409
+ export function depthFromLineage(childId: string): number {
410
+ const segments = childId.split('.').filter((part) => part.trim() !== '');
411
+ return Math.max(1, segments.length - 1);
412
+ }
413
+
371
414
  /**
372
415
  * 提取当前打开对话中最新一轮的编排流程。
373
416
  * 正在流式/执行中的回合优先;历史回合倒序寻找最新的一次编排。
@@ -89,6 +89,10 @@ export function AgentsSettingsPanel({
89
89
  const [name, setName] = useState('');
90
90
  const [description, setDescription] = useState('');
91
91
  const [rolePrompt, setRolePrompt] = useState('');
92
+ // R6: the model and reasoning effort this role delegates with. Blank means
93
+ // "follow the conversation", which is what an unconfigured agent must do.
94
+ const [model, setModel] = useState('');
95
+ const [reasoningEffort, setReasoningEffort] = useState('');
92
96
  const [color, setColor] = useState(DEFAULT_COLOR);
93
97
  const [capability, setCapability] = useState<AgentCapabilityDraft>(
94
98
  DEFAULT_CAPABILITY_DRAFT,
@@ -123,6 +127,8 @@ export function AgentsSettingsPanel({
123
127
  setName('');
124
128
  setDescription('');
125
129
  setRolePrompt('');
130
+ setModel('');
131
+ setReasoningEffort('');
126
132
  setColor(nextColor(agents));
127
133
  setCapability(DEFAULT_CAPABILITY_DRAFT);
128
134
  };
@@ -138,6 +144,8 @@ export function AgentsSettingsPanel({
138
144
  setName(agent.name);
139
145
  setDescription(agent.description ?? '');
140
146
  setRolePrompt(agent.rolePrompt ?? '');
147
+ setModel(agent.model ?? '');
148
+ setReasoningEffort(agent.reasoningEffort ?? '');
141
149
  setColor(agent.color || DEFAULT_COLOR);
142
150
  setCapability({
143
151
  skillIds: agent.skillIds ?? [],
@@ -164,6 +172,10 @@ export function AgentsSettingsPanel({
164
172
  allowExternalSkills: capability.allowExternalSkills,
165
173
  loadAllSkills: capability.loadAllSkills,
166
174
  toolPolicy: capability.toolPolicy,
175
+ // Blank clears the pin: null means "follow the conversation", not
176
+ // "keep the old value".
177
+ model: model.trim() || null,
178
+ reasoningEffort: reasoningEffort.trim() || null,
167
179
  };
168
180
  if (editingId) {
169
181
  await updateChatAgent(editingId, body);
@@ -261,6 +273,39 @@ export function AgentsSettingsPanel({
261
273
  data-testid="agent-form-role"
262
274
  />
263
275
  <AgentCapabilityFields value={capability} onChange={setCapability} />
276
+ <div className="flex gap-2">
277
+ <label className="flex-1">
278
+ <span className="mb-1.5 block text-[10px] font-medium text-agent-muted-foreground">
279
+ {t('Model')}
280
+ </span>
281
+ <input
282
+ type="text"
283
+ value={model}
284
+ onChange={(event) => setModel(event.target.value)}
285
+ placeholder={t('Follows the conversation')}
286
+ className="h-8 w-full rounded-agent-md border border-agent-border bg-agent-canvas px-3 text-xs text-agent-foreground focus:outline-none focus:ring-2 focus:ring-agent-foreground/30"
287
+ data-testid="agent-form-model"
288
+ />
289
+ </label>
290
+ <label className="flex-1">
291
+ <span className="mb-1.5 block text-[10px] font-medium text-agent-muted-foreground">
292
+ {t('Reasoning effort')}
293
+ </span>
294
+ <input
295
+ type="text"
296
+ value={reasoningEffort}
297
+ onChange={(event) => setReasoningEffort(event.target.value)}
298
+ placeholder={t('Follows the conversation')}
299
+ className="h-8 w-full rounded-agent-md border border-agent-border bg-agent-canvas px-3 text-xs text-agent-foreground focus:outline-none focus:ring-2 focus:ring-agent-foreground/30"
300
+ data-testid="agent-form-effort"
301
+ />
302
+ </label>
303
+ </div>
304
+ <p className="text-[10px] text-agent-muted-foreground">
305
+ {t(
306
+ 'Used when the main agent delegates to this one. Leave either blank to follow the conversation. A model this endpoint cannot serve fails the delegation instead of silently running the parent model.',
307
+ )}
308
+ </p>
264
309
  <div className="flex justify-end gap-2">
265
310
  <button
266
311
  type="button"
@@ -1,13 +1,22 @@
1
1
  import { LuGitFork } from 'react-icons/lu';
2
- import { useOrchestrationSetting } from '@/lib/orchestration-settings';
2
+ import {
3
+ ORCHESTRATION_MAX_DEPTH_RANGE,
4
+ ORCHESTRATION_MAX_PARALLEL_RANGE,
5
+ useOrchestrationLimits,
6
+ } from '@/lib/orchestration-settings';
3
7
  import { t } from '@/i18n';
4
8
 
5
9
  /**
6
10
  * OrchestrationSettingsPanel — 多智能体协同编排设置面板。
7
- * 默认开启。用户可手动关闭或再次开启,变更实时持久化并影响后续对话请求。
11
+ * 默认开启。开关、深度与并发都实时持久化,并随 `metadata.orchestration`
12
+ * 以对象形式下发给后续回合。
13
+ *
14
+ * 深度是权限(子代理能不能再派孙代理),所以它必须能在界面上改;写死 1/4
15
+ * 会让「设置里有这个开关」变成一句空话。
8
16
  */
9
17
  export function OrchestrationSettingsPanel() {
10
- const [enabled, setEnabled] = useOrchestrationSetting();
18
+ const [setting, update] = useOrchestrationLimits();
19
+ const enabled = setting.enabled;
11
20
 
12
21
  return (
13
22
  <div
@@ -37,7 +46,7 @@ export function OrchestrationSettingsPanel() {
37
46
  type="button"
38
47
  role="radio"
39
48
  aria-checked={enabled}
40
- onClick={() => setEnabled(true)}
49
+ onClick={() => update({ enabled: true })}
41
50
  className={[
42
51
  'h-6 rounded-full px-2.5 text-[11px] font-medium transition-colors',
43
52
  enabled
@@ -51,7 +60,7 @@ export function OrchestrationSettingsPanel() {
51
60
  type="button"
52
61
  role="radio"
53
62
  aria-checked={!enabled}
54
- onClick={() => setEnabled(false)}
63
+ onClick={() => update({ enabled: false })}
55
64
  className={[
56
65
  'h-6 rounded-full px-2.5 text-[11px] font-medium transition-colors',
57
66
  !enabled
@@ -63,8 +72,75 @@ export function OrchestrationSettingsPanel() {
63
72
  </button>
64
73
  </div>
65
74
  </div>
75
+
76
+ {/* 编排参数:关掉开关时置灰,值保留(下次打开还是用户调过的)。 */}
77
+ <div className="grid grid-cols-2 gap-2 border-t border-agent-border/60 pt-2">
78
+ <label className={enabled ? 'space-y-1' : 'space-y-1 opacity-50'}>
79
+ <span className="block text-[10px] font-medium text-agent-muted-foreground">
80
+ {t('Max depth')}
81
+ </span>
82
+ <select
83
+ value={setting.maxDepth}
84
+ disabled={!enabled}
85
+ onChange={(event) => update({ maxDepth: Number(event.target.value) })}
86
+ className="h-7 w-full rounded-agent-md border border-agent-border bg-agent-canvas px-2 text-xs text-agent-foreground disabled:cursor-not-allowed"
87
+ data-testid="orchestration-max-depth"
88
+ >
89
+ {rangeOptions(ORCHESTRATION_MAX_DEPTH_RANGE).map((n) => (
90
+ <option key={n} value={n}>
91
+ {n}
92
+ </option>
93
+ ))}
94
+ </select>
95
+ <span className="block text-[10px] leading-snug text-agent-muted-foreground">
96
+ {t('{min}–{max}; above 1 lets sub-agents spawn their own.', {
97
+ min: ORCHESTRATION_MAX_DEPTH_RANGE.min,
98
+ max: ORCHESTRATION_MAX_DEPTH_RANGE.max,
99
+ })}
100
+ </span>
101
+ </label>
102
+ <label className={enabled ? 'space-y-1' : 'space-y-1 opacity-50'}>
103
+ <span className="block text-[10px] font-medium text-agent-muted-foreground">
104
+ {t('Max parallel')}
105
+ </span>
106
+ <select
107
+ value={setting.maxParallel}
108
+ disabled={!enabled}
109
+ onChange={(event) => update({ maxParallel: Number(event.target.value) })}
110
+ className="h-7 w-full rounded-agent-md border border-agent-border bg-agent-canvas px-2 text-xs text-agent-foreground disabled:cursor-not-allowed"
111
+ data-testid="orchestration-max-parallel"
112
+ >
113
+ {rangeOptions(ORCHESTRATION_MAX_PARALLEL_RANGE).map((n) => (
114
+ <option key={n} value={n}>
115
+ {n}
116
+ </option>
117
+ ))}
118
+ </select>
119
+ <span className="block text-[10px] leading-snug text-agent-muted-foreground">
120
+ {t('{min}–{max}; how many sub-agents run at once.', {
121
+ min: ORCHESTRATION_MAX_PARALLEL_RANGE.min,
122
+ max: ORCHESTRATION_MAX_PARALLEL_RANGE.max,
123
+ })}
124
+ </span>
125
+ </label>
126
+ </div>
127
+ {enabled && setting.maxDepth > 1 ? (
128
+ // 深度 >1 是权限扩张,不是普通偏好:说清代价。
129
+ <p className="text-[10px] leading-relaxed text-agent-muted-foreground">
130
+ {t(
131
+ 'Allowing children to spawn further sub-agents raises token use and unpredictability with every extra layer.',
132
+ )}
133
+ </p>
134
+ ) : null}
135
+ <p className="text-[10px] text-agent-muted-foreground">
136
+ {t('Taking effect next turn')}
137
+ </p>
66
138
  </div>
67
139
  );
68
140
  }
69
141
 
142
+ function rangeOptions(range: { min: number; max: number }): number[] {
143
+ return Array.from({ length: range.max - range.min + 1 }, (_, i) => range.min + i);
144
+ }
145
+
70
146
  export default OrchestrationSettingsPanel;
@@ -38,6 +38,8 @@ interface UsageSummaryWire {
38
38
  totalTokens: number;
39
39
  cachedPromptTokens: number;
40
40
  costUsd: number;
41
+ /** R5: rows that are only a partial bill (external-engine children). */
42
+ partialTurns: number;
41
43
  };
42
44
  }
43
45
 
@@ -185,6 +187,16 @@ export function UsagePanel() {
185
187
  'Cost is estimated from the framework price table and converted to RMB at about 1 USD = 7.2 CNY. Only models with a price are counted; "—" means the model has no price (local or unknown). Cache hits are the tokens served from the prompt cache.',
186
188
  )}
187
189
  </p>
190
+ {summary.totals.partialTurns > 0 && (
191
+ // 外部引擎子代理不报 token,那几轮存下的数字只是下限。
192
+ // 不加这句,偏小的合计会被读成完整账单。
193
+ <p className="text-[10px] text-agent-muted-foreground">
194
+ {t(
195
+ '{turns} turns exclude sub-agents whose engine reports no tokens; their share is not counted.',
196
+ { turns: summary.totals.partialTurns },
197
+ )}
198
+ </p>
199
+ )}
188
200
  </>
189
201
  )}
190
202
  </div>
@@ -57,6 +57,13 @@ export interface LocalChatAgent {
57
57
  allowExternalSkills?: boolean;
58
58
  /** true = 无视触发条件加载全部技能(内置「智能助手」如此)。 */
59
59
  loadAllSkills?: boolean;
60
+ /**
61
+ * 委派给这个智能体时用的模型。null/缺省 = 跟随父级;配了则由 sidecar
62
+ * 重建 provider,宿主服务不了的名字在建 provider 时失败即拒绝。
63
+ */
64
+ model?: string | null;
65
+ /** 委派时的推理强度。null/缺省 = 跟随父级。 */
66
+ reasoningEffort?: string | null;
60
67
  isBuiltin: boolean;
61
68
  isArchived?: boolean;
62
69
  /**
@@ -1,9 +1,28 @@
1
1
  import { useEffect, useState } from 'react';
2
2
 
3
+ /** 开关:true / false。保留旧键,旧客户端写过的值继续生效。 */
3
4
  export const ORCHESTRATION_SETTING_STORAGE_KEY = 'steerable.orchestration.enabled';
5
+ /** 深度上限(1–3)。与开关分开存,关掉开关时值保留。 */
6
+ export const ORCHESTRATION_MAX_DEPTH_KEY = 'steerable.orchestration.maxDepth';
7
+ /** 并发上限(1–8)。同上。 */
8
+ export const ORCHESTRATION_MAX_PARALLEL_KEY = 'steerable.orchestration.maxParallel';
4
9
 
5
10
  const CHANGE_EVENT = 'steerable:orchestration-setting-changed';
6
11
 
12
+ /** 设置页给出的范围。超出范围的值由 `resolveTurnOrchestration` 夹紧。 */
13
+ export const ORCHESTRATION_MAX_DEPTH_RANGE = { min: 1, max: 3 } as const;
14
+ export const ORCHESTRATION_MAX_PARALLEL_RANGE = { min: 1, max: 8 } as const;
15
+
16
+ const DEFAULT_MAX_DEPTH = 1;
17
+ const DEFAULT_MAX_PARALLEL = 4;
18
+
19
+ /** 下发给回合的编排参数(`metadata.orchestration` 的对象形式)。 */
20
+ export interface OrchestrationTurnSetting {
21
+ enabled: boolean;
22
+ maxDepth: number;
23
+ maxParallel: number;
24
+ }
25
+
7
26
  /**
8
27
  * 读取多智能体协同编排功能开关,默认开启 (true)。
9
28
  */
@@ -14,17 +33,84 @@ export function isOrchestrationSettingEnabled(): boolean {
14
33
  return stored !== 'false' && stored !== '0';
15
34
  }
16
35
 
36
+ /**
37
+ * 读取编排参数(开关 + 深度 + 并发)。
38
+ *
39
+ * 三个键分开存,因为关掉开关时两个数字要保留:用户下次打开还是他调过的
40
+ * 值,而不是悄悄回到 1 / 4。
41
+ */
42
+ export function readOrchestrationSetting(): OrchestrationTurnSetting {
43
+ return {
44
+ enabled: isOrchestrationSettingEnabled(),
45
+ maxDepth: readInt(
46
+ ORCHESTRATION_MAX_DEPTH_KEY,
47
+ DEFAULT_MAX_DEPTH,
48
+ ORCHESTRATION_MAX_DEPTH_RANGE,
49
+ ),
50
+ maxParallel: readInt(
51
+ ORCHESTRATION_MAX_PARALLEL_KEY,
52
+ DEFAULT_MAX_PARALLEL,
53
+ ORCHESTRATION_MAX_PARALLEL_RANGE,
54
+ ),
55
+ };
56
+ }
57
+
17
58
  /**
18
59
  * 持久化多智能体协同编排开关到 localStorage 并广播变更。
19
60
  */
20
61
  export function persistOrchestrationSetting(enabled: boolean): void {
21
62
  if (typeof localStorage === 'undefined') return;
22
63
  localStorage.setItem(ORCHESTRATION_SETTING_STORAGE_KEY, enabled ? 'true' : 'false');
64
+ broadcast(enabled);
65
+ }
66
+
67
+ /**
68
+ * 持久化深度 / 并发上限并广播变更。
69
+ *
70
+ * @param limits Partial of the two numbers; omitted keys keep their value.
71
+ */
72
+ export function persistOrchestrationLimits(
73
+ limits: Partial<Pick<OrchestrationTurnSetting, 'maxDepth' | 'maxParallel'>>,
74
+ ): void {
75
+ if (typeof localStorage === 'undefined') return;
76
+ if (limits.maxDepth !== undefined) {
77
+ localStorage.setItem(
78
+ ORCHESTRATION_MAX_DEPTH_KEY,
79
+ String(clamp(limits.maxDepth, ORCHESTRATION_MAX_DEPTH_RANGE)),
80
+ );
81
+ }
82
+ if (limits.maxParallel !== undefined) {
83
+ localStorage.setItem(
84
+ ORCHESTRATION_MAX_PARALLEL_KEY,
85
+ String(clamp(limits.maxParallel, ORCHESTRATION_MAX_PARALLEL_RANGE)),
86
+ );
87
+ }
88
+ broadcast(isOrchestrationSettingEnabled());
89
+ }
90
+
91
+ function broadcast(enabled: boolean): void {
23
92
  if (typeof window !== 'undefined') {
24
93
  window.dispatchEvent(new CustomEvent(CHANGE_EVENT, { detail: enabled }));
25
94
  }
26
95
  }
27
96
 
97
+ function readInt(
98
+ key: string,
99
+ fallback: number,
100
+ range: { min: number; max: number },
101
+ ): number {
102
+ if (typeof localStorage === 'undefined') return fallback;
103
+ const raw = localStorage.getItem(key);
104
+ if (raw === null) return fallback;
105
+ const parsed = Number.parseInt(raw, 10);
106
+ if (!Number.isFinite(parsed)) return fallback;
107
+ return clamp(parsed, range);
108
+ }
109
+
110
+ function clamp(value: number, range: { min: number; max: number }): number {
111
+ return Math.min(range.max, Math.max(range.min, Math.trunc(value)));
112
+ }
113
+
28
114
  /**
29
115
  * 响应式 hook:订阅并切换编排功能开关。
30
116
  */
@@ -56,3 +142,39 @@ export function useOrchestrationSetting(): [boolean, (enabled: boolean) => void]
56
142
 
57
143
  return [enabled, update];
58
144
  }
145
+
146
+ /**
147
+ * 响应式 hook:订阅并修改编排参数(开关 + 两个上限)。
148
+ */
149
+ export function useOrchestrationLimits(): [
150
+ OrchestrationTurnSetting,
151
+ (next: Partial<OrchestrationTurnSetting>) => void,
152
+ ] {
153
+ const [setting, setSetting] = useState<OrchestrationTurnSetting>(() =>
154
+ readOrchestrationSetting(),
155
+ );
156
+
157
+ useEffect(() => {
158
+ if (typeof window === 'undefined') return;
159
+ const handler = () => setSetting(readOrchestrationSetting());
160
+ window.addEventListener(CHANGE_EVENT, handler);
161
+ window.addEventListener('storage', handler);
162
+ return () => {
163
+ window.removeEventListener(CHANGE_EVENT, handler);
164
+ window.removeEventListener('storage', handler);
165
+ };
166
+ }, []);
167
+
168
+ const update = (next: Partial<OrchestrationTurnSetting>) => {
169
+ if (next.enabled !== undefined) persistOrchestrationSetting(next.enabled);
170
+ if (next.maxDepth !== undefined || next.maxParallel !== undefined) {
171
+ persistOrchestrationLimits({
172
+ ...(next.maxDepth !== undefined ? { maxDepth: next.maxDepth } : {}),
173
+ ...(next.maxParallel !== undefined ? { maxParallel: next.maxParallel } : {}),
174
+ });
175
+ }
176
+ setSetting(readOrchestrationSetting());
177
+ };
178
+
179
+ return [setting, update];
180
+ }