feat: add NEAR AI inference provider#7883
Open
PierreLeGuen wants to merge 3 commits into
Open
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates to
No linked issue.
Risks
Low. This adds a new OpenAI-compatible inference provider plugin and wires it into existing provider discovery/configuration surfaces.
Background
What does this PR do?
Adds
@elizaos/plugin-nearaias a first-party NEAR AI Cloud TEE inference provider for text generation. The plugin uses the NEAR AI Cloud OpenAI-compatible endpoint, supportsTEXT_SMALLandTEXT_LARGE, and defaults to TEE-verifiable models from the public NEAR AI catalog.The change also wires NEAR AI into provider auto-enable, onboarding/provider switching, provider status, credential discovery, model catalog discovery, plugin registry metadata, and provider documentation.
What kind of change is this?
Features (non-breaking change which adds functionality)
Documentation changes needed?
Documentation has been updated in the model provider references.
Testing
Where should a reviewer start?
Start with
plugins/plugin-nearai, then review the provider wiring inpackages/agent/src/runtime/plugin-collector.ts, the onboarding catalog, andpackages/docs/model-providers.mdx.Detailed testing steps
bun run --cwd plugins/plugin-nearai lint:checkbun run --cwd plugins/plugin-nearai typecheckbun run --cwd plugins/plugin-nearai testbun run --cwd plugins/plugin-nearai buildbun run --cwd packages/agent test -- src/runtime/__tests__/plugin-collector-nearai.test.tsbun run --cwd packages/shared typecheckbun run --cwd packages/core typecheck./node_modules/.bin/biome check packages/core/src/contracts/onboarding.ts./node_modules/.bin/tsc --noEmit -p packages/core/tsconfig.jsonGreptile Summary
This PR introduces
@elizaos/plugin-nearai, a new first-party inference provider plugin that connects to NEAR AI Cloud's OpenAI-compatible API with TEE-verifiable model support. It follows the same structure as existing provider plugins and correctly wires NEAR AI into all relevant discovery, onboarding, credential resolution, routing policy, and provider-switching surfaces.index.ts,models/text.ts,providers/openai-compatible.ts) wraps the Vercel AI SDK'screateOpenAICompatibleclient and applies a fetch interceptor to strip/rename OpenAI-specific fields (max_completion_tokens,store,reasoning_effort,strict,developerrole) that the NEAR AI endpoint does not accept.zaiandmoonshotare integrated.Confidence Score: 5/5
This PR is safe to merge. It adds a self-contained new provider plugin with no changes to existing provider logic.
The plugin implementation is complete and correct: the fetch interceptor properly normalizes NEAR AI-incompatible OpenAI fields, API key gating is consistently enforced across all provider discovery surfaces, and wiring into onboarding, credential resolution, vault, routing policy, and plugin-collector all follow the established patterns of adjacent providers (zai, moonshot). The large refactor in onboarding.ts extracts repeated inline patterns into named helpers without changing behavior. The two findings are configuration completeness gaps that do not affect runtime behavior.
No files require special attention. The two comments on nearai.json and config-routes.ts are config-surface completeness suggestions that do not affect the plugin's runtime operation.
Important Files Changed
Sequence Diagram
sequenceDiagram participant Agent as Agent Runtime participant Plugin as plugin-nearai participant Fetch as NearAIRequestFetch (interceptor) participant SDK as Vercel AI SDK (generateText) participant API as NEAR AI Cloud API Agent->>Plugin: "useModel(TEXT_SMALL | TEXT_LARGE, params)" Plugin->>Plugin: resolveTextParams(params) Plugin->>Plugin: getSmallModel / getLargeModel (runtime settings) Plugin->>Plugin: "createNearAIClient(runtime, {fetch: wrapped})" Plugin->>SDK: "generateText({model, prompt, maxTokens, ...})" SDK->>Fetch: "fetch(url, {body: OpenAI JSON})" Fetch->>Fetch: strip max_completion_tokens to max_tokens Fetch->>Fetch: delete store, reasoning_effort, strict Fetch->>Fetch: remap role:developer to role:system Fetch->>API: POST /v1/chat/completions (cleaned body) API-->>Fetch: "{choices, usage}" Fetch-->>SDK: response SDK-->>Plugin: "{text, usage}" Plugin->>Agent: emitEvent(MODEL_USED, tokens) Plugin-->>Agent: text stringReviews (2): Last reviewed commit: "fix: tighten NEAR AI provider initializa..." | Re-trigger Greptile