agentified 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.
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # @agentified/sdk
2
+
3
+ Register 200 tools. Get the 5 that matter.
4
+
5
+ TypeScript SDK for [Agentified](../../../README.md) — register tools, discover relevant ones via [hybrid ranking](../../../docs/concepts/ranking.md), and track [sessions](../../../docs/concepts/session-continuity.md) across turns.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @agentified/sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { ApiClient, tool } from "@agentified/sdk";
17
+
18
+ const agent = new ApiClient({
19
+ serverUrl: "http://localhost:9119",
20
+ tools: [
21
+ tool({ name: "get_weather", description: "Get current weather", parameters: { type: "object", properties: { city: { type: "string" } }, required: ["city"] } }),
22
+ tool({ name: "book_flight", description: "Book a flight", parameters: { type: "object", properties: { from: { type: "string" }, to: { type: "string" } }, required: ["from", "to"] } }),
23
+ ],
24
+ });
25
+
26
+ await agent.register();
27
+
28
+ const ranked = await agent.prefetch({
29
+ messages: [{ role: "user", content: "What's the weather in Rome?" }],
30
+ });
31
+ // → [{ name: "get_weather", score: 0.92, ... }, ...]
32
+ ```
33
+
34
+ ## API Reference
35
+
36
+ ### `tool(definition)`
37
+
38
+ Creates a `ServerTool` with auto-populated `fields` for embedding.
39
+
40
+ ```typescript
41
+ import { tool } from "@agentified/sdk";
42
+
43
+ const t = tool({
44
+ name: "search_docs",
45
+ description: "Search documentation by keyword",
46
+ parameters: { type: "object", properties: { query: { type: "string" } }, required: ["query"] },
47
+ metadata: { category: "search" }, // optional
48
+ });
49
+ ```
50
+
51
+ ### `new ApiClient(config)`
52
+
53
+ ```typescript
54
+ interface ApiClientConfig {
55
+ serverUrl: string;
56
+ tools: ServerTool[];
57
+ onEvent?: (event: AgentifiedEvent) => void;
58
+ }
59
+ ```
60
+
61
+ ### `agent.register()`
62
+
63
+ Registers all tools with the server. Embeddings are computed and cached server-side.
64
+
65
+ ```typescript
66
+ const result = await agent.register();
67
+ // { registered: 10 }
68
+ ```
69
+
70
+ ### `agent.prefetch(options)`
71
+
72
+ Discovers relevant tools for a conversation. Joins all message contents (newline-separated) as the discovery query.
73
+
74
+ ```typescript
75
+ interface PrefetchOptions {
76
+ messages: Message[];
77
+ limit?: number; // default 5
78
+ exclude?: string[];
79
+ turnId?: string; // for session continuity
80
+ }
81
+
82
+ const tools = await agent.prefetch({
83
+ messages: [{ role: "user", content: "Book me a flight to Paris" }],
84
+ limit: 10,
85
+ exclude: ["admin_tool"],
86
+ turnId: "prev-turn-id",
87
+ });
88
+ ```
89
+
90
+ ### `agent.captureTurn(options)`
91
+
92
+ Captures a turn for session continuity. The returned `turnId` can be passed to subsequent `prefetch`/`discover` calls.
93
+
94
+ ```typescript
95
+ const { turnId } = await agent.captureTurn({
96
+ toolsLoaded: ["get_weather", "book_flight"],
97
+ message: "What's the weather in Rome?",
98
+ });
99
+ ```
100
+
101
+ ### `agent.getFrontendTools()`
102
+
103
+ Returns tools with `metadata.location === "frontend"`.
104
+
105
+ ```typescript
106
+ const frontendTools = agent.getFrontendTools();
107
+ ```
108
+
109
+ ### `agent.getFrontendToolNames()`
110
+
111
+ Returns names of frontend tools.
112
+
113
+ ```typescript
114
+ const names = agent.getFrontendToolNames();
115
+ // ["navigate_to_page", "open_modal"]
116
+ ```
117
+
118
+ ### `agent.asDiscoverTool()`
119
+
120
+ Returns a tool definition + execute function for `agentified_discover` — useful for giving the agent a tool that can discover more tools at runtime.
121
+
122
+ ```typescript
123
+ const { definition, execute } = agent.asDiscoverTool();
124
+ // definition: { name: "agentified_discover", description: "...", parameters: { ... } }
125
+ // execute({ query: "...", limit: 5 }) → Promise<RankedTool[]>
126
+ ```
127
+
128
+ ## Events
129
+
130
+ Subscribe to lifecycle events via `onEvent` in the config:
131
+
132
+ ```typescript
133
+ const agent = new ApiClient({
134
+ serverUrl: "http://localhost:9119",
135
+ tools: [...],
136
+ onEvent: (event) => {
137
+ switch (event.type) {
138
+ case "agentified:prefetch:start": // { messages }
139
+ case "agentified:prefetch:complete": // { tools, durationMs, tokenUsage? }
140
+ case "agentified:prefetch:skipped": // { tools, durationMs }
141
+ case "agentified:discover:start": // { query }
142
+ case "agentified:discover:complete": // { query, tools, durationMs, tokenUsage? }
143
+ }
144
+ },
145
+ });
146
+ ```
147
+
148
+ ## Types
149
+
150
+ ```typescript
151
+ interface ServerTool {
152
+ name: string;
153
+ description: string;
154
+ parameters: Record<string, unknown>;
155
+ metadata?: Record<string, unknown>;
156
+ fields?: { name: string; description: string; inputSchema?: string; outputSchema?: string };
157
+ }
158
+
159
+ interface RankedTool extends ServerTool {
160
+ score: number;
161
+ graphExpanded?: boolean;
162
+ }
163
+
164
+ interface Message {
165
+ role: string;
166
+ content: string;
167
+ }
168
+
169
+ interface TokenUsage {
170
+ input: number;
171
+ output: number;
172
+ cached: number;
173
+ reasoning: number;
174
+ }
175
+ ```
176
+
177
+ ## Links
178
+
179
+ - [Root README](../../../README.md)
180
+ - [Documentation](../../../docs/)
181
+ - [Architecture](../../../docs/architecture.md)
182
+ - [agentified-core](../../core/README.md)
183
+ - [Frontend Client](../fe-client/README.md)
184
+ - [React Bindings](../react/README.md)
185
+ - [Mastra Adapter](../mastra/README.md)
186
+ - [Python SDK](../../py-packages/sdk/README.md)
187
+
188
+ ## License
189
+
190
+ [MIT](../../../LICENSE.md#mit-license)
@@ -0,0 +1,17 @@
1
+ import type { ApiClientConfig, AppendMessagesResponse, CaptureTurnOptions, CaptureTurnResponse, ContextOpts, ContextResponse, DiscoverTool, GetMessagesOpts, GetMessagesResponse, Message, PrefetchOptions, RankedTool, RegisterResponse, ServerTool } from "./types.js";
2
+ export declare class ApiClient {
3
+ private config;
4
+ constructor(config: ApiClientConfig);
5
+ register(datasetId: string): Promise<RegisterResponse>;
6
+ discover(datasetId: string, query: string, limit?: number, exclude?: string[], turnId?: string): Promise<RankedTool[]>;
7
+ prefetch(datasetId: string, options: PrefetchOptions): Promise<RankedTool[]>;
8
+ captureTurn(namespace: string, session: string, options: CaptureTurnOptions): Promise<CaptureTurnResponse>;
9
+ appendMessages(dataset: string, namespace: string, session: string, messages: Message[]): Promise<AppendMessagesResponse>;
10
+ getMessages(dataset: string, namespace: string, session: string, opts?: GetMessagesOpts): Promise<GetMessagesResponse>;
11
+ getContext(dataset: string, namespace: string, session: string, opts?: ContextOpts): Promise<ContextResponse>;
12
+ getFrontendTools(): ServerTool[];
13
+ getFrontendToolNames(): string[];
14
+ asDiscoverTool(datasetId: string): DiscoverTool;
15
+ private emit;
16
+ }
17
+ //# sourceMappingURL=agentified.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentified.d.ts","sourceRoot":"","sources":["../src/agentified.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAEf,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,eAAe,EAEf,YAAY,EAEZ,eAAe,EACf,mBAAmB,EACnB,OAAO,EACP,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAkB;gBAEpB,MAAM,EAAE,eAAe;IAI7B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAStD,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAwBtH,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAe5E,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAe1G,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAUzH,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAyBtH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC;IAwCnH,gBAAgB,IAAI,UAAU,EAAE;IAIhC,oBAAoB,IAAI,MAAM,EAAE;IAIhC,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY;IA+B/C,OAAO,CAAC,IAAI;CAGb"}
@@ -0,0 +1,169 @@
1
+ export class ApiClient {
2
+ config;
3
+ constructor(config) {
4
+ this.config = config;
5
+ }
6
+ async register(datasetId) {
7
+ const res = await fetch(`${this.config.serverUrl}/api/v1/datasets/${datasetId}/tools`, {
8
+ method: "POST",
9
+ headers: { "Content-Type": "application/json" },
10
+ body: JSON.stringify({ tools: this.config.tools }),
11
+ });
12
+ return res.json();
13
+ }
14
+ async discover(datasetId, query, limit, exclude, turnId) {
15
+ const body = { query };
16
+ if (limit !== undefined)
17
+ body.limit = limit;
18
+ if (exclude !== undefined)
19
+ body.exclude = exclude;
20
+ if (turnId !== undefined)
21
+ body.turn_id = turnId;
22
+ const res = await fetch(`${this.config.serverUrl}/api/v1/datasets/${datasetId}/discover`, {
23
+ method: "POST",
24
+ headers: { "Content-Type": "application/json" },
25
+ body: JSON.stringify(body),
26
+ });
27
+ const data = (await res.json());
28
+ const tools = data.tools ?? [];
29
+ if (this.config.tools.length > 0) {
30
+ const registered = new Set(this.config.tools.map((t) => t.name));
31
+ for (const tool of tools) {
32
+ if (!registered.has(tool.name)) {
33
+ throw new Error(`Discovered tool '${tool.name}' is not registered in the SDK. Register it before use.`);
34
+ }
35
+ }
36
+ }
37
+ return tools;
38
+ }
39
+ async prefetch(datasetId, options) {
40
+ this.emit({ type: "agentified:prefetch:start", messages: options.messages });
41
+ const start = performance.now();
42
+ const query = options.messages.map((m) => m.content).join("\n");
43
+ const tools = await this.discover(datasetId, query, options.limit, options.exclude, options.turnId);
44
+ this.emit({
45
+ type: "agentified:prefetch:complete",
46
+ tools,
47
+ durationMs: performance.now() - start,
48
+ });
49
+ return tools;
50
+ }
51
+ async captureTurn(namespace, session, options) {
52
+ const res = await fetch(`${this.config.serverUrl}/api/v1/turns`, {
53
+ method: "POST",
54
+ headers: { "Content-Type": "application/json" },
55
+ body: JSON.stringify({
56
+ namespace_id: namespace,
57
+ session_id: session,
58
+ tools_loaded: options.toolsLoaded,
59
+ message: options.message,
60
+ }),
61
+ });
62
+ const data = (await res.json());
63
+ return { turnId: data.turn_id };
64
+ }
65
+ async appendMessages(dataset, namespace, session, messages) {
66
+ const res = await fetch(`${this.config.serverUrl}/api/v1/messages`, {
67
+ method: "POST",
68
+ headers: { "Content-Type": "application/json" },
69
+ body: JSON.stringify({ dataset, namespace, session, messages }),
70
+ });
71
+ const data = (await res.json());
72
+ return { appended: data.appended, firstSeq: data.first_seq, lastSeq: data.last_seq };
73
+ }
74
+ async getMessages(dataset, namespace, session, opts) {
75
+ const params = new URLSearchParams({ dataset, namespace, session });
76
+ if (opts?.limit !== undefined)
77
+ params.set("limit", String(opts.limit));
78
+ if (opts?.afterSeq !== undefined)
79
+ params.set("after_seq", String(opts.afterSeq));
80
+ if (opts?.aroundSeq !== undefined)
81
+ params.set("around_seq", String(opts.aroundSeq));
82
+ const res = await fetch(`${this.config.serverUrl}/api/v1/messages?${params}`, {
83
+ method: "GET",
84
+ });
85
+ const data = (await res.json());
86
+ return {
87
+ messages: data.messages.map((m) => ({
88
+ id: m.id,
89
+ role: m.role,
90
+ content: m.content,
91
+ toolCallId: m.tool_call_id,
92
+ toolCalls: m.tool_calls,
93
+ createdAt: m.created_at,
94
+ seq: m.seq,
95
+ })),
96
+ hasMore: data.has_more,
97
+ maxSeq: data.max_seq,
98
+ };
99
+ }
100
+ async getContext(dataset, namespace, session, opts) {
101
+ const messagesConfig = {};
102
+ if (opts?.strategy !== undefined)
103
+ messagesConfig.strategy = opts.strategy;
104
+ if (opts?.maxTokens !== undefined)
105
+ messagesConfig.max_tokens = opts.maxTokens;
106
+ const res = await fetch(`${this.config.serverUrl}/api/v1/context`, {
107
+ method: "POST",
108
+ headers: { "Content-Type": "application/json" },
109
+ body: JSON.stringify({ dataset, namespace, session, messages: messagesConfig }),
110
+ });
111
+ const data = (await res.json());
112
+ return {
113
+ messages: data.messages.map((m) => ({
114
+ id: m.id,
115
+ role: m.role,
116
+ content: m.content,
117
+ toolCallId: m.tool_call_id,
118
+ toolCalls: m.tool_calls,
119
+ createdAt: m.created_at,
120
+ seq: m.seq,
121
+ })),
122
+ strategyUsed: data.strategy_used,
123
+ totalMessages: data.total_messages,
124
+ includedMessages: data.included_messages,
125
+ recalled: data.recalled,
126
+ tokenEstimate: data.token_estimate,
127
+ conversationMessages: data.conversation_messages,
128
+ fallback: data.fallback,
129
+ };
130
+ }
131
+ getFrontendTools() {
132
+ return this.config.tools.filter((t) => t.metadata?.location === "frontend");
133
+ }
134
+ getFrontendToolNames() {
135
+ return this.getFrontendTools().map((t) => t.name);
136
+ }
137
+ asDiscoverTool(datasetId) {
138
+ return {
139
+ definition: {
140
+ name: "agentified_discover",
141
+ description: "Find tools relevant to the current task. Call this when you need capabilities you don't have.",
142
+ parameters: {
143
+ type: "object",
144
+ properties: {
145
+ query: { type: "string", description: "Natural language description of what you need to do" },
146
+ limit: { type: "number", description: "Max number of tools to return" },
147
+ },
148
+ required: ["query"],
149
+ },
150
+ },
151
+ execute: async (input) => {
152
+ this.emit({ type: "agentified:discover:start", query: input.query });
153
+ const start = performance.now();
154
+ const tools = await this.discover(datasetId, input.query, input.limit);
155
+ this.emit({
156
+ type: "agentified:discover:complete",
157
+ query: input.query,
158
+ tools,
159
+ durationMs: performance.now() - start,
160
+ });
161
+ return tools;
162
+ },
163
+ };
164
+ }
165
+ emit(event) {
166
+ this.config.onEvent?.(event);
167
+ }
168
+ }
169
+ //# sourceMappingURL=agentified.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentified.js","sourceRoot":"","sources":["../src/agentified.ts"],"names":[],"mappings":"AAoBA,MAAM,OAAO,SAAS;IACZ,MAAM,CAAkB;IAEhC,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,SAAiB;QAC9B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,oBAAoB,SAAS,QAAQ,EAAE;YACrF,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;SACnD,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,IAAI,EAA+B,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,SAAiB,EAAE,KAAa,EAAE,KAAc,EAAE,OAAkB,EAAE,MAAe;QAClG,MAAM,IAAI,GAA4B,EAAE,KAAK,EAAE,CAAC;QAChD,IAAI,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAC5C,IAAI,OAAO,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAClD,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,GAAG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AI,CAAC,EAAE,IAAI,EAAE,2BAA2B,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;gBACrE,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;gBAEhC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;gBAEvE,IAAI,CAAC,IAAI,CAAC;oBACR,IAAI,EAAE,8BAA8B;oBACpC,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,KAAK;oBACL,UAAU,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK;iBACtC,CAAC,CAAC;gBACH,OAAO,KAAK,CAAC;YACf,CAAC;SACF,CAAC;IACJ,CAAC;IAEO,IAAI,CAAC,KAAsB;QACjC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;CACF"}
package/dist/index.cjs ADDED
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Agentified: () => Agentified,
24
+ tool: () => tool
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/agentified.ts
29
+ var Agentified = class {
30
+ serverUrl;
31
+ constructor(config) {
32
+ this.serverUrl = config.serverUrl.replace(/\/+$/, "");
33
+ }
34
+ async register(tools) {
35
+ const serverTools = tools.map(toServerTool);
36
+ const res = await fetch(`${this.serverUrl}/api/v1/tools`, {
37
+ method: "POST",
38
+ headers: { "Content-Type": "application/json" },
39
+ body: JSON.stringify({ tools: serverTools })
40
+ });
41
+ if (!res.ok) {
42
+ const body = await res.json();
43
+ throw new Error(body.error ?? `register failed (${res.status})`);
44
+ }
45
+ return res.json();
46
+ }
47
+ async prefetch(options) {
48
+ const lastUserMsg = [...options.messages].reverse().find((m) => m.role === "user");
49
+ if (!lastUserMsg) return { tools: [] };
50
+ return this.discover(lastUserMsg.content, options.topK ?? 10);
51
+ }
52
+ asDiscoverTool(options) {
53
+ const limit = options?.topK ?? 10;
54
+ return {
55
+ name: "discover_tools",
56
+ description: "Discover relevant tools by semantic search. Provide a query string or multiple queries.",
57
+ inputSchema: {
58
+ type: "object",
59
+ properties: {
60
+ query: {
61
+ type: "string",
62
+ description: "A single search query to find relevant tools"
63
+ },
64
+ queries: {
65
+ type: "array",
66
+ items: { type: "string" },
67
+ description: "Multiple search queries to find relevant tools (results merged and deduplicated)"
68
+ }
69
+ }
70
+ },
71
+ execute: async (input) => {
72
+ if (input.queries) {
73
+ const results = await Promise.all(
74
+ input.queries.map((q) => this.discover(q, limit))
75
+ );
76
+ return dedupeByName(results.flatMap((r) => r.tools));
77
+ }
78
+ const { tools } = await this.discover(input.query ?? "", limit);
79
+ return tools;
80
+ }
81
+ };
82
+ }
83
+ async discover(query, limit) {
84
+ const res = await fetch(`${this.serverUrl}/api/v1/discover`, {
85
+ method: "POST",
86
+ headers: { "Content-Type": "application/json" },
87
+ body: JSON.stringify({ query, limit })
88
+ });
89
+ if (!res.ok) {
90
+ const body = await res.json();
91
+ throw new Error(body.error ?? `discover failed (${res.status})`);
92
+ }
93
+ return res.json();
94
+ }
95
+ };
96
+ function dedupeByName(tools) {
97
+ const map = /* @__PURE__ */ new Map();
98
+ for (const t of tools) {
99
+ const existing = map.get(t.name);
100
+ if (!existing || t.score > existing.score) map.set(t.name, t);
101
+ }
102
+ return [...map.values()];
103
+ }
104
+ function toServerTool(def) {
105
+ const fields = {
106
+ name: def.name,
107
+ description: def.description
108
+ };
109
+ if (def.inputSchema) fields.input_schema = JSON.stringify(def.inputSchema);
110
+ if (def.outputSchema) fields.output_schema = JSON.stringify(def.outputSchema);
111
+ const tool2 = {
112
+ name: def.name,
113
+ description: def.description,
114
+ parameters: def.inputSchema ?? {},
115
+ fields
116
+ };
117
+ if (def.metadata) tool2.metadata = def.metadata;
118
+ return tool2;
119
+ }
120
+
121
+ // src/tool.ts
122
+ function tool(definition) {
123
+ return { ...definition };
124
+ }
125
+ // Annotate the CommonJS export names for ESM import in node:
126
+ 0 && (module.exports = {
127
+ Agentified,
128
+ tool
129
+ });
130
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/agentified.ts","../src/tool.ts"],"sourcesContent":["export { Agentified } from \"./agentified.js\";\nexport { tool } from \"./tool.js\";\nexport type {\n AgentifiedConfig,\n DiscoverRequest,\n DiscoverResponse,\n DiscoverTool,\n DiscoverToolInput,\n Message,\n PrefetchOptions,\n RankedTool,\n RegisterRequest,\n RegisterResponse,\n ServerTool,\n ServerToolFields,\n ToolDefinition,\n} from \"./types.js\";\n","import type {\n AgentifiedConfig,\n DiscoverResponse,\n DiscoverTool,\n DiscoverToolInput,\n PrefetchOptions,\n RankedTool,\n ToolDefinition,\n RegisterResponse,\n ServerTool,\n ServerToolFields,\n} from \"./types.js\";\n\nexport class Agentified {\n private serverUrl: string;\n\n constructor(config: AgentifiedConfig) {\n this.serverUrl = config.serverUrl.replace(/\\/+$/, \"\");\n }\n\n async register(tools: ToolDefinition[]): Promise<RegisterResponse> {\n const serverTools = tools.map(toServerTool);\n const res = await fetch(`${this.serverUrl}/api/v1/tools`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ tools: serverTools }),\n });\n if (!res.ok) {\n const body = (await res.json()) as { error?: string };\n throw new Error(body.error ?? `register failed (${res.status})`);\n }\n return res.json() as Promise<RegisterResponse>;\n }\n\n async prefetch(options: PrefetchOptions): Promise<DiscoverResponse> {\n const lastUserMsg = [...options.messages]\n .reverse()\n .find((m) => m.role === \"user\");\n if (!lastUserMsg) return { tools: [] };\n\n return this.discover(lastUserMsg.content, options.topK ?? 10);\n }\n\n asDiscoverTool(options?: { topK?: number }): DiscoverTool {\n const limit = options?.topK ?? 10;\n return {\n name: \"discover_tools\",\n description:\n \"Discover relevant tools by semantic search. Provide a query string or multiple queries.\",\n inputSchema: {\n type: \"object\",\n properties: {\n query: {\n type: \"string\",\n description: \"A single search query to find relevant tools\",\n },\n queries: {\n type: \"array\",\n items: { type: \"string\" },\n description:\n \"Multiple search queries to find relevant tools (results merged and deduplicated)\",\n },\n },\n },\n execute: async (input: DiscoverToolInput): Promise<RankedTool[]> => {\n if (input.queries) {\n const results = await Promise.all(\n input.queries.map((q) => this.discover(q, limit))\n );\n return dedupeByName(results.flatMap((r) => r.tools));\n }\n const { tools } = await this.discover(input.query ?? \"\", limit);\n return tools;\n },\n };\n }\n\n private async discover(\n query: string,\n limit: number\n ): Promise<DiscoverResponse> {\n const res = await fetch(`${this.serverUrl}/api/v1/discover`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ query, limit }),\n });\n if (!res.ok) {\n const body = (await res.json()) as { error?: string };\n throw new Error(body.error ?? `discover failed (${res.status})`);\n }\n return res.json() as Promise<DiscoverResponse>;\n }\n}\n\nfunction dedupeByName(tools: RankedTool[]): RankedTool[] {\n const map = new Map<string, RankedTool>();\n for (const t of tools) {\n const existing = map.get(t.name);\n if (!existing || t.score > existing.score) map.set(t.name, t);\n }\n return [...map.values()];\n}\n\nfunction toServerTool(def: ToolDefinition): ServerTool {\n const fields: ServerToolFields = {\n name: def.name,\n description: def.description,\n };\n if (def.inputSchema) fields.input_schema = JSON.stringify(def.inputSchema);\n if (def.outputSchema) fields.output_schema = JSON.stringify(def.outputSchema);\n\n const tool: ServerTool = {\n name: def.name,\n description: def.description,\n parameters: def.inputSchema ?? {},\n fields,\n };\n if (def.metadata) tool.metadata = def.metadata;\n return tool;\n}\n","import type { ToolDefinition } from \"./types.js\";\n\nexport function tool(definition: ToolDefinition): ToolDefinition {\n return { ...definition };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,IAAM,aAAN,MAAiB;AAAA,EACd;AAAA,EAER,YAAY,QAA0B;AACpC,SAAK,YAAY,OAAO,UAAU,QAAQ,QAAQ,EAAE;AAAA,EACtD;AAAA,EAEA,MAAM,SAAS,OAAoD;AACjE,UAAM,cAAc,MAAM,IAAI,YAAY;AAC1C,UAAM,MAAM,MAAM,MAAM,GAAG,KAAK,SAAS,iBAAiB;AAAA,MACxD,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,EAAE,OAAO,YAAY,CAAC;AAAA,IAC7C,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,OAAQ,MAAM,IAAI,KAAK;AAC7B,YAAM,IAAI,MAAM,KAAK,SAAS,oBAAoB,IAAI,MAAM,GAAG;AAAA,IACjE;AACA,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA,EAEA,MAAM,SAAS,SAAqD;AAClE,UAAM,cAAc,CAAC,GAAG,QAAQ,QAAQ,EACrC,QAAQ,EACR,KAAK,CAAC,MAAM,EAAE,SAAS,MAAM;AAChC,QAAI,CAAC,YAAa,QAAO,EAAE,OAAO,CAAC,EAAE;AAErC,WAAO,KAAK,SAAS,YAAY,SAAS,QAAQ,QAAQ,EAA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I,EAAE,IAAI;AAC/B,QAAI,CAAC,YAAY,EAAE,QAAQ,SAAS,MAAO,KAAI,IAAI,EAAE,MAAM,CAAC;AAAA,EAC9D;AACA,SAAO,CAAC,GAAG,IAAI,OAAO,CAAC;AACzB;AAEA,SAAS,aAAa,KAAiC;AACrD,QAAM,SAA2B;AAAA,IAC/B,MAAM,IAAI;AAAA,IACV,aAAa,IAAI;AAAA,EACnB;AACA,MAAI,IAAI,YAAa,QAAO,eAAe,KAAK,UAAU,IAAI,WAAW;AACzE,MAAI,IAAI,aAAc,QAAO,gBAAgB,KAAK,UAAU,IAAI,YAAY;AAE5E,QAAMA,QAAmB;AAAA,IACvB,MAAM,IAAI;AAAA,IACV,aAAa,IAAI;AAAA,IACjB,YAAY,IAAI,eAAe,CAAC;AAAA,IAChC;AAAA,EACF;AACA,MAAI,IAAI,SAAU,CAAAA,MAAK,WAAW,IAAI;AACtC,SAAOA;AACT;;;ACrHO,SAAS,KAAK,YAA4C;AAC/D,SAAO,EAAE,GAAG,WAAW;AACzB;","names":["tool"]}
@@ -0,0 +1,72 @@
1
+ interface ToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema?: Record<string, unknown>;
5
+ outputSchema?: Record<string, unknown>;
6
+ metadata?: Record<string, unknown>;
7
+ }
8
+ interface ServerToolFields {
9
+ name: string;
10
+ description: string;
11
+ input_schema?: string;
12
+ output_schema?: string;
13
+ }
14
+ interface ServerTool {
15
+ name: string;
16
+ description: string;
17
+ parameters: Record<string, unknown>;
18
+ metadata?: Record<string, unknown>;
19
+ fields?: ServerToolFields;
20
+ }
21
+ interface RegisterRequest {
22
+ tools: ServerTool[];
23
+ }
24
+ interface RegisterResponse {
25
+ registered: number;
26
+ }
27
+ interface DiscoverRequest {
28
+ query: string;
29
+ limit?: number;
30
+ }
31
+ interface RankedTool extends ServerTool {
32
+ score: number;
33
+ }
34
+ interface DiscoverResponse {
35
+ tools: RankedTool[];
36
+ }
37
+ interface AgentifiedConfig {
38
+ serverUrl: string;
39
+ }
40
+ interface Message {
41
+ role: string;
42
+ content: string;
43
+ }
44
+ interface PrefetchOptions {
45
+ messages: Message[];
46
+ topK?: number;
47
+ }
48
+ interface DiscoverToolInput {
49
+ query?: string;
50
+ queries?: string[];
51
+ }
52
+ interface DiscoverTool {
53
+ name: string;
54
+ description: string;
55
+ inputSchema: Record<string, unknown>;
56
+ execute: (input: DiscoverToolInput) => Promise<RankedTool[]>;
57
+ }
58
+
59
+ declare class Agentified {
60
+ private serverUrl;
61
+ constructor(config: AgentifiedConfig);
62
+ register(tools: ToolDefinition[]): Promise<RegisterResponse>;
63
+ prefetch(options: PrefetchOptions): Promise<DiscoverResponse>;
64
+ asDiscoverTool(options?: {
65
+ topK?: number;
66
+ }): DiscoverTool;
67
+ private discover;
68
+ }
69
+
70
+ declare function tool(definition: ToolDefinition): ToolDefinition;
71
+
72
+ export { Agentified, type AgentifiedConfig, type DiscoverRequest, type DiscoverResponse, type DiscoverTool, type DiscoverToolInput, type Message, type PrefetchOptions, type RankedTool, type RegisterRequest, type RegisterResponse, type ServerTool, type ServerToolFields, type ToolDefinition, tool };
@@ -0,0 +1,6 @@
1
+ export { ApiClient } from "./agentified.js";
2
+ /** @deprecated Use ApiClient instead */
3
+ export { ApiClient as Agentified } from "./agentified.js";
4
+ export { tool } from "./tool.js";
5
+ export type { ApiClientConfig, AgentifiedEvent, AppendMessagesResponse, CaptureTurnOptions, CaptureTurnResponse, ContextOpts, ContextResponse, DiscoverResponse, DiscoverTool, DiscoverToolInput, GetMessagesOpts, GetMessagesResponse, Message, PrefetchOptions, RankedTool, RegisterRequest, RegisterResponse, ServerTool, ServerToolFields, StoredMessage, TokenUsage, ToolDefinition, } from "./types.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,wCAAwC;AACxC,OAAO,EAAE,SAAS,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EACV,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,OAAO,EACP,eAAe,EACf,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,cAAc,GACf,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { ApiClient } from "./agentified.js";
2
+ /** @deprecated Use ApiClient instead */
3
+ export { ApiClient as Agentified } from "./agentified.js";
4
+ export { tool } from "./tool.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,wCAAwC;AACxC,OAAO,EAAE,SAAS,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
package/dist/tool.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { ServerTool, ToolDefinition } from "./types.js";
2
+ export declare function tool(def: ToolDefinition): ServerTool;
3
+ //# sourceMappingURL=tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE7D,wBAAgB,IAAI,CAAC,GAAG,EAAE,cAAc,GAAG,UAAU,CAYpD"}
package/dist/tool.js ADDED
@@ -0,0 +1,14 @@
1
+ export function tool(def) {
2
+ return {
3
+ name: def.name,
4
+ description: def.description,
5
+ parameters: def.parameters,
6
+ ...(def.metadata && { metadata: def.metadata }),
7
+ fields: {
8
+ name: def.name,
9
+ description: def.description,
10
+ inputSchema: JSON.stringify(def.parameters),
11
+ },
12
+ };
13
+ }
14
+ //# sourceMappingURL=tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI,CAAC,GAAmB;IACtC,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,GAAG,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC/C,MAAM,EAAE;YACN,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC;SAC5C;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,132 @@
1
+ export interface ServerToolFields {
2
+ name: string;
3
+ description: string;
4
+ inputSchema?: string;
5
+ outputSchema?: string;
6
+ }
7
+ export interface ServerTool {
8
+ name: string;
9
+ description: string;
10
+ parameters: Record<string, unknown>;
11
+ metadata?: Record<string, unknown>;
12
+ fields?: ServerToolFields;
13
+ }
14
+ export interface RankedTool extends ServerTool {
15
+ score: number;
16
+ graphExpanded?: boolean;
17
+ }
18
+ export interface ToolDefinition {
19
+ name: string;
20
+ description: string;
21
+ parameters: Record<string, unknown>;
22
+ metadata?: Record<string, unknown>;
23
+ }
24
+ export interface RegisterRequest {
25
+ tools: ServerTool[];
26
+ }
27
+ export interface RegisterResponse {
28
+ registered: number;
29
+ }
30
+ export interface DiscoverResponse {
31
+ tools: RankedTool[];
32
+ }
33
+ export interface Message {
34
+ role: string;
35
+ content: string;
36
+ }
37
+ export interface PrefetchOptions {
38
+ messages: Message[];
39
+ limit?: number;
40
+ exclude?: string[];
41
+ turnId?: string;
42
+ }
43
+ export interface CaptureTurnOptions {
44
+ toolsLoaded: string[];
45
+ message: string;
46
+ }
47
+ export interface CaptureTurnResponse {
48
+ turnId: string;
49
+ }
50
+ export interface DiscoverToolInput {
51
+ query: string;
52
+ limit?: number;
53
+ }
54
+ export interface DiscoverTool {
55
+ definition: ToolDefinition;
56
+ execute: (input: DiscoverToolInput) => Promise<RankedTool[]>;
57
+ }
58
+ export interface StoredMessage {
59
+ id: string;
60
+ role: string;
61
+ content: string;
62
+ toolCallId?: string;
63
+ toolCalls?: unknown;
64
+ createdAt: string;
65
+ seq: number;
66
+ }
67
+ export interface AppendMessagesResponse {
68
+ appended: number;
69
+ firstSeq: number;
70
+ lastSeq: number;
71
+ }
72
+ export interface GetMessagesOpts {
73
+ limit?: number;
74
+ afterSeq?: number;
75
+ aroundSeq?: number;
76
+ }
77
+ export interface GetMessagesResponse {
78
+ messages: StoredMessage[];
79
+ hasMore: boolean;
80
+ maxSeq: number;
81
+ }
82
+ export interface ContextOpts {
83
+ strategy?: string;
84
+ maxTokens?: number;
85
+ }
86
+ export interface ContextResponse {
87
+ messages: StoredMessage[];
88
+ strategyUsed: string;
89
+ totalMessages: number;
90
+ includedMessages: number;
91
+ recalled: {
92
+ tools: unknown[];
93
+ memories: unknown[];
94
+ };
95
+ tokenEstimate: number;
96
+ conversationMessages: number;
97
+ fallback: boolean;
98
+ }
99
+ export interface TokenUsage {
100
+ input: number;
101
+ output: number;
102
+ cached: number;
103
+ reasoning: number;
104
+ }
105
+ export type AgentifiedEvent = {
106
+ type: "agentified:prefetch:start";
107
+ messages: Message[];
108
+ } | {
109
+ type: "agentified:prefetch:complete";
110
+ tools: RankedTool[];
111
+ durationMs: number;
112
+ tokenUsage?: TokenUsage;
113
+ } | {
114
+ type: "agentified:prefetch:skipped";
115
+ tools: RankedTool[];
116
+ durationMs: number;
117
+ } | {
118
+ type: "agentified:discover:start";
119
+ query: string;
120
+ } | {
121
+ type: "agentified:discover:complete";
122
+ query: string;
123
+ tools: RankedTool[];
124
+ durationMs: number;
125
+ tokenUsage?: TokenUsage;
126
+ };
127
+ export interface ApiClientConfig {
128
+ serverUrl: string;
129
+ tools: ServerTool[];
130
+ onEvent?: (event: AgentifiedEvent) => void;
131
+ }
132
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAED,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAID,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB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GACpD;IACE,IAAI,EAAE,8BAA8B,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,CAAC;AAIN,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;CAC5C"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ // Server types (mirror Rust models)
2
+ export {};
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oCAAoC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "agentified",
3
+ "version": "0.0.4",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/agentified/agentified",
17
+ "directory": "src/ts-packages/sdk"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.build.json",
27
+ "test": "vitest run",
28
+ "test:e2e": "AGENTIFIED_TEST_URL=http://localhost:9119 vitest run src/__tests__/integration.test.ts"
29
+ },
30
+ "devDependencies": {
31
+ "typescript": "^5.9.0",
32
+ "vitest": "^2.1.0"
33
+ }
34
+ }