pi-openai-toolkit 0.20.7 → 0.21.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/LICENSE +21 -21
- package/NOTICE +83 -83
- package/README.md +8 -26
- package/README.zh.md +8 -26
- package/config.schema.json +278 -366
- package/docs/configuration.md +294 -310
- package/docs/internals.md +166 -175
- package/package.json +3 -13
- package/src/compact-client.ts +412 -389
- package/src/compaction-errors.ts +96 -0
- package/src/compaction-projection.ts +35 -35
- package/src/config/legacy.ts +519 -717
- package/src/config/migration.ts +103 -100
- package/src/config/notifications.ts +36 -28
- package/src/config/policy.ts +10 -18
- package/src/config/v2.ts +1167 -1380
- package/src/config.ts +310 -319
- package/src/context-management/codex-provider.ts +270 -270
- package/src/context-management/history-notes.ts +357 -357
- package/src/context-management/manual-compact.ts +0 -11
- package/src/context-management/tools.ts +371 -371
- package/src/context-management/types.ts +168 -168
- package/src/context-management/window-manager.ts +801 -801
- package/src/debug.ts +238 -237
- package/src/deferred-tool-carryover.ts +282 -282
- package/src/details-store.ts +151 -151
- package/src/extension-runtime.ts +1662 -1623
- package/src/image-generation/extension.ts +189 -189
- package/src/image-generation/protocol.ts +579 -579
- package/src/image-generation/types.ts +300 -300
- package/src/native-fallback.ts +4 -132
- package/src/payload-rewrite.ts +515 -518
- package/src/pi-context-hook.ts +117 -117
- package/src/remote-v2-client.ts +811 -814
- package/src/request-context-cache.ts +155 -155
- package/src/responses-headers.ts +180 -180
- package/src/runtime.ts +865 -832
- package/src/serializer.ts +882 -882
- package/src/supported-environment.ts +27 -27
- package/src/types.ts +565 -648
- package/src/web-search/alpha-client.ts +876 -876
- package/src/web-search/extension.ts +530 -530
- package/src/web-search/payload.ts +299 -299
- package/src/web-search/prompt.ts +60 -60
- package/src/web-search/types.ts +166 -166
- package/tsconfig.check.json +50 -54
- package/src/auto-mode/classifier.ts +0 -161
- package/src/auto-mode/extension.ts +0 -691
- package/src/auto-mode/model-selection-guard.ts +0 -52
- package/src/auto-mode/policy.ts +0 -146
- package/src/auto-mode/prompt.ts +0 -279
- package/src/auto-mode/reviewer.ts +0 -325
- package/src/auto-mode/tool-review-tui.ts +0 -211
- package/src/auto-mode/transcript.ts +0 -135
- package/src/auto-mode/types.ts +0 -137
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
import type { ResponsesCompatibleRequestPayload } from "./runtime";
|
|
2
|
-
import { LOCAL_WEB_SEARCH_TOOL_NAME, WEB_RUN_TOOL_NAME } from "./web-search/types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Explicit allowlist of fields mirrored from the latest live Responses request.
|
|
6
|
-
* remote_compaction_v2 has no provider payload at session_before_compact time, so
|
|
7
|
-
* the extension reuses only these compact-relevant fields for the same runtime identity.
|
|
8
|
-
* `stream`, `store`, `input`, and trigger semantics are always forced separately.
|
|
9
|
-
*/
|
|
10
|
-
export type CompactionRequestExtras = {
|
|
11
|
-
tools?: unknown[];
|
|
12
|
-
parallel_tool_calls?: boolean;
|
|
13
|
-
reasoning?: Record<string, unknown>;
|
|
14
|
-
service_tier?: string;
|
|
15
|
-
prompt_cache_key?: string;
|
|
16
|
-
prompt_cache_retention?: "in_memory" | "24h";
|
|
17
|
-
prompt_cache_options?: Record<string, unknown>;
|
|
18
|
-
text?: Record<string, unknown>;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type RequestContextIdentity = {
|
|
22
|
-
provider: string;
|
|
23
|
-
api: string;
|
|
24
|
-
model: string;
|
|
25
|
-
baseUrl: string;
|
|
26
|
-
sessionId?: string;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type CachedRequestContext = {
|
|
30
|
-
identity: RequestContextIdentity;
|
|
31
|
-
extras: CompactionRequestExtras;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type RequestContextCaptureOptions = {
|
|
35
|
-
/** Standalone Web Search is a local tool and must not enter synthetic compact requests. */
|
|
36
|
-
excludeWebSearchTools?: boolean;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
let cached: CachedRequestContext | undefined;
|
|
40
|
-
|
|
41
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
42
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function isWebSearchTool(value: unknown): boolean {
|
|
46
|
-
if (!isRecord(value)) return false;
|
|
47
|
-
if (value.type === "web_search" || value.type === "web_search_preview") return true;
|
|
48
|
-
return value.type === "function" && (value.name === LOCAL_WEB_SEARCH_TOOL_NAME || value.name === WEB_RUN_TOOL_NAME);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function sameIdentity(cachedIdentity: RequestContextIdentity, current: RequestContextIdentity): boolean {
|
|
52
|
-
return (
|
|
53
|
-
cachedIdentity.provider === current.provider &&
|
|
54
|
-
cachedIdentity.api === current.api &&
|
|
55
|
-
cachedIdentity.model === current.model &&
|
|
56
|
-
cachedIdentity.baseUrl === current.baseUrl &&
|
|
57
|
-
cachedIdentity.sessionId === current.sessionId
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Remember compact-relevant fields from a live Responses request payload.
|
|
63
|
-
* Purely additive metadata: failures are swallowed so caching can never
|
|
64
|
-
* break the provider request path.
|
|
65
|
-
*/
|
|
66
|
-
export function rememberRequestContext(
|
|
67
|
-
payload: ResponsesCompatibleRequestPayload,
|
|
68
|
-
identity: RequestContextIdentity,
|
|
69
|
-
options: RequestContextCaptureOptions = {},
|
|
70
|
-
): void {
|
|
71
|
-
try {
|
|
72
|
-
if (payload.model !== identity.model) {
|
|
73
|
-
cached = undefined;
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const extras: CompactionRequestExtras = {};
|
|
78
|
-
if (Array.isArray(payload.tools)) {
|
|
79
|
-
const tools = options.excludeWebSearchTools
|
|
80
|
-
? payload.tools.filter((tool) => !isWebSearchTool(tool))
|
|
81
|
-
: payload.tools;
|
|
82
|
-
extras.tools = structuredClone(tools);
|
|
83
|
-
}
|
|
84
|
-
if (typeof payload.parallel_tool_calls === "boolean") {
|
|
85
|
-
extras.parallel_tool_calls = payload.parallel_tool_calls;
|
|
86
|
-
}
|
|
87
|
-
if (isRecord(payload.reasoning)) {
|
|
88
|
-
extras.reasoning = structuredClone(payload.reasoning);
|
|
89
|
-
}
|
|
90
|
-
if (typeof payload.service_tier === "string" && payload.service_tier.trim().length > 0) {
|
|
91
|
-
extras.service_tier = payload.service_tier;
|
|
92
|
-
}
|
|
93
|
-
if (typeof payload.prompt_cache_key === "string" && payload.prompt_cache_key.trim().length > 0) {
|
|
94
|
-
extras.prompt_cache_key = payload.prompt_cache_key;
|
|
95
|
-
}
|
|
96
|
-
if (payload.prompt_cache_retention === "in_memory" || payload.prompt_cache_retention === "24h") {
|
|
97
|
-
extras.prompt_cache_retention = payload.prompt_cache_retention;
|
|
98
|
-
}
|
|
99
|
-
if (isRecord(payload.prompt_cache_options)) {
|
|
100
|
-
extras.prompt_cache_options = structuredClone(payload.prompt_cache_options);
|
|
101
|
-
}
|
|
102
|
-
if (isRecord(payload.text)) {
|
|
103
|
-
extras.text = structuredClone(payload.text);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
cached = {
|
|
107
|
-
identity: structuredClone(identity),
|
|
108
|
-
extras,
|
|
109
|
-
};
|
|
110
|
-
} catch {
|
|
111
|
-
cached = undefined;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Look up the exact live-request identity. When building a synthetic request,
|
|
117
|
-
* supply its producer to omit cache fields unsupported by that model/API.
|
|
118
|
-
* No TTL conversion or implicit cache policy is applied.
|
|
119
|
-
*/
|
|
120
|
-
export function getCompactionRequestExtras(
|
|
121
|
-
identity: RequestContextIdentity,
|
|
122
|
-
producer?: { api: string; compat?: unknown },
|
|
123
|
-
): CompactionRequestExtras | undefined {
|
|
124
|
-
if (!cached || !sameIdentity(cached.identity, identity)) {
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
const extras = structuredClone(cached.extras);
|
|
130
|
-
if (producer) {
|
|
131
|
-
const compat = isRecord(producer.compat) ? producer.compat : {};
|
|
132
|
-
if (producer.api !== "openai-responses") {
|
|
133
|
-
delete extras.prompt_cache_options;
|
|
134
|
-
delete extras.prompt_cache_retention;
|
|
135
|
-
} else {
|
|
136
|
-
if (compat.supportsExplicitPromptCacheMode === true) {
|
|
137
|
-
delete extras.prompt_cache_retention;
|
|
138
|
-
} else {
|
|
139
|
-
delete extras.prompt_cache_options;
|
|
140
|
-
}
|
|
141
|
-
if (compat.supportsLongCacheRetention === false) {
|
|
142
|
-
if (extras.prompt_cache_options?.ttl !== undefined) delete extras.prompt_cache_options;
|
|
143
|
-
if (extras.prompt_cache_retention === "24h") delete extras.prompt_cache_retention;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return extras;
|
|
148
|
-
} catch {
|
|
149
|
-
return undefined;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function clearRequestContextCache(): void {
|
|
154
|
-
cached = undefined;
|
|
155
|
-
}
|
|
1
|
+
import type { ResponsesCompatibleRequestPayload } from "./runtime";
|
|
2
|
+
import { LOCAL_WEB_SEARCH_TOOL_NAME, WEB_RUN_TOOL_NAME } from "./web-search/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Explicit allowlist of fields mirrored from the latest live Responses request.
|
|
6
|
+
* remote_compaction_v2 has no provider payload at session_before_compact time, so
|
|
7
|
+
* the extension reuses only these compact-relevant fields for the same runtime identity.
|
|
8
|
+
* `stream`, `store`, `input`, and trigger semantics are always forced separately.
|
|
9
|
+
*/
|
|
10
|
+
export type CompactionRequestExtras = {
|
|
11
|
+
tools?: unknown[];
|
|
12
|
+
parallel_tool_calls?: boolean;
|
|
13
|
+
reasoning?: Record<string, unknown>;
|
|
14
|
+
service_tier?: string;
|
|
15
|
+
prompt_cache_key?: string;
|
|
16
|
+
prompt_cache_retention?: "in_memory" | "24h";
|
|
17
|
+
prompt_cache_options?: Record<string, unknown>;
|
|
18
|
+
text?: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type RequestContextIdentity = {
|
|
22
|
+
provider: string;
|
|
23
|
+
api: string;
|
|
24
|
+
model: string;
|
|
25
|
+
baseUrl: string;
|
|
26
|
+
sessionId?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type CachedRequestContext = {
|
|
30
|
+
identity: RequestContextIdentity;
|
|
31
|
+
extras: CompactionRequestExtras;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type RequestContextCaptureOptions = {
|
|
35
|
+
/** Standalone Web Search is a local tool and must not enter synthetic compact requests. */
|
|
36
|
+
excludeWebSearchTools?: boolean;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
let cached: CachedRequestContext | undefined;
|
|
40
|
+
|
|
41
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
42
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isWebSearchTool(value: unknown): boolean {
|
|
46
|
+
if (!isRecord(value)) return false;
|
|
47
|
+
if (value.type === "web_search" || value.type === "web_search_preview") return true;
|
|
48
|
+
return value.type === "function" && (value.name === LOCAL_WEB_SEARCH_TOOL_NAME || value.name === WEB_RUN_TOOL_NAME);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function sameIdentity(cachedIdentity: RequestContextIdentity, current: RequestContextIdentity): boolean {
|
|
52
|
+
return (
|
|
53
|
+
cachedIdentity.provider === current.provider &&
|
|
54
|
+
cachedIdentity.api === current.api &&
|
|
55
|
+
cachedIdentity.model === current.model &&
|
|
56
|
+
cachedIdentity.baseUrl === current.baseUrl &&
|
|
57
|
+
cachedIdentity.sessionId === current.sessionId
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Remember compact-relevant fields from a live Responses request payload.
|
|
63
|
+
* Purely additive metadata: failures are swallowed so caching can never
|
|
64
|
+
* break the provider request path.
|
|
65
|
+
*/
|
|
66
|
+
export function rememberRequestContext(
|
|
67
|
+
payload: ResponsesCompatibleRequestPayload,
|
|
68
|
+
identity: RequestContextIdentity,
|
|
69
|
+
options: RequestContextCaptureOptions = {},
|
|
70
|
+
): void {
|
|
71
|
+
try {
|
|
72
|
+
if (payload.model !== identity.model) {
|
|
73
|
+
cached = undefined;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const extras: CompactionRequestExtras = {};
|
|
78
|
+
if (Array.isArray(payload.tools)) {
|
|
79
|
+
const tools = options.excludeWebSearchTools
|
|
80
|
+
? payload.tools.filter((tool) => !isWebSearchTool(tool))
|
|
81
|
+
: payload.tools;
|
|
82
|
+
extras.tools = structuredClone(tools);
|
|
83
|
+
}
|
|
84
|
+
if (typeof payload.parallel_tool_calls === "boolean") {
|
|
85
|
+
extras.parallel_tool_calls = payload.parallel_tool_calls;
|
|
86
|
+
}
|
|
87
|
+
if (isRecord(payload.reasoning)) {
|
|
88
|
+
extras.reasoning = structuredClone(payload.reasoning);
|
|
89
|
+
}
|
|
90
|
+
if (typeof payload.service_tier === "string" && payload.service_tier.trim().length > 0) {
|
|
91
|
+
extras.service_tier = payload.service_tier;
|
|
92
|
+
}
|
|
93
|
+
if (typeof payload.prompt_cache_key === "string" && payload.prompt_cache_key.trim().length > 0) {
|
|
94
|
+
extras.prompt_cache_key = payload.prompt_cache_key;
|
|
95
|
+
}
|
|
96
|
+
if (payload.prompt_cache_retention === "in_memory" || payload.prompt_cache_retention === "24h") {
|
|
97
|
+
extras.prompt_cache_retention = payload.prompt_cache_retention;
|
|
98
|
+
}
|
|
99
|
+
if (isRecord(payload.prompt_cache_options)) {
|
|
100
|
+
extras.prompt_cache_options = structuredClone(payload.prompt_cache_options);
|
|
101
|
+
}
|
|
102
|
+
if (isRecord(payload.text)) {
|
|
103
|
+
extras.text = structuredClone(payload.text);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
cached = {
|
|
107
|
+
identity: structuredClone(identity),
|
|
108
|
+
extras,
|
|
109
|
+
};
|
|
110
|
+
} catch {
|
|
111
|
+
cached = undefined;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Look up the exact live-request identity. When building a synthetic request,
|
|
117
|
+
* supply its producer to omit cache fields unsupported by that model/API.
|
|
118
|
+
* No TTL conversion or implicit cache policy is applied.
|
|
119
|
+
*/
|
|
120
|
+
export function getCompactionRequestExtras(
|
|
121
|
+
identity: RequestContextIdentity,
|
|
122
|
+
producer?: { api: string; compat?: unknown },
|
|
123
|
+
): CompactionRequestExtras | undefined {
|
|
124
|
+
if (!cached || !sameIdentity(cached.identity, identity)) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
const extras = structuredClone(cached.extras);
|
|
130
|
+
if (producer) {
|
|
131
|
+
const compat = isRecord(producer.compat) ? producer.compat : {};
|
|
132
|
+
if (producer.api !== "openai-responses") {
|
|
133
|
+
delete extras.prompt_cache_options;
|
|
134
|
+
delete extras.prompt_cache_retention;
|
|
135
|
+
} else {
|
|
136
|
+
if (compat.supportsExplicitPromptCacheMode === true) {
|
|
137
|
+
delete extras.prompt_cache_retention;
|
|
138
|
+
} else {
|
|
139
|
+
delete extras.prompt_cache_options;
|
|
140
|
+
}
|
|
141
|
+
if (compat.supportsLongCacheRetention === false) {
|
|
142
|
+
if (extras.prompt_cache_options?.ttl !== undefined) delete extras.prompt_cache_options;
|
|
143
|
+
if (extras.prompt_cache_retention === "24h") delete extras.prompt_cache_retention;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return extras;
|
|
148
|
+
} catch {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function clearRequestContextCache(): void {
|
|
154
|
+
cached = undefined;
|
|
155
|
+
}
|