Compare commits

...
Author SHA1 Message Date
Tanish Manku 2bf5611391 Frontend: remove dead API client code targeting unregistered endpoints
Deletes dormant legacy API surface (zero live callers, verified against the
full backend route table):

- VoiceDesignerApi, VoiceConversionApi, AnalyticsApi (/v1/analytics/log_session
  was never registered) - both @storyteller/api and the Tauri app's ApiManager
  copies, plus their tests
- PromptsApi/EngineApi: /v1/image_studio/prompt, /v1/image_studio/session_jobs,
  /v1/jobs/session/{token} methods (routes do not exist)
- UserBookmarksApi: broken-path list methods (/list/{user} and /list/{et}/{etok};
  backend shapes are /list/user/{u} and /list/entity/{et}/{etok}) and the
  FakeYou-era scoped enums that only they consumed
- Dashboard UsersApi: RequestPasswordReset/ResetPassword pointing at removed
  /v1/request_password_reset + /v1/reset_password (live pages use
  PasswordResetApi -> /v1/password_reset/* correctly)

Fixes WeightsApi cover-image path to the registered route:
/v1/weights/weight/{token}/cover_image (both copies).
2026-07-13 14:12:17 -07:00
21 changed files with 5 additions and 1452 deletions
@@ -169,60 +169,6 @@ export class UsersApi extends ApiManager {
}));
}
public async RequestPasswordReset({
email,
}: {
email: string;
}): Promise<ApiResponse<null>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/request_password_reset`;
return await this.post<
{ email: string },
{ success: boolean; error_message?: string }
>({
endpoint,
body: { email },
})
.then((response) => ({
success: response.success,
errorMessage: response.error_message,
}))
.catch((err) => ({
success: false,
errorMessage: err.message,
}));
}
public async ResetPassword({
token,
password,
passwordConfirmation,
}: {
token: string;
password: string;
passwordConfirmation: string;
}): Promise<ApiResponse<null>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/reset_password`;
return await this.post<
{ token: string; password: string; password_confirmation: string },
{ success: boolean; error_message?: string }
>({
endpoint,
body: {
token,
password,
password_confirmation: passwordConfirmation,
},
})
.then((response) => ({
success: response.success,
errorMessage: response.error_message,
}))
.catch((err) => ({
success: false,
errorMessage: err.message,
}));
}
public async ChangePassword({
password,
passwordConfirmation,
@@ -1,38 +0,0 @@
import { ApiManager, ApiResponse } from "./ApiManager";
export class AnalyticsApi extends ApiManager {
public PostAnalytics({
maybeLastAction,
maybeLogToken,
}: {
maybeLastAction: string;
maybeLogToken: string;
}): Promise<ApiResponse<string>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/analytics/log_session`;
const body = {
maybe_last_action: maybeLastAction,
maybe_log_token: maybeLogToken,
};
return this.post<
{
maybe_last_action: string;
maybe_log_token: string;
},
{
success?: boolean;
log_token?: string;
BadInput?: string;
}
>({ endpoint, body })
.then((response) => ({
success: response.success ?? false,
data: response.log_token,
errorMessage: response.BadInput,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
}
@@ -86,128 +86,4 @@ export class EngineApi extends ApiManager {
return result;
}
public async enqueueImageGeneration({
disableSystemPrompt,
prompt,
snapshotMediaToken,
additionalImages,
}: {
disableSystemPrompt: boolean;
prompt: string;
snapshotMediaToken: string;
additionalImages?: string[];
}): Promise<ApiResponse<string>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/image_studio/prompt`;
const uuidIdempotencyToken = crypto.randomUUID(); // Generate a new UUID
const body = {
uuid_idempotency_token: uuidIdempotencyToken,
disable_system_prompt: disableSystemPrompt,
prompt,
snapshot_media_token: snapshotMediaToken, // Changed from scene_media_token to snapshot_media_token
additional_images: additionalImages,
};
const postResponse = await this.post<
{
uuid_idempotency_token: string;
disable_system_prompt: boolean;
prompt: string;
snapshot_media_token: string;
additional_images?: string[];
},
{ success?: boolean; job_token?: string; error_reason?: string, failure_reason?: string}
>({
endpoint,
body,
});
console.log("postResponse", postResponse);
// Check if the response is successful
const isSuccess = postResponse.success ?? false;
// Prepare the result object
const result = {
success: isSuccess,
data: isSuccess ? postResponse.job_token : undefined,
errorMessage: isSuccess ? undefined : (postResponse.error_reason || postResponse.failure_reason),
};
return result;
}
public async pollJobSession(jobToken: string): Promise<
ApiResponse<{
status: string;
result: {
generated_images?: string[];
error?: string;
};
}>
> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/jobs/session/${jobToken}`;
const response = await this.get<{
success?: boolean;
status?: string;
result?: {
generated_images?: string[];
error?: string;
};
BadInput?: string;
}>({
endpoint,
});
const success = response.success ?? false;
const status = response.status ?? "";
const result = response.result ?? {
generated_images: [],
error: undefined,
};
const errorMessage = response.BadInput;
return {
success,
data: { status, result },
errorMessage,
};
}
public async pollStudioSessionJobs(jobToken: string): Promise<
ApiResponse<{
status: string;
result: {
generated_images?: string[];
error?: string;
};
}>
> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/image_studio/session_jobs/${jobToken}`;
const response = await this.get<{
success?: boolean;
status?: string;
result?: {
generated_images?: string[];
error?: string;
};
BadInput?: string;
}>({
endpoint,
});
const success = response.success ?? false;
const status = response.status ?? "";
const result = response.result ?? {
generated_images: [],
error: undefined,
};
const errorMessage = response.BadInput;
return {
success,
data: { status, result },
errorMessage,
};
}
}
@@ -1,53 +1,5 @@
import { ApiManager, ApiResponse } from "./ApiManager";
import type {
Pagination,
UserBookmarkBatch,
UserBookmarkByEntity,
UserBookmarkByUser,
} from "@storyteller/ui-pagescene";
import { authentication } from "~/signals";
export enum ScopedEntityTypes {
USER = "user",
TTS_MODEL = "tts-model",
TTS_RESULT = "tts-result",
W2L_TEMPLATE = "w2l-template",
W2L_RESULT = "w2l-result",
MEDIA_FILE = "media_file",
MODEL_WEIGHT = "model_weight",
VOICE_CONVERSION_MODEL = "voice_conversion_model",
ZS_VOICE = "z_voice",
}
export enum ScopedWeightTypes {
HIFIGAN_TTl2 = "hifigan_tt2",
RVC_V2 = "rvc_v2",
SD_1_5 = "sd_1.5",
SDXL = "sdxl",
SO_VITS_SVC = "so_vits_svc",
TT2 = "tt2",
LORA = "loRA",
VALL_E = "vall_e",
COMFY_UI = "comfy_ui",
}
export enum ScopedMediaFileType {
IMAGE_GENERATION = "image_generation",
TEXT_TO_SPEECH = "text_to_speech",
VOCODER = "vocoder",
VOICE_CONVERSION = "voice_conversion",
WORKFLOW_CONFIG = "workflow_config",
}
interface ListUserBookmarksByUserRequest {
username?: string;
sort_ascending?: boolean;
page_size?: number;
page_index?: number;
maybe_scoped_entity_type?: ScopedEntityTypes[];
maybe_scoped_weight_type?: ScopedWeightTypes[];
maybe_scoped_media_file_type?: ScopedMediaFileType[];
}
import type { UserBookmarkBatch } from "@storyteller/ui-pagescene";
export class UserBookmarksApi extends ApiManager {
public CreateUserBookmark({
@@ -134,69 +86,4 @@ export class UserBookmarksApi extends ApiManager {
});
}
public ListUserBookmarksByUser({
username,
sort_ascending,
page_size,
page_index,
maybe_scoped_entity_type,
maybe_scoped_weight_type,
maybe_scoped_media_file_type,
}: ListUserBookmarksByUserRequest): Promise<
ApiResponse<UserBookmarkByUser[], Pagination>
> {
const user = username ?? authentication.userInfo.value?.username;
const endpoint = `${this.getApiSchemeAndHost()}/v1/user_bookmarks/list/${user}`;
const query = {
sort_ascending,
page_size,
page_index,
maybe_scoped_entity_type: maybe_scoped_entity_type
? maybe_scoped_entity_type.join(",")
: undefined,
maybe_scoped_weight_type: maybe_scoped_weight_type
? maybe_scoped_weight_type.join(",")
: undefined,
maybe_scoped_media_file_type: maybe_scoped_media_file_type
? maybe_scoped_media_file_type.join(",")
: undefined,
};
return this.get<{
success?: boolean;
pagination?: Pagination;
results: UserBookmarkByUser[];
}>({ endpoint, query })
.then((response) => ({
success: response.success ?? false,
data: response.results,
pagination: response.pagination,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
public ListUserBookmarksByEntity({
entityType,
entityToken,
}: {
entityType: string;
entityToken: string;
}): Promise<ApiResponse<UserBookmarkByEntity[]>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/user_bookmarks/list/${entityType}/${entityToken}`;
return this.get<{
success: boolean;
user_bookmarks: UserBookmarkByEntity[];
}>({ endpoint })
.then((response) => ({
success: true,
data: response.user_bookmarks,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
}
@@ -1,53 +0,0 @@
import { ApiManager, ApiResponse } from "./ApiManager";
interface VoiceConversionParams {
autoPredictF0?: boolean;
creatorSetVisibility?: string;
isStorytellerDemo?: boolean;
overrideF0Method?: string;
sourceMediaUploadToken: string;
transpose?: number;
uuidIdempotencyToken: string;
voiceConversionModelToken: string;
}
interface VoiceConversionRequest {
auto_predict_f0: boolean;
creator_set_visibility: string;
is_storyteller_demo: boolean;
override_f0_method: string;
source_media_upload_token: string;
transpose: number;
uuid_idempotency_token: string;
voice_conversion_model_token: string;
}
export class VoiceConversionApi extends ApiManager {
public ConvertVoice(
params: VoiceConversionParams,
): Promise<ApiResponse<string>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/voice_conversion/inference`;
const body = this.parseBodyValues<
VoiceConversionParams,
VoiceConversionRequest
>(params);
return this.post<
VoiceConversionRequest,
{
success?: boolean;
inference_job_token?: string;
BadInput?: string;
}
>({ endpoint, body })
.then((response) => ({
success: response.success ?? false,
data: response.inference_job_token,
errorMessage: response.BadInput,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
}
@@ -1,78 +0,0 @@
import { ApiManager, ApiResponse } from "./ApiManager";
import type { Pagination } from "@storyteller/ui-pagescene";
import { authentication } from "~/signals";
import { ZsDataset } from "~/models/Dataset";
interface VoiceDesignerParams {
text: string;
uuidIdempotencyToken: string;
voiceToken: string;
}
interface VoiceDesignerRequest {
text: string;
uuid_idempotency_token: string;
voice_token: string;
}
export class VoiceDesignerApi extends ApiManager {
public EnqueueTts(
params: VoiceDesignerParams,
): Promise<
ApiResponse<{ inference_job_token?: string; voice_token?: string }>
> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/voice_designer/enqueue_tts`;
const body = this.parseBodyValues<
VoiceDesignerParams,
VoiceDesignerRequest
>(params);
return this.post<
VoiceDesignerRequest,
{
success?: boolean;
inference_job_token?: string;
voice_token: string;
BadInput?: string;
}
>({ endpoint, body })
.then((response) => ({
success: response.success ?? false,
...(response.success
? {
data: {
inference_job_token: response.inference_job_token,
voice_token: response.voice_token,
},
}
: {}),
errorMessage: response.BadInput,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
public ListDatasetsByUser({
username,
}: {
username?: string;
}): Promise<ApiResponse<ZsDataset[]>> {
const user = username ?? authentication.userInfo.value?.username;
const endpoint = `${this.getApiSchemeAndHost()}/v1/voice_designer/user/${user}/list`;
return this.get<{
success: boolean;
datasets: ZsDataset[];
pagination: Pagination;
}>({ endpoint })
.then((response) => ({
success: true,
data: response.datasets,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
}
@@ -275,7 +275,7 @@ export class WeightsApi extends ApiManager {
weightToken: string;
coverImageMediaFileToken: string;
}): Promise<ApiResponse<undefined>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/weights/${weightToken}/cover_image`;
const endpoint = `${this.getApiSchemeAndHost()}/v1/weights/weight/${weightToken}/cover_image`;
const body = {
cover_image_media_file_token: coverImageMediaFileToken,
@@ -1,5 +1,4 @@
// https://storyteller-docs.netlify.app/#/
export * from "./AnalyticsApi";
export * from "./BetaKeysApi";
export * from "./BillingApi";
export * from "./CommentsApi";
@@ -1,39 +0,0 @@
import { authentication } from "~/signals";
import { UserInfo } from "~/models";
import EnvironmentVariables from "~/Classes/EnvironmentVariables";
import { AnalyticsApi } from "~/Classes/ApiManager/AnalyticsApi";
import testUpdateDeleteEndpoints from "./utils/testUpdateDeleteEndpoints";
EnvironmentVariables.initialize({ BASE_API: "http://localhost:3000" });
describe("AnalyticsApi", () => {
beforeAll(() => {
authentication.userInfo.value = {
user_token: "un1",
username: "un1",
} as UserInfo;
});
describe("run tests", () => {
const api = new AnalyticsApi();
[
{
name: "PostAnalytics",
function: api.PostAnalytics.bind(api),
endpoint: "http://localhost:3000/v1/analytics/log_session",
method: "POST",
paramsIn: {
maybeLastAction: "mla1",
maybeLogToken: "mlt1",
},
paramsTest: {
maybe_last_action: "mla1",
maybe_log_token: "mlt1",
},
response: { success: true, log_token: "lt1" },
data: "lt1",
},
].forEach((testMethod) => {
testUpdateDeleteEndpoints(api, testMethod);
});
});
});
@@ -1,58 +1,7 @@
import { authentication } from "~/signals";
import { UserInfo } from "~/models";
import EnvironmentVariables from "~/Classes/EnvironmentVariables";
import {
ScopedEntityTypes,
ScopedMediaFileType,
ScopedWeightTypes,
UserBookmarksApi,
} from "~/Classes/ApiManager/UserBookmarksApi";
const mockBookmark = {
created_at: "2024-06-15T11:15:26.997Z",
details: {
entity_token: "string",
entity_type: "user",
maybe_media_file_data: {
maybe_creator: {
default_avatar: {
color_index: 0,
image_index: 0,
},
display_name: "string",
gravatar_hash: "string",
user_token: "string",
username: "string",
},
media_type: "audio",
public_bucket_path: "string",
},
maybe_summary_text: "string",
maybe_thumbnail_url: "string",
maybe_weight_data: {
maybe_cover_image_public_bucket_path: "string",
maybe_creator: {
default_avatar: {
color_index: 0,
image_index: 0,
},
display_name: "string",
gravatar_hash: "string",
user_token: "string",
username: "string",
},
title: "string",
weight_category: "image_generation",
weight_type: "hifigan_tt2",
},
stats: {
bookmark_count: 0,
positive_rating_count: 0,
},
},
token: "string",
updated_at: "2024-06-15T11:15:26.997Z",
};
import { UserBookmarksApi } from "~/Classes/ApiManager/UserBookmarksApi";
describe("UserBookmarksApi", () => {
beforeAll(() => {
@@ -286,192 +235,4 @@ describe("UserBookmarksApi", () => {
});
});
describe("ListUserBookmarksByUser", () => {
it("no params", async () => {
const api = new UserBookmarksApi();
jest.spyOn(api, "fetch").mockResolvedValue({
pagination: {
current: 0,
total_page_count: 0,
},
results: [mockBookmark],
success: true,
});
const response = await api.ListUserBookmarksByUser({});
expect(api.fetch).toHaveBeenCalledWith(
"http://localhost:3000/v1/user_bookmarks/list/un1",
{
method: "GET",
query: {
maybe_scoped_entity_type: undefined,
maybe_scoped_media_file_type: undefined,
maybe_scoped_weight_type: undefined,
page_index: undefined,
page_size: undefined,
sort_ascending: undefined,
},
},
);
expect(response).toEqual({
success: true,
data: [mockBookmark],
pagination: {
current: 0,
total_page_count: 0,
},
});
});
it("all params", async () => {
const api = new UserBookmarksApi();
jest.spyOn(api, "fetch").mockResolvedValue({
pagination: {
current: 0,
total_page_count: 0,
},
results: [mockBookmark],
success: true,
});
const response = await api.ListUserBookmarksByUser({
username: "user1",
sort_ascending: true,
page_size: 76,
page_index: 2,
maybe_scoped_entity_type: [ScopedEntityTypes.MEDIA_FILE],
maybe_scoped_weight_type: [
ScopedWeightTypes.COMFY_UI,
ScopedWeightTypes.SDXL,
],
maybe_scoped_media_file_type: [
ScopedMediaFileType.IMAGE_GENERATION,
ScopedMediaFileType.TEXT_TO_SPEECH,
ScopedMediaFileType.WORKFLOW_CONFIG,
],
});
expect(api.fetch).toHaveBeenCalledWith(
"http://localhost:3000/v1/user_bookmarks/list/user1",
{
method: "GET",
query: {
maybe_scoped_entity_type: "media_file",
maybe_scoped_media_file_type:
"image_generation,text_to_speech,workflow_config",
maybe_scoped_weight_type: "comfy_ui,sdxl",
page_index: 2,
page_size: 76,
sort_ascending: true,
},
},
);
expect(response).toEqual({
success: true,
data: [mockBookmark],
pagination: {
current: 0,
total_page_count: 0,
},
});
});
it("exception", async () => {
const api = new UserBookmarksApi();
jest.spyOn(api, "fetch").mockRejectedValue(new Error("server error"));
const response = await api.ListUserBookmarksByUser({});
expect(api.fetch).toHaveBeenCalledWith(
"http://localhost:3000/v1/user_bookmarks/list/un1",
{
method: "GET",
query: {
maybe_scoped_entity_type: undefined,
maybe_scoped_media_file_type: undefined,
maybe_scoped_weight_type: undefined,
page_index: undefined,
page_size: undefined,
sort_ascending: undefined,
},
},
);
expect(response).toEqual({
success: false,
errorMessage: "server error",
});
});
});
describe("ListUserBookmarksByEntity", () => {
it("success", async () => {
const api = new UserBookmarksApi();
jest.spyOn(api, "fetch").mockResolvedValue({
success: true,
user_bookmarks: [
{
created_at: "2024-06-15T11:34:56.678Z",
token: "string",
updated_at: "2024-06-15T11:34:56.678Z",
user: {
default_avatar: {
color_index: 0,
image_index: 0,
},
display_name: "string",
gravatar_hash: "string",
user_token: "string",
username: "string",
},
},
],
});
const response = await api.ListUserBookmarksByEntity({
entityType: "et1",
entityToken: "tok1",
});
expect(api.fetch).toHaveBeenCalledWith(
"http://localhost:3000/v1/user_bookmarks/list/et1/tok1",
{
method: "GET",
query: undefined,
},
);
expect(response).toEqual({
success: true,
data: [
{
created_at: "2024-06-15T11:34:56.678Z",
token: "string",
updated_at: "2024-06-15T11:34:56.678Z",
user: {
default_avatar: {
color_index: 0,
image_index: 0,
},
display_name: "string",
gravatar_hash: "string",
user_token: "string",
username: "string",
},
},
],
});
});
it("exception", async () => {
const api = new UserBookmarksApi();
jest.spyOn(api, "fetch").mockRejectedValue(new Error("server error"));
const response = await api.ListUserBookmarksByEntity({
entityType: "et1",
entityToken: "tok1",
});
expect(api.fetch).toHaveBeenCalledWith(
"http://localhost:3000/v1/user_bookmarks/list/et1/tok1",
{
method: "GET",
query: undefined,
},
);
expect(response).toEqual({
success: false,
errorMessage: "server error",
});
});
});
});
@@ -1,52 +0,0 @@
import { authentication } from "~/signals";
import { UserInfo } from "~/models";
import EnvironmentVariables from "~/Classes/EnvironmentVariables";
import testUpdateDeleteEndpoints from "./utils/testUpdateDeleteEndpoints";
import { VoiceConversionApi } from "~/Classes/ApiManager/VoiceConversionApi";
EnvironmentVariables.initialize({ BASE_API: "http://localhost:3000" });
describe("VoiceConversionApi", () => {
beforeAll(() => {
authentication.userInfo.value = {
user_token: "un1",
username: "un1",
} as UserInfo;
});
describe("run tests", () => {
const api = new VoiceConversionApi();
[
{
name: "PostAnalytics",
function: api.ConvertVoice.bind(api),
endpoint: "http://localhost:3000/v1/voice_conversion/inference",
method: "POST",
hasFailure: true,
paramsIn: {
autoPredictF0: true,
creatorSetVisibility: "public",
isStorytellerDemo: true,
overrideF0Method: "rmvpe",
sourceMediaUploadToken: "sourceToken123",
transpose: 2,
uuidIdempotencyToken: "uuid-1234-5678",
voiceConversionModelToken: "voiceModelToken123",
},
paramsTest: {
auto_predict_f0: true,
creator_set_visibility: "public",
is_storyteller_demo: true,
override_f0_method: "rmvpe",
source_media_upload_token: "sourceToken123",
transpose: 2,
uuid_idempotency_token: "uuid-1234-5678",
voice_conversion_model_token: "voiceModelToken123",
},
response: { inference_job_token: "ijt1" },
data: "ijt1",
},
].forEach((testMethod) => {
testUpdateDeleteEndpoints(api, testMethod);
});
});
});
@@ -1,93 +0,0 @@
import { authentication } from "~/signals";
import { UserInfo } from "~/models";
import EnvironmentVariables from "~/Classes/EnvironmentVariables";
import testUpdateDeleteEndpoints from "./utils/testUpdateDeleteEndpoints";
import { VoiceDesignerApi } from "~/Classes/ApiManager/VoiceDesignerApi";
import testListEndpoints from "./utils/testListEndpoints";
const mockDataset = {
created_at: "2024-06-18T11:11:03.533Z",
creator: {
default_avatar: {
color_index: 3,
image_index: 1,
},
display_name: "JaneDoe",
gravatar_hash: "b1c967db4babc4eebc51abfa7a3e74d5",
user_token: "user-token-9876",
username: "janedoe",
},
creator_set_visibility: "private",
dataset_token: "dataset-token-456",
ietf_language_tag: "fr-FR",
ietf_primary_language_subtag: "fr",
title: "French Language Dataset",
updated_at: "2024-06-18T12:15:30.000Z",
};
EnvironmentVariables.initialize({ BASE_API: "http://localhost:3000" });
describe("VoiceDesignerApi", () => {
beforeAll(() => {
authentication.userInfo.value = {
user_token: "un1",
username: "un1",
} as UserInfo;
});
describe("run tests", () => {
const api = new VoiceDesignerApi();
[
{
name: "PostAnalytics",
function: api.EnqueueTts.bind(api),
endpoint: "http://localhost:3000/v1/voice_designer/enqueue_tts",
method: "POST",
hasFailure: true,
paramsIn: {
text: "Sample text 1",
uuidIdempotencyToken: "uuid-1234-5678-abcdef",
voiceToken: "voice-token-1",
},
paramsTest: {
text: "Sample text 1",
uuid_idempotency_token: "uuid-1234-5678-abcdef",
voice_token: "voice-token-1",
},
response: { inference_job_token: "ijt1", voice_token: "vt1" },
data: { inference_job_token: "ijt1", voice_token: "vt1" },
},
].forEach((testMethod) => {
testUpdateDeleteEndpoints(api, testMethod);
});
});
describe("run list tests", () => {
const api = new VoiceDesignerApi();
[
{
name: "ListWeightsByUser",
function: api.ListDatasetsByUser.bind(api),
tests: [
{
name: "no user",
endpoint: "http://localhost:3000/v1/voice_designer/user/un1/list",
query: {},
fetchQuery: undefined,
response: { datasets: [mockDataset] },
data: [mockDataset],
},
{
name: "user",
endpoint: "http://localhost:3000/v1/voice_designer/user/user1/list",
query: { username: "user1" },
fetchQuery: undefined,
response: { datasets: [mockDataset] },
data: [mockDataset],
},
],
},
].forEach((testMethod) => {
testListEndpoints(api, testMethod);
});
});
});
-1
View File
@@ -3,7 +3,6 @@ export * from "./lib/enums/Job.js";
export * from "./lib/models/Users.js";
export * from "./lib/models/Job.js";
export * from "./lib/models/Prompts.js";
export * from "./lib/AnalyticsApi.js";
export * from "./lib/BillingApi.js";
export * from "./lib/CreditsApi.js";
export * from "./lib/GenerationApi.js";
-38
View File
@@ -1,38 +0,0 @@
import { ApiManager, ApiResponse } from "./ApiManager.js";
export class AnalyticsApi extends ApiManager {
public PostAnalytics({
maybeLastAction,
maybeLogToken,
}: {
maybeLastAction: string;
maybeLogToken: string;
}): Promise<ApiResponse<string>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/analytics/log_session`;
const body = {
maybe_last_action: maybeLastAction,
maybe_log_token: maybeLogToken,
};
return this.post<
{
maybe_last_action: string;
maybe_log_token: string;
},
{
success?: boolean;
log_token?: string;
BadInput?: string;
}
>({ endpoint, body })
.then((response) => ({
success: response.success ?? false,
data: response.log_token,
errorMessage: response.BadInput,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
}
-124
View File
@@ -86,128 +86,4 @@ export class EngineApi extends ApiManager {
return result;
}
public async enqueueImageGeneration({
disableSystemPrompt,
prompt,
snapshotMediaToken,
additionalImages,
}: {
disableSystemPrompt: boolean;
prompt: string;
snapshotMediaToken: string;
additionalImages?: string[];
}): Promise<ApiResponse<string>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/image_studio/prompt`;
const uuidIdempotencyToken = crypto.randomUUID(); // Generate a new UUID
const body = {
uuid_idempotency_token: uuidIdempotencyToken,
disable_system_prompt: disableSystemPrompt,
prompt,
snapshot_media_token: snapshotMediaToken, // Changed from scene_media_token to snapshot_media_token
additional_images: additionalImages,
};
const postResponse = await this.post<
{
uuid_idempotency_token: string;
disable_system_prompt: boolean;
prompt: string;
snapshot_media_token: string;
additional_images?: string[];
},
{ success?: boolean; job_token?: string; BadInput?: string }
>({
endpoint,
body,
});
// Check if the response is successful
const isSuccess = postResponse.success ?? false;
// Prepare the result object
const result = {
success: isSuccess,
data: isSuccess ? postResponse.job_token : undefined,
errorMessage: isSuccess ? undefined : postResponse.BadInput,
};
return result;
}
public async pollJobSession(jobToken: string): Promise<
ApiResponse<{
status: string;
result: {
generated_images?: string[];
error?: string;
};
}>
> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/jobs/session/${jobToken}`;
const response = await this.get<{
success?: boolean;
status?: string;
result?: {
generated_images?: string[];
error?: string;
};
BadInput?: string;
}>({
endpoint,
});
const success = response.success ?? false;
const status = response.status ?? "";
const result = response.result ?? {
generated_images: [],
error: undefined,
};
const errorMessage = response.BadInput;
return {
success,
data: { status, result },
errorMessage,
};
}
public async pollStudioSessionJobs(jobToken: string): Promise<
ApiResponse<{
status: string;
result: {
generated_images?: string[];
error?: string;
};
}>
> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/image_studio/session_jobs/${jobToken}`;
const response = await this.get<{
success?: boolean;
status?: string;
result?: {
generated_images?: string[];
error?: string;
};
BadInput?: string;
}>({
endpoint,
});
const success = response.success ?? false;
const status = response.status ?? "";
const result = response.result ?? {
generated_images: [],
error: undefined,
};
const errorMessage = response.BadInput;
return {
success,
data: { status, result },
errorMessage,
};
}
}
-89
View File
@@ -3,57 +3,6 @@ import { Prompts } from "./models/Prompts.js";
import { FetchProxy as fetch } from "@storyteller/tauri-utils";
export class PromptsApi extends ApiManager {
public async enqueueImageGeneration({
disableSystemPrompt,
prompt,
snapshotMediaToken,
additionalImages,
}: {
disableSystemPrompt: boolean;
prompt: string;
snapshotMediaToken: string;
additionalImages?: string[];
}): Promise<ApiResponse<string>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/image_studio/prompt`;
const uuidIdempotencyToken = crypto.randomUUID(); // Generate a new UUID
const body = {
uuid_idempotency_token: uuidIdempotencyToken,
disable_system_prompt: disableSystemPrompt,
prompt,
snapshot_media_token: snapshotMediaToken, // Changed from scene_media_token to snapshot_media_token
additional_images: additionalImages,
};
const postResponse = await this.post<
{
uuid_idempotency_token: string;
disable_system_prompt: boolean;
prompt: string;
snapshot_media_token: string;
additional_images?: string[];
},
{ success?: boolean; job_token?: string; BadInput?: string }
>({
endpoint,
body,
});
// Check if the response is successful
const isSuccess = postResponse.success ?? false;
// Prepare the result object
console.log("postResponse FOR ENQUEUE IMAGE GENERATION");
console.log(postResponse);
const result = {
success: isSuccess,
data: isSuccess ? postResponse.job_token : undefined,
errorMessage: isSuccess ? undefined : postResponse.BadInput,
};
return result;
}
public async pollJobSession(
jobToken: string,
thumbnailWidth = 256
@@ -130,44 +79,6 @@ export class PromptsApi extends ApiManager {
};
}
public async pollStudioSessionJobs(jobToken: string): Promise<
ApiResponse<{
status: string;
result: {
generated_images?: string[];
error?: string;
};
}>
> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/image_studio/session_jobs/${jobToken}`;
const response = await this.get<{
success?: boolean;
status?: string;
result?: {
generated_images?: string[];
error?: string;
};
BadInput?: string;
}>({
endpoint,
});
const success = response.success ?? false;
const status = response.status ?? "";
const result = response.result ?? {
generated_images: [],
error: undefined,
};
const errorMessage = response.BadInput;
return {
success,
data: { status, result },
errorMessage,
};
}
public GetPromptsByToken({
token,
}: {
+1 -113
View File
@@ -1,52 +1,5 @@
import { ApiManager, ApiResponse } from "./ApiManager.js";
import {
UserBookmarkBatch,
UserBookmarkByEntity,
UserBookmarkByUser,
} from "./models/UserBookmark.js";
import { Pagination } from "./models/Pagination.js";
export enum ScopedEntityTypes {
USER = "user",
TTS_MODEL = "tts-model",
TTS_RESULT = "tts-result",
W2L_TEMPLATE = "w2l-template",
W2L_RESULT = "w2l-result",
MEDIA_FILE = "media_file",
MODEL_WEIGHT = "model_weight",
VOICE_CONVERSION_MODEL = "voice_conversion_model",
ZS_VOICE = "z_voice",
}
export enum ScopedWeightTypes {
HIFIGAN_TTl2 = "hifigan_tt2",
RVC_V2 = "rvc_v2",
SD_1_5 = "sd_1.5",
SDXL = "sdxl",
SO_VITS_SVC = "so_vits_svc",
TT2 = "tt2",
LORA = "loRA",
VALL_E = "vall_e",
COMFY_UI = "comfy_ui",
}
export enum ScopedMediaFileType {
IMAGE_GENERATION = "image_generation",
TEXT_TO_SPEECH = "text_to_speech",
VOCODER = "vocoder",
VOICE_CONVERSION = "voice_conversion",
WORKFLOW_CONFIG = "workflow_config",
}
interface ListUserBookmarksByUserRequest {
username: string;
sort_ascending?: boolean;
page_size?: number;
page_index?: number;
maybe_scoped_entity_type?: ScopedEntityTypes[];
maybe_scoped_weight_type?: ScopedWeightTypes[];
maybe_scoped_media_file_type?: ScopedMediaFileType[];
}
import { UserBookmarkBatch } from "./models/UserBookmark.js";
export class UserBookmarksApi extends ApiManager {
public CreateUserBookmark({
@@ -133,69 +86,4 @@ export class UserBookmarksApi extends ApiManager {
});
}
public ListUserBookmarksByUser({
username,
sort_ascending,
page_size,
page_index,
maybe_scoped_entity_type,
maybe_scoped_weight_type,
maybe_scoped_media_file_type,
}: ListUserBookmarksByUserRequest): Promise<
ApiResponse<UserBookmarkByUser[], Pagination>
> {
const user = username;
const endpoint = `${this.getApiSchemeAndHost()}/v1/user_bookmarks/list/${user}`;
const query = {
sort_ascending,
page_size,
page_index,
maybe_scoped_entity_type: maybe_scoped_entity_type
? maybe_scoped_entity_type.join(",")
: undefined,
maybe_scoped_weight_type: maybe_scoped_weight_type
? maybe_scoped_weight_type.join(",")
: undefined,
maybe_scoped_media_file_type: maybe_scoped_media_file_type
? maybe_scoped_media_file_type.join(",")
: undefined,
};
return this.get<{
success?: boolean;
pagination?: Pagination;
results: UserBookmarkByUser[];
}>({ endpoint, query })
.then((response) => ({
success: response.success ?? false,
data: response.results,
pagination: response.pagination,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
public ListUserBookmarksByEntity({
entityType,
entityToken,
}: {
entityType: string;
entityToken: string;
}): Promise<ApiResponse<UserBookmarkByEntity[]>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/user_bookmarks/list/${entityType}/${entityToken}`;
return this.get<{
success: boolean;
user_bookmarks: UserBookmarkByEntity[];
}>({ endpoint })
.then((response) => ({
success: true,
data: response.user_bookmarks,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
}
@@ -1,53 +0,0 @@
import { ApiManager, ApiResponse } from "./ApiManager.js";
interface VoiceConversionParams {
autoPredictF0?: boolean;
creatorSetVisibility?: string;
isStorytellerDemo?: boolean;
overrideF0Method?: string;
sourceMediaUploadToken: string;
transpose?: number;
uuidIdempotencyToken: string;
voiceConversionModelToken: string;
}
interface VoiceConversionRequest {
auto_predict_f0: boolean;
creator_set_visibility: string;
is_storyteller_demo: boolean;
override_f0_method: string;
source_media_upload_token: string;
transpose: number;
uuid_idempotency_token: string;
voice_conversion_model_token: string;
}
export class VoiceConversionApi extends ApiManager {
public ConvertVoice(
params: VoiceConversionParams,
): Promise<ApiResponse<string>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/voice_conversion/inference`;
const body = this.parseBodyValues<
VoiceConversionParams,
VoiceConversionRequest
>(params);
return this.post<
VoiceConversionRequest,
{
success?: boolean;
inference_job_token?: string;
BadInput?: string;
}
>({ endpoint, body })
.then((response) => ({
success: response.success ?? false,
data: response.inference_job_token,
errorMessage: response.BadInput,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
}
@@ -1,77 +0,0 @@
import { ApiManager, ApiResponse } from "./ApiManager.js";
import { Pagination } from "./models/Pagination.js";
import { ZsDataset } from "./models/Dataset.js";
interface VoiceDesignerParams {
text: string;
uuidIdempotencyToken: string;
voiceToken: string;
}
interface VoiceDesignerRequest {
text: string;
uuid_idempotency_token: string;
voice_token: string;
}
export class VoiceDesignerApi extends ApiManager {
public EnqueueTts(
params: VoiceDesignerParams,
): Promise<
ApiResponse<{ inference_job_token?: string; voice_token?: string }>
> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/voice_designer/enqueue_tts`;
const body = this.parseBodyValues<
VoiceDesignerParams,
VoiceDesignerRequest
>(params);
return this.post<
VoiceDesignerRequest,
{
success?: boolean;
inference_job_token?: string;
voice_token: string;
BadInput?: string;
}
>({ endpoint, body })
.then((response) => ({
success: response.success ?? false,
...(response.success
? {
data: {
inference_job_token: response.inference_job_token,
voice_token: response.voice_token,
},
}
: {}),
errorMessage: response.BadInput,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
public ListDatasetsByUser({
username,
}: {
username: string;
}): Promise<ApiResponse<ZsDataset[]>> {
const user = username;
const endpoint = `${this.getApiSchemeAndHost()}/v1/voice_designer/user/${user}/list`;
return this.get<{
success: boolean;
datasets: ZsDataset[];
pagination: Pagination;
}>({ endpoint })
.then((response) => ({
success: true,
data: response.datasets,
}))
.catch((err) => {
return { success: false, errorMessage: err.message };
});
}
}
+1 -1
View File
@@ -274,7 +274,7 @@ export class WeightsApi extends ApiManager {
weightToken: string;
coverImageMediaFileToken: string;
}): Promise<ApiResponse<undefined>> {
const endpoint = `${this.getApiSchemeAndHost()}/v1/weights/${weightToken}/cover_image`;
const endpoint = `${this.getApiSchemeAndHost()}/v1/weights/weight/${weightToken}/cover_image`;
const body = {
cover_image_media_file_token: coverImageMediaFileToken,
@@ -4,72 +4,3 @@ export interface UserBookmarkBatch {
is_bookmarked: boolean;
maybe_bookmark_token: string;
}
interface DefaultAvatar {
color_index: number;
image_index: number;
}
interface User {
default_avatar: DefaultAvatar;
display_name: string;
gravatar_hash: string;
user_token: string;
username: string;
}
export interface UserBookmarkByEntity {
created_at: string;
token: string;
updated_at: string;
user: User;
}
interface DefaultAvatar {
color_index: number;
image_index: number;
}
interface Creator {
default_avatar: DefaultAvatar;
display_name: string;
gravatar_hash: string;
user_token: string;
username: string;
}
interface MediaFileData {
maybe_creator: Creator;
media_type: string; // Adjust type as per your specific schema
public_bucket_path: string;
}
interface WeightData {
maybe_cover_image_public_bucket_path: string;
maybe_creator: Creator;
title: string;
weight_category: string; // Adjust type as per your specific schema
weight_type: string; // Adjust type as per your specific schema
}
interface Stats {
bookmark_count: number;
positive_rating_count: number;
}
interface Details {
entity_token: string;
entity_type: string; // Adjust type as per your specific schema
maybe_media_file_data?: MediaFileData;
maybe_summary_text?: string;
maybe_thumbnail_url?: string;
maybe_weight_data?: WeightData;
stats: Stats;
}
export interface UserBookmarkByUser {
created_at: string;
details: Details;
token: string;
updated_at: string;
}