@swarmclawai/swarmclaw 1.2.6 → 1.2.9
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/README.md +54 -23
- package/next.config.ts +1 -0
- package/package.json +4 -3
- package/scripts/easy-setup.mjs +1 -1
- package/scripts/postinstall.mjs +1 -1
- package/skills/swarmclaw.md +115 -0
- package/skills/tools/browser.md +131 -0
- package/skills/tools/execute.md +98 -0
- package/skills/tools/files.md +98 -0
- package/skills/tools/memory.md +104 -0
- package/skills/tools/platform.md +144 -0
- package/skills/tools/skills.md +83 -0
- package/src/app/agents/[id]/page.tsx +1 -18
- package/src/app/api/agents/thread-route.test.ts +0 -1
- package/src/app/api/approvals/route.test.ts +6 -22
- package/src/app/api/chats/[id]/messages/route.ts +23 -19
- package/src/app/api/chats/messages-route.test.ts +105 -51
- package/src/app/api/connectors/route.ts +2 -2
- package/src/app/api/mcp-servers/[id]/test/route.ts +3 -2
- package/src/app/api/openclaw/deploy/route.ts +2 -0
- package/src/app/api/portability/export/route.ts +8 -0
- package/src/app/api/portability/import/route.test.ts +80 -0
- package/src/app/api/portability/import/route.ts +28 -0
- package/src/app/api/settings/route.ts +0 -2
- package/src/app/api/setup/doctor/route.ts +4 -4
- package/src/app/api/wallets/[id]/route.ts +15 -157
- package/src/app/api/wallets/generate/route.ts +22 -0
- package/src/app/api/wallets/route.test.ts +147 -0
- package/src/app/api/wallets/route.ts +13 -95
- package/src/app/autonomy/page.tsx +2 -57
- package/src/app/protocols/page.tsx +2 -21
- package/src/app/settings/page.tsx +0 -9
- package/src/app/wallets/page.tsx +105 -5
- package/src/cli/index.js +21 -33
- package/src/cli/spec.js +19 -30
- package/src/components/agents/agent-chat-list.tsx +23 -1
- package/src/components/agents/agent-sheet.tsx +2 -40
- package/src/components/agents/inspector-panel.tsx +165 -131
- package/src/components/chat/chat-area.tsx +38 -9
- package/src/components/chat/chat-card.tsx +0 -31
- package/src/components/chat/message-bubble.tsx +1 -108
- package/src/components/chat/message-list.tsx +33 -19
- package/src/components/connectors/connector-sheet.tsx +25 -1
- package/src/components/gateways/gateway-sheet.tsx +5 -2
- package/src/components/layout/sidebar-rail.tsx +6 -10
- package/src/components/projects/project-detail.tsx +3 -35
- package/src/components/projects/tabs/overview-tab.tsx +3 -59
- package/src/components/projects/tabs/work-tab.tsx +7 -77
- package/src/components/protocols/structured-session-launcher.tsx +1 -22
- package/src/components/shared/connector-platform-icon.tsx +1 -0
- package/src/components/tasks/task-card.tsx +4 -34
- package/src/components/tasks/task-sheet.tsx +6 -36
- package/src/components/wallets/wallet-list.tsx +150 -0
- package/src/lib/agent-execute-defaults.test.ts +24 -0
- package/src/lib/agent-execute-defaults.ts +62 -0
- package/src/lib/app/navigation.test.ts +0 -13
- package/src/lib/app/navigation.ts +2 -7
- package/src/lib/app/view-constants.ts +14 -19
- package/src/lib/chat/queued-message-queue.test.ts +134 -1
- package/src/lib/chat/queued-message-queue.ts +77 -2
- package/src/lib/server/agents/agent-service.ts +5 -0
- package/src/lib/server/agents/agent-thread-session.ts +0 -1
- package/src/lib/server/agents/delegation-advisory.test.ts +0 -1
- package/src/lib/server/agents/delegation-jobs.test.ts +0 -69
- package/src/lib/server/agents/delegation-jobs.ts +0 -25
- package/src/lib/server/agents/main-agent-loop.ts +1 -49
- package/src/lib/server/agents/subagent-runtime.ts +0 -1
- package/src/lib/server/approval-match.ts +0 -85
- package/src/lib/server/approvals.test.ts +6 -6
- package/src/lib/server/approvals.ts +0 -6
- package/src/lib/server/autonomy/supervisor-reflection.test.ts +0 -1
- package/src/lib/server/builtin-extensions.ts +1 -2
- package/src/lib/server/capability-router.test.ts +0 -2
- package/src/lib/server/chat-execution/chat-execution-advanced.test.ts +1 -1
- package/src/lib/server/chat-execution/chat-execution-tool-events.test.ts +15 -14
- package/src/lib/server/chat-execution/chat-execution-types.ts +0 -2
- package/src/lib/server/chat-execution/chat-execution-utils.ts +2 -4
- package/src/lib/server/chat-execution/chat-streaming-utils.ts +2 -30
- package/src/lib/server/chat-execution/chat-turn-finalization.ts +1 -36
- package/src/lib/server/chat-execution/chat-turn-preparation.ts +81 -64
- package/src/lib/server/chat-execution/chat-turn-stream-execution.ts +4 -0
- package/src/lib/server/chat-execution/continuation-evaluator.ts +8 -0
- package/src/lib/server/chat-execution/iteration-event-handler.ts +0 -24
- package/src/lib/server/chat-execution/memory-mutation-tools.ts +1 -1
- package/src/lib/server/chat-execution/message-classifier.test.ts +0 -45
- package/src/lib/server/chat-execution/message-classifier.ts +11 -16
- package/src/lib/server/chat-execution/prompt-builder.test.ts +27 -0
- package/src/lib/server/chat-execution/prompt-builder.ts +14 -31
- package/src/lib/server/chat-execution/prompt-mode.test.ts +24 -0
- package/src/lib/server/chat-execution/prompt-mode.ts +5 -1
- package/src/lib/server/chat-execution/prompt-sections.ts +0 -1
- package/src/lib/server/chat-execution/situational-awareness.test.ts +2 -73
- package/src/lib/server/chat-execution/situational-awareness.ts +4 -38
- package/src/lib/server/chat-execution/stream-agent-chat.test.ts +13 -126
- package/src/lib/server/chat-execution/stream-agent-chat.ts +46 -21
- package/src/lib/server/chat-execution/stream-continuation.test.ts +4 -52
- package/src/lib/server/chat-execution/stream-continuation.ts +6 -48
- package/src/lib/server/chatrooms/chatroom-routing.test.ts +4 -0
- package/src/lib/server/chatrooms/session-mailbox.ts +0 -10
- package/src/lib/server/chats/chat-session-service.ts +3 -5
- package/src/lib/server/connectors/connector-inbound.ts +0 -1
- package/src/lib/server/connectors/connector-lifecycle.ts +19 -3
- package/src/lib/server/connectors/connector-service.ts +39 -9
- package/src/lib/server/connectors/discord.ts +2 -2
- package/src/lib/server/connectors/matrix.ts +3 -2
- package/src/lib/server/connectors/signal.ts +5 -4
- package/src/lib/server/connectors/slack.ts +10 -9
- package/src/lib/server/connectors/swarmdock-bidding.ts +74 -0
- package/src/lib/server/connectors/swarmdock-payloads.test.ts +85 -0
- package/src/lib/server/connectors/swarmdock-secret.test.ts +128 -0
- package/src/lib/server/connectors/swarmdock-secret.ts +152 -0
- package/src/lib/server/connectors/swarmdock-tasks.ts +119 -0
- package/src/lib/server/connectors/swarmdock.ts +255 -0
- package/src/lib/server/connectors/teams.ts +3 -2
- package/src/lib/server/connectors/telegram.ts +4 -4
- package/src/lib/server/connectors/whatsapp.ts +2 -2
- package/src/lib/server/daemon/controller.ts +7 -0
- package/src/lib/server/execution-brief.test.ts +2 -25
- package/src/lib/server/execution-brief.ts +12 -35
- package/src/lib/server/execution-engine/task-attempt.ts +0 -1
- package/src/lib/server/gateways/gateway-profile-service.ts +19 -1
- package/src/lib/server/messages/message-repository.test.ts +70 -0
- package/src/lib/server/messages/message-repository.ts +11 -6
- package/src/lib/server/openclaw/deploy.ts +32 -2
- package/src/lib/server/persistence/storage-context.ts +0 -5
- package/src/lib/server/plugins-advanced.test.ts +1 -2
- package/src/lib/server/portability/export.ts +109 -0
- package/src/lib/server/portability/import.ts +159 -0
- package/src/lib/server/protocols/protocol-normalization.ts +0 -4
- package/src/lib/server/protocols/protocol-queries.ts +0 -6
- package/src/lib/server/protocols/protocol-run-lifecycle.ts +4 -32
- package/src/lib/server/protocols/protocol-service.ts +0 -1
- package/src/lib/server/protocols/protocol-step-helpers.ts +0 -4
- package/src/lib/server/protocols/protocol-step-processors.ts +0 -6
- package/src/lib/server/protocols/protocol-swarm.ts +0 -2
- package/src/lib/server/protocols/protocol-types.ts +0 -2
- package/src/lib/server/provider-health.ts +1 -10
- package/src/lib/server/runtime/daemon-state/core.ts +0 -9
- package/src/lib/server/runtime/daemon-state.test.ts +0 -35
- package/src/lib/server/runtime/heartbeat-service.ts +3 -23
- package/src/lib/server/runtime/process-manager.ts +13 -9
- package/src/lib/server/runtime/queue/core.ts +11 -33
- package/src/lib/server/runtime/runtime-storage-write-paths.test.ts +6 -6
- package/src/lib/server/runtime/scheduler.ts +0 -13
- package/src/lib/server/runtime/session-run-manager/drain.ts +0 -24
- package/src/lib/server/runtime/session-run-manager/enqueue.ts +0 -1
- package/src/lib/server/runtime/session-run-manager/queries.ts +15 -1
- package/src/lib/server/runtime/session-run-manager/recovery.ts +0 -1
- package/src/lib/server/runtime/session-run-manager.test.ts +58 -28
- package/src/lib/server/sandbox/session-runtime.test.ts +18 -1
- package/src/lib/server/sandbox/session-runtime.ts +40 -28
- package/src/lib/server/session-tools/autonomy-tools.test.ts +7 -9
- package/src/lib/server/session-tools/context.ts +1 -1
- package/src/lib/server/session-tools/credential-env.ts +109 -0
- package/src/lib/server/session-tools/crud.ts +3 -17
- package/src/lib/server/session-tools/delegate.ts +0 -4
- package/src/lib/server/session-tools/edit_file.ts +3 -2
- package/src/lib/server/session-tools/execute.test.ts +58 -0
- package/src/lib/server/session-tools/execute.ts +334 -0
- package/src/lib/server/session-tools/files-tool.ts +635 -0
- package/src/lib/server/session-tools/index.ts +14 -8
- package/src/lib/server/session-tools/memory-tool.ts +242 -0
- package/src/lib/server/session-tools/memory.ts +1 -1
- package/src/lib/server/session-tools/openclaw-nodes.ts +3 -2
- package/src/lib/server/session-tools/openclaw-workspace.ts +3 -2
- package/src/lib/server/session-tools/platform-tool.ts +617 -0
- package/src/lib/server/session-tools/session-info.ts +3 -2
- package/src/lib/server/session-tools/session-tools-wiring.test.ts +3 -4
- package/src/lib/server/session-tools/shell.ts +7 -122
- package/src/lib/server/session-tools/skills-tool.ts +396 -0
- package/src/lib/server/session-tools/team-context.ts +0 -3
- package/src/lib/server/session-tools/web.ts +2 -2
- package/src/lib/server/storage-normalization.ts +10 -0
- package/src/lib/server/storage.ts +18 -45
- package/src/lib/server/tasks/task-checkout.ts +59 -0
- package/src/lib/server/tasks/task-lifecycle.ts +2 -0
- package/src/lib/server/tasks/task-route-service.ts +4 -26
- package/src/lib/server/tasks/task-service.ts +0 -7
- package/src/lib/server/tool-aliases.ts +2 -2
- package/src/lib/server/tool-capability-policy-advanced.test.ts +13 -6
- package/src/lib/server/tool-capability-policy.test.ts +2 -1
- package/src/lib/server/tool-capability-policy.ts +60 -35
- package/src/lib/server/tool-planning.ts +11 -12
- package/src/lib/server/universal-tool-access.ts +0 -1
- package/src/lib/server/wallets/wallet-crypto.ts +33 -0
- package/src/lib/server/wallets/wallet-repository.ts +24 -0
- package/src/lib/server/wallets/wallet-service.ts +119 -0
- package/src/lib/server/working-state/extraction.ts +8 -42
- package/src/lib/server/working-state/normalization.ts +10 -103
- package/src/lib/server/working-state/service.ts +12 -21
- package/src/lib/setup-defaults.ts +5 -0
- package/src/lib/strip-internal-metadata.test.ts +1 -1
- package/src/lib/strip-internal-metadata.ts +1 -1
- package/src/lib/tool-definitions.ts +1 -1
- package/src/lib/validation/schemas.test.ts +16 -0
- package/src/lib/validation/schemas.ts +49 -2
- package/src/stores/slices/data-slice.ts +5 -1
- package/src/stores/slices/ui-slice.ts +0 -4
- package/src/stores/use-chat-store.test.ts +231 -0
- package/src/stores/use-chat-store.ts +62 -13
- package/src/types/agent.ts +264 -0
- package/src/types/app-settings.ts +173 -0
- package/src/types/approval.ts +25 -0
- package/src/types/connector.ts +188 -0
- package/src/types/extension.ts +386 -0
- package/src/types/index.ts +16 -3555
- package/src/types/message.ts +56 -0
- package/src/types/misc.ts +737 -0
- package/src/types/protocol.ts +420 -0
- package/src/types/provider.ts +52 -0
- package/src/types/run.ts +180 -0
- package/src/types/schedule.ts +59 -0
- package/src/types/session.ts +215 -0
- package/src/types/skill.ts +157 -0
- package/src/types/swarmdock.ts +29 -0
- package/src/types/task.ts +144 -0
- package/src/types/working-state.ts +204 -0
- package/src/views/settings/section-heartbeat.tsx +2 -2
- package/src/views/settings/section-runtime-loop.tsx +0 -14
- package/src/app/api/canvas/[sessionId]/route.ts +0 -35
- package/src/app/api/missions/[id]/actions/route.ts +0 -31
- package/src/app/api/missions/[id]/events/route.ts +0 -14
- package/src/app/api/missions/[id]/route.ts +0 -10
- package/src/app/api/missions/route.test.ts +0 -244
- package/src/app/api/missions/route.ts +0 -57
- package/src/app/api/wallets/[id]/approve/route.ts +0 -79
- package/src/app/api/wallets/[id]/balance-history/route.ts +0 -18
- package/src/app/api/wallets/[id]/send/route.ts +0 -113
- package/src/app/api/wallets/[id]/transactions/route.ts +0 -18
- package/src/app/missions/[id]/page.tsx +0 -3
- package/src/app/missions/page.tsx +0 -685
- package/src/components/canvas/canvas-panel.tsx +0 -267
- package/src/components/wallets/wallet-approval-dialog.tsx +0 -107
- package/src/components/wallets/wallet-panel.tsx +0 -1010
- package/src/components/wallets/wallet-section.tsx +0 -260
- package/src/features/missions/queries.ts +0 -23
- package/src/lib/canvas-content.test.ts +0 -360
- package/src/lib/canvas-content.ts +0 -198
- package/src/lib/server/canvas-content.test.ts +0 -32
- package/src/lib/server/canvas-content.ts +0 -6
- package/src/lib/server/ethereum.ts +0 -591
- package/src/lib/server/evm-swap.ts +0 -476
- package/src/lib/server/missions/mission-intent.test.ts +0 -63
- package/src/lib/server/missions/mission-intent.ts +0 -569
- package/src/lib/server/missions/mission-repository.ts +0 -74
- package/src/lib/server/missions/mission-service/actions.ts +0 -6
- package/src/lib/server/missions/mission-service/bindings.ts +0 -9
- package/src/lib/server/missions/mission-service/context.ts +0 -4
- package/src/lib/server/missions/mission-service/core.ts +0 -2271
- package/src/lib/server/missions/mission-service/queries.ts +0 -12
- package/src/lib/server/missions/mission-service/recovery.ts +0 -5
- package/src/lib/server/missions/mission-service/ticks.ts +0 -9
- package/src/lib/server/missions/mission-service.test.ts +0 -888
- package/src/lib/server/missions/mission-service.ts +0 -6
- package/src/lib/server/session-tools/canvas.ts +0 -105
- package/src/lib/server/session-tools/sandbox.ts +0 -281
- package/src/lib/server/session-tools/wallet-tool.test.ts +0 -150
- package/src/lib/server/session-tools/wallet.ts +0 -1287
- package/src/lib/server/solana.ts +0 -327
- package/src/lib/server/wallet/wallet-execution.test.ts +0 -198
- package/src/lib/server/wallet/wallet-portfolio.test.ts +0 -98
- package/src/lib/server/wallet/wallet-portfolio.ts +0 -772
- package/src/lib/server/wallet/wallet-service.test.ts +0 -81
- package/src/lib/server/wallet/wallet-service.ts +0 -225
- package/src/lib/wallet/wallet-transactions.test.ts +0 -75
- package/src/lib/wallet/wallet-transactions.ts +0 -43
- package/src/lib/wallet/wallet.test.ts +0 -333
- package/src/lib/wallet/wallet.ts +0 -183
- package/src/views/settings/section-wallets.tsx +0 -35
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CanvasActionItem,
|
|
3
|
-
CanvasBlock,
|
|
4
|
-
CanvasCardItem,
|
|
5
|
-
CanvasContent,
|
|
6
|
-
CanvasDocument,
|
|
7
|
-
CanvasMetricItem,
|
|
8
|
-
CanvasTableData,
|
|
9
|
-
} from '@/types'
|
|
10
|
-
|
|
11
|
-
function asObject(value: unknown): Record<string, unknown> | null {
|
|
12
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) return null
|
|
13
|
-
return value as Record<string, unknown>
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function asTrimmedString(value: unknown, max = 8000): string | null {
|
|
17
|
-
if (typeof value === 'number' || typeof value === 'boolean') return String(value).slice(0, max)
|
|
18
|
-
if (typeof value !== 'string') return null
|
|
19
|
-
const trimmed = value.trim()
|
|
20
|
-
return trimmed ? trimmed.slice(0, max) : null
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function asStringArray(value: unknown): string[] {
|
|
24
|
-
if (!Array.isArray(value)) return []
|
|
25
|
-
return value
|
|
26
|
-
.map((entry) => asTrimmedString(entry, 240))
|
|
27
|
-
.filter((entry): entry is string => Boolean(entry))
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function normalizeMetricItems(value: unknown): CanvasMetricItem[] {
|
|
31
|
-
if (!Array.isArray(value)) return []
|
|
32
|
-
const items: CanvasMetricItem[] = []
|
|
33
|
-
for (const entry of value) {
|
|
34
|
-
const row = asObject(entry)
|
|
35
|
-
if (!row) continue
|
|
36
|
-
const label = asTrimmedString(row.label, 120)
|
|
37
|
-
const metricValue = asTrimmedString(row.value, 120)
|
|
38
|
-
if (!label || !metricValue) continue
|
|
39
|
-
items.push({
|
|
40
|
-
label,
|
|
41
|
-
value: metricValue,
|
|
42
|
-
detail: asTrimmedString(row.detail, 240) || undefined,
|
|
43
|
-
tone: row.tone === 'positive' || row.tone === 'negative' || row.tone === 'warning' ? row.tone : 'default',
|
|
44
|
-
})
|
|
45
|
-
if (items.length >= 24) break
|
|
46
|
-
}
|
|
47
|
-
return items
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function normalizeCardItems(value: unknown): CanvasCardItem[] {
|
|
51
|
-
if (!Array.isArray(value)) return []
|
|
52
|
-
const items: CanvasCardItem[] = []
|
|
53
|
-
for (const entry of value) {
|
|
54
|
-
const row = asObject(entry)
|
|
55
|
-
if (!row) continue
|
|
56
|
-
const title = asTrimmedString(row.title, 180)
|
|
57
|
-
if (!title) continue
|
|
58
|
-
items.push({
|
|
59
|
-
title,
|
|
60
|
-
body: asTrimmedString(row.body, 1600) || undefined,
|
|
61
|
-
meta: asTrimmedString(row.meta, 200) || undefined,
|
|
62
|
-
tone: row.tone === 'positive' || row.tone === 'negative' || row.tone === 'warning' ? row.tone : 'default',
|
|
63
|
-
})
|
|
64
|
-
if (items.length >= 24) break
|
|
65
|
-
}
|
|
66
|
-
return items
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function normalizeActionItems(value: unknown): CanvasActionItem[] {
|
|
70
|
-
if (!Array.isArray(value)) return []
|
|
71
|
-
const items: CanvasActionItem[] = []
|
|
72
|
-
for (const entry of value) {
|
|
73
|
-
const row = asObject(entry)
|
|
74
|
-
if (!row) continue
|
|
75
|
-
const label = asTrimmedString(row.label, 120)
|
|
76
|
-
if (!label) continue
|
|
77
|
-
items.push({
|
|
78
|
-
label,
|
|
79
|
-
href: asTrimmedString(row.href, 1000) || undefined,
|
|
80
|
-
note: asTrimmedString(row.note, 240) || undefined,
|
|
81
|
-
intent: row.intent === 'primary' || row.intent === 'success' || row.intent === 'danger' ? row.intent : 'secondary',
|
|
82
|
-
})
|
|
83
|
-
if (items.length >= 24) break
|
|
84
|
-
}
|
|
85
|
-
return items
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function normalizeTable(value: unknown): CanvasTableData | null {
|
|
89
|
-
const row = asObject(value)
|
|
90
|
-
if (!row) return null
|
|
91
|
-
const columns = asStringArray(row.columns).slice(0, 20)
|
|
92
|
-
if (!columns.length) return null
|
|
93
|
-
const rows = Array.isArray(row.rows)
|
|
94
|
-
? row.rows
|
|
95
|
-
.map((entry) => Array.isArray(entry)
|
|
96
|
-
? entry.slice(0, columns.length).map((cell) => (
|
|
97
|
-
typeof cell === 'string'
|
|
98
|
-
|| typeof cell === 'number'
|
|
99
|
-
|| typeof cell === 'boolean'
|
|
100
|
-
|| cell === null
|
|
101
|
-
? cell
|
|
102
|
-
: JSON.stringify(cell)
|
|
103
|
-
))
|
|
104
|
-
: null)
|
|
105
|
-
.filter((entry): entry is Array<string | number | boolean | null> => Array.isArray(entry))
|
|
106
|
-
.slice(0, 100)
|
|
107
|
-
: []
|
|
108
|
-
return rows.length
|
|
109
|
-
? {
|
|
110
|
-
columns,
|
|
111
|
-
rows,
|
|
112
|
-
caption: asTrimmedString(row.caption, 240) || undefined,
|
|
113
|
-
}
|
|
114
|
-
: null
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function normalizeBlock(value: unknown): CanvasBlock | null {
|
|
118
|
-
const row = asObject(value)
|
|
119
|
-
if (!row) return null
|
|
120
|
-
const title = asTrimmedString(row.title, 160) || undefined
|
|
121
|
-
switch (row.type) {
|
|
122
|
-
case 'markdown': {
|
|
123
|
-
const markdown = asTrimmedString(row.markdown, 20_000)
|
|
124
|
-
return markdown ? { type: 'markdown', title, markdown } : null
|
|
125
|
-
}
|
|
126
|
-
case 'metrics': {
|
|
127
|
-
const items = normalizeMetricItems(row.items)
|
|
128
|
-
return items.length ? { type: 'metrics', title, items } : null
|
|
129
|
-
}
|
|
130
|
-
case 'cards': {
|
|
131
|
-
const items = normalizeCardItems(row.items)
|
|
132
|
-
return items.length ? { type: 'cards', title, items } : null
|
|
133
|
-
}
|
|
134
|
-
case 'table': {
|
|
135
|
-
const table = normalizeTable(row.table)
|
|
136
|
-
return table ? { type: 'table', title, table } : null
|
|
137
|
-
}
|
|
138
|
-
case 'code': {
|
|
139
|
-
const code = asTrimmedString(row.code, 20_000)
|
|
140
|
-
return code ? { type: 'code', title, code, language: asTrimmedString(row.language, 60) || undefined } : null
|
|
141
|
-
}
|
|
142
|
-
case 'actions': {
|
|
143
|
-
const items = normalizeActionItems(row.items)
|
|
144
|
-
return items.length ? { type: 'actions', title, items } : null
|
|
145
|
-
}
|
|
146
|
-
default:
|
|
147
|
-
return null
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function normalizeCanvasDocument(value: unknown): CanvasDocument | null {
|
|
152
|
-
const row = asObject(value)
|
|
153
|
-
if (!row) return null
|
|
154
|
-
const blocks = Array.isArray(row.blocks)
|
|
155
|
-
? row.blocks.map((entry) => normalizeBlock(entry)).filter((entry): entry is CanvasBlock => entry !== null).slice(0, 24)
|
|
156
|
-
: []
|
|
157
|
-
if (!blocks.length) return null
|
|
158
|
-
return {
|
|
159
|
-
kind: 'structured',
|
|
160
|
-
title: asTrimmedString(row.title, 180) || undefined,
|
|
161
|
-
subtitle: asTrimmedString(row.subtitle, 320) || undefined,
|
|
162
|
-
theme: row.theme === 'sky' || row.theme === 'emerald' || row.theme === 'amber' || row.theme === 'rose' ? row.theme : 'slate',
|
|
163
|
-
blocks,
|
|
164
|
-
updatedAt: typeof row.updatedAt === 'number' && Number.isFinite(row.updatedAt) ? row.updatedAt : Date.now(),
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function isCanvasDocument(value: unknown): value is CanvasDocument {
|
|
169
|
-
return normalizeCanvasDocument(value) !== null
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function normalizeCanvasContent(value: unknown): CanvasContent {
|
|
173
|
-
if (typeof value === 'string') return value || null
|
|
174
|
-
if (value === null || value === undefined) return null
|
|
175
|
-
return normalizeCanvasDocument(value)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function summarizeCanvasContent(content: CanvasContent): Record<string, unknown> {
|
|
179
|
-
if (!content) {
|
|
180
|
-
return { kind: 'empty', hasContent: false, contentLength: 0, preview: null }
|
|
181
|
-
}
|
|
182
|
-
if (typeof content === 'string') {
|
|
183
|
-
return {
|
|
184
|
-
kind: 'html',
|
|
185
|
-
hasContent: true,
|
|
186
|
-
contentLength: content.length,
|
|
187
|
-
preview: content.slice(0, 500),
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return {
|
|
191
|
-
kind: 'structured',
|
|
192
|
-
hasContent: true,
|
|
193
|
-
blockCount: content.blocks.length,
|
|
194
|
-
title: content.title || null,
|
|
195
|
-
blockTypes: content.blocks.map((block) => block.type),
|
|
196
|
-
preview: JSON.stringify(content).slice(0, 500),
|
|
197
|
-
}
|
|
198
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict'
|
|
2
|
-
import { describe, it } from 'node:test'
|
|
3
|
-
|
|
4
|
-
import { normalizeCanvasDocument } from './canvas-content'
|
|
5
|
-
|
|
6
|
-
describe('normalizeCanvasDocument', () => {
|
|
7
|
-
it('filters invalid metric rows and keeps valid metrics blocks', () => {
|
|
8
|
-
const result = normalizeCanvasDocument({
|
|
9
|
-
title: 'Smoke',
|
|
10
|
-
blocks: [
|
|
11
|
-
{
|
|
12
|
-
type: 'metrics',
|
|
13
|
-
items: [
|
|
14
|
-
{ label: 'Healthy', value: 12, tone: 'positive' },
|
|
15
|
-
{ label: '', value: 'skip-me' },
|
|
16
|
-
{ value: 'missing-label' },
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
assert.ok(result)
|
|
23
|
-
assert.equal(result?.blocks.length, 1)
|
|
24
|
-
assert.deepEqual(result?.blocks[0], {
|
|
25
|
-
type: 'metrics',
|
|
26
|
-
items: [
|
|
27
|
-
{ label: 'Healthy', value: '12', tone: 'positive', detail: undefined },
|
|
28
|
-
],
|
|
29
|
-
title: undefined,
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
})
|