@xiangyixie/dsh-superagent 0.18.2 → 0.18.4
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/lib/client.js +69 -4
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -274,6 +274,10 @@ window.__ModuleLoader__.load({
|
|
|
274
274
|
.dsa-attention-options{display:flex;flex-wrap:wrap;gap:6px}
|
|
275
275
|
.dsa-artifact-row{display:flex;align-items:center;gap:4px}
|
|
276
276
|
.dsa-artifact-row .dsa-artifact-link{flex:1;min-width:0;overflow:hidden}
|
|
277
|
+
.dsa-preview{border:1px solid var(--dsw-alias-border-l3,rgba(255,255,255,.16));border-radius:var(--dsw-radius-md,12px);padding:8px}
|
|
278
|
+
.dsa-preview-img{display:block;max-width:100%;border-radius:var(--dsw-radius-sm,8px)}
|
|
279
|
+
.dsa-preview-frame{width:100%;height:320px;border:0;border-radius:var(--dsw-radius-sm,8px);background:var(--dsw-alias-bg-base,rgb(21,21,23))}
|
|
280
|
+
.dsa-preview-text{max-height:320px;overflow:auto;white-space:pre-wrap;word-break:break-word;font:inherit;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,rgb(207,211,214))}
|
|
277
281
|
.dsa-chip{padding:3px 10px;border:1px solid var(--dsw-alias-border-l3,rgba(255,255,255,.16));border-radius:999px;background:transparent;color:var(--dsw-alias-label-primary,#f9fafb);font:inherit;font-size:12px;line-height:18px;cursor:pointer}
|
|
278
282
|
.dsa-chip:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08))}
|
|
279
283
|
`
|
|
@@ -357,6 +361,9 @@ window.__ModuleLoader__.load({
|
|
|
357
361
|
detail: null,
|
|
358
362
|
detailBusy: false,
|
|
359
363
|
answerDraft: '',
|
|
364
|
+
preview: null,
|
|
365
|
+
previewText: '',
|
|
366
|
+
previewBusy: false,
|
|
360
367
|
uploadInsert: '',
|
|
361
368
|
uploading: false,
|
|
362
369
|
unread: 0,
|
|
@@ -549,6 +556,9 @@ window.__ModuleLoader__.load({
|
|
|
549
556
|
sessionsOpen: false,
|
|
550
557
|
detail: null,
|
|
551
558
|
answerDraft: '',
|
|
559
|
+
preview: null,
|
|
560
|
+
previewText: '',
|
|
561
|
+
previewBusy: false,
|
|
552
562
|
}
|
|
553
563
|
case 'stream.snapshot': {
|
|
554
564
|
let next = { ...model, messages: [], currentId: null }
|
|
@@ -576,6 +586,15 @@ window.__ModuleLoader__.load({
|
|
|
576
586
|
const others = model.approvals.filter(entry => entry.id !== approval.id)
|
|
577
587
|
return { ...model, approvals: [...others, approval], unread: (model.unread ?? 0) + 1 }
|
|
578
588
|
}
|
|
589
|
+
if (frame.action === 'expired' && frame.id) {
|
|
590
|
+
// The card must not vanish silently: the tool call it guarded is
|
|
591
|
+
// already cancelled, and the user should know why.
|
|
592
|
+
return {
|
|
593
|
+
...model,
|
|
594
|
+
approvals: model.approvals.filter(entry => entry.id !== frame.id),
|
|
595
|
+
toast: { kind: 'err', text: '这个审批已超时,工具调用已取消' },
|
|
596
|
+
}
|
|
597
|
+
}
|
|
579
598
|
if (frame.id) {
|
|
580
599
|
return { ...model, approvals: model.approvals.filter(entry => entry.id !== frame.id) }
|
|
581
600
|
}
|
|
@@ -937,6 +956,27 @@ window.__ModuleLoader__.load({
|
|
|
937
956
|
}, run.status === 'running' ? '停止' : '已停'),
|
|
938
957
|
h('button', { type: 'button', className: 'dsa-linkbtn', onClick: () => props.onClose?.() }, '关闭')),
|
|
939
958
|
h('div', { className: 'dsa-detail-body' },
|
|
959
|
+
model.preview
|
|
960
|
+
? h('div', { className: 'dsa-detail-sec dsa-preview' },
|
|
961
|
+
h('div', { className: 'dsa-detail-head' },
|
|
962
|
+
h('span', { className: 'dsa-detail-title' }, model.preview.name),
|
|
963
|
+
h('button', { type: 'button', className: 'dsa-linkbtn', onClick: () => props.onClosePreview?.() }, '关闭预览')),
|
|
964
|
+
model.preview.kind === 'img'
|
|
965
|
+
? h('img', { className: 'dsa-preview-img', src: model.preview.url, alt: model.preview.name })
|
|
966
|
+
: model.preview.kind === 'html'
|
|
967
|
+
? h('iframe', {
|
|
968
|
+
className: 'dsa-preview-frame',
|
|
969
|
+
sandbox: '',
|
|
970
|
+
src: model.preview.url,
|
|
971
|
+
title: model.preview.name,
|
|
972
|
+
})
|
|
973
|
+
: h('div', { className: 'dsa-preview-text' },
|
|
974
|
+
model.previewBusy
|
|
975
|
+
? '读取中…'
|
|
976
|
+
: model.preview.kind === 'md' && MarkdownText
|
|
977
|
+
? h(MarkdownText, { text: model.previewText, labels: MARKDOWN_LABELS })
|
|
978
|
+
: model.previewText))
|
|
979
|
+
: null,
|
|
940
980
|
h('div', { className: 'dsa-detail-sec' },
|
|
941
981
|
h('div', { className: 'dsa-detail-label' }, '状态'),
|
|
942
982
|
h('div', { className: 'dsa-detail-q' }, `${run.status ?? '未知'}${run.startedAt ? ` · ${run.startedAt}` : ''}`)),
|
|
@@ -1174,6 +1214,7 @@ window.__ModuleLoader__.load({
|
|
|
1174
1214
|
onDraft: value => dispatch({ type: 'draft', value }),
|
|
1175
1215
|
onAnswer: (runId, attentionId, answer) => dispatch({ type: 'answer', runId, attentionId, answer }),
|
|
1176
1216
|
onArtifact: item => dispatch({ type: 'artifact', item }),
|
|
1217
|
+
onClosePreview: () => dispatch({ type: 'closePreview' }),
|
|
1177
1218
|
onReveal: item => dispatch({ type: 'revealArtifact', item }),
|
|
1178
1219
|
onDownload: item => dispatch({ type: 'downloadArtifact', item }),
|
|
1179
1220
|
})),
|
|
@@ -1367,7 +1408,7 @@ window.__ModuleLoader__.load({
|
|
|
1367
1408
|
throw error
|
|
1368
1409
|
}
|
|
1369
1410
|
},
|
|
1370
|
-
closeRun: () => patch(current => ({ ...current, detail: null, answerDraft: '' })),
|
|
1411
|
+
closeRun: () => patch(current => ({ ...current, detail: null, answerDraft: '', preview: null, previewText: '', previewBusy: false })),
|
|
1371
1412
|
cancelRun: async action => {
|
|
1372
1413
|
await call(`/runs/${encodeURIComponent(action.runId)}/cancel`, { method: 'POST' })
|
|
1373
1414
|
patch(current => ({
|
|
@@ -1397,11 +1438,35 @@ window.__ModuleLoader__.load({
|
|
|
1397
1438
|
: current.detail,
|
|
1398
1439
|
}))
|
|
1399
1440
|
},
|
|
1400
|
-
artifact: action => {
|
|
1441
|
+
artifact: async action => {
|
|
1401
1442
|
const item = action.item ?? {}
|
|
1402
|
-
const
|
|
1403
|
-
|
|
1443
|
+
const href = String(item.href ?? '')
|
|
1444
|
+
const url = `${API}/artifact?path=${encodeURIComponent(href)}&runId=${encodeURIComponent(item.runId ?? '')}`
|
|
1445
|
+
const ext = href.toLowerCase().split('.').pop()
|
|
1446
|
+
const kind = ['md', 'markdown'].includes(ext)
|
|
1447
|
+
? 'md'
|
|
1448
|
+
: ['html', 'htm'].includes(ext)
|
|
1449
|
+
? 'html'
|
|
1450
|
+
: ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg'].includes(ext)
|
|
1451
|
+
? 'img'
|
|
1452
|
+
: 'text'
|
|
1453
|
+
patch(current => ({
|
|
1454
|
+
...current,
|
|
1455
|
+
preview: { name: item.name ?? href, url, kind },
|
|
1456
|
+
previewText: '',
|
|
1457
|
+
previewBusy: kind === 'md' || kind === 'text',
|
|
1458
|
+
}))
|
|
1459
|
+
if (kind !== 'md' && kind !== 'text') return
|
|
1460
|
+
try {
|
|
1461
|
+
const res = await fetch(url, { headers: { accept: 'text/plain, text/markdown, */*' } })
|
|
1462
|
+
const text = await res.text()
|
|
1463
|
+
if (!res.ok) throw new Error(text.slice(0, 200) || `HTTP ${res.status}`)
|
|
1464
|
+
patch(current => ({ ...current, previewBusy: false, previewText: text }))
|
|
1465
|
+
} catch (error) {
|
|
1466
|
+
patch(current => ({ ...current, previewBusy: false, previewText: `这个产物读不出来:${error.message}` }))
|
|
1467
|
+
}
|
|
1404
1468
|
},
|
|
1469
|
+
closePreview: () => patch(current => ({ ...current, preview: null, previewText: '', previewBusy: false })),
|
|
1405
1470
|
revealArtifact: async action => {
|
|
1406
1471
|
const item = action.item ?? {}
|
|
1407
1472
|
const query = `?path=${encodeURIComponent(item.href ?? '')}&runId=${encodeURIComponent(item.runId ?? '')}`
|