|
1 | 1 | # Phase 0 leftovers (Python) |
2 | 2 |
|
3 | | -Everything in the Phase 0 scope (`py-prompt.md`, opus-plan.md §6 "Phase 0 — Foundation", |
4 | | -§3.2–3.4, §3.7) landed. A few items are deliberately smaller than the plan's framing, or |
5 | | -were already true on the Python side without a code change — documented here rather than |
6 | | -silently shipped (or silently skipped) without explanation, mirroring the TypeScript |
7 | | -SDK's own `PHASE0_LEFTOVERS.md` on this branch. |
| 3 | +Everything in the Phase 0 scope landed. This file records the items that are |
| 4 | +deliberately smaller than the original plan's framing, and how each was resolved |
| 5 | +under the reduced-scope coverage plan (`sdk-reduced/plan.md`). It mirrors the |
| 6 | +TypeScript SDK's own `PHASE0_LEFTOVERS.md`. |
8 | 7 |
|
9 | | -## 1. No literal "endpoint registry" data structure |
| 8 | +## 1. Literal "endpoint registry" data structure: won't do |
10 | 9 |
|
11 | | -opus-plan §3.2/§6 0.1 frames the per-host base URLs as part of "an endpoint registry + |
12 | | -per-host base URLs." What landed is the per-host base URL resolution |
13 | | -(`api_base`/`kg_base`/`llm_base`/`nlp_base`, old `*_url` options winning aliases) directly |
14 | | -in `client.py` — there's no separate data structure mapping `(operation) -> {path, |
15 | | -auth_style, retryable}`. |
| 10 | +The original plan framed per-host base URLs as part of "an endpoint registry". |
| 11 | +What landed is per-host base URL resolution (`api_base`/`kg_base`/`llm_base`/ |
| 12 | +`nlp_base`, with the older `*_url` options winning) directly in `client.py`, plus |
| 13 | +an ad hoc `retryable=False` at the one call site that needs it |
| 14 | +(`crawl_delete_job`). The reduced-scope plan adds no new API areas, so a |
| 15 | +per-operation table would never get a second consumer. **Won't do.** |
16 | 16 |
|
17 | | -This mirrors the TypeScript SDK's same call on this branch: Phase 0 adds zero new |
18 | | -endpoints, so the only thing a registry would currently serve is base-URL resolution |
19 | | -(done) and a `retryable` flag (done ad hoc, as an explicit `retryable=False` at the one |
20 | | -call site that needs it — `crawl_delete_job`/`crawl_delete_job_async`). Building a |
21 | | -generic per-operation table with no second or third consumer risked guessing the wrong |
22 | | -shape for Phase 1+ (Account, Enhance, Bulk, Custom API, ...), which is where a real |
23 | | -registry starts paying for itself. Revisit when Phase 1 lands. |
| 17 | +## 2. Success-path response headers: won't do (DQL reports cut) |
24 | 18 |
|
25 | | -## 2. Response headers: error path only, not success path |
26 | | - |
27 | | -opus-plan §6 0.6 asks for "response headers surfaced to callers," calling out an |
28 | | -`include_headers` option or a `*_raw` variant returning `(body, headers)`. |
29 | | - |
30 | | -What landed: every error response's headers are attached to `APIError` (and its |
31 | | -subclasses `AuthError`, `NotFoundError`, `RateLimitError`, `JobError`) via a new |
32 | | -`headers` field, populated in `_transport.raise_for_status()`. Tested in |
33 | | -`tests/test_transport.py`'s `raise_for_status` tests. |
34 | | - |
35 | | -What didn't land: a generic opt-in mechanism for a *successful* response's headers. The |
36 | | -plan's own stated motivation is `X-Diffbot-CoverageReportId` on a DQL coverage report |
37 | | -(opus-plan §3.4, §6 0.6's "prerequisite for DQL coverage reports") — that's a Phase 6 |
38 | | -operation (`dql_report`) that doesn't exist yet. Building the success-path mechanism now, |
39 | | -with no real caller to shape it against, risked the same guessing problem as the |
40 | | -registry above. Build it alongside `dql_report`/`dql_report_by_id` in Phase 6. Matches |
41 | | -the TypeScript SDK's identical call on this branch. |
| 19 | +Every *error* response's headers are attached to `APIError` (and subclasses) via |
| 20 | +`headers`, populated in `_transport.raise_for_status()`. A generic opt-in for a |
| 21 | +*successful* response's headers was only motivated by DQL coverage reports |
| 22 | +(`X-Diffbot-CoverageReportId`), which are out of scope. **Won't do.** |
42 | 23 |
|
43 | 24 | ## 3. `dql(raw=True)` binary correctness: no bug existed on the Python side |
44 | 25 |
|
45 | | -opus-plan §3.3/§6 0.5 frames this as "binary + text response reads" plus a concrete bug: |
46 | | -the TypeScript SDK's `dql()` read the body as text and re-encoded it with |
47 | | -`TextEncoder`, corrupting `xls`/`xlsx` exports. The audit explicitly notes Python's byte |
48 | | -path was already correct (`kg.py` returning `response.content` directly). No code change |
49 | | -was needed here beyond routing the call through the shared `client.request()` helper, |
50 | | -which preserves the same `response.content` / `response.json()` split. Covered by the |
51 | | -existing `test_dql.py` raw-mode tests (unchanged) plus the new per-host-base tests. |
52 | | - |
53 | | -## 4. Ontology asymmetries are Phase 1, not Phase 0 |
54 | | - |
55 | | -opus-plan §5.2's core-surface-mapping row for the ontology endpoint lists adding |
56 | | -`dql_fetch_ontology_text()` and `dql_refresh_ontology_async()` to close the existing |
57 | | -Python/TypeScript asymmetry (`dql_refresh_ontology` has no async twin; TypeScript has no |
58 | | -raw-text fetch). That row is scoped under "Phase 1 — Account + token verification," not |
59 | | -Phase 0, and the `py-prompt.md` Phase 0 scope list does not mention it. Left alone. |
60 | | - |
61 | | -## 5. TypedDict/Literal annotations: existing-surface request parameters only |
62 | | - |
63 | | -`py-prompt.md` asks for "matching TypedDict(total=False)/Literal annotations, additive, |
64 | | -no Pydantic" as the Python counterpart to the TypeScript SDK's much larger Phase 0 type |
65 | | -safety push (vendored OpenAPI, generated response schemas, per-handler overloads). The |
66 | | -typesafety-revision page's override on this point is specifically about TypeScript's |
67 | | -approach; opus-plan's own phasing (§6, Phase 7 "typed responses... land as a dedicated |
68 | | -minor, not bundled with each endpoint" — the risk being a `TypedDict` claiming a field |
69 | | -that a future server response omits) argues for keeping Python's response shapes as |
70 | | -plain `dict`/`bytes` for now, which is what shipped. |
71 | | - |
72 | | -What landed: `src/diffbot/types.py` adds `ChatMessage`, `ResponseFormatType`, |
73 | | -`ResponseFormat`, `ExportFormat`, `SnippetLength`, and `CrawlJobStatusCode` (the last |
74 | | -documents the numeric status codes `crawl.py` already branches on; not yet wired into a |
75 | | -public signature since no handler takes a status code as an input). These are wired into |
76 | | -the existing `ask()`/`ask_json()`/`dql()`/`web_search()` request-parameter signatures in |
77 | | -both `client.py` and the handler modules — purely additive, no runtime behavior change |
78 | | -(verified by the full test suite staying green before and after). |
| 26 | +The TypeScript SDK corrupted `xls`/`xlsx` exports by re-encoding text. Python's |
| 27 | +byte path (`response.content`) was already correct; no code change was needed. |
| 28 | +Unchanged by the move to POST. Covered by the existing raw-mode tests. |
79 | 29 |
|
80 | | -What didn't land: `TypedDict` overlays for *response* shapes (`DqlResponse`, |
81 | | -`WebSearchResponse`, `NlpResponse`, `ExtractResponse`, a `CrawlJob`/`JobStatus` pair, |
82 | | -`Ontology`'s wire format). This repo has no mypy/type-checking gate in CI today (checked |
83 | | -`.github/workflows/tests.yml`), so there is no second consumer to shape these against |
84 | | -yet, and retrofitting them risks exactly the staleness opus-plan §3.5/§6 Phase 7 warns |
85 | | -about. Revisit if/when Enhance (Phase 2) introduces the first genuinely new typed |
86 | | -response and a type-checking CI gate is added. |
| 30 | +## 4. Ontology parity: scheduled for S2 |
87 | 31 |
|
88 | | -## Everything else |
| 32 | +Adding `dql_fetch_ontology_text()` and `dql_refresh_ontology_async()` to close the |
| 33 | +Python/TypeScript asymmetry is scheduled for **S2** (Python 3.4.0). |
89 | 34 |
|
90 | | -The sync/async de-duplication refactor (shared `_transport.py` request/response |
91 | | -helpers), per-host bases, repeated query parameters, DELETE + arbitrary method/body/ |
92 | | -Content-Type, form-encoded and raw bodies, per-call timeout, the default-on retry policy |
93 | | -with per-call `retryable=False` opt-out, `NotFoundError`/`JobError` (both subclassing |
94 | | -`APIError`), and the streaming `ask()` `ResponseNotRead` fix (sync and async, with tests |
95 | | -using a real byte-stream mock transport so the fix is actually exercised) all landed — |
96 | | -see the commit log for the breakdown and `tests/test_transport.py`, `tests/test_client.py`, |
97 | | -`tests/test_ask.py`, `tests/test_crawl.py`, `tests/test_dql.py` for coverage. |
| 35 | +## 5. Response TypedDicts: scheduled for S1 |
98 | 36 |
|
99 | | -The TypeScript SDK's two fixes (dql raw-mode binary corruption, crawl CSV quote-aware |
100 | | -parsing) and its full type-safety push (vendored OpenAPI, generated types, per-handler |
101 | | -overloads, typescript-eslint strict-type-checked) are not part of this checkout; they |
102 | | -were implemented first on the matching TypeScript branch per the assignment. |
| 37 | +Request-side `TypedDict`/`Literal` aliases landed in `src/diffbot/types.py`. |
| 38 | +Response shapes (`DqlResponse`, `WebSearchResponse`, `ExtractResponse`, `CrawlJob`, |
| 39 | +`AccountResponse`, `AskChunk`, ...) are scheduled for **S1** (Python 3.3.0), |
| 40 | +together with a pyright CI gate so they are checked from day one. |
0 commit comments