@zhin.js/adapter-sandbox 1.1.17 → 1.1.18

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.
@@ -1,3 +1,4 @@
1
+ import { sandboxText, type SandboxLocale } from './messages.js';
1
2
  import { getSandboxApiBase, getSandboxAuthHeaders } from './sandboxTransport.js';
2
3
 
3
4
  export type SandboxScope = 'private' | 'group' | 'channel';
@@ -221,7 +222,7 @@ export function deriveTaskRuns(snapshot: AgentTraceSnapshot | null): AgentTaskRu
221
222
  }).sort((left, right) => right.startedAt - left.startedAt);
222
223
  }
223
224
 
224
- export function deriveWorkbenchArtifacts(snapshot: AgentTraceSnapshot | null): WorkbenchArtifact[] {
225
+ export function deriveWorkbenchArtifacts(snapshot: AgentTraceSnapshot | null, locale: SandboxLocale = 'zh-CN'): WorkbenchArtifact[] {
225
226
  if (!snapshot) return [];
226
227
  const outcomes = new Map<string, AgentTraceEvent>();
227
228
  for (const event of snapshot.events) {
@@ -251,7 +252,7 @@ export function deriveWorkbenchArtifacts(snapshot: AgentTraceSnapshot | null): W
251
252
  return [{
252
253
  ...common,
253
254
  kind: 'file-change',
254
- title: toolName === 'write_file' ? '写入文件' : '编辑文件',
255
+ title: toolName === 'write_file' ? sandboxText(locale, "写入文件") : sandboxText(locale, "编辑文件"),
255
256
  path: filePath,
256
257
  detail: artifactOutputDetail(outcome),
257
258
  diff: fileDiff(toolName, args, filePath),
@@ -271,7 +272,7 @@ export function deriveWorkbenchArtifacts(snapshot: AgentTraceSnapshot | null): W
271
272
  }).sort((left, right) => right.recordedAt - left.recordedAt);
272
273
  }
273
274
 
274
- export function deriveAgentRunSteps(snapshot: AgentTraceSnapshot | null, run: AgentRunIdentity | undefined): AgentRunStep[] {
275
+ export function deriveAgentRunSteps(snapshot: AgentTraceSnapshot | null, run: AgentRunIdentity | undefined, locale: SandboxLocale = 'zh-CN'): AgentRunStep[] {
275
276
  if (!snapshot || !run) return [];
276
277
  const { turnId } = run;
277
278
  const events = snapshot.events.filter((event) => matchesRun(event, run));
@@ -285,12 +286,12 @@ export function deriveAgentRunSteps(snapshot: AgentTraceSnapshot | null, run: Ag
285
286
  const steps = events.flatMap((event): AgentRunStep[] => {
286
287
  const common = { id: `${event.runtimeId ?? 'legacy'}:${turnId}:${event.sequence}`, recordedAt: event.recordedAt } as const;
287
288
  if (event.type === 'turn_start') {
288
- return [{ ...common, title: '接收任务', detail: shortTurn(turnId), status: 'completed' }];
289
+ return [{ ...common, title: sandboxText(locale, "接收任务"), detail: shortTurn(turnId), status: 'completed' }];
289
290
  }
290
291
  if (event.type === 'capability_resolution') {
291
292
  return [{
292
293
  ...common,
293
- title: '准备运行能力',
294
+ title: sandboxText(locale, "准备运行能力"),
294
295
  detail: `${arrayLength(event.data.tools)} tools · ${arrayLength(event.data.skills)} skills`,
295
296
  status: 'completed',
296
297
  }];
@@ -298,8 +299,8 @@ export function deriveAgentRunSteps(snapshot: AgentTraceSnapshot | null, run: Ag
298
299
  if (event.type === 'iteration_start') {
299
300
  return [{
300
301
  ...common,
301
- title: `推理迭代 ${String(event.data.iteration ?? '')}`.trim(),
302
- detail: event.data.maxIterations == null ? undefined : `上限 ${String(event.data.maxIterations)}`,
302
+ title: sandboxText(locale, "推理迭代 {0}", [String(event.data.iteration ?? '')]).trim(),
303
+ detail: event.data.maxIterations == null ? undefined : sandboxText(locale, "上限 {0}", [String(event.data.maxIterations)]),
303
304
  status: 'completed',
304
305
  }];
305
306
  }
@@ -313,7 +314,7 @@ export function deriveAgentRunSteps(snapshot: AgentTraceSnapshot | null, run: Ag
313
314
  return [{
314
315
  ...common,
315
316
  id: toolCorrelationKey(event, toolUseId),
316
- title: `运行 ${toolName}`,
317
+ title: sandboxText(locale, "运行 {0}", [toolName]),
317
318
  ...(detail ? { detail } : {}),
318
319
  status: artifactStatus(outcome),
319
320
  ...(durationMs !== undefined ? { durationMs } : {}),
@@ -322,7 +323,7 @@ export function deriveAgentRunSteps(snapshot: AgentTraceSnapshot | null, run: Ag
322
323
  if (event.type === 'subagent_start') {
323
324
  return [{
324
325
  ...common,
325
- title: `委派 ${stringValue(event.data.agentName) || '子 Agent'}`,
326
+ title: sandboxText(locale, "委派 {0}", [stringValue(event.data.agentName) || sandboxText(locale, "子 Agent")]),
326
327
  detail: preview(event.data.description) || undefined,
327
328
  status: 'running',
328
329
  }];
@@ -331,15 +332,15 @@ export function deriveAgentRunSteps(snapshot: AgentTraceSnapshot | null, run: Ag
331
332
  const failed = event.data.status === 'error';
332
333
  return [{
333
334
  ...common,
334
- title: failed ? '子 Agent 失败' : '子 Agent 返回',
335
+ title: failed ? sandboxText(locale, "子 Agent 失败") : sandboxText(locale, "子 Agent 返回"),
335
336
  detail: preview(event.data.summary ?? event.data.error) || undefined,
336
337
  status: failed ? 'failed' : 'completed',
337
338
  }];
338
339
  }
339
- if (event.type === 'turn_end') return [{ ...common, title: '任务完成', detail: 'Agent 已返回结果', status: 'completed' }];
340
- if (event.type === 'turn_cancelled') return [{ ...common, title: '任务已停止', detail: preview(event.data.reason) || undefined, status: 'cancelled' }];
341
- if (event.type === 'budget_exceeded') return [{ ...common, title: '达到预算上限', detail: preview(event.data.budget) || undefined, status: 'failed' }];
342
- if (event.type === 'error') return [{ ...common, title: '任务失败', detail: preview(event.data.error) || undefined, status: 'failed' }];
340
+ if (event.type === 'turn_end') return [{ ...common, title: sandboxText(locale, "任务完成"), detail: sandboxText(locale, "Agent 已返回结果"), status: 'completed' }];
341
+ if (event.type === 'turn_cancelled') return [{ ...common, title: sandboxText(locale, "任务已停止"), detail: preview(event.data.reason) || undefined, status: 'cancelled' }];
342
+ if (event.type === 'budget_exceeded') return [{ ...common, title: sandboxText(locale, "达到预算上限"), detail: preview(event.data.budget) || undefined, status: 'failed' }];
343
+ if (event.type === 'error') return [{ ...common, title: sandboxText(locale, "任务失败"), detail: preview(event.data.error) || undefined, status: 'failed' }];
343
344
  return [];
344
345
  });
345
346
 
@@ -354,8 +355,8 @@ export function deriveAgentRunSteps(snapshot: AgentTraceSnapshot | null, run: Ag
354
355
  if (task?.status === 'running' && steps.length > 0 && steps.at(-1)?.status !== 'running') {
355
356
  steps.push({
356
357
  id: `${task.id}:waiting`,
357
- title: '等待 Agent 返回',
358
- detail: '任务仍在运行',
358
+ title: sandboxText(locale, "等待 Agent 返回"),
359
+ detail: sandboxText(locale, "任务仍在运行"),
359
360
  status: 'running',
360
361
  recordedAt: events.at(-1)?.recordedAt ?? task.startedAt,
361
362
  });
@@ -363,79 +364,79 @@ export function deriveAgentRunSteps(snapshot: AgentTraceSnapshot | null, run: Ag
363
364
  return steps;
364
365
  }
365
366
 
366
- export function buildAgentRunReport(snapshot: AgentTraceSnapshot | null, context: AgentRunReportContext = {}): string {
367
+ export function buildAgentRunReport(snapshot: AgentTraceSnapshot | null, context: AgentRunReportContext = {}, locale: SandboxLocale = 'zh-CN'): string {
367
368
  const runs = deriveTaskRuns(snapshot);
368
369
  const run = context.run ? runs.find((candidate) => candidate.id === runIdentityKey(context.run)) : runs[0];
369
370
  const identity = run ?? context.run;
370
371
  const turnId = identity?.turnId;
371
- const steps = deriveAgentRunSteps(snapshot, identity);
372
- const artifacts = deriveWorkbenchArtifacts(snapshot).filter((artifact) => identity && matchesRun(artifact, identity));
373
- const status = run ? taskStatusText(run.status) : '无运行记录';
372
+ const steps = deriveAgentRunSteps(snapshot, identity, locale);
373
+ const artifacts = deriveWorkbenchArtifacts(snapshot, locale).filter((artifact) => identity && matchesRun(artifact, identity));
374
+ const status = run ? taskStatusText(run.status, locale) : sandboxText(locale, "无运行记录");
374
375
  const lines = [
375
- '# Agent 运行报告',
376
+ sandboxText(locale, "# Agent 运行报告"),
376
377
  '',
377
- `- **会话:** ${markdownInline(context.sessionName || snapshot?.sessionKey || '未命名会话')}`,
378
- `- **任务 ID:** ${markdownInline(turnId || '—')}`,
379
- `- **状态:** ${status}`,
380
- `- **开始时间:** ${run ? new Date(run.startedAt).toISOString() : '—'}`,
381
- `- **耗时:** ${run?.durationMs === undefined ? (run?.status === 'running' ? '进行中' : '—') : `${run.durationMs.toLocaleString()} ms`}`,
382
- `- **工作目录:** ${markdownInline(context.workingDirectory || 'Host project root')}`,
383
- `- **安全策略:** ${markdownInline(context.safetyMode || '—')} / ${markdownInline(context.approvalMode || '—')} / network ${context.networkAccess ? 'enabled' : 'disabled'}`,
384
- `- **用量:** ${run?.toolCount ?? 0} tools / ${(run?.tokenCount ?? 0).toLocaleString()} tokens / ${run?.problemCount ?? 0} problems`,
378
+ sandboxText(locale, "- **会话:** {0}", [markdownInline(context.sessionName || snapshot?.sessionKey || sandboxText(locale, "未命名会话"))]),
379
+ sandboxText(locale, "- **任务 ID:** {0}", [markdownInline(turnId || '—')]),
380
+ sandboxText(locale, "- **状态:** {0}", [status]),
381
+ sandboxText(locale, "- **开始时间:** {0}", [run ? new Date(run.startedAt).toISOString() : '—']),
382
+ sandboxText(locale, "- **耗时:** {0}", [run?.durationMs === undefined ? (run?.status === 'running' ? sandboxText(locale, "进行中") : '—') : `${run.durationMs.toLocaleString(locale)} ms`]),
383
+ sandboxText(locale, "- **工作目录:** {0}", [markdownInline(context.workingDirectory || 'Host project root')]),
384
+ sandboxText(locale, "- **安全策略:** {0} / {1} / network {2}", [markdownInline(context.safetyMode || '—'), markdownInline(context.approvalMode || '—'), context.networkAccess ? 'enabled' : 'disabled']),
385
+ sandboxText(locale, "- **用量:** {0} tools / {1} tokens / {2} problems", [run?.toolCount ?? 0, (run?.tokenCount ?? 0).toLocaleString(locale), run?.problemCount ?? 0]),
385
386
  ];
386
387
 
387
388
  if (context.taskPrompt?.trim()) {
388
- lines.push('', '## 任务', '', ...markdownBlock('text', context.taskPrompt.trim()));
389
+ lines.push('', sandboxText(locale, "## 任务"), '', ...markdownBlock('text', context.taskPrompt.trim()));
389
390
  }
390
- lines.push('', '## 执行轨迹', '');
391
- if (steps.length === 0) lines.push('- 暂无可用轨迹');
391
+ lines.push('', sandboxText(locale, "## 执行轨迹"), '');
392
+ if (steps.length === 0) lines.push(sandboxText(locale, "- 暂无可用轨迹"));
392
393
  else for (const step of steps) {
393
- lines.push(`- ${stepStatusMark(step.status)} **${reportStepTitle(step.title)}**${step.detail ? ` — ${markdownInline(step.detail)}` : ''}${step.durationMs === undefined ? '' : ` (${step.durationMs.toLocaleString()} ms)`}`);
394
+ lines.push(`- ${stepStatusMark(step.status)} **${reportStepTitle(step.title, locale)}**${step.detail ? ` — ${markdownInline(step.detail)}` : ''}${step.durationMs === undefined ? '' : ` (${step.durationMs.toLocaleString(locale)} ms)`}`);
394
395
  }
395
396
 
396
- lines.push('', '## 变更与产物', '');
397
- if (artifacts.length === 0) lines.push('- 本次运行没有文件、命令或测试产物。');
397
+ lines.push('', sandboxText(locale, "## 变更与产物"), '');
398
+ if (artifacts.length === 0) lines.push(sandboxText(locale, "- 本次运行没有文件、命令或测试产物。"));
398
399
  else artifacts.forEach((artifact, index) => {
399
400
  lines.push(`### ${index + 1}. ${markdownInline(artifact.title)}`, '');
400
- lines.push(`- 类型:${artifact.kind}`, `- 状态:${artifact.status}`);
401
- if (artifact.path) lines.push(`- 路径:${markdownInlineCode(artifact.path)}`);
402
- if (artifact.durationMs !== undefined) lines.push(`- 耗时:${artifact.durationMs.toLocaleString()} ms`);
401
+ lines.push(sandboxText(locale, "- 类型:{0}", [artifact.kind]), sandboxText(locale, "- 状态:{0}", [artifact.status]));
402
+ if (artifact.path) lines.push(sandboxText(locale, "- 路径:{0}", [markdownInlineCode(artifact.path)]));
403
+ if (artifact.durationMs !== undefined) lines.push(sandboxText(locale, "- 耗时:{0} ms", [artifact.durationMs.toLocaleString(locale)]));
403
404
  if (artifact.diff) lines.push('', ...markdownBlock('diff', artifact.diff));
404
405
  else if (artifact.detail) lines.push('', ...markdownBlock('text', artifact.detail));
405
406
  lines.push('');
406
407
  });
407
408
 
408
- lines.push('---', `由 Zhin Agent 试验台于 ${new Date().toISOString()} 导出。`);
409
+ lines.push('---', sandboxText(locale, "由 Zhin「试聊一下」于 {0} 导出。", [new Date().toISOString()]));
409
410
  return `${lines.join('\n').trim()}\n`;
410
411
  }
411
412
 
412
- export function presentTraceEvent(event: AgentTraceEvent): { readonly title: string; readonly detail: string; readonly tone: string } {
413
+ export function presentTraceEvent(event: AgentTraceEvent, locale: SandboxLocale = 'zh-CN'): { readonly title: string; readonly detail: string; readonly tone: string } {
413
414
  const data = event.data;
414
415
  const tool = String(data.toolName ?? 'tool');
415
416
  switch (event.type) {
416
- case 'turn_start': return { title: '开始处理', detail: shortTurn(event.turnId), tone: 'running' };
417
- case 'capability_resolution': return { title: '能力已解析', detail: `${arrayLength(data.tools)} tools · ${arrayLength(data.skills)} skills`, tone: 'capability' };
418
- case 'iteration_start': return { title: `推理迭代 ${String(data.iteration ?? '')}`, detail: `上限 ${String(data.maxIterations ?? '—')}`, tone: 'thinking' };
419
- case 'thinking': return { title: '模型思考', detail: preview(data.text), tone: 'thinking' };
420
- case 'tool_call': return { title: `调用 ${tool}`, detail: preview(data.toolUseId), tone: 'tool' };
421
- case 'tool_result': return { title: `${tool} 完成`, detail: duration(data.durationMs), tone: 'success' };
422
- case 'tool_denied': return { title: `${tool} 被拒绝`, detail: preview(data.reason ?? data.policy), tone: 'problem' };
423
- case 'tool_failed': return { title: `${tool} 失败`, detail: preview(data.error), tone: 'problem' };
424
- case 'mcp_connect': return { title: `${String(data.serverName ?? 'MCP')} 连接`, detail: String(data.status ?? ''), tone: 'capability' };
417
+ case 'turn_start': return { title: sandboxText(locale, "开始处理"), detail: shortTurn(event.turnId), tone: 'running' };
418
+ case 'capability_resolution': return { title: sandboxText(locale, "能力已解析"), detail: `${arrayLength(data.tools)} tools · ${arrayLength(data.skills)} skills`, tone: 'capability' };
419
+ case 'iteration_start': return { title: sandboxText(locale, "推理迭代 {0}", [String(data.iteration ?? '')]), detail: sandboxText(locale, "上限 {0}", [String(data.maxIterations ?? '—')]), tone: 'thinking' };
420
+ case 'thinking': return { title: sandboxText(locale, "模型思考"), detail: preview(data.text), tone: 'thinking' };
421
+ case 'tool_call': return { title: sandboxText(locale, "调用 {0}", [tool]), detail: preview(data.toolUseId), tone: 'tool' };
422
+ case 'tool_result': return { title: sandboxText(locale, "{0} 完成", [tool]), detail: duration(data.durationMs, locale), tone: 'success' };
423
+ case 'tool_denied': return { title: sandboxText(locale, "{0} 被拒绝", [tool]), detail: preview(data.reason ?? data.policy), tone: 'problem' };
424
+ case 'tool_failed': return { title: sandboxText(locale, "{0} 失败", [tool]), detail: preview(data.error), tone: 'problem' };
425
+ case 'mcp_connect': return { title: sandboxText(locale, "{0} 连接", [String(data.serverName ?? 'MCP')]), detail: String(data.status ?? ''), tone: 'capability' };
425
426
  case 'mcp_tool_call': return { title: String(data.toolName ?? 'MCP tool'), detail: `via ${String(data.serverName ?? 'MCP')}`, tone: 'tool' };
426
- case 'subagent_start': return { title: `委派 ${String(data.agentName ?? 'subagent')}`, detail: preview(data.description), tone: 'capability' };
427
- case 'subagent_progress': return { title: '子 Agent 更新', detail: preview(data.summary), tone: 'running' };
428
- case 'subagent_end': return { title: '子 Agent 返回', detail: String(data.status ?? 'done'), tone: data.status === 'error' ? 'problem' : 'success' };
429
- case 'usage': return { title: `${usageTotal(data).toLocaleString()} tokens`, detail: usageDetail(data), tone: 'usage' };
430
- case 'turn_end': return { title: '本轮完成', detail: 'Agent 已返回结果', tone: 'success' };
431
- case 'turn_cancelled': return { title: '本轮取消', detail: preview(data.reason), tone: 'muted' };
432
- case 'budget_exceeded': return { title: '达到预算上限', detail: preview(data.budget), tone: 'problem' };
433
- case 'error': return { title: '执行失败', detail: preview(data.error), tone: 'problem' };
427
+ case 'subagent_start': return { title: sandboxText(locale, "委派 {0}", [String(data.agentName ?? 'subagent')]), detail: preview(data.description), tone: 'capability' };
428
+ case 'subagent_progress': return { title: sandboxText(locale, "子 Agent 更新"), detail: preview(data.summary), tone: 'running' };
429
+ case 'subagent_end': return { title: sandboxText(locale, "子 Agent 返回"), detail: String(data.status ?? 'done'), tone: data.status === 'error' ? 'problem' : 'success' };
430
+ case 'usage': return { title: `${usageTotal(data).toLocaleString(locale)} tokens`, detail: usageDetail(data, locale), tone: 'usage' };
431
+ case 'turn_end': return { title: sandboxText(locale, "本轮完成"), detail: sandboxText(locale, "Agent 已返回结果"), tone: 'success' };
432
+ case 'turn_cancelled': return { title: sandboxText(locale, "本轮取消"), detail: preview(data.reason), tone: 'muted' };
433
+ case 'budget_exceeded': return { title: sandboxText(locale, "达到预算上限"), detail: preview(data.budget), tone: 'problem' };
434
+ case 'error': return { title: sandboxText(locale, "执行失败"), detail: preview(data.error), tone: 'problem' };
434
435
  default: return { title: event.type.replaceAll('_', ' '), detail: '', tone: 'muted' };
435
436
  }
436
437
  }
437
438
 
438
- export async function fetchAgentTrace(sessionKey: string, afterSequence = 0): Promise<AgentTraceSnapshot> {
439
+ export async function fetchAgentTrace(sessionKey: string, afterSequence = 0, locale: SandboxLocale = 'zh-CN'): Promise<AgentTraceSnapshot> {
439
440
  const base = getSandboxApiBase() || window.location.origin;
440
441
  const url = new URL('/api/agent/traces', `${base}/`);
441
442
  url.searchParams.set('sessionKey', sessionKey);
@@ -445,13 +446,13 @@ export async function fetchAgentTrace(sessionKey: string, afterSequence = 0): Pr
445
446
  const body = await response.json().catch(() => ({})) as { success?: boolean; data?: AgentTraceSnapshot; error?: string };
446
447
  if (!response.ok || body.success === false || !body.data) {
447
448
  throw new Error(response.status === 503
448
- ? 'Agent Trace 尚未启用'
449
- : body.error || '无法读取 Agent Trace');
449
+ ? sandboxText(locale, "Agent Trace 尚未启用")
450
+ : body.error || sandboxText(locale, "无法读取 Agent Trace"));
450
451
  }
451
452
  return body.data;
452
453
  }
453
454
 
454
- export async function cancelAgentTask(sessionKey: string): Promise<boolean> {
455
+ export async function cancelAgentTask(sessionKey: string, locale: SandboxLocale = 'zh-CN'): Promise<boolean> {
455
456
  const base = getSandboxApiBase() || window.location.origin;
456
457
  const response = await fetch(new URL('/api/agent/tasks/cancel', `${base}/`), {
457
458
  method: 'POST',
@@ -464,7 +465,7 @@ export async function cancelAgentTask(sessionKey: string): Promise<boolean> {
464
465
  error?: string;
465
466
  };
466
467
  if (!response.ok || body.success === false) {
467
- throw new Error(body.error || '无法停止 Agent 任务');
468
+ throw new Error(body.error || sandboxText(locale, "无法停止 Agent 任务"));
468
469
  }
469
470
  return body.data?.cancelled === true;
470
471
  }
@@ -477,9 +478,9 @@ function usageTotal(data: Record<string, unknown>): number {
477
478
  return Number(usageRecord(data).totalTokens ?? 0);
478
479
  }
479
480
 
480
- function usageDetail(data: Record<string, unknown>): string {
481
+ function usageDetail(data: Record<string, unknown>, locale: SandboxLocale = 'zh-CN'): string {
481
482
  const usage = usageRecord(data);
482
- return `输入 ${Number(usage.promptTokens ?? 0).toLocaleString()} · 输出 ${Number(usage.completionTokens ?? 0).toLocaleString()}`;
483
+ return sandboxText(locale, "输入 {0} · 输出 {1}", [Number(usage.promptTokens ?? 0).toLocaleString(locale), Number(usage.completionTokens ?? 0).toLocaleString(locale)]);
483
484
  }
484
485
 
485
486
  function arrayLength(value: unknown): number {
@@ -492,9 +493,9 @@ function preview(value: unknown): string {
492
493
  try { return JSON.stringify(value).slice(0, 96); } catch { return String(value).slice(0, 96); }
493
494
  }
494
495
 
495
- function duration(value: unknown): string {
496
+ function duration(value: unknown, locale: SandboxLocale = 'zh-CN'): string {
496
497
  const ms = Number(value);
497
- return Number.isFinite(ms) ? `${ms.toLocaleString()} ms` : '执行完成';
498
+ return Number.isFinite(ms) ? `${ms.toLocaleString(locale)} ms` : sandboxText(locale, "执行完成");
498
499
  }
499
500
 
500
501
  function shortTurn(value: string): string {
@@ -525,11 +526,11 @@ function toolStepDetail(toolName: string, args: Record<string, unknown>, fallbac
525
526
  return fallback;
526
527
  }
527
528
 
528
- function taskStatusText(status: AgentTaskStatus): string {
529
- if (status === 'running') return '运行中';
530
- if (status === 'completed') return '已完成';
531
- if (status === 'cancelled') return '已取消';
532
- return '失败';
529
+ function taskStatusText(status: AgentTaskStatus, locale: SandboxLocale = 'zh-CN'): string {
530
+ if (status === 'running') return sandboxText(locale, "运行中");
531
+ if (status === 'completed') return sandboxText(locale, "已完成");
532
+ if (status === 'cancelled') return sandboxText(locale, "已取消");
533
+ return sandboxText(locale, "失败");
533
534
  }
534
535
 
535
536
  function stepStatusMark(status: AgentRunStepStatus): string {
@@ -543,9 +544,9 @@ function markdownInline(value: string): string {
543
544
  return value.replace(/[\\`*_[\]<>]/gu, '\\$&').replace(/\r?\n/gu, ' ');
544
545
  }
545
546
 
546
- function reportStepTitle(value: string): string {
547
+ function reportStepTitle(value: string, locale: SandboxLocale = 'zh-CN'): string {
547
548
  const tool = /^运行 (.+)$/u.exec(value)?.[1];
548
- return tool ? `运行 ${markdownInlineCode(tool)}` : markdownInline(value);
549
+ return tool ? sandboxText(locale, "运行 {0}", [markdownInlineCode(tool)]) : markdownInline(value);
549
550
  }
550
551
 
551
552
  function markdownInlineCode(value: string): string {
@@ -3,7 +3,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { definePage } from '@zhin.js/console-contract';
4
4
  import SandboxChat from './SandboxChat';
5
5
  export const meta = definePage({
6
- title: 'Agent 试验台',
6
+ title: '试聊一下',
7
+ titleI18n: { en: 'Try a conversation' },
7
8
  icon: 'Box',
8
9
  order: 10,
9
10
  });
@@ -2,7 +2,8 @@ import { definePage } from '@zhin.js/console-contract';
2
2
  import SandboxChat from './SandboxChat';
3
3
 
4
4
  export const meta = definePage({
5
- title: 'Agent 试验台',
5
+ title: '试聊一下',
6
+ titleI18n: { en: 'Try a conversation' },
6
7
  icon: 'Box',
7
8
  order: 10,
8
9
  });
@@ -0,0 +1,227 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ /** Authored interface copy only; unknown/user text is returned unchanged. */
3
+ export const sandboxEnglish = {
4
+ "当前用户": "Current user",
5
+ "审阅者": "Reviewer",
6
+ "协作者": "Collaborator",
7
+ "当前 Token 只有演示权限,任务运行已禁用。": "This token has demo access only. Task execution is disabled.",
8
+ "未检测到隔离执行环境": "No isolated execution environment detected",
9
+ "Sandbox 拒绝了本次操作": "Sandbox rejected this operation",
10
+ "会话 {0}": "Conversation {0}",
11
+ "群组场景 {0}": "Group scenario {0}",
12
+ "频道场景 {0}": "Channel scenario {0}",
13
+ "Sandbox 连接尚未就绪,审批选择未发送。": "Sandbox is not connected. Your approval choice was not sent.",
14
+ "审批选择发送失败,请等待连接恢复后重试。": "Could not send your approval choice. Retry after the connection recovers.",
15
+ "Agent Trace 暂不可用": "Agent Trace is temporarily unavailable",
16
+ "点数 {0}": "Rolled {0}",
17
+ "骰子": "Dice",
18
+ "结果 {0}": "Result {0}",
19
+ "猜拳": "Rock, paper, scissors",
20
+ "[图片]": "[Image]",
21
+ "[视频无地址]": "[Video URL missing]",
22
+ "[音频无地址]": "[Audio URL missing]",
23
+ "↩ 引用消息 #": "↩ Quoted message #",
24
+ "聊天记录": "Chat history",
25
+ "…共": "…total",
26
+ "条": "messages",
27
+ "[合并转发]": "[Forwarded messages]",
28
+ "已提交本次选择": "Your choice was submitted",
29
+ "测试用户": "Test user",
30
+ "未命名试验": "Untitled experiment",
31
+ "单用户": "Single user",
32
+ "群组上下文": "Group context",
33
+ "频道上下文": "Channel context",
34
+ "已发送停止请求,正在等待任务结束。": "Stop requested. Waiting for the task to finish.",
35
+ "当前会话没有运行中的任务。": "No running task in this conversation.",
36
+ "无法停止任务": "Could not stop the task",
37
+ "停止中": "Stopping",
38
+ "停止": "Stop",
39
+ "重试": "Retry",
40
+ "导出 Markdown 运行报告": "Export Markdown run report",
41
+ "导出": "Export",
42
+ "耗时": "Duration",
43
+ "进行中": "In progress",
44
+ "步骤": "Steps",
45
+ "工具": "Tools",
46
+ "异常": "Problems",
47
+ "正在等待第一条运行事件…": "Waiting for the first run event…",
48
+ "收起步骤": "Collapse steps",
49
+ "查看 {0} 个步骤": "View {0} steps",
50
+ "{0} 个变更与产物": "{0} changes and artifacts",
51
+ "打开运行检查器": "Open run inspector",
52
+ "测试会话": "Test conversations",
53
+ "试聊一下": "Try a conversation",
54
+ "检查器": "Inspector",
55
+ "Sandbox WebSocket 已连接": "Sandbox WebSocket connected",
56
+ "正在重连 Sandbox WebSocket": "Reconnecting Sandbox WebSocket",
57
+ "单用户作用域": "Single-user scope",
58
+ "群组作用域": "Group scope",
59
+ "频道作用域": "Channel scope",
60
+ "会话名称": "Conversation name",
61
+ "消息作用域": "Message scope",
62
+ "群组": "Group",
63
+ "频道": "Channel",
64
+ "取消": "Cancel",
65
+ "创建": "Create",
66
+ "新建测试会话": "New test conversation",
67
+ "会话已持久化": "Conversation saved",
68
+ "会话保存失败": "Could not save conversation",
69
+ "{0} 条消息": "{0} messages",
70
+ "停止当前任务": "Stop current task",
71
+ "重新运行上一个任务": "Rerun previous task",
72
+ "配置运行环境": "Configure run environment",
73
+ "切换运行检查器": "Toggle run inspector",
74
+ "清空当前会话": "Clear current conversation",
75
+ "清空当前测试记录?": "Clear the current test history?",
76
+ "只移除“": "Only messages from “",
77
+ "”在浏览器中的消息,不影响 Agent 会话存储。": "” in this browser are removed. Agent conversation storage is unchanged.",
78
+ "确认清空": "Clear history",
79
+ "运行暂不可用": "Execution unavailable",
80
+ "知道了": "Got it",
81
+ "运行配置": "Run configuration",
82
+ "工作目录": "Working directory",
83
+ "使用 Host 项目目录": "Use the Host project directory",
84
+ "安全策略": "Security policy",
85
+ "只读": "Read only",
86
+ "工作区写入": "Workspace write",
87
+ "完全访问": "Full access",
88
+ "审批策略": "Approval policy",
89
+ "按需确认": "Ask when needed",
90
+ "审核 Agent 自动判断": "Review Agent decides automatically",
91
+ "绕过审批": "Bypass approval",
92
+ "网络访问": "Network access",
93
+ "完全访问允许 Agent 操作工作目录之外的文件并访问网络,请仅用于可信任务。": "Full access lets the Agent modify files outside the working directory and access the network. Use it only for trusted tasks.",
94
+ "安全 Shell 需要可用的 Docker daemon;当前仅文件工具可运行。": "Secure shell requires an available Docker daemon. Only file tools can run at present.",
95
+ "Agent 对话": "Agent conversation",
96
+ "开始一次可观察的 Agent 运行": "Start an observable Agent run",
97
+ "发送任务后,回复、工具调用、Token 与异常会在同一会话上下文中关联。": "Replies, tool calls, tokens and problems are linked within the same conversation context.",
98
+ "介绍当前 Agent 可以使用的能力,并给出三个具体示例。": "Introduce the capabilities available to this Agent and give three concrete examples.",
99
+ "探索可用能力": "Explore available capabilities",
100
+ "用 Markdown 表格总结当前运行环境,并附上一段 TypeScript 示例代码。": "Summarize the current environment in a Markdown table and include a TypeScript code example.",
101
+ "测试富文本输出": "Test rich text output",
102
+ "分析一个任务从推理、工具调用到最终回复的完整执行路径。": "Analyze the full path of a task, from reasoning and tool calls to the final reply.",
103
+ "观察执行路径": "Observe execution",
104
+ "需要你的确认": "Your confirmation is required",
105
+ "你": "You",
106
+ "任务输入": "Task input",
107
+ "插入表情": "Insert emoji",
108
+ "插入图片 URL": "Insert image URL",
109
+ "插入视频 URL": "Insert video URL",
110
+ "插入音频 URL": "Insert audio URL",
111
+ "消息编辑模式": "Message editor mode",
112
+ "编写": "Write",
113
+ "预览": "Preview",
114
+ "清空输入": "Clear input",
115
+ "搜索表情...": "Search emoji…",
116
+ "未找到匹配的表情": "No matching emoji",
117
+ "支持 http(s) 图片链接或 data URL": "Supports HTTP(S) image links or data URLs",
118
+ "支持浏览器可解码的视频直链(如 .mp4、.webm)": "Supports direct links to browser-decodable video (such as .mp4 and .webm)",
119
+ "支持 .mp3、.ogg、.wav 等音频直链": "Supports direct links to .mp3, .ogg, .wav and other audio",
120
+ "图片 URL…": "Image URL…",
121
+ "视频 URL…": "Video URL…",
122
+ "音频 URL…": "Audio URL…",
123
+ "插入到输入框": "Insert into editor",
124
+ "向 {0} 发送消息,支持 Markdown...": "Message {0}; Markdown is supported…",
125
+ "输入 Markdown 后可在这里检查最终效果": "Enter Markdown to preview the final result here",
126
+ "未找到匹配的用户": "No matching users",
127
+ "发送": "Send",
128
+ "快捷操作:": "Shortcuts:",
129
+ "换行": "New line",
130
+ "代码块": "Code block",
131
+ "**文本**": "**text**",
132
+ "加粗": "Bold",
133
+ "[@名称]": "[@name]",
134
+ "@某人": "@someone",
135
+ "运行检查器": "Run inspector",
136
+ "刷新 Agent Trace": "Refresh Agent Trace",
137
+ "关闭运行检查器": "Close run inspector",
138
+ "检查器视图": "Inspector view",
139
+ "任务": "Tasks",
140
+ "变更与产物": "Changes and artifacts",
141
+ "运行概览": "Run overview",
142
+ "事件": "Events",
143
+ "上下文": "Context",
144
+ "任务历史": "Task history",
145
+ "运行任务后会在这里形成可回溯记录": "Task runs will appear here for review",
146
+ "最近执行": "Recent execution",
147
+ "发送任务后显示推理与工具轨迹": "Reasoning and tool traces appear after you send a task",
148
+ "文件与命令产物": "File and command artifacts",
149
+ "暂无输出": "No output yet",
150
+ "等待结果": "Waiting for a result",
151
+ "Agent 修改文件、执行命令或测试后,产物会集中出现在这里": "Artifacts appear here when the Agent modifies files, runs commands or executes tests",
152
+ "在 Agent Studio 中完整诊断": "Open full diagnostics in Agent Studio",
153
+ "Agent 运行中": "Agent is running",
154
+ "最近任务已完成": "Latest task completed",
155
+ "最近任务失败": "Latest task failed",
156
+ "最近任务已取消": "Latest task cancelled",
157
+ "完成": "Done",
158
+ "已拒绝": "Denied",
159
+ "已取消": "Cancelled",
160
+ "失败": "Failed",
161
+ "输入消息...": "Type a message…",
162
+ "📹 视频": "📹 Video",
163
+ "🎵 音频": "🎵 Audio",
164
+ "HTML 消息": "HTML message",
165
+ "写入文件": "Write file",
166
+ "编辑文件": "Edit file",
167
+ "接收任务": "Receive task",
168
+ "准备运行能力": "Prepare capabilities",
169
+ "推理迭代 {0}": "Reasoning iteration {0}",
170
+ "上限 {0}": "Limit {0}",
171
+ "运行 {0}": "Run {0}",
172
+ "委派 {0}": "Delegate {0}",
173
+ "子 Agent": "Sub-agent",
174
+ "子 Agent 失败": "Sub-agent failed",
175
+ "子 Agent 返回": "Sub-agent returned",
176
+ "任务完成": "Task completed",
177
+ "Agent 已返回结果": "Agent returned a result",
178
+ "任务已停止": "Task stopped",
179
+ "达到预算上限": "Budget limit reached",
180
+ "任务失败": "Task failed",
181
+ "等待 Agent 返回": "Waiting for the Agent",
182
+ "任务仍在运行": "Task is still running",
183
+ "无运行记录": "No run history",
184
+ "# Agent 运行报告": "# Agent run report",
185
+ "- **会话:** {0}": "- **Conversation:** {0}",
186
+ "未命名会话": "Untitled conversation",
187
+ "- **任务 ID:** {0}": "- **Task ID:** {0}",
188
+ "- **状态:** {0}": "- **Status:** {0}",
189
+ "- **开始时间:** {0}": "- **Started:** {0}",
190
+ "- **耗时:** {0}": "- **Duration:** {0}",
191
+ "- **工作目录:** {0}": "- **Working directory:** {0}",
192
+ "- **安全策略:** {0} / {1} / network {2}": "- **Security policy:** {0} / {1} / network {2}",
193
+ "- **用量:** {0} tools / {1} tokens / {2} problems": "- **Usage:** {0} tools / {1} tokens / {2} problems",
194
+ "## 任务": "## Task",
195
+ "## 执行轨迹": "## Execution trace",
196
+ "- 暂无可用轨迹": "- No trace available",
197
+ "## 变更与产物": "## Changes and artifacts",
198
+ "- 本次运行没有文件、命令或测试产物。": "- This run produced no file, command or test artifacts.",
199
+ "- 类型:{0}": "- Kind: {0}",
200
+ "- 状态:{0}": "- Status: {0}",
201
+ "- 路径:{0}": "- Path: {0}",
202
+ "- 耗时:{0} ms": "- Duration: {0} ms",
203
+ "由 Zhin「试聊一下」于 {0} 导出。": "Exported from Zhin “Try a conversation” at {0}.",
204
+ "开始处理": "Start processing",
205
+ "能力已解析": "Capabilities resolved",
206
+ "模型思考": "Model reasoning",
207
+ "调用 {0}": "Call {0}",
208
+ "{0} 完成": "{0} completed",
209
+ "{0} 被拒绝": "{0} denied",
210
+ "{0} 失败": "{0} failed",
211
+ "{0} 连接": "{0} connected",
212
+ "子 Agent 更新": "Sub-agent update",
213
+ "本轮完成": "Turn completed",
214
+ "本轮取消": "Turn cancelled",
215
+ "执行失败": "Execution failed",
216
+ "Agent Trace 尚未启用": "Agent Trace is not enabled",
217
+ "无法读取 Agent Trace": "Could not read Agent Trace",
218
+ "无法停止 Agent 任务": "Could not stop the Agent task",
219
+ "输入 {0} · 输出 {1}": "Input {0} · output {1}",
220
+ "执行完成": "Execution completed",
221
+ "运行中": "Running",
222
+ "已完成": "Completed"
223
+ };
224
+ export function sandboxText(locale, message, values = []) {
225
+ const text = locale === 'en' && Object.hasOwn(sandboxEnglish, message) ? sandboxEnglish[message] : message;
226
+ return text.replace(/\{(\d+)\}/gu, (slot, index) => Number(index) < values.length ? String(values[Number(index)]) : slot);
227
+ }