@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
@@ -1,5 +1,3 @@
1
- import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
2
-
3
1
  //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
4
2
  var _a$1;
5
3
  function $constructor(name, initializer, params) {
@@ -2830,6 +2828,17 @@ function _array(Class, element, params) {
2830
2828
  });
2831
2829
  }
2832
2830
  /* @__NO_SIDE_EFFECTS__ */
2831
+ function _custom(Class, fn, _params) {
2832
+ const norm = normalizeParams(_params);
2833
+ norm.abort ?? (norm.abort = true);
2834
+ return new Class({
2835
+ type: "custom",
2836
+ check: "custom",
2837
+ fn,
2838
+ ...norm
2839
+ });
2840
+ }
2841
+ /* @__NO_SIDE_EFFECTS__ */
2833
2842
  function _refine(Class, fn, _params) {
2834
2843
  return new Class({
2835
2844
  type: "custom",
@@ -4319,6 +4328,9 @@ const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
4319
4328
  ZodType.init(inst, def);
4320
4329
  inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx, json, params);
4321
4330
  });
4331
+ function custom(fn, _params) {
4332
+ return _custom(ZodCustom, fn ?? (() => true), _params);
4333
+ }
4322
4334
  function refine(fn, _params = {}) {
4323
4335
  return _refine(ZodCustom, fn, _params);
4324
4336
  }
@@ -4329,397 +4341,4 @@ const describe = describe$1;
4329
4341
  const meta = meta$1;
4330
4342
 
4331
4343
  //#endregion
