sap-aicore 0.3.0: a new provider for SAP AI Core's GPT Responses and Claude Messages deployments (caikn, #651)

A new provider package, @magpie-community/opencode-sap-aicore-auth 0.3.0
(packages/sap-aicore). It signs in from a local SAP AI Core client-secret
credential file, discovers the account's running GPT (Responses) and Claude
(Messages, Bedrock) deployments per resource group, and sends requests only to
https://*.authentication.*.hana.ondemand.com (token) and
https://api.ai.*.hana.ondemand.com (inference). Image input is gated per model
on the catalog's inputTypes. Also: the root README row, a registry.json entry,
.DS_Store in .gitignore, and scripts/check.mjs accepts an empty static model
list for a package whose provider.models hook is a function with the same id
(npm and the loader are still required).

Reviewed at head b44b3e1b68889c2a12bcaa37ad5d546a398bdde0, with main 9bba5fed
merged in locally, on a Mac mini (macOS, Bun 1.4.2), no real SAP account:
- bun test packages/sap-aicore scripts: 351 pass, 0 fail.
- bun scripts/check.mjs: every package ok, sap-aicore included.
- The two tests that reached the network at e955194 now use inputs root()
  really rejects (/oauth, /v1), and a new test stubs fetch and checks that
  /oauth/token and /v2 are accepted and the token is posted to
  <authUrl>/oauth/token once. plugin.test.js fails on any unstubbed fetch.
- Whole package under a preload that records every non-loopback fetch, connect
  and DNS lookup: 0 attempts (the preload caught a deliberate fetch to
  example.invalid, so it does record).
- Broken by hand: putting the e955194 inputs back turns the test red through
  the new guard; making root() keep the given path turns the new
  /oauth/token + /v2 test red; letting root() accept any path turns 3 URL
  tests red.
- Not tried: a real SAP AI Core account (the author's run record covers one
  GPT and one Claude turn, plain and with a tool call; no image turn).

The first version goes out through the dist branch (npm doesn't have the name).
This commit is contained in:
caikn
2026-11-04 22:19:43 +08:00
committed by GitHub
parent 9bba5fedc2
commit 0daf0c7421
37 changed files with 10688 additions and 1 deletions
+4 -1
View File
@@ -83,7 +83,10 @@ for (const name of readdirSync(root)) {
if (p && !signInOnly && !usageOnly) {
needsLoader = true
servesModels = true
if (!p.npm || !p.models || !Object.keys(p.models).length) problems.push(`${fn.name}: config gives ${auth.provider} no npm or models`)
// Account-scoped catalogs may be empty before sign-in. Do not call
// their models hook here: this check must stay credential/network-free.
const dynamicModels = hooks.provider?.id === auth.provider && typeof hooks.provider.models === "function"
if (!p.npm || (!Object.keys(p.models ?? {}).length && !dynamicModels)) problems.push(`${fn.name}: config gives ${auth.provider} no npm or models`)
}
}
if ((needsLoader || auth.loader !== undefined) && typeof auth.loader !== "function") problems.push(`${fn.name}: auth.loader`)
+37
View File
@@ -61,6 +61,43 @@ test("check still requires loaders for providers, including providers with tools
}
})
test("check accepts account-scoped models without signing in or fetching them", () => {
const result = check(`export const Plugin = async () => ({
auth: {...${auth}, loader: async () => ({})},
config: async (cfg) => { cfg.provider.fixture = {npm: "@ai-sdk/openai", models: {}} },
provider: {id: "fixture", models() { throw new Error("must not ask for credentials") }}
})`, okRegistry,
{ main: "./index.mjs", exports: { ".": "./opencode2.mjs" }, files: ["index.mjs", "opencode.mjs", "opencode2.mjs"] },
{ "opencode.mjs": 'export { Plugin } from "./index.mjs"\n', "opencode2.mjs": adapter })
expect(result.code).toBe(0)
expect(result.output).toContain("✓ fixture")
})
test("check rejects missing, mismatched or non-callable account catalogs and still requires npm and a loader", () => {
for (const provider of ["undefined", '{id: "wrong", models() {}}', '{id: "fixture", models: {}}']) {
const result = check(`export const Plugin = async () => ({
auth: {...${auth}, loader: async () => ({})},
config: async (cfg) => { cfg.provider.fixture = {npm: "@ai-sdk/openai", models: {}} },
provider: ${provider}
})`)
expect(result.code).toBe(1)
expect(result.output).toContain("no npm or models")
}
for (const [npm, loader, problem] of [
['"@ai-sdk/openai"', "undefined", "auth.loader"],
["undefined", "async () => ({})", "no npm or models"],
]) {
const result = check(`export const Plugin = async () => ({
auth: {...${auth}, loader: ${loader}},
config: async (cfg) => { cfg.provider.fixture = {npm: ${npm}, models: {}} },
provider: {id: "fixture", models() {}}
})`)
expect(result.code).toBe(1)
expect(result.output).toContain(problem)
}
})
const fine = `export const Plugin = async () => ({ tool: ${tool} })`
test("check accepts quota-only providers with a loader and no model transport", () => {