MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / spawn

Method spawn

src/workspaces/session-pool.ts:91–124  ·  view source on GitHub ↗

Spawn a PTY for a pre-allocated record.

(wsId: string, factoryCtx: SessionFactoryContext)

Source from the content-addressed store, hash-verified

89
90 /** Spawn a PTY for a pre-allocated record. */
91 spawn(wsId: string, factoryCtx: SessionFactoryContext): PersistentSession {
92 const recordId = factoryCtx.recordId;
93 const { opts, adapter } = this.configFactory(wsId, factoryCtx);
94 const session = new PersistentSession({
95 ...opts,
96 wsId,
97 recordId,
98 name: factoryCtx.recordName,
99 onDisposed: () => this.onSessionDisposed(wsId, recordId),
100 });
101
102 this.sessions.set(recordId, session);
103 this.adapterFor.set(recordId, adapter);
104 let ids = this.byWs.get(wsId);
105 if (!ids) {
106 ids = new Set();
107 this.byWs.set(wsId, ids);
108 }
109 ids.add(recordId);
110 this.logger.info('pool.session_created', {
111 wsId,
112 recordId,
113 name: factoryCtx.recordName,
114 agent: adapter.id,
115 total: this.sessions.size,
116 forWorkspace: ids.size,
117 });
118 if (this.transcriptWatcher) {
119 // Fire-and-forget — the watcher logs its own errors. A failed register
120 // just means agentSessionId stays null, which is a tooltip cosmetic.
121 void this.transcriptWatcher.register(session, adapter);
122 }
123 return session;
124 }
125
126 /** Attach a WebSocket to a known record. Returns false if id is unknown. */
127 attachById(

Callers

nothing calls this directly

Calls 6

onSessionDisposedMethod · 0.95
infoMethod · 0.80
setMethod · 0.65
getMethod · 0.65
addMethod · 0.65
registerMethod · 0.65

Tested by

no test coverage detected