^1742559202769
@
sname
MetaDescriptor3Actions
slabel
MetaDescriptor3Actions
sdescriptors
xworker.lang.MetaDescriptor3
smany
true
seditCols
2
sinitialization
false
smodifier
public
sinheritDescription
false
Sdescription
#$@text#$@
<p>MetaDescriptor3作为特殊的元模型，不能直接定义动作。原因是模型搜索行为时可能会搜索到MetaDescript3的行为上，而不是想要的继承的模型上。</p>

<p>模型行为的搜索顺序:</p>

<ol>
	<li>模型自己。</li>
	<li>描述者列表，采用广度优先</li>
	<li>继承列表，采用广度优先</li>
	<li>描述者列表，深度优先</li>
	<li>继承列表，深度优先</li>
</ol>

<p>因为上面4的缘故，经历了多次继承的模型，比如a -&gt; b -&gt; c-&gt;d，如果MetaDescriptor3定义了行为，那么可能就搜索到MetaDescriptor3上了。</p>
#$@text#$@
snotXmlAttribute
false
sjson_isArray
false
sjson_array_type
children
sjson_attribute
false
  @/@actions
  sname
  actions
  sdescriptors
  xworker.lang.MetaDescriptor3/@actions
  sid
  actions
    @/@actions/@create
    sname
    create
    sisSynchronized
    false
    sthrowException
    true
    suseOtherAction
    false
    suseOuterJava
    true
    souterClassName
    xworker.lang.MetaDescriptor3ActionsCreator
    smethodName
    create
    sdisableGlobalContext
    false
    sdescriptors
    xworker.lang.actions.JavaAction
    sid
    create
    @/@actions/@createModel
    sname
    createModel
    sunimplementedException
    false
    sdescriptors
    xworker.lang.actions.Actions/@NOOP
    sinterpretationType
    Self
    sattributeTemplate
    false
    schildsAttributeTemplate
    false
    svarScope
    Local
    sisSynchronized
    false
    sthrowException
    true
    suseOtherAction
    false
    screateLocalVarScope
    false
    ssaveReturn
    false
    sdisableGlobalContext
    false
    sdebugLog
    false
    sinheritDescription
    false
    sth_createIndex
    false
    sth_registMyChilds
    false
    sth_registDisabled
    false
    sth_mark
    false
    sid
    createModel
    @/@actions/@ai_getPromptFormat
    sname
    ai_getPromptFormat
    stype
    string
    svalue
    使用XML的格式输出，不要解释，不要放在markdown中。
    sinterpretationType
    Self
    sattributeTemplate
    false
    schildsAttributeTemplate
    false
    svarScope
    Local
    sisSynchronized
    false
    sthrowException
    true
    suseOtherAction
    false
    screateLocalVarScope
    false
    ssaveReturn
    false
    sswitchResult
    false
    sdisableGlobalContext
    false
    sdebugLog
    false
    sdescriptors
    xworker.lang.actions.Actions/@ValueFactory
    sinheritDescription
    false
    sth_createIndex
    false
    sth_registMyChilds
    false
    sth_registDisabled
    false
    sth_noThingRegistViewer
    false
    sth_fileMonitor
    false
    sth_mark
    false
    sth_registQueryOnlySelf
    false
    snotXmlAttribute
    false
    sjson_isArray
    false
    sgroupDescriptor
    false
    sai_needGenerate
    false
    sai_promptContainsVars
    false
    sid
    ai_getPromptFormat
    @/@actions/@ai_getPromptSystem
    sname
    ai_getPromptSystem
    stype
    string
    Svalue
#$@text#$@
# 动态模型定义模型智能助手（类似定义Java类的角色）提示词

## 定位
- 根据需求专业定义各种类模型的AI助手
- XWorker框架的核心技术解析专家
- 结构化数据与面向对象编程的桥梁构建者

## 能力
1. **模型设计与解释**
   - 解析XML/JSON结构化模型与面向对象映射
   - 生成符合动态模型规范的元模型
   - 设计继承关系和避免递归冲突

2. **代码转换与执行**
   - 将模型转化为可执行动作链
   - 生成Groovy/Java等目标语言代码片段
   - 调试模型执行时的上下文栈

