@iaforged/context-code 2.3.1 → 2.3.3

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 (44) hide show
  1. package/dist/src/QueryEngine.js +1 -1
  2. package/dist/src/cli/handlers/auth.js +1 -1
  3. package/dist/src/cli/handlers/modelList.js +1 -1
  4. package/dist/src/cli/structuredIO.js +1 -1
  5. package/dist/src/commands/branch/index.js +1 -1
  6. package/dist/src/commands/login/login.js +1 -1
  7. package/dist/src/commands/profile/index.js +1 -1
  8. package/dist/src/commands/profile/profile.js +1 -1
  9. package/dist/src/commands/provider/index.js +1 -1
  10. package/dist/src/commands/provider/provider.js +1 -1
  11. package/dist/src/components/ConsoleOAuthFlow.js +1 -1
  12. package/dist/src/components/LogoV2/Opus1mMergeNotice.js +1 -1
  13. package/dist/src/components/ModelPicker.js +1 -1
  14. package/dist/src/components/SessionTokenFooter.js +1 -0
  15. package/dist/src/constants/oauth.js +1 -1
  16. package/dist/src/core/providers/providerCore.js +1 -1
  17. package/dist/src/hooks/useTypeahead.js +1 -1
  18. package/dist/src/main.js +1 -1
  19. package/dist/src/screens/REPL.js +1 -1
  20. package/dist/src/services/api/openai.js +1 -1
  21. package/dist/src/services/oauth/auth-code-listener.js +1 -1
  22. package/dist/src/services/oauth/client.js +1 -1
  23. package/dist/src/services/oauth/geminiCli.js +1 -1
  24. package/dist/src/utils/auth.js +1 -1
  25. package/dist/src/utils/claudeInChrome/setup.js +1 -1
  26. package/dist/src/utils/envUtils.js +1 -1
  27. package/dist/src/utils/git.js +1 -1
  28. package/dist/src/utils/localInstaller.js +1 -1
  29. package/dist/src/utils/model/configs.js +1 -1
  30. package/dist/src/utils/model/model.js +1 -1
  31. package/dist/src/utils/model/modelAllowlist.js +1 -1
  32. package/dist/src/utils/model/modelOptions.js +1 -1
  33. package/dist/src/utils/model/providerBaseUrls.js +1 -1
  34. package/dist/src/utils/model/providerCatalog.js +1 -1
  35. package/dist/src/utils/model/providerModels.js +1 -1
  36. package/dist/src/utils/model/providerProfiles.js +1 -1
  37. package/dist/src/utils/model/providerProfilesDb.js +1 -1
  38. package/dist/src/utils/model/providers.js +1 -1
  39. package/dist/src/utils/model/validateModel.js +1 -1
  40. package/dist/src/utils/ripgrep.js +1 -1
  41. package/dist/webapp/chunk-VAB2VXFI.js +1 -1
  42. package/dist/webapp/main-MTQLKGXD.js +1 -1
  43. package/dist/webapp/ngsw.json +1 -1
  44. package/package.json +1 -1
