Skip to content

Commit 9e0fe1d

Browse files
authored
Sync alphalib 20250324 (#220)
* w * w
1 parent 2daaa64 commit 9e0fe1d

9 files changed

Lines changed: 71 additions & 95 deletions

File tree

.cursor/rules/cli-scripts.mdc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
description: CLI Scripts
3+
globs:
4+
alwaysApply: false
5+
---
6+
- For CLI scripts, use TypeScript
7+
- Use tsx vs ts-node
8+
- If we need complex CLI arg parsing use Clipanion & Typanion
9+
- Use execa for running commands. We use version 4 because not all repo's are ESM compatible yet
10+
- Use dotenv to load secrets
11+
- Have one main() or run() method that catches fails and exit(1) the process. Then have less excessive try/catches throughout the entire script
12+
- Use `import { randomUUID } from 'node:crypto'` vs `import { v4 as uuidv4 } from 'uuid'`

.cursor/rules/coding-style.mdc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ alwaysApply: false
99
- Favor using real paths (`../lib/schemas.ts`) over aliases (`@/app/lib/schemas`).
1010
- Favor `for (const comment of comments) {` over `comments.forEach((comment) => {`
1111
- Favor named exports over default exports, with the exception of Next.js pages
12+
- Do not wrap each function body and function call in `try`/`catch` blocks. It pollutes the code. Assume we will always have an e.g. `main().catch((err) => { console.error(err); process.exit(1) })` to catch us.
13+
- Before creating new files and new code, see if we can leverage existing work, maybe slighty adapt that without breaking BC, to keep things DRY.
14+
- Favor early exits, so quickly `continue`, `return false` (or `throw` if needed), over nesting everything in positive conditions, creating christmas trees.

.cursor/rules/general.mdc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ alwaysApply: true
55
---
66
- Do not touch `.env` files!
77
- Favor Yarn (4) over npm
8+
- Never run any dev server yourself. I have one running that auto-reloads on changes.
89
- Avoid blocking the conversation with terminal commands. For example: A) most of my git commands run through pagers, so pipe their output to `cat` to avoid blocking the
9-
terminal. B) Running a server in the foreground will block the conversation. Avoid it. C) You can use `tail` for logs, but be smart and use `-n` instead of `-f`, or the conversation will block
10+
terminal. B) You can use `tail` for logs, but be smart and use `-n` instead of `-f`, or the conversation will block

