Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/appkit/src/plugins/genie/genie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class GeniePlugin extends Plugin {
});
}

private defaultSpaces(): Record<string, string> {
private defaultSpaces(): Record<string, string | undefined> {
const spaceId = process.env.DATABRICKS_GENIE_SPACE_ID;
return spaceId ? { default: spaceId } : {};
}
Expand Down
33 changes: 33 additions & 0 deletions packages/appkit/src/plugins/genie/tests/genie.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,39 @@ describe("Genie Plugin", () => {
error: "Unknown space alias: default",
});
});

test("should 404 when an alias maps to undefined (e.g. unset process.env.X)", async () => {
// The IGenieConfig.spaces type accepts `string | undefined` so callers
// can pass process.env values directly. Resolution still falls through
// to "Unknown space alias", same as a missing key.
delete process.env.DATABRICKS_GENIE_SPACE_ID;

const plugin = new GeniePlugin({
timeout: 5000,
spaces: { wanderbricks: process.env.DATABRICKS_GENIE_SPACE_ID },
});
const { router, getHandler } = createMockRouter();

plugin.injectRoutes(router);

const handler = getHandler("POST", "/:alias/messages");
const mockReq = createMockRequest({
params: { alias: "wanderbricks" },
body: { content: "test question" },
headers: {
"x-forwarded-access-token": "user-token",
"x-forwarded-user": "user-1",
},
});
const mockRes = createMockResponse();

await handler(mockReq, mockRes);

expect(mockRes.status).toHaveBeenCalledWith(404);
expect(mockRes.json).toHaveBeenCalledWith({
error: "Unknown space alias: wanderbricks",
});
});
});

describe("getConversation with pageToken", () => {
Expand Down
11 changes: 9 additions & 2 deletions packages/appkit/src/plugins/genie/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ export type { GenieStreamEvent } from "shared";
export type { GenieConversationHistoryResponse } from "../../connectors/genie";

export interface IGenieConfig extends BasePluginConfig {
/** Map of alias → Genie Space ID. Defaults to { default: DATABRICKS_GENIE_SPACE_ID } if omitted. */
spaces?: Record<string, string>;
/**
* Map of alias → Genie Space ID. Defaults to { default: DATABRICKS_GENIE_SPACE_ID } if omitted.
*
* Values may be `undefined` so callers can pass `process.env.X` directly
* (which is `string | undefined`) without a hoist-and-narrow dance. Aliases
* with undefined values resolve to "unknown alias" at request time, same
* as missing keys.
*/
spaces?: Record<string, string | undefined>;
/** Genie polling timeout in ms. Set to 0 for indefinite. Default: 120000 (2 min) */
timeout?: number;
}
Expand Down
Loading