@llblab/pi-telegram 0.36.3 → 0.36.5

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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  > Each release keeps at most 8 outcome records of at most 512 characters.
4
4
 
5
+ ## 0.36.5: Separated Tool Errors
6
+
7
+ - `Separated Tool Errors`: Prefixes Telegram attachment and direct-message Tool failures with one normalized leading newline so Pi renders error evidence on a visually separated line beneath the Tool name without changing the underlying diagnostic text.
8
+
9
+ ## 0.36.4: Async Host Settings Compatibility
10
+
11
+ - `Async Host Settings`: Normalizes synchronous or asynchronous settings construction plus legacy enabled-model methods or generic `get` / `set` services at the Pi adapter boundary before model-menu reads and scoped-model persistence, improving compatible-host interoperability without changing native Pi behavior or weakening required `agent_settled` semantics.
12
+
5
13
  ## 0.36.3: Ordered Prompt Compatibility
6
14
 
7
15
  - `Prompt Compatibility`: Preserves plain and ordered-block system prompts across Pi-compatible runtimes; Telegram guidance remains a distinct block when the host supplies blocks, while unavailable transport strips only Telegram tool metadata without collapsing unrelated prompt context.
package/README.md CHANGED
@@ -28,6 +28,8 @@ pi install git:github.com/llblab/pi-telegram
28
28
 
29
29
  The 0.21 extension platform requires Pi `0.80.6` or newer. Its Activity API uses the public `agent_settled` lifecycle event to keep retries/continuations under one activity identity and release that identity only after the run fully settles.
30
30
 
31
+ Pi is the primary and only officially supported host. Narrow host-neutral adapters preserve ordered prompt blocks and normalize synchronous or asynchronous legacy/generic settings services for Pi-compatible hosts, but this is best-effort compatibility rather than an OMP support guarantee. Alternate-host shims must still reproduce required Pi lifecycle semantics—especially `agent_settled`—and their maintainers own ongoing validation.
32
+
31
33
  ## Quick Start
32
34
 
33
35
  ### 1. Create a Telegram bot
@@ -88,6 +88,16 @@ The repository uses a **Flat Domain DAG**:
88
88
  - `bindings` / `lifecycle` / `prompts` / `prompt-templates` / `pi`: Pi-facing command/tool/hook registration and cohesive cross-domain binding assembly, including queue mutation/dispatch/watchdog composition over admission and transport ports; session-generation fencing and start/shutdown sequencing across Queue, grouped input, Delivery, polling, capability monitor, follower refresh, and assistant-output projection; Telegram prompt guidance; prompt-template discovery/expansion; and centralized direct Pi SDK imports.
89
89
  - `command-templates`: shell-free command-template helpers, composition expansion, placeholder substitution, executable resolution, warnings, and retry/timeout semantics.
90
90
 
91
+ ### Host Compatibility Boundary
92
+
93
+ Pi is the primary and only officially supported host. `pi-telegram` may still accept narrow, host-neutral representation differences at its existing Pi-facing boundary when they preserve native Pi behavior and do not create a second runtime policy layer:
94
+
95
+ - `prompts` preserves either Pi's plain system-prompt string or an ordered block array supplied by a compatible host, appending Telegram guidance without collapsing host-owned blocks.
96
+ - `pi` normalizes settings-manager construction that is either synchronous or asynchronous, then adapts either Pi's legacy enabled-model methods or a generic `get` / `set` settings service before model-menu reads and scoped-model persistence use it. Hosts without an explicit reload method rely on fresh asynchronous construction; durable writes still require `flush`.
97
+ - `lifecycle` continues to require Pi's semantic `agent_settled` boundary. It does not infer terminal settlement from host-specific `agent_end`, retry, or stop events; a compatibility shim must reproduce that contract before it can safely support activity identity and unrecovered-error finalization.
98
+
99
+ This boundary uses no host-name detection, host package dependency, prototype patching, hidden agent process, PTY, or terminal forwarding. Representation adapters are best-effort compatibility rather than an OMP support guarantee. Alternate hosts and community contributors own validation of their compatibility shims and must supply every lifecycle semantic that the bridge requires.
100
+
91
101
  ### Guarded Invariants
92
102
 
93
103
  Architecture invariant tests protect:
package/lib/menu-model.ts CHANGED
@@ -119,7 +119,9 @@ export interface TelegramModelMenuStateBuilderDeps<
119
119
  TelegramModelMenuStateBuilderContext<TModel>,
120
120
  > {
121
121
  runtime: TelegramModelMenuRuntime<TModel>;
122
- createSettingsManager: (cwd: string) => MenuSettingsManager;
122
+ createSettingsManager: (
123
+ cwd: string,
124
+ ) => MenuSettingsManager | PromiseLike<MenuSettingsManager>;
123
125
  getActiveModel: (ctx: TContext) => TModel | undefined;
124
126
  }
125
127
 
@@ -490,7 +492,7 @@ export function createTelegramModelMenuStateBuilder<
490
492
  threadId?: number,
