@gholl-studio/pier-connector 0.2.51 → 0.3.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.
- package/package.json +17 -8
- package/src/cli.ts +29 -0
- package/src/config.ts +29 -0
- package/src/inbound.ts +162 -0
- package/src/index.ts +155 -0
- package/src/job-handler.ts +51 -0
- package/src/robot.ts +300 -0
- package/src/types/pier-sdk.d.ts +20 -0
- package/src/types.ts +32 -0
- package/src/config.js +0 -37
- package/src/index.js +0 -1222
- package/src/job-handler.js +0 -81
package/src/job-handler.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Job handler — processes incoming NATS messages by routing them
|
|
3
|
-
* through OpenClaw's built-in agent and responding with results.
|
|
4
|
-
*
|
|
5
|
-
* No direct LLM calls — OpenClaw handles inference internally.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Parse a raw NATS message into a structured job object.
|
|
10
|
-
*
|
|
11
|
-
* Expected inbound JSON:
|
|
12
|
-
* {
|
|
13
|
-
* "id": "job-uuid",
|
|
14
|
-
* "task": "Summarize this article …",
|
|
15
|
-
* "systemPrompt": "(optional) system prompt",
|
|
16
|
-
* "meta": { … } // pass-through metadata
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* @param {import('@nats-io/transport-node').Msg} msg
|
|
20
|
-
* @param {object} logger
|
|
21
|
-
* @returns {{ ok: true, job: object } | { ok: false, error: string }}
|
|
22
|
-
*/
|
|
23
|
-
import { protocol } from '@gholl-studio/pier-sdk';
|
|
24
|
-
const { normalizeInboundPayload } = protocol;
|
|
25
|
-
|
|
26
|
-
export function parseJob(msg, logger) {
|
|
27
|
-
let raw;
|
|
28
|
-
try {
|
|
29
|
-
raw = msg.string();
|
|
30
|
-
} catch (err) {
|
|
31
|
-
logger.error(`[pier-connector] Failed to read message bytes: ${err.message}`);
|
|
32
|
-
return { ok: false, error: 'Unreadable message payload' };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let payload;
|
|
36
|
-
try {
|
|
37
|
-
payload = JSON.parse(raw);
|
|
38
|
-
} catch (err) {
|
|
39
|
-
logger.error(`[pier-connector] Failed to parse JSON: ${err.message}`);
|
|
40
|
-
return { ok: false, error: `Invalid JSON: ${err.message}` };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return normalizeInboundPayload(payload);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Build a JSON response buffer to send back via msg.respond().
|
|
48
|
-
*
|
|
49
|
-
* @param {object} data
|
|
50
|
-
* @returns {Uint8Array}
|
|
51
|
-
*/
|
|
52
|
-
export function encodeResponse(data) {
|
|
53
|
-
return new TextEncoder().encode(JSON.stringify(data));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Safely respond to a NATS message with a JSON object.
|
|
58
|
-
*
|
|
59
|
-
* @param {import('@nats-io/transport-node').Msg} msg
|
|
60
|
-
* @param {object} data
|
|
61
|
-
*/
|
|
62
|
-
export function safeRespond(msg, data) {
|
|
63
|
-
try {
|
|
64
|
-
msg.respond(encodeResponse(data));
|
|
65
|
-
} catch {
|
|
66
|
-
// msg.respond may throw if connection is closed or
|
|
67
|
-
// message is not a request — silently ignore.
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Truncate a string for log readability.
|
|
73
|
-
*
|
|
74
|
-
* @param {string} str
|
|
75
|
-
* @param {number} max
|
|
76
|
-
* @returns {string}
|
|
77
|
-
*/
|
|
78
|
-
export function truncate(str, max = 100) {
|
|
79
|
-
if (typeof str !== 'string') return String(str);
|
|
80
|
-
return str.length > max ? str.slice(0, max) + '…' : str;
|
|
81
|
-
}
|