Skip to content

Commit 071919a

Browse files
committed
Upgrade Vercel SDK v4 -> v5 + zod@v4 + 💀 zsa server actions abstraction
1 parent 9c92845 commit 071919a

File tree

354 files changed

+4759
-5071
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

354 files changed

+4759
-5071
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ apps/web/scripts-dist
5959

6060
# File uploads in development
6161
apps/web/uploads
62+
apps/web/storage
6263
apps/web/public/uploads
63-
apps/web/public/storage
64+
apps/web/public/files
6465
uploads
6566
storage
6667

AGENTS.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,41 @@
6060

6161
### Action Layer (`apps/web/src/actions/`)
6262

63-
- Server actions use `authProcedure.createServerAction()` pattern
63+
- Server actions use `authProcedure` pattern
6464
- Input validation with Zod schemas
6565
- Actions fetch model instances using repositories before calling services
6666
- **Admin-only actions**: Place under `actions/admin/` directory for backoffice functionality
6767
- Example pattern:
6868

6969
```typescript
7070
export const updateApiKeyAction = authProcedure
71-
.createServerAction()
72-
.input(z.object({ id: z.number(), name: z.string() }))
73-
.handler(async ({ input, ctx }) => {
71+
.inputSchema(z.object({ id: z.number(), name: z.string() }))
72+
.action(async ({ parsedInput, ctx }) => {
7473
const repo = new Repository(ctx.workspace.id)
75-
const model = await repo.find(input.id).then((r) => r.unwrap())
76-
return updateService(model, { name: input.name }).then((r) => r.unwrap())
74+
const model = await repo.find(parsedInput.id).then((r) => r.unwrap())
75+
return updateService(model, { name: parsedInput.name }).then((r) =>
76+
r.unwrap(),
77+
)
7778
})
7879
```
7980

81+
- For writing an action with a different scope. Let's say withing projects:
82+
83+
```typescript
84+
import { withProject, withProjectSchema } from '../../procedures'
85+
export const updateProjectAction = withProject
86+
.inputSchema(withProjectSchema.extend({ id: z.number(), name: z.string() }))
87+
.action(async ({ parsedInput, ctx }) => {
88+
const repo = new ProjectRepository(ctx.workspace.id)
89+
const model = await repo.find(parsedInput.id).then((r) => r.unwrap())
90+
return updateProjectService(model, { name: parsedInput.name }).then((r) =>
91+
r.unwrap(),
92+
)
93+
})
94+
```
95+
96+
`withProject` procedure inherits from `authProcedure` and adds project validation.
97+
8098
### Store Layer (`apps/web/src/stores/`)
8199

82100
- Use SWR for data fetching with custom hooks

apps/gateway/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@hono/node-server": "1.13.2",
1818
"@hono/swagger-ui": "0.4.1",
19-
"@hono/zod-openapi": "0.16.4",
19+
"@hono/zod-openapi": "1.1.1",
2020
"@latitude-data/constants": "workspace:^",
2121
"@latitude-data/core": "workspace:^",
2222
"@latitude-data/env": "workspace:^",

