@automate.ax/api-contract 0.84.0 → 0.86.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.
- package/dist/automation.d.ts +5 -3
- package/dist/automation.js +3 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.js +2 -0
- package/dist/events/webflow.d.ts +6 -0
- package/dist/events/webflow.js +16 -0
- package/dist/execution-data.d.ts +6 -6
- package/dist/execution-data.js +1 -1
- package/dist/index.d.ts +51 -12
- package/dist/index.js +1 -1
- package/dist/runtime.d.ts +168 -2
- package/dist/runtime.js +113 -3
- package/package.json +4 -4
- package/src/automation.ts +3 -0
- package/src/events/index.ts +2 -0
- package/src/events/webflow.ts +18 -0
- package/src/execution-data.ts +1 -1
- package/src/index.ts +12 -1
- package/src/runtime.ts +152 -5
package/src/runtime.ts
CHANGED
|
@@ -1,24 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
encodableSchema,
|
|
3
|
+
isSensitivityMask,
|
|
4
|
+
type SensitivityMask,
|
|
5
|
+
} from "@automate.ax/codec"
|
|
6
|
+
import type { GatewayImageModelId, GatewayModelId } from "@ai-sdk/gateway"
|
|
3
7
|
import { oc } from "@orpc/contract"
|
|
4
8
|
import stableStringify from "fast-json-stable-stringify"
|
|
5
9
|
import * as z from "zod"
|
|
6
10
|
import { automationErrorSchema } from "./errors"
|
|
7
11
|
|
|
8
|
-
export type { GatewayModelId } from "@ai-sdk/gateway"
|
|
12
|
+
export type { GatewayImageModelId, GatewayModelId } from "@ai-sdk/gateway"
|
|
9
13
|
|
|
10
14
|
/** Default model used by the platform Vercel AI Gateway account. */
|
|
11
15
|
export const DEFAULT_GATEWAY_MODEL_ID =
|
|
12
16
|
"openai/gpt-4.1-nano" satisfies GatewayModelId
|
|
17
|
+
|
|
18
|
+
/** Default image model used by the platform Vercel AI Gateway account. */
|
|
19
|
+
export const DEFAULT_GATEWAY_IMAGE_MODEL_ID =
|
|
20
|
+
"bfl/flux-2-flex" satisfies GatewayImageModelId
|
|
13
21
|
export const AUTOMATION_INVOCATION_DEFAULT_ENTRYPOINT = "default"
|
|
14
22
|
export const AUTOMATION_INVOCATION_RESERVED_ENTRYPOINT_PREFIX = "__$"
|
|
15
23
|
export const AUTOMATION_DELAY_ENTRYPOINT_PREFIX =
|
|
16
24
|
`${AUTOMATION_INVOCATION_RESERVED_ENTRYPOINT_PREFIX}delay:` as const
|
|
25
|
+
export const AUTOMATION_IMAGE_GENERATION_ENTRYPOINT_PREFIX =
|
|
26
|
+
`${AUTOMATION_INVOCATION_RESERVED_ENTRYPOINT_PREFIX}generate-image:` as const
|
|
17
27
|
export const CALLBACK_PROTECTION_QUERY_PARAMETER = "_axCallback"
|
|
18
28
|
export const AUTOMATION_LOG_MAX_ENTRIES = 1_000
|
|
19
29
|
export const AUTOMATION_TRACE_MAX_SPANS = 250
|
|
20
30
|
export const AUTOMATION_OBSERVABILITY_MAX_FIELDS = 64
|
|
21
31
|
export const AUTOMATION_OBSERVABILITY_MAX_ENCODED_BYTES = 64 * 1_024
|
|
32
|
+
|
|
33
|
+
const RUNTIME_BLOB_JSON_SERIALIZER_TYPE = 8
|
|
34
|
+
|
|
35
|
+
/** Blob wrappers that should use oRPC's native multipart serialization. */
|
|
36
|
+
const runtimeBlobTransportValues = new WeakSet<Blob>()
|
|
37
|
+
|
|
38
|
+
/** Preserves Blob media types while oRPC carries the bytes as multipart data. */
|
|
39
|
+
export const runtimeBlobJsonSerializer = {
|
|
40
|
+
type: RUNTIME_BLOB_JSON_SERIALIZER_TYPE,
|
|
41
|
+
condition: (value: unknown) =>
|
|
42
|
+
value instanceof Blob && !runtimeBlobTransportValues.has(value),
|
|
43
|
+
serialize(value: Blob) {
|
|
44
|
+
const transportValue = new Blob([value])
|
|
45
|
+
runtimeBlobTransportValues.add(transportValue)
|
|
46
|
+
return { transportValue, type: value.type }
|
|
47
|
+
},
|
|
48
|
+
deserialize(value: unknown) {
|
|
49
|
+
const { transportValue, type } = z
|
|
50
|
+
.object({ transportValue: z.instanceof(Blob), type: z.string() })
|
|
51
|
+
.parse(value)
|
|
52
|
+
return new Blob([transportValue], { type })
|
|
53
|
+
},
|
|
54
|
+
}
|
|
22
55
|
export const AUTOMATION_LOG_MAX_MESSAGE_LENGTH = 16_384
|
|
23
56
|
export const AUTOMATION_TRACE_MAX_NAME_LENGTH = 256
|
|
24
57
|
|
|
@@ -42,6 +75,12 @@ const TRACE_SPAN_INDEX_SCHEMA = z
|
|
|
42
75
|
.min(0)
|
|
43
76
|
.max(AUTOMATION_TRACE_MAX_SPANS - 1)
|
|
44
77
|
|
|
78
|
+
/** Runtime-validated structural policy for author-visible value projection. */
|
|
79
|
+
export const sensitivityMaskSchema = z.custom<SensitivityMask>(
|
|
80
|
+
isSensitivityMask,
|
|
81
|
+
{ message: "Invalid structural sensitivity mask" },
|
|
82
|
+
)
|
|
83
|
+
|
|
45
84
|
const AUTOMATION_INVOCATION_RUN_AT_SCHEMA = z.union([
|
|
46
85
|
z.date(),
|
|
47
86
|
z.string().min(1),
|
|
@@ -169,6 +208,7 @@ const ACTION_INVOCATION_BASE_SCHEMA = z.object({
|
|
|
169
208
|
eventDependencyIds: z.string().array(),
|
|
170
209
|
inputHash: z.string(),
|
|
171
210
|
name: z.string(),
|
|
211
|
+
outputSensitivity: sensitivityMaskSchema.nullable().optional(),
|
|
172
212
|
scopePath: HOOK_SCOPE_PATH_SCHEMA,
|
|
173
213
|
signalDependencyIds: z.string().array(),
|
|
174
214
|
slot: z.number().int().nonnegative(),
|
|
@@ -445,6 +485,7 @@ const ACTION_VALUE_OUTCOME_SCHEMA = z.union([
|
|
|
445
485
|
}),
|
|
446
486
|
ACTION_VALUE_OUTCOME_BASE_SCHEMA.extend({
|
|
447
487
|
output: encodableSchema,
|
|
488
|
+
outputSensitivity: sensitivityMaskSchema.nullable().optional(),
|
|
448
489
|
status: z.literal("succeeded"),
|
|
449
490
|
}),
|
|
450
491
|
])
|
|
@@ -540,7 +581,7 @@ const TARGET_ACTION_SCHEMA = z.union([
|
|
|
540
581
|
}),
|
|
541
582
|
])
|
|
542
583
|
|
|
543
|
-
const
|
|
584
|
+
const AI_WARNING_SCHEMA = z.discriminatedUnion("type", [
|
|
544
585
|
z.object({
|
|
545
586
|
details: z.string().optional(),
|
|
546
587
|
feature: z.string(),
|
|
@@ -648,7 +689,7 @@ export const generationResultSchema = z.object({
|
|
|
648
689
|
}),
|
|
649
690
|
text: z.string(),
|
|
650
691
|
usage: GENERATION_USAGE_SCHEMA,
|
|
651
|
-
warnings:
|
|
692
|
+
warnings: AI_WARNING_SCHEMA.array().optional(),
|
|
652
693
|
})
|
|
653
694
|
|
|
654
695
|
export type GenerationInput = z.output<typeof generationInputSchema>
|
|
@@ -675,6 +716,106 @@ export type RuntimeGenerationInput = z.output<
|
|
|
675
716
|
typeof RUNTIME_GENERATION_INPUT_SCHEMA
|
|
676
717
|
>
|
|
677
718
|
|
|
719
|
+
const IMAGE_DATA_CONTENT_SCHEMA = z.union([
|
|
720
|
+
z.string(),
|
|
721
|
+
z.custom<Uint8Array>((value) => value instanceof Uint8Array),
|
|
722
|
+
z.instanceof(ArrayBuffer),
|
|
723
|
+
z.instanceof(Blob),
|
|
724
|
+
])
|
|
725
|
+
|
|
726
|
+
const IMAGE_GENERATION_PROMPT_SCHEMA = z.union([
|
|
727
|
+
z.string(),
|
|
728
|
+
z.object({
|
|
729
|
+
images: IMAGE_DATA_CONTENT_SCHEMA.array(),
|
|
730
|
+
mask: IMAGE_DATA_CONTENT_SCHEMA.optional(),
|
|
731
|
+
text: z.string().optional(),
|
|
732
|
+
}),
|
|
733
|
+
])
|
|
734
|
+
|
|
735
|
+
const GATEWAY_IMAGE_MODEL_ID_SCHEMA = z
|
|
736
|
+
.custom<GatewayImageModelId>(
|
|
737
|
+
(value) => typeof value === "string" && value.length > 0,
|
|
738
|
+
"Model must be a nonempty AI Gateway image model ID.",
|
|
739
|
+
)
|
|
740
|
+
.default(DEFAULT_GATEWAY_IMAGE_MODEL_ID)
|
|
741
|
+
|
|
742
|
+
/** Shared options accepted by the built-in image-generation action. */
|
|
743
|
+
export const imageGenerationInputSchema = z.object({
|
|
744
|
+
aspectRatio: z
|
|
745
|
+
.custom<`${number}:${number}`>((value) => typeof value === "string" && /^\d+(?:\.\d+)?:\d+(?:\.\d+)?$/.test(value), "Aspect ratio must use the format {width}:{height}.")
|
|
746
|
+
.optional(),
|
|
747
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
748
|
+
maxImagesPerCall: z.number().int().positive().optional(),
|
|
749
|
+
maxRetries: z.number().int().nonnegative().optional(),
|
|
750
|
+
model: GATEWAY_IMAGE_MODEL_ID_SCHEMA,
|
|
751
|
+
n: z.number().int().positive().optional(),
|
|
752
|
+
prompt: IMAGE_GENERATION_PROMPT_SCHEMA,
|
|
753
|
+
providerOptions: z
|
|
754
|
+
.record(z.string(), z.record(z.string(), z.json()))
|
|
755
|
+
.optional(),
|
|
756
|
+
seed: z.number().int().optional(),
|
|
757
|
+
size: z
|
|
758
|
+
.custom<`${number}x${number}`>((value) => typeof value === "string" && /^\d+x\d+$/.test(value), "Size must use the format {width}x{height}.")
|
|
759
|
+
.optional(),
|
|
760
|
+
})
|
|
761
|
+
|
|
762
|
+
const IMAGE_PROVIDER_METADATA_SCHEMA = z
|
|
763
|
+
.object({ images: z.json().array().optional() })
|
|
764
|
+
.catchall(z.json())
|
|
765
|
+
|
|
766
|
+
/** Serializable subset of the AI SDK image-generation result. */
|
|
767
|
+
export const imageGenerationResultSchema = z.object({
|
|
768
|
+
images: z.instanceof(Blob).array().min(1),
|
|
769
|
+
providerMetadata: z.record(z.string(), IMAGE_PROVIDER_METADATA_SCHEMA),
|
|
770
|
+
responses: z
|
|
771
|
+
.object({
|
|
772
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
773
|
+
modelId: z.string(),
|
|
774
|
+
timestamp: z.iso.datetime(),
|
|
775
|
+
})
|
|
776
|
+
.array(),
|
|
777
|
+
usage: z.object({
|
|
778
|
+
inputTokens: z.number().optional(),
|
|
779
|
+
outputTokens: z.number().optional(),
|
|
780
|
+
totalTokens: z.number().optional(),
|
|
781
|
+
}),
|
|
782
|
+
warnings: AI_WARNING_SCHEMA.array(),
|
|
783
|
+
})
|
|
784
|
+
|
|
785
|
+
/** Internal terminal delivery emitted by a platform image-generation job. */
|
|
786
|
+
export const imageGenerationCompletionSchema = z.object({
|
|
787
|
+
key: z.string().min(1),
|
|
788
|
+
outcome: z.discriminatedUnion("status", [
|
|
789
|
+
z.object({
|
|
790
|
+
result: imageGenerationResultSchema,
|
|
791
|
+
status: z.literal("succeeded"),
|
|
792
|
+
}),
|
|
793
|
+
z.object({ failure: automationErrorSchema, status: z.literal("failed") }),
|
|
794
|
+
]),
|
|
795
|
+
})
|
|
796
|
+
|
|
797
|
+
/** Starts platform image generation for one reserved internal entrypoint. */
|
|
798
|
+
export const platformImageGenerationInputSchema =
|
|
799
|
+
imageGenerationInputSchema.extend({
|
|
800
|
+
entrypoint: z
|
|
801
|
+
.string()
|
|
802
|
+
.startsWith(AUTOMATION_IMAGE_GENERATION_ENTRYPOINT_PREFIX),
|
|
803
|
+
})
|
|
804
|
+
|
|
805
|
+
/** Durable identity returned after platform image generation is queued. */
|
|
806
|
+
export const platformImageGenerationStartSchema = z.object({
|
|
807
|
+
key: z.string().min(1),
|
|
808
|
+
})
|
|
809
|
+
|
|
810
|
+
export type ImageGenerationInput = z.output<typeof imageGenerationInputSchema>
|
|
811
|
+
export type ImageGenerationResult = z.output<typeof imageGenerationResultSchema>
|
|
812
|
+
export type ImageGenerationCompletion = z.output<
|
|
813
|
+
typeof imageGenerationCompletionSchema
|
|
814
|
+
>
|
|
815
|
+
export type PlatformImageGenerationInput = z.output<
|
|
816
|
+
typeof platformImageGenerationInputSchema
|
|
817
|
+
>
|
|
818
|
+
|
|
678
819
|
/**
|
|
679
820
|
* Hashes one coordinator definition exactly as the runtime stores it.
|
|
680
821
|
*
|
|
@@ -766,6 +907,9 @@ export const runtimeContract = {
|
|
|
766
907
|
generate: oc
|
|
767
908
|
.input(RUNTIME_GENERATION_INPUT_SCHEMA)
|
|
768
909
|
.output(generationResultSchema),
|
|
910
|
+
startImageGeneration: oc
|
|
911
|
+
.input(platformImageGenerationInputSchema)
|
|
912
|
+
.output(platformImageGenerationStartSchema),
|
|
769
913
|
createCallbackToken: oc
|
|
770
914
|
.input(z.object({ endpointKey: z.string().min(1) }))
|
|
771
915
|
.output(z.string()),
|
|
@@ -809,6 +953,7 @@ export const runtimeContract = {
|
|
|
809
953
|
type: z.string().min(1),
|
|
810
954
|
}),
|
|
811
955
|
outputIndex: z.number().int().nonnegative(),
|
|
956
|
+
sensitivity: sensitivityMaskSchema.optional(),
|
|
812
957
|
}),
|
|
813
958
|
)
|
|
814
959
|
.output(z.void()),
|
|
@@ -819,6 +964,7 @@ export const runtimeContract = {
|
|
|
819
964
|
level: z.enum(["debug", "info", "warn", "error"]),
|
|
820
965
|
logIndex: LOG_INDEX_SCHEMA,
|
|
821
966
|
message: z.string().min(1).max(AUTOMATION_LOG_MAX_MESSAGE_LENGTH),
|
|
967
|
+
sensitivity: sensitivityMaskSchema.optional(),
|
|
822
968
|
spanIndex: TRACE_SPAN_INDEX_SCHEMA.optional(),
|
|
823
969
|
timestamp: z.date(),
|
|
824
970
|
}),
|
|
@@ -829,6 +975,7 @@ export const runtimeContract = {
|
|
|
829
975
|
z.object({
|
|
830
976
|
attributes: OBSERVABILITY_FIELDS_SCHEMA.optional(),
|
|
831
977
|
name: z.string().min(1).max(AUTOMATION_TRACE_MAX_NAME_LENGTH),
|
|
978
|
+
sensitivity: sensitivityMaskSchema.optional(),
|
|
832
979
|
parentSpanIndex: TRACE_SPAN_INDEX_SCHEMA.optional(),
|
|
833
980
|
spanIndex: TRACE_SPAN_INDEX_SCHEMA,
|
|
834
981
|
startedAt: z.date(),
|