From 2c16fe49df00f3bcc06821d2acf10708bc237a5a Mon Sep 17 00:00:00 2001 From: Hackall <36754621+hackall360@users.noreply.github.com> Date: Wed, 17 Sep 2025 12:46:42 -0700 Subject: [PATCH 1/2] Align PolliLib defaults with Unity AI endpoints --- Libs/pollilib/index.js | 1 + Libs/pollilib/src/audio.js | 7 ++- Libs/pollilib/src/client.js | 19 ++++---- Libs/pollilib/src/defaults.js | 3 ++ Libs/pollilib/src/image.js | 18 ++++++-- Libs/pollilib/src/text.js | 53 +++++++++++++++++----- src/main.js | 9 +--- src/pollinations-client.js | 4 +- tests/pollilib-chat.test.mjs | 14 +++++- tests/pollilib-seed-chat.test.mjs | 4 ++ tests/pollilib-text.test.mjs | 7 ++- tests/pollilib-token-query.test.mjs | 4 ++ tests/pollinations-token-optional.test.mjs | 3 +- 13 files changed, 109 insertions(+), 37 deletions(-) create mode 100644 Libs/pollilib/src/defaults.js diff --git a/Libs/pollilib/index.js b/Libs/pollilib/index.js index 495c245..a2de2cd 100644 --- a/Libs/pollilib/index.js +++ b/Libs/pollilib/index.js @@ -10,3 +10,4 @@ export * from './src/mcp.js'; export * from './src/binary.js'; export * from './src/errors.js'; export * from './src/sse.js'; +export * from './src/defaults.js'; diff --git a/Libs/pollilib/src/audio.js b/Libs/pollilib/src/audio.js index 331bdfa..9be3527 100644 --- a/Libs/pollilib/src/audio.js +++ b/Libs/pollilib/src/audio.js @@ -93,8 +93,13 @@ function buildTtsParams(options) { assignIfPresent(params, 'language', extras.language); delete extras.language; + if ('referer' in extras && extras.referer) { + params.referer = extras.referer; + delete extras.referer; + } + if ('referrer' in extras && extras.referrer) { - params.referrer = extras.referrer; + params.referer = params.referer ?? extras.referrer; delete extras.referrer; } diff --git a/Libs/pollilib/src/client.js b/Libs/pollilib/src/client.js index c9c3c5b..9ac189f 100644 --- a/Libs/pollilib/src/client.js +++ b/Libs/pollilib/src/client.js @@ -1,3 +1,5 @@ +import { DEFAULT_REFERRER } from './defaults.js'; + const DEFAULT_ENDPOINTS = { image: 'https://image.pollinations.ai', text: 'https://text.pollinations.ai', @@ -307,7 +309,7 @@ function isBodyObject(value) { } function createAuthManager({ auth, referrer, token, tokenProvider } = {}) { - const fallbackReferrer = referrer ?? inferReferrer(); + const fallbackReferrer = referrer ?? inferReferrer() ?? DEFAULT_REFERRER; if (auth) { if (auth.mode === 'none') { return new AuthManager({ mode: 'none', referrer: null, placement: 'header', getToken: async () => null }); @@ -374,12 +376,11 @@ class AuthManager { async apply({ method, url, headers, body, includeReferrer, includeToken, tokenPlacement }) { if (includeReferrer !== false && this.referrer) { - if ((method === 'GET' || method === 'HEAD') && !url.searchParams.has('referrer')) { - url.searchParams.set('referrer', this.referrer); - } else if (isBodyObject(body) && body.referrer == null) { - body.referrer = this.referrer; - } else if (!url.searchParams.has('referrer')) { - url.searchParams.set('referrer', this.referrer); + if (!url.searchParams.has('referer')) { + url.searchParams.set('referer', this.referrer); + } + if (isBodyObject(body) && body.referer == null) { + body.referer = this.referrer; } } @@ -407,8 +408,8 @@ class AuthManager { } async decorateUrl(url, { includeReferrer = true, includeToken = false, tokenPlacement } = {}) { - if (includeReferrer && this.referrer && !url.searchParams.has('referrer')) { - url.searchParams.set('referrer', this.referrer); + if (includeReferrer && this.referrer && !url.searchParams.has('referer')) { + url.searchParams.set('referer', this.referrer); } if (includeToken && this.mode === 'token') { const token = await this.getToken(); diff --git a/Libs/pollilib/src/defaults.js b/Libs/pollilib/src/defaults.js new file mode 100644 index 0000000..8de4d50 --- /dev/null +++ b/Libs/pollilib/src/defaults.js @@ -0,0 +1,3 @@ +export const DEFAULT_MODEL = 'unity'; +export const DEFAULT_SEED = '12345678'; +export const DEFAULT_REFERRER = 'https://www.unityailab.com'; diff --git a/Libs/pollilib/src/image.js b/Libs/pollilib/src/image.js index 2f0a43f..a6d2ad9 100644 --- a/Libs/pollilib/src/image.js +++ b/Libs/pollilib/src/image.js @@ -1,4 +1,5 @@ import { getDefaultClient } from './client.js'; +import { DEFAULT_MODEL, DEFAULT_SEED } from './defaults.js'; import { BinaryData } from './binary.js'; import { raiseForStatus } from './errors.js'; @@ -41,10 +42,16 @@ function buildImageParams(options) { const params = {}; const extras = { ...options }; - assignIfPresent(params, 'model', extras.model); + const model = extras.model ?? DEFAULT_MODEL; + if (model) { + params.model = model; + } delete extras.model; - assignIfPresent(params, 'seed', extras.seed); + const seed = extras.seed ?? DEFAULT_SEED; + if (seed != null) { + params.seed = seed; + } delete extras.seed; assignIfPresent(params, 'width', extras.width); @@ -91,8 +98,13 @@ function buildImageParams(options) { delete extras.high_contrast; delete extras.highContrast; + if ('referer' in extras && extras.referer) { + params.referer = extras.referer; + delete extras.referer; + } + if ('referrer' in extras && extras.referrer) { - params.referrer = extras.referrer; + params.referer = params.referer ?? extras.referrer; delete extras.referrer; } diff --git a/Libs/pollilib/src/text.js b/Libs/pollilib/src/text.js index 955e006..1abccca 100644 --- a/Libs/pollilib/src/text.js +++ b/Libs/pollilib/src/text.js @@ -1,4 +1,5 @@ import { getDefaultClient } from './client.js'; +import { DEFAULT_MODEL, DEFAULT_SEED } from './defaults.js'; import { sseEvents } from './sse.js'; import { raiseForStatus } from './errors.js'; @@ -7,12 +8,14 @@ export async function text(prompt, options = {}, client = getDefaultClient()) { const { stream = false, timeoutMs, ...rest } = options ?? {}; const params = buildTextParams(rest); - const url = `${client.textBase}/${encodeURIComponent(normalizedPrompt)}`; + if (!('input' in params)) { + params.input = normalizedPrompt; + } + const url = `${client.textBase}/openai`; if (stream) { - params.stream = 'true'; const response = await client.get(url, { - params, + params: { ...params, stream: 'true' }, headers: { Accept: 'text/event-stream' }, timeoutMs: timeoutMs ?? 0, }); @@ -35,7 +38,7 @@ export async function text(prompt, options = {}, client = getDefaultClient()) { } export async function chat(options = {}, client = getDefaultClient()) { - const { body, stream, timeoutMs } = buildChatPayload(options); + const { body, stream, timeoutMs, query } = buildChatPayload(options); const url = `${client.textBase}/openai`; if (stream) { @@ -43,6 +46,7 @@ export async function chat(options = {}, client = getDefaultClient()) { const response = await client.postJson(url, body, { headers: { Accept: 'text/event-stream' }, timeoutMs: timeoutMs ?? 0, + params: query, }); if (!response.ok) { await raiseForStatus(response, 'chat (stream)', { consumeBody: false }); @@ -57,7 +61,7 @@ export async function chat(options = {}, client = getDefaultClient()) { })(); } - const response = await client.postJson(url, body, { timeoutMs }); + const response = await client.postJson(url, body, { timeoutMs, params: query }); await raiseForStatus(response, 'chat'); return await response.json(); } @@ -140,10 +144,16 @@ function buildTextParams(options) { const params = {}; const extras = { ...options }; - assignIfPresent(params, 'model', extras.model); + const model = extras.model ?? DEFAULT_MODEL; + if (model) { + params.model = model; + } delete extras.model; - assignIfPresent(params, 'seed', extras.seed); + const seed = extras.seed ?? DEFAULT_SEED; + if (seed != null) { + params.seed = seed; + } delete extras.seed; assignIfPresent(params, 'temperature', pickFirst(extras, ['temperature'])); @@ -181,8 +191,13 @@ function buildTextParams(options) { delete extras.private; } + if ('referer' in extras && extras.referer) { + params.referer = extras.referer; + delete extras.referer; + } + if ('referrer' in extras && extras.referrer) { - params.referrer = extras.referrer; + params.referer = params.referer ?? extras.referrer; delete extras.referrer; } @@ -196,11 +211,15 @@ function buildTextParams(options) { function buildChatPayload(options = {}) { const extras = { ...options }; - const model = extras.model; + const model = extras.model ?? DEFAULT_MODEL; + delete extras.model; + if (!model) { throw new Error('chat() requires a model'); } - delete extras.model; + + const seed = extras.seed ?? DEFAULT_SEED; + delete extras.seed; const messages = normalizeMessages(extras.messages ?? [], extras.system ?? extras.systemPrompt); if (!messages.length) { @@ -213,6 +232,10 @@ function buildChatPayload(options = {}) { const body = { model, messages }; + if (seed != null) { + body.seed = seed; + } + if ('private' in extras) { body.private = !!extras.private; delete extras.private; @@ -256,7 +279,15 @@ function buildChatPayload(options = {}) { body[key] = value; } - return { body, stream, timeoutMs }; + const query = {}; + if (model) { + query.model = model; + } + if (seed != null) { + query.seed = seed; + } + + return { body, stream, timeoutMs, query }; } function normalizeMessages(messages, systemPrompt) { diff --git a/src/main.js b/src/main.js index 25a616a..aa5ec1d 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,5 @@ import './style.css'; -import { chat, image, textModels, tts } from '../Libs/pollilib/index.js'; +import { chat, image, textModels, tts, DEFAULT_SEED } from '../Libs/pollilib/index.js'; import { createPollinationsClient } from './pollinations-client.js'; import { createFallbackModel, @@ -7,7 +7,6 @@ import { normalizeTextCatalog, } from './model-catalog.js'; import { doesResponseMatchModel, isMatchingModelName } from './model-matching.js'; -import { generateSeed } from './seed.js'; const FALLBACK_MODELS = [ createFallbackModel('openai', 'OpenAI GPT-5 Nano (fallback)'), @@ -433,7 +432,6 @@ async function handleChatResponse(initialResponse, model, endpoint) { messages: state.conversation, tools: [IMAGE_TOOL], tool_choice: 'auto', - seed: generateSeed(), }, client, ); @@ -540,14 +538,13 @@ async function generateImageAsset(prompt, { width, height, model: imageModel } = if (!client) { throw new Error('Pollinations client is not ready.'); } - const seed = generateSeed(); + const seed = DEFAULT_SEED; const binary = await image( prompt, { width, height, model: imageModel, - seed, nologo: true, private: true, enhance: true, @@ -755,7 +752,6 @@ async function requestChatCompletion(model, endpoints) { const attemptErrors = []; for (const endpoint of endpoints) { try { - const requestSeed = generateSeed(); const response = await chat( { model: model.id, @@ -763,7 +759,6 @@ async function requestChatCompletion(model, endpoints) { messages: state.conversation, tools: [IMAGE_TOOL], tool_choice: 'auto', - seed: requestSeed, }, client, ); diff --git a/src/pollinations-client.js b/src/pollinations-client.js index d3dce8c..cbfcc5f 100644 --- a/src/pollinations-client.js +++ b/src/pollinations-client.js @@ -1,4 +1,4 @@ -import { PolliClient } from '../Libs/pollilib/index.js'; +import { PolliClient, DEFAULT_REFERRER } from '../Libs/pollilib/index.js'; let tokenPromise = null; let cachedResult = null; @@ -6,7 +6,7 @@ let cachedResult = null; export async function createPollinationsClient({ referrer } = {}) { const tokenResult = await ensureToken(); const { token, source, messages = [], errors = [] } = tokenResult; - const inferredReferrer = referrer ?? inferReferrer(); + const inferredReferrer = referrer ?? inferReferrer() ?? DEFAULT_REFERRER; const clientOptions = {}; if (token) { diff --git a/tests/pollilib-chat.test.mjs b/tests/pollilib-chat.test.mjs index 2636af1..fcbd0af 100644 --- a/tests/pollilib-chat.test.mjs +++ b/tests/pollilib-chat.test.mjs @@ -56,9 +56,14 @@ export async function run() { ); assert.equal(defaultResponse.model, 'openai'); assert.equal(requests[0].init.method, 'POST'); - assert.ok(requests[0].url.endsWith('/openai')); + const defaultUrl = new URL(requests[0].url); + assert.ok(defaultUrl.pathname.endsWith('/openai')); + assert.equal(defaultUrl.searchParams.get('model'), 'openai'); + assert.equal(defaultUrl.searchParams.get('seed'), '12345678'); + assert.equal(defaultUrl.searchParams.get('referer'), 'https://www.unityailab.com'); const defaultPayload = JSON.parse(requests[0].init.body); assert.equal(defaultPayload.model, 'openai'); + assert.equal(defaultPayload.seed, '12345678'); assert.equal(defaultPayload.endpoint, undefined); assert.deepEqual(defaultPayload.metadata, { session: 'abc123' }); assert.equal(defaultPayload.user, 'tester-1'); @@ -80,9 +85,14 @@ export async function run() { assert.equal(seedResponse.model, 'unity'); assert.equal(seedResponse.choices[0].message.content, 'Hello from Pollinations!'); assert.equal(requests[1].init.method, 'POST'); - assert.ok(requests[1].url.endsWith('/openai')); + const seedUrl = new URL(requests[1].url); + assert.ok(seedUrl.pathname.endsWith('/openai')); + assert.equal(seedUrl.searchParams.get('model'), 'unity'); + assert.equal(seedUrl.searchParams.get('seed'), '12345678'); + assert.equal(seedUrl.searchParams.get('referer'), 'https://www.unityailab.com'); const parsedSeedBody = JSON.parse(requests[1].init.body); assert.equal(parsedSeedBody.model, 'unity'); + assert.equal(parsedSeedBody.seed, '12345678'); assert.equal(parsedSeedBody.endpoint, 'seed'); assert.deepEqual(parsedSeedBody.response_format, { type: 'json_object' }); assert.equal(parsedSeedBody.json, undefined); diff --git a/tests/pollilib-seed-chat.test.mjs b/tests/pollilib-seed-chat.test.mjs index 05b4907..9311c0e 100644 --- a/tests/pollilib-seed-chat.test.mjs +++ b/tests/pollilib-seed-chat.test.mjs @@ -49,8 +49,12 @@ export async function run() { const url = new URL(request.url); assert.ok(url.pathname.endsWith('/openai'), 'Seed requests should hit the /openai endpoint'); + assert.equal(url.searchParams.get('model'), 'unity'); + assert.equal(url.searchParams.get('seed'), '12345678'); + assert.equal(url.searchParams.get('referer'), 'https://www.unityailab.com'); const payload = JSON.parse(request.init.body); assert.equal(payload.model, 'unity'); + assert.equal(payload.seed, '12345678'); assert.equal(payload.temperature, 0.2); assert.equal(payload.endpoint, 'seed'); assert.deepEqual(payload.messages, messages); diff --git a/tests/pollilib-text.test.mjs b/tests/pollilib-text.test.mjs index ecde0e5..7bed839 100644 --- a/tests/pollilib-text.test.mjs +++ b/tests/pollilib-text.test.mjs @@ -36,6 +36,11 @@ export async function run() { assert.equal(response, 'Hello from Pollinations!'); assert.equal(requests.length, 1, 'Expected the mock fetch to be invoked once'); - assert.ok(requests[0].url.includes(encodeURIComponent(prompt)), 'The request URL should include the encoded prompt'); assert.equal(requests[0].init.method, 'GET'); + const url = new URL(requests[0].url); + assert.ok(url.pathname.endsWith('/openai'), 'Text requests should use the /openai endpoint'); + assert.equal(url.searchParams.get('input'), prompt); + assert.equal(url.searchParams.get('model'), 'webgpt'); + assert.equal(url.searchParams.get('seed'), '12345678'); + assert.equal(url.searchParams.get('referer'), 'https://github.com/Unity-Lab-AI/chatdemo'); } diff --git a/tests/pollilib-token-query.test.mjs b/tests/pollilib-token-query.test.mjs index 0940484..c305edd 100644 --- a/tests/pollilib-token-query.test.mjs +++ b/tests/pollilib-token-query.test.mjs @@ -60,9 +60,13 @@ export async function run() { const requestUrl = new URL(request.url); assert.ok(requestUrl.pathname.endsWith('/openai')); assert.equal(requestUrl.searchParams.get('token'), 'example-token'); + assert.equal(requestUrl.searchParams.get('model'), 'unity'); + assert.equal(requestUrl.searchParams.get('seed'), '12345678'); + assert.equal(requestUrl.searchParams.get('referer'), 'https://www.unityailab.com'); const authHeader = request.init.headers?.Authorization ?? request.init.headers?.authorization; assert.equal(authHeader, 'Bearer example-token'); const payload = JSON.parse(request.init.body); assert.equal(payload.endpoint, 'seed'); + assert.equal(payload.seed, '12345678'); assert.deepEqual(payload.messages, messages); } diff --git a/tests/pollinations-token-optional.test.mjs b/tests/pollinations-token-optional.test.mjs index 5247335..cec3265 100644 --- a/tests/pollinations-token-optional.test.mjs +++ b/tests/pollinations-token-optional.test.mjs @@ -80,7 +80,8 @@ export async function run() { const { client, tokenSource, tokenMessages } = await createPollinationsClient(); assert.equal(tokenSource, null); - assert.equal(client.authMode, 'none'); + assert.equal(client.authMode, 'referrer'); + assert.equal(client.referrer, 'https://www.unityailab.com'); assert.ok(Array.isArray(tokenMessages)); assert.equal(tokenMessages.length, 0, `Unexpected messages: ${tokenMessages.join('; ')}`); if (fetchCalled !== 0) { From 1aa0d78d436bed92196dffca402b9c3d6779c4f1 Mon Sep 17 00:00:00 2001 From: Hackall <36754621+hackall360@users.noreply.github.com> Date: Wed, 17 Sep 2025 13:07:52 -0700 Subject: [PATCH 2/2] Default to Unity tokenized endpoints --- Libs/pollilib/src/client.js | 23 ++++++++++++++++++++-- Libs/pollilib/src/defaults.js | 1 + src/pollinations-client.js | 18 +++++++++++++---- tests/pollilib-chat.test.mjs | 2 ++ tests/pollilib-text.test.mjs | 16 +++++++++++++++ tests/pollinations-token-optional.test.mjs | 6 ++++-- 6 files changed, 58 insertions(+), 8 deletions(-) diff --git a/Libs/pollilib/src/client.js b/Libs/pollilib/src/client.js index 9ac189f..ee7ce4b 100644 --- a/Libs/pollilib/src/client.js +++ b/Libs/pollilib/src/client.js @@ -1,4 +1,4 @@ -import { DEFAULT_REFERRER } from './defaults.js'; +import { DEFAULT_REFERRER, DEFAULT_TOKEN } from './defaults.js'; const DEFAULT_ENDPOINTS = { image: 'https://image.pollinations.ai', @@ -20,6 +20,20 @@ export class PolliClient { defaultHeaders = {}, } = options ?? {}; + let authOptions = auth; + let referrerOption = referrer; + let tokenOption = token; + let tokenProviderOption = tokenProvider; + + if (!authOptions && !tokenOption && !tokenProviderOption) { + authOptions = { + mode: 'token', + placement: 'query', + token: DEFAULT_TOKEN, + referrer: referrerOption ?? undefined, + }; + } + const impl = fetchImpl ?? globalThis.fetch; if (typeof impl !== 'function') { throw new Error('PolliClient requires a fetch implementation'); @@ -36,7 +50,12 @@ export class PolliClient { this.textBase = resolvedBases.text; this.timeoutMs = Number.isFinite(timeoutMs) && timeoutMs > 0 ? timeoutMs : 60_000; this.defaultHeaders = normalizeHeaderBag(defaultHeaders); - this._auth = createAuthManager({ auth, referrer, token, tokenProvider }); + this._auth = createAuthManager({ + auth: authOptions, + referrer: referrerOption, + token: tokenOption, + tokenProvider: tokenProviderOption, + }); } get authMode() { diff --git a/Libs/pollilib/src/defaults.js b/Libs/pollilib/src/defaults.js index 8de4d50..e11426e 100644 --- a/Libs/pollilib/src/defaults.js +++ b/Libs/pollilib/src/defaults.js @@ -1,3 +1,4 @@ export const DEFAULT_MODEL = 'unity'; export const DEFAULT_SEED = '12345678'; export const DEFAULT_REFERRER = 'https://www.unityailab.com'; +export const DEFAULT_TOKEN = 'POLLI_TOKEN'; diff --git a/src/pollinations-client.js b/src/pollinations-client.js index cbfcc5f..2b445c9 100644 --- a/src/pollinations-client.js +++ b/src/pollinations-client.js @@ -1,4 +1,4 @@ -import { PolliClient, DEFAULT_REFERRER } from '../Libs/pollilib/index.js'; +import { PolliClient, DEFAULT_REFERRER, DEFAULT_TOKEN } from '../Libs/pollilib/index.js'; let tokenPromise = null; let cachedResult = null; @@ -9,6 +9,10 @@ export async function createPollinationsClient({ referrer } = {}) { const inferredReferrer = referrer ?? inferReferrer() ?? DEFAULT_REFERRER; const clientOptions = {}; + if (inferredReferrer) { + clientOptions.referrer = inferredReferrer; + } + if (token) { clientOptions.auth = { mode: 'token', @@ -16,14 +20,12 @@ export async function createPollinationsClient({ referrer } = {}) { getToken: async () => token, referrer: inferredReferrer ?? undefined, }; - } else if (inferredReferrer) { - clientOptions.referrer = inferredReferrer; } const client = new PolliClient(clientOptions); return { client, - tokenSource: token ? source : null, + tokenSource: token ? source ?? null : null, tokenMessages: messages, tokenErrors: errors, }; @@ -81,6 +83,14 @@ async function resolveToken() { const messages = errors .map(entry => formatError(entry.source, entry.error)) .filter(Boolean); + if (DEFAULT_TOKEN) { + return { + token: DEFAULT_TOKEN, + source: 'default', + errors, + messages, + }; + } return { token: null, source: null, diff --git a/tests/pollilib-chat.test.mjs b/tests/pollilib-chat.test.mjs index fcbd0af..85cb288 100644 --- a/tests/pollilib-chat.test.mjs +++ b/tests/pollilib-chat.test.mjs @@ -61,6 +61,7 @@ export async function run() { assert.equal(defaultUrl.searchParams.get('model'), 'openai'); assert.equal(defaultUrl.searchParams.get('seed'), '12345678'); assert.equal(defaultUrl.searchParams.get('referer'), 'https://www.unityailab.com'); + assert.equal(defaultUrl.searchParams.get('token'), 'POLLI_TOKEN'); const defaultPayload = JSON.parse(requests[0].init.body); assert.equal(defaultPayload.model, 'openai'); assert.equal(defaultPayload.seed, '12345678'); @@ -90,6 +91,7 @@ export async function run() { assert.equal(seedUrl.searchParams.get('model'), 'unity'); assert.equal(seedUrl.searchParams.get('seed'), '12345678'); assert.equal(seedUrl.searchParams.get('referer'), 'https://www.unityailab.com'); + assert.equal(seedUrl.searchParams.get('token'), 'POLLI_TOKEN'); const parsedSeedBody = JSON.parse(requests[1].init.body); assert.equal(parsedSeedBody.model, 'unity'); assert.equal(parsedSeedBody.seed, '12345678'); diff --git a/tests/pollilib-text.test.mjs b/tests/pollilib-text.test.mjs index 7bed839..fa6d498 100644 --- a/tests/pollilib-text.test.mjs +++ b/tests/pollilib-text.test.mjs @@ -43,4 +43,20 @@ export async function run() { assert.equal(url.searchParams.get('model'), 'webgpt'); assert.equal(url.searchParams.get('seed'), '12345678'); assert.equal(url.searchParams.get('referer'), 'https://github.com/Unity-Lab-AI/chatdemo'); + + requests.length = 0; + const defaultClient = new PolliClient({ fetch: fakeFetch }); + const defaultPrompt = 'Hello Unity'; + await text(defaultPrompt, undefined, defaultClient); + + assert.equal(requests.length, 1, 'Default client should issue a single request'); + const defaultRequest = requests[0]; + assert.equal(defaultRequest.init.method, 'GET'); + const defaultUrl = new URL(defaultRequest.url); + assert.ok(defaultUrl.pathname.endsWith('/openai'), 'Default client should target /openai'); + assert.equal(defaultUrl.searchParams.get('input'), defaultPrompt); + assert.equal(defaultUrl.searchParams.get('model'), 'unity'); + assert.equal(defaultUrl.searchParams.get('seed'), '12345678'); + assert.equal(defaultUrl.searchParams.get('referer'), 'https://www.unityailab.com'); + assert.equal(defaultUrl.searchParams.get('token'), 'POLLI_TOKEN'); } diff --git a/tests/pollinations-token-optional.test.mjs b/tests/pollinations-token-optional.test.mjs index cec3265..0856d21 100644 --- a/tests/pollinations-token-optional.test.mjs +++ b/tests/pollinations-token-optional.test.mjs @@ -79,8 +79,10 @@ export async function run() { const { client, tokenSource, tokenMessages } = await createPollinationsClient(); - assert.equal(tokenSource, null); - assert.equal(client.authMode, 'referrer'); + assert.equal(tokenSource, 'default'); + assert.equal(client.authMode, 'token'); + assert.equal(await client._auth.getToken(), 'POLLI_TOKEN'); + assert.equal(client.tokenPlacement, 'query'); assert.equal(client.referrer, 'https://www.unityailab.com'); assert.ok(Array.isArray(tokenMessages)); assert.equal(tokenMessages.length, 0, `Unexpected messages: ${tokenMessages.join('; ')}`);