@mastra/core 0.1.27-unstable.1 → 0.2.0-alpha.100
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 +176 -4
- package/dist/agent/index.d.ts +16 -60
- package/dist/agent/index.js +7 -0
- package/dist/base.d.ts +46 -0
- package/dist/base.js +3 -0
- package/dist/bundler/index.d.ts +29 -0
- package/dist/bundler/index.js +4 -0
- package/dist/chunk-42DYOLDV.js +96 -0
- package/dist/chunk-4LJFWC2Q.js +216 -0
- package/dist/chunk-4ZUSEHLH.js +285 -0
- package/dist/chunk-AE3H2QEY.js +1 -0
- package/dist/chunk-AJJZUHB4.js +14 -0
- package/dist/chunk-ANDRINSL.js +285 -0
- package/dist/chunk-C55JWGDU.js +76 -0
- package/dist/chunk-G4MCO7XF.js +70 -0
- package/dist/chunk-HBTQNIAX.js +90 -0
- package/dist/chunk-HPXWJBQK.js +222 -0
- package/dist/chunk-ICMEXHKD.js +149 -0
- package/dist/chunk-JJ57BXQR.js +16 -0
- package/dist/chunk-JP37ODNX.js +36 -0
- package/dist/chunk-K3N7KJHH.js +52 -0
- package/dist/chunk-KNPBNSJ7.js +145 -0
- package/dist/chunk-MCB4M5W4.js +28 -0
- package/dist/chunk-MDM2JS2U.js +1288 -0
- package/dist/chunk-MG3WAQV7.js +69 -0
- package/dist/chunk-QXH6EK72.js +1198 -0
- package/dist/chunk-VOUPGVRD.js +27 -0
- package/dist/chunk-Z7JFMQZZ.js +551 -0
- package/dist/chunk-ZJOMHCWE.js +673 -0
- package/dist/deployer/index.d.ts +21 -0
- package/dist/deployer/index.js +5 -0
- package/dist/eval/index.d.ts +32 -0
- package/dist/eval/index.js +3 -0
- package/dist/filter/index.d.ts +90 -0
- package/dist/filter/index.js +2 -0
- package/dist/hooks/index.d.ts +38 -0
- package/dist/hooks/index.js +2 -0
- package/dist/index-CBZ2mk2H.d.ts +85 -0
- package/dist/index-Cwb-5AzX.d.ts +816 -0
- package/dist/index.d.ts +105 -11
- package/dist/index.js +157 -5
- package/dist/integration/index.d.ts +42 -4
- package/dist/integration/index.js +3 -0
- package/dist/llm/index.d.ts +16 -101
- package/dist/llm/index.js +1 -0
- package/dist/logger/index.d.ts +3 -60
- package/dist/logger/index.js +2 -0
- package/dist/mastra/index.d.ts +60 -43
- package/dist/mastra/index.js +9 -0
- package/dist/memory/index.d.ts +16 -0
- package/dist/memory/index.js +9 -0
- package/dist/metric-BWeQNZt6.d.ts +9 -0
- package/dist/relevance/index.d.ts +21 -0
- package/dist/relevance/index.js +8 -0
- package/dist/storage/index.d.ts +72 -0
- package/dist/storage/index.js +7 -0
- package/dist/telemetry/index.d.ts +20 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry-oCUM52DG.d.ts +104 -0
- package/dist/tools/index.d.ts +30 -2
- package/dist/tools/index.js +2 -0
- package/dist/tts/index.d.ts +30 -0
- package/dist/tts/index.js +5 -0
- package/dist/utils.d.ts +26 -1
- package/dist/utils.js +2 -0
- package/dist/vector/index.d.ts +20 -4
- package/dist/vector/index.js +4 -0
- package/dist/vector/libsql/index.d.ts +32 -0
- package/dist/vector/libsql/index.js +6 -0
- package/dist/workflow-DTtv7_Eq.d.ts +95 -0
- package/dist/workflows/index.d.ts +32 -3
- package/dist/workflows/index.js +4 -0
- package/package.json +100 -61
- package/dist/core.cjs.development.js +0 -2969
- package/dist/core.cjs.development.js.map +0 -1
- package/dist/core.cjs.production.min.js +0 -2
- package/dist/core.cjs.production.min.js.map +0 -1
- package/dist/core.esm.js +0 -2943
- package/dist/core.esm.js.map +0 -1
- package/dist/engine/index.d.ts +0 -146
- package/dist/engine/schema.d.ts +0 -36
- package/dist/engine/types.d.ts +0 -115
- package/dist/engine/utils.d.ts +0 -27
- package/dist/integration/test-integration.d.ts +0 -12
- package/dist/llm/types.d.ts +0 -174
- package/dist/mastra/types.d.ts +0 -1
- package/dist/sync/index.d.ts +0 -2
- package/dist/sync/types.d.ts +0 -30
- package/dist/tools/types.d.ts +0 -35
- package/dist/workflows/step.d.ts +0 -15
- package/dist/workflows/types.d.ts +0 -129
- package/dist/workflows/utils.d.ts +0 -8
- package/dist/workflows/workflow.d.ts +0 -53
package/README.md
CHANGED
|
@@ -1,8 +1,180 @@
|
|
|
1
1
|
# @mastra/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The core foundation of the Mastra framework, providing essential components and interfaces for building AI-powered applications.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
`@mastra/core` is the foundational package of the Mastra framework, providing:
|
|
14
|
+
|
|
15
|
+
- Core abstractions and interfaces
|
|
16
|
+
- AI agent management and execution
|
|
17
|
+
- Integration with multiple AI providers
|
|
18
|
+
- Workflow orchestration
|
|
19
|
+
- Memory and vector store management
|
|
20
|
+
- Telemetry and logging infrastructure
|
|
21
|
+
- Text-to-speech capabilities
|
|
22
|
+
|
|
23
|
+
For comprehensive documentation, visit our [official documentation](https://mastra.ai/docs).
|
|
24
|
+
|
|
25
|
+
## Core Components
|
|
26
|
+
|
|
27
|
+
### Agents (`/agent`)
|
|
28
|
+
|
|
29
|
+
Agents are autonomous AI entities that can understand instructions, use tools, and complete tasks. They encapsulate LLM interactions and can maintain conversation history, use provided tools, and follow specific behavioral guidelines through instructions.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { openai } from '@ai-sdk/openai';
|
|
33
|
+
import { Agent } from '@mastra/core/agent';
|
|
34
|
+
|
|
35
|
+
const agent = new Agent({
|
|
36
|
+
name: 'my-agent',
|
|
37
|
+
instructions: 'Your task-specific instructions',
|
|
38
|
+
model: openai('gpt-4o-mini'),
|
|
39
|
+
tools: {}, // Optional tools
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
[More agent documentation →](https://mastra.ai/docs/reference/agents/overview)
|
|
44
|
+
|
|
45
|
+
### Embeddings (`/embeddings`)
|
|
46
|
+
|
|
47
|
+
The embeddings module provides a unified interface for converting text into vector representations across multiple AI providers. These vectors are essential for semantic search, similarity comparisons, and other NLP tasks.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { openai } from '@ai-sdk/openai';
|
|
51
|
+
import { embed } from 'ai';
|
|
52
|
+
|
|
53
|
+
const embeddings = await embed({
|
|
54
|
+
model: openai.embedding('text-embedding-3-small'),
|
|
55
|
+
value: 'text to embed',
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Supported providers right now are OpenAI, Cohere, Amazon Bedrock, Google AI, Mistral, and Voyage.
|
|
60
|
+
|
|
61
|
+
[More embeddings documentation →](https://mastra.ai/docs/reference/embeddings/overview)
|
|
62
|
+
|
|
63
|
+
### Evaluations (`/eval`)
|
|
64
|
+
|
|
65
|
+
The evaluation system enables quantitative assessment of AI outputs. Create custom metrics to measure specific aspects of AI performance, from response quality to task completion accuracy.
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { Metric, evaluate } from '@mastra/core';
|
|
69
|
+
|
|
70
|
+
class CustomMetric extends Metric {
|
|
71
|
+
async measure(input: string, output: string): Promise<MetricResult> {
|
|
72
|
+
// Your evaluation logic
|
|
73
|
+
return { score: 0.95 };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
[More evaluations documentation →](https://mastra.ai/docs/reference/eval/overview)
|
|
79
|
+
|
|
80
|
+
### Memory (`/memory`)
|
|
81
|
+
|
|
82
|
+
Memory management provides persistent storage and retrieval of AI interactions. It supports different storage backends and enables context-aware conversations and long-term learning.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { MastraMemory } from '@mastra/core';
|
|
86
|
+
|
|
87
|
+
const memory = new MastraMemory({
|
|
88
|
+
// Memory configuration
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Note:** this is the base `MastraMemory` class. This class in `@mastra/core` is intended to be extended when developing custom agent memory strategies.
|
|
93
|
+
To use a premade memory strategy (recommended), with long and short term memory built in, use `import { Memory } from "@mastra/memory"` instead.
|
|
94
|
+
|
|
95
|
+
[Visit the memory documentation to use Memory in your project →](https://mastra.ai/docs/reference/memory/overview)
|
|
96
|
+
|
|
97
|
+
### Vector Stores (`/vector`)
|
|
98
|
+
|
|
99
|
+
Vector stores provide the infrastructure for storing and querying vector embeddings. They support semantic search, similarity matching, and efficient vector operations across different backend implementations.
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { MastraVector } from '@mastra/core';
|
|
103
|
+
|
|
104
|
+
class CustomVectorStore extends MastraVector {
|
|
105
|
+
// Vector store implementation
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
[More vector stores documentation →](https://mastra.ai/docs/reference/vector/overview)
|
|
110
|
+
|
|
111
|
+
### Workflows (`/workflows`)
|
|
112
|
+
|
|
113
|
+
Workflows orchestrate complex AI tasks by combining multiple actions into a coherent sequence. They handle state management, error recovery, and can include conditional logic and parallel execution.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { Workflow } from '@mastra/core';
|
|
117
|
+
|
|
118
|
+
const workflow = new Workflow({
|
|
119
|
+
name: 'my-workflow',
|
|
120
|
+
steps: [
|
|
121
|
+
// Workflow steps
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
[More workflows documentation →](https://mastra.ai/docs/reference/workflows/overview)
|
|
127
|
+
|
|
128
|
+
### Tools (`/tools`)
|
|
129
|
+
|
|
130
|
+
Tools are functions that agents can use to interact with external systems or perform specific tasks. Each tool has a clear description and schema, making it easy for AI to understand and use them effectively.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { ToolAction } from '@mastra/core';
|
|
134
|
+
|
|
135
|
+
const tool = new ToolAction({
|
|
136
|
+
name: 'tool-name',
|
|
137
|
+
description: 'Tool description',
|
|
138
|
+
execute: async context => {
|
|
139
|
+
// Tool implementation
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
[More tools documentation →](https://mastra.ai/docs/reference/tools/overview)
|
|
145
|
+
|
|
146
|
+
### Logger (`/logger`)
|
|
147
|
+
|
|
148
|
+
The logging system provides structured, leveled logging with multiple transport options. It supports debug information, performance monitoring, and error tracking across your AI applications.
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import { createLogger, LogLevel } from '@mastra/core';
|
|
152
|
+
|
|
153
|
+
const logger = createLogger({
|
|
154
|
+
name: 'MyApp',
|
|
155
|
+
level: LogLevel.INFO,
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
[More logging documentation →](https://mastra.ai/docs/reference/observability/logging)
|
|
160
|
+
|
|
161
|
+
### Telemetry (`/telemetry`)
|
|
162
|
+
|
|
163
|
+
Telemetry provides OpenTelemetry integration for comprehensive monitoring of your AI systems. Track latency, success rates, and system health with distributed tracing and metrics collection.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { Telemetry } from '@mastra/core';
|
|
167
|
+
|
|
168
|
+
const telemetry = Telemetry.init({
|
|
169
|
+
serviceName: 'my-service',
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
[More Telemetry documentation →](https://mastra.ai/docs/reference/observability/telemetry)
|
|
174
|
+
|
|
175
|
+
## Additional Resources
|
|
176
|
+
|
|
177
|
+
- [Getting Started Guide](https://mastra.ai/docs/getting-started/installation)
|
|
178
|
+
- [API Reference](https://mastra.ai/docs/reference)
|
|
179
|
+
- [Examples](https://mastra.ai/docs/examples)
|
|
180
|
+
- [Deployment Guide](https://mastra.ai/docs/deployment/overview)
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,60 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
model: ModelConfig;
|
|
18
|
-
enabledTools?: Partial<Record<TKeys, boolean>>;
|
|
19
|
-
});
|
|
20
|
-
/**
|
|
21
|
-
* Set the concrete tools for the agent
|
|
22
|
-
* @param tools
|
|
23
|
-
*/
|
|
24
|
-
__setTools(tools: Record<TKeys, ToolApi>): void;
|
|
25
|
-
/**
|
|
26
|
-
* Set the logger for the agent
|
|
27
|
-
* @param logger
|
|
28
|
-
*/
|
|
29
|
-
__setLogger(logger: Logger): void;
|
|
30
|
-
text({ messages, onStepFinish, maxSteps, }: {
|
|
31
|
-
messages: UserContent[];
|
|
32
|
-
onStepFinish?: (step: string) => void;
|
|
33
|
-
maxSteps?: number;
|
|
34
|
-
}): Promise<import("ai").GenerateTextResult<{}>>;
|
|
35
|
-
textObject({ messages, structuredOutput, onStepFinish, maxSteps, }: {
|
|
36
|
-
messages: UserContent[];
|
|
37
|
-
structuredOutput: StructuredOutput;
|
|
38
|
-
onStepFinish?: (step: string) => void;
|
|
39
|
-
maxSteps?: number;
|
|
40
|
-
}): Promise<import("ai").GenerateObjectResult<{
|
|
41
|
-
[x: string]: any;
|
|
42
|
-
}>>;
|
|
43
|
-
stream({ messages, onStepFinish, onFinish, maxSteps, }: {
|
|
44
|
-
messages: UserContent[];
|
|
45
|
-
onStepFinish?: (step: string) => void;
|
|
46
|
-
onFinish?: (result: string) => Promise<void> | void;
|
|
47
|
-
maxSteps?: number;
|
|
48
|
-
}): Promise<import("ai").StreamTextResult<{}>>;
|
|
49
|
-
streamObject({ messages, structuredOutput, onStepFinish, onFinish, maxSteps, }: {
|
|
50
|
-
messages: UserContent[];
|
|
51
|
-
structuredOutput: StructuredOutput;
|
|
52
|
-
onStepFinish?: (step: string) => void;
|
|
53
|
-
onFinish?: (result: string) => Promise<void> | void;
|
|
54
|
-
maxSteps?: number;
|
|
55
|
-
}): Promise<import("ai").StreamObjectResult<{
|
|
56
|
-
[x: string]: any;
|
|
57
|
-
}, {
|
|
58
|
-
[x: string]: any;
|
|
59
|
-
}, never>>;
|
|
60
|
-
}
|
|
1
|
+
import 'ai';
|
|
2
|
+
import 'json-schema';
|
|
3
|
+
import 'zod';
|
|
4
|
+
export { A as Agent } from '../index-Cwb-5AzX.js';
|
|
5
|
+
import '../base.js';
|
|
6
|
+
import '../metric-BWeQNZt6.js';
|
|
7
|
+
import '../telemetry-oCUM52DG.js';
|
|
8
|
+
import 'sift';
|
|
9
|
+
import '../index-CBZ2mk2H.js';
|
|
10
|
+
import 'pino';
|
|
11
|
+
import 'stream';
|
|
12
|
+
import '../vector/index.js';
|
|
13
|
+
import '@opentelemetry/api';
|
|
14
|
+
import '@opentelemetry/sdk-node';
|
|
15
|
+
import '@opentelemetry/sdk-trace-base';
|
|
16
|
+
import '../tts/index.js';
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as _opentelemetry_api from '@opentelemetry/api';
|
|
2
|
+
import { R as RegisteredLogger, L as Logger, a as LogLevel } from './index-CBZ2mk2H.js';
|
|
3
|
+
import { T as Telemetry } from './telemetry-oCUM52DG.js';
|
|
4
|
+
import 'pino';
|
|
5
|
+
import 'stream';
|
|
6
|
+
import '@opentelemetry/sdk-node';
|
|
7
|
+
import '@opentelemetry/sdk-trace-base';
|
|
8
|
+
|
|
9
|
+
declare class MastraBase {
|
|
10
|
+
component: RegisteredLogger;
|
|
11
|
+
protected logger: Logger;
|
|
12
|
+
name?: string;
|
|
13
|
+
telemetry?: Telemetry;
|
|
14
|
+
constructor({ component, name }: {
|
|
15
|
+
component?: RegisteredLogger;
|
|
16
|
+
name?: string;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Set the logger for the agent
|
|
20
|
+
* @param logger
|
|
21
|
+
*/
|
|
22
|
+
__setLogger(logger: Logger): void;
|
|
23
|
+
/**
|
|
24
|
+
* Internal logging helper that formats and sends logs to the configured logger
|
|
25
|
+
* @param level - Severity level of the log
|
|
26
|
+
* @param message - Main log message
|
|
27
|
+
* @param opts - Optional object for the log
|
|
28
|
+
*/
|
|
29
|
+
log(level: LogLevel, message: string, opts?: Record<string, any>): void;
|
|
30
|
+
/**
|
|
31
|
+
* Set the telemetry for the
|
|
32
|
+
* @param telemetry
|
|
33
|
+
*/
|
|
34
|
+
__setTelemetry(telemetry: Telemetry): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get the telemetry on the vector
|
|
37
|
+
* @returns telemetry
|
|
38
|
+
*/
|
|
39
|
+
__getTelemetry(): Telemetry | undefined;
|
|
40
|
+
get experimental_telemetry(): {
|
|
41
|
+
tracer: _opentelemetry_api.Tracer;
|
|
42
|
+
isEnabled: boolean;
|
|
43
|
+
} | undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { MastraBase };
|
package/dist/base.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MastraBase } from '../base.js';
|
|
2
|
+
import '@opentelemetry/api';
|
|
3
|
+
import '../index-CBZ2mk2H.js';
|
|
4
|
+
import 'pino';
|
|
5
|
+
import 'stream';
|
|
6
|
+
import '../telemetry-oCUM52DG.js';
|
|
7
|
+
import '@opentelemetry/sdk-node';
|
|
8
|
+
import '@opentelemetry/sdk-trace-base';
|
|
9
|
+
|
|
10
|
+
interface IBundler {
|
|
11
|
+
loadEnvVars(): Promise<Map<string, string>>;
|
|
12
|
+
getEnvFiles(): Promise<string[]>;
|
|
13
|
+
bundle(entryFile: string, outputDirectory: string): Promise<void>;
|
|
14
|
+
prepare(outputDirectory: string): Promise<void>;
|
|
15
|
+
writePackageJson(outputDirectory: string, dependencies: Map<string, string>): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
declare abstract class MastraBundler extends MastraBase implements IBundler {
|
|
18
|
+
constructor({ name, component }: {
|
|
19
|
+
name: string;
|
|
20
|
+
component?: 'BUNDLER' | 'DEPLOYER';
|
|
21
|
+
});
|
|
22
|
+
loadEnvVars(): Promise<Map<string, string>>;
|
|
23
|
+
abstract prepare(outputDirectory: string): Promise<void>;
|
|
24
|
+
abstract writePackageJson(outputDirectory: string, dependencies: Map<string, string>): Promise<void>;
|
|
25
|
+
abstract getEnvFiles(): Promise<string[]>;
|
|
26
|
+
abstract bundle(entryFile: string, outputDirectory: string): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { type IBundler, MastraBundler };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createTool } from './chunk-VOUPGVRD.js';
|
|
2
|
+
import { __name, __publicField } from './chunk-AJJZUHB4.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
// src/integration/integration.ts
|
|
6
|
+
var _Integration = class _Integration {
|
|
7
|
+
constructor() {
|
|
8
|
+
__publicField(this, "name", "Integration");
|
|
9
|
+
__publicField(this, "workflows");
|
|
10
|
+
this.workflows = {};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Workflows
|
|
14
|
+
*/
|
|
15
|
+
registerWorkflow(name, fn) {
|
|
16
|
+
if (this.workflows[name]) {
|
|
17
|
+
throw new Error(`Sync function "${name}" already registered`);
|
|
18
|
+
}
|
|
19
|
+
this.workflows[name] = fn;
|
|
20
|
+
}
|
|
21
|
+
getWorkflows({ serialized }) {
|
|
22
|
+
if (serialized) {
|
|
23
|
+
return Object.entries(this.workflows).reduce((acc, [k, v]) => {
|
|
24
|
+
return {
|
|
25
|
+
...acc,
|
|
26
|
+
[k]: {
|
|
27
|
+
name: v.name
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}, {});
|
|
31
|
+
}
|
|
32
|
+
return this.workflows;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* TOOLS
|
|
36
|
+
*/
|
|
37
|
+
getStaticTools(_params) {
|
|
38
|
+
throw new Error("Method not implemented.");
|
|
39
|
+
}
|
|
40
|
+
async getTools(_params) {
|
|
41
|
+
throw new Error("Method not implemented.");
|
|
42
|
+
}
|
|
43
|
+
async getApiClient() {
|
|
44
|
+
throw new Error("Method not implemented");
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
__name(_Integration, "Integration");
|
|
48
|
+
var Integration = _Integration;
|
|
49
|
+
var _OpenAPIToolset = class _OpenAPIToolset {
|
|
50
|
+
constructor() {
|
|
51
|
+
__publicField(this, "authType", "API_KEY");
|
|
52
|
+
}
|
|
53
|
+
get toolSchemas() {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
get toolDocumentations() {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
get baseClient() {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
async getApiClient() {
|
|
63
|
+
throw new Error("API not implemented");
|
|
64
|
+
}
|
|
65
|
+
_generateIntegrationTools() {
|
|
66
|
+
const { client, ...clientMethods } = this.baseClient;
|
|
67
|
+
const schemas = this.toolSchemas;
|
|
68
|
+
const documentations = this.toolDocumentations;
|
|
69
|
+
const tools = Object.keys(clientMethods).reduce((acc, key) => {
|
|
70
|
+
const comment = documentations[key]?.comment;
|
|
71
|
+
const fallbackComment = `Execute ${key}`;
|
|
72
|
+
const tool = createTool({
|
|
73
|
+
id: key,
|
|
74
|
+
inputSchema: schemas[key] || z.object({}),
|
|
75
|
+
description: comment || fallbackComment,
|
|
76
|
+
// documentation: doc || fallbackComment,
|
|
77
|
+
execute: /* @__PURE__ */ __name(async ({ context }) => {
|
|
78
|
+
const client2 = await this.getApiClient();
|
|
79
|
+
const value = client2[key];
|
|
80
|
+
return value({
|
|
81
|
+
...context
|
|
82
|
+
});
|
|
83
|
+
}, "execute")
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
...acc,
|
|
87
|
+
[key]: tool
|
|
88
|
+
};
|
|
89
|
+
}, {});
|
|
90
|
+
return tools;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
__name(_OpenAPIToolset, "OpenAPIToolset");
|
|
94
|
+
var OpenAPIToolset = _OpenAPIToolset;
|
|
95
|
+
|
|
96
|
+
export { Integration, OpenAPIToolset };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { __name, __publicField } from './chunk-AJJZUHB4.js';
|
|
2
|
+
|
|
3
|
+
// src/filter/base.ts
|
|
4
|
+
var _a;
|
|
5
|
+
var BaseFilterTranslator = (_a = class {
|
|
6
|
+
/**
|
|
7
|
+
* Operator type checks
|
|
8
|
+
*/
|
|
9
|
+
isOperator(key) {
|
|
10
|
+
return key.startsWith("$");
|
|
11
|
+
}
|
|
12
|
+
isLogicalOperator(key) {
|
|
13
|
+
return _a.DEFAULT_OPERATORS.logical.includes(key);
|
|
14
|
+
}
|
|
15
|
+
isBasicOperator(key) {
|
|
16
|
+
return _a.DEFAULT_OPERATORS.basic.includes(key);
|
|
17
|
+
}
|
|
18
|
+
isNumericOperator(key) {
|
|
19
|
+
return _a.DEFAULT_OPERATORS.numeric.includes(key);
|
|
20
|
+
}
|
|
21
|
+
isArrayOperator(key) {
|
|
22
|
+
return _a.DEFAULT_OPERATORS.array.includes(key);
|
|
23
|
+
}
|
|
24
|
+
isElementOperator(key) {
|
|
25
|
+
return _a.DEFAULT_OPERATORS.element.includes(key);
|
|
26
|
+
}
|
|
27
|
+
isRegexOperator(key) {
|
|
28
|
+
return _a.DEFAULT_OPERATORS.regex.includes(key);
|
|
29
|
+
}
|
|
30
|
+
isFieldOperator(key) {
|
|
31
|
+
return this.isOperator(key) && !this.isLogicalOperator(key);
|
|
32
|
+
}
|
|
33
|
+
isCustomOperator(key) {
|
|
34
|
+
const support = this.getSupportedOperators();
|
|
35
|
+
return support.custom?.includes(key) ?? false;
|
|
36
|
+
}
|
|
37
|
+
getSupportedOperators() {
|
|
38
|
+
return _a.DEFAULT_OPERATORS;
|
|
39
|
+
}
|
|
40
|
+
isValidOperator(key) {
|
|
41
|
+
const support = this.getSupportedOperators();
|
|
42
|
+
const allSupported = Object.values(support).flat();
|
|
43
|
+
return allSupported.includes(key);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Value normalization for comparison operators
|
|
47
|
+
*/
|
|
48
|
+
normalizeComparisonValue(value) {
|
|
49
|
+
if (value instanceof Date) {
|
|
50
|
+
return value.toISOString();
|
|
51
|
+
}
|
|
52
|
+
if (typeof value === "number" && Object.is(value, -0)) {
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Helper method to simulate $all operator using $and + $eq when needed.
|
|
59
|
+
* Some vector stores don't support $all natively.
|
|
60
|
+
*/
|
|
61
|
+
simulateAllOperator(field, values) {
|
|
62
|
+
return {
|
|
63
|
+
$and: values.map((value) => ({
|
|
64
|
+
[field]: {
|
|
65
|
+
$in: [
|
|
66
|
+
this.normalizeComparisonValue(value)
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}))
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Utility functions for type checking
|
|
74
|
+
*/
|
|
75
|
+
isPrimitive(value) {
|
|
76
|
+
return value === null || value === undefined || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
77
|
+
}
|
|
78
|
+
isRegex(value) {
|
|
79
|
+
return value instanceof RegExp;
|
|
80
|
+
}
|
|
81
|
+
isEmpty(obj) {
|
|
82
|
+
return obj === null || obj === undefined || typeof obj === "object" && Object.keys(obj).length === 0;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Helper to handle array value normalization consistently
|
|
86
|
+
*/
|
|
87
|
+
normalizeArrayValues(values) {
|
|
88
|
+
return values.map((value) => this.normalizeComparisonValue(value));
|
|
89
|
+
}
|
|
90
|
+
validateFilter(filter) {
|
|
91
|
+
const validation = this.validateFilterSupport(filter);
|
|
92
|
+
if (!validation.supported) {
|
|
93
|
+
throw new Error(validation.messages.join(", "));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Validates if a filter structure is supported by the specific vector DB
|
|
98
|
+
* and returns detailed validation information.
|
|
99
|
+
*/
|
|
100
|
+
validateFilterSupport(node, path = "") {
|
|
101
|
+
const messages = [];
|
|
102
|
+
if (this.isPrimitive(node) || this.isEmpty(node)) {
|
|
103
|
+
return {
|
|
104
|
+
supported: true,
|
|
105
|
+
messages: []
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (Array.isArray(node)) {
|
|
109
|
+
const arrayResults = node.map((item) => this.validateFilterSupport(item, path));
|
|
110
|
+
const arrayMessages = arrayResults.flatMap((r) => r.messages);
|
|
111
|
+
return {
|
|
112
|
+
supported: arrayResults.every((r) => r.supported),
|
|
113
|
+
messages: arrayMessages
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const nodeObj = node;
|
|
117
|
+
let isSupported = true;
|
|
118
|
+
for (const [key, value] of Object.entries(nodeObj)) {
|
|
119
|
+
const newPath = path ? `${path}.${key}` : key;
|
|
120
|
+
if (this.isOperator(key)) {
|
|
121
|
+
if (!this.isValidOperator(key)) {
|
|
122
|
+
isSupported = false;
|
|
123
|
+
messages.push(_a.ErrorMessages.UNSUPPORTED_OPERATOR(key));
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (!path && !this.isLogicalOperator(key)) {
|
|
127
|
+
isSupported = false;
|
|
128
|
+
messages.push(_a.ErrorMessages.INVALID_TOP_LEVEL_OPERATOR(key));
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (key === "$elemMatch" && (typeof value !== "object" || Array.isArray(value))) {
|
|
132
|
+
isSupported = false;
|
|
133
|
+
messages.push(_a.ErrorMessages.ELEM_MATCH_REQUIRES_OBJECT);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (this.isLogicalOperator(key)) {
|
|
137
|
+
if (key === "$not") {
|
|
138
|
+
if (Array.isArray(value) || typeof value !== "object") {
|
|
139
|
+
isSupported = false;
|
|
140
|
+
messages.push(_a.ErrorMessages.NOT_REQUIRES_OBJECT);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (this.isEmpty(value)) {
|
|
144
|
+
isSupported = false;
|
|
145
|
+
messages.push(_a.ErrorMessages.NOT_CANNOT_BE_EMPTY);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (path && !this.isLogicalOperator(path.split(".").pop())) {
|
|
151
|
+
isSupported = false;
|
|
152
|
+
messages.push(_a.ErrorMessages.INVALID_LOGICAL_OPERATOR_LOCATION(key, newPath));
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (Array.isArray(value)) {
|
|
156
|
+
const hasDirectOperators = value.some((item) => typeof item === "object" && Object.keys(item).length === 1 && this.isFieldOperator(Object.keys(item)[0]));
|
|
157
|
+
if (hasDirectOperators) {
|
|
158
|
+
isSupported = false;
|
|
159
|
+
messages.push(_a.ErrorMessages.INVALID_LOGICAL_OPERATOR_CONTENT(newPath));
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const nestedValidation = this.validateFilterSupport(value, newPath);
|
|
166
|
+
if (!nestedValidation.supported) {
|
|
167
|
+
isSupported = false;
|
|
168
|
+
messages.push(...nestedValidation.messages);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
supported: isSupported,
|
|
173
|
+
messages
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}, __name(_a, "BaseFilterTranslator"), __publicField(_a, "BASIC_OPERATORS", [
|
|
177
|
+
"$eq",
|
|
178
|
+
"$ne"
|
|
179
|
+
]), __publicField(_a, "NUMERIC_OPERATORS", [
|
|
180
|
+
"$gt",
|
|
181
|
+
"$gte",
|
|
182
|
+
"$lt",
|
|
183
|
+
"$lte"
|
|
184
|
+
]), __publicField(_a, "ARRAY_OPERATORS", [
|
|
185
|
+
"$in",
|
|
186
|
+
"$nin",
|
|
187
|
+
"$all",
|
|
188
|
+
"$elemMatch"
|
|
189
|
+
]), __publicField(_a, "LOGICAL_OPERATORS", [
|
|
190
|
+
"$and",
|
|
191
|
+
"$or",
|
|
192
|
+
"$not",
|
|
193
|
+
"$nor"
|
|
194
|
+
]), __publicField(_a, "ELEMENT_OPERATORS", [
|
|
195
|
+
"$exists"
|
|
196
|
+
]), __publicField(_a, "REGEX_OPERATORS", [
|
|
197
|
+
"$regex",
|
|
198
|
+
"$options"
|
|
199
|
+
]), __publicField(_a, "DEFAULT_OPERATORS", {
|
|
200
|
+
logical: _a.LOGICAL_OPERATORS,
|
|
201
|
+
basic: _a.BASIC_OPERATORS,
|
|
202
|
+
numeric: _a.NUMERIC_OPERATORS,
|
|
203
|
+
array: _a.ARRAY_OPERATORS,
|
|
204
|
+
element: _a.ELEMENT_OPERATORS,
|
|
205
|
+
regex: _a.REGEX_OPERATORS
|
|
206
|
+
}), __publicField(_a, "ErrorMessages", {
|
|
207
|
+
UNSUPPORTED_OPERATOR: /* @__PURE__ */ __name((op) => `Unsupported operator: ${op}`, "UNSUPPORTED_OPERATOR"),
|
|
208
|
+
INVALID_LOGICAL_OPERATOR_LOCATION: /* @__PURE__ */ __name((op, path) => `Logical operator ${op} cannot be used at field level: ${path}`, "INVALID_LOGICAL_OPERATOR_LOCATION"),
|
|
209
|
+
NOT_REQUIRES_OBJECT: `$not operator requires an object`,
|
|
210
|
+
NOT_CANNOT_BE_EMPTY: `$not operator cannot be empty`,
|
|
211
|
+
INVALID_LOGICAL_OPERATOR_CONTENT: /* @__PURE__ */ __name((path) => `Logical operators must contain field conditions, not direct operators: ${path}`, "INVALID_LOGICAL_OPERATOR_CONTENT"),
|
|
212
|
+
INVALID_TOP_LEVEL_OPERATOR: /* @__PURE__ */ __name((op) => `Invalid top-level operator: ${op}`, "INVALID_TOP_LEVEL_OPERATOR"),
|
|
213
|
+
ELEM_MATCH_REQUIRES_OBJECT: `$elemMatch requires an object with conditions`
|
|
214
|
+
}), _a);
|
|
215
|
+
|
|
216
|
+
export { BaseFilterTranslator };
|