@portel/photon 1.4.1 → 1.5.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.
- package/README.md +287 -1160
- package/dist/auto-ui/beam.d.ts +9 -0
- package/dist/auto-ui/beam.d.ts.map +1 -0
- package/dist/auto-ui/beam.js +2381 -0
- package/dist/auto-ui/beam.js.map +1 -0
- package/dist/auto-ui/components/card.d.ts +13 -0
- package/dist/auto-ui/components/card.d.ts.map +1 -0
- package/dist/auto-ui/components/card.js +64 -0
- package/dist/auto-ui/components/card.js.map +1 -0
- package/dist/auto-ui/components/form.d.ts +15 -0
- package/dist/auto-ui/components/form.d.ts.map +1 -0
- package/dist/auto-ui/components/form.js +72 -0
- package/dist/auto-ui/components/form.js.map +1 -0
- package/dist/auto-ui/components/list.d.ts +13 -0
- package/dist/auto-ui/components/list.d.ts.map +1 -0
- package/dist/auto-ui/components/list.js +58 -0
- package/dist/auto-ui/components/list.js.map +1 -0
- package/dist/auto-ui/components/progress.d.ts +18 -0
- package/dist/auto-ui/components/progress.d.ts.map +1 -0
- package/dist/auto-ui/components/progress.js +125 -0
- package/dist/auto-ui/components/progress.js.map +1 -0
- package/dist/auto-ui/components/table.d.ts +13 -0
- package/dist/auto-ui/components/table.d.ts.map +1 -0
- package/dist/auto-ui/components/table.js +82 -0
- package/dist/auto-ui/components/table.js.map +1 -0
- package/dist/auto-ui/components/tree.d.ts +13 -0
- package/dist/auto-ui/components/tree.d.ts.map +1 -0
- package/dist/auto-ui/components/tree.js +61 -0
- package/dist/auto-ui/components/tree.js.map +1 -0
- package/dist/auto-ui/daemon-tools.d.ts +45 -0
- package/dist/auto-ui/daemon-tools.d.ts.map +1 -0
- package/dist/auto-ui/daemon-tools.js +580 -0
- package/dist/auto-ui/daemon-tools.js.map +1 -0
- package/dist/auto-ui/design-system/index.d.ts +21 -0
- package/dist/auto-ui/design-system/index.d.ts.map +1 -0
- package/dist/auto-ui/design-system/index.js +27 -0
- package/dist/auto-ui/design-system/index.js.map +1 -0
- package/dist/auto-ui/design-system/tokens.d.ts +9 -0
- package/dist/auto-ui/design-system/tokens.d.ts.map +1 -0
- package/dist/auto-ui/design-system/tokens.js +27 -0
- package/dist/auto-ui/design-system/tokens.js.map +1 -0
- package/dist/auto-ui/design-system/transaction-ui.d.ts +70 -0
- package/dist/auto-ui/design-system/transaction-ui.d.ts.map +1 -0
- package/dist/auto-ui/design-system/transaction-ui.js +982 -0
- package/dist/auto-ui/design-system/transaction-ui.js.map +1 -0
- package/dist/auto-ui/frontend/index.html +84 -0
- package/dist/auto-ui/index.d.ts +21 -0
- package/dist/auto-ui/index.d.ts.map +1 -0
- package/dist/auto-ui/index.js +25 -0
- package/dist/auto-ui/index.js.map +1 -0
- package/dist/auto-ui/openapi-generator.d.ts +71 -0
- package/dist/auto-ui/openapi-generator.d.ts.map +1 -0
- package/dist/auto-ui/openapi-generator.js +223 -0
- package/dist/auto-ui/openapi-generator.js.map +1 -0
- package/dist/auto-ui/photon-bridge.d.ts +159 -0
- package/dist/auto-ui/photon-bridge.d.ts.map +1 -0
- package/dist/auto-ui/photon-bridge.js +262 -0
- package/dist/auto-ui/photon-bridge.js.map +1 -0
- package/dist/auto-ui/photon-host.d.ts +113 -0
- package/dist/auto-ui/photon-host.d.ts.map +1 -0
- package/dist/auto-ui/photon-host.js +284 -0
- package/dist/auto-ui/photon-host.js.map +1 -0
- package/dist/auto-ui/platform-compat.d.ts +71 -0
- package/dist/auto-ui/platform-compat.d.ts.map +1 -0
- package/dist/auto-ui/platform-compat.js +574 -0
- package/dist/auto-ui/platform-compat.js.map +1 -0
- package/dist/auto-ui/playground-html.d.ts +15 -0
- package/dist/auto-ui/playground-html.d.ts.map +1 -0
- package/dist/auto-ui/playground-html.js +1113 -0
- package/dist/auto-ui/playground-html.js.map +1 -0
- package/dist/auto-ui/playground-server.d.ts +7 -0
- package/dist/auto-ui/playground-server.d.ts.map +1 -0
- package/dist/auto-ui/playground-server.js +840 -0
- package/dist/auto-ui/playground-server.js.map +1 -0
- package/dist/auto-ui/registry.d.ts +13 -0
- package/dist/auto-ui/registry.d.ts.map +1 -0
- package/dist/auto-ui/registry.js +62 -0
- package/dist/auto-ui/registry.js.map +1 -0
- package/dist/auto-ui/renderer.d.ts +14 -0
- package/dist/auto-ui/renderer.d.ts.map +1 -0
- package/dist/auto-ui/renderer.js +88 -0
- package/dist/auto-ui/renderer.js.map +1 -0
- package/dist/auto-ui/rendering/components.d.ts +29 -0
- package/dist/auto-ui/rendering/components.d.ts.map +1 -0
- package/dist/auto-ui/rendering/components.js +773 -0
- package/dist/auto-ui/rendering/components.js.map +1 -0
- package/dist/auto-ui/rendering/field-analyzer.d.ts +48 -0
- package/dist/auto-ui/rendering/field-analyzer.d.ts.map +1 -0
- package/dist/auto-ui/rendering/field-analyzer.js +270 -0
- package/dist/auto-ui/rendering/field-analyzer.js.map +1 -0
- package/dist/auto-ui/rendering/field-renderers.d.ts +64 -0
- package/dist/auto-ui/rendering/field-renderers.d.ts.map +1 -0
- package/dist/auto-ui/rendering/field-renderers.js +317 -0
- package/dist/auto-ui/rendering/field-renderers.js.map +1 -0
- package/dist/auto-ui/rendering/index.d.ts +28 -0
- package/dist/auto-ui/rendering/index.d.ts.map +1 -0
- package/dist/auto-ui/rendering/index.js +60 -0
- package/dist/auto-ui/rendering/index.js.map +1 -0
- package/dist/auto-ui/rendering/layout-selector.d.ts +48 -0
- package/dist/auto-ui/rendering/layout-selector.d.ts.map +1 -0
- package/dist/auto-ui/rendering/layout-selector.js +352 -0
- package/dist/auto-ui/rendering/layout-selector.js.map +1 -0
- package/dist/auto-ui/rendering/template-engine.d.ts +41 -0
- package/dist/auto-ui/rendering/template-engine.d.ts.map +1 -0
- package/dist/auto-ui/rendering/template-engine.js +238 -0
- package/dist/auto-ui/rendering/template-engine.js.map +1 -0
- package/dist/auto-ui/streamable-http-transport.d.ts +79 -0
- package/dist/auto-ui/streamable-http-transport.d.ts.map +1 -0
- package/dist/auto-ui/streamable-http-transport.js +1314 -0
- package/dist/auto-ui/streamable-http-transport.js.map +1 -0
- package/dist/auto-ui/types.d.ts +310 -0
- package/dist/auto-ui/types.d.ts.map +1 -0
- package/dist/auto-ui/types.js +71 -0
- package/dist/auto-ui/types.js.map +1 -0
- package/dist/beam.bundle.js +13506 -0
- package/dist/beam.bundle.js.map +7 -0
- package/dist/claude-code-plugin.d.ts.map +1 -1
- package/dist/claude-code-plugin.js +30 -30
- package/dist/claude-code-plugin.js.map +1 -1
- package/dist/cli/commands/info.d.ts +11 -0
- package/dist/cli/commands/info.d.ts.map +1 -0
- package/dist/cli/commands/info.js +313 -0
- package/dist/cli/commands/info.js.map +1 -0
- package/dist/cli/commands/marketplace.d.ts +11 -0
- package/dist/cli/commands/marketplace.d.ts.map +1 -0
- package/dist/cli/commands/marketplace.js +198 -0
- package/dist/cli/commands/marketplace.js.map +1 -0
- package/dist/cli/commands/package-app.d.ts +9 -0
- package/dist/cli/commands/package-app.d.ts.map +1 -0
- package/dist/cli/commands/package-app.js +191 -0
- package/dist/cli/commands/package-app.js.map +1 -0
- package/dist/cli/commands/package.d.ts +11 -0
- package/dist/cli/commands/package.d.ts.map +1 -0
- package/dist/cli/commands/package.js +573 -0
- package/dist/cli/commands/package.js.map +1 -0
- package/dist/cli-alias.d.ts.map +1 -1
- package/dist/cli-alias.js +30 -28
- package/dist/cli-alias.js.map +1 -1
- package/dist/cli-formatter.d.ts +8 -24
- package/dist/cli-formatter.d.ts.map +1 -1
- package/dist/cli-formatter.js +8 -325
- package/dist/cli-formatter.js.map +1 -1
- package/dist/cli.d.ts +15 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1157 -1132
- package/dist/cli.js.map +1 -1
- package/dist/daemon/client.d.ts +79 -0
- package/dist/daemon/client.d.ts.map +1 -1
- package/dist/daemon/client.js +532 -8
- package/dist/daemon/client.js.map +1 -1
- package/dist/daemon/manager.d.ts +46 -12
- package/dist/daemon/manager.d.ts.map +1 -1
- package/dist/daemon/manager.js +102 -61
- package/dist/daemon/manager.js.map +1 -1
- package/dist/daemon/protocol.d.ts +62 -6
- package/dist/daemon/protocol.d.ts.map +1 -1
- package/dist/daemon/protocol.js +76 -1
- package/dist/daemon/protocol.js.map +1 -1
- package/dist/daemon/server.d.ts +6 -6
- package/dist/daemon/server.js +743 -133
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/session-manager.d.ts +8 -1
- package/dist/daemon/session-manager.d.ts.map +1 -1
- package/dist/daemon/session-manager.js +32 -9
- package/dist/daemon/session-manager.js.map +1 -1
- package/dist/deploy/cloudflare.d.ts +12 -0
- package/dist/deploy/cloudflare.d.ts.map +1 -0
- package/dist/deploy/cloudflare.js +216 -0
- package/dist/deploy/cloudflare.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +168 -21
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +1120 -318
- package/dist/loader.js.map +1 -1
- package/dist/markdown-utils.d.ts +8 -0
- package/dist/markdown-utils.d.ts.map +1 -0
- package/dist/markdown-utils.js +63 -0
- package/dist/markdown-utils.js.map +1 -0
- package/dist/marketplace-manager.d.ts +10 -0
- package/dist/marketplace-manager.d.ts.map +1 -1
- package/dist/marketplace-manager.js +112 -28
- package/dist/marketplace-manager.js.map +1 -1
- package/dist/mcp-client.d.ts +9 -0
- package/dist/mcp-client.d.ts.map +1 -0
- package/dist/mcp-client.js +11 -0
- package/dist/mcp-client.js.map +1 -0
- package/dist/mcp-elicitation.d.ts +32 -0
- package/dist/mcp-elicitation.d.ts.map +1 -0
- package/dist/mcp-elicitation.js +26 -0
- package/dist/mcp-elicitation.js.map +1 -0
- package/dist/path-resolver.d.ts +9 -12
- package/dist/path-resolver.d.ts.map +1 -1
- package/dist/path-resolver.js +13 -43
- package/dist/path-resolver.js.map +1 -1
- package/dist/photon-cli-runner.d.ts.map +1 -1
- package/dist/photon-cli-runner.js +202 -77
- package/dist/photon-cli-runner.js.map +1 -1
- package/dist/photon-doc-extractor.d.ts +88 -0
- package/dist/photon-doc-extractor.d.ts.map +1 -1
- package/dist/photon-doc-extractor.js +536 -27
- package/dist/photon-doc-extractor.js.map +1 -1
- package/dist/photons/maker.photon.d.ts +182 -0
- package/dist/photons/maker.photon.d.ts.map +1 -0
- package/dist/photons/maker.photon.js +504 -0
- package/dist/photons/maker.photon.js.map +1 -0
- package/dist/photons/maker.photon.ts +626 -0
- package/dist/photons/marketplace.photon.d.ts +110 -0
- package/dist/photons/marketplace.photon.d.ts.map +1 -0
- package/dist/photons/marketplace.photon.js +260 -0
- package/dist/photons/marketplace.photon.js.map +1 -0
- package/dist/photons/marketplace.photon.ts +378 -0
- package/dist/photons/tunnel.photon.d.ts +80 -0
- package/dist/photons/tunnel.photon.d.ts.map +1 -0
- package/dist/photons/tunnel.photon.js +269 -0
- package/dist/photons/tunnel.photon.js.map +1 -0
- package/dist/photons/tunnel.photon.ts +345 -0
- package/dist/security-scanner.d.ts.map +1 -1
- package/dist/security-scanner.js +18 -15
- package/dist/security-scanner.js.map +1 -1
- package/dist/serv/auth/jwt.d.ts +89 -0
- package/dist/serv/auth/jwt.d.ts.map +1 -0
- package/dist/serv/auth/jwt.js +239 -0
- package/dist/serv/auth/jwt.js.map +1 -0
- package/dist/serv/auth/oauth.d.ts +117 -0
- package/dist/serv/auth/oauth.d.ts.map +1 -0
- package/dist/serv/auth/oauth.js +395 -0
- package/dist/serv/auth/oauth.js.map +1 -0
- package/dist/serv/auth/well-known.d.ts +60 -0
- package/dist/serv/auth/well-known.d.ts.map +1 -0
- package/dist/serv/auth/well-known.js +154 -0
- package/dist/serv/auth/well-known.js.map +1 -0
- package/dist/serv/db/d1-client.d.ts +65 -0
- package/dist/serv/db/d1-client.d.ts.map +1 -0
- package/dist/serv/db/d1-client.js +137 -0
- package/dist/serv/db/d1-client.js.map +1 -0
- package/dist/serv/db/d1-stores.d.ts +62 -0
- package/dist/serv/db/d1-stores.d.ts.map +1 -0
- package/dist/serv/db/d1-stores.js +307 -0
- package/dist/serv/db/d1-stores.js.map +1 -0
- package/dist/serv/index.d.ts +114 -0
- package/dist/serv/index.d.ts.map +1 -0
- package/dist/serv/index.js +172 -0
- package/dist/serv/index.js.map +1 -0
- package/dist/serv/local.d.ts +118 -0
- package/dist/serv/local.d.ts.map +1 -0
- package/dist/serv/local.js +392 -0
- package/dist/serv/local.js.map +1 -0
- package/dist/serv/middleware/auth.d.ts +66 -0
- package/dist/serv/middleware/auth.d.ts.map +1 -0
- package/dist/serv/middleware/auth.js +178 -0
- package/dist/serv/middleware/auth.js.map +1 -0
- package/dist/serv/middleware/tenant.d.ts +94 -0
- package/dist/serv/middleware/tenant.d.ts.map +1 -0
- package/dist/serv/middleware/tenant.js +152 -0
- package/dist/serv/middleware/tenant.js.map +1 -0
- package/dist/serv/runtime/executor.d.ts +76 -0
- package/dist/serv/runtime/executor.d.ts.map +1 -0
- package/dist/serv/runtime/executor.js +105 -0
- package/dist/serv/runtime/executor.js.map +1 -0
- package/dist/serv/runtime/index.d.ts +8 -0
- package/dist/serv/runtime/index.d.ts.map +1 -0
- package/dist/serv/runtime/index.js +10 -0
- package/dist/serv/runtime/index.js.map +1 -0
- package/dist/serv/runtime/oauth-context.d.ts +121 -0
- package/dist/serv/runtime/oauth-context.d.ts.map +1 -0
- package/dist/serv/runtime/oauth-context.js +153 -0
- package/dist/serv/runtime/oauth-context.js.map +1 -0
- package/dist/serv/session/kv-store.d.ts +54 -0
- package/dist/serv/session/kv-store.d.ts.map +1 -0
- package/dist/serv/session/kv-store.js +149 -0
- package/dist/serv/session/kv-store.js.map +1 -0
- package/dist/serv/session/store.d.ts +113 -0
- package/dist/serv/session/store.d.ts.map +1 -0
- package/dist/serv/session/store.js +284 -0
- package/dist/serv/session/store.js.map +1 -0
- package/dist/serv/types/index.d.ts +147 -0
- package/dist/serv/types/index.d.ts.map +1 -0
- package/dist/serv/types/index.js +8 -0
- package/dist/serv/types/index.js.map +1 -0
- package/dist/serv/vault/token-vault.d.ts +102 -0
- package/dist/serv/vault/token-vault.d.ts.map +1 -0
- package/dist/serv/vault/token-vault.js +177 -0
- package/dist/serv/vault/token-vault.js.map +1 -0
- package/dist/server.d.ts +173 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1622 -86
- package/dist/server.js.map +1 -1
- package/dist/shared/cli-sections.d.ts +6 -0
- package/dist/shared/cli-sections.d.ts.map +1 -0
- package/dist/shared/cli-sections.js +16 -0
- package/dist/shared/cli-sections.js.map +1 -0
- package/dist/shared/cli-utils.d.ts +81 -0
- package/dist/shared/cli-utils.d.ts.map +1 -0
- package/dist/shared/cli-utils.js +174 -0
- package/dist/shared/cli-utils.js.map +1 -0
- package/dist/shared/config-docs.d.ts +6 -0
- package/dist/shared/config-docs.d.ts.map +1 -0
- package/dist/shared/config-docs.js +6 -0
- package/dist/shared/config-docs.js.map +1 -0
- package/dist/shared/error-handler.d.ts +128 -0
- package/dist/shared/error-handler.d.ts.map +1 -0
- package/dist/shared/error-handler.js +342 -0
- package/dist/shared/error-handler.js.map +1 -0
- package/dist/shared/logger.d.ts +42 -0
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/logger.js +123 -0
- package/dist/shared/logger.js.map +1 -0
- package/dist/shared/performance.d.ts +65 -0
- package/dist/shared/performance.d.ts.map +1 -0
- package/dist/shared/performance.js +136 -0
- package/dist/shared/performance.js.map +1 -0
- package/dist/shared/task-runner.d.ts +2 -0
- package/dist/shared/task-runner.d.ts.map +1 -0
- package/dist/shared/task-runner.js +16 -0
- package/dist/shared/task-runner.js.map +1 -0
- package/dist/shared/validation.d.ts +6 -0
- package/dist/shared/validation.d.ts.map +1 -0
- package/dist/shared/validation.js +6 -0
- package/dist/shared/validation.js.map +1 -0
- package/dist/shared-utils.d.ts +63 -0
- package/dist/shared-utils.d.ts.map +1 -0
- package/dist/shared-utils.js +123 -0
- package/dist/shared-utils.js.map +1 -0
- package/dist/template-manager.d.ts +23 -2
- package/dist/template-manager.d.ts.map +1 -1
- package/dist/template-manager.js +175 -86
- package/dist/template-manager.js.map +1 -1
- package/dist/test-client.d.ts.map +1 -1
- package/dist/test-client.js +10 -8
- package/dist/test-client.js.map +1 -1
- package/dist/test-runner.d.ts +52 -0
- package/dist/test-runner.d.ts.map +1 -0
- package/dist/test-runner.js +785 -0
- package/dist/test-runner.js.map +1 -0
- package/dist/testing.d.ts +103 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +163 -0
- package/dist/testing.js.map +1 -0
- package/dist/version-checker.d.ts.map +1 -1
- package/dist/version-checker.js +2 -2
- package/dist/version-checker.js.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/dist/watcher.d.ts +6 -3
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +49 -10
- package/dist/watcher.js.map +1 -1
- package/package.json +47 -7
- package/templates/cloudflare/worker.ts.template +381 -0
- package/templates/cloudflare/wrangler.toml.template +9 -0
- package/dist/base.d.ts +0 -58
- package/dist/base.d.ts.map +0 -1
- package/dist/base.js +0 -92
- package/dist/base.js.map +0 -1
- package/dist/dependency-manager.d.ts +0 -49
- package/dist/dependency-manager.d.ts.map +0 -1
- package/dist/dependency-manager.js +0 -165
- package/dist/dependency-manager.js.map +0 -1
- package/dist/registry-manager.d.ts +0 -76
- package/dist/registry-manager.d.ts.map +0 -1
- package/dist/registry-manager.js +0 -220
- package/dist/registry-manager.js.map +0 -1
- package/dist/schema-extractor.d.ts +0 -110
- package/dist/schema-extractor.d.ts.map +0 -1
- package/dist/schema-extractor.js +0 -727
- package/dist/schema-extractor.js.map +0 -1
- package/dist/test-marketplace-sources.d.ts +0 -5
- package/dist/test-marketplace-sources.d.ts.map +0 -1
- package/dist/test-marketplace-sources.js +0 -53
- package/dist/test-marketplace-sources.js.map +0 -1
- package/dist/types.d.ts +0 -109
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -12
- package/dist/types.js.map +0 -1
|
@@ -6,16 +6,35 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import * as fs from 'fs/promises';
|
|
9
|
-
import { SchemaExtractor, setPromptHandler } from '@portel/photon-core';
|
|
9
|
+
import { SchemaExtractor, setPromptHandler, setElicitHandler, elicitReadline, } from '@portel/photon-core';
|
|
10
10
|
import * as readline from 'readline';
|
|
11
11
|
import chalk from 'chalk';
|
|
12
12
|
import { highlight } from 'cli-highlight';
|
|
13
13
|
import { resolvePhotonPath } from './path-resolver.js';
|
|
14
14
|
import { PhotonLoader } from './loader.js';
|
|
15
|
+
import { fileURLToPath } from 'url';
|
|
16
|
+
import { getBundledPhotonPath } from './shared-utils.js';
|
|
17
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
+
const __dirname = path.dirname(__filename);
|
|
19
|
+
// getBundledPhotonPath is imported from shared-utils.js
|
|
20
|
+
/**
|
|
21
|
+
* Resolve photon path - checks bundled first, then user directory
|
|
22
|
+
*/
|
|
23
|
+
async function resolvePhotonPathWithBundled(name) {
|
|
24
|
+
// Check bundled photons first
|
|
25
|
+
const bundledPath = getBundledPhotonPath(name, __dirname);
|
|
26
|
+
if (bundledPath) {
|
|
27
|
+
return bundledPath;
|
|
28
|
+
}
|
|
29
|
+
// Fall back to user photons
|
|
30
|
+
return resolvePhotonPath(name);
|
|
31
|
+
}
|
|
15
32
|
import { PhotonDocExtractor } from './photon-doc-extractor.js';
|
|
16
33
|
import { isDaemonRunning, startDaemon } from './daemon/manager.js';
|
|
17
34
|
import { sendCommand, pingDaemon } from './daemon/client.js';
|
|
18
35
|
import { formatOutput as baseFormatOutput, renderNone, formatKey, } from './cli-formatter.js';
|
|
36
|
+
import { getErrorMessage } from './shared/error-handler.js';
|
|
37
|
+
import { logger } from './shared/logger.js';
|
|
19
38
|
/**
|
|
20
39
|
* Extract all public async methods from a photon file
|
|
21
40
|
*/
|
|
@@ -24,8 +43,8 @@ async function extractMethods(filePath) {
|
|
|
24
43
|
const extractor = new SchemaExtractor();
|
|
25
44
|
const methods = [];
|
|
26
45
|
// Extract methods using the schema extractor
|
|
27
|
-
// Also match async generator methods (async *methodName)
|
|
28
|
-
const methodMatches = source.matchAll(/async\s+\*?\s*(\w+)\s*\(([^)]*)\)/g);
|
|
46
|
+
// Also match async generator methods (async *methodName) and static methods
|
|
47
|
+
const methodMatches = source.matchAll(/(?:static\s+)?async\s+\*?\s*(\w+)\s*\(([^)]*)\)/g);
|
|
29
48
|
for (const match of methodMatches) {
|
|
30
49
|
const methodName = match[1];
|
|
31
50
|
const methodParams = match[2];
|
|
@@ -52,7 +71,7 @@ async function extractMethods(filePath) {
|
|
|
52
71
|
const description = descMatch
|
|
53
72
|
? descMatch[1]
|
|
54
73
|
.split('\n')
|
|
55
|
-
.map(line => line.replace(/^\s*\*\s?/, '').trim())
|
|
74
|
+
.map((line) => line.replace(/^\s*\*\s?/, '').trim())
|
|
56
75
|
.join(' ')
|
|
57
76
|
.trim()
|
|
58
77
|
: undefined;
|
|
@@ -82,8 +101,8 @@ async function extractMethods(filePath) {
|
|
|
82
101
|
}
|
|
83
102
|
// Extract format hint from @format tag (structural and content formats)
|
|
84
103
|
let format;
|
|
85
|
-
// Match structural formats
|
|
86
|
-
const structuralMatch = jsdoc.match(/@format\s+(primitive|table|tree|list|none)/i);
|
|
104
|
+
// Match structural formats (including card, tabs, accordion)
|
|
105
|
+
const structuralMatch = jsdoc.match(/@format\s+(primitive|table|tree|list|card|tabs|accordion|none)/i);
|
|
87
106
|
if (structuralMatch) {
|
|
88
107
|
format = structuralMatch[1].toLowerCase();
|
|
89
108
|
}
|
|
@@ -108,8 +127,51 @@ async function extractMethods(filePath) {
|
|
|
108
127
|
while ((paramMatch = paramRegex.exec(jsdoc)) !== null) {
|
|
109
128
|
const paramName = paramMatch[1];
|
|
110
129
|
const paramDesc = paramMatch[2].trim();
|
|
111
|
-
//
|
|
112
|
-
const
|
|
130
|
+
// Extract custom label from {@label displayName} tag
|
|
131
|
+
const labelMatch = paramDesc.match(/\{@label\s+([^}]+)\}/);
|
|
132
|
+
const customLabel = labelMatch ? labelMatch[1].trim() : undefined;
|
|
133
|
+
// Extract {@example ...} - handle nested braces/brackets for JSON
|
|
134
|
+
let example;
|
|
135
|
+
const exampleStart = paramDesc.indexOf('{@example ');
|
|
136
|
+
if (exampleStart !== -1) {
|
|
137
|
+
const contentStart = exampleStart + '{@example '.length;
|
|
138
|
+
let braceDepth = 0;
|
|
139
|
+
let bracketDepth = 0;
|
|
140
|
+
let i = contentStart;
|
|
141
|
+
let inString = false;
|
|
142
|
+
while (i < paramDesc.length) {
|
|
143
|
+
const ch = paramDesc[i];
|
|
144
|
+
const prevCh = i > 0 ? paramDesc[i - 1] : '';
|
|
145
|
+
if (ch === '"' && prevCh !== '\\') {
|
|
146
|
+
inString = !inString;
|
|
147
|
+
}
|
|
148
|
+
else if (!inString) {
|
|
149
|
+
if (ch === '{')
|
|
150
|
+
braceDepth++;
|
|
151
|
+
else if (ch === '[')
|
|
152
|
+
bracketDepth++;
|
|
153
|
+
else if (ch === ']')
|
|
154
|
+
bracketDepth--;
|
|
155
|
+
else if (ch === '}') {
|
|
156
|
+
if (braceDepth === 0 && bracketDepth === 0) {
|
|
157
|
+
example = paramDesc.substring(contentStart, i).trim();
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
braceDepth--;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
i++;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Remove {@example ...} tag (handles nested braces/brackets)
|
|
167
|
+
let cleanedParamDesc = paramDesc;
|
|
168
|
+
if (exampleStart !== -1 && example) {
|
|
169
|
+
// Remove the full {@example ...} tag we extracted
|
|
170
|
+
const tagEnd = exampleStart + '{@example '.length + example.length + 1; // +1 for closing }
|
|
171
|
+
cleanedParamDesc = paramDesc.substring(0, exampleStart) + paramDesc.substring(tagEnd);
|
|
172
|
+
}
|
|
173
|
+
// Remove remaining JSDoc constraint tags for display
|
|
174
|
+
const cleanDesc = cleanedParamDesc
|
|
113
175
|
.replace(/\{@\w+[^}]*\}/g, '')
|
|
114
176
|
.replace(/\(optional\)/gi, '')
|
|
115
177
|
.replace(/\(default:.*?\)/gi, '')
|
|
@@ -123,13 +185,19 @@ async function extractMethods(filePath) {
|
|
|
123
185
|
type: tsParamTypes.get(paramName) || 'any',
|
|
124
186
|
optional,
|
|
125
187
|
description: cleanDesc,
|
|
188
|
+
...(customLabel ? { label: customLabel } : {}),
|
|
189
|
+
...(example ? { example } : {}),
|
|
126
190
|
});
|
|
127
191
|
}
|
|
192
|
+
// Extract button label from @returns {@label ...} tag
|
|
193
|
+
const returnsMatch = jsdoc.match(/@returns?\s+.*?\{@label\s+([^}]+)\}/i);
|
|
194
|
+
const buttonLabel = returnsMatch ? returnsMatch[1].trim() : undefined;
|
|
128
195
|
methods.push({
|
|
129
196
|
name: methodName,
|
|
130
197
|
params,
|
|
131
198
|
description,
|
|
132
199
|
...(format ? { format } : {}),
|
|
200
|
+
...(buttonLabel ? { buttonLabel } : {}),
|
|
133
201
|
});
|
|
134
202
|
}
|
|
135
203
|
return methods;
|
|
@@ -148,7 +216,7 @@ function extractBaseType(typeStr) {
|
|
|
148
216
|
return objectMatch[1];
|
|
149
217
|
}
|
|
150
218
|
// Handle unions: boolean | number -> take first primitive type
|
|
151
|
-
const unionTypes = typeStr.split('|').map(t => t.trim());
|
|
219
|
+
const unionTypes = typeStr.split('|').map((t) => t.trim());
|
|
152
220
|
for (const type of unionTypes) {
|
|
153
221
|
if (/^(boolean|number|string)/.test(type)) {
|
|
154
222
|
return type;
|
|
@@ -206,7 +274,10 @@ function formatOutput(result, formatHint) {
|
|
|
206
274
|
hint = inlineMarkdownFormat;
|
|
207
275
|
}
|
|
208
276
|
if (markdownText) {
|
|
209
|
-
const primaryBlock = buildMarkdownBlockFromPrepared(markdownText, {
|
|
277
|
+
const primaryBlock = buildMarkdownBlockFromPrepared(markdownText, {
|
|
278
|
+
hint,
|
|
279
|
+
inlineFormat: inlineMarkdownFormat,
|
|
280
|
+
});
|
|
210
281
|
if (primaryBlock) {
|
|
211
282
|
const metadata = extractMetadataFields(result);
|
|
212
283
|
renderMarkdownBlocks([primaryBlock], { additionalMetadata: metadata });
|
|
@@ -218,10 +289,10 @@ function formatOutput(result, formatHint) {
|
|
|
218
289
|
dataToFormat = result.data;
|
|
219
290
|
}
|
|
220
291
|
else {
|
|
221
|
-
const otherFields = Object.keys(result).filter(k => k !== 'success' && k !== 'message' && k !== 'error');
|
|
292
|
+
const otherFields = Object.keys(result).filter((k) => k !== 'success' && k !== 'message' && k !== 'error');
|
|
222
293
|
if (otherFields.length > 0) {
|
|
223
294
|
dataToFormat = {};
|
|
224
|
-
otherFields.forEach(k => dataToFormat[k] = result[k]);
|
|
295
|
+
otherFields.forEach((k) => (dataToFormat[k] = result[k]));
|
|
225
296
|
}
|
|
226
297
|
else {
|
|
227
298
|
if (!result.message) {
|
|
@@ -238,7 +309,10 @@ function formatOutput(result, formatHint) {
|
|
|
238
309
|
}
|
|
239
310
|
dataToFormat = inline.text;
|
|
240
311
|
}
|
|
241
|
-
const markdownBlock = buildMarkdownBlockFromPrepared(dataToFormat, {
|
|
312
|
+
const markdownBlock = buildMarkdownBlockFromPrepared(dataToFormat, {
|
|
313
|
+
hint,
|
|
314
|
+
inlineFormat: inline?.format,
|
|
315
|
+
});
|
|
242
316
|
if (markdownBlock) {
|
|
243
317
|
renderMarkdownBlocks([markdownBlock]);
|
|
244
318
|
return true;
|
|
@@ -264,7 +338,10 @@ function formatOutput(result, formatHint) {
|
|
|
264
338
|
}
|
|
265
339
|
payload = inline.text;
|
|
266
340
|
}
|
|
267
|
-
const standaloneBlock = buildMarkdownBlockFromPrepared(payload, {
|
|
341
|
+
const standaloneBlock = buildMarkdownBlockFromPrepared(payload, {
|
|
342
|
+
hint,
|
|
343
|
+
inlineFormat: inline?.format,
|
|
344
|
+
});
|
|
268
345
|
if (standaloneBlock) {
|
|
269
346
|
renderMarkdownBlocks([standaloneBlock]);
|
|
270
347
|
return true;
|
|
@@ -289,7 +366,7 @@ function formatOutput(result, formatHint) {
|
|
|
289
366
|
function parseCliArgs(args, params) {
|
|
290
367
|
const result = {};
|
|
291
368
|
// Create a map of param names to types for quick lookup
|
|
292
|
-
const paramTypes = new Map(params.map(p => [p.name, p.type]));
|
|
369
|
+
const paramTypes = new Map(params.map((p) => [p.name, p.type]));
|
|
293
370
|
// Handle both positional and --flag style arguments
|
|
294
371
|
let positionalIndex = 0;
|
|
295
372
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -400,7 +477,7 @@ function looksLikeMarkdown(value) {
|
|
|
400
477
|
/^```/m,
|
|
401
478
|
/(?:^|\n)(?:-{3,}|_{3,}|\*{3,})(?:\n|$)/m,
|
|
402
479
|
];
|
|
403
|
-
if (blockPatterns.some(pattern => pattern.test(trimmed))) {
|
|
480
|
+
if (blockPatterns.some((pattern) => pattern.test(trimmed))) {
|
|
404
481
|
return true;
|
|
405
482
|
}
|
|
406
483
|
if (/\[.+?\]\(.+?\)/.test(trimmed)) {
|
|
@@ -437,7 +514,9 @@ function renderMarkdownNicely(content) {
|
|
|
437
514
|
return `\u0000CODE${codeBlocks.length - 1}\u0000`;
|
|
438
515
|
});
|
|
439
516
|
// Wrap text paragraphs
|
|
440
|
-
rendered = rendered
|
|
517
|
+
rendered = rendered
|
|
518
|
+
.split('\n')
|
|
519
|
+
.map((line) => {
|
|
441
520
|
// Skip headers, placeholders, empty lines, lists, quotes
|
|
442
521
|
if (line.startsWith('#') ||
|
|
443
522
|
line.includes('\u0000CODE') ||
|
|
@@ -447,7 +526,8 @@ function renderMarkdownNicely(content) {
|
|
|
447
526
|
}
|
|
448
527
|
// Wrap plain text line
|
|
449
528
|
return wrapToWidth(line, termWidth).join('\n');
|
|
450
|
-
})
|
|
529
|
+
})
|
|
530
|
+
.join('\n');
|
|
451
531
|
// Restore code blocks and highlight
|
|
452
532
|
rendered = rendered.replace(/\u0000CODE(\d+)\u0000/g, (_m, index) => {
|
|
453
533
|
const block = codeBlocks[parseInt(index)];
|
|
@@ -478,7 +558,10 @@ function renderMarkdownNicely(content) {
|
|
|
478
558
|
rendered = rendered.replace(/\*(.+?)\*/g, (_m, text) => chalk.italic(text));
|
|
479
559
|
rendered = rendered.replace(/_(.+?)_/g, (_m, text) => chalk.italic(text));
|
|
480
560
|
rendered = rendered.replace(/`([^`]+)`/g, (_m, code) => chalk.cyan(code));
|
|
481
|
-
rendered = rendered
|
|
561
|
+
rendered = rendered
|
|
562
|
+
.split('\n')
|
|
563
|
+
.map((line) => line.trimEnd())
|
|
564
|
+
.join('\n');
|
|
482
565
|
rendered = rendered.replace(/\n{3,}/g, '\n\n');
|
|
483
566
|
console.log(rendered.trim());
|
|
484
567
|
}
|
|
@@ -506,12 +589,10 @@ function convertFrontMatterToMarkdown(markdown) {
|
|
|
506
589
|
return { markdown: prefix + text, metadata, hadFrontMatter };
|
|
507
590
|
}
|
|
508
591
|
function frontMatterToTable(parsed) {
|
|
509
|
-
const rows = Object.entries(parsed)
|
|
510
|
-
|
|
511
|
-
'
|
|
512
|
-
|
|
513
|
-
rows,
|
|
514
|
-
].join('\n');
|
|
592
|
+
const rows = Object.entries(parsed)
|
|
593
|
+
.map(([key, value]) => `| ${escapePipes(key)} | ${escapePipes(value)} |`)
|
|
594
|
+
.join('\n');
|
|
595
|
+
return ['| Field | Value |', '| --- | --- |', rows].join('\n');
|
|
515
596
|
}
|
|
516
597
|
function escapePipes(text) {
|
|
517
598
|
return text.replace(/\|/g, '\\|');
|
|
@@ -822,7 +903,7 @@ function renderMarkdownTableBlock(block) {
|
|
|
822
903
|
const rows = lines
|
|
823
904
|
.slice(2)
|
|
824
905
|
.map(parseMarkdownTableRow)
|
|
825
|
-
.filter(row => row.length === header.length);
|
|
906
|
+
.filter((row) => row.length === header.length);
|
|
826
907
|
if (!rows.length) {
|
|
827
908
|
return block;
|
|
828
909
|
}
|
|
@@ -834,18 +915,18 @@ function parseMarkdownTableRow(line) {
|
|
|
834
915
|
.replace(/^\|/, '')
|
|
835
916
|
.replace(/\|$/, '')
|
|
836
917
|
.split('|')
|
|
837
|
-
.map(cell => cell.trim());
|
|
918
|
+
.map((cell) => cell.trim());
|
|
838
919
|
}
|
|
839
920
|
function renderGenericTable(headers, rows) {
|
|
840
921
|
if (!headers.length) {
|
|
841
|
-
return rows.map(row => row.join(' | ')).join('\n');
|
|
922
|
+
return rows.map((row) => row.join(' | ')).join('\n');
|
|
842
923
|
}
|
|
843
924
|
const termWidth = process.stdout.columns || 80;
|
|
844
925
|
const columns = headers.length;
|
|
845
926
|
const baseOverhead = 2 * columns + (columns - 1) + 2; // padding + connectors + borders
|
|
846
927
|
const maxAvailable = Math.max(columns, termWidth - baseOverhead);
|
|
847
|
-
const colWidths = headers.map(header => Math.max(visibleLength(header), 3));
|
|
848
|
-
rows.forEach(row => {
|
|
928
|
+
const colWidths = headers.map((header) => Math.max(visibleLength(header), 3));
|
|
929
|
+
rows.forEach((row) => {
|
|
849
930
|
row.forEach((cell, idx) => {
|
|
850
931
|
const width = visibleLength(cell ?? '');
|
|
851
932
|
if (width > (colWidths[idx] || 0)) {
|
|
@@ -865,13 +946,13 @@ function renderGenericTable(headers, rows) {
|
|
|
865
946
|
}
|
|
866
947
|
colWidths[maxIdx]--;
|
|
867
948
|
}
|
|
868
|
-
const wrappedRows = [headers, ...rows].map(row => row.map((cell, idx) => wrapToWidth(cell ?? '', colWidths[idx] || 1)));
|
|
869
|
-
const horizontal = colWidths.map(width => '─'.repeat(width + 2));
|
|
949
|
+
const wrappedRows = [headers, ...rows].map((row) => row.map((cell, idx) => wrapToWidth(cell ?? '', colWidths[idx] || 1)));
|
|
950
|
+
const horizontal = colWidths.map((width) => '─'.repeat(width + 2));
|
|
870
951
|
const top = `┌${horizontal.join('┬')}┐`;
|
|
871
952
|
const mid = `├${horizontal.join('┼')}┤`;
|
|
872
953
|
const bottom = `└${horizontal.join('┴')}┘`;
|
|
873
954
|
const formatWrappedRow = (wrappedCells) => {
|
|
874
|
-
const maxLines = Math.max(...wrappedCells.map(cell => cell.length));
|
|
955
|
+
const maxLines = Math.max(...wrappedCells.map((cell) => cell.length));
|
|
875
956
|
const lines = [];
|
|
876
957
|
for (let lineIdx = 0; lineIdx < maxLines; lineIdx++) {
|
|
877
958
|
const parts = wrappedCells.map((cellLines, idx) => {
|
|
@@ -893,6 +974,16 @@ function renderGenericTable(headers, rows) {
|
|
|
893
974
|
});
|
|
894
975
|
return output.join('\n');
|
|
895
976
|
}
|
|
977
|
+
/**
|
|
978
|
+
* Format camelCase/PascalCase to "Title Case With Spaces"
|
|
979
|
+
*/
|
|
980
|
+
function formatLabel(name) {
|
|
981
|
+
return name
|
|
982
|
+
.replace(/([A-Z])/g, ' $1') // Add space before capitals
|
|
983
|
+
.replace(/([a-zA-Z])(\d)/g, '$1 $2') // Add space before numbers
|
|
984
|
+
.replace(/^./, (str) => str.toUpperCase()) // Capitalize first letter
|
|
985
|
+
.trim();
|
|
986
|
+
}
|
|
896
987
|
/**
|
|
897
988
|
* Print help for a specific method
|
|
898
989
|
*/
|
|
@@ -900,11 +991,11 @@ function printMethodHelp(photonName, method) {
|
|
|
900
991
|
console.log(`\nNAME:`);
|
|
901
992
|
console.log(` ${method.name} - ${method.description || 'No description'}\n`);
|
|
902
993
|
console.log(`USAGE:`);
|
|
903
|
-
const requiredParams = method.params.filter(p => !p.optional);
|
|
904
|
-
const optionalParams = method.params.filter(p => p.optional);
|
|
994
|
+
const requiredParams = method.params.filter((p) => !p.optional);
|
|
995
|
+
const optionalParams = method.params.filter((p) => p.optional);
|
|
905
996
|
let usage = ` photon cli ${photonName} ${method.name}`;
|
|
906
997
|
if (requiredParams.length > 0) {
|
|
907
|
-
usage += ' ' + requiredParams.map(p => `--${p.name} <value>`).join(' ');
|
|
998
|
+
usage += ' ' + requiredParams.map((p) => `--${p.name} <value>`).join(' ');
|
|
908
999
|
}
|
|
909
1000
|
if (optionalParams.length > 0) {
|
|
910
1001
|
usage += ' [options]';
|
|
@@ -914,20 +1005,32 @@ function printMethodHelp(photonName, method) {
|
|
|
914
1005
|
if (requiredParams.length > 0) {
|
|
915
1006
|
console.log(`REQUIRED:`);
|
|
916
1007
|
for (const param of requiredParams) {
|
|
917
|
-
|
|
1008
|
+
// Show custom label or formatted name
|
|
1009
|
+
const displayLabel = param.label || formatLabel(param.name);
|
|
1010
|
+
console.log(` --${param.name} (${displayLabel})`);
|
|
918
1011
|
if (param.description) {
|
|
919
1012
|
console.log(` ${param.description}`);
|
|
920
1013
|
}
|
|
1014
|
+
// Show example for complex types (JSON)
|
|
1015
|
+
if (param.example) {
|
|
1016
|
+
console.log(` Example: ${param.example}`);
|
|
1017
|
+
}
|
|
921
1018
|
}
|
|
922
1019
|
console.log('');
|
|
923
1020
|
}
|
|
924
1021
|
if (optionalParams.length > 0) {
|
|
925
1022
|
console.log(`OPTIONS:`);
|
|
926
1023
|
for (const param of optionalParams) {
|
|
927
|
-
|
|
1024
|
+
// Show custom label or formatted name
|
|
1025
|
+
const displayLabel = param.label || formatLabel(param.name);
|
|
1026
|
+
console.log(` --${param.name} (${displayLabel})`);
|
|
928
1027
|
if (param.description) {
|
|
929
1028
|
console.log(` ${param.description}`);
|
|
930
1029
|
}
|
|
1030
|
+
// Show example for complex types (JSON)
|
|
1031
|
+
if (param.example) {
|
|
1032
|
+
console.log(` Example: ${param.example}`);
|
|
1033
|
+
}
|
|
931
1034
|
}
|
|
932
1035
|
console.log('');
|
|
933
1036
|
}
|
|
@@ -937,7 +1040,7 @@ function printMethodHelp(photonName, method) {
|
|
|
937
1040
|
}
|
|
938
1041
|
console.log(`EXAMPLE:`);
|
|
939
1042
|
if (requiredParams.length > 0) {
|
|
940
|
-
const exampleParams = requiredParams.map(p => `--${p.name} <value>`).join(' ');
|
|
1043
|
+
const exampleParams = requiredParams.map((p) => `--${p.name} <value>`).join(' ');
|
|
941
1044
|
console.log(` photon cli ${photonName} ${method.name} ${exampleParams}\n`);
|
|
942
1045
|
}
|
|
943
1046
|
else {
|
|
@@ -949,9 +1052,9 @@ function printMethodHelp(photonName, method) {
|
|
|
949
1052
|
*/
|
|
950
1053
|
export async function listMethods(photonName) {
|
|
951
1054
|
try {
|
|
952
|
-
const resolvedPath = await
|
|
1055
|
+
const resolvedPath = await resolvePhotonPathWithBundled(photonName);
|
|
953
1056
|
if (!resolvedPath) {
|
|
954
|
-
|
|
1057
|
+
logger.error(`Photon '${photonName}' not found`);
|
|
955
1058
|
console.error(`\nMake sure the photon is installed in ~/.photon/`);
|
|
956
1059
|
process.exit(1);
|
|
957
1060
|
}
|
|
@@ -962,7 +1065,7 @@ export async function listMethods(photonName) {
|
|
|
962
1065
|
// Print commands
|
|
963
1066
|
console.log(`COMMANDS:`);
|
|
964
1067
|
// Find longest method name for alignment
|
|
965
|
-
const maxLength = Math.max(...methods.map(m => m.name.length));
|
|
1068
|
+
const maxLength = Math.max(...methods.map((m) => m.name.length));
|
|
966
1069
|
for (const method of methods) {
|
|
967
1070
|
const padding = ' '.repeat(maxLength - method.name.length + 4);
|
|
968
1071
|
const description = method.description || 'No description';
|
|
@@ -977,9 +1080,9 @@ export async function listMethods(photonName) {
|
|
|
977
1080
|
// Show first 3 methods as examples
|
|
978
1081
|
const exampleMethods = methods.slice(0, 3);
|
|
979
1082
|
for (const method of exampleMethods) {
|
|
980
|
-
const requiredParams = method.params.filter(p => !p.optional);
|
|
1083
|
+
const requiredParams = method.params.filter((p) => !p.optional);
|
|
981
1084
|
if (requiredParams.length > 0) {
|
|
982
|
-
const paramStr = requiredParams.map(p => `--${p.name} <value>`).join(' ');
|
|
1085
|
+
const paramStr = requiredParams.map((p) => `--${p.name} <value>`).join(' ');
|
|
983
1086
|
console.log(` photon cli ${photonName} ${method.name} ${paramStr}`);
|
|
984
1087
|
}
|
|
985
1088
|
else {
|
|
@@ -990,7 +1093,7 @@ export async function listMethods(photonName) {
|
|
|
990
1093
|
}
|
|
991
1094
|
}
|
|
992
1095
|
catch (error) {
|
|
993
|
-
|
|
1096
|
+
logger.error(`Error: ${getErrorMessage(error)}`);
|
|
994
1097
|
process.exit(1);
|
|
995
1098
|
}
|
|
996
1099
|
}
|
|
@@ -1005,20 +1108,20 @@ export async function runMethod(photonName, methodName, args) {
|
|
|
1005
1108
|
input: process.stdin,
|
|
1006
1109
|
output: process.stdout,
|
|
1007
1110
|
});
|
|
1008
|
-
const prompt = defaultValue
|
|
1009
|
-
? `${message} [${defaultValue}]: `
|
|
1010
|
-
: `${message}: `;
|
|
1111
|
+
const prompt = defaultValue ? `${message} [${defaultValue}]: ` : `${message}: `;
|
|
1011
1112
|
rl.question(prompt, (answer) => {
|
|
1012
1113
|
rl.close();
|
|
1013
1114
|
resolve(answer || defaultValue || null);
|
|
1014
1115
|
});
|
|
1015
1116
|
});
|
|
1016
1117
|
});
|
|
1118
|
+
// Set up readline elicit handler for CLI (confirm, select, etc.)
|
|
1119
|
+
setElicitHandler(elicitReadline);
|
|
1017
1120
|
try {
|
|
1018
1121
|
// Resolve photon path
|
|
1019
|
-
const resolvedPath = await
|
|
1122
|
+
const resolvedPath = await resolvePhotonPathWithBundled(photonName);
|
|
1020
1123
|
if (!resolvedPath) {
|
|
1021
|
-
|
|
1124
|
+
logger.error(`Photon '${photonName}' not found`);
|
|
1022
1125
|
console.error(`\nMake sure the photon is installed in ~/.photon/`);
|
|
1023
1126
|
process.exit(1);
|
|
1024
1127
|
}
|
|
@@ -1031,10 +1134,10 @@ export async function runMethod(photonName, methodName, args) {
|
|
|
1031
1134
|
await listMethods(photonName);
|
|
1032
1135
|
return;
|
|
1033
1136
|
}
|
|
1034
|
-
const method = methods.find(m => m.name === methodName);
|
|
1137
|
+
const method = methods.find((m) => m.name === methodName);
|
|
1035
1138
|
if (!method) {
|
|
1036
|
-
|
|
1037
|
-
console.error(`\nAvailable methods: ${methods.map(m => m.name).join(', ')}`);
|
|
1139
|
+
logger.error(`Method '${methodName}' not found in ${photonName}`);
|
|
1140
|
+
console.error(`\nAvailable methods: ${methods.map((m) => m.name).join(', ')}`);
|
|
1038
1141
|
console.error(`\nRun 'photon cli ${photonName}' to see all methods`);
|
|
1039
1142
|
process.exit(1);
|
|
1040
1143
|
}
|
|
@@ -1045,7 +1148,14 @@ export async function runMethod(photonName, methodName, args) {
|
|
|
1045
1148
|
}
|
|
1046
1149
|
// Check for --json flag
|
|
1047
1150
|
const jsonOutput = args.includes('--json');
|
|
1048
|
-
|
|
1151
|
+
// Check for --resume <runId> flag
|
|
1152
|
+
let resumeRunId;
|
|
1153
|
+
const resumeIndex = args.indexOf('--resume');
|
|
1154
|
+
if (resumeIndex !== -1 && args[resumeIndex + 1]) {
|
|
1155
|
+
resumeRunId = args[resumeIndex + 1];
|
|
1156
|
+
}
|
|
1157
|
+
// Filter out special flags before parsing method args
|
|
1158
|
+
const filteredArgs = args.filter((arg, i) => arg !== '--json' && arg !== '--resume' && (resumeIndex === -1 || i !== resumeIndex + 1));
|
|
1049
1159
|
// Parse arguments
|
|
1050
1160
|
const parsedArgs = parseCliArgs(filteredArgs, method.params);
|
|
1051
1161
|
// Validate required parameters
|
|
@@ -1056,8 +1166,10 @@ export async function runMethod(photonName, methodName, args) {
|
|
|
1056
1166
|
}
|
|
1057
1167
|
}
|
|
1058
1168
|
if (missing.length > 0) {
|
|
1059
|
-
|
|
1060
|
-
console.error(`\nUsage: photon cli ${photonName} ${methodName} ${method.params
|
|
1169
|
+
logger.error(`Missing required parameters: ${missing.join(', ')}`);
|
|
1170
|
+
console.error(`\nUsage: photon cli ${photonName} ${methodName} ${method.params
|
|
1171
|
+
.map((p) => (p.optional ? `[--${p.name}]` : `--${p.name} <value>`))
|
|
1172
|
+
.join(' ')}`);
|
|
1061
1173
|
process.exit(1);
|
|
1062
1174
|
}
|
|
1063
1175
|
// Check if photon is stateful
|
|
@@ -1072,14 +1184,14 @@ export async function runMethod(photonName, methodName, args) {
|
|
|
1072
1184
|
// Wait for daemon to be ready
|
|
1073
1185
|
let ready = false;
|
|
1074
1186
|
for (let i = 0; i < 10; i++) {
|
|
1075
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
1187
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1076
1188
|
if (await pingDaemon(photonName)) {
|
|
1077
1189
|
ready = true;
|
|
1078
1190
|
break;
|
|
1079
1191
|
}
|
|
1080
1192
|
}
|
|
1081
1193
|
if (!ready) {
|
|
1082
|
-
|
|
1194
|
+
logger.error(`Failed to start daemon for ${photonName}`);
|
|
1083
1195
|
process.exit(1);
|
|
1084
1196
|
}
|
|
1085
1197
|
}
|
|
@@ -1090,40 +1202,53 @@ export async function runMethod(photonName, methodName, args) {
|
|
|
1090
1202
|
// STATELESS PATH: Direct execution
|
|
1091
1203
|
const loader = new PhotonLoader(false); // verbose=false for CLI mode
|
|
1092
1204
|
const photonInstance = await loader.loadFile(resolvedPath);
|
|
1093
|
-
//
|
|
1094
|
-
|
|
1205
|
+
// Print resume message before execution
|
|
1206
|
+
if (resumeRunId) {
|
|
1207
|
+
console.log(`Resuming workflow ${resumeRunId}...`);
|
|
1208
|
+
}
|
|
1209
|
+
// Call the method (with optional resume)
|
|
1210
|
+
result = await loader.executeTool(photonInstance, methodName, parsedArgs, { resumeRunId });
|
|
1095
1211
|
}
|
|
1212
|
+
// Check if this was a stateful workflow execution
|
|
1213
|
+
const isStateful = result && typeof result === 'object' && result._stateful === true;
|
|
1214
|
+
const actualResult = isStateful ? result.result : result;
|
|
1096
1215
|
// Display result
|
|
1097
1216
|
if (jsonOutput) {
|
|
1098
|
-
|
|
1217
|
+
// For JSON output, include workflow metadata if stateful
|
|
1218
|
+
const outputData = isStateful ? { ...result, result: actualResult } : actualResult;
|
|
1219
|
+
const jsonStr = JSON.stringify(outputData, null, 2);
|
|
1099
1220
|
baseFormatOutput(jsonStr, 'json');
|
|
1100
1221
|
// Check for errors in JSON output too
|
|
1101
|
-
if (
|
|
1222
|
+
if (actualResult && typeof actualResult === 'object' && actualResult.success === false) {
|
|
1102
1223
|
process.exit(1);
|
|
1103
1224
|
}
|
|
1104
1225
|
}
|
|
1105
1226
|
else {
|
|
1106
|
-
const formatHint = method.format || (looksLikeMarkdown(
|
|
1107
|
-
const success = formatOutput(
|
|
1227
|
+
const formatHint = method.format || (looksLikeMarkdown(actualResult) ? 'markdown' : undefined);
|
|
1228
|
+
const success = formatOutput(actualResult, formatHint);
|
|
1108
1229
|
if (!success) {
|
|
1109
1230
|
process.exit(1);
|
|
1110
1231
|
}
|
|
1232
|
+
// Show run ID for stateful workflows
|
|
1233
|
+
if (isStateful && result.runId) {
|
|
1234
|
+
console.log('');
|
|
1235
|
+
if (result.resumed && result.resumedFromStep !== undefined) {
|
|
1236
|
+
console.log(`Resumed from step ${result.resumedFromStep}, completed ${result.checkpointsCompleted} checkpoints`);
|
|
1237
|
+
}
|
|
1238
|
+
console.log(`Run ID: ${result.runId}`);
|
|
1239
|
+
}
|
|
1111
1240
|
}
|
|
1112
1241
|
}
|
|
1113
1242
|
catch (error) {
|
|
1114
|
-
//
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
console.
|
|
1123
|
-
console.log('💡 Try reconnecting with: photon cli lg-remote connect --ip <tv-ip>');
|
|
1124
|
-
}
|
|
1125
|
-
else {
|
|
1126
|
-
console.log(`❌ ${errorMsg}`);
|
|
1243
|
+
// Check for custom user-facing message from photon
|
|
1244
|
+
// Photons can throw: throw Object.assign(new Error('internal'), { userMessage: 'friendly msg', hint: 'try this' })
|
|
1245
|
+
const userMessage = (error && typeof error === 'object' && 'userMessage' in error && error.userMessage) ||
|
|
1246
|
+
getErrorMessage(error) ||
|
|
1247
|
+
'Unknown error occurred';
|
|
1248
|
+
const hint = error && typeof error === 'object' && 'hint' in error ? error.hint : undefined;
|
|
1249
|
+
logger.error(`${userMessage}`);
|
|
1250
|
+
if (hint) {
|
|
1251
|
+
console.error(`💡 ${hint}`);
|
|
1127
1252
|
}
|
|
1128
1253
|
process.exit(1);
|
|
1129
1254
|
}
|