giliarde-dsh-bots 1.2.0 → 1.3.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.
- package/INSTALACAO.md +1 -1
- package/README.md +11 -4
- package/client.js +210 -9
- package/index.js +4 -1
- package/package.json +1 -1
- package/src/api.js +45 -6
package/INSTALACAO.md
CHANGED
|
@@ -19,7 +19,7 @@ Reinicie o DSH, abra **Plugins** e ative `include:bots` se necessário.
|
|
|
19
19
|
## Instalar via tarball
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
|
-
dsh plugin --profile web add /caminho/giliarde-dsh-bots-1.
|
|
22
|
+
dsh plugin --profile web add /caminho/giliarde-dsh-bots-1.3.0.tgz
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Ou use o Plugin Manager → instalar bundle → selecionar o `.tgz`.
|
package/README.md
CHANGED
|
@@ -2,13 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
Criado por **Giliarde**.
|
|
4
4
|
|
|
5
|
+
## Instalação rápida
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
dsh plugin --profile web add giliarde-dsh-bots
|
|
9
|
+
```
|
|
10
|
+
|
|
5
11
|
Painel **Bots** na sidebar do DSH (acessível em qualquer sessão, inclusive Creator
|
|
6
12
|
Mode). Cada bot é um agente próprio do plugin
|
|
7
13
|
(loop de tool-calling sobre `ctx.llm`), com personalidade, memória, ferramentas,
|
|
8
14
|
workspace compartilhado e, opcionalmente, controle do desktop X11 real servido
|
|
9
15
|
por `Xtigervnc + XFCE`.
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
Instalação e requisitos estão na seção **Instalação** abaixo.
|
|
12
18
|
|
|
13
19
|
Recursos principais:
|
|
14
20
|
|
|
@@ -21,6 +27,7 @@ Recursos principais:
|
|
|
21
27
|
após 2 minutos ocioso (ou pelo botão **Ligar desktop**);
|
|
22
28
|
- UI escura estilo estúdio, inspirada no Grok, mantendo o painel na sidebar;
|
|
23
29
|
- copiar/responder mensagem, badge de duração e **Rastreamento** com timeline de modelo/ferramentas;
|
|
30
|
+
- **Biblioteca por chat**: imagens, textos e arquivos com filtro, busca, preview ao clicar e download direto;
|
|
24
31
|
- medidor discreto de **janela de contexto** por bot;
|
|
25
32
|
- botão **+** no composer para trocar **modelo**, **esforço de raciocínio** e **acessos** (computador, gestor, acesso total) sem sair do chat.
|
|
26
33
|
|
|
@@ -38,16 +45,16 @@ opcional: sem ele o painel, chats, grupos, rede e rotinas funcionam.
|
|
|
38
45
|
|
|
39
46
|
Opção A — tarball (sem registry):
|
|
40
47
|
|
|
41
|
-
1. Gere o pacote com `npm run build:public` (cria `dist/giliarde-dsh-bots-1.
|
|
48
|
+
1. Gere o pacote com `npm run build:public` (cria `dist/giliarde-dsh-bots-1.3.0.tgz`).
|
|
42
49
|
2. Envie o `.tgz`.
|
|
43
|
-
3. No DSH da outra pessoa: `dsh plugin --profile web add /caminho/giliarde-dsh-bots-1.
|
|
50
|
+
3. No DSH da outra pessoa: `dsh plugin --profile web add /caminho/giliarde-dsh-bots-1.3.0.tgz`
|
|
44
51
|
ou Plugin Manager → instalar bundle → caminho do `.tgz`.
|
|
45
52
|
4. Configurar `browserCommand`/`display` só se o desktop for usado.
|
|
46
53
|
|
|
47
54
|
Opção B — npm público (sem escopo):
|
|
48
55
|
|
|
49
56
|
1. Crie conta em npmjs.com e rode `npm login`.
|
|
50
|
-
2. `npm publish ./dist/giliarde-dsh-bots-1.
|
|
57
|
+
2. `npm publish ./dist/giliarde-dsh-bots-1.3.0.tgz --access public`.
|
|
51
58
|
3. Outra pessoa instala com `dsh plugin --profile web add giliarde-dsh-bots`.
|
|
52
59
|
|
|
53
60
|
O pacote não contém dados de bots, prints ou credenciais; tudo fica em
|
package/client.js
CHANGED
|
@@ -265,6 +265,33 @@ window.__ModuleLoader__.load({
|
|
|
265
265
|
.bots-tracelegend i{display:inline-block;width:8px;height:8px;border-radius:2px;margin-right:4px;vertical-align:middle;background:#6d8cff}
|
|
266
266
|
.bots-tracelegend i.tool{background:#2dd4bf}.bots-tracelegend i.error{background:#ef4444}
|
|
267
267
|
.bots-modal{background:linear-gradient(180deg,#101725,#0b1018);border:1px solid var(--b-line);box-shadow:0 30px 90px rgba(0,0,0,.55)}
|
|
268
|
+
.bots-library{padding:16px}
|
|
269
|
+
.bots-libhead{display:flex;align-items:flex-start;justify-content:space-between;gap:14px;margin-bottom:10px}
|
|
270
|
+
.bots-libhead h3{margin:0 0 2px;font-size:15px;color:#edf5ff}
|
|
271
|
+
.bots-libhead p{margin:0}
|
|
272
|
+
.bots-libhead .bots-search{width:260px;max-width:40vw}
|
|
273
|
+
.bots-libfilters{display:flex;gap:5px;flex-wrap:wrap;margin-bottom:10px}
|
|
274
|
+
.bots-libchip{appearance:none;border:1px solid var(--b-line2);background:rgba(255,255,255,.025);color:#8fa0b7;border-radius:999px;padding:4px 10px;font:inherit;font-size:11px;cursor:pointer}
|
|
275
|
+
.bots-libchip.active{color:#bfffea;border-color:rgba(62,230,176,.3);background:rgba(62,230,176,.1)}
|
|
276
|
+
.bots-liblist{display:flex;flex-direction:column;gap:5px}
|
|
277
|
+
.bots-librow{display:flex;align-items:center;gap:10px;background:rgba(255,255,255,.02);border:1px solid var(--b-line2);border-radius:11px;padding:8px 10px;min-width:0}
|
|
278
|
+
.bots-librow:hover{background:rgba(255,255,255,.04)}
|
|
279
|
+
.bots-librow.clickable{cursor:pointer}
|
|
280
|
+
.bots-libthumb{width:40px;height:40px;border-radius:8px;background:rgba(255,255,255,.04);border:1px solid var(--b-line2);display:flex;align-items:center;justify-content:center;color:#8fa0b7;overflow:hidden;flex:0 0 40px}
|
|
281
|
+
.bots-libthumb img{width:100%;height:100%;object-fit:cover;display:block}
|
|
282
|
+
.bots-libbody{display:flex;flex-direction:column;gap:1px;min-width:0;flex:1}
|
|
283
|
+
.bots-libbody b{font-size:12.5px;color:#dbe7f5;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
284
|
+
.bots-libbody span{font-size:10.5px;color:#718096;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
285
|
+
.bots-libpreview{font-size:10.5px;color:#8492a8;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:640px}
|
|
286
|
+
.bots-libdownload{appearance:none;display:inline-flex;align-items:center;gap:4px;border:1px solid rgba(62,230,176,.24);background:rgba(62,230,176,.09);color:#a9f7df;border-radius:7px;padding:5px 8px;font:inherit;font-size:11px;font-weight:600;text-decoration:none;cursor:pointer;white-space:nowrap;flex:0 0 auto}
|
|
287
|
+
.bots-libdownload:hover{background:rgba(62,230,176,.16);border-color:rgba(62,230,176,.42)}
|
|
288
|
+
@media (max-width:760px){.bots-libhead{flex-direction:column}.bots-libhead .bots-search{width:100%;max-width:none}.bots-libpreview{max-width:300px}}
|
|
289
|
+
.bots-previewmeta{display:flex;align-items:center;gap:4px;font-size:11.5px;color:#c7d4e5;margin-bottom:8px}
|
|
290
|
+
.bots-previewimage{display:flex;align-items:center;justify-content:center;background:#05070b;border:1px solid var(--b-line2);border-radius:10px;padding:8px;min-height:180px}
|
|
291
|
+
.bots-previewimage img{display:block;max-width:100%;max-height:58vh;object-fit:contain;border-radius:6px}
|
|
292
|
+
.bots-previewtext{max-height:58vh;overflow:auto;white-space:pre-wrap;word-break:break-word;background:#0a1019;border:1px solid var(--b-line2);border-radius:10px;padding:12px;color:#dbe7f5;font:12px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace;margin:0}
|
|
293
|
+
.bots-previewempty{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;min-height:180px;background:#0a1019;border:1px dashed var(--b-line);border-radius:10px;color:#8fa0b7;padding:24px;text-align:center}
|
|
294
|
+
.bots-previewfoot{display:flex;justify-content:flex-end;margin-top:10px}
|
|
268
295
|
.bots-composer{position:relative}
|
|
269
296
|
.bots-inputrow > .bots-btn.sm{width:38px;height:38px;min-width:38px;padding:0;display:inline-flex;align-items:center;justify-content:center;border-radius:10px;font-size:15px;line-height:1;flex:0 0 38px}
|
|
270
297
|
.bots-inputrow > .bots-btn.primary{width:40px;height:38px;min-width:40px;padding:0;display:inline-flex;align-items:center;justify-content:center;border-radius:10px;flex:0 0 40px}
|
|
@@ -818,6 +845,57 @@ window.__ModuleLoader__.load({
|
|
|
818
845
|
)
|
|
819
846
|
}
|
|
820
847
|
|
|
848
|
+
function downloadHref(url) {
|
|
849
|
+
if (!url) return null
|
|
850
|
+
if (/^(blob:|data:)/u.test(url)) return url
|
|
851
|
+
return /(?:^|[?&])download=1(?:&|$)/u.test(url) ? url : `${url}${url.includes('?') ? '&' : '?'}download=1`
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
function inlineHref(url) {
|
|
855
|
+
if (!url) return null
|
|
856
|
+
return url.replace(/([?&])download=1(?=&|$)/u, '$1').replace(/[?&]$/u, '')
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
function triggerTextDownload(name, text) {
|
|
860
|
+
const blob = new Blob([text ?? ''], { type: 'text/plain;charset=utf-8' })
|
|
861
|
+
const url = URL.createObjectURL(blob)
|
|
862
|
+
const anchor = document.createElement('a')
|
|
863
|
+
anchor.href = url
|
|
864
|
+
anchor.download = String(name || 'mensagem.txt').replace(/[\\/:*?"<>|\r\n]/gu, '-')
|
|
865
|
+
document.body.appendChild(anchor)
|
|
866
|
+
anchor.click()
|
|
867
|
+
anchor.remove()
|
|
868
|
+
setTimeout(() => URL.revokeObjectURL(url), 2000)
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
function FilePreviewModal({ item, onClose }) {
|
|
872
|
+
const [text, setText] = useState(item?.text ?? null)
|
|
873
|
+
const [error, setError] = useState(null)
|
|
874
|
+
const sourceUrl = inlineHref(item?.url)
|
|
875
|
+
useEffect(() => {
|
|
876
|
+
setText(item?.text ?? null)
|
|
877
|
+
setError(null)
|
|
878
|
+
if (!item || item.text != null || item.kind !== 'text' || !sourceUrl) return
|
|
879
|
+
let cancelled = false
|
|
880
|
+
fetch(sourceUrl)
|
|
881
|
+
.then((response) => { if (!response.ok) throw new Error(`HTTP ${response.status}`); return response.text() })
|
|
882
|
+
.then((value) => { if (!cancelled) setText(value) })
|
|
883
|
+
.catch((cause) => { if (!cancelled) setError(cause instanceof Error ? cause.message : String(cause)) })
|
|
884
|
+
return () => { cancelled = true }
|
|
885
|
+
}, [item, sourceUrl])
|
|
886
|
+
if (!item) return null
|
|
887
|
+
const isImage = item.kind === 'image'
|
|
888
|
+
const isText = item.kind === 'text' || item.text != null
|
|
889
|
+
const href = downloadHref(item.url)
|
|
890
|
+
return h(Modal, { title: item.name ?? 'Arquivo', onClose, wide: true },
|
|
891
|
+
h('div', { className: 'bots-previewmeta' }, h('span', null, item.author ? `${item.author} · ` : ''), h('span', { className: 'bots-hint' }, `${item.kind === 'image' ? 'Imagem' : isText ? 'Texto' : 'Arquivo'}${item.size ? ` · ${Math.max(1, Math.round(item.size / 1024))} KB` : ''}`)),
|
|
892
|
+
isImage && sourceUrl ? h('div', { className: 'bots-previewimage' }, h('img', { src: sourceUrl, alt: item.name ?? '' })) : isText ? h('pre', { className: 'bots-previewtext' }, error ? `Erro ao abrir: ${error}` : text ?? 'Carregando…') : h('div', { className: 'bots-previewempty' }, h(IconFile, { size: 34 }), h('b', null, item.name ?? 'Arquivo'), h('span', { className: 'bots-hint' }, 'Pré-visualização não disponível para este tipo. Baixe para abrir no aplicativo.'))
|
|
893
|
+
, h('div', { className: 'bots-previewfoot' },
|
|
894
|
+
href ? h('a', { className: 'bots-libdownload', href, download: item.name ?? 'arquivo', onClick: (event) => event.stopPropagation() }, h(IconDown, { size: 13 }), 'Baixar') : h('button', { className: 'bots-libdownload', onClick: () => triggerTextDownload(item.name, text ?? item.text ?? '') }, h(IconDown, { size: 13 }), 'Baixar')
|
|
895
|
+
)
|
|
896
|
+
)
|
|
897
|
+
}
|
|
898
|
+
|
|
821
899
|
function Toast({ notice, onClose }) {
|
|
822
900
|
useEffect(() => {
|
|
823
901
|
if (!notice) return
|
|
@@ -838,6 +916,7 @@ window.__ModuleLoader__.load({
|
|
|
838
916
|
const reply = message.replyTo
|
|
839
917
|
const trace = message.meta?.trace
|
|
840
918
|
const [copied, setCopied] = useState(false)
|
|
919
|
+
const [preview, setPreview] = useState(null)
|
|
841
920
|
function copyMessage() {
|
|
842
921
|
const text = String(message.text ?? '')
|
|
843
922
|
const done = () => { setCopied(true); setTimeout(() => setCopied(false), 1400) }
|
|
@@ -866,17 +945,21 @@ window.__ModuleLoader__.load({
|
|
|
866
945
|
h('div', { className: 'bots-msgtext' }, renderRich(message.text)),
|
|
867
946
|
Array.isArray(message.attachments) && message.attachments.length > 0 ? h('div', { className: 'bots-attach' },
|
|
868
947
|
message.attachments.filter((item) => item.url).map((item) => {
|
|
869
|
-
const
|
|
948
|
+
const name = item.name ?? item.artifact ?? 'arquivo'
|
|
949
|
+
const mediaType = String(item.mediaType ?? '')
|
|
950
|
+
const image = item.kind === 'image' || item.kind === 'screenshot' || mediaType.startsWith('image/')
|
|
951
|
+
const textFile = !image && (mediaType.startsWith('text/') || /\.(txt|md|csv|json|log|xml|ya?ml)$/iu.test(name))
|
|
952
|
+
const previewItem = { name, url: item.url, kind: image ? 'image' : textFile ? 'text' : 'file', mediaType, size: item.size, author: message.author?.name, createdAt: message.createdAt }
|
|
870
953
|
if (image) return h('img', {
|
|
871
954
|
key: item.artifact ?? item.id ?? item.url,
|
|
872
955
|
src: item.url,
|
|
873
|
-
alt:
|
|
956
|
+
alt: name,
|
|
874
957
|
onError: (e) => { e.currentTarget.style.display = 'none' },
|
|
875
|
-
onClick: () =>
|
|
958
|
+
onClick: () => setPreview(previewItem)
|
|
876
959
|
})
|
|
877
|
-
return h('a', { key: item.id ?? item.url, className: 'bots-filelink', href: item.url,
|
|
960
|
+
return h('a', { key: item.id ?? item.url, className: 'bots-filelink', href: item.url, onClick: (event) => { event.preventDefault(); setPreview(previewItem) }, title: 'Abrir arquivo' },
|
|
878
961
|
h(IconFile, { size: 15 }),
|
|
879
|
-
h('span', null,
|
|
962
|
+
h('span', null, name),
|
|
880
963
|
h('small', null, item.size ? `${Math.max(1, Math.round(item.size / 1024))} KB` : '')
|
|
881
964
|
)
|
|
882
965
|
})
|
|
@@ -892,7 +975,8 @@ window.__ModuleLoader__.load({
|
|
|
892
975
|
h('span', { className: 'bots-tracechev' }, '›')
|
|
893
976
|
) : null
|
|
894
977
|
) : null
|
|
895
|
-
)
|
|
978
|
+
),
|
|
979
|
+
preview ? h(FilePreviewModal, { item: preview, onClose: () => setPreview(null) }) : null
|
|
896
980
|
)
|
|
897
981
|
}
|
|
898
982
|
|
|
@@ -1563,6 +1647,102 @@ window.__ModuleLoader__.load({
|
|
|
1563
1647
|
)
|
|
1564
1648
|
}
|
|
1565
1649
|
|
|
1650
|
+
function LibraryPanel({ messages, title }) {
|
|
1651
|
+
const [filter, setFilter] = useState('all')
|
|
1652
|
+
const [query, setQuery] = useState('')
|
|
1653
|
+
const [preview, setPreview] = useState(null)
|
|
1654
|
+
function cleanName(value) {
|
|
1655
|
+
return String(value ?? 'arquivo').replace(/[\\/:*?"<>|\r\n]/gu, '-').slice(0, 140)
|
|
1656
|
+
}
|
|
1657
|
+
const items = useMemo(() => {
|
|
1658
|
+
const list = []
|
|
1659
|
+
const seen = new Set()
|
|
1660
|
+
const safeName = (value) => String(value ?? 'arquivo').replace(/[\\/:*?"<>|\r\n]/gu, '-').slice(0, 140)
|
|
1661
|
+
for (const message of messages ?? []) {
|
|
1662
|
+
if (message.author?.type === 'system') continue
|
|
1663
|
+
for (const attachment of message.attachments ?? []) {
|
|
1664
|
+
const key = attachment.artifact ? `a:${attachment.artifact}` : attachment.id ? `u:${attachment.id}` : attachment.url
|
|
1665
|
+
if (!key || seen.has(key)) continue
|
|
1666
|
+
seen.add(key)
|
|
1667
|
+
const mediaType = String(attachment.mediaType ?? '')
|
|
1668
|
+
const name = attachment.name ?? (attachment.artifact ? `screenshot-${new Date(message.createdAt).toISOString().slice(0, 10)}.jpg` : 'arquivo')
|
|
1669
|
+
const image = attachment.kind === 'image' || attachment.kind === 'screenshot' || mediaType.startsWith('image/')
|
|
1670
|
+
const textFile = !image && (mediaType.startsWith('text/') || /\.(txt|md|csv|json|log|xml|ya?ml)$/iu.test(name))
|
|
1671
|
+
list.push({
|
|
1672
|
+
id: key,
|
|
1673
|
+
kind: image ? 'image' : textFile ? 'text' : 'file',
|
|
1674
|
+
name,
|
|
1675
|
+
url: attachment.url ? `${attachment.url}${attachment.url.includes('?') ? '&' : '?'}download=1` : null,
|
|
1676
|
+
size: attachment.size ?? 0,
|
|
1677
|
+
author: message.author?.name ?? 'Você',
|
|
1678
|
+
createdAt: message.createdAt,
|
|
1679
|
+
preview: image ? attachment.url : null
|
|
1680
|
+
})
|
|
1681
|
+
}
|
|
1682
|
+
const body = String(message.text ?? '').trim()
|
|
1683
|
+
if (body) {
|
|
1684
|
+
const date = new Date(message.createdAt)
|
|
1685
|
+
const stamp = Number.isNaN(date.getTime()) ? 'data' : date.toISOString().slice(0, 16).replace(/[:T]/gu, '-')
|
|
1686
|
+
list.push({
|
|
1687
|
+
id: `t:${message.id}`,
|
|
1688
|
+
kind: 'text',
|
|
1689
|
+
name: safeName(`${message.author?.name ?? 'mensagem'} — ${stamp}.txt`),
|
|
1690
|
+
size: new TextEncoder().encode(body).length,
|
|
1691
|
+
author: message.author?.name ?? '—',
|
|
1692
|
+
createdAt: message.createdAt,
|
|
1693
|
+
text: body,
|
|
1694
|
+
preview: null
|
|
1695
|
+
})
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
return list.sort((a, b) => (b.createdAt ?? 0) - (a.createdAt ?? 0))
|
|
1699
|
+
}, [messages])
|
|
1700
|
+
const filtered = items.filter((item) => {
|
|
1701
|
+
if (filter !== 'all' && item.kind !== filter) return false
|
|
1702
|
+
if (query.trim() && !item.name.toLowerCase().includes(query.trim().toLowerCase())) return false
|
|
1703
|
+
return true
|
|
1704
|
+
})
|
|
1705
|
+
function downloadText(item) {
|
|
1706
|
+
const blob = new Blob([item.text ?? ''], { type: 'text/plain;charset=utf-8' })
|
|
1707
|
+
const url = URL.createObjectURL(blob)
|
|
1708
|
+
const anchor = document.createElement('a')
|
|
1709
|
+
anchor.href = url
|
|
1710
|
+
anchor.download = cleanName(item.name)
|
|
1711
|
+
document.body.appendChild(anchor)
|
|
1712
|
+
anchor.click()
|
|
1713
|
+
anchor.remove()
|
|
1714
|
+
setTimeout(() => URL.revokeObjectURL(url), 2000)
|
|
1715
|
+
}
|
|
1716
|
+
function formatSize(bytes) {
|
|
1717
|
+
const n = Number(bytes) || 0
|
|
1718
|
+
if (n >= 1048576) return `${(n / 1048576).toFixed(1)} MB`
|
|
1719
|
+
if (n >= 1024) return `${(n / 1024).toFixed(1)} KB`
|
|
1720
|
+
return `${n} B`
|
|
1721
|
+
}
|
|
1722
|
+
const kindLabel = { image: 'Imagem', text: 'Texto', file: 'Arquivo' }
|
|
1723
|
+
return h('div', { className: 'bots-scroll bots-library' },
|
|
1724
|
+
h('div', { className: 'bots-libhead' },
|
|
1725
|
+
h('div', null, h('h3', null, `Biblioteca — ${title}`), h('p', { className: 'bots-hint' }, `${items.length} itens deste chat. Download direto, sem links.`)),
|
|
1726
|
+
h('input', { className: 'bots-search', value: query, onChange: (event) => setQuery(event.target.value), placeholder: 'Buscar na biblioteca…' })
|
|
1727
|
+
),
|
|
1728
|
+
h('div', { className: 'bots-libfilters' }, [['all', 'Todos'], ['image', 'Imagens'], ['text', 'Textos'], ['file', 'Arquivos']].map(([key, label]) => h('button', { key, className: cx('bots-libchip', filter === key && 'active'), onClick: () => setFilter(key) }, label))),
|
|
1729
|
+
filtered.length === 0 ? h('div', { className: 'bots-empty' }, h('h3', null, 'Nada por aqui'), h('p', null, 'Imagens, textos e arquivos deste chat aparecem aqui.')) : h('div', { className: 'bots-liblist' },
|
|
1730
|
+
filtered.map((item) => h('div', { key: item.id, className: 'bots-librow clickable', onClick: () => setPreview(item) },
|
|
1731
|
+
h('div', { className: 'bots-libthumb' }, item.preview ? h('img', { src: item.preview, alt: '', onError: (e) => { e.currentTarget.style.display = 'none' } }) : h(IconFile, { size: 18 })),
|
|
1732
|
+
h('div', { className: 'bots-libbody' },
|
|
1733
|
+
h('b', null, item.name),
|
|
1734
|
+
h('span', { className: 'bots-hint' }, `${kindLabel[item.kind]} · ${item.author} · ${new Date(item.createdAt).toLocaleString('pt-BR')} · ${formatSize(item.size)}`),
|
|
1735
|
+
item.kind === 'text' ? h('small', { className: 'bots-libpreview' }, String(item.text ?? '').replace(/\s+/gu, ' ').slice(0, 180)) : null
|
|
1736
|
+
),
|
|
1737
|
+
item.kind === 'text'
|
|
1738
|
+
? h('button', { className: 'bots-libdownload', onClick: (event) => { event.stopPropagation(); downloadText(item) }, title: `Baixar ${item.name}` }, h(IconDown, { size: 13 }), 'Baixar')
|
|
1739
|
+
: h('a', { className: 'bots-libdownload', href: item.url, download: item.name, title: `Baixar ${item.name}`, onClick: (event) => event.stopPropagation() }, h(IconDown, { size: 13 }), 'Baixar')
|
|
1740
|
+
))
|
|
1741
|
+
),
|
|
1742
|
+
preview ? h(FilePreviewModal, { item: preview, onClose: () => setPreview(null) }) : null
|
|
1743
|
+
)
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1566
1746
|
function BotDetail({ store, bot, onDelete, onOpenArtifact }) {
|
|
1567
1747
|
const state = useStore(store)
|
|
1568
1748
|
const [tab, setTab] = useState('chat')
|
|
@@ -1602,7 +1782,7 @@ window.__ModuleLoader__.load({
|
|
|
1602
1782
|
)
|
|
1603
1783
|
),
|
|
1604
1784
|
h('div', { className: 'bots-subtabs' },
|
|
1605
|
-
['chat', 'config', 'memory', 'routines'].map((key) => h('button', { key, className: cx('bots-subtab', tab === key && 'active'), onClick: () => setTab(key) }, key === 'chat' ? 'Chat 1:1' : key === 'config' ? 'Configuração' : key === 'memory' ? 'Memória' : 'Rotinas'))
|
|
1785
|
+
['chat', 'config', 'memory', 'routines', 'library'].map((key) => h('button', { key, className: cx('bots-subtab', tab === key && 'active'), onClick: () => setTab(key) }, key === 'chat' ? 'Chat 1:1' : key === 'config' ? 'Configuração' : key === 'memory' ? 'Memória' : key === 'routines' ? 'Rotinas' : 'Biblioteca'))
|
|
1606
1786
|
),
|
|
1607
1787
|
tab === 'routines' ? h(BotRoutines, { store, bot }) : tab === 'chat' ? h(ChatThread, {
|
|
1608
1788
|
messages,
|
|
@@ -1629,7 +1809,7 @@ window.__ModuleLoader__.load({
|
|
|
1629
1809
|
onSave: (patch) => store.api(`bots/${bot.id}`, patch).catch(() => {}),
|
|
1630
1810
|
onOpenConfig: () => setTab('config')
|
|
1631
1811
|
}
|
|
1632
|
-
}) : tab === 'config' ? h(BotConfig, { store, bot, onChanged: () => {} }) : h(BotMemory, { store, bot }),
|
|
1812
|
+
}) : tab === 'config' ? h(BotConfig, { store, bot, onChanged: () => {} }) : tab === 'memory' ? h(BotMemory, { store, bot }) : h(LibraryPanel, { messages, title: bot.name }),
|
|
1633
1813
|
confirm ? h(ConfirmModal, {
|
|
1634
1814
|
title: 'Apagar bot',
|
|
1635
1815
|
text: `Apagar ${bot.name}? O histórico do chat some e ele sai dos grupos.`,
|
|
@@ -1717,6 +1897,7 @@ window.__ModuleLoader__.load({
|
|
|
1717
1897
|
const [settings, setSettings] = useState(false)
|
|
1718
1898
|
const [confirmDelete, setConfirmDelete] = useState(false)
|
|
1719
1899
|
const [traceMessage, setTraceMessage] = useState(null)
|
|
1900
|
+
const [groupTab, setGroupTab] = useState('chat')
|
|
1720
1901
|
const typing = state.typing[group.id]
|
|
1721
1902
|
const members = group.memberBotIds.map((id) => state.bots.find((bot) => bot.id === id)).filter(Boolean)
|
|
1722
1903
|
function send(text, reply, attachments) {
|
|
@@ -1744,7 +1925,10 @@ window.__ModuleLoader__.load({
|
|
|
1744
1925
|
h('button', { className: 'bots-btn sm danger', onClick: () => setConfirmDelete(true) }, h(IconTrash, { size: 13 }), 'Apagar')
|
|
1745
1926
|
)
|
|
1746
1927
|
),
|
|
1747
|
-
h(
|
|
1928
|
+
h('div', { className: 'bots-subtabs' },
|
|
1929
|
+
['chat', 'library'].map((key) => h('button', { key, className: cx('bots-subtab', groupTab === key && 'active'), onClick: () => setGroupTab(key) }, key === 'chat' ? 'Chat do grupo' : 'Biblioteca'))
|
|
1930
|
+
),
|
|
1931
|
+
groupTab === 'library' ? h(LibraryPanel, { messages, title: group.name }) : h(ChatThread, {
|
|
1748
1932
|
messages,
|
|
1749
1933
|
botMap,
|
|
1750
1934
|
typing,
|
|
@@ -1957,6 +2141,7 @@ window.__ModuleLoader__.load({
|
|
|
1957
2141
|
const state = useStore(store)
|
|
1958
2142
|
const [filter, setFilter] = useState('all')
|
|
1959
2143
|
const [query, setQuery] = useState('')
|
|
2144
|
+
const [preview, setPreview] = useState(null)
|
|
1960
2145
|
useEffect(() => { store.refreshAudit() }, [state.lastAuditAt])
|
|
1961
2146
|
const rows = (state.audit ?? []).filter((row) => {
|
|
1962
2147
|
if (filter === 'approvals') return row.kind === 'approval' || row.kind === 'approval-result'
|
|
@@ -2090,9 +2275,25 @@ window.__ModuleLoader__.load({
|
|
|
2090
2275
|
)
|
|
2091
2276
|
}
|
|
2092
2277
|
|
|
2278
|
+
function DownloadPresentedAction({ actionUrl }) {
|
|
2279
|
+
if (!actionUrl) return null
|
|
2280
|
+
const query = actionUrl.includes('?') ? actionUrl.slice(actionUrl.indexOf('?') + 1) : ''
|
|
2281
|
+
const href = `/bots-api/present-download?${query}${query ? '&' : ''}download=1`
|
|
2282
|
+
return h('a', {
|
|
2283
|
+
href,
|
|
2284
|
+
download: '',
|
|
2285
|
+
title: 'Baixar arquivo',
|
|
2286
|
+
style: { display: 'inline-flex', alignItems: 'center', gap: 4, height: 24, padding: '0 8px', borderRadius: 6, border: '1px solid var(--dsw-alias-border-l2)', background: 'var(--dsw-alias-bg-layer-1)', color: 'var(--dsw-alias-label-primary)', fontSize: 11, fontWeight: 600, textDecoration: 'none', whiteSpace: 'nowrap' }
|
|
2287
|
+
}, '↓ Baixar')
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2093
2290
|
function apply(ctx) {
|
|
2094
2291
|
const store = createClientStore()
|
|
2095
2292
|
ctx.effect(() => () => store.close(), 'bots client store')
|
|
2293
|
+
ctx.slots.inject('deliverables.file.actions', () => ctx.slots.register({
|
|
2294
|
+
name: 'deliverables.file.actions',
|
|
2295
|
+
id: 'bots-download'
|
|
2296
|
+
}, DownloadPresentedAction))
|
|
2096
2297
|
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
|
|
2097
2298
|
name: 'sidebar.panellist',
|
|
2098
2299
|
id: 'bots',
|
package/index.js
CHANGED
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -210,11 +210,14 @@ export class BotsApi {
|
|
|
210
210
|
approvals: this.confirmations.list()
|
|
211
211
|
})
|
|
212
212
|
}
|
|
213
|
+
if (req.method === 'GET' && pathname === '/bots-api/present-download') {
|
|
214
|
+
return this.presentedDownload(req, res)
|
|
215
|
+
}
|
|
213
216
|
if (req.method === 'GET' && pathname.startsWith('/bots-api/artifacts/')) {
|
|
214
|
-
return this.handleArtifact(pathname.slice('/bots-api/artifacts/'.length), res)
|
|
217
|
+
return this.handleArtifact(pathname.slice('/bots-api/artifacts/'.length), res, new URL(req.url, 'http://x').searchParams.get('download') === '1')
|
|
215
218
|
}
|
|
216
219
|
if (req.method === 'GET' && pathname.startsWith('/bots-api/uploads/')) {
|
|
217
|
-
return this.handleUpload(pathname.slice('/bots-api/uploads/'.length), res)
|
|
220
|
+
return this.handleUpload(pathname.slice('/bots-api/uploads/'.length), res, new URL(req.url, 'http://x').searchParams.get('download') === '1')
|
|
218
221
|
}
|
|
219
222
|
const memoryMatch = /^\/bots-api\/bots\/([^/]+)\/memories$/u.exec(pathname)
|
|
220
223
|
if (req.method === 'GET' && memoryMatch) {
|
|
@@ -289,14 +292,19 @@ export class BotsApi {
|
|
|
289
292
|
}
|
|
290
293
|
}
|
|
291
294
|
|
|
292
|
-
async handleArtifact(id, res) {
|
|
295
|
+
async handleArtifact(id, res, download = false) {
|
|
293
296
|
if (!/^[A-Za-z0-9_.-]+$/u.test(id) || id.includes('..')) return sendText(res, 400, 'bad artifact')
|
|
294
297
|
const file = this.store.artifactPath(id)
|
|
295
298
|
try {
|
|
296
299
|
const data = await fs.readFile(file)
|
|
297
300
|
const ext = path.extname(id).toLowerCase()
|
|
298
301
|
const type = ext === '.png' ? 'image/png' : ext === '.jpg' || ext === '.jpeg' ? 'image/jpeg' : 'application/octet-stream'
|
|
299
|
-
res.writeHead(200, {
|
|
302
|
+
res.writeHead(200, {
|
|
303
|
+
'content-type': type,
|
|
304
|
+
'content-disposition': `${download ? 'attachment' : 'inline'}; filename="${path.basename(id)}"`,
|
|
305
|
+
'cache-control': 'private, max-age=300',
|
|
306
|
+
'x-content-type-options': 'nosniff'
|
|
307
|
+
})
|
|
300
308
|
res.end(data)
|
|
301
309
|
} catch {
|
|
302
310
|
sendText(res, 404, 'not found')
|
|
@@ -487,6 +495,37 @@ export class BotsApi {
|
|
|
487
495
|
return sendJson(res, 200, { ok: true, bot: publicBot(bot, this.runner) })
|
|
488
496
|
}
|
|
489
497
|
|
|
498
|
+
async presentedDownload(req, res) {
|
|
499
|
+
const url = new URL(req.url, 'http://localhost')
|
|
500
|
+
const id = url.searchParams.get('sessionId') ?? ''
|
|
501
|
+
const seq = Number(url.searchParams.get('seq'))
|
|
502
|
+
const index = Number(url.searchParams.get('index'))
|
|
503
|
+
if (!id || !Number.isSafeInteger(seq) || seq < 0 || !Number.isSafeInteger(index) || index < 0) return sendText(res, 400, 'coordenadas inválidas')
|
|
504
|
+
try {
|
|
505
|
+
const read = await this.ctx.sessionQuery.readEvent({ sessionId: id, seq, before: 0, after: 0 })
|
|
506
|
+
const target = read?.target
|
|
507
|
+
const session = read?.session
|
|
508
|
+
const file = target?.type === 'deliverables/presented' ? target.data?.files?.[index] : null
|
|
509
|
+
if (!file || typeof file.path !== 'string') return sendText(res, 404, 'arquivo apresentado não encontrado')
|
|
510
|
+
const scope = { sessionId: id, workspaceRoot: session?.cwd ?? this.ctx.sandboxPolicy.workspaceRoot }
|
|
511
|
+
await this.ctx.workspaceFiles.stat(scope, file.path)
|
|
512
|
+
const bytes = await this.ctx.workspaceFiles.readBytes(scope, file.path, {})
|
|
513
|
+
const name = path.basename(file.path)
|
|
514
|
+
const ext = path.extname(name).toLowerCase()
|
|
515
|
+
const types = { '.zip': 'application/zip', '.tgz': 'application/gzip', '.gz': 'application/gzip', '.sh': 'text/x-shellscript; charset=utf-8', '.txt': 'text/plain; charset=utf-8', '.md': 'text/markdown; charset=utf-8', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.pdf': 'application/pdf', '.json': 'application/json; charset=utf-8', '.csv': 'text/csv; charset=utf-8' }
|
|
516
|
+
res.writeHead(200, {
|
|
517
|
+
'content-type': types[ext] ?? 'application/octet-stream',
|
|
518
|
+
'content-length': bytes.data.length,
|
|
519
|
+
'content-disposition': `attachment; filename="${name.replace(/["\r\n]/gu, '_')}"`,
|
|
520
|
+
'cache-control': 'no-store',
|
|
521
|
+
'x-content-type-options': 'nosniff'
|
|
522
|
+
})
|
|
523
|
+
res.end(bytes.data)
|
|
524
|
+
} catch {
|
|
525
|
+
sendText(res, 404, 'arquivo indisponível')
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
490
529
|
async upload(body, res) {
|
|
491
530
|
try {
|
|
492
531
|
const name = asString(body?.name, 200, 'arquivo')
|
|
@@ -503,7 +542,7 @@ export class BotsApi {
|
|
|
503
542
|
}
|
|
504
543
|
}
|
|
505
544
|
|
|
506
|
-
async handleUpload(id, res) {
|
|
545
|
+
async handleUpload(id, res, download = false) {
|
|
507
546
|
const meta = this.store.getUpload(String(id))
|
|
508
547
|
if (!meta) return sendText(res, 404, 'upload não encontrado')
|
|
509
548
|
try {
|
|
@@ -511,7 +550,7 @@ export class BotsApi {
|
|
|
511
550
|
res.writeHead(200, {
|
|
512
551
|
'content-type': meta.mediaType || 'application/octet-stream',
|
|
513
552
|
'content-length': buffer.length,
|
|
514
|
-
'content-disposition':
|
|
553
|
+
'content-disposition': `${download ? 'attachment' : 'inline'}; filename="${String(meta.name).replace(/["\r\n]/gu, '_')}"`,
|
|
515
554
|
'cache-control': 'private, max-age=3600',
|
|
516
555
|
'x-content-type-options': 'nosniff'
|
|
517
556
|
})
|