Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/37364-record-citation-verifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@objectstack/spec': minor
'@objectstack/service-record-context': minor
---

feat(ai): the record citation shape enters spec, with the verifier that checks a citation's quote as the asking user (ADR-0160 D9)

Clause-②: yes
Metadata-protocol: added
Skills-docs: follow-up #37177

An AI answer about a record may carry citations: the passage of the record it rests on.

- **`@objectstack/spec/ai`**: `RecordCitationSchema` is `{ object, id, context?, anchor?, quote }`, closed (an unknown key is refused), with `quote` required and non-empty. `RecordCitationsSchema` is a list of at most `RECORD_CITATIONS_MAX` (20). `RECORD_CITATIONS_PART_TYPE` (`data-record-citations`) names the UI-message data part a verified list rides. `headingsOf` and `stripBodyTags` (`record-body-anchor.ts`) derive a body's headings and anchors, so the server and a surface that opens a record at a cited anchor derive the same anchor.
- **`@objectstack/service-record-context`**: `verifyRecordCitations(citations, door)` returns the citations that survive. For each distinct `(object, id, context, anchor)` it calls `get_record_context` once, through the door bound to the asking user, and keeps a citation only when its `quote` is found in that answer's data member: a field or related-list cell `value` (when it is a string) or `display`, or the body `text` (an `html`/`richtext` body also with its tags removed). Whitespace runs collapse; case and every other character must agree. Notes, the framing sentence and labels are never matched. A refused call (a pack that does not exist, several packs and no `context`, an anchor that does not resolve, a record the caller cannot read) drops its citations. It never throws for a citation, and it reads at most the first 20 entries.

Nothing produces or draws citations yet: the producer persists the verified list with the message, and surfaces draw it without re-verifying.
3 changes: 2 additions & 1 deletion content/docs/references/ai/index.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: AI Protocol — complete schema reference
navTitle: AI Protocol
description: "The ObjectStack AI Protocol in 16 reference pages: every schema in @objectstack/spec with its properties, types, defaults and a TypeScript example."
description: "The ObjectStack AI Protocol in 17 reference pages: every schema in @objectstack/spec with its properties, types, defaults and a TypeScript example."
---

{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}
Expand All @@ -20,6 +20,7 @@ This section contains all protocol schemas for the ai layer of ObjectStack.
<Card href="/docs/references/ai/mcp" title="Mcp" description="Source: packages/spec/src/ai/mcp.zod.ts" />
<Card href="/docs/references/ai/model-registry" title="Model Registry" description="Source: packages/spec/src/ai/model-registry.zod.ts" />
<Card href="/docs/references/ai/object-query-source" title="Object Query Source" description="Source: packages/spec/src/ai/object-query-source.zod.ts" />
<Card href="/docs/references/ai/record-citation" title="Record Citation" description="Source: packages/spec/src/ai/record-citation.zod.ts" />
<Card href="/docs/references/ai/record-context-tools" title="Record Context Tools" description="Source: packages/spec/src/ai/record-context-tools.zod.ts" />
<Card href="/docs/references/ai/skill" title="Skill" description="Source: packages/spec/src/ai/skill.zod.ts" />
<Card href="/docs/references/ai/solution-blueprint" title="Solution Blueprint" description="Source: packages/spec/src/ai/solution-blueprint.zod.ts" />
Expand Down
1 change: 1 addition & 0 deletions content/docs/references/ai/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"build-progress",
"dataset-tools",
"object-query-source",
"record-citation",
"record-context-tools"
]
}
79 changes: 79 additions & 0 deletions content/docs/references/ai/record-citation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: Record Citation schema — AI Protocol reference
navTitle: Record Citation
description: "A record citation — the passage of a record an answer rests on. One citation is { object, id, context?, anchor?, quote }."
---

{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}

A record citation — the passage of a record an answer rests on
(ADR-0160 D9, as amended a third time).

One citation is `{ object, id, context?, anchor?, quote }`. It is the record
sibling of a dataset answer's `sourceLine` (`dataset-tools.zod.ts`), with one
difference: a dataset answer's provenance is composed by the tool, while a
citation is written by the model, so it is a claim. The shape lets the
platform check the claim without a model: `quote` must be found verbatim in
the data member of what `get_record_context` answers for `object`, `id`,
`context` and `anchor` to the asking user (`record-context-tools.zod.ts`,
`RecordContextDataSchema`).

- `object`, `id` name the root record of the pack the statement was read
through. A quote taken from a related row still names the root.
- `context` names that pack, spelt as `get_record_context`'s `context`
argument takes it. It may be omitted when the object has one pack; on an
object with several, a citation without it is not verified.
- `anchor` is a heading of the root record's body, as the body outline
issued it (`record-body-anchor.ts`, `headingsOf`). Omitted when the
citation is to the record as a whole or to a field.
- `quote` is the passage relied on, verbatim from text the tool returned.

A citation is verified once, when the answer is produced, by the platform
as the asking user; one whose quote is not found, or whose verifying call is
refused, is dropped before the answer is shown. The verified list is
persisted with the message, and no surface re-verifies it on display. The
verifier is `@objectstack/service-record-context`'s `verifyRecordCitations`;
only the shapes are spec.

The verified list rides an answer as a UI-message data part named
`RECORD_CITATIONS_PART_TYPE`, whose `data` is a
`RecordCitationsSchema` list.

