@slates/test 1.0.0-rc.3 → 1.0.0-rc.5

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.
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/config.ts
21
+ var config_exports = {};
22
+ __export(config_exports, {
23
+ createSlatesVitestConfig: () => createSlatesVitestConfig
24
+ });
25
+ module.exports = __toCommonJS(config_exports);
26
+ var import_testing_tools = require("@lowerdeck/testing-tools");
27
+ var createSlatesVitestConfig = (config = {}) => (0, import_testing_tools.createVitestConfig)(config);
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ createSlatesVitestConfig
31
+ });
@@ -0,0 +1,6 @@
1
+ import * as vite from 'vite';
2
+ import { createVitestConfig } from '@lowerdeck/testing-tools';
3
+
4
+ declare let createSlatesVitestConfig: (config?: Parameters<typeof createVitestConfig>[0]) => vite.UserConfig;
5
+
6
+ export { createSlatesVitestConfig };
@@ -0,0 +1,6 @@
1
+ import * as vite from 'vite';
2
+ import { createVitestConfig } from '@lowerdeck/testing-tools';
3
+
4
+ declare let createSlatesVitestConfig: (config?: Parameters<typeof createVitestConfig>[0]) => vite.UserConfig;
5
+
6
+ export { createSlatesVitestConfig };
@@ -0,0 +1,6 @@
1
+ // src/config.ts
2
+ import { createVitestConfig } from "@lowerdeck/testing-tools";
3
+ var createSlatesVitestConfig = (config = {}) => createVitestConfig(config);
4
+ export {
5
+ createSlatesVitestConfig
6
+ };
package/dist/index.cjs CHANGED
@@ -22,25 +22,45 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  createLocalSlateTestClient: () => createLocalSlateTestClient,
24
24
  createSlatesTestClient: () => createSlatesTestClient,
25
- createSlatesVitestConfig: () => createSlatesVitestConfig,
26
25
  expectSlateContract: () => expectSlateContract,
27
26
  expectSlateError: () => expectSlateError,
28
27
  expectToolCall: () => expectToolCall,
29
28
  getSlateContract: () => getSlateContract,
29
+ getVitestExpect: () => getVitestExpect,
30
30
  handleSlateTriggerWebhook: () => handleSlateTriggerWebhook,
31
31
  loadSlatesProfile: () => loadSlatesProfile,
32
32
  loadSlatesRuntimeContext: () => loadSlatesRuntimeContext,
33
33
  mapSlateTriggerEvent: () => mapSlateTriggerEvent,
34
+ pollSlateTriggerEvents: () => pollSlateTriggerEvents,
34
35
  registerSlateTriggerWebhook: () => registerSlateTriggerWebhook,
35
36
  unregisterSlateTriggerWebhook: () => unregisterSlateTriggerWebhook,
36
37
  withSlateProfile: () => withSlateProfile
37
38
  });
38
39
  module.exports = __toCommonJS(index_exports);
39
- var import_testing_tools = require("@lowerdeck/testing-tools");
40
+
41
+ // src/runtime.ts
40
42
  var import_client = require("@slates/client");
41
43
  var import_profiles = require("@slates/profiles");
42
44
  var import_promises = require("fs/promises");
