loopengine 0.3.92 → 0.3.93
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.
|
@@ -174,7 +174,7 @@ export declare class WorkflowRunner {
|
|
|
174
174
|
task_name?: string;
|
|
175
175
|
message: string;
|
|
176
176
|
session_id: string;
|
|
177
|
-
} & Pick<StartRunInput, 'callback_url' | 'decisions_to' | 'chat_notice' | 'warnings'>): Promise<RunOutcome>;
|
|
177
|
+
} & Pick<StartRunInput, 'result_to_chat' | 'callback_url' | 'decisions_to' | 'chat_notice' | 'warnings'>): Promise<RunOutcome>;
|
|
178
178
|
/** Waits for the runs this process has started (tests, shutdown). */
|
|
179
179
|
idle(): Promise<void>;
|
|
180
180
|
/** How many runs are executing right now (for idle-shutdown checks). */
|
|
@@ -163,6 +163,7 @@ export class WorkflowRunner {
|
|
|
163
163
|
source: 'schedule',
|
|
164
164
|
task_id: input.task_id,
|
|
165
165
|
...(input.task_name ? { task_name: input.task_name } : {}),
|
|
166
|
+
...(input.result_to_chat ? { result_to_chat: true } : {}),
|
|
166
167
|
...(input.callback_url ? { callback_url: input.callback_url } : {}),
|
|
167
168
|
...(input.decisions_to ? { decisions_to: input.decisions_to } : {}),
|
|
168
169
|
...(input.chat_notice ? { chat_notice: input.chat_notice } : {}),
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
import { WORKFLOW_SECTIONS_CSS, WORKFLOW_SECTIONS_SCRIPT } from './workflow-sections.js';
|
|
29
29
|
import { devUiCss } from './dev-ui-styles.js';
|
|
30
30
|
import { MESSAGING_ICONS } from './messaging-icons.js';
|
|
31
|
+
import { renderMarkdownScript } from './markdown-script.js';
|
|
31
32
|
import { consoleShellScript, consoleSidebarHtml } from './console-shell.js';
|
|
32
33
|
import { REASONING_PROVIDERS } from './agent-file-admin.js';
|
|
33
34
|
export const agentsConfigPageHtml = `<!doctype html>
|
|
@@ -120,14 +121,27 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
120
121
|
.wf-tab:hover:not(:disabled) { background: none; color: var(--ink); }
|
|
121
122
|
.wf-tab[aria-selected="true"] { color: var(--accent-ink); border-bottom-color: var(--accent); }
|
|
122
123
|
.wf-msg-form { display: flex; flex-direction: column; gap: 14px; max-width: 760px; }
|
|
123
|
-
.wf-msg-
|
|
124
|
-
.wf-msg-
|
|
125
|
-
.wf-msg-
|
|
126
|
-
.wf-msg-
|
|
127
|
-
.wf-msg-
|
|
124
|
+
.wf-msg-dests { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
|
|
125
|
+
.wf-msg-dest { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
|
|
126
|
+
.wf-msg-dest-k { font-weight: 600; font-size: 13px; }
|
|
127
|
+
.wf-msg-dest input[name="msgUrl"] { margin-top: 4px; }
|
|
128
|
+
.wf-msg-grid-wrap { overflow-x: auto; }
|
|
129
|
+
.wf-msg-grid { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
130
|
+
.wf-msg-grid th, .wf-msg-grid td { padding: 10px 8px; border-top: 1px solid var(--line); vertical-align: top; }
|
|
131
|
+
.wf-msg-grid thead th { border-top: 0; font-weight: 600; text-align: center; }
|
|
132
|
+
.wf-msg-grid th { background: none; }
|
|
133
|
+
.wf-msg-grid tbody th { text-align: left; font-weight: 600; }
|
|
134
|
+
.wf-msg-grid tbody th .hint { font-weight: 400; }
|
|
135
|
+
.wf-msg-grid td { text-align: center; width: 110px; }
|
|
136
|
+
.wf-msg-cell { display: inline-flex; justify-content: center; }
|
|
137
|
+
.wf-msg-cell input { width: auto; margin: 0; }
|
|
138
|
+
.wf-msg-appcell.is-off { opacity: .35; }
|
|
139
|
+
.wf-msg-notice { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; font-weight: 400; }
|
|
140
|
+
.wf-msg-notice[hidden] { display: none; }
|
|
141
|
+
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
128
142
|
.wf-msg-own { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); }
|
|
129
143
|
.wf-msg-foot { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
|
|
130
|
-
@media (max-width: 640px) { .wf-msg-
|
|
144
|
+
@media (max-width: 640px) { .wf-msg-dests { grid-template-columns: 1fr; } .wf-msg-grid td { width: 64px; } }
|
|
131
145
|
.wf-tab-count { margin-left: 4px; font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--ink-muted); }
|
|
132
146
|
.wf-row .workflow-steps-text { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--surface); font-size: 13px; line-height: 1.6; max-height: 420px; overflow: auto; white-space: pre-wrap; }
|
|
133
147
|
.wf-original { margin-top: 10px; }
|
|
@@ -686,162 +700,7 @@ ${consoleShellScript}
|
|
|
686
700
|
return attempt().catch(function () { return attempt(); });
|
|
687
701
|
}
|
|
688
702
|
|
|
689
|
-
|
|
690
|
-
// the skill Body field's Preview toggle (see wireSkillsHandlers) — this
|
|
691
|
-
// page stays a self-contained string, no build step, no CDN (same
|
|
692
|
-
// reasoning as devUiCss's own header comment), so pulling in a real
|
|
693
|
-
// markdown library isn't an option without breaking that. Covers what
|
|
694
|
-
// an actual SKILL.md body realistically uses (headings, bold/italic,
|
|
695
|
-
// inline code, fenced code blocks, links, lists, rules, paragraphs) —
|
|
696
|
-
// good enough for "does this read the way it will on GitHub", not a
|
|
697
|
-
// spec-complete parser. Escapes first, so no markdown source can inject
|
|
698
|
-
// raw HTML into the preview.
|
|
699
|
-
function renderMarkdownPreview(md) {
|
|
700
|
-
var lines = escapeHtml(md).split('\\n');
|
|
701
|
-
var html = '';
|
|
702
|
-
var inCode = false;
|
|
703
|
-
var codeBuffer = '';
|
|
704
|
-
var listType = null;
|
|
705
|
-
var paragraph = [];
|
|
706
|
-
|
|
707
|
-
// This whole page is one outer TS template literal AND its output is
|
|
708
|
-
// itself served as JS source text a browser then parses again — two
|
|
709
|
-
// layers of "escape sequences get processed", not one. The unicode
|
|
710
|
-
// escape used for the backtick patterns below survives both layers fine, since
|
|
711
|
-
// it's a real, recognized escape at both of them. A star/bracket/
|
|
712
|
-
// paren/s/d/dot escape (\*, \[, \s, \d, \.) is *not* a recognized
|
|
713
|
-
// escape at either layer, so each layer that touches it silently
|
|
714
|
-
// drops the backslash and keeps just the character — confirmed by
|
|
715
|
-
// extracting and executing the actually-served page during
|
|
716
|
-
// development, where every regex built the "obvious" way here ended
|
|
717
|
-
// up with its escapes stripped entirely, sometimes still parsing
|
|
718
|
-
// (silently wrong) and sometimes throwing ("nothing to repeat").
|
|
719
|
-
// Building these particular patterns from a runtime backslash
|
|
720
|
-
// character instead sidesteps the whole problem: there is no
|
|
721
|
-
// backslash-followed-by-letter sequence anywhere in this source for
|
|
722
|
-
// either layer to misinterpret.
|
|
723
|
-
var bs = String.fromCharCode(92);
|
|
724
|
-
var inlineCodePattern = new RegExp('\\u0060([^\\u0060]+)\\u0060', 'g');
|
|
725
|
-
var fencePattern = new RegExp('^\\u0060\\u0060\\u0060');
|
|
726
|
-
var boldPattern = new RegExp(bs + '*' + bs + '*([^*]+)' + bs + '*' + bs + '*', 'g');
|
|
727
|
-
var italicPattern = new RegExp(bs + '*([^*]+)' + bs + '*', 'g');
|
|
728
|
-
var linkPattern = new RegExp(bs + '[([^' + bs + ']]+)' + bs + ']' + bs + '(([^)]+)' + bs + ')', 'g');
|
|
729
|
-
var headingPattern = new RegExp('^(#{1,6})' + bs + 's+(.*)$');
|
|
730
|
-
var hrPattern = new RegExp('^(---|' + bs + '*' + bs + '*' + bs + '*)' + bs + 's*$');
|
|
731
|
-
var ulPattern = new RegExp('^[-*]' + bs + 's+(.*)$');
|
|
732
|
-
var olPattern = new RegExp('^' + bs + 'd+' + bs + '.' + bs + 's+(.*)$');
|
|
733
|
-
function inlineFormat(text) {
|
|
734
|
-
return text
|
|
735
|
-
.replace(inlineCodePattern, '<code>$1</code>')
|
|
736
|
-
.replace(boldPattern, '<strong>$1</strong>')
|
|
737
|
-
.replace(italicPattern, '<em>$1</em>')
|
|
738
|
-
.replace(linkPattern, function (_, label, href) {
|
|
739
|
-
var lowerHref = href.toLowerCase();
|
|
740
|
-
var safeHref = lowerHref.indexOf('https://') === 0 || lowerHref.indexOf('http://') === 0 || lowerHref.indexOf('mailto:') === 0;
|
|
741
|
-
return safeHref ? '<a href="' + href + '" target="_blank" rel="noopener noreferrer">' + label + '</a>' : label;
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
function flushParagraph() {
|
|
745
|
-
if (paragraph.length) {
|
|
746
|
-
html += '<p>' + inlineFormat(paragraph.join(' ')) + '</p>';
|
|
747
|
-
paragraph = [];
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
function closeList() {
|
|
751
|
-
if (listType) {
|
|
752
|
-
html += '</' + listType + '>';
|
|
753
|
-
listType = null;
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
function tableCells(line) {
|
|
757
|
-
var value = line.trim();
|
|
758
|
-
if (value.charAt(0) === '|') value = value.slice(1);
|
|
759
|
-
if (value.charAt(value.length - 1) === '|') value = value.slice(0, -1);
|
|
760
|
-
return value.split('|').map(function (cell) { return cell.trim(); });
|
|
761
|
-
}
|
|
762
|
-
function isTableDivider(line) {
|
|
763
|
-
if (line.indexOf('|') < 0) return false;
|
|
764
|
-
var cells = tableCells(line);
|
|
765
|
-
return cells.length > 0 && cells.every(function (cell) {
|
|
766
|
-
var value = cell.replace(/:/g, '').replace(/-/g, '').trim();
|
|
767
|
-
return cell.indexOf('-') >= 0 && value === '';
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
for (var i = 0; i < lines.length; i++) {
|
|
772
|
-
var line = lines[i];
|
|
773
|
-
if (fencePattern.test(line)) {
|
|
774
|
-
if (!inCode) {
|
|
775
|
-
flushParagraph();
|
|
776
|
-
closeList();
|
|
777
|
-
inCode = true;
|
|
778
|
-
codeBuffer = '';
|
|
779
|
-
} else {
|
|
780
|
-
html += '<pre><code>' + codeBuffer + '</code></pre>';
|
|
781
|
-
inCode = false;
|
|
782
|
-
}
|
|
783
|
-
continue;
|
|
784
|
-
}
|
|
785
|
-
if (inCode) {
|
|
786
|
-
codeBuffer += line + '\\n';
|
|
787
|
-
continue;
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
if (line.indexOf('|') >= 0 && i + 1 < lines.length && isTableDivider(lines[i + 1])) {
|
|
791
|
-
flushParagraph();
|
|
792
|
-
closeList();
|
|
793
|
-
var headers = tableCells(line);
|
|
794
|
-
html += '<div class="workflow-markdown-table"><table><thead><tr>' + headers.map(function (cell) { return '<th>' + inlineFormat(cell) + '</th>'; }).join('') + '</tr></thead><tbody>';
|
|
795
|
-
i += 2;
|
|
796
|
-
while (i < lines.length && lines[i].indexOf('|') >= 0 && lines[i].trim() !== '') {
|
|
797
|
-
var cells = tableCells(lines[i]);
|
|
798
|
-
html += '<tr>' + headers.map(function (_, index) { return '<td>' + inlineFormat(cells[index] || '') + '</td>'; }).join('') + '</tr>';
|
|
799
|
-
i++;
|
|
800
|
-
}
|
|
801
|
-
html += '</tbody></table></div>';
|
|
802
|
-
i--;
|
|
803
|
-
continue;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
var heading = line.match(headingPattern);
|
|
807
|
-
if (heading) {
|
|
808
|
-
flushParagraph();
|
|
809
|
-
closeList();
|
|
810
|
-
var level = heading[1].length;
|
|
811
|
-
html += '<h' + level + '>' + inlineFormat(heading[2]) + '</h' + level + '>';
|
|
812
|
-
continue;
|
|
813
|
-
}
|
|
814
|
-
if (hrPattern.test(line)) {
|
|
815
|
-
flushParagraph();
|
|
816
|
-
closeList();
|
|
817
|
-
html += '<hr>';
|
|
818
|
-
continue;
|
|
819
|
-
}
|
|
820
|
-
var ul = line.match(ulPattern);
|
|
821
|
-
var ol = line.match(olPattern);
|
|
822
|
-
if (ul || ol) {
|
|
823
|
-
flushParagraph();
|
|
824
|
-
var wantType = ul ? 'ul' : 'ol';
|
|
825
|
-
if (listType !== wantType) {
|
|
826
|
-
closeList();
|
|
827
|
-
html += '<' + wantType + '>';
|
|
828
|
-
listType = wantType;
|
|
829
|
-
}
|
|
830
|
-
html += '<li>' + inlineFormat((ul || ol)[1]) + '</li>';
|
|
831
|
-
continue;
|
|
832
|
-
}
|
|
833
|
-
closeList();
|
|
834
|
-
|
|
835
|
-
if (line.trim() === '') {
|
|
836
|
-
flushParagraph();
|
|
837
|
-
continue;
|
|
838
|
-
}
|
|
839
|
-
paragraph.push(line.trim());
|
|
840
|
-
}
|
|
841
|
-
flushParagraph();
|
|
842
|
-
closeList();
|
|
843
|
-
return html || '<p class="hint">Nothing to preview yet.</p>';
|
|
844
|
-
}
|
|
703
|
+
${renderMarkdownScript}
|
|
845
704
|
|
|
846
705
|
// ---- Overview tab ----
|
|
847
706
|
|
|
@@ -970,7 +829,7 @@ ${consoleShellScript}
|
|
|
970
829
|
'</div>';
|
|
971
830
|
}
|
|
972
831
|
|
|
973
|
-
var APP_NAMES = { slack: 'Slack', lark: 'Lark', webhook: 'Webhook', email: 'Email', database: 'Database', redis: 'Redis' };
|
|
832
|
+
var APP_NAMES = { slack: 'Slack', telegram: 'Telegram', lark: 'Lark', webhook: 'Webhook', email: 'Email', database: 'Database', redis: 'Redis' };
|
|
974
833
|
|
|
975
834
|
// Messaging and Schedules come from their own endpoints, so their
|
|
976
835
|
// cards are filled in once those answer. Called after every render of
|
|
@@ -1148,34 +1007,58 @@ ${consoleShellScript}
|
|
|
1148
1007
|
return ['slack', 'telegram', 'lark'].indexOf(workflowsMeta.messaging) !== -1 ? workflowChatName() : null;
|
|
1149
1008
|
}
|
|
1150
1009
|
|
|
1151
|
-
// Its Messages tab: where every run's
|
|
1152
|
-
//
|
|
1153
|
-
//
|
|
1010
|
+
// Its Messages tab: where every run's messages go, however it starts,
|
|
1011
|
+
// as a grid of what happens in a run (rows) by where it can go
|
|
1012
|
+
// (columns): the agent's messaging app, the Inbox and your app's
|
|
1013
|
+
// address. What can't be turned off is shown ticked and locked: the
|
|
1014
|
+
// Inbox keeps every run (web/inbox-admin.ts); your app gets nothing
|
|
1015
|
+
// without an address, and with one gets every decision, finish and
|
|
1016
|
+
// failure (adapters/http.ts, reportWorkflowRun).
|
|
1154
1017
|
function workflowMessagesHtml(w, agentName) {
|
|
1155
1018
|
var d = w.delivery || {};
|
|
1156
|
-
var chat = workflowChatAppName();
|
|
1157
|
-
var chatLabel = escapeHtml(chat || 'chat');
|
|
1158
|
-
// With no messaging app, an unattended run's approvals and questions
|
|
1159
|
-
// wait in the Inbox (adapters/http.ts, executeUnattendedRun).
|
|
1160
|
-
var decisionsLabel = workflowChatName() ? escapeHtml(workflowChatName())
|
|
1161
|
-
: 'The Inbox <span class="hint">(no messaging app is set up, so they wait in the Inbox)</span>';
|
|
1162
|
-
var noChat = chat ? '' : ' disabled';
|
|
1163
1019
|
var RSQ = String.fromCharCode(8217);
|
|
1164
|
-
var
|
|
1020
|
+
var chatName = workflowChatName();
|
|
1021
|
+
var chat = workflowChatAppName();
|
|
1022
|
+
var chatCol = escapeHtml(chatName || 'Messaging app');
|
|
1023
|
+
var toApp = d.decisions_to === 'callback';
|
|
1024
|
+
var box = function (name, checked, locked, label, extra) {
|
|
1025
|
+
return '<label class="wf-msg-cell"><input type="checkbox"' + (name ? ' name="' + name + '"' : '') + (checked ? ' checked' : '') + (locked ? ' disabled' : '') + ' aria-label="' + label + '"' + (extra || '') + '></label>';
|
|
1026
|
+
};
|
|
1027
|
+
var none = '<span class="wf-msg-cell hint" aria-label="Not sent">' + String.fromCharCode(8212) + '</span>';
|
|
1028
|
+
var always = function (label) { return box('', true, true, label + ': always'); };
|
|
1029
|
+
var appCell = function (key, label) { return '<span class="wf-msg-appcell" data-app="' + key + '">' + box('', Boolean(d.callback_url), true, label + ', when an address is set') + '</span>'; };
|
|
1030
|
+
var row = function (what, hint, chatCell, inboxCell, appCellHtml, below) {
|
|
1031
|
+
return '<tr><th scope="row"><div>' + what + '</div><div class="hint">' + hint + '</div>' + (below || '') + '</th>' +
|
|
1032
|
+
'<td>' + chatCell + '</td><td>' + inboxCell + '</td><td>' + appCellHtml + '</td></tr>';
|
|
1033
|
+
};
|
|
1165
1034
|
// Webhooks saved with settings of their own: their runs use those.
|
|
1166
1035
|
var own = (w.triggers || []).filter(function (t) { return t.callback || t.decisions_to || t.chat_notice || t.result_to_chat; });
|
|
1167
1036
|
return '<form class="wf-msg-form">' +
|
|
1168
|
-
'<p class="hint" style="margin:0
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
'<
|
|
1174
|
-
'<
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
'
|
|
1037
|
+
'<p class="hint" style="margin:0">Where this workflow' + RSQ + 's messages go, for every run: started by Run now, a schedule, a webhook or the API. A ticked, greyed box can' + RSQ + 't be turned off. Your app gets nothing until you give it an address.</p>' +
|
|
1038
|
+
'<div class="wf-msg-dests">' +
|
|
1039
|
+
'<div class="wf-msg-dest"><div class="wf-msg-dest-k">' + chatCol + '</div><div class="hint">' +
|
|
1040
|
+
(chatName ? 'The agent' + RSQ + 's messaging app, set in its <a href="?agent=' + encodeURIComponent(agentName) + '&tab=messaging">Messaging</a> tab.'
|
|
1041
|
+
: 'Not set up. <a href="?agent=' + encodeURIComponent(agentName) + '&tab=messaging">Set one up in Messaging</a> (Slack, Telegram or Lark) to post to chat.') + '</div></div>' +
|
|
1042
|
+
'<div class="wf-msg-dest"><div class="wf-msg-dest-k">Inbox</div><div class="hint">Always. Every run is kept as a case, and approvals and questions can be answered there.</div></div>' +
|
|
1043
|
+
'<div class="wf-msg-dest"><div class="wf-msg-dest-k">Your app</div><div class="hint">Optional. Only when you set an address: it then gets each update as signed JSON (a webhook).</div>' +
|
|
1044
|
+
'<input name="msgUrl" inputmode="url" placeholder="https://example.com/hooks/loopengine" value="' + escapeHtml(d.callback_url || '') + '"></div>' +
|
|
1045
|
+
'</div>' +
|
|
1046
|
+
'<div class="wf-msg-grid-wrap"><table class="wf-msg-grid"><thead><tr><th scope="col"><span class="sr-only">When</span></th><th scope="col">' + chatCol + '</th><th scope="col">Inbox</th><th scope="col">Your app</th></tr></thead><tbody>' +
|
|
1047
|
+
row('A run starts', 'A short note that it began.',
|
|
1048
|
+
chat ? box('msgNoticeOn', Boolean(d.chat_notice), false, 'Post a start note to ' + chatCol) : none,
|
|
1049
|
+
always('Shown in the Inbox'),
|
|
1050
|
+
'<span class="wf-msg-appcell" data-app="start">' + box('', toApp, true, 'Sent to your app when it answers approvals and questions') + '</span>',
|
|
1051
|
+
chat ? '<div class="wf-msg-notice"' + (d.chat_notice ? '' : ' hidden') + '><input name="msgNotice" maxlength="1000" placeholder="Run started" value="' + escapeHtml(d.chat_notice || '') + '"><span class="hint">{{name}} puts in an input' + RSQ + 's value.</span></div>' : '') +
|
|
1052
|
+
row('Approvals and questions', 'Someone answers in one place; the Inbox can always answer too.',
|
|
1053
|
+
chatName ? box('msgDecisionsChat', !toApp, !d.callback_url, 'Send approvals and questions to ' + chatCol, ' data-locked-without-app="1"') : none,
|
|
1054
|
+
always('Approvals and questions in the Inbox'),
|
|
1055
|
+
appCell('decisions', 'Approvals and questions sent to your app')) +
|
|
1056
|
+
row('A run finishes or fails', 'Its result, or what went wrong.',
|
|
1057
|
+
chatName ? box('msgResult', Boolean(d.result_to_chat), false, 'Post the result to ' + chatCol) : none,
|
|
1058
|
+
always('Results in the Inbox'),
|
|
1059
|
+
appCell('finish', 'Results sent to your app')) +
|
|
1060
|
+
'</tbody></table></div>' +
|
|
1061
|
+
'<p class="hint wf-msg-decide-note" style="margin:0"></p>' +
|
|
1179
1062
|
(own.length
|
|
1180
1063
|
? '<div class="wf-msg-own">' + own.map(function (t) {
|
|
1181
1064
|
return '<p class="hint" style="margin:0">The ' + escapeHtml(t.name) + ' webhook has settings of its own, so its runs use those instead. ' +
|
|
@@ -1196,7 +1079,7 @@ ${consoleShellScript}
|
|
|
1196
1079
|
};
|
|
1197
1080
|
return '<div class="wf-ways">' +
|
|
1198
1081
|
way('run', 'Run now', 'Starts a run right away, from here. It shows under Evidence as it goes.', workflowRunBarHtml(w, params)) +
|
|
1199
|
-
way('schedule', 'Schedule', 'Runs it on a timer, like every day at 9:00. Approvals and questions go
|
|
1082
|
+
way('schedule', 'Schedule', 'Runs it on a timer, like every day at 9:00. Approvals and questions go where its Messages tab says.',
|
|
1200
1083
|
(schedules || '<p class="hint" style="margin:0">None yet.</p>') +
|
|
1201
1084
|
'<div><button type="button" class="workflow-add-schedule">+ Schedule</button></div>') +
|
|
1202
1085
|
way('webhook', 'Webhook', 'Another app (Stripe, GitHub, Shopify or your own) calls a private address when something happens, and each call starts a run.',
|
|
@@ -1957,25 +1840,47 @@ ${consoleShellScript}
|
|
|
1957
1840
|
var msgForm = card.querySelector('.wf-msg-form');
|
|
1958
1841
|
if (msgForm) {
|
|
1959
1842
|
var msgResult = msgForm.querySelector('.wf-msg-result');
|
|
1960
|
-
var
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1843
|
+
var decideChat = msgForm.msgDecisionsChat || null;
|
|
1844
|
+
var decideNote = msgForm.querySelector('.wf-msg-decide-note');
|
|
1845
|
+
var hasChat = Boolean(decideChat);
|
|
1846
|
+
// Your app's column follows its address; approvals and questions
|
|
1847
|
+
// can leave the chat app only for an address that's given, and
|
|
1848
|
+
// your app hears of a run starting only when it answers them.
|
|
1849
|
+
var syncMsgForm = function () {
|
|
1850
|
+
var url = msgForm.msgUrl.value.trim();
|
|
1851
|
+
var toApp = Boolean(url) && (!hasChat || !decideChat.checked);
|
|
1852
|
+
if (decideChat) {
|
|
1853
|
+
decideChat.disabled = !url;
|
|
1854
|
+
if (!url) decideChat.checked = true;
|
|
1855
|
+
}
|
|
1856
|
+
msgForm.querySelectorAll('.wf-msg-appcell').forEach(function (cell) {
|
|
1857
|
+
var input = cell.querySelector('input');
|
|
1858
|
+
var on = Boolean(url) && (cell.dataset.app !== 'start' || toApp);
|
|
1859
|
+
input.checked = on;
|
|
1860
|
+
cell.classList.toggle('is-off', !url);
|
|
1861
|
+
});
|
|
1862
|
+
decideNote.textContent = !url
|
|
1863
|
+
? (hasChat ? 'Add your app' + String.fromCharCode(8217) + 's address to answer approvals and questions there instead.' : 'With no messaging app, approvals and questions wait in the Inbox.')
|
|
1864
|
+
: toApp ? 'Your app answers approvals and questions (through the API), and gets a note when each run starts.' + (hasChat ? ' Nothing goes to chat for them.' : '')
|
|
1865
|
+
: 'Approvals and questions are answered in chat; your app is told about them too.';
|
|
1866
|
+
};
|
|
1867
|
+
msgForm.msgUrl.addEventListener('input', syncMsgForm);
|
|
1868
|
+
if (decideChat) decideChat.addEventListener('change', syncMsgForm);
|
|
1869
|
+
if (msgForm.msgNoticeOn) msgForm.msgNoticeOn.addEventListener('change', function () {
|
|
1870
|
+
var notice = msgForm.querySelector('.wf-msg-notice');
|
|
1871
|
+
notice.hidden = !msgForm.msgNoticeOn.checked;
|
|
1968
1872
|
if (msgForm.msgNoticeOn.checked) msgForm.msgNotice.focus();
|
|
1969
1873
|
});
|
|
1874
|
+
syncMsgForm();
|
|
1970
1875
|
var reloadOnMessages = function () { workflowTabs[id] = 'messages'; loadWorkflowsSection(name); };
|
|
1971
1876
|
msgForm.addEventListener('submit', function (ev) {
|
|
1972
1877
|
ev.preventDefault();
|
|
1973
1878
|
var url = msgForm.msgUrl.value.trim();
|
|
1974
1879
|
var body = {};
|
|
1975
1880
|
if (url) body.callback_url = url;
|
|
1976
|
-
if (url &&
|
|
1977
|
-
if (msgForm.msgNoticeOn.checked && msgForm.msgNotice.value.trim()) body.chat_notice = msgForm.msgNotice.value.trim();
|
|
1978
|
-
if (msgForm.msgResult.checked) body.result_to_chat = true;
|
|
1881
|
+
if (url && (!decideChat || !decideChat.checked)) body.decisions = 'callback';
|
|
1882
|
+
if (msgForm.msgNoticeOn && msgForm.msgNoticeOn.checked && msgForm.msgNotice.value.trim()) body.chat_notice = msgForm.msgNotice.value.trim();
|
|
1883
|
+
if (msgForm.msgResult && msgForm.msgResult.checked) body.result_to_chat = true;
|
|
1979
1884
|
msgResult.textContent = 'Saving' + String.fromCharCode(8230);
|
|
1980
1885
|
fetchJsonRetryOnce(base + '/messages', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }).then(function (r) {
|
|
1981
1886
|
if (!r.ok) { msgResult.textContent = r.body.error || 'Could not save'; return; }
|
package/dist/web/inbox-page.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The console's Inbox: /inbox lists every workflow run as a case, the ones
|
|
2
|
-
// waiting on a person first; /inbox?case=<id> opens one, with what it was
|
|
2
|
+
// waiting on a person first (?open=1 shows only those); /inbox?case=<id> opens one, with what it was
|
|
3
3
|
// given, what the agent did, what it asks now (answer, approve, approve
|
|
4
4
|
// as changed, deny) and who decided what (web/inbox-admin.ts behind
|
|
5
5
|
// /inbox/*). An approver or viewer sees only this page; a viewer can't
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// literal.
|
|
9
9
|
import { devUiCss } from './dev-ui-styles.js';
|
|
10
10
|
import { consoleShellScript, consoleSidebarHtml } from './console-shell.js';
|
|
11
|
+
import { renderMarkdownScript } from './markdown-script.js';
|
|
11
12
|
export const inboxPageHtml = `<!doctype html>
|
|
12
13
|
<html lang="en">
|
|
13
14
|
<head>
|
|
@@ -45,7 +46,7 @@ export const inboxPageHtml = `<!doctype html>
|
|
|
45
46
|
.ib-kv dt { color: var(--ink-muted); font-family: var(--font-mono); font-size: 12.5px; padding-top: 1px; }
|
|
46
47
|
.ib-kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
47
48
|
.ib-pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; background: var(--surface); padding: 10px 12px; border-radius: 8px; max-height: 360px; overflow: auto; }
|
|
48
|
-
.ib-question { margin: 0; font-size: 14.5px;
|
|
49
|
+
.ib-question { margin: 0; font-size: 14.5px; }
|
|
49
50
|
.ib-card textarea { width: 100%; box-sizing: border-box; min-height: 80px; font: inherit; font-size: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); resize: vertical; }
|
|
50
51
|
.ib-card textarea.mono { font-family: var(--font-mono); font-size: 12.5px; min-height: 200px; }
|
|
51
52
|
.ib-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
@@ -60,6 +61,22 @@ export const inboxPageHtml = `<!doctype html>
|
|
|
60
61
|
.ib-step details summary { cursor: pointer; font-size: 12.5px; color: var(--ink-muted); }
|
|
61
62
|
.ib-who { font-size: 13px; display: grid; gap: 4px; }
|
|
62
63
|
.hint { font-size: 12.5px; color: var(--ink-muted); }
|
|
64
|
+
.ib-md { font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
|
|
65
|
+
.ib-md > :first-child { margin-top: 0; }
|
|
66
|
+
.ib-md > :last-child { margin-bottom: 0; }
|
|
67
|
+
.ib-md p, .ib-md ul, .ib-md ol, .ib-md pre { margin: 0 0 .6em; }
|
|
68
|
+
.ib-md ul, .ib-md ol { padding-left: 1.4em; }
|
|
69
|
+
.ib-md li + li { margin-top: .25em; }
|
|
70
|
+
.ib-md h1, .ib-md h2, .ib-md h3, .ib-md h4, .ib-md h5, .ib-md h6 { margin: .8em 0 .4em; font-size: 15px; line-height: 1.35; }
|
|
71
|
+
.ib-md h1, .ib-md h2 { font-size: 16px; }
|
|
72
|
+
.ib-md a { color: var(--accent-ink); }
|
|
73
|
+
.ib-md code { font-family: var(--font-mono); font-size: .9em; background: var(--code-bg); padding: 1px 4px; border-radius: 4px; }
|
|
74
|
+
.ib-md pre { background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
|
|
75
|
+
.ib-md pre code { background: none; padding: 0; }
|
|
76
|
+
.ib-md hr { border: 0; border-top: 1px solid var(--line); margin: .8em 0; }
|
|
77
|
+
.ib-md .workflow-markdown-table { overflow-x: auto; margin: 0 0 .6em; }
|
|
78
|
+
.ib-md table { border-collapse: collapse; font-size: 13px; }
|
|
79
|
+
.ib-md th, .ib-md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
|
|
63
80
|
.error { font-size: 13px; color: var(--bad); margin: 0; }
|
|
64
81
|
@media (max-width: 640px) { .ib-row { grid-template-columns: 12px minmax(0, 1fr); } .ib-row-side { grid-column: 2; align-items: flex-start; flex-direction: row; gap: 8px; } .ib-kv { grid-template-columns: 1fr; } }
|
|
65
82
|
</style>
|
|
@@ -81,11 +98,12 @@ ${consoleSidebarHtml}
|
|
|
81
98
|
${consoleShellScript}
|
|
82
99
|
<script>
|
|
83
100
|
(function () {
|
|
101
|
+
${renderMarkdownScript}
|
|
84
102
|
var page = document.getElementById('ibPage');
|
|
85
103
|
var ELLIPSIS = String.fromCharCode(8230);
|
|
86
104
|
var DOT = ' ' + String.fromCharCode(183) + ' ';
|
|
87
105
|
var params = new URLSearchParams(location.search);
|
|
88
|
-
var state = { open: params.get('
|
|
106
|
+
var state = { open: params.get('open') === '1', q: params.get('q') || '', workflow: params.get('workflow') || '' };
|
|
89
107
|
var role = 'owner';
|
|
90
108
|
var workflows = {};
|
|
91
109
|
|
|
@@ -122,7 +140,7 @@ ${consoleShellScript}
|
|
|
122
140
|
}
|
|
123
141
|
function pageUrl() {
|
|
124
142
|
var q = new URLSearchParams();
|
|
125
|
-
if (
|
|
143
|
+
if (state.open) q.set('open', '1');
|
|
126
144
|
if (state.q) q.set('q', state.q);
|
|
127
145
|
if (state.workflow) q.set('workflow', state.workflow);
|
|
128
146
|
var s = q.toString();
|
|
@@ -142,7 +160,7 @@ ${consoleShellScript}
|
|
|
142
160
|
}).join('');
|
|
143
161
|
page.innerHTML =
|
|
144
162
|
'<div class="ib-bar">' +
|
|
145
|
-
'<span class="ib-filter" role="group" aria-label="Show"><button type="button" data-open="
|
|
163
|
+
'<span class="ib-filter" role="group" aria-label="Show"><button type="button" data-open="0" aria-pressed="' + !state.open + '">All</button><button type="button" data-open="1" aria-pressed="' + state.open + '">Needs you (' + (data.open || 0) + ')</button></span>' +
|
|
146
164
|
'<select id="ibWorkflow" aria-label="Workflow"><option value="">All workflows</option>' + options + '</select>' +
|
|
147
165
|
'<input id="ibSearch" type="search" placeholder="Search cases, inputs or people" value="' + esc(state.q) + '" aria-label="Search">' +
|
|
148
166
|
'</div>' +
|
|
@@ -186,7 +204,7 @@ ${consoleShellScript}
|
|
|
186
204
|
var locked = canDecide() ? '' : '<p class="hint" style="margin:0">Your role can see this but not decide.</p>';
|
|
187
205
|
if (p.kind === 'question') {
|
|
188
206
|
return '<div class="ib-card needs" data-pending="' + esc(p.pendingId) + '" data-kind="question"><h3>Question for you</h3>' +
|
|
189
|
-
'<
|
|
207
|
+
'<div class="ib-question ib-md">' + renderMarkdownPreview(p.question || '') + '</div>' +
|
|
190
208
|
(canDecide()
|
|
191
209
|
? (p.options && p.options.length ? '<div class="ib-actions">' + p.options.map(function (o) { return '<button type="button" class="ib-btn opt" data-option="' + esc(o) + '">' + esc(o) + '</button>'; }).join('') + '</div>' : '') +
|
|
192
210
|
'<textarea class="ib-answer" placeholder="Your answer"></textarea>' +
|
|
@@ -206,8 +224,8 @@ ${consoleShellScript}
|
|
|
206
224
|
}
|
|
207
225
|
|
|
208
226
|
function stepHtml(s) {
|
|
209
|
-
if (s.kind === 'text') return '<li class="ib-step"><span class="ib-step-k">Agent</span><div
|
|
210
|
-
if (s.kind === 'question') return '<li class="ib-step q"><span class="ib-step-k">Asked</span><div
|
|
227
|
+
if (s.kind === 'text') return '<li class="ib-step"><span class="ib-step-k">Agent</span><div class="ib-md">' + renderMarkdownPreview(s.text) + '</div></li>';
|
|
228
|
+
if (s.kind === 'question') return '<li class="ib-step q"><span class="ib-step-k">Asked</span><div class="ib-md">' + renderMarkdownPreview(s.question) + '</div>' +
|
|
211
229
|
(s.answer != null ? '<span class="ib-step-k">Answer</span><div style="white-space:pre-wrap">' + esc(s.answer) + '</div>' : '<span class="hint">Waiting for an answer</span>') + '</li>';
|
|
212
230
|
return '<li class="ib-step"><span class="ib-step-k">Used ' + esc(s.tool) + (s.failed ? ' (failed)' : '') + '</span>' +
|
|
213
231
|
'<details><summary>What it sent' + (s.result != null ? ' and got back' : '') + '</summary><pre class="ib-pre">' + esc(JSON.stringify(s.args, null, 2)) + '</pre>' +
|
|
@@ -235,7 +253,7 @@ ${consoleShellScript}
|
|
|
235
253
|
(run && run.params ? '<div class="ib-card"><h3>Inputs</h3>' + kvHtml(run.params) + '</div>' : '') +
|
|
236
254
|
(c.steps.length ? '<div class="ib-card"><h3>What the agent did</h3><ol class="ib-steps">' + c.steps.map(stepHtml).join('') + '</ol></div>' : '') +
|
|
237
255
|
(run ? decidedHtml(run) : '') +
|
|
238
|
-
(run && run.result ? '<div class="ib-card"><h3>Result</h3><div
|
|
256
|
+
(run && run.result ? '<div class="ib-card"><h3>Result</h3><div class="ib-md">' + renderMarkdownPreview(run.result) + '</div></div>' : '') +
|
|
239
257
|
(run && run.error ? '<div class="ib-card"><h3>Failed</h3><p class="error">' + esc(run.error) + '</p></div>' : '');
|
|
240
258
|
wireCase(c);
|
|
241
259
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const renderMarkdownScript: string;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// The console pages' markdown renderer, as inline script: the
|
|
2
|
+
// workflow pages and the Inbox put it in their own <script>, inside their
|
|
3
|
+
// template literal, so it's kept here as a string of browser JS with the
|
|
4
|
+
// same escaping rules as those pages (no backslash-letter sequences, no
|
|
5
|
+
// template placeholders). renderMarkdownPreview(md) returns HTML; it
|
|
6
|
+
// escapes first, so no markdown can inject raw HTML.
|
|
7
|
+
export const renderMarkdownScript = `
|
|
8
|
+
function markdownEscapeHtml(s) {
|
|
9
|
+
return String(s).replace(/[&<>"']/g, function (c) {
|
|
10
|
+
return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c];
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// A small, deliberately non-CommonMark markdown-to-HTML renderer for
|
|
15
|
+
// the skill Body field's Preview toggle (see wireSkillsHandlers) — this
|
|
16
|
+
// page stays a self-contained string, no build step, no CDN (same
|
|
17
|
+
// reasoning as devUiCss's own header comment), so pulling in a real
|
|
18
|
+
// markdown library isn't an option without breaking that. Covers what
|
|
19
|
+
// an actual SKILL.md body realistically uses (headings, bold/italic,
|
|
20
|
+
// inline code, fenced code blocks, links, lists, rules, paragraphs) —
|
|
21
|
+
// good enough for "does this read the way it will on GitHub", not a
|
|
22
|
+
// spec-complete parser. Escapes first, so no markdown source can inject
|
|
23
|
+
// raw HTML into the preview.
|
|
24
|
+
function renderMarkdownPreview(md) {
|
|
25
|
+
var lines = markdownEscapeHtml(md).split('\\n');
|
|
26
|
+
var html = '';
|
|
27
|
+
var inCode = false;
|
|
28
|
+
var codeBuffer = '';
|
|
29
|
+
var listType = null;
|
|
30
|
+
var paragraph = [];
|
|
31
|
+
|
|
32
|
+
// This whole page is one outer TS template literal AND its output is
|
|
33
|
+
// itself served as JS source text a browser then parses again — two
|
|
34
|
+
// layers of "escape sequences get processed", not one. The unicode
|
|
35
|
+
// escape used for the backtick patterns below survives both layers fine, since
|
|
36
|
+
// it's a real, recognized escape at both of them. A star/bracket/
|
|
37
|
+
// paren/s/d/dot escape (\*, \[, \s, \d, \.) is *not* a recognized
|
|
38
|
+
// escape at either layer, so each layer that touches it silently
|
|
39
|
+
// drops the backslash and keeps just the character — confirmed by
|
|
40
|
+
// extracting and executing the actually-served page during
|
|
41
|
+
// development, where every regex built the "obvious" way here ended
|
|
42
|
+
// up with its escapes stripped entirely, sometimes still parsing
|
|
43
|
+
// (silently wrong) and sometimes throwing ("nothing to repeat").
|
|
44
|
+
// Building these particular patterns from a runtime backslash
|
|
45
|
+
// character instead sidesteps the whole problem: there is no
|
|
46
|
+
// backslash-followed-by-letter sequence anywhere in this source for
|
|
47
|
+
// either layer to misinterpret.
|
|
48
|
+
var bs = String.fromCharCode(92);
|
|
49
|
+
var inlineCodePattern = new RegExp('\\u0060([^\\u0060]+)\\u0060', 'g');
|
|
50
|
+
var fencePattern = new RegExp('^\\u0060\\u0060\\u0060');
|
|
51
|
+
var boldPattern = new RegExp(bs + '*' + bs + '*([^*]+)' + bs + '*' + bs + '*', 'g');
|
|
52
|
+
var italicPattern = new RegExp(bs + '*([^*]+)' + bs + '*', 'g');
|
|
53
|
+
var linkPattern = new RegExp(bs + '[([^' + bs + ']]+)' + bs + ']' + bs + '(([^)]+)' + bs + ')', 'g');
|
|
54
|
+
var headingPattern = new RegExp('^(#{1,6})' + bs + 's+(.*)$');
|
|
55
|
+
var hrPattern = new RegExp('^(---|' + bs + '*' + bs + '*' + bs + '*)' + bs + 's*$');
|
|
56
|
+
var ulPattern = new RegExp('^[-*]' + bs + 's+(.*)$');
|
|
57
|
+
var olPattern = new RegExp('^' + bs + 'd+' + bs + '.' + bs + 's+(.*)$');
|
|
58
|
+
function inlineFormat(text) {
|
|
59
|
+
return text
|
|
60
|
+
.replace(inlineCodePattern, '<code>$1</code>')
|
|
61
|
+
.replace(boldPattern, '<strong>$1</strong>')
|
|
62
|
+
.replace(italicPattern, '<em>$1</em>')
|
|
63
|
+
.replace(linkPattern, function (_, label, href) {
|
|
64
|
+
var lowerHref = href.toLowerCase();
|
|
65
|
+
var safeHref = lowerHref.indexOf('https://') === 0 || lowerHref.indexOf('http://') === 0 || lowerHref.indexOf('mailto:') === 0;
|
|
66
|
+
return safeHref ? '<a href="' + href + '" target="_blank" rel="noopener noreferrer">' + label + '</a>' : label;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function flushParagraph() {
|
|
70
|
+
if (paragraph.length) {
|
|
71
|
+
html += '<p>' + inlineFormat(paragraph.join(' ')) + '</p>';
|
|
72
|
+
paragraph = [];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function closeList() {
|
|
76
|
+
if (listType) {
|
|
77
|
+
html += '</' + listType + '>';
|
|
78
|
+
listType = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function tableCells(line) {
|
|
82
|
+
var value = line.trim();
|
|
83
|
+
if (value.charAt(0) === '|') value = value.slice(1);
|
|
84
|
+
if (value.charAt(value.length - 1) === '|') value = value.slice(0, -1);
|
|
85
|
+
return value.split('|').map(function (cell) { return cell.trim(); });
|
|
86
|
+
}
|
|
87
|
+
function isTableDivider(line) {
|
|
88
|
+
if (line.indexOf('|') < 0) return false;
|
|
89
|
+
var cells = tableCells(line);
|
|
90
|
+
return cells.length > 0 && cells.every(function (cell) {
|
|
91
|
+
var value = cell.replace(/:/g, '').replace(/-/g, '').trim();
|
|
92
|
+
return cell.indexOf('-') >= 0 && value === '';
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (var i = 0; i < lines.length; i++) {
|
|
97
|
+
var line = lines[i];
|
|
98
|
+
if (fencePattern.test(line)) {
|
|
99
|
+
if (!inCode) {
|
|
100
|
+
flushParagraph();
|
|
101
|
+
closeList();
|
|
102
|
+
inCode = true;
|
|
103
|
+
codeBuffer = '';
|
|
104
|
+
} else {
|
|
105
|
+
html += '<pre><code>' + codeBuffer + '</code></pre>';
|
|
106
|
+
inCode = false;
|
|
107
|
+
}
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (inCode) {
|
|
111
|
+
codeBuffer += line + '\\n';
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (line.indexOf('|') >= 0 && i + 1 < lines.length && isTableDivider(lines[i + 1])) {
|
|
116
|
+
flushParagraph();
|
|
117
|
+
closeList();
|
|
118
|
+
var headers = tableCells(line);
|
|
119
|
+
html += '<div class="workflow-markdown-table"><table><thead><tr>' + headers.map(function (cell) { return '<th>' + inlineFormat(cell) + '</th>'; }).join('') + '</tr></thead><tbody>';
|
|
120
|
+
i += 2;
|
|
121
|
+
while (i < lines.length && lines[i].indexOf('|') >= 0 && lines[i].trim() !== '') {
|
|
122
|
+
var cells = tableCells(lines[i]);
|
|
123
|
+
html += '<tr>' + headers.map(function (_, index) { return '<td>' + inlineFormat(cells[index] || '') + '</td>'; }).join('') + '</tr>';
|
|
124
|
+
i++;
|
|
125
|
+
}
|
|
126
|
+
html += '</tbody></table></div>';
|
|
127
|
+
i--;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
var heading = line.match(headingPattern);
|
|
132
|
+
if (heading) {
|
|
133
|
+
flushParagraph();
|
|
134
|
+
closeList();
|
|
135
|
+
var level = heading[1].length;
|
|
136
|
+
html += '<h' + level + '>' + inlineFormat(heading[2]) + '</h' + level + '>';
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (hrPattern.test(line)) {
|
|
140
|
+
flushParagraph();
|
|
141
|
+
closeList();
|
|
142
|
+
html += '<hr>';
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
var ul = line.match(ulPattern);
|
|
146
|
+
var ol = line.match(olPattern);
|
|
147
|
+
if (ul || ol) {
|
|
148
|
+
flushParagraph();
|
|
149
|
+
var wantType = ul ? 'ul' : 'ol';
|
|
150
|
+
if (listType !== wantType) {
|
|
151
|
+
closeList();
|
|
152
|
+
html += '<' + wantType + '>';
|
|
153
|
+
listType = wantType;
|
|
154
|
+
}
|
|
155
|
+
html += '<li>' + inlineFormat((ul || ol)[1]) + '</li>';
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
closeList();
|
|
159
|
+
|
|
160
|
+
if (line.trim() === '') {
|
|
161
|
+
flushParagraph();
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
paragraph.push(line.trim());
|
|
165
|
+
}
|
|
166
|
+
flushParagraph();
|
|
167
|
+
closeList();
|
|
168
|
+
return html || '<p class="hint">Nothing to preview yet.</p>';
|
|
169
|
+
}
|
|
170
|
+
`;
|