@codeany/open-agent-sdk 0.2.1 → 0.2.2

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.
Files changed (232) hide show
  1. package/.env.example +8 -0
  2. package/examples/01-simple-query.ts +43 -0
  3. package/examples/02-multi-tool.ts +44 -0
  4. package/examples/03-multi-turn.ts +39 -0
  5. package/examples/04-prompt-api.ts +29 -0
  6. package/examples/05-custom-system-prompt.ts +26 -0
  7. package/examples/06-mcp-server.ts +49 -0
  8. package/examples/07-custom-tools.ts +87 -0
  9. package/examples/08-official-api-compat.ts +38 -0
  10. package/examples/09-subagents.ts +48 -0
  11. package/examples/10-permissions.ts +40 -0
  12. package/examples/11-custom-mcp-tools.ts +101 -0
  13. package/examples/12-skills.ts +88 -0
  14. package/examples/13-hooks.ts +88 -0
  15. package/examples/14-openai-compat.ts +71 -0
  16. package/examples/web/index.html +365 -0
  17. package/examples/web/server.ts +157 -0
  18. package/package.json +1 -7
  19. package/src/engine.ts +3 -0
  20. package/tsconfig.json +19 -0
  21. package/dist/agent.d.ts +0 -113
  22. package/dist/agent.d.ts.map +0 -1
  23. package/dist/agent.js +0 -446
  24. package/dist/agent.js.map +0 -1
  25. package/dist/engine.d.ts +0 -62
  26. package/dist/engine.d.ts.map +0 -1
  27. package/dist/engine.js +0 -494
  28. package/dist/engine.js.map +0 -1
  29. package/dist/hooks.d.ts +0 -111
  30. package/dist/hooks.d.ts.map +0 -1
  31. package/dist/hooks.js +0 -179
  32. package/dist/hooks.js.map +0 -1
  33. package/dist/index.d.ts +0 -66
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/index.js +0 -133
  36. package/dist/index.js.map +0 -1
  37. package/dist/mcp/client.d.ts +0 -19
  38. package/dist/mcp/client.d.ts.map +0 -1
  39. package/dist/mcp/client.js +0 -126
  40. package/dist/mcp/client.js.map +0 -1
  41. package/dist/providers/anthropic.d.ts +0 -17
  42. package/dist/providers/anthropic.d.ts.map +0 -1
  43. package/dist/providers/anthropic.js +0 -47
  44. package/dist/providers/anthropic.js.map +0 -1
  45. package/dist/providers/index.d.ts +0 -20
  46. package/dist/providers/index.d.ts.map +0 -1
  47. package/dist/providers/index.js +0 -26
  48. package/dist/providers/index.js.map +0 -1
  49. package/dist/providers/openai.d.ts +0 -26
  50. package/dist/providers/openai.d.ts.map +0 -1
  51. package/dist/providers/openai.js +0 -212
  52. package/dist/providers/openai.js.map +0 -1
  53. package/dist/providers/types.d.ts +0 -84
  54. package/dist/providers/types.d.ts.map +0 -1
  55. package/dist/providers/types.js +0 -11
  56. package/dist/providers/types.js.map +0 -1
  57. package/dist/sdk-mcp-server.d.ts +0 -52
  58. package/dist/sdk-mcp-server.d.ts.map +0 -1
  59. package/dist/sdk-mcp-server.js +0 -57
  60. package/dist/sdk-mcp-server.js.map +0 -1
  61. package/dist/session.d.ts +0 -73
  62. package/dist/session.d.ts.map +0 -1
  63. package/dist/session.js +0 -159
  64. package/dist/session.js.map +0 -1
  65. package/dist/skills/bundled/commit.d.ts +0 -7
  66. package/dist/skills/bundled/commit.d.ts.map +0 -1
  67. package/dist/skills/bundled/commit.js +0 -35
  68. package/dist/skills/bundled/commit.js.map +0 -1
  69. package/dist/skills/bundled/debug.d.ts +0 -7
  70. package/dist/skills/bundled/debug.d.ts.map +0 -1
  71. package/dist/skills/bundled/debug.js +0 -46
  72. package/dist/skills/bundled/debug.js.map +0 -1
  73. package/dist/skills/bundled/index.d.ts +0 -11
  74. package/dist/skills/bundled/index.d.ts.map +0 -1
  75. package/dist/skills/bundled/index.js +0 -26
  76. package/dist/skills/bundled/index.js.map +0 -1
  77. package/dist/skills/bundled/review.d.ts +0 -7
  78. package/dist/skills/bundled/review.d.ts.map +0 -1
  79. package/dist/skills/bundled/review.js +0 -38
  80. package/dist/skills/bundled/review.js.map +0 -1
  81. package/dist/skills/bundled/simplify.d.ts +0 -8
  82. package/dist/skills/bundled/simplify.d.ts.map +0 -1
  83. package/dist/skills/bundled/simplify.js +0 -48
  84. package/dist/skills/bundled/simplify.js.map +0 -1
  85. package/dist/skills/bundled/test.d.ts +0 -7
  86. package/dist/skills/bundled/test.d.ts.map +0 -1
  87. package/dist/skills/bundled/test.js +0 -40
  88. package/dist/skills/bundled/test.js.map +0 -1
  89. package/dist/skills/index.d.ts +0 -7
  90. package/dist/skills/index.d.ts.map +0 -1
  91. package/dist/skills/index.js +0 -8
  92. package/dist/skills/index.js.map +0 -1
  93. package/dist/skills/registry.d.ts +0 -43
  94. package/dist/skills/registry.d.ts.map +0 -1
  95. package/dist/skills/registry.js +0 -111
  96. package/dist/skills/registry.js.map +0 -1
  97. package/dist/skills/types.d.ts +0 -83
  98. package/dist/skills/types.d.ts.map +0 -1
  99. package/dist/skills/types.js +0 -8
  100. package/dist/skills/types.js.map +0 -1
  101. package/dist/tool-helper.d.ts +0 -73
  102. package/dist/tool-helper.d.ts.map +0 -1
  103. package/dist/tool-helper.js +0 -86
  104. package/dist/tool-helper.js.map +0 -1
  105. package/dist/tools/agent-tool.d.ts +0 -17
  106. package/dist/tools/agent-tool.d.ts.map +0 -1
  107. package/dist/tools/agent-tool.js +0 -146
  108. package/dist/tools/agent-tool.js.map +0 -1
  109. package/dist/tools/ask-user.d.ts +0 -18
  110. package/dist/tools/ask-user.d.ts.map +0 -1
  111. package/dist/tools/ask-user.js +0 -72
  112. package/dist/tools/ask-user.js.map +0 -1
  113. package/dist/tools/bash.d.ts +0 -5
  114. package/dist/tools/bash.d.ts.map +0 -1
  115. package/dist/tools/bash.js +0 -67
  116. package/dist/tools/bash.js.map +0 -1
  117. package/dist/tools/config-tool.d.ts +0 -20
  118. package/dist/tools/config-tool.d.ts.map +0 -1
  119. package/dist/tools/config-tool.js +0 -83
  120. package/dist/tools/config-tool.js.map +0 -1
  121. package/dist/tools/cron-tools.d.ts +0 -33
  122. package/dist/tools/cron-tools.d.ts.map +0 -1
  123. package/dist/tools/cron-tools.js +0 -128
  124. package/dist/tools/cron-tools.js.map +0 -1
  125. package/dist/tools/edit.d.ts +0 -5
  126. package/dist/tools/edit.d.ts.map +0 -1
  127. package/dist/tools/edit.js +0 -70
  128. package/dist/tools/edit.js.map +0 -1
  129. package/dist/tools/glob.d.ts +0 -5
  130. package/dist/tools/glob.d.ts.map +0 -1
  131. package/dist/tools/glob.js +0 -75
  132. package/dist/tools/glob.js.map +0 -1
  133. package/dist/tools/grep.d.ts +0 -5
  134. package/dist/tools/grep.d.ts.map +0 -1
  135. package/dist/tools/grep.js +0 -168
  136. package/dist/tools/grep.js.map +0 -1
  137. package/dist/tools/index.d.ts +0 -45
  138. package/dist/tools/index.d.ts.map +0 -1
  139. package/dist/tools/index.js +0 -162
  140. package/dist/tools/index.js.map +0 -1
  141. package/dist/tools/lsp-tool.d.ts +0 -9
  142. package/dist/tools/lsp-tool.d.ts.map +0 -1
  143. package/dist/tools/lsp-tool.js +0 -137
  144. package/dist/tools/lsp-tool.js.map +0 -1
  145. package/dist/tools/mcp-resource-tools.d.ts +0 -14
  146. package/dist/tools/mcp-resource-tools.d.ts.map +0 -1
  147. package/dist/tools/mcp-resource-tools.js +0 -117
  148. package/dist/tools/mcp-resource-tools.js.map +0 -1
  149. package/dist/tools/notebook-edit.d.ts +0 -5
  150. package/dist/tools/notebook-edit.d.ts.map +0 -1
  151. package/dist/tools/notebook-edit.js +0 -85
  152. package/dist/tools/notebook-edit.js.map +0 -1
  153. package/dist/tools/plan-tools.d.ts +0 -12
  154. package/dist/tools/plan-tools.d.ts.map +0 -1
  155. package/dist/tools/plan-tools.js +0 -77
  156. package/dist/tools/plan-tools.js.map +0 -1
  157. package/dist/tools/read.d.ts +0 -5
  158. package/dist/tools/read.d.ts.map +0 -1
  159. package/dist/tools/read.js +0 -66
  160. package/dist/tools/read.js.map +0 -1
  161. package/dist/tools/send-message.d.ts +0 -31
  162. package/dist/tools/send-message.d.ts.map +0 -1
  163. package/dist/tools/send-message.js +0 -77
  164. package/dist/tools/send-message.js.map +0 -1
  165. package/dist/tools/skill-tool.d.ts +0 -9
  166. package/dist/tools/skill-tool.d.ts.map +0 -1
  167. package/dist/tools/skill-tool.js +0 -115
  168. package/dist/tools/skill-tool.js.map +0 -1
  169. package/dist/tools/task-tools.d.ts +0 -48
  170. package/dist/tools/task-tools.d.ts.map +0 -1
  171. package/dist/tools/task-tools.js +0 -242
  172. package/dist/tools/task-tools.js.map +0 -1
  173. package/dist/tools/team-tools.d.ts +0 -34
  174. package/dist/tools/team-tools.d.ts.map +0 -1
  175. package/dist/tools/team-tools.js +0 -103
  176. package/dist/tools/team-tools.js.map +0 -1
  177. package/dist/tools/todo-tool.d.ts +0 -22
  178. package/dist/tools/todo-tool.d.ts.map +0 -1
  179. package/dist/tools/todo-tool.js +0 -93
  180. package/dist/tools/todo-tool.js.map +0 -1
  181. package/dist/tools/tool-search.d.ts +0 -13
  182. package/dist/tools/tool-search.d.ts.map +0 -1
  183. package/dist/tools/tool-search.js +0 -76
  184. package/dist/tools/tool-search.js.map +0 -1
  185. package/dist/tools/types.d.ts +0 -29
  186. package/dist/tools/types.d.ts.map +0 -1
  187. package/dist/tools/types.js +0 -52
  188. package/dist/tools/types.js.map +0 -1
  189. package/dist/tools/web-fetch.d.ts +0 -5
  190. package/dist/tools/web-fetch.d.ts.map +0 -1
  191. package/dist/tools/web-fetch.js +0 -60
  192. package/dist/tools/web-fetch.js.map +0 -1
  193. package/dist/tools/web-search.d.ts +0 -5
  194. package/dist/tools/web-search.d.ts.map +0 -1
  195. package/dist/tools/web-search.js +0 -77
  196. package/dist/tools/web-search.js.map +0 -1
  197. package/dist/tools/worktree-tools.d.ts +0 -10
  198. package/dist/tools/worktree-tools.d.ts.map +0 -1
  199. package/dist/tools/worktree-tools.js +0 -130
  200. package/dist/tools/worktree-tools.js.map +0 -1
  201. package/dist/tools/write.d.ts +0 -5
  202. package/dist/tools/write.d.ts.map +0 -1
  203. package/dist/tools/write.js +0 -40
  204. package/dist/tools/write.js.map +0 -1
  205. package/dist/types.d.ts +0 -423
  206. package/dist/types.d.ts.map +0 -1
  207. package/dist/types.js +0 -5
  208. package/dist/types.js.map +0 -1
  209. package/dist/utils/compact.d.ts +0 -44
  210. package/dist/utils/compact.d.ts.map +0 -1
  211. package/dist/utils/compact.js +0 -162
  212. package/dist/utils/compact.js.map +0 -1
  213. package/dist/utils/context.d.ts +0 -35
  214. package/dist/utils/context.d.ts.map +0 -1
  215. package/dist/utils/context.js +0 -174
  216. package/dist/utils/context.js.map +0 -1
  217. package/dist/utils/fileCache.d.ts +0 -64
  218. package/dist/utils/fileCache.d.ts.map +0 -1
  219. package/dist/utils/fileCache.js +0 -117
  220. package/dist/utils/fileCache.js.map +0 -1
  221. package/dist/utils/messages.d.ts +0 -57
  222. package/dist/utils/messages.d.ts.map +0 -1
  223. package/dist/utils/messages.js +0 -152
  224. package/dist/utils/messages.js.map +0 -1
  225. package/dist/utils/retry.d.ts +0 -48
  226. package/dist/utils/retry.d.ts.map +0 -1
  227. package/dist/utils/retry.js +0 -111
  228. package/dist/utils/retry.js.map +0 -1
  229. package/dist/utils/tokens.d.ts +0 -57
  230. package/dist/utils/tokens.d.ts.map +0 -1
  231. package/dist/utils/tokens.js +0 -134
  232. package/dist/utils/tokens.js.map +0 -1
