@agentified/fe-client 0.0.3 → 0.0.5-beta.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.
Files changed (2) hide show
  1. package/README.md +166 -0
  2. package/package.json +2 -1
package/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # @agentified/fe-client
2
+
3
+ Frontend client for [Agentified](../../README.md) — connects to an AG-UI agent backend, handles streaming events, manages frontend tool execution, and exposes full inspector state.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @agentified/fe-client
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { AgentifiedClient } from "@agentified/fe-client";
15
+
16
+ const client = new AgentifiedClient({
17
+ agentUrl: "http://localhost:3003/api/chat",
18
+ });
19
+
20
+ // Subscribe to state changes
21
+ client.subscribe((state) => {
22
+ console.log("Messages:", state.messages);
23
+ console.log("Loading:", state.isLoading);
24
+ console.log("Tools:", state.agentified.currentTools);
25
+ });
26
+
27
+ // Register a frontend tool handler
28
+ client.registerToolHandler("navigate_to_page", async (args) => {
29
+ window.location.href = args.path;
30
+ return { success: true };
31
+ });
32
+
33
+ // Send a message (streams AG-UI events from backend)
34
+ await client.sendMessage("Show me the dashboard");
35
+ ```
36
+
37
+ ## API Reference
38
+
39
+ ### `new AgentifiedClient(config)`
40
+
41
+ ```typescript
42
+ interface AgentifiedClientConfig {
43
+ agentUrl: string; // AG-UI agent backend URL
44
+ headers?: Record<string, string>; // custom HTTP headers
45
+ contextWindowSize?: number; // reserved for future use
46
+ maxEventLogSize?: number; // reserved for future use
47
+ }
48
+ ```
49
+
50
+ ### `client.subscribe(listener)`
51
+
52
+ Subscribe to state changes. Returns an object with `unsubscribe()`.
53
+
54
+ ```typescript
55
+ const sub = client.subscribe((state: InspectorState) => {
56
+ // called on every state change
57
+ });
58
+ sub.unsubscribe();
59
+ ```
60
+
61
+ ### `client.sendMessage(content)`
62
+
63
+ Sends a user message and streams the agent response.
64
+
65
+ ```typescript
66
+ await client.sendMessage("What employees are on leave?");
67
+ ```
68
+
69
+ ### `client.run(input)`
70
+
71
+ Lower-level: runs the agent with full message history and optional context.
72
+
73
+ ```typescript
74
+ await client.run({
75
+ messages: [{ role: "user", content: "Hello" }],
76
+ context: [{ description: "Current page", value: "/dashboard" }],
77
+ });
78
+ ```
79
+
80
+ `context` is `Context[]` from `@ag-ui/client`.
81
+
82
+ ### `client.registerToolHandler(name, handler)`
83
+
84
+ Registers a frontend tool handler. When the agent calls this tool, the handler runs client-side.
85
+
86
+ ```typescript
87
+ client.registerToolHandler("open_modal", async (args) => {
88
+ openModal(args.modalId);
89
+ return { opened: true };
90
+ });
91
+ ```
92
+
93
+ ### `client.unregisterToolHandler(name)`
94
+
95
+ ```typescript
96
+ client.unregisterToolHandler("open_modal");
97
+ ```
98
+
99
+ ### `client.setSharedContext(ctx)`
100
+
101
+ Sets shared context (page, modals, active tab) sent with each agent request.
102
+
103
+ ```typescript
104
+ client.setSharedContext({ page: "/employees", openModals: [], activeTab: "list" });
105
+ ```
106
+
107
+ ### `client.getMessages()`
108
+
109
+ Returns current message history.
110
+
111
+ ### `client.getState()`
112
+
113
+ Returns the full `InspectorState` snapshot.
114
+
115
+ ### `client.getAvailableFrontendToolNames()`
116
+
117
+ Returns names of registered frontend tool handlers.
118
+
119
+ ### `client.reset()`
120
+
121
+ Resets all state (messages, events, tools, connection status).
122
+
123
+ ## State Model
124
+
125
+ The client maintains an `InspectorState` that tracks everything:
126
+
127
+ ```typescript
128
+ interface InspectorState {
129
+ connection: ConnectionStatus; // "idle" | "connecting" | "connected" | "disconnected" | "error"
130
+ run: RunInfo; // runId, threadId, startedAt, durationMs
131
+ agentified: {
132
+ prefetchResults: PrefetchResult[];
133
+ discoveries: DiscoveryResult[];
134
+ currentTools: AgentifiedTool[];
135
+ };
136
+ tokens: TokenState; // input, output, cached, reasoning, contextWindowPercent
137
+ streaming: StreamingMetrics; // messageCount, toolCallCount, timeToFirstTokenMs
138
+ toolCalls: ToolCallDetail[]; // all tool calls with timing
139
+ events: EventLogEntry[]; // full event log
140
+ messages: Message[];
141
+ isLoading: boolean;
142
+ error: string | null;
143
+ frontendTools: string[];
144
+ sharedContext?: SharedContext;
145
+ }
146
+ ```
147
+
148
+ ## Frontend Tool Handling
149
+
150
+ The client handles frontend tools automatically:
151
+
152
+ 1. Agent calls a tool with `metadata.location === "frontend"`
153
+ 2. Client intercepts it and runs the registered handler
154
+ 3. Tool result is injected back into the conversation
155
+ 4. Agent continues with up to 5 iterations of frontend tool calls
156
+
157
+ ## Links
158
+
159
+ - [Root README](../../../README.md)
160
+ - [React Bindings](../react/README.md) — React wrapper with Provider/hooks
161
+ - [TypeScript SDK](../sdk/README.md)
162
+ - [agentified-core](../../core/README.md)
163
+
164
+ ## License
165
+
166
+ [MIT](../../../LICENSE.md#mit-license)
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@agentified/fe-client",
3
- "version": "0.0.3",
3
+ "version": "0.0.5-beta.0",
4
+ "license": "MIT",
4
5
  "type": "module",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",