jbilcke-hf HF staff commited on
Commit
c046d6a
1 Parent(s): fa2b025

bump to 0.0.13

Browse files
packages/aitube-client/README.md CHANGED
@@ -28,11 +28,21 @@ npm install @aitube/client
28
  ```typescript
29
  import {
30
  createClap,
31
- editClapEntities,
32
  editClapDialogues,
 
33
  editClapStoryboards,
34
  editClapVideos,
35
- exportClapToVideo
 
 
 
 
 
 
 
 
 
 
36
  } from '@aitube/client';
37
 
38
  const ultraSecret = "ultra secret token unavailable to common mortals"
 
28
  ```typescript
29
  import {
30
  createClap,
 
31
  editClapDialogues,
32
+ editClapEntities,
33
  editClapStoryboards,
34
  editClapVideos,
35
+ exportClapToVideo,
36
+ defaultAitubeHostname,
37
+ defaultClapWidth,
38
+ defaultClapHeight,
39
+ defaultExportFormat,
40
+ aitubeUrl,
41
+ aitubeApiVersion,
42
+ aitubeApiUrl,
43
+ ClapCompletionMode,
44
+ ClapEntityPrompt,
45
+ SupportedExportFormat
46
  } from '@aitube/client';
47
 
48
  const ultraSecret = "ultra secret token unavailable to common mortals"
packages/aitube-client/bun.lockb CHANGED
Binary files a/packages/aitube-client/bun.lockb and b/packages/aitube-client/bun.lockb differ
 
packages/aitube-client/package.json CHANGED
@@ -4,7 +4,7 @@
4
  "main": "dist/index.js",
5
  "types": "dist/index.d.ts",
6
  "type": "module",
7
- "version": "0.0.12",
8
  "description": "Official API client for AiTube.at",
9
  "scripts": {
10
  "build": "bun build --target=node ./src/index.ts --outfile=dist/index.js && bun run build:declaration",
@@ -38,5 +38,8 @@
38
  "dist/*.js",
39
  "dist/*.d.ts",
40
  "dist/**/*.d.ts"
41
- ]
 
 
 
42
  }
 
4
  "main": "dist/index.js",
5
  "types": "dist/index.d.ts",
6
  "type": "module",
7
+ "version": "0.0.13",
8
  "description": "Official API client for AiTube.at",
9
  "scripts": {
10
  "build": "bun build --target=node ./src/index.ts --outfile=dist/index.js && bun run build:declaration",
 
38
  "dist/*.js",
39
  "dist/*.d.ts",
40
  "dist/**/*.d.ts"
41
+ ],
42
+ "dependencies": {
43
+ "query-string": "^9.0.0"
44
+ }
45
  }
packages/aitube-client/src/api/createClap.ts CHANGED
@@ -1,11 +1,13 @@
1
  import { ClapProject, fetchClap } from "@aitube/clap"
2
 
3
- import { aitubeApiUrl } from "@/config"
 
 
4
 