4332
- //#region ../api-contract/dist/errors.mjs
4333
- /**
4334
- * Error shape returned by every `/api/v1` machine operation (and by the shared
4335
- * auth guard). Each operation registers its own error schema component in the
4336
- * OpenAPI document, so this is a factory rather than a single shared instance.
4337
- */
4338
- function createApiErrorResponseSchema() {
4339
- return object({
4340
- error: string(),
4341
- issues: array(unknown()).optional()
4342
- });
4343
- }
4344
- const apiErrorResponseSchema = createApiErrorResponseSchema();
4345
- /**
4346
- * Canonical error codes for the `/api/v1` resource operations. Machine
4347
- * operations keep the flat `{ error: string }` shape above unchanged; the
4348
- * nested envelope below applies to resource operations only.
4349
- */
4350
- const resourceErrorCodeSchema = _enum([
4351
- "bad_request",
4352
- "unauthenticated",
4353
- "forbidden",
4354
- "not_found",
4355
- "conflict",
4356
- "payload_too_large",
4357
- "rate_limited",
4358
- "capability_disabled",
4359
- "upstream_error",
4360
- "internal_error"
4361
- ]);
4362
- /** Factory, matching `createApiErrorResponseSchema`, for per-route OpenAPI components. */
4363
- function createResourceApiErrorResponseSchema() {
4364
- return object({ error: object({
4365
- code: resourceErrorCodeSchema,
4366
- message: string(),
4367
- issues: array(unknown()).optional(),
4368
- retryable: boolean().optional()
4369
- }) });
4370
- }
4371
- const resourceApiErrorResponseSchema = createResourceApiErrorResponseSchema();
4372
-
4373
- //#endregion
4374
- //#region ../api-contract/dist/resources.mjs
4375
- /**
4376
- * Canonical schemas for persistent `/api/v1` resources plus the owned,
4377
- * deterministic code-extraction operation.
4378
- *
4379
- * These models are canonical, not upstream-shaped: providers (e.g. the Stately
4380
- * Registry adapter) are responsible for translating upstream envelopes,
4381
- * identifier quirks and casing into these shapes. No `{ data }` envelope
4382
- * appears anywhere; all timestamps are ISO strings.
4383
- */
4384
- /**
4385
- * XState major versions the editor targets (see
4386
- * `packages/editor/src/formats/xstate.ts`).
4387
- */
4388
- const xstateVersionSchema = union([literal(5), literal(6)]);
4389
- const projectVisibilitySchema = _enum([
4390
- "public",
4391
- "unlisted",
4392
- "private"
4393
- ]);
4394
- const verifyResultSchema = object({
4395
- valid: literal(true),
4396
- tokenScope: _enum(["user", "project"])
4397
- });
4398
- const projectSummarySchema = object({
4399
- projectId: string(),
4400
- projectVersionId: string(),
4401
- name: string(),
4402
- description: string().nullable(),
4403
- visibility: projectVisibilitySchema,
4404
- createdAt: string(),
4405
- updatedAt: string()
4406
- });
4407
- const projectSchema = projectSummarySchema.extend({
4408
- rootMachineId: string().nullable(),
4409
- machines: array(object({ machineId: string() }))
4410
- });
4411
- /**
4412
- * `name` is optional: the Registry project envelope only returns machine ids.
4413
- * Providers that can supply names cheaply should.
4414
- */
4415
- const projectMachineSummarySchema = object({
4416
- machineId: string(),
4417
- name: string().optional()
4418
- });
4419
- const machineSchema = object({
4420
- machineId: string(),
4421
- name: string(),
4422
- projectId: string().optional(),
4423
- projectVersionId: string(),
4424
- definition: unknown(),
4425
- createdAt: string().optional(),
4426
- updatedAt: string().optional()
4427
- });
4428
- const machineVersionSchema = object({
4429
- machineVersionId: string(),
4430
- machineId: string(),
4431
- versionNumber: number(),
4432
- name: string(),
4433
- definition: unknown(),
4434
- createdAt: string(),
4435
- updatedAt: string()
4436
- });
4437
- const extractedMachinesSchema = object({ machines: array(object({ config: record(string(), unknown()) })) });
4438
- const projectsCreateRequestSchema = object({
4439
- name: string().min(1),
4440
- visibility: projectVisibilitySchema
4441
- });
4442
- const projectsUpdateRequestSchema = object({
4443
- name: string().min(1).optional(),
4444
- description: string().nullable().optional(),
4445
- visibility: projectVisibilitySchema.optional()
4446
- }).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." });
4447
- const machinesCreateRequestSchema = object({
4448
- projectVersionId: string().min(1),
4449
- xstateVersion: xstateVersionSchema,
4450
- name: string().min(1).optional(),
4451
- definition: unknown().optional()
4452
- });
4453
- const machinesUpdateRequestSchema = object({
4454
- name: string().min(1).optional(),
4455
- definition: unknown().optional()
4456
- }).refine((value) => value.name !== void 0 || value.definition !== void 0, { message: "At least one of `name` or `definition` is required." });
4457
- const codeExtractMachinesRequestSchema = object({
4458
- code: string().min(1),
4459
- xstateVersion: xstateVersionSchema.optional()
4460
- });
4461
- const authVerifyResponseSchema = verifyResultSchema;
4462
- const projectsListResponseSchema = array(projectSummarySchema);
4463
- const projectsGetResponseSchema = projectSchema;
4464
- const projectsCreateResponseSchema = projectSchema;
4465
- const projectsUpdateResponseSchema = projectSchema;
4466
- const projectsDeleteResponseSchema = object({ projectId: string() });
4467
- const projectsListMachinesResponseSchema = array(projectMachineSummarySchema);
4468
- const machinesCreateResponseSchema = machineSchema;
4469
- const machinesGetResponseSchema = machineSchema;
4470
- const machinesUpdateResponseSchema = machineSchema;
4471
- const machinesGetVersionResponseSchema = machineVersionSchema;
4472
- const codeExtractMachinesResponseSchema = extractedMachinesSchema;
4473
- /**
4474
- * Request/response schema pairs keyed by resource capability name. Kept here
4475
- * rather than on the `Capability` metadata entries so that the capability
4476
- * registry stays plain, serialisable data.
4477
- */
4478
- const resourceOperationSchemas = {
4479
- "auth.verify": { response: authVerifyResponseSchema },
4480
- "projects.list": { response: projectsListResponseSchema },
4481
- "projects.create": {
4482
- request: projectsCreateRequestSchema,
4483
- response: projectsCreateResponseSchema
4484
- },
4485
- "projects.get": { response: projectsGetResponseSchema },
4486
- "projects.update": {
4487
- request: projectsUpdateRequestSchema,
4488
- response: projectsUpdateResponseSchema
4489
- },
4490
- "projects.delete": { response: projectsDeleteResponseSchema },
4491
- "projects.listMachines": { response: projectsListMachinesResponseSchema },
4492
- "machines.create": {
4493
- request: machinesCreateRequestSchema,
4494
- response: machinesCreateResponseSchema
4495
- },
4496
- "machines.get": { response: machinesGetResponseSchema },
4497
- "machines.getVersion": { response: machinesGetVersionResponseSchema },
4498
- "machines.update": {
4499
- request: machinesUpdateRequestSchema,
4500
- response: machinesUpdateResponseSchema
4501
- }
4502
- };
4503
- /** Provider-independent operations implemented by this repository. */
4504
- const codeOperationSchemas = { "code.extractMachines": {
4505
- request: codeExtractMachinesRequestSchema,
4506
- response: codeExtractMachinesResponseSchema
4507
- } };
4508
- /** Every owned API operation with a canonical request/response contract. */
4509
- const operationSchemas = {
4510
- ...resourceOperationSchemas,
4511
- ...codeOperationSchemas
4512
- };
4513
-
4514
- //#endregion
4515
- //#region src/studio.ts
4516
- /**
4517
- * Remote client for the owned Stately resource contract (`/api/v1/*`).
4518
- *
4519
- * Every method targets our own routes (never the legacy Registry API), sends
4520
- * JSON bodies with a bearer credential, and validates responses against the
4521
- * canonical Zod schemas from `@statelyai/api-contract`. Responses are canonical
4522
- * values directly: there is no `{ data }` envelope. Errors use the nested
4523
- * envelope `{ error: { code, message, issues?, retryable? } }`.
4524
- */
4525
- /** Default base URL of the editor/API deployment hosting `/api/v1`. */
4526
- const DEFAULT_STATELY_BASE_URL = "https://editor.stately.ai";
4527
- var StudioApiError = class extends Error {
4528
- status;
4529
- /** Canonical resource error code, when the server sent one. */
4530
- code;
4531
- issues;
4532
- retryable;
4533
- constructor(message, status, options = {}) {
4534
- super(message);
4535
- this.name = "StudioApiError";
4536
- this.status = status;
4537
- this.code = options.code;
4538
- this.issues = options.issues;
4539
- this.retryable = options.retryable;
4540
- }
4541
- };
4542
- function getFetch(fetchImpl) {
4543
- const resolvedFetch = fetchImpl ?? globalThis.fetch;
4544
- if (!resolvedFetch) throw new Error("No fetch implementation available. Pass one via createStatelyClient({ fetch }).");
4545
- return resolvedFetch;
4546
- }
4547
- function joinApiUrl(baseUrl, path) {
4548
- return `${baseUrl.replace(/\/+$/, "")}/api/v1${path}`;
4549
- }
4550
- async function parseJson(response) {
4551
- if (!response.headers.get("content-type")?.includes("application/json")) return null;
4552
- return response.json().catch(() => null);
4553
- }
4554
- function toApiError(data, status) {
4555
- const parsed = resourceApiErrorResponseSchema.safeParse(data);
4556
- if (parsed.success) {
4557
- const { code, message, issues, retryable } = parsed.data.error;
4558
- return new StudioApiError(message, status, {
4559
- code,
4560
- issues,
4561
- retryable
4562
- });
4563
- }
4564
- if (typeof data === "object" && data !== null && "error" in data && typeof data.error === "string") return new StudioApiError(data.error, status);
4565
- return new StudioApiError(`HTTP ${status}`, status);
4566
- }
4567
- function normalizeVisibility(visibility) {
4568
- return visibility.toLowerCase();
4569
- }
4570
- function normalizeXStateVersion(xstateVersion) {
4571
- return xstateVersion === void 0 || xstateVersion === 4 ? 5 : xstateVersion;
4572
- }
4573
- function normalizeExtractXStateVersion(xstateVersion) {
4574
- return xstateVersion === 4 ? 5 : xstateVersion;
4575
- }
4576
- function withMachineAlias(machine) {
4577
- return {
4578
- ...machine,
4579
- definition: machine.definition,
4580
- id: machine.machineId
4581
- };
4582
- }
4583
- function withProjectAlias(project) {
4584
- return {
4585
- ...project,
4586
- id: project.projectVersionId
4587
- };
4588
- }
4589
- function isCredentialLike(value) {
4590
- if (typeof value === "string") return true;
4591
- return typeof value === "object" && value !== null && "type" in value && (value.type === "api_key" || value.type === "oauth");
4592
- }
4593
- function createStatelyClient(options = {}) {
4594
- const baseUrl = options.baseUrl ?? DEFAULT_STATELY_BASE_URL;
4595
- const fetchImpl = getFetch(options.fetch);
4596
- const defaultCredential = options.credential ?? (options.apiKey ? {
4597
- type: "api_key",
4598
- token: options.apiKey
4599
- } : void 0);
4600
- const defaultAuthMode = options.authMode ?? "auto";
4601
- async function request(path, init, schema, requestOptions = {}) {
4602
- const headers = new Headers(init.headers);
4603
- const authMode = requestOptions.authMode ?? defaultAuthMode;
4604
- const credential = requestOptions.credential ?? defaultCredential;
4605
- if (authMode !== "none") {
4606
- const token = getCredentialToken(credential);
4607
- 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" });
4608
- if (token && credential) headers.set("Authorization", createAuthorizationHeader(credential));
4609
- }
4610
- const response = await fetchImpl(joinApiUrl(baseUrl, path), {
4611
- ...init,
4612
- headers,
4613
- ...requestOptions.signal ? { signal: requestOptions.signal } : {}
4614
- });
4615
- const data = await parseJson(response);
4616
- if (!response.ok) throw toApiError(data, response.status);
4617
- const parsed = schema.safeParse(data);
4618
- if (!parsed.success) throw new StudioApiError(`Unexpected response for ${path}: ${parsed.error.message}`, response.status, {
4619
- code: "internal_error",
4620
- issues: [...parsed.error.issues]
4621
- });
4622
- return parsed.data;
4623
- }
4624
- function jsonInit(method, body) {
4625
- return {
4626
- method,
4627
- headers: { "Content-Type": "application/json" },
4628
- body: JSON.stringify(body)
4629
- };
4630
- }
4631
- const projects = {
4632
- list(requestOptions) {
4633
- return request("/projects", { method: "GET" }, projectsListResponseSchema, requestOptions);
4634
- },
4635
- create(input, requestOptions) {
4636
- return request("/projects", jsonInit("POST", {
4637
- name: input.name,
4638
- visibility: normalizeVisibility(input.visibility)
4639
- }), projectSchema, requestOptions).then(withProjectAlias);
4640
- },
4641
- get(projectId, requestOptions) {
4642
- return request(`/projects/${encodeURIComponent(projectId)}`, { method: "GET" }, projectSchema, requestOptions).then(withProjectAlias);
4643
- },
4644
- update(projectId, input, requestOptions) {
4645
- return request(`/projects/${encodeURIComponent(projectId)}`, jsonInit("PATCH", {
4646
- ...input.name !== void 0 ? { name: input.name } : {},
4647
- ...input.description !== void 0 ? { description: input.description } : {},
4648
- ...input.visibility !== void 0 ? { visibility: normalizeVisibility(input.visibility) } : {}
4649
- }), projectSchema, requestOptions).then(withProjectAlias);
4650
- },
4651
- delete(projectId, requestOptions) {
4652
- return request(`/projects/${encodeURIComponent(projectId)}`, { method: "DELETE" }, projectsDeleteResponseSchema, requestOptions);
4653
- },
4654
- listMachines(projectId, requestOptions) {
4655
- return request(`/projects/${encodeURIComponent(projectId)}/machines`, { method: "GET" }, projectsListMachinesResponseSchema, requestOptions);
4656
- },
4657
- async ensure(input, requestOptions) {
4658
- if (input.matchConnectedRepo !== false) {
4659
- const match = (await projects.list(requestOptions)).find((candidate) => candidate.name === input.name);
4660
- if (match) return projects.get(match.projectId, requestOptions);
4661
- }
4662
- return projects.create(input, requestOptions);
4663
- }
4664
- };
4665
- const machines = {
4666
- create(input, requestOptions) {
4667
- return request("/machines", jsonInit("POST", {
4668
- projectVersionId: input.projectVersionId,
4669
- xstateVersion: normalizeXStateVersion(input.xstateVersion),
4670
- ...input.name !== void 0 ? { name: input.name } : {},
4671
- ...input.definition !== void 0 ? { definition: input.definition } : {}
4672
- }), machineSchema, requestOptions).then((machine) => withMachineAlias(machine));
4673
- },
4674
- async createMany(input, requestOptions) {
4675
- return [await machines.create(input, requestOptions)];
4676
- },
4677
- get(machineId, getOptions = {}) {
4678
- return request(`/machines/${encodeURIComponent(machineId)}`, { method: "GET" }, machineSchema, getOptions).then((machine) => withMachineAlias(machine));
4679
- },
4680
- getVersion(machineId, versionId, requestOptions) {
4681
- return request(`/machines/${encodeURIComponent(machineId)}/versions/${encodeURIComponent(versionId)}`, { method: "GET" }, machineVersionSchema, requestOptions);
4682
- },
4683
- update(machineIdOrInput, inputOrOptions, maybeOptions) {
4684
- const machineId = typeof machineIdOrInput === "string" ? machineIdOrInput : machineIdOrInput.machineId ?? machineIdOrInput.id;
4685
- if (!machineId) throw new StudioApiError("machines.update requires a machine id.", 400, { code: "bad_request" });
4686
- const input = (typeof machineIdOrInput === "string" ? inputOrOptions : machineIdOrInput) ?? {};
4687
- const requestOptions = typeof machineIdOrInput === "string" ? maybeOptions : inputOrOptions;
4688
- return request(`/machines/${encodeURIComponent(machineId)}`, jsonInit("PATCH", {
4689
- ...input.name !== void 0 ? { name: input.name } : {},
4690
- ...input.definition !== void 0 ? { definition: input.definition } : {}
4691
- }), machineSchema, requestOptions).then((machine) => withMachineAlias(machine));
4692
- }
4693
- };
4694
- return {
4695
- auth: { verify(credentialOrOptions, verifyOptions) {
4696
- return request("/auth/verify", { method: "GET" }, verifyResultSchema, isCredentialLike(credentialOrOptions) ? {
4697
- ...verifyOptions,
4698
- credential: credentialOrOptions
4699
- } : credentialOrOptions ?? verifyOptions ?? {});
4700
- } },
4701
- projects,
4702
- machines,
4703
- code: { extractMachines(codeOrInput, extractOptions = {}) {
4704
- const input = typeof codeOrInput === "string" ? {
4705
- code: codeOrInput,
4706
- xstateVersion: extractOptions.xstateVersion
4707
- } : codeOrInput;
4708
- const legacyOptions = extractOptions;
4709
- const credential = legacyOptions.credential ?? (legacyOptions.apiKey ? {
4710
- type: "api_key",
4711
- token: legacyOptions.apiKey
4712
- } : void 0);
4713
- return request("/code/extract-machines", jsonInit("POST", {
4714
- code: input.code,
4715
- xstateVersion: normalizeExtractXStateVersion(input.xstateVersion)
4716
- }), extractedMachinesSchema, {
4717
- ...extractOptions,
4718
- credential
4719
- });
4720
- } }
4721
- };
4722
- }
4723
-
4724
- //#endregion
4725
- export { array as a, literal as c, record as d, string as f, _enum as i, number as l, unknown as m, StudioApiError as n, boolean as o, union as p, createStatelyClient as r, discriminatedUnion as s, DEFAULT_STATELY_BASE_URL as t, object as u };
4344
+ export { discriminatedUnion as a, object as c, union as d, unknown as f, custom as i, record as l, array as n, literal as o, boolean as r, number as s, _enum as t, string as u };