Public: anyone can read this; the crew can change it.

GET the models Talk offers me, and `model` on POST /api/v1/conversations and /conversation/messages #17916

opened this in answer to

Merged 19h 14m ago, live in production

Native clients can now ask which models Talk offers them and pick one when starting a conversation or sending a message. I ran only the suites that cover this change, not the whole suite, because scripts/fast.ts named 2814 files and was too broad. Those suites, the type check and the gate pass.

Notes

opened this

Native clients can now ask which models Talk offers them and pick one when starting a conversation or sending a message. I ran only the suites that cover this change, not the whole suite, because scripts/fast.ts named 2814 files and was too broad. Those suites, the type check and the gate pass. I did not run scripts/design-lint.ts (no src/web/ change) or similar.ts, and the gate's note about duplicate test helpers is left as is.

  • GET /api/v1/models returns { models: [{ id, name, connection, default }] }, in the order the Talk picker lists them.
    • The forge's own model is first, with an empty id; then each working connection's models.
    • default marks the one a new conversation starts on, which is the person's last choice while it is still offered. name is the same plain name the picker shows.
  • model on POST /api/v1/conversations starts the conversation on that model.
  • model on POST /api/v1/conversation/messages switches the named (or open) conversation before the turn runs. It also becomes the person's last choice, as the page picker does.
  • Refusals:
    • A model that is not offered is 422 model_not_offered, and nothing is made or sent.
    • A model that is not a string of up to 400 characters is 422 invalid_model.
    • Both are in openapi.json, including the new route's tag, mark and generated index.
  • Reuse: modelList in core/model_choice.ts builds on startingChoice, offers, plainName and choiceValue. The 422 bounds check reuses modelRefusal from build_input.ts, and the choice is made with choiceFrom and setChoice, the same calls /api/v1/builds uses.
  • New dependencies: none.

I did not add a terminal side: pickList already gives the terminal the same list and choice, so the commit says No door:. I added a section to docs/features/talk.md.

A message that passes the model check but is then refused by the rate limit still leaves the conversation switched to that model. I judged that harmless; say if you want the switch to wait until the message is accepted.

To try it on the preview, call GET /api/v1/models with a token. Then send POST /api/v1/conversations {"model": "<an id from that list>"}, and the same model on POST /api/v1/conversation/messages for a conversation you own. The tests are in test/api-models.test.ts.

🤖 Generated with Claude Code

Closes #17912

Show 2 earlier items

7 earlier comments
commented

I regenerated src/http/lazy_lists.ts with bun scripts/lazy-lists.ts and pushed it; the forge's check on the pull is what confirms it. The check failed because that file was stale after the models route was added. The only change is one line, with no behaviour change.

I ran these locally and they pass:

  • Stale-file test: the lazy-list generator test.
  • Other named failures: the dead-code (unused-exports), duplicate-import, module-state and hollow tests.
  • Gate and types: the gate's --explain run and bun x tsc --noEmit.

I ran the unused-exports test after pushing rather than before.

Nothing else on the branch changed. To try it, run bun scripts/lazy-lists.ts and confirm git status stays clean.

commented

I merged main into the branch and pushed it. The only conflict was src/generated/marks.ts, which bun scripts/own-source.ts generates. I took main's side and regenerated it. It now carries both main's new api-v1-home mark and this pull's api-v1-models mark.

  • Checks run: bun x tsc --noEmit came back clean. test/own-source.test.ts, test/api-models.test.ts and test/talk-pin.test.ts pass (15 tests).
  • Full suite not run: scripts/fast.ts put the affected set at 2819 files, about 231 minutes, so I stopped the attempt. The forge's check runs the full suite on this push.
  • Gate: bun scripts/gate.ts --fix changed nothing. It still notes a comment over 100 columns in src/core/model_choice.ts, which the nightly rewrap handles on main. It also flags two helpers in test/api-models.test.ts as near-duplicates of helpers in test/admin-words.test.ts and test/talk-pin.test.ts; I left both alone.
commented

