pi-openai-toolkit 0.23.2 → 0.24.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.
Files changed (54) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +83 -83
  3. package/README.md +4 -15
  4. package/README.zh.md +4 -15
  5. package/config.schema.json +264 -278
  6. package/docs/configuration.md +304 -306
  7. package/docs/internals.md +34 -120
  8. package/package.json +123 -136
  9. package/src/compact-client.ts +412 -412
  10. package/src/compaction-projection.ts +35 -35
  11. package/src/config/legacy.ts +469 -519
  12. package/src/config/migration.ts +115 -103
  13. package/src/config/notifications.ts +46 -36
  14. package/src/config/policy.ts +115 -116
  15. package/src/config/v2.ts +1128 -1167
  16. package/src/config.ts +320 -310
  17. package/src/debug.ts +238 -238
  18. package/src/deferred-tool-carryover.ts +282 -282
  19. package/src/details-store.ts +151 -151
  20. package/src/extension-runtime.ts +1095 -1919
  21. package/src/image-generation/extension.ts +189 -189
  22. package/src/image-generation/protocol.ts +579 -579
  23. package/src/image-generation/types.ts +300 -300
  24. package/src/native-fallback.ts +140 -152
  25. package/src/payload-rewrite.ts +515 -515
  26. package/src/pi-context-hook.ts +117 -117
  27. package/src/remote-v2-client.ts +811 -811
  28. package/src/request-context-cache.ts +155 -155
  29. package/src/responses-headers.ts +180 -180
  30. package/src/retired-remote-windows.ts +35 -0
  31. package/src/runtime.ts +875 -865
  32. package/src/serializer.ts +882 -882
  33. package/src/supported-environment.ts +27 -27
  34. package/src/types.ts +541 -565
  35. package/src/web-search/alpha-client.ts +876 -876
  36. package/src/web-search/extension.ts +530 -530
  37. package/src/web-search/payload.ts +299 -299
  38. package/src/web-search/prompt.ts +60 -60
  39. package/src/web-search/types.ts +166 -166
  40. package/tsconfig.check.json +50 -50
  41. package/src/context-management/codex-provider.ts +0 -270
  42. package/src/context-management/history-notes.ts +0 -357
  43. package/src/context-management/manual-compact.ts +0 -247
  44. package/src/context-management/messages.ts +0 -238
  45. package/src/context-management/namespace-tools.ts +0 -426
  46. package/src/context-management/responses-tools.ts +0 -238
  47. package/src/context-management/scoped-compaction.ts +0 -89
  48. package/src/context-management/tool-contract.ts +0 -62
  49. package/src/context-management/tools.ts +0 -371
  50. package/src/context-management/types.ts +0 -168
  51. package/src/context-management/window-budget.ts +0 -83
  52. package/src/context-management/window-bulk.ts +0 -155
  53. package/src/context-management/window-manager.ts +0 -912
  54. package/src/context-management/window-request.ts +0 -125