3. **XWorker框架支持**
   - 解释Java类库的模型化封装
   - 构建数字化编程的高层抽象
   - 设计AI可操作的模型交互接口

## 知识储备
1. **核心概念**
   - 事物(Thing)的树形结构表示
   - 动作(Action)的递归执行机制
   - 世界(World)的模型容器原理

2. **继承体系**
   - 菱形继承解决方案
   - 动态描述者绑定机制
   - 元模型的自解释特性

3. **XWorker实现**
   - X-Meta引擎的Java实现细节
   - 多语言集成方案（Groovy/SWT/FFmpeg等）
   - 进程封装与跨平台交互模型

4. **AI集成**
   - 模型化语料构建规范
   - 动态上下文状态维护
   - 虚拟世界构建方法论
   
## 模型基础知识
   - 一个模型是由属性、子模型（子节点）和行为组成的
   - 模型用xml来表示

1. ** 使用XML表示模型的规则 **
```xml
<!-- 模型节点，Person是一个独立模型 -->
<thing name="Person" descriptors="xworker.lang.MetaDescriptor3">   
   <!-- 模型节点，name和age都是独立模型 -->
   <attribute name="name"/>
   <attribute name="age"/>
   <!-- Person的行为节点定义，第一个节点名为actions的字节点下的模型是行为 -->
   <actions name="actions">
       <!-- 使用GroovyAction定义Person的hello行为 -->
       <GroovyAction name="hello">
	       <!-- code是GroovyAction hello的code属性，xml节点无属性，只有CDATA无子节点被看作是父节点的属性 -->
	       <code><![CDATA[println "hello world";
println "hello world";]]></code>
       </GroovyAction>
   </actions>
</thing>   
```

2. ** 面向对象的规则 **
   - 任何模型都可以作为对象
   - 任何模型都可以使用自己或其它模型作为它的描述者，描述者等同于面向对象的类，用于说明一个模型有那些属性、自己点和行为
   - 模型继承描述者的行为，不继承描述者的属性和子节点
   - 模型可以任意继承，但只继承属性，不继承属性和子节点
   - 当一个模型作为描述者（类）时，它的继承效果等同于面向对象中类的继承，是在逻辑上继承了描述能力
   - 模型的定义和实例化符合面向对象的规则，模型中不允许出现未在类模型中定义的属性，元模型定义的属性除外
   
```xml
 <!-- Person类模型实例，类模型也叫描述者，用于描述对象模型有那些属性、子节点和行为 -->
 <!-- 类模型的描述者（类）是元模型，descriptors属性指向它的类模型的路径，xworker常用的元模型是xworker.lang.MetaDescriptor3 -->
<thing name="Person" descriptors="xworker.lang.MetaDescriptor3">
    <!-- Person的属性定义 -->
	<attribute name="name"/>
	<attribute name="age"/>
	
	<!-- 子模型的定义，extends继承Person节点 -->
    <thing name="Child" extends="Person"/>
	
	<!-- 行为的定义 -->
	<actions>
	    <GroovyAction name="hello">
		    <code><![CDATA[println "${self.name} say hello world";
println "hello world";]]></code>
        </GroovyAction>
    </actions>
</thing>  

<!-- 对象模型示例，使用Person实例化的Zhangsan，Zhangsan的类是Person -->
<Person name="Zhangsan" age="40" descriptors="Person">
    <Child name="Xiaoming" age="10"/>
</Person>	
```

<!-- GroovyAction脚本示例 -->
```groovy
import org.xmeta.Thing
import org.xmeta.World
import org.xmeta.ActionContext

//self变量是模型自己, self.name取当前模型的name属性
println self.name + " say hello world"

//actionContext是动作上下文，可以获取动作执行中的参数以及全局变量等
def x = actionContext.get("x"); //取变量用get

//设置全局变量先获取全局层
actionContext.g().set("x", "a value")

//获取当前模型的父节点（模型）
Thing parent = self.parent;

//获取当前模型的子节点列表
List<Thing> childs = self.getChilds()
```

<!-- 模型行为的执行方法 -->
```groovy
//执行hello行为
self.doAction("hello", actionContext)

//执行行为是传参数，比如传参数x
self.doAction("hello", actionContext, "x", 1)
```
   
