@agentified/mastra 0.0.5-beta.6 → 0.0.5-beta.7
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/README.md +30 -8
- package/dist/agentified.d.ts +64 -7
- package/dist/agentified.d.ts.map +1 -1
- package/dist/agentified.js +121 -14
- package/dist/agentified.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/adapter.d.ts +0 -94
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js +0 -361
- package/dist/adapter.js.map +0 -1
- package/dist/spawn-utils.d.ts +0 -3
- package/dist/spawn-utils.d.ts.map +0 -1
- package/dist/spawn-utils.js +0 -42
- package/dist/spawn-utils.js.map +0 -1
package/README.md
CHANGED
|
@@ -21,18 +21,34 @@ import { openai } from "@ai-sdk/openai";
|
|
|
21
21
|
const ag = new Agentified().adaptTo(mastra());
|
|
22
22
|
await ag.connect("http://localhost:9119");
|
|
23
23
|
|
|
24
|
-
const
|
|
24
|
+
const instance = await ag.dataset("my-agent").register({
|
|
25
25
|
tools: [
|
|
26
26
|
{ name: "get_weather", description: "Get weather", parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"] }, handler: async (args) => ({ temp: 22 }) },
|
|
27
27
|
],
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
const session = instance.session("chat-1");
|
|
30
31
|
const agent = new Agent({
|
|
31
32
|
name: "my-agent",
|
|
32
33
|
model: openai("gpt-4o-mini"),
|
|
33
|
-
instructions: "
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
instructions: "Use agentified_discover to find tools, then call them.",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Simple — prepareStep is a property, includes discover by default
|
|
38
|
+
const result = await agent.generate(messages, {
|
|
39
|
+
prepareStep: session.prepareStep,
|
|
40
|
+
maxSteps: 10,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// With explicit tools via context chain
|
|
44
|
+
const ctx = await session.context
|
|
45
|
+
.tools({ agentified_discover: session.discoverTool })
|
|
46
|
+
.assemble();
|
|
47
|
+
// ctx.tools → { agentified_discover, ...discoveredTools }
|
|
48
|
+
// ctx.prepareStep → returns { tools } for Mastra injection
|
|
49
|
+
const result2 = await agent.generate(messages, {
|
|
50
|
+
prepareStep: ctx.prepareStep,
|
|
51
|
+
maxSteps: 10,
|
|
36
52
|
});
|
|
37
53
|
```
|
|
38
54
|
|
|
@@ -47,11 +63,17 @@ Agentified.adaptTo(mastra()) → MastraAgentified
|
|
|
47
63
|
└─ .dataset(name) → MastraDatasetRef
|
|
48
64
|
└─ .register({ tools }) → MastraInstance
|
|
49
65
|
├─ .discoverTool — Mastra createTool
|
|
50
|
-
├─ .prepareStep —
|
|
66
|
+
├─ .prepareStep — property, returns { tools } for injection
|
|
51
67
|
├─ .session(id) → MastraSession
|
|
52
68
|
│ ├─ .discoverTool — Mastra createTool
|
|
53
|
-
│ ├─ .prepareStep
|
|
54
|
-
│ ├─ .context
|
|
69
|
+
│ ├─ .prepareStep — property, returns { tools }
|
|
70
|
+
│ ├─ .context → MastraContextBuilder
|
|
71
|
+
│ │ ├─ .tools(Record<string, MastraTool>) — chainable
|
|
72
|
+
│ │ ├─ .messages() / .recall()
|
|
73
|
+
│ │ └─ .assemble() → MastraAssembledContext
|
|
74
|
+
│ │ ├─ .tools — explicit + discovered
|
|
75
|
+
│ │ └─ .prepareStep — returns { tools }
|
|
76
|
+
│ ├─ .conversation (SDK passthrough)
|
|
55
77
|
│ └─ .getMessages / .updateConversation
|
|
56
78
|
└─ .namespace(id) → MastraNamespace
|
|
57
79
|
└─ .session(id) → MastraSession
|
|
@@ -105,7 +127,7 @@ import { jsonSchemaToZod } from "@agentified/mastra";
|
|
|
105
127
|
- [TypeScript SDK](../sdk/README.md)
|
|
106
128
|
- [Frontend Client](../fe-client/README.md)
|
|
107
129
|
- [React Bindings](../react/README.md)
|
|
108
|
-
- [mastra-smoke example](../../../examples/mastra-smoke/) — runnable smoke test
|
|
130
|
+
- [ts-mastra-smoke example](../../../examples/ts-mastra-smoke/) — runnable smoke test
|
|
109
131
|
- [QuickHR Example](../../../examples/quickhr/) — full Mastra + React app
|
|
110
132
|
|
|
111
133
|
## License
|
package/dist/agentified.d.ts
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createTool } from "@mastra/core/tools";
|
|
2
|
+
import type { Agentified, Instance, DatasetRef, Session, Namespace, BackendTool, RegisterInput, GetMessagesOptions, ContextBuilder, AssembledContext, ContextStrategy } from "agentified";
|
|
3
|
+
type MastraTool = ReturnType<typeof createTool>;
|
|
4
|
+
export declare class MastraAssembledContext {
|
|
5
|
+
private readonly sdkCtx;
|
|
6
|
+
readonly tools: Record<string, MastraTool>;
|
|
7
|
+
private readonly sdkPrepareStep;
|
|
8
|
+
constructor(sdkCtx: AssembledContext, tools: Record<string, MastraTool>, sdkPrepareStep: Session["prepareStep"]);
|
|
9
|
+
get messages(): import("agentified").StoredMessage[];
|
|
10
|
+
get recalled(): {
|
|
11
|
+
tools: unknown[];
|
|
12
|
+
memories: unknown[];
|
|
13
|
+
};
|
|
14
|
+
get strategyUsed(): ContextStrategy;
|
|
15
|
+
get fallback(): boolean;
|
|
16
|
+
get tokenEstimate(): number;
|
|
17
|
+
get conversationMessages(): number;
|
|
18
|
+
get totalMessages(): number;
|
|
19
|
+
get includedMessages(): number;
|
|
20
|
+
readonly prepareStep: (params: {
|
|
21
|
+
stepNumber: number;
|
|
22
|
+
steps: any[];
|
|
23
|
+
}) => Promise<{
|
|
24
|
+
tools: Record<string, import("@mastra/core/tools").Tool<unknown, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, string, unknown>>;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export declare class MastraContextBuilder {
|
|
28
|
+
private readonly sdkBuilder;
|
|
29
|
+
private readonly sdkPrepareStep;
|
|
30
|
+
private readonly discoverMastraTool;
|
|
31
|
+
private readonly discoveredNames;
|
|
32
|
+
private readonly mastraToolCache;
|
|
33
|
+
private explicitTools;
|
|
34
|
+
constructor(sdkBuilder: ContextBuilder, sdkPrepareStep: Session["prepareStep"], discoverMastraTool: MastraTool, discoveredNames: Set<string>, mastraToolCache: Record<string, MastraTool>);
|
|
35
|
+
tools(tools: Record<string, MastraTool>): this;
|
|
36
|
+
messages(opts: {
|
|
37
|
+
strategy?: ContextStrategy;
|
|
38
|
+
maxTokens?: number;
|
|
39
|
+
}): this;
|
|
40
|
+
recall(opts?: unknown): this;
|
|
41
|
+
assemble(): Promise<MastraAssembledContext>;
|
|
42
|
+
}
|
|
2
43
|
export declare function mastra(): {
|
|
3
44
|
adapt: (ag: Agentified) => MastraAgentified;
|
|
4
45
|
};
|
|
@@ -17,22 +58,36 @@ export declare class MastraDatasetRef {
|
|
|
17
58
|
}
|
|
18
59
|
export declare class MastraInstance {
|
|
19
60
|
private readonly inst;
|
|
61
|
+
private readonly backendTools;
|
|
20
62
|
readonly discoverTool: any;
|
|
21
|
-
readonly
|
|
63
|
+
private readonly mastraToolCache;
|
|
22
64
|
get instanceId(): string;
|
|
23
65
|
get datasetId(): string;
|
|
24
|
-
constructor(inst: Instance);
|
|
66
|
+
constructor(inst: Instance, backendTools: BackendTool[]);
|
|
67
|
+
readonly prepareStep: (params: {
|
|
68
|
+
stepNumber: number;
|
|
69
|
+
steps: any[];
|
|
70
|
+
}) => Promise<{
|
|
71
|
+
tools: Record<string, import("@mastra/core/tools").Tool<unknown, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, string, unknown>>;
|
|
72
|
+
}>;
|
|
25
73
|
session(id: string): MastraSession;
|
|
26
74
|
namespace(id: string): MastraNamespace;
|
|
27
75
|
}
|
|
28
76
|
export declare class MastraSession {
|
|
29
77
|
private readonly sess;
|
|
78
|
+
private readonly backendTools;
|
|
30
79
|
readonly discoverTool: any;
|
|
31
|
-
readonly
|
|
80
|
+
private readonly mastraToolCache;
|
|
32
81
|
get id(): string;
|
|
33
|
-
get context(): import("agentified").ContextBuilder;
|
|
34
82
|
get conversation(): import("agentified").Conversation;
|
|
35
|
-
constructor(sess: Session);
|
|
83
|
+
constructor(sess: Session, backendTools: BackendTool[]);
|
|
84
|
+
get context(): MastraContextBuilder;
|
|
85
|
+
readonly prepareStep: (params: {
|
|
86
|
+
stepNumber: number;
|
|
87
|
+
steps: any[];
|
|
88
|
+
}) => Promise<{
|
|
89
|
+
tools: Record<string, import("@mastra/core/tools").Tool<unknown, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, string, unknown>>;
|
|
90
|
+
}>;
|
|
36
91
|
getMessages(opts?: GetMessagesOptions): Promise<import("agentified").GetMessagesResult>;
|
|
37
92
|
updateConversation(input: {
|
|
38
93
|
messages: Array<{
|
|
@@ -43,8 +98,10 @@ export declare class MastraSession {
|
|
|
43
98
|
}
|
|
44
99
|
export declare class MastraNamespace {
|
|
45
100
|
private readonly ns;
|
|
46
|
-
|
|
101
|
+
private readonly backendTools;
|
|
102
|
+
constructor(ns: Namespace, backendTools: BackendTool[]);
|
|
47
103
|
get id(): string;
|
|
48
104
|
session(id: string): MastraSession;
|
|
49
105
|
}
|
|
106
|
+
export {};
|
|
50
107
|
//# sourceMappingURL=agentified.d.ts.map
|
package/dist/agentified.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentified.d.ts","sourceRoot":"","sources":["../src/agentified.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agentified.d.ts","sourceRoot":"","sources":["../src/agentified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,OAAO,EACP,SAAS,EAET,WAAW,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IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAR/B,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA6B;IAE7D,IAAI,EAAE,WAA2B;IACjC,IAAI,YAAY,sCAAqC;gBAGlC,IAAI,EAAE,OAAO,EACb,YAAY,EAAE,WAAW,EAAE;IAM9C,IAAI,OAAO,IAAI,oBAAoB,CAQlC;IAED,QAAQ,CAAC,WAAW,GAAU,QAAQ;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,EAAE,CAAA;KAAE;;OASxE;IAEF,WAAW,CAAC,IAAI,CAAC,EAAE,kBAAkB;IACrC,kBAAkB,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;CAGjF;AAED,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,EAAE,EAAE,SAAS,EACb,YAAY,EAAE,WAAW,EAAE;IAG9C,IAAI,EAAE,WAAyB;IAE/B,OAAO,CAAC,EAAE,EAAE,MAAM;CACnB"}
|
package/dist/agentified.js
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
import { createTool } from "@mastra/core/tools";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { jsonSchemaToZod } from "./schema.js";
|
|
4
|
+
// --- MastraAssembledContext ---
|
|
5
|
+
export class MastraAssembledContext {
|
|
6
|
+
sdkCtx;
|
|
7
|
+
tools;
|
|
8
|
+
sdkPrepareStep;
|
|
9
|
+
constructor(sdkCtx, tools, sdkPrepareStep) {
|
|
10
|
+
this.sdkCtx = sdkCtx;
|
|
11
|
+
this.tools = tools;
|
|
12
|
+
this.sdkPrepareStep = sdkPrepareStep;
|
|
13
|
+
}
|
|
14
|
+
get messages() { return this.sdkCtx.messages; }
|
|
15
|
+
get recalled() { return this.sdkCtx.recalled; }
|
|
16
|
+
get strategyUsed() { return this.sdkCtx.strategyUsed; }
|
|
17
|
+
get fallback() { return this.sdkCtx.fallback; }
|
|
18
|
+
get tokenEstimate() { return this.sdkCtx.tokenEstimate; }
|
|
19
|
+
get conversationMessages() { return this.sdkCtx.conversationMessages; }
|
|
20
|
+
get totalMessages() { return this.sdkCtx.totalMessages; }
|
|
21
|
+
get includedMessages() { return this.sdkCtx.includedMessages; }
|
|
22
|
+
prepareStep = async (params) => {
|
|
23
|
+
await this.sdkPrepareStep(params);
|
|
24
|
+
return { tools: this.tools };
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// --- MastraContextBuilder ---
|
|
28
|
+
export class MastraContextBuilder {
|
|
29
|
+
sdkBuilder;
|
|
30
|
+
sdkPrepareStep;
|
|
31
|
+
discoverMastraTool;
|
|
32
|
+
discoveredNames;
|
|
33
|
+
mastraToolCache;
|
|
34
|
+
explicitTools = {};
|
|
35
|
+
constructor(sdkBuilder, sdkPrepareStep, discoverMastraTool, discoveredNames, mastraToolCache) {
|
|
36
|
+
this.sdkBuilder = sdkBuilder;
|
|
37
|
+
this.sdkPrepareStep = sdkPrepareStep;
|
|
38
|
+
this.discoverMastraTool = discoverMastraTool;
|
|
39
|
+
this.discoveredNames = discoveredNames;
|
|
40
|
+
this.mastraToolCache = mastraToolCache;
|
|
41
|
+
}
|
|
42
|
+
tools(tools) {
|
|
43
|
+
Object.assign(this.explicitTools, tools);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
messages(opts) {
|
|
47
|
+
this.sdkBuilder.messages(opts);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
recall(opts) {
|
|
51
|
+
this.sdkBuilder.recall(opts);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
async assemble() {
|
|
55
|
+
const sdkCtx = await this.sdkBuilder.assemble();
|
|
56
|
+
const resolvedTools = { ...this.explicitTools };
|
|
57
|
+
for (const name of this.discoveredNames) {
|
|
58
|
+
if (!resolvedTools[name] && this.mastraToolCache[name]) {
|
|
59
|
+
resolvedTools[name] = this.mastraToolCache[name];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return new MastraAssembledContext(sdkCtx, resolvedTools, this.sdkPrepareStep);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
3
65
|
// --- Factory ---
|
|
4
66
|
export function mastra() {
|
|
5
67
|
return { adapt: (ag) => new MastraAgentified(ag) };
|
|
@@ -14,7 +76,8 @@ export class MastraAgentified {
|
|
|
14
76
|
disconnect() { return this.ag.disconnect(); }
|
|
15
77
|
dataset(name) { return new MastraDatasetRef(this.ag.dataset(name)); }
|
|
16
78
|
async register(input) {
|
|
17
|
-
|
|
79
|
+
const backendTools = extractBackendTools(input.tools);
|
|
80
|
+
return new MastraInstance(await this.ag.register(input), backendTools);
|
|
18
81
|
}
|
|
19
82
|
}
|
|
20
83
|
export class MastraDatasetRef {
|
|
@@ -23,37 +86,64 @@ export class MastraDatasetRef {
|
|
|
23
86
|
this.ref = ref;
|
|
24
87
|
}
|
|
25
88
|
async register(input) {
|
|
26
|
-
|
|
89
|
+
const backendTools = extractBackendTools(input.tools);
|
|
90
|
+
return new MastraInstance(await this.ref.register(input), backendTools);
|
|
27
91
|
}
|
|
28
92
|
}
|
|
29
93
|
export class MastraInstance {
|
|
30
94
|
inst;
|
|
95
|
+
backendTools;
|
|
31
96
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
97
|
discoverTool;
|
|
33
|
-
|
|
98
|
+
mastraToolCache;
|
|
34
99
|
get instanceId() { return this.inst.instanceId; }
|
|
35
100
|
get datasetId() { return this.inst.datasetId; }
|
|
36
|
-
constructor(inst) {
|
|
101
|
+
constructor(inst, backendTools) {
|
|
37
102
|
this.inst = inst;
|
|
103
|
+
this.backendTools = backendTools;
|
|
38
104
|
this.discoverTool = wrapDiscoverTool(inst.discoverTool);
|
|
39
|
-
this.
|
|
105
|
+
this.mastraToolCache = buildMastraToolMap(backendTools);
|
|
40
106
|
}
|
|
41
|
-
|
|
42
|
-
|
|
107
|
+
prepareStep = async (params) => {
|
|
108
|
+
await this.inst.prepareStep(params);
|
|
109
|
+
const tools = { agentified_discover: this.discoverTool };
|
|
110
|
+
for (const name of this.inst.discoverTool.discoveredNames) {
|
|
111
|
+
if (!tools[name] && this.mastraToolCache[name]) {
|
|
112
|
+
tools[name] = this.mastraToolCache[name];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { tools };
|
|
116
|
+
};
|
|
117
|
+
session(id) { return new MastraSession(this.inst.session(id), this.backendTools); }
|
|
118
|
+
namespace(id) { return new MastraNamespace(this.inst.namespace(id), this.backendTools); }
|
|
43
119
|
}
|
|
44
120
|
export class MastraSession {
|
|
45
121
|
sess;
|
|
122
|
+
backendTools;
|
|
46
123
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
124
|
discoverTool;
|
|
48
|
-
|
|
125
|
+
mastraToolCache;
|
|
49
126
|
get id() { return this.sess.id; }
|
|
50
|
-
get context() { return this.sess.context; }
|
|
51
127
|
get conversation() { return this.sess.conversation; }
|
|
52
|
-
constructor(sess) {
|
|
128
|
+
constructor(sess, backendTools) {
|
|
53
129
|
this.sess = sess;
|
|
130
|
+
this.backendTools = backendTools;
|
|
54
131
|
this.discoverTool = wrapDiscoverTool(sess.discoverTool);
|
|
55
|
-
this.
|
|
132
|
+
this.mastraToolCache = buildMastraToolMap(backendTools);
|
|
133
|
+
}
|
|
134
|
+
get context() {
|
|
135
|
+
return new MastraContextBuilder(this.sess.context, this.sess.prepareStep, this.discoverTool, this.sess.discoverTool.discoveredNames, this.mastraToolCache);
|
|
56
136
|
}
|
|
137
|
+
prepareStep = async (params) => {
|
|
138
|
+
await this.sess.prepareStep(params);
|
|
139
|
+
const tools = { agentified_discover: this.discoverTool };
|
|
140
|
+
for (const name of this.sess.discoverTool.discoveredNames) {
|
|
141
|
+
if (!tools[name] && this.mastraToolCache[name]) {
|
|
142
|
+
tools[name] = this.mastraToolCache[name];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return { tools };
|
|
146
|
+
};
|
|
57
147
|
getMessages(opts) { return this.sess.getMessages(opts); }
|
|
58
148
|
updateConversation(input) {
|
|
59
149
|
return this.sess.updateConversation(input);
|
|
@@ -61,13 +151,18 @@ export class MastraSession {
|
|
|
61
151
|
}
|
|
62
152
|
export class MastraNamespace {
|
|
63
153
|
ns;
|
|
64
|
-
|
|
154
|
+
backendTools;
|
|
155
|
+
constructor(ns, backendTools) {
|
|
65
156
|
this.ns = ns;
|
|
157
|
+
this.backendTools = backendTools;
|
|
66
158
|
}
|
|
67
159
|
get id() { return this.ns.id; }
|
|
68
|
-
session(id) { return new MastraSession(this.ns.session(id)); }
|
|
160
|
+
session(id) { return new MastraSession(this.ns.session(id), this.backendTools); }
|
|
161
|
+
}
|
|
162
|
+
// --- Helpers ---
|
|
163
|
+
function extractBackendTools(tools) {
|
|
164
|
+
return tools.filter((t) => !("type" in t) || t.type === "backend");
|
|
69
165
|
}
|
|
70
|
-
// --- Converter ---
|
|
71
166
|
function wrapDiscoverTool(dt) {
|
|
72
167
|
return createTool({
|
|
73
168
|
id: dt.definition.name,
|
|
@@ -76,4 +171,16 @@ function wrapDiscoverTool(dt) {
|
|
|
76
171
|
execute: async (input) => dt.execute(input),
|
|
77
172
|
});
|
|
78
173
|
}
|
|
174
|
+
function buildMastraToolMap(backendTools) {
|
|
175
|
+
const tools = {};
|
|
176
|
+
for (const t of backendTools) {
|
|
177
|
+
tools[t.name] = createTool({
|
|
178
|
+
id: t.name,
|
|
179
|
+
description: t.description,
|
|
180
|
+
inputSchema: jsonSchemaToZod(t.parameters),
|
|
181
|
+
execute: async (inputData) => t.handler(inputData),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return tools;
|
|
185
|
+
}
|
|
79
186
|
//# sourceMappingURL=agentified.js.map
|
package/dist/agentified.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentified.js","sourceRoot":"","sources":["../src/agentified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"agentified.js","sourceRoot":"","sources":["../src/agentified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAM9C,iCAAiC;AAEjC,MAAM,OAAO,sBAAsB;IAEd;IACR;IACQ;IAHnB,YACmB,MAAwB,EAChC,KAAiC,EACzB,cAAsC;QAFtC,WAAM,GAAN,MAAM,CAAkB;QAChC,UAAK,GAAL,KAAK,CAA4B;QACzB,mBAAc,GAAd,cAAc,CAAwB;IACtD,CAAC;IAEJ,IAAI,QAAQ,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/C,IAAI,QAAQ,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/C,IAAI,YAAY,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IACvD,IAAI,QAAQ,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/C,IAAI,aAAa,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;IACzD,IAAI,oBAAoB,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACvE,IAAI,aAAa,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CA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AU,CAAC,IAAI;QACtB,WAAW,EAAE,EAAE,CAAC,UAAU,CAAC,WAAW;QACtC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC1E,OAAO,EAAE,KAAK,EAAE,KAAwC,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;KAC/E,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,YAA2B;IACrD,MAAM,KAAK,GAA+B,EAAE,CAAC;IAC7C,KAAK,MAAM,CAAC,IAAI,YAAY,EAAE,CAAC;QAC7B,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC;YACzB,EAAE,EAAE,CAAC,CAAC,IAAI;YACV,WAAW,EAAE,CAAC,CAAC,WAAW;YAC1B,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC;YAC1C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,SAAoC,CAAC;SAC9E,CAAe,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { mastra, MastraAgentified, MastraInstance, MastraSession, MastraNamespace, MastraDatasetRef } from "./agentified.js";
|
|
1
|
+
export { mastra, MastraAgentified, MastraInstance, MastraSession, MastraNamespace, MastraDatasetRef, MastraContextBuilder, MastraAssembledContext } from "./agentified.js";
|
|
2
2
|
export { streamSSE } from "./stream-sse.js";
|
|
3
3
|
export { jsonSchemaToZod } from "./schema.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC3K,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { mastra, MastraAgentified, MastraInstance, MastraSession, MastraNamespace, MastraDatasetRef } from "./agentified.js";
|
|
1
|
+
export { mastra, MastraAgentified, MastraInstance, MastraSession, MastraNamespace, MastraDatasetRef, MastraContextBuilder, MastraAssembledContext } from "./agentified.js";
|
|
2
2
|
export { streamSSE } from "./stream-sse.js";
|
|
3
3
|
export { jsonSchemaToZod } from "./schema.js";
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC3K,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentified/mastra",
|
|
3
|
-
"version": "0.0.5-beta.
|
|
3
|
+
"version": "0.0.5-beta.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@ag-ui/mastra": ">=1.0.0",
|
|
28
28
|
"@mastra/core": ">=1.0.0",
|
|
29
29
|
"zod": ">=3.0.0",
|
|
30
|
-
"agentified": "0.0.5-beta.
|
|
30
|
+
"agentified": "0.0.5-beta.7"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"rxjs": "^7.8.0"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"typescript": "^5.9.0",
|
|
41
41
|
"vitest": "^2.1.0",
|
|
42
42
|
"zod": "^3.25.0",
|
|
43
|
-
"agentified": "0.0.5-beta.
|
|
43
|
+
"agentified": "0.0.5-beta.7"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsc -p tsconfig.build.json",
|
package/dist/adapter.d.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { BaseEvent } from "@ag-ui/client";
|
|
2
|
-
import type { RegisterResponse, ServerTool } from "agentified";
|
|
3
|
-
import { Observable } from "rxjs";
|
|
4
|
-
export interface GenerateOptions {
|
|
5
|
-
messages: Array<{
|
|
6
|
-
role: string;
|
|
7
|
-
content: string;
|
|
8
|
-
}>;
|
|
9
|
-
maxSteps?: number;
|
|
10
|
-
turnId?: string;
|
|
11
|
-
toolLimit?: number;
|
|
12
|
-
seed?: number;
|
|
13
|
-
debug?: boolean;
|
|
14
|
-
onStepFinish?: (event: {
|
|
15
|
-
usage: any;
|
|
16
|
-
toolCalls: any[];
|
|
17
|
-
}) => void;
|
|
18
|
-
}
|
|
19
|
-
export interface DebugEntry {
|
|
20
|
-
phase: string;
|
|
21
|
-
detail: Record<string, unknown>;
|
|
22
|
-
}
|
|
23
|
-
export interface GenerateResult {
|
|
24
|
-
text: string;
|
|
25
|
-
toolCalls: Array<{
|
|
26
|
-
toolName: string;
|
|
27
|
-
toolCallId: string;
|
|
28
|
-
args: Record<string, unknown>;
|
|
29
|
-
}>;
|
|
30
|
-
steps: any[];
|
|
31
|
-
usage: {
|
|
32
|
-
inputTokens: number;
|
|
33
|
-
outputTokens: number;
|
|
34
|
-
totalTokens: number;
|
|
35
|
-
cachedInputTokens?: number;
|
|
36
|
-
reasoningTokens?: number;
|
|
37
|
-
};
|
|
38
|
-
hydratedTools: string[];
|
|
39
|
-
turnId?: string;
|
|
40
|
-
durationMs: number;
|
|
41
|
-
debugLog?: DebugEntry[];
|
|
42
|
-
}
|
|
43
|
-
export interface AgentifiedMastraConfig {
|
|
44
|
-
agentifiedUrl: string;
|
|
45
|
-
tools: ServerTool[];
|
|
46
|
-
toolHandlers: Record<string, (args: Record<string, unknown>) => Promise<unknown>>;
|
|
47
|
-
agent: {
|
|
48
|
-
name: string;
|
|
49
|
-
generate: (...args: any[]) => any;
|
|
50
|
-
stream: (...args: any[]) => any;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export interface RunOptions {
|
|
54
|
-
messages: Array<{
|
|
55
|
-
role: string;
|
|
56
|
-
content: string;
|
|
57
|
-
toolCallId?: string;
|
|
58
|
-
toolCalls?: Array<{
|
|
59
|
-
id: string;
|
|
60
|
-
type: "function";
|
|
61
|
-
function: {
|
|
62
|
-
name: string;
|
|
63
|
-
arguments: string;
|
|
64
|
-
};
|
|
65
|
-
}>;
|
|
66
|
-
}>;
|
|
67
|
-
frontendTools?: string[];
|
|
68
|
-
}
|
|
69
|
-
/** @deprecated Use the new `Agentified` class instead. This class will be removed in a future version. */
|
|
70
|
-
export declare class AgentifiedMastra {
|
|
71
|
-
private config;
|
|
72
|
-
private sdk;
|
|
73
|
-
private datasetId;
|
|
74
|
-
private lastPrefetchResult;
|
|
75
|
-
constructor(config: AgentifiedMastraConfig);
|
|
76
|
-
/**
|
|
77
|
-
* WORKAROUND: @ag-ui/mastra strips providerOptions during message conversion,
|
|
78
|
-
* losing Gemini 3's required thoughtSignature on function call parts.
|
|
79
|
-
* We wrap agent.stream() to inject a dummy signature so Gemini 3 doesn't 400.
|
|
80
|
-
*
|
|
81
|
-
* Tracked: https://github.com/ag-ui-protocol/ag-ui/issues/TBD
|
|
82
|
-
* Remove when: ag-ui preserves providerOptions in convertAGUIMessagesToMastra()
|
|
83
|
-
*/
|
|
84
|
-
private patchAgentStreamForGemini;
|
|
85
|
-
private static hasToolResults;
|
|
86
|
-
register(): Promise<RegisterResponse>;
|
|
87
|
-
private ensureDataset;
|
|
88
|
-
generate(options: GenerateOptions): Promise<GenerateResult>;
|
|
89
|
-
run(options: RunOptions): Promise<Observable<BaseEvent>>;
|
|
90
|
-
private buildAllMastraTools;
|
|
91
|
-
private buildMastraTools;
|
|
92
|
-
private createDiscoverMastraTool;
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=adapter.d.ts.map
|
package/dist/adapter.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,eAAe,CAAC;AAIrE,OAAO,KAAK,EAGV,gBAAgB,EAChB,UAAU,EACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAC;AAI3C,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC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AgB;IAMxB,OAAO,CAAC,wBAAwB;CAqCjC"}
|
package/dist/adapter.js
DELETED
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
import { createTool } from "@mastra/core/tools";
|
|
2
|
-
import { MastraAgent } from "@ag-ui/mastra";
|
|
3
|
-
import { ApiClient } from "agentified";
|
|
4
|
-
import { Observable, Subject } from "rxjs";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
import { jsonSchemaToZod } from "./schema.js";
|
|
7
|
-
/** @deprecated Use the new `Agentified` class instead. This class will be removed in a future version. */
|
|
8
|
-
export class AgentifiedMastra {
|
|
9
|
-
config;
|
|
10
|
-
sdk;
|
|
11
|
-
datasetId = null;
|
|
12
|
-
lastPrefetchResult = null;
|
|
13
|
-
constructor(config) {
|
|
14
|
-
this.config = config;
|
|
15
|
-
this.sdk = new ApiClient({
|
|
16
|
-
serverUrl: config.agentifiedUrl,
|
|
17
|
-
tools: config.tools,
|
|
18
|
-
});
|
|
19
|
-
this.patchAgentStreamForGemini();
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* WORKAROUND: @ag-ui/mastra strips providerOptions during message conversion,
|
|
23
|
-
* losing Gemini 3's required thoughtSignature on function call parts.
|
|
24
|
-
* We wrap agent.stream() to inject a dummy signature so Gemini 3 doesn't 400.
|
|
25
|
-
*
|
|
26
|
-
* Tracked: https://github.com/ag-ui-protocol/ag-ui/issues/TBD
|
|
27
|
-
* Remove when: ag-ui preserves providerOptions in convertAGUIMessagesToMastra()
|
|
28
|
-
*/
|
|
29
|
-
patchAgentStreamForGemini() {
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
-
const agent = this.config.agent;
|
|
32
|
-
const originalStream = agent.stream.bind(agent);
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
agent.stream = async (messages, ...rest) => {
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
const patched = messages.map((m) => {
|
|
37
|
-
if (m.role === "assistant" &&
|
|
38
|
-
Array.isArray(m.content) &&
|
|
39
|
-
m.content.some((p) => p.type === "tool-call")) {
|
|
40
|
-
return {
|
|
41
|
-
...m,
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
content: m.content.map((part) => {
|
|
44
|
-
if (part.providerOptions?.google?.thoughtSignature)
|
|
45
|
-
return part;
|
|
46
|
-
return {
|
|
47
|
-
...part,
|
|
48
|
-
providerOptions: {
|
|
49
|
-
...part.providerOptions,
|
|
50
|
-
google: {
|
|
51
|
-
...part.providerOptions?.google,
|
|
52
|
-
thoughtSignature: "skip_thought_signature_validator",
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
}),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return m;
|
|
60
|
-
});
|
|
61
|
-
return originalStream(patched, ...rest);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
static hasToolResults(messages) {
|
|
65
|
-
return messages.some((m) => m.role === "tool");
|
|
66
|
-
}
|
|
67
|
-
async register() {
|
|
68
|
-
return this.sdk.register(this.ensureDataset());
|
|
69
|
-
}
|
|
70
|
-
ensureDataset() {
|
|
71
|
-
if (!this.datasetId) {
|
|
72
|
-
this.datasetId = "default";
|
|
73
|
-
}
|
|
74
|
-
return this.datasetId;
|
|
75
|
-
}
|
|
76
|
-
async generate(options) {
|
|
77
|
-
const start = performance.now();
|
|
78
|
-
const debug = options.debug ?? false;
|
|
79
|
-
const debugLog = [];
|
|
80
|
-
const log = (phase, detail) => {
|
|
81
|
-
if (!debug)
|
|
82
|
-
return;
|
|
83
|
-
debugLog.push({ phase, detail });
|
|
84
|
-
console.error(`[agentified] ${phase}:`, JSON.stringify(detail));
|
|
85
|
-
};
|
|
86
|
-
// 1. Prefetch (with turnId for session continuity)
|
|
87
|
-
const dsId = this.ensureDataset();
|
|
88
|
-
const ranked = await this.sdk.prefetch(dsId, {
|
|
89
|
-
messages: options.messages.map(m => ({ role: m.role, content: m.content })),
|
|
90
|
-
turnId: options.turnId,
|
|
91
|
-
...(options.toolLimit !== undefined && { limit: options.toolLimit }),
|
|
92
|
-
}) ?? [];
|
|
93
|
-
const prefilledNames = ranked.map(t => t.name);
|
|
94
|
-
log("prefetch", {
|
|
95
|
-
toolCount: ranked.length,
|
|
96
|
-
tools: ranked.map(t => ({ name: t.name, score: t.score })),
|
|
97
|
-
});
|
|
98
|
-
// 2. Build ALL tools (not just ranked — needed for discover → use)
|
|
99
|
-
const allTools = this.buildAllMastraTools();
|
|
100
|
-
const registryNames = new Set(Object.keys(allTools));
|
|
101
|
-
// 3. Discover tool
|
|
102
|
-
const discoverDef = this.sdk.asDiscoverTool(dsId);
|
|
103
|
-
const discoverTool = createTool({
|
|
104
|
-
id: "agentified_discover",
|
|
105
|
-
description: discoverDef.definition.description,
|
|
106
|
-
inputSchema: z.object({ query: z.string(), limit: z.number().optional() }),
|
|
107
|
-
execute: async (input) => {
|
|
108
|
-
const result = await discoverDef.execute(input);
|
|
109
|
-
log("discover-result", {
|
|
110
|
-
query: input.query,
|
|
111
|
-
tools: Array.isArray(result) ? result.map((t) => t.name) : result,
|
|
112
|
-
});
|
|
113
|
-
return result;
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
// 4. Active tool set — grows as discover returns results
|
|
117
|
-
const activeSet = new Set(prefilledNames);
|
|
118
|
-
activeSet.add("agentified_discover");
|
|
119
|
-
// 5. Inject full tool set into agent
|
|
120
|
-
const fullTools = { ...allTools, agentified_discover: discoverTool };
|
|
121
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
122
|
-
this.config.agent.__setTools(fullTools);
|
|
123
|
-
log("setup", {
|
|
124
|
-
totalToolsRegistered: Object.keys(fullTools).length,
|
|
125
|
-
initialActiveSet: [...activeSet],
|
|
126
|
-
});
|
|
127
|
-
// 6. Call agent.generate() with prepareStep
|
|
128
|
-
const result = await this.config.agent.generate(options.messages, {
|
|
129
|
-
maxSteps: options.maxSteps ?? 10,
|
|
130
|
-
...(options.seed !== undefined && { seed: options.seed }),
|
|
131
|
-
onStepFinish: options.onStepFinish,
|
|
132
|
-
prepareStep: async ({ stepNumber, steps }) => {
|
|
133
|
-
// Merge discovered tools from prior steps (handle AG-UI payload wrapping)
|
|
134
|
-
const prevSize = activeSet.size;
|
|
135
|
-
for (const step of steps) {
|
|
136
|
-
for (const tr of step.toolResults ?? []) {
|
|
137
|
-
const trName = tr.toolName ?? tr.payload?.toolName;
|
|
138
|
-
const trResult = tr.result ?? tr.payload?.result;
|
|
139
|
-
if (trName === "agentified_discover" && Array.isArray(trResult)) {
|
|
140
|
-
for (const t of trResult) {
|
|
141
|
-
if (registryNames.has(t.name))
|
|
142
|
-
activeSet.add(t.name);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
const newTools = activeSet.size > prevSize
|
|
148
|
-
? [...activeSet].filter(n => !prefilledNames.includes(n) && n !== "agentified_discover")
|
|
149
|
-
: [];
|
|
150
|
-
log("prepareStep", {
|
|
151
|
-
stepNumber,
|
|
152
|
-
activeSet: [...activeSet],
|
|
153
|
-
newlyAdded: newTools.length > 0 ? newTools : undefined,
|
|
154
|
-
});
|
|
155
|
-
return { activeTools: [...activeSet] };
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
// 7. Collect tool calls (excluding discover)
|
|
159
|
-
// Mastra wraps tool calls in AG-UI events: { payload: { toolName, toolCallId, args } }
|
|
160
|
-
const toolCalls = [];
|
|
161
|
-
for (const step of result.steps ?? []) {
|
|
162
|
-
for (const _tc of step.toolCalls ?? []) {
|
|
163
|
-
const tc = _tc;
|
|
164
|
-
const name = tc.toolName ?? tc.payload?.toolName;
|
|
165
|
-
const id = tc.toolCallId ?? tc.payload?.toolCallId;
|
|
166
|
-
const args = tc.args ?? tc.payload?.args ?? {};
|
|
167
|
-
if (name === "agentified_discover")
|
|
168
|
-
continue;
|
|
169
|
-
toolCalls.push({ toolName: name, toolCallId: id, args });
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
// 8. Post-process: expand activeSet from result steps
|
|
173
|
-
for (const step of result.steps ?? []) {
|
|
174
|
-
for (const _tr of step.toolResults ?? []) {
|
|
175
|
-
const tr = _tr;
|
|
176
|
-
const trName = tr.toolName ?? tr.payload?.toolName;
|
|
177
|
-
const trResult = tr.result ?? tr.payload?.result;
|
|
178
|
-
if (trName === "agentified_discover" && Array.isArray(trResult)) {
|
|
179
|
-
for (const t of trResult) {
|
|
180
|
-
if (registryNames.has(t.name))
|
|
181
|
-
activeSet.add(t.name);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
// 9. Capture turn for session continuity
|
|
187
|
-
const toolsLoaded = [...activeSet].filter(n => n !== "agentified_discover");
|
|
188
|
-
let turnId;
|
|
189
|
-
try {
|
|
190
|
-
const capture = await this.sdk.captureTurn("default", "default", {
|
|
191
|
-
toolsLoaded,
|
|
192
|
-
message: options.messages[options.messages.length - 1]?.content ?? "",
|
|
193
|
-
});
|
|
194
|
-
turnId = capture.turnId;
|
|
195
|
-
}
|
|
196
|
-
catch { /* non-fatal */ }
|
|
197
|
-
const usage = (result.usage ?? {});
|
|
198
|
-
const inputTokens = usage.inputTokens ?? usage.promptTokens ?? 0;
|
|
199
|
-
const outputTokens = usage.outputTokens ?? usage.completionTokens ?? 0;
|
|
200
|
-
return {
|
|
201
|
-
text: result.text ?? "",
|
|
202
|
-
toolCalls,
|
|
203
|
-
steps: result.steps ?? [],
|
|
204
|
-
usage: {
|
|
205
|
-
inputTokens,
|
|
206
|
-
outputTokens,
|
|
207
|
-
totalTokens: usage.totalTokens ?? (inputTokens + outputTokens),
|
|
208
|
-
cachedInputTokens: usage.cachedInputTokens,
|
|
209
|
-
reasoningTokens: usage.reasoningTokens,
|
|
210
|
-
},
|
|
211
|
-
hydratedTools: toolsLoaded,
|
|
212
|
-
turnId,
|
|
213
|
-
durationMs: performance.now() - start,
|
|
214
|
-
...(debug && { debugLog }),
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
async run(options) {
|
|
218
|
-
const dsId = this.ensureDataset();
|
|
219
|
-
const allFrontendNames = this.sdk.getFrontendToolNames();
|
|
220
|
-
const available = new Set(options.frontendTools ?? []);
|
|
221
|
-
const unavailable = allFrontendNames.filter((n) => !available.has(n));
|
|
222
|
-
let ranked;
|
|
223
|
-
let prefetchDurationMs;
|
|
224
|
-
let prefetchSkipped = false;
|
|
225
|
-
if (this.lastPrefetchResult && AgentifiedMastra.hasToolResults(options.messages)) {
|
|
226
|
-
ranked = this.lastPrefetchResult.ranked;
|
|
227
|
-
prefetchDurationMs = this.lastPrefetchResult.durationMs;
|
|
228
|
-
prefetchSkipped = true;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
const prefetchStart = performance.now();
|
|
232
|
-
ranked = await this.sdk.prefetch(dsId, {
|
|
233
|
-
messages: options.messages.map((m) => ({
|
|
234
|
-
role: m.role,
|
|
235
|
-
content: m.content,
|
|
236
|
-
})),
|
|
237
|
-
exclude: unavailable.length > 0 ? unavailable : undefined,
|
|
238
|
-
});
|
|
239
|
-
prefetchDurationMs = performance.now() - prefetchStart;
|
|
240
|
-
this.lastPrefetchResult = { ranked, durationMs: prefetchDurationMs };
|
|
241
|
-
}
|
|
242
|
-
const subject = new Subject();
|
|
243
|
-
const mastraTools = this.buildMastraTools(ranked);
|
|
244
|
-
const discoverTool = this.createDiscoverMastraTool(subject, dsId);
|
|
245
|
-
const frontendToolDefs = this.sdk
|
|
246
|
-
.getFrontendTools()
|
|
247
|
-
.filter((t) => available.has(t.name))
|
|
248
|
-
.map((t) => ({
|
|
249
|
-
name: t.name,
|
|
250
|
-
description: t.description,
|
|
251
|
-
parameters: t.parameters,
|
|
252
|
-
}));
|
|
253
|
-
const runId = crypto.randomUUID();
|
|
254
|
-
const threadId = crypto.randomUUID();
|
|
255
|
-
return new Observable((subscriber) => {
|
|
256
|
-
// Inject tools synchronously (safe: runs on subscribe, same tick)
|
|
257
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
|
-
this.config.agent.__setTools({ ...mastraTools, agentified_discover: discoverTool });
|
|
259
|
-
const mastraAgent = new MastraAgent({ agent: this.config.agent, resourceId: this.config.agent.name });
|
|
260
|
-
subscriber.next({
|
|
261
|
-
type: "RUN_STARTED",
|
|
262
|
-
runId,
|
|
263
|
-
threadId,
|
|
264
|
-
});
|
|
265
|
-
subscriber.next({
|
|
266
|
-
type: "CUSTOM",
|
|
267
|
-
name: prefetchSkipped ? "agentified:prefetch:skipped" : "agentified:prefetch:complete",
|
|
268
|
-
value: { tools: ranked, durationMs: prefetchDurationMs },
|
|
269
|
-
});
|
|
270
|
-
const agentObs = mastraAgent.run({
|
|
271
|
-
messages: options.messages.map((m) => {
|
|
272
|
-
const msg = {
|
|
273
|
-
id: crypto.randomUUID(),
|
|
274
|
-
role: m.role,
|
|
275
|
-
content: m.content,
|
|
276
|
-
};
|
|
277
|
-
if (m.toolCallId)
|
|
278
|
-
msg.toolCallId = m.toolCallId;
|
|
279
|
-
if (m.toolCalls)
|
|
280
|
-
msg.toolCalls = m.toolCalls;
|
|
281
|
-
return msg;
|
|
282
|
-
}),
|
|
283
|
-
threadId,
|
|
284
|
-
runId,
|
|
285
|
-
tools: frontendToolDefs,
|
|
286
|
-
context: [],
|
|
287
|
-
});
|
|
288
|
-
const agentSub = agentObs.subscribe({
|
|
289
|
-
next: (e) => {
|
|
290
|
-
if (e.type === "RUN_STARTED")
|
|
291
|
-
return;
|
|
292
|
-
subscriber.next(e);
|
|
293
|
-
},
|
|
294
|
-
error: (err) => subscriber.error(err),
|
|
295
|
-
complete: () => subscriber.complete(),
|
|
296
|
-
});
|
|
297
|
-
const subjectSub = subject.subscribe({
|
|
298
|
-
next: (e) => subscriber.next(e),
|
|
299
|
-
});
|
|
300
|
-
return () => {
|
|
301
|
-
agentSub.unsubscribe();
|
|
302
|
-
subjectSub.unsubscribe();
|
|
303
|
-
};
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
307
|
-
buildAllMastraTools() {
|
|
308
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
309
|
-
const tools = {};
|
|
310
|
-
for (const def of this.config.tools) {
|
|
311
|
-
const handler = this.config.toolHandlers[def.name];
|
|
312
|
-
if (!handler)
|
|
313
|
-
continue;
|
|
314
|
-
tools[def.name] = createTool({
|
|
315
|
-
id: def.name,
|
|
316
|
-
description: def.description,
|
|
317
|
-
inputSchema: jsonSchemaToZod(def.parameters),
|
|
318
|
-
execute: async (inputData) => handler(inputData),
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
return tools;
|
|
322
|
-
}
|
|
323
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
324
|
-
buildMastraTools(ranked) {
|
|
325
|
-
const names = new Set(ranked.map((t) => t.name));
|
|
326
|
-
const all = this.buildAllMastraTools();
|
|
327
|
-
return Object.fromEntries(Object.entries(all).filter(([n]) => names.has(n)));
|
|
328
|
-
}
|
|
329
|
-
createDiscoverMastraTool(subject, datasetId) {
|
|
330
|
-
const discoverTool = this.sdk.asDiscoverTool(datasetId);
|
|
331
|
-
return createTool({
|
|
332
|
-
id: discoverTool.definition.name,
|
|
333
|
-
description: discoverTool.definition.description,
|
|
334
|
-
inputSchema: z.object({
|
|
335
|
-
query: z.string(),
|
|
336
|
-
limit: z.number().optional(),
|
|
337
|
-
}),
|
|
338
|
-
execute: async (input) => {
|
|
339
|
-
subject.next({
|
|
340
|
-
type: "CUSTOM",
|
|
341
|
-
name: "agentified:discover:start",
|
|
342
|
-
value: { type: "agentified:discover:start", query: input.query },
|
|
343
|
-
});
|
|
344
|
-
const start = performance.now();
|
|
345
|
-
const tools = await discoverTool.execute(input);
|
|
346
|
-
subject.next({
|
|
347
|
-
type: "CUSTOM",
|
|
348
|
-
name: "agentified:discover:complete",
|
|
349
|
-
value: {
|
|
350
|
-
type: "agentified:discover:complete",
|
|
351
|
-
query: input.query,
|
|
352
|
-
tools,
|
|
353
|
-
durationMs: performance.now() - start,
|
|
354
|
-
},
|
|
355
|
-
});
|
|
356
|
-
return tools;
|
|
357
|
-
},
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
//# sourceMappingURL=adapter.js.map
|
package/dist/adapter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAOvC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA4D9C,0GAA0G;AAC1G,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAyB;IAC/B,GAAG,CAAY;IACf,SAAS,GAAkB,IAAI,CAAC;IAChC,kBAAkB,GAAwD,IAAI,CAAC;IAEvF,YAAY,MAA8B;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,SAAS,CAAC;YACvB,SAAS,EAAE,MAAM,CAAC,aAAa;YAC/B,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC,CAAC;QACH,IAAI,CAAC,yBAAyB,EAAE,CAAC;IACnC,CAAC;IAED;;;;;;;OAOG;IACK,yBAAyB;QAC/B,8DAA8D;QAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAY,CAAC;QACvC,MA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wBAAgB,iBAAiB,IAAI,MAAM,GAAG,IAAI,CAYjD;AAED,wBAAgB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAc9C"}
|
package/dist/spawn-utils.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { createServer } from "node:net";
|
|
3
|
-
const PLATFORM_MAP = {
|
|
4
|
-
darwin: "darwin",
|
|
5
|
-
linux: "linux",
|
|
6
|
-
win32: "win32",
|
|
7
|
-
};
|
|
8
|
-
const ARCH_MAP = {
|
|
9
|
-
arm64: "arm64",
|
|
10
|
-
x64: "x64",
|
|
11
|
-
};
|
|
12
|
-
export function resolveBinaryPath() {
|
|
13
|
-
const platform = PLATFORM_MAP[process.platform];
|
|
14
|
-
const arch = ARCH_MAP[process.arch];
|
|
15
|
-
if (!platform || !arch)
|
|
16
|
-
return null;
|
|
17
|
-
const packageName = `@agentified/core-${platform}-${arch}`;
|
|
18
|
-
try {
|
|
19
|
-
const require = createRequire(import.meta.url);
|
|
20
|
-
return require.resolve(packageName);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export function findFreePort() {
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
const server = createServer();
|
|
29
|
-
server.listen(0, "127.0.0.1", () => {
|
|
30
|
-
const addr = server.address();
|
|
31
|
-
if (addr && typeof addr === "object") {
|
|
32
|
-
const port = addr.port;
|
|
33
|
-
server.close(() => resolve(port));
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
server.close(() => reject(new Error("Failed to get port")));
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
server.on("error", reject);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=spawn-utils.js.map
|
package/dist/spawn-utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spawn-ut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