@meetopenbot/pi 0.1.2 → 1.0.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/dist/session.js CHANGED
@@ -12,7 +12,7 @@ const hasPiByok = (provider) => {
12
12
  resolveByokApiKey('deepseek'));
13
13
  };
14
14
  const buildSessionKey = (state, byok) => {
15
- const scope = state.threadId ? `${state.channelId}:${state.threadId}` : state.channelId;
15
+ const scope = state.threadId ? `${state.channelId ?? ''}:${state.threadId}` : (state.channelId ?? '');
16
16
  return `${scope}:${byok ? 'byok' : 'credits'}`;
17
17
  };
18
18
  const resolveModel = async (config, modelRegistry) => {
@@ -83,7 +83,9 @@ export const disposePiSession = (sessionKey) => {
83
83
  sessionCache.delete(sessionKey);
84
84
  };
85
85
  export const disposePiSessionsForThread = (state) => {
86
- const prefix = state.threadId ? `${state.channelId}:${state.threadId}:` : `${state.channelId}:`;
86
+ const prefix = state.threadId
87
+ ? `${state.channelId ?? ''}:${state.threadId}:`
88
+ : `${state.channelId ?? ''}:`;
87
89
  for (const key of sessionCache.keys()) {
88
90
  if (key.startsWith(prefix))
89
91
  disposePiSession(key);
package/dist/state.js CHANGED
@@ -7,13 +7,17 @@ export const readPersistedState = (state) => {
7
7
  return typeof record.sessionFile === 'string' ? { sessionFile: record.sessionFile } : {};
8
8
  };
9
9
  export const persistPiState = async (state, storage, patch) => {
10
+ const channelId = state.channelId;
11
+ if (!channelId) {
12
+ throw new Error('channelId is required to persist Pi session state');
13
+ }
10
14
  if (state.threadId) {
11
15
  await storage.patchThreadState({
12
- channelId: state.channelId,
16
+ channelId,
13
17
  threadId: state.threadId,
14
18
  state: patch,
15
19
  });
16
20
  return;
17
21
  }
18
- await storage.patchChannelState({ channelId: state.channelId, state: patch });
22
+ await storage.patchChannelState({ channelId, state: patch });
19
23
  };
package/dist/stream.js CHANGED
@@ -2,6 +2,23 @@ import { createTextReplyBuffer, textReply, yieldFromBackgroundQueue, } from '@me
2
2
  import { remapPiError } from './credits.js';
3
3
  const isAssistantMessage = (message) => message.role === 'assistant';
4
4
  export const classifyPiEvent = (event) => {
5
+ if (event.type === 'tool_execution_start') {
6
+ return {
7
+ type: 'tool_call',
8
+ id: event.toolCallId,
9
+ name: event.toolName,
10
+ input: event.args,
11
+ };
12
+ }
13
+ if (event.type === 'tool_execution_end') {
14
+ return {
15
+ type: 'tool_result',
16
+ id: event.toolCallId,
17
+ name: event.toolName,
18
+ output: event.result,
19
+ error: event.isError,
20
+ };
21
+ }
5
22
  if (event.type === 'message_update') {
6
23
  const assistantEvent = event.assistantMessageEvent;
7
24
  if (assistantEvent.type === 'text_delta')
@@ -23,9 +40,9 @@ function* consumePiEvent(event, replies) {
23
40
  }
24
41
  yield* replies.apply(classifyPiEvent(event));
25
42
  }
26
- /** Run a Pi prompt and yield each completed assistant turn. */
43
+ /** Run a Pi prompt and yield each completed assistant turn and tool widget. */
27
44
  export async function* runPiPrompt(session, prompt, options) {
28
- const replies = createTextReplyBuffer();
45
+ const replies = createTextReplyBuffer({ groupId: 'pi:tools' });
29
46
  yield* yieldFromBackgroundQueue(async (enqueue) => {
30
47
  const unsubscribe = session.subscribe((event) => {
31
48
  for (const item of consumePiEvent(event, replies))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/pi",
3
- "version": "0.1.2",
3
+ "version": "1.0.0",
4
4
  "description": "OpenBot agent plugin powered by the Pi coding agent SDK.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@earendil-works/pi-ai": "^0.79.1",
23
23
  "@earendil-works/pi-coding-agent": "^0.79.1",
24
- "@meetopenbot/plugin-sdk": "^0.4.0"
24
+ "@meetopenbot/plugin-sdk": "^1.0.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "^25.9.2",