@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.
@@ -0,0 +1,229 @@
1
+ export type SandboxLocale = 'zh-CN' | 'en';
2
+
3
+ /** Authored interface copy only; unknown/user text is returned unchanged. */
4
+ export const sandboxEnglish: Readonly<Record<string, string>> = {
5
+ "当前用户": "Current user",
6
+ "审阅者": "Reviewer",
7
+ "协作者": "Collaborator",
8
+ "当前 Token 只有演示权限,任务运行已禁用。": "This token has demo access only. Task execution is disabled.",
9
+ "未检测到隔离执行环境": "No isolated execution environment detected",
10
+ "Sandbox 拒绝了本次操作": "Sandbox rejected this operation",
11
+ "会话 {0}": "Conversation {0}",
12
+ "群组场景 {0}": "Group scenario {0}",
13
+ "频道场景 {0}": "Channel scenario {0}",
14
+ "Sandbox 连接尚未就绪,审批选择未发送。": "Sandbox is not connected. Your approval choice was not sent.",
15
+ "审批选择发送失败,请等待连接恢复后重试。": "Could not send your approval choice. Retry after the connection recovers.",
16
+ "Agent Trace 暂不可用": "Agent Trace is temporarily unavailable",
17
+ "点数 {0}": "Rolled {0}",
18
+ "骰子": "Dice",
19
+ "结果 {0}": "Result {0}",
20
+ "猜拳": "Rock, paper, scissors",
21
+ "[图片]": "[Image]",
22
+ "[视频无地址]": "[Video URL missing]",
23
+ "[音频无地址]": "[Audio URL missing]",
24
+ "↩ 引用消息 #": "↩ Quoted message #",
25
+ "聊天记录": "Chat history",
26
+ "…共": "…total",
27
+ "条": "messages",
28
+ "[合并转发]": "[Forwarded messages]",
29
+ "已提交本次选择": "Your choice was submitted",
30
+ "测试用户": "Test user",
31
+ "未命名试验": "Untitled experiment",
32
+ "单用户": "Single user",
33
+ "群组上下文": "Group context",
34
+ "频道上下文": "Channel context",
35
+ "已发送停止请求,正在等待任务结束。": "Stop requested. Waiting for the task to finish.",
36
+ "当前会话没有运行中的任务。": "No running task in this conversation.",
37
+ "无法停止任务": "Could not stop the task",
38
+ "停止中": "Stopping",
39
+ "停止": "Stop",
40
+ "重试": "Retry",
41
+ "导出 Markdown 运行报告": "Export Markdown run report",
42
+ "导出": "Export",
43
+ "耗时": "Duration",
44
+ "进行中": "In progress",
45
+ "步骤": "Steps",
46
+ "工具": "Tools",
47
+ "异常": "Problems",
48
+ "正在等待第一条运行事件…": "Waiting for the first run event…",
49
+ "收起步骤": "Collapse steps",
50
+ "查看 {0} 个步骤": "View {0} steps",
51
+ "{0} 个变更与产物": "{0} changes and artifacts",
52
+ "打开运行检查器": "Open run inspector",
53
+ "测试会话": "Test conversations",
54
+ "试聊一下": "Try a conversation",
55
+ "检查器": "Inspector",
56
+ "Sandbox WebSocket 已连接": "Sandbox WebSocket connected",
57
+ "正在重连 Sandbox WebSocket": "Reconnecting Sandbox WebSocket",
58
+ "单用户作用域": "Single-user scope",
59
+ "群组作用域": "Group scope",
60
+ "频道作用域": "Channel scope",
61
+ "会话名称": "Conversation name",
62
+ "消息作用域": "Message scope",
63
+ "群组": "Group",
64
+ "频道": "Channel",
65
+ "取消": "Cancel",
66
+ "创建": "Create",
67
+ "新建测试会话": "New test conversation",
68
+ "会话已持久化": "Conversation saved",
69
+ "会话保存失败": "Could not save conversation",
70
+ "{0} 条消息": "{0} messages",
71
+ "停止当前任务": "Stop current task",
72
+ "重新运行上一个任务": "Rerun previous task",
73
+ "配置运行环境": "Configure run environment",
74
+ "切换运行检查器": "Toggle run inspector",
75
+ "清空当前会话": "Clear current conversation",
76
+ "清空当前测试记录?": "Clear the current test history?",
77
+ "只移除“": "Only messages from “",
78
+ "”在浏览器中的消息,不影响 Agent 会话存储。": "” in this browser are removed. Agent conversation storage is unchanged.",
79
+ "确认清空": "Clear history",
80
+ "运行暂不可用": "Execution unavailable",
81
+ "知道了": "Got it",
82
+ "运行配置": "Run configuration",
83
+ "工作目录": "Working directory",
84
+ "使用 Host 项目目录": "Use the Host project directory",
85
+ "安全策略": "Security policy",
86
+ "只读": "Read only",
87
+ "工作区写入": "Workspace write",
88
+ "完全访问": "Full access",
89
+ "审批策略": "Approval policy",
90
+ "按需确认": "Ask when needed",
91
+ "审核 Agent 自动判断": "Review Agent decides automatically",
92
+ "绕过审批": "Bypass approval",
93
+ "网络访问": "Network access",
94
+ "完全访问允许 Agent 操作工作目录之外的文件并访问网络,请仅用于可信任务。": "Full access lets the Agent modify files outside the working directory and access the network. Use it only for trusted tasks.",
95
+ "安全 Shell 需要可用的 Docker daemon;当前仅文件工具可运行。": "Secure shell requires an available Docker daemon. Only file tools can run at present.",
96
+ "Agent 对话": "Agent conversation",
97
+ "开始一次可观察的 Agent 运行": "Start an observable Agent run",
98
+ "发送任务后,回复、工具调用、Token 与异常会在同一会话上下文中关联。": "Replies, tool calls, tokens and problems are linked within the same conversation context.",
99
+ "介绍当前 Agent 可以使用的能力,并给出三个具体示例。": "Introduce the capabilities available to this Agent and give three concrete examples.",
100
+ "探索可用能力": "Explore available capabilities",
101
+ "用 Markdown 表格总结当前运行环境,并附上一段 TypeScript 示例代码。": "Summarize the current environment in a Markdown table and include a TypeScript code example.",
102
+ "测试富文本输出": "Test rich text output",
103
+ "分析一个任务从推理、工具调用到最终回复的完整执行路径。": "Analyze the full path of a task, from reasoning and tool calls to the final reply.",
104
+ "观察执行路径": "Observe execution",
105
+ "需要你的确认": "Your confirmation is required",
106
+ "你": "You",
107
+ "任务输入": "Task input",
108
+ "插入表情": "Insert emoji",
109
+ "插入图片 URL": "Insert image URL",
110
+ "插入视频 URL": "Insert video URL",
111
+ "插入音频 URL": "Insert audio URL",
112
+ "消息编辑模式": "Message editor mode",
113
+ "编写": "Write",
114
+ "预览": "Preview",
115
+ "清空输入": "Clear input",
116
+ "搜索表情...": "Search emoji…",
117
+ "未找到匹配的表情": "No matching emoji",
118
+ "支持 http(s) 图片链接或 data URL": "Supports HTTP(S) image links or data URLs",
119
+ "支持浏览器可解码的视频直链(如 .mp4、.webm)": "Supports direct links to browser-decodable video (such as .mp4 and .webm)",
120
+ "支持 .mp3、.ogg、.wav 等音频直链": "Supports direct links to .mp3, .ogg, .wav and other audio",
121
+ "图片 URL…": "Image URL…",
122
+ "视频 URL…": "Video URL…",
123
+ "音频 URL…": "Audio URL…",
124
+ "插入到输入框": "Insert into editor",
125
+ "向 {0} 发送消息,支持 Markdown...": "Message {0}; Markdown is supported…",
126
+ "输入 Markdown 后可在这里检查最终效果": "Enter Markdown to preview the final result here",
127
+ "未找到匹配的用户": "No matching users",
128
+ "发送": "Send",
129
+ "快捷操作:": "Shortcuts:",
130
+ "换行": "New line",
131
+ "代码块": "Code block",
132
+ "**文本**": "**text**",
133
+ "加粗": "Bold",
134
+ "[@名称]": "[@name]",
135
+ "@某人": "@someone",
136
+ "运行检查器": "Run inspector",
137
+ "刷新 Agent Trace": "Refresh Agent Trace",
138
+ "关闭运行检查器": "Close run inspector",
139
+ "检查器视图": "Inspector view",
140
+ "任务": "Tasks",
141
+ "变更与产物": "Changes and artifacts",
142
+ "运行概览": "Run overview",
143
+ "事件": "Events",
144
+ "上下文": "Context",
145
+ "任务历史": "Task history",
146
+ "运行任务后会在这里形成可回溯记录": "Task runs will appear here for review",
147
+ "最近执行": "Recent execution",
148
+ "发送任务后显示推理与工具轨迹": "Reasoning and tool traces appear after you send a task",
149
+ "文件与命令产物": "File and command artifacts",
150
+ "暂无输出": "No output yet",
151
+ "等待结果": "Waiting for a result",
152
+ "Agent 修改文件、执行命令或测试后,产物会集中出现在这里": "Artifacts appear here when the Agent modifies files, runs commands or executes tests",
153
+ "在 Agent Studio 中完整诊断": "Open full diagnostics in Agent Studio",
154
+ "Agent 运行中": "Agent is running",
155
+ "最近任务已完成": "Latest task completed",
156
+ "最近任务失败": "Latest task failed",
157
+ "最近任务已取消": "Latest task cancelled",
158
+ "完成": "Done",
159
+ "已拒绝": "Denied",
160
+ "已取消": "Cancelled",
161
+ "失败": "Failed",
162
+ "输入消息...": "Type a message…",
163
+ "📹 视频": "📹 Video",
164
+ "🎵 音频": "🎵 Audio",
165
+ "HTML 消息": "HTML message",
166
+ "写入文件": "Write file",
167
+ "编辑文件": "Edit file",
168
+ "接收任务": "Receive task",
169
+ "准备运行能力": "Prepare capabilities",
170
+ "推理迭代 {0}": "Reasoning iteration {0}",
171
+ "上限 {0}": "Limit {0}",
172
+ "运行 {0}": "Run {0}",
173
+ "委派 {0}": "Delegate {0}",
174
+ "子 Agent": "Sub-agent",
175
+ "子 Agent 失败": "Sub-agent failed",
176
+ "子 Agent 返回": "Sub-agent returned",
177
+ "任务完成": "Task completed",
178
+ "Agent 已返回结果": "Agent returned a result",
179
+ "任务已停止": "Task stopped",
180
+ "达到预算上限": "Budget limit reached",
181
+ "任务失败": "Task failed",
182
+ "等待 Agent 返回": "Waiting for the Agent",
183
+ "任务仍在运行": "Task is still running",
184
+ "无运行记录": "No run history",
185
+ "# Agent 运行报告": "# Agent run report",
186
+ "- **会话:** {0}": "- **Conversation:** {0}",
187
+ "未命名会话": "Untitled conversation",
188
+ "- **任务 ID:** {0}": "- **Task ID:** {0}",
189
+ "- **状态:** {0}": "- **Status:** {0}",
190
+ "- **开始时间:** {0}": "- **Started:** {0}",
191
+ "- **耗时:** {0}": "- **Duration:** {0}",
192
+ "- **工作目录:** {0}": "- **Working directory:** {0}",
193
+ "- **安全策略:** {0} / {1} / network {2}": "- **Security policy:** {0} / {1} / network {2}",
194
+ "- **用量:** {0} tools / {1} tokens / {2} problems": "- **Usage:** {0} tools / {1} tokens / {2} problems",
195
+ "## 任务": "## Task",
196
+ "## 执行轨迹": "## Execution trace",
197
+ "- 暂无可用轨迹": "- No trace available",
198
+ "## 变更与产物": "## Changes and artifacts",
199
+ "- 本次运行没有文件、命令或测试产物。": "- This run produced no file, command or test artifacts.",
200
+ "- 类型:{0}": "- Kind: {0}",
201
+ "- 状态:{0}": "- Status: {0}",
202
+ "- 路径:{0}": "- Path: {0}",
203
+ "- 耗时:{0} ms": "- Duration: {0} ms",
204
+ "由 Zhin「试聊一下」于 {0} 导出。": "Exported from Zhin “Try a conversation” at {0}.",
205
+ "开始处理": "Start processing",
206
+ "能力已解析": "Capabilities resolved",
207
+ "模型思考": "Model reasoning",
208
+ "调用 {0}": "Call {0}",
209
+ "{0} 完成": "{0} completed",
210
+ "{0} 被拒绝": "{0} denied",
211
+ "{0} 失败": "{0} failed",
212
+ "{0} 连接": "{0} connected",
213
+ "子 Agent 更新": "Sub-agent update",
214
+ "本轮完成": "Turn completed",
215
+ "本轮取消": "Turn cancelled",
216
+ "执行失败": "Execution failed",
217
+ "Agent Trace 尚未启用": "Agent Trace is not enabled",
218
+ "无法读取 Agent Trace": "Could not read Agent Trace",
219
+ "无法停止 Agent 任务": "Could not stop the Agent task",
220
+ "输入 {0} · 输出 {1}": "Input {0} · output {1}",
221
+ "执行完成": "Execution completed",
222
+ "运行中": "Running",
223
+ "已完成": "Completed"
224
+ };
225
+
226
+ export function sandboxText(locale: SandboxLocale, message: string, values: readonly unknown[] = []): string {
227
+ const text = locale === 'en' && Object.hasOwn(sandboxEnglish, message) ? sandboxEnglish[message]! : message;
228
+ return text.replace(/\{(\d+)\}/gu, (slot, index: string) => Number(index) < values.length ? String(values[Number(index)]) : slot);
229
+ }
package/schema.json CHANGED
@@ -8,7 +8,12 @@
8
8
  "string",
