pi-roundtable 0.38.0 → 0.38.1
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 +7 -0
- package/package.json +1 -1
- package/src/core/agents/team-helpers.ts +11 -2
- package/src/core/plugin-api/define.ts +3 -0
- package/src/core/runtime/extensions/ask-user-arguments.ts +1 -10
- package/src/core/runtime/text-tools.ts +5 -2
- package/src/core/shared/json-arguments.ts +46 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.38.1] - 2026-11-08
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- A list a model sends as JSON text, such as `helper_end { names: "[\"blog-2\"]" }`, reaches the tool as the list. Pi wrapped such text whole in a list of one, so `helper_end` found no temp knight by that name; text tools and `defineTool` tools now decode a top-level string their schema refuses when its JSON is an array or object the schema accepts. `ask_user` shares the same decoder.
|
|
13
|
+
- `helper_end` with `"finished"` says which temp knights it passed over because they are still working, such as one whose action waits for the owner's approval, and that ending one by name archives it anyway.
|
|
14
|
+
|
|
8
15
|
## [0.38.0] - 2026-11-08
|
|
9
16
|
|
|
10
17
|
### Added
|
package/package.json
CHANGED
|
@@ -72,12 +72,21 @@ export class TeamHelpers {
|
|
|
72
72
|
);
|
|
73
73
|
return own;
|
|
74
74
|
});
|
|
75
|
+
// "finished" passes over the ones still working; saying which keeps one from being forgotten.
|
|
76
|
+
const working =
|
|
77
|
+
names === "finished"
|
|
78
|
+
? mine.filter((agent) => agent.finishedAt === undefined)
|
|
79
|
+
: [];
|
|
80
|
+
const left =
|
|
81
|
+
working.length === 0
|
|
82
|
+
? ""
|
|
83
|
+
: ` Still working, so not archived: ${working.map((agent) => agent.name).join(", ")}. A temp knight works while a turn runs, a message waits for it, or an action of its waits for the owner's approval; end one by name to archive it anyway.`;
|
|
75
84
|
if (wanted.length === 0)
|
|
76
|
-
return
|
|
85
|
+
return `None of your temp knights is finished yet, so none was archived.${left}`;
|
|
77
86
|
const archived = await this.archive(wanted.map((agent) => agent.name));
|
|
78
87
|
for (const listener of this.#ended)
|
|
79
88
|
listener({ parent: caller.name, names: archived });
|
|
80
|
-
return `Archived ${archived.length} temp knight${archived.length === 1 ? "" : "s"}: ${archived.join(", ")}. Their history stays readable, and the owner can restore them
|
|
89
|
+
return `Archived ${archived.length} temp knight${archived.length === 1 ? "" : "s"}: ${archived.join(", ")}. Their history stays readable, and the owner can restore them.${left}`;
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
/**
|
|
@@ -14,6 +14,7 @@ import { messages } from "../i18n/index.ts";
|
|
|
14
14
|
import { type Speaker, TIERS, type Tier } from "../identity/speakers.ts";
|
|
15
15
|
import type { ApprovedBy } from "../interactions/prompts.ts";
|
|
16
16
|
import { PluginError } from "../kernel/errors.ts";
|
|
17
|
+
import { decodeJsonArguments } from "../shared/json-arguments.ts";
|
|
17
18
|
import {
|
|
18
19
|
type ToolOutput,
|
|
19
20
|
toolError,
|
|
@@ -206,6 +207,8 @@ export function defineTool<Schema extends TObject>(
|
|
|
206
207
|
label: name,
|
|
207
208
|
description: spec.description,
|
|
208
209
|
parameters: spec.parameters,
|
|
210
|
+
prepareArguments: (args) =>
|
|
211
|
+
decodeJsonArguments(spec.parameters, args) as never,
|
|
209
212
|
execute: async (toolCallId, params, signal) => {
|
|
210
213
|
try {
|
|
211
214
|
return toolOutput(
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// pi-lens-ignore: no-unknown-returns — this reads untyped model JSON; the tool schema is where it is parsed
|
|
3
|
-
function decoded(value: unknown): unknown {
|
|
4
|
-
if (typeof value !== "string") return value;
|
|
5
|
-
try {
|
|
6
|
-
return JSON.parse(value) as unknown;
|
|
7
|
-
} catch {
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
import { decodedJson as decoded } from "../../shared/json-arguments.ts";
|
|
11
2
|
|
|
12
3
|
/**
|
|
13
4
|
* The arguments of an `ask_user` call in the `questions` form: a legacy call's top-level
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ExtensionFactory } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { TSchema } from "typebox";
|
|
3
3
|
import { AgentError } from "../domain/errors.ts";
|
|
4
|
+
import { decodeJsonArguments } from "../shared/json-arguments.ts";
|
|
4
5
|
import { toolError, toolText } from "../shared/tool-result.ts";
|
|
5
6
|
|
|
6
7
|
export type ToolInput = Record<string, unknown>;
|
|
@@ -15,8 +16,8 @@ export interface TextToolDef<Name extends string = string> {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
|
-
* Registers text tools. A
|
|
19
|
-
* error fails the call.
|
|
19
|
+
* Registers text tools. A list or object the model sent as JSON text is decoded first. A thrown
|
|
20
|
+
* `refusal` becomes an error result the model reads; any other error fails the call.
|
|
20
21
|
*/
|
|
21
22
|
export function textToolsExtension(
|
|
22
23
|
defs: readonly TextToolDef[],
|
|
@@ -29,6 +30,8 @@ export function textToolsExtension(
|
|
|
29
30
|
label: def.label,
|
|
30
31
|
description: def.description,
|
|
31
32
|
parameters: def.parameters,
|
|
33
|
+
prepareArguments: (args) =>
|
|
34
|
+
decodeJsonArguments(def.parameters, args) as ToolInput,
|
|
32
35
|
execute: async (_toolCallId, params, signal) => {
|
|
33
36
|
try {
|
|
34
37
|
return toolText(await def.run(params as ToolInput, signal));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { TSchema } from "typebox";
|
|
2
|
+
import Value from "typebox/value";
|
|
3
|
+
|
|
4
|
+
/** Parses a value a model double-encoded as a JSON string; anything else, or a bad string, comes back as it was. */
|
|
5
|
+
// pi-lens-ignore: no-unknown-returns — this reads untyped model JSON; the tool schema is where it is parsed
|
|
6
|
+
export function decodedJson(value: unknown): unknown {
|
|
7
|
+
if (typeof value !== "string") return value;
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(value) as unknown;
|
|
10
|
+
} catch {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A tool call's arguments with each top-level string the schema refuses, but whose JSON decodes
|
|
17
|
+
* to an array or object it accepts, replaced by that value. A model sometimes sends a list as the
|
|
18
|
+
* text `["a"]`, most often where the schema offers a list or a word; pi would otherwise wrap that
|
|
19
|
+
* text whole in a list of one. Anything else is left for the schema to judge.
|
|
20
|
+
*/
|
|
21
|
+
// pi-lens-ignore: no-unknown-returns — pi checks the prepared arguments against the tool schema right after
|
|
22
|
+
export function decodeJsonArguments(schema: TSchema, args: unknown): unknown {
|
|
23
|
+
const properties = (schema as { properties?: Record<string, TSchema> })
|
|
24
|
+
.properties;
|
|
25
|
+
if (
|
|
26
|
+
!properties ||
|
|
27
|
+
typeof args !== "object" ||
|
|
28
|
+
args === null ||
|
|
29
|
+
Array.isArray(args)
|
|
30
|
+
)
|
|
31
|
+
return args;
|
|
32
|
+
const input = args as Record<string, unknown>;
|
|
33
|
+
let output: Record<string, unknown> | undefined;
|
|
34
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
35
|
+
const value = input[key];
|
|
36
|
+
if (typeof value !== "string" || !/^\s*[[{]/.test(value)) continue;
|
|
37
|
+
if (Value.Check(property, value)) continue;
|
|
38
|
+
const decoded = decodedJson(value);
|
|
39
|
+
if (typeof decoded !== "object" || decoded === null) continue;
|
|
40
|
+
const converted = Value.Convert(property, decoded);
|
|
41
|
+
if (!Value.Check(property, converted)) continue;
|
|
42
|
+
output ??= { ...input };
|
|
43
|
+
output[key] = converted;
|
|
44
|
+
}
|
|
45
|
+
return output ?? args;
|
|
46
|
+
}
|