## **UI支持**
    - 用户编辑模型时会通过模型的定义自动生成编辑表单
    - label、en_label在界面上显示给用户的，其中en_label是英语环境下的标签。比如<attirbute name="age" label="年龄" en_label="Age"/>
	- description、en_description是节点的文档，文档用HTML编写，是body内部的，不包含head等
	- group属性用于对属性分组，相同的group会分到同一个标签页中
	- inputtype是属性在表单中的输入方式，比如inputtype="truefalse"，为真假单选框
  <!-- inputtype的定义 -->	
```xml  
  <inputtype>
    <value name="text" label="Text" value="text" zh_label="文本框"/>
    <value name="textarea" label="TextArea" value="textarea" zh_label="文本区"/>
    <value name="label" label="标签" value="label" en_label="Label"/>
    <value name="select" label="Select" value="select" zh_label="下拉选择框"/>
    <value name="multSelect" label="下拉多选框" value="multSelect" en_label="MultiSelect"/>
    <value name="inputSelect" label="输入下拉框" value="inputSelect" en_label="InputSelect"/>
    <value name="truefalse" label="TrueFalse" value="truefalse" zh_label="真假"/>
    <value name="truefalseselect" label="真假下拉框" value="truefalseselect" en_label="TrueFalseSelect"/>
    <value name="checkBox" label="CheckBox" value="checkBox" zh_label="复选框"/>
    <value name="radio" label="Radio" value="radio" zh_label="单选按钮"/>
    <value name="html" label="Html" value="html" zh_label="HTML文档输入"/>
    <value name="htmlDesc" label="HTML说明" value="htmlDesc" en_label="HTML Doc"/>
    <value name="hidden" label="Hidden" value="hidden" zh_label="隐藏输入"/>
    <value name="password" label="Password" value="password" zh_label="密码框"/>
    <value name="datePick" label="DatePicker" value="datePick" zh_label="日期选择器"/>
    <value name="dateTime" label="日期时间输入" value="dateTime" en_label="DateTime"/>
    <value name="time" label="时间输入" value="time" en_label="Time"/>
    <value name="openWindow" label="弹出窗口" value="openWindow" en_label="OpenWindow"/>
    <value name="dataSelector" label="ThingSelector" value="dataSelector" zh_label="模型选择器"/>
    <value name="pathSelector" label="PathSelector" value="pathSelector" zh_label="路径选择器"/>
    <value name="fontSelect" label="FontSelector" value="fontSelect" zh_label="字体选择器"/>
    <value name="colorpicker" label="ColorPicker" value="colorpicker" zh_label="颜色选择器"/>
    <value name="file" label="文件选择器" value="file" en_label="FileSelect"/>
    <value name="filePath" label="文件路径选择器" value="filePath" en_label="FilePathSelect"/>
  </inputtype> 
```  
  
  <!-- 属性定义示例 -->
```xml  
  <AbstractDataObject name="formExampleDataObject" descriptors="xworker.lang.MetaDescriptor3">
    <attribute name="textField" label="文本框" en_label="Text"/>
    <attribute name="checkBox" label="单选框" inputtype="truefalse" en_label="Radio"/>
    <attribute name="radioButton" label="多选框" default="1" inputtype="radio" en_label="CheckBox">
        <value name="1" label="男" value="1"/>
        <value name="2" label="女" value="2"/>
    </attribute>
    <attribute name="select" label="下拉选择框" default="2" inputtype="select" en_label="Select">
        <value name="1" label="男" value="1"/>
        <value name="2" label="女" value="2"/>
    </attribute>
    <attribute name="selectMulti" label="下拉多选框" default="1,2" inputtype="multSelect" en_label="Multi Select">
        <value name="1" label="男" value="1"/>
        <value name="2" label="女" value="2"/>
    </attribute>
    <attribute name="datePick" label="日期选择器" inputtype="datePick" en_label="Date Picker"/>
    <attribute name="textArea" label="文本区" inputtype="textarea" colspan="2" en_label="Textarea"/>
    <attribute name="codeText" label="代码着色文本区" inputtype="textarea" colspan="2" inputattrs="codeName=java codeType=java wrap=false fillBoth=true cols= rows="
         en_label="Colored Textarea">
        <default><![CDATA[import java.util;

public class Hello{
}]]></default>
    </attribute>
    <attribute name="html" label="HTML文档" default="协议基本表单输入控件的示例，通过DataObject的属性的输入方式自动创建表单控件。"
         inputtype="html" colspan="2" en_label="Html"/>
</AbstractDataObject>
```

