@agentified/fe-client 0.0.3 → 0.0.4

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 +160 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,160 @@
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; // for token % calculation
46
+ maxEventLogSize?: number; // max events in log (default unbounded)
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: { page: "/dashboard" },
77
+ });
78
+ ```
79
+
80
+ ### `client.registerToolHandler(name, handler)`
81
+
82
+ Registers a frontend tool handler. When the agent calls this tool, the handler runs client-side.
83
+
84
+ ```typescript
85
+ client.registerToolHandler("open_modal", async (args) => {
86
+ openModal(args.modalId);
87
+ return { opened: true };
88
+ });
89
+ ```
90
+
91
+ ### `client.unregisterToolHandler(name)`
92
+
93
+ ```typescript
94
+ client.unregisterToolHandler("open_modal");
95
+ ```
96
+
97
+ ### `client.setSharedContext(ctx)`
98
+
99
+ Sets shared context (page, modals, active tab) sent with each agent request.
100
+
101
+ ```typescript
102
+ client.setSharedContext({ page: "/employees", openModals: [], activeTab: "list" });
103
+ ```
104
+
105
+ ### `client.getMessages()`
106
+
107
+ Returns current message history.
108
+
109
+ ### `client.getState()`
110
+
111
+ Returns the full `InspectorState` snapshot.
112
+
113
+ ### `client.getAvailableFrontendToolNames()`
114
+
115
+ Returns names of registered frontend tool handlers.
116
+
117
+ ### `client.reset()`
118
+
119
+ Resets all state (messages, events, tools, connection status).
120
+
121
+ ## State Model
122
+
123
+ The client maintains an `InspectorState` that tracks everything:
124
+
125
+ ```typescript
126
+ interface InspectorState {
127
+ connection: ConnectionStatus; // "idle" | "connecting" | "connected" | "disconnected" | "error"
128
+ run: RunInfo; // runId, threadId, startedAt, durationMs
129
+ agentified: {
130
+ prefetchResults: PrefetchResult[];
131
+ discoveries: DiscoveryResult[];
132
+ currentTools: AgentifiedTool[];
133
+ };
134
+ tokens: TokenState; // input, output, cached, reasoning, contextWindowPercent
135
+ streaming: StreamingMetrics; // messageCount, toolCallCount, timeToFirstTokenMs
136
+ toolCalls: ToolCallDetail[]; // all tool calls with timing
137
+ events: EventLogEntry[]; // full event log
138
+ messages: Message[];
139
+ isLoading: boolean;
140
+ error: string | null;
141
+ frontendTools: string[];
142
+ sharedContext?: SharedContext;
143
+ }
144
+ ```
145
+
146
+ ## Frontend Tool Handling
147
+
148
+ The client handles frontend tools automatically:
149
+
150
+ 1. Agent calls a tool with `metadata.location === "frontend"`
151
+ 2. Client intercepts it and runs the registered handler
152
+ 3. Tool result is injected back into the conversation
153
+ 4. Agent continues with up to 5 iterations of frontend tool calls
154
+
155
+ ## Links
156
+
157
+ - [Root README](../../../README.md)
158
+ - [React Bindings](../react/README.md) — React wrapper with Provider/hooks
159
+ - [TypeScript SDK](../sdk/README.md)
160
+ - [agentified-core](../../core/README.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentified/fe-client",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",