@vegamo/loom 0.1.1

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 (196) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +465 -0
  3. package/dist/agents/core/agent.d.ts +65 -0
  4. package/dist/agents/core/agent.d.ts.map +1 -0
  5. package/dist/agents/core/agent.js +277 -0
  6. package/dist/agents/core/agent.js.map +1 -0
  7. package/dist/agents/core/prompt.d.ts +11 -0
  8. package/dist/agents/core/prompt.d.ts.map +1 -0
  9. package/dist/agents/core/prompt.js +117 -0
  10. package/dist/agents/core/prompt.js.map +1 -0
  11. package/dist/agents/core/types.d.ts +49 -0
  12. package/dist/agents/core/types.d.ts.map +1 -0
  13. package/dist/agents/core/types.js +5 -0
  14. package/dist/agents/core/types.js.map +1 -0
  15. package/dist/agents/memory/memory.d.ts +62 -0
  16. package/dist/agents/memory/memory.d.ts.map +1 -0
  17. package/dist/agents/memory/memory.js +113 -0
  18. package/dist/agents/memory/memory.js.map +1 -0
  19. package/dist/agents/memory/types.d.ts +15 -0
  20. package/dist/agents/memory/types.d.ts.map +1 -0
  21. package/dist/agents/memory/types.js +5 -0
  22. package/dist/agents/memory/types.js.map +1 -0
  23. package/dist/index.d.ts +13 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +104 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/llm/client.d.ts +49 -0
  28. package/dist/llm/client.d.ts.map +1 -0
  29. package/dist/llm/client.js +256 -0
  30. package/dist/llm/client.js.map +1 -0
  31. package/dist/llm/config.d.ts +13 -0
  32. package/dist/llm/config.d.ts.map +1 -0
  33. package/dist/llm/config.js +50 -0
  34. package/dist/llm/config.js.map +1 -0
  35. package/dist/llm/types.d.ts +74 -0
  36. package/dist/llm/types.d.ts.map +1 -0
  37. package/dist/llm/types.js +17 -0
  38. package/dist/llm/types.js.map +1 -0
  39. package/dist/mocks/generator.d.ts +10 -0
  40. package/dist/mocks/generator.d.ts.map +1 -0
  41. package/dist/mocks/generator.js +19 -0
  42. package/dist/mocks/generator.js.map +1 -0
  43. package/dist/mocks/router.d.ts +13 -0
  44. package/dist/mocks/router.d.ts.map +1 -0
  45. package/dist/mocks/router.js +44 -0
  46. package/dist/mocks/router.js.map +1 -0
  47. package/dist/mocks/server.d.ts +21 -0
  48. package/dist/mocks/server.d.ts.map +1 -0
  49. package/dist/mocks/server.js +36 -0
  50. package/dist/mocks/server.js.map +1 -0
  51. package/dist/serve.d.ts +17 -0
  52. package/dist/serve.d.ts.map +1 -0
  53. package/dist/serve.js +56 -0
  54. package/dist/serve.js.map +1 -0
  55. package/dist/shared/config-wizard.d.ts +7 -0
  56. package/dist/shared/config-wizard.d.ts.map +1 -0
  57. package/dist/shared/config-wizard.js +84 -0
  58. package/dist/shared/config-wizard.js.map +1 -0
  59. package/dist/shared/config.d.ts +32 -0
  60. package/dist/shared/config.d.ts.map +1 -0
  61. package/dist/shared/config.js +77 -0
  62. package/dist/shared/config.js.map +1 -0
  63. package/dist/shared/entity-utils.d.ts +30 -0
  64. package/dist/shared/entity-utils.d.ts.map +1 -0
  65. package/dist/shared/entity-utils.js +207 -0
  66. package/dist/shared/entity-utils.js.map +1 -0
  67. package/dist/shared/logger.d.ts +13 -0
  68. package/dist/shared/logger.d.ts.map +1 -0
  69. package/dist/shared/logger.js +45 -0
  70. package/dist/shared/logger.js.map +1 -0
  71. package/dist/shared/manifest-utils.d.ts +9 -0
  72. package/dist/shared/manifest-utils.d.ts.map +1 -0
  73. package/dist/shared/manifest-utils.js +110 -0
  74. package/dist/shared/manifest-utils.js.map +1 -0
  75. package/dist/shared/schema-entity-resolver.d.ts +15 -0
  76. package/dist/shared/schema-entity-resolver.d.ts.map +1 -0
  77. package/dist/shared/schema-entity-resolver.js +134 -0
  78. package/dist/shared/schema-entity-resolver.js.map +1 -0
  79. package/dist/shared/schema-utils.d.ts +21 -0
  80. package/dist/shared/schema-utils.d.ts.map +1 -0
  81. package/dist/shared/schema-utils.js +56 -0
  82. package/dist/shared/schema-utils.js.map +1 -0
  83. package/dist/shared/types.d.ts +130 -0
  84. package/dist/shared/types.d.ts.map +1 -0
  85. package/dist/shared/types.js +5 -0
  86. package/dist/shared/types.js.map +1 -0
  87. package/dist/tools/entity-file-ops.d.ts +10 -0
  88. package/dist/tools/entity-file-ops.d.ts.map +1 -0
  89. package/dist/tools/entity-file-ops.js +183 -0
  90. package/dist/tools/entity-file-ops.js.map +1 -0
  91. package/dist/tools/entity-workflow.d.ts +10 -0
  92. package/dist/tools/entity-workflow.d.ts.map +1 -0
  93. package/dist/tools/entity-workflow.js +447 -0
  94. package/dist/tools/entity-workflow.js.map +1 -0
  95. package/dist/tools/file-ops.d.ts +9 -0
  96. package/dist/tools/file-ops.d.ts.map +1 -0
  97. package/dist/tools/file-ops.js +83 -0
  98. package/dist/tools/file-ops.js.map +1 -0
  99. package/dist/tools/registry.d.ts +31 -0
  100. package/dist/tools/registry.d.ts.map +1 -0
  101. package/dist/tools/registry.js +58 -0
  102. package/dist/tools/registry.js.map +1 -0
  103. package/dist/tools/schema-gen.d.ts +8 -0
  104. package/dist/tools/schema-gen.d.ts.map +1 -0
  105. package/dist/tools/schema-gen.js +82 -0
  106. package/dist/tools/schema-gen.js.map +1 -0
  107. package/dist/tools/schema-validate.d.ts +8 -0
  108. package/dist/tools/schema-validate.d.ts.map +1 -0
  109. package/dist/tools/schema-validate.js +79 -0
  110. package/dist/tools/schema-validate.js.map +1 -0
  111. package/dist/tools/types.d.ts +29 -0
  112. package/dist/tools/types.d.ts.map +1 -0
  113. package/dist/tools/types.js +5 -0
  114. package/dist/tools/types.js.map +1 -0
  115. package/dist/tui/app.d.ts +13 -0
  116. package/dist/tui/app.d.ts.map +1 -0
  117. package/dist/tui/app.js +357 -0
  118. package/dist/tui/app.js.map +1 -0
  119. package/dist/tui/components/Chat.d.ts +14 -0
  120. package/dist/tui/components/Chat.d.ts.map +1 -0
  121. package/dist/tui/components/Chat.js +24 -0
  122. package/dist/tui/components/Chat.js.map +1 -0
  123. package/dist/tui/components/Header.d.ts +14 -0
  124. package/dist/tui/components/Header.d.ts.map +1 -0
  125. package/dist/tui/components/Header.js +6 -0
  126. package/dist/tui/components/Header.js.map +1 -0
  127. package/dist/tui/components/Input.d.ts +15 -0
  128. package/dist/tui/components/Input.d.ts.map +1 -0
  129. package/dist/tui/components/Input.js +74 -0
  130. package/dist/tui/components/Input.js.map +1 -0
  131. package/dist/tui/components/SchemaPreview.d.ts +13 -0
  132. package/dist/tui/components/SchemaPreview.d.ts.map +1 -0
  133. package/dist/tui/components/SchemaPreview.js +9 -0
  134. package/dist/tui/components/SchemaPreview.js.map +1 -0
  135. package/dist/tui/components/StatusBar.d.ts +15 -0
  136. package/dist/tui/components/StatusBar.d.ts.map +1 -0
  137. package/dist/tui/components/StatusBar.js +7 -0
  138. package/dist/tui/components/StatusBar.js.map +1 -0
  139. package/dist/tui/hooks/useAgent.d.ts +41 -0
  140. package/dist/tui/hooks/useAgent.d.ts.map +1 -0
  141. package/dist/tui/hooks/useAgent.js +180 -0
  142. package/dist/tui/hooks/useAgent.js.map +1 -0
  143. package/dist/view/frontend/components/App.d.ts +4 -0
  144. package/dist/view/frontend/components/App.d.ts.map +1 -0
  145. package/dist/view/frontend/components/App.js +35 -0
  146. package/dist/view/frontend/components/App.js.map +1 -0
  147. package/dist/view/frontend/components/EndpointDetailPage.d.ts +4 -0
  148. package/dist/view/frontend/components/EndpointDetailPage.d.ts.map +1 -0
  149. package/dist/view/frontend/components/EndpointDetailPage.js +103 -0
  150. package/dist/view/frontend/components/EndpointDetailPage.js.map +1 -0
  151. package/dist/view/frontend/components/HomePage.d.ts +4 -0
  152. package/dist/view/frontend/components/HomePage.d.ts.map +1 -0
  153. package/dist/view/frontend/components/HomePage.js +6 -0
  154. package/dist/view/frontend/components/HomePage.js.map +1 -0
  155. package/dist/view/frontend/components/ModuleDetailPage.d.ts +4 -0
  156. package/dist/view/frontend/components/ModuleDetailPage.d.ts.map +1 -0
  157. package/dist/view/frontend/components/ModuleDetailPage.js +64 -0
  158. package/dist/view/frontend/components/ModuleDetailPage.js.map +1 -0
  159. package/dist/view/frontend/components/ModulesPage.d.ts +4 -0
  160. package/dist/view/frontend/components/ModulesPage.d.ts.map +1 -0
  161. package/dist/view/frontend/components/ModulesPage.js +40 -0
  162. package/dist/view/frontend/components/ModulesPage.js.map +1 -0
  163. package/dist/view/frontend/index.d.ts +2 -0
  164. package/dist/view/frontend/index.d.ts.map +1 -0
  165. package/dist/view/frontend/index.js +15 -0
  166. package/dist/view/frontend/index.js.map +1 -0
  167. package/dist/view/frontend/types.d.ts +35 -0
  168. package/dist/view/frontend/types.d.ts.map +1 -0
  169. package/dist/view/frontend/types.js +2 -0
  170. package/dist/view/frontend/types.js.map +1 -0
  171. package/dist/view/frontend/utils/api.d.ts +5 -0
  172. package/dist/view/frontend/utils/api.d.ts.map +1 -0
  173. package/dist/view/frontend/utils/api.js +28 -0
  174. package/dist/view/frontend/utils/api.js.map +1 -0
  175. package/dist/view/public/bundle.js +104633 -0
  176. package/dist/view/public/bundle.js.map +7 -0
  177. package/dist/view/public/index.html +50 -0
  178. package/dist/view/routes/docs.d.ts +13 -0
  179. package/dist/view/routes/docs.d.ts.map +1 -0
  180. package/dist/view/routes/docs.js +53 -0
  181. package/dist/view/routes/docs.js.map +1 -0
  182. package/dist/view/routes/entities.d.ts +11 -0
  183. package/dist/view/routes/entities.d.ts.map +1 -0
  184. package/dist/view/routes/entities.js +39 -0
  185. package/dist/view/routes/entities.js.map +1 -0
  186. package/dist/view/routes/schema.d.ts +11 -0
  187. package/dist/view/routes/schema.d.ts.map +1 -0
  188. package/dist/view/routes/schema.js +43 -0
  189. package/dist/view/routes/schema.js.map +1 -0
  190. package/dist/view/server.d.ts +20 -0
  191. package/dist/view/server.d.ts.map +1 -0
  192. package/dist/view/server.js +54 -0
  193. package/dist/view/server.js.map +1 -0
  194. package/docgen.config.json +19 -0
  195. package/docgen.config.json.example +19 -0
  196. package/package.json +79 -0
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2025 Loom Contributors
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,465 @@
1
+ # Loom
2
+
3
+ <div align="center">
4
+
5
+ AI-powered JSON Schema document generator with TUI, web viewer and mock server
6
+
7
+ [![Node.js](https://img.shields.io/badge/Node.js-≥18.0.0-green)](https://nodejs.org/)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue)](https://www.typescriptlang.org/)
9
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](LICENSE)
10
+
11
+ </div>
12
+
13
+ ## ✨ Features
14
+
15
+ - **🤖 AI-Powered Schema Generation** - Interactive TUI chat interface to generate and update JSON Schema API documentation using LLMs (DeepSeek, OpenAI)
16
+ - **🧩 Entity-Centric Modeling** - Manage reusable entity schemas in `docs/entities` and reference them in endpoint schemas via `x-entity-ref`
17
+ - **📚 Modern Web Viewer** - React-based SPA for browsing modules, endpoints, and entities with interactive schema rendering
18
+ - **⚡ Mock Server** - Dynamic mock API server that generates realistic test data based on JSON Schema
19
+ - **🖥️ In-Chat Service Control** - Start/stop/restart mock server and web viewer directly inside TUI (`/mock`, `/view`)
20
+ - **🗂️ Manifest Indexing** - Built-in manifest rebuild command for dependency/index consistency (`loom manifest rebuild`)
21
+ - **🔧 TypeScript First** - Fully typed with modern TypeScript architecture
22
+
23
+ ## 📦 Installation
24
+
25
+ ### Prerequisites
26
+ - Node.js ≥ 18.0.0
27
+ - npm or yarn
28
+ - DeepSeek API key (for chat functionality)
29
+
30
+ ### Global Installation
31
+ ```bash
32
+ npm install -g loom
33
+ # or
34
+ yarn global add loom
35
+ ```
36
+
37
+ ### Local Development
38
+ ```bash
39
+ git clone <repository-url>
40
+ cd loom
41
+ npm install
42
+ npm run build:all
43
+ ```
44
+
45
+ ## ⚙️ Configuration
46
+
47
+ ### Configuration File
48
+ Loom now uses only `loom.config.json` (no `.env` dependency).
49
+
50
+ When you run `loom chat` for the first time, it will guide you to create/update this file interactively.
51
+
52
+ Default chat onboarding values:
53
+ - `provider`: `deepseek`
54
+ - `model`: `deepseek-chat`
55
+ - `baseURL`: `https://api.deepseek.com/v1`
56
+ - `apiKey`: required, must be entered by user
57
+
58
+ You can also create `loom.config.json` manually:
59
+ ```json
60
+ {
61
+ "outDir": "docs",
62
+ "llm": {
63
+ "provider": "deepseek",
64
+ "model": "deepseek-chat",
65
+ "baseURL": "https://api.deepseek.com/v1",
66
+ "apiKey": "your_deepseek_api_key",
67
+ "temperature": 0.7,
68
+ "maxTokens": 2000
69
+ },
70
+ "serve": {
71
+ "port": 3000,
72
+ "host": "0.0.0.0"
73
+ },
74
+ "mock": {
75
+ "port": 3001,
76
+ "host": "0.0.0.0"
77
+ }
78
+ }
79
+ ```
80
+
81
+ ## 🚀 Quick Start
82
+
83
+ ### 1. Generate API Documentation
84
+ ```bash
85
+ # Start interactive TUI to generate JSON Schema
86
+ loom chat
87
+
88
+ # Or specify project directory
89
+ loom chat --dir ./my-api-project
90
+ ```
91
+
92
+ In `loom chat`, you can also control local services:
93
+ - `/mock`, `/mock stop`, `/mock restart [port]`
94
+ - `/view`, `/view stop`, `/view restart [port]`
95
+
96
+ ### 2. View Documentation
97
+ ```bash
98
+ # Start web documentation viewer
99
+ loom view
100
+
101
+ # Or with custom port
102
+ loom view --port 8080
103
+ ```
104
+
105
+ ### 3. Start Mock Server
106
+ ```bash
107
+ # Start mock API server
108
+ loom mock
109
+
110
+ # Or with custom port
111
+ loom mock --port 8081
112
+ ```
113
+
114
+ ### 4. Combined Service (Recommended)
115
+ ```bash
116
+ # Start both viewer and mock server on same port
117
+ loom serve
118
+
119
+ # Access at:
120
+ # - Web Viewer: http://localhost:3000
121
+ # - Mock API: http://localhost:3000/mock/...
122
+ ```
123
+
124
+ ## 📖 Usage Guide
125
+
126
+ ### `loom chat`
127
+ Interactive terminal UI for generating JSON Schema documents through AI conversation.
128
+
129
+ ```bash
130
+ loom chat [options]
131
+
132
+ Options:
133
+ -d, --dir <path> Target project directory (default: current directory)
134
+ -h, --help Display help
135
+ ```
136
+
137
+ **Example Workflow:**
138
+ 1. Run `loom chat`
139
+ 2. Describe your API endpoints in natural language
140
+ 3. AI generates JSON Schema with proper structure
141
+ 4. Schema files are saved to `docs/` directory (configurable)
142
+
143
+ **Built-in chat commands:**
144
+ - `/help` — Show command help
145
+ - `/reset` — Reset conversation history
146
+ - `/list` — List generated schema files
147
+ - `/mock`, `/mock stop`, `/mock restart [port]` — Manage mock server
148
+ - `/view`, `/view stop`, `/view restart [port]` — Manage web viewer
149
+ - `/abort` — Abort current request
150
+ - `/exit` — Exit Loom
151
+
152
+ ### `loom view`
153
+ Modern web-based documentation viewer with React SPA interface.
154
+
155
+ ```bash
156
+ loom view [options]
157
+
158
+ Options:
159
+ -p, --port <number> Port number (default: 3000)
160
+ -d, --dir <path> Target project directory (default: current directory)
161
+ -h, --help Display help
162
+ ```
163
+
164
+ **Features:**
165
+ - 📁 Module browsing with endpoint counts
166
+ - 🧩 Entity browsing from `docs/entities`
167
+ - 🔍 Real-time search across modules and endpoints
168
+ - 📊 Interactive JSON schema viewer with expand/collapse
169
+ - 🔗 `x-entity-ref` auto-resolve in endpoint request/response rendering
170
+ - 🎨 Clean, responsive UI with dark sidebar
171
+ - 🔗 Direct links to specific endpoints
172
+
173
+ ### `loom mock`
174
+ Dynamic mock API server that generates realistic data based on JSON Schema.
175
+
176
+ ```bash
177
+ loom mock [options]
178
+
179
+ Options:
180
+ -p, --port <number> Port number (default: 3001)
181
+ -d, --dir <path> Target project directory (default: current directory)
182
+ -h, --help Display help
183
+ ```
184
+
185
+ **Features:**
186
+ - 🚀 Automatic route registration from JSON Schema files
187
+ - 🎲 Smart mock data generation using mock-json-schema
188
+ - 📡 Support for all HTTP methods (GET, POST, PUT, DELETE, PATCH)
189
+ - 🔧 Configurable response status codes and schemas
190
+
191
+ ### `loom serve`
192
+ Combined service that runs both web viewer and mock server together.
193
+
194
+ ```bash
195
+ loom serve [options]
196
+
197
+ Options:
198
+ -p, --port <number> Port number (default: 3000)
199
+ -d, --dir <path> Target project directory (default: current directory)
200
+ -h, --help Display help
201
+ ```
202
+
203
+ **URL Structure:**
204
+ - `http://localhost:3000/` - Web documentation viewer
205
+ - `http://localhost:3000/api/docs` - Documentation API
206
+ - `http://localhost:3000/api/schemas` - Schema file API
207
+ - `http://localhost:3000/api/entities` - Entity file API
208
+ - `http://localhost:3000/mock/...` - Mock API endpoints
209
+
210
+ ### `loom manifest rebuild`
211
+ Rebuild docs manifest index file (`.loom-manifest.json`) for dependency/index consistency.
212
+
213
+ ```bash
214
+ loom manifest rebuild [options]
215
+
216
+ Options:
217
+ -d, --dir <path> Target project directory (default: current directory)
218
+ -h, --help Display help
219
+ ```
220
+
221
+ ## 📝 JSON Schema Format
222
+
223
+ Loom uses a custom JSON Schema format optimized for API documentation:
224
+
225
+ ```json
226
+ {
227
+ "$schema": "http://json-schema.org/draft-07/schema#",
228
+ "title": "Authentication API",
229
+ "description": "User authentication endpoints",
230
+ "version": "1.0.0",
231
+ "endpoints": [
232
+ {
233
+ "path": "/api/auth/login",
234
+ "method": "POST",
235
+ "summary": "User login",
236
+ "description": "Authenticate user with credentials",
237
+ "tags": ["auth"],
238
+ "request": {
239
+ "headers": {
240
+ "Content-Type": { "type": "string", "enum": ["application/json"] }
241
+ },
242
+ "body": {
243
+ "type": "object",
244
+ "properties": {
245
+ "username": { "type": "string" },
246
+ "password": { "type": "string" }
247
+ },
248
+ "required": ["username", "password"]
249
+ }
250
+ },
251
+ "response": {
252
+ "200": {
253
+ "type": "object",
254
+ "properties": {
255
+ "token": { "type": "string" },
256
+ "user": { "type": "object" }
257
+ }
258
+ },
259
+ "400": {
260
+ "type": "object",
261
+ "properties": {
262
+ "error": { "type": "string" }
263
+ }
264
+ }
265
+ }
266
+ }
267
+ ]
268
+ }
269
+ ```
270
+
271
+ ### Schema Structure
272
+ - **title**: API module title
273
+ - **description**: Module description
274
+ - **endpoints**: Array of API endpoint definitions
275
+ - **endpoint.path**: URL path (supports path parameters)
276
+ - **endpoint.method**: HTTP method (GET, POST, PUT, DELETE, PATCH)
277
+ - **endpoint.request**: Optional request schema (headers, params, query, body)
278
+ - **endpoint.response**: Response schemas keyed by status code
279
+
280
+ ## 🧩 Entity Schema & References
281
+
282
+ Loom supports reusable entity schemas in:
283
+
284
+ ```text
285
+ docs/entities/*.entity.schema.json
286
+ ```
287
+
288
+ Example entity file:
289
+
290
+ ```json
291
+ {
292
+ "$schema": "http://json-schema.org/draft-07/schema#",
293
+ "title": "User",
294
+ "description": "Reusable user entity",
295
+ "type": "object",
296
+ "properties": {
297
+ "id": { "type": "integer" },
298
+ "name": { "type": "string" },
299
+ "email": { "type": "string", "format": "email" }
300
+ },
301
+ "required": ["id", "name", "email"]
302
+ }
303
+ ```
304
+
305
+ In endpoint schemas, reference an entity with `x-entity-ref`:
306
+
307
+ ```json
308
+ {
309
+ "user": {
310
+ "x-entity-ref": {
311
+ "entity": "User",
312
+ "pick": ["id", "name", "email"]
313
+ }
314
+ }
315
+ }
316
+ ```
317
+
318
+ Supported forms:
319
+ - String form: `"x-entity-ref": "User"`
320
+ - Object form: `"x-entity-ref": { "entity": "User", "pick": ["id", "name"] }`
321
+
322
+ ## 🏗️ Project Structure
323
+
324
+ ```
325
+ loom/
326
+ ├── src/
327
+ │ ├── agents/ # AI agent system with tool calling
328
+ │ │ ├── core/ # Agent core logic
329
+ │ │ └── memory/ # Conversation memory management
330
+ │ ├── llm/ # LLM client (DeepSeek, OpenAI)
331
+ │ │ ├── client.ts # Streaming LLM client
332
+ │ │ └── config.ts # LLM configuration
333
+ │ ├── tools/ # Tool system for agent
334
+ │ │ ├── schema-gen.ts # Schema generation tools
335
+ │ │ ├── schema-validate.ts # Schema validation tools
336
+ │ │ ├── file-ops.ts # Schema file operations tools
337
+ │ │ ├── entity-file-ops.ts # Entity file operations tools
338
+ │ │ └── entity-workflow.ts # Entity impact/sync/validate tools
339
+ │ ├── tui/ # Terminal UI (chat interface)
340
+ │ │ ├── app.tsx # Main TUI application
341
+ │ │ └── components/ # React components for TUI
342
+ │ ├── view/ # Web documentation viewer
343
+ │ │ ├── server.ts # Fastify web server
344
+ │ │ ├── routes/ # API routes
345
+ │ │ ├── frontend/ # React SPA frontend
346
+ │ │ └── public/ # Static assets
347
+ │ ├── mocks/ # Mock server
348
+ │ │ ├── server.ts # Mock server implementation
349
+ │ │ ├── router.ts # Dynamic route registration
350
+ │ │ └── generator.ts # Mock data generation
351
+ │ ├── shared/ # Shared utilities
352
+ │ │ ├── config.ts # Configuration loader
353
+ │ │ ├── entity-utils.ts # Entity read/write/reference helpers
354
+ │ │ ├── manifest-utils.ts # Manifest index builder
355
+ │ │ ├── schema-entity-resolver.ts # x-entity-ref resolver for viewer APIs
356
+ │ │ ├── types.ts # TypeScript definitions
357
+ │ │ └── logger.ts # Logging utilities
358
+ │ ├── serve.ts # Combined viewer + mock server
359
+ │ └── index.ts # CLI entry point
360
+ ├── docs/ # Generated schema files
361
+ ├── scripts/ # Build scripts
362
+ ├── dist/ # Compiled output
363
+ └── package.json
364
+ ```
365
+
366
+ ## 🛠️ Development
367
+
368
+ ### Building the Project
369
+ ```bash
370
+ # Build TypeScript backend
371
+ npm run build
372
+
373
+ # Build React frontend
374
+ npm run build:view
375
+
376
+ # Build both (recommended)
377
+ npm run build:all
378
+ ```
379
+
380
+ ### Development Mode
381
+ ```bash
382
+ # Start TypeScript development server
383
+ npm run dev
384
+
385
+ # Watch mode for frontend development
386
+ npm run dev:view
387
+ ```
388
+
389
+ ### Adding New Features
390
+ 1. **New LLM Provider**: Extend `src/llm/config.ts` and `src/llm/client.ts`
391
+ 2. **New Agent Tool**: Add under `src/tools/` and register in `src/agents/core/agent.ts`
392
+ 3. **UI Component**: Add to `src/view/frontend/components/`
393
+ 4. **API Endpoint**: Add to `src/view/routes/` or `src/mocks/router.ts`
394
+
395
+ ## 📦 Publishing to npm
396
+
397
+ For maintainers, to publish a new version to npm registry:
398
+
399
+ ```bash
400
+ # Login to npm (first time only)
401
+ npm login
402
+
403
+ # Update version if needed
404
+ npm version patch # or minor, major
405
+
406
+ # Build and create package
407
+ npm run build:all
408
+
409
+ # Publish to npm
410
+ npm publish
411
+
412
+ # Or publish with dry-run first
413
+ npm publish --dry-run
414
+ ```
415
+
416
+ The package includes:
417
+ - Compiled JavaScript in `dist/`
418
+ - TypeScript definitions
419
+ - Pre-built React frontend bundle
420
+ - CLI executable (`loom`)
421
+
422
+ Package configuration:
423
+ - `prepack` script ensures fresh build before packaging
424
+ - `.npmignore` excludes source files and development artifacts
425
+ - All runtime dependencies are correctly specified
426
+
427
+ ## 🤝 Contributing
428
+
429
+ Contributions are welcome! Please follow these steps:
430
+
431
+ 1. **Fork** the repository
432
+ 2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
433
+ 3. **Commit your changes**: `git commit -m 'Add amazing feature'`
434
+ 4. **Push to the branch**: `git push origin feature/amazing-feature`
435
+ 5. **Open a Pull Request**
436
+
437
+ ### Development Guidelines
438
+ - Use TypeScript with strict mode
439
+ - Follow existing code style and patterns
440
+ - Add tests for new functionality
441
+ - Update documentation as needed
442
+
443
+ ## 📄 License
444
+
445
+ This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details.
446
+
447
+ ## 🙏 Acknowledgments
448
+
449
+ - [DeepSeek](https://www.deepseek.com/) for AI capabilities
450
+ - [Fastify](https://fastify.io/) for high-performance web server
451
+ - [React](https://reactjs.org/) for UI components
452
+ - [mock-json-schema](https://github.com/anttiviljami/mock-json-schema) for mock data generation
453
+ - [Ink](https://github.com/vadimdemedes/ink) for terminal UI
454
+
455
+ ## 📞 Support
456
+
457
+ - **Issues**: [GitHub Issues](https://github.com/yourusername/loom/issues)
458
+ - **Documentation**: This README and code comments
459
+ - **Questions**: Open an issue or discussion
460
+
461
+ ---
462
+
463
+ <div align="center">
464
+ Made with ❤️ by the Loom team
465
+ </div>
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Agent 主类
3
+ *
4
+ * 核心职责: 编排 LLM 调用与 Tool 执行的循环
5
+ *
6
+ * 流程:
7
+ * 1. 接收用户输入
8
+ * 2. 构建 messages (system prompt + memory + user message)
9
+ * 3. 调用 LLM (streaming)
10
+ * 4. 如果 LLM 返回 tool_calls → 执行工具 → 将结果拼入 messages → 回到步骤 3
11
+ * 5. 如果 LLM 返回纯文本 → 返回给用户
12
+ *
13
+ * 特性:
14
+ * - 支持 streaming (逐字输出到 TUI)
15
+ * - 自动降级到非 streaming (如果 streaming 不可用)
16
+ * - 完善的错误分类和向上传播
17
+ * - 通过事件系统通知上层进度
18
+ */
19
+ import type { AgentConfig, AgentReply, AgentState, AgentEventCallback } from './types.js';
20
+ export declare class Agent {
21
+ private llm;
22
+ private tools;
23
+ private memory;
24
+ private config;
25
+ private toolContext;
26
+ private state;
27
+ private abortController;
28
+ /** 事件回调 */
29
+ onEvent?: AgentEventCallback;
30
+ /** 向后兼容的状态变更回调 */
31
+ onStateChange?: (event: {
32
+ state: AgentState;
33
+ message?: string;
34
+ toolName?: string;
35
+ }) => void;
36
+ constructor(config: AgentConfig);
37
+ /**
38
+ * 处理用户输入,返回 Agent 回复
39
+ *
40
+ * 根据 config.streaming 自动选择 streaming 或非 streaming 模式
41
+ */
42
+ chat(userMessage: string): Promise<AgentReply>;
43
+ /**
44
+ * 中断当前请求
45
+ */
46
+ abort(): void;
47
+ /**
48
+ * 重置对话
49
+ */
50
+ reset(): void;
51
+ /**
52
+ * 非 streaming LLM 调用
53
+ */
54
+ private callLLM;
55
+ /**
56
+ * Streaming LLM 调用
57
+ *
58
+ * 逐字发送 content_delta 事件到 TUI,同时累积完整响应
59
+ */
60
+ private callLLMStreaming;
61
+ private initSystemPrompt;
62
+ private setState;
63
+ private emit;
64
+ }
65
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../src/agents/core/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAkBH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAc,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAKtG,qBAAa,KAAK;IAChB,OAAO,CAAC,GAAG,CAAY;IACvB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,eAAe,CAAgC;IAEvD,WAAW;IACJ,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAEpC,kBAAkB;IACX,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,UAAU,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;gBAEvF,MAAM,EAAE,WAAW;IAmC/B;;;;OAIG;IACG,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAoJpD;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,KAAK,IAAI,IAAI;IAWb;;OAEG;YACW,OAAO;IAQrB;;;;OAIG;YACW,gBAAgB;IAsB9B,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,IAAI;CAGb"}