Forsion connect

From Changan-Su/Forsion · View interactive version

Forsion connect is an AI agent skill from the GitHub repository Changan-Su/Forsion. Build web pages/apps that call Forsion's AI (LLM chat, server-managed agent conversations with web search, image generation) using the signed-in Forsion account — one script tag, no API keys. Use this whenever the user wants a website or HTML page with any AI feature (smart import/parsing, chatbot/a

How to use this skill

Skill file

Forsion Connect AI SDK

Any web page you write for the user can call Forsion's AI through window.forsion — in the Forsion Desktop preview panel (chat side panel and Coding Space alike) AND after the user publishes it via Forsion Connect (/apps/<handle>/<slug>/). The host injects the SDK and proxies every call with the signed-in account's token; your code never sees keys or tokens.

Setup — one script tag

<script src="/forsion-connect.js"></script>

Rules:

API (identical in both modes)

forsion.mode                       // 'preview' | 'published'
await forsion.user()               // {username, nickname, avatar, tier} | null (null = not signed in)
await forsion.login()              // → user; published: opens Forsion login popup; preview: uses desktop login (rejects if desktop not signed in)
await forsion.models(type?)        // [{id, name, type}]; type 'llm' (default) | 'image'
await forsion.ai.chat({            // → {text, model}
  messages,                        // [{role:'user'|'assistant'|'system', content}] — or use `prompt` (string) instead
  system,                          // optional system prompt
  model,                           // optional; omit → platform default (recommended)
  temperature, maxTokens,          // optional
  onDelta: (d) => {}               // optional streaming callback, receives text increments
})
await forsion.ai.agent({           // → {text, session}
  input,                           // the task/request text (required)
  session,                         // optional: pass the returned session back to continue the SAME server-side conversation
  onDelta: (d) => {}               // optional streaming callback (may include interim progress text; `text` is authoritative)
})                                 // the model is decided server-side — there is no model parameter
await forsion.ai.generateImage({ prompt, model?, size?, n?, responseFormat? })
                                   // → {model, images: [{url, b64}]}; responseFormat 'url' (default) | 'b64'

chat vs agent — pick deliberately

Minimal working pattern

<script src="/forsion-connect.js"></script>
<script>
async function aiNormalize(rawText) {
  if (!window.forsion) throw new Error('请通过 Forsion 预览或 /apps/ 链接打开本页');
  if (!(await forsion.user())) await forsion.login();   // published: popup; preview: desktop login
  const out = document.getElementById('out');
  out.textContent = '';
  const { text } = await forsion.ai.chat({
    system: 'Convert the word list into JSON [{word,meaning,phonetic,example}]. Output JSON only.',
    prompt: rawText,
    onDelta: (d) => { out.textContent += d; },           // live streaming into the UI
  });
  return JSON.parse(text.replace(/^```(json)?|```$/gm, '').trim()); // models may fence JSON — strip defensively
}
</script>

Practical rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.