@happyvertical/smrt-content 0.49.3 → 0.49.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/content-query-JaCGj01O.js +4092 -0
- package/dist/chunks/{content-query-CmjfYsO9.js.map → content-query-JaCGj01O.js.map} +1 -1
- package/dist/chunks/{content-versions-DzjCS3xs.js → content-versions-qIuk5bbv.js} +2 -2
- package/dist/chunks/{content-versions-DzjCS3xs.js.map → content-versions-qIuk5bbv.js.map} +1 -1
- package/dist/chunks/{contents-vywEFhzL.js → contents-DZaQwoRH.js} +2 -2
- package/dist/chunks/{contents-vywEFhzL.js.map → contents-DZaQwoRH.js.map} +1 -1
- package/dist/index.js +4 -4
- package/dist/manifest.json +1324 -116
- package/dist/server/content-list-actions.d.ts +4 -2
- package/dist/server/content-list-actions.d.ts.map +1 -1
- package/dist/server/content-list-lifecycle.d.ts +1 -1
- package/dist/server/content-list-lifecycle.d.ts.map +1 -1
- package/dist/server.js +6 -2
- package/dist/server.js.map +1 -1
- package/dist/smrt-knowledge.json +8 -8
- package/package.json +18 -17
- package/dist/chunks/content-query-CmjfYsO9.js +0 -4092
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { PrincipalRun } from '@happyvertical/smrt-agents';
|
|
2
2
|
import { createDataSurfaceActionAdapter, DataSurfaceActionAdapter, DataSurfaceActionStateStore, DataSurfaceBackgroundQueue, DataSurfaceServerActionContext, DataSurfaceServerActionRequest } from '@happyvertical/smrt-agents/server';
|
|
3
|
-
import { DataQueryRequest } from '@happyvertical/smrt-types';
|
|
4
|
-
import { DataSurfaceActionResult, DataSurfaceDescriptor, DataSurfaceIdentity, DataSurfaceJsonObject, DataSurfaceJsonValue } from '@happyvertical/smrt-ui/data';
|
|
3
|
+
import { DataQueryRequest, DataSurfaceActionResult, DataSurfaceDescriptor, DataSurfaceIdentity, DataSurfaceJsonObject, DataSurfaceJsonValue } from '@happyvertical/smrt-types';
|
|
5
4
|
import { ContentBodyFormat } from '../body-format.js';
|
|
6
5
|
import { Content } from '../content.js';
|
|
7
6
|
import { ContentQueryCollection, ContentQueryScope } from '../content-query.js';
|
|
@@ -113,6 +112,9 @@ export interface ContentListActionAdapterOptions {
|
|
|
113
112
|
authorize?: (workflow: ContentListServerActionId, run: PrincipalRun) => boolean | Promise<boolean>;
|
|
114
113
|
handlers?: ContentListWorkflowHandlers;
|
|
115
114
|
backgroundQueue?: DataSurfaceBackgroundQueue;
|
|
115
|
+
backgroundHandlerId?: string;
|
|
116
|
+
/** In-process secret used to authenticate the durable background envelope. */
|
|
117
|
+
deferredEnvelopeSigningKey?: string | Uint8Array;
|
|
116
118
|
descriptor?: DataSurfaceDescriptor;
|
|
117
119
|
maxSelectionSize?: number;
|
|
118
120
|
representativeLimit?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-list-actions.d.ts","sourceRoot":"","sources":["../../src/server/content-list-actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,OAAO,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,YAAY,EAElB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,8BAA8B,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,8BAA8B,EAEnC,KAAK,8BAA8B,EAEpC,MAAM,mCAAmC,CAAC;AAM3C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"content-list-actions.d.ts","sourceRoot":"","sources":["../../src/server/content-list-actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,OAAO,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,YAAY,EAElB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,8BAA8B,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,8BAA8B,EAEnC,KAAK,8BAA8B,EAEpC,MAAM,mC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O,8BAA8B,CACtC,CAAC,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC;CAClC;AAkkBD,MAAM,WAAW,wBAAyB,SAAQ,wBAAwB;IACxE,OAAO,CACL,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACpC,KAAK,CACH,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACrC;AAED,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,wBAAwB,CAqU1B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataSurfaceServerActionContext } from '@happyvertical/smrt-agents/server';
|
|
2
|
-
import { DataSurfaceActionResult } from '@happyvertical/smrt-
|
|
2
|
+
import { DataSurfaceActionResult } from '@happyvertical/smrt-types';
|
|
3
3
|
import { ContentListActionAdapter } from './content-list-actions.js';
|
|
4
4
|
export interface ContentListLifecycleService {
|
|
5
5
|
invoke(request: unknown, context: DataSurfaceServerActionContext): Promise<DataSurfaceActionResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-list-lifecycle.d.ts","sourceRoot":"","sources":["../../src/server/content-list-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,KAAK,EACV,uBAAuB,EAExB,MAAM,
|
|
1
|
+
{"version":3,"file":"content-list-lifecycle.d.ts","sourceRoot":"","sources":["../../src/server/content-list-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,KAAK,EACV,uBAAuB,EAExB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,KAAK,wBAAwB,EAG9B,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,2BAA2B;IAC1C,MAAM,CACJ,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,gCAAgC;IAC/C,OAAO,EAAE,wBAAwB,CAAC;IAClC,yEAAyE;IACzE,OAAO,CACL,OAAO,EAAE,OAAO,GACf,8BAA8B,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;CAC7E;AA6CD,mFAAmF;AACnF,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,wBAAwB,GAChC,2BAA2B,CAgB7B;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,gCAAgC,GACxC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAoCzC"}
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as assertContentQuerySchema, t as CONTENT_QUERY_CLASS_NAME, v as buildContentQuerySchema, w as Content, x as executeContentQuery } from "./chunks/content-query-
|
|
1
|
+
import { _ as assertContentQuerySchema, t as CONTENT_QUERY_CLASS_NAME, v as buildContentQuerySchema, w as Content, x as executeContentQuery } from "./chunks/content-query-JaCGj01O.js";
|
|
2
2
|
import { MAX_DATA_QUERY_PAGE_LIMIT, createDataQueryFingerprint, normalizeDataQueryRequest, startRestServer } from "@happyvertical/smrt-core";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -845,6 +845,7 @@ function createContentListActionAdapter(options) {
|
|
|
845
845
|
putToken: (...args) => options.state.putToken(...args),
|
|
846
846
|
getToken: (...args) => options.state.getToken(...args),
|
|
847
847
|
markTokenConsumed: (...args) => options.state.markTokenConsumed(...args),
|
|
848
|
+
consumeTokenAndReserveIdempotency: (...args) => options.state.consumeTokenAndReserveIdempotency(...args),
|
|
848
849
|
getIdempotency: (...args) => options.state.getIdempotency(...args),
|
|
849
850
|
reserveIdempotency: (...args) => options.state.reserveIdempotency(...args),
|
|
850
851
|
completeIdempotency: (key, ownerToken, result) => {
|
|
@@ -857,6 +858,8 @@ function createContentListActionAdapter(options) {
|
|
|
857
858
|
releaseIdempotency: (...args) => options.state.releaseIdempotency(...args)
|
|
858
859
|
},
|
|
859
860
|
backgroundQueue: options.backgroundQueue,
|
|
861
|
+
backgroundHandlerId: options.backgroundHandlerId,
|
|
862
|
+
deferredEnvelopeSigningKey: options.deferredEnvelopeSigningKey,
|
|
860
863
|
tokenTtlMs: options.tokenTtlMs,
|
|
861
864
|
runAsPrincipal: options.runAsPrincipal,
|
|
862
865
|
resolveDeferredPrincipal: options.resolveDeferredPrincipal,
|
|
@@ -935,7 +938,8 @@ function createContentListActionAdapter(options) {
|
|
|
935
938
|
}
|
|
936
939
|
return {
|
|
937
940
|
preview: (request, context) => invoke("preview", request, context),
|
|
938
|
-
apply: (request, context) => invoke("apply", request, context)
|
|
941
|
+
apply: (request, context) => invoke("apply", request, context),
|
|
942
|
+
executeDeferred: (envelope) => generic.executeDeferred(envelope)
|
|
939
943
|
};
|
|
940
944
|
}
|
|
941
945
|
//#endregion
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":["workflow"],"sources":["../src/server/content-list-actions.ts","../src/server/content-list-data-surface.ts","../src/server/content-list-lifecycle.ts","../src/server.ts"],"sourcesContent":["/**\n * Principal-bound ContentList bulk workflows (#2453).\n *\n * The generic action adapter owns confirmation tokens, idempotency, principal\n * execution, permission checks, per-row outcomes, and background acceptance.\n * This module supplies the content-specific half: declarative workflows,\n * canonical query resolution, row-revision binding, governance eligibility,\n * and domain mutations.\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { createHash } from 'node:crypto';\n// Publication and automated-review permissions include facts operations. The\n// catalog is registration-driven, so ensure those definitions exist even when\n// a host imports only the content server entry point.\nimport '@happyvertical/smrt-facts';\nimport {\n type PrincipalRun,\n PrincipalToolNotAllowedError,\n} from '@happyvertical/smrt-agents';\nimport {\n createDataSurfaceActionAdapter,\n type DataSurfaceActionAdapter,\n type DataSurfaceActionStateStore,\n type DataSurfaceBackgroundQueue,\n type DataSurfaceServerActionContext,\n type DataSurfaceServerActionDefinition,\n type DataSurfaceServerActionRequest,\n isBoundedDataSurfaceJsonValue,\n} from '@happyvertical/smrt-agents/server';\nimport {\n createDataQueryFingerprint,\n MAX_DATA_QUERY_PAGE_LIMIT,\n normalizeDataQueryRequest,\n} from '@happyvertical/smrt-core';\nimport type { DataQueryRequest } from '@happyvertical/smrt-types';\nimport type {\n DataSurfaceActionResult,\n DataSurfaceDescriptor,\n DataSurfaceIdentity,\n DataSurfaceJsonObject,\n DataSurfaceJsonValue,\n DataSurfaceRowId,\n} from '@happyvertical/smrt-ui/data';\nimport type { ContentBodyFormat } from '../body-format.js';\nimport type { Content } from '../content.js';\nimport {\n buildContentQuerySchema,\n CONTENT_QUERY_MAX_PAGE_LIMIT,\n type ContentQueryCollection,\n type ContentQueryScope,\n executeContentQuery,\n} from '../content-query.js';\n\nexport const CONTENT_LIST_WORKFLOW_IDS = [\n 'move-to-trash',\n 'mark-draft',\n 'submit-review',\n 'publish',\n 'archive',\n 'restore',\n 'automated-review',\n 'format-body',\n 'categorize',\n 'optimize',\n] as const;\n\nexport type ContentListWorkflowId = (typeof CONTENT_LIST_WORKFLOW_IDS)[number];\nexport const CONTENT_LIST_LIFECYCLE_ACTION_IDS = [\n 'move-to-trash',\n 'restore',\n 'permanent-delete',\n] as const;\nexport type ContentListLifecycleActionId =\n (typeof CONTENT_LIST_LIFECYCLE_ACTION_IDS)[number];\nexport type ContentListServerActionId =\n | ContentListWorkflowId\n | ContentListLifecycleActionId;\nexport type ContentListWorkflowExecution = 'foreground' | 'background';\nexport type ContentListWorkflowConfirmation = 'required' | 'none';\n\nexport interface ContentListWorkflowDescriptor {\n id: ContentListServerActionId;\n label: string;\n description: string;\n selectionScopes: Array<'current-page' | 'explicit-ids' | 'all-matching'>;\n sensitivity: 'public' | 'sensitive';\n confirmation: ContentListWorkflowConfirmation;\n execution: ContentListWorkflowExecution;\n inputSchema: DataSurfaceJsonObject | null;\n eligibility: string[];\n permissionRequirements: {\n tool: string;\n operations: Array<{ id: string; collection: string; action: string }>;\n };\n consequences: string[];\n partialResult: {\n statuses: Array<'accepted' | 'skipped' | 'failed'>;\n preservesFailedSelection: true;\n };\n}\n\nconst ALL_SELECTION_SCOPES: ContentListWorkflowDescriptor['selectionScopes'] = [\n 'current-page',\n 'explicit-ids',\n 'all-matching',\n];\n\nconst NO_INPUT: DataSurfaceJsonObject = {\n type: 'object',\n additionalProperties: false,\n};\n\nconst OPTIONAL_REVIEW_INPUT: DataSurfaceJsonObject = {\n type: 'object',\n additionalProperties: false,\n properties: {\n kind: { type: 'string', enum: ['facts', 'safety', 'custom'] },\n policyKey: { type: 'string', maxLength: 128 },\n },\n};\n\nconst CONTENT_UPDATE_OPERATION = {\n id: 'contents:update',\n collection: 'contents',\n action: 'update',\n};\n\nconst CONTENT_READ_OPERATION = {\n id: 'contents:read',\n collection: 'contents',\n action: 'read',\n};\n\nconst GOVERNANCE_READ_OPERATIONS = [\n {\n id: 'content-governance-assignments:read',\n collection: 'contentgovernanceassignments',\n action: 'read',\n },\n {\n id: 'content-governance-policies:read',\n collection: 'contentgovernancepolicies',\n action: 'read',\n },\n {\n id: 'content-governance-profiles:read',\n collection: 'contentgovernanceprofiles',\n action: 'read',\n },\n] as const;\n\nconst PUBLICATION_OPERATIONS = [\n CONTENT_READ_OPERATION,\n CONTENT_UPDATE_OPERATION,\n ...GOVERNANCE_READ_OPERATIONS,\n {\n id: 'content-references:read',\n collection: 'contentreferences',\n action: 'read',\n },\n {\n id: 'content-assets:read',\n collection: 'contentassets',\n action: 'read',\n },\n { id: 'assets:read', collection: 'assets', action: 'read' },\n { id: 'facts:read', collection: 'facts', action: 'read' },\n { id: 'fact-contents:read', collection: 'factcontents', action: 'read' },\n { id: 'fact-sources:read', collection: 'factsources', action: 'read' },\n { id: 'content-reviews:read', collection: 'contentreviews', action: 'read' },\n {\n id: 'content-corrections:read',\n collection: 'contentcorrections',\n action: 'read',\n },\n {\n id: 'content-versions:read',\n collection: 'contentversions',\n action: 'read',\n },\n {\n id: 'content-versions:create',\n collection: 'contentversions',\n action: 'create',\n },\n] as const;\n\nconst AUTOMATED_REVIEW_OPERATIONS = [\n ...PUBLICATION_OPERATIONS,\n {\n id: 'prompt-overrides:read',\n collection: 'promptoverrides',\n action: 'read',\n },\n {\n id: 'content-reviews:create',\n collection: 'contentreviews',\n action: 'create',\n },\n] as const;\n\nexport const CONTENT_LIST_WORKFLOWS: readonly ContentListWorkflowDescriptor[] =\n Object.freeze([\n workflow('move-to-trash', 'Move to trash', {\n description: 'Soft-delete eligible content into the trash lifecycle.',\n sensitivity: 'sensitive',\n eligibility: ['content is not already deleted'],\n consequences: [\n 'Content leaves active views and becomes restorable from trash.',\n ],\n }),\n workflow('mark-draft', 'Mark draft', {\n description: 'Return eligible active content to draft.',\n eligibility: ['content is not deleted', 'content is not already draft'],\n consequences: ['Published content is no longer public.'],\n }),\n workflow('submit-review', 'Submit for review', {\n description: 'Move eligible draft content into editorial review.',\n eligibility: ['content is draft'],\n consequences: ['Content enters the review queue.'],\n }),\n workflow('publish', 'Publish', {\n description: 'Publish content that passes current governance readiness.',\n sensitivity: 'sensitive',\n eligibility: [\n 'content is draft, review, or archived',\n 'publication readiness passes',\n ],\n consequences: [\n 'Content becomes public and may create a publication snapshot.',\n ],\n permissionRequirements: {\n tool: 'content.workflow.publish',\n operations: [...PUBLICATION_OPERATIONS],\n },\n }),\n workflow('archive', 'Archive', {\n description: 'Remove eligible content from active publication workflows.',\n eligibility: [\n 'content is not deleted',\n 'content is not already archived',\n ],\n consequences: ['Published content is no longer public.'],\n }),\n workflow('restore', 'Restore', {\n description: 'Restore deleted content to an explicit eligible status.',\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['status'],\n properties: {\n status: { enum: ['draft', 'review', 'published'] },\n },\n },\n eligibility: [\n 'content is deleted',\n 'requested destination is valid',\n 'publish readiness passes when publishing',\n ],\n consequences: [\n 'Content leaves trash.',\n 'Publishing makes content public.',\n ],\n permissionRequirements: {\n tool: 'content.workflow.restore',\n operations: [...PUBLICATION_OPERATIONS],\n },\n }),\n workflow('automated-review', 'Automated review', {\n description: 'Run the configured content governance review.',\n execution: 'background',\n inputSchema: OPTIONAL_REVIEW_INPUT,\n eligibility: [\n 'content is not deleted',\n 'content governance is configured',\n ],\n consequences: [\n 'Creates a review result and may create a review version.',\n ],\n permissionRequirements: {\n tool: 'content.workflow.automated-review',\n operations: [...AUTOMATED_REVIEW_OPERATIONS],\n },\n }),\n workflow('format-body', 'Format body', {\n description: 'Run the application-owned body-formatting workflow.',\n execution: 'background',\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n properties: { format: { enum: ['markdown', 'html'] } },\n },\n eligibility: [\n 'content is not deleted',\n 'a formatting handler is configured',\n ],\n consequences: ['The persisted content body may change.'],\n permissionRequirements: {\n tool: 'content.workflow.format-body',\n operations: [...PUBLICATION_OPERATIONS],\n },\n }),\n workflow('categorize', 'Categorize', {\n description: 'Assign one required hierarchical category path.',\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['category'],\n properties: {\n category: { type: 'string', minLength: 1, maxLength: 256 },\n },\n },\n eligibility: ['content is not deleted', 'category is non-empty'],\n consequences: ['The content category changes.'],\n permissionRequirements: {\n tool: 'content.workflow.categorize',\n operations: [...PUBLICATION_OPERATIONS],\n },\n }),\n workflow('optimize', 'Optimize / complete', {\n description: 'Run the application-owned content optimization workflow.',\n execution: 'background',\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n properties: { instructions: { type: 'string', maxLength: 4096 } },\n },\n eligibility: [\n 'content is draft or review',\n 'an optimization handler is configured',\n ],\n consequences: ['Content fields may be revised or completed.'],\n }),\n ]);\n\nconst PERMANENT_DELETE_ACTION: ContentListWorkflowDescriptor = workflow(\n 'permanent-delete',\n 'Delete permanently',\n {\n description: 'Permanently delete content that is already in trash.',\n sensitivity: 'sensitive',\n eligibility: ['content is deleted'],\n consequences: [\n 'Content and its owned lifecycle data are irreversibly deleted.',\n ],\n permissionRequirements: {\n tool: 'content.lifecycle.permanent-delete',\n operations: [\n CONTENT_READ_OPERATION,\n {\n id: 'contents:delete',\n collection: 'contents',\n action: 'delete',\n },\n ],\n },\n },\n);\n\n/** The lifecycle-only catalog exposed by the dedicated route/service. */\nexport const CONTENT_LIST_LIFECYCLE_ACTIONS: readonly ContentListWorkflowDescriptor[] =\n Object.freeze([\n contentListWorkflow('move-to-trash'),\n contentListWorkflow('restore'),\n PERMANENT_DELETE_ACTION,\n ]);\n\nconst CONTENT_LIST_SERVER_ACTIONS: readonly ContentListWorkflowDescriptor[] =\n Object.freeze([...CONTENT_LIST_WORKFLOWS, PERMANENT_DELETE_ACTION]);\n\nfunction contentListWorkflow(\n id: ContentListWorkflowId,\n): ContentListWorkflowDescriptor {\n const descriptor = CONTENT_LIST_WORKFLOWS.find((entry) => entry.id === id);\n if (!descriptor) throw new Error(`Missing ContentList workflow: ${id}`);\n return descriptor;\n}\n\nfunction workflow(\n id: ContentListServerActionId,\n label: string,\n options: Partial<ContentListWorkflowDescriptor> &\n Pick<\n ContentListWorkflowDescriptor,\n 'description' | 'eligibility' | 'consequences'\n >,\n): ContentListWorkflowDescriptor {\n return {\n id,\n label,\n description: options.description,\n selectionScopes: options.selectionScopes ?? [...ALL_SELECTION_SCOPES],\n sensitivity: options.sensitivity ?? 'public',\n confirmation: options.confirmation ?? 'required',\n execution: options.execution ?? 'foreground',\n inputSchema: options.inputSchema ?? NO_INPUT,\n eligibility: options.eligibility,\n permissionRequirements: options.permissionRequirements ?? {\n tool: `content.workflow.${id}`,\n operations: [CONTENT_READ_OPERATION, CONTENT_UPDATE_OPERATION],\n },\n consequences: options.consequences,\n partialResult: {\n statuses: ['accepted', 'skipped', 'failed'],\n preservesFailedSelection: true,\n },\n };\n}\n\nexport interface ContentListActionTarget {\n /** Canonical query sent to the content query endpoint. Required except for explicit IDs. */\n query?: DataQueryRequest;\n /** Count visible at selection time; drift fails the preview/apply. */\n expectedCount: number;\n /** Operator-entered preview count, required only for permanent-delete apply. */\n confirmedCount?: number;\n}\n\nexport interface ContentListActionRequest\n extends DataSurfaceServerActionRequest {\n actionId: ContentListServerActionId;\n target: ContentListActionTarget;\n}\n\nexport interface ContentListActionCollection extends ContentQueryCollection {\n get(filter: string | Record<string, unknown>): Promise<Content | null>;\n}\n\n/**\n * Persistence-free copy supplied to host format/optimize handlers.\n *\n * Only the explicitly copied mutable fields are applied back to Content before\n * the adapter's revision-guarded save. Identity, tenancy, lifecycle state,\n * relationship IDs, database handles, and Content persistence methods are\n * deliberately absent.\n */\nexport interface ContentListWorkflowDraft {\n readonly contentId: string;\n readonly tenantId: string | null;\n readonly type: string | null;\n readonly variant: string | null;\n readonly status: Content['status'];\n readonly state: Content['state'];\n fileKey: string | null;\n author: string | null;\n name: string;\n title: string;\n description: string | null;\n body: string;\n bodyFormat: ContentBodyFormat | null;\n publish_date: Date | null;\n url: string | null;\n source: string | null;\n original_url: string | null;\n language: string | null;\n tags: string[];\n category: string | null;\n metadata: Record<string, unknown>;\n thumbnailAssetId: string | null;\n}\n\nexport interface ContentListWorkflowHandlers {\n /** Mutate a persistence-free draft; the adapter applies it by revision CAS. */\n formatBody?: (\n content: ContentListWorkflowDraft,\n payload: DataSurfaceJsonValue | undefined,\n run: PrincipalRun,\n ) => Promise<void>;\n /** Mutate a persistence-free draft; the adapter applies it by revision CAS. */\n optimize?: (\n content: ContentListWorkflowDraft,\n payload: DataSurfaceJsonValue | undefined,\n run: PrincipalRun,\n ) => Promise<void>;\n}\n\nexport interface ContentListWorkflowStorage {\n adapterType: 'sqlite' | 'postgres' | 'duckdb' | 'json';\n writeStrategy?: 'immediate' | 'manual' | 'none';\n}\n\nexport class UnsupportedContentListWorkflowStorageError extends Error {\n readonly code = 'UNSUPPORTED_CONTENT_LIST_WORKFLOW_STORAGE';\n\n constructor(storage: ContentListWorkflowStorage) {\n super(\n `ContentList workflows do not support ${storage.adapterType} with ` +\n 'immediate write-back because exported files are not transactionally ' +\n 'rolled back. Use PostgreSQL, SQLite, ordinary DuckDB, or a ' +\n 'non-immediate write strategy.',\n );\n this.name = 'UnsupportedContentListWorkflowStorageError';\n }\n}\n\nexport function assertContentListWorkflowStorageSupported(\n storage: ContentListWorkflowStorage,\n): void {\n const adapterType: unknown = storage?.adapterType;\n const writeStrategy: unknown = storage?.writeStrategy;\n if (\n adapterType !== 'sqlite' &&\n adapterType !== 'postgres' &&\n adapterType !== 'duckdb' &&\n adapterType !== 'json'\n ) {\n throw new TypeError(\n 'ContentList workflow storage adapterType must be sqlite, postgres, duckdb, or json.',\n );\n }\n if (\n writeStrategy !== undefined &&\n writeStrategy !== 'immediate' &&\n writeStrategy !== 'manual' &&\n writeStrategy !== 'none'\n ) {\n throw new TypeError(\n 'ContentList workflow storage writeStrategy must be immediate, manual, or none.',\n );\n }\n const effectiveStrategy =\n adapterType === 'json' ? (writeStrategy ?? 'immediate') : writeStrategy;\n if (\n (adapterType === 'json' || adapterType === 'duckdb') &&\n effectiveStrategy === 'immediate'\n ) {\n throw new UnsupportedContentListWorkflowStorageError({\n adapterType,\n writeStrategy: effectiveStrategy,\n });\n }\n}\n\nexport interface ContentListActionAdapterOptions {\n /** Public adapter capability contract; validated before any workflow state is created. */\n workflowStorage: ContentListWorkflowStorage;\n state: DataSurfaceActionStateStore;\n collection(\n run: PrincipalRun,\n ): ContentListActionCollection | Promise<ContentListActionCollection>;\n /** Trusted site/organization narrowing, applied in addition to tenant context. */\n scope?: (\n run: PrincipalRun,\n ) => ContentQueryScope | undefined | Promise<ContentQueryScope | undefined>;\n /** Server-owned mounted/catalog revision. Defaults to zero for standalone endpoints. */\n revision?: (\n run: PrincipalRun,\n identity: DataSurfaceIdentity,\n ) => number | Promise<number>;\n authorize?: (\n workflow: ContentListServerActionId,\n run: PrincipalRun,\n ) => boolean | Promise<boolean>;\n handlers?: ContentListWorkflowHandlers;\n backgroundQueue?: DataSurfaceBackgroundQueue;\n descriptor?: DataSurfaceDescriptor;\n maxSelectionSize?: number;\n representativeLimit?: number;\n tokenTtlMs?: number;\n /** Test/host seam for principal execution; production defaults to executeAsPrincipal. */\n runAsPrincipal?: typeof import('@happyvertical/smrt-agents').executeAsPrincipal;\n /** Resolve the live persona/TenantAgent binding before a queued mutation. */\n resolveDeferredPrincipal?: Parameters<\n typeof createDataSurfaceActionAdapter\n >[0]['resolveDeferredPrincipal'];\n}\n\ninterface ResolvedContentSelection {\n revision: number;\n queryFingerprint: string;\n rowIds: DataSurfaceRowId[];\n rows: Array<Record<string, unknown>>;\n representativeLabels: string[];\n scope: ContentListActionRequest['selection']['scope'];\n}\n\nconst REQUIRED_QUERY_FIELDS = ['id', 'title', 'status', 'updated_at'] as const;\nconst DEFAULT_MAX_SELECTION_SIZE = 200;\nconst DEFAULT_REPRESENTATIVE_LIMIT = 5;\n\nclass ContentListActionError extends Error {\n constructor(readonly reason: string) {\n super(reason);\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isPermissionDenied(error: unknown): boolean {\n if (!(error instanceof Error) || error.name !== 'OperationPermissionError')\n return false;\n const decision = (error as Error & { decision?: unknown }).decision;\n return isRecord(decision) && decision.reason === 'permission_denied';\n}\n\nfunction isServerActionId(value: unknown): value is ContentListServerActionId {\n return CONTENT_LIST_SERVER_ACTIONS.some(({ id }) => id === value);\n}\n\nfunction payloadRecord(\n value: DataSurfaceJsonValue | undefined,\n): Record<string, unknown> {\n return isRecord(value) ? value : {};\n}\n\nfunction validPayload(\n workflowId: ContentListServerActionId,\n payload: DataSurfaceJsonValue | undefined,\n): boolean {\n if (payload !== undefined && !isRecord(payload)) return false;\n const value = payloadRecord(payload);\n const keys = Object.keys(value);\n switch (workflowId) {\n case 'restore':\n return (\n keys.length === 1 &&\n typeof value.status === 'string' &&\n ['draft', 'review', 'published'].includes(value.status)\n );\n case 'categorize':\n return (\n keys.length === 1 &&\n typeof value.category === 'string' &&\n value.category.trim().length > 0 &&\n value.category.length <= 256\n );\n case 'automated-review':\n return (\n keys.every((key) => ['kind', 'policyKey'].includes(key)) &&\n (value.kind === undefined ||\n (typeof value.kind === 'string' &&\n ['facts', 'safety', 'custom'].includes(value.kind) &&\n value.kind.length > 0 &&\n value.kind.length <= 64)) &&\n (value.policyKey === undefined ||\n (typeof value.policyKey === 'string' &&\n value.policyKey.length > 0 &&\n value.policyKey.length <= 128))\n );\n case 'format-body':\n return (\n keys.every((key) => key === 'format') &&\n (value.format === undefined ||\n value.format === 'markdown' ||\n value.format === 'html')\n );\n case 'optimize':\n return (\n keys.every((key) => key === 'instructions') &&\n (value.instructions === undefined ||\n (typeof value.instructions === 'string' &&\n value.instructions.length <= 4096))\n );\n default:\n return keys.length === 0;\n }\n}\n\nfunction actionResult(\n request: unknown,\n ok: boolean,\n reason?: string,\n): DataSurfaceActionResult {\n const candidate = isRecord(request) ? request : {};\n const identityCandidate = isRecord(candidate.identity)\n ? candidate.identity\n : {};\n const identity: DataSurfaceIdentity =\n typeof identityCandidate.surfaceId === 'string' &&\n ['table', 'list', 'report', 'custom'].includes(\n String(identityCandidate.kind),\n )\n ? (identityCandidate as unknown as DataSurfaceIdentity)\n : { surfaceId: 'content-list', kind: 'table' };\n return {\n version: 1,\n requestId:\n typeof candidate.requestId === 'string'\n ? candidate.requestId\n : 'invalid-request',\n identity,\n actionId:\n typeof candidate.actionId === 'string' ? candidate.actionId : 'invalid',\n phase: candidate.phase === 'apply' ? 'apply' : 'preview',\n ok,\n ...(reason ? { reason } : {}),\n };\n}\n\nfunction validateTarget(request: unknown): string | undefined {\n if (\n !isRecord(request) ||\n !isServerActionId(request.actionId) ||\n !isRecord(request.target) ||\n !isRecord(request.selection)\n )\n return 'invalid_request';\n const keys = Object.keys(request.target);\n if (\n keys.some(\n (key) =>\n key !== 'query' && key !== 'expectedCount' && key !== 'confirmedCount',\n )\n )\n return 'invalid_request';\n const expectedCount = request.target.expectedCount;\n if (\n typeof expectedCount !== 'number' ||\n !Number.isSafeInteger(expectedCount) ||\n expectedCount < 0\n ) {\n return 'invalid_request';\n }\n const requiresCountAffirmation =\n request.actionId === 'permanent-delete' && request.phase === 'apply';\n if (\n (requiresCountAffirmation &&\n (request.target.confirmedCount !== expectedCount ||\n !Number.isSafeInteger(request.target.confirmedCount))) ||\n (!requiresCountAffirmation && request.target.confirmedCount !== undefined)\n ) {\n return 'confirmation_count_mismatch';\n }\n if (\n request.selection.scope !== 'explicit-ids' &&\n !isRecord(request.target.query)\n ) {\n return 'invalid_request';\n }\n if (\n request.target.query !== undefined &&\n !isBoundedDataSurfaceJsonValue(request.target.query)\n ) {\n return 'invalid_request';\n }\n return undefined;\n}\n\nfunction statusOf(content: Content): string {\n return String(content.status ?? '').toLowerCase();\n}\n\nasync function publishReady(content: Content): Promise<boolean> {\n const governance = await content.resolveGovernance();\n if (!governance.isGoverned || !governance.enforcePublishReadiness)\n return true;\n if (!governance.publicationProfileKey) return false;\n return (await content.evaluateReviewProfile(governance.publicationProfileKey))\n .ready;\n}\n\nasync function eligibility(\n workflowId: ContentListServerActionId,\n content: Content,\n payload: DataSurfaceJsonValue | undefined,\n handlers: ContentListWorkflowHandlers,\n): Promise<{ eligible: boolean; reason?: string }> {\n const status = statusOf(content);\n if (workflowId === 'restore') {\n if (status !== 'deleted') return { eligible: false, reason: 'not_deleted' };\n if (\n payloadRecord(payload).status === 'published' &&\n !(await publishReady(content))\n ) {\n return { eligible: false, reason: 'publish_readiness_failed' };\n }\n return { eligible: true };\n }\n if (workflowId === 'permanent-delete') {\n return status === 'deleted'\n ? { eligible: true }\n : { eligible: false, reason: 'not_deleted' };\n }\n if (status === 'deleted') return { eligible: false, reason: 'deleted' };\n switch (workflowId) {\n case 'move-to-trash':\n return { eligible: true };\n case 'mark-draft':\n return status === 'draft'\n ? { eligible: false, reason: 'already_draft' }\n : { eligible: true };\n case 'submit-review':\n return status === 'draft'\n ? { eligible: true }\n : { eligible: false, reason: 'requires_draft' };\n case 'publish':\n if (!['draft', 'review', 'archived'].includes(status))\n return { eligible: false, reason: 'invalid_status' };\n return (await publishReady(content))\n ? { eligible: true }\n : { eligible: false, reason: 'publish_readiness_failed' };\n case 'archive':\n return status === 'archived'\n ? { eligible: false, reason: 'already_archived' }\n : { eligible: true };\n case 'automated-review': {\n const governance = await content.resolveGovernance();\n if (!governance.isGoverned)\n return { eligible: false, reason: 'governance_unavailable' };\n const input = payloadRecord(payload);\n const policy =\n typeof input.policyKey === 'string'\n ? governance.reviewPolicies.find(\n (entry) => entry.key === input.policyKey,\n )\n : undefined;\n if (typeof input.policyKey === 'string' && !policy)\n return { eligible: false, reason: 'review_policy_unavailable' };\n if (\n typeof input.kind === 'string' &&\n policy &&\n policy.kind !== input.kind\n )\n return { eligible: false, reason: 'review_kind_mismatch' };\n return { eligible: true };\n }\n case 'format-body':\n return handlers.formatBody\n ? { eligible: true }\n : { eligible: false, reason: 'handler_unavailable' };\n case 'categorize':\n return { eligible: true };\n case 'optimize':\n if (!handlers.optimize)\n return { eligible: false, reason: 'handler_unavailable' };\n return ['draft', 'review'].includes(status)\n ? { eligible: true }\n : { eligible: false, reason: 'requires_draft_or_review' };\n }\n}\n\nasync function applyWorkflow(\n workflowId: ContentListServerActionId,\n content: Content,\n expectedUpdatedAt: Date | string,\n payload: DataSurfaceJsonValue | undefined,\n run: PrincipalRun,\n handlers: ContentListWorkflowHandlers,\n): Promise<void> {\n const input = payloadRecord(payload);\n const save = async () => {\n await content.withTransaction((bound) => bound.save({ expectedUpdatedAt }));\n };\n const mutationDraft = (): ContentListWorkflowDraft => ({\n contentId: String(content.id),\n tenantId: content.tenantId,\n type: content.type,\n variant: content.variant,\n status: content.status,\n state: content.state,\n fileKey: content.fileKey,\n author: content.author,\n name: content.name,\n title: content.title,\n description: content.description,\n body: content.body,\n bodyFormat: content.bodyFormat,\n publish_date: content.publish_date,\n url: content.url,\n source: content.source,\n original_url: content.original_url,\n language: content.language,\n tags: [...(content.tags ?? [])],\n category: content.category,\n metadata: structuredClone(content.metadata ?? {}),\n thumbnailAssetId: content.thumbnailAssetId,\n });\n const applyDraft = (draft: ContentListWorkflowDraft) => {\n content.fileKey = draft.fileKey;\n content.author = draft.author;\n content.name = draft.name;\n content.title = draft.title;\n content.description = draft.description;\n content.body = draft.body;\n content.bodyFormat = draft.bodyFormat;\n content.publish_date = draft.publish_date;\n content.url = draft.url;\n content.source = draft.source;\n content.original_url = draft.original_url;\n content.language = draft.language;\n content.tags = [...draft.tags];\n content.category = draft.category;\n content.metadata = structuredClone(draft.metadata);\n content.thumbnailAssetId = draft.thumbnailAssetId;\n };\n const runHandler = async (\n handler: NonNullable<ContentListWorkflowHandlers['formatBody']>,\n ) => {\n const draft = mutationDraft();\n await handler(draft, payload, run);\n applyDraft(draft);\n await save();\n };\n switch (workflowId) {\n case 'move-to-trash':\n content.status = 'deleted';\n await save();\n return;\n case 'mark-draft':\n content.status = 'draft';\n await save();\n return;\n case 'submit-review':\n content.status = 'review';\n await save();\n return;\n case 'publish':\n content.status = 'published';\n await save();\n return;\n case 'archive':\n content.status = 'archived';\n await save();\n return;\n case 'restore':\n content.status = input.status as Content['status'];\n await save();\n return;\n case 'permanent-delete':\n // Content owns cascading references, so a revision-guarded destructive\n // delete must never use the core's documented non-transaction fallback.\n // Probe through the public object API before any cascade can begin.\n await content.withTransaction(async () => undefined);\n await content.delete({ expectedUpdatedAt });\n return;\n case 'automated-review':\n await content.runReviewAction({\n expectedUpdatedAt,\n ...(typeof input.kind === 'string'\n ? { kind: input.kind as never }\n : {}),\n ...(typeof input.policyKey === 'string'\n ? { policyKey: input.policyKey }\n : {}),\n });\n return;\n case 'format-body':\n if (!handlers.formatBody) throw new Error('format handler unavailable');\n await runHandler(handlers.formatBody);\n return;\n case 'categorize':\n content.category = String(input.category).trim();\n await save();\n return;\n case 'optimize':\n if (!handlers.optimize) throw new Error('optimize handler unavailable');\n await runHandler(handlers.optimize);\n return;\n }\n}\n\nfunction revisionFingerprint(rows: readonly Record<string, unknown>[]): string {\n const canonical = rows\n .map((row) => `${String(row.id)}\\u0000${String(row.updated_at ?? '')}`)\n .sort();\n return createHash('sha256')\n .update(canonical.join('\\u0001'))\n .digest('base64url');\n}\n\nfunction representativeLabels(\n rows: readonly Record<string, unknown>[],\n limit: number,\n): string[] {\n return rows.slice(0, limit).map((row) => {\n const title = typeof row.title === 'string' ? row.title.trim() : '';\n return title || String(row.id);\n });\n}\n\nasync function resolveQuerySelection(\n request: ContentListActionRequest,\n collection: ContentListActionCollection,\n scope: ContentQueryScope | undefined,\n maxSelectionSize: number,\n representativeLimit: number,\n revision: number,\n): Promise<ResolvedContentSelection> {\n const schema = await buildContentQuerySchema();\n const selection = request.selection;\n const rows: Array<Record<string, unknown>> = [];\n let queryFingerprint: string;\n\n if (selection.scope === 'explicit-ids') {\n const ids = [...new Set(selection.rowIds.map((rowId) => String(rowId)))];\n if (ids.length > maxSelectionSize)\n throw new ContentListActionError('limit_exceeded');\n queryFingerprint = `explicit:${revisionFingerprint(ids.map((id) => ({ id })))}`;\n for (let start = 0; start < ids.length; start += 100) {\n const chunk = ids.slice(start, start + 100);\n const query: DataQueryRequest = {\n version: 1,\n requestId: `content-action-explicit-${start}`,\n mode: 'rows',\n projection: [...REQUIRED_QUERY_FIELDS],\n filter: {\n kind: 'condition',\n field: 'id',\n operator: 'in',\n value: chunk,\n },\n sort: [{ field: 'id', direction: 'asc' }],\n page: { kind: 'offset', offset: 0, limit: Math.max(1, chunk.length) },\n };\n const result = await executeContentQuery(collection, query, { scope });\n rows.push(...result.rows);\n }\n queryFingerprint = `${queryFingerprint}:${revisionFingerprint(rows)}`;\n } else {\n const input = request.target.query;\n if (!input) throw new ContentListActionError('invalid_target');\n const normalized = normalizeDataQueryRequest(input, schema);\n const allMatchingPageLimit = Math.min(\n maxSelectionSize,\n MAX_DATA_QUERY_PAGE_LIMIT,\n );\n const querySchema =\n selection.scope === 'all-matching'\n ? {\n ...schema,\n defaultPageLimit: Math.min(\n schema.defaultPageLimit ?? CONTENT_QUERY_MAX_PAGE_LIMIT,\n allMatchingPageLimit,\n ),\n maxPageLimit: allMatchingPageLimit,\n }\n : schema;\n if (normalized.mode !== 'rows')\n throw new ContentListActionError('invalid_target');\n for (const field of REQUIRED_QUERY_FIELDS) {\n if (!normalized.projection?.includes(field))\n throw new ContentListActionError('missing_action_projection');\n }\n const baseFingerprint = createDataQueryFingerprint(normalized, schema);\n if (\n selection.scope === 'all-matching' &&\n selection.queryFingerprint !== baseFingerprint\n ) {\n throw new ContentListActionError('stale_query_fingerprint');\n }\n const pageLimit =\n selection.scope === 'current-page'\n ? (normalized.page?.limit ?? CONTENT_QUERY_MAX_PAGE_LIMIT)\n : allMatchingPageLimit;\n const offset =\n selection.scope === 'current-page' && normalized.page?.kind === 'offset'\n ? normalized.page.offset\n : 0;\n const pageRequest: DataQueryRequest = {\n ...normalized,\n requestId: `${normalized.requestId}-action-${offset}`.slice(0, 128),\n page: { kind: 'offset', offset, limit: Math.max(1, pageLimit) },\n };\n const result = await executeContentQuery(collection, pageRequest, {\n scope,\n schema: querySchema,\n });\n if (result.total.kind !== 'exact')\n throw new ContentListActionError('count_unavailable');\n if (selection.scope === 'all-matching' && result.total.value > pageLimit) {\n throw new ContentListActionError('limit_exceeded');\n }\n rows.push(...result.rows);\n if (\n selection.scope === 'all-matching' &&\n rows.length !== result.total.value\n ) {\n throw new ContentListActionError('matching_count_drifted');\n }\n if (selection.scope === 'all-matching') {\n const distinctIds = new Set(rows.map((row) => String(row.id)));\n if (distinctIds.size !== rows.length) {\n throw new ContentListActionError('matching_count_drifted');\n }\n }\n queryFingerprint = `${baseFingerprint}:${revisionFingerprint(rows)}`;\n }\n\n if (request.target.expectedCount !== rows.length) {\n throw new ContentListActionError('matching_count_drifted');\n }\n return {\n revision,\n queryFingerprint,\n rowIds: rows.map((row) => row.id as DataSurfaceRowId),\n rows,\n representativeLabels: representativeLabels(rows, representativeLimit),\n scope: selection.scope,\n };\n}\n\nfunction defaultDescriptor(maxSelectionSize: number): DataSurfaceDescriptor {\n return {\n version: 1,\n identity: { surfaceId: 'content-list', kind: 'table' },\n schemaVersion: 2,\n label: 'Contents',\n rowKey: 'id',\n columns: [\n {\n id: 'id',\n label: 'Content id',\n fieldName: 'id',\n role: 'row-key',\n capabilities: ['read', 'project'],\n },\n {\n id: 'title',\n label: 'Title',\n fieldName: 'title',\n capabilities: ['read', 'project'],\n },\n {\n id: 'status',\n label: 'Status',\n fieldName: 'status',\n role: 'status',\n capabilities: ['read', 'project'],\n },\n ],\n query: {\n modes: ['rows', 'count'],\n projectableColumnIds: ['id', 'title', 'status'],\n },\n controls: [],\n actions: CONTENT_LIST_SERVER_ACTIONS.map((entry) => ({\n id: entry.id,\n label: entry.label,\n description: entry.description,\n sensitivity: entry.sensitivity,\n selectionScopes: [...entry.selectionScopes],\n requiresConfirmation: entry.confirmation === 'required',\n })),\n limits: {\n maxQueryRows: CONTENT_QUERY_MAX_PAGE_LIMIT,\n maxQueryBytes: 1_000_000,\n maxSelectionSize,\n },\n };\n}\n\nexport interface ContentListActionAdapter extends DataSurfaceActionAdapter {\n preview(\n request: ContentListActionRequest,\n context: DataSurfaceServerActionContext,\n ): Promise<DataSurfaceActionResult>;\n apply(\n request: ContentListActionRequest,\n context: DataSurfaceServerActionContext,\n ): Promise<DataSurfaceActionResult>;\n}\n\nexport function createContentListActionAdapter(\n options: ContentListActionAdapterOptions,\n): ContentListActionAdapter {\n assertContentListWorkflowStorageSupported(options.workflowStorage);\n const handlers = options.handlers ?? {};\n const maxSelectionSize =\n options.maxSelectionSize ??\n options.descriptor?.limits.maxSelectionSize ??\n DEFAULT_MAX_SELECTION_SIZE;\n if (\n !Number.isSafeInteger(maxSelectionSize) ||\n maxSelectionSize < 1 ||\n maxSelectionSize > MAX_DATA_QUERY_PAGE_LIMIT\n ) {\n throw new Error(\n `ContentList maxSelectionSize must be an integer between 1 and ${MAX_DATA_QUERY_PAGE_LIMIT} so all-matching membership resolves in one bounded query`,\n );\n }\n const representativeLimit =\n options.representativeLimit ?? DEFAULT_REPRESENTATIVE_LIMIT;\n const descriptor = options.descriptor ?? defaultDescriptor(maxSelectionSize);\n if (descriptor.limits.maxSelectionSize !== maxSelectionSize) {\n throw new Error(\n 'ContentList descriptor maxSelectionSize must match the server selection cap',\n );\n }\n const resolvedByRequest = new WeakMap<object, ResolvedContentSelection>();\n const contentByRequest = new WeakMap<\n object,\n Map<string, Promise<Content | null>>\n >();\n // Request ids are client input and may collide across concurrent calls.\n const invocationResources = new AsyncLocalStorage<\n Map<string, { resourceId: string; resourceType: string }>\n >();\n async function loadContent(\n invocation: { run: PrincipalRun; request: DataSurfaceServerActionRequest },\n rowId: DataSurfaceRowId,\n ): Promise<Content | null> {\n const key = String(rowId);\n let byRow = contentByRequest.get(invocation.request);\n if (!byRow) {\n byRow = new Map();\n contentByRequest.set(invocation.request, byRow);\n }\n let pending = byRow.get(key);\n if (!pending) {\n pending = (async () => {\n const collection = await options.collection(invocation.run);\n const content = await collection.get({ id: key });\n if (!content) return null;\n const serialized = content.toJSON() as Record<string, unknown>;\n invocationResources.getStore()?.set(key, {\n resourceId: String(content.id),\n resourceType:\n typeof serialized._meta_type === 'string'\n ? serialized._meta_type\n : content.constructor.name,\n });\n const resolved = resolvedByRequest.get(invocation.request);\n const expected = resolved?.rows.find((row) => String(row.id) === key);\n const revisionValue = (value: unknown) =>\n value instanceof Date ? value.toISOString() : String(value ?? '');\n if (\n !expected ||\n revisionValue(content.updated_at) !==\n revisionValue(expected.updated_at)\n ) {\n throw new ContentListActionError('row_revision_drifted');\n }\n return content;\n })();\n byRow.set(key, pending);\n }\n return pending;\n }\n\n const mapActionError = (error: unknown) =>\n error instanceof ContentListActionError\n ? error.reason\n : isRecord(error) && error.code === 'RUNTIME_REVISION_CONFLICT'\n ? 'row_revision_drifted'\n : isPermissionDenied(error) ||\n error instanceof PrincipalToolNotAllowedError\n ? 'denied'\n : undefined;\n\n const definitions = Object.fromEntries(\n CONTENT_LIST_SERVER_ACTIONS.map(\n (entry): [string, DataSurfaceServerActionDefinition] => [\n entry.id,\n {\n descriptor: {\n id: entry.id,\n label: entry.label,\n description: entry.description,\n sensitivity: entry.sensitivity,\n selectionScopes: [...entry.selectionScopes],\n requiresConfirmation: entry.confirmation === 'required',\n },\n inputSchema: entry.inputSchema,\n validatePayload: (payload) =>\n validPayload(entry.id, payload)\n ? { valid: true }\n : { valid: false, reason: 'invalid_payload' },\n confirmation: entry.confirmation,\n execution: entry.execution,\n tool: entry.permissionRequirements.tool,\n operation:\n entry.permissionRequirements.operations[0] ??\n CONTENT_READ_OPERATION,\n authorize: async (invocation) => {\n const operations =\n entry.id === 'restore' &&\n payloadRecord(invocation.request.payload).status !== 'published'\n ? entry.permissionRequirements.operations.slice(0, 2)\n : entry.permissionRequirements.operations;\n for (const operation of operations.slice(1)) {\n try {\n await invocation.run.assertOperation(\n operation.collection,\n operation.action,\n );\n } catch (error) {\n if (isPermissionDenied(error)) return false;\n throw error;\n }\n }\n return options.authorize?.(entry.id, invocation.run) ?? true;\n },\n eligible: async (invocation, rowId) => {\n const content = await loadContent(invocation, rowId);\n if (!content)\n return { eligible: false, reason: 'not_found_or_denied' };\n return eligibility(\n entry.id,\n content,\n invocation.request.payload,\n handlers,\n );\n },\n apply: async (invocation, rowId) => {\n const content = await loadContent(invocation, rowId);\n if (!content) throw new Error('content not found');\n const expectedUpdatedAt = content.updated_at;\n if (\n !(expectedUpdatedAt instanceof Date) &&\n typeof expectedUpdatedAt !== 'string'\n ) {\n throw new ContentListActionError('row_revision_drifted');\n }\n const resource = invocationResources.getStore()?.get(String(rowId));\n try {\n await applyWorkflow(\n entry.id,\n content,\n expectedUpdatedAt,\n invocation.request.payload,\n invocation.run,\n handlers,\n );\n } catch (error) {\n if (entry.id !== 'permanent-delete') throw error;\n // delete() commits before its post-delete hooks. If one of those\n // hooks fails, confirm the authoritative row state so an\n // irreversible success is never reported as retryable failure.\n const collection = await options.collection(invocation.run);\n if (await collection.get({ id: String(rowId) })) throw error;\n }\n return resource ?? null;\n },\n },\n ],\n ),\n );\n\n const state: DataSurfaceActionStateStore = {\n putToken: (...args) => options.state.putToken(...args),\n getToken: (...args) => options.state.getToken(...args),\n markTokenConsumed: (...args) => options.state.markTokenConsumed(...args),\n getIdempotency: (...args) => options.state.getIdempotency(...args),\n reserveIdempotency: (...args) => options.state.reserveIdempotency(...args),\n completeIdempotency: (key, ownerToken, result) => {\n if (result.details) {\n result.details = {\n ...result.details,\n auditReference: result.requestId,\n };\n }\n return options.state.completeIdempotency(key, ownerToken, result);\n },\n releaseIdempotency: (...args) => options.state.releaseIdempotency(...args),\n };\n\n const generic = createDataSurfaceActionAdapter({\n state,\n backgroundQueue: options.backgroundQueue,\n tokenTtlMs: options.tokenTtlMs,\n runAsPrincipal: options.runAsPrincipal,\n resolveDeferredPrincipal: options.resolveDeferredPrincipal,\n requestFingerprintExtension: (request) =>\n (() => {\n const target = (request as ContentListActionRequest).target;\n // The operator-entered count exists only on apply. Bind the preview's\n // server-checked expected count/query into the token while validating\n // the separate affirmation above before the generic adapter runs.\n return {\n expectedCount: target.expectedCount,\n ...(target.query ? { query: target.query } : {}),\n } as unknown as DataSurfaceJsonValue;\n })(),\n mapError: mapActionError,\n resolveSurface: async (run) => ({\n descriptor,\n revision: await (options.revision?.(run, descriptor.identity) ?? 0),\n actions: definitions,\n }),\n resolveSelection: async (invocation, selection) => {\n const request = invocation.request as ContentListActionRequest;\n const collection = await options.collection(invocation.run);\n const scope = await options.scope?.(invocation.run);\n const revision = await (options.revision?.(\n invocation.run,\n descriptor.identity,\n ) ?? 0);\n const resolved = await resolveQuerySelection(\n { ...request, selection },\n collection,\n scope,\n maxSelectionSize,\n representativeLimit,\n revision,\n );\n resolvedByRequest.set(request, resolved);\n return resolved;\n },\n });\n\n async function invoke(\n phase: 'preview' | 'apply',\n request: ContentListActionRequest,\n context: DataSurfaceServerActionContext,\n ): Promise<DataSurfaceActionResult> {\n const invalid = validateTarget(request);\n if (invalid) return actionResult(request, false, invalid);\n try {\n const resources = new Map<\n string,\n { resourceId: string; resourceType: string }\n >();\n const result = await invocationResources.run(resources, () =>\n generic[phase](request, context),\n );\n const resolved = resolvedByRequest.get(request);\n const workflow = CONTENT_LIST_SERVER_ACTIONS.find(\n (entry) => entry.id === request.actionId,\n );\n const outcomes = Array.isArray(result.details?.outcomes)\n ? result.details.outcomes.map((outcome) => {\n if (!isRecord(outcome)) return outcome;\n const resource =\n resources?.get(String(outcome.rowId)) ??\n (typeof outcome.resourceId === 'string' &&\n typeof outcome.resourceType === 'string'\n ? {\n resourceId: outcome.resourceId,\n resourceType: outcome.resourceType,\n }\n : undefined);\n return resource ? { ...outcome, ...resource } : outcome;\n })\n : undefined;\n if (phase !== 'preview' || !result.ok) {\n return {\n ...result,\n ...(result.details\n ? {\n details: {\n ...result.details,\n ...(outcomes ? { outcomes } : {}),\n auditReference:\n typeof result.details.auditReference === 'string'\n ? result.details.auditReference\n : request.requestId,\n },\n }\n : {}),\n };\n }\n return {\n ...result,\n details: {\n ...(result.details ?? {}),\n ...(outcomes ? { outcomes } : {}),\n resolvedScope: resolved?.scope ?? request.selection.scope,\n representativeLabels: resolved?.representativeLabels ?? [],\n ineligible: Array.isArray(result.details?.outcomes)\n ? result.details.outcomes.filter(\n (entry) => isRecord(entry) && entry.status === 'skipped',\n )\n : [],\n consequences: workflow?.consequences ?? [],\n sensitivity: workflow?.sensitivity ?? 'public',\n execution: workflow?.execution ?? 'foreground',\n auditReference: request.requestId,\n },\n };\n } catch (error) {\n return actionResult(\n request,\n false,\n mapActionError(error) ?? 'execution_failed',\n );\n } finally {\n resolvedByRequest.delete(request);\n }\n }\n\n return {\n preview: (request, context) => invoke('preview', request, context),\n apply: (request, context) => invoke('apply', request, context),\n };\n}\n","/** Principal-bound, silent ContentList query discovery and execution (#2456). */\n\nimport type {\n DataSurfaceDefinition,\n DataSurfaceExecutionContext,\n DataSurfaceSchema,\n} from '@happyvertical/smrt-agents';\nimport { normalizeDataQueryRequest } from '@happyvertical/smrt-core';\nimport type { DataQuerySchema } from '@happyvertical/smrt-types';\nimport {\n assertContentQuerySchema,\n buildContentQuerySchema,\n CONTENT_QUERY_CLASS_NAME,\n type ContentQueryCollection,\n type ContentQueryScope,\n executeContentQuery,\n} from '../content-query.js';\n\nexport const CONTENT_LIST_DATA_SURFACE_ID = 'content-list';\nexport const CONTENT_LIST_DATA_SURFACE_COLLECTION = 'contents';\n\nexport interface ContentListDataSurfaceOptions {\n /** Stable catalog id. Defaults to the mounted ContentList surface id. */\n id?: string;\n /** Permission-catalog collection checked by the generic agent tools. */\n collectionName?: string;\n label?: string;\n description?: string;\n metadata?: NonNullable<DataSurfaceDefinition['metadata']>;\n /** Resolve a collection from the live principal context, never model input. */\n collection:\n | ContentQueryCollection\n | ((\n context: DataSurfaceExecutionContext,\n ) => ContentQueryCollection | Promise<ContentQueryCollection>);\n /** Trusted application narrowing applied in addition to tenant isolation. */\n scope?:\n | ContentQueryScope\n | ((\n context: DataSurfaceExecutionContext,\n ) =>\n | ContentQueryScope\n | undefined\n | Promise<ContentQueryScope | undefined>);\n /** Trusted policy override; defaults to the canonical Content query schema. */\n schema?: DataSurfaceSchema;\n}\n\nfunction requiredName(\n value: string | undefined,\n fallback: string,\n label: string,\n) {\n const resolved = value ?? fallback;\n if (resolved.trim().length === 0) {\n throw new Error(`${label} must be a non-empty string`);\n }\n return resolved;\n}\n\nfunction querySchema(schema: DataSurfaceSchema): DataQuerySchema {\n return {\n ...schema,\n // A host descriptor is untrusted at this boundary. Discovery redacts\n // protected fields, and execution uses the same principal-aware field set\n // so a direct data.query request cannot bypass that policy.\n fields: schema.fields\n .filter(({ sensitive, readPermission }) => {\n if (sensitive) return false;\n return !readPermission;\n })\n .map(\n ({\n sensitive: _sensitive,\n readPermission: _readPermission,\n metadata: _metadata,\n ...field\n }) => field,\n ),\n };\n}\n\nasync function resolveCollection(\n options: ContentListDataSurfaceOptions,\n context: DataSurfaceExecutionContext,\n): Promise<ContentQueryCollection> {\n return typeof options.collection === 'function'\n ? options.collection(context)\n : options.collection;\n}\n\nasync function resolveScope(\n options: ContentListDataSurfaceOptions,\n context: DataSurfaceExecutionContext,\n): Promise<ContentQueryScope | undefined> {\n return typeof options.scope === 'function'\n ? options.scope(context)\n : options.scope;\n}\n\n/**\n * Build one server-owned ContentList surface for `data.discover`,\n * `data.inspect`, and silent/background `data.query` calls.\n *\n * The returned executor resolves its collection and application scope from the\n * live principal context. The request can only narrow that trusted scope, and\n * every projection/count/facet/page still passes through `executeContentQuery`.\n */\nexport async function createContentListDataSurfaceDefinition(\n options: ContentListDataSurfaceOptions,\n): Promise<DataSurfaceDefinition> {\n const schema = options.schema ?? (await buildContentQuerySchema());\n // `SmrtCollection.list({ select })` intentionally refuses model fields with\n // readPermission because that projection primitive has no permission\n // context. Publishing one here would let discovery promise a query that the\n // real collection cannot execute. Keep the server data surface fail-closed:\n // only universally executable, non-sensitive fields are advertised.\n const executableSchema = querySchema(schema);\n assertContentQuerySchema(executableSchema);\n\n return {\n id: requiredName(\n options.id,\n CONTENT_LIST_DATA_SURFACE_ID,\n 'ContentList data surface id',\n ),\n collection: requiredName(\n options.collectionName,\n CONTENT_LIST_DATA_SURFACE_COLLECTION,\n 'ContentList permission collection',\n ),\n className: CONTENT_QUERY_CLASS_NAME,\n label: options.label ?? 'Contents',\n description:\n options.description ??\n 'Bounded, tenant-safe content rows, counts, facets, and continuations.',\n metadata: {\n domain: 'content',\n adapter: 'ContentList',\n views: ['grid', 'detailed', 'compact'],\n queryModes: ['rows', 'count', 'facets'],\n ...options.metadata,\n },\n schema: executableSchema,\n execute: async (_surface, request, context) => {\n // Validate before resolving the host collection. This makes a rejected\n // protected projection a zero-I/O failure, even for hostile descriptors.\n normalizeDataQueryRequest(request, executableSchema);\n return executeContentQuery(\n await resolveCollection(options, context),\n request,\n {\n schema: executableSchema,\n scope: await resolveScope(options, context),\n },\n );\n },\n };\n}\n","/**\n * Principal-bound HTTP boundary for ContentList lifecycle actions (#2454).\n *\n * Hosts supply authentication by resolving a DataSurface server context from\n * the incoming Request. The service gates this dedicated endpoint to lifecycle\n * actions, then delegates to the same content action adapter used by agents and\n * bulk workflows so authorization, selection resolution, confirmation,\n * idempotency, and audit metadata cannot diverge by caller.\n */\n\nimport type { DataSurfaceServerActionContext } from '@happyvertical/smrt-agents/server';\nimport type {\n DataSurfaceActionResult,\n DataSurfaceIdentity,\n} from '@happyvertical/smrt-ui/data';\nimport {\n CONTENT_LIST_LIFECYCLE_ACTION_IDS,\n type ContentListActionAdapter,\n type ContentListActionRequest,\n type ContentListLifecycleActionId,\n} from './content-list-actions.js';\n\nexport interface ContentListLifecycleService {\n invoke(\n request: unknown,\n context: DataSurfaceServerActionContext,\n ): Promise<DataSurfaceActionResult>;\n}\n\nexport interface ContentListLifecycleRouteOptions {\n adapter: ContentListActionAdapter;\n /** Authenticate and bind the request to its current principal/tenant. */\n context(\n request: Request,\n ): DataSurfaceServerActionContext | Promise<DataSurfaceServerActionContext>;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isLifecycleActionId(\n value: unknown,\n): value is ContentListLifecycleActionId {\n return (CONTENT_LIST_LIFECYCLE_ACTION_IDS as readonly unknown[]).includes(\n value,\n );\n}\n\nfunction safeIdentity(value: unknown): DataSurfaceIdentity {\n if (!isRecord(value)) return { surfaceId: 'content-list', kind: 'table' };\n if (\n typeof value.surfaceId !== 'string' ||\n !['table', 'list', 'report', 'custom'].includes(String(value.kind))\n ) {\n return { surfaceId: 'content-list', kind: 'table' };\n }\n return value as unknown as DataSurfaceIdentity;\n}\n\nfunction rejected(\n request: unknown,\n reason: 'invalid_request' | 'unsupported',\n): DataSurfaceActionResult {\n const candidate = isRecord(request) ? request : {};\n return {\n version: 1,\n requestId:\n typeof candidate.requestId === 'string'\n ? candidate.requestId\n : 'invalid-request',\n identity: safeIdentity(candidate.identity),\n actionId:\n typeof candidate.actionId === 'string' ? candidate.actionId : 'invalid',\n phase: candidate.phase === 'apply' ? 'apply' : 'preview',\n ok: false,\n reason,\n };\n}\n\n/** Create the transport-neutral lifecycle service used by HTTP and agent hosts. */\nexport function createContentListLifecycleService(\n adapter: ContentListActionAdapter,\n): ContentListLifecycleService {\n return {\n async invoke(request, context) {\n if (!isRecord(request)) return rejected(request, 'invalid_request');\n if (!isLifecycleActionId(request.actionId)) {\n return rejected(request, 'unsupported');\n }\n if (request.phase !== 'preview' && request.phase !== 'apply') {\n return rejected(request, 'invalid_request');\n }\n return adapter[request.phase](\n request as unknown as ContentListActionRequest,\n context,\n );\n },\n };\n}\n\n/**\n * Create a native Request/Response handler for `POST /api/v1/contents/lifecycle`.\n * SvelteKit hosts can call it with `event.request`; other runtimes can mount it\n * directly anywhere that implements the standard Fetch API.\n */\nexport function createContentListLifecycleRoute(\n options: ContentListLifecycleRouteOptions,\n): (request: Request) => Promise<Response> {\n const service = createContentListLifecycleService(options.adapter);\n return async (request) => {\n if (request.method !== 'POST') {\n return Response.json(\n { error: { message: 'Method not allowed.' } },\n { status: 405, headers: { allow: 'POST' } },\n );\n }\n let input: unknown;\n try {\n input = await request.json();\n } catch {\n return Response.json(\n { error: { message: 'The lifecycle request body must be JSON.' } },\n { status: 400 },\n );\n }\n let context: DataSurfaceServerActionContext;\n try {\n context = await options.context(request);\n } catch {\n return Response.json(\n { error: { message: 'Authentication is required.' } },\n { status: 401 },\n );\n }\n try {\n return Response.json({ result: await service.invoke(input, context) });\n } catch {\n return Response.json(\n { error: { message: 'The lifecycle request could not be completed.' } },\n { status: 500 },\n );\n }\n };\n}\n","/**\n * SMRT Content Service Server\n *\n * Demonstrates auto-generated REST API from SMRT Content objects.\n * No manual route definitions needed - everything is generated from @smrt() decorated classes.\n */\n\nimport { startRestServer } from '@happyvertical/smrt-core';\nimport './__smrt-register__.js';\nimport { Content } from './content';\n\nasync function startServer() {\n console.log('🚀 Starting SMRT Content Server...');\n\n // Start server with registered SMRT objects\n const shutdown = await startRestServer(\n [Content], // SMRT objects to generate API for\n {}, // context\n {\n port: 3100,\n hostname: 'localhost',\n basePath: '/api/v1',\n enableCors: true,\n },\n );\n\n console.log('✅ Server ready!');\n console.log('📡 REST API: http://localhost:3100/api/v1');\n console.log('📚 Endpoints:');\n console.log(' GET /api/v1/contents - List contents');\n console.log(' POST /api/v1/contents - Create content');\n console.log(' GET /api/v1/contents/:id - Get content');\n console.log(' PUT /api/v1/contents/:id - Update content');\n console.log(' DELETE /api/v1/contents/:id - Delete content');\n\n console.log('\\n💡 Try these endpoints:');\n console.log(' curl http://localhost:3100/api/v1/contents');\n console.log(\n ' curl -X POST http://localhost:3100/api/v1/contents -H \"Content-Type: application/json\" -d \\'{\"title\":\"Test Content\",\"body\":\"Test body content\"}\\'',\n );\n\n return { shutdown };\n}\n\n// Start if running directly\nif (import.meta.url === `file://${process.argv[1]}`) {\n startServer().catch(console.error);\n}\n\nexport * from './server/content-list-actions.js';\nexport * from './server/content-list-data-surface.js';\nexport * from './server/content-list-lifecycle.js';\nexport { startServer };\n"],"mappings":";;;;;;;;AAsDO,IAAM,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGO,IAAM,oCAAoC;CAC/C;CACA;CACA;AACF;AA8BA,IAAM,uBAAyE;CAC7E;CACA;CACA;AACF;AAEA,IAAM,WAAkC;CACtC,MAAM;CACN,sBAAsB;AACxB;AAEA,IAAM,wBAA+C;CACnD,MAAM;CACN,sBAAsB;CACtB,YAAY;EACV,MAAM;GAAE,MAAM;GAAU,MAAM;IAAC;IAAS;IAAU;GAAQ;EAAE;EAC5D,WAAW;GAAE,MAAM;GAAU,WAAW;EAAI;CAC9C;AACF;AAEA,IAAM,2BAA2B;CAC/B,IAAI;CACJ,YAAY;CACZ,QAAQ;A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,IAAI;GACF,OAAO,SAAS,KAAK,EAAE,QAAQ,MAAM,QAAQ,OAAO,OAAO,OAAO,EAAE,CAAC;EACvE,QAAQ;GACN,OAAO,SAAS,KACd,EAAE,OAAO,EAAE,SAAS,gDAAgD,EAAE,GACtE,EAAE,QAAQ,IAAI,CAChB;EACF;CACF;AACF;;;ACrIA,eAAe,cAAc;CAC3B,QAAQ,IAAI,oCAAoC;CAGhD,MAAM,WAAW,MAAM,gBACrB,CAAC,OAAO,GACR,CAAC,GACD;EACE,MAAM;EACN,UAAU;EACV,UAAU;EACV,YAAY;CACd,CACF;CAEA,QAAQ,IAAI,iBAAiB;CAC7B,QAAQ,IAAI,2CAA2C;CACvD,QAAQ,IAAI,eAAe;CAC3B,QAAQ,IAAI,4CAA4C;CACxD,QAAQ,IAAI,6CAA6C;CACzD,QAAQ,IAAI,8CAA8C;CAC1D,QAAQ,IAAI,iDAAiD;CAC7D,QAAQ,IAAI,iDAAiD;CAE7D,QAAQ,IAAI,2BAA2B;CACvC,QAAQ,IAAI,+CAA+C;CAC3D,QAAQ,IACN,oJACF;CAEA,OAAO,EAAE,SAAS;AACpB;AAGA,IAAI,OAAA,KAAY,QAAQ,UAAU,QAAQ,KAAK,MAC7C,YAAY,CAAA,CAAE,MAAM,QAAQ,KAAK"}
|
|
1
|
+
{"version":3,"file":"server.js","names":["workflow"],"sources":["../src/server/content-list-actions.ts","../src/server/content-list-data-surface.ts","../src/server/content-list-lifecycle.ts","../src/server.ts"],"sourcesContent":["/**\n * Principal-bound ContentList bulk workflows (#2453).\n *\n * The generic action adapter owns confirmation tokens, idempotency, principal\n * execution, permission checks, per-row outcomes, and background acceptance.\n * This module supplies the content-specific half: declarative workflows,\n * canonical query resolution, row-revision binding, governance eligibility,\n * and domain mutations.\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { createHash } from 'node:crypto';\n// Publication and automated-review permissions include facts operations. The\n// catalog is registration-driven, so ensure those definitions exist even when\n// a host imports only the content server entry point.\nimport '@happyvertical/smrt-facts';\nimport {\n type PrincipalRun,\n PrincipalToolNotAllowedError,\n} from '@happyvertical/smrt-agents';\nimport {\n createDataSurfaceActionAdapter,\n type DataSurfaceActionAdapter,\n type DataSurfaceActionStateStore,\n type DataSurfaceBackgroundQueue,\n type DataSurfaceServerActionContext,\n type DataSurfaceServerActionDefinition,\n type DataSurfaceServerActionRequest,\n isBoundedDataSurfaceJsonValue,\n} from '@happyvertical/smrt-agents/server';\nimport {\n createDataQueryFingerprint,\n MAX_DATA_QUERY_PAGE_LIMIT,\n normalizeDataQueryRequest,\n} from '@happyvertical/smrt-core';\nimport type {\n DataQueryRequest,\n DataSurfaceActionResult,\n DataSurfaceDescriptor,\n DataSurfaceIdentity,\n DataSurfaceJsonObject,\n DataSurfaceJsonValue,\n DataSurfaceRowId,\n} from '@happyvertical/smrt-types';\nimport type { ContentBodyFormat } from '../body-format.js';\nimport type { Content } from '../content.js';\nimport {\n buildContentQuerySchema,\n CONTENT_QUERY_MAX_PAGE_LIMIT,\n type ContentQueryCollection,\n type ContentQueryScope,\n executeContentQuery,\n} from '../content-query.js';\n\nexport const CONTENT_LIST_WORKFLOW_IDS = [\n 'move-to-trash',\n 'mark-draft',\n 'submit-review',\n 'publish',\n 'archive',\n 'restore',\n 'automated-review',\n 'format-body',\n 'categorize',\n 'optimize',\n] as const;\n\nexport type ContentListWorkflowId = (typeof CONTENT_LIST_WORKFLOW_IDS)[number];\nexport const CONTENT_LIST_LIFECYCLE_ACTION_IDS = [\n 'move-to-trash',\n 'restore',\n 'permanent-delete',\n] as const;\nexport type ContentListLifecycleActionId =\n (typeof CONTENT_LIST_LIFECYCLE_ACTION_IDS)[number];\nexport type ContentListServerActionId =\n | ContentListWorkflowId\n | ContentListLifecycleActionId;\nexport type ContentListWorkflowExecution = 'foreground' | 'background';\nexport type ContentListWorkflowConfirmation = 'required' | 'none';\n\nexport interface ContentListWorkflowDescriptor {\n id: ContentListServerActionId;\n label: string;\n description: string;\n selectionScopes: Array<'current-page' | 'explicit-ids' | 'all-matching'>;\n sensitivity: 'public' | 'sensitive';\n confirmation: ContentListWorkflowConfirmation;\n execution: ContentListWorkflowExecution;\n inputSchema: DataSurfaceJsonObject | null;\n eligibility: string[];\n permissionRequirements: {\n tool: string;\n operations: Array<{ id: string; collection: string; action: string }>;\n };\n consequences: string[];\n partialResult: {\n statuses: Array<'accepted' | 'skipped' | 'failed'>;\n preservesFailedSelection: true;\n };\n}\n\nconst ALL_SELECTION_SCOPES: ContentListWorkflowDescriptor['selectionScopes'] = [\n 'current-page',\n 'explicit-ids',\n 'all-matching',\n];\n\nconst NO_INPUT: DataSurfaceJsonObject = {\n type: 'object',\n additionalProperties: false,\n};\n\nconst OPTIONAL_REVIEW_INPUT: DataSurfaceJsonObject = {\n type: 'object',\n additionalProperties: false,\n properties: {\n kind: { type: 'string', enum: ['facts', 'safety', 'custom'] },\n policyKey: { type: 'string', maxLength: 128 },\n },\n};\n\nconst CONTENT_UPDATE_OPERATION = {\n id: 'contents:update',\n collection: 'contents',\n action: 'update',\n};\n\nconst CONTENT_READ_OPERATION = {\n id: 'contents:read',\n collection: 'contents',\n action: 'read',\n};\n\nconst GOVERNANCE_READ_OPERATIONS = [\n {\n id: 'content-governance-assignments:read',\n collection: 'contentgovernanceassignments',\n action: 'read',\n },\n {\n id: 'content-governance-policies:read',\n collection: 'contentgovernancepolicies',\n action: 'read',\n },\n {\n id: 'content-governance-profiles:read',\n collection: 'contentgovernanceprofiles',\n action: 'read',\n },\n] as const;\n\nconst PUBLICATION_OPERATIONS = [\n CONTENT_READ_OPERATION,\n CONTENT_UPDATE_OPERATION,\n ...GOVERNANCE_READ_OPERATIONS,\n {\n id: 'content-references:read',\n collection: 'contentreferences',\n action: 'read',\n },\n {\n id: 'content-assets:read',\n collection: 'contentassets',\n action: 'read',\n },\n { id: 'assets:read', collection: 'assets', action: 'read' },\n { id: 'facts:read', collection: 'facts', action: 'read' },\n { id: 'fact-contents:read', collection: 'factcontents', action: 'read' },\n { id: 'fact-sources:read', collection: 'factsources', action: 'read' },\n { id: 'content-reviews:read', collection: 'contentreviews', action: 'read' },\n {\n id: 'content-corrections:read',\n collection: 'contentcorrections',\n action: 'read',\n },\n {\n id: 'content-versions:read',\n collection: 'contentversions',\n action: 'read',\n },\n {\n id: 'content-versions:create',\n collection: 'contentversions',\n action: 'create',\n },\n] as const;\n\nconst AUTOMATED_REVIEW_OPERATIONS = [\n ...PUBLICATION_OPERATIONS,\n {\n id: 'prompt-overrides:read',\n collection: 'promptoverrides',\n action: 'read',\n },\n {\n id: 'content-reviews:create',\n collection: 'contentreviews',\n action: 'create',\n },\n] as const;\n\nexport const CONTENT_LIST_WORKFLOWS: readonly ContentListWorkflowDescriptor[] =\n Object.freeze([\n workflow('move-to-trash', 'Move to trash', {\n description: 'Soft-delete eligible content into the trash lifecycle.',\n sensitivity: 'sensitive',\n eligibility: ['content is not already deleted'],\n consequences: [\n 'Content leaves active views and becomes restorable from trash.',\n ],\n }),\n workflow('mark-draft', 'Mark draft', {\n description: 'Return eligible active content to draft.',\n eligibility: ['content is not deleted', 'content is not already draft'],\n consequences: ['Published content is no longer public.'],\n }),\n workflow('submit-review', 'Submit for review', {\n description: 'Move eligible draft content into editorial review.',\n eligibility: ['content is draft'],\n consequences: ['Content enters the review queue.'],\n }),\n workflow('publish', 'Publish', {\n description: 'Publish content that passes current governance readiness.',\n sensitivity: 'sensitive',\n eligibility: [\n 'content is draft, review, or archived',\n 'publication readiness passes',\n ],\n consequences: [\n 'Content becomes public and may create a publication snapshot.',\n ],\n permissionRequirements: {\n tool: 'content.workflow.publish',\n operations: [...PUBLICATION_OPERATIONS],\n },\n }),\n workflow('archive', 'Archive', {\n description: 'Remove eligible content from active publication workflows.',\n eligibility: [\n 'content is not deleted',\n 'content is not already archived',\n ],\n consequences: ['Published content is no longer public.'],\n }),\n workflow('restore', 'Restore', {\n description: 'Restore deleted content to an explicit eligible status.',\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['status'],\n properties: {\n status: { enum: ['draft', 'review', 'published'] },\n },\n },\n eligibility: [\n 'content is deleted',\n 'requested destination is valid',\n 'publish readiness passes when publishing',\n ],\n consequences: [\n 'Content leaves trash.',\n 'Publishing makes content public.',\n ],\n permissionRequirements: {\n tool: 'content.workflow.restore',\n operations: [...PUBLICATION_OPERATIONS],\n },\n }),\n workflow('automated-review', 'Automated review', {\n description: 'Run the configured content governance review.',\n execution: 'background',\n inputSchema: OPTIONAL_REVIEW_INPUT,\n eligibility: [\n 'content is not deleted',\n 'content governance is configured',\n ],\n consequences: [\n 'Creates a review result and may create a review version.',\n ],\n permissionRequirements: {\n tool: 'content.workflow.automated-review',\n operations: [...AUTOMATED_REVIEW_OPERATIONS],\n },\n }),\n workflow('format-body', 'Format body', {\n description: 'Run the application-owned body-formatting workflow.',\n execution: 'background',\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n properties: { format: { enum: ['markdown', 'html'] } },\n },\n eligibility: [\n 'content is not deleted',\n 'a formatting handler is configured',\n ],\n consequences: ['The persisted content body may change.'],\n permissionRequirements: {\n tool: 'content.workflow.format-body',\n operations: [...PUBLICATION_OPERATIONS],\n },\n }),\n workflow('categorize', 'Categorize', {\n description: 'Assign one required hierarchical category path.',\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['category'],\n properties: {\n category: { type: 'string', minLength: 1, maxLength: 256 },\n },\n },\n eligibility: ['content is not deleted', 'category is non-empty'],\n consequences: ['The content category changes.'],\n permissionRequirements: {\n tool: 'content.workflow.categorize',\n operations: [...PUBLICATION_OPERATIONS],\n },\n }),\n workflow('optimize', 'Optimize / complete', {\n description: 'Run the application-owned content optimization workflow.',\n execution: 'background',\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n properties: { instructions: { type: 'string', maxLength: 4096 } },\n },\n eligibility: [\n 'content is draft or review',\n 'an optimization handler is configured',\n ],\n consequences: ['Content fields may be revised or completed.'],\n }),\n ]);\n\nconst PERMANENT_DELETE_ACTION: ContentListWorkflowDescriptor = workflow(\n 'permanent-delete',\n 'Delete permanently',\n {\n description: 'Permanently delete content that is already in trash.',\n sensitivity: 'sensitive',\n eligibility: ['content is deleted'],\n consequences: [\n 'Content and its owned lifecycle data are irreversibly deleted.',\n ],\n permissionRequirements: {\n tool: 'content.lifecycle.permanent-delete',\n operations: [\n CONTENT_READ_OPERATION,\n {\n id: 'contents:delete',\n collection: 'contents',\n action: 'delete',\n },\n ],\n },\n },\n);\n\n/** The lifecycle-only catalog exposed by the dedicated route/service. */\nexport const CONTENT_LIST_LIFECYCLE_ACTIONS: readonly ContentListWorkflowDescriptor[] =\n Object.freeze([\n contentListWorkflow('move-to-trash'),\n contentListWorkflow('restore'),\n PERMANENT_DELETE_ACTION,\n ]);\n\nconst CONTENT_LIST_SERVER_ACTIONS: readonly ContentListWorkflowDescriptor[] =\n Object.freeze([...CONTENT_LIST_WORKFLOWS, PERMANENT_DELETE_ACTION]);\n\nfunction contentListWorkflow(\n id: ContentListWorkflowId,\n): ContentListWorkflowDescriptor {\n const descriptor = CONTENT_LIST_WORKFLOWS.find((entry) => entry.id === id);\n if (!descriptor) throw new Error(`Missing ContentList workflow: ${id}`);\n return descriptor;\n}\n\nfunction workflow(\n id: ContentListServerActionId,\n label: string,\n options: Partial<ContentListWorkflowDescriptor> &\n Pick<\n ContentListWorkflowDescriptor,\n 'description' | 'eligibility' | 'consequences'\n >,\n): ContentListWorkflowDescriptor {\n return {\n id,\n label,\n description: options.description,\n selectionScopes: options.selectionScopes ?? [...ALL_SELECTION_SCOPES],\n sensitivity: options.sensitivity ?? 'public',\n confirmation: options.confirmation ?? 'required',\n execution: options.execution ?? 'foreground',\n inputSchema: options.inputSchema ?? NO_INPUT,\n eligibility: options.eligibility,\n permissionRequirements: options.permissionRequirements ?? {\n tool: `content.workflow.${id}`,\n operations: [CONTENT_READ_OPERATION, CONTENT_UPDATE_OPERATION],\n },\n consequences: options.consequences,\n partialResult: {\n statuses: ['accepted', 'skipped', 'failed'],\n preservesFailedSelection: true,\n },\n };\n}\n\nexport interface ContentListActionTarget {\n /** Canonical query sent to the content query endpoint. Required except for explicit IDs. */\n query?: DataQueryRequest;\n /** Count visible at selection time; drift fails the preview/apply. */\n expectedCount: number;\n /** Operator-entered preview count, required only for permanent-delete apply. */\n confirmedCount?: number;\n}\n\nexport interface ContentListActionRequest\n extends DataSurfaceServerActionRequest {\n actionId: ContentListServerActionId;\n target: ContentListActionTarget;\n}\n\nexport interface ContentListActionCollection extends ContentQueryCollection {\n get(filter: string | Record<string, unknown>): Promise<Content | null>;\n}\n\n/**\n * Persistence-free copy supplied to host format/optimize handlers.\n *\n * Only the explicitly copied mutable fields are applied back to Content before\n * the adapter's revision-guarded save. Identity, tenancy, lifecycle state,\n * relationship IDs, database handles, and Content persistence methods are\n * deliberately absent.\n */\nexport interface ContentListWorkflowDraft {\n readonly contentId: string;\n readonly tenantId: string | null;\n readonly type: string | null;\n readonly variant: string | null;\n readonly status: Content['status'];\n readonly state: Content['state'];\n fileKey: string | null;\n author: string | null;\n name: string;\n title: string;\n description: string | null;\n body: string;\n bodyFormat: ContentBodyFormat | null;\n publish_date: Date | null;\n url: string | null;\n source: string | null;\n original_url: string | null;\n language: string | null;\n tags: string[];\n category: string | null;\n metadata: Record<string, unknown>;\n thumbnailAssetId: string | null;\n}\n\nexport interface ContentListWorkflowHandlers {\n /** Mutate a persistence-free draft; the adapter applies it by revision CAS. */\n formatBody?: (\n content: ContentListWorkflowDraft,\n payload: DataSurfaceJsonValue | undefined,\n run: PrincipalRun,\n ) => Promise<void>;\n /** Mutate a persistence-free draft; the adapter applies it by revision CAS. */\n optimize?: (\n content: ContentListWorkflowDraft,\n payload: DataSurfaceJsonValue | undefined,\n run: PrincipalRun,\n ) => Promise<void>;\n}\n\nexport interface ContentListWorkflowStorage {\n adapterType: 'sqlite' | 'postgres' | 'duckdb' | 'json';\n writeStrategy?: 'immediate' | 'manual' | 'none';\n}\n\nexport class UnsupportedContentListWorkflowStorageError extends Error {\n readonly code = 'UNSUPPORTED_CONTENT_LIST_WORKFLOW_STORAGE';\n\n constructor(storage: ContentListWorkflowStorage) {\n super(\n `ContentList workflows do not support ${storage.adapterType} with ` +\n 'immediate write-back because exported files are not transactionally ' +\n 'rolled back. Use PostgreSQL, SQLite, ordinary DuckDB, or a ' +\n 'non-immediate write strategy.',\n );\n this.name = 'UnsupportedContentListWorkflowStorageError';\n }\n}\n\nexport function assertContentListWorkflowStorageSupported(\n storage: ContentListWorkflowStorage,\n): void {\n const adapterType: unknown = storage?.adapterType;\n const writeStrategy: unknown = storage?.writeStrategy;\n if (\n adapterType !== 'sqlite' &&\n adapterType !== 'postgres' &&\n adapterType !== 'duckdb' &&\n adapterType !== 'json'\n ) {\n throw new TypeError(\n 'ContentList workflow storage adapterType must be sqlite, postgres, duckdb, or json.',\n );\n }\n if (\n writeStrategy !== undefined &&\n writeStrategy !== 'immediate' &&\n writeStrategy !== 'manual' &&\n writeStrategy !== 'none'\n ) {\n throw new TypeError(\n 'ContentList workflow storage writeStrategy must be immediate, manual, or none.',\n );\n }\n const effectiveStrategy =\n adapterType === 'json' ? (writeStrategy ?? 'immediate') : writeStrategy;\n if (\n (adapterType === 'json' || adapterType === 'duckdb') &&\n effectiveStrategy === 'immediate'\n ) {\n throw new UnsupportedContentListWorkflowStorageError({\n adapterType,\n writeStrategy: effectiveStrategy,\n });\n }\n}\n\nexport interface ContentListActionAdapterOptions {\n /** Public adapter capability contract; validated before any workflow state is created. */\n workflowStorage: ContentListWorkflowStorage;\n state: DataSurfaceActionStateStore;\n collection(\n run: PrincipalRun,\n ): ContentListActionCollection | Promise<ContentListActionCollection>;\n /** Trusted site/organization narrowing, applied in addition to tenant context. */\n scope?: (\n run: PrincipalRun,\n ) => ContentQueryScope | undefined | Promise<ContentQueryScope | undefined>;\n /** Server-owned mounted/catalog revision. Defaults to zero for standalone endpoints. */\n revision?: (\n run: PrincipalRun,\n identity: DataSurfaceIdentity,\n ) => number | Promise<number>;\n authorize?: (\n workflow: ContentListServerActionId,\n run: PrincipalRun,\n ) => boolean | Promise<boolean>;\n handlers?: ContentListWorkflowHandlers;\n backgroundQueue?: DataSurfaceBackgroundQueue;\n backgroundHandlerId?: string;\n /** In-process secret used to authenticate the durable background envelope. */\n deferredEnvelopeSigningKey?: string | Uint8Array;\n descriptor?: DataSurfaceDescriptor;\n maxSelectionSize?: number;\n representativeLimit?: number;\n tokenTtlMs?: number;\n /** Test/host seam for principal execution; production defaults to executeAsPrincipal. */\n runAsPrincipal?: typeof import('@happyvertical/smrt-agents').executeAsPrincipal;\n /** Resolve the live persona/TenantAgent binding before a queued mutation. */\n resolveDeferredPrincipal?: Parameters<\n typeof createDataSurfaceActionAdapter\n >[0]['resolveDeferredPrincipal'];\n}\n\ninterface ResolvedContentSelection {\n revision: number;\n queryFingerprint: string;\n rowIds: DataSurfaceRowId[];\n rows: Array<Record<string, unknown>>;\n representativeLabels: string[];\n scope: ContentListActionRequest['selection']['scope'];\n}\n\nconst REQUIRED_QUERY_FIELDS = ['id', 'title', 'status', 'updated_at'] as const;\nconst DEFAULT_MAX_SELECTION_SIZE = 200;\nconst DEFAULT_REPRESENTATIVE_LIMIT = 5;\n\nclass ContentListActionError extends Error {\n constructor(readonly reason: string) {\n super(reason);\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isPermissionDenied(error: unknown): boolean {\n if (!(error instanceof Error) || error.name !== 'OperationPermissionError')\n return false;\n const decision = (error as Error & { decision?: unknown }).decision;\n return isRecord(decision) && decision.reason === 'permission_denied';\n}\n\nfunction isServerActionId(value: unknown): value is ContentListServerActionId {\n return CONTENT_LIST_SERVER_ACTIONS.some(({ id }) => id === value);\n}\n\nfunction payloadRecord(\n value: DataSurfaceJsonValue | undefined,\n): Record<string, unknown> {\n return isRecord(value) ? value : {};\n}\n\nfunction validPayload(\n workflowId: ContentListServerActionId,\n payload: DataSurfaceJsonValue | undefined,\n): boolean {\n if (payload !== undefined && !isRecord(payload)) return false;\n const value = payloadRecord(payload);\n const keys = Object.keys(value);\n switch (workflowId) {\n case 'restore':\n return (\n keys.length === 1 &&\n typeof value.status === 'string' &&\n ['draft', 'review', 'published'].includes(value.status)\n );\n case 'categorize':\n return (\n keys.length === 1 &&\n typeof value.category === 'string' &&\n value.category.trim().length > 0 &&\n value.category.length <= 256\n );\n case 'automated-review':\n return (\n keys.every((key) => ['kind', 'policyKey'].includes(key)) &&\n (value.kind === undefined ||\n (typeof value.kind === 'string' &&\n ['facts', 'safety', 'custom'].includes(value.kind) &&\n value.kind.length > 0 &&\n value.kind.length <= 64)) &&\n (value.policyKey === undefined ||\n (typeof value.policyKey === 'string' &&\n value.policyKey.length > 0 &&\n value.policyKey.length <= 128))\n );\n case 'format-body':\n return (\n keys.every((key) => key === 'format') &&\n (value.format === undefined ||\n value.format === 'markdown' ||\n value.format === 'html')\n );\n case 'optimize':\n return (\n keys.every((key) => key === 'instructions') &&\n (value.instructions === undefined ||\n (typeof value.instructions === 'string' &&\n value.instructions.length <= 4096))\n );\n default:\n return keys.length === 0;\n }\n}\n\nfunction actionResult(\n request: unknown,\n ok: boolean,\n reason?: string,\n): DataSurfaceActionResult {\n const candidate = isRecord(request) ? request : {};\n const identityCandidate = isRecord(candidate.identity)\n ? candidate.identity\n : {};\n const identity: DataSurfaceIdentity =\n typeof identityCandidate.surfaceId === 'string' &&\n ['table', 'list', 'report', 'custom'].includes(\n String(identityCandidate.kind),\n )\n ? (identityCandidate as unknown as DataSurfaceIdentity)\n : { surfaceId: 'content-list', kind: 'table' };\n return {\n version: 1,\n requestId:\n typeof candidate.requestId === 'string'\n ? candidate.requestId\n : 'invalid-request',\n identity,\n actionId:\n typeof candidate.actionId === 'string' ? candidate.actionId : 'invalid',\n phase: candidate.phase === 'apply' ? 'apply' : 'preview',\n ok,\n ...(reason ? { reason } : {}),\n };\n}\n\nfunction validateTarget(request: unknown): string | undefined {\n if (\n !isRecord(request) ||\n !isServerActionId(request.actionId) ||\n !isRecord(request.target) ||\n !isRecord(request.selection)\n )\n return 'invalid_request';\n const keys = Object.keys(request.target);\n if (\n keys.some(\n (key) =>\n key !== 'query' && key !== 'expectedCount' && key !== 'confirmedCount',\n )\n )\n return 'invalid_request';\n const expectedCount = request.target.expectedCount;\n if (\n typeof expectedCount !== 'number' ||\n !Number.isSafeInteger(expectedCount) ||\n expectedCount < 0\n ) {\n return 'invalid_request';\n }\n const requiresCountAffirmation =\n request.actionId === 'permanent-delete' && request.phase === 'apply';\n if (\n (requiresCountAffirmation &&\n (request.target.confirmedCount !== expectedCount ||\n !Number.isSafeInteger(request.target.confirmedCount))) ||\n (!requiresCountAffirmation && request.target.confirmedCount !== undefined)\n ) {\n return 'confirmation_count_mismatch';\n }\n if (\n request.selection.scope !== 'explicit-ids' &&\n !isRecord(request.target.query)\n ) {\n return 'invalid_request';\n }\n if (\n request.target.query !== undefined &&\n !isBoundedDataSurfaceJsonValue(request.target.query)\n ) {\n return 'invalid_request';\n }\n return undefined;\n}\n\nfunction statusOf(content: Content): string {\n return String(content.status ?? '').toLowerCase();\n}\n\nasync function publishReady(content: Content): Promise<boolean> {\n const governance = await content.resolveGovernance();\n if (!governance.isGoverned || !governance.enforcePublishReadiness)\n return true;\n if (!governance.publicationProfileKey) return false;\n return (await content.evaluateReviewProfile(governance.publicationProfileKey))\n .ready;\n}\n\nasync function eligibility(\n workflowId: ContentListServerActionId,\n content: Content,\n payload: DataSurfaceJsonValue | undefined,\n handlers: ContentListWorkflowHandlers,\n): Promise<{ eligible: boolean; reason?: string }> {\n const status = statusOf(content);\n if (workflowId === 'restore') {\n if (status !== 'deleted') return { eligible: false, reason: 'not_deleted' };\n if (\n payloadRecord(payload).status === 'published' &&\n !(await publishReady(content))\n ) {\n return { eligible: false, reason: 'publish_readiness_failed' };\n }\n return { eligible: true };\n }\n if (workflowId === 'permanent-delete') {\n return status === 'deleted'\n ? { eligible: true }\n : { eligible: false, reason: 'not_deleted' };\n }\n if (status === 'deleted') return { eligible: false, reason: 'deleted' };\n switch (workflowId) {\n case 'move-to-trash':\n return { eligible: true };\n case 'mark-draft':\n return status === 'draft'\n ? { eligible: false, reason: 'already_draft' }\n : { eligible: true };\n case 'submit-review':\n return status === 'draft'\n ? { eligible: true }\n : { eligible: false, reason: 'requires_draft' };\n case 'publish':\n if (!['draft', 'review', 'archived'].includes(status))\n return { eligible: false, reason: 'invalid_status' };\n return (await publishReady(content))\n ? { eligible: true }\n : { eligible: false, reason: 'publish_readiness_failed' };\n case 'archive':\n return status === 'archived'\n ? { eligible: false, reason: 'already_archived' }\n : { eligible: true };\n case 'automated-review': {\n const governance = await content.resolveGovernance();\n if (!governance.isGoverned)\n return { eligible: false, reason: 'governance_unavailable' };\n const input = payloadRecord(payload);\n const policy =\n typeof input.policyKey === 'string'\n ? governance.reviewPolicies.find(\n (entry) => entry.key === input.policyKey,\n )\n : undefined;\n if (typeof input.policyKey === 'string' && !policy)\n return { eligible: false, reason: 'review_policy_unavailable' };\n if (\n typeof input.kind === 'string' &&\n policy &&\n policy.kind !== input.kind\n )\n return { eligible: false, reason: 'review_kind_mismatch' };\n return { eligible: true };\n }\n case 'format-body':\n return handlers.formatBody\n ? { eligible: true }\n : { eligible: false, reason: 'handler_unavailable' };\n case 'categorize':\n return { eligible: true };\n case 'optimize':\n if (!handlers.optimize)\n return { eligible: false, reason: 'handler_unavailable' };\n return ['draft', 'review'].includes(status)\n ? { eligible: true }\n : { eligible: false, reason: 'requires_draft_or_review' };\n }\n}\n\nasync function applyWorkflow(\n workflowId: ContentListServerActionId,\n content: Content,\n expectedUpdatedAt: Date | string,\n payload: DataSurfaceJsonValue | undefined,\n run: PrincipalRun,\n handlers: ContentListWorkflowHandlers,\n): Promise<void> {\n const input = payloadRecord(payload);\n const save = async () => {\n await content.withTransaction((bound) => bound.save({ expectedUpdatedAt }));\n };\n const mutationDraft = (): ContentListWorkflowDraft => ({\n contentId: String(content.id),\n tenantId: content.tenantId,\n type: content.type,\n variant: content.variant,\n status: content.status,\n state: content.state,\n fileKey: content.fileKey,\n author: content.author,\n name: content.name,\n title: content.title,\n description: content.description,\n body: content.body,\n bodyFormat: content.bodyFormat,\n publish_date: content.publish_date,\n url: content.url,\n source: content.source,\n original_url: content.original_url,\n language: content.language,\n tags: [...(content.tags ?? [])],\n category: content.category,\n metadata: structuredClone(content.metadata ?? {}),\n thumbnailAssetId: content.thumbnailAssetId,\n });\n const applyDraft = (draft: ContentListWorkflowDraft) => {\n content.fileKey = draft.fileKey;\n content.author = draft.author;\n content.name = draft.name;\n content.title = draft.title;\n content.description = draft.description;\n content.body = draft.body;\n content.bodyFormat = draft.bodyFormat;\n content.publish_date = draft.publish_date;\n content.url = draft.url;\n content.source = draft.source;\n content.original_url = draft.original_url;\n content.language = draft.language;\n content.tags = [...draft.tags];\n content.category = draft.category;\n content.metadata = structuredClone(draft.metadata);\n content.thumbnailAssetId = draft.thumbnailAssetId;\n };\n const runHandler = async (\n handler: NonNullable<ContentListWorkflowHandlers['formatBody']>,\n ) => {\n const draft = mutationDraft();\n await handler(draft, payload, run);\n applyDraft(draft);\n await save();\n };\n switch (workflowId) {\n case 'move-to-trash':\n content.status = 'deleted';\n await save();\n return;\n case 'mark-draft':\n content.status = 'draft';\n await save();\n return;\n case 'submit-review':\n content.status = 'review';\n await save();\n return;\n case 'publish':\n content.status = 'published';\n await save();\n return;\n case 'archive':\n content.status = 'archived';\n await save();\n return;\n case 'restore':\n content.status = input.status as Content['status'];\n await save();\n return;\n case 'permanent-delete':\n // Content owns cascading references, so a revision-guarded destructive\n // delete must never use the core's documented non-transaction fallback.\n // Probe through the public object API before any cascade can begin.\n await content.withTransaction(async () => undefined);\n await content.delete({ expectedUpdatedAt });\n return;\n case 'automated-review':\n await content.runReviewAction({\n expectedUpdatedAt,\n ...(typeof input.kind === 'string'\n ? { kind: input.kind as never }\n : {}),\n ...(typeof input.policyKey === 'string'\n ? { policyKey: input.policyKey }\n : {}),\n });\n return;\n case 'format-body':\n if (!handlers.formatBody) throw new Error('format handler unavailable');\n await runHandler(handlers.formatBody);\n return;\n case 'categorize':\n content.category = String(input.category).trim();\n await save();\n return;\n case 'optimize':\n if (!handlers.optimize) throw new Error('optimize handler unavailable');\n await runHandler(handlers.optimize);\n return;\n }\n}\n\nfunction revisionFingerprint(rows: readonly Record<string, unknown>[]): string {\n const canonical = rows\n .map((row) => `${String(row.id)}\\u0000${String(row.updated_at ?? '')}`)\n .sort();\n return createHash('sha256')\n .update(canonical.join('\\u0001'))\n .digest('base64url');\n}\n\nfunction representativeLabels(\n rows: readonly Record<string, unknown>[],\n limit: number,\n): string[] {\n return rows.slice(0, limit).map((row) => {\n const title = typeof row.title === 'string' ? row.title.trim() : '';\n return title || String(row.id);\n });\n}\n\nasync function resolveQuerySelection(\n request: ContentListActionRequest,\n collection: ContentListActionCollection,\n scope: ContentQueryScope | undefined,\n maxSelectionSize: number,\n representativeLimit: number,\n revision: number,\n): Promise<ResolvedContentSelection> {\n const schema = await buildContentQuerySchema();\n const selection = request.selection;\n const rows: Array<Record<string, unknown>> = [];\n let queryFingerprint: string;\n\n if (selection.scope === 'explicit-ids') {\n const ids = [...new Set(selection.rowIds.map((rowId) => String(rowId)))];\n if (ids.length > maxSelectionSize)\n throw new ContentListActionError('limit_exceeded');\n queryFingerprint = `explicit:${revisionFingerprint(ids.map((id) => ({ id })))}`;\n for (let start = 0; start < ids.length; start += 100) {\n const chunk = ids.slice(start, start + 100);\n const query: DataQueryRequest = {\n version: 1,\n requestId: `content-action-explicit-${start}`,\n mode: 'rows',\n projection: [...REQUIRED_QUERY_FIELDS],\n filter: {\n kind: 'condition',\n field: 'id',\n operator: 'in',\n value: chunk,\n },\n sort: [{ field: 'id', direction: 'asc' }],\n page: { kind: 'offset', offset: 0, limit: Math.max(1, chunk.length) },\n };\n const result = await executeContentQuery(collection, query, { scope });\n rows.push(...result.rows);\n }\n queryFingerprint = `${queryFingerprint}:${revisionFingerprint(rows)}`;\n } else {\n const input = request.target.query;\n if (!input) throw new ContentListActionError('invalid_target');\n const normalized = normalizeDataQueryRequest(input, schema);\n const allMatchingPageLimit = Math.min(\n maxSelectionSize,\n MAX_DATA_QUERY_PAGE_LIMIT,\n );\n const querySchema =\n selection.scope === 'all-matching'\n ? {\n ...schema,\n defaultPageLimit: Math.min(\n schema.defaultPageLimit ?? CONTENT_QUERY_MAX_PAGE_LIMIT,\n allMatchingPageLimit,\n ),\n maxPageLimit: allMatchingPageLimit,\n }\n : schema;\n if (normalized.mode !== 'rows')\n throw new ContentListActionError('invalid_target');\n for (const field of REQUIRED_QUERY_FIELDS) {\n if (!normalized.projection?.includes(field))\n throw new ContentListActionError('missing_action_projection');\n }\n const baseFingerprint = createDataQueryFingerprint(normalized, schema);\n if (\n selection.scope === 'all-matching' &&\n selection.queryFingerprint !== baseFingerprint\n ) {\n throw new ContentListActionError('stale_query_fingerprint');\n }\n const pageLimit =\n selection.scope === 'current-page'\n ? (normalized.page?.limit ?? CONTENT_QUERY_MAX_PAGE_LIMIT)\n : allMatchingPageLimit;\n const offset =\n selection.scope === 'current-page' && normalized.page?.kind === 'offset'\n ? normalized.page.offset\n : 0;\n const pageRequest: DataQueryRequest = {\n ...normalized,\n requestId: `${normalized.requestId}-action-${offset}`.slice(0, 128),\n page: { kind: 'offset', offset, limit: Math.max(1, pageLimit) },\n };\n const result = await executeContentQuery(collection, pageRequest, {\n scope,\n schema: querySchema,\n });\n if (result.total.kind !== 'exact')\n throw new ContentListActionError('count_unavailable');\n if (selection.scope === 'all-matching' && result.total.value > pageLimit) {\n throw new ContentListActionError('limit_exceeded');\n }\n rows.push(...result.rows);\n if (\n selection.scope === 'all-matching' &&\n rows.length !== result.total.value\n ) {\n throw new ContentListActionError('matching_count_drifted');\n }\n if (selection.scope === 'all-matching') {\n const distinctIds = new Set(rows.map((row) => String(row.id)));\n if (distinctIds.size !== rows.length) {\n throw new ContentListActionError('matching_count_drifted');\n }\n }\n queryFingerprint = `${baseFingerprint}:${revisionFingerprint(rows)}`;\n }\n\n if (request.target.expectedCount !== rows.length) {\n throw new ContentListActionError('matching_count_drifted');\n }\n return {\n revision,\n queryFingerprint,\n rowIds: rows.map((row) => row.id as DataSurfaceRowId),\n rows,\n representativeLabels: representativeLabels(rows, representativeLimit),\n scope: selection.scope,\n };\n}\n\nfunction defaultDescriptor(maxSelectionSize: number): DataSurfaceDescriptor {\n return {\n version: 1,\n identity: { surfaceId: 'content-list', kind: 'table' },\n schemaVersion: 2,\n label: 'Contents',\n rowKey: 'id',\n columns: [\n {\n id: 'id',\n label: 'Content id',\n fieldName: 'id',\n role: 'row-key',\n capabilities: ['read', 'project'],\n },\n {\n id: 'title',\n label: 'Title',\n fieldName: 'title',\n capabilities: ['read', 'project'],\n },\n {\n id: 'status',\n label: 'Status',\n fieldName: 'status',\n role: 'status',\n capabilities: ['read', 'project'],\n },\n ],\n query: {\n modes: ['rows', 'count'],\n projectableColumnIds: ['id', 'title', 'status'],\n },\n controls: [],\n actions: CONTENT_LIST_SERVER_ACTIONS.map((entry) => ({\n id: entry.id,\n label: entry.label,\n description: entry.description,\n sensitivity: entry.sensitivity,\n selectionScopes: [...entry.selectionScopes],\n requiresConfirmation: entry.confirmation === 'required',\n })),\n limits: {\n maxQueryRows: CONTENT_QUERY_MAX_PAGE_LIMIT,\n maxQueryBytes: 1_000_000,\n maxSelectionSize,\n },\n };\n}\n\nexport interface ContentListActionAdapter extends DataSurfaceActionAdapter {\n preview(\n request: ContentListActionRequest,\n context: DataSurfaceServerActionContext,\n ): Promise<DataSurfaceActionResult>;\n apply(\n request: ContentListActionRequest,\n context: DataSurfaceServerActionContext,\n ): Promise<DataSurfaceActionResult>;\n}\n\nexport function createContentListActionAdapter(\n options: ContentListActionAdapterOptions,\n): ContentListActionAdapter {\n assertContentListWorkflowStorageSupported(options.workflowStorage);\n const handlers = options.handlers ?? {};\n const maxSelectionSize =\n options.maxSelectionSize ??\n options.descriptor?.limits.maxSelectionSize ??\n DEFAULT_MAX_SELECTION_SIZE;\n if (\n !Number.isSafeInteger(maxSelectionSize) ||\n maxSelectionSize < 1 ||\n maxSelectionSize > MAX_DATA_QUERY_PAGE_LIMIT\n ) {\n throw new Error(\n `ContentList maxSelectionSize must be an integer between 1 and ${MAX_DATA_QUERY_PAGE_LIMIT} so all-matching membership resolves in one bounded query`,\n );\n }\n const representativeLimit =\n options.representativeLimit ?? DEFAULT_REPRESENTATIVE_LIMIT;\n const descriptor = options.descriptor ?? defaultDescriptor(maxSelectionSize);\n if (descriptor.limits.maxSelectionSize !== maxSelectionSize) {\n throw new Error(\n 'ContentList descriptor maxSelectionSize must match the server selection cap',\n );\n }\n const resolvedByRequest = new WeakMap<object, ResolvedContentSelection>();\n const contentByRequest = new WeakMap<\n object,\n Map<string, Promise<Content | null>>\n >();\n // Request ids are client input and may collide across concurrent calls.\n const invocationResources = new AsyncLocalStorage<\n Map<string, { resourceId: string; resourceType: string }>\n >();\n async function loadContent(\n invocation: { run: PrincipalRun; request: DataSurfaceServerActionRequest },\n rowId: DataSurfaceRowId,\n ): Promise<Content | null> {\n const key = String(rowId);\n let byRow = contentByRequest.get(invocation.request);\n if (!byRow) {\n byRow = new Map();\n contentByRequest.set(invocation.request, byRow);\n }\n let pending = byRow.get(key);\n if (!pending) {\n pending = (async () => {\n const collection = await options.collection(invocation.run);\n const content = await collection.get({ id: key });\n if (!content) return null;\n const serialized = content.toJSON() as Record<string, unknown>;\n invocationResources.getStore()?.set(key, {\n resourceId: String(content.id),\n resourceType:\n typeof serialized._meta_type === 'string'\n ? serialized._meta_type\n : content.constructor.name,\n });\n const resolved = resolvedByRequest.get(invocation.request);\n const expected = resolved?.rows.find((row) => String(row.id) === key);\n const revisionValue = (value: unknown) =>\n value instanceof Date ? value.toISOString() : String(value ?? '');\n if (\n !expected ||\n revisionValue(content.updated_at) !==\n revisionValue(expected.updated_at)\n ) {\n throw new ContentListActionError('row_revision_drifted');\n }\n return content;\n })();\n byRow.set(key, pending);\n }\n return pending;\n }\n\n const mapActionError = (error: unknown) =>\n error instanceof ContentListActionError\n ? error.reason\n : isRecord(error) && error.code === 'RUNTIME_REVISION_CONFLICT'\n ? 'row_revision_drifted'\n : isPermissionDenied(error) ||\n error instanceof PrincipalToolNotAllowedError\n ? 'denied'\n : undefined;\n\n const definitions = Object.fromEntries(\n CONTENT_LIST_SERVER_ACTIONS.map(\n (entry): [string, DataSurfaceServerActionDefinition] => [\n entry.id,\n {\n descriptor: {\n id: entry.id,\n label: entry.label,\n description: entry.description,\n sensitivity: entry.sensitivity,\n selectionScopes: [...entry.selectionScopes],\n requiresConfirmation: entry.confirmation === 'required',\n },\n inputSchema: entry.inputSchema,\n validatePayload: (payload) =>\n validPayload(entry.id, payload)\n ? { valid: true }\n : { valid: false, reason: 'invalid_payload' },\n confirmation: entry.confirmation,\n execution: entry.execution,\n tool: entry.permissionRequirements.tool,\n operation:\n entry.permissionRequirements.operations[0] ??\n CONTENT_READ_OPERATION,\n authorize: async (invocation) => {\n const operations =\n entry.id === 'restore' &&\n payloadRecord(invocation.request.payload).status !== 'published'\n ? entry.permissionRequirements.operations.slice(0, 2)\n : entry.permissionRequirements.operations;\n for (const operation of operations.slice(1)) {\n try {\n await invocation.run.assertOperation(\n operation.collection,\n operation.action,\n );\n } catch (error) {\n if (isPermissionDenied(error)) return false;\n throw error;\n }\n }\n return options.authorize?.(entry.id, invocation.run) ?? true;\n },\n eligible: async (invocation, rowId) => {\n const content = await loadContent(invocation, rowId);\n if (!content)\n return { eligible: false, reason: 'not_found_or_denied' };\n return eligibility(\n entry.id,\n content,\n invocation.request.payload,\n handlers,\n );\n },\n apply: async (invocation, rowId) => {\n const content = await loadContent(invocation, rowId);\n if (!content) throw new Error('content not found');\n const expectedUpdatedAt = content.updated_at;\n if (\n !(expectedUpdatedAt instanceof Date) &&\n typeof expectedUpdatedAt !== 'string'\n ) {\n throw new ContentListActionError('row_revision_drifted');\n }\n const resource = invocationResources.getStore()?.get(String(rowId));\n try {\n await applyWorkflow(\n entry.id,\n content,\n expectedUpdatedAt,\n invocation.request.payload,\n invocation.run,\n handlers,\n );\n } catch (error) {\n if (entry.id !== 'permanent-delete') throw error;\n // delete() commits before its post-delete hooks. If one of those\n // hooks fails, confirm the authoritative row state so an\n // irreversible success is never reported as retryable failure.\n const collection = await options.collection(invocation.run);\n if (await collection.get({ id: String(rowId) })) throw error;\n }\n return resource ?? null;\n },\n },\n ],\n ),\n );\n\n const state: DataSurfaceActionStateStore = {\n putToken: (...args) => options.state.putToken(...args),\n getToken: (...args) => options.state.getToken(...args),\n markTokenConsumed: (...args) => options.state.markTokenConsumed(...args),\n consumeTokenAndReserveIdempotency: (...args) =>\n options.state.consumeTokenAndReserveIdempotency(...args),\n getIdempotency: (...args) => options.state.getIdempotency(...args),\n reserveIdempotency: (...args) => options.state.reserveIdempotency(...args),\n completeIdempotency: (key, ownerToken, result) => {\n if (result.details) {\n result.details = {\n ...result.details,\n auditReference: result.requestId,\n };\n }\n return options.state.completeIdempotency(key, ownerToken, result);\n },\n releaseIdempotency: (...args) => options.state.releaseIdempotency(...args),\n };\n\n const generic = createDataSurfaceActionAdapter({\n state,\n backgroundQueue: options.backgroundQueue,\n backgroundHandlerId: options.backgroundHandlerId,\n deferredEnvelopeSigningKey: options.deferredEnvelopeSigningKey,\n tokenTtlMs: options.tokenTtlMs,\n runAsPrincipal: options.runAsPrincipal,\n resolveDeferredPrincipal: options.resolveDeferredPrincipal,\n requestFingerprintExtension: (request) =>\n (() => {\n const target = (request as ContentListActionRequest).target;\n // The operator-entered count exists only on apply. Bind the preview's\n // server-checked expected count/query into the token while validating\n // the separate affirmation above before the generic adapter runs.\n return {\n expectedCount: target.expectedCount,\n ...(target.query ? { query: target.query } : {}),\n } as unknown as DataSurfaceJsonValue;\n })(),\n mapError: mapActionError,\n resolveSurface: async (run) => ({\n descriptor,\n revision: await (options.revision?.(run, descriptor.identity) ?? 0),\n actions: definitions,\n }),\n resolveSelection: async (invocation, selection) => {\n const request = invocation.request as ContentListActionRequest;\n const collection = await options.collection(invocation.run);\n const scope = await options.scope?.(invocation.run);\n const revision = await (options.revision?.(\n invocation.run,\n descriptor.identity,\n ) ?? 0);\n const resolved = await resolveQuerySelection(\n { ...request, selection },\n collection,\n scope,\n maxSelectionSize,\n representativeLimit,\n revision,\n );\n resolvedByRequest.set(request, resolved);\n return resolved;\n },\n });\n\n async function invoke(\n phase: 'preview' | 'apply',\n request: ContentListActionRequest,\n context: DataSurfaceServerActionContext,\n ): Promise<DataSurfaceActionResult> {\n const invalid = validateTarget(request);\n if (invalid) return actionResult(request, false, invalid);\n try {\n const resources = new Map<\n string,\n { resourceId: string; resourceType: string }\n >();\n const result = await invocationResources.run(resources, () =>\n generic[phase](request, context),\n );\n const resolved = resolvedByRequest.get(request);\n const workflow = CONTENT_LIST_SERVER_ACTIONS.find(\n (entry) => entry.id === request.actionId,\n );\n const outcomes = Array.isArray(result.details?.outcomes)\n ? result.details.outcomes.map((outcome) => {\n if (!isRecord(outcome)) return outcome;\n const resource =\n resources?.get(String(outcome.rowId)) ??\n (typeof outcome.resourceId === 'string' &&\n typeof outcome.resourceType === 'string'\n ? {\n resourceId: outcome.resourceId,\n resourceType: outcome.resourceType,\n }\n : undefined);\n return resource ? { ...outcome, ...resource } : outcome;\n })\n : undefined;\n if (phase !== 'preview' || !result.ok) {\n return {\n ...result,\n ...(result.details\n ? {\n details: {\n ...result.details,\n ...(outcomes ? { outcomes } : {}),\n auditReference:\n typeof result.details.auditReference === 'string'\n ? result.details.auditReference\n : request.requestId,\n },\n }\n : {}),\n };\n }\n return {\n ...result,\n details: {\n ...(result.details ?? {}),\n ...(outcomes ? { outcomes } : {}),\n resolvedScope: resolved?.scope ?? request.selection.scope,\n representativeLabels: resolved?.representativeLabels ?? [],\n ineligible: Array.isArray(result.details?.outcomes)\n ? result.details.outcomes.filter(\n (entry) => isRecord(entry) && entry.status === 'skipped',\n )\n : [],\n consequences: workflow?.consequences ?? [],\n sensitivity: workflow?.sensitivity ?? 'public',\n execution: workflow?.execution ?? 'foreground',\n auditReference: request.requestId,\n },\n };\n } catch (error) {\n return actionResult(\n request,\n false,\n mapActionError(error) ?? 'execution_failed',\n );\n } finally {\n resolvedByRequest.delete(request);\n }\n }\n\n return {\n preview: (request, context) => invoke('preview', request, context),\n apply: (request, context) => invoke('apply', request, context),\n executeDeferred: (envelope) => generic.executeDeferred(envelope),\n };\n}\n","/** Principal-bound, silent ContentList query discovery and execution (#2456). */\n\nimport type {\n DataSurfaceDefinition,\n DataSurfaceExecutionContext,\n DataSurfaceSchema,\n} from '@happyvertical/smrt-agents';\nimport { normalizeDataQueryRequest } from '@happyvertical/smrt-core';\nimport type { DataQuerySchema } from '@happyvertical/smrt-types';\nimport {\n assertContentQuerySchema,\n buildContentQuerySchema,\n CONTENT_QUERY_CLASS_NAME,\n type ContentQueryCollection,\n type ContentQueryScope,\n executeContentQuery,\n} from '../content-query.js';\n\nexport const CONTENT_LIST_DATA_SURFACE_ID = 'content-list';\nexport const CONTENT_LIST_DATA_SURFACE_COLLECTION = 'contents';\n\nexport interface ContentListDataSurfaceOptions {\n /** Stable catalog id. Defaults to the mounted ContentList surface id. */\n id?: string;\n /** Permission-catalog collection checked by the generic agent tools. */\n collectionName?: string;\n label?: string;\n description?: string;\n metadata?: NonNullable<DataSurfaceDefinition['metadata']>;\n /** Resolve a collection from the live principal context, never model input. */\n collection:\n | ContentQueryCollection\n | ((\n context: DataSurfaceExecutionContext,\n ) => ContentQueryCollection | Promise<ContentQueryCollection>);\n /** Trusted application narrowing applied in addition to tenant isolation. */\n scope?:\n | ContentQueryScope\n | ((\n context: DataSurfaceExecutionContext,\n ) =>\n | ContentQueryScope\n | undefined\n | Promise<ContentQueryScope | undefined>);\n /** Trusted policy override; defaults to the canonical Content query schema. */\n schema?: DataSurfaceSchema;\n}\n\nfunction requiredName(\n value: string | undefined,\n fallback: string,\n label: string,\n) {\n const resolved = value ?? fallback;\n if (resolved.trim().length === 0) {\n throw new Error(`${label} must be a non-empty string`);\n }\n return resolved;\n}\n\nfunction querySchema(schema: DataSurfaceSchema): DataQuerySchema {\n return {\n ...schema,\n // A host descriptor is untrusted at this boundary. Discovery redacts\n // protected fields, and execution uses the same principal-aware field set\n // so a direct data.query request cannot bypass that policy.\n fields: schema.fields\n .filter(({ sensitive, readPermission }) => {\n if (sensitive) return false;\n return !readPermission;\n })\n .map(\n ({\n sensitive: _sensitive,\n readPermission: _readPermission,\n metadata: _metadata,\n ...field\n }) => field,\n ),\n };\n}\n\nasync function resolveCollection(\n options: ContentListDataSurfaceOptions,\n context: DataSurfaceExecutionContext,\n): Promise<ContentQueryCollection> {\n return typeof options.collection === 'function'\n ? options.collection(context)\n : options.collection;\n}\n\nasync function resolveScope(\n options: ContentListDataSurfaceOptions,\n context: DataSurfaceExecutionContext,\n): Promise<ContentQueryScope | undefined> {\n return typeof options.scope === 'function'\n ? options.scope(context)\n : options.scope;\n}\n\n/**\n * Build one server-owned ContentList surface for `data.discover`,\n * `data.inspect`, and silent/background `data.query` calls.\n *\n * The returned executor resolves its collection and application scope from the\n * live principal context. The request can only narrow that trusted scope, and\n * every projection/count/facet/page still passes through `executeContentQuery`.\n */\nexport async function createContentListDataSurfaceDefinition(\n options: ContentListDataSurfaceOptions,\n): Promise<DataSurfaceDefinition> {\n const schema = options.schema ?? (await buildContentQuerySchema());\n // `SmrtCollection.list({ select })` intentionally refuses model fields with\n // readPermission because that projection primitive has no permission\n // context. Publishing one here would let discovery promise a query that the\n // real collection cannot execute. Keep the server data surface fail-closed:\n // only universally executable, non-sensitive fields are advertised.\n const executableSchema = querySchema(schema);\n assertContentQuerySchema(executableSchema);\n\n return {\n id: requiredName(\n options.id,\n CONTENT_LIST_DATA_SURFACE_ID,\n 'ContentList data surface id',\n ),\n collection: requiredName(\n options.collectionName,\n CONTENT_LIST_DATA_SURFACE_COLLECTION,\n 'ContentList permission collection',\n ),\n className: CONTENT_QUERY_CLASS_NAME,\n label: options.label ?? 'Contents',\n description:\n options.description ??\n 'Bounded, tenant-safe content rows, counts, facets, and continuations.',\n metadata: {\n domain: 'content',\n adapter: 'ContentList',\n views: ['grid', 'detailed', 'compact'],\n queryModes: ['rows', 'count', 'facets'],\n ...options.metadata,\n },\n schema: executableSchema,\n execute: async (_surface, request, context) => {\n // Validate before resolving the host collection. This makes a rejected\n // protected projection a zero-I/O failure, even for hostile descriptors.\n normalizeDataQueryRequest(request, executableSchema);\n return executeContentQuery(\n await resolveCollection(options, context),\n request,\n {\n schema: executableSchema,\n scope: await resolveScope(options, context),\n },\n );\n },\n };\n}\n","/**\n * Principal-bound HTTP boundary for ContentList lifecycle actions (#2454).\n *\n * Hosts supply authentication by resolving a DataSurface server context from\n * the incoming Request. The service gates this dedicated endpoint to lifecycle\n * actions, then delegates to the same content action adapter used by agents and\n * bulk workflows so authorization, selection resolution, confirmation,\n * idempotency, and audit metadata cannot diverge by caller.\n */\n\nimport type { DataSurfaceServerActionContext } from '@happyvertical/smrt-agents/server';\nimport type {\n DataSurfaceActionResult,\n DataSurfaceIdentity,\n} from '@happyvertical/smrt-types';\nimport {\n CONTENT_LIST_LIFECYCLE_ACTION_IDS,\n type ContentListActionAdapter,\n type ContentListActionRequest,\n type ContentListLifecycleActionId,\n} from './content-list-actions.js';\n\nexport interface ContentListLifecycleService {\n invoke(\n request: unknown,\n context: DataSurfaceServerActionContext,\n ): Promise<DataSurfaceActionResult>;\n}\n\nexport interface ContentListLifecycleRouteOptions {\n adapter: ContentListActionAdapter;\n /** Authenticate and bind the request to its current principal/tenant. */\n context(\n request: Request,\n ): DataSurfaceServerActionContext | Promise<DataSurfaceServerActionContext>;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isLifecycleActionId(\n value: unknown,\n): value is ContentListLifecycleActionId {\n return (CONTENT_LIST_LIFECYCLE_ACTION_IDS as readonly unknown[]).includes(\n value,\n );\n}\n\nfunction safeIdentity(value: unknown): DataSurfaceIdentity {\n if (!isRecord(value)) return { surfaceId: 'content-list', kind: 'table' };\n if (\n typeof value.surfaceId !== 'string' ||\n !['table', 'list', 'report', 'custom'].includes(String(value.kind))\n ) {\n return { surfaceId: 'content-list', kind: 'table' };\n }\n return value as unknown as DataSurfaceIdentity;\n}\n\nfunction rejected(\n request: unknown,\n reason: 'invalid_request' | 'unsupported',\n): DataSurfaceActionResult {\n const candidate = isRecord(request) ? request : {};\n return {\n version: 1,\n requestId:\n typeof candidate.requestId === 'string'\n ? candidate.requestId\n : 'invalid-request',\n identity: safeIdentity(candidate.identity),\n actionId:\n typeof candidate.actionId === 'string' ? candidate.actionId : 'invalid',\n phase: candidate.phase === 'apply' ? 'apply' : 'preview',\n ok: false,\n reason,\n };\n}\n\n/** Create the transport-neutral lifecycle service used by HTTP and agent hosts. */\nexport function createContentListLifecycleService(\n adapter: ContentListActionAdapter,\n): ContentListLifecycleService {\n return {\n async invoke(request, context) {\n if (!isRecord(request)) return rejected(request, 'invalid_request');\n if (!isLifecycleActionId(request.actionId)) {\n return rejected(request, 'unsupported');\n }\n if (request.phase !== 'preview' && request.phase !== 'apply') {\n return rejected(request, 'invalid_request');\n }\n return adapter[request.phase](\n request as unknown as ContentListActionRequest,\n context,\n );\n },\n };\n}\n\n/**\n * Create a native Request/Response handler for `POST /api/v1/contents/lifecycle`.\n * SvelteKit hosts can call it with `event.request`; other runtimes can mount it\n * directly anywhere that implements the standard Fetch API.\n */\nexport function createContentListLifecycleRoute(\n options: ContentListLifecycleRouteOptions,\n): (request: Request) => Promise<Response> {\n const service = createContentListLifecycleService(options.adapter);\n return async (request) => {\n if (request.method !== 'POST') {\n return Response.json(\n { error: { message: 'Method not allowed.' } },\n { status: 405, headers: { allow: 'POST' } },\n );\n }\n let input: unknown;\n try {\n input = await request.json();\n } catch {\n return Response.json(\n { error: { message: 'The lifecycle request body must be JSON.' } },\n { status: 400 },\n );\n }\n let context: DataSurfaceServerActionContext;\n try {\n context = await options.context(request);\n } catch {\n return Response.json(\n { error: { message: 'Authentication is required.' } },\n { status: 401 },\n );\n }\n try {\n return Response.json({ result: await service.invoke(input, context) });\n } catch {\n return Response.json(\n { error: { message: 'The lifecycle request could not be completed.' } },\n { status: 500 },\n );\n }\n };\n}\n","/**\n * SMRT Content Service Server\n *\n * Demonstrates auto-generated REST API from SMRT Content objects.\n * No manual route definitions needed - everything is generated from @smrt() decorated classes.\n */\n\nimport { startRestServer } from '@happyvertical/smrt-core';\nimport './__smrt-register__.js';\nimport { Content } from './content';\n\nasync function startServer() {\n console.log('🚀 Starting SMRT Content Server...');\n\n // Start server with registered SMRT objects\n const shutdown = await startRestServer(\n [Content], // SMRT objects to generate API for\n {}, // context\n {\n port: 3100,\n hostname: 'localhost',\n basePath: '/api/v1',\n enableCors: true,\n },\n );\n\n console.log('✅ Server ready!');\n console.log('📡 REST API: http://localhost:3100/api/v1');\n console.log('📚 Endpoints:');\n console.log(' GET /api/v1/contents - List contents');\n console.log(' POST /api/v1/contents - Create content');\n console.log(' GET /api/v1/contents/:id - Get content');\n console.log(' PUT /api/v1/contents/:id - Update content');\n console.log(' DELETE /api/v1/contents/:id - Delete content');\n\n console.log('\\n💡 Try these endpoints:');\n console.log(' curl http://localhost:3100/api/v1/contents');\n console.log(\n ' curl -X POST http://localhost:3100/api/v1/contents -H \"Content-Type: application/json\" -d \\'{\"title\":\"Test Content\",\"body\":\"Test body content\"}\\'',\n );\n\n return { shutdown };\n}\n\n// Start if running directly\nif (import.meta.url === `file://${process.argv[1]}`) {\n startServer().catch(console.error);\n}\n\nexport * from './server/content-list-actions.js';\nexport * from './server/content-list-data-surface.js';\nexport * from './server/content-list-lifecycle.js';\nexport { startServer };\n"],"mappings":";;;;;;;;AAsDO,IAAM,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGO,IAAM,oCAAoC;CAC/C;CACA;CACA;AACF;AA8BA,IAAM,uBAAyE;CAC7E;CACA;CACA;AACF;AAEA,IAAM,WAAkC;CACtC,MAAM;CACN,sBAAsB;AACxB;AAEA,IAAM,wBAA+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