pi-openai-toolkit 0.14.4 → 0.14.5

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.
@@ -1,161 +1,161 @@
1
- import type { ContextManagementMode } from "../types";
2
-
3
- export type { ContextManagementMode };
4
-
5
- export const CONTEXT_MANAGEMENT_PROTOCOL = 1 as const;
6
- export const CODEX_CONTEXT_WINDOW_MESSAGE_TYPE = "codex-context-window" as const;
7
- export const CONTEXT_WINDOW_COMPACTION_STRATEGY = "codex-context-window" as const;
8
- export const CONTEXT_WINDOW_REMINDER_THRESHOLD = 6_144;
9
- export const CONTEXT_WINDOW_FALLBACK_BUFFER = 16_384;
10
-
11
- export type ContextManagementMessageKind = "window" | "reminder" | "fallback";
12
-
13
- export type ContextWindowIdentity = {
14
- firstWindowId: string;
15
- currentWindowId: string;
16
- previousWindowId?: string;
17
- windowNumber: number;
18
- };
19
-
20
- export type CodexContextManagementMessageDetails = {
21
- protocol: typeof CONTEXT_MANAGEMENT_PROTOCOL;
22
- id: string;
23
- sessionId?: string;
24
- contextManagement: ContextWindowIdentity & {
25
- protocol: typeof CONTEXT_MANAGEMENT_PROTOCOL;
26
- kind: ContextManagementMessageKind;
27
- trimPreviousWindow?: true;
28
- };
29
- };
30
-
31
- export type ContextWindowCompactionDetails = {
32
- protocol: typeof CONTEXT_MANAGEMENT_PROTOCOL;
33
- strategy: typeof CONTEXT_WINDOW_COMPACTION_STRATEGY;
34
- windowId?: string;
35
- };
36
-
37
- export type RemoteContextFailureReason =
38
- | "context-management-inactive"
39
- | "unsupported-model"
40
- | "unsupported-api"
41
- | "unsupported-backend"
42
- | "auth-resolution-failed"
43
- | "missing-token"
44
- | "missing-api-key"
45
- | "missing-account-id"
46
- | "missing-base-url"
47
- | "invalid-account-token"
48
- | "backend-timeout"
49
- | "aborted"
50
- | "http-error"
51
- | "invalid-json"
52
- | "invalid-response"
53
- | "protocol-error";
54
-
55
- export type NativeCodexContextProvider = {
56
- kind: "native-codex";
57
- route: "openai-codex";
58
- provider: "openai-codex";
59
- api: "openai-codex-responses";
60
- model: string;
61
- baseUrl: string;
62
- token: string;
63
- accountId: string;
64
- headers: Record<string, string>;
65
- };
66
-
67
- export type GatewayCodexContextProvider = {
68
- kind: "codex-gateway";
69
- route: "codex-gateway";
70
- /** Operator-defined provider name; matched via compaction.gatewayContextModels. */
71
- provider: string;
72
- api: "openai-responses";
73
- model: string;
74
- baseUrl: string;
75
- apiKey: string;
76
- headers: Record<string, string>;
77
- };
78
-
79
- export type CodexContextProvider = NativeCodexContextProvider | GatewayCodexContextProvider;
80
-
81
- export type CodexContextProviderResolution =
82
- | { ok: true; provider: CodexContextProvider }
83
- | {
84
- ok: false;
85
- reason: RemoteContextFailureReason;
86
- provider?: string;
87
- api?: string;
88
- model?: string;
89
- baseUrl?: string;
90
- };
91
-
92
- export type HistoryAction =
93
- | "list_windows"
94
- | "list_items"
95
- | "read_item"
96
- | "search_contents";
97
-
98
- export type NotesAction =
99
- | "list_files_by_prefix"
100
- | "read_file"
101
- | "search_contents"
102
- | "append_to_file"
103
- | "write_file";
104
-
105
- export type HistoryNotesResponse = Record<string, unknown>;
106
-
107
- export type HistoryNotesResult =
108
- | { ok: true; value: HistoryNotesResponse }
109
- | {
110
- ok: false;
111
- reason: Exclude<RemoteContextFailureReason, "context-management-inactive" | "unsupported-model" | "unsupported-api">;
112
- status?: number;
113
- };
114
-
115
- export function isRecord(value: unknown): value is Record<string, unknown> {
116
- return Boolean(value && typeof value === "object" && !Array.isArray(value));
117
- }
118
-
119
- export function isNonEmptyString(value: unknown): value is string {
120
- return typeof value === "string" && value.trim().length > 0;
121
- }
122
-
123
- export function isContextWindowIdentity(value: unknown): value is ContextWindowIdentity {
124
- if (!isRecord(value)) return false;
125
- return (
126
- isNonEmptyString(value.firstWindowId) &&
127
- isNonEmptyString(value.currentWindowId) &&
128
- (value.previousWindowId === undefined || isNonEmptyString(value.previousWindowId)) &&
129
- Number.isInteger(value.windowNumber) &&
130
- (value.windowNumber as number) >= 0
131
- );
132
- }
133
-
134
- export function isCodexContextManagementMessageDetails(
135
- value: unknown,
136
- ): value is CodexContextManagementMessageDetails {
137
- if (!isRecord(value) || value.protocol !== CONTEXT_MANAGEMENT_PROTOCOL || !isNonEmptyString(value.id)) {
138
- return false;
139
- }
140
- if (value.sessionId !== undefined && !isNonEmptyString(value.sessionId)) return false;
141
- if (!isRecord(value.contextManagement) || value.contextManagement.protocol !== CONTEXT_MANAGEMENT_PROTOCOL) {
142
- return false;
143
- }
144
- const context = value.contextManagement;
145
- if (!isRecord(context)) return false;
146
- const trimPreviousWindow = context.trimPreviousWindow;
147
- return (
148
- (context.kind === "window" || context.kind === "reminder" || context.kind === "fallback") &&
149
- isContextWindowIdentity(context) &&
150
- (trimPreviousWindow === undefined || trimPreviousWindow === true)
151
- );
152
- }
153
-
154
- export function isContextWindowCompactionDetails(value: unknown): value is ContextWindowCompactionDetails {
155
- return (
156
- isRecord(value) &&
157
- value.protocol === CONTEXT_MANAGEMENT_PROTOCOL &&
158
- value.strategy === CONTEXT_WINDOW_COMPACTION_STRATEGY &&
159
- (value.windowId === undefined || isNonEmptyString(value.windowId))
160
- );
161
- }
1
+ import type { ContextManagementMode } from "../types";
2
+
3
+ export type { ContextManagementMode };
4
+
5
+ export const CONTEXT_MANAGEMENT_PROTOCOL = 1 as const;
6
+ export const CODEX_CONTEXT_WINDOW_MESSAGE_TYPE = "codex-context-window" as const;
7
+ export const CONTEXT_WINDOW_COMPACTION_STRATEGY = "codex-context-window" as const;
8
+ export const CONTEXT_WINDOW_REMINDER_THRESHOLD = 6_144;
9
+ export const CONTEXT_WINDOW_FALLBACK_BUFFER = 16_384;
10
+
11
+ export type ContextManagementMessageKind = "window" | "reminder" | "fallback";
12
+
13
+ export type ContextWindowIdentity = {
14
+ firstWindowId: string;
15
+ currentWindowId: string;
16
+ previousWindowId?: string;
17
+ windowNumber: number;
18
+ };
19
+
20
+ export type CodexContextManagementMessageDetails = {
21
+ protocol: typeof CONTEXT_MANAGEMENT_PROTOCOL;
22
+ id: string;
23
+ sessionId?: string;
24
+ contextManagement: ContextWindowIdentity & {
25
+ protocol: typeof CONTEXT_MANAGEMENT_PROTOCOL;
26
+ kind: ContextManagementMessageKind;
27
+ trimPreviousWindow?: true;
28
+ };
29
+ };
30
+
31
+ export type ContextWindowCompactionDetails = {
32
+ protocol: typeof CONTEXT_MANAGEMENT_PROTOCOL;
33
+ strategy: typeof CONTEXT_WINDOW_COMPACTION_STRATEGY;
34
+ windowId?: string;
35
+ };
36
+
37
+ export type RemoteContextFailureReason =
38
+ | "context-management-inactive"
39
+ | "unsupported-model"
40
+ | "unsupported-api"
41
+ | "unsupported-backend"
42
+ | "auth-resolution-failed"
43
+ | "missing-token"
44
+ | "missing-api-key"
45
+ | "missing-account-id"
46
+ | "missing-base-url"
47
+ | "invalid-account-token"
48
+ | "backend-timeout"
49
+ | "aborted"
50
+ | "http-error"
51
+ | "invalid-json"
52
+ | "invalid-response"
53
+ | "protocol-error";
54
+
55
+ export type NativeCodexContextProvider = {
56
+ kind: "native-codex";
57
+ route: "openai-codex";
58
+ provider: "openai-codex";
59
+ api: "openai-codex-responses";
60
+ model: string;
61
+ baseUrl: string;
62
+ token: string;
63
+ accountId: string;
64
+ headers: Record<string, string>;
65
+ };
66
+
67
+ export type GatewayCodexContextProvider = {
68
+ kind: "codex-gateway";
69
+ route: "codex-gateway";
70
+ /** Operator-defined provider name; matched via compaction.gatewayContextModels. */
71
+ provider: string;
72
+ api: "openai-responses";
73
+ model: string;
74
+ baseUrl: string;
75
+ apiKey: string;
76
+ headers: Record<string, string>;
77
+ };
78
+
79
+ export type CodexContextProvider = NativeCodexContextProvider | GatewayCodexContextProvider;
80
+
81
+ export type CodexContextProviderResolution =
82
+ | { ok: true; provider: CodexContextProvider }
83
+ | {
84
+ ok: false;
85
+ reason: RemoteContextFailureReason;
86
+ provider?: string;
87
+ api?: string;
88
+ model?: string;
89
+ baseUrl?: string;
90
+ };
91
+
92
+ export type HistoryAction =
93
+ | "list_windows"
94
+ | "list_items"
95
+ | "read_item"
96
+ | "search_contents";
97
+
98
+ export type NotesAction =
99
+ | "list_files_by_prefix"
100
+ | "read_file"
101
+ | "search_contents"
102
+ | "append_to_file"
103
+ | "write_file";
104
+
105
+ export type HistoryNotesResponse = Record<string, unknown>;
106
+
107
+ export type HistoryNotesResult =
108
+ | { ok: true; value: HistoryNotesResponse }
109
+ | {
110
+ ok: false;
111
+ reason: Exclude<RemoteContextFailureReason, "context-management-inactive" | "unsupported-model" | "unsupported-api">;
112
+ status?: number;
113
+ };
114
+
115
+ export function isRecord(value: unknown): value is Record<string, unknown> {
116
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
117
+ }
118
+
119
+ export function isNonEmptyString(value: unknown): value is string {
120
+ return typeof value === "string" && value.trim().length > 0;
121
+ }
122
+
123
+ export function isContextWindowIdentity(value: unknown): value is ContextWindowIdentity {
124
+ if (!isRecord(value)) return false;
125
+ return (
126
+ isNonEmptyString(value.firstWindowId) &&
127
+ isNonEmptyString(value.currentWindowId) &&
128
+ (value.previousWindowId === undefined || isNonEmptyString(value.previousWindowId)) &&
129
+ Number.isInteger(value.windowNumber) &&
130
+ (value.windowNumber as number) >= 0
131
+ );
132
+ }
133
+
134
+ export function isCodexContextManagementMessageDetails(
135
+ value: unknown,
136
+ ): value is CodexContextManagementMessageDetails {
137
+ if (!isRecord(value) || value.protocol !== CONTEXT_MANAGEMENT_PROTOCOL || !isNonEmptyString(value.id)) {
138
+ return false;
139
+ }
140
+ if (value.sessionId !== undefined && !isNonEmptyString(value.sessionId)) return false;
141
+ if (!isRecord(value.contextManagement) || value.contextManagement.protocol !== CONTEXT_MANAGEMENT_PROTOCOL) {
142
+ return false;
143
+ }
144
+ const context = value.contextManagement;
145
+ if (!isRecord(context)) return false;
146
+ const trimPreviousWindow = context.trimPreviousWindow;
147
+ return (
148
+ (context.kind === "window" || context.kind === "reminder" || context.kind === "fallback") &&
149
+ isContextWindowIdentity(context) &&
150
+ (trimPreviousWindow === undefined || trimPreviousWindow === true)
151
+ );
152
+ }
153
+
154
+ export function isContextWindowCompactionDetails(value: unknown): value is ContextWindowCompactionDetails {
155
+ return (
156
+ isRecord(value) &&
157
+ value.protocol === CONTEXT_MANAGEMENT_PROTOCOL &&
158
+ value.strategy === CONTEXT_WINDOW_COMPACTION_STRATEGY &&
159
+ (value.windowId === undefined || isNonEmptyString(value.windowId))
160
+ );
161
+ }
@@ -8,6 +8,7 @@ import {
8
8
  IMAGE_GENERATION_QUALITIES,
9
9
  IMAGE_GENERATION_SIZES,
10
10
  IMAGE_GENERATION_TOOL_NAME,
11
+ MAX_IMAGE_MODEL_ID_CHARS,
11
12
  MAX_IMAGE_PATH_CHARS,
12
13
  MAX_IMAGE_PROMPT_CHARS,
13
14
  MAX_REFERENCE_IMAGE_COUNT,
@@ -65,6 +66,21 @@ const GenerateImageParameters = Type.Object(
65
66
  description: "Requested image quality, or auto.",
66
67
  }),
