@alint-js/agent-pi 0.0.25 → 0.0.28
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/dist/index.d.mts +5 -4
- package/dist/index.mjs +37 -6
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { AgentTool } from "@
|
|
1
|
+
import { AgentAdapter, AgentRequest, AgentTool } from "@alint-js/core/agent";
|
|
2
|
+
import { AgentTool as AgentTool$1 } from "@earendil-works/pi-agent-core";
|
|
2
3
|
import { Model } from "@earendil-works/pi-ai";
|
|
3
4
|
import { ResolvedModel } from "@alint-js/core";
|
|
4
|
-
import { AgentAdapter, AgentRequest, AgentTool as AgentTool$1 } from "@alint-js/core/agent";
|
|
5
|
-
|
|
6
5
|
//#region src/index.d.ts
|
|
7
6
|
interface PiAdapterOptions {
|
|
8
7
|
run: (request: AgentRequest) => Promise<PiMessage[]>;
|
|
9
8
|
}
|
|
10
9
|
interface PiMessage {
|
|
11
10
|
content?: unknown;
|
|
11
|
+
errorMessage?: unknown;
|
|
12
12
|
role?: unknown;
|
|
13
|
+
stopReason?: unknown;
|
|
13
14
|
}
|
|
14
15
|
declare function apiKeyFromModel(model: ResolvedModel): string;
|
|
15
16
|
declare function createPiAdapter(options?: Partial<PiAdapterOptions>): AgentAdapter;
|
|
16
17
|
declare function createPiModel(model: ResolvedModel): Model<'openai-completions'>;
|
|
17
18
|
declare function extractPiText(message?: PiMessage): string;
|
|
18
|
-
declare function toPiTools(tools: AgentTool
|
|
19
|
+
declare function toPiTools(tools: AgentTool[]): AgentTool$1[];
|
|
19
20
|
//#endregion
|
|
20
21
|
export { PiAdapterOptions, apiKeyFromModel, createPiAdapter, createPiModel, extractPiText, toPiTools };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RetryableAgentError } from "@alint-js/core/agent";
|
|
1
2
|
import { Agent } from "@earendil-works/pi-agent-core";
|
|
2
3
|
import { Type } from "@earendil-works/pi-ai";
|
|
3
4
|
//#region src/index.ts
|
|
@@ -7,10 +8,32 @@ function apiKeyFromModel(model) {
|
|
|
7
8
|
function createPiAdapter(options = {}) {
|
|
8
9
|
const run = options.run ?? runPiAgent;
|
|
9
10
|
return async (request) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
let toolStarted = false;
|
|
12
|
+
const trackedRequest = {
|
|
13
|
+
...request,
|
|
14
|
+
tools: request.tools.map((tool) => ({
|
|
15
|
+
...tool,
|
|
16
|
+
execute: (input) => {
|
|
17
|
+
toolStarted = true;
|
|
18
|
+
return tool.execute(input);
|
|
19
|
+
}
|
|
20
|
+
}))
|
|
13
21
|
};
|
|
22
|
+
try {
|
|
23
|
+
request.signal?.throwIfAborted();
|
|
24
|
+
const messages = await run(trackedRequest);
|
|
25
|
+
request.signal?.throwIfAborted();
|
|
26
|
+
const assistant = [...messages].reverse().find((message) => message.role === "assistant");
|
|
27
|
+
if (assistant?.stopReason === "error" || assistant?.stopReason === "aborted") throw new Error(typeof assistant.errorMessage === "string" ? assistant.errorMessage : "Pi agent failed");
|
|
28
|
+
return {
|
|
29
|
+
answer: extractPiText(assistant),
|
|
30
|
+
usage: void 0
|
|
31
|
+
};
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (request.signal?.aborted) throw request.signal.reason;
|
|
34
|
+
if (!toolStarted) throw new RetryableAgentError("Pi agent invocation can be safely replayed", { cause: error });
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
14
37
|
};
|
|
15
38
|
}
|
|
16
39
|
function createPiModel(model) {
|
|
@@ -66,9 +89,17 @@ async function runPiAgent(request) {
|
|
|
66
89
|
tools: toPiTools(request.tools)
|
|
67
90
|
}
|
|
68
91
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
const abort = () => agent.abort();
|
|
93
|
+
request.signal?.addEventListener("abort", abort, { once: true });
|
|
94
|
+
try {
|
|
95
|
+
request.signal?.throwIfAborted();
|
|
96
|
+
await agent.prompt(request.prompt);
|
|
97
|
+
await agent.waitForIdle();
|
|
98
|
+
request.signal?.throwIfAborted();
|
|
99
|
+
return agent.state.messages;
|
|
100
|
+
} finally {
|
|
101
|
+
request.signal?.removeEventListener("abort", abort);
|
|
102
|
+
}
|
|
72
103
|
}
|
|
73
104
|
//#endregion
|
|
74
105
|
export { apiKeyFromModel, createPiAdapter, createPiModel, extractPiText, toPiTools };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alint-js/agent-pi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.28",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.mts",
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@alint-js/core": "0.0.
|
|
16
|
+
"@alint-js/core": "0.0.28"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@earendil-works/pi-agent-core": "^0.80.
|
|
20
|
-
"@earendil-works/pi-ai": "^0.80.
|
|
21
|
-
"@smithy/node-http-handler": "^4.9.
|
|
19
|
+
"@earendil-works/pi-agent-core": "^0.80.7",
|
|
20
|
+
"@earendil-works/pi-ai": "^0.80.7",
|
|
21
|
+
"@smithy/node-http-handler": "^4.9.6"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@alint-js/core": "0.0.
|
|
24
|
+
"@alint-js/core": "0.0.28"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "tsdown",
|