@howaboua/pi-pet 0.1.6 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @howaboua/pi-pet
2
2
 
3
+ ## 0.1.7
4
+
5
+ - Added empty-call reaction discovery, including when no pet is connected, and deferred Code and Notebook help.
6
+
3
7
  ## 0.1.6
4
8
 
5
9
  - Desktop attachment now uses Electron 44 and requires macOS 13 or newer, or a supported 64-bit Windows or Linux desktop. Linux ARMv7, 32-bit Windows and Linux Unity are no longer supported. The browser miniapp is unchanged.
@@ -1,6 +1,6 @@
1
1
  import { join } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
- import { CONFIG_DIR_NAME, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
+ import { CONFIG_DIR_NAME, defineTool, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
4
  import { Container, Text } from "@earendil-works/pi-tui";
5
5
  import { Type } from "typebox";
6
6
  import registerPackageChangelog from "../changelog.js";
@@ -12,7 +12,7 @@ import { registerRemoteApp } from "./remote-app.ts";
12
12
 
13
13
  const packageRoot = fileURLToPath(new URL("../", import.meta.url));
14
14
 
15
- function registerPetRuntime(pi: ExtensionAPI, runtime: PetRuntime): boolean {
15
+ function registerPetRuntime(pi: ExtensionAPI, runtime: PetRuntime) {
16
16
  const appRoot = runtime.root;
17
17
  const catalog: PetCatalog = runtime.catalog;
18
18
  let state: PetState = { schemaVersion: 1, pet: catalog.id, revision: 1, action: catalog.defaultAction };
@@ -44,24 +44,23 @@ function registerPetRuntime(pi: ExtensionAPI, runtime: PetRuntime): boolean {
44
44
  return state;
45
45
  }
46
46
 
47
- pi.registerTool({
47
+ const tool = defineTool({
48
48
  name: "pet_show",
49
49
  label: "Pet",
50
50
  description: "Show a named reaction on the connected Pi Pet",
51
51
  promptGuidelines: ["Use pet_show sparingly; routine task activity animates automatically"],
52
52
  parameters: Type.Object({
53
- action: Type.String({
54
- minLength: 1,
55
- maxLength: 64,
56
- description: 'Reaction name, or "list" to return available names',
57
- }),
53
+ action: Type.Optional(
54
+ Type.String({
55
+ minLength: 1,
56
+ maxLength: 64,
57
+ description: 'Reaction name, or "list" to return available names',
58
+ }),
59
+ ),
58
60
  note: Type.Optional(Type.String({ minLength: 1, maxLength: 280, description: "Short visible context" })),
59
61
  }),
60
62
  async execute(_toolCallId, params) {
61
- if (!registration.available) {
62
- throw new Error(GIPPITY_REQUIRED_TOOL_MESSAGE);
63
- }
64
- if (params.action === "list") {
63
+ if (params.action === undefined || params.action === "list") {
65
64
  const actions = Object.keys(catalog.actions).sort().join(", ");
66
65
  const aliases = Object.entries(catalog.aliases)
67
66
  .sort(([left], [right]) => left.localeCompare(right))
@@ -71,12 +70,15 @@ function registerPetRuntime(pi: ExtensionAPI, runtime: PetRuntime): boolean {
71
70
  content: [
72
71
  {
73
72
  type: "text",
74
- text: `${catalog.displayName} actions: ${actions}.${aliases ? ` Aliases: ${aliases}.` : ""}`,
73
+ text: `${params.action === undefined ? 'pet_show({ action: "<reaction>", note?: "<short context>" }). ' : ""}${catalog.displayName} actions: ${actions}.${aliases ? ` Aliases: ${aliases}.` : ""}`,
75
74
  },
76
75
  ],
77
76
  details: state,
78
77
  };
79
78
  }
79
+ if (!registration.available) {
80
+ throw new Error(GIPPITY_REQUIRED_TOOL_MESSAGE);
81
+ }
80
82
  const next = setAction(params.action, parseNote(params.note));
81
83
  return {
82
84
  content: [{ type: "text", text: `Pet reaction set to ${next.action}.` }],
@@ -84,7 +86,7 @@ function registerPetRuntime(pi: ExtensionAPI, runtime: PetRuntime): boolean {
84
86
  };
85
87
  },
86
88
  renderCall(args, theme) {
87
- return new Text(`${theme.fg("toolTitle", theme.bold("Pet"))} ${theme.fg("muted", args.action)}`, 0, 0);
89
+ return new Text(`${theme.fg("toolTitle", theme.bold("Pet"))} ${theme.fg("muted", args.action ?? "help")}`, 0, 0);
88
90
  },
89
91
  renderResult(result, _options, theme, renderContext) {
90
92
  if (!renderContext.isError) return new Container();
@@ -92,13 +94,37 @@ function registerPetRuntime(pi: ExtensionAPI, runtime: PetRuntime): boolean {
92
94
  return new Text(theme.fg("error", message), 0, 0);
93
95
  },
94
96
  });
97
+ pi.registerTool(tool);
95
98
  pi.on("agent_settled", () => {
96
99
  if (state.action !== catalog.defaultAction) setAction(catalog.defaultAction);
97
100
  });
98
- return registration.available;
101
+ return { available: registration.available, tool };
99
102
  }
100
103
 
101
- export default function piPetExtension(pi: ExtensionAPI): void {
104
+ export default async function piPetExtension(pi: ExtensionAPI): Promise<void> {
105
+ let current: ReturnType<typeof registerPetRuntime> | undefined;
106
+ let refresh = () => {};
107
+ try {
108
+ const { adaptToolForCodeMode, registerCodeModeExtensionTools } = await import(
109
+ "@howaboua/pi-codex-conversion/code-mode"
110
+ );
111
+ const codeRegistration = registerCodeModeExtensionTools(pi, () => [
112
+ ...(current ? [adaptToolForCodeMode(current.tool, { discovery: "help", deferLoading: true })] : []),
113
+ ]);
114
+ refresh = codeRegistration.refresh;
115
+ pi.on("session_shutdown", () => codeRegistration.unregister());
116
+ } catch (error) {
117
+ if (
118
+ !(
119
+ error instanceof Error &&
120
+ "code" in error &&
121
+ ["ERR_MODULE_NOT_FOUND", "MODULE_NOT_FOUND", "ERR_PACKAGE_PATH_NOT_EXPORTED"].includes(String(error.code)) &&
122
+ error.message.includes("@howaboua/pi-codex-conversion")
123
+ )
124
+ )
125
+ throw error;
126
+ }
127
+
102
128
  registerPackageChangelog(pi);
103
129
  registerPetDevices(pi);
104
130
  pi.on("session_start", (_event, ctx) => {
@@ -106,7 +132,8 @@ export default function piPetExtension(pi: ExtensionAPI): void {
106
132
  for (const warning of resolution.warnings) {
107
133
  if (ctx.hasUI) ctx.ui.notify(`Pi Pet ${warning}`, "warning");
108
134
  }
109
- const gippityAvailable = registerPetRuntime(pi, resolution.runtime);
110
- if (!gippityAvailable && ctx.hasUI) ctx.ui.notify(GIPPITY_REQUIRED_USER_MESSAGE, "error");
135
+ current = registerPetRuntime(pi, resolution.runtime);
136
+ refresh();
137
+ if (!current.available && ctx.hasUI) ctx.ui.notify(GIPPITY_REQUIRED_USER_MESSAGE, "error");
111
138
  });
112
139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-pet",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Animated companions for GipPity Remote.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -77,11 +77,15 @@
77
77
  "@howaboua/pi-gippity-control": ">=0.0.20",
78
78
  "@earendil-works/pi-coding-agent": ">=1.0.0",
79
79
  "@earendil-works/pi-tui": ">=1.0.0",
80
- "typebox": "*"
80
+ "typebox": "*",
81
+ "@howaboua/pi-codex-conversion": ">=4.0.2"
81
82
  },
82
83
  "peerDependenciesMeta": {
83
84
  "@howaboua/pi-gippity-control": {
84
85
  "optional": true
86
+ },
87
+ "@howaboua/pi-codex-conversion": {
88
+ "optional": true
85
89
  }
86
90
  },
87
91
  "devDependencies": {
@@ -93,7 +97,8 @@
93
97
  "knip": "^6.41.0",
94
98
  "typebox": "1.3.37",
95
99
  "@typescript/native-preview": "^7.0.0-dev.20260707.2",
96
- "typescript": "^7.0.2"
100
+ "typescript": "^7.0.2",
101
+ "@howaboua/pi-codex-conversion": "4.0.2"
97
102
  },
98
103
  "publishConfig": {
99
104
  "access": "public"