consistency
This commit is contained in:
parent
4dcbfea875
commit
95cfd6efff
9 changed files with 26 additions and 28 deletions
|
|
@ -2,7 +2,7 @@ import { v } from 'convex/values';
|
||||||
import { mutation, query } from './_generated/server';
|
import { mutation, query } from './_generated/server';
|
||||||
import { api } from './_generated/api';
|
import { api } from './_generated/api';
|
||||||
import { messageRoleValidator, providerValidator } from './schema';
|
import { messageRoleValidator, providerValidator } from './schema';
|
||||||
import { Id } from './_generated/dataModel';
|
import type { Id } from './_generated/dataModel';
|
||||||
|
|
||||||
export const getAllFromConversation = query({
|
export const getAllFromConversation = query({
|
||||||
args: {
|
args: {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import * as array from '../../utils/array';
|
||||||
import * as object from '../../utils/object';
|
import * as object from '../../utils/object';
|
||||||
import { internal } from './_generated/api';
|
import { internal } from './_generated/api';
|
||||||
import { Provider } from '../../types';
|
import { Provider } from '../../types';
|
||||||
import { Doc } from './_generated/dataModel';
|
import type { Doc } from './_generated/dataModel';
|
||||||
|
|
||||||
export const getModelKey = (args: { provider: Provider; model_id: string }) => {
|
export const getModelKey = (args: { provider: Provider; model_id: string }) => {
|
||||||
return `${args.provider}:${args.model_id}`;
|
return `${args.provider}:${args.model_id}`;
|
||||||
|
|
@ -13,11 +13,11 @@ export const getModelKey = (args: { provider: Provider; model_id: string }) => {
|
||||||
|
|
||||||
export const get_enabled = query({
|
export const get_enabled = query({
|
||||||
args: {
|
args: {
|
||||||
sessionToken: v.string(),
|
session_token: v.string(),
|
||||||
},
|
},
|
||||||
handler: async (ctx, args): Promise<Record<string, Doc<'user_enabled_models'>>> => {
|
handler: async (ctx, args): Promise<Record<string, Doc<'user_enabled_models'>>> => {
|
||||||
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
||||||
sessionToken: args.sessionToken,
|
sessionToken: args.session_token,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!session) throw new Error('Invalid session token');
|
if (!session) throw new Error('Invalid session token');
|
||||||
|
|
@ -59,11 +59,11 @@ export const get = query({
|
||||||
args: {
|
args: {
|
||||||
provider: providerValidator,
|
provider: providerValidator,
|
||||||
model_id: v.string(),
|
model_id: v.string(),
|
||||||
sessionToken: v.string(),
|
session_token: v.string(),
|
||||||
},
|
},
|
||||||
handler: async (ctx, args): Promise<Doc<'user_enabled_models'> | null> => {
|
handler: async (ctx, args): Promise<Doc<'user_enabled_models'> | null> => {
|
||||||
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
||||||
sessionToken: args.sessionToken,
|
sessionToken: args.session_token,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!session) throw new Error('Invalid session token');
|
if (!session) throw new Error('Invalid session token');
|
||||||
|
|
@ -71,9 +71,7 @@ export const get = query({
|
||||||
const model = await ctx.db
|
const model = await ctx.db
|
||||||
.query('user_enabled_models')
|
.query('user_enabled_models')
|
||||||
.withIndex('by_model_provider_user', (q) =>
|
.withIndex('by_model_provider_user', (q) =>
|
||||||
q.eq('model_id', args.model_id)
|
q.eq('model_id', args.model_id).eq('provider', args.provider).eq('user_id', session.userId)
|
||||||
.eq('provider', args.provider)
|
|
||||||
.eq('user_id', session.userId)
|
|
||||||
)
|
)
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
|
|
@ -86,11 +84,11 @@ export const set = mutation({
|
||||||
provider: providerValidator,
|
provider: providerValidator,
|
||||||
model_id: v.string(),
|
model_id: v.string(),
|
||||||
enabled: v.boolean(),
|
enabled: v.boolean(),
|
||||||
sessionToken: v.string(),
|
session_token: v.string(),
|
||||||
},
|
},
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
||||||
sessionToken: args.sessionToken,
|
sessionToken: args.session_token,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!session) throw new Error('Invalid session token');
|
if (!session) throw new Error('Invalid session token');
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,18 @@ import { v } from 'convex/values';
|
||||||
import { mutation, query } from './_generated/server';
|
import { mutation, query } from './_generated/server';
|
||||||
import { internal } from './_generated/api';
|
import { internal } from './_generated/api';
|
||||||
import { ruleAttachValidator } from './schema';
|
import { ruleAttachValidator } from './schema';
|
||||||
import { Doc } from './_generated/dataModel';
|
import type { Doc } from './_generated/dataModel';
|
||||||
|
|
||||||
export const create = mutation({
|
export const create = mutation({
|
||||||
args: {
|
args: {
|
||||||
name: v.string(),
|
name: v.string(),
|
||||||
attach: ruleAttachValidator,
|
attach: ruleAttachValidator,
|
||||||
rule: v.string(),
|
rule: v.string(),
|
||||||
sessionToken: v.string(),
|
session_token: v.string(),
|
||||||
},
|
},
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
||||||
sessionToken: args.sessionToken,
|
sessionToken: args.session_token,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!session) throw new Error('Invalid session token');
|
if (!session) throw new Error('Invalid session token');
|
||||||
|
|
@ -39,11 +39,11 @@ export const update = mutation({
|
||||||
ruleId: v.id('user_rules'),
|
ruleId: v.id('user_rules'),
|
||||||
attach: ruleAttachValidator,
|
attach: ruleAttachValidator,
|
||||||
rule: v.string(),
|
rule: v.string(),
|
||||||
sessionToken: v.string(),
|
session_token: v.string(),
|
||||||
},
|
},
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
||||||
sessionToken: args.sessionToken,
|
sessionToken: args.session_token,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!session) throw new Error('Invalid session token');
|
if (!session) throw new Error('Invalid session token');
|
||||||
|
|
@ -63,11 +63,11 @@ export const update = mutation({
|
||||||
export const remove = mutation({
|
export const remove = mutation({
|
||||||
args: {
|
args: {
|
||||||
ruleId: v.id('user_rules'),
|
ruleId: v.id('user_rules'),
|
||||||
sessionToken: v.string(),
|
session_token: v.string(),
|
||||||
},
|
},
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
||||||
sessionToken: args.sessionToken,
|
sessionToken: args.session_token,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!session) throw new Error('Invalid session token');
|
if (!session) throw new Error('Invalid session token');
|
||||||
|
|
@ -83,11 +83,11 @@ export const remove = mutation({
|
||||||
|
|
||||||
export const all = query({
|
export const all = query({
|
||||||
args: {
|
args: {
|
||||||
sessionToken: v.string(),
|
session_token: v.string(),
|
||||||
},
|
},
|
||||||
handler: async (ctx, args): Promise<Doc<'user_rules'>[]> => {
|
handler: async (ctx, args): Promise<Doc<'user_rules'>[]> => {
|
||||||
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
const session = await ctx.runQuery(internal.betterAuth.getSession, {
|
||||||
sessionToken: args.sessionToken,
|
sessionToken: args.session_token,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!session) throw new Error('Invalid session token');
|
if (!session) throw new Error('Invalid session token');
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ export class Models {
|
||||||
|
|
||||||
init = createInit(() => {
|
init = createInit(() => {
|
||||||
const query = useCachedQuery(api.user_enabled_models.get_enabled, {
|
const query = useCachedQuery(api.user_enabled_models.get_enabled, {
|
||||||
sessionToken: session.current?.session.token ?? '',
|
session_token: session.current?.session.token ?? '',
|
||||||
});
|
});
|
||||||
watch(
|
watch(
|
||||||
() => $state.snapshot(query.data),
|
() => $state.snapshot(query.data),
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
let creatingRule = $state(false);
|
let creatingRule = $state(false);
|
||||||
|
|
||||||
const userRulesQuery: QueryResult<Doc<'user_rules'>[]> = useCachedQuery(api.user_rules.all, {
|
const userRulesQuery: QueryResult<Doc<'user_rules'>[]> = useCachedQuery(api.user_rules.all, {
|
||||||
sessionToken: session.current?.session.token ?? '',
|
session_token: session.current?.session.token ?? '',
|
||||||
});
|
});
|
||||||
|
|
||||||
async function submitNewRule(e: SubmitEvent) {
|
async function submitNewRule(e: SubmitEvent) {
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
name,
|
name,
|
||||||
attach,
|
attach,
|
||||||
rule,
|
rule,
|
||||||
sessionToken: session.current?.session.token ?? '',
|
session_token: session.current?.session.token ?? '',
|
||||||
});
|
});
|
||||||
|
|
||||||
creatingRule = false;
|
creatingRule = false;
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@
|
||||||
ruleId: rule._id,
|
ruleId: rule._id,
|
||||||
attach,
|
attach,
|
||||||
rule: ruleText,
|
rule: ruleText,
|
||||||
sessionToken: session.current?.session.token ?? '',
|
session_token: session.current?.session.token ?? '',
|
||||||
}),
|
}),
|
||||||
(e) => e
|
(e) => e
|
||||||
);
|
);
|
||||||
|
|
@ -61,7 +61,7 @@
|
||||||
|
|
||||||
await client.mutation(api.user_rules.remove, {
|
await client.mutation(api.user_rules.remove, {
|
||||||
ruleId: rule._id,
|
ruleId: rule._id,
|
||||||
sessionToken: session.current?.session.token ?? '',
|
session_token: session.current?.session.token ?? '',
|
||||||
});
|
});
|
||||||
|
|
||||||
deleting = false;
|
deleting = false;
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@
|
||||||
provider,
|
provider,
|
||||||
model_id: model.id,
|
model_id: model.id,
|
||||||
enabled: v,
|
enabled: v,
|
||||||
sessionToken: session.current?.session.token,
|
session_token: session.current?.session.token,
|
||||||
}),
|
}),
|
||||||
(e) => e
|
(e) => e
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ async function generateAIResponse(
|
||||||
client.query(api.user_enabled_models.get, {
|
client.query(api.user_enabled_models.get, {
|
||||||
provider: Provider.OpenRouter,
|
provider: Provider.OpenRouter,
|
||||||
model_id: modelId,
|
model_id: modelId,
|
||||||
sessionToken: session.token,
|
session_token: session.token,
|
||||||
}),
|
}),
|
||||||
(e) => `Failed to get model: ${e}`
|
(e) => `Failed to get model: ${e}`
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
let { class: className }: Props = $props();
|
let { class: className }: Props = $props();
|
||||||
|
|
||||||
const enabledModelsQuery = useCachedQuery(api.user_enabled_models.get_enabled, {
|
const enabledModelsQuery = useCachedQuery(api.user_enabled_models.get_enabled, {
|
||||||
sessionToken: session.current?.session.token ?? '',
|
session_token: session.current?.session.token ?? '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const enabledArr = $derived(Object.values(enabledModelsQuery.data ?? {}));
|
const enabledArr = $derived(Object.values(enabledModelsQuery.data ?? {}));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue