@mugwork/mug 0.1.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.
Files changed (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +251 -0
  3. package/dist/explorer.js +3 -0
  4. package/dist/packages/email-template/src/email-template.d.ts +18 -0
  5. package/dist/packages/email-template/src/email-template.js +74 -0
  6. package/dist/packages/email-template/src/index.d.ts +1 -0
  7. package/dist/packages/email-template/src/index.js +1 -0
  8. package/dist/packages/surface-renderer/src/form-renderer.d.ts +117 -0
  9. package/dist/packages/surface-renderer/src/form-renderer.js +719 -0
  10. package/dist/packages/surface-renderer/src/index.d.ts +4 -0
  11. package/dist/packages/surface-renderer/src/index.js +2 -0
  12. package/dist/packages/surface-renderer/src/portal-renderer.d.ts +177 -0
  13. package/dist/packages/surface-renderer/src/portal-renderer.js +1089 -0
  14. package/dist/packages/surface-renderer/src/workspace-home.d.ts +46 -0
  15. package/dist/packages/surface-renderer/src/workspace-home.js +345 -0
  16. package/dist/runtime/agent-types.d.ts +48 -0
  17. package/dist/runtime/agent-types.js +3 -0
  18. package/dist/runtime/ai-router.d.ts +32 -0
  19. package/dist/runtime/ai-router.js +112 -0
  20. package/dist/runtime/app.d.ts +6 -0
  21. package/dist/runtime/app.js +399 -0
  22. package/dist/runtime/chunker.d.ts +6 -0
  23. package/dist/runtime/chunker.js +30 -0
  24. package/dist/runtime/context.d.ts +115 -0
  25. package/dist/runtime/context.js +440 -0
  26. package/dist/runtime/do/workspace-database.d.ts +10 -0
  27. package/dist/runtime/do/workspace-database.js +199 -0
  28. package/dist/runtime/form-types.d.ts +143 -0
  29. package/dist/runtime/form-types.js +1 -0
  30. package/dist/runtime/runtime.d.ts +9 -0
  31. package/dist/runtime/runtime.js +7 -0
  32. package/dist/runtime/source-types.d.ts +15 -0
  33. package/dist/runtime/source-types.js +1 -0
  34. package/dist/runtime/source.d.ts +70 -0
  35. package/dist/runtime/source.js +21 -0
  36. package/dist/runtime/sync-runtime.d.ts +10 -0
  37. package/dist/runtime/sync-runtime.js +185 -0
  38. package/dist/runtime/types.d.ts +21 -0
  39. package/dist/runtime/types.js +1 -0
  40. package/dist/runtime/workflow-entrypoint.d.ts +31 -0
  41. package/dist/runtime/workflow-entrypoint.js +1297 -0
  42. package/dist/runtime/workflow.d.ts +285 -0
  43. package/dist/runtime/workflow.js +1008 -0
  44. package/dist/src/cli.d.ts +2 -0
  45. package/dist/src/cli.js +44116 -0
  46. package/dist/src/commands/ai-gateway-route.d.ts +24 -0
  47. package/dist/src/commands/ai-gateway-route.js +192 -0
  48. package/dist/src/commands/auth.d.ts +1 -0
  49. package/dist/src/commands/auth.js +42 -0
  50. package/dist/src/commands/billing.d.ts +6 -0
  51. package/dist/src/commands/billing.js +76 -0
  52. package/dist/src/commands/brain.d.ts +1 -0
  53. package/dist/src/commands/brain.js +194 -0
  54. package/dist/src/commands/demo.d.ts +12 -0
  55. package/dist/src/commands/demo.js +147 -0
  56. package/dist/src/commands/deploy.d.ts +1 -0
  57. package/dist/src/commands/deploy.js +1052 -0
  58. package/dist/src/commands/dev.d.ts +14 -0
  59. package/dist/src/commands/dev.js +2818 -0
  60. package/dist/src/commands/form.d.ts +8 -0
  61. package/dist/src/commands/form.js +396 -0
  62. package/dist/src/commands/init.d.ts +1 -0
  63. package/dist/src/commands/init.js +139 -0
  64. package/dist/src/commands/issue.d.ts +7 -0
  65. package/dist/src/commands/issue.js +191 -0
  66. package/dist/src/commands/login.d.ts +9 -0
  67. package/dist/src/commands/login.js +163 -0
  68. package/dist/src/commands/logs.d.ts +8 -0
  69. package/dist/src/commands/logs.js +113 -0
  70. package/dist/src/commands/portal.d.ts +2 -0
  71. package/dist/src/commands/portal.js +111 -0
  72. package/dist/src/commands/pull.d.ts +3 -0
  73. package/dist/src/commands/pull.js +184 -0
  74. package/dist/src/commands/push.d.ts +4 -0
  75. package/dist/src/commands/push.js +183 -0
  76. package/dist/src/commands/run.d.ts +6 -0
  77. package/dist/src/commands/run.js +91 -0
  78. package/dist/src/commands/secret.d.ts +7 -0
  79. package/dist/src/commands/secret.js +105 -0
  80. package/dist/src/commands/shutdown.d.ts +1 -0
  81. package/dist/src/commands/shutdown.js +46 -0
  82. package/dist/src/commands/sql.d.ts +8 -0
  83. package/dist/src/commands/sql.js +142 -0
  84. package/dist/src/commands/status.d.ts +5 -0
  85. package/dist/src/commands/status.js +39 -0
  86. package/dist/src/commands/sync.d.ts +7 -0
  87. package/dist/src/commands/sync.js +991 -0
  88. package/dist/src/commands/usage.d.ts +6 -0
  89. package/dist/src/commands/usage.js +78 -0
  90. package/dist/src/commands/webhooks.d.ts +1 -0
  91. package/dist/src/commands/webhooks.js +102 -0
  92. package/dist/src/commands/workspace.d.ts +23 -0
  93. package/dist/src/commands/workspace.js +590 -0
  94. package/dist/src/connector-migration.d.ts +20 -0
  95. package/dist/src/connector-migration.js +43 -0
  96. package/dist/src/connector-parser.d.ts +14 -0
  97. package/dist/src/connector-parser.js +94 -0
  98. package/dist/src/connector-service/discover.d.ts +37 -0
  99. package/dist/src/connector-service/discover.js +79 -0
  100. package/dist/src/connector-service/gather.d.ts +22 -0
  101. package/dist/src/connector-service/gather.js +89 -0
  102. package/dist/src/connector-service/init.d.ts +14 -0
  103. package/dist/src/connector-service/init.js +109 -0
  104. package/dist/src/connector-service/scaffold.d.ts +17 -0
  105. package/dist/src/connector-service/scaffold.js +194 -0
  106. package/dist/src/connector-service/spec-storage.d.ts +8 -0
  107. package/dist/src/connector-service/spec-storage.js +48 -0
  108. package/dist/src/connector-service/types.d.ts +57 -0
  109. package/dist/src/connector-service/types.js +2 -0
  110. package/dist/src/connector-service/verify.d.ts +24 -0
  111. package/dist/src/connector-service/verify.js +575 -0
  112. package/dist/src/email-template.d.ts +2 -0
  113. package/dist/src/email-template.js +1 -0
  114. package/dist/src/manifest.d.ts +31 -0
  115. package/dist/src/manifest.js +25 -0
  116. package/dist/src/mug-icon.d.ts +1 -0
  117. package/dist/src/mug-icon.js +12 -0
  118. package/dist/src/slack-manifest.d.ts +119 -0
  119. package/dist/src/slack-manifest.js +163 -0
  120. package/dist/src/source-migration.d.ts +20 -0
  121. package/dist/src/source-migration.js +43 -0
  122. package/dist/src/surface-renderer.d.ts +5 -0
  123. package/dist/src/surface-renderer.js +3 -0
  124. package/dist/src/templates.d.ts +3 -0
  125. package/dist/src/templates.js +48 -0
  126. package/dist/src/version-check.d.ts +1 -0
  127. package/dist/src/version-check.js +28 -0
  128. package/dist/src/workflow-parser.d.ts +95 -0
  129. package/dist/src/workflow-parser.js +526 -0
  130. package/dist/worker/src/agent-types.d.ts +27 -0
  131. package/dist/worker/src/agent-types.js +3 -0
  132. package/dist/worker/src/source-types.d.ts +14 -0
  133. package/dist/worker/src/source-types.js +1 -0
  134. package/package.json +90 -0
  135. package/src/data/model-capabilities.json +171 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mug
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,251 @@
1
+ ![Mug](https://pub-b8207fa7ce394b47b9fc818bd5c45470.r2.dev/images/mug-cli-github-banner.png)
2
+
3
+ # Mug
4
+
5
+ [Mug](https://mug.work) is an AI automation platform for building deployed agents, real code workflows, & headless web surfaces for everyday business, integrated with any API, and accessed via email, SMS, & Slack — all built locally using Claude Code, Codex, & Cursor.
6
+
7
+ Ship complete AI operating systems for any business with the coding agent subscription you already pay for.
8
+
9
+ ---
10
+
11
+ # Get Started with Mug CLI Agent Kit
12
+
13
+ ## Install
14
+ Mug's CLI Agent Kit gives Claude, Codex, & Cursor everything they need to build anything on Mug — agentic CLI, CLAUDE.md/AGENTS.md, skills that teach the entire Mug platform, and the entire Mug docs library.
15
+
16
+
17
+ ### Single-command global install
18
+ ```
19
+ npm install -g @mugwork/mug
20
+ ```
21
+
22
+ ### Prompt your agent to install & learn how to use Mug in one shot
23
+ ```
24
+ Install the Mug.work CLI Agent Kit by running `npm install -g @mugwork/mug`. After install, run `mug start`, then review the unpacked agent kit materials to help me get started.
25
+ ```
26
+
27
+ ## Human CLI
28
+
29
+ Mug is meant to be driven by a coding agent like Claude, Codex, or Cursor, but we wanted the CLI to be usable for humans too. Open a terminal and run `mug` from any directory. You'll be prompted to log in if you're not already, then the CLI walks you through everything interactively. Arrow keys to navigate, enter to select. No commands to memorize.
30
+
31
+ Scaffold a fresh local workspace or clone an existing workspace from the cloud. Navigate into a workspace to launch the Mug dev server + workspace explorer UI, validate + deploy workspaces, browse the entire contents of a workspace, and even manage billing.
32
+
33
+ ## Agentic CLI
34
+
35
+ AI coding agents like Claude, Codex, & Cursor are who the Mug CLI was really designed for. They drive the CLI via bash commands:
36
+
37
+ ```bash
38
+ mug login # authenticate
39
+ mug init <name> # create new workspace
40
+ mug clone # clone existing workspace from cloud
41
+ mug dev # start local dev server
42
+ mug deploy # deploy to production
43
+ mug --help # full command reference
44
+ ```
45
+
46
+ Your coding agent can build everything the Mug platform supports by using the CLI and the agent kit materials bundled in your workspace.
47
+
48
+ ## Set up a new workspace
49
+
50
+ ### Manually via terminal
51
+ 1. Run `mug` from any directory
52
+ 2. Select `Create New Workspace` from menu
53
+ 3. Create or navigate to the folder you want to put your workspace in
54
+ 4. Select `Scaffold workspace here` from menu
55
+
56
+ Now launch your coding agent from the workspace directory and it will automatically pick up all agent kit materials in the workspace: CLAUDE.md/AGENTS.md, skills, and Mug docs.
57
+
58
+ ### Prompt your agent
59
+ ```
60
+ Run `mug init` to create a new Mug workspace called [name of your new workspace] in [directory you want workspace in]
61
+ ```
62
+
63
+ **IMPORTANT**: After agent scaffolds your new workspace, re-launch your coding agent from the new workspace directory so it automatically picks up all agent kit materials in the workspace: CLAUDE.md/AGENTS.md, skills, and Mug docs.
64
+
65
+ ## Auto Update
66
+
67
+ The Mug CLI keeps workspaces in sync with Mug platform improvements by automatically updating global CLI npm package and all agent kit materials: CLAUDE.md/AGENTS.md, skills, and Mug docs.
68
+
69
+ ## Start
70
+
71
+ Use /start skill for a quick guide on what you and your agent can do with Mug.
72
+
73
+ ---
74
+
75
+ # What's In a Workspace
76
+
77
+ **Workspaces are repos** you build locally, then deploy to tenant-isolated Cloudflare via `mug deploy`. Optionally sync your workspace to GitHub for a backup with full git functionality.
78
+
79
+ ```
80
+ acme-workspace/
81
+ ├── .agents/skills/ # Agent skills (Codex, etc.)
82
+ ├── .claude/skills/ # Claude Code skills
83
+ ├── .cursor/rules/ # Cursor IDE rules
84
+ ├── .mug/docs/ # Platform API reference
85
+ ├── agents/ # AI agents
86
+ │ ├── dispatch-agent/
87
+ │ │ ├── agent.json # Config: model, tools, caps, memory
88
+ │ │ ├── BRAIN.db # Persistent agent memory
89
+ │ │ ├── SOUL.md # Core identity & instructions
90
+ │ │ └── skills/ # Agent-specific skills
91
+ │ ├── invoice-agent/
92
+ │ │ └── ...
93
+ │ └── shared-skills/ # Skills available to all agents
94
+ ├── connectors/ # Data sync from external APIs
95
+ ├── databases/ # Local SQLite (synced to production)
96
+ ├── files/ # Static files synced to R2
97
+ ├── surfaces/ # Forms, portals, dashboards
98
+ ├── workflows/ # Scheduled & triggered automation
99
+ ├── AGENTS.md # Auto-generated agent instructions
100
+ ├── CLAUDE.md # Auto-generated — teaches AI agents Mug's API
101
+ ├── mug.json # Workspace config
102
+ ├── slack.json # Slack app config
103
+ └── package.json
104
+ ```
105
+
106
+ - Workspaces are scaffolded via `mug init` or `mug clone` and kept up-to-date with Mug platform via `mug update`
107
+ - Mug primitives live in 4 top-level directories — `/connectors`, `/workflows`, `/agents`, & `/surfaces`
108
+ - Workspace files and databases live in `/files` and `/databases` and are manually push/pulled to/from cloud via `mug push` and `mug pull`
109
+ - Agent Kit ships with all Mug platform skills and docs so cold agents learn how to build anything in Mug in minutes
110
+ - TypeScript for automation workflows, SQL for data, JSON for configuring AI agents and surfaces, and Markdown for agent instructions and skills
111
+
112
+ ---
113
+
114
+ # Custom Deployed Agents
115
+
116
+ **Mug agents run 150+ models supported by [Cloudflare AI Gateway](https://developers.cloudflare.com/ai/models/)** — Anthropic, OpenAI, Google, Meta, DeepSeek, & more. Unlike always-on agents that burn tokens waiting for work, Mug agents turn on when a workflow pings them, then go back to sleep.
117
+
118
+ ```
119
+ dispatch-agent/
120
+ ├── agent.json # Config: model, tools, caps, memory
121
+ ├── BRAIN.db # Persistent agent memory
122
+ ├── SOUL.md # Core identity & instructions
123
+ └── skills/ # Agent-specific skills
124
+ ```
125
+
126
+ ```json
127
+ {
128
+ "model": { "fast": "claude-haiku", "balanced": "claude-sonnet", "powerful": "claude-opus" },
129
+ "tools": ["query", "search", "notify", "http", "trigger_workflow"],
130
+ "memory": true,
131
+ "caps": { "maxTurns": 30, "maxCredits": 200, "maxDuration": 300 },
132
+ "chat": true
133
+ }
134
+ ```
135
+
136
+ - Each agent has a SOUL.md for identity, a BRAIN.db database for memory, and a folder of skills — plus shared skills available to every agent in the workspace
137
+ - Agents write journal entries during work to build their own "mantra" — a self-authored summary of critical context they accumulate over their lifetime
138
+ - Agents can query data with SQL, run vector search and RAG, send emails, SMS, and Slack messages, call APIs, and trigger other workflows
139
+ - Set fast / balanced / powerful model tiers and Mug routes to the right one based on task complexity — or bring your own API keys to skip Mug's credit system entirely
140
+
141
+ ---
142
+
143
+ # TypeScript Automation Workflows
144
+
145
+ **Workflows are TypeScript functions** that run on a schedule, trigger automatically when data changes, or get invoked by an AI agent — written by you and your coding agent.
146
+
147
+ ```typescript
148
+ workflow("weekly-invoice-followup", async (ctx) => {
149
+ const overdue = await ctx.query("finance", "SELECT * FROM invoices WHERE due_date < date('now') AND status = 'unpaid'");
150
+ const draft = await ctx.ai("balanced", { prompt: `Draft follow-up emails for these invoices: ${JSON.stringify(overdue)}`, system: "You are a collections specialist." });
151
+ await ctx.notify.email({ to: "accounting@acme.com", subject: "Overdue Invoice Report", message: draft });
152
+ }, { schedule: { weekday: "friday", time: "09:00" } });
153
+ ```
154
+
155
+ - Schedule workflows to run when you need them — Fridays at 9am, 3rd Tuesday of the month, every 15 mins from 2-4pm on Wednesdays
156
+ - Workflows can fire when synced data changes, when an inbound webhook arrives, or when an agent receives an email to their custom email address
157
+ - Workflows can be made available in Slack as slash commands
158
+ - Mug agents can run as workflow steps — reading data, making decisions, and routing the workflow down different branches based on what they find
159
+ - Workflows can push data back to any connected API via `ctx.action()` — Mug automatically snapshots every record before changing it, so any action can be rolled back
160
+ - Every workflow step is checkpointed with durable execution — if something fails mid-run, only that step retries and all prior work is preserved
161
+
162
+ ---
163
+
164
+ # Universal API Sync Connectors
165
+
166
+ **Mug connects to any API** you and your coding agent can build a connector for. Sync a read-only copy of live business data into local SQLite to build agents and workflows on top.
167
+
168
+ ```typescript
169
+ source({
170
+ name: "quickbooks",
171
+ database: "finance",
172
+ tables: [{
173
+ name: "invoices",
174
+ primaryKey: "Id",
175
+ fetch: async (ctx) => {
176
+ const res = await ctx.http("https://quickbooks.api.intuit.com/v3/company/...");
177
+ return res.json.QueryResponse.Invoice;
178
+ }
179
+ }]
180
+ });
181
+ ```
182
+
183
+ - Mug CLI ships with a multi-step connector skill that walks your agent through researching any API and building a connector from scratch
184
+ - Connectors pull data on the interval you set — up to every minute on Business plans — and only process records that have changed since last sync
185
+ - Synced data is stored as SQLite, a format AI agents work with natively — once data is in Mug, it's simple SQL to join records across any table or database, regardless of the source
186
+ - Upload files and folders directly in your workspace to be used by agents and utilized in workflows alongside business data
187
+ - Any external edits to data happen through separate workflows outside the sync process — Mug never bulk updates external data
188
+ - Mug crowdsources and maintains a pre-built connector library [here](https://github.com/mugwork/mug-connectors)
189
+
190
+ ---
191
+
192
+ # Headless Web Surfaces
193
+
194
+ **No one wants a new app.** Mug uses headless "click and close" web surfaces to reach people where they already are, on any device — forms, portals, dashboards, etc — all configured with just a few lines of JSON, no UI design necessary.
195
+
196
+ [Click here to demo surfaces](https://demo.mug.work)
197
+
198
+ ```json
199
+ {
200
+ "type": "form",
201
+ "title": "Time Off Request",
202
+ "access": { "mode": "auth", "table": { "database": "hr", "table": "employees", "column": "email" } },
203
+ "fields": [
204
+ { "name": "type", "label": "Type", "type": "select", "options": ["PTO", "Sick", "Personal"] },
205
+ { "name": "start_date", "label": "Start Date", "type": "date" },
206
+ { "name": "notes", "label": "Notes", "type": "textarea" }
207
+ ],
208
+ "handler": "handle-time-off"
209
+ }
210
+ ```
211
+
212
+ - Surfaces support user login via email or SMS, letting you build personalized, secure interfaces for each user
213
+ - Surfaces are progressive web apps — users are auto-prompted to save to their home screen for an app-like experience, without the app store
214
+ - Mug has Resend and Twilio built-in to notify users across email, SMS, and Slack — bring your own API keys for unlimited sends
215
+ - Custom branding with your logo and accent color applied across all surfaces and emails
216
+ - Share surfaces with stakeholders in demo mode — pre-authenticated links with notification routing controls
217
+
218
+ ---
219
+
220
+ # Automatic Slack App
221
+
222
+ **Every agent and workflow you create in Mug automatically gets wrapped in a custom Slack app** you can install in a couple clicks — no App Directory review needed.
223
+
224
+ ```typescript
225
+ workflow("handle-approve", async (ctx) => {
226
+ const { userId, actionValue } = ctx.params;
227
+ await ctx.exec("ops", "UPDATE requests SET status = 'approved' WHERE id = ?", [actionValue]);
228
+ await ctx.notify.slack({ to: "#approvals", message: `Request ${actionValue} approved by <@${userId}>` });
229
+ }, { inbound: "slack" });
230
+ ```
231
+
232
+ - DM your Mug agents directly in Slack for threaded AI conversations, with multi-agent routing via @mentions
233
+ - Trigger any workflow with a slash command — someone types the command, the workflow runs
234
+ - Use Slack's Block Kit for interactive flows inside Slack — approval buttons, modals, rich formatting
235
+ - Slack user and channel data auto-syncs into your workspace database for use in workflows
236
+ - Mug handles all the OAuth, event routing, token rotation, and manifest API deployment — you just write the TypeScript
237
+
238
+ ---
239
+
240
+ # Links
241
+
242
+ - [Mug.work](https://mug.work) — product site
243
+ - [Mug Connectors](https://github.com/mugwork/mug-connectors) — ready-to-use API sync connectors for Mug
244
+ - [Demo Surfaces](https://demo.mug.work) — interactive headless web surface examples
245
+
246
+ ---
247
+
248
+ # Support / Contact
249
+
250
+ - Contact: Founder / Chief Vibe Coder — Tyler Berggren | [tyler@mug.work](mailto:tyler@mug.work) | [LinkedIn](https://www.linkedin.com/in/tyler-berggren)
251
+ - [Open an issue](https://github.com/mugwork/mug/issues)
@@ -0,0 +1,3 @@
1
+ var ue,C,vt,_n,z,ft,_t,bt,Ne,Se,ie,yt,qe,Oe,je,wt,Le={},Ce=[],bn=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,de=Array.isArray;function O(t,n){for(var s in n)t[s]=n[s];return t}function ze(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function De(t,n,s){var a,o,r,i={};for(r in n)r=="key"?a=n[r]:r=="ref"?o=n[r]:i[r]=n[r];if(arguments.length>2&&(i.children=arguments.length>3?ue.call(arguments,2):s),typeof t=="function"&&t.defaultProps!=null)for(r in t.defaultProps)i[r]===void 0&&(i[r]=t.defaultProps[r]);return ce(t,i,a,o,null)}function ce(t,n,s,a,o){var r={type:t,props:n,key:s,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++vt,__i:-1,__u:0};return o==null&&C.vnode!=null&&C.vnode(r),r}function L(t){return t.children}function ne(t,n){this.props=t,this.context=n}function se(t,n){if(n==null)return t.__?se(t.__,t.__i+1):null;for(var s;n<t.__k.length;n++)if((s=t.__k[n])!=null&&s.__e!=null)return s.__e;return typeof t.type=="function"?se(t):null}function yn(t){if(t.__P&&t.__d){var n=t.__v,s=n.__e,a=[],o=[],r=O({},n);r.__v=n.__v+1,C.vnode&&C.vnode(r),Ge(t.__P,r,n,t.__n,t.__P.namespaceURI,32&n.__u?[s]:null,a,s??se(n),!!(32&n.__u),o),r.__v=n.__v,r.__.__k[r.__i]=r,Lt(a,r,o),n.__e=n.__=null,r.__e!=s&&kt(r)}}function kt(t){if((t=t.__)!=null&&t.__c!=null)return t.__e=t.__c.base=null,t.__k.some(function(n){if(n!=null&&n.__e!=null)return t.__e=t.__c.base=n.__e}),kt(t)}function We(t){(!t.__d&&(t.__d=!0)&&z.push(t)&&!$e.__r++||ft!=C.debounceRendering)&&((ft=C.debounceRendering)||_t)($e)}function $e(){try{for(var t,n=1;z.length;)z.length>n&&z.sort(bt),t=z.shift(),n=z.length,yn(t)}finally{z.length=$e.__r=0}}function xt(t,n,s,a,o,r,i,l,d,u,g){var c,m,p,w,b,y,f,v=a&&a.__k||Ce,k=n.length;for(d=wn(s,n,v,d,k),c=0;c<k;c++)(p=s.__k[c])!=null&&(m=p.__i!=-1&&v[p.__i]||Le,p.__i=c,y=Ge(t,p,m,o,r,i,l,d,u,g),w=p.__e,p.ref&&m.ref!=p.ref&&(m.ref&&Ke(m.ref,null,p),g.push(p.ref,p.__c||w,p)),b==null&&w!=null&&(b=w),(f=!!(4&p.__u))||m.__k===p.__k?(d=St(p,d,t,f),f&&m.__e&&(m.__e=null)):typeof p.type=="function"&&y!==void 0?d=y:w&&(d=w.nextSibling),p.__u&=-7);return s.__e=b,d}function wn(t,n,s,a,o){var r,i,l,d,u,g=s.length,c=g,m=0;for(t.__k=new Array(o),r=0;r<o;r++)(i=n[r])!=null&&typeof i!="boolean"&&typeof i!="function"?(typeof i=="string"||typeof i=="number"||typeof i=="bigint"||i.constructor==String?i=t.__k[r]=ce(null,i,null,null,null):de(i)?i=t.__k[r]=ce(L,{children:i},null,null,null):i.constructor===void 0&&i.__b>0?i=t.__k[r]=ce(i.type,i.props,i.key,i.ref?i.ref:null,i.__v):t.__k[r]=i,d=r+m,i.__=t,i.__b=t.__b+1,l=null,(u=i.__i=kn(i,s,d,c))!=-1&&(c--,(l=s[u])&&(l.__u|=2)),l==null||l.__v==null?(u==-1&&(o>g?m--:o<g&&m++),typeof i.type!="function"&&(i.__u|=4)):u!=d&&(u==d-1?m--:u==d+1?m++:(u>d?m--:m++,i.__u|=4))):t.__k[r]=null;if(c)for(r=0;r<g;r++)(l=s[r])!=null&&(2&l.__u)==0&&(l.__e==a&&(a=se(l)),$t(l,l));return a}function St(t,n,s,a){var o,r;if(typeof t.type=="function"){for(o=t.__k,r=0;o&&r<o.length;r++)o[r]&&(o[r].__=t,n=St(o[r],n,s,a));return n}t.__e!=n&&(a&&(n&&t.type&&!n.parentNode&&(n=se(t)),s.insertBefore(t.__e,n||null)),n=t.__e);do n=n&&n.nextSibling;while(n!=null&&n.nodeType==8);return n}function He(t,n){return n=n||[],t==null||typeof t=="boolean"||(de(t)?t.some(function(s){He(s,n)}):n.push(t)),n}function kn(t,n,s,a){var o,r,i,l=t.key,d=t.type,u=n[s],g=u!=null&&(2&u.__u)==0;if(u===null&&l==null||g&&l==u.key&&d==u.type)return s;if(a>(g?1:0)){for(o=s-1,r=s+1;o>=0||r<n.length;)if((u=n[i=o>=0?o--:r++])!=null&&(2&u.__u)==0&&l==u.key&&d==u.type)return i}return-1}function gt(t,n,s){n[0]=="-"?t.setProperty(n,s??""):t[n]=s==null?"":typeof s!="number"||bn.test(n)?s:s+"px"}function xe(t,n,s,a,o){var r,i;e:if(n=="style")if(typeof s=="string")t.style.cssText=s;else{if(typeof a=="string"&&(t.style.cssText=a=""),a)for(n in a)s&&n in s||gt(t.style,n,"");if(s)for(n in s)a&&s[n]==a[n]||gt(t.style,n,s[n])}else if(n[0]=="o"&&n[1]=="n")r=n!=(n=n.replace(yt,"$1")),i=n.toLowerCase(),n=i in t||n=="onFocusOut"||n=="onFocusIn"?i.slice(2):n.slice(2),t.l||(t.l={}),t.l[n+r]=s,s?a?s[ie]=a[ie]:(s[ie]=qe,t.addEventListener(n,r?je:Oe,r)):t.removeEventListener(n,r?je:Oe,r);else{if(o=="http://www.w3.org/2000/svg")n=n.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(n!="width"&&n!="height"&&n!="href"&&n!="list"&&n!="form"&&n!="tabIndex"&&n!="download"&&n!="rowSpan"&&n!="colSpan"&&n!="role"&&n!="popover"&&n in t)try{t[n]=s??"";break e}catch{}typeof s=="function"||(s==null||s===!1&&n[4]!="-"?t.removeAttribute(n):t.setAttribute(n,n=="popover"&&s==1?"":s))}}function ht(t){return function(n){if(this.l){var s=this.l[n.type+t];if(n[Se]==null)n[Se]=qe++;else if(n[Se]<s[ie])return;return s(C.event?C.event(n):n)}}}function Ge(t,n,s,a,o,r,i,l,d,u){var g,c,m,p,w,b,y,f,v,k,_,F,A,T,I,M=n.type;if(n.constructor!==void 0)return null;128&s.__u&&(d=!!(32&s.__u),r=[l=n.__e=s.__e]),(g=C.__b)&&g(n);e:if(typeof M=="function")try{if(f=n.props,v=M.prototype&&M.prototype.render,k=(g=M.contextType)&&a[g.__c],_=g?k?k.props.value:g.__:a,s.__c?y=(c=n.__c=s.__c).__=c.__E:(v?n.__c=c=new M(f,_):(n.__c=c=new ne(f,_),c.constructor=M,c.render=Sn),k&&k.sub(c),c.state||(c.state={}),c.__n=a,m=c.__d=!0,c.__h=[],c._sb=[]),v&&c.__s==null&&(c.__s=c.state),v&&M.getDerivedStateFromProps!=null&&(c.__s==c.state&&(c.__s=O({},c.__s)),O(c.__s,M.getDerivedStateFromProps(f,c.__s))),p=c.props,w=c.state,c.__v=n,m)v&&M.getDerivedStateFromProps==null&&c.componentWillMount!=null&&c.componentWillMount(),v&&c.componentDidMount!=null&&c.__h.push(c.componentDidMount);else{if(v&&M.getDerivedStateFromProps==null&&f!==p&&c.componentWillReceiveProps!=null&&c.componentWillReceiveProps(f,_),n.__v==s.__v||!c.__e&&c.shouldComponentUpdate!=null&&c.shouldComponentUpdate(f,c.__s,_)===!1){n.__v!=s.__v&&(c.props=f,c.state=c.__s,c.__d=!1),n.__e=s.__e,n.__k=s.__k,n.__k.some(function(V){V&&(V.__=n)}),Ce.push.apply(c.__h,c._sb),c._sb=[],c.__h.length&&i.push(c);break e}c.componentWillUpdate!=null&&c.componentWillUpdate(f,c.__s,_),v&&c.componentDidUpdate!=null&&c.__h.push(function(){c.componentDidUpdate(p,w,b)})}if(c.context=_,c.props=f,c.__P=t,c.__e=!1,F=C.__r,A=0,v)c.state=c.__s,c.__d=!1,F&&F(n),g=c.render(c.props,c.state,c.context),Ce.push.apply(c.__h,c._sb),c._sb=[];else do c.__d=!1,F&&F(n),g=c.render(c.props,c.state,c.context),c.state=c.__s;while(c.__d&&++A<25);c.state=c.__s,c.getChildContext!=null&&(a=O(O({},a),c.getChildContext())),v&&!m&&c.getSnapshotBeforeUpdate!=null&&(b=c.getSnapshotBeforeUpdate(p,w)),T=g!=null&&g.type===L&&g.key==null?Ct(g.props.children):g,l=xt(t,de(T)?T:[T],n,s,a,o,r,i,l,d,u),c.base=n.__e,n.__u&=-161,c.__h.length&&i.push(c),y&&(c.__E=c.__=null)}catch(V){if(n.__v=null,d||r!=null)if(V.then){for(n.__u|=d?160:128;l&&l.nodeType==8&&l.nextSibling;)l=l.nextSibling;r[r.indexOf(l)]=null,n.__e=l}else{for(I=r.length;I--;)ze(r[I]);Pe(n)}else n.__e=s.__e,n.__k=s.__k,V.then||Pe(n);C.__e(V,n,s)}else r==null&&n.__v==s.__v?(n.__k=s.__k,n.__e=s.__e):l=n.__e=xn(s.__e,n,s,a,o,r,i,d,u);return(g=C.diffed)&&g(n),128&n.__u?void 0:l}function Pe(t){t&&(t.__c&&(t.__c.__e=!0),t.__k&&t.__k.some(Pe))}function Lt(t,n,s){for(var a=0;a<s.length;a++)Ke(s[a],s[++a],s[++a]);C.__c&&C.__c(n,t),t.some(function(o){try{t=o.__h,o.__h=[],t.some(function(r){r.call(o)})}catch(r){C.__e(r,o.__v)}})}function Ct(t){return typeof t!="object"||t==null||t.__b>0?t:de(t)?t.map(Ct):t.constructor!==void 0?null:O({},t)}function xn(t,n,s,a,o,r,i,l,d){var u,g,c,m,p,w,b,y=s.props||Le,f=n.props,v=n.type;if(v=="svg"?o="http://www.w3.org/2000/svg":v=="math"?o="http://www.w3.org/1998/Math/MathML":o||(o="http://www.w3.org/1999/xhtml"),r!=null){for(u=0;u<r.length;u++)if((p=r[u])&&"setAttribute"in p==!!v&&(v?p.localName==v:p.nodeType==3)){t=p,r[u]=null;break}}if(t==null){if(v==null)return document.createTextNode(f);t=document.createElementNS(o,v,f.is&&f),l&&(C.__m&&C.__m(n,r),l=!1),r=null}if(v==null)y===f||l&&t.data==f||(t.data=f);else{if(r=v=="textarea"&&f.defaultValue!=null?null:r&&ue.call(t.childNodes),!l&&r!=null)for(y={},u=0;u<t.attributes.length;u++)y[(p=t.attributes[u]).name]=p.value;for(u in y)p=y[u],u=="dangerouslySetInnerHTML"?c=p:u=="children"||u in f||u=="value"&&"defaultValue"in f||u=="checked"&&"defaultChecked"in f||xe(t,u,null,p,o);for(u in f)p=f[u],u=="children"?m=p:u=="dangerouslySetInnerHTML"?g=p:u=="value"?w=p:u=="checked"?b=p:l&&typeof p!="function"||y[u]===p||xe(t,u,p,y[u],o);if(g)l||c&&(g.__html==c.__html||g.__html==t.innerHTML)||(t.innerHTML=g.__html),n.__k=[];else if(c&&(t.innerHTML=""),xt(n.type=="template"?t.content:t,de(m)?m:[m],n,s,a,v=="foreignObject"?"http://www.w3.org/1999/xhtml":o,r,i,r?r[0]:s.__k&&se(s,0),l,d),r!=null)for(u=r.length;u--;)ze(r[u]);l&&v!="textarea"||(u="value",v=="progress"&&w==null?t.removeAttribute("value"):w!=null&&(w!==t[u]||v=="progress"&&!w||v=="option"&&w!=y[u])&&xe(t,u,w,y[u],o),u="checked",b!=null&&b!=t[u]&&xe(t,u,b,y[u],o))}return t}function Ke(t,n,s){try{if(typeof t=="function"){var a=typeof t.__u=="function";a&&t.__u(),a&&n==null||(t.__u=t(n))}else t.current=n}catch(o){C.__e(o,s)}}function $t(t,n,s){var a,o;if(C.unmount&&C.unmount(t),(a=t.ref)&&(a.current&&a.current!=t.__e||Ke(a,null,n)),(a=t.__c)!=null){if(a.componentWillUnmount)try{a.componentWillUnmount()}catch(r){C.__e(r,n)}a.base=a.__P=null}if(a=t.__k)for(o=0;o<a.length;o++)a[o]&&$t(a[o],n,s||typeof t.type!="function");s||ze(t.__e),t.__c=t.__=t.__e=void 0}function Sn(t,n,s){return this.constructor(t,s)}function Dt(t,n,s){var a,o,r,i;n==document&&(n=document.documentElement),C.__&&C.__(t,n),o=(a=typeof s=="function")?null:s&&s.__k||n.__k,r=[],i=[],Ge(n,t=(!a&&s||n).__k=De(L,null,[t]),o||Le,Le,n.namespaceURI,!a&&s?[s]:o?null:n.firstChild?ue.call(n.childNodes):null,r,!a&&s?s:o?o.__e:n.firstChild,a,i),Lt(r,t,i)}function Ht(t,n,s){var a,o,r,i,l=O({},t.props);for(r in t.type&&t.type.defaultProps&&(i=t.type.defaultProps),n)r=="key"?a=n[r]:r=="ref"?o=n[r]:l[r]=n[r]===void 0&&i!=null?i[r]:n[r];return arguments.length>2&&(l.children=arguments.length>3?ue.call(arguments,2):s),ce(t.type,l,a||t.key,o||t.ref,null)}function Et(t){function n(s){var a,o;return this.getChildContext||(a=new Set,(o={})[n.__c]=this,this.getChildContext=function(){return o},this.componentWillUnmount=function(){a=null},this.shouldComponentUpdate=function(r){this.props.value!=r.value&&a.forEach(function(i){i.__e=!0,We(i)})},this.sub=function(r){a.add(r);var i=r.componentWillUnmount;r.componentWillUnmount=function(){a&&a.delete(r),i&&i.call(r)}}),s.children}return n.__c="__cC"+wt++,n.__=t,n.Provider=n.__l=(n.Consumer=function(s,a){return s.children(a)}).contextType=n,n}ue=Ce.slice,C={__e:function(t,n,s,a){for(var o,r,i;n=n.__;)if((o=n.__c)&&!o.__)try{if((r=o.constructor)&&r.getDerivedStateFromError!=null&&(o.setState(r.getDerivedStateFromError(t)),i=o.__d),o.componentDidCatch!=null&&(o.componentDidCatch(t,a||{}),i=o.__d),i)return o.__E=o}catch(l){t=l}throw t}},vt=0,_n=function(t){return t!=null&&t.constructor===void 0},ne.prototype.setState=function(t,n){var s;s=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=O({},this.state),typeof t=="function"&&(t=t(O({},s),this.props)),t&&O(s,t),t!=null&&this.__v&&(n&&this._sb.push(n),We(this))},ne.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),We(this))},ne.prototype.render=L,z=[],_t=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,bt=function(t,n){return t.__v.__b-n.__v.__b},$e.__r=0,Ne=Math.random().toString(8),Se="__d"+Ne,ie="__a"+Ne,yt=/(PointerCapture)$|Capture$/i,qe=0,Oe=ht(!1),je=ht(!0),wt=0;var pe,E,Je,Rt,me=0,Ut=[],R=C,It=R.__b,Mt=R.__r,Vt=R.diffed,At=R.__c,Tt=R.unmount,Bt=R.__;function Ye(t,n){R.__h&&R.__h(E,t,me||n),me=0;var s=E.__H||(E.__H={__:[],__h:[]});return t>=s.__.length&&s.__.push({}),s.__[t]}function h(t){return me=1,Ln(jt,t)}function Ln(t,n,s){var a=Ye(pe++,2);if(a.t=t,!a.__c&&(a.__=[s?s(n):jt(void 0,n),function(l){var d=a.__N?a.__N[0]:a.__[0],u=a.t(d,l);d!==u&&(a.__N=[u,a.__[1]],a.__c.setState({}))}],a.__c=E,!E.__f)){var o=function(l,d,u){if(!a.__c.__H)return!0;var g=a.__c.__H.__.filter(function(m){return m.__c});if(g.every(function(m){return!m.__N}))return!r||r.call(this,l,d,u);var c=a.__c.props!==l;return g.some(function(m){if(m.__N){var p=m.__[0];m.__=m.__N,m.__N=void 0,p!==m.__[0]&&(c=!0)}}),r&&r.call(this,l,d,u)||c};E.__f=!0;var r=E.shouldComponentUpdate,i=E.componentWillUpdate;E.componentWillUpdate=function(l,d,u){if(this.__e){var g=r;r=void 0,o(l,d,u),r=g}i&&i.call(this,l,d,u)},E.shouldComponentUpdate=o}return a.__N||a.__}function S(t,n){var s=Ye(pe++,3);!R.__s&&Ot(s.__H,n)&&(s.__=t,s.u=n,E.__H.__h.push(s))}function fe(t){return me=5,Nt(function(){return{current:t}},[])}function Nt(t,n){var s=Ye(pe++,7);return Ot(s.__H,n)&&(s.__=t(),s.__H=n,s.__h=t),s.__}function B(t,n){return me=8,Nt(function(){return t},n)}function Cn(){for(var t;t=Ut.shift();){var n=t.__H;if(t.__P&&n)try{n.__h.some(Ee),n.__h.some(Ze),n.__h=[]}catch(s){n.__h=[],R.__e(s,t.__v)}}}R.__b=function(t){E=null,It&&It(t)},R.__=function(t,n){t&&n.__k&&n.__k.__m&&(t.__m=n.__k.__m),Bt&&Bt(t,n)},R.__r=function(t){Mt&&Mt(t),pe=0;var n=(E=t.__c).__H;n&&(Je===E?(n.__h=[],E.__h=[],n.__.some(function(s){s.__N&&(s.__=s.__N),s.u=s.__N=void 0})):(n.__h.some(Ee),n.__h.some(Ze),n.__h=[],pe=0)),Je=E},R.diffed=function(t){Vt&&Vt(t);var n=t.__c;n&&n.__H&&(n.__H.__h.length&&(Ut.push(n)!==1&&Rt===R.requestAnimationFrame||((Rt=R.requestAnimationFrame)||$n)(Cn)),n.__H.__.some(function(s){s.u&&(s.__H=s.u),s.u=void 0})),Je=E=null},R.__c=function(t,n){n.some(function(s){try{s.__h.some(Ee),s.__h=s.__h.filter(function(a){return!a.__||Ze(a)})}catch(a){n.some(function(o){o.__h&&(o.__h=[])}),n=[],R.__e(a,s.__v)}}),At&&At(t,n)},R.unmount=function(t){Tt&&Tt(t);var n,s=t.__c;s&&s.__H&&(s.__H.__.some(function(a){try{Ee(a)}catch(o){n=o}}),s.__H=void 0,n&&R.__e(n,s.__v))};var Ft=typeof requestAnimationFrame=="function";function $n(t){var n,s=function(){clearTimeout(a),Ft&&cancelAnimationFrame(n),setTimeout(t)},a=setTimeout(s,35);Ft&&(n=requestAnimationFrame(s))}function Ee(t){var n=E,s=t.__c;typeof s=="function"&&(t.__c=void 0,s()),E=n}function Ze(t){var n=E;t.__c=t.__(),E=n}function Ot(t,n){return!t||t.length!==n.length||n.some(function(s,a){return s!==t[a]})}function jt(t,n){return typeof n=="function"?n(t):n}var Dn={};function Re(t,n){for(var s in n)t[s]=n[s];return t}function Hn(t,n,s){var a,o=/(?:\?([^#]*))?(#.*)?$/,r=t.match(o),i={};if(r&&r[1])for(var l=r[1].split("&"),d=0;d<l.length;d++){var u=l[d].split("=");i[decodeURIComponent(u[0])]=decodeURIComponent(u.slice(1).join("="))}t=Qe(t.replace(o,"")),n=Qe(n||"");for(var g=Math.max(t.length,n.length),c=0;c<g;c++)if(n[c]&&n[c].charAt(0)===":"){var m=n[c].replace(/(^:|[+*?]+$)/g,""),p=(n[c].match(/[+*?]+$/)||Dn)[0]||"",w=~p.indexOf("+"),b=~p.indexOf("*"),y=t[c]||"";if(!y&&!b&&(p.indexOf("?")<0||w)){a=!1;break}if(i[m]=decodeURIComponent(y),w||b){i[m]=t.slice(c).map(decodeURIComponent).join("/");break}}else if(n[c]!==t[c]){a=!1;break}return(s.default===!0||a!==!1)&&i}function En(t,n){return t.rank<n.rank?1:t.rank>n.rank?-1:t.index-n.index}function Rn(t,n){return t.index=n,t.rank=(function(s){return s.props.default?0:Qe(s.props.path).map(In).join("")})(t),t.props}function Qe(t){return t.replace(/(^\/+|\/+$)/g,"").split("/")}function In(t){return t.charAt(0)==":"?1+"*+?".indexOf(t.charAt(t.length-1))||4:5}var Mn={},Q=[],Wt=[],U=null,qt={url:Xe()},Vn=Et(qt);function Xe(){var t;return""+((t=U&&U.location?U.location:U&&U.getCurrentLocation?U.getCurrentLocation():typeof location<"u"?location:Mn).pathname||"")+(t.search||"")}function et(t,n){return n===void 0&&(n=!1),typeof t!="string"&&t.url&&(n=t.replace,t=t.url),(function(s){for(var a=Q.length;a--;)if(Q[a].canRoute(s))return!0;return!1})(t)&&(function(s,a){a===void 0&&(a="push"),U&&U[a]?U[a](s):typeof history<"u"&&history[a+"State"]&&history[a+"State"](null,null,s)})(t,n?"replace":"push"),zt(t)}function zt(t){for(var n=!1,s=0;s<Q.length;s++)Q[s].routeTo(t)&&(n=!0);return n}function An(t){if(t&&t.getAttribute){var n=t.getAttribute("href"),s=t.getAttribute("target");if(n&&n.match(/^\//g)&&(!s||s.match(/^_?self$/i)))return et(n)}}function Tn(t){return t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation&&t.stopPropagation(),t.preventDefault(),!1}function Bn(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||t.button)){var n=t.target;do if(n.localName==="a"&&n.getAttribute("href")){if(n.hasAttribute("data-native")||n.hasAttribute("native"))return;if(An(n))return Tn(t)}while(n=n.parentNode)}}var Pt=!1;function tt(t){t.history&&(U=t.history),this.state={url:t.url||Xe()}}Re(tt.prototype=new ne,{shouldComponentUpdate:function(t){return t.static!==!0||t.url!==this.props.url||t.onChange!==this.props.onChange},canRoute:function(t){var n=He(this.props.children);return this.g(n,t)!==void 0},routeTo:function(t){this.setState({url:t});var n=this.canRoute(t);return this.p||this.forceUpdate(),n},componentWillMount:function(){this.p=!0},componentDidMount:function(){var t=this;Pt||(Pt=!0,U||addEventListener("popstate",function(){zt(Xe())}),addEventListener("click",Bn)),Q.push(this),U&&(this.u=U.listen(function(n){var s=n.location||n;t.routeTo(""+(s.pathname||"")+(s.search||""))})),this.p=!1},componentWillUnmount:function(){typeof this.u=="function"&&this.u(),Q.splice(Q.indexOf(this),1)},componentWillUpdate:function(){this.p=!0},componentDidUpdate:function(){this.p=!1},g:function(t,n){t=t.filter(Rn).sort(En);for(var s=0;s<t.length;s++){var a=t[s],o=Hn(n,a.props.path,a.props);if(o)return[a,o]}},render:function(t,n){var s,a,o=t.onChange,r=n.url,i=this.c,l=this.g(He(t.children),r);if(l&&(a=Ht(l[0],Re(Re({url:r,matches:s=l[1]},s),{key:void 0,ref:void 0}))),r!==(i&&i.url)){Re(qt,i=this.c={url:r,previous:i&&i.url,current:a,path:a?a.props.path:null,matches:s}),i.router=this,i.active=a?[a]:[];for(var d=Wt.length;d--;)Wt[d]({});typeof o=="function"&&o(i)}return De(Vn.Provider,{value:i},a)}});var H=function(t){return De(t.component,t)};var st=new Set,W=null,nt=null;function rt(){if(W&&(W.readyState===WebSocket.CONNECTING||W.readyState===WebSocket.OPEN))return;let t=`ws://${location.host}/_dev/ws`;W=new WebSocket(t),W.onmessage=n=>{try{let s=JSON.parse(n.data);for(let a of st)a(s)}catch{}},W.onclose=()=>{W=null,nt||(nt=setTimeout(()=>{nt=null,rt()},1e3))},W.onerror=()=>{W?.close()}}rt();function G(t){S(()=>(st.add(t),rt(),()=>{st.delete(t)}),[t])}var he=null,ge=null;function Gt(){return he?Promise.resolve(he):(ge||(ge=fetch("/explorer/api/overview").then(t=>t.json()).then(t=>(he=t,ge=null,t))),ge)}function Fn(){he=null,ge=null}function N(){let[t,n]=h(he),s=B(()=>{Fn(),Gt().then(n)},[]);return S(()=>{Gt().then(n)},[]),G(B(a=>{(a.type==="refresh"||a.type==="reload")&&s()},[s])),t}function re(t){return t<1e3?`${t} B`:t<1e6?`${(t/1e3).toFixed(1)} KB`:`${(t/1e6).toFixed(1)} MB`}var Un=0;function e(t,n,s,a,o,r){n||(n={});var i,l,d=n;if("ref"in d)for(l in d={},n)l=="ref"?i=n[l]:d[l]=n[l];var u={type:t,props:d,key:s,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Un,__i:-1,__u:0,__source:o,__self:r};if(typeof t=="function"&&(i=t.defaultProps))for(l in i)d[l]===void 0&&(d[l]=i[l]);return C.vnode&&C.vnode(u),u}var at=null;function Kt({children:t}){let[n,s]=h(at),[a,o]=h(!1),[r,i]=h(()=>localStorage.getItem("mug-source")||"cloud"),l=fe(null),d=N();S(()=>{at||fetch("/explorer/api/overview").then(m=>m.json()).then(m=>{at=m.workspace,s(m.workspace)}).catch(()=>{})},[]),S(()=>{fetch("/explorer/api/source-preference").then(m=>m.json()).then(m=>{let p=m.global||m.default||"local";i(p),localStorage.setItem("mug-source",p)}).catch(()=>{})},[]);let u=m=>{i(m),localStorage.setItem("mug-source",m),fetch("/explorer/api/source-preference",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({global:m})}).catch(()=>{})};S(()=>{let m=p=>{l.current&&!l.current.contains(p.target)&&o(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]);let g=n?.accentColor||"#71B7FB",c=e(L,{children:[e("a",{href:"/explorer/usage",class:"explorer-nav-link",onClick:()=>o(!1),children:[e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[e("path",{d:"M3 3v16a2 2 0 0 0 2 2h16"}),e("path",{d:"M7 16h8"}),e("path",{d:"M7 11h12"}),e("path",{d:"M7 6h3"})]})," Usage"]}),e("a",{href:"/home",class:"explorer-nav-link",target:"_blank",onClick:()=>o(!1),children:[e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[e("rect",{width:"7",height:"18",x:"3",y:"3",rx:"1"}),e("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),e("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"})]})," Home Surface"]}),e("a",{href:"https://mug.work/account",class:"explorer-nav-link explorer-nav-account",target:"_blank",onClick:()=>o(!1),children:[e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[e("circle",{cx:"12",cy:"12",r:"10"}),e("circle",{cx:"12",cy:"10",r:"3"}),e("path",{d:"M7 20.662V19a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v1.662"})]})," Account"]})]});return e("div",{class:"explorer",children:[e("header",{class:"explorer-header",children:[e("a",{href:"/explorer",class:"explorer-logo",children:[e(Wn,{color:g}),e("span",{class:"explorer-workspace-name",children:jn(n?.name)}),e("span",{class:"explorer-badge",children:"Workspace Explorer"})]}),e("div",{class:"explorer-header-right",children:[e("div",{class:"source-toggle-wrap",children:[e("span",{class:"source-toggle-label",children:"Data"}),e("div",{class:"source-toggle",children:[e("button",{class:r==="local"?"active":"",onClick:()=>u("local"),children:"Local"}),e("button",{class:r==="cloud"?"active":"",onClick:()=>u("cloud"),children:"Cloud"})]})]}),e(On,{overview:d}),e("nav",{class:"explorer-nav explorer-nav-desktop",children:c}),e("div",{class:"explorer-hamburger-wrap",ref:l,children:[e("button",{class:"explorer-hamburger",onClick:()=>o(!a),"aria-label":"Menu",children:a?e("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[e("path",{d:"M18 6 6 18"}),e("path",{d:"m6 6 12 12"})]}):e("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[e("path",{d:"M4 5h16"}),e("path",{d:"M4 12h16"}),e("path",{d:"M4 19h16"})]})}),a&&e("nav",{class:"explorer-hamburger-menu",children:c})]})]})]}),e("main",{class:"explorer-main",children:t})]})}function Nn(t){let n=[];for(let s of t.sources){let a=s.connection?t.connections.find(o=>o.name===s.connection):void 0;n.push({name:s.name,label:s.name,category:"Sync Sources",icon:"cloud-download",href:`/explorer/sources/${s.name}`,meta:[a?.baseUrl,s.database?`\u2192 ${s.database}`:""].filter(Boolean).join(" ")||void 0})}for(let s of t.databases)n.push({name:s.name,label:s.name,category:"Databases",icon:"database",href:`/explorer/databases/${s.name}`,meta:`${s.tableCount} table${s.tableCount!==1?"s":""}`});for(let s of t.workflows)n.push({name:s.name,label:s.name,category:"Workflows",icon:"zap",href:`/explorer/workflows/${s.name}`,meta:s.schedule?`Schedule: ${s.schedule}`:s.webhook?"Webhook":"Manual"});for(let s of t.surfaces)n.push({name:s.name,label:s.title||s.name,category:"Surfaces",icon:"layout-panel-left",href:`/explorer/surfaces/${s.name}`,meta:`${s.type||"form"} \xB7 ${s.accessMode||"public"}`});for(let s of t.agents??[])n.push({name:s.name,label:s.name,category:"Agents",icon:"bot",href:`/explorer/agents/${s.name}`,meta:s.model||"agent"});for(let s of t.files)n.push({name:s.name,label:s.name,category:"Files",icon:"files",href:`/_files/${s.name}`,meta:s.type});return n}function On({overview:t}){let[n,s]=h(""),[a,o]=h(!1),[r,i]=h(-1),l=fe(null),d=t&&n.length>0?Nn(t).filter(m=>{let p=n.toLowerCase();return m.name.toLowerCase().includes(p)||m.label.toLowerCase().includes(p)||m.category.toLowerCase().includes(p)}):[],u=a&&n.length>0,g=m=>{s(""),o(!1),m.startsWith("/_files/")?window.open(m,"_blank"):et(m)},c=m=>{m.key==="ArrowDown"?(m.preventDefault(),i(p=>Math.min(p+1,d.length-1))):m.key==="ArrowUp"?(m.preventDefault(),i(p=>Math.max(p-1,0))):m.key==="Enter"&&r>=0&&d[r]?(m.preventDefault(),g(d[r].href)):m.key==="Escape"&&(s(""),o(!1))};return S(()=>{i(-1)},[n]),S(()=>{let m=p=>{l.current&&!l.current.contains(p.target)&&o(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]),e("div",{class:"explorer-search-wrap",ref:l,children:[e("div",{class:"explorer-search-input-wrap",children:[e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"explorer-search-icon",children:[e("circle",{cx:"11",cy:"11",r:"8"}),e("path",{d:"m21 21-4.3-4.3"})]}),e("input",{type:"text",class:"explorer-search",placeholder:"Search workspace...",value:n,onInput:m=>s(m.target.value),onFocus:()=>o(!0),onKeyDown:c})]}),u&&e("div",{class:"explorer-search-dropdown",children:d.length===0?e("div",{class:"explorer-search-empty",children:"No results"}):d.map((m,p)=>e("div",{class:`explorer-search-result ${p===r?"selected":""}`,onClick:()=>g(m.href),onMouseEnter:()=>i(p),children:[e("i",{"data-lucide":m.icon,class:"explorer-search-result-icon"}),e("div",{class:"explorer-search-result-text",children:[e("span",{class:"explorer-search-result-name",children:m.label}),m.meta&&e("span",{class:"explorer-search-result-meta",children:m.meta})]}),e("span",{class:"explorer-search-result-category",children:m.category})]},m.href))})]})}function jn(t){return t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"..."}function Wn({color:t}){return e("svg",{width:"28",height:"36",viewBox:"0 0 291 371",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:"flex-shrink:0",children:[e("path",{d:"M134.129 122.279L140.915 122.8L141.155 124.478L141.394 126.157L151.534 126.674L161.674 127.191L167.245 128.392L172.817 129.593L176.743 130.899L180.668 132.206L179.403 132.915L178.139 133.624L170.306 134.807L162.472 135.99L156.284 135.995L150.097 136V138.406V140.813L103.591 140.606L57.0848 140.4L56.8325 138.2L56.5794 136L51.2438 135.984L45.9073 135.968L40.3186 135.187L34.7299 134.406L30.9376 133.523L27.1452 132.641V131.987V131.334L34.1311 129.714L41.117 128.094L47.362 127.247L53.6078 126.4H59.5374H65.4678V124.438V122.476L70.4577 122.192L75.4477 121.908L101.395 121.834L127.343 121.759L134.129 122.279Z",fill:t}),e("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M3.07464 136.078L5.58875 136.957V137.573V138.189L10.5787 139.553L15.5686 140.917L19.6268 142.398L23.6858 143.878L29.8645 144.739L36.0433 145.6H43.9161H51.7891L52.0422 147.8L52.2944 150H103.391H154.488L154.729 147.918L154.97 145.836L167.503 145.398L180.036 144.96L184.827 143.222L189.617 141.485L195.206 139.871L200.795 138.258L201.623 137.208L202.452 136.158L204.418 135.879L206.383 135.6L206.407 231.8L206.431 328H204.315H202.198L201.636 335.2L201.074 342.4H199.138H197.202V344.8V347.2H194.807H192.411V349.6V352H190.016H187.621V354.4V356.8H182.831H178.04V359.2V361.6H173.25H168.46L168.461 363.8L168.461 366H157.084H145.706L145.454 368.2L145.2 370.4H103.391H61.5821L61.329 368.2L61.0767 366L49.3005 365.778L37.5243 365.558V363.578V361.6H33.1331H28.742V359.2V356.8H23.9517H19.1613V354.453V352.106L16.9658 351.853L14.7702 351.6L14.5179 349.4L14.2648 347.2H11.9232H9.58069V342.4V337.6H7.18553H4.79036V332.8V328H2.3952H3.8147e-05V231.6V135.2H0.280282H0.560526L3.07464 136.078ZM19.1613 323.094V243.547V164H23.9517H28.742V239.2V314.4H31.1372H33.5323V321.6V328.8H35.5283H37.5243V330.8V332.8H39.9194H42.3146V335.2V337.6H44.7097H47.1049V342.4V347.2H42.7665H38.4288L38.1757 345L37.9235 342.8L33.4948 342.565L29.0654 342.33L28.1751 339.965L27.2841 337.6H25.649H24.0139L23.7832 330.6L23.5525 323.6L21.3569 323.347L19.1613 323.094Z",fill:t}),e("path",{d:"M237.972 155.228L239.516 156.056V157.586V159.116L243.708 159.358L247.899 159.6L248.687 161.4L249.475 163.2H251.182H252.889L255.384 163.7L257.879 164.2V166.5V168.8H260.189H262.499L262.961 170.007L263.423 171.214L265.442 172.135L267.46 173.057V175.275V177.494L269.655 177.747L271.851 178L272.101 180.6L272.352 183.2H274.585H276.819L276.438 185.2L276.056 187.2H278.544H281.033V192V196.8H283.428H285.823V204V211.2H288.218H290.613V230V248.8H288.218H285.823V255.547V262.294L283.627 262.547L281.432 262.8L281.192 267.4L280.953 272H278.977H277.001L276.522 274.4L276.043 276.8H274.146H272.25V278.508V280.217L270.454 282.033L268.658 283.85L267.628 285.125L266.598 286.4H264.634H262.67V288.8V291.2H260.274H257.879V293.2V295.2H255.484H253.089V297.6V300H246.303H239.516V302.4V304.8H227.541H215.565V295.622V286.442L227.341 286.222L239.117 286L239.086 283.8L239.054 281.6H243.677H248.299V279.2V276.8H250.694H253.089V274.4V272H255.484H257.879V269.6V267.2H260.274H262.67V264.8V262.4H265.065H267.46V257.492V252.583L269.456 250.73L271.452 248.876V230.038V211.2H269.487H267.522L267.291 204.2L267.061 197.2L264.865 196.947L262.67 196.694V194.347V192H260.274H257.879V190.063V188.127L255.484 187.6L253.089 187.073V185.19V183.306L250.893 183.053L248.698 182.8L248.445 180.6L248.192 178.4H243.907H239.623L239.369 176.2L239.117 174L227.341 173.778L215.565 173.558V163.978V154.4H225.996H236.427L237.972 155.228Z",fill:t}),e("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M107.782 6.8V13.6H110.073H112.364L112.858 16.6L113.354 19.6V23.2V26.8L112.866 29.756L112.378 32.7128L110.28 32.956L108.182 33.2L107.929 35.4L107.676 37.6H105.786H103.897L103.644 39.8L103.391 42L101.196 42.2528L99.0001 42.5064V44.0792V45.6512L97.8433 48.4256L96.6864 51.2H95.5527H94.419L93.924 54.2L93.4289 57.2L93.4904 64.4L93.5511 71.6L94.0805 75.6L94.609 79.6L96.8045 79.8528L99.0001 80.1064V82.0528V84H103.391H107.782V79.6V75.2H105.88H103.976L103.495 73.4L103.014 71.6L103.003 65.852L102.992 60.104L103.77 58.052L104.549 56H106.113H107.676L107.929 53.8L108.182 51.6L110.328 51.3512L112.476 51.1032L112.724 48.9512L112.972 46.8L115.167 46.5472L117.363 46.2936V44.4V42.5064L119.559 42.2528L121.754 42L121.992 37.4496L122.23 32.8992L124.387 32.6496L126.544 32.4L126.303 26L126.062 19.6L123.583 12.2392L121.105 4.87841L119.433 4.6392L117.762 4.4L117.51 2.2L117.257 0H112.52H107.782V6.8ZM66.2662 37.548V47.096L65.4878 49.148L64.7093 51.2H63.0926H61.4759V53.6V56H59.0807H56.6856V58.4V60.8H54.2904H51.8952V69.9472V79.0936L54.0908 79.3472L56.2864 79.6L56.5386 81.8L56.7917 84H61.1294H65.4678V79.6V75.2H63.4719H61.4759V70.4V65.6H63.4088H65.3409L65.867 63.2L66.3932 60.8H68.2726H70.152L70.4051 58.6L70.6573 56.4L72.8042 56.1512L74.9519 55.9032L75.1994 53.7512L75.4477 51.6L77.6432 51.3472L79.8388 51.0936V41.9472V32.8H77.4436H75.0485V30.4V28H70.6573H66.2662V37.548ZM146.096 36.6L146.087 45.2L145.592 48.2L145.097 51.2H143.206H141.315V53.6V56H138.919H136.524V58.4V60.8H134.129H131.734V69.9368V79.0728L134.129 79.6L136.524 80.1272V82.0632V84H140.915H145.307V79.6V75.2H143.359H141.413L140.876 71.6096L140.338 68.02L140.801 66.8096L141.264 65.6H143.286H145.307V63.2V60.8H147.649H149.991L150.244 58.6L150.496 56.4L152.692 56.1472L154.887 55.8936V53.5472V51.2H156.883H158.879V42V32.8H156.883H154.887V30.4V28H150.496H146.105L146.096 36.6Z",fill:t}),e("path",{d:"M145.307 105.2V107.2L147.901 107.222L150.496 107.243L161.274 107.678L172.053 108.113L173.051 108.431L174.049 108.75V110.261V111.772L178.719 112.262L183.39 112.75L189.697 114.747L196.004 116.744L199.797 119.154L203.589 121.565V123.164V124.763L201.78 125.951L199.97 127.139L196.544 128.35L193.118 129.562L190.538 126.981L187.958 124.4L182.8 122.609L177.641 120.818L167.262 118.471L156.883 116.125L149.698 115.261L142.512 114.396L132.217 113.598L121.922 112.8H104.641H87.362L73.0214 113.988L58.6815 115.176L53.0928 116.069L47.5041 116.962L35.7965 119.63L24.0882 122.298L21.0264 123.871L17.9638 125.444L16.0987 127.446L14.2345 129.449L12.0844 128.831L9.93437 128.214L6.51408 126.465L3.09379 124.716L3.3429 122.962L3.59278 121.209L7.73164 118.734L11.8705 116.26L17.2644 114.486L22.6575 112.711L27.637 112.246L32.6158 111.78L33.0892 109.89L33.5627 108H40.2108H46.8598L54.1675 107.48L61.4759 106.961V105.08V103.2H103.391H145.307V105.2Z",fill:t})]})}var Pn={1:"1st",2:"2nd",3:"3rd",21:"21st",22:"22nd",23:"23rd",31:"31st"};function qn(t){return Pn[t]??`${t}th`}function ot(t){return t<10?`0${t}`:`${t}`}function lt(t,n,s){let a=new Date(2026,0,1,t,n),o={hour:"numeric",minute:"2-digit"};return s&&(o.timeZone=s),a.toLocaleTimeString("en-US",o)}function P(t,n){let s=t.trim().split(/\s+/);if(s.length<5)return t;let[a,o,r,i,l]=s,d=n?` ${new Date().toLocaleTimeString("en-US",{timeZone:n,timeZoneName:"short"}).split(" ").pop()}`:"";if(a.startsWith("*/")&&o==="*"&&r==="*"&&i==="*"&&l==="*"){let u=parseInt(a.slice(2));return u===1?"Every minute":`Every ${u} minutes`}if(!a.includes("*")&&!a.includes("/")&&o.startsWith("*/")&&r==="*"&&i==="*"&&l==="*"){let u=parseInt(o.slice(2));return u===1?`Hourly at :${ot(parseInt(a))}`:`Every ${u} hours at :${ot(parseInt(a))}`}if(!a.includes("*")&&!a.includes("/")&&o==="*"&&r==="*"&&i==="*"&&l==="*")return`Hourly at :${ot(parseInt(a))}`;if(!a.includes("*")&&!o.includes("*")&&r==="*"&&i==="*"&&l==="*")return`Daily at ${lt(parseInt(o),parseInt(a),n)}${d}`;if(!a.includes("*")&&!o.includes("*")&&r==="*"&&i==="*"&&l!=="*"){let u=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];return`${l.split(",").map(c=>u[parseInt(c)]??c).join(", ")} at ${lt(parseInt(o),parseInt(a),n)}${d}`}return!a.includes("*")&&!o.includes("*")&&r!=="*"&&i==="*"&&l==="*"?`${qn(r)} of each month at ${lt(parseInt(o),parseInt(a),n)}${d}`:a==="0"&&o==="0"&&r==="*"&&i==="*"&&l==="*"?`Daily at midnight${d}`:t}function Ie(t){if(!t)return"default";if(typeof t=="string")return t;let s=["fast","balanced","powerful"].filter(a=>t[a]).map(a=>`${a}:${zn(t[a])}`);return s.length>0?s.join(" / "):"default"}function zn(t){let n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Yt(){let[t,n]=h(null),[s,a]=h(null),o=B(()=>{fetch("/explorer/api/overview").then(r=>r.json()).then(n).catch(r=>a(r.message))},[]);return S(()=>{o()},[]),G(B(r=>{(r.type==="refresh"||r.type==="reload")&&o()},[o])),s?e("div",{class:"explorer-error",children:["Failed to load: ",s]}):t?e("div",{class:"overview",children:[e("nav",{class:"breadcrumb",children:"Explorer"}),e("div",{class:"overview-grid",children:[e(ae,{title:"Sync Sources",icon:"cloud-download",path:"sources",empty:"No sync sources yet. Add a connector in connectors/ to sync data from an external API.",children:t.sources.map(r=>{let i=r.syncs??[],l=[...new Set(i.map(g=>g.database).filter(Boolean))],d=l.reduce((g,c)=>{let m=t.databases?.find(p=>p.name===c);return g+(m?.remoteTables?.length??m?.tableCount??0)},0),u=t.scheduleHealth?.find(g=>g.item_type==="source"&&g.item_name===r.name);return e("a",{href:`/explorer/sources/${r.name}`,class:"card",children:[e("span",{class:"card-name",children:[r.name,e(Me,{drift:r.drift})]}),e("span",{class:"card-meta",children:[l.length," database",l.length!==1?"s":""," \xB7 ",i.length," sync",i.length!==1?"s":""," \xB7 ",d," table",d!==1?"s":""]}),u&&e(Jt,{item:u,label:"sync"})]},r.name)})}),e(ae,{title:"Databases",icon:"database",path:"databases",empty:"No databases yet. Connectors sync data into databases/, or create one with mug sql.",children:t.databases.map(r=>e("a",{href:`/explorer/databases/${r.name}`,class:"card",children:[e("span",{class:"card-name",children:[r.name,r.remote&&!r.local?e("span",{class:"card-badge card-badge-remote",children:"remote"}):""]}),e("span",{class:"card-meta",children:[r.tableCount," table",r.tableCount!==1?"s":""," \xB7 ",Zt(r.sizeBytes),r.remote&&!r.local?" \xB7 mug pull to download":""]})]},r.name))}),e(ae,{title:"Workflows",icon:"zap",path:"workflows",empty:"No workflows yet. Add one in workflows/ and register it in mug.json.",children:t.workflows.map(r=>{let i=t.scheduleHealth?.find(l=>l.item_type==="workflow"&&l.item_name===r.name);return e("a",{href:`/explorer/workflows/${r.name}`,class:"card",children:[e("span",{class:"card-name",children:[r.name,e(Me,{drift:r.drift})]}),e("span",{class:"card-meta",children:[r.schedule?P(r.schedule,t.workspace.timezone):r.webhook?"Webhook":"Manual",r.stepCount?` \xB7 ${r.stepCount} step${r.stepCount!==1?"s":""}`:""]}),i&&e(Jt,{item:i})]},r.name)})}),e(ae,{title:"Agents",icon:"bot",path:"agents",empty:"No agents yet. Add one in agents/ with agent.json config.",children:(t.agents??[]).map(r=>e("a",{href:`/explorer/agents/${r.name}`,class:"card",children:[e("span",{class:"card-name",children:[r.name,e(Me,{drift:r.drift})]}),e("span",{class:"card-meta",children:[Ie(r.model),r.tools?.length?` \xB7 ${r.tools.length} tool${r.tools.length!==1?"s":""}`:""]})]},r.name))}),e(ae,{title:"Surfaces",icon:"layout-panel-left",path:"surfaces",empty:"No surfaces yet. Add a form or portal JSON in surfaces/.",children:t.surfaces.map(r=>e("a",{href:`/explorer/surfaces/${r.name}`,class:"card",children:[e("span",{class:"card-name",children:[r.title||r.name,e(Me,{drift:r.drift})]}),e("span",{class:"card-meta",children:[r.type||"form"," \xB7 ",r.accessMode||"public"]})]},r.name))}),e(ae,{title:"Files",icon:"files",path:"files",empty:"No files yet. Add files to the files/ directory for static assets.",children:t.files.map(r=>e("a",{href:r.local?`/_files/${r.name}`:"#",class:"card",target:r.local?"_blank":void 0,children:[e("span",{class:"card-name",children:[r.name,r.remote&&!r.local?e("span",{class:"card-badge card-badge-remote",children:"remote"}):""]}),e("span",{class:"card-meta",children:[Zt(r.sizeBytes),r.remote&&!r.local?" \xB7 mug pull to download":""]})]},r.name))})]})]}):e("div",{class:"explorer-loading",children:"Loading workspace..."})}function ae({title:t,icon:n,path:s,empty:a,children:o}){let i=(Array.isArray(o)?o.filter(Boolean):o?[o]:[]).length;return e("section",{class:"overview-section",children:[e("h2",{children:[e("a",{href:`/explorer/${s}`,class:"section-header",children:[e("i",{"data-lucide":n,class:"section-icon"}),t]}),e("span",{class:"section-count",children:i})]}),i>0?e("div",{class:"card-list",children:o}):e("div",{class:"empty-state",children:a})]})}function Me({drift:t}){if(!t||t==="synced")return null;let n={diverged:"modified","local-only":"not deployed","remote-only":"remote only"},s=`card-badge card-badge-${t}`;return e("span",{class:s,children:n[t]||t})}function Jt({item:t,label:n}){let s=n||"ran";return t.lastError?e("span",{class:"card-schedule card-schedule-error",children:["Last ",s," failed \xB7 ",Ve(t.lastRun)]}):t.lastRun?e("span",{class:"card-schedule card-schedule-ok",children:["Last ",s," ",Ve(t.lastRun)," \u2713",t.nextAlarm?` \xB7 next ${Ve(t.nextAlarm,!0)}`:""]}):t.nextAlarm?e("span",{class:"card-schedule",children:["Next ",s," ",Ve(t.nextAlarm,!0)]}):null}function Ve(t,n=!1){if(!t)return"";let s=(new Date(t).getTime()-Date.now())/1e3,a=Math.abs(s);if(a<60)return n?"in <1m":"<1m ago";if(a<3600){let r=Math.round(a/60);return n?`in ${r}m`:`${r}m ago`}if(a<86400){let r=Math.round(a/3600);return n?`in ${r}h`:`${r}h ago`}let o=Math.round(a/86400);return n?`in ${o}d`:`${o}d ago`}function Zt(t){return t<1e3?`${t} B`:t<1e6?`${(t/1e3).toFixed(1)} KB`:`${(t/1e6).toFixed(1)} MB`}var Gn={sources:{title:"Sync Sources",icon:"cloud-download"},databases:{title:"Databases",icon:"database"},workflows:{title:"Workflows",icon:"zap"},surfaces:{title:"Surfaces",icon:"layout-panel-left"},agents:{title:"Agents",icon:"bot"}};function oe({category:t}){let[n,s]=h(null),[a,o]=h(null),r=B(()=>{fetch("/explorer/api/overview").then(l=>l.json()).then(s).catch(l=>o(l.message))},[]);if(G(B(l=>{(l.type==="refresh"||l.type==="reload")&&r()},[r])),S(()=>{fetch("/explorer/api/overview").then(l=>l.json()).then(s).catch(l=>o(l.message))},[]),a)return e("div",{class:"explorer-error",children:["Failed to load: ",a]});if(!n)return e("div",{class:"explorer-loading",children:"Loading..."});let i=Gn[t??""]??{title:t,icon:"folder"};return e("div",{children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A ",i.title]}),e("header",{class:"detail-header",children:e("h1",{children:[e("i",{"data-lucide":i.icon,class:"section-icon"})," ",i.title]})}),e("div",{class:"card-list",children:[t==="databases"&&n.databases.map(l=>e("a",{href:`/explorer/databases/${l.name}`,class:"card",children:[e("span",{class:"card-name",children:[l.name,l.remote&&!l.local?e("span",{class:"card-badge card-badge-remote",children:"remote"}):""]}),e("span",{class:"card-meta",children:[l.tableCount," table",l.tableCount!==1?"s":""," \xB7 ",Kn(l.sizeBytes),l.remote&&!l.local?" \xB7 mug pull to download":""]})]},l.name)),t==="workflows"&&n.workflows.map(l=>e("a",{href:`/explorer/workflows/${l.name}`,class:"card",children:[e("span",{class:"card-name",children:l.name}),e("span",{class:"card-meta",children:[l.schedule?P(l.schedule,n.workspace.timezone):l.webhook?"Webhook":"Manual",l.stepCount?` \xB7 ${l.stepCount} step${l.stepCount!==1?"s":""}`:""]})]},l.name)),t==="sources"&&n.sources.map(l=>{let d=l.syncs??[],u=[...new Set(d.map(c=>c.database).filter(Boolean))],g=u.reduce((c,m)=>{let p=n.databases?.find(w=>w.name===m);return c+(p?.remoteTables?.length??p?.tableCount??0)},0);return e("a",{href:`/explorer/sources/${l.name}`,class:"card",children:[e("span",{class:"card-name",children:l.name}),e("span",{class:"card-meta",children:[u.length," database",u.length!==1?"s":""," \xB7 ",d.length," sync",d.length!==1?"s":""," \xB7 ",g," table",g!==1?"s":""]})]},l.name)}),t==="surfaces"&&n.surfaces.map(l=>e("a",{href:`/explorer/surfaces/${l.name}`,class:"card",children:[e("span",{class:"card-name",children:l.title||l.name}),e("span",{class:"card-meta",children:[l.type||"form"," \xB7 ",l.accessMode||"public"]})]},l.name)),t==="agents"&&(n.agents??[]).map(l=>{let d=(l.skills?.length??0)+(l.sharedSkills?.length??0);return e("a",{href:`/explorer/agents/${l.name}`,class:"card",children:[e("span",{class:"card-name",children:l.name}),e("span",{class:"card-meta",children:[Ie(l.model),l.tools?.length?` \xB7 ${l.tools.length} tool${l.tools.length!==1?"s":""}`:"",d>0?` \xB7 ${d} skill${d!==1?"s":""}`:""]})]},l.name)})]})]})}function Kn(t){return t<1e3?`${t} B`:t<1e6?`${(t/1e3).toFixed(1)} KB`:`${(t/1e6).toFixed(1)} MB`}function K({connections:t}){let n=t.filter(i=>i.items.length>0),[s,a]=h(!1),o=n.length>0?n.map(i=>`${i.items.length} ${i.category}`).join(", "):"Nothing yet",r=n.length>0;return e("div",{class:`connected-to ${s?"connected-to-open":""}`,children:[r?e("button",{class:"connected-to-toggle",onClick:()=>a(!s),children:[e("span",{class:"connected-to-heading",children:[e("i",{"data-lucide":"cable",class:"connected-to-icon"}),"Connected to",e("span",{class:"connected-to-summary",children:o})]}),e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:`connected-to-chevron toggle-icon ${s?"toggle-icon-open":""}`,children:e("path",{d:"m9 18 6-6-6-6"})})]}):e("div",{class:"connected-to-toggle connected-to-empty",children:e("span",{class:"connected-to-heading",children:[e("i",{"data-lucide":"cable",class:"connected-to-icon"}),"Connected to",e("span",{class:"connected-to-summary",children:o})]})}),s&&e("div",{class:"connected-to-body",children:n.map(i=>e("section",{class:"overview-section",children:[e("h2",{children:e("a",{href:`/explorer/${i.path}`,class:"section-header",children:[e("i",{"data-lucide":i.icon,class:"section-icon"}),i.category]})}),e("div",{class:"card-list",children:i.items.map(l=>e("a",{href:`/explorer/${i.path}/${l.name}`,class:"card",children:[e("span",{class:"card-name",children:l.label||l.name}),l.meta&&e("span",{class:"card-meta",children:l.meta})]},l.name))})]},i.category))})]})}function Qt({name:t}){let[n,s]=h(null),[a,o]=h(null),r=N();if(S(()=>{t&&fetch(`/explorer/api/databases/${encodeURIComponent(t)}`).then(d=>d.ok?d.json():Promise.reject(new Error(`${d.status}`))).then(s).catch(d=>o(d.message))},[t]),a)return e("div",{class:"explorer-error",children:["Failed to load database: ",a]});if(!n)return e("div",{class:"explorer-loading",children:"Loading database..."});let i=(n.sources??[]).map(d=>{let u=r?.sources.find(c=>c.name===d),g=u?.connection?r?.connections.find(c=>c.name===u.connection):void 0;return{name:d,meta:[g?.baseUrl,u?.database?`\u2192 ${u.database}`:"",u?.schedule?`(${u.schedule})`:""].filter(Boolean).join(" ")||void 0}}),l=(n.surfaces??[]).map(d=>{let u=r?.surfaces.find(g=>g.name===d);return{name:d,label:u?.title||d,meta:`${u?.type||"form"} \xB7 ${u?.accessMode||"public"}`}});return e("div",{class:"database-detail",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A ",e("a",{href:"/explorer/databases",children:"Databases"})," \u203A ",n.name]}),e("header",{class:"detail-header",children:[e("h1",{children:[n.name,n.remote?e("span",{class:"card-badge card-badge-remote",style:"margin-left: 10px;",children:"remote"}):""]}),e("span",{class:"detail-meta",children:re(n.sizeBytes)}),n.description&&e("p",{class:"detail-description",style:"width: 100%",children:n.description})]}),n.remote&&n.pullCommand&&e("div",{class:"remote-notice",children:[e("i",{"data-lucide":"cloud",class:"remote-notice-icon"}),"This database exists in production but hasn't been pulled locally. Run ",e("code",{children:n.pullCommand})," to download a copy."]}),e(K,{connections:[{category:"Sync Sources",icon:"cloud-download",path:"sources",items:i},{category:"Surfaces",icon:"layout-panel-left",path:"surfaces",items:l}]}),e("div",{class:"table-list",children:n.tables.map(d=>e("a",{href:`/explorer/databases/${t}/${d.name}`,class:"card table-card",children:[e("div",{class:"card-name",children:d.name}),e("div",{class:"card-meta",children:[d.rowCount.toLocaleString()," row",d.rowCount!==1?"s":""," \xB7"," ",d.columns.length," column",d.columns.length!==1?"s":""]}),e("div",{class:"table-columns",children:d.columns.map(u=>e("span",{class:`col-tag ${u.pk?"col-pk":""}`,children:[u.name," ",e("span",{class:"col-type",children:u.type||"any"})]},u.name))})]},d.name))}),n.tables.length===0&&e("div",{class:"empty-state",children:"No tables in this database."})]})}function tn({name:t,table:n}){let[s,a]=h(null),[o,r]=h(null),[i,l]=h(1),[d,u]=h([]),[g,c]=h([]),[m,p]=h(""),[w,b]=h(""),[y,f]=h(new Set),[v,k]=h(!1),[_,F]=h(!1),A=fe(),T=100,I=B(()=>{if(!t||!n)return;let x=new URLSearchParams({page:String(i),pageSize:String(T)});d.length>0&&x.set("sort",JSON.stringify(d)),g.length>0&&x.set("filters",JSON.stringify(g)),m&&x.set("search",m),fetch(`/explorer/api/databases/${encodeURIComponent(t)}/${encodeURIComponent(n)}?${x}`).then(D=>D.ok?D.json():Promise.reject(new Error(`${D.status}`))).then(a).catch(D=>r(D.message))},[t,n,i,d,g,m]);S(()=>{I()},[I]);let M=x=>{b(x),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>{p(x),l(1)},250)},V=(x,D)=>{u($=>{let j=$.find(Y=>Y.column===x);if(j)return j.dir==="asc"?$.map(Y=>Y.column===x?{...Y,dir:"desc"}:Y):$.filter(Y=>Y.column!==x);let te={column:x,dir:"asc"};return D?[...$,te]:[te]}),l(1)},ye=()=>{!s||s.columns.length===0||(c(x=>[...x,{column:s.columns[0].name,op:"contains",value:""}]),k(!0))},we=(x,D)=>{c($=>$.map((j,te)=>te===x?{...j,...D}:j))},mt=x=>{c(D=>D.filter(($,j)=>j!==x)),l(1)},Fe=()=>{l(1),I()},Ue=x=>{f(D=>{let $=new Set(D);return $.has(x)?$.delete(x):$.add(x),$})};if(o)return e("div",{class:"explorer-error",children:["Failed to load table: ",o]});if(!s)return e("div",{class:"explorer-loading",children:"Loading table..."});let ke=s.columns.filter(x=>!y.has(x.name)),ee=Math.ceil(s.totalRows/T);return e("div",{class:"table-browser",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A"," ",e("a",{href:"/explorer/databases",children:"Databases"})," \u203A"," ",e("a",{href:`/explorer/databases/${t}`,children:t})," \u203A ",n]}),e("header",{class:"detail-header",children:[e("h1",{children:[n,s.remote?e("span",{class:"card-badge card-badge-remote",style:"margin-left: 10px;",children:"remote"}):""]}),e("span",{class:"detail-meta",children:[s.totalRows.toLocaleString()," row",s.totalRows!==1?"s":""," \xB7"," ",s.columns.length," column",s.columns.length!==1?"s":""]})]}),s.remote&&s.pullCommand&&e("div",{class:"remote-notice",children:[e("i",{"data-lucide":"cloud",class:"remote-notice-icon"}),"This table exists in production but hasn't been pulled locally. Run ",e("code",{children:s.pullCommand})," to download a copy."]}),s.remote?s.columns.length>0&&e("div",{class:"remote-columns",children:[e("div",{class:"source-tables-label",children:"Columns"}),s.columns.map(x=>e("span",{class:"col-tag",children:[x.name," ",e("span",{class:"col-type",children:x.type||"any"})]},x.name))]}):e(L,{children:[e("div",{class:"toolbar",children:[e("input",{type:"text",class:"search-input",placeholder:"Search...",value:w,onInput:x=>M(x.target.value)}),e("button",{class:`toolbar-btn ${g.length>0?"active":""}`,onClick:()=>g.length>0?k(!v):ye(),children:["Filter",g.length>0?` (${g.length})`:""]}),e("button",{class:`toolbar-btn ${d.length>0?"active":""}`,onClick:()=>d.length>0?u([]):void 0,children:["Sort",d.length>0?` (${d.length})`:""]}),e("div",{class:"col-menu-wrap",children:[e("button",{class:`toolbar-btn ${y.size>0?"active":""}`,onClick:()=>F(!_),children:["Columns",y.size>0?` (${s.columns.length-y.size}/${s.columns.length})`:""]}),_&&e("div",{class:"dropdown",children:s.columns.map(x=>e("label",{class:"dropdown-item",children:[e("input",{type:"checkbox",checked:!y.has(x.name),onChange:()=>Ue(x.name)}),x.name]},x.name))})]})]}),v&&e("div",{class:"filter-panel",children:[g.map((x,D)=>e(Zn,{filter:x,columns:s.columns,onChange:$=>we(D,$),onRemove:()=>mt(D)},D)),e("div",{class:"filter-actions",children:[e("button",{class:"toolbar-btn",onClick:ye,children:"+ Add filter"}),e("button",{class:"toolbar-btn active",onClick:Fe,children:"Apply"})]})]}),s.totalRows===0&&!m&&g.length===0?e("div",{class:"empty-state",children:"This table is empty."}):s.totalRows===0?e("div",{class:"empty-state",children:"No rows match your filters."}):e(L,{children:[e("div",{class:"table-wrap",children:e("table",{class:"data-table",children:[e("thead",{children:e("tr",{children:ke.map(x=>{let D=d.find($=>$.column===x.name);return e("th",{class:"sortable-th",onClick:$=>V(x.name,$.shiftKey),children:[e("span",{class:"th-name",children:x.name}),e("span",{class:"th-type",children:x.type||"any"}),D&&e("span",{class:"sort-indicator",children:D.dir==="asc"?" \u2191":" \u2193"})]},x.name)})})}),e("tbody",{children:s.rows.map((x,D)=>e("tr",{children:ke.map($=>e("td",{children:e(Yn,{value:x[$.name],type:$.type})},$.name))},D))})]})}),ee>1&&e("div",{class:"pagination",children:[e("button",{disabled:i<=1,onClick:()=>l(i-1),children:"Previous"}),e("span",{class:"page-info",children:["Page ",i," of ",ee]}),e("button",{disabled:i>=ee,onClick:()=>l(i+1),children:"Next"})]})]})]})]})}var Xt={text:[{value:"contains",label:"contains"},{value:"eq",label:"equals"},{value:"neq",label:"not equals"},{value:"starts_with",label:"starts with"},{value:"empty",label:"is empty"},{value:"not_empty",label:"is not empty"}],number:[{value:"eq",label:"="},{value:"neq",label:"\u2260"},{value:"gt",label:">"},{value:"gte",label:"\u2265"},{value:"lt",label:"<"},{value:"lte",label:"\u2264"},{value:"empty",label:"is empty"},{value:"not_empty",label:"is not empty"}]};function Jn(t){let n=t.toUpperCase();return n.includes("INT")||n.includes("REAL")||n.includes("FLOAT")||n.includes("NUMERIC")?"number":"text"}function Zn({filter:t,columns:n,onChange:s,onRemove:a}){let o=n.find(d=>d.name===t.column),r=o?Jn(o.type):"text",i=Xt[r]||Xt.text,l=!["empty","not_empty"].includes(t.op);return e("div",{class:"filter-row",children:[e("select",{value:t.column,onChange:d=>s({column:d.target.value}),children:n.map(d=>e("option",{value:d.name,children:d.name},d.name))}),e("select",{value:t.op,onChange:d=>s({op:d.target.value}),children:i.map(d=>e("option",{value:d.value,children:d.label},d.value))}),l&&e("input",{type:r==="number"?"number":"text",class:"filter-value",value:String(t.value??""),onInput:d=>{let u=d.target.value;s({value:r==="number"?u===""?"":Number(u):u})},placeholder:"value"}),e("button",{class:"filter-remove",onClick:a,children:"\xD7"})]})}function Yn({value:t,type:n}){if(t==null)return e("span",{class:"cell-null",children:"null"});let s=String(t),a=n.toLowerCase();return typeof t=="boolean"||a==="boolean"?e("span",{class:"cell-bool",children:t?"true":"false"}):typeof t=="number"||a.includes("int")||a.includes("real")||a.includes("float")||a.includes("numeric")?e("span",{class:"cell-number",children:typeof t=="number"?t.toLocaleString():s}):Qn(s)?e("span",{class:"cell-date",title:s,children:ts(s)}):Xn(s)?e("span",{class:"cell-email",children:s}):es(s)?e("span",{class:"cell-url",title:s,children:en(s,50)}):s.length>200?e("span",{class:"cell-text",title:s,children:en(s,200)}):e("span",{children:s})}function Qn(t){return/^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2})?/.test(t)}function Xn(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)&&t.length<100}function es(t){return/^https?:\/\/.+/.test(t)}function ts(t){try{let n=new Date(t);return isNaN(n.getTime())?t:t.length<=10?n.toLocaleDateString():n.toLocaleString()}catch{return t}}function en(t,n){return t.length>n?t.slice(0,n)+"...":t}var ns={query:"database",exec:"database",ai:"sparkles",email:"mail",sms:"message-square",slack:"hash",collect:"clipboard",return:"flag",loop:"repeat",branch:"git-branch",agent:"bot"};function Ae({steps:t,runData:n}){return!t||t.length===0?null:e("div",{class:"step-flow",children:e(ve,{steps:t,runData:n,runIndex:{i:0},depth:0})})}function ve({steps:t,runData:n,runIndex:s,depth:a}){return e(L,{children:t.map((o,r)=>e(ss,{step:o,runData:n,runIndex:s,isLast:r===t.length-1,depth:a},r))})}function ss({step:t,runData:n,runIndex:s,isLast:a,depth:o}){return t.type==="loop"?e(as,{step:t,runData:n,runIndex:s,isLast:a,depth:o}):t.type==="branch"?e(os,{step:t,runData:n,runIndex:s,isLast:a,depth:o}):e(rs,{step:t,runData:n,runIndex:s,isLast:a})}function rs({step:t,runData:n,runIndex:s,isLast:a}){let[o,r]=h(!1),i=ns[t.type]??"circle",l=n?.[s.i],d=l&&l.type===t.type;d&&s.i++;let u=ls(t),g=!!u,c=d&&!!l?.error;return e("div",{class:`step-card-wrap ${a?"step-last":""}`,children:[e("div",{class:"step-connector"}),e("div",{class:`step-card ${c?"step-error":""} ${g?"step-expandable":""}`,onClick:g?()=>r(!o):void 0,children:[e("div",{class:"step-card-header",children:[e("i",{"data-lucide":i,class:`step-icon step-icon-${t.type}`}),e("span",{class:"step-label",children:t.label}),e("span",{class:"step-type-badge",children:t.type}),d&&l?.durationMs!=null&&e("span",{class:"step-duration",children:is(l.durationMs)}),d&&!c&&e("span",{class:"step-status step-status-ok",children:"\u2713"}),c&&e("span",{class:"step-status step-status-err",children:"\u2717"}),g&&e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:`step-expand-icon toggle-icon ${o?"toggle-icon-open":""}`,children:e("path",{d:"m9 18 6-6-6-6"})})]}),t.description&&e("div",{class:"step-description",children:t.description}),c&&e("div",{class:"step-error-msg",children:l.error}),o&&u&&e("div",{class:"step-detail",children:e("pre",{children:u})})]})]})}function as({step:t,runData:n,runIndex:s,isLast:a,depth:o}){return e("div",{class:`step-card-wrap ${a?"step-last":""}`,children:[e("div",{class:"step-connector"}),e("div",{class:"step-loop",children:[e("div",{class:"step-loop-header",children:[e("i",{"data-lucide":"repeat",class:"step-icon step-icon-loop"}),e("span",{class:"step-label",children:t.label}),e("span",{class:"step-type-badge",children:"loop"})]}),t.description&&e("div",{class:"step-description",style:"padding: 0 14px;",children:t.description}),e("div",{class:"step-loop-body",children:e(ve,{steps:t.steps,runData:n,runIndex:s,depth:o+1})})]})]})}function os({step:t,runData:n,runIndex:s,isLast:a,depth:o}){let r=t.else&&t.else.length>0,i=t.after&&t.after.length>0;return e("div",{class:`step-card-wrap ${a?"step-last":""}`,children:[e("div",{class:"step-connector"}),e("div",{class:"step-branch",children:[e("div",{class:"step-branch-header",children:[e("i",{"data-lucide":"git-branch",class:"step-icon step-icon-branch"}),e("span",{class:"step-label",children:t.label}),e("span",{class:"step-type-badge",children:"branch"})]}),t.description&&e("div",{class:"step-description",style:"padding: 0 14px;",children:t.description}),e("div",{class:"step-branch-path",children:[e("div",{class:"step-branch-path-label",children:"Then"}),e(ve,{steps:t.if,runData:n,runIndex:s,depth:o+1})]}),r&&e("div",{class:"step-branch-path step-branch-else",children:[e("div",{class:"step-branch-path-label",children:"Else"}),e(ve,{steps:t.else,runData:n,runIndex:s,depth:o+1})]}),i&&e("div",{class:"step-branch-path step-branch-after",children:[e("div",{class:"step-branch-path-label",children:"Then continues"}),e(ve,{steps:t.after,runData:n,runIndex:s,depth:o+1})]})]})]})}function ls(t){switch(t.type){case"query":case"exec":return t.sql||null;case"ai":return t.prompt||null;case"email":return[t.to&&`To: ${t.to}`,t.subject&&`Subject: ${t.subject}`].filter(Boolean).join(`
2
+ `)||null;case"sms":return t.to?`To: ${t.to}`:null;case"slack":return t.channel?`Channel: ${t.channel}`:null;case"return":return t.value||null;case"agent":return[`Agent: ${t.agentName}`,t.model?`Model: ${t.model}`:"",`Goal: ${t.goal}`,t.credits?`Credits: ${t.credits}`:"",t.capped?"\u26A0 Capped":""].filter(Boolean).join(`
3
+ `)||null;default:return null}}function is(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function nn({name:t}){let[n,s]=h(null),[a,o]=h(null),[r,i]=h([]),[l,d]=h(null),u=N(),g=B(()=>{t&&fetch(`/explorer/api/workflows/${encodeURIComponent(t)}/runs`).then(f=>f.ok?f.json():{runs:[]}).then(f=>i(f.runs??[])).catch(()=>{})},[t]);if(S(()=>{t&&(fetch(`/explorer/api/workflows/${encodeURIComponent(t)}`).then(f=>f.ok?f.json():Promise.reject(new Error(`${f.status}`))).then(s).catch(f=>o(f.message)),g(),fetch("/explorer/api/overview").then(f=>f.json()).then(f=>{let v=f.scheduleHealth?.find(k=>k.item_type==="workflow"&&k.item_name===t);v&&d(v)}).catch(()=>{}))},[t]),G(B(f=>{f.type==="refresh"&&f.area==="workflows"&&g()},[g])),a)return e("div",{class:"explorer-error",children:["Failed to load workflow: ",a]});if(!n)return e("div",{class:"explorer-loading",children:"Loading workflow..."});let c=u?.workflows.find(f=>f.name===n.name)?.drift,m=(n.sources??[]).map(f=>{let k=u?.sources.find(_=>_.name===f)?.syncs?.length??0;return{name:f,meta:k?`${k} sync${k!==1?"s":""}`:void 0}}),p=new Set;for(let f of u?.sources??[])if((n.sources??[]).includes(f.name))for(let v of f.syncs??[])v.database&&p.add(v.database);let b=n.databases.filter(f=>!p.has(f)).map(f=>{let v=u?.databases.find(k=>k.name===f);return{name:f,meta:v?`${v.tableCount} table${v.tableCount!==1?"s":""} \xB7 ${re(v.sizeBytes)}`:void 0}}),y=n.surfaces.map(f=>{let v=u?.surfaces.find(k=>k.name===f);return{name:f,label:v?.title||f,meta:`${v?.type||"form"} \xB7 ${v?.accessMode||"public"}`}});return e("div",{class:"workflow-detail",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A ",e("a",{href:"/explorer/workflows",children:"Workflows"})," \u203A ",n.name]}),e("header",{class:"detail-header",children:[e("h1",{children:[n.name,c&&e(cs,{drift:c})]}),e("div",{class:"detail-header-actions",children:r.length>0&&e("a",{href:`/explorer/workflows/${n.name}/logs`,class:"header-action-btn",children:[e("i",{"data-lucide":"logs",class:"btn-icon"})," View Run Logs"]})}),e("div",{style:"width: 100%",children:[e("span",{class:"detail-meta",children:[n.schedule?P(n.schedule,u?.workspace.timezone):n.webhook?"Webhook trigger":"Manual trigger",n.steps?` \xB7 ${_e(n.steps)} steps`:""]}),n.description&&e("span",{class:"detail-meta",style:"display: block; margin-top: 4px",children:n.description}),e("div",{class:"cli-hint",children:["Run via CLI: ",e("code",{children:["mug run ",n.name]})]})]})]}),l&&e(us,{item:l}),e(K,{connections:[{category:"Sync Sources",icon:"cloud-download",path:"sources",items:m},{category:"Databases",icon:"database",path:"databases",items:b},{category:"Surfaces",icon:"layout-panel-left",path:"surfaces",items:y}]}),e("div",{class:"detail-props",children:[e(J,{label:"Source",value:n.sourceFile??"\u2014",warn:!n.sourceExists}),n.schedule&&e(J,{label:"Schedule",value:`${P(n.schedule,u?.workspace.timezone)} (${n.schedule})`}),n.webhook&&e(J,{label:"Trigger",value:"Webhook"})]}),n.steps&&e("div",{class:"step-flow-section",children:[e("div",{class:"step-flow-section-header",children:[e("i",{"data-lucide":"workflow",class:"step-icon"}),e("span",{class:"step-flow-section-title",children:"Steps"})]}),e(Ae,{steps:n.steps})]}),n.parseError&&e("div",{class:"step-flow-parse-error",children:["Could not parse workflow steps: ",n.parseError]})]})}function J({label:t,value:n,warn:s}){return e("div",{class:"prop-row",children:[e("span",{class:"prop-label",children:t}),e("span",{class:`prop-value ${s?"prop-warn":""}`,children:[n,s?" (missing)":""]})]})}function cs({drift:t}){if(!t||t==="synced")return null;let n={diverged:"modified","local-only":"not deployed","remote-only":"remote only"};return e("span",{class:`card-badge card-badge-${t}`,children:n[t]||t})}function us({item:t}){return e("section",{class:"detail-section",children:[e("h2",{children:"Schedule Health"}),e("div",{class:"detail-props",children:[e(J,{label:"Last Run",value:t.lastRun?t.lastRun.slice(0,19).replace("T"," "):"Never"}),e(J,{label:"Status",value:t.lastError?`Error: ${t.lastError}`:t.lastResult??"\u2014",warn:!!t.lastError}),e(J,{label:"Next Run",value:t.nextAlarm?t.nextAlarm.slice(0,19).replace("T"," "):"\u2014"}),(t.retryCount??0)>0&&e(J,{label:"Retry Count",value:String(t.retryCount)}),t.recentFailures&&t.recentFailures.length>0&&e(J,{label:"Recent Failures",value:t.recentFailures.map(n=>`${n.at.slice(0,16).replace("T"," ")}: ${n.error}`).join("; "),warn:!0})]})]})}function _e(t){let n=0;for(let s of t)n++,s.type==="loop"&&(n+=_e(s.steps??[])),s.type==="branch"&&(n+=_e(s.if??[]),s.else&&(n+=_e(s.else)),s.after&&(n+=_e(s.after)));return n}function rn({name:t}){let[n,s]=h(null),[a,o]=h(null),[r,i]=h(null),[l,d]=h({}),[u,g]=h(null);S(()=>{t&&(fetch(`/explorer/api/workflows/${encodeURIComponent(t)}/runs`).then(p=>p.ok?p.json():Promise.reject(new Error(`${p.status}`))).then(p=>s(p.runs??[])).catch(p=>o(p.message)),fetch(`/explorer/api/workflows/${encodeURIComponent(t)}`).then(p=>p.ok?p.json():null).then(p=>{p?.steps&&g(p.steps)}).catch(()=>{}))},[t]);function c(p){!l[p]&&t&&fetch(`/explorer/api/workflows/${encodeURIComponent(t)}/runs/${encodeURIComponent(p)}`).then(w=>w.ok?w.json():null).then(w=>{if(!w)return;let b=w.run?w:{run:{id:w.id,status:w.status,startedAt:w.started_at??w.startedAt,completedAt:w.completed_at??w.completedAt,durationMs:w.duration_ms??w.durationMs,error:w.error},steps:(w.steps??[]).map(y=>({name:y.step_name??y.name,type:y.step_type??y.type,startedAt:y.started_at??y.startedAt,completedAt:y.completed_at??y.completedAt,durationMs:y.duration_ms??y.durationMs,input:y.input,output:y.output,error:y.error,tokensUsed:y.tokens_used??y.tokensUsed}))};d(y=>({...y,[p]:b}))})}function m(p){r===p?i(null):(i(p),c(p))}return a?e("div",{class:"explorer-error",children:["Failed to load run logs: ",a]}):n?e("div",{class:"workflow-logs",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A ",e("a",{href:"/explorer/workflows",children:"Workflows"})," \u203A ",e("a",{href:`/explorer/workflows/${t}`,children:t})," \u203A Run Logs"]}),e("header",{class:"detail-header",children:[e("h1",{children:[e("i",{"data-lucide":"logs",class:"section-icon"})," ",t,": Run Logs"]}),e("span",{class:"detail-meta",children:[n.length," run",n.length!==1?"s":""]})]}),n.length===0?e("p",{class:"explorer-empty",children:["No runs yet. Run this workflow via ",e("code",{children:["mug run ",t]})]}):e("table",{class:"sessions-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Status"}),e("th",{children:"Duration"}),e("th",{children:"Error"}),e("th",{children:"Date"})]})}),e("tbody",{children:n.map(p=>{let w=r===p.id,b=l[p.id];return e(L,{children:[e("tr",{class:`${p.error?"session-row-error":""} ${w?"session-row-open":""}`,onClick:()=>m(p.id),children:[e("td",{children:e("span",{class:`run-summary-badge ${p.status==="complete"?"run-summary-complete":"run-summary-errored"}`,children:p.status})}),e("td",{class:"sessions-td-duration",children:p.durationMs!=null?sn(p.durationMs):"\u2014"}),e("td",{class:"sessions-td-goal",children:p.error?p.error.slice(0,80)+(p.error.length>80?"\u2026":""):"\u2014"}),e("td",{class:"sessions-td-date",children:ds(p.startedAt)})]},p.id),w&&e("tr",{class:"session-detail-row",children:e("td",{colSpan:4,children:b?e("div",{class:"session-detail-inline",children:[e("div",{class:"session-detail-meta",children:[e("span",{children:["Status: ",b.run.status]}),b.run.durationMs!=null&&e("span",{children:["Duration: ",sn(b.run.durationMs)]}),e("span",{children:[b.steps.length," steps"]})]}),b.run.error&&e("div",{class:"session-detail-block",children:[e("span",{class:"session-detail-label",children:"Error"}),e("pre",{class:"session-detail-pre session-error",children:b.run.error})]}),u&&e(Ae,{steps:u,runData:b.steps})]}):e("div",{class:"explorer-loading",children:"Loading..."})})})]})})})]})]}):e("div",{class:"explorer-loading",children:"Loading run logs..."})}function ds(t){try{let n=new Date(t);return`${n.getMonth()+1}/${n.getDate()}/${String(n.getFullYear()).slice(2)} ${n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}`}catch{return t}}function sn(t){return t<1e3?`${t}ms`:t<6e4?`${(t/1e3).toFixed(1)}s`:`${Math.floor(t/6e4)}m ${Math.round(t%6e4/1e3)}s`}function an({name:t}){let[n,s]=h(null),[a,o]=h(null),[r,i]=h(null),l=N();if(S(()=>{t&&(fetch(`/explorer/api/sources/${encodeURIComponent(t)}`).then(c=>c.ok?c.json():Promise.reject(new Error(`${c.status}`))).then(s).catch(c=>o(c.message)),fetch("/explorer/api/overview").then(c=>c.json()).then(c=>{let m=c.scheduleHealth?.find(p=>p.item_type==="source"&&p.item_name===t);m&&i(m)}).catch(()=>{}))},[t]),a)return e("div",{class:"explorer-error",children:["Failed to load source: ",a]});if(!n)return e("div",{class:"explorer-loading",children:"Loading source..."});let d=ps(n.syncs),u=n.syncs.reduce((c,m)=>c+m.tables.length,0),g=l?.sources.find(c=>c.name===n.name)?.drift;return e("div",{class:"source-detail",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A ",e("a",{href:"/explorer/sources",children:"Sync Sources"})," \u203A ",n.name]}),e("header",{class:"detail-header",children:[e("h1",{children:[n.name,g&&e(fs,{drift:g})]}),e("span",{class:"detail-meta",children:[d.length," database",d.length!==1?"s":""," \xB7 ",u," table",u!==1?"s":""," \xB7 ",n.syncs.length," sync",n.syncs.length!==1?"s":""]})]}),r&&e(gs,{item:r,label:"Sync"}),e("div",{class:"detail-props",children:[e(q,{label:"API",value:n.baseUrl||"\u2014"}),e(q,{label:"Auth",value:n.authType})]}),e("div",{class:"source-syncs-section",children:[e("div",{class:"step-flow-section-header",children:[e("i",{"data-lucide":"database",class:"step-icon"}),e("span",{class:"step-flow-section-title",children:"Databases"})]}),d.map(c=>e(ms,{db:c,timezone:l?.workspace.timezone},c.database))]})]})}function ps(t){let n=new Map;for(let s of t){let a=s.database??"unknown",o=n.get(a);o||(o={database:a,syncs:[],tables:[]},n.set(a,o)),o.syncs.push(s);for(let r of s.tables)o.tables.find(i=>i.name===r.name)||o.tables.push(r)}return[...n.values()]}function ms({db:t,timezone:n}){let[s,a]=h(!1),o=t.syncs.map(r=>r.description).filter(Boolean);return e("div",{class:"source-sync-card",children:[e("div",{class:"source-sync-header",onClick:()=>a(!s),style:"cursor: pointer;",children:[e("i",{"data-lucide":"database",class:"step-icon step-icon-query"}),e("div",{class:"source-sync-title",children:[e("span",{class:"step-label",children:t.database}),o.length>0&&e("span",{class:"source-sync-desc",children:o.join(". ")})]}),e("span",{class:"source-sync-schedule",children:[t.syncs.length," sync",t.syncs.length!==1?"s":""," \xB7 ",t.tables.length," table",t.tables.length!==1?"s":""]}),e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:`step-expand-icon toggle-icon ${s?"toggle-icon-open":""}`,children:e("path",{d:"m9 18 6-6-6-6"})})]}),s&&e(L,{children:t.syncs.map(r=>e("div",{class:"source-sync-group",children:[e("div",{class:"source-sync-props",children:[e("div",{class:"source-sync-name",children:[e("i",{"data-lucide":"cloud-download",class:"source-sync-name-icon"}),r.name]}),e(q,{label:"Source",value:r.sourceFile,warn:!r.sourceExists}),r.schedule&&e(q,{label:"Schedule",value:`${P(r.schedule,n)} (${r.schedule})`})]}),r.tables.length>0&&e("div",{class:"source-tables",children:r.tables.map(i=>e("div",{class:"source-table-row",children:[e("i",{"data-lucide":"table",class:"source-table-icon"}),e("a",{href:`/explorer/databases/${t.database}/${i.name}`,class:"source-table-name",children:i.name}),e("span",{class:"source-table-pk",children:["pk: ",i.primaryKey]}),i.endpoint&&e("span",{class:"source-table-endpoint",children:i.endpoint}),i.description&&e("div",{class:"source-table-desc",children:i.description})]},i.name))})]},r.name))})]})}function fs({drift:t}){if(!t||t==="synced")return null;let n={diverged:"modified","local-only":"not deployed","remote-only":"remote only"};return e("span",{class:`card-badge card-badge-${t}`,children:n[t]||t})}function gs({item:t,label:n}){let s=n||"Schedule";return e("section",{class:"detail-section",children:[e("h2",{children:[s," Health"]}),e("div",{class:"detail-props",children:[e(q,{label:`Last ${s}`,value:t.lastRun?t.lastRun.slice(0,19).replace("T"," "):"Never"}),e(q,{label:"Status",value:t.lastError?`Error: ${t.lastError}`:t.lastResult??"\u2014",warn:!!t.lastError}),e(q,{label:`Next ${s}`,value:t.nextAlarm?t.nextAlarm.slice(0,19).replace("T"," "):"\u2014"}),(t.retryCount??0)>0&&e(q,{label:"Retry Count",value:String(t.retryCount)}),t.recentFailures&&t.recentFailures.length>0&&e(q,{label:"Recent Failures",value:t.recentFailures.map(a=>`${a.at.slice(0,16).replace("T"," ")}: ${a.error}`).join("; "),warn:!0})]})]})}function q({label:t,value:n,warn:s}){return e("div",{class:"prop-row",children:[e("span",{class:"prop-label",children:t}),e("span",{class:`prop-value ${s?"prop-warn":""}`,children:[n,s?" (missing)":""]})]})}function on({name:t}){let[n,s]=h(null),[a,o]=h(null),r=N();if(S(()=>{t&&fetch(`/explorer/api/surfaces/${encodeURIComponent(t)}`).then(u=>u.ok?u.json():Promise.reject(new Error(`${u.status}`))).then(s).catch(u=>o(u.message))},[t]),a)return e("div",{class:"explorer-error",children:["Failed to load surface: ",a]});if(!n)return e("div",{class:"explorer-loading",children:"Loading surface..."});let i=r?.surfaces.find(u=>u.name===n.name)?.drift,l=n.databases.map(u=>{let g=r?.databases.find(c=>c.name===u);return{name:u,meta:g?`${g.tableCount} table${g.tableCount!==1?"s":""} \xB7 ${re(g.sizeBytes)}`:void 0}}),d=n.workflows.map(u=>{let g=r?.workflows.find(c=>c.name===u);return{name:u,meta:g?.schedule?`Schedule: ${g.schedule}`:g?.webhook?"Webhook":"Manual"}});return e("div",{class:"surface-detail",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A ",e("a",{href:"/explorer/surfaces",children:"Surfaces"})," \u203A ",n.title||n.name]}),e("header",{class:"detail-header",children:[e("h1",{children:[n.title||n.name,i&&e(hs,{drift:i})]}),e("span",{class:"detail-meta",children:[n.type," \xB7 ",n.accessMode]})]}),e(K,{connections:[{category:"Databases",icon:"database",path:"databases",items:l},{category:"Workflows",icon:"zap",path:"workflows",items:d}]}),e("div",{class:"detail-props",children:[e(it,{label:"Type",value:n.type}),e(it,{label:"Access",value:n.accessMode}),e(it,{label:"Config",value:`surfaces/${n.name}.json`})]}),e("div",{class:"detail-actions",children:e("a",{href:n.liveUrl,class:"action-link",target:"_blank",children:"Open surface \u2192"})})]})}function hs({drift:t}){if(!t||t==="synced")return null;let n={diverged:"modified","local-only":"not deployed","remote-only":"remote only"};return e("span",{class:`card-badge card-badge-${t}`,children:n[t]||t})}function it({label:t,value:n}){return e("div",{class:"prop-row",children:[e("span",{class:"prop-label",children:t}),e("span",{class:"prop-value",children:n})]})}function ln({name:t}){let[n,s]=h(null),[a,o]=h(null),[r,i]=h(!1),[l,d]=h(!1),[u,g]=h(new Set),[c,m]=h(null),p=N();if(S(()=>{t&&fetch(`/explorer/api/agents/${encodeURIComponent(t)}`).then(f=>f.ok?f.json():Promise.reject(new Error(`${f.status}`))).then(s).catch(f=>o(f.message))},[t]),S(()=>{!t||c||fetch(`/explorer/api/agents/${encodeURIComponent(t)}/sessions`).then(f=>f.ok?f.json():Promise.reject(new Error(`${f.status}`))).then(f=>m(f.sessions)).catch(()=>m([]))},[t]),a)return e("div",{class:"explorer-error",children:["Failed to load agent: ",a]});if(!n)return e("div",{class:"explorer-loading",children:"Loading agent..."});let w=(p?.agents??[]).find(f=>f.name===n.name)?.drift,b=n.workflows.map(f=>{let v=p?.workflows.find(k=>k.name===f);return{name:f,meta:v?.schedule?`Schedule: ${v.schedule}`:v?.webhook?"Webhook":"Manual"}}),y=typeof n.memory=="boolean"?n.memory:!!(n.memory?.entities||n.memory?.outcomes||n.memory?.struggles);return e("div",{class:"agent-detail",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A ",e("a",{href:"/explorer/agents",children:"Agents"})," \u203A ",n.name]}),e("header",{class:"detail-header",children:[e("h1",{children:[e("i",{"data-lucide":"bot",class:"section-icon"})," ",n.name,w&&e(ws,{drift:w})]}),e("div",{class:"detail-header-actions",children:[e("a",{href:`/explorer/agents/${n.name}/sessions`,class:"header-action-btn",children:[e("i",{"data-lucide":"logs",class:"btn-icon"})," View Session Logs"]}),y&&e("a",{href:`/explorer/agents/${n.name}/brain`,class:"header-action-btn",children:[e("i",{"data-lucide":"brain",class:"btn-icon"})," View Brain"]})]})]}),b.length>0&&e(K,{connections:[{category:"Workflows",icon:"zap",path:"workflows",items:b}]}),e("div",{class:"detail-props",children:[n.requireApproval.length>0&&e(Z,{label:"Require Approval",value:n.requireApproval.join(", ")}),e("div",{class:"prop-group-label",children:"Model"}),typeof n.model=="object"?e(L,{children:[n.model.fast&&e(Te,{label:"fast",model:n.model.fast}),n.model.balanced&&e(Te,{label:"balanced",model:n.model.balanced}),n.model.powerful&&e(Te,{label:"powerful",model:n.model.powerful})]}):e(Te,{model:typeof n.model=="string"?n.model:"Dynamic routing"}),e("div",{class:"prop-group-label",children:["Tools ",e("span",{class:"prop-group-tooltip",children:[e("i",{"data-lucide":"info",class:"prop-group-info-icon"}),e("span",{class:"prop-group-tooltip-text",children:["Grants control which platform tools this agent can use. ",e("a",{class:"tooltip-link",onClick:(f=>{f.stopPropagation(),d(!0)}),children:"Learn more"})]})]})]}),n.tools.length>0?n.tools.map(f=>e(Z,{label:f,value:vs[f]??"Custom tool",indent:!0},f)):e(Z,{label:"\u2014",value:"No tools granted",indent:!0}),e("div",{class:"prop-group-label",children:"Memory"}),e(Z,{label:"Brain",value:y?"Enabled":"\u2014",indent:!0}),e("div",{class:"prop-group-label",children:"Chat"}),e(Z,{label:"Slack",value:n.chat?`Enabled (@${n.slackName||n.name})`:"\u2014",indent:!0}),e("div",{class:"prop-group-label",children:["Session Caps ",e("span",{class:"prop-group-tooltip",children:[e("i",{"data-lucide":"info",class:"prop-group-info-icon"}),e("span",{class:"prop-group-tooltip-text",children:"Safety limits per agent session. Turns = round trips with the AI model. Credits = metered AI usage (~$0.001 per credit). Duration = wall-clock time. When a cap is hit, the agent delivers partial results."})]})]}),e(Z,{label:"Max Turns",value:n.caps.maxTurns?String(n.caps.maxTurns):"\u2014",indent:!0}),e(Z,{label:"Max Credits",value:n.caps.maxCredits?String(n.caps.maxCredits):"\u2014",indent:!0}),e(Z,{label:"Max Duration",value:n.caps.maxDuration?`${n.caps.maxDuration}s`:"\u2014",indent:!0})]}),n.soulContent&&e("div",{class:"detail-props",children:[e("div",{class:"prop-row prop-row-accordion",onClick:()=>i(!r),children:e("span",{class:"prop-label",children:["SOUL.md",e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:`toggle-icon ${r?"toggle-icon-open":""}`,children:e("path",{d:"m9 18 6-6-6-6"})})]})}),r&&e("pre",{class:"soul-content",children:n.soulContent})]}),(n.skills.length>0||n.sharedSkills.length>0)&&e("div",{class:"detail-props",children:[e("div",{class:"prop-group-label",children:"Skills"}),n.skills.map(f=>{let v=`skill:${f.name}`,k=u.has(v);return e(L,{children:[e("div",{class:"prop-row prop-row-indent prop-row-accordion",onClick:()=>{let _=new Set(u);k?_.delete(v):_.add(v),g(_)},children:e("span",{class:"prop-label",children:[f.name,e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:`toggle-icon ${k?"toggle-icon-open":""}`,children:e("path",{d:"m9 18 6-6-6-6"})})]})},v),k&&f.content&&e("pre",{class:"soul-content",children:f.content})]})}),n.sharedSkills.length>0&&e(L,{children:[e("div",{class:"prop-row prop-row-indent skill-tree-shared",children:e("span",{class:"prop-label",children:"shared"})}),n.sharedSkills.map(f=>{let v=`shared:${f.name}`,k=u.has(v);return e(L,{children:[e("div",{class:"prop-row prop-row-indent prop-row-accordion skill-shared-item",onClick:()=>{let _=new Set(u);k?_.delete(v):_.add(v),g(_)},children:e("span",{class:"prop-label",children:[f.name,e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:`toggle-icon ${k?"toggle-icon-open":""}`,children:e("path",{d:"m9 18 6-6-6-6"})})]})},v),k&&f.content&&e("pre",{class:"soul-content",children:f.content})]})})]})]}),l&&e(bs,{onClose:()=>d(!1),granted:n.tools})]})}var vs={query:"Read-only SQL queries",search:"Semantic data search",ask:"RAG question answering",notify:"Send email and SMS",http:"External API requests",ai:"Sub-AI model calls",trigger_workflow:"Invoke other workflows",workspace:"Workspace management"},_s=[{grant:"query",tools:"query",description:"Run read-only SQL queries against workspace databases"},{grant:"search",tools:"search_data",description:"Semantic search across synced data sources"},{grant:"ask",tools:"ask_question",description:"RAG-powered question answering over workspace data"},{grant:"notify",tools:"send_email, send_sms",description:"Send notifications via email and SMS"},{grant:"http",tools:"http_request",description:"Make external HTTP/API requests"},{grant:"ai",tools:"ai_call",description:"Call AI models for sub-tasks (credits metered)"},{grant:"trigger_workflow",tools:"trigger_workflow",description:"Invoke other workflows by name"},{grant:"workspace",tools:"workspace tools",description:"Workspace management operations"}];function bs({onClose:t,granted:n}){return e("div",{class:"modal-overlay",onClick:s=>{s.target.classList.contains("modal-overlay")&&t()},children:e("div",{class:"modal-content",children:[e("div",{class:"modal-header",children:[e("h2",{children:"Agent Tool Grants"}),e("button",{class:"modal-close",onClick:t,children:e("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[e("path",{d:"M18 6 6 18"}),e("path",{d:"m6 6 12 12"})]})})]}),e("p",{class:"modal-description",children:["The ",e("code",{children:"tools"})," field in agent.json is a grant list that controls which platform-provided tools this agent can use. Each grant enables one or more runtime tools."]}),e("table",{class:"modal-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Grant"}),e("th",{children:"Runtime Tools"}),e("th",{children:"Description"})]})}),e("tbody",{children:_s.map(s=>e("tr",{class:n.includes(s.grant)?"modal-row-active":"",children:[e("td",{class:"modal-td-grant",children:e("code",{children:s.grant})}),e("td",{class:"modal-td-tools",children:e("code",{children:s.tools})}),e("td",{children:s.description})]},s.grant))})]}),e("p",{class:"modal-footnote",children:["Auto-granted tools (no config needed): ",e("code",{children:"deliver_output"})," (always), memory tools when ",e("code",{children:"memory: true"}),", ",e("code",{children:"load_skill"})," when skills are configured."]})]})})}function ys(t){return t.startsWith("@cf/")?`https://developers.cloudflare.com/ai/models/${t.replace(/@/g,"%40")}/`:`https://developers.cloudflare.com/ai-gateway/models/${encodeURIComponent(t)}/`}function Te({label:t,model:n}){let s=ys(n);return e("div",{class:"prop-row prop-row-indent",children:[t&&e("span",{class:"prop-label",children:[t,":"]}),s?e("a",{class:"prop-value model-link",href:s,target:"_blank",rel:"noopener",children:n}):e("span",{class:"prop-value",children:n})]})}function ws({drift:t}){if(!t||t==="synced")return null;let n={diverged:"modified","local-only":"not deployed","remote-only":"remote only"};return e("span",{class:`card-badge card-badge-${t}`,children:n[t]||t})}function Z({label:t,value:n,indent:s}){return e("div",{class:`prop-row${s?" prop-row-indent":""}`,children:[e("span",{class:"prop-label",children:t}),e("span",{class:"prop-value",children:n})]})}function ks(t){let n=new Map;for(let s of t){let a=s.thread??s.runId,o=n.get(a)??[];o.push(s),n.set(a,o)}return[...n.entries()].map(([s,a])=>(a.sort((o,r)=>new Date(o.startedAt).getTime()-new Date(r.startedAt).getTime()),{thread:s,sessions:a,totalDuration:a.reduce((o,r)=>o+(r.durationMs??0),0),totalCredits:a.reduce((o,r)=>o+(r.tokensUsed??0),0),firstAt:a[0].startedAt,lastGoal:a[a.length-1].goal||a[0].goal})).sort((s,a)=>new Date(a.firstAt).getTime()-new Date(s.firstAt).getTime())}function ut({name:t}){let[n,s]=h(null),[a,o]=h(null),[r,i]=h(null),[l,d]=h(null),[u,g]=h({});S(()=>{t&&fetch(`/explorer/api/agents/${encodeURIComponent(t)}/sessions`).then(b=>b.ok?b.json():Promise.reject(new Error(`${b.status}`))).then(b=>s(b.sessions)).catch(b=>o(b.message))},[t]);function c(b){!u[b]&&t&&fetch(`/explorer/api/agents/${encodeURIComponent(t)}/sessions/${encodeURIComponent(b)}`).then(y=>y.ok?y.json():null).then(y=>{y&&g(f=>({...f,[b]:y}))})}function m(b){r===b?(i(null),d(null)):(i(b),d(null))}function p(b){l===b?d(null):(d(b),c(b))}if(a)return e("div",{class:"explorer-error",children:["Failed to load sessions: ",a]});if(!n)return e("div",{class:"explorer-loading",children:"Loading sessions..."});let w=ks(n);return e("div",{class:"agent-sessions",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A ",e("a",{href:"/explorer/agents",children:"Agents"})," \u203A ",e("a",{href:`/explorer/agents/${t}`,children:t})," \u203A Session Logs"]}),e("header",{class:"detail-header",children:[e("h1",{children:[e("i",{"data-lucide":"logs",class:"section-icon"})," ",t,": Sessions"]}),e("span",{class:"detail-meta",children:[w.length," session",w.length!==1?"s":""]})]}),n.length===0?e("p",{class:"explorer-empty",children:"No sessions yet. Run a workflow that invokes this agent."}):e("table",{class:"sessions-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Goal"}),e("th",{children:"Turns"}),e("th",{children:"Duration"}),e("th",{children:"Credits"}),e("th",{children:"Date"})]})}),e("tbody",{children:w.map(b=>{let y=r===b.thread,f=b.sessions.length===1,v=b.sessions[0];if(f){let k=l===v.runId,_=u[v.runId];return e(L,{children:[e("tr",{class:`${v.error?"session-row-error":""} ${k?"session-row-open":""}`,onClick:()=>p(v.runId),children:[e("td",{class:"sessions-td-goal",children:[v.goal.slice(0,80)||"\u2014",v.goal.length>80?"\u2026":""]}),e("td",{class:"sessions-td-duration",children:"1"}),e("td",{class:"sessions-td-duration",children:v.durationMs!=null?Be(v.durationMs):"\u2014"}),e("td",{class:"sessions-td-duration",children:v.tokensUsed??"\u2014"}),e("td",{class:"sessions-td-date",children:ct(v.startedAt)})]},v.runId),k&&e(cn,{detail:_,session:v})]})}return e(L,{children:[e("tr",{class:`session-group-row ${y?"session-row-open":""}`,onClick:()=>m(b.thread),children:[e("td",{class:"sessions-td-goal",children:[e("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:`toggle-icon ${y?"toggle-icon-open":""}`,children:e("path",{d:"m9 18 6-6-6-6"})}),b.lastGoal.slice(0,70)||"\u2014",b.lastGoal.length>70?"\u2026":""]}),e("td",{class:"sessions-td-duration",children:b.sessions.length}),e("td",{class:"sessions-td-duration",children:Be(b.totalDuration)}),e("td",{class:"sessions-td-duration",children:b.totalCredits}),e("td",{class:"sessions-td-date",children:ct(b.firstAt)})]},b.thread),y&&b.sessions.map(k=>{let _=l===k.runId,F=u[k.runId];return e(L,{children:[e("tr",{class:`session-child-row ${k.error?"session-row-error":""} ${_?"session-row-open":""}`,onClick:A=>{A.stopPropagation(),p(k.runId)},children:[e("td",{class:"sessions-td-goal session-child-goal",children:[k.goal.slice(0,70)||"\u2014",k.goal.length>70?"\u2026":""]}),e("td",{class:"sessions-td-duration"}),e("td",{class:"sessions-td-duration",children:k.durationMs!=null?Be(k.durationMs):"\u2014"}),e("td",{class:"sessions-td-duration",children:k.tokensUsed??"\u2014"}),e("td",{class:"sessions-td-date",children:ct(k.startedAt)})]},k.runId),_&&e(cn,{detail:F,session:k})]})})]})})})]})]})}function cn({detail:t,session:n}){if(!t)return e("tr",{class:"session-detail-row",children:e("td",{colSpan:5,children:e("div",{class:"explorer-loading",children:"Loading..."})})});let s=t.steps?.[0],a=n.goal,o=n.response;if(s?.input)try{a=a||JSON.parse(s.input).goal||""}catch{}s?.output&&(o=o||s.output),!o&&t.result&&(o=t.result);let r={};if(n.model||n.toolsCalled||n.skillsLoaded)r={model:n.model,toolsCalled:n.toolsCalled,skillsLoaded:n.skillsLoaded};else if(s?.meta)try{r=JSON.parse(s.meta)}catch{}return e("tr",{class:"session-detail-row",children:e("td",{colSpan:5,children:e("div",{class:"session-detail-inline",children:[a&&e("div",{class:"session-detail-block",children:[e("span",{class:"session-detail-label",children:"Goal"}),e("pre",{class:"session-detail-pre",children:a})]}),o&&e("div",{class:"session-detail-block",children:[e("span",{class:"session-detail-label",children:"Response"}),e("pre",{class:"session-detail-pre",children:o})]}),(t.error||n.error)&&e("div",{class:"session-detail-block",children:[e("span",{class:"session-detail-label",children:"Error"}),e("pre",{class:"session-detail-pre session-error",children:t.error||n.error})]}),e("div",{class:"session-detail-meta",children:[e("span",{children:["Status: ",t.status]}),t.duration_ms!=null&&e("span",{children:["Duration: ",Be(t.duration_ms)]}),s?.tokens_used!=null&&e("span",{children:["Credits: ",s.tokens_used]}),r.model&&e("span",{children:["Model: ",r.model]}),r.toolsCalled&&r.toolsCalled.length>0&&e("span",{children:["Tools: ",r.toolsCalled.join(", ")]}),r.skillsLoaded&&r.skillsLoaded.length>0&&e("span",{children:["Skills: ",r.skillsLoaded.join(", ")]})]})]})})})}function ct(t){try{let n=new Date(t);return`${n.getMonth()+1}/${n.getDate()}/${String(n.getFullYear()).slice(2)} ${n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}`}catch{return t}}function Be(t){return t<1e3?`${t}ms`:t<6e4?`${(t/1e3).toFixed(1)}s`:`${Math.floor(t/6e4)}m ${Math.round(t%6e4/1e3)}s`}function un({name:t}){let[n,s]=h(null),[a,o]=h(null);return S(()=>{t&&fetch(`/explorer/api/agents/${encodeURIComponent(t)}/brain`).then(r=>r.ok?r.json():Promise.reject(new Error(`${r.status}`))).then(s).catch(r=>o(r.message))},[t]),a?e("div",{class:"explorer-error",children:["Failed to load brain: ",a]}):n?e("div",{class:"agent-brain",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A ",e("a",{href:"/explorer/agents",children:"Agents"})," \u203A ",e("a",{href:`/explorer/agents/${t}`,children:t})," \u203A Brain"]}),e("header",{class:"detail-header",children:[e("h1",{children:[e("i",{"data-lucide":"brain",class:"section-icon"})," ",t,": Brain"]}),e("span",{class:`card-badge card-badge-${n.source==="cloud"?"remote":"synced"}`,children:n.source})]}),n.source==="cloud"?e(xs,{data:n}):e(Ss,{data:n})]}):e("div",{class:"explorer-loading",children:"Loading brain..."})}function xs({data:t}){let[n,s]=h("logs"),[a,o]=h(null);return!t.mantra&&t.logs.length===0&&t.journal.length===0?e("div",{class:"brain-empty",children:e("p",{children:"This agent has no memories yet. It will start learning after its first session."})}):e(L,{children:[e("div",{class:"brain-tabs",children:[e("button",{class:n==="logs"?"active":"",onClick:()=>{s("logs"),o(null)},children:["Logs (",t.logs.length,")"]}),e("button",{class:n==="journal"?"active":"",onClick:()=>{s("journal"),o(null)},children:["Journal (",t.journal.length,")"]}),e("button",{class:n==="mantra"?"active":"",onClick:()=>s("mantra"),children:"MANTRA.md"})]}),n==="logs"&&(t.logs.length===0?e("p",{class:"brain-empty-tab",children:"No log entries."}):e("table",{class:"sessions-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Type"}),e("th",{children:"Content"}),e("th",{children:"Date"})]})}),e("tbody",{children:t.logs.map(i=>{let l=a===i.id;return e(L,{children:[e("tr",{class:l?"session-row-open":"",onClick:()=>o(l?null:i.id),children:[e("td",{children:e("span",{class:"struggle-badge",children:i.type})}),e("td",{class:"sessions-td-goal",children:[i.content.slice(0,80),i.content.length>80?"\u2026":""]}),e("td",{class:"sessions-td-date",children:dt(i.created_at)})]},i.id),l&&e("tr",{class:"session-detail-row",children:e("td",{colSpan:3,children:e("div",{class:"session-detail-inline",children:e("div",{class:"session-detail-block",children:e("pre",{class:"session-detail-pre",children:i.content})})})})})]})})})]})),n==="journal"&&(t.journal.length===0?e("p",{class:"brain-empty-tab",children:"No journal entries."}):e("table",{class:"sessions-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Content"}),e("th",{children:"Session"}),e("th",{children:"Date"})]})}),e("tbody",{children:t.journal.map(i=>{let l=a===i.id;return e(L,{children:[e("tr",{class:l?"session-row-open":"",onClick:()=>o(l?null:i.id),children:[e("td",{class:"sessions-td-goal",children:[i.content.slice(0,100),i.content.length>100?"\u2026":""]}),e("td",{class:"sessions-td-date",children:i.session_id||"\u2014"}),e("td",{class:"sessions-td-date",children:dt(i.created_at)})]},i.id),l&&e("tr",{class:"session-detail-row",children:e("td",{colSpan:3,children:e("div",{class:"session-detail-inline",children:e("div",{class:"session-detail-block",children:e("pre",{class:"session-detail-pre",children:i.content})})})})})]})})})]})),n==="mantra"&&(t.mantra?e(L,{children:[t.mantra.updated_at&&e("div",{style:"display: flex; justify-content: flex-end; margin-bottom: 6px",children:e("span",{class:"brain-item-date",children:["Updated ",dt(t.mantra.updated_at)]})}),e("pre",{class:"soul-content",children:t.mantra.content})]}):e("p",{class:"brain-empty-tab",children:"No mantra set."}))]})}function Ss({data:t}){let[n,s]=h("struggles");return t.entityCount===0&&t.struggleCount===0&&t.sessionCount===0?e("div",{class:"brain-empty",children:e("p",{children:"This agent has no memories yet. It will start learning after its first session."})}):e(L,{children:[e("div",{class:"brain-stats",children:[e(be,{label:"Entities",value:t.entityCount}),e(be,{label:"Facts",value:t.factCount}),e(be,{label:"Outcomes",value:t.outcomeCount}),e(be,{label:"Struggles",value:t.struggleCount}),e(be,{label:"Sessions",value:t.sessionCount})]}),e("div",{class:"brain-tabs",children:[e("button",{class:n==="struggles"?"active":"",onClick:()=>s("struggles"),children:["Struggles (",t.recentStruggles.length,")"]}),e("button",{class:n==="entities"?"active":"",onClick:()=>s("entities"),children:["Entities (",t.entities.length,")"]}),e("button",{class:n==="outcomes"?"active":"",onClick:()=>s("outcomes"),children:["Outcomes (",t.recentOutcomes.length,")"]}),e("button",{class:n==="sessions"?"active":"",onClick:()=>s("sessions"),children:["Sessions (",t.recentSessions.length,")"]})]}),n==="struggles"&&e("div",{class:"brain-list",children:t.recentStruggles.length===0?e("p",{class:"brain-empty-tab",children:"No struggles recorded."}):t.recentStruggles.map((o,r)=>e("div",{class:`brain-item ${o.resolved?"resolved":"unresolved"}`,children:[e("span",{class:`struggle-badge badge-${o.category}`,children:o.category.replace("_"," ")}),e("span",{class:"brain-item-text",children:o.description}),e("span",{class:"brain-item-date",children:o.recorded_at?.slice(0,10)})]},r))}),n==="entities"&&e("div",{class:"brain-list",children:t.entities.length===0?e("p",{class:"brain-empty-tab",children:"No entities remembered."}):t.entities.map((o,r)=>e("div",{class:"brain-item",children:[e("span",{class:"entity-name",children:o.name}),e("span",{class:"entity-type",children:o.type}),o.summary&&e("span",{class:"brain-item-text",children:o.summary}),e("span",{class:"brain-item-date",children:[o.mention_count," mention",o.mention_count!==1?"s":""]})]},r))}),n==="outcomes"&&e("div",{class:"brain-list",children:t.recentOutcomes.length===0?e("p",{class:"brain-empty-tab",children:"No outcomes logged."}):t.recentOutcomes.map((o,r)=>e("div",{class:"brain-item",children:[e("span",{class:`outcome-badge ${o.effective===!0?"effective":o.effective===!1?"ineffective":"unknown"}`,children:o.effective===!0?"\u2713":o.effective===!1?"\u2717":"?"}),e("span",{class:"brain-item-text",children:[e("strong",{children:o.action})," \u2014 ",o.result]}),e("span",{class:"brain-item-date",children:o.recorded_at?.slice(0,10)})]},r))}),n==="sessions"&&e("div",{class:"brain-list",children:t.recentSessions.length===0?e("p",{class:"brain-empty-tab",children:"No sessions recorded."}):t.recentSessions.map((o,r)=>e("div",{class:"brain-item",children:[e("span",{class:"session-workflow",children:o.workflow}),e("span",{class:"brain-item-text",children:o.goal?.slice(0,100)}),e("span",{class:"brain-item-date",children:[o.credits_used," credits \xB7 ",o.turns_used," turns",o.capped&&e("span",{class:"struggle-badge badge-cap_hit",children:"capped"})]})]},r))})]})}function dt(t){try{let n=t.includes("T")||t.includes("Z")?t:t.replace(" ","T")+"Z",s=new Date(n);return isNaN(s.getTime())?t:`${s.getMonth()+1}/${s.getDate()}/${String(s.getFullYear()).slice(2)} ${s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}`}catch{return t}}function be({label:t,value:n}){return e("div",{class:"brain-stat",children:[e("span",{class:"brain-stat-value",children:n}),e("span",{class:"brain-stat-label",children:t})]})}function pn({database:t,id:n}){let[s,a]=h(null),[o,r]=h(null),[i,l]=h(!1),[d,u]=h(!1);S(()=>{!t||!n||fetch(`/explorer/api/changesets/${encodeURIComponent(t)}/${encodeURIComponent(n)}`).then(p=>p.ok?p.json():Promise.reject(new Error(`${p.status}`))).then(p=>a(p.operations??[])).catch(p=>r(p.message))},[t,n]);let g=async()=>{if(!(!t||!n||i)&&confirm(`Roll back changeset ${n}? This will undo all operations.`)){l(!0);try{let p=await fetch(`/explorer/api/changesets/${encodeURIComponent(t)}/${encodeURIComponent(n)}/rollback`,{method:"POST"});if(!p.ok)throw new Error(await p.text());u(!0)}catch(p){alert(`Rollback failed: ${p.message}`)}finally{l(!1)}}};if(o)return e("div",{class:"explorer-error",children:["Failed to load changeset: ",o]});if(!s)return e("div",{class:"explorer-loading",children:"Loading changeset..."});let c=[...new Set(s.map(p=>p.table_name))],m=s[0]?.source??"unknown";return e("div",{class:"changeset-detail",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A ",e("a",{href:`/explorer/databases/${t}`,children:t})," \u203A Changeset"]}),e("header",{class:"detail-header",children:[e("h1",{children:[e("i",{"data-lucide":"git-commit",class:"section-icon"})," Changeset"]}),e("span",{class:"detail-meta",children:[s.length," operation",s.length!==1?"s":""," \xB7 ",c.join(", ")]})]}),e("div",{class:"detail-props",children:[e(le,{label:"ID",value:n??""}),e(le,{label:"Source",value:m}),e(le,{label:"Database",value:t??""}),e(le,{label:"Tables",value:c.join(", ")}),e(le,{label:"Operations",value:String(s.length)}),s[0]?.created_at&&e(le,{label:"Created",value:Ls(s[0].created_at)})]}),!d&&s.length>0&&e("button",{class:"rollback-btn",onClick:g,disabled:i,children:[e("i",{"data-lucide":"undo-2",class:"btn-icon"}),i?"Rolling back...":"Rollback changeset"]}),d&&e("div",{class:"rollback-done",children:"Changeset rolled back successfully."}),e("section",{class:"detail-section",children:[e("h2",{children:"Operations"}),s.map(p=>e("div",{class:`changeset-op changeset-op-${p.operation.toLowerCase()}`,children:[e("div",{class:"changeset-op-header",children:[e("span",{class:`changeset-op-badge op-${p.operation.toLowerCase()}`,children:p.operation}),e("span",{class:"changeset-op-table",children:p.table_name}),p.row_id&&e("span",{class:"changeset-op-rowid",children:["row ",p.row_id]})]}),(p.before_state||p.after_state)&&e("div",{class:"changeset-diff",children:[p.before_state&&e("div",{class:"changeset-before",children:[e("span",{class:"diff-label",children:"Before"}),e("pre",{children:dn(p.before_state)})]}),p.after_state&&e("div",{class:"changeset-after",children:[e("span",{class:"diff-label",children:"After"}),e("pre",{children:dn(p.after_state)})]})]})]},p.id))]})]})}function le({label:t,value:n}){return e("div",{class:"prop-row",children:[e("span",{class:"prop-label",children:t}),e("span",{class:"prop-value",children:n})]})}function Ls(t){try{let n=new Date(t);return n.toLocaleDateString(void 0,{month:"short",day:"numeric"})+" "+n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return t}}function dn(t){try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}}function pt({splat:t}){let n=t||"",[s,a]=h(null),[o,r]=h(null);if(S(()=>{let l=n?`/explorer/api/files/${encodeURIComponent(n)}`:"/explorer/api/files";fetch(l).then(d=>d.ok?d.json():Promise.reject(new Error(`${d.status}`))).then(a).catch(d=>r(d.message))},[n]),o)return e("div",{class:"explorer-error",children:["Failed to load files: ",o]});if(!s)return e("div",{class:"explorer-loading",children:"Loading files..."});let i=n?n.split("/").filter(Boolean):[];return e("div",{class:"file-browser",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A"," ",e("a",{href:"/explorer/files",children:"Files"}),i.map((l,d)=>{let u="/explorer/files/"+i.slice(0,d+1).join("/");return e("span",{children:[" ","\u203A ",e("a",{href:u,children:l})]},d)})]}),e("header",{class:"detail-header",children:[e("h1",{children:n||"Files"}),e("span",{class:"detail-meta",children:[s.files.length," item",s.files.length!==1?"s":""]})]}),s.files.length===0?e("div",{class:"empty-state",children:"No files in this directory."}):e("div",{class:"card-list",children:s.files.map(l=>{let d=l.isDir?`/explorer/files/${n?n+"/":""}${l.name}`:`/_files/${n?n+"/":""}${l.name}`,u=["png","jpg","jpeg","gif","webp","svg"].includes(l.type);return e("a",{href:d,class:"card",target:l.isDir?void 0:"_blank",children:[u&&!l.isDir&&e("img",{class:"file-preview",src:`/_files/${n?n+"/":""}${l.name}`,alt:l.name}),e("span",{class:"card-name",children:l.isDir?`${l.name}/`:l.name}),e("span",{class:"card-meta",children:l.isDir?"directory":Cs(l.sizeBytes)})]},l.name)})})]})}function Cs(t){return t<1e3?`${t} B`:t<1e6?`${(t/1e3).toFixed(1)} KB`:`${(t/1e6).toFixed(1)} MB`}var mn=[{key:"operations",label:"Operations",icon:"activity",format:X},{key:"ai_credits",label:"AI credits",icon:"sparkles",format:X},{key:"records",label:"Database records",icon:"database",format:X},{key:"storage_bytes",label:"File storage",icon:"hard-drive",format:Hs},{key:"email",label:"Email sends",icon:"mail",format:X},{key:"sms",label:"SMS sends",icon:"message-square",format:X}],fn={operations:"Workflow step executions, external API write actions (create/update/delete), and synced record changes (inserts and updates only).",ai_credits:"1 credit \u2248 $0.001 USD. Bring your own key to bypass Mug credits."},$s=["January","February","March","April","May","June","July","August","September","October","November","December"];function Ds(t){let n=t.split("-");return`${$s[parseInt(n[1])-1]} ${n[0]}`}function gn(){let t=new Date;return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}`}function hn(){let[t,n]=h(null),[s,a]=h(null),[o,r]=h(null),[i,l]=h(gn()),[d,u]=h(!1);if(S(()=>{fetch("/explorer/api/workspace-info").then(_=>_.json()).then(_=>{_.error||a(_)}).catch(()=>{})},[]),S(()=>{r(null),fetch(`/explorer/api/usage?period=${i}`).then(_=>_.json()).then(_=>{_.error?r(_.error):n(_)}).catch(_=>r(_.message))},[i]),o)return e("div",{class:"explorer-error",children:["Failed to load usage: ",o]});if(!t)return e("div",{class:"explorer-loading",children:"Loading usage data..."});let g=t.dimensions??{},c=t.tier.charAt(0).toUpperCase()+t.tier.slice(1),m=Object.values(g).some(_=>_.base_limit>0&&_.used/_.base_limit*100>=80),p=Object.entries(g).reduce((_,[F,A])=>{let T=A.base_limit>0?A.used/A.base_limit*100:0;return!_||T>_.pct?{key:F,pct:T}:_},null),w=t.periods??[],b=gn();w.includes(b)||w.unshift(b);let y=i===b,f=s?.workspace,v=f?.members?.find(_=>_.role==="owner"),k=f?.members?.filter(_=>_.role==="admin")??[];return e("div",{class:"usage-page",children:e("div",{class:"usage-wrap",children:[e("div",{class:"usage-top-row",children:[e("nav",{class:"breadcrumb",children:[e("a",{href:"/explorer",children:"Explorer"})," \u203A Usage"]}),e("a",{href:`https://mug.work/workspace/${encodeURIComponent(t.workspace)}`,target:"_blank",rel:"noopener",class:"ws-card-manage",children:["Manage billing at mug.work ",e("i",{"data-lucide":"external-link",style:"width:12px;height:12px"})]})]}),f&&e("div",{class:"ws-card ws-card-static",children:e("div",{class:"ws-card-top",children:[e("div",{children:[e("div",{class:"ws-name",children:f.name}),e("div",{class:"ws-meta",children:[e("div",{class:"ws-meta-row",children:["owner: ",v?.email??"\u2014"]}),k.length>0&&e("div",{class:"ws-meta-row",children:["admins: ",k.map(_=>_.email).join(", ")]})]})]}),e("div",{class:"ws-card-right",children:e("div",{class:"ws-card-right-top",children:e("span",{class:"ws-badge",children:c})})})]})}),m&&p&&e("div",{class:"usage-banner usage-banner-yellow",children:[e("i",{"data-lucide":"alert-triangle"}),e("span",{children:[mn.find(_=>_.key===p.key)?.label??p.key,p.pct>=100?" in overage":` at ${Math.round(p.pct)}% of monthly limit`]}),e("a",{href:`https://mug.work/workspace/${encodeURIComponent(t.workspace)}`,target:"_blank",rel:"noopener",children:"Manage billing \u2192"})]}),e("div",{class:"usage-period-row",children:[e("span",{class:"usage-period-title",children:"Usage"}),e("select",{class:"usage-period-select",value:i,onChange:_=>l(_.target.value),children:w.map(_=>e("option",{value:_,children:Ds(_)},_))})]}),e("div",{class:"usage-meters",children:mn.map(({key:_,label:F,icon:A,format:T})=>{let I=g[_];if(!I||I.base_limit==null||I.used==null)return null;let M=I.base_limit,V=M>0?Math.round(I.used/M*100):0,ye=Math.min(100,V),we=V>=80?"#f59e0b":"#22c55e",mt=V>=100?"#f59e0b":we,Fe=V>100,Ue=T(I.used),ke=T(M),ee=t.tier!=="free"&&y,x=I.overage_enabled??!1,D=I.overage_cap??0,$=I.used>M?I.used-M:0,j=$>0?T($):"",te=I.overage_charge??0;return e("div",{class:"usage-meter",children:[e("div",{class:"usage-meter-header",children:[e("div",{class:"usage-meter-label",children:[e("i",{"data-lucide":A}),e("span",{children:F}),fn[_]&&e("span",{class:"dim-info",tabIndex:0,children:[e("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[e("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 16v-4"}),e("path",{d:"M12 8h.01"})]}),e("span",{class:"dim-info-tip",children:fn[_]})]})]}),ee&&e("div",{class:"usage-meter-header-right",children:e("div",{class:`overage-toggle-wrap${x?" on":""} readonly`,children:[e("span",{class:"overage-toggle-label",children:"Allow overages"}),e("div",{class:"overage-track"})]})})]}),e("div",{class:"usage-bar-track",children:[e("div",{class:"usage-bar-fill",style:{width:`${ye}%`,background:we}}),Fe&&e("div",{class:"usage-bar-overage",style:{left:`${Math.round(1e4/V)}%`,width:`${100-Math.round(1e4/V)}%`}})]}),e("div",{class:"usage-meter-footer",children:[e("div",{class:"usage-meter-values",children:[e("span",{children:Ue}),e("span",{class:"usage-meter-limit",children:["/ ",ke]}),$>0&&e("span",{class:"usage-overage-qty",children:["+",j," for $",te.toFixed(2)]})]}),ee&&x&&D>0&&e("span",{class:"usage-meter-cap-label",children:["Overage cap $",D,"/mo"]})]})]},_)})}),t.ai_detail&&t.ai_detail.length>0&&e("div",{class:"usage-ai-section",children:[e("button",{class:"usage-ai-toggle",onClick:()=>u(!d),children:[e("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:`toggle-icon ${d?"toggle-icon-open":""}`,children:e("path",{d:"m9 18 6-6-6-6"})}),"AI model breakdown (last 30 days)"]}),d&&e("table",{class:"usage-ai-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Model"}),e("th",{children:"Requests"}),e("th",{children:"Tokens"})]})}),e("tbody",{children:t.ai_detail.map(_=>e("tr",{children:[e("td",{children:_.model}),e("td",{children:X(Number(_.request_count))}),e("td",{children:X(Number(_.total_tokens))})]},_.model))})]})]})]})})}function X(t){return t>=1e6?`${(t/1e6).toFixed(1).replace(/\.0$/,"")}M`:t>=1e4?`${(t/1e3).toFixed(1).replace(/\.0$/,"")}K`:t.toLocaleString()}function Hs(t){if(t===0)return"0 B";let n=["B","KB","MB","GB","TB"],s=Math.floor(Math.log(t)/Math.log(1e3));return`${(t/Math.pow(1e3,s)).toFixed(s>0?1:0)} ${n[s]}`}function vn(){return e(Kt,{children:e(tt,{children:[e(H,{path:"/explorer",component:Yt}),e(H,{path:"/explorer/usage",component:hn}),e(H,{path:"/explorer/databases/:name/:table",component:tn}),e(H,{path:"/explorer/databases/:name",component:Qt}),e(H,{path:"/explorer/databases",component:()=>e(oe,{category:"databases"})}),e(H,{path:"/explorer/workflows/:name/logs",component:rn}),e(H,{path:"/explorer/workflows/:name",component:nn}),e(H,{path:"/explorer/workflows",component:()=>e(oe,{category:"workflows"})}),e(H,{path:"/explorer/sources/:name",component:an}),e(H,{path:"/explorer/sources",component:()=>e(oe,{category:"sources"})}),e(H,{path:"/explorer/surfaces/:name",component:on}),e(H,{path:"/explorer/surfaces",component:()=>e(oe,{category:"surfaces"})}),e(H,{path:"/explorer/agents/:name/brain",component:un}),e(H,{path:"/explorer/agents/:name/sessions/:key",component:ut}),e(H,{path:"/explorer/agents/:name/sessions",component:ut}),e(H,{path:"/explorer/agents/:name",component:ln}),e(H,{path:"/explorer/agents",component:()=>e(oe,{category:"agents"})}),e(H,{path:"/explorer/changesets/:database/:id",component:pn}),e(H,{path:"/explorer/files/:splat*",component:pt}),e(H,{path:"/explorer/files",component:pt}),e(H,{default:!0,component:Es})]})})}function Es(){return e("div",{class:"explorer-not-found",children:[e("h1",{children:"Not Found"}),e("a",{href:"/explorer",children:"Back to Explorer"})]})}Dt(e(vn,{}),document.getElementById("root"));
@@ -0,0 +1,18 @@
1
+ export declare function markdownToHtml(text: string): string;
2
+ export interface BrandingConfig {
3
+ logo?: string;
4
+ logoSquare?: string;
5
+ accentColor?: string;
6
+ }
7
+ interface EmailTemplateOptions {
8
+ subject: string;
9
+ bodyHtml: string;
10
+ cta?: {
11
+ label: string;
12
+ url: string;
13
+ };
14
+ fromName?: string;
15
+ branding?: BrandingConfig;
16
+ }
17
+ export declare function renderEmailHtml(options: EmailTemplateOptions): string;
18
+ export {};