Skip to content

Commit 3b900a8

Browse files
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/client': patch
3+
---
4+
5+
feat(client): `ai.savedQuestions` and `ai.answers`, the SDK methods for the AI answer follow-up routes
6+
7+
Clause-②: yes
8+
Metadata-protocol: none
9+
10+
The client now calls the eight routes `@objectstack/spec/api` declares in `ai-answer.zod.ts`, typed from those spec shapes only:
11+
12+
- `ai.savedQuestions.list()`, `create(request)`, `delete(id)` and `run(id)`: `GET`/`POST /api/v1/ai/saved-questions`, `DELETE /api/v1/ai/saved-questions/:id` and `POST /api/v1/ai/saved-questions/:id/run`.
13+
- `ai.answers.createArtifact(conversationId, turnId, request)`: `POST /api/v1/ai/conversations/:id/turns/:turnId/artifact`, answering a list view, a report draft or a one-widget dashboard draft, discriminated by `kind`.
14+
- `ai.answers.getFeedback`, `setFeedback` and `deleteFeedback(conversationId, turnId, …)`: `GET`/`POST`/`DELETE /api/v1/ai/conversations/:id/turns/:turnId/feedback`.
15+
16+
Each method resolves to the route's `data` payload; the two deletes resolve `undefined` on the route's 204. A refusal throws the usual transport error, with the route's code on `err.code` and the status on `err.httpStatus`. The request and response types are re-exported from `@objectstack/client`. The routes are served by the AI service; check `discovery.services` first, as for the rest of `ai.*`.
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* `client.ai.savedQuestions.*` and `client.ai.answers.*` against the AI answer
5+
* follow-up routes `ai-answer.zod.ts` declares.
6+
*
7+
* The producer is the cloud AI service, so nothing in this repo serves these
8+
* routes: the URL conformance sweep exempts `/api/v1/ai/` and the cloud repo's
9+
* route ledger drives this namespace against its real table. What this file
10+
* pins is the half that lives here, per method: the verb, the URL, the request
11+
* body, and the `data` payload the method resolves to once the envelope is
12+
* stripped. Every fixture parses against its spec schema, and every signature
13+
* is pinned to the spec type, so a shape changed in the spec reaches this file
14+
* instead of drifting away from it.
15+
*/
16+
17+
import { describe, it, expect, expectTypeOf, vi } from 'vitest';
18+
import {
19+
CreateAiAnswerArtifactRequestSchema,
20+
CreateAiAnswerArtifactResponseSchema,
21+
CreateAiSavedQuestionRequestSchema,
22+
CreateAiSavedQuestionResponseSchema,
23+
GetAiAnswerFeedbackResponseSchema,
24+
ListAiSavedQuestionsResponseSchema,
25+
RunAiSavedQuestionResponseSchema,
26+
SetAiAnswerFeedbackRequestSchema,
27+
SetAiAnswerFeedbackResponseSchema,
28+
AiSavedQuestionErrorSchema,
29+
type CreateAiAnswerArtifactRequest,
30+
type CreateAiAnswerArtifactResponse,
31+
type CreateAiSavedQuestionRequest,
32+
type CreateAiSavedQuestionResponse,
33+
type GetAiAnswerFeedbackResponse,
34+
type ListAiSavedQuestionsResponse,
35+
type RunAiSavedQuestionResponse,
36+
type SetAiAnswerFeedbackRequest,
37+
type SetAiAnswerFeedbackResponse,
38+
} from '@objectstack/spec/api';
39+
import { ObjectStackClient } from './index';
40+
41+
const BASE = 'http://localhost:3000';
42+
const AI = `${BASE}/api/v1/ai`;
43+
44+
interface Answer { status: number; body?: unknown }
45+
46+
function clientAnswering(answer: Answer) {
47+
const fetchMock = vi.fn().mockResolvedValue({
48+
ok: answer.status >= 200 && answer.status < 300,
49+
status: answer.status,
50+
statusText: String(answer.status),
51+
headers: new Headers(),
52+
json: async () => {
53+
if (answer.body === undefined) throw new SyntaxError('Unexpected end of JSON input');
54+
return answer.body;
55+
},
56+
});
57+
return { client: new ObjectStackClient({ baseUrl: BASE, fetch: fetchMock }), fetchMock };
58+
}
59+
60+
const enveloped = (data: unknown): Answer => ({ status: 200, body: { success: true, data } });
61+
62+
/** The one request a method put on the wire: verb, URL, parsed body. */
63+
function sent(fetchMock: ReturnType<typeof vi.fn>) {
64+
expect(fetchMock).toHaveBeenCalledTimes(1);
65+
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit | undefined];
66+
return {
67+
verb: (init?.method ?? 'GET').toUpperCase(),
68+
url,
69+
body: typeof init?.body === 'string' ? JSON.parse(init.body) : init?.body,
70+
};
71+
}
72+
73+
const SAVED = {
74+
id: 'sq_1',
75+
question: 'How many open deals per stage?',
76+
source: null,
77+
agentId: 'ask',
78+
conversationId: 'conv/1',
79+
turnId: 'turn 1',
80+
createdAt: '2026-11-29T07:00:00.000Z',
81+
};
82+
83+
const FEEDBACK = {
84+
conversationId: 'conv/1',
85+
turnId: 'turn 1',
86+
rating: 'down' as const,
87+
note: 'Wrong quarter',
88+
createdAt: '2026-11-29T07:00:00.000Z',
89+
updatedAt: null,
90+
};
91+
92+
describe('fixtures are spec-legal', () => {
93+
it('every response payload and request body below parses against its spec schema', () => {
94+
expect(ListAiSavedQuestionsResponseSchema.parse({ questions: [SAVED] })).toBeTruthy();
95+
expect(CreateAiSavedQuestionResponseSchema.parse({ question: SAVED })).toBeTruthy();
96+
expect(RunAiSavedQuestionResponseSchema.parse({ question: SAVED.question, toolName: 'aggregate_data', result: { rows: [] } })).toBeTruthy();
97+
expect(CreateAiAnswerArtifactResponseSchema.parse({
98+
kind: 'view',
99+
view: { id: 'pv_1', object_name: 'deal', label: 'Open deals', config: {} },
100+
})).toBeTruthy();
101+
expect(GetAiAnswerFeedbackResponseSchema.parse({ feedback: FEEDBACK })).toBeTruthy();
102+
expect(SetAiAnswerFeedbackResponseSchema.parse({ feedback: FEEDBACK })).toBeTruthy();
103+
expect(CreateAiSavedQuestionRequestSchema.parse({ conversationId: 'conv/1', turnId: 'turn 1' })).toBeTruthy();
104+
expect(CreateAiAnswerArtifactRequestSchema.parse({ kind: 'report', label: 'Deals' })).toBeTruthy();
105+
expect(SetAiAnswerFeedbackRequestSchema.parse({ rating: 'down', note: 'Wrong quarter' })).toBeTruthy();
106+
});
107+
});
108+
109+
describe('client.ai.savedQuestions — verb, URL, body, payload', () => {
110+
it('list: GET /saved-questions, no body, resolves to the `data` payload', async () => {
111+
const data = { questions: [SAVED] };
112+
const { client, fetchMock } = clientAnswering(enveloped(data));
113+
await expect(client.ai.savedQuestions.list()).resolves.toEqual(data);
114+
expect(sent(fetchMock)).toEqual({ verb: 'GET', url: `${AI}/saved-questions`, body: undefined });
115+
});
116+
117+
it('create: POST /saved-questions with the request as the body', async () => {
118+
const request = { conversationId: 'conv/1', turnId: 'turn 1', toolCallId: 'call_2' };
119+
const data = { question: SAVED };
120+
const { client, fetchMock } = clientAnswering({ status: 201, body: { success: true, data } });
121+
await expect(client.ai.savedQuestions.create(request)).resolves.toEqual(data);
122+
expect(sent(fetchMock)).toEqual({ verb: 'POST', url: `${AI}/saved-questions`, body: request });
123+
});
124+
125+
it('delete: DELETE /saved-questions/:id, encoded, and a 204 with no body resolves', async () => {
126+
const { client, fetchMock } = clientAnswering({ status: 204 });
127+
await expect(client.ai.savedQuestions.delete('sq/1')).resolves.toBeUndefined();
128+
expect(sent(fetchMock)).toEqual({ verb: 'DELETE', url: `${AI}/saved-questions/sq%2F1`, body: undefined });
129+
});
130+
131+
it('run: POST /saved-questions/:id/run with no request body', async () => {
132+
const data = { question: SAVED.question, toolName: 'query_records', result: { records: [] } };
133+
const { client, fetchMock } = clientAnswering(enveloped(data));
134+
await expect(client.ai.savedQuestions.run('sq_1')).resolves.toEqual(data);
135+
expect(sent(fetchMock)).toEqual({ verb: 'POST', url: `${AI}/saved-questions/sq_1/run`, body: undefined });
136+
});
137+
138+
it('a refusal throws with the route error code and status', async () => {
139+
const error = {
140+
code: 'RESOURCE_CONFLICT',
141+
message: 'This saved question has no query to run',
142+
details: { reason: 'saved_question_has_no_query', question: SAVED.question },
143+
};
144+
expect(AiSavedQuestionErrorSchema.parse(error)).toBeTruthy();
145+
const { client } = clientAnswering({ status: 409, body: { success: false, error } });
146+
await expect(client.ai.savedQuestions.run('sq_1')).rejects.toMatchObject({
147+
code: 'RESOURCE_CONFLICT',
148+
httpStatus: 409,
149+
});
150+
});
151+
});
152+
153+
describe('client.ai.answers — verb, URL, body, payload', () => {
154+
const TURN = `${AI}/conversations/conv%2F1/turns/turn%201`;
155+
156+
it('createArtifact: POST …/turns/:turnId/artifact with the request as the body', async () => {
157+
const request = { kind: 'widget' as const, toolCallId: 'call_2', label: 'Deals by stage' };
158+
const data = {
159+
kind: 'widget',
160+
published: false,
161+
drafts: [{ type: 'dataset', name: 'deals_by_stage' }, { type: 'dashboard', name: 'deals_by_stage_dashboard' }],
162+
dataset: { name: 'deals_by_stage' },
163+
dashboard: { name: 'deals_by_stage_dashboard' },
164+
};
165+
expect(CreateAiAnswerArtifactResponseSchema.parse(data)).toBeTruthy();
166+
const { client, fetchMock } = clientAnswering({ status: 201, body: { success: true, data } });
167+
await expect(client.ai.answers.createArtifact('conv/1', 'turn 1', request)).resolves.toEqual(data);
168+
expect(sent(fetchMock)).toEqual({ verb: 'POST', url: `${TURN}/artifact`, body: request });
169+
});
170+
171+
it('getFeedback: GET …/turns/:turnId/feedback; an unrated answer resolves `feedback: null`', async () => {
172+
const { client, fetchMock } = clientAnswering(enveloped({ feedback: null }));
173+
await expect(client.ai.answers.getFeedback('conv/1', 'turn 1')).resolves.toEqual({ feedback: null });
174+
expect(sent(fetchMock)).toEqual({ verb: 'GET', url: `${TURN}/feedback`, body: undefined });
175+
});
176+
177+
it('setFeedback: POST …/turns/:turnId/feedback with the request as the body', async () => {
178+
const request = { rating: 'down' as const, note: 'Wrong quarter' };
179+
const data = { feedback: FEEDBACK };
180+
const { client, fetchMock } = clientAnswering(enveloped(data));
181+
await expect(client.ai.answers.setFeedback('conv/1', 'turn 1', request)).resolves.toEqual(data);
182+
expect(sent(fetchMock)).toEqual({ verb: 'POST', url: `${TURN}/feedback`, body: request });
183+
});
184+
185+
it('deleteFeedback: DELETE …/turns/:turnId/feedback, and a 204 with no body resolves', async () => {
186+
const { client, fetchMock } = clientAnswering({ status: 204 });
187+
await expect(client.ai.answers.deleteFeedback('conv/1', 'turn 1')).resolves.toBeUndefined();
188+
expect(sent(fetchMock)).toEqual({ verb: 'DELETE', url: `${TURN}/feedback`, body: undefined });
189+
});
190+
});
191+
192+
describe('signatures are the spec types', () => {
193+
it('every request parameter and resolved value is the `@objectstack/spec/api` type', () => {
194+
const { client } = clientAnswering({ status: 204 });
195+
const { savedQuestions, answers } = client.ai;
196+
expectTypeOf(savedQuestions.list).returns.resolves.toEqualTypeOf<ListAiSavedQuestionsResponse>();
197+
expectTypeOf(savedQuestions.create).parameter(0).toEqualTypeOf<CreateAiSavedQuestionRequest>();
198+
expectTypeOf(savedQuestions.create).returns.resolves.toEqualTypeOf<CreateAiSavedQuestionResponse>();
199+
expectTypeOf(savedQuestions.delete).returns.resolves.toEqualTypeOf<void>();
200+
expectTypeOf(savedQuestions.run).returns.resolves.toEqualTypeOf<RunAiSavedQuestionResponse>();
201+
expectTypeOf(answers.createArtifact).parameter(2).toEqualTypeOf<CreateAiAnswerArtifactRequest>();
202+
expectTypeOf(answers.createArtifact).returns.resolves.toEqualTypeOf<CreateAiAnswerArtifactResponse>();
203+
expectTypeOf(answers.getFeedback).returns.resolves.toEqualTypeOf<GetAiAnswerFeedbackResponse>();
204+
expectTypeOf(answers.setFeedback).parameter(2).toEqualTypeOf<SetAiAnswerFeedbackRequest>();
205+
expectTypeOf(answers.setFeedback).returns.resolves.toEqualTypeOf<SetAiAnswerFeedbackResponse>();
206+
expectTypeOf(answers.deleteFeedback).returns.resolves.toEqualTypeOf<void>();
207+
});
208+
});

