@cloudbase/agent-tools 0.0.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 (194) hide show
  1. package/CHANGELOG.md +416 -0
  2. package/dist/agent_tool.d.ts +7 -0
  3. package/dist/agent_tool.d.ts.map +1 -0
  4. package/dist/agent_tool.js +16 -0
  5. package/dist/agent_tool.js.map +1 -0
  6. package/dist/bash/bash-tool.d.ts +61 -0
  7. package/dist/bash/bash-tool.d.ts.map +1 -0
  8. package/dist/bash/bash-tool.js +191 -0
  9. package/dist/bash/bash-tool.js.map +1 -0
  10. package/dist/bash/index.d.ts +7 -0
  11. package/dist/bash/index.d.ts.map +1 -0
  12. package/dist/bash/index.js +17 -0
  13. package/dist/bash/index.js.map +1 -0
  14. package/dist/bash/operator/base-operator.d.ts +44 -0
  15. package/dist/bash/operator/base-operator.d.ts.map +1 -0
  16. package/dist/bash/operator/base-operator.js +14 -0
  17. package/dist/bash/operator/base-operator.js.map +1 -0
  18. package/dist/bash/operator/local-operator.d.ts +15 -0
  19. package/dist/bash/operator/local-operator.d.ts.map +1 -0
  20. package/dist/bash/operator/local-operator.js +145 -0
  21. package/dist/bash/operator/local-operator.js.map +1 -0
  22. package/dist/bash/operator/sandbox-operator.d.ts +22 -0
  23. package/dist/bash/operator/sandbox-operator.d.ts.map +1 -0
  24. package/dist/bash/operator/sandbox-operator.js +112 -0
  25. package/dist/bash/operator/sandbox-operator.js.map +1 -0
  26. package/dist/bash/utils.d.ts +106 -0
  27. package/dist/bash/utils.d.ts.map +1 -0
  28. package/dist/bash/utils.js +197 -0
  29. package/dist/bash/utils.js.map +1 -0
  30. package/dist/browser/browser-instance-manager.d.ts +79 -0
  31. package/dist/browser/browser-instance-manager.d.ts.map +1 -0
  32. package/dist/browser/browser-instance-manager.js +242 -0
  33. package/dist/browser/browser-instance-manager.js.map +1 -0
  34. package/dist/browser/browser-tool-executor.d.ts +57 -0
  35. package/dist/browser/browser-tool-executor.d.ts.map +1 -0
  36. package/dist/browser/browser-tool-executor.js +205 -0
  37. package/dist/browser/browser-tool-executor.js.map +1 -0
  38. package/dist/browser/browser_client_unified.d.ts +52 -0
  39. package/dist/browser/browser_client_unified.d.ts.map +1 -0
  40. package/dist/browser/browser_client_unified.js +381 -0
  41. package/dist/browser/browser_client_unified.js.map +1 -0
  42. package/dist/browser/browser_tool_unified.d.ts +93 -0
  43. package/dist/browser/browser_tool_unified.d.ts.map +1 -0
  44. package/dist/browser/browser_tool_unified.js +181 -0
  45. package/dist/browser/browser_tool_unified.js.map +1 -0
  46. package/dist/browser/index.d.ts +7 -0
  47. package/dist/browser/index.d.ts.map +1 -0
  48. package/dist/browser/index.js +19 -0
  49. package/dist/browser/index.js.map +1 -0
  50. package/dist/browser/sandbox-connector.d.ts +93 -0
  51. package/dist/browser/sandbox-connector.d.ts.map +1 -0
  52. package/dist/browser/sandbox-connector.js +272 -0
  53. package/dist/browser/sandbox-connector.js.map +1 -0
  54. package/dist/browser/types.d.ts +53 -0
  55. package/dist/browser/types.d.ts.map +1 -0
  56. package/dist/browser/types.js +3 -0
  57. package/dist/browser/types.js.map +1 -0
  58. package/dist/code_executers/base_code_executor.d.ts +17 -0
  59. package/dist/code_executers/base_code_executor.d.ts.map +1 -0
  60. package/dist/code_executers/base_code_executor.js +20 -0
  61. package/dist/code_executers/base_code_executor.js.map +1 -0
  62. package/dist/code_executers/built_in_code_executor.d.ts +25 -0
  63. package/dist/code_executers/built_in_code_executor.d.ts.map +1 -0
  64. package/dist/code_executers/built_in_code_executor.js +106 -0
  65. package/dist/code_executers/built_in_code_executor.js.map +1 -0
  66. package/dist/code_executers/unsafe_local_code_executor.d.ts +118 -0
  67. package/dist/code_executers/unsafe_local_code_executor.d.ts.map +1 -0
  68. package/dist/code_executers/unsafe_local_code_executor.js +605 -0
  69. package/dist/code_executers/unsafe_local_code_executor.js.map +1 -0
  70. package/dist/fs/edit-tool.d.ts +26 -0
  71. package/dist/fs/edit-tool.d.ts.map +1 -0
  72. package/dist/fs/edit-tool.js +202 -0
  73. package/dist/fs/edit-tool.js.map +1 -0
  74. package/dist/fs/glob-tool.d.ts +31 -0
  75. package/dist/fs/glob-tool.d.ts.map +1 -0
  76. package/dist/fs/glob-tool.js +287 -0
  77. package/dist/fs/glob-tool.js.map +1 -0
  78. package/dist/fs/grep-tool.d.ts +32 -0
  79. package/dist/fs/grep-tool.d.ts.map +1 -0
  80. package/dist/fs/grep-tool.js +353 -0
  81. package/dist/fs/grep-tool.js.map +1 -0
  82. package/dist/fs/index.d.ts +11 -0
  83. package/dist/fs/index.d.ts.map +1 -0
  84. package/dist/fs/index.js +38 -0
  85. package/dist/fs/index.js.map +1 -0
  86. package/dist/fs/ls-tool.d.ts +26 -0
  87. package/dist/fs/ls-tool.d.ts.map +1 -0
  88. package/dist/fs/ls-tool.js +235 -0
  89. package/dist/fs/ls-tool.js.map +1 -0
  90. package/dist/fs/multiedit-tool.d.ts +34 -0
  91. package/dist/fs/multiedit-tool.d.ts.map +1 -0
  92. package/dist/fs/multiedit-tool.js +158 -0
  93. package/dist/fs/multiedit-tool.js.map +1 -0
  94. package/dist/fs/operator/base-operator.d.ts +28 -0
  95. package/dist/fs/operator/base-operator.d.ts.map +1 -0
  96. package/dist/fs/operator/base-operator.js +21 -0
  97. package/dist/fs/operator/base-operator.js.map +1 -0
  98. package/dist/fs/operator/in-memory-operator.d.ts +39 -0
  99. package/dist/fs/operator/in-memory-operator.d.ts.map +1 -0
  100. package/dist/fs/operator/in-memory-operator.js +115 -0
  101. package/dist/fs/operator/in-memory-operator.js.map +1 -0
  102. package/dist/fs/operator/index.d.ts +6 -0
  103. package/dist/fs/operator/index.d.ts.map +1 -0
  104. package/dist/fs/operator/index.js +28 -0
  105. package/dist/fs/operator/index.js.map +1 -0
  106. package/dist/fs/operator/local-operator.d.ts +25 -0
  107. package/dist/fs/operator/local-operator.d.ts.map +1 -0
  108. package/dist/fs/operator/local-operator.js +62 -0
  109. package/dist/fs/operator/local-operator.js.map +1 -0
  110. package/dist/fs/operator/sanbox-operator.d.ts +31 -0
  111. package/dist/fs/operator/sanbox-operator.d.ts.map +1 -0
  112. package/dist/fs/operator/sanbox-operator.js +172 -0
  113. package/dist/fs/operator/sanbox-operator.js.map +1 -0
  114. package/dist/fs/operator/transaction/index.d.ts +6 -0
  115. package/dist/fs/operator/transaction/index.d.ts.map +1 -0
  116. package/dist/fs/operator/transaction/index.js +28 -0
  117. package/dist/fs/operator/transaction/index.js.map +1 -0
  118. package/dist/fs/operator/transaction/snapshot-strategies.d.ts +54 -0
  119. package/dist/fs/operator/transaction/snapshot-strategies.d.ts.map +1 -0
  120. package/dist/fs/operator/transaction/snapshot-strategies.js +278 -0
  121. package/dist/fs/operator/transaction/snapshot-strategies.js.map +1 -0
  122. package/dist/fs/operator/transaction/transaction-operator.d.ts +53 -0
  123. package/dist/fs/operator/transaction/transaction-operator.d.ts.map +1 -0
  124. package/dist/fs/operator/transaction/transaction-operator.js +195 -0
  125. package/dist/fs/operator/transaction/transaction-operator.js.map +1 -0
  126. package/dist/fs/operator/transaction/transaction-utils.d.ts +80 -0
  127. package/dist/fs/operator/transaction/transaction-utils.d.ts.map +1 -0
  128. package/dist/fs/operator/transaction/transaction-utils.js +156 -0
  129. package/dist/fs/operator/transaction/transaction-utils.js.map +1 -0
  130. package/dist/fs/read-tool.d.ts +32 -0
  131. package/dist/fs/read-tool.d.ts.map +1 -0
  132. package/dist/fs/read-tool.js +271 -0
  133. package/dist/fs/read-tool.js.map +1 -0
  134. package/dist/fs/str-replace-editor.d.ts +23 -0
  135. package/dist/fs/str-replace-editor.d.ts.map +1 -0
  136. package/dist/fs/str-replace-editor.js +74 -0
  137. package/dist/fs/str-replace-editor.js.map +1 -0
  138. package/dist/fs/toolkit.d.ts +61 -0
  139. package/dist/fs/toolkit.d.ts.map +1 -0
  140. package/dist/fs/toolkit.js +113 -0
  141. package/dist/fs/toolkit.js.map +1 -0
  142. package/dist/fs/utils.d.ts +32 -0
  143. package/dist/fs/utils.d.ts.map +1 -0
  144. package/dist/fs/utils.js +133 -0
  145. package/dist/fs/utils.js.map +1 -0
  146. package/dist/fs/write-tool.d.ts +26 -0
  147. package/dist/fs/write-tool.d.ts.map +1 -0
  148. package/dist/fs/write-tool.js +110 -0
  149. package/dist/fs/write-tool.js.map +1 -0
  150. package/dist/index.d.ts +10 -0
  151. package/dist/index.d.ts.map +1 -0
  152. package/dist/index.js +40 -0
  153. package/dist/index.js.map +1 -0
  154. package/dist/mcp/agkit-mcp-server.d.ts +291 -0
  155. package/dist/mcp/agkit-mcp-server.d.ts.map +1 -0
  156. package/dist/mcp/agkit-mcp-server.js +821 -0
  157. package/dist/mcp/agkit-mcp-server.js.map +1 -0
  158. package/dist/mcp/client-tool.d.ts +65 -0
  159. package/dist/mcp/client-tool.d.ts.map +1 -0
  160. package/dist/mcp/client-tool.js +220 -0
  161. package/dist/mcp/client-tool.js.map +1 -0
  162. package/dist/mcp/index.d.ts +14 -0
  163. package/dist/mcp/index.d.ts.map +1 -0
  164. package/dist/mcp/index.js +26 -0
  165. package/dist/mcp/index.js.map +1 -0
  166. package/dist/mcp/mcp-client-manager.d.ts +153 -0
  167. package/dist/mcp/mcp-client-manager.d.ts.map +1 -0
  168. package/dist/mcp/mcp-client-manager.js +606 -0
  169. package/dist/mcp/mcp-client-manager.js.map +1 -0
  170. package/dist/mcp/mcp-toolkit.d.ts +112 -0
  171. package/dist/mcp/mcp-toolkit.d.ts.map +1 -0
  172. package/dist/mcp/mcp-toolkit.js +188 -0
  173. package/dist/mcp/mcp-toolkit.js.map +1 -0
  174. package/dist/mcp/types.d.ts +157 -0
  175. package/dist/mcp/types.d.ts.map +1 -0
  176. package/dist/mcp/types.js +34 -0
  177. package/dist/mcp/types.js.map +1 -0
  178. package/dist/mcp/utils.d.ts +17 -0
  179. package/dist/mcp/utils.d.ts.map +1 -0
  180. package/dist/mcp/utils.js +48 -0
  181. package/dist/mcp/utils.js.map +1 -0
  182. package/dist/types/index.d.ts +31 -0
  183. package/dist/types/index.d.ts.map +1 -0
  184. package/dist/types/index.js +3 -0
  185. package/dist/types/index.js.map +1 -0
  186. package/dist/types/zod.d.ts +18 -0
  187. package/dist/types/zod.d.ts.map +1 -0
  188. package/dist/types/zod.js +3 -0
  189. package/dist/types/zod.js.map +1 -0
  190. package/dist/utils.d.ts +141 -0
  191. package/dist/utils.d.ts.map +1 -0
  192. package/dist/utils.js +379 -0
  193. package/dist/utils.js.map +1 -0
  194. package/package.json +46 -0
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionController = exports.TransactionExecutor = void 0;
4
+ exports.createTransactionExecutor = createTransactionExecutor;
5
+ exports.withTransaction = withTransaction;
6
+ const transaction_operator_1 = require("./transaction-operator");
7
+ /**
8
+ * 事务执行器 - 提供便捷的事务操作方法
9
+ */
10
+ class TransactionExecutor {
11
+ constructor(baseOperator) {
12
+ this.operations = [];
13
+ this.transactionOperator = new transaction_operator_1.TransactionFileOperator(baseOperator);
14
+ }
15
+ /**
16
+ * 获取事务操作器
17
+ */
18
+ getOperator() {
19
+ return this.transactionOperator;
20
+ }
21
+ /**
22
+ * 添加文件写入操作
23
+ */
24
+ writeFile(path, data, options) {
25
+ this.operations.push(async (op) => {
26
+ await op.writeFile(path, data, options);
27
+ });
28
+ return this;
29
+ }
30
+ /**
31
+ * 添加目录创建操作
32
+ */
33
+ mkdir(path, options) {
34
+ this.operations.push(async (op) => {
35
+ await op.mkdir(path, options);
36
+ });
37
+ return this;
38
+ }
39
+ /**
40
+ * 添加自定义操作
41
+ */
42
+ custom(operation) {
43
+ this.operations.push(operation);
44
+ return this;
45
+ }
46
+ /**
47
+ * 执行所有操作
48
+ */
49
+ async execute() {
50
+ await this.transactionOperator.beginTransaction();
51
+ try {
52
+ for (const operation of this.operations) {
53
+ await operation(this.transactionOperator);
54
+ }
55
+ await this.transactionOperator.commitTransaction();
56
+ return { success: true };
57
+ }
58
+ catch (error) {
59
+ await this.transactionOperator.rollbackTransaction();
60
+ return { success: false, error: error };
61
+ }
62
+ finally {
63
+ this.operations = []; // 清理操作列表
64
+ }
65
+ }
66
+ /**
67
+ * 在事务中执行操作
68
+ * @param operation 要执行的操作函数
69
+ * @returns 操作结果
70
+ */
71
+ async executeInTransaction(operation) {
72
+ await this.transactionOperator.beginTransaction();
73
+ try {
74
+ const result = await operation(this.transactionOperator);
75
+ await this.transactionOperator.commitTransaction();
76
+ return result;
77
+ }
78
+ catch (error) {
79
+ await this.transactionOperator.rollbackTransaction();
80
+ throw error;
81
+ }
82
+ }
83
+ /**
84
+ * 手动控制的事务 - 返回事务控制器
85
+ */
86
+ async createTransaction() {
87
+ await this.transactionOperator.beginTransaction();
88
+ return new TransactionController(this.transactionOperator);
89
+ }
90
+ }
91
+ exports.TransactionExecutor = TransactionExecutor;
92
+ /**
93
+ * 事务控制器 - 用于手动控制事务的提交和回滚
94
+ */
95
+ class TransactionController {
96
+ constructor(transactionOperator) {
97
+ this.isCompleted = false;
98
+ this.transactionOperator = transactionOperator;
99
+ }
100
+ /**
101
+ * 获取事务操作器
102
+ */
103
+ getOperator() {
104
+ if (this.isCompleted) {
105
+ throw new Error("Transaction has been completed");
106
+ }
107
+ return this.transactionOperator;
108
+ }
109
+ /**
110
+ * 提交事务
111
+ */
112
+ async commit() {
113
+ if (this.isCompleted) {
114
+ throw new Error("Transaction has already been completed");
115
+ }
116
+ await this.transactionOperator.commitTransaction();
117
+ this.isCompleted = true;
118
+ }
119
+ /**
120
+ * 回滚事务
121
+ */
122
+ async rollback() {
123
+ if (this.isCompleted) {
124
+ throw new Error("Transaction has already been completed");
125
+ }
126
+ await this.transactionOperator.rollbackTransaction();
127
+ this.isCompleted = true;
128
+ }
129
+ /**
130
+ * 检查事务是否已完成
131
+ */
132
+ isTransactionCompleted() {
133
+ return this.isCompleted;
134
+ }
135
+ /**
136
+ * 获取事务操作历史
137
+ */
138
+ getOperationHistory() {
139
+ return this.transactionOperator.getTransactionOperations();
140
+ }
141
+ }
142
+ exports.TransactionController = TransactionController;
143
+ /**
144
+ * 创建事务执行器的便捷函数
145
+ */
146
+ function createTransactionExecutor(baseOperator) {
147
+ return new TransactionExecutor(baseOperator);
148
+ }
149
+ /**
150
+ * 直接在事务中执行操作的便捷函数
151
+ */
152
+ async function withTransaction(baseOperator, operation) {
153
+ const executor = new TransactionExecutor(baseOperator);
154
+ return executor.executeInTransaction(operation);
155
+ }
156
+ //# sourceMappingURL=transaction-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-utils.js","sourceRoot":"","sources":["../../../../src/fs/operator/transaction/transaction-utils.ts"],"names":[],"mappings":";;;AAwKA,8DAIC;AAKD,0CAMC;AAtLD,iEAAiE;AAEjE;;GAEG;AACH,MAAa,mBAAmB;IAK9B,YAAY,YAA8B;QAHlC,eAAU,GAChB,EAAE,CAAC;QAGH,IAAI,CAAC,mBAAmB,GAAG,IAAI,8CAAuB,CAAC,YAAY,CAAC,CAAC;IACvE,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,SAAS,CACP,IAAY,EACZ,IAAqB,EACrB,OAAa;QAEb,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YAChC,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAY,EAAE,OAAa;QAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YAChC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH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C,YAAY,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,eAAe,CACnC,YAA8B,EAC9B,SAA4D;IAE5D,MAAM,QAAQ,GAAG,IAAI,mBAAmB,CAAC,YAAY,CAAC,CAAC;IACvD,OAAO,QAAQ,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { z } from "zod/v4";
2
+ import { ExecutionContext } from "./utils";
3
+ import { ToolResult } from "../utils";
4
+ /**
5
+ * File read result with metadata
6
+ */
7
+ export interface IFileReadResult {
8
+ content: string;
9
+ filePath: string;
10
+ fileType: "text" | "image" | "pdf" | "binary";
11
+ mimeType?: string;
12
+ lineCount?: number;
13
+ isTruncated?: boolean;
14
+ linesShown?: [number, number];
15
+ size: number;
16
+ }
17
+ export declare function read(context: ExecutionContext, params: {
18
+ file_path: string;
19
+ offset?: number;
20
+ endLine?: number;
21
+ limit?: number;
22
+ encoding?: string;
23
+ }): Promise<ToolResult<IFileReadResult>>;
24
+ /**
25
+ * Create SuperDesign read tool with execution context
26
+ */
27
+ export declare function createReadTool(context: ExecutionContext): import("../utils").DynamicTool<z.ZodObject<{
28
+ file_path: z.ZodString;
29
+ offset: z.ZodOptional<z.ZodNumber>;
30
+ limit: z.ZodOptional<z.ZodNumber>;
31
+ }, z.core.$strip>, Record<string, unknown>, IFileReadResult>;
32
+ //# sourceMappingURL=read-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-tool.d.ts","sourceRoot":"","sources":["../../src/fs/read-tool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,OAAO,EACL,gBAAgB,EAKjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAQ,UAAU,EAAmB,MAAM,UAAU,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd;AAkKD,wBAAsB,IAAI,CACxB,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE;IACN,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACA,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAyHtC;AAgBD;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB;;;;6DAwBvD"}
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.read = read;
37
+ exports.createReadTool = createReadTool;
38
+ const path = __importStar(require("path"));
39
+ const mime = __importStar(require("mime-types"));
40
+ const v4_1 = require("zod/v4");
41
+ const utils_1 = require("./utils");
42
+ const utils_2 = require("../utils");
43
+ // Constants for file processing
44
+ const DEFAULT_MAX_LINES = 1000;
45
+ const MAX_LINE_LENGTH = 2000;
46
+ const MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024; // 10MB
47
+ /**
48
+ * Detect file type based on extension and content
49
+ */
50
+ function detectFileType(context, filePath) {
51
+ const ext = path.extname(filePath).toLowerCase();
52
+ const mimeType = mime.lookup(filePath);
53
+ // Check for images
54
+ if (mimeType && mimeType.startsWith("image/")) {
55
+ return "image";
56
+ }
57
+ // Check for PDF
58
+ if (mimeType === "application/pdf") {
59
+ return "pdf";
60
+ }
61
+ // Known binary extensions
62
+ const binaryExtensions = [
63
+ ".exe",
64
+ ".dll",
65
+ ".so",
66
+ ".dylib",
67
+ ".zip",
68
+ ".tar",
69
+ ".gz",
70
+ ".7z",
71
+ ".bin",
72
+ ".dat",
73
+ ".class",
74
+ ".jar",
75
+ ".war",
76
+ ".pyc",
77
+ ".pyo",
78
+ ".doc",
79
+ ".docx",
80
+ ".xls",
81
+ ".xlsx",
82
+ ".ppt",
83
+ ".pptx",
84
+ ".odt",
85
+ ".ods",
86
+ ".odp",
87
+ ".wasm",
88
+ ".obj",
89
+ ".o",
90
+ ".a",
91
+ ".lib",
92
+ ];
93
+ if (binaryExtensions.includes(ext)) {
94
+ return "binary";
95
+ }
96
+ return "text";
97
+ }
98
+ /**
99
+ * Process text file content with line range support
100
+ */
101
+ async function processTextFile(context, filePath, startLine, lineCount, endLine, encoding = "utf-8") {
102
+ const content = (await context.fsOperator.readFile(filePath, encoding)).toString();
103
+ const lines = content.split("\n");
104
+ const originalLineCount = lines.length;
105
+ // Handle line range
106
+ const actualStartLine = Math.max((startLine || 1) - 1, 0); // Convert to 0-based
107
+ if (endLine === undefined) {
108
+ const actualLineCount = lineCount || Math.min(DEFAULT_MAX_LINES, originalLineCount);
109
+ endLine = Math.min(actualStartLine + actualLineCount, originalLineCount);
110
+ }
111
+ if (endLine < 0) {
112
+ endLine += originalLineCount + 1;
113
+ }
114
+ const selectedLines = lines.slice(actualStartLine, endLine);
115
+ // Truncate long lines
116
+ let linesWereTruncated = false;
117
+ const processedLines = selectedLines.map((line) => {
118
+ if (line.length > MAX_LINE_LENGTH) {
119
+ linesWereTruncated = true;
120
+ return line.substring(0, MAX_LINE_LENGTH) + "... [line truncated]";
121
+ }
122
+ return line;
123
+ });
124
+ const contentWasTruncated = endLine < originalLineCount;
125
+ const isTruncated = contentWasTruncated || linesWereTruncated;
126
+ let processedContent = catWithLineNumbers(processedLines.join("\n"), actualStartLine);
127
+ // Add truncation notice
128
+ if (contentWasTruncated) {
129
+ processedContent =
130
+ `[Content truncated: showing lines ${actualStartLine + 1}-${endLine} of ${originalLineCount} total lines]\n\n` + processedContent;
131
+ }
132
+ else if (linesWereTruncated) {
133
+ processedContent =
134
+ `[Some lines truncated due to length (max ${MAX_LINE_LENGTH} chars)]\n\n` +
135
+ processedContent;
136
+ }
137
+ return {
138
+ content: processedContent,
139
+ metadata: {
140
+ lineCount: originalLineCount,
141
+ isTruncated,
142
+ linesShown: [actualStartLine + 1, endLine],
143
+ },
144
+ };
145
+ }
146
+ /**
147
+ * Process image or PDF file
148
+ */
149
+ async function processMediaFile(context, filePath, fileType) {
150
+ const buffer = await context.fsOperator.readFile(filePath);
151
+ const mimeType = mime.lookup(filePath) || "application/octet-stream";
152
+ // For SuperDesign, we'll return a descriptive message rather than raw base64
153
+ // The actual file handling would be done by the VS Code webview
154
+ const fileName = path.basename(filePath);
155
+ const fileSize = (buffer.length / 1024).toFixed(1);
156
+ return {
157
+ content: `[${fileType.toUpperCase()} FILE: ${fileName}]\nFile size: ${fileSize} KB\nMIME type: ${mimeType}\nBase64 data available for webview display.`,
158
+ metadata: {
159
+ mimeType,
160
+ },
161
+ };
162
+ }
163
+ async function read(context, params) {
164
+ const { file_path, offset: startLine, endLine, limit: lineCount, encoding = "utf-8", } = params;
165
+ const startTime = Date.now();
166
+ try {
167
+ // Validate workspace path (handles both absolute and relative paths)
168
+ const pathError = (0, utils_1.validateWorkspacePath)(file_path, context);
169
+ if (pathError) {
170
+ return pathError;
171
+ }
172
+ // Resolve file path
173
+ const absolutePath = (0, utils_1.resolveWorkspacePath)(file_path, context);
174
+ // Check file existence
175
+ const fileError = await (0, utils_1.validateFileExists)(context, absolutePath, file_path);
176
+ if (fileError) {
177
+ return fileError;
178
+ }
179
+ // Check if it's a directory
180
+ const stats = await context.fsOperator.stat(absolutePath);
181
+ if (stats.isDirectory()) {
182
+ return (0, utils_2.handleToolError)(`Path is a directory, not a file: ${file_path}`, "Path validation", "validation");
183
+ }
184
+ // Check file size
185
+ if (stats.size > MAX_FILE_SIZE_BYTES) {
186
+ const sizeMB = (stats.size / 1024 / 1024).toFixed(1);
187
+ return (0, utils_2.handleToolError)(`File too large (${sizeMB}MB). Maximum size: ${MAX_FILE_SIZE_BYTES / 1024 / 1024}MB`, "File size check", "validation");
188
+ }
189
+ // Detect file type
190
+ const fileType = detectFileType(context, absolutePath);
191
+ context.messageHandler?.currentText.append(`\n[read] Reading ${fileType} file: ${file_path} (${(stats.size / 1024).toFixed(1)} KB)`);
192
+ let content;
193
+ let metadata = {};
194
+ // Process based on file type
195
+ switch (fileType) {
196
+ case "text": {
197
+ const result = await processTextFile(context, absolutePath, startLine, endLine, lineCount, encoding);
198
+ content = result.content;
199
+ metadata = result.metadata;
200
+ break;
201
+ }
202
+ case "image":
203
+ case "pdf": {
204
+ const result = await processMediaFile(context, absolutePath, fileType);
205
+ content = result.content;
206
+ metadata = result.metadata;
207
+ break;
208
+ }
209
+ case "binary": {
210
+ const fileName = path.basename(absolutePath);
211
+ const fileSize = (stats.size / 1024).toFixed(1);
212
+ content = `[BINARY FILE: ${fileName}]\nFile size: ${fileSize} KB\nCannot display binary content as text.`;
213
+ break;
214
+ }
215
+ default:
216
+ return (0, utils_2.handleToolError)(`Unsupported file type: ${fileType}`, "File type detection", "validation");
217
+ }
218
+ // Create result
219
+ const fileReadResult = {
220
+ content,
221
+ filePath: file_path || "",
222
+ fileType,
223
+ mimeType: mime.lookup(absolutePath) || undefined,
224
+ size: stats.size,
225
+ ...metadata,
226
+ };
227
+ const duration = Date.now() - startTime;
228
+ context.messageHandler?.currentText.append(`\n[read] File read completed in ${duration}ms\n`);
229
+ return (0, utils_1.createSuccessResponse)(fileReadResult);
230
+ }
231
+ catch (error) {
232
+ const errorMessage = error instanceof Error ? error.message : String(error);
233
+ context.messageHandler?.currentText.append(`\n[read] Read failed: ${errorMessage}\n`);
234
+ return (0, utils_2.handleToolError)(error, "Read tool execution", "execution");
235
+ }
236
+ }
237
+ function catWithLineNumbers(content, offset = 0) {
238
+ // Split by lines
239
+ const lines = content.split("\n");
240
+ // Add line numbers to each line, consistent with cat -n format
241
+ const numberedLines = lines.map((line, index) => {
242
+ const lineNumber = index + 1 + offset;
243
+ // Right-align line numbers, 6-digit width, followed by tab
244
+ return `${lineNumber.toString().padStart(6)}\t${line}`;
245
+ });
246
+ return numberedLines.join("\n");
247
+ }
248
+ /**
249
+ * Create SuperDesign read tool with execution context
250
+ */
251
+ function createReadTool(context) {
252
+ return (0, utils_2.tool)((params) => read(context, params), {
253
+ name: "Read",
254
+ description: "Reads a file from the local filesystem. You can access any file directly by using this tool.\nAssume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.\n\nUsage:\n- The file_path parameter must be an absolute path, not a relative path\n- By default, it reads up to 2000 lines starting from the beginning of the file\n- You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters\n- Any lines longer than 2000 characters will be truncated\n- Results are returned using cat -n format, with line numbers starting at 1\n- You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful. \n- If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.",
255
+ schema: v4_1.z.object({
256
+ file_path: v4_1.z.string().describe("The absolute path to the file to read"),
257
+ offset: v4_1.z
258
+ .number()
259
+ .optional()
260
+ .describe("Optional: The number of lines to read. Only provide if the file is too large to read at once."),
261
+ limit: v4_1.z
262
+ .number()
263
+ .optional()
264
+ .describe("Optional: The line number to start reading from. Only provide if the file is too large to read at once"),
265
+ }),
266
+ getDisplay: ({ name, input }) => {
267
+ return `> Using ${name} for tool call: ${input.file_path || ""}`;
268
+ },
269
+ });
270
+ }
271
+ //# sourceMappingURL=read-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-tool.js","sourceRoot":"","sources":["../../src/fs/read-tool.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2LA,oBAkIC;AAmBD,wCAwBC;AAxWD,2CAA6B;AAC7B,iDAAmC;AAEnC,+BAA2B;AAC3B,mCAMiB;AACjB,oCAA6D;AAgB7D,gCAAgC;AAChC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAC/B,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO;AAErD;;GAEG;AACH,SAAS,cAAc,CACrB,OAAO,EACP,QAAgB;IAEhB,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IACjD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AiiC;QACniC,MAAM,EAAE,MAAC,CAAC,MAAM,CAAC;YACf,SAAS,EAAE,MAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,uCAAuC,CAAC;YACvE,MAAM,EAAE,MAAC;iBACN,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CACP,+FAA+F,CAChG;YACH,KAAK,EAAE,MAAC;iBACL,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CACP,wGAAwG,CACzG;SACJ,CAAC;QACF,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;YAC9B,OAAO,WAAW,IAAI,mBAAmB,KAAK,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC;QACnE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { z } from "zod/v4";
2
+ import { ExecutionContext } from "./utils";
3
+ import { IFileReadResult } from "./read-tool";
4
+ import { IFileWriteResult } from "./write-tool";
5
+ import { IFileEditResult } from "./edit-tool";
6
+ type StrReplaceEditorResult = IFileReadResult | IFileWriteResult | IFileEditResult;
7
+ export declare function createStrReplaceEditorTool(context: ExecutionContext): import("../utils").DynamicTool<z.ZodObject<{
8
+ command: z.ZodEnum<{
9
+ grep: "grep";
10
+ view: "view";
11
+ str_replace: "str_replace";
12
+ create: "create";
13
+ insert: "insert";
14
+ }>;
15
+ path: z.ZodString;
16
+ view_range: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
17
+ old_str: z.ZodOptional<z.ZodString>;
18
+ new_str: z.ZodOptional<z.ZodString>;
19
+ file_text: z.ZodOptional<z.ZodString>;
20
+ insert_line: z.ZodOptional<z.ZodNumber>;
21
+ }, z.core.$strip>, Record<string, unknown>, StrReplaceEditorResult>;
22
+ export {};
23
+ //# sourceMappingURL=str-replace-editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"str-replace-editor.d.ts","sourceRoot":"","sources":["../../src/fs/str-replace-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAQ,eAAe,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAS,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAY,eAAe,EAAE,MAAM,aAAa,CAAC;AAIxD,KAAK,sBAAsB,GACvB,eAAe,GACf,gBAAgB,GAChB,eAAe,CAAC;AAmCpB,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,gBAAgB;;;;;;;;;;;;;;oEAwFnE"}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStrReplaceEditorTool = createStrReplaceEditorTool;
4
+ const v4_1 = require("zod/v4");
5
+ const read_tool_1 = require("./read-tool");
6
+ const write_tool_1 = require("./write-tool");
7
+ const edit_tool_1 = require("./edit-tool");
8
+ const utils_1 = require("../utils");
9
+ function createStrReplaceEditorTool(context) {
10
+ return (0, utils_1.tool)(async ({ command, path, view_range = [], old_str, new_str, file_text, insert_line, }) => {
11
+ switch (command) {
12
+ case "view":
13
+ const [startLine = 0, endLine = -1] = view_range;
14
+ return (0, read_tool_1.read)(context, { file_path: path, offset: startLine, endLine });
15
+ case "str_replace":
16
+ return (0, edit_tool_1.editFile)(context, {
17
+ file_path: path,
18
+ old_string: old_str,
19
+ new_string: new_str,
20
+ });
21
+ case "create":
22
+ return (0, write_tool_1.write)(context, { file_path: path, content: file_text });
23
+ case "insert": {
24
+ const content = (await context.fsOperator.readFile(path, "utf-8")).toString();
25
+ const lines = content.split("\n");
26
+ if (insert_line != undefined && insert_line <= lines.length) {
27
+ lines.splice(insert_line + 1, 0, new_str || "");
28
+ }
29
+ return (0, write_tool_1.write)(context, { file_path: path, content: lines.join("\n") });
30
+ }
31
+ default:
32
+ return {
33
+ success: false,
34
+ error: `Unknown command: ${command}`,
35
+ };
36
+ }
37
+ }, {
38
+ name: "str-replace-editor",
39
+ description: "Text editor tool to view and modify text files, helping you debug, fix, and improve code or other text documents.Common indicates the operation type. Different commons require different parameters.",
40
+ schema: v4_1.z.object({
41
+ command: v4_1.z.enum(["view", "str_replace", "create", "insert", "grep"])
42
+ .describe(`Edit type,Must be one of:
43
+ 1. view: Examine the contents of a file or list the contents of a directory. It can read the entire file or a specific range of lines
44
+ 2. str_replace: Replace a specific string in a file with a new string. This is used for making precise edits.
45
+ 3. create: Create a new file with specified content.
46
+ 4. insert: Insert text at a specific location in a file.
47
+ 5. grep: Search for text patterns within file contents using regular expressions. Can filter by file types and paths.`),
48
+ path: v4_1.z.string().describe("The path to the file or directory to view."),
49
+ view_range: v4_1.z
50
+ .array(v4_1.z.number())
51
+ .min(2)
52
+ .max(2)
53
+ .optional()
54
+ .describe("Optional: An array of two integers specifying the start and end line numbers to view. Line numbers are 1-indexed, and -1 for the end line means read to the end of the file. This parameter only applies when viewing files, not directories."),
55
+ old_str: v4_1.z
56
+ .string()
57
+ .optional()
58
+ .describe("The text to replace (must match exactly, including whitespace and indentation). Is required when command is str_replace."),
59
+ new_str: v4_1.z
60
+ .string()
61
+ .optional()
62
+ .describe("The new text to insert in place of the old text. Is required when command is str_replace or insert."),
63
+ file_text: v4_1.z
64
+ .string()
65
+ .optional()
66
+ .describe("The content to write to the new file. Is required when command is create."),
67
+ insert_line: v4_1.z
68
+ .number()
69
+ .optional()
70
+ .describe("The line number after which to insert the text (0 for beginning of file). Is required when command is insert."),
71
+ }),
72
+ });
73
+ }
74
+ //# sourceMappingURL=str-replace-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"str-replace-editor.js","sourceRoot":"","sources":["../../src/fs/str-replace-editor.ts"],"names":[],"mappings":";;AA8CA,gEAwFC;AAtID,+BAA2B;AAE3B,2CAAoD;AACpD,6CAAuD;AACvD,2CAAwD;AACxD,oCAA4C;AAyC5C,SAAgB,0BAA0B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AAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACxE,CAAC;YACD;gBACE,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,oBAAoB,OAAO,EAAE;iBACrC,CAAC;QACN,CAAC;IACH,CAAC,EACD;QACE,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EACT,uMAAuM;QACzM,MAAM,EAAE,MAAC,CAAC,MAAM,CAAC;YACf,OAAO,EAAE,MAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;iBACjE,QAAQ,CAAC;;;;;sHAKkG,CAAC;YAC/G,IAAI,EAAE,MAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;YACvE,UAAU,EAAE,MAAC;iBACV,KAAK,CAAC,MAAC,CAAC,MAAM,EAAE,CAAC;iBACjB,GAAG,CAAC,CAAC,CAAC;iBACN,GAAG,CAAC,CAAC,CAAC;iBACN,QAAQ,EAAE;iBACV,QAAQ,CACP,+OAA+O,CAChP;YACH,OAAO,EAAE,MAAC;iBACP,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CACP,0HAA0H,CAC3H;YACH,OAAO,EAAE,MAAC;iBACP,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CACP,qGAAqG,CACtG;YACH,SAAS,EAAE,MAAC;iBACT,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CACP,2EAA2E,CAC5E;YACH,WAAW,EAAE,MAAC;iBACX,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CACP,+GAA+G,CAChH;SACJ,CAAC;KACH,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { ExecutionContext } from "./utils";
2
+ import { BaseToolkit, BaseTool } from "../utils";
3
+ import { IToolkitOptions } from "../types/index";
4
+ /**
5
+ * Configuration options for FilesystemToolkit
6
+ */
7
+ export interface FilesystemToolkitConfig {
8
+ /**
9
+ * Mode for file editing operations
10
+ * - 'integrated': Use str-replace-editor tool (single tool for read/write/edit operations)
11
+ * - 'atomic': Use separate read, write, and edit tools
12
+ */
13
+ mode: "integrated" | "atomic";
14
+ }
15
+ /**
16
+ * Options for creating FilesystemToolkit
17
+ */
18
+ export interface FilesystemToolkitOptions extends IToolkitOptions {
19
+ context: ExecutionContext;
20
+ config?: FilesystemToolkitConfig;
21
+ }
22
+ /**
23
+ * FilesystemToolkit provides a comprehensive set of file system tools
24
+ * with configurable modes for different use cases.
25
+ */
26
+ export declare class FilesystemToolkit extends BaseToolkit {
27
+ context: ExecutionContext;
28
+ private config;
29
+ constructor(options: FilesystemToolkitOptions);
30
+ /**
31
+ * Initialize toolkit and add tools
32
+ */
33
+ protected onInitialize(): Promise<void>;
34
+ /**
35
+ * Initialize tools based on configuration
36
+ */
37
+ private initializeTools;
38
+ /**
39
+ * Get tools by category
40
+ */
41
+ getFileOperationTools(): BaseTool[];
42
+ /**
43
+ * Get utility tools (glob, grep, ls)
44
+ */
45
+ getUtilityTools(): BaseTool[];
46
+ /**
47
+ * Get current configuration
48
+ */
49
+ getConfig(): FilesystemToolkitConfig;
50
+ /**
51
+ * Switch between integrated and atomic modes
52
+ */
53
+ switchMode(mode: "integrated" | "atomic"): void;
54
+ /**
55
+ * Get toolkit statistics
56
+ */
57
+ getStats(): {
58
+ mode: string;
59
+ };
60
+ }
61
+ //# sourceMappingURL=toolkit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolkit.d.ts","sourceRoot":"","sources":["../../src/fs/toolkit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAQ3C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,eAAe;IAC/D,OAAO,EAAE,gBAAgB,CAAC;IAC1B,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAClC;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;IACzC,OAAO,EAAE,gBAAgB,CAG9B;IACF,OAAO,CAAC,MAAM,CAA0B;gBAE5B,OAAO,EAAE,wBAAwB;IAoB7C;;OAEG;cACa,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7C;;OAEG;IACH,OAAO,CAAC,eAAe;IAkCvB;;OAEG;IACH,qBAAqB,IAAI,QAAQ,EAAE;IAYnC;;OAEG;IACH,eAAe,IAAI,QAAQ,EAAE;IAM7B;;OAEG;IACH,SAAS,IAAI,uBAAuB;IAIpC;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,QAAQ,GAAG,IAAI;IAO/C;;OAEG;IACH,QAAQ,IAAI;QACV,IAAI,EAAE,MAAM,CAAC;KACd;CAKF"}