MCPcopy Create free account
hub / github.com/MagicCube/agentara / createSession

Method createSession

src/kernel/sessioning/session-manager.ts:102–145  ·  view source on GitHub ↗

* Creates a new session and inserts a row into the database. * @param sessionId - The session identifier. * @param options - Optional agent_type and cwd (default from config). * @returns A Session instance with isNewSession: true. * @throws SessionAlreadyExistsError if the session alread

(
    sessionId = uuid(),
    options?: SessionResolveOptions,
  )

Source from the content-addressed store, hash-verified

100 * @throws SessionAlreadyExistsError if the session already exists.
101 */
102 async createSession(
103 sessionId = uuid(),
104 options?: SessionResolveOptions,
105 ): Promise<Session> {
106 if (this.existsSession(sessionId)) {
107 throw new SessionAlreadyExistsError(sessionId);
108 }
109
110 const agentType = options?.agentType ?? config.agents.default.type;
111 const cwd = options?.cwd ?? config.paths.home;
112 const channelId = options?.channelId ?? null;
113 const now = Date.now();
114
115 this._db
116 .insert(sessions)
117 .values({
118 id: sessionId,
119 agent_type: agentType,
120 cwd,
121 channel_id: channelId,
122 last_message_created_at: null,
123 runner_session_id: null,
124 created_at: now,
125 updated_at: now,
126 })
127 .run();
128
129 if (options?.firstMessage) {
130 this._updateFirstMessage(
131 sessionId,
132 extractTextContent(options.firstMessage),
133 );
134 }
135
136 this._logger.info(`Creating session: ${sessionId}`);
137 const session = new Session(sessionId, agentType, {
138 isNewSession: true,
139 cwd,
140 runnerSessionId: undefined,
141 });
142 this._attachWriter(session, sessionId);
143
144 return session;
145 }
146
147 /**
148 * Creates a session for a handoff from an external Claude Code instance.

Callers 1

resolveSessionMethod · 0.95

Calls 6

existsSessionMethod · 0.95
_updateFirstMessageMethod · 0.95
_attachWriterMethod · 0.95
uuidFunction · 0.90
extractTextContentFunction · 0.90
runMethod · 0.80

Tested by

no test coverage detected