Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions src/ai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,76 @@ export class Ai extends CrowdinApi {
return this.get(url, this.defaultConfig());
}

/**
* @param aiProviderId ai Provider identifier
* @param path raw provider API path after `/gateway/`
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.enterprise.get
*/
organizationAiGatewayGet(aiProviderId: number, path: string): Promise<ResponseObject<PlainObject>> {
const url = `${this.url}/ai/providers/${aiProviderId}/gateway/${path}`;

return this.get(url, this.defaultConfig());
}

/**
* @param aiProviderId ai Provider identifier
* @param path raw provider API path after `/gateway/`
* @param request request body
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.enterprise.post
*/
organizationAiGatewayPost(
aiProviderId: number,
path: string,
request?: PlainObject,
): Promise<ResponseObject<PlainObject>> {
const url = `${this.url}/ai/providers/${aiProviderId}/gateway/${path}`;

return this.post(url, request, this.defaultConfig());
}

/**
* @param aiProviderId ai Provider identifier
* @param path raw provider API path after `/gateway/`
* @param request request body
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.enterprise.put
*/
organizationAiGatewayPut(
aiProviderId: number,
path: string,
request?: PlainObject,
): Promise<ResponseObject<PlainObject>> {
const url = `${this.url}/ai/providers/${aiProviderId}/gateway/${path}`;

return this.put(url, request, this.defaultConfig());
}

/**
* @param aiProviderId ai Provider identifier
* @param path raw provider API path after `/gateway/`
* @param request request body
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.enterprise.patch
*/
organizationAiGatewayPatch(
aiProviderId: number,
path: string,
request?: PlainObject,
): Promise<ResponseObject<PlainObject>> {
const url = `${this.url}/ai/providers/${aiProviderId}/gateway/${path}`;

return this.patch(url, request, this.defaultConfig());
}

/**
* @param aiProviderId ai Provider identifier
* @param path raw provider API path after `/gateway/`
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.enterprise.delete
*/
organizationAiGatewayDelete(aiProviderId: number, path: string): Promise<ResponseObject<PlainObject>> {
const url = `${this.url}/ai/providers/${aiProviderId}/gateway/${path}`;

return this.delete(url, this.defaultConfig());
}

// Community

/**
Expand Down Expand Up @@ -1112,6 +1182,84 @@ export class Ai extends CrowdinApi {

return this.get(url, this.defaultConfig());
}

/**
* @param userId user identifier
* @param aiProviderId ai Provider identifier
* @param path raw provider API path after `/gateway/`
* @see https://support.crowdin.com/developer/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.crowdin.get
*/
userAiGatewayGet(userId: number, aiProviderId: number, path: string): Promise<ResponseObject<PlainObject>> {
const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/gateway/${path}`;

return this.get(url, this.defaultConfig());
}

/**
* @param userId user identifier
* @param aiProviderId ai Provider identifier
* @param path raw provider API path after `/gateway/`
* @param request request body
* @see https://support.crowdin.com/developer/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.crowdin.post
*/
userAiGatewayPost(
userId: number,
aiProviderId: number,
path: string,
request?: PlainObject,
): Promise<ResponseObject<PlainObject>> {
const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/gateway/${path}`;

return this.post(url, request, this.defaultConfig());
}

/**
* @param userId user identifier
* @param aiProviderId ai Provider identifier
* @param path raw provider API path after `/gateway/`
* @param request request body
* @see https://support.crowdin.com/developer/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.crowdin.put
*/
userAiGatewayPut(
userId: number,
aiProviderId: number,
path: string,
request?: PlainObject,
): Promise<ResponseObject<PlainObject>> {
const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/gateway/${path}`;

return this.put(url, request, this.defaultConfig());
}

/**
* @param userId user identifier
* @param aiProviderId ai Provider identifier
* @param path raw provider API path after `/gateway/`
* @param request request body
* @see https://support.crowdin.com/developer/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.crowdin.patch
*/
userAiGatewayPatch(
userId: number,
aiProviderId: number,
path: string,
request?: PlainObject,
): Promise<ResponseObject<PlainObject>> {
const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/gateway/${path}`;

return this.patch(url, request, this.defaultConfig());
}

/**
* @param userId user identifier
* @param aiProviderId ai Provider identifier
* @param path raw provider API path after `/gateway/`
* @see https://support.crowdin.com/developer/api/v2/#tag/AI-Gateway/operation/api.ai.providers.gateway.crowdin.delete
*/
userAiGatewayDelete(userId: number, aiProviderId: number, path: string): Promise<ResponseObject<PlainObject>> {
const url = `${this.url}/users/${userId}/ai/providers/${aiProviderId}/gateway/${path}`;

return this.delete(url, this.defaultConfig());
}
}