src/alphalib/types/robots/_index.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ import { robotGoogleImportInstructionsSchema, meta as googleImportMeta } from '.
9292
import { robotGoogleStoreInstructionsSchema, meta as googleStoreMeta } from './google-store.ts'
9393
import { robotHtmlConvertInstructionsSchema, meta as htmlConvertMeta } from './html-convert.ts'
9494
import { robotHttpImportInstructionsSchema, meta as httpImportMeta } from './http-import.ts'
95+
import { robotImageBgremoveInstructionsSchema } from './image-bgremove.ts'
9596
import {
9697
robotImageDescribeInstructionsSchema,
9798
meta as imageDescribeMeta,
@@ -110,12 +111,7 @@ import {
110111
robotImageOptimizeInstructionsSchema,
111112
meta as imageOptimizeMeta,
112113
} from './image-optimize.ts'
113-
import { robotImageRemoveBackgroundInstructionsSchema } from './image-remove-background.ts'
114114
import { robotImageResizeInstructionsSchema, meta as imageResizeMeta } from './image-resize.ts'
115-
import {
116-
robotMediaPlaylistInstructionsSchema,
117-
meta as mediaPlaylistMeta,
118-
} from './media-playlist.ts'
119115
import { robotMetaWriteInstructionsSchema, meta as metaWriteMeta } from './meta-write.ts'
120116
import { robotMinioImportInstructionsSchema, meta as minioImportMeta } from './minio-import.ts'
121117
import { robotMinioStoreInstructionsSchema, meta as minioStoreMeta } from './minio-store.ts'
@@ -208,13 +204,13 @@ const robotStepsInstructions = [
208204
robotGoogleStoreInstructionsSchema,
209205
robotHtmlConvertInstructionsSchema,
210206
robotHttpImportInstructionsSchema,
207+
robotImageBgremoveInstructionsSchema,
211208
robotImageDescribeInstructionsSchema,
212209
robotImageFacedetectInstructionsSchema,
213210
robotImageMergeInstructionsSchema,
214211
robotImageOcrInstructionsSchema,
215212
robotImageOptimizeInstructionsSchema,
216213
robotImageResizeInstructionsSchema,
217-
robotMediaPlaylistInstructionsSchema,
218214
robotMetaWriteInstructionsSchema,
219215
robotMinioImportInstructionsSchema,
220216
robotMinioStoreInstructionsSchema,
@@ -294,7 +290,6 @@ const robotStepsInstructionsWithHiddenFields = [
294290
robotImageOcrInstructionsSchema,
295291
robotImageOptimizeInstructionsSchema,
296292
robotImageResizeInstructionsSchema,
297-
robotMediaPlaylistInstructionsSchema,
298293
robotMetaWriteInstructionsSchema,
299294
robotMinioImportInstructionsSchema,
300295
robotMinioStoreInstructionsSchema,
@@ -342,14 +337,12 @@ export const robotsWithHiddenBotsSchema = z.discriminatedUnion('robot', [
342337
...robotStepsInstructions,
343338
robotFileWatermarkInstructionsSchema,
344339
robotImageGenerateInstructionsSchema,
345-
robotImageRemoveBackgroundInstructionsSchema,
346340
robotProgressSimulateInstructionsSchema,
347341
])
348342
export const robotsWithHiddenBotsAndFieldsSchema = z.discriminatedUnion('robot', [
349343
...robotStepsInstructionsWithHiddenFields,
350344
robotFileWatermarkInstructionsSchema,
351345
robotImageGenerateInstructionsWithHiddenFieldsSchema,
352-
robotImageRemoveBackgroundInstructionsSchema,
353346
robotProgressSimulateInstructionsSchema,
354347
])
355348

@@ -403,7 +396,6 @@ export const robotsMeta = {
403396
imageOcrMeta,
404397
imageOptimizeMeta,
405398
imageResizeMeta,
406-
mediaPlaylistMeta,
407399
metaWriteMeta,
408400
minioImportMeta,
409401
minioStoreMeta,

src/alphalib/types/robots/_instructions-primitives.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface RobotMeta {
5555
| 'transcribe'
5656
| 'translate'
5757
| 'verify'
58+
| 'remove'
5859
| 'write'
5960

6061
purpose_word: string
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { z } from 'zod'
2+
3+
import type { RobotMeta } from './_instructions-primitives.ts'
4+
import { robotBase, robotUse } from './_instructions-primitives.ts'
5+
6+
export const meta: RobotMeta = {
7+
allowed_for_url_transform: true,
8+
discount_factor: 1,
9+
bytescount: 1,
10+
discount_pct: 0,
11+
docs_redirect_from: ['/docs/image-bgremove/'],
12+
example_code: {
13+
steps: {
14+
remove_background: {
15+
robot: '/image/bgremove',
16+
use: ':original',
17+
},
18+
},
19+
},
20+
example_code_description: 'Remove the background from the uploaded image:',
21+
minimum_charge: 0,
22+
output_factor: 0.6,
23+
override_lvl1: 'Image Manipulation',
24+
purpose_sentence: 'removes the background from images',
25+
purpose_verb: 'remove',
26+
purpose_word: 'remove',
27+
purpose_words: 'Remove the background from images',
28+
service_slug: 'image-manipulation',
29+
slot_count: 10,
30+
title: 'Remove the background from images',
31+
typical_file_size_mb: 0.8,
32+
typical_file_type: 'image',
33+
}
34+
35+
export const robotImageBgremoveInstructionsSchema = robotBase
36+
.merge(robotUse)
37+
.extend({
38+
robot: z.literal('/image/bgremove'),
39+
select: z
40+
.enum(['foreground', 'background'])
41+
.optional()
42+
.describe('Region to select and keep in the image. The other region is removed.'),
43+
format: z.enum(['png', 'gif', 'webp']).optional().describe('Format of the generated image.'),
44+
provider: z
45+
.enum(['transloadit', 'replicate', 'fal'])
46+
.optional()
47+
.describe('Provider to use for removing the background.'),
48+
})
49+
.strict()
50+
51+
export type RobotImageBgremoveInstructions = z.infer<typeof robotImageBgremoveInstructionsSchema>

src/alphalib/types/robots/image-remove-background.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/alphalib/types/robots/media-playlist.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/alphalib/types/robots/video-encode.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ Splits the video into multiple chunks so that each chunk can be encoded in paral
101101
`),
102102
chunk_duration: z.number().int().min(1).optional().describe(`
103103
Allows you to specify the duration of each chunk when \`turbo\` is set to \`true\`. This means you can take advantage of that feature while using fewer <dfn>Priority Job Slots</dfn>. For instance, the longer each chunk is, the fewer <dfn>Encoding Jobs</dfn> will need to be used.
104-
`),
105-
freeze_detect: z.boolean().default(false).describe(`
106-
Examines the transcoding result file for video freeze frames and re-transcodes the video a second time if they are found. This is useful when you are using \`turbo: true\` because freeze frames can sometimes happen there. The re-transcode would then happen without turbo mode.
107104
`),
108105
watermark_url: z.string().default('').describe(`
109106
A URL indicating a PNG image to be overlaid above this image. You can also [supply the watermark via another Assembly Step](/docs/transcoding/video-encoding/video-encode/#watermark-parameters-video-encode).

0 commit comments

Comments
 (0)