43
- var getExpect = () => {
45
+ var selectProfileAuth = (profile, authMethodId) => {
46
+ if (!profile || !authMethodId) {
47
+ return profile;
48
+ }
49
+ let selectedAuth = profile.auth[authMethodId];
50
+ if (!selectedAuth) {
51
+ let availableAuthMethods = Object.keys(profile.auth);
52
+ throw new Error(
53
+ `No stored authentication found for auth method "${authMethodId}" in profile "${profile.name}".` + (availableAuthMethods.length > 0 ? ` Available auth methods: ${availableAuthMethods.join(", ")}.` : " No auth methods are stored for this profile.")
54
+ );
55
+ }
56
+ return {
57
+ ...profile,
58
+ auth: {
59
+ [selectedAuth.authMethodId]: selectedAuth
60
+ }
61
+ };
62
+ };
63
+ var getVitestExpect = () => {
44
64
  let maybeExpect = globalThis.expect;
45
65
  if (!maybeExpect) {
46
66
  throw new Error("Vitest expect is not available in the current runtime.");
@@ -52,23 +72,38 @@ var loadSlatesRuntimeContext = async (opts = {}) => {
52
72
  if (runtimeContextPath) {
53
73
  let raw = await (0, import_promises.readFile)(runtimeContextPath, "utf-8");
54
74
  let parsed = JSON.parse(raw);
55
- let store2 = await (0, import_profiles.openSlatesCliStore)({ storePath: parsed.storePath });
56
- let profile2 = store2.getProfile(opts.profile ?? parsed.profileId ?? null);
75
+ let store2 = await (0, import_profiles.openSlatesCliStore)({
76
+ storePath: parsed.storePath,
77
+ rootDir: parsed.rootDir ?? process.env.SLATES_STORE_ROOT_DIR
78
+ });
79
+ let authMethodId2 = parsed.authMethodId ?? null;
80
+ let profile2 = selectProfileAuth(
81
+ store2.getProfile(opts.profile ?? parsed.profileId ?? null),
82
+ authMethodId2
83
+ );
57
84
  return {
58
85
  integration: parsed.integration ?? store2.scope?.key ?? null,
59
86
  profileId: profile2?.id ?? parsed.profileId ?? null,
87
+ authMethodId: authMethodId2,
60
88
  profile: profile2,
89
+ rootDir: parsed.rootDir ?? store2.rootDir,
61
90
  storePath: parsed.storePath,
62
91
  cliDir: parsed.cliDir
63
92
  };
64
93
  }
65
- let store = process.env.SLATES_STORE_PATH ? await (0, import_profiles.openSlatesCliStore)({ storePath: process.env.SLATES_STORE_PATH }) : await (0, import_profiles.openSlatesCliStore)({ cwd: opts.cwd });
94
+ let store = process.env.SLATES_STORE_PATH ? await (0, import_profiles.openSlatesCliStore)({
95
+ storePath: process.env.SLATES_STORE_PATH,
96
+ rootDir: process.env.SLATES_STORE_ROOT_DIR
97
+ }) : await (0, import_profiles.openSlatesCliStore)({ cwd: opts.cwd });
66
98
  let profileId = opts.profile ?? process.env.SLATES_PROFILE_ID ?? null;
67
- let profile = store.getProfile(profileId);
99
+ let authMethodId = null;
100
+ let profile = selectProfileAuth(store.getProfile(profileId), authMethodId);
68
101
  return {
69
102
  integration: process.env.SLATES_INTEGRATION ?? store.scope?.key ?? null,
70
103
  profileId: profile?.id ?? null,
104
+ authMethodId,
71
105
  profile,
106
+ rootDir: store.rootDir,
72
107
  storePath: store.storePath,
73
108
  cliDir: store.dirPath
74
109
  };
@@ -85,7 +120,10 @@ var createSlatesTestClient = async (opts = {}) => {
85
120
  if (!context.profile) {
86
121
  throw new Error("No Slates profile is available for the current test context.");
87
122
  }
88
- let store = await (0, import_profiles.openSlatesCliStore)({ storePath: context.storePath });
123
+ let store = await (0, import_profiles.openSlatesCliStore)({
124
+ storePath: context.storePath,
125
+ rootDir: context.rootDir
126
+ });
89
127
  return (0, import_profiles.createSlatesClientFromProfile)(context.profile, { cwd: opts.cwd, store });
90
128
  };
91
129
  var withSlateProfile = async (profileName, cb) => {
@@ -93,7 +131,7 @@ var withSlateProfile = async (profileName, cb) => {
93
131
  return cb({ profile });
94
132
  };
95
133
  var expectToolCall = async (d) => {
96
- let expect = getExpect();
134
+ let expect = getVitestExpect();
97
135
  let client = d.client ?? await createSlatesTestClient({ profile: d.profile });
98
136
  let result = await client.invokeTool(d.toolId, d.input);
99
137
  if (d.output) {
@@ -123,7 +161,7 @@ var getSlateContract = async (client) => {
123
161
  };
124
162
  };
125
163
  var expectActionMatches = (actual, expected) => {
126
- let expect = getExpect();
164
+ let expect = getVitestExpect();
127
165
  expect(actual).toBeTruthy();
128
166
  expect(actual?.id).toBe(expected.id);
129
167
  if (expected.name !== void 0) {
@@ -145,7 +183,7 @@ var expectActionMatches = (actual, expected) => {
145
183
  }
146
184
  };
147
185
  var expectSlateContract = async (d) => {
148
- let expect = getExpect();
186
+ let expect = getVitestExpect();
149
187
  let contract = await getSlateContract(d.client);
150
188
  if (d.provider) {
151
189
  expect(contract.provider.id).toBe(d.provider.id);
@@ -166,14 +204,27 @@ var expectSlateContract = async (d) => {
166
204
  expect(contract.authMethods.map((method) => method.id)).toEqual(d.authMethodIds);
167
205
  }
168
206
  for (let tool of d.tools ?? []) {
169
- expectActionMatches(contract.tools.find((action) => action.id === tool.id), tool);
207
+ expectActionMatches(
208
+ contract.tools.find((action) => action.id === tool.id),
209
+ tool
210
+ );
170
211
  }
171
212
  for (let trigger of d.triggers ?? []) {
172
- expectActionMatches(contract.triggers.find((action) => action.id === trigger.id), trigger);
213
+ expectActionMatches(
214
+ contract.triggers.find((action) => action.id === trigger.id),
215
+ trigger
216
+ );
173
217
  }
174
218
  return contract;
175
219
  };
176
220
  var registerSlateTriggerWebhook = async (d) => d.client.registerTriggerWebhook(d.triggerId, d.webhookBaseUrl);
221
+ var pollSlateTriggerEvents = async (d) => {
222
+ d.client.ensureSession();
223
+ return d.client.request("slates/action.trigger.poll_events", {
224
+ actionId: d.triggerId,
225
+ state: d.state ?? null
226
+ });
227
+ };
177
228
  var handleSlateTriggerWebhook = async (d) => d.client.handleTriggerWebhook({
178
229
  actionId: d.triggerId,
179
230
  url: d.url,
@@ -189,7 +240,7 @@ var unregisterSlateTriggerWebhook = async (d) => d.client.unregisterTriggerWebho
189
240
  state: d.state
190
241
  });
191
242
  var mapSlateTriggerEvent = async (d) => {
192
- let expect = getExpect();
243
+ let expect = getVitestExpect();
193
244
  let result = await d.client.mapTriggerEvent(d.triggerId, d.input);
194
245
  if (d.type !== void 0) {
195
246
  expect(result.type).toBe(d.type);
@@ -200,7 +251,7 @@ var mapSlateTriggerEvent = async (d) => {
200
251
  return result;
201
252
  };
202
253
  var expectSlateError = async (run, expected) => {
203
- let expect = getExpect();
254
+ let expect = getVitestExpect();
204
255
  try {
205
256
  await (typeof run === "function" ? run() : run);
206
257
  } catch (error) {
@@ -220,20 +271,20 @@ var expectSlateError = async (run, expected) => {
220
271
  }
221
272
  throw new Error("Expected the operation to fail, but it completed successfully.");
222
273
  };
223
- var createSlatesVitestConfig = (config = {}) => (0, import_testing_tools.createVitestConfig)(config);
224
274
  // Annotate the CommonJS export names for ESM import in node:
225
275
  0 && (module.exports = {
226
276
  createLocalSlateTestClient,
227
277
  createSlatesTestClient,
228
- createSlatesVitestConfig,
229
278
  expectSlateContract,
230
279
  expectSlateError,
231
280
  expectToolCall,
232
281
  getSlateContract,
282
+ getVitestExpect,
233
283
  handleSlateTriggerWebhook,
234
284
  loadSlatesProfile,
235
285
  loadSlatesRuntimeContext,
236
286
  mapSlateTriggerEvent,
287
+ pollSlateTriggerEvents,
237
288
  registerSlateTriggerWebhook,
238
289
  unregisterSlateTriggerWebhook,
239
290
  withSlateProfile
package/dist/index.d.cts CHANGED
@@ -1,13 +1,14 @@
1
- import * as vite from 'vite';
2
1
  import * as _slates_client from '@slates/client';
3
2
  import { createSlatesClient, createLocalSlateTransport, SlatesProtocolClientOptions } from '@slates/client';
4
- import { createVitestConfig } from '@lowerdeck/testing-tools';
3
+ import * as vitest from 'vitest';
5
4
  import { SlatesProfileRecord } from '@slates/profiles';
6
5
 
7
6
  interface SlatesRuntimeContext {
8
7
  integration: string | null;
9
8
  profileId: string | null;
9
+ authMethodId: string | null;
10
10
  profile: SlatesProfileRecord | null;
11
+ rootDir: string;
11
12
  storePath: string;
12
13
  cliDir: string;
13
14
  }
@@ -21,6 +22,7 @@ interface ExpectedSlateAction {
21
22
  destructive?: boolean;
22
23
  invocationType?: 'polling' | 'webhook';
23
24
  }
25
+ declare let getVitestExpect: () => vitest.ExpectStatic;
24
26
  declare let loadSlatesRuntimeContext: (opts?: {
25
27
  cwd?: string;
26
28
  profile?: string | null;
@@ -51,7 +53,7 @@ declare let expectToolCall: (d: {
51
53
  url: string;
52
54
  } | {
53
55
  type: "content";
54
- encoding: "base64" | "utf-8";
56
+ encoding: "utf-8" | "base64";
55
57
  content: string;
56
58
  };
57
59
  mimeType?: string | undefined;
@@ -221,6 +223,7 @@ declare let getSlateContract: (client: SlatesTestClient) => Promise<{
221
223
  id: string;
222
224
  title: string;
223
225
  description?: string | undefined;
226
+ defaultChecked?: boolean | undefined;
224
227
  }[] | undefined;
225
228
  }[];
226
229
  configSchema: Record<string, any>;
@@ -368,6 +371,7 @@ declare let expectSlateContract: (d: {
368
371
  id: string;
369
372
  title: string;
370
373
  description?: string | undefined;
374
+ defaultChecked?: boolean | undefined;
371
375
  }[] | undefined;
372
376
  }[];
373
377
  configSchema: Record<string, any>;
@@ -408,6 +412,42 @@ declare let registerSlateTriggerWebhook: (d: {
408
412
  } | undefined;
409
413
  }[] | undefined;
410
414
  }>;
415
+ declare let pollSlateTriggerEvents: (d: {
416
+ client: SlatesTestClient;
417
+ triggerId: string;
418
+ state?: any;
419
+ }) => Promise<{
420
+ inputs: Record<string, any>[];
421
+ updatedState?: any;
422
+ requestTraces?: {
423
+ startedAt: string;
424
+ durationMs: number;
425
+ request: {
426
+ method: string;
427
+ url: string;
428
+ headers?: Record<string, string> | undefined;
429
+ body?: {
430
+ text: string;
431
+ contentType?: string | undefined;
432
+ truncated?: boolean | undefined;
433
+ } | undefined;
434
+ };
435
+ response?: {
436
+ status: number;
437
+ statusText?: string | undefined;
438
+ headers?: Record<string, string> | undefined;
439
+ body?: {
440
+ text: string;
441
+ contentType?: string | undefined;
442
+ truncated?: boolean | undefined;
443
+ } | undefined;
444
+ } | undefined;
445
+ error?: {
446
+ message: string;
447
+ code?: string | undefined;
448
+ } | undefined;
449
+ }[] | undefined;
450
+ }>;
411
451
  declare let handleSlateTriggerWebhook: (d: {
412
452
  client: SlatesTestClient;
413
453
  triggerId: string;
@@ -524,6 +564,5 @@ declare let mapSlateTriggerEvent: (d: {
524
564
  }[] | undefined;
525
565
  }>;
526
566
  declare let expectSlateError: (run: Promise<unknown> | (() => Promise<unknown>), expected: Record<string, any> | string | RegExp) => Promise<unknown>;
527
- declare let createSlatesVitestConfig: (config?: Parameters<typeof createVitestConfig>[0]) => vite.UserConfig;
528
567
 
529
- export { type ExpectedSlateAction, type SlatesRuntimeContext, type SlatesTestClient, createLocalSlateTestClient, createSlatesTestClient, createSlatesVitestConfig, expectSlateContract, expectSlateError, expectToolCall, getSlateContract, handleSlateTriggerWebhook, loadSlatesProfile, loadSlatesRuntimeContext, mapSlateTriggerEvent, registerSlateTriggerWebhook, unregisterSlateTriggerWebhook, withSlateProfile };
568
+ export { type ExpectedSlateAction, type SlatesRuntimeContext, type SlatesTestClient, createLocalSlateTestClient, createSlatesTestClient, expectSlateContract, expectSlateError, expectToolCall, getSlateContract, getVitestExpect, handleSlateTriggerWebhook, loadSlatesProfile, loadSlatesRuntimeContext, mapSlateTriggerEvent, pollSlateTriggerEvents, registerSlateTriggerWebhook, unregisterSlateTriggerWebhook, withSlateProfile };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- import * as vite from 'vite';
2
1
  import * as _slates_client from '@slates/client';
3
2
  import { createSlatesClient, createLocalSlateTransport, SlatesProtocolClientOptions } from '@slates/client';
4
- import { createVitestConfig } from '@lowerdeck/testing-tools';
3
+ import * as vitest from 'vitest';
5
4
  import { SlatesProfileRecord } from '@slates/profiles';
6
5
 
7
6
  interface SlatesRuntimeContext {
8
7
  integration: string | null;
9
8
  profileId: string | null;
9
+ authMethodId: string | null;
10
10
  profile: SlatesProfileRecord | null;
11
+ rootDir: string;
11
12
  storePath: string;
12
13
  cliDir: string;
13
14
  }
@@ -21,6 +22,7 @@ interface ExpectedSlateAction {
21
22
  destructive?: boolean;
22
23
  invocationType?: 'polling' | 'webhook';
23
24
  }
25
+ declare let getVitestExpect: () => vitest.ExpectStatic;
24
26
  declare let loadSlatesRuntimeContext: (opts?: {
25
27
  cwd?: string;
26
28
  profile?: string | null;
@@ -51,7 +53,7 @@ declare let expectToolCall: (d: {
51
53
  url: string;
52
54
  } | {
53
55
  type: "content";
54
- encoding: "base64" | "utf-8";
56
+ encoding: "utf-8" | "base64";
55
57
  content: string;
56
58
  };
57
59
  mimeType?: string | undefined;
@@ -221,6 +223,7 @@ declare let getSlateContract: (client: SlatesTestClient) => Promise<{
221
223
  id: string;
222
224
  title: string;
223
225
  description?: string | undefined;
226
+ defaultChecked?: boolean | undefined;
224
227
  }[] | undefined;
225
228
  }[];
226
229
  configSchema: Record<string, any>;
@@ -368,6 +371,7 @@ declare let expectSlateContract: (d: {
368
371
  id: string;
369
372
  title: string;
370
373
  description?: string | undefined;
374
+ defaultChecked?: boolean | undefined;
371
375
  }[] | undefined;
372
376
  }[];
373
377
  configSchema: Record<string, any>;
@@ -408,6 +412,42 @@ declare let registerSlateTriggerWebhook: (d: {
408
412
  } | undefined;
409
413
  }[] | undefined;
410
414
  }>;
415
+ declare let pollSlateTriggerEvents: (d: {
416
+ client: SlatesTestClient;
417
+ triggerId: string;
418
+ state?: any;
419
+ }) => Promise<{
420
+ inputs: Record<string, any>[];
421
+ updatedState?: any;
422
+ requestTraces?: {
423
+ startedAt: string;
424
+ durationMs: number;
425
+ request: {
426
+ method: string;
427
+ url: string;
428
+ headers?: Record<string, string> | undefined;
429
+ body?: {
430
+ text: string;
431
+ contentType?: string | undefined;
432
+ truncated?: boolean | undefined;
433
+ } | undefined;
434
+ };
435
+ response?: {
436
+ status: number;
437
+ statusText?: string | undefined;
438
+ headers?: Record<string, string> | undefined;
439
+ body?: {
440
+ text: string;
441
+ contentType?: string | undefined;
442
+ truncated?: boolean | undefined;
443
+ } | undefined;
444
+ } | undefined;
445
+ error?: {
446
+ message: string;
447
+ code?: string | undefined;
448
+ } | undefined;
449
+ }[] | undefined;
450
+ }>;
411
451
  declare let handleSlateTriggerWebhook: (d: {
412
452
  client: SlatesTestClient;
413
453
  triggerId: string;
@@ -524,6 +564,5 @@ declare let mapSlateTriggerEvent: (d: {
524
564
  }[] | undefined;
525
565
  }>;
526
566
  declare let expectSlateError: (run: Promise<unknown> | (() => Promise<unknown>), expected: Record<string, any> | string | RegExp) => Promise<unknown>;
527
- declare let createSlatesVitestConfig: (config?: Parameters<typeof createVitestConfig>[0]) => vite.UserConfig;
528
567
 
529
- export { type ExpectedSlateAction, type SlatesRuntimeContext, type SlatesTestClient, createLocalSlateTestClient, createSlatesTestClient, createSlatesVitestConfig, expectSlateContract, expectSlateError, expectToolCall, getSlateContract, handleSlateTriggerWebhook, loadSlatesProfile, loadSlatesRuntimeContext, mapSlateTriggerEvent, registerSlateTriggerWebhook, unregisterSlateTriggerWebhook, withSlateProfile };
568
+ export { type ExpectedSlateAction, type SlatesRuntimeContext, type SlatesTestClient, createLocalSlateTestClient, createSlatesTestClient, expectSlateContract, expectSlateError, expectToolCall, getSlateContract, getVitestExpect, handleSlateTriggerWebhook, loadSlatesProfile, loadSlatesRuntimeContext, mapSlateTriggerEvent, pollSlateTriggerEvents, registerSlateTriggerWebhook, unregisterSlateTriggerWebhook, withSlateProfile };
@@ -1,5 +1,4 @@
1
- // src/index.ts
2
- import { createVitestConfig } from "@lowerdeck/testing-tools";
1
+ // src/runtime.ts
3
2
  import {
4
3
  createLocalSlateTransport,
5
4
  createSlatesClient,
@@ -10,7 +9,25 @@ import {
10
9
  openSlatesCliStore
11
10
  } from "@slates/profiles";
12
11
  import { readFile } from "fs/promises";
13
- var getExpect = () => {
12
+ var selectProfileAuth = (profile, authMethodId) => {
13
+ if (!profile || !authMethodId) {
14
+ return profile;
15
+ }
16
+ let selectedAuth = profile.auth[authMethodId];
17
+ if (!selectedAuth) {
18
+ let availableAuthMethods = Object.keys(profile.auth);
19
+ throw new Error(
20
+ `No stored authentication found for auth method "${authMethodId}" in profile "${profile.name}".` + (availableAuthMethods.length > 0 ? ` Available auth methods: ${availableAuthMethods.join(", ")}.` : " No auth methods are stored for this profile.")
21
+ );
22
+ }
23
+ return {
24
+ ...profile,
25
+ auth: {
26
+ [selectedAuth.authMethodId]: selectedAuth
27
+ }
28
+ };
29
+ };
30
+ var getVitestExpect = () => {
14
31
  let maybeExpect = globalThis.expect;
15
32
  if (!maybeExpect) {
16
33
  throw new Error("Vitest expect is not available in the current runtime.");
@@ -22,23 +39,38 @@ var loadSlatesRuntimeContext = async (opts = {}) => {
22
39
  if (runtimeContextPath) {
23
40
  let raw = await readFile(runtimeContextPath, "utf-8");
24
41
  let parsed = JSON.parse(raw);
25
- let store2 = await openSlatesCliStore({ storePath: parsed.storePath });
26
- let profile2 = store2.getProfile(opts.profile ?? parsed.profileId ?? null);
42
+ let store2 = await openSlatesCliStore({
43
+ storePath: parsed.storePath,
44
+ rootDir: parsed.rootDir ?? process.env.SLATES_STORE_ROOT_DIR
45
+ });
46
+ let authMethodId2 = parsed.authMethodId ?? null;
47
+ let profile2 = selectProfileAuth(
48
+ store2.getProfile(opts.profile ?? parsed.profileId ?? null),
49
+ authMethodId2
50
+ );
27
51
  return {
28
52
  integration: parsed.integration ?? store2.scope?.key ?? null,
29
53
  profileId: profile2?.id ?? parsed.profileId ?? null,
54
+ authMethodId: authMethodId2,
30
55
  profile: profile2,
56
+ rootDir: parsed.rootDir ?? store2.rootDir,
31
57
  storePath: parsed.storePath,
32
58
  cliDir: parsed.cliDir
33
59
  };
34
60
  }
35
- let store = process.env.SLATES_STORE_PATH ? await openSlatesCliStore({ storePath: process.env.SLATES_STORE_PATH }) : await openSlatesCliStore({ cwd: opts.cwd });
61
+ let store = process.env.SLATES_STORE_PATH ? await openSlatesCliStore({
62
+ storePath: process.env.SLATES_STORE_PATH,
63
+ rootDir: process.env.SLATES_STORE_ROOT_DIR
64
+ }) : await openSlatesCliStore({ cwd: opts.cwd });
36
65
  let profileId = opts.profile ?? process.env.SLATES_PROFILE_ID ?? null;
37
- let profile = store.getProfile(profileId);
66
+ let authMethodId = null;
67
+ let profile = selectProfileAuth(store.getProfile(profileId), authMethodId);
38
68
  return {
39
69
  integration: process.env.SLATES_INTEGRATION ?? store.scope?.key ?? null,
40
70
  profileId: profile?.id ?? null,
71
+ authMethodId,
41
72
  profile,
73
+ rootDir: store.rootDir,
42
74
  storePath: store.storePath,
43
75
  cliDir: store.dirPath
44
76
  };
@@ -55,7 +87,10 @@ var createSlatesTestClient = async (opts = {}) => {
55
87
  if (!context.profile) {
56
88
  throw new Error("No Slates profile is available for the current test context.");
57
89
  }
58
- let store = await openSlatesCliStore({ storePath: context.storePath });
90
+ let store = await openSlatesCliStore({
91
+ storePath: context.storePath,
92
+ rootDir: context.rootDir
93
+ });
59
94
  return createSlatesClientFromProfile(context.profile, { cwd: opts.cwd, store });
60
95
  };
61
96
  var withSlateProfile = async (profileName, cb) => {
@@ -63,7 +98,7 @@ var withSlateProfile = async (profileName, cb) => {
63
98
  return cb({ profile });
64
99
  };
65
100
  var expectToolCall = async (d) => {
66
- let expect = getExpect();
101
+ let expect = getVitestExpect();
67
102
  let client = d.client ?? await createSlatesTestClient({ profile: d.profile });
68
103
  let result = await client.invokeTool(d.toolId, d.input);
69
104
  if (d.output) {
@@ -93,7 +128,7 @@ var getSlateContract = async (client) => {
93
128
  };
94
129
  };
95
130
  var expectActionMatches = (actual, expected) => {
96
- let expect = getExpect();
131
+ let expect = getVitestExpect();
97
132
  expect(actual).toBeTruthy();
98
133
  expect(actual?.id).toBe(expected.id);
99
134
  if (expected.name !== void 0) {
@@ -115,7 +150,7 @@ var expectActionMatches = (actual, expected) => {
115
150
  }
116
151
  };
117
152
  var expectSlateContract = async (d) => {
118
- let expect = getExpect();
153
+ let expect = getVitestExpect();
119
154
  let contract = await getSlateContract(d.client);
120
155
  if (d.provider) {
121
156
  expect(contract.provider.id).toBe(d.provider.id);
@@ -136,14 +171,27 @@ var expectSlateContract = async (d) => {
136
171
  expect(contract.authMethods.map((method) => method.id)).toEqual(d.authMethodIds);
137
172
  }
138
173
  for (let tool of d.tools ?? []) {
139
- expectActionMatches(contract.tools.find((action) => action.id === tool.id), tool);
174
+ expectActionMatches(
175
+ contract.tools.find((action) => action.id === tool.id),
176
+ tool
177
+ );
140
178
  }
141
179
  for (let trigger of d.triggers ?? []) {
142
- expectActionMatches(contract.triggers.find((action) => action.id === trigger.id), trigger);
180
+ expectActionMatches(
181
+ contract.triggers.find((action) => action.id === trigger.id),
182
+ trigger
183
+ );
143
184
  }
144
185
  return contract;
145
186
  };
146
187
  var registerSlateTriggerWebhook = async (d) => d.client.registerTriggerWebhook(d.triggerId, d.webhookBaseUrl);
188
+ var pollSlateTriggerEvents = async (d) => {
189
+ d.client.ensureSession();
190
+ return d.client.request("slates/action.trigger.poll_events", {
191
+ actionId: d.triggerId,
192
+ state: d.state ?? null
193
+ });
194
+ };
147
195
  var handleSlateTriggerWebhook = async (d) => d.client.handleTriggerWebhook({
148
196
  actionId: d.triggerId,
149
197
  url: d.url,
@@ -159,7 +207,7 @@ var unregisterSlateTriggerWebhook = async (d) => d.client.unregisterTriggerWebho
159
207
  state: d.state
160
208
  });
161
209
  var mapSlateTriggerEvent = async (d) => {
162
- let expect = getExpect();
210
+ let expect = getVitestExpect();
163
211
  let result = await d.client.mapTriggerEvent(d.triggerId, d.input);
164
212
  if (d.type !== void 0) {
165
213
  expect(result.type).toBe(d.type);
@@ -170,7 +218,7 @@ var mapSlateTriggerEvent = async (d) => {
170
218
  return result;
171
219
  };
172
220
  var expectSlateError = async (run, expected) => {
173
- let expect = getExpect();
221
+ let expect = getVitestExpect();
174
222
  try {
175
223
  await (typeof run === "function" ? run() : run);
176
224
  } catch (error) {
@@ -190,19 +238,19 @@ var expectSlateError = async (run, expected) => {
190
238
  }
191
239
  throw new Error("Expected the operation to fail, but it completed successfully.");
192
240
  };
193
- var createSlatesVitestConfig = (config = {}) => createVitestConfig(config);
194
241
  export {
195
242
  createLocalSlateTestClient,
196
243
  createSlatesTestClient,
197
- createSlatesVitestConfig,
198
244
  expectSlateContract,
199
245
  expectSlateError,
200
246
  expectToolCall,
201
247
  getSlateContract,
248
+ getVitestExpect,
202
249
  handleSlateTriggerWebhook,
203
250
  loadSlatesProfile,
204
251
  loadSlatesRuntimeContext,
205
252
  mapSlateTriggerEvent,
253
+ pollSlateTriggerEvents,
206
254
  registerSlateTriggerWebhook,
207
255
  unregisterSlateTriggerWebhook,
208
256
  withSlateProfile