pi-openai-toolkit 0.14.4 → 0.14.6
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/README.md +119 -147
- package/README.zh.md +119 -151
- package/docs/internals.md +42 -21
- package/package.json +127 -127
- package/src/auto-mode/classifier.ts +165 -165
- package/src/auto-mode/policy.ts +146 -146
- package/src/auto-mode/prompt.ts +279 -279
- package/src/auto-mode/reviewer.ts +325 -325
- package/src/auto-mode/transcript.ts +133 -133
- package/src/auto-mode/types.ts +137 -137
- package/src/codex-astra/effort-planner.ts +175 -175
- package/src/codex-astra/extension.ts +122 -122
- package/src/config.ts +621 -592
- package/src/context-management/codex-provider.ts +260 -260
- package/src/context-management/history-notes.ts +357 -325
- package/src/context-management/messages.ts +112 -106
- package/src/context-management/namespace-tools.ts +426 -426
- package/src/context-management/tool-contract.ts +23 -23
- package/src/context-management/tools.ts +306 -311
- package/src/context-management/types.ts +168 -161
- package/src/context-management/window-budget.ts +83 -83
- package/src/context-management/window-manager.ts +60 -51
- package/src/context-management/window-request.ts +125 -125
- package/src/debug.ts +1 -1
- package/src/extension-runtime.ts +34 -9
- package/src/image-generation/artifacts.ts +237 -237
- package/src/image-generation/client.ts +248 -248
- package/src/image-generation/eligibility.ts +18 -18
- package/src/image-generation/extension.ts +19 -2
- package/src/image-generation/protocol.ts +473 -405
- package/src/image-generation/references.ts +194 -194
- package/src/image-generation/render.ts +252 -252
- package/src/image-generation/service.ts +249 -243
- package/src/image-generation/types.ts +189 -184
- package/src/model-scope.ts +17 -17
- package/src/provider-headers.ts +23 -23
- package/src/responses-headers.ts +173 -108
- package/src/runtime.ts +513 -477
- package/src/types.ts +11 -0
- package/src/web-search/extension.ts +80 -80
- package/src/web-search/payload.ts +96 -96
- package/src/web-search/prompt.ts +20 -20
- package/src/web-search/types.ts +45 -45
|
@@ -1,106 +1,112 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
3
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import {
|
|
5
|
-
CODEX_CONTEXT_WINDOW_MESSAGE_TYPE,
|
|
6
|
-
CONTEXT_MANAGEMENT_PROTOCOL,
|
|
7
|
-
CONTEXT_WINDOW_COMPACTION_STRATEGY,
|
|
8
|
-
CONTEXT_WINDOW_FALLBACK_BUFFER,
|
|
9
|
-
CONTEXT_WINDOW_REMINDER_THRESHOLD,
|
|
10
|
-
type CodexContextManagementMessageDetails,
|
|
11
|
-
type ContextManagementMessageKind,
|
|
12
|
-
type ContextWindowCompactionDetails,
|
|
13
|
-
type ContextWindowIdentity,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
lines.push(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
:
|
|
106
|
-
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
3
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import {
|
|
5
|
+
CODEX_CONTEXT_WINDOW_MESSAGE_TYPE,
|
|
6
|
+
CONTEXT_MANAGEMENT_PROTOCOL,
|
|
7
|
+
CONTEXT_WINDOW_COMPACTION_STRATEGY,
|
|
8
|
+
CONTEXT_WINDOW_FALLBACK_BUFFER,
|
|
9
|
+
CONTEXT_WINDOW_REMINDER_THRESHOLD,
|
|
10
|
+
type CodexContextManagementMessageDetails,
|
|
11
|
+
type ContextManagementMessageKind,
|
|
12
|
+
type ContextWindowCompactionDetails,
|
|
13
|
+
type ContextWindowIdentity,
|
|
14
|
+
type NotesCheckpointReceipt,
|
|
15
|
+
isCodexContextManagementMessageDetails,
|
|
16
|
+
isContextWindowCompactionDetails,
|
|
17
|
+
} from "./types";
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
CODEX_CONTEXT_WINDOW_MESSAGE_TYPE,
|
|
21
|
+
CONTEXT_WINDOW_COMPACTION_STRATEGY,
|
|
22
|
+
CONTEXT_WINDOW_FALLBACK_BUFFER,
|
|
23
|
+
CONTEXT_WINDOW_REMINDER_THRESHOLD,
|
|
24
|
+
isCodexContextManagementMessageDetails,
|
|
25
|
+
isContextWindowCompactionDetails,
|
|
26
|
+
};
|
|
27
|
+
export type {
|
|
28
|
+
CodexContextManagementMessageDetails,
|
|
29
|
+
ContextManagementMessageKind,
|
|
30
|
+
ContextWindowCompactionDetails,
|
|
31
|
+
ContextWindowIdentity,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const CONTEXT_WINDOW_COMPACTION_SUMMARY =
|
|
35
|
+
"[Pi Codex context-window boundary; no conversation summary was generated.]";
|
|
36
|
+
|
|
37
|
+
const CONTEXT_WINDOW_GUIDANCE = `<context_window_guidance>
|
|
38
|
+
Checkpoint the active request, known history IDs, decisions, progress, learnings and next steps in notes before new_context; no summary carries over. After rollover, read the checkpoint receipt note first when present; use a thread hint only as supplemental guidance. Use history only for a missing detail.
|
|
39
|
+
</context_window_guidance>`;
|
|
40
|
+
|
|
41
|
+
export function renderContextWindowMessage(
|
|
42
|
+
identity: ContextWindowIdentity,
|
|
43
|
+
threadHint?: string,
|
|
44
|
+
checkpoint?: NotesCheckpointReceipt,
|
|
45
|
+
): string {
|
|
46
|
+
const lines = [
|
|
47
|
+
"<context_window>",
|
|
48
|
+
"Agent name: /root",
|
|
49
|
+
`First context window id: ${identity.firstWindowId}`,
|
|
50
|
+
`Current context window id: ${identity.currentWindowId}`,
|
|
51
|
+
];
|
|
52
|
+
if (identity.previousWindowId) lines.push(`Previous context window id: ${identity.previousWindowId}`);
|
|
53
|
+
if (checkpoint) {
|
|
54
|
+
lines.push("Checkpoint successfully written:");
|
|
55
|
+
lines.push(` Read this note before doing anything else with notes action "read_file": ${JSON.stringify(checkpoint.path)}`);
|
|
56
|
+
}
|
|
57
|
+
if (threadHint) lines.push(threadHint);
|
|
58
|
+
lines.push("</context_window>");
|
|
59
|
+
return `${CONTEXT_WINDOW_GUIDANCE}\n\n${lines.join("\n")}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function renderContextWindowReminder(remainingTokens: number): string {
|
|
63
|
+
return `<context_window_reminder>
|
|
64
|
+
Only ${Math.max(0, Math.floor(remainingTokens))} context tokens remain. Checkpoint the active request, state and known history IDs in notes, then call new_context; no conversation summary carries over.
|
|
65
|
+
</context_window_reminder>`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const CONTEXT_WINDOW_FALLBACK_MESSAGE = `<context_window_reminder>
|
|
69
|
+
Context exhausted. Do not continue or answer. Make exactly one notes write or append call that checkpoints the active request, state and known history IDs, then call new_context. Use no other tools before rollover.
|
|
70
|
+
</context_window_reminder>`;
|
|
71
|
+
|
|
72
|
+
export function isContextWindowBoundary(
|
|
73
|
+
message: AgentMessage,
|
|
74
|
+
): message is Extract<AgentMessage, { role: "custom" }> & {
|
|
75
|
+
details: CodexContextManagementMessageDetails;
|
|
76
|
+
} {
|
|
77
|
+
return (
|
|
78
|
+
message.role === "custom" &&
|
|
79
|
+
message.customType === CODEX_CONTEXT_WINDOW_MESSAGE_TYPE &&
|
|
80
|
+
isCodexContextManagementMessageDetails(message.details) &&
|
|
81
|
+
message.details.contextManagement.kind === "window"
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function sendContextWindowMessage(
|
|
86
|
+
pi: ExtensionAPI,
|
|
87
|
+
content: string,
|
|
88
|
+
kind: ContextManagementMessageKind,
|
|
89
|
+
identity: ContextWindowIdentity,
|
|
90
|
+
options: { triggerTurn: boolean; sessionId?: string },
|
|
91
|
+
trimPreviousWindow = false,
|
|
92
|
+
): void {
|
|
93
|
+
const details: CodexContextManagementMessageDetails = {
|
|
94
|
+
protocol: CONTEXT_MANAGEMENT_PROTOCOL,
|
|
95
|
+
id: randomUUID(),
|
|
96
|
+
...(options.sessionId ? { sessionId: options.sessionId } : {}),
|
|
97
|
+
contextManagement: {
|
|
98
|
+
protocol: CONTEXT_MANAGEMENT_PROTOCOL,
|
|
99
|
+
kind,
|
|
100
|
+
...identity,
|
|
101
|
+
...(trimPreviousWindow ? { trimPreviousWindow: true as const } : {}),
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
pi.sendMessage({
|
|
105
|
+
customType: CODEX_CONTEXT_WINDOW_MESSAGE_TYPE,
|
|
106
|
+
content,
|
|
107
|
+
display: true,
|
|
108
|
+
details,
|
|
109
|
+
}, options.triggerTurn
|
|
110
|
+
? { deliverAs: "steer", triggerTurn: true }
|
|
111
|
+
: { triggerTurn: false });
|
|
112
|
+
}
|