Skip to content

Fix schema mismatch in @effect/ai-anthropic citations field #5105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
2 changes: 2 additions & 0 deletions packages/ai/anthropic/scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env sh
mkdir -p tmp
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
anthropic_stats_url="https://raw.githubusercontent.com/anthropics/anthropic-sdk-typescript/refs/heads/main/.stats.yml"
openapi_spec_url=$(curl -sSL $anthropic_stats_url | yq '.openapi_spec_url')
curl $openapi_spec_url > tmp/anthropic.yaml
Expand All @@ -8,3 +9,4 @@ echo "/**
*/" > src/Generated.ts
pnpm openapi-gen -s tmp/anthropic.yaml >> src/Generated.ts
pnpm eslint --fix src/Generated.ts
git apply $SCRIPT_DIR/response-text-block.patch
74 changes: 74 additions & 0 deletions packages/ai/anthropic/scripts/response-text-block.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
diff --git a/packages/ai/anthropic/src/Generated.ts b/packages/ai/anthropic/src/Generated.ts
index 1234567..abcdefg 100644
--- a/packages/ai/anthropic/src/Generated.ts
+++ b/packages/ai/anthropic/src/Generated.ts
@@ -472,15 +472,20 @@ export class ResponseTextBlockType extends S.Literal("text") {}

export class ResponseTextBlock extends S.Struct({
- "citations": S.NullOr(
- S.Union(
- S.Array(
- S.Union(
- ResponseCharLocationCitation,
- ResponsePageLocationCitation,
- ResponseContentBlockLocationCitation,
- ResponseWebSearchResultLocationCitation
- )
- ),
- S.Null
- )
- ),
+ // TODO: change this once the following upstream issue has been closed
+ // https://github.com/anthropics/anthropic-sdk-typescript/issues/605
+ "citations": S.optionalWith(
+ S.Union(
+ S.Array(
+ S.Union(
+ ResponseCharLocationCitation,
+ ResponsePageLocationCitation,
+ ResponseContentBlockLocationCitation,
+ ResponseWebSearchResultLocationCitation
+ )
+ ),
+ S.Null
+ ),
+ { nullable: true }
+ ),
"text": S.String.pipe(S.minLength(0), S.maxLength(5000000)),
"type": ResponseTextBlockType
}) {}
@@ -1508,15 +1513,20 @@ export class BetaResponseTextBlockType extends S.Literal("text") {}

export class BetaResponseTextBlock extends S.Struct({
- "citations": S.NullOr(
- S.Union(
- S.Array(
- S.Union(
- BetaResponseCharLocationCitation,
- BetaResponsePageLocationCitation,
- BetaResponseContentBlockLocationCitation,
- BetaResponseWebSearchResultLocationCitation
- )
- ),
- S.Null
- )
- ),
+ // TODO: change this once the following upstream issue has been closed
+ // https://github.com/anthropics/anthropic-sdk-typescript/issues/605
+ "citations": S.optionalWith(
+ S.Union(
+ S.Array(
+ S.Union(
+ BetaResponseCharLocationCitation,
+ BetaResponsePageLocationCitation,
+ BetaResponseContentBlockLocationCitation,
+ BetaResponseWebSearchResultLocationCitation
+ )
+ ),
+ S.Null
+ ),
+ { nullable: true }
+ ),
"text": S.String.pipe(S.minLength(0), S.maxLength(5000000)),
"type": BetaResponseTextBlockType
}) {}
14 changes: 10 additions & 4 deletions packages/ai/anthropic/src/Generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ export class ResponseWebSearchResultLocationCitation extends S.Struct({
export class ResponseTextBlockType extends S.Literal("text") {}

export class ResponseTextBlock extends S.Struct({
"citations": S.NullOr(
// TODO: change this once the following upstream issue has been closed
// https://github.com/anthropics/anthropic-sdk-typescript/issues/605
"citations": S.optionalWith(
S.Union(
S.Array(
S.Union(
Expand All @@ -483,7 +485,8 @@ export class ResponseTextBlock extends S.Struct({
)
),
S.Null
)
),
{ nullable: true }
),
"text": S.String.pipe(S.minLength(0), S.maxLength(5000000)),
"type": ResponseTextBlockType
Expand Down Expand Up @@ -1505,7 +1508,9 @@ export class BetaResponseWebSearchResultLocationCitation extends S.Struct({
export class BetaResponseTextBlockType extends S.Literal("text") {}

export class BetaResponseTextBlock extends S.Struct({
"citations": S.NullOr(
// TODO: change this once the following upstream issue has been closed
// https://github.com/anthropics/anthropic-sdk-typescript/issues/605
"citations": S.optionalWith(
S.Union(
S.Array(
S.Union(
Expand All @@ -1516,7 +1521,8 @@ export class BetaResponseTextBlock extends S.Struct({
)
),
S.Null
)
),
{ nullable: true }
),
"text": S.String.pipe(S.minLength(0), S.maxLength(5000000)),
"type": BetaResponseTextBlockType
Expand Down