@zhin.js/adapter-sandbox 1.1.36 → 1.2.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.
@@ -367,7 +367,7 @@ export async function fetchAgentTrace(sessionKey, afterSequence = 0, locale = 'z
367
367
  url.searchParams.set('after', String(afterSequence));
368
368
  const response = await fetch(url, { headers: getSandboxAuthHeaders(), signal });
369
369
  const body = await response.json().catch(() => ({}));
370
- if (!response.ok || body.success === false || !body.data) {
370
+ if (!response.ok || body.success === false || !body.data || !Array.isArray(body.data.events)) {
371
371
  throw new Error(response.status === 503
372
372
  ? sandboxText(locale, "Agent Trace 尚未启用")
373
373
  : body.error || sandboxText(locale, "无法读取 Agent Trace"));
@@ -451,7 +451,7 @@ export async function fetchAgentTrace(sessionKey: string, afterSequence = 0, loc
451
451
  if (afterSequence > 0) url.searchParams.set('after', String(afterSequence));
452
452
  const response = await fetch(url, { headers: getSandboxAuthHeaders(), signal });
453
453
  const body = await response.json().catch(() => ({})) as { success?: boolean; data?: AgentTraceSnapshot; error?: string };
454
- if (!response.ok || body.success === false || !body.data) {
454
+ if (!response.ok || body.success === false || !body.data || !Array.isArray(body.data.events)) {
455
455
  throw new Error(response.status === 503
456
456
  ? sandboxText(locale, "Agent Trace 尚未启用")
457
457
  : body.error || sandboxText(locale, "无法读取 Agent Trace"));
@@ -38,3 +38,31 @@ export function prependResultPage(previous, earlier) {
38
38
  rows.set(result.turnId, result);
39
39
  return { ...earlier, results: [...rows.values()].sort((a, b) => a.completedAt - b.completedAt || a.turnId.localeCompare(b.turnId)) };
40
40
  }
41
+ /**
42
+ * Why one sent message got (or did not get) a reply: `null` on a Host without the route,
43
+ * `undefined` while the message is still being processed (not settled yet).
44
+ */
45
+ export async function readMessageOutcome(connectionId, sessionKey, messageId, locale, signal, context = captureSandboxRequestContext()) {
46
+ const url = new URL('/api/conversations/outcomes', `${context.apiBase || window.location.origin}/`);
47
+ url.searchParams.set('connectionId', connectionId);
48
+ url.searchParams.set('sessionKey', sessionKey);
49
+ url.searchParams.set('messageId', messageId);
50
+ url.searchParams.set('locale', locale);
51
+ const response = await fetch(url, { headers: context.headers, cache: 'no-store', signal });
52
+ if (response.status === 404 || response.status === 405)
53
+ return null;
54
+ const body = await response.json();
55
+ if (!response.ok || !body.success || !body.data)
56
+ throw new Error(body.error || `Outcome read failed (${response.status})`);
57
+ return body.data.outcomes?.[0];
58
+ }
59
+ /**
60
+ * The notice for a message nobody answered: only outcomes with no chat reply by design
61
+ * (`reply: 'no'`), with the code and reason so the run log and the trace can be matched.
62
+ */
63
+ export function quietOutcomeNotice(outcome, locale = 'zh-CN') {
64
+ if (!outcome || outcome.reply !== 'no')
65
+ return null;
66
+ const code = `${outcome.outcome}${outcome.reason ? ` · ${outcome.reason}` : ''}`;
67
+ return locale === 'en' ? `${outcome.text} (${code})` : `${outcome.text}(${code})`;
68
+ }
@@ -66,3 +66,44 @@ export function prependResultPage(previous: RecoveredResultPage, earlier: Recove
66
66
  for (const result of earlier.results) if (!rows.has(result.turnId)) rows.set(result.turnId, result);
67
67
  return { ...earlier, results: [...rows.values()].sort((a, b) => a.completedAt - b.completedAt || a.turnId.localeCompare(b.turnId)) };
68
68
  }
69
+
70
+ /** One settled inbound outcome (ADR 0061) as `GET /api/conversations/outcomes` returns it (#1250). */
71
+ export interface ConversationOutcome {
72
+ readonly id: string;
73
+ readonly messageId?: string;
74
+ readonly settledAt: number;
75
+ readonly outcome: string;
76
+ readonly reason?: string;
77
+ readonly stage: string;
78
+ readonly addressed: boolean;
79
+ readonly reply: 'yes' | 'no' | 'throttled';
80
+ readonly text: string;
81
+ }
82
+
83
+ /**
84
+ * Why one sent message got (or did not get) a reply: `null` on a Host without the route,
85
+ * `undefined` while the message is still being processed (not settled yet).
86
+ */
87
+ export async function readMessageOutcome(connectionId: string, sessionKey: string, messageId: string, locale: 'zh-CN' | 'en',
88
+ signal?: AbortSignal, context: SandboxRequestContext = captureSandboxRequestContext()): Promise<ConversationOutcome | null | undefined> {
89
+ const url = new URL('/api/conversations/outcomes', `${context.apiBase || window.location.origin}/`);
90
+ url.searchParams.set('connectionId', connectionId);
91
+ url.searchParams.set('sessionKey', sessionKey);
92
+ url.searchParams.set('messageId', messageId);
93
+ url.searchParams.set('locale', locale);
94
+ const response = await fetch(url, { headers: context.headers, cache: 'no-store', signal });
95
+ if (response.status === 404 || response.status === 405) return null;
96
+ const body = await response.json() as { success?: boolean; data?: { outcomes?: readonly ConversationOutcome[] }; error?: string };
97
+ if (!response.ok || !body.success || !body.data) throw new Error(body.error || `Outcome read failed (${response.status})`);
98
+ return body.data.outcomes?.[0];
99
+ }
100
+
101
+ /**
102
+ * The notice for a message nobody answered: only outcomes with no chat reply by design
103
+ * (`reply: 'no'`), with the code and reason so the run log and the trace can be matched.
104
+ */
105
+ export function quietOutcomeNotice(outcome: ConversationOutcome | null | undefined, locale: 'zh-CN' | 'en' = 'zh-CN'): string | null {
106
+ if (!outcome || outcome.reply !== 'no') return null;
107
+ const code = `${outcome.outcome}${outcome.reason ? ` · ${outcome.reason}` : ''}`;
108
+ return locale === 'en' ? `${outcome.text} (${code})` : `${outcome.text}(${code})`;
109
+ }
@@ -7,6 +7,8 @@ export const meta = definePage({
7
7
  titleI18n: { en: 'Conversations' },
8
8
  icon: 'Box',
9
9
  order: 10,
10
+ // ADR 0063 决策 2: the one workspace page that fills the content area; the header stays the shell's.
11
+ fullWidth: true,
10
12
  });
11
13
  /**
12
14
  * Convention page entry (ADR 0046).
@@ -6,6 +6,8 @@ export const meta = definePage({
6
6
  titleI18n: { en: 'Conversations' },
7
7
  icon: 'Box',
8
8
  order: 10,
9
+ // ADR 0063 决策 2: the one workspace page that fills the content area; the header stays the shell's.
10
+ fullWidth: true,
9
11
  });
10
12
 
11
13
  /**
@@ -260,7 +260,8 @@ export const sandboxEnglish = {
260
260
  "输入 {0} · 输出 {1}": "Input {0} · output {1}",
261
261
  "执行完成": "Execution completed",
262
262
  "运行中": "Running",
263
- "已完成": "Completed"
263
+ "已完成": "Completed",
264
+ "这条消息没有回复:": "No reply to this message: "
264
265
  };
265
266
  export function sandboxText(locale, message, values = []) {
266
267
  const text = locale === 'en' && Object.hasOwn(sandboxEnglish, message) ? sandboxEnglish[message] : message;
@@ -261,7 +261,8 @@ export const sandboxEnglish: Readonly<Record<string, string>> = {
261
261
  "输入 {0} · 输出 {1}": "Input {0} · output {1}",
262
262
  "执行完成": "Execution completed",
263
263
  "运行中": "Running",
264
- "已完成": "Completed"
264
+ "已完成": "Completed",
265
+ "这条消息没有回复:": "No reply to this message: "
265
266
  };
266
267
 
267
268
  export function sandboxText(locale: SandboxLocale, message: string, values: readonly unknown[] = []): string {