-
Notifications
You must be signed in to change notification settings - Fork 1
Fix/emoji #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix/emoji #4
Changes from all commits
dba9a37
348635e
179878b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "cSpell.words": [ | ||
| "arcjet", | ||
| "Kinde", | ||
| "openrouter", | ||
| "orpc" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,8 @@ const openrouter = createOpenRouter({ | |
| apiKey: process.env.OPENROUTER_LLM_KEY, | ||
| }); | ||
|
|
||
| const MODEL_ID = "amazon/nova-2-lite-v1:free"; | ||
|
|
||
| // const MODEL_ID = "amazon/nova-2-lite-v1:free"; | ||
| const MODEL_ID = "nvidia/nemotron-nano-9b-v2:free" | ||
| const model = openrouter.chat(MODEL_ID); | ||
|
Comment on lines
+16
to
18
|
||
|
|
||
| export const generateThreadSummary = base | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { base } from "../middleware/base"; | |
| import { requiredWorkspaceMiddleware } from "../middleware/workspace"; | ||
| import { inviteMemberSchema } from "../schemas/member"; | ||
| import { | ||
| ApiError, | ||
| init, | ||
| organization_user, | ||
| Organizations, | ||
|
|
@@ -14,6 +15,48 @@ import { | |
| import { getAvatar } from "@/lib/get-avatar"; | ||
| import { readSecurityMiddleware } from "../middleware/arcjet/read"; | ||
|
|
||
| function getKindeErrorMessage(error: unknown): string { | ||
| if (!error) return "Unknown Kinde error"; | ||
|
|
||
| const maybeError = error as { | ||
| message?: string; | ||
| body?: unknown; | ||
| }; | ||
|
|
||
| const body = maybeError.body; | ||
| if (body && typeof body === "object") { | ||
| const record = body as Record<string, unknown>; | ||
| const message = | ||
| (typeof record.message === "string" && record.message) || | ||
| (typeof record.error === "string" && record.error) || | ||
| (typeof record.error_description === "string" && | ||
| record.error_description); | ||
|
|
||
| if (message) return message; | ||
| } | ||
|
|
||
| if (maybeError.message) return maybeError.message; | ||
| return "Unknown Kinde error"; | ||
| } | ||
|
|
||
| function ensureKindeManagementEnv() { | ||
| const missing: string[] = []; | ||
|
|
||
| if (!process.env.KINDE_MANAGEMENT_CLIENT_ID) { | ||
| missing.push("KINDE_MANAGEMENT_CLIENT_ID"); | ||
| } | ||
| if (!process.env.KINDE_MANAGEMENT_CLIENT_SECRET) { | ||
| missing.push("KINDE_MANAGEMENT_CLIENT_SECRET"); | ||
| } | ||
| if (!process.env.KINDE_DOMAIN) { | ||
| missing.push("KINDE_DOMAIN"); | ||
| } | ||
|
|
||
| if (missing.length > 0) { | ||
| throw new Error(`Missing required Kinde env vars: ${missing.join(", ")}`); | ||
| } | ||
| } | ||
|
Comment on lines
+18
to
+58
|
||
|
|
||
| export const inviteMember = base | ||
| .use(requiredAuthMiddleware) | ||
| .use(requiredWorkspaceMiddleware) | ||
|
|
@@ -29,6 +72,7 @@ export const inviteMember = base | |
| .output(z.void()) | ||
| .handler(async ({ input, context, errors }) => { | ||
| try { | ||
| ensureKindeManagementEnv(); | ||
| init(); | ||
|
|
||
| await Users.createUser({ | ||
|
|
@@ -48,8 +92,41 @@ export const inviteMember = base | |
| ], | ||
| }, | ||
| }); | ||
| } catch { | ||
| throw errors.INTERNAL_SERVER_ERROR(); | ||
| } catch (error: unknown) { | ||
| if (error instanceof ApiError) { | ||
| const reason = getKindeErrorMessage(error); | ||
|
|
||
| if (error.status === 401 || error.status === 403) { | ||
| throw errors.FORBIDDEN({ | ||
| message: | ||
| `Kinde Management API denied this request (${error.status}). ` + | ||
| "Check M2M scopes (e.g. create:users) and credentials. " + | ||
| `Reason: ${reason}`, | ||
| }); | ||
| } | ||
|
|
||
| if (error.status === 409) { | ||
| throw errors.BAD_REQUEST({ | ||
| message: | ||
| "A user with this email already exists. Invite flow requires existing-user handling.", | ||
| }); | ||
| } | ||
|
|
||
| if (error.status === 429) { | ||
| throw errors.RATE_LIMITED({ | ||
| message: `Kinde rate limit hit. Reason: ${reason}`, | ||
| }); | ||
| } | ||
|
|
||
| throw errors.INTERNAL_SERVER_ERROR({ | ||
| message: `Kinde invite failed (${error.status}): ${reason}`, | ||
| }); | ||
| } | ||
|
|
||
| const reason = getKindeErrorMessage(error); | ||
| throw errors.INTERNAL_SERVER_ERROR({ | ||
| message: `Invite failed before Kinde call completed: ${reason}`, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
|
|
@@ -68,6 +145,7 @@ export const listMembers = base | |
| .output(z.array(z.custom<organization_user>())) | ||
| .handler(async ({ context, errors }) => { | ||
| try { | ||
| ensureKindeManagementEnv(); | ||
| init(); | ||
|
|
||
| const data = await Organizations.getOrganizationUsers({ | ||
|
|
@@ -80,7 +158,28 @@ export const listMembers = base | |
| } | ||
|
|
||
| return data.organization_users; | ||
| } catch { | ||
| throw errors.INTERNAL_SERVER_ERROR(); | ||
| } catch (error: unknown) { | ||
| if (error instanceof ApiError) { | ||
| const reason = getKindeErrorMessage(error); | ||
|
|
||
| if (error.status === 401 || error.status === 403) { | ||
| throw errors.FORBIDDEN({ | ||
| message: | ||
| `Kinde Management API denied member listing (${error.status}). ` + | ||
| "Check M2M scopes (e.g. read:organization_users). " + | ||
| `Reason: ${reason}`, | ||
| }); | ||
| } | ||
|
|
||
| if (error.status === 429) { | ||
| throw errors.RATE_LIMITED({ | ||
| message: `Kinde rate limit hit. Reason: ${reason}`, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| throw errors.INTERNAL_SERVER_ERROR({ | ||
| message: `Failed to list members: ${getKindeErrorMessage(error)}`, | ||
| }); | ||
| } | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change switches the OpenRouter model and leaves a commented-out
MODEL_ID, but the newMODEL_IDline has inconsistent spacing and is missing a trailing semicolon, which may fail formatting/lint checks used elsewhere in the repo. Please align with the surrounding style (single space around=and consistent semicolons) and remove dead commented code if it’s not needed.