@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
|
@@ -41,6 +41,7 @@ export function buildOpenClawGatewayInvocation(req) {
|
|
|
41
41
|
if (Object.keys(invocationEnvs(req)).length)
|
|
42
42
|
throw new Error("CONTEXT_ENVS_UNSUPPORTED: openclaw gateway has no per-run environment carrier");
|
|
43
43
|
const gatewayUrl = requiredOption(req, OPENCLAW_PROVIDER_OPTIONS.url);
|
|
44
|
+
// TODO(P2, #243):按 URL.hostname 判定产物位置,127.0.0.1/localhost/0.0.0.0 为本地;不使用 agentSource。
|
|
44
45
|
const token = requiredOption(req, OPENCLAW_PROVIDER_OPTIONS.token);
|
|
45
46
|
const device = {
|
|
46
47
|
deviceId: requiredOption(req, OPENCLAW_PROVIDER_OPTIONS.deviceId),
|
|
@@ -50,7 +51,14 @@ export function buildOpenClawGatewayInvocation(req) {
|
|
|
50
51
|
const agentId = req.agentConfig.providerAgentId;
|
|
51
52
|
if (!agentId || !/^[a-z0-9_][a-z0-9_-]{0,63}$/.test(agentId))
|
|
52
53
|
throw new Error("OpenClaw provider_agent_id is required");
|
|
53
|
-
const
|
|
54
|
+
const resumedKey = req.providerSession?.sessionId;
|
|
55
|
+
if (resumedKey &&
|
|
56
|
+
(!resumedKey.startsWith(`agent:${agentId}:`) ||
|
|
57
|
+
(req.providerSession?.agentId !== undefined && req.providerSession.agentId !== agentId)))
|
|
58
|
+
throw new Error("OPENCLAW_SESSION_AGENT_MISMATCH: recovery handle belongs to another agent");
|
|
59
|
+
// 名称仅用于展示;原生 key 附独立随机量,同名调用绝不合并,续接只认 opaque handle。
|
|
60
|
+
const sessionKey = resumedKey ??
|
|
61
|
+
`agent:${agentId}:${req.sessionName ? `${encodeURIComponent(req.sessionName)}-` : ""}${randomUUID()}`;
|
|
54
62
|
const requestId = `octo-runtime-${req.runId}-${randomUUID()}`;
|
|
55
63
|
const message = composeOpenClawPrompt(req);
|
|
56
64
|
const timeout = finiteNumber(req.agentConfig.timeoutSeconds);
|
|
@@ -92,7 +100,8 @@ function gatewayMessage(state, channel, nativeId) {
|
|
|
92
100
|
if (!message) {
|
|
93
101
|
message = {
|
|
94
102
|
messageId: nativeId ? `openclaw:${nativeId}` : `openclaw:${channel}:${++state.messageNumber}`,
|
|
95
|
-
|
|
103
|
+
stepId: state.stepId,
|
|
104
|
+
channel: channel === "assistant" ? "commentary" : channel,
|
|
96
105
|
...(channel === "analysis"
|
|
97
106
|
? {
|
|
98
107
|
exposure: "public_reasoning",
|
|
@@ -104,6 +113,212 @@ function gatewayMessage(state, channel, nativeId) {
|
|
|
104
113
|
}
|
|
105
114
|
return message;
|
|
106
115
|
}
|
|
116
|
+
/** Run 内的模型轮独立编号;只有模型输出/原生消息边界才能开始新轮,工具结果不换轮。 */
|
|
117
|
+
function startGatewayStep(state, startedAtMs) {
|
|
118
|
+
if (state.stepStarted && !state.stepFinished)
|
|
119
|
+
return [];
|
|
120
|
+
state.stepId = `openclaw:${state.runId}:round:${++state.stepNumber}`;
|
|
121
|
+
state.stepStarted = true;
|
|
122
|
+
state.stepFinished = false;
|
|
123
|
+
state.stepFinishReason = undefined;
|
|
124
|
+
state.stepHasTools = false;
|
|
125
|
+
state.assistantText = "";
|
|
126
|
+
state.reasoningText = "";
|
|
127
|
+
state.assistantItemId = undefined;
|
|
128
|
+
state.completedAnswerText = undefined;
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
protocolVersion: 2,
|
|
132
|
+
type: "model_step.started",
|
|
133
|
+
payload: {
|
|
134
|
+
stepId: state.stepId,
|
|
135
|
+
...(startedAtMs === undefined ? {} : { startedAtMs })
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
function finishGatewayStep(state, status, finishReason, endedAtMs) {
|
|
141
|
+
if (!state.stepStarted || state.stepFinished)
|
|
142
|
+
return [];
|
|
143
|
+
state.stepFinished = true;
|
|
144
|
+
state.stepFinishReason = finishReason;
|
|
145
|
+
const events = [
|
|
146
|
+
{
|
|
147
|
+
protocolVersion: 2,
|
|
148
|
+
type: "model_step.finished",
|
|
149
|
+
payload: {
|
|
150
|
+
stepId: state.stepId,
|
|
151
|
+
status: canonicalTerminalStatus(status),
|
|
152
|
+
...(finishReason ? { finishReason } : {}),
|
|
153
|
+
...(endedAtMs === undefined ? {} : { endedAtMs })
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
];
|
|
157
|
+
for (const key of [...state.messages.keys()])
|
|
158
|
+
events.push(...closeGatewayMessage(state, key, status));
|
|
159
|
+
return events;
|
|
160
|
+
}
|
|
161
|
+
function rememberGatewayAnswer(state, message, phase) {
|
|
162
|
+
if (typeof message.messageId === "string") {
|
|
163
|
+
if (!state.answers.has(message.messageId) && state.answers.size >= 4096)
|
|
164
|
+
throw new Error("OPENCLAW_STREAM_STATE_EXCEEDED");
|
|
165
|
+
state.answers.set(message.messageId, {
|
|
166
|
+
message,
|
|
167
|
+
text: state.assistantText,
|
|
168
|
+
phase: phase === "commentary" || phase === "final_answer"
|
|
169
|
+
? phase
|
|
170
|
+
: state.answers.get(message.messageId)?.phase
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** 旧 Gateway 缺最终 RPC 正文时只选当前步的最终片段;显式 commentary 永不兜底为 final。 */
|
|
175
|
+
function fallbackGatewayAnswer(state) {
|
|
176
|
+
const answers = [...state.answers.values()].filter((answer) => answer.message.stepId === state.stepId);
|
|
177
|
+
if (answers.some((answer) => answer.phase))
|
|
178
|
+
return answers
|
|
179
|
+
.filter((answer) => answer.phase === "final_answer")
|
|
180
|
+
.map((answer) => answer.text)
|
|
181
|
+
.join("\n");
|
|
182
|
+
return answers.at(-1)?.text ?? "";
|
|
183
|
+
}
|
|
184
|
+
/** 持久消息可能聚合多个已交付过程片段,只把尚属最后一条的正文交给该消息。 */
|
|
185
|
+
function remainingGatewayAnswer(text, earlierAnswers) {
|
|
186
|
+
const prefix = ["\n\n", "\n"]
|
|
187
|
+
.map((separator) => earlierAnswers.join(separator) + separator)
|
|
188
|
+
.find((candidate) => earlierAnswers.length > 0 && text.startsWith(candidate));
|
|
189
|
+
return prefix ? text.slice(prefix.length) : text;
|
|
190
|
+
}
|
|
191
|
+
/** 与原生 assistant phase 对齐:显式区分时,只取 final_answer,不把 commentary 混入最终投递。 */
|
|
192
|
+
function completedGatewayAnswer(message, blocks) {
|
|
193
|
+
const textBlocks = blocks.filter((block) => block.type === "text" && typeof block.text === "string");
|
|
194
|
+
const phases = textBlocks.map((block) => {
|
|
195
|
+
if (typeof block.textSignature !== "string" || !block.textSignature.startsWith("{"))
|
|
196
|
+
return undefined;
|
|
197
|
+
try {
|
|
198
|
+
const signature = asRecord(JSON.parse(block.textSignature));
|
|
199
|
+
return signature?.v === 1 && ["commentary", "final_answer"].includes(String(signature.phase))
|
|
200
|
+
? signature.phase
|
|
201
|
+
: undefined;
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
const explicit = phases.some(Boolean);
|
|
208
|
+
const final = textBlocks.filter((_, index) => (phases[index] ?? (explicit ? undefined : message.phase)) === "final_answer");
|
|
209
|
+
if (final.length)
|
|
210
|
+
return final.map((block) => block.text).join("\n");
|
|
211
|
+
if (explicit || message.phase === "commentary")
|
|
212
|
+
return "";
|
|
213
|
+
return textBlocks.map((block) => block.text).join("\n");
|
|
214
|
+
}
|
|
215
|
+
/** 只处理调用层已核验 session/run 的持久消息;不从 transcript 补发未公开的 reasoning。 */
|
|
216
|
+
function normalizeGatewaySessionMessage(payload, state) {
|
|
217
|
+
const native = asRecord(payload);
|
|
218
|
+
const message = asRecord(native?.message);
|
|
219
|
+
const metadata = asRecord(message?.__openclaw);
|
|
220
|
+
const id = nonEmptyString(native?.messageId) ?? nonEmptyString(metadata?.id);
|
|
221
|
+
if (!id || !message || message.role !== "assistant" || !Array.isArray(message.content))
|
|
222
|
+
return [];
|
|
223
|
+
if (state.completedMessages.has(id))
|
|
224
|
+
return [];
|
|
225
|
+
if (state.completedMessages.size >= 4096)
|
|
226
|
+
throw new Error("OPENCLAW_STREAM_STATE_EXCEEDED");
|
|
227
|
+
state.completedMessages.add(id);
|
|
228
|
+
const blocks = message.content.map(asRecord).filter((b) => !!b);
|
|
229
|
+
const toolBlocks = blocks.filter((b) => b.type === "toolCall" && nonEmptyString(b.id));
|
|
230
|
+
const knownStep = toolBlocks.map((b) => state.tools.get(String(b.id))?.stepId).find(Boolean);
|
|
231
|
+
// 已经通过工具边界换轮后才到达的消息属于旧轮,不能结束当前模型调用或重复创建工具。
|
|
232
|
+
if (knownStep && (knownStep !== state.stepId || state.stepFinished))
|
|
233
|
+
return [];
|
|
234
|
+
const events = startGatewayStep(state, finiteNumber(message.timestamp));
|
|
235
|
+
for (const block of toolBlocks) {
|
|
236
|
+
const toolId = String(block.id);
|
|
237
|
+
if (state.tools.has(toolId))
|
|
238
|
+
continue;
|
|
239
|
+
if (state.tools.size >= 4096)
|
|
240
|
+
throw new Error("OPENCLAW_STREAM_STATE_EXCEEDED");
|
|
241
|
+
state.tools.set(toolId, { stepId: state.stepId, finished: false });
|
|
242
|
+
state.stepHasTools = true;
|
|
243
|
+
events.push({
|
|
244
|
+
protocolVersion: 2,
|
|
245
|
+
type: "tool_call.create",
|
|
246
|
+
payload: {
|
|
247
|
+
id: toolId,
|
|
248
|
+
name: nonEmptyString(block.name) ?? "tool",
|
|
249
|
+
status: "running",
|
|
250
|
+
args: asRecord(block.arguments) ?? {},
|
|
251
|
+
stepId: state.stepId
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
const textBlocks = blocks
|
|
256
|
+
.filter((b) => b.type === "text" && typeof b.text === "string")
|
|
257
|
+
.map((b) => String(b.text));
|
|
258
|
+
const text = textBlocks.join("\n");
|
|
259
|
+
const stepAnswers = [...state.answers.entries()].filter(([, answer]) => answer.message.stepId === state.stepId);
|
|
260
|
+
const alreadyDelivered = ["\n", "\n\n"].some((separator) => text === stepAnswers.map(([, answer]) => answer.text).join(separator));
|
|
261
|
+
if (text && !alreadyDelivered) {
|
|
262
|
+
const corrections = [];
|
|
263
|
+
if (stepAnswers.length > 0 && stepAnswers.length === textBlocks.length) {
|
|
264
|
+
// 原生 text block 和流式 item 保持顺序;每块分别校正,不能把全量正文塞进末块。
|
|
265
|
+
for (const [index, [, answer]] of stepAnswers.entries())
|
|
266
|
+
corrections.push({ message: answer.message, text: textBlocks[index] });
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
const answer = gatewayMessage(state, "assistant");
|
|
270
|
+
const earlierAnswers = stepAnswers
|
|
271
|
+
.filter(([id]) => id !== answer.messageId)
|
|
272
|
+
.map(([, value]) => value.text);
|
|
273
|
+
const nextText = remainingGatewayAnswer(text, earlierAnswers);
|
|
274
|
+
if (earlierAnswers.length && nextText === text) {
|
|
275
|
+
// Provider 合并/拆分 block 且旧前缀也被修正时,以持久正文替换本步片段并清空旧余片。
|
|
276
|
+
const first = stepAnswers[0][1].message;
|
|
277
|
+
corrections.push({ message: first, text });
|
|
278
|
+
for (const [, previous] of stepAnswers.slice(1)) {
|
|
279
|
+
events.push({
|
|
280
|
+
protocolVersion: 2,
|
|
281
|
+
type: "message.update",
|
|
282
|
+
payload: { ...previous.message, text: "", status: "completed" }
|
|
283
|
+
});
|
|
284
|
+
state.answers.delete(String(previous.message.messageId));
|
|
285
|
+
}
|
|
286
|
+
state.messages.set("assistant", first);
|
|
287
|
+
}
|
|
288
|
+
else
|
|
289
|
+
corrections.push({ message: answer, text: nextText });
|
|
290
|
+
}
|
|
291
|
+
for (const correction of corrections) {
|
|
292
|
+
if (state.answers.get(String(correction.message.messageId))?.text !== correction.text)
|
|
293
|
+
events.push({
|
|
294
|
+
protocolVersion: 2,
|
|
295
|
+
type: "message.update",
|
|
296
|
+
payload: {
|
|
297
|
+
...correction.message,
|
|
298
|
+
text: correction.text,
|
|
299
|
+
role: "assistant",
|
|
300
|
+
status: "completed"
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
state.assistantText = correction.text;
|
|
304
|
+
rememberGatewayAnswer(state, correction.message);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const reason = nonEmptyString(message.stopReason);
|
|
308
|
+
const finishReason = reason === "toolUse" || reason === "tool_use" ? "tool-calls" : reason;
|
|
309
|
+
if (finishReason === "tool-calls")
|
|
310
|
+
state.stepHasTools = true;
|
|
311
|
+
const status = ["error", "failed", "aborted", "cancelled"].includes(reason ?? "")
|
|
312
|
+
? "failed"
|
|
313
|
+
: "completed";
|
|
314
|
+
state.completedAnswerText =
|
|
315
|
+
status === "completed" && finishReason !== "tool-calls" && finishReason !== "length"
|
|
316
|
+
? completedGatewayAnswer(message, blocks)
|
|
317
|
+
: "";
|
|
318
|
+
const endedAtMs = finiteNumber(metadata?.recordTimestampMs);
|
|
319
|
+
events.push(...finishGatewayStep(state, status, finishReason, endedAtMs));
|
|
320
|
+
return events;
|
|
321
|
+
}
|
|
107
322
|
function closeGatewayMessage(state, key, status = "completed") {
|
|
108
323
|
const message = state.messages.get(key);
|
|
109
324
|
if (!message)
|
|
@@ -154,54 +369,54 @@ function normalizeGatewayAgentEvent(payload, state) {
|
|
|
154
369
|
return [];
|
|
155
370
|
state.lastSeq = seq;
|
|
156
371
|
const events = [];
|
|
157
|
-
|
|
158
|
-
const ensureStep = () => {
|
|
159
|
-
if (state.stepStarted)
|
|
160
|
-
return;
|
|
161
|
-
state.stepStarted = true;
|
|
162
|
-
events.push({ protocolVersion: 2, type: "model_step.started", payload: { stepId } });
|
|
163
|
-
};
|
|
372
|
+
state.runId = nonEmptyString(native.runId) ?? state.runId;
|
|
164
373
|
if (stream === "lifecycle") {
|
|
165
374
|
const phase = nonEmptyString(data.phase);
|
|
166
375
|
const terminal = gatewayTerminal(data, "lifecycle");
|
|
167
|
-
if (phase === "start")
|
|
168
|
-
|
|
376
|
+
if (phase === "start" && !state.stepStarted)
|
|
377
|
+
events.push(...startGatewayStep(state, finiteNumber(data.startedAt)));
|
|
169
378
|
if ((phase === "end" || phase === "error") &&
|
|
170
379
|
terminal &&
|
|
171
380
|
state.stepStarted &&
|
|
172
381
|
!state.stepFinished) {
|
|
173
|
-
state.stepFinished = true;
|
|
174
382
|
const finishReason = nonEmptyString(data.stopReason);
|
|
175
|
-
events.push(
|
|
176
|
-
protocolVersion: 2,
|
|
177
|
-
type: "model_step.finished",
|
|
178
|
-
payload: {
|
|
179
|
-
stepId,
|
|
180
|
-
status: canonicalTerminalStatus(terminal),
|
|
181
|
-
...(finishReason ? { finishReason } : {})
|
|
182
|
-
}
|
|
183
|
-
});
|
|
383
|
+
events.push(...finishGatewayStep(state, terminal, finishReason, finiteNumber(data.endedAt)));
|
|
184
384
|
}
|
|
185
385
|
return events;
|
|
186
386
|
}
|
|
187
|
-
|
|
387
|
+
const modelOutput = stream === "assistant" ||
|
|
388
|
+
stream === "thinking" ||
|
|
389
|
+
(stream === "item" && data.kind === "preamble");
|
|
390
|
+
// 持久 stop 通知后可能再次 flush 同一份 assistant 快照;它不是新模型调用。
|
|
391
|
+
if (stream === "assistant" &&
|
|
392
|
+
state.stepFinished &&
|
|
393
|
+
state.stepFinishReason === "stop" &&
|
|
394
|
+
(data.text === state.assistantText || data.text === state.completedAnswerText))
|
|
395
|
+
return events;
|
|
396
|
+
if (modelOutput) {
|
|
397
|
+
// 旧 Gateway 没有可关联的持久消息时,以工具批次后下一次模型输出确认新调用。
|
|
398
|
+
if (state.stepHasTools && !state.stepFinished)
|
|
399
|
+
events.push(...finishGatewayStep(state, "completed", "tool-calls"));
|
|
400
|
+
events.push(...startGatewayStep(state, finiteNumber(native.ts)));
|
|
401
|
+
}
|
|
188
402
|
if (stream === "assistant" && typeof data.text === "string") {
|
|
189
403
|
events.push(...closeGatewayMessage(state, "analysis"));
|
|
190
404
|
state.reasoningText = "";
|
|
191
405
|
const nativeId = nonEmptyString(data.itemId);
|
|
192
406
|
if (nativeId && nativeId !== state.assistantItemId) {
|
|
193
|
-
events.push(...closeGatewayMessage(state, "
|
|
407
|
+
events.push(...closeGatewayMessage(state, "assistant"));
|
|
194
408
|
state.assistantText = "";
|
|
195
409
|
state.assistantItemId = nativeId;
|
|
196
410
|
}
|
|
197
|
-
const message = gatewayMessage(state, "
|
|
411
|
+
const message = gatewayMessage(state, "assistant", nativeId);
|
|
198
412
|
const change = snapshotDelta(state.assistantText, data.text);
|
|
199
413
|
state.assistantText = data.text;
|
|
414
|
+
rememberGatewayAnswer(state, message, data.phase);
|
|
200
415
|
if (change.delta)
|
|
201
416
|
events.push({
|
|
202
417
|
protocolVersion: 2,
|
|
203
418
|
type: "message.delta",
|
|
204
|
-
payload: { ...message, text: change.delta
|
|
419
|
+
payload: { ...message, text: change.delta }
|
|
205
420
|
});
|
|
206
421
|
if (change.replacement !== undefined) {
|
|
207
422
|
events.push({
|
|
@@ -212,7 +427,7 @@ function normalizeGatewayAgentEvent(payload, state) {
|
|
|
212
427
|
role: "assistant",
|
|
213
428
|
status: "streaming",
|
|
214
429
|
text: change.replacement,
|
|
215
|
-
channel: "
|
|
430
|
+
channel: "commentary"
|
|
216
431
|
}
|
|
217
432
|
});
|
|
218
433
|
}
|
|
@@ -252,10 +467,18 @@ function normalizeGatewayAgentEvent(payload, state) {
|
|
|
252
467
|
const id = nonEmptyString(data.toolCallId);
|
|
253
468
|
if (!id)
|
|
254
469
|
return events;
|
|
470
|
+
let tool = state.tools.get(id);
|
|
255
471
|
if (phase === "start") {
|
|
256
|
-
if (
|
|
472
|
+
if (tool)
|
|
257
473
|
return events;
|
|
258
|
-
|
|
474
|
+
// 7.1 的 toolUse 持久消息可能只含正文;随后才广播的工具仍属于刚结束的模型调用。
|
|
475
|
+
if (!state.stepFinished || state.stepFinishReason !== "tool-calls")
|
|
476
|
+
events.push(...startGatewayStep(state));
|
|
477
|
+
tool = { stepId: state.stepId, finished: false };
|
|
478
|
+
if (state.tools.size >= 4096)
|
|
479
|
+
throw new Error("OPENCLAW_STREAM_STATE_EXCEEDED");
|
|
480
|
+
state.tools.set(id, tool);
|
|
481
|
+
state.stepHasTools = true;
|
|
259
482
|
events.push(...closeGatewayMessage(state, "analysis"));
|
|
260
483
|
state.reasoningText = "";
|
|
261
484
|
events.push({
|
|
@@ -264,29 +487,42 @@ function normalizeGatewayAgentEvent(payload, state) {
|
|
|
264
487
|
payload: {
|
|
265
488
|
status: "running",
|
|
266
489
|
id,
|
|
490
|
+
stepId: tool.stepId,
|
|
267
491
|
name: nonEmptyString(data.name) ?? "tool",
|
|
268
492
|
args: asRecord(data.args) ?? {}
|
|
269
493
|
}
|
|
270
494
|
});
|
|
271
495
|
}
|
|
272
496
|
else if (phase === "update") {
|
|
497
|
+
if (!tool || tool.finished)
|
|
498
|
+
return events;
|
|
499
|
+
const argsDelta = typeof data.argsDelta === "string" ? data.argsDelta : undefined;
|
|
500
|
+
const output = data.result ?? data.partialResult;
|
|
273
501
|
events.push({
|
|
274
502
|
protocolVersion: 2,
|
|
275
503
|
type: "tool_call.delta",
|
|
276
504
|
payload: {
|
|
277
505
|
id,
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
506
|
+
stepId: tool.stepId,
|
|
507
|
+
...(argsDelta === undefined ? {} : { argsDelta }),
|
|
508
|
+
...(output === undefined && argsDelta !== undefined
|
|
509
|
+
? {}
|
|
510
|
+
: {
|
|
511
|
+
outputSnapshot: typeof output === "string" ? output : JSON.stringify(output ?? "")
|
|
512
|
+
})
|
|
281
513
|
}
|
|
282
514
|
});
|
|
283
515
|
}
|
|
284
516
|
else if (phase === "result") {
|
|
517
|
+
if (!tool || tool.finished)
|
|
518
|
+
return events;
|
|
519
|
+
tool.finished = true;
|
|
285
520
|
events.push({
|
|
286
521
|
protocolVersion: 2,
|
|
287
522
|
type: "tool_call.update",
|
|
288
523
|
payload: {
|
|
289
524
|
id,
|
|
525
|
+
stepId: tool.stepId,
|
|
290
526
|
...(nonEmptyString(data.name) ? { name: data.name } : {}),
|
|
291
527
|
status: canonicalTerminalStatus(data.isError === true ? "error" : "completed"),
|
|
292
528
|
output: data.result
|
|
@@ -294,6 +530,40 @@ function normalizeGatewayAgentEvent(payload, state) {
|
|
|
294
530
|
});
|
|
295
531
|
}
|
|
296
532
|
}
|
|
533
|
+
else if (stream === "command_output") {
|
|
534
|
+
const id = nonEmptyString(data.toolCallId);
|
|
535
|
+
const tool = id ? state.tools.get(id) : undefined;
|
|
536
|
+
// command_output 是已有工具的输出快照,不是模型思考,也不能单独创建模型轮次。
|
|
537
|
+
if (!id || !tool)
|
|
538
|
+
return events;
|
|
539
|
+
if (data.phase === "delta" && typeof data.output === "string" && !tool.finished)
|
|
540
|
+
events.push({
|
|
541
|
+
protocolVersion: 2,
|
|
542
|
+
type: "tool_call.delta",
|
|
543
|
+
payload: {
|
|
544
|
+
id,
|
|
545
|
+
stepId: tool.stepId,
|
|
546
|
+
outputSnapshot: data.output
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
if (data.phase === "end") {
|
|
550
|
+
tool.finished = true;
|
|
551
|
+
const exitCode = finiteNumber(data.exitCode);
|
|
552
|
+
const durationMs = finiteNumber(data.durationMs);
|
|
553
|
+
events.push({
|
|
554
|
+
protocolVersion: 2,
|
|
555
|
+
type: "tool_call.update",
|
|
556
|
+
payload: {
|
|
557
|
+
id,
|
|
558
|
+
stepId: tool.stepId,
|
|
559
|
+
status: canonicalTerminalStatus(data.status),
|
|
560
|
+
...(typeof data.output === "string" ? { output: data.output } : {}),
|
|
561
|
+
...(exitCode === undefined ? {} : { exitCode }),
|
|
562
|
+
...(durationMs === undefined ? {} : { durationMs })
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
}
|
|
297
567
|
else if (stream === "item" &&
|
|
298
568
|
data.kind === "preamble" &&
|
|
299
569
|
typeof data.progressText === "string") {
|
|
@@ -308,6 +578,8 @@ function normalizeGatewayAgentEvent(payload, state) {
|
|
|
308
578
|
status: data.phase === "end" ? "completed" : "streaming"
|
|
309
579
|
}
|
|
310
580
|
});
|
|
581
|
+
if (data.phase === "end")
|
|
582
|
+
state.messages.delete(`commentary:${nativeId ?? "preamble"}`);
|
|
311
583
|
}
|
|
312
584
|
else if (stream === "usage") {
|
|
313
585
|
const event = usageEvent(data);
|
|
@@ -353,46 +625,28 @@ function normalizeFinalResponse(value, state, runId) {
|
|
|
353
625
|
const meta = asRecord(result?.meta);
|
|
354
626
|
const agentMeta = asRecord(meta?.agentMeta);
|
|
355
627
|
const events = [];
|
|
356
|
-
|
|
357
|
-
const payloads = Array.isArray(result?.payloads) ? result.payloads : [];
|
|
358
|
-
|
|
359
|
-
|
|
628
|
+
state.runId = runId;
|
|
629
|
+
const payloads = Array.isArray(result?.payloads) ? result.payloads.map(asRecord) : [];
|
|
630
|
+
// 原生 finalTextFromResult 的选择合同:不把过程、reasoning 或错误 payload 投进 IM finalMsg。
|
|
631
|
+
const selected = payloads
|
|
632
|
+
.filter((item) => item && item.isReasoning !== true && item.isCommentary !== true && item.isError !== true)
|
|
633
|
+
.map((item) => nonEmptyString(item?.text)?.trimEnd() ?? "")
|
|
360
634
|
.filter(Boolean)
|
|
361
635
|
.join("\n");
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
636
|
+
// 7.1 的 payload 投影会丢失 reasoning 标记;原生最终可见正文比未标记的列表更权威。
|
|
637
|
+
const metadataText = !payloads.some((item) => item?.isError === true) &&
|
|
638
|
+
typeof meta?.finalAssistantVisibleText === "string"
|
|
639
|
+
? meta.finalAssistantVisibleText.trimEnd()
|
|
640
|
+
: undefined;
|
|
641
|
+
const finalText = metadataText ?? selected;
|
|
642
|
+
if (Array.isArray(result?.payloads) || typeof meta?.finalAssistantVisibleText === "string")
|
|
643
|
+
state.finalAnswerText = finalText;
|
|
644
|
+
const needsNextStep = state.stepFinished &&
|
|
645
|
+
(state.stepHasTools || ["length", "error", "failed"].includes(state.stepFinishReason ?? ""));
|
|
372
646
|
if (finalText) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
state.assistantText = finalText;
|
|
377
|
-
if (change.delta)
|
|
378
|
-
events.push({
|
|
379
|
-
protocolVersion: 2,
|
|
380
|
-
type: "message.delta",
|
|
381
|
-
payload: { ...message, text: change.delta, channel: "final" }
|
|
382
|
-
});
|
|
383
|
-
if (change.replacement !== undefined) {
|
|
384
|
-
events.push({
|
|
385
|
-
protocolVersion: 2,
|
|
386
|
-
type: "message.update",
|
|
387
|
-
payload: {
|
|
388
|
-
...message,
|
|
389
|
-
role: "assistant",
|
|
390
|
-
status: "streaming",
|
|
391
|
-
text: change.replacement,
|
|
392
|
-
channel: "final"
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
}
|
|
647
|
+
// 工具/length 后模型可能不公开任何流式输出,最终正文仍证明发生了下一次模型调用。
|
|
648
|
+
if (!state.stepStarted || needsNextStep)
|
|
649
|
+
events.push(...startGatewayStep(state));
|
|
396
650
|
}
|
|
397
651
|
const usage = asRecord(agentMeta?.usage);
|
|
398
652
|
const usageUpdate = usageEvent({
|
|
@@ -405,19 +659,9 @@ function normalizeFinalResponse(value, state, runId) {
|
|
|
405
659
|
events.push(usageUpdate);
|
|
406
660
|
const terminal = gatewayTerminal(response, "final");
|
|
407
661
|
if (terminal && !state.stepFinished) {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
events.push(
|
|
411
|
-
protocolVersion: 2,
|
|
412
|
-
type: "model_step.finished",
|
|
413
|
-
payload: {
|
|
414
|
-
stepId,
|
|
415
|
-
status: canonicalTerminalStatus(terminal === "cancelled" ? "cancelled" : terminal === "failed" ? "failed" : "completed"),
|
|
416
|
-
...(nonEmptyString(meta?.stopReason)
|
|
417
|
-
? { finishReason: nonEmptyString(meta?.stopReason) }
|
|
418
|
-
: {})
|
|
419
|
-
}
|
|
420
|
-
});
|
|
662
|
+
if (!state.stepStarted)
|
|
663
|
+
events.push(...startGatewayStep(state));
|
|
664
|
+
events.push(...finishGatewayStep(state, terminal, nonEmptyString(meta?.stopReason)));
|
|
421
665
|
}
|
|
422
666
|
return {
|
|
423
667
|
events,
|
|
@@ -519,6 +763,7 @@ async function* invokeOpenClawGateway(req, invocation, context, clientFactory, p
|
|
|
519
763
|
const activeApprovals = new Map();
|
|
520
764
|
let providerSessionKey = invocation.sessionKey;
|
|
521
765
|
const routedApprovals = new Set();
|
|
766
|
+
const staleApprovals = new Set();
|
|
522
767
|
const acceptEvent = (event) => {
|
|
523
768
|
if (closing || terminal)
|
|
524
769
|
return;
|
|
@@ -528,19 +773,50 @@ async function* invokeOpenClawGateway(req, invocation, context, clientFactory, p
|
|
|
528
773
|
if (runId !== acceptedRunId && runId !== invocation.requestId)
|
|
529
774
|
return;
|
|
530
775
|
}
|
|
776
|
+
else if (event.event === "session.message") {
|
|
777
|
+
if (!agentDispatched || payload?.sessionKey !== providerSessionKey)
|
|
778
|
+
return;
|
|
779
|
+
if (payload.agentId !== undefined && payload.agentId !== invocation.agentId)
|
|
780
|
+
return;
|
|
781
|
+
const message = asRecord(payload.message);
|
|
782
|
+
if (message?.role !== "assistant")
|
|
783
|
+
return;
|
|
784
|
+
const topRunId = nonEmptyString(payload.runId);
|
|
785
|
+
const messageRunId = nonEmptyString(asRecord(message.__openclaw)?.runId);
|
|
786
|
+
const ids = [topRunId, messageRunId].filter((id) => !!id);
|
|
787
|
+
// 中间消息的 runId 在原生 __openclaw 元数据内;任何显式身份冲突都拒绝。
|
|
788
|
+
// 续聊不得按到达时间认领无 runId 的旧消息;fresh 的随机独占 key 没有历史消息。
|
|
789
|
+
if (ids.some((id) => id !== acceptedRunId && id !== invocation.requestId))
|
|
790
|
+
return;
|
|
791
|
+
if (!ids.length && req.providerSession?.sessionId)
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
531
794
|
else if (event.event === "exec.approval.requested") {
|
|
532
795
|
const request = asRecord(payload?.request);
|
|
533
796
|
const id = nonEmptyString(payload?.id);
|
|
534
|
-
if (!id ||
|
|
797
|
+
if (!id ||
|
|
798
|
+
routedApprovals.has(id) ||
|
|
799
|
+
staleApprovals.has(id) ||
|
|
800
|
+
request?.sessionKey !== providerSessionKey)
|
|
535
801
|
return;
|
|
536
802
|
if (request.runId &&
|
|
537
803
|
request.runId !== acceptedRunId &&
|
|
538
804
|
request.runId !== invocation.requestId)
|
|
539
805
|
return;
|
|
540
|
-
if (routedApprovals.size >= 1024) {
|
|
806
|
+
if (routedApprovals.size + staleApprovals.size >= 1024) {
|
|
541
807
|
queue.fail(new Error("APPROVAL_WAIT_UNAVAILABLE"));
|
|
542
808
|
return;
|
|
543
809
|
}
|
|
810
|
+
// 派发前的无 runId 审批属于旧轮次;记住 ID,避免稍后重播时串入本轮。
|
|
811
|
+
if (!request.runId && !agentDispatched) {
|
|
812
|
+
staleApprovals.add(id);
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
// 共享旧 session 时,到达时间不能证明轮次;无 runId 则停止本轮,不回答未知归属的审批。
|
|
816
|
+
if (!request.runId && req.providerSession?.sessionId) {
|
|
817
|
+
queue.fail(new Error("OPENCLAW_APPROVAL_RUN_UNVERIFIED: resumed session approval has no runId; turn ownership cannot be verified"));
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
544
820
|
routedApprovals.add(id);
|
|
545
821
|
}
|
|
546
822
|
else if (event.event === "exec.approval.resolved") {
|
|
@@ -558,36 +834,41 @@ async function* invokeOpenClawGateway(req, invocation, context, clientFactory, p
|
|
|
558
834
|
req.signal?.addEventListener("abort", onAbort, { once: true });
|
|
559
835
|
const state = {
|
|
560
836
|
lastSeq: -1,
|
|
837
|
+
runId: invocation.requestId,
|
|
838
|
+
stepNumber: 0,
|
|
839
|
+
stepHasTools: false,
|
|
561
840
|
assistantText: "",
|
|
562
841
|
reasoningText: "",
|
|
563
842
|
stepStarted: false,
|
|
564
843
|
stepFinished: false,
|
|
565
844
|
messageNumber: 0,
|
|
566
845
|
messages: new Map(),
|
|
567
|
-
tools: new
|
|
846
|
+
tools: new Map(),
|
|
847
|
+
completedMessages: new Set(),
|
|
848
|
+
answers: new Map()
|
|
568
849
|
};
|
|
569
850
|
// 原生终态和步骤收尾共用出口;旧等待失败不能覆盖已确认的结果或丢失步骤结束。
|
|
570
851
|
const terminalEvents = (outcome, message) => {
|
|
571
852
|
const events = [];
|
|
572
|
-
|
|
573
|
-
|
|
853
|
+
events.push(...finishGatewayStep(state, outcome));
|
|
854
|
+
const processOnly = state.stepHasTools || ["length", "error", "failed"].includes(state.stepFinishReason ?? "");
|
|
855
|
+
const finalText = state.finalAnswerText ??
|
|
856
|
+
(processOnly ? "" : (state.completedAnswerText ?? fallbackGatewayAnswer(state)));
|
|
857
|
+
// final 通道只有这一份已选定的回答;IM 按 messageId 聚合时不会再拼进过程正文。
|
|
858
|
+
// TODO(P2, #243):成功 final 的远端文件引用由 Adapter 协调转换为可读取 HTTPS;不读本机同名路径、不代发 IM。
|
|
859
|
+
if (outcome === "completed" && finalText)
|
|
574
860
|
events.push({
|
|
575
861
|
protocolVersion: 2,
|
|
576
|
-
type: "
|
|
577
|
-
payload: {
|
|
862
|
+
type: "message.update",
|
|
863
|
+
payload: {
|
|
864
|
+
messageId: `openclaw:${state.runId}:final-answer`,
|
|
865
|
+
stepId: state.stepId,
|
|
866
|
+
role: "assistant",
|
|
867
|
+
status: "completed",
|
|
868
|
+
text: finalText,
|
|
869
|
+
channel: "final"
|
|
870
|
+
}
|
|
578
871
|
});
|
|
579
|
-
}
|
|
580
|
-
events.push({
|
|
581
|
-
protocolVersion: 2,
|
|
582
|
-
type: "message.update",
|
|
583
|
-
payload: {
|
|
584
|
-
...gatewayMessage(state, "final", state.assistantItemId),
|
|
585
|
-
role: "assistant",
|
|
586
|
-
status: outcome === "cancelled" ? "stopped" : outcome,
|
|
587
|
-
text: state.assistantText,
|
|
588
|
-
channel: "final"
|
|
589
|
-
}
|
|
590
|
-
});
|
|
591
872
|
if (outcome === "cancelled")
|
|
592
873
|
events.push({
|
|
593
874
|
protocolVersion: 2,
|
|
@@ -631,26 +912,43 @@ async function* invokeOpenClawGateway(req, invocation, context, clientFactory, p
|
|
|
631
912
|
}
|
|
632
913
|
};
|
|
633
914
|
await assertExistingAgent(client, invocation.agentId, req.signal);
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
915
|
+
if (req.providerSession?.sessionId) {
|
|
916
|
+
// describe 是实际 Gateway 广告的只读查询;缺失时不能让 patch/agent 隐式建会话。
|
|
917
|
+
for (const method of ["sessions.describe", "sessions.patch"]) {
|
|
918
|
+
if (!contract.methods.includes(method))
|
|
919
|
+
throw new Error(`OPENCLAW_COMPATIBILITY_UNSUPPORTED: missing required method ${method}`);
|
|
920
|
+
}
|
|
921
|
+
const described = asRecord(await client.request("sessions.describe", { key: providerSessionKey }, { timeoutMs: 10_000, signal: req.signal }));
|
|
922
|
+
const resolved = asRecord(described?.session);
|
|
923
|
+
if (!resolved)
|
|
924
|
+
throw new Error("OPENCLAW_SESSION_NOT_FOUND: requested native session is unavailable");
|
|
925
|
+
if (resolved.key !== providerSessionKey ||
|
|
926
|
+
(resolved.agentId !== undefined && resolved.agentId !== invocation.agentId))
|
|
927
|
+
throw new Error("OPENCLAW_SESSION_AGENT_MISMATCH: resolved session does not match handle");
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
930
|
+
const created = asRecord(await client.request("sessions.create", createParams, {
|
|
931
|
+
timeoutMs: 30_000,
|
|
646
932
|
signal: req.signal
|
|
647
933
|
}));
|
|
934
|
+
const createdKey = nonEmptyString(created?.key);
|
|
935
|
+
if (!createdKey || !createdKey.startsWith(`agent:${invocation.agentId}:`))
|
|
936
|
+
throw new Error("OpenClaw Gateway returned no valid created session key");
|
|
937
|
+
providerSessionKey = createdKey;
|
|
938
|
+
}
|
|
939
|
+
invocation.agentParams.sessionKey = providerSessionKey;
|
|
940
|
+
if (contract.family === "legacy" || req.providerSession?.sessionId) {
|
|
941
|
+
const permissionMode = policy.effective === "full_access" ? "full" : "guarded";
|
|
942
|
+
const patched = asRecord(await client.request("sessions.patch", contract.family === "legacy"
|
|
943
|
+
? gatewayLegacyPermissionParams(providerSessionKey)
|
|
944
|
+
: { key: providerSessionKey, agentId: invocation.agentId, permissionMode }, { timeoutMs: 10_000, signal: req.signal }));
|
|
648
945
|
const entry = asRecord(patched?.entry);
|
|
649
946
|
if (patched?.ok !== true ||
|
|
650
947
|
patched.key !== providerSessionKey ||
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
948
|
+
(contract.family === "legacy"
|
|
949
|
+
? entry?.execSecurity !== "full" || entry.execAsk !== "off"
|
|
950
|
+
: entry?.permissionMode !== permissionMode)) {
|
|
951
|
+
throw new Error("OPENCLAW_PERMISSION_UNAVAILABLE: session policy was not confirmed");
|
|
654
952
|
}
|
|
655
953
|
}
|
|
656
954
|
await client.request("sessions.messages.subscribe", {
|
|
@@ -670,7 +968,8 @@ async function* invokeOpenClawGateway(req, invocation, context, clientFactory, p
|
|
|
670
968
|
payload: {
|
|
671
969
|
providerSession: {
|
|
672
970
|
sessionId: providerSessionKey,
|
|
673
|
-
resumable:
|
|
971
|
+
resumable: true,
|
|
972
|
+
...(req.providerSession?.sessionId ? { resumeOutcome: "resumed" } : {}),
|
|
674
973
|
agentId: invocation.agentId
|
|
675
974
|
}
|
|
676
975
|
}
|
|
@@ -710,25 +1009,9 @@ async function* invokeOpenClawGateway(req, invocation, context, clientFactory, p
|
|
|
710
1009
|
if (resourceFailure)
|
|
711
1010
|
throw resourceFailure;
|
|
712
1011
|
terminal ??= confirmed;
|
|
713
|
-
if (!state.
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
yield {
|
|
717
|
-
protocolVersion: 2,
|
|
718
|
-
type: "model_step.started",
|
|
719
|
-
payload: { stepId: state.stepId }
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
state.stepFinished = true;
|
|
723
|
-
yield {
|
|
724
|
-
protocolVersion: 2,
|
|
725
|
-
type: "model_step.finished",
|
|
726
|
-
payload: {
|
|
727
|
-
stepId: state.stepId,
|
|
728
|
-
status: canonicalTerminalStatus(terminal)
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
}
|
|
1012
|
+
if (!state.stepStarted)
|
|
1013
|
+
yield* startGatewayStep(state);
|
|
1014
|
+
yield* finishGatewayStep(state, terminal);
|
|
732
1015
|
}
|
|
733
1016
|
if (terminal === "failed")
|
|
734
1017
|
throw new Error(reconciled.error ?? "OpenClaw Gateway agent run failed");
|
|
@@ -820,6 +1103,10 @@ async function* invokeOpenClawGateway(req, invocation, context, clientFactory, p
|
|
|
820
1103
|
});
|
|
821
1104
|
continue;
|
|
822
1105
|
}
|
|
1106
|
+
if (item.event?.event === "session.message") {
|
|
1107
|
+
yield* normalizeGatewaySessionMessage(item.event.payload, state);
|
|
1108
|
+
continue;
|
|
1109
|
+
}
|
|
823
1110
|
if (!item.event || item.event.event !== "agent")
|
|
824
1111
|
continue;
|
|
825
1112
|
const native = asRecord(item.event.payload);
|