{"version":3,"file":"threads.mjs","names":[],"sources":["../../../../../src/v2/runtime/handlers/intelligence/threads.ts"],"sourcesContent":["import {\n  CopilotIntelligenceRuntimeLike,\n  CopilotRuntimeLike,\n  isIntelligenceRuntime,\n} from \"../../core/runtime\";\nimport { logger } from \"@copilotkit/shared\";\nimport { errorResponse, isHandlerResponse } from \"../shared/json-response\";\nimport { isValidIdentifier } from \"../shared/intelligence-utils\";\nimport { resolveIntelligenceUser } from \"../shared/resolve-intelligence-user\";\nimport { InMemoryAgentRunner } from \"../../runner/in-memory\";\n\ninterface ThreadsHandlerParams {\n  runtime: CopilotRuntimeLike;\n  request: Request;\n}\n\ninterface ThreadMutationParams extends ThreadsHandlerParams {\n  threadId: string;\n}\n\ninterface ThreadMutationContext {\n  userId: string;\n  agentId: string;\n  body: Record<string, unknown>;\n}\n\nasync function parseJsonBody(\n  request: Request,\n): Promise<Record<string, unknown> | Response> {\n  try {\n    return (await request.json()) as Record<string, unknown>;\n  } catch (error) {\n    logger.error({ err: error }, \"Malformed JSON in request body\");\n    return errorResponse(\"Invalid request body\", 400);\n  }\n}\n\nfunction requireIntelligenceRuntime(\n  runtime: CopilotRuntimeLike,\n): CopilotIntelligenceRuntimeLike | Response {\n  if (!isIntelligenceRuntime(runtime)) {\n    return errorResponse(\n      \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n      422,\n    );\n  }\n\n  return runtime;\n}\n\nasync function resolveThreadMutationContext(\n  runtime: CopilotIntelligenceRuntimeLike,\n  request: Request,\n): Promise<ThreadMutationContext | Response> {\n  const body = await parseJsonBody(request);\n  if (isHandlerResponse(body)) return body;\n\n  const user = await resolveIntelligenceUser({ runtime, request });\n  if (isHandlerResponse(user)) return user;\n\n  const agentId = body.agentId;\n  if (!isValidIdentifier(agentId)) {\n    return errorResponse(\"Valid agentId is required\", 400);\n  }\n\n  return {\n    body,\n    userId: user.id,\n    agentId,\n  };\n}\n\nexport async function handleListThreads({\n  runtime,\n  request,\n}: ThreadsHandlerParams): Promise<Response> {\n  // Intelligence platform path\n  if (isIntelligenceRuntime(runtime)) {\n    try {\n      const url = new URL(request.url);\n      const agentId = url.searchParams.get(\"agentId\");\n      const includeArchived =\n        url.searchParams.get(\"includeArchived\") === \"true\";\n      const limitParam = url.searchParams.get(\"limit\");\n      const cursor = url.searchParams.get(\"cursor\");\n      const user = await resolveIntelligenceUser({ runtime, request });\n      if (isHandlerResponse(user)) return user;\n\n      if (!isValidIdentifier(agentId)) {\n        return errorResponse(\"Valid agentId query param is required\", 400);\n      }\n\n      const data = await runtime.intelligence.listThreads({\n        userId: user.id,\n        agentId,\n        ...(includeArchived ? { includeArchived: true } : {}),\n        ...(limitParam ? { limit: Number(limitParam) } : {}),\n        ...(cursor ? { cursor } : {}),\n      });\n\n      return Response.json(data);\n    } catch (error) {\n      logger.error({ err: error }, \"Error listing threads\");\n      return errorResponse(\"Failed to list threads\", 500);\n    }\n  }\n\n  // Local in-memory fallback — useful for local development without Intelligence\n  if (runtime.runner instanceof InMemoryAgentRunner) {\n    const url = new URL(request.url);\n    const agentId = url.searchParams.get(\"agentId\");\n    let threads = runtime.runner.listThreads();\n    if (agentId) {\n      threads = threads.filter((t) => t.agentId === agentId);\n    }\n    return Response.json({ threads, nextCursor: null });\n  }\n\n  return errorResponse(\n    \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n    422,\n  );\n}\n\n/**\n * Clears all in-memory thread history for the local-dev InMemory fallback.\n *\n * The local-dev fallback exposes this so consumers (e.g. the demo's Clear\n * button) can wipe in-memory thread history without restarting the runtime.\n * Intentionally a no-op when the Intelligence platform is configured: real\n * thread history lives in the database and must not be wiped by a\n * client-side page load.\n */\nexport function handleClearThreads({\n  runtime,\n}: ThreadsHandlerParams): Response {\n  if (runtime.runner instanceof InMemoryAgentRunner) {\n    runtime.runner.clearThreads();\n  }\n  return new Response(null, { status: 204 });\n}\n\nexport async function handleUpdateThread({\n  runtime,\n  request,\n  threadId,\n}: ThreadMutationParams): Promise<Response> {\n  const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n  if (isHandlerResponse(intelligenceRuntime)) {\n    return intelligenceRuntime;\n  }\n\n  try {\n    const mutation = await resolveThreadMutationContext(\n      intelligenceRuntime,\n      request,\n    );\n    if (isHandlerResponse(mutation)) return mutation;\n\n    const updates = { ...mutation.body };\n    delete updates.agentId;\n    delete updates.userId;\n\n    const thread = await intelligenceRuntime.intelligence.updateThread({\n      threadId,\n      userId: mutation.userId,\n      agentId: mutation.agentId,\n      updates,\n    });\n\n    return Response.json(thread);\n  } catch (error) {\n    logger.error({ err: error, threadId }, \"Error updating thread\");\n    return errorResponse(\"Failed to update thread\", 500);\n  }\n}\n\nexport async function handleSubscribeToThreads({\n  runtime,\n  request,\n}: ThreadsHandlerParams): Promise<Response> {\n  const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n  if (isHandlerResponse(intelligenceRuntime)) {\n    return intelligenceRuntime;\n  }\n\n  try {\n    const user = await resolveIntelligenceUser({\n      runtime: intelligenceRuntime,\n      request,\n    });\n    if (isHandlerResponse(user)) return user;\n\n    const credentials =\n      await intelligenceRuntime.intelligence.ɵsubscribeToThreads({\n        userId: user.id,\n      });\n\n    return Response.json({ joinToken: credentials.joinToken });\n  } catch (error) {\n    logger.error({ err: error }, \"Error subscribing to threads\");\n    return errorResponse(\"Failed to subscribe to threads\", 500);\n  }\n}\n\nexport async function handleArchiveThread({\n  runtime,\n  request,\n  threadId,\n}: ThreadMutationParams): Promise<Response> {\n  const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n  if (isHandlerResponse(intelligenceRuntime)) {\n    return intelligenceRuntime;\n  }\n\n  try {\n    const mutation = await resolveThreadMutationContext(\n      intelligenceRuntime,\n      request,\n    );\n    if (isHandlerResponse(mutation)) return mutation;\n\n    await intelligenceRuntime.intelligence.archiveThread({\n      threadId,\n      userId: mutation.userId,\n      agentId: mutation.agentId,\n    });\n\n    return Response.json({ threadId, archived: true });\n  } catch (error) {\n    logger.error({ err: error, threadId }, \"Error archiving thread\");\n    return errorResponse(\"Failed to archive thread\", 500);\n  }\n}\n\nexport async function handleDeleteThread({\n  runtime,\n  request,\n  threadId,\n}: ThreadMutationParams): Promise<Response> {\n  const intelligenceRuntime = requireIntelligenceRuntime(runtime);\n  if (isHandlerResponse(intelligenceRuntime)) {\n    return intelligenceRuntime;\n  }\n\n  try {\n    const mutation = await resolveThreadMutationContext(\n      intelligenceRuntime,\n      request,\n    );\n    if (isHandlerResponse(mutation)) return mutation;\n\n    await intelligenceRuntime.intelligence.deleteThread({\n      threadId,\n      userId: mutation.userId,\n      agentId: mutation.agentId,\n    });\n\n    return Response.json({ threadId, deleted: true });\n  } catch (error) {\n    logger.error({ err: error, threadId }, \"Error deleting thread\");\n    return errorResponse(\"Failed to delete thread\", 500);\n  }\n}\n\nexport async function handleGetThreadMessages({\n  runtime,\n  request,\n  threadId,\n}: ThreadMutationParams): Promise<Response> {\n  // Intelligence platform path\n  if (isIntelligenceRuntime(runtime)) {\n    try {\n      const user = await resolveIntelligenceUser({ runtime, request });\n      if (isHandlerResponse(user)) return user;\n\n      const data = await runtime.intelligence.getThreadMessages({ threadId });\n      return Response.json(data);\n    } catch (error) {\n      logger.error({ err: error, threadId }, \"Error fetching thread messages\");\n      return errorResponse(\"Failed to fetch thread messages\", 500);\n    }\n  }\n\n  // Local in-memory fallback — useful for local development without Intelligence\n  if (runtime.runner instanceof InMemoryAgentRunner) {\n    const messages = runtime.runner.getThreadMessages(threadId);\n    // Map ag-ui Message objects to the same shape the Intelligence platform\n    // returns. Switching on the discriminant `role` lets each branch read\n    // the narrowed message arm directly, instead of laundering through\n    // `Record<string, unknown>` and chained `as` casts.\n    const mapped = messages.map((msg) => {\n      switch (msg.role) {\n        case \"assistant\": {\n          const toolCalls = msg.toolCalls ?? [];\n          return {\n            id: msg.id,\n            role: msg.role,\n            ...(msg.content !== undefined ? { content: msg.content } : {}),\n            ...(toolCalls.length > 0\n              ? {\n                  toolCalls: toolCalls.map((tc) => ({\n                    id: tc.id,\n                    name: tc.function.name,\n                    args: tc.function.arguments,\n                  })),\n                }\n              : {}),\n          };\n        }\n        case \"tool\":\n          return {\n            id: msg.id,\n            role: msg.role,\n            content: msg.content,\n            toolCallId: msg.toolCallId,\n          };\n        default:\n          return {\n            id: msg.id,\n            role: msg.role,\n            ...(\"content\" in msg && msg.content !== undefined\n              ? { content: msg.content }\n              : {}),\n          };\n      }\n    });\n    return Response.json({ messages: mapped });\n  }\n\n  return errorResponse(\n    \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n    422,\n  );\n}\n\nexport async function handleGetThreadEvents({\n  runtime,\n  request,\n  threadId,\n}: ThreadMutationParams): Promise<Response> {\n  // Intelligence platform path. Delegates to the platform's `_inspect`\n  // endpoint (Intelligence PR #144). Auth still flows through the standard\n  // identifyUser → API key path; threadId scoping happens server-side.\n  if (isIntelligenceRuntime(runtime)) {\n    try {\n      const user = await resolveIntelligenceUser({ runtime, request });\n      if (isHandlerResponse(user)) return user;\n\n      const data = await runtime.intelligence.getThreadEvents({ threadId });\n      // Strip platform-internal fields (`decodeErrorRowIds`, `truncated`)\n      // before returning to the inspector — those describe persistence-side\n      // concerns the inspector currently has no UI for. The shape becomes\n      // `{ events }`, matching the in-memory branch below.\n      return Response.json({ events: data.events });\n    } catch (error) {\n      logger.error({ err: error, threadId }, \"Error fetching thread events\");\n      return errorResponse(\"Failed to fetch thread events\", 500);\n    }\n  }\n\n  // Local in-memory fallback\n  if (runtime.runner instanceof InMemoryAgentRunner) {\n    try {\n      const events = runtime.runner.getThreadEvents(threadId);\n      return Response.json({ events });\n    } catch (error) {\n      logger.error({ err: error, threadId }, \"Error fetching thread events\");\n      return errorResponse(\"Failed to fetch thread events\", 500);\n    }\n  }\n\n  return errorResponse(\n    \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n    422,\n  );\n}\n\nexport async function handleGetThreadState({\n  runtime,\n  request,\n  threadId,\n}: ThreadMutationParams): Promise<Response> {\n  // Intelligence platform path. Delegates to the platform's `_inspect`\n  // state endpoint, which folds STATE_DELTA events onto the latest\n  // STATE_SNAPSHOT to return the thread's current state.\n  if (isIntelligenceRuntime(runtime)) {\n    try {\n      const user = await resolveIntelligenceUser({ runtime, request });\n      if (isHandlerResponse(user)) return user;\n\n      const data = await runtime.intelligence.getThreadState({ threadId });\n      // Flatten the discriminated `ThreadStateResult` to the wire shape the\n      // inspector consumes (`{ state: <value> | null }`). Missing snapshot\n      // and decode-error both surface as `null`; the inspector renders an\n      // empty state branch for null and the platform's decode-error case is\n      // already logged platform-side.\n      const state = data.kind === \"snapshot\" ? data.state : null;\n      return Response.json({ state });\n    } catch (error) {\n      logger.error({ err: error, threadId }, \"Error fetching thread state\");\n      return errorResponse(\"Failed to fetch thread state\", 500);\n    }\n  }\n\n  if (runtime.runner instanceof InMemoryAgentRunner) {\n    try {\n      const state = runtime.runner.getThreadState(threadId);\n      return Response.json({ state });\n    } catch (error) {\n      logger.error({ err: error, threadId }, \"Error fetching thread state\");\n      return errorResponse(\"Failed to fetch thread state\", 500);\n    }\n  }\n\n  return errorResponse(\n    \"Missing CopilotKitIntelligence configuration. Thread operations require a CopilotKitIntelligence instance to be provided in CopilotRuntime options.\",\n    422,\n  );\n}\n"],"mappings":";;;;;;;;;AA0BA,eAAe,cACb,SAC6C;AAC7C,KAAI;AACF,SAAQ,MAAM,QAAQ,MAAM;UACrB,OAAO;AACd,SAAO,MAAM,EAAE,KAAK,OAAO,EAAE,iCAAiC;AAC9D,SAAO,cAAc,wBAAwB,IAAI;;;AAIrD,SAAS,2BACP,SAC2C;AAC3C,KAAI,CAAC,sBAAsB,QAAQ,CACjC,QAAO,cACL,uJACA,IACD;AAGH,QAAO;;AAGT,eAAe,6BACb,SACA,SAC2C;CAC3C,MAAM,OAAO,MAAM,cAA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