@mininglamp-oss/octo-runtime 1.1.6 → 1.1.7
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/apps/cli/dist/build-info.json +2 -2
- package/dist/public/dsh.d.ts +1 -1
- package/dist/public/dsh.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +17 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/dist/index.d.ts +20 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/index.d.ts +32 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/index.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.d.ts +16 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.d.ts +32 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-IW62UM3C.js → chunk-CFKMMCO6.js} +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-FWAPYRV2.js → chunk-LO34KB7D.js} +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-3GXX5VD5.js → chunk-V5W6ZTYC.js} +14 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +4 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +17 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +8 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/index.d.ts +10 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/compatibility.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/compatibility.js +12 -40
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.d.ts +22 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +422 -135
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +6 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +18 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +7 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.d.ts +20 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -24
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/runner.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/runner.js +102 -52
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.js +8 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-input.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-input.js +9 -6
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +8 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/context-gap.d.ts +17 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/context-gap.js +22 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/history-context.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/history-context.js +27 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +444 -226
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/rules-context.d.ts +5 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/rules-context.js +42 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/stable-context.d.ts +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/stable-context.js +28 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +16 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.d.ts +4 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.js +12 -9
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js +7 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/identity.d.ts +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/identity.js +36 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/scheduler.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/scheduler.js +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.d.ts +5 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +36 -22
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/extra.js +14 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/lifecycle/configuration.js +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/presentation/run-projector.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/presentation/run-projector.js +265 -38
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js +19 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/errors.d.ts +0 -12
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/errors.js +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.js +8 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/messages.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/messages.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/card-session.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/card-session.js +27 -15
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +17 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +217 -50
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.js +2 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connector.d.ts +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connector.js +41 -12
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/contexts.d.ts +2 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/contexts.js +53 -82
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/history-content.d.ts +12 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/history-content.js +133 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/history-messages.d.ts +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/history-messages.js +76 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/mentions.d.ts +0 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/mentions.js +0 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-identities.d.ts +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-identities.js +74 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-time.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-time.js +19 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-trigger.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-trigger.js +90 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/reasoning-frame.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/retry-after.d.ts +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/retry-after.js +60 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +20 -8
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +10 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/extra.js +14 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/transport/channel.js +2 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/context-loader.d.ts +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/context-loader.js +11 -4
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.js +8 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.d.ts +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.js +14 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/node_modules/iconv-lite/LICENSE +21 -0
- package/node_modules/iconv-lite/README.md +138 -0
- package/node_modules/iconv-lite/encodings/dbcs-codec.js +532 -0
- package/node_modules/iconv-lite/encodings/dbcs-data.js +185 -0
- package/node_modules/iconv-lite/encodings/index.js +23 -0
- package/node_modules/iconv-lite/encodings/internal.js +218 -0
- package/node_modules/iconv-lite/encodings/sbcs-codec.js +75 -0
- package/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
- package/node_modules/iconv-lite/encodings/sbcs-data.js +180 -0
- package/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
- package/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
- package/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
- package/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
- package/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
- package/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
- package/node_modules/iconv-lite/encodings/tables/gbk-added.json +56 -0
- package/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
- package/node_modules/iconv-lite/encodings/utf16.js +187 -0
- package/node_modules/iconv-lite/encodings/utf32.js +314 -0
- package/node_modules/iconv-lite/encodings/utf7.js +283 -0
- package/node_modules/iconv-lite/lib/bom-handling.js +48 -0
- package/node_modules/iconv-lite/lib/helpers/merge-exports.js +13 -0
- package/node_modules/iconv-lite/lib/index.d.ts +129 -0
- package/node_modules/iconv-lite/lib/index.js +182 -0
- package/node_modules/iconv-lite/lib/streams.js +105 -0
- package/node_modules/iconv-lite/package.json +70 -0
- package/node_modules/iconv-lite/types/encodings.d.ts +425 -0
- package/node_modules/safer-buffer/LICENSE +21 -0
- package/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/node_modules/safer-buffer/Readme.md +156 -0
- package/node_modules/safer-buffer/dangerous.js +58 -0
- package/node_modules/safer-buffer/package.json +34 -0
- package/node_modules/safer-buffer/safer.js +77 -0
- package/node_modules/safer-buffer/tests.js +406 -0
- package/node_modules/semver/LICENSE +15 -0
- package/node_modules/semver/README.md +680 -0
- package/node_modules/semver/bin/semver.js +195 -0
- package/node_modules/semver/classes/comparator.js +143 -0
- package/node_modules/semver/classes/index.js +7 -0
- package/node_modules/semver/classes/range.js +577 -0
- package/node_modules/semver/classes/semver.js +350 -0
- package/node_modules/semver/functions/clean.js +8 -0
- package/node_modules/semver/functions/cmp.js +54 -0
- package/node_modules/semver/functions/coerce.js +62 -0
- package/node_modules/semver/functions/compare-build.js +9 -0
- package/node_modules/semver/functions/compare-loose.js +5 -0
- package/node_modules/semver/functions/compare.js +7 -0
- package/node_modules/semver/functions/diff.js +60 -0
- package/node_modules/semver/functions/eq.js +5 -0
- package/node_modules/semver/functions/gt.js +5 -0
- package/node_modules/semver/functions/gte.js +5 -0
- package/node_modules/semver/functions/inc.js +21 -0
- package/node_modules/semver/functions/lt.js +5 -0
- package/node_modules/semver/functions/lte.js +5 -0
- package/node_modules/semver/functions/major.js +5 -0
- package/node_modules/semver/functions/minor.js +5 -0
- package/node_modules/semver/functions/neq.js +5 -0
- package/node_modules/semver/functions/parse.js +18 -0
- package/node_modules/semver/functions/patch.js +5 -0
- package/node_modules/semver/functions/prerelease.js +8 -0
- package/node_modules/semver/functions/rcompare.js +5 -0
- package/node_modules/semver/functions/rsort.js +5 -0
- package/node_modules/semver/functions/satisfies.js +12 -0
- package/node_modules/semver/functions/sort.js +5 -0
- package/node_modules/semver/functions/truncate.js +48 -0
- package/node_modules/semver/functions/valid.js +8 -0
- package/node_modules/semver/index.js +93 -0
- package/node_modules/semver/internal/constants.js +37 -0
- package/node_modules/semver/internal/debug.js +11 -0
- package/node_modules/semver/internal/identifiers.js +29 -0
- package/node_modules/semver/internal/lrucache.js +42 -0
- package/node_modules/semver/internal/parse-options.js +17 -0
- package/node_modules/semver/internal/re.js +223 -0
- package/node_modules/semver/package.json +78 -0
- package/node_modules/semver/preload.js +4 -0
- package/node_modules/semver/range.bnf +17 -0
- package/node_modules/semver/ranges/gtr.js +6 -0
- package/node_modules/semver/ranges/intersects.js +9 -0
- package/node_modules/semver/ranges/ltr.js +6 -0
- package/node_modules/semver/ranges/max-satisfying.js +27 -0
- package/node_modules/semver/ranges/min-satisfying.js +26 -0
- package/node_modules/semver/ranges/min-version.js +63 -0
- package/node_modules/semver/ranges/outside.js +82 -0
- package/node_modules/semver/ranges/simplify.js +49 -0
- package/node_modules/semver/ranges/subset.js +249 -0
- package/node_modules/semver/ranges/to-comparators.js +10 -0
- package/node_modules/semver/ranges/valid.js +13 -0
- package/package.json +33 -27
- package/packages/octo-runtime-extra-channel-gateway/config-schema.json +8 -1
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +43 -1
|
@@ -4,7 +4,7 @@ import { shutdownDeadline, withinShutdown } from "@mininglamp-oss/octo-runtime-h
|
|
|
4
4
|
* 管理会话、排队、取消和交互归属;平台协议交给 connector,领域业务交给发起方。
|
|
5
5
|
*/
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
|
-
import { assertModelInputParts, failurePayload, failureMessage } from "@mininglamp-oss/octo-runtime-protocol";
|
|
7
|
+
import { assertModelInputParts, assertSessionName, failurePayload, failureMessage } from "@mininglamp-oss/octo-runtime-protocol";
|
|
8
8
|
import { ImImageInputError } from "../transport/image-input.js";
|
|
9
9
|
import { performance } from "node:perf_hooks";
|
|
10
10
|
import { imBotIdentity, validateImConfig } from "../lifecycle/configuration.js";
|
|
@@ -12,14 +12,49 @@ import { GatewayTransport } from "../transport/channel.js";
|
|
|
12
12
|
import { createImInvocation } from "../execution/dispatcher.js";
|
|
13
13
|
import { ImTask } from "../execution/task.js";
|
|
14
14
|
import { MODEL_WAIT_TIMEOUT_MESSAGE } from "../execution/model-wait.js";
|
|
15
|
+
import { ImDeliveryIdentity } from "../delivery/identity.js";
|
|
15
16
|
import { ImDeliveryDispatcher } from "../delivery/dispatcher.js";
|
|
16
17
|
import { ImRunProjector } from "../presentation/run-projector.js";
|
|
17
18
|
import { deliveryNotice } from "../presentation/delivery-notice.js";
|
|
18
19
|
import { MemoryImSessionStore } from "./session-store.js";
|
|
19
20
|
import { addRulesRecovery, selectRulesContext } from "./rules-context.js";
|
|
21
|
+
import { planStableContext } from "./stable-context.js";
|
|
20
22
|
import { groupScope } from "../transport/normalize.js";
|
|
21
23
|
import { connectionFailure, ImConnectionError } from "../transport/connection-error.js";
|
|
22
24
|
import { commitHistoryGap, gapMetadata, planHistoryGap, validMessageSeq } from "./context-gap.js";
|
|
25
|
+
function readableSessionName(message, current) {
|
|
26
|
+
if (current !== undefined) {
|
|
27
|
+
try {
|
|
28
|
+
assertSessionName(current);
|
|
29
|
+
return current;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// 修复旧版本已保存的非法展示名称,不触碰业务身份和原生恢复句柄。
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// 每个地址片段最多 80 个码点,最长群话题名称(含 UUID)不超过 215 个码点。
|
|
36
|
+
const displayPart = (value) => [...value]
|
|
37
|
+
.slice(0, 80)
|
|
38
|
+
.map((character) => {
|
|
39
|
+
const code = character.charCodeAt(0);
|
|
40
|
+
return code < 32 || (code >= 127 && code <= 159) ? "-" : character;
|
|
41
|
+
})
|
|
42
|
+
.join("") || "unknown";
|
|
43
|
+
const suffix = randomUUID();
|
|
44
|
+
const scope = groupScope(message.conversationId);
|
|
45
|
+
const name = message.conversationKind === "direct"
|
|
46
|
+
? `octo-dm-${displayPart(message.conversationId)}-${suffix}`
|
|
47
|
+
: message.conversationKind === "thread"
|
|
48
|
+
? `octo-group-${displayPart(scope.groupNo)}-topic-${displayPart(scope.shortId ?? message.conversationId)}-${suffix}`
|
|
49
|
+
: `octo-group-${displayPart(message.conversationId)}-${suffix}`;
|
|
50
|
+
assertSessionName(name);
|
|
51
|
+
return name;
|
|
52
|
+
}
|
|
53
|
+
// 仅精确匹配已定义的准备期原因;未知异常正文不得进入回复或新增诊断。
|
|
54
|
+
const preparationFailureMessages = new Map([
|
|
55
|
+
["IM_AGENT_WORKDIR_FIXED", "本轮工作目录与固定目录配置冲突,尚未发起执行。请检查工作目录配置。"],
|
|
56
|
+
["IM_RULE_PROTOCOL_INVALID", "规则数据格式不符合协议,尚未发起执行。请检查规则服务返回格式。"]
|
|
57
|
+
]);
|
|
23
58
|
export class ImRuntime {
|
|
24
59
|
dependencies;
|
|
25
60
|
#processEpoch = randomUUID();
|
|
@@ -28,6 +63,10 @@ export class ImRuntime {
|
|
|
28
63
|
config;
|
|
29
64
|
#connector;
|
|
30
65
|
#delivery;
|
|
66
|
+
#cardDelivery;
|
|
67
|
+
#deliveryIdentity;
|
|
68
|
+
// 宿主凭据来源是黑盒;沿原初始化/建联入口保存值,REST 不重新获取或等待 WS 核验。
|
|
69
|
+
#restToken;
|
|
31
70
|
#sessions = new Map();
|
|
32
71
|
#sessionStore;
|
|
33
72
|
#seen = new Map();
|
|
@@ -53,6 +92,8 @@ export class ImRuntime {
|
|
|
53
92
|
#failureNotifications = new Map();
|
|
54
93
|
#busyNotifiedAt = new Map();
|
|
55
94
|
#retry = 0;
|
|
95
|
+
#backoff = 0;
|
|
96
|
+
#fastRetriesRemaining = 0;
|
|
56
97
|
#disconnecting;
|
|
57
98
|
constructor(config, dependencies) {
|
|
58
99
|
this.dependencies = dependencies;
|
|
@@ -112,8 +153,14 @@ export class ImRuntime {
|
|
|
112
153
|
};
|
|
113
154
|
this.dependencies.signal?.addEventListener("abort", this.#ownerStopped, { once: true });
|
|
114
155
|
this.#delivery = new ImDeliveryDispatcher(this.#signal);
|
|
156
|
+
// 卡片/文件回执归 Bot,跨 WS 恢复复用同一有界缓存;与文本回执分开统计。
|
|
157
|
+
this.#cardDelivery = new ImDeliveryDispatcher(this.#signal);
|
|
158
|
+
this.#deliveryIdentity = new ImDeliveryIdentity();
|
|
159
|
+
this.#restToken = undefined;
|
|
115
160
|
}
|
|
116
161
|
this.#retry = 0;
|
|
162
|
+
this.#backoff = 0;
|
|
163
|
+
this.#fastRetriesRemaining = 0;
|
|
117
164
|
this.#error = undefined;
|
|
118
165
|
this.#state = "connecting";
|
|
119
166
|
this.#connecting = this.#connect(false);
|
|
@@ -130,6 +177,7 @@ export class ImRuntime {
|
|
|
130
177
|
this.#log(recovering ? "channel.retry_started" : "channel.connecting", {
|
|
131
178
|
attempt: this.#retry
|
|
132
179
|
});
|
|
180
|
+
// 只回收单次 WS;Bot 持有的 REST 凭据及任务展示不随连接清理暂停。
|
|
133
181
|
this.#connectionAbort?.abort();
|
|
134
182
|
try {
|
|
135
183
|
await this.#disconnecting;
|
|
@@ -148,7 +196,14 @@ export class ImRuntime {
|
|
|
148
196
|
const signal = AbortSignal.any([this.#signal, this.#connectionAbort.signal]);
|
|
149
197
|
let starting = true;
|
|
150
198
|
let disconnected;
|
|
151
|
-
const credentials =
|
|
199
|
+
const credentials = async (config, signal) => {
|
|
200
|
+
const token = await (this.dependencies.credentials
|
|
201
|
+
? this.dependencies.credentials(config, signal)
|
|
202
|
+
: Promise.resolve(config.bf_token));
|
|
203
|
+
signal.throwIfAborted();
|
|
204
|
+
this.#restToken = token?.trim();
|
|
205
|
+
return token;
|
|
206
|
+
};
|
|
152
207
|
const connector = new GatewayTransport(this.config, credentials, {
|
|
153
208
|
authorizeSpace: this.dependencies.authorizeSpace,
|
|
154
209
|
onPosition: (position) => {
|
|
@@ -177,6 +232,13 @@ export class ImRuntime {
|
|
|
177
232
|
if (!starting)
|
|
178
233
|
this.#lostConnection(connector, disconnected);
|
|
179
234
|
}
|
|
235
|
+
}, {
|
|
236
|
+
signal: this.#signal,
|
|
237
|
+
dispatcher: this.#cardDelivery,
|
|
238
|
+
identity: this.#deliveryIdentity,
|
|
239
|
+
token: () => this.#restToken,
|
|
240
|
+
// 只供旧任务选择本 Bot 当前连接;生命周期停止后旧 signal 不会随新 start 复活。
|
|
241
|
+
current: () => this.#connector
|
|
180
242
|
});
|
|
181
243
|
this.#connector = connector;
|
|
182
244
|
try {
|
|
@@ -192,12 +254,15 @@ export class ImRuntime {
|
|
|
192
254
|
this.#log("channel.connected", { state: "online" });
|
|
193
255
|
this.#error = undefined;
|
|
194
256
|
this.#retry = 0;
|
|
257
|
+
this.#backoff = 0;
|
|
258
|
+
this.#fastRetriesRemaining = 0;
|
|
195
259
|
}
|
|
196
260
|
catch (error) {
|
|
197
261
|
if (signal.aborted)
|
|
198
262
|
return;
|
|
199
263
|
starting = false;
|
|
200
264
|
const failure = connectionFailure(error);
|
|
265
|
+
// 注册/WS 握手失败只影响连接恢复,不撤销 Bot 已持有的 REST 凭据。
|
|
201
266
|
this.#connectionAbort.abort();
|
|
202
267
|
this.#error = failure.message;
|
|
203
268
|
// 首次离线与后续断线共用恢复;服务端断开不等于永久拒绝,由传输分类决定资格。
|
|
@@ -223,26 +288,37 @@ export class ImRuntime {
|
|
|
223
288
|
this.#state = retry ? "retrying" : "failed";
|
|
224
289
|
this.#log("channel.disconnected", { state: this.#state, code: failure.message });
|
|
225
290
|
this.#connectionAbort?.abort();
|
|
226
|
-
//
|
|
291
|
+
// 确认断线即退出 online;立即重连后追加最多十次 1 秒重试,覆盖换网恢复间隙。
|
|
292
|
+
// 关闭和旧回调不能再创建连接,回收失败须单独诊断,不能以加速为由重叠连接。
|
|
227
293
|
this.#disconnecting = connector.close();
|
|
228
294
|
void this.#disconnecting.then(() => {
|
|
229
|
-
if (retry)
|
|
230
|
-
this.#
|
|
295
|
+
if (retry) {
|
|
296
|
+
this.#fastRetriesRemaining = 10;
|
|
297
|
+
this.#scheduleReconnect(failure.retryAfterMs, true);
|
|
298
|
+
}
|
|
231
299
|
}, () => {
|
|
232
300
|
if (!this.#closed)
|
|
233
301
|
this.#state = "failed";
|
|
234
302
|
this.#diagnostic("IM_DISPOSE_FAILED");
|
|
235
303
|
});
|
|
236
304
|
}
|
|
237
|
-
#scheduleReconnect(retryAfterMs = 0) {
|
|
305
|
+
#scheduleReconnect(retryAfterMs = 0, immediate = false) {
|
|
238
306
|
if (this.#closed ||
|
|
239
307
|
this.#draining ||
|
|
240
308
|
this.#signal.aborted ||
|
|
241
309
|
this.#state !== "retrying" ||
|
|
242
310
|
this.#reconnect)
|
|
243
311
|
return;
|
|
244
|
-
|
|
312
|
+
// 快速重试仅用于上线后的断线恢复,不消耗常规退避档位;Retry-After 仍优先。
|
|
313
|
+
// 每次失败回收完成才安排下一次,慢握手或休眠恢复不会堆积并发连接。
|
|
314
|
+
const fast = !immediate && this.#fastRetriesRemaining > 0;
|
|
315
|
+
const baseDelayMs = immediate ? 0 : fast ? 1_000 : [5_000, 10_000, 15_000][this.#backoff];
|
|
316
|
+
const delayMs = Math.max(baseDelayMs, retryAfterMs);
|
|
245
317
|
this.#retry = Math.min(Number.MAX_SAFE_INTEGER, this.#retry + 1);
|
|
318
|
+
if (fast)
|
|
319
|
+
this.#fastRetriesRemaining--;
|
|
320
|
+
else if (!immediate)
|
|
321
|
+
this.#backoff = Math.min(2, this.#backoff + 1);
|
|
246
322
|
this.#log("channel.retry_scheduled", {
|
|
247
323
|
state: "retrying",
|
|
248
324
|
delay_ms: delayMs,
|
|
@@ -330,6 +406,24 @@ export class ImRuntime {
|
|
|
330
406
|
next.localOutputSeqs = [...new Set([...next.localOutputSeqs, position.messageSeq])]
|
|
331
407
|
.sort((left, right) => left - right)
|
|
332
408
|
.slice(-32);
|
|
409
|
+
const providerSessionId = position.turn?.providerSessionId;
|
|
410
|
+
if (position.own &&
|
|
411
|
+
position.outputFingerprint &&
|
|
412
|
+
providerSessionId &&
|
|
413
|
+
binding.providerSession?.sessionId === providerSessionId) {
|
|
414
|
+
const previous = next.assistantOutputs?.providerSessionId === providerSessionId
|
|
415
|
+
? next.assistantOutputs.messages
|
|
416
|
+
: [];
|
|
417
|
+
next.assistantOutputs = {
|
|
418
|
+
providerSessionId,
|
|
419
|
+
messages: [
|
|
420
|
+
...previous.filter((entry) => entry.seq !== position.messageSeq),
|
|
421
|
+
{ seq: position.messageSeq, fingerprint: position.outputFingerprint }
|
|
422
|
+
]
|
|
423
|
+
.sort((left, right) => left.seq - right.seq)
|
|
424
|
+
.slice(-32)
|
|
425
|
+
};
|
|
426
|
+
}
|
|
333
427
|
return next;
|
|
334
428
|
});
|
|
335
429
|
}
|
|
@@ -418,9 +512,11 @@ export class ImRuntime {
|
|
|
418
512
|
this.#finalDeliveries.get(key)?.abort();
|
|
419
513
|
this.#tasks.get(key)?.task.stopRetries();
|
|
420
514
|
session.id = binding.id;
|
|
515
|
+
session.sessionName = binding.sessionName;
|
|
421
516
|
session.generation = binding.generation;
|
|
422
517
|
session.providerSession = binding.providerSession;
|
|
423
518
|
session.initialization = { attempted: false };
|
|
519
|
+
session.stableContext = { turnCount: 0, refreshPending: true };
|
|
424
520
|
session.lastRunId = undefined;
|
|
425
521
|
void this.#reply(message, "会话已经重置", `control:${message.messageId}`, true).catch(() => {
|
|
426
522
|
this.#seen.delete(dedupe);
|
|
@@ -473,6 +569,7 @@ export class ImRuntime {
|
|
|
473
569
|
generation: 1,
|
|
474
570
|
...binding,
|
|
475
571
|
initialization: { attempted: binding?.initialContextPrepared === true },
|
|
572
|
+
stableContext: binding?.stableContext ?? { turnCount: 0, refreshPending: true },
|
|
476
573
|
pending: 0,
|
|
477
574
|
tail: Promise.resolve()
|
|
478
575
|
};
|
|
@@ -498,8 +595,6 @@ export class ImRuntime {
|
|
|
498
595
|
retry: (senderId, id) => {
|
|
499
596
|
if (!controls.failed)
|
|
500
597
|
return false;
|
|
501
|
-
if (!message.position)
|
|
502
|
-
return this.#enqueue({ ...message, senderId }, key, id);
|
|
503
598
|
const saved = this.#sessionStore.occurrence(key, message.messageId)?.snapshot;
|
|
504
599
|
if (!saved)
|
|
505
600
|
return false;
|
|
@@ -511,6 +606,8 @@ export class ImRuntime {
|
|
|
511
606
|
...message,
|
|
512
607
|
senderId,
|
|
513
608
|
historyRetry: true,
|
|
609
|
+
frozenArtifacts: this.#sessionStore.occurrence(key, message.messageId)?.artifacts,
|
|
610
|
+
runMetadata: saved.runMetadata,
|
|
514
611
|
buildContext: () => Promise.resolve(structuredClone(saved.contexts)),
|
|
515
612
|
...(images.length
|
|
516
613
|
? { buildInputs: () => Promise.resolve(structuredClone(images)) }
|
|
@@ -541,9 +638,10 @@ export class ImRuntime {
|
|
|
541
638
|
// Octospec F26: .octospec/tasks/gateway-august-feature-assessment/assessment.md
|
|
542
639
|
// 每个非空 session 占一个工作槽位;结束清理后原子交给同 session 的下一条。
|
|
543
640
|
// 排队另计四条,不把 Bot 的工作数与所有排队消息混加。
|
|
641
|
+
// 只有空闲 session 需要申请新槽;Bot 满载不阻止已有工作 session 排队。
|
|
544
642
|
const full = session.pending >= 5
|
|
545
643
|
? "IM_SESSION_QUEUE_FULL"
|
|
546
|
-
: this.#working >= 64
|
|
644
|
+
: session.pending === 0 && this.#working >= 64
|
|
547
645
|
? "IM_BOT_WORKING_FULL"
|
|
548
646
|
: undefined;
|
|
549
647
|
if (full) {
|
|
@@ -559,6 +657,13 @@ export class ImRuntime {
|
|
|
559
657
|
this.#sessionStore.save(key, binding);
|
|
560
658
|
session.id = binding.id;
|
|
561
659
|
}
|
|
660
|
+
if (message.text.trim() !== "/session") {
|
|
661
|
+
const name = readableSessionName(message, session.sessionName);
|
|
662
|
+
if (name !== session.sessionName) {
|
|
663
|
+
session.sessionName = name;
|
|
664
|
+
this.#saveBinding(key, session);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
562
667
|
const executionSession = { ...session };
|
|
563
668
|
const frozenMessage = {
|
|
564
669
|
...message,
|
|
@@ -608,7 +713,10 @@ export class ImRuntime {
|
|
|
608
713
|
};
|
|
609
714
|
const effect = `busy:${message.messageId}`;
|
|
610
715
|
const notification = Promise.allSettled([
|
|
611
|
-
Promise.resolve().then(() => message.replyFailure?.(event, effect
|
|
716
|
+
Promise.resolve().then(() => message.replyFailure?.(event, effect, {
|
|
717
|
+
signal: this.#signal,
|
|
718
|
+
obsolete: () => this.#closed || this.#signal.aborted
|
|
719
|
+
})),
|
|
612
720
|
this.#reply(message, `当前智能体繁忙,请稍后再试\n错误码:${payload.failure.code}`, `${effect}:text`)
|
|
613
721
|
])
|
|
614
722
|
.then((results) => {
|
|
@@ -621,7 +729,7 @@ export class ImRuntime {
|
|
|
621
729
|
this.#busyNotifications.set(key, notification);
|
|
622
730
|
}
|
|
623
731
|
/** 独立错误展示不复用已坏的 presentation;共享有界投递,迟到失败不触发再次执行或递归通知。 */
|
|
624
|
-
#notifyFailure(message, failure, identity, retry = false) {
|
|
732
|
+
#notifyFailure(message, failure, identity, retry = false, turnSignal) {
|
|
625
733
|
const data = {
|
|
626
734
|
code: failure.code,
|
|
627
735
|
reason_code: failure.reasonCode,
|
|
@@ -645,6 +753,16 @@ export class ImRuntime {
|
|
|
645
753
|
};
|
|
646
754
|
const delivery = this.#delivery;
|
|
647
755
|
const options = { transient: true, obsolete: () => this.#closed || performance.now() >= until };
|
|
756
|
+
const deliveryOptions = {
|
|
757
|
+
signal: AbortSignal.any([
|
|
758
|
+
this.#signal,
|
|
759
|
+
...(turnSignal ? [turnSignal] : []),
|
|
760
|
+
...(Number.isFinite(until)
|
|
761
|
+
? [AbortSignal.timeout(Math.max(0, Math.ceil(until - performance.now())))]
|
|
762
|
+
: [])
|
|
763
|
+
]),
|
|
764
|
+
obsolete: () => options.obsolete() || Boolean(turnSignal?.aborted)
|
|
765
|
+
};
|
|
648
766
|
const secondary = (code) => {
|
|
649
767
|
this.#diagnostic(code, identity?.runId, {
|
|
650
768
|
...data,
|
|
@@ -657,12 +775,16 @@ export class ImRuntime {
|
|
|
657
775
|
};
|
|
658
776
|
const send = async (operation, key) => {
|
|
659
777
|
const receipt = await delivery.deliver(key, operation, options);
|
|
778
|
+
if (turnSignal?.aborted)
|
|
779
|
+
return;
|
|
660
780
|
if (receipt.state !== "delivered")
|
|
661
781
|
secondary(receipt.code ?? "IM_DELIVERY_FAILED");
|
|
662
782
|
};
|
|
663
783
|
const notification = withinShutdown(Promise.allSettled([
|
|
664
|
-
...(message.replyFailure
|
|
665
|
-
|
|
784
|
+
...(message.replyFailure
|
|
785
|
+
? [send(() => message.replyFailure(event, effect, deliveryOptions), effect)]
|
|
786
|
+
: []),
|
|
787
|
+
send(() => message.reply(text, `${effect}:text`, deliveryOptions), `${effect}:text`)
|
|
666
788
|
]), until, "IM_DELIVERY_UNKNOWN")
|
|
667
789
|
.then(() => undefined)
|
|
668
790
|
.catch(() => secondary("IM_DELIVERY_UNKNOWN"))
|
|
@@ -675,7 +797,7 @@ export class ImRuntime {
|
|
|
675
797
|
return;
|
|
676
798
|
const receipt = await this.#delivery.deliver(effectKey, () => final && message.replyFinal
|
|
677
799
|
? message.replyFinal(text, effectKey, finalOptions)
|
|
678
|
-
: message.reply(text, effectKey), { obsolete: finalOptions ? () => finalOptions.obsolete() : undefined });
|
|
800
|
+
: message.reply(text, effectKey, finalOptions), { obsolete: finalOptions ? () => finalOptions.obsolete() : undefined });
|
|
679
801
|
if (finalOptions?.obsolete())
|
|
680
802
|
return;
|
|
681
803
|
if (receipt.state !== "delivered") {
|
|
@@ -688,8 +810,16 @@ export class ImRuntime {
|
|
|
688
810
|
!this.#closed &&
|
|
689
811
|
!this.#signal.aborted) {
|
|
690
812
|
const notice = deliveryNotice();
|
|
691
|
-
|
|
692
|
-
|
|
813
|
+
// 未知通知仍属于原轮最终投递;stop/reset 必须取消在途请求并阻止后续重试。
|
|
814
|
+
// 迟到 ACK 与代次过期共用发送边界检查,不能因 REST 独立于 WS 而脱离任务期限。
|
|
815
|
+
const noticeSignal = finalOptions
|
|
816
|
+
? AbortSignal.any([this.#signal, finalOptions.signal])
|
|
817
|
+
: this.#signal;
|
|
818
|
+
const obsolete = () => noticeSignal.aborted ||
|
|
819
|
+
Boolean(finalOptions?.obsolete()) ||
|
|
820
|
+
Boolean(message.isReplyDelivered?.(effectKey));
|
|
821
|
+
const result = await this.#delivery.deliver(`delivery-unknown:${effectKey}`, () => message.replyDeliveryUnknown(notice, `delivery-unknown:${effectKey}`, effectKey, noticeSignal, obsolete), { obsolete });
|
|
822
|
+
if (result.state !== "delivered" && !obsolete())
|
|
693
823
|
this.#diagnostic("IM_DELIVERY_NOTICE_FAILED");
|
|
694
824
|
}
|
|
695
825
|
if (requireDelivered)
|
|
@@ -771,6 +901,12 @@ export class ImRuntime {
|
|
|
771
901
|
let failureAfterSeq = null;
|
|
772
902
|
let rulesRevision = 0;
|
|
773
903
|
let rulesVersions;
|
|
904
|
+
const stableState = executionSession.stableContext;
|
|
905
|
+
const initialWasAttempted = executionSession.initialization.attempted;
|
|
906
|
+
const stablePlan = message.historyRetry
|
|
907
|
+
? { turn: stableState.turnCount, refresh: false }
|
|
908
|
+
: planStableContext(stableState, this.config.stable_context_refresh_interval_turns);
|
|
909
|
+
let stableRecovered = false;
|
|
774
910
|
const rulesEnabled = message.conversationKind !== "direct";
|
|
775
911
|
// Octospec F05: .octospec/tasks/gateway-august-feature-assessment/assessment.md
|
|
776
912
|
// 仅普通任务开始时回执;通知失败不阻断 Context 准备和模型执行。
|
|
@@ -785,9 +921,9 @@ export class ImRuntime {
|
|
|
785
921
|
executionSession.providerSession = session.providerSession;
|
|
786
922
|
const initialization = executionSession.initialization;
|
|
787
923
|
const initialSession = !initialization.attempted;
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
924
|
+
const refreshStableContext = stablePlan.refresh ||
|
|
925
|
+
!executionSession.providerSession?.sessionId ||
|
|
926
|
+
executionSession.providerSession.resumable === false;
|
|
791
927
|
const binding = this.#sessionStore.read(key);
|
|
792
928
|
const rulesCursor = !message.historyRetry &&
|
|
793
929
|
typeof this.#sessionStore.patchRules === "function" &&
|
|
@@ -806,6 +942,16 @@ export class ImRuntime {
|
|
|
806
942
|
binding.generation === executionSession.generation
|
|
807
943
|
? binding.gap
|
|
808
944
|
: undefined, this.#processEpoch, typeof this.#sessionStore.patchGap === "function");
|
|
945
|
+
const outputs = binding?.gap?.assistantOutputs;
|
|
946
|
+
// 补位/新建/恢复不明均保留;旧 ACK 与同 UID 不能代替当前 Provider 的归属证据。
|
|
947
|
+
if (!initialSession &&
|
|
948
|
+
gapPlan.mode === "delta" &&
|
|
949
|
+
binding?.gap?.pendingAfterSeq === undefined &&
|
|
950
|
+
!binding?.gap?.continuityUnknown &&
|
|
951
|
+
outputs?.providerSessionId === executionSession.providerSession?.sessionId &&
|
|
952
|
+
executionSession.providerSession?.resumable !== false &&
|
|
953
|
+
!["fresh_fallback", "compacted"].includes(executionSession.providerSession?.resumeOutcome ?? ""))
|
|
954
|
+
gapPlan.excludedOutputs = outputs?.messages;
|
|
809
955
|
message.bindHistoryTurn?.({
|
|
810
956
|
sessionId: executionSession.id,
|
|
811
957
|
generation: executionSession.generation,
|
|
@@ -817,8 +963,6 @@ export class ImRuntime {
|
|
|
817
963
|
? undefined
|
|
818
964
|
: await this.dependencies.prepareContexts?.(this.config, turnSignal),
|
|
819
965
|
initialSession,
|
|
820
|
-
// 逐轮提醒让升级前的 Provider binding 也收到新 mention 规则,不隐式 reset。
|
|
821
|
-
mentionGuidance: true,
|
|
822
966
|
...(gapEnabled
|
|
823
967
|
? {
|
|
824
968
|
historyGap: gapPlan,
|
|
@@ -828,13 +972,13 @@ export class ImRuntime {
|
|
|
828
972
|
}
|
|
829
973
|
: {})
|
|
830
974
|
});
|
|
831
|
-
const selection = selectRulesContext(fullContext, rulesCursor, executionSession.providerSession);
|
|
975
|
+
const selection = selectRulesContext(fullContext, rulesCursor, executionSession.providerSession, !message.historyRetry && refreshStableContext);
|
|
832
976
|
const context = selection.context;
|
|
833
977
|
rulesVersions = message.historyRetry ? undefined : selection.versions;
|
|
834
978
|
if (gapEnabled)
|
|
835
979
|
failureAfterSeq = gapPlan.afterSeq ?? null;
|
|
836
|
-
//
|
|
837
|
-
prepared = createImInvocation(this.config, message, context, key, executionSession, turnSignal, occurrenceId);
|
|
980
|
+
// 准备只计算发送计划;直到第一次执行尝试才消费轮次和首轮历史资格。
|
|
981
|
+
prepared = createImInvocation(this.config, message, context, key, executionSession, turnSignal, occurrenceId, refreshStableContext);
|
|
838
982
|
if (gapEnabled &&
|
|
839
983
|
context.items.some((item) => item.namespace === "extra.im" &&
|
|
840
984
|
item.name === "history" &&
|
|
@@ -850,7 +994,17 @@ export class ImRuntime {
|
|
|
850
994
|
throw new ImImageInputError("每条独立图片消息只接收一张图片。");
|
|
851
995
|
prepared.request.inputs = parts;
|
|
852
996
|
}
|
|
853
|
-
|
|
997
|
+
// 恢复补充只含主历史排除的消息,同一窗口/快照,不重复用户 gap 或另起读取。
|
|
998
|
+
addRulesRecovery(prepared.request, [
|
|
999
|
+
...selection.omitted,
|
|
1000
|
+
...prepared.recoveryContexts,
|
|
1001
|
+
...(prepared.historyContext && gapPlan.recoveryHistory ? [gapPlan.recoveryHistory] : [])
|
|
1002
|
+
]);
|
|
1003
|
+
if (!message.historyRetry)
|
|
1004
|
+
prepared.request.runMetadata = {
|
|
1005
|
+
...prepared.request.runMetadata,
|
|
1006
|
+
conversationTurn: stablePlan.turn
|
|
1007
|
+
};
|
|
854
1008
|
if (message.historyRetry) {
|
|
855
1009
|
const saved = this.#sessionStore.occurrence(key, message.messageId)?.snapshot;
|
|
856
1010
|
if (saved?.freshFallbackModelInput !== undefined)
|
|
@@ -872,7 +1026,8 @@ export class ImRuntime {
|
|
|
872
1026
|
text: message.text,
|
|
873
1027
|
sessionId: executionSession.id,
|
|
874
1028
|
runId: prepared.request.runId,
|
|
875
|
-
snapshot
|
|
1029
|
+
snapshot,
|
|
1030
|
+
artifacts: prepared.artifacts
|
|
876
1031
|
});
|
|
877
1032
|
}
|
|
878
1033
|
catch (error) {
|
|
@@ -880,14 +1035,17 @@ export class ImRuntime {
|
|
|
880
1035
|
this.#finishRules(key, executionSession, rulesRevision, undefined, false);
|
|
881
1036
|
if (turnSignal.aborted)
|
|
882
1037
|
return;
|
|
883
|
-
|
|
1038
|
+
const preparationMessage = error instanceof Error ? preparationFailureMessages.get(error.message) : undefined;
|
|
1039
|
+
if (error instanceof Error &&
|
|
1040
|
+
(preparationMessage || /^IM_CONTEXT_(?:LOADING|RESULT)_[A-Z_]+$/.test(error.message)))
|
|
884
1041
|
this.#diagnostic(error.message);
|
|
885
1042
|
this.#diagnostic("IM_CONTEXT_PREPARATION_FAILED");
|
|
886
|
-
await this.#reply(message,
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
1043
|
+
await this.#reply(message, preparationMessage ??
|
|
1044
|
+
(error instanceof ImImageInputError
|
|
1045
|
+
? error.message
|
|
1046
|
+
: message.buildInputs
|
|
1047
|
+
? "图片输入准备失败,尚未发起执行。请检查图片或稍后重试。"
|
|
1048
|
+
: "本轮输入或执行配置准备失败,尚未发起执行。请检查配置、会话权限或稍后重试。"), `prepare:${occurrenceId ?? message.messageId}`);
|
|
891
1049
|
return;
|
|
892
1050
|
}
|
|
893
1051
|
finally {
|
|
@@ -906,14 +1064,24 @@ export class ImRuntime {
|
|
|
906
1064
|
let presentationSeq = 0;
|
|
907
1065
|
let projector = new ImRunProjector(rootRunId, message.conversationKind === "direct");
|
|
908
1066
|
let handedOff = false;
|
|
1067
|
+
let turnStarted = false;
|
|
909
1068
|
const task = new ImTask(this.dependencies.kernel, request, prepared.adapterType, this.config, { ...environment, signal: this.#signal }, (attempt) => {
|
|
1069
|
+
// 同代次排队共享状态;自动/卡片重试不增加用户轮数,reset 后旧任务仅更新旧对象。
|
|
1070
|
+
if (!turnStarted && !message.historyRetry) {
|
|
1071
|
+
turnStarted = true;
|
|
1072
|
+
stableState.turnCount = stablePlan.turn;
|
|
1073
|
+
stableState.refreshPending ||= prepared.stableContextIncluded;
|
|
1074
|
+
executionSession.initialization.attempted = true;
|
|
1075
|
+
}
|
|
910
1076
|
if (!handedOff &&
|
|
911
1077
|
message.position &&
|
|
912
1078
|
message.conversationKind !== "direct" &&
|
|
913
1079
|
!message.historyRetry) {
|
|
914
1080
|
handedOff = true;
|
|
915
1081
|
try {
|
|
916
|
-
this.#sessionStore.patchGap?.(key, { sessionId: executionSession.id, generation: executionSession.generation }, (previous) => commitHistoryGap(gapMetadata(this.#processEpoch, previous), message.position?.messageSeq, gapPlan, attempt.contexts.items.
|
|
1082
|
+
this.#sessionStore.patchGap?.(key, { sessionId: executionSession.id, generation: executionSession.generation }, (previous) => commitHistoryGap(gapMetadata(this.#processEpoch, previous), message.position?.messageSeq, gapPlan, attempt.contexts.items.some((item) => item.namespace === "extra.im" && item.name === "history")
|
|
1083
|
+
? prepared.historyContext
|
|
1084
|
+
: undefined));
|
|
917
1085
|
}
|
|
918
1086
|
catch {
|
|
919
1087
|
this.#finalizationFailed("IM_HISTORY_POSITION_UNAVAILABLE");
|
|
@@ -923,6 +1091,7 @@ export class ImRuntime {
|
|
|
923
1091
|
if (entry.invocationId === request.invocationId)
|
|
924
1092
|
this.#interactions.delete(id);
|
|
925
1093
|
request = attempt;
|
|
1094
|
+
projector.dispose();
|
|
926
1095
|
projector = new ImRunProjector(rootRunId, message.conversationKind === "direct");
|
|
927
1096
|
session.activeInvocationId = request.invocationId;
|
|
928
1097
|
if (session.id === request.sessionId) {
|
|
@@ -963,228 +1132,275 @@ export class ImRuntime {
|
|
|
963
1132
|
}
|
|
964
1133
|
};
|
|
965
1134
|
try {
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
session.
|
|
975
|
-
|
|
976
|
-
|
|
1135
|
+
try {
|
|
1136
|
+
presentation = message.beginPresentation?.(rootRunId, (code) => this.#diagnostic(code, rootRunId), controls);
|
|
1137
|
+
presentation?.update(snapshot());
|
|
1138
|
+
session.activeInvocationId = request.invocationId;
|
|
1139
|
+
executionStarted = true;
|
|
1140
|
+
for await (const event of task.events()) {
|
|
1141
|
+
if (this.#closed || this.#signal.aborted)
|
|
1142
|
+
break;
|
|
1143
|
+
if (event.type === "session.update" && session.id === request.sessionId) {
|
|
1144
|
+
session.providerSession = event.payload.providerSession;
|
|
1145
|
+
this.#saveBinding(key, session);
|
|
1146
|
+
if (event.payload.providerSession?.resumeOutcome === "fresh_fallback") {
|
|
1147
|
+
stableRecovered = true;
|
|
1148
|
+
try {
|
|
1149
|
+
this.#sessionStore.patchGap?.(key, { sessionId: request.sessionId, generation: executionSession.generation }, (previous) => ({
|
|
1150
|
+
...gapMetadata(this.#processEpoch, previous),
|
|
1151
|
+
continuityUnknown: true,
|
|
1152
|
+
pendingAfterSeq: null
|
|
1153
|
+
}));
|
|
1154
|
+
}
|
|
1155
|
+
catch {
|
|
1156
|
+
this.#finalizationFailed("IM_HISTORY_POSITION_UNAVAILABLE");
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
// 只有执行策略与事件策略均为 full_access 的审批才是自动处理的审计记录。
|
|
1161
|
+
// 问题/elicitation 仍须展示并交回原交互入口,不能一并过滤。
|
|
1162
|
+
if (event.type === "interaction.requested" &&
|
|
1163
|
+
event.payload.kind === "approval" &&
|
|
1164
|
+
request.approvalMode === "full_access" &&
|
|
1165
|
+
event.payload.request.policy?.mode === "full_access")
|
|
1166
|
+
continue;
|
|
1167
|
+
if (event.type === "interaction.requested") {
|
|
1168
|
+
if (this.#draining)
|
|
1169
|
+
continue;
|
|
1170
|
+
// Octospec F09: .octospec/tasks/gateway-august-feature-assessment/assessment.md
|
|
1171
|
+
// 普通 IM 不提供秘密输入通道,禁止退回聊天命令收集凭据。
|
|
1172
|
+
if (Array.isArray(event.payload.request.questions) &&
|
|
1173
|
+
event.payload.request.questions.some((question) => question !== null &&
|
|
1174
|
+
typeof question === "object" &&
|
|
1175
|
+
"isSecret" in question &&
|
|
1176
|
+
question.isSecret === true)) {
|
|
1177
|
+
this.#diagnostic("IM_INTERACTION_SECRET_UNSUPPORTED", request.runId);
|
|
1178
|
+
await this.#reply(message, "本次执行需要安全输入,当前聊天不支持。请勿在聊天中发送密码或密钥;本次执行已请求停止。", `interaction:${event.payload.interactionId}`);
|
|
1179
|
+
await this.dependencies.kernel.cancelInvocation(request.invocationId, "IM secret input unsupported");
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
if (this.#interactions.size >= 64)
|
|
1183
|
+
throw new Error("IM_INTERACTION_CAPACITY_EXHAUSTED");
|
|
1184
|
+
this.#interactions.set(event.payload.interactionId, {
|
|
1185
|
+
invocationId: request.invocationId,
|
|
1186
|
+
sessionId: request.sessionId,
|
|
1187
|
+
key,
|
|
1188
|
+
senderId: message.senderId,
|
|
1189
|
+
request: structuredClone(event.payload)
|
|
1190
|
+
});
|
|
1191
|
+
const interaction = event.payload;
|
|
1192
|
+
let cardShown = false;
|
|
1193
|
+
try {
|
|
1194
|
+
cardShown =
|
|
1195
|
+
!presentationFailed && ((await presentation?.interaction?.(interaction)) ?? false);
|
|
1196
|
+
}
|
|
1197
|
+
catch {
|
|
1198
|
+
this.#diagnostic("IM_INTERACTION_CARD_FAILED", request.runId);
|
|
1199
|
+
}
|
|
1200
|
+
const display = interaction.request.operation;
|
|
1201
|
+
const summary = [
|
|
1202
|
+
display?.summary,
|
|
1203
|
+
interaction.request.question,
|
|
1204
|
+
interaction.request.message
|
|
1205
|
+
].find((value) => typeof value === "string");
|
|
1206
|
+
const instruction = interaction.kind === "approval"
|
|
1207
|
+
? `/approve ${interaction.interactionId} 或 /decline ${interaction.interactionId}`
|
|
1208
|
+
: `/respond ${interaction.interactionId} ${interaction.kind === "elicitation" ? "<JSON>" : "<回答>"}`;
|
|
1209
|
+
if (!cardShown)
|
|
1210
|
+
await this.#reply(message, `${summary?.slice(0, 1000) ?? "执行需要你的确认或输入。"}\n${Array.isArray(interaction.request.questions) ? JSON.stringify(interaction.request.questions).slice(0, 8000) + "\n请按问题 ID 提交 JSON 答案。\n" : ""}${instruction}`, `interaction:${interaction.interactionId}`, true);
|
|
1211
|
+
}
|
|
1212
|
+
if (event.type === "interaction.resolved") {
|
|
1213
|
+
this.#interactions.delete(event.payload.interactionId);
|
|
977
1214
|
try {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
continuityUnknown: true,
|
|
981
|
-
pendingAfterSeq: null
|
|
982
|
-
}));
|
|
1215
|
+
if (!presentationFailed)
|
|
1216
|
+
await presentation?.resolveInteraction?.(event.payload.interactionId, event.payload.status);
|
|
983
1217
|
}
|
|
984
1218
|
catch {
|
|
985
|
-
this.#
|
|
1219
|
+
this.#diagnostic("IM_INTERACTION_CARD_FAILED", request.runId);
|
|
986
1220
|
}
|
|
987
1221
|
}
|
|
1222
|
+
projector.accept(event);
|
|
1223
|
+
controls.failed =
|
|
1224
|
+
projector.snapshot().terminal === "failed" ||
|
|
1225
|
+
(projector.snapshot().terminal === "cancelled" &&
|
|
1226
|
+
task.modelWait.snapshot.timeout === "terminated");
|
|
1227
|
+
updatePresentation();
|
|
988
1228
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1229
|
+
if (!projector.snapshot().terminal)
|
|
1230
|
+
throw new Error("IM_RUN_WITHOUT_TERMINAL");
|
|
1231
|
+
}
|
|
1232
|
+
catch {
|
|
1233
|
+
if (!executionStarted || task.notSubmittedFailure) {
|
|
1234
|
+
localFailure =
|
|
1235
|
+
task.notSubmittedFailure ??
|
|
1236
|
+
failurePayload({ code: "IM_PRESENTATION_INITIALIZATION_FAILED" }, {
|
|
1237
|
+
stage: "channel_presentation_initialize",
|
|
1238
|
+
defaultDomain: "runtime",
|
|
1239
|
+
runId: request.runId
|
|
1240
|
+
}).failure;
|
|
1241
|
+
controls.failed = false;
|
|
1242
|
+
// 未提交失败的错误卡也可能等待重连;先移交取消权,stop/reset 才能终止待发通知。
|
|
1243
|
+
this.#finalDeliveries.set(key, delivery);
|
|
1244
|
+
await this.#notifyFailure(message, localFailure, request, task.attempts.length > 1, delivery.signal);
|
|
1245
|
+
}
|
|
1246
|
+
else {
|
|
997
1247
|
if (this.#draining)
|
|
998
|
-
|
|
999
|
-
//
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
sessionId: request.sessionId,
|
|
1016
|
-
key,
|
|
1017
|
-
senderId: message.senderId,
|
|
1018
|
-
request: structuredClone(event.payload)
|
|
1019
|
-
});
|
|
1020
|
-
const interaction = event.payload;
|
|
1021
|
-
let cardShown = false;
|
|
1022
|
-
try {
|
|
1023
|
-
cardShown =
|
|
1024
|
-
!presentationFailed && ((await presentation?.interaction?.(interaction)) ?? false);
|
|
1025
|
-
}
|
|
1026
|
-
catch {
|
|
1027
|
-
this.#diagnostic("IM_INTERACTION_CARD_FAILED", request.runId);
|
|
1248
|
+
this.#drainErrors.push(new Error("IM_EXECUTION_RESULT_UNKNOWN"));
|
|
1249
|
+
// 流断开无法证明执行失败;尽力取消并提示核查,不自动重跑潜在的业务副作用。
|
|
1250
|
+
await this.dependencies.kernel
|
|
1251
|
+
.cancelInvocation(request.invocationId, "IM execution stream failed")
|
|
1252
|
+
.catch(() => undefined);
|
|
1253
|
+
this.#diagnostic("IM_EXECUTION_RESULT_UNKNOWN", request.runId);
|
|
1254
|
+
// 原源流即使在终态后失败,也不能被展示层的终态掩盖。
|
|
1255
|
+
controls.failed = false;
|
|
1256
|
+
projector.dispose();
|
|
1257
|
+
projector = new ImRunProjector(rootRunId, message.conversationKind === "direct");
|
|
1258
|
+
if (!presentationFailed) {
|
|
1259
|
+
try {
|
|
1260
|
+
presentation?.update({ ...snapshot(), resultUnknown: true });
|
|
1261
|
+
}
|
|
1262
|
+
catch {
|
|
1263
|
+
this.#finalizationFailed("IM_PRESENTATION_FAILED", request.runId);
|
|
1264
|
+
}
|
|
1028
1265
|
}
|
|
1029
|
-
const display = interaction.request.operation;
|
|
1030
|
-
const summary = [
|
|
1031
|
-
display?.summary,
|
|
1032
|
-
interaction.request.question,
|
|
1033
|
-
interaction.request.message
|
|
1034
|
-
].find((value) => typeof value === "string");
|
|
1035
|
-
const instruction = interaction.kind === "approval"
|
|
1036
|
-
? `/approve ${interaction.interactionId} 或 /decline ${interaction.interactionId}`
|
|
1037
|
-
: `/respond ${interaction.interactionId} ${interaction.kind === "elicitation" ? "<JSON>" : "<回答>"}`;
|
|
1038
|
-
if (!cardShown)
|
|
1039
|
-
await this.#reply(message, `${summary?.slice(0, 1000) ?? "执行需要你的确认或输入。"}\n${Array.isArray(interaction.request.questions) ? JSON.stringify(interaction.request.questions).slice(0, 8000) + "\n请按问题 ID 提交 JSON 答案。\n" : ""}${instruction}`, `interaction:${interaction.interactionId}`, true);
|
|
1040
1266
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1267
|
+
}
|
|
1268
|
+
finally {
|
|
1269
|
+
let stableChanged = false;
|
|
1270
|
+
if (localFailure &&
|
|
1271
|
+
turnStarted &&
|
|
1272
|
+
task.attempts.every((attempt) => attempt.outcome === "not_submitted") &&
|
|
1273
|
+
session.id === executionSession.id &&
|
|
1274
|
+
session.generation === executionSession.generation) {
|
|
1275
|
+
// 可信未提交才允许回退轮次;已执行失败或结果未知不能当作从未执行。
|
|
1276
|
+
stableState.turnCount--;
|
|
1277
|
+
executionSession.initialization.attempted = initialWasAttempted;
|
|
1278
|
+
stableChanged = true;
|
|
1279
|
+
}
|
|
1280
|
+
if (session.id === executionSession.id &&
|
|
1281
|
+
session.generation === executionSession.generation &&
|
|
1282
|
+
projector.snapshot().terminal === "completed" &&
|
|
1283
|
+
(prepared.stableContextIncluded || stableRecovered)) {
|
|
1284
|
+
stableState.refreshPending = false;
|
|
1285
|
+
stableChanged = true;
|
|
1286
|
+
}
|
|
1287
|
+
if (stableChanged)
|
|
1043
1288
|
try {
|
|
1044
|
-
|
|
1045
|
-
await presentation?.resolveInteraction?.(event.payload.interactionId, event.payload.status);
|
|
1289
|
+
this.#saveBinding(key, session);
|
|
1046
1290
|
}
|
|
1047
1291
|
catch {
|
|
1048
|
-
this.#
|
|
1292
|
+
this.#finalizationFailed("IM_SESSION_STORE_FAILED", rootRunId);
|
|
1049
1293
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
projector.snapshot().terminal === "failed" ||
|
|
1054
|
-
(projector.snapshot().terminal === "cancelled" &&
|
|
1055
|
-
task.modelWait.snapshot.timeout === "terminated");
|
|
1056
|
-
updatePresentation();
|
|
1057
|
-
}
|
|
1058
|
-
if (!projector.snapshot().terminal)
|
|
1059
|
-
throw new Error("IM_RUN_WITHOUT_TERMINAL");
|
|
1060
|
-
}
|
|
1061
|
-
catch {
|
|
1062
|
-
if (!executionStarted || task.notSubmittedFailure) {
|
|
1063
|
-
localFailure =
|
|
1064
|
-
task.notSubmittedFailure ??
|
|
1065
|
-
failurePayload({ code: "IM_PRESENTATION_INITIALIZATION_FAILED" }, {
|
|
1066
|
-
stage: "channel_presentation_initialize",
|
|
1067
|
-
defaultDomain: "runtime",
|
|
1068
|
-
runId: request.runId
|
|
1069
|
-
}).failure;
|
|
1070
|
-
controls.failed = false;
|
|
1071
|
-
await this.#notifyFailure(message, localFailure, request, task.attempts.length > 1);
|
|
1072
|
-
}
|
|
1073
|
-
else {
|
|
1074
|
-
if (this.#draining)
|
|
1075
|
-
this.#drainErrors.push(new Error("IM_EXECUTION_RESULT_UNKNOWN"));
|
|
1076
|
-
// 流断开无法证明执行失败;尽力取消并提示核查,不自动重跑潜在的业务副作用。
|
|
1077
|
-
await this.dependencies.kernel
|
|
1078
|
-
.cancelInvocation(request.invocationId, "IM execution stream failed")
|
|
1079
|
-
.catch(() => undefined);
|
|
1080
|
-
this.#diagnostic("IM_EXECUTION_RESULT_UNKNOWN", request.runId);
|
|
1081
|
-
// 原源流即使在终态后失败,也不能被展示层的终态掩盖。
|
|
1082
|
-
controls.failed = false;
|
|
1083
|
-
projector = new ImRunProjector(rootRunId, message.conversationKind === "direct");
|
|
1084
|
-
if (!presentationFailed) {
|
|
1294
|
+
if (rulesEnabled)
|
|
1295
|
+
this.#finishRules(key, executionSession, rulesRevision, rulesVersions, projector.snapshot().terminal === "completed");
|
|
1296
|
+
if (!this.#closed && handedOff && projector.snapshot().terminal !== "completed") {
|
|
1085
1297
|
try {
|
|
1086
|
-
|
|
1298
|
+
this.#sessionStore.patchGap?.(key, { sessionId: executionSession.id, generation: executionSession.generation }, (previous) => {
|
|
1299
|
+
const next = gapMetadata(this.#processEpoch, previous);
|
|
1300
|
+
next.pendingAfterSeq =
|
|
1301
|
+
next.pendingAfterSeq === null || failureAfterSeq === null
|
|
1302
|
+
? null
|
|
1303
|
+
: Math.min(next.pendingAfterSeq ?? failureAfterSeq, failureAfterSeq);
|
|
1304
|
+
return next;
|
|
1305
|
+
});
|
|
1087
1306
|
}
|
|
1088
1307
|
catch {
|
|
1089
|
-
this.#finalizationFailed("
|
|
1308
|
+
this.#finalizationFailed("IM_HISTORY_POSITION_UNAVAILABLE");
|
|
1090
1309
|
}
|
|
1091
1310
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1311
|
+
if (task.stopReason)
|
|
1312
|
+
this.#diagnostic(task.stopReason, rootRunId);
|
|
1313
|
+
this.#log("agent_run.finished", {
|
|
1314
|
+
run_id: rootRunId,
|
|
1315
|
+
invocation_id: request.invocationId,
|
|
1316
|
+
session_id: request.sessionId,
|
|
1317
|
+
status: localFailure ? "not_submitted" : (projector.snapshot().terminal ?? "unknown")
|
|
1318
|
+
});
|
|
1319
|
+
// 移除执行身份前移交收尾/产物投递的取消权;finish 等待期间的 stop 不能落入空窗。
|
|
1320
|
+
if (!localFailure)
|
|
1321
|
+
this.#finalDeliveries.set(key, delivery);
|
|
1322
|
+
this.#tasks.delete(key);
|
|
1098
1323
|
try {
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1324
|
+
// 长任务结束后重新开始终态去重窗口,保留有界尝试身份,避免立即重复执行。
|
|
1325
|
+
const saved = { ...prepared.request };
|
|
1326
|
+
if (!this.#closed)
|
|
1327
|
+
this.#sessionStore.remember(key, occurrenceId ?? message.messageId, {
|
|
1328
|
+
text: message.text,
|
|
1329
|
+
sessionId: request.sessionId,
|
|
1330
|
+
runId: rootRunId,
|
|
1331
|
+
snapshot: saved,
|
|
1332
|
+
artifacts: prepared.artifacts,
|
|
1333
|
+
attempts: task.attempts.map((attempt) => ({ ...attempt })),
|
|
1334
|
+
...(localFailure &&
|
|
1335
|
+
task.attempts.every((attempt) => attempt.outcome === "not_submitted")
|
|
1336
|
+
? { notSubmittedFailure: localFailure }
|
|
1337
|
+
: {})
|
|
1338
|
+
});
|
|
1107
1339
|
}
|
|
1108
1340
|
catch {
|
|
1109
|
-
this.#finalizationFailed("
|
|
1341
|
+
this.#finalizationFailed("IM_SESSION_STORE_FAILED", rootRunId);
|
|
1342
|
+
}
|
|
1343
|
+
session.activeInvocationId = undefined;
|
|
1344
|
+
for (const [id, entry] of this.#interactions)
|
|
1345
|
+
if (entry.invocationId === request.invocationId)
|
|
1346
|
+
this.#interactions.delete(id);
|
|
1347
|
+
try {
|
|
1348
|
+
if (!this.#closed)
|
|
1349
|
+
await withinShutdown(Promise.resolve().then(() => presentation?.finish()), shutdownDeadline(this.dependencies.signal), "IM_PRESENTATION_FINISH_INCOMPLETE");
|
|
1350
|
+
}
|
|
1351
|
+
catch (error) {
|
|
1352
|
+
// 截止只结束等待,不能证明尚未完成的展示资源已经释放。
|
|
1353
|
+
if (error instanceof Error && error.message === "IM_PRESENTATION_FINISH_INCOMPLETE")
|
|
1354
|
+
this.#finishIncomplete ??= error;
|
|
1355
|
+
this.#finalizationFailed("IM_PRESENTATION_FAILED", request.runId);
|
|
1110
1356
|
}
|
|
1111
1357
|
}
|
|
1112
|
-
if (task.stopReason)
|
|
1113
|
-
this.#diagnostic(task.stopReason, rootRunId);
|
|
1114
|
-
this.#log("agent_run.finished", {
|
|
1115
|
-
run_id: rootRunId,
|
|
1116
|
-
invocation_id: request.invocationId,
|
|
1117
|
-
session_id: request.sessionId,
|
|
1118
|
-
status: localFailure ? "not_submitted" : (projector.snapshot().terminal ?? "unknown")
|
|
1119
|
-
});
|
|
1120
|
-
// 移除执行身份前移交收尾/产物投递的取消权;finish 等待期间的 stop 不能落入空窗。
|
|
1121
|
-
if (!localFailure)
|
|
1122
|
-
this.#finalDeliveries.set(key, delivery);
|
|
1123
|
-
this.#tasks.delete(key);
|
|
1124
1358
|
try {
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
text:
|
|
1359
|
+
if (localFailure || this.#closed || this.#signal.aborted || delivery.signal.aborted)
|
|
1360
|
+
return;
|
|
1361
|
+
const { text, allowMention } = task.modelWait.snapshot.timeout && projector.snapshot().terminal !== "completed"
|
|
1362
|
+
? {
|
|
1363
|
+
text: MODEL_WAIT_TIMEOUT_MESSAGE +
|
|
1364
|
+
(task.modelWait.snapshot.timeout === "terminated"
|
|
1365
|
+
? "已确认执行结束,可以重试。"
|
|
1366
|
+
: "尚未确认执行停止,请核查运行记录,避免重复执行。"),
|
|
1367
|
+
allowMention: false
|
|
1368
|
+
}
|
|
1369
|
+
: projector.finalReply;
|
|
1370
|
+
const obsolete = () => {
|
|
1371
|
+
const binding = this.#sessionStore.read(key);
|
|
1372
|
+
return (binding?.id !== request.sessionId || binding.generation !== request.sessionGeneration);
|
|
1373
|
+
};
|
|
1374
|
+
// reset 不取消原模型执行,但旧代次的结果不能启动上传或继续最终消息重试。
|
|
1375
|
+
if (allowMention && obsolete())
|
|
1376
|
+
return;
|
|
1377
|
+
const deliverySignal = AbortSignal.any([this.#signal, delivery.signal]);
|
|
1378
|
+
if (allowMention &&
|
|
1379
|
+
projector.snapshot().terminal === "completed" &&
|
|
1380
|
+
session.providerSession?.sessionId &&
|
|
1381
|
+
session.providerSession.resumable !== false)
|
|
1382
|
+
message.bindHistoryTurn?.({
|
|
1130
1383
|
sessionId: request.sessionId,
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
...(localFailure &&
|
|
1135
|
-
task.attempts.every((attempt) => attempt.outcome === "not_submitted")
|
|
1136
|
-
? { notSubmittedFailure: localFailure }
|
|
1137
|
-
: {})
|
|
1384
|
+
generation: executionSession.generation,
|
|
1385
|
+
processEpoch: this.#processEpoch,
|
|
1386
|
+
providerSessionId: session.providerSession.sessionId
|
|
1138
1387
|
});
|
|
1388
|
+
// 最终文本拥有独立投递身份,即使进度卡投递失败,也必须尝试回复用户。
|
|
1389
|
+
await this.#reply(message, text, `final:${rootRunId}`, false, allowMention, projector.snapshot().terminal !== "cancelled", {
|
|
1390
|
+
artifacts: prepared.artifacts,
|
|
1391
|
+
signal: deliverySignal,
|
|
1392
|
+
obsolete: () => deliverySignal.aborted || (allowMention && obsolete())
|
|
1393
|
+
});
|
|
1139
1394
|
}
|
|
1140
|
-
|
|
1141
|
-
this.#
|
|
1142
|
-
|
|
1143
|
-
session.activeInvocationId = undefined;
|
|
1144
|
-
for (const [id, entry] of this.#interactions)
|
|
1145
|
-
if (entry.invocationId === request.invocationId)
|
|
1146
|
-
this.#interactions.delete(id);
|
|
1147
|
-
try {
|
|
1148
|
-
if (!this.#closed)
|
|
1149
|
-
await withinShutdown(Promise.resolve().then(() => presentation?.finish()), shutdownDeadline(this.dependencies.signal), "IM_PRESENTATION_FINISH_INCOMPLETE");
|
|
1150
|
-
}
|
|
1151
|
-
catch (error) {
|
|
1152
|
-
// 截止只结束等待,不能证明尚未完成的展示资源已经释放。
|
|
1153
|
-
if (error instanceof Error && error.message === "IM_PRESENTATION_FINISH_INCOMPLETE")
|
|
1154
|
-
this.#finishIncomplete ??= error;
|
|
1155
|
-
this.#finalizationFailed("IM_PRESENTATION_FAILED", request.runId);
|
|
1395
|
+
finally {
|
|
1396
|
+
if (this.#finalDeliveries.get(key) === delivery)
|
|
1397
|
+
this.#finalDeliveries.delete(key);
|
|
1156
1398
|
}
|
|
1157
1399
|
}
|
|
1158
|
-
try {
|
|
1159
|
-
if (localFailure || this.#closed || this.#signal.aborted || delivery.signal.aborted)
|
|
1160
|
-
return;
|
|
1161
|
-
const { text, allowMention } = task.modelWait.snapshot.timeout && projector.snapshot().terminal !== "completed"
|
|
1162
|
-
? {
|
|
1163
|
-
text: MODEL_WAIT_TIMEOUT_MESSAGE +
|
|
1164
|
-
(task.modelWait.snapshot.timeout === "terminated"
|
|
1165
|
-
? "已确认执行结束,可以重试。"
|
|
1166
|
-
: "尚未确认执行停止,请核查运行记录,避免重复执行。"),
|
|
1167
|
-
allowMention: false
|
|
1168
|
-
}
|
|
1169
|
-
: projector.finalReply;
|
|
1170
|
-
const obsolete = () => {
|
|
1171
|
-
const binding = this.#sessionStore.read(key);
|
|
1172
|
-
return (binding?.id !== request.sessionId || binding.generation !== request.sessionGeneration);
|
|
1173
|
-
};
|
|
1174
|
-
// reset 不取消原模型执行,但旧代次的结果不能启动上传或继续最终消息重试。
|
|
1175
|
-
if (allowMention && obsolete())
|
|
1176
|
-
return;
|
|
1177
|
-
const deliverySignal = AbortSignal.any([this.#signal, delivery.signal]);
|
|
1178
|
-
// 最终文本拥有独立投递身份,即使进度卡投递失败,也必须尝试回复用户。
|
|
1179
|
-
await this.#reply(message, text, `final:${rootRunId}`, false, allowMention, projector.snapshot().terminal !== "cancelled", {
|
|
1180
|
-
artifacts: prepared.artifacts,
|
|
1181
|
-
signal: deliverySignal,
|
|
1182
|
-
obsolete: () => deliverySignal.aborted || (allowMention && obsolete())
|
|
1183
|
-
});
|
|
1184
|
-
}
|
|
1185
1400
|
finally {
|
|
1186
|
-
|
|
1187
|
-
|
|
1401
|
+
// 先保留 final 的读取与投递机会,再解除正文引用;取消/早退同样进入此收尾。
|
|
1402
|
+
projector.dispose();
|
|
1403
|
+
presentation = undefined;
|
|
1188
1404
|
}
|
|
1189
1405
|
}
|
|
1190
1406
|
#saveBinding(key, session) {
|
|
@@ -1193,11 +1409,13 @@ export class ImRuntime {
|
|
|
1193
1409
|
const binding = this.#sessionStore.read(key);
|
|
1194
1410
|
this.#sessionStore.save(key, {
|
|
1195
1411
|
id: session.id,
|
|
1412
|
+
sessionName: session.sessionName,
|
|
1196
1413
|
generation: session.generation,
|
|
1197
1414
|
providerSession: session.providerSession,
|
|
1198
1415
|
lastEventId: session.lastEventId,
|
|
1199
1416
|
lastRunId: session.lastRunId,
|
|
1200
1417
|
initialContextPrepared: session.initialization?.attempted === true,
|
|
1418
|
+
stableContext: session.stableContext,
|
|
1201
1419
|
...(binding?.id === session.id &&
|
|
1202
1420
|
binding?.generation === session.generation &&
|
|
1203
1421
|
binding.rulesContext
|