5
  export async function createClap({
6
  prompt,
7
- height = 512,
8
- width = 288,
9
  token,
10
  }: {
11
  prompt: string
 
1
  import { ClapProject, fetchClap } from "@aitube/clap"
2
 
3
+ import { aitubeApiUrl } from "@/constants/config"
4
+
5
+ import { defaultClapHeight, defaultClapWidth } from "@/constants/defaultValues"
6
 
7
  export async function createClap({
8
  prompt,
9
+ height = defaultClapHeight,
10
+ width = defaultClapWidth,
11
  token,
12
  }: {
13
  prompt: string
packages/aitube-client/src/api/editClapDialogues.ts CHANGED
@@ -1,7 +1,8 @@
1
  import { ClapProject, fetchClap, serializeClap } from "@aitube/clap"
2
 
3
- import { aitubeApiUrl } from "@/config"
4
- import { ClapCompletionMode } from "./types"
 
5
 
6
  export async function editClapDialogues({
7
  clap,
 
1
  import { ClapProject, fetchClap, serializeClap } from "@aitube/clap"
2
 
3
+ import { aitubeApiUrl } from "@/constants/config"
4
+
5
+ import { ClapCompletionMode } from "../constants/types"
6
 
7
  export async function editClapDialogues({
8
  clap,
packages/aitube-client/src/api/editClapEntities.ts CHANGED
@@ -1,16 +1,22 @@
1
  import { ClapProject, fetchClap, serializeClap } from "@aitube/clap"
 
2
 
3
- import { aitubeApiUrl } from "@/config"
4
- import { ClapCompletionMode } from "./types"
 
5
 
6
  export async function editClapEntities({
7
  clap,
 
8
  completionMode = ClapCompletionMode.MERGE,
9
  token,
10
  }: {
11
  // A ClapProject instance
12
  clap: ClapProject
13
 
 
 
 
14
  /**
15
  * Completion mode (optional, defaults to "merge")
16
  *
@@ -29,16 +35,24 @@ export async function editClapEntities({
29
 
30
  const hasToken = typeof token === "string" && token.length > 0
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  const newClap = await fetchClap(
33
- `${aitubeApiUrl}edit/entities${
34
- typeof completionMode === "string"
35
- ? `?c=${
36
- completionMode === ClapCompletionMode.FULL
37
- ? "full"
38
- : "partial"
39
- }`
40
- : ""
41
- }`, {
42
  method: "POST",
43
  headers: {
44
  "Content-Type": "application/x-gzip",
 
1
  import { ClapProject, fetchClap, serializeClap } from "@aitube/clap"
2
+ import queryString from "query-string"
3
 
4
+ import { aitubeApiUrl } from "@/constants/config"
5
+
6
+ import { ClapCompletionMode, ClapEntityPrompt } from "../constants/types"
7
 
8
  export async function editClapEntities({
9
  clap,
10
+ entityPrompts = [],
11
  completionMode = ClapCompletionMode.MERGE,
12
  token,
13
  }: {
14
  // A ClapProject instance
15
  clap: ClapProject
16
 
17
+ // a list of entity prompts
18
+ entityPrompts: ClapEntityPrompt[],
19
+
20
  /**
21
  * Completion mode (optional, defaults to "merge")
22
  *
 
35
 
36
  const hasToken = typeof token === "string" && token.length > 0
37
 
38
+ const params: Record<string, any> = {}
39
+
40
+ if (typeof completionMode === "string") {
41
+ params.c = completionMode === ClapCompletionMode.FULL
42
+ ? "full"
43
+ : "partial"
44
+ }
45
+
46
+ if (entityPrompts.length) {
47
+ // if "params.e = JSON.stringify(item)" works with UTF-8 characters,
48
+ // then we don't need to import "js-base64"
49
+ // otherwise you will have to do:
50
+ // params.e = jsBase64.encode(JSON.stringify(item))
51
+ params.e = JSON.stringify(entityPrompts)
52
+ }
53
+
54
  const newClap = await fetchClap(
55
+ `${aitubeApiUrl}edit/entities?${queryString.stringify(params)}`, {
 
 
 
 
 
 
 
 
56
  method: "POST",
57
  headers: {
58
  "Content-Type": "application/x-gzip",
packages/aitube-client/src/api/editClapStoryboards.ts CHANGED
@@ -1,7 +1,8 @@
1
  import { ClapProject, fetchClap, serializeClap } from "@aitube/clap"
2
 
3
- import { aitubeApiUrl } from "@/config"
4
- import { ClapCompletionMode } from "./types"
 
5
 
6
  export async function editClapStoryboards({
7
  clap,
 
1
  import { ClapProject, fetchClap, serializeClap } from "@aitube/clap"
2
 
3
+ import { aitubeApiUrl } from "@/constants/config"
4
+
5
+ import { ClapCompletionMode } from "../constants/types"
6
 
7
  export async function editClapStoryboards({
8
  clap,
packages/aitube-client/src/api/editClapVideos.ts CHANGED
@@ -1,7 +1,8 @@
1
  import { ClapProject, fetchClap, serializeClap } from "@aitube/clap"
2
 
3
- import { aitubeApiUrl } from "@/config"
4
- import { ClapCompletionMode } from "./types"
 
5
 
6
  export async function editClapVideos({
7
  clap,
 
1
  import { ClapProject, fetchClap, serializeClap } from "@aitube/clap"
2
 
3
+ import { aitubeApiUrl } from "@/constants/config"
4
+
5
+ import { ClapCompletionMode } from "../constants/types"
6
 
7
  export async function editClapVideos({
8
  clap,
packages/aitube-client/src/api/exportClapToVideo.ts CHANGED
@@ -1,6 +1,6 @@
1
  import { ClapProject, serializeClap, blobToDataUri } from "@aitube/clap"
2
 
3
- import { aitubeApiUrl } from "@/config"
4
 
5
  export type SupportedExportFormat = "mp4" | "webm"
6
  export const defaultExportFormat = "mp4"
 
1
  import { ClapProject, serializeClap, blobToDataUri } from "@aitube/clap"
2
 
3
+ import { aitubeApiUrl } from "@/constants/config"
4
 
5
  export type SupportedExportFormat = "mp4" | "webm"
6
  export const defaultExportFormat = "mp4"
packages/aitube-client/src/api/index.ts CHANGED
@@ -4,4 +4,3 @@ export { editClapVideos } from "./editClapVideos"
4
  export { editClapDialogues } from "./editClapDialogues"
5
  export { editClapEntities } from "./editClapEntities"
6
  export { createClap } from "./createClap"
7
- export { ClapCompletionMode } from "./types"
 
4
  export { editClapDialogues } from "./editClapDialogues"
5
  export { editClapEntities } from "./editClapEntities"
6
  export { createClap } from "./createClap"
 
packages/aitube-client/src/{config.ts → constants/config.ts} RENAMED
@@ -1,9 +1,4 @@
1
-
2
- // unfortunately, this doesn't work yet due to a redirection issue
3
- // const defaultAitubeHostname = "aitube.at"
4
-
5
- // so we have to use the direct space hostname instead
6
- export const defaultAitubeHostname = "jbilcke-hf-ai-tube.hf.space"
7
 
8
  // we leave the opportunity to override this at runtime
9
  export const aitubeUrl = `${
 
1
+ import { defaultAitubeHostname } from "./defaultValues"
 
 
 
 
 
2
 
3
  // we leave the opportunity to override this at runtime
4
  export const aitubeUrl = `${
packages/aitube-client/src/constants/defaultValues.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ // unfortunately, this doesn't work yet due to a redirection issue
2
+ // const defaultAitubeHostname = "aitube.at"
3
+
4
+ // so we have to use the direct space hostname instead
5
+ export const defaultAitubeHostname = "jbilcke-hf-ai-tube.hf.space"
6
+
7
+ export const defaultClapWidth = 512
8
+ export const defaultClapHeight = 288
9
+
10
+ export const defaultExportFormat = "mp4"
packages/aitube-client/src/constants/index.ts ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export {
2
+ defaultAitubeHostname,
3
+ defaultClapWidth,
4
+ defaultClapHeight,
5
+ defaultExportFormat
6
+ } from './defaultValues'
7
+
8
+ export {
9
+ aitubeUrl,
10
+ aitubeApiVersion,
11
+ aitubeApiUrl
12
+ } from './config'
13
+
14
+ export {
15
+ ClapCompletionMode,
16
+ ClapEntityPrompt,
17
+ SupportedExportFormat
18
+ } from "./types"
packages/aitube-client/src/{api → constants}/types.ts RENAMED
@@ -1,3 +1,5 @@
 
 
1
  export enum ClapCompletionMode {
2
  /**
3
  * the API and the client will return a full clap file.
@@ -25,4 +27,24 @@ export enum ClapCompletionMode {
25
  * This is the most efficient mode, but it relies on side-effects and inline object updates.
26
  */
27
  REPLACE = "replace"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
 
1
+ export type SupportedExportFormat = "mp4" | "webm"
2
+
3
  export enum ClapCompletionMode {
4
  /**
5
  * the API and the client will return a full clap file.
 
27
  * This is the most efficient mode, but it relies on side-effects and inline object updates.
28
  */
29
  REPLACE = "replace"
30
+ }
31
+
32
+
33
+ export type ClapEntityPrompt = {
34
+ name: string
35
+
36
+ // age of the person, animal or entity (eg. robot, talking spaceship etc)
37
+ age: string
38
+
39
+ // characterization of the person, animal or entity (texture, hair color, gender etc)
40
+ variant: string
41
+
42
+ // region from where the person, animal or entity is coming from (human, mechanical, alien planet, european, south-american etc)
43
+ region: string
44
+
45
+ // identity picture
46
+ identityImage: string
47
+
48
+ // identity voice
49
+ identityVoice: string
50
  }
packages/aitube-client/src/index.ts CHANGED
@@ -6,12 +6,17 @@ export {
6
  editClapStoryboards,
7
  editClapVideos,
8
  exportClapToVideo,
9
- ClapCompletionMode,
10
  } from './api'
11
 
12
  export {
13
  defaultAitubeHostname,
 
 
 
14
  aitubeUrl,
15
  aitubeApiVersion,
16
- aitubeApiUrl
17
- } from './config'
 
 
 
 
6
  editClapStoryboards,
7
  editClapVideos,
8
  exportClapToVideo,
 
9
  } from './api'
10
 
11
  export {
12
  defaultAitubeHostname,
13
+ defaultClapWidth,
14
+ defaultClapHeight,
15
+ defaultExportFormat,
16
  aitubeUrl,
17
  aitubeApiVersion,
18
+ aitubeApiUrl,
19
+ ClapCompletionMode,
20
+ ClapEntityPrompt,
21
+ SupportedExportFormat
22
+ } from "./constants"
packages/aitube-client/src/parsers/index.ts ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ export { parseEntityPrompt } from "./parseEntityPrompt"
2
+ export { parseString } from "./parseString"
3
+ export { parseStringArray } from "./parseStringArray"
packages/aitube-client/src/parsers/parseEntityPrompt.ts ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ import { ClapEntityPrompt } from "@/constants/types"
4
+
5
+ import { parseString } from "./parseString"
6
+
7
+ export function parseEntityPrompt(entityPrompt: Partial<ClapEntityPrompt> = {}): ClapEntityPrompt {
8
+
9
+ return {
10
+ name: parseString(entityPrompt?.name),
11
+
12
+ // age of the person, animal or entity (eg. robot, talking spaceship etc)
13
+ age: parseString(entityPrompt?.age),
14
+
15
+ // characterization of the person, animal or entity (texture, hair color, gender etc)
16
+ variant: parseString(entityPrompt?.variant),
17
+
18
+ // region from where the person, animal or entity is coming from (human, mechanical, alien planet, european, south-american etc)
19
+ region: parseString(entityPrompt?.region),
20
+
21
+ // identity picture
22
+ identityImage: parseString(entityPrompt?.identityImage),
23
+
24
+ // identity voice
25
+ identityVoice: parseString(entityPrompt?.identityVoice),
26
+ }
27
+ }
packages/aitube-client/src/parsers/parseString.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ export function parseString(input?: any, defaultValue?: string): string {
2
+ const defValue = `${defaultValue || ""}`
3
+
4
+ if (typeof input !== "string") { return defValue }
5
+
6
+ return input || defValue
7
+ }
packages/aitube-client/src/parsers/parseStringArray.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ export function parseStringArray(something: any): string[] {
2
+ let result: string[] = []
3
+ if (typeof something === "string") {
4
+ result = [something]
5
+ } else if (Array.isArray(something)) {
6
+ result = something.map(thing => typeof thing === "string" ? thing : "").filter(x => x)
7
+ }
8
+ return result
9
+ }