@botpress/cognitive 0.1.49 → 0.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/dist/index.d.ts CHANGED
@@ -3977,6 +3977,10 @@ interface GetOrCreateWorkflowRequestBody {
3977
3977
  * Optional list of tag names to use for strict matching when looking up existing workflows. If provided, all specified tags must match exactly for a workflow to be considered a match. For example, with an existing workflow whose tags are {"foo": "a", "bar": "b", baz: "c"}: Without this parameter, ALL tags must match exactly. With ["bar","baz"], all listed tags must match their values, and other tags are not considered.
3978
3978
  */
3979
3979
  discriminateByTags?: string[];
3980
+ /**
3981
+ * When provided, will only match workflows whose status corresponds to the status group.
3982
+ */
3983
+ discriminateByStatusGroup?: "active" | "finished";
3980
3984
  }
3981
3985
  type GetOrCreateWorkflowInput = GetOrCreateWorkflowRequestBody & GetOrCreateWorkflowRequestHeaders & GetOrCreateWorkflowRequestQuery & GetOrCreateWorkflowRequestParams;
3982
3986
  interface GetOrCreateWorkflowResponse {
@@ -6615,9 +6619,20 @@ interface CreateBotResponse {
6615
6619
  interfaces?: {
6616
6620
  [k: string]: {
6617
6621
  integrationId: string;
6622
+ integrationAlias: string;
6623
+ integrationInterfaceAlias?: string;
6618
6624
  interfaceId: string;
6619
6625
  };
6620
6626
  };
6627
+ /**
6628
+ * A mapping of plugin integration aliases to their backing integrations
6629
+ */
6630
+ integrations?: {
6631
+ [k: string]: {
6632
+ integrationId: string;
6633
+ integrationAlias: string;
6634
+ };
6635
+ };
6621
6636
  /**
6622
6637
  * ID of the [Plugin](#schema_plugin)
6623
6638
  */
@@ -7108,6 +7123,23 @@ interface UpdateBotRequestBody {
7108
7123
  interfaces?: {
7109
7124
  [k: string]: {
7110
7125
  integrationId: string;
7126
+ /**
7127
+ * When an alias is provided, the plugin will use the integration corresponding to this alias. If not provided, the first integration matching the integrationId will be used.
7128
+ */
7129
+ integrationAlias?: string;
7130
+ /**
7131
+ * When an alias is provided, the plugin will use the integration interface corresponding to this alias.
7132
+ */
7133
+ integrationInterfaceAlias?: string;
7134
+ };
7135
+ };
7136
+ /**
7137
+ * A mapping of plugin integration aliases to their backing integrations
7138
+ */
7139
+ integrations?: {
7140
+ [k: string]: {
7141
+ integrationId: string;
7142
+ integrationAlias: string;
7111
7143
  };
7112
7144
  };
7113
7145
  } | null;
@@ -7246,9 +7278,20 @@ interface UpdateBotResponse {
7246
7278
  interfaces?: {
7247
7279
  [k: string]: {
7248
7280
  integrationId: string;
7281
+ integrationAlias: string;
7282
+ integrationInterfaceAlias?: string;
7249
7283
  interfaceId: string;
7250
7284
  };
7251
7285
  };
7286
+ /**
7287
+ * A mapping of plugin integration aliases to their backing integrations
7288
+ */
7289
+ integrations?: {
7290
+ [k: string]: {
7291
+ integrationId: string;
7292
+ integrationAlias: string;
7293
+ };
7294
+ };
7252
7295
  /**
7253
7296
  * ID of the [Plugin](#schema_plugin)
7254
7297
  */
@@ -7709,9 +7752,20 @@ interface GetBotResponse {
7709
7752
  interfaces?: {
7710
7753
  [k: string]: {
7711
7754
  integrationId: string;
7755
+ integrationAlias: string;
7756
+ integrationInterfaceAlias?: string;
7712
7757
  interfaceId: string;
7713
7758
  };
7714
7759
  };
7760
+ /**
7761
+ * A mapping of plugin integration aliases to their backing integrations
7762
+ */
7763
+ integrations?: {
7764
+ [k: string]: {
7765
+ integrationId: string;
7766
+ integrationAlias: string;
7767
+ };
7768
+ };
7715
7769
  /**
7716
7770
  * ID of the [Plugin](#schema_plugin)
7717
7771
  */
@@ -8374,6 +8428,7 @@ interface DeployBotVersionResponse {
8374
8428
  interface CreateIntegrationShareableIdRequestHeaders {
8375
8429
  }
8376
8430
  interface CreateIntegrationShareableIdRequestQuery {
8431
+ integrationInstanceAlias?: string;
8377
8432
  }
8378
8433
  interface CreateIntegrationShareableIdRequestParams {
8379
8434
  botId: string;
@@ -8389,6 +8444,7 @@ interface CreateIntegrationShareableIdResponse {
8389
8444
  interface DeleteIntegrationShareableIdRequestHeaders {
8390
8445
  }
8391
8446
  interface DeleteIntegrationShareableIdRequestQuery {
8447
+ integrationInstanceAlias?: string;
8392
8448
  }
8393
8449
  interface DeleteIntegrationShareableIdRequestParams {
8394
8450
  botId: string;
@@ -8403,6 +8459,7 @@ interface DeleteIntegrationShareableIdResponse {
8403
8459
  interface GetIntegrationShareableIdRequestHeaders {
8404
8460
  }
8405
8461
  interface GetIntegrationShareableIdRequestQuery {
8462
+ integrationInstanceAlias?: string;
8406
8463
  }
8407
8464
  interface GetIntegrationShareableIdRequestParams {
8408
8465
  botId: string;
@@ -8419,6 +8476,7 @@ interface GetIntegrationShareableIdResponse {
8419
8476
  interface UnlinkSandboxedConversationsRequestHeaders {
8420
8477
  }
8421
8478
  interface UnlinkSandboxedConversationsRequestQuery {
8479
+ integrationInstanceAlias?: string;
8422
8480
  }
8423
8481
  interface UnlinkSandboxedConversationsRequestParams {
8424
8482
  botId: string;
@@ -8689,6 +8747,7 @@ interface CreateWorkspaceResponse {
8689
8747
  socialAccounts?: string[];
8690
8748
  isPublic?: boolean;
8691
8749
  handle?: string;
8750
+ activeTrialId: string | null;
8692
8751
  }
8693
8752
 
8694
8753
  interface GetPublicWorkspaceRequestHeaders {
@@ -8742,6 +8801,7 @@ interface GetWorkspaceResponse {
8742
8801
  socialAccounts?: string[];
8743
8802
  isPublic?: boolean;
8744
8803
  handle?: string;
8804
+ activeTrialId: string | null;
8745
8805
  }
8746
8806
 
8747
8807
  interface ListWorkspaceUsagesRequestHeaders {
@@ -8913,6 +8973,7 @@ interface UpdateWorkspaceResponse$1 {
8913
8973
  socialAccounts?: string[];
8914
8974
  isPublic?: boolean;
8915
8975
  handle?: string;
8976
+ activeTrialId: string | null;
8916
8977
  }
8917
8978
 
8918
8979
  interface CheckHandleAvailabilityRequestHeaders {
@@ -8969,6 +9030,7 @@ interface UpdateWorkspaceResponse {
8969
9030
  socialAccounts?: string[];
8970
9031
  isPublic?: boolean;
8971
9032
  handle?: string;
9033
+ activeTrialId: string | null;
8972
9034
  }
8973
9035
 
8974
9036
  interface ListPublicWorkspacesRequestHeaders {
@@ -9038,7 +9100,7 @@ interface GetAuditRecordsResponse {
9038
9100
  resourceId: string | null;
9039
9101
  resourceName?: string | null;
9040
9102
  value?: string | null;
9041
- action: "UNKNOWN" | "ADD_WORKSPACE_MEMBER" | "REMOVE_WORKSPACE_MEMBER" | "UPDATE_WORKSPACE_MEMBER" | "CLOSE_WORKSPACE" | "CREATE_BOT" | "CREATE_WORKSPACE" | "DELETE_BOT" | "DEPLOY_BOT" | "TRANSFER_BOT" | "DOWNLOAD_BOT_ARCHIVE" | "UPDATE_BOT" | "UPDATE_BOT_CHANNEL" | "UPDATE_BOT_CONFIG" | "UPDATE_PAYMENT_METHOD" | "UPDATE_WORKSPACE" | "SET_SPENDING_LIMIT" | "SET_AI_SPENDING_LIMIT" | "UPDATE_WORKSPACE_BILLING_READONLY";
9103
+ action: "UNKNOWN" | "ADD_WORKSPACE_MEMBER" | "REMOVE_WORKSPACE_MEMBER" | "UPDATE_WORKSPACE_MEMBER" | "CLOSE_WORKSPACE" | "CREATE_BOT" | "CREATE_WORKSPACE" | "DELETE_BOT" | "DEPLOY_BOT" | "TRANSFER_BOT" | "DOWNLOAD_BOT_ARCHIVE" | "UPDATE_BOT" | "UPDATE_BOT_CHANNEL" | "UPDATE_BOT_CONFIG" | "UPDATE_PAYMENT_METHOD" | "UPDATE_WORKSPACE" | "SET_SPENDING_LIMIT" | "SET_AI_SPENDING_LIMIT" | "UPDATE_WORKSPACE_BILLING_READONLY" | "EXECUTE_AUTO_RECHARGE_SUCCESS" | "EXECUTE_AUTO_RECHARGE_FAILED";
9042
9104
  }[];
9043
9105
  meta: {
9044
9106
  /**
@@ -17519,6 +17581,10 @@ interface FindTableRowsRequestBody {
17519
17581
  * Search term to apply to the row search. When using this parameter, some rows which doesn't match the search term will be returned, use the similarity field to know how much the row matches the search term.
17520
17582
  */
17521
17583
  search?: string;
17584
+ /**
17585
+ * Specify which columns to return in the response. Supports both top-level columns (e.g., "name") and nested attributes using dot notation (e.g., "attributes.price"). System columns (id, createdAt, updatedAt, etc.) are always included. If omitted, all columns are returned.
17586
+ */
17587
+ select?: string[];
17522
17588
  /**
17523
17589
  * Specifies the column by which to order the results. By default it is ordered by id. Build-in columns: id, createdAt, updatedAt
17524
17590
  */
@@ -19149,6 +19215,20 @@ type Model = {
19149
19215
  lifecycle: 'production' | 'preview' | 'deprecated' | 'discontinued';
19150
19216
  };
19151
19217
 
19218
+ type BetaEvents = {
19219
+ request: (req: {
19220
+ input: CognitiveRequest;
19221
+ }) => void;
19222
+ response: (req: {
19223
+ input: CognitiveRequest;
19224
+ }, res: CognitiveResponse) => void;
19225
+ error: (req: {
19226
+ input: CognitiveRequest;
19227
+ }, error: any) => void;
19228
+ retry: (req: {
19229
+ input: CognitiveRequest;
19230
+ }, error: any) => void;
19231
+ };
19152
19232
  type ClientProps = {
19153
19233
  apiUrl?: string;
19154
19234
  timeout?: number;
@@ -19170,8 +19250,10 @@ declare class CognitiveBeta {
19170
19250
  private readonly _withCredentials;
19171
19251
  private readonly _headers;
19172
19252
  private readonly _debug;
19253
+ private _events;
19173
19254
  constructor(props: ClientProps);
19174
19255
  clone(): CognitiveBeta;
19256
+ on<K extends keyof BetaEvents>(event: K, cb: BetaEvents[K]): Unsubscribe;
19175
19257
  generateText(input: CognitiveRequest, options?: RequestOptions): Promise<CognitiveResponse>;
19176
19258
  listModels(): Promise<Model[]>;
19177
19259
  generateTextStream(request: CognitiveRequest, options?: RequestOptions): AsyncGenerator<CognitiveStreamChunk, void, unknown>;
@@ -19181,4 +19263,4 @@ declare class CognitiveBeta {
19181
19263
  }
19182
19264
  declare const getCognitiveV2Model: (model: string) => Model | undefined;
19183
19265
 
19184
- export { type BotpressClientLike, Cognitive, CognitiveBeta, type CognitiveRequest, type CognitiveResponse, type CognitiveStreamChunk, type Events, type GenerateContentInput, type GenerateContentOutput, type Model$1 as Model, type ModelPreferences, ModelProvider, type Models, RemoteModelProvider, getCognitiveV2Model };
19266
+ export { type BetaEvents, type BotpressClientLike, Cognitive, CognitiveBeta, type CognitiveRequest, type CognitiveResponse, type CognitiveStreamChunk, type Events, type GenerateContentInput, type GenerateContentOutput, type Model$1 as Model, type ModelPreferences, ModelProvider, type Models, RemoteModelProvider, getCognitiveV2Model };
package/dist/index.mjs CHANGED
@@ -1747,6 +1747,7 @@ var CognitiveBeta = class _CognitiveBeta {
1747
1747
  _withCredentials;
1748
1748
  _headers;
1749
1749
  _debug = false;
1750
+ _events = createNanoEvents();
1750
1751
  constructor(props) {
1751
1752
  this._apiUrl = props.apiUrl || "https://api.botpress.cloud";
1752
1753
  this._timeout = props.timeout || 60001;
@@ -1777,15 +1778,28 @@ var CognitiveBeta = class _CognitiveBeta {
1777
1778
  debug: this._debug
1778
1779
  });
1779
1780
  }
1781
+ on(event, cb) {
1782
+ return this._events.on(event, cb);
1783
+ }
1780
1784
  async generateText(input, options = {}) {
1781
1785
  const signal = options.signal ?? AbortSignal.timeout(this._timeout);
1782
- const { data } = await this._withServerRetry(
1783
- () => this._axiosClient.post("/v2/cognitive/generate-text", input, {
1784
- signal,
1785
- timeout: options.timeout ?? this._timeout
1786
- })
1787
- );
1788
- return data;
1786
+ const req = { input };
1787
+ this._events.emit("request", req);
1788
+ try {
1789
+ const { data } = await this._withServerRetry(
1790
+ () => this._axiosClient.post("/v2/cognitive/generate-text", input, {
1791
+ signal,
1792
+ timeout: options.timeout ?? this._timeout
1793
+ }),
1794
+ options,
1795
+ req
1796
+ );
1797
+ this._events.emit("response", req, data);
1798
+ return data;
1799
+ } catch (error) {
1800
+ this._events.emit("error", req, error);
1801
+ throw error;
1802
+ }
1789
1803
  }
1790
1804
  async listModels() {
1791
1805
  const { data } = await this._withServerRetry(
@@ -1795,61 +1809,88 @@ var CognitiveBeta = class _CognitiveBeta {
1795
1809
  }
1796
1810
  async *generateTextStream(request, options = {}) {
1797
1811
  const signal = options.signal ?? AbortSignal.timeout(this._timeout);
1798
- if (isBrowser()) {
1799
- const res2 = await fetch(`${this._apiUrl}/v2/cognitive/generate-text-stream`, {
1800
- method: "POST",
1801
- headers: {
1802
- ...this._headers,
1803
- "Content-Type": "application/json"
1804
- },
1805
- credentials: this._withCredentials ? "include" : "omit",
1806
- body: JSON.stringify({ ...request, stream: true }),
1807
- signal
1808
- });
1809
- if (!res2.ok) {
1810
- const text = await res2.text().catch(() => "");
1811
- const err = new Error(`HTTP ${res2.status}: ${text || res2.statusText}`);
1812
- err.response = { status: res2.status, data: text };
1813
- throw err;
1812
+ const req = { input: request };
1813
+ const chunks = [];
1814
+ let lastChunk;
1815
+ this._events.emit("request", req);
1816
+ try {
1817
+ if (isBrowser()) {
1818
+ const res2 = await fetch(`${this._apiUrl}/v2/cognitive/generate-text-stream`, {
1819
+ method: "POST",
1820
+ headers: {
1821
+ ...this._headers,
1822
+ "Content-Type": "application/json"
1823
+ },
1824
+ credentials: this._withCredentials ? "include" : "omit",
1825
+ body: JSON.stringify({ ...request, stream: true }),
1826
+ signal
1827
+ });
1828
+ if (!res2.ok) {
1829
+ const text = await res2.text().catch(() => "");
1830
+ const err = new Error(`HTTP ${res2.status}: ${text || res2.statusText}`);
1831
+ err.response = { status: res2.status, data: text };
1832
+ throw err;
1833
+ }
1834
+ const body = res2.body;
1835
+ if (!body) {
1836
+ throw new Error("No response body received for streaming request");
1837
+ }
1838
+ const reader = body.getReader();
1839
+ const iterable = (async function* () {
1840
+ for (; ; ) {
1841
+ const { value, done } = await reader.read();
1842
+ if (done) {
1843
+ break;
1844
+ }
1845
+ if (value) {
1846
+ yield value;
1847
+ }
1848
+ }
1849
+ })();
1850
+ for await (const obj of this._ndjson(iterable)) {
1851
+ chunks.push(obj);
1852
+ lastChunk = obj;
1853
+ yield obj;
1854
+ }
1855
+ if (lastChunk?.metadata) {
1856
+ this._events.emit("response", req, {
1857
+ output: chunks.map((c) => c.output || "").join(""),
1858
+ metadata: lastChunk.metadata
1859
+ });
1860
+ }
1861
+ return;
1814
1862
  }
1815
- const body = res2.body;
1816
- if (!body) {
1863
+ const res = await this._withServerRetry(
1864
+ () => this._axiosClient.post(
1865
+ "/v2/cognitive/generate-text-stream",
1866
+ { ...request, stream: true },
1867
+ {
1868
+ responseType: "stream",
1869
+ signal,
1870
+ timeout: options.timeout ?? this._timeout
1871
+ }
1872
+ ),
1873
+ options,
1874
+ req
1875
+ );
1876
+ const nodeStream = res.data;
1877
+ if (!nodeStream) {
1817
1878
  throw new Error("No response body received for streaming request");
1818
1879
  }
1819
- const reader = body.getReader();
1820
- const iterable = (async function* () {
1821
- for (; ; ) {
1822
- const { value, done } = await reader.read();
1823
- if (done) {
1824
- break;
1825
- }
1826
- if (value) {
1827
- yield value;
1828
- }
1829
- }
1830
- })();
1831
- for await (const obj of this._ndjson(iterable)) {
1880
+ for await (const obj of this._ndjson(nodeStream)) {
1881
+ chunks.push(obj);
1882
+ lastChunk = obj;
1832
1883
  yield obj;
1833
1884
  }
1834
- return;
1835
- }
1836
- const res = await this._withServerRetry(
1837
- () => this._axiosClient.post(
1838
- "/v2/cognitive/generate-text-stream",
1839
- { ...request, stream: true },
1840
- {
1841
- responseType: "stream",
1842
- signal,
1843
- timeout: options.timeout ?? this._timeout
1844
- }
1845
- )
1846
- );
1847
- const nodeStream = res.data;
1848
- if (!nodeStream) {
1849
- throw new Error("No response body received for streaming request");
1850
- }
1851
- for await (const obj of this._ndjson(nodeStream)) {
1852
- yield obj;
1885
+ if (lastChunk?.metadata) {
1886
+ this._events.emit("response", req, {
1887
+ output: chunks.map((c) => c.output || "").join(""),
1888
+ metadata: lastChunk.metadata
1889
+ });
1890
+ }
1891
+ } catch (error) {
1892
+ this._events.emit("error", req, error);
1893
+ throw error;
1853
1894
  }
1854
1895
  }
1855
1896
  async *_ndjson(stream) {
@@ -1891,14 +1932,30 @@ var CognitiveBeta = class _CognitiveBeta {
1891
1932
  }
1892
1933
  return false;
1893
1934
  }
1894
- async _withServerRetry(fn) {
1895
- return (0, import_exponential_backoff.backOff)(fn, {
1896
- numOfAttempts: 3,
1897
- startingDelay: 300,
1898
- timeMultiple: 2,
1899
- jitter: "full",
1900
- retry: (e) => this._isRetryableServerError(e)
1901
- });
1935
+ async _withServerRetry(fn, options = {}, req) {
1936
+ let attemptCount = 0;
1937
+ return (0, import_exponential_backoff.backOff)(
1938
+ async () => {
1939
+ try {
1940
+ const result = await fn();
1941
+ attemptCount = 0;
1942
+ return result;
1943
+ } catch (error) {
1944
+ if (attemptCount > 0 && req) {
1945
+ this._events.emit("retry", req, error);
1946
+ }
1947
+ attemptCount++;
1948
+ throw error;
1949
+ }
1950
+ },
1951
+ {
1952
+ numOfAttempts: 3,
1953
+ startingDelay: 300,
1954
+ timeMultiple: 2,
1955
+ jitter: "full",
1956
+ retry: (e) => !options.signal?.aborted && this._isRetryableServerError(e)
1957
+ }
1958
+ );
1902
1959
  }
1903
1960
  };
1904
1961
  var getCognitiveV2Model = (model) => {
@@ -2281,8 +2338,21 @@ var Cognitive = class _Cognitive {
2281
2338
  delete input.systemPrompt;
2282
2339
  }
2283
2340
  const betaClient = new CognitiveBeta(this._client.config);
2284
- const response = await betaClient.generateText(input);
2285
- return {
2341
+ const props = { input };
2342
+ betaClient.on("request", () => {
2343
+ this._events.emit("request", props);
2344
+ });
2345
+ betaClient.on("error", (_req, error) => {
2346
+ this._events.emit("error", props, error);
2347
+ });
2348
+ betaClient.on("retry", (_req, error) => {
2349
+ this._events.emit("retry", props, error);
2350
+ });
2351
+ const response = await betaClient.generateText(input, {
2352
+ signal: input.signal,
2353
+ timeout: this._timeoutMs
2354
+ });
2355
+ const result = {
2286
2356
  output: {
2287
2357
  id: "beta-output",
2288
2358
  provider: response.metadata.provider,
@@ -2320,6 +2390,8 @@ var Cognitive = class _Cognitive {
2320
2390
  }
2321
2391
  }
2322
2392
  };
2393
+ this._events.emit("response", props, result);
2394
+ return result;
2323
2395
  }
2324
2396
  async _generateContent(input) {
2325
2397
  const start = Date.now();