@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,135 +0,0 @@
|
|
|
1
|
-
/** Rotating Slack bot-token provider backed by owner-only channel state. */
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import { writeFileAtomic } from "../../atomic-write.js";
|
|
4
|
-
const REFRESH_EARLY_MS = 5 * 60_000;
|
|
5
|
-
const REQUEST_TIMEOUT_MS = 30_000;
|
|
6
|
-
function isState(value) {
|
|
7
|
-
const state = value;
|
|
8
|
-
return (typeof state === "object" &&
|
|
9
|
-
state !== null &&
|
|
10
|
-
state.version === 1 &&
|
|
11
|
-
typeof state.accessToken === "string" &&
|
|
12
|
-
typeof state.refreshToken === "string" &&
|
|
13
|
-
typeof state.expiresAt === "number");
|
|
14
|
-
}
|
|
15
|
-
function load(path) {
|
|
16
|
-
let raw;
|
|
17
|
-
try {
|
|
18
|
-
raw = readFileSync(path, "utf8");
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
if (error.code === "ENOENT")
|
|
22
|
-
return undefined;
|
|
23
|
-
throw new Error(`Slack bot auth state ${path} is unreadable: ${String(error)}`, { cause: error });
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
const value = JSON.parse(raw);
|
|
27
|
-
if (!isState(value))
|
|
28
|
-
throw new Error("unexpected shape/version");
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
// A stale env refresh token may already have been consumed. Never hide corrupt rotating state by
|
|
33
|
-
// falling back to it: recovery requires restoring the durable file or reinstalling the app.
|
|
34
|
-
throw new Error(`Slack bot auth state ${path} is invalid: ${String(error)}`, { cause: error });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function save(path, state) {
|
|
38
|
-
writeFileAtomic(path, JSON.stringify(state), 0o600);
|
|
39
|
-
}
|
|
40
|
-
async function refreshSlackBotToken(input) {
|
|
41
|
-
const authorization = Buffer.from(`${input.clientId}:${input.clientSecret}`, "utf8").toString("base64");
|
|
42
|
-
let lastError;
|
|
43
|
-
// Slack keeps a short grace window for a just-consumed refresh token. One retry recovers the
|
|
44
|
-
// committed-but-response-lost boundary without creating an unbounded refresh loop.
|
|
45
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
46
|
-
try {
|
|
47
|
-
const response = await input.fetch(`${input.apiBaseUrl}/oauth.v2.access`, {
|
|
48
|
-
method: "POST",
|
|
49
|
-
headers: {
|
|
50
|
-
authorization: `Basic ${authorization}`,
|
|
51
|
-
"content-type": "application/x-www-form-urlencoded",
|
|
52
|
-
},
|
|
53
|
-
body: new URLSearchParams({
|
|
54
|
-
grant_type: "refresh_token",
|
|
55
|
-
refresh_token: input.refreshToken,
|
|
56
|
-
}).toString(),
|
|
57
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
58
|
-
});
|
|
59
|
-
const data = (await response.json().catch(() => ({})));
|
|
60
|
-
if (!response.ok ||
|
|
61
|
-
data.ok !== true ||
|
|
62
|
-
!data.access_token ||
|
|
63
|
-
!data.refresh_token ||
|
|
64
|
-
typeof data.expires_in !== "number") {
|
|
65
|
-
throw new Error(`Slack rejected bot-token refresh (HTTP ${response.status})`);
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
version: 1,
|
|
69
|
-
accessToken: data.access_token,
|
|
70
|
-
refreshToken: data.refresh_token,
|
|
71
|
-
expiresAt: Date.now() + data.expires_in * 1_000,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
lastError = error;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
throw new Error("Slack bot-token rotation failed; restore credentials or reinstall the app", { cause: lastError });
|
|
79
|
-
}
|
|
80
|
-
/** Latest local rotating credentials for `deploy --run`. The remote runtime still prefers its own
|
|
81
|
-
* durable volume; this overlay prevents a locally consumed refresh token from being redeployed. */
|
|
82
|
-
export function readSlackBotAuthEnv(statePath) {
|
|
83
|
-
const state = load(statePath);
|
|
84
|
-
return state
|
|
85
|
-
? {
|
|
86
|
-
SLACK_BOT_TOKEN: state.accessToken,
|
|
87
|
-
SLACK_BOT_REFRESH_TOKEN: state.refreshToken,
|
|
88
|
-
SLACK_BOT_TOKEN_EXPIRES_AT: String(state.expiresAt),
|
|
89
|
-
}
|
|
90
|
-
: {};
|
|
91
|
-
}
|
|
92
|
-
/** Resolve the current bot token, refreshing once per process when it approaches expiry. */
|
|
93
|
-
export function createSlackBotTokenProvider(options) {
|
|
94
|
-
const rotatingFields = [options.botRefreshToken, options.clientId, options.clientSecret, options.botTokenExpiresAt];
|
|
95
|
-
const rotating = rotatingFields.some((value) => value !== undefined);
|
|
96
|
-
if (rotating && rotatingFields.some((value) => value === undefined || value === "")) {
|
|
97
|
-
throw new Error("Slack token rotation requires botRefreshToken, clientId, clientSecret, and botTokenExpiresAt together");
|
|
98
|
-
}
|
|
99
|
-
if (rotating && (!Number.isFinite(options.botTokenExpiresAt) || options.botTokenExpiresAt <= 0)) {
|
|
100
|
-
throw new Error("Slack botTokenExpiresAt must be a positive epoch-millisecond value");
|
|
101
|
-
}
|
|
102
|
-
if (!rotating)
|
|
103
|
-
return async () => options.botToken;
|
|
104
|
-
const configured = {
|
|
105
|
-
version: 1,
|
|
106
|
-
accessToken: options.botToken,
|
|
107
|
-
refreshToken: options.botRefreshToken,
|
|
108
|
-
expiresAt: options.botTokenExpiresAt,
|
|
109
|
-
};
|
|
110
|
-
const persisted = load(options.statePath);
|
|
111
|
-
// Deploy may carry a newer pair from the owner machine onto an existing remote volume; ordinary
|
|
112
|
-
// restarts carry the original stale env and therefore keep the newer persisted pair.
|
|
113
|
-
let state = persisted && persisted.expiresAt >= configured.expiresAt ? persisted : configured;
|
|
114
|
-
let refreshing;
|
|
115
|
-
return async () => {
|
|
116
|
-
if (state.expiresAt > Date.now() + REFRESH_EARLY_MS)
|
|
117
|
-
return state.accessToken;
|
|
118
|
-
refreshing ??= refreshSlackBotToken({
|
|
119
|
-
refreshToken: state.refreshToken,
|
|
120
|
-
clientId: options.clientId,
|
|
121
|
-
clientSecret: options.clientSecret,
|
|
122
|
-
apiBaseUrl: (options.apiBaseUrl ?? "https://slack.com/api").replace(/\/$/, ""),
|
|
123
|
-
fetch: options.fetch ?? globalThis.fetch,
|
|
124
|
-
})
|
|
125
|
-
.then((next) => {
|
|
126
|
-
save(options.statePath, next);
|
|
127
|
-
state = next;
|
|
128
|
-
})
|
|
129
|
-
.finally(() => {
|
|
130
|
-
refreshing = undefined;
|
|
131
|
-
});
|
|
132
|
-
await refreshing;
|
|
133
|
-
return state.accessToken;
|
|
134
|
-
};
|
|
135
|
-
}
|