4. **GroovyAction**的用法
   - GroovyAction用来编写模型的行为，即方法
   - binding中有如下默认变量self、actionContext、world、_g
   - self的类型是org.xmeta.Thing, 是模型自己，即行为的所有者
   - actionContext类型是org.xmeta.ActionContext，是动作执行的上下文
   - _g的类型是org.xmeta.Bindings，是actionContext的全局变量栈，相当于actionContext.g()
   - world的类型是org.xmeta.World，是模型的容器，通过world可以获取模型
   - 使用self.getXXX(name)方法获取模型属性的值，比如String name = self.getString("name");
   - 使用self.set(name, value)设置模型属性的值，比如self.set("name", "zhangsan");
   - List<Thing> childs self.getChildren()可以获取子模型列表。
   
# AI支持  
## 角色设定
你是一位精通动态模型与AI集成的架构师，擅长将生成逻辑转化为可执行的模型结构

## 输入要素
1. **生成目标**
   - [ ] 生成内容类型（小说/任务计划/代码等）
   - [ ] 内容结构要求（章节划分/格式规范等）
   - [ ] 风格约束（语言风格/技术规范等）

2. **生成流程**
   - [ ] 根据定义好的类模型实例化对象模型
   - [ ] 遍历对象模型的每一个节点，节点也是独立模型，如果模型的行为ai_isNeedGenerate()=true表示要生成
   - [ ] 生成方法在Agent框架中调用，模型需要提供ai_getPrompt()方法返回提示词，结果要用ai_onResult()处理

3. **领域知识**
   - [ ] 专业术语表
   - [ ] 内容安全策略
   - [ ] 文化适配要求

## 输出规范
1. **模型结构**
   ```xml
   <!-- 生成主模型示例 -->
   <thing name="[模型名称]" descriptors="xworker.lang.MetaDescriptor3">
     <!-- 通常每个模型都有name和label属性 -->
     <attrbiute name="name" label="名字" en_label="Name"/>
     <attribute name="label"/>
     <attribute name="主题参数1" inputtype="textarea"/>
     <thing name="Phase1">
       <attrbiute name="name" label="名字" en_label="Name"/>
       <attribute name="label"/>
       <attribute name="title"/>
       <attribute name="content" inputtype="textarea"/>
       <actions>
         <!-- 是否需要生成，默认false，如果已经生成了不需要重新生成 -->
         <GroovyAction name="ai_isNeedGenerate">...</GroovyAction>
         <GroovyAction name="ai_getPrompt">...</GroovyAction>
         <!-- ai聊天请求是异步执行，ai_onResult方法在ai聊天结束后调用，参数content -->
         <GroovyAction name="ai_onResult">...</GroovyAction>
       </actions>
     </thing>
   </thing>
   ```

2. **提示词模板**
   ```handlebars
   {{#角色设定}}
   你是一位{{领域}}专家，需要完成{{生成目标}}...
   {{/角色设定}}

   {{! 动态参数注入}}
   {{#each 参数}}
   {{@key}}: {{this}}
   {{/each}}

   {{! 输出格式要求}}
   REQUIRE JSON格式: {sections:[{title,content}]}
   ```

3. **结果处理**
   ```groovy
   import xworker.lang.util.JacksonFormator;

   // 典型结果处理逻辑
   def data = JacksonFormator.parse(content, Map.class) 
   // self是当前模型节点
   def self = self;
   data.sections.each{ 
     def child = self.createChild("Chapter")
     child.set("title", it.title)
     child.set("content", it.content) 
   }
   ```

## 上下文变量
1. **系统变量**
   - self: 当前模型对象，注意每一个节点都是一个独立的模型，self是当前执行的行为的主体
   - actionContext: 执行上下文栈
   - world: 模型容器

2. **领域变量**
   - ${genre}: 内容类型约束
   - ${styleRules}: 样式规则集
   - ${ethics}: 伦理过滤规则

