9.4 KiB
Custom Integrations
Use this document before changing non-generic provider/platform behavior. If a user request includes a custom keyword such as 元界, mozheAPI, or 智能配置 API, first check long-term memory and the relevant rows in the Codex docs, then verify the current source/runtime before editing.
Required Workflow
- Search existing long-term memory and this docs folder for the exact custom keyword.
- Read the matching feature, bug, API, or architecture entry before touching code.
- Treat custom provider/platform behavior as a named integration boundary, not as generic fallback logic.
- Preserve the provider-specific contract unless the user explicitly changes that contract.
- When a fix reveals a new reusable rule, update this file or the matching Codex doc in the same change set.
- If the rule is durable across future sessions, write it to long-term memory instead of relying only on chat context.
元界 AI
-
Start with
src/lib/yuanjie-image-model-templates.ts,src/lib/yuanjie-video-model-templates.ts,src/lib/yuanjie-template-installer.ts,src/lib/user-api-manifest-executor.ts, and the selected create panel. -
Built-in 元界 templates are not generic OpenAI-compatible models. Their manifests may map UI fields to provider-specific params such as
size,aspect_ratio,aspectRatio,imageSize,resolution,quality,images, or task polling fields. -
Built-in 元界 video media requests should stay in Manifest form and should not fall back to the generic OpenAI-compatible video parser.
/v1/media/generatesubmit bodies use onlymodel,prompt, andparams; HappyHorse text-to-video specifically sendsparams.resolution,params.ratio, andparams.duration, then readsoutput.task_idand polls/v1/media/status?task_id=.... -
Some image models expose orientation through a
size/resolutionvalue instead of a separate aspect-ratio field. In those cases the create panel must derive the ratio from the selected option label or pixel dimensions, rather than requiring the user to write the ratio in the prompt. -
元界 media submit responses may return the task identifier under nested result objects such as
result.task_id,result.taskId, orresult.id. The Manifest executor must extract task IDs from those nested objects before pollingv1/media/status. -
If 元界后台 shows a successful image but MiaoJing marks the job failed, treat it as a result-media download/persistence issue before changing submit/poll config. Check
src/app/api/generate/image/route.ts,src/lib/media-storage.ts, andsrc/lib/remote-fetch.tsfor 403, timeout, object-storage, or thumbnail errors. Result URL fetches should use browser-like headers plus limited retry, and Manifest result persistence failures should be reported as platform download/save failures, not as image-resolution mismatch. -
Do not add
自动back to controls where the user explicitly asked for explicit manual choices. Image count should default to1when automatic inference is not part of the requested workflow. -
Admin default models must use
system_api_configs.nameas the frontend display name, whilemodel_nameremains the upstream request model. -
When 元界 is used as a system default model, credit deduction must still follow the selected
system_api_configsrow's pricing through the generation job backend. New-job balance preflight should include same-user queued/running system-default jobs. Image and video create UI should display only the completed job's returnedcreditsCostand refresh the profile balance fromcreditsBalance, not a separate predicted button cost. Failed jobs must not write consume transactions. -
Yuanjie image and video templates that accept reference media should render provider-facing references with
$inputImages.urls, not$inputImages.dataUrls. The Manifest executor uploads data URL references into storage first, then exposes object/local-storage public URLs as$inputImages.urlswhile keeping raw data URLs available as$inputImages.dataUrlsfor multipart/file-upload manifests. -
Yuanjie GPT Image 2 / GPT Image 2 official-transfer image-to-image must pass all frontend references.
src/components/create/image-to-image.tsxsends the primary image asimageand additional references asextraImages;src/app/api/generate/image/route.tsmust normalize them into the ManifestinputImagesarray before callingsrc/lib/user-api-manifest-executor.ts. -
Yuanjie video templates must stay in
src/lib/yuanjie-video-model-templates.tsand map documented model-specific fields there instead of changing generic mozheAPI/custom-API request builders. Current documented special mappings includesora-2.params.input_reference,wan2.6-cankaosheng.params.reference_urls,wan2.6-shouzheng.params.img_url,kling-v3-omni-shouweizhen.params.image/image_tail,happyhorse-r2v.params.ratio,grok-video-3.params.size, andveo3.1.params.generation_mode/enhance_prompt/enable_upsample. -
Existing admin-created 元界 system rows may have an empty
manifest_pathand a submit endpoint inapi_url.src/lib/yuanjie-system-manifest.tsis responsible for exposing built-in frontend capabilities for those rows and repairing them at generation time by writing the missing Manifest and normalizingapi_urlto the 元界 base URL. This repair must remain scoped to 元界 provider/model-group checks and must not rewrite mozheAPI. -
元界价格/计费方式同步 is manual only. Admins trigger it from the
系统默认模型provider view; the route is/api/admin/system-apis/yuanjie-pricingand the logic lives insrc/lib/yuanjie-pricing-sync.ts. It updates only existing 元界 image/video rows, accepting provider spellings such as元界 AI/元界AIandyuanjie-*model groups, synchronizingbilling_modeand a元界计费同步price note from local built-in template metadata. It must not delete, create, or rewrite mozheAPI rows, generic smart-import rows, API keys, Manifest paths, or administrator-entered numeric prices.
Agnes AI
- Start with
src/lib/agnes-model-templates.ts,src/lib/agnes-template-installer.ts,src/app/api/admin/system-apis/agnes-capabilities/route.ts, andsrc/components/admin/api-management-tab.tsx. - Agnes built-in templates belong to the
系统默认模型management flow. Do not expose them as a generic智能配置 APIimport; keep one system API row per model and one independentsystem-api-manifests/<systemApiId>.jsonfile for each image/video row. - The API base is
https://apihub.agnes-ai.com. Image modelsagnes-image-2.1-flashandagnes-image-2.0-flashusePOST /v1/images/generationswithmodel,prompt,size, and optional top-levelimage: string[]for image-to-image. URL output must be requested asextra_body.response_format = "url"; do not putresponse_formatat the top level. Readdata.*.url, withdata.*.b64_jsonas a fallback. - Video model
agnes-video-v2.0usesPOST /v1/videosto create an async task andGET /agnesapi?video_id={video_id}&model_name=agnes-video-v2.0to poll. Treatvideo_id,task_id, oridas the task identifier,completedas success,failedas failure, and read the final video fromremixed_from_video_id,video_url, orurl. - Agnes Video duration is controlled by
num_frames, not adurationrequest field. The create route currently exposes only production-stable UI durations 3/5/10 seconds, maps them to the documented 24fps frame counts 81/121/241, and sendsframe_rate: 24. Do not re-enable 18 seconds from stale Manifests or older docs until production evidence shows Agnes no longer returns upstreamfailedfor that length; backend requests for 18 seconds should be rejected quickly with a clear user-facing message. - Agnes Video generation can spend minutes in the async task. Keep the Manifest total polling budget separate from per-request submit/poll timeouts, and treat single poll-side 502/503/504,
fetch failed, or network timeouts as transient until the total budget expires. - For image-to-video, Agnes uses the top-level
imagefield as the starting/first frame. Do not treat Agnes Video as a generic multi-reference video model unless Agnes adds a separate reference-image field. - Text/multimodal models
agnes-2.0-flashandagnes-1.5-flashuse OpenAI-compatiblePOST /v1/chat/completions; they do not need Manifest files and can be used by prompt optimization or reverse prompt through the existing system text API path. - The installer creates Agnes rows as inactive, 0-credit templates with empty API Key fields so admins can fill the Key in the existing system API edit form, review visibility/member scope, and then enable the model.
mozheAPI
- Start with
src/proxy.tsfor iframe/embed failures before changing page components. - Third-party embedding depends on CSP
frame-ancestorsandX-Frame-Options;SAMEORIGINblocks external parents even if app pages render correctly. - Keep the allowlist explicit. Do not globally weaken security headers for unrelated origins.
智能配置 API
- User-level manifests must stay one model/key row to one JSON Manifest file. Do not merge multiple request configs under one user-level shared file.
- Admin global default manifests can be shared through system API configuration, but generation must still resolve the selected model row and charge according to that model's pricing rules.
- Imported rows should preserve
manifest_path, provider/model display metadata, and per-model request templates.