@linxiraos/pi-agent-core 1.1.7 → 1.1.9
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 +9 -12
- package/package.json +73 -79
- package/src/agent-loop.ts +81 -16
- package/src/compaction/compaction-v2-streaming.ts +44 -35
- package/src/compaction/compaction.ts +89 -18
- package/src/compaction/messages.ts +2 -0
- package/src/compaction/openai.ts +6 -3
- package/src/compaction/pruning.ts +1 -0
- package/src/compaction/shake.ts +1 -0
- package/src/telemetry.ts +2 -2
- package/src/types.ts +34 -7
- package/THIRD-PARTY-NOTICES.txt +0 -22909
- package/dist/types/agent-loop.d.ts +0 -150
- package/dist/types/agent.d.ts +0 -472
- package/dist/types/append-only-context.d.ts +0 -131
- package/dist/types/compaction/branch-summarization.d.ts +0 -102
- package/dist/types/compaction/compaction-v2-streaming.d.ts +0 -85
- package/dist/types/compaction/compaction.d.ts +0 -341
- package/dist/types/compaction/entries.d.ts +0 -120
- package/dist/types/compaction/errors.d.ts +0 -38
- package/dist/types/compaction/index.d.ts +0 -14
- package/dist/types/compaction/message-cache.d.ts +0 -25
- package/dist/types/compaction/messages.d.ts +0 -103
- package/dist/types/compaction/openai.d.ts +0 -118
- package/dist/types/compaction/pruning.d.ts +0 -106
- package/dist/types/compaction/shake.d.ts +0 -104
- package/dist/types/compaction/tool-protection.d.ts +0 -19
- package/dist/types/compaction/transcript-tokens.d.ts +0 -76
- package/dist/types/compaction/utils.d.ts +0 -63
- package/dist/types/compaction.d.ts +0 -1
- package/dist/types/index.d.ts +0 -13
- package/dist/types/pause.d.ts +0 -46
- package/dist/types/proxy.d.ts +0 -91
- package/dist/types/replay-policy.d.ts +0 -5
- package/dist/types/run-collector.d.ts +0 -196
- package/dist/types/telemetry.d.ts +0 -625
- package/dist/types/thinking.d.ts +0 -18
- package/dist/types/tokenizer.d.ts +0 -78
- package/dist/types/types.d.ts +0 -786
- package/dist/types/utils/yield.d.ts +0 -71
|
@@ -226,6 +226,7 @@ export function convertMessageToLlm(message: AgentMessage): Message | undefined
|
|
|
226
226
|
},
|
|
227
227
|
],
|
|
228
228
|
attribution: "agent",
|
|
229
|
+
historyRewriteAt: message.timestamp,
|
|
229
230
|
timestamp: message.timestamp,
|
|
230
231
|
};
|
|
231
232
|
case "compactionSummary":
|
|
@@ -245,6 +246,7 @@ export function convertMessageToLlm(message: AgentMessage): Message | undefined
|
|
|
245
246
|
...(message.images ?? []),
|
|
246
247
|
],
|
|
247
248
|
attribution: "agent",
|
|
249
|
+
historyRewriteAt: message.timestamp,
|
|
248
250
|
providerPayload: message.providerPayload,
|
|
249
251
|
timestamp: message.timestamp,
|
|
250
252
|
};
|
package/src/compaction/openai.ts
CHANGED
|
@@ -48,6 +48,7 @@ import { captureOpenAIHttpError } from "@linxiraos/pi-ai/utils/openai-http";
|
|
|
48
48
|
import {
|
|
49
49
|
applyCodexResidencyHeader,
|
|
50
50
|
CODEX_BASE_URL,
|
|
51
|
+
codexRoutingHint,
|
|
51
52
|
getCodexAccountId,
|
|
52
53
|
OPENAI_HEADER_VALUES,
|
|
53
54
|
OPENAI_HEADERS,
|
|
@@ -390,7 +391,7 @@ export function withOpenAiRemoteCompactionPreserveData(
|
|
|
390
391
|
): Record<string, unknown> | undefined {
|
|
391
392
|
if (remoteCompaction) {
|
|
392
393
|
return {
|
|
393
|
-
...
|
|
394
|
+
...preserveData,
|
|
394
395
|
[OPENAI_REMOTE_COMPACTION_PRESERVE_KEY]: remoteCompaction,
|
|
395
396
|
};
|
|
396
397
|
}
|
|
@@ -803,12 +804,12 @@ export async function requestOpenAiRemoteCompaction(
|
|
|
803
804
|
? {
|
|
804
805
|
"content-type": "application/json",
|
|
805
806
|
"api-key": apiKey,
|
|
806
|
-
...
|
|
807
|
+
...model.headers,
|
|
807
808
|
}
|
|
808
809
|
: {
|
|
809
810
|
"content-type": "application/json",
|
|
810
811
|
Authorization: `Bearer ${apiKey}`,
|
|
811
|
-
...
|
|
812
|
+
...model.headers,
|
|
812
813
|
};
|
|
813
814
|
|
|
814
815
|
// Codex endpoints require additional auth headers
|
|
@@ -824,6 +825,8 @@ export async function requestOpenAiRemoteCompaction(
|
|
|
824
825
|
}
|
|
825
826
|
headers[OPENAI_HEADERS.BETA] = OPENAI_HEADER_VALUES.BETA_RESPONSES;
|
|
826
827
|
headers[OPENAI_HEADERS.ORIGINATOR] = OPENAI_HEADER_VALUES.ORIGINATOR_CODEX;
|
|
828
|
+
// This compaction request sends no `service_tier`, so the hint is model-only.
|
|
829
|
+
headers[OPENAI_HEADERS.ROUTING_HINT] = codexRoutingHint(request.model, undefined);
|
|
827
830
|
Object.assign(
|
|
828
831
|
headers,
|
|
829
832
|
createOpenAICodexCompatibilityMetadata({
|
|
@@ -141,6 +141,7 @@ function estimatePrunedSavings(tokens: number, notice: string): number {
|
|
|
141
141
|
* mutations inside the cheap-to-recache tail.
|
|
142
142
|
*/
|
|
143
143
|
function computeMessageSuffixTokens(entries: readonly SessionEntry[], tokenizer: Tokenizer): number[] {
|
|
144
|
+
// [suppressed] length preallocation
|
|
144
145
|
const suffix = new Array<number>(entries.length);
|
|
145
146
|
let accumulated = 0;
|
|
146
147
|
for (let i = entries.length - 1; i >= 0; i--) {
|
package/src/compaction/shake.ts
CHANGED
|
@@ -318,6 +318,7 @@ export function collectShakeRegions(entries: SessionEntry[], tokenizer: Tokenize
|
|
|
318
318
|
if (n === 0) return [];
|
|
319
319
|
|
|
320
320
|
// Tokens of all entries strictly more recent than index i.
|
|
321
|
+
// [suppressed] length preallocation
|
|
321
322
|
const accumulatedAfter = new Array<number>(n);
|
|
322
323
|
let acc = 0;
|
|
323
324
|
for (let i = n - 1; i >= 0; i--) {
|
package/src/telemetry.ts
CHANGED
|
@@ -1638,7 +1638,7 @@ export async function recordManualChatTelemetry(
|
|
|
1638
1638
|
/**
|
|
1639
1639
|
* Options accepted by {@link instrumentedCompleteSimple}. Mirrors the
|
|
1640
1640
|
* `streamAssistantResponse` chat-span lifecycle for oneshot LLM calls
|
|
1641
|
-
* (compaction summaries, handoff document, branch summary,
|
|
1641
|
+
* (compaction summaries, handoff document, branch summary, image_question).
|
|
1642
1642
|
*/
|
|
1643
1643
|
export interface InstrumentedChatSpanOptions {
|
|
1644
1644
|
readonly telemetry: AgentTelemetry | undefined;
|
|
@@ -1649,7 +1649,7 @@ export interface InstrumentedChatSpanOptions {
|
|
|
1649
1649
|
/**
|
|
1650
1650
|
* Tag stamped onto `pi.gen_ai.oneshot.kind`. Values used by the agent:
|
|
1651
1651
|
* `compaction_summary`, `compaction_short_summary`, `compaction_turn_prefix`,
|
|
1652
|
-
* `handoff`, `branch_summary`, `
|
|
1652
|
+
* `handoff`, `branch_summary`, `image_question`. Free-form to allow callers
|
|
1653
1653
|
* outside this package to add new kinds without bumping the helper.
|
|
1654
1654
|
*/
|
|
1655
1655
|
readonly oneshotKind?: string;
|
package/src/types.ts
CHANGED
|
@@ -245,8 +245,10 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
245
245
|
/**
|
|
246
246
|
* Peeks whether steering messages are queued, without consuming them.
|
|
247
247
|
*
|
|
248
|
-
*
|
|
249
|
-
* whether to
|
|
248
|
+
* Polled while a tool batch runs (unless interruptMode is "wait") to decide
|
|
249
|
+
* whether to abort in-flight and skip not-yet-started *interruptible* waits;
|
|
250
|
+
* every other already-emitted call still executes and the message injects
|
|
251
|
+
* at the batch boundary. The queue keeps
|
|
250
252
|
* owning its messages until the loop reaches the next injection boundary and
|
|
251
253
|
* dequeues via {@link getSteeringMessages} — so callers can still cancel or
|
|
252
254
|
* restore queued messages while in-flight tools settle, and an external
|
|
@@ -758,11 +760,34 @@ export type AgentToolExecFn<TParameters extends TSchema = TSchema, TDetails = an
|
|
|
758
760
|
context?: AgentToolContext,
|
|
759
761
|
) => Promise<AgentToolResult<TDetails, TParameters>>;
|
|
760
762
|
|
|
763
|
+
/** Live receiver for a tool call's streamed arguments (see AgentTool.openArgStream). */
|
|
764
|
+
export interface AgentToolArgStream {
|
|
765
|
+
/** Raw wire fragment of the arguments (JSON text, or verbatim payload for custom-format tools). */
|
|
766
|
+
push(delta: string): void;
|
|
767
|
+
/** Arguments are complete; `args` is the final parsed object the loop will pass to `execute`. */
|
|
768
|
+
end(args: unknown): void;
|
|
769
|
+
/** The call will never execute (stream error, abort, blocked). Release resources. */
|
|
770
|
+
cancel(): void;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
export interface AgentToolArgStreamInit {
|
|
774
|
+
toolCallId: string;
|
|
775
|
+
toolName: string;
|
|
776
|
+
/** Wire-level name for custom-format tools; undefined for JSON function tools. */
|
|
777
|
+
customWireName?: string;
|
|
778
|
+
/** Push a serializable projection of the in-flight call (e.g. diff previews); surfaces as `tool_stream_update`. */
|
|
779
|
+
emit(update: unknown): void;
|
|
780
|
+
}
|
|
781
|
+
|
|
761
782
|
// AgentTool extends Tool but adds the execute function
|
|
762
783
|
export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any, TTheme = unknown>
|
|
763
784
|
extends Tool<TParameters> {
|
|
764
785
|
// A human-readable label for the tool to be displayed in UI
|
|
765
786
|
label: string;
|
|
787
|
+
/**
|
|
788
|
+
* Called at `toolcall_start`, before any argument delta. Return `undefined` to opt out.
|
|
789
|
+
*/
|
|
790
|
+
openArgStream?: (init: AgentToolArgStreamInit) => AgentToolArgStream | undefined;
|
|
766
791
|
/** If true, tool is excluded unless explicitly listed in --tools or agent's tools field */
|
|
767
792
|
hidden?: boolean;
|
|
768
793
|
/** If true, tool can stage a pending action that requires explicit resolution via the resolve tool. */
|
|
@@ -781,14 +806,15 @@ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any
|
|
|
781
806
|
/** If true, argument validation errors are non-fatal: raw args are passed to execute() instead of returning an error to the LLM. */
|
|
782
807
|
lenientArgValidation?: boolean;
|
|
783
808
|
/**
|
|
784
|
-
* Whether the agent loop may abort this tool mid-execution
|
|
785
|
-
*
|
|
786
|
-
* pre-validation arguments.
|
|
809
|
+
* Whether the agent loop may abort this tool mid-execution — or skip it
|
|
810
|
+
* before it starts — to deliver a queued steering message. A function
|
|
811
|
+
* resolves this per call from the raw, pre-validation arguments.
|
|
787
812
|
*
|
|
788
813
|
* Enable only for calls that purely *wait* and observe their abort signal
|
|
789
814
|
* cleanly (e.g. `job` poll), so the abort surfaces the tool's current
|
|
790
|
-
* snapshot rather than corrupting a side effect.
|
|
791
|
-
*
|
|
815
|
+
* snapshot rather than corrupting a side effect. Every other call runs to
|
|
816
|
+
* completion even when steering is queued; the message lands at the next
|
|
817
|
+
* batch boundary. Honored only when `interruptMode` is "immediate".
|
|
792
818
|
*/
|
|
793
819
|
interruptible?: boolean | ((args: Partial<Static<TParameters>>) => boolean);
|
|
794
820
|
/**
|
|
@@ -882,4 +908,5 @@ export type AgentEvent =
|
|
|
882
908
|
// Tool execution lifecycle
|
|
883
909
|
| { type: "tool_execution_start"; toolCallId: string; toolName: string; args: any; intent?: string }
|
|
884
910
|
| { type: "tool_execution_update"; toolCallId: string; toolName: string; args: any; partialResult: any }
|
|
911
|
+
| { type: "tool_stream_update"; toolCallId: string; toolName: string; update: unknown }
|
|
885
912
|
| { type: "tool_execution_end"; toolCallId: string; toolName: string; result: any; isError?: boolean };
|