@statelyai/sdk 0.18.0 → 0.20.1

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.
Files changed (33) hide show
  1. package/README.md +33 -2
  2. package/dist/auth.d.mts +1 -1
  3. package/dist/editor-sync-types-C-zWaaVk.d.mts +95 -0
  4. package/dist/editorHostProtocol-D_h4y3rX.mjs +5 -0
  5. package/dist/editorHostSession-CCTwvUOB.mjs +479 -0
  6. package/dist/editorHostSession-lL7wPLnL.d.mts +184 -0
  7. package/dist/editorHostSession.d.mts +2 -0
  8. package/dist/editorHostSession.mjs +4 -0
  9. package/dist/embed.d.mts +1 -1
  10. package/dist/embed.mjs +31 -3
  11. package/dist/{graph-DuOeLGvh.d.mts → graph-yDK-MM3G.d.mts} +6 -4
  12. package/dist/graph.d.mts +1 -1
  13. package/dist/{index-ag6K2iAS.d.mts → index-BAkQThnl.d.mts} +9 -9
  14. package/dist/index.d.mts +7 -6
  15. package/dist/index.mjs +7 -5
  16. package/dist/{inspect-BZFzyeew.d.mts → inspect-CGJR4iZK.d.mts} +13 -3
  17. package/dist/{inspect-llcqYpZ1.mjs → inspect-DWu20a8g.mjs} +58 -31
  18. package/dist/inspect.d.mts +1 -1
  19. package/dist/inspect.mjs +2 -2
  20. package/dist/patchTypes.d.mts +1 -1
  21. package/dist/protocol.d.mts +44 -50
  22. package/dist/protocol.mjs +2 -2
  23. package/dist/{studio-txdyJHD7.mjs → schemas-b9wG-zYl.mjs} +15 -396
  24. package/dist/{statelyPragma-Bm9O4XV6.mjs → statelyPragma-CIzsR_Sx.mjs} +977 -934
  25. package/dist/studio-DHGspwII.mjs +397 -0
  26. package/dist/{studio-Bk_u41gu.d.mts → studio-YSppd-am.d.mts} +2 -2
  27. package/dist/studio.d.mts +1 -1
  28. package/dist/studio.mjs +1 -1
  29. package/dist/sync.d.mts +2 -2
  30. package/dist/sync.mjs +12 -5
  31. package/dist/{transport-CyCrdKyz.mjs → version-YJizbJxR.mjs} +14 -4
  32. package/package.json +7 -3
  33. /package/dist/{auth-2Thaw42j.d.mts → auth-B0ZTKri2.d.mts} +0 -0
