@usestatemachines/sdk 0.7.1 → 0.8.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.
Files changed (77) hide show
  1. package/README.md +75 -30
  2. package/agents/SKILL.md +7 -6
  3. package/agents/index.d.ts +2 -0
  4. package/agents/index.js +6 -4
  5. package/agents/llms.txt +6 -4
  6. package/esm/extensions/client.d.ts +11 -7
  7. package/esm/extensions/client.js +32 -49
  8. package/esm/extensions/credentials.d.ts +25 -8
  9. package/esm/extensions/credentials.js +75 -40
  10. package/esm/extensions/environment.d.ts +1 -1
  11. package/esm/extensions/errors.js +1 -1
  12. package/esm/extensions/index.d.ts +2 -2
  13. package/esm/extensions/yaml.js +14 -12
  14. package/esm/funcs/environments-creators.d.ts +11 -0
  15. package/esm/funcs/environments-creators.js +90 -0
  16. package/esm/funcs/environments-list.js +2 -0
  17. package/esm/funcs/requests-list.js +5 -1
  18. package/esm/funcs/requests-stats.js +5 -1
  19. package/esm/lib/config.d.ts +2 -2
  20. package/esm/lib/config.js +2 -2
  21. package/esm/models/app-entry.d.ts +8 -0
  22. package/esm/models/app-entry.js +11 -0
  23. package/esm/models/create-environment-app.d.ts +25 -0
  24. package/esm/models/create-environment-app.js +14 -0
  25. package/esm/models/create-environment.d.ts +3 -26
  26. package/esm/models/create-environment.js +2 -19
  27. package/esm/models/credential.d.ts +50 -0
  28. package/esm/models/credential.js +60 -0
  29. package/esm/models/credentials.d.ts +26 -5
  30. package/esm/models/credentials.js +20 -3
  31. package/esm/models/environment-failure.d.ts +3 -2
  32. package/esm/models/environment-failure.js +3 -2
  33. package/esm/models/environment.d.ts +4 -1
  34. package/esm/models/environment.js +2 -1
  35. package/esm/models/error.d.ts +1 -0
  36. package/esm/models/error.js +1 -0
  37. package/esm/models/index.d.ts +6 -1
  38. package/esm/models/index.js +6 -1
  39. package/esm/models/mcp-server.d.ts +11 -0
  40. package/esm/models/mcp-server.js +16 -0
  41. package/esm/models/mcp-tool.d.ts +12 -0
  42. package/esm/models/mcp-tool.js +16 -0
  43. package/esm/models/me.d.ts +2 -0
  44. package/esm/models/me.js +2 -0
  45. package/esm/models/operations/create-credentials.d.ts +2 -0
  46. package/esm/models/operations/create-credentials.js +1 -0
  47. package/esm/models/operations/get-request-stats.d.ts +10 -2
  48. package/esm/models/operations/get-request-stats.js +5 -1
  49. package/esm/models/operations/index.d.ts +1 -0
  50. package/esm/models/operations/index.js +1 -0
  51. package/esm/models/operations/list-environment-creators.d.ts +23 -0
  52. package/esm/models/operations/list-environment-creators.js +20 -0
  53. package/esm/models/operations/list-environments.d.ts +5 -1
  54. package/esm/models/operations/list-environments.js +2 -0
  55. package/esm/models/operations/list-requests.d.ts +10 -2
  56. package/esm/models/operations/list-requests.js +5 -1
  57. package/esm/models/request-detail.d.ts +8 -1
  58. package/esm/models/request-detail.js +5 -1
  59. package/esm/models/request-stats.d.ts +8 -0
  60. package/esm/models/request-stats.js +9 -0
  61. package/esm/models/request.d.ts +8 -1
  62. package/esm/models/request.js +5 -1
  63. package/esm/models/service.d.ts +25 -0
  64. package/esm/models/service.js +28 -0
  65. package/esm/models/snapshot.d.ts +7 -0
  66. package/esm/models/snapshot.js +3 -0
  67. package/esm/models/version.d.ts +2 -2
  68. package/esm/models/version.js +2 -2
  69. package/esm/sdk/environments.d.ts +1 -0
  70. package/esm/sdk/environments.js +4 -0
  71. package/esm/types/discriminated-union.d.ts +24 -0
  72. package/esm/types/discriminated-union.js +60 -0
  73. package/esm/types/smart-union.js +2 -1
  74. package/openapi.json +596 -116
  75. package/package.json +1 -1
  76. package/esm/models/api.d.ts +0 -17
  77. package/esm/models/api.js +0 -21
