@golpoai/sdk 0.1.0
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/dist/index.cjs +187 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +150 -0
- package/package.json +32 -0
package/dist/index.cjs
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
|
30
|
+
// src/index.ts
|
31
|
+
var index_exports = {};
|
32
|
+
__export(index_exports, {
|
33
|
+
Golpo: () => Golpo,
|
34
|
+
default: () => Golpo
|
35
|
+
});
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
37
|
+
|
38
|
+
// src/Golpo.ts
|
39
|
+
var import_axios = __toESM(require("axios"), 1);
|
40
|
+
var import_fs = require("fs");
|
41
|
+
var import_fs2 = require("fs");
|
42
|
+
var import_path = require("path");
|
43
|
+
var import_mime_types = require("mime-types");
|
44
|
+
var import_p_limit = __toESM(require("p-limit"), 1);
|
45
|
+
var URL_RE = /^(https?|s3):\/\//i;
|
46
|
+
var Golpo = class {
|
47
|
+
http;
|
48
|
+
constructor(apiKey, baseUrl = "https://api.golpoai.com") {
|
49
|
+
this.http = import_axios.default.create({
|
50
|
+
baseURL: baseUrl.replace(/\/+$/, ""),
|
51
|
+
headers: { "x-api-key": apiKey }
|
52
|
+
});
|
53
|
+
}
|
54
|
+
/* ------------------------------------------------------------ *
|
55
|
+
* PUBLIC API
|
56
|
+
* ------------------------------------------------------------ */
|
57
|
+
async createPodcast(prompt, opts = {}) {
|
58
|
+
const {
|
59
|
+
uploads,
|
60
|
+
pollIntervalMs = 2e3,
|
61
|
+
concurrency = 8,
|
62
|
+
addMusic = false,
|
63
|
+
voiceInstructions,
|
64
|
+
personality1,
|
65
|
+
personality2,
|
66
|
+
doResearch = false,
|
67
|
+
ttsModel = "accurate",
|
68
|
+
language,
|
69
|
+
style = "conversational",
|
70
|
+
bgMusic
|
71
|
+
} = opts;
|
72
|
+
const fields = [
|
73
|
+
["prompt", prompt],
|
74
|
+
["add_music", String(addMusic)],
|
75
|
+
["do_research", String(doResearch)],
|
76
|
+
["tts_model", ttsModel],
|
77
|
+
["style", style]
|
78
|
+
];
|
79
|
+
if (voiceInstructions) fields.push(["voice_instructions", voiceInstructions]);
|
80
|
+
if (personality1) fields.push(["personality_1", personality1]);
|
81
|
+
if (personality2) fields.push(["personality_2", personality2]);
|
82
|
+
if (language) fields.push(["language", language]);
|
83
|
+
if (bgMusic) fields.push(["bg_music", bgMusic]);
|
84
|
+
await this.attachUploads(fields, uploads, concurrency);
|
85
|
+
const { data } = await this.http.post("/generate", new URLSearchParams(fields), {
|
86
|
+
timeout: 6e4
|
87
|
+
});
|
88
|
+
return this.poll(
|
89
|
+
data.job_id,
|
90
|
+
pollIntervalMs
|
91
|
+
).then((r) => ({
|
92
|
+
podcastUrl: r.podcast_url,
|
93
|
+
podcastScript: r.podcast_script
|
94
|
+
}));
|
95
|
+
}
|
96
|
+
async createVideo(prompt, opts = {}) {
|
97
|
+
const {
|
98
|
+
uploads,
|
99
|
+
pollIntervalMs = 2e3,
|
100
|
+
concurrency = 8,
|
101
|
+
voiceInstructions,
|
102
|
+
personality1,
|
103
|
+
doResearch = false,
|
104
|
+
ttsModel = "accurate",
|
105
|
+
language,
|
106
|
+
style = "solo-female",
|
107
|
+
bgMusic = "engaging",
|
108
|
+
bgVolume = 1.4,
|
109
|
+
videoType = "long",
|
110
|
+
includeWatermark = true,
|
111
|
+
logo,
|
112
|
+
timing = "1"
|
113
|
+
} = opts;
|
114
|
+
const fields = [
|
115
|
+
["prompt", prompt],
|
116
|
+
["do_research", String(doResearch)],
|
117
|
+
["tts_model", ttsModel],
|
118
|
+
["bg_volume", String(bgVolume)],
|
119
|
+
["style", style],
|
120
|
+
["video_type", videoType],
|
121
|
+
["include_watermark", String(includeWatermark)],
|
122
|
+
["timing", timing]
|
123
|
+
];
|
124
|
+
if (language) fields.push(["language", language]);
|
125
|
+
if (voiceInstructions) fields.push(["voice_instructions", voiceInstructions]);
|
126
|
+
if (personality1) fields.push(["personality_1", personality1]);
|
127
|
+
if (bgMusic) fields.push(["bg_music", bgMusic]);
|
128
|
+
if (logo) fields.push(["logo", await this.normalizeUpload(logo)]);
|
129
|
+
await this.attachUploads(fields, uploads, concurrency);
|
130
|
+
const { data } = await this.http.post("/generate", new URLSearchParams(fields), {
|
131
|
+
timeout: 6e4
|
132
|
+
});
|
133
|
+
return this.poll(
|
134
|
+
data.job_id,
|
135
|
+
pollIntervalMs
|
136
|
+
).then((r) => ({
|
137
|
+
videoUrl: r.podcast_url,
|
138
|
+
videoScript: r.podcast_script
|
139
|
+
}));
|
140
|
+
}
|
141
|
+
/* ------------------------------------------------------------ *
|
142
|
+
* INTERNAL HELPERS
|
143
|
+
* ------------------------------------------------------------ */
|
144
|
+
async poll(jobId, interval) {
|
145
|
+
while (true) {
|
146
|
+
const { data } = await this.http.get(`/status/${jobId}`);
|
147
|
+
if (data.status === "completed") return data;
|
148
|
+
await new Promise((r) => setTimeout(r, interval));
|
149
|
+
}
|
150
|
+
}
|
151
|
+
async attachUploads(fields, uploads, concurrency) {
|
152
|
+
if (!uploads) return;
|
153
|
+
const list = typeof uploads === "string" ? [uploads] : [...uploads];
|
154
|
+
const limit = (0, import_p_limit.default)(concurrency);
|
155
|
+
const passthrough = await Promise.all(
|
156
|
+
list.map(
|
157
|
+
(item) => limit(async () => {
|
158
|
+
const str = item.trim().replace(/^<|>$/g, "");
|
159
|
+
return URL_RE.test(str) ? str : this.uploadToS3((0, import_path.resolve)(str));
|
160
|
+
})
|
161
|
+
)
|
162
|
+
);
|
163
|
+
passthrough.forEach((url) => fields.push(["upload_urls", url]));
|
164
|
+
}
|
165
|
+
async normalizeUpload(pathOrUrl) {
|
166
|
+
const trimmed = pathOrUrl.trim().replace(/^<|>$/g, "");
|
167
|
+
return URL_RE.test(trimmed) ? trimmed : this.uploadToS3((0, import_path.resolve)(trimmed));
|
168
|
+
}
|
169
|
+
async uploadToS3(absPath) {
|
170
|
+
const { data: presign } = await this.http.post("/upload-url", new URLSearchParams({ filename: (0, import_path.basename)(absPath) }), {
|
171
|
+
timeout: 3e4
|
172
|
+
});
|
173
|
+
const mime = (0, import_mime_types.lookup)(absPath) || "application/octet-stream";
|
174
|
+
const size = (0, import_fs2.statSync)(absPath).size;
|
175
|
+
await import_axios.default.put(presign.url, (0, import_fs.createReadStream)(absPath), {
|
176
|
+
headers: { "Content-Type": mime, "Content-Length": size },
|
177
|
+
maxBodyLength: Infinity,
|
178
|
+
maxContentLength: Infinity,
|
179
|
+
timeout: 6e4
|
180
|
+
});
|
181
|
+
return presign.url.split("?", 1)[0];
|
182
|
+
}
|
183
|
+
};
|
184
|
+
// Annotate the CommonJS export names for ESM import in node:
|
185
|
+
0 && (module.exports = {
|
186
|
+
Golpo
|
187
|
+
});
|
package/dist/index.d.cts
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
interface CreatePodcastOptions {
|
2
|
+
uploads?: string | Iterable<string>;
|
3
|
+
addMusic?: boolean;
|
4
|
+
voiceInstructions?: string;
|
5
|
+
personality1?: string;
|
6
|
+
personality2?: string;
|
7
|
+
doResearch?: boolean;
|
8
|
+
ttsModel?: 'accurate' | 'fast';
|
9
|
+
language?: string;
|
10
|
+
style?: 'conversational' | 'solo-male' | 'solo-female';
|
11
|
+
bgMusic?: 'jazz' | 'lofi' | 'dramatic' | null;
|
12
|
+
pollIntervalMs?: number;
|
13
|
+
concurrency?: number;
|
14
|
+
}
|
15
|
+
interface CreateVideoOptions {
|
16
|
+
uploads?: string | Iterable<string>;
|
17
|
+
voiceInstructions?: string;
|
18
|
+
personality1?: string;
|
19
|
+
doResearch?: boolean;
|
20
|
+
ttsModel?: 'accurate' | 'fast';
|
21
|
+
language?: string;
|
22
|
+
style?: 'solo-male' | 'solo-female';
|
23
|
+
bgMusic?: 'engaging' | 'lofi' | null;
|
24
|
+
bgVolume?: number;
|
25
|
+
videoType?: 'short' | 'long';
|
26
|
+
includeWatermark?: boolean;
|
27
|
+
logo?: string;
|
28
|
+
timing?: '1' | '2';
|
29
|
+
pollIntervalMs?: number;
|
30
|
+
concurrency?: number;
|
31
|
+
}
|
32
|
+
declare class Golpo {
|
33
|
+
private readonly http;
|
34
|
+
constructor(apiKey: string, baseUrl?: string);
|
35
|
+
createPodcast(prompt: string, opts?: CreatePodcastOptions): Promise<{
|
36
|
+
podcastUrl: string;
|
37
|
+
podcastScript: string;
|
38
|
+
}>;
|
39
|
+
createVideo(prompt: string, opts?: CreateVideoOptions): Promise<{
|
40
|
+
videoUrl: string;
|
41
|
+
videoScript: string;
|
42
|
+
}>;
|
43
|
+
private poll;
|
44
|
+
private attachUploads;
|
45
|
+
private normalizeUpload;
|
46
|
+
private uploadToS3;
|
47
|
+
}
|
48
|
+
|
49
|
+
export { type CreatePodcastOptions, type CreateVideoOptions, Golpo, Golpo as default };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
interface CreatePodcastOptions {
|
2
|
+
uploads?: string | Iterable<string>;
|
3
|
+
addMusic?: boolean;
|
4
|
+
voiceInstructions?: string;
|
5
|
+
personality1?: string;
|
6
|
+
personality2?: string;
|
7
|
+
doResearch?: boolean;
|
8
|
+
ttsModel?: 'accurate' | 'fast';
|
9
|
+
language?: string;
|
10
|
+
style?: 'conversational' | 'solo-male' | 'solo-female';
|
11
|
+
bgMusic?: 'jazz' | 'lofi' | 'dramatic' | null;
|
12
|
+
pollIntervalMs?: number;
|
13
|
+
concurrency?: number;
|
14
|
+
}
|
15
|
+
interface CreateVideoOptions {
|
16
|
+
uploads?: string | Iterable<string>;
|
17
|
+
voiceInstructions?: string;
|
18
|
+
personality1?: string;
|
19
|
+
doResearch?: boolean;
|
20
|
+
ttsModel?: 'accurate' | 'fast';
|
21
|
+
language?: string;
|
22
|
+
style?: 'solo-male' | 'solo-female';
|
23
|
+
bgMusic?: 'engaging' | 'lofi' | null;
|
24
|
+
bgVolume?: number;
|
25
|
+
videoType?: 'short' | 'long';
|
26
|
+
includeWatermark?: boolean;
|
27
|
+
logo?: string;
|
28
|
+
timing?: '1' | '2';
|
29
|
+
pollIntervalMs?: number;
|
30
|
+
concurrency?: number;
|
31
|
+
}
|
32
|
+
declare class Golpo {
|
33
|
+
private readonly http;
|
34
|
+
constructor(apiKey: string, baseUrl?: string);
|
35
|
+
createPodcast(prompt: string, opts?: CreatePodcastOptions): Promise<{
|
36
|
+
podcastUrl: string;
|
37
|
+
podcastScript: string;
|
38
|
+
}>;
|
39
|
+
createVideo(prompt: string, opts?: CreateVideoOptions): Promise<{
|
40
|
+
videoUrl: string;
|
41
|
+
videoScript: string;
|
42
|
+
}>;
|
43
|
+
private poll;
|
44
|
+
private attachUploads;
|
45
|
+
private normalizeUpload;
|
46
|
+
private uploadToS3;
|
47
|
+
}
|
48
|
+
|
49
|
+
export { type CreatePodcastOptions, type CreateVideoOptions, Golpo, Golpo as default };
|
package/dist/index.js
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
// src/Golpo.ts
|
2
|
+
import axios from "axios";
|
3
|
+
import { createReadStream } from "fs";
|
4
|
+
import { statSync } from "fs";
|
5
|
+
import { basename, resolve } from "path";
|
6
|
+
import { lookup as mimeLookup } from "mime-types";
|
7
|
+
import pLimit from "p-limit";
|
8
|
+
var URL_RE = /^(https?|s3):\/\//i;
|
9
|
+
var Golpo = class {
|
10
|
+
http;
|
11
|
+
constructor(apiKey, baseUrl = "https://api.golpoai.com") {
|
12
|
+
this.http = axios.create({
|
13
|
+
baseURL: baseUrl.replace(/\/+$/, ""),
|
14
|
+
headers: { "x-api-key": apiKey }
|
15
|
+
});
|
16
|
+
}
|
17
|
+
/* ------------------------------------------------------------ *
|
18
|
+
* PUBLIC API
|
19
|
+
* ------------------------------------------------------------ */
|
20
|
+
async createPodcast(prompt, opts = {}) {
|
21
|
+
const {
|
22
|
+
uploads,
|
23
|
+
pollIntervalMs = 2e3,
|
24
|
+
concurrency = 8,
|
25
|
+
addMusic = false,
|
26
|
+
voiceInstructions,
|
27
|
+
personality1,
|
28
|
+
personality2,
|
29
|
+
doResearch = false,
|
30
|
+
ttsModel = "accurate",
|
31
|
+
language,
|
32
|
+
style = "conversational",
|
33
|
+
bgMusic
|
34
|
+
} = opts;
|
35
|
+
const fields = [
|
36
|
+
["prompt", prompt],
|
37
|
+
["add_music", String(addMusic)],
|
38
|
+
["do_research", String(doResearch)],
|
39
|
+
["tts_model", ttsModel],
|
40
|
+
["style", style]
|
41
|
+
];
|
42
|
+
if (voiceInstructions) fields.push(["voice_instructions", voiceInstructions]);
|
43
|
+
if (personality1) fields.push(["personality_1", personality1]);
|
44
|
+
if (personality2) fields.push(["personality_2", personality2]);
|
45
|
+
if (language) fields.push(["language", language]);
|
46
|
+
if (bgMusic) fields.push(["bg_music", bgMusic]);
|
47
|
+
await this.attachUploads(fields, uploads, concurrency);
|
48
|
+
const { data } = await this.http.post("/generate", new URLSearchParams(fields), {
|
49
|
+
timeout: 6e4
|
50
|
+
});
|
51
|
+
return this.poll(
|
52
|
+
data.job_id,
|
53
|
+
pollIntervalMs
|
54
|
+
).then((r) => ({
|
55
|
+
podcastUrl: r.podcast_url,
|
56
|
+
podcastScript: r.podcast_script
|
57
|
+
}));
|
58
|
+
}
|
59
|
+
async createVideo(prompt, opts = {}) {
|
60
|
+
const {
|
61
|
+
uploads,
|
62
|
+
pollIntervalMs = 2e3,
|
63
|
+
concurrency = 8,
|
64
|
+
voiceInstructions,
|
65
|
+
personality1,
|
66
|
+
doResearch = false,
|
67
|
+
ttsModel = "accurate",
|
68
|
+
language,
|
69
|
+
style = "solo-female",
|
70
|
+
bgMusic = "engaging",
|
71
|
+
bgVolume = 1.4,
|
72
|
+
videoType = "long",
|
73
|
+
includeWatermark = true,
|
74
|
+
logo,
|
75
|
+
timing = "1"
|
76
|
+
} = opts;
|
77
|
+
const fields = [
|
78
|
+
["prompt", prompt],
|
79
|
+
["do_research", String(doResearch)],
|
80
|
+
["tts_model", ttsModel],
|
81
|
+
["bg_volume", String(bgVolume)],
|
82
|
+
["style", style],
|
83
|
+
["video_type", videoType],
|
84
|
+
["include_watermark", String(includeWatermark)],
|
85
|
+
["timing", timing]
|
86
|
+
];
|
87
|
+
if (language) fields.push(["language", language]);
|
88
|
+
if (voiceInstructions) fields.push(["voice_instructions", voiceInstructions]);
|
89
|
+
if (personality1) fields.push(["personality_1", personality1]);
|
90
|
+
if (bgMusic) fields.push(["bg_music", bgMusic]);
|
91
|
+
if (logo) fields.push(["logo", await this.normalizeUpload(logo)]);
|
92
|
+
await this.attachUploads(fields, uploads, concurrency);
|
93
|
+
const { data } = await this.http.post("/generate", new URLSearchParams(fields), {
|
94
|
+
timeout: 6e4
|
95
|
+
});
|
96
|
+
return this.poll(
|
97
|
+
data.job_id,
|
98
|
+
pollIntervalMs
|
99
|
+
).then((r) => ({
|
100
|
+
videoUrl: r.podcast_url,
|
101
|
+
videoScript: r.podcast_script
|
102
|
+
}));
|
103
|
+
}
|
104
|
+
/* ------------------------------------------------------------ *
|
105
|
+
* INTERNAL HELPERS
|
106
|
+
* ------------------------------------------------------------ */
|
107
|
+
async poll(jobId, interval) {
|
108
|
+
while (true) {
|
109
|
+
const { data } = await this.http.get(`/status/${jobId}`);
|
110
|
+
if (data.status === "completed") return data;
|
111
|
+
await new Promise((r) => setTimeout(r, interval));
|
112
|
+
}
|
113
|
+
}
|
114
|
+
async attachUploads(fields, uploads, concurrency) {
|
115
|
+
if (!uploads) return;
|
116
|
+
const list = typeof uploads === "string" ? [uploads] : [...uploads];
|
117
|
+
const limit = pLimit(concurrency);
|
118
|
+
const passthrough = await Promise.all(
|
119
|
+
list.map(
|
120
|
+
(item) => limit(async () => {
|
121
|
+
const str = item.trim().replace(/^<|>$/g, "");
|
122
|
+
return URL_RE.test(str) ? str : this.uploadToS3(resolve(str));
|
123
|
+
})
|
124
|
+
)
|
125
|
+
);
|
126
|
+
passthrough.forEach((url) => fields.push(["upload_urls", url]));
|
127
|
+
}
|
128
|
+
async normalizeUpload(pathOrUrl) {
|
129
|
+
const trimmed = pathOrUrl.trim().replace(/^<|>$/g, "");
|
130
|
+
return URL_RE.test(trimmed) ? trimmed : this.uploadToS3(resolve(trimmed));
|
131
|
+
}
|
132
|
+
async uploadToS3(absPath) {
|
133
|
+
const { data: presign } = await this.http.post("/upload-url", new URLSearchParams({ filename: basename(absPath) }), {
|
134
|
+
timeout: 3e4
|
135
|
+
});
|
136
|
+
const mime = mimeLookup(absPath) || "application/octet-stream";
|
137
|
+
const size = statSync(absPath).size;
|
138
|
+
await axios.put(presign.url, createReadStream(absPath), {
|
139
|
+
headers: { "Content-Type": mime, "Content-Length": size },
|
140
|
+
maxBodyLength: Infinity,
|
141
|
+
maxContentLength: Infinity,
|
142
|
+
timeout: 6e4
|
143
|
+
});
|
144
|
+
return presign.url.split("?", 1)[0];
|
145
|
+
}
|
146
|
+
};
|
147
|
+
export {
|
148
|
+
Golpo,
|
149
|
+
Golpo as default
|
150
|
+
};
|
package/package.json
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"name": "@golpoai/sdk",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"type": "module",
|
5
|
+
"exports": "./dist/index.js",
|
6
|
+
"types": "./dist/index.d.ts",
|
7
|
+
"files": [
|
8
|
+
"dist/**/*"
|
9
|
+
],
|
10
|
+
"scripts": {
|
11
|
+
"clean": "rm -rf dist",
|
12
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
13
|
+
"prepublishOnly": "npm run clean && npm run build"
|
14
|
+
},
|
15
|
+
"engines": {
|
16
|
+
"node": ">=18.17"
|
17
|
+
},
|
18
|
+
"dependencies": {
|
19
|
+
"@golpoai/sdk": "file:golpoai-sdk-0.1.0.tgz",
|
20
|
+
"axios": "^1.6.8",
|
21
|
+
"dotenv": "^17.2.1",
|
22
|
+
"mime-types": "^2.1.35",
|
23
|
+
"p-limit": "^4.0.0"
|
24
|
+
},
|
25
|
+
"devDependencies": {
|
26
|
+
"@types/mime-types": "^2.1.4",
|
27
|
+
"@types/node": "^20.11.19",
|
28
|
+
"ts-node": "^10.9.2",
|
29
|
+
"tsup": "^8.0.2",
|
30
|
+
"typescript": "^5.9.2"
|
31
|
+
}
|
32
|
+
}
|