[codex] Structure preview capability errors (#3454)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
23ab75e84a
commit
8d4a8b4f31
3 files changed
+62
-5
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import {
|
||||
EnvironmentId,
|
||||
PreviewAutomationUnavailableError,
|
||||
ProviderInstanceId,
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Effect from "effect/Effect";
|
||||
|
||||
import * as McpInvocationContext from "./McpInvocationContext.ts";
|
||||
|
||||
it.effect("reports the scoped credential context when preview capability is unavailable", () => {
|
||||
const invocation: McpInvocationContext.McpInvocationScope = {
|
||||
environmentId: EnvironmentId.make("environment-1"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
providerSessionId: "provider-session-1",
|
||||
providerInstanceId: ProviderInstanceId.make("codex"),
|
||||
capabilities: new Set(),
|
||||
issuedAt: 1,
|
||||
expiresAt: 2,
|
||||
};
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const error = yield* McpInvocationContext.requireMcpCapability("preview").pipe(
|
||||
Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
|
||||
Effect.flip,
|
||||
);
|
||||
|
||||
expect(error).toBeInstanceOf(PreviewAutomationUnavailableError);
|
||||
expect(error).toMatchObject({
|
||||
capability: "preview",
|
||||
environmentId: invocation.environmentId,
|
||||
threadId: invocation.threadId,
|
||||
providerSessionId: invocation.providerSessionId,
|
||||
providerInstanceId: invocation.providerInstanceId,
|
||||
});
|
||||
expect(error.message).toBe("MCP credential does not grant the preview capability.");
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,9 @@
|
||||
import type { EnvironmentId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
|
||||
import { PreviewAutomationUnavailableError } from "@t3tools/contracts";
|
||||
import {
|
||||
type EnvironmentId,
|
||||
PreviewAutomationUnavailableError,
|
||||
type ProviderInstanceId,
|
||||
type ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
|
||||
@@ -26,7 +30,11 @@ export const requireMcpCapability = Effect.fn("mcp.requireCapability")(function*
|
||||
const invocation = yield* McpInvocationContext;
|
||||
if (!invocation.capabilities.has(capability)) {
|
||||
return yield* new PreviewAutomationUnavailableError({
|
||||
message: `MCP credential does not grant the ${capability} capability.`,
|
||||
capability,
|
||||
environmentId: invocation.environmentId,
|
||||
threadId: invocation.threadId,
|
||||
providerSessionId: invocation.providerSessionId,
|
||||
providerInstanceId: invocation.providerInstanceId,
|
||||
});
|
||||
}
|
||||
return invocation;
|
||||
|
||||
@@ -453,8 +453,18 @@ export type PreviewAutomationResponse = typeof PreviewAutomationResponse.Type;
|
||||
|
||||
export class PreviewAutomationUnavailableError extends Schema.TaggedErrorClass<PreviewAutomationUnavailableError>()(
|
||||
"PreviewAutomationUnavailableError",
|
||||
{ message: Schema.String },
|
||||
) {}
|
||||
{
|
||||
capability: Schema.Literal("preview"),
|
||||
environmentId: EnvironmentId,
|
||||
threadId: ThreadId,
|
||||
providerSessionId: TrimmedNonEmptyString,
|
||||
providerInstanceId: ProviderInstanceId,
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `MCP credential does not grant the ${this.capability} capability.`;
|
||||
}
|
||||
}
|
||||
|
||||
const PreviewAutomationScopeErrorFields = {
|
||||
operation: PreviewAutomationOperation,
|
||||
|
||||
Reference in new issue
Block a user