Merge branch 'main' into next

This commit is contained in:
nocobase[bot]
2026-02-25 15:11:50 +00:00
5 changed files with 40 additions and 12 deletions
@@ -21,5 +21,8 @@
"devDependencies": {
"langchain-gigachat": "^0.0.14"
},
"keywords": [
"AI"
],
"license": "Apache-2.0"
}
@@ -18,7 +18,7 @@ export const ProviderSettingsForm: React.FC = () => {
schema={{
type: 'void',
properties: {
credentials: {
apiKey: {
title: tval('Authorization key', { ns: namespace }),
type: 'string',
required: true,
@@ -48,12 +48,6 @@ export const ProviderSettingsForm: React.FC = () => {
],
},
},
baseURL: {
title: tval('Base URL', { ns: namespace }),
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'TextAreaWithGlobalScope',
},
authURL: {
title: tval('Auth URL', { ns: namespace }),
type: 'string',
@@ -13,16 +13,29 @@ import { GigaChat as GigaChatModel } from 'langchain-gigachat';
import { LLMProvider, LLMProviderMeta } from '@nocobase/plugin-ai';
type GigaChatOptions = {
credentials: string;
apiKey: string;
baseURL?: string;
authURL?: string;
scope?: 'GIGACHAT_API_PERS' | 'GIGACHAT_API_B2B' | 'GIGACHAT_API_CORP';
enableSSL?: boolean;
};
class GigaChatModelInternal extends GigaChatModel {
bindTools(tools, kwargs) {
return this.withConfig({
tools: tools?.map((t) => ({
name: t.name,
description: t.description,
parameters: t.schema.toJSONSchema?.() ?? t.schema,
})),
...kwargs,
});
}
}
export class GigaChatProvider extends LLMProvider {
createModel() {
const { credentials, baseURL, authURL, scope, enableSSL } = (this.serviceOptions as GigaChatOptions) || {};
const { apiKey: credentials, baseURL, authURL, scope, enableSSL } = (this.serviceOptions as GigaChatOptions) || {};
const { responseFormat } = this.modelOptions || {};
const baseUrl = this.isUrlEmpty(baseURL) ? this.baseURL : baseURL;
const authUrl = this.isUrlEmpty(authURL) ? this.authURL : authURL;
@@ -30,7 +43,7 @@ export class GigaChatProvider extends LLMProvider {
rejectUnauthorized: enableSSL ?? false,
});
return new GigaChatModel({
return new GigaChatModelInternal({
credentials,
baseUrl,
authUrl,
@@ -51,7 +64,13 @@ export class GigaChatProvider extends LLMProvider {
errMsg?: string;
}> {
try {
const { credentials, baseURL, authURL, scope, enableSSL } = (this.serviceOptions as GigaChatOptions) || {};
const {
apiKey: credentials,
baseURL,
authURL,
scope,
enableSSL,
} = (this.serviceOptions as GigaChatOptions) || {};
const baseUrl = this.isUrlEmpty(baseURL) ? this.baseURL : baseURL;
const authUrl = this.isUrlEmpty(authURL) ? this.authURL : authURL;
const httpsAgent = new Agent({
@@ -84,6 +103,13 @@ export class GigaChatProvider extends LLMProvider {
private isUrlEmpty(baseURL: string) {
return !baseURL || baseURL === null || baseURL.trim().length === 0;
}
parseResponseError(err) {
if (err?.name === 'AuthenticationError' || err?.name === 'ResponseError') {
return `GigaChat service error: ${err.response?.status} ${err.response?.statusText}`;
}
return err?.message ?? 'Unexpected LLM service error';
}
}
export const gigaChatProviderOptions: LLMProviderMeta = {
@@ -535,7 +535,7 @@ export class AIEmployee {
if (err.name === 'GraphRecursionError') {
this.sendSpecificError({ name: err.name, message: err.message });
} else {
this.sendErrorResponse(err.message);
this.sendErrorResponse(provider.parseResponseError(err));
}
} finally {
this.ctx.res.end();
@@ -180,6 +180,7 @@ export abstract class LLMProvider {
options,
};
}
async testFlight(): Promise<{ status: 'success' | 'error'; code: number; message?: string }> {
try {
const result = await this.chatModel.invoke('hello');
@@ -219,6 +220,10 @@ export abstract class LLMProvider {
parseResponseMetadata(output: LLMResult): any {
return [null, null];
}
parseResponseError(err) {
return err?.message ?? 'Unexpected LLM service error';
}
}
export interface EmbeddingProviderOptions {