SCSAI Agent Development Guide
1. SCSAI System Architecture Overview
1.1 Core Components
- Sciot Object: The core global object of the SCSAI system, providing all SCSAI functional interfaces
- IOM (Agent Object Model): SCSAI object model for object operations
- Soap Communication: Communication protocol with the SCSAI server
- AML (SCSAI Markup Language): SCSAI object operation language
1.2 System Initialization Process
1. SCSAIFileLoader.js - 按依赖顺序加载所有 SCSAI 核心 JS 文件
2. SCSAICoreWrapper.js - 封装核心依赖加载逻辑
3. RealSCSAIWrapper.js - Create sciot 对象和初始化环境
4. 配置服务器连接
5. 用户登录
6. 初始化主窗口信息
7. 加载元数据和系统配置
1.3 SCSAI基础JS文件加载机制与核心文件分析
#### 1.3.1 核心加载器:SCSAIFileLoader
File Path: src/core/SCSAIFileLoader.js
Functionality:
- Loads all SCSAI foundational JS files in the correct dependency order
- Uses traditional script tag loading to avoid ES module import conflicts
- Supports sequential and parallel loading
- Provides loading status tracking and error handling
#### 1.3.2 Core Foundational JS File List
The following are the key SCSAI foundational JS files listed in loading order:
| Loading Order | File Path | Function Description |
|----------|----------|----------|
| 1-5 | enumerations.js | Defines SCSAI system enumerations |
| 6-10 | core/Xml.js | Core XML processing library |
| 11-15 | core/Soap.js | SOAP communication protocol implementation |
| 16-20 | core/aml.js | AML (SCSAI Markup Language) parsing |
| 21-25 | core/SessionSoap.js | Session management SOAP communication |
| 26-30 | core/utils.js | Core utility functions |
| 31-35 | core/XmlToJson.js | XML to JSON conversion |
| 36-40 | core/sciot_object.js | Creates the global sciot object |
| 41-45 | core/iom.js | IOM (Agent Object Model) Implementation |
| 46-50 | sciot_item_methods.js | Item Operation Methods |
| 51-55 | sciot_itemtype_methods.js | Item Type Operation Methods |
| 56-60 | sciot_ui_methods.js | UI Operation Methods |
| 61-65 | sciot_workflow_methods.js | Workflow Operation Methods |
#### 1.3.3 Detailed Description of Key Files
##### 1.3.3.1 core/sciot_object.js - Global sciot Object Creation
Core Functions:
- Creates the global window.sciot object
- Defines the basic properties and methods of the sciot object
- Initializes sciot components and services
- Provides the foundational framework for communication with the SCSAI server
##### 1.3.3.2 core/Soap.js - SOAP Communication
Core Functions:
- Implements SOAP protocol communication
- Handles requests/responses with the SCSAI server
- Manages sessions and authentication
- Provides an interface for executing AML queries
##### 1.3.3.3 core/aml.js - AML Parsing and Generation
Core Functions:
- AML (SCSAI Markup Language) Parsing
- AML Query Generation
- XML/AML Data Processing
- Provides AML templates for item operations
#### 1.3.4 Loading Mechanism
##### 1.3.4.1 Loading Process
- Upon application startup, SCSAIFileLoader is initialized
- Calls loadAllFiles() to load all files in sequence
- Each file is dynamically added to the DOM via script tags
- Updates the loading status upon file completion
- After all files are loaded, the global sciot object becomes available.
##### 1.3.4.2 Loading Strategy
- Load foundational dependencies first (e.g., Xml.js, Soap.js)
- Then load the core object (sciot_object.js)
- Finally, load functional methods (sciot_*.js)
- Parallel loading is supported for performance optimization (optional)
#### 1.3.5 sciot Object Initialization Process
- sciot_object.js is loaded
- Create the Sciot constructor
- Instantiate the sciot object and mount it to the window
- Load other sciot method files, extending the sciot object
- After initialization is complete, window.sciot is available
#### 1.3.6 How to Use in a Project
Use the global object directly:
// sciot对象在所有文件加载完成后可用
if (window.sciot) {
// 使用sciot对象执行操作
const result = window.sciot.applyAML(amlQuery);
}
通过SCSAIModules访问:
import SCSAIModules from '@/SCSAI/index.js';
// 访问sciot相关功能
const sciot = window.sciot;
#### 1.3.7 调试与验证
Check the sciot object:
// 检查sciot对象是否可用
console.log('sciot对象:', typeof window.sciot);
// 检查sciot方法
console.log('sciot方法:', Object.keys(window.sciot));
检查文件加载状态:
import { SCSAIFileLoader } from '@/core/SCSAIFileLoader';
// 查看已加载文件
console.log('已加载文件:', SCSAIFileLoader.getLoadedFiles());
#### 1.3.8 关键结论
- Core file: core/sciot_object.js is the key file that creates the global sciot object
- Loading order: Files must be loaded in dependency order; otherwise, runtime errors will occur
- Global object: All SCSAI functionality is accessed via the window.sciot global object
- Traditional loading: Use traditional script tag loading to avoid ES module conflicts
- Dependency management: SCSAIFileLoader ensures files are loaded in the correct order
#### 1.3.9 File Loader API
// 使用SCSAIFileLoader加载所有SCSAI核心文件
import { SCSAIFileLoader } from './src/core/SCSAIFileLoader.js';
// 顺序加载所有文件
const result = await SCSAIFileLoader.loadAllFiles();
console.log('加载结果:', result.status);
// 并行加载文件(性能优化)
await SCSAIFileLoader.loadFilesParallel(5);
// 检查文件是否已加载
const isLoaded = SCSAIFileLoader.isFileLoaded('core/sciot_object.js');
// 获取已加载文件列表
const loadedFiles = SCSAIFileLoader.getLoadedFiles();
2. 核心依赖管理
2.1 依赖关系图
基于 modaladmin.html 构建的依赖关系:
┌───────────────────┐
│ StaticVariablesStorage │
└───────────┬───────┘
│
┌───────────▼───────┐
│ ModulesHelper │
└───────────┬───────┘
│
┌───────────▼───────┐ ┌───────────┐ ┌───────────┐
│ Sciot │◀───┤ XmlDocument │◀───┤ Enums │
└───────────┬───────┘ └───────────┘ └───────────┘
│
┌───────────▼───────┐
│ XmlHttpRequestManager │
└───────────────────┘
│
┌───────────▼───────┐ ┌───────────┐ ┌───────────┐
│ IOM.ScriptSharp.debug │◀───┤ sciot_user │◀───┤ aggridnew │
└───────────────────┘ └───────────┘ └───────────┘
2.2 动态加载核心文件
// 使用 SCSAICoreWrapper 加载核心依赖
const SCSAICore = new SCSAICoreWrapper();
// 加载核心模块
await SCSAICore.loadCoreDependencies();
// 加载单个模块
await SCSAICore.loadModule('sciot_user');
3. 全局 Sciot 对象创建
3.1 创建流程
// 1. 等待 Sciot 构造函数可用
if (typeof Sciot === 'undefined') {
throw new Error('Sciot 构造函数未定义');
}
// 2. Create Sciot 对象实例
const sciot = new Sciot();
window.sciot = sciot;
// 3. 初始化浏览器信息
sciot.Browser = new BrowserInfo();
// 4. 初始化核心组件
sciot.IomFactory = new Sciot.IOM.IomFactory();
sciot.IomAgent = sciot.newIOMAgent();
sciot.AgentUser = new Sciot.IOM.AgentUser();
sciot.GUIDManager = new GUIDManager(sciot);
sciot.MetadataCache = new MetadataCache(sciot);
3.2 核心属性和方法
| 属性/方法 | 描述 |
|-----------|------|
| sciot.Browser | Browser information object |
| sciot.IomFactory | IOM object factory |
| sciot.IomAgent | IOM Agent instance |
| sciot.login() | User login method |
| sciot.soapSend() | Send SOAP request |
| sciot.setServer() | Set server URL |
| sciot.newIOMAgent() | Create a new IOM Agent instance |
4. User Login Process
4.1 Standard Login Method
// 1. 设置服务器 URL
sciot.setServer(serverUrl);
// 2. 执行登录
const result = await sciot.login(
username, // Username
password, // Password
database, // 数据库名称
dohash_flag, // 是否使用哈希密码
serverUrl // 服务器 URL
);
// 3. 登录成功后处理
if (result) {
// 登录成功,执行后续操作
sciot.setCommonPropertyValue('loginName', username);
sciot.setCommonPropertyValue('password', password);
sciot.setCommonPropertyValue('database', database);
}
4.2 登录后初始化
// 初始化主窗口信息
window.sciotMainWindowInfo = new SciotMainWindowInfo(sciot);
// 设置身份列表
sciot.buildIdentityList(window.sciotMainWindowInfo.getIdentityListResult);
// 更新元数据缓存
sciot.MetadataCache.UpdatePreloadDates(metadataDates);
5. 基本对象操作
5.1 使用 SOAP 请求
// Send SOAP 请求
const result = await sciot.soapSend(
methodName, // 方法名称,如 'ApplyItem'、'GetItemTypeList'
amlContent // AML 内容
);
// 处理响应
if (result.getFaultCode() === '0') {
// 请求成功,处理结果
const items = result.results.selectNodes('//Item');
} else {
// 请求失败
throw new Error(result.getFaultString());
}
5.2 AML 语言基础
#### 查询对象
<Item type="Part" action="get">
<select>
<name />
<description />
<item_number />
</select>
<where>
<name condition="like">%test%</name>
</where>
</Item>
#### 创建对象
<Item type="Part" action="add">
<name>Test Part</name>
<item_number>TEST-001</item_number>
<description>This is a test part</description>
</Item>
#### 更新对象
<Item type="Part" action="update" id="{GUID}">
<name>Updated Part</name>
<description>Updated description</description>
</Item>
#### 删除对象
<Item type="Part" action="delete" id="{GUID}">
</Item>
5.3 常用 SOAP 方法
| 方法名 | 描述 |
|--------|------|
| ApplyItem | Perform AML operations (Query, Create, Update, Delete) |
| GetItemTypeList | Get all object class list |
| GetVersion | Get SCSAI server version |
| GetItemByKeyedName | Get object by keyed name |
| GetItemById | Get object by ID |
6. Advanced Features
6.1 Object Class Management
// 获取对象类列表
const itemTypes = await SCSAICore.getObjectClasses();
// 获取指定对象类的对象列表
const parts = await SCSAICore.getObjectsByType('Part', {
pageSize: 10,
pageNumber: 1,
select: '<name><item_number><description>'
});
6.2 使用 ag-Grid
// 加载 ag-Grid 模块
await SCSAICore.loadModule('aggridnew');
// 获取网格数据
const gridData = await SCSAICore.getGridData('Part');
6.3 会话管理
// 获取当前用户信息
const userInfo = {
loginName: sciot.getCommonPropertyValue('loginName'),
database: sciot.getCommonPropertyValue('database')
};
// 检查登录状态
const isLoggedIn = sciot.isLoggedIn || false;
// 登出
const logoutResult = await sciot.logout();
7. NODE 开发集成
7.1 核心封装
// 在 NODE 环境中封装 SCSAI 客户端
class SCSAINodeClient {
constructor(config) {
this.config = config;
this.sciot = null;
this.isAuthenticated = false;
}
async initialize() {
// 初始化 SCSAI 核心
const SCSAICore = new SCSAICoreWrapper();
await SCSAICore.initialize(this.config);
// 获取 sciot 对象
this.sciot = SCSAICore.sciot;
return this.sciot;
}
async login(credentials) {
const result = await this.sciot.login(
credentials.username,
credentials.password,
credentials.database,
false,
this.config.serverUrl
);
this.isAuthenticated = true;
return result;
}
async queryObjects(itemType, options = {}) {
// 构建 AML 查询
const aml = this.buildAMLQuery(itemType, options);
// Send SOAP 请求
return await this.sciot.soapSend('ApplyItem', aml);
}
// 其他方法...
}
7.2 飞书集成示例
// 飞书机器人与 SCSAI 集成
const { SCSAINodeClient } = require('./SCSAI-client');
const { LarkClient } = require('./lark-client');
class SCSAIFeishuBot {
constructor(config) {
this.SCSAIClient = new SCSAINodeClient(config.SCSAI);
this.larkClient = new LarkClient(config.lark);
}
async initialize() {
// 初始化 SCSAI 客户端
await this.SCSAIClient.initialize();
// Sign in SCSAI
await this.SCSAIClient.login({
username: config.SCSAI.username,
password: config.SCSAI.password,
database: config.SCSAI.database
});
}
async handleFeishuEvent(event) {
// 处理飞书事件
if (event.type === 'message') {
// 解析消息内容
const message = event.message.content;
// 查询 SCSAI 对象
const result = await this.SCSAIClient.queryObjects('Part', {
where: `<name condition="like">%${message}%</name>`
});
// 返回结果到飞书
await this.larkClient.sendMessage({
chatId: event.chatId,
content: this.formatResult(result)
});
}
}
}
8. 最佳实践
8.1 性能优化
- 合理使用元数据缓存
- 减少 SOAP 请求次数
- 使用分页查询处理大量数据
- Optimize AML 查询语句
8.2 错误处理
try {
const result = await sciot.soapSend(methodName, amlContent);
if (result.getFaultCode() !== '0') {
throw new Error(result.getFaultString());
}
return result;
} catch (error) {
console.error('SCSAI 请求失败:', error);
// 处理重试逻辑
if (error.message.includes('timeout')) {
// 重试逻辑
}
throw error;
}
8.3 安全性
- 加密存储敏感信息
- 合理设置权限
- 验证输入数据
- 防止 SQL/AML 注入
9. 调试工具
9.1 日志记录
// 启用 SCSAI 调试日志
sciot.setCommonPropertyValue('debugMode', true);
// 监听 SOAP 请求
sciot.on('soapSend', (method, aml) => {
console.log('SOAP 请求:', method, aml);
});
// 监听 SOAP 响应
sciot.on('soapResponse', (result) => {
console.log('SOAP 响应:', result);
});
9.2 浏览器调试
- 使用浏览器开发者工具查看网络请求
- 检查 window.sciot 对象状态
- 调试 AML 语法错误
- 监控性能指标
10. 常见问题
10.1 404 错误
- 检查核心文件路径是否正确
- 确认服务器配置正确
- 检查依赖加载顺序
10.2 登录失败
- 验证用户名密码
- 确认数据库名称正确
- 检查服务器连接
10.3 对象操作失败
- 检查 AML 语法
- 验证对象权限
- 确认对象类存在
11. SCSAI BOM 技能实现
11.1 技能概述
SCSAI BOM 技能是一个 OpenClaw 技能,用于获取和管理 SCSAI 系统中的 Bill of Materials (BOM) 数据。
11.2 Feature Highlights
- ✅ Get BOM list
- ✅ Get specified BOM details
- ✅ Display BOM structure
- ✅ Compare multiple BOMs
- ✅ Supports real SCSAI server integration
- ✅ Detailed logging and error handling
11.3 Skill Architecture
┌─────────────────────┐
│ SCSAI BOM 技能入口 │
└───────────┬─────────┘
│
┌───────────▼─────────┐
│ 配置管理 │
│ (SCSAIConfigService) │
└───────────┬─────────┘
│
┌───────────▼─────────┐
│ SCSAI 连接管理 │
│ (RealSCSAIWrapper) │
└───────────┬─────────┘
│
┌───────────▼─────────┐
│ BOM 核心功能 │
│ - 获取 BOM 列表 │
│ - 获取指定 BOM │
│ - BOM 比较 │
└───────────┬─────────┘
│
┌───────────▼─────────┐
│ AML 处理和 XML 解析 │
└─────────────────────┘
11.4 核心 API
#### 11.4.1 技能初始化
// 导入 BOM 技能
const bomSkill = require('./openclaw-skill/SCSAI-bom-skill/index.js');
// 获取技能配置
const config = bomSkill.getConfig();
console.log('BOM 技能配置:', config);
// 初始化技能
await bomSkill.initialize();
#### 11.4.2 获取 BOM 列表
// 获取 BOM 列表
const bomList = await bomSkill.getBOMList();
console.log('BOM 列表:', bomList);
#### 11.4.3 获取指定 BOM
// 获取指定 ID 的 BOM
const bomId = '32DF3F23-7A8B-4C9D-8E7F-1234567890AB';
const bomDetail = await bomSkill.getBOMById(bomId);
console.log('指定 BOM 详情:', bomDetail);
// 获取指定名称的 BOM
const bomName = 'Product-ABC';
const bomByName = await bomSkill.getBOMByName(bomName);
console.log('按名称获取 BOM:', bomByName);
#### 11.4.4 比较多个 BOM
// 比较两个 BOM
const bomId1 = '32DF3F23-7A8B-4C9D-8E7F-1234567890AB';
const bomId2 = '45EF4E34-8B9C-5D0E-9F8G-0987654321BA';
const comparisonResult = await bomSkill.compareBOMs([bomId1, bomId2]);
console.log('BOM 比较结果:', comparisonResult);
11.5 配置管理
#### 11.5.1 配置文件
The skill uses SCSAIConfigService to fetch configuration, supporting the following items:
| Configuration Item | Default Value | Description |
|--------|--------|------|
| serverUrl | https://ylxt.chat/scplm/server | SCSAI server URL |
| database | SCPLM | Database name |
| timeout | 30000 | Request timeout (milliseconds) |
| debug | true | Enable debug logging |
#### 11.5.2 Environment Detection
The skill automatically detects the runtime environment, supporting both browser and Node.js:
// 环境检测示例
const isBrowser = typeof window !== 'undefined';
if (isBrowser) {
// 浏览器环境处理
console.log('Running in browser environment');
} else {
// Node.js 环境处理
console.log('Running in Node.js environment');
}
11.6 错误处理
技能实现了详细的错误处理机制:
try {
const result = await bomSkill.getBOMList();
return result;
} catch (error) {
console.error('SCSAI BOM 技能错误:', error);
// 详细的错误信息,包含错误代码和描述
const errorInfo = {
code: error.code || 'UNKNOWN_ERROR',
message: error.message,
details: error.details || {}
};
return { success: false, error: errorInfo };
}
11.7 日志系统
技能内置了详细的日志记录:
// 日志示例
console.log('[SCSAI BOM SKILL] 初始化技能...');
console.debug('[SCSAI BOM SKILL] 配置信息:', this.config);
console.info('[SCSAI BOM SKILL] 开始获取 BOM 列表...');
console.warn('[SCSAI BOM SKILL] 服务器响应较慢,当前耗时:', responseTime, 'ms');
console.error('[SCSAI BOM SKILL] 获取 BOM 失败:', error);
12. 资源链接
文档版本: 1.1
Update Date: 2026-03-28
Applicable SCSAI Version: 12.0+
Author: SCSAI Development Team
Maintenance Location: Project root /SCSAI-DEVELOPER-GUIDE.md
Purpose: Serves as a reference for OpenClaw skill development, available for consultation anytime
BossAgents