@relaymessenger/pi 0.1.4-staging.24 → 0.1.4-staging.26
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/README.md +6 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +22 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,8 +30,10 @@ checks any number of options and submits them once; checking sends nothing, and
|
|
|
30
30
|
a person answers a given selection once. iOS may draw a checkmark in place of
|
|
31
31
|
each bullet and repeat the prompt's title, as presentation only.
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Payment
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
The agent ends the final Pi answer with a `payment` JSON fence holding the
|
|
36
|
+
payment request's fields (`description`, `category`, and `amount` with
|
|
37
|
+
`currency`, or `mode: "subscription"` with `price_id`). The plugin creates the
|
|
38
|
+
request with its own Relay token, on the card's own idempotency key; the words
|
|
39
|
+
go first and the payment card follows as its own Message.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Relay, { type MessagePart } from "@relaymessenger/sdk";
|
|
1
|
+
import Relay, { type MessagePart, type PaymentRequestCreateParams } from "@relaymessenger/sdk";
|
|
2
2
|
export interface PiChannelOptions {
|
|
3
3
|
readonly agentToken: string;
|
|
4
4
|
readonly baseURL?: string;
|
|
@@ -31,6 +31,7 @@ export declare const piPrompt: (message: string) => string;
|
|
|
31
31
|
export declare const answerMessages: (answer: string) => {
|
|
32
32
|
parts: MessagePart[];
|
|
33
33
|
error?: string;
|
|
34
|
+
payment?: PaymentRequestCreateParams;
|
|
34
35
|
}[];
|
|
35
36
|
export declare class PiChannel {
|
|
36
37
|
#private;
|
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, PAYMENT_BLOCK_INSTRUCTION, PAYMENT_GUIDANCE, selectionReply, selectionReplyContext, SELECTION_GUIDANCE, SELECTION_BLOCK_INSTRUCTION, LINK_LINE_INSTRUCTION, answerMessages as splitAnswer, createPaymentPart, RelayAPIError, } 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(); }
|
|
@@ -26,7 +26,7 @@ const textFromEvent = (event) => {
|
|
|
26
26
|
* This process sends pi's final text for it, and the same buttons and link
|
|
27
27
|
* rules every other runtime carries.
|
|
28
28
|
*/
|
|
29
|
-
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} ${SELECTION_BLOCK_INSTRUCTION} ${SELECTION_GUIDANCE} ${
|
|
29
|
+
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} ${SELECTION_BLOCK_INSTRUCTION} ${SELECTION_GUIDANCE} ${PAYMENT_BLOCK_INSTRUCTION} ${PAYMENT_GUIDANCE}`;
|
|
30
30
|
/**
|
|
31
31
|
* The messages an answer becomes: each link written alone on a line as its
|
|
32
32
|
* own message, text in chunks the API takes, and the buttons its fenced block
|
|
@@ -48,6 +48,10 @@ export const answerMessages = (answer) => {
|
|
|
48
48
|
}
|
|
49
49
|
if (split.error && messages[0])
|
|
50
50
|
messages[0].error = split.error;
|
|
51
|
+
// The payment request the block described: created with the card's own key
|
|
52
|
+
// and sent as the last Message.
|
|
53
|
+
if (split.payment)
|
|
54
|
+
messages.push({ parts: [], payment: split.payment });
|
|
51
55
|
return messages;
|
|
52
56
|
};
|
|
53
57
|
class ChatSession {
|
|
@@ -175,8 +179,22 @@ export class PiChannel {
|
|
|
175
179
|
const messages = answerMessages(answer);
|
|
176
180
|
if (messages[0]?.error)
|
|
177
181
|
console.error(`Relay: the component block in pi's answer was left as text: ${messages[0].error}.`);
|
|
178
|
-
for (const [index, message] of messages.entries())
|
|
179
|
-
|
|
182
|
+
for (const [index, message] of messages.entries()) {
|
|
183
|
+
const key = `pi-${event.event_id}-${index}`;
|
|
184
|
+
let parts = message.parts;
|
|
185
|
+
if (message.payment) {
|
|
186
|
+
try {
|
|
187
|
+
parts = [await createPaymentPart(this.#relay, message.payment, key)];
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
if (!(error instanceof RelayAPIError) || error.retryable)
|
|
191
|
+
throw error;
|
|
192
|
+
console.error(`Relay: the payment in pi's answer was not sent: ${error.message}`);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
await this.#relay.chats.messages.send(data.chat.id, { message: { parts, idempotency_key: key } });
|
|
197
|
+
}
|
|
180
198
|
}
|
|
181
199
|
}
|
|
182
200
|
export const runPiChannel = (options, signal) => new PiChannel(options).run(signal);
|
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.26",
|
|
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.26"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@earendil-works/pi-coding-agent": "0.86.0",
|