From cdf9a1935d0549ca487665b4b283d50a87e4e4ef Mon Sep 17 00:00:00 2001
From: Samuel Colvin
Date: Sun, 22 Dec 2024 14:00:50 +0000
Subject: [PATCH 01/10] add warning about being ahead of release
---
docs/.partials/index-header.html | 7 +++++
docs/_worker.js | 45 ++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
create mode 100644 docs/_worker.js
diff --git a/docs/.partials/index-header.html b/docs/.partials/index-header.html
index 8da53b01..dc454437 100644
--- a/docs/.partials/index-header.html
+++ b/docs/.partials/index-header.html
@@ -25,6 +25,13 @@
+
+
+
PydanticAI is a Python agent framework designed to make it less painful to
build production grade applications with Generative AI.
diff --git a/docs/_worker.js b/docs/_worker.js
new file mode 100644
index 00000000..d9aba904
--- /dev/null
+++ b/docs/_worker.js
@@ -0,0 +1,45 @@
+export default {
+ async fetch(request, env) {
+ const url = new URL(request.url)
+ if (url.pathname === '/env.json') {
+ const headers = new Headers({'Content-Type': 'application/json'})
+ return new Response(JSON.stringify(env), { headers })
+ }
+ if (url.pathname === '/ahead-warning.html') {
+ try {
+ const html = await aheadOfRelease()
+ return new Response(html, { headers: {'Content-Type': 'text/html'} })
+ } catch (e) {
+ console.error(e)
+ return new Response(
+ `Error getting ahead HTML: ${e}`,
+ { status: 500, headers: {'Content-Type': 'text/plain'} }
+ )
+ }
+ } else {
+ return env.ASSETS.fetch(request)
+ }
+ },
+}
+
+async function aheadOfRelease() {
+ const r1 = await fetch('https://api.github.com/repos/pydantic/pydantic-ai/releases/latest')
+ if (!r1.ok) {
+ throw new Error(`Failed to fetch latest release, response status ${r.status}`)
+ }
+ const {tag_name} = await r1.json()
+ const r2 = await fetch(`https://api.github.com/repos/pydantic/pydantic-ai/compare/${tag_name}...main`)
+ if (!r2.ok) {
+ throw new Error(`Failed to fetch compare, response status ${r.status}`)
+ }
+ const {ahead_by} = await r2.json()
+
+ return `
+
Warning
+
These docs are ahead of the latest release by ${ahead_by} commits.
+
+ You may see documentation for features not yet supported in the
+ latest release.
+
+
`
+}
From 332da06e39b02ff29370255036dd6354acd5fa2b Mon Sep 17 00:00:00 2001
From: Samuel Colvin
Date: Sun, 22 Dec 2024 14:04:47 +0000
Subject: [PATCH 02/10] use head
---
docs/_worker.js | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/docs/_worker.js b/docs/_worker.js
index d9aba904..71bd7b13 100644
--- a/docs/_worker.js
+++ b/docs/_worker.js
@@ -1,13 +1,13 @@
export default {
async fetch(request, env) {
const url = new URL(request.url)
- if (url.pathname === '/env.json') {
- const headers = new Headers({'Content-Type': 'application/json'})
- return new Response(JSON.stringify(env), { headers })
- }
+ // if (url.pathname === '/env.json') {
+ // const headers = new Headers({'Content-Type': 'application/json'})
+ // return new Response(JSON.stringify(env), { headers })
+ // }
if (url.pathname === '/ahead-warning.html') {
try {
- const html = await aheadOfRelease()
+ const html = await aheadOfRelease(env)
return new Response(html, { headers: {'Content-Type': 'text/html'} })
} catch (e) {
console.error(e)
@@ -22,13 +22,14 @@ export default {
},
}
-async function aheadOfRelease() {
+async function aheadOfRelease(env) {
const r1 = await fetch('https://api.github.com/repos/pydantic/pydantic-ai/releases/latest')
if (!r1.ok) {
throw new Error(`Failed to fetch latest release, response status ${r.status}`)
}
const {tag_name} = await r1.json()
- const r2 = await fetch(`https://api.github.com/repos/pydantic/pydantic-ai/compare/${tag_name}...main`)
+ const head = env.CF_PAGES_COMMIT_SHA
+ const r2 = await fetch(`https://api.github.com/repos/pydantic/pydantic-ai/compare/${tag_name}...${head}`)
if (!r2.ok) {
throw new Error(`Failed to fetch compare, response status ${r.status}`)
}
From 223c94ef710adf06b2a17c80aa15c0172f578cb3 Mon Sep 17 00:00:00 2001
From: Samuel Colvin
Date: Sun, 22 Dec 2024 14:07:53 +0000
Subject: [PATCH 03/10] better error message
---
docs/_worker.js | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/docs/_worker.js b/docs/_worker.js
index 71bd7b13..889ff601 100644
--- a/docs/_worker.js
+++ b/docs/_worker.js
@@ -1,10 +1,6 @@
export default {
async fetch(request, env) {
const url = new URL(request.url)
- // if (url.pathname === '/env.json') {
- // const headers = new Headers({'Content-Type': 'application/json'})
- // return new Response(JSON.stringify(env), { headers })
- // }
if (url.pathname === '/ahead-warning.html') {
try {
const html = await aheadOfRelease(env)
@@ -22,16 +18,20 @@ export default {
},
}
+// env looks like
+// {"ASSETS":{},"CF_PAGES":"1","CF_PAGES_BRANCH":"ahead-warning","CF_PAGES_COMMIT_SHA":"...","CF_PAGES_URL":"https://..."}
async function aheadOfRelease(env) {
const r1 = await fetch('https://api.github.com/repos/pydantic/pydantic-ai/releases/latest')
if (!r1.ok) {
- throw new Error(`Failed to fetch latest release, response status ${r.status}`)
+ const text = await r1.text()
+ throw new Error(`Failed to fetch latest release, response status ${r1.status}:\n${text}`)
}
const {tag_name} = await r1.json()
const head = env.CF_PAGES_COMMIT_SHA
const r2 = await fetch(`https://api.github.com/repos/pydantic/pydantic-ai/compare/${tag_name}...${head}`)
if (!r2.ok) {
- throw new Error(`Failed to fetch compare, response status ${r.status}`)
+ const text = await r2.text()
+ throw new Error(`Failed to fetch compare, response status ${r2.status}:\n${text}`)
}
const {ahead_by} = await r2.json()
From 463258b9e719e6bac44239ef1514465a633aa0b7 Mon Sep 17 00:00:00 2001
From: Samuel Colvin
Date: Sun, 22 Dec 2024 14:13:15 +0000
Subject: [PATCH 04/10] add headers better error behaviour
---
docs/.partials/index-header.html | 8 ++++++--
docs/_worker.js | 8 ++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/docs/.partials/index-header.html b/docs/.partials/index-header.html
index dc454437..877dc15b 100644
--- a/docs/.partials/index-header.html
+++ b/docs/.partials/index-header.html
@@ -27,8 +27,12 @@
diff --git a/docs/_worker.js b/docs/_worker.js
index 889ff601..ac4ca030 100644
--- a/docs/_worker.js
+++ b/docs/_worker.js
@@ -21,14 +21,18 @@ export default {
// env looks like
// {"ASSETS":{},"CF_PAGES":"1","CF_PAGES_BRANCH":"ahead-warning","CF_PAGES_COMMIT_SHA":"...","CF_PAGES_URL":"https://..."}
async function aheadOfRelease(env) {
- const r1 = await fetch('https://api.github.com/repos/pydantic/pydantic-ai/releases/latest')
+ const headers = new Headers({
+ 'User-Agent': 'pydantic-ai-docs',
+ 'Accept': 'application/vnd.github.v3+json',
+ })
+ const r1 = await fetch('https://api.github.com/repos/pydantic/pydantic-ai/releases/latest', {headers})
if (!r1.ok) {
const text = await r1.text()
throw new Error(`Failed to fetch latest release, response status ${r1.status}:\n${text}`)
}
const {tag_name} = await r1.json()
const head = env.CF_PAGES_COMMIT_SHA
- const r2 = await fetch(`https://api.github.com/repos/pydantic/pydantic-ai/compare/${tag_name}...${head}`)
+ const r2 = await fetch(`https://api.github.com/repos/pydantic/pydantic-ai/compare/${tag_name}...${head}`, {headers})
if (!r2.ok) {
const text = await r2.text()
throw new Error(`Failed to fetch compare, response status ${r2.status}:\n${text}`)
From 2c8214268aae58ddc6d29548bf328803585800dc Mon Sep 17 00:00:00 2001
From: Samuel Colvin
Date: Sun, 22 Dec 2024 14:29:46 +0000
Subject: [PATCH 05/10] rename, fix logic
---
docs/.partials/index-header.html | 6 +++---
docs/_worker.js | 36 +++++++++++++++++++++++---------
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/docs/.partials/index-header.html b/docs/.partials/index-header.html
index 877dc15b..5bbddb63 100644
--- a/docs/.partials/index-header.html
+++ b/docs/.partials/index-header.html
@@ -25,11 +25,11 @@
-
+
-
PydanticAI is a Python agent framework designed to make it less painful to
build production grade applications with Generative AI.
diff --git a/docs/_worker.js b/docs/_worker.js
index 7c3bca0a..0156fce3 100644
--- a/docs/_worker.js
+++ b/docs/_worker.js
@@ -42,10 +42,7 @@ async function versionWarning(request, env) {
const {ahead_by} = await r2.json()
if (ahead_by === 0) {
- return `
-
Version
-
Showing documentation for the latest release ${name}.
-
`
+ return ''
}
return `
diff --git a/mkdocs.yml b/mkdocs.yml
index 0f5ba1b2..5d603a6e 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -57,7 +57,7 @@ extra:
theme:
name: "material"
- custom_dir: docs/overrides
+ custom_dir: docs/.overrides
palette:
- media: "(prefers-color-scheme)"
scheme: default
@@ -105,7 +105,7 @@ validation:
anchors: warn
extra_css:
- - 'extra/tweaks.css'
+ - "extra/tweaks.css"
# used for analytics
extra_javascript:
- "/flarelytics/client.js"
From a487d3023ad368bf9271d7d959dc32cc70a7f86c Mon Sep 17 00:00:00 2001
From: Samuel Colvin
Date: Sun, 22 Dec 2024 14:52:24 +0000
Subject: [PATCH 08/10] add main override
---
docs/.overrides/main.html | 14 ++++++++++++++
1 file changed, 14 insertions(+)
create mode 100644 docs/.overrides/main.html
diff --git a/docs/.overrides/main.html b/docs/.overrides/main.html
new file mode 100644
index 00000000..97fefa83
--- /dev/null
+++ b/docs/.overrides/main.html
@@ -0,0 +1,14 @@
+{% extends "base.html" %}
+{% block content %}
+
+
+ {{ super() }}
+{% endblock %}
From bf44b3b8d3d5fae4215c19252cc6f76dbe3f7d21 Mon Sep 17 00:00:00 2001
From: Samuel Colvin
Date: Sun, 22 Dec 2024 14:54:56 +0000
Subject: [PATCH 09/10] change wording
---
docs/_worker.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/_worker.js b/docs/_worker.js
index 0156fce3..89ea2a01 100644
--- a/docs/_worker.js
+++ b/docs/_worker.js
@@ -19,7 +19,7 @@ export default {
}
// env looks like
-// {"ASSETS":{},"CF_PAGES":"1","CF_PAGES_BRANCH":"ahead-warning","CF_PAGES_COMMIT_SHA":"...","CF_PAGES_URL":"https://..."}
+// {"CF_PAGES":"1","CF_PAGES_BRANCH":"ahead-warning","CF_PAGES_COMMIT_SHA":"...","CF_PAGES_URL":"https://..."}
async function versionWarning(request, env) {
const headers = new Headers({
'User-Agent': request.headers.get('User-Agent') || 'pydantic-ai-docs',
@@ -45,8 +45,8 @@ async function versionWarning(request, env) {
return ''
}
- return `
-
Notice
+ return `
+
Version Notice
${env.CF_PAGES_BRANCH === 'main' ? '' : `(${env.CF_PAGES_BRANCH} preview)`}
This documentation is ahead of the latest release by ${ahead_by} commit${ahead_by === 1 ? '' : 's'}.
From bcb9ff3e99db6dbf6fa205db3e3cc2a07c73072e Mon Sep 17 00:00:00 2001
From: Samuel Colvin
Date: Sun, 22 Dec 2024 15:02:56 +0000
Subject: [PATCH 10/10] fixed height
---
docs/.overrides/main.html | 2 +-
docs/_worker.js | 10 ++++++++--
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/docs/.overrides/main.html b/docs/.overrides/main.html
index 97fefa83..eb833f1c 100644
--- a/docs/.overrides/main.html
+++ b/docs/.overrides/main.html
@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% block content %}
-
+