export namespace AiModel {
Expand Down
10 changes: 8 additions & 2 deletions src/sourceStrings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,16 @@ export class SourceStrings extends CrowdinApi {
/**
* @param projectId project identifier
* @param request request body
* @param query query params
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.strings.batchPatch
*/
stringBatchOperations(
projectId: number,
request: PatchRequest[],
query?: { updateOption?: SourceStringsModel.UpdateOption },
): Promise<ResponseList<SourceStringsModel.String>> {
const url = `${this.url}/projects/${projectId}/strings`;
let url = `${this.url}/projects/${projectId}/strings`;
url = this.addQueryParam(url, 'updateOption', query?.updateOption);
return this.patch(url, request, this.defaultConfig());
}

Expand Down Expand Up @@ -174,14 +177,17 @@ export class SourceStrings extends CrowdinApi {
* @param projectId project identifier
* @param stringId string identifier
* @param request request body
* @param query query params
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.strings.patch
*/
editString(
projectId: number,
stringId: number,
request: PatchRequest[],
query?: { updateOption?: SourceStringsModel.UpdateOption },
): Promise<ResponseObject<SourceStringsModel.String>> {
const url = `${this.url}/projects/${projectId}/strings/${stringId}`;
let url = `${this.url}/projects/${projectId}/strings/${stringId}`;
url = this.addQueryParam(url, 'updateOption', query?.updateOption);
return this.patch(url, request, this.defaultConfig());
}
}
Expand Down
130 changes: 130 additions & 0 deletions tests/ai/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,46 @@ describe('AI API', () => {
url: link,
},
})
.get(`/ai/providers/${aiProviderId}/gateway/chat/completions`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: field,
})
.post(`/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: field,
})
.put(`/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: field,
})
.patch(`/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: field,
})
.delete(`/ai/providers/${aiProviderId}/gateway/chat/completions`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: field,
})
.get(`/users/${userId}/ai/settings/custom-placeholders`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
Expand Down Expand Up @@ -1185,6 +1225,46 @@ describe('AI API', () => {
data: {
url: link,
},
})
.get(`/users/${userId}/ai/providers/${aiProviderId}/gateway/chat/completions`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: field,
})
.post(`/users/${userId}/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: field,
})
.put(`/users/${userId}/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: field,
})
.patch(`/users/${userId}/ai/providers/${aiProviderId}/gateway/chat/completions`, field, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: field,
})
.delete(`/users/${userId}/ai/providers/${aiProviderId}/gateway/chat/completions`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: field,
});
});

Expand Down Expand Up @@ -1461,6 +1541,31 @@ describe('AI API', () => {
expect(res.data.url).toBe(link);
});

it('Organization AI Gateway GET', async () => {
const res = await api.organizationAiGatewayGet(aiProviderId, 'chat/completions');
expect(res.data).toStrictEqual(field);
});

it('Organization AI Gateway POST', async () => {
const res = await api.organizationAiGatewayPost(aiProviderId, 'chat/completions', field);
expect(res.data).toStrictEqual(field);
});

it('Organization AI Gateway PUT', async () => {
const res = await api.organizationAiGatewayPut(aiProviderId, 'chat/completions', field);
expect(res.data).toStrictEqual(field);
});

it('Organization AI Gateway PATCH', async () => {
const res = await api.organizationAiGatewayPatch(aiProviderId, 'chat/completions', field);
expect(res.data).toStrictEqual(field);
});

it('Organization AI Gateway DELETE', async () => {
const res = await api.organizationAiGatewayDelete(aiProviderId, 'chat/completions');
expect(res.data).toStrictEqual(field);
});

it('List AI User Custom Placeholders', async () => {
const placeholders = await api.listAiUserCustomPlaceholders(userId);
expect(placeholders.data.length).toBe(1);
Expand Down Expand Up @@ -1729,4 +1834,29 @@ describe('AI API', () => {
const res = await api.downloadAiUserFileTranslationStrings(userId, jobId);
expect(res.data.url).toBe(link);
});

it('User AI Gateway GET', async () => {
const res = await api.userAiGatewayGet(userId, aiProviderId, 'chat/completions');
expect(res.data).toStrictEqual(field);
});

it('User AI Gateway POST', async () => {
const res = await api.userAiGatewayPost(userId, aiProviderId, 'chat/completions', field);
expect(res.data).toStrictEqual(field);
});

it('User AI Gateway PUT', async () => {
const res = await api.userAiGatewayPut(userId, aiProviderId, 'chat/completions', field);
expect(res.data).toStrictEqual(field);
});

it('User AI Gateway PATCH', async () => {
const res = await api.userAiGatewayPatch(userId, aiProviderId, 'chat/completions', field);
expect(res.data).toStrictEqual(field);
});

it('User AI Gateway DELETE', async () => {
const res = await api.userAiGatewayDelete(userId, aiProviderId, 'chat/completions');
expect(res.data).toStrictEqual(field);
});
});
Loading