9
9
  "number"
10
10
  ],
11
- "description": "框架 master(sandbox client id (distinct from endpoints[].owner);AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖"
11
+ "description": "框架 master(sandbox client id (distinct from endpoints[].owner);AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖",
12
+ "x-i18n": {
13
+ "en": {
14
+ "description": "Framework masters (sandbox client id, distinct from endpoints[].owner; AI/tool permissions and endpoint management). endpoints[i].master can override this value."
15
+ }
16
+ }
12
17
  },
13
18
  "trusted": {
14
19
  "type": "array",
@@ -19,7 +24,12 @@
19
24
  ],
20
25
  "description": "Trusted sandbox client id (distinct from endpoints[].owner)"
21
26
  },
22
- "description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加"
27
+ "description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加",
28
+ "x-i18n": {
29
+ "en": {
30
+ "description": "Framework trusted users, below master authority. endpoints[i].trusted can add users."
31
+ }
32
+ }
23
33
  },
24
34
  "endpoints": {
25
35
  "type": "array",
@@ -33,7 +43,12 @@
33
43
  "string",
34
44
  "number"
35
45
  ],
36
- "description": "本 endpoint 的框架 master(sandbox client id (distinct from endpoints[].owner));覆盖顶层 master"
46
+ "description": "本 endpoint 的框架 master(sandbox client id (distinct from endpoints[].owner));覆盖顶层 master",
47
+ "x-i18n": {
48
+ "en": {
49
+ "description": "Framework masters for this endpoint (sandbox client id, distinct from endpoints[].owner), overriding the top-level master list."
50
+ }
51
+ }
37
52
  },
