@a1hvdy/cc-openclaw 0.8.0 → 0.9.1
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/dist/scripts/bench/ab-harness.d.ts +58 -0
- package/dist/scripts/bench/ab-harness.d.ts.map +1 -0
- package/dist/scripts/bench/ab-harness.js +78 -0
- package/dist/scripts/bench/ab-harness.js.map +1 -0
- package/dist/src/channels/adapter.d.ts.map +1 -0
- package/dist/src/channels/telegram/completion-summary.d.ts.map +1 -0
- package/dist/src/channels/telegram/error-renderer.d.ts.map +1 -0
- package/dist/src/channels/telegram/event-reducer.d.ts.map +1 -0
- package/dist/src/channels/telegram/index.d.ts.map +1 -0
- package/dist/src/channels/telegram/injector.d.ts.map +1 -0
- package/dist/src/channels/telegram/live-card.d.ts.map +1 -0
- package/dist/src/channels/telegram/state-machine.d.ts.map +1 -0
- package/dist/src/channels/telegram/tool-tracker.d.ts.map +1 -0
- package/dist/src/command-router/cc-handler.d.ts.map +1 -0
- package/dist/src/command-router/index.d.ts.map +1 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/council/consensus.d.ts.map +1 -0
- package/dist/src/council/council.d.ts.map +1 -0
- package/dist/src/council/index.d.ts.map +1 -0
- package/dist/src/engines/base-oneshot-session.d.ts.map +1 -0
- package/dist/src/engines/index.d.ts.map +1 -0
- package/dist/src/engines/persistent-codex-session.d.ts.map +1 -0
- package/dist/src/engines/persistent-cursor-session.d.ts.map +1 -0
- package/dist/src/engines/persistent-custom-session.d.ts.map +1 -0
- package/dist/src/engines/persistent-gemini-session.d.ts.map +1 -0
- package/dist/src/engines/persistent-session.d.ts.map +1 -0
- package/dist/src/health/handler.d.ts.map +1 -0
- package/dist/src/health/index.d.ts.map +1 -0
- package/dist/src/index.d.ts +10 -1
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +47 -7
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/auto-recovery.d.ts.map +1 -0
- package/dist/src/lib/cache-parity.d.ts.map +1 -0
- package/dist/src/lib/circuit-breaker.d.ts.map +1 -0
- package/dist/src/lib/config-service.d.ts +106 -0
- package/dist/src/lib/config-service.js +217 -0
- package/dist/src/lib/config-service.js.map +1 -0
- package/dist/src/lib/config.d.ts +33 -14
- package/dist/src/lib/config.d.ts.map +1 -0
- package/dist/src/lib/config.js +147 -34
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/debug-tap.d.ts.map +1 -0
- package/dist/src/lib/drift-detector.d.ts.map +1 -0
- package/dist/src/lib/error-formatter.d.ts.map +1 -0
- package/dist/src/lib/heartbeat-workaround.d.ts.map +1 -0
- package/dist/src/lib/index.d.ts +1 -1
- package/dist/src/lib/index.d.ts.map +1 -0
- package/dist/src/lib/index.js +4 -1
- package/dist/src/lib/index.js.map +1 -1
- package/dist/src/lib/register-guard.d.ts.map +1 -0
- package/dist/src/lib/req-shape-log.d.ts +31 -0
- package/dist/src/lib/req-shape-log.js +106 -0
- package/dist/src/lib/req-shape-log.js.map +1 -0
- package/dist/src/lib/route-flag.d.ts.map +1 -0
- package/dist/src/lib/sysprompt-strip.d.ts.map +1 -0
- package/dist/src/lib/telemetry.d.ts.map +1 -0
- package/dist/src/lib/test-mode.d.ts.map +1 -0
- package/dist/src/lib/vendor-paths.d.ts.map +1 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/mcp/bridge.d.ts.map +1 -0
- package/dist/src/mcp/index.d.ts.map +1 -0
- package/dist/src/models.d.ts.map +1 -0
- package/dist/src/openai-compat/cli-stream-parser.d.ts.map +1 -0
- package/dist/src/openai-compat/index.d.ts.map +1 -0
- package/dist/src/openai-compat/message-extractor.d.ts +79 -0
- package/dist/src/openai-compat/message-extractor.js +162 -0
- package/dist/src/openai-compat/message-extractor.js.map +1 -0
- package/dist/src/openai-compat/mode-flags.d.ts +34 -0
- package/dist/src/openai-compat/mode-flags.js +44 -0
- package/dist/src/openai-compat/mode-flags.js.map +1 -0
- package/dist/src/openai-compat/non-streaming-handler.d.ts +26 -0
- package/dist/src/openai-compat/non-streaming-handler.js +108 -0
- package/dist/src/openai-compat/non-streaming-handler.js.map +1 -0
- package/dist/src/openai-compat/openai-compat.d.ts +15 -166
- package/dist/src/openai-compat/openai-compat.d.ts.map +1 -0
- package/dist/src/openai-compat/openai-compat.js +65 -849
- package/dist/src/openai-compat/openai-compat.js.map +1 -1
- package/dist/src/openai-compat/prompts.d.ts +47 -0
- package/dist/src/openai-compat/prompts.js +119 -0
- package/dist/src/openai-compat/prompts.js.map +1 -0
- package/dist/src/openai-compat/response-formatter.d.ts +33 -0
- package/dist/src/openai-compat/response-formatter.js +74 -0
- package/dist/src/openai-compat/response-formatter.js.map +1 -0
- package/dist/src/openai-compat/session-key-resolver.d.ts +41 -0
- package/dist/src/openai-compat/session-key-resolver.js +78 -0
- package/dist/src/openai-compat/session-key-resolver.js.map +1 -0
- package/dist/src/openai-compat/skill-resolver.d.ts.map +1 -0
- package/dist/src/openai-compat/sse-translator.d.ts.map +1 -0
- package/dist/src/openai-compat/status-reporter.d.ts +30 -0
- package/dist/src/openai-compat/status-reporter.js +81 -0
- package/dist/src/openai-compat/status-reporter.js.map +1 -0
- package/dist/src/openai-compat/streaming-handler.d.ts +41 -0
- package/dist/src/openai-compat/streaming-handler.js +294 -0
- package/dist/src/openai-compat/streaming-handler.js.map +1 -0
- package/dist/src/openai-compat/tool-calls-parser.d.ts +34 -0
- package/dist/src/openai-compat/tool-calls-parser.js +93 -0
- package/dist/src/openai-compat/tool-calls-parser.js.map +1 -0
- package/dist/src/openai-compat/tool-results-serializer.d.ts +60 -0
- package/dist/src/openai-compat/tool-results-serializer.js +56 -0
- package/dist/src/openai-compat/tool-results-serializer.js.map +1 -0
- package/dist/src/proxy/anthropic-adapter.d.ts.map +1 -0
- package/dist/src/proxy/handler.d.ts.map +1 -0
- package/dist/src/proxy/index.d.ts.map +1 -0
- package/dist/src/proxy/schema-cleaner.d.ts.map +1 -0
- package/dist/src/proxy/thought-cache.d.ts.map +1 -0
- package/dist/src/session/embedded-server.d.ts.map +1 -0
- package/dist/src/session/inbox-manager.d.ts.map +1 -0
- package/dist/src/session/index.d.ts.map +1 -0
- package/dist/src/session/session-manager.d.ts.map +1 -0
- package/dist/src/session-bootstrap/cwd-patch.d.ts.map +1 -0
- package/dist/src/session-bootstrap/cwd-patch.js +20 -13
- package/dist/src/session-bootstrap/cwd-patch.js.map +1 -1
- package/dist/src/session-bootstrap/index.d.ts.map +1 -0
- package/dist/src/session-bootstrap/sysprompt-strip.d.ts.map +1 -0
- package/dist/src/session-bootstrap/think-conflict-resolver.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +15 -0
- package/dist/src/types/index.js +16 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/route.d.ts +41 -0
- package/dist/src/types/route.js +12 -0
- package/dist/src/types/route.js.map +1 -0
- package/dist/src/types/runtime-config.d.ts +161 -0
- package/dist/src/types/runtime-config.js +118 -0
- package/dist/src/types/runtime-config.js.map +1 -0
- package/dist/src/types/session.d.ts +48 -0
- package/dist/src/types/session.js +20 -0
- package/dist/src/types/session.js.map +1 -0
- package/dist/src/types/sse.d.ts +38 -0
- package/dist/src/types/sse.js +12 -0
- package/dist/src/types/sse.js.map +1 -0
- package/dist/src/types/tool-bridge.d.ts +81 -0
- package/dist/src/types/tool-bridge.js +34 -0
- package/dist/src/types/tool-bridge.js.map +1 -0
- package/dist/src/types/upstream.d.ts +652 -0
- package/dist/src/types/upstream.js +145 -0
- package/dist/src/types/upstream.js.map +1 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/validation.d.ts.map +1 -0
- package/dist/tests/_helpers/subprocess-mock.d.ts +35 -0
- package/dist/tests/_helpers/subprocess-mock.d.ts.map +1 -0
- package/dist/tests/_helpers/subprocess-mock.js +136 -0
- package/dist/tests/_helpers/subprocess-mock.js.map +1 -0
- package/dist/tests/auto-recovery.test.d.ts +2 -0
- package/dist/tests/auto-recovery.test.d.ts.map +1 -0
- package/dist/tests/auto-recovery.test.js +189 -0
- package/dist/tests/auto-recovery.test.js.map +1 -0
- package/dist/tests/bench-harness.test.d.ts +2 -0
- package/dist/tests/bench-harness.test.d.ts.map +1 -0
- package/dist/tests/bench-harness.test.js +21 -0
- package/dist/tests/bench-harness.test.js.map +1 -0
- package/dist/tests/cache-parity.test.d.ts +2 -0
- package/dist/tests/cache-parity.test.d.ts.map +1 -0
- package/dist/tests/cache-parity.test.js +401 -0
- package/dist/tests/cache-parity.test.js.map +1 -0
- package/dist/tests/command-router.test.d.ts +2 -0
- package/dist/tests/command-router.test.d.ts.map +1 -0
- package/dist/tests/command-router.test.js +60 -0
- package/dist/tests/command-router.test.js.map +1 -0
- package/dist/tests/council.test.d.ts +2 -0
- package/dist/tests/council.test.d.ts.map +1 -0
- package/dist/tests/council.test.js +20 -0
- package/dist/tests/council.test.js.map +1 -0
- package/dist/tests/drift-detector.test.d.ts +2 -0
- package/dist/tests/drift-detector.test.d.ts.map +1 -0
- package/dist/tests/drift-detector.test.js +268 -0
- package/dist/tests/drift-detector.test.js.map +1 -0
- package/dist/tests/eager-bootstrap-gating.test.d.ts +9 -0
- package/dist/tests/eager-bootstrap-gating.test.d.ts.map +1 -0
- package/dist/tests/eager-bootstrap-gating.test.js +97 -0
- package/dist/tests/eager-bootstrap-gating.test.js.map +1 -0
- package/dist/tests/engines.test.d.ts +2 -0
- package/dist/tests/engines.test.d.ts.map +1 -0
- package/dist/tests/engines.test.js +8 -0
- package/dist/tests/engines.test.js.map +1 -0
- package/dist/tests/error-formatter.test.d.ts +2 -0
- package/dist/tests/error-formatter.test.d.ts.map +1 -0
- package/dist/tests/error-formatter.test.js +220 -0
- package/dist/tests/error-formatter.test.js.map +1 -0
- package/dist/tests/health.test.d.ts +2 -0
- package/dist/tests/health.test.d.ts.map +1 -0
- package/dist/tests/health.test.js +110 -0
- package/dist/tests/health.test.js.map +1 -0
- package/dist/tests/heartbeat-workaround.test.d.ts +2 -0
- package/dist/tests/heartbeat-workaround.test.d.ts.map +1 -0
- package/dist/tests/heartbeat-workaround.test.js +90 -0
- package/dist/tests/heartbeat-workaround.test.js.map +1 -0
- package/dist/tests/index.test.d.ts +2 -0
- package/dist/tests/index.test.d.ts.map +1 -0
- package/dist/tests/index.test.js +7 -0
- package/dist/tests/index.test.js.map +1 -0
- package/dist/tests/lib-sysprompt-strip.test.d.ts +2 -0
- package/dist/tests/lib-sysprompt-strip.test.d.ts.map +1 -0
- package/dist/tests/lib-sysprompt-strip.test.js +145 -0
- package/dist/tests/lib-sysprompt-strip.test.js.map +1 -0
- package/dist/tests/listener-activation.test.d.ts +2 -0
- package/dist/tests/listener-activation.test.d.ts.map +1 -0
- package/dist/tests/listener-activation.test.js +87 -0
- package/dist/tests/listener-activation.test.js.map +1 -0
- package/dist/tests/mcp-bridge.test.d.ts +2 -0
- package/dist/tests/mcp-bridge.test.d.ts.map +1 -0
- package/dist/tests/mcp-bridge.test.js +137 -0
- package/dist/tests/mcp-bridge.test.js.map +1 -0
- package/dist/tests/openai-compat.test.d.ts +2 -0
- package/dist/tests/openai-compat.test.d.ts.map +1 -0
- package/dist/tests/openai-compat.test.js +8 -0
- package/dist/tests/openai-compat.test.js.map +1 -0
- package/dist/tests/proxy-heartbeat-integration.test.d.ts +15 -0
- package/dist/tests/proxy-heartbeat-integration.test.d.ts.map +1 -0
- package/dist/tests/proxy-heartbeat-integration.test.js +122 -0
- package/dist/tests/proxy-heartbeat-integration.test.js.map +1 -0
- package/dist/tests/proxy.test.d.ts +2 -0
- package/dist/tests/proxy.test.d.ts.map +1 -0
- package/dist/tests/proxy.test.js +8 -0
- package/dist/tests/proxy.test.js.map +1 -0
- package/dist/tests/register-guard-stacking.test.d.ts +2 -0
- package/dist/tests/register-guard-stacking.test.d.ts.map +1 -0
- package/dist/tests/register-guard-stacking.test.js +61 -0
- package/dist/tests/register-guard-stacking.test.js.map +1 -0
- package/dist/tests/register-guard.test.d.ts +2 -0
- package/dist/tests/register-guard.test.d.ts.map +1 -0
- package/dist/tests/register-guard.test.js +129 -0
- package/dist/tests/register-guard.test.js.map +1 -0
- package/dist/tests/route-flag-rollback.test.d.ts +2 -0
- package/dist/tests/route-flag-rollback.test.d.ts.map +1 -0
- package/dist/tests/route-flag-rollback.test.js +70 -0
- package/dist/tests/route-flag-rollback.test.js.map +1 -0
- package/dist/tests/route-flag.test.d.ts +2 -0
- package/dist/tests/route-flag.test.d.ts.map +1 -0
- package/dist/tests/route-flag.test.js +101 -0
- package/dist/tests/route-flag.test.js.map +1 -0
- package/dist/tests/session-bootstrap.test.d.ts +2 -0
- package/dist/tests/session-bootstrap.test.d.ts.map +1 -0
- package/dist/tests/session-bootstrap.test.js +183 -0
- package/dist/tests/session-bootstrap.test.js.map +1 -0
- package/dist/tests/session.test.d.ts +2 -0
- package/dist/tests/session.test.d.ts.map +1 -0
- package/dist/tests/session.test.js +17 -0
- package/dist/tests/session.test.js.map +1 -0
- package/dist/tests/state-machine.test.d.ts +2 -0
- package/dist/tests/state-machine.test.d.ts.map +1 -0
- package/dist/tests/state-machine.test.js +133 -0
- package/dist/tests/state-machine.test.js.map +1 -0
- package/dist/tests/streaming/cli-stream-parser.test.d.ts +2 -0
- package/dist/tests/streaming/cli-stream-parser.test.d.ts.map +1 -0
- package/dist/tests/streaming/cli-stream-parser.test.js +233 -0
- package/dist/tests/streaming/cli-stream-parser.test.js.map +1 -0
- package/dist/tests/streaming/feature-flag.test.d.ts +14 -0
- package/dist/tests/streaming/feature-flag.test.d.ts.map +1 -0
- package/dist/tests/streaming/feature-flag.test.js +163 -0
- package/dist/tests/streaming/feature-flag.test.js.map +1 -0
- package/dist/tests/streaming/no-tools-prompt.test.d.ts +17 -0
- package/dist/tests/streaming/no-tools-prompt.test.d.ts.map +1 -0
- package/dist/tests/streaming/no-tools-prompt.test.js +229 -0
- package/dist/tests/streaming/no-tools-prompt.test.js.map +1 -0
- package/dist/tests/streaming/skill-plus-tools.test.d.ts +14 -0
- package/dist/tests/streaming/skill-plus-tools.test.d.ts.map +1 -0
- package/dist/tests/streaming/skill-plus-tools.test.js +234 -0
- package/dist/tests/streaming/skill-plus-tools.test.js.map +1 -0
- package/dist/tests/streaming/sse-translator.test.d.ts +2 -0
- package/dist/tests/streaming/sse-translator.test.d.ts.map +1 -0
- package/dist/tests/streaming/sse-translator.test.js +227 -0
- package/dist/tests/streaming/sse-translator.test.js.map +1 -0
- package/dist/tests/streaming/tool-result-roundtrip.test.d.ts +11 -0
- package/dist/tests/streaming/tool-result-roundtrip.test.d.ts.map +1 -0
- package/dist/tests/streaming/tool-result-roundtrip.test.js +215 -0
- package/dist/tests/streaming/tool-result-roundtrip.test.js.map +1 -0
- package/dist/tests/streaming/tool-use-translation.test.d.ts +10 -0
- package/dist/tests/streaming/tool-use-translation.test.d.ts.map +1 -0
- package/dist/tests/streaming/tool-use-translation.test.js +251 -0
- package/dist/tests/streaming/tool-use-translation.test.js.map +1 -0
- package/dist/tests/telegram-bridge.test.d.ts +2 -0
- package/dist/tests/telegram-bridge.test.d.ts.map +1 -0
- package/dist/tests/telegram-bridge.test.js +17 -0
- package/dist/tests/telegram-bridge.test.js.map +1 -0
- package/dist/tests/telegram-injector.test.d.ts +2 -0
- package/dist/tests/telegram-injector.test.d.ts.map +1 -0
- package/dist/tests/telegram-injector.test.js +74 -0
- package/dist/tests/telegram-injector.test.js.map +1 -0
- package/dist/tests/telemetry.test.d.ts +2 -0
- package/dist/tests/telemetry.test.d.ts.map +1 -0
- package/dist/tests/telemetry.test.js +405 -0
- package/dist/tests/telemetry.test.js.map +1 -0
- package/dist/tests/test-mode.test.d.ts +2 -0
- package/dist/tests/test-mode.test.d.ts.map +1 -0
- package/dist/tests/test-mode.test.js +39 -0
- package/dist/tests/test-mode.test.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-flag.d.ts","sourceRoot":"","sources":["../../../src/lib/route-flag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,MAAM,MAAM,GAAG,aAAa,GAAG,cAAc,CAAC;AAEpD,yCAAyC;AACzC,eAAO,MAAM,eAAe,gCAAgC,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,cAAc,6BAA6B,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAK7C;AAED,mEAAmE;AACnE,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,mBAAmB,IAAI,YAAY,CAKlD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sysprompt-strip.d.ts","sourceRoot":"","sources":["../../../src/lib/sysprompt-strip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,WAAW,YAAY;IAC3B,sFAAsF;IACtF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,yDAAyD;IACzD,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,kFAAkF;IAClF,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,GAAE,YAAiB,GAAG,OAAO,CAK/D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,WAAW,CA+BpF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../../src/lib/telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAcH,eAA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aAAa,8BAA8B,CAAC;AAEzD,wBAAgB,UAAU,IAAI,OAAO,CAKpC;AAED,gEAAgE;AAChE,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAGtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vendor-paths.d.ts","sourceRoot":"","sources":["../../../src/lib/vendor-paths.ts"],"names":[],"mappings":"AAmBA,0DAA0D;AAC1D,eAAO,MAAM,YAAY,QAAoC,CAAC;AAE9D,wCAAwC;AACxC,eAAO,MAAM,UAAU,QAA+B,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,YAAY;;;;CAIf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC7C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC5C,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAC9C;AAUD,qFAAqF;AACrF,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAoB3D;AAED,yDAAyD;AACzD,eAAO,MAAM,UAAU,EAAE,MAKxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../../src/mcp/bridge.ts"],"names":[],"mappings":"AAqCA,MAAM,WAAW,SAAS;IACxB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,IAAI,CAAC;IAClE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAA+C;IAE5D,KAAK,IAAI,IAAI;IAOb,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAUrB,SAAS,IAAI,OAAO;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAaxF;AAGD,wBAAgB,wBAAwB,IAAI,IAAI,CAAmE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5E,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI7C,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnF,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,iDAAiD;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,8BAA8B;IAC9B,MAAM,EAAE,UAAU,CAAC;IACnB,wCAAwC;IACxC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,MAAM,GAAG,WAAW,EAAE,CAAC;IACnC,kFAAkF;IAClF,KAAK,IAAI,WAAW,EAAE,CAAC;CACxB;AAED,wBAAgB,qBAAqB,IAAI,eAAe,CA0KvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/openai-compat/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cluster B — Message extractor.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `openai-compat.ts:177-301` (Phase 4 Cluster B
|
|
5
|
+
* Module D). Single function that converts an OpenAI `messages[]` array
|
|
6
|
+
* into the inputs Claude CLI's bridge expects:
|
|
7
|
+
*
|
|
8
|
+
* - systemPrompt — joined `role:system` content, undefined if none
|
|
9
|
+
* - userMessage — last user message (with skill-inline applied)
|
|
10
|
+
* OR XML-wrapped tool-result block when the
|
|
11
|
+
* last non-system message is `role:tool`
|
|
12
|
+
* - userMessageBlocks — tool-stream mode only: native Anthropic
|
|
13
|
+
* content blocks (tool_result + text) for the
|
|
14
|
+
* stream-json input path
|
|
15
|
+
* - isNewConversation — drives session-create vs session-append
|
|
16
|
+
*
|
|
17
|
+
* Single call site in the orchestrator (handleChatCompletion line 482).
|
|
18
|
+
* The two types `UserMessageBlock` and `ExtractedMessage` are also re-
|
|
19
|
+
* exported from openai-compat.ts for callers across the orchestrator
|
|
20
|
+
* (formatCompletionResponse + helpers all consume them as parameters).
|
|
21
|
+
*
|
|
22
|
+
* Session-reset semantics:
|
|
23
|
+
* - X-Session-Reset: 1|true → always treated as new conversation
|
|
24
|
+
* - OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1 (env) → legacy
|
|
25
|
+
* "system + single user ⇒ new conversation" rule, opt-in for
|
|
26
|
+
* callers that re-send the full transcript every turn
|
|
27
|
+
* - Default (env unset) → only the explicit header creates a new
|
|
28
|
+
* conversation; persistent CLI sessions survive across turns and
|
|
29
|
+
* benefit from Anthropic prompt caching (PR #40)
|
|
30
|
+
*/
|
|
31
|
+
import type { OpenAIChatMessage } from './openai-compat.js';
|
|
32
|
+
import { type AnthropicToolResultBlock } from './tool-results-serializer.js';
|
|
33
|
+
/**
|
|
34
|
+
* Phase 2 R4 wire-up: optional structured content for tool-stream mode.
|
|
35
|
+
* When set, consumers should send this array to the subprocess instead of
|
|
36
|
+
* the legacy XML-wrapped `userMessage` string. Each element is either a
|
|
37
|
+
* native Anthropic `tool_result` block (for prior tool outputs) or a
|
|
38
|
+
* `text` block (for the user's follow-up message).
|
|
39
|
+
*/
|
|
40
|
+
export type UserMessageBlock = AnthropicToolResultBlock | {
|
|
41
|
+
type: 'text';
|
|
42
|
+
text: string;
|
|
43
|
+
};
|
|
44
|
+
export interface ExtractedMessage {
|
|
45
|
+
systemPrompt: string | undefined;
|
|
46
|
+
userMessage: string;
|
|
47
|
+
/**
|
|
48
|
+
* Populated only in tool-stream mode when the last non-system message
|
|
49
|
+
* is a tool-role result. Carries native Anthropic tool_result blocks
|
|
50
|
+
* + optional follow-up text. When undefined, consumers fall back to
|
|
51
|
+
* the string `userMessage` (legacy XML-wrapped path).
|
|
52
|
+
*/
|
|
53
|
+
userMessageBlocks?: UserMessageBlock[];
|
|
54
|
+
isNewConversation: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Extract the relevant parts from an OpenAI messages array.
|
|
58
|
+
*
|
|
59
|
+
* Sessions are stateful — we only need the last user message. The tricky
|
|
60
|
+
* question is whether to start a fresh session or append to the existing one.
|
|
61
|
+
*
|
|
62
|
+
* Default mode (no env var): only honor an explicit `X-Session-Reset: 1`
|
|
63
|
+
* header. This is correct for clients that maintain their own conversation
|
|
64
|
+
* transcript and forward only the latest user turn (OpenClaw main agent
|
|
65
|
+
* loop, cron jobs, subagents). The previous heuristic
|
|
66
|
+
* (`nonSystemMessages.length <= 1`) fired on every such request, killing the
|
|
67
|
+
* persistent CLI every turn and preventing Anthropic prompt caching from
|
|
68
|
+
* ever warming. Originally diagnosed in PR #40 by @megayounus786.
|
|
69
|
+
*
|
|
70
|
+
* Legacy mode (`OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1`): restore the old
|
|
71
|
+
* `system + single user ⇒ new conversation` rule, for clients that re-send
|
|
72
|
+
* the full transcript on every turn (ChatGPT-Next-Web, Open WebUI, data
|
|
73
|
+
* labeling tools, etc). They use the transcript shape itself as their only
|
|
74
|
+
* "start a new conversation" signal.
|
|
75
|
+
*
|
|
76
|
+
* The env var is read on every call so ops can flip it via launchctl setenv
|
|
77
|
+
* without restarting the server.
|
|
78
|
+
*/
|
|
79
|
+
export declare function extractUserMessage(messages: OpenAIChatMessage[], headers?: Record<string, string | string[] | undefined>): ExtractedMessage;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cluster B — Message extractor.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `openai-compat.ts:177-301` (Phase 4 Cluster B
|
|
5
|
+
* Module D). Single function that converts an OpenAI `messages[]` array
|
|
6
|
+
* into the inputs Claude CLI's bridge expects:
|
|
7
|
+
*
|
|
8
|
+
* - systemPrompt — joined `role:system` content, undefined if none
|
|
9
|
+
* - userMessage — last user message (with skill-inline applied)
|
|
10
|
+
* OR XML-wrapped tool-result block when the
|
|
11
|
+
* last non-system message is `role:tool`
|
|
12
|
+
* - userMessageBlocks — tool-stream mode only: native Anthropic
|
|
13
|
+
* content blocks (tool_result + text) for the
|
|
14
|
+
* stream-json input path
|
|
15
|
+
* - isNewConversation — drives session-create vs session-append
|
|
16
|
+
*
|
|
17
|
+
* Single call site in the orchestrator (handleChatCompletion line 482).
|
|
18
|
+
* The two types `UserMessageBlock` and `ExtractedMessage` are also re-
|
|
19
|
+
* exported from openai-compat.ts for callers across the orchestrator
|
|
20
|
+
* (formatCompletionResponse + helpers all consume them as parameters).
|
|
21
|
+
*
|
|
22
|
+
* Session-reset semantics:
|
|
23
|
+
* - X-Session-Reset: 1|true → always treated as new conversation
|
|
24
|
+
* - OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1 (env) → legacy
|
|
25
|
+
* "system + single user ⇒ new conversation" rule, opt-in for
|
|
26
|
+
* callers that re-send the full transcript every turn
|
|
27
|
+
* - Default (env unset) → only the explicit header creates a new
|
|
28
|
+
* conversation; persistent CLI sessions survive across turns and
|
|
29
|
+
* benefit from Anthropic prompt caching (PR #40)
|
|
30
|
+
*/
|
|
31
|
+
import { serializeToolResults, serializeToolResultsAsBlocks, } from './tool-results-serializer.js';
|
|
32
|
+
import { isToolStreamMode } from './mode-flags.js';
|
|
33
|
+
import { maybeInlineSkill } from './skill-resolver.js';
|
|
34
|
+
import { isOpenaiCompatNewConvoHeuristic } from '../lib/config.js';
|
|
35
|
+
/**
|
|
36
|
+
* Extract the relevant parts from an OpenAI messages array.
|
|
37
|
+
*
|
|
38
|
+
* Sessions are stateful — we only need the last user message. The tricky
|
|
39
|
+
* question is whether to start a fresh session or append to the existing one.
|
|
40
|
+
*
|
|
41
|
+
* Default mode (no env var): only honor an explicit `X-Session-Reset: 1`
|
|
42
|
+
* header. This is correct for clients that maintain their own conversation
|
|
43
|
+
* transcript and forward only the latest user turn (OpenClaw main agent
|
|
44
|
+
* loop, cron jobs, subagents). The previous heuristic
|
|
45
|
+
* (`nonSystemMessages.length <= 1`) fired on every such request, killing the
|
|
46
|
+
* persistent CLI every turn and preventing Anthropic prompt caching from
|
|
47
|
+
* ever warming. Originally diagnosed in PR #40 by @megayounus786.
|
|
48
|
+
*
|
|
49
|
+
* Legacy mode (`OPENAI_COMPAT_NEW_CONVO_HEURISTIC=1`): restore the old
|
|
50
|
+
* `system + single user ⇒ new conversation` rule, for clients that re-send
|
|
51
|
+
* the full transcript on every turn (ChatGPT-Next-Web, Open WebUI, data
|
|
52
|
+
* labeling tools, etc). They use the transcript shape itself as their only
|
|
53
|
+
* "start a new conversation" signal.
|
|
54
|
+
*
|
|
55
|
+
* The env var is read on every call so ops can flip it via launchctl setenv
|
|
56
|
+
* without restarting the server.
|
|
57
|
+
*/
|
|
58
|
+
export function extractUserMessage(messages, headers) {
|
|
59
|
+
if (!messages || messages.length === 0) {
|
|
60
|
+
throw new Error('messages array is empty');
|
|
61
|
+
}
|
|
62
|
+
// Normalize content from any message: OpenAI API allows content as a string
|
|
63
|
+
// OR an array of content parts (e.g. multimodal messages with text + images).
|
|
64
|
+
// We need a string for the CLI, so arrays are joined.
|
|
65
|
+
const textOf = (m) => {
|
|
66
|
+
if (typeof m.content === 'string')
|
|
67
|
+
return m.content;
|
|
68
|
+
if (Array.isArray(m.content)) {
|
|
69
|
+
return m.content
|
|
70
|
+
.map((p) => p.text || '')
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.join('');
|
|
73
|
+
}
|
|
74
|
+
return m.content != null ? String(m.content) : '';
|
|
75
|
+
};
|
|
76
|
+
// Extract system prompt if present
|
|
77
|
+
const systemMessages = messages.filter((m) => m.role === 'system');
|
|
78
|
+
const systemPrompt = systemMessages.length > 0 ? systemMessages.map(textOf).join('\n') : undefined;
|
|
79
|
+
// Pick the actual user message — skipping OpenClaw upstream's
|
|
80
|
+
// `<system>...</system>` transport wrappers. OpenClaw stuffs the full
|
|
81
|
+
// system context (Lossless Recall + USER.md + TOOLS.md + runtime info)
|
|
82
|
+
// into user-role messages because its plugin SDK doesn't use the
|
|
83
|
+
// role:system slot. Without this filter, `extractUserMessage` would
|
|
84
|
+
// pick the 33K-char system blob as the "current turn" instead of the
|
|
85
|
+
// user's actual text earlier in the array.
|
|
86
|
+
//
|
|
87
|
+
// Diagnosed 2026-05-11 from sysprompt + usermsg dumps: a /new turn
|
|
88
|
+
// arrived as 3 user messages — the user's text in msg 1+2 (duplicate)
|
|
89
|
+
// and the system wrapper in msg 3. Model interpreted the wrapper's
|
|
90
|
+
// stray "continue" from USER.md as the user's input.
|
|
91
|
+
const isOpenClawSystemWrap = (text) => text.startsWith('<system>') && text.includes('</system>');
|
|
92
|
+
/** From `userMessages`, pick the most recent message that is NOT an
|
|
93
|
+
* OpenClaw system-context wrapper. Falls back to the last message
|
|
94
|
+
* when all candidates are wrappers (preserves pre-fix behavior for
|
|
95
|
+
* callers that don't trigger the OpenClaw pattern). */
|
|
96
|
+
const pickActualUserText = (userMessages) => {
|
|
97
|
+
if (userMessages.length === 0)
|
|
98
|
+
return '';
|
|
99
|
+
for (let i = userMessages.length - 1; i >= 0; i--) {
|
|
100
|
+
const t = textOf(userMessages[i]);
|
|
101
|
+
if (!isOpenClawSystemWrap(t))
|
|
102
|
+
return t;
|
|
103
|
+
}
|
|
104
|
+
return textOf(userMessages[userMessages.length - 1]);
|
|
105
|
+
};
|
|
106
|
+
// Handle tool result messages — only when the LAST non-system message is
|
|
107
|
+
// a tool role (meaning we're in an active tool-use cycle). If the last
|
|
108
|
+
// message is a user role, it's a follow-up in an existing conversation
|
|
109
|
+
// and the old tool results are already in the CLI's history.
|
|
110
|
+
const lastNonSystem = [...messages].reverse().find((m) => m.role !== 'system');
|
|
111
|
+
if (lastNonSystem?.role === 'tool') {
|
|
112
|
+
const userMessages = messages.filter((m) => m.role === 'user');
|
|
113
|
+
const lastUserText = pickActualUserText(userMessages);
|
|
114
|
+
// Phase 2 R4 wire-up: in tool-stream mode, emit native Anthropic
|
|
115
|
+
// tool_result blocks instead of XML-wrapped text. Claude CLI's
|
|
116
|
+
// stream-json input accepts content arrays directly.
|
|
117
|
+
if (isToolStreamMode()) {
|
|
118
|
+
const toolBlocks = serializeToolResultsAsBlocks(messages);
|
|
119
|
+
const userMessageBlocks = [...toolBlocks];
|
|
120
|
+
if (lastUserText) {
|
|
121
|
+
userMessageBlocks.push({ type: 'text', text: lastUserText });
|
|
122
|
+
}
|
|
123
|
+
// Keep userMessage populated as the legacy XML form for callers
|
|
124
|
+
// that don't yet handle the structured path. Both fields agree in
|
|
125
|
+
// intent; consumers should prefer userMessageBlocks when present.
|
|
126
|
+
const fallback = serializeToolResults(messages);
|
|
127
|
+
const userMessage = lastUserText ? `${fallback}\n\n${lastUserText}` : fallback;
|
|
128
|
+
return { systemPrompt, userMessage, userMessageBlocks, isNewConversation: false };
|
|
129
|
+
}
|
|
130
|
+
const toolResultBlock = serializeToolResults(messages);
|
|
131
|
+
const userMessage = lastUserText ? `${toolResultBlock}\n\n${lastUserText}` : toolResultBlock;
|
|
132
|
+
return { systemPrompt, userMessage, isNewConversation: false };
|
|
133
|
+
}
|
|
134
|
+
// Find last user message — using the OpenClaw-aware picker to skip
|
|
135
|
+
// `<system>...</system>` transport wrappers.
|
|
136
|
+
const userMessages = messages.filter((m) => m.role === 'user');
|
|
137
|
+
if (userMessages.length === 0) {
|
|
138
|
+
throw new Error('No user message found in messages array');
|
|
139
|
+
}
|
|
140
|
+
const rawUserMessage = pickActualUserText(userMessages);
|
|
141
|
+
// Workspace skill auto-inline: if the last user message is /<skill> [args]
|
|
142
|
+
// and ~/.openclaw/workspace/skills/*/SKILL.md has a matching `name:` in
|
|
143
|
+
// frontmatter, replace the user message with the SKILL.md body so the
|
|
144
|
+
// model has full skill context without needing the Read tool (cc-openclaw
|
|
145
|
+
// disables built-in tools by design — see the `sessionConfig.tools = ''`
|
|
146
|
+
// line below).
|
|
147
|
+
const userMessage = maybeInlineSkill(rawUserMessage) ?? rawUserMessage;
|
|
148
|
+
// 1. Explicit reset header — honored in both modes. Normalize trim+lowercase
|
|
149
|
+
// so callers using `TRUE`, ` 1 `, etc. don't silently fail.
|
|
150
|
+
const rawReset = headers?.['x-session-reset'];
|
|
151
|
+
const resetHeader = typeof rawReset === 'string' ? rawReset.trim().toLowerCase() : '';
|
|
152
|
+
if (resetHeader === 'true' || resetHeader === '1') {
|
|
153
|
+
return { systemPrompt, userMessage, isNewConversation: true };
|
|
154
|
+
}
|
|
155
|
+
// 2. Legacy heuristic — only when explicitly opted in via env var.
|
|
156
|
+
if (isOpenaiCompatNewConvoHeuristic()) {
|
|
157
|
+
const nonSystemMessages = messages.filter((m) => m.role !== 'system');
|
|
158
|
+
return { systemPrompt, userMessage, isNewConversation: nonSystemMessages.length <= 1 };
|
|
159
|
+
}
|
|
160
|
+
return { systemPrompt, userMessage, isNewConversation: false };
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=message-extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-extractor.js","sourceRoot":"","sources":["../../../src/openai-compat/message-extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EACL,oBAAoB,EACpB,4BAA4B,GAE7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAC;AA0BnE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA6B,EAC7B,OAAuD;IAEvD,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,4EAA4E;IAC5E,8EAA8E;IAC9E,sDAAsD;IACtD,MAAM,MAAM,GAAG,CAAC,CAAoB,EAAU,EAAE;QAC9C,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ;YAAE,OAAO,CAAC,CAAC,OAAO,CAAC;QACpD,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7B,OAAQ,CAAC,CAAC,OAAmD;iBAC1D,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;iBACxB,MAAM,CAAC,OAAO,CAAC;iBACf,IAAI,CAAC,EAAE,CAAC,CAAC;QAC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OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IACzF,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cluster B beachhead — tool-mode flag predicates.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `openai-compat.ts` so that `session-key-resolver.ts`
|
|
5
|
+
* (and future Cluster B modules) can read these flags without creating
|
|
6
|
+
* a circular import back into the orchestrator.
|
|
7
|
+
*
|
|
8
|
+
* Behavior preserved bit-for-bit from the original definitions in
|
|
9
|
+
* `openai-compat.ts:126-142`. openai-compat.ts re-exports both
|
|
10
|
+
* functions for any external caller that previously imported them
|
|
11
|
+
* from there (none exist today, but the re-export is cheap insurance).
|
|
12
|
+
*
|
|
13
|
+
* Cluster B follow-on will fold these into the `IToolBridge` strategy
|
|
14
|
+
* pattern (PRP §5 Cluster B `bridges/factory.ts`); for now they
|
|
15
|
+
* remain free-function predicates.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Legacy mode: when set, tool definitions are prepended to every user
|
|
19
|
+
* message instead of being baked into the session system prompt. Defeats
|
|
20
|
+
* prompt caching but allows mutating the tool list mid-session.
|
|
21
|
+
*
|
|
22
|
+
* Truthy values: '1', 'true', 'yes' (case-insensitive, trimmed).
|
|
23
|
+
*/
|
|
24
|
+
export declare function isToolsPerMessageModeEnabled(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Phase 2 R5: tool-stream mode flag. When `CC_OPENCLAW_TOOL_STREAM=1`
|
|
27
|
+
* AND the caller provides `tools[]`, cc-openclaw skips the defensive
|
|
28
|
+
* "no tools" system prompt and does NOT clear `sessionConfig.tools`,
|
|
29
|
+
* allowing Claude CLI's native tool_use events to flow through the
|
|
30
|
+
* parser+translator pipeline.
|
|
31
|
+
*
|
|
32
|
+
* Strict opt-in: only true when env value is exactly `'1'`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isToolStreamMode(): boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cluster B beachhead — tool-mode flag predicates.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `openai-compat.ts` so that `session-key-resolver.ts`
|
|
5
|
+
* (and future Cluster B modules) can read these flags without creating
|
|
6
|
+
* a circular import back into the orchestrator.
|
|
7
|
+
*
|
|
8
|
+
* Behavior preserved bit-for-bit from the original definitions in
|
|
9
|
+
* `openai-compat.ts:126-142`. openai-compat.ts re-exports both
|
|
10
|
+
* functions for any external caller that previously imported them
|
|
11
|
+
* from there (none exist today, but the re-export is cheap insurance).
|
|
12
|
+
*
|
|
13
|
+
* Cluster B follow-on will fold these into the `IToolBridge` strategy
|
|
14
|
+
* pattern (PRP §5 Cluster B `bridges/factory.ts`); for now they
|
|
15
|
+
* remain free-function predicates.
|
|
16
|
+
*/
|
|
17
|
+
import { getOpenaiCompatToolsPerMessage } from '../lib/config.js';
|
|
18
|
+
/**
|
|
19
|
+
* Legacy mode: when set, tool definitions are prepended to every user
|
|
20
|
+
* message instead of being baked into the session system prompt. Defeats
|
|
21
|
+
* prompt caching but allows mutating the tool list mid-session.
|
|
22
|
+
*
|
|
23
|
+
* Truthy values: '1', 'true', 'yes' (case-insensitive, trimmed).
|
|
24
|
+
*/
|
|
25
|
+
export function isToolsPerMessageModeEnabled() {
|
|
26
|
+
const v = getOpenaiCompatToolsPerMessage();
|
|
27
|
+
if (!v)
|
|
28
|
+
return false;
|
|
29
|
+
const t = v.trim().toLowerCase();
|
|
30
|
+
return t === '1' || t === 'true' || t === 'yes';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Phase 2 R5: tool-stream mode flag. When `CC_OPENCLAW_TOOL_STREAM=1`
|
|
34
|
+
* AND the caller provides `tools[]`, cc-openclaw skips the defensive
|
|
35
|
+
* "no tools" system prompt and does NOT clear `sessionConfig.tools`,
|
|
36
|
+
* allowing Claude CLI's native tool_use events to flow through the
|
|
37
|
+
* parser+translator pipeline.
|
|
38
|
+
*
|
|
39
|
+
* Strict opt-in: only true when env value is exactly `'1'`.
|
|
40
|
+
*/
|
|
41
|
+
export function isToolStreamMode() {
|
|
42
|
+
return process.env.CC_OPENCLAW_TOOL_STREAM === '1';
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=mode-flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mode-flags.js","sourceRoot":"","sources":["../../../src/openai-compat/mode-flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,UAAU,4BAA4B;IAC1C,MAAM,CAAC,GAAG,8BAA8B,EAAE,CAAC;IAC3C,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrB,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACjC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,KAAK,CAAC;AAClD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,GAAG,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cluster B Phase 2 — Non-streaming HTTP handler.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `openai-compat.ts:508-615` (Module G).
|
|
5
|
+
* Handles the response path when the caller did NOT request `stream:true` —
|
|
6
|
+
* a single buffered Claude CLI session call, then one JSON object back to
|
|
7
|
+
* the client.
|
|
8
|
+
*
|
|
9
|
+
* Lifecycle:
|
|
10
|
+
* 1. reportStatus('thinking') → SessionManager.sendMessage(...)
|
|
11
|
+
* 2. On each tool_use event → push a status update + emit trajectory
|
|
12
|
+
* 3. On each tool_result event → emit trajectory only (no status)
|
|
13
|
+
* 4. v0.7.1: accumulate thinking-block content when surfaceThinking is on
|
|
14
|
+
* 5. On completion → read token stats, format response, write back
|
|
15
|
+
* 6. On error → reportStatus('idle','Request failed') + 500 with
|
|
16
|
+
* structured `formatError` telemetry
|
|
17
|
+
*
|
|
18
|
+
* Parameterized fully — no closure capture from openai-compat.ts. All
|
|
19
|
+
* dependencies are imported from their dedicated Cluster B modules
|
|
20
|
+
* (response-formatter, tool-calls-parser, status-reporter,
|
|
21
|
+
* message-extractor for types) or from lib/.
|
|
22
|
+
*/
|
|
23
|
+
import type * as http from 'node:http';
|
|
24
|
+
import type { SessionManagerLike } from './openai-compat.js';
|
|
25
|
+
import type { UserMessageBlock } from './message-extractor.js';
|
|
26
|
+
export declare function handleNonStreaming(manager: SessionManagerLike, sessionName: string, model: string, userMessage: string | UserMessageBlock[], completionId: string, res: http.ServerResponse, hasTools: boolean): Promise<void>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cluster B Phase 2 — Non-streaming HTTP handler.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `openai-compat.ts:508-615` (Module G).
|
|
5
|
+
* Handles the response path when the caller did NOT request `stream:true` —
|
|
6
|
+
* a single buffered Claude CLI session call, then one JSON object back to
|
|
7
|
+
* the client.
|
|
8
|
+
*
|
|
9
|
+
* Lifecycle:
|
|
10
|
+
* 1. reportStatus('thinking') → SessionManager.sendMessage(...)
|
|
11
|
+
* 2. On each tool_use event → push a status update + emit trajectory
|
|
12
|
+
* 3. On each tool_result event → emit trajectory only (no status)
|
|
13
|
+
* 4. v0.7.1: accumulate thinking-block content when surfaceThinking is on
|
|
14
|
+
* 5. On completion → read token stats, format response, write back
|
|
15
|
+
* 6. On error → reportStatus('idle','Request failed') + 500 with
|
|
16
|
+
* structured `formatError` telemetry
|
|
17
|
+
*
|
|
18
|
+
* Parameterized fully — no closure capture from openai-compat.ts. All
|
|
19
|
+
* dependencies are imported from their dedicated Cluster B modules
|
|
20
|
+
* (response-formatter, tool-calls-parser, status-reporter,
|
|
21
|
+
* message-extractor for types) or from lib/.
|
|
22
|
+
*/
|
|
23
|
+
import { reportStatus, getToolDescription } from './status-reporter.js';
|
|
24
|
+
import { parseToolCallsFromText } from './tool-calls-parser.js';
|
|
25
|
+
import { formatCompletionResponse } from './response-formatter.js';
|
|
26
|
+
import { getSurfaceThinkingEnabled } from '../lib/config.js';
|
|
27
|
+
import { emit as emitTrajectory } from '../lib/trajectory.js';
|
|
28
|
+
import { formatError, ERROR_CODES } from '../lib/error-formatter.js';
|
|
29
|
+
export async function handleNonStreaming(manager, sessionName, model,
|
|
30
|
+
// Phase 2 R4 wire-up: accepts native content-block arrays in tool-stream mode.
|
|
31
|
+
userMessage, completionId, res, hasTools) {
|
|
32
|
+
try {
|
|
33
|
+
reportStatus('thinking', 'Processing request...');
|
|
34
|
+
// v0.7.1: accumulate thinking-block content when surfaceThinking is on.
|
|
35
|
+
// Default OFF for privacy — empty string means no `reasoning` field
|
|
36
|
+
// gets attached to the response.
|
|
37
|
+
const surfaceThinking = getSurfaceThinkingEnabled();
|
|
38
|
+
let thinkingBuffer = '';
|
|
39
|
+
const result = await manager.sendMessage(sessionName, userMessage, {
|
|
40
|
+
onEvent: (event) => {
|
|
41
|
+
if (event.type === 'tool_use' && event.tool?.name) {
|
|
42
|
+
const desc = getToolDescription(event.tool.name, event.tool.input);
|
|
43
|
+
reportStatus('working', desc, event.tool.name);
|
|
44
|
+
// Pillar B v0.4.3: trajectory tool_use event. Emit tool name and
|
|
45
|
+
// input-arg keys (not values — keys leak no sensitive content
|
|
46
|
+
// while still letting offline analysis cluster tool-call shapes).
|
|
47
|
+
emitTrajectory('tool_use', {
|
|
48
|
+
name: event.tool.name,
|
|
49
|
+
inputKeys: event.tool.input ? Object.keys(event.tool.input) : [],
|
|
50
|
+
}, sessionName);
|
|
51
|
+
}
|
|
52
|
+
else if (event.type === 'tool_result') {
|
|
53
|
+
emitTrajectory('tool_result', {}, sessionName);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
// v0.7.1: when surfaceThinking is on, accumulate extended-thinking text
|
|
57
|
+
// for the `reasoning` field on the OpenAI response. Subscribing to the
|
|
58
|
+
// callback always (cheap closure cost ~ none); only buffering when
|
|
59
|
+
// the env flag is set so the privacy-default-OFF promise holds.
|
|
60
|
+
onThinking: surfaceThinking
|
|
61
|
+
? (text) => {
|
|
62
|
+
thinkingBuffer += text;
|
|
63
|
+
}
|
|
64
|
+
: undefined,
|
|
65
|
+
});
|
|
66
|
+
reportStatus('idle', 'Ready');
|
|
67
|
+
let tokensIn = 0;
|
|
68
|
+
let tokensOut = 0;
|
|
69
|
+
try {
|
|
70
|
+
const status = manager.getStatus(sessionName);
|
|
71
|
+
tokensIn = status.stats.tokensIn;
|
|
72
|
+
tokensOut = status.stats.tokensOut;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
/* stats unavailable */
|
|
76
|
+
}
|
|
77
|
+
// v0.7.1: emit thinking_block trajectory event with token-count metadata
|
|
78
|
+
// only (never raw text). Fires when buffer is non-empty regardless of
|
|
79
|
+
// whether the response surfaces it — so observability is independent
|
|
80
|
+
// of the user-visible flag.
|
|
81
|
+
if (thinkingBuffer.length > 0) {
|
|
82
|
+
emitTrajectory('thinking_block', {
|
|
83
|
+
excerpt_chars: thinkingBuffer.length,
|
|
84
|
+
tokens_approx: Math.ceil(thinkingBuffer.length / 4),
|
|
85
|
+
}, sessionName);
|
|
86
|
+
}
|
|
87
|
+
// Parse tool_calls from response text when caller provided tools
|
|
88
|
+
if (hasTools) {
|
|
89
|
+
const parsed = parseToolCallsFromText(result.output);
|
|
90
|
+
const response = formatCompletionResponse(completionId, model, parsed.textContent ?? '', tokensIn, tokensOut, parsed.toolCalls.length > 0 ? parsed.toolCalls : undefined, surfaceThinking ? thinkingBuffer : undefined);
|
|
91
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
92
|
+
res.end(JSON.stringify(response));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const response = formatCompletionResponse(completionId, model, result.output, tokensIn, tokensOut, undefined, surfaceThinking ? thinkingBuffer : undefined);
|
|
96
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
97
|
+
res.end(JSON.stringify(response));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
reportStatus('idle', 'Request failed');
|
|
102
|
+
// v0.4.3: route through formatError for errors_total + trajectory error.
|
|
103
|
+
formatError(err, { code: ERROR_CODES.SESSION_ERROR, sessionId: sessionName, details: { phase: 'handleNonStreaming' } });
|
|
104
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
105
|
+
res.end(JSON.stringify({ error: { message: err.message, type: 'server_error' } }));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=non-streaming-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"non-streaming-handler.js","sourceRoot":"","sources":["../../../src/openai-compat/non-streaming-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,IAAI,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAErE,MAAM,CAAC,KAAK,UAAU,kBAAkB,C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