Skip to content

Commit aeb04fb

Browse files
authored
Vercel sdk v5 maybe this time (#1766)
* Vercel SDK v5 This PR introduce Vercel SDK v5 which force us also to upgrade Zod from v3 to v4 and also to change our server action lib because is not compatible with Zod 4. * Fix unhandle Vercel SDK error NoOutputGeneratedError The way we handle this is by listening to `onError` callback on `streamText` and throw the error before we start reading from the streamText promises which will fail anyway because when Vercel gets provider API error they return the NoOutputGeneratedError content which is not handle in our side. Throwing on their onError callback we avoid this problem
1 parent 41bf7f7 commit aeb04fb

File tree

345 files changed

+5113
-4727
lines changed

Some content is hidden

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

345 files changed

+5113
-4727
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
@@ -17,7 +17,7 @@
1717
"dependencies": {
1818
"@hono/node-server": "1.13.2",
1919
"@hono/swagger-ui": "0.4.1",
20-
"@hono/zod-openapi": "0.16.4",
20+
"@hono/zod-openapi": "1.1.1",
2121
"@latitude-data/constants": "workspace:^",
2222
"@latitude-data/core": "workspace:^",
2323
"@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/constants'
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/v3/conversations/chat/chat.handler.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ const step: ChainStepResponse<'text'> = {
6767
streamType: 'text',
6868
text: 'fake-response-text',
6969
reasoning: undefined,
70-
usage: { promptTokens: 4, completionTokens: 6, totalTokens: 10 },
70+
usage: {
71+
inputTokens: 4,
72+
outputTokens: 6,
73+
promptTokens: 4,
74+
completionTokens: 6,
75+
totalTokens: 10,
76+
reasoningTokens: 0,
77+
cachedInputTokens: 0,
78+
},
7179
toolCalls: [],
7280
documentLogUuid: 'fake-document-log-uuid',
7381
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
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const documentLogSchema = z.object({
1010
commitId: z.number(),
1111
resolvedContent: z.string(),
1212
contentHash: z.string(),
13-
parameters: z.record(z.any()),
13+
parameters: z.record(z.string(), z.any()),
1414
customIdentifier: z.string().optional(),
1515
duration: z.number().optional(),
16-
source: z.nativeEnum(LogSources),
16+
source: z.enum(LogSources),
1717
createdAt: z.date(),
1818
updatedAt: z.date(),
1919
})

apps/gateway/src/routes/api/v3/projects/versions/documents/run/run.route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const runRoute = createRoute({
2424
path: z.string(),
2525
stream: z.boolean().default(false),
2626
customIdentifier: z.string().optional(),
27-
parameters: z.record(z.any()).optional().default({}),
27+
parameters: z.record(z.string(), z.any()).optional().default({}),
2828
tools: z.array(z.string()).optional().default([]),
2929
userMessage: z.string().optional(),
3030
background: z.boolean().default(false),

0 commit comments

Comments
 (0)