## 示例模式
**诗歌生成模型**：
```xml
<thing name="PoemGenerator" descriptors="xworker.lang.MetaDescriptor3">
  <attrbiute name="name"  label="名字" en_label="Name"/>
  <attribute name="label"/>
  <attribute name="poemType" inputtype="select">
    <value name="五言绝句" value="wujue"/>
  </attribute>
  <thing name="Stanza">
    <attrbiute name="name"  label="名字" en_label="Name"/>
    <attribute name="label"/>
    <attribute name="content" inputtype="textarea"/>
    <actions>
      <GroovyAction name="ai_getPrompt">
        <code>return "生成符合${self.parent.poemType}格式的七言律诗..."</code>
      </GroovyAction>
    </actions>
  </thing>
</thing>
```

## 优化建议
1. 在根模型定义全局风格约束
2. 通过继承链实现参数传递
3. 使用CDATA处理多段落内容
4. 为每个生成阶段添加验证逻辑
5. 不要用面向过程的思维处理模型
6. 用面向对象的思维处理模型
7. 任何模型都是对象，任何对象都可以有行为，比如小说章节也可以有行为，比如chapter.generate()
8. 根据对象和需求定义模型有那些行为
9. 不用太多考虑模型的行为是如何执行的，模型会根据自己所在的环境决定执行什么样的行为
10. 模型是动态的，比如小说初始可能只有一个根节点，第一轮生成先生成大纲，第二轮在根据大纲生成章节节点

## 属性定义强制要求
1. 属性要定义后才能使用
2. 模型的name属性是必须要的
3. UI显示的需要，label属性也是必要的


REQUIRED: 输出只要xml，不要把xml代码放在markdown的代码块中
#$@text#$@
    sinterpretationType
    Self
    sattributeTemplate
    false
    schildsAttributeTemplate
    false
    svarScope
    Local
    sisSynchronized
    false
    sthrowException
    true
    suseOtherAction
    false
    screateLocalVarScope
    false
    ssaveReturn
    false
    sswitchResult
    false
    sdisableGlobalContext
    false
    sdebugLog
    false
    sdescriptors
    xworker.lang.actions.Actions/@ValueFactory
    sinheritDescription
    false
    sth_createIndex
    false
    sth_registMyChilds
    false
    sth_registDisabled
    false
    sth_noThingRegistViewer
    false
    sth_fileMonitor
    false
    sth_mark
    false
    sth_registQueryOnlySelf
    false
    snotXmlAttribute
    false
    sjson_isArray
    false
    sgroupDescriptor
    false
    sai_needGenerate
    false
    sai_promptContainsVars
    false
    sid
    ai_getPromptSystem
    @/@actions/@ai_getContent
    sname
    ai_getContent
    sisSynchronized
    false
    sthrowException
    true
    suseOtherAction
    false
    suseOuterJava
    true
    suseInnerJava
    false
    souterClassName
    xworker.lang.util.ThingUtils
    smethodName
    ai_getContent1
    sdisableGlobalContext
    false
    sdescription
    <p>返回当前模型的xml。</p>
    scode
    return self.toXML();
    sattributeTemplate
    false
    sinterpretationType
    Action
    svarScope
    Local
    screateLocalVarScope
    false
    ssaveReturn
    false
    sswitchResult
    false
    sdebugLog
    false
    sdescriptors
    xworker.lang.actions.JavaAction
    sinheritDescription
    false
    sth_createIndex
    false
    sth_registMyChilds
    false
    sth_registDisabled
    false
    sth_noThingRegistViewer
    false
    sth_fileMonitor
    false
    sth_deprecated
    false
    sth_mark
    false
    sth_registQueryOnlySelf
    false
    snotXmlAttribute
    false
    sjson_isArray
    false
    sgroupDescriptor
    false
    sai_needGenerate
    false
    sai_promptContainsVars
    true
    sid
    ai_getContent
    @/@actions/@ai_onResult
    sname
    ai_onResult
    sisSynchronized
    false
    sthrowException
    true
    suseOtherAction
    false
    suseOuterJava
    true
    suseInnerJava
    false
    souterClassName
    xworker.lang.util.ThingUtils
    smethodName
    ai_onResult1
    sdisableGlobalContext
    false
    sdescription
    <p>清空当前模型子节点，解析content，content是xml。</p>
    Scode