package/dist/hooks.d.ts DELETED
@@ -1,111 +0,0 @@
1
- /**
2
- * Hook System
3
- *
4
- * Lifecycle hooks for intercepting agent behavior.
5
- * Supports pre/post tool use, session lifecycle, and custom events.
6
- *
7
- * Hook events:
8
- * - PreToolUse: before tool execution
9
- * - PostToolUse: after tool execution
10
- * - PostToolUseFailure: after tool failure
11
- * - SessionStart: session initialization
12
- * - SessionEnd: session cleanup
13
- * - Stop: when turn completes
14
- * - SubagentStart: subagent spawned
15
- * - SubagentStop: subagent completed
16
- * - UserPromptSubmit: user sends message
17
- * - PermissionRequest: permission check triggered
18
- * - TaskCreated: task created
19
- * - TaskCompleted: task finished
20
- * - ConfigChange: settings changed
21
- * - CwdChanged: working directory changed
22
- * - FileChanged: file modified
23
- * - Notification: system notification
24
- */
25
- /**
26
- * All supported hook events.
27
- */
28
- export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "UserPromptSubmit", "PermissionRequest", "PermissionDenied", "TaskCreated", "TaskCompleted", "ConfigChange", "CwdChanged", "FileChanged", "Notification", "PreCompact", "PostCompact", "TeammateIdle"];
29
- export type HookEvent = typeof HOOK_EVENTS[number];
30
- /**
31
- * Hook definition.
32
- */
33
- export interface HookDefinition {
34
- /** Shell command or function to execute */
35
- command?: string;
36
- /** Function handler */
37
- handler?: (input: HookInput) => Promise<HookOutput | void>;
38
- /** Tool name matcher (regex pattern) */
39
- matcher?: string;
40
- /** Timeout in milliseconds */
41
- timeout?: number;
42
- }
43
- /**
44
- * Hook input passed to handlers.
45
- */
46
- export interface HookInput {
47
- event: HookEvent;
48
- toolName?: string;
49
- toolInput?: unknown;
50
- toolOutput?: unknown;
51
- toolUseId?: string;
52
- sessionId?: string;
53
- cwd?: string;
54
- error?: string;
55
- [key: string]: unknown;
56
- }
57
- /**
58
- * Hook output returned by handlers.
59
- */
60
- export interface HookOutput {
61
- /** Message to append to conversation */
62
- message?: string;
63
- /** Permission update */
64
- permissionUpdate?: {
65
- tool: string;
66
- behavior: 'allow' | 'deny';
67
- };
68
- /** Whether to block the action */
69
- block?: boolean;
70
- /** Notification */
71
- notification?: {
72
- title: string;
73
- body: string;
74
- level?: 'info' | 'warning' | 'error';
75
- };
76
- }
77
- /**
78
- * Hook configuration (from settings).
79
- */
80
- export type HookConfig = Record<string, HookDefinition[]>;
81
- /**
82
- * Hook registry for managing and executing hooks.
83
- */
84
- export declare class HookRegistry {
85
- private hooks;
86
- /**
87
- * Register hooks from configuration.
88
- */
89
- registerFromConfig(config: HookConfig): void;
90
- /**
91
- * Register a single hook.
92
- */
93
- register(event: HookEvent, definition: HookDefinition): void;
94
- /**
95
- * Execute hooks for an event.
96
- */
97
- execute(event: HookEvent, input: HookInput): Promise<HookOutput[]>;
98
- /**
99
- * Check if any hooks are registered for an event.
100
- */
101
- hasHooks(event: HookEvent): boolean;
102
- /**
103
- * Clear all hooks.
104
- */
105
- clear(): void;
106
- }
107
- /**
108
- * Create a default hook registry.
109
- */
110
- export declare function createHookRegistry(config?: HookConfig): HookRegistry;
111
- //# sourceMappingURL=hooks.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH;;GAEG;AACH,eAAO,MAAM,WAAW,4UAqBd,CAAA;AAEV,MAAM,MAAM,SAAS,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAA;AAElD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uBAAuB;IACvB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;IAC1D,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,SAAS,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,wBAAwB;IACxB,gBAAgB,CAAC,EAAE;QACjB,IAAI,EAAE,MAAM,CAAA;QACZ,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAA;KAC3B,CAAA;IACD,kCAAkC;IAClC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,mBAAmB;IACnB,YAAY,CAAC,EAAE;QACb,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAA;KACrC,CAAA;CACF;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,CAAA;AAEzD;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAA8C;IAE3D;;OAEG;IACH,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAU5C;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,GAAG,IAAI;IAM5D;;OAEG;IACG,OAAO,CACX,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,GACf,OAAO,CAAC,UAAU,EAAE,CAAC;IAuCxB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO;IAInC;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAuDD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,YAAY,CAMpE"}
package/dist/hooks.js DELETED
@@ -1,179 +0,0 @@
1
- /**
2
- * Hook System
3
- *
4
- * Lifecycle hooks for intercepting agent behavior.
5
- * Supports pre/post tool use, session lifecycle, and custom events.
6
- *
7
- * Hook events:
8
- * - PreToolUse: before tool execution
9
- * - PostToolUse: after tool execution
10
- * - PostToolUseFailure: after tool failure
11
- * - SessionStart: session initialization
12
- * - SessionEnd: session cleanup
13
- * - Stop: when turn completes
14
- * - SubagentStart: subagent spawned
15
- * - SubagentStop: subagent completed
16
- * - UserPromptSubmit: user sends message
17
- * - PermissionRequest: permission check triggered
18
- * - TaskCreated: task created
19
- * - TaskCompleted: task finished
20
- * - ConfigChange: settings changed
21
- * - CwdChanged: working directory changed
22
- * - FileChanged: file modified
23
- * - Notification: system notification
24
- */
25
- import { spawn } from 'child_process';
26
- /**
27
- * All supported hook events.
28
- */
29
- export const HOOK_EVENTS = [
30
- 'PreToolUse',
31
- 'PostToolUse',
32
- 'PostToolUseFailure',
33
- 'SessionStart',
34
- 'SessionEnd',
35
- 'Stop',
36
- 'SubagentStart',
37
- 'SubagentStop',
38
- 'UserPromptSubmit',
39
- 'PermissionRequest',
40
- 'PermissionDenied',
41
- 'TaskCreated',
42
- 'TaskCompleted',
43
- 'ConfigChange',
44
- 'CwdChanged',
45
- 'FileChanged',
46
- 'Notification',
47
- 'PreCompact',
48
- 'PostCompact',
49
- 'TeammateIdle',
50
- ];
51
- /**
52
- * Hook registry for managing and executing hooks.
53
- */
54
- export class HookRegistry {
55
- hooks = new Map();
56
- /**
57
- * Register hooks from configuration.
58
- */
59
- registerFromConfig(config) {
60
- for (const [event, definitions] of Object.entries(config)) {
61
- const hookEvent = event;
62
- if (!HOOK_EVENTS.includes(hookEvent))
63
- continue;
64
- const existing = this.hooks.get(hookEvent) || [];
65
- this.hooks.set(hookEvent, [...existing, ...definitions]);
66
- }
67
- }
68
- /**
69
- * Register a single hook.
70
- */
71
- register(event, definition) {
72
- const existing = this.hooks.get(event) || [];
73
- existing.push(definition);
74
- this.hooks.set(event, existing);
75
- }
76
- /**
77
- * Execute hooks for an event.
78
- */
79
- async execute(event, input) {
80
- const definitions = this.hooks.get(event) || [];
81
- const results = [];
82
- for (const def of definitions) {
83
- // Check matcher for tool-specific hooks
84
- if (def.matcher && input.toolName) {
85
- const regex = new RegExp(def.matcher);
86
- if (!regex.test(input.toolName))
87
- continue;
88
- }
89
- try {
90
- let output = undefined;
91
- if (def.handler) {
92
- // Function handler
93
- output = await Promise.race([
94
- def.handler(input),
95
- new Promise((_, reject) => setTimeout(() => reject(new Error('Hook timeout')), def.timeout || 30000)),
96
- ]);
97
- }
98
- else if (def.command) {
99
- // Shell command handler
100
- output = await executeShellHook(def.command, input, def.timeout || 30000);
101
- }
102
- if (output) {
103
- results.push(output);
104
- }
105
- }
106
- catch (err) {
107
- // Log but don't fail on hook errors
108
- console.error(`[Hook] ${event} hook failed: ${err.message}`);
109
- }
110
- }
111
- return results;
112
- }
113
- /**
114
- * Check if any hooks are registered for an event.
115
- */
116
- hasHooks(event) {
117
- return (this.hooks.get(event)?.length || 0) > 0;
118
- }
119
- /**
120
- * Clear all hooks.
121
- */
122
- clear() {
123
- this.hooks.clear();
124
- }
125
- }
126
- /**
127
- * Execute a shell command as a hook.
128
- */
129
- async function executeShellHook(command, input, timeout) {
130
- return new Promise((resolve) => {
131
- const proc = spawn('bash', ['-c', command], {
132
- timeout,
133
- env: {
134
- ...process.env,
135
- HOOK_EVENT: input.event,
136
- HOOK_TOOL_NAME: input.toolName || '',
137
- HOOK_SESSION_ID: input.sessionId || '',
138
- HOOK_CWD: input.cwd || '',
139
- },
140
- stdio: ['pipe', 'pipe', 'pipe'],
141
- });
142
- // Send input as JSON on stdin
143
- proc.stdin?.write(JSON.stringify(input));
144
- proc.stdin?.end();
145
- const chunks = [];
146
- proc.stdout?.on('data', (d) => chunks.push(d));
147
- proc.on('close', (code) => {
148
- if (code !== 0) {
149
- resolve(undefined);
150
- return;
151
- }
152
- const stdout = Buffer.concat(chunks).toString('utf-8').trim();
153
- if (!stdout) {
154
- resolve(undefined);
155
- return;
156
- }
157
- try {
158
- const output = JSON.parse(stdout);
159
- resolve(output);
160
- }
161
- catch {
162
- // Non-JSON output treated as message
163
- resolve({ message: stdout });
164
- }
165
- });
166
- proc.on('error', () => resolve(undefined));
167
- });
168
- }
169
- /**
170
- * Create a default hook registry.
171
- */
172
- export function createHookRegistry(config) {
173
- const registry = new HookRegistry();
174
- if (config) {
175
- registry.registerFromConfig(config);
176
- }
177
- return registry;
178
- }
179
- //# sourceMappingURL=hooks.js.map
package/dist/hooks.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAA;AAExD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,YAAY;IACZ,aAAa;IACb,oBAAoB;IACpB,cAAc;IACd,YAAY;IACZ,MAAM;IACN,eAAe;IACf,cAAc;IACd,kBAAkB;IAClB,mBAAmB;IACnB,kBAAkB;IAClB,aAAa;IACb,eAAe;IACf,cAAc;IACd,YAAY;IACZ,aAAa;IACb,cAAc;IACd,YAAY;IACZ,aAAa;IACb,cAAc;CACN,CAAA;AA2DV;;GAEG;AACH,MAAM,OAAO,YAAY;IACf,KAAK,GAAqC,IAAI,GAAG,EAAE,CAAA;IAE3D;;OAEG;IACH,kBAAkB,CAAC,MAAkB;QACnC,KAAK,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1D,MAAM,SAAS,GAAG,KAAkB,CAAA;YACpC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAAE,SAAQ;YAE9C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAA;YAChD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,WAAW,CAAC,CAAC,CAAA;QAC1D,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,KAAgB,EAAE,UAA0B;QACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,I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}
package/dist/index.d.ts DELETED
@@ -1,66 +0,0 @@
1
- /**
2
- * @codeany/open-agent-sdk
3
- *
4
- * Open-source Agent SDK by CodeAny (https://codeany.ai).
5
- * Runs the full agent loop in-process without spawning subprocesses.
6
- *
7
- * Features:
8
- * - 30+ built-in tools (file I/O, shell, web, agents, tasks, teams, etc.)
9
- * - Skill system (reusable prompt templates with bundled skills)
10
- * - MCP server integration (stdio, SSE, HTTP)
11
- * - Context compression (auto-compact, micro-compact)
12
- * - Retry with exponential backoff
13
- * - Git status & project context injection
14
- * - Multi-turn session persistence
15
- * - Permission system (allow/deny/bypass modes)
16
- * - Subagent spawning & team coordination
17
- * - Task management & scheduling
18
- * - Hook system with lifecycle integration (pre/post tool use, session, compact)
19
- * - Token estimation & cost tracking
20
- * - File state LRU caching
21
- * - Plan mode for structured workflows
22
- */
23
- export { Agent, createAgent, query } from './agent.js';
24
- export { tool, sdkToolToToolDefinition } from './tool-helper.js';
25
- export type { ToolAnnotations, CallToolResult, SdkMcpToolDefinition, } from './tool-helper.js';
26
- export { createSdkMcpServer, isSdkServerConfig } from './sdk-mcp-server.js';
27
- export type { McpSdkServerConfig } from './sdk-mcp-server.js';
28
- export { QueryEngine } from './engine.js';
29
- export { createProvider, AnthropicProvider, OpenAIProvider, } from './providers/index.js';
30
- export type { ApiType, LLMProvider, CreateMessageParams, CreateMessageResponse, NormalizedMessageParam, NormalizedContentBlock, NormalizedTool, NormalizedResponseBlock, } from './providers/index.js';
31
- export { getAllBaseTools, filterTools, assembleToolPool, defineTool, toApiTool, BashTool, FileReadTool, FileWriteTool, FileEditTool, GlobTool, GrepTool, NotebookEditTool, WebFetchTool, WebSearchTool, AgentTool, SendMessageTool, TeamCreateTool, TeamDeleteTool, TaskCreateTool, TaskListTool, TaskUpdateTool, TaskGetTool, TaskStopTool, TaskOutputTool, EnterWorktreeTool, ExitWorktreeTool, EnterPlanModeTool, ExitPlanModeTool, AskUserQuestionTool, ToolSearchTool, ListMcpResourcesTool, ReadMcpResourceTool, CronCreateTool, CronDeleteTool, CronListTool, RemoteTriggerTool, LSPTool, ConfigTool, TodoWriteTool, SkillTool, } from './tools/index.js';
32
- export { connectMCPServer, closeAllConnections } from './mcp/client.js';
33
- export type { MCPConnection } from './mcp/client.js';
34
- export { registerSkill, getSkill, getAllSkills, getUserInvocableSkills, hasSkill, unregisterSkill, clearSkills, formatSkillsForPrompt, initBundledSkills, } from './skills/index.js';
35
- export type { SkillDefinition, SkillContentBlock, SkillResult, } from './skills/index.js';
36
- export { HookRegistry, createHookRegistry, HOOK_EVENTS, } from './hooks.js';
37
- export type { HookEvent, HookDefinition, HookInput, HookOutput, HookConfig, } from './hooks.js';
38
- export { saveSession, loadSession, listSessions, forkSession, getSessionMessages, getSessionInfo, renameSession, tagSession, appendToSession, deleteSession, } from './session.js';
39
- export type { SessionMetadata, SessionData } from './session.js';
40
- export { getSystemContext, getUserContext, getGitStatus, readProjectContextContent, discoverProjectContextFiles, clearContextCache, } from './utils/context.js';
41
- export { createUserMessage, createAssistantMessage, normalizeMessagesForAPI, stripImagesFromMessages, extractTextFromContent, createCompactBoundaryMessage, truncateText, } from './utils/messages.js';
42
- export { estimateTokens, estimateMessagesTokens, estimateSystemPromptTokens, getTokenCountFromUsage, getContextWindowSize, getAutoCompactThreshold, estimateCost, MODEL_PRICING, AUTOCOMPACT_BUFFER_TOKENS, } from './utils/tokens.js';
43
- export { shouldAutoCompact, compactConversation, microCompactMessages, createAutoCompactState, } from './utils/compact.js';
44
- export type { AutoCompactState } from './utils/compact.js';
45
- export { withRetry, isRetryableError, isPromptTooLongError, isAuthError, isRateLimitError, formatApiError, getRetryDelay, DEFAULT_RETRY_CONFIG, } from './utils/retry.js';
46
- export type { RetryConfig } from './utils/retry.js';
47
- export { FileStateCache, createFileStateCache, } from './utils/fileCache.js';
48
- export type { FileState } from './utils/fileCache.js';
49
- export { getAllTasks, getTask, clearTasks, } from './tools/task-tools.js';
50
- export type { Task, TaskStatus } from './tools/task-tools.js';
51
- export { getAllTeams, getTeam, clearTeams, } from './tools/team-tools.js';
52
- export type { Team } from './tools/team-tools.js';
53
- export { readMailbox, writeToMailbox, clearMailboxes, } from './tools/send-message.js';
54
- export type { AgentMessage } from './tools/send-message.js';
55
- export { isPlanModeActive, getCurrentPlan, } from './tools/plan-tools.js';
56
- export { registerAgents, clearAgents, } from './tools/agent-tool.js';
57
- export { setQuestionHandler, clearQuestionHandler, } from './tools/ask-user.js';
58
- export { setDeferredTools, } from './tools/tool-search.js';
59
- export { setMcpConnections, } from './tools/mcp-resource-tools.js';
60
- export { getAllCronJobs, clearCronJobs, } from './tools/cron-tools.js';
61
- export type { CronJob } from './tools/cron-tools.js';
62
- export { getConfig, setConfig, clearConfig, } from './tools/config-tool.js';
63
- export { getTodos, clearTodos, } from './tools/todo-tool.js';
64
- export type { TodoItem } from './tools/todo-tool.js';
65
- export type { Message, UserMessage, AssistantMessage, ConversationMessage, MessageRole, SDKMessage, SDKAssistantMessage, SDKToolResultMessage, SDKResultMessage, SDKPartialMessage, ToolDefinition, ToolInputSchema, ToolContext, ToolResult, PermissionMode, PermissionBehavior, CanUseToolFn, CanUseToolResult, McpServerConfig, McpStdioConfig, McpSseConfig, McpHttpConfig, AgentOptions, AgentDefinition, QueryResult, ThinkingConfig, TokenUsage, QueryEngineConfig, ContentBlockParam, ContentBlock, SandboxSettings, SandboxNetworkConfig, SandboxFilesystemConfig, OutputFormat, SettingSource, ModelInfo, } from './types.js';
66
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAMtD,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAChE,YAAY,EACV,eAAe,EACf,cAAc,EACd,oBAAoB,G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AAW,EACX,UAAU,EAGV,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAGhB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,aAAa,EAGb,YAAY,EACZ,eAAe,EACf,WAAW,EACX,cAAc,EACd,UAAU,EAGV,iBAAiB,EAGjB,iBAAiB,EACjB,YAAY,EAGZ,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EAGvB,YAAY,EAGZ,aAAa,EAGb,SAAS,GACV,MAAM,YAAY,CAAA"}
package/dist/index.js DELETED
@@ -1,133 +0,0 @@
1
- /**
2
- * @codeany/open-agent-sdk
3
- *
4
- * Open-source Agent SDK by CodeAny (https://codeany.ai).
5
- * Runs the full agent loop in-process without spawning subprocesses.
6
- *
7
- * Features:
8
- * - 30+ built-in tools (file I/O, shell, web, agents, tasks, teams, etc.)
9
- * - Skill system (reusable prompt templates with bundled skills)
10
- * - MCP server integration (stdio, SSE, HTTP)
11
- * - Context compression (auto-compact, micro-compact)
12
- * - Retry with exponential backoff
13
- * - Git status & project context injection
14
- * - Multi-turn session persistence
15
- * - Permission system (allow/deny/bypass modes)
16
- * - Subagent spawning & team coordination
17
- * - Task management & scheduling
18
- * - Hook system with lifecycle integration (pre/post tool use, session, compact)
19
- * - Token estimation & cost tracking
20
- * - File state LRU caching
21
- * - Plan mode for structured workflows
22
- */
23
- // --------------------------------------------------------------------------
24
- // High-level Agent API
25
- // --------------------------------------------------------------------------
26
- export { Agent, createAgent, query } from './agent.js';
27
- // --------------------------------------------------------------------------
28
- // Tool Helper (Zod-based tool creation, compatible with official SDK)
29
- // --------------------------------------------------------------------------
30
- export { tool, sdkToolToToolDefinition } from './tool-helper.js';
31
- // --------------------------------------------------------------------------
32
- // In-Process MCP Server
33
- // --------------------------------------------------------------------------
34
- export { createSdkMcpServer, isSdkServerConfig } from './sdk-mcp-server.js';
35
- // --------------------------------------------------------------------------
36
- // Core Engine
37
- // --------------------------------------------------------------------------
38
- export { QueryEngine } from './engine.js';
39
- // --------------------------------------------------------------------------
40
- // LLM Providers (Anthropic + OpenAI)
41
- // --------------------------------------------------------------------------
42
- export { createProvider, AnthropicProvider, OpenAIProvider, } from './providers/index.js';
43
- // --------------------------------------------------------------------------
44
- // Tool System (30+ tools)
45
- // --------------------------------------------------------------------------
46
- export {
47
- // Registry
48
- getAllBaseTools, filterTools, assembleToolPool,
49
- // Helpers
50
- defineTool, toApiTool,
51
- // Core file I/O & execution
52
- BashTool, FileReadTool, FileWriteTool, FileEditTool, GlobTool, GrepTool, NotebookEditTool,
53
- // Web
54
- WebFetchTool, WebSearchTool,
55
- // Agent & Multi-agent
56
- AgentTool, SendMessageTool, TeamCreateTool, TeamDeleteTool,
57
- // Tasks
58
- TaskCreateTool, TaskListTool, TaskUpdateTool, TaskGetTool, TaskStopTool, TaskOutputTool,
59
- // Worktree
60
- EnterWorktreeTool, ExitWorktreeTool,
61
- // Planning
62
- EnterPlanModeTool, ExitPlanModeTool,
63
- // User interaction
64
- AskUserQuestionTool,
65
- // Discovery
66
- ToolSearchTool,
67
- // MCP Resources
68
- ListMcpResourcesTool, ReadMcpResourceTool,
69
- // Scheduling
70
- CronCreateTool, CronDeleteTool, CronListTool, RemoteTriggerTool,
71
- // LSP
72
- LSPTool,
73
- // Config
74
- ConfigTool,
75
- // Todo
76
- TodoWriteTool,
77
- // Skill
78
- SkillTool, } from './tools/index.js';
79
- // --------------------------------------------------------------------------
80
- // MCP Client
81
- // --------------------------------------------------------------------------
82
- export { connectMCPServer, closeAllConnections } from './mcp/client.js';
83
- // --------------------------------------------------------------------------
84
- // Skill System
85
- // --------------------------------------------------------------------------
86
- export { registerSkill, getSkill, getAllSkills, getUserInvocableSkills, hasSkill, unregisterSkill, clearSkills, formatSkillsForPrompt, initBundledSkills, } from './skills/index.js';
87
- // --------------------------------------------------------------------------
88
- // Hook System
89
- // --------------------------------------------------------------------------
90
- export { HookRegistry, createHookRegistry, HOOK_EVENTS, } from './hooks.js';
91
- // --------------------------------------------------------------------------
92
- // Session Management
93
- // --------------------------------------------------------------------------
94
- export { saveSession, loadSession, listSessions, forkSession, getSessionMessages, getSessionInfo, renameSession, tagSession, appendToSession, deleteSession, } from './session.js';
95
- // --------------------------------------------------------------------------
96
- // Context Utilities
97
- // --------------------------------------------------------------------------
98
- export { getSystemContext, getUserContext, getGitStatus, readProjectContextContent, discoverProjectContextFiles, clearContextCache, } from './utils/context.js';
99
- // --------------------------------------------------------------------------
100
- // Message Utilities
101
- // --------------------------------------------------------------------------
102
- export { createUserMessage, createAssistantMessage, normalizeMessagesForAPI, stripImagesFromMessages, extractTextFromContent, createCompactBoundaryMessage, truncateText, } from './utils/messages.js';
103
- // --------------------------------------------------------------------------
104
- // Token Estimation & Cost
105
- // --------------------------------------------------------------------------
106
- export { estimateTokens, estimateMessagesTokens, estimateSystemPromptTokens, getTokenCountFromUsage, getContextWindowSize, getAutoCompactThreshold, estimateCost, MODEL_PRICING, AUTOCOMPACT_BUFFER_TOKENS, } from './utils/tokens.js';
107
- // --------------------------------------------------------------------------
108
- // Context Compression
109
- // --------------------------------------------------------------------------
110
- export { shouldAutoCompact, compactConversation, microCompactMessages, createAutoCompactState, } from './utils/compact.js';
111
- // --------------------------------------------------------------------------
112
- // Retry Logic
113
- // --------------------------------------------------------------------------
114
- export { withRetry, isRetryableError, isPromptTooLongError, isAuthError, isRateLimitError, formatApiError, getRetryDelay, DEFAULT_RETRY_CONFIG, } from './utils/retry.js';
115
- // --------------------------------------------------------------------------
116
- // File State Cache
117
- // --------------------------------------------------------------------------
118
- export { FileStateCache, createFileStateCache, } from './utils/fileCache.js';
119
- // --------------------------------------------------------------------------
120
- // Task & Team State (for advanced usage)
121
- // --------------------------------------------------------------------------
122
- export { getAllTasks, getTask, clearTasks, } from './tools/task-tools.js';
123
- export { getAllTeams, getTeam, clearTeams, } from './tools/team-tools.js';
124
- export { readMailbox, writeToMailbox, clearMailboxes, } from './tools/send-message.js';
125
- export { isPlanModeActive, getCurrentPlan, } from './tools/plan-tools.js';
126
- export { registerAgents, clearAgents, } from './tools/agent-tool.js';
127
- export { setQuestionHandler, clearQuestionHandler, } from './tools/ask-user.js';
128
- export { setDeferredTools, } from './tools/tool-search.js';
129
- export { setMcpConnections, } from './tools/mcp-resource-tools.js';
130
- export { getAllCronJobs, clearCronJobs, } from './tools/cron-tools.js';
131
- export { getConfig, setConfig, clearConfig, } from './tools/config-tool.js';
132
- export { getTodos, clearTodos, } from './tools/todo-tool.js';
133
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,6EAA6E;AAC7E,uBAAuB;AACvB,6EAA6E;AAE7E,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEtD,6EAA6E;AAC7E,sEAAsE;AACtE,6EAA6E;AAE7E,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAOhE,6EAA6E;AAC7E,wBAAwB;AACxB,6EAA6E;AAE7E,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAG3E,6EAA6E;AAC7E,cAAc;AACd,6EAA6E;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,6EAA6E;AAC7E,qCAAqC;AACrC,6EAA6E;AAE7E,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,cAAc,GACf,MAAM,sBAAsB,CAAA;AAY7B,6EAA6E;AAC7E,0BAA0B;AAC1B,6EAA6E;AAE7E,OAAO;AACL,WAAW;AACX,eAAe,EACf,WAAW,EACX,gBAAgB;AAEhB,UAAU;AACV,UAAU,EACV,SAAS;AAET,4BAA4B;AAC5B,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,gBAAgB;AAE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OAAO,EACL,cAAc,EACd,WAAW,GACZ,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,gBAAgB,GACjB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EACL,iBAAiB,GAClB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EACL,cAAc,EACd,aAAa,GACd,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,GACZ,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EACL,QAAQ,EACR,UAAU,GACX,MAAM,sBAAsB,CAAA"}
@@ -1,19 +0,0 @@
1
- /**
2
- * MCP Client - Connect to Model Context Protocol servers
3
- */
4
- import type { ToolDefinition, McpServerConfig } from '../types.js';
5
- export interface MCPConnection {
6
- name: string;
7
- status: 'connected' | 'disconnected' | 'error';
8
- tools: ToolDefinition[];
9
- close: () => Promise<void>;
10
- }
11
- /**
12
- * Connect to an MCP server and fetch its tools.
13
- */
14
- export declare function connectMCPServer(name: string, config: McpServerConfig): Promise<MCPConnection>;
15
- /**
16
- * Close all MCP connections.
17
- */
18
- export declare function closeAllConnections(connections: MCPConnection[]): Promise<void>;
19
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/mcp/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAA2B,MAAM,aAAa,CAAA;AAE3F,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,WAAW,GAAG,cAAc,GAAG,OAAO,CAAA;IAC9C,KAAK,EAAE,cAAc,EAAE,CAAA;IACvB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,aAAa,CAAC,CAgExB;AA6DD;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAErF"}