Repository navigation
Commit b7dee0e
feat(spec,console): ask_ai action type — focus the in-app assistant on a record (#37215)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8GQ6AcWeR72ieTBXyYMDAWk)_
Fixes #37142
Fixes #37276
## 维护者速读
- 做了什么:元数据作者可以在记录页放一个「问 AI」按钮(`type:
'ask_ai'`),点了就把站内助手对准这条记录并展开,不发消息、不调服务端。
- 为什么:专题 #36996 第 6 行,落实 ADR-0160 D7;前置 #36999(助手聚焦)已合。
- 风险:spec 新增一个动作类型(扩宽);`target` 与 `ai.exposed: true`
写在它旁边会在解析时被拒;没有站内助手、或手上不是恰好一条记录(批量栏、相关列表工具栏、列表头未选或多选)时按钮不出现,而不是置灰。
- 要你做什么:暂无。等席位 L1 与 L2 契约审核(spec 面,fable 档)。
## What changes
ADR-0160 D7 — an action on one record that focuses the in-app assistant
on that record and opens it.
**Spec (`@objectstack/spec`)**
- `ActionType` gains `ask_ai`. It is outside the target-required set: it
takes no `target`.
- `ActionSchema` and `InlineActionSchema` refuse a `target` beside it
(inline `to` too) at the `target` path, and `ai.exposed: true` at
`ai.exposed` (`false` parses). `body` stays `script`-only.
- `DashboardHeaderActionSchema` refuses `actionType: 'ask_ai'` at
`actionType`: a header runs on no record. `WidgetActionTypeSchema` stays
derived from `ActionType`.
- Reference docs regenerated.
**Runtime (`@objectstack/runtime`)**
- `isHeadlessInvokableAction` answers `false` for `ask_ai`, so MCP
`list_actions` skips it and the AI posture of the action door refuses
it, whatever a stored row carries beside the type.
- `headlessActionTypeError` answers the REST door with a sentence about
the in-app assistant instead of the generic "opens its `target`".
**Console**
- `@object-ui/core`: `ActionRunner` gets an `ask_ai` executor that hands
`{ object, id }` to the installed `AssistantFocusHandler`
(`setAssistantFocusHandler`) and nothing else: no registered handler, no
fetch, no success toast unless `successMessage` is declared. The record
is the row a row surface stashed (`recordIdField` honoured), else the
page record, else the one selected row. No record, or several selected,
is refused before any `confirmText`; so is a launch with no handler
installed. `drawsAction()` answers whether an action is drawn;
`ActionEngine.getActionsForLocation` and `getBulkActions` leave undrawn
actions out. `isAskAiAction` reads `type` and the legacy `actionType`.
- `@object-ui/react`: `<ActionProvider onAskAi>` installs the handler
(the latest one runs; the gate identity changes only when the handler
appears or goes) and `useDrawsAction()` answers for every surface under
it; with no provider, `ask_ai` is not drawn.
- `@object-ui/app-shell`: `useAskAiHandler` returns `dock.open({ agent,
fresh: true })` + `setChatFocus(focus, { follow: true })` only when the
layout hosts the chat drawer (`useChatDockControl`, which is null when
the AI surface is off) and an agent in the catalog advertises
`capabilities.focus` (`useAiSurfaceEnabled().focusServed`); the console
action runtime passes it as `onAskAi`.
- **No single record ⇒ absent.** The bulk bar never offers an `ask_ai`
action (the type of a promoted def is read off its `actionDef`);
`ActionRunner.bulkRefusal` refuses a per-row run over a selection (the
grid's per-record bulk dispatch asks it), and
`ActionEngine.getBulkActions` / `executeBulk` leave it out. A list
header draws it only while exactly one row is selected, and leaves it
out (not greyed) with none or several. A related list's toolbar leaves
it out, because a launch there runs on the parent; its rows still draw
it.
- **The conversation it opens.** The click opens the drawer on a fresh
thread of an agent that declares `capabilities.focus` (`focusAgentName`,
an `ask` agent first), so the drawer's pin control, which asks the
active agent, is drawn, and pins the record to that thread.
`setChatFocus(focus, { follow: true })` (new option): a host showing a
conversation keeps that conversation's focus and gives this one to the
next conversation it shows; the first send carries it onto the id it
mints, and an unsent fresh thread creates nothing.
- `resolveAiApiBase` moves to `hooks/aiApiBase.ts` (re-exported from
`useAiSurface`), so `useAskAiHandler` does not import a module many
layout tests mock.
- Every action surface asks `useDrawsAction()` beside its existing
gates: record header/`DeclaredActionsBar`, `action:bar`,
`action:button`, `action:icon`, `action:group`, `action:menu`, element
buttons, container action filters, grid row menu and actions column,
data-table row actions, related-list toolbar, bulk action bar.
## Tests
- `packages/spec/src/ui/action-ask-ai.test.ts`: member, parses with no
target, refusals at `target` / `ai.exposed` (both in one parse),
`ai.exposed: false` accepted, `body` refused, inline refusals,
neighbours keep their rules.
- `packages/spec/src/ui/dashboard-header-ask-ai-37142.test.ts`: header
refusal, vocabulary still derived, other types still accepted.
- `packages/runtime/src/action-ask-ai-headless.test.ts`: not
headless-invokable (with or without automation, and for an at-rest row
carrying `target`/`body`/`ai.exposed`), REST sentence.
-
`ui/packages/core/src/actions/__tests__/ActionRunner.askAi-37142.test.ts`:
click hands the record once and sends nothing (fetch stub, script
handler, toast unspied), row / scoped / selected record readings,
refusals before confirm, not drawn without a handler, `ActionEngine`
filtering.
-
`ui/packages/react/src/context/__tests__/ActionProvider.askAi-37142.test.tsx`:
drawn only with `onAskAi`, gate identity, latest handler runs, no
provider.
-
`ui/packages/app-shell/src/hooks/__tests__/useAskAiHandler-37142.test.tsx`,
`useAiSurface.test.ts` (`focusServed`),
`views/__tests__/DeclaredActionsBar.askAi-37142.test.tsx` (absent
without assistant, drawn and focuses with one; ablation of the filter
turns it red).
- `skills/objectstack-ui/SKILL.md`: one table row and one sentence (164
→ 165 lines); the token ratchet stays under its ceiling.
-
`ui/packages/core/src/actions/__tests__/ActionRunner.askAi-37142.test.ts`
adds `bulkRefusal`, `getBulkActions` / `executeBulk` and page-record
`recordIdField`;
`plugin-grid/src/__tests__/BulkActionBar.askAi-37142.test.tsx`,
`plugin-detail/src/__tests__/RelatedList.toolbarAskAi-37142.test.tsx`,
`app-shell/src/views/__tests__/objectViewHeaderLaunchGate.askAi-37142.test.tsx`
pin the three no-single-record surfaces; `useAskAiHandler-37142` pins
the agent it opens.
- `ui/packages/app-shell/src/layout/__tests__/chatFocus-36999.test.tsx`
(objectstack#37142 block): the real dock body and focus host under a
real `useAskAiHandler`; a drawer open on another conversation keeps that
conversation's focus and the fresh thread's first send carries the
record; a drawer on an unsent thread takes it at once. Ablated: without
`follow`, and with `open({ agent })` instead of the fresh thread, the
first case fails.
- The same block pins N4: after an `ask_ai` click, opening a history
conversation before sending shows and sends that conversation's own
focus (rec_9 kept), and a conversation with no focus gets none. Ablated:
without the target key, both fail.
- Updated pins that enumerate `ActionType.options` (spec row-update,
undoable, inline; Studio presets and type-switch pins).
## Acceptance notes
- Contract review N4 (an unsent fresh thread's carry lands on a history
conversation picked before the first send; predates this PR, widened by
it): filed as #37276 (claim 7160324153) and fixed here.
`useConversationFocus` takes a key of the dock's target and drops a
hand-off's carry when it changes, so only the id the target resolves, or
the first send mints, takes the carried focus. A pending `follow` is
kept across that change.
- Studio's action inspector does not offer `ask_ai` in its Type picker
(its option list is hand-written); authoring is code / metadata only for
now.
- `params` beside `ask_ai` are not refused (inert); a record-less
location such as `list_toolbar` is not refused at parse — the action is
absent there unless exactly one row is selected, and the runner refuses
a launch that reaches it anyway.
- The global `ConsoleShell` action runtime sits above the chat dock, so
`ask_ai` is absent there; per-view runtimes inside the layout get it.
Direct `useActionRunner` owners get no handler, so `ask_ai` is absent
for them.
- `form.tsx` (update-operation actions only) and the managed-by empty
state are not gated.
- The dashboard-header refusal goes beyond the ADR's words; flagged for
L2 (judged justified in record 7152689299).
- The SKILL.md row does not name the dashboard-header refusal (R7):
adding it puts the file 14 tokens over its ratchet ceiling, so it is
left to #37217.
## Verification
- `@objectstack/spec`: full suite 892 files / 28329 tests pass.
- `@objectstack/runtime`: typecheck pass; ask_ai + declarative-update
tests pass.
- `@object-ui/core` 4789, `@object-ui/react` 1601,
`@object-ui/components` 4966, `@object-ui/plugin-grid` 2783,
`@object-ui/plugin-detail` 3941 tests pass; type-check passes on all six
ui packages.
- `@object-ui/app-shell`: hooks, console, metadata-admin, studio-design
and `DeclaredActionsBar` tests pass (1204 files after the two pin
fixes).
- Review round (R1–R6) and the three CI failures at `076ed686`:
`@object-ui/core` 248 files / 4792 pass; plugin-grid `__tests__` +
components 272 files pass; plugin-detail RelatedList /
RecordRelatedListRenderer 73 files pass; app-shell layout + hooks +
console/home 311 files pass, views 220 files pass;
`@objectstack/example-showcase` 49 files / 554 pass; type-check passes
on core, plugin-grid, plugin-detail, app-shell. New tests each turn red
when their fix is removed (list header 3/3, bulk bar 1/1, related-list
toolbar 1/1, and the two CI-red AppHeader files fail again with the old
import).
- Gates derived by `scripts/pm/dispatch-gates.mjs --commands` for this
change set (131 commands): all pass except three that could not measure
in this container — `check-plugin-teardown-shape --self-test` (needs an
unshallow clone), `check:dual-build-cjs-loads` (needs every package's
`dist/`); `check:skill-examples` passed on a re-run once the spec build
had finished. CI runs them in full.
- ESLint on every changed source and test file: 0 errors.
Clause-②: yes
Metadata-protocol: added
Skills-docs: follow-up #37217
## 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.
- [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.
- [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 by [Claude Code](https://claude.ai/code)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 012f0a1 commit b7dee0e
61 files changed
Lines changed: 1776 additions & 122 deletions
File tree
- .changeset
- content/docs
- protocol/objectui
- references
- data
- kernel
- ui
- ui
- examples/app-showcase/src
- system/translations
- ui
- actions
- pages
- packages
- runtime/src
- spec/src/ui
- skills/objectstack-ui
- ui/packages
- app-shell/src
- console
- __tests__
- hooks
- __tests__
- layout
- __tests__
- views
- __tests__
- metadata-admin
- inspectors
- previews
- studio-design
- components/src/renderers
- action
- basic
- complex
- layout
- core/src/actions
- __tests__
- plugin-detail/src
- __tests__
- plugin-grid/src
- __tests__
- components
- react/src/context
- __tests__
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
224 | 225 | | |
225 | 226 | | |
226 | 227 | | |
227 | | - | |
| 228 | + | |
228 | 229 | | |
229 | 230 | | |
230 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
524 | | - | |
| 524 | + | |
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
332 | | - | |
| 332 | + | |
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
| 422 | + | |
422 | 423 | | |
423 | 424 | | |
424 | 425 | | |
| |||
429 | 430 | | |
430 | 431 | | |
431 | 432 | | |
432 | | - | |
| 433 | + | |
433 | 434 | | |
434 | 435 | | |
435 | 436 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
| 221 | + | |
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
| 228 | + | |
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| |||
0 commit comments