cap-apps-ai-service-layer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRule: Domo App Platform AI (Toolkit-First)
规则:Domo应用平台AI(以工具包优先)
This rule is toolkit-first. Use from .
AIClient@domoinc/toolkitLegacy endpoint-first guidance has been archived to.archive/legacy-rules/domo-ai-endpoints.md
本规则以工具包优先。请使用中的。
@domoinc/toolkitAIClient旧版以端点优先的指南已归档至。archive/legacy-rules/domo-ai-endpoints.md
Canonical Client
标准客户端
bash
yarn add @domoinc/toolkittypescript
import { AIClient } from '@domoinc/toolkit';bash
yarn add @domoinc/toolkittypescript
import { AIClient } from '@domoinc/toolkit';Critical: AIClient methods are static
重点:AIClient的方法为静态方法
Do not instantiate for these methods.
AIClientWrong:
typescript
const ai = new AIClient();
await ai.text_to_sql('...');Correct:
typescript
await AIClient.text_to_sql('...');请勿为这些方法实例化。
AIClient错误示例:
typescript
const ai = new AIClient();
await ai.text_to_sql('...');正确示例:
typescript
await AIClient.text_to_sql('...');Text Generation
文本生成
typescript
const response = await AIClient.generate_text(
'Explain this sales trend in simple terms',
{ template: 'You are a business analyst. ${input}' },
{ tone: 'professional' },
undefined,
{ temperature: 0.7 }
);
const body = response.data || response.body || response;
const text = body.output || body.choices?.[0]?.output;typescript
const response = await AIClient.generate_text(
'用简单的语言解释这个销售趋势',
{ template: '你是一名商业分析师。${input}' },
{ tone: 'professional' },
undefined,
{ temperature: 0.7 }
);
const body = response.data || response.body || response;
const text = body.output || body.choices?.[0]?.output;Additional AI Methods
其他AI方法
text_to_sql
schema argument must be an array
text_to_sqltext_to_sql
的schema参数必须为数组
text_to_sqlWrong:
typescript
await AIClient.text_to_sql('Show top vendors by spend', {
dataSourceName: 'vendorPayments',
columns: [{ name: 'amount', type: 'number' }]
});Correct:
typescript
await AIClient.text_to_sql('Show top vendors by spend', [
{
dataSourceName: 'vendorPayments',
description: 'Vendor payment invoices',
columns: [
{ name: 'vendor', type: 'string' },
{ name: 'amount', type: 'number' },
{ name: 'date', type: 'date' }
]
}
]);错误示例:
typescript
await AIClient.text_to_sql('按支出显示顶级供应商', {
dataSourceName: 'vendorPayments',
columns: [{ name: 'amount', type: 'number' }]
});正确示例:
typescript
await AIClient.text_to_sql('按支出显示顶级供应商', [
{
dataSourceName: 'vendorPayments',
description: '供应商付款发票',
columns: [
{ name: 'vendor', type: 'string' },
{ name: 'amount', type: 'number' },
{ name: 'date', type: 'date' }
]
}
]);Signature reference
签名参考
(Approximate; check installed toolkit typings for exact current signature.)
typescript
AIClient.text_to_sql(
input: string,
dataSourceSchemas?: DataSourceSchema[], // array
promptTemplate?: any,
parameters?: Record<string, string>,
model?: string,
modelConfiguration?: Record<string, Object>
): Promise<Response<TextAIResponse>>;Why array: this supports multi-table SQL generation (including join-aware SQL) when multiple schemas are provided.
(为近似内容;请查看已安装工具包的类型定义获取当前准确签名。)
typescript
AIClient.text_to_sql(
input: string,
dataSourceSchemas?: DataSourceSchema[], // array
promptTemplate?: any,
parameters?: Record<string, string>,
model?: string,
modelConfiguration?: Record<string, Object>
): Promise<Response<TextAIResponse>>;为何使用数组:当提供多个schema时,这支持多表SQL生成(包括支持关联的SQL)。
text_to_sql usage note
text_to_sql使用说明
text_to_sql/sql/v1/data/v1@domoinc/querytypescript
const sqlResult = await AIClient.text_to_sql('Show total sales by region', [
{
dataSourceName: 'Sales',
description: 'Sales transactions',
columns: [{ name: 'region', type: 'string' }, { name: 'amount', type: 'number' }]
}
]);
const beastModeResult = await AIClient.text_to_beastmode(
'Calculate year over year growth percentage',
{ dataSourceName: 'Revenue', columns: [{ name: 'revenue', type: 'number' }, { name: 'date', type: 'date' }] }
);text_to_sql/sql/v1@domoinc/query/data/v1typescript
const sqlResult = await AIClient.text_to_sql('按区域显示总销售额', [
{
dataSourceName: 'Sales',
description: '销售交易记录',
columns: [{ name: 'region', type: 'string' }, { name: 'amount', type: 'number' }]
}
]);
const beastModeResult = await AIClient.text_to_beastmode(
'计算同比增长率',
{ dataSourceName: 'Revenue', columns: [{ name: 'revenue', type: 'number' }, { name: 'date', type: 'date' }] }
);Response Handling Rule
响应处理规则
AIClient- often uses
response.data - may include both and
outputchoices
Use defensive parsing plus a strict string guard:
typescript
const body = response?.data ?? response?.body ?? response;
const outputCandidate = body?.output ?? body?.choices?.[0]?.output;
const output = typeof outputCandidate === 'string' ? outputCandidate.trim() : '';
if (!output) throw new Error('AI returned no usable output');AIClient- 通常使用
response.data - 可能同时包含和
outputchoices
请使用防御式解析加上严格的字符串校验:
typescript
const body = response?.data ?? response?.body ?? response;
const outputCandidate = body?.output ?? body?.choices?.[0]?.output;
const output = typeof outputCandidate === 'string' ? outputCandidate.trim() : '';
if (!output) throw new Error('AI未返回可用输出');Canonical Rules References
标准规则参考
- Toolkit AI methods and caveats:
.cursor/rules/04-toolkit.mdc - Naming/response gotchas:
.cursor/rules/09-gotchas.mdc
- 工具包AI方法及注意事项:
.cursor/rules/04-toolkit.mdc - 命名/响应陷阱:
.cursor/rules/09-gotchas.mdc
Checklist
检查清单
- methods use snake_case (
AIClient,generate_text, etc.)text_to_sql - methods are called statically (for example
AIClient, not instance methods)AIClient.text_to_sql(...) - second argument is
AIClient.text_to_sql(array), not a single objectDataSourceSchema[] - Responses parsed from /
datafallbackbody - Output extraction includes string guard and empty-output handling
- Error handling and loading state in UI
- 方法使用蛇形命名法(如
AIClient、generate_text等)text_to_sql - 方法以静态方式调用(例如
AIClient,而非实例方法)AIClient.text_to_sql(...) - 的第二个参数为
AIClient.text_to_sql(数组),而非单个对象DataSourceSchema[] - 响应从/
data降级解析body - 输出提取包含字符串校验和空输出处理
- UI中包含错误处理和加载状态