@@ -7,12 +7,14 @@ export type ListEnvironmentsRequest = {
7
7
  cursor?: string | undefined;
8
8
  workspaceId?: string | undefined;
9
9
  status?: Array<models.EnvironmentStatus> | undefined;
10
+ appId?: Array<string> | undefined;
11
+ createdBy?: Array<string> | undefined;
10
12
  snapshotId?: string | undefined;
11
13
  search?: string | undefined;
12
14
  label?: Array<string> | undefined;
13
15
  };
14
16
  /**
15
- * The workspace's environments, newest first
17
+ * The workspace's environments, newest created first
16
18
  */
17
19
  export type ListEnvironmentsResponse = {
18
20
  data: Array<models.Environment>;
@@ -24,6 +26,8 @@ export type ListEnvironmentsRequest$Outbound = {
24
26
  cursor?: string | undefined;
25
27
  workspaceId?: string | undefined;
26
28
  status?: Array<string> | undefined;
29
+ appId?: Array<string> | undefined;
30
+ createdBy?: Array<string> | undefined;
27
31
  snapshotId?: string | undefined;
28
32
  search?: string | undefined;
29
33
  label?: Array<string> | undefined;
@@ -11,6 +11,8 @@ export const ListEnvironmentsRequest$outboundSchema = z.object({
11
11
  cursor: z.optional(z.string()),
12
12
  workspaceId: z.optional(z.string()),
13
13
  status: z.optional(z.array(models.EnvironmentStatus$outboundSchema)),
14
+ appId: z.optional(z.array(z.string())),
15
+ createdBy: z.optional(z.array(z.string())),
14
16
  snapshotId: z.optional(z.string()),
15
17
  search: z.optional(z.string()),
16
18
  label: z.optional(z.array(z.string())),
@@ -26,11 +26,15 @@ export type ListRequestsRequest = {
26
26
  limit?: number | undefined;
27
27
  cursor?: string | undefined;
28
28
  environmentId: string;
29
- app?: string | undefined;
29
+ appName?: string | undefined;
30
30
  method?: ListRequestsMethod | undefined;
31
31
  responseStatus?: number | undefined;
32
32
  statusClass?: ListRequestsStatusClass | undefined;
33
33
  writesOnly?: boolean | undefined;
34
+ service?: string | undefined;
35
+ mcpServer?: string | undefined;
36
+ tool?: string | undefined;
37
+ operation?: string | undefined;
34
38
  search?: string | undefined;
35
39
  from?: Date | undefined;
36
40
  to?: Date | undefined;
@@ -51,11 +55,15 @@ export type ListRequestsRequest$Outbound = {
51
55
  limit: number;
52
56
  cursor?: string | undefined;
53
57
  environmentId: string;
54
- app?: string | undefined;
58
+ appName?: string | undefined;
55
59
  method?: string | undefined;
56
60
  responseStatus?: number | undefined;
57
61
  statusClass?: string | undefined;
58
62
  writesOnly?: boolean | undefined;
63
+ service?: string | undefined;
64
+ mcpServer?: string | undefined;
65
+ tool?: string | undefined;
66
+ operation?: string | undefined;
59
67
  search?: string | undefined;
60
68
  from?: string | undefined;
61
69
  to?: string | undefined;
@@ -31,11 +31,15 @@ export const ListRequestsRequest$outboundSchema = z.object({
31
31
  limit: z._default(z.int(), 50),
32
32
  cursor: z.optional(z.string()),
33
33
  environmentId: z.string(),
34
- app: z.optional(z.string()),
34
+ appName: z.optional(z.string()),
35
35
  method: z.optional(ListRequestsMethod$outboundSchema),
36
36
  responseStatus: z.optional(z.int()),
37
37
  statusClass: z.optional(ListRequestsStatusClass$outboundSchema),
38
38
  writesOnly: z.optional(z.boolean()),
39
+ service: z.optional(z.string()),
40
+ mcpServer: z.optional(z.string()),
41
+ tool: z.optional(z.string()),
42
+ operation: z.optional(z.string()),
39
43
  search: z.optional(z.string()),
40
44
  from: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))),
41
45
  to: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))),
@@ -9,13 +9,18 @@ export declare const RequestDetailRespondedBy: {
9
9
  };
10
10
  export type RequestDetailRespondedBy = OpenEnum<typeof RequestDetailRespondedBy>;
11
11
  export type RequestDetail = {
12
- app: string;
12
+ appName: string;
13
13
  completedAt: Date;
14
14
  durationMs: number;
15
15
  environmentId: string;
16
16
  errorCode: string | null;
17
17
  id: string;
18
+ /**
19
+ * The MCP server that the request called, as the app named it. `null` when the gateway answered, when State Machines refused the request before the app read it, or when the request called no MCP server that the environment serves.
20
+ */
21
+ mcpServer: string | null;
18
22
  method: string;
23
+ operation: string | null;
19
24
  path: string;
20
25
  query: string;
21
26
  receivedAt: Date;
@@ -23,6 +28,8 @@ export type RequestDetail = {
23
28
  respondedBy: RequestDetailRespondedBy;
24
29
  responseBytes: number | null;
25
30
  responseStatus: number;
31
+ service: string | null;
32
+ tool: string | null;
26
33
  requestBody: BodyPreview;
27
34
  requestHeaders: {
28
35
  [k: string]: string;
@@ -14,13 +14,15 @@ export const RequestDetailRespondedBy = {
14
14
  export const RequestDetailRespondedBy$inboundSchema = openEnums.inboundSchema(RequestDetailRespondedBy);
15
15
  /** @internal */
16
16
  export const RequestDetail$inboundSchema = z.object({
17
- app: types.string(),
17
+ appName: types.string(),
18
18
  completedAt: types.date(),
19
19
  durationMs: types.number(),
20
20
  environmentId: types.string(),
21
21
  errorCode: types.nullable(types.string()),
22
22
  id: types.string(),
23
+ mcpServer: types.nullable(types.string()),
23
24
  method: types.string(),
25
+ operation: types.nullable(types.string()),
24
26
  path: types.string(),
25
27
  query: types.string(),
26
28
  receivedAt: types.date(),
@@ -28,6 +30,8 @@ export const RequestDetail$inboundSchema = z.object({
28
30
  respondedBy: RequestDetailRespondedBy$inboundSchema,
29
31
  responseBytes: types.nullable(types.number()),
30
32
  responseStatus: types.number(),
33
+ service: types.nullable(types.string()),
34
+ tool: types.nullable(types.string()),
31
35
  requestBody: BodyPreview$inboundSchema,
32
36
  requestHeaders: z.record(z.string(), types.string()),
33
37
  responseBody: BodyPreview$inboundSchema,
@@ -7,6 +7,10 @@ export type Bucket = {
7
7
  serverError: number;
8
8
  success: number;
9
9
  };
10
+ export type RequestStatsService = {
11
+ count: number;
12
+ id: string;
13
+ };
10
14
  export type RequestStats = {
11
15
  buckets: Array<Bucket>;
12
16
  clientErrorCount: number;
@@ -15,6 +19,7 @@ export type RequestStats = {
15
19
  p50Ms: number | null;
16
20
  p95Ms: number | null;
17
21
  serverErrorCount: number;
22
+ services: Array<RequestStatsService>;
18
23
  successCount: number;
19
24
  to: Date;
20
25
  };
@@ -22,5 +27,8 @@ export type RequestStats = {
22
27
  export declare const Bucket$inboundSchema: z.ZodMiniType<Bucket, unknown>;
23
28
  export declare function bucketFromJSON(jsonString: string): SafeParseResult<Bucket, SDKValidationError>;
24
29
  /** @internal */
30
+ export declare const RequestStatsService$inboundSchema: z.ZodMiniType<RequestStatsService, unknown>;
31
+ export declare function requestStatsServiceFromJSON(jsonString: string): SafeParseResult<RequestStatsService, SDKValidationError>;
32
+ /** @internal */
25
33
  export declare const RequestStats$inboundSchema: z.ZodMiniType<RequestStats, unknown>;
26
34
  export declare function requestStatsFromJSON(jsonString: string): SafeParseResult<RequestStats, SDKValidationError>;
@@ -15,6 +15,14 @@ export function bucketFromJSON(jsonString) {
15
15
  return safeParse(jsonString, (x) => Bucket$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Bucket' from JSON`);
16
16
  }
17
17
  /** @internal */
18
+ export const RequestStatsService$inboundSchema = z.object({
19
+ count: types.number(),
20
+ id: types.string(),
21
+ });
22
+ export function requestStatsServiceFromJSON(jsonString) {
23
+ return safeParse(jsonString, (x) => RequestStatsService$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'RequestStatsService' from JSON`);
24
+ }
25
+ /** @internal */
18
26
  export const RequestStats$inboundSchema = z.object({
19
27
  buckets: z.array(z.lazy(() => Bucket$inboundSchema)),
20
28
  clientErrorCount: types.number(),
@@ -23,6 +31,7 @@ export const RequestStats$inboundSchema = z.object({
23
31
  p50Ms: types.nullable(types.number()),
24
32
  p95Ms: types.nullable(types.number()),
25
33
  serverErrorCount: types.number(),
34
+ services: z.array(z.lazy(() => RequestStatsService$inboundSchema)),
26
35
  successCount: types.number(),
27
36
  to: types.date(),
28
37
  });
@@ -8,13 +8,18 @@ export declare const RequestRespondedBy: {
8
8
  };
9
9
  export type RequestRespondedBy = OpenEnum<typeof RequestRespondedBy>;
10
10
  export type RequestT = {
11
- app: string;
11
+ appName: string;
12
12
  completedAt: Date;
13
13
  durationMs: number;
14
14
  environmentId: string;
15
15
  errorCode: string | null;
16
16
  id: string;
17
+ /**
18
+ * The MCP server that the request called, as the app named it. `null` when the gateway answered, when State Machines refused the request before the app read it, or when the request called no MCP server that the environment serves.
19
+ */
20
+ mcpServer: string | null;
17
21
  method: string;
22
+ operation: string | null;
18
23
  path: string;
19
24
  query: string;
20
25
  receivedAt: Date;
@@ -22,6 +27,8 @@ export type RequestT = {
22
27
  respondedBy: RequestRespondedBy;
23
28
  responseBytes: number | null;
24
29
  responseStatus: number;
30
+ service: string | null;
31
+ tool: string | null;
25
32
  };
26
33
  /** @internal */
27
34
  export declare const RequestRespondedBy$inboundSchema: z.ZodMiniType<RequestRespondedBy, unknown>;
@@ -14,13 +14,15 @@ export const RequestRespondedBy$inboundSchema = openEnums.inboundSchema(RequestR
14
14
  /** @internal */
15
15
  export const RequestT$inboundSchema = z
16
16
  .object({
17
- app: types.string(),
17
+ appName: types.string(),
18
18
  completedAt: types.date(),
19
19
  durationMs: types.number(),
20
20
  environmentId: types.string(),
21
21
  errorCode: types.nullable(types.string()),
22
22
  id: types.string(),
23
+ mcpServer: types.nullable(types.string()),
23
24
  method: types.string(),
25
+ operation: types.nullable(types.string()),
24
26
  path: types.string(),
25
27
  query: types.string(),
26
28
  receivedAt: types.date(),
@@ -28,6 +30,8 @@ export const RequestT$inboundSchema = z
28
30
  respondedBy: RequestRespondedBy$inboundSchema,
29
31
  responseBytes: types.nullable(types.number()),
30
32
  responseStatus: types.number(),
33
+ service: types.nullable(types.string()),
34
+ tool: types.nullable(types.string()),
31
35
  });
32
36
  export function requestFromJSON(jsonString) {
33
37
  return safeParse(jsonString, (x) => RequestT$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'RequestT' from JSON`);
@@ -0,0 +1,25 @@
1
+ import * as z from "zod/v4-mini";
2
+ import { OpenEnum } from "../types/enums.js";
3
+ import { Result as SafeParseResult } from "../types/fp.js";
4
+ import { SDKValidationError } from "./errors/sdk-validation-error.js";
5
+ import { McpServer } from "./mcp-server.js";
6
+ export declare const Visibility: {
7
+ readonly Public: "public";
8
+ readonly Preview: "preview";
9
+ };
10
+ export type Visibility = OpenEnum<typeof Visibility>;
11
+ export type Service = {
12
+ description: string;
13
+ id: string;
14
+ limitations: Array<string>;
15
+ name: string;
16
+ path: string;
17
+ prompt: Array<string>;
18
+ servers?: Array<McpServer> | undefined;
19
+ visibility: Visibility;
20
+ };
21
+ /** @internal */
22
+ export declare const Visibility$inboundSchema: z.ZodMiniType<Visibility, unknown>;
23
+ /** @internal */
24
+ export declare const Service$inboundSchema: z.ZodMiniType<Service, unknown>;
25
+ export declare function serviceFromJSON(jsonString: string): SafeParseResult<Service, SDKValidationError>;
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+ import * as z from "zod/v4-mini";
5
+ import { safeParse } from "../lib/schemas.js";
6
+ import * as openEnums from "../types/enums.js";
7
+ import * as types from "../types/primitives.js";
8
+ import { McpServer$inboundSchema } from "./mcp-server.js";
9
+ export const Visibility = {
10
+ Public: "public",
11
+ Preview: "preview",
12
+ };
13
+ /** @internal */
14
+ export const Visibility$inboundSchema = openEnums.inboundSchema(Visibility);
15
+ /** @internal */
16
+ export const Service$inboundSchema = z.object({
17
+ description: types.string(),
18
+ id: types.string(),
19
+ limitations: z.array(types.string()),
20
+ name: types.string(),
21
+ path: types.string(),
22
+ prompt: z.array(types.string()),
23
+ servers: types.optional(z.array(McpServer$inboundSchema)),
24
+ visibility: Visibility$inboundSchema,
25
+ });
26
+ export function serviceFromJSON(jsonString) {
27
+ return safeParse(jsonString, (x) => Service$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Service' from JSON`);
28
+ }
@@ -7,6 +7,12 @@ import { SnapshotStatus } from "./snapshot-status.js";
7
7
  export type SnapshotApp = {
8
8
  appId: string;
9
9
  name: string;
10
+ services: {
11
+ [k: string]: any;
12
+ };
13
+ setup: {
14
+ [k: string]: any;
15
+ };
10
16
  sizeBytes: number | null;
11
17
  version: string;
12
18
  versionId: string;
@@ -26,6 +32,7 @@ export type Snapshot = {
26
32
  createdBy: Principal;
27
33
  deletedAt: Date | null;
28
34
  environmentId: string;
35
+ environmentName: string | null;
29
36
  failure: Failure | null;
30
37
  id: string;
31
38
  name: string | null;
@@ -16,6 +16,8 @@ export const SnapshotApp$inboundSchema = z
16
16
  .object({
17
17
  appId: types.string(),
18
18
  name: types.string(),
19
+ services: z.record(z.string(), z.any()),
20
+ setup: z.record(z.string(), z.any()),
19
21
  sizeBytes: types.nullable(types.number()),
20
22
  version: types.string(),
21
23
  versionId: types.string(),
@@ -41,6 +43,7 @@ export const Snapshot$inboundSchema = z
41
43
  createdBy: Principal$inboundSchema,
42
44
  deletedAt: types.nullable(types.date()),
43
45
  environmentId: types.string(),
46
+ environmentName: types.nullable(types.string()),
44
47
  failure: types.nullable(z.lazy(() => Failure$inboundSchema)),
45
48
  id: types.string(),
46
49
  name: types.nullable(types.string()),
@@ -2,8 +2,8 @@ import * as z from "zod/v4-mini";
2
2
  import { OpenEnum } from "../types/enums.js";
3
3
  import { Result as SafeParseResult } from "../types/fp.js";
4
4
  import { Actor } from "./actor.js";
5
- import { Api } from "./api.js";
6
5
  import { SDKValidationError } from "./errors/sdk-validation-error.js";
6
+ import { Service } from "./service.js";
7
7
  export declare const Status: {
8
8
  readonly Published: "published";
9
9
  readonly Retired: "retired";
@@ -11,12 +11,12 @@ export declare const Status: {
11
11
  export type Status = OpenEnum<typeof Status>;
12
12
  export type Version = {
13
13
  actors: Array<Actor>;
14
- apis: Array<Api>;
15
14
  appId: string;
16
15
  id: string;
17
16
  isDefault: boolean;
18
17
  publishedAt: Date;
19
18
  retiredAt: Date | null;
19
+ services: Array<Service>;
20
20
  status: Status;
21
21
  version: string;
22
22
  };
@@ -6,7 +6,7 @@ import { safeParse } from "../lib/schemas.js";
6
6
  import * as openEnums from "../types/enums.js";
7
7
  import * as types from "../types/primitives.js";
8
8
  import { Actor$inboundSchema } from "./actor.js";
9
- import { Api$inboundSchema } from "./api.js";
9
+ import { Service$inboundSchema } from "./service.js";
10
10
  export const Status = {
11
11
  Published: "published",
12
12
  Retired: "retired",
@@ -17,12 +17,12 @@ export const Status$inboundSchema = openEnums
17
17
  /** @internal */
18
18
  export const Version$inboundSchema = z.object({
19
19
  actors: z.array(Actor$inboundSchema),
20
- apis: z.array(Api$inboundSchema),
21
20
  appId: types.string(),
22
21
  id: types.string(),
23
22
  isDefault: types.boolean(),
24
23
  publishedAt: types.date(),
25
24
  retiredAt: types.nullable(types.date()),
25
+ services: z.array(Service$inboundSchema),
26
26
  status: Status$inboundSchema,
27
27
  version: types.string(),
28
28
  });
@@ -4,6 +4,7 @@ import * as operations from "../models/operations/index.js";
4
4
  export declare class Environments extends ClientSDK {
5
5
  list(request?: operations.ListEnvironmentsRequest | undefined, options?: RequestOptions): Promise<operations.ListEnvironmentsResponse>;
6
6
  create(request: operations.CreateEnvironmentRequest, options?: RequestOptions): Promise<models.Environment>;
7
+ creators(request?: operations.ListEnvironmentCreatorsRequest | undefined, options?: RequestOptions): Promise<operations.ListEnvironmentCreatorsResponse>;
7
8
  delete(request: operations.DeleteEnvironmentRequest, options?: RequestOptions): Promise<models.Environment>;
8
9
  get(request: operations.GetEnvironmentRequest, options?: RequestOptions): Promise<models.Environment>;
9
10
  update(request: operations.UpdateEnvironmentRequest, options?: RequestOptions): Promise<models.Environment>;
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import { environmentsConnect } from "../funcs/environments-connect.js";
5
5
  import { environmentsCreate } from "../funcs/environments-create.js";
6
+ import { environmentsCreators } from "../funcs/environments-creators.js";
6
7
  import { environmentsDelete } from "../funcs/environments-delete.js";
7
8
  import { environmentsGet } from "../funcs/environments-get.js";
8
9
  import { environmentsList } from "../funcs/environments-list.js";
@@ -16,6 +17,9 @@ export class Environments extends ClientSDK {
16
17
  async create(request, options) {
17
18
  return unwrapAsync(environmentsCreate(this, request, options));
18
19
  }
20
+ async creators(request, options) {
21
+ return unwrapAsync(environmentsCreators(this, request, options));
22
+ }
19
23
  async delete(request, options) {
20
24
  return unwrapAsync(environmentsDelete(this, request, options));
21
25
  }
@@ -0,0 +1,24 @@
1
+ import * as z from "zod/v4-mini";
2
+ export type Unknown<Discriminator extends string, UnknownValue = "UNKNOWN"> = {
3
+ [K in Discriminator]: UnknownValue;
4
+ } & {
5
+ raw: unknown;
6
+ isUnknown: true;
7
+ };
8
+ export declare function isUnknown<Discriminator extends string>(value: unknown): value is Unknown<Discriminator>;
9
+ /**
10
+ * Forward-compatible discriminated union parser.
11
+ *
12
+ * If the input does not match one of the predefined options, it will be
13
+ * captured and available as `{ raw: <original input>, [discriminator]: "UNKNOWN", isUnknown: true }`.
14
+ *
15
+ * @param inputPropertyName - The discriminator property name in the input payload
16
+ * @param options - Map of discriminator values to their corresponding schemas
17
+ * @param opts - Optional configuration object
18
+ * @param opts.unknownValue - The value to use for the discriminator when the input is unknown (default: "UNKNOWN")
19
+ * @param opts.outputPropertyName - Output property name if the sanitized (camelCase) property name differs from inputPropertyName
20
+ */
21
+ export declare function discriminatedUnion<InputDiscriminator extends string, TOptions extends Readonly<Record<string, z.ZodMiniType>>, UnknownValue extends string = "UNKNOWN", OutputDiscriminator extends string = InputDiscriminator>(inputPropertyName: InputDiscriminator, options: TOptions, opts?: {
22
+ unknownValue?: UnknownValue;
23
+ outputPropertyName?: OutputDiscriminator;
24
+ }): z.ZodMiniType<z.output<TOptions[keyof TOptions]> | Unknown<OutputDiscriminator, UnknownValue>, unknown>;
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+ import * as z from "zod/v4-mini";
5
+ import { startCountingDefaultToZeroValue } from "./default-to-zero-value.js";
6
+ import { startCountingUnrecognized } from "./unrecognized.js";
7
+ const UNKNOWN = Symbol("UNKNOWN");
8
+ export function isUnknown(value) {
9
+ return typeof value === "object" && value !== null && UNKNOWN in value;
10
+ }
11
+ /**
12
+ * Forward-compatible discriminated union parser.
13
+ *
14
+ * If the input does not match one of the predefined options, it will be
15
+ * captured and available as `{ raw: <original input>, [discriminator]: "UNKNOWN", isUnknown: true }`.
16
+ *
17
+ * @param inputPropertyName - The discriminator property name in the input payload
18
+ * @param options - Map of discriminator values to their corresponding schemas
19
+ * @param opts - Optional configuration object
20
+ * @param opts.unknownValue - The value to use for the discriminator when the input is unknown (default: "UNKNOWN")
21
+ * @param opts.outputPropertyName - Output property name if the sanitized (camelCase) property name differs from inputPropertyName
22
+ */
23
+ export function discriminatedUnion(inputPropertyName, options, opts = {}) {
24
+ const { unknownValue = "UNKNOWN", outputPropertyName } = opts;
25
+ return z.pipe(z.unknown(), z.transform((input) => {
26
+ const fallback = Object.defineProperties({
27
+ raw: input,
28
+ [outputPropertyName ?? inputPropertyName]: unknownValue,
29
+ isUnknown: true,
30
+ }, { [UNKNOWN]: { value: true, enumerable: false, configurable: false } });
31
+ const isObject = typeof input === "object" && input !== null;
32
+ if (!isObject)
33
+ return fallback;
34
+ const discriminator = input[inputPropertyName];
35
+ if (typeof discriminator !== "string")
36
+ return fallback;
37
+ if (!(discriminator in options))
38
+ return fallback;
39
+ const schema = options[discriminator];
40
+ if (!schema)
41
+ return fallback;
42
+ // Start counters before parsing to track nested unrecognized/zeroDefault values
43
+ const unrecognizedCtr = startCountingUnrecognized();
44
+ const zeroDefaultCtr = startCountingDefaultToZeroValue();
45
+ const result = z.safeParse(schema, input);
46
+ if (!result.success) {
47
+ // Parse failed - don't propagate any counts from the failed attempt
48
+ unrecognizedCtr.end(0);
49
+ zeroDefaultCtr.end(0);
50
+ return fallback;
51
+ }
52
+ // Parse succeeded - propagate the actual counts
53
+ unrecognizedCtr.end();
54
+ zeroDefaultCtr.end();
55
+ if (outputPropertyName) {
56
+ result.data[outputPropertyName] = discriminator;
57
+ }
58
+ return result.data;
59
+ }));
60
+ }
@@ -4,6 +4,7 @@
4
4
  // Not needed if lax mode
5
5
  import * as z from "zod/v4-mini";
6
6
  import { startCountingDefaultToZeroValue } from "./default-to-zero-value.js";
7
+ import { isUnknown as isDiscriminatedUnionUnknown } from "./discriminated-union.js";
7
8
  import { RFCDate } from "./rfcdate.js";
8
9
  import { startCountingUnrecognized } from "./unrecognized.js";
9
10
  /**
@@ -87,7 +88,7 @@ function countFieldsRecursive(parsed) {
87
88
  let index = 0;
88
89
  while (index < queue.length) {
89
90
  const value = queue[index++];
90
- if (value === undefined) {
91
+ if (value === undefined || isDiscriminatedUnionUnknown(value)) {
91
92
  continue;
92
93
  }
93
94
  // Check if it's a primitive value