I merged main into the branch again and pushed it. The only conflict was in src/http/api/conversation_talk.ts, in the POST /api/v1/conversations handler.

  • Conflict: this pull set the chosen model on the new conversation and refused with 409 too_many when the start failed. Main made createConversation always succeed and removed the too-many check. I kept this pull's model choice and dropped the 409 branch, since it can no longer happen.
  • Checks run:
    • bun x tsc --noEmit is clean.
    • The model, talk, conversation and own-source tests pass: 994 pass, 50 skipped, 0 fail. The skips include the Talk layout test, which skips because no chromium starts here.
    • bun scripts/gate.ts --fix changed nothing. It still notes the over-long comment in src/core/model_choice.ts and the two near-duplicate test helpers in test/api-models.test.ts, as before.
  • Full suite not run: the forge's check runs it on this push.
commented

Still red on current main: the pane's frame > draws a public app. Fix it and push.

commented

I fixed one of the three failures and pushed; the other two I did not touch, and I couldn't confirm they were flakes.

  • Fixed: "no GET route answers 200 without a session phase" failed because GET /api/v1/models answers 200 without a session timing phase. I added it to the UNTIMED allowlist in test/route-timing-coverage.test.ts, next to /api/v1/conversations (same kind of read). That test file now passes.
  • Not fixed: "the pane's frame > draws a public app" and the "N+1: a pull's crew activity…" test. Nothing on this branch touches the Talk preview frame or crew activity, and the check log says both are green on main at 703a520. The frame test needs chromium, which doesn't start in my sandbox, so I couldn't run it. The N+1 test passed locally. I left both alone and expect them to pass on the re-run; if either fails again it will need a look.
commented

All four items from the review are done and pushed. bun x tsc --noEmit is clean, and the model, talk, conversation, dead-code and process-state tests pass (1184 pass, 52 skip, 0 fail). I did not run the full suite; the forge's check does.

  • Refused messages (1): I switched before talk() rather than after, because the turn reads the conversation's model as it starts. Switching afterwards would run the first turn on the old model. Instead switchModel in src/core/model_choice.ts returns an undo, and the messages route runs it when talk() refuses (rate limit, queue, agent off).
    • What undo restores: the conversation's own choice, the person's last choice, and any conversation the request had to create when none was named.
    • Kept messages: a kept message counts as accepted, so its switch stays.
    • Unchanged: an unknown model still returns 422 before anything is touched.
    • Docs: docs/features/talk.md now says this.
  • Tests (2): all five are in test/api-models.test.ts.
    • invalid_model on the messages route (a number, and a 401-character string).
    • model: "" switches back to the forge's own on both POSTs.
    • A message refused by the rate limit leaves the choice, the last choice and the conversation count as they were. I checked this fails with the undo disabled.
    • The "switches" test now asserts 202.
    • GET /api/v1/models shows default following the person's last choice.
  • Empty text test: I did not write the empty-text test you described, because bad text, files and during are rejected before any switch happens, so it would pass with or without the fix. A bad file id has the same ordering and does not exercise it either. The rate-limit refusal is the real test for item 1.
  • POST /api/v1/conversations (3): setChoice cannot refuse there, since choiceFrom just passed and the conversation is new and the person's own. I left a comment saying so rather than adding an unreachable branch.
  • Comments (4): all over-long comments in src/core/model_choice.ts are rewrapped, and the gate now reports no comment over 100 columns.
  • Door: the commit says No door: because the terminal's /model picker already covers it.
commented

The gate failure is fixed and pushed. I had rewrapped comments in src/core/model_choice.ts that this pull didn't write, and the "diff is the change" rule refuses that. I restored all of them, so the file's diff against main is now only the import, ModelEntry, modelList and switchModel.

The gate now passes locally. Its remaining notes are the over-100-column comment in model_choice.ts and the two near-duplicate test helpers, none of them blocking. bun x tsc --noEmit is clean and test/api-models.test.ts passes (11 tests). I did not re-run the wider suite for this comment-only restore.

The review's item 4 asked me to rewrap the over-long comment. The gate won't allow that for comments the pull didn't write, so I left them for the nightly rewrap.

commented

I merged main into the branch again and pushed it. The only conflict was src/generated/marks.ts. I took main's version and regenerated it with bun scripts/own-source.ts, so it now has both main's changes and this pull's api-v1-models mark.

bun x tsc --noEmit is clean. The gate reports nothing new: it still notes the over-long comment in src/core/model_choice.ts and the two near-duplicate test helpers in test/api-models.test.ts. The own-source, api-models, route-timing-coverage, conversation and talk tests pass (1003 pass, 50 skipped, 0 fail). The skips include tests that need a browser or network that the sandbox doesn't have. I did not run the full suite; the forge's check does that on this push.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs