@agentified/mastra 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 +149 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # @agentified/mastra
2
+
3
+ [Mastra](https://mastra.ai) adapter for [Agentified](../../README.md) — wraps a Mastra agent with Agentified context resolution, dynamic tool hydration, and AG-UI streaming.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @agentified/mastra @agentified/sdk
9
+ ```
10
+
11
+ **Peer dependencies:** `@mastra/core >= 1.0.0`, `@ag-ui/client >= 0.0.45`, `@ag-ui/mastra >= 1.0.0`, `zod >= 3.0.0`
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { Agent } from "@mastra/core/agent";
17
+ import { AgentifiedMastra, streamSSE } from "@agentified/mastra";
18
+ import { tool } from "@agentified/sdk";
19
+
20
+ const agent = new Agent({ name: "my-agent", model: google("gemini-3-flash-preview"), instructions: "You are a helpful assistant." });
21
+
22
+ const agentified = new AgentifiedMastra({
23
+ agentifiedUrl: "http://localhost:9119",
24
+ tools: [
25
+ tool({ name: "get_weather", description: "Get weather", parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"] } }),
26
+ ],
27
+ toolHandlers: {
28
+ get_weather: async ({ city }) => ({ temp: 22, unit: "C", city }),
29
+ },
30
+ agent,
31
+ });
32
+
33
+ await agentified.register();
34
+ ```
35
+
36
+ ## API Reference
37
+
38
+ ### `new AgentifiedMastra(config)`
39
+
40
+ ```typescript
41
+ interface AgentifiedMastraConfig {
42
+ agentifiedUrl: string;
43
+ tools: ServerTool[];
44
+ toolHandlers: Record<string, (args: unknown) => Promise<unknown>>;
45
+ agent: Agent; // @mastra/core Agent instance
46
+ }
47
+ ```
48
+
49
+ ### `agentified.register()`
50
+
51
+ Registers tools with the Agentified server.
52
+
53
+ ```typescript
54
+ await agentified.register();
55
+ ```
56
+
57
+ ### `agentified.generate(options)`
58
+
59
+ Runs a full generate cycle: prefetch → hydrate tools → agent.generate → capture turn.
60
+
61
+ ```typescript
62
+ interface GenerateOptions {
63
+ messages: Message[];
64
+ maxSteps?: number;
65
+ turnId?: string; // session continuity
66
+ toolLimit?: number;
67
+ seed?: number;
68
+ debug?: boolean;
69
+ onStepFinish?: (event: { usage: TokenUsage; toolCalls: unknown[] }) => void;
70
+ }
71
+
72
+ const result = await agentified.generate({
73
+ messages: [{ role: "user", content: "What's the weather in Rome?" }],
74
+ maxSteps: 5,
75
+ });
76
+
77
+ // result:
78
+ // {
79
+ // text: "The weather in Rome is 22°C.",
80
+ // toolCalls: [...],
81
+ // steps: [...],
82
+ // usage: { inputTokens, outputTokens, totalTokens },
83
+ // hydratedTools: ["get_weather"],
84
+ // turnId: "...",
85
+ // durationMs: 1234,
86
+ // }
87
+ ```
88
+
89
+ The `generate` flow:
90
+ 1. **Prefetch** — discovers relevant tools for the conversation
91
+ 2. **Hydrate** — converts ranked tools to Mastra tools (JSON Schema → Zod) and injects `agentified_discover` for runtime discovery
92
+ 3. **Generate** — calls `agent.generate()` with a `prepareStep` callback that dynamically expands tools when the agent discovers more
93
+ 4. **Capture turn** — stores the turn for session continuity
94
+
95
+ ### `agentified.run(options)`
96
+
97
+ Returns an `Observable<BaseEvent>` for AG-UI streaming — designed for use with the frontend client.
98
+
99
+ ```typescript
100
+ interface RunOptions {
101
+ messages: Message[];
102
+ frontendTools?: string[]; // frontend tool names to exclude from prefetch
103
+ }
104
+
105
+ const observable = await agentified.run({
106
+ messages: [{ role: "user", content: "Hello" }],
107
+ frontendTools: ["navigate_to_page"],
108
+ });
109
+ ```
110
+
111
+ ### `streamSSE(observable, res)`
112
+
113
+ Pipes an AG-UI Observable into an HTTP SSE response.
114
+
115
+ ```typescript
116
+ import { streamSSE } from "@agentified/mastra";
117
+ import http from "http";
118
+
119
+ http.createServer(async (req, res) => {
120
+ const observable = await agentified.run({ messages });
121
+ streamSSE(observable, res);
122
+ }).listen(3003);
123
+ ```
124
+
125
+ SSE format: `data: <JSON>\n\n` per event, connection closes on stream completion.
126
+
127
+ ### `jsonSchemaToZod(schema)`
128
+
129
+ Converts a JSON Schema object to a Zod schema. Used internally to hydrate Mastra tools from Agentified's JSON Schema parameters.
130
+
131
+ ```typescript
132
+ import { jsonSchemaToZod } from "@agentified/mastra";
133
+
134
+ const zodSchema = jsonSchemaToZod({
135
+ type: "object",
136
+ properties: { city: { type: "string" } },
137
+ required: ["city"],
138
+ });
139
+ ```
140
+
141
+ Supports: `string`, `number`, `integer`, `boolean`, `array`, `object`, `enum`.
142
+
143
+ ## Links
144
+
145
+ - [Root README](../../../README.md)
146
+ - [TypeScript SDK](../sdk/README.md)
147
+ - [Frontend Client](../fe-client/README.md)
148
+ - [React Bindings](../react/README.md)
149
+ - [QuickHR Example](../../../examples/quickhr/) — full Mastra + React app
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentified/mastra",
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",
@@ -26,7 +26,7 @@
26
26
  "@ag-ui/mastra": ">=1.0.0",
27
27
  "@mastra/core": ">=1.0.0",
28
28
  "zod": ">=3.0.0",
29
- "@agentified/sdk": "0.0.3"
29
+ "@agentified/sdk": "0.0.4"
30
30
  },
31
31
  "dependencies": {
32
32
  "rxjs": "^7.8.0"
@@ -39,7 +39,7 @@
39
39
  "typescript": "^5.9.0",
40
40
  "vitest": "^2.1.0",
41
41
  "zod": "^3.25.0",
42
- "@agentified/sdk": "0.0.3"
42
+ "@agentified/sdk": "0.0.4"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "tsc -p tsconfig.build.json",