@blinkdotnew/sdk 0.1.0 → 0.2.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.
package/dist/index.mjs CHANGED
@@ -1601,6 +1601,55 @@ var BlinkAIImpl = class {
1601
1601
  constructor(httpClient) {
1602
1602
  this.httpClient = httpClient;
1603
1603
  }
1604
+ // Supported image formats for validation
1605
+ SUPPORTED_IMAGE_FORMATS = ["jpg", "jpeg", "png", "gif", "webp"];
1606
+ /**
1607
+ * Validates if a URL is a valid HTTPS image URL
1608
+ */
1609
+ validateImageUrl(url) {
1610
+ try {
1611
+ const parsedUrl = new URL(url);
1612
+ if (parsedUrl.protocol !== "https:") {
1613
+ return { isValid: false, error: "Image URLs must use HTTPS protocol" };
1614
+ }
1615
+ const pathname = parsedUrl.pathname.toLowerCase();
1616
+ const hasValidExtension = this.SUPPORTED_IMAGE_FORMATS.some(
1617
+ (format) => pathname.endsWith(`.${format}`)
1618
+ );
1619
+ if (!hasValidExtension) {
1620
+ return {
1621
+ isValid: false,
1622
+ error: `Image URL must end with a supported format: ${this.SUPPORTED_IMAGE_FORMATS.join(", ")}`
1623
+ };
1624
+ }
1625
+ return { isValid: true };
1626
+ } catch (error) {
1627
+ return { isValid: false, error: "Invalid URL format" };
1628
+ }
1629
+ }
1630
+ /**
1631
+ * Validates messages for image content
1632
+ */
1633
+ validateMessages(messages) {
1634
+ const errors = [];
1635
+ messages.forEach((message, messageIndex) => {
1636
+ if (Array.isArray(message.content)) {
1637
+ message.content.forEach((item, contentIndex) => {
1638
+ if (item.type === "image") {
1639
+ if (!item.image || typeof item.image !== "string") {
1640
+ errors.push(`Message ${messageIndex}, content ${contentIndex}: Image content must have a valid image URL`);
1641
+ } else {
1642
+ const validation = this.validateImageUrl(item.image);
1643
+ if (!validation.isValid) {
1644
+ errors.push(`Message ${messageIndex}, content ${contentIndex}: ${validation.error}`);
1645
+ }
1646
+ }
1647
+ }
1648
+ });
1649
+ }
1650
+ });
1651
+ return { isValid: errors.length === 0, errors };
1652
+ }
1604
1653
  /**
1605
1654
  * Get MIME type for audio format
1606
1655
  */
@@ -1630,7 +1679,7 @@ var BlinkAIImpl = class {
1630
1679
  * prompt: "Write a poem about coding"
1631
1680
  * });
1632
1681
  *
1633
- * // Chat messages
1682
+ * // Chat messages (text only)
1634
1683
  * const { text } = await blink.ai.generateText({
1635
1684
  * messages: [
1636
1685
  * { role: "system", content: "You are a helpful assistant" },
@@ -1638,6 +1687,33 @@ var BlinkAIImpl = class {
1638
1687
  * ]
1639
1688
  * });
1640
1689
  *
1690
+ * // With image content
1691
+ * const { text } = await blink.ai.generateText({
1692
+ * messages: [
1693
+ * {
1694
+ * role: "user",
1695
+ * content: [
1696
+ * { type: "text", text: "What do you see in this image?" },
1697
+ * { type: "image", image: "https://example.com/photo.jpg" }
1698
+ * ]
1699
+ * }
1700
+ * ]
1701
+ * });
1702
+ *
1703
+ * // Mixed content with multiple images
1704
+ * const { text } = await blink.ai.generateText({
1705
+ * messages: [
1706
+ * {
1707
+ * role: "user",
1708
+ * content: [
1709
+ * { type: "text", text: "Compare these two images:" },
1710
+ * { type: "image", image: "https://example.com/image1.jpg" },
1711
+ * { type: "image", image: "https://example.com/image2.jpg" }
1712
+ * ]
1713
+ * }
1714
+ * ]
1715
+ * });
1716
+ *
1641
1717
  * // With options
1642
1718
  * const { text, usage } = await blink.ai.generateText({
1643
1719
  * prompt: "Summarize this article",
@@ -1657,6 +1733,12 @@ var BlinkAIImpl = class {
1657
1733
  if (!options.prompt && !options.messages) {
1658
1734
  throw new BlinkAIError("Either prompt or messages is required");
1659
1735
  }
1736
+ if (options.messages) {
1737
+ const validation = this.validateMessages(options.messages);
1738
+ if (!validation.isValid) {
1739
+ throw new BlinkAIError(`Message validation failed: ${validation.errors.join("; ")}`);
1740
+ }
1741
+ }
1660
1742
  const requestBody = {
1661
1743
  model: options.model,
1662
1744
  stream: false,
@@ -1727,6 +1809,12 @@ var BlinkAIImpl = class {
1727
1809
  if (!options.prompt && !options.messages) {
1728
1810
  throw new BlinkAIError("Either prompt or messages is required");
1729
1811
  }
1812
+ if (options.messages) {
1813
+ const validation = this.validateMessages(options.messages);
1814
+ if (!validation.isValid) {
1815
+ throw new BlinkAIError(`Message validation failed: ${validation.errors.join("; ")}`);
1816
+ }
1817
+ }
1730
1818
  const result = await this.httpClient.streamAiText(
1731
1819
  options.prompt || "",
1732
1820
  {