transloadit 4.7.3 → 4.7.6
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/README.md +897 -5
- package/dist/Transloadit.d.ts +13 -3
- package/dist/Transloadit.d.ts.map +1 -1
- package/dist/Transloadit.js +22 -2
- package/dist/Transloadit.js.map +1 -1
- package/dist/alphalib/types/assembliesGet.d.ts +5 -0
- package/dist/alphalib/types/assembliesGet.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyReplay.d.ts +5 -0
- package/dist/alphalib/types/assemblyReplay.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyReplayNotification.d.ts +5 -0
- package/dist/alphalib/types/assemblyReplayNotification.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyStatus.d.ts +25 -25
- package/dist/alphalib/types/assemblyStatus.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyStatus.js +4 -1
- package/dist/alphalib/types/assemblyStatus.js.map +1 -1
- package/dist/alphalib/types/bill.d.ts +5 -0
- package/dist/alphalib/types/bill.d.ts.map +1 -1
- package/dist/alphalib/types/builtinTemplates.d.ts +83 -0
- package/dist/alphalib/types/builtinTemplates.d.ts.map +1 -0
- package/dist/alphalib/types/builtinTemplates.js +19 -0
- package/dist/alphalib/types/builtinTemplates.js.map +1 -0
- package/dist/alphalib/types/robots/ai-chat.d.ts.map +1 -1
- package/dist/alphalib/types/robots/ai-chat.js +1 -0
- package/dist/alphalib/types/robots/ai-chat.js.map +1 -1
- package/dist/alphalib/types/skillFrontmatter.d.ts +29 -0
- package/dist/alphalib/types/skillFrontmatter.d.ts.map +1 -0
- package/dist/alphalib/types/skillFrontmatter.js +19 -0
- package/dist/alphalib/types/skillFrontmatter.js.map +1 -0
- package/dist/alphalib/types/template.d.ts +36 -0
- package/dist/alphalib/types/template.d.ts.map +1 -1
- package/dist/alphalib/types/template.js +10 -0
- package/dist/alphalib/types/template.js.map +1 -1
- package/dist/alphalib/types/templateCredential.d.ts +10 -0
- package/dist/alphalib/types/templateCredential.d.ts.map +1 -1
- package/dist/bearerToken.d.ts +31 -0
- package/dist/bearerToken.d.ts.map +1 -0
- package/dist/bearerToken.js +158 -0
- package/dist/bearerToken.js.map +1 -0
- package/dist/cli/commands/assemblies.d.ts +8 -2
- package/dist/cli/commands/assemblies.d.ts.map +1 -1
- package/dist/cli/commands/assemblies.js +566 -411
- package/dist/cli/commands/assemblies.js.map +1 -1
- package/dist/cli/commands/auth.d.ts +1 -4
- package/dist/cli/commands/auth.d.ts.map +1 -1
- package/dist/cli/commands/auth.js +7 -123
- package/dist/cli/commands/auth.js.map +1 -1
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +5 -0
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/templates.d.ts.map +1 -1
- package/dist/cli/commands/templates.js +4 -14
- package/dist/cli/commands/templates.js.map +1 -1
- package/dist/cli/fileProcessingOptions.d.ts +35 -0
- package/dist/cli/fileProcessingOptions.d.ts.map +1 -0
- package/dist/cli/fileProcessingOptions.js +182 -0
- package/dist/cli/fileProcessingOptions.js.map +1 -0
- package/dist/cli/generateIntentDocs.d.ts +2 -0
- package/dist/cli/generateIntentDocs.d.ts.map +1 -0
- package/dist/cli/generateIntentDocs.js +321 -0
- package/dist/cli/generateIntentDocs.js.map +1 -0
- package/dist/cli/intentCommandSpecs.d.ts +36 -0
- package/dist/cli/intentCommandSpecs.d.ts.map +1 -0
- package/dist/cli/intentCommandSpecs.js +181 -0
- package/dist/cli/intentCommandSpecs.js.map +1 -0
- package/dist/cli/intentCommands.d.ts +13 -0
- package/dist/cli/intentCommands.d.ts.map +1 -0
- package/dist/cli/intentCommands.js +368 -0
- package/dist/cli/intentCommands.js.map +1 -0
- package/dist/cli/intentFields.d.ts +25 -0
- package/dist/cli/intentFields.d.ts.map +1 -0
- package/dist/cli/intentFields.js +298 -0
- package/dist/cli/intentFields.js.map +1 -0
- package/dist/cli/intentInputPolicy.d.ts +10 -0
- package/dist/cli/intentInputPolicy.d.ts.map +1 -0
- package/dist/cli/intentInputPolicy.js +2 -0
- package/dist/cli/intentInputPolicy.js.map +1 -0
- package/dist/cli/intentRuntime.d.ts +114 -0
- package/dist/cli/intentRuntime.d.ts.map +1 -0
- package/dist/cli/intentRuntime.js +464 -0
- package/dist/cli/intentRuntime.js.map +1 -0
- package/dist/cli/resultFiles.d.ts +19 -0
- package/dist/cli/resultFiles.d.ts.map +1 -0
- package/dist/cli/resultFiles.js +66 -0
- package/dist/cli/resultFiles.js.map +1 -0
- package/dist/cli/resultUrls.d.ts +19 -0
- package/dist/cli/resultUrls.d.ts.map +1 -0
- package/dist/cli/resultUrls.js +36 -0
- package/dist/cli/resultUrls.js.map +1 -0
- package/dist/cli/semanticIntents/imageDescribe.d.ts +43 -0
- package/dist/cli/semanticIntents/imageDescribe.d.ts.map +1 -0
- package/dist/cli/semanticIntents/imageDescribe.js +188 -0
- package/dist/cli/semanticIntents/imageDescribe.js.map +1 -0
- package/dist/cli/semanticIntents/index.d.ts +18 -0
- package/dist/cli/semanticIntents/index.d.ts.map +1 -0
- package/dist/cli/semanticIntents/index.js +18 -0
- package/dist/cli/semanticIntents/index.js.map +1 -0
- package/dist/cli/semanticIntents/markdownPdf.d.ts +4 -0
- package/dist/cli/semanticIntents/markdownPdf.d.ts.map +1 -0
- package/dist/cli/semanticIntents/markdownPdf.js +93 -0
- package/dist/cli/semanticIntents/markdownPdf.js.map +1 -0
- package/dist/cli/semanticIntents/parsing.d.ts +11 -0
- package/dist/cli/semanticIntents/parsing.d.ts.map +1 -0
- package/dist/cli/semanticIntents/parsing.js +29 -0
- package/dist/cli/semanticIntents/parsing.js.map +1 -0
- package/dist/cli/stepsInput.d.ts +4 -0
- package/dist/cli/stepsInput.d.ts.map +1 -0
- package/dist/cli/stepsInput.js +23 -0
- package/dist/cli/stepsInput.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +5 -4
- package/dist/cli.js.map +1 -1
- package/dist/ensureUniqueCounter.d.ts +8 -0
- package/dist/ensureUniqueCounter.d.ts.map +1 -0
- package/dist/ensureUniqueCounter.js +48 -0
- package/dist/ensureUniqueCounter.js.map +1 -0
- package/dist/inputFiles.d.ts +9 -0
- package/dist/inputFiles.d.ts.map +1 -1
- package/dist/inputFiles.js +177 -26
- package/dist/inputFiles.js.map +1 -1
- package/dist/robots.js +1 -1
- package/dist/robots.js.map +1 -1
- package/package.json +9 -7
- package/src/Transloadit.ts +35 -3
- package/src/alphalib/types/assemblyStatus.ts +4 -1
- package/src/alphalib/types/builtinTemplates.ts +24 -0
- package/src/alphalib/types/robots/ai-chat.ts +1 -0
- package/src/alphalib/types/skillFrontmatter.ts +24 -0
- package/src/alphalib/types/template.ts +14 -0
- package/src/bearerToken.ts +208 -0
- package/src/cli/commands/assemblies.ts +825 -505
- package/src/cli/commands/auth.ts +9 -151
- package/src/cli/commands/index.ts +6 -3
- package/src/cli/commands/templates.ts +6 -17
- package/src/cli/fileProcessingOptions.ts +294 -0
- package/src/cli/generateIntentDocs.ts +419 -0
- package/src/cli/intentCommandSpecs.ts +282 -0
- package/src/cli/intentCommands.ts +525 -0
- package/src/cli/intentFields.ts +403 -0
- package/src/cli/intentInputPolicy.ts +11 -0
- package/src/cli/intentRuntime.ts +734 -0
- package/src/cli/resultFiles.ts +105 -0
- package/src/cli/resultUrls.ts +72 -0
- package/src/cli/semanticIntents/imageDescribe.ts +254 -0
- package/src/cli/semanticIntents/index.ts +48 -0
- package/src/cli/semanticIntents/markdownPdf.ts +120 -0
- package/src/cli/semanticIntents/parsing.ts +56 -0
- package/src/cli/stepsInput.ts +32 -0
- package/src/cli.ts +5 -4
- package/src/ensureUniqueCounter.ts +75 -0
- package/src/inputFiles.ts +277 -26
- package/src/robots.ts +1 -1
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { Option } from 'clipanion'
|
|
2
|
+
import * as t from 'typanion'
|
|
3
|
+
import type { z } from 'zod'
|
|
4
|
+
import {
|
|
5
|
+
ZodArray,
|
|
6
|
+
ZodBoolean,
|
|
7
|
+
ZodDefault,
|
|
8
|
+
ZodEffects,
|
|
9
|
+
ZodEnum,
|
|
10
|
+
ZodLiteral,
|
|
11
|
+
ZodNullable,
|
|
12
|
+
ZodNumber,
|
|
13
|
+
ZodObject,
|
|
14
|
+
ZodOptional,
|
|
15
|
+
ZodString,
|
|
16
|
+
ZodUnion,
|
|
17
|
+
} from 'zod'
|
|
18
|
+
|
|
19
|
+
export type IntentFieldKind = 'auto' | 'boolean' | 'json' | 'number' | 'string' | 'string-array'
|
|
20
|
+
|
|
21
|
+
export interface IntentFieldSpec {
|
|
22
|
+
kind: IntentFieldKind
|
|
23
|
+
name: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface IntentOptionLike extends IntentFieldSpec {
|
|
27
|
+
description?: string
|
|
28
|
+
optionFlags: string
|
|
29
|
+
required?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function unwrapIntentSchema(input: unknown): { required: boolean; schema: unknown } {
|
|
33
|
+
let schema = input
|
|
34
|
+
let required = true
|
|
35
|
+
|
|
36
|
+
while (true) {
|
|
37
|
+
if (schema instanceof ZodEffects) {
|
|
38
|
+
schema = schema._def.schema
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (schema instanceof ZodOptional) {
|
|
43
|
+
required = false
|
|
44
|
+
schema = schema.unwrap()
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (schema instanceof ZodDefault) {
|
|
49
|
+
required = false
|
|
50
|
+
schema = schema.removeDefault()
|
|
51
|
+
continue
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (schema instanceof ZodNullable) {
|
|
55
|
+
required = false
|
|
56
|
+
schema = schema.unwrap()
|
|
57
|
+
continue
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return { required, schema }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function inferIntentFieldKind(schema: unknown): IntentFieldKind {
|
|
65
|
+
const unwrappedSchema = unwrapIntentSchema(schema).schema
|
|
66
|
+
|
|
67
|
+
if (unwrappedSchema instanceof ZodString || unwrappedSchema instanceof ZodEnum) {
|
|
68
|
+
return 'string'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (unwrappedSchema instanceof ZodNumber) {
|
|
72
|
+
return 'number'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (unwrappedSchema instanceof ZodBoolean) {
|
|
76
|
+
return 'boolean'
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (unwrappedSchema instanceof ZodLiteral) {
|
|
80
|
+
if (typeof unwrappedSchema.value === 'number') return 'number'
|
|
81
|
+
if (typeof unwrappedSchema.value === 'boolean') return 'boolean'
|
|
82
|
+
return 'string'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (unwrappedSchema instanceof ZodArray) {
|
|
86
|
+
const elementKind = inferIntentFieldKind(unwrappedSchema.element)
|
|
87
|
+
if (elementKind === 'string') {
|
|
88
|
+
return 'string-array'
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return 'json'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (unwrappedSchema instanceof ZodObject) {
|
|
95
|
+
return 'json'
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (unwrappedSchema instanceof ZodUnion) {
|
|
99
|
+
const optionKinds = Array.from(
|
|
100
|
+
new Set(unwrappedSchema._def.options.map((option: unknown) => inferIntentFieldKind(option))),
|
|
101
|
+
) as IntentFieldKind[]
|
|
102
|
+
if (
|
|
103
|
+
optionKinds.length === 2 &&
|
|
104
|
+
optionKinds.includes('string') &&
|
|
105
|
+
optionKinds.includes('string-array')
|
|
106
|
+
) {
|
|
107
|
+
return 'string-array'
|
|
108
|
+
}
|
|
109
|
+
if (optionKinds.length === 1) {
|
|
110
|
+
const [kind] = optionKinds
|
|
111
|
+
if (kind != null) return kind
|
|
112
|
+
}
|
|
113
|
+
return 'auto'
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
throw new Error('Unsupported schema type')
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function createIntentOption(fieldDefinition: IntentOptionLike): unknown {
|
|
120
|
+
const { description, kind, optionFlags, required } = fieldDefinition
|
|
121
|
+
|
|
122
|
+
if (kind === 'boolean') {
|
|
123
|
+
return Option.Boolean(optionFlags, {
|
|
124
|
+
description,
|
|
125
|
+
required,
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (kind === 'number') {
|
|
130
|
+
return Option.String(optionFlags, {
|
|
131
|
+
description,
|
|
132
|
+
required,
|
|
133
|
+
validator: t.isNumber(),
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (kind === 'string-array') {
|
|
138
|
+
return Option.Array(optionFlags, {
|
|
139
|
+
description,
|
|
140
|
+
required,
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return Option.String(optionFlags, {
|
|
145
|
+
description,
|
|
146
|
+
required,
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function inferSchemaExampleValue(schema: unknown): string | null {
|
|
151
|
+
const unwrappedSchema = unwrapIntentSchema(schema).schema
|
|
152
|
+
|
|
153
|
+
if (unwrappedSchema instanceof ZodLiteral) {
|
|
154
|
+
return String(unwrappedSchema.value)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (unwrappedSchema instanceof ZodEnum) {
|
|
158
|
+
return unwrappedSchema.options[0] ?? null
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (unwrappedSchema instanceof ZodUnion) {
|
|
162
|
+
for (const option of unwrappedSchema._def.options) {
|
|
163
|
+
const exampleValue = inferSchemaExampleValue(option)
|
|
164
|
+
if (exampleValue != null) {
|
|
165
|
+
return exampleValue
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return null
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function parseStringArrayValue(raw: unknown): string[] {
|
|
174
|
+
const addNormalizedValues = (source: string[], value: string): void => {
|
|
175
|
+
source.push(
|
|
176
|
+
...value
|
|
177
|
+
.split(',')
|
|
178
|
+
.map((part) => part.trim())
|
|
179
|
+
.filter(Boolean),
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const normalizeJsonArray = (value: string): string[] | null => {
|
|
184
|
+
const trimmed = value.trim()
|
|
185
|
+
if (!trimmed.startsWith('[')) {
|
|
186
|
+
return null
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
let parsedJson: unknown
|
|
190
|
+
try {
|
|
191
|
+
parsedJson = JSON.parse(trimmed)
|
|
192
|
+
} catch {
|
|
193
|
+
throw new Error(`Expected valid JSON but received "${value}"`)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (!Array.isArray(parsedJson) || !parsedJson.every((item) => typeof item === 'string')) {
|
|
197
|
+
throw new Error(`Expected an array of strings but received "${value}"`)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return parsedJson
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const values = Array.isArray(raw) ? raw : [raw]
|
|
204
|
+
const normalizedValues: string[] = []
|
|
205
|
+
for (const value of values) {
|
|
206
|
+
if (typeof value !== 'string') {
|
|
207
|
+
normalizedValues.push(String(value))
|
|
208
|
+
continue
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const parsedJson = normalizeJsonArray(value)
|
|
212
|
+
if (parsedJson != null) {
|
|
213
|
+
normalizedValues.push(...parsedJson)
|
|
214
|
+
continue
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
addNormalizedValues(normalizedValues, value)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return normalizedValues
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function pickPreferredExampleValue(name: string, candidates: readonly string[]): string | null {
|
|
224
|
+
if (candidates.length === 0) {
|
|
225
|
+
return null
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (name === 'format') {
|
|
229
|
+
const preferredFormats = ['pdf', 'zip', 'jpg', 'png', 'mp3']
|
|
230
|
+
for (const preferredFormat of preferredFormats) {
|
|
231
|
+
if (candidates.includes(preferredFormat)) {
|
|
232
|
+
return preferredFormat
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return candidates[0] ?? null
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function inferIntentExampleValue({
|
|
241
|
+
kind,
|
|
242
|
+
name,
|
|
243
|
+
schema,
|
|
244
|
+
}: {
|
|
245
|
+
kind: IntentFieldKind
|
|
246
|
+
name: string
|
|
247
|
+
schema?: z.ZodTypeAny
|
|
248
|
+
}): string {
|
|
249
|
+
const preferredExamples = {
|
|
250
|
+
prompt: JSON.stringify('A red bicycle in a studio'),
|
|
251
|
+
provider: 'aws',
|
|
252
|
+
target_language: 'en-US',
|
|
253
|
+
voice: 'female-1',
|
|
254
|
+
} as const satisfies Record<string, string>
|
|
255
|
+
const preferredExample = (preferredExamples as Record<string, string>)[name]
|
|
256
|
+
if (preferredExample != null) {
|
|
257
|
+
return preferredExample
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const schemaExample =
|
|
261
|
+
schema instanceof ZodEnum
|
|
262
|
+
? pickPreferredExampleValue(name, schema.options)
|
|
263
|
+
: schema instanceof ZodUnion
|
|
264
|
+
? pickPreferredExampleValue(
|
|
265
|
+
name,
|
|
266
|
+
schema._def.options
|
|
267
|
+
.map((option: unknown) => inferSchemaExampleValue(option))
|
|
268
|
+
.filter((value: string | null): value is string => value != null),
|
|
269
|
+
)
|
|
270
|
+
: schema == null
|
|
271
|
+
? null
|
|
272
|
+
: inferSchemaExampleValue(schema)
|
|
273
|
+
if (schemaExample != null) {
|
|
274
|
+
return schemaExample
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (kind === 'boolean') {
|
|
278
|
+
return 'true'
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (kind === 'number') {
|
|
282
|
+
return '1'
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return 'value'
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function coerceIntentFieldValue(
|
|
289
|
+
kind: IntentFieldKind,
|
|
290
|
+
raw: unknown,
|
|
291
|
+
fieldSchema?: z.ZodTypeAny,
|
|
292
|
+
): unknown {
|
|
293
|
+
if (kind === 'number' && typeof raw === 'number') {
|
|
294
|
+
return raw
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (kind === 'boolean' && typeof raw === 'boolean') {
|
|
298
|
+
return raw
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (kind === 'auto') {
|
|
302
|
+
if (fieldSchema == null) {
|
|
303
|
+
return raw
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const candidates: unknown[] = []
|
|
307
|
+
|
|
308
|
+
if (typeof raw !== 'string') {
|
|
309
|
+
candidates.push(raw)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const trimmed = typeof raw === 'string' ? raw.trim() : ''
|
|
313
|
+
|
|
314
|
+
if (typeof raw === 'string' && (trimmed.startsWith('{') || trimmed.startsWith('['))) {
|
|
315
|
+
try {
|
|
316
|
+
candidates.push(JSON.parse(trimmed))
|
|
317
|
+
} catch {}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
candidates.push(raw)
|
|
321
|
+
|
|
322
|
+
if (
|
|
323
|
+
typeof raw === 'string' &&
|
|
324
|
+
trimmed !== '' &&
|
|
325
|
+
!trimmed.startsWith('{') &&
|
|
326
|
+
!trimmed.startsWith('[')
|
|
327
|
+
) {
|
|
328
|
+
try {
|
|
329
|
+
candidates.push(JSON.parse(trimmed))
|
|
330
|
+
} catch {}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (raw === 'true' || raw === 'false') {
|
|
334
|
+
candidates.push(raw === 'true')
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const numericValue = Number(raw)
|
|
338
|
+
if ((typeof raw === 'number' || trimmed !== '') && !Number.isNaN(numericValue)) {
|
|
339
|
+
candidates.push(numericValue)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
for (const candidate of candidates) {
|
|
343
|
+
const parsed = fieldSchema.safeParse(candidate)
|
|
344
|
+
if (parsed.success) {
|
|
345
|
+
return parsed.data as boolean | number | string
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return raw
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (kind === 'number') {
|
|
353
|
+
if (typeof raw !== 'string') {
|
|
354
|
+
throw new Error(`Expected a number but received "${String(raw)}"`)
|
|
355
|
+
}
|
|
356
|
+
if (raw.trim() === '') {
|
|
357
|
+
throw new Error(`Expected a number but received "${raw}"`)
|
|
358
|
+
}
|
|
359
|
+
const value = Number(raw)
|
|
360
|
+
if (Number.isNaN(value)) {
|
|
361
|
+
throw new Error(`Expected a number but received "${raw}"`)
|
|
362
|
+
}
|
|
363
|
+
return value
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (kind === 'json') {
|
|
367
|
+
if (typeof raw !== 'string') {
|
|
368
|
+
return raw
|
|
369
|
+
}
|
|
370
|
+
let parsedJson: unknown
|
|
371
|
+
try {
|
|
372
|
+
parsedJson = JSON.parse(raw)
|
|
373
|
+
} catch {
|
|
374
|
+
throw new Error(`Expected valid JSON but received "${raw}"`)
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (fieldSchema == null) {
|
|
378
|
+
return parsedJson
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const parsed = fieldSchema.safeParse(parsedJson)
|
|
382
|
+
if (!parsed.success) {
|
|
383
|
+
throw new Error(parsed.error.message)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return parsed.data
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (kind === 'boolean') {
|
|
390
|
+
if (typeof raw !== 'string') {
|
|
391
|
+
throw new Error(`Expected "true" or "false" but received "${String(raw)}"`)
|
|
392
|
+
}
|
|
393
|
+
if (raw === 'true') return true
|
|
394
|
+
if (raw === 'false') return false
|
|
395
|
+
throw new Error(`Expected "true" or "false" but received "${raw}"`)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (kind === 'string-array') {
|
|
399
|
+
return parseStringArrayValue(raw)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return raw
|
|
403
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface RequiredIntentInputPolicy {
|
|
2
|
+
kind: 'required'
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface OptionalIntentInputPolicy {
|
|
6
|
+
attachUseWhenInputsProvided: boolean
|
|
7
|
+
field: string
|
|
8
|
+
kind: 'optional'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type IntentInputPolicy = OptionalIntentInputPolicy | RequiredIntentInputPolicy
|