@mariozechner/pi-agent-core 0.9.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/dist/agent.d.ts +47 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +311 -0
- package/dist/agent.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/transports/AppTransport.d.ts +24 -0
- package/dist/transports/AppTransport.d.ts.map +1 -0
- package/dist/transports/AppTransport.js +312 -0
- package/dist/transports/AppTransport.js.map +1 -0
- package/dist/transports/ProviderTransport.d.ts +25 -0
- package/dist/transports/ProviderTransport.d.ts.map +1 -0
- package/dist/transports/ProviderTransport.js +46 -0
- package/dist/transports/ProviderTransport.js.map +1 -0
- package/dist/transports/index.d.ts +5 -0
- package/dist/transports/index.d.ts.map +1 -0
- package/dist/transports/index.js +3 -0
- package/dist/transports/index.js.map +1 -0
- package/dist/transports/proxy-types.d.ts +53 -0
- package/dist/transports/proxy-types.d.ts.map +1 -0
- package/dist/transports/proxy-types.js +2 -0
- package/dist/transports/proxy-types.js.map +1 -0
- package/dist/transports/types.d.ts +22 -0
- package/dist/transports/types.d.ts.map +1 -0
- package/dist/transports/types.js +2 -0
- package/dist/transports/types.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { AgentTool, AssistantMessage, AssistantMessageEvent, Message, Model, UserMessage } from "@mariozechner/pi-ai";
|
|
2
|
+
/**
|
|
3
|
+
* Attachment type definition.
|
|
4
|
+
* Processing is done by consumers (e.g., document extraction in web-ui).
|
|
5
|
+
*/
|
|
6
|
+
export interface Attachment {
|
|
7
|
+
id: string;
|
|
8
|
+
type: "image" | "document";
|
|
9
|
+
fileName: string;
|
|
10
|
+
mimeType: string;
|
|
11
|
+
size: number;
|
|
12
|
+
content: string;
|
|
13
|
+
extractedText?: string;
|
|
14
|
+
preview?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Thinking/reasoning level for models that support it.
|
|
18
|
+
*/
|
|
19
|
+
export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high";
|
|
20
|
+
/**
|
|
21
|
+
* User message with optional attachments.
|
|
22
|
+
*/
|
|
23
|
+
export type UserMessageWithAttachments = UserMessage & {
|
|
24
|
+
attachments?: Attachment[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Extensible interface for custom app messages.
|
|
28
|
+
* Apps can extend via declaration merging:
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* declare module "@mariozechner/agent" {
|
|
33
|
+
* interface CustomMessages {
|
|
34
|
+
* artifact: ArtifactMessage;
|
|
35
|
+
* notification: NotificationMessage;
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export interface CustomMessages {
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* AppMessage: Union of LLM messages + attachments + custom messages.
|
|
44
|
+
* This abstraction allows apps to add custom message types while maintaining
|
|
45
|
+
* type safety and compatibility with the base LLM messages.
|
|
46
|
+
*/
|
|
47
|
+
export type AppMessage = AssistantMessage | UserMessageWithAttachments | Message | CustomMessages[keyof CustomMessages];
|
|
48
|
+
/**
|
|
49
|
+
* Agent state containing all configuration and conversation data.
|
|
50
|
+
*/
|
|
51
|
+
export interface AgentState {
|
|
52
|
+
systemPrompt: string;
|
|
53
|
+
model: Model<any>;
|
|
54
|
+
thinkingLevel: ThinkingLevel;
|
|
55
|
+
tools: AgentTool<any>[];
|
|
56
|
+
messages: AppMessage[];
|
|
57
|
+
isStreaming: boolean;
|
|
58
|
+
streamMessage: Message | null;
|
|
59
|
+
pendingToolCalls: Set<string>;
|
|
60
|
+
error?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Events emitted by the Agent for UI updates.
|
|
64
|
+
* These events provide fine-grained lifecycle information for messages, turns, and tool executions.
|
|
65
|
+
*/
|
|
66
|
+
export type AgentEvent = {
|
|
67
|
+
type: "agent_start";
|
|
68
|
+
} | {
|
|
69
|
+
type: "agent_end";
|
|
70
|
+
messages: AppMessage[];
|
|
71
|
+
} | {
|
|
72
|
+
type: "turn_start";
|
|
73
|
+
} | {
|
|
74
|
+
type: "turn_end";
|
|
75
|
+
message: AppMessage;
|
|
76
|
+
toolResults: AppMessage[];
|
|
77
|
+
} | {
|
|
78
|
+
type: "message_start";
|
|
79
|
+
message: AppMessage;
|
|
80
|
+
} | {
|
|
81
|
+
type: "message_update";
|
|
82
|
+
message: AppMessage;
|
|
83
|
+
assistantMessageEvent: AssistantMessageEvent;
|
|
84
|
+
} | {
|
|
85
|
+
type: "message_end";
|
|
86
|
+
message: AppMessage;
|
|
87
|
+
} | {
|
|
88
|
+
type: "tool_execution_start";
|
|
89
|
+
toolCallId: string;
|
|
90
|
+
toolName: string;
|
|
91
|
+
args: any;
|
|
92
|
+
} | {
|
|
93
|
+
type: "tool_execution_end";
|
|
94
|
+
toolCallId: string;
|
|
95
|
+
toolName: string;
|
|
96
|
+
result: any;
|
|
97
|
+
isError: boolean;
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,OAAO,EACP,KAAK,EACL,WAAW,EACX,MAAM,qBAAqB,CAAC;AAE7B;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,GAAG,UA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,UAAU,CAAC;IAAC,OAAO,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,UAAU,EAAE,CAAA;CAAE,GAEpE;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAE,GAE9C;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,UAAU,CAAC;IAAC,qBAAqB,EAAE,qBAAqB,CAAA;CAAE,GAC7F;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAE,GAE5C;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,GACjF;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,GAAG,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC","sourcesContent":["import type {\n\tAgentTool,\n\tAssistantMessage,\n\tAssistantMessageEvent,\n\tMessage,\n\tModel,\n\tUserMessage,\n} from \"@mariozechner/pi-ai\";\n\n/**\n * Attachment type definition.\n * Processing is done by consumers (e.g., document extraction in web-ui).\n */\nexport interface Attachment {\n\tid: string;\n\ttype: \"image\" | \"document\";\n\tfileName: string;\n\tmimeType: string;\n\tsize: number;\n\tcontent: string; // base64 encoded (without data URL prefix)\n\textractedText?: string; // For documents\n\tpreview?: string; // base64 image preview\n}\n\n/**\n * Thinking/reasoning level for models that support it.\n */\nexport type ThinkingLevel = \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\";\n\n/**\n * User message with optional attachments.\n */\nexport type UserMessageWithAttachments = UserMessage & { attachments?: Attachment[] };\n\n/**\n * Extensible interface for custom app messages.\n * Apps can extend via declaration merging:\n *\n * @example\n * ```typescript\n * declare module \"@mariozechner/agent\" {\n * interface CustomMessages {\n * artifact: ArtifactMessage;\n * notification: NotificationMessage;\n * }\n * }\n * ```\n */\nexport interface CustomMessages {\n\t// Empty by default - apps extend via declaration merging\n}\n\n/**\n * AppMessage: Union of LLM messages + attachments + custom messages.\n * This abstraction allows apps to add custom message types while maintaining\n * type safety and compatibility with the base LLM messages.\n */\nexport type AppMessage =\n\t| AssistantMessage\n\t| UserMessageWithAttachments\n\t| Message // Includes ToolResultMessage\n\t| CustomMessages[keyof CustomMessages];\n\n/**\n * Agent state containing all configuration and conversation data.\n */\nexport interface AgentState {\n\tsystemPrompt: string;\n\tmodel: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\ttools: AgentTool<any>[];\n\tmessages: AppMessage[]; // Can include attachments + custom message types\n\tisStreaming: boolean;\n\tstreamMessage: Message | null;\n\tpendingToolCalls: Set<string>;\n\terror?: string;\n}\n\n/**\n * Events emitted by the Agent for UI updates.\n * These events provide fine-grained lifecycle information for messages, turns, and tool executions.\n */\nexport type AgentEvent =\n\t// Agent lifecycle\n\t| { type: \"agent_start\" }\n\t| { type: \"agent_end\"; messages: AppMessage[] }\n\t// Turn lifecycle - a turn is one assistant response + any tool calls/results\n\t| { type: \"turn_start\" }\n\t| { type: \"turn_end\"; message: AppMessage; toolResults: AppMessage[] }\n\t// Message lifecycle - emitted for user, assistant, and toolResult messages\n\t| { type: \"message_start\"; message: AppMessage }\n\t// Only emitted for assistant messages during streaming\n\t| { type: \"message_update\"; message: AppMessage; assistantMessageEvent: AssistantMessageEvent }\n\t| { type: \"message_end\"; message: AppMessage }\n\t// Tool execution lifecycle\n\t| { type: \"tool_execution_start\"; toolCallId: string; toolName: string; args: any }\n\t| { type: \"tool_execution_end\"; toolCallId: string; toolName: string; result: any; isError: boolean };\n"]}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n\tAgentTool,\n\tAssistantMessage,\n\tAssistantMessageEvent,\n\tMessage,\n\tModel,\n\tUserMessage,\n} from \"@mariozechner/pi-ai\";\n\n/**\n * Attachment type definition.\n * Processing is done by consumers (e.g., document extraction in web-ui).\n */\nexport interface Attachment {\n\tid: string;\n\ttype: \"image\" | \"document\";\n\tfileName: string;\n\tmimeType: string;\n\tsize: number;\n\tcontent: string; // base64 encoded (without data URL prefix)\n\textractedText?: string; // For documents\n\tpreview?: string; // base64 image preview\n}\n\n/**\n * Thinking/reasoning level for models that support it.\n */\nexport type ThinkingLevel = \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\";\n\n/**\n * User message with optional attachments.\n */\nexport type UserMessageWithAttachments = UserMessage & { attachments?: Attachment[] };\n\n/**\n * Extensible interface for custom app messages.\n * Apps can extend via declaration merging:\n *\n * @example\n * ```typescript\n * declare module \"@mariozechner/agent\" {\n * interface CustomMessages {\n * artifact: ArtifactMessage;\n * notification: NotificationMessage;\n * }\n * }\n * ```\n */\nexport interface CustomMessages {\n\t// Empty by default - apps extend via declaration merging\n}\n\n/**\n * AppMessage: Union of LLM messages + attachments + custom messages.\n * This abstraction allows apps to add custom message types while maintaining\n * type safety and compatibility with the base LLM messages.\n */\nexport type AppMessage =\n\t| AssistantMessage\n\t| UserMessageWithAttachments\n\t| Message // Includes ToolResultMessage\n\t| CustomMessages[keyof CustomMessages];\n\n/**\n * Agent state containing all configuration and conversation data.\n */\nexport interface AgentState {\n\tsystemPrompt: string;\n\tmodel: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\ttools: AgentTool<any>[];\n\tmessages: AppMessage[]; // Can include attachments + custom message types\n\tisStreaming: boolean;\n\tstreamMessage: Message | null;\n\tpendingToolCalls: Set<string>;\n\terror?: string;\n}\n\n/**\n * Events emitted by the Agent for UI updates.\n * These events provide fine-grained lifecycle information for messages, turns, and tool executions.\n */\nexport type AgentEvent =\n\t// Agent lifecycle\n\t| { type: \"agent_start\" }\n\t| { type: \"agent_end\"; messages: AppMessage[] }\n\t// Turn lifecycle - a turn is one assistant response + any tool calls/results\n\t| { type: \"turn_start\" }\n\t| { type: \"turn_end\"; message: AppMessage; toolResults: AppMessage[] }\n\t// Message lifecycle - emitted for user, assistant, and toolResult messages\n\t| { type: \"message_start\"; message: AppMessage }\n\t// Only emitted for assistant messages during streaming\n\t| { type: \"message_update\"; message: AppMessage; assistantMessageEvent: AssistantMessageEvent }\n\t| { type: \"message_end\"; message: AppMessage }\n\t// Tool execution lifecycle\n\t| { type: \"tool_execution_start\"; toolCallId: string; toolName: string; args: any }\n\t| { type: \"tool_execution_end\"; toolCallId: string; toolName: string; result: any; isError: boolean };\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mariozechner/pi-agent-core",
|
|
3
|
+
"version": "0.9.1",
|
|
4
|
+
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"clean": "rm -rf dist",
|
|
14
|
+
"build": "tsgo -p tsconfig.build.json",
|
|
15
|
+
"dev": "tsgo -p tsconfig.build.json --watch --preserveWatchOutput",
|
|
16
|
+
"check": "tsgo --noEmit",
|
|
17
|
+
"test": "vitest --run",
|
|
18
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@mariozechner/pi-ai": "^0.9.1",
|
|
22
|
+
"@mariozechner/pi-tui": "^0.9.1"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"ai",
|
|
26
|
+
"agent",
|
|
27
|
+
"llm",
|
|
28
|
+
"transport",
|
|
29
|
+
"state-management"
|
|
30
|
+
],
|
|
31
|
+
"author": "Mario Zechner",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/badlogic/pi-mono.git",
|
|
36
|
+
"directory": "packages/agent"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^24.3.0",
|
|
43
|
+
"typescript": "^5.7.3",
|
|
44
|
+
"vitest": "^3.2.4"
|
|
45
|
+
}
|
|
46
|
+
}
|