@flowe-ai/cli 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -7
- package/dist/chunk-3AO4PCEG.js +5 -0
- package/dist/chunk-B32B6OSK.js +1 -0
- package/dist/{chunk-M56P7SDZ.js → chunk-FXWU7EJA.js} +1 -1
- package/dist/{chunk-JTAA4OAX.js → chunk-LCVEDM2W.js} +1 -1
- package/dist/cli.js +68 -56
- package/dist/{login-IDFOVWCU.js → login-UO2GGRN2.js} +2 -2
- package/dist/mcp-server.js +9 -9
- package/dist/me-3CJ5RYRM.js +1 -0
- package/dist/{session-client-XHJ2MGA5.js → session-client-BR4JJT7O.js} +1 -1
- package/dist/ui/live-session.html +8 -8
- package/dist/ui/micro.html +6 -6
- package/package.json +4 -5
- package/protocols.json +857 -76
- package/skills/flowe/SKILL.md +15 -7
- package/audio/body_scan_60.ada.cues.json +0 -67
- package/audio/body_scan_60.ada.mp3 +0 -0
- package/audio/body_scan_60.ellie.cues.json +0 -67
- package/audio/body_scan_60.ellie.mp3 +0 -0
- package/audio/body_scan_60.sage.cues.json +0 -67
- package/audio/body_scan_60.sage.mp3 +0 -0
- package/audio/box_breath_45.ada.cues.json +0 -103
- package/audio/box_breath_45.ada.mp3 +0 -0
- package/audio/box_breath_45.ellie.cues.json +0 -103
- package/audio/box_breath_45.ellie.mp3 +0 -0
- package/audio/box_breath_45.sage.cues.json +0 -103
- package/audio/box_breath_45.sage.mp3 +0 -0
- package/audio/box_breath_60.ada.cues.json +0 -135
- package/audio/box_breath_60.ada.mp3 +0 -0
- package/audio/box_breath_60.ellie.cues.json +0 -135
- package/audio/box_breath_60.ellie.mp3 +0 -0
- package/audio/box_breath_60.sage.cues.json +0 -135
- package/audio/box_breath_60.sage.mp3 +0 -0
- package/audio/extended_box_90.ada.cues.json +0 -199
- package/audio/extended_box_90.ada.mp3 +0 -0
- package/audio/extended_box_90.ellie.cues.json +0 -199
- package/audio/extended_box_90.ellie.mp3 +0 -0
- package/audio/extended_box_90.sage.cues.json +0 -199
- package/audio/extended_box_90.sage.mp3 +0 -0
- package/audio/eye_rotation_30.ada.cues.json +0 -41
- package/audio/eye_rotation_30.ada.mp3 +0 -0
- package/audio/eye_rotation_30.ellie.cues.json +0 -41
- package/audio/eye_rotation_30.ellie.mp3 +0 -0
- package/audio/eye_rotation_30.sage.cues.json +0 -41
- package/audio/eye_rotation_30.sage.mp3 +0 -0
- package/audio/full_sensory_90.ada.cues.json +0 -60
- package/audio/full_sensory_90.ada.mp3 +0 -0
- package/audio/full_sensory_90.ellie.cues.json +0 -60
- package/audio/full_sensory_90.ellie.mp3 +0 -0
- package/audio/full_sensory_90.sage.cues.json +0 -60
- package/audio/full_sensory_90.sage.mp3 +0 -0
- package/audio/grounded_feet_45.ada.cues.json +0 -40
- package/audio/grounded_feet_45.ada.mp3 +0 -0
- package/audio/grounded_feet_45.ellie.cues.json +0 -40
- package/audio/grounded_feet_45.ellie.mp3 +0 -0
- package/audio/grounded_feet_45.sage.cues.json +0 -40
- package/audio/grounded_feet_45.sage.mp3 +0 -0
- package/audio/neck_rotation_45.ada.cues.json +0 -55
- package/audio/neck_rotation_45.ada.mp3 +0 -0
- package/audio/neck_rotation_45.ellie.cues.json +0 -55
- package/audio/neck_rotation_45.ellie.mp3 +0 -0
- package/audio/neck_rotation_45.sage.cues.json +0 -55
- package/audio/neck_rotation_45.sage.mp3 +0 -0
- package/audio/palming_60.ada.cues.json +0 -61
- package/audio/palming_60.ada.mp3 +0 -0
- package/audio/palming_60.ellie.cues.json +0 -61
- package/audio/palming_60.ellie.mp3 +0 -0
- package/audio/palming_60.sage.cues.json +0 -61
- package/audio/palming_60.sage.mp3 +0 -0
- package/audio/physiological_sigh_30.ada.cues.json +0 -55
- package/audio/physiological_sigh_30.ada.mp3 +0 -0
- package/audio/physiological_sigh_30.ellie.cues.json +0 -55
- package/audio/physiological_sigh_30.ellie.mp3 +0 -0
- package/audio/physiological_sigh_30.sage.cues.json +0 -55
- package/audio/physiological_sigh_30.sage.mp3 +0 -0
- package/audio/progressive_palming_90.ada.cues.json +0 -61
- package/audio/progressive_palming_90.ada.mp3 +0 -0
- package/audio/progressive_palming_90.ellie.cues.json +0 -61
- package/audio/progressive_palming_90.ellie.mp3 +0 -0
- package/audio/progressive_palming_90.sage.cues.json +0 -61
- package/audio/progressive_palming_90.sage.mp3 +0 -0
- package/audio/quick_palming_30.ada.cues.json +0 -40
- package/audio/quick_palming_30.ada.mp3 +0 -0
- package/audio/quick_palming_30.ellie.cues.json +0 -40
- package/audio/quick_palming_30.ellie.mp3 +0 -0
- package/audio/quick_palming_30.sage.cues.json +0 -40
- package/audio/quick_palming_30.sage.mp3 +0 -0
- package/dist/chunk-3KM7AYV7.js +0 -5
- package/dist/chunk-DX2IZG3L.js +0 -1
- package/dist/me-6WIWKE2Q.js +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @flowe-ai/cli
|
|
2
2
|
|
|
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.
|
|
3
|
+
> Science-backed resets in your terminal and AI chat: 30–90 s micro-resets shaped to your moment, live Quick and Deep Resets with Ada, and an MCP App for your AI tools.
|
|
4
4
|
|
|
5
|
-
`flowe` runs 30–90 s micro-resets
|
|
5
|
+
`flowe` runs 30–90 s micro-resets shaped to your moment, with no account, live Quick and Deep Resets with Ada when you sign in, and **MCP App cards (SEP-1865)** inside the Codex app, Claude Desktop, Antigravity, Cursor and VS Code, with plain text in Claude Code and Codex in a terminal.
|
|
6
6
|
|
|
7
7
|
Docs and a live demo: **[cli.flowe.ai](https://cli.flowe.ai)**
|
|
8
8
|
|
|
@@ -41,19 +41,26 @@ Supporting MCP Apps hosts mount Flowe's self-contained **Dusk + Peek** UI cards
|
|
|
41
41
|
|
|
42
42
|
| Tier | Duration | Auth | Command |
|
|
43
43
|
|---|---|---|---|
|
|
44
|
-
| **Micro-Resets** | 30–90s |
|
|
44
|
+
| **Micro-Resets** | 30–90s | 5 shaped a week with no account; unlimited with Flowe Pro | `flowe reset 60 --protocol box_breath` |
|
|
45
45
|
| **Quick Resets** | 5–15 min | 5 free a week with an account | `flowe quick logic_lock --ambient rain_window_soft` |
|
|
46
46
|
| **Deep Resets** | 30–50 min | Flowe Pro or a team plan | `flowe deep ht_burnout --open` |
|
|
47
47
|
|
|
48
48
|
### Micro-Resets
|
|
49
49
|
|
|
50
|
+
Every micro-reset is shaped to the moment. Your agent (or you) describes it in one plain line; Flowe writes the words around a fixed breath plan, voices them, and the CLI plays the file. The breath counts and pauses come from the plan, never from the model. Nothing is pre-recorded.
|
|
51
|
+
|
|
50
52
|
```bash
|
|
51
53
|
flowe reset # interactive picker
|
|
52
|
-
flowe reset 30 --protocol physiological_sigh
|
|
53
|
-
flowe reset 60 --protocol box_breath
|
|
54
|
+
flowe reset 30 --protocol physiological_sigh --moment "Third red test run tonight" --feeling frustrated
|
|
55
|
+
flowe reset 60 --protocol box_breath --situation before_meeting
|
|
54
56
|
flowe reset --quick # skip picker, use defaults
|
|
55
57
|
```
|
|
56
58
|
|
|
59
|
+
- **5 a week without an account.** Signing in brings an account's own 5 (shared with Quick Resets); Flowe Pro, alone or through a team, is unlimited. When the 5 are used, the card or terminal says so and nothing plays.
|
|
60
|
+
- **Never a broken wait.** Offline, or no audio within 12 seconds, the reset still runs as a silent guide (orb, cue captions, soft chimes in the card) with no voice, and it does not count toward the 5.
|
|
61
|
+
- **Shaping is on by default.** `flowe config shaping off` (or `FLOWE_OPT_OUT=1`) runs the silent guide instead, and nothing is sent.
|
|
62
|
+
- In an MCP App card, the reset runs a breath-driven orb with captions lit word by word, and ends with a small "back to it" step for the work you left.
|
|
63
|
+
|
|
57
64
|
### Live Quick & Deep Resets (Flowe Account)
|
|
58
65
|
|
|
59
66
|
```bash
|
|
@@ -78,10 +85,11 @@ flowe voice ada | ellie | sage
|
|
|
78
85
|
|
|
79
86
|
## Privacy & Opt-Out
|
|
80
87
|
|
|
81
|
-
- **No account needed:**
|
|
88
|
+
- **No account needed:** Micro-resets work with no account. `~/.config/flowe/config.json` keeps a random install ID, which counts the week's 5 shaped resets.
|
|
89
|
+
- **One plain line, never code:** A shaped reset sends only a line about your moment (≤ 200 characters), two labels (situation, feeling) and the time of day. The CLI strips paths, links, email addresses, keys and anything that looks like code before sending, and the server strips again; the card shows the line it sent ("For …"). No audio is stored.
|
|
82
90
|
- **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
91
|
- **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.
|
|
92
|
+
- **Full opt-out:** Set `FLOWE_OPT_OUT=1` to disable telemetry, shaping and proactive MCP suggestions completely. `flowe config shaping off` turns off shaping alone.
|
|
85
93
|
|
|
86
94
|
## License
|
|
87
95
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{a as R,e as ue,g as le,h as I,i as de,j as pe,k as $}from"./chunk-B32B6OSK.js";import{readFileSync as ze}from"fs";import{dirname as qe,join as Be}from"path";import{fileURLToPath as Ue}from"url";var Je=qe(Ue(import.meta.url));function L(){try{let e=ze(Be(Je,"..","package.json"),"utf-8");return JSON.parse(e).version}catch{return"0.0.0"}}var ln=["logic_lock","deploy_anxiety","context_switch","sprint_prep","quick_reset","executive_reset","presentation_prep","shutdown"],dn=["ht_stress","ht_anxiety","ht_people_pleasing","ht_relationships","ht_confidence","ht_fears","ht_anger","ht_procrastination","ht_burnout"];import{readFileSync as We}from"fs";import{dirname as Ke,join as Ge}from"path";import{fileURLToPath as Qe}from"url";var Ze=Ke(Qe(import.meta.url));function He(){return Ge(Ze,"..","protocols.json")}var E=null;function Ye(){if(E)return E;try{let e=We(He(),"utf-8");return E=JSON.parse(e),E}catch{return E={protocols:{}},E}}function K(){return Object.values(Ye().protocols)}function G(e){return e.replace(/_\d+$/,"")}function hn(){let e=new Set;for(let t of K())e.add(G(t.protocol_id));return[...e].sort()}function yn(e){return K().filter(t=>G(t.protocol_id)===e).map(t=>t.duration_seconds).sort((t,n)=>t-n)}function Q(e,t){let n=K().filter(o=>o.duration_seconds===e&&(t===void 0||G(o.protocol_id)===t));return n.length===0?null:t!==void 0?n[0]:n[Math.floor(Math.random()*n.length)]}import{spawn as Z}from"child_process";import{platform as Xe}from"os";var y=null;function me(e){return typeof e!="number"||!Number.isFinite(e)||e<=0?1:Math.min(2,Math.max(.05,e))}function et(e,t=1){let n=me(t),o=Xe();if(o==="darwin"){let i=n===1?[e]:["-v",String(n),e];return Z("afplay",i,{stdio:"ignore"})}if(o==="win32"){let l=["Add-Type -AssemblyName presentationCore;","$p = New-Object System.Windows.Media.MediaPlayer;",`$p.Open([Uri]'${e.replace(/'/g,"''")}');`,`$p.Volume = ${Math.min(1,n)};`,"$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 Z("powershell",["-NoProfile","-NonInteractive","-Command",l],{stdio:"ignore"})}let r=Math.round(32768*n);return Z("mpg123",["-q","-f",String(r),e],{stdio:"ignore"})}function H(){return y!==null}function vn(){return y?.donePromise??null}function fe(e,t={}){if(y)return Promise.reject(new Error("already playing \u2014 call stopAudio first"));let n=me(t.volume),o=t.spawnPlayer??et,r;try{r=o(e,n)}catch(u){return Promise.reject(u instanceof Error?u:new Error(String(u)))}let i=!1,l=!1,a,c,s=new Promise((u,d)=>{a=u,c=d}),p=()=>{y?.child===r&&(y=null)},f=()=>{i||(i=!0,p(),a())},m=u=>{i||(i=!0,p(),c(u))};return y={child:r,stop:()=>{if(l=!0,p(),!r.killed)try{r.kill("SIGTERM")}catch{}f()},donePromise:s},r.once("error",u=>{if(l){f();return}let d=Object.assign(new Error(`audio playback failed: ${u.message}`),{code:"audio_device"});m(d)}),r.once("exit",(u,d)=>{if(l||d==="SIGTERM"||d==="SIGINT"||u===0||u===null){f();return}let _=Object.assign(new Error(`audio player exited with code ${u}`),{code:"audio_device"});m(_)}),s}function _e(){y&&y.stop()}import{existsSync as k,mkdirSync as tt,readFileSync as Y,renameSync as he,rmSync as X,writeFileSync as ee}from"fs";import{homedir as nt}from"os";import{join as P}from"path";var ot="state.json",rt="daemon.pid",st="control.txt",it="daemon.log",at=3e4,ct=["pause","resume","skip","quit"];function j(){return process.env.FLOWE_HOME??P(nt(),".flowe")}function M(){return P(j(),"sessions","active")}function ye(){return P(M(),ot)}function te(){return P(M(),rt)}function Se(){return P(M(),st)}function be(){return P(M(),it)}function D(){let e=M();return k(e)||tt(e,{recursive:!0}),e}function Tn(e){D();let t=ye(),n=`${t}.tmp`;ee(n,JSON.stringify(e,null,2),"utf-8"),he(n,t)}function xe(e={}){let t=ye();if(!k(t))return null;try{let n=Y(t,"utf-8"),o=JSON.parse(n);if(o.version!==1)return null;let r=o;if(!ut(r)||A()!==r.pid)return null;if(!C(r.pid,e.kill))return O(),null;let l=e.now??Date.now,a=e.staleAfterMs??at;return l()-r.updatedAt>a?null:r}catch{return null}}function ut(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 O(){let e=M();k(e)&&X(e,{recursive:!0,force:!0})}function ge(e=process.pid){D(),ee(te(),String(e),"utf-8")}function A(){let e=te();if(!k(e))return null;try{let t=Y(e,"utf-8").trim();if(t.length===0)return null;let n=Number(t);return!Number.isInteger(n)||n<=0?null:n}catch{return null}}function lt(){let e=te();k(e)&&X(e,{force:!0})}function C(e,t=(n,o)=>{process.kill(n,o)}){if(!Number.isInteger(e)||e<=0)return!1;try{return t(e,0),!0}catch(n){return n.code==="EPERM"}}function Rn(e={}){let t=e.pidOverride??process.pid,n=A();return n!==null&&n!==t&&C(n,e.kill)?{kind:"busy",pid:n}:n!==null&&n!==t?(O(),ge(t),{kind:"swept",stalePid:n}):(ge(t),{kind:"acquired"})}function Dn(){lt()}function On(e){let t=A();if(t===null||!C(t))throw t!==null&&O(),new Error("no active focus session");D();let n=Se(),o=`${n}.tmp`;ee(o,`${e}
|
|
2
|
+
`,"utf-8"),he(o,n)}function Cn(){let e=Se();if(!k(e))return null;let t;try{t=Y(e,"utf-8")}catch{return null}finally{X(e,{force:!0})}let n=t.trim().toLowerCase();return ct.includes(n)?n:null}import{existsSync as Ee,mkdirSync as xt,readFileSync as ke,renameSync as wt,writeFileSync as vt}from"fs";import{join as Et}from"path";import{readFileSync as dt,writeFileSync as pt,mkdirSync as mt,existsSync as oe,appendFileSync as ft}from"fs";import{homedir as _t}from"os";import{join as ve}from"path";var ne=ve(_t(),".cache","flowe"),F=ve(ne,"pending-events.jsonl"),gt=5e3;function N(){let e=process.env.FLOWE_OPT_OUT?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}async function V(e,t,n){if(!(t.telemetry==="off"||N())){try{ht(),yt(e)}catch{return}try{await bt(t,n)}catch{}}}function ht(){oe(ne)||mt(ne,{recursive:!0})}function yt(e){for(let t of e)ft(F,JSON.stringify(t)+`
|
|
3
|
+
`,"utf-8")}function St(){return oe(F)?dt(F,"utf-8").split(`
|
|
4
|
+
`).filter(t=>t.trim().length>0).map(t=>JSON.parse(t)):[]}function we(){oe(F)&&pt(F,"","utf-8")}async function bt(e,t){let n=St();if(n.length===0)return;let o={version:L(),platform:`${process.platform}-${process.arch}`,node_version:process.version},r=new AbortController,i=setTimeout(()=>r.abort(),gt);try{let l={"Content-Type":"application/json"};t&&(l.Authorization=`Bearer ${t}`);let a=await fetch(`${e.backend_url}/api/v1/reset/log`,{method:"POST",headers:l,body:JSON.stringify({events:n,client:o,anonymous_id:e.anonymous_id}),signal:r.signal});(a.ok||a.status===401||a.status===400)&&we()}finally{clearTimeout(i)}}var kt="mcp-session.json",Pt=300*1e3,Pe=14400*1e3;function re(){return Et(j(),kt)}function z(e){return{version:1,session_started_at:e,last_reset_at:null,last_suggested_at:null,snoozed_until:null,resets_this_session:0}}function q(e=Date.now()){let t=re();if(!Ee(t)){let n=z(e);return x(n),n}try{let n=JSON.parse(ke(t,"utf-8"));if(n.version!==1||typeof n.session_started_at!="number"){let r=z(e);return x(r),r}let o=Math.max(n.session_started_at,n.last_reset_at??0,n.last_suggested_at??0);if(e-o>Pe){let r=z(e);return x(r),r}return{version:1,session_started_at:n.session_started_at,last_reset_at:n.last_reset_at??null,last_suggested_at:n.last_suggested_at??null,snoozed_until:n.snoozed_until??null,resets_this_session:n.resets_this_session??0}}catch{let n=z(e);return x(n),n}}function x(e){try{let t=j();Ee(t)||xt(t,{recursive:!0});let n=re(),o=`${n}.tmp`;vt(o,JSON.stringify(e,null,2),"utf-8"),wt(o,n)}catch{}}function Me(e=Date.now()){try{let t=JSON.parse(ke(re(),"utf-8"));if(t.version!==1||typeof t.session_started_at!="number")return null;let n=Math.max(t.session_started_at,t.last_reset_at??0,t.last_suggested_at??0);return e-n>Pe?null:Math.max(0,Math.round((e-t.session_started_at)/6e4))}catch{return null}}function Kn(e=Date.now()){let t=q(e);return t.last_suggested_at=e,x(t),t}function Gn(e=Date.now()){let t=q(e);return t.last_reset_at=e,t.resets_this_session+=1,x(t),t}function Qn(e,t=Date.now()){let n=Math.max(1,Math.min(240,Math.round(e))),o=q(t);return o.snoozed_until=t+n*60*1e3,x(o),o}function Zn(e={}){let t=e.nowMs??Date.now(),n=e.cooldownMs??Pt,o=q(t),r=xe({now:()=>t}),i=N(),l=Math.max(0,Math.round((t-o.session_started_at)/6e4)),a=o.last_reset_at!==null?Math.max(0,t-o.last_reset_at):null,c=a!==null?Math.round(a/6e4):null,s=a!==null?Math.max(0,n-a):0,p=o.snoozed_until!==null?Math.max(0,o.snoozed_until-t):0,f=null;i?f="opted_out":p>0?f="snoozed":r&&(r.status==="BREAK"||r.status==="LONG_BREAK")?f="focus_break_active":s>0&&(f="cooldown");let m="micro";if(e.authenticated){let u=c??l;u>=120?m="deep":u>=45&&(m="quick")}return{opted_out:i,can_suggest:f===null,blocked_reason:f,session_minutes:l,minutes_since_last_reset:c,cooldown_remaining_seconds:Math.ceil(s/1e3),snooze_remaining_minutes:Math.ceil(p/6e4),resets_this_session:o.resets_this_session,sessions_today:I(new Date(t)),streak_days:de(new Date(t)),total_sessions:pe(),active_focus:r,recommended_tier:m}}var Mt=["debugging_loop","failing_tests","waiting_on_build","waiting_on_agent","before_deploy","after_shipping","before_meeting","after_meeting","reviewing_code","context_switch","long_session","end_of_day"],At=["frustrated","anxious","foggy","tired","wired","tense","restless","eyes_tired","flat","fine"],Tt=12e3,se=200;function oo(e){return typeof e=="string"&&Mt.includes(e)}function ro(e){return typeof e=="string"&&At.includes(e)}function Ae(e=R()){return e.shaping!==!1&&!N()}var Rt="ts|tsx|js|jsx|mjs|cjs|json|py|rb|go|rs|java|kt|swift|c|h|cc|cpp|cs|php|sh|zsh|bash|yml|yaml|toml|ini|md|mdx|css|scss|html|vue|svelte|sql|lock|env|log|txt|xml|gradle|tf",Dt=[/```[\s\S]*?(?:```|$)/g,/`[^`]*`?/g,/\b(?:https?|ftp|file|ssh|git):\/\/\S+/gi,/\bwww\.\S+/gi,/\b[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g,/\beyJ[\w-]+(?:\.[\w-]+)*/g,/\b(?:sk|pk|rk|ghp|gho|ghu|ghs|ghr|github_pat|xox[abprs]|flowe_cli|AKIA|ASIA|AIza|glpat|npm)[-_][\w-]*/g,/(?:[A-Za-z]:)?(?:~|\.{1,2})?(?:[\w.@-]*[\\/])+[\w.@-]*/g,new RegExp(`\\b[\\w-]+\\.(?:${Rt})\\b`,"gi"),/\b[\w.$]+\([^)]*\)/g,/(?:^|\s)--?[A-Za-z][\w-]*/g,/\$\{?\w+\}?/g,/=>|->|::|!==?|===?|<=|>=|&&|\|\|/g,/\b[A-Za-z]+(?:_[A-Za-z0-9]+)+\b/g,/\b[a-z]+[A-Z][A-Za-z0-9]*\b/g,/\b[A-Z][a-z0-9]+(?:[A-Z][a-z0-9]*)+\b/g,/\b0x[0-9a-f]+\b/gi,/[{}[\]<>;=|\\^~*#]+/g];function Ot(e){return e.length>=7&&/^[0-9a-f]+$/i.test(e)&&/\d/.test(e)?!0:e.length>=20&&/\d/.test(e)&&/[A-Za-z]/.test(e)}function Ct(e){if(typeof e!="string")return null;let t=e.replace(/[\r\n\t]+/g," ");for(let n of Dt)t=t.replace(n,o=>` ${o.match(/[.,!?]+$/)?.[0]??""}`);if(t=t.split(/\s+/).filter(n=>n&&!Ot(n.replace(/[^\w-]/g,""))).join(" "),t=t.replace(/\(\s*\)|"\s*"|'\s*'/g," ").replace(/\s+([,.;:!?])/g,"$1").replace(/([,;:])(?:\s*[,;:])+/g,"$1").replace(/\s+/g," ").replace(/^[\s,.;:!?'"()-]+/,"").replace(/[\s,;:'"(-]+$/,"").trim(),!/[A-Za-z\u00C0-\uFFFF]{2,}/.test(t))return null;if(t.length>se){let n=t.slice(0,se+1),o=n.lastIndexOf(" ");t=(o>40?n.slice(0,o):n.slice(0,se)).replace(/[\s,;:'"(-]+$/,"")}return t}function Ft(e){return e>=5&&e<12?"morning":e>=12&&e<17?"afternoon":e>=17&&e<22?"evening":"late"}function Te(e){return e==="guest"?"That\u2019s this week\u2019s 5. Sign in for 5 more.":"That\u2019s this week\u2019s 5. Flowe Pro is unlimited."}var B=class extends Error{constructor(n,o){super(Te(n));this.account=n;this.allowance=o;this.name="ShapedLimitError"}account;allowance;code="shaped_limit"};function Re(e){if(!e||typeof e!="object")return null;let t=e;return typeof t.used!="number"||typeof t.cap!="number"?null:{used:t.used,cap:t.cap,resets_at:typeof t.resets_at=="string"?t.resets_at:null}}function Nt(e){if(!e||typeof e!="object")return null;let t=e,n=t.audio;if(!n||typeof n.base64!="string"||n.base64.length===0||!Array.isArray(t.cues)||!Array.isArray(t.captions)||typeof t.protocol_id!="string"||typeof t.duration_seconds!="number")return null;let o=t.account==="pro"||t.account==="free"?t.account:"guest";return{reset_id:typeof t.reset_id=="string"?t.reset_id:"",protocol_id:t.protocol_id,family:typeof t.family=="string"?t.family:t.protocol_id.replace(/_\d+$/,""),display_name:typeof t.display_name=="string"?t.display_name:"Micro reset",category:t.category??"breath",duration_seconds:t.duration_seconds,voice:t.voice??"ellie",audio:{mime:typeof n.mime=="string"?n.mime:"audio/mpeg",base64:n.base64},cues:t.cues,captions:t.captions,back_to_it:typeof t.back_to_it=="string"&&t.back_to_it.trim()?t.back_to_it.trim():null,moment:typeof t.moment=="string"&&t.moment.trim()?t.moment.trim():null,account:o,allowance:o==="pro"?null:Re(t.allowance)}}async function De(e,t={}){let n=t.fetch??globalThis.fetch,o=t.config??R(),r=t.now?.()??new Date,i=await(t.getAuthToken??$)().catch(()=>null),l={"Content-Type":"application/json"};i?l.Authorization=`Bearer ${i}`:l["X-Flowe-Install"]=o.install_id;let a=r.getHours(),c={duration_seconds:e.duration,context:{part_of_day:Ft(a),local_hour:a,...e.context},client:{name:"flowe-cli",version:L(),surface:e.surface}};e.family&&(c.protocol=e.family);let s=Ct(e.moment);s&&(c.moment=s),e.situation&&(c.situation=e.situation),e.feeling&&(c.feeling=e.feeling),e.voice&&(c.voice=e.voice);let p=new AbortController,f=setTimeout(()=>p.abort(),t.timeoutMs??Tt);try{let m=await n(`${o.backend_url.replace(/\/+$/,"")}/api/v1/micro-resets`,{method:"POST",headers:l,body:JSON.stringify(c),signal:p.signal}),u=await m.json().catch(()=>null);if(m.status===402){let _=u?.error??{};if(_.code==="SHAPED_LIMIT"){let w=_.account??u?.account,T=w==="free"||w==="guest"?w:i?"free":"guest";return{kind:"limit",account:T,allowance:Re(_.allowance??u?.allowance),message:Te(T)}}}if(!m.ok)return{kind:"unavailable",reason:`http_${m.status}`};let d=Nt(u);return d?{kind:"ok",reset:d}:{kind:"unavailable",reason:"bad_response"}}catch(m){return{kind:"unavailable",reason:p.signal.aborted?"timeout":m?.message||"offline"}}finally{clearTimeout(f)}}import{mkdirSync as It,readdirSync as $t,rmSync as Fe,statSync as Lt,writeFileSync as jt}from"fs";import{homedir as Vt,tmpdir as zt}from"os";import{join as U}from"path";import{nanoid as Oe}from"nanoid";var qt=[U(Vt(),".cache","flowe","resets"),U(zt(),"flowe-resets")],Bt=1440*60*1e3;function Ut(e,t){let n=e.toLowerCase();if(n.includes("inhale"))return"inhale";if(n.includes("exhale"))return"exhale";if(n.includes("hold"))return t==="exhale"||t==="hold_out"?"hold_out":"hold_in"}function Jt(e,t,n){if(e.length===0)return[];let r=t*1e3/e.length,i;return e.map((l,a)=>{let c={label:l,mode:n,start_ms:Math.round(a*r),end_ms:Math.round((a+1)*r)};if(n==="breath"){let s=Ut(l,i);s&&(c.phase=s),i=s??i}return c})}function Wt(e,t){if(!e.plan?.length)return Jt(e.text_cues,t,e.category);let n=t/e.duration_seconds;return n===1?e.plan.map(o=>({...o})):e.plan.map(o=>({...o,start_ms:Math.round(o.start_ms*n),end_ms:Math.round(o.end_ms*n)}))}function Kt(e,t){try{for(let n of $t(e)){if(!n.endsWith(".mp3"))continue;let o=U(e,n);t-Lt(o).mtimeMs>Bt&&Fe(o,{force:!0})}}catch{}}function Gt(e,t){let n=Buffer.from(t,"base64");for(let o of qt)try{It(o,{recursive:!0}),Kt(o,Date.now());let r=U(o,`${e}.mp3`);return jt(r,n),r}catch{}return null}function Qt(e){try{Fe(e,{force:!0})}catch{}}var Ce=new Set;function Zt(e){if(e){if(Ce.has(e))return;Ce.add(e)}le()}function So(){return H()?(_e(),!0):!1}async function bo(e,t="user_requested",n,o={}){let r=process.env.FLOWE_SILENT_AUDIO==="1"?"silent":o.audioMode??"local";if(r==="local"&&H())throw Object.assign(new Error("a reset is already running"),{code:"agent_busy"});let i=R(),l=o.voice??i.voice,a=o.surface??"terminal",c=Q(e,n)??(n?Q(e):null),s=null,p=null;if(r==="local"&&Ae(i)){let g=a==="mcp"?Me():null,S=await De({duration:e,family:n,moment:o.moment,situation:o.situation,feeling:o.feeling,voice:o.voice,surface:a,context:{...g!==null?{session_minutes:g}:{},resets_today:Ht()}},{config:i,...o.shapedDeps});if(S.kind==="limit")throw new B(S.account,S.allowance);S.kind==="ok"&&(p=Gt(S.reset.reset_id||Oe(8),S.reset.audio.base64),p&&(s=S.reset))}if(!s&&!c){let g=n?`${n} at ${e}s`:`${e}s`;throw Object.assign(new Error(`no protocol available for ${g}`),{code:"protocol_unavailable"})}let f=s?"local":"silent",m=s?.protocol_id??c.protocol_id,u=s?.voice??l,d=s?.duration_seconds??e,_=`reset_${Oe(8)}`,w=new Date,T=Math.floor(w.getTime()/1e3),Ve=T+d;ue();let J=await $(),W=g=>({type:g,session_id:_,protocol_id:m,duration_seconds:d,voice:u,trigger:t,client_timestamp:new Date().toISOString()});if(await V([W("reset_started")],i,J),s&&p){let g=p;fe(g).then(()=>{if(o.recordOnComplete)try{Zt(_)}catch{}V([W("reset_completed")],i,J).catch(()=>{})}).catch(()=>{V([W("reset_abandoned")],i,J).catch(()=>{})}).finally(()=>Qt(g))}let ce={session_id:_,duration_seconds:d,voice:u,audio_mode:f,status:"started",started_at_unix:T,started_at_ms:w.getTime(),ends_at_unix:Ve};if(s)return{...ce,protocol:s.protocol_id,protocol_display_name:s.display_name,category:s.category,shaped:!0,reset_id:s.reset_id,cues:s.cues,captions:s.captions,back_to_it:s.back_to_it,moment:s.moment,account:s.account,allowance:s.allowance,rounds:c&&c.protocol_id===s.protocol_id?c.rounds:void 0,message_for_user:`${d}s ${s.display_name} started \xB7 ${u}`};let v=c;return{...ce,protocol:v.protocol_id,protocol_display_name:v.display_name,category:v.category,shaped:!1,cues:Wt(v,d),rounds:v.rounds,message_for_user:`${d}s ${v.display_name} started \xB7 silent guide`}}function Ht(){try{return I()}catch{return 0}}import{spawn as Yt}from"child_process";import{openSync as Xt,closeSync as en}from"fs";var Ne="FLOWE_FOCUS_DAEMON",ie="FLOWE_FOCUS_PRESET",Ie="FLOWE_FOCUS_AMBIENT_FILE",$e="FLOWE_FOCUS_AMBIENT_ID",Le="FLOWE_FOCUS_BREAK_TYPE",je="FLOWE_FOCUS_LONG_BREAK_TYPE",ae=class extends Error{constructor(n){super(`a focus daemon is already running (pid ${n})`);this.existingPid=n;this.name="DaemonAlreadyRunningError"}existingPid};function tn(e){let t={...process.env,[Ne]:"1",[ie]:e.preset};return e.ambientFilePath&&(t[Ie]=e.ambientFilePath),e.ambientId&&(t[$e]=e.ambientId),e.breakType&&(t[Le]=e.breakType),e.longBreakType&&(t[je]=e.longBreakType),t}function Po(e){let t=A();if(t!==null){if(C(t))throw new ae(t);O()}D();let n=be(),o=Xt(n,"a"),r=e.spawnArgs?.cmd??process.execPath,i=e.spawnArgs?.args??[...process.execArgv,process.argv[1]??"","focus",e.preset],a=(e.spawnFn??Yt)(r,i,{detached:!0,stdio:["ignore",o,o],env:tn(e)});if(en(o),a.unref(),a.pid===void 0)throw new Error("failed to spawn focus daemon (no pid returned)");let c=e.readyTimeoutMs??(e.spawnFn?0:1500);if(c>0&&!nn(a.pid,c))throw new Error("focus daemon did not become ready");return{pid:a.pid,logPath:n}}function nn(e,t){let n=Date.now()+t;for(;Date.now()<=n;){if(A()===e)return!0;on(25)}return!1}function on(e){let t=new SharedArrayBuffer(4),n=new Int32Array(t);Atomics.wait(n,0,0,e)}function Mo(){let e=process.env[ie];if(e!=="pomodoro"&&e!=="dev"&&e!=="ultradian"&&e!=="test2"&&e!=="test5")throw new Error(`invalid ${ie}: ${e??"(unset)"} \u2014 daemon child cannot start`);return{preset:e,ambientFilePath:process.env[Ie]||void 0,ambientId:process.env[$e]||void 0,breakType:process.env[Le]||void 0,longBreakType:process.env[je]||void 0}}function Ao(){return process.env[Ne]==="1"}function To(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{L as a,ln as b,dn as c,K as d,hn as e,yn as f,vn as g,fe as h,_e as i,Tn as j,xe as k,O as l,Rn as m,Dn as n,On as o,Cn as p,Kn as q,Gn as r,Qn as s,Zn as t,Mt as u,At as v,oo as w,ro as x,Ae as y,Ct as z,B as A,Zt as B,So as C,bo as D,ae as E,Po as F,Mo as G,Ao as H,To as I};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readFileSync as b,writeFileSync as P,mkdirSync as N,existsSync as v}from"fs";import{randomUUID as O}from"crypto";import{homedir as U,platform as I}from"os";import{join as _}from"path";import{nanoid as k}from"nanoid";var F="https://www.flowe.ai",V=90,R=["sage","ada","ellie"],z=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,K=7,D=null,u=0;function C(){return D??=O(),D}function L(t){return typeof t=="string"&&R.includes(t)?t:"ellie"}function x(){let t=U();return I()==="win32"?_(t,"AppData","Roaming","flowe"):_(t,".config","flowe")}function E(){return _(x(),"config.json")}function S(){return{version:2,voice:"ellie",anonymous_id:`anon_${k(12)}`,telemetry:"on",backend_url:process.env.FLOWE_BACKEND_URL||F,session_dates:[],install_id:C(),shaping:!0,...u?{nudge_snoozed_until:u}:{}}}function $(t){let e=typeof t.version=="number"?t.version:1,n=t.voice,o=L(n),r={version:2,voice:o,anonymous_id:t.anonymous_id??`anon_${k(12)}`,telemetry:t.telemetry??"on",backend_url:t.backend_url??F,session_dates:Array.isArray(t.session_dates)?t.session_dates:[],install_id:typeof t.install_id=="string"&&z.test(t.install_id)?t.install_id:C(),shaping:t.shaping!==!1};return typeof t.first_reset_at=="string"&&(r.first_reset_at=t.first_reset_at),typeof t.user_first_name=="string"&&(r.user_first_name=t.user_first_name),typeof t.nudge_snoozed_until=="number"&&(r.nudge_snoozed_until=t.nudge_snoozed_until),u>(r.nudge_snoozed_until??0)&&(r.nudge_snoozed_until=u),(e<2||n!==o||r.install_id!==t.install_id)&&i(r),r}function s(){let t=E();if(!v(t)){let e=S();return i(e),e}try{let e=b(t,"utf-8"),n=JSON.parse(e),o=$(n);return process.env.FLOWE_BACKEND_URL&&(o.backend_url=process.env.FLOWE_BACKEND_URL),o}catch{let e=S();return i(e),e}}function f(t){let e=x();v(e)||N(e,{recursive:!0}),P(E(),JSON.stringify(t,null,2),"utf-8")}function i(t){try{return f(t),!0}catch{return!1}}function st(t){let e=s();e.voice=t,f(e)}function it(t){let e=s();e.shaping=t,f(e)}function ct(t=new Date,e=K){let n=s(),o=Math.floor(t.getTime()/1e3)+e*86400;return n.nudge_snoozed_until=o,u=o,i(n),o}function at(){let t=s();t.first_reset_at||(t.first_reset_at=new Date().toISOString(),i(t))}function ut(t){let e=s();t&&t.trim().length>0?e.user_first_name=t.trim():delete e.user_first_name,f(e)}function l(t=new Date){let e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${o}`}function M(t,e){let n=new Date(e);n.setDate(n.getDate()-V);let o=l(n);return t.filter(r=>r>=o)}function lt(t=new Date){let e=s(),n=l(t),o=M([...e.session_dates,n],t);e.session_dates=o,i(e)}function ft(t=new Date){let e=s(),n=l(t);return e.session_dates.filter(o=>o===n).length}function dt(t=new Date){let e=s(),n=new Set(e.session_dates),o=new Date(t);o.setHours(0,0,0,0);let r=new Date(o);n.has(l(r))||r.setDate(r.getDate()-1);let w=0;for(;n.has(l(r));)w+=1,r.setDate(r.getDate()-1);return w}function gt(){return s().session_dates.length}import{execFileSync as m}from"child_process";import{existsSync as p,mkdirSync as j,readFileSync as B,rmSync as W,writeFileSync as Y}from"fs";import{homedir as H,platform as g}from"os";import{join as d}from"path";var c="flowe-cli",a="clerk-token";function y(){let t=H(),e=g()==="win32"?d(t,"AppData","Roaming","flowe"):d(t,".config","flowe");return d(e,".token")}function J(){if(g()!=="darwin")return null;try{let t=m("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 G(t){if(g()!=="darwin")return!1;try{return m("security",["add-generic-password","-U","-s",c,"-a",a,"-w",t],{stdio:"ignore"}),!0}catch{return!1}}function Q(){if(g()!=="darwin")return!1;try{return m("security",["delete-generic-password","-s",c,"-a",a],{stdio:"ignore"}),!0}catch{return!1}}function Z(){try{let t=y();if(!p(t))return null;let e=B(t,"utf-8").trim();return e.length>0?e:null}catch{return null}}function q(t){let e=y(),n=d(e,"..");p(n)||j(n,{recursive:!0}),Y(e,t,{encoding:"utf-8",mode:384})}function X(){try{let t=y();p(t)&&W(t,{force:!0})}catch{}}async function h(){try{let e=(await import("keytar")).default;return e&&typeof e.getPassword=="function"?e:null}catch{return null}}async function Dt(){let t=process.env.FLOWE_AUTH_TOKEN?.trim();if(t)return t;let e=await h();if(e)try{let n=await e.getPassword(c,a);return n||null}catch{return null}return J()??Z()}async function St(t){let e=await h();if(e)try{await e.setPassword(c,a,t);return}catch{}G(t)||q(t)}async function vt(){let t=await h();if(t)try{await t.deletePassword(c,a)}catch{}Q(),X()}export{s as a,st as b,it as c,ct as d,at as e,ut as f,lt as g,ft as h,dt as i,gt as j,Dt as k,St as l,vt as m};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as i,
|
|
1
|
+
import{a as i,f as n,k as o}from"./chunk-B32B6OSK.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as y,
|
|
1
|
+
import{a as y,f as v,g as C,k as f,l as D}from"./chunk-B32B6OSK.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};
|