@f5-sales-demo/pi-agent-core 21.5.7 → 21.6.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.
- package/package.json +3 -3
- package/src/agent.ts +17 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5-sales-demo/pi-agent-core",
|
|
4
|
-
"version": "21.
|
|
4
|
+
"version": "21.6.1",
|
|
5
5
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
6
6
|
"homepage": "https://github.com/f5-sales-demo/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"fmt": "biome format --write ."
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@f5-sales-demo/pi-ai": "21.
|
|
39
|
-
"@f5-sales-demo/pi-utils": "21.
|
|
38
|
+
"@f5-sales-demo/pi-ai": "21.6.1",
|
|
39
|
+
"@f5-sales-demo/pi-utils": "21.6.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@sinclair/typebox": "^0.34",
|
package/src/agent.ts
CHANGED
|
@@ -132,6 +132,8 @@ export interface AgentOptions {
|
|
|
132
132
|
* Inspect or replace provider payloads before they are sent.
|
|
133
133
|
*/
|
|
134
134
|
onPayload?: SimpleStreamOptions["onPayload"];
|
|
135
|
+
/** Observe the final provider payload after all transforms. Must not retain raw content. */
|
|
136
|
+
onFinalPayload?: SimpleStreamOptions["onPayload"];
|
|
135
137
|
/**
|
|
136
138
|
* Inspect assistant streaming events before they are emitted to subscribers.
|
|
137
139
|
* Use this when abort decisions must happen before buffered events continue flowing.
|
|
@@ -211,9 +213,10 @@ export interface AgentPromptOptions {
|
|
|
211
213
|
export function composeOnPayload(
|
|
212
214
|
base: SimpleStreamOptions["onPayload"] | undefined,
|
|
213
215
|
serverTools: Record<string, unknown>[] | undefined,
|
|
216
|
+
final: SimpleStreamOptions["onPayload"] | undefined = undefined,
|
|
214
217
|
): SimpleStreamOptions["onPayload"] | undefined {
|
|
215
218
|
const hasServerTools = Array.isArray(serverTools) && serverTools.length > 0;
|
|
216
|
-
if (!base && !hasServerTools) return undefined;
|
|
219
|
+
if (!base && !hasServerTools && !final) return undefined;
|
|
217
220
|
return async (payload, model) => {
|
|
218
221
|
let p = payload;
|
|
219
222
|
if (base) {
|
|
@@ -224,6 +227,10 @@ export function composeOnPayload(
|
|
|
224
227
|
const params = p as { tools?: unknown[] };
|
|
225
228
|
params.tools = [...(params.tools ?? []), ...serverTools];
|
|
226
229
|
}
|
|
230
|
+
if (final) {
|
|
231
|
+
const replaced = await final(p, model);
|
|
232
|
+
if (replaced !== undefined) p = replaced;
|
|
233
|
+
}
|
|
227
234
|
return p;
|
|
228
235
|
};
|
|
229
236
|
}
|
|
@@ -278,6 +285,7 @@ export class Agent {
|
|
|
278
285
|
#intentTracing: boolean;
|
|
279
286
|
#getToolChoice?: () => ToolChoice | undefined;
|
|
280
287
|
#onPayload?: SimpleStreamOptions["onPayload"];
|
|
288
|
+
#onFinalPayload?: SimpleStreamOptions["onPayload"];
|
|
281
289
|
#onAssistantMessageEvent?: (message: AssistantMessage, event: AssistantMessageEvent) => void;
|
|
282
290
|
|
|
283
291
|
/** Buffered Cursor tool results with text length at time of call (for correct ordering) */
|
|
@@ -307,6 +315,7 @@ export class Agent {
|
|
|
307
315
|
this.#maxRetryDelayMs = opts.maxRetryDelayMs;
|
|
308
316
|
this.getApiKey = opts.getApiKey;
|
|
309
317
|
this.#onPayload = opts.onPayload;
|
|
318
|
+
this.#onFinalPayload = opts.onFinalPayload;
|
|
310
319
|
this.#getToolContext = opts.getToolContext;
|
|
311
320
|
this.#cursorExecHandlers = opts.cursorExecHandlers;
|
|
312
321
|
this.#cursorOnToolResult = opts.cursorOnToolResult;
|
|
@@ -798,7 +807,13 @@ export class Agent {
|
|
|
798
807
|
transformContext: this.#transformContext,
|
|
799
808
|
// Per-turn: compose the extension hook with any server-tool injection for
|
|
800
809
|
// THIS prompt (e.g. Office "Search the web"). No-op when neither is present.
|
|
801
|
-
onPayload: composeOnPayload(
|
|
810
|
+
onPayload: composeOnPayload(
|
|
811
|
+
this.#onPayload,
|
|
812
|
+
options?.serverTools,
|
|
813
|
+
this.#onFinalPayload
|
|
814
|
+
? (payload, payloadModel) => this.#onFinalPayload?.(payload, payloadModel ?? model)
|
|
815
|
+
: undefined,
|
|
816
|
+
),
|
|
802
817
|
getApiKey: this.getApiKey,
|
|
803
818
|
getToolContext: this.#getToolContext,
|
|
804
819
|
syncContextBeforeModelCall: async context => {
|