@botbotgo/agent-harness 0.0.475 → 0.0.476
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 +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,206 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.split("\n")
|
|
39
|
-
.map((line) => line.trimEnd())
|
|
40
|
-
.filter((line) => line.trim().length > 0);
|
|
41
|
-
if (lines.length < 2 || !lines.every((line) => line.includes("|")) || !isMarkdownTableSeparator(lines[1] ?? "")) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
const rows = lines.map(parseMarkdownTableRow);
|
|
45
|
-
const header = rows[0] ?? [];
|
|
46
|
-
const body = rows.slice(2);
|
|
47
|
-
const columnCount = Math.max(header.length, ...body.map((row) => row.length));
|
|
48
|
-
const normalizedRows = [header, ...body].map((row) => Array.from({ length: columnCount }, (_, index) => renderInlineConsoleMarkdown(row[index] ?? "")));
|
|
49
|
-
const widths = Array.from({ length: columnCount }, (_, index) => Math.max(...normalizedRows.map((row) => stripAnsi(row[index] ?? "").length), 0));
|
|
50
|
-
const renderedWidth = widths.reduce((sum, width) => sum + width, 0) + (columnCount * 3) + 1;
|
|
51
|
-
if (renderedWidth > 120 || columnCount > 5) {
|
|
52
|
-
return renderMarkdownTableAsList(header, body);
|
|
53
|
-
}
|
|
54
|
-
const renderRow = (row) => `| ${row
|
|
55
|
-
.map((cell, index) => cell.padEnd(widths[index] + (cell.length - stripAnsi(cell).length)))
|
|
56
|
-
.join(" | ")} |`;
|
|
57
|
-
const separator = `|-${widths.map((width) => "-".repeat(Math.max(3, width))).join("-|-")}-|`;
|
|
58
|
-
return [renderRow(normalizedRows[0] ?? []), separator, ...normalizedRows.slice(1).map(renderRow)].join("\n");
|
|
59
|
-
}
|
|
60
|
-
function renderMarkdownTableAsList(header, body) {
|
|
61
|
-
const normalizedHeader = header.map((cell) => cell.trim()).filter(Boolean);
|
|
62
|
-
return body
|
|
63
|
-
.map((row, rowIndex) => {
|
|
64
|
-
const title = renderInlineConsoleMarkdown(row[0]?.trim() || `Row ${rowIndex + 1}`);
|
|
65
|
-
const details = normalizedHeader.slice(1).flatMap((label, index) => {
|
|
66
|
-
const value = row[index + 1]?.trim();
|
|
67
|
-
if (!value) {
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
return ` • ${renderInlineConsoleMarkdown(label)}: ${renderInlineConsoleMarkdown(value)}`;
|
|
71
|
-
});
|
|
72
|
-
return [`• ${title}`, ...details].join("\n");
|
|
73
|
-
})
|
|
74
|
-
.join("\n\n");
|
|
75
|
-
}
|
|
76
|
-
export function markdownToHtml(markdown) {
|
|
77
|
-
const normalized = markdown.replace(/\r\n/g, "\n").replace(/<br\s*\/?>/gi, "\n");
|
|
78
|
-
const blocks = normalized.split(/\n\n+/);
|
|
79
|
-
const html = [];
|
|
80
|
-
for (const block of blocks) {
|
|
81
|
-
const trimmed = block.trim();
|
|
82
|
-
if (!trimmed) {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (trimmed.startsWith("```") && trimmed.endsWith("```")) {
|
|
86
|
-
const lines = trimmed.split("\n");
|
|
87
|
-
const language = lines[0]?.slice(3).trim();
|
|
88
|
-
const code = lines.slice(1, -1).join("\n");
|
|
89
|
-
html.push(`<pre class="ah-code"><code${language ? ` data-language="${escapeHtml(language)}"` : ""}>${escapeHtml(code)}</code></pre>`);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (/^#{1,6}\s/.test(trimmed)) {
|
|
93
|
-
const match = trimmed.match(/^(#{1,6})\s+(.*)$/);
|
|
94
|
-
const level = match?.[1].length ?? 1;
|
|
95
|
-
const content = renderInlineMarkdown(match?.[2] ?? trimmed);
|
|
96
|
-
html.push(`<h${level}>${content}</h${level}>`);
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
if (trimmed.split("\n").every((line) => /^[-*]\s+/.test(line))) {
|
|
100
|
-
const items = trimmed
|
|
101
|
-
.split("\n")
|
|
102
|
-
.map((line) => line.replace(/^[-*]\s+/, ""))
|
|
103
|
-
.map((line) => `<li>${renderInlineMarkdown(line)}</li>`)
|
|
104
|
-
.join("");
|
|
105
|
-
html.push(`<ul>${items}</ul>`);
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
html.push(`<p>${trimmed
|
|
109
|
-
.split("\n")
|
|
110
|
-
.map((line) => renderInlineMarkdown(line))
|
|
111
|
-
.join("<br />")}</p>`);
|
|
112
|
-
}
|
|
113
|
-
return html.join("");
|
|
114
|
-
}
|
|
115
|
-
export function markdownToConsole(markdown) {
|
|
116
|
-
if (!markdown.includes("\n")) {
|
|
117
|
-
return renderInlineConsoleMarkdown(markdown.replace(/<br\s*\/?>/gi, "\n").trim());
|
|
118
|
-
}
|
|
119
|
-
const normalized = markdown
|
|
120
|
-
.replace(/\r\n/g, "\n")
|
|
121
|
-
.replace(/<br\s*\/?>/gi, "\n")
|
|
122
|
-
.replace(/^(#{1,6}\s+.+)$/gm, "\n$1\n")
|
|
123
|
-
.replace(/^(\s*[-*_=])(?:\s*\1){2,}\s*$/gm, "\n$&\n");
|
|
124
|
-
const blocks = normalized.split(/\n\n+/);
|
|
125
|
-
const rendered = [];
|
|
126
|
-
for (const block of blocks) {
|
|
127
|
-
const trimmed = block.trim();
|
|
128
|
-
if (!trimmed) {
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const table = renderMarkdownTable(trimmed);
|
|
132
|
-
if (table) {
|
|
133
|
-
rendered.push(table);
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
if (trimmed.startsWith("```") && trimmed.endsWith("```")) {
|
|
137
|
-
const lines = trimmed.split("\n");
|
|
138
|
-
const language = lines[0]?.slice(3).trim();
|
|
139
|
-
const code = lines.slice(1, -1);
|
|
140
|
-
const label = language ? ` ${language} ` : " code ";
|
|
141
|
-
const borderWidth = Math.max(label.length, 6);
|
|
142
|
-
rendered.push([
|
|
143
|
-
`\u001b[2m┌${"─".repeat(borderWidth)}\u001b[0m`,
|
|
144
|
-
`\u001b[2m│\u001b[0m${label}`,
|
|
145
|
-
...code.map((line) => ` ${line}`),
|
|
146
|
-
`\u001b[2m└${"─".repeat(borderWidth)}\u001b[0m`,
|
|
147
|
-
].join("\n"));
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
if (/^#{1,6}\s/.test(trimmed)) {
|
|
151
|
-
const match = trimmed.match(/^(#{1,6})\s+(.*)$/);
|
|
152
|
-
const level = match?.[1].length ?? 1;
|
|
153
|
-
const title = renderInlineConsoleMarkdown(match?.[2] ?? trimmed);
|
|
154
|
-
const underline = level === 1 ? "=" : "-";
|
|
155
|
-
const underlineWidth = Math.min(72, Math.max(3, title.replace(/\u001b\[[0-9;]*m/g, "").length));
|
|
156
|
-
rendered.push(`\u001b[1m${title}\u001b[0m\n\u001b[2m${underline.repeat(underlineWidth)}\u001b[0m`);
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
if (trimmed.split("\n").every((line) => /^\s*[-*]\s+/.test(line))) {
|
|
160
|
-
rendered.push(trimmed
|
|
161
|
-
.split("\n")
|
|
162
|
-
.map((line) => {
|
|
163
|
-
const match = line.match(/^(\s*)[-*]\s+(.*)$/);
|
|
164
|
-
const indent = match?.[1] ?? "";
|
|
165
|
-
const content = match?.[2] ?? line;
|
|
166
|
-
return `${indent}• ${content}`;
|
|
167
|
-
})
|
|
168
|
-
.map((line) => renderInlineConsoleMarkdown(line))
|
|
169
|
-
.join("\n"));
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
if (trimmed.split("\n").every((line) => /^\s*\d+\.\s+/.test(line))) {
|
|
173
|
-
rendered.push(trimmed
|
|
174
|
-
.split("\n")
|
|
175
|
-
.map((line) => renderInlineConsoleMarkdown(line))
|
|
176
|
-
.join("\n"));
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
if (trimmed.split("\n").every((line) => /^\s*>\s?/.test(line))) {
|
|
180
|
-
rendered.push(trimmed
|
|
181
|
-
.split("\n")
|
|
182
|
-
.map((line) => line.replace(/^\s*>\s?/, ""))
|
|
183
|
-
.map((line) => `\u001b[2m│\u001b[0m ${renderInlineConsoleMarkdown(line)}`)
|
|
184
|
-
.join("\n"));
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
if (/^([-*_=])(?:\s*\1){2,}$/.test(trimmed)) {
|
|
188
|
-
rendered.push(`\u001b[2m${"─".repeat(24)}\u001b[0m`);
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
rendered.push(trimmed
|
|
192
|
-
.split("\n")
|
|
193
|
-
.map((line) => renderInlineConsoleMarkdown(line))
|
|
194
|
-
.join("\n"));
|
|
195
|
-
}
|
|
196
|
-
return rendered.join("\n\n");
|
|
197
|
-
}
|
|
198
|
-
function resolveTemplateSource(template) {
|
|
199
|
-
if (existsSync(template)) {
|
|
200
|
-
return readFileSync(template, "utf8");
|
|
201
|
-
}
|
|
202
|
-
return template;
|
|
203
|
-
}
|
|
204
|
-
export function renderTemplate(data, template) {
|
|
205
|
-
return Mustache.render(resolveTemplateSource(template), data);
|
|
206
|
-
}
|
|
1
|
+
import{existsSync as j,readFileSync as M}from"node:fs";import w from"mustache";function $(t){return t.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}function f(t){return $(t).replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>").replace(/\*(.+?)\*/g,"<em>$1</em>").replace(/`([^`]+)`/g,"<code>$1</code>")}function u(t){return t.replace(/`([^`]+)`/g,"\x1B[100m $1 \x1B[0m").replace(/\*\*([^*]+)\*\*/g,"\x1B[1m$1\x1B[0m").replace(/\*([^*]+)\*/g,"\x1B[3m$1\x1B[0m").replace(/\[([^\]]+)\]\(([^)]+)\)/g,"$1 ($2)")}function g(t){return t.replace(/\u001b\[[0-9;]*m/g,"")}function b(t){return t.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(l=>l.trim())}function y(t){const i=b(t);return i.length>0&&i.every(l=>/^:?-{3,}:?$/.test(l))}function k(t){const i=t.split(`
|
|
2
|
+
`).map(s=>s.trimEnd()).filter(s=>s.trim().length>0);if(i.length<2||!i.every(s=>s.includes("|"))||!y(i[1]??""))return;const l=i.map(b),r=l[0]??[],m=l.slice(2),e=Math.max(r.length,...m.map(s=>s.length)),o=[r,...m].map(s=>Array.from({length:e},(p,h)=>u(s[h]??""))),n=Array.from({length:e},(s,p)=>Math.max(...o.map(h=>g(h[p]??"").length),0));if(n.reduce((s,p)=>s+p,0)+e*3+1>120||e>5)return v(r,m);const a=s=>`| ${s.map((p,h)=>p.padEnd(n[h]+(p.length-g(p).length))).join(" | ")} |`,d=`|-${n.map(s=>"-".repeat(Math.max(3,s))).join("-|-")}-|`;return[a(o[0]??[]),d,...o.slice(1).map(a)].join(`
|
|
3
|
+
`)}function v(t,i){const l=t.map(r=>r.trim()).filter(Boolean);return i.map((r,m)=>{const e=u(r[0]?.trim()||`Row ${m+1}`),o=l.slice(1).flatMap((n,c)=>{const a=r[c+1]?.trim();return a?` \u2022 ${u(n)}: ${u(a)}`:[]});return[`\u2022 ${e}`,...o].join(`
|
|
4
|
+
`)}).join(`
|
|
5
|
+
|
|
6
|
+
`)}function T(t){const l=t.replace(/\r\n/g,`
|
|
7
|
+
`).replace(/<br\s*\/?>/gi,`
|
|
8
|
+
`).split(/\n\n+/),r=[];for(const m of l){const e=m.trim();if(e){if(e.startsWith("```")&&e.endsWith("```")){const o=e.split(`
|
|
9
|
+
`),n=o[0]?.slice(3).trim(),c=o.slice(1,-1).join(`
|
|
10
|
+
`);r.push(`<pre class="ah-code"><code${n?` data-language="${$(n)}"`:""}>${$(c)}</code></pre>`);continue}if(/^#{1,6}\s/.test(e)){const o=e.match(/^(#{1,6})\s+(.*)$/),n=o?.[1].length??1,c=f(o?.[2]??e);r.push(`<h${n}>${c}</h${n}>`);continue}if(e.split(`
|
|
11
|
+
`).every(o=>/^[-*]\s+/.test(o))){const o=e.split(`
|
|
12
|
+
`).map(n=>n.replace(/^[-*]\s+/,"")).map(n=>`<li>${f(n)}</li>`).join("");r.push(`<ul>${o}</ul>`);continue}r.push(`<p>${e.split(`
|
|
13
|
+
`).map(o=>f(o)).join("<br />")}</p>`)}}return r.join("")}function W(t){if(!t.includes(`
|
|
14
|
+
`))return u(t.replace(/<br\s*\/?>/gi,`
|
|
15
|
+
`).trim());const l=t.replace(/\r\n/g,`
|
|
16
|
+
`).replace(/<br\s*\/?>/gi,`
|
|
17
|
+
`).replace(/^(#{1,6}\s+.+)$/gm,`
|
|
18
|
+
$1
|
|
19
|
+
`).replace(/^(\s*[-*_=])(?:\s*\1){2,}\s*$/gm,`
|
|
20
|
+
$&
|
|
21
|
+
`).split(/\n\n+/),r=[];for(const m of l){const e=m.trim();if(!e)continue;const o=k(e);if(o){r.push(o);continue}if(e.startsWith("```")&&e.endsWith("```")){const n=e.split(`
|
|
22
|
+
`),c=n[0]?.slice(3).trim(),a=n.slice(1,-1),d=c?` ${c} `:" code ",s=Math.max(d.length,6);r.push([`\x1B[2m\u250C${"\u2500".repeat(s)}\x1B[0m`,`\x1B[2m\u2502\x1B[0m${d}`,...a.map(p=>` ${p}`),`\x1B[2m\u2514${"\u2500".repeat(s)}\x1B[0m`].join(`
|
|
23
|
+
`));continue}if(/^#{1,6}\s/.test(e)){const n=e.match(/^(#{1,6})\s+(.*)$/),c=n?.[1].length??1,a=u(n?.[2]??e),d=c===1?"=":"-",s=Math.min(72,Math.max(3,a.replace(/\u001b\[[0-9;]*m/g,"").length));r.push(`\x1B[1m${a}\x1B[0m
|
|
24
|
+
\x1B[2m${d.repeat(s)}\x1B[0m`);continue}if(e.split(`
|
|
25
|
+
`).every(n=>/^\s*[-*]\s+/.test(n))){r.push(e.split(`
|
|
26
|
+
`).map(n=>{const c=n.match(/^(\s*)[-*]\s+(.*)$/),a=c?.[1]??"",d=c?.[2]??n;return`${a}\u2022 ${d}`}).map(n=>u(n)).join(`
|
|
27
|
+
`));continue}if(e.split(`
|
|
28
|
+
`).every(n=>/^\s*\d+\.\s+/.test(n))){r.push(e.split(`
|
|
29
|
+
`).map(n=>u(n)).join(`
|
|
30
|
+
`));continue}if(e.split(`
|
|
31
|
+
`).every(n=>/^\s*>\s?/.test(n))){r.push(e.split(`
|
|
32
|
+
`).map(n=>n.replace(/^\s*>\s?/,"")).map(n=>`\x1B[2m\u2502\x1B[0m ${u(n)}`).join(`
|
|
33
|
+
`));continue}if(/^([-*_=])(?:\s*\1){2,}$/.test(e)){r.push(`\x1B[2m${"\u2500".repeat(24)}\x1B[0m`);continue}r.push(e.split(`
|
|
34
|
+
`).map(n=>u(n)).join(`
|
|
35
|
+
`))}return r.join(`
|
|
36
|
+
|
|
37
|
+
`)}function x(t){return j(t)?M(t,"utf8"):t}function R(t,i){return w.render(x(i),t)}export{$ as escapeHtml,W as markdownToConsole,T as markdownToHtml,R as renderTemplate};
|