@sepveneto/dnde-agent 0.2.0-beta.3 → 0.2.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -3
- package/dist/{agent-B2u2g_gS.js → agent--M87gUL-.js} +1 -1
- package/dist/agents.d.ts.map +1 -1
- package/dist/editorContext.d.ts +26 -0
- package/dist/editorContext.d.ts.map +1 -0
- package/dist/element.js +621 -569
- package/dist/{index-Cz-N1hlP.js → index-BozWbCey.js} +559 -507
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -14
- package/dist/runtime.d.ts.map +1 -1
- package/dist/tool.d.ts +3 -1
- package/dist/tool.d.ts.map +1 -1
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,9 +41,9 @@ interface AgentHostApi {
|
|
|
41
41
|
apiMode?: 'responses' | 'chat_completions'
|
|
42
42
|
}
|
|
43
43
|
editor?: {
|
|
44
|
-
getCurrentEditor()
|
|
45
|
-
getWidgets()
|
|
46
|
-
operateEditor(operation: AgentEditorOperation)
|
|
44
|
+
getCurrentEditor: () => unknown | Promise<unknown>
|
|
45
|
+
getWidgets: () => unknown | Promise<unknown>
|
|
46
|
+
operateEditor: (operation: AgentEditorOperation) => unknown | Promise<unknown>
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
```
|
|
@@ -51,6 +51,33 @@ interface AgentHostApi {
|
|
|
51
51
|
默认带三个基于编辑器 API 的工具:`get_current_editor`、`get_widgets`、
|
|
52
52
|
`editor_operator`。写操作和历史不可逆操作应先取得用户确认。
|
|
53
53
|
|
|
54
|
+
### 添加组件时的业务数据
|
|
55
|
+
|
|
56
|
+
`items` 通常是由业务 ID 查询并组装的复杂数据,不能交给模型生成。业务工具
|
|
57
|
+
应把组装结果写入当前 Agent Run 的 Context,`editor_operator` 会在 `add`
|
|
58
|
+
时自动注入,并在操作成功后一次性消费:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const queryProduct = defineAgentTool({
|
|
62
|
+
name: 'query_product',
|
|
63
|
+
description: '查询商品并准备添加到编辑器。',
|
|
64
|
+
parameters: z.object({ keyword: z.string() }),
|
|
65
|
+
async execute({ keyword }, toolContext) {
|
|
66
|
+
const product = await api.product.search(keyword)
|
|
67
|
+
const items = await api.product.buildEditorItems([product.id])
|
|
68
|
+
|
|
69
|
+
// 只返回模型需要做决策的轻量信息。
|
|
70
|
+
toolContext.context.pendingItems = items
|
|
71
|
+
return { id: product.id, name: product.name }
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
模型随后只调用
|
|
77
|
+
`editor_operator({ action: 'add', widget: 'product', target: '页面节点 UUID' })`。
|
|
78
|
+
工具参数不包含 `items`;即使模型额外传入也会被移除。每次 Agent Run 都会
|
|
79
|
+
创建独立的 Context,失败时保留待添加数据以支持同一轮重试,成功后清空。
|
|
80
|
+
|
|
54
81
|
## 业务工具
|
|
55
82
|
|
|
56
83
|
```ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var V = Object.defineProperty;
|
|
2
2
|
var Q = (t, s, e) => s in t ? V(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
|
|
3
3
|
var a = (t, s, e) => Q(t, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
-
import { C as E, U as x, r as X, t as I, o as v, s as y, a as Z, w as A, i as q, e as ee, A as te, n as k, b as R, p as C, c as se, S as ie, d as ne, M as re, f as ae } from "./index-
|
|
4
|
+
import { C as E, U as x, r as X, t as I, o as v, s as y, a as Z, w as A, i as q, e as ee, A as te, n as k, b as R, p as C, c as se, S as ie, d as ne, M as re, f as ae } from "./index-BozWbCey.js";
|
|
5
5
|
function oe(t) {
|
|
6
6
|
return t ? !(typeof t == "object" && t && "constructor" in t && typeof t.constructor == "function" ? t.constructor.name : "").includes("ChatCompletions") : !0;
|
|
7
7
|
}
|
package/dist/agents.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AACjD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AACjD,OAAO,KAAK,EAAwB,YAAY,EAAsB,MAAM,SAAS,CAAA;AACrF,OAAO,EAAE,KAAK,EAAQ,MAAM,gBAAgB,CAAA;AAO5C,eAAO,MAAM,mBAAmB,kBAAkB,CAAA;AAClD,eAAO,MAAM,qBAAqB,6BAA6B,CAAA;AAE/D,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,YAAY,CAAA;IACjB,KAAK,CAAC,EAAE,mBAAmB,EAAE,CAAA;IAC7B,UAAU,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC3C;AAsLD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB;;EA8BxD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AgentEditorOperation, EditorAgentContext } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Create isolated editor/business state for one Agent Run.
|
|
4
|
+
*
|
|
5
|
+
* Host context is copied in as read-only starting data. `pendingItems` is
|
|
6
|
+
* always reset so data prepared by a previous turn cannot leak into this one.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createEditorAgentContext(initial?: Record<string, unknown>): EditorAgentContext;
|
|
9
|
+
export interface PreparedEditorOperation {
|
|
10
|
+
operation: AgentEditorOperation;
|
|
11
|
+
/** Items reserved for this add operation; cleared only after success. */
|
|
12
|
+
pendingItems?: unknown[];
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Remove any model-produced items and, for add operations, inject the data
|
|
17
|
+
* prepared by a business tool for this run.
|
|
18
|
+
*/
|
|
19
|
+
export declare function prepareEditorOperation(input: unknown, context: EditorAgentContext): PreparedEditorOperation;
|
|
20
|
+
export declare function editorOperationSucceeded(result: unknown): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Consume pending items only after the editor confirms success. A failed
|
|
23
|
+
* operation keeps them available for a corrected retry in the same Run.
|
|
24
|
+
*/
|
|
25
|
+
export declare function completeEditorOperation(context: EditorAgentContext, prepared: PreparedEditorOperation, result: unknown): void;
|
|
26
|
+
//# sourceMappingURL=editorContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editorContext.d.ts","sourceRoot":"","sources":["../src/editorContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,SAAS,CAAA;AAEhB;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACpC,kBAAkB,CAKpB;AAED,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,oBAAoB,CAAA;IAC/B,yEAAyE;IACzE,YAAY,CAAC,EAAE,OAAO,EAAE,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,kBAAkB,GAC1B,uBAAuB,CA6BzB;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CASjE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,uBAAuB,EACjC,MAAM,EAAE,OAAO,GACd,IAAI,CAGN"}
|