Skip to content

Commit

Permalink
Sync alphalib
Browse files Browse the repository at this point in the history
  • Loading branch information
kvz committed Jan 30, 2025
1 parent 92ebdbf commit 542ce00
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 61 deletions.
106 changes: 100 additions & 6 deletions src/alphalib/types/robots/_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import { robotHtmlConvertInstructionsSchema } from './html-convert.ts'
import { robotHttpImportInstructionsSchema } from './http-import.ts'
import { robotImageDescribeInstructionsSchema } from './image-describe.ts'
import { robotImageFacedetectInstructionsSchema } from './image-facedetect.ts'
import { robotImageGenerateInstructionsSchema } from './image-generate.ts'
import {
robotImageGenerateInstructionsSchema,
robotImageGenerateInstructionsWithHiddenFieldsSchema,
} from './image-generate.ts'
import { robotImageMergeInstructionsSchema } from './image-merge.ts'
import { robotImageOcrInstructionsSchema } from './image-ocr.ts'
import { robotImageOptimizeInstructionsSchema } from './image-optimize.ts'
Expand All @@ -59,7 +62,10 @@ import { robotS3StoreInstructionsSchema } from './s3-store.ts'
import { robotScriptRunInstructionsSchema } from './script-run.ts'
import { robotSftpImportInstructionsSchema } from './sftp-import.ts'
import { robotSftpStoreInstructionsSchema } from './sftp-store.ts'
import { robotSpeechTranscribeInstructionsSchema } from './speech-transcribe.ts'
import {
robotSpeechTranscribeInstructionsSchema,
robotSpeechTranscribeInstructionsWithHiddenFieldsSchema,
} from './speech-transcribe.ts'
import { robotSupabaseImportInstructionsSchema } from './supabase-import.ts'
import { robotSupabaseStoreInstructionsSchema } from './supabase-store.ts'
import { robotSwiftImportInstructionsSchema } from './swift-import.ts'
Expand Down Expand Up @@ -158,21 +164,109 @@ const robotStepsInstructions = [
robotYoutubeStoreInstructionsSchema,
] as const

const robotStepsInstructionsWithHiddenFields = [
robotAudioArtworkInstructionsSchema,
robotAudioConcatInstructionsSchema,
robotAudioEncodeInstructionsSchema,
robotAudioLoopInstructionsSchema,
robotAudioMergeInstructionsSchema,
robotAudioWaveformInstructionsSchema,
robotAzureImportInstructionsSchema,
robotAzureStoreInstructionsSchema,
robotBackblazeImportInstructionsSchema,
robotBackblazeStoreInstructionsSchema,
robotCloudfilesImportInstructionsSchema,
robotCloudfilesStoreInstructionsSchema,
robotCloudflareImportInstructionsSchema,
robotCloudflareStoreInstructionsSchema,
robotDigitaloceanImportInstructionsSchema,
robotDigitaloceanStoreInstructionsSchema,
robotDocumentAutorotateInstructionsSchema,
robotDocumentConvertInstructionsSchema,
robotDocumentMergeInstructionsSchema,
robotDocumentOcrInstructionsSchema,
robotFileReadInstructionsSchema,
robotDocumentSplitInstructionsSchema,
robotDocumentThumbsInstructionsSchema,
robotDropboxImportInstructionsSchema,
robotDropboxStoreInstructionsSchema,
robotEdglyDeliverInstructionsSchema,
robotFileCompressInstructionsSchema,
robotFileDecompressInstructionsSchema,
robotFileFilterInstructionsSchema,
robotFileHashInstructionsSchema,
robotFilePreviewInstructionsSchema,
robotFileServeInstructionsSchema,
robotFileVerifyInstructionsSchema,
robotFileVirusscanInstructionsSchema,
robotFtpImportInstructionsSchema,
robotFtpStoreInstructionsSchema,
robotGoogleImportInstructionsSchema,
robotGoogleStoreInstructionsSchema,
robotHtmlConvertInstructionsSchema,
robotHttpImportInstructionsSchema,
robotImageDescribeInstructionsSchema,
robotImageFacedetectInstructionsSchema,
robotImageMergeInstructionsSchema,
robotImageOcrInstructionsSchema,
robotImageOptimizeInstructionsSchema,
robotImageResizeInstructionsSchema,
robotMediaPlaylistInstructionsSchema,
robotMetaWriteInstructionsSchema,
robotMinioImportInstructionsSchema,
robotMinioStoreInstructionsSchema,
robotS3ImportInstructionsSchema,
robotS3StoreInstructionsSchema,
robotScriptRunInstructionsSchema,
robotSftpImportInstructionsSchema,
robotSftpStoreInstructionsSchema,
robotSpeechTranscribeInstructionsWithHiddenFieldsSchema,
robotSupabaseImportInstructionsSchema,
robotSupabaseStoreInstructionsSchema,
robotSwiftImportInstructionsSchema,
robotSwiftStoreInstructionsSchema,
robotTextSpeakInstructionsSchema,
robotTextTranslateInstructionsSchema,
robotTlcdnDeliverInstructionsSchema,
robotTusStoreInstructionsSchema,
robotUploadHandleInstructionsSchema,
robotVideoAdaptiveInstructionsSchema,
robotVideoConcatInstructionsSchema,
robotVideoEncodeInstructionsSchema,
robotVideoMergeInstructionsSchema,
robotVideoSubtitleInstructionsSchema,
robotVideoThumbsInstructionsSchema,
robotVimeoStoreInstructionsSchema,
robotWasabiImportInstructionsSchema,
robotWasabiStoreInstructionsSchema,
robotYoutubeStoreInstructionsSchema,
] as const