‎packages/client/src/index.ts‎

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ import {
7474
ListAiPendingActionsResponse,
7575
ApproveAiPendingActionResponse,
7676
RejectAiPendingActionResponse,
77+
// The AI answer follow-up routes (`ai-answer.zod.ts`): saved questions, an
78+
// answer turned into an artifact, an answer's rating.
79+
ListAiSavedQuestionsResponse,
80+
CreateAiSavedQuestionRequest,
81+
CreateAiSavedQuestionResponse,
82+
RunAiSavedQuestionResponse,
83+
CreateAiAnswerArtifactRequest,
84+
CreateAiAnswerArtifactResponse,
85+
GetAiAnswerFeedbackResponse,
86+
SetAiAnswerFeedbackRequest,
87+
SetAiAnswerFeedbackResponse,
7788
GetLocalesResponse,
7889
GetTranslationsResponse,
7990
GetFieldLabelsResponse,
@@ -8023,6 +8034,125 @@ export class ObjectStackClient {
80238034
return this.unwrapResponse<RejectAiPendingActionResponse>(res);
80248035
},
80258036
},
8037+
8038+
/**
8039+
* Saved questions: a question the caller keeps to run again later, typed
8040+
* in or saved from one of their answers.
8041+
*
8042+
* Every type here is a `@objectstack/spec/api` shape from `ai-answer.zod.ts`,
8043+
* and each method resolves to the route's `data` payload once
8044+
* `unwrapResponse` strips the `{ success: true, data }` envelope. A failure
8045+
* throws the shared transport error: `err.code` is the route's
8046+
* `AiSavedQuestionErrorCode`, `err.httpStatus` the status.
8047+
*
8048+
* Every route is the caller's own: a saved question that is not the
8049+
* caller's answers 404 RESOURCE_NOT_FOUND.
8050+
*/
8051+
savedQuestions: {
8052+
/** The caller's saved questions in the session's organization, newest first, at most 200. */
8053+
list: async (): Promise<ListAiSavedQuestionsResponse> => {
8054+
const route = this.getRoute('ai');
8055+
const res = await this.fetch(`${this.baseUrl}${route}/saved-questions`);
8056+
return this.unwrapResponse<ListAiSavedQuestionsResponse>(res);
8057+
},
8058+
8059+
/**
8060+
* Save a typed question (`question`), or one of the caller's answers
8061+
* (`conversationId` with `turnId`, and optionally `toolCallId`). Saved
8062+
* from an answer, the server reads the query off the stored turn.
8063+
*/
8064+
create: async (request: CreateAiSavedQuestionRequest): Promise<CreateAiSavedQuestionResponse> => {
8065+
const route = this.getRoute('ai');
8066+
const res = await this.fetch(`${this.baseUrl}${route}/saved-questions`, {
8067+
method: 'POST',
8068+
body: JSON.stringify(request),
8069+
});
8070+
return this.unwrapResponse<CreateAiSavedQuestionResponse>(res);
8071+
},
8072+
8073+
/** Delete a saved question. The route answers 204 with no body. */
8074+
delete: async (id: string): Promise<void> => {
8075+
const route = this.getRoute('ai');
8076+
await this.fetch(`${this.baseUrl}${route}/saved-questions/${encodeURIComponent(id)}`, {
8077+
method: 'DELETE',
8078+
});
8079+
},
8080+
8081+
/**
8082+
* Run a saved question's stored query again, as the caller and under
8083+
* their current permissions. Nothing is stored. A question saved without
8084+
* a query answers 409 RESOURCE_CONFLICT (`saved_question_has_no_query`).
8085+
*/
8086+
run: async (id: string): Promise<RunAiSavedQuestionResponse> => {
8087+
const route = this.getRoute('ai');
8088+
const res = await this.fetch(`${this.baseUrl}${route}/saved-questions/${encodeURIComponent(id)}/run`, {
8089+
method: 'POST',
8090+
});
8091+
return this.unwrapResponse<RunAiSavedQuestionResponse>(res);
8092+
},
8093+
},
8094+
8095+
/**
8096+
* One answer of a conversation, addressed by the conversation id and the
8097+
* turn id: turn it into an artifact, or rate it.
8098+
*
8099+
* Typed from the same `ai-answer.zod.ts` shapes as {@link savedQuestions},
8100+
* and resolving to the `data` payload the same way. A conversation that is
8101+
* not the caller's answers 403 PERMISSION_DENIED.
8102+
*/
8103+
answers: {
8104+
/**
8105+
* Turn an answer into a list view, a report draft or a one-widget
8106+
* dashboard draft. The server builds it from the stored turn's query,
8107+
* never from the request body; `report` and `widget` need the
8108+
* manage_metadata capability and publish nothing. Narrow the answer on
8109+
* its `kind`.
8110+
*/
8111+
createArtifact: async (
8112+
conversationId: string,
8113+
turnId: string,
8114+
request: CreateAiAnswerArtifactRequest,
8115+
): Promise<CreateAiAnswerArtifactResponse> => {
8116+
const route = this.getRoute('ai');
8117+
const res = await this.fetch(
8118+
`${this.baseUrl}${route}/conversations/${encodeURIComponent(conversationId)}/turns/${encodeURIComponent(turnId)}/artifact`,
8119+
{ method: 'POST', body: JSON.stringify(request) },
8120+
);
8121+
return this.unwrapResponse<CreateAiAnswerArtifactResponse>(res);
8122+
},
8123+
8124+
/** The caller's rating of an answer; `feedback` is null when unrated. */
8125+
getFeedback: async (conversationId: string, turnId: string): Promise<GetAiAnswerFeedbackResponse> => {
8126+
const route = this.getRoute('ai');
8127+
const res = await this.fetch(
8128+
`${this.baseUrl}${route}/conversations/${encodeURIComponent(conversationId)}/turns/${encodeURIComponent(turnId)}/feedback`,
8129+
);
8130+
return this.unwrapResponse<GetAiAnswerFeedbackResponse>(res);
8131+
},
8132+
8133+
/** Rate an answer, or change its rating. */
8134+
setFeedback: async (
8135+
conversationId: string,
8136+
turnId: string,
8137+
request: SetAiAnswerFeedbackRequest,
8138+
): Promise<SetAiAnswerFeedbackResponse> => {
8139+
const route = this.getRoute('ai');
8140+
const res = await this.fetch(
8141+
`${this.baseUrl}${route}/conversations/${encodeURIComponent(conversationId)}/turns/${encodeURIComponent(turnId)}/feedback`,
8142+
{ method: 'POST', body: JSON.stringify(request) },
8143+
);
8144+
return this.unwrapResponse<SetAiAnswerFeedbackResponse>(res);
8145+
},
8146+
8147+
/** Clear the caller's rating. The route answers 204 with no body, also when there was no rating. */
8148+
deleteFeedback: async (conversationId: string, turnId: string): Promise<void> => {
8149+
const route = this.getRoute('ai');
8150+
await this.fetch(
8151+
`${this.baseUrl}${route}/conversations/${encodeURIComponent(conversationId)}/turns/${encodeURIComponent(turnId)}/feedback`,
8152+
{ method: 'DELETE' },
8153+
);
8154+
},
8155+
},
80268156
};
80278157

80288158
/**
@@ -9569,6 +9699,22 @@ export type {
95699699
ListAiPendingActionsResponse,
95709700
ApproveAiPendingActionResponse,
95719701
RejectAiPendingActionResponse,
9702+
// The AI answer follow-up routes (`ai-answer.zod.ts`): saved questions, an
9703+
// answer turned into an artifact, an answer's rating.
9704+
AiSavedQuestion,
9705+
ListAiSavedQuestionsResponse,
9706+
CreateAiSavedQuestionRequest,
9707+
CreateAiSavedQuestionResponse,
9708+
RunAiSavedQuestionResponse,
9709+
AiSavedQuestionErrorCode,
9710+
AiAnswerArtifactKind,
9711+
CreateAiAnswerArtifactRequest,
9712+
CreateAiAnswerArtifactResponse,
9713+
AiAnswerRating,
9714+
AiAnswerFeedback,
9715+
GetAiAnswerFeedbackResponse,
9716+
SetAiAnswerFeedbackRequest,
9717+
SetAiAnswerFeedbackResponse,
95729718
GetLocalesResponse,
95739719
GetTranslationsResponse,
95749720
GetFieldLabelsResponse,

0 commit comments

Comments
 (0)