feat: add better provider support, icons, regen, and a lot more
This commit is contained in:
+115
-21
@@ -1,9 +1,43 @@
|
||||
import { Schema as S } from '@triplit/client';
|
||||
import { authSchema } from './auth-schema';
|
||||
import { Providers } from '../app/types/model';
|
||||
import { Providers, SupportedModalities } from '../app/types/model';
|
||||
|
||||
const systemAssistantRecord = S.Record({
|
||||
enabled: S.Boolean({ default: true }),
|
||||
prompt: S.String({ nullable: true }),
|
||||
modelId: S.String({ nullable: true }),
|
||||
})
|
||||
|
||||
export const schema = S.Collections({
|
||||
...authSchema,
|
||||
settings: {
|
||||
schema: S.Schema({
|
||||
id: S.Id(),
|
||||
userId: S.String(),
|
||||
systemAssistants: S.Record({
|
||||
rename: systemAssistantRecord
|
||||
}),
|
||||
}),
|
||||
permissions: {
|
||||
authenticated: {
|
||||
read: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
insert: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
update: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
postUpdate: {
|
||||
filter: [['userId', '=', '$prev.userId']],
|
||||
},
|
||||
delete: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
agents: {
|
||||
schema: S.Schema({
|
||||
id: S.Id(),
|
||||
@@ -33,6 +67,9 @@ export const schema = S.Collections({
|
||||
update: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
postUpdate: {
|
||||
filter: [['userId', '=', '$prev.userId']],
|
||||
},
|
||||
delete: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
@@ -44,6 +81,7 @@ export const schema = S.Collections({
|
||||
id: S.Id(),
|
||||
userId: S.String(),
|
||||
agentId: S.String(),
|
||||
renaming: S.Boolean({ default: false, nullable: true }),
|
||||
name: S.String(),
|
||||
createdAt: S.Date({ default: S.Default.now() }),
|
||||
}),
|
||||
@@ -69,6 +107,9 @@ export const schema = S.Collections({
|
||||
update: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
postUpdate: {
|
||||
filter: [['userId', '=', '$prev.userId']],
|
||||
},
|
||||
delete: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
@@ -78,6 +119,8 @@ export const schema = S.Collections({
|
||||
message_parts: {
|
||||
schema: S.Schema({
|
||||
id: S.Id(),
|
||||
userId: S.String(),
|
||||
topicId: S.String(),
|
||||
messageId: S.String(),
|
||||
toolCallId: S.String({ nullable: true }),
|
||||
type: S.String({ enum: ['reasoning', 'text', 'tool-call', 'file'] }),
|
||||
@@ -98,16 +141,24 @@ export const schema = S.Collections({
|
||||
permissions: {
|
||||
authenticated: {
|
||||
read: {
|
||||
filter: [['message.topic.userId', '=', '$token.sub']],
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
insert: {
|
||||
// blank means it can only be inserted by the service token (ie the server)
|
||||
},
|
||||
update: {
|
||||
filter: [['message.topic.userId', '=', '$token.sub']],
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
postUpdate: {
|
||||
filter: [
|
||||
['userId', '=', '$prev.userId'],
|
||||
['topicId', '=', '$prev.topicId'],
|
||||
['messageId', '=', '$prev.messageId'],
|
||||
['toolCallId', '=', '$prev.toolCallId'],
|
||||
],
|
||||
},
|
||||
delete: {
|
||||
filter: [['message.topic.userId', '=', '$token.sub']],
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -142,7 +193,10 @@ export const schema = S.Collections({
|
||||
messages: {
|
||||
schema: S.Schema({
|
||||
id: S.Id(),
|
||||
topicId: S.String(),
|
||||
topicId: S.String({ nullable: true }),
|
||||
focusedIndex: S.Number({ nullable: true }),
|
||||
userId: S.String(),
|
||||
deleted: S.Boolean({ default: false, nullable: true }),
|
||||
role: S.String({ enum: ['user', 'assistant'] }),
|
||||
content: S.String(),
|
||||
generationId: S.String({ nullable: true, default: null }),
|
||||
@@ -173,16 +227,27 @@ export const schema = S.Collections({
|
||||
permissions: {
|
||||
authenticated: {
|
||||
read: {
|
||||
filter: [['topic.userId', '=', '$token.sub']],
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
insert: {
|
||||
filter: [['topic.userId', '=', '$token.sub']],
|
||||
filter: [
|
||||
['userId', '=', '$token.sub'],
|
||||
['topic.userId', '=', '$token.sub'],
|
||||
],
|
||||
},
|
||||
update: {
|
||||
filter: [['topic.userId', '=', '$token.sub']],
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
postUpdate: {
|
||||
filter: [
|
||||
['userId', '=', '$prev.userId'],
|
||||
['topicId', '=', '$prev.topicId'],
|
||||
['generationId', '=', '$prev.generationId'],
|
||||
['parentMessageId', '=', '$prev.parentMessageId'],
|
||||
],
|
||||
},
|
||||
delete: {
|
||||
filter: [['topic.userId', '=', '$token.sub']],
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -190,6 +255,7 @@ export const schema = S.Collections({
|
||||
generations: {
|
||||
schema: S.Schema({
|
||||
id: S.Id(),
|
||||
userId: S.String(),
|
||||
status: S.String({
|
||||
enum: ['pending', 'cancelled', 'completed', 'failed'],
|
||||
}),
|
||||
@@ -204,6 +270,8 @@ export const schema = S.Collections({
|
||||
}, { nullable: true }),
|
||||
output: S.Number({ nullable: true }),
|
||||
thinking: S.Number({ nullable: true }),
|
||||
ttft: S.Number({ nullable: true }),
|
||||
tps: S.Number({ nullable: true }),
|
||||
}, { nullable: true }),
|
||||
error: S.String({ nullable: true, default: null }),
|
||||
}),
|
||||
@@ -218,19 +286,22 @@ export const schema = S.Collections({
|
||||
permissions: {
|
||||
authenticated: {
|
||||
read: {
|
||||
filter: [
|
||||
['message.topic.userId', '=', '$token.sub'],
|
||||
['topic.userId', '=', '$token.sub'],
|
||||
],
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
insert: {},
|
||||
update: {},
|
||||
delete: {
|
||||
update: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
postUpdate: {
|
||||
filter: [
|
||||
['message.topic.userId', '=', '$token.sub'],
|
||||
['topic.userId', '=', '$token.sub'],
|
||||
['userId', '=', '$prev.userId'],
|
||||
['topicId', '=', '$prev.topicId'],
|
||||
['messageId', '=', '$prev.messageId'],
|
||||
],
|
||||
},
|
||||
delete: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -261,6 +332,9 @@ export const schema = S.Collections({
|
||||
update: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
postUpdate: {
|
||||
filter: [['userId', '=', '$prev.userId']],
|
||||
},
|
||||
delete: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
@@ -274,9 +348,25 @@ export const schema = S.Collections({
|
||||
externalId: S.String(),// e.g. "x-ai/grok-4.1-fast"
|
||||
providerId: S.String(),
|
||||
name: S.String(),
|
||||
cost: S.Record({
|
||||
prompt: S.String({ nullable: true }),
|
||||
completion: S.String({ nullable: true }),
|
||||
request: S.String({ nullable: true }),
|
||||
image: S.String({ nullable: true }),
|
||||
imageTokens: S.String({ nullable: true }),
|
||||
imageOutput: S.String({ nullable: true }),
|
||||
audio: S.String({ nullable: true }),
|
||||
audioOutput: S.String({ nullable: true }),
|
||||
inputAudioCache: S.String({ nullable: true }),
|
||||
webSearch: S.String({ nullable: true }),
|
||||
internalReasoning: S.String({ nullable: true }),
|
||||
inputCacheRead: S.String({ nullable: true }),
|
||||
inputCacheWrite: S.String({ nullable: true }),
|
||||
discount: S.String({ nullable: true }),
|
||||
}),
|
||||
attributes: S.Record({
|
||||
inputModalities: S.Set(S.String({ enum: ['text', 'image'] })),
|
||||
outputModalities: S.Set(S.String({ enum: ['text', 'image'] })),
|
||||
inputModalities: S.Set(S.String({ enum: SupportedModalities })),
|
||||
outputModalities: S.Set(S.String({ enum: SupportedModalities })),
|
||||
capabilities: S.Set(S.String({ enum: ['reasoning', 'tools'] })),
|
||||
contextWindow: S.Number({ nullable: true }),
|
||||
supported_parameters: S.Set(S.String(), { nullable: true }),
|
||||
@@ -284,8 +374,6 @@ export const schema = S.Collections({
|
||||
isCustom: S.Boolean({ default: false }),
|
||||
enabled: S.Boolean({ default: true }),
|
||||
releasedAt: S.Date({ nullable: true }),
|
||||
createdAt: S.Date({ default: S.Default.now() }),
|
||||
updatedAt: S.Date({ default: S.Default.now() }),
|
||||
}),
|
||||
relationships: {
|
||||
provider: S.RelationOne('providers', {
|
||||
@@ -303,6 +391,12 @@ export const schema = S.Collections({
|
||||
update: {
|
||||
filter: [['userId', '=', '$token.sub'], ['provider.userId', '=', '$token.sub']],
|
||||
},
|
||||
postUpdate: {
|
||||
filter: [
|
||||
['userId', '=', '$prev.userId'],
|
||||
['providerId', '=', '$prev.providerId'],
|
||||
]
|
||||
},
|
||||
delete: {
|
||||
filter: [['userId', '=', '$token.sub'], ['provider.userId', '=', '$token.sub']],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user