@sleep2agi/agent-network 2.3.0-preview.22 → 2.3.0-preview.220
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 +35 -324
- package/build-info.json +7 -0
- package/dist/bin/anet.cjs +101 -0
- package/dist/bin/cli.d.ts +1 -1
- package/dist/bin/cli.js +20 -1
- package/dist/src/active-network-task.d.ts +28 -0
- package/dist/src/batch-workdir.d.ts +9 -0
- package/dist/src/bootstrap-password-db.d.ts +13 -0
- package/dist/src/build-info.d.ts +26 -0
- package/dist/src/channel-attachments.d.ts +29 -0
- package/dist/src/channel-inbox-wake.d.ts +21 -0
- package/dist/src/channel-meta.d.ts +10 -0
- package/dist/src/channel-peer-reply.d.ts +41 -0
- package/dist/src/channel-task-trace.d.ts +14 -0
- package/dist/src/claude-vendor-env.d.ts +28 -0
- package/dist/src/cli-args.d.ts +8 -0
- package/dist/src/cli-auth-session.d.ts +47 -0
- package/dist/src/cli-errors.d.ts +41 -0
- package/dist/src/cli-exit.d.ts +11 -0
- package/dist/src/cli-help.d.ts +10 -0
- package/dist/src/cli-version-display.d.ts +16 -0
- package/dist/src/client-task-trace.d.ts +9 -0
- package/dist/src/client.js +1 -1
- package/dist/src/codex-adopt.d.ts +46 -0
- package/dist/src/codex-auth-fingerprint.d.ts +211 -0
- package/dist/src/codex-bin-pin.d.ts +23 -0
- package/dist/src/codex-commhub-mcp.d.ts +22 -0
- package/dist/src/codex-copresence-bridge-log.d.ts +44 -0
- package/dist/src/codex-copresence-env.d.ts +5 -0
- package/dist/src/codex-copresence-login-gate.d.ts +18 -0
- package/dist/src/codex-copresence-model.d.ts +23 -0
- package/dist/src/codex-copresence-preflight.d.ts +78 -0
- package/dist/src/codex-copresence-profile.d.ts +126 -0
- package/dist/src/codex-copresence-recovery.d.ts +70 -0
- package/dist/src/codex-copresence-resume-timeout.d.ts +28 -0
- package/dist/src/codex-copresence-rollout-guard.d.ts +36 -0
- package/dist/src/codex-copresence-rpc.d.ts +17 -0
- package/dist/src/codex-copresence-thread.d.ts +13 -0
- package/dist/src/codex-copresence-yolo.d.ts +16 -0
- package/dist/src/codex-external-appserver.d.ts +130 -0
- package/dist/src/codex-fork-recovery.d.ts +52 -0
- package/dist/src/codex-home-enforce.d.ts +88 -0
- package/dist/src/codex-lifecycle-account.d.ts +104 -0
- package/dist/src/codex-lifecycle-canary.d.ts +20 -0
- package/dist/src/codex-lifecycle-facts.d.ts +53 -0
- package/dist/src/codex-lifecycle-fork.d.ts +91 -0
- package/dist/src/codex-lifecycle-preflight.d.ts +79 -0
- package/dist/src/codex-lifecycle-receipt.d.ts +53 -0
- package/dist/src/codex-lifecycle-restart.d.ts +88 -0
- package/dist/src/codex-login-share-guard.d.ts +146 -0
- package/dist/src/codex-menu.d.ts +99 -0
- package/dist/src/codex-model-default.d.ts +6 -0
- package/dist/src/codex-node-login.d.ts +98 -0
- package/dist/src/codex-pending-thread-restart.d.ts +69 -0
- package/dist/src/codex-reasoning-effort.d.ts +17 -0
- package/dist/src/codex-recovery-lease.d.ts +39 -0
- package/dist/src/codex-recovery-resource-gate.d.ts +15 -0
- package/dist/src/codex-resume.d.ts +89 -0
- package/dist/src/codex-rollout-history-guard.d.ts +84 -0
- package/dist/src/codex-tui-client-health.d.ts +30 -0
- package/dist/src/commhub-response.d.ts +1 -0
- package/dist/src/controlled-upload.d.ts +83 -0
- package/dist/src/copresence-deps.d.ts +22 -0
- package/dist/src/copresence-identity.d.ts +363 -0
- package/dist/src/copresence-startup-diagnosis.d.ts +17 -0
- package/dist/src/daemon-adopt.d.ts +14 -0
- package/dist/src/daemon-anet-bin.d.ts +32 -0
- package/dist/src/daemon-capability-display.d.ts +110 -0
- package/dist/src/daemon-capability-display.js +21 -0
- package/dist/src/daemon-codex-inventory.d.ts +65 -0
- package/dist/src/daemon-inherited-env.d.ts +9 -0
- package/dist/src/daemon-provider-account-custody.d.ts +28 -0
- package/dist/src/daemon-provider-account-readback.d.ts +3 -0
- package/dist/src/daemon-provider-application.d.ts +36 -0
- package/dist/src/daemon-provider-apply-command.d.ts +9 -0
- package/dist/src/daemon-provider-collect.d.ts +29 -0
- package/dist/src/daemon-provider-command.d.ts +7 -0
- package/dist/src/daemon-provider-initialize.d.ts +27 -0
- package/dist/src/daemon-provider-lifecycle.d.ts +4 -0
- package/dist/src/daemon-provider-store.d.ts +104 -0
- package/dist/src/daemon-runtime-path-preflight.d.ts +22 -0
- package/dist/src/daemon-runtime-staleness.d.ts +13 -0
- package/dist/src/dashboard-managed-process.d.ts +35 -0
- package/dist/src/display-width.d.ts +27 -0
- package/dist/src/doctor-node-count.d.ts +28 -0
- package/dist/src/grok-attach-client.d.ts +129 -0
- package/dist/src/grok-build-drift.d.ts +15 -0
- package/dist/src/grok-copresence-disclosure.d.ts +11 -0
- package/dist/src/grok-copresence-orchestration.d.ts +75 -0
- package/dist/src/grok-copresence-profile.d.ts +65 -0
- package/dist/src/grok-create-mode.d.ts +19 -0
- package/dist/src/host-telemetry.d.ts +14 -0
- package/dist/src/hub-health-timeout.d.ts +4 -0
- package/dist/src/hub-server-version.d.ts +64 -0
- package/dist/src/hub-stop.d.ts +74 -0
- package/dist/src/hub-time-display.d.ts +20 -0
- package/dist/src/hub-version-skew.d.ts +19 -0
- package/dist/src/im/correlation-store.d.ts +34 -0
- package/dist/src/im/feishu/adapter.d.ts +47 -0
- package/dist/src/im/feishu/bridge.d.ts +72 -14
- package/dist/src/im/feishu/chat-context.d.ts +44 -0
- package/dist/src/im/feishu/config.d.ts +15 -1
- package/dist/src/im/feishu/hub-upload.d.ts +1 -1
- package/dist/src/im/feishu/queue-notice.d.ts +2 -0
- package/dist/src/im/feishu/worker-lifecycle.d.ts +13 -0
- package/dist/src/im/feishu/worker.js +171 -154
- package/dist/src/inbox-drain.d.ts +20 -0
- package/dist/src/local-process-state.d.ts +12 -0
- package/dist/src/locale-diagnostic.d.ts +12 -0
- package/dist/src/login-client-label.d.ts +6 -0
- package/dist/src/ls-columns.d.ts +15 -0
- package/dist/src/mock-llm.d.ts +12 -0
- package/dist/src/node-activity-log.d.ts +4 -0
- package/dist/src/node-clone.d.ts +134 -0
- package/dist/src/node-delete-hub.d.ts +42 -0
- package/dist/src/node-files.d.ts +62 -0
- package/dist/src/node-locate.d.ts +60 -0
- package/dist/src/node-ls-all.d.ts +80 -0
- package/dist/src/node-menu.d.ts +40 -0
- package/dist/src/node-not-found.d.ts +1 -0
- package/dist/src/node-remote.d.ts +180 -0
- package/dist/src/node-running-guard.d.ts +9 -0
- package/dist/src/node-secret-file.d.ts +32 -0
- package/dist/src/node-server-identity.d.ts +35 -0
- package/dist/src/node-server-payload.d.ts +66 -0
- package/dist/src/node-server-rules-file.d.ts +14 -0
- package/dist/src/node-server-secrets.d.ts +60 -0
- package/dist/src/node-server-version.d.ts +39 -0
- package/dist/src/node-server.d.ts +0 -12
- package/dist/src/node-server.js +8 -1
- package/dist/src/node-skills.d.ts +57 -0
- package/dist/src/normalize-runtime.d.ts +29 -2
- package/dist/src/offline-age.d.ts +29 -0
- package/dist/src/one-line-cell.d.ts +20 -0
- package/dist/src/opencode-agent-node-pair.d.ts +28 -0
- package/dist/src/opencode-auth-login.d.ts +43 -0
- package/dist/src/opencode-free-tier.d.ts +27 -0
- package/dist/src/opencode-generation-create.d.ts +27 -0
- package/dist/src/opencode-generation-record.d.ts +24 -0
- package/dist/src/opencode-launch-env.d.ts +13 -0
- package/dist/src/opencode-owner-mode.d.ts +6 -0
- package/dist/src/opencode-package-binary.d.ts +44 -0
- package/dist/src/opencode-pin.d.ts +28 -8
- package/dist/src/opencode-preset.d.ts +42 -8
- package/dist/src/opencode-runtime-binding.d.ts +30 -0
- package/dist/src/opencode-safe-root.d.ts +36 -0
- package/dist/src/opencode-shared-server-create.d.ts +5 -0
- package/dist/src/opencode-smoke-env.d.ts +1 -0
- package/dist/src/opencode-start-mode.d.ts +8 -0
- package/dist/src/opencode-v2-configured-model.d.ts +34 -0
- package/dist/src/opencode-v2-create-align.d.ts +18 -0
- package/dist/src/opencode-versions.d.ts +44 -0
- package/dist/src/os-user.d.ts +4 -0
- package/dist/src/outbound-attachments.d.ts +60 -0
- package/dist/src/outbound-tool-names.d.ts +1 -0
- package/dist/src/owned-roots.d.ts +58 -0
- package/dist/src/owner-env-file.d.ts +2 -0
- package/dist/src/package-mode-preflight.d.ts +41 -0
- package/dist/src/posix-codex-copresence.d.ts +33 -0
- package/dist/src/posix-modes.d.ts +36 -0
- package/dist/src/primary-network.d.ts +23 -0
- package/dist/src/private-state.d.ts +18 -0
- package/dist/src/process-telemetry.d.ts +12 -0
- package/dist/src/profile-merge.d.ts +12 -0
- package/dist/src/profile-serialize.d.ts +1 -0
- package/dist/src/provider-application-contract.d.ts +11 -0
- package/dist/src/provider-apply.d.ts +28 -0
- package/dist/src/provider-presets.d.ts +76 -0
- package/dist/src/reply-local-links.d.ts +47 -0
- package/dist/src/reply-originator.d.ts +20 -0
- package/dist/src/resume-runtime-infer.d.ts +18 -0
- package/dist/src/rules-file.d.ts +53 -0
- package/dist/src/scoped-secrets.d.ts +56 -0
- package/dist/src/secret-shell-guidance.d.ts +4 -0
- package/dist/src/session-status-class.d.ts +48 -0
- package/dist/src/shared/opencode-borrowed-launch-health.d.ts +29 -0
- package/dist/src/shared/provider-collection.d.ts +9 -0
- package/dist/src/shared/provider-initialization.d.ts +7 -0
- package/dist/src/shared/reserved-env.d.ts +3 -0
- package/dist/src/shared/scoped-secret-contract.d.ts +1 -0
- package/dist/src/shared/scoped-secret-env.d.ts +3 -0
- package/dist/src/sibling-agent-node.d.ts +23 -0
- package/dist/src/stale-socket.d.ts +118 -0
- package/dist/src/standalone-bin.d.ts +101 -0
- package/dist/src/standalone-build-stamp.d.ts +33 -0
- package/dist/src/start-resource-gate.d.ts +146 -0
- package/dist/src/stopped-receipt.d.ts +8 -0
- package/dist/src/subcommand-redirect.d.ts +26 -0
- package/dist/src/task-trace.d.ts +33 -0
- package/dist/src/tmux-attach.d.ts +11 -0
- package/dist/src/tmux-capability.d.ts +58 -0
- package/dist/src/tmux-exact-target.d.ts +36 -0
- package/dist/src/tmux-format.d.ts +20 -0
- package/dist/src/tmux-pane-prompt.d.ts +22 -0
- package/dist/src/tmux.d.ts +44 -0
- package/dist/src/token-cli.d.ts +13 -0
- package/dist/src/tool-allowlist.d.ts +28 -0
- package/dist/src/unsafe-package-path-reason.d.ts +31 -0
- package/dist/src/upgrade-channel.d.ts +31 -0
- package/dist/src/win-launcher.d.ts +20 -0
- package/dist/src/windows-codex-copresence.d.ts +238 -0
- package/dist/src/windows-rename-retry.d.ts +13 -0
- package/package.json +19 -9
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export declare const GROK_UNIX_SOCKET_PATH_MAX_BYTES = 100;
|
|
2
|
+
export declare const GROK_COPRESENCE_CAPABILITY_MARKER = "ANET_CAPABILITY_GROK_COPRESENCE_V2";
|
|
3
|
+
export declare const GROK_PREVIEW_RESOLVER_INHERITED_ENV_KEYS: readonly ["PATH", "TMPDIR", "TMP", "TEMP", "LANG", "LC_ALL", "LC_CTYPE", "TZ"];
|
|
4
|
+
export declare const GROK_AGENT_NODE_INHERITED_ENV_KEYS: readonly ["PATH", "HOME", "TMPDIR", "TMP", "TEMP", "LANG", "LC_ALL", "LC_CTYPE", "TZ", "SHELL", "USER", "LOGNAME", "TERM", "COLORTERM", "NO_COLOR"];
|
|
5
|
+
export declare const GROK_AGENT_NODE_OPTIONAL_ENV_KEYS: readonly ["GROK_BINARY", "GROK_HOME", "FLOCK_BINARY", "SETPRIV_BINARY", "UNSHARE_BINARY", "GROK_CLI_TIMEOUT_MS", "GROK_HANDSHAKE_TIMEOUT_MS", "LOG_LEVEL", "ANET_GOAL_TICK_MS", "COMMHUB_MAX_GOALS_PER_NODE"];
|
|
6
|
+
/** Exact environment for the long-lived agent-node parent of the Grok TUI. */
|
|
7
|
+
export declare function buildGrokAgentNodeEnv(parentEnv: NodeJS.ProcessEnv): Record<string, string>;
|
|
8
|
+
export declare function grokPreviewResolverConfigPaths(home: string): {
|
|
9
|
+
directory: string;
|
|
10
|
+
userConfig: string;
|
|
11
|
+
globalConfig: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* npm rejects loading the same file as both user and global config. Prepare
|
|
15
|
+
* two distinct, empty, owner-only files without following a final symlink so
|
|
16
|
+
* the resolver cannot inherit a user's ordinary npmrc credentials.
|
|
17
|
+
*/
|
|
18
|
+
export declare function prepareGrokPreviewResolverConfigs(home: string): void;
|
|
19
|
+
/** Exact environment for the short-lived npm resolver and capability probe. */
|
|
20
|
+
export declare function buildGrokPreviewResolverEnv(parentEnv: NodeJS.ProcessEnv, home: string): Record<string, string>;
|
|
21
|
+
/** Old headless-only agent-node builds already advertised grok-build-cli. */
|
|
22
|
+
export declare function agentNodeHelpSupportsGrokCopresence(help: string): boolean;
|
|
23
|
+
export interface GrokCopresenceProfileFields {
|
|
24
|
+
grokCopresence: boolean;
|
|
25
|
+
grokLeaderSocket?: string;
|
|
26
|
+
grokAttachSocket?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface GrokSocketPathOptions {
|
|
29
|
+
cwd?: string;
|
|
30
|
+
home?: string;
|
|
31
|
+
xdgRuntimeDir?: string;
|
|
32
|
+
uid?: number;
|
|
33
|
+
platform?: NodeJS.Platform;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Allocate deterministic Unix socket paths without creating anything.
|
|
37
|
+
*
|
|
38
|
+
* Grok's workspace sandbox does not admit an otherwise owner-controlled
|
|
39
|
+
* XDG_RUNTIME_DIR such as /run/user/<uid>. Keep the primary sockets under the
|
|
40
|
+
* node's owner-bound state home, which the runtime already admits, and use a
|
|
41
|
+
* short private tmp path only when the Unix socket length limit requires it.
|
|
42
|
+
* The runtime owns directory creation and permissions; `anet node create`
|
|
43
|
+
* only persists the identity of the two sockets.
|
|
44
|
+
*/
|
|
45
|
+
export declare function grokCopresenceSocketPaths(nodeId: string, options?: GrokSocketPathOptions): {
|
|
46
|
+
leaderSocket: string;
|
|
47
|
+
attachSocket: string;
|
|
48
|
+
};
|
|
49
|
+
export type GrokAttachTarget = {
|
|
50
|
+
ok: true;
|
|
51
|
+
socketPath: string;
|
|
52
|
+
} | {
|
|
53
|
+
ok: false;
|
|
54
|
+
reason: "not_grok_build_cli" | "headless" | "missing_attach_socket";
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* `anet grok attach` eligibility. The CLI is the only human join path;
|
|
58
|
+
* this is the shipped decision so tests can drive it without a TTY.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveGrokAttachTarget(input: {
|
|
61
|
+
runtime: string;
|
|
62
|
+
grokCopresence?: unknown;
|
|
63
|
+
grokAttachSocket?: unknown;
|
|
64
|
+
}): GrokAttachTarget;
|
|
65
|
+
export declare function grokBuildCliCreationFields(runtime: string, nodeId: string, headless?: boolean, options?: GrokSocketPathOptions): GrokCopresenceProfileFields | Record<string, never>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** One-line limitation list shown wherever co-presence is offered (CLI help,
|
|
2
|
+
* picker, create warning). Keep it one line — it is appended to menus. */
|
|
3
|
+
export declare const GROK_COPRESENCE_EXPERIMENTAL_NOTE_ZH = "\u5B9E\u9A8C\u6027\uFF1A\u4EBA\u5728 TUI \u8F93\u5165\u6846\u6253\u5B57\u65F6\u7F51\u7EDC\u4EFB\u52A1\u4F1A\u6392\u961F\u76F4\u5230\u8D85\u65F6\uFF1Bgrok \u987B\u9489\u5728\u5DF2\u9A8C\u8BC1\u7248\u672C\uFF08\u65B0\u7248\u4F1A\u62D2\u7EDD\u542F\u52A8\uFF09\uFF1BmacOS \u9700\u7279\u6B8A\u5904\u7406\uFF1B\u4E0D\u52A0\u8F7D .agents/skills \u6280\u80FD\u3002\u8981\u7A33\u5B9A\u63A5\u6D3B\u7528\u9ED8\u8BA4\u7684 ACP\u3002";
|
|
4
|
+
export declare const GROK_COPRESENCE_EXPERIMENTAL_NOTE_EN = "Experimental: network tasks queue until timeout while a human is typing in the TUI; grok must be pinned to a verified build (newer builds refuse to start); macOS needs special handling; .agents/skills skills are not loaded. For a stable node use the default ACP mode.";
|
|
5
|
+
export type GrokCreateModeResult = {
|
|
6
|
+
ok: true;
|
|
7
|
+
runtime: string | undefined;
|
|
8
|
+
copresenceRequested: boolean;
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
error: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the runtime string a NEW node is created with.
|
|
15
|
+
*
|
|
16
|
+
* Non-Grok runtimes (and an absent runtime) pass through untouched — this
|
|
17
|
+
* helper only decides between the two Grok lanes.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveGrokCreateRuntime(rawRuntime: string | undefined, copresence: unknown): GrokCreateModeResult;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface HostTelemetry {
|
|
2
|
+
hostname: string;
|
|
3
|
+
ip: string | null;
|
|
4
|
+
cpu_load_1min: number | null;
|
|
5
|
+
cpu_cores: number | null;
|
|
6
|
+
mem_total_gb: number | null;
|
|
7
|
+
mem_used_gb: number | null;
|
|
8
|
+
mem_avail_gb: number | null;
|
|
9
|
+
disk_total_gb: number | null;
|
|
10
|
+
disk_used_gb: number | null;
|
|
11
|
+
disk_avail_gb: number | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function getHostTelemetry(): HostTelemetry;
|
|
14
|
+
export declare function _clearHostTelemetryCache(): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const LOOPBACK_HUB_HEALTH_TIMEOUT_MS = 2000;
|
|
2
|
+
export declare const REMOTE_HUB_HEALTH_TIMEOUT_MS = 10000;
|
|
3
|
+
export declare const HUB_HEALTH_TIMEOUT_ENV = "ANET_HUB_HEALTH_TIMEOUT_MS";
|
|
4
|
+
export declare function hubHealthTimeoutMs(hub: string, env?: NodeJS.ProcessEnv): number;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export declare const COMMHUB_SERVER_PKG = "@sleep2agi/commhub-server";
|
|
2
|
+
export declare const AGENT_NETWORK_PKG = "@sleep2agi/agent-network";
|
|
3
|
+
export type HubReleaseChannel = "latest" | "preview";
|
|
4
|
+
export type HubVersionSource = "explicit" | "registry" | "cache" | "pinned-floor";
|
|
5
|
+
export interface DistTags {
|
|
6
|
+
latest?: string | null;
|
|
7
|
+
preview?: string | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function isExactSemver(v: string | null | undefined): boolean;
|
|
10
|
+
/** Semver precedence. Unparseable versions sort lowest. */
|
|
11
|
+
export declare function compareSemver(a: string, b: string): number;
|
|
12
|
+
export declare function resolveHubChannel(input: {
|
|
13
|
+
anetVersion: string;
|
|
14
|
+
flag?: string | null;
|
|
15
|
+
anetDistTags: DistTags | null;
|
|
16
|
+
}): {
|
|
17
|
+
channel: HubReleaseChannel;
|
|
18
|
+
reason: string;
|
|
19
|
+
};
|
|
20
|
+
export interface HubVersionDecision {
|
|
21
|
+
version: string;
|
|
22
|
+
source: HubVersionSource;
|
|
23
|
+
channel: HubReleaseChannel | null;
|
|
24
|
+
/** true when `version` is already present in the local bun install cache. */
|
|
25
|
+
cached: boolean;
|
|
26
|
+
/** One-line, human readable "where it came from". */
|
|
27
|
+
origin: string;
|
|
28
|
+
/** Must be printed prominently (stderr). */
|
|
29
|
+
warnings: string[];
|
|
30
|
+
}
|
|
31
|
+
export declare function decideHubServerVersion(input: {
|
|
32
|
+
explicit?: string | null;
|
|
33
|
+
channelFlag?: string | null;
|
|
34
|
+
anetVersion: string;
|
|
35
|
+
anetDistTags: DistTags | null;
|
|
36
|
+
serverDistTags: DistTags | null;
|
|
37
|
+
floor: string;
|
|
38
|
+
cachedVersions: string[];
|
|
39
|
+
}): HubVersionDecision;
|
|
40
|
+
export type ExecFn = (cmd: string, args: string[]) => string;
|
|
41
|
+
export declare function fetchDistTags(exec: ExecFn, pkg: string): DistTags | null;
|
|
42
|
+
export interface CacheFs {
|
|
43
|
+
existsSync(p: string): boolean;
|
|
44
|
+
readdirSync(p: string): string[];
|
|
45
|
+
readFileSync(p: string): string;
|
|
46
|
+
}
|
|
47
|
+
export declare function bunInstallCacheDir(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Versions of commhub-server present in bun's install cache. Bun uses two
|
|
50
|
+
* layouts (`@sleep2agi/commhub-server@<ver-or-hash>@@@1/` and
|
|
51
|
+
* `@sleep2agi/commhub-server/<ver-or-hash>@@@1/`); prerelease parts are
|
|
52
|
+
* hashed in the directory name, so the version is read from package.json.
|
|
53
|
+
*/
|
|
54
|
+
export declare function listCachedServerVersions(cacheDir: string, fs?: CacheFs): string[];
|
|
55
|
+
export declare function resolveHubServerVersion(input: {
|
|
56
|
+
explicit?: string | null;
|
|
57
|
+
channelFlag?: string | null;
|
|
58
|
+
anetVersion: string;
|
|
59
|
+
floor: string;
|
|
60
|
+
exec: ExecFn;
|
|
61
|
+
cacheDir: string;
|
|
62
|
+
fs?: CacheFs;
|
|
63
|
+
}): HubVersionDecision;
|
|
64
|
+
export declare function formatHubVersionBanner(d: HubVersionDecision): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export type ProbeName = "proc" | "ss" | "lsof" | "netstat";
|
|
2
|
+
/** null = 这条探针在本机跑不了(没有 /proc、没装 ss …);数组 = 跑了,这些 PID 在监听。 */
|
|
3
|
+
export interface SocketProbeResult {
|
|
4
|
+
pids: number[];
|
|
5
|
+
/** 端口确实被监听、但属主 PID 读不到(别的用户的进程)。 */
|
|
6
|
+
unresolved?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface HubPidRecord {
|
|
9
|
+
pid: number;
|
|
10
|
+
port: number;
|
|
11
|
+
launcher_pid?: number;
|
|
12
|
+
started_at?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface HubStopProbes {
|
|
15
|
+
platform: NodeJS.Platform;
|
|
16
|
+
socket: Partial<Record<ProbeName, (port: number) => SocketProbeResult | null>>;
|
|
17
|
+
readPidFile: (port: number) => HubPidRecord | null;
|
|
18
|
+
cmdline: (pid: number) => string | null;
|
|
19
|
+
alive: (pid: number) => boolean;
|
|
20
|
+
}
|
|
21
|
+
export type CandidateVerdict = "commhub" | "not-commhub" | "cmdline-unreadable";
|
|
22
|
+
export interface Candidate {
|
|
23
|
+
pid: number;
|
|
24
|
+
source: ProbeName | "pidfile";
|
|
25
|
+
cmdline: string | null;
|
|
26
|
+
verdict: CandidateVerdict;
|
|
27
|
+
}
|
|
28
|
+
export interface HubListenerResolution {
|
|
29
|
+
port: number;
|
|
30
|
+
/** 每条探针的结果,按尝试顺序。 */
|
|
31
|
+
tried: {
|
|
32
|
+
probe: ProbeName | "pidfile";
|
|
33
|
+
outcome: string;
|
|
34
|
+
}[];
|
|
35
|
+
/** 给出端口归属的那条探针;null = 本机没有一条能跑。 */
|
|
36
|
+
authority: ProbeName | null;
|
|
37
|
+
/** 端口被监听但读不到属主 PID 的个数。 */
|
|
38
|
+
unresolved: number;
|
|
39
|
+
/** 核实过是 commhub-server 的 PID —— 只有这些会被停。 */
|
|
40
|
+
hubPids: Candidate[];
|
|
41
|
+
/** 端口上的其他进程 / cmdline 读不到的进程 —— 拒绝动手。 */
|
|
42
|
+
refused: Candidate[];
|
|
43
|
+
}
|
|
44
|
+
export declare function probeOrder(platform: NodeJS.Platform): ProbeName[];
|
|
45
|
+
/** cmdline 是不是 commhub-server。只做核实,不用来挑选进程。 */
|
|
46
|
+
export declare function isCommhubServerCmdline(cmdline: string | null | undefined): boolean;
|
|
47
|
+
/** /proc/net/tcp 或 tcp6 文本 → 在 port 上 LISTEN(st=0A)的 socket inode。 */
|
|
48
|
+
export declare function parseProcNetTcp(text: string, port: number): string[];
|
|
49
|
+
/** `ss -Hltnp 'sport = :PORT'` → pids;有行却没有 users:(…) 的算 unresolved。 */
|
|
50
|
+
export declare function parseSsOutput(text: string, port: number): SocketProbeResult;
|
|
51
|
+
/** Windows `netstat -ano`:`TCP 127.0.0.1:9200 0.0.0.0:0 LISTENING 1234`。 */
|
|
52
|
+
export declare function parseNetstatWindows(text: string, port: number): SocketProbeResult;
|
|
53
|
+
/** macOS `netstat -anv -p tcp`:按表头找 pid 列;本地地址形如 `127.0.0.1.9200` / `*.9200`。 */
|
|
54
|
+
export declare function parseNetstatDarwin(text: string, port: number): SocketProbeResult;
|
|
55
|
+
export declare function resolveHubListener(port: number, probes: HubStopProbes): HubListenerResolution;
|
|
56
|
+
export interface StopHubDeps {
|
|
57
|
+
probes: HubStopProbes;
|
|
58
|
+
kill: (pid: number, signal: "SIGTERM" | "SIGKILL") => void;
|
|
59
|
+
sleep: (ms: number) => Promise<void>;
|
|
60
|
+
/** /health 是否 ok —— 与探针无关的独立判据。 */
|
|
61
|
+
healthy: () => Promise<boolean>;
|
|
62
|
+
log: (line: string) => void;
|
|
63
|
+
error: (line: string) => void;
|
|
64
|
+
graceMs?: number;
|
|
65
|
+
}
|
|
66
|
+
export interface StopHubResult {
|
|
67
|
+
code: 0 | 1;
|
|
68
|
+
killed: number[];
|
|
69
|
+
refused: Candidate[];
|
|
70
|
+
}
|
|
71
|
+
export declare function stopHub(port: number, d: StopHubDeps): Promise<StopHubResult>;
|
|
72
|
+
export declare function procNetListeners(port: number, procRoot?: string): SocketProbeResult | null;
|
|
73
|
+
export declare function defaultHubStopProbes(readPidFile: (port: number) => HubPidRecord | null, platform?: NodeJS.Platform): HubStopProbes;
|
|
74
|
+
export declare function readCmdline(pid: number, platform?: NodeJS.Platform): string | null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把 hub 的 TEXT 时间戳显示给人看。
|
|
3
|
+
*
|
|
4
|
+
* 🔴 原先是**原样打印**:
|
|
5
|
+
*
|
|
6
|
+
* updated: 2026-08-31 00:20:11
|
|
7
|
+
*
|
|
8
|
+
* 那是 UTC,**没有任何时区标记**。同一时刻本地是 `08:22:41 CST` ——
|
|
9
|
+
* 于是一个 **2 分钟前**刚心跳过的节点,在 UTC+8 的用户眼里像是 **8 小时前**的。
|
|
10
|
+
*
|
|
11
|
+
* 这不是假想:2026-08-31 我自己就这么读错过一次,据此差点报出「舰队心跳陈旧
|
|
12
|
+
* 8.3 小时」。**CLI 在主动制造这个误读。**
|
|
13
|
+
*
|
|
14
|
+
* 所以显示两样东西:
|
|
15
|
+
* - **相对时长**(人真正想知道的那个)
|
|
16
|
+
* - 绝对值,并**显式标 UTC**(便于和日志、issue 里的时间对齐)
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatHubTime(raw: unknown, nowMs?: number): string;
|
|
19
|
+
/** 人读的时长。负数(时钟偏差/未来时间)如实说,不折成 0。 */
|
|
20
|
+
export declare function formatAgo(deltaMs: number): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #1595 —— `anet doctor` 原先只印 hub 自报的版本:
|
|
3
|
+
*
|
|
4
|
+
* ✅ CommHub reachable (http://127.0.0.1:9200 v0.9.0-preview.38)
|
|
5
|
+
*
|
|
6
|
+
* 读的人**看不到自己这台 CLI 钉的是哪个**。实测(2026-08-31):生产 hub 在
|
|
7
|
+
* `.38`,而 `anet hub start` 的 `PINNED_SERVER_VERSION` 是 `.44` —— 两个数
|
|
8
|
+
* 差 6 个版本,而屏幕上只有一个。今天有一整条排查(agent→用户消息为什么
|
|
9
|
+
* 验不了端到端)就卡在这个差上:`.44` 之前 `send_desktop_message` 是
|
|
10
|
+
* fire-and-forget 且仍返回 `ok:true`,所以在 `.38` 上拿到的 `ok:true`
|
|
11
|
+
* 不是「用户看到了」的证据。
|
|
12
|
+
*
|
|
13
|
+
* 🔴 **只并排摆出两个数,不判断谁对、不给阈值、不发警告。**
|
|
14
|
+
* hub 比 CLI 的 pin 老或新都可能完全合理 —— 连的是别人运维的 hub、
|
|
15
|
+
* 本机 hub 还没重启、或者故意钉在旧版。给一个猜出来的「应该一致」
|
|
16
|
+
* 判据,会在这些正常情况下变成误报,而一个会误报的检查第一周就会被关掉。
|
|
17
|
+
* 让读的人自己看见差在哪,是这一格能诚实做到的全部。
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatHubVersionDetail(hubUrl: string, hubVersion: unknown, pinnedVersion: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IMCorrelationStore, IMTaskCorrelation } from "./types";
|
|
2
|
+
export interface JsonIMCorrelationStoreOptions {
|
|
3
|
+
now?: () => number;
|
|
4
|
+
/** How long idempotency keys remain valid. Defaults to 24h. */
|
|
5
|
+
seenTtlMs?: number;
|
|
6
|
+
/** How long terminal correlations remain queryable. Defaults to 24h. */
|
|
7
|
+
terminalTtlMs?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Small durable store for RFC-020 §2.9④ / §4.4 correlation state.
|
|
11
|
+
*
|
|
12
|
+
* The first gateway PR needs this as a standalone data structure before the
|
|
13
|
+
* bridge is rewired: idempotency keys survive process restart, and task replies
|
|
14
|
+
* can be routed back to their originating IM conversation.
|
|
15
|
+
*/
|
|
16
|
+
export declare class JsonIMCorrelationStore implements IMCorrelationStore {
|
|
17
|
+
private readonly path;
|
|
18
|
+
private readonly now;
|
|
19
|
+
private readonly seenTtlMs;
|
|
20
|
+
private readonly terminalTtlMs;
|
|
21
|
+
constructor(path: string, options?: JsonIMCorrelationStoreOptions);
|
|
22
|
+
hasSeen(idempotencyKey: string): Promise<string | null>;
|
|
23
|
+
recordSeen(idempotencyKey: string, taskId: string): Promise<void>;
|
|
24
|
+
getCorrelation(taskId: string): Promise<IMTaskCorrelation | null>;
|
|
25
|
+
putCorrelation(taskId: string, correlation: IMTaskCorrelation): Promise<void>;
|
|
26
|
+
updateStatus(taskId: string, status: IMTaskCorrelation["status"]): Promise<void>;
|
|
27
|
+
gc(now: number): Promise<{
|
|
28
|
+
removed: number;
|
|
29
|
+
}>;
|
|
30
|
+
private isExpired;
|
|
31
|
+
private load;
|
|
32
|
+
private save;
|
|
33
|
+
}
|
|
34
|
+
export declare function createJsonIMCorrelationStore(path: string, options?: JsonIMCorrelationStoreOptions): IMCorrelationStore;
|
|
@@ -1,5 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-020 §3.1 — Feishu (Lark) adapter for the IM compatibility layer.
|
|
3
|
+
*
|
|
4
|
+
* Uses `@larksuiteoapi/node-sdk` in WebSocket long-connection mode (WSClient).
|
|
5
|
+
* No public IP / no domain verification / no webhook signature decryption —
|
|
6
|
+
* the three biggest 飞书 接入 risks all live in the HTTP event-callback path,
|
|
7
|
+
* not in WSClient mode.
|
|
8
|
+
*
|
|
9
|
+
* Milestones:
|
|
10
|
+
* M1: contract scaffold.
|
|
11
|
+
* M2 (this file): WSClient init + EventDispatcher for `im.message.receive_v1`
|
|
12
|
+
* + event normalization + access whitelist gate + audit log.
|
|
13
|
+
* M3: outbound `im.message.create` (text), edit support (≤20/msg).
|
|
14
|
+
* M5: image upload / download (`im.image.create` / `im.messageResource.get`)
|
|
15
|
+
* + group @bot detection refined to match the bot's own open_id.
|
|
16
|
+
*/
|
|
17
|
+
import type { FeishuHistoryItem } from "./chat-context";
|
|
18
|
+
import * as lark from "@larksuiteoapi/node-sdk";
|
|
1
19
|
import type { IMAdapter, IMAdapterHealth, IMChannelConfig, IMConversationRef, IMIngressMode, NormalizedIMEvent, NormalizedIMMessage } from "../types.js";
|
|
2
20
|
type OnEventHandler = (event: NormalizedIMEvent) => Promise<void>;
|
|
21
|
+
export type FeishuWsClientLike = Pick<lark.WSClient, "start" | "close">;
|
|
22
|
+
export type FeishuWsClientFactory = (params: ConstructorParameters<typeof lark.WSClient>[0]) => FeishuWsClientLike;
|
|
23
|
+
type FeishuInboundHandler = (rawEvent: unknown) => Promise<unknown>;
|
|
24
|
+
export interface FeishuEventDispatcherLike {
|
|
25
|
+
register(handlers: Record<string, FeishuInboundHandler>): unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface FeishuAdapterOptions {
|
|
28
|
+
/** @internal Avoids real bot-info HTTP calls in lifecycle tests. */
|
|
29
|
+
createClient?: (params: ConstructorParameters<typeof lark.Client>[0]) => lark.Client;
|
|
30
|
+
/** @internal Test seam; production uses the pinned Lark SDK WSClient. */
|
|
31
|
+
createWsClient?: FeishuWsClientFactory;
|
|
32
|
+
/** @internal Test seam; production uses the pinned Lark SDK dispatcher. */
|
|
33
|
+
createEventDispatcher?: () => FeishuEventDispatcherLike;
|
|
34
|
+
/** Independent outer bound in case the SDK promise/callback path stalls. */
|
|
35
|
+
wsReadyTimeoutMs?: number;
|
|
36
|
+
/** Called once when an already-ready socket exhausts reconnect attempts. */
|
|
37
|
+
onTerminalError?: (error: Error) => void;
|
|
38
|
+
}
|
|
3
39
|
export declare class FeishuAdapter implements IMAdapter {
|
|
4
40
|
readonly platform = "feishu";
|
|
5
41
|
readonly ingressMode: IMIngressMode;
|
|
@@ -7,6 +43,8 @@ export declare class FeishuAdapter implements IMAdapter {
|
|
|
7
43
|
private connectionName_;
|
|
8
44
|
private client;
|
|
9
45
|
private wsClient;
|
|
46
|
+
private lifecycleGeneration;
|
|
47
|
+
private readonly options;
|
|
10
48
|
/**
|
|
11
49
|
* The bot's own open_id, resolved at init() via /open-apis/bot/v3/info.
|
|
12
50
|
* Used to detect real @bot mentions (vs any mention) in group messages.
|
|
@@ -17,6 +55,7 @@ export declare class FeishuAdapter implements IMAdapter {
|
|
|
17
55
|
/** Where to persist downloaded inbound media (M5c). */
|
|
18
56
|
private mediaDir;
|
|
19
57
|
private health_;
|
|
58
|
+
constructor(options?: FeishuAdapterOptions);
|
|
20
59
|
/**
|
|
21
60
|
* Snapshot of the current `access.allowFrom` list (from access.json).
|
|
22
61
|
* Used by the bridge's rate-limiter to exempt operator-vouched explicit
|
|
@@ -37,6 +76,9 @@ export declare class FeishuAdapter implements IMAdapter {
|
|
|
37
76
|
init(config: IMChannelConfig): Promise<void>;
|
|
38
77
|
start(onEvent: OnEventHandler): Promise<void>;
|
|
39
78
|
stop(): Promise<void>;
|
|
79
|
+
/** #3682 —— 拉这个会话最近的消息,做聊天上下文。放在 adapter 是因为只有它有已鉴权的 client。
|
|
80
|
+
* 失败一律返回 []:上下文是增益不是链路的一部分,绝不因为读历史失败而丢消息。 */
|
|
81
|
+
fetchRecentContext(chatId: string, limit?: number): Promise<FeishuHistoryItem[]>;
|
|
40
82
|
send(message: NormalizedIMMessage): Promise<{
|
|
41
83
|
messageId: string;
|
|
42
84
|
}>;
|
|
@@ -131,4 +173,9 @@ export declare const FEISHU_TEXT_SINGLE_LIMIT = 4000;
|
|
|
131
173
|
* If the input is already short enough, returns a single-element array.
|
|
132
174
|
*/
|
|
133
175
|
export declare function splitTextForFeishu(text: string, maxChars: number): string[];
|
|
176
|
+
/**
|
|
177
|
+
* Lark errors may echo request/config values. Keep worker logs actionable while
|
|
178
|
+
* ensuring credentials and multiline payloads never cross the process boundary.
|
|
179
|
+
*/
|
|
180
|
+
export declare function sanitizeFeishuWsError(rawError: unknown, appId: string, appSecret: string): Error;
|
|
134
181
|
export {};
|
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
* RFC-020 §2.5 / RFC-002 §2.2 — Feishu bridge worker.
|
|
3
3
|
*
|
|
4
4
|
* Entry point spawned by agent-node when a node profile has `channels.feishu`
|
|
5
|
-
* enabled.
|
|
6
|
-
* "agent-node direct bridge" model, not the full commhub-gateway:
|
|
5
|
+
* enabled. This worker owns the FeishuAdapter and its WSClient connection.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
* - Inbound IM event → access whitelist gate → forward to agent-node's main
|
|
10
|
-
* `think()` via parent IPC.
|
|
11
|
-
* - think() result → adapter.send() back to the originating conversation.
|
|
7
|
+
* 🔴 There are TWO outbound paths, and which one runs is decided at line ~445:
|
|
12
8
|
*
|
|
13
|
-
*
|
|
9
|
+
* 选路由是**显式**的(resolveFeishuBridgeMode):默认 direct,只有
|
|
10
|
+
* ANET_FEISHU_BRIDGE_MODE=commhub 才走 Hub。非法值启动即抛,不静默取默认。
|
|
11
|
+
*
|
|
12
|
+
* (A) direct(默认)—— 消息直接进本机节点的 think()(IPC)。
|
|
13
|
+
* 桥必须和节点同机;少一跳,失败只在一层。
|
|
14
|
+
* (B) commhub —— 消息变成一条 **CommHub task** 派给目标 alias,再轮询自己的
|
|
15
|
+
* inbox 取 reply。桥可以在任何机器;多一层(派发/执行/回读),
|
|
16
|
+
* 多节点还需要一层"@谁发给谁"的路由(尚未实现)。
|
|
17
|
+
*
|
|
18
|
+
* ⚠️ 这段曾经写成「CommHub dispatch 是任何真实节点的默认」,而代码里默认是 direct ——
|
|
19
|
+
* 谁按注释选模式就会以为自己走 Hub。改默认值时,同一提交里改这段。
|
|
20
|
+
*
|
|
21
|
+
* Still true of both paths (unchanged from the first cut):
|
|
14
22
|
* - No separate gateway ntok_ / dedicated commhub alias.
|
|
15
|
-
* - IM messages do NOT pass through commhub task dispatch.
|
|
16
|
-
* - Feishu messages do NOT appear in Dashboard topology / Chat.
|
|
17
23
|
*
|
|
18
|
-
* The
|
|
19
|
-
*
|
|
20
|
-
* — tracked in #182.
|
|
24
|
+
* The remaining §2.9 work (meta_json columns, SSE passthrough, Dashboard
|
|
25
|
+
* topology / Chat visibility for Feishu conversations) is tracked in #182.
|
|
21
26
|
*
|
|
22
27
|
* Milestones:
|
|
23
28
|
* M1: worker entry scaffold.
|
|
@@ -29,8 +34,29 @@
|
|
|
29
34
|
* M4: agent-node spawn integration (fork(this) wired by agent-node).
|
|
30
35
|
* M5: group @bot trigger refinement, image up/down, Docker smoke.
|
|
31
36
|
*/
|
|
32
|
-
import type { NormalizedIMEvent } from "../types.js";
|
|
37
|
+
import type { IMCorrelationStore, NormalizedIMEvent } from "../types.js";
|
|
33
38
|
import { FeishuAdapter } from "./adapter.js";
|
|
39
|
+
export type IMBridgeCommHubInboxMessage = {
|
|
40
|
+
id: string;
|
|
41
|
+
type?: string;
|
|
42
|
+
content: string;
|
|
43
|
+
from_session?: string;
|
|
44
|
+
in_reply_to?: string;
|
|
45
|
+
meta?: unknown;
|
|
46
|
+
};
|
|
47
|
+
export interface IMBridgeCommHubClient {
|
|
48
|
+
sendTask(args: {
|
|
49
|
+
alias: string;
|
|
50
|
+
task: string;
|
|
51
|
+
priority?: "high" | "normal" | "low";
|
|
52
|
+
ttlSeconds?: number;
|
|
53
|
+
meta?: unknown;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
taskId: string;
|
|
56
|
+
}>;
|
|
57
|
+
getInbox(alias: string): Promise<IMBridgeCommHubInboxMessage[]>;
|
|
58
|
+
ackInbox(alias: string, messageId: string): Promise<void>;
|
|
59
|
+
}
|
|
34
60
|
export interface FeishuBridgeOptions {
|
|
35
61
|
/** Absolute path to `.anet/nodes/<node>/channels/feishu/`. */
|
|
36
62
|
channelDir: string;
|
|
@@ -44,6 +70,16 @@ export interface FeishuBridgeOptions {
|
|
|
44
70
|
* - stderr logger otherwise (standalone smoke debugging).
|
|
45
71
|
*/
|
|
46
72
|
onEvent?: (event: NormalizedIMEvent) => Promise<void>;
|
|
73
|
+
/** Fatal WS failure after initial readiness (for worker lifecycle ownership). */
|
|
74
|
+
onTerminalError?: (error: Error) => void;
|
|
75
|
+
/** Persistent task/message correlation state. Defaults to channelDir/state.json. */
|
|
76
|
+
correlationStore?: IMCorrelationStore;
|
|
77
|
+
/** CommHub task transport. Defaults to COMMHUB_URL/COMMHUB_TOKEN when available. */
|
|
78
|
+
commhubClient?: IMBridgeCommHubClient;
|
|
79
|
+
/** Poll interval for CommHub replies. Defaults to 1500ms. */
|
|
80
|
+
commhubPollMs?: number;
|
|
81
|
+
/** 出站传输模式。省略时按 ANET_FEISHU_BRIDGE_MODE,再省略则 "direct"。 */
|
|
82
|
+
bridgeMode?: FeishuBridgeMode;
|
|
47
83
|
}
|
|
48
84
|
/** Bridge → parent: inbound IM event ready for think(). */
|
|
49
85
|
export interface BridgeIncomingEnvelope {
|
|
@@ -56,6 +92,9 @@ export interface BridgeIncomingEnvelope {
|
|
|
56
92
|
* bridge from `event.conversation.conversationId` + `adapter
|
|
57
93
|
* .connectionName`. Trailing slash included. */
|
|
58
94
|
outboundDir?: string;
|
|
95
|
+
/** #3682 —— 已归一化/裁剪/写明"不是新指令"的上下文块(跨包共享不了 mapper,
|
|
96
|
+
* 所以归一化留在有 mapper 的这一侧,node 侧只做拼接)。 */
|
|
97
|
+
contextBlock?: string;
|
|
59
98
|
}
|
|
60
99
|
/** Parent → bridge: agent reply text for a previously-forwarded event. */
|
|
61
100
|
export interface BridgeReplyEnvelope {
|
|
@@ -101,6 +140,24 @@ export type WithRateLimitHandle = {
|
|
|
101
140
|
floodKeyCount: number;
|
|
102
141
|
};
|
|
103
142
|
};
|
|
143
|
+
/**
|
|
144
|
+
* 出站传输模式。**显式声明,不靠环境变量在场与否去猜。**
|
|
145
|
+
*
|
|
146
|
+
* direct — parent IPC → agent-node 的 think()。**默认。**
|
|
147
|
+
* 2026-06-24 的第一版路径,飞书消息不进 CommHub 任务分发,
|
|
148
|
+
* 也不出现在 Dashboard 拓扑 / Chat 里。
|
|
149
|
+
* commhub — 入站事件变成一个 CommHub task,回复带 in_reply_to,
|
|
150
|
+
* correlation store 跟踪状态。**必须显式打开。**
|
|
151
|
+
*
|
|
152
|
+
* 🔴 为什么要显式:在此之前是 `commhubClient ?? createEnvCommHubClient()` ——
|
|
153
|
+
* 有 COMMHUB_URL 就走 commhub、没有就悄悄回落 IPC。两条路径的可观测性、
|
|
154
|
+
* Dashboard 可见性、失败语义完全不同,而**运维看不出自己在哪条上**,
|
|
155
|
+
* 文件头注释也因此和代码说了相反的话长达一次发布。
|
|
156
|
+
*/
|
|
157
|
+
export type FeishuBridgeMode = "commhub" | "direct";
|
|
158
|
+
export declare const DEFAULT_FEISHU_BRIDGE_MODE: FeishuBridgeMode;
|
|
159
|
+
/** 解析模式。优先级:显式入参 > 环境变量 > 默认。非法值直接抛,不静默取默认。 */
|
|
160
|
+
export declare function resolveFeishuBridgeMode(explicit?: FeishuBridgeMode, env?: NodeJS.ProcessEnv): FeishuBridgeMode;
|
|
104
161
|
/**
|
|
105
162
|
* IPC handler — forwards inbound events to the parent agent-node and routes
|
|
106
163
|
* the parent's reply back to Feishu via the adapter. The parent contract is
|
|
@@ -125,7 +182,8 @@ export type WithRateLimitHandle = {
|
|
|
125
182
|
* the agent-node.log (closes the prior silent-success blindspot).
|
|
126
183
|
*/
|
|
127
184
|
/** @internal exported for test harness; not intended for production callers. */
|
|
128
|
-
export declare function createIPCEventHandler(adapter: FeishuAdapter, ttlMs: number, ackPlaceholder: boolean): (event: NormalizedIMEvent) => Promise<void>;
|
|
185
|
+
export declare function createIPCEventHandler(adapter: FeishuAdapter, ttlMs: number, ackPlaceholder: boolean, correlationStore?: IMCorrelationStore): (event: NormalizedIMEvent) => Promise<void>;
|
|
186
|
+
export declare function createCommHubEventHandler(nodeAlias: string, adapter: FeishuAdapter, ttlMs: number, ackPlaceholder: boolean, correlationStore: IMCorrelationStore | undefined, commhubClient: IMBridgeCommHubClient, pollMs?: number): (event: NormalizedIMEvent) => Promise<void>;
|
|
129
187
|
export { FeishuAdapter } from "./adapter.js";
|
|
130
188
|
export { loadFeishuChannelConfig } from "./config.js";
|
|
131
189
|
export type { FeishuAccessList, FeishuChannelConfig, FeishuChannelEnv, } from "./config.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface FeishuHistoryItem {
|
|
2
|
+
message_id?: string;
|
|
3
|
+
create_time?: string;
|
|
4
|
+
msg_type?: string;
|
|
5
|
+
body?: {
|
|
6
|
+
content?: string;
|
|
7
|
+
};
|
|
8
|
+
sender?: {
|
|
9
|
+
id?: string;
|
|
10
|
+
sender_type?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface ChatContextLine {
|
|
14
|
+
/** 发送者 open_id(拿不到就是 null,不编)。 */
|
|
15
|
+
senderId: string | null;
|
|
16
|
+
/** 是否机器人自己说的(sender_type === "app")。 */
|
|
17
|
+
fromBot: boolean;
|
|
18
|
+
/** 已裁剪的纯文本;空消息不会出现在结果里。 */
|
|
19
|
+
text: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ChatContextLimits {
|
|
22
|
+
/** 最多几条(默认 8)。历史越长越容易掺进无关内容。 */
|
|
23
|
+
limit?: number;
|
|
24
|
+
/** 单条最多多少字符(默认 500)。 */
|
|
25
|
+
maxCharsPerMessage?: number;
|
|
26
|
+
/** 总字符预算(默认 2000);超了从**最旧**的开始丢。 */
|
|
27
|
+
maxTotalChars?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 飞书 history items → 上下文行。
|
|
31
|
+
*
|
|
32
|
+
* 输入顺序按飞书返回的"新→旧"(ByCreateTimeDesc)。**输出反转成"旧→新"**:
|
|
33
|
+
* 读起来像对话,且模型不会把最旧的那句当成最后说的话。
|
|
34
|
+
*/
|
|
35
|
+
export declare function mapHistoryToContext(items: readonly FeishuHistoryItem[] | undefined, limits?: ChatContextLimits): ChatContextLine[];
|
|
36
|
+
/**
|
|
37
|
+
* 上下文 → 注入 prompt 的块。
|
|
38
|
+
*
|
|
39
|
+
* 三条写在文案里、必须一眼可见的约束:
|
|
40
|
+
* · 这是**历史数据**,不是新指令(防"历史里的句子被执行")
|
|
41
|
+
* · 可能被截断(防模型以为看到了全部)
|
|
42
|
+
* · 发送者用 open_id 的短前缀,不展开身份(拿不到就不编)
|
|
43
|
+
*/
|
|
44
|
+
export declare function renderContextBlock(lines: readonly ChatContextLine[]): string;
|
|
@@ -7,6 +7,12 @@ export interface FeishuAccessList {
|
|
|
7
7
|
allowFrom: string[];
|
|
8
8
|
/** Feishu chat_ids the bot is permitted to listen in. */
|
|
9
9
|
allowChats: string[];
|
|
10
|
+
/** #3682 —— open_id → 角色。只对**已准入**的人生效。 */
|
|
11
|
+
users?: Record<string, {
|
|
12
|
+
role?: string;
|
|
13
|
+
} | undefined>;
|
|
14
|
+
/** #3682 —— 未登记角色的人的默认档(缺省 member,与接入前行为一致)。 */
|
|
15
|
+
defaultRole?: string;
|
|
10
16
|
}
|
|
11
17
|
/**
|
|
12
18
|
* Outbound text-reply rendering mode (RFC-020 §16). Controls how
|
|
@@ -62,4 +68,12 @@ export interface FeishuChannelConfig {
|
|
|
62
68
|
* Load Feishu channel config from a node's channels/feishu directory.
|
|
63
69
|
* Throws if required secrets are missing.
|
|
64
70
|
*/
|
|
65
|
-
export declare function loadFeishuChannelConfig(channelDir: string
|
|
71
|
+
export declare function loadFeishuChannelConfig(channelDir: string,
|
|
72
|
+
/**
|
|
73
|
+
* 进程环境(可选)。存在的理由:跨机节点拿不到"把 .env 拷过去"这件事 ——
|
|
74
|
+
* 密钥只能通过 Hub 保险库推到 <nodeDir>/node-secrets.json,agent-node 启动时
|
|
75
|
+
* 把它灌进 process.env(activation: next_start)。所以这里的读取顺序是:
|
|
76
|
+
* .env 文件 > process.env
|
|
77
|
+
* 反过来会让一个陈旧的 .env 悄悄盖掉刚推下来的值。
|
|
78
|
+
*/
|
|
79
|
+
processEnv?: Record<string, string | undefined>): FeishuChannelConfig;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* RFC-020 §17 — feishu inbound bridge → hub `/api/upload` integration.
|
|
3
3
|
*
|
|
4
|
-
* Vincent 2026-06-30: cross-machine agents (e.g.
|
|
4
|
+
* Vincent 2026-06-30: cross-machine agents (e.g. a partner-team node on a partner-team host)
|
|
5
5
|
* delegated by the feishu-local bot can't read inbound attachments
|
|
6
6
|
* because the only thing they get is a host-local path that doesn't
|
|
7
7
|
* exist on the receiver's filesystem. #351 already wired agent-node's
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface WorkerProcessBoundary {
|
|
2
|
+
stderr: {
|
|
3
|
+
write(message: string): unknown;
|
|
4
|
+
};
|
|
5
|
+
exit(code: number): unknown;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A terminal WS error means this worker no longer owns a live ingress path.
|
|
9
|
+
* Exit non-zero so the parent/supervisor cannot continue advertising it as
|
|
10
|
+
* healthy. Kept separate from worker.ts so the real exit contract is testable.
|
|
11
|
+
*/
|
|
12
|
+
export declare function exitFeishuWorker(error: Error, boundary?: WorkerProcessBoundary): void;
|
|
13
|
+
export {};
|