/**
* Public robot instructions
*/
export const robotStepsInstructionsSchema = z.discriminatedUnion('robot', [
...robotStepsInstructions,
export const robotsSchema = z.discriminatedUnion('robot', [...robotStepsInstructions])
export const robotsWithHiddenFieldsSchema = z.discriminatedUnion('robot', [
...robotStepsInstructionsWithHiddenFields,
])

/**
* All robot instructions, including private ones.
*/
export const robotAnyInstructionsSchema = z.discriminatedUnion('robot', [
export const robotsWithHiddenBotsSchema = z.discriminatedUnion('robot', [
...robotStepsInstructions,
robotFileWatermarkInstructionsSchema,
robotImageGenerateInstructionsSchema,
robotImageRemoveBackgroundInstructionsSchema,
robotProgressSimulateInstructionsSchema,
])
export type RobotAnyInstructions = z.infer<typeof robotAnyInstructionsSchema>
export const robotsWithHiddenBotsAndFieldsSchema = z.discriminatedUnion('robot', [
...robotStepsInstructionsWithHiddenFields,
robotFileWatermarkInstructionsSchema,
robotImageGenerateInstructionsWithHiddenFieldsSchema,
robotImageRemoveBackgroundInstructionsSchema,
robotProgressSimulateInstructionsSchema,
])

export type RobotsWithHiddenBots = z.infer<typeof robotsWithHiddenBotsSchema>
export type RobotsWithHiddenBotsAndFields = z.infer<typeof robotsWithHiddenBotsAndFieldsSchema>
7 changes: 4 additions & 3 deletions src/alphalib/types/robots/image-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const robotImageGenerateInstructionsSchema = z
model: z.string(),
prompt: z.string().describe('The prompt describing the desired image content.'),
format: z
.enum(['jpeg', 'png', 'gif', 'webp'])
.enum(['jpeg', 'png', 'gif', 'webp', 'svg'])
.optional()
.describe('Format of the generated image.'),
seed: z.number().optional().describe('Seed for the random number generator.'),
Expand All @@ -25,12 +25,13 @@ export const robotImageGenerateInstructionsSchema = z
})
.strict()

export const robotImageGenerateInstructionsWithHiddenFields =
export const robotImageGenerateInstructionsWithHiddenFieldsSchema =
robotImageGenerateInstructionsSchema.extend({
result: z.union([z.literal('debug'), robotImageGenerateInstructionsSchema.shape.result]),
provider: z.string().optional().describe('Provider for generating the image.'),
})

export type RobotImageGenerateInstructions = z.infer<typeof robotImageGenerateInstructionsSchema>
export type RobotImageGenerateInstructionsWithHiddenFields = z.infer<
typeof robotImageGenerateInstructionsWithHiddenFields
typeof robotImageGenerateInstructionsWithHiddenFieldsSchema
>
23 changes: 22 additions & 1 deletion src/alphalib/types/robots/speech-transcribe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { z } from 'zod'

import { aiProviderSchema, granularitySchema, useParamSchema } from './_instructions-primitives.ts'
import {
aiProviderSchema,
granularitySchema,
outputMetaParamSchema,
useParamSchema,
} from './_instructions-primitives.ts'
import type { RobotMeta } from './_instructions-primitives.ts'

export const meta: RobotMeta = {
Expand Down Expand Up @@ -66,15 +71,31 @@ Output format for the transcription.
- \`"srt"\` and \`"webvtt"\` output subtitle files of those respective file types, which can be stored separately or used in other encoding <dfn>Steps</dfn>.
- \`"meta"\` does not return a file, but stores the data inside Transloadit's file object (under \`\${file.meta.transcription.text}\`) that's passed around between encoding <dfn>Steps</dfn>, so that you can use the values to burn the data into videos, filter on them, etc.
`),
output_meta: outputMetaParamSchema.optional(),
// TODO determine the list of languages
source_language: z.string().default('en-US').describe(`
The spoken language of the audio or video. This will also be the language of the transcribed text.
The language should be specified in the [BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) format, such as \`"en-GB"\`, \`"de-DE"\` or \`"fr-FR"\`. Please also consult the list of supported languages for [the \`gcp\` provider](https://cloud.google.com/speech-to-text/docs/languages) and the [the \`aws\` provider](https://docs.aws.amazon.com/transcribe/latest/dg/what-is-transcribe.html).
`),
// TODO determine the list of languages
target_language: z.string().default('en-US').describe(`
This will also be the language of the written text.
The language should be specified in the [BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) format, such as \`"en-GB"\`, \`"de-DE"\` or \`"fr-FR"\`. Please consult the list of supported languages and voices.
`),
})
.strict()

