moi-computer 0.11.1-dev.1c52199 → 0.11.1-dev.be1ed10
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/client/api/app-config.ts +1 -2
- package/client/app/routes/WorkspaceRoute.tsx +19 -27
- package/client/features/applets/AppletMount.tsx +1 -4
- package/client/features/applets/applet-runtime.ts +2 -13
- package/client/features/chat/applet-chat-intents.ts +6 -15
- package/client/features/chat/sessions/useSelectedSession.ts +20 -64
- package/client/features/chat/useChat.ts +0 -4
- package/client/features/dev/DevIndexPage.tsx +0 -5
- package/client/features/dev/DevRoutes.tsx +1 -14
- package/client/features/views/ViewManager.tsx +1 -4
- package/client/features/views/api.ts +2 -2
- package/client/features/views/useViewBuilderActions.ts +0 -3
- package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -18
- package/client/features/workspace/WorkspaceScreen.tsx +11 -19
- package/client/features/workspace/api.ts +1 -3
- package/client/features/workspace/moi-context.ts +2 -7
- package/client/features/workspace/useWorkspaceNavigation.ts +3 -12
- package/client/index.tsx +3 -4
- package/dist/chunk-691pqsj6.js +2 -0
- package/dist/chunk-7a5nm4k9.css +1 -0
- package/dist/chunk-amb8y04y.js +1 -0
- package/dist/chunk-cf3pgy7j.js +546 -0
- package/dist/{chunk-wnmf38ta.js → chunk-mzrgr577.js} +1 -1
- package/dist/chunk-q6a0g26x.js +1 -0
- package/dist/chunk-twgdemkc.js +74 -0
- package/dist/chunk-x90k0f5c.js +2 -0
- package/dist/chunk-yq00csvd.js +2 -0
- package/dist/index.html +1 -1
- package/lib/moi-context.ts +0 -7
- package/lib/types.ts +6 -12
- package/package.json +1 -3
- package/server/api.ts +2 -23
- package/server/app-config.ts +34 -127
- package/server/applet-typecheck.ts +1 -6
- package/server/applets/build-applet.ts +0 -10
- package/server/cli.ts +12 -57
- package/server/layout.ts +3 -16
- package/server/skills-template.ts +2 -14
- package/server/web.ts +17 -62
- package/ui-components/avatar.tsx +4 -5
- package/ui-components/docs/avatar.md +5 -5
- package/client/features/collab/DevCollabIdentity.tsx +0 -170
- package/client/features/collab/DevCollabKit.tsx +0 -501
- package/client/features/collab/DevCollabPage.tsx +0 -25
- package/client/features/collab/WorkspaceCollabControls.tsx +0 -313
- package/client/features/collab/client.ts +0 -146
- package/client/features/collab/components.tsx +0 -307
- package/client/features/collab/dev-persona.ts +0 -66
- package/client/features/collab/engine.ts +0 -96
- package/client/features/collab/entry.tsx +0 -35
- package/client/features/collab/facehash-avatar.ts +0 -132
- package/client/features/collab/fake-engine.ts +0 -130
- package/client/features/collab/hooks.tsx +0 -253
- package/client/features/collab/identity.ts +0 -305
- package/client/features/collab/index.ts +0 -45
- package/client/features/collab/people.ts +0 -102
- package/client/features/collab/personal-state.ts +0 -61
- package/client/features/collab/presence-publisher.ts +0 -29
- package/client/features/collab/presence-target.ts +0 -10
- package/client/features/collab/primitives.tsx +0 -398
- package/client/features/collab/proxy-identity.ts +0 -24
- package/client/features/collab/store.ts +0 -156
- package/client/features/workspace/layout-save.ts +0 -13
- package/dist/chunk-1ftessc8.js +0 -2
- package/dist/chunk-3802vh2p.js +0 -2
- package/dist/chunk-542a2m9m.js +0 -1
- package/dist/chunk-5745d83v.js +0 -2
- package/dist/chunk-5zxdsjym.js +0 -1
- package/dist/chunk-7r4z77ry.js +0 -2
- package/dist/chunk-9cm0wjah.js +0 -79
- package/dist/chunk-cvgdm1hq.js +0 -2
- package/dist/chunk-gptm4jpd.js +0 -546
- package/dist/chunk-xaehhr1j.css +0 -1
- package/dist/chunk-xpt063fx.js +0 -1
- package/lib/collab/colors.ts +0 -24
- package/lib/collab/protocol.ts +0 -83
- package/lib/collab/types.ts +0 -63
- package/lib/experimental.ts +0 -14
- package/server/chat-selection.ts +0 -23
- package/server/collab/applet-module.ts +0 -50
- package/server/collab/cloudflare-access.ts +0 -77
- package/server/collab/config.ts +0 -18
- package/server/collab/ipc.ts +0 -10
- package/server/collab/manager.ts +0 -407
- package/server/collab/service.ts +0 -137
- package/server/collab/skill/collab-env.d.ts +0 -92
- package/server/collab/skill/index.ts +0 -59
- package/server/collab/worker.ts +0 -52
- package/workspace/.claude/skills/moi-workspace/references/COLLABORATIVE.md +0 -151
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CollabClientMessage,
|
|
3
|
-
CollabIdentity,
|
|
4
|
-
CollabJsonValue,
|
|
5
|
-
CollabLocation,
|
|
6
|
-
CollabParticipant,
|
|
7
|
-
CollabPresenceRegistration,
|
|
8
|
-
CollabServerMessage
|
|
9
|
-
} from '@/lib/collab/types'
|
|
10
|
-
|
|
11
|
-
export type CollabConnectionState = {
|
|
12
|
-
status: 'connecting' | 'connected' | 'disconnected'
|
|
13
|
-
connectionId: string | null
|
|
14
|
-
participants: CollabParticipant[]
|
|
15
|
-
// Current live profiles only. The host owns the full workspace directory.
|
|
16
|
-
users: readonly CollabIdentity[]
|
|
17
|
-
error: string | null
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const DISCONNECTED_STATE: CollabConnectionState = {
|
|
21
|
-
status: 'disconnected',
|
|
22
|
-
connectionId: null,
|
|
23
|
-
participants: [],
|
|
24
|
-
users: [],
|
|
25
|
-
error: null
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type CollabPresenceEntry = {
|
|
29
|
-
registrationId: string
|
|
30
|
-
connectionId: string
|
|
31
|
-
userId: string
|
|
32
|
-
value: CollabJsonValue
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const EMPTY_PRESENCE: readonly CollabPresenceEntry[] = []
|
|
36
|
-
const channelKey = (surface: string, channel: string) => JSON.stringify([surface, channel])
|
|
37
|
-
|
|
38
|
-
// Sockets and timers live in client.ts; this model owns ephemeral registrations.
|
|
39
|
-
export class CollabStore {
|
|
40
|
-
private state: CollabConnectionState = DISCONNECTED_STATE
|
|
41
|
-
private peopleState: CollabConnectionState = DISCONNECTED_STATE
|
|
42
|
-
private channels = new Map<string, readonly CollabPresenceEntry[]>()
|
|
43
|
-
private listeners = new Set<() => void>()
|
|
44
|
-
private registrations = new Map<string, CollabPresenceRegistration>()
|
|
45
|
-
private location: CollabLocation | null = null
|
|
46
|
-
private send: (message: CollabClientMessage) => void = () => {}
|
|
47
|
-
|
|
48
|
-
getSnapshot = (): CollabConnectionState => this.state
|
|
49
|
-
// User hooks never need cursor coordinates or other publication payloads.
|
|
50
|
-
getPeopleSnapshot = (): CollabConnectionState => this.peopleState
|
|
51
|
-
getPresenceSnapshot = (surface: string, channel: string): readonly CollabPresenceEntry[] =>
|
|
52
|
-
this.channels.get(channelKey(surface, channel)) ?? EMPTY_PRESENCE
|
|
53
|
-
subscribe = (listener: () => void): (() => void) => {
|
|
54
|
-
this.listeners.add(listener)
|
|
55
|
-
return () => {
|
|
56
|
-
this.listeners.delete(listener)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
setSender(send: (message: CollabClientMessage) => void): void {
|
|
60
|
-
this.send = send
|
|
61
|
-
}
|
|
62
|
-
connecting(): void {
|
|
63
|
-
this.publish({ status: 'connecting', error: null })
|
|
64
|
-
}
|
|
65
|
-
disconnect(message?: string): void {
|
|
66
|
-
this.publish({ ...DISCONNECTED_STATE, error: message ?? null })
|
|
67
|
-
}
|
|
68
|
-
setLocation(location: CollabLocation | null): void {
|
|
69
|
-
if (JSON.stringify(this.location) === JSON.stringify(location)) return
|
|
70
|
-
this.location = location
|
|
71
|
-
// Page filters update immediately, without waiting for the server echo.
|
|
72
|
-
this.publish({}, true)
|
|
73
|
-
if (this.state.status === 'connected') this.send({ type: 'location', location })
|
|
74
|
-
}
|
|
75
|
-
getLocation(): CollabLocation | null {
|
|
76
|
-
return this.location
|
|
77
|
-
}
|
|
78
|
-
setPresence(registration: CollabPresenceRegistration): void {
|
|
79
|
-
const previous = this.registrations.get(registration.registrationId)
|
|
80
|
-
if (previous && JSON.stringify(previous) === JSON.stringify(registration)) return
|
|
81
|
-
this.registrations.set(registration.registrationId, registration)
|
|
82
|
-
if (this.state.status === 'connected') this.send({ type: 'presence:set', ...registration })
|
|
83
|
-
}
|
|
84
|
-
deletePresence(registrationId: string): void {
|
|
85
|
-
this.registrations.delete(registrationId)
|
|
86
|
-
if (this.state.status === 'connected') this.send({ type: 'presence:delete', registrationId })
|
|
87
|
-
}
|
|
88
|
-
receive(message: CollabServerMessage): void {
|
|
89
|
-
switch (message.type) {
|
|
90
|
-
case 'welcome':
|
|
91
|
-
this.publish({
|
|
92
|
-
status: 'connected',
|
|
93
|
-
connectionId: message.connectionId,
|
|
94
|
-
participants: message.participants,
|
|
95
|
-
users: message.users,
|
|
96
|
-
error: null
|
|
97
|
-
})
|
|
98
|
-
for (const registration of this.registrations.values()) {
|
|
99
|
-
this.send({ type: 'presence:set', ...registration })
|
|
100
|
-
}
|
|
101
|
-
break
|
|
102
|
-
case 'participants':
|
|
103
|
-
this.publish({ participants: message.participants, users: message.users })
|
|
104
|
-
break
|
|
105
|
-
case 'error':
|
|
106
|
-
this.publish({ error: message.message })
|
|
107
|
-
break
|
|
108
|
-
case 'pong':
|
|
109
|
-
break
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
private publish(patch: Partial<CollabConnectionState>, locationChanged = false): void {
|
|
113
|
-
this.state = { ...this.state, ...patch }
|
|
114
|
-
const people = {
|
|
115
|
-
...this.state,
|
|
116
|
-
participants: this.state.participants.map(participant => ({ ...participant, presence: [] }))
|
|
117
|
-
}
|
|
118
|
-
if (locationChanged || JSON.stringify(people) !== JSON.stringify(this.peopleState)) {
|
|
119
|
-
this.peopleState = people
|
|
120
|
-
}
|
|
121
|
-
const channels = new Map<string, CollabPresenceEntry[]>()
|
|
122
|
-
if (this.location && !this.location.away) {
|
|
123
|
-
for (const participant of this.state.participants) {
|
|
124
|
-
if (
|
|
125
|
-
participant.connectionId === this.state.connectionId ||
|
|
126
|
-
participant.location?.page !== this.location.page ||
|
|
127
|
-
participant.location.away
|
|
128
|
-
)
|
|
129
|
-
continue
|
|
130
|
-
for (const registration of participant.presence) {
|
|
131
|
-
const key = channelKey(registration.surface, registration.channel)
|
|
132
|
-
const entries = channels.get(key) ?? []
|
|
133
|
-
entries.push({
|
|
134
|
-
registrationId: registration.registrationId,
|
|
135
|
-
connectionId: participant.connectionId,
|
|
136
|
-
userId: participant.userId,
|
|
137
|
-
value: registration.value
|
|
138
|
-
})
|
|
139
|
-
channels.set(key, entries)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// Keep references for unchanged channels. Only current nonempty channels are
|
|
144
|
-
// retained, so navigating through many records does not grow a selector cache.
|
|
145
|
-
this.channels = new Map(
|
|
146
|
-
[...channels].map(([key, entries]) => {
|
|
147
|
-
const previous = this.channels.get(key)
|
|
148
|
-
return [
|
|
149
|
-
key,
|
|
150
|
-
previous && JSON.stringify(previous) === JSON.stringify(entries) ? previous : entries
|
|
151
|
-
]
|
|
152
|
-
})
|
|
153
|
-
)
|
|
154
|
-
this.listeners.forEach(listener => listener())
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { WorkspaceLayout, WorkspaceLayoutSave } from '@/lib/types'
|
|
2
|
-
|
|
3
|
-
// Unrelated edits must omit tabs from the PUT. Keep the last explicit tab edit
|
|
4
|
-
// through the debounce window, even if a refetch replaces the optimistic cache.
|
|
5
|
-
export function accumulateLayoutSave(
|
|
6
|
-
next: WorkspaceLayout,
|
|
7
|
-
update: Partial<WorkspaceLayout>,
|
|
8
|
-
pending: WorkspaceLayoutSave | null
|
|
9
|
-
): WorkspaceLayoutSave {
|
|
10
|
-
const { tabs: _tabs, ...layout } = next
|
|
11
|
-
const tabs = update.tabs ?? pending?.tabs
|
|
12
|
-
return tabs === undefined ? layout : { ...layout, tabs }
|
|
13
|
-
}
|
package/dist/chunk-1ftessc8.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var f=Object.create;var{getPrototypeOf:k,defineProperty:v,getOwnPropertyNames:y}=Object;var u=Object.prototype.hasOwnProperty;function z(a){return this[a]}var _,j,e=(a,r,t)=>{var l=a!=null&&typeof a==="object";if(l){var n=r?_??=new WeakMap:j??=new WeakMap,o=n.get(a);if(o)return o}t=a!=null?f(k(a)):{};let s=r||!a||!a.__esModule||!u.call(a,"default")?v(t,"default",{value:a,enumerable:!0}):t;if(a&&typeof a==="object"||typeof a==="function"){for(let i of y(a))if(!u.call(s,i))v(s,i,{get:z.bind(a,i),enumerable:!0})}if(l)n.set(a,s);return s};var x=(a,r)=>()=>(r||a((r={exports:{}}).exports,r),r.exports);var C=(a)=>a;function E(a,r){this[a]=C.bind(null,r)}var ne=(a,r)=>{for(var t in r)v(a,t,{get:r[t],enumerable:!0,configurable:!0,set:E.bind(r,t)})};var Ee=((a)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(r,t)=>(typeof require<"u"?require:r)[t]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var b,w,h,B=(a,r)=>{for(var[t,l,n]of b||[])for(var o=[a],s=globalThis,i=s.document,m,p,g,c,d;p=o.pop();)if(!w[p]&&(g=l[p])){w[p]=1;for(c=1;c<g.length;c++)o.push(n[g[c]]);if(!r&&p!==a&&(m=i&&i.head)){if(h===void 0)h=(c=i.querySelector("meta[property=csp-nonce]"))&&(c.nonce||c.getAttribute("nonce"))||"";if(d=i.createElement("link"),d.rel="modulepreload",d.crossOrigin="",h)d.nonce=h;d.href=new s.URL(g[0],t),m.appendChild(d)}}},q=(a,r,t,l)=>{for(var n={},o=0;o<r.length;o++)n[r[o]]=t[o];(b||=[]).push([a,n,r]),w||={},B(r[l],1)};q(import.meta.url,["1ftessc8","9cm0wjah","542a2m9m","xpt063fx","nf2wkvf9","gptm4jpd","cvgdm1hq","3802vh2p","7r4z77ry","5745d83v","5zxdsjym","wnmf38ta"],[["/chunk-1ftessc8.js"],["/chunk-9cm0wjah.js",6,7,8,9,0],["/chunk-542a2m9m.js",9,8],["/chunk-xpt063fx.js",8,7],["/chunk-nf2wkvf9.js"],["/chunk-gptm4jpd.js",11,6,8,0],["/chunk-cvgdm1hq.js",0,8],["/chunk-3802vh2p.js"],["/chunk-7r4z77ry.js",0],["/chunk-5745d83v.js",8,0],["/chunk-5zxdsjym.js",11],["/chunk-wnmf38ta.js"]],0);
|
|
2
|
-
if(typeof globalThis.structuredClone==="function")globalThis.structuredClone=globalThis.structuredClone.bind(globalThis);async function A(a){let[{mount:r}]=await Promise.all([(B("9cm0wjah"),import("/chunk-9cm0wjah.js")),(B("542a2m9m"),import("/chunk-542a2m9m.js")).then((t)=>t.loadAppConfig()),(B("xpt063fx"),import("/chunk-xpt063fx.js")).then((t)=>t.loadProxyIdentity())]);r(a)}globalThis.__init=A;export{e,x,ne,Ee,B};
|
package/dist/chunk-3802vh2p.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var De=8192;function E(t){return typeof t==="object"&&t!==null&&!Array.isArray(t)}function a(t,e=256){return typeof t==="string"&&t.length>0&&!t.includes("\x00")&&new TextEncoder().encode(t).length<=e}function S(t){return E(t)&&a(t.id,240)&&t.id.trim().length>0&&(t.name===void 0||t.name===""||a(t.name))&&a(t.color,64)&&(t.avatar===void 0||a(t.avatar,8192))&&(t.email===void 0||a(t.email,320))}var h="moi:collab:dev-profile",s=null,I=!1,p=null,i=null,c=new Set,l=new Map,b=new Set,g=Object.freeze([]),x=Object.freeze({}),O=Object.freeze({status:"loading"}),A=Object.freeze({status:"unavailable",users:g}),L=Object.freeze({status:"loading",users:g}),d=null;function u(t){if(!t||typeof t.id!=="string"||!t.id.trim())throw Error("An identity needs an id.");if(t.name!==void 0&&typeof t.name!=="string")throw Error("An identity name must be a string when provided.");let e={id:t.id.trim(),...t.name!==void 0?{name:t.name.trim()}:{},color:/^#[0-9a-f]{6}$/i.test(t.color)?t.color:"#0f766e",...t.avatar!==void 0?{avatar:t.avatar}:{},...t.email!==void 0?{email:t.email}:{}};if(!S(e))throw Error("Invalid user profile.");return Object.freeze(e)}function k(t){if(!Array.isArray(t))throw Error("Workspace users must be an array.");let e=new Set,n=t.map((o)=>{let r=u(o);if(e.has(r.id))throw Error("Workspace users must have unique ids.");return e.add(r.id),r});return Object.freeze(n)}function _(t){if(!t||typeof t!=="object")throw Error("Invalid host state.");let e=t.identity===null?null:u(t.identity);if(!t.workspaces||typeof t.workspaces!=="object"||Array.isArray(t.workspaces))throw Error("Host workspaces must be a record.");let n=Object.entries(t.workspaces).map(([o,r])=>{if(!o.trim()||!r||typeof r!=="object")throw Error("Invalid workspace directory.");if(r.status==="loading")return[o,O];if(r.status!=="ready")throw Error("Invalid workspace directory status.");let y=k(r.users),m=Object.freeze(y.map((w)=>e&&w.id===e.id?e:w));return[o,Object.freeze({status:"ready",users:m})]});return Object.freeze({identity:e,workspaces:e?Object.freeze(Object.fromEntries(n)):x})}function C(){return d}function fe(t){if(!d)return A;let e=Object.hasOwn(d.workspaces,t)?d.workspaces[t]:void 0;return e?.status==="ready"?e:L}function Oe(t){let e=fe(t);return e.status==="unavailable"?null:e.users}function f(t){let e=_(t),n=new Map([...l.keys()].map((o)=>[o,fe(o)]));d=e,i="external",s=e.identity,c.forEach((o)=>o());for(let[o,r]of l)if(fe(o)!==n.get(o))r.forEach((y)=>y());b.forEach((o)=>o())}function H(t){return b.add(t),()=>{b.delete(t)}}function R(t){let e=H(()=>t(C()));return t(C()),e}function Ne(t,e){let n=l.get(t);if(!n)n=new Set,l.set(t,n);return n.add(e),()=>{if(n.delete(e),!n.size)l.delete(t)}}function N(){return s}function Q(t){return c.add(t),()=>{c.delete(t)}}function Le(){return i}function Fe({provider:t,identity:e}){if(i==="external")return;if(t===null){if(i===null||i==="dev")return;i=null,s=null}else{let n=e===null?null:u(e);if(i===t&&JSON.stringify(s)===JSON.stringify(n))return;i=t,s=n}c.forEach((n)=>n())}async function Be(t){let e=new URL(`/workspace/${encodeURIComponent(t)}`,location.origin).href;if(p){let n=await p({workspaceId:t,url:e}),o=new URL(n.url);if(o.protocol!=="https:"&&o.protocol!=="http:")throw Error("The share handler returned an invalid URL.");return await navigator.clipboard.writeText(o.href),"copied"}return await navigator.clipboard.writeText(e),"copied"}function ze(){if(typeof window>"u"||I)return;I=!0;let t=window,e=t.moi?.collab;if(e?.getHostState)try{f(e.getHostState()??{identity:null,workspaces:{}})}catch{f({identity:null,workspaces:{}})}else if(i===null)try{let n=sessionStorage.getItem(h);if(n)s=u(JSON.parse(n)),i="dev"}catch{}if(t.moi??={},t.moi.collab={getHostState:C,setHostState:f,subscribeHostState:R,setShareHandler(n){p=n}},typeof window.dispatchEvent==="function")window.dispatchEvent(new CustomEvent("moi:collab-ready"))}
|
|
2
|
-
export{De,fe,Oe,Ne,N,Q,Le,Fe,Be,ze};
|
package/dist/chunk-542a2m9m.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Ve,D}from"/chunk-5745d83v.js";import"/chunk-7r4z77ry.js";export{Ve as loadAppConfig,D as useAppConfig};
|
package/dist/chunk-5745d83v.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{t,f,ee}from"/chunk-7r4z77ry.js";import{e}from"/chunk-1ftessc8.js";var p=e(t(),1);var n={collab:!1},c=Object.keys(n);var a={cloudDemo:!1,experimental:{...n},demoInstallUrl:"https://moi.computer"},s=a,r=new Set;function l(o){return r.add(o),()=>{r.delete(o)}}async function i(){try{s=await f("/api/config");for(let o of r)o()}catch{}}async function Ve(){await i(),ee(()=>{i()})}function D(){return p.useSyncExternalStore(l,()=>s)}
|
|
2
|
-
export{Ve,D};
|
package/dist/chunk-5zxdsjym.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Ue}from"/chunk-wnmf38ta.js";export{Ue as sanitizeSvg};
|
package/dist/chunk-7r4z77ry.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{e,x}from"/chunk-1ftessc8.js";var t=x(function(q,v){v.exports=globalThis.__esm.react});async function m(n,s){let o=await n.text();return Error(o||s)}async function f(n,s,o="Request failed"){let i=await fetch(n,s);if(!i.ok)throw await m(i,o);return i.json()}async function O(n,s,o="Request failed"){let i=await fetch(n,s);if(!i.ok)throw await m(i,o)}function k(n,s){return{method:n,headers:{"Content-Type":"application/json"},body:s===void 0?void 0:JSON.stringify(s)}}var w=e(t(),1);var d=e(t(),1);function I(n){let s=d.useRef(n);return d.useLayoutEffect(()=>{s.current=n},[n]),s}function se(n){return`${location.protocol==="https:"?"wss":"ws"}://${location.host}${n}`}var c=new Set,l=new Set,h=!1,r=null,p=!1,R=1000,S=30000,g=0;function b(){let n=Math.min(R*2**g,S);g++,setTimeout(E,n)}function E(){if(r||p)return;p=!0;let n=new WebSocket(se("/api/workspaces/ws"));n.onopen=()=>{if(r=n,p=!1,g=0,a(),h)for(let s of l)s();h=!0},n.onmessage=(s)=>{try{let o=JSON.parse(s.data);for(let i of c)i(o)}catch{}},n.onclose=()=>{if(r=null,p=!1,c.size>0)b()},n.onerror=()=>{n.close()}}function ee(n){return l.add(n),()=>{l.delete(n)}}function P(n){let s=I(n);w.useEffect(()=>{let o=(i)=>s.current(i);return c.add(o),E(),()=>{if(c.delete(o),c.size===0&&r)r.close(),r=null}},[s])}var u=null;function a(){if(r?.readyState!==WebSocket.OPEN)return;r.send(JSON.stringify({type:"navigation:presence",workspaceId:u,focused:document.visibilityState==="visible"&&document.hasFocus()}))}function He(n,s){w.useEffect(()=>(u=n,a(),window.addEventListener("focus",a),document.addEventListener("visibilitychange",a),()=>{u=null,a(),window.removeEventListener("focus",a),document.removeEventListener("visibilitychange",a)}),[n]),P((o)=>{if(o.type!=="navigation:request"||o.workspaceId!==n)return;let i=r;try{if(u!==n)throw Error("The browser switched workspaces.");s(o.href),i?.send(JSON.stringify({type:"navigation:result",requestId:o.requestId,ok:!0}))}catch(y){i?.send(JSON.stringify({type:"navigation:result",requestId:o.requestId,error:y instanceof Error?y.message:"Navigation failed"}))}})}
|
|
2
|
-
export{t,se,f,O,k,I,ee,P,He};
|