agent-pulse 1.4.5 → 1.5.0

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.
@@ -23,17 +23,51 @@ 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
- // Both generation and editing use /v1/images/generations
27
- // For editing, just add image_url to the same request
28
26
  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
- });
27
+ let response;
28
+ if (imageUrl) {
29
+ // Image EDITING: use /v1/images/edits with JSON body (not multipart/form-data)
30
+ // The OpenAI SDK's images.edit() uses multipart/form-data which xAI doesn't support,
31
+ // so we make a direct fetch call with application/json
32
+ const editBody = {
33
+ model: this.model,
34
+ prompt: promptText,
35
+ n: config?.n || 1,
36
+ response_format: config?.response_format || 'b64_json',
37
+ image: {
38
+ url: imageUrl,
39
+ type: 'image_url',
40
+ },
41
+ };
42
+ // For multi-image editing, aspect_ratio can override input ratio
43
+ if (config?.aspect_ratio) {
44
+ editBody.aspect_ratio = config.aspect_ratio;
45
+ }
46
+ const res = await fetch('https://api.x.ai/v1/images/edits', {
47
+ method: 'POST',
48
+ headers: {
49
+ 'Content-Type': 'application/json',
50
+ 'Authorization': `Bearer ${this.client.apiKey}`,
51
+ },
52
+ body: JSON.stringify(editBody),
53
+ });
54
+ if (!res.ok) {
55
+ const errorText = await res.text();
56
+ throw new Error(`xAI image edit failed (${res.status}): ${errorText}`);
57
+ }
58
+ response = await res.json();
59
+ }
60
+ else {
61
+ // Image GENERATION: text-to-image via /v1/images/generations
62
+ const genResponse = await this.client.images.generate({
63
+ model: this.model,
64
+ prompt: promptText,
65
+ n: config?.n || 1,
66
+ response_format: config?.response_format || 'b64_json',
67
+ ...(config?.aspect_ratio && { aspect_ratio: config.aspect_ratio }),
68
+ });
69
+ response = genResponse;
70
+ }
37
71
  const images = response.data;
38
72
  const markdownParts = images.map((img, i) => {
39
73
  if (img.b64_json) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-pulse",
3
- "version": "1.4.5",
3
+ "version": "1.5.0",
4
4
  "description": "A lightweight, agentic AI framework for JavaScript/TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",