@simmalugnt-se/payload-editor-assistant 0.1.1 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ Breaking: options that were accepted but did nothing are removed.
6
+
7
+ - `tools` (and the `HostToolDefinition` type): host tools were validated but never given to the
8
+ model. They will come back when the assistant can run them.
9
+ - `audit.retentionDays`: nothing deleted old audit entries.
10
+
11
+ Also: README documents `validateProposal`.
12
+
3
13
  ## 0.1.1
4
14
 
5
15
  - Provider failures are logged on the server through Payload's logger (missing model, `ai` not
package/README.md CHANGED
@@ -87,6 +87,7 @@ secrets (`password`, `token`, `apiKey`, ...) are always off limits.
87
87
  | `shortcuts` | One-click prompts in the drawer: `{ id, label, prompt, when?, entities? }`. |
88
88
  | `enabled` | `({ userId }) => boolean` to offer the assistant to some users only. |
89
89
  | `redact` | `({ slug, data }) => data` to strip values before documents reach the model. |
90
+ | `validateProposal` | `({ operations, data }) => ({ ok: true } \| { ok: false, errors })` for project rules. Runs before a proposal reaches the editor; errors go back to the assistant, which can correct itself. |
90
91
  | `trustedOrigins` | Origins allowed to call the assistant's endpoints. Default: only the origin serving Admin. When set, only the listed origins. |
91
92
  | `audit.collection` | Slug of the collection that logs assistant actions (default `editor-assistant-audit`). |
92
93
  | `disabled` | Turn the plugin off without removing its config. |
@@ -1,15 +1,13 @@
1
- import type { EditorAssistantPluginOptions, EntityAllowlist, HostToolDefinition } from "../types.ts";
1
+ import type { EditorAssistantPluginOptions, EntityAllowlist } from "../types.ts";
2
2
  export type ValidatedEditorAssistantOptions = EditorAssistantPluginOptions & {
3
3
  disabled: boolean;
4
4
  collections: Record<string, EntityAllowlist>;
5
5
  globals: Record<string, EntityAllowlist>;
6
6
  denyFields: string[];
7
7
  shortcuts: NonNullable<EditorAssistantPluginOptions["shortcuts"]>;
8
- tools: HostToolDefinition[];
9
8
  trustedOrigins: string[];
10
9
  audit: {
11
10
  collection: string;
12
- retentionDays?: number;
13
11
  };
14
12
  };
15
13
  export declare function validateEditorAssistantOptions(options: EditorAssistantPluginOptions): ValidatedEditorAssistantOptions;
@@ -1,6 +1,5 @@
1
- import { BUILTIN_RISK, EMBEDDED_ONLY_CAPABILITIES, isBuiltinCapability, isEntityCapability, } from "../capabilities.js";
1
+ import { isEntityCapability } from "../capabilities.js";
2
2
  import { isDeniedCollectionSlug } from "./denied-fields.js";
3
- const RISK_ORDER = { auto: 0, approval: 1, forbidden: 2 };
4
3
  export function validateEditorAssistantOptions(options) {
5
4
  const disabled = options.disabled === true;
6
5
  const collections = options.collections ?? {};
@@ -11,7 +10,6 @@ export function validateEditorAssistantOptions(options) {
11
10
  }
12
11
  validateEntityMap("collections", collections, { allowDraftCreate: true });
13
12
  validateEntityMap("globals", globals, { allowDraftCreate: false });
14
- validateHostTools(options.tools ?? []);
15
13
  }
16
14
  return {
17
15
  ...options,
@@ -20,11 +18,9 @@ export function validateEditorAssistantOptions(options) {
20
18
  globals,
21
19
  denyFields: options.denyFields ?? [],
22
20
  shortcuts: options.shortcuts ?? [],
23
- tools: options.tools ?? [],
24
21
  trustedOrigins: options.trustedOrigins ?? [],
25
22
  audit: {
26
23
  collection: options.audit?.collection ?? "editor-assistant-audit",
27
- retentionDays: options.audit?.retentionDays,
28
24
  },
29
25
  };
30
26
  }
