agent-pulse 1.4.0 → 1.4.2

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.
@@ -18,6 +18,63 @@ class GrokProvider {
18
18
  });
19
19
  }
20
20
  async generate(system, prompt, files, tools, config, output_schema, onToken) {
21
+ // Image generation mode — route to images API instead of chat completions
22
+ if (this.model.includes('imagine')) {
23
+ const promptText = Array.isArray(prompt)
24
+ ? prompt.filter(m => m.role === 'user').map(m => m.content).join('\n')
25
+ : String(prompt);
26
+ let images;
27
+ if (config?.image_url) {
28
+ // Image editing — direct JSON request to /v1/images/edits
29
+ // (OpenAI SDK's images.edit() uses multipart/form-data, but x.ai requires JSON)
30
+ const body = {
31
+ model: this.model,
32
+ prompt: promptText,
33
+ image_url: config.image_url,
34
+ n: config?.n || 1,
35
+ response_format: config?.response_format || 'b64_json',
36
+ ...(config?.aspect_ratio && { aspect_ratio: config.aspect_ratio }),
37
+ };
38
+ const res = await fetch('https://api.x.ai/v1/images/edits', {
39
+ method: 'POST',
40
+ headers: {
41
+ 'Authorization': `Bearer ${this.client.apiKey}`,
42
+ 'Content-Type': 'application/json',
43
+ },
44
+ body: JSON.stringify(body),
45
+ });
46
+ if (!res.ok) {
47
+ const errText = await res.text();
48
+ throw new Error(`Request failed with status ${res.status}: ${errText}`);
49
+ }
50
+ const json = await res.json();
51
+ images = json.data;
52
+ }
53
+ else {
54
+ // Standard image generation
55
+ const response = await this.client.images.generate({
56
+ model: this.model,
57
+ prompt: promptText,
58
+ n: config?.n || 1,
59
+ response_format: config?.response_format || 'b64_json',
60
+ ...(config?.aspect_ratio && { aspect_ratio: config.aspect_ratio }),
61
+ });
62
+ images = response.data;
63
+ }
64
+ const markdownParts = images.map((img, i) => {
65
+ if (img.b64_json) {
66
+ return `![Generated Image${images.length > 1 ? ` ${i + 1}` : ''}](data:image/png;base64,${img.b64_json})`;
67
+ }
68
+ return `![Generated Image${images.length > 1 ? ` ${i + 1}` : ''}](${img.url})`;
69
+ });
70
+ const content = markdownParts.join('\n\n');
71
+ onToken(content);
72
+ return {
73
+ content,
74
+ usage: { input_tokens: 0, output_tokens: 0, total_tokens: 0 },
75
+ meta: { model: this.model, latency_ms: 0 }
76
+ };
77
+ }
21
78
  // 1. Prepare messages
22
79
  const messages = [];
23
80
  if (system) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-pulse",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "A lightweight, agentic AI framework for JavaScript/TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",