@@ -0,0 +1,397 @@
1
+ import { c as object, d as union, f as unknown, l as record, n as array, o as literal, r as boolean, s as number, t as _enum, u as string } from "./schemas-b9wG-zYl.mjs";
2
+ import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
3
+
4
+ //#region ../api-contract/dist/errors.mjs
5
+ /**
6
+ * Error shape returned by every `/api/v1` machine operation (and by the shared
7
+ * auth guard). Each operation registers its own error schema component in the
8
+ * OpenAPI document, so this is a factory rather than a single shared instance.
9
+ */
10
+ function createApiErrorResponseSchema() {
11
+ return object({
12
+ error: string(),
13
+ issues: array(unknown()).optional()
14
+ });
15
+ }
16
+ const apiErrorResponseSchema = createApiErrorResponseSchema();
17
+ /**
18
+ * Canonical error codes for the `/api/v1` resource operations. Machine
19
+ * operations keep the flat `{ error: string }` shape above unchanged; the
20
+ * nested envelope below applies to resource operations only.
21
+ */
22
+ const resourceErrorCodeSchema = _enum([
23
+ "bad_request",
24
+ "unauthenticated",
25
+ "forbidden",
26
+ "not_found",
27
+ "conflict",
28
+ "payload_too_large",
29
+ "rate_limited",
30
+ "capability_disabled",
31
+ "upstream_error",
32
+ "internal_error"
33
+ ]);
34
+ /** Factory, matching `createApiErrorResponseSchema`, for per-route OpenAPI components. */
35
+ function createResourceApiErrorResponseSchema() {
36
+ return object({ error: object({
37
+ code: resourceErrorCodeSchema,
38
+ message: string(),
39
+ issues: array(unknown()).optional(),
40
+ retryable: boolean().optional()
41
+ }) });
42
+ }
43
+ const resourceApiErrorResponseSchema = createResourceApiErrorResponseSchema();
44
+
45
+ //#endregion
46
+ //#region ../api-contract/dist/resources.mjs
47
+ /**
48
+ * Canonical schemas for persistent `/api/v1` resources plus the owned,
49
+ * deterministic code-extraction operation.
50
+ *
51
+ * These models are canonical, not upstream-shaped: providers (e.g. the Stately
52
+ * Registry adapter) are responsible for translating upstream envelopes,
53
+ * identifier quirks and casing into these shapes. No `{ data }` envelope
54
+ * appears anywhere; all timestamps are ISO strings.
55
+ */
56
+ /**
57
+ * XState major versions the editor targets (see
58
+ * `packages/editor/src/formats/xstate.ts`).
59
+ */
60
+ const xstateVersionSchema = union([literal(5), literal(6)]);
61
+ const projectVisibilitySchema = _enum([
62
+ "public",
63
+ "unlisted",
64
+ "private"
65
+ ]);
66
+ const verifyResultSchema = object({
67
+ valid: literal(true),
68
+ tokenScope: _enum(["user", "project"])
69
+ });
70
+ const projectSummarySchema = object({
71
+ projectId: string(),
72
+ projectVersionId: string(),
73
+ name: string(),
74
+ description: string().nullable(),
75
+ visibility: projectVisibilitySchema,
76
+ createdAt: string(),
77
+ updatedAt: string()
78
+ });
79
+ const projectSchema = projectSummarySchema.extend({
80
+ rootMachineId: string().nullable(),
81
+ machines: array(object({ machineId: string() }))
82
+ });
83
+ /**
84
+ * `name` is optional: the Registry project envelope only returns machine ids.
85
+ * Providers that can supply names cheaply should.
86
+ */
87
+ const projectMachineSummarySchema = object({
88
+ machineId: string(),
89
+ name: string().optional()
90
+ });
91
+ const machineSchema = object({
92
+ machineId: string(),
93
+ name: string(),
94
+ projectId: string().optional(),
95
+ projectVersionId: string(),
96
+ definition: unknown(),
97
+ createdAt: string().optional(),
98
+ updatedAt: string().optional()
99
+ });
100
+ const machineVersionSchema = object({
101
+ machineVersionId: string(),
102
+ machineId: string(),
103
+ versionNumber: number(),
104
+ name: string(),
105
+ definition: unknown(),
106
+ createdAt: string(),
107
+ updatedAt: string()
108
+ });
109
+ const extractedMachinesSchema = object({ machines: array(object({ config: record(string(), unknown()) })) });
110
+ const projectsCreateRequestSchema = object({
111
+ name: string().min(1),
112
+ visibility: projectVisibilitySchema
113
+ });
114
+ const projectsUpdateRequestSchema = object({
115
+ name: string().min(1).optional(),
116
+ description: string().nullable().optional(),
117
+ visibility: projectVisibilitySchema.optional()
118
+ }).refine((value) => value.name !== void 0 || value.description !== void 0 || value.visibility !== void 0, { message: "At least one of `name`, `description` or `visibility` is required." });
119
+ const machinesCreateRequestSchema = object({
120
+ projectVersionId: string().min(1),
121
+ xstateVersion: xstateVersionSchema,
122
+ name: string().min(1).optional(),
123
+ definition: unknown().optional()
124
+ });
125
+ const machinesUpdateRequestSchema = object({
126
+ name: string().min(1).optional(),
127
+ definition: unknown().optional()
128
+ }).refine((value) => value.name !== void 0 || value.definition !== void 0, { message: "At least one of `name` or `definition` is required." });
129
+ const codeExtractMachinesRequestSchema = object({
130
+ code: string().min(1),
131
+ xstateVersion: xstateVersionSchema.optional()
132
+ });
133
+ const authVerifyResponseSchema = verifyResultSchema;
134
+ const projectsListResponseSchema = array(projectSummarySchema);
135
+ const projectsGetResponseSchema = projectSchema;
136
+ const projectsCreateResponseSchema = projectSchema;
137
+ const projectsUpdateResponseSchema = projectSchema;
138
+ const projectsDeleteResponseSchema = object({ projectId: string() });
139
+ const projectsListMachinesResponseSchema = array(projectMachineSummarySchema);
140
+ const machinesCreateResponseSchema = machineSchema;
141
+ const machinesGetResponseSchema = machineSchema;
142
+ const machinesUpdateResponseSchema = machineSchema;
143
+ const machinesGetVersionResponseSchema = machineVersionSchema;
144
+ const codeExtractMachinesResponseSchema = extractedMachinesSchema;
145
+ /**
146
+ * Request/response schema pairs keyed by resource capability name. Kept here
147
+ * rather than on the `Capability` metadata entries so that the capability
148
+ * registry stays plain, serialisable data.
149
+ */
150
+ const resourceOperationSchemas = {
151
+ "auth.verify": { response: authVerifyResponseSchema },
152
+ "projects.list": { response: projectsListResponseSchema },
153
+ "projects.create": {
154
+ request: projectsCreateRequestSchema,
155
+ response: projectsCreateResponseSchema
156
+ },
157
+ "projects.get": { response: projectsGetResponseSchema },
158
+ "projects.update": {
159
+ request: projectsUpdateRequestSchema,
160
+ response: projectsUpdateResponseSchema
161
+ },
162
+ "projects.delete": { response: projectsDeleteResponseSchema },
163
+ "projects.listMachines": { response: projectsListMachinesResponseSchema },
164
+ "machines.create": {
165
+ request: machinesCreateRequestSchema,
166
+ response: machinesCreateResponseSchema
167
+ },
168
+ "machines.get": { response: machinesGetResponseSchema },
169
+ "machines.getVersion": { response: machinesGetVersionResponseSchema },
170
+ "machines.update": {
171
+ request: machinesUpdateRequestSchema,
172
+ response: machinesUpdateResponseSchema
173
+ }
174
+ };
175
+ /** Provider-independent operations implemented by this repository. */
176
+ const codeOperationSchemas = { "code.extractMachines": {
177
+ request: codeExtractMachinesRequestSchema,
178
+ response: codeExtractMachinesResponseSchema
179
+ } };
180
+ /** Every owned API operation with a canonical request/response contract. */
181
+ const operationSchemas = {
182
+ ...resourceOperationSchemas,
183
+ ...codeOperationSchemas
184
+ };
185
+
186
+ //#endregion
187
+ //#region src/studio.ts
188
+ /**
189
+ * Remote client for the owned Stately resource contract (`/api/v1/*`).
190
+ *
191
+ * Every method targets our own routes (never the legacy Registry API), sends
192
+ * JSON bodies with a bearer credential, and validates responses against the
193
+ * canonical Zod schemas from `@statelyai/api-contract`. Responses are canonical
194
+ * values directly: there is no `{ data }` envelope. Errors use the nested
195
+ * envelope `{ error: { code, message, issues?, retryable? } }`.
196
+ */
197
+ /** Default base URL of the editor/API deployment hosting `/api/v1`. */
198
+ const DEFAULT_STATELY_BASE_URL = "https://editor.stately.ai";
199
+ var StudioApiError = class extends Error {
200
+ status;
201
+ /** Canonical resource error code, when the server sent one. */
202
+ code;
203
+ issues;
204
+ retryable;
205
+ constructor(message, status, options = {}) {
206
+ super(message);
207
+ this.name = "StudioApiError";
208
+ this.status = status;
209
+ this.code = options.code;
210
+ this.issues = options.issues;
211
+ this.retryable = options.retryable;
212
+ }
213
+ };
214
+ function getFetch(fetchImpl) {
215
+ const resolvedFetch = fetchImpl ?? globalThis.fetch;
216
+ if (!resolvedFetch) throw new Error("No fetch implementation available. Pass one via createStatelyClient({ fetch }).");
217
+ return resolvedFetch;
218
+ }
219
+ function joinApiUrl(baseUrl, path) {
220
+ return `${baseUrl.replace(/\/+$/, "")}/api/v1${path}`;
221
+ }
222
+ async function parseJson(response) {
223
+ if (!response.headers.get("content-type")?.includes("application/json")) return null;
224
+ return response.json().catch(() => null);
225
+ }
226
+ function toApiError(data, status) {
227
+ const parsed = resourceApiErrorResponseSchema.safeParse(data);
228
+ if (parsed.success) {
229
+ const { code, message, issues, retryable } = parsed.data.error;
230
+ return new StudioApiError(message, status, {
231
+ code,
232
+ issues,
233
+ retryable
234
+ });
235
+ }
236
+ if (typeof data === "object" && data !== null && "error" in data && typeof data.error === "string") return new StudioApiError(data.error, status);
237
+ return new StudioApiError(`HTTP ${status}`, status);
238
+ }
239
+ function normalizeVisibility(visibility) {
240
+ return visibility.toLowerCase();
241
+ }
242
+ function normalizeXStateVersion(xstateVersion) {
243
+ return xstateVersion === void 0 || xstateVersion === 4 ? 5 : xstateVersion;
244
+ }
245
+ function normalizeExtractXStateVersion(xstateVersion) {
246
+ return xstateVersion === 4 ? 5 : xstateVersion;
247
+ }
248
+ function withMachineAlias(machine) {
249
+ return {
250
+ ...machine,
251
+ definition: machine.definition,
252
+ id: machine.machineId
253
+ };
254
+ }
255
+ function withProjectAlias(project) {
256
+ return {
257
+ ...project,
258
+ id: project.projectVersionId
259
+ };
260
+ }
261
+ function isCredentialLike(value) {
262
+ if (typeof value === "string") return true;
263
+ return typeof value === "object" && value !== null && "type" in value && (value.type === "api_key" || value.type === "oauth");
264
+ }
265
+ function createStatelyClient(options = {}) {
266
+ const baseUrl = options.baseUrl ?? DEFAULT_STATELY_BASE_URL;
267
+ const fetchImpl = getFetch(options.fetch);
268
+ const defaultCredential = options.credential ?? (options.apiKey ? {
269
+ type: "api_key",
270
+ token: options.apiKey
271
+ } : void 0);
272
+ const defaultAuthMode = options.authMode ?? "auto";
273
+ async function request(path, init, schema, requestOptions = {}) {
274
+ const headers = new Headers(init.headers);
275
+ const authMode = requestOptions.authMode ?? defaultAuthMode;
276
+ const credential = requestOptions.credential ?? defaultCredential;
277
+ if (authMode !== "none") {
278
+ const token = getCredentialToken(credential);
279
+ if (authMode === "bearer" && (!token || !credential)) throw new StudioApiError("No Stately credential configured. Pass createStatelyClient({ credential }) or use authMode: \"auto\" to let the server decide whether authentication is required.", 401, { code: "unauthenticated" });
280
+ if (token && credential) headers.set("Authorization", createAuthorizationHeader(credential));
281
+ }
282
+ const response = await fetchImpl(joinApiUrl(baseUrl, path), {
283
+ ...init,
284
+ headers,
285
+ ...requestOptions.signal ? { signal: requestOptions.signal } : {}
286
+ });
287
+ const data = await parseJson(response);
288
+ if (!response.ok) throw toApiError(data, response.status);
289
+ const parsed = schema.safeParse(data);
290
+ if (!parsed.success) throw new StudioApiError(`Unexpected response for ${path}: ${parsed.error.message}`, response.status, {
291
+ code: "internal_error",
292
+ issues: [...parsed.error.issues]
293
+ });
294
+ return parsed.data;
295
+ }
296
+ function jsonInit(method, body) {
297
+ return {
298
+ method,
299
+ headers: { "Content-Type": "application/json" },
300
+ body: JSON.stringify(body)
301
+ };
302
+ }
303
+ const projects = {
304
+ list(requestOptions) {
305
+ return request("/projects", { method: "GET" }, projectsListResponseSchema, requestOptions);
306
+ },
307
+ create(input, requestOptions) {
308
+ return request("/projects", jsonInit("POST", {
309
+ name: input.name,
310
+ visibility: normalizeVisibility(input.visibility)
311
+ }), projectSchema, requestOptions).then(withProjectAlias);
312
+ },
313
+ get(projectId, requestOptions) {
314
+ return request(`/projects/${encodeURIComponent(projectId)}`, { method: "GET" }, projectSchema, requestOptions).then(withProjectAlias);
315
+ },
316
+ update(projectId, input, requestOptions) {
317
+ return request(`/projects/${encodeURIComponent(projectId)}`, jsonInit("PATCH", {
318
+ ...input.name !== void 0 ? { name: input.name } : {},
319
+ ...input.description !== void 0 ? { description: input.description } : {},
320
+ ...input.visibility !== void 0 ? { visibility: normalizeVisibility(input.visibility) } : {}
321
+ }), projectSchema, requestOptions).then(withProjectAlias);
322
+ },
323
+ delete(projectId, requestOptions) {
324
+ return request(`/projects/${encodeURIComponent(projectId)}`, { method: "DELETE" }, projectsDeleteResponseSchema, requestOptions);
325
+ },
326
+ listMachines(projectId, requestOptions) {
327
+ return request(`/projects/${encodeURIComponent(projectId)}/machines`, { method: "GET" }, projectsListMachinesResponseSchema, requestOptions);
328
+ },
329
+ async ensure(input, requestOptions) {
330
+ if (input.matchConnectedRepo !== false) {
331
+ const match = (await projects.list(requestOptions)).find((candidate) => candidate.name === input.name);
332
+ if (match) return projects.get(match.projectId, requestOptions);
333
+ }
334
+ return projects.create(input, requestOptions);
335
+ }
336
+ };
337
+ const machines = {
338
+ create(input, requestOptions) {
339
+ return request("/machines", jsonInit("POST", {
340
+ projectVersionId: input.projectVersionId,
341
+ xstateVersion: normalizeXStateVersion(input.xstateVersion),
342
+ ...input.name !== void 0 ? { name: input.name } : {},
343
+ ...input.definition !== void 0 ? { definition: input.definition } : {}
344
+ }), machineSchema, requestOptions).then((machine) => withMachineAlias(machine));
345
+ },
346
+ async createMany(input, requestOptions) {
347
+ return [await machines.create(input, requestOptions)];
348
+ },
349
+ get(machineId, getOptions = {}) {
350
+ return request(`/machines/${encodeURIComponent(machineId)}`, { method: "GET" }, machineSchema, getOptions).then((machine) => withMachineAlias(machine));
351
+ },
352
+ getVersion(machineId, versionId, requestOptions) {
353
+ return request(`/machines/${encodeURIComponent(machineId)}/versions/${encodeURIComponent(versionId)}`, { method: "GET" }, machineVersionSchema, requestOptions);
354
+ },
355
+ update(machineIdOrInput, inputOrOptions, maybeOptions) {
356
+ const machineId = typeof machineIdOrInput === "string" ? machineIdOrInput : machineIdOrInput.machineId ?? machineIdOrInput.id;
357
+ if (!machineId) throw new StudioApiError("machines.update requires a machine id.", 400, { code: "bad_request" });
358
+ const input = (typeof machineIdOrInput === "string" ? inputOrOptions : machineIdOrInput) ?? {};
359
+ const requestOptions = typeof machineIdOrInput === "string" ? maybeOptions : inputOrOptions;
360
+ return request(`/machines/${encodeURIComponent(machineId)}`, jsonInit("PATCH", {
361
+ ...input.name !== void 0 ? { name: input.name } : {},
362
+ ...input.definition !== void 0 ? { definition: input.definition } : {}
363
+ }), machineSchema, requestOptions).then((machine) => withMachineAlias(machine));
364
+ }
365
+ };
366
+ return {
367
+ auth: { verify(credentialOrOptions, verifyOptions) {
368
+ return request("/auth/verify", { method: "GET" }, verifyResultSchema, isCredentialLike(credentialOrOptions) ? {
369
+ ...verifyOptions,
370
+ credential: credentialOrOptions
371
+ } : credentialOrOptions ?? verifyOptions ?? {});
372
+ } },
373
+ projects,
374
+ machines,
375
+ code: { extractMachines(codeOrInput, extractOptions = {}) {
376
+ const input = typeof codeOrInput === "string" ? {
377
+ code: codeOrInput,
378
+ xstateVersion: extractOptions.xstateVersion
379
+ } : codeOrInput;
380
+ const legacyOptions = extractOptions;
381
+ const credential = legacyOptions.credential ?? (legacyOptions.apiKey ? {
382
+ type: "api_key",
383
+ token: legacyOptions.apiKey
384
+ } : void 0);
385
+ return request("/code/extract-machines", jsonInit("POST", {
386
+ code: input.code,
387
+ xstateVersion: normalizeExtractXStateVersion(input.xstateVersion)
388
+ }), extractedMachinesSchema, {
389
+ ...extractOptions,
390
+ credential
391
+ });
392
+ } }
393
+ };
394
+ }
395
+
396
+ //#endregion
397
+ export { StudioApiError as n, createStatelyClient as r, DEFAULT_STATELY_BASE_URL as t };
@@ -1,5 +1,5 @@
1
- import { A as $strip, C as ZodObject, D as ZodUnion, E as ZodString, O as ZodUnknown, S as ZodNumber, T as ZodRecord, b as ZodLiteral, k as output, v as ZodArray, w as ZodOptional, x as ZodNullable, y as ZodEnum } from "./index-ag6K2iAS.mjs";
2
- import { n as StatelyCredential, t as StatelyAuthMode } from "./auth-2Thaw42j.mjs";
1
+ import { A as $strip, C as ZodObject, D as ZodUnion, E as ZodString, O as ZodUnknown, S as ZodNumber, T as ZodRecord, b as ZodLiteral, k as output, v as ZodArray, w as ZodOptional, x as ZodNullable, y as ZodEnum } from "./index-BAkQThnl.mjs";
2
+ import { n as StatelyCredential, t as StatelyAuthMode } from "./auth-B0ZTKri2.mjs";
3
3
 
