pi-xai-oauth 1.0.21 → 1.0.22

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.
@@ -487,6 +487,7 @@ export default function (pi: ExtensionAPI) {
487
487
  reasoning_effort: { type: "string", enum: ["low", "medium", "high"], default: "medium" },
488
488
  response_format: { type: "string", description: "Set to 'json' for JSON output" },
489
489
  previous_response_id: { type: "string", description: "Continue conversation" },
490
+ image_url: { type: "string", description: "Optional image URL for vision/multimodal input (supports image analysis)" },
490
491
  },
491
492
  required: ["prompt"],
492
493
  },
@@ -499,9 +500,25 @@ export default function (pi: ExtensionAPI) {
499
500
  };
500
501
  }
501
502
 
503
+ // Build proper Responses API input format (array of messages) to support text + images
504
+ let inputContent: any;
505
+ if (params.image_url) {
506
+ inputContent = [
507
+ { type: "input_text", text: params.prompt || "Describe this image." },
508
+ { type: "input_image", image_url: params.image_url }
509
+ ];
510
+ } else {
511
+ inputContent = params.prompt;
512
+ }
513
+
514
+ const userMessage = {
515
+ role: "user",
516
+ content: inputContent,
517
+ };
518
+
502
519
  const body: any = {
503
520
  model: params.model || "grok-4.3",
504
- input: params.prompt,
521
+ input: [userMessage],
505
522
  reasoning: { effort: params.reasoning_effort || "medium" },
506
523
  };
507
524
 
@@ -521,6 +538,14 @@ export default function (pi: ExtensionAPI) {
521
538
  body: JSON.stringify(body),
522
539
  });
523
540
 
541
+ if (!res.ok) {
542
+ const errorText = await res.text().catch(() => "Unknown error");
543
+ return {
544
+ content: [{ type: "text", text: `xAI API Error ${res.status}: ${errorText}` }],
545
+ details: { error: true, status: res.status, reasoning: "", response_id: "" },
546
+ };
547
+ }
548
+
524
549
  const data = await res.json();
525
550
  const text = data.output?.[0]?.content?.[0]?.text || JSON.stringify(data);
526
551
 
@@ -566,11 +591,19 @@ export default function (pi: ExtensionAPI) {
566
591
  },
567
592
  body: JSON.stringify({
568
593
  model: "grok-4.3",
569
- input: prompt,
594
+ input: [{ role: "user", content: prompt }],
570
595
  reasoning: { effort: params.reasoning_effort || "high" },
571
596
  }),
572
597
  });
573
598
 
599
+ if (!res.ok) {
600
+ const errorText = await res.text().catch(() => "Unknown error");
601
+ return {
602
+ content: [{ type: "text", text: `xAI API Error ${res.status}: ${errorText}` }],
603
+ details: { error: true, status: res.status, agents_used: 0, response_id: "" },
604
+ };
605
+ }
606
+
574
607
  const data = await res.json();
575
608
  const text = data.output?.[0]?.content?.[0]?.text || "Research completed";
576
609
 
@@ -604,8 +637,12 @@ export default function (pi: ExtensionAPI) {
604
637
  const res = await fetch("https://api.x.ai/v1/responses", {
605
638
  method: "POST",
606
639
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` },
607
- body: JSON.stringify({ model: "grok-4.3", input: prompt, reasoning: { effort: "medium" } }),
640
+ body: JSON.stringify({ model: "grok-4.3", input: [{ role: "user", content: prompt }], reasoning: { effort: "medium" } }),
608
641
  });
642
+ if (!res.ok) {
643
+ const errorText = await res.text().catch(() => "Unknown error");
644
+ return { content: [{ type: "text", text: `xAI API Error ${res.status}: ${errorText}` }], details: { error: true, status: res.status, query: params.query } };
645
+ }
609
646
  const data = await res.json();
610
647
  const text = data.output?.[0]?.content?.[0]?.text || `No results for: ${params.query}`;
611
648
  return { content: [{ type: "text", text }], details: { query: params.query } };
@@ -638,8 +675,12 @@ Be specific and cite examples where helpful.`;
638
675
  const res = await fetch("https://api.x.ai/v1/responses", {
639
676
  method: "POST",
640
677
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` },
641
- body: JSON.stringify({ model: "grok-4.3", input: prompt, reasoning: { effort: "medium" } }),
678
+ body: JSON.stringify({ model: "grok-4.3", input: [{ role: "user", content: prompt }], reasoning: { effort: "medium" } }),
642
679
  });
680
+ if (!res.ok) {
681
+ const errorText = await res.text().catch(() => "Unknown error");
682
+ return { content: [{ type: "text", text: `xAI API Error ${res.status}: ${errorText}` }], details: { error: true, status: res.status, query: params.query } };
683
+ }
643
684
  const data = await res.json();
644
685
  const text = data.output?.[0]?.content?.[0]?.text || `No X results for: ${params.query}`;
645
686
  return { content: [{ type: "text", text }], details: { query: params.query } };
@@ -664,8 +705,12 @@ Be specific and cite examples where helpful.`;
664
705
  const res = await fetch("https://api.x.ai/v1/responses", {
665
706
  method: "POST",
666
707
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` },
667
- body: JSON.stringify({ model: "grok-4.3", input: prompt, reasoning: { effort: "low" } }),
708
+ body: JSON.stringify({ model: "grok-4.3", input: [{ role: "user", content: prompt }], reasoning: { effort: "low" } }),
668
709
  });
710
+ if (!res.ok) {
711
+ const errorText = await res.text().catch(() => "Unknown error");
712
+ return { content: [{ type: "text", text: `xAI API Error ${res.status}: ${errorText}` }], details: { error: true, status: res.status, code: params.code } };
713
+ }
669
714
  const data = await res.json();
670
715
  const text = data.output?.[0]?.content?.[0]?.text || `Executed: ${String(params.code).substring(0, 100)}...`;
671
716
  return { content: [{ type: "text", text }], details: { code: params.code } };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-xai-oauth",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "One-command installer for xAI (Grok) OAuth provider + Grok 4.3 in pi",
5
5
  "keywords": [
6
6
  "pi-package",