apps/gateway/src/openApi/schemas/ai.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export const languageModelUsageSchema = z.object({
1515
export const toolCallSchema = z.object({
1616
id: z.string(),
1717
name: z.string(),
18-
arguments: z.record(z.any()),
18+
arguments: z.record(z.string(), z.any()),
1919
})
2020

21-
export const configSchema = z.object({}).passthrough()
22-
export const providerLogSchema = z.object({}).passthrough()
21+
export const configSchema = z.record(z.string(), z.any())
22+
export const providerLogSchema = z.record(z.string(), z.any())
2323
export const chainStepResponseSchema = z.discriminatedUnion('streamType', [
2424
z.object({
2525
streamType: z.literal('text'),
@@ -58,7 +58,7 @@ export const chainEventDtoResponseSchema = z.discriminatedUnion('streamType', [
5858
export const legacyChainEventDtoSchema = z.discriminatedUnion('event', [
5959
z.object({
6060
event: z.literal(StreamEventTypes.Provider),
61-
data: z.object({}).passthrough(),
61+
data: z.record(z.string(), z.any()),
6262
}),
6363
z.object({
6464
event: z.literal(StreamEventTypes.Latitude),
@@ -79,7 +79,7 @@ export const legacyChainEventDtoSchema = z.discriminatedUnion('event', [
7979
type: z.literal(LegacyChainEventTypes.Complete),
8080
config: configSchema,
8181
messages: z.array(messageSchema).optional(),
82-
object: z.object({}).passthrough().optional(),
82+
object: z.record(z.string(), z.any()).optional(),
8383
response: chainEventDtoResponseSchema,
8484
uuid: z.string().optional(),
8585
}),
@@ -110,8 +110,8 @@ export const ProjectSchema = z.object({
110110
id: z.number(),
111111
name: z.string(),
112112
workspaceId: z.number(),
113-
createdAt: z.string().datetime(),
114-
updatedAt: z.string().datetime(),
115-
lastEditedAt: z.string().datetime().optional(),
116-
deletedAt: z.string().datetime().nullable().optional(),
113+
createdAt: z.iso.datetime(),
114+
updatedAt: z.iso.datetime(),
115+
lastEditedAt: z.iso.datetime().optional(),
116+
deletedAt: z.iso.datetime().nullable().optional(),
117117
})

apps/gateway/src/openApi/schemas/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { LogSources } from '@latitude-data/core/browser'
44
export const internalInfoSchema = z.object({
55
__internal: z
66
.object({
7-
source: z.nativeEnum(LogSources).optional(),
7+
source: z.enum(LogSources).optional(),
88
})
99
.optional(),
1010
})

apps/gateway/src/presenters/documentPresenter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export const documentPresenterSchema = z.object({
1616
path: z.string(),
1717
content: z.string(),
1818
contentHash: z.string().optional(),
19-
config: z.object({}).passthrough(),
20-
parameters: z.record(z.object({ type: z.nativeEnum(ParameterType) })),
21-
provider: z.nativeEnum(Providers).optional(),
19+
config: z.record(z.string(), z.any()),
20+
parameters: z.record(z.string(), z.object({ type: z.enum(ParameterType) })),
21+
provider: z.enum(Providers).optional(),
2222
})
2323
type Parameters = z.infer<typeof documentPresenterSchema>['parameters']
2424

apps/gateway/src/routes/api/v1/run/run.route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const runRoute = createRoute({
2020
schema: internalInfoSchema.extend({
2121
path: z.string(),
2222
customIdentifier: z.string().optional(),
23-
parameters: z.record(z.any()).optional().default({}),
23+
parameters: z.record(z.string(), z.any()).optional().default({}),
2424
}),
2525
},
2626
},

apps/gateway/src/routes/api/v2/documents/run/run.route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const runRoute = createRoute({
2222
path: z.string(),
2323
stream: z.boolean().default(false),
2424
customIdentifier: z.string().optional(),
25-
parameters: z.record(z.any()).optional().default({}),
25+
parameters: z.record(z.string(), z.any()).optional().default({}),
2626
}),
2727
},
2828
},

apps/gateway/src/routes/api/v3/conversations/chat/chat.handler.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,15 @@ const step: ChainStepResponse<'text'> = {
7777
streamType: 'text',
7878
text: 'fake-response-text',
7979
reasoning: undefined,
80-
usage: { promptTokens: 4, completionTokens: 6, totalTokens: 10 },
80+
usage: {
81+
inputTokens: 4,
82+
outputTokens: 6,
83+
promptTokens: 4,
84+
completionTokens: 6,
85+
totalTokens: 10,
86+
reasoningTokens: 0,
87+
cachedInputTokens: 0,
88+
},
8189
toolCalls: [],
8290
documentLogUuid: 'fake-document-log-uuid',
8391
providerLog: {

apps/gateway/src/routes/api/v3/projects/versions/create/createCommit.route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const CommitSchema = z.object({
1111
authorName: z.string().nullable(),
1212
authorEmail: z.string().nullable(),
1313
authorId: z.number().nullable(),
14-
createdAt: z.string().datetime(),
15-
updatedAt: z.string().datetime(),
14+
createdAt: z.iso.datetime(),
15+
updatedAt: z.iso.datetime(),
1616
status: z.string(),
1717
parentCommitUuid: z.string().nullable(),
1818
})

0 commit comments

Comments
 (0)