38
53
  "trusted": {
39
54
  "type": "array",
@@ -44,7 +59,12 @@
44
59
  ],
45
60
  "description": "Trusted sandbox client id (distinct from endpoints[].owner)"
46
61
  },
47
- "description": "本 endpoint 的 trusted 列表"
62
+ "description": "本 endpoint 的 trusted 列表",
63
+ "x-i18n": {
64
+ "en": {
65
+ "description": "Trusted users for this endpoint."
66
+ }
67
+ }
48
68
  },
49
69
  "owner": {
50
70
  "type": "string",
@@ -61,12 +81,22 @@
61
81
  "required": [
62
82
  "id"
63
83
  ]
84
+ },
85
+ "x-i18n": {
86
+ "en": {
87
+ "description": "Multiple accounts: mount multiple endpoints in one plugin instance. Each entry uses the top-level fields; id is required and other fields override defaults."
88
+ }
64
89
  }
65
90
  },
66
91
  "commandPrefix": {
67
92
  "type": "string",
68
93
  "default": "",
69
- "description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖"
94
+ "description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖",
95
+ "x-i18n": {
96
+ "en": {
97
+ "description": "Command prefix. The default empty string allows unprefixed commands; '/' requires a leading slash. Each endpoints[i] can override it."
98
+ }
99
+ }
70
100
  }
