@mindstudio-ai/agent 0.0.9 → 0.0.10
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 +59 -18
- package/dist/index.js.map +1 -1
- package/llms.txt +644 -135
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,29 +19,27 @@ import { MindStudioAgent } from '@mindstudio-ai/agent';
|
|
|
19
19
|
|
|
20
20
|
const agent = new MindStudioAgent({ apiKey: 'your-api-key' });
|
|
21
21
|
|
|
22
|
+
// Generate text with an AI model
|
|
23
|
+
const { content } = await agent.generateText({
|
|
24
|
+
message: 'Summarize this article: ...',
|
|
25
|
+
});
|
|
26
|
+
console.log(content);
|
|
27
|
+
|
|
22
28
|
// Generate an image
|
|
23
29
|
const { imageUrl } = await agent.generateImage({
|
|
24
30
|
prompt: 'A mountain landscape at sunset',
|
|
25
|
-
mode: 'background',
|
|
26
31
|
});
|
|
27
32
|
console.log(imageUrl);
|
|
28
33
|
|
|
29
|
-
// Send a message to an AI model
|
|
30
|
-
const { content } = await agent.userMessage({
|
|
31
|
-
message: 'Summarize this article: ...',
|
|
32
|
-
source: 'user',
|
|
33
|
-
});
|
|
34
|
-
console.log(content);
|
|
35
|
-
|
|
36
34
|
// Search Google
|
|
37
35
|
const { results } = await agent.searchGoogle({
|
|
38
|
-
query: 'TypeScript best practices
|
|
36
|
+
query: 'TypeScript best practices',
|
|
39
37
|
exportType: 'json',
|
|
40
38
|
});
|
|
41
39
|
console.log(results);
|
|
42
40
|
```
|
|
43
41
|
|
|
44
|
-
Every method is fully typed — your editor will autocomplete available parameters, show enum options, and infer the output shape.
|
|
42
|
+
Every method is fully typed — your editor will autocomplete available parameters, show enum options, and infer the output shape. Results are returned flat for easy destructuring.
|
|
45
43
|
|
|
46
44
|
## Authentication
|
|
47
45
|
|
|
@@ -73,27 +71,42 @@ Resolution order: constructor `apiKey` > `MINDSTUDIO_API_KEY` env > `CALLBACK_TO
|
|
|
73
71
|
Steps execute within threads. Pass `$threadId` and `$appId` from a previous call to maintain state across calls:
|
|
74
72
|
|
|
75
73
|
```typescript
|
|
76
|
-
const r1 = await agent.
|
|
74
|
+
const r1 = await agent.generateText({
|
|
77
75
|
message: 'My name is Alice',
|
|
78
|
-
source: 'user',
|
|
79
76
|
});
|
|
80
77
|
|
|
81
78
|
// The model remembers the conversation
|
|
82
|
-
const r2 = await agent.
|
|
83
|
-
{ message: 'What is my name?'
|
|
79
|
+
const r2 = await agent.generateText(
|
|
80
|
+
{ message: 'What is my name?' },
|
|
84
81
|
{ threadId: r1.$threadId, appId: r1.$appId },
|
|
85
82
|
);
|
|
86
83
|
```
|
|
87
84
|
|
|
85
|
+
## Rate limiting
|
|
86
|
+
|
|
87
|
+
Rate limiting is handled automatically:
|
|
88
|
+
|
|
89
|
+
- **Concurrency queue** — requests beyond the server's concurrent limit are queued and proceed as slots open up (10 for internal tokens, 20 for API keys)
|
|
90
|
+
- **Auto-retry on 429** — rate-limited responses are retried automatically using the `Retry-After` header (default: 3 retries, configurable via `maxRetries`)
|
|
91
|
+
- **Call cap** — internal tokens are capped at 500 calls per execution; the SDK throws `MindStudioError` with code `call_cap_exceeded` rather than sending requests that will fail
|
|
92
|
+
|
|
93
|
+
Every result includes `$rateLimitRemaining` so you can throttle proactively:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const result = await agent.generateText({ message: 'Hello' });
|
|
97
|
+
console.log(result.$rateLimitRemaining); // calls remaining in window
|
|
98
|
+
```
|
|
99
|
+
|
|
88
100
|
## Available steps
|
|
89
101
|
|
|
90
102
|
Every step has a dedicated typed method. A few highlights:
|
|
91
103
|
|
|
92
104
|
| Method | Description |
|
|
93
105
|
| --- | --- |
|
|
94
|
-
| `
|
|
106
|
+
| `generateText()` | Send a message to an AI model |
|
|
95
107
|
| `generateImage()` | Generate an image from a text prompt |
|
|
96
108
|
| `generateVideo()` | Generate a video from a text prompt |
|
|
109
|
+
| `generateAsset()` | Generate an HTML/PDF/PNG/video asset |
|
|
97
110
|
| `analyzeImage()` | Analyze an image with a vision model |
|
|
98
111
|
| `textToSpeech()` | Convert text to speech |
|
|
99
112
|
| `transcribeAudio()` | Transcribe audio to text |
|
|
@@ -131,6 +144,9 @@ const agent = new MindStudioAgent({
|
|
|
131
144
|
// Base URL (or set MINDSTUDIO_BASE_URL env var)
|
|
132
145
|
// Defaults to https://v1.mindstudio-api.com
|
|
133
146
|
baseUrl: 'http://localhost:3129',
|
|
147
|
+
|
|
148
|
+
// Max retries on 429 rate limit responses (default: 3)
|
|
149
|
+
maxRetries: 5,
|
|
134
150
|
});
|
|
135
151
|
```
|
|
136
152
|
|
|
@@ -152,14 +168,39 @@ All input/output types are exported for use in your own code:
|
|
|
152
168
|
import type {
|
|
153
169
|
GenerateImageStepInput,
|
|
154
170
|
GenerateImageStepOutput,
|
|
155
|
-
|
|
171
|
+
GenerateTextStepInput,
|
|
156
172
|
StepName,
|
|
157
173
|
StepInputMap,
|
|
158
174
|
StepOutputMap,
|
|
159
175
|
} from '@mindstudio-ai/agent';
|
|
160
176
|
```
|
|
161
177
|
|
|
162
|
-
`StepName` is a union of all available step type names. `StepInputMap` and `StepOutputMap` map step names to their input/output types,
|
|
178
|
+
`StepName` is a union of all available step type names. `StepInputMap` and `StepOutputMap` map step names to their input/output types, useful for building generic utilities.
|
|
179
|
+
|
|
180
|
+
## Snippets
|
|
181
|
+
|
|
182
|
+
A `stepSnippets` object is exported for building UI menus or code generators:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { stepSnippets } from '@mindstudio-ai/agent';
|
|
186
|
+
|
|
187
|
+
stepSnippets.generateText;
|
|
188
|
+
// {
|
|
189
|
+
// method: "generateText",
|
|
190
|
+
// snippet: "{\n message: ``,\n}",
|
|
191
|
+
// outputKeys: ["content"]
|
|
192
|
+
// }
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## LLM documentation
|
|
196
|
+
|
|
197
|
+
An `llms.txt` file ships with the package for AI agent consumption:
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
node_modules/@mindstudio-ai/agent/llms.txt
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
It contains a compact, complete reference of all methods with their required parameters and output keys — optimized for LLM context windows.
|
|
163
204
|
|
|
164
205
|
## Error handling
|
|
165
206
|
|
|
@@ -167,7 +208,7 @@ import type {
|
|
|
167
208
|
import { MindStudioAgent, MindStudioError } from '@mindstudio-ai/agent';
|
|
168
209
|
|
|
169
210
|
try {
|
|
170
|
-
await agent.generateImage({ prompt: '...'
|
|
211
|
+
await agent.generateImage({ prompt: '...' });
|
|
171
212
|
} catch (err) {
|
|
172
213
|
if (err instanceof MindStudioError) {
|
|
173
214
|
console.error(err.message); // Human-readable message
|