@tangle-network/sdk-provider-cli-base 0.13.131 → 0.13.133
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.
|
@@ -101,6 +101,7 @@ declare class HermesProviderAdapter extends CliProviderAdapterBase<HermesConfig,
|
|
|
101
101
|
readonly provider = "hermes";
|
|
102
102
|
protected readonly profileHarness: HarnessId;
|
|
103
103
|
private activeSessionId?;
|
|
104
|
+
private readonly streamMarker;
|
|
104
105
|
protected readonly defaultCliPath = "hermes";
|
|
105
106
|
protected isBenignNonZeroExit({
|
|
106
107
|
exitCode,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { C as plaintextResponseParser, F as isLocalMcpConfig, I as localMcpArgv, L as localMcpEnv, O as recordCliTokenUsage, Rt as sessionObservedEvents, _t as prependPromptSection, ht as partitionImageAttachments, k as CliProviderAdapterBase } from "../../src-BjWuYvIc.mjs";
|
|
1
|
+
import { Bt as textDeltaEvents, C as plaintextResponseParser, F as isLocalMcpConfig, I as localMcpArgv, It as finalTextEvent, L as localMcpEnv, O as recordCliTokenUsage, Rt as sessionObservedEvents, Vt as textSnapshotEvents, _t as prependPromptSection, ht as partitionImageAttachments, k as CliProviderAdapterBase } from "../../src-BjWuYvIc.mjs";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { resolveTangleRouterDefaults } from "@tangle-network/agent-interface";
|
|
3
4
|
import { writeFile } from "node:fs/promises";
|
|
4
5
|
import { dirname, join } from "node:path";
|
|
@@ -56,6 +57,82 @@ function resolveHermesNativeConnection(config, explicitModel) {
|
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
59
|
//#endregion
|
|
60
|
+
//#region src/adapters/hermes/stream-parser.ts
|
|
61
|
+
/** Hermes emits its stream marker only on the packaged quiet chat path. A
|
|
62
|
+
* custom or older CLI can print a JSON answer without selecting this protocol. */
|
|
63
|
+
function hermesStreamParser(marker, plaintext, state, onEvent) {
|
|
64
|
+
let streaming = false;
|
|
65
|
+
let finished = false;
|
|
66
|
+
function fail(message) {
|
|
67
|
+
state.terminalStatus = "failed";
|
|
68
|
+
state.failure ??= {
|
|
69
|
+
message,
|
|
70
|
+
code: "HERMES_ERROR"
|
|
71
|
+
};
|
|
72
|
+
onEvent?.({
|
|
73
|
+
type: "warning",
|
|
74
|
+
code: "HERMES_ERROR",
|
|
75
|
+
message
|
|
76
|
+
});
|
|
77
|
+
onEvent?.({
|
|
78
|
+
type: "status",
|
|
79
|
+
status: "failed",
|
|
80
|
+
detail: message
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
parseAs: "lines",
|
|
85
|
+
transform: (raw) => ({
|
|
86
|
+
type: "text",
|
|
87
|
+
line: String(raw)
|
|
88
|
+
}),
|
|
89
|
+
onEvent(event) {
|
|
90
|
+
if (event.type !== "text") return;
|
|
91
|
+
const { line } = event;
|
|
92
|
+
if (!streaming && line === marker) {
|
|
93
|
+
streaming = true;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!streaming) {
|
|
97
|
+
const value = plaintext.transform?.(line);
|
|
98
|
+
if (value) plaintext.onEvent(value);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (finished || !line.startsWith("{")) return;
|
|
102
|
+
let frame;
|
|
103
|
+
try {
|
|
104
|
+
frame = JSON.parse(line);
|
|
105
|
+
} catch {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (frame.type === "text" && typeof frame.text === "string") for (const part of textDeltaEvents(state, frame.text)) onEvent?.(part);
|
|
109
|
+
else if (frame.type === "result") {
|
|
110
|
+
finished = true;
|
|
111
|
+
if (typeof frame.exit_code !== "number" || typeof frame.text !== "string" || !frame.text && frame.exit_code !== 0) {
|
|
112
|
+
fail(typeof frame.error === "string" ? frame.error : "Hermes did not complete the turn");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (frame.text.startsWith(state.textBuffer)) for (const part of textSnapshotEvents(state, frame.text)) onEvent?.(part);
|
|
116
|
+
else {
|
|
117
|
+
const update = finalTextEvent(state, frame.text);
|
|
118
|
+
if (update.type === "message.part.updated") onEvent?.({
|
|
119
|
+
type: update.type,
|
|
120
|
+
part: update.part
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
onEvent?.({
|
|
124
|
+
type: "status",
|
|
125
|
+
status: "completed"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
onComplete() {
|
|
130
|
+
if (!streaming) plaintext.onComplete?.();
|
|
131
|
+
else if (!finished) fail("Hermes stopped before its terminal result");
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
59
136
|
//#region src/adapters/hermes/adapter.ts
|
|
60
137
|
/**
|
|
61
138
|
* `profile.extensions.hermes` — the hermes-specific escape hatch, mirroring the
|
|
@@ -74,6 +151,7 @@ var HermesProviderAdapter = class extends CliProviderAdapterBase {
|
|
|
74
151
|
provider = "hermes";
|
|
75
152
|
profileHarness = "hermes";
|
|
76
153
|
activeSessionId;
|
|
154
|
+
streamMarker = `tangle-hermes-stream-${randomUUID()}`;
|
|
77
155
|
defaultCliPath = "hermes";
|
|
78
156
|
isBenignNonZeroExit({ exitCode, stderr, state }) {
|
|
79
157
|
if (exitCode === null || exitCode === 0) return false;
|
|
@@ -162,6 +240,8 @@ var HermesProviderAdapter = class extends CliProviderAdapterBase {
|
|
|
162
240
|
return {
|
|
163
241
|
...this.agentEnvironmentValues(),
|
|
164
242
|
HERMES_HOME: this.resolveHermesHome(),
|
|
243
|
+
TANGLE_HERMES_STREAM_MARKER: process.env.HERMES_STREAM === "1" ? this.streamMarker : void 0,
|
|
244
|
+
TANGLE_HERMES_CATALOG_DEFAULTS: process.env.HERMES_STREAM === "1" ? "1" : void 0,
|
|
165
245
|
...resolveHermesNativeConnection(config).env
|
|
166
246
|
};
|
|
167
247
|
}
|
|
@@ -216,7 +296,7 @@ var HermesProviderAdapter = class extends CliProviderAdapterBase {
|
|
|
216
296
|
});
|
|
217
297
|
}
|
|
218
298
|
createEventParser(state, onEvent) {
|
|
219
|
-
|
|
299
|
+
const plaintext = plaintextResponseParser(state, onEvent, {
|
|
220
300
|
classify: (line) => line.startsWith("API call failed") || line.startsWith("Error:") || line.startsWith("hermes:") ? {
|
|
221
301
|
type: "error",
|
|
222
302
|
message: line
|
|
@@ -241,6 +321,7 @@ var HermesProviderAdapter = class extends CliProviderAdapterBase {
|
|
|
241
321
|
},
|
|
242
322
|
emptyFailureDetail: "hermes errored without producing a response body"
|
|
243
323
|
});
|
|
324
|
+
return process.env.HERMES_STREAM === "1" ? hermesStreamParser(this.streamMarker, plaintext, state, onEvent) : plaintext;
|
|
244
325
|
}
|
|
245
326
|
};
|
|
246
327
|
function parseHermesSessionId(stderr) {
|
|
@@ -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.133",
|
|
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.127",
|
|
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-
|
|
82
|
+
"sourceSha": "a3279e5ca9286d7b244f65b1b5d3517dc77e8b99",
|
|
83
|
+
"mergedAt": "2026-11-19T19:14:53-08:00"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"build": "tsdown",
|