pi-adaptive-thinking 0.3.0 → 0.4.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/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
2
2
|
import { open, rm, stat } from "node:fs/promises";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
import { StringEnum } from "@earendil-works/pi-ai";
|
|
5
6
|
import type {
|
|
6
7
|
AgentEndEvent,
|
|
7
8
|
AgentToolResult,
|
|
@@ -12,10 +13,11 @@ import type {
|
|
|
12
13
|
ToolCallEventResult,
|
|
13
14
|
ToolDefinition,
|
|
14
15
|
} from "@earendil-works/pi-coding-agent";
|
|
15
|
-
import { type Static, Type } from "typebox";
|
|
16
|
+
import { type Static, type TSchema, Type } from "typebox";
|
|
16
17
|
import { Parse } from "typebox/value";
|
|
17
18
|
import { loadConfig, type AdaptiveThinkingConfig } from "./config-loader.js";
|
|
18
19
|
import {
|
|
20
|
+
fallbackThinkingLevels,
|
|
19
21
|
isThinkingLevel,
|
|
20
22
|
resolveSupportedThinkingLevels,
|
|
21
23
|
type PiThinkingLevel,
|
|
@@ -53,9 +55,26 @@ type ToolParameters = Static<typeof ToolParameters>;
|
|
|
53
55
|
|
|
54
56
|
const StatusToolParameters = Type.Object({}, { additionalProperties: false });
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
const ThinkingLevelSchema = StringEnum(fallbackThinkingLevels);
|
|
59
|
+
|
|
60
|
+
/** Exact final-details schema returned by the Thinking Level Status tool. */
|
|
61
|
+
export const ThinkingLevelStatusSchema = Type.Object(
|
|
62
|
+
{
|
|
63
|
+
currentLevel: Type.Union([ThinkingLevelSchema, Type.Literal("unknown")]),
|
|
64
|
+
supportedLevels: Type.Array(ThinkingLevelSchema),
|
|
65
|
+
},
|
|
66
|
+
{ additionalProperties: false },
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const UndefinedToolOutputSchema = Type.Undefined();
|
|
70
|
+
|
|
71
|
+
type ThinkingLevelStatus = Static<typeof ThinkingLevelStatusSchema>;
|
|
72
|
+
|
|
73
|
+
type ToolDefinitionWithOutputSchema<
|
|
74
|
+
TParameters extends TSchema,
|
|
75
|
+
TOutputSchema extends TSchema,
|
|
76
|
+
> = ToolDefinition<TParameters, Static<TOutputSchema>> & {
|
|
77
|
+
outputSchema: TOutputSchema;
|
|
59
78
|
};
|
|
60
79
|
|
|
61
80
|
/** The extension-context fields Adaptive Thinking reads at its lifecycle and tool seams. */
|
|
@@ -85,11 +104,14 @@ export type AdaptiveThinkingSetThinkingLevelParameters = Static<typeof ToolParam
|
|
|
85
104
|
/** Current and supported thinking levels returned by the status tool. */
|
|
86
105
|
export type AdaptiveThinkingLevelStatus = ThinkingLevelStatus;
|
|
87
106
|
|
|
88
|
-
type SetThinkingLevelTool = Omit<
|
|
107
|
+
type SetThinkingLevelTool = Omit<
|
|
108
|
+
ToolDefinitionWithOutputSchema<typeof ToolParameters, typeof UndefinedToolOutputSchema>,
|
|
109
|
+
"execute"
|
|
110
|
+
> & {
|
|
89
111
|
execute: AdaptiveThinkingToolExecution<AdaptiveThinkingSetThinkingLevelParameters, undefined>;
|
|
90
112
|
};
|
|
91
113
|
type GetThinkingLevelTool = Omit<
|
|
92
|
-
|
|
114
|
+
ToolDefinitionWithOutputSchema<typeof StatusToolParameters, typeof ThinkingLevelStatusSchema>,
|
|
93
115
|
"execute"
|
|
94
116
|
> & {
|
|
95
117
|
execute: AdaptiveThinkingToolExecution<Record<string, never>, ThinkingLevelStatus>;
|
|
@@ -337,6 +359,7 @@ export function registerAdaptiveThinking(pi: AdaptiveThinkingExtensionHost) {
|
|
|
337
359
|
`Do not call ${config.toolName} twice in a row; reassess only after new evidence from other tool calls or user input.`,
|
|
338
360
|
],
|
|
339
361
|
parameters: ToolParameters,
|
|
362
|
+
outputSchema: UndefinedToolOutputSchema,
|
|
340
363
|
execute: async (toolCallId, params: ToolParameters, _signal, _onUpdate, ctx) => {
|
|
341
364
|
const state = runtime;
|
|
342
365
|
if (!state) return textResult("Adaptive Thinking is not enabled for this session.");
|
|
@@ -399,6 +422,7 @@ export function registerAdaptiveThinking(pi: AdaptiveThinkingExtensionHost) {
|
|
|
399
422
|
`Use ${config.statusToolName} only when thinking-level state is uncertain; do not poll it routinely.`,
|
|
400
423
|
],
|
|
401
424
|
parameters: StatusToolParameters,
|
|
425
|
+
outputSchema: ThinkingLevelStatusSchema,
|
|
402
426
|
execute: async (_toolCallId, _params, _signal, _onUpdate, ctx) => {
|
|
403
427
|
const currentLevel = pi.getThinkingLevel();
|
|
404
428
|
return thinkingLevelStatusResult(
|