@redocly/replay 0.28.0-next.4 → 0.28.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{replay-AiChatProvider-BIplPHOS.js → replay-AiChatProvider-Bj2P_hdU.js} +371 -369
- package/dist/replay-AiChatProvider-GeumgtIo.js +6 -0
- package/dist/{replay-AiChatSqliteDBStorage-Bay95FHW.js → replay-AiChatSqliteDBStorage-0M2Ejnzu.js} +1 -1
- package/dist/{replay-AiChatSqliteDBStorage-C-rkQ3jG.js → replay-AiChatSqliteDBStorage-BWJl1qdO.js} +1 -1
- package/dist/{replay-AiPanel-DU5aVA3q.js → replay-AiPanel-DfOpKMDQ.js} +709 -712
- package/dist/replay-AiPanel-ON_QfwBN.js +742 -0
- package/dist/replay-FileWatcher-04GlEkra.js +360 -0
- package/dist/replay-FileWatcher-B-T0jz_R.js +1 -0
- package/dist/{replay-SemanticSearchService-Dk4UTm2r.js → replay-SemanticSearchService-BQgdj2wy.js} +1 -1
- package/dist/{replay-SemanticSearchService-BWwCFW3F.js → replay-SemanticSearchService-CPIb_cUk.js} +7 -7
- package/dist/{replay-SqliteDBStorage-BFdjYsG7.js → replay-SqliteDBStorage-Bt2xXqei.js} +1 -1
- package/dist/{replay-SqliteDBStorage-DGQjzDy4.js → replay-SqliteDBStorage-vehgvWXZ.js} +1 -1
- package/dist/{replay-TauriFileSystemAdapter-CLzYSck7.js → replay-TauriFileSystemAdapter-D2yxrS6Q.js} +1 -1
- package/dist/{replay-TauriFileSystemAdapter-C8k9RvT1.js → replay-TauriFileSystemAdapter-YLdtT-Xp.js} +1 -1
- package/dist/{replay-TauriRootStorage-C1MIH5ji.js → replay-TauriRootStorage-BE6RmQfE.js} +162 -165
- package/dist/replay-TauriRootStorage-DcENVsBJ.js +1 -0
- package/dist/{replay-agent-loop-BoEw65rR.js → replay-agent-loop-CvopOugZ.js} +13 -13
- package/dist/{replay-agent-loop-Cm1iS9G2.js → replay-agent-loop-UwDSVh-4.js} +1 -1
- package/dist/{replay-ai-chat-mappers-IZNFNXug.js → replay-ai-chat-mappers-B7fm-v_w.js} +1 -1
- package/dist/{replay-ai-chat-mappers-Csm9vJrG.js → replay-ai-chat-mappers-yKBypIXh.js} +1 -1
- package/dist/{replay-create-model-BqvD-0wF.js → replay-create-model-CHahxEJy.js} +3 -3
- package/dist/{replay-create-model-Y9UJSztb.js → replay-create-model-CyBZMAWB.js} +4 -4
- package/dist/{replay-db-BImXgUGU.js → replay-db-CifZMdnr.js} +5 -5
- package/dist/{replay-db-C7FD3opa.js → replay-db-EWL-uAt-.js} +1 -1
- package/dist/{replay-external-resolver-CjM7Da6t.js → replay-external-resolver-D5fSfJEm.js} +1 -1
- package/dist/{replay-external-resolver-Bj3sLTnz.js → replay-external-resolver-G11iwLVZ.js} +2 -2
- package/dist/{replay-index-Dxk-kqkZ.js → replay-index-B2NUTBd8.js} +1 -1
- package/dist/{replay-index-CKRKzXMt.js → replay-index-B3MQaIS-.js} +1 -1
- package/dist/replay-index-Coy4kD_x.js +7009 -0
- package/dist/{replay-index-DJwfdo0s.js → replay-index-CqRiEj9e.js} +1 -1
- package/dist/{replay-index-DlTloE6S.js → replay-index-D0mbH_TN.js} +1 -1
- package/dist/{replay-index-Cp06WK82.js → replay-index-DDqKE6bs.js} +5 -5
- package/dist/{replay-index-xheWgsnj.js → replay-index-DrI9ZFwH.js} +2 -2
- package/dist/{replay-index-BH8cTSEK.js → replay-index-Dx8O3ZoA.js} +68783 -67874
- package/dist/{replay-lint-BIbkYU09.js → replay-lint-BiOcDIDr.js} +3 -3
- package/dist/{replay-lint--iBW-6Vj.js → replay-lint-CAo2fuiZ.js} +3 -3
- package/dist/{replay-lint-graphql-EXBI8I89.js → replay-lint-graphql-DAa8UNRg.js} +1 -1
- package/dist/{replay-lint-graphql-2b4GIER6.js → replay-lint-graphql-DzI2rUbR.js} +1 -1
- package/dist/replay-periodic-revalidation-D18ihfUc.js +1 -0
- package/dist/replay-periodic-revalidation-w7mrtjYg.js +22 -0
- package/dist/{replay-resolve-D9BUvjqv.js → replay-resolve-CojDRP37.js} +1 -1
- package/dist/{replay-resolve-B5yIfyuT.js → replay-resolve-DgAthAfi.js} +1 -1
- package/dist/{replay-respect-run-DNFoFnJU.js → replay-respect-run-3ukV7LMg.js} +1 -1
- package/dist/{replay-respect-run-Bx46aUHi.js → replay-respect-run-DNvB8rLX.js} +3 -3
- package/dist/replay-tauri-path-DM8PdMK8.js +22 -0
- package/dist/{replay-tauri-path-C8GiFO5s.js → replay-tauri-path-kr9DtxLs.js} +1 -1
- package/dist/{replay-useAiChatQueries-BTuu2xLG.js → replay-useAiChatQueries-BULoKr4E.js} +1564 -1395
- package/dist/replay-useAiChatQueries-BdjsFz1P.js +215 -0
- package/dist/{replay-validate-key-D4M7QvCw.js → replay-validate-key-CGmguj5X.js} +1 -1
- package/dist/{replay-validate-key-CjcIElmE.js → replay-validate-key-DzseOR5a.js} +2 -2
- package/dist/replay.cjs +1 -1
- package/dist/replay.d.ts +3 -3
- package/dist/replay.js +10 -10
- package/package.json +12 -5
- package/dist/replay-AiChatProvider-TF1u9E5L.js +0 -6
- package/dist/replay-AiPanel-DzGN1t86.js +0 -742
- package/dist/replay-FileWatcher-XMkIoDEA.js +0 -1
- package/dist/replay-FileWatcher-iYbHpwCv.js +0 -352
- package/dist/replay-TauriRootStorage-CiGY8MO6.js +0 -1
- package/dist/replay-index-BuYoH96w.js +0 -6982
- package/dist/replay-periodic-revalidation-BoyLQHtg.js +0 -1
- package/dist/replay-periodic-revalidation-Dsp-n7ui.js +0 -21
- package/dist/replay-tauri-path-BVoW6En0.js +0 -22
- package/dist/replay-useAiChatQueries-BDgjmzz-.js +0 -215
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("react/jsx-runtime"),i=require("react"),a=require("./replay-index-BuYoH96w.js"),te=require("./replay-create-model-BqvD-0wF.js"),pe=require("./replay-agent-loop-Cm1iS9G2.js"),ge=require("./replay-db-C7FD3opa.js"),m=require("./replay-useAiChatQueries-BDgjmzz-.js"),F=require("@tanstack/react-query"),Z=require("./replay-ai-chat-mappers-IZNFNXug.js");class Ce{handlers=new Map;middlewares;constructor(t){this.middlewares=t?.middlewares??[]}register(t){this.handlers.set(t.name,t)}getToolSet(){const t={};for(const[n,s]of this.handlers)t[n]=this.buildTool(s);return t}buildTool(t){return{...t.definition,execute:this.wrapExecutor(t)}}wrapExecutor(t){const n=(o,r)=>({isError:!0,error:{message:o,details:r}}),s=this.applyMiddlewares(t.name,t.execute);return(o,r)=>{if(r.abortSignal?.aborted)return n("Tool execution was aborted.");try{const l=s(o,r);return typeof l=="object"&&l!==null&&"then"in l?l.then(c=>c,c=>n(c instanceof Error?c.message:"Unknown tool execution error")):l}catch(l){return n(l instanceof Error?l.message:"Unknown tool execution error")}}}applyMiddlewares(t,n){return this.middlewares.length===0?n:this.middlewares.reduceRight((s,o)=>o(t,s),n)}}function ue(){const e=F.useQueryClient();return F.useMutation({async mutationFn(t){const n=Z.buildPersistableUiChat(t);await a.AiChatServiceFactory.getInstance().upsert(n)},onSuccess(){e.invalidateQueries({queryKey:a.aiChatKeys.all()})},onError(t){console.error("Failed to upsert ai chat item:",t)}})}function me(e){const t=F.useQueryClient(),n=a.aiChatKeys.detailTitle(e??"");return F.useMutation({mutationKey:n,async mutationFn(s){if(t.isMutating({mutationKey:n,exact:!0})>1)return;const o=Z.buildPersistableUiChat(s);await a.AiChatServiceFactory.getInstance().upsert(o)},onSuccess(){t.invalidateQueries({queryKey:a.aiChatKeys.all()})},onError(s){console.error("Failed to upsert ai chat item:",s)}})}function ve(){const e=F.useQueryClient();return F.useMutation({async mutationFn(t){await a.AiChatServiceFactory.getInstance().remove(t)},onMutate:async t=>{await e.cancelQueries({queryKey:a.aiChatKeys.all()});const n=e.getQueryData(a.aiChatKeys.all());n&&e.setQueryData(a.aiChatKeys.all(),n.filter(s=>s.id!==t)),e.setQueryData(a.aiChatKeys.detail(t),null),e.setQueriesData({queryKey:a.aiChatKeys.infiniteHistories()},s=>s&&{...s,pages:s.pages.map(o=>({...o,items:o.items.filter(r=>r.id!==t)}))})},onError(t){console.error("Failed to remove ai chat:",t)},onSettled(){e.invalidateQueries({queryKey:a.aiChatKeys.all()})}})}var ee,ae;function we(){if(ae)return ee;ae=1;function e(t,n){if(typeof t!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof t}\`.`);let s,o=0;return function(...l){clearTimeout(s);const c=Date.now(),u=c-o,h=n-u;h<=0?(o=c,t.apply(this,l)):s=setTimeout(()=>{o=Date.now(),t.apply(this,l)},h)}}return ee=e,ee}var Ie=we();const Te=a.getDefaultExportFromCjs(Ie);var de=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},f=(e,t,n)=>(de(e,t,"read from private field"),n?n.call(e):t.get(e)),b=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},M=(e,t,n,s)=>(de(e,t,"write to private field"),t.set(e,n),n);function ye(e,t){return t!=null?Te(e,t):e}var w,Y,J,j,Q,V,B,ne,se,be=class{constructor(e=[]){b(this,w,void 0),b(this,Y,"ready"),b(this,J,void 0),b(this,j,new Set),b(this,Q,new Set),b(this,V,new Set),this.pushMessage=t=>{M(this,w,f(this,w).concat(t)),f(this,B).call(this)},this.popMessage=()=>{M(this,w,f(this,w).slice(0,-1)),f(this,B).call(this)},this.replaceMessage=(t,n)=>{M(this,w,[...f(this,w).slice(0,t),this.snapshot(n),...f(this,w).slice(t+1)]),f(this,B).call(this)},this.snapshot=t=>structuredClone(t),this["~registerMessagesCallback"]=(t,n)=>{const s=n?ye(t,n):t;return f(this,j).add(s),()=>{f(this,j).delete(s)}},this["~registerStatusCallback"]=t=>(f(this,Q).add(t),()=>{f(this,Q).delete(t)}),this["~registerErrorCallback"]=t=>(f(this,V).add(t),()=>{f(this,V).delete(t)}),b(this,B,()=>{f(this,j).forEach(t=>t())}),b(this,ne,()=>{f(this,Q).forEach(t=>t())}),b(this,se,()=>{f(this,V).forEach(t=>t())}),M(this,w,e)}get status(){return f(this,Y)}set status(e){M(this,Y,e),f(this,ne).call(this)}get error(){return f(this,J)}set error(e){M(this,J,e),f(this,se).call(this)}get messages(){return f(this,w)}set messages(e){M(this,w,[...e]),f(this,B).call(this)}};w=new WeakMap;Y=new WeakMap;J=new WeakMap;j=new WeakMap;Q=new WeakMap;V=new WeakMap;B=new WeakMap;ne=new WeakMap;se=new WeakMap;var L,ie=class extends te.AbstractChat{constructor({messages:e,...t}){const n=new be(e);super({...t,state:n}),b(this,L,void 0),this["~registerMessagesCallback"]=(s,o)=>f(this,L)["~registerMessagesCallback"](s,o),this["~registerStatusCallback"]=s=>f(this,L)["~registerStatusCallback"](s),this["~registerErrorCallback"]=s=>f(this,L)["~registerErrorCallback"](s),M(this,L,n)}};L=new WeakMap;function Se({experimental_throttle:e,resume:t=!1,...n}={}){const s=i.useRef("chat"in n?{}:{onToolCall:n.onToolCall,onData:n.onData,onFinish:n.onFinish,onError:n.onError,sendAutomaticallyWhen:n.sendAutomaticallyWhen});"chat"in n||(s.current={onToolCall:n.onToolCall,onData:n.onData,onFinish:n.onFinish,onError:n.onError,sendAutomaticallyWhen:n.sendAutomaticallyWhen});const o={...n,onToolCall:d=>{var g,p;return(p=(g=s.current).onToolCall)==null?void 0:p.call(g,d)},onData:d=>{var g,p;return(p=(g=s.current).onData)==null?void 0:p.call(g,d)},onFinish:d=>{var g,p;return(p=(g=s.current).onFinish)==null?void 0:p.call(g,d)},onError:d=>{var g,p;return(p=(g=s.current).onError)==null?void 0:p.call(g,d)},sendAutomaticallyWhen:d=>{var g,p,R;return(R=(p=(g=s.current).sendAutomaticallyWhen)==null?void 0:p.call(g,d))!=null?R:!1}},r=i.useRef("chat"in n?n.chat:new ie(o));("chat"in n&&n.chat!==r.current||"id"in n&&n.id!=null&&r.current.id!==n.id)&&(r.current="chat"in n?n.chat:new ie(o));const c=i.useCallback(d=>r.current["~registerMessagesCallback"](d,e),[e,r.current.id]),u=i.useSyncExternalStore(c,()=>r.current.messages,()=>r.current.messages),h=i.useSyncExternalStore(r.current["~registerStatusCallback"],()=>r.current.status,()=>r.current.status),I=i.useSyncExternalStore(r.current["~registerErrorCallback"],()=>r.current.error,()=>r.current.error),T=i.useCallback(d=>{typeof d=="function"&&(d=d(r.current.messages)),r.current.messages=d},[r]);return i.useEffect(()=>{t&&r.current.resumeStream()},[t,r]),{id:r.current.id,messages:u,setMessages:T,sendMessage:r.current.sendMessage,regenerate:r.current.regenerate,clearError:r.current.clearError,stop:r.current.stop,error:I,resumeStream:r.current.resumeStream,status:h,addToolResult:r.current.addToolOutput,addToolOutput:r.current.addToolOutput,addToolApprovalResponse:r.current.addToolApprovalResponse}}const Ae=20;function ke(e){if(e.length===0)return"No OpenAPI specs loaded.";const t=e.slice(0,Ae),n=t.map(Ee),s=e.length-t.length;return s>0&&n.push(` …and ${s} more API(s) not shown.`),[`Loaded APIs (${e.length}):`,...n].join(`
|
|
2
|
-
`)}function Ee(e){return[` apiId="${e.apiId}"`,`title="${e.title}"`,e.version?`version="${e.version}"`:null,e.primaryServer?`server="${e.primaryServer}"`:null].filter(Boolean).join(" ")}const Me=30;function Re(e){if(e.length===0)return"No Arazzo collections loaded.";const t=[`Arazzo collections (${e.length}):`];let n=Me,s=0,o=0;for(const l of e){if(n<=0){s+=l.workflows.length,o++;continue}if(t.push(_e(l)),n--,l.workflows.length===0)t.push(" (no workflows)");else if(n>=2){t.push(` workflows (${l.workflows.length}):`),n--;for(const c of l.workflows)n>0?(t.push(` ${xe(c)}`),n--):s++}else s+=l.workflows.length}const r=[s>0?`${s} more workflow(s)`:null,o>0?`${o} more collection(s)`:null].filter(Boolean);return r.length>0&&t.push(` …and ${r.join(", plus ")} not shown.`),t.join(`
|
|
3
|
-
`)}function _e(e){const t=e.sourceApiIds.length>0?` apis=[${e.sourceApiIds.join(", ")}]`:"";return` collectionId="${e.collectionId}" title="${e.title}"${t}`}function xe(e){const t=`id="${e.workflowId}"`,n=e.summary?`label="${e.summary}"`:null,s=`[${e.stepCount} step${e.stepCount!==1?"s":""}]`;return[t,n,s].filter(Boolean).join(" ")}const Pe=20;function De(e){if(e.length===0)return"No environments configured.";const t=e.slice(0,Pe),n=t.map($e),s=e.length-t.length;return s>0&&n.push(` …and ${s} more environment(s) not shown.`),[`Environments (${e.length}); * marks the active environment:`,...n].join(`
|
|
4
|
-
`)}function $e(e){return[`${e.isActive?"*":" "} name="${e.name}"`,`inputs=${e.inputCount}`,`servers=${e.serverCount}`].join(" ")}const Oe=30;function We(e){if(e.length===0)return"No tabs are open.";const t=e.slice(0,Oe),n=t.map(Ue),s=e.length-t.length;return s>0&&n.push(` …and ${s} more tab(s) not shown.`),[`Open tabs (${e.length}), listed by tabIndex; * marks the active (focused) tab:`,...n].join(`
|
|
5
|
-
`)}function Ue(e){const t=[e.collectionId?`collectionId="${e.collectionId}"`:null,e.workflowId?`workflowId="${e.workflowId}"`:null,e.stepId?`stepId="${e.stepId}"`:null,e.operationId?`operationId="${e.operationId}"`:null].filter(Boolean),n=[e.isPreview?"preview":null,e.isDraft?"draft":null,e.isHistory?"history":null].filter(Boolean);return[`${e.isActive?"*":" "} ${e.tabIndex}.`,`type="${e.type}"`,`label="${e.label}"`,...t,n.length>0?`(${n.join(", ")})`:null].filter(Boolean).join(" ")}const Be="Auto-attached snapshot of the user's current Replay UI state. Generated by Replay before each step; not written by the user. It is a shallow summary — use tools to read detailed tab contents when needed.";function Le(e){const t=`
|
|
6
|
-
`.repeat(2),n=[Be,t,We(e.tabs),t,ke(e.apis),t,Re(e.collections),t,De(e.environments)].join("");return ge.section("active_state",n)}function Fe(e){return e.apis.get({noproxy:!0}).map(Ne)}function Ne(e){return{apiId:e.id,title:e.info?.title??"Untitled API",version:e.info?.version,primaryServer:e.servers?.[0]?.url}}function qe(e){return e.collections.get({noproxy:!0}).map(Ke)}function Ke(e){const t=(e.workflows??[]).map(s=>({workflowId:s.workflowId,summary:s.summary,stepCount:s.steps?.length??0})),n=(e.sourceDescriptions??[]).map(s=>s.apiId).filter(Boolean);return{collectionId:e.id,title:e.info?.title??"Untitled Collection",workflows:t,sourceApiIds:n}}function je(e){const t=e.environments.get({noproxy:!0}),n=e.activeEnvironmentId.get({noproxy:!0});return t.filter(s=>s.state!==a.ItemState.Draft).map(s=>({name:s.name,isActive:s.name===n,inputCount:s.inputs.length,serverCount:s.servers.length}))}function Qe(e){const t=e.tabsState.tabs.get({noproxy:!0}),n=e.tabsState.activeTabIdx.get({noproxy:!0});return t.map((s,o)=>Ve(e,s,o,o===n))}function Ve(e,t,n,s){const o={tabIndex:n,type:t.data.type,isActive:s,isPreview:t.state===a.TabState.Preview};switch(t.data.type){case a.TabDataType.Collection:{const{collectionId:r}=t.data;return{...o,label:Ge(e,r)??r,collectionId:r}}case a.TabDataType.Workflow:{const{collectionId:r,workflowId:l}=t.data;return{...o,label:l,collectionId:r,workflowId:l}}case a.TabDataType.WorkflowRun:{const{collectionId:r,workflowId:l,historyId:c,label:u}=t.data;return{...o,label:u??`${l} run`,collectionId:r,workflowId:l,isHistory:c!=null}}case a.TabDataType.Step:{const r=t.data;return{...o,label:He(r),collectionId:r.collectionId,workflowId:r.workflowId,stepId:r.stepId,operationId:r.draftStep?.operation?.operationId??null,isDraft:!r.collectionId&&!r.workflowId,isHistory:r.historyId!=null}}}}function Ge(e,t){return e.collections.find(s=>s.id.get()===t)?.info.title.get()}function He(e){if(e.stepId)return e.stepId;if(e.draftStep){const t=[a.getStepMethod(e.draftStep),a.getStepUrl(e.draftStep)].filter(Boolean).join(" ");if(t)return t}return"New Request"}function ze(e){return{tabs:Qe(e),apis:Fe(e),collections:qe(e),environments:je(e)}}function Ye(){const{getCollection:e}=a.useCollections(),{getWorkflow:t}=a.useWorkflows(),{getStep:n}=a.useSteps(),{tab:s}=a.useActiveTab(),o=s?.data.get();return i.useMemo(()=>{if(!o)return null;switch(o.type){case a.TabDataType.Collection:const l=e(o.collectionId);return{...o,collection:l?l.get():null};case a.TabDataType.Workflow:const c=t({collectionId:o.collectionId,workflowId:o.workflowId});return{...o,workflow:c?c.get():null};case a.TabDataType.Step:const u=n({collectionId:o.collectionId,workflowId:o.workflowId,stepId:o.stepId});return{...o,step:u?u.get():null};case a.TabDataType.WorkflowRun:const h=t({collectionId:o.collectionId,workflowId:o.workflowId});return{...o,workflow:h?h.get():null}}},[o,e,t,n])}function Je(e){if(!e||typeof e!="object"||!("changes"in e)||!Array.isArray(e.changes))return e;const t=e.changes.filter(s=>s&&typeof s=="object"&&"approved"in s&&s.approved===!0),n="meta"in e&&typeof e.meta=="object"?e.meta:{};return{...e,changes:t,meta:{...n,totalChanges:e.changes.length,approvedChanges:t.length}}}function Xe(){return(e,t)=>(n,s)=>t(Je(n),s)}function Ze(){const{getApiOperation:e}=a.useApiOperation(),t=a.useTabHandlers();return i.useMemo(()=>({getApiOperation:e,...t}),[e,t])}function et(e){const{convertOperationToReplayValue:t}=a.useSettingsContext(),n=Ye(),s=Ze(),o=a.useSettingsState(),r=a.useGlobalStore(),{attachApiToCollection:l}=a.useCollections(),{handleCloseByDataId:c}=a.useTabHandlers(),u=a.useRunWorkflow(),h=i.useRef(n);return h.current=n,{tools:i.useMemo(()=>{const T=new Ce({middlewares:[Xe()]});return m.registerBuiltInTools(T,{[m.reportStatusBlueprint.name]:void 0,[m.runRequestBlueprint.name]:{store:r,settingsState:o},[m.runWorkflowBlueprint.name]:{store:r,runWorkflow:u},[m.updateSecurityBlueprint.name]:{store:r},[m.updateStepBlueprint.name]:{store:r},[m.manageCollectionBlueprint.name]:{store:r,attachApiToCollection:l,handleCloseByDataId:c,convertOperationToReplayValue:t},[m.manageEnvironmentBlueprint.name]:{store:r},[m.webSearchBlueprint.name]:{model:e},[m.searchBlueprint.name]:{store:r},[m.openTabBlueprint.name]:{store:r,context:s},[m.getCurrentTabBlueprint.name]:{getActiveTabDetailedData:()=>h.current},[m.getApiMetadataBlueprint.name]:{store:r}}),T.getToolSet()},[l,t,c,e,s,u,o,r])}}function tt(e){const{children:t,chatId:n,model:s,initialMessages:o,onChatFinish:r,onChatMessagesUpdated:l}=e,c=a.useSettingsState(),{getReuniteAuth:u}=a.useSettingsContext(),{tools:h}=et(s),{sendEvent:I}=a.useTelemetry(),T=i.useRef(h),d=i.useRef(s),{isOpen:g,openPanel:p,closePanel:R}=a.useAiPanel(),_=i.useRef(void 0),N=a.useGlobalStore(),S=i.useRef(N);T.current=h,d.current=s,S.current=N;const v=i.useMemo(()=>{_.current?.end();const k=a.trace.getTracer("replay-ai-chat").startSpan("ai.chat.session",{attributes:{conversation_id:n}});_.current=k;const E=a.trace.setSpan(a.context.active(),k);return new pe.AgentLoop({activeConversationId:n,model:d.current,tools:T.current,sendEvent:I,parentCtx:E,getActiveStateMessage:()=>Le(ze(S.current))})},[n,I]);i.useEffect(()=>()=>_.current?.end(),[]);const W=i.useMemo(()=>{if(v)return new te.DirectChatTransport({agent:v.getAgent()})},[v]);i.useEffect(()=>{v.setModel(s)},[v,s]),i.useEffect(()=>{v.registerTools(h)},[v,h]);const{messages:A,setMessages:x,sendMessage:q,status:P,error:G,stop:D,addToolApprovalResponse:$}=Se({id:n,messages:o,transport:W,sendAutomaticallyWhen:te.lastAssistantMessageIsCompleteWithApprovalResponses,onFinish(k){if(!r||!v)return;r({agentLoop:v,chat:this},k)}}),O=i.useMemo(()=>P==="streaming"||P==="submitted",[P]),K=i.useCallback(()=>{c.aiEnabled.get()===!0&&p()},[p,c.aiEnabled]),H=i.useCallback(()=>{R()},[R]),C=i.useCallback(async k=>{const E=k.trim();if(!(!E||!W)){if(s.provider===a.REUNITE_AI_PROVIDER){const y=await u?.();y?.baseUrl&&y?.accessToken&&v.setModel({provider:a.REUNITE_AI_PROVIDER,baseUrl:y.baseUrl,accessToken:y.accessToken})}x(y=>m.hasPendingApprovalMessage(y)?m.denyPendingApprovals(y):y),q({text:E})}},[v,u,s.provider,q,x,W]),U=i.useCallback(()=>{O&&D()},[O,D]);i.useEffect(()=>()=>{D()},[n,D]);const re=i.useCallback(k=>{const E=k(A),y=E.map(z=>z.message),oe=[...A];for(const z of E)oe[z.index]=z.message;x(oe),l?.(y)},[A,l,x]),he=i.useMemo(()=>({messages:A,isStreaming:O,chatStatus:P,chatError:G,sendMessage:C,updateMessages:re,stopGeneration:U,addToolApprovalResponse:$}),[$,G,O,A,C,P,U,re]),fe=i.useMemo(()=>({isOpen:g,openPanel:K,closePanel:H}),[g,K,H]);return X.jsx(m.AiConversationContext.Provider,{value:he,children:X.jsx(a.AiPanelContext.Provider,{value:fe,children:t})})}function nt(e){return e.slice(-2)}function st(e,t){return!!(e||t<1)}function rt(e){return i.useCallback(async(t,n)=>{if(st(e,n.messages.length))return null;const s=n.messages[0],o=m.getMessageTextContent(s.parts);try{return(await t.agentLoop.generateTitle(o)).trim()}catch(r){return console.error("Unable to generate chat title",r),null}},[e])}function ot({chatId:e,model:t,existingTitle:n}){const{mutate:s}=me(e),o=rt(n);return i.useCallback(async(...r)=>{const l=await o(...r);l!==null&&l.length!==0&&s({id:e,model:t,messages:[],title:l})},[o,t,e,s])}function at({chatId:e,model:t}){const{mutate:n}=ue();return i.useCallback((s,o)=>{const r=nt(o.messages);n({id:e,model:t,messages:r})},[t,e,n])}function it({chatId:e,model:t}){const{mutate:n}=ue();return i.useCallback(s=>{s.length!==0&&n({id:e,model:t,messages:s})},[t,e,n])}function lt(e){return i.useMemo(()=>{const t=[a.REUNITE_MODEL_OPTION];if(e){for(const[n,s]of Object.entries(e))if(s.enabled&&s.apiKey){const o=s.models.map(r=>({...r,provider:n}));t.push(...o)}}return t},[e])}function le(e){return typeof e=="function"?e():e}function ce(e,t){try{const n=globalThis.localStorage.getItem(e);return n===null?le(t):n}catch{return le(t)}}function ct(e,t){try{globalThis.localStorage.setItem(e,t)}catch{console.error("Failed to write to localStorage",{key:e,value:t})}}function ut(e,t){const[n,s]=i.useState(()=>ce(e,t)),o=i.useRef(t);o.current=t,i.useEffect(()=>{s(ce(e,o.current))},[e]);const r=i.useCallback(l=>{s(c=>{const u=l instanceof Function?l(c):l;return ct(e,u),u})},[e]);return[n,r]}const dt="replay:ai:selectedModelId";function ht(e){const{availableModels:t,aiProviders:n,reuniteAuth:s}=e,[o,r]=ut(dt,a.REUNITE_MODEL_OPTION.id);return i.useEffect(()=>{t.find(u=>u.id===o)||r(a.REUNITE_MODEL_OPTION.id)},[t,o,r]),{model:i.useMemo(()=>{const c={provider:a.REUNITE_AI_PROVIDER,baseUrl:s.baseUrl,accessToken:s.accessToken},u=t.find(I=>I.id===o);if(!u||u.provider===a.REUNITE_AI_PROVIDER)return c;const h=n?.[u.provider];return!h||!h.apiKey||!h.enabled?c:{provider:u.provider,modelId:u.id,apiKey:h.apiKey}},[o,t,n,s]),selectedModelId:o,selectModel:r}}function ft(){const[e,t]=i.useState({baseUrl:"",accessToken:""}),{getReuniteAuth:n}=a.useSettingsContext();return i.useEffect(()=>{let s=!1;async function o(){const r=await n?.();s||t({baseUrl:r?.baseUrl??"",accessToken:r?.accessToken??""})}return o().catch(()=>{s||t({baseUrl:"",accessToken:""})}),()=>{s=!0}},[n]),e}function pt(e){const{children:t}=e,[n,s]=i.useState(Z.generateAiChatId),[o,r]=i.useState(n),[l,c]=i.useState(null),u=a.useSettingsState(),h=a.useSettingsContext(),{openPanel:I}=a.useAiPanel(),T=o!==n,d=i.useCallback(()=>{const C=Z.generateAiChatId();r(C),s(C)},[]),g=i.useCallback(C=>{r(C)},[]),{data:p}=m.useAiChat(o),R=ft(),_=lt(h.aiProviders),{selectedModelId:N,model:S,selectModel:v}=ht({availableModels:_,aiProviders:h.aiProviders,reuniteAuth:R}),W=ve(),A=at({chatId:n,model:S}),x=it({chatId:n,model:S}),q=ot({chatId:n,model:S,existingTitle:p?.title}),P=i.useCallback((C,U)=>{U.isAbort||(A(C,U),q(C,U))},[A,q]),G=i.useCallback((...C)=>{x(...C)},[x]),D=i.useCallback(C=>{(o===C||n===C)&&d(),W.mutate(C)},[d,n,W,o]),$=p?.id;i.useEffect(()=>{$&&$!==n&&s($)},[$,o,n]);const O=i.useCallback(()=>{c(null)},[]),K=i.useCallback(C=>{u.aiEnabled.get()&&(d(),c(C),I())},[I,d,u.aiEnabled]),H=i.useMemo(()=>({chatId:n,model:S,availableModels:_,selectedModelId:N,selectModel:v,onSettingsOpen:h.onSettingsOpen,title:p?.title??a.defaultAiChatContextValue.title,isLoading:T,selectChat:g,removeChat:D,createNewChat:d,openAiChatWithPresetInput:K,pendingComposerPreset:l,clearPendingComposerPreset:O}),[n,_,p?.title,S,T,g,D,d,K,l,O,N,v,h.onSettingsOpen]);return X.jsx(a.AiChatContext.Provider,{value:H,children:X.jsx(tt,{chatId:n,model:S,initialMessages:p?.messages,onChatFinish:P,onChatMessagesUpdated:G,children:t})})}exports.AiChatProvider=pt;
|