repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
breadboard | github_2023 | breadboard-ai | typescript | err | function err($error: string) {
return { $error };
} | // TODO: Find a better place for these. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/data-store/src/file-system/idb-backend.ts#L452-L454 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | IDBRunStore.start | async start(url: RunURL): Promise<RunTimestamp> {
// 1. Store the URLs that we've seen (necessary to support the truncation
// and drop calls).
const runListing = await idb.openDB<RunListing>(
RUN_LISTING_DB,
RUN_LISTING_VERSION,
{
upgrade(db) {
db.createObjectStore("urls", { keyPath: "url" });
},
}
);
await runListing.put("urls", { url });
runListing.close();
// 2. Create a database and object store for this particular run.
const dbName = this.#urlToDbName(url);
const timestamp = Date.now();
const timestampKey = timestamp.toString();
const dbVersion = await idb.openDB(dbName);
const nextVersion = dbVersion.version + 1;
dbVersion.close();
// 3. Set up a stream to write to the new database.
let db: idb.IDBPDatabase;
const stream = new WritableStream({
async start() {
db = await idb.openDB(dbName, nextVersion, {
blocked(currentVersion, blockedVersion, event) {
console.warn(
`IDB Store blocked version ${blockedVersion} by version ${currentVersion}`,
event
);
},
upgrade(db) {
db.createObjectStore(timestampKey, {
keyPath: "id",
autoIncrement: true,
});
},
});
db.close();
},
async write(chunk: HarnessRunResult) {
try {
const result = JSON.parse(JSON.stringify(chunk)) as HarnessRunResult;
// Before storing any inputs, check if they are using StoredDataParts.
// If so inflate them back to inlineData before storage.
if (result.type === "nodeend" && result.data.node.type === "input") {
for (const output of Object.values(result.data.outputs)) {
if (!isLLMContent(output) && !isLLMContentArray(output)) {
continue;
}
const outputs: LLMContent[] = isLLMContent(output)
? [output]
: output;
for (const output of outputs) {
if (isMetadataEntry(output)) {
continue;
}
for (let i = 0; i < output.parts.length; i++) {
const part = output.parts[i];
if (!isStoredData(part)) {
continue;
}
output.parts[i] = await toInlineDataPart(part);
}
}
}
}
db = await idb.openDB(dbName);
const tx = db.transaction(timestampKey, "readwrite");
await Promise.all([tx.store.add(result), tx.done]);
} catch (err) {
console.warn(
`Unable to write to storage (URL: ${url}, Timestamp: ${timestampKey})`,
chunk
);
console.warn(err);
if (this.abort) {
this.abort();
}
} finally {
db.close();
}
},
abort() {
db.close();
},
close() {
db.close();
},
});
// 4. Store the writer and return the timestamp.
let store = this.#writers.get(url);
if (!store) {
store = new Map<
RunTimestamp,
WritableStreamDefaultWriter<HarnessRunResult>
>();
this.#writers.set(url, store);
}
if (store.has(timestamp)) {
throw new Error("Already writing a stream - please stop it first");
}
store.set(timestamp, stream.getWriter());
return timestamp;
} | /**
* Starts tracking a run.
*
* @param storeId The ID of the store to create.
* @param releaseGroupIds The IDs of any old stores to be released.
* @returns The store ID used.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/data-store/src/run/idb-run-store.ts#L57-L174 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | parseMarkdown | function parseMarkdown(text: string): ParsedLine[] {
const lines = text.split(/\n/);
const result: ParsedLine[] = [];
const cursor: Cursor = { pos: 0 };
lines
.map((line) => line.trimEnd())
.forEach((line) => {
if (!line) {
return;
}
const heading = parseHeading(cursor, line);
if (heading) {
result.push(heading);
return;
}
const bullet = parseBullet(cursor, line);
if (bullet) {
result.push(bullet);
return;
}
result.push({
type: "text",
text: line,
...updateCursor(cursor, line.length),
});
});
return result;
} | /**
* Super-naive Markdown parser.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/google-drive-kit/src/util/markdown.ts#L19-L46 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | inflateConfiguration | async function inflateConfiguration(
configuration: IDBProjectStoreConfiguration,
loadedKits: Kit[]
): Promise<BoardServerConfiguration> {
const secrets = new Map<string, string>(configuration.secrets);
const kits: Kit[] = loadedKits;
// TODO: Figure out the right fix.
// configuration.kits
// .map((url) => {
// const kit = loadedKits.find((kit) => kit.url === url);
// if (!kit) {
// console.warn(`Unable to find kit for ${url}`);
// return null;
// }
// return kit;
// })
// .filter((kit) => kit !== null);
const extensions: BoardServerExtension[] = configuration.extensions
.map((url) => {
const extension = loadedExtensions.find(
(extension) => extension.url.href === url
);
if (!extension) {
console.warn(`Unable to find extension for ${url}`);
return null;
}
return extension;
})
.filter((extension) => extension !== null);
return {
capabilities: configuration.capabilities,
extensions,
projects: Promise.resolve([]),
kits,
secrets,
users: configuration.users,
url: new URL(configuration.url),
};
} | // Since IDB does not support various items, like functions, we use | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/idb-board-server/src/idb-board-server.ts#L37-L79 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | IDBBoardServer.getAccess | async getAccess(url: URL, user: User): Promise<Permission> {
const projects = await this.projects;
const project = projects.find((project) => project.url === url);
return (
project?.metadata.access.get(user.username) ?? {
create: false,
retrieve: false,
update: false,
delete: false,
}
);
} | // Users are irrelevant for local stores. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/idb-board-server/src/idb-board-server.ts#L528-L539 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | inferOperationId | const inferOperationId = (path: string, method: string) => {
const newName = path
.split("/")
.map((part) =>
part.length == 0 ? part : part[0].toUpperCase() + part.slice(1)
)
.join("")
.replace(/[.-]/g, "") // Remove dashes and dots
.replace(/[{}]/g, ""); // Remove curly braces (need to improve this)
return `${method}${newName}`;
}; | /*
If there is no operation ID, we need to generate one from the path, but format it like a JS function name.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/import/src/generateAPISpecs.ts#L18-L29 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | buildURL | function buildURL(
board: Board,
api: {
operationId: string;
url: string;
method: string;
description: string | undefined;
summary: string | undefined;
parameters: ExcludedParameter[];
requestBody: AtLeastV3MediaObjectMap;
secrets:
| AtLeastV3ReferenceObject
| AtLeastV3SecuritySchemeObject
| undefined;
}
) {
if (api.parameters.length > 0) {
// For each QS or Path parameter on the API, we need to add an input node to the board.
const params: Record<string, NodeValue> = {};
for (const param of api.parameters) {
if (param.name == undefined) {
continue;
}
params[param.name] = {
title: param?.name,
type: param?.schema.type,
description: param?.description || `The data for ${param.name}`,
example: param?.schema?.example,
};
board.addEdge({
from: "path-inputs",
to: "url",
out: param?.name,
in: param?.name,
optional: param.required == undefined || param?.required == false,
});
}
board.addNode({
id: "path-inputs",
type: "input",
configuration: {
schema: {
type: "object",
properties: params,
required: api.parameters
.filter((param) => param?.required)
.map((param) => param?.name),
},
},
});
}
board.addNode({
id: "url",
type: "urlTemplate",
configuration: {
template: `${api.url}?${api.parameters
.map((param) => `{&${param?.name}}`)
.join("")}`,
},
});
board.addEdge({
from: "url",
to: "fetch",
out: "url",
in: "url",
});
} | /*
Creates the URL node and the path-inputs node for the board.
The URL is a combination of the URL from the API and the parameters from the API.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/import/src/index.ts#L206-L277 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | toAltJson | const toAltJson = (
node: XmlElement | XmlDocument | XmlText | XmlCdata | XmlComment
): [string, NodeValue] => {
if (node.type === "document") {
const doc = node as XmlDocument;
const element = doc.children.find(
(child) => child.type === "element"
) as XmlElement;
const [name, value] = toAltJson(element);
return ["$doc", element ? { [name]: value } : ""];
}
if (node.type === "element") {
const element = node as XmlElement;
const childEntries = element.children.map(toAltJson) as [string, unknown][];
const children = Object.fromEntries(
childEntries.reduce((map, [name, value]) => {
map.has(name) ? map.get(name).push(value) : map.set(name, [value]);
return map;
}, new Map())
);
return [properName(element.name), { ...children, ...element.attributes }];
}
if (node.type === "text") {
const text = node as XmlText;
return ["$t", text.text];
}
return ["$c", ""];
}; | /**
* Converts to alt-json format, as outlined in:
* https://developers.google.com/gdata/docs/json
* @param node
* @returns
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/json-kit/src/nodes/xml-to-json.ts#L44-L71 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | niceType | function niceType(
value: unknown
):
| "null"
| "array"
| "string"
| "number"
| "bigint"
| "boolean"
| "symbol"
| "undefined"
| "object"
| "function" {
if (value === null) {
return "null";
}
if (Array.isArray(value)) {
return "array";
}
return typeof value;
} | /**
* Just `typeof`, but with a special case for `null` and `array` (which would
* otherwise both be `"object"`).
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/python-wasm/src/run-python.ts#L128-L148 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkType | function checkType(a: JSONSchema4, b: JSONSchema4, context: Context): boolean {
if (a.type === b.type) {
// Fast path to avoid Set allocations for very common simple case of e.g.
// `{type: "string"} vs `{type: "number"}.
return true;
}
const aTypes = normalizedTypes(a);
const bTypes = normalizedTypes(b);
if (aTypes.has("integer") && bTypes.has("number")) {
// All integers are numbers, but not all numbers are integers. So, here is
// special handling to allow the case where A is an integer and B is a
// number (but not vice-versa).
aTypes.delete("integer");
aTypes.add("number");
}
if (!isSubsetOf(aTypes, bTypes)) {
context.details.push({
pathA: [...context.pathA, "type"],
pathB: [...context.pathB, "type"],
});
return false;
}
return true;
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/type}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L146-L169 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkEnum | function checkEnum(a: JSONSchema4, b: JSONSchema4, context: Context): boolean {
if (b.enum === undefined) {
return true;
}
if (
a.enum === undefined ||
(a.enum.length === 0 && b.enum.length > 0) ||
!isSubsetOf(coerceSet(a.enum), coerceSet(b.enum))
) {
context.details.push({
pathA: [...context.pathA, "enum"],
pathB: [...context.pathB, "enum"],
});
return false;
}
return true;
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/enum}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L182-L198 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkStringLength | function checkStringLength(
a: JSONSchema4,
b: JSONSchema4,
context: Context
): boolean {
if (b.minLength === undefined && b.maxLength === undefined) {
return true;
}
let ok = true;
const aMin = a.minLength ?? 0;
const bMin = b.minLength ?? 0;
if (aMin < bMin) {
ok = false;
context.details.push({
pathA: [...context.pathA, "minLength"],
pathB: [...context.pathB, "minLength"],
});
}
const aMax = a.maxLength ?? Number.MAX_VALUE;
const bMax = b.maxLength ?? Number.MAX_VALUE;
if (aMax > bMax) {
ok = false;
context.details.push({
pathA: [...context.pathA, "maxLength"],
pathB: [...context.pathB, "maxLength"],
});
}
return ok;
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/string#length}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L203-L235 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkStringPattern | function checkStringPattern(
a: JSONSchema4,
b: JSONSchema4,
context: Context
): boolean {
if (b.pattern === undefined) {
return true;
}
if (a.pattern !== b.pattern) {
context.details.push({
pathA: [...context.pathA, "pattern"],
pathB: [...context.pathB, "pattern"],
});
return false;
}
return true;
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/string#regexp}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L240-L256 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkStringFormat | function checkStringFormat(
a: JSONSchema4,
b: JSONSchema4,
context: Context
): boolean {
if (b.format === undefined) {
return true;
}
if (a.format !== b.format) {
context.details.push({
pathA: [...context.pathA, "format"],
pathB: [...context.pathB, "format"],
});
return false;
}
return true;
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/string#format}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L261-L277 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkNumberRange | function checkNumberRange(
a: JSONSchema4,
b: JSONSchema4,
context: Context
): boolean {
if (b.minimum === undefined && b.maximum === undefined) {
return true;
}
const aMin = a.minimum ?? 0;
const bMin = b.minimum ?? 0;
if (aMin < bMin) {
context.details.push({
pathA: [...context.pathA, "minimum"],
pathB: [...context.pathB, "minimum"],
});
return false;
}
const aMax = a.maximum ?? Number.MAX_VALUE;
const bMax = b.maximum ?? Number.MAX_VALUE;
if (aMax > bMax) {
context.details.push({
pathA: [...context.pathA, "maximum"],
pathB: [...context.pathB, "maximum"],
});
return false;
}
return true;
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/numeric#range}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L282-L310 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkArrayItems | function checkArrayItems(
a: JSONSchema4,
b: JSONSchema4,
context: Context
): boolean {
if (b.items === undefined) {
return true;
}
if (Array.isArray(a.items) || Array.isArray(b.items)) {
// TODO(aomarks) Implement tuple support.
return true;
}
// TODO(aomarks) Recurse in a way that won't lose context (once context is
// actually used for anything).
context.pathA.push("items");
context.pathB.push("items");
const ok = analyzeIsJsonSubSchema(
a.items ?? ALL_TYPES_SCHEMA,
b.items,
context
).isSubSchema;
context.pathA.pop();
context.pathB.pop();
return ok;
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/array#items}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L315-L339 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkObjectProperties | function checkObjectProperties(
a: JSONSchema4,
b: JSONSchema4,
context: Context
): boolean {
if (a.properties === undefined) {
return true;
}
for (const [name, aSchema] of Object.entries(a.properties)) {
const bSchema = b.properties?.[name];
if (bSchema !== undefined) {
// B also specifies this property, check compatibility.
context.pathA.push("properties", name);
context.pathB.push("properties", name);
const { isSubSchema } = analyzeIsJsonSubSchema(aSchema, bSchema, context);
context.pathA.pop();
context.pathB.pop();
if (!isSubSchema) {
return false;
}
} else if (
b.additionalProperties === true ||
b.additionalProperties === /* defaults to true */ undefined
) {
// B allows any additional property.
continue;
} else if (b.additionalProperties === false) {
// B doesn't allow any additional properties.
context.details.push({
pathA: [...context.pathA, "properties", name],
pathB: [...context.pathB, "additionalProperties"],
});
return false;
} else {
// B allows additional properties but constrains their schema.
context.pathA.push("properties", name);
context.pathB.push("additionalProperties");
const { isSubSchema } = analyzeIsJsonSubSchema(
aSchema,
b.additionalProperties,
context
);
context.pathA.pop();
context.pathB.pop();
if (!isSubSchema) {
return false;
}
}
}
return true;
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/object#properties}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L344-L394 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkObjectAdditionalProperties | function checkObjectAdditionalProperties(
a: JSONSchema4,
b: JSONSchema4,
context: Context
): boolean {
// The additionalProperties constraint can be true (any additional property is
// OK), false (no additional properties are OK), or an object (additional
// property is OK as long as it matches that type).
const bAdditional = b.additionalProperties ?? true;
if (bAdditional === true) {
// A | B | Result |
// ----- | ------| ------- |
// true | true | true | T
// false | true | true | T
// {...} | true | true | T
return true;
}
const aAdditional = a.additionalProperties ?? true;
if (aAdditional === false) {
// A | B | Result |
// ----- | ------| ------- |
// false | false | true | T
// false | {...} | true | T
return true;
}
if (bAdditional === false) {
// A | B | Result |
// ----- | ------| ------- |
// {...} | false | false | T
// true | false | false | T
context.details.push({
pathA: [...context.pathA, "additionalProperties"],
pathB: [...context.pathB, "additionalProperties"],
});
return false;
}
// A | B | Result |
// ----- | ------| ------- |
// true | {...} | compare | T
// {...} | {...} | compare |
context.pathA.push("additionalProperties");
context.pathB.push("additionalProperties");
const result = analyzeIsJsonSubSchema(
aAdditional === true ? {} : aAdditional,
bAdditional,
context
).isSubSchema;
context.pathA.pop();
context.pathB.pop();
return result;
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/object#additionalproperties}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L399-L449 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkObjectRequiredProperties | function checkObjectRequiredProperties(
a: JSONSchema4,
b: JSONSchema4,
context: Context
): boolean {
if (typeof a.required === "boolean" || typeof b.required === "boolean") {
// TODO(aomarks) Validate that required can't actually be a boolean. The
// `json-schema` types package say that it can be, but the docs don't
// mention this, so it doesn't seem right.
return true;
}
if (b.required === undefined || b.required.length === 0) {
return true;
}
const aRequired = new Set(a.required ?? []);
let ok = true;
for (let i = 0; i < b.required.length; i++) {
const name = b.required[i];
if (!aRequired.has(name)) {
ok = false;
context.details.push({
pathA: [...context.pathA, "required"],
pathB: [...context.pathB, "required", i],
});
}
}
return ok;
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/object#required}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L454-L481 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkAnyOf | function checkAnyOf(
a: JSONSchema4,
b: JSONSchema4,
context: Context
):
| boolean
| typeof PASS_AND_SKIP_REMAINING_CHECKS
| typeof FAIL_AND_SKIP_REMAINING_CHECKS {
if (a.anyOf !== undefined) {
// ALL possibilities from A must satisfy B.
for (let idxA = 0; idxA < a.anyOf.length; idxA++) {
const originalSubA = a.anyOf[idxA];
const modifiedSubA = inheritParentConstraintsIntoAnyOfEntry(
a,
originalSubA
);
if (b.anyOf === undefined) {
// B is NOT an `anyOf`, so check each A directly against B.
//
// We need to be a bit clever here, because we ARE passing down the
// context, but we're doing so with "fake" paths (see
// `inheritParentConstraintsIntoAnyOfEntry`). So we do this:
//
// 1. Make a temporary context so that we can easily isolate the details
// from this recursion from any other details we might already have.
// 2. Undo the effect of `inheritParentConstraintsIntoAnyOfEntry` using
// `repairDetailPathsForInheritedProperties`.
// 3. Merge back in the details we temporarily excluded in (1).
const tempDetails: JsonSubSchemaAnalysisDetail[] = [];
const tempContext = { ...context, details: tempDetails };
context.pathA.push("anyOf", idxA);
const ok = analyzeIsJsonSubSchema(
modifiedSubA,
b,
tempContext
).isSubSchema;
context.pathA.pop();
context.pathA.pop();
if (!ok) {
context.details.push(
...repairDetailPathsForInheritedProperties(
tempDetails,
idxA,
originalSubA
)
);
return FAIL_AND_SKIP_REMAINING_CHECKS;
}
} else {
// B is also an `anyOf`, so check that ALL possibilities from A
// satisfies AT LEAST ONE posibility from B.
//
// PERFORMANCE WARNING: O(n^2) comparisons!
let found = false;
for (const subB of b.anyOf) {
if (
analyzeIsJsonSubSchema(
modifiedSubA,
inheritParentConstraintsIntoAnyOfEntry(b, subB)
// Note we do NOT pass down context here because we don't want to
// accumulate details, because we're _searching_ for a match, not
// asserting a match.
).isSubSchema
) {
found = true;
break;
}
}
if (!found) {
context.details.push({
pathA: [...context.pathA, "anyOf", idxA],
pathB: [...context.pathB, "anyOf"],
});
return FAIL_AND_SKIP_REMAINING_CHECKS;
}
}
}
return PASS_AND_SKIP_REMAINING_CHECKS;
} else if (b.anyOf !== undefined) {
// Only B is an `anyOf`. Ensure that A satisfies AT LEAST ONE possibility
// from B.
for (const subB of b.anyOf) {
if (
analyzeIsJsonSubSchema(
a,
inheritParentConstraintsIntoAnyOfEntry(b, subB)
// Note we do NOT pass down context here because we don't want to
// accumulate details, because we're _searching_ for a match, not
// asserting a match.
).isSubSchema
) {
return PASS_AND_SKIP_REMAINING_CHECKS;
}
}
context.details.push({
pathA: [...context.pathA],
pathB: [...context.pathB, "anyOf"],
});
return FAIL_AND_SKIP_REMAINING_CHECKS;
} else {
return true;
}
} | /**
* {@link https://json-schema.org/understanding-json-schema/reference/combining#anyOf}
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L486-L588 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | inheritParentConstraintsIntoAnyOfEntry | function inheritParentConstraintsIntoAnyOfEntry(
parentSchema: JSONSchema4,
anyOfEntry: JSONSchema4
): JSONSchema4 {
if (Object.keys(parentSchema).length === 1) {
// We assume `parent` has `anyOf`, so if there's only 1 property then it
// must be `anyOf`, which we can ignore and save a copy.
return anyOfEntry;
}
return { ...parentSchema, anyOf: undefined, ...anyOfEntry };
} | /**
* If you have e.g. `{ maxLength: 4, anyOf: { A, B } }` then the `maxLength`
* constraint implicitly applies to both `A` and `B`. This function copies any
* such constraints from a parent JSON schema object into one of its given
* `anyOf` entries so that it can more easily be analyzed.
*
* See
* {@link https://json-schema.org/understanding-json-schema/reference/combining#factoringschemas}.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L599-L609 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | isSubsetOf | function isSubsetOf(a: Set<unknown>, b: Set<unknown>): boolean {
if (a.size > b.size) {
return false;
}
for (const item of a) {
if (!b.has(item)) {
return false;
}
}
return true;
} | // Replace with | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/schema/src/subschema.ts#L646-L656 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | MarkdownDirective.render | render(value: string) {
const htmlString = this.#markdownIt.render(value);
return unsafeHTML(htmlString);
} | /**
* Renders the markdown string to HTML using MarkdownIt.
*
* Note: MarkdownIt doesn't enable HTML in its output, so we render the
* value directly without further sanitization.
* @see https://github.com/markdown-it/markdown-it/blob/master/docs/security.md
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/directives/markdown.ts#L60-L63 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | GraphAssets.constructor | private constructor() {} | // Not to be instantiated directly. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/elements/editor/graph-assets.ts#L122-L122 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | GraphComment.outputHeight | set outputHeight(outputHeight: number) {
this.#outputHeight = outputHeight;
this.#isDirty = true;
} | // Not currently used, but here for parity with the GraphNode | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/elements/editor/graph-comment.ts#L326-L329 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | lineIntersect | function lineIntersect(
p1s: PIXI.Point,
p1e: PIXI.Point,
p2s: PIXI.Point,
p2e: PIXI.Point
): boolean {
const i = segmentIntersection(p1s, p1e, p2s, p2e);
if (Number.isNaN(i.x) || Number.isNaN(i.y)) return false;
return true;
} | // pixi-math returns the intersection point. The coordinates of that point are | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/elements/editor/graph-edge.ts#L713-L722 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | rectangleVertices | function rectangleVertices(r: PIXI.Rectangle) {
return [
new PIXI.Point(r.x, r.y),
new PIXI.Point(r.x + r.width, r.y),
new PIXI.Point(r.x + r.width, r.y + r.height),
new PIXI.Point(r.x, r.y + r.height),
];
} | // Returns all corners of a rectangle. Order is important so that you can | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/elements/editor/graph-edge.ts#L733-L740 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | loadNonModuleWithHeadScriptTag | async function loadNonModuleWithHeadScriptTag(src: string): Promise<void> {
const script = document.createElement("script");
script.async = true;
script.src = src;
let resolve: () => void;
let reject: () => void;
const promise = new Promise<void>((innerResolve, innerReject) => {
resolve = innerResolve;
reject = innerReject;
});
const cancel = new AbortController();
script.addEventListener(
"load",
() => {
resolve();
cancel.abort();
},
{ once: true, signal: cancel.signal }
);
script.addEventListener(
"error",
() => {
reject();
cancel.abort();
},
{ once: true, signal: cancel.signal }
);
document.head.appendChild(script);
return promise;
} | /**
* This is like `import`, except for JavaScript that can't be executed as a
* module, like GAPI.
*
* This function does NOT implement caching.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/elements/google-drive/google-apis.ts#L83-L115 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | maybeTrimNodestart | function maybeTrimNodestart(events: InspectableRunEvent[], hideLast: boolean) {
const last = events.at(-1);
if (last?.type === "node" && !last.end && hideLast) {
return events.slice(0, -1);
}
return events;
} | /**
* A helper that trims the last incomplete event (the event that does not have
* a closing `nodeend`) when asked.
*
* This is used to remove the "next up" item in the activity log when we are
* stepping through the nodes step by step.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/elements/overlay/board-activity.ts#L236-L242 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | isTool | function isTool(entry: GraphStoreEntry) {
return (
!entry.updating &&
entry.tags?.includes("tool") &&
!!entry.url &&
entry?.tags.includes("quick-access") &&
(entry.url?.includes("/@shared/") || entry.url?.startsWith("file:"))
);
} | /**
* Controls the filter for tools. Use it to tweak what shows up in the "Tools"
* section of the "@" menu.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/state/project.ts#L44-L52 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | updateMap | function updateMap<T extends SignalMap>(
map: T,
updated: [string, unknown][]
): void {
const toDelete = new Set(map.keys());
updated.forEach(([key, value]) => {
map.set(key, value);
toDelete.delete(key);
});
[...toDelete.values()].forEach((key) => {
map.delete(key);
});
} | /**
* Incrementally updates a map, given updated values.
* Updates the values in `updated`, deletes the ones that aren't in it.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/state/project.ts#L222-L236 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | SigninAdapter.whenSignedIn | async whenSignedIn(
signinCallback: (adapter: SigninAdapter) => Promise<void>
) {
const now = Date.now();
if (this.state === "invalid") {
await signinCallback(new SigninAdapter());
return;
}
const nonce = this.#nonce;
// Reset the nonce in case the user signs out and signs back in again, since
// we don't want to ever mix up different requests.
setTimeout(
// TODO(aomarks) This shouldn't be necessary, what's up?
() => (this.#nonce = crypto.randomUUID()),
500
);
// The OAuth broker page will know to broadcast the token on this unique
// channel because it also knows the nonce (since we pack that in the OAuth
// "state" parameter).
const channelName = oauthTokenBroadcastChannelName(nonce);
const channel = new BroadcastChannel(channelName);
const grantResponse = await new Promise<GrantResponse>((resolve) => {
channel.addEventListener("message", (m) => resolve(m.data), {
once: true,
});
});
channel.close();
if (grantResponse.error !== undefined) {
// TODO(aomarks) Show error info in the UI.
console.error(grantResponse.error);
await signinCallback(new SigninAdapter());
return;
}
const connection = await this.#getConnection();
if (!connection) {
await signinCallback(new SigninAdapter());
return;
}
const settingsValue: TokenGrant = {
client_id: connection.clientId,
access_token: grantResponse.access_token,
expires_in: grantResponse.expires_in,
refresh_token: grantResponse.refresh_token,
issue_time: now,
name: grantResponse.name,
picture: grantResponse.picture,
id: grantResponse.id,
};
await this.#settingsHelper?.set(SETTINGS_TYPE.CONNECTIONS, connection.id, {
name: connection.id,
value: JSON.stringify(settingsValue),
});
await signinCallback(
new SigninAdapter(
this.#tokenVendor,
this.#environment,
this.#settingsHelper
)
);
} | /**
* Handles the part of the process after
* the sign-in: storing the connection in
* the settings, and calling the callback.
* Note, it always returns a new copy of
* the SigninAdapter, which will contain
* the picture and name.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/utils/signin-adapter.ts#L178-L239 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | RunDetails.initialize | async initialize() {
const runs = await this.#observer.runs();
// Take inputs from the previous run.
this.#lastRunInputs = runs.at(1)?.inputs() || null;
} | /**
* Must be called before using the instance, right after the very first
* "graphstart". Reason:
* The lifetime of runs begins at "graphstart", and the details aren't
* available until after that.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/utils/top-graph-observer/run-details.ts#L28-L32 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | computeEntryId | function computeEntryId(graph?: GraphDescriptor) {
if (!graph || !graph.edges) return;
const incoming = new Set(graph.edges.map((edge) => edge.to));
const entries = graph.nodes.filter((node) => !incoming.has(node.id));
return entries.at(0)?.id;
} | // Ideally, this function should live somewhere in packages/breadboard, | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/utils/top-graph-observer/top-graph-observer.ts#L141-L146 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | placeOutputInLog | function placeOutputInLog(log: LogEntry[], edge: EdgeLogEntry): LogEntry[] {
const last = log[log.length - 1];
if (last?.type === "edge" && last.value) {
return [...log, edge];
}
// @ts-expect-error - findLastIndex is not in the TS lib
const lastNode = log.findLastIndex((entry) => entry.type === "node");
if (lastNode === -1) {
return [...log, edge];
}
if (lastNode === 0) {
return [edge, ...log];
}
const maybeReplace = log[lastNode - 1] as LogEntry;
if (maybeReplace.type === "edge" && !maybeReplace.value) {
return [...log.slice(0, lastNode - 1), edge, ...log.slice(lastNode)];
}
// Comment out this logic, because it causes transient outputs from modules
// to be eaten.
// TODO: Figure out if this should just be deleted or improved to avoid
// eating outputs from modules.
// To avoid there being two edges placed side-by-side we skip this edge if we
// intend to place it next to an existing edge.
// if (lastNode > 0) {
// const succeedingItemIdx = lastNode + 1;
// const precedingItemIsEdge = log[lastNode] && log[lastNode].type === "edge";
// const succeedingItemIsEdge =
// log[succeedingItemIdx] && log[succeedingItemIdx].type === "edge";
// if (precedingItemIsEdge || succeedingItemIsEdge) {
// return [...log, edge];
// }
// }
return [...log.slice(0, lastNode), edge, ...log.slice(lastNode)];
} | /**
* Places the output edge in the log, according to the following rules:
* - Until first bubbling input, place output before the last node,
* possibly replacing an empty edge.
* - After first bubbling input, place output after the last node.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/shared-ui/src/utils/top-graph-observer/top-graph-observer.ts#L522-L557 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | RecentBoardStore.constructor | private constructor() {} | // Not instantiated directly. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/visual-editor/src/data/recent-boards.ts#L30-L30 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Board.getProviderByName | getProviderByName(name: string) {
return this.providers.find((provider) => provider.name === name) || null;
} | /**
* @deprecated Use getBoardServerByName instead.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/visual-editor/src/runtime/board.ts#L178-L180 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Board.getProviderForURL | getProviderForURL(url: URL) {
return this.providers.find((provider) => provider.canProvide(url)) || null;
} | /**
* @deprecated Use getBoardServerForURL instead.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/visual-editor/src/runtime/board.ts#L185-L187 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Board.getProviders | getProviders(): GraphProvider[] {
console.warn("getProviders is deprecated - use getBoardServers instead.");
return this.providers;
} | /**
*
* @deprecated Use getBoardServers() instead.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/visual-editor/src/runtime/board.ts#L203-L206 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | isModule | function isModule(source: unknown): source is Module {
return typeof source === "object" && source !== null && "code" in source;
} | // function isGraphDescriptor(source: unknown): source is GraphDescriptor { | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/visual-editor/src/runtime/edit.ts#L66-L68 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | createPastRunObserver | function createPastRunObserver(run: InspectableRun): InspectableRunObserver {
return {
runs: async () => [run],
observe: async () => {
return;
},
load: async () => {
throw new Error("Attempting to load in read-only tab.");
},
append: async () => {
throw new Error("Do not append to a past run observer.");
},
async replay(stopAt: NodeIdentifier[]): Promise<void> {
for await (const result of run.replay()) {
await this.observe(result);
const { type, data } = result;
if (
type === "nodestart" &&
data.path.length === 1 &&
stopAt.includes(data.node.id)
) {
break;
}
}
},
};
} | /**
* Creaetes an InspectableRunObserver that holds a single run.
* Useful for historical runs
*
* @param run -- the run to hold.
* @returns
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/visual-editor/src/utils/past-run-observer.ts#L22-L48 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | renderFrontend | function renderFrontend(response: ChatResponse) {
const { next, message } = response;
return new Response(
`<!DOCTYPE html>
<h1>Chat with your cat</h1>
<form method="POST">
${next ? `<input type="hidden" name="next" value="${next}" />` : ""}
${
message
? `<p>Cat says:</p>
<p>${message}</p>`
: ""
}
<p>
<label>Your message:
<input type="text" name="message" required></label>
<input type="submit" value="Send">
</p>
</form>
`,
{
headers: {
"Content-Type": "text/html",
},
}
);
} | // A very, very simple frontend. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/samples/endpoint/deno/index.ts#L112-L138 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | getCompleteChunks | const getCompleteChunks = (pending: string, chunk: string) => {
const asString = `${pending}${chunk}`;
return asString.split("\n\n").filter(Boolean);
}; | /**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/samples/endpoint/nextjs/app/new/chunk-repair.ts#L7-L10 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
kaifangqian-base | github_2023 | kaifangqian | typescript | currentPage | function currentPage(opt:any){
for(var i =0;i<opt.pageSize;i++){
//计算控件是否再空白区域
var start = (i+1) * CanvasZoom.space + i * CanvasZoom.height;
var end =(i+1) * CanvasZoom.space + (i+1) * CanvasZoom.height;
// console.log(opt.y,start,end);
if(opt.y>start && opt.y< end){
opt.currentPage = i;
}
}
// console.log(opt);
} | //计算控件所在的页面 | https://github.com/kaifangqian/kaifangqian-base/blob/9157ecd23e1e59d3d8849efadd83efe2bd28e00a/kaifangqian-demo-vue/src/components/control/data/ControlerMoveRange.ts#L32-L44 | 9157ecd23e1e59d3d8849efadd83efe2bd28e00a |
kaifangqian-base | github_2023 | kaifangqian | typescript | isControlPage | function isControlPage(opt:any,allHeight:number){
//var temHeight = 0;
var start = (opt.currentPage+1) * CanvasZoom.space + opt.currentPage * CanvasZoom.height;
var end =(opt.currentPage+1) * CanvasZoom.space + (opt.currentPage+1) * CanvasZoom.height;
var top = opt.y + opt.size.height;
// console.log("scope:",start,end,opt.y + opt.size.height);
if(top>start && top< end){
return;
}
if(top>allHeight){
opt.y = allHeight - opt.size.height ;
return;
}
var outSize = top - end;
if(outSize>opt.size.height/2){
opt.currentPage += 1;
opt.y = end + CanvasZoom.space;
}else{
opt.y = end - opt.size.height;
}
console.log("超出:",outSize);
} | //判断控件是否再边界上 | https://github.com/kaifangqian/kaifangqian-base/blob/9157ecd23e1e59d3d8849efadd83efe2bd28e00a/kaifangqian-demo-vue/src/components/control/data/ControlerMoveRange.ts#L47-L71 | 9157ecd23e1e59d3d8849efadd83efe2bd28e00a |
resume-json-pdf | github_2023 | RylanBot | typescript | useEditWithUndo | function useEditWithUndo<K extends keyof TempStore>(storeType: K) {
const { setTempStore, resetTempStore, [storeType]: originalStore, tempStores } = useDataStore();
// 依赖真正 data,确保数据一致
useEffect(() => {
setTempStore(storeType, originalStore);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [originalStore]);
const originalSetters = {
profileStore: useDataStore.getState().setProfileStore,
experienceStore: useDataStore.getState().setExperienceStore,
styleStore: useDataStore.getState().setStyleStore,
} as Record<K, (newValue: StyleData | ProfileData | ExperienceData[]) => void>;
const startEdit = () => {
setTempStore(storeType, originalStore);
};
const confirmEdit = () => {
const setter = originalSetters[storeType];
const value = tempStores[storeType];
if (setter && value) {
setter(value);
}
};
const cancelEdit = () => {
resetTempStore(storeType);
};
/**
* 局部更新 JSON 指定嵌套数组的某项
* @param subPath 字段所在路径
* @param newText 更新值
*/
const updateTempValue = (subPath: string, newText: string | number) => {
const updatedStore = _.cloneDeep(tempStores[storeType]);
_.set(updatedStore, subPath, newText);
setTempStore(storeType, updatedStore);
};
return { tempStore: tempStores[storeType], startEdit, confirmEdit, cancelEdit, updateTempValue };
} | /**
* 只暴露 temp data 实现页面预览
* @param storeType 具体的 store 类型 (style/profile/experience)
*/ | https://github.com/RylanBot/resume-json-pdf/blob/528cae8a3136bd6a6f2e2f1c58d5e7b57c7b4173/src/hooks/useEditWithUndo.tsx#L15-L58 | 528cae8a3136bd6a6f2e2f1c58d5e7b57c7b4173 |
resume-json-pdf | github_2023 | RylanBot | typescript | updateTempValue | const updateTempValue = (subPath: string, newText: string | number) => {
const updatedStore = _.cloneDeep(tempStores[storeType]);
_.set(updatedStore, subPath, newText);
setTempStore(storeType, updatedStore);
}; | /**
* 局部更新 JSON 指定嵌套数组的某项
* @param subPath 字段所在路径
* @param newText 更新值
*/ | https://github.com/RylanBot/resume-json-pdf/blob/528cae8a3136bd6a6f2e2f1c58d5e7b57c7b4173/src/hooks/useEditWithUndo.tsx#L51-L55 | 528cae8a3136bd6a6f2e2f1c58d5e7b57c7b4173 |
codeium-react-code-editor | github_2023 | Exafunction | typescript | MonacoCompletionProvider.provideInlineCompletions | public async provideInlineCompletions(
model: monaco.editor.ITextModel,
monacoPosition: monaco.Position,
token: CancellationToken,
): Promise<
| monaco.languages.InlineCompletions<monaco.languages.InlineCompletion>
| undefined
> {
const document = new Document(model);
const position = Position.fromMonaco(monacoPosition);
// Pre-register cancellation callback to get around bug in Monaco cancellation tokens breaking
// after await.
token.onCancellationRequested(() => token.cancellationCallback?.());
const abortController = new AbortController();
token.onCancellationRequested(() => {
abortController.abort();
});
const signal = abortController.signal;
this.setStatus(Status.PROCESSING);
this.setMessage('Generating completions...');
const documentInfo = this.getDocumentInfo(document, position);
const editorOptions = {
tabSize: BigInt(model.getOptions().tabSize),
insertSpaces: model.getOptions().insertSpaces,
};
let includedOtherDocs = this.otherDocuments;
if (includedOtherDocs.length > 10) {
console.warn(
`Too many other documents: ${includedOtherDocs.length} (max 10)`,
);
includedOtherDocs = includedOtherDocs.slice(0, 10);
}
let multilineConfig: MultilineConfig | undefined = undefined;
if (this.multilineModelThreshold !== undefined) {
multilineConfig = new MultilineConfig({
threshold: this.multilineModelThreshold,
});
}
// Get completions.
let getCompletionsResponse: GetCompletionsResponse;
try {
getCompletionsResponse = await this.client.getCompletions(
{
metadata: this.getMetadata(),
document: documentInfo,
editorOptions: editorOptions,
otherDocuments: includedOtherDocs,
multilineConfig,
},
{
signal,
headers: this.getAuthHeader(),
},
);
} catch (err) {
// Handle cancellation.
if (err instanceof ConnectError && err.code === Code.Canceled) {
// cancelled
} else {
this.setStatus(Status.ERROR);
this.setMessage('Something went wrong; please try again.');
}
return undefined;
}
if (!getCompletionsResponse.completionItems) {
// TODO(nick): Distinguish warning / error states here.
const message = ' No completions were generated';
this.setStatus(Status.SUCCESS);
this.setMessage(message);
return undefined;
}
const completionItems = getCompletionsResponse.completionItems;
// Create inline completion items from completions.
const inlineCompletionItems = completionItems
.map((completionItem) =>
this.createInlineCompletionItem(completionItem, document),
)
.filter((item) => !!item);
this.setStatus(Status.SUCCESS);
let message = `Generated ${inlineCompletionItems.length} completions`;
if (inlineCompletionItems.length === 1) {
message = `Generated 1 completion`;
}
this.setMessage(message);
return {
items: inlineCompletionItems as monaco.languages.InlineCompletion[],
};
} | /**
* Generate CompletionAndRanges.
*
* @param model - Monaco model.
* @param token - Cancellation token.
* @returns InlineCompletions or undefined
*/ | https://github.com/Exafunction/codeium-react-code-editor/blob/768e1b231c00e078c86bc19c8ede697a1e37ec75/src/components/CodeiumEditor/CompletionProvider.ts#L99-L196 | 768e1b231c00e078c86bc19c8ede697a1e37ec75 |
codeium-react-code-editor | github_2023 | Exafunction | typescript | MonacoCompletionProvider.acceptedLastCompletion | public acceptedLastCompletion(completionId: string) {
new Promise((resolve, reject) => {
this.client
.acceptCompletion(
{
metadata: this.getMetadata(),
completionId: completionId,
},
{
headers: this.getAuthHeader(),
},
)
.then(resolve)
.catch((err) => {
console.log('Error: ', err);
});
});
} | /**
* Record that the last completion shown was accepted by the user.
* @param ctx - Codeium context
* @param completionId - unique ID of the last completion.
*/ | https://github.com/Exafunction/codeium-react-code-editor/blob/768e1b231c00e078c86bc19c8ede697a1e37ec75/src/components/CodeiumEditor/CompletionProvider.ts#L203-L220 | 768e1b231c00e078c86bc19c8ede697a1e37ec75 |
codeium-react-code-editor | github_2023 | Exafunction | typescript | MonacoCompletionProvider.getDocumentInfo | private getDocumentInfo(
document: Document,
position: Position,
): DocumentInfo {
// The offset is measured in bytes.
const text = document.getText();
const numCodeUnits = document.offsetAt(position);
const offset = numCodeUnitsToNumUtf8Bytes(text, numCodeUnits);
const language = languageIdToEnum(document.languageId);
if (language === Language.UNSPECIFIED) {
console.warn(`Unknown language: ${document.languageId}`);
}
const documentInfo = new DocumentInfo({
text: text,
editorLanguage: document.languageId,
language,
cursorOffset: BigInt(offset),
lineEnding: '\n',
});
return documentInfo;
} | /**
* Gets document info object for the given document.
*
* @param document - The document to get info for.
* @param position - Optional position used to get offset in document.
* @returns The document info object and additional UTF-8 byte offset.
*/ | https://github.com/Exafunction/codeium-react-code-editor/blob/768e1b231c00e078c86bc19c8ede697a1e37ec75/src/components/CodeiumEditor/CompletionProvider.ts#L229-L252 | 768e1b231c00e078c86bc19c8ede697a1e37ec75 |
codeium-react-code-editor | github_2023 | Exafunction | typescript | MonacoCompletionProvider.createInlineCompletionItem | private createInlineCompletionItem(
completionItem: CompletionItem,
document: Document,
): MonacoInlineCompletion | undefined {
if (!completionItem.completion || !completionItem.range) {
return undefined;
}
// Create and return inlineCompletionItem.
const text = document.getText();
const startPosition = document.positionAt(
numUtf8BytesToNumCodeUnits(
text,
Number(completionItem.range.startOffset),
),
);
const endPosition = document.positionAt(
numUtf8BytesToNumCodeUnits(text, Number(completionItem.range.endOffset)),
);
const range = new Range(startPosition, endPosition);
const inlineCompletionItem = new MonacoInlineCompletion(
completionItem.completion.text,
range,
completionItem.completion.completionId,
);
return inlineCompletionItem;
} | /**
* Converts the completion and range to inline completion item.
*
* @param completionItem
* @param document
* @returns Inline completion item.
*/ | https://github.com/Exafunction/codeium-react-code-editor/blob/768e1b231c00e078c86bc19c8ede697a1e37ec75/src/components/CodeiumEditor/CompletionProvider.ts#L261-L288 | 768e1b231c00e078c86bc19c8ede697a1e37ec75 |
codeium-react-code-editor | github_2023 | Exafunction | typescript | numUtf8BytesForCodePoint | function numUtf8BytesForCodePoint(codePointValue: number): number {
if (codePointValue < 0x80) {
return 1;
}
if (codePointValue < 0x800) {
return 2;
}
if (codePointValue < 0x10000) {
return 3;
}
return 4;
} | /**
* Returns the number of UTF-8 bytes required to represent the given Unicode code point.
*
* @param {number} codePointValue - The Unicode code point value.
* @return {number} The number of UTF-8 bytes needed to represent the code point.
*/ | https://github.com/Exafunction/codeium-react-code-editor/blob/768e1b231c00e078c86bc19c8ede697a1e37ec75/src/utils/utf.ts#L7-L18 | 768e1b231c00e078c86bc19c8ede697a1e37ec75 |
elevenlabs-js | github_2023 | elevenlabs | typescript | AudioIsolation.audioIsolation | public async audioIsolation(
request: ElevenLabs.BodyAudioIsolationV1AudioIsolationPost,
requestOptions?: AudioIsolation.RequestOptions,
): Promise<stream.Readable> {
const _request = await core.newFormData();
await _request.appendFile("audio", request.audio);
const _maybeEncodedRequest = await _request.getRequest();
const _response = await core.fetcher<stream.Readable>({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/audio-isolation",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
..._maybeEncodedRequest.headers,
...requestOptions?.headers,
},
requestType: "file",
duplex: _maybeEncodedRequest.duplex,
body: _maybeEncodedRequest.body,
responseType: "streaming",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling POST /v1/audio-isolation.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Removes background noise from audio
* @throws {@link ElevenLabs.UnprocessableEntityError}
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/audioIsolation/client/Client.ts#L42-L110 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | AudioIsolation.audioIsolationStream | public async audioIsolationStream(
request: ElevenLabs.BodyAudioIsolationStreamV1AudioIsolationStreamPost,
requestOptions?: AudioIsolation.RequestOptions,
): Promise<stream.Readable> {
const _request = await core.newFormData();
await _request.appendFile("audio", request.audio);
const _maybeEncodedRequest = await _request.getRequest();
const _response = await core.fetcher<stream.Readable>({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/audio-isolation/stream",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
..._maybeEncodedRequest.headers,
...requestOptions?.headers,
},
requestType: "file",
duplex: _maybeEncodedRequest.duplex,
body: _maybeEncodedRequest.body,
responseType: "streaming",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling POST /v1/audio-isolation/stream.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Removes background noise from audio and streams the result
* @throws {@link ElevenLabs.UnprocessableEntityError}
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/audioIsolation/client/Client.ts#L116-L186 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | AudioNative.create | public async create(
request: ElevenLabs.BodyCreatesAudioNativeEnabledProjectV1AudioNativePost,
requestOptions?: AudioNative.RequestOptions,
): Promise<ElevenLabs.AudioNativeCreateProjectResponseModel> {
const _request = await core.newFormData();
_request.append("name", request.name);
if (request.image != null) {
_request.append("image", request.image);
}
if (request.author != null) {
_request.append("author", request.author);
}
if (request.title != null) {
_request.append("title", request.title);
}
if (request.small != null) {
_request.append("small", request.small.toString());
}
if (request.text_color != null) {
_request.append("text_color", request.text_color);
}
if (request.background_color != null) {
_request.append("background_color", request.background_color);
}
if (request.sessionization != null) {
_request.append("sessionization", request.sessionization.toString());
}
if (request.voice_id != null) {
_request.append("voice_id", request.voice_id);
}
if (request.model_id != null) {
_request.append("model_id", request.model_id);
}
if (request.file != null) {
await _request.appendFile("file", request.file);
}
if (request.auto_convert != null) {
_request.append("auto_convert", request.auto_convert.toString());
}
const _maybeEncodedRequest = await _request.getRequest();
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/audio-native",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
..._maybeEncodedRequest.headers,
...requestOptions?.headers,
},
requestType: "file",
duplex: _maybeEncodedRequest.duplex,
body: _maybeEncodedRequest.body,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.AudioNativeCreateProjectResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling POST /v1/audio-native.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Creates AudioNative enabled project, optionally starts conversion and returns project id and embeddable html snippet.
*
* @param {ElevenLabs.BodyCreatesAudioNativeEnabledProjectV1AudioNativePost} request
* @param {AudioNative.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.audioNative.create({
* name: "name"
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/audioNative/client/Client.ts#L50-L161 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | AudioNative.updateContent | public async updateContent(
projectId: string,
request: ElevenLabs.BodyUpdateAudioNativeProjectContentV1AudioNativeProjectIdContentPost,
requestOptions?: AudioNative.RequestOptions,
): Promise<ElevenLabs.AudioNativeEditContentResponseModel> {
const _request = await core.newFormData();
if (request.file != null) {
await _request.appendFile("file", request.file);
}
if (request.auto_convert != null) {
_request.append("auto_convert", request.auto_convert.toString());
}
if (request.auto_publish != null) {
_request.append("auto_publish", request.auto_publish.toString());
}
const _maybeEncodedRequest = await _request.getRequest();
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/audio-native/${encodeURIComponent(projectId)}/content`,
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
..._maybeEncodedRequest.headers,
...requestOptions?.headers,
},
requestType: "file",
duplex: _maybeEncodedRequest.duplex,
body: _maybeEncodedRequest.body,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.AudioNativeEditContentResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling POST /v1/audio-native/{project_id}/content.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Updates content for the specific AudioNative Project.
*
* @param {string} projectId
* @param {ElevenLabs.BodyUpdateAudioNativeProjectContentV1AudioNativeProjectIdContentPost} request
* @param {AudioNative.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.audioNative.updateContent("21m00Tcm4TlvDq8ikWAM", {})
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/audioNative/client/Client.ts#L175-L256 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getSignedUrl | public async getSignedUrl(
request: ElevenLabs.ConversationalAiGetSignedUrlRequest,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.ConversationSignedUrlResponseModel> {
const { agent_id: agentId } = request;
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
_queryParams["agent_id"] = agentId;
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/convai/conversation/get_signed_url",
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.ConversationSignedUrlResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/convai/conversation/get_signed_url.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Get a signed url to start a conversation with an agent with an agent that requires authorization
*
* @param {ElevenLabs.ConversationalAiGetSignedUrlRequest} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getSignedUrl({
* agent_id: "21m00Tcm4TlvDq8ikWAM"
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L51-L119 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.createAgent | public async createAgent(
request: ElevenLabs.BodyCreateAgentV1ConvaiAgentsCreatePost,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.CreateAgentResponseModel> {
const { use_tool_ids: useToolIds, ..._body } = request;
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
if (useToolIds != null) {
_queryParams["use_tool_ids"] = useToolIds.toString();
}
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/convai/agents/create",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
body: _body,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.CreateAgentResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling POST /v1/convai/agents/create.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Create an agent from a config object
*
* @param {ElevenLabs.BodyCreateAgentV1ConvaiAgentsCreatePost} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.createAgent({
* conversation_config: {}
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L134-L204 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getAgent | public async getAgent(
agentId: string,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetAgentResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/agents/${encodeURIComponent(agentId)}`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetAgentResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/convai/agents/{agent_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Retrieve config for an agent
*
* @param {string} agentId - The id of an agent. This is returned on agent creation.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getAgent("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L217-L281 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.deleteAgent | public async deleteAgent(agentId: string, requestOptions?: ConversationalAi.RequestOptions): Promise<unknown> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/agents/${encodeURIComponent(agentId)}`,
),
method: "DELETE",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling DELETE /v1/convai/agents/{agent_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Delete an agent
*
* @param {string} agentId - The id of an agent. This is returned on agent creation.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.deleteAgent("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L294-L355 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.updateAgent | public async updateAgent(
agentId: string,
request: ElevenLabs.BodyPatchesAnAgentSettingsV1ConvaiAgentsAgentIdPatch = {},
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetAgentResponseModel> {
const { use_tool_ids: useToolIds, ..._body } = request;
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
if (useToolIds != null) {
_queryParams["use_tool_ids"] = useToolIds.toString();
}
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/agents/${encodeURIComponent(agentId)}`,
),
method: "PATCH",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
body: _body,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetAgentResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling PATCH /v1/convai/agents/{agent_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Patches an Agent settings
*
* @param {string} agentId - The id of an agent. This is returned on agent creation.
* @param {ElevenLabs.BodyPatchesAnAgentSettingsV1ConvaiAgentsAgentIdPatch} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.updateAgent("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L369-L442 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getAgentWidget | public async getAgentWidget(
agentId: string,
request: ElevenLabs.ConversationalAiGetAgentWidgetRequest = {},
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetAgentEmbedResponseModel> {
const { conversation_signature: conversationSignature } = request;
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
if (conversationSignature != null) {
_queryParams["conversation_signature"] = conversationSignature;
}
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/agents/${encodeURIComponent(agentId)}/widget`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetAgentEmbedResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/convai/agents/{agent_id}/widget.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Retrieve the widget configuration for an agent
*
* @param {string} agentId - The id of an agent. This is returned on agent creation.
* @param {ElevenLabs.ConversationalAiGetAgentWidgetRequest} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getAgentWidget("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L456-L528 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getAgentLink | public async getAgentLink(
agentId: string,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetAgentLinkResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/agents/${encodeURIComponent(agentId)}/link`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetAgentLinkResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/convai/agents/{agent_id}/link.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Get the current link used to share the agent with others
*
* @param {string} agentId - The id of an agent. This is returned on agent creation.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getAgentLink("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L541-L605 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.postAgentAvatar | public async postAgentAvatar(
agentId: string,
request: ElevenLabs.BodyPostAgentAvatarV1ConvaiAgentsAgentIdAvatarPost,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.PostAgentAvatarResponseModel> {
const _request = await core.newFormData();
await _request.appendFile("avatar_file", request.avatar_file);
const _maybeEncodedRequest = await _request.getRequest();
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/agents/${encodeURIComponent(agentId)}/avatar`,
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
..._maybeEncodedRequest.headers,
...requestOptions?.headers,
},
requestType: "file",
duplex: _maybeEncodedRequest.duplex,
body: _maybeEncodedRequest.body,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.PostAgentAvatarResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling POST /v1/convai/agents/{agent_id}/avatar.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Sets the avatar for an agent displayed in the widget
*
* @param {string} agentId
* @param {ElevenLabs.BodyPostAgentAvatarV1ConvaiAgentsAgentIdAvatarPost} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.postAgentAvatar("21m00Tcm4TlvDq8ikWAM", {
* avatar_file: fs.createReadStream("/path/to/your/file")
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L621-L691 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.addAgentSecret | public async addAgentSecret(
agentId: string,
request: ElevenLabs.BodyAddASecretToTheAgentWhichCanBeReferencedInToolCallsV1ConvaiAgentsAgentIdAddSecretPost,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.AddAgentSecretResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/agents/${encodeURIComponent(agentId)}/add-secret`,
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
body: request,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.AddAgentSecretResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling POST /v1/convai/agents/{agent_id}/add-secret.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Uploads a file or reference a webpage for the agent to use as part of it's knowledge base
*
* @param {string} agentId - The id of an agent. This is returned on agent creation.
* @param {ElevenLabs.BodyAddASecretToTheAgentWhichCanBeReferencedInToolCallsV1ConvaiAgentsAgentIdAddSecretPost} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.addAgentSecret("21m00Tcm4TlvDq8ikWAM", {
* name: "name",
* secret_value: "secret_value"
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L708-L774 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getAgents | public async getAgents(
request: ElevenLabs.ConversationalAiGetAgentsRequest = {},
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetAgentsPageResponseModel> {
const { cursor, page_size: pageSize, search } = request;
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
if (cursor != null) {
_queryParams["cursor"] = cursor;
}
if (pageSize != null) {
_queryParams["page_size"] = pageSize.toString();
}
if (search != null) {
_queryParams["search"] = search;
}
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/convai/agents",
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetAgentsPageResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling GET /v1/convai/agents.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Returns a page of your agents and their metadata.
*
* @param {ElevenLabs.ConversationalAiGetAgentsRequest} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getAgents()
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L787-L864 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getConversations | public async getConversations(
request: ElevenLabs.ConversationalAiGetConversationsRequest = {},
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetConversationsPageResponseModel> {
const { cursor, agent_id: agentId, call_successful: callSuccessful, page_size: pageSize } = request;
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
if (cursor != null) {
_queryParams["cursor"] = cursor;
}
if (agentId != null) {
_queryParams["agent_id"] = agentId;
}
if (callSuccessful != null) {
_queryParams["call_successful"] = callSuccessful;
}
if (pageSize != null) {
_queryParams["page_size"] = pageSize.toString();
}
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/convai/conversations",
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetConversationsPageResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling GET /v1/convai/conversations.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Get all conversations of agents that user owns. With option to restrict to a specific agent.
*
* @param {ElevenLabs.ConversationalAiGetConversationsRequest} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getConversations({
* agent_id: "21m00Tcm4TlvDq8ikWAM"
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L879-L960 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getConversation | public async getConversation(
conversationId: string,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetConversationResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/conversations/${encodeURIComponent(conversationId)}`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetConversationResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/convai/conversations/{conversation_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Get the details of a particular conversation
*
* @param {string} conversationId - The id of the conversation you're taking the action on.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getConversation("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L973-L1037 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.deleteConversation | public async deleteConversation(
conversationId: string,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<unknown> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/conversations/${encodeURIComponent(conversationId)}`,
),
method: "DELETE",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling DELETE /v1/convai/conversations/{conversation_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Delete a particular conversation
*
* @param {string} conversationId - The id of the conversation you're taking the action on.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.deleteConversation("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1050-L1114 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getConversationAudio | public async getConversationAudio(
conversationId: string,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<void> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/conversations/${encodeURIComponent(conversationId)}/audio`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/convai/conversations/{conversation_id}/audio.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Get the audio recording of a particular conversation
*
* @param {string} conversationId - The id of the conversation you're taking the action on.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getConversationAudio("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1127-L1191 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.postConversationFeedback | public async postConversationFeedback(
conversationId: string,
request: ElevenLabs.BodySendConversationFeedbackV1ConvaiConversationsConversationIdFeedbackPost,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<unknown> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/conversations/${encodeURIComponent(conversationId)}/feedback`,
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
body: request,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling POST /v1/convai/conversations/{conversation_id}/feedback.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Send the feedback for the given conversation
*
* @param {string} conversationId - The id of the conversation you're taking the action on.
* @param {ElevenLabs.BodySendConversationFeedbackV1ConvaiConversationsConversationIdFeedbackPost} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.postConversationFeedback("21m00Tcm4TlvDq8ikWAM", {
* feedback: "like"
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1207-L1273 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.createPhoneNumber | public async createPhoneNumber(
request: ElevenLabs.CreatePhoneNumberRequest,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.CreatePhoneNumberResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/convai/phone-numbers/create",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
body: { ...request, provider: "twilio" },
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.CreatePhoneNumberResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling POST /v1/convai/phone-numbers/create.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Import Phone Number from Twilio configuration
*
* @param {ElevenLabs.CreatePhoneNumberRequest} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.createPhoneNumber({
* phone_number: "phone_number",
* provider: "twilio",
* label: "label",
* sid: "sid",
* token: "token"
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1292-L1357 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getPhoneNumber | public async getPhoneNumber(
phoneNumberId: string,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetPhoneNumberResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/phone-numbers/${encodeURIComponent(phoneNumberId)}`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetPhoneNumberResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/convai/phone-numbers/{phone_number_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Retrieve Phone Number details by ID
*
* @param {string} phoneNumberId - The id of an agent. This is returned on agent creation.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getPhoneNumber("TeaqRRdTcIfIu2i7BYfT")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1370-L1434 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.deletePhoneNumber | public async deletePhoneNumber(
phoneNumberId: string,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<unknown> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/phone-numbers/${encodeURIComponent(phoneNumberId)}`,
),
method: "DELETE",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling DELETE /v1/convai/phone-numbers/{phone_number_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Delete Phone Number by ID
*
* @param {string} phoneNumberId - The id of an agent. This is returned on agent creation.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.deletePhoneNumber("TeaqRRdTcIfIu2i7BYfT")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1447-L1511 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.updatePhoneNumber | public async updatePhoneNumber(
phoneNumberId: string,
request: ElevenLabs.UpdatePhoneNumberRequest = {},
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetPhoneNumberResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/phone-numbers/${encodeURIComponent(phoneNumberId)}`,
),
method: "PATCH",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
body: request,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetPhoneNumberResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling PATCH /v1/convai/phone-numbers/{phone_number_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Update Phone Number details by ID
*
* @param {string} phoneNumberId - The id of an agent. This is returned on agent creation.
* @param {ElevenLabs.UpdatePhoneNumberRequest} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.updatePhoneNumber("TeaqRRdTcIfIu2i7BYfT")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1525-L1591 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getPhoneNumbers | public async getPhoneNumbers(
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetPhoneNumberResponseModel[]> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/convai/phone-numbers/",
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetPhoneNumberResponseModel[];
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling GET /v1/convai/phone-numbers/.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Retrieve all Phone Numbers
*
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getPhoneNumbers()
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1603-L1664 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getKnowledgeBaseList | public async getKnowledgeBaseList(
request: ElevenLabs.ConversationalAiGetKnowledgeBaseListRequest = {},
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetKnowledgeBaseListResponseModel> {
const { cursor, page_size: pageSize } = request;
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
if (cursor != null) {
_queryParams["cursor"] = cursor;
}
if (pageSize != null) {
_queryParams["page_size"] = pageSize.toString();
}
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/convai/knowledge-base",
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetKnowledgeBaseListResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling GET /v1/convai/knowledge-base.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Get a list of available knowledge base documents
*
* @param {ElevenLabs.ConversationalAiGetKnowledgeBaseListRequest} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getKnowledgeBaseList()
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1677-L1750 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.addToKnowledgeBase | public async addToKnowledgeBase(
request: ElevenLabs.BodyAddToKnowledgeBaseV1ConvaiKnowledgeBasePost,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.AddKnowledgeBaseResponseModel> {
const _request = await core.newFormData();
if (request.url != null) {
_request.append("url", request.url);
}
if (request.file != null) {
await _request.appendFile("file", request.file);
}
const _maybeEncodedRequest = await _request.getRequest();
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/convai/knowledge-base",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
..._maybeEncodedRequest.headers,
...requestOptions?.headers,
},
requestType: "file",
duplex: _maybeEncodedRequest.duplex,
body: _maybeEncodedRequest.body,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.AddKnowledgeBaseResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling POST /v1/convai/knowledge-base.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Uploads a file or reference a webpage to use as part of the shared knowledge base
*
* @param {ElevenLabs.BodyAddToKnowledgeBaseV1ConvaiKnowledgeBasePost} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.addToKnowledgeBase({})
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1763-L1839 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getKnowledgeBaseDocumentById | public async getKnowledgeBaseDocumentById(
documentationId: string,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetKnowledgeBaseResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/knowledge-base/${encodeURIComponent(documentationId)}`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetKnowledgeBaseResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/convai/knowledge-base/{documentation_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Get details about a specific documentation making up the agent's knowledge base
*
* @param {string} documentationId - The id of a document from the knowledge base. This is returned on document addition.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getKnowledgeBaseDocumentById("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1852-L1916 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.deleteKnowledgeBaseDocument | public async deleteKnowledgeBaseDocument(
documentationId: string,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<unknown> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/knowledge-base/${encodeURIComponent(documentationId)}`,
),
method: "DELETE",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling DELETE /v1/convai/knowledge-base/{documentation_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Delete a document from the knowledge base
*
* @param {string} documentationId - The id of a document from the knowledge base. This is returned on document addition.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.deleteKnowledgeBaseDocument("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L1929-L1993 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getDependentAgents | public async getDependentAgents(
documentationId: string,
request: ElevenLabs.ConversationalAiGetDependentAgentsRequest = {},
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.GetKnowledgeBaseDependentAgentsResponseModel> {
const { cursor, page_size: pageSize } = request;
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
if (cursor != null) {
_queryParams["cursor"] = cursor;
}
if (pageSize != null) {
_queryParams["page_size"] = pageSize.toString();
}
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/knowledge-base/${encodeURIComponent(documentationId)}/dependent-agents`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetKnowledgeBaseDependentAgentsResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/convai/knowledge-base/{documentation_id}/dependent-agents.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Get a list of agents depending on this knowledge base document
*
* @param {string} documentationId - The id of a document from the knowledge base. This is returned on document addition.
* @param {ElevenLabs.ConversationalAiGetDependentAgentsRequest} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getDependentAgents("21m00Tcm4TlvDq8ikWAM")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L2007-L2083 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getTools | public async getTools(requestOptions?: ConversationalAi.RequestOptions): Promise<ElevenLabs.ToolsResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/convai/tools",
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.ToolsResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling GET /v1/convai/tools.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Get all available tools available in the workspace.
*
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getTools()
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L2095-L2154 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.addTool | public async addTool(
request: ElevenLabs.ToolRequestModel,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.ToolResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/convai/tools",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
body: request,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.ToolResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling POST /v1/convai/tools.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Add a new tool to the available tools in the workspace.
*
* @param {ElevenLabs.ToolRequestModel} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.addTool({
* tool_config: {
* type: "webhook",
* name: "name",
* description: "description",
* api_schema: {
* url: "url"
* }
* }
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L2176-L2239 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.getTool | public async getTool(
toolId: string,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.ToolResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/tools/${encodeURIComponent(toolId)}`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.ToolResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/convai/tools/{tool_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Get tool that is available in the workspace.
*
* @param {string} toolId - ID of the requested tool.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.getTool("tool_id")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L2252-L2316 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.removeTool | public async removeTool(toolId: string, requestOptions?: ConversationalAi.RequestOptions): Promise<unknown> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/tools/${encodeURIComponent(toolId)}`,
),
method: "DELETE",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling DELETE /v1/convai/tools/{tool_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Delete tool from the workspace.
*
* @param {string} toolId - ID of the requested tool.
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.removeTool("tool_id")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L2329-L2390 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | ConversationalAi.updateTool | public async updateTool(
toolId: string,
request: ElevenLabs.ToolRequestModel,
requestOptions?: ConversationalAi.RequestOptions,
): Promise<ElevenLabs.ToolResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/convai/tools/${encodeURIComponent(toolId)}`,
),
method: "PATCH",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
body: request,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.ToolResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling PATCH /v1/convai/tools/{tool_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Update tool that is available in the workspace.
*
* @param {string} toolId - ID of the requested tool.
* @param {ElevenLabs.ToolRequestModel} request
* @param {ConversationalAi.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.conversationalAi.updateTool("tool_id", {
* tool_config: {
* type: "webhook",
* name: "name",
* description: "description",
* api_schema: {
* url: "url"
* }
* }
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/conversationalAi/client/Client.ts#L2413-L2479 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | Dubbing.dubAVideoOrAnAudioFile | public async dubAVideoOrAnAudioFile(
request: ElevenLabs.BodyDubAVideoOrAnAudioFileV1DubbingPost,
requestOptions?: Dubbing.RequestOptions,
): Promise<ElevenLabs.DoDubbingResponse> {
const _request = await core.newFormData();
if (request.file != null) {
await _request.appendFile("file", request.file);
}
if (request.name != null) {
_request.append("name", request.name);
}
if (request.source_url != null) {
_request.append("source_url", request.source_url);
}
if (request.source_lang != null) {
_request.append("source_lang", request.source_lang);
}
_request.append("target_lang", request.target_lang);
if (request.num_speakers != null) {
_request.append("num_speakers", request.num_speakers.toString());
}
if (request.watermark != null) {
_request.append("watermark", request.watermark.toString());
}
if (request.start_time != null) {
_request.append("start_time", request.start_time.toString());
}
if (request.end_time != null) {
_request.append("end_time", request.end_time.toString());
}
if (request.highest_resolution != null) {
_request.append("highest_resolution", request.highest_resolution.toString());
}
if (request.drop_background_audio != null) {
_request.append("drop_background_audio", request.drop_background_audio.toString());
}
if (request.use_profanity_filter != null) {
_request.append("use_profanity_filter", request.use_profanity_filter.toString());
}
const _maybeEncodedRequest = await _request.getRequest();
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/dubbing",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
..._maybeEncodedRequest.headers,
...requestOptions?.headers,
},
requestType: "file",
duplex: _maybeEncodedRequest.duplex,
body: _maybeEncodedRequest.body,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.DoDubbingResponse;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling POST /v1/dubbing.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Dubs provided audio or video file into given language.
*
* @param {ElevenLabs.BodyDubAVideoOrAnAudioFileV1DubbingPost} request
* @param {Dubbing.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.dubbing.dubAVideoOrAnAudioFile({
* target_lang: "target_lang"
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/dubbing/client/Client.ts#L51-L162 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | Dubbing.getDubbingProjectMetadata | public async getDubbingProjectMetadata(
dubbingId: string,
requestOptions?: Dubbing.RequestOptions,
): Promise<ElevenLabs.DubbingMetadataResponse> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/dubbing/${encodeURIComponent(dubbingId)}`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.DubbingMetadataResponse;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling GET /v1/dubbing/{dubbing_id}.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Returns metadata about a dubbing project, including whether it's still in progress or not
*
* @param {string} dubbingId - ID of the dubbing project.
* @param {Dubbing.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.dubbing.getDubbingProjectMetadata("dubbing_id")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/dubbing/client/Client.ts#L175-L237 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | Dubbing.deleteDubbingProject | public async deleteDubbingProject(dubbingId: string, requestOptions?: Dubbing.RequestOptions): Promise<unknown> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/dubbing/${encodeURIComponent(dubbingId)}`,
),
method: "DELETE",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling DELETE /v1/dubbing/{dubbing_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Deletes a dubbing project.
*
* @param {string} dubbingId - ID of the dubbing project.
* @param {Dubbing.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.dubbing.deleteDubbingProject("dubbing_id")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/dubbing/client/Client.ts#L250-L311 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | Dubbing.getDubbedFile | public async getDubbedFile(
dubbingId: string,
languageCode: string,
requestOptions?: Dubbing.RequestOptions,
): Promise<stream.Readable> {
const _response = await core.fetcher<stream.Readable>({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/dubbing/${encodeURIComponent(dubbingId)}/audio/${encodeURIComponent(languageCode)}`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
responseType: "streaming",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/dubbing/{dubbing_id}/audio/{language_code}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Returns dubbed file as a streamed file. Videos will be returned in MP4 format and audio only dubs will be returned in MP3.
* @throws {@link ElevenLabs.UnprocessableEntityError}
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/dubbing/client/Client.ts#L317-L383 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | Dubbing.getTranscriptForDub | public async getTranscriptForDub(
dubbingId: string,
languageCode: string,
request: ElevenLabs.DubbingGetTranscriptForDubRequest = {},
requestOptions?: Dubbing.RequestOptions,
): Promise<unknown> {
const { format_type: formatType } = request;
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
if (formatType != null) {
_queryParams["format_type"] = formatType;
}
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/dubbing/${encodeURIComponent(dubbingId)}/transcript/${encodeURIComponent(languageCode)}`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/dubbing/{dubbing_id}/transcript/{language_code}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Returns transcript for the dub as an SRT file.
*
* @param {string} dubbingId - ID of the dubbing project.
* @param {string} languageCode - ID of the language.
* @param {ElevenLabs.DubbingGetTranscriptForDubRequest} request
* @param {Dubbing.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.dubbing.getTranscriptForDub("dubbing_id", "language_code")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/dubbing/client/Client.ts#L398-L471 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | History.getAll | public async getAll(
request: ElevenLabs.HistoryGetAllRequest = {},
requestOptions?: History.RequestOptions,
): Promise<ElevenLabs.GetSpeechHistoryResponse> {
const {
page_size: pageSize,
start_after_history_item_id: startAfterHistoryItemId,
voice_id: voiceId,
search,
source,
} = request;
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
if (pageSize != null) {
_queryParams["page_size"] = pageSize.toString();
}
if (startAfterHistoryItemId != null) {
_queryParams["start_after_history_item_id"] = startAfterHistoryItemId;
}
if (voiceId != null) {
_queryParams["voice_id"] = voiceId;
}
if (search != null) {
_queryParams["search"] = search;
}
if (source != null) {
_queryParams["source"] = source;
}
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/history",
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetSpeechHistoryResponse;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling GET /v1/history.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Returns metadata about all your generated audio.
*
* @param {ElevenLabs.HistoryGetAllRequest} request
* @param {History.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.history.getAll()
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/history/client/Client.ts#L49-L140 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | History.get | public async get(
historyItemId: string,
requestOptions?: History.RequestOptions,
): Promise<ElevenLabs.SpeechHistoryItemResponse> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/history/${encodeURIComponent(historyItemId)}`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.SpeechHistoryItemResponse;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/history/{history_item_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Returns information about an history item by its ID.
*
* @param {string} historyItemId - History item ID to be used, you can use GET https://api.elevenlabs.io/v1/history to receive a list of history items and their IDs.
* @param {History.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.history.get("HISTORY_ITEM_ID")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/history/client/Client.ts#L153-L217 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | History.delete | public async delete(historyItemId: string, requestOptions?: History.RequestOptions): Promise<unknown> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/history/${encodeURIComponent(historyItemId)}`,
),
method: "DELETE",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling DELETE /v1/history/{history_item_id}.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Delete a history item by its ID
*
* @param {string} historyItemId - History item ID to be used, you can use GET https://api.elevenlabs.io/v1/history to receive a list of history items and their IDs.
* @param {History.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.history.delete("HISTORY_ITEM_ID")
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/history/client/Client.ts#L230-L291 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | History.getAudio | public async getAudio(historyItemId: string, requestOptions?: History.RequestOptions): Promise<stream.Readable> {
const _response = await core.fetcher<stream.Readable>({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
`v1/history/${encodeURIComponent(historyItemId)}/audio`,
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
responseType: "streaming",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling GET /v1/history/{history_item_id}/audio.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Returns the audio of an history item.
* @throws {@link ElevenLabs.UnprocessableEntityError}
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/history/client/Client.ts#L297-L359 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | History.download | public async download(
request: ElevenLabs.DownloadHistoryRequest,
requestOptions?: History.RequestOptions,
): Promise<void> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/history/download",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
body: request,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling POST /v1/history/download.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Download one or more history items. If one history item ID is provided, we will return a single audio file. If more than one history item IDs are provided, we will provide the history items packed into a .zip file.
*
* @param {ElevenLabs.DownloadHistoryRequest} request
* @param {History.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.history.download({
* history_item_ids: ["HISTORY_ITEM_ID"]
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/history/client/Client.ts#L374-L437 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | Models.getAll | public async getAll(requestOptions?: Models.RequestOptions): Promise<ElevenLabs.Model[]> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/models",
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.Model[];
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling GET /v1/models.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Gets a list of available models.
*
* @param {Models.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.models.getAll()
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/models/client/Client.ts#L50-L109 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | Projects.createPodcast | public async createPodcast(
request: ElevenLabs.BodyCreatePodcastV1ProjectsPodcastCreatePost,
requestOptions?: Projects.RequestOptions,
): Promise<ElevenLabs.PodcastProjectResponseModel> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/projects/podcast/create",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
body: request,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.PodcastProjectResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError(
"Timeout exceeded when calling POST /v1/projects/podcast/create.",
);
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Create and auto-convert a podcast project. Currently, the LLM cost is covered by us but you will still be charged for the audio generation. In the future, you will be charged for both the LLM and audio generation costs.
*
* @param {ElevenLabs.BodyCreatePodcastV1ProjectsPodcastCreatePost} request
* @param {Projects.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.projects.createPodcast({
* model_id: "model_id",
* mode: {
* type: "conversation",
* conversation: {
* host_voice_id: "host_voice_id",
* guest_voice_id: "guest_voice_id"
* }
* },
* source: {
* text: "text"
* }
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/projects/client/Client.ts#L64-L129 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | Projects.getProjects | public async getProjects(requestOptions?: Projects.RequestOptions): Promise<ElevenLabs.GetProjectsResponse> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/projects",
),
method: "GET",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.GetProjectsResponse;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling GET /v1/projects.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Returns a list of your projects together and its metadata.
*
* @param {Projects.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.projects.getProjects()
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/projects/client/Client.ts#L141-L200 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
elevenlabs-js | github_2023 | elevenlabs | typescript | Projects.addProject | public async addProject(
request: ElevenLabs.BodyAddProjectV1ProjectsAddPost,
requestOptions?: Projects.RequestOptions,
): Promise<ElevenLabs.AddProjectResponseModel> {
const _request = await core.newFormData();
_request.append("name", request.name);
_request.append("default_title_voice_id", request.default_title_voice_id);
_request.append("default_paragraph_voice_id", request.default_paragraph_voice_id);
_request.append("default_model_id", request.default_model_id);
if (request.from_url != null) {
_request.append("from_url", request.from_url);
}
if (request.from_document != null) {
await _request.appendFile("from_document", request.from_document);
}
if (request.quality_preset != null) {
_request.append("quality_preset", request.quality_preset);
}
if (request.title != null) {
_request.append("title", request.title);
}
if (request.author != null) {
_request.append("author", request.author);
}
if (request.description != null) {
_request.append("description", request.description);
}
if (request.genres != null) {
for (const _item of request.genres) {
_request.append("genres", _item);
}
}
if (request.target_audience != null) {
_request.append("target_audience", request.target_audience);
}
if (request.language != null) {
_request.append("language", request.language);
}
if (request.content_type != null) {
_request.append("content_type", request.content_type);
}
if (request.original_publication_date != null) {
_request.append("original_publication_date", request.original_publication_date);
}
if (request.mature_content != null) {
_request.append("mature_content", request.mature_content.toString());
}
if (request.isbn_number != null) {
_request.append("isbn_number", request.isbn_number);
}
if (request.acx_volume_normalization != null) {
_request.append("acx_volume_normalization", request.acx_volume_normalization.toString());
}
if (request.volume_normalization != null) {
_request.append("volume_normalization", request.volume_normalization.toString());
}
if (request.pronunciation_dictionary_locators != null) {
for (const _item of request.pronunciation_dictionary_locators) {
_request.append("pronunciation_dictionary_locators", _item);
}
}
if (request.fiction != null) {
_request.append("fiction", request.fiction);
}
if (request.quality_check_on != null) {
_request.append("quality_check_on", request.quality_check_on.toString());
}
if (request.apply_text_normalization != null) {
_request.append("apply_text_normalization", request.apply_text_normalization);
}
if (request.auto_convert != null) {
_request.append("auto_convert", request.auto_convert.toString());
}
if (request.auto_assign_voices != null) {
_request.append("auto_assign_voices", request.auto_assign_voices.toString());
}
const _maybeEncodedRequest = await _request.getRequest();
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.ElevenLabsEnvironment.Production,
"v1/projects/add",
),
method: "POST",
headers: {
"xi-api-key":
(await core.Supplier.get(this._options.apiKey)) != null
? await core.Supplier.get(this._options.apiKey)
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "1.51.0",
"User-Agent": "elevenlabs/1.51.0",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
..._maybeEncodedRequest.headers,
...requestOptions?.headers,
},
requestType: "file",
duplex: _maybeEncodedRequest.duplex,
body: _maybeEncodedRequest.body,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ElevenLabs.AddProjectResponseModel;
}
if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 422:
throw new ElevenLabs.UnprocessableEntityError(
_response.error.body as ElevenLabs.HttpValidationError,
);
default:
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}
switch (_response.error.reason) {
case "non-json":
throw new errors.ElevenLabsError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ElevenLabsTimeoutError("Timeout exceeded when calling POST /v1/projects/add.");
case "unknown":
throw new errors.ElevenLabsError({
message: _response.error.errorMessage,
});
}
} | /**
* Creates a new project, it can be either initialized as blank, from a document or from a URL.
*
* @param {ElevenLabs.BodyAddProjectV1ProjectsAddPost} request
* @param {Projects.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link ElevenLabs.UnprocessableEntityError}
*
* @example
* await client.projects.addProject({
* name: "name",
* default_title_voice_id: "default_title_voice_id",
* default_paragraph_voice_id: "default_paragraph_voice_id",
* default_model_id: "default_model_id"
* })
*/ | https://github.com/elevenlabs/elevenlabs-js/blob/89894c5601806e8c95e7eb3931a7d674e5ad9a8d/src/api/resources/projects/client/Client.ts#L218-L376 | 89894c5601806e8c95e7eb3931a7d674e5ad9a8d |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.