@jini-ai/plugins 0.0.0-stage → 0.4.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +201 -0
  3. package/README.md +60 -2
  4. package/dist/glue/attachment-points/content-lifecycle.d.ts +10 -0
  5. package/dist/glue/attachment-points/content-lifecycle.js +5 -0
  6. package/dist/glue/attachment-points/events.d.ts +12 -0
  7. package/dist/glue/attachment-points/events.js +5 -0
  8. package/dist/glue/attachment-points/tool-registration.d.ts +23 -0
  9. package/dist/glue/attachment-points/tool-registration.js +43 -0
  10. package/dist/glue/capability-gate.d.ts +20 -0
  11. package/dist/glue/capability-gate.js +23 -0
  12. package/dist/glue/dispatch.d.ts +20 -0
  13. package/dist/glue/dispatch.js +9 -0
  14. package/dist/glue/index.d.ts +8 -0
  15. package/dist/glue/index.js +8 -0
  16. package/dist/glue/manifest.d.ts +43 -0
  17. package/dist/glue/manifest.js +106 -0
  18. package/dist/glue/ports.d.ts +60 -0
  19. package/dist/glue/ports.js +2 -0
  20. package/dist/host/activation.d.ts +118 -0
  21. package/dist/host/activation.js +104 -0
  22. package/dist/host/attach-loaded-plugin.d.ts +37 -0
  23. package/dist/host/attach-loaded-plugin.js +19 -0
  24. package/dist/host/capability-sdk.d.ts +74 -0
  25. package/dist/host/capability-sdk.js +58 -0
  26. package/dist/host/claim-conflicts.d.ts +101 -0
  27. package/dist/host/claim-conflicts.js +139 -0
  28. package/dist/host/declarative-enable.d.ts +43 -0
  29. package/dist/host/declarative-enable.js +73 -0
  30. package/dist/host/discovery-types.d.ts +52 -0
  31. package/dist/host/discovery-types.js +2 -0
  32. package/dist/host/errors.d.ts +20 -0
  33. package/dist/host/errors.js +22 -0
  34. package/dist/host/hook-registry.d.ts +113 -0
  35. package/dist/host/hook-registry.js +190 -0
  36. package/dist/host/index.d.ts +16 -0
  37. package/dist/host/index.js +16 -0
  38. package/dist/host/manifest.d.ts +149 -0
  39. package/dist/host/manifest.js +407 -0
  40. package/dist/host/node/discovery.d.ts +25 -0
  41. package/dist/host/node/discovery.js +217 -0
  42. package/dist/host/node/index.d.ts +7 -0
  43. package/dist/host/node/index.js +7 -0
  44. package/dist/host/node/install.d.ts +73 -0
  45. package/dist/host/node/install.js +301 -0
  46. package/dist/host/node/loader.d.ts +55 -0
  47. package/dist/host/node/loader.js +146 -0
  48. package/dist/host/node/module-snapshot.d.ts +25 -0
  49. package/dist/host/node/module-snapshot.js +53 -0
  50. package/dist/host/node/package-files.d.ts +52 -0
  51. package/dist/host/node/package-files.js +214 -0
  52. package/dist/host/plugin-claims.d.ts +113 -0
  53. package/dist/host/plugin-claims.js +134 -0
  54. package/dist/host/ports.d.ts +196 -0
  55. package/dist/host/ports.js +2 -0
  56. package/dist/host/quarantine.d.ts +19 -0
  57. package/dist/host/quarantine.js +28 -0
  58. package/dist/host/repo.memory.d.ts +27 -0
  59. package/dist/host/repo.memory.js +33 -0
  60. package/dist/host/sql/index.d.ts +4 -0
  61. package/dist/host/sql/index.js +4 -0
  62. package/dist/host/sql/repo.d.ts +38 -0
  63. package/dist/host/sql/repo.js +50 -0
  64. package/dist/host/sql/repo.rows.d.ts +28 -0
  65. package/dist/host/sql/repo.rows.js +28 -0
  66. package/dist/host/uninstall.d.ts +88 -0
  67. package/dist/host/uninstall.js +112 -0
  68. package/dist/host/worker/import-seam.d.ts +45 -0
  69. package/dist/host/worker/import-seam.js +52 -0
  70. package/dist/host/worker/index.d.ts +5 -0
  71. package/dist/host/worker/index.js +5 -0
  72. package/dist/host/worker/protocol.d.ts +62 -0
  73. package/dist/host/worker/protocol.js +31 -0
  74. package/dist/host/worker/run-call.d.ts +27 -0
  75. package/dist/host/worker/run-call.js +76 -0
  76. package/package.json +102 -3