@@ -1,151 +1,151 @@
1
- import type { CompactionEntry, SessionEntry } from "@earendil-works/pi-coding-agent";
2
- import {
3
- isNativeCompactionDetails,
4
- isNativeCompactionEntry,
5
- type NativeCompactionDetails,
6
- type NativeCompactionEntry,
7
- type NativeCompactionIdentity,
8
- } from "./types";
9
-
10
- export type NativeCompactionEntryMatch = Partial<NativeCompactionIdentity>;
11
-
12
- export type LatestNativeCompactionResolutionFailureReason =
13
- | "no-compaction"
14
- | "latest-compaction-not-native"
15
- | "latest-native-compaction-mismatch";
16
-
17
- export type LatestNativeCompactionResolution =
18
- | {
19
- ok: true;
20
- entry: NativeCompactionEntry;
21
- index: number;
22
- latestCompactionIndex: number;
23
- }
24
- | {
25
- ok: false;
26
- reason: LatestNativeCompactionResolutionFailureReason;
27
- latestCompactionIndex?: number;
28
- latestCompaction?: CompactionEntry;
29
- };
30
-
31
- function entryMatches(entry: NativeCompactionEntry, match: NativeCompactionEntryMatch): boolean {
32
- const details = entry.details;
33
- if (!details) {
34
- return false;
35
- }
36
-
37
- return (
38
- (match.provider === undefined || details.provider === match.provider) &&
39
- (match.api === undefined || details.api === match.api) &&
40
- (match.model === undefined || details.model === match.model) &&
41
- (match.baseUrl === undefined || details.baseUrl === match.baseUrl)
42
- );
43
- }
44
-
45
- export function getNativeCompactionDetails(
46
- entry: CompactionEntry | SessionEntry | undefined,
47
- ): NativeCompactionDetails | undefined {
48
- if (!entry || entry.type !== "compaction") {
49
- return undefined;
50
- }
51
-
52
- return isNativeCompactionDetails(entry.details) ? entry.details : undefined;
53
- }
54
-
55
- export function isPersistedNativeCompactionEntry(
56
- entry: CompactionEntry | SessionEntry | undefined,
57
- ): entry is NativeCompactionEntry {
58
- return isNativeCompactionEntry(entry);
59
- }
60
-
61
- export function findLatestCompactionEntryIndex(entries: readonly SessionEntry[]): number | undefined {
62
- for (let index = entries.length - 1; index >= 0; index--) {
63
- if (entries[index]?.type === "compaction") {
64
- return index;
65
- }
66
- }
67
-
68
- return undefined;
69
- }
70
-
71
- export function findLatestCompactionEntry(entries: readonly SessionEntry[]): CompactionEntry | undefined {
72
- const index = findLatestCompactionEntryIndex(entries);
73
- return index === undefined ? undefined : (entries[index] as CompactionEntry);
74
- }
75
-
76
- export function findLatestNativeCompactionEntryIndex(
77
- entries: readonly SessionEntry[],
78
- match: NativeCompactionEntryMatch = {},
79
- ): number | undefined {
80
- for (let index = entries.length - 1; index >= 0; index--) {
81
- const entry = entries[index];
82
- if (!isPersistedNativeCompactionEntry(entry)) {
83
- continue;
84
- }
85
-
86
- if (!entryMatches(entry, match)) {
87
- continue;
88
- }
89
-
90
- return index;
91
- }
92
-
93
- return undefined;
94
- }
95
-
96
- export function findLatestNativeCompactionEntry(
97
- entries: readonly SessionEntry[],
98
- match: NativeCompactionEntryMatch = {},
99
- ): NativeCompactionEntry | undefined {
100
- const index = findLatestNativeCompactionEntryIndex(entries, match);
101
- return index === undefined ? undefined : (entries[index] as NativeCompactionEntry);
102
- }
103
-
104
- export function findLatestNativeCompactionDetails(
105
- entries: readonly SessionEntry[],
106
- match: NativeCompactionEntryMatch = {},
107
- ): NativeCompactionDetails | undefined {
108
- return findLatestNativeCompactionEntry(entries, match)?.details;
109
- }
110
-
111
- export function resolveLatestNativeCompactionEntry(
112
- entries: readonly SessionEntry[],
113
- match: NativeCompactionEntryMatch = {},
114
- ): LatestNativeCompactionResolution {
115
- const latestCompactionIndex = findLatestCompactionEntryIndex(entries);
116
- if (latestCompactionIndex === undefined) {
117
- return {
118
- ok: false,
119
- reason: "no-compaction",
120
- };
121
- }
122
-
123
- const latestCompaction = entries[latestCompactionIndex];
124
- if (!latestCompaction || latestCompaction.type !== "compaction" || !isPersistedNativeCompactionEntry(latestCompaction)) {
125
- return {
126
- ok: false,
127
- reason: "latest-compaction-not-native",
128
- latestCompactionIndex,
129
- latestCompaction:
130
- latestCompaction && latestCompaction.type === "compaction"
131
- ? (latestCompaction as CompactionEntry)
132
- : undefined,
133
- };
134
- }
135
-
136
- if (!entryMatches(latestCompaction, match)) {
137
- return {
138
- ok: false,
139
- reason: "latest-native-compaction-mismatch",
140
- latestCompactionIndex,
141
- latestCompaction,
142
- };
143
- }
144
-
145
- return {
146
- ok: true,
147
- entry: latestCompaction,
148
- index: latestCompactionIndex,
149
- latestCompactionIndex,
150
- };
151
- }
1
+ import type { CompactionEntry, SessionEntry } from "@earendil-works/pi-coding-agent";
2
+ import {
3
+ isNativeCompactionDetails,
4
+ isNativeCompactionEntry,
5
+ type NativeCompactionDetails,
6
+ type NativeCompactionEntry,
7
+ type NativeCompactionIdentity,
8
+ } from "./types";
9
+
10
+ export type NativeCompactionEntryMatch = Partial<NativeCompactionIdentity>;
11
+
12
+ export type LatestNativeCompactionResolutionFailureReason =
13
+ | "no-compaction"
14
+ | "latest-compaction-not-native"
15
+ | "latest-native-compaction-mismatch";
16
+
17
+ export type LatestNativeCompactionResolution =
18
+ | {
19
+ ok: true;
20
+ entry: NativeCompactionEntry;
21
+ index: number;
22
+ latestCompactionIndex: number;
23
+ }
24
+ | {
25
+ ok: false;
26
+ reason: LatestNativeCompactionResolutionFailureReason;
27
+ latestCompactionIndex?: number;
28
+ latestCompaction?: CompactionEntry;
29
+ };
30
+
31
+ function entryMatches(entry: NativeCompactionEntry, match: NativeCompactionEntryMatch): boolean {
32
+ const details = entry.details;
33
+ if (!details) {
34
+ return false;
35
+ }
36
+
37
+ return (
38
+ (match.provider === undefined || details.provider === match.provider) &&
39
+ (match.api === undefined || details.api === match.api) &&
40
+ (match.model === undefined || details.model === match.model) &&
41
+ (match.baseUrl === undefined || details.baseUrl === match.baseUrl)
42
+ );
43
+ }
44
+
45
+ export function getNativeCompactionDetails(
46
+ entry: CompactionEntry | SessionEntry | undefined,
47
+ ): NativeCompactionDetails | undefined {
48
+ if (!entry || entry.type !== "compaction") {
49
+ return undefined;
50
+ }
51
+
52
+ return isNativeCompactionDetails(entry.details) ? entry.details : undefined;
53
+ }
54
+
55
+ export function isPersistedNativeCompactionEntry(
56
+ entry: CompactionEntry | SessionEntry | undefined,
57
+ ): entry is NativeCompactionEntry {
58
+ return isNativeCompactionEntry(entry);
59
+ }
60
+
61
+ export function findLatestCompactionEntryIndex(entries: readonly SessionEntry[]): number | undefined {
62
+ for (let index = entries.length - 1; index >= 0; index--) {
63
+ if (entries[index]?.type === "compaction") {
64
+ return index;
65
+ }
66
+ }
67
+
68
+ return undefined;
69
+ }
70
+
71
+ export function findLatestCompactionEntry(entries: readonly SessionEntry[]): CompactionEntry | undefined {
72
+ const index = findLatestCompactionEntryIndex(entries);
73
+ return index === undefined ? undefined : (entries[index] as CompactionEntry);
74
+ }
75
+
76
+ export function findLatestNativeCompactionEntryIndex(
77
+ entries: readonly SessionEntry[],
78
+ match: NativeCompactionEntryMatch = {},
79
+ ): number | undefined {
80
+ for (let index = entries.length - 1; index >= 0; index--) {
81
+ const entry = entries[index];
82
+ if (!isPersistedNativeCompactionEntry(entry)) {
83
+ continue;
84
+ }
85
+
86
+ if (!entryMatches(entry, match)) {
87
+ continue;
88
+ }
89
+
90
+ return index;
91
+ }
92
+
93
+ return undefined;
94
+ }
95
+
96
+ export function findLatestNativeCompactionEntry(
97
+ entries: readonly SessionEntry[],
98
+ match: NativeCompactionEntryMatch = {},
99
+ ): NativeCompactionEntry | undefined {
100
+ const index = findLatestNativeCompactionEntryIndex(entries, match);
101
+ return index === undefined ? undefined : (entries[index] as NativeCompactionEntry);
102
+ }
103
+
104
+ export function findLatestNativeCompactionDetails(
105
+ entries: readonly SessionEntry[],
106
+ match: NativeCompactionEntryMatch = {},
107
+ ): NativeCompactionDetails | undefined {
108
+ return findLatestNativeCompactionEntry(entries, match)?.details;
109
+ }
110
+
111
+ export function resolveLatestNativeCompactionEntry(
112
+ entries: readonly SessionEntry[],
113
+ match: NativeCompactionEntryMatch = {},
114
+ ): LatestNativeCompactionResolution {
115
+ const latestCompactionIndex = findLatestCompactionEntryIndex(entries);
116
+ if (latestCompactionIndex === undefined) {
117
+ return {
118
+ ok: false,
119
+ reason: "no-compaction",
120
+ };
121
+ }
122
+
123
+ const latestCompaction = entries[latestCompactionIndex];
124
+ if (!latestCompaction || latestCompaction.type !== "compaction" || !isPersistedNativeCompactionEntry(latestCompaction)) {
125
+ return {
126
+ ok: false,
127
+ reason: "latest-compaction-not-native",
128
+ latestCompactionIndex,
129
+ latestCompaction:
130
+ latestCompaction && latestCompaction.type === "compaction"
131
+ ? (latestCompaction as CompactionEntry)
132
+ : undefined,
133
+ };
134
+ }
135
+
136
+ if (!entryMatches(latestCompaction, match)) {
137
+ return {
138
+ ok: false,
139
+ reason: "latest-native-compaction-mismatch",
140
+ latestCompactionIndex,
141
+ latestCompaction,
142
+ };
143
+ }
144
+
145
+ return {
146
+ ok: true,
147
+ entry: latestCompaction,
148
+ index: latestCompactionIndex,
149
+ latestCompactionIndex,
150
+ };
151
+ }