@jini-ai/plugins 0.0.0-stage → 0.4.1
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 +27 -0
- package/LICENSE +201 -0
- package/README.md +60 -2
- package/dist/glue/attachment-points/content-lifecycle.d.ts +52 -0
- package/dist/glue/attachment-points/content-lifecycle.js +15 -0
- package/dist/glue/attachment-points/events.d.ts +12 -0
- package/dist/glue/attachment-points/events.js +5 -0
- package/dist/glue/attachment-points/tool-registration.d.ts +23 -0
- package/dist/glue/attachment-points/tool-registration.js +43 -0
- package/dist/glue/capability-gate.d.ts +73 -0
- package/dist/glue/capability-gate.js +41 -0
- package/dist/glue/dispatch.d.ts +20 -0
- package/dist/glue/dispatch.js +9 -0
- package/dist/glue/index.d.ts +8 -0
- package/dist/glue/index.js +8 -0
- package/dist/glue/manifest.d.ts +43 -0
- package/dist/glue/manifest.js +106 -0
- package/dist/glue/ports.d.ts +60 -0
- package/dist/glue/ports.js +2 -0
- package/dist/host/activation.d.ts +118 -0
- package/dist/host/activation.js +104 -0
- package/dist/host/attach-loaded-plugin.d.ts +37 -0
- package/dist/host/attach-loaded-plugin.js +19 -0
- package/dist/host/capability-sdk.d.ts +74 -0
- package/dist/host/capability-sdk.js +94 -0
- package/dist/host/claim-conflicts.d.ts +101 -0
- package/dist/host/claim-conflicts.js +139 -0
- package/dist/host/contributions.d.ts +129 -0
- package/dist/host/contributions.js +167 -0
- package/dist/host/declarative-enable.d.ts +43 -0
- package/dist/host/declarative-enable.js +73 -0
- package/dist/host/discovery-types.d.ts +55 -0
- package/dist/host/discovery-types.js +2 -0
- package/dist/host/errors.d.ts +20 -0
- package/dist/host/errors.js +22 -0
- package/dist/host/hook-registry.d.ts +113 -0
- package/dist/host/hook-registry.js +190 -0
- package/dist/host/index.d.ts +19 -0
- package/dist/host/index.js +19 -0
- package/dist/host/manifest.d.ts +159 -0
- package/dist/host/manifest.js +417 -0
- package/dist/host/node/discovery.d.ts +32 -0
- package/dist/host/node/discovery.js +241 -0
- package/dist/host/node/index.d.ts +8 -0
- package/dist/host/node/index.js +8 -0
- package/dist/host/node/install.d.ts +118 -0
- package/dist/host/node/install.js +431 -0
- package/dist/host/node/loader.d.ts +55 -0
- package/dist/host/node/loader.js +146 -0
- package/dist/host/node/module-snapshot.d.ts +25 -0
- package/dist/host/node/module-snapshot.js +53 -0
- package/dist/host/node/package-files.d.ts +52 -0
- package/dist/host/node/package-files.js +214 -0
- package/dist/host/node/source-drafts.d.ts +98 -0
- package/dist/host/node/source-drafts.js +323 -0
- package/dist/host/plugin-claims.d.ts +75 -0
- package/dist/host/plugin-claims.js +182 -0
- package/dist/host/ports.d.ts +208 -0
- package/dist/host/ports.js +2 -0
- package/dist/host/quarantine.d.ts +19 -0
- package/dist/host/quarantine.js +28 -0
- package/dist/host/repo.memory.d.ts +27 -0
- package/dist/host/repo.memory.js +33 -0
- package/dist/host/source-policy.d.ts +18 -0
- package/dist/host/source-policy.js +13 -0
- package/dist/host/sql/index.d.ts +4 -0
- package/dist/host/sql/index.js +4 -0
- package/dist/host/sql/repo.d.ts +38 -0
- package/dist/host/sql/repo.js +50 -0
- package/dist/host/sql/repo.rows.d.ts +28 -0
- package/dist/host/sql/repo.rows.js +28 -0
- package/dist/host/tool-contributions.d.ts +26 -0
- package/dist/host/tool-contributions.js +42 -0
- package/dist/host/uninstall.d.ts +88 -0
- package/dist/host/uninstall.js +112 -0
- package/dist/host/worker/import-seam.d.ts +45 -0
- package/dist/host/worker/import-seam.js +52 -0
- package/dist/host/worker/index.d.ts +5 -0
- package/dist/host/worker/index.js +5 -0
- package/dist/host/worker/protocol.d.ts +62 -0
- package/dist/host/worker/protocol.js +31 -0
- package/dist/host/worker/run-call.d.ts +27 -0
- package/dist/host/worker/run-call.js +76 -0
- package/package.json +107 -3
|
@@ -0,0 +1,208 @@
|
|
|
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 plugins?: import("@jini-ai/core/plugin-directory").PluginLookupPort;
|
|
20
|
+
readonly content: {
|
|
21
|
+
read(): Readonly<ContentEntryDraft>;
|
|
22
|
+
extend(field: string, value: string | number | boolean): void;
|
|
23
|
+
};
|
|
24
|
+
addFilter<K extends keyof H & string>(hookName: K, filter: H[K] extends (...args: never[]) => unknown ? H[K] : BeforeSaveFilter): void;
|
|
25
|
+
readonly routes: {
|
|
26
|
+
add(required: import('./contributions.js').PluginRouteContribution, optional?: Record<string, never>): void;
|
|
27
|
+
};
|
|
28
|
+
readonly tools: {
|
|
29
|
+
add(required: import('./contributions.js').PluginToolContribution, optional?: Record<string, never>): void;
|
|
30
|
+
};
|
|
31
|
+
readonly widgets: {
|
|
32
|
+
add(required: import('./contributions.js').PluginWidgetContribution, optional?: Record<string, never>): void;
|
|
33
|
+
};
|
|
34
|
+
addAction(...args: never[]): void;
|
|
35
|
+
addContribution(required: import('./contributions.js').PluginContribution, optional?: Record<string, never>): void;
|
|
36
|
+
}
|
|
37
|
+
export interface DefinedPlugin<H extends HookPoints = HookPoints> {
|
|
38
|
+
readonly definition: {
|
|
39
|
+
setup(sdk: PluginSdk<H>): void | Promise<void>;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Required binding to the host-owned SDK. Hook ids and semantics never default to a product catalog.
|
|
43
|
+
* @example { hookIds: ['beforeSave'], beforeSaveHook: 'beforeSave', hookSemantics: { beforeSave: 'shared' }, ...abi }
|
|
44
|
+
*/
|
|
45
|
+
export interface PluginSdkBinding<H extends HookPoints = HookPoints> {
|
|
46
|
+
readonly hookIds: readonly (keyof H & string)[];
|
|
47
|
+
readonly beforeSaveHook: keyof H & string;
|
|
48
|
+
readonly hookSemantics: Readonly<Record<string, ClaimMode>>;
|
|
49
|
+
readonly runtimeSdkVersion: string;
|
|
50
|
+
readonly readDefinedPlugin: (required: {
|
|
51
|
+
moduleValue: unknown;
|
|
52
|
+
}, optional?: Record<string, never>) => DefinedPlugin<H> | null;
|
|
53
|
+
readonly buildSdk: (required: {
|
|
54
|
+
sdk: PluginSdk<H>;
|
|
55
|
+
}, optional?: Record<string, never>) => PluginSdk<H>;
|
|
56
|
+
/** Wraps a worker proxy in the host's definePlugin ABI without evaluating plugin code. */
|
|
57
|
+
readonly definePlugin: (required: DefinedPlugin<H>['definition'], optional?: Record<string, never>) => DefinedPlugin<H>;
|
|
58
|
+
}
|
|
59
|
+
/** The declaration grammar and create/write lifecycle remain host-owned. Opaque fields and plans
|
|
60
|
+
* are carried unchanged; a host adapter binds its concrete content-type contracts. */
|
|
61
|
+
export interface DeclaredContentType {
|
|
62
|
+
readonly key: string;
|
|
63
|
+
readonly label: string;
|
|
64
|
+
readonly fields: readonly unknown[];
|
|
65
|
+
}
|
|
66
|
+
export interface DeclaredContentTypePlan {
|
|
67
|
+
readonly conflicts: readonly string[];
|
|
68
|
+
readonly items: readonly unknown[];
|
|
69
|
+
}
|
|
70
|
+
export interface DeclaredContentTypePorts {
|
|
71
|
+
findByKey(required: {
|
|
72
|
+
workspaceId: string;
|
|
73
|
+
key: string;
|
|
74
|
+
}): Promise<unknown>;
|
|
75
|
+
register(required: {
|
|
76
|
+
workspaceId: string;
|
|
77
|
+
key: string;
|
|
78
|
+
label: string;
|
|
79
|
+
fields: readonly unknown[];
|
|
80
|
+
actorId: string;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
ok: true;
|
|
83
|
+
} | {
|
|
84
|
+
ok: false;
|
|
85
|
+
error: Error;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
export interface DeclarativeContentTypesPort {
|
|
89
|
+
validateManifest(required: {
|
|
90
|
+
manifest: Readonly<Record<string, unknown>>;
|
|
91
|
+
}, optional?: Record<string, never>): {
|
|
92
|
+
readonly errors: readonly PluginValidationError[];
|
|
93
|
+
};
|
|
94
|
+
parse(required: {
|
|
95
|
+
value: unknown;
|
|
96
|
+
}, optional?: Record<string, never>): {
|
|
97
|
+
readonly decls: readonly DeclaredContentType[];
|
|
98
|
+
readonly errors: readonly PluginValidationError[];
|
|
99
|
+
};
|
|
100
|
+
plan(required: {
|
|
101
|
+
ports: Pick<DeclaredContentTypePorts, 'findByKey'>;
|
|
102
|
+
workspaceId: string;
|
|
103
|
+
decls: readonly DeclaredContentType[];
|
|
104
|
+
}, optional?: Record<string, never>): Promise<DeclaredContentTypePlan>;
|
|
105
|
+
apply(required: {
|
|
106
|
+
ports: DeclaredContentTypePorts;
|
|
107
|
+
workspaceId: string;
|
|
108
|
+
pluginId: string;
|
|
109
|
+
plan: DeclaredContentTypePlan;
|
|
110
|
+
}, optional?: Record<string, never>): Promise<unknown>;
|
|
111
|
+
}
|
|
112
|
+
export interface ManifestHostPorts<H extends HookPoints = HookPoints> {
|
|
113
|
+
/** Namespace containing publisher id/provides; default retains the existing site contract. */
|
|
114
|
+
readonly identityNamespace?: string;
|
|
115
|
+
readonly pluginSdkBinding: PluginSdkBinding<H>;
|
|
116
|
+
readonly capabilityVocabulary: readonly string[];
|
|
117
|
+
readonly declarativeContentTypes: DeclarativeContentTypesPort;
|
|
118
|
+
/** Preserves the host's reserved-id diagnostic without embedding a product display name. */
|
|
119
|
+
readonly coreOwnerName: string;
|
|
120
|
+
}
|
|
121
|
+
/** Tier-1 is never executable; tier-2 requires a worker importer; tier-3 requires explicit host allow.
|
|
122
|
+
* Site/install admission errors retain host wording and are supplied by composition. */
|
|
123
|
+
export interface PluginTierPolicy {
|
|
124
|
+
readonly siteErrors: (required: {
|
|
125
|
+
manifestValue: unknown;
|
|
126
|
+
}, optional?: Record<string, never>) => readonly PluginValidationError[];
|
|
127
|
+
readonly checkInstall: (required: {
|
|
128
|
+
manifest: PluginManifest;
|
|
129
|
+
files: ReadonlyMap<string, Uint8Array>;
|
|
130
|
+
}, optional?: Record<string, never>) => void;
|
|
131
|
+
readonly allowLoad: (required: {
|
|
132
|
+
record: PluginDiscoveryRecord;
|
|
133
|
+
manifest: PluginManifest;
|
|
134
|
+
}, optional?: Record<string, never>) => boolean;
|
|
135
|
+
readonly execution: 'in-process' | 'worker';
|
|
136
|
+
}
|
|
137
|
+
/** Byte reader owns archive parsing, zip-slip checks and limits. Never accept an unvalidated ZIP map. */
|
|
138
|
+
export type ArchiveReaderPort = (required: {
|
|
139
|
+
archive: Uint8Array;
|
|
140
|
+
}, optional?: Record<string, never>) => Promise<Map<string, Uint8Array>>;
|
|
141
|
+
/** Host computes the established sha256-hex digest; the ordered loader compares it to the manifest. */
|
|
142
|
+
export type VerifyDigestPort = (required: {
|
|
143
|
+
absoluteFilePath: string;
|
|
144
|
+
}, optional?: Record<string, never>) => Promise<string>;
|
|
145
|
+
/** STRUCTURAL mirrors of Phase 13, packages/agent-plugins/src/lifecycle/{trusted-plugin-files,
|
|
146
|
+
* contribution-loader}.ts. Both packages are L4; the host supplies the existing implementations.
|
|
147
|
+
* These are declarations only: no parallel trust, activation or contribution-loader owner. */
|
|
148
|
+
export interface TrustedPluginPackage {
|
|
149
|
+
readonly pluginId: string;
|
|
150
|
+
readonly packageRoot: string;
|
|
151
|
+
}
|
|
152
|
+
export interface TrustedPluginPackagesQuery {
|
|
153
|
+
readonly workspaceId: string;
|
|
154
|
+
readonly filename: string;
|
|
155
|
+
readonly contribution: string;
|
|
156
|
+
readonly requireActive: boolean;
|
|
157
|
+
readonly orderByPluginId?: boolean | undefined;
|
|
158
|
+
readonly onInactive?: ((required: {
|
|
159
|
+
readonly plugin: TrustedPluginPackage;
|
|
160
|
+
}) => Promise<void>) | undefined;
|
|
161
|
+
}
|
|
162
|
+
export type TrustedPluginVerdict = {
|
|
163
|
+
readonly trusted: TrustedPluginPackage;
|
|
164
|
+
} | {
|
|
165
|
+
readonly refusal: string;
|
|
166
|
+
};
|
|
167
|
+
export type PluginModuleImportPort = (input: {
|
|
168
|
+
readonly plugin: TrustedPluginPackage;
|
|
169
|
+
readonly modulePath: string;
|
|
170
|
+
}) => Promise<{
|
|
171
|
+
readonly exported: unknown;
|
|
172
|
+
} | string>;
|
|
173
|
+
export interface PluginContributionPorts {
|
|
174
|
+
readonly findPackages: (input: TrustedPluginPackagesQuery) => Promise<readonly TrustedPluginVerdict[]>;
|
|
175
|
+
readonly readFile: (input: {
|
|
176
|
+
readonly plugin: TrustedPluginPackage;
|
|
177
|
+
readonly filename: string;
|
|
178
|
+
}) => Promise<string>;
|
|
179
|
+
readonly importModule: PluginModuleImportPort;
|
|
180
|
+
}
|
|
181
|
+
/** Structural host removal port, matching Tovu trash/ports.ts without a CMS dependency edge. */
|
|
182
|
+
export type RemoveEntity = (required: {
|
|
183
|
+
workspaceId: string;
|
|
184
|
+
id: string;
|
|
185
|
+
display: {
|
|
186
|
+
title: string;
|
|
187
|
+
subtitle?: string | null;
|
|
188
|
+
};
|
|
189
|
+
at: string;
|
|
190
|
+
expectedVersion: number | null;
|
|
191
|
+
actor: {
|
|
192
|
+
principalId: string;
|
|
193
|
+
pluginId?: string | null;
|
|
194
|
+
};
|
|
195
|
+
priorMarker?: string | null;
|
|
196
|
+
}) => Promise<{
|
|
197
|
+
ok: true;
|
|
198
|
+
version: number | null;
|
|
199
|
+
} | {
|
|
200
|
+
ok: false;
|
|
201
|
+
reason: 'not-found' | 'version-changed';
|
|
202
|
+
} | {
|
|
203
|
+
ok: false;
|
|
204
|
+
reason: 'blocked';
|
|
205
|
+
code: string;
|
|
206
|
+
count: number;
|
|
207
|
+
}>;
|
|
208
|
+
//# sourceMappingURL=ports.d.ts.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,18 @@
|
|
|
1
|
+
/** Host-injected deployment policy. Environment interpretation belongs to composition adapters. */
|
|
2
|
+
export interface PluginSourcePolicyPort {
|
|
3
|
+
localInstallEnabled(required?: Record<string, never>, optional?: Record<string, never>): boolean;
|
|
4
|
+
confirmEnable(required: {
|
|
5
|
+
sealedHere: boolean;
|
|
6
|
+
}, optional?: Record<string, never>): boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Local authoring runs directly; hosted sideloading retains the host's explicit opt-in.
|
|
9
|
+
* @param required Deployment facts supplied by the host.
|
|
10
|
+
* @param _optional Reserved factory options.
|
|
11
|
+
* @returns The shared install/enable policy, with no environment reads.
|
|
12
|
+
* @example createPluginSourcePolicy({ hosted: false, localInstallOptIn: false }, {})
|
|
13
|
+
*/
|
|
14
|
+
export declare function createPluginSourcePolicy(required: {
|
|
15
|
+
hosted: boolean;
|
|
16
|
+
localInstallOptIn: boolean;
|
|
17
|
+
}, _optional?: {}): PluginSourcePolicyPort;
|
|
18
|
+
//# sourceMappingURL=source-policy.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Local authoring runs directly; hosted sideloading retains the host's explicit opt-in.
|
|
2
|
+
* @param required Deployment facts supplied by the host.
|
|
3
|
+
* @param _optional Reserved factory options.
|
|
4
|
+
* @returns The shared install/enable policy, with no environment reads.
|
|
5
|
+
* @example createPluginSourcePolicy({ hosted: false, localInstallOptIn: false }, {})
|
|
6
|
+
*/
|
|
7
|
+
export function createPluginSourcePolicy(required, _optional = {}) {
|
|
8
|
+
return {
|
|
9
|
+
localInstallEnabled: (_required = {}, _optional = {}) => !required.hosted || required.localInstallOptIn,
|
|
10
|
+
confirmEnable: ({ sealedHere }, _optional = {}) => !sealedHere,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=source-policy.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,26 @@
|
|
|
1
|
+
/** Projects executable plugins onto the host's existing ToolRegistry. Metadata/auth are host
|
|
2
|
+
* ports; no separate catalog, executor, permission vocabulary, or approval engine is created. */
|
|
3
|
+
import { type ToolRegistry, type ToolRegistration, type ToolMetadata } from '@jini-ai/core';
|
|
4
|
+
import { type PluginContributionRegistry, type PluginAuthContext } from './contributions.js';
|
|
5
|
+
export interface PluginToolContributionPorts {
|
|
6
|
+
readonly contributions: PluginContributionRegistry;
|
|
7
|
+
readonly isEnabled: (required: {
|
|
8
|
+
pluginId: string;
|
|
9
|
+
}, optional?: Record<string, never>) => Promise<boolean>;
|
|
10
|
+
readonly resolveAuth: (required: {
|
|
11
|
+
pluginId: string;
|
|
12
|
+
principalId: string;
|
|
13
|
+
}, optional?: Record<string, never>) => Promise<PluginAuthContext | null>;
|
|
14
|
+
readonly metadata: ToolMetadata;
|
|
15
|
+
}
|
|
16
|
+
/** Generation + durable activation are checked before authorization and after confirmation.
|
|
17
|
+
* Arbitrary tier-3 handlers cannot establish read-only safety; the host supplies approval policy. */
|
|
18
|
+
export declare function buildPluginContributionToolRegistrations(required: PluginToolContributionPorts, _optional?: Record<string, never>): ToolRegistration[];
|
|
19
|
+
/** Host lifecycle attaches one revocable scope to its existing registry. Disposal removes only
|
|
20
|
+
* this scope's tools and subscription. A failed replacement leaves the previous generation. */
|
|
21
|
+
export declare function attachPluginContributionTools(required: PluginToolContributionPorts & {
|
|
22
|
+
registry: ToolRegistry;
|
|
23
|
+
}, _optional?: Record<string, never>): {
|
|
24
|
+
dispose(_required: Record<string, never>, _optional?: Record<string, never>): void;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=tool-contributions.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Projects executable plugins onto the host's existing ToolRegistry. Metadata/auth are host
|
|
2
|
+
* ports; no separate catalog, executor, permission vocabulary, or approval engine is created. */
|
|
3
|
+
import { createToolRegistrationScope, requireInputRecord, ToolInputError } from '@jini-ai/core';
|
|
4
|
+
import { pluginToolIdFor } from './contributions.js';
|
|
5
|
+
/** Generation + durable activation are checked before authorization and after confirmation.
|
|
6
|
+
* Arbitrary tier-3 handlers cannot establish read-only safety; the host supplies approval policy. */
|
|
7
|
+
export function buildPluginContributionToolRegistrations(required, _optional = {}) {
|
|
8
|
+
const { contributions } = required;
|
|
9
|
+
return contributions.list({}).flatMap(snapshot => snapshot.tools.map(tool => {
|
|
10
|
+
const active = async () => await required.isEnabled({ pluginId: snapshot.pluginId }) && contributions.list({}).includes(snapshot);
|
|
11
|
+
return {
|
|
12
|
+
descriptor: {
|
|
13
|
+
id: pluginToolIdFor({ pluginId: snapshot.pluginId, name: tool.name }), description: tool.description,
|
|
14
|
+
inputSchema: tool.inputSchema, readOnly: false, requiresConfirmation: required.metadata.approval?.confirmation !== 'direct',
|
|
15
|
+
timeoutMs: 30000, maxOutputBytes: 65536, metadata: required.metadata,
|
|
16
|
+
},
|
|
17
|
+
policy: { authorize: async (ctx) => {
|
|
18
|
+
if (!await active())
|
|
19
|
+
return 'deny';
|
|
20
|
+
const auth = await required.resolveAuth({ pluginId: snapshot.pluginId, principalId: ctx.principal.id });
|
|
21
|
+
return auth && await active() ? 'allow' : 'deny';
|
|
22
|
+
} },
|
|
23
|
+
handler: async (ctx) => {
|
|
24
|
+
const auth = await required.resolveAuth({ pluginId: snapshot.pluginId, principalId: ctx.principal.id });
|
|
25
|
+
if (!auth || !await active())
|
|
26
|
+
throw new ToolInputError({ message: 'Plugin tool is disabled or was reloaded.' });
|
|
27
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
28
|
+
return tool.handler({ pluginId: snapshot.pluginId, sdk: snapshot.sdk, auth, input, signal: ctx.signal }, {});
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
/** Host lifecycle attaches one revocable scope to its existing registry. Disposal removes only
|
|
34
|
+
* this scope's tools and subscription. A failed replacement leaves the previous generation. */
|
|
35
|
+
export function attachPluginContributionTools(required, _optional = {}) {
|
|
36
|
+
const scope = createToolRegistrationScope({ registry: required.registry });
|
|
37
|
+
const refresh = () => scope.replace({ registrations: buildPluginContributionToolRegistrations(required) });
|
|
38
|
+
refresh();
|
|
39
|
+
const unsubscribe = required.contributions.subscribe({ onChanged: refresh });
|
|
40
|
+
return { dispose(_required, _optional = {}) { unsubscribe(); scope.replace({ registrations: [] }); } };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=tool-contributions.js.map
|