Edits history of script submission #22283 for ' Search Strale Capabilities (strale)'

  • deno
    // Search Strale's 290+ quality-tested data capabilities.
    // Returns matching capabilities with descriptions, pricing, and quality scores.
    //
    // Strale is the data layer for AI agents — every data source independently
    // quality-tested, scored, and audit-logged. https://strale.dev
    
    type Strale = {
      api_key: string;
      base_url?: string;
    };
    
    export async function main(
      strale: Strale,
      query: string,
      limit: number = 5,
    ) {
      const baseUrl = strale.base_url ?? "https://api.strale.io";
    
      const response = await fetch(`${baseUrl}/v1/suggest`, {
        method: "POST",
        headers: {
          "Authorization": `Bearer ${strale.api_key}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify({ task: query, limit }),
      });
    
      if (!response.ok) {
        const error = await response.json().catch(() => ({ message: response.statusText }));
        throw new Error(
          `Strale API error (${response.status}): ${(error as any).error?.message ?? (error as any).message ?? "Unknown error"}`
        );
      }
    
      const data = await response.json() as {
        suggestions: Array<{
          slug: string;
          name: string;
          description: string;
          category: string;
          price_cents: number;
          quality_score?: number;
          relevance_score?: number;
        }>;
      };
    
      return {
        query,
        matches: data.suggestions.map((s) => ({
          slug: s.slug,
          name: s.name,
          description: s.description,
          category: s.category,
          price: `€${(s.price_cents / 100).toFixed(2)}`,
          price_cents: s.price_cents,
          quality_score: s.quality_score,
          relevance_score: s.relevance_score,
        })),
        count: data.suggestions.length,
      };
    }

    Submitted by petter133 56 days ago