@oh-my-pi/pi-agent-core 6.1.0 → 6.7.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/package.json +3 -3
- package/src/agent-loop.ts +10 -1
- package/src/agent.ts +3 -2
- package/src/types.ts +22 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/pi-agent-core",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.7.0",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"test": "vitest --run"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@oh-my-pi/pi-ai": "6.
|
|
17
|
-
"@oh-my-pi/pi-tui": "6.
|
|
16
|
+
"@oh-my-pi/pi-ai": "6.7.0",
|
|
17
|
+
"@oh-my-pi/pi-tui": "6.7.0"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"ai",
|
package/src/agent-loop.ts
CHANGED
|
@@ -377,6 +377,8 @@ async function executeToolCalls(
|
|
|
377
377
|
const results: ToolResultMessage[] = [];
|
|
378
378
|
let steeringMessages: AgentMessage[] | undefined;
|
|
379
379
|
const shouldInterruptImmediately = interruptMode !== "wait";
|
|
380
|
+
const toolCallInfos = toolCalls.map((call) => ({ id: call.id, name: call.name }));
|
|
381
|
+
const batchId = `${assistantMessage.timestamp ?? Date.now()}_${toolCalls[0]?.id ?? "batch"}`;
|
|
380
382
|
|
|
381
383
|
for (let index = 0; index < toolCalls.length; index++) {
|
|
382
384
|
const toolCall = toolCalls[index];
|
|
@@ -397,7 +399,14 @@ async function executeToolCalls(
|
|
|
397
399
|
|
|
398
400
|
const validatedArgs = validateToolArguments(tool, toolCall);
|
|
399
401
|
|
|
400
|
-
const toolContext = getToolContext
|
|
402
|
+
const toolContext = getToolContext
|
|
403
|
+
? getToolContext({
|
|
404
|
+
batchId,
|
|
405
|
+
index,
|
|
406
|
+
total: toolCalls.length,
|
|
407
|
+
toolCalls: toolCallInfos,
|
|
408
|
+
})
|
|
409
|
+
: undefined;
|
|
401
410
|
result = await tool.execute(
|
|
402
411
|
toolCall.id,
|
|
403
412
|
validatedArgs,
|
package/src/agent.ts
CHANGED
|
@@ -27,6 +27,7 @@ import type {
|
|
|
27
27
|
AgentToolContext,
|
|
28
28
|
StreamFn,
|
|
29
29
|
ThinkingLevel,
|
|
30
|
+
ToolCallContext,
|
|
30
31
|
} from "./types";
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -94,7 +95,7 @@ export interface AgentOptions {
|
|
|
94
95
|
* Provides tool execution context, resolved per tool call.
|
|
95
96
|
* Use for late-bound UI or session state access.
|
|
96
97
|
*/
|
|
97
|
-
getToolContext?: () => AgentToolContext | undefined;
|
|
98
|
+
getToolContext?: (toolCall?: ToolCallContext) => AgentToolContext | undefined;
|
|
98
99
|
|
|
99
100
|
/**
|
|
100
101
|
* Cursor exec handlers for local tool execution.
|
|
@@ -139,7 +140,7 @@ export class Agent {
|
|
|
139
140
|
private _sessionId?: string;
|
|
140
141
|
private _thinkingBudgets?: ThinkingBudgets;
|
|
141
142
|
public getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
|
142
|
-
private getToolContext?: () => AgentToolContext | undefined;
|
|
143
|
+
private getToolContext?: (toolCall?: ToolCallContext) => AgentToolContext | undefined;
|
|
143
144
|
private cursorExecHandlers?: CursorExecHandlers;
|
|
144
145
|
private cursorOnToolResult?: CursorToolResultHandler;
|
|
145
146
|
private runningPrompt?: Promise<void>;
|
package/src/types.ts
CHANGED
|
@@ -109,7 +109,14 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
109
109
|
* Provides tool execution context, resolved per tool call.
|
|
110
110
|
* Use for late-bound UI or session state access.
|
|
111
111
|
*/
|
|
112
|
-
getToolContext?: () => AgentToolContext | undefined;
|
|
112
|
+
getToolContext?: (toolCall?: ToolCallContext) => AgentToolContext | undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface ToolCallContext {
|
|
116
|
+
batchId: string;
|
|
117
|
+
index: number;
|
|
118
|
+
total: number;
|
|
119
|
+
toolCalls: Array<{ id: string; name: string }>;
|
|
113
120
|
}
|
|
114
121
|
|
|
115
122
|
/**
|
|
@@ -158,15 +165,19 @@ export interface AgentState {
|
|
|
158
165
|
error?: string;
|
|
159
166
|
}
|
|
160
167
|
|
|
161
|
-
export interface AgentToolResult<T> {
|
|
168
|
+
export interface AgentToolResult<T, TNormative extends TSchema = any> {
|
|
162
169
|
// Content blocks supporting text and images
|
|
163
170
|
content: (TextContent | ImageContent)[];
|
|
164
171
|
// Details to be displayed in a UI or logged
|
|
165
|
-
details
|
|
172
|
+
details?: T;
|
|
173
|
+
/** Normative input for the tool result */
|
|
174
|
+
$normative?: Static<TNormative>;
|
|
166
175
|
}
|
|
167
176
|
|
|
168
177
|
// Callback for streaming tool execution updates
|
|
169
|
-
export type AgentToolUpdateCallback<T = any
|
|
178
|
+
export type AgentToolUpdateCallback<T = any, TNormative extends TSchema = any> = (
|
|
179
|
+
partialResult: AgentToolResult<T, TNormative>,
|
|
180
|
+
) => void;
|
|
170
181
|
|
|
171
182
|
/** Options passed to renderResult */
|
|
172
183
|
export interface RenderResultOptions {
|
|
@@ -197,15 +208,19 @@ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any
|
|
|
197
208
|
toolCallId: string,
|
|
198
209
|
params: Static<TParameters>,
|
|
199
210
|
signal?: AbortSignal,
|
|
200
|
-
onUpdate?: AgentToolUpdateCallback<TDetails>,
|
|
211
|
+
onUpdate?: AgentToolUpdateCallback<TDetails, TParameters>,
|
|
201
212
|
context?: AgentToolContext,
|
|
202
|
-
) => Promise<AgentToolResult<TDetails>>;
|
|
213
|
+
) => Promise<AgentToolResult<TDetails, TParameters>>;
|
|
203
214
|
|
|
204
215
|
/** Optional custom rendering for tool call display (returns UI component) */
|
|
205
216
|
renderCall?: (args: Static<TParameters>, theme: TTheme) => unknown;
|
|
206
217
|
|
|
207
218
|
/** Optional custom rendering for tool result display (returns UI component) */
|
|
208
|
-
renderResult?: (
|
|
219
|
+
renderResult?: (
|
|
220
|
+
result: AgentToolResult<TDetails, TParameters>,
|
|
221
|
+
options: RenderResultOptions,
|
|
222
|
+
theme: TTheme,
|
|
223
|
+
) => unknown;
|
|
209
224
|
}
|
|
210
225
|
|
|
211
226
|
// AgentContext is like Context but uses AgentTool
|