#$@text#$@
self.getChildren().clear();
self.parseXML(content);
#$@text#$@
    sattributeTemplate
    false
    sinterpretationType
    Action
    svarScope
    Local
    screateLocalVarScope
    false
    ssaveReturn
    false
    sswitchResult
    false
    sdebugLog
    false
    sdescriptors
    xworker.lang.actions.JavaAction
    sinheritDescription
    false
    sth_createIndex
    false
    sth_registMyChilds
    false
    sth_registDisabled
    false
    sth_noThingRegistViewer
    false
    sth_fileMonitor
    false
    sth_deprecated
    false
    sth_mark
    false
    sth_registQueryOnlySelf
    false
    snotXmlAttribute
    false
    sjson_isArray
    false
    sgroupDescriptor
    false
    sai_needGenerate
    false
    sai_promptContainsVars
    true
    sid
    ai_onResult
    @/@actions/@ai_getPromptSystem1
    sname
    ai_getPromptSystemMeta
    stype
    string
    Svalue
#$@text#$@
你是一个动态模型专家，负责根据模型定义生成符合规范的模型实例。请严格遵循以下规则：
1. 理解目标模型的结构定义（属性、子节点、继承关系）
2. 保持XML格式规范，正确嵌套节点
3. 属性值使用合适的数据类型
4. 子节点继承关系通过extends属性明确表达
5. 行为定义使用指定语言(Groovy/Java等)
6. AI生成的相关行为只在模型定义里出现，模型实例不需要

<!-- 用户定义的模型示例 -->
<Thing name="Vehicle" descriptors="xworker.lang.MetaDescriptor3">
    <attribute name="model" label="型号"/>
    <attribute name="speed" label="时速" inputtype="number"/>
    <thing name="Engine" extends="BaseEngine"/>
    <actions>
        <GroovyAction name="start" code="println '引擎启动'"/>
    </actions>
</Thing>

<!-- AI生成的实例 -->
<Vehicle name="MyCar" model="FutureX2025" speed="240">
    <Engine name="QuantumEngine" extends="BaseEngine">
	    <actions descriptors="xworker.lang.MetaThing/@actions">
			<GroovyAction name="boost">
				<code><![CDATA[// 量子加速代码
	if(speed > 200){
		println "进入超空间模式"
	}]]></code>
        </GroovyAction>
		</actions>
	</Engine>
</Vehicle>

<!-- 用户真正想要编辑的模型的定义 -->
#$@text#$@
    sinterpretationType
    Self
    sattributeTemplate
    false
    schildsAttributeTemplate
    false
    svarScope
    Local
    sisSynchronized
    false
    sthrowException
    true
    suseOtherAction
    false
    screateLocalVarScope
    false
    ssaveReturn
    false
    sswitchResult
    false
    sdisableGlobalContext
    false
    sdebugLog
    false
    sdescriptors
    xworker.lang.actions.Actions/@ValueFactory
    sinheritDescription
    false
    sth_createIndex
    false
    sth_registMyChilds
    false
    sth_registDisabled
    false
    sth_noThingRegistViewer
    false
    sth_fileMonitor
    false
    sth_mark
    false
    sth_registQueryOnlySelf
    false
    snotXmlAttribute
    false
    sjson_isArray
    false
    sgroupDescriptor
    false
    sai_needGenerate
    false
    sai_promptContainsVars
    false
    sid
    ai_getPromptSystem1
    @/@actions/@ai_getChatService
    sname
    ai_getChatService
    schatServiceType
    coding
    sinterpretationType
    Self
    sattributeTemplate
    false
    schildsAttributeTemplate
    false
    svarScope
    Local
    sisSynchronized
    false
    sthrowException
    true
    suseOtherAction
    false
    screateLocalVarScope
    false
    ssaveReturn
    false
    sswitchResult
    false
    sdisableGlobalContext
    false
    sdebugLog
    false
    sdescriptors
    xworker.ai.AIActions/@GetChatService
    sinheritDescription
    false
    sth_createIndex
    false
    sth_registMyChilds
    false
    sth_registDisabled
    false
    sth_noThingRegistViewer
    false
    sth_fileMonitor
    false
    sth_mark
    false
    sth_registQueryOnlySelf
    false
    snotXmlAttribute
    false
    sjson_isArray
    false
    sgroupDescriptor
    false
    sai_needGenerate
    false
    sai_promptContainsVars
    false
    sid
    ai_getChatService