export type RobotSpeechTranscribeInstructions = z.infer<
typeof robotSpeechTranscribeInstructionsSchema
>

export const robotSpeechTranscribeInstructionsWithHiddenFieldsSchema =
robotSpeechTranscribeInstructionsSchema.extend({
result: z.union([z.literal('debug'), robotSpeechTranscribeInstructionsSchema.shape.result]),
})

export type RobotSpeechTranscribeInstructionsWithHiddenFields = z.infer<
typeof robotSpeechTranscribeInstructionsWithHiddenFieldsSchema
>
1 change: 1 addition & 0 deletions src/alphalib/types/robots/upload-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ There are **3 important constraints** when using this <dfn>Robot</dfn>:
.strict()

export type RobotUploadHandleInstructions = z.infer<typeof robotUploadHandleInstructionsSchema>
export type RobotUploadHandleInstructionsInput = z.input<typeof robotUploadHandleInstructionsSchema>
5 changes: 3 additions & 2 deletions src/alphalib/types/robots/video-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ If the given width/height parameters are bigger than the input image's dimension
The background color of the resulting video the \`"rrggbbaa"\` format (red, green, blue, alpha) when used with the \`"pad"\` resize strategy. The default color is black.
`),
framerate: z
.string()
.regex(/^\d+\/\d+$/)
.union([z.number().int().min(1), z.string().regex(/^\d+(?:\/\d+)?$/)])
.default('1/5').describe(`
When merging images to generate a video this is the input framerate. A value of "1/5" means each image is given 5 seconds before the next frame appears (the inverse of a framerate of "5"). Likewise for "1/10", "1/20", etc. A value of "5" means there are 5 frames per second.
`),
Expand All @@ -80,6 +79,8 @@ When merging audio files and video files, the duration of the longest video or a
audio_delay: z.number().default(0).describe(`
When merging a video and an audio file, and when merging images and an audio file to generate a video, this is the desired delay in seconds for the audio file to start playing. Imagine you merge a video file without sound and an audio file, but you wish the audio to start playing after 5 seconds and not immediately, then this is the parameter to use.
`),
loop: z.boolean().default(false).describe(`
Determines whether the shorter media file should be looped to match the duration of the longer one. For example, if you merge a 1-minute video with a 3-minute audio file and enable this option, the video will play three times in a row to match the audio length.`),
replace_audio: z.boolean().default(false).describe(`
Determines whether the audio of the video should be replaced with a provided audio file.
`),
Expand Down
23 changes: 18 additions & 5 deletions src/alphalib/types/template.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
import { z } from 'zod'

import { robotStepsInstructionsSchema } from './robots/_index.ts'
import { robotsWithHiddenBotsAndFieldsSchema, robotsSchema } from './robots/_index.ts'
import type { UseParamInput } from './robots/_instructions-primitives.ts'

export const stepSchema = z
.object({
// This is a hack to get nicer robot hover messages in editors.
robot: z.string().describe('The [robot](https://transloadit.com/docs/transcoding/) to use'),
})
.and(robotStepsInstructionsSchema)
.and(robotsSchema)
export const stepsSchema = z.record(stepSchema).describe('Contains Assembly Instructions.')
export type Step = z.infer<typeof stepSchema>
export type StepInput = z.input<typeof stepSchema>
export type StepInputWithUse = StepInput & { use: UseParamInput }
export const stepsSchema = z.record(stepSchema).describe('Contains Assembly Instructions.')

export type Steps = z.infer<typeof stepsSchema>
export type StepsInput = z.input<typeof stepsSchema>

export const stepSchemaWithHiddenFields = z
.object({
// This is a hack to get nicer robot hover messages in editors.
robot: z.string().describe('The [robot](https://transloadit.com/docs/transcoding/) to use'),
})
.and(robotsWithHiddenBotsAndFieldsSchema)
export const stepsSchemaWithHiddenFields = z
.record(stepSchemaWithHiddenFields)
.describe('Contains Assembly Instructions.')
export type StepWithHiddenFields = z.infer<typeof stepSchemaWithHiddenFields>
export type StepWithHiddenFieldsInput = z.input<typeof stepSchemaWithHiddenFields>
export type StepsWithHiddenFields = z.infer<typeof stepsSchemaWithHiddenFields>
export type StepsWithHiddenFieldsInput = z.input<typeof stepsSchemaWithHiddenFields>

export const assemblyAuthInstructionsSchema = z.object({
key: z.string().describe('The Transloadit API key to use'),
secret: z.string().optional().describe('The Transloadit API secret to use'),
Expand Down Expand Up @@ -44,7 +57,7 @@ export const assemblyInstructionsSchema = z.object({
.describe(
'An object of string to string pairs (name -> value) that can be used as Assembly Variables, just like additional form fields can.',
),
quite: z
quiet: z
.boolean()
.optional()
.describe(
Expand Down
Loading

0 comments on commit 542ce00

Please sign in to comment.