@botpress/zai 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,7 @@ It's built on top of Zui and the Botpress client to interface with the different
10
10
  import Zai from '@botpress/zai'
11
11
 
12
12
  const zai = new Zai({
13
- client: new Client({}) // your botpress client here
13
+ client: new Client({}), // your botpress client here
14
14
  })
15
15
  ```
16
16
 
package/build.ts ADDED
@@ -0,0 +1,9 @@
1
+ import esbuild from 'esbuild'
2
+ import glob from 'glob'
3
+
4
+ const entryPoints = glob.sync('./src/**/*.ts')
5
+ void esbuild.build({
6
+ entryPoints,
7
+ platform: 'neutral',
8
+ outdir: './dist',
9
+ })
@@ -1,5 +1,5 @@
1
1
  import { z } from "@bpinternal/zui";
2
- import { BotpressClient, GenerationMetadata } from "../utils";
2
+ import { GenerationMetadata } from "../utils";
3
3
  import { Adapter } from "./adapter";
4
4
  const CRITICAL_TAGS = {
5
5
  system: "true",
@@ -15,7 +15,7 @@ const OPTIONAL_TAGS = {
15
15
  };
16
16
  const FACTOR = 30;
17
17
  const Props = z.object({
18
- client: BotpressClient,
18
+ client: z.custom(() => true),
19
19
  tableName: z.string().regex(
20
20
  /^[a-zA-Z0-9_]{1,45}Table$/,
21
21
  "Table name must be lowercase and contain only letters, numbers and underscores"
@@ -44,20 +44,20 @@ const TableJsonSchema = Object.entries(TableSchema.shape).reduce((acc, [key, val
44
44
  return acc;
45
45
  }, {});
46
46
  export class TableAdapter extends Adapter {
47
- client;
48
- tableName;
49
- status;
47
+ _client;
48
+ _tableName;
49
+ _status;
50
50
  constructor(props) {
51
51
  super();
52
52
  props = Props.parse(props);
53
- this.client = props.client;
54
- this.tableName = props.tableName;
55
- this.status = "ready";
53
+ this._client = props.client;
54
+ this._tableName = props.tableName;
55
+ this._status = "ready";
56
56
  }
57
57
  async getExamples({ taskType, taskId, input }) {
58
- await this.assertTableExists();
59
- const { rows } = await this.client.findTableRows({
60
- table: this.tableName,
58
+ await this._assertTableExists();
59
+ const { rows } = await this._client.findTableRows({
60
+ table: this._tableName,
61
61
  search: JSON.stringify({ value: input }).substring(0, 1023),
62
62
  // Search is limited to 1024 characters
63
63
  limit: 10,
@@ -91,9 +91,9 @@ export class TableAdapter extends Adapter {
91
91
  metadata,
92
92
  status = "pending"
93
93
  }) {
94
- await this.assertTableExists();
95
- await this.client.upsertTableRows({
96
- table: this.tableName,
94
+ await this._assertTableExists();
95
+ await this._client.upsertTableRows({
96
+ table: this._tableName,
97
97
  keyColumn: "key",
98
98
  rows: [
99
99
  {
@@ -111,12 +111,12 @@ export class TableAdapter extends Adapter {
111
111
  }).catch(() => {
112
112
  });
113
113
  }
114
- async assertTableExists() {
115
- if (this.status !== "ready") {
114
+ async _assertTableExists() {
115
+ if (this._status !== "ready") {
116
116
  return;
117
117
  }
118
- const { table, created } = await this.client.getOrCreateTable({
119
- table: this.tableName,
118
+ const { table, created } = await this._client.getOrCreateTable({
119
+ table: this._tableName,
120
120
  factor: FACTOR,
121
121
  frozen: true,
122
122
  isComputeEnabled: false,
@@ -126,7 +126,7 @@ export class TableAdapter extends Adapter {
126
126
  },
127
127
  schema: TableJsonSchema
128
128
  }).catch(() => {
129
- this.status = "error";
129
+ this._status = "error";
130
130
  return { table: null, created: false };
131
131
  });
132
132
  if (!table) {
@@ -160,9 +160,9 @@ export class TableAdapter extends Adapter {
160
160
  }
161
161
  }
162
162
  if (issues.length) {
163
- this.status = "error";
163
+ this._status = "error";
164
164
  }
165
165
  }
166
- this.status = "initialized";
166
+ this._status = "initialized";
167
167
  }
168
168
  }