ompgui 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +6 -6
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +3 -3
- package/.next/required-server-files.js +3 -3
- package/.next/required-server-files.json +3 -3
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/agent/[id]/events/route.js +2 -4
- package/.next/server/app/api/agent/[id]/events/route.js.nft.json +1 -1
- package/.next/server/app/api/agent/[id]/route.js +1 -1
- package/.next/server/app/api/agent/[id]/route.js.nft.json +1 -1
- package/.next/server/app/api/agent/new/route.js +1 -1
- package/.next/server/app/api/agent/new/route.js.nft.json +1 -1
- package/.next/server/app/api/agent/running/events/route.js +2 -2
- package/.next/server/app/api/agent/running/events/route.js.nft.json +1 -1
- package/.next/server/app/api/app-update/route.js +1 -1
- package/.next/server/app/api/mcp/route.js +2 -2
- package/.next/server/app/api/mcp/route.js.nft.json +1 -1
- package/.next/server/app/api/omp-update/route.js +1 -1
- package/.next/server/app/api/omp-update/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/[id]/archive/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/archive/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/[id]/auto-name/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/auto-name/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/[id]/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/[id]/state/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/state/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/[id]/subagents/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/subagents/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/route.js +1 -1
- package/.next/server/app/api/sessions/route.js.nft.json +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +2 -2
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/index.segments/_full.segment.rsc +2 -2
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login.html +1 -1
- package/.next/server/app/login.rsc +1 -1
- package/.next/server/app/login.segments/_full.segment.rsc +1 -1
- package/.next/server/app/login.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/page.js +4 -4
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app-paths-manifest.json +6 -6
- package/.next/server/chunks/6209.js +1 -1
- package/.next/server/chunks/6465.js +1 -0
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/app/page-42f14d1d105b560f.js +76 -0
- package/package.json +1 -1
- package/.next/server/chunks/2407.js +0 -1
- package/.next/static/chunks/app/page-996c13eb0fd7f2f5.js +0 -76
- /package/.next/static/{2RFCzMViB3kmtz57FAIur → p27_8jX1Nr1Q_uA0Whr9L}/_buildManifest.js +0 -0
- /package/.next/static/{2RFCzMViB3kmtz57FAIur → p27_8jX1Nr1Q_uA0Whr9L}/_ssgManifest.js +0 -0
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";exports.id=2407,exports.ids=[2407],exports.modules={28967:(a,b,c)=>{function d(){return globalThis.__piModelsCacheState||(globalThis.__piModelsCacheState={entries:new Map,inFlight:new Map,generation:0}),globalThis.__piModelsCacheState}function e(){let a=d();a.generation+=1,a.entries.clear(),a.inFlight.clear()}function f(a,b){return b?{...a,modelError:b}:a}function g(a){return{...a,modelError:"Model list is temporarily unavailable. Check your configuration and try again."}}function h(a,b){var c,e,f;let g,h,i=d(),j=i.entries.get(a);if(j&&j.expiresAt>Date.now())return Promise.resolve(j.data);let k=i.inFlight.get(a)??(c=i,e=a,f=b,g=c.generation,h=Promise.resolve().then(f).then(a=>{if(c.generation===g&&c.inFlight.get(e)===h){for(c.entries.delete(e);c.entries.size>=32;){let a=c.entries.keys().next().value;if(void 0===a)break;c.entries.delete(a)}c.entries.set(e,{data:a,expiresAt:Date.now()+6e4})}return a}).finally(()=>{c.inFlight.get(e)===h&&c.inFlight.delete(e)}),c.inFlight.set(e,h),h);return j?(k.catch(()=>{}),Promise.resolve(j.data)):k}c.d(b,{Fw:()=>g,Mx:()=>f,kn:()=>e,rC:()=>h})},62407:(a,b,c)=>{c.d(b,{OZ:()=>A,A4:()=>N,HG:()=>O,rb:()=>J,Te:()=>P,OF:()=>U,Fn:()=>R});var d=c(29021),e=c(21820),f=c(28967),g=c(13798),h=c(88501),i=c(78573);function j(a){return"object"==typeof a&&null!==a&&!Array.isArray(a)}function k(a){return j(a)&&"assistant"===a.role&&Array.isArray(a.content)&&a.content.every(a=>j(a)&&"string"==typeof a.type)}function l(a,b){if(Object.is(a,b))return!0;if(typeof a!=typeof b||null===a||null===b||"object"!=typeof a)return!1;if(Array.isArray(a)||Array.isArray(b))return Array.isArray(a)&&Array.isArray(b)&&a.length===b.length&&a.every((a,c)=>l(a,b[c]));if(!j(a)||!j(b))return!1;let c=Object.keys(a),d=Object.keys(b);return c.length===d.length&&c.every(c=>Object.prototype.hasOwnProperty.call(b,c)&&l(a[c],b[c]))}function m(a,b=new WeakMap){if(null===a||"object"!=typeof a)return a;let c=b.get(a);if(void 0!==c)return c;if(Array.isArray(a)){let c=[];for(let d of(b.set(a,c),a))c.push(m(d,b));return c}let d={};for(let c of(b.set(a,d),Object.keys(a)))d[c]=m(a[c],b);return d}function n(a,b){let c={};for(let d of Object.keys(a))d!==b&&(c[d]=a[d]);return c}function o(a,b,c){return l(n(a,c),n(b,c))}function p(a){return[{op:"replace_message",message:m(a)}]}function q(a){try{let b=JSON.stringify(a);return void 0===b?1/0:b.length}catch{return 1/0}}class r extends TypeError{constructor(a,b="frame"){super(`${b}: ${a}`),this.name="RelayFrameValidationError",this.path=b}}function s(a){return"object"==typeof a&&null!==a&&!Array.isArray(a)}function t(a,b=0){if(b>64)return!1;if(null===a||"boolean"==typeof a||"string"==typeof a&&a.length<=0x1000000||"number"==typeof a&&Number.isFinite(a))return!0;if(Array.isArray(a))return a.length<=16384&&a.every(a=>t(a,b+1));if(!s(a))return!1;let c=Object.keys(a);return c.length<=65536&&c.every(c=>t(a[c],b+1))}function u(){let a=globalThis.__ompRelayEpoch??0;if(!Number.isSafeInteger(a)||a>=Number.MAX_SAFE_INTEGER)throw Error("Compact relay epoch exhausted");let b=a+1;return globalThis.__ompRelayEpoch=b,b}function v(a,b=new WeakMap){if(null===a||"object"!=typeof a)return a;let c=b.get(a);if(void 0!==c)return c;if(Array.isArray(a)){let c=[];for(let d of(b.set(a,c),a))c.push(v(d,b));return c}let d={};for(let c of(b.set(a,d),Object.keys(a)))d[c]=v(a[c],b);return d}function w(a){var b=a.message;try{let a=JSON.parse(JSON.stringify(b));return!function(a){try{return!function(a,b="message"){if(!s(a))throw new r("expected an object",b);if("assistant"!==a.role)throw new r('role must be "assistant"',`${b}.role`);if(!Array.isArray(a.content)||a.content.length>16384)throw new r("content must be an array within bounds",`${b}.content`);if(!t(a))throw new r("contains a non-JSON value",b);a.content.forEach((a,c)=>(function(a,b){if(!s(a))throw new r("expected an object",b);var c=a.type,d=`${b}.type`;if("string"!=typeof c||0===c.length||c.length>256)throw new r("expected non-empty string (max 256)",d);if(!t(a))throw new r("contains a non-JSON value",b)})(a,`${b}.content[${c}]`))}(a),!0}catch{return!1}}(a)?null:a}catch{return null}}function x(a,b){for(let c of[a.messageId,a.assistantMessageId,a.id,b&&b.messageId,b&&b.id])if("string"==typeof c&&c.trim())return c}class y{constructor(a="session",b={}){this.subscribers=new Map,this.nextSubscriberId=1,this.pendingTimer=null,this.pending=null,this.active=null,this.lastCommit=null,this.messageCounter=0,this.closed=!1,this._headSeq=0,this._commitSeq=0,this.options=b,this.schedule=b.schedule??((a,b)=>setTimeout(a,b)),this.cancelSchedule=b.cancelSchedule??(a=>clearTimeout(a)),this._sessionId=a||"session",this._epoch=u()}get sessionId(){return this._sessionId}get epoch(){return this._epoch}get seq(){return this._headSeq}get headSeq(){return this._headSeq}get commitSeq(){return this._commitSeq}get subscriberCount(){return this.subscribers.size}get isClosed(){return this.closed}hasSubscribers(){return this.subscribers.size>0}hasCompactSubscribers(){return this.hasSubscribers()}getSubscriberCount(){return this.subscriberCount}getSubscriberIds(){return new Set(this.subscribers.keys())}getActiveCheckpoint(){return this.active?{messageId:this.active.messageId,revision:this.active.revision,message:v(this.active.message)}:null}get activeCheckpoint(){return this.getActiveCheckpoint()}createSyncFrame(a){let b=void 0!==a&&a!==this._commitSeq;return{wire:1,sessionId:this._sessionId,epoch:this._epoch,seq:this._headSeq,type:"relay_sync",headSeq:this._headSeq,commitSeq:this._commitSeq,requiresStateRefresh:b,active:this.getActiveCheckpoint()}}getSyncFrame(a){return this.createSyncFrame(a)}sync(a){return this.createSyncFrame(a)}subscribe(a,b){if(this.closed)return()=>{};let c="number"==typeof b?b:b?.lastCommitSeq,d=this.nextSubscriberId++;this.subscribers.set(d,a),this.options.onSubscriberCountChange?.(this.subscribers.size);try{a(this.createSyncFrame(c))}catch{this.subscribers.delete(d),this.options.onSubscriberCountChange?.(this.subscribers.size)}let e=!0;return()=>{e&&(e=!1,this.subscribers.delete(d)&&this.options.onSubscriberCountChange?.(this.subscribers.size))}}onFrame(a,b){return this.subscribe(a,b)}addSubscriber(a,b){return this.subscribe(a,b)}publish(a){var b;if(!this.closed&&"object"==typeof(b=a)&&null!==b&&!Array.isArray(b)&&"string"==typeof b.type)switch(a.type){case"message_start":this.publishMessageStart(a);return;case"message_update":this.publishMessageUpdate(a);return;case"message_end":this.publishMessageEnd(a);return;default:this.flushPending(),this.emitEvent(a)}}publishEvent(a){this.publish(a)}handleEvent(a){this.publish(a)}flushPending(){this.cancelPendingTimer();let a=this.pending;if(this.pending=null,!a)return!1;let b=this.active;if(!b||b.messageId!==a.messageId)return!1;let c=function(a,b){if(!k(a)||!k(b))return p(b);if(l(a,b))return[];if(!l(n(a,"content"),n(b,"content")))return p(b);let c=[],d=a.content,e=b.content,f=Math.min(d.length,e.length);for(let a=0;a<f;a+=1){let b=d[a],f=e[a];if(l(b,f))continue;let g=function(a,b,c){if("text"===a.type&&"text"===b.type&&"string"==typeof a.text&&"string"==typeof b.text&&b.text.startsWith(a.text)&&!(b.text.length<=a.text.length)&&o(a,b,"text"))return{op:"append_text",index:c,text:b.text.slice(a.text.length)}}(b,f,a);if(g){c.push(g);continue}let h=function(a,b,c){if("thinking"===a.type&&"thinking"===b.type&&"string"==typeof a.thinking&&"string"==typeof b.thinking&&b.thinking.startsWith(a.thinking)&&!(b.thinking.length<=a.thinking.length)&&o(a,b,"thinking"))return{op:"append_thinking",index:c,thinking:b.thinking.slice(a.thinking.length)}}(b,f,a);if(h){c.push(h);continue}c.push({op:"set_block",index:a,block:m(f)})}for(let a=f;a<e.length;a+=1)c.push({op:"set_block",index:a,block:m(e[a])});e.length<d.length&&c.push({op:"truncate_content",length:e.length});let g=p(b);return q(c)>=q(g)?g:c}(b.message,a.message);if(0===c.length)return b.message=v(a.message),!1;let d=b.revision,e=d+1,f={wire:1,sessionId:this._sessionId,epoch:this._epoch,seq:this.nextSeq(),type:"message_patch",messageId:b.messageId,baseRevision:d,revision:e,operations:v(c)};return b.revision=e,b.message=v(a.message),this.fanOut(f),!0}close(a="destroyed"){if(this.closed)return;this.flushPending(),this.closed=!0;let b=this.makeEnvelope("session_closed",{reason:a});this.fanOut(b,!0),this.pending=null,this.active=null,this.subscribers.clear(),this.options.onSubscriberCountChange?.(0)}destroy(a="destroyed"){this.close(a)}rotate(a=this._sessionId,b="identity_changed"){this.close(b),this._sessionId=a||"session",this._epoch=u(),this._headSeq=0,this._commitSeq=0,this.pending=null,this.active=null,this.lastCommit=null,this.closed=!1,this.messageCounter=0}setSessionId(a,b="identity_changed"){let c=a||"session";if(c!==this._sessionId){if(0===this._headSeq&&!this.active&&!this.pending&&0===this.subscribers.size){this._sessionId=c;return}this.rotate(c,b)}}get hasPublishedFrames(){return this._headSeq>0}publishMessageStart(a){let b=w(a);if(!b){this.flushPending(),this.emitEvent(a);return}this.flushPending();let c=x(a,b)??this.mintMessageId(),d={wire:1,sessionId:this._sessionId,epoch:this._epoch,seq:this.nextSeq(),type:"message_begin",messageId:c,revision:0,message:v(b)};this.active={messageId:c,revision:0,message:v(b)},this.pending=null,this.fanOut(d)}publishMessageUpdate(a){let b=w(a);if(!b){this.flushPending(),this.emitEvent(a);return}let c=x(a,b),d=this.active;if(!d||void 0!==c&&c!==d.messageId){this.flushPending();let a=c??this.mintMessageId(),e={wire:1,sessionId:this._sessionId,epoch:this._epoch,seq:this.nextSeq(),type:"message_begin",messageId:a,revision:0,message:v(b)};d={messageId:a,revision:0,message:v(b)},this.active=d,this.fanOut(e)}let e=d.messageId;this.pending={messageId:e,message:v(b)},this.schedulePendingFlush()}publishMessageEnd(a){let b=w(a);if(!b){this.flushPending(),this.emitEvent(a);return}let c=x(a,b);if(!this.active&&this.lastCommit&&(void 0===c||c===this.lastCommit.messageId)&&l(this.lastCommit.message,b))return;let d=this.active;if(d&&(void 0===c||c===d.messageId))this.cancelPendingTimer(),this.pending=null;else{this.flushPending();let a=c??this.mintMessageId(),e={wire:1,sessionId:this._sessionId,epoch:this._epoch,seq:this.nextSeq(),type:"message_begin",messageId:a,revision:0,message:v(b)};d={messageId:a,revision:0,message:v(b)},this.active=d,this.fanOut(e)}let e={wire:1,sessionId:this._sessionId,epoch:this._epoch,seq:this.nextSeq(),type:"message_commit",messageId:d.messageId,authoritative:!0,message:v(b)};this._commitSeq=e.seq,this.lastCommit={messageId:d.messageId,message:v(b)},this.active=null,this.fanOut(e)}emitEvent(a){let b={wire:1,sessionId:this._sessionId,epoch:this._epoch,seq:this.nextSeq(),type:"event",event:v(a)};this.fanOut(b)}schedulePendingFlush(){if(null!==this.pendingTimer)return;let a=this.schedule(()=>{this.pendingTimer=null,this.flushPending()},33);this.pendingTimer=a,a&&"object"==typeof a&&"unref"in a&&"function"==typeof a.unref&&a.unref()}cancelPendingTimer(){null!==this.pendingTimer&&(this.cancelSchedule(this.pendingTimer),this.pendingTimer=null)}mintMessageId(){return this.messageCounter+=1,`${this._sessionId}:assistant:${this._epoch}:${this.messageCounter}`}nextSeq(){if(this._headSeq>=Number.MAX_SAFE_INTEGER)throw Error("Compact relay sequence exhausted");return this._headSeq+=1,this._headSeq}makeEnvelope(a,b){return{wire:1,sessionId:this._sessionId,epoch:this._epoch,seq:this.nextSeq(),type:a,...b}}fanOut(a,b=!1){if(!this.closed||b)for(let b of this.subscribers.values())try{b(a)}catch{}}}let z="This session is restarting — retry in a moment.";class A extends Error{constructor(a,b){super(a),this.name="WebRpcError",this.code=b}}let B=new Set(["select","confirm","input","editor","open_url"]),C=new Set(["abort","abort_and_prompt","set_thinking_level","cycle_thinking_level","cycle_model","get_available_models","set_auto_compaction","set_auto_retry","abort_retry","abort_bash","set_todos","set_steering_mode","set_follow_up_mode","set_interrupt_mode","get_branch_messages","get_messages","get_messages_page","export_html","handoff","get_subagents","get_subagent_messages","set_subagent_subscription","get_login_providers","login"]),D={navigate_tree:"Branch navigation is not supported over the omp RPC protocol",clear_queue:"Recalling queued messages is not supported over the omp RPC protocol",get_tools:"Per-session tool listing is not supported over the omp RPC protocol",set_tools:"Changing tools on a running session is not supported over the omp RPC protocol; tool presets apply to new sessions",extension_ui_input:"Extension custom UI is not supported over the omp RPC protocol"},E={find:"glob",search:"grep"},F=new Set(["ls"]),G=["bash","read","edit","write","grep","find","ls","task"].map(a=>a.toLowerCase()).sort().join(",");function H(a,b,c=!1){let d=[];if(a)d.push("--resume",a);else if(void 0!==b){let a=b.map(a=>a.toLowerCase()).sort().join(",");if(0===b.length)d.push("--no-tools");else if(a===G);else{let a=function(a){let b=[];for(let c of a){let a=c.toLowerCase();if(F.has(a))continue;let d=E[a]??a;b.includes(d)||b.push(d)}return b}(b);a.length>0&&d.push("--tools",a.join(","))}}return c&&!a&&d.push("--advisor"),d}function I(a){return a?.length?a:void 0}function J(a){if(a&&(0,d.existsSync)(a))return{cwd:a,fellBack:!1};try{let a=process.cwd();if(a&&(0,d.existsSync)(a))return{cwd:a,fellBack:!0}}catch{}return{cwd:(0,e.homedir)(),fellBack:!0}}function K(a){a&&"object"==typeof a&&void 0===a.estimatedTokensAfter&&(a.estimatedTokensAfter=Math.round((a.summary?.length??0)/4))}class L{constructor(a,b,c,d){this.listeners=[],this.pendingUiRequests=new Map,this.uiExpiryTimers=new Map,this.extensionStatuses=new Map,this.extensionWidgets=new Map,this.promptRunning=!1,this.bashRunning=!1,this.streaming=!1,this.compacting=!1,this.fastModeEnabled=!1,this.idleTimer=null,this.destroyListeners=[],this.onIdentityChangeCallback=null,this.unsubscribeFrames=null,this.initPromise=null,this.restarting=!1,this.mcpListWaiter=null,this._alive=!0,this.hostToolNames=new Set,this.pendingHostTools=new Map,this.hostUriSchemes=new Map,this.pendingHostUris=new Map,this.destroyPromise=null,this._sessionId="",this._sessionFile="",this.sessionFileSignalTimer=null,this.proc=a,this.cwd=b,this.recordedCwd=c??null,this.relayPublisher=this.createRelayPublisher(d)}createRelayPublisher(a){return new y(a||"session",{onSubscriberCountChange:()=>this.onCompactSubscriberCountChange()})}onCompactSubscriberCountChange(){this.prunePendingHostRecipients()}hasBrowserSubscribers(){return this.listeners.length>0||this.relayPublisher.hasSubscribers()}getRelayPublisher(){return this.relayPublisher}get compactPublisher(){return this.relayPublisher}get compactSubscriberCount(){return this.relayPublisher.subscriberCount}replaceRelayPublisher(a,b){this.relayPublisher.close(a),this.relayPublisher=this.createRelayPublisher(b||this._sessionId||"session")}get sessionId(){return this._sessionId}get sessionFile(){return this._sessionFile}isAlive(){return this._alive&&this.proc.isAlive}isRunning(){return this.isAlive()&&(this.promptRunning||this.streaming||this.compacting||this.bashRunning)}start(){this.unsubscribeFrames=this.proc.onFrame(a=>this.handleFrame(a)),this.resetIdleTimer(),T()}waitUntilReady(){return this.initPromise||(this.initPromise=this.initialize()),this.initPromise}async initialize(){let a=await this.proc.waitReady(12e4);await this.proc.negotiateProtocol(a),await this.proc.sendCommand({type:"set_subagent_subscription",level:"events"}).catch(()=>{});let b=await this.proc.sendCommand({type:"get_state"});this.applyIdentity(b),this.recordedCwd&&this.recordedCwd!==this.cwd&&this.emit({type:"notice",level:"warning",message:`This session's working directory no longer exists; the agent is running in ${this.cwd}.`})}applyIdentity(a){a.sessionId&&this.relayPublisher.setSessionId(a.sessionId),this._sessionId=a.sessionId,this._sessionFile=a.sessionFile??"",this._sessionName=a.sessionName,this.streaming=a.isStreaming,this.compacting=a.isCompacting,this.fastModeEnabled=a.fastModeEnabled??a.fastMode??this.fastModeEnabled,this._sessionFile&&(0,i.O8)(this._sessionId,this._sessionFile)}handleProcessExit(a){if(!this._alive||this.restarting)return;let b=a.trim().split("\n").pop()??"";this.emit({type:"notice",level:"error",message:`The omp process for this session exited unexpectedly${b?`: ${b}`:"."}`}),(this.streaming||this.promptRunning)&&this.emit({type:"agent_end",isTerminal:!0,messages:[]}),this.destroy()}handleFrame(a){this.resetIdleTimer();let b=!1;switch(a.type){case"command_output":{let b=this.mcpListWaiter;if(b&&"string"==typeof a.text){clearTimeout(b.timer),this.mcpListWaiter=null,b.resolve(a.text),T();return}break}case"agent_start":this.streaming=!0,(0,i.mD)(),b=!0,this._sessionFile&&!(0,d.existsSync)(this._sessionFile)&&this.signalWhenSessionFileAppears();break;case"agent_end":!1!==a.isTerminal&&(this.streaming=!1,this.promptRunning=!1,(0,i.mD)());break;case"prompt_result":this.promptRunning=!1;break;case"auto_compaction_start":this.compacting=!0;break;case"auto_compaction_end":this.compacting=!1,K(a.result),(0,i.mD)();break;case"session_info_update":"string"==typeof a.title&&(this._sessionName=a.title),(0,i.mD)(),b=!0;break;case"response":if(!1===a.success&&"prompt"===a.command){this.promptRunning=!1,this.emit({type:"prompt_error",errorMessage:a.error??"Prompt failed"}),T();return}break;case"extension_ui_request":if(this.trackExtensionUiRequest(a))return void T();break;case"host_tool_call":{let b="string"==typeof a.id?a.id:"",c="string"==typeof a.toolName?a.toolName:"";if(b&&c&&this.hostToolNames.has(c)&&this.hasBrowserSubscribers()){this.pendingHostTools.set(b,this.captureHostRequestRecipients(a)),this.emit(a),T();return}this.rejectUnexpectedHostTool(a);return}case"host_tool_cancel":{let b="string"==typeof a.targetId?a.targetId:"";if(b&&this.pendingHostTools.delete(b)){this.emit(a),T();return}break}case"host_uri_request":{let b="string"==typeof a.id?a.id:"",c=("string"==typeof a.url?a.url:"").split(":")[0]??"",d="write"===a.operation?"write":"read",e=this.hostUriSchemes.get(c);if(b&&c&&e&&("write"!==d||e.writable)&&this.hasBrowserSubscribers()){this.pendingHostUris.set(b,this.captureHostRequestRecipients(a)),this.emit(a),T();return}this.proc.sendFrame({type:"host_uri_result",id:b,isError:!0,error:`URI scheme "${c}" is not registered by omp-web`});return}case"host_uri_cancel":{let b="string"==typeof a.targetId?a.targetId:"";if(b&&this.pendingHostUris.delete(b)){this.emit(a),T();return}}}this.emit(a),T({refreshSessionList:b})}forgetPendingUiRequest(a){this.pendingUiRequests.delete(a);let b=this.uiExpiryTimers.get(a);b&&(clearTimeout(b),this.uiExpiryTimers.delete(a))}clearPendingUiRequests(){for(let a of this.uiExpiryTimers.values())clearTimeout(a);this.uiExpiryTimers.clear(),this.pendingUiRequests.clear()}trackExtensionUiRequest(a){let b=a.method,c=a.id;if("cancel"===b)return this.forgetPendingUiRequest(a.targetId),!1;let d=!1;try{d=(0,h.r)().settings.tools?.approval?.extension==="allow"}catch{}if("confirm"===b&&"string"==typeof a.title&&/^allow tool\s*:/i.test(a.title)&&d)return this.forgetPendingUiRequest(c),this.proc.sendFrame({type:"extension_ui_response",id:c,confirmed:!0}),!0;if(B.has(b)){this.forgetPendingUiRequest(c);let b="number"==typeof a.timeout?a.timeout:void 0;if(b&&b>0){a.expiresAt=Date.now()+b;let d=setTimeout(()=>this.forgetPendingUiRequest(c),b);d.unref?.(),this.uiExpiryTimers.set(c,d)}return this.pendingUiRequests.set(c,a),!1}if("setStatus"===b){let b=a.statusKey,c=a.statusText;return void 0===c?this.extensionStatuses.delete(b):this.extensionStatuses.set(b,c),!1}if("setWidget"===b){let b=a.widgetKey,c=a.widgetLines;void 0===c?this.extensionWidgets.delete(b):this.extensionWidgets.set(b,{key:b,lines:c,placement:a.widgetPlacement??"aboveEditor"})}return!1}rejectUnexpectedHostTool(a){let b="string"==typeof a.id?a.id:"";if(!b)return;let c="string"==typeof a.toolName?a.toolName:"unknown";this.proc.sendFrame({type:"host_tool_result",id:b,isError:!0,result:{content:[{type:"text",text:`Host tool "${c}" is not available in ompgui. Use OMP's built-in tools within the selected workspace.`}]}}),this.emit({type:"notice",level:"warning",message:`Rejected unavailable host tool: ${c}`})}rejectPendingHostTool(a,b){this.pendingHostTools.delete(a)&&this.proc.sendFrame({type:"host_tool_result",id:a,isError:!0,result:{content:[{type:"text",text:b}]}})}rejectPendingHostTools(a){for(let b of[...this.pendingHostTools.keys()])this.rejectPendingHostTool(b,a)}rejectPendingHostUri(a,b){this.pendingHostUris.delete(a)&&this.proc.sendFrame({type:"host_uri_result",id:a,isError:!0,error:b})}rejectPendingHostUris(a){for(let b of[...this.pendingHostUris.keys()])this.rejectPendingHostUri(b,a)}captureHostRequestRecipients(a){return{event:a,legacyRecipients:new Set(this.listeners),compactRecipientIds:this.relayPublisher.getSubscriberIds()}}prunePendingHostRecipients(a){let b=this.relayPublisher.getSubscriberIds(),c=(c,d,e)=>{for(let[f,g]of c){for(let c of(a&&g.legacyRecipients.delete(a),g.compactRecipientIds))b.has(c)||g.compactRecipientIds.delete(c);0===g.legacyRecipients.size&&0===g.compactRecipientIds.size&&d(f,e)}};c(this.pendingHostTools,(a,b)=>this.rejectPendingHostTool(a,b),"The web UI that received this host tool disconnected before answering"),c(this.pendingHostUris,(a,b)=>this.rejectPendingHostUri(a,b),"The web UI that received this URI request disconnected before answering")}emit(a){for(let b of(this.relayPublisher.publish(a),this.listeners))try{b(a)}catch{}}signalWhenSessionFileAppears(){if(this.sessionFileSignalTimer)return;let a=0,b=()=>{if(this.sessionFileSignalTimer=null,this._alive&&this._sessionFile){if(!(0,d.existsSync)(this._sessionFile)){(a+=1)<40&&(this.sessionFileSignalTimer=setTimeout(b,250));return}(0,i.mD)(),T({refreshSessionList:!0})}};this.sessionFileSignalTimer=setTimeout(b,250)}resetIdleTimer(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.isRunning()?this.resetIdleTimer():this.destroy()},6e5)}onEvent(a){this.listeners.push(a);let b=Date.now();for(let[c,d]of this.pendingUiRequests){let e=d.expiresAt;if(void 0!==e&&e<=b){this.forgetPendingUiRequest(c);continue}a(d)}return()=>{let b=this.listeners.indexOf(a);-1!==b&&this.listeners.splice(b,1),this.prunePendingHostRecipients(a)}}onDestroy(a){return this._alive?(this.destroyListeners.push(a),()=>{let b=this.destroyListeners.indexOf(a);-1!==b&&this.destroyListeners.splice(b,1)}):(a(),()=>{})}onIdentityChange(a){this.onIdentityChangeCallback=a}async withFinalRunningNotification(a){try{return await a()}finally{T()}}async getMcpList(){let a,b;if(this.restarting)throw new A(z,"session_restarting");if(!this.isAlive())throw Error("Session is no longer running");if(this.isRunning())throw new A("Wait for the current run to finish","session_busy");if(this.mcpListWaiter)throw new A("MCP list is already loading","mcp_list_loading");this.promptRunning=!0,T();let c=new Promise((c,d)=>{a=c,b=d}),d={resolve:a,reject:b,timer:void 0};d.timer=setTimeout(()=>{this.mcpListWaiter===d&&(this.mcpListWaiter=null,b(new A("Timed out while loading MCP servers","mcp_list_timeout")))},15e3),d.timer.unref?.(),this.mcpListWaiter=d;try{return await this.proc.sendCommand({type:"prompt",message:"/mcp list"}),await c}catch(a){throw this.mcpListWaiter===d&&(clearTimeout(d.timer),this.mcpListWaiter=null,d.reject(a instanceof Error?a:Error(String(a)))),a}finally{this.mcpListWaiter===d&&(clearTimeout(d.timer),this.mcpListWaiter=null),this.promptRunning=!1,T()}}buildWebState(a){return this.streaming=a.isStreaming,this.compacting=a.isCompacting,this._sessionName=a.sessionName,a.sessionId&&(this._sessionId=a.sessionId,this._sessionFile=a.sessionFile??this._sessionFile),{sessionId:a.sessionId,sessionFile:a.sessionFile??"",sessionName:a.sessionName,isStreaming:a.isStreaming,isPromptRunning:this.promptRunning,isBashRunning:this.bashRunning,isCompacting:a.isCompacting,autoCompactionEnabled:a.autoCompactionEnabled,autoRetryEnabled:a.autoRetryEnabled,interruptMode:a.interruptMode,steeringMode:a.steeringMode,followUpMode:a.followUpMode,model:a.model?{id:a.model.id,provider:a.model.provider,name:a.model.name,reasoning:a.model.reasoning,thinking:a.model.thinking?{efforts:a.model.thinking.efforts}:void 0}:void 0,messageCount:a.messageCount,queuedMessageCount:a.queuedMessageCount,contextUsage:a.contextUsage??null,systemPrompt:a.systemPrompt?.join("\n\n")??"",thinkingLevel:a.thinkingLevel??"off",fastModeEnabled:a.fastModeEnabled??a.fastMode??this.fastModeEnabled,fastModeActive:a.fastModeActive,todoPhases:a.todoPhases??[],extensionStatuses:Array.from(this.extensionStatuses,([a,b])=>({key:a,text:b})),extensionWidgets:Array.from(this.extensionWidgets.values())}}async refreshIdentityAfterSessionChange(){let a=this._sessionId,b=await this.proc.sendCommand({type:"get_state"});return this.applyIdentity(b),a&&a!==this._sessionId&&this.onIdentityChangeCallback?.(a,this._sessionId),(0,i.mD)(),this._sessionId}async restart(){if(this.restarting)throw new A(z,"session_restarting");this.replaceRelayPublisher("destroyed");let a=this._sessionFile,b=!!a&&(0,d.existsSync)(a),c=this.proc;this.restarting=!0,this.unsubscribeFrames?.();try{if(await c.dispose(),!this._alive)return;this.extensionStatuses.clear(),this.extensionWidgets.clear(),this.clearPendingUiRequests(),this.promptRunning=!1,this.bashRunning=!1,this.streaming=!1,this.compacting=!1;let d=new g.X({cwd:this.cwd,extraArgs:H(b?a:""),onExit:({stderrTail:a})=>{this.proc===d&&this.handleProcessExit(a)}});this.proc=d,this.unsubscribeFrames=d.onFrame(a=>this.handleFrame(a));try{let a=await d.waitReady(12e4);await d.negotiateProtocol(a),await d.sendCommand({type:"set_subagent_subscription",level:"events"}).catch(()=>{});let b=await d.sendCommand({type:"get_state"});this.applyIdentity(b)}catch(a){throw this.unsubscribeFrames?.(),this.unsubscribeFrames=null,d.dispose(),this.destroy(),a}}finally{this.restarting=!1}T()}async send(a){if(this.restarting)throw new A(z,"session_restarting");if(!this.isAlive())throw Error("Session is no longer running");this.resetIdleTimer();let b=a.type;if("prompt"===b||"steer"===b||"follow_up"===b){let b=function(a){if(void 0===a)return null;if(!Array.isArray(a))return"images must be an array";if(a.length>10)return"A message can include at most 10 images";for(let b of a){if(!b||"object"!=typeof b||"image"!==b.type)return"Each attachment must be an image";if(!function(a){if(!a||"object"!=typeof a||"string"!=typeof a.data||"string"!=typeof a.mimeType||!a.mimeType.startsWith("image/"))return!1;let b=function(a){if(!a||a.length%4!=0)return null;let b=a.endsWith("==")?2:+!!a.endsWith("="),c=a.length-b;for(let b=0;b<c;b+=1){var d;if(!((d=a.charCodeAt(b))>=65&&d<=90||d>=97&&d<=122||d>=48&&d<=57||43===d||47===d))return null}for(let b=c;b<a.length;b+=1)if("="!==a[b])return null;return a.length/4*3-b}(a.data);return null!==b&&b<=0xa00000}(b))return"Each image must be valid base64 image data of 10MB or smaller"}return null}(a.images);if(b)throw Error(b)}let c=D[b];if(c)throw new g.x(b,c,"unsupported");switch(b){case"prompt":{if(this.bashRunning)throw Error("Cannot send a prompt while a shell command is running");let b=a.streamingBehavior;b||(this.promptRunning=!0,T());try{let c=await this.proc.sendCommand({type:"prompt",message:a.message,...I(a.images)?{images:I(a.images)}:{},...b?{streamingBehavior:b}:{}});c?.agentInvoked!==!1||b||(this.promptRunning=!1,this.emit({type:"prompt_result",agentInvoked:!1}),T())}catch(a){throw this.promptRunning=!1,T(),a}return null}case"steer":case"follow_up":return await this.proc.sendCommand({type:b,message:a.message,...I(a.images)?{images:I(a.images)}:{}}),null;case"abort":return await this.withFinalRunningNotification(async()=>{await this.proc.sendCommand({type:"abort"}),this.promptRunning=!1}),null;case"get_state":{let a=await this.proc.sendCommand({type:"get_state"});return this.buildWebState(a)}case"set_model":{let{provider:b,modelId:c}=a,d=await this.proc.sendCommand({type:"set_model",provider:b,modelId:c});return(0,f.kn)(),(0,i.mD)(),{id:d.id,provider:d.provider}}case"set_fast_mode":{let b=!0===a.enabled,c=await this.proc.sendCommand({type:"set_fast_mode",enabled:b});return this.fastModeEnabled=c?.enabled??b,{enabled:this.fastModeEnabled,active:c?.active??!1}}case"fork":if(this.bashRunning)throw Error("Cannot fork while a shell command is running");if((await this.proc.sendCommand({type:"branch",entryId:a.entryId})).cancelled)return{cancelled:!0};return{cancelled:!1,newSessionId:await this.refreshIdentityAfterSessionChange()};case"new_session":case"switch_session":{let b=await this.proc.sendCommand(a);if(!b.cancelled)return{cancelled:!1,newSessionId:await this.refreshIdentityAfterSessionChange()};return b}case"compact":try{return await this.withFinalRunningNotification(async()=>{this.compacting=!0,T();try{let b=await this.proc.sendCommand({type:"compact",...a.customInstructions?{customInstructions:a.customInstructions}:{}});return K(b),b}finally{this.compacting=!1}})}finally{(0,i.mD)()}case"abort_compaction":return await this.withFinalRunningNotification(()=>this.proc.sendCommand({type:"abort"})),null;case"set_session_name":{let b=a.name?.trim();if(!b)throw Error("Session name cannot be empty");return await this.proc.sendCommand({type:"set_session_name",name:b}),this._sessionName=b,(0,i.mD)(),null}case"get_session_stats":return{...await this.proc.sendCommand({type:"get_session_stats"}),sessionName:this._sessionName};case"get_last_assistant_text":return{text:(await this.proc.sendCommand({type:"get_last_assistant_text"})).text??""};case"get_commands":return await this.proc.sendCommand({type:"get_available_commands"});case"reload":return await this.restart(),{success:!0};case"extension_ui_response":{let{id:b,...c}=a;return this.forgetPendingUiRequest(b),this.proc.sendFrame({type:"extension_ui_response",id:b,...c}),null}case"bash":if(!0===a.excludeFromContext)throw new A("omp cannot run a shell command with its output excluded from the model context (`!!`): the RPC bash command has no exclusion option, so the output would silently enter the context anyway. Run it with a single `!` to share the output with the model, or use a terminal outside ompgui.","bash_exclude_unsupported");if(this.isRunning())throw Error("Cannot run a shell command while the session is busy");this.bashRunning=!0,T();try{return await this.proc.sendCommand({type:"bash",command:a.command})}finally{this.bashRunning=!1,(0,i.mD)(),T()}case"set_host_tools":{let b=(Array.isArray(a.tools)?a.tools:[]).filter(a=>"string"==typeof a.name&&a.name);return this.hostToolNames=new Set(b.map(a=>a.name)),await this.proc.sendCommand({type:"set_host_tools",tools:b}),null}case"host_tool_result":return"string"==typeof a.id&&this.pendingHostTools.delete(a.id),await this.proc.sendCommand(a),null;case"set_host_uri_schemes":{let b=Array.isArray(a.schemes)?a.schemes:[];for(let a of(this.hostUriSchemes=new Map,b))"string"==typeof a.scheme&&a.scheme&&this.hostUriSchemes.set(a.scheme,{writable:!0===a.writable});return await this.proc.sendCommand({type:"set_host_uri_schemes",schemes:b}),null}case"host_uri_result":return"string"==typeof a.id&&this.pendingHostUris.delete(a.id),await this.proc.sendCommand(a),null;default:if(C.has(b)){let c=await this.proc.sendCommand(a);return"set_thinking_level"===b&&(0,i.mD)(),c??null}throw Error(`Unsupported command: ${b}`)}}destroy(){this.destroyAndWait()}async destroyAndWait(){if(this.destroyPromise)return this.destroyPromise;if(!this._alive)return;this._alive=!1,this.relayPublisher.close("destroyed"),this.idleTimer&&clearTimeout(this.idleTimer),this.sessionFileSignalTimer&&(clearTimeout(this.sessionFileSignalTimer),this.sessionFileSignalTimer=null),this.unsubscribeFrames?.(),this.clearPendingUiRequests(),this.mcpListWaiter&&(clearTimeout(this.mcpListWaiter.timer),this.mcpListWaiter.reject(Error("Session was closed while loading MCP servers")),this.mcpListWaiter=null);let a=this.proc.dispose().catch(()=>{});for(let b of(this.destroyPromise=a,this.pendingHostTools.clear(),this.hostToolNames.clear(),this.pendingHostUris.clear(),this.hostUriSchemes.clear(),this.destroyListeners.splice(0)))try{b()}catch{}T(),await a}}function M(){if(!globalThis.__ompSessions){globalThis.__ompSessions=new Map;let a=()=>globalThis.__ompSessions?.forEach(a=>a.destroy());process.once("exit",a),process.once("SIGINT",a),process.once("SIGTERM",a)}return globalThis.__ompSessions}function N(a){return M().get(a)}function O(){let a=new Set;for(let[b,c]of M())c.isRunning()&&a.add(c.sessionId||b);return[...a]}async function P(){let a=[...new Set(M().values())];return await Promise.all(a.map(a=>a.destroyAndWait())),a.length}function Q(){return globalThis.__ompRunningListeners||(globalThis.__ompRunningListeners=new Set),globalThis.__ompRunningListeners}function R(a){let b=Q();return b.add(a),()=>{b.delete(a)}}let S="";function T({refreshSessionList:a=!1}={}){let b=O(),c=JSON.stringify([...b].sort());if(c===S&&!a)return;S=c;let d={ids:b,refreshSessionList:a};for(let a of Q())try{a(d)}catch{}}async function U(a,b,c,d,e=!1,f){let h=M(),i=(globalThis.__ompStartLocks||(globalThis.__ompStartLocks=new Map),globalThis.__ompStartLocks),j=h.get(a);if(j?.isAlive())return{session:j,realSessionId:a};j?.destroyPromise&&await j.destroyPromise;let k=i.get(a);if(k)return k;let l=(async()=>{let i={},j=new L(new g.X({cwd:c,extraArgs:H(b,d,e),onExit:({stderrTail:a})=>i.wrapper?.handleProcessExit(a)}),c,f,a);i.wrapper=j,j.start();try{await j.waitUntilReady()}catch(a){throw await j.destroyAndWait(),a}let k=j.sessionId;return j.onDestroy(()=>{h.get(j.sessionId)===j&&h.delete(j.sessionId),h.get(k)===j&&h.delete(k)}),j.onIdentityChange((a,b)=>{h.get(a)===j&&h.delete(a),h.set(b,j)}),h.set(k,j),{session:j,realSessionId:k}})().finally(()=>i.delete(a));return i.set(a,l),l}}};
|