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