botapp-cli 0.2.7 → 0.2.8
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/bin/bot.js +51 -21
- package/dist/bin/bot.js.map +1 -1
- package/dist/index.js +51 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/bin/bot.js
CHANGED
|
@@ -2385,7 +2385,7 @@ Invalid ACP stdout: ${line}`;
|
|
|
2385
2385
|
clientInfo: {
|
|
2386
2386
|
name: "botapp-daemon",
|
|
2387
2387
|
title: "botapp daemon",
|
|
2388
|
-
version: "0.2.
|
|
2388
|
+
version: "0.2.8"
|
|
2389
2389
|
}
|
|
2390
2390
|
});
|
|
2391
2391
|
const session = await request2("session/new", {
|
|
@@ -4492,7 +4492,7 @@ function packageJson(ctx, headless) {
|
|
|
4492
4492
|
typecheck: "tsc --noEmit"
|
|
4493
4493
|
};
|
|
4494
4494
|
const deps = {
|
|
4495
|
-
"botapp-sdk": "^0.1.
|
|
4495
|
+
"botapp-sdk": "^0.1.1",
|
|
4496
4496
|
ws: "^8.18.0"
|
|
4497
4497
|
};
|
|
4498
4498
|
const devDeps = {
|
|
@@ -4654,7 +4654,7 @@ function apiEntryTs(ctx, headless) {
|
|
|
4654
4654
|
|
|
4655
4655
|
ctx.serveStatic('./dist/public')
|
|
4656
4656
|
`;
|
|
4657
|
-
return `import { BotApp } from 'botapp-sdk'
|
|
4657
|
+
return `import { BotApp, runHosted } from 'botapp-sdk'
|
|
4658
4658
|
|
|
4659
4659
|
const app = new BotApp({
|
|
4660
4660
|
name: '${ctx.name}',
|
|
@@ -4676,7 +4676,16 @@ const app = new BotApp({
|
|
|
4676
4676
|
${widget} },
|
|
4677
4677
|
})
|
|
4678
4678
|
|
|
4679
|
-
|
|
4679
|
+
export default app
|
|
4680
|
+
|
|
4681
|
+
// Hosted-tier bridge: only connects when launched with BOTAPP_SERVER +
|
|
4682
|
+
// BOTAPP_APP_TOKEN (set by \`bot simulate\` and the platform-spawned runner).
|
|
4683
|
+
// In every other context (tests, in-process discovery) the bridge stays
|
|
4684
|
+
// dormant. Use globalThis.process so this typechecks without @types/node.
|
|
4685
|
+
const env = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env ?? {}
|
|
4686
|
+
if (env.BOTAPP_SERVER && env.BOTAPP_APP_TOKEN) {
|
|
4687
|
+
await runHosted(app)
|
|
4688
|
+
}
|
|
4680
4689
|
`;
|
|
4681
4690
|
}
|
|
4682
4691
|
function srcMainTsx(_ctx) {
|
|
@@ -4717,32 +4726,53 @@ export function App() {
|
|
|
4717
4726
|
}
|
|
4718
4727
|
function srcApiTs() {
|
|
4719
4728
|
return `// Tiny client for calling app routes/commands from the browser.
|
|
4720
|
-
//
|
|
4721
|
-
//
|
|
4729
|
+
// Two ways an app frontend reaches its backend on a botapp server:
|
|
4730
|
+
//
|
|
4731
|
+
// 1. Path-prefixed: /apps/<name>/api/commands/<cmd> (on bare apex)
|
|
4732
|
+
// 2. Subdomain: /api/apps/<name>/commands/<cmd> (on app subdomain)
|
|
4733
|
+
//
|
|
4734
|
+
// The subdomain dispatcher in the server leaves /api/* unrewritten on
|
|
4735
|
+
// subdomain hosts, so the frontend has to construct the absolute
|
|
4736
|
+
// /api/apps/<name>/... URL itself. We resolve <name> three ways and
|
|
4737
|
+
// take the first that works:
|
|
4738
|
+
// \u2022 from a /apps/<name>/ path prefix (host is the apex)
|
|
4739
|
+
// \u2022 from the first DNS label (host is <name>.<domain>)
|
|
4740
|
+
// \u2022 fallback: skip the /api/apps/<name> prefix (single-app local dev)
|
|
4722
4741
|
|
|
4723
|
-
|
|
4724
|
-
const m = location.pathname.match(/^\\/apps\\/[^/]
|
|
4725
|
-
|
|
4726
|
-
|
|
4742
|
+
function resolveAppName(): string | null {
|
|
4743
|
+
const m = location.pathname.match(/^\\/apps\\/([^/]+)\\//)
|
|
4744
|
+
if (m) return m[1]
|
|
4745
|
+
const host = location.hostname
|
|
4746
|
+
const first = host.split('.')[0]
|
|
4747
|
+
if (first && first !== 'www' && host.split('.').length >= 2) return first
|
|
4748
|
+
return null
|
|
4749
|
+
}
|
|
4727
4750
|
|
|
4728
|
-
|
|
4729
|
-
|
|
4751
|
+
const APP_NAME = resolveAppName()
|
|
4752
|
+
const API_BASE = APP_NAME ? \`/api/apps/\${APP_NAME}\` : '/api'
|
|
4753
|
+
|
|
4754
|
+
async function call(kind: 'commands' | 'actions', name: string, params: Record<string, unknown>): Promise<unknown> {
|
|
4755
|
+
const r = await fetch(\`\${API_BASE}/\${kind}/\${encodeURIComponent(name)}\`, {
|
|
4730
4756
|
method: 'POST',
|
|
4731
4757
|
headers: { 'Content-Type': 'application/json' },
|
|
4732
4758
|
body: JSON.stringify(params),
|
|
4733
4759
|
})
|
|
4734
4760
|
if (!r.ok) throw new Error(await r.text())
|
|
4735
|
-
|
|
4761
|
+
// The /api/apps/<name>/... handler wraps responses as
|
|
4762
|
+
// \`{ status: 'success', result }\` or \`{ status: 'error', error }\`.
|
|
4763
|
+
// Unwrap so callers see the bare result; throw on error.
|
|
4764
|
+
const json = (await r.json()) as { status?: string; result?: unknown; error?: string }
|
|
4765
|
+
if (json.status === 'error') throw new Error(json.error ?? 'unknown error')
|
|
4766
|
+
if (json.status === 'success') return json.result
|
|
4767
|
+
return json
|
|
4768
|
+
}
|
|
4769
|
+
|
|
4770
|
+
export async function callCommand(name: string, params: Record<string, unknown> = {}) {
|
|
4771
|
+
return call('commands', name, params)
|
|
4736
4772
|
}
|
|
4737
4773
|
|
|
4738
4774
|
export async function callAction(name: string, params: Record<string, unknown> = {}) {
|
|
4739
|
-
|
|
4740
|
-
method: 'POST',
|
|
4741
|
-
headers: { 'Content-Type': 'application/json' },
|
|
4742
|
-
body: JSON.stringify(params),
|
|
4743
|
-
})
|
|
4744
|
-
if (!r.ok) throw new Error(await r.text())
|
|
4745
|
-
return r.json()
|
|
4775
|
+
return call('actions', name, params)
|
|
4746
4776
|
}
|
|
4747
4777
|
`;
|
|
4748
4778
|
}
|
|
@@ -5009,7 +5039,7 @@ function die(msg) {
|
|
|
5009
5039
|
}
|
|
5010
5040
|
|
|
5011
5041
|
// src/index.ts
|
|
5012
|
-
var version = "0.2.
|
|
5042
|
+
var version = "0.2.8";
|
|
5013
5043
|
var program = new Command25().name("bot").description("botapp CLI \u2014 operate apps from the command line").version(version).enablePositionalOptions(true).option("--json", "Output as JSON").option("-s, --server <url>", "Server URL override").option("-t, --token <token>", "Auth token override").option("-v, --verbose", "Verbose output");
|
|
5014
5044
|
program.addCommand(launchCommand);
|
|
5015
5045
|
program.addCommand(runCommand);
|