@inupedia/spotlight-client 0.1.0
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 +77 -0
- package/dist/agentCapability.d.ts +43 -0
- package/dist/agentCapability.d.ts.map +1 -0
- package/dist/agentCapability.js +84 -0
- package/dist/agentDecoratorTypes.d.ts +26 -0
- package/dist/agentDecoratorTypes.d.ts.map +1 -0
- package/dist/agentDecoratorTypes.js +1 -0
- package/dist/agentExecutor.d.ts +35 -0
- package/dist/agentExecutor.d.ts.map +1 -0
- package/dist/agentExecutor.js +224 -0
- package/dist/agentRegistry.d.ts +110 -0
- package/dist/agentRegistry.d.ts.map +1 -0
- package/dist/agentRegistry.js +171 -0
- package/dist/contextualAction.d.ts +8 -0
- package/dist/contextualAction.d.ts.map +1 -0
- package/dist/contextualAction.js +9 -0
- package/dist/defineAgentService.d.ts +13 -0
- package/dist/defineAgentService.d.ts.map +1 -0
- package/dist/defineAgentService.js +14 -0
- package/dist/defineAgentTool.d.ts +37 -0
- package/dist/defineAgentTool.d.ts.map +1 -0
- package/dist/defineAgentTool.js +48 -0
- package/dist/defineToolsFromRegistry.d.ts +20 -0
- package/dist/defineToolsFromRegistry.d.ts.map +1 -0
- package/dist/defineToolsFromRegistry.js +19 -0
- package/dist/host.d.ts +40 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +160 -0
- package/dist/http.d.ts +20 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +58 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/registryBridge.d.ts +27 -0
- package/dist/registryBridge.d.ts.map +1 -0
- package/dist/registryBridge.js +18 -0
- package/dist/skillPrompt.d.ts +20 -0
- package/dist/skillPrompt.d.ts.map +1 -0
- package/dist/skillPrompt.js +59 -0
- package/dist/skillScriptRunner.d.ts +19 -0
- package/dist/skillScriptRunner.d.ts.map +1 -0
- package/dist/skillScriptRunner.js +39 -0
- package/dist/skillScriptTool.d.ts +18 -0
- package/dist/skillScriptTool.d.ts.map +1 -0
- package/dist/skillScriptTool.js +53 -0
- package/dist/skillServiceStandard.d.ts +20 -0
- package/dist/skillServiceStandard.d.ts.map +1 -0
- package/dist/skillServiceStandard.js +82 -0
- package/dist/vite/index.d.ts +4 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +1 -0
- package/dist/vite/spotlightAgentIoc.d.ts +11 -0
- package/dist/vite/spotlightAgentIoc.d.ts.map +1 -0
- package/dist/vite/spotlightAgentIoc.js +331 -0
- package/package.json +58 -0
- package/src/agentDecorator.d.ts +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @inupedia/spotlight-client
|
|
2
|
+
|
|
3
|
+
Spotlight **宿主侧执行层** + **Inupedia skills/service 标准**。
|
|
4
|
+
|
|
5
|
+
## Service 注入(单一 `@agent`)
|
|
6
|
+
|
|
7
|
+
在函数上方加一行 `@agent`;**scene / tab / host 由文件路径 + name 自动推断**。
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// capabilities/panels/construction.ts
|
|
11
|
+
@agent({
|
|
12
|
+
name: "panel.openCadViewer",
|
|
13
|
+
description: "打开 CAD 图纸",
|
|
14
|
+
rollback: () => store.setCadViewerVisible(false),
|
|
15
|
+
})
|
|
16
|
+
export async function openCadViewer() {
|
|
17
|
+
store.setCadViewerVisible(true);
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
编译后等价于:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
registerAgentCapability(
|
|
25
|
+
resolveAgentMeta({ name: "panel.openCadViewer", ... }, "/…/construction.ts"),
|
|
26
|
+
openCadViewer,
|
|
27
|
+
);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
宿主 `vite.config.ts`:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import spotlightAgentIoc from "@inupedia/spotlight-client/vite";
|
|
34
|
+
|
|
35
|
+
export default defineConfig({
|
|
36
|
+
plugins: [
|
|
37
|
+
spotlightAgentIoc({
|
|
38
|
+
agentPreset: "@/service/agent/presets/resolveAgentMeta",
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
TypeScript shim:`/// <reference types="@inupedia/spotlight-client/agent-decorator" />`
|
|
45
|
+
|
|
46
|
+
路径约定与 name 推断规则见 `src/service/agent/README.md`。
|
|
47
|
+
|
|
48
|
+
> 暂不支持运行时装饰器(esbuild 限制);HOF 写法 `agent(meta)(fn)` 仍可用。
|
|
49
|
+
|
|
50
|
+
## 分工(Inupedia 标准)
|
|
51
|
+
|
|
52
|
+
| 注入 | 目录 | 作用 |
|
|
53
|
+
|------|------|------|
|
|
54
|
+
| **Skills** | `.inupedia/skills/<id>/` | 知识、流程、`allowed-tools` |
|
|
55
|
+
| **Service** | `src/service/agent/capabilities/` | 可执行 host tools(`@agent` IoC) |
|
|
56
|
+
|
|
57
|
+
Skills 布局与 [Agent Skills 开放标准](https://agentskills.io) 一致。
|
|
58
|
+
|
|
59
|
+
## Service 目录
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
src/service/agent/
|
|
63
|
+
├── host.ts
|
|
64
|
+
├── capabilities/ # @agent + 函数体
|
|
65
|
+
├── actions/ # Vue / Cesium 复用
|
|
66
|
+
└── presets/
|
|
67
|
+
└── resolveAgentMeta.ts
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
registerAgentCapability / buildAgentServiceHost / loadAgentCapabilities
|
|
74
|
+
validateSkillFrontmatter / substituteSkillPlaceholders
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
校验:`pnpm validate:skills`
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type AgentToolDef } from "./defineAgentTool.js";
|
|
2
|
+
/** Metadata for IoC-style `@agent({ name })` registration (invoke comes from the decorated function). */
|
|
3
|
+
export type AgentCapabilityMeta<TInput extends Record<string, unknown> = Record<string, unknown>> = Omit<AgentToolDef<TInput>, "invoke"> & {
|
|
4
|
+
/**
|
|
5
|
+
* Optional guard run before the handler (scene/tab navigation, etc.).
|
|
6
|
+
* Replaces a separate `*Controller.ts` when the only extra work is prepare.
|
|
7
|
+
*/
|
|
8
|
+
before?: () => void | Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
declare const AGENT_CAPABILITY: unique symbol;
|
|
11
|
+
export type AgentCapabilityHandler<TInput extends Record<string, unknown> = Record<string, unknown>> = (input: TInput) => Promise<unknown>;
|
|
12
|
+
export type AgentCapabilityDecorator<TInput extends Record<string, unknown> = Record<string, unknown>> = AgentCapabilityHandler<TInput> & {
|
|
13
|
+
[AGENT_CAPABILITY]?: AgentCapabilityMeta<TInput>;
|
|
14
|
+
};
|
|
15
|
+
export declare function getAgentCapabilityMeta<TInput extends Record<string, unknown>>(handler: AgentCapabilityHandler<TInput>): AgentCapabilityMeta<TInput> | undefined;
|
|
16
|
+
/** Register a handler against tool metadata (shared by decorator + manual wiring). */
|
|
17
|
+
export declare function registerAgentCapability<TInput extends Record<string, unknown>>(meta: AgentCapabilityMeta<TInput>, handler: AgentCapabilityHandler<TInput>): AgentCapabilityDecorator<TInput>;
|
|
18
|
+
/**
|
|
19
|
+
* IoC-style agent capability registration.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* @agent({ name: "demo.ping", description: "…" })
|
|
23
|
+
* export async function demoPing() {
|
|
24
|
+
* return { ok: true };
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* // or HOF (no decorator flag):
|
|
28
|
+
* export const demoPing = agent({ name: "demo.ping", description: "…" })(async () => ({ ok: true }));
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* Requires `experimentalDecorators: true` in tsconfig for `@agent` syntax.
|
|
32
|
+
*/
|
|
33
|
+
export declare function agent<TInput extends Record<string, unknown> = Record<string, unknown>>(meta: AgentCapabilityMeta<TInput>): AgentCapabilityDecorator<TInput> & ((handler: AgentCapabilityHandler<TInput>) => AgentCapabilityDecorator<TInput>);
|
|
34
|
+
/** Alias for teams preferring `@Agent({ … })` naming. */
|
|
35
|
+
export declare const Agent: typeof agent;
|
|
36
|
+
/** Eager-load capability modules (Vite `import.meta.glob` side effects). */
|
|
37
|
+
export declare function loadAgentCapabilities(modules: Record<string, unknown>, options?: {
|
|
38
|
+
exclude?: RegExp;
|
|
39
|
+
}): void;
|
|
40
|
+
/** Optional: register exported handlers tagged via HOF `agent(meta)(fn)` without decorators. */
|
|
41
|
+
export declare function registerExportedAgentCapabilities(moduleExports: Record<string, unknown>): void;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=agentCapability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentCapability.d.ts","sourceRoot":"","sources":["../src/agentCapability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE1E,yGAAyG;AACzG,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC9F,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG;IACrC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC,CAAC;AAEJ,QAAA,MAAM,gBAAgB,eAAmD,CAAC;AAE1E,MAAM,MAAM,sBAAsB,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CACrG,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,M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aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,IAAI,CAUN"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { defineAgentTool } from "./defineAgentTool.js";
|
|
2
|
+
const AGENT_CAPABILITY = Symbol.for("inupedia.spotlight.agentCapability");
|
|
3
|
+
function attachCapabilityMeta(handler, meta) {
|
|
4
|
+
const tagged = handler;
|
|
5
|
+
tagged[AGENT_CAPABILITY] = meta;
|
|
6
|
+
return tagged;
|
|
7
|
+
}
|
|
8
|
+
export function getAgentCapabilityMeta(handler) {
|
|
9
|
+
return handler[AGENT_CAPABILITY];
|
|
10
|
+
}
|
|
11
|
+
/** Register a handler against tool metadata (shared by decorator + manual wiring). */
|
|
12
|
+
export function registerAgentCapability(meta, handler) {
|
|
13
|
+
const { before, ...toolMeta } = meta;
|
|
14
|
+
const invoke = before
|
|
15
|
+
? async (input) => {
|
|
16
|
+
await before();
|
|
17
|
+
return handler(input);
|
|
18
|
+
}
|
|
19
|
+
: handler;
|
|
20
|
+
defineAgentTool({ ...toolMeta, invoke });
|
|
21
|
+
return attachCapabilityMeta(handler, meta);
|
|
22
|
+
}
|
|
23
|
+
function isLegacyMethodDecoratorArgs(args) {
|
|
24
|
+
return (args.length === 3 &&
|
|
25
|
+
(typeof args[1] === "string" || typeof args[1] === "symbol") &&
|
|
26
|
+
typeof args[2] === "object" &&
|
|
27
|
+
args[2] !== null);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* IoC-style agent capability registration.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* @agent({ name: "demo.ping", description: "…" })
|
|
34
|
+
* export async function demoPing() {
|
|
35
|
+
* return { ok: true };
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* // or HOF (no decorator flag):
|
|
39
|
+
* export const demoPing = agent({ name: "demo.ping", description: "…" })(async () => ({ ok: true }));
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* Requires `experimentalDecorators: true` in tsconfig for `@agent` syntax.
|
|
43
|
+
*/
|
|
44
|
+
export function agent(meta) {
|
|
45
|
+
function registerHandler(handler) {
|
|
46
|
+
return registerAgentCapability(meta, handler);
|
|
47
|
+
}
|
|
48
|
+
function decorator(...args) {
|
|
49
|
+
if (args.length === 1 && typeof args[0] === "function") {
|
|
50
|
+
return registerHandler(args[0]);
|
|
51
|
+
}
|
|
52
|
+
if (isLegacyMethodDecoratorArgs(args)) {
|
|
53
|
+
const descriptor = args[2];
|
|
54
|
+
if (typeof descriptor.value === "function") {
|
|
55
|
+
registerHandler(descriptor.value);
|
|
56
|
+
}
|
|
57
|
+
return descriptor;
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`@agent(${meta.name}) must decorate a function declaration or method`);
|
|
60
|
+
}
|
|
61
|
+
return decorator;
|
|
62
|
+
}
|
|
63
|
+
/** Alias for teams preferring `@Agent({ … })` naming. */
|
|
64
|
+
export const Agent = agent;
|
|
65
|
+
/** Eager-load capability modules (Vite `import.meta.glob` side effects). */
|
|
66
|
+
export function loadAgentCapabilities(modules, options) {
|
|
67
|
+
const exclude = options?.exclude ?? /\/(_|\.test\.|\.spec\.)/;
|
|
68
|
+
for (const path of Object.keys(modules)) {
|
|
69
|
+
if (exclude.test(path))
|
|
70
|
+
continue;
|
|
71
|
+
void modules[path];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Optional: register exported handlers tagged via HOF `agent(meta)(fn)` without decorators. */
|
|
75
|
+
export function registerExportedAgentCapabilities(moduleExports) {
|
|
76
|
+
for (const exported of Object.values(moduleExports)) {
|
|
77
|
+
if (typeof exported !== "function")
|
|
78
|
+
continue;
|
|
79
|
+
const meta = getAgentCapabilityMeta(exported);
|
|
80
|
+
if (meta) {
|
|
81
|
+
registerAgentCapability(meta, exported);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal @agent meta — scene/host/tab resolved at compile time via resolveAgentMeta(filePath).
|
|
3
|
+
*/
|
|
4
|
+
import type { AgentCapabilityMeta } from "./agentCapability.js";
|
|
5
|
+
import type { HostEffectConfig, ToolFieldSchema } from "./defineAgentTool.js";
|
|
6
|
+
export type AgentDef<TInput extends Record<string, unknown> = Record<string, unknown>> = {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
displayName?: string;
|
|
10
|
+
tab?: string;
|
|
11
|
+
scene?: "construction" | "onsite";
|
|
12
|
+
host?: Partial<HostEffectConfig<TInput>>;
|
|
13
|
+
input?: Record<string, ToolFieldSchema>;
|
|
14
|
+
rollback?: () => void | Promise<void>;
|
|
15
|
+
recovery?: AgentCapabilityMeta<TInput>["recovery"];
|
|
16
|
+
exposeToLoop?: boolean;
|
|
17
|
+
executionMode?: "serial" | "parallel-safe";
|
|
18
|
+
executionTarget?: "host" | "runtime";
|
|
19
|
+
summarizeResult?: AgentCapabilityMeta<TInput>["summarizeResult"];
|
|
20
|
+
requires?: string[];
|
|
21
|
+
withSmallTabPayload?: boolean;
|
|
22
|
+
navScene?: 0 | 1 | 2;
|
|
23
|
+
mainTab?: string;
|
|
24
|
+
smallTab?: string;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=agentDecoratorTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentDecoratorTypes.d.ts","sourceRoot":"","sources":["../src/agentDecoratorTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE9E,MAAM,MAAM,QAAQ,CAClB,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC9D;IACF,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,cAAc,GAAG,QAAQ,CAAC;IAClC,IAAI,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC;IACnD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,QAAQ,GAAG,eAAe,CAAC;IAC3C,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,eAAe,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACjE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AgentToolErrorCode, ToolExecutionTarget } from "@inupedia/spotlight-protocol";
|
|
2
|
+
import { type HostToolEffect } from "./agentRegistry.js";
|
|
3
|
+
export interface ToolTraceEvent {
|
|
4
|
+
phase: "dependency" | "context" | "execution";
|
|
5
|
+
source: "executor" | "spotlight_action";
|
|
6
|
+
type: "start" | "missing" | "cycle" | "require" | "prerequisites_resolved" | "precondition_failed" | "retry_scheduled" | "retrying" | "recovery_action" | "rollback_applied" | "rollback_failed" | "run_failed" | "done";
|
|
7
|
+
tool: string;
|
|
8
|
+
detail?: string;
|
|
9
|
+
at: number;
|
|
10
|
+
elapsedMs: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ToolResult<T = unknown> {
|
|
13
|
+
success: boolean;
|
|
14
|
+
data?: T;
|
|
15
|
+
error?: string;
|
|
16
|
+
errorCode?: AgentToolErrorCode;
|
|
17
|
+
executionTarget?: ToolExecutionTarget;
|
|
18
|
+
hostEffect?: HostToolEffect;
|
|
19
|
+
trace: ToolTraceEvent[];
|
|
20
|
+
}
|
|
21
|
+
export type AgentExecutorContext = Record<string, unknown>;
|
|
22
|
+
export type AgentExecutorNavigation = {
|
|
23
|
+
getContext: () => AgentExecutorContext;
|
|
24
|
+
ensureMainScene?: () => Promise<void>;
|
|
25
|
+
ensureMidScene?: () => Promise<void>;
|
|
26
|
+
ensureSmallScene?: () => Promise<void>;
|
|
27
|
+
ensureMainTab?: (tab: string) => Promise<void>;
|
|
28
|
+
ensureSmallTab?: (tab: string) => Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
export type CreateAgentExecutorOptions = AgentExecutorNavigation & {
|
|
31
|
+
loadTools?: () => Promise<unknown>;
|
|
32
|
+
onToolComplete?: (toolName: string, input: unknown, result: ToolResult<unknown>) => void;
|
|
33
|
+
};
|
|
34
|
+
export declare function createAgentExecutor(options: CreateAgentExecutorOptions): <TInput = unknown, TOutput = unknown>(toolName: string, input: TInput) => Promise<ToolResult<TOutput>>;
|
|
35
|
+
//# sourceMappingURL=agentExecutor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentExecutor.d.ts","sourceRoot":"","sources":["../src/agentExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAC5F,OAAO,EAWL,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAA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AC,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,uBAAuB,GAAG;IACjE,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,cAAc,CAAC,EAAE,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,KACxB,IAAI,CAAC;CACX,CAAC;AAsBF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,IAgXvC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC/D,UAAU,MAAM,EAChB,OAAO,MAAM,KACZ,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAQhC"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { getTool, getToolAvailabilityCheck, getToolContextHint, getToolExecutionTarget, getToolHostEffectBuilder, getToolInvoker, getToolPreflight, getToolRecovery, getToolRequirements, getToolTimeoutMs, } from "./agentRegistry.js";
|
|
2
|
+
function createTraceEvent(phase, source, type, tool, startAt, detail) {
|
|
3
|
+
const at = Date.now();
|
|
4
|
+
return {
|
|
5
|
+
phase,
|
|
6
|
+
source,
|
|
7
|
+
type,
|
|
8
|
+
tool,
|
|
9
|
+
detail,
|
|
10
|
+
at,
|
|
11
|
+
elapsedMs: Math.max(0, at - startAt),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function createAgentExecutor(options) {
|
|
15
|
+
const ok = (data, trace = [], meta = {}) => ({ success: true, data, trace, ...meta });
|
|
16
|
+
const fail = (errorCode, error, trace = [], meta = {}) => ({ success: false, errorCode, error, trace, ...meta });
|
|
17
|
+
async function applyContextHint(toolName, ctx) {
|
|
18
|
+
let nextContext = ctx;
|
|
19
|
+
const tool = getTool(toolName);
|
|
20
|
+
const isAvailable = tool ? getToolAvailabilityCheck(tool) : null;
|
|
21
|
+
if (tool && isAvailable && !isAvailable(nextContext)) {
|
|
22
|
+
const hint = getToolContextHint(tool);
|
|
23
|
+
if (hint?.ensureSceneLevel === 0) {
|
|
24
|
+
await options.ensureMainScene?.();
|
|
25
|
+
nextContext = options.getContext();
|
|
26
|
+
}
|
|
27
|
+
if (hint?.ensureSceneLevel === 1) {
|
|
28
|
+
await options.ensureMidScene?.();
|
|
29
|
+
nextContext = options.getContext();
|
|
30
|
+
}
|
|
31
|
+
if (hint?.ensureSceneLevel === 2) {
|
|
32
|
+
await options.ensureSmallScene?.();
|
|
33
|
+
nextContext = options.getContext();
|
|
34
|
+
}
|
|
35
|
+
if (hint?.ensureMainTab) {
|
|
36
|
+
await options.ensureMainTab?.(hint.ensureMainTab);
|
|
37
|
+
nextContext = options.getContext();
|
|
38
|
+
}
|
|
39
|
+
if (hint?.ensureSmallTab) {
|
|
40
|
+
await options.ensureSmallTab?.(hint.ensureSmallTab);
|
|
41
|
+
nextContext = options.getContext();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return nextContext;
|
|
45
|
+
}
|
|
46
|
+
async function resolvePrerequisites(toolName, visited, trace, startAt) {
|
|
47
|
+
const tool = getTool(toolName);
|
|
48
|
+
if (!tool) {
|
|
49
|
+
return fail("UNKNOWN_TOOL", `未知工具: ${toolName}`, [
|
|
50
|
+
...trace,
|
|
51
|
+
createTraceEvent("execution", "executor", "missing", toolName, startAt),
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
if (visited.has(toolName)) {
|
|
55
|
+
return fail("CIRCULAR_DEPENDENCY", `工具依赖存在循环: ${toolName}`, [
|
|
56
|
+
...trace,
|
|
57
|
+
createTraceEvent("dependency", "executor", "cycle", toolName, startAt),
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
visited.add(toolName);
|
|
61
|
+
for (const dependencyName of tool.requires ?? []) {
|
|
62
|
+
const nextTrace = [
|
|
63
|
+
...trace,
|
|
64
|
+
createTraceEvent("dependency", "executor", "require", toolName, startAt, dependencyName),
|
|
65
|
+
];
|
|
66
|
+
const result = await runToolInternal(dependencyName, undefined, visited, nextTrace);
|
|
67
|
+
if (!result.success) {
|
|
68
|
+
return fail("PREREQUISITE_FAILED", `前置工具执行失败: ${toolName} <- ${dependencyName},${result.error ?? "未知错误"}`, [...nextTrace, ...(result.trace ?? [])]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
visited.delete(toolName);
|
|
72
|
+
return ok(undefined, [
|
|
73
|
+
...trace,
|
|
74
|
+
createTraceEvent("dependency", "executor", "prerequisites_resolved", toolName, startAt),
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
async function runToolInternal(toolName, input, visited = new Set(), trace = [], attempt = 1, runStartAt = Date.now()) {
|
|
78
|
+
const tool = getTool(toolName);
|
|
79
|
+
const startAt = runStartAt;
|
|
80
|
+
if (!tool) {
|
|
81
|
+
return fail("UNKNOWN_TOOL", `未知工具: ${toolName}`, [
|
|
82
|
+
...trace,
|
|
83
|
+
createTraceEvent("execution", "executor", "missing", toolName, startAt),
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
const baseTrace = [
|
|
87
|
+
...trace,
|
|
88
|
+
createTraceEvent("execution", "executor", attempt === 1 ? "start" : "retrying", toolName, startAt, attempt === 1 ? undefined : `attempt=${attempt}`),
|
|
89
|
+
];
|
|
90
|
+
let ctx = options.getContext();
|
|
91
|
+
const isAvailable = getToolAvailabilityCheck(tool);
|
|
92
|
+
const requirements = getToolRequirements(tool);
|
|
93
|
+
if (!isAvailable(ctx) && requirements.length) {
|
|
94
|
+
const dependencyResult = await resolvePrerequisites(toolName, visited, [], startAt);
|
|
95
|
+
if (!dependencyResult.success) {
|
|
96
|
+
return dependencyResult;
|
|
97
|
+
}
|
|
98
|
+
ctx = options.getContext();
|
|
99
|
+
baseTrace.push(...dependencyResult.trace);
|
|
100
|
+
}
|
|
101
|
+
ctx = await applyContextHint(toolName, ctx);
|
|
102
|
+
if (!isAvailable(ctx)) {
|
|
103
|
+
const sceneLevel = ctx.sceneLevel ?? "?";
|
|
104
|
+
const mainTab = ctx.mainTab ?? "?";
|
|
105
|
+
const smallTab = ctx.smallTab ?? "?";
|
|
106
|
+
const failure = fail("PRECONDITION_FAILED", `前置条件不满足: ${toolName},当前 sceneLevel=${sceneLevel} mainTab=${mainTab} smallTab=${smallTab}`, [
|
|
107
|
+
...baseTrace,
|
|
108
|
+
createTraceEvent("context", "executor", "precondition_failed", toolName, startAt, `scene=${sceneLevel},main=${mainTab},small=${smallTab}`),
|
|
109
|
+
]);
|
|
110
|
+
return finalizeFailure(toolName, input, failure, attempt, startAt);
|
|
111
|
+
}
|
|
112
|
+
const preflight = getToolPreflight(tool);
|
|
113
|
+
if (preflight) {
|
|
114
|
+
const result = await preflight(input, { uiContext: ctx });
|
|
115
|
+
if (result.ok === false) {
|
|
116
|
+
const failure = fail("PRECONDITION_FAILED", `执行前校验未通过: ${toolName},${result.reason}`, [
|
|
117
|
+
...baseTrace,
|
|
118
|
+
createTraceEvent("context", "executor", "precondition_failed", toolName, startAt, `preflight:${result.reason}`),
|
|
119
|
+
]);
|
|
120
|
+
return finalizeFailure(toolName, input, failure, attempt, startAt);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const invoke = getToolInvoker(tool);
|
|
125
|
+
const executionTarget = getToolExecutionTarget(tool);
|
|
126
|
+
const timeoutMs = getToolTimeoutMs(tool);
|
|
127
|
+
const data = (await runWithTimeout(toolName, timeoutMs, () => invoke(input)));
|
|
128
|
+
const buildHostEffect = getToolHostEffectBuilder(tool);
|
|
129
|
+
const hostEffect = executionTarget === "host" && buildHostEffect
|
|
130
|
+
? buildHostEffect(input, data)
|
|
131
|
+
: undefined;
|
|
132
|
+
const resultMeta = executionTarget === "host"
|
|
133
|
+
? { executionTarget, ...(hostEffect ? { hostEffect } : {}) }
|
|
134
|
+
: {};
|
|
135
|
+
return ok(data, [
|
|
136
|
+
...baseTrace,
|
|
137
|
+
createTraceEvent("execution", "executor", "done", toolName, startAt),
|
|
138
|
+
], resultMeta);
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
142
|
+
const errorCode = message.includes("工具执行超时:")
|
|
143
|
+
? "TOOL_TIMEOUT"
|
|
144
|
+
: "TOOL_RUN_FAILED";
|
|
145
|
+
const failure = fail(errorCode, message, [
|
|
146
|
+
...baseTrace,
|
|
147
|
+
createTraceEvent("execution", "executor", "run_failed", toolName, startAt, message),
|
|
148
|
+
], getToolExecutionTarget(tool) === "host"
|
|
149
|
+
? { executionTarget: "host" }
|
|
150
|
+
: {});
|
|
151
|
+
return finalizeFailure(toolName, input, failure, attempt, startAt);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async function finalizeFailure(toolName, input, result, attempt, startAt) {
|
|
155
|
+
const tool = getTool(toolName);
|
|
156
|
+
const recovery = tool ? getToolRecovery(tool) : undefined;
|
|
157
|
+
if (recovery?.maxRetries &&
|
|
158
|
+
result.errorCode &&
|
|
159
|
+
attempt <= recovery.maxRetries) {
|
|
160
|
+
const retryOn = recovery.retryOn ??
|
|
161
|
+
[
|
|
162
|
+
"PRECONDITION_FAILED",
|
|
163
|
+
"TOOL_RUN_FAILED",
|
|
164
|
+
"TOOL_TIMEOUT",
|
|
165
|
+
];
|
|
166
|
+
if (retryOn.includes(result.errorCode)) {
|
|
167
|
+
const retryTrace = [
|
|
168
|
+
...result.trace,
|
|
169
|
+
createTraceEvent("execution", "executor", "retry_scheduled", toolName, startAt, `attempt=${attempt + 1}`),
|
|
170
|
+
];
|
|
171
|
+
if (recovery.beforeRetry) {
|
|
172
|
+
await recovery.beforeRetry(input);
|
|
173
|
+
retryTrace.push(createTraceEvent("execution", "executor", "recovery_action", toolName, startAt, "before_retry"));
|
|
174
|
+
}
|
|
175
|
+
return runToolInternal(toolName, input, new Set(), retryTrace, attempt + 1, startAt);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (recovery?.rollback && result.errorCode) {
|
|
179
|
+
const rollbackOn = recovery.retryOn ??
|
|
180
|
+
[
|
|
181
|
+
"PRECONDITION_FAILED",
|
|
182
|
+
"TOOL_RUN_FAILED",
|
|
183
|
+
"TOOL_TIMEOUT",
|
|
184
|
+
];
|
|
185
|
+
if (rollbackOn.includes(result.errorCode)) {
|
|
186
|
+
try {
|
|
187
|
+
await recovery.rollback(input);
|
|
188
|
+
result.trace.push(createTraceEvent("execution", "executor", "rollback_applied", toolName, startAt));
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
192
|
+
result.trace.push(createTraceEvent("execution", "executor", "rollback_failed", toolName, startAt, message));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
async function runWithTimeout(toolName, timeoutMs, run) {
|
|
199
|
+
if (!timeoutMs || timeoutMs <= 0)
|
|
200
|
+
return run();
|
|
201
|
+
return new Promise((resolve, reject) => {
|
|
202
|
+
const timer = setTimeout(() => {
|
|
203
|
+
reject(new Error(`工具执行超时: ${toolName} (${timeoutMs}ms)`));
|
|
204
|
+
}, timeoutMs);
|
|
205
|
+
run()
|
|
206
|
+
.then((value) => {
|
|
207
|
+
clearTimeout(timer);
|
|
208
|
+
resolve(value);
|
|
209
|
+
})
|
|
210
|
+
.catch((error) => {
|
|
211
|
+
clearTimeout(timer);
|
|
212
|
+
reject(error);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return async function runTool(toolName, input) {
|
|
217
|
+
if (options.loadTools) {
|
|
218
|
+
await options.loadTools();
|
|
219
|
+
}
|
|
220
|
+
const result = await runToolInternal(toolName, input);
|
|
221
|
+
options.onToolComplete?.(toolName, input, result);
|
|
222
|
+
return result;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic host-side agent tool registry (registerTool / listTools / schemas).
|
|
3
|
+
*/
|
|
4
|
+
import type { AgentToolErrorCode, AgentUiContext, HostToolEffect, ToolExecutionTarget } from "@inupedia/spotlight-protocol";
|
|
5
|
+
export type { AgentToolErrorCode, HostToolEffect, ToolExecutionTarget };
|
|
6
|
+
export interface ToolContextHint {
|
|
7
|
+
ensureSceneLevel?: number;
|
|
8
|
+
ensureMainTab?: string;
|
|
9
|
+
ensureSmallTab?: string;
|
|
10
|
+
}
|
|
11
|
+
export type ToolExecutionMode = "serial" | "parallel-safe";
|
|
12
|
+
export interface ToolInputSchemaSuccess<TInput> {
|
|
13
|
+
success: true;
|
|
14
|
+
data: TInput;
|
|
15
|
+
}
|
|
16
|
+
export interface ToolInputSchemaFailure {
|
|
17
|
+
success: false;
|
|
18
|
+
error: string;
|
|
19
|
+
}
|
|
20
|
+
export type ToolInputSchemaResult<TInput> = ToolInputSchemaSuccess<TInput> | ToolInputSchemaFailure;
|
|
21
|
+
export interface ToolInputSchema<TInput = unknown> {
|
|
22
|
+
safeParse(input: unknown): ToolInputSchemaResult<TInput>;
|
|
23
|
+
describe?: string;
|
|
24
|
+
}
|
|
25
|
+
type ToolInputFieldDescriptor = {
|
|
26
|
+
type: "string" | "number" | "boolean";
|
|
27
|
+
enum?: readonly (string | number | boolean)[];
|
|
28
|
+
optional?: boolean;
|
|
29
|
+
description?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function createToolInputSchema<TInput extends Record<string, unknown>>(fields: Record<string, ToolInputFieldDescriptor>): ToolInputSchema<TInput>;
|
|
32
|
+
export declare function createLooseObjectSchema<TInput extends Record<string, unknown> = Record<string, unknown>>(description?: string): ToolInputSchema<TInput>;
|
|
33
|
+
export interface ToolRecoveryConfig<TInput = unknown> {
|
|
34
|
+
maxRetries?: number;
|
|
35
|
+
retryOn?: AgentToolErrorCode[];
|
|
36
|
+
beforeRetry?: (input: TInput) => Promise<void> | void;
|
|
37
|
+
rollback?: (input: TInput) => Promise<void> | void;
|
|
38
|
+
}
|
|
39
|
+
export interface ToolPreflightContext<TContext extends AgentUiContext = AgentUiContext> {
|
|
40
|
+
uiContext: TContext;
|
|
41
|
+
}
|
|
42
|
+
export type ToolPreflightResult = {
|
|
43
|
+
ok: true;
|
|
44
|
+
} | {
|
|
45
|
+
ok: false;
|
|
46
|
+
reason: string;
|
|
47
|
+
};
|
|
48
|
+
export interface ToolAvailability<TInput = unknown, TContext extends AgentUiContext = AgentUiContext> {
|
|
49
|
+
isAvailable?: (ctx: TContext) => boolean;
|
|
50
|
+
requirements?: string[];
|
|
51
|
+
contextHint?: ToolContextHint;
|
|
52
|
+
preflight?: (input: TInput, context: ToolPreflightContext<TContext>) => Promise<ToolPreflightResult> | ToolPreflightResult;
|
|
53
|
+
}
|
|
54
|
+
export interface ToolExecution<TInput = unknown, TOutput = unknown> {
|
|
55
|
+
invoke: (input: TInput) => Promise<TOutput>;
|
|
56
|
+
summarizeResult?: (result: TOutput) => string;
|
|
57
|
+
executionMode?: ToolExecutionMode;
|
|
58
|
+
executionTarget?: ToolExecutionTarget;
|
|
59
|
+
timeoutMs?: number;
|
|
60
|
+
recovery?: ToolRecoveryConfig<TInput>;
|
|
61
|
+
exposeToLoop?: boolean;
|
|
62
|
+
buildHostEffect?: (input: TInput, output: TOutput) => HostToolEffect | undefined;
|
|
63
|
+
}
|
|
64
|
+
export interface AgentTool<TInput = unknown, TOutput = unknown, TContext extends AgentUiContext = AgentUiContext> {
|
|
65
|
+
name: string;
|
|
66
|
+
title?: string;
|
|
67
|
+
displayName?: string;
|
|
68
|
+
description: string;
|
|
69
|
+
category?: string;
|
|
70
|
+
tags?: string[];
|
|
71
|
+
inputSchema?: ToolInputSchema<TInput>;
|
|
72
|
+
isAvailable?: (ctx: TContext) => boolean;
|
|
73
|
+
invoke: (input: TInput) => Promise<TOutput>;
|
|
74
|
+
executionMode?: ToolExecutionMode;
|
|
75
|
+
executionTarget?: ToolExecutionTarget;
|
|
76
|
+
timeoutMs?: number;
|
|
77
|
+
summarizeResult?: (result: TOutput) => string;
|
|
78
|
+
exposeToLoop?: boolean;
|
|
79
|
+
buildHostEffect?: (input: TInput, output: TOutput) => HostToolEffect | undefined;
|
|
80
|
+
requires?: string[];
|
|
81
|
+
contextHint?: ToolContextHint;
|
|
82
|
+
preflight?: (input: TInput, context: ToolPreflightContext<TContext>) => Promise<ToolPreflightResult> | ToolPreflightResult;
|
|
83
|
+
recovery?: ToolRecoveryConfig<TInput>;
|
|
84
|
+
}
|
|
85
|
+
type AgentToolLegacyCompat<TInput = unknown, TOutput = unknown, TContext extends AgentUiContext = AgentUiContext> = Omit<Partial<AgentTool<TInput, TOutput, TContext>>, "invoke" | "isAvailable"> & {
|
|
86
|
+
availability?: ToolAvailability<TInput, TContext>;
|
|
87
|
+
execution?: ToolExecution<TInput, TOutput>;
|
|
88
|
+
canRun?: (ctx: TContext) => boolean;
|
|
89
|
+
run?: (input: TInput) => Promise<TOutput>;
|
|
90
|
+
};
|
|
91
|
+
export declare function registerTool<TInput = unknown, TOutput = unknown, TContext extends AgentUiContext = AgentUiContext>(tool: AgentTool<TInput, TOutput, TContext> | AgentToolLegacyCompat<TInput, TOutput, TContext>): void;
|
|
92
|
+
export declare function getTool(name: string): AgentTool<unknown, unknown> | undefined;
|
|
93
|
+
export declare function listTools(): AgentTool<unknown, unknown>[];
|
|
94
|
+
export declare function listLoopTools(): AgentTool<unknown, unknown>[];
|
|
95
|
+
export declare function getToolsByPrefix(prefix: string): AgentTool<unknown, unknown>[];
|
|
96
|
+
export declare function clearTools(): void;
|
|
97
|
+
export declare function getToolTitle(tool: AgentTool<unknown, unknown>): string;
|
|
98
|
+
export declare function getToolAvailabilityCheck<TInput = unknown>(tool: AgentTool<TInput, unknown>): (ctx: AgentUiContext) => boolean;
|
|
99
|
+
export declare function getToolRequirements(tool: AgentTool<unknown, unknown>): string[];
|
|
100
|
+
export declare function getToolContextHint(tool: AgentTool<unknown, unknown>): ToolContextHint | undefined;
|
|
101
|
+
export declare function getToolPreflight<TInput = unknown>(tool: AgentTool<TInput, unknown>): ((input: TInput, context: ToolPreflightContext<AgentUiContext>) => Promise<ToolPreflightResult> | ToolPreflightResult) | undefined;
|
|
102
|
+
export declare function getToolInvoker<TInput = unknown, TOutput = unknown>(tool: AgentTool<TInput, TOutput>): (input: TInput) => Promise<TOutput>;
|
|
103
|
+
export declare function getToolExecutionMode(tool: AgentTool<unknown, unknown>): ToolExecutionMode | undefined;
|
|
104
|
+
export declare function getToolExecutionTarget(tool: AgentTool<unknown, unknown>): ToolExecutionTarget;
|
|
105
|
+
export declare function getToolExposeToLoop(tool: AgentTool<unknown, unknown>): boolean;
|
|
106
|
+
export declare function getToolTimeoutMs(tool: AgentTool<unknown, unknown>): number | undefined;
|
|
107
|
+
export declare function getToolRecovery<TInput = unknown>(tool: AgentTool<TInput, unknown>): ToolRecoveryConfig<TInput> | undefined;
|
|
108
|
+
export declare function getToolResultSummarizer<TOutput = unknown>(tool: AgentTool<unknown, TOutput>): ((result: TOutput) => string) | undefined;
|
|
109
|
+
export declare function getToolHostEffectBuilder<TInput = unknown, TOutput = unknown>(tool: AgentTool<TInput, TOutput>): ((input: TInput, output: TOutput) => HostToolEffect | undefined) | undefined;
|
|
110
|
+
//# sourceMappingURL=agentRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentRegistry.d.ts","sourceRoot":"","sources":["../src/agentRegistry.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,mBAAmB,EAAE,CAAC;AAExE,MAAM,WAAW,eAAe;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,iBAAiB,GAAG,QA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