agent-message 0.1.1 → 0.1.2
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 +3 -3
- package/npm/bin/agent-message.mjs +60 -3
- package/npm/runtime/bin/agent-message-cli-darwin-amd64 +0 -0
- package/npm/runtime/bin/agent-message-cli-darwin-arm64 +0 -0
- package/npm/runtime/bin/agent-message-server-darwin-amd64 +0 -0
- package/npm/runtime/bin/agent-message-server-darwin-arm64 +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,10 +22,10 @@ agent-message stop
|
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
Default ports:
|
|
25
|
-
- API: `127.0.0.1:
|
|
26
|
-
- Web: `127.0.0.1:
|
|
25
|
+
- API: `127.0.0.1:45180`
|
|
26
|
+
- Web: `127.0.0.1:45788`
|
|
27
27
|
|
|
28
|
-
After `agent-message start`, open `http://127.0.0.1:
|
|
28
|
+
After `agent-message start`, open `http://127.0.0.1:45788` in your browser.
|
|
29
29
|
The bundled CLI continues to work from the same command:
|
|
30
30
|
|
|
31
31
|
```bash
|
|
@@ -9,9 +9,9 @@ import process from 'node:process'
|
|
|
9
9
|
import { fileURLToPath } from 'node:url'
|
|
10
10
|
|
|
11
11
|
const DEFAULT_API_HOST = '127.0.0.1'
|
|
12
|
-
const DEFAULT_API_PORT =
|
|
12
|
+
const DEFAULT_API_PORT = 45180
|
|
13
13
|
const DEFAULT_WEB_HOST = '127.0.0.1'
|
|
14
|
-
const DEFAULT_WEB_PORT =
|
|
14
|
+
const DEFAULT_WEB_PORT = 45788
|
|
15
15
|
const STARTUP_ATTEMPTS = 40
|
|
16
16
|
const STARTUP_DELAY_MS = 500
|
|
17
17
|
const PROCESS_STOP_DELAY_MS = 1000
|
|
@@ -170,6 +170,7 @@ function runtimePaths(runtimeDir) {
|
|
|
170
170
|
gatewayLog: join(runtimeDir, 'logs', 'gateway.log'),
|
|
171
171
|
serverPidfile: join(runtimeDir, 'server.pid'),
|
|
172
172
|
gatewayPidfile: join(runtimeDir, 'gateway.pid'),
|
|
173
|
+
stackMetadataPath: join(runtimeDir, 'stack.json'),
|
|
173
174
|
sqlitePath: join(runtimeDir, 'agent_message.sqlite'),
|
|
174
175
|
}
|
|
175
176
|
}
|
|
@@ -216,6 +217,7 @@ async function startStack(options) {
|
|
|
216
217
|
writeFileSync(paths.gatewayPidfile, `${gatewayChild.pid}\n`)
|
|
217
218
|
|
|
218
219
|
await waitForHttp(`http://${options.webHost}:${options.webPort}`, 'web gateway')
|
|
220
|
+
writeStackMetadata(paths.stackMetadataPath, options)
|
|
219
221
|
} catch (error) {
|
|
220
222
|
await stopStack(options, { quiet: true })
|
|
221
223
|
throw error
|
|
@@ -231,6 +233,7 @@ async function stopStack(options, { quiet }) {
|
|
|
231
233
|
const paths = runtimePaths(options.runtimeDir)
|
|
232
234
|
const stoppedServer = await killFromPidfile(paths.serverPidfile)
|
|
233
235
|
const stoppedGateway = await killFromPidfile(paths.gatewayPidfile)
|
|
236
|
+
rmSync(paths.stackMetadataPath, { force: true })
|
|
234
237
|
|
|
235
238
|
if (!quiet) {
|
|
236
239
|
if (stoppedServer || stoppedGateway) {
|
|
@@ -259,7 +262,8 @@ async function printStatus(options) {
|
|
|
259
262
|
|
|
260
263
|
function delegateToBundledCli(args) {
|
|
261
264
|
const cliBinary = resolveBinaryPath('agent-message-cli')
|
|
262
|
-
const
|
|
265
|
+
const delegatedArgs = buildDelegatedCliArgs(args)
|
|
266
|
+
const result = spawnSync(cliBinary, delegatedArgs, {
|
|
263
267
|
stdio: 'inherit',
|
|
264
268
|
env: process.env,
|
|
265
269
|
})
|
|
@@ -276,6 +280,59 @@ function delegateToBundledCli(args) {
|
|
|
276
280
|
process.exit(result.status ?? 1)
|
|
277
281
|
}
|
|
278
282
|
|
|
283
|
+
function buildDelegatedCliArgs(args) {
|
|
284
|
+
if (shouldSkipLocalServerOverride(args) || hasExplicitServerURL(args)) {
|
|
285
|
+
return args
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const localServerURL = readLocalServerURL()
|
|
289
|
+
if (!localServerURL) {
|
|
290
|
+
return args
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return ['--server-url', localServerURL, ...args]
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function shouldSkipLocalServerOverride(args) {
|
|
297
|
+
const [command] = args
|
|
298
|
+
return command === undefined || command === 'config' || command === 'profile'
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function hasExplicitServerURL(args) {
|
|
302
|
+
return args.some((arg) => arg === '--server-url' || arg.startsWith('--server-url='))
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function readLocalServerURL() {
|
|
306
|
+
const paths = runtimePaths(join(os.homedir(), '.agent-message'))
|
|
307
|
+
const serverPid = readPidfile(paths.serverPidfile)
|
|
308
|
+
if (serverPid === null || !isPidAlive(serverPid)) {
|
|
309
|
+
return null
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
try {
|
|
313
|
+
const raw = readFileSync(paths.stackMetadataPath, 'utf8')
|
|
314
|
+
const metadata = JSON.parse(raw)
|
|
315
|
+
const apiHost = typeof metadata.apiHost === 'string' ? metadata.apiHost.trim() : ''
|
|
316
|
+
const apiPort = metadata.apiPort
|
|
317
|
+
if (!apiHost || !Number.isInteger(apiPort) || apiPort <= 0 || apiPort > 65535) {
|
|
318
|
+
return null
|
|
319
|
+
}
|
|
320
|
+
return `http://${apiHost}:${apiPort}`
|
|
321
|
+
} catch {
|
|
322
|
+
return null
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function writeStackMetadata(path, options) {
|
|
327
|
+
const metadata = {
|
|
328
|
+
apiHost: options.apiHost,
|
|
329
|
+
apiPort: options.apiPort,
|
|
330
|
+
webHost: options.webHost,
|
|
331
|
+
webPort: options.webPort,
|
|
332
|
+
}
|
|
333
|
+
writeFileSync(path, `${JSON.stringify(metadata, null, 2)}\n`)
|
|
334
|
+
}
|
|
335
|
+
|
|
279
336
|
function spawnDetached(command, args, env, logFile) {
|
|
280
337
|
const stdoutFd = openSync(logFile, 'a')
|
|
281
338
|
const stderrFd = openSync(logFile, 'a')
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|