bazilion 0.14.2 → 0.15.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/dist/cli.js +1126 -334
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +8180 -3651
- package/dist/daemon.js.map +1 -1
- package/dist/migrations/0001_init.sql +171 -3
- package/dist/web/client/assets/ChatPane-55j13bBj.js +74 -0
- package/dist/web/client/assets/{ConfirmDialog-_bmG-wVG.js → ConfirmDialog-CGZzom9E.js} +1 -1
- package/dist/web/client/assets/{FieldRow-Do1cBkRc.js → FieldRow-DYNU9gWb.js} +1 -1
- package/dist/web/client/assets/{ProductionTeamPolicyEditor-XP-QJul4.js → ProductionTeamPolicyEditor-DT5Sl8jd.js} +1 -1
- package/dist/web/client/assets/{ProfileCommunicationEditor-CwdFPdpk.js → ProfileCommunicationEditor-TyCU5vXX.js} +1 -1
- package/dist/web/client/assets/ResultCard-Cps_lXVN.js +1 -0
- package/dist/web/client/assets/ResultSourceConversation-CGhKTSTD.js +1 -0
- package/dist/web/client/assets/TeamTabs-BZHyRnbd.js +1 -0
- package/dist/web/client/assets/{TemplatesTabs-D4WHvs6b.js → TemplatesTabs-BHzkPMRC.js} +1 -1
- package/dist/web/client/assets/{UnsavedChangesGuard-B1aLqiK5.js → UnsavedChangesGuard-CFQcKsrf.js} +1 -1
- package/dist/web/client/assets/_id-9nCIhbVd.js +1 -0
- package/dist/web/client/assets/{_id-3w4PFfma.js → _id-BSu3AqKA.js} +1 -1
- package/dist/web/client/assets/_id-CGd21j3k.js +1 -0
- package/dist/web/client/assets/{_id-BH3v_vI_.js → _id-D_eKokkd.js} +1 -1
- package/dist/web/client/assets/{_id-Cx7o4Zmf.js → _id-SRMFlIgP.js} +1 -1
- package/dist/web/client/assets/{activity-A_HrG1Tv.js → activity-Cn2-9PpZ.js} +1 -1
- package/dist/web/client/assets/{agents-BeeFCt2c.js → agents-CCmiZek6.js} +1 -1
- package/dist/web/client/assets/{agents-C8OVKq3N.js → agents-NY3VrZgB.js} +1 -1
- package/dist/web/client/assets/{approvals-BIdZ9BSn.js → approvals-CPDAPgrM.js} +1 -1
- package/dist/web/client/assets/{attention-B9bUrxiU.js → attention-Qra_9_OI.js} +1 -1
- package/dist/web/client/assets/chevron-right-DXE4CWf2.js +1 -0
- package/dist/web/client/assets/{config-By86S7k-.js → config-D8EO0LPB.js} +1 -1
- package/dist/web/client/assets/{inbox-DlXQCJLe.js → inbox-C5W-sm1q.js} +1 -1
- package/dist/web/client/assets/{index-CLdmsmiN.js → index-BUhhk_u9.js} +2 -2
- package/dist/web/client/assets/{learning-BqZIw2nA.js → learning-Dr-7_7J4.js} +1 -1
- package/dist/web/client/assets/login-Bu5UxbJh.js +1 -0
- package/dist/web/client/assets/{mcp-DKSY2yVa.js → mcp-BueuwQiv.js} +1 -1
- package/dist/web/client/assets/{members-9GuOiq6J.js → members-ZikuYNcy.js} +1 -1
- package/dist/web/client/assets/{memory-DiGMI6FC.js → memory-1JUJlPrn.js} +1 -1
- package/dist/web/client/assets/{policy-TBGQffw5.js → policy-DbkhsFNA.js} +1 -1
- package/dist/web/client/assets/results-mMr8Ar2u.js +1 -0
- package/dist/web/client/assets/routes-DJYB-MS9.js +1 -0
- package/dist/web/client/assets/{services-1Z398CES.js → services-kfQA9cpJ.js} +1 -1
- package/dist/web/client/assets/{skills-BP2gciFt.js → skills-C6pcgxaC.js} +1 -1
- package/dist/web/client/assets/styles-CcNf8jT_.css +2 -0
- package/dist/web/client/assets/{teams-tNoMDJ_M.js → teams-C6_Noz5X.js} +1 -1
- package/dist/web/client/assets/{teams-DBIivGT7.js → teams-LB0KBXY9.js} +1 -1
- package/dist/web/client/assets/telegram-A2jaI1QM.js +1 -0
- package/dist/web/client/assets/{tokens-eDWCGQQ2.js → tokens-BGlUpJcL.js} +1 -1
- package/dist/web/client/assets/{triggers-DZME3IcK.js → triggers-C54_feGg.js} +1 -1
- package/dist/web/client/assets/{welcome-B49sh_uf.js → welcome-DyUIswRi.js} +1 -1
- package/dist/web/client/assets/wire-constants-CBD-lTaa.js +1 -0
- package/dist/web/client/assets/{x-CHc7_-TH.js → x-BY2MPLr9.js} +1 -1
- package/dist/web/server/assets/{ChatPane-CgSe7tsy.js → ChatPane-DJ30FdFG.js} +1122 -107
- package/dist/web/server/assets/ResultCard-B3zD9N0t.js +143 -0
- package/dist/web/server/assets/ResultSourceConversation-zYogeOWp.js +64 -0
- package/dist/web/server/assets/{TeamTabs-Co3n2exj.js → TeamTabs-TCKjCvMA.js} +4 -0
- package/dist/web/server/assets/{_id-sNu5aXZt.js → _id-1LwoHhJg.js} +2 -1
- package/dist/web/server/assets/{_id-BeKhPKw3.js → _id-1hTvnKLN2.js} +7 -3
- package/dist/web/server/assets/{_id-BAA9KJBU.js → _id-B2EEyStS.js} +1 -1
- package/dist/web/server/assets/_id-BDEpe6k0.js +6 -0
- package/dist/web/server/assets/{_id-BqWTB8Wl.js → _id-B_-CDHOi2.js} +1 -1
- package/dist/web/server/assets/{_id-DxCnEFpm.js → _id-BvSWsPI5.js} +3 -4
- package/dist/web/server/assets/{_id-ndxFHx0t.js → _id-CDBtO_jL.js} +2 -2
- package/dist/web/server/assets/{_id-DvlDkk04.js → _id-DDNVQx3y.js} +1 -1
- package/dist/web/server/assets/{_id-BYKpT2Tu.js → _id-DFHB9JFQ.js} +1 -1
- package/dist/web/server/assets/{_id-HMy7jM3P.js → _id-DxFLSIio.js} +1 -1
- package/dist/web/server/assets/{_id-DYU6uIBx.js → _id-T_8btpbB.js} +1 -1
- package/dist/web/server/assets/_id-wyjrf0JG.js +17 -0
- package/dist/web/server/assets/{_tanstack-start-manifest_v-Duhf0z7H.js → _tanstack-start-manifest_v-DP4ZUBw3.js} +102 -75
- package/dist/web/server/assets/{activity-BWv1goK6.js → activity-5fWKPDxj.js} +2 -2
- package/dist/web/server/assets/{activity-LjpblbDL.js → activity-C88qrNqv.js} +1 -1
- package/dist/web/server/assets/{activity-9VP6QDTH.js → activity-D73w4mkZ.js} +1 -1
- package/dist/web/server/assets/{agents-DjyQk94u.js → agents-DB5hCSAI.js} +1 -1
- package/dist/web/server/assets/{agents-BJAv919x.js → agents-DRSo7lRX.js} +1 -1
- package/dist/web/server/assets/{approvals-BYi84gwl.js → approvals-4y9bZF4r.js} +1 -1
- package/dist/web/server/assets/{approvals-7JOoBchn.js → approvals-DTdrltyk.js} +1 -1
- package/dist/web/server/assets/{approvals-Bz123liE.js → approvals-DXoN-T57.js} +15 -1
- package/dist/web/server/assets/{attention-UhqPK_Ro.js → attention-BFx8ZkmH.js} +1 -1
- package/dist/web/server/assets/{auth-7BHTH-KS.js → auth-_eaCwhyq.js} +1 -1
- package/dist/web/server/assets/{config-BMiajTZP.js → config-B7JIfv_7.js} +1 -1
- package/dist/web/server/assets/{daemon-client-CI5NHwNC.js → daemon-client-B06W1Qa2.js} +54 -0
- package/dist/web/server/assets/{inbox-Dv55rGYq.js → inbox-YRpDQcvp.js} +1 -1
- package/dist/web/server/assets/{learning-C2upa1CE.js → learning-UBZb6h6M.js} +1 -1
- package/dist/web/server/assets/{login-BNj3U6ok.js → login-B_-9L8TU.js} +7 -2
- package/dist/web/server/assets/{login-Be8eP4Jp.js → login-rDox7PRD.js} +5 -2
- package/dist/web/server/assets/{mcp-BvnvlVFd.js → mcp-Dv6RXMaS.js} +1 -1
- package/dist/web/server/assets/{members-BP3UTqu1.js → members-BFTKSlOe.js} +1 -1
- package/dist/web/server/assets/{members-DiYtr-zm.js → members-CD3GiTfF.js} +1 -1
- package/dist/web/server/assets/{members-DHYTVgwb.js → members-cc5SeEaW.js} +2 -2
- package/dist/web/server/assets/{memory-CkXUgf5s.js → memory-C5i_GxlY.js} +2 -2
- package/dist/web/server/assets/{memory-DTFEmfF3.js → memory-CVqnyUaM.js} +1 -1
- package/dist/web/server/assets/{memory-BqV-Afy1.js → memory-D0PQgZAn.js} +1 -1
- package/dist/web/server/assets/{policy-18fdTFO4.js → policy-C-p8HIhA.js} +1 -1
- package/dist/web/server/assets/{policy-Bvvav8fh.js → policy-Dgjb0_gK.js} +2 -2
- package/dist/web/server/assets/{policy-BddK4xom.js → policy-bLKwvnja.js} +1 -1
- package/dist/web/server/assets/results-Cfev4KNt.js +12 -0
- package/dist/web/server/assets/results-Cj-Dlw3C.js +173 -0
- package/dist/web/server/assets/results-CwEQ5EUL.js +12 -0
- package/dist/web/server/assets/{router-CY_pCgP1.js → router-d3sTMpMX.js} +60 -43
- package/dist/web/server/assets/{routes-DAU2g7Uz.js → routes-B765DVhj.js} +1 -1
- package/dist/web/server/assets/{routes-BgHisAxH.js → routes-MIZz6uMr.js} +2 -2
- package/dist/web/server/assets/{routes-COtkyZG1.js → routes-cW4MWU18.js} +3 -3
- package/dist/web/server/assets/{services-DozuJtzX.js → services-BCbdn3R9.js} +1 -1
- package/dist/web/server/assets/{skills-DfGSJTCB.js → skills-Bpoa8MIp.js} +1 -1
- package/dist/web/server/assets/{teams-be05ci17.js → teams-CXzwqzcE.js} +1 -1
- package/dist/web/server/assets/{teams-DPnAX4wD.js → teams-hWGjbpUA.js} +1 -1
- package/dist/web/server/assets/{telegram-Dj4Wwhd6.js → telegram-CoNeOgqZ.js} +465 -1
- package/dist/web/server/assets/{telegram-1AWL6lFw.js → telegram-DhpvtGUc.js} +1 -1
- package/dist/web/server/assets/{telegram-DbOFpTFm.js → telegram-Zd1rIZxg.js} +1 -1
- package/dist/web/server/assets/{tokens-DjM8GsgS.js → tokens-Bjp19Vkn.js} +1 -1
- package/dist/web/server/assets/{triggers-Nezfw-Bd.js → triggers-DJlcvXzn.js} +1 -1
- package/dist/web/server/server.js +31 -27
- package/dist/worker.js +294 -104
- package/dist/worker.js.map +1 -1
- package/package.json +3 -3
- package/dist/web/client/assets/TeamTabs-DIRiKcqx.js +0 -1
- package/dist/web/client/assets/_id-DIiVVxBl.js +0 -1
- package/dist/web/client/assets/chevron-right-VWrk_dTX.js +0 -1
- package/dist/web/client/assets/login-CCMPXiny.js +0 -1
- package/dist/web/client/assets/routes-g3yUOhCb.js +0 -1
- package/dist/web/client/assets/styles-B5vcgXln.css +0 -2
- package/dist/web/client/assets/telegram-CJG_DFdI.js +0 -1
- package/dist/web/client/assets/wire-constants-zZ7Wjb9C.js +0 -74
|
@@ -37,7 +37,7 @@ CREATE TABLE agents (
|
|
|
37
37
|
team_id TEXT NOT NULL REFERENCES teams(id) ON DELETE RESTRICT,
|
|
38
38
|
created_at INTEGER NOT NULL,
|
|
39
39
|
archived_at INTEGER
|
|
40
|
-
, telegram_topic_id INTEGER, telegram_topic_name_locked INTEGER NOT NULL DEFAULT 0, telegram_icon_emoji TEXT, telegram_mirror_mode TEXT NOT NULL DEFAULT 'minimal'
|
|
40
|
+
, telegram_topic_id INTEGER, telegram_binding_id TEXT NOT NULL DEFAULT (lower(hex(randomblob(16)))), telegram_topic_name_locked INTEGER NOT NULL DEFAULT 0, telegram_icon_emoji TEXT, telegram_mirror_mode TEXT NOT NULL DEFAULT 'minimal'
|
|
41
41
|
CHECK (telegram_mirror_mode IN ('minimal','verbose')));
|
|
42
42
|
CREATE TABLE agent_skills (
|
|
43
43
|
agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
|
@@ -62,6 +62,7 @@ CREATE TABLE trigger_dispatches (
|
|
|
62
62
|
id TEXT PRIMARY KEY,
|
|
63
63
|
trigger_id TEXT NOT NULL REFERENCES agent_triggers(id) ON DELETE CASCADE,
|
|
64
64
|
agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
|
65
|
+
conversation_id TEXT NOT NULL,
|
|
65
66
|
scheduled_at INTEGER NOT NULL,
|
|
66
67
|
status TEXT NOT NULL CHECK (status IN ('pending','running','retrying','succeeded','failed','cancelled')),
|
|
67
68
|
attempt_count INTEGER NOT NULL DEFAULT 0,
|
|
@@ -72,7 +73,8 @@ CREATE TABLE trigger_dispatches (
|
|
|
72
73
|
last_error TEXT,
|
|
73
74
|
created_at INTEGER NOT NULL,
|
|
74
75
|
updated_at INTEGER NOT NULL,
|
|
75
|
-
UNIQUE (trigger_id, scheduled_at)
|
|
76
|
+
UNIQUE (trigger_id, scheduled_at),
|
|
77
|
+
FOREIGN KEY (agent_id, conversation_id) REFERENCES agent_conversations(agent_id, id)
|
|
76
78
|
);
|
|
77
79
|
CREATE INDEX trigger_dispatches_claimable
|
|
78
80
|
ON trigger_dispatches(status, next_attempt_at, scheduled_at);
|
|
@@ -87,7 +89,8 @@ CREATE TABLE messages (
|
|
|
87
89
|
causal_hop INTEGER NOT NULL DEFAULT 0 CHECK (causal_hop >= 0),
|
|
88
90
|
payload TEXT NOT NULL,
|
|
89
91
|
created_at INTEGER NOT NULL,
|
|
90
|
-
read_at INTEGER
|
|
92
|
+
read_at INTEGER,
|
|
93
|
+
conversation_id TEXT
|
|
91
94
|
, policy_disposition TEXT NOT NULL DEFAULT 'deliverable'
|
|
92
95
|
CHECK (policy_disposition IN ('deliverable', 'policy_blocked')), policy_blocked_at INTEGER, policy_claimed_at INTEGER, policy_delivered_at INTEGER);
|
|
93
96
|
CREATE INDEX messages_to_unread ON messages(to_agent_id) WHERE read_at IS NULL;
|
|
@@ -219,6 +222,7 @@ CREATE UNIQUE INDEX idx_agents_telegram_topic_id
|
|
|
219
222
|
WHERE telegram_topic_id IS NOT NULL;
|
|
220
223
|
CREATE TABLE telegram_allowed_users (
|
|
221
224
|
user_id INTEGER PRIMARY KEY,
|
|
225
|
+
grant_id TEXT NOT NULL DEFAULT (lower(hex(randomblob(16)))),
|
|
222
226
|
username TEXT,
|
|
223
227
|
label TEXT,
|
|
224
228
|
role TEXT NOT NULL DEFAULT 'member' CHECK (role IN ('owner','member')),
|
|
@@ -520,6 +524,28 @@ WHEN NOT EXISTS (
|
|
|
520
524
|
BEGIN
|
|
521
525
|
SELECT RAISE(ABORT, 'Team Agent state does not match agents.team_id');
|
|
522
526
|
END;
|
|
527
|
+
-- Captured bytes and their publication receipt share one atomic SQLite commit.
|
|
528
|
+
-- Agent identity is retained across deletion/transfer; Team deletion owns cleanup.
|
|
529
|
+
CREATE TABLE agent_results (
|
|
530
|
+
id TEXT PRIMARY KEY,
|
|
531
|
+
team_id TEXT NOT NULL REFERENCES teams(id) ON DELETE CASCADE,
|
|
532
|
+
agent_id TEXT NOT NULL,
|
|
533
|
+
session_id TEXT NOT NULL,
|
|
534
|
+
tool_call_id TEXT NOT NULL,
|
|
535
|
+
name TEXT NOT NULL,
|
|
536
|
+
mime_type TEXT NOT NULL,
|
|
537
|
+
byte_length INTEGER NOT NULL CHECK (byte_length BETWEEN 0 AND 26214400),
|
|
538
|
+
sha256 TEXT NOT NULL CHECK (length(sha256) = 64),
|
|
539
|
+
created_at INTEGER NOT NULL,
|
|
540
|
+
released_at INTEGER,
|
|
541
|
+
deleted_at INTEGER,
|
|
542
|
+
bytes BLOB,
|
|
543
|
+
UNIQUE (agent_id, session_id, tool_call_id),
|
|
544
|
+
CHECK ((deleted_at IS NULL AND bytes IS NOT NULL AND length(bytes) = byte_length)
|
|
545
|
+
OR (deleted_at IS NOT NULL AND bytes IS NULL))
|
|
546
|
+
);
|
|
547
|
+
CREATE INDEX agent_results_team_time ON agent_results(team_id, created_at DESC, id DESC);
|
|
548
|
+
|
|
523
549
|
CREATE TRIGGER validate_team_policy_baseline_update
|
|
524
550
|
BEFORE UPDATE OF baseline_instantiation_id ON team_policies
|
|
525
551
|
WHEN NEW.baseline_instantiation_id IS NOT NULL AND NOT EXISTS (
|
|
@@ -529,3 +555,145 @@ WHEN NEW.baseline_instantiation_id IS NOT NULL AND NOT EXISTS (
|
|
|
529
555
|
BEGIN
|
|
530
556
|
SELECT RAISE(ABORT, 'baseline instantiation belongs to another Team');
|
|
531
557
|
END;
|
|
558
|
+
|
|
559
|
+
-- Conversation metadata never duplicates the canonical Pi transcript.
|
|
560
|
+
CREATE TABLE agent_conversations (
|
|
561
|
+
id TEXT PRIMARY KEY,
|
|
562
|
+
agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
|
563
|
+
filename TEXT NOT NULL,
|
|
564
|
+
title TEXT NOT NULL,
|
|
565
|
+
title_revision INTEGER NOT NULL DEFAULT 1,
|
|
566
|
+
initial_title TEXT,
|
|
567
|
+
creation_revision INTEGER NOT NULL,
|
|
568
|
+
creation_conversation_id TEXT,
|
|
569
|
+
created_at INTEGER NOT NULL,
|
|
570
|
+
updated_at INTEGER NOT NULL,
|
|
571
|
+
UNIQUE(agent_id, id),
|
|
572
|
+
UNIQUE(agent_id, filename)
|
|
573
|
+
);
|
|
574
|
+
CREATE INDEX agent_conversations_agent_time ON agent_conversations(agent_id, created_at DESC, id);
|
|
575
|
+
CREATE TABLE agent_conversation_selection (
|
|
576
|
+
agent_id TEXT PRIMARY KEY REFERENCES agents(id) ON DELETE CASCADE,
|
|
577
|
+
conversation_id TEXT NOT NULL,
|
|
578
|
+
revision INTEGER NOT NULL CHECK(revision > 0),
|
|
579
|
+
FOREIGN KEY(agent_id, conversation_id) REFERENCES agent_conversations(agent_id, id)
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
-- Retained user input only: canonical responses remain in Pi JSONL.
|
|
583
|
+
CREATE TABLE user_queue_controls (
|
|
584
|
+
agent_id TEXT PRIMARY KEY REFERENCES agents(id) ON DELETE CASCADE,
|
|
585
|
+
paused INTEGER NOT NULL DEFAULT 0 CHECK(paused IN (0,1)),
|
|
586
|
+
revision INTEGER NOT NULL DEFAULT 0,
|
|
587
|
+
reason TEXT,
|
|
588
|
+
next_position INTEGER NOT NULL DEFAULT 1
|
|
589
|
+
);
|
|
590
|
+
CREATE TABLE user_queue_items (
|
|
591
|
+
id TEXT PRIMARY KEY,
|
|
592
|
+
agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
|
593
|
+
team_id TEXT NOT NULL,
|
|
594
|
+
conversation_id TEXT NOT NULL,
|
|
595
|
+
source TEXT NOT NULL CHECK(source IN ('http','telegram')),
|
|
596
|
+
attempt_id TEXT NOT NULL,
|
|
597
|
+
input_digest TEXT NOT NULL,
|
|
598
|
+
provenance_json TEXT,
|
|
599
|
+
revision INTEGER NOT NULL DEFAULT 1,
|
|
600
|
+
position INTEGER NOT NULL,
|
|
601
|
+
status TEXT NOT NULL CHECK(status IN ('pending','claimed','running','held','completed','failed','cancelled','uncertain','superseded')),
|
|
602
|
+
text TEXT,
|
|
603
|
+
payload_retained INTEGER NOT NULL DEFAULT 1 CHECK(payload_retained IN (0,1)),
|
|
604
|
+
supersedes_id TEXT,
|
|
605
|
+
approval_id TEXT REFERENCES communication_approvals(id) ON DELETE SET NULL,
|
|
606
|
+
diagnostic TEXT,
|
|
607
|
+
created_at INTEGER NOT NULL,
|
|
608
|
+
updated_at INTEGER NOT NULL,
|
|
609
|
+
started_at INTEGER,
|
|
610
|
+
finished_at INTEGER,
|
|
611
|
+
UNIQUE(source, attempt_id),
|
|
612
|
+
FOREIGN KEY(agent_id, conversation_id) REFERENCES agent_conversations(agent_id, id) ON DELETE CASCADE
|
|
613
|
+
);
|
|
614
|
+
CREATE INDEX user_queue_agent_order ON user_queue_items(agent_id, position, created_at);
|
|
615
|
+
CREATE INDEX user_queue_status ON user_queue_items(status, updated_at);
|
|
616
|
+
CREATE TABLE user_queue_attachments (
|
|
617
|
+
id TEXT PRIMARY KEY,
|
|
618
|
+
item_id TEXT NOT NULL REFERENCES user_queue_items(id) ON DELETE CASCADE,
|
|
619
|
+
ordinal INTEGER NOT NULL,
|
|
620
|
+
name TEXT,
|
|
621
|
+
mime_type TEXT NOT NULL,
|
|
622
|
+
byte_length INTEGER NOT NULL,
|
|
623
|
+
sha256 TEXT NOT NULL,
|
|
624
|
+
bytes BLOB NOT NULL,
|
|
625
|
+
UNIQUE(item_id, ordinal)
|
|
626
|
+
);
|
|
627
|
+
|
|
628
|
+
-- Narrow live clarification receipts; continuation ownership remains process-local.
|
|
629
|
+
CREATE TABLE IF NOT EXISTS agent_questions (
|
|
630
|
+
id TEXT PRIMARY KEY,
|
|
631
|
+
agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
|
632
|
+
team_id TEXT NOT NULL,
|
|
633
|
+
conversation_id TEXT NOT NULL,
|
|
634
|
+
turn_id TEXT NOT NULL,
|
|
635
|
+
tool_call_id TEXT NOT NULL,
|
|
636
|
+
question_json TEXT NOT NULL,
|
|
637
|
+
delivered_at INTEGER,
|
|
638
|
+
binding_json TEXT NOT NULL,
|
|
639
|
+
status TEXT NOT NULL CHECK (status IN ('pending','answered','skipped','expired','cancelled')),
|
|
640
|
+
revision INTEGER NOT NULL DEFAULT 0,
|
|
641
|
+
created_at INTEGER NOT NULL,
|
|
642
|
+
expires_at INTEGER NOT NULL,
|
|
643
|
+
settled_at INTEGER,
|
|
644
|
+
answer_json TEXT,
|
|
645
|
+
response_request_id TEXT,
|
|
646
|
+
no_answer_reason TEXT,
|
|
647
|
+
continuation TEXT NOT NULL CHECK (continuation IN ('waiting','unconfirmed','consumed','interrupted')),
|
|
648
|
+
consumed_at INTEGER,
|
|
649
|
+
delivery_approval_id TEXT REFERENCES communication_approvals(id) ON DELETE SET NULL,
|
|
650
|
+
answer_approval_id TEXT REFERENCES communication_approvals(id) ON DELETE SET NULL,
|
|
651
|
+
proposal_json TEXT,
|
|
652
|
+
FOREIGN KEY (agent_id, conversation_id) REFERENCES agent_conversations(agent_id, id) ON DELETE CASCADE,
|
|
653
|
+
UNIQUE (turn_id, tool_call_id)
|
|
654
|
+
);
|
|
655
|
+
CREATE UNIQUE INDEX IF NOT EXISTS agent_questions_one_pending ON agent_questions(turn_id) WHERE status = 'pending';
|
|
656
|
+
CREATE INDEX IF NOT EXISTS agent_questions_agent_time ON agent_questions(agent_id, created_at, id);
|
|
657
|
+
|
|
658
|
+
-- Daemon-only provenance key. Never merged into provider/worker environments.
|
|
659
|
+
-- Stable across bootstrap credential rotation and included in canonical backups.
|
|
660
|
+
CREATE TABLE question_receipt_key (
|
|
661
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
662
|
+
key BLOB NOT NULL CHECK (length(key) = 32)
|
|
663
|
+
);
|
|
664
|
+
|
|
665
|
+
-- Operator notification metadata only. Source content remains in its canonical tables.
|
|
666
|
+
CREATE TABLE notification_settings (
|
|
667
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
668
|
+
revision INTEGER NOT NULL DEFAULT 0,
|
|
669
|
+
enabled INTEGER NOT NULL DEFAULT 0 CHECK (enabled IN (0, 1)),
|
|
670
|
+
restore_paused INTEGER NOT NULL DEFAULT 0 CHECK (restore_paused IN (0, 1)),
|
|
671
|
+
restore_history_uncertain INTEGER NOT NULL DEFAULT 0 CHECK (restore_history_uncertain IN (0, 1)),
|
|
672
|
+
kinds_json TEXT NOT NULL,
|
|
673
|
+
kind_cutoffs_json TEXT NOT NULL DEFAULT '{}',
|
|
674
|
+
timezone TEXT NOT NULL DEFAULT 'UTC',
|
|
675
|
+
quiet_json TEXT,
|
|
676
|
+
destination_json TEXT,
|
|
677
|
+
eligible_after INTEGER,
|
|
678
|
+
updated_at INTEGER NOT NULL DEFAULT 0
|
|
679
|
+
);
|
|
680
|
+
CREATE TABLE notification_receipts (
|
|
681
|
+
id TEXT PRIMARY KEY,
|
|
682
|
+
source_kind TEXT NOT NULL CHECK (source_kind IN ('communication_approval','lesson_proposal','review_failure','trigger_failure','agent_loop_break')),
|
|
683
|
+
source_id TEXT NOT NULL,
|
|
684
|
+
agent_id TEXT,
|
|
685
|
+
team_id TEXT,
|
|
686
|
+
destination_id TEXT NOT NULL,
|
|
687
|
+
destination_json TEXT NOT NULL CHECK (length(destination_json) <= 4096),
|
|
688
|
+
state TEXT NOT NULL CHECK (state IN ('deferred','sending','delivered','failed','uncertain','suppressed')),
|
|
689
|
+
attempts INTEGER NOT NULL DEFAULT 0,
|
|
690
|
+
created_at INTEGER NOT NULL,
|
|
691
|
+
updated_at INTEGER NOT NULL,
|
|
692
|
+
attempted_at INTEGER,
|
|
693
|
+
delivered_at INTEGER,
|
|
694
|
+
telegram_message_id INTEGER,
|
|
695
|
+
diagnostic TEXT CHECK (diagnostic IS NULL OR length(diagnostic) <= 160),
|
|
696
|
+
UNIQUE (source_kind, source_id, destination_id)
|
|
697
|
+
);
|
|
698
|
+
CREATE INDEX notification_receipts_state ON notification_receipts(state, created_at, id);
|
|
699
|
+
CREATE INDEX notification_receipts_time ON notification_receipts(created_at, id);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import{r as e,t}from"./jsx-runtime-DGeXAQPT.js";import{t as n}from"./react-3W8R1pOO.js";import{t as r}from"./Button-ByiV6fpd.js";import{t as i}from"./ResultCard-Cps_lXVN.js";var a=e(n(),1);function o(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function s(e){if(Array.isArray(e))return e}function c(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function l(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
2
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function u(e,t){return s(e)||c(e,t)||d(e,t)||l()}function d(e,t){if(e){if(typeof e==`string`)return o(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}var ee=Object.entries,f=Object.setPrototypeOf,p=Object.isFrozen,m=Object.getPrototypeOf,h=Object.getOwnPropertyDescriptor,g=Object.freeze,_=Object.seal,v=Object.create,y=typeof Reflect<`u`&&Reflect,b=y.apply,x=y.construct;g||=function(e){return e},_||=function(e){return e},b||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},x||=function(e){return new e(...[...arguments].slice(1))};var S=P(Array.prototype.forEach),te=P(Array.prototype.lastIndexOf),C=P(Array.prototype.pop),w=P(Array.prototype.push),ne=P(Array.prototype.splice),T=Array.isArray,re=P(String.prototype.toLowerCase),ie=P(String.prototype.toString),ae=P(String.prototype.match),E=P(String.prototype.replace),D=P(String.prototype.indexOf),oe=P(String.prototype.trim),O=P(Number.prototype.toString),k=P(Boolean.prototype.toString),A=typeof BigInt>`u`?null:P(BigInt.prototype.toString),j=typeof Symbol>`u`?null:P(Symbol.prototype.toString),M=P(Object.prototype.hasOwnProperty),se=P(Object.prototype.toString),N=P(RegExp.prototype.test),ce=le(TypeError);function P(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return b(e,t,n)}}function le(e){return function(){return x(e,[...arguments])}}function F(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:re;if(f&&f(e,null),!T(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(p(t)||(t[r]=e),i=e)}e[i]=!0}return e}function ue(e){for(let t=0;t<e.length;t++)M(e,t)||(e[t]=null);return e}function I(e){let t=v(null);for(let r of ee(e)){var n=u(r,2);let i=n[0],a=n[1];M(e,i)&&(T(a)?t[i]=ue(a):a&&typeof a==`object`&&a.constructor===Object?t[i]=I(a):t[i]=a)}return t}function L(e){switch(typeof e){case`string`:return e;case`number`:return O(e);case`boolean`:return k(e);case`bigint`:return A?A(e):`0`;case`symbol`:return j?j(e):`Symbol()`;case`undefined`:return se(e);case`function`:case`object`:{if(e===null)return se(e);let t=e,n=R(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:se(e)}return se(e)}default:return se(e)}}function R(e,t){for(;e!==null;){let n=h(e,t);if(n){if(n.get)return P(n.get);if(typeof n.value==`function`)return P(n.value)}e=m(e)}function n(){return null}return n}function de(e){try{return N(e,``),!0}catch{return!1}}var fe=g(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),z=g(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),pe=g([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),me=g([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),he=g(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),ge=g([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),_e=g([`#text`]),ve=g(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),B=g(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-rendering.textlength.type.u1.u2.unicode.values.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),ye=g(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),be=g([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),xe=_(/{{[\w\W]*|^[\w\W]*}}/g),Se=_(/<%[\w\W]*|^[\w\W]*%>/g),Ce=_(/\${[\w\W]*/g),we=_(/^data-[\-\w.\u00B7-\uFFFF]+$/),Te=_(/^aria-[\-\w]+$/),Ee=_(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),De=_(/^(?:\w+script|data):/i),Oe=_(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),ke=_(/^html$/i),Ae=_(/^[a-z][.\w]*(-[.\w]+)+$/i),je=_(/<[/\w!]/g),Me=_(/<[/\w]/g),Ne=_(/<\/no(script|embed|frames)/i),Pe=_(/\/>/i),Fe={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Ie=function(){return typeof window>`u`?null:window},Le=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},Re=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},ze=function(e,t,n,r){return M(e,t)&&T(e[t])?F(r.base?I(r.base):{},e[t],r.transform):n};function Be(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ie(),t=e=>Be(e);if(t.version=`3.4.11`,t.removed=[],!e||!e.document||e.document.nodeType!==Fe.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=R(d,`cloneNode`),p=R(d,`remove`),m=R(d,`nextSibling`),h=R(d,`childNodes`),y=R(d,`parentNode`),b=R(d,`shadowRoot`),x=R(d,`attributes`),O=o&&o.prototype?R(o.prototype,`nodeType`):null,k=o&&o.prototype?R(o.prototype,`nodeName`):null;if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let A,j=``,se,P=!1,le=0,ue=function(){if(le>0)throw ce(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},Ve=function(e){ue(),le++;try{return A.createHTML(e)}finally{le--}},He=function(e){ue(),le++;try{return A.createScriptURL(e)}finally{le--}},Ue=function(){return P||=(se=Le(u,i),!0),se},We=n,Ge=We.implementation,Ke=We.createNodeIterator,V=We.createDocumentFragment,qe=We.getElementsByTagName,H=r.importNode,U=Re();t.isSupported=typeof ee==`function`&&typeof y==`function`&&Ge&&Ge.createHTMLDocument!==void 0;let Je=xe,Ye=Se,Xe=Ce,Ze=we,Qe=Te,$e=De,et=Oe,tt=Ae,nt=Ee,W=null,rt=F({},[...fe,...z,...pe,...he,..._e]),G=null,it=F({},[...ve,...B,...ye,...be]),K=Object.seal(v(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),at=null,ot=null,st=Object.seal(v(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),ct=!0,lt=!0,ut=!1,dt=!0,ft=!1,pt=!0,mt=!1,ht=!1,gt=null,_t=null,vt=!1,yt=!1,bt=!1,xt=!1,St=!0,Ct=!1,wt=`user-content-`,Tt=!0,Et=!1,Dt={},Ot=null,kt=F({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),At=null,jt=F({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Mt=null,Nt=F({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Pt=`http://www.w3.org/1998/Math/MathML`,Ft=`http://www.w3.org/2000/svg`,q=`http://www.w3.org/1999/xhtml`,It=q,Lt=!1,Rt=null,zt=F({},[Pt,Ft,q],ie),Bt=g([`mi`,`mo`,`mn`,`ms`,`mtext`]),Vt=F({},Bt),Ht=g([`annotation-xml`]),Ut=F({},Ht),Wt=F({},[`title`,`style`,`font`,`a`,`script`]),Gt=null,Kt=[`application/xhtml+xml`,`text/html`],J=null,qt=null,Jt=n.createElement(`form`),Y=function(e){return e instanceof RegExp||e instanceof Function},Yt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(qt&&qt===e)return;(!e||typeof e!=`object`)&&(e={}),e=I(e),Gt=Kt.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,J=Gt===`application/xhtml+xml`?ie:re,W=ze(e,`ALLOWED_TAGS`,rt,{transform:J}),G=ze(e,`ALLOWED_ATTR`,it,{transform:J}),Rt=ze(e,`ALLOWED_NAMESPACES`,zt,{transform:ie}),Mt=ze(e,`ADD_URI_SAFE_ATTR`,Nt,{transform:J,base:Nt}),At=ze(e,`ADD_DATA_URI_TAGS`,jt,{transform:J,base:jt}),Ot=ze(e,`FORBID_CONTENTS`,kt,{transform:J}),at=ze(e,`FORBID_TAGS`,I({}),{transform:J}),ot=ze(e,`FORBID_ATTR`,I({}),{transform:J}),Dt=M(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?I(e.USE_PROFILES):e.USE_PROFILES:!1,ct=e.ALLOW_ARIA_ATTR!==!1,lt=e.ALLOW_DATA_ATTR!==!1,ut=e.ALLOW_UNKNOWN_PROTOCOLS||!1,dt=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,ft=e.SAFE_FOR_TEMPLATES||!1,pt=e.SAFE_FOR_XML!==!1,mt=e.WHOLE_DOCUMENT||!1,yt=e.RETURN_DOM||!1,bt=e.RETURN_DOM_FRAGMENT||!1,xt=e.RETURN_TRUSTED_TYPE||!1,vt=e.FORCE_BODY||!1,St=e.SANITIZE_DOM!==!1,Ct=e.SANITIZE_NAMED_PROPS||!1,Tt=e.KEEP_CONTENT!==!1,Et=e.IN_PLACE||!1,nt=de(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:Ee,It=typeof e.NAMESPACE==`string`?e.NAMESPACE:q,Vt=M(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?I(e.MATHML_TEXT_INTEGRATION_POINTS):F({},Bt),Ut=M(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?I(e.HTML_INTEGRATION_POINTS):F({},Ht);let t=M(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?I(e.CUSTOM_ELEMENT_HANDLING):v(null);if(K=v(null),M(t,`tagNameCheck`)&&Y(t.tagNameCheck)&&(K.tagNameCheck=t.tagNameCheck),M(t,`attributeNameCheck`)&&Y(t.attributeNameCheck)&&(K.attributeNameCheck=t.attributeNameCheck),M(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(K.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),_(K),ft&&(lt=!1),bt&&(yt=!0),Dt&&(W=F({},_e),G=v(null),Dt.html===!0&&(F(W,fe),F(G,ve)),Dt.svg===!0&&(F(W,z),F(G,B),F(G,be)),Dt.svgFilters===!0&&(F(W,pe),F(G,B),F(G,be)),Dt.mathMl===!0&&(F(W,he),F(G,ye),F(G,be))),st.tagCheck=null,st.attributeCheck=null,M(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?st.tagCheck=e.ADD_TAGS:T(e.ADD_TAGS)&&(W===rt&&(W=I(W)),F(W,e.ADD_TAGS,J))),M(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?st.attributeCheck=e.ADD_ATTR:T(e.ADD_ATTR)&&(G===it&&(G=I(G)),F(G,e.ADD_ATTR,J))),M(e,`ADD_URI_SAFE_ATTR`)&&T(e.ADD_URI_SAFE_ATTR)&&F(Mt,e.ADD_URI_SAFE_ATTR,J),M(e,`FORBID_CONTENTS`)&&T(e.FORBID_CONTENTS)&&(Ot===kt&&(Ot=I(Ot)),F(Ot,e.FORBID_CONTENTS,J)),M(e,`ADD_FORBID_CONTENTS`)&&T(e.ADD_FORBID_CONTENTS)&&(Ot===kt&&(Ot=I(Ot)),F(Ot,e.ADD_FORBID_CONTENTS,J)),Tt&&(W[`#text`]=!0),mt&&F(W,[`html`,`head`,`body`]),W.table&&(F(W,[`tbody`]),delete at.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw ce(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw ce(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=A;A=e.TRUSTED_TYPES_POLICY;try{j=Ve(``)}catch(e){throw A=t,e}}else e.TRUSTED_TYPES_POLICY===null?(A=void 0,j=``):(A===void 0&&(A=Ue()),A&&typeof j==`string`&&(j=Ve(``)));g&&g(e),qt=e},Xt=F({},[...z,...pe,...me]),Zt=F({},[...he,...ge]),Qt=function(e,t,n){return t.namespaceURI===q?e===`svg`:t.namespaceURI===Pt?e===`svg`&&(n===`annotation-xml`||Vt[n]):!!Xt[e]},$t=function(e,t,n){return t.namespaceURI===q?e===`math`:t.namespaceURI===Ft?e===`math`&&Ut[n]:!!Zt[e]},en=function(e,t,n){return t.namespaceURI===Ft&&!Ut[n]||t.namespaceURI===Pt&&!Vt[n]?!1:!Zt[e]&&(Wt[e]||!Xt[e])},tn=function(e){let t=y(e);(!t||!t.tagName)&&(t={namespaceURI:It,tagName:`template`});let n=re(e.tagName),r=re(t.tagName);return Rt[e.namespaceURI]?e.namespaceURI===Ft?Qt(n,t,r):e.namespaceURI===Pt?$t(n,t,r):e.namespaceURI===q?en(n,t,r):!!(Gt===`application/xhtml+xml`&&Rt[e.namespaceURI]):!1},nn=function(e){w(t.removed,{element:e});try{y(e).removeChild(e)}catch{if(p(e),!y(e))throw ce(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},rn=function(e){let t=h(e);if(t){let e=[];S(t,t=>{w(e,t)}),S(e,e=>{try{p(e)}catch{}})}let n=x(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;if(typeof i==`string`)try{e.removeAttribute(i)}catch{}}},X=function(e,n){try{w(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{w(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e===`is`)if(yt||bt)try{nn(n)}catch{}else try{n.setAttribute(e,``)}catch{}},an=function(e){let t=x(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;if(!(typeof i!=`string`||G[J(i)]))try{e.removeAttribute(i)}catch{}}},on=function(e){let t=[e];for(;t.length>0;){let e=t.pop();(O?O(e):e.nodeType)===Fe.element&&an(e);let n=h(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},Z=function(e){let t=null,r=null;if(vt)e=`<remove></remove>`+e;else{let t=ae(e,/^[\r\n\t ]+/);r=t&&t[0]}Gt===`application/xhtml+xml`&&It===q&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=A?Ve(e):e;if(It===q)try{t=new l().parseFromString(i,Gt)}catch{}if(!t||!t.documentElement){t=Ge.createDocument(It,`template`,null);try{t.documentElement.innerHTML=Lt?j:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),It===q?qe.call(t,mt?`html`:`body`)[0]:mt?t.documentElement:a},sn=function(e){return Ke.call(e.ownerDocument||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},cn=function(e){return e=E(e,Je,` `),e=E(e,Ye,` `),e=E(e,Xe,` `),e},Q=function(e){e.normalize();let t=Ke.call(e.ownerDocument||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),n=t.nextNode();for(;n;)n.data=cn(n.data),n=t.nextNode();let r=e.querySelectorAll?.call(e,`template`);r&&S(r,e=>{un(e.content)&&Q(e.content)})},ln=function(e){let t=k?k(e):null;return typeof t!=`string`||J(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==x(e)||typeof e.removeAttribute!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==O(e)||e.childNodes!==h(e)},un=function(e){if(!O||typeof e!=`object`||!e)return!1;try{return O(e)===Fe.documentFragment}catch{return!1}},dn=function(e){if(!O||typeof e!=`object`||!e)return!1;try{return typeof O(e)==`number`}catch{return!1}};function fn(e,n,r){e.length!==0&&S(e,e=>{e.call(t,n,r,qt)})}let $=function(e,t){return!!(pt&&e.hasChildNodes()&&!dn(e.firstElementChild)&&N(je,e.textContent)&&N(je,e.innerHTML)||pt&&e.namespaceURI===q&&t===`style`&&dn(e.firstElementChild)||e.nodeType===Fe.processingInstruction||pt&&e.nodeType===Fe.comment&&N(Me,e.data))},pn=function(e,t){if(!at[t]&&_n(t)&&(K.tagNameCheck instanceof RegExp&&N(K.tagNameCheck,t)||K.tagNameCheck instanceof Function&&K.tagNameCheck(t)))return!1;if(Tt&&!Ot[t]){let t=y(e),n=h(e);if(n&&t){let r=n.length;for(let i=r-1;i>=0;--i){let r=Et?n[i]:f(n[i],!0);t.insertBefore(r,m(e))}}}return nn(e),!0},mn=function(e){if(fn(U.beforeSanitizeElements,e,null),ln(e))return nn(e),!0;let n=J(k?k(e):e.nodeName);if(fn(U.uponSanitizeElement,e,{tagName:n,allowedTags:W}),$(e,n))return nn(e),!0;if(at[n]||!(st.tagCheck instanceof Function&&st.tagCheck(n))&&!W[n])return pn(e,n);if((O?O(e):e.nodeType)===Fe.element&&!tn(e)||(n===`noscript`||n===`noembed`||n===`noframes`)&&N(Ne,e.innerHTML))return nn(e),!0;if(ft&&e.nodeType===Fe.text){let n=cn(e.textContent);e.textContent!==n&&(w(t.removed,{element:e.cloneNode()}),e.textContent=n)}return fn(U.afterSanitizeElements,e,null),!1},hn=function(e,t,r){if(ot[t]||St&&(t===`id`||t===`name`)&&(r in n||r in Jt))return!1;let i=G[t]||st.attributeCheck instanceof Function&&st.attributeCheck(t,e);if(!(lt&&N(Ze,t))&&!(ct&&N(Qe,t))){if(!i){if(!(_n(e)&&(K.tagNameCheck instanceof RegExp&&N(K.tagNameCheck,e)||K.tagNameCheck instanceof Function&&K.tagNameCheck(e))&&(K.attributeNameCheck instanceof RegExp&&N(K.attributeNameCheck,t)||K.attributeNameCheck instanceof Function&&K.attributeNameCheck(t,e))||t===`is`&&K.allowCustomizedBuiltInElements&&(K.tagNameCheck instanceof RegExp&&N(K.tagNameCheck,r)||K.tagNameCheck instanceof Function&&K.tagNameCheck(r))))return!1}else if(!Mt[t]&&!N(nt,E(r,et,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&D(r,`data:`)===0&&At[e])&&!(ut&&!N($e,E(r,et,``)))&&r)return!1}return!0},gn=F({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),_n=function(e){return!gn[re(e)]&&N(tt,e)},vn=function(e,t,n,r){if(A&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return Ve(r);case`TrustedScriptURL`:return He(r)}return r},yn=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),ln(e)?nn(e):C(t.removed)}catch{X(n,e)}},bn=function(e){fn(U.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||ln(e))return;let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:G,forceKeepAttr:void 0},r=t.length,i=J(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=J(o),u=c,d=o===`value`?u:oe(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,fn(U.uponSanitizeAttribute,e,n),d=n.attrValue,Ct&&(l===`id`||l===`name`)&&D(d,wt)!==0&&(X(o,e),d=wt+d),pt&&N(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){X(o,e);continue}if(l===`attributename`&&ae(d,`href`)){X(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){X(o,e);continue}if(!dt&&N(Pe,d)){X(o,e);continue}if(ft&&(d=cn(d)),!hn(i,l,d)){X(o,e);continue}d=vn(i,l,s,d),d!==u&&yn(e,o,s,d)}}fn(U.afterSanitizeAttributes,e,null)},xn=function(e){let t=null,n=sn(e);for(fn(U.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(fn(U.uponSanitizeShadowNode,t,null),mn(t),bn(t),un(t.content)&&xn(t.content),(O?O(t):t.nodeType)===Fe.element){let e=b(t);un(e)&&(Sn(e),xn(e))}fn(U.afterSanitizeShadowDOM,e,null)},Sn=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){xn(e.shadow);continue}let n=e.node,r=(O?O(n):n.nodeType)===Fe.element,i=h(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=k?k(n):null;if(typeof e==`string`&&J(e)===`template`){let e=n.content;un(e)&&t.push({node:e,shadow:null})}}if(r){let e=b(n);un(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(Lt=!e,Lt&&(e=`<!-->`),typeof e!=`string`&&!dn(e)&&(e=L(e),typeof e!=`string`))throw ce(`dirty is not a string, aborting`);if(!t.isSupported)return e;ht?(W=gt,G=_t):Yt(n),(U.uponSanitizeElement.length>0||U.uponSanitizeAttribute.length>0)&&(W=I(W)),U.uponSanitizeAttribute.length>0&&(G=I(G)),t.removed=[];let c=Et&&typeof e!=`string`&&dn(e);if(c){let t=k?k(e):e.nodeName;if(typeof t==`string`){let e=J(t);if(!W[e]||at[e])throw ce(`root node is forbidden and cannot be sanitized in-place`)}if(ln(e))throw ce(`root node is clobbered and cannot be sanitized in-place`);try{Sn(e)}catch(t){throw rn(e),t}}else if(dn(e))i=Z(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===Fe.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Sn(a);else{if(!yt&&!ft&&!mt&&e.indexOf(`<`)===-1)return A&&xt?Ve(e):e;if(i=Z(e),!i)return yt?null:xt?j:``}i&&vt&&nn(i.firstChild);let l=sn(c?e:i);try{for(;o=l.nextNode();)mn(o),bn(o),un(o.content)&&xn(o.content)}catch(t){throw c&&rn(e),t}if(c)return S(t.removed,e=>{e.element&&on(e.element)}),ft&&Q(e),e;if(yt){if(ft&&Q(i),bt)for(s=V.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(G.shadowroot||G.shadowrootmode)&&(s=H.call(r,s,!0)),s}let u=mt?i.outerHTML:i.innerHTML;return mt&&W[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&N(ke,i.ownerDocument.doctype.name)&&(u=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
|
|
3
|
+
`+u),ft&&(u=cn(u)),A&&xt?Ve(u):u},t.setConfig=function(){Yt(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}),ht=!0,gt=W,_t=G},t.clearConfig=function(){qt=null,ht=!1,gt=null,_t=null,A=se,j=``},t.isValidAttribute=function(e,t,n){return qt||Yt({}),hn(J(e),J(t),n)},t.addHook=function(e,t){typeof t==`function`&&M(U,e)&&w(U[e],t)},t.removeHook=function(e,t){if(M(U,e)){if(t!==void 0){let n=te(U[e],t);return n===-1?void 0:ne(U[e],n,1)[0]}return C(U[e])}},t.removeHooks=function(e){M(U,e)&&(U[e]=[])},t.removeAllHooks=function(){U=Re()},t}var Ve=Be();function He(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Ue=He();function We(e){Ue=e}var Ge={exec:()=>null};function Ke(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),i=t[r];return i||(i=e(r),t[r]=i),i}}function V(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(H.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var qe=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),H={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:Ke(e=>RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:Ke(e=>RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:Ke(e=>RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:Ke(e=>RegExp(`^ {0,${e}}#`)),htmlBeginRegex:Ke(e=>RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,`i`)),blockquoteBeginRegex:Ke(e=>RegExp(`^ {0,${e}}>`))},U=/^(?:[ \t]*(?:\n|$))+/,Je=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ye=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Xe=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ze=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Qe=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,$e=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,et=V($e).replace(/bull/g,Qe).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),tt=V($e).replace(/bull/g,Qe).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),nt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,W=/^[^\n]+/,rt=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,G=V(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,rt).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),it=V(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,Qe).getRegex(),K=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,at=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,ot=V(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,at).replace(`tag`,K).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),st=V(nt).replace(`hr`,Xe).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,K).getRegex(),ct={blockquote:V(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,st).getRegex(),code:Je,def:G,fences:Ye,heading:Ze,hr:Xe,html:ot,lheading:et,list:it,newline:U,paragraph:st,table:Ge,text:W},lt=V(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,Xe).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,K).getRegex(),ut={...ct,lheading:tt,table:lt,paragraph:V(nt).replace(`hr`,Xe).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,lt).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,K).getRegex()},dt={...ct,html:V(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,at).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Ge,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:V(nt).replace(`hr`,Xe).replace(`heading`,` *#{1,6} *[^
|
|
4
|
+
]`).replace(`lheading`,et).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},ft=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,pt=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,mt=/^( {2,}|\\)\n(?!\s*$)/,ht=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,gt=/[\p{P}\p{S}]/u,_t=/[\s\p{P}\p{S}]/u,vt=/[^\s\p{P}\p{S}]/u,yt=V(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,_t).getRegex(),bt=/(?!~)[\p{P}\p{S}]/u,xt=/(?!~)[\s\p{P}\p{S}]/u,St=/(?:[^\s\p{P}\p{S}]|~)/u,Ct=V(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,qe?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),wt=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Tt=V(wt,`u`).replace(/punct/g,gt).getRegex(),Et=V(wt,`u`).replace(/punct/g,bt).getRegex(),Dt=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,Ot=V(Dt,`gu`).replace(/notPunctSpace/g,vt).replace(/punctSpace/g,_t).replace(/punct/g,gt).getRegex(),kt=V(Dt,`gu`).replace(/notPunctSpace/g,St).replace(/punctSpace/g,xt).replace(/punct/g,bt).getRegex(),At=V(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,vt).replace(/punctSpace/g,_t).replace(/punct/g,gt).getRegex(),jt=V(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,gt).getRegex(),Mt=V(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,vt).replace(/punctSpace/g,_t).replace(/punct/g,gt).getRegex(),Nt=V(/\\(punct)/,`gu`).replace(/punct/g,gt).getRegex(),Pt=V(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Ft=V(at).replace(`(?:-->|$)`,`-->`).getRegex(),q=V(`^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,Ft).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),It=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Lt=V(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace(`label`,It).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Rt=V(/^!?\[(label)\]\[(ref)\]/).replace(`label`,It).replace(`ref`,rt).getRegex(),zt=V(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,rt).getRegex(),Bt=V(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,Rt).replace(`nolink`,zt).getRegex(),Vt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,Ht={_backpedal:Ge,anyPunctuation:Nt,autolink:Pt,blockSkip:Ct,br:mt,code:pt,del:Ge,delLDelim:Ge,delRDelim:Ge,emStrongLDelim:Tt,emStrongRDelimAst:Ot,emStrongRDelimUnd:At,escape:ft,link:Lt,nolink:zt,punctuation:yt,reflink:Rt,reflinkSearch:Bt,tag:q,text:ht,url:Ge},Ut={...Ht,link:V(/^!?\[(label)\]\((.*?)\)/).replace(`label`,It).getRegex(),reflink:V(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,It).getRegex()},Wt={...Ht,emStrongRDelimAst:kt,emStrongLDelim:Et,delLDelim:jt,delRDelim:Mt,url:V(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,Vt).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:V(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace(`protocol`,Vt).getRegex()},Gt={...Wt,br:V(mt).replace(`{2,}`,`*`).getRegex(),text:V(Wt.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},Kt={normal:ct,gfm:ut,pedantic:dt},J={normal:Ht,gfm:Wt,breaks:Gt,pedantic:Ut},qt={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},Jt=e=>qt[e];function Y(e,t){if(t){if(H.escapeTest.test(e))return e.replace(H.escapeReplace,Jt)}else if(H.escapeTestNoEncode.test(e))return e.replace(H.escapeReplaceNoEncode,Jt);return e}function Yt(e){try{e=encodeURI(e).replace(H.percentDecode,`%`)}catch{return null}return e}function Xt(e,t){let n=e.replace(H.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(H.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``);for(;r<n.length;r++)n[r]=n[r].trim().replace(H.slashPipe,`|`);return n}function Zt(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function Qt(e){let t=e.split(`
|
|
5
|
+
`),n=t.length-1;for(;n>=0&&H.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
|
|
6
|
+
`)}function $t(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function en(e,t=0){let n=t,r=``;for(let t of e)if(t===` `){let e=4-n%4;r+=` `.repeat(e),n+=e}else r+=t,n++;return r}function tn(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function nn(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
|
|
7
|
+
`).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join(`
|
|
8
|
+
`)}var rn=class{options;rules;lexer;constructor(e){this.options=e||Ue}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:`space`,raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=this.options.pedantic?t[0]:Qt(t[0]);return{type:`code`,raw:e,codeBlockStyle:`indented`,text:e.replace(this.rules.other.codeRemoveIndent,``)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=nn(e,t[3]||``,this.rules);return{type:`code`,raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,`$1`):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=Zt(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:Zt(t[0],`
|
|
9
|
+
`),depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:`hr`,raw:Zt(t[0],`
|
|
10
|
+
`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=Zt(t[0],`
|
|
11
|
+
`).split(`
|
|
12
|
+
`),n=``,r=``,i=[];for(;e.length>0;){let t=!1,a=[],o;for(o=0;o<e.length;o++)if(this.rules.other.blockquoteStart.test(e[o]))a.push(e[o]),t=!0;else if(!t)a.push(e[o]);else break;e=e.slice(o);let s=a.join(`
|
|
13
|
+
`),c=s.replace(this.rules.other.blockquoteSetextReplace,`
|
|
14
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,``);n=n?`${n}
|
|
15
|
+
${s}`:s,r=r?`${r}
|
|
16
|
+
${c}`:c;let l=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,i,!0),this.lexer.state.top=l,e.length===0)break;let u=i.at(-1);if(u?.type===`code`)break;if(u?.type===`blockquote`){let t=u,a=t.raw+`
|
|
17
|
+
`+e.join(`
|
|
18
|
+
`),o=this.blockquote(a);i[i.length-1]=o,n=n.substring(0,n.length-t.raw.length)+o.raw,r=r.substring(0,r.length-t.text.length)+o.text;break}else if(u?.type===`list`){let t=u,a=t.raw+`
|
|
19
|
+
`+e.join(`
|
|
20
|
+
`),o=this.list(a);i[i.length-1]=o,n=n.substring(0,n.length-u.raw.length)+o.raw,r=r.substring(0,r.length-t.raw.length)+o.raw,e=a.substring(i.at(-1).raw.length).split(`
|
|
21
|
+
`);continue}}return{type:`blockquote`,raw:n,tokens:i,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,i={type:`list`,raw:``,ordered:r,start:r?+n.slice(0,-1):``,loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:`[*+-]`);let a=this.rules.other.listItemRegex(n),o=!1;for(;e;){let n=!1,r=``,s=``;if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let c=en(t[2].split(`
|
|
22
|
+
`,1)[0],t[1].length),l=e.split(`
|
|
23
|
+
`,1)[0],u=!c.trim(),d=0;if(this.options.pedantic?(d=2,s=c.trimStart()):u?d=t[1].length+1:(d=c.search(this.rules.other.nonSpaceChar),d=d>4?1:d,s=c.slice(d),d+=t[1].length),u&&this.rules.other.blankLine.test(l)&&(r+=l+`
|
|
24
|
+
`,e=e.substring(l.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(d),n=this.rules.other.hrRegex(d),i=this.rules.other.fencesBeginRegex(d),a=this.rules.other.headingBeginRegex(d),o=this.rules.other.htmlBeginRegex(d),ee=this.rules.other.blockquoteBeginRegex(d);for(;e;){let f=e.split(`
|
|
25
|
+
`,1)[0],p;if(l=f,this.options.pedantic?(l=l.replace(this.rules.other.listReplaceNesting,` `),p=l):p=l.replace(this.rules.other.tabCharGlobal,` `),i.test(l)||a.test(l)||o.test(l)||ee.test(l)||t.test(l)||n.test(l))break;if(p.search(this.rules.other.nonSpaceChar)>=d||!l.trim())s+=`
|
|
26
|
+
`+p.slice(d);else{if(u||c.replace(this.rules.other.tabCharGlobal,` `).search(this.rules.other.nonSpaceChar)>=4||i.test(c)||a.test(c)||n.test(c))break;s+=`
|
|
27
|
+
`+l}u=!l.trim(),r+=f+`
|
|
28
|
+
`,e=e.substring(f.length+1),c=p.slice(d)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(o=!0)),i.items.push({type:`list_item`,raw:r,task:!!this.options.gfm&&this.rules.other.listIsTask.test(s),loose:!1,text:s,tokens:[]}),i.raw+=r}let s=i.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let e of i.items){this.lexer.state.top=!1,e.tokens=this.lexer.blockTokens(e.text,[]);let t=e.tokens[0];if(e.task&&(t?.type===`text`||t?.type===`paragraph`)){e.text=e.text.replace(this.rules.other.listReplaceTask,``),t.raw=t.raw.replace(this.rules.other.listReplaceTask,``),t.text=t.text.replace(this.rules.other.listReplaceTask,``);for(let e=this.lexer.inlineQueue.length-1;e>=0;e--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[e].src)){this.lexer.inlineQueue[e].src=this.lexer.inlineQueue[e].src.replace(this.rules.other.listReplaceTask,``);break}let n=this.rules.other.listTaskCheckbox.exec(e.raw);if(n){let t={type:`checkbox`,raw:n[0]+` `,checked:n[0]!==`[ ]`};e.checked=t.checked,i.loose?e.tokens[0]&&[`paragraph`,`text`].includes(e.tokens[0].type)&&`tokens`in e.tokens[0]&&e.tokens[0].tokens?(e.tokens[0].raw=t.raw+e.tokens[0].raw,e.tokens[0].text=t.raw+e.tokens[0].text,e.tokens[0].tokens.unshift(t)):e.tokens.unshift({type:`paragraph`,raw:t.raw,text:t.raw,tokens:[t]}):e.tokens.unshift(t)}}else e.task&&=!1;if(!i.loose){let t=e.tokens.filter(e=>e.type===`space`);i.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}}if(i.loose)for(let e of i.items){e.loose=!0;for(let t of e.tokens)t.type===`text`&&(t.type=`paragraph`)}return i}}html(e){let t=this.rules.block.html.exec(e);if(t){let e=Qt(t[0]);return{type:`html`,block:!0,raw:e,pre:t[1]===`pre`||t[1]===`script`||t[1]===`style`,text:e}}}def(e){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal,` `),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,`$1`).replace(this.rules.inline.anyPunctuation,`$1`):``,r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,`$1`):t[3];return{type:`def`,tag:e,raw:Zt(t[0],`
|
|
29
|
+
`),href:n,title:r}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Xt(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,``).split(`|`),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,``).split(`
|
|
30
|
+
`):[],a={type:`table`,raw:Zt(t[0],`
|
|
31
|
+
`),header:[],align:[],rows:[]};if(n.length===r.length){for(let e of r)this.rules.other.tableAlignRight.test(e)?a.align.push(`right`):this.rules.other.tableAlignCenter.test(e)?a.align.push(`center`):this.rules.other.tableAlignLeft.test(e)?a.align.push(`left`):a.align.push(null);for(let e=0;e<n.length;e++)a.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:a.align[e]});for(let e of i)a.rows.push(Xt(e,a.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let e=t[1].trim();return{type:`heading`,raw:Zt(t[0],`
|
|
32
|
+
`),depth:t[2].charAt(0)===`=`?1:2,text:e,tokens:this.lexer.inline(e)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e=t[1].charAt(t[1].length-1)===`
|
|
33
|
+
`?t[1].slice(0,-1):t[1];return{type:`paragraph`,raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:`text`,raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:`escape`,raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:`html`,raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=Zt(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=$t(t[2],`()`);if(e===-2)return;if(e>-1){let n=(t[0].indexOf(`!`)===0?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=``}}let n=t[2],r=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):``;return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),tn(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,`$1`),title:r&&r.replace(this.rules.inline.anyPunctuation,`$1`)},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal,` `).toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return tn(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=``){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=0,c=r[0][0]===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+n);(r=c.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}else if((r[5]||r[6])&&n%3&&!((n+a)%3)){s+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+s);let t=[...r[0]][0].length,c=e.slice(0,n+r.index+t+a);if(Math.min(n,a)%2){let e=c.slice(1,-1);return{type:`em`,raw:c,text:e,tokens:this.lexer.inlineTokens(e)}}let l=c.slice(2,-2);return{type:`strong`,raw:c,text:l,tokens:this.lexer.inlineTokens(l)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal,` `),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:`codespan`,raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:`br`,raw:t[0]}}del(e,t,n=``){let r=this.rules.inline.delLDelim.exec(e);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=this.rules.inline.delRDelim;for(s.lastIndex=0,t=t.slice(-1*e.length+n);(r=s.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(a=[...i].length,a!==n))continue;if(r[3]||r[4]){o+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o);let t=[...r[0]][0].length,s=e.slice(0,n+r.index+t+a),c=s.slice(n,-n);return{type:`del`,raw:s,text:c,tokens:this.lexer.inlineTokens(c)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return t[2]===`@`?(e=t[1],n=`mailto:`+e):(e=t[1],n=e),{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if(t[2]===`@`)e=t[0],n=`mailto:`+e;else{let r;do r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??``;while(r!==t[0]);e=t[0],n=t[1]===`www.`?`http://`+t[0]:t[0]}return{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:`text`,raw:t[0],text:t[0],escaped:e}}}},X=class e{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Ue,this.options.tokenizer=this.options.tokenizer||new rn,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:H,block:Kt.normal,inline:J.normal};this.options.pedantic?(t.block=Kt.pedantic,t.inline=J.pedantic):this.options.gfm&&(t.block=Kt.gfm,this.options.breaks?t.inline=J.breaks:t.inline=J.gfm),this.tokenizer.rules=t}static get rules(){return{block:Kt,inline:J}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(H.carriageReturn,`
|
|
34
|
+
`),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(H.tabCharGlobal,` `).replace(H.spaceLine,``));let r=1/0;for(;e;){if(e.length<r)r=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(n=>(i=n.call({lexer:this},e,t))?(e=e.substring(i.raw.length),t.push(i),!0):!1))continue;if(i=this.tokenizer.space(e)){e=e.substring(i.raw.length);let n=t.at(-1);i.raw.length===1&&n!==void 0?n.raw+=`
|
|
35
|
+
`:t.push(i);continue}if(i=this.tokenizer.code(e)){e=e.substring(i.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(`
|
|
36
|
+
`)?``:`
|
|
37
|
+
`)+i.raw,n.text+=`
|
|
38
|
+
`+i.text,this.inlineQueue.at(-1).src=n.text):t.push(i);continue}if(i=this.tokenizer.fences(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.heading(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.hr(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.blockquote(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.list(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.html(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.def(e)){e=e.substring(i.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(`
|
|
39
|
+
`)?``:`
|
|
40
|
+
`)+i.raw,n.text+=`
|
|
41
|
+
`+i.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},t.push(i));continue}if(i=this.tokenizer.table(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.lheading(e)){e=e.substring(i.raw.length),t.push(i);continue}let a=e;if(this.options.extensions?.startBlock){let t=1/0,n=e.slice(1),r;this.options.extensions.startBlock.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(a=e.substring(0,t+1))}if(this.state.top&&(i=this.tokenizer.paragraph(a))){let r=t.at(-1);n&&r?.type===`paragraph`?(r.raw+=(r.raw.endsWith(`
|
|
42
|
+
`)?``:`
|
|
43
|
+
`)+i.raw,r.text+=`
|
|
44
|
+
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=r.text):t.push(i),n=a.length!==e.length,e=e.substring(i.raw.length);continue}if(i=this.tokenizer.text(e)){e=e.substring(i.raw.length);let n=t.at(-1);n?.type===`text`?(n.raw+=(n.raw.endsWith(`
|
|
45
|
+
`)?``:`
|
|
46
|
+
`)+i.raw,n.text+=`
|
|
47
|
+
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let n=e,r=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(n))!==null;)e.includes(r[0].slice(r[0].lastIndexOf(`[`)+1,-1))&&(n=n.slice(0,r.index)+`[`+`a`.repeat(r[0].length-2)+`]`+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(n))!==null;)n=n.slice(0,r.index)+`++`+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(r=this.tokenizer.rules.inline.blockSkip.exec(n))!==null;)i=r[2]?r[2].length:0,n=n.slice(0,r.index+i)+`[`+`a`.repeat(r[0].length-i-2)+`]`+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n;let a=!1,o=``,s=1/0;for(;e;){if(e.length<s)s=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}a||(o=``),a=!1;let r;if(this.options.extensions?.inline?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if(r=this.tokenizer.escape(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.tag(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.link(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);let n=t.at(-1);r.type===`text`&&n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if(r=this.tokenizer.emStrong(e,n,o)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.codespan(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.br(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.del(e,n,o)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.autolink(e)){e=e.substring(r.raw.length),t.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startInline){let t=1/0,n=e.slice(1),r;this.options.extensions.startInline.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(r=this.tokenizer.inlineText(i)){e=e.substring(r.raw.length),r.raw.slice(-1)!==`_`&&(o=r.raw.slice(-1)),a=!0;let n=t.at(-1);n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return t}infiniteLoopError(e){let t=`Infinite loop on byte: `+e;if(this.options.silent)console.error(t);else throw Error(t)}},an=class{options;parser;constructor(e){this.options=e||Ue}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(H.notSpaceStart)?.[0],i=e.replace(H.endingNewline,``)+`
|
|
48
|
+
`;return r?`<pre><code class="language-`+Y(r)+`">`+(n?i:Y(i,!0))+`</code></pre>
|
|
49
|
+
`:`<pre><code>`+(n?i:Y(i,!0))+`</code></pre>
|
|
50
|
+
`}blockquote({tokens:e}){return`<blockquote>
|
|
51
|
+
${this.parser.parse(e)}</blockquote>
|
|
52
|
+
`}html({text:e}){return e}def(e){return``}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
53
|
+
`}hr(e){return`<hr>
|
|
54
|
+
`}list(e){let t=e.ordered,n=e.start,r=``;for(let t=0;t<e.items.length;t++){let n=e.items[t];r+=this.listitem(n)}let i=t?`ol`:`ul`,a=t&&n!==1?` start="`+n+`"`:``;return`<`+i+a+`>
|
|
55
|
+
`+r+`</`+i+`>
|
|
56
|
+
`}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
|
|
57
|
+
`}checkbox({checked:e}){return`<input `+(e?`checked="" `:``)+`disabled="" type="checkbox"> `}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
|
|
58
|
+
`}table(e){let t=``,n=``;for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let r=``;for(let t=0;t<e.rows.length;t++){let i=e.rows[t];n=``;for(let e=0;e<i.length;e++)n+=this.tablecell(i[e]);r+=this.tablerow({text:n})}return r&&=`<tbody>${r}</tbody>`,`<table>
|
|
59
|
+
<thead>
|
|
60
|
+
`+t+`</thead>
|
|
61
|
+
`+r+`</table>
|
|
62
|
+
`}tablerow({text:e}){return`<tr>
|
|
63
|
+
${e}</tr>
|
|
64
|
+
`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
|
|
65
|
+
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${Y(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=Yt(e);if(i===null)return r;e=i;let a=`<a href="`+e+`"`;return t&&(a+=` title="`+Y(t)+`"`),a+=`>`+r+`</a>`,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Yt(e);if(i===null)return Y(n);e=i;let a=`<img src="${e}" alt="${Y(n)}"`;return t&&(a+=` title="${Y(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:Y(e.text)}},on=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}checkbox({raw:e}){return e}},Z=class e{options;renderer;textRenderer;constructor(e){this.options=e||Ue,this.options.renderer=this.options.renderer||new an,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new on}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){this.renderer.parser=this;let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(this.options.extensions?.renderers?.[r.type]){let e=r,n=this.options.extensions.renderers[e.type].call({parser:this},e);if(n!==!1||![`space`,`hr`,`heading`,`code`,`table`,`blockquote`,`list`,`html`,`def`,`paragraph`,`text`].includes(e.type)){t+=n||``;continue}}let i=r;switch(i.type){case`space`:t+=this.renderer.space(i);break;case`hr`:t+=this.renderer.hr(i);break;case`heading`:t+=this.renderer.heading(i);break;case`code`:t+=this.renderer.code(i);break;case`table`:t+=this.renderer.table(i);break;case`blockquote`:t+=this.renderer.blockquote(i);break;case`list`:t+=this.renderer.list(i);break;case`checkbox`:t+=this.renderer.checkbox(i);break;case`html`:t+=this.renderer.html(i);break;case`def`:t+=this.renderer.def(i);break;case`paragraph`:t+=this.renderer.paragraph(i);break;case`text`:t+=this.renderer.text(i);break;default:{let e=`Token with "`+i.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(e!==!1||![`escape`,`html`,`link`,`image`,`strong`,`em`,`codespan`,`br`,`del`,`text`].includes(i.type)){n+=e||``;continue}}let a=i;switch(a.type){case`escape`:n+=t.text(a);break;case`html`:n+=t.html(a);break;case`link`:n+=t.link(a);break;case`image`:n+=t.image(a);break;case`checkbox`:n+=t.checkbox(a);break;case`strong`:n+=t.strong(a);break;case`em`:n+=t.em(a);break;case`codespan`:n+=t.codespan(a);break;case`br`:n+=t.br(a);break;case`del`:n+=t.del(a);break;case`text`:n+=t.text(a);break;default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},sn=class{options;block;constructor(e){this.options=e||Ue}static passThroughHooks=new Set([`preprocess`,`postprocess`,`processAllTokens`,`emStrongMask`]);static passThroughHooksRespectAsync=new Set([`preprocess`,`postprocess`,`processAllTokens`]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?X.lex:X.lexInline}provideParser(e=this.block){return e?Z.parse:Z.parseInline}},cn=new class{defaults=He();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Z;Renderer=an;TextRenderer=on;Lexer=X;Tokenizer=rn;Hooks=sn;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case`list`:{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new an(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new rn(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new sn;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];sn.passThroughHooks.has(n)?t[r]=e=>{if(this.defaults.async&&sn.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:t[r]=(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return X.lex(e,t??this.defaults)}parser(e,t){return Z.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer(e):e?X.lex:X.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser(e):e?Z.parse:Z.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer(e):e?X.lex:X.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser(e):e?Z.parse:Z.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
|
|
66
|
+
Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+Y(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function Q(e,t){return cn.parse(e,t)}Q.options=Q.setOptions=function(e){return cn.setOptions(e),Q.defaults=cn.defaults,We(Q.defaults),Q},Q.getDefaults=He,Q.defaults=Ue,Q.use=function(...e){return cn.use(...e),Q.defaults=cn.defaults,We(Q.defaults),Q},Q.walkTokens=function(e,t){return cn.walkTokens(e,t)},Q.parseInline=cn.parseInline,Q.Parser=Z,Q.parser=Z.parse,Q.Renderer=an,Q.TextRenderer=on,Q.Lexer=X,Q.lexer=X.lex,Q.Tokenizer=rn,Q.Hooks=sn,Q.parse=Q,Q.options,Q.setOptions,Q.use,Q.walkTokens,Q.parseInline,Z.parse,X.lex;var ln=!1;function un(){ln||=(Q.setOptions({breaks:!0,gfm:!0}),Ve.addHook(`afterSanitizeAttributes`,e=>{e.nodeName===`A`&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))}),!0)}function dn(e,t){if(!e)return``;if(!t||typeof window>`u`)return fn(e);try{un();let t=Q.parse(e,{async:!1});return Ve.sanitize(t)}catch{return fn(e)}}function fn(e){return String(e).replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}var $=t();function pn({agentId:e,turnBusy:t,onCreated:n,renderHistory:i,initialConversationId:o}){let[s,c]=(0,a.useState)(null),[l,u]=(0,a.useState)(0),[d,ee]=(0,a.useState)(0),[f,p]=(0,a.useState)(null),[m,h]=(0,a.useState)(null),[g,_]=(0,a.useState)(``),[v,y]=(0,a.useState)(``),[b,x]=(0,a.useState)(``),[S,te]=(0,a.useState)(!1),C=`bazilion:conversation-create:${e}`,w=(0,a.useRef)(null);(0,a.useEffect)(()=>{try{w.current=JSON.parse(sessionStorage.getItem(C)??`null`)}catch{w.current=null}},[C]);function ne(){w.current=null,sessionStorage.removeItem(C)}let T=`/api/agents/${encodeURIComponent(e)}/conversations`;(0,a.useEffect)(()=>{if(!o)return;let e=new AbortController;return fetch(`${T}/${encodeURIComponent(o)}`,{signal:e.signal}).then(async t=>{if(!t.ok)throw Error(`Retained conversation is unavailable`);let n=await t.json();e.signal.aborted||(p(n.conversation),_(n.conversation.title))}).catch(t=>{e.signal.aborted||y(t.message)}),()=>e.abort()},[T,o]),(0,a.useEffect)(()=>{let e=new AbortController;return c(null),fetch(`${T}?limit=20&offset=${l}`,{signal:e.signal}).then(async t=>{if(!t.ok)throw Error(`Could not load conversations.`);let n=await t.json();e.signal.aborted||c(n)}).catch(t=>{e.signal.aborted||y(t.message)}),()=>e.abort()},[T,l,d]),(0,a.useEffect)(()=>{if(!f)return;let e=new AbortController;return h(null),x(``),fetch(`${T}/${encodeURIComponent(f.id)}`,{signal:e.signal}).then(async t=>{if(!t.ok)throw Error(`This conversation history is unavailable. You can still start a new conversation.`);let n=await t.json();e.signal.aborted||h(n.messages)}).catch(t=>{e.signal.aborted||x(t.message)}),()=>e.abort()},[T,f?.id]);async function re(){if(!s||S||t)return;te(!0),y(``);let e=w.current??{requestId:crypto.randomUUID(),expectedSelection:s.selection};w.current=e;try{sessionStorage.setItem(C,JSON.stringify(e));let t=await fetch(T,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),r=await t.json();if(!t.ok)throw(t.status===409||t.status===400)&&ne(),Error(r.error??`Could not create conversation.`);ne(),p(null),u(0),ee(e=>e+1),await n()}catch(e){y(e instanceof Error?e.message:`Could not create conversation.`)}finally{te(!1)}}async function ie(){if(!(!f||S)){te(!0),y(``);try{let e=await fetch(`${T}/${encodeURIComponent(f.id)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({title:g,expectedTitleRevision:f.titleRevision})}),t=await e.json();if(!e.ok)throw Error(t.error??`Could not rename conversation.`);p(t.conversation),ee(e=>e+1)}catch(e){y(e instanceof Error?e.message:`Could not rename conversation.`)}finally{te(!1)}}}return(0,$.jsxs)(`section`,{"aria-live":`off`,className:`my-3 min-w-0 space-y-4 rounded-lg border border-fawn bg-ivory p-4`,"aria-label":`Conversation library`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsx)(`h2`,{className:`m-0 text-lg`,children:`Conversations`}),(0,$.jsx)(r,{variant:`primary`,disabled:!s||S||t,onClick:()=>void re(),children:`New conversation`})]}),(0,$.jsx)(`p`,{className:`m-0 text-sm`,children:`Starting a new conversation keeps previous history and saved files. Viewing history does not change the active conversation.`}),t&&(0,$.jsx)(`p`,{role:`status`,children:`Wait for the current turn to finish before starting a new conversation.`}),v&&(0,$.jsxs)(`p`,{role:`alert`,children:[v,` `,(0,$.jsx)(r,{variant:`ghost`,disabled:S,onClick:()=>{y(``),ee(e=>e+1)},children:`Refresh library`})]}),s?(0,$.jsxs)($.Fragment,{children:[!s.total&&(0,$.jsx)(`p`,{children:`No conversations yet.`}),(0,$.jsx)(`ul`,{className:`mt-4 grid list-none gap-2 p-0`,children:s.conversations.map(e=>(0,$.jsxs)(`li`,{className:`flex min-w-0 flex-col items-start gap-3 rounded border border-fawn p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 break-words [overflow-wrap:anywhere]`,children:e.title}),e.id===s.selection.conversationId&&(0,$.jsx)(`strong`,{className:`shrink-0 rounded-full bg-frost px-2 py-0.5 text-xs`,children:`Active`})]}),(0,$.jsxs)(r,{variant:`ghost`,className:`max-w-full whitespace-normal break-words text-left sm:max-w-[50%]`,disabled:S,"aria-pressed":f?.id===e.id,onClick:()=>{p(e),_(e.title)},children:[`View `,e.title]})]},e.id))}),(0,$.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(r,{variant:`ghost`,disabled:S||l===0,onClick:()=>u(Math.max(0,l-20)),children:`Previous`}),(0,$.jsx)(r,{variant:`ghost`,disabled:S||l+s.conversations.length>=s.total,onClick:()=>u(l+20),children:`Next`}),(0,$.jsxs)(`span`,{className:`text-sm`,children:[s.total,` conversations`]})]})]}):(0,$.jsx)(`p`,{role:`status`,children:`Loading conversations…`}),f&&(0,$.jsxs)(`section`,{className:`space-y-4 border-t border-fawn pt-4`,"aria-label":`Retained conversation`,children:[(0,$.jsxs)(`div`,{className:`grid min-w-0 grid-cols-2 items-end gap-2 sm:grid-cols-[minmax(0,1fr)_auto_auto]`,children:[(0,$.jsxs)(`label`,{className:`col-span-2 m-0 grid min-w-0 gap-2 sm:col-span-1`,children:[`Conversation title`,(0,$.jsx)(`input`,{className:`h-11`,value:g,maxLength:200,onChange:e=>_(e.target.value)})]}),(0,$.jsx)(r,{variant:`ghost`,className:`h-11`,disabled:S||!g.trim(),onClick:()=>void ie(),children:`Rename`}),(0,$.jsx)(r,{variant:`ghost`,className:`h-11`,disabled:S,onClick:()=>p(null),children:`Close history`})]}),(0,$.jsx)(`p`,{className:`m-0 text-sm`,children:`Viewing retained history. New messages still go to the active conversation.`}),b?(0,$.jsx)(`p`,{role:`alert`,children:b}):m===null?(0,$.jsx)(`p`,{role:`status`,children:`Loading history…`}):m.length?i(m):(0,$.jsx)(`p`,{children:`This conversation is empty.`})]})]})}async function mn(e,t,n){return new Promise((r,i)=>{let a=indexedDB.open(`bazilion-queue-attempts`,1);a.onupgradeneeded=()=>{a.result.createObjectStore(`requests`,{keyPath:`input.requestId`}).createIndex(`agentId`,`agentId`)},a.onerror=()=>i(Error(`Local queue recovery storage is unavailable`)),a.onblocked=()=>i(Error(`Close other Bazilion tabs to open queue recovery storage`)),a.onsuccess=()=>{let o=a.result,s=o.transaction(`requests`,t===void 0?`readonly`:`readwrite`),c=s.objectStore(`requests`);if(t===null&&!n){o.close(),i(Error(`Queue request identity is required to clear recovery state`));return}let l=t===void 0?c.index(`agentId`).get(e):t===null?c.delete(n):c.put(t);s.oncomplete=()=>{o.close(),r(t===void 0?l.result??null:t)},s.onerror=s.onabort=()=>{o.close(),i(Error(`Unable to retain queue request locally; it was not acknowledged`))}}})}var hn=(0,a.forwardRef)(function({agentId:e,selection:t,onQueueMode:n,onViewConversation:i},o){let s=`/api/agents/${encodeURIComponent(e)}/queue`,[c,l]=(0,a.useState)(null),[u,d]=(0,a.useState)(``),[ee,f]=(0,a.useState)(``),[p,m]=(0,a.useState)(!1),[h,g]=(0,a.useState)(!1),_=(0,a.useRef)(!1),[v,y]=(0,a.useState)(null),b=(0,a.useRef)(null),x=(0,a.useRef)(!1),S=(0,a.useRef)(!0),te=(0,a.useRef)(0);(0,a.useEffect)(()=>(S.current=!0,()=>{S.current=!1}),[]);let[C,w]=(0,a.useState)(null),[ne,T]=(0,a.useState)(``),[re,ie]=(0,a.useState)([]),[ae,E]=(0,a.useState)(!1),[D,oe]=(0,a.useState)(0),O=(0,a.useRef)(n);O.current=n;async function k(){let e=++te.current,t=await fetch(`${s}?all=${+!!ae}&offset=${D}`);if(!t.ok)throw Error(`Queue could not be loaded`);let n=await t.json(),r=ae?await fetch(s):null,i=r?.ok?await r.json():n;return S.current&&e===te.current&&(l(n),_.current&&O.current(i.total>0||i.control.paused||!!b.current)),n}(0,a.useEffect)(()=>{let t=!0;return mn(e).then(e=>{t&&(b.current=e,y(e),_.current=!0,g(!0),k().catch(e=>d(e.message)))}).catch(e=>{t&&d(e.message)}),()=>{t=!1}},[e]),(0,a.useEffect)(()=>{k().catch(e=>d(e.message));let e=setInterval(()=>{k().catch(e=>d(e.message))},2e3);return()=>clearInterval(e)},[e,ae,D]);async function A(t){await mn(e,null,t.input.requestId);let n=await mn(e);b.current=n,y(n)}async function j(t,n=!1){if(x.current||!h)return!1;if(b.current&&!n)return d(`Resolve the unacknowledged queue request before sending another.`),!1;x.current=!0,m(!0),d(``),f(``);try{await mn(e,t),b.current=t,y(t);let n=await fetch(t.replacementId?`${s}/${encodeURIComponent(t.replacementId)}`:s,{method:t.replacementId?`PATCH`:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t.input)});if(!n.ok){let e=await n.json().catch(()=>({}));throw n.status>=400&&n.status<500&&await A(t),Error(e.error??`Queue acknowledgement unavailable; retry this same request.`)}let r=await n.json();return await A(t),f(`Follow-up ${r.status}.`),w(null),await k().catch(()=>d(`Input acknowledged; queue display could not refresh.`)),!0}catch(e){return d(e instanceof Error?e.message:`Queue request failed`),!1}finally{x.current=!1,m(!1)}}async function M(e,t,n=`POST`){if(x.current)return!1;x.current=!0,m(!0),d(``);try{let r=await fetch(`${s}${e}`,{method:n,headers:{"content-type":`application/json`},body:JSON.stringify(t)});if(!r.ok){let e=await r.json();throw Error(e.error??`Queue changed; refresh and try again`)}return await k(),!0}catch(e){return d(e instanceof Error?e.message:`Queue action failed`),await k().catch(()=>{}),!1}finally{x.current=!1,m(!1)}}(0,a.useImperativeHandle)(o,()=>({async enqueue(t,n,r){return r?j({agentId:e,input:{requestId:crypto.randomUUID(),message:t,attachments:n,expectedSelection:r}}):(d(`Refresh conversation history before queuing input.`),!1)},async stop(){return c?M(`/stop`,{expectedRevision:c.control.revision}):(d(`Load queue controls before stopping.`),!1)}}));async function se(e){try{let t=await fetch(`${s}/${encodeURIComponent(e.id)}/input`);if(!t.ok)throw Error(`Retained input is unavailable`);let n=await t.json();w(e),T(n.message),ie(n.attachments)}catch(e){d(e instanceof Error?e.message:`Could not edit`)}}return(0,$.jsxs)(`section`,{"aria-label":`Follow-up queue`,className:`max-h-[45%] min-w-0 shrink-0 space-y-3 overflow-y-auto border-t border-frost px-5 py-4 text-sm`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`strong`,{className:`shrink-0`,children:[`Follow-ups `,c?.control.paused?`· Paused`:``]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c&&(0,$.jsx)(r,{variant:`ghost`,disabled:p,onClick:()=>void M(`/control`,{paused:!c.control.paused,expectedRevision:c.control.revision}),children:c.control.paused?`Resume queue`:`Pause queue`}),c&&(0,$.jsx)(r,{variant:`danger`,disabled:p,onClick:()=>void M(`/stop`,{expectedRevision:c.control.revision}),children:`Stop and pause`}),(0,$.jsx)(r,{variant:`ghost`,onClick:()=>{E(!ae),oe(0)},children:ae?`Pending`:`History`})]})]}),u&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 break-words text-danger`,children:u}),ee&&(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-mocha`,children:ee}),v&&(0,$.jsxs)(`div`,{role:`status`,className:`flex min-w-0 flex-col gap-3 rounded-lg border border-frost bg-ivory p-3`,children:[(0,$.jsx)(`p`,{children:`A queue request has no confirmed acknowledgement. Retrying uses the same request and files.`}),(0,$.jsx)(`p`,{className:`truncate`,children:v.input.message}),(0,$.jsx)(r,{variant:`primary`,disabled:p,onClick:()=>void j(v,!0),children:`Retry saved request`})]}),(0,$.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[c?.items.map(e=>(0,$.jsxs)(`article`,{className:`flex min-w-0 flex-col gap-3 rounded-lg border border-frost bg-ivory p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`strong`,{className:`rounded-full bg-frost px-2 py-1 text-xs capitalize`,children:e.status}),(0,$.jsx)(`span`,{className:`text-xs text-mocha`,children:e.source===`telegram`?`Telegram`:`Web / API`})]}),(0,$.jsx)(r,{variant:`ghost`,onClick:()=>i(e.conversationId),children:`View conversation`})]}),(0,$.jsx)(`p`,{className:`m-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:e.text??`Input retention expired`}),e.attachments.map(e=>(0,$.jsxs)(`p`,{className:`m-0 break-all text-xs text-mocha`,children:[e.name??`Attachment`,` · `,e.byteLength,` bytes`]},e.id)),e.diagnostic&&(0,$.jsx)(`p`,{className:`m-0 break-words`,children:e.diagnostic}),e.approvalId&&(0,$.jsx)(`a`,{href:`/approvals`,children:`Review communication approval`}),e.status===`pending`&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(r,{variant:`ghost`,disabled:p||!!v,onClick:()=>void se(e),children:`Edit`}),(0,$.jsx)(r,{variant:`danger`,disabled:p,onClick:()=>void M(`/${e.id}`,{expectedRevision:e.revision},`DELETE`),children:`Remove`})]}),e.status===`uncertain`&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{children:`This input may already have acted. Review its conversation before closing it. Closing never retries it.`}),(0,$.jsx)(r,{variant:`danger`,disabled:p,onClick:()=>void M(`/${e.id}/reconcile`,{expectedRevision:e.revision,acknowledged:!0}),children:`Acknowledge and close`})]})]},e.id)),C&&(0,$.jsxs)(`form`,{className:`flex min-w-0 flex-col gap-3 rounded-lg border border-frost bg-ivory p-3`,onSubmit:n=>{n.preventDefault();let r=t();r&&j({agentId:e,replacementId:C.id,input:{requestId:crypto.randomUUID(),expectedRevision:C.revision,expectedSelection:r,message:ne,attachments:re}})},children:[(0,$.jsxs)(`label`,{className:`m-0 grid gap-2`,children:[`Edit queued input`,(0,$.jsx)(`textarea`,{"aria-label":`Edit queued input`,rows:3,className:`w-full resize-y`,value:ne,onChange:e=>T(e.target.value)})]}),re.map((e,t)=>(0,$.jsxs)(`div`,{children:[e.name??`Attachment`,` `,(0,$.jsx)(r,{variant:`ghost`,onClick:()=>ie(e=>e.filter((e,n)=>n!==t)),children:`Remove attachment`})]},t)),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(r,{variant:`primary`,type:`submit`,disabled:p||!!v,children:`Save replacement`}),(0,$.jsx)(r,{variant:`ghost`,onClick:()=>w(null),children:`Cancel edit`})]})]})]}),c&&(D>0||D+c.items.length<c.total)&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(r,{variant:`ghost`,disabled:D===0,onClick:()=>oe(Math.max(0,D-20)),children:`Previous`}),(0,$.jsx)(r,{variant:`ghost`,disabled:D+c.items.length>=c.total,onClick:()=>oe(D+20),children:`Next`})]})]})});function gn({agentId:e}){let[t,n]=(0,a.useState)([]),[r,i]=(0,a.useState)(``);return(0,a.useEffect)(()=>{let t=!0,r=!1,a=async()=>{if(!r){r=!0;try{let r=await fetch(`/api/agents/${encodeURIComponent(e)}/questions`,{cache:`no-store`});if(!r.ok)throw Error(`Questions could not be refreshed`);let a=await r.json();t&&(n(a.questions),i(``))}catch(e){t&&(n([]),i(e instanceof Error?e.message:`Questions unavailable`))}finally{r=!1}}};a();let o=setInterval(()=>{a()},2e3);return()=>{t=!1,clearInterval(o)}},[e]),!t.length&&!r?null:(0,$.jsxs)(`section`,{"aria-label":`Agent questions`,className:`max-h-[40vh] min-w-0 shrink-0 space-y-3 overflow-y-auto border-t border-frost px-5 py-3`,children:[r&&(0,$.jsx)(`p`,{role:`status`,children:r}),t.filter(e=>e.status===`pending`||e.continuation===`unconfirmed`).map(e=>(0,$.jsx)(_n,{item:e},e.id)),t.some(e=>e.status!==`pending`&&e.continuation!==`unconfirmed`)&&(0,$.jsxs)(`details`,{children:[(0,$.jsx)(`summary`,{children:`Recent question outcomes`}),t.filter(e=>e.status!==`pending`&&e.continuation!==`unconfirmed`).map(e=>(0,$.jsx)(_n,{item:e},e.id))]})]})}function _n({item:e}){let t=`bazilion-question-answer:${e.agentId}:${e.id}`,[n,i]=(0,a.useState)(``),[o,s]=(0,a.useState)(``),[c,l]=(0,a.useState)(null),u=(0,a.useRef)(null),[d,ee]=(0,a.useState)(!1),[f,p]=(0,a.useState)(!1),m=(0,a.useRef)(!1),[h,g]=(0,a.useState)(``),[_,v]=(0,a.useState)(``);(0,a.useEffect)(()=>{try{let e=sessionStorage.getItem(t);if(e){let t=JSON.parse(e);u.current=t,l(t)}ee(!0)}catch{g(`Answer recovery storage is unavailable. Enable session storage before answering.`)}},[t]),(0,a.useEffect)(()=>{if(e.status!==`pending`)try{sessionStorage.removeItem(t),u.current=null,l(null)}catch{}},[e.status,t]);async function y(n){if(!(m.current||!d||e.status!==`pending`)){m.current=!0,p(!0),g(``);try{if(!u.current&&!n)throw Error(`Choose an answer first`);let r=u.current??{requestId:crypto.randomUUID(),conversationId:e.conversationId,answer:n};sessionStorage.setItem(t,JSON.stringify(r)),u.current=r,l(r);let i=await fetch(`/api/agents/${encodeURIComponent(e.agentId)}/questions/${encodeURIComponent(e.id)}/answer`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(r)}).catch(()=>{throw Error(`Answer acknowledgement unavailable. Retry the same answer.`)});if(!i.ok)throw i.status===409||i.status===404?Error(`This question is no longer answerable. Its outcome will refresh shortly.`):Error(`Answer acknowledgement unavailable. Retry the same answer.`);(await i.json()).kind===`held`?v(`Answer awaits communication approval. The Agent has not received it.`):(sessionStorage.removeItem(t),v(`Answer accepted. Waiting for saved conversation evidence that the Agent consumed it.`))}catch(e){g(e instanceof Error?e.message:`Answer failed`)}finally{m.current=!1,p(!1)}}}let b=!d||f||!!c||e.status!==`pending`||!!e.answerApprovalId;return(0,$.jsxs)(`article`,{className:`flex min-w-0 flex-col gap-3 rounded-lg border border-frost bg-ivory p-3`,children:[(0,$.jsx)(`p`,{className:`m-0 break-words font-medium`,children:e.question.prompt}),(0,$.jsxs)(`details`,{className:`text-xs text-mocha`,children:[(0,$.jsxs)(`summary`,{className:`cursor-pointer`,children:[`Question details · `,e.status]}),(0,$.jsxs)(`p`,{className:`mt-2 break-all`,children:[`Conversation `,e.conversationId,` · `,e.continuation]})]}),e.status===`pending`?(0,$.jsxs)(`form`,{className:`flex min-w-0 flex-col gap-3`,onSubmit:e=>{e.preventDefault(),n===`other`?y({kind:`text`,text:o}):n!==``&&y({kind:`choice`,index:Number(n)})},children:[(0,$.jsxs)(`fieldset`,{disabled:b,className:`m-0 grid min-w-0 gap-2 border-0 p-0 sm:grid-cols-2`,children:[(0,$.jsx)(`legend`,{className:`sr-only`,children:`Answer this question`}),e.question.choices.map((t,r)=>(0,$.jsxs)(`label`,{className:`m-0 flex min-w-0 cursor-pointer items-center gap-2 rounded-md border border-frost px-3 py-2.5 has-[:checked]:border-sapphire has-[:checked]:bg-sapphire-glow`,children:[(0,$.jsx)(`input`,{className:`m-0 h-4 w-4 shrink-0 accent-sapphire`,type:`radio`,name:`question-${e.id}`,value:r,checked:n===String(r),onChange:()=>i(String(r))}),(0,$.jsxs)(`span`,{className:`min-w-0 break-words [overflow-wrap:anywhere]`,children:[t.label,e.question.recommendedIndex===r?` (Recommended)`:``,t.description&&(0,$.jsx)(`small`,{className:`block`,children:t.description})]})]},r)),(0,$.jsxs)(`label`,{className:`m-0 flex min-w-0 cursor-pointer items-center gap-2 rounded-md border border-frost px-3 py-2.5 has-[:checked]:border-sapphire has-[:checked]:bg-sapphire-glow`,children:[(0,$.jsx)(`input`,{className:`m-0 h-4 w-4 shrink-0 accent-sapphire`,type:`radio`,name:`question-${e.id}`,checked:n===`other`,onChange:()=>i(`other`)}),(0,$.jsx)(`span`,{children:`Other`})]}),n===`other`&&(0,$.jsxs)(`label`,{className:`m-0 grid gap-2 sm:col-span-2`,children:[`Your answer`,(0,$.jsx)(`textarea`,{rows:2,className:`w-full resize-y`,value:o,maxLength:4096,onChange:e=>s(e.target.value)})]})]}),c&&(0,$.jsxs)(`p`,{className:`break-words`,children:[`Saved answer: `,c.answer.kind===`choice`?e.question.choices[c.answer.index]?.label:c.answer.kind===`text`?c.answer.text:`Skip`]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(r,{variant:`primary`,type:`submit`,disabled:b||!n||n===`other`&&(!o.trim()||new TextEncoder().encode(o).length>4096),children:`Send answer`}),(0,$.jsx)(r,{variant:`ghost`,disabled:b,onClick:()=>{y({kind:`skip`})},children:`Skip`}),c&&!e.answerApprovalId&&(0,$.jsx)(r,{variant:`ghost`,disabled:f,onClick:()=>{y()},children:`Retry same answer`})]}),(0,$.jsxs)(`p`,{className:`m-0 text-xs text-mocha`,children:[`Clarification does not grant permission. This question expires at `,new Date(e.expiresAt).toLocaleTimeString(),`.`]}),e.answerApprovalId&&(0,$.jsx)(`a`,{href:`/approvals`,children:`View communication approvals`})]}):(0,$.jsxs)(`p`,{children:[e.answer?.kind===`choice`?e.question.choices[e.answer.index]?.label:e.answer?.kind===`text`?e.answer.text:`No answer: ${e.noAnswerReason??e.status}`,`. `,e.continuation===`consumed`?`Saved in the originating conversation; task completion is separate.`:e.continuation===`interrupted`?`The waiting turn ended.`:`Consumption has not been confirmed.`]}),_&&(0,$.jsx)(`p`,{role:`status`,children:_}),h&&(0,$.jsx)(`p`,{role:`alert`,children:h})]})}var vn=`[[bazilion:inbox-wake]]
|
|
67
|
+
`,yn=`[conversation summary]`,bn=40,xn=1e4,Sn=320,Cn=200,wn=()=>()=>{},Tn=()=>!0,En=()=>!1;function Dn(e,t){let n=e.findIndex(e=>e.type===`command_approval`&&e.approval.id===t.id);if(n===-1)return[...e,{type:`command_approval`,approval:t}];let r=[...e];return r[n]={type:`command_approval`,approval:t},r}function On(e,t){return{message:e,attachments:t,bashApprovalMode:`interactive`,questionMode:`web`}}function kn(e){return`/api/shell-approvals?agentId=${encodeURIComponent(e)}`}var An=`slash commands:
|
|
68
|
+
/context — context breakdown (system prompt, tools, skills, history)
|
|
69
|
+
/compact [N] — summarize the head; keep the last N messages verbatim (default 10)
|
|
70
|
+
/new — open the retained conversation library
|
|
71
|
+
/help — show this list`;function jn(e){if(!e)return``;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Mn(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KiB`:`${(e/(1024*1024)).toFixed(2)} MiB`}function Nn(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let n=String(r.result),i=n.indexOf(`,`);t({name:e.name,data:i>=0?n.slice(i+1):n,mimeType:e.type||`application/octet-stream`})},r.onerror=()=>n(r.error),r.readAsDataURL(e)})}var Pn=e=>e.startsWith(`image/`);function Fn(e){let t=[],n=null;for(let r of e)if(r.role===`user`)n=null,t.push({type:`user`,content:r.content,...r.images&&r.images.length>0?{images:r.images}:{}});else if(r.role===`assistant`){if(r.content&&(n=null,t.push({type:`assistant`,content:r.content})),r.toolCalls&&r.toolCalls.length>0){n||(n={type:`tool`,items:[]},t.push(n));for(let e of r.toolCalls)n.items.push({kind:`call`,id:e.id,name:e.name,body:e.arguments})}}else if(r.role===`tool`){n||(n={type:`tool`,items:[]},t.push(n));let e=r.content.startsWith(`Error:`)||r.content.startsWith(`error:`);n.items.push({kind:e?`error`:`result`,id:r.toolCallId??``,name:r.toolName??``,body:r.content}),r.result&&(t.push({type:`result`,resultId:r.result.resultId}),n=null),r.images&&r.images.length>0&&(t.push({type:`images`,images:r.images}),n=null)}return t}function In({agentId:e,agentName:t,initialMessages:n,initialSessionHead:i}){let o=(0,a.useSyncExternalStore)(wn,Tn,En),[s,c]=(0,a.useState)(n),[l,u]=(0,a.useState)([]),[d,ee]=(0,a.useState)([]),[f,p]=(0,a.useState)(!1),[m,h]=(0,a.useState)(!1),[g,_]=(0,a.useState)(null),[v,y]=(0,a.useState)(``),[b,x]=(0,a.useState)([]),[S,te]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[ne,T]=(0,a.useState)(!1),[re,ie]=(0,a.useState)({}),[ae,E]=(0,a.useState)({}),[D,oe]=(0,a.useState)(!1),[O,k]=(0,a.useState)(),[A,j]=(0,a.useState)(!1),[M,se]=(0,a.useState)(!1),N=(0,a.useRef)(null),[ce,P]=(0,a.useState)(i?.unavailable??!1),le=(0,a.useRef)(null),F=(0,a.useRef)(null),ue=(0,a.useRef)(null),I=(0,a.useRef)(null),L=(0,a.useRef)(e),R=(0,a.useRef)(!1);L.current=e;let de=(0,a.useRef)(0),fe=(0,a.useRef)(0),z=(0,a.useRef)(i??{file:null,size:0}),pe=(0,a.useRef)(!1);pe.current=m;let me=m||ne;(0,a.useEffect)(()=>{I.current?.abort(),I.current=null,R.current=!1,c(n),u([]),ee([]),_(null),y(``),se(!1),x([]),P(i?.unavailable??!1),p(!1),h(!1),w(!1),T(!1),ie({}),E({}),z.current=i??{file:null,size:0}},[e]),(0,a.useEffect)(()=>{let t=new AbortController,n=!1;async function r(){try{let r=await fetch(kn(e),{signal:t.signal});if(!r.ok)return;let i=(await r.json()).approvals.filter(t=>t.agentId===e&&t.status===`pending`);if(n||i.length===0)return;sessionStorage.removeItem(`bz_pending_${e}`),R.current=!0,u(e=>i.reduce(Dn,e)),T(!0)}catch(e){if(e.name===`AbortError`)return}}return r(),()=>{n=!0,t.abort()}},[e]);let he=(0,a.useRef)(!0);(0,a.useLayoutEffect)(()=>{let e=le.current;e&&he.current&&(e.scrollTop=e.scrollHeight)});function ge(){let e=le.current;if(!e){he.current=!0;return}he.current=e.scrollHeight-e.scrollTop-e.clientHeight<bn}(0,a.useLayoutEffect)(()=>{let e=ue.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,Cn)}px`)},[v]),(0,a.useEffect)(()=>{let t=`bz_pending_${e}`;function n(){document.visibilityState===`visible`&&sessionStorage.getItem(t)&&(sessionStorage.removeItem(t),w(!0))}return document.addEventListener(`visibilitychange`,n),()=>document.removeEventListener(`visibilitychange`,n)},[e]),(0,a.useEffect)(()=>{if(!i)return;let t=!1,n=null;async function r(){if(!t){if(!document.hidden&&!pe.current&&!C)try{let t=await fetch(`/api/agents/${encodeURIComponent(e)}/sessions/head`);if(t.ok){let e=await t.json();if(typeof e.size==`number`){let t=z.current;(e.unavailable!==t.unavailable||e.file!==t.file||e.size!==t.size)&&w(!0)}}}catch{}n=setTimeout(r,xn)}}return n=setTimeout(r,xn),()=>{t=!0,n&&clearTimeout(n)}},[e,i,C]);async function _e(){if(!pe.current)try{let t=await fetch(`/api/agents/${encodeURIComponent(e)}/sessions/messages`);if(!t.ok)throw Error(`Conversation history is unavailable. Your draft is preserved.`);let n=await t.json();if(L.current!==e)return;P(n.head.unavailable??!1),c(n.messages),u([]),_(null),z.current=n.head,w(!1)}catch(e){B(e instanceof Error?e.message:`Could not refresh conversation`)}}async function ve(){if(L.current===e)try{let t=await fetch(`/api/agents/${encodeURIComponent(e)}/sessions/head`);if(!t.ok)return;let n=await t.json();if(L.current===e&&typeof n.size==`number`){let e=z.current.selection;if(e?.conversationId&&e.conversationId!==n.selection?.conversationId){w(!0);return}P(n.unavailable??!1),z.current=n}}catch{}}function B(e){ge(),ee(t=>[...t,{id:de.current++,content:e,afterIdx:fe.current}])}async function ye(){try{let t=await fetch(`/api/agents/${encodeURIComponent(e)}/chat/context`);if(!t.ok){B(`/context failed: ${t.statusText}`);return}let n=await t.json(),r=(e,t)=>`${e.toLocaleString()} chars (~${t.toLocaleString()} tok)`,i=[];i.push(`context for ${n.agentId}`),i.push(`model: ${n.model}`),i.push(``),i.push(`system prompt: ${r(n.systemPrompt.chars,n.systemPrompt.tokens)}`);for(let e of n.systemPrompt.files)i.push(` - ${e.name}: ${e.chars.toLocaleString()} chars`);i.push(``),i.push(`tools: ${n.tools.count} (${n.tools.schemaChars.toLocaleString()} chars of schema)`);for(let e of n.tools.entries.slice(0,5))i.push(` - ${e.name}: ${e.schemaChars.toLocaleString()} chars`);if(n.skills.count>0){i.push(``),i.push(`skills: ${n.skills.count}`);for(let e of n.skills.entries.slice(0,10))i.push(` - ${e.name}: ${e.blockChars.toLocaleString()} chars`)}i.push(``),i.push(`history: ${n.history.messageEntries} messages / ${n.history.compactionEntries} compactions`),i.push(` ${r(n.history.chars,n.history.tokensEstimate)}`),i.push(` bytes on disk: ${Mn(n.history.bytes)}`),i.push(``),i.push(`TOTAL: ${r(n.totals.chars,n.totals.tokens)}`),B(i.join(`
|
|
72
|
+
`))}catch(e){B(`/context failed: ${e.message}`)}}async function be(t){if(s.length<2){B(`/compact: need ≥2 messages to compact`);return}let n,r=t.trim();if(r){let e=Number(r);Number.isFinite(e)&&e>=0&&(n=Math.floor(e))}we(),h(!0),p(!0);try{let t=await fetch(`/api/agents/${encodeURIComponent(e)}/chat/compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({keepTail:n,expectedSelection:z.current.selection})});if(!t.ok){let e=t.statusText;try{e=(await t.json()).error||e}catch{}B(`/compact failed: ${e}`);return}let r=await t.json();B(`/compact: ${r.before} → ${r.after} entries (${r.summarized} summarized, ${r.keptTail} kept verbatim; ~${r.tokensBefore.toLocaleString()} → ~${r.tokensAfter.toLocaleString()} tok). reloading…`),setTimeout(()=>window.location.reload(),400)}catch(e){B(`/compact failed: ${e.message}`)}finally{p(!1),h(!1)}}async function xe(e){let t=e.trim();if(!t.startsWith(`/`))return!1;let n=t.split(/\s+/),r=(n[0]??``).toLowerCase(),i=n.slice(1).join(` `);switch(r){case`/help`:return B(An),!0;case`/context`:return await ye(),!0;case`/new`:return oe(!0),!0;case`/compact`:return await be(i),!0;default:return!1}}function Se(){for(let e=s.length-1;e>=0;e--)if(s[e]?.role===`user`)return e;return-1}function Ce(){if(l.length>0||me)return;let e=Se();if(e===-1)return;let t=s[e];t&&(_(e),y(t.content),ue.current?.focus())}function we(){_(null)}async function Te(e){if(!e)return;let t=Array.from(e);if(t.length===0)return;let n=await Promise.all(t.map(Nn));x(e=>[...e,...n].slice(0,16))}function Ee(e){let t=Array.from(e.clipboardData.files);t.some(e=>e.type.startsWith(`image/`))&&(e.preventDefault(),Te(t))}function De(e){Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),te(!0))}function Oe(e){e.currentTarget===e.target&&te(!1)}function ke(e){e.dataTransfer.files.length!==0&&(e.preventDefault(),te(!1),Te(e.dataTransfer.files))}let Ae=(0,a.useCallback)(async t=>{let n=b;if(!t.trim()&&n.length===0)return;if(!M){B(`Queue status is loading. Your draft is preserved.`);return}if(me||A){await N.current?.enqueue(t,n,z.current.selection)&&L.current===e&&(y(e=>e===t?``:e),x(e=>e===n?[]:e));return}if(y(``),await xe(t))return;x([]);let r=null;if(g!==null){let n=g;try{let i=await fetch(`/api/agents/${encodeURIComponent(e)}/chat/truncate`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({keepCount:n,expectedSelection:z.current.selection})});if(!i.ok){let e=i.statusText;try{e=(await i.json()).error||e}catch{}y(t),B(`Could not replace the last turn: ${e}`);return}r=s.slice(0,n),c(r),_(null)}catch(e){y(t),B(`Could not replace the last turn: ${e.message}`);return}}ge();let i=n.filter(e=>Pn(e.mimeType)),a=n.filter(e=>!Pn(e.mimeType));u([{type:`user`,content:t,...i.length>0?{images:i}:{},...a.length>0?{files:a.map(e=>({name:e.name??`file`}))}:{}}]),T(!1),ie({}),E({}),R.current=!1,sessionStorage.setItem(`bz_pending_${e}`,`1`);let o=new AbortController;I.current=o,h(!0),p(!0);let l=!1;try{let r=await fetch(`/api/agents/${encodeURIComponent(e)}/chat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({...On(t,n),expectedSelection:z.current.selection}),signal:o.signal});if(r.status===202){let t=await r.json();u(e=>[...e,{type:`error`,content:`[approval pending] ${t.approvalId} · expires ${new Date(t.expiresAt).toLocaleString()} · review in /approvals`}]),sessionStorage.removeItem(`bz_pending_${e}`);return}if(r.status===409){y(t),x(n),u([]),w(!0),sessionStorage.removeItem(`bz_pending_${e}`),B(`Conversation changed. Refresh history, then review and send your preserved draft.`);return}if(!r.ok||!r.body){let e=r.statusText;try{e=(await r.json()).error||e}catch{}u(t=>[...t,{type:`error`,content:`[error] ${e}`}]);return}let i=r.headers.get(`x-bazilion-conversation-selection`);if(i)try{let e=JSON.parse(i);typeof e.conversationId==`string`&&Number.isSafeInteger(e.revision)&&e.revision>=0&&(z.current={...z.current,selection:e})}catch{}let a=r.body.getReader(),s=new TextDecoder,c=``;for(;;){let{done:e,value:t}=await a.read();if(e)break;c+=s.decode(t,{stream:!0});let n=c.split(`
|
|
73
|
+
`);c=n.pop()??``;for(let e of n){if(!e.trim())continue;let t;try{t=JSON.parse(e)}catch{continue}(t.kind===`done`||t.kind===`fatal`)&&(l=!0),je(t)}}if(c.trim())try{let e=JSON.parse(c);(e.kind===`done`||e.kind===`fatal`)&&(l=!0),je(e)}catch{}await ve(),sessionStorage.removeItem(`bz_pending_${e}`)}catch(t){t.name!==`AbortError`&&u(e=>[...e,{type:`error`,content:`[network error] ${t.message}`}]),sessionStorage.removeItem(`bz_pending_${e}`)}finally{L.current===e&&I.current===o&&(!l&&R.current&&T(!0),p(!1),h(!1),I.current=null)}},[e,g,s,me,A,M,b]);function je(t){if(L.current!==e)return;if(t.kind===`fatal`){R.current=!1,u(e=>[...e.map(e=>e.type===`command_approval`&&e.approval.status===`pending`?{type:`command_approval`,approval:{...e.approval,status:`cancelled`}}:e),{type:`error`,content:`[fatal] ${t.error}`}]),T(!1);return}if(t.kind===`done`){R.current=!1,c(t.messages),u([]),T(!1),ie({}),E({});return}if(t.kind!==`event`)return;let n=t.event;if(ge(),n.type!==`user_message`){if(n.type===`assistant_delta`){p(!1),u(e=>{let t=[...e],r=t[t.length-1];return r?.type===`assistant`?t[t.length-1]={type:`assistant`,content:r.content+n.delta}:t.push({type:`assistant`,content:n.delta}),t});return}if(n.type===`assistant_message`){p(!1),u(e=>{let t=[...e];return t[t.length-1]?.type===`assistant`?t[t.length-1]={type:`assistant`,content:n.text}:t.push({type:`assistant`,content:n.text}),t});return}if(n.type===`command_approval`){if(n.approval.agentId!==e)return;R.current=!0,p(n.approval.status!==`pending`&&n.approval.status!==`cancelled`),u(e=>Dn(e,n.approval));return}if(n.type===`tool_call`||n.type===`tool_result`||n.type===`tool_error`){p(n.type!==`tool_call`);let e=n.type===`tool_call`?{kind:`call`,id:n.id,name:n.name,body:n.arguments}:n.type===`tool_result`?{kind:`result`,id:n.id,name:n.name,body:n.result}:{kind:`error`,id:n.id,name:n.name,body:n.error},t=n.type===`tool_result`?n.images:void 0;u(n=>{let r=[...n],i=r[r.length-1];return i?.type===`tool`?r[r.length-1]={type:`tool`,items:[...i.items,e]}:r.push({type:`tool`,items:[e]}),t&&t.length>0&&r.push({type:`images`,images:t}),r});return}if(n.type===`file`){if(n.result){let e=n.result.resultId;u(t=>[...t,{type:`result`,resultId:e}]);return}u(e=>[...e,{type:`file`,name:n.name,mimeType:n.mimeType,data:n.data}]);return}n.type===`error`&&u(e=>[...e,{type:`error`,content:`[error] ${n.error}`}])}}async function Me(t){if(L.current!==e)return null;try{let n=await fetch(kn(e));if(!n.ok)return null;let r=await n.json();if(L.current!==e)return null;let i=r.approvals.find(n=>n.id===t&&n.agentId===e);return i&&u(e=>Dn(e,i)),i??null}catch{return null}}async function Ne(t,n){if(!(t.agentId!==e||t.status!==`pending`)){ie(e=>({...e,[t.id]:!0})),E(e=>{let n={...e};return delete n[t.id],n});try{let r=await fetch(`/api/shell-approvals/${encodeURIComponent(t.id)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({decision:n})}),i=await r.json().catch(()=>null);if(L.current!==e)return;if(i?.approval?.agentId===e&&u(e=>Dn(e,i.approval)),!r.ok){let e=i?.error??`Decision failed (${r.status})`,n=Bn(e);if(n){u(e=>Dn(e,{...t,status:n}));return}throw Error(e)}}catch(n){let r=await Me(t.id);if(L.current!==e)return;(!r||r.status===`pending`)&&E(e=>({...e,[t.id]:n instanceof Error?n.message:String(n)}))}finally{L.current===e&&ie(e=>({...e,[t.id]:!1}))}}}async function Pe(){!await N.current?.stop()&&L.current===e&&B(`Stop was not confirmed. Check queue controls and try again; the active response may still be running.`)}function Fe(e){e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Ae(v))}let Ie=Fn(s);fe.current=Ie.length+l.length;let Le=(()=>{if(l.length>0||me)return-1;for(let e=Ie.length-1;e>=0;e--)if(Ie[e]?.type===`user`)return e;return-1})(),Re=(()=>{if(g===null)return-1;let e=0;for(let t=0;t<Ie.length;t++)if(Ie[t]?.type===`user`){if(e===s.slice(0,g+1).filter(e=>e.role===`user`).length-1)return t;e++}return Le})();return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col overflow-hidden rounded-[16px] border border-frost bg-snow shadow-baziu-sm`,onDragOver:De,onDragLeave:Oe,onDrop:ke,children:[S&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-[16px] border-2 border-dashed border-sapphire bg-sapphire-glow/80 text-[0.95em] font-medium text-sapphire-deep`,children:`drop images or files to attach`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-frost px-4 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`a`,{href:`/`,className:`inline-flex h-7 items-center rounded-md border border-frost px-2 text-xs font-semibold text-mocha lg:hidden`,children:`← agents`}),(0,$.jsx)(`h1`,{className:`truncate font-display text-[1.2rem] text-charcoal`,children:t})]}),(0,$.jsx)(`a`,{href:`/agents/${e}?mode=settings`,className:`shrink-0 text-xs text-mocha-light hover:text-sapphire`,children:`Manage agent →`})]}),(0,$.jsx)(`div`,{className:`mx-5 mt-2`,children:(0,$.jsx)(r,{variant:`ghost`,"aria-expanded":D,onClick:()=>oe(e=>!e),children:D?`Close conversations`:`Conversations`})}),ce&&(0,$.jsx)(`p`,{role:`alert`,className:`mx-5 mt-2 text-sm`,children:`Selected conversation history is unavailable. Open Conversations to start a new one; retained history and files stay listed.`}),C&&(0,$.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`mx-5 mt-2 flex items-center gap-2 rounded-md border border-sapphire bg-frost px-4 py-2 text-[0.86em] text-mocha`,children:[(0,$.jsx)(`span`,{className:`h-2 w-2 flex-none rounded-full bg-sapphire`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`flex-1`,children:ne?`the recovered turn has new activity — reload to see it`:`new activity from another source — reload to see it`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void _e(),className:`rounded-sm bg-sapphire px-3 py-1 text-[0.92em] text-snow hover:opacity-90`,children:`reload`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>w(!1),className:`px-1 text-mocha-light hover:text-mocha`,"aria-label":`dismiss`,children:`×`})]}),(0,$.jsxs)(`div`,{ref:le,onScroll:ge,role:`log`,"aria-label":`Conversation with ${t}`,"aria-live":`polite`,"aria-relevant":`additions`,"aria-busy":me,className:`min-h-0 flex-1 overflow-y-auto px-5 py-5 ${g===null?``:`is-editing`}`,children:[D&&(0,$.jsx)(pn,{initialConversationId:O,agentId:e,turnBusy:me,onCreated:_e,renderHistory:e=>(0,$.jsx)(Wn,{messages:e})},e),!ce&&Ie.length===0&&l.length===0&&d.length===0&&(0,$.jsx)(`p`,{className:`py-12 text-center italic text-mocha-light`,children:`Start a conversation…`}),(()=>{let e=[],t=0,n=n=>{for(;t<d.length&&d[t].afterIdx<=n;){let n=d[t];e.push((0,$.jsx)(Ln,{entry:{type:`system`,content:n.content},markdownReady:o,onCommandApprovalDecision:Ne},`y-${n.id}`)),t++}};n(0);for(let t=0;t<Ie.length;t++){let r=Ie[t];e.push((0,$.jsx)(Ln,{entry:r,markdownReady:o,isLastUser:t===Le&&g===null,isWillDrop:Re!==-1&&t>=Re,onEdit:Ce,onCommandApprovalDecision:Ne,commandApprovalBusy:r.type===`command_approval`&&!!re[r.approval.id],commandApprovalError:r.type===`command_approval`?ae[r.approval.id]:void 0},`s-${t}`)),n(t+1)}for(let t=0;t<l.length;t++){let r=l[t];e.push((0,$.jsx)(Ln,{entry:r,markdownReady:o,onCommandApprovalDecision:Ne,commandApprovalBusy:r.type===`command_approval`&&!!re[r.approval.id],commandApprovalError:r.type===`command_approval`?ae[r.approval.id]:void 0},`l-${t}`)),n(Ie.length+t+1)}for(;t<d.length;){let n=d[t];e.push((0,$.jsx)(Ln,{entry:{type:`system`,content:n.content},markdownReady:o,onCommandApprovalDecision:Ne},`y-${n.id}`)),t++}return e})(),f&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-1 py-1 text-[0.85em] text-mocha-light`,children:[(0,$.jsx)(Un,{}),(0,$.jsx)(Un,{delay:`0.15s`}),(0,$.jsx)(Un,{delay:`0.3s`}),(0,$.jsx)(`span`,{children:`agent is thinking…`})]})]}),(0,$.jsx)(`p`,{className:`sr-only`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:me?`${t} is responding.`:`Conversation ready.`}),g!==null&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-frost bg-sapphire-glow px-5 py-2 text-[0.85em] text-sapphire-deep`,children:[(0,$.jsx)(`span`,{children:`editing last message — submit to replace, or`}),(0,$.jsx)(`button`,{type:`button`,onClick:we,className:`ml-auto rounded-sm border border-sapphire-light bg-transparent px-2 py-0.5 text-[0.92em] text-sapphire-deep hover:bg-snow`,children:`cancel`})]}),b.length>0&&(0,$.jsx)(`div`,{className:`flex max-h-24 shrink-0 flex-wrap gap-2 overflow-y-auto border-t border-frost bg-ivory px-5 pt-3`,children:b.map((e,t)=>{let n=()=>x(e=>e.filter((e,n)=>n!==t));return Pn(e.mimeType)?(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:`pending attachment`,className:`h-16 w-16 rounded-md border border-frost object-cover`}),(0,$.jsx)(`button`,{type:`button`,onClick:n,className:`absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full border border-frost bg-snow text-[0.7em] text-mocha hover:border-sapphire hover:text-sapphire`,"aria-label":`remove attachment`,children:`✕`})]},`${e.mimeType}-${t}`):(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-frost bg-snow px-2 py-1 text-[0.82em] text-mocha`,children:[(0,$.jsx)(`span`,{children:`📄`}),(0,$.jsx)(`span`,{className:`max-w-[160px] truncate`,children:e.name??`file`}),(0,$.jsx)(`button`,{type:`button`,onClick:n,className:`text-[0.85em] text-mocha hover:text-sapphire`,"aria-label":`remove attachment`,children:`✕`})]},`${e.name??`file`}-${t}`)})}),(0,$.jsx)(hn,{onViewConversation:e=>{k(e),oe(!0)},ref:N,agentId:e,selection:()=>z.current.selection,onQueueMode:e=>{j(e),se(!0)}},e),(0,$.jsx)(gn,{agentId:e},`questions-${e}`),(0,$.jsxs)(`form`,{className:`grid shrink-0 grid-cols-[auto_minmax(0,1fr)] items-end gap-2 border-t border-frost bg-ivory px-3 py-3 sm:grid-cols-[auto_minmax(0,1fr)_auto] sm:px-5`,onSubmit:e=>{e.preventDefault(),Ae(v)},children:[(0,$.jsx)(`input`,{ref:F,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{Te(e.target.files),e.target.value=``}}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>F.current?.click(),title:`attach images or files`,"aria-label":`attach files`,className:`flex h-11 items-center justify-center rounded-md border-[1.5px] border-frost bg-snow px-3 py-2 text-[1em] text-mocha transition-colors hover:border-sapphire hover:text-sapphire disabled:cursor-not-allowed disabled:opacity-50`,children:`📎`}),(0,$.jsx)(`textarea`,{ref:ue,rows:1,value:v,onChange:e=>y(e.target.value),onKeyDown:Fe,onPaste:Ee,placeholder:`Write a message…`,title:`Shift+Enter for a new line. Paste or attach files with the paperclip.`,autoComplete:`off`,"aria-label":`Message ${t}`,className:`max-h-[200px] min-h-11 min-w-0 flex-1 resize-none overflow-y-auto rounded-md border-[1.5px] border-frost bg-snow px-3 py-2 text-[0.93em] leading-[1.45] text-chocolate outline-none transition-colors focus:border-sapphire focus:shadow-[0_0_0_3px_var(--color-sapphire-glow)]`}),(0,$.jsxs)(`div`,{className:`col-span-2 flex flex-wrap justify-end gap-2 sm:col-span-1`,children:[(0,$.jsx)(r,{variant:`primary`,type:`submit`,className:`min-h-11 whitespace-normal text-center`,disabled:!v.trim()&&b.length===0,children:me||A?`Queue follow-up`:`Send`}),me&&(0,$.jsx)(r,{variant:`danger`,className:`min-h-11`,onClick:()=>void Pe(),"aria-label":`Stop response and pause queue`,children:`Stop`})]})]})]})}function Ln({entry:e,markdownReady:t,isLastUser:n,isWillDrop:r,onEdit:a,onCommandApprovalDecision:o,commandApprovalBusy:s,commandApprovalError:c}){let l=r?`opacity-40 [&_.bubble-content]:line-through`:``;if(e.type===`user`){if(e.content.startsWith(vn)){let t=e.content.slice(24);return(0,$.jsxs)(`div`,{className:`my-4 flex flex-col items-end ${l}`,children:[(0,$.jsx)(`span`,{className:`mb-1 text-[0.72em] font-semibold uppercase tracking-wider text-mocha opacity-90`,children:`inbox`}),(0,$.jsx)(`div`,{className:`bubble-content max-w-[85%] whitespace-pre-wrap break-words rounded-[14px_14px_4px_14px] border border-fawn border-l-[3px] border-l-mocha-light bg-ivory px-3 py-2 font-mono text-[0.88em] leading-[1.5] text-mocha`,children:t})]})}return(0,$.jsxs)(`div`,{className:`team relative my-4 flex flex-col items-end ${l}`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:`you`}),e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-1 flex max-w-[85%] flex-wrap justify-end gap-1`,children:e.images.map((e,t)=>(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:`attachment`,className:`max-h-48 rounded-lg border border-sapphire-light`},t))}),e.files&&e.files.length>0&&(0,$.jsx)(`div`,{className:`mb-1 flex max-w-[85%] flex-wrap justify-end gap-1`,children:e.files.map((e,t)=>(0,$.jsxs)(`span`,{className:`flex items-center gap-1 rounded-md border border-sapphire-light bg-sapphire-glow px-2 py-1 text-[0.8em] text-chocolate`,children:[`📄 `,(0,$.jsx)(`span`,{className:`max-w-[180px] truncate`,children:e.name})]},t))}),e.content&&(0,$.jsx)(`div`,{className:`bubble-content max-w-[85%] whitespace-pre-wrap break-words rounded-[14px_14px_4px_14px] border border-sapphire-light bg-sapphire-glow px-3 py-2 text-chocolate`,children:e.content}),n&&a&&(0,$.jsx)(`button`,{type:`button`,onClick:a,title:`edit and resend — replaces the last turn`,className:`absolute left-1 top-1 rounded-sm border border-fawn bg-ivory px-2 py-0.5 text-[0.78em] font-medium text-mocha opacity-65 transition hover:border-sapphire hover:bg-sapphire-glow hover:text-sapphire hover:opacity-100 team-hover:opacity-100 team-focus-within:opacity-100`,children:`edit`})]})}if(e.type===`assistant`){if(e.content.startsWith(yn)){let n=e.content.slice(22).trim();return(0,$.jsx)(`div`,{className:`my-3 border-y border-dashed border-frost py-2 text-[0.85em] italic text-mocha-light ${l}`,children:(0,$.jsxs)(`details`,{children:[(0,$.jsx)(`summary`,{className:`cursor-pointer select-none text-center [&::-webkit-details-marker]:hidden`,children:`— conversation summary (click to expand) —`}),(0,$.jsx)(`div`,{className:`md-content mt-2 rounded-sm bg-frost/40 p-2 not-italic`,dangerouslySetInnerHTML:{__html:dn(n,t)}})]})})}return e.content.startsWith(`[error]`)||e.content.startsWith(`[fatal]`)||e.content.startsWith(`[network error]`)?(0,$.jsxs)(`div`,{className:`my-4 flex flex-col items-start ${l}`,children:[(0,$.jsx)(`span`,{className:`mb-1 text-[0.72em] font-semibold uppercase tracking-wider text-danger`,children:`error`}),(0,$.jsx)(`div`,{className:`bubble-content rounded-r-sm border-l-[3px] border-l-danger bg-danger/10 py-1 pl-3 pr-2 leading-[1.55]`,dangerouslySetInnerHTML:{__html:dn(e.content,t)}})]}):(0,$.jsxs)(`div`,{className:`my-4 flex flex-col items-start ${l}`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:`agent`}),(0,$.jsx)(`div`,{className:`md-content bubble-content w-full leading-[1.55] text-chocolate`,dangerouslySetInnerHTML:{__html:dn(e.content,t)}})]})}if(e.type===`tool`)return(0,$.jsx)(Vn,{items:e.items,dropCls:l});if(e.type===`images`)return(0,$.jsx)(`div`,{className:`my-2 space-y-2 ${l}`,children:e.images.map((e,t)=>(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:`screenshot`,className:`block max-w-full rounded-lg border border-fawn`},t))});if(e.type===`result`)return(0,$.jsx)(i,{resultId:e.resultId});if(e.type===`file`){let t=e.mimeType.startsWith(`image/`),n=`data:${e.mimeType};base64,${e.data}`;return(0,$.jsxs)(`div`,{className:`my-2 ${l}`,children:[t&&(0,$.jsx)(`img`,{src:n,alt:e.name,className:`mb-1 block max-w-full rounded-lg border border-fawn`}),(0,$.jsxs)(`a`,{href:n,download:e.name,className:`inline-flex items-center gap-2 rounded-md border border-fawn bg-ivory px-3 py-2 text-[0.88em] text-mocha hover:border-sapphire hover:text-sapphire`,children:[(0,$.jsx)(`span`,{children:`📄`}),(0,$.jsx)(`span`,{className:`max-w-[260px] truncate`,children:e.name}),(0,$.jsx)(`span`,{className:`text-[0.85em] opacity-70`,children:`download`})]})]})}return e.type===`command_approval`?(0,$.jsx)(Rn,{approval:e.approval,busy:s,error:c,onDecision:o}):e.type===`system`?(0,$.jsxs)(`div`,{className:`my-3 rounded-r-sm border-l-[3px] border-sapphire bg-sapphire-glow px-3 py-1 font-mono text-[0.88em] text-sapphire-deep ${l}`,children:[(0,$.jsx)(`span`,{className:`mr-2 font-semibold uppercase tracking-wider opacity-80`,children:`system`}),(0,$.jsx)(`span`,{className:`whitespace-pre-wrap`,children:e.content})]}):e.type===`error`?(0,$.jsx)(`div`,{className:`my-3 rounded-r-sm border-l-[3px] border-danger bg-danger/10 px-3 py-1 text-[0.92em] text-danger ${l}`,children:e.content}):null}function Rn({approval:e,busy:t=!1,error:n,onDecision:i}){let a=e.status===`pending`;return(0,$.jsxs)(`section`,{className:`my-3 rounded-lg border border-danger/50 bg-danger/5 p-4 text-chocolate`,"aria-label":`Shell command approval`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`m-0 text-[0.72em] font-semibold uppercase tracking-wider text-danger`,children:`Shell command approval`}),(0,$.jsx)(`h2`,{className:`m-0 mt-1 font-body text-[0.95em] font-semibold`,children:a?`A risky command is waiting for you`:`Command decision recorded`})]}),(0,$.jsx)(`span`,{className:`rounded-full border border-danger/30 px-2 py-0.5 text-[0.75em] font-semibold uppercase tracking-wide text-danger`,children:e.status.replaceAll(`_`,` `)})]}),(0,$.jsx)(`pre`,{className:`mt-3 max-h-48 overflow-auto whitespace-pre-wrap break-words rounded-md border border-fawn bg-snow p-3 font-mono text-[0.82em] leading-[1.45] text-charcoal`,children:e.command}),(0,$.jsx)(`ul`,{className:`mt-3 space-y-1.5 pl-5 text-[0.84em] leading-[1.4] text-mocha`,children:e.risks.map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-chocolate`,children:e.message}),` `,(0,$.jsx)(`code`,{className:`text-[0.9em]`,children:e.code})]},`${e.code}:${e.span.start}:${e.span.end}`))}),a?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`p`,{className:`mt-3 text-[0.78em] text-mocha-light`,children:[`This approval expires`,` `,(0,$.jsx)(`time`,{dateTime:new Date(e.expiresAt).toISOString(),children:new Date(e.expiresAt).toLocaleString()}),`. Deny blocks only this command; cancel stops the whole turn.`]}),n&&(0,$.jsx)(`p`,{role:`alert`,className:`mt-2 rounded-md bg-danger/10 px-3 py-2 text-[0.82em] text-danger`,children:n}),i&&(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(r,{variant:`primary`,disabled:t,onClick:()=>i(e,`deny`),children:`Deny`}),(0,$.jsx)(r,{variant:`danger`,disabled:t,onClick:()=>i(e,`allow`),children:`Allow once`})]})]}):(0,$.jsx)(`p`,{role:`status`,className:`mt-3 text-[0.84em] font-medium text-mocha`,children:zn(e.status)})]})}function zn(e){switch(e){case`pending`:return`Waiting for a decision.`;case`allowed`:return`Allowed once — the command may run for this tool call only.`;case`denied`:return`Denied — the command was not run.`;case`auto_denied`:return`Automatically denied — no interactive approval path was available.`;case`expired`:return`Expired — the command was not run.`;case`cancelled`:return`Cancelled — the command was not run.`}}function Bn(e){if(!e.startsWith(`shell approval already decided: `))return null;let t=e.slice(32);switch(t){case`allowed`:case`denied`:case`auto_denied`:case`expired`:case`cancelled`:return t;default:return null}}function Vn({items:e,dropCls:t}){let[n,r]=(0,a.useState)(!1),i=(0,a.useRef)(null),[o,s]=(0,a.useState)(!1);return(0,a.useLayoutEffect)(()=>{let e=i.current;e&&s(e.scrollHeight>324)},[e.length]),(0,$.jsxs)(`div`,{className:`my-1.5 rounded-r-sm border-l-[3px] border-fawn bg-ivory px-3 py-2 font-mono text-[0.82em] leading-[1.5] text-mocha-light ${t}`,children:[(0,$.jsxs)(`div`,{ref:i,className:`relative overflow-hidden`,style:{maxHeight:n?`none`:`${Sn}px`},children:[e.map((e,t)=>(0,$.jsx)(Hn,{item:e},t)),o&&!n&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-0 h-10`,style:{background:`linear-gradient(to bottom, rgba(247,240,229,0), var(--color-ivory))`}})]}),o&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`mt-2 rounded-sm border border-fawn bg-transparent px-2 py-0.5 text-[0.9em] text-mocha hover:border-sapphire hover:text-sapphire-deep`,children:n?`show less ↑`:`show more ↓`})]})}function Hn({item:e}){if(e.kind===`call`){let t=jn(e.body),n=t.includes(`
|
|
74
|
+
`);return(0,$.jsxs)(`div`,{className:`whitespace-pre-wrap break-words py-0.5`,children:[(0,$.jsx)(`span`,{className:`mr-1 opacity-45`,children:`→`}),(0,$.jsx)(`span`,{className:`font-medium text-mocha`,children:e.name}),n?(0,$.jsx)(`pre`,{className:`ml-4 mt-0.5 rounded-sm bg-[rgba(42,31,22,0.04)] px-2 py-1 font-mono text-[0.95em] leading-[1.4] text-mocha`,children:t}):t?(0,$.jsxs)(`span`,{children:[` (`,t,`)`]}):null]})}return e.kind===`error`?(0,$.jsxs)(`div`,{className:`whitespace-pre-wrap break-words py-0.5 text-rose-baziu`,children:[(0,$.jsx)(`span`,{className:`mr-1 opacity-45`,children:`←`}),e.body]}):(0,$.jsxs)(`div`,{className:`whitespace-pre-wrap break-words py-0.5`,children:[(0,$.jsx)(`span`,{className:`mr-1 opacity-45`,children:`←`}),e.body]})}function Un({delay:e=`0s`}){return(0,$.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 animate-pulse rounded-full bg-mocha-light/60`,style:{animationDelay:e},"aria-hidden":`true`})}function Wn({messages:e}){let t=(0,a.useSyncExternalStore)(wn,Tn,En);return(0,$.jsx)(`div`,{"aria-label":`Source conversation`,children:Fn(e).map((e,n)=>(0,$.jsx)(Ln,{entry:e,markdownReady:t},n))})}export{Wn as n,In as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e,t}from"./jsx-runtime-DGeXAQPT.js";import{t as n}from"./react-3W8R1pOO.js";import{A as r,
|
|
1
|
+
import{r as e,t}from"./jsx-runtime-DGeXAQPT.js";import{t as n}from"./react-3W8R1pOO.js";import{A as r,B as i,F as a,I as o,L as s,M as c,N as l,P as u,R as d,U as f,V as p,W as m,j as h,k as g,z as _}from"./index-BUhhk_u9.js";import{t as v}from"./Button-ByiV6fpd.js";var y=e(n(),1),b=t(),x=`Dialog`,[S,C]=i(x),[w,T]=S(x),E=e=>{let{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:s=!0}=e,c=y.useRef(null),l=y.useRef(null),[u,f]=d({prop:r,defaultProp:i??!1,onChange:a,caller:x});return(0,b.jsx)(w,{scope:t,triggerRef:c,contentRef:l,contentId:o(),titleId:o(),descriptionId:o(),open:u,onOpenChange:f,onOpenToggle:y.useCallback(()=>f(e=>!e),[f]),modal:s,children:n})};E.displayName=x;var D=`DialogTrigger`,O=y.forwardRef((e,t)=>{let{__scopeDialog:n,...r}=e,i=T(D,n),a=m(t,i.triggerRef);return(0,b.jsx)(p.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":J(i.open),...r,ref:a,onClick:_(e.onClick,i.onOpenToggle)})});O.displayName=D;var k=`DialogPortal`,[A,j]=S(k,{forceMount:void 0}),M=e=>{let{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=T(k,t);return(0,b.jsx)(A,{scope:t,forceMount:n,children:y.Children.map(r,e=>(0,b.jsx)(s,{present:n||a.open,children:(0,b.jsx)(c,{asChild:!0,container:i,children:e})}))})};M.displayName=k;var N=`DialogOverlay`,P=y.forwardRef((e,t)=>{let n=j(N,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=T(N,e.__scopeDialog);return a.modal?(0,b.jsx)(s,{present:r||a.open,children:(0,b.jsx)(I,{...i,ref:t})}):null});P.displayName=N;var F=f(`DialogOverlay.RemoveScroll`),I=y.forwardRef((e,t)=>{let{__scopeDialog:n,...i}=e,o=T(N,n),s=m(t,a());return(0,b.jsx)(r,{as:F,allowPinchZoom:!0,shards:[o.contentRef],children:(0,b.jsx)(p.div,{"data-state":J(o.open),...i,ref:s,style:{pointerEvents:`auto`,...i.style}})})}),L=`DialogContent`,R=y.forwardRef((e,t)=>{let n=j(L,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=T(L,e.__scopeDialog);return(0,b.jsx)(s,{present:r||a.open,children:a.modal?(0,b.jsx)(z,{...i,ref:t}):(0,b.jsx)(B,{...i,ref:t})})});R.displayName=L;var z=y.forwardRef((e,t)=>{let n=T(L,e.__scopeDialog),r=y.useRef(null),i=m(t,n.contentRef,r);return y.useEffect(()=>{let e=r.current;if(e)return g(e)},[]),(0,b.jsx)(V,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:_(e.onCloseAutoFocus,e=>{e.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:_(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;(t.button===2||n)&&e.preventDefault()}),onFocusOutside:_(e.onFocusOutside,e=>e.preventDefault())})}),B=y.forwardRef((e,t)=>{let n=T(L,e.__scopeDialog),r=y.useRef(!1),i=y.useRef(!1);return(0,b.jsx)(V,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})}),V=y.forwardRef((e,t)=>{let{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=e,s=T(L,n);return h(),(0,b.jsx)(b.Fragment,{children:(0,b.jsx)(l,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,b.jsx)(u,{role:`dialog`,id:s.contentId,"aria-describedby":s.descriptionId,"aria-labelledby":s.titleId,"data-state":J(s.open),...o,ref:t,deferPointerDownOutside:!0,onDismiss:()=>s.onOpenChange(!1)})})})}),H=`DialogTitle`,U=y.forwardRef((e,t)=>{let{__scopeDialog:n,...r}=e,i=T(H,n);return(0,b.jsx)(p.h2,{id:i.titleId,...r,ref:t})});U.displayName=H;var W=`DialogDescription`,G=y.forwardRef((e,t)=>{let{__scopeDialog:n,...r}=e,i=T(W,n);return(0,b.jsx)(p.p,{id:i.descriptionId,...r,ref:t})});G.displayName=W;var K=`DialogClose`,q=y.forwardRef((e,t)=>{let{__scopeDialog:n,...r}=e,i=T(K,n);return(0,b.jsx)(p.button,{type:`button`,...r,ref:t,onClick:_(e.onClick,()=>i.onOpenChange(!1))})});q.displayName=K;function J(e){return e?`open`:`closed`}var Y=typeof document>`u`?y.useEffect:y.useLayoutEffect;function X(e){let t=e.activeElement;return!t||t===e.body||t===e.documentElement||!(`focus`in t)||typeof t.focus!=`function`?null:t}function Z(e,t){!e||!e.isConnected||e.ownerDocument!==t||e.focus({preventScroll:!0})}function Q({open:e,title:t,description:n,confirmLabel:r,confirmVariant:i=`danger`,onConfirm:a,onOpenChange:o}){let[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),d=(0,y.useRef)(null),f=(0,y.useRef)(!1);Y(()=>{e&&!f.current&&(d.current=X(document)),f.current=e},[e]),(0,y.useEffect)(()=>{e||(c(!1),u(null))},[e]);async function p(){c(!0),u(null);try{await a(),o(!1)}catch(e){u(e instanceof Error?e.message:String(e)),c(!1)}}return(0,b.jsx)(E,{open:e,onOpenChange:e=>{!e&&!s&&o(!1)},children:(0,b.jsxs)(M,{children:[(0,b.jsx)(P,{className:`fixed inset-0 z-50 bg-chocolate/35 backdrop-blur-[2px] data-[state=closed]:animate-out data-[state=open]:animate-in data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`}),(0,b.jsxs)(R,{className:`fixed left-1/2 top-1/2 z-50 grid w-[calc(100%-2rem)] max-w-md -translate-x-1/2 -translate-y-1/2 gap-4 rounded-[16px] border border-frost bg-snow p-5 text-chocolate shadow-baziu-lg outline-none data-[state=closed]:animate-out data-[state=open]:animate-in data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`,onCloseAutoFocus:e=>{e.preventDefault();let t=d.current;d.current=null,Z(t,document)},onEscapeKeyDown:e=>{s&&e.preventDefault()},onPointerDownOutside:e=>{s&&e.preventDefault()},children:[(0,b.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,b.jsx)(U,{className:`font-serif text-xl text-chocolate`,children:t}),(0,b.jsx)(G,{asChild:!0,children:(0,b.jsx)(`div`,{className:`text-sm leading-6 text-mocha`,children:n})})]}),l&&(0,b.jsx)(`p`,{role:`alert`,className:`rounded-md bg-danger/10 px-3 py-2 text-sm text-danger`,children:l}),(0,b.jsxs)(`div`,{className:`flex flex-col-reverse gap-2 border-t border-frost pt-4 sm:flex-row sm:justify-end`,children:[(0,b.jsx)(v,{variant:`ghost`,disabled:s,onClick:()=>o(!1),children:`cancel`}),(0,b.jsx)(v,{variant:i,disabled:s,onClick:()=>void p(),children:s?`working…`:r})]})]})]})})}export{G as a,U as c,R as i,E as n,P as o,q as r,M as s,Q as t};
|