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