@flowe-ai/cli 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -170
- package/dist/{ambient-SIMIQWQM.js → ambient-RIFETQIW.js} +1 -1
- package/dist/{chunk-RB3EXF6P.js → chunk-3HG2U5YK.js} +1 -1
- package/dist/chunk-3TLGYA6M.js +3 -0
- package/dist/chunk-EC5WRPZP.js +1 -0
- package/dist/chunk-GUTZZ5P5.js +5 -0
- package/dist/chunk-MM4EMTNC.js +1 -0
- package/dist/cli.js +74 -54
- package/dist/{login-FRWDEJ6B.js → login-Q4QMATEN.js} +2 -2
- package/dist/mcp-server.js +9 -4
- package/dist/me-SZLS6RWX.js +1 -0
- package/dist/session-client-2SS65HUQ.js +1 -0
- package/dist/setup-harness-RR77VO5C.js +9 -0
- package/dist/ui/live-session.html +49 -0
- package/dist/ui/micro.html +9 -0
- package/package.json +18 -8
- package/scripts/preinstall.js +1 -1
- package/skills/flowe/SKILL.md +49 -111
- package/dist/chunk-AX3TLBEV.js +0 -2
- package/dist/chunk-C6NO4B4N.js +0 -3
- package/dist/chunk-P2IV5O3T.js +0 -1
- package/dist/me-LA6RUW2D.js +0 -1
package/README.md
CHANGED
|
@@ -1,210 +1,88 @@
|
|
|
1
|
-
# flowe
|
|
1
|
+
# @flowe-ai/cli
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Science-backed resets in your terminal and AI chat: 30–90 s micro-resets, live Quick and Deep Resets with Ada, and an MCP App for your AI tools.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`flowe` runs 30–90 s micro-resets in your terminal with no account, live Quick and Deep Resets with Ada when you sign in, and **MCP App cards (SEP-1865)** inside Claude Desktop, Antigravity, Cursor and VS Code, with plain text in Codex and Claude Code.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Docs and voice samples: [cli.flowe.ai](https://cli.flowe.ai)
|
|
7
|
+
Docs and a live demo: **[cli.flowe.ai](https://cli.flowe.ai)**
|
|
10
8
|
|
|
11
9
|
## Install
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
npm install -g @flowe-ai/cli
|
|
15
|
-
```
|
|
11
|
+
Fastest: paste this into your AI agent (Claude Code, Codex, Cursor, VS Code or Antigravity). It installs the CLI, connects the app and offers a first reset.
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
## Quickstart
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
flowe reset # interactive picker — choose duration + protocol
|
|
23
|
-
flowe reset 60 # 60-second reset, random protocol
|
|
24
|
-
flowe reset 60 --protocol box_breath # deterministic — box-breathing only
|
|
25
|
-
flowe reset --quick # skip the picker, use defaults
|
|
26
|
-
|
|
27
|
-
flowe focus # interactive focus picker — preset + ambient sound
|
|
28
|
-
flowe focus pomodoro --ambient nature_spring_birds
|
|
29
|
-
flowe focus dev --detach --ambient rain_window_soft
|
|
30
|
-
flowe focus status
|
|
13
|
+
```text
|
|
14
|
+
Set up flowe for me: follow https://cli.flowe.ai/setup.md
|
|
31
15
|
```
|
|
32
16
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
## What flowe does
|
|
36
|
-
|
|
37
|
-
When your agent is thinking for 30–120 seconds, your nervous system has two real options. Tab to reels and your working memory drains, dopamine spikes, focus fragments. Or run a science-backed neural reset that restores focus and steadies your nervous system. `flowe reset` is the second option, sized for the agent wait window.
|
|
38
|
-
|
|
39
|
-
When you are settling into longer work, `flowe focus` gives you a visible work/break cadence with optional ambient sound. It can run in the foreground TUI, detach into the background, or show live controls in the macOS menu bar.
|
|
40
|
-
|
|
41
|
-
Eleven protocol families ship with the CLI:
|
|
42
|
-
|
|
43
|
-
| Family | Durations | What it is |
|
|
44
|
-
|---|---|---|
|
|
45
|
-
| `box_breath` | 45s, 60s | Box breathing — inhale, hold, exhale, hold |
|
|
46
|
-
| `extended_box` | 90s | Box breathing with longer rounds |
|
|
47
|
-
| `physiological_sigh` | 30s | Double inhale through the nose, long exhale |
|
|
48
|
-
| `quick_palming` | 30s | Short palming — cover the eyes |
|
|
49
|
-
| `palming` | 60s | Standard palming reset |
|
|
50
|
-
| `progressive_palming` | 90s | Longer palming with phased relaxation |
|
|
51
|
-
| `body_scan` | 60s | Brief somatic check-in |
|
|
52
|
-
| `eye_rotation` | 30s | Eye movement reset |
|
|
53
|
-
| `neck_rotation` | 45s | Neck mobility break |
|
|
54
|
-
| `grounded_feet` | 45s | Pressure-into-ground grounding |
|
|
55
|
-
| `full_sensory` | 90s | 5-4-3-2-1 sensory grounding |
|
|
56
|
-
|
|
57
|
-
Run `flowe protocols` to see the full list.
|
|
58
|
-
|
|
59
|
-
## Focus cycles
|
|
17
|
+
By hand:
|
|
60
18
|
|
|
61
19
|
```bash
|
|
62
|
-
|
|
63
|
-
flowe focus pomodoro # 25/5, 4 focus blocks
|
|
64
|
-
flowe focus dev # 50/10, 3 focus blocks
|
|
65
|
-
flowe focus ultradian # 90/15, 2 focus blocks
|
|
66
|
-
flowe focus pomodoro --ambient none # silence
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
The foreground focus TUI uses the same calm particle-orb visual language as `flowe reset`, with the literal countdown shown above it. Space pauses and resumes, `s` skips to the next phase, `q` quits, and `?` shows help.
|
|
70
|
-
|
|
71
|
-
For long-running work, detach the session so your shell is free:
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
flowe focus pomodoro --detach --ambient nature_spring_birds
|
|
75
|
-
flowe focus status
|
|
76
|
-
flowe focus pause
|
|
77
|
-
flowe focus resume
|
|
78
|
-
flowe focus skip
|
|
79
|
-
flowe focus quit
|
|
80
|
-
flowe focus --attach
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
Detached focus sessions keep their state on disk so another terminal, the attach TUI, or the menu bar plugin can control the same cycle.
|
|
84
|
-
|
|
85
|
-
## Ambient sound
|
|
86
|
-
|
|
87
|
-
Hosted ambient sounds are fetched from the flowe manifest at startup, downloaded once, and cached under `~/.config/flowe/cache/ambient/`. If the manifest or download fails, focus falls back to silence instead of failing the session.
|
|
88
|
-
|
|
89
|
-
Useful built-in ambient ids include:
|
|
90
|
-
|
|
91
|
-
| Ambient id | Feel |
|
|
92
|
-
|---|---|
|
|
93
|
-
| `nature_spring_birds` | Light spring morning birds |
|
|
94
|
-
| `rain_window_soft` | Soft rain against a window |
|
|
95
|
-
| `tones_deep_brown_noise` | Deep masking noise for focus |
|
|
96
|
-
| `seaside_la_sunrise` | Peaceful Los Angeles sunrise beach |
|
|
97
|
-
| `interiors_quiet_cafe` | Quiet cafe ambience |
|
|
98
|
-
| `none` | No ambient sound |
|
|
99
|
-
|
|
100
|
-
You can also generate custom ambience from a prompt. This requires `flowe login` and paid access.
|
|
101
|
-
|
|
102
|
-
```bash
|
|
103
|
-
flowe ambient create "quiet library, soft page turns, distant rain" --name "library rain"
|
|
104
|
-
flowe ambient list
|
|
105
|
-
flowe focus pomodoro --ambient custom_abc123def456
|
|
20
|
+
npm install -g @flowe-ai/cli
|
|
106
21
|
```
|
|
107
22
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
## Menu bar
|
|
111
|
-
|
|
112
|
-
On macOS, `flowe` can install a SwiftBar plugin that shows the current focus cycle in your menu bar and gives you pause/resume/skip/quit controls.
|
|
113
|
-
|
|
114
|
-
```bash
|
|
115
|
-
flowe install-menubar
|
|
116
|
-
flowe uninstall-menubar
|
|
117
|
-
```
|
|
23
|
+
Requires **Node.js ≥ 20** on **macOS, Linux, or Windows**.
|
|
118
24
|
|
|
119
|
-
|
|
25
|
+
## Connect your AI harness (MCP Apps)
|
|
120
26
|
|
|
121
|
-
|
|
27
|
+
Merge Flowe's stdio MCP server cleanly into your AI host in one command:
|
|
122
28
|
|
|
123
29
|
```bash
|
|
124
|
-
flowe
|
|
125
|
-
flowe
|
|
30
|
+
flowe setup claude-desktop --write
|
|
31
|
+
flowe setup antigravity --write
|
|
32
|
+
flowe setup cursor --write
|
|
33
|
+
flowe setup vscode --write
|
|
34
|
+
flowe setup claude-code --write
|
|
35
|
+
flowe setup codex --write
|
|
126
36
|
```
|
|
127
37
|
|
|
128
|
-
|
|
38
|
+
Supporting MCP Apps hosts mount Flowe's self-contained **Dusk + Peek** UI cards (`ui://flowe/micro.html`, `ui://flowe/live-session.html`) inline inside the chat. Terminal-only hosts automatically receive concise structured text.
|
|
129
39
|
|
|
130
|
-
##
|
|
40
|
+
## Three Reset Tiers
|
|
131
41
|
|
|
132
|
-
|
|
42
|
+
| Tier | Duration | Auth | Command |
|
|
43
|
+
|---|---|---|---|
|
|
44
|
+
| **Micro-Resets** | 30–90s | Free · no account | `flowe reset 60 --protocol box_breath` |
|
|
45
|
+
| **Quick Resets** | 5–15 min | Free account · 5 a week | `flowe quick logic_lock --ambient rain_window_soft` |
|
|
46
|
+
| **Deep Resets** | 30–50 min | Flowe Pro or your team | `flowe deep ht_burnout --open` |
|
|
133
47
|
|
|
134
|
-
|
|
48
|
+
### Micro-Resets
|
|
135
49
|
|
|
136
50
|
```bash
|
|
137
|
-
flowe
|
|
51
|
+
flowe reset # interactive picker
|
|
52
|
+
flowe reset 30 --protocol physiological_sigh
|
|
53
|
+
flowe reset 60 --protocol box_breath
|
|
54
|
+
flowe reset --quick # skip picker, use defaults
|
|
138
55
|
```
|
|
139
56
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
Don't want to use the CLI to install? Download `SKILL.md` directly:
|
|
143
|
-
|
|
144
|
-
- [github.com/flowe-ai/flowe-cli/blob/main/SKILL.md](https://github.com/flowe-ai/flowe-cli/blob/main/SKILL.md)
|
|
145
|
-
|
|
146
|
-
Drop it into `~/.claude/skills/flowe/SKILL.md` (or your project's `.claude/skills/flowe/SKILL.md`). The skill content is the same.
|
|
147
|
-
|
|
148
|
-
To opt out of auto-trigger entirely, set `FLOWE_OPT_OUT=1` in your shell or delete the file.
|
|
149
|
-
|
|
150
|
-
## Login (optional)
|
|
57
|
+
### Live Quick & Deep Resets (Flowe Account)
|
|
151
58
|
|
|
152
59
|
```bash
|
|
153
|
-
flowe login
|
|
60
|
+
flowe login # OAuth device grant (stored in OS Keychain)
|
|
61
|
+
flowe whoami # check account, plan & Quick Reset quota
|
|
62
|
+
flowe quick logic_lock --ambient rain_window_soft
|
|
63
|
+
flowe deep ht_burnout --open # opens desktop or prints phone handoff QR
|
|
154
64
|
```
|
|
155
65
|
|
|
156
|
-
|
|
66
|
+
### Flowe for Teams
|
|
157
67
|
|
|
158
|
-
|
|
68
|
+
Your team's Flowe Pro works in the CLI and the MCP server. Sign in with the email your admin invited; `flowe whoami` shows the team. See [cli.flowe.ai/docs/teams](https://cli.flowe.ai/docs/teams/).
|
|
159
69
|
|
|
160
|
-
|
|
70
|
+
### Focus Cycles & Voices
|
|
161
71
|
|
|
162
72
|
```bash
|
|
163
|
-
flowe
|
|
164
|
-
flowe
|
|
73
|
+
flowe focus pomodoro --ambient rain_window_soft
|
|
74
|
+
flowe focus dev --ambient forest_morning
|
|
75
|
+
flowe focus ultradian --ambient brown_noise
|
|
76
|
+
flowe voice ada | ellie | sage
|
|
165
77
|
```
|
|
166
78
|
|
|
167
|
-
##
|
|
168
|
-
|
|
169
|
-
Config lives at `~/.config/flowe/config.json`. Voice preference, telemetry mode, and the anonymous ID live there. Ambient MP3s are cached under `~/.config/flowe/cache/ambient/`. Login tokens go in the OS keychain via `keytar`, never on disk.
|
|
79
|
+
## Privacy & Opt-Out
|
|
170
80
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
-
|
|
174
|
-
-
|
|
175
|
-
- `FLOWE_OPT_OUT=1` in your shell: events skipped entirely.
|
|
176
|
-
|
|
177
|
-
## Troubleshooting
|
|
178
|
-
|
|
179
|
-
**No audio.** macOS uses `afplay`. If `afplay --version` fails, check System Settings → Privacy → Microphone is not blocking the binary. The CLI exits with code `4` on audio device errors.
|
|
180
|
-
|
|
181
|
-
**`flowe: command not found` after install.** Your npm global bin path isn't on `$PATH`. Run `npm config get prefix` and add `$(npm config get prefix)/bin` to your shell profile.
|
|
182
|
-
|
|
183
|
-
**Session won't start, "agent_busy".** A previous reset is still running. Wait for it to finish or run `flowe status` to see what's open.
|
|
184
|
-
|
|
185
|
-
**Focus session says one is already running.** Run `flowe focus status` to inspect it, `flowe focus --attach` to watch it, or `flowe focus quit` to stop it.
|
|
186
|
-
|
|
187
|
-
**Ambient sound does not appear.** Run `flowe focus` interactively so the CLI can refresh the hosted manifest. Network failures degrade to silence; custom ambience also requires `flowe login`.
|
|
188
|
-
|
|
189
|
-
**Menu bar stays idle during a focus session.** Reinstall or restart the plugin with `flowe install-menubar`. SwiftBar sometimes needs a restart to re-scan newly written plugin files.
|
|
190
|
-
|
|
191
|
-
**Login redirects but never completes.** The device-grant flow waits up to 5 minutes. If the browser closes early, run `flowe login` again.
|
|
192
|
-
|
|
193
|
-
## Exit codes
|
|
194
|
-
|
|
195
|
-
| Code | Meaning |
|
|
196
|
-
|---|---|
|
|
197
|
-
| `0` | Success |
|
|
198
|
-
| `1` | User error (bad flag, unknown protocol family) |
|
|
199
|
-
| `2` | Auth required or expired |
|
|
200
|
-
| `3` | Session already running |
|
|
201
|
-
| `4` | Network/offline/audio failure |
|
|
81
|
+
- **No account needed:** All 12 micro-reset protocols work with no account and store only a local ID in `~/.config/flowe/config.json`.
|
|
82
|
+
- **Keychain tokens:** `flowe login` and inline MCP `flowe_auth` store credentials in your OS Keychain (falling back to `0600` local storage only if unavailable).
|
|
83
|
+
- **Zero code leaves your machine:** Never reads files, prompts, or repository paths.
|
|
84
|
+
- **Full opt-out:** Set `FLOWE_OPT_OUT=1` to disable telemetry and proactive MCP suggestions completely.
|
|
202
85
|
|
|
203
86
|
## License
|
|
204
87
|
|
|
205
|
-
MIT
|
|
206
|
-
|
|
207
|
-
## Links
|
|
208
|
-
|
|
209
|
-
Docs: [cli.flowe.ai](https://cli.flowe.ai)
|
|
210
|
-
Issues + feature requests: [github.com/flowe-ai/flowe-cli/issues](https://github.com/flowe-ai/flowe-cli/issues)
|
|
88
|
+
MIT © [Flowe AI](https://www.flowe.ai)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"./chunk-3TLGYA6M.js";export{a as DEFAULT_MANIFEST_URL,c as applyAmbientAssetBaseUrl,l as buildAmbientEntries,d as cachePathFor,b as defaultManifestUrl,j as downloadAmbient,i as fetchAmbientManifest,h as isCached,e as loadCustomAmbientManifest,f as mergeAmbientManifests,g as saveCustomAmbientSound,m as selectableIndices,k as startAmbientFile};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as i,d as n,i as o}from"./chunk-
|
|
1
|
+
import{a as i,d as n,i as o}from"./chunk-EC5WRPZP.js";async function l(t={}){let e=i(),r=t.authToken!==void 0?t.authToken:await o();if(!r)return null;let a=t.fetch??globalThis.fetch;try{let s=await a(`${e.backend_url}/api/v1/me`,{method:"GET",headers:{Authorization:`Bearer ${r}`}});return s.ok?await s.json():null}catch{return null}}async function m(t={}){let e=await l(t);return e?typeof e.first_name=="string"&&e.first_name.trim().length>0?(n(e.first_name),e.first_name):(n(null),null):null}export{l as a,m as b};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{spawn as M}from"child_process";import{createHash as A}from"crypto";import{EventEmitter as _}from"events";import{createWriteStream as C,existsSync as y,mkdirSync as k,readFileSync as P,statSync as L,unlinkSync as E,writeFileSync as v}from"fs";import{homedir as I,platform as O}from"os";import{dirname as R,join as m}from"path";import{Readable as F}from"stream";import{pipeline as N}from"stream/promises";var U="https://www.flowe.ai/cli/ambient/manifest.json",D=5e3,B=3e4,$=29e3,W=900;function j(){return process.env.FLOWE_AMBIENT_MANIFEST_URL||U}function J(){return process.env.FLOWE_AMBIENT_ASSET_BASE_URL||null}function H(t){try{return new URL(t).pathname.split("/").filter(Boolean).pop()||t}catch{return t.split("/").filter(Boolean).pop()||t}}function G(t,e=J()){if(!e)return t;let n=e.replace(/\/+$/,"");return{...t,sounds:t.sounds.map(o=>({...o,url:`${n}/${encodeURIComponent(H(o.url))}`}))}}function w(){let t=I(),e=O()==="win32"?m(t,"AppData","Roaming","flowe"):m(t,".config","flowe");return m(e,"cache","ambient")}function x(){return m(w(),"custom-manifest.json")}function S(t){return m(w(),`${t.sha256}.mp3`)}function q(){let t=x();if(!y(t))return null;try{let e=JSON.parse(P(t,"utf-8"));return e.version!==1||!Array.isArray(e.categories)||!Array.isArray(e.sounds)?null:e}catch{return null}}function st(t,e){if(!t&&!e)return null;if(!t)return e;if(!e||e.sounds.length===0)return t;let n=new Set(t.categories.map(r=>r.id)),o=[...t.categories];for(let r of e.categories)n.has(r.id)||(n.add(r.id),o.push(r));let i=new Set(t.sounds.map(r=>r.id)),s=[...t.sounds];for(let r of e.sounds)i.has(r.id)||(i.add(r.id),s.push(r));return{version:1,generated_at:t.generated_at,categories:o,sounds:s}}function at(t){let e=Buffer.from(t.bytes),n=A("sha256").update(e).digest("hex"),o=`custom_${n.slice(0,12)}`,i=(t.name.trim()||"custom ambience").slice(0,48),s={id:o,category:"custom",name:i,blurb:"generated ambience",url:`flowe-local://ambient/custom/${o}.mp3`,sha256:n,bytes:e.byteLength};k(w(),{recursive:!0}),v(S(s),e);let r=q(),c=[s,...r?.sounds.filter(u=>u.id!==o)??[]],d={version:1,generated_at:(t.now??(()=>new Date))().toISOString(),categories:[{id:"custom",label:"custom"}],sounds:c};return v(x(),JSON.stringify(d,null,2)+`
|
|
2
|
+
`,"utf-8"),s}function z(t){let e=S(t);if(!y(e))return!1;try{let n=P(e);return A("sha256").update(n).digest("hex")===t.sha256}catch{return!1}}async function lt(t){let e=t?.url??j(),n=t?.timeoutMs??D,o=new AbortController,i=setTimeout(()=>o.abort(),n);t?.signal&&(t.signal.aborted?o.abort():t.signal.addEventListener("abort",()=>o.abort()));try{let s=await fetch(e,{signal:o.signal});if(!s.ok)throw new Error(`manifest fetch failed: ${s.status}`);let r=await s.json();if(!r.sounds||!r.categories)throw new Error("manifest shape invalid");return G(r)}finally{clearTimeout(i)}}async function ct(t,e){let n=S(t);if(z(t))return e?.onProgress?.({downloaded:t.bytes,total:t.bytes}),n;k(R(n),{recursive:!0});let o=e?.timeoutMs??B,i=new AbortController,s=setTimeout(()=>i.abort(),o);e?.signal&&(e.signal.aborted?i.abort():e.signal.addEventListener("abort",()=>i.abort()));let r=`${n}.part`;try{let c=await fetch(t.url,{signal:i.signal});if(!c.ok||!c.body)throw new Error(`download failed: ${c.status}`);let d=t.bytes,u=0,f=A("sha256"),b=c.body.getReader(),g=new F({read(){b.read().then(({value:a,done:h})=>{if(h){this.push(null);return}u+=a.byteLength,f.update(a),e?.onProgress?.({downloaded:u,total:d}),this.push(Buffer.from(a))}).catch(a=>this.destroy(a))}});if(await N(g,C(r)),f.digest("hex")!==t.sha256){try{E(r)}catch{}throw new Error("sha256 mismatch")}let{renameSync:l}=await import("fs");return l(r,n),n}catch(c){try{y(r)&&E(r)}catch{}throw c}finally{clearTimeout(s)}}var T=!1;function V(){let t=new _;return t.killed=!1,t.kill=()=>(t.killed||(t.killed=!0,t.emit("exit",null,"SIGTERM")),!0),t}function K(t,e=1){let n=Number.isFinite(e)&&e>0?e:1;return process.platform==="darwin"?M("afplay",["-v",String(n),t],{stdio:"ignore"}):process.platform==="win32"?(T||(T=!0,process.stderr.write(`ambience isn't supported on Windows yet \u2014 the session runs without background sound
|
|
3
|
+
`)),V()):M("mpg123",["-q","-f",String(Math.round(32768*n)),t],{stdio:"ignore"})}function ut(t,e={}){if(!t||!y(t))return{stop:()=>{}};try{if(L(t).size<=0)return{stop:()=>{}}}catch{return{stop:()=>{}}}let n=!1,o=null,i=null,s=new Set,r=new Set,c=e.loopRestartMs??$,d=e.overlapMs??W,u=e.volume??1,f=e.spawnPlayer??K,b=()=>{i&&(clearTimeout(i),i=null);for(let l of s)clearTimeout(l);s.clear()},g=l=>{if(l&&!l.killed)try{l.kill("SIGTERM")}catch{}},p=()=>{if(n)return;let l=o,a;try{a=f(t,u)}catch{n=!0;return}if(o=a,r.add(a),l&&l!==a){let h=setTimeout(()=>{s.delete(h),g(l)},d);s.add(h)}i=setTimeout(()=>{i=null,p()},c),a.on("exit",()=>{r.delete(a),!n&&o===a&&(i&&(clearTimeout(i),i=null),p())}),a.on("error",()=>{n=!0,b()})};return p(),{stop:()=>{n=!0,b(),o=null;for(let l of r)g(l);r.clear()}}}function dt(t){let e=[{kind:"none"}];if(!t)return e;for(let n of t.categories){let o=t.sounds.filter(i=>i.category===n.id);if(o.length!==0){e.push({kind:"category",categoryId:n.id,label:n.label});for(let i of o)e.push({kind:"sound",sound:i})}}return e}function mt(t){let e=[];for(let n=0;n<t.length;n++)t[n].kind!=="category"&&e.push(n);return e}export{U as a,j as b,G as c,S as d,q as e,st as f,at as g,z as h,lt as i,ct as j,ut as k,dt as l,mt as m};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readFileSync as x,writeFileSync as A,mkdirSync as E,existsSync as h}from"fs";import{homedir as T,platform as P}from"os";import{join as d}from"path";import{nanoid as D}from"nanoid";var v="https://www.flowe.ai",O=90,b=["sage","ada","ellie"];function V(t){return typeof t=="string"&&b.includes(t)?t:"ellie"}function S(){let t=T();return P()==="win32"?d(t,"AppData","Roaming","flowe"):d(t,".config","flowe")}function k(){return d(S(),"config.json")}function w(){return{version:2,voice:"ellie",anonymous_id:`anon_${D(12)}`,telemetry:"on",backend_url:process.env.FLOWE_BACKEND_URL||v,session_dates:[]}}function N(t){let e=typeof t.version=="number"?t.version:1,n=t.voice,r=V(n),o={version:2,voice:r,anonymous_id:t.anonymous_id??`anon_${D(12)}`,telemetry:t.telemetry??"on",backend_url:t.backend_url??v,session_dates:Array.isArray(t.session_dates)?t.session_dates:[]};return typeof t.first_reset_at=="string"&&(o.first_reset_at=t.first_reset_at),typeof t.user_first_name=="string"&&(o.user_first_name=t.user_first_name),(e<2||n!==r)&&s(o),o}function i(){let t=k();if(!h(t)){let e=w();return s(e),e}try{let e=x(t,"utf-8"),n=JSON.parse(e),r=N(n);return process.env.FLOWE_BACKEND_URL&&(r.backend_url=process.env.FLOWE_BACKEND_URL),r}catch{let e=w();return s(e),e}}function s(t){let e=S();h(e)||E(e,{recursive:!0}),A(k(),JSON.stringify(t,null,2),"utf-8")}function Q(t){let e=i();e.voice=t,s(e)}function X(){let t=i();t.first_reset_at||(t.first_reset_at=new Date().toISOString(),s(t))}function Z(t){let e=i();t&&t.trim().length>0?e.user_first_name=t.trim():delete e.user_first_name,s(e)}function u(t=new Date){let e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`}function R(t,e){let n=new Date(e);n.setDate(n.getDate()-O);let r=u(n);return t.filter(o=>o>=r)}function tt(t=new Date){let e=i(),n=u(t),r=R([...e.session_dates,n],t);e.session_dates=r,s(e)}function et(t=new Date){let e=i(),n=u(t);return e.session_dates.filter(r=>r===n).length}function nt(t=new Date){let e=i(),n=new Set(e.session_dates),r=new Date(t);r.setHours(0,0,0,0);let o=new Date(r);n.has(u(o))||o.setDate(o.getDate()-1);let _=0;for(;n.has(u(o));)_+=1,o.setDate(o.getDate()-1);return _}function rt(){return i().session_dates.length}import{execFileSync as g}from"child_process";import{existsSync as m,mkdirSync as K,readFileSync as L,rmSync as U,writeFileSync as I}from"fs";import{homedir as $,platform as l}from"os";import{join as f}from"path";var c="flowe-cli",a="clerk-token";function p(){let t=$(),e=l()==="win32"?f(t,"AppData","Roaming","flowe"):f(t,".config","flowe");return f(e,".token")}function j(){if(l()!=="darwin")return null;try{let t=g("security",["find-generic-password","-s",c,"-a",a,"-w"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim();return t.length>0?t:null}catch{return null}}function B(t){if(l()!=="darwin")return!1;try{return g("security",["add-generic-password","-U","-s",c,"-a",a,"-w",t],{stdio:"ignore"}),!0}catch{return!1}}function M(){if(l()!=="darwin")return!1;try{return g("security",["delete-generic-password","-s",c,"-a",a],{stdio:"ignore"}),!0}catch{return!1}}function W(){try{let t=p();if(!m(t))return null;let e=L(t,"utf-8").trim();return e.length>0?e:null}catch{return null}}function H(t){let e=p(),n=f(e,"..");m(n)||K(n,{recursive:!0}),I(e,t,{encoding:"utf-8",mode:384})}function J(){try{let t=p();m(t)&&U(t,{force:!0})}catch{}}async function y(){try{let e=(await import("keytar")).default;return e&&typeof e.getPassword=="function"?e:null}catch{return null}}async function ft(){let t=process.env.FLOWE_AUTH_TOKEN?.trim();if(t)return t;let e=await y();if(e)try{let n=await e.getPassword(c,a);return n||null}catch{return null}return j()??W()}async function lt(t){let e=await y();if(e)try{await e.setPassword(c,a,t);return}catch{}B(t)||H(t)}async function dt(){let t=await y();if(t)try{await t.deletePassword(c,a)}catch{}M(),J()}export{i as a,Q as b,X as c,Z as d,tt as e,et as f,nt as g,rt as h,ft as i,lt as j,dt as k};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{a as W,c as Q,e as Y,i as G}from"./chunk-EC5WRPZP.js";import{readFileSync as ge}from"fs";import{dirname as ye,join as he}from"path";import{fileURLToPath as be}from"url";var xe=ye(be(import.meta.url));function H(){try{let e=ge(he(xe,"..","package.json"),"utf-8");return JSON.parse(e).version}catch{return"0.0.0"}}var at=["logic_lock","deploy_anxiety","context_switch","sprint_prep","quick_reset","executive_reset","presentation_prep","shutdown"],ct=["ht_stress","ht_anxiety","ht_people_pleasing","ht_relationships","ht_confidence","ht_fears","ht_anger","ht_procrastination","ht_burnout"];import{readFileSync as K}from"fs";import{dirname as Se,join as N}from"path";import{fileURLToPath as ve}from"url";var A=Se(ve(import.meta.url));function Ee(){return N(A,"..","protocols.json")}var g=null;function k(){if(g)return g;try{let e=K(Ee(),"utf-8");return g=JSON.parse(e),g}catch{return g={protocols:{},audio_paths:{},cues_paths:{}},g}}function D(){return Object.values(k().protocols)}function M(e){return e.replace(/_\d+$/,"")}function ft(){let e=new Set;for(let t of D())e.add(M(t.protocol_id));return[...e].sort()}function _t(e){return D().filter(t=>M(t.protocol_id)===e).map(t=>t.duration_seconds).sort((t,r)=>t-r)}function z(e,t){let r=D().filter(n=>n.duration_seconds===e&&(t===void 0||M(n.protocol_id)===t));return r.length===0?null:t!==void 0?r[0]:r[Math.floor(Math.random()*r.length)]}function X(e,t){let r=k(),n=`${e}.${t}`,o=r.audio_paths[n];return o?N(A,"..",o):null}var C=new Map;function Z(e,t){let r=`${e}.${t}`,n=C.get(r);if(n!==void 0)return n;let a=k().cues_paths?.[r];if(!a)return C.set(r,null),null;try{let s=K(N(A,"..",a),"utf-8"),i=JSON.parse(s);return C.set(r,i),i}catch{return C.set(r,null),null}}import{spawn as R}from"child_process";import{platform as Pe}from"os";var d=null;function ee(e){return typeof e!="number"||!Number.isFinite(e)||e<=0?1:Math.min(2,Math.max(.05,e))}function we(e,t=1){let r=ee(t),n=Pe();if(n==="darwin"){let a=r===1?[e]:["-v",String(r),e];return R("afplay",a,{stdio:"ignore"})}if(n==="win32"){let s=["Add-Type -AssemblyName presentationCore;","$p = New-Object System.Windows.Media.MediaPlayer;",`$p.Open([Uri]'${e.replace(/'/g,"''")}');`,`$p.Volume = ${Math.min(1,r)};`,"$p.Play();","Start-Sleep -Milliseconds 300;","while ($p.Position -lt $p.NaturalDuration.TimeSpan -and $p.NaturalDuration.HasTimeSpan) { Start-Sleep -Milliseconds 200 };","$p.Close();"].join(" ");return R("powershell",["-NoProfile","-NonInteractive","-Command",s],{stdio:"ignore"})}let o=Math.round(32768*r);return R("mpg123",["-q","-f",String(o),e],{stdio:"ignore"})}function I(){return d!==null}function xt(){return d?.donePromise??null}function te(e,t={}){if(d)return Promise.reject(new Error("already playing \u2014 call stopAudio first"));let r=ee(t.volume),n=t.spawnPlayer??we,o;try{o=n(e,r)}catch(c){return Promise.reject(c instanceof Error?c:new Error(String(c)))}let a=!1,s=!1,i,u,p=new Promise((c,l)=>{i=c,u=l}),f=()=>{d?.child===o&&(d=null)},_=()=>{a||(a=!0,f(),i())},T=c=>{a||(a=!0,f(),u(c))};return d={child:o,stop:()=>{if(s=!0,f(),!o.killed)try{o.kill("SIGTERM")}catch{}_()},donePromise:p},o.once("error",c=>{if(s){_();return}let l=Object.assign(new Error(`audio playback failed: ${c.message}`),{code:"audio_device"});T(l)}),o.once("exit",(c,l)=>{if(s||l==="SIGTERM"||l==="SIGINT"||c===0||c===null){_();return}let O=Object.assign(new Error(`audio player exited with code ${c}`),{code:"audio_device"});T(O)}),p}function re(){d&&d.stop()}import{nanoid as $e}from"nanoid";import{readFileSync as Te,writeFileSync as Ce,mkdirSync as Fe,existsSync as L,appendFileSync as Oe}from"fs";import{homedir as Ne}from"os";import{join as oe}from"path";var $=oe(Ne(),".cache","flowe"),v=oe($,"pending-events.jsonl"),Ae=5e3;function ke(){let e=process.env.FLOWE_OPT_OUT?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}async function F(e,t,r){if(!(t.telemetry==="off"||ke())){De(),Me(e);try{await Ie(t,r)}catch{}}}function De(){L($)||Fe($,{recursive:!0})}function Me(e){for(let t of e)Oe(v,JSON.stringify(t)+`
|
|
2
|
+
`,"utf-8")}function Re(){return L(v)?Te(v,"utf-8").split(`
|
|
3
|
+
`).filter(t=>t.trim().length>0).map(t=>JSON.parse(t)):[]}function ne(){L(v)&&Ce(v,"","utf-8")}async function Ie(e,t){let r=Re();if(r.length===0)return;let n={version:H(),platform:`${process.platform}-${process.arch}`,node_version:process.version},o=new AbortController,a=setTimeout(()=>o.abort(),Ae);try{let s={"Content-Type":"application/json"};t&&(s.Authorization=`Bearer ${t}`);let i=await fetch(`${e.backend_url}/api/v1/reset/log`,{method:"POST",headers:s,body:JSON.stringify({events:r,client:n,anonymous_id:e.anonymous_id}),signal:o.signal});(i.ok||i.status===401||i.status===400)&&ne()}finally{clearTimeout(a)}}function Le(e,t,r){if(e.length===0)return[];let o=t*1e3/e.length;return e.map((a,s)=>({label:a,mode:r,start_ms:Math.round(s*o),end_ms:Math.round((s+1)*o)}))}function Rt(){return I()?(re(),!0):!1}async function It(e,t="user_requested",r,n={}){let o=process.env.FLOWE_SILENT_AUDIO==="1"?"silent":n.audioMode??"local";if(o==="local"&&I())throw Object.assign(new Error("a reset is already running"),{code:"agent_busy"});let a=W(),s=n.voice??a.voice,i=z(e,r);if(!i){let _e=r?`${r} at ${e}s`:`${e}s`;throw Object.assign(new Error(`no protocol available for ${_e}`),{code:"protocol_unavailable"})}let u=X(i.protocol_id,s);if(o==="local"&&!u)throw Object.assign(new Error(`no audio available for ${i.protocol_id}:${s}`),{code:"protocol_unavailable"});let p=`reset_${$e(8)}`,f=new Date,_=Math.floor(f.getTime()/1e3),T=_+e;Q();let c=await G();await F([{type:"reset_started",session_id:p,protocol_id:i.protocol_id,duration_seconds:e,voice:s,trigger:t,client_timestamp:f.toISOString()}],a,c),o==="local"&&u&&te(u).then(()=>{if(n.recordOnComplete)try{Y()}catch{}F([{type:"reset_completed",session_id:p,protocol_id:i.protocol_id,duration_seconds:e,voice:s,trigger:t,client_timestamp:new Date().toISOString()}],a,c).catch(()=>{})}).catch(()=>{F([{type:"reset_abandoned",session_id:p,protocol_id:i.protocol_id,duration_seconds:e,voice:s,trigger:t,client_timestamp:new Date().toISOString()}],a,c).catch(()=>{})});let l=Z(i.protocol_id,s),O=l?l.cues:Le(i.text_cues,e,i.category);return{session_id:p,protocol:i.protocol_id,protocol_display_name:i.display_name,duration_seconds:e,voice:s,category:i.category,audio_mode:o,cues:O,rounds:i.rounds,status:"started",started_at_unix:_,ends_at_unix:T,message_for_user:`${e}s ${i.display_name} started \xB7 ${s}`}}import{existsSync as y,mkdirSync as Ve,readFileSync as V,renameSync as se,rmSync as j,writeFileSync as q}from"fs";import{homedir as je}from"os";import{join as h}from"path";var qe="state.json",Be="daemon.pid",Ue="control.txt",Je="daemon.log",We=3e4,Qe=["pause","resume","skip","quit"];function Ye(){return process.env.FLOWE_HOME??h(je(),".flowe")}function b(){return h(Ye(),"sessions","active")}function ae(){return h(b(),qe)}function B(){return h(b(),Be)}function ce(){return h(b(),Ue)}function ue(){return h(b(),Je)}function E(){let e=b();return y(e)||Ve(e,{recursive:!0}),e}function Bt(e){E();let t=ae(),r=`${t}.tmp`;q(r,JSON.stringify(e,null,2),"utf-8"),se(r,t)}function Ut(e={}){let t=ae();if(!y(t))return null;try{let r=V(t,"utf-8"),n=JSON.parse(r);if(n.version!==1)return null;let o=n;if(!Ge(o)||x()!==o.pid)return null;if(!w(o.pid,e.kill))return P(),null;let s=e.now??Date.now,i=e.staleAfterMs??We;return s()-o.updatedAt>i?null:o}catch{return null}}function Ge(e){return e.version===1&&typeof e.pid=="number"&&Number.isInteger(e.pid)&&e.pid>0&&typeof e.updatedAt=="number"&&Number.isFinite(e.updatedAt)}function P(){let e=b();y(e)&&j(e,{recursive:!0,force:!0})}function ie(e=process.pid){E(),q(B(),String(e),"utf-8")}function x(){let e=B();if(!y(e))return null;try{let t=V(e,"utf-8").trim();if(t.length===0)return null;let r=Number(t);return!Number.isInteger(r)||r<=0?null:r}catch{return null}}function He(){let e=B();y(e)&&j(e,{force:!0})}function w(e,t=(r,n)=>{process.kill(r,n)}){if(!Number.isInteger(e)||e<=0)return!1;try{return t(e,0),!0}catch(r){return r.code==="EPERM"}}function Jt(e={}){let t=e.pidOverride??process.pid,r=x();return r!==null&&r!==t&&w(r,e.kill)?{kind:"busy",pid:r}:r!==null&&r!==t?(P(),ie(t),{kind:"swept",stalePid:r}):(ie(t),{kind:"acquired"})}function Wt(){He()}function Qt(e){let t=x();if(t===null||!w(t))throw t!==null&&P(),new Error("no active focus session");E();let r=ce(),n=`${r}.tmp`;q(n,`${e}
|
|
4
|
+
`,"utf-8"),se(n,r)}function Yt(){let e=ce();if(!y(e))return null;let t;try{t=V(e,"utf-8")}catch{return null}finally{j(e,{force:!0})}let r=t.trim().toLowerCase();return Qe.includes(r)?r:null}import{spawn as Ke}from"child_process";import{openSync as ze,closeSync as Xe}from"fs";var le="FLOWE_FOCUS_DAEMON",U="FLOWE_FOCUS_PRESET",de="FLOWE_FOCUS_AMBIENT_FILE",pe="FLOWE_FOCUS_AMBIENT_ID",me="FLOWE_FOCUS_BREAK_TYPE",fe="FLOWE_FOCUS_LONG_BREAK_TYPE",J=class extends Error{constructor(r){super(`a focus daemon is already running (pid ${r})`);this.existingPid=r;this.name="DaemonAlreadyRunningError"}existingPid};function Ze(e){let t={...process.env,[le]:"1",[U]:e.preset};return e.ambientFilePath&&(t[de]=e.ambientFilePath),e.ambientId&&(t[pe]=e.ambientId),e.breakType&&(t[me]=e.breakType),e.longBreakType&&(t[fe]=e.longBreakType),t}function Zt(e){let t=x();if(t!==null){if(w(t))throw new J(t);P()}E();let r=ue(),n=ze(r,"a"),o=e.spawnArgs?.cmd??process.execPath,a=e.spawnArgs?.args??[...process.execArgv,process.argv[1]??"","focus",e.preset],i=(e.spawnFn??Ke)(o,a,{detached:!0,stdio:["ignore",n,n],env:Ze(e)});if(Xe(n),i.unref(),i.pid===void 0)throw new Error("failed to spawn focus daemon (no pid returned)");let u=e.readyTimeoutMs??(e.spawnFn?0:1500);if(u>0&&!et(i.pid,u))throw new Error("focus daemon did not become ready");return{pid:i.pid,logPath:r}}function et(e,t){let r=Date.now()+t;for(;Date.now()<=r;){if(x()===e)return!0;tt(25)}return!1}function tt(e){let t=new SharedArrayBuffer(4),r=new Int32Array(t);Atomics.wait(r,0,0,e)}function er(){let e=process.env[U];if(e!=="pomodoro"&&e!=="dev"&&e!=="ultradian"&&e!=="test2"&&e!=="test5")throw new Error(`invalid ${U}: ${e??"(unset)"} \u2014 daemon child cannot start`);return{preset:e,ambientFilePath:process.env[de]||void 0,ambientId:process.env[pe]||void 0,breakType:process.env[me]||void 0,longBreakType:process.env[fe]||void 0}}function tr(){return process.env[le]==="1"}function rr(e){return[`detached. pid ${e.pid}.`,`logs: ${e.logPath}`,"status: flowe focus status","pause: flowe focus pause resume: flowe focus resume","skip: flowe focus skip quit: flowe focus quit"].join(`
|
|
5
|
+
`)}export{H as a,at as b,ct as c,D as d,ft as e,_t as f,xt as g,te as h,re as i,ke as j,Rt as k,It as l,Ye as m,Bt as n,Ut as o,P as p,Jt as q,Wt as r,Qt as s,Yt as t,J as u,Zt as v,er as w,tr as x,rr as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as y,d as v,e as C,i as f,j as D}from"./chunk-EC5WRPZP.js";var O="30\u201350 min",F=[{id:"quick_reset",name:"Reset",description:"Quick mental refresh between tasks.",duration_minutes:10,technique:"Yoga Nidra",category:"calm"},{id:"sprint_prep",name:"Lock In",description:"Before deep work or a focus sprint.",duration_minutes:10,technique:"Dopamine priming",category:"focus"},{id:"context_switch",name:"Clear",description:"After meetings, before code.",duration_minutes:8,technique:"Body scan",category:"focus"},{id:"shutdown",name:"Wind Down",description:"End of day, sleep transition.",duration_minutes:15,technique:"Breathing",category:"sleep"},{id:"logic_lock",name:"Unstuck",description:"When a problem keeps circling.",duration_minutes:10,technique:"Open focus",category:"focus"},{id:"deploy_anxiety",name:"Calm Down",description:"Heart racing, high stakes.",duration_minutes:5,technique:"Cyclic sighing",category:"calm"},{id:"executive_reset",name:"Defog",description:"Brain fog, decision fatigue.",duration_minutes:12,technique:"Quiet focus",category:"calm"},{id:"presentation_prep",name:"Steady",description:"Before a presentation or meeting.",duration_minutes:8,technique:"Grounding",category:"focus"}],I=[{id:"ht_stress",name:"Stress",hook:"For the days everything feels too much."},{id:"ht_anxiety",name:"Anxiety",hook:"For the racing 2 a.m. loop you cannot shake."},{id:"ht_people_pleasing",name:"People pleasing",hook:"When saying no still feels impossible."},{id:"ht_relationships",name:"Relationships",hook:"When the same fight keeps showing up."},{id:"ht_confidence",name:"Confidence",hook:"When imposter syndrome will not quiet down."},{id:"ht_fears",name:"Fears and phobias",hook:"For the freeze before the big moment."},{id:"ht_anger",name:"Anger",hook:"When the reaction is bigger than the trigger."},{id:"ht_procrastination",name:"Procrastination",hook:"For the task you cannot seem to start."},{id:"ht_burnout",name:"Burnout",hook:"When nothing feels like it refills you."}];function l(e,t){return Object.assign(new Error(t),{code:e})}function _(e){return(e?.backendUrl??y().backend_url).replace(/\/+$/,"")}async function Q(e={}){let t=e.fetch??globalThis.fetch,r=_(e),s;try{s=await t(`${r}/api/v1/cli/auth/start`,{method:"POST",headers:{"Content-Type":"application/json"}})}catch{throw l("network_error",`could not reach ${r}`)}if(!s.ok)throw l("network_error",`failed to start sign-in (${s.status})`);let n=await s.json();return{device_code:n.device_code,user_code:n.user_code,verification_uri:n.verification_uri,verification_uri_complete:n.verification_uri_complete,interval:n.interval,expires_at:n.expires_at}}async function U(e,t={}){let r=t.fetch??globalThis.fetch,s=t.setAuthToken??D,n=_(t),o;try{o=await r(`${n}/api/v1/cli/auth/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:e})})}catch{throw l("network_error",`could not reach ${n}`)}if(o.status===410)return{status:"expired"};if(!o.ok)throw l("network_error",`sign-in poll failed (${o.status})`);let i=await o.json();if(i.status==="authorized"&&i.token){await s(i.token);let c=await x({...t,getAuthToken:async()=>i.token}).catch(()=>({authenticated:!0,user_id:i.user_id,is_pro:!1,plan_type:"free"}));return c.first_name&&v(c.first_name),{status:"authorized",user_id:i.user_id,account:c}}return{status:"authorization_pending"}}async function x(e={}){let t=e.fetch??globalThis.fetch,r=e.getAuthToken??f,s=_(e),n=await r();if(!n)return{authenticated:!1,is_pro:!1,plan_type:"guest",quick_reset_quota:null};let o={Authorization:`Bearer ${n}`},[i,c,m]=await Promise.all([t(`${s}/api/v1/me`,{headers:o}).catch(()=>null),t(`${s}/api/v1/user/plan-status`,{headers:o}).catch(()=>null),t(`${s}/api/v1/quota/quick-reset`,{headers:o}).catch(()=>null)]);if(i?.status===401)return{authenticated:!1,is_pro:!1,plan_type:"guest",quick_reset_quota:null};let d=i?.ok?await i.json():null,a=c?.ok?await c.json():null,u=m?.ok?await m.json():null;d?.first_name&&v(d.first_name);let g=a?!a.is_quota_limited:u?.cap===-1;return{authenticated:!0,user_id:d?.user_id,first_name:d?.first_name??y().user_first_name??null,email:d?.email??null,is_pro:g,plan_type:a?.plan_type??(g?"pro":"free"),quick_reset_quota:u,team:a?.plan_source==="team"?q(a.team_info):null,team_paused:q(a?.team_paused)}}function q(e){return e?.team_name?{name:e.team_name,role:e.role??"member",status:e.status,trial_ends_at:e.trial_ends_at??null}:null}function P(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toLocaleDateString("en-GB",{day:"numeric",month:"short",timeZone:"UTC"})}function z(e){switch(e.status){case"trial_ended":return`The free trial of your team plan (${e.name}) ended.`;case"canceled":return`Your team plan (${e.name}) is canceled.`;case"paused":return`Your team plan (${e.name}) is paused.`;default:return`Your team plan (${e.name}) is off.`}}function W(e){if(e.team){let t=e.team.status==="trialing"?P(e.team.trial_ends_at):null;return`team: ${e.team.name}${t?` \xB7 trial ends ${t}`:""}`}if(e.team_paused){let t=e.team_paused.status==="trial_ended"?"free trial ended":e.team_paused.status??"off";return`team: ${e.team_paused.name} \xB7 ${t} \xB7 ask your admin to turn it back on`}return null}function G(e){return e.is_pro?e.team?`Flowe Pro from ${e.team.name}`:"Flowe Pro":e.plan_type}async function J(e,t={}){let r=t.fetch??globalThis.fetch,s=t.getAuthToken??f,n=_(t),o=y(),i=await s();if(!i)throw l("auth_required","Sign in with Flowe to run live Quick and Deep Resets.");let c=e.tier==="deep"?"hypnotherapy":"nsdr",m=e.voice??o.voice,d=e.ambient??"none",a;try{a=await r(`${n}/api/v1/sessions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({protocolId:c,sessionType:e.sessionType})})}catch{throw l("network_error","Network unreachable \u2014 try a local 30\u201390s micro-reset.")}if(!a.ok){let h=await a.json().catch(()=>({})),p=h?.error?.code,T=h?.error?.message??h?.message??`server error ${a.status}`;throw a.status===401?l("auth_required","Session expired \u2014 sign in to Flowe again."):a.status===403?l(p==="QUOTA_EXCEEDED"?"quota_exceeded":"subscription_required",T):l("network_error",T)}let u=await a.json(),g=`flowe://session/${u.session_id}`,b=`${n}/session/${u.session_id}`,S,k,w,A,R=[],$="waiting_for_join";if(e.startRoom!==!1)try{let h=await r(`${n}/api/v1/sessions/${encodeURIComponent(u.session_id)}/start`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({voiceId:m,ambient:d})});if(h.ok){let p=await h.json();S=p.room_name,k=p.livekit_url,w=p.livekit_token,A=p.current_phase,R=Array.isArray(p.phases)?p.phases:[],k&&w&&($="live")}}catch{}let E=e.tier==="deep"?"Deep Reset":"Quick Reset";return{session_id:u.session_id,tier:e.tier,protocol_id:u.protocol_id??c,session_type:u.session_type??e.sessionType,session_type_name:u.session_type_name,estimated_duration:u.estimated_duration,voice:m,ambient:d,room_name:S,livekit_url:k,livekit_token:w,current_phase:A,phases:R,join_url:g,web_url:b,status:$,requires_microphone:e.tier==="deep",message_for_user:`${E}: ${u.session_type_name} (${u.estimated_duration} min) ready \xB7 ${b}`}}async function M(e,t={},r={}){let s=r.fetch??globalThis.fetch,n=r.getAuthToken??f,o=_(r),i=await n();if(!i)throw l("auth_required","Sign in with Flowe first.");let c={};if(typeof t.durationMinutes=="number"&&(c.durationMinutes=t.durationMinutes),typeof t.rating=="number"&&(c.userFeedback={rating:t.rating,comments:t.comments}),(await s(`${o}/api/v1/sessions/${encodeURIComponent(e)}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify(c)})).ok){try{C()}catch{}return{completed:!0}}return{completed:!1}}async function Y(e,t={}){let r=t.fetch??globalThis.fetch,s=t.getAuthToken??f,n=_(t),o=await s();if(!o)return{cancelled:!1};try{return{cancelled:(await r(`${n}/api/v1/sessions/${encodeURIComponent(e)}`,{method:"DELETE",headers:{Authorization:`Bearer ${o}`}})).ok}}catch{return{cancelled:!1}}}export{O as a,F as b,I as c,Q as d,U as e,x as f,z as g,W as h,G as i,J as j,M as k,Y as l};
|