491
493
  ) => Promise<TelegramModelMenuState<TModel>> {
492
494
  return async (chatId, ctx, threadId) => {
493
- const settingsManager = deps.createSettingsManager(ctx.cwd);
495
+ const settingsManager = await deps.createSettingsManager(ctx.cwd);
494
496
  return deps.runtime.buildState({
495
497
  chatId,
496
498
  threadId,
@@ -436,6 +436,11 @@ async function buildTelegramOutboundAttachmentViews(options: {
436
436
  return pendingAttachments;
437
437
  }
438
438
 
439
+ function formatTelegramOutboundToolError(error: unknown): Error {
440
+ const message = error instanceof Error ? error.message : String(error);
441
+ return new Error(`\n${message.replace(/^\n+/u, "") || "Telegram outbound operation failed."}`);
442
+ }
443
+
439
444
  export function registerTelegramOutboundAttachmentTool(
440
445
  pi: ExtensionAPI,
441
446
  deps: TelegramOutboundAttachmentToolRegistrationDeps,
@@ -496,7 +501,7 @@ export function registerTelegramOutboundAttachmentTool(
496
501
  phase: "queue",
497
502
  count: params.paths.length,
498
503
  });
499
- throw error;
504
+ throw formatTelegramOutboundToolError(error);
500
505
  }
501
506
  },
502
507
  });
@@ -548,7 +553,7 @@ export function registerTelegramOutboundMessageTool(
548
553
  });
549
554
  } catch (error) {
550
555
  deps.recordRuntimeEvent?.("message", error, { phase: "direct" });
551
- throw error;
556
+ throw formatTelegramOutboundToolError(error);
552
557
  }
553
558
  },
554
559
  });
package/lib/pi.ts CHANGED
@@ -151,16 +151,82 @@ export function createExtensionApiRuntimePorts(
151
151
  };
152
152
  }
153
153
 
154
- export function createSettingsManager(cwd: string): PiSettingsManager {
155
- return SettingsManager.create(cwd);
154
+ type PiSettingsManagerFactory = {
155
+ create: (cwd: string) => unknown | PromiseLike<unknown>;
156
+ };
157
+
158
+ type HostSettingsManager = {
159
+ reload?: () => void | PromiseLike<void>;
160
+ flush?: () => void | PromiseLike<void>;
161
+ getEnabledModels?: () => unknown;
162
+ setEnabledModels?: (patterns: string[] | undefined) => void;
163
+ get?: (key: string) => unknown;
164
+ set?: (key: string, value: unknown) => void;
165
+ };
166
+
167
+ function readEnabledModels(value: unknown): string[] | undefined {
168
+ if (value === undefined) return undefined;
169
+ if (Array.isArray(value) && value.every((entry) => typeof entry === "string")) {
170
+ return [...value];
171
+ }
172
+ throw new TypeError("Host settings enabledModels must be a string array or undefined.");
173
+ }
174
+
175
+ export function normalizeSettingsManager(manager: unknown): PiSettingsManager {
176
+ if (typeof manager !== "object" || manager === null) {
177
+ throw new TypeError("Host settings manager must be an object.");
178
+ }
179
+ const host = manager as HostSettingsManager;
180
+ if (typeof host.flush !== "function") {
181
+ throw new TypeError("Host settings manager must provide flush().");
182
+ }
183
+ const read = typeof host.getEnabledModels === "function"
184
+ ? () => host.getEnabledModels!.call(host)
185
+ : typeof host.get === "function"
186
+ ? () => host.get!.call(host, "enabledModels")
187
+ : undefined;
188
+ const write = typeof host.setEnabledModels === "function"
189
+ ? (patterns: string[] | undefined) =>
190
+ host.setEnabledModels!.call(host, patterns)
191
+ : typeof host.set === "function"
192
+ ? (patterns: string[] | undefined) =>
193
+ host.set!.call(host, "enabledModels", patterns ?? [])
194
+ : undefined;
195
+ if (!read || !write) {
196
+ throw new TypeError(
197
+ "Host settings manager must provide enabled-model read and write capabilities.",
198
+ );
199
+ }
200
+ return {
201
+ reload: async () => {
202
+ await host.reload?.call(host);
203
+ },
204
+ flush: async () => {
205
+ await host.flush!.call(host);
206
+ },
207
+ getEnabledModels: () => readEnabledModels(read()),
208
+ setEnabledModels: write,
209
+ };
210
+ }
211
+
212
+ export async function createSettingsManager(
213
+ cwd: string,
214
+ ): Promise<PiSettingsManager> {
215
+ // Pi returns its legacy settings surface synchronously. Compatible hosts may
216
+ // resolve a generic settings service asynchronously; normalize both once at
217
+ // the SDK boundary instead of leaking host distinctions into menu domains.
218
+ const factory = SettingsManager as unknown as PiSettingsManagerFactory;
219
+ return normalizeSettingsManager(await factory.create(cwd));
156
220
  }
157
221
 
158
222
  export function createScopedModelPatternPersister(deps: {
159
- createSettingsManager: (cwd: string) => PiSettingsManager;
223
+ createSettingsManager: (
224
+ cwd: string,
225
+ ) => PiSettingsManager | PromiseLike<PiSettingsManager>;
160
226
  clearCachedModelMenuInputs: () => void;
161
227
  }): (patterns: string[], ctx: ExtensionContext) => Promise<void> {
162
228
  return async (patterns, ctx) => {
163
- const settingsManager = deps.createSettingsManager(ctx.cwd);
229
+ const settingsManager = await deps.createSettingsManager(ctx.cwd);
164
230
  settingsManager.setEnabledModels(
165
231
  patterns.length > 0 ? patterns : undefined,
166
232
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llblab/pi-telegram",
3
- "version": "0.36.3",
3
+ "version": "0.36.5",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"