MCPcopy
hub / github.com/nowork-studio/NotFair / getOrCreateSession

Function getOrCreateSession

notfair-cmo/src/server/sessions/index.ts:52–92  ·  view source on GitHub ↗
(input: {
  project_slug: string;
  agent_id: string;
  label: string;
  harness_adapter: HarnessAdapterId;
  task_id?: string | null;
})

Source from the content-addressed store, hash-verified

50}
51
52export function getOrCreateSession(input: {
53 project_slug: string;
54 agent_id: string;
55 label: string;
56 harness_adapter: HarnessAdapterId;
57 task_id?: string | null;
58}): Session {
59 const db = getDb();
60 const existing = db
61 .prepare(
62 "SELECT * FROM sessions WHERE project_slug = ? AND agent_id = ? AND label = ?",
63 )
64 .get(input.project_slug, input.agent_id, input.label) as SessionRow | undefined;
65 if (existing) return rowToSession(existing);
66
67 const session: Session = {
68 id: randomUUID(),
69 project_slug: input.project_slug,
70 agent_id: input.agent_id,
71 label: input.label,
72 harness_adapter: input.harness_adapter,
73 harness_session_id: null,
74 task_id: input.task_id ?? null,
75 created_at: new Date().toISOString(),
76 updated_at: new Date().toISOString(),
77 };
78
79 db.prepare(
80 "INSERT INTO sessions (id, project_slug, agent_id, label, harness_adapter, harness_session_id, task_id, created_at, updated_at) VALUES (?, ?, ?, ?, ?, NULL, ?, ?, ?)",
81 ).run(
82 session.id,
83 session.project_slug,
84 session.agent_id,
85 session.label,
86 session.harness_adapter,
87 session.task_id,
88 session.created_at,
89 session.updated_at,
90 );
91 return session;
92}
93
94export function getSession(id: string): Session | null {
95 const row = getDb()

Callers 6

POSTFunction · 0.90
materializeSessionFunction · 0.90
dispatchJobFunction · 0.90
runTaskKickoffServerSideFunction · 0.90

Calls 2

getDbFunction · 0.90
rowToSessionFunction · 0.85

Tested by

no test coverage detected