@@ -1 +1 @@
1
- import{jsx as e,jsxs as o,Fragment as t}from"react/jsx-runtime";import r from"lodash-es/capitalize.js";import*as i from"react";import{useMemo as n,useState as l}from"react";import{useExitOnCtrlCDWithKeybindings as a}from"../hooks/useExitOnCtrlCDWithKeybindings.js";import{logEvent as s}from"../services/analytics/index.js";import{FAST_MODE_MODEL_DISPLAY as c,isFastModeAvailable as d,isFastModeCooldown as m,isFastModeEnabled as u}from"../utils/fastMode.js";import{Box as f,Text as p,useInput as h}from"../ink.js";import{useKeybindings as v}from"../keybindings/useKeybinding.js";import{useAppState as g,useSetAppState as b}from"../state/AppState.js";import{getGlobalConfig as C,saveGlobalConfig as j}from"../utils/config.js";import{convertEffortValueToLevel as x,getDefaultEffortForModel as E,modelSupportsEffort as P,modelSupportsMaxEffort as S,resolvePickerEffortPersistence as O,toPersistableEffort as M}from"../utils/effort.js";import{getDefaultMainLoopModel as k,modelDisplayString as w,parseUserSpecifiedModel as y}from"../utils/model/model.js";import{getModelOptions as L}from"../utils/model/modelOptions.js";import{getAPIProvider as V}from"../utils/model/providers.js";import{getSettingsForSource as F,updateSettingsForSource as _}from"../utils/settings/settings.js";import{ConfigurableShortcutHint as D}from"./ConfigurableShortcutHint.js";import{Select as I}from"./CustomSelect/index.js";import{Byline as A}from"./design-system/Byline.js";import{KeyboardShortcutHint as H}from"./design-system/KeyboardShortcutHint.js";import{Pane as R}from"./design-system/Pane.js";import{effortLevelToSymbol as B}from"./EffortIndicator.js";const z="__NO_PREFERENCE__",N="__MODEL_HEADER__";function writePickerState(e){j(o=>({...o,modelPickerFavorites:e.favorites,modelPickerRecent:e.recent}))}function providerLabel(e){switch(e){case"firstParty":return"Claude";case"openai":return"OpenAI";case"openrouter":return"OpenRouter";case"ollama":return"Ollama";case"ollama-cloud":return"Ollama Cloud";case"gemini-api":return"Gemini API";case"gemini-google":return"Gemini Google";case"zai":return"Z.AI";case"minimax":return"MiniMax";case"nvidia":return"NVIDIA";default:return e}}function asSelectValue(e){return null===e?z:e}function isHeaderValue(e){return e?.startsWith(N)??!1}function resolveOptionModel(e){if(e&&!isHeaderValue(e))return e===z?k():y(e)}function getDefaultEffortLevelForOption(e){const o=resolveOptionModel(e)??k(),t=E(o);return void 0!==t?x(t):"high"}function EffortLevelIndicator({effort:o}){return e(p,{color:o?"claude":"subtle",children:B(o??"low")})}export function ModelPicker({initial:j,sessionModel:E,onSelect:k,onCancel:y,isStandaloneCommand:B,showFastModeNotice:$,headerText:G,skipSettingsWrite:K,onOpenProvider:U}){const W=b(),T=a(),Z=null===j?z:j,[q,J]=l(Z),[Q,X]=l(()=>function(){const e=C();return{favorites:e.modelPickerFavorites??[],recent:e.modelPickerRecent??[]}}()),Y=g(e=>!!u()&&e.fastMode),[ee,oe]=l(!1),te=g(e=>e.effortValue),[re,ie]=l(void 0!==te?x(te):void 0),[ne,le]=l([]);i.useEffect(()=>{(async()=>{const e=V();if("openai"===e||"openrouter"===e||"ollama"===e||"ollama-cloud"===e||"gemini-api"===e||"gemini-google"===e||"zai"===e||"minimax"===e||"nvidia"===e||"deepseek"===e||"custom-openai"===e){const{getCachedProviderModels:o,fetchProviderModels:t}=await import("../utils/model/providerModels.js"),r=o(e);if(r)le(r);else{const o=await t(e);le(o)}}})()},[]);const ae=n(()=>L(Y??!1),[Y]),se=n(()=>{if(0===ne.length)return ae;const e=new Set;return[...ae,...ne].filter(o=>{const t=o.value??z;return!e.has(t)&&(e.add(t),!0)})},[ae,ne]),ce=n(()=>null===j||se.some(e=>e.value===j)?se:[...se,{value:j,label:w(j),description:"Modelo actual"}],[j,se]),de=n(()=>new Map(ce.map(e=>[asSelectValue(e.value),e])),[ce]),me=n(()=>{const e=ce.map(e=>asSelectValue(e.value)),o=new Set(e),t=Q.favorites.filter(e=>o.has(e)),r=Q.recent.filter(e=>e!==z&&o.has(e)&&!t.includes(e)),i=e.filter(e=>!t.includes(e)&&!r.includes(e)),n=[];if(t.length>0){n.push({value:`${N}:favorites`,label:"Favorites",disabled:!0});for(const e of t){const o=de.get(e);o&&n.push({value:e,label:`★ ${o.label}`,description:o.description})}}if(r.length>0){n.push({value:`${N}:recent`,label:"Recent",disabled:!0});for(const e of r){const o=de.get(e);o&&n.push({value:e,label:o.label,description:o.description})}}n.push({value:`${N}:provider`,label:providerLabel(V()),disabled:!0});for(const e of i){const o=de.get(e);o&&n.push({value:e,label:o.label,description:o.description})}return n},[de,ce,Q.favorites,Q.recent]),ue=n(()=>me.some(e=>e.value===Z&&!e.disabled)?Z:me.find(e=>!e.disabled)?.value,[me,Z]),fe=Math.min(10,me.length),pe=Math.max(0,me.length-fe),he=me.find(e=>e.value===q)?.label,ve=resolveOptionModel(q),ge=!!ve&&P(ve),be=!!ve&&S(ve),Ce=getDefaultEffortLevelForOption(q),je="max"!==re||be?re:"high",handleCycleEffort=e=>{ge&&(ie(o=>function(e,o,t){const r=t?["low","medium","high","max"]:["low","medium","high"],i=r.indexOf(e),n=-1!==i?i:r.indexOf("high");return"right"===o?r[(n+1)%r.length]:r[(n-1+r.length)%r.length]}(o??Ce,e,be)),oe(!0))};v({"modelPicker:decreaseEffort":()=>handleCycleEffort("left"),"modelPicker:increaseEffort":()=>handleCycleEffort("right")},{context:"ModelPicker"}),h((e,o)=>{const t=q;if(t&&!isHeaderValue(t)){if(o.ctrl&&"f"===e.toLowerCase()&&t!==z){const e=Q.favorites.includes(t)?Q.favorites.filter(e=>e!==t):[t,...Q.favorites].slice(0,25),o={...Q,favorites:e};return X(o),void writePickerState(o)}o.ctrl&&"a"===e.toLowerCase()&&U&&U()}});const xe=q&&!isHeaderValue(q)&&q!==z&&Q.favorites.includes(q)?"Unfavorite":"Favorite",Ee=o(f,{flexDirection:"column",children:[o(f,{marginBottom:1,flexDirection:"column",children:[e(p,{color:"remember",bold:!0,children:"Seleccionar modelo"}),e(p,{dimColor:!0,children:G??"Cambia entre modelos. Se aplica a esta sesion y a futuras sesiones de Context Code. Para otros nombres de modelo, usa --model."}),E&&o(p,{dimColor:!0,children:["Usando ",w(E)," en esta sesion (definido por el modo plan). Al elegir otro modelo se deshace este ajuste."]})]}),o(f,{flexDirection:"column",marginBottom:1,children:[e(I,{defaultValue:Z,defaultFocusValue:ue,options:me,onChange:e=>{if(isHeaderValue(e))return;if(s("tengu_model_command_menu_effort",{effort:re}),!K){const o=O(re,getDefaultEffortLevelForOption(e),F("userSettings")?.effortLevel,ee),t=M(o);void 0!==t&&_("userSettings",{effortLevel:t}),W(e=>({...e,effortValue:o}))}const o=ee&&ve&&P(ve)?re:void 0,t=[e,...Q.recent.filter(o=>o!==e)].slice(0,15),r={...Q,recent:t};X(r),writePickerState(r),k(function(e){return e===z?null:e}(e),o)},onFocus:e=>{J(e),ee||void 0!==te||isHeaderValue(e)||ie(getDefaultEffortLevelForOption(e))},onCancel:y??(()=>{}),visibleOptionCount:fe,hideIndexes:!0,layout:"compact-vertical"}),pe>0&&e(f,{paddingLeft:3,children:o(p,{dimColor:!0,children:["y ",pe," más…"]})})]}),e(f,{marginBottom:1,flexDirection:"column",children:o(p,ge?{dimColor:!0,children:[e(EffortLevelIndicator,{effort:je})," ",r("low"===je?"bajo":"medium"===je?"medio":"high"===je?"alto":"máximo")," ","esfuerzo",je===Ce?" (predeterminado)":""," ",e(p,{color:"subtle",children:"← → para ajustar"})]}:{color:"subtle",children:[e(EffortLevelIndicator,{effort:void 0})," Esfuerzo no soportado",he?` para ${String(he)}`:""]})}),u()?$?e(f,{marginBottom:1,children:o(p,{dimColor:!0,children:["El modo rápido está ",e(p,{bold:!0,children:"ACTIVADO"})," y disponible solo con"," ",c," (/fast). Cambiar a otros modelos desactivará el modo rápido."]})}):d()&&!m()?e(f,{marginBottom:1,children:o(p,{dimColor:!0,children:["Usa ",e(p,{bold:!0,children:"/fast"})," para activar el modo rápido (solo"," ",c,")."]})}):null:null,B&&e(p,{dimColor:!0,italic:!0,children:T.pending?o(t,{children:["Presiona ",T.keyName," de nuevo para salir"]}):o(A,{children:[e(H,{shortcut:"Enter",action:"confirmar"}),e(H,{shortcut:"Ctrl+F",action:xe}),e(H,{shortcut:"Ctrl+A",action:"Provider"}),e(D,{action:"select:cancel",context:"Seleccionar",fallback:"Esc",description:"salir"})]})})]});return B?e(R,{color:"permission",children:Ee}):Ee}
1
+ import{jsx as e,jsxs as o,Fragment as t}from"react/jsx-runtime";import r from"lodash-es/capitalize.js";import*as i from"react";import{useMemo as n,useState as l}from"react";import{useExitOnCtrlCDWithKeybindings as s}from"../hooks/useExitOnCtrlCDWithKeybindings.js";import{logEvent as a}from"../services/analytics/index.js";import{FAST_MODE_MODEL_DISPLAY as c,isFastModeAvailable as d,isFastModeCooldown as u,isFastModeEnabled as f}from"../utils/fastMode.js";import{Box as m,Text as p,useInput as h}from"../ink.js";import{useKeybindings as v}from"../keybindings/useKeybinding.js";import{useAppState as g,useSetAppState as b}from"../state/AppState.js";import{getGlobalConfig as C,saveGlobalConfig as j}from"../utils/config.js";import{convertEffortValueToLevel as x,getDefaultEffortForModel as E,modelSupportsEffort as S,modelSupportsMaxEffort as O,resolvePickerEffortPersistence as P,toPersistableEffort as k}from"../utils/effort.js";import{getDefaultMainLoopModel as M,modelDisplayString as w,parseUserSpecifiedModel as y}from"../utils/model/model.js";import{getModelOptions as L}from"../utils/model/modelOptions.js";import{getAPIProvider as V,isOpenAICompatibleProvider as D}from"../utils/model/providers.js";import{getSettingsForSource as F,updateSettingsForSource as _}from"../utils/settings/settings.js";import{ConfigurableShortcutHint as A}from"./ConfigurableShortcutHint.js";import{Select as I}from"./CustomSelect/index.js";import{Byline as H}from"./design-system/Byline.js";import{KeyboardShortcutHint as R}from"./design-system/KeyboardShortcutHint.js";import{Pane as z}from"./design-system/Pane.js";import{effortLevelToSymbol as B}from"./EffortIndicator.js";const N="__NO_PREFERENCE__",$="__MODEL_HEADER__";function writePickerState(e){j(o=>({...o,modelPickerFavorites:e.favorites,modelPickerRecent:e.recent}))}function providerLabel(e){switch(e){case"firstParty":return"Claude";case"openai":return"OpenAI";case"openrouter":return"OpenRouter";case"ollama":return"Ollama";case"ollama-cloud":return"Ollama Cloud";case"gemini-api":return"Gemini API";case"gemini-google":return"Gemini Google";case"zai":return"Z.AI";case"minimax":return"MiniMax";case"nvidia":return"NVIDIA";case"deepseek":return"DeepSeek";case"custom-openai":return"OpenAI personalizado";case"custom-anthropic":return"Anthropic personalizado";default:return e}}function asSelectValue(e){return null===e?N:e}function isHeaderValue(e){return e?.startsWith($)??!1}function resolveOptionModel(e){if(e&&!isHeaderValue(e))return e===N?M():y(e)}function getDefaultEffortLevelForOption(e){const o=resolveOptionModel(e)??M(),t=E(o);return void 0!==t?x(t):"high"}function EffortLevelIndicator({effort:o}){return e(p,{color:o?"claude":"subtle",children:B(o??"low")})}export function ModelPicker({initial:j,sessionModel:E,onSelect:M,onCancel:y,isStandaloneCommand:B,showFastModeNotice:G,headerText:K,skipSettingsWrite:W,onOpenProvider:T}){const U=b(),Q=s(),Z=null===j?N:j,[q,J]=l(Z),[X,Y]=l(()=>function(){const e=C();return{favorites:e.modelPickerFavorites??[],recent:e.modelPickerRecent??[]}}()),ee=g(e=>!!f()&&e.fastMode),[oe,te]=l(!1),re=g(e=>e.effortValue),[ie,ne]=l(void 0!==re?x(re):void 0),[le,se]=l([]);i.useEffect(()=>{(async()=>{const e=V();if(D(e)){const{getCachedProviderModels:o,fetchProviderModels:t}=await import("../utils/model/providerModels.js"),r=o(e);if(r)se(r);else{const o=await t(e);se(o)}}})()},[]);const ae=n(()=>L(ee??!1),[ee]),ce=n(()=>{if(0===le.length)return ae;const e=new Set;return[...ae,...le].filter(o=>{const t=o.value??N;return!e.has(t)&&(e.add(t),!0)})},[ae,le]),de=n(()=>null===j||ce.some(e=>e.value===j)?ce:[...ce,{value:j,label:w(j),description:"Modelo actual"}],[j,ce]),ue=n(()=>new Map(de.map(e=>[asSelectValue(e.value),e])),[de]),fe=n(()=>{const e=de.map(e=>asSelectValue(e.value)),o=new Set(e),t=X.favorites.filter(e=>o.has(e)),r=X.recent.filter(e=>e!==N&&o.has(e)&&!t.includes(e)),i=e.filter(e=>!t.includes(e)&&!r.includes(e)),n=[];if(t.length>0){n.push({value:`${$}:favorites`,label:"Favoritos",disabled:!0});for(const e of t){const o=ue.get(e);o&&n.push({value:e,label:`★ ${o.label}`,description:o.description})}}if(r.length>0){n.push({value:`${$}:recent`,label:"Recientes",disabled:!0});for(const e of r){const o=ue.get(e);o&&n.push({value:e,label:o.label,description:o.description})}}n.push({value:`${$}:provider`,label:providerLabel(V()),disabled:!0});for(const e of i){const o=ue.get(e);o&&n.push({value:e,label:o.label,description:o.description})}return n},[ue,de,X.favorites,X.recent]),me=n(()=>fe.some(e=>e.value===Z&&!e.disabled)?Z:fe.find(e=>!e.disabled)?.value,[fe,Z]),pe=Math.min(10,fe.length),he=Math.max(0,fe.length-pe),ve=fe.find(e=>e.value===q)?.label,ge=resolveOptionModel(q),be=!!ge&&S(ge),Ce=!!ge&&O(ge),je=getDefaultEffortLevelForOption(q),xe="max"!==ie||Ce?ie:"high",handleCycleEffort=e=>{be&&(ne(o=>function(e,o,t){const r=t?["low","medium","high","max"]:["low","medium","high"],i=r.indexOf(e),n=-1!==i?i:r.indexOf("high");return"right"===o?r[(n+1)%r.length]:r[(n-1+r.length)%r.length]}(o??je,e,Ce)),te(!0))};v({"modelPicker:decreaseEffort":()=>handleCycleEffort("left"),"modelPicker:increaseEffort":()=>handleCycleEffort("right")},{context:"ModelPicker"}),h((e,o)=>{const t=q;if(t&&!isHeaderValue(t)){if(o.ctrl&&"f"===e.toLowerCase()&&t!==N){const e=X.favorites.includes(t)?X.favorites.filter(e=>e!==t):[t,...X.favorites].slice(0,25),o={...X,favorites:e};return Y(o),void writePickerState(o)}o.ctrl&&"a"===e.toLowerCase()&&T&&T()}});const Ee=q&&!isHeaderValue(q)&&q!==N&&X.favorites.includes(q)?"Quitar favorito":"Favorito",Se=o(m,{flexDirection:"column",children:[o(m,{marginBottom:1,flexDirection:"column",children:[e(p,{color:"remember",bold:!0,children:"Seleccionar modelo"}),e(p,{dimColor:!0,children:K??"Cambia entre modelos. Se aplica a esta sesion y a futuras sesiones de Context Code. Para otros nombres de modelo, usa --model."}),E&&o(p,{dimColor:!0,children:["Usando ",w(E)," en esta sesion (definido por el modo plan). Al elegir otro modelo se deshace este ajuste."]})]}),o(m,{flexDirection:"column",marginBottom:1,children:[e(I,{defaultValue:Z,defaultFocusValue:me,options:fe,onChange:e=>{if(isHeaderValue(e))return;if(a("tengu_model_command_menu_effort",{effort:ie}),!W){const o=P(ie,getDefaultEffortLevelForOption(e),F("userSettings")?.effortLevel,oe),t=k(o);void 0!==t&&_("userSettings",{effortLevel:t}),U(e=>({...e,effortValue:o}))}const o=oe&&ge&&S(ge)?ie:void 0,t=[e,...X.recent.filter(o=>o!==e)].slice(0,15),r={...X,recent:t};Y(r),writePickerState(r),M(function(e){return e===N?null:e}(e),o)},onFocus:e=>{J(e),oe||void 0!==re||isHeaderValue(e)||ne(getDefaultEffortLevelForOption(e))},onCancel:y??(()=>{}),visibleOptionCount:pe,hideIndexes:!0,layout:"compact-vertical"}),he>0&&e(m,{paddingLeft:3,children:o(p,{dimColor:!0,children:["y ",he," más…"]})})]}),e(m,{marginBottom:1,flexDirection:"column",children:o(p,be?{dimColor:!0,children:[e(EffortLevelIndicator,{effort:xe})," ",r("low"===xe?"bajo":"medium"===xe?"medio":"high"===xe?"alto":"máximo")," ","esfuerzo",xe===je?" (predeterminado)":""," ",e(p,{color:"subtle",children:"← → para ajustar"})]}:{color:"subtle",children:[e(EffortLevelIndicator,{effort:void 0})," Esfuerzo no soportado",ve?` para ${String(ve)}`:""]})}),f()?G?e(m,{marginBottom:1,children:o(p,{dimColor:!0,children:["El modo rápido está ",e(p,{bold:!0,children:"ACTIVADO"})," y disponible solo con"," ",c," (/fast). Cambiar a otros modelos desactivará el modo rápido."]})}):d()&&!u()?e(m,{marginBottom:1,children:o(p,{dimColor:!0,children:["Usa ",e(p,{bold:!0,children:"/fast"})," para activar el modo rápido (solo"," ",c,")."]})}):null:null,B&&e(p,{dimColor:!0,italic:!0,children:Q.pending?o(t,{children:["Presiona ",Q.keyName," de nuevo para salir"]}):o(H,{children:[e(R,{shortcut:"Enter",action:"confirmar"}),e(R,{shortcut:"Ctrl+F",action:Ee}),e(R,{shortcut:"Ctrl+A",action:"Proveedor"}),e(A,{action:"select:cancel",context:"Seleccionar",fallback:"Esc",description:"salir"})]})})]});return B?e(z,{color:"permission",children:Se}):Se}
@@ -0,0 +1 @@
1
+ import{jsxs as o,jsx as r}from"react/jsx-runtime";import{getTotalCost as e,getTotalInputTokens as t,getTotalOutputTokens as i}from"../cost-tracker.js";import{useMainLoopModel as n}from"../hooks/useMainLoopModel.js";import{Box as s,Text as m}from"../ink.js";import{getAPIProvider as l}from"../utils/model/providers.js";import{getCurrentUsage as d}from"../utils/tokens.js";function formatNumber(o){return o>=1e6?`${(o/1e6).toFixed(2)}M`:o>=1e3?`${(o/1e3).toFixed(1)}k`:String(o)}export const SessionTokenFooter=({messages:c})=>{const a=l(),u=n(),f=t(),p=i(),h=d(c),k=h?.input_tokens??0,j=h?.output_tokens??0,x=e(),b="firstParty"===a||"openai"===a||"bedrock"===a||"vertex"===a||"foundry"===a;return r(s,{paddingX:1,children:o(m,{dimColor:!0,children:[a," · ",u||"sin modelo"," ",o(m,{color:"cyan",children:["↑ ",formatNumber(f)]})," / ",o(m,{color:"green",children:["↓ ",formatNumber(p)]})," tokens en esta sesion",h&&o(m,{dimColor:!0,children:[" · ultima respuesta: ",r(m,{color:"cyan",children:formatNumber(k)})," / ",r(m,{color:"green",children:formatNumber(j)})]}),x>0&&o(m,{dimColor:!0,children:[" · ",o(m,{color:"yellow",children:["$",x.toFixed(4)]}),b?"":" (estimado)"]})]})})};
@@ -1 +1 @@
1
- import{isEnvTruthy as e}from"../utils/envUtils.js";function getOauthConfigType(){if("ant"===process.env.USER_TYPE){if(e(process.env.USE_LOCAL_OAUTH))return"local";if(e(process.env.USE_STAGING_OAUTH))return"staging"}return"prod"}export function fileSuffixForOauthConfig(){if(process.env.CONTEXT_CODE_CUSTOM_OAUTH_URL||process.env.CLAUDE_CODE_CUSTOM_OAUTH_URL)return"-custom-oauth";switch(getOauthConfigType()){case"local":return"-local-oauth";case"staging":return"-staging-oauth";case"prod":return""}}function parseSpaceSeparatedList(e){return e?.split(/\s+/).filter(Boolean)??[]}const t="/auth/callback",_=`http://localhost:1455${t}`,o=["openid","profile","email","offline_access"];export const CLAUDE_AI_INFERENCE_SCOPE="user:inference";export const CLAUDE_AI_PROFILE_SCOPE="user:profile";export const OAUTH_BETA_HEADER="oauth-2025-04-20";export const CONSOLE_OAUTH_SCOPES=["org:create_api_key","user:profile"];export const CLAUDE_AI_OAUTH_SCOPES=["user:profile","user:inference","user:sessions:claude_code","user:mcp_servers","user:file_upload"];export const ALL_OAUTH_SCOPES=Array.from(new Set([...CONSOLE_OAUTH_SCOPES,...CLAUDE_AI_OAUTH_SCOPES]));const a={BASE_API_URL:"https://api.anthropic.com",CONSOLE_AUTHORIZE_URL:"https://platform.claude.com/oauth/authorize",CLAUDE_AI_AUTHORIZE_URL:"https://claude.com/cai/oauth/authorize",CLAUDE_AI_ORIGIN:"https://claude.ai",TOKEN_URL:"https://platform.claude.com/v1/oauth/token",API_KEY_URL:"https://api.anthropic.com/api/oauth/claude_cli/create_api_key",ROLES_URL:"https://api.anthropic.com/api/oauth/claude_cli/roles",CONSOLE_SUCCESS_URL:"https://platform.claude.com/buy_credits?returnUrl=/oauth/code/success%3Fapp%3Dclaude-code",CLAUDEAI_SUCCESS_URL:"https://platform.claude.com/oauth/code/success?app=claude-code",MANUAL_REDIRECT_URL:"https://platform.claude.com/oauth/code/callback",CLIENT_ID:"9d1c250a-e61b-44d9-88ed-5944d1962f5e",OAUTH_FILE_SUFFIX:"",MCP_PROXY_URL:"https://mcp-proxy.anthropic.com",MCP_PROXY_PATH:"/v1/mcp/{server_id}"};export const MCP_CLIENT_METADATA_URL="https://claude.ai/oauth/claude-code-client-metadata";const c="ant"===process.env.USER_TYPE?{BASE_API_URL:"https://api-staging.anthropic.com",CONSOLE_AUTHORIZE_URL:"https://platform.staging.ant.dev/oauth/authorize",CLAUDE_AI_AUTHORIZE_URL:"https://claude-ai.staging.ant.dev/oauth/authorize",CLAUDE_AI_ORIGIN:"https://claude-ai.staging.ant.dev",TOKEN_URL:"https://platform.staging.ant.dev/v1/oauth/token",API_KEY_URL:"https://api-staging.anthropic.com/api/oauth/claude_cli/create_api_key",ROLES_URL:"https://api-staging.anthropic.com/api/oauth/claude_cli/roles",CONSOLE_SUCCESS_URL:"https://platform.staging.ant.dev/buy_credits?returnUrl=/oauth/code/success%3Fapp%3Dclaude-code",CLAUDEAI_SUCCESS_URL:"https://platform.staging.ant.dev/oauth/code/success?app=claude-code",MANUAL_REDIRECT_URL:"https://platform.staging.ant.dev/oauth/code/callback",CLIENT_ID:"22422756-60c9-4084-8eb7-27705fd5cf9a",OAUTH_FILE_SUFFIX:"-staging-oauth",MCP_PROXY_URL:"https://mcp-proxy-staging.anthropic.com",MCP_PROXY_PATH:"/v1/mcp/{server_id}"}:void 0;const s=["https://beacon.claude-ai.staging.ant.dev","https://claude.fedstart.com","https://claude-staging.fedstart.com"];export function getOauthConfig(){let e=(()=>{switch(getOauthConfigType()){case"local":return function(){const e=(process.env.CONTEXT_LOCAL_OAUTH_API_BASE??process.env.CLAUDE_LOCAL_OAUTH_API_BASE)?.replace(/\/$/,"")??"http://localhost:8000",t=(process.env.CONTEXT_LOCAL_OAUTH_APPS_BASE??process.env.CLAUDE_LOCAL_OAUTH_APPS_BASE)?.replace(/\/$/,"")??"http://localhost:4000",_=(process.env.CONTEXT_LOCAL_OAUTH_CONSOLE_BASE??process.env.CLAUDE_LOCAL_OAUTH_CONSOLE_BASE)?.replace(/\/$/,"")??"http://localhost:3000";return{BASE_API_URL:e,CONSOLE_AUTHORIZE_URL:`${_}/oauth/authorize`,CLAUDE_AI_AUTHORIZE_URL:`${t}/oauth/authorize`,CLAUDE_AI_ORIGIN:t,TOKEN_URL:`${e}/v1/oauth/token`,API_KEY_URL:`${e}/api/oauth/claude_cli/create_api_key`,ROLES_URL:`${e}/api/oauth/claude_cli/roles`,CONSOLE_SUCCESS_URL:`${_}/buy_credits?returnUrl=/oauth/code/success%3Fapp%3Dclaude-code`,CLAUDEAI_SUCCESS_URL:`${_}/oauth/code/success?app=claude-code`,MANUAL_REDIRECT_URL:`${_}/oauth/code/callback`,CLIENT_ID:"22422756-60c9-4084-8eb7-27705fd5cf9a",OAUTH_FILE_SUFFIX:"-local-oauth",MCP_PROXY_URL:"http://localhost:8205",MCP_PROXY_PATH:"/v1/toolbox/shttp/mcp/{server_id}"}}();case"staging":return c??a;case"prod":return a}})();const t=process.env.CONTEXT_CODE_CUSTOM_OAUTH_URL??process.env.CLAUDE_CODE_CUSTOM_OAUTH_URL;if(t){const _=t.replace(/\/$/,"");if(!s.includes(_)){const e=void 0!==process.env.CONTEXT_CODE_CUSTOM_OAUTH_URL?"CONTEXT_CODE_CUSTOM_OAUTH_URL":"CLAUDE_CODE_CUSTOM_OAUTH_URL";throw new Error(`${e} is not an approved endpoint.`)}e={...e,BASE_API_URL:_,CONSOLE_AUTHORIZE_URL:`${_}/oauth/authorize`,CLAUDE_AI_AUTHORIZE_URL:`${_}/oauth/authorize`,CLAUDE_AI_ORIGIN:_,TOKEN_URL:`${_}/v1/oauth/token`,API_KEY_URL:`${_}/api/oauth/claude_cli/create_api_key`,ROLES_URL:`${_}/api/oauth/claude_cli/roles`,CONSOLE_SUCCESS_URL:`${_}/oauth/code/success?app=claude-code`,CLAUDEAI_SUCCESS_URL:`${_}/oauth/code/success?app=claude-code`,MANUAL_REDIRECT_URL:`${_}/oauth/code/callback`,OAUTH_FILE_SUFFIX:"-custom-oauth"}}const _=process.env.CONTEXT_CODE_OAUTH_CLIENT_ID??process.env.CLAUDE_CODE_OAUTH_CLIENT_ID;return _&&(e={...e,CLIENT_ID:_}),e}export function getOpenAIOAuthConfig(){const e=process.env.OPENAI_OAUTH_BASE_URL?.replace(/\/$/,"")??process.env.OPENAI_OAUTH_ENDPOINT_BASE?.replace(/\/$/,"")??"https://auth.openai.com";return{AUTHORIZE_URL:process.env.OPENAI_OAUTH_AUTHORIZE_URL??`${e}/oauth/authorize`,TOKEN_URL:process.env.OPENAI_OAUTH_TOKEN_URL??`${e}/oauth/token`,CLIENT_ID:process.env.OPENAI_OAUTH_CLIENT_ID??"app_EMoamEEZ73f0CkXaXp7hrann",MANUAL_REDIRECT_URL:process.env.OPENAI_OAUTH_MANUAL_REDIRECT_URL??process.env.OPENAI_OAUTH_REDIRECT_URL??_,LOCAL_REDIRECT_URL:process.env.OPENAI_OAUTH_LOCAL_REDIRECT_URL??_,CALLBACK_PATH:process.env.OPENAI_OAUTH_CALLBACK_PATH??t,CALLBACK_PORT:parseInt(process.env.OPENAI_OAUTH_CALLBACK_PORT||String(1455),10),SUCCESS_URL:process.env.OPENAI_OAUTH_SUCCESS_URL??(e?`${e}/oauth/code/success?app=codex`:void 0),FILE_SUFFIX:"-openai-oauth",BASE_API_URL:e,PROFILE_URL:process.env.OPENAI_OAUTH_PROFILE_URL??(e?`${e}/api/oauth/profile`:void 0),SCOPES:parseSpaceSeparatedList(process.env.OPENAI_OAUTH_SCOPES).length>0?parseSpaceSeparatedList(process.env.OPENAI_OAUTH_SCOPES):[...o]}}
1
+ import{isEnvTruthy as e}from"../utils/envUtils.js";function getOauthConfigType(){if("ant"===process.env.USER_TYPE){if(e(process.env.USE_LOCAL_OAUTH))return"local";if(e(process.env.USE_STAGING_OAUTH))return"staging"}return"prod"}export function fileSuffixForOauthConfig(){if(process.env.CONTEXT_CODE_CUSTOM_OAUTH_URL||process.env.CLAUDE_CODE_CUSTOM_OAUTH_URL)return"-custom-oauth";switch(getOauthConfigType()){case"local":return"-local-oauth";case"staging":return"-staging-oauth";case"prod":return""}}function parseSpaceSeparatedList(e){return e?.split(/\s+/).filter(Boolean)??[]}export function getOpenAIOriginator(){return process.env.OPENAI_OAUTH_ORIGINATOR?.trim()||"codex_cli_rs"}const t="/auth/callback",_=`http://localhost:1455${t}`,o=["openid","profile","email","offline_access"];export const CLAUDE_AI_INFERENCE_SCOPE="user:inference";export const CLAUDE_AI_PROFILE_SCOPE="user:profile";export const OAUTH_BETA_HEADER="oauth-2025-04-20";export const CONSOLE_OAUTH_SCOPES=["org:create_api_key","user:profile"];export const CLAUDE_AI_OAUTH_SCOPES=["user:profile","user:inference","user:sessions:claude_code","user:mcp_servers","user:file_upload"];export const ALL_OAUTH_SCOPES=Array.from(new Set([...CONSOLE_OAUTH_SCOPES,...CLAUDE_AI_OAUTH_SCOPES]));const a={BASE_API_URL:"https://api.anthropic.com",CONSOLE_AUTHORIZE_URL:"https://platform.claude.com/oauth/authorize",CLAUDE_AI_AUTHORIZE_URL:"https://claude.com/cai/oauth/authorize",CLAUDE_AI_ORIGIN:"https://claude.ai",TOKEN_URL:"https://platform.claude.com/v1/oauth/token",API_KEY_URL:"https://api.anthropic.com/api/oauth/claude_cli/create_api_key",ROLES_URL:"https://api.anthropic.com/api/oauth/claude_cli/roles",CONSOLE_SUCCESS_URL:"https://platform.claude.com/buy_credits?returnUrl=/oauth/code/success%3Fapp%3Dclaude-code",CLAUDEAI_SUCCESS_URL:"https://platform.claude.com/oauth/code/success?app=claude-code",MANUAL_REDIRECT_URL:"https://platform.claude.com/oauth/code/callback",CLIENT_ID:"9d1c250a-e61b-44d9-88ed-5944d1962f5e",OAUTH_FILE_SUFFIX:"",MCP_PROXY_URL:"https://mcp-proxy.anthropic.com",MCP_PROXY_PATH:"/v1/mcp/{server_id}"};export const MCP_CLIENT_METADATA_URL="https://claude.ai/oauth/claude-code-client-metadata";const c="ant"===process.env.USER_TYPE?{BASE_API_URL:"https://api-staging.anthropic.com",CONSOLE_AUTHORIZE_URL:"https://platform.staging.ant.dev/oauth/authorize",CLAUDE_AI_AUTHORIZE_URL:"https://claude-ai.staging.ant.dev/oauth/authorize",CLAUDE_AI_ORIGIN:"https://claude-ai.staging.ant.dev",TOKEN_URL:"https://platform.staging.ant.dev/v1/oauth/token",API_KEY_URL:"https://api-staging.anthropic.com/api/oauth/claude_cli/create_api_key",ROLES_URL:"https://api-staging.anthropic.com/api/oauth/claude_cli/roles",CONSOLE_SUCCESS_URL:"https://platform.staging.ant.dev/buy_credits?returnUrl=/oauth/code/success%3Fapp%3Dclaude-code",CLAUDEAI_SUCCESS_URL:"https://platform.staging.ant.dev/oauth/code/success?app=claude-code",MANUAL_REDIRECT_URL:"https://platform.staging.ant.dev/oauth/code/callback",CLIENT_ID:"22422756-60c9-4084-8eb7-27705fd5cf9a",OAUTH_FILE_SUFFIX:"-staging-oauth",MCP_PROXY_URL:"https://mcp-proxy-staging.anthropic.com",MCP_PROXY_PATH:"/v1/mcp/{server_id}"}:void 0;const s=["https://beacon.claude-ai.staging.ant.dev","https://claude.fedstart.com","https://claude-staging.fedstart.com"];export function getOauthConfig(){let e=(()=>{switch(getOauthConfigType()){case"local":return function(){const e=(process.env.CONTEXT_LOCAL_OAUTH_API_BASE??process.env.CLAUDE_LOCAL_OAUTH_API_BASE)?.replace(/\/$/,"")??"http://localhost:8000",t=(process.env.CONTEXT_LOCAL_OAUTH_APPS_BASE??process.env.CLAUDE_LOCAL_OAUTH_APPS_BASE)?.replace(/\/$/,"")??"http://localhost:4000",_=(process.env.CONTEXT_LOCAL_OAUTH_CONSOLE_BASE??process.env.CLAUDE_LOCAL_OAUTH_CONSOLE_BASE)?.replace(/\/$/,"")??"http://localhost:3000";return{BASE_API_URL:e,CONSOLE_AUTHORIZE_URL:`${_}/oauth/authorize`,CLAUDE_AI_AUTHORIZE_URL:`${t}/oauth/authorize`,CLAUDE_AI_ORIGIN:t,TOKEN_URL:`${e}/v1/oauth/token`,API_KEY_URL:`${e}/api/oauth/claude_cli/create_api_key`,ROLES_URL:`${e}/api/oauth/claude_cli/roles`,CONSOLE_SUCCESS_URL:`${_}/buy_credits?returnUrl=/oauth/code/success%3Fapp%3Dclaude-code`,CLAUDEAI_SUCCESS_URL:`${_}/oauth/code/success?app=claude-code`,MANUAL_REDIRECT_URL:`${_}/oauth/code/callback`,CLIENT_ID:"22422756-60c9-4084-8eb7-27705fd5cf9a",OAUTH_FILE_SUFFIX:"-local-oauth",MCP_PROXY_URL:"http://localhost:8205",MCP_PROXY_PATH:"/v1/toolbox/shttp/mcp/{server_id}"}}();case"staging":return c??a;case"prod":return a}})();const t=process.env.CONTEXT_CODE_CUSTOM_OAUTH_URL??process.env.CLAUDE_CODE_CUSTOM_OAUTH_URL;if(t){const _=t.replace(/\/$/,"");if(!s.includes(_)){const e=void 0!==process.env.CONTEXT_CODE_CUSTOM_OAUTH_URL?"CONTEXT_CODE_CUSTOM_OAUTH_URL":"CLAUDE_CODE_CUSTOM_OAUTH_URL";throw new Error(`${e} is not an approved endpoint.`)}e={...e,BASE_API_URL:_,CONSOLE_AUTHORIZE_URL:`${_}/oauth/authorize`,CLAUDE_AI_AUTHORIZE_URL:`${_}/oauth/authorize`,CLAUDE_AI_ORIGIN:_,TOKEN_URL:`${_}/v1/oauth/token`,API_KEY_URL:`${_}/api/oauth/claude_cli/create_api_key`,ROLES_URL:`${_}/api/oauth/claude_cli/roles`,CONSOLE_SUCCESS_URL:`${_}/oauth/code/success?app=claude-code`,CLAUDEAI_SUCCESS_URL:`${_}/oauth/code/success?app=claude-code`,MANUAL_REDIRECT_URL:`${_}/oauth/code/callback`,OAUTH_FILE_SUFFIX:"-custom-oauth"}}const _=process.env.CONTEXT_CODE_OAUTH_CLIENT_ID??process.env.CLAUDE_CODE_OAUTH_CLIENT_ID;return _&&(e={...e,CLIENT_ID:_}),e}export function getOpenAIOAuthConfig(){const e=process.env.OPENAI_OAUTH_BASE_URL?.replace(/\/$/,"")??process.env.OPENAI_OAUTH_ENDPOINT_BASE?.replace(/\/$/,"")??"https://auth.openai.com";return{AUTHORIZE_URL:process.env.OPENAI_OAUTH_AUTHORIZE_URL??`${e}/oauth/authorize`,TOKEN_URL:process.env.OPENAI_OAUTH_TOKEN_URL??`${e}/oauth/token`,CLIENT_ID:process.env.OPENAI_OAUTH_CLIENT_ID??"app_EMoamEEZ73f0CkXaXp7hrann",MANUAL_REDIRECT_URL:process.env.OPENAI_OAUTH_MANUAL_REDIRECT_URL??process.env.OPENAI_OAUTH_REDIRECT_URL??_,LOCAL_REDIRECT_URL:process.env.OPENAI_OAUTH_LOCAL_REDIRECT_URL??_,CALLBACK_PATH:process.env.OPENAI_OAUTH_CALLBACK_PATH??t,CALLBACK_PORT:parseInt(process.env.OPENAI_OAUTH_CALLBACK_PORT||String(1455),10),SUCCESS_URL:process.env.OPENAI_OAUTH_SUCCESS_URL??(e?`${e}/oauth/code/success?app=codex`:void 0),FILE_SUFFIX:"-openai-oauth",BASE_API_URL:e,PROFILE_URL:process.env.OPENAI_OAUTH_PROFILE_URL??(e?`${e}/api/oauth/profile`:void 0),SCOPES:parseSpaceSeparatedList(process.env.OPENAI_OAUTH_SCOPES).length>0?parseSpaceSeparatedList(process.env.OPENAI_OAUTH_SCOPES):[...o]}}
@@ -1 +1 @@
1
- import{getVisibleProvider as e,VISIBLE_PROVIDERS as r}from"../../utils/model/providerCatalog.js";import{getActiveProviderProfile as i,getLastUsedProviderProfile as o,isProfiledProvider as t,listProviderProfiles as a,setActiveProfileForProvider as n}from"../../utils/model/providerProfiles.js";import{switchProviderPreference as l}from"../../utils/model/providerSwitch.js";import{hasStoredProviderApiKey as d,hasStoredProviderOAuthTokens as u}from"../../utils/auth.js";export function isCoreProviderEnabled(){return"0"!==process.env.CORE_PROVIDER_ENABLED}export function listCoreProviders(){return r.map(e=>({id:e.id,label:e.label,implemented:e.implemented}))}export function normalizeCoreProviderInput(e){if(e)switch(e.trim().toLowerCase()){case"z.ai":case"z-ai":return"zai";case"open-router":return"openrouter";case"ollama-cloud":case"ollama_cloud":case"ollamacloud":return"ollama-cloud";case"gemini":case"gemini-api-key":case"google-ai":case"google-ai-studio":return"gemini-api";case"gemini-google":case"google":case"google-oauth":return"gemini-google";default:return e.trim().toLowerCase()}}export function getCoreProviderLabel(r){return e(r).label}export function listCoreProviderProfiles(){const e=a(),r=i(),o=e.reduce((e,i)=>{const o=i.provider;return e[o]||(e[o]=[]),e[o].push({id:i.id,name:i.name,provider:o,baseUrl:i.baseUrl,isActive:i.id===r?.id,isAuthenticated:isProviderProfileAuthenticated(o,i.id)}),e},{});return{activeProfile:r?{id:r.id,name:r.name,provider:r.provider,baseUrl:r.baseUrl}:null,providers:o}}export function getCoreCurrentProviderProfile(){const e=i();return e?{activeProfile:{id:e.id,name:e.name,provider:e.provider,baseUrl:e.baseUrl}}:{activeProfile:null}}export function setCoreActiveProfile(e,r){t(e)&&n(e,r)}export function isCoreSelectedProfileReady(e,r){if(!r||!t(e))return!0;const i=o(e);return!!i&&isProviderProfileAuthenticated(e,i.id)}export function switchCoreProvider(e){const r=l({currentModel:e.currentModel,currentProvider:e.currentProvider,targetProvider:e.targetProvider,targetProfileName:e.targetProfileName}),i=t(e.targetProvider)?o(e.targetProvider):null;return{restoredModel:r,activeProfileName:i?.name}}function isProviderProfileAuthenticated(e,r){return"claude"===e?u("claude",r):"openai"===e?u("openai",r):"openrouter"!==e&&"gemini-api"!==e&&"zai"!==e&&"minimax"!==e&&"nvidia"!==e||d(e,r)}
1
+ import{getVisibleProvider as e,VISIBLE_PROVIDERS as r}from"../../utils/model/providerCatalog.js";import{getActiveProviderProfile as i,getLastUsedProviderProfile as o,isProfiledProvider as t,listProviderProfiles as a,setActiveProfileForProvider as n}from"../../utils/model/providerProfiles.js";import{switchProviderPreference as l}from"../../utils/model/providerSwitch.js";import{hasStoredProviderApiKey as d,hasStoredProviderOAuthTokens as u}from"../../utils/auth.js";export function isCoreProviderEnabled(){return"0"!==process.env.CORE_PROVIDER_ENABLED}export function listCoreProviders(){return r.map(e=>({id:e.id,label:e.label,implemented:e.implemented}))}export function normalizeCoreProviderInput(e){if(e)switch(e.trim().toLowerCase()){case"z.ai":case"z-ai":return"zai";case"open-router":return"openrouter";case"ollama-cloud":case"ollama_cloud":case"ollamacloud":return"ollama-cloud";case"gemini":case"gemini-api-key":case"google-ai":case"google-ai-studio":return"gemini-api";case"gemini-google":case"google":case"google-oauth":return"gemini-google";default:return e.trim().toLowerCase()}}export function getCoreProviderLabel(r){return e(r).label}export function listCoreProviderProfiles(){const e=a(),r=i(),o=e.reduce((e,i)=>{const o=i.provider;return e[o]||(e[o]=[]),e[o].push({id:i.id,name:i.name,provider:o,baseUrl:i.baseUrl,isActive:i.id===r?.id,isAuthenticated:isProviderProfileAuthenticated(o,i.id)}),e},{});return{activeProfile:r?{id:r.id,name:r.name,provider:r.provider,baseUrl:r.baseUrl}:null,providers:o}}export function getCoreCurrentProviderProfile(){const e=i();return e?{activeProfile:{id:e.id,name:e.name,provider:e.provider,baseUrl:e.baseUrl}}:{activeProfile:null}}export function setCoreActiveProfile(e,r){t(e)&&n(e,r)}export function isCoreSelectedProfileReady(e,r){if(!r||!t(e))return!0;const i=o(e);return!!i&&isProviderProfileAuthenticated(e,i.id)}export function switchCoreProvider(e){const r=l({currentModel:e.currentModel,currentProvider:e.currentProvider,targetProvider:e.targetProvider,targetProfileName:e.targetProfileName}),i=t(e.targetProvider)?o(e.targetProvider):null;return{restoredModel:r,activeProfileName:i?.name}}function isProviderProfileAuthenticated(e,r){return"claude"===e?u("claude",r):"openai"===e?u("openai",r):"openrouter"!==e&&"gemini-api"!==e&&"zai"!==e&&"minimax"!==e&&"nvidia"!==e&&"deepseek"!==e&&"xai"!==e&&"gmi"!==e&&"novita"!==e&&"stepfun"!==e&&"huggingface"!==e&&"opencode-zen"!==e&&"arcee"!==e&&"alibaba"!==e&&"kimi"!==e||d(e,r)}
@@ -1 +1 @@
1
- import{jsxs as e}from"react/jsx-runtime";import{useCallback as t,useEffect as n,useMemo as o,useRef as s,useState as r}from"react";import{useNotifications as i}from"../context/notifications.js";import{Text as a}from"../ink.js";import{logEvent as l}from"../services/analytics/index.js";import{useDebounceCallback as m}from"usehooks-ts";import{getCommandName as g}from"../commands.js";import{getModeFromInput as c,getValueFromInput as u}from"../components/PromptInput/inputModes.js";import{useIsModalOverlayActive as d,useRegisterOverlay as p}from"../context/overlayContext.js";import{KeyboardEvent as f}from"../ink/events/keyboard-event.js";import{useInput as h}from"../ink.js";import{useOptionalKeybindingContext as v,useRegisterKeybindingContext as A}from"../keybindings/KeybindingContext.js";import{useKeybindings as b}from"../keybindings/useKeybinding.js";import{useShortcutDisplay as S}from"../keybindings/useShortcutDisplay.js";import{useAppState as w,useAppStateStore as $}from"../state/AppState.js";import{isAgentSwarmsEnabled as y}from"../utils/agentSwarmsEnabled.js";import{getShellCompletions as C}from"../utils/bash/shellCompletion.js";import{formatLogMetadata as x}from"../utils/format.js";import{getSessionIdFromLog as k,searchSessionsByCustomTitle as H}from"../utils/sessionStorage.js";import{applyCommandSuggestion as P,findMidInputSlashCommand as T,getBestCommandMatch as W,isCommandInput as L}from"../utils/suggestions/commandSuggestions.js";import{getDirectoryCompletions as j}from"../utils/suggestions/directoryCompletion.js";import{getShellHistoryCompletion as N}from"../utils/suggestions/shellHistoryCompletion.js";import{getSlackChannelSuggestions as I,hasSlackMcpServer as M}from"../utils/suggestions/slackChannelSuggestions.js";import{TEAM_LEAD_NAME as q}from"../utils/swarm/constants.js";import{listProviderProfiles as Q}from"../utils/model/providerProfiles.js";import{applyFileSuggestion as D,findLongestCommonPrefix as R,onIndexBuildComplete as V,startBackgroundCacheRefresh as O}from"./fileSuggestions.js";import{generateUnifiedSuggestions as E}from"./unifiedSuggestions.js";const _=/^@[\p{L}\p{N}\p{M}_\-./\\()[\]~:]*/u,z=/^[\p{L}\p{N}\p{M}_\-./\\()[\]~:]+/u,G=/(@[\p{L}\p{N}\p{M}_\-./\\()[\]~:]*|[\p{L}\p{N}\p{M}_\-./\\()[\]~:]+)$/u,F=/[\p{L}\p{N}\p{M}_\-./\\()[\]~:]+$/u,K=/(^|\s)@([\p{L}\p{N}\p{M}_\-./\\()[\]~:]*|"[^"]*"?)$/u,B=/(^|\s)#([a-z0-9][a-z0-9_-]*)$/,U=["list","current","use","rename","remove","model","agent"],Z=["list","show","enable","disable","setup","orchestrator"],J=["list","create","show","orchestrator","equipo","add-member"],X=["frontend","backend","docs","tests","review","database","devops"],Y=[{provider:"claude",label:"Context"},{provider:"openai",label:"OpenAI"},{provider:"openrouter",label:"OpenRouter"},{provider:"ollama",label:"Ollama"},{provider:"ollama-cloud",label:"Ollama Cloud"},{provider:"gemini-api",label:"Gemini API"},{provider:"gemini-google",label:"Gemini Google OAuth"},{provider:"zai",label:"Z.AI"},{provider:"minimax",label:"MiniMax"},{provider:"nvidia",label:"NVIDIA API"},{provider:"deepseek",label:"DeepSeek"},{provider:"custom-openai",label:"Custom OpenAI"},{provider:"custom-anthropic",label:"Custom Anthropic"}];function isPathMetadata(e){return"object"==typeof e&&null!==e&&"type"in e&&("directory"===e.type||"file"===e.type)}function getPreservedSelection(e,t,n){if(0===n.length)return-1;if(t<0)return 0;const o=e[t];if(!o)return 0;const s=n.findIndex(e=>e.id===o.id);return s>=0?s:0}function replaceProfileArgs(e,t){const n="/profile";return t.length>0?`${n} ${t}`:n}function buildProfileArgSuggestion(e,t,n,o){return{id:e,displayText:t,description:o,metadata:{replacement:n}}}function replaceWorkspaceArgs(e){const t="/workspace";return e.length>0?`${t} ${e}`:t}function buildWorkspaceArgSuggestion(e,t,n,o){return{id:e,displayText:t,description:o,metadata:{replacement:n}}}function replaceTeamArgs(e){const t="/team";return e.length>0?`${t} ${e}`:t}function buildTeamArgSuggestion(e,t,n,o){return{id:e,displayText:t,description:o,metadata:{replacement:n}}}function getProviderCommandSuggestions(e){const t=extractCommandNameAndArgs(e);if(!t||"provider"!==t.commandName)return null;const n=t.args??"",o=/\s$/.test(n),s=n.trim().length>0?n.trim().split(/\s+/):[],r=o?[...s,""]:s,i=r[0]??"",a=r[1]??"",makeProviderSuggestions=e=>Y.filter(t=>t.provider.startsWith(e.toLowerCase())).map(e=>buildProfileArgSuggestion(`provider-choice-${e.provider}`,e.provider,`/provider ${e.provider} `,e.label));if(r.length<=1){const e=i.toLowerCase();return{suggestions:[...["list","current","reset"].filter(t=>t.startsWith(e)).map(e=>buildProfileArgSuggestion(`provider-subcommand-${e}`,e,`/provider ${e} `,"list"===e?"Listar proveedores":"current"===e?"Ver proveedor actual":"Resetear configuración")),...makeProviderSuggestions(e)],commandArgumentHint:"<proveedor|list|current>"}}if(["list","current","reset"].includes(i.toLowerCase()))return{suggestions:[],commandArgumentHint:void 0};if(Y.some(e=>e.provider===i.toLowerCase())&&r.length<=2){const e=a.toLowerCase(),t=((e,t)=>Q(e).filter(e=>e.name.toLowerCase().startsWith(t.toLowerCase())).map(t=>buildProfileArgSuggestion(`provider-profile-${t.id}`,t.name,`/provider ${e} ${t.name} `,`${t.agentName}${t.lastModel?` · ${t.lastModel}`:""}`)))(i.toLowerCase(),e);return{suggestions:[...t,...["reset","set","url","clear"].filter(t=>t.startsWith(e)).map(e=>buildProfileArgSuggestion(`provider-keyword-${e}`,e,`/provider ${i} ${e} `,`Acción: ${e}`))],commandArgumentHint:"<perfil|url|reset>"}}return{suggestions:[],commandArgumentHint:void 0}}function buildSlashArgSuggestion(e,t,n,o){return{id:e,displayText:t,description:o,metadata:{replacement:n}}}const ee=[{name:"status",description:"Ver configuración actual"},{name:"browser",description:"Cambiar navegador",valueAfter:"<chromium|chrome|firefox|webkit|msedge>"},{name:"visible",description:"Modo visible (headed)"},{name:"headless",description:"Modo oculto (headless)"},{name:"executable",description:'Ruta a binario custom o "clear"'},{name:"device",description:'Dispositivo a emular o "clear"'},{name:"viewport",description:'Tamaño viewport (ej 1280x720) o "clear"'},{name:"reset",description:"Borrar config y volver a defaults"},{name:"help",description:"Ver ayuda detallada"}],te=[{name:"chromium",description:"Chromium (default, Playwright lo descarga)"},{name:"chrome",description:"Google Chrome del sistema"},{name:"msedge",description:"Microsoft Edge del sistema (Windows)"},{name:"firefox",description:"Firefox (Playwright lo descarga)"},{name:"webkit",description:"WebKit (Playwright lo descarga)"}];const ne=[{name:"status",description:"Ver estado del bridge y números autorizados"},{name:"permitidos",description:"Listar/configurar números autorizados"},{name:"start",description:"Iniciar bridge (requiere cuenta vinculada)"},{name:"stop",description:"Detener bridge"},{name:"help",description:"Ver ayuda detallada"},{name:"global",description:"Subcomandos del canal global (status/start/stop)"}],oe=[{name:"status",description:"Estado del daemon global"},{name:"start",description:"Iniciar daemon global"},{name:"stop",description:"Detener daemon global"}];const se=[{name:"status",description:"Ver estado del bot y usuarios permitidos"},{name:"permitidos",description:"Listar usuarios autorizados"},{name:"help",description:"Ver ayuda detallada"},{name:"global",description:"Subcomandos del canal global (status/start/stop)"}];const re=[{name:"start",description:"Iniciar servidor y abrir en navegador"},{name:"stop",description:"Detener servidor web"},{name:"status",description:"Ver estado del servidor y conexiones"},{name:"open",description:"Abrir la WebApp en el navegador"},{name:"token",description:"Ver token de autenticación actual"},{name:"port",description:"Cambiar puerto del servidor"},{name:"autostart",description:"Activar/desactivar inicio automático"},{name:"help",description:"Ver ayuda detallada"}];function getProviderAgentRefSuggestions(e,t,n=!0){const o=e.toLowerCase(),s=[];for(const e of Y)for(const r of Q(e.provider)){const i=`${e.provider}/${r.agentName||`${r.name}-lead`}`;i.toLowerCase().startsWith(o)&&s.push(buildTeamArgSuggestion(`team-agent-${r.id}`,i,replaceTeamArgs([...t,i].join(" ")+(n?" ":"")),r.lastModel?`${e.label} - ${r.lastModel}`:e.label))}return s}function applyCommandArgSuggestion(e,t,n){const o=e.metadata,s=o?.replacement??e.displayText;t(s),n(s.length)}function buildResumeInputFromSuggestion(e){const t=e.metadata;return t?.sessionId?`/resume ${t.sessionId}`:`/resume ${e.displayText}`}export function extractSearchToken(e){return e.isQuoted?e.token.slice(2).replace(/"$/,""):e.token.startsWith("@")?e.token.substring(1):e.token}export function formatReplacementValue(e){const{displayText:t,mode:n,hasAtPrefix:o,needsQuotes:s,isQuoted:r,isComplete:i}=e,a=i?" ":"";return r||s?"bash"===n?`"${t}"${a}`:`@"${t}"${a}`:o?"bash"===n?`${t}${a}`:`@${t}${a}`:t}export function applyShellSuggestion(e,t,n,o,s,r){const i=t.slice(0,n).lastIndexOf(" ")+1;let a;a="variable"===r?"$"+e.displayText+" ":"command"===r?e.displayText+" ":e.displayText;o(t.slice(0,i)+a+t.slice(n)),s(i+a.length)}const ie=/(^|\s)@[\w-]*$/;function applyTriggerSuggestion(e,t,n,o,s,r){const i=t.slice(0,n).match(o);if(!i||void 0===i.index)return;const a=i.index+(i[1]?.length??0),l=t.slice(0,a);s(l+e.displayText+" "+t.slice(n)),r(l.length+e.displayText.length+1)}let ae=null;export function applyDirectorySuggestion(e,t,n,o,s){const r=s?"/":" ",i=e.slice(0,n),a="@"+t+r;return{newInput:i+a+e.slice(n+o),cursorPos:i.length+a.length}}export function extractCompletionToken(e,t,n=!1){if(!e)return null;const o=e.substring(0,t);if(n){const n=/@"([^"]*)"?$/,s=o.match(n);if(s&&void 0!==s.index){const n=e.substring(t).match(/^[^"]*"?/),o=n?n[0]:"";return{token:s[0]+o,startPos:s.index,isQuoted:!0}}}if(n){const n=o.lastIndexOf("@");if(n>=0&&(0===n||/\s/.test(o[n-1]))){const s=o.substring(n),r=s.match(_);if(r&&r[0].length===s.length){const o=e.substring(t).match(z),s=o?o[0]:"";return{token:r[0]+s,startPos:n,isQuoted:!1}}}}const s=n?G:F,r=o.match(s);if(!r||void 0===r.index)return null;const i=e.substring(t).match(z),a=i?i[0]:"";return{token:r[0]+a,startPos:r.index,isQuoted:!1}}function extractCommandNameAndArgs(e){if(L(e)){const t=e.indexOf(" ");return-1===t?{commandName:e.slice(1),args:""}:{commandName:e.slice(1,t),args:e.slice(t+1)}}return null}export function useTypeahead({commands:_,onInputChange:z,onSubmit:G,setCursorOffset:F,input:le,cursorOffset:me,mode:ge,agents:ce,setSuggestionsState:ue,suggestionsState:{suggestions:de,selectedSuggestion:pe,commandArgumentHint:fe},suppressSuggestions:he=!1,markAccepted:ve,onModeChange:Ae}){const{addNotification:be}=i(),Se=S("chat:thinkingToggle","Chat","alt+t"),[we,$e]=r("none"),ye=o(()=>{const e=_.filter(e=>!e.isHidden);if(0===e.length)return;return Math.max(...e.map(e=>g(e).length))+6},[_]),[Ce,xe]=r(void 0),ke=w(e=>e.mcp.resources),He=$(),Pe=w(e=>e.promptSuggestion),Te=w(e=>!!e.viewingAgentTaskId),We=v(),[Le,je]=r(void 0),Ne=o(()=>{if("prompt"!==ge||he)return;const e=T(le,me);if(!e)return;const t=W(e.partialCommand,_);return t?{text:t.suffix,fullCommand:t.fullCommand,insertPosition:e.startPos+1+e.partialCommand.length}:void 0},[le,me,ge,_,he]),Ie=he?void 0:"prompt"===ge?Ne:Le,Me=s(me);Me.current=me;const qe=s(null),Qe=s(""),De=(s(""),s("")),Re=s("");s(de).current=de;const Ve=s(null),Oe=t(()=>{ue(()=>({commandArgumentHint:void 0,suggestions:[],selectedSuggestion:-1})),$e("none"),xe(void 0),je(void 0)},[ue]),Ee=t(async(e,t=!1)=>{qe.current=e;const n=await E(e,ke,ce,t);if(qe.current===e){if(0===n.length)return ue(()=>({commandArgumentHint:void 0,suggestions:[],selectedSuggestion:-1})),$e("none"),void xe(void 0);ue(e=>({commandArgumentHint:void 0,suggestions:n,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,n)})),$e(n.length>0?"file":"none"),xe(void 0)}},[ke,ue,$e,xe,ce]);n(()=>(O(),V(()=>{const e=qe.current;null!==e&&(qe.current=null,Ee(e,""===e))})),[Ee]);const _e=m(Ee,50),ze=t(async e=>{Re.current=e;const t=await I(He.getState().mcp.clients,e);Re.current===e&&(ue(e=>({commandArgumentHint:void 0,suggestions:t,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,t)})),$e(t.length>0?"slack-channel":"none"),xe(void 0))},[ue]),Ge=m(ze,150),Fe=t(async(e,t)=>{const n=t??Me.current;if(he)return _e.cancel(),void Oe();if("prompt"===ge){const t=T(e,n);if(t){if(W(t.partialCommand,_))return ue(()=>({commandArgumentHint:void 0,suggestions:[],selectedSuggestion:-1})),$e("none"),void xe(void 0)}}if("bash"===ge&&e.trim()){De.current=e;const t=await N(e);if(De.current!==e)return;if(t)return je({text:t.suffix,fullCommand:t.fullCommand,insertPosition:e.length}),ue(()=>({commandArgumentHint:void 0,suggestions:[],selectedSuggestion:-1})),$e("none"),void xe(void 0);je(void 0)}const o="bash"!==ge?e.substring(0,n).match(/(^|\s)@([\w-]*)$/):null;if(o){const e=(o[2]??"").toLowerCase(),t=He.getState(),n=[],s=new Set;if(y()&&t.teamContext)for(const o of Object.values(t.teamContext.teammates??{}))o.name!==q&&o.name.toLowerCase().startsWith(e)&&(s.add(o.name),n.push({id:`dm-${o.name}`,displayText:`@${o.name}`,description:"send message"}));for(const[o,r]of t.agentNameRegistry){if(s.has(o))continue;if(!o.toLowerCase().startsWith(e))continue;const i=t.tasks[r]?.status;n.push({id:`dm-${o}`,displayText:`@${o}`,description:i?`send message · ${i}`:"send message"})}if(n.length>0)return _e.cancel(),ue(e=>({commandArgumentHint:void 0,suggestions:n,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,n)})),$e("agent"),void xe(void 0)}if("prompt"===ge){const t=e.substring(0,n).match(B);if(t&&M(He.getState().mcp.clients))return void Ge(t[2]);"slack-channel"===we&&(Ge.cancel(),Oe())}const s=e.substring(0,n).match(K),r=n===e.length&&n>0&&e.length>0&&" "===e[n-1];if("prompt"===ge&&L(e)&&n>0){const t=extractCommandNameAndArgs(e);if(t&&"add-dir"===t.commandName&&t.args){const{args:e}=t;if(e.match(/\s+$/))return _e.cancel(),void Oe();const n=await j(e);return n.length>0?(ue(e=>({suggestions:n,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,n),commandArgumentHint:void 0})),void $e("directory")):(_e.cancel(),void Oe())}if(t&&"resume"===t.commandName&&void 0!==t.args&&e.includes(" ")){const{args:e}=t,n=(await H(e,{limit:10})).map(e=>{const t=k(e);return{id:`resume-title-${t}`,displayText:e.customTitle,description:x(e),metadata:{sessionId:t}}});return n.length>0?(ue(e=>({suggestions:n,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,n),commandArgumentHint:void 0})),void $e("custom-title")):void Oe()}}const i="prompt"===ge?function(e){const t=extractCommandNameAndArgs(e);if(!t||"team"!==t.commandName)return null;const n=t.args??"",o=/\s$/.test(n),s=n.trim().length>0?n.trim().split(/\s+/):[],r=o?[...s,""]:s,i=r[0]??"",a=i.toLowerCase();if(r.length<=1){const e=i.toLowerCase();return{suggestions:J.filter(t=>t.startsWith(e)).map(e=>buildTeamArgSuggestion(`team-subcommand-${e}`,e,replaceTeamArgs(`${e} `))),commandArgumentHint:"<subcomando>"}}if("list"===a)return{suggestions:[],commandArgumentHint:void 0};if("create"===a)return{suggestions:[],commandArgumentHint:"<nombre-equipo>"};if("show"===a)return{suggestions:[],commandArgumentHint:"<equipo>"};if("orchestrator"===a)return r.length<=2?{suggestions:[],commandArgumentHint:"<equipo>"}:{suggestions:getProviderAgentRefSuggestions(r[r.length-1]??"",r.slice(0,r.length-1),!1),commandArgumentHint:"<provider/agent>"};if("equipo"===a){if(r.length<=2)return{suggestions:[],commandArgumentHint:"<equipo>"};if(r.length<=3){const e=r[1]??"",t=(r[2]??"").toLowerCase();return{suggestions:X.filter(e=>e.startsWith(t)).map(t=>buildTeamArgSuggestion(`team-equipo-${t}`,t,replaceTeamArgs(["equipo",e,t,""].join(" ").trimEnd()+" "),`equipo ${t}`)),commandArgumentHint:"<area>"}}return{suggestions:getProviderAgentRefSuggestions(r[r.length-1]??"",r.slice(0,r.length-1),!1),commandArgumentHint:"<provider/agent>"}}if("add-member"===a){if(r.length<=2)return{suggestions:[],commandArgumentHint:"<equipo>"};if(r.length<=3){const e=r[1]??"",t=(r[2]??"").toLowerCase();return{suggestions:X.filter(e=>e.startsWith(t)).map(t=>buildTeamArgSuggestion(`team-member-equipo-${t}`,t,replaceTeamArgs(["add-member",e,t,""].join(" ").trimEnd()+" "),`equipo ${t}`)),commandArgumentHint:"<area>"}}return r.length<=4?{suggestions:getProviderAgentRefSuggestions(r[3]??"",r.slice(0,3)),commandArgumentHint:"<provider/agent>"}:{suggestions:[],commandArgumentHint:"[duty]"}}return{suggestions:[],commandArgumentHint:void 0}}(e):null;if(i){const{suggestions:e,commandArgumentHint:t}=i;return ue(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),$e(e.length>0?"command-arg":"none"),void xe(void 0)}const a="prompt"===ge?function(e){const t=extractCommandNameAndArgs(e);if(!t||"workspace"!==t.commandName)return null;const n=t.args??"",o=/\s$/.test(n),s=n.trim().length>0?n.trim().split(/\s+/):[],r=o?[...s,""]:s,i=r[0]??"",a=i.toLowerCase();if(r.length<=1){const e=i.toLowerCase();return{suggestions:Z.filter(t=>t.startsWith(e)).map(e=>buildWorkspaceArgSuggestion(`workspace-subcommand-${e}`,e,replaceWorkspaceArgs(`${e} `))),commandArgumentHint:"<subcomando>"}}if(["show","enable","disable"].includes(a)&&r.length<=2){const e=(r[1]??"").toLowerCase();return{suggestions:Y.filter(t=>t.provider.startsWith(e)).map(e=>buildWorkspaceArgSuggestion(`workspace-provider-${e.provider}`,e.provider,replaceWorkspaceArgs(`${a} ${e.provider}`),e.label)),commandArgumentHint:"<proveedor>"}}if("orchestrator"===a)return{suggestions:[],commandArgumentHint:"[equipo] [provider/agent]"};if("setup"!==a)return{suggestions:[],commandArgumentHint:void 0};if(r.length<=2)return{suggestions:[],commandArgumentHint:"<equipo> [orchestrator=<area|provider/agent>]"};const l=r.length-1,m=r[l]??"",g=r.slice(0,l);if(!g.some(e=>e.toLowerCase().startsWith("orchestrator="))&&"orchestrator=".startsWith(m.toLowerCase()))return{suggestions:[buildWorkspaceArgSuggestion("workspace-orchestrator","orchestrator=",replaceWorkspaceArgs([...g,"orchestrator="].join(" ")),"escoger coordinador principal")],commandArgumentHint:"orchestrator=<area|provider/agent>"};if(m.toLowerCase().startsWith("orchestrator=")){const e=m.slice(13).toLowerCase(),t=X.filter(t=>t.startsWith(e)).map(e=>buildWorkspaceArgSuggestion(`workspace-orchestrator-equipo-${e}`,e,replaceWorkspaceArgs([...g,`orchestrator=${e} `].join(" ").trimEnd()),`usar el equipo ${e} como orquestador`)),n=[];for(const t of Y)for(const o of Q(t.provider)){const s=`${t.provider}/${o.agentName||`${o.name}-lead`}`;s.toLowerCase().startsWith(e)&&n.push(buildWorkspaceArgSuggestion(`workspace-orchestrator-agent-${o.id}`,s,replaceWorkspaceArgs([...g,`orchestrator=${s} `].join(" ").trimEnd()),`agente de ${t.label}`))}return{suggestions:[...t,...n],commandArgumentHint:"orchestrator=<area|provider/agent>"}}const c=m.indexOf(":");if(c>=0){const e=m.slice(0,c),t=m.slice(c+1).toLowerCase();return{suggestions:X.filter(e=>e.startsWith(t)).map(t=>buildWorkspaceArgSuggestion(`workspace-equipo-${e}-${t}`,t,replaceWorkspaceArgs([...g,`${e}:${t} `].join(" ").trimEnd()),`equipo ${t}`)),commandArgumentHint:"<proveedor/perfil:area>"}}const u=m.toLowerCase(),d=[];for(const e of Y)for(const t of Q(e.provider)){const n=`${e.provider}/${t.name}`;n.toLowerCase().startsWith(u)&&d.push(buildWorkspaceArgSuggestion(`workspace-profile-${t.id}`,`${n}:`,replaceWorkspaceArgs([...g,`${n}:`].join(" ")),t.lastModel?`${e.label} - ${t.lastModel}`:e.label))}return{suggestions:d,commandArgumentHint:"<proveedor/perfil:area>"}}(e):null;if(a){const{suggestions:e,commandArgumentHint:t}=a;return ue(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),$e(e.length>0?"command-arg":"none"),void xe(void 0)}const l="prompt"===ge?function(e){const t=extractCommandNameAndArgs(e);if(!t||"profile"!==t.commandName)return null;const n=t.args??"",o=/\s$/.test(n),s=n.trim().length>0?n.trim().split(/\s+/):[],r=o?[...s,""]:s,i=r[0]??"",a=r[1]??"",l=r[2]??"",m=i.toLowerCase(),makeProviderSuggestions=(e,t)=>Y.filter(t=>t.provider.startsWith(e.toLowerCase())).map(e=>buildProfileArgSuggestion(`profile-provider-${e.provider}`,e.provider,replaceProfileArgs(0,[...t,e.provider,""].join(" ").trimEnd()+" "),e.label)),makeProfileSuggestions=(e,t,n)=>e&&Y.some(t=>t.provider===e)?Q(e).filter(e=>e.name.toLowerCase().startsWith(t.toLowerCase())).map(e=>buildProfileArgSuggestion(`profile-name-${e.id}`,e.name,replaceProfileArgs(0,[...n,e.name,""].join(" ").trimEnd()+" "),`${e.agentName}${e.lastModel?` · ${e.lastModel}`:""}`)):[];if(r.length<=1){const e=i.toLowerCase();return{suggestions:U.filter(t=>t.startsWith(e)).map(e=>buildProfileArgSuggestion(`profile-subcommand-${e}`,e,replaceProfileArgs(0,`${e} `))),commandArgumentHint:"<subcomando>"}}if("list"===m||"current"===m)return{suggestions:[],commandArgumentHint:void 0};if("remove"===m&&r.length<=2){const e=a.toLowerCase();return{suggestions:[buildProfileArgSuggestion("profile-remove-all","all",replaceProfileArgs(0,"remove all"),"Eliminar todos los perfiles"),...makeProviderSuggestions(e,["remove"])].filter(t=>t.displayText.toLowerCase().startsWith(e)),commandArgumentHint:"<proveedor|all>"}}return["use","rename","remove","model","agent"].includes(m)&&r.length<=2?{suggestions:makeProviderSuggestions(a,[m]),commandArgumentHint:"<proveedor>"}:["use","remove","model","agent"].includes(m)&&r.length<=3?{suggestions:makeProfileSuggestions(a,l,[m,a]),commandArgumentHint:"<perfil>"}:"rename"===m&&r.length<=3?{suggestions:makeProfileSuggestions(a,l,[m,a]),commandArgumentHint:"<perfil-actual>"}:{suggestions:[],commandArgumentHint:void 0}}(e):null;if(l){const{suggestions:e,commandArgumentHint:t}=l;return ue(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),$e(e.length>0?"command-arg":"none"),void xe(void 0)}const m="prompt"===ge?getProviderCommandSuggestions(e):null;if(m){const{suggestions:e,commandArgumentHint:t}=m;return ue(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),$e(e.length>0?"command-arg":"none"),void xe(void 0)}const c="prompt"===ge?function(e){const t=extractCommandNameAndArgs(e);if(!t)return null;const n=t.commandName.toLowerCase();if("playwright"!==n&&"pw"!==n)return null;const o=t.args??"",s=/\s$/.test(o),r=o.trim().length>0?o.trim().split(/\s+/):[],i=s?[...r,""]:r,a=(i[0]??"").toLowerCase(),l=(i[1]??"").toLowerCase();if(i.length<=1)return{suggestions:ee.filter(e=>e.name.startsWith(a)).map(e=>buildSlashArgSuggestion(`playwright-sub-${e.name}`,e.name,`/playwright ${e.name} `,e.description)),commandArgumentHint:"[status|browser|visible|headless|reset|help]"};if("browser"===a&&i.length<=2)return{suggestions:te.filter(e=>e.name.startsWith(l)).map(e=>buildSlashArgSuggestion(`playwright-browser-${e.name}`,e.name,`/playwright browser ${e.name} `,e.description)),commandArgumentHint:"<chromium|chrome|firefox|webkit|msedge>"};return("executable"===a||"device"===a||"viewport"===a)&&i.length<=2&&"clear".startsWith(l)?{suggestions:[buildSlashArgSuggestion(`playwright-${a}-clear`,"clear",`/playwright ${a} clear`,`Quitar ${a} custom`)],commandArgumentHint:"<valor|clear>"}:{suggestions:[],commandArgumentHint:void 0}}(e):null;if(c){const{suggestions:e,commandArgumentHint:t}=c;return ue(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),$e(e.length>0?"command-arg":"none"),void xe(void 0)}const u="prompt"===ge?function(e){const t=extractCommandNameAndArgs(e);if(!t)return null;const n=t.commandName.toLowerCase();if("whatsapp"!==n&&"wa"!==n&&"whats"!==n)return null;const o=t.args??"",s=/\s$/.test(o),r=o.trim().length>0?o.trim().split(/\s+/):[],i=s?[...r,""]:r,a=(i[0]??"").toLowerCase(),l=(i[1]??"").toLowerCase();if(i.length<=1)return{suggestions:ne.filter(e=>e.name.startsWith(a)).map(e=>buildSlashArgSuggestion(`whatsapp-sub-${e.name}`,e.name,`/whatsapp ${e.name} `,e.description)),commandArgumentHint:"[status|permitidos|start|stop|global|help]"};if("global"===a&&i.length<=2)return{suggestions:oe.filter(e=>e.name.startsWith(l)).map(e=>buildSlashArgSuggestion(`whatsapp-global-${e.name}`,e.name,`/whatsapp global ${e.name} `,e.description)),commandArgumentHint:"<status|start|stop>"};return{suggestions:[],commandArgumentHint:void 0}}(e):null;if(u){const{suggestions:e,commandArgumentHint:t}=u;return ue(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),$e(e.length>0?"command-arg":"none"),void xe(void 0)}const d="prompt"===ge?function(e){const t=extractCommandNameAndArgs(e);if(!t)return null;const n=t.commandName.toLowerCase();if("telegram"!==n&&"tg"!==n)return null;const o=t.args??"",s=/\s$/.test(o),r=o.trim().length>0?o.trim().split(/\s+/):[],i=s?[...r,""]:r,a=(i[0]??"").toLowerCase(),l=(i[1]??"").toLowerCase();if(i.length<=1)return{suggestions:se.filter(e=>e.name.startsWith(a)).map(e=>buildSlashArgSuggestion(`telegram-sub-${e.name}`,e.name,`/telegram ${e.name} `,e.description)),commandArgumentHint:"[status|permitidos|global|help]"};if("global"===a&&i.length<=2)return{suggestions:oe.filter(e=>e.name.startsWith(l)).map(e=>buildSlashArgSuggestion(`telegram-global-${e.name}`,e.name,`/telegram global ${e.name} `,e.description)),commandArgumentHint:"<status|start|stop>"};return{suggestions:[],commandArgumentHint:void 0}}(e):null;if(d){const{suggestions:e,commandArgumentHint:t}=d;return ue(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),$e(e.length>0?"command-arg":"none"),void xe(void 0)}const p="prompt"===ge?function(e){const t=extractCommandNameAndArgs(e);if(!t)return null;const n=t.commandName.toLowerCase();if("webapp"!==n&&"app"!==n&&"pwa"!==n&&"aplicacion-web"!==n)return null;const o=t.args??"",s=/\s$/.test(o),r=o.trim().length>0?o.trim().split(/\s+/):[],i=s?[...r,""]:r,a=(i[0]??"").toLowerCase(),l=(i[1]??"").toLowerCase();if(i.length<=1)return{suggestions:re.filter(e=>e.name.startsWith(a)).map(e=>buildSlashArgSuggestion(`webapp-sub-${e.name}`,e.name,`/webapp ${e.name} `,e.description)),commandArgumentHint:"[start|stop|status|open|token|port|autostart|help]"};if("token"===a&&i.length<=2)return{suggestions:[{name:"reset",description:"Regenerar token (invalida el anterior)"}].filter(e=>e.name.startsWith(l)).map(e=>buildSlashArgSuggestion(`webapp-token-${e.name}`,e.name,`/webapp token ${e.name} `,e.description)),commandArgumentHint:"[reset]"};return{suggestions:[],commandArgumentHint:void 0}}(e):null;if(p){const{suggestions:e,commandArgumentHint:t}=p;return ue(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),$e(e.length>0?"command-arg":"none"),void xe(void 0)}if("bash"!==ge&&L(e)&&n>0&&!r){const t=e.slice(1).toLowerCase();if(!function(e,t){return!e&&t.includes(" ")&&!t.endsWith(" ")}(r,e)){const e=_.filter(e=>!e.isHidden).filter(e=>g(e).startsWith(t)||(e.aliases??[]).some(e=>e.startsWith(t))).map(e=>({id:g(e),displayText:`/${g(e)}`,description:e.description??"",metadata:e}));return ue(t=>({commandArgumentHint:void 0,suggestions:e,selectedSuggestion:getPreservedSelection(t.suggestions,t.selectedSuggestion,e)})),$e(e.length>0?"command":"none"),void xe(e.length>0?ye:void 0)}}if(s){const t=extractCompletionToken(e,n,!0);if(t){const e=t.token.startsWith("@"),n=e?t.token.substring(1):t.token;return void _e(n,e)}}_e.cancel(),Oe()},[ge,he,_,Oe,_e,ue,ye,Ge,we]);n(()=>{Ve.current!==le&&(Qe.current!==le&&(Qe.current=le,qe.current=null),Ve.current=null,Fe(le))},[le,Fe]);const Ke=t(async()=>{if(Ie){if("bash"===ge)return z(Ie.fullCommand),F(Ie.fullCommand.length),void je(void 0);const e=T(le,me);if(e){const t=le.slice(0,e.startPos),n=le.slice(e.startPos+e.token.length),o=t+"/"+Ie.fullCommand+" "+n,s=e.startPos+1+Ie.fullCommand.length+1;return z(o),void F(s)}}if(de.length>0){_e.cancel(),Ge.cancel();const e=-1===pe?0:pe,t=de[e];if("command"===we&&e<de.length)t&&(P(t,!1,_,z,F,G),Oe());else if("command-arg"===we&&e<de.length)t&&(applyCommandArgSuggestion(t,z,F),Oe());else if("custom-title"===we&&de.length>0){if(t){const e=buildResumeInputFromSuggestion(t);z(e),F(e.length),Oe()}}else if("directory"===we&&de.length>0){const t=de[e];if(t){let e;if(L(le)){const n=le.indexOf(" "),o=le.slice(0,n+1),s=isPathMetadata(t.metadata)&&"directory"===t.metadata.type?"/":" ";e=o+t.id+s,z(e),F(e.length),isPathMetadata(t.metadata)&&"directory"===t.metadata.type?(ue(e=>({...e,commandArgumentHint:void 0})),Fe(e,e.length)):Oe()}else{const n=extractCompletionToken(le,me,!0)??extractCompletionToken(le,me,!1);if(n){const o=isPathMetadata(t.metadata)&&"directory"===t.metadata.type,s=applyDirectorySuggestion(le,t.id,n.startPos,n.token.length,o);e=s.newInput,z(e),F(s.cursorPos),o?(ue(e=>({...e,commandArgumentHint:void 0})),Fe(e,s.cursorPos)):Oe()}else Oe()}}}else if("shell"===we&&de.length>0){const t=de[e];if(t){const e=t.metadata;applyShellSuggestion(t,le,me,z,F,e?.completionType),Oe()}}else if("agent"===we&&de.length>0&&de[e]?.id?.startsWith("dm-")){const t=de[e];t&&(applyTriggerSuggestion(t,le,me,ie,z,F),Oe())}else if("slack-channel"===we&&de.length>0){const t=de[e];t&&(applyTriggerSuggestion(t,le,me,B,z,F),Oe())}else if("file"===we&&de.length>0){const t=extractCompletionToken(le,me,!0);if(!t)return void Oe();const n=R(de),o=t.token.startsWith("@");let s;if(s=t.isQuoted?t.token.slice(2).replace(/"$/,"").length:o?t.token.length-1:t.token.length,n.length>s){const e=formatReplacementValue({displayText:n,mode:ge,hasAtPrefix:o,needsQuotes:!1,isQuoted:t.isQuoted,isComplete:!1});D(e,le,t.token,t.startPos,z,F),Fe(le.replace(t.token,e),me)}else if(e<de.length){const n=de[e];if(n){const e=n.displayText.includes(" "),s=formatReplacementValue({displayText:n.displayText,mode:ge,hasAtPrefix:o,needsQuotes:e,isQuoted:t.isQuoted,isComplete:!0});D(s,le,t.token,t.startPos,z,F),Oe()}}}}else if(""!==le.trim()){let e,t;if("bash"===ge){e="shell";const n=await async function(e,t){try{return ae&&ae.abort(),ae=new AbortController,await C(e,t,ae.signal)}catch{return l("tengu_shell_completion_failed",{}),[]}}(le,me);if(1===n.length){const e=n[0];if(e){const t=e.metadata;applyShellSuggestion(e,le,me,z,F,t?.completionType)}t=[]}else t=n}else{e="file";const n=extractCompletionToken(le,me,!0);if(n){const e=n.token.startsWith("@"),o=e?n.token.substring(1):n.token;t=await E(o,ke,ce,e)}else t=[]}t.length>0&&(ue(e=>({commandArgumentHint:void 0,suggestions:t,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,t)})),$e(e),xe(void 0))}},[de,pe,le,we,_,ge,z,F,G,Oe,me,Fe,ke,ue,ce,_e,Ge,Ie]),Be=t(()=>{if(pe<0||0===de.length)return;const e=de[pe];if("command"===we&&pe<de.length)e&&(P(e,!0,_,z,F,G),_e.cancel(),Oe());else if("command-arg"===we&&pe<de.length){if(e){const t=e.metadata;if((t?.replacement??e.displayText).trim()===le.trim())return _e.cancel(),Oe(),void G(le,!0);applyCommandArgSuggestion(e,z,F),_e.cancel(),Oe()}}else if("custom-title"===we&&pe<de.length){if(e){const t=buildResumeInputFromSuggestion(e);z(t),F(t.length),G(t,!0),_e.cancel(),Oe()}}else if("shell"===we&&pe<de.length){const e=de[pe];if(e){const t=e.metadata;applyShellSuggestion(e,le,me,z,F,t?.completionType),_e.cancel(),Oe()}}else if("agent"===we&&pe<de.length&&e?.id?.startsWith("dm-"))applyTriggerSuggestion(e,le,me,ie,z,F),_e.cancel(),Oe();else if("slack-channel"===we&&pe<de.length)e&&(applyTriggerSuggestion(e,le,me,B,z,F),Ge.cancel(),Oe());else if("file"===we&&pe<de.length){const t=extractCompletionToken(le,me,!0);if(t&&e){const n=t.token.startsWith("@"),o=e.displayText.includes(" "),s=formatReplacementValue({displayText:e.displayText,mode:ge,hasAtPrefix:n,needsQuotes:o,isQuoted:t.isQuoted,isComplete:!0});D(s,le,t.token,t.startPos,z,F),_e.cancel(),Oe()}}else if("directory"===we&&pe<de.length&&e){if(L(le))return _e.cancel(),void Oe();const t=extractCompletionToken(le,me,!0)??extractCompletionToken(le,me,!1);if(t){const n=isPathMetadata(e.metadata)&&"directory"===e.metadata.type,o=applyDirectorySuggestion(le,e.id,t.startPos,t.token.length,n);z(o.newInput),F(o.cursorPos)}_e.cancel(),Oe()}},[de,pe,we,_,le,me,ge,z,F,G,Oe,_e,Ge]),Ue=t(()=>{Ke()},[Ke]),Ze=t(()=>{_e.cancel(),Ge.cancel(),Oe(),Ve.current=le},[_e,Ge,Oe,le]),Je=t(()=>{ue(e=>({...e,selectedSuggestion:e.selectedSuggestion<=0?de.length-1:e.selectedSuggestion-1}))},[de.length,ue]),Xe=t(()=>{ue(e=>({...e,selectedSuggestion:e.selectedSuggestion>=de.length-1?0:e.selectedSuggestion+1}))},[de.length,ue]),Ye=o(()=>({"autocomplete:accept":Ue,"autocomplete:dismiss":Ze,"autocomplete:previous":Je,"autocomplete:next":Xe}),[Ue,Ze,Je,Xe]),et=de.length>0||!!Ie,tt=d();function acceptSuggestionText(e){const t=c(e);if("prompt"!==t&&Ae){Ae(t);const n=u(e);z(n),F(n.length)}else z(e),F(e.length)}p("autocomplete",et),A("Autocomplete",et),b(Ye,{context:"Autocomplete",isActive:et&&!tt});const handleKeyDown=t=>{if("right"===t.key&&!Te){const e=Pe.text,n=Pe.shownAt;if(e&&n>0&&""===le)return ve(),acceptSuggestionText(e),void t.stopImmediatePropagation()}if("tab"===t.key&&!t.shift){if(de.length>0||Ie)return;const n=Pe.text,o=Pe.shownAt;return n&&o>0&&""===le&&!Te?(t.preventDefault(),ve(),void acceptSuggestionText(n)):void(""===le.trim()&&(t.preventDefault(),be({key:"thinking-toggle-hint",jsx:e(a,{dimColor:!0,children:["Usa ",Se," para alternar el modo de razonamiento"]}),priority:"immediate",timeoutMs:3e3})))}if(0===de.length)return;const n=null!=We?.pendingChord;return t.ctrl&&"n"===t.key&&!n?(t.preventDefault(),void Xe()):t.ctrl&&"p"===t.key&&!n?(t.preventDefault(),void Je()):void("return"!==t.key||t.shift||t.meta||(t.preventDefault(),Be()))};return h((e,t,n)=>{const o=new f(n.keypress);handleKeyDown(o),o.didStopImmediatePropagation()&&n.stopImmediatePropagation()}),{suggestions:de,selectedSuggestion:pe,suggestionType:we,maxColumnWidth:Ce,commandArgumentHint:fe,inlineGhostText:Ie,handleKeyDown}}
1
+ import{jsxs as e}from"react/jsx-runtime";import{useCallback as t,useEffect as n,useMemo as o,useRef as s,useState as r}from"react";import{useNotifications as i}from"../context/notifications.js";import{Text as a}from"../ink.js";import{logEvent as l}from"../services/analytics/index.js";import{useDebounceCallback as g}from"usehooks-ts";import{getCommandName as m}from"../commands.js";import{getModeFromInput as c,getValueFromInput as u}from"../components/PromptInput/inputModes.js";import{useIsModalOverlayActive as d,useRegisterOverlay as p}from"../context/overlayContext.js";import{KeyboardEvent as f}from"../ink/events/keyboard-event.js";import{useInput as h}from"../ink.js";import{useOptionalKeybindingContext as v,useRegisterKeybindingContext as A}from"../keybindings/KeybindingContext.js";import{useKeybindings as b}from"../keybindings/useKeybinding.js";import{useShortcutDisplay as S}from"../keybindings/useShortcutDisplay.js";import{useAppState as w,useAppStateStore as $}from"../state/AppState.js";import{isAgentSwarmsEnabled as y}from"../utils/agentSwarmsEnabled.js";import{getShellCompletions as C}from"../utils/bash/shellCompletion.js";import{formatLogMetadata as x}from"../utils/format.js";import{getSessionIdFromLog as k,searchSessionsByCustomTitle as H}from"../utils/sessionStorage.js";import{applyCommandSuggestion as P,findMidInputSlashCommand as T,getBestCommandMatch as W,isCommandInput as L}from"../utils/suggestions/commandSuggestions.js";import{getDirectoryCompletions as j}from"../utils/suggestions/directoryCompletion.js";import{getShellHistoryCompletion as N}from"../utils/suggestions/shellHistoryCompletion.js";import{getSlackChannelSuggestions as I,hasSlackMcpServer as M}from"../utils/suggestions/slackChannelSuggestions.js";import{TEAM_LEAD_NAME as q}from"../utils/swarm/constants.js";import{listProviderProfiles as Q}from"../utils/model/providerProfiles.js";import{applyFileSuggestion as D,findLongestCommonPrefix as R,onIndexBuildComplete as V,startBackgroundCacheRefresh as O}from"./fileSuggestions.js";import{generateUnifiedSuggestions as E}from"./unifiedSuggestions.js";const _=/^@[\p{L}\p{N}\p{M}_\-./\\()[\]~:]*/u,z=/^[\p{L}\p{N}\p{M}_\-./\\()[\]~:]+/u,G=/(@[\p{L}\p{N}\p{M}_\-./\\()[\]~:]*|[\p{L}\p{N}\p{M}_\-./\\()[\]~:]+)$/u,F=/[\p{L}\p{N}\p{M}_\-./\\()[\]~:]+$/u,K=/(^|\s)@([\p{L}\p{N}\p{M}_\-./\\()[\]~:]*|"[^"]*"?)$/u,B=/(^|\s)#([a-z0-9][a-z0-9_-]*)$/,U=["list","current","create","use","rename","remove","model","agent","migrate","clear","clear-all"],Z=new Set(["perfil","perfiles","profile","profiles"]),J=["list","show","enable","disable","setup","orchestrator"],X=["list","create","show","orchestrator","equipo","add-member"],Y=["frontend","backend","docs","tests","review","database","devops"],ee=[{provider:"claude",label:"Context"},{provider:"openai",label:"OpenAI"},{provider:"openrouter",label:"OpenRouter"},{provider:"ollama",label:"Ollama"},{provider:"ollama-cloud",label:"Ollama Cloud"},{provider:"gemini-api",label:"Gemini API"},{provider:"gemini-google",label:"Gemini Google OAuth"},{provider:"zai",label:"Z.AI"},{provider:"minimax",label:"MiniMax"},{provider:"nvidia",label:"NVIDIA API"},{provider:"deepseek",label:"DeepSeek"},{provider:"custom-openai",label:"Custom OpenAI"},{provider:"custom-anthropic",label:"Custom Anthropic"}];function isPathMetadata(e){return"object"==typeof e&&null!==e&&"type"in e&&("directory"===e.type||"file"===e.type)}function getPreservedSelection(e,t,n){if(0===n.length)return-1;if(t<0)return 0;const o=e[t];if(!o)return 0;const s=n.findIndex(e=>e.id===o.id);return s>=0?s:0}function replaceProfileArgs(e,t){const n=/^\/([^\s]+)/.exec(e),o=n?`/${n[1]}`:"/perfil";return t.length>0?`${o} ${t}`:o}function buildProfileArgSuggestion(e,t,n,o){return{id:e,displayText:t,description:o,metadata:{replacement:n}}}function replaceWorkspaceArgs(e){const t="/workspace";return e.length>0?`${t} ${e}`:t}function buildWorkspaceArgSuggestion(e,t,n,o){return{id:e,displayText:t,description:o,metadata:{replacement:n}}}function replaceTeamArgs(e){const t="/team";return e.length>0?`${t} ${e}`:t}function buildTeamArgSuggestion(e,t,n,o){return{id:e,displayText:t,description:o,metadata:{replacement:n}}}function getProviderCommandSuggestions(e){const t=extractCommandNameAndArgs(e);if(!t||"provider"!==t.commandName)return null;const n=t.args??"",o=/\s$/.test(n),s=n.trim().length>0?n.trim().split(/\s+/):[],r=o?[...s,""]:s,i=r[0]??"",a=r[1]??"",makeProviderSuggestions=e=>ee.filter(t=>t.provider.startsWith(e.toLowerCase())).map(e=>buildProfileArgSuggestion(`provider-choice-${e.provider}`,e.provider,`/provider ${e.provider} `,e.label));if(r.length<=1){const e=i.toLowerCase();return{suggestions:[...["list","current","reset","clear","clear-all"].filter(t=>t.startsWith(e)).map(e=>buildProfileArgSuggestion(`provider-subcommand-${e}`,e,`/provider ${e} `,"list"===e?"Listar proveedores":"current"===e?"Ver proveedor actual":"clear"===e||"clear-all"===e?"Eliminar todos los perfiles y credenciales":"Resetear configuración")),...makeProviderSuggestions(e)],commandArgumentHint:"<proveedor|list|current|clear>"}}if("clear"===i.toLowerCase()&&r.length<=2){const e=a.toLowerCase();if("all".startsWith(e))return{suggestions:[buildProfileArgSuggestion("provider-clear-all","all","/provider clear all","Eliminar todos los perfiles y credenciales")],commandArgumentHint:"[all]"}}if(["list","current","reset","clear","clear-all"].includes(i.toLowerCase()))return{suggestions:[],commandArgumentHint:void 0};if(ee.some(e=>e.provider===i.toLowerCase())&&r.length<=2){const e=a.toLowerCase(),t=((e,t)=>Q(e).filter(e=>e.name.toLowerCase().startsWith(t.toLowerCase())).map(t=>buildProfileArgSuggestion(`provider-profile-${t.id}`,t.name,`/provider ${e} ${t.name} `,`${t.agentName}${t.lastModel?` · ${t.lastModel}`:""}`)))(i.toLowerCase(),e);return{suggestions:[...t,...["reset","set","url","clear"].filter(t=>t.startsWith(e)).map(e=>buildProfileArgSuggestion(`provider-keyword-${e}`,e,`/provider ${i} ${e} `,`Acción: ${e}`))],commandArgumentHint:"<perfil|url|reset>"}}return{suggestions:[],commandArgumentHint:void 0}}function buildSlashArgSuggestion(e,t,n,o){return{id:e,displayText:t,description:o,metadata:{replacement:n}}}const te=[{name:"status",description:"Ver configuración actual"},{name:"browser",description:"Cambiar navegador",valueAfter:"<chromium|chrome|firefox|webkit|msedge>"},{name:"visible",description:"Modo visible (headed)"},{name:"headless",description:"Modo oculto (headless)"},{name:"executable",description:'Ruta a binario custom o "clear"'},{name:"device",description:'Dispositivo a emular o "clear"'},{name:"viewport",description:'Tamaño viewport (ej 1280x720) o "clear"'},{name:"reset",description:"Borrar config y volver a defaults"},{name:"help",description:"Ver ayuda detallada"}],ne=[{name:"chromium",description:"Chromium (default, Playwright lo descarga)"},{name:"chrome",description:"Google Chrome del sistema"},{name:"msedge",description:"Microsoft Edge del sistema (Windows)"},{name:"firefox",description:"Firefox (Playwright lo descarga)"},{name:"webkit",description:"WebKit (Playwright lo descarga)"}];const oe=[{name:"status",description:"Ver estado del bridge y números autorizados"},{name:"permitidos",description:"Listar/configurar números autorizados"},{name:"start",description:"Iniciar bridge (requiere cuenta vinculada)"},{name:"stop",description:"Detener bridge"},{name:"help",description:"Ver ayuda detallada"},{name:"global",description:"Subcomandos del canal global (status/start/stop)"}],se=[{name:"status",description:"Estado del daemon global"},{name:"start",description:"Iniciar daemon global"},{name:"stop",description:"Detener daemon global"}];const re=[{name:"status",description:"Ver estado del bot y usuarios permitidos"},{name:"permitidos",description:"Listar usuarios autorizados"},{name:"help",description:"Ver ayuda detallada"},{name:"global",description:"Subcomandos del canal global (status/start/stop)"}];const ie=[{name:"start",description:"Iniciar servidor y abrir en navegador"},{name:"stop",description:"Detener servidor web"},{name:"status",description:"Ver estado del servidor y conexiones"},{name:"open",description:"Abrir la WebApp en el navegador"},{name:"token",description:"Ver token de autenticación actual"},{name:"port",description:"Cambiar puerto del servidor"},{name:"autostart",description:"Activar/desactivar inicio automático"},{name:"help",description:"Ver ayuda detallada"}];function getProviderAgentRefSuggestions(e,t,n=!0){const o=e.toLowerCase(),s=[];for(const e of ee)for(const r of Q(e.provider)){const i=`${e.provider}/${r.agentName||`${r.name}-lead`}`;i.toLowerCase().startsWith(o)&&s.push(buildTeamArgSuggestion(`team-agent-${r.id}`,i,replaceTeamArgs([...t,i].join(" ")+(n?" ":"")),r.lastModel?`${e.label} - ${r.lastModel}`:e.label))}return s}function applyCommandArgSuggestion(e,t,n){const o=e.metadata,s=o?.replacement??e.displayText;t(s),n(s.length)}function buildResumeInputFromSuggestion(e){const t=e.metadata;return t?.sessionId?`/resume ${t.sessionId}`:`/resume ${e.displayText}`}export function extractSearchToken(e){return e.isQuoted?e.token.slice(2).replace(/"$/,""):e.token.startsWith("@")?e.token.substring(1):e.token}export function formatReplacementValue(e){const{displayText:t,mode:n,hasAtPrefix:o,needsQuotes:s,isQuoted:r,isComplete:i}=e,a=i?" ":"";return r||s?"bash"===n?`"${t}"${a}`:`@"${t}"${a}`:o?"bash"===n?`${t}${a}`:`@${t}${a}`:t}export function applyShellSuggestion(e,t,n,o,s,r){const i=t.slice(0,n).lastIndexOf(" ")+1;let a;a="variable"===r?"$"+e.displayText+" ":"command"===r?e.displayText+" ":e.displayText;o(t.slice(0,i)+a+t.slice(n)),s(i+a.length)}const ae=/(^|\s)@[\w-]*$/;function applyTriggerSuggestion(e,t,n,o,s,r){const i=t.slice(0,n).match(o);if(!i||void 0===i.index)return;const a=i.index+(i[1]?.length??0),l=t.slice(0,a);s(l+e.displayText+" "+t.slice(n)),r(l.length+e.displayText.length+1)}let le=null;export function applyDirectorySuggestion(e,t,n,o,s){const r=s?"/":" ",i=e.slice(0,n),a="@"+t+r;return{newInput:i+a+e.slice(n+o),cursorPos:i.length+a.length}}export function extractCompletionToken(e,t,n=!1){if(!e)return null;const o=e.substring(0,t);if(n){const n=/@"([^"]*)"?$/,s=o.match(n);if(s&&void 0!==s.index){const n=e.substring(t).match(/^[^"]*"?/),o=n?n[0]:"";return{token:s[0]+o,startPos:s.index,isQuoted:!0}}}if(n){const n=o.lastIndexOf("@");if(n>=0&&(0===n||/\s/.test(o[n-1]))){const s=o.substring(n),r=s.match(_);if(r&&r[0].length===s.length){const o=e.substring(t).match(z),s=o?o[0]:"";return{token:r[0]+s,startPos:n,isQuoted:!1}}}}const s=n?G:F,r=o.match(s);if(!r||void 0===r.index)return null;const i=e.substring(t).match(z),a=i?i[0]:"";return{token:r[0]+a,startPos:r.index,isQuoted:!1}}function extractCommandNameAndArgs(e){if(L(e)){const t=e.indexOf(" ");return-1===t?{commandName:e.slice(1),args:""}:{commandName:e.slice(1,t),args:e.slice(t+1)}}return null}export function useTypeahead({commands:_,onInputChange:z,onSubmit:G,setCursorOffset:F,input:ge,cursorOffset:me,mode:ce,agents:ue,setSuggestionsState:de,suggestionsState:{suggestions:pe,selectedSuggestion:fe,commandArgumentHint:he},suppressSuggestions:ve=!1,markAccepted:Ae,onModeChange:be}){const{addNotification:Se}=i(),we=S("chat:thinkingToggle","Chat","alt+t"),[$e,ye]=r("none"),Ce=o(()=>{const e=_.filter(e=>!e.isHidden);if(0===e.length)return;return Math.max(...e.map(e=>m(e).length))+6},[_]),[xe,ke]=r(void 0),He=w(e=>e.mcp.resources),Pe=$(),Te=w(e=>e.promptSuggestion),We=w(e=>!!e.viewingAgentTaskId),Le=v(),[je,Ne]=r(void 0),Ie=o(()=>{if("prompt"!==ce||ve)return;const e=T(ge,me);if(!e)return;const t=W(e.partialCommand,_);return t?{text:t.suffix,fullCommand:t.fullCommand,insertPosition:e.startPos+1+e.partialCommand.length}:void 0},[ge,me,ce,_,ve]),Me=ve?void 0:"prompt"===ce?Ie:je,qe=s(me);qe.current=me;const Qe=s(null),De=s(""),Re=(s(""),s("")),Ve=s("");s(pe).current=pe;const Oe=s(null),Ee=t(()=>{de(()=>({commandArgumentHint:void 0,suggestions:[],selectedSuggestion:-1})),ye("none"),ke(void 0),Ne(void 0)},[de]),_e=t(async(e,t=!1)=>{Qe.current=e;const n=await E(e,He,ue,t);if(Qe.current===e){if(0===n.length)return de(()=>({commandArgumentHint:void 0,suggestions:[],selectedSuggestion:-1})),ye("none"),void ke(void 0);de(e=>({commandArgumentHint:void 0,suggestions:n,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,n)})),ye(n.length>0?"file":"none"),ke(void 0)}},[He,de,ye,ke,ue]);n(()=>(O(),V(()=>{const e=Qe.current;null!==e&&(Qe.current=null,_e(e,""===e))})),[_e]);const ze=g(_e,50),Ge=t(async e=>{Ve.current=e;const t=await I(Pe.getState().mcp.clients,e);Ve.current===e&&(de(e=>({commandArgumentHint:void 0,suggestions:t,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,t)})),ye(t.length>0?"slack-channel":"none"),ke(void 0))},[de]),Fe=g(Ge,150),Ke=t(async(e,t)=>{const n=t??qe.current;if(ve)return ze.cancel(),void Ee();if("prompt"===ce){const t=T(e,n);if(t){if(W(t.partialCommand,_))return de(()=>({commandArgumentHint:void 0,suggestions:[],selectedSuggestion:-1})),ye("none"),void ke(void 0)}}if("bash"===ce&&e.trim()){Re.current=e;const t=await N(e);if(Re.current!==e)return;if(t)return Ne({text:t.suffix,fullCommand:t.fullCommand,insertPosition:e.length}),de(()=>({commandArgumentHint:void 0,suggestions:[],selectedSuggestion:-1})),ye("none"),void ke(void 0);Ne(void 0)}const o="bash"!==ce?e.substring(0,n).match(/(^|\s)@([\w-]*)$/):null;if(o){const e=(o[2]??"").toLowerCase(),t=Pe.getState(),n=[],s=new Set;if(y()&&t.teamContext)for(const o of Object.values(t.teamContext.teammates??{}))o.name!==q&&o.name.toLowerCase().startsWith(e)&&(s.add(o.name),n.push({id:`dm-${o.name}`,displayText:`@${o.name}`,description:"send message"}));for(const[o,r]of t.agentNameRegistry){if(s.has(o))continue;if(!o.toLowerCase().startsWith(e))continue;const i=t.tasks[r]?.status;n.push({id:`dm-${o}`,displayText:`@${o}`,description:i?`send message · ${i}`:"send message"})}if(n.length>0)return ze.cancel(),de(e=>({commandArgumentHint:void 0,suggestions:n,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,n)})),ye("agent"),void ke(void 0)}if("prompt"===ce){const t=e.substring(0,n).match(B);if(t&&M(Pe.getState().mcp.clients))return void Fe(t[2]);"slack-channel"===$e&&(Fe.cancel(),Ee())}const s=e.substring(0,n).match(K),r=n===e.length&&n>0&&e.length>0&&" "===e[n-1];if("prompt"===ce&&L(e)&&n>0){const t=extractCommandNameAndArgs(e);if(t&&"add-dir"===t.commandName&&t.args){const{args:e}=t;if(e.match(/\s+$/))return ze.cancel(),void Ee();const n=await j(e);return n.length>0?(de(e=>({suggestions:n,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,n),commandArgumentHint:void 0})),void ye("directory")):(ze.cancel(),void Ee())}if(t&&"resume"===t.commandName&&void 0!==t.args&&e.includes(" ")){const{args:e}=t,n=(await H(e,{limit:10})).map(e=>{const t=k(e);return{id:`resume-title-${t}`,displayText:e.customTitle,description:x(e),metadata:{sessionId:t}}});return n.length>0?(de(e=>({suggestions:n,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,n),commandArgumentHint:void 0})),void ye("custom-title")):void Ee()}}const i="prompt"===ce?function(e){const t=extractCommandNameAndArgs(e);if(!t||"team"!==t.commandName)return null;const n=t.args??"",o=/\s$/.test(n),s=n.trim().length>0?n.trim().split(/\s+/):[],r=o?[...s,""]:s,i=r[0]??"",a=i.toLowerCase();if(r.length<=1){const e=i.toLowerCase();return{suggestions:X.filter(t=>t.startsWith(e)).map(e=>buildTeamArgSuggestion(`team-subcommand-${e}`,e,replaceTeamArgs(`${e} `))),commandArgumentHint:"<subcomando>"}}if("list"===a)return{suggestions:[],commandArgumentHint:void 0};if("create"===a)return{suggestions:[],commandArgumentHint:"<nombre-equipo>"};if("show"===a)return{suggestions:[],commandArgumentHint:"<equipo>"};if("orchestrator"===a)return r.length<=2?{suggestions:[],commandArgumentHint:"<equipo>"}:{suggestions:getProviderAgentRefSuggestions(r[r.length-1]??"",r.slice(0,r.length-1),!1),commandArgumentHint:"<provider/agent>"};if("equipo"===a){if(r.length<=2)return{suggestions:[],commandArgumentHint:"<equipo>"};if(r.length<=3){const e=r[1]??"",t=(r[2]??"").toLowerCase();return{suggestions:Y.filter(e=>e.startsWith(t)).map(t=>buildTeamArgSuggestion(`team-equipo-${t}`,t,replaceTeamArgs(["equipo",e,t,""].join(" ").trimEnd()+" "),`equipo ${t}`)),commandArgumentHint:"<area>"}}return{suggestions:getProviderAgentRefSuggestions(r[r.length-1]??"",r.slice(0,r.length-1),!1),commandArgumentHint:"<provider/agent>"}}if("add-member"===a){if(r.length<=2)return{suggestions:[],commandArgumentHint:"<equipo>"};if(r.length<=3){const e=r[1]??"",t=(r[2]??"").toLowerCase();return{suggestions:Y.filter(e=>e.startsWith(t)).map(t=>buildTeamArgSuggestion(`team-member-equipo-${t}`,t,replaceTeamArgs(["add-member",e,t,""].join(" ").trimEnd()+" "),`equipo ${t}`)),commandArgumentHint:"<area>"}}return r.length<=4?{suggestions:getProviderAgentRefSuggestions(r[3]??"",r.slice(0,3)),commandArgumentHint:"<provider/agent>"}:{suggestions:[],commandArgumentHint:"[duty]"}}return{suggestions:[],commandArgumentHint:void 0}}(e):null;if(i){const{suggestions:e,commandArgumentHint:t}=i;return de(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),ye(e.length>0?"command-arg":"none"),void ke(void 0)}const a="prompt"===ce?function(e){const t=extractCommandNameAndArgs(e);if(!t||"workspace"!==t.commandName)return null;const n=t.args??"",o=/\s$/.test(n),s=n.trim().length>0?n.trim().split(/\s+/):[],r=o?[...s,""]:s,i=r[0]??"",a=i.toLowerCase();if(r.length<=1){const e=i.toLowerCase();return{suggestions:J.filter(t=>t.startsWith(e)).map(e=>buildWorkspaceArgSuggestion(`workspace-subcommand-${e}`,e,replaceWorkspaceArgs(`${e} `))),commandArgumentHint:"<subcomando>"}}if(["show","enable","disable"].includes(a)&&r.length<=2){const e=(r[1]??"").toLowerCase();return{suggestions:ee.filter(t=>t.provider.startsWith(e)).map(e=>buildWorkspaceArgSuggestion(`workspace-provider-${e.provider}`,e.provider,replaceWorkspaceArgs(`${a} ${e.provider}`),e.label)),commandArgumentHint:"<proveedor>"}}if("orchestrator"===a)return{suggestions:[],commandArgumentHint:"[equipo] [provider/agent]"};if("setup"!==a)return{suggestions:[],commandArgumentHint:void 0};if(r.length<=2)return{suggestions:[],commandArgumentHint:"<equipo> [orchestrator=<area|provider/agent>]"};const l=r.length-1,g=r[l]??"",m=r.slice(0,l);if(!m.some(e=>e.toLowerCase().startsWith("orchestrator="))&&"orchestrator=".startsWith(g.toLowerCase()))return{suggestions:[buildWorkspaceArgSuggestion("workspace-orchestrator","orchestrator=",replaceWorkspaceArgs([...m,"orchestrator="].join(" ")),"escoger coordinador principal")],commandArgumentHint:"orchestrator=<area|provider/agent>"};if(g.toLowerCase().startsWith("orchestrator=")){const e=g.slice(13).toLowerCase(),t=Y.filter(t=>t.startsWith(e)).map(e=>buildWorkspaceArgSuggestion(`workspace-orchestrator-equipo-${e}`,e,replaceWorkspaceArgs([...m,`orchestrator=${e} `].join(" ").trimEnd()),`usar el equipo ${e} como orquestador`)),n=[];for(const t of ee)for(const o of Q(t.provider)){const s=`${t.provider}/${o.agentName||`${o.name}-lead`}`;s.toLowerCase().startsWith(e)&&n.push(buildWorkspaceArgSuggestion(`workspace-orchestrator-agent-${o.id}`,s,replaceWorkspaceArgs([...m,`orchestrator=${s} `].join(" ").trimEnd()),`agente de ${t.label}`))}return{suggestions:[...t,...n],commandArgumentHint:"orchestrator=<area|provider/agent>"}}const c=g.indexOf(":");if(c>=0){const e=g.slice(0,c),t=g.slice(c+1).toLowerCase();return{suggestions:Y.filter(e=>e.startsWith(t)).map(t=>buildWorkspaceArgSuggestion(`workspace-equipo-${e}-${t}`,t,replaceWorkspaceArgs([...m,`${e}:${t} `].join(" ").trimEnd()),`equipo ${t}`)),commandArgumentHint:"<proveedor/perfil:area>"}}const u=g.toLowerCase(),d=[];for(const e of ee)for(const t of Q(e.provider)){const n=`${e.provider}/${t.name}`;n.toLowerCase().startsWith(u)&&d.push(buildWorkspaceArgSuggestion(`workspace-profile-${t.id}`,`${n}:`,replaceWorkspaceArgs([...m,`${n}:`].join(" ")),t.lastModel?`${e.label} - ${t.lastModel}`:e.label))}return{suggestions:d,commandArgumentHint:"<proveedor/perfil:area>"}}(e):null;if(a){const{suggestions:e,commandArgumentHint:t}=a;return de(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),ye(e.length>0?"command-arg":"none"),void ke(void 0)}const l="prompt"===ce?function(e){const t=extractCommandNameAndArgs(e);if(!t||!Z.has(t.commandName.toLowerCase()))return null;const n=t.args??"",o=/\s$/.test(n),s=n.trim().length>0?n.trim().split(/\s+/):[],r=o?[...s,""]:s,i=r[0]??"",a=r[1]??"",l=r[2]??"",g=i.toLowerCase(),makeProviderSuggestions=(t,n)=>ee.filter(e=>e.provider.startsWith(t.toLowerCase())).map(t=>buildProfileArgSuggestion(`profile-provider-${t.provider}`,t.provider,replaceProfileArgs(e,[...n,t.provider,""].join(" ").trimEnd()+" "),t.label)),makeProfileSuggestions=(t,n,o)=>t&&ee.some(e=>e.provider===t)?Q(t).filter(e=>e.name.toLowerCase().startsWith(n.toLowerCase())).map(t=>buildProfileArgSuggestion(`profile-name-${t.id}`,t.name,replaceProfileArgs(e,[...o,t.name,""].join(" ").trimEnd()+" "),`${t.agentName}${t.lastModel?` · ${t.lastModel}`:""}`)):[];if(r.length<=1){const t=i.toLowerCase();return{suggestions:U.filter(e=>e.startsWith(t)).map(t=>buildProfileArgSuggestion(`profile-subcommand-${t}`,t,replaceProfileArgs(e,`${t} `))),commandArgumentHint:"<subcomando>"}}if("list"===g||"current"===g||"migrate"===g||"clear"===g||"clear-all"===g)return{suggestions:[],commandArgumentHint:void 0};if(("remove"===g||"clear"===g)&&r.length<=2){const t=a.toLowerCase();return{suggestions:[buildProfileArgSuggestion("profile-remove-all","all",replaceProfileArgs(e,`${g} all`),"Eliminar todos los perfiles"),...makeProviderSuggestions(t,[g])].filter(e=>e.displayText.toLowerCase().startsWith(t)),commandArgumentHint:"<proveedor|all>"}}return["create","use","rename","remove","model","agent"].includes(g)&&r.length<=2?{suggestions:makeProviderSuggestions(a,[g]),commandArgumentHint:"<proveedor>"}:["use","remove","model","agent"].includes(g)&&r.length<=3?{suggestions:makeProfileSuggestions(a,l,[g,a]),commandArgumentHint:"<perfil>"}:"rename"===g&&r.length<=3?{suggestions:makeProfileSuggestions(a,l,[g,a]),commandArgumentHint:"<perfil-actual>"}:{suggestions:[],commandArgumentHint:void 0}}(e):null;if(l){const{suggestions:e,commandArgumentHint:t}=l;return de(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),ye(e.length>0?"command-arg":"none"),void ke(void 0)}const g="prompt"===ce?getProviderCommandSuggestions(e):null;if(g){const{suggestions:e,commandArgumentHint:t}=g;return de(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),ye(e.length>0?"command-arg":"none"),void ke(void 0)}const c="prompt"===ce?function(e){const t=extractCommandNameAndArgs(e);if(!t)return null;const n=t.commandName.toLowerCase();if("playwright"!==n&&"pw"!==n)return null;const o=t.args??"",s=/\s$/.test(o),r=o.trim().length>0?o.trim().split(/\s+/):[],i=s?[...r,""]:r,a=(i[0]??"").toLowerCase(),l=(i[1]??"").toLowerCase();if(i.length<=1)return{suggestions:te.filter(e=>e.name.startsWith(a)).map(e=>buildSlashArgSuggestion(`playwright-sub-${e.name}`,e.name,`/playwright ${e.name} `,e.description)),commandArgumentHint:"[status|browser|visible|headless|reset|help]"};if("browser"===a&&i.length<=2)return{suggestions:ne.filter(e=>e.name.startsWith(l)).map(e=>buildSlashArgSuggestion(`playwright-browser-${e.name}`,e.name,`/playwright browser ${e.name} `,e.description)),commandArgumentHint:"<chromium|chrome|firefox|webkit|msedge>"};return("executable"===a||"device"===a||"viewport"===a)&&i.length<=2&&"clear".startsWith(l)?{suggestions:[buildSlashArgSuggestion(`playwright-${a}-clear`,"clear",`/playwright ${a} clear`,`Quitar ${a} custom`)],commandArgumentHint:"<valor|clear>"}:{suggestions:[],commandArgumentHint:void 0}}(e):null;if(c){const{suggestions:e,commandArgumentHint:t}=c;return de(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),ye(e.length>0?"command-arg":"none"),void ke(void 0)}const u="prompt"===ce?function(e){const t=extractCommandNameAndArgs(e);if(!t)return null;const n=t.commandName.toLowerCase();if("whatsapp"!==n&&"wa"!==n&&"whats"!==n)return null;const o=t.args??"",s=/\s$/.test(o),r=o.trim().length>0?o.trim().split(/\s+/):[],i=s?[...r,""]:r,a=(i[0]??"").toLowerCase(),l=(i[1]??"").toLowerCase();if(i.length<=1)return{suggestions:oe.filter(e=>e.name.startsWith(a)).map(e=>buildSlashArgSuggestion(`whatsapp-sub-${e.name}`,e.name,`/whatsapp ${e.name} `,e.description)),commandArgumentHint:"[status|permitidos|start|stop|global|help]"};if("global"===a&&i.length<=2)return{suggestions:se.filter(e=>e.name.startsWith(l)).map(e=>buildSlashArgSuggestion(`whatsapp-global-${e.name}`,e.name,`/whatsapp global ${e.name} `,e.description)),commandArgumentHint:"<status|start|stop>"};return{suggestions:[],commandArgumentHint:void 0}}(e):null;if(u){const{suggestions:e,commandArgumentHint:t}=u;return de(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),ye(e.length>0?"command-arg":"none"),void ke(void 0)}const d="prompt"===ce?function(e){const t=extractCommandNameAndArgs(e);if(!t)return null;const n=t.commandName.toLowerCase();if("telegram"!==n&&"tg"!==n)return null;const o=t.args??"",s=/\s$/.test(o),r=o.trim().length>0?o.trim().split(/\s+/):[],i=s?[...r,""]:r,a=(i[0]??"").toLowerCase(),l=(i[1]??"").toLowerCase();if(i.length<=1)return{suggestions:re.filter(e=>e.name.startsWith(a)).map(e=>buildSlashArgSuggestion(`telegram-sub-${e.name}`,e.name,`/telegram ${e.name} `,e.description)),commandArgumentHint:"[status|permitidos|global|help]"};if("global"===a&&i.length<=2)return{suggestions:se.filter(e=>e.name.startsWith(l)).map(e=>buildSlashArgSuggestion(`telegram-global-${e.name}`,e.name,`/telegram global ${e.name} `,e.description)),commandArgumentHint:"<status|start|stop>"};return{suggestions:[],commandArgumentHint:void 0}}(e):null;if(d){const{suggestions:e,commandArgumentHint:t}=d;return de(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),ye(e.length>0?"command-arg":"none"),void ke(void 0)}const p="prompt"===ce?function(e){const t=extractCommandNameAndArgs(e);if(!t)return null;const n=t.commandName.toLowerCase();if("webapp"!==n&&"app"!==n&&"pwa"!==n&&"aplicacion-web"!==n)return null;const o=t.args??"",s=/\s$/.test(o),r=o.trim().length>0?o.trim().split(/\s+/):[],i=s?[...r,""]:r,a=(i[0]??"").toLowerCase(),l=(i[1]??"").toLowerCase();if(i.length<=1)return{suggestions:ie.filter(e=>e.name.startsWith(a)).map(e=>buildSlashArgSuggestion(`webapp-sub-${e.name}`,e.name,`/webapp ${e.name} `,e.description)),commandArgumentHint:"[start|stop|status|open|token|port|autostart|help]"};if("token"===a&&i.length<=2)return{suggestions:[{name:"reset",description:"Regenerar token (invalida el anterior)"}].filter(e=>e.name.startsWith(l)).map(e=>buildSlashArgSuggestion(`webapp-token-${e.name}`,e.name,`/webapp token ${e.name} `,e.description)),commandArgumentHint:"[reset]"};return{suggestions:[],commandArgumentHint:void 0}}(e):null;if(p){const{suggestions:e,commandArgumentHint:t}=p;return de(()=>({commandArgumentHint:t,suggestions:e,selectedSuggestion:e.length>0?0:-1})),ye(e.length>0?"command-arg":"none"),void ke(void 0)}if("bash"!==ce&&L(e)&&n>0&&!r){const t=e.slice(1).toLowerCase();if(!function(e,t){return!e&&t.includes(" ")&&!t.endsWith(" ")}(r,e)){const e=_.filter(e=>!e.isHidden).filter(e=>m(e).startsWith(t)||(e.aliases??[]).some(e=>e.startsWith(t))).map(e=>({id:m(e),displayText:`/${m(e)}`,description:e.description??"",metadata:e}));return de(t=>({commandArgumentHint:void 0,suggestions:e,selectedSuggestion:getPreservedSelection(t.suggestions,t.selectedSuggestion,e)})),ye(e.length>0?"command":"none"),void ke(e.length>0?Ce:void 0)}}if(s){const t=extractCompletionToken(e,n,!0);if(t){const e=t.token.startsWith("@"),n=e?t.token.substring(1):t.token;return void ze(n,e)}}ze.cancel(),Ee()},[ce,ve,_,Ee,ze,de,Ce,Fe,$e]);n(()=>{Oe.current!==ge&&(De.current!==ge&&(De.current=ge,Qe.current=null),Oe.current=null,Ke(ge))},[ge,Ke]);const Be=t(async()=>{if(Me){if("bash"===ce)return z(Me.fullCommand),F(Me.fullCommand.length),void Ne(void 0);const e=T(ge,me);if(e){const t=ge.slice(0,e.startPos),n=ge.slice(e.startPos+e.token.length),o=t+"/"+Me.fullCommand+" "+n,s=e.startPos+1+Me.fullCommand.length+1;return z(o),void F(s)}}if(pe.length>0){ze.cancel(),Fe.cancel();const e=-1===fe?0:fe,t=pe[e];if("command"===$e&&e<pe.length)t&&(P(t,!1,_,z,F,G),Ee());else if("command-arg"===$e&&e<pe.length)t&&(applyCommandArgSuggestion(t,z,F),Ee());else if("custom-title"===$e&&pe.length>0){if(t){const e=buildResumeInputFromSuggestion(t);z(e),F(e.length),Ee()}}else if("directory"===$e&&pe.length>0){const t=pe[e];if(t){let e;if(L(ge)){const n=ge.indexOf(" "),o=ge.slice(0,n+1),s=isPathMetadata(t.metadata)&&"directory"===t.metadata.type?"/":" ";e=o+t.id+s,z(e),F(e.length),isPathMetadata(t.metadata)&&"directory"===t.metadata.type?(de(e=>({...e,commandArgumentHint:void 0})),Ke(e,e.length)):Ee()}else{const n=extractCompletionToken(ge,me,!0)??extractCompletionToken(ge,me,!1);if(n){const o=isPathMetadata(t.metadata)&&"directory"===t.metadata.type,s=applyDirectorySuggestion(ge,t.id,n.startPos,n.token.length,o);e=s.newInput,z(e),F(s.cursorPos),o?(de(e=>({...e,commandArgumentHint:void 0})),Ke(e,s.cursorPos)):Ee()}else Ee()}}}else if("shell"===$e&&pe.length>0){const t=pe[e];if(t){const e=t.metadata;applyShellSuggestion(t,ge,me,z,F,e?.completionType),Ee()}}else if("agent"===$e&&pe.length>0&&pe[e]?.id?.startsWith("dm-")){const t=pe[e];t&&(applyTriggerSuggestion(t,ge,me,ae,z,F),Ee())}else if("slack-channel"===$e&&pe.length>0){const t=pe[e];t&&(applyTriggerSuggestion(t,ge,me,B,z,F),Ee())}else if("file"===$e&&pe.length>0){const t=extractCompletionToken(ge,me,!0);if(!t)return void Ee();const n=R(pe),o=t.token.startsWith("@");let s;if(s=t.isQuoted?t.token.slice(2).replace(/"$/,"").length:o?t.token.length-1:t.token.length,n.length>s){const e=formatReplacementValue({displayText:n,mode:ce,hasAtPrefix:o,needsQuotes:!1,isQuoted:t.isQuoted,isComplete:!1});D(e,ge,t.token,t.startPos,z,F),Ke(ge.replace(t.token,e),me)}else if(e<pe.length){const n=pe[e];if(n){const e=n.displayText.includes(" "),s=formatReplacementValue({displayText:n.displayText,mode:ce,hasAtPrefix:o,needsQuotes:e,isQuoted:t.isQuoted,isComplete:!0});D(s,ge,t.token,t.startPos,z,F),Ee()}}}}else if(""!==ge.trim()){let e,t;if("bash"===ce){e="shell";const n=await async function(e,t){try{return le&&le.abort(),le=new AbortController,await C(e,t,le.signal)}catch{return l("tengu_shell_completion_failed",{}),[]}}(ge,me);if(1===n.length){const e=n[0];if(e){const t=e.metadata;applyShellSuggestion(e,ge,me,z,F,t?.completionType)}t=[]}else t=n}else{e="file";const n=extractCompletionToken(ge,me,!0);if(n){const e=n.token.startsWith("@"),o=e?n.token.substring(1):n.token;t=await E(o,He,ue,e)}else t=[]}t.length>0&&(de(e=>({commandArgumentHint:void 0,suggestions:t,selectedSuggestion:getPreservedSelection(e.suggestions,e.selectedSuggestion,t)})),ye(e),ke(void 0))}},[pe,fe,ge,$e,_,ce,z,F,G,Ee,me,Ke,He,de,ue,ze,Fe,Me]),Ue=t(()=>{if(fe<0||0===pe.length)return;const e=pe[fe];if("command"===$e&&fe<pe.length)e&&(P(e,!0,_,z,F,G),ze.cancel(),Ee());else if("command-arg"===$e&&fe<pe.length){if(e){const t=e.metadata;if((t?.replacement??e.displayText).trim()===ge.trim())return ze.cancel(),Ee(),void G(ge,!0);applyCommandArgSuggestion(e,z,F),ze.cancel(),Ee()}}else if("custom-title"===$e&&fe<pe.length){if(e){const t=buildResumeInputFromSuggestion(e);z(t),F(t.length),G(t,!0),ze.cancel(),Ee()}}else if("shell"===$e&&fe<pe.length){const e=pe[fe];if(e){const t=e.metadata;applyShellSuggestion(e,ge,me,z,F,t?.completionType),ze.cancel(),Ee()}}else if("agent"===$e&&fe<pe.length&&e?.id?.startsWith("dm-"))applyTriggerSuggestion(e,ge,me,ae,z,F),ze.cancel(),Ee();else if("slack-channel"===$e&&fe<pe.length)e&&(applyTriggerSuggestion(e,ge,me,B,z,F),Fe.cancel(),Ee());else if("file"===$e&&fe<pe.length){const t=extractCompletionToken(ge,me,!0);if(t&&e){const n=t.token.startsWith("@"),o=e.displayText.includes(" "),s=formatReplacementValue({displayText:e.displayText,mode:ce,hasAtPrefix:n,needsQuotes:o,isQuoted:t.isQuoted,isComplete:!0});D(s,ge,t.token,t.startPos,z,F),ze.cancel(),Ee()}}else if("directory"===$e&&fe<pe.length&&e){if(L(ge))return ze.cancel(),void Ee();const t=extractCompletionToken(ge,me,!0)??extractCompletionToken(ge,me,!1);if(t){const n=isPathMetadata(e.metadata)&&"directory"===e.metadata.type,o=applyDirectorySuggestion(ge,e.id,t.startPos,t.token.length,n);z(o.newInput),F(o.cursorPos)}ze.cancel(),Ee()}},[pe,fe,$e,_,ge,me,ce,z,F,G,Ee,ze,Fe]),Ze=t(()=>{Be()},[Be]),Je=t(()=>{ze.cancel(),Fe.cancel(),Ee(),Oe.current=ge},[ze,Fe,Ee,ge]),Xe=t(()=>{de(e=>({...e,selectedSuggestion:e.selectedSuggestion<=0?pe.length-1:e.selectedSuggestion-1}))},[pe.length,de]),Ye=t(()=>{de(e=>({...e,selectedSuggestion:e.selectedSuggestion>=pe.length-1?0:e.selectedSuggestion+1}))},[pe.length,de]),et=o(()=>({"autocomplete:accept":Ze,"autocomplete:dismiss":Je,"autocomplete:previous":Xe,"autocomplete:next":Ye}),[Ze,Je,Xe,Ye]),tt=pe.length>0||!!Me,nt=d();function acceptSuggestionText(e){const t=c(e);if("prompt"!==t&&be){be(t);const n=u(e);z(n),F(n.length)}else z(e),F(e.length)}p("autocomplete",tt),A("Autocomplete",tt),b(et,{context:"Autocomplete",isActive:tt&&!nt});const handleKeyDown=t=>{if("right"===t.key&&!We){const e=Te.text,n=Te.shownAt;if(e&&n>0&&""===ge)return Ae(),acceptSuggestionText(e),void t.stopImmediatePropagation()}if("tab"===t.key&&!t.shift){if(pe.length>0||Me)return;const n=Te.text,o=Te.shownAt;return n&&o>0&&""===ge&&!We?(t.preventDefault(),Ae(),void acceptSuggestionText(n)):void(""===ge.trim()&&(t.preventDefault(),Se({key:"thinking-toggle-hint",jsx:e(a,{dimColor:!0,children:["Usa ",we," para alternar el modo de razonamiento"]}),priority:"immediate",timeoutMs:3e3})))}if(0===pe.length)return;const n=null!=Le?.pendingChord;return t.ctrl&&"n"===t.key&&!n?(t.preventDefault(),void Ye()):t.ctrl&&"p"===t.key&&!n?(t.preventDefault(),void Xe()):void("return"!==t.key||t.shift||t.meta||(t.preventDefault(),Ue()))};return h((e,t,n)=>{const o=new f(n.keypress);handleKeyDown(o),o.didStopImmediatePropagation()&&n.stopImmediatePropagation()}),{suggestions:pe,selectedSuggestion:fe,suggestionType:$e,maxColumnWidth:xe,commandArgumentHint:he,inlineGhostText:Me,handleKeyDown}}