MCPcopy
hub / github.com/vercel/hyper / createSession

Function createSession

app/ui/window.ts:126–160  ·  view source on GitHub ↗
(extraOptions: any = {})

Source from the content-addressed store, hash-verified

124 });
125
126 function createSession(extraOptions: any = {}) {
127 const uid = uuidv4();
128 const extraOptionsFiltered: any = {};
129 Object.keys(extraOptions).forEach((key) => {
130 if (extraOptions[key] !== undefined) extraOptionsFiltered[key] = extraOptions[key];
131 });
132
133 let cwd = '';
134 if (cfg.preserveCWD === undefined || cfg.preserveCWD) {
135 const activePID = extraOptionsFiltered.activeUid && sessions.get(extraOptionsFiltered.activeUid)?.pty?.pid;
136 try {
137 cwd = activePID && getWorkingDirectoryFromPID(activePID);
138 } catch (error) {
139 console.error(error);
140 }
141 cwd = cwd && isAbsolute(cwd) ? cwd : '';
142 }
143
144 // remove the rows and cols, the wrong value of them will break layout when init create
145 const defaultOptions = Object.assign(
146 {
147 cwd: cwd || workingDirectory,
148 splitDirection: undefined,
149 shell: cfg.shell,
150 shellArgs: cfg.shellArgs && Array.from(cfg.shellArgs)
151 },
152 extraOptionsFiltered,
153 {uid}
154 );
155 const options = decorateSessionOptions(defaultOptions);
156 const DecoratedSession = decorateSessionClass(Session);
157 const session = new DecoratedSession(options);
158 sessions.set(uid, session);
159 return {session, options};
160 }
161
162 rpc.on('new', (extraOptions) => {
163 const {session, options} = createSession(extraOptions);

Callers 1

newWindowFunction · 0.85

Calls 6

decorateSessionOptionsFunction · 0.90
decorateSessionClassFunction · 0.90
getMethod · 0.80
setMethod · 0.80
forEachMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected