Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/allow-public-expert-without-api-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@perstack/runtime": patch
"@perstack/installer": patch
"perstack": patch
---

Allow resolving public experts without PERSTACK_API_KEY. Public experts on the Perstack API do not require authentication.
6 changes: 1 addition & 5 deletions packages/installer/src/expert-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,9 @@ export async function resolveAllExperts(
if (toResolve.size === 0) {
return experts
}
const apiKey = env.PERSTACK_API_KEY
if (!apiKey) {
throw new PerstackError("PERSTACK_API_KEY is required to resolve remote delegates")
}
const client = createApiClient({
baseUrl: config.perstackApiBaseUrl ?? defaultPerstackApiBaseUrl,
apiKey,
apiKey: env.PERSTACK_API_KEY ?? "",
})
while (toResolve.size > 0) {
const delegateKey = toResolve.values().next().value
Expand Down
11 changes: 5 additions & 6 deletions packages/runtime/src/helpers/resolve-expert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@ describe("@perstack/runtime: resolveExpertToRun", () => {
expect(experts["remote-expert"]).toBeUndefined()
})

it("throws error when API key is not provided for published expert", async () => {
it("fetches public expert from API without API key", async () => {
const experts: Record<string, Expert> = {}
await expect(
resolveExpertToRun("published-expert", experts, {
perstackApiBaseUrl: "https://api.test.com",
}),
).rejects.toThrow('PERSTACK_API_KEY is required to resolve published expert "published-expert"')
const result = await resolveExpertToRun("published-expert", experts, {
perstackApiBaseUrl: "https://api.test.com",
})
expect(result.key).toBe("published-expert")
})
})
7 changes: 1 addition & 6 deletions packages/runtime/src/helpers/resolve-expert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ export async function resolveExpertToRun(
if (experts[expertKey]) {
return experts[expertKey]
}
if (!clientOptions.perstackApiKey) {
throw new PerstackError(
`PERSTACK_API_KEY is required to resolve published expert "${expertKey}"`,
)
}
const client = createApiClient({
baseUrl: clientOptions.perstackApiBaseUrl,
apiKey: clientOptions.perstackApiKey,
apiKey: clientOptions.perstackApiKey ?? "",
})
const result = await client.experts.get(expertKey)
if (!result.ok) {
Expand Down