71
101
  },
72
102
  "required": [
package/src/endpoint.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { createMessages, resolveLocale, type Locale } from 'zhin.js/i18n';
1
2
  import { Endpoint, type EndpointSendRequest } from 'zhin.js/adapter';
2
3
  /**
3
4
  * SandboxWsEndpoint — WebSocket lifecycle and OutboundMessageService bridge for /sandbox.
@@ -111,7 +112,16 @@ export function createSandboxReadinessGate(probe: ShellIsolationProbe): Readonly
111
112
  });
112
113
  }
113
114
 
115
+ const messages = createMessages({
116
+ readOnly: { 'zh-CN': '当前连接是只读演示权限,不能运行 Agent 任务。', en: 'This connection is a read-only demo and cannot run Agent tasks.' },
117
+ connected: { 'zh-CN': '已连接 Sandbox「{target}」', en: 'Connected to Sandbox “{target}”' },
118
+ protocol: { 'zh-CN': '与 Node Host 控制台沙盒协议一致({path})', en: 'Using the Node Host Console sandbox protocol ({path})' },
119
+ profile: { 'zh-CN': '「试聊一下」会话已启用持久化运行配置。', en: 'The “Try a chat” session uses a persistent runtime profile.' },
120
+ });
121
+
114
122
  export interface SandboxEndpointOptions {
123
+ /** Project language captured from this endpoint generation's resources. */
124
+ readonly locale?: Locale;
115
125
  readonly id: CapabilityId;
116
126
  readonly http: HttpHost;
117
127
  readonly defaults: ResolvedSandboxBot;
@@ -126,6 +136,7 @@ export class SandboxWsEndpoint extends Endpoint<SandboxClient> {
126
136
  readonly #logger!: ReturnType<typeof getAdapterLogger>;
127
137
 
128
138
  readonly #options: SandboxEndpointOptions;
139
+ readonly #locale: Locale;
129
140
  readonly #connections = new Map<string, SandboxConnection>();
130
141
  readonly #readiness = createSandboxReadinessGate(probeShellIsolation);
131
142
  #wsHandleRelease?: () => void;
@@ -138,6 +149,7 @@ export class SandboxWsEndpoint extends Endpoint<SandboxClient> {
138
149
  super();
139
150
  this.#logger = getAdapterLogger('sandbox', options.defaults.id);
140
151
  this.#options = options;
152
+ this.#locale = resolveLocale(options.locale);
141
153
  this.client = new SandboxClient(
142
154
  () => this.#wsPath,
143
155
  () => [...this.#connections.values()].map((connection) => ({
@@ -283,7 +295,7 @@ export class SandboxWsEndpoint extends Endpoint<SandboxClient> {
283
295
  type: 'error',
284
296
  id: owner,
285
297
  endpoint: target,
286
- content: [{ type: 'text', data: { text: '当前连接是只读演示权限,不能运行 Agent 任务。' } }],
298
+ content: [{ type: 'text', data: { text: messages(this.#locale, 'readOnly') } }],
287
299
  timestamp: Date.now(),
288
300
  }));
289
301
  return;
@@ -354,6 +366,7 @@ export class SandboxWsEndpoint extends Endpoint<SandboxClient> {
354
366
  if (!current || current.socket !== socket) return;
355
367
  const readyPayload = JSON.stringify({
356
368
  type: 'ready',
369
+ locale: this.#locale,
357
370
  id: owner,
358
371
  endpoint: target,
359
372
  workingDirectory: process.cwd(),
@@ -363,9 +376,9 @@ export class SandboxWsEndpoint extends Endpoint<SandboxClient> {
363
376
  type: 'text',
364
377
  data: {
365
378
  text: [
366
- `已连接 Sandbox「${target}」`,
367
- `与 Node Host 控制台沙盒协议一致(${this.#wsPath})`,
368
- 'Agent 试验台会话已启用持久化运行配置。',
379
+ messages(this.#locale, 'connected', { target }),
380
+ messages(this.#locale, 'protocol', { path: this.#wsPath }),
381
+ messages(this.#locale, 'profile'),
369
382
  ].join('\n'),
370
383
  },
371
384
  }],