4
4
  //#region ../api-contract/dist/errors.d.mts
5
5
  /**
package/dist/studio.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as Machine, C as StudioMachineRecord, D as VerifyApiKeyResponse, E as UpdateProjectInput, F as ProjectVisibility, I as VerifyResult, L as XStateVersion, M as Project, N as ProjectMachineSummary, O as createStatelyClient, P as ProjectSummary, R as ResourceErrorCode, S as StudioClientOptions, T as UpdateMachineInput, _ as ProjectMachine, a as CreateMachineTemplate, b as StudioApiErrorOptions, c as EnsureProjectInput, d as ExtractedMachine, f as GetMachineOptions, g as ProjectData, h as LegacyUpdateMachineInput, i as CreateMachineInput, j as MachineVersion, k as ExtractedMachines, l as ExtractMachinesInput, m as LegacyProjectVisibility, n as CreateMachineFromDefinitionInput, o as CreateProjectInput, p as LegacyExtractMachinesOptions, r as CreateMachineFromTemplateInput, s as DEFAULT_STATELY_BASE_URL, t as ConnectedRepo, u as ExtractMachinesResponse, v as RepoType, w as StudioRequestOptions, x as StudioClient, y as StudioApiError } from "./studio-Bk_u41gu.mjs";
1
+ import { A as Machine, C as StudioMachineRecord, D as VerifyApiKeyResponse, E as UpdateProjectInput, F as ProjectVisibility, I as VerifyResult, L as XStateVersion, M as Project, N as ProjectMachineSummary, O as createStatelyClient, P as ProjectSummary, R as ResourceErrorCode, S as StudioClientOptions, T as UpdateMachineInput, _ as ProjectMachine, a as CreateMachineTemplate, b as StudioApiErrorOptions, c as EnsureProjectInput, d as ExtractedMachine, f as GetMachineOptions, g as ProjectData, h as LegacyUpdateMachineInput, i as CreateMachineInput, j as MachineVersion, k as ExtractedMachines, l as ExtractMachinesInput, m as LegacyProjectVisibility, n as CreateMachineFromDefinitionInput, o as CreateProjectInput, p as LegacyExtractMachinesOptions, r as CreateMachineFromTemplateInput, s as DEFAULT_STATELY_BASE_URL, t as ConnectedRepo, u as ExtractMachinesResponse, v as RepoType, w as StudioRequestOptions, x as StudioClient, y as StudioApiError } from "./studio-YSppd-am.mjs";
2
2
  export { ConnectedRepo, CreateMachineFromDefinitionInput, CreateMachineFromTemplateInput, CreateMachineInput, CreateMachineTemplate, CreateProjectInput, DEFAULT_STATELY_BASE_URL, EnsureProjectInput, ExtractMachinesInput, ExtractMachinesResponse, ExtractedMachine, ExtractedMachines, GetMachineOptions, LegacyExtractMachinesOptions, LegacyProjectVisibility, LegacyUpdateMachineInput, Machine, MachineVersion, Project, ProjectData, ProjectMachine, ProjectMachineSummary, ProjectSummary, ProjectVisibility, RepoType, ResourceErrorCode, StudioApiError, StudioApiErrorOptions, StudioClient, StudioClientOptions, StudioMachineRecord, StudioRequestOptions, UpdateMachineInput, UpdateProjectInput, VerifyApiKeyResponse, VerifyResult, XStateVersion, createStatelyClient };
package/dist/studio.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as StudioApiError, r as createStatelyClient, t as DEFAULT_STATELY_BASE_URL } from "./studio-txdyJHD7.mjs";
1
+ import { n as StudioApiError, r as createStatelyClient, t as DEFAULT_STATELY_BASE_URL } from "./studio-DHGspwII.mjs";
2
2
 
3
3
  export { DEFAULT_STATELY_BASE_URL, StudioApiError, createStatelyClient };
package/dist/sync.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { b as DigraphConfig, i as StatelyGraph } from "./graph-DuOeLGvh.mjs";
2
- import { C as StudioMachineRecord, L as XStateVersion, g as ProjectData, o as CreateProjectInput, x as StudioClient } from "./studio-Bk_u41gu.mjs";
1
+ import { b as DigraphConfig, i as StatelyGraph } from "./graph-yDK-MM3G.mjs";
2
+ import { C as StudioMachineRecord, L as XStateVersion, g as ProjectData, o as CreateProjectInput, x as StudioClient } from "./studio-YSppd-am.mjs";
3
3
  import { GraphDiff } from "@statelyai/graph";
4
4
 
5
5
  //#region src/sync.d.ts
package/dist/sync.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { r as createStatelyClient } from "./studio-txdyJHD7.mjs";
2
- import { i as INLINE_EXPRESSION_DIRECTIVE_FIELDS, m as xstateSourceToConfig, n as getStatelyPragma, p as serializeJS, r as upsertStatelyPragma, s as detectXStateSourceProfile, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-Bm9O4XV6.mjs";
1
+ import { r as createStatelyClient } from "./studio-DHGspwII.mjs";
2
+ import { f as normalizeMachineProfile, h as xstateSourceToConfig, i as INLINE_EXPRESSION_DIRECTIVE_FIELDS, m as serializeJS, n as getStatelyPragma, r as upsertStatelyPragma, s as detectXStateSourceProfile, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-CIzsR_Sx.mjs";
3
3
  import { fromStudioMachine, toStudioMachine } from "./graph.mjs";
4
4
  import * as ts$1 from "typescript";
5
5
  import ts from "typescript";
@@ -157,7 +157,8 @@ function collectXStateSourceLocations(sourceText, document, options = {}) {
157
157
  const inferredProfile = rootProfile === "xstate-v6-alpha" || resolvedTransitionFunctions.size > 0 || [...referencedStateSymbols].some((symbol) => detectXStateSourceProfile(bindings.get(symbol)?.sourceFile.text ?? "") === "xstate-v6-alpha") ? "xstate-v6-alpha" : rootProfile;
158
158
  return {
159
159
  version: 1,
160
- profile: packageProfile ?? inferredProfile,
160
+ profile: packageProfile?.profile ?? inferredProfile,
161
+ profileRef: packageProfile?.profileRef ?? normalizeMachineProfile(inferredProfile),
161
162
  root: {
162
163
  uri,
163
164
  range: toSourceRange$1(sourceFile, root)
@@ -198,10 +199,16 @@ function detectXStatePackageProfile(packageJson) {
198
199
  }
199
200
  }
200
201
  if (!range) return void 0;
201
- const clauseProfiles = range.replace(/^(?:workspace:|npm:xstate@)/, "").split("||").map((clause) => detectXStateRangeClauseProfile(clause.trim()));
202
+ const normalizedRange = range.replace(/^(?:workspace:|npm:xstate@)/, "");
203
+ const clauseProfiles = normalizedRange.split("||").map((clause) => detectXStateRangeClauseProfile(clause.trim()));
202
204
  const profiles = new Set(clauseProfiles);
203
205
  if (profiles.size !== 1 || profiles.has(void 0)) return void 0;
204
- return clauseProfiles[0];
206
+ const profile = clauseProfiles[0];
207
+ if (!profile) return void 0;
208
+ return {
209
+ profile,
210
+ profileRef: /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(normalizedRange) ? `@statelyai/xstate@${normalizedRange}` : normalizeMachineProfile(profile)
211
+ };
205
212
  }
206
213
  function detectXStateRangeClauseProfile(clause) {
207
214
  const normalizedClause = clause.replace(/([<>]=?)\s+/g, "$1");
@@ -166,12 +166,13 @@ function createPostMessageTransport(options) {
166
166
  }
167
167
  const data = e.data;
168
168
  if (!data?.type?.startsWith?.(PREFIX)) return;
169
- if (data.type === "@statelyai.ready" && !isReady) {
170
- isReady = true;
169
+ const becameReady = data.type === "@statelyai.ready" && !isReady;
170
+ if (becameReady) isReady = true;
171
+ messageHandlers.forEach((fn) => fn(data));
172
+ if (becameReady) {
171
173
  readyHandlers.forEach((fn) => fn());
172
174
  readyHandlers.clear();
173
175
  }
174
- messageHandlers.forEach((fn) => fn(data));
175
176
  }
176
177
  window.addEventListener("message", handleMessage);
177
178
  return {
@@ -326,4 +327,13 @@ function createWebSocketTransport(options) {
326
327
  }
327
328
 
328
329
  //#endregion
329
- export { toInitMessage as a, createPendingExportManager as i, createWebSocketTransport as n, createEventRegistry as r, createPostMessageTransport as t };
330
+ //#region src/version.ts
331
+ const SDK_VERSION = "0.20.1";
332
+ function inspectionRuntime() {
333
+ if (typeof window !== "undefined") return "browser";
334
+ if (typeof process !== "undefined" && process.versions?.node) return "node";
335
+ return "unknown";
336
+ }
337
+
338
+ //#endregion
339
+ export { createEventRegistry as a, createWebSocketTransport as i, inspectionRuntime as n, createPendingExportManager as o, createPostMessageTransport as r, toInitMessage as s, SDK_VERSION as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/sdk",
3
- "version": "0.18.0",
3
+ "version": "0.20.1",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "stately-sdk": "./dist/bin.mjs"
@@ -61,6 +61,10 @@
61
61
  "types": "./dist/protocol.d.mts",
62
62
  "import": "./dist/protocol.mjs"
63
63
  },
64
+ "./editor-host": {
65
+ "types": "./dist/editorHostSession.d.mts",
66
+ "import": "./dist/editorHostSession.mjs"
67
+ },
64
68
  "./relay": {
65
69
  "types": "./dist/relay.d.mts",
66
70
  "import": "./dist/relay.mjs"
@@ -89,8 +93,8 @@
89
93
  "jsdom": "^27.4.0",
90
94
  "tsdown": "0.21.0-beta.2",
91
95
  "vitest": "^3.2.4",
92
- "@statelyai/api-contract": "0.0.2",
93
- "@statelyai/graph-tools": "0.0.8"
96
+ "@statelyai/api-contract": "0.1.1",
97
+ "@statelyai/graph-tools": "0.0.9"
94
98
  },
95
99
  "engines": {
96
100
  "node": ">=22.4"