@kingsoftcloud/agentkit-harness-ui 0.0.29 → 0.0.30
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.
- package/dist/studio-client.mjs +95 -88
- package/package.json +2 -2
- package/src/engine-view/adapter.mjs +4 -1
- package/src/protocol.mjs +3 -1
- package/src/react-binding.mjs +20 -0
- package/src/reducer.mjs +8 -2
- package/src/styles.mjs +7 -0
- package/src/view.mjs +13 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingsoftcloud/agentkit-harness-ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Reusable React task-process UI for AgentKit Native: an explicitly versioned event protocol, a pure state reducer, and an accessible timeline. No Studio/DSH/Python imports; React is a peer dependency.",
|
|
@@ -99,6 +99,6 @@
|
|
|
99
99
|
"registry": "https://registry.npmjs.org"
|
|
100
100
|
},
|
|
101
101
|
"dependencies": {
|
|
102
|
-
"@kingsoftcloud/agentkit-harness-core": "0.0.
|
|
102
|
+
"@kingsoftcloud/agentkit-harness-core": "0.0.30"
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -98,10 +98,13 @@ export function engineEventToTimeline(event, { runId = "run", time, startedAt =
|
|
|
98
98
|
}
|
|
99
99
|
case "model.retry_scheduled":
|
|
100
100
|
return Number.isSafeInteger(event.retryAt) && event.retryAt > 0
|
|
101
|
-
? [{ v, id: id("model-wait"), type: "model.wait", retryAt: event.retryAt, httpStatus: event.httpStatus
|
|
101
|
+
? [{ v, id: id("model-wait"), type: "model.wait", retryAt: event.retryAt, httpStatus: event.httpStatus,
|
|
102
|
+
attempt: event.attempt, purpose: event.purpose }] : [];
|
|
102
103
|
case "model.retry_exhausted":
|
|
103
104
|
return [{ v, id: id("paused"), type: "task.state", state: "paused", reason: "provider_unavailable",
|
|
104
105
|
message: event.modelError }];
|
|
106
|
+
case "run.paused":
|
|
107
|
+
return [{ v, id: id("paused"), type: "task.state", state: "paused", reason: event.reason, message: event.modelError }];
|
|
105
108
|
case "run.terminal": {
|
|
106
109
|
const out = [];
|
|
107
110
|
const itemId = `${runId}:final`;
|
package/src/protocol.mjs
CHANGED
|
@@ -169,7 +169,9 @@ function normalizePayload(type, event) {
|
|
|
169
169
|
return { state: requiredChoice(event.state, TASK_STATES, "task state"), reason: str(event.reason) || null, message: str(event.message) || null };
|
|
170
170
|
case EventType.ModelWait:
|
|
171
171
|
if (!Number.isSafeInteger(event.retryAt) || event.retryAt <= 0) throw new TypeError('model wait requires a committed deadline');
|
|
172
|
-
return { retryAt: event.retryAt, ...(Number.isSafeInteger(event.httpStatus) ? { httpStatus: event.httpStatus } : {})
|
|
172
|
+
return { retryAt: event.retryAt, ...(Number.isSafeInteger(event.httpStatus) ? { httpStatus: event.httpStatus } : {}),
|
|
173
|
+
...(Number.isSafeInteger(event.attempt) && event.attempt > 0 ? { attempt: event.attempt } : {}),
|
|
174
|
+
...(event.purpose === 'compaction' ? { purpose: 'compaction' } : {}) };
|
|
173
175
|
case EventType.ModelRequest:
|
|
174
176
|
if (typeof event.active !== "boolean") throw new TypeError("model request requires an active flag");
|
|
175
177
|
return { active: event.active, itemId: str(event.itemId), ...(event.retry === true ? { retry: true } : {}),
|
package/src/react-binding.mjs
CHANGED
|
@@ -275,6 +275,9 @@ function renderTree(node, renderText, callbacks, React, reducedMotion, toolEleme
|
|
|
275
275
|
const { createElement } = React;
|
|
276
276
|
const testid = node.props?.["data-testid"];
|
|
277
277
|
const props = node.props || {};
|
|
278
|
+
if (testid === 'model-retry-countdown') return createElement(ModelRetryCountdown, {
|
|
279
|
+
key: props['data-retry-at'], retryAt: props['data-retry-at'], zh: props['data-retry-language'] === 'zh', React,
|
|
280
|
+
});
|
|
278
281
|
if (testid === 'user-image') return createElement(UserImage, { key: props['data-item-id'], image: props.image,
|
|
279
282
|
loadImage: callbacks.loadImage, id: props['data-item-id'] });
|
|
280
283
|
if (testid === 'tool-block' && toolElementCache?.has(node)) return toolElementCache.get(node);
|
|
@@ -335,6 +338,23 @@ function renderTree(node, renderText, callbacks, React, reducedMotion, toolEleme
|
|
|
335
338
|
return element;
|
|
336
339
|
}
|
|
337
340
|
|
|
341
|
+
function ModelRetryCountdown({ retryAt, zh, React }) {
|
|
342
|
+
const remaining = () => Math.max(0, Math.ceil((retryAt - Date.now()) / 1000));
|
|
343
|
+
const [seconds, setSeconds] = React.useState(remaining);
|
|
344
|
+
React.useEffect(() => {
|
|
345
|
+
let timer;
|
|
346
|
+
const update = () => {
|
|
347
|
+
const left = remaining();
|
|
348
|
+
setSeconds(left);
|
|
349
|
+
if (left > 0) timer = setTimeout(update, Math.max(1, retryAt - Date.now() - (left - 1) * 1000));
|
|
350
|
+
};
|
|
351
|
+
update();
|
|
352
|
+
return () => clearTimeout(timer);
|
|
353
|
+
}, [retryAt]);
|
|
354
|
+
return React.createElement('span', { 'data-testid': 'model-retry-countdown', 'aria-hidden': 'true' },
|
|
355
|
+
seconds ? (zh ? `${seconds} 秒后` : `in ${seconds}s`) : (zh ? '即将重试' : 'Retry due'));
|
|
356
|
+
}
|
|
357
|
+
|
|
338
358
|
function UserImage({ image, loadImage, id }) {
|
|
339
359
|
const { attachment, previewUrl } = image;
|
|
340
360
|
const [source, setSource] = useState(() => imagePreviewUrl(previewUrl ?? loadImage?.peek?.(attachment)));
|
package/src/reducer.mjs
CHANGED
|
@@ -35,6 +35,7 @@ export function initialState() {
|
|
|
35
35
|
verificationRequired: null,
|
|
36
36
|
modelRequestActive: false,
|
|
37
37
|
modelRequestRetry: false,
|
|
38
|
+
modelRetryAttempt: undefined,
|
|
38
39
|
modelRequestPurpose: null,
|
|
39
40
|
modelWait: null,
|
|
40
41
|
modelThinkingId: null,
|
|
@@ -91,11 +92,14 @@ function apply(state, e) {
|
|
|
91
92
|
case EventType.TaskState: return applyTaskState(state, e);
|
|
92
93
|
case EventType.TaskFinished: return applyTaskFinished(state, e);
|
|
93
94
|
case EventType.ModelWait:
|
|
94
|
-
if (state.taskState === TaskState.Running) state.modelWait = { retryAt: e.retryAt, httpStatus: e.httpStatus
|
|
95
|
+
if (state.taskState === TaskState.Running) state.modelWait = { retryAt: e.retryAt, httpStatus: e.httpStatus,
|
|
96
|
+
attempt: e.attempt, purpose: e.purpose };
|
|
95
97
|
return;
|
|
96
98
|
case EventType.ModelRequest:
|
|
99
|
+
state.modelRetryAttempt = e.active && e.retry ? state.modelWait?.attempt : undefined;
|
|
97
100
|
if (e.active) state.modelWait = null;
|
|
98
|
-
if (e.active && state.taskState === TaskState.Paused
|
|
101
|
+
if (e.active && state.taskState === TaskState.Paused
|
|
102
|
+
&& ['provider_unavailable', 'delivery_no_progress', 'delivery_repair_budget_exhausted'].includes(state.taskReason))
|
|
99
103
|
applyTaskState(state, { state: TaskState.Running, reason: null, message: null });
|
|
100
104
|
if (!e.active || state.modelThinkingId !== e.itemId) settleModelPresentation(state);
|
|
101
105
|
state.modelRequestActive = e.active;
|
|
@@ -183,6 +187,7 @@ function applyTaskState(state, e) {
|
|
|
183
187
|
state.modelWait = null;
|
|
184
188
|
state.modelRequestActive = false;
|
|
185
189
|
state.modelRequestRetry = false;
|
|
190
|
+
state.modelRetryAttempt = undefined;
|
|
186
191
|
state.modelRequestPurpose = null;
|
|
187
192
|
state.modelThinkingId = null;
|
|
188
193
|
}
|
|
@@ -199,6 +204,7 @@ function applyTaskFinished(state, e) {
|
|
|
199
204
|
state.modelWait = null;
|
|
200
205
|
state.modelRequestActive = false;
|
|
201
206
|
state.modelRequestRetry = false;
|
|
207
|
+
state.modelRetryAttempt = undefined;
|
|
202
208
|
state.modelRequestPurpose = null;
|
|
203
209
|
state.modelThinkingId = null;
|
|
204
210
|
state.verificationRequired = e.verificationRequired;
|
package/src/styles.mjs
CHANGED
|
@@ -112,6 +112,13 @@ export const styles = `
|
|
|
112
112
|
.harness-thought-preview { color: var(--harness-fg-muted); font-style: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60ch; }
|
|
113
113
|
.harness-thought-body { margin: 12px 0 0 8px; white-space: pre-wrap; word-break: break-word; max-height: 240px; overflow: auto; padding-left: 14px; border-left: 1px solid var(--harness-border); color: var(--harness-thought); }
|
|
114
114
|
.harness-thought-label-streaming { color: var(--harness-running); }
|
|
115
|
+
.harness-retry-caret {
|
|
116
|
+
display: inline-block; flex: 0 0 auto; width: 2px; height: .85em;
|
|
117
|
+
border-radius: 1px; background: var(--harness-running);
|
|
118
|
+
animation: harness-retry-blink 1s step-end infinite;
|
|
119
|
+
}
|
|
120
|
+
@keyframes harness-retry-blink { 50% { opacity: .2; } }
|
|
121
|
+
@media (prefers-reduced-motion: reduce) { .harness-retry-caret { animation: none; } }
|
|
115
122
|
.harness-thought-preview {
|
|
116
123
|
color: var(--harness-fg-muted); font-style: normal; overflow: hidden; white-space: nowrap;
|
|
117
124
|
text-overflow: ellipsis; min-width: 0; flex: 1 1 auto; max-width: 60ch;
|
package/src/view.mjs
CHANGED
|
@@ -285,22 +285,29 @@ function textBlock(item, opts) {
|
|
|
285
285
|
|
|
286
286
|
function modelActivity(opts, state) {
|
|
287
287
|
if (state.modelWait) {
|
|
288
|
-
const zh = String(opts.locale ?? '').startsWith('zh')
|
|
289
|
-
const
|
|
288
|
+
const zh = String(opts.locale ?? '').startsWith('zh');
|
|
289
|
+
const { retryAt, httpStatus, purpose, attempt } = state.modelWait;
|
|
290
|
+
const label = httpStatus === 429 ? (zh ? '网关限流,等待重试' : 'Gateway rate limited; waiting to retry')
|
|
290
291
|
: zh ? '模型请求暂未成功,等待重试' : 'Model request delayed; waiting to retry';
|
|
292
|
+
const stage = purpose === 'compaction' ? (zh ? '上下文压缩 · ' : 'Context compaction · ') : '';
|
|
293
|
+
const number = attempt ? (zh ? ` · 第 ${attempt} 次重试` : ` · Attempt ${attempt}`) : '';
|
|
291
294
|
return h('div', { className: 'harness-thought-summary harness-model-activity', role: 'status',
|
|
292
|
-
'data-testid': 'model-backoff', 'data-retry-at':
|
|
293
|
-
|
|
295
|
+
'data-testid': 'model-backoff', 'data-retry-at': retryAt },
|
|
296
|
+
h('span', { className: 'harness-retry-caret', 'aria-hidden': 'true' }),
|
|
297
|
+
h('span', {}, stage + label + number),
|
|
298
|
+
h('span', { 'data-testid': 'model-retry-countdown', 'data-retry-at': retryAt, 'data-retry-language': zh ? 'zh' : 'en' }));
|
|
294
299
|
}
|
|
295
300
|
const zh = String(opts.locale ?? '').startsWith('zh');
|
|
296
301
|
const compacting = state.modelRequestPurpose === 'compaction', retry = state.modelRequestRetry;
|
|
297
302
|
const label = compacting ? (retry ? (zh ? '正在重试上下文压缩…' : 'Retrying context compaction…')
|
|
298
303
|
: (zh ? '正在压缩上下文…' : 'Compacting context…'))
|
|
299
304
|
: retry ? (zh ? '模型正在重试…' : 'Retrying model request…') : opts.labels.thinking;
|
|
305
|
+
const attempt = state.modelRetryAttempt;
|
|
306
|
+
const number = retry && attempt ? (zh ? ` · 第 ${attempt} 次重试` : ` · Attempt ${attempt}`) : '';
|
|
300
307
|
return h("div", { className: "harness-thought-summary harness-model-activity", role: "status",
|
|
301
308
|
"data-testid": compacting ? "model-compaction" : retry ? "model-retry" : "model-thinking" },
|
|
302
|
-
brainIcon("harness-thought-icon"),
|
|
303
|
-
h("span", { className: "harness-thought-label harness-thought-label-streaming" }, label));
|
|
309
|
+
retry ? h('span', { className: 'harness-retry-caret', 'aria-hidden': 'true' }) : brainIcon("harness-thought-icon"),
|
|
310
|
+
h("span", { className: "harness-thought-label harness-thought-label-streaming" }, label + number));
|
|
304
311
|
}
|
|
305
312
|
|
|
306
313
|
function thoughtBlock(item, opts) {
|