@@ -62,25 +58,3 @@ function validateFields(entry, label) {
62
58
  throw new Error(`payload-editor-assistant: ${label} fields.exclude must be an array.`);
63
59
  }
64
60
  }
65
- function validateHostTools(tools) {
66
- for (const tool of tools) {
67
- if (!tool.id || !tool.capabilityId) {
68
- throw new Error("payload-editor-assistant: host tools require id and capabilityId.");
69
- }
70
- const risk = tool.risk ?? "approval";
71
- if (risk !== "auto" && risk !== "approval" && risk !== "forbidden") {
72
- throw new Error(`payload-editor-assistant: host tool "${tool.id}" has invalid risk.`);
73
- }
74
- if (isBuiltinCapability(tool.capabilityId)) {
75
- if (RISK_ORDER[risk] < RISK_ORDER[BUILTIN_RISK[tool.capabilityId]]) {
76
- throw new Error(`payload-editor-assistant: host tool "${tool.id}" cannot loosen risk below ${tool.capabilityId}.`);
77
- }
78
- if (tool.mcp && EMBEDDED_ONLY_CAPABILITIES.has(tool.capabilityId)) {
79
- throw new Error(`payload-editor-assistant: host tool "${tool.id}" cannot mark ${tool.capabilityId} as MCP-eligible.`);
80
- }
81
- }
82
- if (risk === "auto" && tool.mcp === true && tool.capabilityId === "form.propose") {
83
- throw new Error(`payload-editor-assistant: host tool "${tool.id}" cannot expose form writes to MCP.`);
84
- }
85
- }
86
- }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { BuiltinCapability, CapabilityRisk, EntityCapability } from "./capabilities.ts";
2
2
  export { BUILTIN_CAPABILITIES, BUILTIN_RISK, ENTITY_CAPABILITIES } from "./capabilities.ts";
3
3
  export { editorAssistantPlugin } from "./plugin.ts";
4
- export type { AssistantShortcut, EditorAssistantPluginOptions, EntityAllowlist, FieldAllowlist, HostLanguageModel, HostToolDefinition, ModelResolver, ProposalValidationResult, } from "./types.ts";
4
+ export type { AssistantShortcut, EditorAssistantPluginOptions, EntityAllowlist, FieldAllowlist, HostLanguageModel, ModelResolver, ProposalValidationResult, } from "./types.ts";
5
5
  export { defineEditorAssistantConfig } from "./types.ts";
package/dist/types.d.ts CHANGED
@@ -22,13 +22,6 @@ export type AssistantShortcut = {
22
22
  /** Collection or global slugs where the shortcut is shown. Views without an entity (dashboard) are not filtered. */
23
23
  entities?: string[];
24
24
  };
25
- export type HostToolRisk = "auto" | "approval" | "forbidden";
26
- export type HostToolDefinition = {
27
- id: string;
28
- capabilityId: string;
29
- risk?: HostToolRisk;
30
- mcp?: boolean;
31
- };
32
25
  export type ProposalValidationResult = {
33
26
  ok: true;
34
27
  } | {
@@ -43,7 +36,6 @@ export type EditorAssistantPluginOptions = {
43
36
  denyFields?: string[];
44
37
  instructions?: string;
45
38
  shortcuts?: AssistantShortcut[];
46
- tools?: HostToolDefinition[];
47
39
  validateProposal?: (input: unknown) => ProposalValidationResult | Promise<ProposalValidationResult>;
48
40
  redact?: (input: {
49
41
  slug: string;
@@ -55,7 +47,6 @@ export type EditorAssistantPluginOptions = {
55
47
  trustedOrigins?: string[];
56
48
  audit?: {
57
49
  collection?: string;
58
- retentionDays?: number;
59
50
  };
60
51
  };
61
52
  export declare function defineEditorAssistantConfig<T extends EditorAssistantPluginOptions>(options: T): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simmalugnt-se/payload-editor-assistant",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Context-aware editor assistant plugin for Payload Admin",
5
5
  "keywords": [
6
6
  "payload",