@saleso.innovations/bridge 0.1.45 → 0.1.47
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/hermesForwarder.d.ts.map +1 -1
- package/dist/hermesForwarder.js +21 -15
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hermesForwarder.d.ts","sourceRoot":"","sources":["../src/hermesForwarder.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAyB,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"hermesForwarder.d.ts","sourceRoot":"","sources":["../src/hermesForwarder.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAyB,eAAe,EAAE,MAAM,aAAa,CAAC;AAkCtF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAkBF,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,sBAA2B,GAAG;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAaA;AAiID,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,UAAU,EACjB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,CAsG9B;AA4BD,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,sBAA2B,IAC/D,SAAS,MAAM,EAAE,MAAM,eAAe,EAAE,OAAO,UAAU,KAAG,OAAO,CAAC,IAAI,CAAC,CAOxF"}
|
package/dist/hermesForwarder.js
CHANGED
|
@@ -6,8 +6,21 @@ import { getLatestTurnMessageIds, getSessionUsage, hermesStateDbExists } from ".
|
|
|
6
6
|
import { diffSkillsLearned, snapshotSkills } from "./skillLearnedDetector.js";
|
|
7
7
|
import { buildTurnActivity, createTurnActivityAccumulator, parseSseDataLines, processSseEventBlock, } from "./turnActivity.js";
|
|
8
8
|
import { parseMediaReferences, resolveMediaReferenceBytes, stripMediaReferences, } from "./hermesFiles.js";
|
|
9
|
-
import {
|
|
9
|
+
import { unwrapHermesStructuredContent } from "./hermesStructuredContent.js";
|
|
10
10
|
import { resolveProfileContext } from "./profiles.js";
|
|
11
|
+
/**
|
|
12
|
+
* Instructs Hermes models to reply in plain conversational markdown so the Cleos
|
|
13
|
+
* chat renders Telegram-style text (and streams cleanly), instead of emitting
|
|
14
|
+
* model-specific JSON. Cards, when enabled, are still built from this markdown
|
|
15
|
+
* downstream by the structurer.
|
|
16
|
+
*/
|
|
17
|
+
const PLAIN_MARKDOWN_SYSTEM_PROMPT = [
|
|
18
|
+
"You are replying inside a mobile chat app. Respond in plain, conversational markdown only.",
|
|
19
|
+
"Do not output JSON, UI component objects, or wrap the whole reply in a code fence.",
|
|
20
|
+
"Never prefix lines with field labels like \"heading:\", \"text:\", \"list:\", \"callout:\", or \"suggestions:\". Write the content directly instead.",
|
|
21
|
+
"Use light markdown for structure: short paragraphs separated by blank lines, \"-\" for bullet lists, \"##\" for a heading, and **bold** for emphasis.",
|
|
22
|
+
"Write naturally, like a normal chat message.",
|
|
23
|
+
].join("\n");
|
|
11
24
|
function readHermesApiKeyFromEnvFile(home) {
|
|
12
25
|
const envPath = join(home?.trim() || join(homedir(), ".hermes"), ".env");
|
|
13
26
|
try {
|
|
@@ -165,7 +178,10 @@ export async function forwardToHermes(content, meta, reply, options = {}) {
|
|
|
165
178
|
const body = {
|
|
166
179
|
model,
|
|
167
180
|
stream: true,
|
|
168
|
-
messages: [
|
|
181
|
+
messages: [
|
|
182
|
+
{ role: "system", content: PLAIN_MARKDOWN_SYSTEM_PROMPT },
|
|
183
|
+
{ role: "user", content: userContent },
|
|
184
|
+
],
|
|
169
185
|
user: sessionId,
|
|
170
186
|
};
|
|
171
187
|
const turnStartedAt = Date.now();
|
|
@@ -190,13 +206,8 @@ export async function forwardToHermes(content, meta, reply, options = {}) {
|
|
|
190
206
|
const counters = { textSequence: 0, activitySequence: 0 };
|
|
191
207
|
const accumulator = createTurnActivityAccumulator();
|
|
192
208
|
let fullText = "";
|
|
193
|
-
let suppressStreamDeltas = false;
|
|
194
209
|
const streamingReply = {
|
|
195
|
-
delta(text, sequence)
|
|
196
|
-
if (!suppressStreamDeltas) {
|
|
197
|
-
reply.delta(text, sequence);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
210
|
+
delta: (text, sequence) => reply.delta(text, sequence),
|
|
200
211
|
activity: (activity) => reply.activity(activity),
|
|
201
212
|
complete: (...args) => reply.complete(...args),
|
|
202
213
|
failed: (failure) => reply.failed(failure),
|
|
@@ -211,18 +222,13 @@ export async function forwardToHermes(content, meta, reply, options = {}) {
|
|
|
211
222
|
for (const eventBlock of events) {
|
|
212
223
|
processSseEventBlock(eventBlock, streamingReply, counters, accumulator, (delta) => {
|
|
213
224
|
fullText += delta;
|
|
214
|
-
if (!suppressStreamDeltas && looksLikeHermesStructuredStream(fullText)) {
|
|
215
|
-
suppressStreamDeltas = true;
|
|
216
|
-
}
|
|
217
225
|
});
|
|
218
226
|
}
|
|
219
227
|
}
|
|
220
228
|
if (!fullText.trim()) {
|
|
221
229
|
fullText = "(Hermes returned an empty response)";
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
counters.textSequence += 1;
|
|
225
|
-
}
|
|
230
|
+
reply.delta(fullText, counters.textSequence);
|
|
231
|
+
counters.textSequence += 1;
|
|
226
232
|
}
|
|
227
233
|
const mediaRefs = parseMediaReferences(fullText);
|
|
228
234
|
const attachments = mediaRefs.length > 0 ? await uploadMediaAttachments(meta.agentId, mediaRefs, home) : [];
|