67
68
  ),
69
+ model: Type.Optional(
70
+ Type.Union(
71
+ [
72
+ Type.Null(),
73
+ Type.String({
74
+ minLength: 1,
75
+ maxLength: MAX_IMAGE_MODEL_ID_CHARS,
76
+ }),
77
+ ],
78
+ {
79
+ description:
80
+ "Use null to accept the default image model, which is the first entry of imageGeneration.models; otherwise provide another model id exactly as it appears in that configured list.",
81
+ },
82
+ ),
83
+ ),
68
84
  },
69
85
  { additionalProperties: false },
70
86
  );
@@ -98,14 +114,15 @@ export function registerImageGenerationExtension(
98
114
  name: IMAGE_GENERATION_TOOL_NAME,
99
115
  label: "OpenAI Generate Image",
100
116
  description:
101
- "Generate a PNG image, or edit from one to five user-approved local reference images, through the current Responses-capable model and the hosted gpt-image-2 image_generation tool. This is a paid provider operation.",
102
- promptSnippet: "Generate or edit PNG images through the current Responses-capable model and gpt-image-2.",
117
+ "Generate a PNG image, or edit from one to five user-approved local reference images, through the current Responses-capable model and a configured hosted image_generation model. This is a paid provider operation.",
118
+ promptSnippet: "Generate or edit PNG images through the current Responses-capable model and a configured imageGeneration.models entry.",
103
119
  promptGuidelines: [
104
120
  "Use openai_generate_image when the user explicitly asks to create, draw, render, or edit a raster image and the active model speaks a Responses API.",
105
121
  "Do not call openai_generate_image speculatively: it consumes the user's provider or gateway image quota.",
106
122
  "Keep the image prompt faithful to the user's requested subject and constraints; do not invent unrequested style details.",
107
123
  "Set referenceImagePaths to null unless the user explicitly identified local files; never invent paths or placeholder strings, and remember upload requires user approval.",
108
124
  "Set outputPath to null unless the user explicitly asks for a destination; never invent a destination or placeholder string, and otherwise use the default Pi agent artifact.",
125
+ "Set model to null unless the user named an image model configured in imageGeneration.models; never invent or guess a model id, and remember an unlisted model fails before the paid request.",
109
126
  "Do not substitute Python, browser automation, shell scripts, or unrelated image tools for an eligible image request.",
110
127
  ],
111
128
  parameters: GenerateImageParameters,