@@ -0,0 +1,196 @@
1
+ /** Host contracts only. No product SDK, content-type implementation or executable importer lives here. */
2
+ import type { PluginManifest, PluginValidationError } from './manifest.js';
3
+ import type { PluginDiscoveryRecord } from './discovery-types.js';
4
+ import type { ClaimMode } from './claim-conflicts.js';
5
+ /** Plain serializable entry envelope; hosts extend it with their own hook payload fields. */
6
+ export interface ContentEntryDraft {
7
+ readonly workspaceId: string;
8
+ readonly ext: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
9
+ }
10
+ export interface HookContext {
11
+ readonly pluginId: string;
12
+ readonly workspaceId: string;
13
+ }
14
+ export type ExtPatch = Readonly<Record<string, string | number | boolean>>;
15
+ /** Positional callbacks are the existing plugin wire ABI, not Jini factory boundaries. */
16
+ export type BeforeSaveFilter = (entry: Readonly<ContentEntryDraft>, ctx: HookContext) => ExtPatch | Promise<ExtPatch>;
17
+ export type HookPoints = Readonly<Record<string, unknown>>;
18
+ export interface PluginSdk<H extends HookPoints = HookPoints> {
19
+ readonly content: {
20
+ read(): Readonly<ContentEntryDraft>;
21
+ extend(field: string, value: string | number | boolean): void;
22
+ };
23
+ addFilter<K extends keyof H & string>(hookName: K, filter: H[K] extends (...args: never[]) => unknown ? H[K] : BeforeSaveFilter): void;
24
+ addAction(...args: never[]): void;
25
+ addContribution(...args: never[]): void;
26
+ }
27
+ export interface DefinedPlugin<H extends HookPoints = HookPoints> {
28
+ readonly definition: {
29
+ setup(sdk: PluginSdk<H>): void | Promise<void>;
30
+ };
31
+ }
32
+ /** Required binding to the host-owned SDK. Hook ids and semantics never default to a product catalog.
33
+ * @example { hookIds: ['beforeSave'], beforeSaveHook: 'beforeSave', hookSemantics: { beforeSave: 'shared' }, ...abi }
34
+ */
35
+ export interface PluginSdkBinding<H extends HookPoints = HookPoints> {
36
+ readonly hookIds: readonly (keyof H & string)[];
37
+ readonly beforeSaveHook: keyof H & string;
38
+ readonly hookSemantics: Readonly<Record<string, ClaimMode>>;
39
+ readonly runtimeSdkVersion: string;
40
+ readonly readDefinedPlugin: (required: {
41
+ moduleValue: unknown;
42
+ }, optional?: Record<string, never>) => DefinedPlugin<H> | null;
43
+ readonly buildSdk: (required: {
44
+ sdk: PluginSdk<H>;
45
+ }, optional?: Record<string, never>) => PluginSdk<H>;
46
+ /** Wraps a worker proxy in the host's definePlugin ABI without evaluating plugin code. */
47
+ readonly definePlugin: (required: DefinedPlugin<H>['definition'], optional?: Record<string, never>) => DefinedPlugin<H>;
48
+ }
49
+ /** The declaration grammar and create/write lifecycle remain host-owned. Opaque fields and plans
50
+ * are carried unchanged; a host adapter binds its concrete content-type contracts. */
51
+ export interface DeclaredContentType {
52
+ readonly key: string;
53
+ readonly label: string;
54
+ readonly fields: readonly unknown[];
55
+ }
56
+ export interface DeclaredContentTypePlan {
57
+ readonly conflicts: readonly string[];
58
+ readonly items: readonly unknown[];
59
+ }
60
+ export interface DeclaredContentTypePorts {
61
+ findByKey(required: {
62
+ workspaceId: string;
63
+ key: string;
64
+ }): Promise<unknown>;
65
+ register(required: {
66
+ workspaceId: string;
67
+ key: string;
68
+ label: string;
69
+ fields: readonly unknown[];
70
+ actorId: string;
71
+ }): Promise<{
72
+ ok: true;
73
+ } | {
74
+ ok: false;
75
+ error: Error;
76
+ }>;
77
+ }
78
+ export interface DeclarativeContentTypesPort {
79
+ validateManifest(required: {
80
+ manifest: Readonly<Record<string, unknown>>;
81
+ }, optional?: Record<string, never>): {
82
+ readonly errors: readonly PluginValidationError[];
83
+ };
84
+ parse(required: {
85
+ value: unknown;
86
+ }, optional?: Record<string, never>): {
87
+ readonly decls: readonly DeclaredContentType[];
88
+ readonly errors: readonly PluginValidationError[];
89
+ };
90
+ plan(required: {
91
+ ports: Pick<DeclaredContentTypePorts, 'findByKey'>;
92
+ workspaceId: string;
93
+ decls: readonly DeclaredContentType[];
94
+ }, optional?: Record<string, never>): Promise<DeclaredContentTypePlan>;
95
+ apply(required: {
96
+ ports: DeclaredContentTypePorts;
97
+ workspaceId: string;
98
+ pluginId: string;
99
+ plan: DeclaredContentTypePlan;
100
+ }, optional?: Record<string, never>): Promise<unknown>;
101
+ }
102
+ export interface ManifestHostPorts<H extends HookPoints = HookPoints> {
103
+ readonly pluginSdkBinding: PluginSdkBinding<H>;
104
+ readonly capabilityVocabulary: readonly string[];
105
+ readonly declarativeContentTypes: DeclarativeContentTypesPort;
106
+ /** Preserves the host's reserved-id diagnostic without embedding a product display name. */
107
+ readonly coreOwnerName: string;
108
+ }
109
+ /** Tier-1 is never executable; tier-2 requires a worker importer; tier-3 requires explicit host allow.
110
+ * Site/install admission errors retain host wording and are supplied by composition. */
111
+ export interface PluginTierPolicy {
112
+ readonly siteErrors: (required: {
113
+ manifestValue: unknown;
114
+ }, optional?: Record<string, never>) => readonly PluginValidationError[];
115
+ readonly checkInstall: (required: {
116
+ manifest: PluginManifest;
117
+ files: ReadonlyMap<string, Uint8Array>;
118
+ }, optional?: Record<string, never>) => void;
119
+ readonly allowLoad: (required: {
120
+ record: PluginDiscoveryRecord;
121
+ manifest: PluginManifest;
122
+ }, optional?: Record<string, never>) => boolean;
123
+ readonly execution: 'in-process' | 'worker';
124
+ }
125
+ /** Byte reader owns archive parsing, zip-slip checks and limits. Never accept an unvalidated ZIP map. */
126
+ export type ArchiveReaderPort = (required: {
127
+ archive: Uint8Array;
128
+ }, optional?: Record<string, never>) => Promise<Map<string, Uint8Array>>;
129
+ /** Host computes the established sha256-hex digest; the ordered loader compares it to the manifest. */
130
+ export type VerifyDigestPort = (required: {
131
+ absoluteFilePath: string;
132
+ }, optional?: Record<string, never>) => Promise<string>;
133
+ /** STRUCTURAL mirrors of Phase 13, packages/agent-plugins/src/lifecycle/{trusted-plugin-files,
134
+ * contribution-loader}.ts. Both packages are L4; the host supplies the existing implementations.
135
+ * These are declarations only: no parallel trust, activation or contribution-loader owner. */
136
+ export interface TrustedPluginPackage {
137
+ readonly pluginId: string;
138
+ readonly packageRoot: string;
139
+ }
140
+ export interface TrustedPluginPackagesQuery {
141
+ readonly workspaceId: string;
142
+ readonly filename: string;
143
+ readonly contribution: string;
144
+ readonly requireActive: boolean;
145
+ readonly orderByPluginId?: boolean | undefined;
146
+ readonly onInactive?: ((required: {
147
+ readonly plugin: TrustedPluginPackage;
148
+ }) => Promise<void>) | undefined;
149
+ }
150
+ export type TrustedPluginVerdict = {
151
+ readonly trusted: TrustedPluginPackage;
152
+ } | {
153
+ readonly refusal: string;
154
+ };
155
+ export type PluginModuleImportPort = (input: {
156
+ readonly plugin: TrustedPluginPackage;
157
+ readonly modulePath: string;
158
+ }) => Promise<{
159
+ readonly exported: unknown;
160
+ } | string>;
161
+ export interface PluginContributionPorts {
162
+ readonly findPackages: (input: TrustedPluginPackagesQuery) => Promise<readonly TrustedPluginVerdict[]>;
163
+ readonly readFile: (input: {
164
+ readonly plugin: TrustedPluginPackage;
165
+ readonly filename: string;
166
+ }) => Promise<string>;
167
+ readonly importModule: PluginModuleImportPort;
168
+ }
169
+ /** Structural host removal port, matching Tovu trash/ports.ts without a CMS dependency edge. */
170
+ export type RemoveEntity = (required: {
171
+ workspaceId: string;
172
+ id: string;
173
+ display: {
174
+ title: string;
175
+ subtitle?: string | null;
176
+ };
177
+ at: string;
178
+ expectedVersion: number | null;
179
+ actor: {
180
+ principalId: string;
181
+ pluginId?: string | null;
182
+ };
183
+ priorMarker?: string | null;
184
+ }) => Promise<{
185
+ ok: true;
186
+ version: number | null;
187
+ } | {
188
+ ok: false;
189
+ reason: 'not-found' | 'version-changed';
190
+ } | {
191
+ ok: false;
192
+ reason: 'blocked';
193
+ code: string;
194
+ count: number;
195
+ }>;
196
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1,19 @@
1
+ import type { Clock as ClockPort } from "@jini-ai/core/primitives";
2
+ import type { PluginActivationRecord, PluginActivationRepoPort } from "./activation.js";
3
+ import type { PluginQuarantineEvent } from "./hook-registry.js";
4
+ export interface QuarantinePluginRequired {
5
+ readonly deps: {
6
+ readonly clock: ClockPort;
7
+ readonly repo: PluginActivationRepoPort;
8
+ };
9
+ readonly input: PluginQuarantineEvent;
10
+ }
11
+ /**
12
+ * Records the recovery action through the existing activation gateway. The hook registry detaches
13
+ * first so later saves recover immediately; this write makes that disabled state survive restart
14
+ * and supplies the operator-facing reason/count.
15
+ */
16
+ export declare function quarantinePlugin(required: QuarantinePluginRequired, _optional?: Record<string, never>): Promise<{
17
+ activation: PluginActivationRecord;
18
+ }>;
19
+ //# sourceMappingURL=quarantine.d.ts.map
@@ -0,0 +1,28 @@
1
+ import { nowIso as clockNowIso } from "@jini-ai/core/primitives";
2
+ /**
3
+ * Records the recovery action through the existing activation gateway. The hook registry detaches
4
+ * first so later saves recover immediately; this write makes that disabled state survive restart
5
+ * and supplies the operator-facing reason/count.
6
+ */
7
+ export async function quarantinePlugin(required, _optional = {}) {
8
+ const { deps, input } = required;
9
+ const existing = await deps.repo.getActivation({
10
+ workspaceId: input.workspaceId,
11
+ pluginId: input.pluginId,
12
+ });
13
+ if (!existing) {
14
+ throw new Error(`cannot quarantine plugin '${input.pluginId}' without an activation record`);
15
+ }
16
+ const quarantinedAt = clockNowIso({ clock: deps.clock });
17
+ const activation = {
18
+ ...existing,
19
+ enabled: false,
20
+ updatedAt: quarantinedAt,
21
+ quarantinedAt,
22
+ quarantineReason: input.reason,
23
+ quarantineFailureCount: input.consecutiveFailures,
24
+ };
25
+ await deps.repo.save(activation);
26
+ return { activation };
27
+ }
28
+ //# sourceMappingURL=quarantine.js.map
@@ -0,0 +1,27 @@
1
+ import type { PluginActivationRecord, PluginActivationRepoPort } from "./activation.js";
2
+ /**
3
+ * @file In-memory `PluginActivationRepoPort` adapter — mirrors
4
+ * `src/features/presentation/repo.memory.ts`'s shape exactly (rule-of-two, day one).
5
+ *
6
+ * Architectural role:
7
+ * TDD-certified adapter (implementation outline C-013). Implements get/upsert/delete/list over an
8
+ * in-memory row set and satisfies `__tests__/integration/repo.contract.test.ts`, the shared suite
9
+ * this adapter and `repo.sqlite.ts` run identically.
10
+ */
11
+ export declare class InMemoryPluginActivationRepo implements PluginActivationRepoPort {
12
+ private rows;
13
+ constructor({ initialRows }?: {
14
+ initialRows?: PluginActivationRecord[];
15
+ }, _optional?: Record<string, never>);
16
+ getActivation(required: {
17
+ workspaceId: string;
18
+ pluginId: string;
19
+ }, _optional?: Record<string, never>): Promise<PluginActivationRecord | null>;
20
+ save(record: PluginActivationRecord, _optional?: Record<string, never>): Promise<void>;
21
+ deleteActivation(required: {
22
+ workspaceId: string;
23
+ pluginId: string;
24
+ }, _optional?: Record<string, never>): Promise<void>;
25
+ listAll(_required?: Record<string, never>, _optional?: Record<string, never>): Promise<PluginActivationRecord[]>;
26
+ }
27
+ //# sourceMappingURL=repo.memory.d.ts.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @file In-memory `PluginActivationRepoPort` adapter — mirrors
3
+ * `src/features/presentation/repo.memory.ts`'s shape exactly (rule-of-two, day one).
4
+ *
5
+ * Architectural role:
6
+ * TDD-certified adapter (implementation outline C-013). Implements get/upsert/delete/list over an
7
+ * in-memory row set and satisfies `__tests__/integration/repo.contract.test.ts`, the shared suite
8
+ * this adapter and `repo.sqlite.ts` run identically.
9
+ */
10
+ export class InMemoryPluginActivationRepo {
11
+ rows;
12
+ constructor({ initialRows = [] } = {}, _optional = {}) {
13
+ this.rows = [...initialRows];
14
+ }
15
+ async getActivation(required, _optional = {}) {
16
+ return (this.rows.find((row) => row.workspaceId === required.workspaceId && row.pluginId === required.pluginId) ?? null);
17
+ }
18
+ async save(record, _optional = {}) {
19
+ const index = this.rows.findIndex((row) => row.workspaceId === record.workspaceId && row.pluginId === record.pluginId);
20
+ if (index === -1) {
21
+ this.rows.push(record);
22
+ return;
23
+ }
24
+ this.rows[index] = record;
25
+ }
26
+ async deleteActivation(required, _optional = {}) {
27
+ this.rows = this.rows.filter((row) => row.workspaceId !== required.workspaceId || row.pluginId !== required.pluginId);
28
+ }
29
+ async listAll(_required = {}, _optional = {}) {
30
+ return [...this.rows];
31
+ }
32
+ }
33
+ //# sourceMappingURL=repo.memory.js.map
@@ -0,0 +1,4 @@
1
+ /** Optional StorageKernel adapter; callers supply their activation table. */
2
+ export * from './repo.js';
3
+ export * from './repo.rows.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ /** Optional StorageKernel adapter; callers supply their activation table. */
2
+ export * from './repo.js';
3
+ export * from './repo.rows.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,38 @@
1
+ import type { StorageKernel } from "@jini-ai/db/kernel";
2
+ import type { PluginActivationTable } from "./repo.rows.js";
3
+ export interface PluginActivationDatabase {
4
+ [table: string]: PluginActivationTable;
5
+ }
6
+ export interface PluginActivationSqlRequired {
7
+ readonly kernel: StorageKernel<PluginActivationDatabase>;
8
+ readonly tables: {
9
+ readonly activations: string;
10
+ };
11
+ }
12
+ import type { PluginActivationRecord, PluginActivationRepoPort } from "../activation.js";
13
+ /**
14
+ * @file THE `PluginActivationRepoPort` adapter: one Kysely query body for every database the
15
+ * storage kernel drives (SQLite, PGlite, Postgres). One row per (workspace, plugin); `save` upserts
16
+ * on that key. Every statement goes through `kernel.run` and is awaited. Satisfies
17
+ * `__tests__/integration/repo.contract.test.ts`, the suite `repo.memory.ts` runs identically.
18
+ */
19
+ export declare class SqlPluginActivationRepo implements PluginActivationRepoPort {
20
+ protected readonly kernel: StorageKernel<PluginActivationDatabase>;
21
+ protected readonly tables: {
22
+ readonly activations: string;
23
+ };
24
+ constructor(required: PluginActivationSqlRequired, _optional?: Record<string, never>);
25
+ getActivation(required: {
26
+ workspaceId: string;
27
+ pluginId: string;
28
+ }, _optional?: Record<string, never>): Promise<PluginActivationRecord | null>;
29
+ save(record: PluginActivationRecord, _optional?: Record<string, never>): Promise<void>;
30
+ deleteActivation(required: {
31
+ workspaceId: string;
32
+ pluginId: string;
33
+ }, _optional?: Record<string, never>): Promise<void>;
34
+ listAll(_required?: Record<string, never>, _optional?: Record<string, never>): Promise<PluginActivationRecord[]>;
35
+ }
36
+ /** The plugin-activation repo for `kernel`. */
37
+ export declare function pluginActivationRepoFor(required: PluginActivationSqlRequired, _optional?: Record<string, never>): SqlPluginActivationRepo;
38
+ //# sourceMappingURL=repo.d.ts.map
@@ -0,0 +1,50 @@
1
+ import { toActivationRecord, toActivationRow } from "./repo.rows.js";
2
+ /**
3
+ * @file THE `PluginActivationRepoPort` adapter: one Kysely query body for every database the
4
+ * storage kernel drives (SQLite, PGlite, Postgres). One row per (workspace, plugin); `save` upserts
5
+ * on that key. Every statement goes through `kernel.run` and is awaited. Satisfies
6
+ * `__tests__/integration/repo.contract.test.ts`, the suite `repo.memory.ts` runs identically.
7
+ */
8
+ export class SqlPluginActivationRepo {
9
+ kernel;
10
+ tables;
11
+ constructor(required, _optional = {}) {
12
+ this.kernel = required.kernel;
13
+ this.tables = required.tables;
14
+ }
15
+ async getActivation(required, _optional = {}) {
16
+ const row = await this.kernel.run((db) => db
17
+ .selectFrom(this.tables.activations)
18
+ .selectAll()
19
+ .where("workspace_id", "=", required.workspaceId)
20
+ .where("plugin_id", "=", required.pluginId)
21
+ .limit(1)
22
+ .executeTakeFirst());
23
+ return row ? toActivationRecord({ row }) : null;
24
+ }
25
+ async save(record, _optional = {}) {
26
+ const row = toActivationRow({ record });
27
+ const { workspace_id: _workspaceId, plugin_id: _pluginId, ...set } = row;
28
+ await this.kernel.run((db) => db
29
+ .insertInto(this.tables.activations)
30
+ .values(row)
31
+ .onConflict((oc) => oc.columns(["workspace_id", "plugin_id"]).doUpdateSet(set))
32
+ .execute());
33
+ }
34
+ async deleteActivation(required, _optional = {}) {
35
+ await this.kernel.run((db) => db
36
+ .deleteFrom(this.tables.activations)
37
+ .where("workspace_id", "=", required.workspaceId)
38
+ .where("plugin_id", "=", required.pluginId)
39
+ .execute());
40
+ }
41
+ async listAll(_required = {}, _optional = {}) {
42
+ const rows = await this.kernel.run((db) => db.selectFrom(this.tables.activations).selectAll().execute());
43
+ return rows.map((row) => toActivationRecord({ row }));
44
+ }
45
+ }
46
+ /** The plugin-activation repo for `kernel`. */
47
+ export function pluginActivationRepoFor(required, _optional = {}) {
48
+ return new SqlPluginActivationRepo(required);
49
+ }
50
+ //# sourceMappingURL=repo.js.map
@@ -0,0 +1,28 @@
1
+ import type { Insertable, Selectable } from "kysely";
2
+ /** Storage columns are the existing plugin_activations wire schema; no generated product DTO. */
3
+ export interface PluginActivationTable {
4
+ workspace_id: string;
5
+ plugin_id: string;
6
+ version: string;
7
+ enabled: boolean | number;
8
+ updated_at: string;
9
+ quarantined_at: string | null;
10
+ quarantine_reason: string | null;
11
+ quarantine_failure_count: number | null;
12
+ }
13
+ import type { PluginActivationRecord } from "../activation.js";
14
+ /**
15
+ * @file Row mapping for `plugin_activations`, shared by every dialect (the generated
16
+ * `ContentDatabase` snake_case columns; `enabled` is a boolean read through `toBool`). Neutral on
17
+ * purpose — no repo, no driver.
18
+ */
19
+ export type PluginActivationRow = Selectable<PluginActivationTable>;
20
+ /** One `plugin_activations` row as a {@link PluginActivationRecord}; NULL quarantine columns are omitted. */
21
+ export declare function toActivationRecord({ row }: {
22
+ row: PluginActivationRow;
23
+ }, _optional?: Record<string, never>): PluginActivationRecord;
24
+ /** The `plugin_activations` row `save` upserts; absent quarantine fields are written as NULL. */
25
+ export declare function toActivationRow({ record }: {
26
+ record: PluginActivationRecord;
27
+ }, _optional?: Record<string, never>): Insertable<PluginActivationTable>;
28
+ //# sourceMappingURL=repo.rows.d.ts.map
@@ -0,0 +1,28 @@
1
+ import { toBool } from "@jini-ai/db/kernel";
2
+ /** One `plugin_activations` row as a {@link PluginActivationRecord}; NULL quarantine columns are omitted. */
3
+ export function toActivationRecord({ row }, _optional = {}) {
4
+ return {
5
+ pluginId: row.plugin_id,
6
+ workspaceId: row.workspace_id,
7
+ version: row.version,
8
+ enabled: toBool(row.enabled) === true,
9
+ updatedAt: row.updated_at,
10
+ ...(row.quarantined_at === null ? {} : { quarantinedAt: row.quarantined_at }),
11
+ ...(row.quarantine_reason === null ? {} : { quarantineReason: row.quarantine_reason }),
12
+ ...(row.quarantine_failure_count === null ? {} : { quarantineFailureCount: row.quarantine_failure_count }),
13
+ };
14
+ }
15
+ /** The `plugin_activations` row `save` upserts; absent quarantine fields are written as NULL. */
16
+ export function toActivationRow({ record }, _optional = {}) {
17
+ return {
18
+ workspace_id: record.workspaceId,
19
+ plugin_id: record.pluginId,
20
+ version: record.version,
21
+ enabled: record.enabled,
22
+ updated_at: record.updatedAt,
23
+ quarantined_at: record.quarantinedAt ?? null,
24
+ quarantine_reason: record.quarantineReason ?? null,
25
+ quarantine_failure_count: record.quarantineFailureCount ?? null,
26
+ };
27
+ }
28
+ //# sourceMappingURL=repo.rows.js.map
@@ -0,0 +1,88 @@
1
+ import type { PluginActivationRepoPort } from "./activation.js";
2
+ import type { PluginDiscoveryRecord } from "./discovery-types.js";
3
+ import type { RemoveEntity } from "./ports.js";
4
+ /** A built-in plugin has no on-disk artifact — there is nothing for `DELETE .../plugins/:id` to
5
+ * remove. Distinct from `PluginNotFoundError` (id doesn't exist at all) so the route can map each
6
+ * to its own status code (mirrors `PluginInvalidError`/`PluginIncompatibleError` both being
7
+ * distinct from `PluginNotFoundError` in `activation.ts`). */
8
+ export declare class PluginNotUninstallableError extends Error {
9
+ }
10
+ /** The plugin is currently enabled in at least one workspace. Since the on-disk artifact is
11
+ * instance-wide (shared across every workspace this `installDir` serves), uninstalling while ANY
12
+ * workspace still has it enabled would silently break that workspace's runtime. */
13
+ export declare class PluginEnabledError extends Error {
14
+ }
15
+ /** The plugin a human confirmed uninstalling is no longer the name and version discovery reports — see
16
+ * `UninstallPluginOptional.confirmedPreview`. Nothing was removed. */
17
+ export declare class PluginChangedSincePreviewError extends Error {
18
+ }
19
+ export declare class PluginAlreadyInTrashError extends Error {
20
+ }
21
+ export type RemovePluginFn = RemoveEntity;
22
+ export interface UninstallPluginDeps {
23
+ readonly repo: PluginActivationRepoPort;
24
+ /** Caller-supplied fresh discovery snapshot — same convention as `SetPluginEnabledDeps.discovery`
25
+ * (`activation.ts`): this function evaluates preconditions over an already-known snapshot rather
26
+ * than calling discovery itself, so it stays deterministic and testable without a real
27
+ * filesystem scan. */
28
+ readonly discovery: readonly PluginDiscoveryRecord[];
29
+ readonly remove: RemovePluginFn;
30
+ }
31
+ export interface UninstallPluginInput {
32
+ readonly pluginId: string;
33
+ readonly workspaceId: string;
34
+ readonly at: string;
35
+ readonly actor: {
36
+ principalId: string;
37
+ pluginId?: string | null;
38
+ };
39
+ }
40
+ export interface UninstallPluginRequired {
41
+ deps: UninstallPluginDeps;
42
+ input: UninstallPluginInput;
43
+ }
44
+ export interface UninstallPluginOptional {
45
+ /** The preview a human confirmed. When given, the uninstall refuses before `remove` (so nothing is removed)
46
+ * unless the record it resolves still has the previewed name and version (t91 F2.2). The admin HTTP route has no
47
+ * gap between showing and removing, and omits it. */
48
+ readonly confirmedPreview?: PluginUninstallPreview;
49
+ }
50
+ export interface UninstallPluginResult {
51
+ readonly trashed: true;
52
+ }
53
+ /** What a human confirmation dialog needs to describe truthfully what is about to be removed.
54
+ * Mirrors `agent-plugins/uninstall.ts`'s own `AgentPluginUninstallPreview` for the sibling family,
55
+ * for the identical reason: the preview carries no host path, only the fields a dialog may say out
56
+ * loud. */
57
+ export interface PluginUninstallPreview {
58
+ readonly pluginId: string;
59
+ readonly name: string;
60
+ readonly version: string;
61
+ }
62
+ /**
63
+ * Evaluates `uninstallPlugin()`'s preconditions and returns what a confirmation dialog needs to name
64
+ * — performing no mutation, so a caller can raise that dialog only once the target is known-good.
65
+ *
66
+ * @throws {PluginNotFoundError} `required.input.pluginId` is absent from `deps.discovery`.
67
+ * @throws {PluginNotUninstallableError} the discovered record's `source` is `"built-in"`.
68
+ * @throws {PluginEnabledError} the plugin is enabled in one or more workspaces.
69
+ * @complexity O(activation rows for this plugin) — delegates to `resolveUninstallTarget`.
70
+ */
71
+ export declare function previewUninstallPlugin(required: UninstallPluginRequired, _optional?: Record<string, never>): Promise<PluginUninstallPreview>;
72
+ /**
73
+ * Moves a site-installed plugin to Trash. Activation rows stay in place until permanent purge.
74
+ *
75
+ * @throws {PluginNotFoundError} `input.pluginId` is absent from `deps.discovery`.
76
+ * @throws {PluginNotUninstallableError} the discovered record's `source` is `"built-in"`.
77
+ * @throws {PluginEnabledError} the plugin is enabled in one or more workspaces.
78
+ * @throws {PluginChangedSincePreviewError} `optional.confirmedPreview` was given and the record's name or version differs from it.
79
+ * @complexity O(activation rows for this plugin) plus one delegated remove.
80
+ */
81
+ export declare function uninstallPlugin(required: UninstallPluginRequired, optional?: UninstallPluginOptional): Promise<UninstallPluginResult>;
82
+ export declare function forgetPluginActivations(required: {
83
+ pluginId: string;
84
+ deps: {
85
+ repo: PluginActivationRepoPort;
86
+ };
87
+ }, _optional?: Record<string, never>): Promise<void>;
88
+ //# sourceMappingURL=uninstall.d.ts.map