@fastagent-sh/fastagent 0.20.0 → 0.21.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/README.md +5 -1
- package/dist/channels/agentcore-protocol.d.ts +112 -0
- package/dist/channels/agentcore-protocol.js +22 -0
- package/dist/channels/agentcore-service.d.ts +0 -4
- package/dist/channels/agentcore-service.js +1 -6
- package/dist/channels/agentcore-state.d.ts +5 -11
- package/dist/channels/agentcore-state.js +4 -1
- package/dist/channels/agentcore.d.ts +1 -67
- package/dist/channels/agentcore.js +90 -89
- package/dist/channels/control.d.ts +1 -1
- package/dist/channels/control.js +13 -62
- package/dist/channels/discover.d.ts +0 -1
- package/dist/channels/discover.js +1 -3
- package/dist/channels/feishu/context-buffer.d.ts +6 -0
- package/dist/channels/feishu/context-buffer.js +0 -38
- package/dist/channels/feishu/crypto.d.ts +0 -2
- package/dist/channels/feishu/crypto.js +3 -8
- package/dist/channels/feishu/feishu-api.js +2 -4
- package/dist/channels/feishu/feishu.js +56 -115
- package/dist/channels/feishu/parse.d.ts +4 -3
- package/dist/channels/feishu/parse.js +5 -4
- package/dist/channels/feishu/register-webhook.d.ts +5 -5
- package/dist/channels/feishu/register-webhook.js +43 -57
- package/dist/channels/feishu/scaffold/feishu-send.ts +12 -67
- package/dist/channels/feishu/setup-mode.d.ts +30 -0
- package/dist/channels/feishu/setup-mode.js +26 -0
- package/dist/channels/feishu/shared-api.d.ts +10 -0
- package/dist/channels/feishu/shared-api.js +38 -0
- package/dist/channels/http.d.ts +0 -8
- package/dist/channels/http.js +4 -56
- package/dist/channels/kit/turn-runner.d.ts +59 -0
- package/dist/channels/kit/turn-runner.js +84 -0
- package/dist/channels/lark/scaffold/lark-send.ts +12 -67
- package/dist/channels/registration.d.ts +36 -1
- package/dist/channels/registration.js +57 -1
- package/dist/channels/secret.d.ts +1 -0
- package/dist/channels/secret.js +16 -0
- package/dist/channels/slack/config-api.d.ts +35 -3
- package/dist/channels/slack/config-api.js +51 -9
- package/dist/channels/slack/manifest.js +5 -1
- package/dist/channels/slack/onboard.d.ts +5 -5
- package/dist/channels/slack/onboard.js +41 -20
- package/dist/channels/slack/register-webhook.d.ts +3 -2
- package/dist/channels/slack/register-webhook.js +34 -14
- package/dist/channels/slack/scaffold/channel.ts +3 -10
- package/dist/channels/slack/scaffold/slack-send.ts +18 -126
- package/dist/channels/slack/shared-api.d.ts +10 -0
- package/dist/channels/slack/shared-api.js +34 -0
- package/dist/channels/slack/slack-api.d.ts +20 -2
- package/dist/channels/slack/slack-api.js +81 -22
- package/dist/channels/slack/slack.d.ts +0 -10
- package/dist/channels/slack/slack.js +60 -99
- package/dist/channels/sse.d.ts +4 -0
- package/dist/channels/sse.js +66 -0
- package/dist/channels/telegram/register-webhook.d.ts +6 -9
- package/dist/channels/telegram/register-webhook.js +44 -42
- package/dist/channels/telegram/telegram.js +47 -142
- package/dist/channels/wait-health.js +7 -4
- package/dist/cli/add-feishu.js +3 -10
- package/dist/cli/add-slack.js +7 -20
- package/dist/cli/commands/add.d.ts +0 -1
- package/dist/cli/commands/add.js +22 -31
- package/dist/cli/commands/chat.js +6 -12
- package/dist/cli/commands/deploy/agentcore.d.ts +2 -0
- package/dist/cli/commands/deploy/agentcore.js +178 -0
- package/dist/cli/commands/deploy/docker.d.ts +2 -0
- package/dist/cli/commands/deploy/docker.js +119 -0
- package/dist/cli/commands/deploy/fly.d.ts +2 -0
- package/dist/cli/commands/deploy/fly.js +131 -0
- package/dist/cli/commands/deploy/railway.d.ts +2 -0
- package/dist/cli/commands/deploy/railway.js +71 -0
- package/dist/cli/commands/deploy/shared.d.ts +114 -0
- package/dist/cli/commands/deploy/shared.js +124 -0
- package/dist/cli/commands/deploy.d.ts +17 -49
- package/dist/cli/commands/deploy.js +39 -618
- package/dist/cli/commands/dev.js +17 -46
- package/dist/cli/commands/fire.js +6 -12
- package/dist/cli/commands/info.js +2 -1
- package/dist/cli/commands/invoke.js +4 -11
- package/dist/cli/commands/schedule.js +1 -1
- package/dist/cli/commands/start.js +17 -46
- package/dist/cli/commands/tool.js +3 -8
- package/dist/cli/kernel.d.ts +0 -2
- package/dist/cli/kernel.js +0 -2
- package/dist/cli/program.js +7 -12
- package/dist/cli/serve.d.ts +36 -19
- package/dist/cli/serve.js +91 -7
- package/dist/cli/shared.d.ts +13 -18
- package/dist/cli/shared.js +20 -4
- package/dist/deploy/agentcore/forwarder.js +250 -0
- package/dist/deploy/agentcore/plan.d.ts +23 -2
- package/dist/deploy/agentcore/plan.js +29 -244
- package/dist/deploy/agentcore/run.d.ts +4 -20
- package/dist/deploy/agentcore/run.js +22 -7
- package/dist/deploy/channel-ingress.js +1 -1
- package/dist/deploy/docker/run.d.ts +17 -3
- package/dist/deploy/docker/run.js +30 -8
- package/dist/deploy/fly/plan.js +7 -0
- package/dist/deploy/fly/run.d.ts +27 -0
- package/dist/deploy/fly/run.js +102 -20
- package/dist/deploy/hosts.d.ts +5 -0
- package/dist/deploy/hosts.js +4 -0
- package/dist/deploy/preflight.js +3 -3
- package/dist/deploy/railway/plan.d.ts +5 -0
- package/dist/deploy/railway/plan.js +7 -0
- package/dist/deploy/railway/run.d.ts +2 -1
- package/dist/deploy/railway/run.js +5 -4
- package/dist/deploy/secrets.js +0 -17
- package/dist/engines/pi/agent-session-factory.d.ts +37 -17
- package/dist/engines/pi/agent-session-factory.js +109 -85
- package/dist/engines/pi/config.d.ts +1 -1
- package/dist/engines/pi/create.d.ts +22 -39
- package/dist/engines/pi/create.js +58 -73
- package/dist/engines/pi/definition.js +8 -8
- package/dist/engines/pi/invoke-session.js +13 -30
- package/dist/engines/pi/open.d.ts +2 -2
- package/dist/engines/pi/open.js +31 -41
- package/dist/engines/pi/retry-event.d.ts +6 -0
- package/dist/engines/pi/retry-event.js +15 -0
- package/dist/engines/pi/session-builder.js +26 -113
- package/dist/engines/pi/session-control.d.ts +10 -18
- package/dist/engines/pi/session-control.js +47 -81
- package/dist/engines/pi/session-settings.d.ts +1 -1
- package/dist/engines/pi/session-settings.js +1 -1
- package/dist/engines/pi/session-store.d.ts +12 -17
- package/dist/engines/pi/session-store.js +18 -40
- package/dist/engines/pi/tool-context.d.ts +3 -3
- package/dist/engines/pi/tool.d.ts +6 -9
- package/dist/engines/pi/tool.js +1 -0
- package/dist/feishu.d.ts +1 -0
- package/dist/feishu.js +1 -0
- package/dist/lark.d.ts +1 -0
- package/dist/lark.js +1 -0
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +5 -0
- package/dist/log.d.ts +9 -17
- package/dist/log.js +25 -30
- package/dist/paths.d.ts +7 -3
- package/dist/paths.js +17 -4
- package/dist/scaffold/add-channel.d.ts +6 -1
- package/dist/scaffold/add-channel.js +48 -65
- package/dist/schedule/wake-alarm.d.ts +1 -12
- package/dist/schedule/wake-alarm.js +2 -3
- package/dist/service.d.ts +23 -22
- package/dist/service.js +7 -73
- package/dist/session-remote.d.ts +5 -5
- package/dist/session-remote.js +25 -28
- package/dist/session.d.ts +1 -1
- package/dist/slack.d.ts +2 -0
- package/dist/slack.js +1 -0
- package/dist/tunnel.d.ts +16 -6
- package/dist/tunnel.js +53 -12
- package/package.json +5 -4
- package/dist/channels/slack/bot-auth.d.ts +0 -15
- package/dist/channels/slack/bot-auth.js +0 -135
|
@@ -1,61 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `fastagent deploy <host> [dir]`: generate host artifacts from the resolved definition and print an
|
|
3
|
-
* ordered deploy runbook. Host-scoped (`docker` | `fly` | `railway` — the extension seam). It does NOT
|
|
4
|
-
* run the host CLI by default: fastagent owns the definition-aware artifacts and precise runbook;
|
|
5
|
-
* Docker may opt into a generated ephemeral tunnel, while durable ingress stays operator-owned. The pre-flight
|
|
6
|
-
* (config/model/channels/container facts) is host-neutral; the host branch adds its config + run drive.
|
|
7
|
-
* Read-only on the definition; the only writes are generated artifacts (never clobbered without
|
|
8
|
-
* --force). `--run` drives the target CLI instead of printing.
|
|
9
|
-
*/
|
|
10
|
-
import { MAX_WEBHOOK_BODY_BYTES } from "../../channels/agentcore-limits.js";
|
|
11
|
-
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
12
|
-
import { tmpdir } from "node:os";
|
|
13
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
14
|
-
import { registerFeishuWebhook } from "../../channels/feishu/register-webhook.js";
|
|
15
|
-
import { readSlackBotAuthEnv } from "../../channels/slack/bot-auth.js";
|
|
16
|
-
import { registerSlackWebhook } from "../../channels/slack/register-webhook.js";
|
|
17
|
-
import { registerTelegramWebhook } from "../../channels/telegram/register-webhook.js";
|
|
18
|
-
import { FORWARDER_FILE, TEMPLATE_FILE, agentcoreName, isGeneratedAgentcoreTemplate, planAgentcoreDeploy, } from "../../deploy/agentcore/plan.js";
|
|
19
|
-
import { deployAgentcoreRun } from "../../deploy/agentcore/run.js";
|
|
20
|
-
import { webhookPaths } from "../../deploy/channel-ingress.js";
|
|
21
|
-
import { isGeneratedDockerfile, isGeneratedDockerignore } from "../../deploy/container.js";
|
|
22
|
-
import { composeHasTunnelService, isGeneratedCompose, planDockerDeploy, toDockerProjectName, } from "../../deploy/docker/plan.js";
|
|
23
|
-
import { deployDockerRun } from "../../deploy/docker/run.js";
|
|
24
|
-
import { isGeneratedFlyToml, parseFlyAppName, parseFlyMinMachines, parseFlyRegion, planFlyDeploy, toFlyAppName, } from "../../deploy/fly/plan.js";
|
|
25
|
-
import { deployFlyRun } from "../../deploy/fly/run.js";
|
|
26
1
|
import { preflightDeploy } from "../../deploy/preflight.js";
|
|
27
|
-
import { dockerfilePathVar, isGeneratedRailwayJson, planRailwayDeploy } from "../../deploy/railway/plan.js";
|
|
28
|
-
import { deployRailwayRun } from "../../deploy/railway/run.js";
|
|
29
|
-
import { spawnRunner } from "../../deploy/runner.js";
|
|
30
|
-
import { assembleSecrets } from "../../deploy/secrets.js";
|
|
31
|
-
import { loadDotEnv } from "../../env.js";
|
|
32
2
|
import { loadConfig, resolveModelSpec } from "../../engines/pi/config.js";
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
telegram: (baseUrl) => registerTelegramWebhook(baseUrl),
|
|
51
|
-
slack: (baseUrl) => registerSlackWebhook(baseUrl, { stateRoot: resolveStateRoot(agentDir) }),
|
|
52
|
-
feishu: (baseUrl, kind) => registerFeishuWebhook(baseUrl, kind),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/** A copy/paste-safe POSIX shell argument for the command hints deploy prints. */
|
|
56
|
-
function shellArg(value) {
|
|
57
|
-
return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
58
|
-
}
|
|
3
|
+
import { failStartup, failUsage } from "../fail.js";
|
|
4
|
+
import { enterAgentCommand } from "../shared.js";
|
|
5
|
+
import { agentcoreHost } from "./deploy/agentcore.js";
|
|
6
|
+
import { dockerHost } from "./deploy/docker.js";
|
|
7
|
+
import { flyHost } from "./deploy/fly.js";
|
|
8
|
+
import { railwayHost } from "./deploy/railway.js";
|
|
9
|
+
import { writeArtifacts } from "./deploy/shared.js";
|
|
10
|
+
export { writeArtifacts };
|
|
11
|
+
/** Every host, by the name the CLI takes. Typed over {@link DeployHost} so a host added to the list
|
|
12
|
+
* without a module here fails to compile. */
|
|
13
|
+
export const HOSTS = {
|
|
14
|
+
docker: dockerHost,
|
|
15
|
+
fly: flyHost,
|
|
16
|
+
railway: railwayHost,
|
|
17
|
+
agentcore: agentcoreHost,
|
|
18
|
+
};
|
|
59
19
|
/** Infers `Owner` from the literal's own `owner`, so each row carries its exhaustiveness itself. The
|
|
60
20
|
* alternative — annotating the array as a tuple of `HostOnlyFlag<"fly"> | …` — put the whole guarantee
|
|
61
21
|
* in one annotation that a third rule invites relaxing to `HostOnlyFlag<DeployHost>[]`, where
|
|
@@ -118,49 +78,20 @@ export function warnHostOnlyFlags(host, opts) {
|
|
|
118
78
|
console.error(`[fastagent] warn: ${rule.flag}: ${rule.owner}-only — ${instead}`);
|
|
119
79
|
}
|
|
120
80
|
}
|
|
121
|
-
/**
|
|
122
|
-
* The `--run` credential carry, for every host: the local model credential (an env key, or the whole
|
|
123
|
-
* auth.json as a `FASTAGENT_AUTH_SEED`) plus channel secrets, read through the one environment that
|
|
124
|
-
* accounts for Slack's rotated bot token. Four drivers assembled this identically; a fifth would have
|
|
125
|
-
* had to remember the `deployEnvironment` wrapper, which is invisible when forgotten (a rotated token
|
|
126
|
-
* silently deploys stale).
|
|
127
|
-
*/
|
|
128
|
-
async function carryCredentials(params) {
|
|
129
|
-
const { agentDir, modelAuth, modelKeyInDefinition, authPath, channels, extraSecrets } = params;
|
|
130
|
-
return assembleSecrets({
|
|
131
|
-
modelAuth,
|
|
132
|
-
modelKeyInDefinition,
|
|
133
|
-
authFile: (await exists(authPath)) ? await readFile(authPath) : undefined,
|
|
134
|
-
channels,
|
|
135
|
-
extraSecrets,
|
|
136
|
-
env: deployEnvironment(agentDir, channels),
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/** Gate a `--run` that has no model credential to carry. Its remediation is `fastagent login`, which
|
|
140
|
-
* is why it is separate from `missingSecrets` (a `.env` fix) rather than folded into it. Docker states
|
|
141
|
-
* the same gate inside its driver, where it belongs after the daemon check. */
|
|
142
|
-
function gateOnModelCredential(needsModelCredential) {
|
|
143
|
-
if (!needsModelCredential)
|
|
144
|
-
return;
|
|
145
|
-
failStartup(new Error(`deploy stopped: no model credential — run \`fastagent login\`, or set a provider API key in .env, then re-run`));
|
|
146
|
-
}
|
|
147
81
|
export async function runDeploy(host, dirArg, opts) {
|
|
148
|
-
// ONE deploy semantic: bake the WORKSPACE (WYSIWYG). Artifacts land under the agent dir
|
|
149
|
-
// (`fastagent/`) plus the one workspace-root `.dockerignore` the packers require; host CLIs run
|
|
150
|
-
// from the workspace, which is the build context.
|
|
151
|
-
const placement = placementOrExit(resolve(dirArg));
|
|
152
|
-
const { agentDir, workspace } = placement;
|
|
153
82
|
if (opts.tunnel && host !== "docker") {
|
|
154
83
|
// A flag/host combination the parser cannot see (host is an argument) — usage class, exit 2.
|
|
155
84
|
failUsage(`deploy stopped: --tunnel is supported only by the local Docker target`);
|
|
156
85
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
//
|
|
163
|
-
|
|
86
|
+
// The picker's write-back lands the model in fastagent.config.* — exactly what the model-travel
|
|
87
|
+
// gate below requires (--model/env don't reach the deployed box) — and an inline login stores the
|
|
88
|
+
// credential `--run` then carries. Runs BEFORE loadConfig; the read-back sees the rewritten file
|
|
89
|
+
// because loadConfig cache-busts on mtime (a failed write-back still gates, correctly).
|
|
90
|
+
const placement = await enterAgentCommand(dirArg, opts);
|
|
91
|
+
// ONE deploy semantic: bake the WORKSPACE (WYSIWYG). Artifacts land under the agent dir
|
|
92
|
+
// (`fastagent/`) plus the one workspace-root `.dockerignore` the packers require; host CLIs run
|
|
93
|
+
// from the workspace, which is the build context.
|
|
94
|
+
const { agentDir, workspace } = placement;
|
|
164
95
|
const { config } = await loadConfig(agentDir).catch(failStartup);
|
|
165
96
|
const modelSpec = resolveModelSpec(opts.model, config);
|
|
166
97
|
// The host-neutral pre-flight (model-travel gate, channel discovery, model-auth probe, container facts +
|
|
@@ -179,531 +110,21 @@ export async function runDeploy(host, dirArg, opts) {
|
|
|
179
110
|
failStartup(new Error(`deploy stopped: ${pre.gate}`));
|
|
180
111
|
for (const m of pre.messages)
|
|
181
112
|
console.error(`[fastagent] ${m.level}: ${m.text}`);
|
|
182
|
-
const { channels
|
|
183
|
-
const webhookChannels = channels.filter((channel) => channel.ingress === "webhook");
|
|
184
|
-
const longConnectionChannels = channels.filter((channel) => channel.ingress === "long-connection");
|
|
185
|
-
const hasDeclaredChannels = channels.length > 0;
|
|
113
|
+
const { channels } = pre;
|
|
186
114
|
warnHostOnlyFlags(host, opts);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
modelAuth,
|
|
195
|
-
channels,
|
|
196
|
-
tunnel,
|
|
197
|
-
extraSecrets,
|
|
198
|
-
...container,
|
|
199
|
-
});
|
|
200
|
-
const requestedTunnel = !!opts.tunnel && (!hasDeclaredChannels || webhookChannels.length > 0);
|
|
201
|
-
if (opts.tunnel && hasDeclaredChannels && webhookChannels.length === 0) {
|
|
202
|
-
console.error(`[fastagent] note: --tunnel skipped — every channel uses a long connection`);
|
|
203
|
-
}
|
|
204
|
-
let plan = dockerPlan(requestedTunnel);
|
|
205
|
-
// An existing Compose file is authoritative: shape its comparison/runbook from the topology on disk,
|
|
206
|
-
// regardless of the current flag. `--force` is the explicit reset to the requested generated shape.
|
|
207
|
-
const composeFile = join(workspace, plan.composePath);
|
|
208
|
-
let keptWithoutRequestedTunnel = false;
|
|
209
|
-
// Same ownership question as fly.toml: a hand-owned compose file survives --force, so the plan must
|
|
210
|
-
// describe the topology that will actually be there.
|
|
211
|
-
const composeText = await readFile(composeFile, "utf8").catch(() => undefined);
|
|
212
|
-
if (composeText !== undefined && (!opts.force || !isGeneratedCompose(composeText))) {
|
|
213
|
-
const existingHasTunnel = composeHasTunnelService(composeText);
|
|
214
|
-
plan = dockerPlan(existingHasTunnel);
|
|
215
|
-
keptWithoutRequestedTunnel = requestedTunnel && !existingHasTunnel;
|
|
216
|
-
}
|
|
217
|
-
await writeArtifacts(workspace, plan.artifacts, {
|
|
218
|
-
force: !!opts.force,
|
|
219
|
-
});
|
|
220
|
-
if (opts.run) {
|
|
221
|
-
return runDeployDocker({
|
|
222
|
-
agentDir,
|
|
223
|
-
workspace,
|
|
224
|
-
composeFile: plan.composePath,
|
|
225
|
-
port,
|
|
226
|
-
requireTunnel: requestedTunnel,
|
|
227
|
-
modelAuth,
|
|
228
|
-
modelKeyInDefinition,
|
|
229
|
-
authPath,
|
|
230
|
-
channels,
|
|
231
|
-
extraSecrets,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
if (keptWithoutRequestedTunnel) {
|
|
235
|
-
console.error(`[fastagent] warn: --tunnel was requested but kept ${plan.composePath} has no "tunnel" service — ` +
|
|
236
|
-
`edit it, delete it and regenerate, or pass --force`);
|
|
237
|
-
}
|
|
238
|
-
console.log(plan.runbook.join("\n"));
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
// Railway: thin config file, scale-to-zero is a manual dashboard step, the URL is minted (see
|
|
242
|
-
// planRailwayDeploy). --run drives the railway CLI to completion; otherwise print the runbook.
|
|
243
|
-
if (host === "railway") {
|
|
244
|
-
// Railway service names are project-scoped (not globally unique like a Fly app); slug the dir
|
|
245
|
-
// basename so a name with spaces/odd chars can't break the `railway add --service <name>` command.
|
|
246
|
-
const serviceName = basename(workspace)
|
|
247
|
-
.replace(/[^a-zA-Z0-9-]+/g, "-")
|
|
248
|
-
.replace(/^-+|-+$/g, "") || "agent";
|
|
249
|
-
const plan = planRailwayDeploy({
|
|
250
|
-
serviceName,
|
|
251
|
-
modelAuth,
|
|
252
|
-
channels,
|
|
253
|
-
extraSecrets,
|
|
254
|
-
hasTimeTriggers,
|
|
255
|
-
...container,
|
|
256
|
-
});
|
|
257
|
-
await writeArtifacts(workspace, plan.artifacts, {
|
|
258
|
-
force: !!opts.force,
|
|
259
|
-
});
|
|
260
|
-
if (opts.run) {
|
|
261
|
-
// The BUILD entry is guaranteed by the RAILWAY_DOCKERFILE_PATH service variable the runner sets
|
|
262
|
-
// (Railway's documented non-root-Dockerfile route), and Railway's default restart policy already
|
|
263
|
-
// equals the file's ON_FAILURE — the dashboard-only Config-as-code pointer only adds the /health
|
|
264
|
-
// deploy gate (boot-crash visibility), so it is an OPTIONAL note, not a gate.
|
|
265
|
-
console.error(`[fastagent] note: optional — point the service at fastagent/railway.json (Service → Settings → ` +
|
|
266
|
-
`Config-as-code, dashboard-only) so the /health healthcheck marks a boot-crashing deploy as FAILED; ` +
|
|
267
|
-
`the build already uses fastagent/Dockerfile via the RAILWAY_DOCKERFILE_PATH variable`);
|
|
268
|
-
return runDeployRailway({
|
|
269
|
-
agentDir,
|
|
270
|
-
workspace,
|
|
271
|
-
name: serviceName,
|
|
272
|
-
modelAuth,
|
|
273
|
-
modelKeyInDefinition,
|
|
274
|
-
authPath,
|
|
275
|
-
channels,
|
|
276
|
-
extraSecrets,
|
|
277
|
-
intoLinked: !!opts.intoLinked,
|
|
278
|
-
dockerfilePath: dockerfilePathVar(pre.container.agentPrefix),
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
console.log(plan.runbook.join("\n"));
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
// AgentCore: one CloudFormation stack (runtime + forwarder Lambda + EventBridge schedules); no
|
|
285
|
-
// public URL and no resident process — see deploy/agentcore/plan.ts for the topology decisions.
|
|
286
|
-
if (host === "agentcore") {
|
|
287
|
-
// Long-connection channels are STRUCTURALLY unsupported: the connection is the ingress, and a
|
|
288
|
-
// reclaimed session has nothing to wake it — events in the gap are silently lost. `--run` gates
|
|
289
|
-
// (deploying a channel that can't connect); generate-only warns and prints the runbook.
|
|
290
|
-
if (longConnectionChannels.length > 0) {
|
|
291
|
-
const msg = `long-connection channel (${longConnectionChannels.map((c) => c.name).join(", ")}) cannot run on AgentCore — there is no ` +
|
|
292
|
-
`resident process to hold the connection, and nothing wakes a reclaimed session. Switch the channel ` +
|
|
293
|
-
`to webhook mode (its events then ride the forwarder like every other channel).`;
|
|
294
|
-
if (opts.run)
|
|
295
|
-
failStartup(new Error(`deploy stopped: ${msg}`));
|
|
296
|
-
console.error(`[fastagent] warn: ${msg}`);
|
|
297
|
-
}
|
|
298
|
-
// selfSchedule is fully supported: pending wake-ups are mirrored into one-shot EventBridge
|
|
299
|
-
// schedules via the forwarder (the wake-alarm mechanism — see deploy/agentcore/plan.ts).
|
|
300
|
-
// Schedules feed EventBridge rules — parsed facts (cron/tz), not just file names, so a bad file
|
|
301
|
-
// must surface here (a schedule silently missing its rule would never fire).
|
|
302
|
-
const loaded = await loadSchedules(agentDir).catch(failStartup);
|
|
303
|
-
if (loaded.failures.length > 0) {
|
|
304
|
-
failStartup(new Error(`deploy stopped: cannot load schedules: ${loaded.failures.map((x) => `${x.label}: ${x.message}`).join("; ")}`));
|
|
305
|
-
}
|
|
306
|
-
const acName = agentcoreName(basename(workspace));
|
|
307
|
-
// Every derived AWS name embeds acName; the tightest ceiling is the Lambda function name
|
|
308
|
-
// (`fastagent-<name>-forwarder` ≤ 64 chars). Gate the base instead of silently truncating —
|
|
309
|
-
// truncation would break the redeploy identity (a renamed stack starts blank state).
|
|
310
|
-
if (acName.length > 40) {
|
|
311
|
-
failStartup(new Error(`deploy stopped: the directory name maps to "${acName}" (${acName.length} chars) — AWS resource ` +
|
|
312
|
-
`names derived from it exceed their limits past 40 chars. Deploy from a shorter directory name.`));
|
|
313
|
-
}
|
|
314
|
-
const plan = planAgentcoreDeploy({
|
|
315
|
-
name: acName,
|
|
316
|
-
modelAuth,
|
|
317
|
-
channels,
|
|
318
|
-
extraSecrets,
|
|
319
|
-
schedules: loaded.schedules.map((s) => ({ name: s.name, cron: s.cron, tz: s.tz })),
|
|
320
|
-
selfSchedule: !!config.selfSchedule,
|
|
321
|
-
...container,
|
|
322
|
-
});
|
|
323
|
-
for (const u of plan.untranslatableSchedules) {
|
|
324
|
-
// Same discipline as Fly's kept-toml time-trigger gate: a deploy whose schedule silently never
|
|
325
|
-
// fires is worse than a stopped deploy — nothing fails visibly when the instant passes.
|
|
326
|
-
const msg = `schedule "${u.name}" cannot be expressed as an EventBridge rule — ${u.reason}`;
|
|
327
|
-
if (opts.run)
|
|
328
|
-
failStartup(new Error(`deploy stopped: ${msg}`));
|
|
329
|
-
console.error(`[fastagent] warn: ${msg} — it will NOT fire on this deployment`);
|
|
330
|
-
}
|
|
331
|
-
// Host capability limit, stated at plan time. GitHub's own webhook contract is 25 MiB, but a
|
|
332
|
-
// Lambda Function URL request caps at 6 MB — so on this host a large payload cannot arrive at
|
|
333
|
-
// all. Better a sentence here than an opaque 502 the first time someone pushes a big diff.
|
|
334
|
-
if (channels.some((channel) => channel.name === "github")) {
|
|
335
|
-
console.error(`[fastagent] note: on AgentCore a webhook body is capped at ~${Math.round(MAX_WEBHOOK_BODY_BYTES / (1 << 20))} MiB ` +
|
|
336
|
-
`(the forwarder's Function URL limit); the GitHub channel accepts 25 MiB on a resident host, so the largest ` +
|
|
337
|
-
`payloads are rejected here rather than delivered`);
|
|
338
|
-
}
|
|
339
|
-
// The template IS the topology (EventBridge rules, wake wiring, secrets) — a kept generated
|
|
340
|
-
// template that no longer matches the definition would deploy a stack silently missing the
|
|
341
|
-
// difference (a new schedule with no rule never fires: the exact miss the gate above stops).
|
|
342
|
-
// A hand-written template (marker removed) is the operator's own — kept, never gated.
|
|
343
|
-
const templateArtifact = plan.artifacts.find((a) => a.path.endsWith(TEMPLATE_FILE));
|
|
344
|
-
const templateHome = join(workspace, templateArtifact?.path ?? TEMPLATE_FILE);
|
|
345
|
-
if (!opts.force && templateArtifact && (await exists(templateHome))) {
|
|
346
|
-
const existing = await readFile(templateHome, "utf8");
|
|
347
|
-
if (isGeneratedAgentcoreTemplate(existing) && existing !== templateArtifact.content) {
|
|
348
|
-
const msg = `${templateArtifact.path} no longer matches this definition (channels/schedules/selfSchedule changed) — ` +
|
|
349
|
-
`the kept template would silently drop the difference. Pass --force to regenerate (hand edits are lost), ` +
|
|
350
|
-
`or delete the file.`;
|
|
351
|
-
if (opts.run)
|
|
352
|
-
failStartup(new Error(`deploy stopped: ${msg}`));
|
|
353
|
-
console.error(`[fastagent] warn: ${msg}`);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
await writeArtifacts(workspace, plan.artifacts, {
|
|
357
|
-
force: !!opts.force,
|
|
358
|
-
alwaysWrite: [`${container.agentPrefix}${FORWARDER_FILE}`],
|
|
359
|
-
});
|
|
360
|
-
if (opts.run) {
|
|
361
|
-
return runDeployAgentcore({
|
|
362
|
-
agentDir,
|
|
363
|
-
workspace,
|
|
364
|
-
agentPrefix: container.agentPrefix,
|
|
365
|
-
name: acName,
|
|
366
|
-
modelAuth,
|
|
367
|
-
modelKeyInDefinition,
|
|
368
|
-
authPath,
|
|
369
|
-
channels,
|
|
370
|
-
extraSecrets,
|
|
371
|
-
selfSchedule: !!config.selfSchedule,
|
|
372
|
-
// Same predicate the template uses for the forwarder resource — kept in one expression so
|
|
373
|
-
// the run path and the topology cannot disagree about whether a forwarder exists.
|
|
374
|
-
needsForwarder: webhookChannels.length > 0 || loaded.schedules.length > 0 || !!config.selfSchedule,
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
console.log(plan.runbook.join("\n"));
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
// host === "fly".
|
|
381
|
-
// The replay floor that makes scale-to-zero safe is Telegram-only (its L1 turn store). GitHub turns
|
|
382
|
-
// are fire-and-forget (no replay), so the generated fly.toml keeps one machine running for them —
|
|
383
|
-
// a note, not a warn, since the plan already did the safe thing (definition-aware autostop).
|
|
384
|
-
if (channels.some((channel) => channel.name === "github")) {
|
|
385
|
-
console.error(`[fastagent] note: github turns have no replay — the generated fly.toml uses min_machines_running=1 ` +
|
|
386
|
-
`(no scale-to-zero) so autostop can't drop an in-flight review. Set it to 0 to accept that trade.`);
|
|
387
|
-
}
|
|
388
|
-
// Two consistent modes. KEEP (no --force): an existing fly.toml is authoritative — not rewritten,
|
|
389
|
-
// and the runbook reads its `app=` (Fly app names are globally unique, so the basename guess may be
|
|
390
|
-
// taken and the user renamed it). --force: the template is authoritative — the WHOLE fly.toml resets
|
|
391
|
-
// (app→basename, region→iad, vm→defaults), so we do NOT round-trip `app` and warn that hand edits go.
|
|
392
|
-
// fly.toml lives in the agent dir (fastagent/fly.toml) — the workspace's own
|
|
393
|
-
// fly.toml (if any) belongs to the host's product deploy and is never read or written here.
|
|
394
|
-
const flyTomlPath = join(agentDir, "fly.toml");
|
|
395
|
-
const flyToml = await readFile(flyTomlPath, "utf8").catch(() => undefined);
|
|
396
|
-
// Every decision below turns on ONE question — will `writeArtifacts` keep this file? — and the answer is
|
|
397
|
-
// OWNERSHIP, not the flag: `--force` resets a fly.toml we generated and leaves a hand-written one alone.
|
|
398
|
-
// Keying these on `--force` alone meant a forced deploy of a hand-owned fly.toml took the app name from
|
|
399
|
-
// the directory basename (shipping that file at a DIFFERENT app than it declares) and skipped the
|
|
400
|
-
// scale-to-zero gate below (a schedules deploy that silently sleeps). Read once, decide once.
|
|
401
|
-
const flyTomlKept = flyToml !== undefined && (!opts.force || !isGeneratedFlyToml(flyToml));
|
|
402
|
-
const keptApp = flyTomlKept ? parseFlyAppName(flyToml) : undefined;
|
|
403
|
-
const appName = keptApp ?? toFlyAppName(basename(workspace));
|
|
404
|
-
if (keptApp)
|
|
405
|
-
console.error(`[fastagent] app: ${keptApp} (from fly.toml)`);
|
|
406
|
-
if (flyToml !== undefined && !flyTomlKept) {
|
|
407
|
-
console.error(`[fastagent] warn: --force resets fly.toml to defaults (app, region, vm) — re-apply any hand edits`);
|
|
408
|
-
}
|
|
409
|
-
// Autostop flags shape the GENERATED fly.toml only. In KEEP mode (fly.toml exists, no --force) it is
|
|
410
|
-
// not rewritten, so the flags would silently do nothing — surface that instead of a confusing no-op.
|
|
411
|
-
if (flyTomlKept && (opts.stop || opts.scaleToZero === false)) {
|
|
412
|
-
console.error(`[fastagent] warn: --stop/--no-scale-to-zero only shape a freshly generated fly.toml — yours exists and ` +
|
|
413
|
-
`was kept. Edit auto_stop_machines/min_machines_running in fly.toml, or pass --force to regenerate.`);
|
|
414
|
-
}
|
|
415
|
-
// KEEP mode + time triggers: the kept fly.toml may still scale to zero — which would sleep through every
|
|
416
|
-
// cron instant / wake-up. The generated plan can't fix a kept file, so surface it instead of the preflight
|
|
417
|
-
// note silently not applying (the author who deployed FIRST and added schedules LATER hits exactly this).
|
|
418
|
-
// Under `--run` this is a GATE (same discipline as the model-travel gate): a full deploy whose schedules
|
|
419
|
-
// silently never fire is worse than a crash-loop — nothing fails visibly when a cron instant passes on a
|
|
420
|
-
// sleeping machine, and unlike github's min=0 there is no legitimate trade to accept here.
|
|
421
|
-
if (flyTomlKept && (hasTimeTriggers || longConnectionChannels.length > 0)) {
|
|
422
|
-
const min = parseFlyMinMachines(flyToml);
|
|
423
|
-
if ((min ?? 0) === 0) {
|
|
424
|
-
// undefined = the line is absent — Fly's platform default for min_machines_running is 0, so a
|
|
425
|
-
// hand-written fly.toml without the line scales to zero exactly like an explicit 0.
|
|
426
|
-
const reason = hasTimeTriggers
|
|
427
|
-
? `schedules/self-scheduling need a running machine (no external wake-up)`
|
|
428
|
-
: `long-connection channel (${longConnectionChannels.map((c) => c.name).join(", ")}) needs an always-on outbound connection`;
|
|
429
|
-
const msg = `your kept fly.toml scales to zero (min_machines_running = ${min ?? "absent → platform default 0"}), but ` +
|
|
430
|
-
`${reason}. Set min_machines_running = 1, or pass --force to regenerate.`;
|
|
431
|
-
if (opts.run)
|
|
432
|
-
failStartup(new Error(`deploy stopped: ${msg}`));
|
|
433
|
-
console.error(`[fastagent] warn: ${msg}`);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
const plan = planFlyDeploy({
|
|
437
|
-
appName,
|
|
438
|
-
port,
|
|
439
|
-
modelAuth,
|
|
115
|
+
const target = HOSTS[host];
|
|
116
|
+
await target.deploy({
|
|
117
|
+
opts,
|
|
118
|
+
agentDir,
|
|
119
|
+
workspace,
|
|
120
|
+
config,
|
|
121
|
+
pre,
|
|
440
122
|
channels,
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
123
|
+
webhookChannels: channels.filter((channel) => channel.ingress === "webhook"),
|
|
124
|
+
longConnectionChannels: channels.filter((channel) => channel.ingress === "long-connection"),
|
|
125
|
+
// The ownership predicate is bound HERE, from the same lookup that chose the host, so no host
|
|
126
|
+
// module can pass one — the four that did each stated theirs twice, in a position where a
|
|
127
|
+
// neighbour's type-checks and silently makes `--force` a no-op for the host's own artifact.
|
|
128
|
+
write: (artifacts, options) => writeArtifacts(workspace, artifacts, { ...options, isOurs: target.isOurs }),
|
|
446
129
|
});
|
|
447
|
-
await writeArtifacts(workspace, plan.artifacts, {
|
|
448
|
-
force: !!opts.force,
|
|
449
|
-
});
|
|
450
|
-
if (opts.run) {
|
|
451
|
-
return runDeployFly({
|
|
452
|
-
agentDir,
|
|
453
|
-
workspace,
|
|
454
|
-
agentPrefix: container.agentPrefix,
|
|
455
|
-
appName,
|
|
456
|
-
modelAuth,
|
|
457
|
-
modelKeyInDefinition,
|
|
458
|
-
authPath,
|
|
459
|
-
channels,
|
|
460
|
-
flyTomlPath,
|
|
461
|
-
extraSecrets,
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
console.log(plan.runbook.join("\n"));
|
|
465
|
-
}
|
|
466
|
-
/** Did fastagent generate the file at `path`? ONE table for every artifact kind: a kind missing from
|
|
467
|
-
* it is permanently classified as the author's, which silently turns `--force` into a no-op for that
|
|
468
|
-
* file (`fly.toml` and `railway.json` were, until the marker predicates below existed). */
|
|
469
|
-
function isOurArtifact(path, content) {
|
|
470
|
-
if (path.endsWith("Dockerfile"))
|
|
471
|
-
return isGeneratedDockerfile(content);
|
|
472
|
-
if (path.endsWith(".dockerignore"))
|
|
473
|
-
return isGeneratedDockerignore(content);
|
|
474
|
-
if (path.endsWith("fastagent.compose.yml"))
|
|
475
|
-
return isGeneratedCompose(content);
|
|
476
|
-
if (path.endsWith("fly.toml"))
|
|
477
|
-
return isGeneratedFlyToml(content);
|
|
478
|
-
if (path.endsWith("railway.json"))
|
|
479
|
-
return isGeneratedRailwayJson(content);
|
|
480
|
-
if (path.endsWith(TEMPLATE_FILE))
|
|
481
|
-
return isGeneratedAgentcoreTemplate(content);
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Write each generated artifact under `target`, under ONE ownership rule: **deploy only ever overwrites
|
|
486
|
-
* its own output.** Each generated file opens with a marker, so a file on disk is either OURS (a previous
|
|
487
|
-
* `deploy` wrote it) or the author's — and `--force` means "my generated artifact is authoritative",
|
|
488
|
-
* which never licenses clobbering a file we did not write. To hand a path back to fastagent, delete it.
|
|
489
|
-
*
|
|
490
|
-
* That single rule replaced a second mechanism (a per-host list of paths exempt from `--force`), which
|
|
491
|
-
* only described one shape: with the agent inside the workspace, the root `.dockerignore` is the
|
|
492
|
-
* WORKSPACE's file and was listed; with the agent flat, the list was empty — so `--force` would have
|
|
493
|
-
* overwritten a hand-written root `Dockerfile` in a repository `init --flat` had explicitly adopted.
|
|
494
|
-
* Ownership is a property of the file, not of where the agent sits.
|
|
495
|
-
*
|
|
496
|
-
* A KEPT file of OURS that no longer matches what deploy would generate now (config/channel/lockfile/
|
|
497
|
-
* version drift — or the author's edits, which we cannot tell apart) is flagged stale; `--force`
|
|
498
|
-
* regenerates that one.
|
|
499
|
-
*
|
|
500
|
-
* Exported for its own test — this is a four-branch state machine over (exists, ours, force) that used
|
|
501
|
-
* to be proven by spawning the CLI eight times, which is command LOGIC re-run through a subprocess
|
|
502
|
-
* (see vitest.config.ts) and the suite's slowest test.
|
|
503
|
-
*/
|
|
504
|
-
export async function writeArtifacts(target, artifacts, options) {
|
|
505
|
-
for (const a of artifacts) {
|
|
506
|
-
const abs = join(target, a.path);
|
|
507
|
-
// Pure build output, not operator-owned configuration. It must track the generated template/runbook.
|
|
508
|
-
if (options.alwaysWrite?.includes(a.path)) {
|
|
509
|
-
await mkdir(dirname(abs), { recursive: true });
|
|
510
|
-
await writeFile(abs, a.content);
|
|
511
|
-
console.error(`[fastagent] wrote ${a.path}`);
|
|
512
|
-
continue;
|
|
513
|
-
}
|
|
514
|
-
const existing = (await exists(abs)) ? await readFile(abs, "utf8") : undefined;
|
|
515
|
-
const ours = existing !== undefined && isOurArtifact(a.path, existing);
|
|
516
|
-
if (existing !== undefined && !ours) {
|
|
517
|
-
// Only the `.dockerignore` has content checks in preflight — pointing at "the preflight warnings"
|
|
518
|
-
// for the other kinds would send the reader looking for output that is never printed.
|
|
519
|
-
console.error(`[fastagent] kept ${a.path} — not generated by fastagent, so --force does not touch it ` +
|
|
520
|
-
`(delete it to let deploy own the path)` +
|
|
521
|
-
(a.path.endsWith(".dockerignore")
|
|
522
|
-
? `; see the preflight warnings for what it must exclude`
|
|
523
|
-
: a.path.endsWith("Dockerfile")
|
|
524
|
-
? `; deploy still assumes it listens on $PORT and runs \`fastagent start /app\``
|
|
525
|
-
: ``));
|
|
526
|
-
continue;
|
|
527
|
-
}
|
|
528
|
-
if (existing !== undefined && !options.force) {
|
|
529
|
-
console.error(existing !== a.content
|
|
530
|
-
? `[fastagent] kept ${a.path} — it no longer matches what deploy would generate (config changed, or ` +
|
|
531
|
-
`you edited it); pass --force to regenerate.`
|
|
532
|
-
: `[fastagent] kept ${a.path} (unchanged)`);
|
|
533
|
-
continue;
|
|
534
|
-
}
|
|
535
|
-
await mkdir(dirname(abs), { recursive: true }); // artifacts live under fastagent/
|
|
536
|
-
await writeFile(abs, a.content);
|
|
537
|
-
console.error(`[fastagent] wrote ${a.path}`);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
function deployEnvironment(agentDir, channels) {
|
|
541
|
-
if (!channels.some((channel) => channel.name === "slack"))
|
|
542
|
-
return process.env;
|
|
543
|
-
const latest = readSlackBotAuthEnv(join(resolveStateRoot(agentDir), "channels", "slack", "bot-auth.json"));
|
|
544
|
-
return { ...process.env, ...latest };
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* `deploy docker --run`: carry local credentials into Compose's child environment, then reconcile the
|
|
548
|
-
* user-owned local topology. Docker owns container/network/volume lifecycle. A Compose tunnel service,
|
|
549
|
-
* when present, yields an ephemeral URL that reuses the same webhook announcer as `dev --tunnel`.
|
|
550
|
-
*/
|
|
551
|
-
async function runDeployDocker(params) {
|
|
552
|
-
const { agentDir, workspace, composeFile, port, requireTunnel, channels } = params;
|
|
553
|
-
const { secrets, missingSecrets, needsModelCredential } = await carryCredentials(params);
|
|
554
|
-
const outcome = await deployDockerRun({
|
|
555
|
-
composeFile,
|
|
556
|
-
port,
|
|
557
|
-
secrets,
|
|
558
|
-
missingSecrets,
|
|
559
|
-
needsModelCredential,
|
|
560
|
-
requireTunnel,
|
|
561
|
-
announce: (tunnelUrl) => announceWebhooks(agentDir, tunnelUrl, channels, {
|
|
562
|
-
openUrl: openExternalUrl,
|
|
563
|
-
stateRoot: resolveStateRoot(agentDir),
|
|
564
|
-
}),
|
|
565
|
-
}, spawnRunner("docker", workspace), (message) => console.error(`[fastagent] ${message}`));
|
|
566
|
-
const compose = `docker compose -f ${composeFile}`;
|
|
567
|
-
// Compose reached "up" iff the driver could report where it is. The gates before that point
|
|
568
|
-
// (no Docker CLI, no daemon, missing secrets) must not be preceded by `docker compose logs`
|
|
569
|
-
// instructions for containers that do not exist; the health-check gate names its own logs command.
|
|
570
|
-
const isUp = outcome.ok || outcome.url !== undefined || outcome.tunnelUrl !== undefined;
|
|
571
|
-
if (outcome.url)
|
|
572
|
-
console.error(`[fastagent] running → ${outcome.url}`);
|
|
573
|
-
if (isUp) {
|
|
574
|
-
console.error(`[fastagent] logs: ${compose} logs -f agent`);
|
|
575
|
-
console.error(`[fastagent] stop: ${compose} down (state volume is kept)`);
|
|
576
|
-
}
|
|
577
|
-
// BEFORE failStartup: a registration gate says "re-run this deploy", and a re-run rebuilds the
|
|
578
|
-
// tunnel service — the operator needs to know the URL will be a different one, or they will read
|
|
579
|
-
// the retry as re-registering the same address.
|
|
580
|
-
if (outcome.tunnelUrl) {
|
|
581
|
-
console.error(`[fastagent] note: Quick Tunnel URLs are ephemeral — after the tunnel container/Docker daemon ` +
|
|
582
|
-
`restarts, re-run this deploy so webhooks receive the new URL`);
|
|
583
|
-
}
|
|
584
|
-
if (!outcome.ok)
|
|
585
|
-
failStartup(new Error(`deploy stopped: ${outcome.gate}`));
|
|
586
|
-
if (outcome.tunnelUrl)
|
|
587
|
-
return;
|
|
588
|
-
const paths = webhookPaths(channels);
|
|
589
|
-
if (paths.length > 0) {
|
|
590
|
-
console.error(`[fastagent] note: public ingress is operator-owned — configure your tunnel/proxy, then wire the ` +
|
|
591
|
-
`default webhook path(s): ${paths.join(", ")} (or your remapped channel routes)`);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
/**
|
|
595
|
-
* `deploy fly --run`: drive flyctl to completion (idempotent, resumable). Gathers the secret VALUES
|
|
596
|
-
* from the local env — the model key (env auth) or the whole auth.json as a `FASTAGENT_AUTH_SEED` seed
|
|
597
|
-
* (OAuth/stored auth: the deployed box materializes it onto the /data volume on first boot, so a
|
|
598
|
-
* personal deploy runs on the SAME subscription) plus channel secrets — then runs the flyctl steps
|
|
599
|
-
* behind the shared {@link spawnRunner} seam (spawned `fly`, cwd = the workspace so the build context is the whole workspace).
|
|
600
|
-
*/
|
|
601
|
-
async function runDeployFly(params) {
|
|
602
|
-
const { agentDir, workspace, agentPrefix, appName, channels, flyTomlPath } = params;
|
|
603
|
-
const fly = spawnRunner("fly", workspace);
|
|
604
|
-
// Fail fast if flyctl is absent (spawn ENOENT → 127), with the install link — not a confusing auth gate.
|
|
605
|
-
if ((await fly(["version"], { capture: true })).code === 127) {
|
|
606
|
-
failStartup(new Error(`flyctl not found — install it: https://fly.io/docs/flyctl/install, then re-run`));
|
|
607
|
-
}
|
|
608
|
-
const region = parseFlyRegion(await readFile(flyTomlPath, "utf8")) ?? "iad";
|
|
609
|
-
const { secrets, missingSecrets, needsModelCredential } = await carryCredentials(params);
|
|
610
|
-
gateOnModelCredential(needsModelCredential);
|
|
611
|
-
const outcome = await deployFlyRun({
|
|
612
|
-
appName,
|
|
613
|
-
region,
|
|
614
|
-
secrets,
|
|
615
|
-
missingSecrets,
|
|
616
|
-
channels,
|
|
617
|
-
flyConfig: `${agentPrefix}fly.toml`,
|
|
618
|
-
dockerfile: `${agentPrefix}Dockerfile`,
|
|
619
|
-
}, fly, (m) => console.error(`[fastagent] ${m}`), registrarsFor(agentDir));
|
|
620
|
-
if (!outcome.ok)
|
|
621
|
-
failStartup(new Error(`deploy stopped: ${outcome.gate}`));
|
|
622
|
-
console.error(`[fastagent] deployed → https://${appName}.fly.dev`);
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* `deploy agentcore --run`: drive aws + docker to completion. Mirrors {@link runDeployFly} — same
|
|
626
|
-
* credential carry via {@link assembleSecrets}, same runner seam (spawned `aws` + `docker`, cwd = the
|
|
627
|
-
* workspace so the build context is the agent). The AgentCore-specific sequence (identity → buildx →
|
|
628
|
-
* ECR → CloudFormation → outputs → webhooks) lives in {@link deployAgentcoreRun}; the params temp
|
|
629
|
-
* file (secret values off argv) is created here — 0600, removed after the run either way.
|
|
630
|
-
*/
|
|
631
|
-
async function runDeployAgentcore(params) {
|
|
632
|
-
const { agentDir, workspace, agentPrefix, name, channels, selfSchedule } = params;
|
|
633
|
-
const { secrets, missingSecrets, needsModelCredential } = await carryCredentials(params);
|
|
634
|
-
// The wake-alarm shared secret (container ↔ forwarder). Minted fresh each run — both sides receive
|
|
635
|
-
// the SAME parameter, so rotation is atomic; it never needs to be remembered locally.
|
|
636
|
-
if (selfSchedule)
|
|
637
|
-
secrets.FASTAGENT_WAKE_SECRET = crypto.randomUUID();
|
|
638
|
-
// The forwarder→runtime ingress secret: what makes an envelope the forwarder's rather than any IAM
|
|
639
|
-
// principal's. Minted fresh each run — both sides receive the SAME parameter, so rotation is atomic.
|
|
640
|
-
if (params.needsForwarder)
|
|
641
|
-
secrets.FASTAGENT_INGRESS_SECRET = crypto.randomUUID();
|
|
642
|
-
gateOnModelCredential(needsModelCredential);
|
|
643
|
-
// The params temp dir holds the ONE file carrying secret values (file:// parameter-overrides —
|
|
644
|
-
// never argv); 0700/0600 and removed after the run, success or gate.
|
|
645
|
-
const paramsDir = await mkdtemp(join(tmpdir(), "fastagent-agentcore-"));
|
|
646
|
-
try {
|
|
647
|
-
const outcome = await deployAgentcoreRun({
|
|
648
|
-
name,
|
|
649
|
-
templatePath: `${agentPrefix}${TEMPLATE_FILE}`,
|
|
650
|
-
dockerfilePath: agentPrefix ? `${agentPrefix}Dockerfile` : undefined,
|
|
651
|
-
tag: new Date()
|
|
652
|
-
.toISOString()
|
|
653
|
-
.replace(/[-:.TZ]/g, "")
|
|
654
|
-
.slice(0, 14),
|
|
655
|
-
region: process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION,
|
|
656
|
-
secrets,
|
|
657
|
-
missingSecrets,
|
|
658
|
-
channels,
|
|
659
|
-
// Same predicate the template uses: the forwarder exists for route channels, cron schedules
|
|
660
|
-
// or selfSchedule — and it is what mints the state snapshot's presigned URLs.
|
|
661
|
-
needsForwarder: params.needsForwarder,
|
|
662
|
-
}, spawnRunner("aws", workspace), spawnRunner("docker", workspace), (m) => console.error(`[fastagent] ${m}`), async (content) => {
|
|
663
|
-
const path = join(paramsDir, "params.json");
|
|
664
|
-
await writeFile(path, content, { mode: 0o600 });
|
|
665
|
-
return path;
|
|
666
|
-
}, async (bytes) => {
|
|
667
|
-
const path = join(paramsDir, "forwarder.zip");
|
|
668
|
-
await writeFile(path, bytes);
|
|
669
|
-
return path;
|
|
670
|
-
}, registrarsFor(agentDir));
|
|
671
|
-
if (!outcome.ok)
|
|
672
|
-
failStartup(new Error(`deploy stopped: ${outcome.gate}`));
|
|
673
|
-
console.error(`[fastagent] deployed → ${outcome.runtimeArn}`);
|
|
674
|
-
if (outcome.url)
|
|
675
|
-
console.error(`[fastagent] webhook ingress → ${outcome.url}`);
|
|
676
|
-
const logsDir = shellArg(workspace);
|
|
677
|
-
console.error(`[fastagent] runtime logs → fastagent logs agentcore ${logsDir} --follow`);
|
|
678
|
-
if (params.needsForwarder) {
|
|
679
|
-
console.error(`[fastagent] forwarder logs → fastagent logs agentcore ${logsDir} --source forwarder --follow`);
|
|
680
|
-
}
|
|
681
|
-
console.error(`[fastagent] invoke: aws bedrock-agentcore invoke-agent-runtime --agent-runtime-arn ${outcome.runtimeArn} \\\n` +
|
|
682
|
-
` --runtime-session-id "my-conversation-000000000000000000" \\\n` +
|
|
683
|
-
` --payload '{"kind":"invoke","session":"cli","text":"hello"}' --cli-binary-format raw-in-base64-out /dev/stdout`);
|
|
684
|
-
}
|
|
685
|
-
finally {
|
|
686
|
-
await rm(paramsDir, { recursive: true, force: true });
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* `deploy railway --run`: drive the railway CLI to completion. Mirrors {@link runDeployFly} — same
|
|
691
|
-
* credential carry (env key OR the OAuth auth.json as `FASTAGENT_AUTH_SEED`) via {@link assembleSecrets},
|
|
692
|
-
* same runner seam (spawned `railway`, cwd = the workspace so `railway up`'s upload is the whole workspace). The
|
|
693
|
-
* Railway-specific sequence (linked-check → init/add/volume when fresh → variables → up → domain →
|
|
694
|
-
* webhook) lives in {@link deployRailwayRun}; see there for why Railway differs from Fly.
|
|
695
|
-
*/
|
|
696
|
-
async function runDeployRailway(params) {
|
|
697
|
-
const { agentDir, workspace, name, channels, intoLinked, dockerfilePath } = params;
|
|
698
|
-
const railway = spawnRunner("railway", workspace);
|
|
699
|
-
// Fail fast if the railway CLI is absent (spawn ENOENT → 127), with the install link.
|
|
700
|
-
if ((await railway(["--version"], { capture: true })).code === 127) {
|
|
701
|
-
failStartup(new Error(`railway CLI not found — install it: https://docs.railway.com/guides/cli, then re-run`));
|
|
702
|
-
}
|
|
703
|
-
const { secrets, missingSecrets, needsModelCredential } = await carryCredentials(params);
|
|
704
|
-
gateOnModelCredential(needsModelCredential);
|
|
705
|
-
const outcome = await deployRailwayRun({ name, mountPath: "/data", secrets, missingSecrets, channels, intoLinked, dockerfilePath }, railway, (m) => console.error(`[fastagent] ${m}`), registrarsFor(agentDir));
|
|
706
|
-
if (!outcome.ok)
|
|
707
|
-
failStartup(new Error(`deploy stopped: ${outcome.gate}`));
|
|
708
|
-
console.error(`[fastagent] deployed → ${outcome.url}`);
|
|
709
130
|
}
|