@tangle-network/sdk-provider-cli-base 0.13.131 → 0.13.132
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Kt as CliProviderConfig, Ot as CliProviderAdapterBase, Wt as CliExecArgs, Xt as ExecutionState, c as WorkspacePlanApplication, n as HarnessId } from "../../index-BvoaIiz8.mjs";
|
|
1
|
+
import { Dn as CliTurnSpawn, En as CliTurnProcess, Kt as CliProviderConfig, Ot as CliProviderAdapterBase, Wt as CliExecArgs, Xt as ExecutionState, c as WorkspacePlanApplication, n as HarnessId } from "../../index-BvoaIiz8.mjs";
|
|
2
2
|
import { StreamParserConfig } from "@tangle-network/sdk-cli-runner";
|
|
3
3
|
import { CliAuthFile, ProviderConfig, StreamEvent } from "@tangle-network/agent-interface";
|
|
4
4
|
|
|
@@ -12,13 +12,7 @@ import { CliAuthFile, ProviderConfig, StreamEvent } from "@tangle-network/agent-
|
|
|
12
12
|
interface OpenclawConfig extends CliProviderConfig {
|
|
13
13
|
authMode?: "auth-files" | "config-only";
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
* OpenClaw's embedded agent: `openclaw agent --local --json --agent main
|
|
17
|
-
* --session-id <id> -m "<prompt>"`, configured by `~/.openclaw/openclaw.json`.
|
|
18
|
-
* It does not stream: `--json` prints one envelope when the turn ends, and
|
|
19
|
-
* that envelope is the only place it reports usage and its session id.
|
|
20
|
-
*/
|
|
21
|
-
declare class OpenclawProviderAdapter extends CliProviderAdapterBase<OpenclawConfig, never> {
|
|
15
|
+
declare class OpenclawProviderAdapter extends CliProviderAdapterBase<OpenclawConfig, string> {
|
|
22
16
|
readonly provider = "openclaw";
|
|
23
17
|
protected readonly profileHarness: HarnessId;
|
|
24
18
|
protected readonly defaultCliPath = "openclaw";
|
|
@@ -68,11 +62,8 @@ declare class OpenclawProviderAdapter extends CliProviderAdapterBase<OpenclawCon
|
|
|
68
62
|
success: boolean;
|
|
69
63
|
};
|
|
70
64
|
}): Promise<void>;
|
|
71
|
-
protected
|
|
72
|
-
|
|
73
|
-
* Parse the buffered stdout as openclaw's JSON envelope and synthesize the
|
|
74
|
-
* canonical message.part.updated + status:completed events.
|
|
75
|
-
*/
|
|
65
|
+
protected spawnExecutionProcess(request: CliTurnSpawn<OpenclawConfig, string>): CliTurnProcess | Promise<CliTurnProcess>;
|
|
66
|
+
protected createEventParser(state: ExecutionState, onEvent?: (event: StreamEvent) => void): StreamParserConfig<string>;
|
|
76
67
|
private flushEnvelope;
|
|
77
68
|
}
|
|
78
69
|
//#endregion
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { It as finalTextEvent, O as recordCliTokenUsage, Rt as sessionObservedEvents, _t as prependPromptSection, h as nativeEffortArgs, k as CliProviderAdapterBase } from "../../src-BjWuYvIc.mjs";
|
|
1
|
+
import { Bt as textDeltaEvents, It as finalTextEvent, O as recordCliTokenUsage, Rt as sessionObservedEvents, Vt as textSnapshotEvents, _t as prependPromptSection, h as nativeEffortArgs, k as CliProviderAdapterBase } from "../../src-BjWuYvIc.mjs";
|
|
2
2
|
import { resolveTangleRouterDefaults } from "@tangle-network/agent-interface";
|
|
3
3
|
//#region src/adapters/openclaw/adapter.ts
|
|
4
4
|
/** openclaw's default agent id; the synthesized config declares only it. */
|
|
5
5
|
const OPENCLAW_AGENT_ID = "main";
|
|
6
|
-
|
|
7
|
-
* OpenClaw's embedded agent: `openclaw agent --local --json --agent main
|
|
8
|
-
* --session-id <id> -m "<prompt>"`, configured by `~/.openclaw/openclaw.json`.
|
|
9
|
-
* It does not stream: `--json` prints one envelope when the turn ends, and
|
|
10
|
-
* that envelope is the only place it reports usage and its session id.
|
|
11
|
-
*/
|
|
6
|
+
const PARTIAL_REPLY = "@openclaw/partial ";
|
|
12
7
|
var OpenclawProviderAdapter = class extends CliProviderAdapterBase {
|
|
13
8
|
provider = "openclaw";
|
|
14
9
|
profileHarness = "openclaw";
|
|
@@ -105,33 +100,58 @@ var OpenclawProviderAdapter = class extends CliProviderAdapterBase {
|
|
|
105
100
|
statusCode
|
|
106
101
|
};
|
|
107
102
|
}
|
|
103
|
+
spawnExecutionProcess(request) {
|
|
104
|
+
const sessionArg = request.execArgs.args.indexOf("--session-id");
|
|
105
|
+
return super.spawnExecutionProcess({
|
|
106
|
+
...request,
|
|
107
|
+
env: {
|
|
108
|
+
...request.env,
|
|
109
|
+
OPENCLAW_SIDECAR_SESSION: sessionArg >= 0 ? request.execArgs.args[sessionArg + 1] : void 0,
|
|
110
|
+
OPENCLAW_STREAM: process.env.OPENCLAW_STREAM === "1" ? "1" : void 0
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
108
114
|
createEventParser(state, onEvent) {
|
|
109
|
-
const
|
|
110
|
-
ext.stdoutBuffer = "";
|
|
115
|
+
const envelope = [];
|
|
111
116
|
return {
|
|
112
|
-
parseAs: "
|
|
113
|
-
onEvent: () => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
parseAs: "lines",
|
|
118
|
+
onEvent: (line) => {
|
|
119
|
+
if (!line.startsWith(PARTIAL_REPLY)) {
|
|
120
|
+
envelope.push(line);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
let partial;
|
|
124
|
+
try {
|
|
125
|
+
partial = JSON.parse(line.slice(18));
|
|
126
|
+
} catch {
|
|
127
|
+
onEvent?.({
|
|
128
|
+
type: "warning",
|
|
129
|
+
code: "OPENCLAW_PARSE_ERROR",
|
|
130
|
+
message: "Malformed OpenClaw partial reply"
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!partial || typeof partial !== "object") return;
|
|
135
|
+
const updates = "delta" in partial && typeof partial.delta === "string" ? textDeltaEvents(state, partial.delta) : "text" in partial && typeof partial.text === "string" ? openclawSnapshotEvents(state, partial.text) : [];
|
|
136
|
+
for (const update of updates) onEvent?.(update);
|
|
137
|
+
},
|
|
138
|
+
onComplete: () => {
|
|
139
|
+
for (const event of this.flushEnvelope(state, envelope.join("\n"))) onEvent?.(event);
|
|
117
140
|
}
|
|
118
141
|
};
|
|
119
142
|
}
|
|
120
|
-
|
|
121
|
-
* Parse the buffered stdout as openclaw's JSON envelope and synthesize the
|
|
122
|
-
* canonical message.part.updated + status:completed events.
|
|
123
|
-
*/
|
|
124
|
-
flushEnvelope(state) {
|
|
125
|
-
const trimmed = state.stdoutBuffer.trim();
|
|
143
|
+
flushEnvelope(state, trimmed) {
|
|
126
144
|
if (!trimmed) return [];
|
|
127
145
|
let parsed;
|
|
128
146
|
try {
|
|
129
|
-
|
|
130
|
-
|
|
147
|
+
const envelope = JSON.parse(trimmed);
|
|
148
|
+
if (!envelope || typeof envelope !== "object" || Array.isArray(envelope)) throw new Error("Expected an OpenClaw result object");
|
|
149
|
+
parsed = envelope;
|
|
150
|
+
} catch {
|
|
131
151
|
return [{
|
|
132
152
|
type: "warning",
|
|
133
153
|
code: "OPENCLAW_PARSE_ERROR",
|
|
134
|
-
message:
|
|
154
|
+
message: "Malformed OpenClaw result envelope"
|
|
135
155
|
}];
|
|
136
156
|
}
|
|
137
157
|
const text = extractFinalText(parsed);
|
|
@@ -139,8 +159,7 @@ var OpenclawProviderAdapter = class extends CliProviderAdapterBase {
|
|
|
139
159
|
const sessionId = typeof agentMeta.sessionId === "string" ? agentMeta.sessionId : void 0;
|
|
140
160
|
const events = sessionId ? sessionObservedEvents(state, "openclaw", sessionId) : [];
|
|
141
161
|
recordCliTokenUsage(state, agentMeta);
|
|
142
|
-
|
|
143
|
-
if (text) events.push(textEvent);
|
|
162
|
+
events.push(...openclawSnapshotEvents(state, text));
|
|
144
163
|
events.push({
|
|
145
164
|
type: "raw",
|
|
146
165
|
backend: this.provider,
|
|
@@ -156,6 +175,14 @@ var OpenclawProviderAdapter = class extends CliProviderAdapterBase {
|
|
|
156
175
|
return events;
|
|
157
176
|
}
|
|
158
177
|
};
|
|
178
|
+
function openclawSnapshotEvents(state, text) {
|
|
179
|
+
if (text.startsWith(state.textBuffer)) return textSnapshotEvents(state, text);
|
|
180
|
+
const event = finalTextEvent(state, text);
|
|
181
|
+
return event.type === "message.part.updated" ? [{
|
|
182
|
+
type: event.type,
|
|
183
|
+
part: event.part
|
|
184
|
+
}] : [event];
|
|
185
|
+
}
|
|
159
186
|
/**
|
|
160
187
|
* Walk an arbitrary content node and accumulate every string-valued `text`
|
|
161
188
|
* field plus any direct strings. Bounded depth (default 4) prevents
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/sdk-provider-cli-base",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.132",
|
|
4
4
|
"description": "Base adapter for CLI-based AI agent providers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
61
61
|
"@tangle-network/agent-core": "^1.0.3",
|
|
62
62
|
"@tangle-network/agent-interface": "^5.10.28",
|
|
63
|
-
"@tangle-network/agent-profile-materialize": "1.1.
|
|
63
|
+
"@tangle-network/agent-profile-materialize": "1.1.144",
|
|
64
64
|
"@tangle-network/agent-trace-contract": "^2.2.0",
|
|
65
|
-
"@tangle-network/cli-agent-registry": "0.15.
|
|
65
|
+
"@tangle-network/cli-agent-registry": "0.15.126",
|
|
66
66
|
"@tangle-network/sdk-cli-runner": "0.3.14",
|
|
67
67
|
"@tangle-network/sdk-session-persistence": "0.7.16",
|
|
68
68
|
"zod": "4.6.7"
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"registry": "https://registry.npmjs.org"
|
|
80
80
|
},
|
|
81
81
|
"tangleRelease": {
|
|
82
|
-
"sourceSha": "
|
|
83
|
-
"mergedAt": "2026-11-19T18:
|
|
82
|
+
"sourceSha": "4ff41a929144ee1fe61c013253eeb73837d9e061",
|
|
83
|
+
"mergedAt": "2026-11-19T18:41:18-08:00"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"build": "tsdown",
|