← back to Trademarks Copyright

src/lib/swot.ts

53 lines

/**
 * SWOT quadrant agents — running on local Qwen via Ollama. No paid APIs.
 * We use a slightly larger model (qwen3:14b) for SWOT since volume is low
 * and quality matters; extraction/discovery uses qwen2.5:latest.
 */

import { qwen } from "./qwen";
import type { Item } from "./types";

const SWOT_MODEL = process.env.QWEN_SWOT_MODEL || "qwen3:14b";

export type Quadrant = "strength" | "weakness" | "opportunity" | "threat";

const SYSTEMS: Record<Quadrant, string> = {
  strength: `You are the STRENGTHS agent in a SWOT analysis of an expired/abandoned US trademark or public-domain copyright.
Your job: identify what made this mark or work valuable, and what residual equity (brand recall, cultural footprint, distinctive design, established categories) a new operator could inherit.
Be concrete. 3-5 bullets. Reference specific eras, demographics, or adjacent categories when relevant.
Do NOT include legal advice. End with one sentence on the single most exploitable strength.`,
  weakness: `You are the WEAKNESSES agent in a SWOT analysis of an expired/abandoned US trademark or public-domain copyright.
Your job: identify why this mark was abandoned, what categories it failed in, what baggage/associations would hurt a revival, and any limits on protectability (descriptive, generic drift, licensing entanglements).
Be concrete. 3-5 bullets. Reference commercial failures, dated positioning, or consumer perception issues.
Do NOT include legal advice. End with one sentence on the single biggest weakness.`,
  opportunity: `You are the OPPORTUNITIES agent in a SWOT analysis of an expired/abandoned US trademark or public-domain copyright.
Your job: identify monetization and revival angles — new categories (NICE classes), merchandising, content/media adaptations, licensing, nostalgia-driven DTC plays, domain + brand packaging, derivative IP.
Be concrete. 3-5 bullets with *specific* product or media ideas, not generic "start a brand" advice.
Do NOT include legal advice. End with one sentence naming the single best opportunity.`,
  threat: `You are the THREATS agent in a SWOT analysis of an expired/abandoned US trademark or public-domain copyright.
Your job: identify risks — original-owner revival, common-law rights in residual use, consumer confusion with active marks, likelihood of opposition/cancellation, cultural sensitivities, derivative-work copyright traps (especially for "public domain" characters where later adaptations are still protected).
Be concrete. 3-5 bullets. Name the kinds of actors (law firms, heirs, competitor brands) likely to object.
Do NOT include legal advice beyond general risk flagging. End with one sentence on the single biggest threat.`,
};

export async function runSwot(
  item: Pick<Item, "name" | "kind" | "original_owner" | "nice_class" | "goods_services" | "expired_date" | "status" | "notes">,
  quadrant: Quadrant
): Promise<string> {
  const prompt = `${SYSTEMS[quadrant]}

Subject of analysis:
- Name: ${item.name}
- Type: ${item.kind}
- Status: ${item.status}
- Expired/abandoned: ${item.expired_date}
- Original owner: ${item.original_owner ?? "unknown"}
- NICE class(es): ${item.nice_class ?? "n/a"}
- Goods/services covered: ${item.goods_services ?? "n/a"}
- Notes: ${item.notes ?? "n/a"}

Write your quadrant of the SWOT now.`;

  return qwen(prompt, { model: SWOT_MODEL, temperature: 0.4 });
}