@xiangyixie/dsh-superagent 0.18.3 → 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 +60 -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 }
|
|
@@ -946,6 +956,27 @@ window.__ModuleLoader__.load({
|
|
|
946
956
|
}, run.status === 'running' ? '停止' : '已停'),
|
|
947
957
|
h('button', { type: 'button', className: 'dsa-linkbtn', onClick: () => props.onClose?.() }, '关闭')),
|
|
948
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,
|
|
949
980
|
h('div', { className: 'dsa-detail-sec' },
|
|
950
981
|
h('div', { className: 'dsa-detail-label' }, '状态'),
|
|
951
982
|
h('div', { className: 'dsa-detail-q' }, `${run.status ?? '未知'}${run.startedAt ? ` · ${run.startedAt}` : ''}`)),
|
|
@@ -1183,6 +1214,7 @@ window.__ModuleLoader__.load({
|
|
|
1183
1214
|
onDraft: value => dispatch({ type: 'draft', value }),
|
|
1184
1215
|
onAnswer: (runId, attentionId, answer) => dispatch({ type: 'answer', runId, attentionId, answer }),
|
|
1185
1216
|
onArtifact: item => dispatch({ type: 'artifact', item }),
|
|
1217
|
+
onClosePreview: () => dispatch({ type: 'closePreview' }),
|
|
1186
1218
|
onReveal: item => dispatch({ type: 'revealArtifact', item }),
|
|
1187
1219
|
onDownload: item => dispatch({ type: 'downloadArtifact', item }),
|
|
1188
1220
|
})),
|
|
@@ -1376,7 +1408,7 @@ window.__ModuleLoader__.load({
|
|
|
1376
1408
|
throw error
|
|
1377
1409
|
}
|
|
1378
1410
|
},
|
|
1379
|
-
closeRun: () => patch(current => ({ ...current, detail: null, answerDraft: '' })),
|
|
1411
|
+
closeRun: () => patch(current => ({ ...current, detail: null, answerDraft: '', preview: null, previewText: '', previewBusy: false })),
|
|
1380
1412
|
cancelRun: async action => {
|
|
1381
1413
|
await call(`/runs/${encodeURIComponent(action.runId)}/cancel`, { method: 'POST' })
|
|
1382
1414
|
patch(current => ({
|
|
@@ -1406,11 +1438,35 @@ window.__ModuleLoader__.load({
|
|
|
1406
1438
|
: current.detail,
|
|
1407
1439
|
}))
|
|
1408
1440
|
},
|
|
1409
|
-
artifact: action => {
|
|
1441
|
+
artifact: async action => {
|
|
1410
1442
|
const item = action.item ?? {}
|
|
1411
|
-
const
|
|
1412
|
-
|
|
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
|
+
}
|
|
1413
1468
|
},
|
|
1469
|
+
closePreview: () => patch(current => ({ ...current, preview: null, previewText: '', previewBusy: false })),
|
|
1414
1470
|
revealArtifact: async action => {
|
|
1415
1471
|
const item = action.item ?? {}
|
|
1416
1472
|
const query = `?path=${encodeURIComponent(item.href ?? '')}&runId=${encodeURIComponent(item.runId ?? '')}`
|