agent-pulse 1.4.3 → 1.4.5
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 +35 -0
- package/dist/providers/google.js +12 -9
- package/dist/providers/grok.js +12 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -450,6 +450,41 @@ const result = await agent.run("A futuristic city skyline in neon colors.");
|
|
|
450
450
|
// "" or ""
|
|
451
451
|
```
|
|
452
452
|
|
|
453
|
+
#### Image Editing (Reference Image)
|
|
454
|
+
|
|
455
|
+
Edit or remix an existing image by passing `reference_image` in config. This is **provider-agnostic** — the same code works with both Grok and Google providers.
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
import { Agent, grok } from 'agent-pulse';
|
|
459
|
+
|
|
460
|
+
const agent = new Agent({
|
|
461
|
+
name: 'editor',
|
|
462
|
+
provider: new grok('grok-imagine-image'),
|
|
463
|
+
config: {
|
|
464
|
+
aspect_ratio: '3:4',
|
|
465
|
+
response_format: 'b64_json',
|
|
466
|
+
reference_image: 'data:image/png;base64,iVBORw0KGgo...' // base64 data URI
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
const result = await agent.run("Change the background to a sunset beach.");
|
|
471
|
+
// result.content contains the edited image as a markdown data URI
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
To swap providers, just change the provider line — `reference_image` works the same way:
|
|
475
|
+
|
|
476
|
+
```typescript
|
|
477
|
+
// Grok
|
|
478
|
+
provider: new grok('grok-imagine-image', process.env.GROK_API_KEY)
|
|
479
|
+
|
|
480
|
+
// Google Gemini
|
|
481
|
+
provider: new google('gemini-2.5-flash-image', process.env.GOOGLE_API_KEY)
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
> **How it works under the hood:**
|
|
485
|
+
> - **Grok**: Sends a JSON request to `/v1/images/edits` with `image_url` (since the OpenAI SDK's `images.edit()` uses multipart/form-data, which x.ai doesn't support).
|
|
486
|
+
> - **Google**: Injects the image as `inlineData` alongside the text prompt in the multimodal content.
|
|
487
|
+
|
|
453
488
|
#### Google (Gemini)
|
|
454
489
|
Gemini models can generate images as part of their response.
|
|
455
490
|
|
package/dist/providers/google.js
CHANGED
|
@@ -72,12 +72,17 @@ class GoogleProvider {
|
|
|
72
72
|
}
|
|
73
73
|
if (m.tool_calls) {
|
|
74
74
|
for (const tc of m.tool_calls) {
|
|
75
|
-
|
|
75
|
+
const fcPart = {
|
|
76
76
|
functionCall: {
|
|
77
77
|
name: tc.name,
|
|
78
78
|
args: tc.arguments
|
|
79
79
|
}
|
|
80
|
-
}
|
|
80
|
+
};
|
|
81
|
+
// Preserve thought_signature for Gemini 3+ models
|
|
82
|
+
if (tc.thought_signature) {
|
|
83
|
+
fcPart.thoughtSignature = tc.thought_signature;
|
|
84
|
+
}
|
|
85
|
+
parts.push(fcPart);
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
if (m.content) {
|
|
@@ -225,20 +230,18 @@ class GoogleProvider {
|
|
|
225
230
|
// Tool Calls
|
|
226
231
|
// New SDK usually aggregates or provides them in chunks.
|
|
227
232
|
// We need to check `candidates[0].content.parts` for `functionCall`.
|
|
228
|
-
// Streaming tool calls might be tricky as they come in parts?
|
|
229
|
-
// Google usually sends the full function call in one chunk or at the end?
|
|
233
|
+
// Streaming tool calls might be tricky as they come in parts?
|
|
234
|
+
// Google usually sends the full function call in one chunk or at the end?
|
|
230
235
|
// Let's inspect the chunk structure via candidates.
|
|
231
236
|
const parts = chunk.candidates?.[0]?.content?.parts;
|
|
232
237
|
if (parts) {
|
|
233
238
|
for (const part of parts) {
|
|
234
239
|
if (part.functionCall) {
|
|
235
|
-
// It seems Google sends full function call or we need to accumulate?
|
|
236
|
-
// Usually it's complete in the response object if stream is done, but in stream?
|
|
237
|
-
// Let's collect them.
|
|
238
240
|
toolCalls.push({
|
|
239
241
|
name: part.functionCall.name,
|
|
240
|
-
arguments: part.functionCall.args,
|
|
241
|
-
id: 'call_' + Date.now()
|
|
242
|
+
arguments: part.functionCall.args,
|
|
243
|
+
id: 'call_' + Date.now(),
|
|
244
|
+
thought_signature: part.thoughtSignature || undefined
|
|
242
245
|
});
|
|
243
246
|
}
|
|
244
247
|
}
|
package/dist/providers/grok.js
CHANGED
|
@@ -23,45 +23,18 @@ class GrokProvider {
|
|
|
23
23
|
const promptText = Array.isArray(prompt)
|
|
24
24
|
? prompt.filter(m => m.role === 'user').map(m => m.content).join('\n')
|
|
25
25
|
: String(prompt);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
const res = await fetch('https://api.x.ai/v1/images/edits', {
|
|
40
|
-
method: 'POST',
|
|
41
|
-
headers: {
|
|
42
|
-
'Authorization': `Bearer ${this.client.apiKey}`,
|
|
43
|
-
'Content-Type': 'application/json',
|
|
44
|
-
},
|
|
45
|
-
body: JSON.stringify(body),
|
|
46
|
-
});
|
|
47
|
-
if (!res.ok) {
|
|
48
|
-
const errText = await res.text();
|
|
49
|
-
throw new Error(`Request failed with status ${res.status}: ${errText}`);
|
|
50
|
-
}
|
|
51
|
-
const json = await res.json();
|
|
52
|
-
images = json.data;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// Standard image generation
|
|
56
|
-
const response = await this.client.images.generate({
|
|
57
|
-
model: this.model,
|
|
58
|
-
prompt: promptText,
|
|
59
|
-
n: config?.n || 1,
|
|
60
|
-
response_format: config?.response_format || 'b64_json',
|
|
61
|
-
...(config?.aspect_ratio && { aspect_ratio: config.aspect_ratio }),
|
|
62
|
-
});
|
|
63
|
-
images = response.data;
|
|
64
|
-
}
|
|
26
|
+
// Both generation and editing use /v1/images/generations
|
|
27
|
+
// For editing, just add image_url to the same request
|
|
28
|
+
const imageUrl = config?.reference_image || config?.image_url;
|
|
29
|
+
const response = await this.client.images.generate({
|
|
30
|
+
model: this.model,
|
|
31
|
+
prompt: promptText,
|
|
32
|
+
n: config?.n || 1,
|
|
33
|
+
response_format: config?.response_format || 'b64_json',
|
|
34
|
+
...(config?.aspect_ratio && { aspect_ratio: config.aspect_ratio }),
|
|
35
|
+
...(imageUrl && { image_url: imageUrl }),
|
|
36
|
+
});
|
|
37
|
+
const images = response.data;
|
|
65
38
|
const markdownParts = images.map((img, i) => {
|
|
66
39
|
if (img.b64_json) {
|
|
67
40
|
return ``;
|