@a1hvdy/cc-openclaw 0.7.1 → 0.9.0

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.
Files changed (79) hide show
  1. package/dist/src/command-router/cc-handler.js +11 -3
  2. package/dist/src/command-router/cc-handler.js.map +1 -1
  3. package/dist/src/engines/persistent-session.d.ts +1 -0
  4. package/dist/src/engines/persistent-session.js +35 -1
  5. package/dist/src/engines/persistent-session.js.map +1 -1
  6. package/dist/src/index.d.ts +10 -1
  7. package/dist/src/index.js +47 -7
  8. package/dist/src/index.js.map +1 -1
  9. package/dist/src/lib/config-service.d.ts +106 -0
  10. package/dist/src/lib/config-service.js +217 -0
  11. package/dist/src/lib/config-service.js.map +1 -0
  12. package/dist/src/lib/config.d.ts +33 -14
  13. package/dist/src/lib/config.js +147 -34
  14. package/dist/src/lib/config.js.map +1 -1
  15. package/dist/src/lib/index.d.ts +1 -1
  16. package/dist/src/lib/index.js +4 -1
  17. package/dist/src/lib/index.js.map +1 -1
  18. package/dist/src/openai-compat/message-extractor.d.ts +79 -0
  19. package/dist/src/openai-compat/message-extractor.js +134 -0
  20. package/dist/src/openai-compat/message-extractor.js.map +1 -0
  21. package/dist/src/openai-compat/mode-flags.d.ts +34 -0
  22. package/dist/src/openai-compat/mode-flags.js +44 -0
  23. package/dist/src/openai-compat/mode-flags.js.map +1 -0
  24. package/dist/src/openai-compat/non-streaming-handler.d.ts +26 -0
  25. package/dist/src/openai-compat/non-streaming-handler.js +108 -0
  26. package/dist/src/openai-compat/non-streaming-handler.js.map +1 -0
  27. package/dist/src/openai-compat/openai-compat.d.ts +15 -166
  28. package/dist/src/openai-compat/openai-compat.js +72 -817
  29. package/dist/src/openai-compat/openai-compat.js.map +1 -1
  30. package/dist/src/openai-compat/prompts.d.ts +47 -0
  31. package/dist/src/openai-compat/prompts.js +119 -0
  32. package/dist/src/openai-compat/prompts.js.map +1 -0
  33. package/dist/src/openai-compat/response-formatter.d.ts +33 -0
  34. package/dist/src/openai-compat/response-formatter.js +74 -0
  35. package/dist/src/openai-compat/response-formatter.js.map +1 -0
  36. package/dist/src/openai-compat/session-key-resolver.d.ts +41 -0
  37. package/dist/src/openai-compat/session-key-resolver.js +78 -0
  38. package/dist/src/openai-compat/session-key-resolver.js.map +1 -0
  39. package/dist/src/openai-compat/status-reporter.d.ts +30 -0
  40. package/dist/src/openai-compat/status-reporter.js +81 -0
  41. package/dist/src/openai-compat/status-reporter.js.map +1 -0
  42. package/dist/src/openai-compat/streaming-handler.d.ts +41 -0
  43. package/dist/src/openai-compat/streaming-handler.js +294 -0
  44. package/dist/src/openai-compat/streaming-handler.js.map +1 -0
  45. package/dist/src/openai-compat/tool-calls-parser.d.ts +34 -0
  46. package/dist/src/openai-compat/tool-calls-parser.js +93 -0
  47. package/dist/src/openai-compat/tool-calls-parser.js.map +1 -0
  48. package/dist/src/openai-compat/tool-results-serializer.d.ts +60 -0
  49. package/dist/src/openai-compat/tool-results-serializer.js +56 -0
  50. package/dist/src/openai-compat/tool-results-serializer.js.map +1 -0
  51. package/dist/src/session/session-manager.js +12 -0
  52. package/dist/src/session/session-manager.js.map +1 -1
  53. package/dist/src/session-bootstrap/cwd-patch.js +30 -13
  54. package/dist/src/session-bootstrap/cwd-patch.js.map +1 -1
  55. package/dist/src/types/index.d.ts +15 -0
  56. package/dist/src/types/index.js +16 -0
  57. package/dist/src/types/index.js.map +1 -0
  58. package/dist/src/types/route.d.ts +41 -0
  59. package/dist/src/types/route.js +12 -0
  60. package/dist/src/types/route.js.map +1 -0
  61. package/dist/src/types/runtime-config.d.ts +161 -0
  62. package/dist/src/types/runtime-config.js +118 -0
  63. package/dist/src/types/runtime-config.js.map +1 -0
  64. package/dist/src/types/session.d.ts +48 -0
  65. package/dist/src/types/session.js +20 -0
  66. package/dist/src/types/session.js.map +1 -0
  67. package/dist/src/types/sse.d.ts +38 -0
  68. package/dist/src/types/sse.js +12 -0
  69. package/dist/src/types/sse.js.map +1 -0
  70. package/dist/src/types/tool-bridge.d.ts +81 -0
  71. package/dist/src/types/tool-bridge.js +34 -0
  72. package/dist/src/types/tool-bridge.js.map +1 -0
  73. package/dist/src/types/upstream.d.ts +652 -0
  74. package/dist/src/types/upstream.js +145 -0
  75. package/dist/src/types/upstream.js.map +1 -0
  76. package/package.json +3 -2
  77. package/dist/src/lib/route-flag.d.ts +0 -49
  78. package/dist/src/lib/route-flag.js +0 -52
  79. package/dist/src/lib/route-flag.js.map +0 -1
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Cluster A — Type the seams.
3
+ *
4
+ * Single typed runtime configuration parsed from `process.env` at boot.
5
+ * Replaces the 12+ scattered env-flag readers in `src/lib/config.ts` with
6
+ * one zod-validated immutable object.
7
+ *
8
+ * Pre-existing latent bugs documented at `src/lib/config.ts:39-42` and
9
+ * `src/lib/config.ts:195-197` (two readers per env var with opposite
10
+ * defaults) are resolved by FIELD-SPLITTING rather than choosing one
11
+ * default. This preserves both current call-site behaviors verbatim.
12
+ *
13
+ * NOT consumed yet — Cluster A first commit establishes the vocabulary.
14
+ * Cluster A migration order (per PRP §14) wires this in incrementally
15
+ * with `src/lib/config.ts` getters delegating during the shim window.
16
+ */
17
+ import { z } from 'zod';
18
+ /**
19
+ * Three-state activation mode derived from the two LISTENERS / ACTIVE flags.
20
+ * Replaces the implicit two-flag matrix at `src/lib/route-flag.ts`.
21
+ *
22
+ * - PASSIVE — listeners NOT wired; no engine routing.
23
+ * - LISTENERS_ONLY — listeners wired, but engine routing returns 'claude-local'.
24
+ * - ACTIVE_ROUTING — listeners wired AND engine routing returns 'cc-openclaw'.
25
+ */
26
+ export declare enum RuntimeMode {
27
+ PASSIVE = "PASSIVE",
28
+ LISTENERS_ONLY = "LISTENERS_ONLY",
29
+ ACTIVE_ROUTING = "ACTIVE_ROUTING"
30
+ }
31
+ /**
32
+ * Derive RuntimeMode from raw env. Honors deprecated alias
33
+ * `OPENCLAW_USE_CC_OPENCLAW` only when the primary `OPENCLAW_CC_OPENCLAW_ACTIVE`
34
+ * is unset. Alias retained through v0.9.x; removed at v1.0.0.
35
+ */
36
+ export declare function deriveMode(env: NodeJS.ProcessEnv): RuntimeMode;
37
+ export declare const RuntimeConfigSchema: z.ZodObject<{
38
+ mode: z.ZodNativeEnum<typeof RuntimeMode>;
39
+ listenersEnabled: z.ZodDefault<z.ZodBoolean>;
40
+ activeRouting: z.ZodDefault<z.ZodBoolean>;
41
+ toolStream: z.ZodDefault<z.ZodBoolean>;
42
+ allowBuiltins: z.ZodDefault<z.ZodBoolean>;
43
+ toolsPerMessage: z.ZodDefault<z.ZodBoolean>;
44
+ cacheParityModuleEnabled: z.ZodDefault<z.ZodBoolean>;
45
+ cacheParityTrackB: z.ZodDefault<z.ZodBoolean>;
46
+ newConvoHeuristic: z.ZodDefault<z.ZodBoolean>;
47
+ aggressiveStripEnabled: z.ZodDefault<z.ZodBoolean>;
48
+ debug: z.ZodDefault<z.ZodBoolean>;
49
+ registerDebug: z.ZodDefault<z.ZodBoolean>;
50
+ tokenTelemetryRouteGate: z.ZodDefault<z.ZodBoolean>;
51
+ tokenTelemetryWriter: z.ZodDefault<z.ZodBoolean>;
52
+ syspromptDump: z.ZodDefault<z.ZodBoolean>;
53
+ trajectoryEnabled: z.ZodDefault<z.ZodBoolean>;
54
+ statusUrl: z.ZodOptional<z.ZodString>;
55
+ surfaceThinking: z.ZodDefault<z.ZodBoolean>;
56
+ thinkingExcerpt: z.ZodDefault<z.ZodBoolean>;
57
+ maxConcurrentSessions: z.ZodDefault<z.ZodNumber>;
58
+ sessionTtlMinutes: z.ZodDefault<z.ZodNumber>;
59
+ serverHost: z.ZodDefault<z.ZodString>;
60
+ rateLimit: z.ZodDefault<z.ZodNumber>;
61
+ serverToken: z.ZodOptional<z.ZodString>;
62
+ corsAllowAll: z.ZodDefault<z.ZodBoolean>;
63
+ claudeBin: z.ZodOptional<z.ZodString>;
64
+ geminiBin: z.ZodOptional<z.ZodString>;
65
+ codexBin: z.ZodOptional<z.ZodString>;
66
+ cursorBin: z.ZodOptional<z.ZodString>;
67
+ driftAlertsEnabled: z.ZodDefault<z.ZodBoolean>;
68
+ autoRecoveryEnabled: z.ZodDefault<z.ZodBoolean>;
69
+ quotaPausePct: z.ZodDefault<z.ZodNumber>;
70
+ testMode: z.ZodDefault<z.ZodBoolean>;
71
+ heartbeatWorkaroundDisabled: z.ZodDefault<z.ZodBoolean>;
72
+ savvyLiveCardEnabled: z.ZodDefault<z.ZodBoolean>;
73
+ /** True if mode was derived from the deprecated alias path. Logged at boot. */
74
+ usedDeprecatedAlias: z.ZodDefault<z.ZodBoolean>;
75
+ }, "strip", z.ZodTypeAny, {
76
+ mode: RuntimeMode;
77
+ listenersEnabled: boolean;
78
+ activeRouting: boolean;
79
+ toolStream: boolean;
80
+ allowBuiltins: boolean;
81
+ toolsPerMessage: boolean;
82
+ cacheParityModuleEnabled: boolean;
83
+ cacheParityTrackB: boolean;
84
+ newConvoHeuristic: boolean;
85
+ aggressiveStripEnabled: boolean;
86
+ debug: boolean;
87
+ registerDebug: boolean;
88
+ tokenTelemetryRouteGate: boolean;
89
+ tokenTelemetryWriter: boolean;
90
+ syspromptDump: boolean;
91
+ trajectoryEnabled: boolean;
92
+ surfaceThinking: boolean;
93
+ thinkingExcerpt: boolean;
94
+ maxConcurrentSessions: number;
95
+ sessionTtlMinutes: number;
96
+ serverHost: string;
97
+ rateLimit: number;
98
+ corsAllowAll: boolean;
99
+ driftAlertsEnabled: boolean;
100
+ autoRecoveryEnabled: boolean;
101
+ quotaPausePct: number;
102
+ testMode: boolean;
103
+ heartbeatWorkaroundDisabled: boolean;
104
+ savvyLiveCardEnabled: boolean;
105
+ usedDeprecatedAlias: boolean;
106
+ statusUrl?: string | undefined;
107
+ serverToken?: string | undefined;
108
+ claudeBin?: string | undefined;
109
+ geminiBin?: string | undefined;
110
+ codexBin?: string | undefined;
111
+ cursorBin?: string | undefined;
112
+ }, {
113
+ mode: RuntimeMode;
114
+ listenersEnabled?: boolean | undefined;
115
+ activeRouting?: boolean | undefined;
116
+ toolStream?: boolean | undefined;
117
+ allowBuiltins?: boolean | undefined;
118
+ toolsPerMessage?: boolean | undefined;
119
+ cacheParityModuleEnabled?: boolean | undefined;
120
+ cacheParityTrackB?: boolean | undefined;
121
+ newConvoHeuristic?: boolean | undefined;
122
+ aggressiveStripEnabled?: boolean | undefined;
123
+ debug?: boolean | undefined;
124
+ registerDebug?: boolean | undefined;
125
+ tokenTelemetryRouteGate?: boolean | undefined;
126
+ tokenTelemetryWriter?: boolean | undefined;
127
+ syspromptDump?: boolean | undefined;
128
+ trajectoryEnabled?: boolean | undefined;
129
+ statusUrl?: string | undefined;
130
+ surfaceThinking?: boolean | undefined;
131
+ thinkingExcerpt?: boolean | undefined;
132
+ maxConcurrentSessions?: number | undefined;
133
+ sessionTtlMinutes?: number | undefined;
134
+ serverHost?: string | undefined;
135
+ rateLimit?: number | undefined;
136
+ serverToken?: string | undefined;
137
+ corsAllowAll?: boolean | undefined;
138
+ claudeBin?: string | undefined;
139
+ geminiBin?: string | undefined;
140
+ codexBin?: string | undefined;
141
+ cursorBin?: string | undefined;
142
+ driftAlertsEnabled?: boolean | undefined;
143
+ autoRecoveryEnabled?: boolean | undefined;
144
+ quotaPausePct?: number | undefined;
145
+ testMode?: boolean | undefined;
146
+ heartbeatWorkaroundDisabled?: boolean | undefined;
147
+ savvyLiveCardEnabled?: boolean | undefined;
148
+ usedDeprecatedAlias?: boolean | undefined;
149
+ }>;
150
+ export type RuntimeConfig = z.infer<typeof RuntimeConfigSchema>;
151
+ export declare class ConfigError extends Error {
152
+ readonly issues: ReadonlyArray<z.ZodIssue>;
153
+ constructor(issues: z.ZodIssue[]);
154
+ }
155
+ export type ParseEnvResult = {
156
+ readonly ok: true;
157
+ readonly config: Readonly<RuntimeConfig>;
158
+ } | {
159
+ readonly ok: false;
160
+ readonly error: ConfigError;
161
+ };
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Cluster A — Type the seams.
3
+ *
4
+ * Single typed runtime configuration parsed from `process.env` at boot.
5
+ * Replaces the 12+ scattered env-flag readers in `src/lib/config.ts` with
6
+ * one zod-validated immutable object.
7
+ *
8
+ * Pre-existing latent bugs documented at `src/lib/config.ts:39-42` and
9
+ * `src/lib/config.ts:195-197` (two readers per env var with opposite
10
+ * defaults) are resolved by FIELD-SPLITTING rather than choosing one
11
+ * default. This preserves both current call-site behaviors verbatim.
12
+ *
13
+ * NOT consumed yet — Cluster A first commit establishes the vocabulary.
14
+ * Cluster A migration order (per PRP §14) wires this in incrementally
15
+ * with `src/lib/config.ts` getters delegating during the shim window.
16
+ */
17
+ import { z } from 'zod';
18
+ // ── Mode derivation ──────────────────────────────────────────────────────────
19
+ /**
20
+ * Three-state activation mode derived from the two LISTENERS / ACTIVE flags.
21
+ * Replaces the implicit two-flag matrix at `src/lib/route-flag.ts`.
22
+ *
23
+ * - PASSIVE — listeners NOT wired; no engine routing.
24
+ * - LISTENERS_ONLY — listeners wired, but engine routing returns 'claude-local'.
25
+ * - ACTIVE_ROUTING — listeners wired AND engine routing returns 'cc-openclaw'.
26
+ */
27
+ export var RuntimeMode;
28
+ (function (RuntimeMode) {
29
+ RuntimeMode["PASSIVE"] = "PASSIVE";
30
+ RuntimeMode["LISTENERS_ONLY"] = "LISTENERS_ONLY";
31
+ RuntimeMode["ACTIVE_ROUTING"] = "ACTIVE_ROUTING";
32
+ })(RuntimeMode || (RuntimeMode = {}));
33
+ const flag = (v) => v === '1' || v?.toLowerCase() === 'true' || v?.toLowerCase() === 'on';
34
+ /**
35
+ * Derive RuntimeMode from raw env. Honors deprecated alias
36
+ * `OPENCLAW_USE_CC_OPENCLAW` only when the primary `OPENCLAW_CC_OPENCLAW_ACTIVE`
37
+ * is unset. Alias retained through v0.9.x; removed at v1.0.0.
38
+ */
39
+ export function deriveMode(env) {
40
+ const listeners = flag(env.OPENCLAW_CC_OPENCLAW_LISTENERS);
41
+ const active = env.OPENCLAW_CC_OPENCLAW_ACTIVE !== undefined
42
+ ? flag(env.OPENCLAW_CC_OPENCLAW_ACTIVE)
43
+ : flag(env.OPENCLAW_USE_CC_OPENCLAW); // deprecated alias
44
+ if (!listeners)
45
+ return RuntimeMode.PASSIVE;
46
+ if (!active)
47
+ return RuntimeMode.LISTENERS_ONLY;
48
+ return RuntimeMode.ACTIVE_ROUTING;
49
+ }
50
+ // ── Schema ───────────────────────────────────────────────────────────────────
51
+ export const RuntimeConfigSchema = z.object({
52
+ // Derived — not read directly from a single env var.
53
+ mode: z.nativeEnum(RuntimeMode),
54
+ // ── Activation ────────────────────────────────────────────────────────────
55
+ listenersEnabled: z.boolean().default(false),
56
+ activeRouting: z.boolean().default(false),
57
+ // ── Tooling ───────────────────────────────────────────────────────────────
58
+ toolStream: z.boolean().default(false),
59
+ allowBuiltins: z.boolean().default(false),
60
+ toolsPerMessage: z.boolean().default(false),
61
+ // ── Caching & state ───────────────────────────────────────────────────────
62
+ // Dual-default split for OPENCLAW_CACHE_PARITY (see file header):
63
+ // moduleEnabled: default TRUE — broad enable, only OFF if env in {0,false,off}
64
+ // trackB: default FALSE — strict opt-in, only ON if env === '1'
65
+ cacheParityModuleEnabled: z.boolean().default(true),
66
+ cacheParityTrackB: z.boolean().default(false),
67
+ newConvoHeuristic: z.boolean().default(false),
68
+ aggressiveStripEnabled: z.boolean().default(true),
69
+ // ── Observability ─────────────────────────────────────────────────────────
70
+ debug: z.boolean().default(false),
71
+ registerDebug: z.boolean().default(false),
72
+ // Dual-default split for OPENCLAW_TOKEN_TELEMETRY (see file header):
73
+ // routeGate: default FALSE — cwd-patch gate, strict `=== '1'`
74
+ // writer: default TRUE — telemetry.ts writer, only OFF on `=== '0'`
75
+ tokenTelemetryRouteGate: z.boolean().default(false),
76
+ tokenTelemetryWriter: z.boolean().default(true),
77
+ syspromptDump: z.boolean().default(false),
78
+ trajectoryEnabled: z.boolean().default(false),
79
+ // statusUrl is intentionally `string`, NOT `string().url()` — current code
80
+ // (src/lib/config.ts:236-239) does zero validation; tightening would change
81
+ // behavior. Audit the live corpus before promoting to URL validation.
82
+ statusUrl: z.string().optional(),
83
+ surfaceThinking: z.boolean().default(false),
84
+ thinkingExcerpt: z.boolean().default(false),
85
+ // ── Session caps ──────────────────────────────────────────────────────────
86
+ maxConcurrentSessions: z.number().int().positive().default(32),
87
+ sessionTtlMinutes: z.number().int().positive().default(1440),
88
+ // ── Embedded HTTP server ──────────────────────────────────────────────────
89
+ serverHost: z.string().default('127.0.0.1'),
90
+ rateLimit: z.number().int().positive().default(100),
91
+ serverToken: z.string().optional(),
92
+ corsAllowAll: z.boolean().default(false),
93
+ // ── Runtime binaries ──────────────────────────────────────────────────────
94
+ claudeBin: z.string().optional(),
95
+ geminiBin: z.string().optional(),
96
+ codexBin: z.string().optional(),
97
+ cursorBin: z.string().optional(),
98
+ // ── Misc ──────────────────────────────────────────────────────────────────
99
+ driftAlertsEnabled: z.boolean().default(true),
100
+ autoRecoveryEnabled: z.boolean().default(true),
101
+ quotaPausePct: z.number().min(0).max(100).default(95),
102
+ testMode: z.boolean().default(false),
103
+ heartbeatWorkaroundDisabled: z.boolean().default(false),
104
+ savvyLiveCardEnabled: z.boolean().default(false),
105
+ // ── Deprecation tracking ──────────────────────────────────────────────────
106
+ /** True if mode was derived from the deprecated alias path. Logged at boot. */
107
+ usedDeprecatedAlias: z.boolean().default(false),
108
+ });
109
+ // ── Error type ───────────────────────────────────────────────────────────────
110
+ export class ConfigError extends Error {
111
+ issues;
112
+ constructor(issues) {
113
+ super(`RuntimeConfig validation failed: ${issues.map((i) => i.message).join('; ')}`);
114
+ this.name = 'ConfigError';
115
+ this.issues = Object.freeze(issues.slice());
116
+ }
117
+ }
118
+ //# sourceMappingURL=runtime-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-config.js","sourceRoot":"","sources":["../../../src/types/runtime-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,gFAAgF;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ACpC,2BAA2B,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IACvD,oBAAoB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAEhD,6EAA6E;IAC7E,+EAA+E;IAC/E,mBAAmB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAChD,CAAC,CAAC;AAIH,gFAAgF;AAEhF,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,MAAM,CAA4B;IAC3C,YAAY,MAAoB;QAC9B,KAAK,CAAC,oCAAoC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrF,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9C,CAAC;CACF"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Cluster A — Session boundary types.
3
+ *
4
+ * Re-exports the session vocabulary already established in the root
5
+ * `src/types.ts` module. New aliases (`SessionStartConfig`, `SessionMeta`)
6
+ * preview Cluster B's `SessionService` boundary without yet introducing
7
+ * a new shape — they're typed wrappers over today's `SessionConfig` /
8
+ * `ActiveSession`.
9
+ *
10
+ * `SessionName` is the branded type that Cluster D's `SessionRegistry`
11
+ * will use to enforce the `'openai-'` prefix routing discriminant
12
+ * (cwd-patch.ts:489 gates CWD redirect, tools restoration, CLAUDE.md
13
+ * injection on this prefix).
14
+ *
15
+ * NOT consumed yet — Cluster A first commit establishes the vocabulary.
16
+ */
17
+ export type { SessionConfig as SessionStartConfig, SessionStats, ActiveSession, SessionInfo, SessionSendOptions, StreamCallbacks, StreamEvent, SendResult, SendOptions, TurnResult, CostBreakdown, ISession, EngineType, PermissionMode, EffortLevel, PluginConfig, HookConfig, CustomEngineConfig, } from '../types.js';
18
+ /**
19
+ * Branded session-name type. Prevents raw string from being passed where
20
+ * the `'openai-'` prefix is load-bearing. Use the constructors below to
21
+ * mint or strip the prefix — never construct directly.
22
+ */
23
+ export type SessionName = string & {
24
+ readonly __brand: 'SessionName';
25
+ };
26
+ export declare const sessionNameFromKey: (key: string) => SessionName;
27
+ export declare const isOpenAiBridgeName: (name: SessionName) => boolean;
28
+ export declare const stripOpenAiPrefix: (name: SessionName) => string;
29
+ /**
30
+ * Cluster B/D will fold this into `SessionRegistry.SessionEntry`. For
31
+ * Cluster A it's a typed preview — the shape Cluster D will persist,
32
+ * declared here so other clusters can compile against the contract.
33
+ */
34
+ export interface SessionMeta {
35
+ readonly name: SessionName;
36
+ readonly claudeSessionId: string | null;
37
+ readonly pid: number | null;
38
+ readonly cachedSysPromptHash: string;
39
+ readonly skipPersistence: boolean;
40
+ readonly createdAt: number;
41
+ readonly updatedAt: number;
42
+ }
43
+ /**
44
+ * Input shape Cluster B's `SessionService.send()` accepts.
45
+ * Today's call sites pass either a string or an array of content blocks;
46
+ * this interface preserves both without yet committing to a tighter shape.
47
+ */
48
+ export type SendInput = string | ReadonlyArray<unknown>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Cluster A — Session boundary types.
3
+ *
4
+ * Re-exports the session vocabulary already established in the root
5
+ * `src/types.ts` module. New aliases (`SessionStartConfig`, `SessionMeta`)
6
+ * preview Cluster B's `SessionService` boundary without yet introducing
7
+ * a new shape — they're typed wrappers over today's `SessionConfig` /
8
+ * `ActiveSession`.
9
+ *
10
+ * `SessionName` is the branded type that Cluster D's `SessionRegistry`
11
+ * will use to enforce the `'openai-'` prefix routing discriminant
12
+ * (cwd-patch.ts:489 gates CWD redirect, tools restoration, CLAUDE.md
13
+ * injection on this prefix).
14
+ *
15
+ * NOT consumed yet — Cluster A first commit establishes the vocabulary.
16
+ */
17
+ export const sessionNameFromKey = (key) => `openai-${key}`;
18
+ export const isOpenAiBridgeName = (name) => name.startsWith('openai-');
19
+ export const stripOpenAiPrefix = (name) => name.replace(/^openai-/, '');
20
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/types/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA8BH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAe,EAAE,CAC7D,UAAU,GAAG,EAAiB,CAAC;AAEjC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAiB,EAAW,EAAE,CAC/D,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AAE7B,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAiB,EAAU,EAAE,CAC7D,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Cluster A — SSE wire-format types.
3
+ *
4
+ * Re-exports the SSE types currently inline in `openai-compat.ts` and the
5
+ * Anthropic event types from `cli-stream-parser.ts` under a single import
6
+ * surface. Cluster B's `sse-translator.ts` already lives at
7
+ * `src/openai-compat/sse-translator.ts` — this module is its typed contract.
8
+ *
9
+ * NOT consumed yet — Cluster A first commit establishes the vocabulary.
10
+ */
11
+ export type { OpenAIChatCompletionChunk as SseChunk, OpenAIToolCall, } from '../openai-compat/openai-compat.js';
12
+ export type { AnthropicEvent, AnthropicMessage, MessageUsage, MessageDeltaBody, ContentBlockStart, ContentBlockDelta, ParsedEvent, CliStreamParser, } from '../openai-compat/cli-stream-parser.js';
13
+ /**
14
+ * OpenAI `finish_reason` values cc-openclaw emits after mapping from
15
+ * Anthropic `stop_reason`:
16
+ * end_turn / stop_sequence → 'stop'
17
+ * tool_use → 'tool_calls'
18
+ * max_tokens → 'length'
19
+ * (cancelled / abort) → null (no finish_reason chunk)
20
+ */
21
+ export type FinishReason = 'stop' | 'tool_calls' | 'length' | null;
22
+ /**
23
+ * One delta in an OpenAI streaming chunk. Cluster B will tighten this when
24
+ * `sse-translator.ts` is extracted into the typed boundary.
25
+ */
26
+ export interface OpenAIDelta {
27
+ readonly role?: 'assistant' | 'system' | 'user' | 'tool';
28
+ readonly content?: string;
29
+ readonly tool_calls?: ReadonlyArray<{
30
+ readonly index: number;
31
+ readonly id?: string;
32
+ readonly type?: 'function';
33
+ readonly function?: {
34
+ readonly name?: string;
35
+ readonly arguments?: string;
36
+ };
37
+ }>;
38
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Cluster A — SSE wire-format types.
3
+ *
4
+ * Re-exports the SSE types currently inline in `openai-compat.ts` and the
5
+ * Anthropic event types from `cli-stream-parser.ts` under a single import
6
+ * surface. Cluster B's `sse-translator.ts` already lives at
7
+ * `src/openai-compat/sse-translator.ts` — this module is its typed contract.
8
+ *
9
+ * NOT consumed yet — Cluster A first commit establishes the vocabulary.
10
+ */
11
+ export {};
12
+ //# sourceMappingURL=sse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/types/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Cluster A — Tool bridge contract.
3
+ *
4
+ * Declares the interface Cluster B's three tool-mode strategies will
5
+ * implement (`EmbeddedToolsBridge`, `PerMessageToolsBridge`,
6
+ * `NativeToolStreamBridge`). Lives in `src/types/` — pure type
7
+ * declaration, no runtime code, zero implementation yet.
8
+ *
9
+ * The mode → bridge selection in Cluster B is one-way: `bridges/factory.ts`
10
+ * imports from this module; `system-prompt-builder.ts` (the other
11
+ * potentially-circular dependency) accepts a `ToolMode` arg from the
12
+ * bridge rather than importing the factory. See PRP §11 Decision Log.
13
+ *
14
+ * NOT consumed yet — Cluster A first commit establishes the vocabulary.
15
+ */
16
+ import type { OpenAIToolCall } from './route.js';
17
+ import type { OpenAIDelta } from './sse.js';
18
+ /**
19
+ * Three tool-handling modes documented in ARCHITECTURE.md §5.3:
20
+ *
21
+ * - Embedded — default. Tools embedded in session system prompt at
22
+ * create-time; NOT re-injected per turn; cacheable.
23
+ * - PerMessage — legacy `OPENAI_COMPAT_TOOLS_PER_MESSAGE=1`. Tool block
24
+ * prepended to every user message; defeats prompt caching;
25
+ * allows mutating tool list mid-session.
26
+ * - NativeStream — `CC_OPENCLAW_TOOL_STREAM=1`. Tools forwarded as
27
+ * `--tools` allowlist; native `tool_use` events flow
28
+ * through; SSE translator emits inline `delta.tool_calls`.
29
+ */
30
+ export declare enum ToolMode {
31
+ Embedded = "embedded",
32
+ PerMessage = "per-message",
33
+ NativeStream = "native-stream"
34
+ }
35
+ /**
36
+ * The tool definition shape OpenClaw's `createOpenClawCodingTools` produces
37
+ * and that callers send in `request.tools`. Shape mirrors the OpenAI tool
38
+ * definition. Cluster B will tighten when bridge implementations land.
39
+ */
40
+ export interface ToolDefinition {
41
+ readonly type: 'function';
42
+ readonly function: {
43
+ readonly name: string;
44
+ readonly description?: string;
45
+ readonly parameters?: Record<string, unknown>;
46
+ };
47
+ }
48
+ /**
49
+ * Result of translating a single Anthropic `tool_use` event from the
50
+ * Claude CLI stream into an OpenAI streaming chunk delta. `null` means
51
+ * the bridge consumed the event but emitted nothing (e.g. mid-block
52
+ * input_json_delta accumulation).
53
+ */
54
+ export type TranslatedToolUseDelta = OpenAIDelta | null;
55
+ /**
56
+ * The contract every tool-mode bridge must satisfy. Cluster B's three
57
+ * strategy classes live at `src/openai-compat/bridges/{embedded-tools,
58
+ * per-message,native-stream}.ts`. Each is constructed once per route
59
+ * request and discarded after the response is written.
60
+ */
61
+ export interface IToolBridge {
62
+ readonly mode: ToolMode;
63
+ /**
64
+ * Build the system-prompt fragment that advertises the tool list to
65
+ * the model. Pure function — no I/O. Empty string when the bridge
66
+ * does not embed tools in the prompt (NativeStream).
67
+ */
68
+ buildToolPreamble(tools: ReadonlyArray<ToolDefinition> | undefined): string;
69
+ /**
70
+ * Translate one parsed Anthropic event into an OpenAI delta if it
71
+ * represents a tool_use boundary. Returns `null` for events the
72
+ * bridge does not surface as tool_calls deltas.
73
+ */
74
+ translateToolUse(event: unknown): TranslatedToolUseDelta;
75
+ /**
76
+ * Serialize an OpenAI tool_call result back into the format the
77
+ * bridge sends to Claude CLI on the next turn. Embedded + PerMessage
78
+ * use `<tool_result>` XML; NativeStream uses native blocks.
79
+ */
80
+ serializeToolResult(call: OpenAIToolCall, result: string): string;
81
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Cluster A — Tool bridge contract.
3
+ *
4
+ * Declares the interface Cluster B's three tool-mode strategies will
5
+ * implement (`EmbeddedToolsBridge`, `PerMessageToolsBridge`,
6
+ * `NativeToolStreamBridge`). Lives in `src/types/` — pure type
7
+ * declaration, no runtime code, zero implementation yet.
8
+ *
9
+ * The mode → bridge selection in Cluster B is one-way: `bridges/factory.ts`
10
+ * imports from this module; `system-prompt-builder.ts` (the other
11
+ * potentially-circular dependency) accepts a `ToolMode` arg from the
12
+ * bridge rather than importing the factory. See PRP §11 Decision Log.
13
+ *
14
+ * NOT consumed yet — Cluster A first commit establishes the vocabulary.
15
+ */
16
+ /**
17
+ * Three tool-handling modes documented in ARCHITECTURE.md §5.3:
18
+ *
19
+ * - Embedded — default. Tools embedded in session system prompt at
20
+ * create-time; NOT re-injected per turn; cacheable.
21
+ * - PerMessage — legacy `OPENAI_COMPAT_TOOLS_PER_MESSAGE=1`. Tool block
22
+ * prepended to every user message; defeats prompt caching;
23
+ * allows mutating tool list mid-session.
24
+ * - NativeStream — `CC_OPENCLAW_TOOL_STREAM=1`. Tools forwarded as
25
+ * `--tools` allowlist; native `tool_use` events flow
26
+ * through; SSE translator emits inline `delta.tool_calls`.
27
+ */
28
+ export var ToolMode;
29
+ (function (ToolMode) {
30
+ ToolMode["Embedded"] = "embedded";
31
+ ToolMode["PerMessage"] = "per-message";
32
+ ToolMode["NativeStream"] = "native-stream";
33
+ })(ToolMode || (ToolMode = {}));
34
+ //# sourceMappingURL=tool-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-bridge.js","sourceRoot":"","sources":["../../../src/types/tool-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH;;;;;;;;;;;GAWG;AACH,MAAM,CAAN,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,iCAAqB,CAAA;IACrB,sCAA0B,CAAA;IAC1B,0CAA8B,CAAA;AAChC,CAAC,EAJW,QAAQ,KAAR,QAAQ,QAInB"}