@melaya/runner 1.0.71 → 1.0.72
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/localRelay.js +42 -0
- package/package.json +1 -1
package/dist/localRelay.js
CHANGED
|
@@ -105,6 +105,48 @@ export function startLocalRelay(socket, verbose, serverUrl) {
|
|
|
105
105
|
});
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
|
+
// ── Mode C RAG search proxy ─────────────────────────────────────
|
|
109
|
+
// A runner-dispatched pipeline's `rag_retrieve` (Mode C: cloud store +
|
|
110
|
+
// local embedder) embeds the query locally then POSTs the vector to
|
|
111
|
+
// `${MEL_BUILDER_URL}/pipelines/<name>/docs/retrieval/search_by_vector`.
|
|
112
|
+
// We forward it over the authenticated socket (the runner is the trust
|
|
113
|
+
// anchor) to `runner:ragSearch`, which calls the server's
|
|
114
|
+
// _forwardSearchByVector → builder search_by_vector on the prod store.
|
|
115
|
+
const sm = req.method === "POST" && req.url
|
|
116
|
+
? req.url.match(/^\/pipelines\/([^/]+)\/docs\/retrieval\/search_by_vector\/?$/)
|
|
117
|
+
: null;
|
|
118
|
+
if (sm) {
|
|
119
|
+
const pipelineName = decodeURIComponent(sm[1]);
|
|
120
|
+
let sbody = "";
|
|
121
|
+
req.on("data", (chunk) => { sbody += chunk.toString(); });
|
|
122
|
+
req.on("end", () => {
|
|
123
|
+
const replyOnce = (status, body) => {
|
|
124
|
+
if (res.headersSent)
|
|
125
|
+
return;
|
|
126
|
+
res.writeHead(status, { "Content-Type": "application/json" });
|
|
127
|
+
res.end(JSON.stringify(body));
|
|
128
|
+
};
|
|
129
|
+
let parsed;
|
|
130
|
+
try {
|
|
131
|
+
parsed = JSON.parse(sbody || "{}");
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
replyOnce(400, { results: [], error: "invalid_json" });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// Relay timeout < the pipeline's urlopen timeout (30s) so the
|
|
138
|
+
// pipeline always gets a JSON reply rather than its own abort.
|
|
139
|
+
const t = setTimeout(() => replyOnce(504, { results: [], error: "upstream_timeout" }), 25000);
|
|
140
|
+
socket.emit("runner:ragSearch", { name: pipelineName, vector: parsed.vector, limit: parsed.limit }, (resp) => {
|
|
141
|
+
clearTimeout(t);
|
|
142
|
+
if (resp && typeof resp === "object")
|
|
143
|
+
replyOnce(200, resp);
|
|
144
|
+
else
|
|
145
|
+
replyOnce(502, { results: [], error: "no_response" });
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
108
150
|
if (req.method !== "POST" || req.url !== expectedPath) {
|
|
109
151
|
res.writeHead(404);
|
|
110
152
|
res.end("Not found");
|