<Callout type="info">
**Source:** `packages/spec/src/ai/record-citation.zod.ts`
</Callout>

## TypeScript Usage

```typescript
import { RecordCitationSchema, RecordCitationsSchema } from '@objectstack/spec/ai';
import type { RecordCitation, RecordCitations } from '@objectstack/spec/ai';

// Validate data
const result = RecordCitationSchema.parse(data);
```

---

## RecordCitation

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **object** | `string` | ✅ | The root record's object, as `get_record_context` was called with it |
| **id** | `string` | ✅ | The root record's id |
| **context** | `string` | optional | The context pack the record was read through, spelt as `get_record_context`'s `context` argument takes it. Omit it only when the object has one pack |
| **anchor** | `string` | optional | A heading of the root record's body, by the `anchor` the body outline issued. Omit it when the citation is to the record as a whole or to a field |
| **quote** | `string` | ✅ | The passage relied on, verbatim from text the tool returned |


---

## RecordCitations

**Type:** `{ object: string; id: string; context?: string; anchor?: string; … }[]`


---

9 changes: 5 additions & 4 deletions content/docs/references/index.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Protocol reference — every schema by module
navTitle: Protocol Reference
description: Every schema published by @objectstack/spec — 1733 schemas across 14 protocol modules
description: Every schema published by @objectstack/spec — 1735 schemas across 14 protocol modules
---

{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}
Expand All @@ -20,7 +20,7 @@ counts are sums of the rows they head. Regenerate with

| Module | Pages | Schemas | Description |
| :--- | ---: | ---: | :--- |
| [AI Protocol](/docs/references/ai) | 16 | 100 | Agents, tools, skills, RAG and knowledge sources, model registry, conversations. |
| [AI Protocol](/docs/references/ai) | 17 | 102 | Agents, tools, skills, RAG and knowledge sources, model registry, conversations. |
| [API Protocol](/docs/references/api) | 37 | 524 | REST contracts, endpoints, routing, realtime, batch, discovery. |
| [Automation Protocol](/docs/references/automation) | 16 | 82 | Flows and their nodes, approvals, ETL pipelines, webhooks, state machines, execution records. |
| [Data Protocol](/docs/references/data) | 35 | 197 | Objects, fields, queries, filters, datasources and drivers — the ObjectQL layer. |
Expand All @@ -34,13 +34,13 @@ counts are sums of the rows they head. Regenerate with
| [Studio Protocol](/docs/references/studio) | 3 | 35 | Studio designer metadata — the authoring surfaces for the protocols above. |
| [System Protocol](/docs/references/system) | 40 | 298 | The runtime environment — logging, jobs, cache, metrics, notifications, i18n and compliance. |
| [UI Protocol](/docs/references/ui) | 16 | 184 | Apps, pages, views, dashboards, reports, actions and themes — the ObjectUI layer. |
| **Total** | **221** | **1733** | 14 protocol modules |
| **Total** | **222** | **1735** | 14 protocol modules |

---

## AI Protocol

**Source:** `packages/spec/src/ai/` · **Import:** `@objectstack/spec/ai` · **16 pages, 100 schemas**
**Source:** `packages/spec/src/ai/` · **Import:** `@objectstack/spec/ai` · **17 pages, 102 schemas**

Agents, tools, skills, RAG and knowledge sources, model registry, conversations.

Expand All @@ -57,6 +57,7 @@ Agents, tools, skills, RAG and knowledge sources, model registry, conversations.
| [`mcp.zod.ts`](/docs/references/ai/mcp) | `MCPApprovalPolicy`, `MCPServerRef`, `MCPToolBinding`, `MCPTransport`, `McpActionNamespace`, `McpListedActionAddress` |
| [`model-registry.zod.ts`](/docs/references/ai/model-registry) | `ModelCapability`, `ModelConfig`, `ModelLimits`, `ModelPricing`, `ModelProvider`, `ModelRegistry`, `ModelRegistryEntry`, `ModelSelectionCriteria`, `PromptTemplate`, `PromptVariable` |
| [`object-query-source.zod.ts`](/docs/references/ai/object-query-source) | `ObjectQuerySource` |
| [`record-citation.zod.ts`](/docs/references/ai/record-citation) | `RecordCitation`, `RecordCitations` |
| [`record-context-tools.zod.ts`](/docs/references/ai/record-context-tools) | `GetRecordContextInput`, `GetRecordContextOutput`, `RecordContextBody`, `RecordContextData`, `RecordContextFieldEntry`, `RecordContextNote`, `RecordContextNoteKind`, `RecordContextOutlineEntry`, `RecordContextRelatedList`, `RecordContextRelatedRow` |
| [`skill.zod.ts`](/docs/references/ai/skill) | `Skill`, `SkillTriggerCondition` |
| [`solution-blueprint.zod.ts`](/docs/references/ai/solution-blueprint) | `BlueprintApp`, `BlueprintCondition`, `BlueprintDashboard`, `BlueprintField`, `BlueprintNavItem`, `BlueprintObject`, `BlueprintSeed`, `BlueprintSummaryOperations`, `BlueprintView`, `BlueprintWidgetCondition`, `SolutionBlueprint`, `SolutionBlueprintStrict` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ hand-patch a number here** — fix the code or the verdict and regenerate.

| Dir | Sites |
|---|---|
| `ai/` | 113 |
| `ai/` | 114 |
Loading
Loading