Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"@aws-sdk/client-dynamodb": "^3.564.0",
"@botpress/api": "1.76.0",
"@botpress/api": "1.80.0",
"@botpress/cli": "workspace:*",
"@botpress/client": "workspace:*",
"@botpress/sdk": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^11.7.0",
"@botpress/chat": "0.5.5",
"@botpress/client": "1.36.0",
"@botpress/sdk": "6.0.0",
"@botpress/client": "1.37.0",
"@botpress/sdk": "6.1.0",
"@bpinternal/const": "^0.1.0",
"@bpinternal/tunnel": "^0.1.1",
"@bpinternal/verel": "^0.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/templates/empty-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
},
"private": true,
"dependencies": {
"@botpress/client": "1.36.0",
"@botpress/sdk": "6.0.0"
"@botpress/client": "1.37.0",
"@botpress/sdk": "6.1.0"
},
"devDependencies": {
"@types/node": "^22.16.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/templates/empty-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"private": true,
"dependencies": {
"@botpress/client": "1.36.0",
"@botpress/sdk": "6.0.0"
"@botpress/client": "1.37.0",
"@botpress/sdk": "6.1.0"
},
"devDependencies": {
"@types/node": "^22.16.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/empty-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"private": true,
"dependencies": {
"@botpress/sdk": "6.0.0"
"@botpress/sdk": "6.1.0"
},
"devDependencies": {
"@types/node": "^22.16.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/templates/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"private": true,
"dependencies": {
"@botpress/client": "1.36.0",
"@botpress/sdk": "6.0.0"
"@botpress/client": "1.37.0",
"@botpress/sdk": "6.1.0"
},
"devDependencies": {
"@types/node": "^22.16.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/templates/webhook-message/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"private": true,
"dependencies": {
"@botpress/client": "1.36.0",
"@botpress/sdk": "6.0.0",
"@botpress/client": "1.37.0",
"@botpress/sdk": "6.1.0",
"axios": "^1.6.8"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botpress/client",
"version": "1.36.0",
"version": "1.37.0",
"description": "Botpress Client",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/llmz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"tsx": "^4.19.2"
},
"peerDependencies": {
"@botpress/client": "1.36.0",
"@botpress/client": "1.37.0",
"@botpress/cognitive": "0.3.18",
"@bpinternal/thicktoken": "^2.0.0",
"@bpinternal/zui": "^2.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botpress/sdk",
"version": "6.0.0",
"version": "6.1.0",
"description": "Botpress SDK",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand All @@ -20,7 +20,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@botpress/client": "1.36.0",
"@botpress/client": "1.37.0",
"browser-or-node": "^2.1.1",
"semver": "^7.3.8"
},
Expand Down
19 changes: 17 additions & 2 deletions packages/sdk/src/bot/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ type MessageResponse<
}>
}

type GetOrCreateMessageResponse<
TBot extends common.BaseBot,
TMessage extends keyof common.GetMessages<TBot> = keyof common.GetMessages<TBot>,
> = utils.Merge<
Awaited<Res<client.Client['getOrCreateMessage']>>,
{
message: utils.ValueOf<{
[K in keyof common.GetMessages<TBot> as K extends TMessage ? K : never]: utils.Merge<
Awaited<Res<client.Client['getOrCreateMessage']>>['message'],
{ type: K; payload: common.GetMessages<TBot>[K] }
>
}>
}
>

type StateResponse<
TBot extends common.BaseBot,
TState extends keyof TBot['states'] = keyof TBot['states'],
Expand Down Expand Up @@ -84,11 +99,11 @@ export type GetOrCreateMessage<TBot extends common.BaseBot> = <TMessage extends
Arg<client.Client['getOrCreateMessage']>,
{
type: utils.Cast<TMessage, string>
payload: utils.Cast<common.GetMessages<TBot>[TMessage], Record<string, any>>
payload?: utils.Cast<common.GetMessages<TBot>[TMessage], Record<string, any>>
// TODO: use bot definiton message property to infer allowed tags
}
>
) => Promise<MessageResponse<TBot, TMessage>>
) => Promise<GetOrCreateMessageResponse<TBot, TMessage>>

export type GetMessage<TBot extends common.BaseBot> = (
x: Arg<client.Client['getMessage']>
Expand Down
26 changes: 23 additions & 3 deletions packages/sdk/src/integration/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ export type CreateMessage<TIntegration extends common.BaseIntegration> = <
>
) => Promise<MessageResponse<TIntegration, TMessage>>

type GetOrCreateMessageResponse<
TIntegration extends common.BaseIntegration,
TMessage extends keyof EnumerateMessages<TIntegration> = keyof EnumerateMessages<TIntegration>,
> = utils.Merge<
Awaited<Res<client.Client['getOrCreateMessage']>>,
{
message: utils.Merge<
Awaited<Res<client.Client['getOrCreateMessage']>>['message'],
utils.Cast<EnumerateMessages<TIntegration>[TMessage], object>
>
}
>

export type GetOrCreateMessage<TIntegration extends common.BaseIntegration> = <
TMessage extends keyof EnumerateMessages<TIntegration>,
TTags extends keyof GetMessageByName<TIntegration, TMessage>['tags'],
Expand All @@ -167,13 +180,13 @@ export type GetOrCreateMessage<TIntegration extends common.BaseIntegration> = <
Arg<client.Client['getOrCreateMessage']>,
{
type: utils.Cast<TMessage, string>
payload: GetMessageByName<TIntegration, TMessage>['payload']
payload?: GetMessageByName<TIntegration, TMessage>['payload']
tags: commonTypes.ToTags<TTags>
// TODO: find a way to restrict discriminateByTags to tags present in x.tags
discriminateByTags?: NoInfer<utils.Cast<TTags[], string[]>>
}
>
) => Promise<MessageResponse<TIntegration, TMessage>>
) => Promise<GetOrCreateMessageResponse<TIntegration, TMessage>>

export type GetMessage<TIntegration extends common.BaseIntegration> = (
x: Arg<client.Client['getMessage']>
Expand Down Expand Up @@ -230,6 +243,13 @@ export type ListUsers<TIntegration extends common.BaseIntegration> = (
>
) => Res<client.Client['listUsers']>

type GetOrCreateUserResponse<TIntegration extends common.BaseIntegration> = utils.Merge<
Awaited<Res<client.Client['getOrCreateUser']>>,
{
user: utils.Merge<Awaited<Res<client.Client['getOrCreateUser']>>['user'], { tags: UserTags<TIntegration> }>
}
>

export type GetOrCreateUser<TIntegration extends common.BaseIntegration> = <
TTags extends keyof TIntegration['user']['tags'],
>(
Expand All @@ -240,7 +260,7 @@ export type GetOrCreateUser<TIntegration extends common.BaseIntegration> = <
discriminateByTags?: NoInfer<utils.Cast<TTags[], string[]>>
}
>
) => Promise<UserResponse<TIntegration>>
) => Promise<GetOrCreateUserResponse<TIntegration>>

export type UpdateUser<TIntegration extends common.BaseIntegration> = (
x: utils.Merge<
Expand Down
2 changes: 1 addition & 1 deletion packages/vai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"tsup": "^8.0.2"
},
"peerDependencies": {
"@botpress/client": "1.36.0",
"@botpress/client": "1.37.0",
"@bpinternal/thicktoken": "^1.0.1",
"@bpinternal/zui": "^2.0.0",
"lodash": "^4.17.21",
Expand Down
5 changes: 3 additions & 2 deletions packages/zui/src/z/__tests__/mandatory.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, test, expect } from 'vitest'
import * as z from '../index'
import * as transforms from '../../transforms'
import { IZodType } from '../typings'

const expectZui = (actual: z.ZodType) => ({
not: {
Expand Down Expand Up @@ -53,8 +54,8 @@ describe('mandatory', () => {
expectZui(requiredSchema).toEqual(z.union([z.string(), z.number()]))
})
test('empty union', () => {
const options: any[] = []
const schema = z.union(options as [any, any]) // should not be allowed
const options: readonly IZodType[] = []
const schema = z.union(options as readonly [IZodType, IZodType]) // should not be allowed
const requiredSchema = schema.mandatory()
expect(requiredSchema.isOptional()).toBe(false)
expectZui(requiredSchema).toEqual(z.never())
Expand Down
2 changes: 1 addition & 1 deletion packages/zui/src/z/__tests__/object-augmentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ test('object augmentation', () => {
ModifiedAnimal.parse({
species: 'asdf',
population: 1324,
} as any)
})
expect(bad).toThrow()
})
2 changes: 1 addition & 1 deletion packages/zui/src/z/__tests__/set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ test('throws when the given set has invalid input', () => {
})

test('throws when the given set has multiple invalid entries', () => {
const result = stringSet.safeParse(new Set([1, 2]) as Set<any>)
const result = stringSet.safeParse(new Set([1, 2]))

expect(result.success).toEqual(false)
if (result.success === false) {
Expand Down
31 changes: 15 additions & 16 deletions packages/zui/src/z/error/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import * as utils from '../../utils'
import type { ZodIssue, ZodFormattedError, ZodErrorMap, IZodError } from '../typings'
import { errorMap as defaultErrorMap } from './locales/en'

type _FieldErrors<U> = {
_errors: U[]
} & {
[K in string | number]: _FieldErrors<U> | unknown[]
}

export class ZodError<T = any> extends Error implements IZodError<T> {
readonly __type__ = 'ZuiError'

Expand All @@ -24,15 +30,15 @@ export class ZodError<T = any> extends Error implements IZodError<T> {
this.issues = issues
}

format(): ZodFormattedError<T>
format(): ZodFormattedError<T, string>
format<U>(mapper: (issue: ZodIssue) => U): ZodFormattedError<T, U>
format(_mapper?: any) {
const mapper: (issue: ZodIssue) => any =
format<U>(_mapper?: (issue: ZodIssue) => U): ZodFormattedError<T, U> {
const mapper: (issue: ZodIssue) => U =
_mapper ||
function (issue: ZodIssue) {
return issue.message
return issue.message as U
}
const fieldErrors = { _errors: [] } as ZodFormattedError<T>
const fieldErrors: _FieldErrors<U> = { _errors: [] }
const processError = (error: ZodError) => {
for (const issue of error.issues) {
if (issue.code === 'invalid_union') {
Expand All @@ -44,35 +50,28 @@ export class ZodError<T = any> extends Error implements IZodError<T> {
} else if (issue.path.length === 0) {
fieldErrors._errors.push(mapper(issue))
} else {
let curr: any = fieldErrors
let curr = fieldErrors
let i = 0
while (i < issue.path.length) {
const el = issue.path[i]!
const terminal = i === issue.path.length - 1

if (!terminal) {
curr[el] = curr[el] || { _errors: [] }
// if (typeof el === "string") {
// curr[el] = curr[el] || { _errors: [] };
// } else if (typeof el === "number") {
// const errorArray: any = [];
// errorArray._errors = [];
// curr[el] = curr[el] || errorArray;
// }
} else {
curr[el] = curr[el] || { _errors: [] }
curr[el]._errors.push(mapper(issue))
;(curr[el] as _FieldErrors<U>)._errors.push(mapper(issue))
}

curr = curr[el]
curr = curr[el] as _FieldErrors<U>
i++
}
}
}
}

processError(this)
return fieldErrors
return fieldErrors as ZodFormattedError<T, U>
}

static create = (issues: ZodIssue[]) => {
Expand Down
Loading
Loading