Use AI Foundation SDK
Treat Halo AI Foundation as an independent SDK. Derive answers and code from its official
documentation and public contracts.
Do not trust memory
AI Foundation evolves independently of other AI libraries. Never write its API calls from memory
or translate a similarly named API from another SDK. Verify every public type, method, option,
event, and package export against the documentation and source for the version used by the target
project.
Use the closest version-matched evidence
Do not clone the repository by default. Use this evidence order:
- If the current workspace is already an AI Foundation source checkout containing
api/, dev/,
and ui/packages/sdk/, use it directly.
- Inspect the target project for its SDK versions:
- Java:
run.halo.aifoundation:api:<version> in Gradle files or version catalogs.
- Browser/Vue:
@halo-dev/ai-foundation-sdk in package.json and the active lockfile.
- Prefer dependencies already resolved in the target project:
- Read the Java source JAR from the Gradle module cache. If no source JAR exists, inspect public
signatures from the binary JAR.
- Read the npm package version, root exports, declaration files, and runtime files from
node_modules/@halo-dev/ai-foundation-sdk.
- Read references/local-artifacts.md for exact lookup commands.
- Use installed artifacts as the authority for the public contract of the installed version. They
may not include the developer guides, integration examples, or application implementation.
- Clone the official repository only when:
- The dependency is not installed locally.
- The installed artifacts do not answer the question.
- The task needs guides, examples, JavaDoc context absent from the artifact, or runtime
implementation details.
Prepare the repository only when needed
Reuse the workspace's existing directory for reference repositories. Otherwise, use
.reference/plugin-ai-foundation and exclude .reference/ locally, such as through
.git/info/exclude, so reference files are never committed to the consumer plugin.
Clone the official repository when the reference checkout is absent:
git clone --filter=blob:none \
https://github.com/halo-dev/plugin-ai-foundation.git \
.reference/plugin-ai-foundation
The remaining examples use this default path. Substitute the existing reference checkout path when
the workspace uses another convention.
Before using the checkout, refresh its branches and tags:
git -C .reference/plugin-ai-foundation fetch origin --tags --prune
Select the matching source:
For a released dependency <version>, verify that v<version> exists and check it out in
detached mode:
git -C .reference/plugin-ai-foundation \
show-ref --verify --quiet 'refs/tags/v<version>'
git -C .reference/plugin-ai-foundation checkout --detach 'v<version>'
For a snapshot, unreleased version, or missing tag, check out origin/main in detached mode and
explicitly say that the answer was checked against main:
git -C .reference/plugin-ai-foundation checkout --detach origin/main
Java and npm dependencies may use different versions. Verify each surface against its own
dependency version when both are involved; use git show <ref>:<path> when comparing files from
two refs without repeatedly switching the checkout.
If the repository cannot be cloned or refreshed, explain what could not be verified instead of
guessing.
Treat the reference checkout as read-only. Never stage its files with the consumer plugin's
changes.
When a source checkout is available, use references/sdk-map.md to locate
the relevant documentation and public source.
Follow the query workflow
- Identify the requested surface:
- Java backend SDK Core.
- Browser or Vue SDK UI.
- UI Message backend-to-frontend transport.
- FormKit
aiModelSelector.
- Halo plugin dependency and lifecycle integration.
- Choose
dev/zh-CN/ for Chinese output or dev/en/ for English output.
- Read the matching installed declaration/source or local path from the SDK map.
- Read only the task-relevant documentation or artifact files.
- Verify names, signatures, exports, and behavior against public source before writing code.
- For a complete consumer shape, read
dev/{locale}/plugin-integration-examples.md.
- Inspect the target plugin's existing Gradle,
plugin.yaml, settings, endpoint, and frontend
conventions before editing it.
Verify the public contract
- Treat
api/src/main/java/run/halo/aifoundation/ as the Java public contract.
- Treat exports from
ui/packages/sdk/src/index.ts as the npm public contract.
- Treat
ui/src/formkit/ai-model-selector-input.ts and
dev/{locale}/model-selector.md as the model selector contract.
- Do not infer public support from classes under
app/ or unexported Console UI components.
- Search the reference checkout with an available code index or
rg. Inspect exact public files
for declarations and use literal search for dependency coordinates, YAML fields, endpoint paths,
error codes, and package exports.
- Never invent a convenience method from another AI library. If a method is absent from the public
source, find the supported composition in the current API.
Integrate a Halo plugin
Apply these defaults unless the target plugin establishes a stronger convention:
- Add the Java API as
compileOnly; add it to tests separately when tests load SDK types.
- Declare
ai-foundation in spec.pluginDependencies.
- Use
ExtensionGetter.getEnabledExtension(AiModelService.class) across plugin
ApplicationContext boundaries.
- Store and pass
AiModel.metadata.name as modelName.
- Resolve the appropriate
LanguageModel, EmbeddingModel, RerankingModel, or
ImageGenerationModel through AiModelService.
- Register beans that reference AI Foundation types only when AI Foundation is available if the
dependency is optional.
- Use
aiModelSelector in Halo settings rather than importing the Console's internal Vue
component.
- Keep business concerns in the consumer plugin: authorization, rate limits, persistence, document
chunking, vector storage, attachment lifecycle, and user-facing error messages.
Preserve runtime contracts
- Keep Reactor composition non-blocking. Do not call
block() in request paths.
- Use either
prompt or messages; combine either with system when needed.
- Preserve
responseMessages for tool loops or continued model context.
- Consume
StreamTextResult projections according to the caller's need:
textStream(), fullStream(), partialOutputStream(), elementStream(), output(), or
result().
- Keep every assistant tool call paired with one tool result or error.
- Validate and convert UI messages through the Java UI Message APIs before model execution.
- Send the Halo UI Message stream headers and
[DONE] marker through
UIMessageStreamResponse.
- Persist final reduced UI messages, not arbitrary partial chunks.
- Treat model capabilities and provider warnings as runtime data; do not infer them from model
names.
Validate changes
Run checks proportional to the edited surface:
# Consumer Java plugin
./gradlew compileJava
./gradlew test
# AI Foundation Java API source checkout
./gradlew :api:compileJava
# AI Foundation npm SDK source checkout
cd ui
pnpm --filter @halo-dev/ai-foundation-sdk typecheck
pnpm --filter @halo-dev/ai-foundation-sdk test
Also run the target plugin's established frontend type check and tests when changing its UI.
Report with evidence
- Name the SDK version or repository ref used.
- Name the public types, exports, and documentation files used.
- Distinguish verified current behavior from consumer-specific policy.
- State which compile, type, or test checks ran.
- Present AI Foundation as an independent SDK and avoid cross-SDK parity framing.
1---2name: use-ai-foundation-sdk3description: Query, explain, integrate, and debug the Halo AI Foundation Java SDK, browser/Vue SDK, UI Message transport, and FormKit model selector. Use when an AI coding agent needs to answer AI Foundation API questions, add AI capabilities to a Halo plugin, implement text generation, structured output, tools, embeddings, reranking, RAG, image generation, streaming chat, message persistence, or model selection, or verify a consumer plugin against the official SDK contracts.4---56# Use AI Foundation SDK78Treat Halo AI Foundation as an independent SDK. Derive answers and code from its official9documentation and public contracts.1011## Do not trust memory1213AI Foundation evolves independently of other AI libraries. Never write its API calls from memory14or translate a similarly named API from another SDK. Verify every public type, method, option,15event, and package export against the documentation and source for the version used by the target16project.1718## Use the closest version-matched evidence1920Do not clone the repository by default. Use this evidence order:21221. If the current workspace is already an AI Foundation source checkout containing `api/`, `dev/`,23 and `ui/packages/sdk/`, use it directly.242. Inspect the target project for its SDK versions:25 - Java: `run.halo.aifoundation:api:<version>` in Gradle files or version catalogs.26 - Browser/Vue: `@halo-dev/ai-foundation-sdk` in `package.json` and the active lockfile.273. Prefer dependencies already resolved in the target project:28 - Read the Java source JAR from the Gradle module cache. If no source JAR exists, inspect public29 signatures from the binary JAR.30 - Read the npm package version, root exports, declaration files, and runtime files from31 `node_modules/@halo-dev/ai-foundation-sdk`.32 - Read [references/local-artifacts.md](references/local-artifacts.md) for exact lookup commands.334. Use installed artifacts as the authority for the public contract of the installed version. They34 may not include the developer guides, integration examples, or application implementation.355. Clone the official repository only when:36 - The dependency is not installed locally.37 - The installed artifacts do not answer the question.38 - The task needs guides, examples, JavaDoc context absent from the artifact, or runtime39 implementation details.4041## Prepare the repository only when needed4243Reuse the workspace's existing directory for reference repositories. Otherwise, use44`.reference/plugin-ai-foundation` and exclude `.reference/` locally, such as through45`.git/info/exclude`, so reference files are never committed to the consumer plugin.4647Clone the official repository when the reference checkout is absent:4849```bash50git clone --filter=blob:none \51 https://github.com/halo-dev/plugin-ai-foundation.git \52 .reference/plugin-ai-foundation53```5455The remaining examples use this default path. Substitute the existing reference checkout path when56the workspace uses another convention.5758Before using the checkout, refresh its branches and tags:5960```bash61git -C .reference/plugin-ai-foundation fetch origin --tags --prune62```6364Select the matching source:6566- For a released dependency `<version>`, verify that `v<version>` exists and check it out in67 detached mode:6869 ```bash70 git -C .reference/plugin-ai-foundation \71 show-ref --verify --quiet 'refs/tags/v<version>'72 git -C .reference/plugin-ai-foundation checkout --detach 'v<version>'73 ```7475- For a snapshot, unreleased version, or missing tag, check out `origin/main` in detached mode and76 explicitly say that the answer was checked against `main`:7778 ```bash79 git -C .reference/plugin-ai-foundation checkout --detach origin/main80 ```8182- Java and npm dependencies may use different versions. Verify each surface against its own83 dependency version when both are involved; use `git show <ref>:<path>` when comparing files from84 two refs without repeatedly switching the checkout.85- If the repository cannot be cloned or refreshed, explain what could not be verified instead of86 guessing.8788Treat the reference checkout as read-only. Never stage its files with the consumer plugin's89changes.9091When a source checkout is available, use [references/sdk-map.md](references/sdk-map.md) to locate92the relevant documentation and public source.9394## Follow the query workflow95961. Identify the requested surface:97 - Java backend SDK Core.98 - Browser or Vue SDK UI.99 - UI Message backend-to-frontend transport.100 - FormKit `aiModelSelector`.101 - Halo plugin dependency and lifecycle integration.1022. Choose `dev/zh-CN/` for Chinese output or `dev/en/` for English output.1033. Read the matching installed declaration/source or local path from the SDK map.1044. Read only the task-relevant documentation or artifact files.1055. Verify names, signatures, exports, and behavior against public source before writing code.1066. For a complete consumer shape, read `dev/{locale}/plugin-integration-examples.md`.1077. Inspect the target plugin's existing Gradle, `plugin.yaml`, settings, endpoint, and frontend108 conventions before editing it.109110## Verify the public contract111112- Treat `api/src/main/java/run/halo/aifoundation/` as the Java public contract.113- Treat exports from `ui/packages/sdk/src/index.ts` as the npm public contract.114- Treat `ui/src/formkit/ai-model-selector-input.ts` and115 `dev/{locale}/model-selector.md` as the model selector contract.116- Do not infer public support from classes under `app/` or unexported Console UI components.117- Search the reference checkout with an available code index or `rg`. Inspect exact public files118 for declarations and use literal search for dependency coordinates, YAML fields, endpoint paths,119 error codes, and package exports.120- Never invent a convenience method from another AI library. If a method is absent from the public121 source, find the supported composition in the current API.122123## Integrate a Halo plugin124125Apply these defaults unless the target plugin establishes a stronger convention:126127- Add the Java API as `compileOnly`; add it to tests separately when tests load SDK types.128- Declare `ai-foundation` in `spec.pluginDependencies`.129- Use `ExtensionGetter.getEnabledExtension(AiModelService.class)` across plugin130 `ApplicationContext` boundaries.131- Store and pass `AiModel.metadata.name` as `modelName`.132- Resolve the appropriate `LanguageModel`, `EmbeddingModel`, `RerankingModel`, or133 `ImageGenerationModel` through `AiModelService`.134- Register beans that reference AI Foundation types only when AI Foundation is available if the135 dependency is optional.136- Use `aiModelSelector` in Halo settings rather than importing the Console's internal Vue137 component.138- Keep business concerns in the consumer plugin: authorization, rate limits, persistence, document139 chunking, vector storage, attachment lifecycle, and user-facing error messages.140141## Preserve runtime contracts142143- Keep Reactor composition non-blocking. Do not call `block()` in request paths.144- Use either `prompt` or `messages`; combine either with `system` when needed.145- Preserve `responseMessages` for tool loops or continued model context.146- Consume `StreamTextResult` projections according to the caller's need:147 `textStream()`, `fullStream()`, `partialOutputStream()`, `elementStream()`, `output()`, or148 `result()`.149- Keep every assistant tool call paired with one tool result or error.150- Validate and convert UI messages through the Java UI Message APIs before model execution.151- Send the Halo UI Message stream headers and `[DONE]` marker through152 `UIMessageStreamResponse`.153- Persist final reduced UI messages, not arbitrary partial chunks.154- Treat model capabilities and provider warnings as runtime data; do not infer them from model155 names.156157## Validate changes158159Run checks proportional to the edited surface:160161```bash162# Consumer Java plugin163./gradlew compileJava164./gradlew test165166# AI Foundation Java API source checkout167./gradlew :api:compileJava168169# AI Foundation npm SDK source checkout170cd ui171pnpm --filter @halo-dev/ai-foundation-sdk typecheck172pnpm --filter @halo-dev/ai-foundation-sdk test173```174175Also run the target plugin's established frontend type check and tests when changing its UI.176177## Report with evidence178179- Name the SDK version or repository ref used.180- Name the public types, exports, and documentation files used.181- Distinguish verified current behavior from consumer-specific policy.182- State which compile, type, or test checks ran.183- Present AI Foundation as an independent SDK and avoid cross-SDK parity framing.