@relaymessenger/pi 0.1.4-staging.5 → 0.1.4-staging.7
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/index.d.ts +6 -5
- package/dist/index.js +21 -17
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -18,14 +18,15 @@ export interface PiProcess {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* The prompt pi is given for one message: the words, then how to answer.
|
|
21
|
-
* This process sends pi's final text for it, and the same buttons
|
|
22
|
-
* every other runtime carries.
|
|
21
|
+
* This process sends pi's final text for it, and the same buttons and link
|
|
22
|
+
* rules every other runtime carries.
|
|
23
23
|
*/
|
|
24
24
|
export declare const piPrompt: (message: string) => string;
|
|
25
25
|
/**
|
|
26
|
-
* The messages an answer becomes:
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* The messages an answer becomes: each link written alone on a line as its
|
|
27
|
+
* own message, text in chunks the API takes, and the buttons its fenced block
|
|
28
|
+
* asked for under the last words. A block pi wrote that cannot be read stays
|
|
29
|
+
* in the words, so nothing the person was told is lost.
|
|
29
30
|
*/
|
|
30
31
|
export declare const answerMessages: (answer: string) => {
|
|
31
32
|
parts: MessagePart[];
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { createInterface } from "node:readline";
|
|
3
|
-
import Relay, { BUTTONS_BLOCK_INSTRUCTION, BUTTONS_GUIDANCE,
|
|
3
|
+
import Relay, { BUTTONS_BLOCK_INSTRUCTION, BUTTONS_GUIDANCE, LINK_LINE_INSTRUCTION, answerMessages as splitAnswer, } from "@relaymessenger/sdk";
|
|
4
4
|
class ChildPiProcess {
|
|
5
5
|
#child;
|
|
6
6
|
constructor(command, args) { this.#child = spawn(command, [...args], { stdio: ["pipe", "pipe", "pipe"] }); this.#child.stderr.resume(); }
|
|
@@ -17,27 +17,31 @@ const textFromEvent = (event) => {
|
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* The prompt pi is given for one message: the words, then how to answer.
|
|
20
|
-
* This process sends pi's final text for it, and the same buttons
|
|
21
|
-
* every other runtime carries.
|
|
20
|
+
* This process sends pi's final text for it, and the same buttons and link
|
|
21
|
+
* rules every other runtime carries.
|
|
22
22
|
*/
|
|
23
|
-
export const piPrompt = (message) => `${message}\n\nWrite your answer as your final message. Relay sends that answer to the chat for you, so do not send it yourself. Write chat text. Inline Markdown draws: bold, italic, strikethrough, code, links. Headings, lists and code fences show as written.\n\n${BUTTONS_BLOCK_INSTRUCTION} ${BUTTONS_GUIDANCE}`;
|
|
23
|
+
export const piPrompt = (message) => `${message}\n\nWrite your answer as your final message. Relay sends that answer to the chat for you, so do not send it yourself. Write chat text. Inline Markdown draws: bold, italic, strikethrough, code, links. Headings, lists and code fences show as written.\n\n${BUTTONS_BLOCK_INSTRUCTION} ${LINK_LINE_INSTRUCTION} ${BUTTONS_GUIDANCE}`;
|
|
24
24
|
/**
|
|
25
|
-
* The messages an answer becomes:
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* The messages an answer becomes: each link written alone on a line as its
|
|
26
|
+
* own message, text in chunks the API takes, and the buttons its fenced block
|
|
27
|
+
* asked for under the last words. A block pi wrote that cannot be read stays
|
|
28
|
+
* in the words, so nothing the person was told is lost.
|
|
28
29
|
*/
|
|
29
30
|
export const answerMessages = (answer) => {
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
const split = splitAnswer(answer);
|
|
32
|
+
const messages = [];
|
|
33
|
+
for (const [first, ...rest] of split.messages) {
|
|
34
|
+
if (first?.type !== "text" || first.value.length <= 10_000) {
|
|
35
|
+
messages.push({ parts: first ? [first, ...rest] : rest });
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const chunks = first.value.match(/[\s\S]{1,10000}/gu) ?? [];
|
|
39
|
+
for (const [index, chunk] of chunks.entries()) {
|
|
40
|
+
messages.push({ parts: [{ type: "text", value: chunk }, ...(index === chunks.length - 1 ? rest : [])] });
|
|
41
|
+
}
|
|
38
42
|
}
|
|
39
|
-
if (error && messages[0])
|
|
40
|
-
messages[0].error = error;
|
|
43
|
+
if (split.error && messages[0])
|
|
44
|
+
messages[0].error = split.error;
|
|
41
45
|
return messages;
|
|
42
46
|
};
|
|
43
47
|
class ChatSession {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@relaymessenger/pi",
|
|
3
|
-
"version": "0.1.4-staging.
|
|
3
|
+
"version": "0.1.4-staging.7",
|
|
4
4
|
"description": "Relay Messenger channel for Pi over Relay v1 WebSocket delivery.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"test": "vitest run"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@relaymessenger/sdk": "0.3.6-staging.
|
|
37
|
+
"@relaymessenger/sdk": "0.3.6-staging.7"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@mariozechner/pi-coding-agent": "0.73.1",
|