Skip to content

feat: add a keyed decisions API with image assets - #31

Closed
TheGreatAxios wants to merge 3 commits into
mainfrom
cl-11530-match-the-typesafe-sdk-question-and-image-api
Closed

TheGreatAxios wants to merge 3 commits into
mainfrom
cl-11530-match-the-typesafe-sdk-question-and-image-api

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Summary

  • Add keyed systemOne() with choice, noul, score, and box. Answers are named. Failures stay a fallback.
  • Add image(), Image.fromBase64(), and withAssets. PNG and JPEG go out as multipart with the images header. Other formats fail before the request.
  • Keep evaluate() and createSystemOneAdapter. The adapter accepts keyed questions.

Verification

  • bun run check exited 0.
  • Review of 6b00c31 found no defects.

Fixes CL-11530

Callers can ask named choice, noul, score, and box questions and attach PNG or JPEG images. The existing question list and adapter stay in place.
@linear-code

linear-code Bot commented Oct 26, 2026

Copy link
Copy Markdown

CL-11530

Asset names no longer match inside JSON keys, box edges are checked on the adapter path, and the keyed API is documented.
@corbits-triage

Copy link
Copy Markdown
Contributor

Triage: Pass

No changes needed from you. A maintainer will review this pull request.

@TheGreatAxios TheGreatAxios left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review · Request changes

Adds a keyed decisions API and PNG/JPEG image assets. Range checks, JSON-key matches, identifier substrings, JPEG-versus-PNG sniffing, and cross-kind answer mismatches behave as required. Three contract checks do not.

Findings

  • src/assets.ts:238 — valueHasToken walks the question type string and the generated <image:…> reference. serializeRequest with an asset named choice, noul, score, or box does not throw when that word appears only as the question type. An asset named image is accepted when the only occurrence is <image:hex>, because < and : are token boundaries. The caller never wrote those names in state, instructions, or criteria, but the pre-send check treats them as referenced. Keys and identifier substrings still throw not referenced.

  • src/schemas.ts:325 — boxEdgesOutOfRange only checks that each edge is inside [0, 1]. A 200 body { top: 0.8, bottom: 0.2, left: 0.1, right: 0.4 } returns fallback: false from systemOne, and parseJSONResponse of { top: 0.9, bottom: 0.1, left: 0.8, right: 0.2 } does not throw. The box contract needs top < bottom and left < right. Both paths share this helper, so inverted boxes are returned as success and crops get a negative width or height. Out-of-range edges still fail.

  • src/client.ts:155 — TypeSafe-Danger-Zone-Images is set only when imageParts.length > 0. A box question with no image part sends the header as absent. The docs require that header on every box question, not only on requests that upload images.

A deleted probe (bun test tmp/critique-tests/pr31-review.test.ts) was 7 pass, 5 fail on these cases.

@TheGreatAxios

Copy link
Copy Markdown
Contributor Author

Review · Follow-up

Commit 946c2d7 is clean.

Asset names count only as whole tokens in state, instructions, and criteria. Question types and a generated image reference do not. Inverted boxes (top >= bottom, left >= right) are a parse error on systemOne and throw from parseJSONResponse. Edges outside [0, 1] still fail. A box question with no upload sends TypeSafe-Danger-Zone-Images; a choice-only request does not.

bun test src/adapter.test.ts src/decisions.test.ts src/evaluate.test.ts exited 0 (43 pass).

This was referenced Oct 27, 2026
@TheGreatAxios

Copy link
Copy Markdown
Contributor Author

Stacked into the 0.4.0 release: #34

This pull is included in that release and must not also be merged. Landing #34 is the only merge into main. Do not close this pull yet.

@TheGreatAxios

Copy link
Copy Markdown
Contributor Author

Superseded by the 0.4.0 release, which is merged: #34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant