Skip to content

Commit 12f2c0e

Browse files
committed
refactor(runtime): rename cki → cpki and use INTELLIGENCE_USER_ID_HEADER constant
Two CR comments addressed: - Rename the local destructure of forwardedProps.auth.copilotkitIntelligence from 'cki' to 'cpki' so it matches the project-wide abbreviation already used in metadata fields (cpki_event_id, cpki_event_seq, etc). - Replace the inline 'X-Cpki-User-Id' string literal with the existing INTELLIGENCE_USER_ID_HEADER constant exported from intelligence-platform/client. Applies to the runtime auto-attach in agent/index.ts and to the three test sites in intelligence-mcp-helper.test.ts so the user-side and runtime-side stay in sync.
1 parent 3e7449d commit 12f2c0e

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

packages/runtime/src/agent/index.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { jsonSchema as aiJsonSchema } from "ai";
5151
import { convertAISDKStream } from "./converters/aisdk";
5252
import { convertTanStackStream } from "./converters/tanstack";
5353
import type { StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
54+
import { INTELLIGENCE_USER_ID_HEADER } from "../v2/runtime/intelligence-platform/client";
5455
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
5556
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
5657
import { randomUUID } from "@copilotkit/shared";
@@ -1200,29 +1201,29 @@ export class BuiltInAgent extends AbstractAgent {
12001201
| { auth?: { copilotkitIntelligence?: unknown } }
12011202
| undefined
12021203
)?.auth;
1203-
const cki = auth?.copilotkitIntelligence as
1204+
const cpki = auth?.copilotkitIntelligence as
12041205
| { userId?: unknown; apiKey?: unknown; mcpUrl?: unknown }
12051206
| undefined;
1206-
const ckiUserId =
1207-
typeof cki?.userId === "string" ? cki.userId : undefined;
1208-
const ckiApiKey =
1209-
typeof cki?.apiKey === "string" ? cki.apiKey : undefined;
1210-
const ckiMcpUrl =
1211-
typeof cki?.mcpUrl === "string" ? cki.mcpUrl : undefined;
1207+
const cpkiUserId =
1208+
typeof cpki?.userId === "string" ? cpki.userId : undefined;
1209+
const cpkiApiKey =
1210+
typeof cpki?.apiKey === "string" ? cpki.apiKey : undefined;
1211+
const cpkiMcpUrl =
1212+
typeof cpki?.mcpUrl === "string" ? cpki.mcpUrl : undefined;
12121213
if (
1213-
ckiUserId &&
1214-
ckiApiKey &&
1215-
ckiMcpUrl &&
1216-
!allMcpServers.some((s) => s.type === "http" && s.url === ckiMcpUrl)
1214+
cpkiUserId &&
1215+
cpkiApiKey &&
1216+
cpkiMcpUrl &&
1217+
!allMcpServers.some((s) => s.type === "http" && s.url === cpkiMcpUrl)
12171218
) {
12181219
allMcpServers.push({
12191220
type: "http",
1220-
url: ckiMcpUrl,
1221+
url: cpkiMcpUrl,
12211222
options: {
12221223
fetch: async (req, init) => {
12231224
const headers = new Headers(init?.headers);
1224-
headers.set("Authorization", `Bearer ${ckiApiKey}`);
1225-
headers.set("X-Cpki-User-Id", ckiUserId);
1225+
headers.set("Authorization", `Bearer ${cpkiApiKey}`);
1226+
headers.set(INTELLIGENCE_USER_ID_HEADER, cpkiUserId);
12261227
return globalThis.fetch(req, { ...init, headers });
12271228
},
12281229
},

packages/runtime/src/v2/runtime/intelligence-platform/__tests__/intelligence-mcp-helper.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
22
import { BasicAgent } from "../../../../agent";
3+
import { INTELLIGENCE_USER_ID_HEADER } from "../client";
34
import { LLMock, MCPMock } from "@copilotkit/aimock";
45
import { streamText } from "ai";
56
import {
@@ -128,7 +129,7 @@ describe("BuiltInAgent — Intelligence MCP auto-attach via forwardedProps", ()
128129
expect(recorder.records.length).toBeGreaterThan(0);
129130
for (const headers of recorder.records) {
130131
expect(headers["authorization"]).toBe("Bearer cpk-proj_short_long");
131-
expect(headers["x-cpki-user-id"]).toBe("jordan-beamson");
132+
expect(headers[INTELLIGENCE_USER_ID_HEADER]).toBe("jordan-beamson");
132133
}
133134
} finally {
134135
recorder.restore();
@@ -203,7 +204,7 @@ describe("BuiltInAgent — Intelligence MCP auto-attach via forwardedProps", ()
203204
userFetchCalls++;
204205
const h = new Headers(init?.headers ?? {});
205206
h.set("Authorization", "Bearer user-supplied");
206-
h.set("X-Cpki-User-Id", "explicit-user");
207+
h.set(INTELLIGENCE_USER_ID_HEADER, "explicit-user");
207208
return globalThis.fetch(input, { ...init, headers: h });
208209
},
209210
},
@@ -235,7 +236,7 @@ describe("BuiltInAgent — Intelligence MCP auto-attach via forwardedProps", ()
235236
// Only the user's fetch wrapper hit the wire — auto-attach skipped.
236237
for (const headers of recorder.records) {
237238
expect(headers["authorization"]).toBe("Bearer user-supplied");
238-
expect(headers["x-cpki-user-id"]).toBe("explicit-user");
239+
expect(headers[INTELLIGENCE_USER_ID_HEADER]).toBe("explicit-user");
239240
}
240241
expect(userFetchCalls).toBeGreaterThan(0);
241242
} finally {

0 commit comments

Comments
 (0)