@oh-my-pi/pi-agent-core 18.14.2 → 18.15.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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [18.15.0] - 2026-11-01
6
+
7
+ ### Fixed
8
+
9
+ - Fixed OpenAI remote compaction (`/responses/compact`) replaying backend-only `internal_chat_message_metadata_passthrough` metadata that Codex rejects as an unknown parameter ([#17590](https://github.com/can1357/oh-my-pi/pull/17590) by [@briankeefe](https://github.com/briankeefe))
10
+
5
11
  ## [18.14.2] - 2026-10-31
6
12
 
7
13
  ### Added
@@ -2,6 +2,7 @@ import { type ApiKey, type AssistantMessage, type AssistantMessageEvent, type Co
2
2
  import type { Dialect } from "@oh-my-pi/pi-ai/dialect";
3
3
  import type { HarmonyAuditEvent } from "@oh-my-pi/pi-ai/utils/harmony-leak";
4
4
  import type { AppendOnlyContextManager } from "./append-only-context.js";
5
+ import { SentToolDefinitions } from "./sent-tool-definitions.js";
5
6
  import { Tokenizer } from "./tokenizer.js";
6
7
  import type { AgentBeforeModelCall, AgentContext, AgentEvent, AgentLoopConfig, AgentMessage, AgentState, AgentTool, AgentToolContext, AgentTurnEndContext, AsideBoundary, AsideMessage, PrepareQueuedMessages, SpeculativeToolExecutionConfig, StreamFn, ToolCallContext, ToolChoiceDirective } from "./types.js";
7
8
  export declare class AgentBusyError extends Error {
@@ -64,6 +65,11 @@ export interface AgentOptions {
64
65
  * Shared provider state map for session-scoped transport/session caches.
65
66
  */
66
67
  providerSessionState?: Map<string, ProviderSessionState>;
68
+ /**
69
+ * Tool definitions already sent, for an Agent that replays another Agent's request history
70
+ * (see {@link Agent.copySentToolDefinitions}). Defaults to an empty store.
71
+ */
72
+ sentToolDefinitions?: SentToolDefinitions;
67
73
  /**
68
74
  * Resolves an API key or resolver dynamically for each LLM call.
69
75
  * Useful for expiring tokens and model-scoped credential routing.
@@ -295,6 +301,11 @@ export declare class Agent {
295
301
  * Set the prompt cache key forwarded to providers.
296
302
  */
297
303
  set promptCacheKey(value: string | undefined);
304
+ /**
305
+ * A detached copy of the tool definitions this agent has sent (`AgentOptions.sentToolDefinitions`), without the
306
+ * names `keep` rejects.
307
+ */
308
+ copySentToolDefinitions(keep?: (name: string) => boolean): SentToolDefinitions;
298
309
  /**
299
310
  * Fields added to every log record written while this agent runs (the
300
311
  * owning session's `sessionId`), so in-process agents' records stay apart.
@@ -8,6 +8,11 @@ export declare class SentToolDefinitions {
8
8
  #private;
9
9
  /** Remember the definitions a request is about to send. */
10
10
  record(tools: readonly Tool[]): void;
11
+ /**
12
+ * A detached copy: an Agent that replays another's request history declares the same withdrawn tools. `keep`
13
+ * leaves out a definition the copy must never declare.
14
+ */
15
+ copy(keep?: (name: string) => boolean): SentToolDefinitions;
11
16
  /**
12
17
  * `context` with {@link Context.inactiveTools} set to the definitions for names the latest
13
18
  * `requestControls.tools.declared` in its messages holds that are not in its `tools`; cleared when
@@ -968,7 +968,7 @@ export type ToolApprovalDecision = ToolTier | {
968
968
  * prompt policies to the tool it dispatches into. */
969
969
  policyKey?: string;
970
970
  };
971
- export type ToolApproval = ToolApprovalDecision | ((args: unknown) => ToolApprovalDecision);
971
+ export type ToolApproval = ToolApprovalDecision | ((args: unknown, context?: AgentToolContext) => ToolApprovalDecision);
972
972
  /**
973
973
  * Context passed to tool execution.
974
974
  * Apps can extend via declaration merging.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/pi-agent-core",
4
- "version": "18.14.2",
4
+ "version": "18.15.0",
5
5
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
6
6
  "homepage": "https://omp.sh",
7
7
  "author": {
@@ -38,16 +38,16 @@
38
38
  "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
39
39
  },
40
40
  "dependencies": {
41
- "@oh-my-pi/pi-ai": "18.14.2",
42
- "@oh-my-pi/pi-catalog": "18.14.2",
43
- "@oh-my-pi/pi-natives": "18.14.2",
44
- "@oh-my-pi/pi-utils": "18.14.2",
45
- "@oh-my-pi/pi-wire": "18.14.2",
46
- "@oh-my-pi/snapcompact": "18.14.2",
41
+ "@oh-my-pi/pi-ai": "18.15.0",
42
+ "@oh-my-pi/pi-catalog": "18.15.0",
43
+ "@oh-my-pi/pi-natives": "18.15.0",
44
+ "@oh-my-pi/pi-utils": "18.15.0",
45
+ "@oh-my-pi/pi-wire": "18.15.0",
46
+ "@oh-my-pi/snapcompact": "18.15.0",
47
47
  "@opentelemetry/api": "^1.9.1"
48
48
  },
49
49
  "devDependencies": {
50
- "@oh-my-pi/omptype": "18.14.2",
50
+ "@oh-my-pi/omptype": "18.15.0",
51
51
  "@opentelemetry/context-async-hooks": "^2.9.0",
52
52
  "@opentelemetry/sdk-trace-base": "^2.9.0",
53
53
  "@types/bun": "^1.3.14"
package/src/agent.ts CHANGED
@@ -176,6 +176,11 @@ export interface AgentOptions {
176
176
  * Shared provider state map for session-scoped transport/session caches.
177
177
  */
178
178
  providerSessionState?: Map<string, ProviderSessionState>;
179
+ /**
180
+ * Tool definitions already sent, for an Agent that replays another Agent's request history
181
+ * (see {@link Agent.copySentToolDefinitions}). Defaults to an empty store.
182
+ */
183
+ sentToolDefinitions?: SentToolDefinitions;
179
184
 
180
185
  /**
181
186
  * Resolves an API key or resolver dynamically for each LLM call.
@@ -568,6 +573,7 @@ export class Agent {
568
573
  this.#deadline = opts.deadline;
569
574
  this.#promptCacheKey = opts.promptCacheKey;
570
575
  this.#providerSessionState = opts.providerSessionState;
576
+ if (opts.sentToolDefinitions) this.#sentToolDefinitions = opts.sentToolDefinitions;
571
577
  this.#thinkingBudgets = opts.thinkingBudgets;
572
578
  this.#temperature = opts.temperature;
573
579
  this.#topP = opts.topP;
@@ -642,6 +648,14 @@ export class Agent {
642
648
  this.#promptCacheKey = value;
643
649
  }
644
650
 
651
+ /**
652
+ * A detached copy of the tool definitions this agent has sent (`AgentOptions.sentToolDefinitions`), without the
653
+ * names `keep` rejects.
654
+ */
655
+ copySentToolDefinitions(keep?: (name: string) => boolean): SentToolDefinitions {
656
+ return this.#sentToolDefinitions.copy(keep);
657
+ }
658
+
645
659
  /**
646
660
  * Fields added to every log record written while this agent runs (the
647
661
  * owning session's `sessionId`), so in-process agents' records stay apart.
@@ -45,6 +45,7 @@ import {
45
45
  getOpenAIResponsesHistoryItems,
46
46
  getOpenAIResponsesHistoryPayload,
47
47
  normalizeResponsesToolCallId,
48
+ stripOpenAIResponsesInternalMetadataForReplay,
48
49
  stripOpenAIResponsesOutputOnlyStatusesForReplay,
49
50
  truncateResponseItemId,
50
51
  } from "@oh-my-pi/pi-ai/utils";
@@ -846,6 +847,9 @@ export function buildOpenAiNativeHistory(
846
847
  msgIndex++;
847
848
  }
848
849
 
850
+ for (let index = 0; index < input.length; index++) {
851
+ input[index] = stripOpenAIResponsesInternalMetadataForReplay(input[index]!);
852
+ }
849
853
  return stripOpenAIResponsesOutputOnlyStatusesForReplay(hoistInterleavedResponsesToolBatchMessages(input));
850
854
  }
851
855
 
@@ -13,6 +13,16 @@ export class SentToolDefinitions {
13
13
  for (const tool of tools) this.#byName.set(tool.name, tool);
14
14
  }
15
15
 
16
+ /**
17
+ * A detached copy: an Agent that replays another's request history declares the same withdrawn tools. `keep`
18
+ * leaves out a definition the copy must never declare.
19
+ */
20
+ copy(keep: (name: string) => boolean = () => true): SentToolDefinitions {
21
+ const copy = new SentToolDefinitions();
22
+ copy.record([...this.#byName.values()].filter(tool => keep(tool.name)));
23
+ return copy;
24
+ }
25
+
16
26
  /**
17
27
  * `context` with {@link Context.inactiveTools} set to the definitions for names the latest
18
28
  * `requestControls.tools.declared` in its messages holds that are not in its `tools`; cleared when
package/src/types.ts CHANGED
@@ -1087,7 +1087,7 @@ export type ToolApprovalDecision =
1087
1087
  * prompt policies to the tool it dispatches into. */
1088
1088
  policyKey?: string;
1089
1089
  };
1090
- export type ToolApproval = ToolApprovalDecision | ((args: unknown) => ToolApprovalDecision);
1090
+ export type ToolApproval = ToolApprovalDecision | ((args: unknown, context?: AgentToolContext) => ToolApprovalDecision);
1091
1091
 
1092
1092
  /**
1093
1093
  * Context passed to tool execution.