Repository navigation
Commit 3b900a8
feat(client): ai.savedQuestions and ai.answers for the AI answer follow-up routes (#38539)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Jianguo** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbXxoCGcWFTzHUA2xmDrNEuW)_
Fixes #32644
Clause-②: yes
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:用户无感;用开发包写程序的人现在能直接调用「收藏问题、把回答存成视图或报表、给回答打分」这几项能力,不必再手拼网址。
- 为什么做:这是控制台两项需求(收藏问题入口、回答打分)要用的开发包这一半,那两张卡在等它。
- 出错会怎样:只有调用这些新方法的人受影响,已有方法一行未改;出了问题可以直接撤回这次合并。
- 要你做什么:无。
## What changes
`ObjectStackClient.ai` gains two namespaces for the eight route and
method pairs `packages/spec/src/api/ai-answer.zod.ts` declares. Every
parameter and return type is a `@objectstack/spec/api` type from that
file; there is no hand-written shape.
| Method | Route | Resolves to |
|:--|:--|:--|
| `ai.savedQuestions.list()` | `GET /api/v1/ai/saved-questions` |
`ListAiSavedQuestionsResponse` |
| `ai.savedQuestions.create(request)` | `POST
/api/v1/ai/saved-questions` | `CreateAiSavedQuestionResponse` |
| `ai.savedQuestions.delete(id)` | `DELETE
/api/v1/ai/saved-questions/:id` | `void` (204) |
| `ai.savedQuestions.run(id)` | `POST
/api/v1/ai/saved-questions/:id/run`, no body |
`RunAiSavedQuestionResponse` |
| `ai.answers.createArtifact(conversationId, turnId, request)` | `POST
…/conversations/:id/turns/:turnId/artifact` |
`CreateAiAnswerArtifactResponse` |
| `ai.answers.getFeedback(conversationId, turnId)` | `GET
…/turns/:turnId/feedback` | `GetAiAnswerFeedbackResponse` |
| `ai.answers.setFeedback(conversationId, turnId, request)` | `POST
…/turns/:turnId/feedback` | `SetAiAnswerFeedbackResponse` |
| `ai.answers.deleteFeedback(conversationId, turnId)` | `DELETE
…/turns/:turnId/feedback` | `void` (204) |
Each method resolves to the route's `data` payload after
`unwrapResponse` strips the envelope, the same reading the rest of
`ai.*` uses. The payload is returned whole rather than plucked
(`questions`, `feedback`), so no `?? []` fallback stands in for a
missing member. A refusal throws the shared transport error, carrying
the route's code on `err.code` and the status on `err.httpStatus`. The
request and response types, plus `AiSavedQuestion`,
`AiSavedQuestionErrorCode`, `AiAnswerArtifactKind`, `AiAnswerRating` and
`AiAnswerFeedback`, are re-exported from the package root beside the
other AI wire types.
Files: `packages/client/src/index.ts`,
`packages/client/src/ai-answer-follow-ups.test.ts`,
`.changeset/32644-client-ai-answer-follow-ups.md`.
## Why
#31889 and #31865 (console, `plugin-chatbot`) need these routes from the
SDK. The card's ruling: "Type them from the spec shapes only; ⛔ no
hand-written shapes."
## Tests
`packages/client/src/ai-answer-follow-ups.test.ts`, 11 tests:
- one test per method pinning verb, URL (ids percent-encoded), request
body and the resolved payload; the two deletes resolve on a 204 that has
no body;
- a refusal pins `err.code` `RESOURCE_CONFLICT` and `err.httpStatus` 409
off an `AiSavedQuestionErrorSchema`-legal envelope;
- every response fixture and request body parses against its spec
schema;
- `expectTypeOf` pins every request parameter and resolved type to the
spec type, compiled by `check:test-typecheck`.
Reverse checks, each restored afterwards: sending `PUT` from
`setFeedback` and an unencoded id plus a `{}` body from `run` turned 2
of 11 red; typing `setFeedback`'s request as a hand-written `{ rating:
string; note?: string | null }` turned `tsc -p tsconfig.test.json` red
at the signature pin (TS2344).
## Acceptance notes
- The producer is the cloud AI service, so nothing in this repo serves
these routes. `client-url-conformance.test.ts` exempts `/api/v1/ai/` for
that reason and stays green with the new methods enumerated and driven;
the cloud repo's AI route ledger drives every `ai.*` method against its
real table, so these URLs are checked there.
- The dispatch suggested a `minor` changeset. `Metadata-protocol: none`
takes `patch` (AGENTS.md Post-Task Checklist step 3,
`check-changeset-no-major`), so it ships `patch`.
- `packages/client/README.md` lists one example per `ai.*` namespace; it
is outside this card's file surface, so the new namespaces are not added
there.
## Verification
All local readings at head `5b9ac603` (base `0af813f3`; `origin/main`
has moved 3 commits since, none under `packages/client` or
`packages/spec`).
<details><summary>Package tests and type-check</summary>
- `pnpm --filter @objectstack/client run typecheck`: exit 0 (`tsc
--noEmit`, then `check:test-typecheck`: 0 files / 0 errors held in the
debt ledger).
- `packages/client`: `vitest run --maxWorkers=2`: Test Files 60 passed
(60), Tests 840 passed (840).
- `eslint --no-inline-config` on the two touched source files: exit 0.
- Closure built first under the verify lock: `turbo run build --filter
'@objectstack/client...'`, 46 of 46 tasks, VERDICT command-exit 0.
</details>
<details><summary>Derived gate families (dispatch-gates --commands,
69)</summary>
- 68 of 69 exit 0. `check-plugin-teardown-shape --self-test` and `spec
check:skill-examples` first exited 3 on prerequisites (the shallow
clone's pinned fixture commit; an unbuilt `@objectstack/client-react`);
both were cleared and re-run green.
- NOT MEASURED: `pnpm check:dual-build-cjs-loads`, reason: PREREQUISITE
NOT MET (it needs every workspace package's `dist/`); CI's Lint and Repo
Gates runs it.
- `dispatch-gates --ran`: 69 derived families accounted for, 68 run, 1
NOT MEASURED, 0 unrun.
- Dogfood battery: not owed (no `!` in the title, no `(narrowing)` arm).
</details>
**Read first:** `packages/client/src/index.ts` in the `ai = {`
namespace, the `savedQuestions` and `answers` blocks (the two 204
deletes are the risk hunk: they must not parse a body); then
`ai-answer-follow-ups.test.ts`.
**Two-minute check:** `cd packages/client && pnpm exec vitest run
src/ai-answer-follow-ups.test.ts` shows 11 passed.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (eslint on the touched
files locally; CI runs the repository lint)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jREYTQb5JmJ3TewGpr
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jREYTQb5JmJ3TewGpr)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 0771cdd commit 3b900a8
3 files changed
Lines changed: 370 additions & 0 deletions
File tree
- .changeset
- packages/client/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
77 | 88 | | |
78 | 89 | | |
79 | 90 | | |
| |||
8023 | 8034 | | |
8024 | 8035 | | |
8025 | 8036 | | |
| 8037 | + | |
| 8038 | + | |
| 8039 | + | |
| 8040 | + | |
| 8041 | + | |
| 8042 | + | |
| 8043 | + | |
| 8044 | + | |
| 8045 | + | |
| 8046 | + | |
| 8047 | + | |
| 8048 | + | |
| 8049 | + | |
| 8050 | + | |
| 8051 | + | |
| 8052 | + | |
| 8053 | + | |
| 8054 | + | |
| 8055 | + | |
| 8056 | + | |
| 8057 | + | |
| 8058 | + | |
| 8059 | + | |
| 8060 | + | |
| 8061 | + | |
| 8062 | + | |
| 8063 | + | |
| 8064 | + | |
| 8065 | + | |
| 8066 | + | |
| 8067 | + | |
| 8068 | + | |
| 8069 | + | |
| 8070 | + | |
| 8071 | + | |
| 8072 | + | |
| 8073 | + | |
| 8074 | + | |
| 8075 | + | |
| 8076 | + | |
| 8077 | + | |
| 8078 | + | |
| 8079 | + | |
| 8080 | + | |
| 8081 | + | |
| 8082 | + | |
| 8083 | + | |
| 8084 | + | |
| 8085 | + | |
| 8086 | + | |
| 8087 | + | |
| 8088 | + | |
| 8089 | + | |
| 8090 | + | |
| 8091 | + | |
| 8092 | + | |
| 8093 | + | |
| 8094 | + | |
| 8095 | + | |
| 8096 | + | |
| 8097 | + | |
| 8098 | + | |
| 8099 | + | |
| 8100 | + | |
| 8101 | + | |
| 8102 | + | |
| 8103 | + | |
| 8104 | + | |
| 8105 | + | |
| 8106 | + | |
| 8107 | + | |
| 8108 | + | |
| 8109 | + | |
| 8110 | + | |
| 8111 | + | |
| 8112 | + | |
| 8113 | + | |
| 8114 | + | |
| 8115 | + | |
| 8116 | + | |
| 8117 | + | |
| 8118 | + | |
| 8119 | + | |
| 8120 | + | |
| 8121 | + | |
| 8122 | + | |
| 8123 | + | |
| 8124 | + | |
| 8125 | + | |
| 8126 | + | |
| 8127 | + | |
| 8128 | + | |
| 8129 | + | |
| 8130 | + | |
| 8131 | + | |
| 8132 | + | |
| 8133 | + | |
| 8134 | + | |
| 8135 | + | |
| 8136 | + | |
| 8137 | + | |
| 8138 | + | |
| 8139 | + | |
| 8140 | + | |
| 8141 | + | |
| 8142 | + | |
| 8143 | + | |
| 8144 | + | |
| 8145 | + | |
| 8146 | + | |
| 8147 | + | |
| 8148 | + | |
| 8149 | + | |
| 8150 | + | |
| 8151 | + | |
| 8152 | + | |
| 8153 | + | |
| 8154 | + | |
| 8155 | + | |
8026 | 8156 | | |
8027 | 8157 | | |
8028 | 8158 | | |
| |||
9569 | 9699 | | |
9570 | 9700 | | |
9571 | 9701 | | |
| 9702 | + | |
| 9703 | + | |
| 9704 | + | |
| 9705 | + | |
| 9706 | + | |
| 9707 | + | |
| 9708 | + | |
| 9709 | + | |
| 9710 | + | |
| 9711 | + | |
| 9712 | + | |
| 9713 | + | |
| 9714 | + | |
| 9715 | + | |
| 9716 | + | |
| 9717 | + | |
9572 | 9718 | | |
9573 | 9719 | | |
9574 | 9720 | | |
| |||
0 commit comments