diff --git a/package.json b/package.json index b290ca2bbdc..c53b31a1b0b 100644 --- a/package.json +++ b/package.json @@ -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:*", diff --git a/packages/cli/package.json b/packages/cli/package.json index 60d621067bd..e6b68c8edc8 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", diff --git a/packages/cli/templates/empty-bot/package.json b/packages/cli/templates/empty-bot/package.json index e5ceb114d6f..598fe09fc17 100644 --- a/packages/cli/templates/empty-bot/package.json +++ b/packages/cli/templates/empty-bot/package.json @@ -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", diff --git a/packages/cli/templates/empty-integration/package.json b/packages/cli/templates/empty-integration/package.json index 51926822d4f..f88a3e0209a 100644 --- a/packages/cli/templates/empty-integration/package.json +++ b/packages/cli/templates/empty-integration/package.json @@ -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", diff --git a/packages/cli/templates/empty-plugin/package.json b/packages/cli/templates/empty-plugin/package.json index bd7679c6e56..b8093914888 100644 --- a/packages/cli/templates/empty-plugin/package.json +++ b/packages/cli/templates/empty-plugin/package.json @@ -6,7 +6,7 @@ }, "private": true, "dependencies": { - "@botpress/sdk": "6.0.0" + "@botpress/sdk": "6.1.0" }, "devDependencies": { "@types/node": "^22.16.4", diff --git a/packages/cli/templates/hello-world/package.json b/packages/cli/templates/hello-world/package.json index 65e239d0843..7123d105d5a 100644 --- a/packages/cli/templates/hello-world/package.json +++ b/packages/cli/templates/hello-world/package.json @@ -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", diff --git a/packages/cli/templates/webhook-message/package.json b/packages/cli/templates/webhook-message/package.json index d8c4b772547..cc70c73e3fc 100644 --- a/packages/cli/templates/webhook-message/package.json +++ b/packages/cli/templates/webhook-message/package.json @@ -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": { diff --git a/packages/client/package.json b/packages/client/package.json index f804c283901..11ae25c87f3 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -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", diff --git a/packages/llmz/package.json b/packages/llmz/package.json index 5d678381323..fa45a872a9d 100644 --- a/packages/llmz/package.json +++ b/packages/llmz/package.json @@ -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" diff --git a/packages/sdk/package.json b/packages/sdk/package.json index d6810cf315f..792f9563304 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -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", @@ -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" }, diff --git a/packages/sdk/src/bot/client/types.ts b/packages/sdk/src/bot/client/types.ts index 29e88417377..cd91cb48d3a 100644 --- a/packages/sdk/src/bot/client/types.ts +++ b/packages/sdk/src/bot/client/types.ts @@ -27,6 +27,21 @@ type MessageResponse< }> } +type GetOrCreateMessageResponse< + TBot extends common.BaseBot, + TMessage extends keyof common.GetMessages = keyof common.GetMessages, +> = utils.Merge< + Awaited>, + { + message: utils.ValueOf<{ + [K in keyof common.GetMessages as K extends TMessage ? K : never]: utils.Merge< + Awaited>['message'], + { type: K; payload: common.GetMessages[K] } + > + }> + } +> + type StateResponse< TBot extends common.BaseBot, TState extends keyof TBot['states'] = keyof TBot['states'], @@ -84,11 +99,11 @@ export type GetOrCreateMessage = , { type: utils.Cast - payload: utils.Cast[TMessage], Record> + payload?: utils.Cast[TMessage], Record> // TODO: use bot definiton message property to infer allowed tags } > -) => Promise> +) => Promise> export type GetMessage = ( x: Arg diff --git a/packages/sdk/src/integration/client/types.ts b/packages/sdk/src/integration/client/types.ts index 37b2a81258d..9453afd5bd3 100644 --- a/packages/sdk/src/integration/client/types.ts +++ b/packages/sdk/src/integration/client/types.ts @@ -159,6 +159,19 @@ export type CreateMessage = < > ) => Promise> +type GetOrCreateMessageResponse< + TIntegration extends common.BaseIntegration, + TMessage extends keyof EnumerateMessages = keyof EnumerateMessages, +> = utils.Merge< + Awaited>, + { + message: utils.Merge< + Awaited>['message'], + utils.Cast[TMessage], object> + > + } +> + export type GetOrCreateMessage = < TMessage extends keyof EnumerateMessages, TTags extends keyof GetMessageByName['tags'], @@ -167,13 +180,13 @@ export type GetOrCreateMessage = < Arg, { type: utils.Cast - payload: GetMessageByName['payload'] + payload?: GetMessageByName['payload'] tags: commonTypes.ToTags // TODO: find a way to restrict discriminateByTags to tags present in x.tags discriminateByTags?: NoInfer> } > -) => Promise> +) => Promise> export type GetMessage = ( x: Arg @@ -230,6 +243,13 @@ export type ListUsers = ( > ) => Res +type GetOrCreateUserResponse = utils.Merge< + Awaited>, + { + user: utils.Merge>['user'], { tags: UserTags }> + } +> + export type GetOrCreateUser = < TTags extends keyof TIntegration['user']['tags'], >( @@ -240,7 +260,7 @@ export type GetOrCreateUser = < discriminateByTags?: NoInfer> } > -) => Promise> +) => Promise> export type UpdateUser = ( x: utils.Merge< diff --git a/packages/vai/package.json b/packages/vai/package.json index 6025ac2acef..19ed6e11970 100644 --- a/packages/vai/package.json +++ b/packages/vai/package.json @@ -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", diff --git a/packages/zui/src/z/__tests__/mandatory.test.ts b/packages/zui/src/z/__tests__/mandatory.test.ts index faf89af60fe..fb140eebb6f 100644 --- a/packages/zui/src/z/__tests__/mandatory.test.ts +++ b/packages/zui/src/z/__tests__/mandatory.test.ts @@ -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: { @@ -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()) diff --git a/packages/zui/src/z/__tests__/object-augmentation.test.ts b/packages/zui/src/z/__tests__/object-augmentation.test.ts index 42c9e817451..8c9c8ececb4 100644 --- a/packages/zui/src/z/__tests__/object-augmentation.test.ts +++ b/packages/zui/src/z/__tests__/object-augmentation.test.ts @@ -22,6 +22,6 @@ test('object augmentation', () => { ModifiedAnimal.parse({ species: 'asdf', population: 1324, - } as any) + }) expect(bad).toThrow() }) diff --git a/packages/zui/src/z/__tests__/set.test.ts b/packages/zui/src/z/__tests__/set.test.ts index a0e70aea05d..083ca5663ff 100644 --- a/packages/zui/src/z/__tests__/set.test.ts +++ b/packages/zui/src/z/__tests__/set.test.ts @@ -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) + const result = stringSet.safeParse(new Set([1, 2])) expect(result.success).toEqual(false) if (result.success === false) { diff --git a/packages/zui/src/z/error/index.ts b/packages/zui/src/z/error/index.ts index 7a196f5714a..83e46d07263 100644 --- a/packages/zui/src/z/error/index.ts +++ b/packages/zui/src/z/error/index.ts @@ -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 = { + _errors: U[] +} & { + [K in string | number]: _FieldErrors | unknown[] +} + export class ZodError extends Error implements IZodError { readonly __type__ = 'ZuiError' @@ -24,15 +30,15 @@ export class ZodError extends Error implements IZodError { this.issues = issues } - format(): ZodFormattedError + format(): ZodFormattedError format(mapper: (issue: ZodIssue) => U): ZodFormattedError - format(_mapper?: any) { - const mapper: (issue: ZodIssue) => any = + format(_mapper?: (issue: ZodIssue) => U): ZodFormattedError { + const mapper: (issue: ZodIssue) => U = _mapper || function (issue: ZodIssue) { - return issue.message + return issue.message as U } - const fieldErrors = { _errors: [] } as ZodFormattedError + const fieldErrors: _FieldErrors = { _errors: [] } const processError = (error: ZodError) => { for (const issue of error.issues) { if (issue.code === 'invalid_union') { @@ -44,7 +50,7 @@ export class ZodError extends Error implements IZodError { } 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]! @@ -52,19 +58,12 @@ export class ZodError extends Error implements IZodError { 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)._errors.push(mapper(issue)) } - curr = curr[el] + curr = curr[el] as _FieldErrors i++ } } @@ -72,7 +71,7 @@ export class ZodError extends Error implements IZodError { } processError(this) - return fieldErrors + return fieldErrors as ZodFormattedError } static create = (issues: ZodIssue[]) => { diff --git a/packages/zui/src/z/types/readonly/readonly.test.ts b/packages/zui/src/z/types/readonly/readonly.test.ts index 6ba552e45a3..ef488f57b09 100644 --- a/packages/zui/src/z/types/readonly/readonly.test.ts +++ b/packages/zui/src/z/types/readonly/readonly.test.ts @@ -59,86 +59,6 @@ test('flat inference', () => { assert.assertEqual, Promise>(true) }) -// test("deep inference", () => { -// assert.assertEqual, string>(true); -// assert.assertEqual, number>(true); -// assert.assertEqual, number>(true); -// assert.assertEqual, bigint>(true); -// assert.assertEqual, boolean>(true); -// assert.assertEqual, Date>(true); -// assert.assertEqual, undefined>(true); -// assert.assertEqual, null>(true); -// assert.assertEqual, any>(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[9]>, -// Readonly -// >(true); -// assert.assertEqual, void>(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[11]>, -// (args_0: string, args_1: number, ...args_2: unknown[]) => unknown -// >(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[12]>, -// readonly string[] -// >(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[13]>, -// readonly [string, number] -// >(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[14]>, -// ReadonlyMap -// >(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[15]>, -// ReadonlySet> -// >(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[16]>, -// Readonly> -// >(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[17]>, -// Readonly> -// >(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[18]>, -// { readonly a: string; readonly 1: number } -// >(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[19]>, -// Readonly -// >(true); -// assert.assertEqual< -// z.infer<(typeof deepReadonlySchemas_0)[20]>, -// Promise -// >(true); - -// assert.assertEqual< -// z.infer, -// ReadonlyMap< -// ReadonlySet, -// { -// readonly a: { -// readonly [x: string]: readonly any[]; -// }; -// readonly b: { -// readonly c: { -// readonly d: { -// readonly e: { -// readonly f: { -// readonly g?: {}; -// }; -// }; -// }; -// }; -// }; -// } -// > -// >(true); -// }); - test('object freezing', () => { expect(Object.isFrozen(z.array(z.string()).readonly().parse(['a']))).toBe(true) expect(Object.isFrozen(z.tuple([z.string(), z.number()]).readonly().parse(['a', 1]))).toBe(true) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 20379639ad9..8c7f39cd510 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,8 +17,8 @@ importers: specifier: ^3.564.0 version: 3.709.0 '@botpress/api': - specifier: 1.76.0 - version: 1.76.0 + specifier: 1.80.0 + version: 1.80.0 '@botpress/cli': specifier: workspace:* version: link:packages/cli @@ -2533,10 +2533,10 @@ importers: specifier: 0.5.5 version: link:../chat-client '@botpress/client': - specifier: 1.36.0 + specifier: 1.37.0 version: link:../client '@botpress/sdk': - specifier: 6.0.0 + specifier: 6.1.0 version: link:../sdk '@bpinternal/const': specifier: ^0.1.0 @@ -2657,10 +2657,10 @@ importers: packages/cli/templates/empty-bot: dependencies: '@botpress/client': - specifier: 1.36.0 + specifier: 1.37.0 version: link:../../../client '@botpress/sdk': - specifier: 6.0.0 + specifier: 6.1.0 version: link:../../../sdk devDependencies: '@types/node': @@ -2673,10 +2673,10 @@ importers: packages/cli/templates/empty-integration: dependencies: '@botpress/client': - specifier: 1.36.0 + specifier: 1.37.0 version: link:../../../client '@botpress/sdk': - specifier: 6.0.0 + specifier: 6.1.0 version: link:../../../sdk devDependencies: '@types/node': @@ -2689,7 +2689,7 @@ importers: packages/cli/templates/empty-plugin: dependencies: '@botpress/sdk': - specifier: 6.0.0 + specifier: 6.1.0 version: link:../../../sdk devDependencies: '@types/node': @@ -2702,10 +2702,10 @@ importers: packages/cli/templates/hello-world: dependencies: '@botpress/client': - specifier: 1.36.0 + specifier: 1.37.0 version: link:../../../client '@botpress/sdk': - specifier: 6.0.0 + specifier: 6.1.0 version: link:../../../sdk devDependencies: '@types/node': @@ -2718,10 +2718,10 @@ importers: packages/cli/templates/webhook-message: dependencies: '@botpress/client': - specifier: 1.36.0 + specifier: 1.37.0 version: link:../../../client '@botpress/sdk': - specifier: 6.0.0 + specifier: 6.1.0 version: link:../../../sdk axios: specifier: ^1.6.8 @@ -2872,7 +2872,7 @@ importers: specifier: ^7.26.3 version: 7.26.9 '@botpress/client': - specifier: 1.36.0 + specifier: 1.37.0 version: link:../client '@botpress/cognitive': specifier: 0.3.18 @@ -2978,7 +2978,7 @@ importers: packages/sdk: dependencies: '@botpress/client': - specifier: 1.36.0 + specifier: 1.37.0 version: link:../client '@bpinternal/zui': specifier: ^2.0.0 @@ -3015,7 +3015,7 @@ importers: packages/vai: dependencies: '@botpress/client': - specifier: 1.36.0 + specifier: 1.37.0 version: link:../client '@bpinternal/thicktoken': specifier: ^1.0.1 @@ -4032,8 +4032,8 @@ packages: '@bcoe/v8-coverage@0.2.3': resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} - '@botpress/api@1.76.0': - resolution: {integrity: sha512-SRKVM0ak9gJGB6TOlraMx5pLQS8Cm58xwBPOiilmuNzB9Cab1hpSJuK4F4ErDOeL2fFEcXAa01/92AA0t/JRmA==} + '@botpress/api@1.80.0': + resolution: {integrity: sha512-2XvtI5xoV+QMW88C1+iL38f3vcor4h9htc4i0+ZT68a2GiFeEwKeIXc0P8rIb64s4xNra3izrR7sbEjOsSnBhQ==} '@bpinternal/const@0.1.0': resolution: {integrity: sha512-iIQg9oYYXOt+LSK34oNhJVQTcgRdtLmLZirEUaE+R9hnmbKONA5reR2kTewxZmekGyxej+5RtDK9xrC/0hmeAw==} @@ -13440,7 +13440,7 @@ snapshots: '@bcoe/v8-coverage@0.2.3': {} - '@botpress/api@1.76.0': + '@botpress/api@1.80.0': dependencies: '@bpinternal/opapi': 1.0.0(openapi-types@12.1.3) transitivePeerDependencies: @@ -18470,7 +18470,7 @@ snapshots: dezalgo: 1.0.4 hexoid: 1.0.0 once: 1.4.0 - qs: 6.13.0 + qs: 6.15.0 forwarded@0.2.0: {} @@ -21278,7 +21278,6 @@ snapshots: qs@6.15.0: dependencies: side-channel: 1.1.0 - optional: true qs@6.5.3: {} @@ -22122,7 +22121,7 @@ snapshots: formidable: 2.1.2 methods: 1.1.2 mime: 2.6.0 - qs: 6.13.0 + qs: 6.15.0 readable-stream: 3.6.2 semver: 7.7.2 transitivePeerDependencies: