@poolzin/pool-bot 2026.2.21 → 2026.2.22
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/CHANGELOG.md +17 -0
- package/dist/agents/api-key-rotation.js +47 -0
- package/dist/agents/apply-patch-update.js +19 -9
- package/dist/agents/apply-patch.js +72 -47
- package/dist/agents/bash-tools.exec.js +141 -559
- package/dist/agents/cli-backends.js +49 -6
- package/dist/agents/cli-runner/helpers.js +69 -152
- package/dist/agents/cli-runner.js +70 -19
- package/dist/agents/identity.js +20 -1
- package/dist/agents/image-sanitization.js +9 -0
- package/dist/agents/live-auth-keys.js +123 -26
- package/dist/agents/live-model-filter.js +13 -4
- package/dist/agents/model-catalog.js +40 -9
- package/dist/agents/model-forward-compat.js +60 -23
- package/dist/agents/model-selection.js +134 -41
- package/dist/agents/pi-auth-json.js +2 -2
- package/dist/agents/pi-embedded-helpers/bootstrap.js +65 -15
- package/dist/agents/pi-embedded-helpers/errors.js +140 -15
- package/dist/agents/pi-embedded-helpers/images.js +22 -12
- package/dist/agents/pi-embedded-helpers.js +2 -2
- package/dist/agents/pi-embedded-runner/abort.js +10 -3
- package/dist/agents/pi-embedded-runner/compact.js +230 -32
- package/dist/agents/pi-embedded-runner/extra-params.js +203 -12
- package/dist/agents/pi-embedded-runner/google.js +109 -19
- package/dist/agents/pi-embedded-runner/history.js +35 -17
- package/dist/agents/pi-embedded-runner/run/attempt.js +386 -95
- package/dist/agents/pi-embedded-runner/run/images.js +81 -55
- package/dist/agents/pi-embedded-runner/run/payloads.js +89 -39
- package/dist/agents/pi-embedded-runner/run.js +193 -25
- package/dist/agents/pi-embedded-runner/run.overflow-compaction.mocks.shared.js +2 -2
- package/dist/agents/pi-embedded-runner/runs.js +17 -8
- package/dist/agents/pi-embedded-runner/tool-result-context-guard.js +262 -0
- package/dist/agents/pi-embedded-runner.js +1 -1
- package/dist/agents/pi-embedded-subscribe.handlers.tools.js +180 -10
- package/dist/agents/pi-embedded-subscribe.js +37 -0
- package/dist/agents/pi-embedded-subscribe.tools.js +127 -30
- package/dist/agents/pi-model-discovery.js +9 -2
- package/dist/agents/pi-tool-definition-adapter.js +60 -8
- package/dist/agents/pi-tools.before-tool-call.js +1 -1
- package/dist/agents/pi-tools.js +113 -94
- package/dist/agents/pi-tools.read.js +337 -38
- package/dist/agents/poolbot-tools.js +14 -5
- package/dist/agents/sandbox/docker.js +10 -5
- package/dist/agents/sandbox/registry.js +96 -46
- package/dist/agents/sandbox/sanitize-env-vars.js +82 -0
- package/dist/agents/sandbox-paths.js +43 -10
- package/dist/agents/session-tool-result-guard-wrapper.js +23 -11
- package/dist/agents/session-tool-result-guard.js +39 -39
- package/dist/agents/session-transcript-repair.js +36 -33
- package/dist/agents/session-write-lock.js +62 -44
- package/dist/agents/skills/frontmatter.js +49 -88
- package/dist/agents/skills/workspace.js +335 -28
- package/dist/agents/subagent-announce.js +508 -174
- package/dist/agents/subagent-registry.js +45 -4
- package/dist/agents/subagent-spawn.js +16 -33
- package/dist/agents/system-prompt-report.js +27 -10
- package/dist/agents/system-prompt.js +26 -32
- package/dist/agents/tool-call-id.js +69 -17
- package/dist/agents/tool-display-common.js +1 -1
- package/dist/agents/tool-images.js +64 -31
- package/dist/agents/tools/canvas-tool.js +17 -11
- package/dist/agents/tools/common.js +37 -19
- package/dist/agents/tools/cron-tool.js +40 -38
- package/dist/agents/tools/gateway.js +70 -2
- package/dist/agents/tools/message-tool.js +181 -40
- package/dist/agents/tools/nodes-tool.js +128 -36
- package/dist/agents/tools/nodes-utils.js +12 -38
- package/dist/agents/tools/session-status-tool.js +24 -71
- package/dist/agents/tools/sessions-helpers.js +38 -210
- package/dist/agents/tools/sessions-spawn-tool.js +28 -198
- package/dist/agents/tools/telegram-actions.js +58 -7
- package/dist/agents/tools/web-fetch-utils.js +112 -7
- package/dist/agents/tools/web-fetch.js +279 -175
- package/dist/agents/tools/web-shared.js +71 -8
- package/dist/agents/usage.js +25 -16
- package/dist/auto-reply/commands-registry.data.js +85 -11
- package/dist/auto-reply/dispatch.js +40 -21
- package/dist/auto-reply/reply/abort.js +102 -33
- package/dist/auto-reply/reply/commands-core.js +82 -33
- package/dist/auto-reply/reply/commands-export-session.js +1 -1
- package/dist/auto-reply/reply/commands-info.js +41 -12
- package/dist/auto-reply/reply/commands-subagents.js +352 -100
- package/dist/auto-reply/reply/commands-system-prompt.js +2 -2
- package/dist/auto-reply/reply/dispatch-from-config.js +100 -29
- package/dist/auto-reply/reply/elevated-unavailable.js +1 -1
- package/dist/auto-reply/reply/inbound-meta.js +12 -1
- package/dist/auto-reply/reply/mentions.js +18 -11
- package/dist/auto-reply/reply/normalize-reply.js +17 -8
- package/dist/auto-reply/reply/reply-dispatcher.js +62 -10
- package/dist/auto-reply/reply/session.js +102 -21
- package/dist/auto-reply/reply/streaming-directives.js +16 -5
- package/dist/auto-reply/status.js +73 -50
- package/dist/browser/extension-relay.js +3 -3
- package/dist/browser/http-auth.js +1 -1
- package/dist/browser/paths.js +2 -2
- package/dist/build-info.json +3 -3
- package/dist/channels/allowlist-match.js +20 -0
- package/dist/channels/allowlists/resolve-utils.js +65 -2
- package/dist/channels/chat-type.js +8 -4
- package/dist/channels/dock.js +127 -35
- package/dist/channels/draft-stream-loop.js +6 -2
- package/dist/channels/plugins/actions/telegram.js +42 -18
- package/dist/channels/plugins/allowlist-match.js +1 -1
- package/dist/channels/plugins/group-mentions.js +51 -41
- package/dist/channels/plugins/message-action-names.js +2 -0
- package/dist/channels/plugins/message-actions.js +24 -5
- package/dist/channels/plugins/normalize/discord.js +26 -4
- package/dist/channels/plugins/normalize/signal.js +35 -22
- package/dist/channels/plugins/onboarding/helpers.js +8 -26
- package/dist/channels/plugins/outbound/imessage.js +15 -14
- package/dist/channels/registry.js +20 -7
- package/dist/cli/acp-cli.js +7 -5
- package/dist/cli/browser-cli-extension.js +25 -12
- package/dist/cli/browser-cli-state.cookies-storage.js +25 -6
- package/dist/cli/browser-cli-state.js +101 -145
- package/dist/cli/command-options.js +28 -0
- package/dist/cli/completion-cli.js +6 -6
- package/dist/cli/cron-cli/register.cron-add.js +25 -1
- package/dist/cli/cron-cli/register.cron-edit.js +44 -0
- package/dist/cli/cron-cli/shared.js +7 -1
- package/dist/cli/daemon-cli/lifecycle-core.js +23 -21
- package/dist/cli/daemon-cli/lifecycle.js +23 -247
- package/dist/cli/daemon-cli/register-service-commands.js +25 -4
- package/dist/cli/daemon-cli.js +1 -0
- package/dist/cli/devices-cli.js +33 -20
- package/dist/cli/gateway-cli/register.js +37 -105
- package/dist/cli/gateway-cli/run.js +49 -11
- package/dist/cli/nodes-camera.js +59 -4
- package/dist/cli/nodes-cli/register.camera.js +27 -24
- package/dist/cli/nodes-cli/rpc.js +21 -38
- package/dist/cli/qr-cli.js +2 -2
- package/dist/cli/skills-cli.format.js +2 -2
- package/dist/cli/update-cli/progress.js +2 -2
- package/dist/cli/update-cli/restart-helper.js +28 -7
- package/dist/cli/update-cli/shared.js +7 -7
- package/dist/cli/update-cli/status.js +1 -1
- package/dist/cli/update-cli/update-command.js +14 -8
- package/dist/cli/update-cli/wizard.js +2 -2
- package/dist/cli/update-cli.js +21 -1027
- package/dist/commands/auth-choice.apply.anthropic.js +10 -2
- package/dist/commands/channels/add-mutators.js +3 -35
- package/dist/commands/channels/add.js +39 -51
- package/dist/commands/config-validation.js +1 -1
- package/dist/commands/configure.gateway-auth.js +52 -15
- package/dist/commands/configure.gateway.js +84 -40
- package/dist/commands/doctor-completion.js +3 -3
- package/dist/commands/doctor-config-flow.js +536 -16
- package/dist/commands/doctor-gateway-services.js +103 -79
- package/dist/commands/doctor-memory-search.js +9 -9
- package/dist/commands/doctor-platform-notes.js +57 -30
- package/dist/commands/doctor-prompter.js +26 -15
- package/dist/commands/doctor-session-locks.js +1 -1
- package/dist/commands/doctor.js +21 -9
- package/dist/commands/model-picker.js +120 -95
- package/dist/commands/models/set.js +2 -21
- package/dist/commands/models/shared.js +65 -37
- package/dist/commands/onboard-helpers.js +81 -39
- package/dist/commands/openai-codex-oauth.js +1 -1
- package/dist/commands/sessions.js +52 -53
- package/dist/commands/status.summary.js +52 -34
- package/dist/commands/test-wizard-helpers.js +2 -2
- package/dist/config/defaults.js +79 -42
- package/dist/config/group-policy.js +50 -18
- package/dist/config/includes.js +37 -10
- package/dist/config/schema.help.js +5 -4
- package/dist/config/schema.hints.js +2 -2
- package/dist/config/schema.labels.js +1 -0
- package/dist/config/sessions/group.js +12 -11
- package/dist/config/sessions/paths.js +137 -11
- package/dist/config/sessions/store.js +185 -65
- package/dist/config/sessions/types.js +15 -1
- package/dist/config/sessions.js +1 -0
- package/dist/config/telegram-custom-commands.js +3 -2
- package/dist/config/types.js +2 -0
- package/dist/config/zod-schema.agent-defaults.js +6 -27
- package/dist/config/zod-schema.agent-runtime.js +171 -79
- package/dist/config/zod-schema.providers-core.js +138 -65
- package/dist/config/zod-schema.session.js +49 -22
- package/dist/control-ui/assets/index-HRr1grwl.js.map +1 -1
- package/dist/cron/isolated-agent/run.js +224 -57
- package/dist/cron/normalize.js +48 -45
- package/dist/cron/run-log.js +14 -0
- package/dist/cron/service/jobs.js +190 -28
- package/dist/cron/service/normalize.js +29 -11
- package/dist/cron/service/store.js +30 -44
- package/dist/cron/service/timer.js +182 -96
- package/dist/cron/service.js +3 -0
- package/dist/cron/stagger.js +37 -0
- package/dist/daemon/inspect.js +132 -92
- package/dist/daemon/runtime-paths.js +25 -4
- package/dist/daemon/service-audit.js +47 -16
- package/dist/discord/accounts.js +23 -20
- package/dist/discord/monitor/agent-components.js +1115 -219
- package/dist/discord/monitor/allow-list.js +114 -34
- package/dist/discord/monitor/listeners.js +204 -97
- package/dist/discord/monitor/message-handler.js +21 -10
- package/dist/discord/monitor/message-handler.preflight.js +195 -101
- package/dist/discord/monitor/message-handler.process.js +384 -123
- package/dist/discord/monitor/message-utils.js +86 -23
- package/dist/discord/monitor/native-command.js +77 -57
- package/dist/discord/monitor/provider.js +122 -117
- package/dist/discord/monitor/reply-context.js +20 -16
- package/dist/discord/monitor/reply-delivery.js +40 -8
- package/dist/discord/monitor/rest-fetch.js +22 -0
- package/dist/discord/monitor/threading.js +117 -24
- package/dist/discord/send.js +2 -1
- package/dist/discord/send.outbound.js +124 -11
- package/dist/discord/send.shared.js +112 -72
- package/dist/discord/voice-message.js +3 -3
- package/dist/gateway/auth.js +119 -44
- package/dist/gateway/call.js +76 -34
- package/dist/gateway/channel-health-monitor.js +57 -50
- package/dist/gateway/client.js +63 -29
- package/dist/gateway/control-ui-contract.js +1 -1
- package/dist/gateway/gateway-config-prompts.shared.js +2 -2
- package/dist/gateway/net.js +109 -1
- package/dist/gateway/protocol/index.js +5 -8
- package/dist/gateway/protocol/schema/agent.js +19 -1
- package/dist/gateway/protocol/schema/channels.js +21 -0
- package/dist/gateway/protocol/schema/cron.js +43 -30
- package/dist/gateway/protocol/schema/protocol-schemas.js +6 -11
- package/dist/gateway/protocol/schema/sessions.js +5 -1
- package/dist/gateway/protocol/schema.js +0 -1
- package/dist/gateway/server/presence-events.js +12 -0
- package/dist/gateway/server/ws-connection/message-handler.js +203 -212
- package/dist/gateway/server/ws-connection.js +58 -21
- package/dist/gateway/server-broadcast.js +18 -13
- package/dist/gateway/server-cron.js +177 -10
- package/dist/gateway/server-methods/agent-job.js +131 -38
- package/dist/gateway/server-methods/send.js +60 -14
- package/dist/gateway/server-methods/sessions.js +160 -96
- package/dist/gateway/server-methods/system.js +5 -7
- package/dist/gateway/server-methods-list.js +8 -0
- package/dist/gateway/server-methods.js +24 -8
- package/dist/gateway/server-node-events.js +278 -68
- package/dist/gateway/session-utils.fs.js +316 -75
- package/dist/gateway/session-utils.js +224 -70
- package/dist/gateway/sessions-patch.js +63 -20
- package/dist/gateway/test-temp-config.js +1 -1
- package/dist/gateway/tools-invoke-http.js +118 -70
- package/dist/gateway/ws-log.js +135 -107
- package/dist/hooks/frontmatter.js +36 -82
- package/dist/hooks/install.js +149 -139
- package/dist/hooks/internal-hooks.js +29 -4
- package/dist/hooks/plugin-hooks.js +2 -1
- package/dist/imessage/monitor/deliver.js +10 -4
- package/dist/imessage/monitor/monitor-provider.js +138 -375
- package/dist/imessage/monitor/runtime.js +4 -8
- package/dist/imessage/send.js +65 -19
- package/dist/infra/exec-approvals-allowlist.js +7 -0
- package/dist/infra/exec-approvals.js +35 -920
- package/dist/infra/exec-safe-bin-trust.js +64 -0
- package/dist/infra/heartbeat-runner.js +207 -134
- package/dist/infra/heartbeat-wake.js +183 -22
- package/dist/infra/install-source-utils.js +47 -0
- package/dist/infra/net/ssrf.js +170 -36
- package/dist/infra/outbound/deliver.js +224 -58
- package/dist/infra/outbound/message-action-spec.js +12 -5
- package/dist/infra/outbound/outbound-session.js +27 -25
- package/dist/infra/poolbot-root.js +32 -22
- package/dist/infra/ports.js +14 -11
- package/dist/infra/skills-remote.js +48 -37
- package/dist/infra/system-events.js +25 -11
- package/dist/infra/system-presence.js +26 -33
- package/dist/infra/tmp-poolbot-dir.js +81 -2
- package/dist/infra/wsl.js +37 -1
- package/dist/line/bot-message-context.js +163 -191
- package/dist/logging/subsystem.js +59 -22
- package/dist/markdown/ir.js +124 -50
- package/dist/media/store.js +1 -1
- package/dist/media-understanding/runner.entries.js +42 -25
- package/dist/media-understanding/runner.js +53 -488
- package/dist/memory/embeddings-gemini.js +53 -38
- package/dist/memory/manager-embedding-ops.js +48 -69
- package/dist/pairing/pairing-store.js +178 -119
- package/dist/plugin-sdk/index.js +34 -6
- package/dist/plugins/hooks.js +135 -14
- package/dist/plugins/install.js +190 -152
- package/dist/polls.js +11 -0
- package/dist/routing/resolve-route.js +190 -56
- package/dist/routing/session-key.js +38 -22
- package/dist/runtime.js +35 -9
- package/dist/security/audit-channel.js +1 -1
- package/dist/sessions/session-key-utils.js +29 -11
- package/dist/shared/frontmatter.js +5 -5
- package/dist/shared/node-list-types.js +1 -0
- package/dist/shared/string-normalization.js +15 -0
- package/dist/signal/monitor/event-handler.js +68 -36
- package/dist/signal/send.js +29 -37
- package/dist/slack/monitor/allow-list.js +10 -11
- package/dist/slack/monitor/commands.js +14 -3
- package/dist/slack/monitor/events/interactions.js +4 -4
- package/dist/slack/monitor/media.js +224 -16
- package/dist/slack/monitor/message-handler/dispatch.js +247 -13
- package/dist/slack/monitor/message-handler/prepare.js +128 -45
- package/dist/slack/monitor/slash.js +357 -144
- package/dist/slack/streaming.js +77 -0
- package/dist/telegram/accounts.js +40 -13
- package/dist/telegram/allowed-updates.js +3 -0
- package/dist/telegram/bot/delivery.js +129 -66
- package/dist/telegram/bot/helpers.js +136 -122
- package/dist/telegram/bot-handlers.js +600 -339
- package/dist/telegram/bot-message-context.js +115 -73
- package/dist/telegram/bot-message-dispatch.js +235 -104
- package/dist/telegram/bot-native-command-menu.js +3 -1
- package/dist/telegram/bot-native-commands.js +213 -193
- package/dist/telegram/bot.js +24 -132
- package/dist/telegram/draft-stream.js +84 -75
- package/dist/telegram/format.js +150 -6
- package/dist/telegram/send.js +415 -255
- package/dist/telegram/targets.js +21 -2
- package/dist/telegram/update-offset-store.js +19 -3
- package/dist/terminal/restore.js +5 -2
- package/dist/test-utils/fetch-mock.js +5 -0
- package/dist/version.js +18 -5
- package/dist/web/auto-reply/monitor/broadcast.js +7 -3
- package/dist/web/auto-reply/monitor/on-message.js +6 -3
- package/dist/web/inbound/media.js +34 -8
- package/dist/web/inbound/monitor.js +34 -17
- package/dist/web/inbound/send-api.js +18 -17
- package/dist/web/outbound.js +12 -5
- package/dist/wizard/clack-prompter.js +40 -7
- package/extensions/bluebubbles/package.json +1 -1
- package/extensions/copilot-proxy/package.json +1 -1
- package/extensions/diagnostics-otel/package.json +1 -1
- package/extensions/discord/package.json +1 -1
- package/extensions/feishu/package.json +1 -1
- package/extensions/google-antigravity-auth/package.json +1 -1
- package/extensions/google-gemini-cli-auth/package.json +1 -1
- package/extensions/googlechat/package.json +1 -1
- package/extensions/imessage/package.json +1 -1
- package/extensions/irc/package.json +1 -1
- package/extensions/line/package.json +1 -1
- package/extensions/llm-task/package.json +1 -1
- package/extensions/lobster/package.json +1 -1
- package/extensions/matrix/CHANGELOG.md +5 -0
- package/extensions/matrix/package.json +1 -1
- package/extensions/mattermost/package.json +1 -1
- package/extensions/memory-core/package.json +1 -1
- package/extensions/memory-lancedb/package.json +1 -1
- package/extensions/minimax-portal-auth/package.json +1 -1
- package/extensions/msteams/CHANGELOG.md +5 -0
- package/extensions/msteams/package.json +1 -1
- package/extensions/nextcloud-talk/package.json +1 -1
- package/extensions/nostr/CHANGELOG.md +5 -0
- package/extensions/nostr/package.json +1 -1
- package/extensions/open-prose/package.json +1 -1
- package/extensions/openai-codex-auth/package.json +1 -1
- package/extensions/signal/package.json +1 -1
- package/extensions/slack/package.json +1 -1
- package/extensions/telegram/package.json +1 -1
- package/extensions/tlon/package.json +1 -1
- package/extensions/twitch/CHANGELOG.md +5 -0
- package/extensions/twitch/package.json +1 -1
- package/extensions/voice-call/CHANGELOG.md +5 -0
- package/extensions/voice-call/package.json +1 -1
- package/extensions/whatsapp/package.json +1 -1
- package/extensions/zalo/CHANGELOG.md +5 -0
- package/extensions/zalo/package.json +1 -1
- package/extensions/zalouser/CHANGELOG.md +5 -0
- package/extensions/zalouser/package.json +1 -1
- package/package.json +1 -1
- package/skills/apple-reminders/SKILL.md +100 -49
- package/skills/coding-agent/SKILL.md +34 -28
- package/skills/github/SKILL.md +131 -16
- package/skills/imsg/SKILL.md +112 -15
- package/skills/openhue/SKILL.md +101 -19
- package/skills/tmux/SKILL.md +111 -79
- package/skills/weather/SKILL.md +88 -25
|
@@ -5,7 +5,7 @@ import { readSessionUpdatedAt, recordSessionMetaFromInbound, resolveStorePath, u
|
|
|
5
5
|
import { logVerbose, shouldLogVerbose } from "../globals.js";
|
|
6
6
|
import { recordChannelActivity } from "../infra/channel-activity.js";
|
|
7
7
|
import { resolveAgentRoute } from "../routing/resolve-route.js";
|
|
8
|
-
function
|
|
8
|
+
export function getLineSourceInfo(source) {
|
|
9
9
|
const userId = source.type === "user"
|
|
10
10
|
? source.userId
|
|
11
11
|
: source.type === "group"
|
|
@@ -30,6 +30,25 @@ function buildPeerId(source) {
|
|
|
30
30
|
}
|
|
31
31
|
return "unknown";
|
|
32
32
|
}
|
|
33
|
+
function resolveLineInboundRoute(params) {
|
|
34
|
+
recordChannelActivity({
|
|
35
|
+
channel: "line",
|
|
36
|
+
accountId: params.account.accountId,
|
|
37
|
+
direction: "inbound",
|
|
38
|
+
});
|
|
39
|
+
const { userId, groupId, roomId, isGroup } = getLineSourceInfo(params.source);
|
|
40
|
+
const peerId = buildPeerId(params.source);
|
|
41
|
+
const route = resolveAgentRoute({
|
|
42
|
+
cfg: params.cfg,
|
|
43
|
+
channel: "line",
|
|
44
|
+
accountId: params.account.accountId,
|
|
45
|
+
peer: {
|
|
46
|
+
kind: isGroup ? "group" : "direct",
|
|
47
|
+
id: peerId,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
return { userId, groupId, roomId, isGroup, peerId, route };
|
|
51
|
+
}
|
|
33
52
|
// Common LINE sticker package descriptions
|
|
34
53
|
const STICKER_PACKAGES = {
|
|
35
54
|
"1": "Moon & James",
|
|
@@ -97,141 +116,172 @@ function extractMediaPlaceholder(message) {
|
|
|
97
116
|
return "";
|
|
98
117
|
}
|
|
99
118
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
119
|
+
function resolveLineConversationLabel(params) {
|
|
120
|
+
return params.isGroup
|
|
121
|
+
? params.groupId
|
|
122
|
+
? `group:${params.groupId}`
|
|
123
|
+
: params.roomId
|
|
124
|
+
? `room:${params.roomId}`
|
|
125
|
+
: "unknown-group"
|
|
126
|
+
: params.senderLabel;
|
|
127
|
+
}
|
|
128
|
+
function resolveLineAddresses(params) {
|
|
129
|
+
const fromAddress = params.isGroup
|
|
130
|
+
? params.groupId
|
|
131
|
+
? `line:group:${params.groupId}`
|
|
132
|
+
: params.roomId
|
|
133
|
+
? `line:room:${params.roomId}`
|
|
134
|
+
: `line:${params.peerId}`
|
|
135
|
+
: `line:${params.userId ?? params.peerId}`;
|
|
136
|
+
const toAddress = params.isGroup ? fromAddress : `line:${params.userId ?? params.peerId}`;
|
|
137
|
+
const originatingTo = params.isGroup ? fromAddress : `line:${params.userId ?? params.peerId}`;
|
|
138
|
+
return { fromAddress, toAddress, originatingTo };
|
|
139
|
+
}
|
|
140
|
+
async function finalizeLineInboundContext(params) {
|
|
141
|
+
const { fromAddress, toAddress, originatingTo } = resolveLineAddresses({
|
|
142
|
+
isGroup: params.source.isGroup,
|
|
143
|
+
groupId: params.source.groupId,
|
|
144
|
+
roomId: params.source.roomId,
|
|
145
|
+
userId: params.source.userId,
|
|
146
|
+
peerId: params.source.peerId,
|
|
106
147
|
});
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
peer: {
|
|
115
|
-
kind: isGroup ? "group" : "dm",
|
|
116
|
-
id: peerId,
|
|
117
|
-
},
|
|
148
|
+
const senderId = params.source.userId ?? "unknown";
|
|
149
|
+
const senderLabel = params.source.userId ? `user:${params.source.userId}` : "unknown";
|
|
150
|
+
const conversationLabel = resolveLineConversationLabel({
|
|
151
|
+
isGroup: params.source.isGroup,
|
|
152
|
+
groupId: params.source.groupId,
|
|
153
|
+
roomId: params.source.roomId,
|
|
154
|
+
senderLabel,
|
|
118
155
|
});
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
const timestamp = event.timestamp;
|
|
122
|
-
// Build message body
|
|
123
|
-
const textContent = extractMessageText(message);
|
|
124
|
-
const placeholder = extractMediaPlaceholder(message);
|
|
125
|
-
let rawBody = textContent || placeholder;
|
|
126
|
-
if (!rawBody && allMedia.length > 0) {
|
|
127
|
-
rawBody = `<media:image>${allMedia.length > 1 ? ` (${allMedia.length} images)` : ""}`;
|
|
128
|
-
}
|
|
129
|
-
if (!rawBody && allMedia.length === 0) {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
// Build sender info
|
|
133
|
-
const senderId = userId ?? "unknown";
|
|
134
|
-
const senderLabel = userId ? `user:${userId}` : "unknown";
|
|
135
|
-
// Build conversation label
|
|
136
|
-
const conversationLabel = isGroup
|
|
137
|
-
? groupId
|
|
138
|
-
? `group:${groupId}`
|
|
139
|
-
: roomId
|
|
140
|
-
? `room:${roomId}`
|
|
141
|
-
: "unknown-group"
|
|
142
|
-
: senderLabel;
|
|
143
|
-
const storePath = resolveStorePath(cfg.session?.store, {
|
|
144
|
-
agentId: route.agentId,
|
|
156
|
+
const storePath = resolveStorePath(params.cfg.session?.store, {
|
|
157
|
+
agentId: params.route.agentId,
|
|
145
158
|
});
|
|
146
|
-
const envelopeOptions = resolveEnvelopeFormatOptions(cfg);
|
|
159
|
+
const envelopeOptions = resolveEnvelopeFormatOptions(params.cfg);
|
|
147
160
|
const previousTimestamp = readSessionUpdatedAt({
|
|
148
161
|
storePath,
|
|
149
|
-
sessionKey: route.sessionKey,
|
|
162
|
+
sessionKey: params.route.sessionKey,
|
|
150
163
|
});
|
|
151
164
|
const body = formatInboundEnvelope({
|
|
152
165
|
channel: "LINE",
|
|
153
166
|
from: conversationLabel,
|
|
154
|
-
timestamp,
|
|
155
|
-
body: rawBody,
|
|
156
|
-
chatType: isGroup ? "group" : "direct",
|
|
167
|
+
timestamp: params.timestamp,
|
|
168
|
+
body: params.rawBody,
|
|
169
|
+
chatType: params.source.isGroup ? "group" : "direct",
|
|
157
170
|
sender: {
|
|
158
171
|
id: senderId,
|
|
159
172
|
},
|
|
160
173
|
previousTimestamp,
|
|
161
174
|
envelope: envelopeOptions,
|
|
162
175
|
});
|
|
163
|
-
// Build location context if applicable
|
|
164
|
-
let locationContext;
|
|
165
|
-
if (message.type === "location") {
|
|
166
|
-
const loc = message;
|
|
167
|
-
locationContext = toLocationContext({
|
|
168
|
-
latitude: loc.latitude,
|
|
169
|
-
longitude: loc.longitude,
|
|
170
|
-
name: loc.title,
|
|
171
|
-
address: loc.address,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
const fromAddress = isGroup
|
|
175
|
-
? groupId
|
|
176
|
-
? `line:group:${groupId}`
|
|
177
|
-
: roomId
|
|
178
|
-
? `line:room:${roomId}`
|
|
179
|
-
: `line:${peerId}`
|
|
180
|
-
: `line:${userId ?? peerId}`;
|
|
181
|
-
const toAddress = isGroup ? fromAddress : `line:${userId ?? peerId}`;
|
|
182
|
-
const originatingTo = isGroup ? fromAddress : `line:${userId ?? peerId}`;
|
|
183
176
|
const ctxPayload = finalizeInboundContext({
|
|
184
177
|
Body: body,
|
|
185
|
-
|
|
186
|
-
|
|
178
|
+
BodyForAgent: params.rawBody,
|
|
179
|
+
RawBody: params.rawBody,
|
|
180
|
+
CommandBody: params.rawBody,
|
|
187
181
|
From: fromAddress,
|
|
188
182
|
To: toAddress,
|
|
189
|
-
SessionKey: route.sessionKey,
|
|
190
|
-
AccountId: route.accountId,
|
|
191
|
-
ChatType: isGroup ? "group" : "direct",
|
|
183
|
+
SessionKey: params.route.sessionKey,
|
|
184
|
+
AccountId: params.route.accountId,
|
|
185
|
+
ChatType: params.source.isGroup ? "group" : "direct",
|
|
192
186
|
ConversationLabel: conversationLabel,
|
|
193
|
-
GroupSubject: isGroup
|
|
187
|
+
GroupSubject: params.source.isGroup
|
|
188
|
+
? (params.source.groupId ?? params.source.roomId)
|
|
189
|
+
: undefined,
|
|
194
190
|
SenderId: senderId,
|
|
195
191
|
Provider: "line",
|
|
196
192
|
Surface: "line",
|
|
197
|
-
MessageSid:
|
|
198
|
-
Timestamp: timestamp,
|
|
199
|
-
MediaPath:
|
|
200
|
-
MediaType:
|
|
201
|
-
MediaUrl:
|
|
202
|
-
MediaPaths:
|
|
203
|
-
MediaUrls:
|
|
204
|
-
MediaTypes:
|
|
205
|
-
|
|
206
|
-
: undefined,
|
|
207
|
-
...locationContext,
|
|
193
|
+
MessageSid: params.messageSid,
|
|
194
|
+
Timestamp: params.timestamp,
|
|
195
|
+
MediaPath: params.media.firstPath,
|
|
196
|
+
MediaType: params.media.firstContentType,
|
|
197
|
+
MediaUrl: params.media.firstPath,
|
|
198
|
+
MediaPaths: params.media.paths,
|
|
199
|
+
MediaUrls: params.media.paths,
|
|
200
|
+
MediaTypes: params.media.types,
|
|
201
|
+
...params.locationContext,
|
|
208
202
|
OriginatingChannel: "line",
|
|
209
203
|
OriginatingTo: originatingTo,
|
|
210
204
|
});
|
|
211
205
|
void recordSessionMetaFromInbound({
|
|
212
206
|
storePath,
|
|
213
|
-
sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
|
|
207
|
+
sessionKey: ctxPayload.SessionKey ?? params.route.sessionKey,
|
|
214
208
|
ctx: ctxPayload,
|
|
215
209
|
}).catch((err) => {
|
|
216
210
|
logVerbose(`line: failed updating session meta: ${String(err)}`);
|
|
217
211
|
});
|
|
218
|
-
if (!isGroup) {
|
|
212
|
+
if (!params.source.isGroup) {
|
|
219
213
|
await updateLastRoute({
|
|
220
214
|
storePath,
|
|
221
|
-
sessionKey: route.mainSessionKey,
|
|
215
|
+
sessionKey: params.route.mainSessionKey,
|
|
222
216
|
deliveryContext: {
|
|
223
217
|
channel: "line",
|
|
224
|
-
to: userId ?? peerId,
|
|
225
|
-
accountId: route.accountId,
|
|
218
|
+
to: params.source.userId ?? params.source.peerId,
|
|
219
|
+
accountId: params.route.accountId,
|
|
226
220
|
},
|
|
227
221
|
ctx: ctxPayload,
|
|
228
222
|
});
|
|
229
223
|
}
|
|
230
224
|
if (shouldLogVerbose()) {
|
|
231
225
|
const preview = body.slice(0, 200).replace(/\n/g, "\\n");
|
|
232
|
-
const mediaInfo =
|
|
233
|
-
|
|
226
|
+
const mediaInfo = params.verboseLog.kind === "inbound" && (params.verboseLog.mediaCount ?? 0) > 1
|
|
227
|
+
? ` mediaCount=${params.verboseLog.mediaCount}`
|
|
228
|
+
: "";
|
|
229
|
+
const label = params.verboseLog.kind === "inbound" ? "line inbound" : "line postback";
|
|
230
|
+
logVerbose(`${label}: from=${ctxPayload.From} len=${body.length}${mediaInfo} preview="${preview}"`);
|
|
234
231
|
}
|
|
232
|
+
return { ctxPayload, replyToken: params.event.replyToken };
|
|
233
|
+
}
|
|
234
|
+
export async function buildLineMessageContext(params) {
|
|
235
|
+
const { event, allMedia, cfg, account } = params;
|
|
236
|
+
const source = event.source;
|
|
237
|
+
const { userId, groupId, roomId, isGroup, peerId, route } = resolveLineInboundRoute({
|
|
238
|
+
source,
|
|
239
|
+
cfg,
|
|
240
|
+
account,
|
|
241
|
+
});
|
|
242
|
+
const message = event.message;
|
|
243
|
+
const messageId = message.id;
|
|
244
|
+
const timestamp = event.timestamp;
|
|
245
|
+
// Build message body
|
|
246
|
+
const textContent = extractMessageText(message);
|
|
247
|
+
const placeholder = extractMediaPlaceholder(message);
|
|
248
|
+
let rawBody = textContent || placeholder;
|
|
249
|
+
if (!rawBody && allMedia.length > 0) {
|
|
250
|
+
rawBody = `<media:image>${allMedia.length > 1 ? ` (${allMedia.length} images)` : ""}`;
|
|
251
|
+
}
|
|
252
|
+
if (!rawBody && allMedia.length === 0) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
let locationContext;
|
|
256
|
+
if (message.type === "location") {
|
|
257
|
+
const loc = message;
|
|
258
|
+
locationContext = toLocationContext({
|
|
259
|
+
latitude: loc.latitude,
|
|
260
|
+
longitude: loc.longitude,
|
|
261
|
+
name: loc.title,
|
|
262
|
+
address: loc.address,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
const { ctxPayload } = await finalizeLineInboundContext({
|
|
266
|
+
cfg,
|
|
267
|
+
account,
|
|
268
|
+
event,
|
|
269
|
+
route,
|
|
270
|
+
source: { userId, groupId, roomId, isGroup, peerId },
|
|
271
|
+
rawBody,
|
|
272
|
+
timestamp,
|
|
273
|
+
messageSid: messageId,
|
|
274
|
+
media: {
|
|
275
|
+
firstPath: allMedia[0]?.path,
|
|
276
|
+
firstContentType: allMedia[0]?.contentType,
|
|
277
|
+
paths: allMedia.length > 0 ? allMedia.map((m) => m.path) : undefined,
|
|
278
|
+
types: allMedia.length > 0
|
|
279
|
+
? allMedia.map((m) => m.contentType).filter(Boolean)
|
|
280
|
+
: undefined,
|
|
281
|
+
},
|
|
282
|
+
locationContext,
|
|
283
|
+
verboseLog: { kind: "inbound", mediaCount: allMedia.length },
|
|
284
|
+
});
|
|
235
285
|
return {
|
|
236
286
|
ctxPayload,
|
|
237
287
|
event,
|
|
@@ -246,27 +296,17 @@ export async function buildLineMessageContext(params) {
|
|
|
246
296
|
}
|
|
247
297
|
export async function buildLinePostbackContext(params) {
|
|
248
298
|
const { event, cfg, account } = params;
|
|
249
|
-
recordChannelActivity({
|
|
250
|
-
channel: "line",
|
|
251
|
-
accountId: account.accountId,
|
|
252
|
-
direction: "inbound",
|
|
253
|
-
});
|
|
254
299
|
const source = event.source;
|
|
255
|
-
const { userId, groupId, roomId, isGroup } =
|
|
256
|
-
|
|
257
|
-
const route = resolveAgentRoute({
|
|
300
|
+
const { userId, groupId, roomId, isGroup, peerId, route } = resolveLineInboundRoute({
|
|
301
|
+
source,
|
|
258
302
|
cfg,
|
|
259
|
-
|
|
260
|
-
accountId: account.accountId,
|
|
261
|
-
peer: {
|
|
262
|
-
kind: isGroup ? "group" : "dm",
|
|
263
|
-
id: peerId,
|
|
264
|
-
},
|
|
303
|
+
account,
|
|
265
304
|
});
|
|
266
305
|
const timestamp = event.timestamp;
|
|
267
306
|
const rawData = event.postback?.data?.trim() ?? "";
|
|
268
|
-
if (!rawData)
|
|
307
|
+
if (!rawData) {
|
|
269
308
|
return null;
|
|
309
|
+
}
|
|
270
310
|
let rawBody = rawData;
|
|
271
311
|
if (rawData.includes("line.action=")) {
|
|
272
312
|
const params = new URLSearchParams(rawData);
|
|
@@ -274,92 +314,24 @@ export async function buildLinePostbackContext(params) {
|
|
|
274
314
|
const device = params.get("line.device");
|
|
275
315
|
rawBody = device ? `line action ${action} device ${device}` : `line action ${action}`;
|
|
276
316
|
}
|
|
277
|
-
const
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
: senderLabel;
|
|
286
|
-
const storePath = resolveStorePath(cfg.session?.store, {
|
|
287
|
-
agentId: route.agentId,
|
|
288
|
-
});
|
|
289
|
-
const envelopeOptions = resolveEnvelopeFormatOptions(cfg);
|
|
290
|
-
const previousTimestamp = readSessionUpdatedAt({
|
|
291
|
-
storePath,
|
|
292
|
-
sessionKey: route.sessionKey,
|
|
293
|
-
});
|
|
294
|
-
const body = formatInboundEnvelope({
|
|
295
|
-
channel: "LINE",
|
|
296
|
-
from: conversationLabel,
|
|
317
|
+
const messageSid = event.replyToken ? `postback:${event.replyToken}` : `postback:${timestamp}`;
|
|
318
|
+
const { ctxPayload } = await finalizeLineInboundContext({
|
|
319
|
+
cfg,
|
|
320
|
+
account,
|
|
321
|
+
event,
|
|
322
|
+
route,
|
|
323
|
+
source: { userId, groupId, roomId, isGroup, peerId },
|
|
324
|
+
rawBody,
|
|
297
325
|
timestamp,
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
326
|
+
messageSid,
|
|
327
|
+
media: {
|
|
328
|
+
firstPath: "",
|
|
329
|
+
firstContentType: undefined,
|
|
330
|
+
paths: undefined,
|
|
331
|
+
types: undefined,
|
|
302
332
|
},
|
|
303
|
-
|
|
304
|
-
envelope: envelopeOptions,
|
|
305
|
-
});
|
|
306
|
-
const fromAddress = isGroup
|
|
307
|
-
? groupId
|
|
308
|
-
? `line:group:${groupId}`
|
|
309
|
-
: roomId
|
|
310
|
-
? `line:room:${roomId}`
|
|
311
|
-
: `line:${peerId}`
|
|
312
|
-
: `line:${userId ?? peerId}`;
|
|
313
|
-
const toAddress = isGroup ? fromAddress : `line:${userId ?? peerId}`;
|
|
314
|
-
const originatingTo = isGroup ? fromAddress : `line:${userId ?? peerId}`;
|
|
315
|
-
const ctxPayload = finalizeInboundContext({
|
|
316
|
-
Body: body,
|
|
317
|
-
RawBody: rawBody,
|
|
318
|
-
CommandBody: rawBody,
|
|
319
|
-
From: fromAddress,
|
|
320
|
-
To: toAddress,
|
|
321
|
-
SessionKey: route.sessionKey,
|
|
322
|
-
AccountId: route.accountId,
|
|
323
|
-
ChatType: isGroup ? "group" : "direct",
|
|
324
|
-
ConversationLabel: conversationLabel,
|
|
325
|
-
GroupSubject: isGroup ? (groupId ?? roomId) : undefined,
|
|
326
|
-
SenderId: senderId,
|
|
327
|
-
Provider: "line",
|
|
328
|
-
Surface: "line",
|
|
329
|
-
MessageSid: event.replyToken ? `postback:${event.replyToken}` : `postback:${timestamp}`,
|
|
330
|
-
Timestamp: timestamp,
|
|
331
|
-
MediaPath: "",
|
|
332
|
-
MediaType: undefined,
|
|
333
|
-
MediaUrl: "",
|
|
334
|
-
MediaPaths: undefined,
|
|
335
|
-
MediaUrls: undefined,
|
|
336
|
-
MediaTypes: undefined,
|
|
337
|
-
OriginatingChannel: "line",
|
|
338
|
-
OriginatingTo: originatingTo,
|
|
333
|
+
verboseLog: { kind: "postback" },
|
|
339
334
|
});
|
|
340
|
-
void recordSessionMetaFromInbound({
|
|
341
|
-
storePath,
|
|
342
|
-
sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
|
|
343
|
-
ctx: ctxPayload,
|
|
344
|
-
}).catch((err) => {
|
|
345
|
-
logVerbose(`line: failed updating session meta: ${String(err)}`);
|
|
346
|
-
});
|
|
347
|
-
if (!isGroup) {
|
|
348
|
-
await updateLastRoute({
|
|
349
|
-
storePath,
|
|
350
|
-
sessionKey: route.mainSessionKey,
|
|
351
|
-
deliveryContext: {
|
|
352
|
-
channel: "line",
|
|
353
|
-
to: userId ?? peerId,
|
|
354
|
-
accountId: route.accountId,
|
|
355
|
-
},
|
|
356
|
-
ctx: ctxPayload,
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
if (shouldLogVerbose()) {
|
|
360
|
-
const preview = body.slice(0, 200).replace(/\n/g, "\\n");
|
|
361
|
-
logVerbose(`line postback: from=${ctxPayload.From} len=${body.length} preview="${preview}"`);
|
|
362
|
-
}
|
|
363
335
|
return {
|
|
364
336
|
ctxPayload,
|
|
365
337
|
event,
|
|
@@ -1,31 +1,35 @@
|
|
|
1
|
+
import { inspect } from "node:util";
|
|
1
2
|
import { Chalk } from "chalk";
|
|
2
3
|
import { CHAT_CHANNEL_ORDER } from "../channels/registry.js";
|
|
4
|
+
import { isVerbose } from "../globals.js";
|
|
3
5
|
import { defaultRuntime } from "../runtime.js";
|
|
6
|
+
import { clearActiveProgressLine } from "../terminal/progress-line.js";
|
|
4
7
|
import { getConsoleSettings, shouldLogSubsystemToConsole } from "./console.js";
|
|
5
|
-
import { isVerbose } from "../globals.js";
|
|
6
8
|
import { levelToMinLevel } from "./levels.js";
|
|
7
|
-
import { getChildLogger } from "./logger.js";
|
|
9
|
+
import { getChildLogger, isFileLogLevelEnabled } from "./logger.js";
|
|
8
10
|
import { loggingState } from "./state.js";
|
|
9
|
-
import { clearActiveProgressLine } from "../terminal/progress-line.js";
|
|
10
11
|
function shouldLogToConsole(level, settings) {
|
|
11
|
-
if (settings.level === "silent")
|
|
12
|
+
if (settings.level === "silent") {
|
|
12
13
|
return false;
|
|
14
|
+
}
|
|
13
15
|
const current = levelToMinLevel(level);
|
|
14
16
|
const min = levelToMinLevel(settings.level);
|
|
15
17
|
return current <= min;
|
|
16
18
|
}
|
|
17
19
|
function isRichConsoleEnv() {
|
|
18
20
|
const term = (process.env.TERM ?? "").toLowerCase();
|
|
19
|
-
if (process.env.COLORTERM || process.env.TERM_PROGRAM)
|
|
21
|
+
if (process.env.COLORTERM || process.env.TERM_PROGRAM) {
|
|
20
22
|
return true;
|
|
23
|
+
}
|
|
21
24
|
return term.length > 0 && term !== "dumb";
|
|
22
25
|
}
|
|
23
26
|
function getColorForConsole() {
|
|
24
27
|
const hasForceColor = typeof process.env.FORCE_COLOR === "string" &&
|
|
25
28
|
process.env.FORCE_COLOR.trim().length > 0 &&
|
|
26
29
|
process.env.FORCE_COLOR.trim() !== "0";
|
|
27
|
-
if (process.env.NO_COLOR && !hasForceColor)
|
|
30
|
+
if (process.env.NO_COLOR && !hasForceColor) {
|
|
28
31
|
return new Chalk({ level: 0 });
|
|
32
|
+
}
|
|
29
33
|
const hasTty = Boolean(process.stdout.isTTY || process.stderr.isTTY);
|
|
30
34
|
return hasTty || isRichConsoleEnv() ? new Chalk({ level: 1 }) : new Chalk({ level: 0 });
|
|
31
35
|
}
|
|
@@ -38,8 +42,9 @@ const SUBSYSTEM_MAX_SEGMENTS = 2;
|
|
|
38
42
|
const CHANNEL_SUBSYSTEM_PREFIXES = new Set(CHAT_CHANNEL_ORDER);
|
|
39
43
|
function pickSubsystemColor(color, subsystem) {
|
|
40
44
|
const override = SUBSYSTEM_COLOR_OVERRIDES[subsystem];
|
|
41
|
-
if (override)
|
|
45
|
+
if (override) {
|
|
42
46
|
return color[override];
|
|
47
|
+
}
|
|
43
48
|
let hash = 0;
|
|
44
49
|
for (let i = 0; i < subsystem.length; i += 1) {
|
|
45
50
|
hash = (hash * 31 + subsystem.charCodeAt(i)) | 0;
|
|
@@ -55,8 +60,9 @@ function formatSubsystemForConsole(subsystem) {
|
|
|
55
60
|
SUBSYSTEM_PREFIXES_TO_DROP.includes(parts[0])) {
|
|
56
61
|
parts.shift();
|
|
57
62
|
}
|
|
58
|
-
if (parts.length === 0)
|
|
63
|
+
if (parts.length === 0) {
|
|
59
64
|
return original;
|
|
65
|
+
}
|
|
60
66
|
if (CHANNEL_SUBSYSTEM_PREFIXES.has(parts[0])) {
|
|
61
67
|
return parts[0];
|
|
62
68
|
}
|
|
@@ -66,8 +72,9 @@ function formatSubsystemForConsole(subsystem) {
|
|
|
66
72
|
return parts.join("/");
|
|
67
73
|
}
|
|
68
74
|
export function stripRedundantSubsystemPrefixForConsole(message, displaySubsystem) {
|
|
69
|
-
if (!displaySubsystem)
|
|
75
|
+
if (!displaySubsystem) {
|
|
70
76
|
return message;
|
|
77
|
+
}
|
|
71
78
|
// Common duplication: "[discord] discord: ..." (when a message manually includes the subsystem tag).
|
|
72
79
|
if (message.startsWith("[")) {
|
|
73
80
|
const closeIdx = message.indexOf("]");
|
|
@@ -75,25 +82,31 @@ export function stripRedundantSubsystemPrefixForConsole(message, displaySubsyste
|
|
|
75
82
|
const bracketTag = message.slice(1, closeIdx);
|
|
76
83
|
if (bracketTag.toLowerCase() === displaySubsystem.toLowerCase()) {
|
|
77
84
|
let i = closeIdx + 1;
|
|
78
|
-
while (message[i] === " ")
|
|
85
|
+
while (message[i] === " ") {
|
|
79
86
|
i += 1;
|
|
87
|
+
}
|
|
80
88
|
return message.slice(i);
|
|
81
89
|
}
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
92
|
const prefix = message.slice(0, displaySubsystem.length);
|
|
85
|
-
if (prefix.toLowerCase() !== displaySubsystem.toLowerCase())
|
|
93
|
+
if (prefix.toLowerCase() !== displaySubsystem.toLowerCase()) {
|
|
86
94
|
return message;
|
|
95
|
+
}
|
|
87
96
|
const next = message.slice(displaySubsystem.length, displaySubsystem.length + 1);
|
|
88
|
-
if (next !== ":" && next !== " ")
|
|
97
|
+
if (next !== ":" && next !== " ") {
|
|
89
98
|
return message;
|
|
99
|
+
}
|
|
90
100
|
let i = displaySubsystem.length;
|
|
91
|
-
while (message[i] === " ")
|
|
101
|
+
while (message[i] === " ") {
|
|
92
102
|
i += 1;
|
|
93
|
-
|
|
103
|
+
}
|
|
104
|
+
if (message[i] === ":") {
|
|
94
105
|
i += 1;
|
|
95
|
-
|
|
106
|
+
}
|
|
107
|
+
while (message[i] === " ") {
|
|
96
108
|
i += 1;
|
|
109
|
+
}
|
|
97
110
|
return message.slice(i);
|
|
98
111
|
}
|
|
99
112
|
function formatConsoleLine(opts) {
|
|
@@ -148,12 +161,14 @@ function writeConsoleLine(level, line) {
|
|
|
148
161
|
}
|
|
149
162
|
}
|
|
150
163
|
function logToFile(fileLogger, level, message, meta) {
|
|
151
|
-
if (level === "silent")
|
|
164
|
+
if (level === "silent") {
|
|
152
165
|
return;
|
|
166
|
+
}
|
|
153
167
|
const safeLevel = level;
|
|
154
168
|
const method = fileLogger[safeLevel];
|
|
155
|
-
if (typeof method !== "function")
|
|
169
|
+
if (typeof method !== "function") {
|
|
156
170
|
return;
|
|
171
|
+
}
|
|
157
172
|
if (meta && Object.keys(meta).length > 0) {
|
|
158
173
|
method.call(fileLogger, meta, message);
|
|
159
174
|
}
|
|
@@ -164,8 +179,9 @@ function logToFile(fileLogger, level, message, meta) {
|
|
|
164
179
|
export function createSubsystemLogger(subsystem) {
|
|
165
180
|
let fileLogger = null;
|
|
166
181
|
const getFileLogger = () => {
|
|
167
|
-
if (!fileLogger)
|
|
182
|
+
if (!fileLogger) {
|
|
168
183
|
fileLogger = getChildLogger({ subsystem });
|
|
184
|
+
}
|
|
169
185
|
return fileLogger;
|
|
170
186
|
};
|
|
171
187
|
const emit = (level, message, meta) => {
|
|
@@ -180,10 +196,12 @@ export function createSubsystemLogger(subsystem) {
|
|
|
180
196
|
fileMeta = Object.keys(rest).length > 0 ? rest : undefined;
|
|
181
197
|
}
|
|
182
198
|
logToFile(getFileLogger(), level, message, fileMeta);
|
|
183
|
-
if (!shouldLogToConsole(level, { level: consoleSettings.level }))
|
|
199
|
+
if (!shouldLogToConsole(level, { level: consoleSettings.level })) {
|
|
184
200
|
return;
|
|
185
|
-
|
|
201
|
+
}
|
|
202
|
+
if (!shouldLogSubsystemToConsole(subsystem)) {
|
|
186
203
|
return;
|
|
204
|
+
}
|
|
187
205
|
const consoleMessage = consoleMessageOverride ?? message;
|
|
188
206
|
if (!isVerbose() &&
|
|
189
207
|
subsystem === "agent/embedded" &&
|
|
@@ -199,8 +217,23 @@ export function createSubsystemLogger(subsystem) {
|
|
|
199
217
|
});
|
|
200
218
|
writeConsoleLine(level, line);
|
|
201
219
|
};
|
|
220
|
+
const isConsoleEnabled = (level) => {
|
|
221
|
+
const consoleSettings = getConsoleSettings();
|
|
222
|
+
return (shouldLogToConsole(level, { level: consoleSettings.level }) &&
|
|
223
|
+
shouldLogSubsystemToConsole(subsystem));
|
|
224
|
+
};
|
|
225
|
+
const isFileEnabled = (level) => isFileLogLevelEnabled(level);
|
|
202
226
|
const logger = {
|
|
203
227
|
subsystem,
|
|
228
|
+
isEnabled: (level, target = "any") => {
|
|
229
|
+
if (target === "console") {
|
|
230
|
+
return isConsoleEnabled(level);
|
|
231
|
+
}
|
|
232
|
+
if (target === "file") {
|
|
233
|
+
return isFileEnabled(level);
|
|
234
|
+
}
|
|
235
|
+
return isConsoleEnabled(level) || isFileEnabled(level);
|
|
236
|
+
},
|
|
204
237
|
trace: (message, meta) => emit("trace", message, meta),
|
|
205
238
|
debug: (message, meta) => emit("debug", message, meta),
|
|
206
239
|
info: (message, meta) => emit("info", message, meta),
|
|
@@ -223,9 +256,13 @@ export function createSubsystemLogger(subsystem) {
|
|
|
223
256
|
return logger;
|
|
224
257
|
}
|
|
225
258
|
export function runtimeForLogger(logger, exit = defaultRuntime.exit) {
|
|
259
|
+
const formatArgs = (...args) => args
|
|
260
|
+
.map((arg) => (typeof arg === "string" ? arg : inspect(arg)))
|
|
261
|
+
.join(" ")
|
|
262
|
+
.trim();
|
|
226
263
|
return {
|
|
227
|
-
log: (
|
|
228
|
-
error: (
|
|
264
|
+
log: (...args) => logger.info(formatArgs(...args)),
|
|
265
|
+
error: (...args) => logger.error(formatArgs(...args)),
|
|
229
266
|
exit,
|
|
230
267
|
};
|
|
231
268
|
}
|