@agentuity/cli 2.0.11 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cmd/ai/prompt/index.d.ts.map +1 -1
- package/dist/cmd/ai/prompt/index.js +2 -7
- package/dist/cmd/ai/prompt/index.js.map +1 -1
- package/dist/cmd/build/adapters/generic.d.ts +29 -0
- package/dist/cmd/build/adapters/generic.d.ts.map +1 -0
- package/dist/cmd/build/adapters/generic.js +190 -0
- package/dist/cmd/build/adapters/generic.js.map +1 -0
- package/dist/cmd/build/adapters/index.d.ts +15 -0
- package/dist/cmd/build/adapters/index.d.ts.map +1 -0
- package/dist/cmd/build/adapters/index.js +24 -0
- package/dist/cmd/build/adapters/index.js.map +1 -0
- package/dist/cmd/build/adapters/nextjs.d.ts +11 -0
- package/dist/cmd/build/adapters/nextjs.d.ts.map +1 -0
- package/dist/cmd/build/adapters/nextjs.js +118 -0
- package/dist/cmd/build/adapters/nextjs.js.map +1 -0
- package/dist/cmd/build/adapters/static-server.d.ts +23 -0
- package/dist/cmd/build/adapters/static-server.d.ts.map +1 -0
- package/dist/cmd/build/adapters/static-server.js +137 -0
- package/dist/cmd/build/adapters/static-server.js.map +1 -0
- package/dist/cmd/build/adapters/types.d.ts +71 -0
- package/dist/cmd/build/adapters/types.d.ts.map +1 -0
- package/dist/cmd/build/adapters/types.js +8 -0
- package/dist/cmd/build/adapters/types.js.map +1 -0
- package/dist/cmd/build/detect/engine.d.ts +24 -0
- package/dist/cmd/build/detect/engine.d.ts.map +1 -0
- package/dist/cmd/build/detect/engine.js +91 -0
- package/dist/cmd/build/detect/engine.js.map +1 -0
- package/dist/cmd/build/detect/frameworks.d.ts +66 -0
- package/dist/cmd/build/detect/frameworks.d.ts.map +1 -0
- package/dist/cmd/build/detect/frameworks.js +278 -0
- package/dist/cmd/build/detect/frameworks.js.map +1 -0
- package/dist/cmd/build/detect/generic.d.ts +13 -0
- package/dist/cmd/build/detect/generic.d.ts.map +1 -0
- package/dist/cmd/build/detect/generic.js +62 -0
- package/dist/cmd/build/detect/generic.js.map +1 -0
- package/dist/cmd/build/detect/index.d.ts +27 -0
- package/dist/cmd/build/detect/index.d.ts.map +1 -0
- package/dist/cmd/build/detect/index.js +76 -0
- package/dist/cmd/build/detect/index.js.map +1 -0
- package/dist/cmd/build/detect/types.d.ts +91 -0
- package/dist/cmd/build/detect/types.d.ts.map +1 -0
- package/dist/cmd/build/detect/types.js +9 -0
- package/dist/cmd/build/detect/types.js.map +1 -0
- package/dist/cmd/build/detect/util.d.ts +41 -0
- package/dist/cmd/build/detect/util.d.ts.map +1 -0
- package/dist/cmd/build/detect/util.js +101 -0
- package/dist/cmd/build/detect/util.js.map +1 -0
- package/dist/cmd/build/index.d.ts.map +1 -1
- package/dist/cmd/build/index.js +49 -22
- package/dist/cmd/build/index.js.map +1 -1
- package/dist/cmd/build/package/index.d.ts +30 -0
- package/dist/cmd/build/package/index.d.ts.map +1 -0
- package/dist/cmd/build/package/index.js +39 -0
- package/dist/cmd/build/package/index.js.map +1 -0
- package/dist/cmd/build/package/launch.d.ts +56 -0
- package/dist/cmd/build/package/launch.d.ts.map +1 -0
- package/dist/cmd/build/package/launch.js +56 -0
- package/dist/cmd/build/package/launch.js.map +1 -0
- package/dist/cmd/build/typecheck.d.ts.map +1 -1
- package/dist/cmd/build/typecheck.js +8 -0
- package/dist/cmd/build/typecheck.js.map +1 -1
- package/dist/cmd/cloud/deploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deploy.js +63 -13
- package/dist/cmd/cloud/deploy.js.map +1 -1
- package/dist/cmd/coder/create.js +7 -7
- package/dist/cmd/coder/create.js.map +1 -1
- package/dist/cmd/coder/update.js +8 -8
- package/dist/cmd/coder/update.js.map +1 -1
- package/dist/cmd/coder/workspace/create.js +9 -9
- package/dist/cmd/coder/workspace/create.js.map +1 -1
- package/dist/cmd/dev/index.d.ts +9 -0
- package/dist/cmd/dev/index.d.ts.map +1 -1
- package/dist/cmd/dev/index.js +127 -923
- package/dist/cmd/dev/index.js.map +1 -1
- package/dist/cmd/project/auth/shared.d.ts.map +1 -1
- package/dist/cmd/project/auth/shared.js +14 -38
- package/dist/cmd/project/auth/shared.js.map +1 -1
- package/dist/cmd/project/create.d.ts.map +1 -1
- package/dist/cmd/project/create.js +12 -19
- package/dist/cmd/project/create.js.map +1 -1
- package/dist/cmd/project/frameworks-ai-examples.d.ts +15 -0
- package/dist/cmd/project/frameworks-ai-examples.d.ts.map +1 -0
- package/dist/cmd/project/frameworks-ai-examples.js +160 -0
- package/dist/cmd/project/frameworks-ai-examples.js.map +1 -0
- package/dist/cmd/project/frameworks-landing-pages.d.ts +17 -0
- package/dist/cmd/project/frameworks-landing-pages.d.ts.map +1 -0
- package/dist/cmd/project/frameworks-landing-pages.js +242 -0
- package/dist/cmd/project/frameworks-landing-pages.js.map +1 -0
- package/dist/cmd/project/frameworks.d.ts +58 -0
- package/dist/cmd/project/frameworks.d.ts.map +1 -0
- package/dist/cmd/project/frameworks.js +152 -0
- package/dist/cmd/project/frameworks.js.map +1 -0
- package/dist/cmd/project/reconcile.d.ts.map +1 -1
- package/dist/cmd/project/reconcile.js +10 -23
- package/dist/cmd/project/reconcile.js.map +1 -1
- package/dist/cmd/project/remote-import.js +1 -1
- package/dist/cmd/project/scaffold.d.ts +58 -0
- package/dist/cmd/project/scaffold.d.ts.map +1 -0
- package/dist/cmd/project/scaffold.js +223 -0
- package/dist/cmd/project/scaffold.js.map +1 -0
- package/dist/cmd/project/template-flow.d.ts +8 -4
- package/dist/cmd/project/template-flow.d.ts.map +1 -1
- package/dist/cmd/project/template-flow.js +93 -144
- package/dist/cmd/project/template-flow.js.map +1 -1
- package/dist/deploy-metadata.d.ts +49 -0
- package/dist/deploy-metadata.d.ts.map +1 -0
- package/dist/deploy-metadata.js +183 -0
- package/dist/deploy-metadata.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +24 -30
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +13 -8
- package/src/cmd/ai/prompt/index.ts +2 -7
- package/src/cmd/build/adapters/generic.ts +239 -0
- package/src/cmd/build/adapters/index.ts +30 -0
- package/src/cmd/build/adapters/nextjs.ts +146 -0
- package/src/cmd/build/adapters/static-server.ts +143 -0
- package/src/cmd/build/adapters/types.ts +93 -0
- package/src/cmd/build/detect/engine.ts +111 -0
- package/src/cmd/build/detect/frameworks.ts +335 -0
- package/src/cmd/build/detect/generic.ts +71 -0
- package/src/cmd/build/detect/index.ts +122 -0
- package/src/cmd/build/detect/types.ts +109 -0
- package/src/cmd/build/detect/util.ts +104 -0
- package/src/cmd/build/index.ts +64 -24
- package/src/cmd/build/package/index.ts +66 -0
- package/src/cmd/build/package/launch.ts +104 -0
- package/src/cmd/build/typecheck.ts +9 -0
- package/src/cmd/cloud/deploy.ts +86 -13
- package/src/cmd/coder/create.ts +8 -8
- package/src/cmd/coder/update.ts +7 -7
- package/src/cmd/coder/workspace/create.ts +10 -10
- package/src/cmd/dev/index.ts +155 -1059
- package/src/cmd/project/auth/shared.ts +14 -39
- package/src/cmd/project/create.ts +14 -19
- package/src/cmd/project/frameworks-ai-examples.ts +166 -0
- package/src/cmd/project/frameworks-landing-pages.ts +267 -0
- package/src/cmd/project/frameworks.ts +223 -0
- package/src/cmd/project/reconcile.ts +10 -22
- package/src/cmd/project/remote-import.ts +1 -1
- package/src/cmd/project/scaffold.ts +300 -0
- package/src/cmd/project/template-flow.ts +102 -156
- package/src/deploy-metadata.ts +253 -0
- package/src/index.ts +0 -2
- package/src/types.ts +0 -31
- package/dist/agents-docs.d.ts +0 -23
- package/dist/agents-docs.d.ts.map +0 -1
- package/dist/agents-docs.js +0 -56
- package/dist/agents-docs.js.map +0 -1
- package/dist/cmd/ai/prompt/agent.d.ts +0 -10
- package/dist/cmd/ai/prompt/agent.d.ts.map +0 -1
- package/dist/cmd/ai/prompt/agent.js +0 -28
- package/dist/cmd/ai/prompt/agent.js.map +0 -1
- package/dist/cmd/build/app-router-detector.d.ts +0 -39
- package/dist/cmd/build/app-router-detector.d.ts.map +0 -1
- package/dist/cmd/build/app-router-detector.js +0 -229
- package/dist/cmd/build/app-router-detector.js.map +0 -1
- package/dist/cmd/build/format-schema.d.ts +0 -6
- package/dist/cmd/build/format-schema.d.ts.map +0 -1
- package/dist/cmd/build/format-schema.js +0 -60
- package/dist/cmd/build/format-schema.js.map +0 -1
- package/dist/cmd/build/vite/agent-discovery.d.ts +0 -37
- package/dist/cmd/build/vite/agent-discovery.d.ts.map +0 -1
- package/dist/cmd/build/vite/agent-discovery.js +0 -263
- package/dist/cmd/build/vite/agent-discovery.js.map +0 -1
- package/dist/cmd/build/vite/beacon-plugin.d.ts +0 -19
- package/dist/cmd/build/vite/beacon-plugin.d.ts.map +0 -1
- package/dist/cmd/build/vite/beacon-plugin.js +0 -137
- package/dist/cmd/build/vite/beacon-plugin.js.map +0 -1
- package/dist/cmd/build/vite/browser-env-plugin.d.ts +0 -9
- package/dist/cmd/build/vite/browser-env-plugin.d.ts.map +0 -1
- package/dist/cmd/build/vite/browser-env-plugin.js +0 -28
- package/dist/cmd/build/vite/browser-env-plugin.js.map +0 -1
- package/dist/cmd/build/vite/bun-dev-server.d.ts +0 -67
- package/dist/cmd/build/vite/bun-dev-server.d.ts.map +0 -1
- package/dist/cmd/build/vite/bun-dev-server.js +0 -340
- package/dist/cmd/build/vite/bun-dev-server.js.map +0 -1
- package/dist/cmd/build/vite/bundle-files.d.ts +0 -12
- package/dist/cmd/build/vite/bundle-files.d.ts.map +0 -1
- package/dist/cmd/build/vite/bundle-files.js +0 -107
- package/dist/cmd/build/vite/bundle-files.js.map +0 -1
- package/dist/cmd/build/vite/config-loader.d.ts +0 -29
- package/dist/cmd/build/vite/config-loader.d.ts.map +0 -1
- package/dist/cmd/build/vite/config-loader.js +0 -57
- package/dist/cmd/build/vite/config-loader.js.map +0 -1
- package/dist/cmd/build/vite/db-rewrite.d.ts +0 -50
- package/dist/cmd/build/vite/db-rewrite.d.ts.map +0 -1
- package/dist/cmd/build/vite/db-rewrite.js +0 -169
- package/dist/cmd/build/vite/db-rewrite.js.map +0 -1
- package/dist/cmd/build/vite/docs-generator.d.ts +0 -13
- package/dist/cmd/build/vite/docs-generator.d.ts.map +0 -1
- package/dist/cmd/build/vite/docs-generator.js +0 -97
- package/dist/cmd/build/vite/docs-generator.js.map +0 -1
- package/dist/cmd/build/vite/env-types-generator.d.ts +0 -26
- package/dist/cmd/build/vite/env-types-generator.d.ts.map +0 -1
- package/dist/cmd/build/vite/env-types-generator.js +0 -110
- package/dist/cmd/build/vite/env-types-generator.js.map +0 -1
- package/dist/cmd/build/vite/index.d.ts +0 -3
- package/dist/cmd/build/vite/index.d.ts.map +0 -1
- package/dist/cmd/build/vite/index.js +0 -4
- package/dist/cmd/build/vite/index.js.map +0 -1
- package/dist/cmd/build/vite/lifecycle-generator.d.ts +0 -19
- package/dist/cmd/build/vite/lifecycle-generator.d.ts.map +0 -1
- package/dist/cmd/build/vite/lifecycle-generator.js +0 -328
- package/dist/cmd/build/vite/lifecycle-generator.js.map +0 -1
- package/dist/cmd/build/vite/metadata-generator.d.ts +0 -36
- package/dist/cmd/build/vite/metadata-generator.d.ts.map +0 -1
- package/dist/cmd/build/vite/metadata-generator.js +0 -575
- package/dist/cmd/build/vite/metadata-generator.js.map +0 -1
- package/dist/cmd/build/vite/prompt-generator.d.ts +0 -23
- package/dist/cmd/build/vite/prompt-generator.d.ts.map +0 -1
- package/dist/cmd/build/vite/prompt-generator.js +0 -123
- package/dist/cmd/build/vite/prompt-generator.js.map +0 -1
- package/dist/cmd/build/vite/public-asset-path-plugin.d.ts +0 -45
- package/dist/cmd/build/vite/public-asset-path-plugin.d.ts.map +0 -1
- package/dist/cmd/build/vite/public-asset-path-plugin.js +0 -166
- package/dist/cmd/build/vite/public-asset-path-plugin.js.map +0 -1
- package/dist/cmd/build/vite/route-discovery.d.ts +0 -64
- package/dist/cmd/build/vite/route-discovery.d.ts.map +0 -1
- package/dist/cmd/build/vite/route-discovery.js +0 -187
- package/dist/cmd/build/vite/route-discovery.js.map +0 -1
- package/dist/cmd/build/vite/server-bundler.d.ts +0 -20
- package/dist/cmd/build/vite/server-bundler.d.ts.map +0 -1
- package/dist/cmd/build/vite/server-bundler.js +0 -388
- package/dist/cmd/build/vite/server-bundler.js.map +0 -1
- package/dist/cmd/build/vite/static-renderer.d.ts +0 -26
- package/dist/cmd/build/vite/static-renderer.d.ts.map +0 -1
- package/dist/cmd/build/vite/static-renderer.js +0 -188
- package/dist/cmd/build/vite/static-renderer.js.map +0 -1
- package/dist/cmd/build/vite/tailwind-source-plugin.d.ts +0 -15
- package/dist/cmd/build/vite/tailwind-source-plugin.d.ts.map +0 -1
- package/dist/cmd/build/vite/tailwind-source-plugin.js +0 -61
- package/dist/cmd/build/vite/tailwind-source-plugin.js.map +0 -1
- package/dist/cmd/build/vite/vite-asset-server-config.d.ts +0 -24
- package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +0 -1
- package/dist/cmd/build/vite/vite-asset-server-config.js +0 -285
- package/dist/cmd/build/vite/vite-asset-server-config.js.map +0 -1
- package/dist/cmd/build/vite/vite-asset-server.d.ts +0 -30
- package/dist/cmd/build/vite/vite-asset-server.d.ts.map +0 -1
- package/dist/cmd/build/vite/vite-asset-server.js +0 -109
- package/dist/cmd/build/vite/vite-asset-server.js.map +0 -1
- package/dist/cmd/build/vite/vite-builder.d.ts +0 -59
- package/dist/cmd/build/vite/vite-builder.d.ts.map +0 -1
- package/dist/cmd/build/vite/vite-builder.js +0 -401
- package/dist/cmd/build/vite/vite-builder.js.map +0 -1
- package/dist/cmd/build/vite/workbench-generator.d.ts +0 -10
- package/dist/cmd/build/vite/workbench-generator.d.ts.map +0 -1
- package/dist/cmd/build/vite/workbench-generator.js +0 -135
- package/dist/cmd/build/vite/workbench-generator.js.map +0 -1
- package/dist/cmd/build/vite/ws-proxy.d.ts +0 -53
- package/dist/cmd/build/vite/ws-proxy.d.ts.map +0 -1
- package/dist/cmd/build/vite/ws-proxy.js +0 -95
- package/dist/cmd/build/vite/ws-proxy.js.map +0 -1
- package/dist/cmd/build/vite-bundler.d.ts +0 -29
- package/dist/cmd/build/vite-bundler.d.ts.map +0 -1
- package/dist/cmd/build/vite-bundler.js +0 -93
- package/dist/cmd/build/vite-bundler.js.map +0 -1
- package/dist/cmd/dev/agents.d.ts +0 -2
- package/dist/cmd/dev/agents.d.ts.map +0 -1
- package/dist/cmd/dev/agents.js +0 -123
- package/dist/cmd/dev/agents.js.map +0 -1
- package/dist/cmd/dev/api.d.ts +0 -20
- package/dist/cmd/dev/api.d.ts.map +0 -1
- package/dist/cmd/dev/api.js +0 -42
- package/dist/cmd/dev/api.js.map +0 -1
- package/dist/cmd/dev/dev-lock.d.ts +0 -62
- package/dist/cmd/dev/dev-lock.d.ts.map +0 -1
- package/dist/cmd/dev/dev-lock.js +0 -250
- package/dist/cmd/dev/dev-lock.js.map +0 -1
- package/dist/cmd/dev/download.d.ts +0 -11
- package/dist/cmd/dev/download.d.ts.map +0 -1
- package/dist/cmd/dev/download.js +0 -94
- package/dist/cmd/dev/download.js.map +0 -1
- package/dist/cmd/dev/file-watcher.d.ts +0 -24
- package/dist/cmd/dev/file-watcher.d.ts.map +0 -1
- package/dist/cmd/dev/file-watcher.js +0 -349
- package/dist/cmd/dev/file-watcher.js.map +0 -1
- package/dist/cmd/dev/process-manager.d.ts +0 -104
- package/dist/cmd/dev/process-manager.d.ts.map +0 -1
- package/dist/cmd/dev/process-manager.js +0 -204
- package/dist/cmd/dev/process-manager.js.map +0 -1
- package/dist/cmd/dev/sync.d.ts +0 -12
- package/dist/cmd/dev/sync.d.ts.map +0 -1
- package/dist/cmd/dev/sync.js +0 -227
- package/dist/cmd/dev/sync.js.map +0 -1
- package/dist/cmd/dev/templates.d.ts +0 -3
- package/dist/cmd/dev/templates.d.ts.map +0 -1
- package/dist/cmd/dev/templates.js +0 -58
- package/dist/cmd/dev/templates.js.map +0 -1
- package/dist/cmd/project/download.d.ts +0 -35
- package/dist/cmd/project/download.d.ts.map +0 -1
- package/dist/cmd/project/download.js +0 -403
- package/dist/cmd/project/download.js.map +0 -1
- package/dist/cmd/project/templates.d.ts +0 -9
- package/dist/cmd/project/templates.d.ts.map +0 -1
- package/dist/cmd/project/templates.js +0 -34
- package/dist/cmd/project/templates.js.map +0 -1
- package/src/agents-docs.ts +0 -86
- package/src/cmd/ai/prompt/agent.md +0 -305
- package/src/cmd/ai/prompt/agent.ts +0 -31
- package/src/cmd/build/app-router-detector.ts +0 -320
- package/src/cmd/build/format-schema.ts +0 -66
- package/src/cmd/build/vite/agent-discovery.ts +0 -380
- package/src/cmd/build/vite/beacon-plugin.ts +0 -164
- package/src/cmd/build/vite/browser-env-plugin.ts +0 -34
- package/src/cmd/build/vite/bun-dev-server.ts +0 -458
- package/src/cmd/build/vite/bundle-files.ts +0 -135
- package/src/cmd/build/vite/config-loader.ts +0 -76
- package/src/cmd/build/vite/db-rewrite.ts +0 -189
- package/src/cmd/build/vite/docs-generator.ts +0 -103
- package/src/cmd/build/vite/env-types-generator.ts +0 -145
- package/src/cmd/build/vite/index.ts +0 -3
- package/src/cmd/build/vite/lifecycle-generator.ts +0 -381
- package/src/cmd/build/vite/metadata-generator.ts +0 -713
- package/src/cmd/build/vite/prompt-generator.ts +0 -169
- package/src/cmd/build/vite/public-asset-path-plugin.ts +0 -209
- package/src/cmd/build/vite/route-discovery.ts +0 -271
- package/src/cmd/build/vite/server-bundler.ts +0 -481
- package/src/cmd/build/vite/static-renderer.ts +0 -239
- package/src/cmd/build/vite/tailwind-source-plugin.ts +0 -73
- package/src/cmd/build/vite/vite-asset-server-config.ts +0 -349
- package/src/cmd/build/vite/vite-asset-server.ts +0 -154
- package/src/cmd/build/vite/vite-builder.ts +0 -503
- package/src/cmd/build/vite/workbench-generator.ts +0 -152
- package/src/cmd/build/vite/ws-proxy.ts +0 -126
- package/src/cmd/build/vite-bundler.ts +0 -137
- package/src/cmd/dev/agents.ts +0 -140
- package/src/cmd/dev/api.ts +0 -65
- package/src/cmd/dev/dev-lock.ts +0 -332
- package/src/cmd/dev/download.ts +0 -117
- package/src/cmd/dev/file-watcher.ts +0 -423
- package/src/cmd/dev/process-manager.ts +0 -261
- package/src/cmd/dev/sync.ts +0 -411
- package/src/cmd/dev/templates.ts +0 -66
- package/src/cmd/project/download.ts +0 -505
- package/src/cmd/project/templates.ts +0 -56
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
# Agents Folder Guide
|
|
2
|
-
|
|
3
|
-
This folder contains AI agents for your Agentuity application. Each agent is organized in its own subdirectory.
|
|
4
|
-
|
|
5
|
-
## Generated Types
|
|
6
|
-
|
|
7
|
-
The `src/generated/` folder contains auto-generated TypeScript files:
|
|
8
|
-
|
|
9
|
-
- `registry.ts` - Agent registry with strongly-typed agent definitions and schema types
|
|
10
|
-
- `app.ts` - Application entry point (regenerated on every build)
|
|
11
|
-
|
|
12
|
-
**Important:** Never edit files in `src/generated/` - they are overwritten on every build.
|
|
13
|
-
|
|
14
|
-
Import generated types in your agents:
|
|
15
|
-
|
|
16
|
-
```typescript
|
|
17
|
-
import type { HelloInput, HelloOutput } from '../generated/registry';
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Directory Structure
|
|
21
|
-
|
|
22
|
-
Each agent folder must contain:
|
|
23
|
-
|
|
24
|
-
- **agent.ts** (required) - Agent definition with schema and handler
|
|
25
|
-
|
|
26
|
-
Example structure:
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
src/agent/
|
|
30
|
-
├── hello/
|
|
31
|
-
│ └── agent.ts
|
|
32
|
-
├── process-data/
|
|
33
|
-
│ └── agent.ts
|
|
34
|
-
└── (generated files in src/generated/)
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**Note:** HTTP routes are defined separately in `src/api/` - see the API folder guide for details.
|
|
38
|
-
|
|
39
|
-
## Creating an Agent
|
|
40
|
-
|
|
41
|
-
### Basic Agent (agent.ts)
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
import { createAgent } from '@agentuity/runtime';
|
|
45
|
-
import { s } from '@agentuity/schema';
|
|
46
|
-
|
|
47
|
-
const agent = createAgent('my-agent', {
|
|
48
|
-
description: 'What this agent does',
|
|
49
|
-
schema: {
|
|
50
|
-
input: s.object({
|
|
51
|
-
name: s.string(),
|
|
52
|
-
age: s.number(),
|
|
53
|
-
}),
|
|
54
|
-
output: s.string(),
|
|
55
|
-
},
|
|
56
|
-
handler: async (ctx, input) => {
|
|
57
|
-
// Access context: ctx.app, ctx.config, ctx.logger, ctx.kv, ctx.vector, ctx.stream
|
|
58
|
-
return `Hello, ${input.name}! You are ${input.age} years old.`;
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export default agent;
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Agent with Lifecycle (setup/shutdown)
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
import { createAgent } from '@agentuity/runtime';
|
|
69
|
-
import { s } from '@agentuity/schema';
|
|
70
|
-
|
|
71
|
-
const agent = createAgent('lifecycle-agent', {
|
|
72
|
-
description: 'Agent with setup and shutdown',
|
|
73
|
-
schema: {
|
|
74
|
-
input: s.object({ message: s.string() }),
|
|
75
|
-
output: s.object({ result: s.string() }),
|
|
76
|
-
},
|
|
77
|
-
setup: async (app) => {
|
|
78
|
-
// Initialize resources (runs once on startup)
|
|
79
|
-
// app contains: appName, version, startedAt, config
|
|
80
|
-
return {
|
|
81
|
-
agentId: `agent-${Math.random().toString(36).substr(2, 9)}`,
|
|
82
|
-
connectionPool: ['conn-1', 'conn-2'],
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
handler: async (ctx, input) => {
|
|
86
|
-
// Access setup config via ctx.config (fully typed)
|
|
87
|
-
ctx.logger.info('Agent ID:', ctx.config.agentId);
|
|
88
|
-
ctx.logger.info('Connections:', ctx.config.connectionPool);
|
|
89
|
-
return { result: `Processed: ${input.message}` };
|
|
90
|
-
},
|
|
91
|
-
shutdown: async (app, config) => {
|
|
92
|
-
// Cleanup resources (runs on shutdown)
|
|
93
|
-
console.log('Shutting down agent:', config.agentId);
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
export default agent;
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Agent with Event Listeners
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
import { createAgent } from '@agentuity/runtime';
|
|
104
|
-
import { s } from '@agentuity/schema';
|
|
105
|
-
|
|
106
|
-
const agent = createAgent('event-agent', {
|
|
107
|
-
schema: {
|
|
108
|
-
input: s.object({ data: s.string() }),
|
|
109
|
-
output: s.string(),
|
|
110
|
-
},
|
|
111
|
-
handler: async (ctx, input) => {
|
|
112
|
-
return `Processed: ${input.data}`;
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
agent.addEventListener('started', (eventName, agent, ctx) => {
|
|
117
|
-
ctx.logger.info('Agent started');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
agent.addEventListener('completed', (eventName, agent, ctx) => {
|
|
121
|
-
ctx.logger.info('Agent completed');
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
agent.addEventListener('errored', (eventName, agent, ctx, error) => {
|
|
125
|
-
ctx.logger.error('Agent errored:', error);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
export default agent;
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
## Agent Context (ctx)
|
|
132
|
-
|
|
133
|
-
The handler receives a context object with:
|
|
134
|
-
|
|
135
|
-
- **ctx.app** - Application state (appName, version, startedAt, config from createApp)
|
|
136
|
-
- **ctx.config** - Agent-specific config (from setup return value, fully typed)
|
|
137
|
-
- **ctx.logger** - Structured logger (info, warn, error, debug, trace)
|
|
138
|
-
- **ctx.tracer** - OpenTelemetry tracer for custom spans
|
|
139
|
-
- **ctx.sessionId** - Unique session identifier
|
|
140
|
-
- **ctx.kv** - Key-value storage
|
|
141
|
-
- **ctx.vector** - Vector storage for embeddings
|
|
142
|
-
- **ctx.stream** - Stream storage for real-time data
|
|
143
|
-
- **ctx.state** - In-memory request-scoped state (Map)
|
|
144
|
-
- **ctx.thread** - Thread information for multi-turn conversations
|
|
145
|
-
- **ctx.session** - Session information
|
|
146
|
-
- **ctx.waitUntil** - Schedule background tasks
|
|
147
|
-
|
|
148
|
-
## Examples
|
|
149
|
-
|
|
150
|
-
### Using Key-Value Storage
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
handler: async (ctx, input) => {
|
|
154
|
-
await ctx.kv.set('users', 'user:123', { name: 'Alice', age: 30 });
|
|
155
|
-
const result = await ctx.kv.get('users', 'user:123');
|
|
156
|
-
await ctx.kv.delete('users', 'user:123');
|
|
157
|
-
const keys = await ctx.kv.getKeys('users');
|
|
158
|
-
return result.exists ? result.data : null;
|
|
159
|
-
};
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### Using Vector Storage
|
|
163
|
-
|
|
164
|
-
```typescript
|
|
165
|
-
handler: async (ctx, input) => {
|
|
166
|
-
await ctx.vector.upsert('docs', [
|
|
167
|
-
{ id: '1', values: [0.1, 0.2, 0.3], metadata: { text: 'Hello' } },
|
|
168
|
-
]);
|
|
169
|
-
const results = await ctx.vector.query('docs', [0.1, 0.2, 0.3], { topK: 5 });
|
|
170
|
-
return results;
|
|
171
|
-
};
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Using Streams
|
|
175
|
-
|
|
176
|
-
```typescript
|
|
177
|
-
handler: async (ctx, input) => {
|
|
178
|
-
const stream = await ctx.stream.create('agent-logs');
|
|
179
|
-
await ctx.stream.write(stream.id, 'Processing step 1');
|
|
180
|
-
await ctx.stream.write(stream.id, 'Processing step 2');
|
|
181
|
-
return { streamId: stream.id };
|
|
182
|
-
};
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### Background Tasks with waitUntil
|
|
186
|
-
|
|
187
|
-
```typescript
|
|
188
|
-
handler: async (ctx, input) => {
|
|
189
|
-
// Schedule background work that continues after response
|
|
190
|
-
ctx.waitUntil(async () => {
|
|
191
|
-
await ctx.kv.set('state', 'processed', Date.now());
|
|
192
|
-
ctx.logger.info('Background task complete');
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
return { status: 'processing' };
|
|
196
|
-
};
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Calling Another Agent
|
|
200
|
-
|
|
201
|
-
```typescript
|
|
202
|
-
// Import the agent directly
|
|
203
|
-
import otherAgent from '../other-agent/agent';
|
|
204
|
-
|
|
205
|
-
handler: async (ctx, input) => {
|
|
206
|
-
const result = await otherAgent.run({ data: input.value });
|
|
207
|
-
return `Other agent returned: ${result}`;
|
|
208
|
-
};
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
## Subagents (Nested Agents)
|
|
212
|
-
|
|
213
|
-
Agents can have subagents organized one level deep. This is useful for grouping related functionality.
|
|
214
|
-
|
|
215
|
-
### Directory Structure for Subagents
|
|
216
|
-
|
|
217
|
-
```
|
|
218
|
-
src/agent/
|
|
219
|
-
└── team/ # Parent agent
|
|
220
|
-
├── agent.ts # Parent agent
|
|
221
|
-
├── members/ # Subagent
|
|
222
|
-
│ └── agent.ts
|
|
223
|
-
└── tasks/ # Subagent
|
|
224
|
-
└── agent.ts
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
### Parent Agent
|
|
228
|
-
|
|
229
|
-
```typescript
|
|
230
|
-
import { createAgent } from '@agentuity/runtime';
|
|
231
|
-
import { s } from '@agentuity/schema';
|
|
232
|
-
|
|
233
|
-
const agent = createAgent('team', {
|
|
234
|
-
description: 'Team Manager',
|
|
235
|
-
schema: {
|
|
236
|
-
input: s.object({ action: s.union([s.literal('info'), s.literal('count')]) }),
|
|
237
|
-
output: s.object({
|
|
238
|
-
message: s.string(),
|
|
239
|
-
timestamp: s.string(),
|
|
240
|
-
}),
|
|
241
|
-
},
|
|
242
|
-
handler: async (ctx, { action }) => {
|
|
243
|
-
return {
|
|
244
|
-
message: 'Team parent agent - manages members and tasks',
|
|
245
|
-
timestamp: new Date().toISOString(),
|
|
246
|
-
};
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
export default agent;
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
### Subagent (Accessing Parent)
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
import { createAgent } from '@agentuity/runtime';
|
|
257
|
-
import { s } from '@agentuity/schema';
|
|
258
|
-
import parentAgent from '../agent';
|
|
259
|
-
|
|
260
|
-
const agent = createAgent('team.members', {
|
|
261
|
-
description: 'Members Subagent',
|
|
262
|
-
schema: {
|
|
263
|
-
input: s.object({
|
|
264
|
-
action: s.union([s.literal('list'), s.literal('add'), s.literal('remove')]),
|
|
265
|
-
name: s.optional(s.string()),
|
|
266
|
-
}),
|
|
267
|
-
output: s.object({
|
|
268
|
-
members: s.array(s.string()),
|
|
269
|
-
parentInfo: s.optional(s.string()),
|
|
270
|
-
}),
|
|
271
|
-
},
|
|
272
|
-
handler: async (ctx, { action, name }) => {
|
|
273
|
-
// Call parent agent directly
|
|
274
|
-
const parentResult = await parentAgent.run({ action: 'info' });
|
|
275
|
-
const parentInfo = `Parent says: ${parentResult.message}`;
|
|
276
|
-
|
|
277
|
-
let members = ['Alice', 'Bob'];
|
|
278
|
-
if (action === 'add' && name) {
|
|
279
|
-
members.push(name);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return { members, parentInfo };
|
|
283
|
-
},
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
export default agent;
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
### Key Points About Subagents
|
|
290
|
-
|
|
291
|
-
- **One level deep**: Only one level of nesting is supported (no nested subagents)
|
|
292
|
-
- **Access parent**: Import and call parent agents directly
|
|
293
|
-
- **Agent names**: Subagents have dotted names like `"team.members"`
|
|
294
|
-
- **Shared context**: Subagents share the same app context (kv, logger, etc.)
|
|
295
|
-
|
|
296
|
-
## Rules
|
|
297
|
-
|
|
298
|
-
- Each agent folder name becomes the agent's route name (e.g., `hello/` → `/agent/hello`)
|
|
299
|
-
- **agent.ts** must export default the agent instance
|
|
300
|
-
- The first argument to `createAgent()` is the agent name (must match folder structure)
|
|
301
|
-
- Input/output schemas are enforced with @agentuity/schema validation
|
|
302
|
-
- Setup return value type automatically flows to ctx.config (fully typed)
|
|
303
|
-
- Use ctx.logger for logging, not console.log
|
|
304
|
-
- Import agents directly to call them (recommended approach)
|
|
305
|
-
- Subagents are one level deep only (team/members/, not team/members/subagent/)
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createSubcommand } from '../../../types';
|
|
2
|
-
import type { CommandContext } from '../../../types';
|
|
3
|
-
import { getCommand } from '../../../command-prefix';
|
|
4
|
-
import { appendHashComment } from './version';
|
|
5
|
-
import agentPromptContent from './agent.md' with { type: 'text' };
|
|
6
|
-
|
|
7
|
-
export const agentSubcommand = createSubcommand({
|
|
8
|
-
name: 'agent',
|
|
9
|
-
description: 'Generate a comprehensive prompt for LLM agents for the agents folder',
|
|
10
|
-
tags: ['read-only', 'fast'],
|
|
11
|
-
idempotent: true,
|
|
12
|
-
examples: [{ command: getCommand('prompt agent'), description: 'Run agent command' }],
|
|
13
|
-
async handler(_ctx: CommandContext) {
|
|
14
|
-
const prompt = generateLLMPrompt();
|
|
15
|
-
console.log(prompt);
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Get the raw prompt content without hash.
|
|
21
|
-
*/
|
|
22
|
-
export function getPromptContent(): string {
|
|
23
|
-
return agentPromptContent;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Generate the agent prompt with hash comment.
|
|
28
|
-
*/
|
|
29
|
-
export function generateLLMPrompt(): string {
|
|
30
|
-
return appendHashComment(agentPromptContent);
|
|
31
|
-
}
|
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* App Router Detector
|
|
3
|
-
*
|
|
4
|
-
* Parses the user's `src/app.ts` to detect whether they pass a `router` property
|
|
5
|
-
* to `createApp()`. If detected, resolves the router variable(s) to their import
|
|
6
|
-
* sources and mount paths.
|
|
7
|
-
*
|
|
8
|
-
* Uses TypeScript's compiler API to reliably detect the pattern, consistent with
|
|
9
|
-
* the lifecycle generator approach.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import ts from 'typescript';
|
|
13
|
-
import { join, dirname, resolve } from 'node:path';
|
|
14
|
-
import { statSync } from 'node:fs';
|
|
15
|
-
import type { Logger } from '../../types';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A resolved mount point from `createApp({ router })`.
|
|
19
|
-
*/
|
|
20
|
-
export interface DetectedRouteMount {
|
|
21
|
-
/** Mount path (e.g., '/api', '/api/v1') */
|
|
22
|
-
path: string;
|
|
23
|
-
/** Absolute file path of the router module */
|
|
24
|
-
routerFile: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Result of detecting explicit router usage in app.ts.
|
|
29
|
-
*/
|
|
30
|
-
export interface AppRouterDetection {
|
|
31
|
-
/** Whether `createApp({ router })` was found */
|
|
32
|
-
detected: boolean;
|
|
33
|
-
/** Resolved mount points with their router files */
|
|
34
|
-
mounts: DetectedRouteMount[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Resolve an import path to an actual file on disk.
|
|
39
|
-
* Tries the path as-is, then with common extensions.
|
|
40
|
-
*/
|
|
41
|
-
async function resolveImportFile(fromDir: string, importPath: string): Promise<string | null> {
|
|
42
|
-
if (!importPath.startsWith('.') && !importPath.startsWith('/')) {
|
|
43
|
-
return null; // Package import — can't resolve
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const basePath = resolve(fromDir, importPath);
|
|
47
|
-
const extensions = ['.ts', '.tsx', '/index.ts', '/index.tsx'];
|
|
48
|
-
|
|
49
|
-
const baseFile = Bun.file(basePath);
|
|
50
|
-
if (await baseFile.exists()) {
|
|
51
|
-
try {
|
|
52
|
-
if (statSync(basePath).isFile()) return basePath;
|
|
53
|
-
} catch {
|
|
54
|
-
// ignore
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
for (const ext of extensions) {
|
|
59
|
-
const candidate = basePath + ext;
|
|
60
|
-
if (await Bun.file(candidate).exists()) {
|
|
61
|
-
return candidate;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* A router mount extracted from the AST before file resolution.
|
|
70
|
-
*/
|
|
71
|
-
interface RawMount {
|
|
72
|
-
path: string;
|
|
73
|
-
varName: string;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Extract router mounts from a createApp() call using TypeScript's AST.
|
|
78
|
-
* Returns null if no router property found.
|
|
79
|
-
*/
|
|
80
|
-
function extractRouterMounts(sourceFile: ts.SourceFile): RawMount[] | null {
|
|
81
|
-
let result: RawMount[] | null = null;
|
|
82
|
-
|
|
83
|
-
function getStringLiteral(node: ts.Expression): string | null {
|
|
84
|
-
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
85
|
-
return node.text;
|
|
86
|
-
}
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function extractMountFromObject(obj: ts.ObjectLiteralExpression): RawMount | null {
|
|
91
|
-
let path: string | undefined;
|
|
92
|
-
let varName: string | undefined;
|
|
93
|
-
|
|
94
|
-
for (const prop of obj.properties) {
|
|
95
|
-
if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name)) continue;
|
|
96
|
-
|
|
97
|
-
if (prop.name.text === 'path') {
|
|
98
|
-
path = getStringLiteral(prop.initializer) ?? undefined;
|
|
99
|
-
}
|
|
100
|
-
if (prop.name.text === 'router') {
|
|
101
|
-
if (ts.isIdentifier(prop.initializer)) {
|
|
102
|
-
varName = prop.initializer.text;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Also handle shorthand: { path: '/v1', router } where router is shorthand
|
|
108
|
-
for (const prop of obj.properties) {
|
|
109
|
-
if (ts.isShorthandPropertyAssignment(prop) && prop.name.text === 'router') {
|
|
110
|
-
varName = prop.name.text;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return path && varName ? { path, varName } : null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function processRouterValue(value: ts.Expression): RawMount[] | null {
|
|
118
|
-
// Form 1: Identifier → createApp({ router: myRouter })
|
|
119
|
-
if (ts.isIdentifier(value)) {
|
|
120
|
-
return [{ path: '/api', varName: value.text }];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Form 2: Object → createApp({ router: { path: '/v1', router: myRouter } })
|
|
124
|
-
if (ts.isObjectLiteralExpression(value)) {
|
|
125
|
-
const mount = extractMountFromObject(value);
|
|
126
|
-
return mount ? [mount] : null;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Form 3: Array → createApp({ router: [...] })
|
|
130
|
-
if (ts.isArrayLiteralExpression(value)) {
|
|
131
|
-
const mounts: RawMount[] = [];
|
|
132
|
-
for (const element of value.elements) {
|
|
133
|
-
if (ts.isObjectLiteralExpression(element)) {
|
|
134
|
-
const mount = extractMountFromObject(element);
|
|
135
|
-
if (mount) mounts.push(mount);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return mounts.length > 0 ? mounts : null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function visit(node: ts.Node): void {
|
|
145
|
-
if (result) return;
|
|
146
|
-
|
|
147
|
-
// Find createApp(...) — with or without await
|
|
148
|
-
let callExpr: ts.CallExpression | undefined;
|
|
149
|
-
|
|
150
|
-
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
151
|
-
if (node.expression.text === 'createApp') callExpr = node;
|
|
152
|
-
} else if (ts.isAwaitExpression(node) && ts.isCallExpression(node.expression)) {
|
|
153
|
-
const call = node.expression;
|
|
154
|
-
if (ts.isIdentifier(call.expression) && call.expression.text === 'createApp') {
|
|
155
|
-
callExpr = call;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (callExpr && callExpr.arguments.length > 0) {
|
|
160
|
-
const configArg = callExpr.arguments[0];
|
|
161
|
-
if (configArg && ts.isObjectLiteralExpression(configArg)) {
|
|
162
|
-
for (const prop of configArg.properties) {
|
|
163
|
-
// Handle: router: value
|
|
164
|
-
if (
|
|
165
|
-
ts.isPropertyAssignment(prop) &&
|
|
166
|
-
ts.isIdentifier(prop.name) &&
|
|
167
|
-
prop.name.text === 'router'
|
|
168
|
-
) {
|
|
169
|
-
result = processRouterValue(prop.initializer);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Handle shorthand: createApp({ router })
|
|
174
|
-
if (ts.isShorthandPropertyAssignment(prop) && prop.name.text === 'router') {
|
|
175
|
-
result = [{ path: '/api', varName: 'router' }];
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
ts.forEachChild(node, visit);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
visit(sourceFile);
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Build import map from the source file: variable name → import path
|
|
191
|
-
*/
|
|
192
|
-
function buildImportMap(sourceFile: ts.SourceFile): Map<string, string> {
|
|
193
|
-
const importMap = new Map<string, string>();
|
|
194
|
-
|
|
195
|
-
for (const stmt of sourceFile.statements) {
|
|
196
|
-
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier)) continue;
|
|
197
|
-
|
|
198
|
-
const importPath = stmt.moduleSpecifier.text;
|
|
199
|
-
const clause = stmt.importClause;
|
|
200
|
-
if (!clause) continue;
|
|
201
|
-
|
|
202
|
-
// Default import: import router from './api'
|
|
203
|
-
if (clause.name) {
|
|
204
|
-
importMap.set(clause.name.text, importPath);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Named imports: import { v1, v2 } from './routers'
|
|
208
|
-
if (clause.namedBindings && ts.isNamedImports(clause.namedBindings)) {
|
|
209
|
-
for (const spec of clause.namedBindings.elements) {
|
|
210
|
-
importMap.set(spec.name.text, importPath);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return importMap;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Detect whether `src/app.ts` uses `createApp({ router })`.
|
|
220
|
-
*
|
|
221
|
-
* Returns `{ detected: false, mounts: [] }` when:
|
|
222
|
-
* - `src/app.ts` doesn't exist
|
|
223
|
-
* - `createApp()` is called without a `router` property
|
|
224
|
-
* - Router variables can't be resolved to files
|
|
225
|
-
*/
|
|
226
|
-
export async function detectExplicitRouter(
|
|
227
|
-
rootDir: string,
|
|
228
|
-
logger: Logger
|
|
229
|
-
): Promise<AppRouterDetection> {
|
|
230
|
-
const noDetection: AppRouterDetection = { detected: false, mounts: [] };
|
|
231
|
-
|
|
232
|
-
// Look for app.ts in src/ (standard location), then root
|
|
233
|
-
let appFile = join(rootDir, 'src', 'app.ts');
|
|
234
|
-
if (!(await Bun.file(appFile).exists())) {
|
|
235
|
-
appFile = join(rootDir, 'app.ts');
|
|
236
|
-
if (!(await Bun.file(appFile).exists())) {
|
|
237
|
-
logger.trace('[router-detect] No app.ts found');
|
|
238
|
-
return noDetection;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
try {
|
|
243
|
-
const source = await Bun.file(appFile).text();
|
|
244
|
-
const appDir = dirname(appFile);
|
|
245
|
-
|
|
246
|
-
// Quick bail-out before parsing
|
|
247
|
-
if (!source.includes('createApp') || !source.includes('router')) {
|
|
248
|
-
logger.trace('[router-detect] No createApp + router pattern found in %s', appFile);
|
|
249
|
-
return noDetection;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// Parse with TypeScript
|
|
253
|
-
const sourceFile = ts.createSourceFile(
|
|
254
|
-
appFile,
|
|
255
|
-
source,
|
|
256
|
-
ts.ScriptTarget.Latest,
|
|
257
|
-
true,
|
|
258
|
-
ts.ScriptKind.TS
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
const rawMounts = extractRouterMounts(sourceFile);
|
|
262
|
-
if (!rawMounts || rawMounts.length === 0) {
|
|
263
|
-
logger.trace('[router-detect] createApp() found but no router property');
|
|
264
|
-
return noDetection;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Build import map to resolve variable names to file paths
|
|
268
|
-
const importMap = buildImportMap(sourceFile);
|
|
269
|
-
|
|
270
|
-
// Resolve each router variable to its file
|
|
271
|
-
const mounts: DetectedRouteMount[] = [];
|
|
272
|
-
for (const { path, varName } of rawMounts) {
|
|
273
|
-
const importPath = importMap.get(varName);
|
|
274
|
-
if (!importPath) {
|
|
275
|
-
logger.debug(
|
|
276
|
-
'[router-detect] Router variable %s is not imported — may be defined locally',
|
|
277
|
-
varName
|
|
278
|
-
);
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const resolvedFile = await resolveImportFile(appDir, importPath);
|
|
283
|
-
if (!resolvedFile) {
|
|
284
|
-
logger.warn(
|
|
285
|
-
'[router-detect] Could not resolve import %s for router variable %s',
|
|
286
|
-
importPath,
|
|
287
|
-
varName
|
|
288
|
-
);
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
logger.trace(
|
|
293
|
-
'[router-detect] Found router mount: %s → %s (%s)',
|
|
294
|
-
path,
|
|
295
|
-
varName,
|
|
296
|
-
resolvedFile
|
|
297
|
-
);
|
|
298
|
-
mounts.push({ path, routerFile: resolvedFile });
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (mounts.length === 0) {
|
|
302
|
-
logger.debug('[router-detect] Router variables found but none could be resolved to files');
|
|
303
|
-
return noDetection;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
logger.debug(
|
|
307
|
-
'[router-detect] Detected %d explicit router mount(s) in %s',
|
|
308
|
-
mounts.length,
|
|
309
|
-
appFile
|
|
310
|
-
);
|
|
311
|
-
return { detected: true, mounts };
|
|
312
|
-
} catch (error) {
|
|
313
|
-
logger.warn(
|
|
314
|
-
'[router-detect] Failed to parse %s: %s',
|
|
315
|
-
appFile,
|
|
316
|
-
error instanceof Error ? error.message : String(error)
|
|
317
|
-
);
|
|
318
|
-
return noDetection;
|
|
319
|
-
}
|
|
320
|
-
}
|