@jini-ai/plugins 0.6.12 → 0.6.15-rc.2

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 (85) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +7 -0
  3. package/dist/host/capability-sdk.d.ts +1 -0
  4. package/dist/host/capability-sdk.d.ts.map +1 -1
  5. package/dist/host/capability-sdk.js +6 -0
  6. package/dist/host/capability-sdk.js.map +1 -1
  7. package/dist/host/contributions.d.ts +9 -1
  8. package/dist/host/contributions.d.ts.map +1 -1
  9. package/dist/host/contributions.js +17 -3
  10. package/dist/host/contributions.js.map +1 -1
  11. package/dist/host/hook-registry.d.ts +1 -1
  12. package/dist/host/hook-registry.d.ts.map +1 -1
  13. package/dist/host/hook-registry.js +18 -6
  14. package/dist/host/hook-registry.js.map +1 -1
  15. package/dist/host/index.d.ts +6 -0
  16. package/dist/host/index.d.ts.map +1 -1
  17. package/dist/host/index.js +4 -0
  18. package/dist/host/index.js.map +1 -1
  19. package/dist/host/manifest-types.d.ts +57 -1
  20. package/dist/host/manifest-types.d.ts.map +1 -1
  21. package/dist/host/manifest.d.ts +3 -3
  22. package/dist/host/manifest.d.ts.map +1 -1
  23. package/dist/host/manifest.js +10 -4
  24. package/dist/host/manifest.js.map +1 -1
  25. package/dist/host/node/discovery.d.ts +9 -0
  26. package/dist/host/node/discovery.d.ts.map +1 -1
  27. package/dist/host/node/discovery.js +73 -17
  28. package/dist/host/node/discovery.js.map +1 -1
  29. package/dist/host/node/index.d.ts +1 -0
  30. package/dist/host/node/index.d.ts.map +1 -1
  31. package/dist/host/node/index.js +1 -0
  32. package/dist/host/node/index.js.map +1 -1
  33. package/dist/host/node/install.d.ts.map +1 -1
  34. package/dist/host/node/install.js +4 -1
  35. package/dist/host/node/install.js.map +1 -1
  36. package/dist/host/node/loader.d.ts +10 -1
  37. package/dist/host/node/loader.d.ts.map +1 -1
  38. package/dist/host/node/loader.js +74 -29
  39. package/dist/host/node/loader.js.map +1 -1
  40. package/dist/host/node/module-snapshot.d.ts +66 -3
  41. package/dist/host/node/module-snapshot.d.ts.map +1 -1
  42. package/dist/host/node/module-snapshot.js +188 -18
  43. package/dist/host/node/module-snapshot.js.map +1 -1
  44. package/dist/host/node/open-flags.d.ts +3 -0
  45. package/dist/host/node/open-flags.d.ts.map +1 -1
  46. package/dist/host/node/open-flags.js +12 -5
  47. package/dist/host/node/open-flags.js.map +1 -1
  48. package/dist/host/node/package-files.d.ts +28 -0
  49. package/dist/host/node/package-files.d.ts.map +1 -1
  50. package/dist/host/node/package-files.js +50 -17
  51. package/dist/host/node/package-files.js.map +1 -1
  52. package/dist/host/node/provider-artifact.d.ts +22 -0
  53. package/dist/host/node/provider-artifact.d.ts.map +1 -0
  54. package/dist/host/node/provider-artifact.js +34 -0
  55. package/dist/host/node/provider-artifact.js.map +1 -0
  56. package/dist/host/plugin-claims.d.ts.map +1 -1
  57. package/dist/host/plugin-claims.js +2 -1
  58. package/dist/host/plugin-claims.js.map +1 -1
  59. package/dist/host/ports.d.ts +1 -0
  60. package/dist/host/ports.d.ts.map +1 -1
  61. package/dist/host/provider-config-source.d.ts +47 -0
  62. package/dist/host/provider-config-source.d.ts.map +1 -0
  63. package/dist/host/provider-config-source.js +2 -0
  64. package/dist/host/provider-config-source.js.map +1 -0
  65. package/dist/host/provider-contributions.d.ts +31 -0
  66. package/dist/host/provider-contributions.d.ts.map +1 -0
  67. package/dist/host/provider-contributions.js +181 -0
  68. package/dist/host/provider-contributions.js.map +1 -0
  69. package/dist/host/provider-host.d.ts +83 -0
  70. package/dist/host/provider-host.d.ts.map +1 -0
  71. package/dist/host/provider-host.js +222 -0
  72. package/dist/host/provider-host.js.map +1 -0
  73. package/dist/host/provider-setting-required.d.ts +19 -0
  74. package/dist/host/provider-setting-required.d.ts.map +1 -0
  75. package/dist/host/provider-setting-required.js +38 -0
  76. package/dist/host/provider-setting-required.js.map +1 -0
  77. package/dist/host/provider-settings-migrations.d.ts +8 -0
  78. package/dist/host/provider-settings-migrations.d.ts.map +1 -0
  79. package/dist/host/provider-settings-migrations.js +14 -0
  80. package/dist/host/provider-settings-migrations.js.map +1 -0
  81. package/dist/host/quarantine.d.ts +5 -0
  82. package/dist/host/quarantine.d.ts.map +1 -1
  83. package/dist/host/quarantine.js +6 -0
  84. package/dist/host/quarantine.js.map +1 -1
  85. package/package.json +7 -7
@@ -0,0 +1,181 @@
1
+ /** Server factories are inert registrations. Clients and timers belong to initialized resources. */
2
+ import { PROVIDER_ID_PATTERN } from '@jini-ai/core/provider-registry';
3
+ export const PLUGIN_PROVIDER_CAPABILITY = 'providers.register';
4
+ /** Shared grammar for manifest validation and runtime capture, using core's frozen id contract. */
5
+ export function isPluginProviderDeclaration(required, _optional = {}) {
6
+ const value = required.value;
7
+ if (!value || typeof value !== 'object' || Array.isArray(value))
8
+ return false;
9
+ const declaration = value;
10
+ return typeof declaration.contract === 'string' && PROVIDER_ID_PATTERN.test(declaration.contract)
11
+ && typeof declaration.id === 'string' && PROVIDER_ID_PATTERN.test(declaration.id)
12
+ && declaration.contractVersion === 1;
13
+ }
14
+ const SETTING_NAME = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
15
+ function optionalOf(value, type) {
16
+ return value === undefined || typeof value === type;
17
+ }
18
+ function optionalFlagsValid({ secret, required, hint, allowCustom }) {
19
+ return optionalOf(secret, 'boolean') && optionalOf(required, 'boolean') && optionalOf(hint, 'string') && optionalOf(allowCustom, 'boolean');
20
+ }
21
+ function labelValid(label) {
22
+ return typeof label === 'string' && label.trim() !== '' && label.length <= 120;
23
+ }
24
+ /** Declared references use the same setting-name grammar. O(1). */
25
+ function settingNameValid(value) {
26
+ return typeof value === 'string' && SETTING_NAME.test(value);
27
+ }
28
+ /** Header alternatives use an explicit allowlist, with HTTP token names only. */
29
+ function headerNamesValid({ headerNames, orPresent }, _optional = {}) {
30
+ if (headerNames === undefined)
31
+ return true;
32
+ return settingNameValid(orPresent) && Array.isArray(headerNames) && headerNames.length > 0
33
+ && headerNames.every(name => typeof name === 'string' && /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(name));
34
+ }
35
+ /** A conditional requirement is an exact match or a named alternative, never executable plugin logic. */
36
+ function requiredUnlessValid(value) {
37
+ if (value === undefined)
38
+ return true;
39
+ if (!value || typeof value !== 'object' || Array.isArray(value))
40
+ return false;
41
+ const { field, equals, orPresent, headerNames } = value;
42
+ return settingNameValid(field) && typeof equals === 'string'
43
+ && (orPresent === undefined || settingNameValid(orPresent))
44
+ && headerNamesValid({ headerNames, orPresent });
45
+ }
46
+ /** A conditional requirement names public string choices, never executable plugin logic.
47
+ * @complexity O(k) in declared choices; no effects. */
48
+ function requiredWhenValid(value) {
49
+ if (value === undefined)
50
+ return true;
51
+ if (!value || typeof value !== 'object' || Array.isArray(value))
52
+ return false;
53
+ const { field, in: choices } = value;
54
+ return typeof field === 'string' && SETTING_NAME.test(field)
55
+ && Array.isArray(choices) && choices.length > 0 && choices.every((choice) => typeof choice === 'string' && choice.trim() !== '');
56
+ }
57
+ const optionValid = (option) => {
58
+ const { value, label } = (option ?? {});
59
+ return typeof value === 'string' && value.trim() !== '' && labelValid(label);
60
+ };
61
+ /**
62
+ * `default` / `options` / `allowCustom` (public fields only): a host prefills a default and renders
63
+ * options as a select, so a secret can carry neither (a declared default would be a shared secret).
64
+ */
65
+ function choicesProblem({ name, field }) {
66
+ const { secret, options, allowCustom } = field;
67
+ if (secret === true && (field.default !== undefined || options !== undefined))
68
+ return `secret provider setting '${name}' cannot declare a default or options`;
69
+ if (!optionalOf(field.default, 'string'))
70
+ return `provider setting '${name}' has a malformed default`;
71
+ if (options === undefined)
72
+ return allowCustom === undefined ? undefined : `provider setting '${name}' declares allowCustom without options`;
73
+ if (!Array.isArray(options) || options.length === 0 || !options.every(optionValid))
74
+ return `provider setting '${name}' options must be a non-empty list of { value, label }`;
75
+ return undefined;
76
+ }
77
+ /** One setting field's problem in words, or undefined. */
78
+ function settingFieldProblem({ field }, _optional = {}) {
79
+ if (!field || typeof field !== 'object' || Array.isArray(field))
80
+ return 'a provider setting must be an object';
81
+ const { name, label } = field;
82
+ if (!settingNameValid(name))
83
+ return 'a provider setting name must be 1-64 letters, digits or _ (starting with a letter)';
84
+ if (!labelValid(label))
85
+ return `provider setting '${name}' needs a label of 1-120 characters`;
86
+ if (!optionalFlagsValid(field))
87
+ return `provider setting '${name}' has a malformed secret/required/hint/allowCustom`;
88
+ if (!requiredUnlessValid(field.requiredUnless))
89
+ return `provider setting '${name}' has a malformed requiredUnless`;
90
+ if (!requiredWhenValid(field.requiredWhen))
91
+ return `provider setting '${name}' has a malformed requiredWhen`;
92
+ return choicesProblem({ name: name, field: field });
93
+ }
94
+ /** Declared provider settings (see `PluginProviderDeclaration.settings`): problems in words. */
95
+ export function providerSettingsErrors({ settings }, _optional = {}) {
96
+ if (settings === undefined)
97
+ return [];
98
+ if (!Array.isArray(settings))
99
+ return ['provider settings must be a list of fields'];
100
+ const problems = [];
101
+ const names = new Set();
102
+ for (const field of settings) {
103
+ const problem = settingFieldProblem({ field });
104
+ if (problem) {
105
+ problems.push(problem);
106
+ continue;
107
+ }
108
+ const { name } = field;
109
+ if (names.has(name))
110
+ problems.push(`duplicate provider setting '${name}'`);
111
+ names.add(name);
112
+ }
113
+ return problems;
114
+ }
115
+ const publicSetting = ({ fields, name }, _optional = {}) => fields.some(field => field.name === name && !field.secret);
116
+ /** Migration conditions only inspect declared public settings, so redacted reads behave identically. */
117
+ function migrationConditionValid({ when, whenPresent, fields }, _optional = {}) {
118
+ if (!when || !requiredWhenValid(when))
119
+ return false;
120
+ const condition = when;
121
+ return optionalOf(condition.orAbsent, 'boolean') && publicSetting({ fields, name: condition.field })
122
+ && (whenPresent === undefined || publicSetting({ fields, name: whenPresent }));
123
+ }
124
+ /** Migrations may assign public string fields only. */
125
+ function migrationAssignmentsValid({ set, fields }, _optional = {}) {
126
+ if (!set || typeof set !== 'object' || Array.isArray(set))
127
+ return false;
128
+ const assignments = Object.entries(set);
129
+ return assignments.length > 0 && assignments.every(([name, value]) => typeof value === 'string' && publicSetting({ fields, name }));
130
+ }
131
+ /** Validate the hook before a host reads it; malformed lists never reach migration execution. */
132
+ function migrationValid({ rule, fields }, _optional = {}) {
133
+ if (!rule || typeof rule !== 'object' || Array.isArray(rule))
134
+ return false;
135
+ const { when, whenPresent, set } = rule;
136
+ return migrationConditionValid({ when, whenPresent, fields }) && migrationAssignmentsValid({ set, fields });
137
+ }
138
+ /** Reject malformed migration hooks before a host can read them. */
139
+ function migrationsValid({ provider }, _optional = {}) {
140
+ if (provider.settingsMigrations === undefined)
141
+ return true;
142
+ return Array.isArray(provider.settings) && providerSettingsErrors({ settings: provider.settings }).length === 0
143
+ && Array.isArray(provider.settingsMigrations)
144
+ && provider.settingsMigrations.every(rule => migrationValid({ rule, fields: provider.settings }));
145
+ }
146
+ /** Collect static declaration errors; provider code is supported only by tier-3 admission. */
147
+ export function validatePluginProviderDeclarations(required, _optional = {}) {
148
+ const error = (message) => ({ code: 'PROVIDERS_INVALID', file: null, message });
149
+ if (!Array.isArray(required.value))
150
+ return [error('contributes.providers must be a list of provider declarations')];
151
+ const errors = [];
152
+ const seen = new Set();
153
+ for (const value of required.value) {
154
+ const declaration = { value };
155
+ if (!isPluginProviderDeclaration(declaration)) {
156
+ errors.push(error('provider requires { contract, id, contractVersion: 1 } with core provider ids'));
157
+ continue;
158
+ }
159
+ errors.push(...providerSettingsErrors({ settings: declaration.value.settings }).map(error));
160
+ if (!migrationsValid({ provider: declaration.value }))
161
+ errors.push(error('provider settingsMigrations are malformed or assign secret fields'));
162
+ const key = `${declaration.value.contract}:${declaration.value.id}`;
163
+ if (seen.has(key))
164
+ errors.push(error(`duplicate provider declaration '${key}'`));
165
+ seen.add(key);
166
+ }
167
+ if (!required.value.length)
168
+ return errors;
169
+ errors.push(...providerAdmissionErrors({ tier: required.tier, capabilities: required.capabilities }));
170
+ return errors;
171
+ }
172
+ function providerAdmissionErrors({ tier, capabilities }, _optional = {}) {
173
+ const errors = [];
174
+ const error = (message) => ({ code: 'PROVIDERS_INVALID', file: null, message });
175
+ if (tier !== 'tier-3')
176
+ errors.push(error('provider declarations require tier-3'));
177
+ if (!Array.isArray(capabilities) || !capabilities.includes(PLUGIN_PROVIDER_CAPABILITY))
178
+ errors.push(error('provider declarations require providers.register'));
179
+ return errors;
180
+ }
181
+ //# sourceMappingURL=provider-contributions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-contributions.js","sourceRoot":"","sources":["../../src/host/provider-contributions.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAGtE,MAAM,CAAC,MAAM,0BAA0B,GAAG,oBAA6B,CAAC;AAiBxE,mGAAmG;AACnG,MAAM,UAAU,2BAA2B,CACzC,QAA4B,EAAE,YAAmC,EAAE;IAEnE,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC7B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,MAAM,WAAW,GAAG,KAA2C,CAAC;IAChE,OAAO,OAAO,WAAW,CAAC,QAAQ,KAAK,QAAQ,IAAI,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;WAC5F,OAAO,WAAW,CAAC,EAAE,KAAK,QAAQ,IAAI,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;WAC9E,WAAW,CAAC,eAAe,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,YAAY,GAAG,8BAA8B,CAAC;AAEpD,SAAS,UAAU,CAAC,KAAc,EAAE,IAA0B;IAC5D,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC;AACtD,CAAC;AAED,SAAS,kBAAkB,CAAC,EAAE,MAAM,EA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AG,CAAC,OAAe,EAAyB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC/G,IAAI,IAAI,KAAK,QAAQ;QAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC,CAAC;IAClF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,0BAA0B,CAAC;QAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC,CAAC;IAC/J,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,83 @@
1
+ /** Resource lifecycle for the existing contribution snapshots. Domain validation stays injected. */
2
+ import { type ProviderDefinition } from '@jini-ai/core/provider-registry';
3
+ import type { PluginContributionRegistry } from './contributions.js';
4
+ import type { PluginProviderResource } from './provider-contributions.js';
5
+ export interface PluginProviderContract {
6
+ readonly contract: string;
7
+ /** Supplied by the domain owner; plugins never select or replace this validator. */
8
+ readonly validate: (required: {
9
+ provider: unknown;
10
+ }, optional?: Record<string, never>) => string | undefined;
11
+ readonly seed?: readonly ProviderDefinition<unknown>[];
12
+ }
13
+ export interface PluginProviderFailure {
14
+ readonly pluginId: string;
15
+ readonly contract: string;
16
+ readonly id: string;
17
+ readonly phase: 'dispose' | 'dispose_timeout';
18
+ readonly error: unknown;
19
+ }
20
+ export interface PluginProviderLease extends PluginProviderResource {
21
+ /** Retired leases must not admit new application work. In-flight work is host-owned. */
22
+ isCurrent(required: Record<string, never>, optional?: Record<string, never>): boolean;
23
+ dispose(required: Record<string, never>, optional?: Record<string, never>): Promise<void>;
24
+ }
25
+ export interface PluginProviderHost {
26
+ /** Await during boot. Undefined means unavailable or retired while initialization was pending. */
27
+ initialize(required: {
28
+ contract: string;
29
+ id: string;
30
+ input: Readonly<Record<string, unknown>>;
31
+ }, optional?: {
32
+ factoryOptions?: Readonly<Record<string, unknown>>;
33
+ }): Promise<PluginProviderLease | undefined>;
34
+ /** Disable/quarantine callers detach the contribution first; shutdown and failed boot call this. */
35
+ dispose(required: Record<string, never>, optional?: Record<string, never>): Promise<void>;
36
+ }
37
+ export declare class PluginProviderError extends Error {
38
+ constructor(required: {
39
+ message: string;
40
+ }, _optional?: Record<string, never>);
41
+ }
42
+ /** Explicit plugin-authored startup guidance. Raw SDK errors must never be shown to users. */
43
+ export declare class PluginProviderStartupError extends Error {
44
+ readonly reason: string;
45
+ readonly action: string;
46
+ constructor({ reason, action, cause }: {
47
+ reason: string;
48
+ action: string;
49
+ cause?: unknown;
50
+ }, _optional?: {});
51
+ }
52
+ /** Startup guidance from a {@link PluginProviderStartupError}, matched by shape: each provider plugin
53
+ * artifact bundles its own copy of this class, so `instanceof` against the host's copy is always false. */
54
+ export declare function pluginProviderStartupGuidance({ error }: {
55
+ error: unknown;
56
+ }, _optional?: {}): {
57
+ reason: string;
58
+ action: string;
59
+ } | undefined;
60
+ /** Applying saved settings either succeeds, requires a browser/process refresh, or fails to start. */
61
+ export type PluginProviderApplyResult = 'now' | 'restart' | {
62
+ appliesAt: 'failed';
63
+ reason: string;
64
+ action: string;
65
+ };
66
+ /**
67
+ * Track resources against snapshot identity, so replacement retires even the same plugin version.
68
+ * @param required.contributions Existing executable contribution owner; detach retires immediately.
69
+ * @param required.contracts Domain validators and optional built-in providers.
70
+ * @param optional.disposeTimeoutMs Positive finite bound for each resource's teardown (default 2000).
71
+ * @param optional.initializeTimeoutMs Positive finite bound for awaiting a factory (default 10000).
72
+ * @returns A host whose shutdown is idempotent and whose late factory results are disposed.
73
+ * @throws RangeError for invalid timeouts; PluginProviderError for unknown/invalid contracts or ports.
74
+ */
75
+ export declare function createPluginProviderHost(required: {
76
+ contributions: PluginContributionRegistry;
77
+ contracts: readonly PluginProviderContract[];
78
+ }, optional?: {
79
+ disposeTimeoutMs?: number;
80
+ initializeTimeoutMs?: number;
81
+ onError?: (required: PluginProviderFailure, optional?: Record<string, never>) => void | Promise<void>;
82
+ }): PluginProviderHost;
83
+ //# sourceMappingURL=provider-host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-host.d.ts","sourceRoot":"","sources":["../../src/host/provider-host.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,OAAO,EAA0B,KAAK,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,KAAK,EAAE,0BAA0B,EAA+B,MAAM,oBAAoB,CAAC;AAClG,OAAO,KAAK,EAA8B,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAEtG,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC;IAC7G,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;CACxD;AACD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,iBAAiB,CAAC;IAC9C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AACD,MAAM,WAAW,mBAAoB,SAAQ,sBAAsB;IACjE,wFAAwF;IACxF,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC;IACtF,OAAO,CAAC,QAAQ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C,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,SAAS,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAI3I;AAED,sGAAsG;AACtG,MAAM,MAAM,yBAAyB,GAAG,KAAK,GAAG,SAAS,GAAG;IAAE,SAAS,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAsCpH;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE;IACjD,aAAa,EAAE,0BAA0B,CAAC;IAAC,SAAS,EAAE,SAAS,sBAAsB,EAAE,CAAC;CACzF,EAAE,QAAQ,GAAE;IACX,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClG,GAAG,kBAAkB,CA0I1B"}
@@ -0,0 +1,222 @@
1
+ /** Resource lifecycle for the existing contribution snapshots. Domain validation stays injected. */
2
+ import { createProviderRegistry } from '@jini-ai/core/provider-registry';
3
+ export class PluginProviderError extends Error {
4
+ constructor(required, _optional = {}) {
5
+ super(required.message);
6
+ this.name = 'PluginProviderError';
7
+ }
8
+ }
9
+ /** Explicit plugin-authored startup guidance. Raw SDK errors must never be shown to users. */
10
+ export class PluginProviderStartupError extends Error {
11
+ reason;
12
+ action;
13
+ constructor({ reason, action, cause }, _optional = {}) {
14
+ super(reason, { cause });
15
+ this.name = 'PluginProviderStartupError';
16
+ this.reason = reason;
17
+ this.action = action;
18
+ }
19
+ }
20
+ /** Startup guidance from a {@link PluginProviderStartupError}, matched by shape: each provider plugin
21
+ * artifact bundles its own copy of this class, so `instanceof` against the host's copy is always false. */
22
+ export function pluginProviderStartupGuidance({ error }, _optional = {}) {
23
+ if (!(error instanceof Error) || error.name !== 'PluginProviderStartupError')
24
+ return undefined;
25
+ const { reason, action } = error;
26
+ return typeof reason === 'string' && typeof action === 'string' ? { reason, action } : undefined;
27
+ }
28
+ /** A timeout bounds waiting, not a promise's effects. Late results are still observed and released. */
29
+ function createResourceDisposer(required, _optional = {}) {
30
+ let disposal;
31
+ return () => {
32
+ disposal ??= (async () => {
33
+ let timer;
34
+ const work = Promise.resolve().then(() => required.resource.dispose({}, {})).catch(error => {
35
+ required.report({ phase: 'dispose', error });
36
+ });
37
+ try {
38
+ await Promise.race([work, new Promise(resolve => {
39
+ timer = setTimeout(() => {
40
+ required.report({ phase: 'dispose_timeout', error: new PluginProviderError({ message: 'provider disposal timed out' }) });
41
+ resolve();
42
+ }, required.timeoutMs);
43
+ })]);
44
+ }
45
+ finally {
46
+ if (timer !== undefined)
47
+ clearTimeout(timer);
48
+ }
49
+ })();
50
+ return disposal;
51
+ };
52
+ }
53
+ function timeoutOption(value, fallback, name) {
54
+ const timeoutMs = value ?? fallback;
55
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1)
56
+ throw new RangeError(`invalid provider ${name} timeout`);
57
+ return timeoutMs;
58
+ }
59
+ /**
60
+ * Track resources against snapshot identity, so replacement retires even the same plugin version.
61
+ * @param required.contributions Existing executable contribution owner; detach retires immediately.
62
+ * @param required.contracts Domain validators and optional built-in providers.
63
+ * @param optional.disposeTimeoutMs Positive finite bound for each resource's teardown (default 2000).
64
+ * @param optional.initializeTimeoutMs Positive finite bound for awaiting a factory (default 10000).
65
+ * @returns A host whose shutdown is idempotent and whose late factory results are disposed.
66
+ * @throws RangeError for invalid timeouts; PluginProviderError for unknown/invalid contracts or ports.
67
+ */
68
+ export function createPluginProviderHost(required, optional = {}) {
69
+ const timeoutMs = timeoutOption(optional.disposeTimeoutMs, 2000, 'disposal');
70
+ const initializeTimeoutMs = timeoutOption(optional.initializeTimeoutMs, 10_000, 'initialization');
71
+ const contracts = new Map();
72
+ for (const contract of required.contracts) {
73
+ if (contracts.has(contract.contract))
74
+ throw new PluginProviderError({ message: 'duplicate provider contract' });
75
+ // Validate built-in definitions eagerly, using core's throwing composition policy.
76
+ createProviderRegistry({ contract: contract.contract }, { validate: contract.validate, seed: contract.seed ?? [] });
77
+ contracts.set(contract.contract, contract);
78
+ }
79
+ const acquired = new Set();
80
+ const cleanups = new Set();
81
+ const disposers = new WeakMap();
82
+ // Pending initializations re-check their generation on each change, so retirement settles them.
83
+ const wakers = new Set();
84
+ let closed = false;
85
+ let shutdown;
86
+ const current = (snapshot) => !closed && required.contributions.list({}).includes(snapshot);
87
+ // Every started teardown, direct or host-triggered, is awaited by shutdown.
88
+ const track = (pending) => {
89
+ cleanups.add(pending);
90
+ void pending.then(() => { cleanups.delete(pending); });
91
+ return pending;
92
+ };
93
+ const cleanup = (item) => item.lease.dispose({});
94
+ const unsubscribe = required.contributions.subscribe({ onChanged: () => {
95
+ // Contribution listeners can reject publication and roll it back synchronously. Release
96
+ // only the committed generation; lease.isCurrent already blocks work during replacement.
97
+ queueMicrotask(() => {
98
+ for (const item of acquired)
99
+ if (!current(item.snapshot))
100
+ void cleanup(item);
101
+ for (const wake of wakers)
102
+ wake();
103
+ });
104
+ } });
105
+ const report = (failure) => {
106
+ // Diagnostics must never prevent another provider from releasing its resources.
107
+ try {
108
+ void Promise.resolve(optional.onError?.(failure, {})).catch(() => { });
109
+ }
110
+ catch { /* Failure reporting is a borrowed host effect. */ }
111
+ };
112
+ function releaserFor(input) {
113
+ let release = disposers.get(input.resource);
114
+ if (!release) {
115
+ release = createResourceDisposer({ resource: input.resource, timeoutMs, report: failure => report({
116
+ ...failure, pluginId: input.snapshot.pluginId, contract: input.provider.contract, id: input.provider.id,
117
+ }) });
118
+ disposers.set(input.resource, release);
119
+ }
120
+ return release;
121
+ }
122
+ function leaseResource(input) {
123
+ let retired = false;
124
+ const item = { snapshot: input.snapshot, lease: {
125
+ port: input.port,
126
+ isCurrent: () => !retired && current(input.snapshot),
127
+ dispose: () => { retired = true; acquired.delete(item); return track(input.release()); },
128
+ } };
129
+ return item;
130
+ }
131
+ function validatePort(input) {
132
+ const registry = createProviderRegistry({ contract: input.contract.contract }, {
133
+ validate: input.contract.validate, seed: input.contract.seed ?? [],
134
+ });
135
+ if (!registry.contribute({ definition: { id: input.provider.id, provider: input.port }, pluginId: input.snapshot.pluginId, contract: input.provider.contract })) {
136
+ throw new PluginProviderError({ message: registry.refusals()[0].message });
137
+ }
138
+ }
139
+ function findProvider(input) {
140
+ for (const snapshot of required.contributions.list({})) {
141
+ const provider = snapshot.providers?.find(value => value.contract === input.contract && value.id === input.id);
142
+ if (provider)
143
+ return { snapshot, provider };
144
+ }
145
+ return undefined;
146
+ }
147
+ /** Admit one factory result; anything not handed out as a lease is released before settling. */
148
+ async function admit(input) {
149
+ const { resource, snapshot } = input;
150
+ if (!resource || typeof resource.dispose !== 'function')
151
+ throw new PluginProviderError({ message: 'provider factory must return { port, dispose }' });
152
+ // Cleanup exists before the first port read; the single read is the value validated and leased.
153
+ const release = releaserFor(input);
154
+ let item;
155
+ try {
156
+ const port = resource.port;
157
+ validatePort({ ...input, port });
158
+ item = leaseResource({ port, release, snapshot });
159
+ }
160
+ catch (error) {
161
+ await track(release());
162
+ throw error;
163
+ }
164
+ if (input.abandoned() || !current(snapshot)) {
165
+ await cleanup(item);
166
+ return undefined;
167
+ }
168
+ acquired.add(item);
169
+ return item.lease;
170
+ }
171
+ /** Settle on the factory, retirement (undefined) or the deadline; admit() still releases late results. */
172
+ function untilRetiredOrDeadline(input) {
173
+ let timer;
174
+ let wake;
175
+ const stopped = new Promise((resolve, reject) => {
176
+ wake = () => { if (!current(input.snapshot)) {
177
+ input.abandon();
178
+ resolve(undefined);
179
+ } };
180
+ timer = setTimeout(() => {
181
+ input.abandon();
182
+ reject(new PluginProviderError({ message: 'provider initialization timed out' }));
183
+ }, initializeTimeoutMs);
184
+ });
185
+ wakers.add(wake);
186
+ // The factory may already have retired the generation (e.g. a borrowed callback shut the host down).
187
+ wake();
188
+ return Promise.race([input.produced, stopped]).finally(() => { wakers.delete(wake); clearTimeout(timer); });
189
+ }
190
+ async function initialize(input, options = {}) {
191
+ if (closed)
192
+ throw new PluginProviderError({ message: 'provider host is closed' });
193
+ const contract = contracts.get(input.contract);
194
+ if (!contract)
195
+ throw new PluginProviderError({ message: `unknown provider contract '${input.contract}'` });
196
+ const selected = findProvider(input);
197
+ if (!selected)
198
+ return undefined;
199
+ const { snapshot, provider } = selected;
200
+ let abandoned = false;
201
+ const produced = Promise.resolve(provider.factory(input.input, options.factoryOptions ?? {}))
202
+ .then(resource => admit({ resource, contract, snapshot, provider, abandoned: () => abandoned }));
203
+ return untilRetiredOrDeadline({ produced, snapshot, abandon: () => { abandoned = true; } });
204
+ }
205
+ return {
206
+ initialize,
207
+ dispose() {
208
+ shutdown ??= (async () => {
209
+ closed = true;
210
+ unsubscribe();
211
+ // Begin every teardown before awaiting any: a hung or rejected sink cannot block peers.
212
+ for (const item of acquired)
213
+ void cleanup(item);
214
+ for (const wake of wakers)
215
+ wake();
216
+ await Promise.all([...cleanups]);
217
+ })();
218
+ return shutdown;
219
+ },
220
+ };
221
+ }
222
+ //# sourceMappingURL=provider-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-host.js","sourceRoot":"","sources":["../../src/host/provider-host.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,OAAO,EAAE,sBAAsB,EAA2B,MAAM,iCAAiC,CAAC;AA8BlG,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,QAA6B,EAAE,YAAmC,EAAE;QAC9E,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAAC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IAC7D,CAAC;CACF;AACD,8FAA8F;AAC9F,MAAM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AE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;gBAChD,KAAK,MAAM,IAAI,IAAI,MAAM;oBAAE,IAAI,EAAE,CAAC;gBAClC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;YACnC,CAAC,CAAC,EAAE,CAAC;YACL,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { PluginProviderSettingField } from './manifest-types.js';
2
+ /**
3
+ * Whether a declared field is required for the effective public values (including defaults).
4
+ * `requiredWhen` gates the requirement by exact choices; `requiredUnless` waives it on an exact match or a nonblank declared alternative.
5
+ * Pure; no values are returned or logged.
6
+ * @example isProviderSettingRequired({ field, values: { auth: 'none' } })
7
+ * @complexity O(k + b) time in conditional choices and alternative text; O(b) transient trim space.
8
+ */
9
+ export declare function isProviderSettingRequired({ field, values }: {
10
+ field: Pick<PluginProviderSettingField, 'required' | 'requiredUnless' | 'requiredWhen'>;
11
+ values: Readonly<Record<string, unknown>>;
12
+ }, _optional?: Record<string, never>): boolean;
13
+ /** Match only declared nonblank Name=Value headers; malformed lists never waive a requirement.
14
+ * @complexity O(h * n) in header text and the manifest's small name allowlist. */
15
+ export declare function hasProviderAuthHeader({ text, names }: {
16
+ text: string;
17
+ names: readonly string[];
18
+ }, _optional?: {}): boolean;
19
+ //# sourceMappingURL=provider-setting-required.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-setting-required.d.ts","sourceRoot":"","sources":["../../src/host/provider-setting-required.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAetE;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;IAC3D,KAAK,EAAE,IAAI,CAAC,0BAA0B,EAAE,UAAU,GAAG,gBAAgB,GAAG,cAAc,CAAC,CAAC;IACxF,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC3C,EAAE,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAM,GAAG,OAAO,CAMjD;AAGD;kFACkF;AAClF,wBAAgB,qBAAqB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,EAAE,SAAS,KAAK,GAAG,OAAO,CAI1H"}
@@ -0,0 +1,38 @@
1
+ /** Evaluate the declared alternative without returning any setting or credential value. O(b) alternative text. */
2
+ function requirementWaived({ condition, values }, _optional = {}) {
3
+ if (!condition)
4
+ return false;
5
+ if (values[condition.field] === condition.equals)
6
+ return true;
7
+ if (!condition.orPresent)
8
+ return false;
9
+ const alternative = values[condition.orPresent];
10
+ if (typeof alternative !== 'string' || alternative.trim() === '')
11
+ return false;
12
+ if (!condition.headerNames)
13
+ return true;
14
+ return hasProviderAuthHeader({ text: alternative, names: condition.headerNames });
15
+ }
16
+ /**
17
+ * Whether a declared field is required for the effective public values (including defaults).
18
+ * `requiredWhen` gates the requirement by exact choices; `requiredUnless` waives it on an exact match or a nonblank declared alternative.
19
+ * Pure; no values are returned or logged.
20
+ * @example isProviderSettingRequired({ field, values: { auth: 'none' } })
21
+ * @complexity O(k + b) time in conditional choices and alternative text; O(b) transient trim space.
22
+ */
23
+ export function isProviderSettingRequired({ field, values }, _optional = {}) {
24
+ const when = field.requiredWhen;
25
+ const required = when
26
+ ? when.in.some((choice) => choice === values[when.field])
27
+ : field.required === true;
28
+ return required && !requirementWaived({ condition: field.requiredUnless, values });
29
+ }
30
+ /** Match only declared nonblank Name=Value headers; malformed lists never waive a requirement.
31
+ * @complexity O(h * n) in header text and the manifest's small name allowlist. */
32
+ export function hasProviderAuthHeader({ text, names }, _optional = {}) {
33
+ const pairs = text.split(',').map(pair => /^([^=\s][^=]*?)\s*=\s*(.+)$/.exec(pair.trim()));
34
+ if (pairs.some(pair => !pair))
35
+ return false;
36
+ return pairs.some(pair => names.some(name => name.toLowerCase() === pair[1].toLowerCase()) && pair[2].trim() !== '');
37
+ }
38
+ //# sourceMappingURL=provider-setting-required.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-setting-required.js","sourceRoot":"","sources":["../../src/host/provider-setting-required.ts"],"names":[],"mappings":"AAEA,kHAAkH;AAClH,SAAS,iBAAiB,CAAC,EAAE,SAAS,EAAE,MAAM,EAE7C,EAAE,SAAS,GAAG,EAAE;IACf,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAC9D,IAAI,CAAC,SAAS,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IACvC,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAChD,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAC/E,IAAI,CAAC,SAAS,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IACxC,OAAO,qBAAqB,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC;AACpF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAC,EAAE,KAAK,EAAE,MAAM,EAGxD,EAAE,YAAmC,EAAE;IACtC,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC;IAChC,MAAM,QAAQ,GAAG,IAAI;QACnB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzD,CAAC,CAAC,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC;IAC5B,OAAO,QAAQ,IAAI,CAAC,iBAAiB,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC;AACrF,CAAC;AAGD;kFACkF;AAClF,MAAM,UAAU,qBAAqB,CAAC,EAAE,IAAI,EAAE,KAAK,EAA8C,EAAE,SAAS,GAAG,EAAE;IAC/G,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,6BAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3F,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,IAAK,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,CAAC,IAAI,IAAK,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAC3H,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { PluginProviderDeclaration } from './manifest-types.js';
2
+ /** Apply the plugin's declared public-setting migrations to a copy; inputs and secrets stay intact.
3
+ * @complexity O(f + m * c) for fields, ordered migrations and their declared choices. */
4
+ export declare function migrateProviderSettings({ providers, settings }: {
5
+ providers: readonly PluginProviderDeclaration[];
6
+ settings: Readonly<Record<string, string>>;
7
+ }, _optional?: {}): Readonly<Record<string, string>>;
8
+ //# sourceMappingURL=provider-settings-migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-settings-migrations.d.ts","sourceRoot":"","sources":["../../src/host/provider-settings-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAErE;yFACyF;AACzF,wBAAgB,uBAAuB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;IAC/D,SAAS,EAAE,SAAS,yBAAyB,EAAE,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC7F,EAAE,SAAS,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAQnD"}
@@ -0,0 +1,14 @@
1
+ /** Apply the plugin's declared public-setting migrations to a copy; inputs and secrets stay intact.
2
+ * @complexity O(f + m * c) for fields, ordered migrations and their declared choices. */
3
+ export function migrateProviderSettings({ providers, settings }, _optional = {}) {
4
+ const next = { ...settings };
5
+ for (const provider of providers)
6
+ for (const rule of provider.settingsMigrations ?? []) {
7
+ const value = next[rule.when.field];
8
+ const matches = value === undefined ? rule.when.orAbsent === true : rule.when.in.includes(value);
9
+ if (matches && (!rule.whenPresent || next[rule.whenPresent]?.trim()))
10
+ Object.assign(next, rule.set);
11
+ }
12
+ return next;
13
+ }
14
+ //# sourceMappingURL=provider-settings-migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-settings-migrations.js","sourceRoot":"","sources":["../../src/host/provider-settings-migrations.ts"],"names":[],"mappings":"AAEA;yFACyF;AACzF,MAAM,UAAU,uBAAuB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAE5D,EAAE,SAAS,GAAG,EAAE;IACf,MAAM,IAAI,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;IAC7B,KAAK,MAAM,QAAQ,IAAI,SAAS;QAAE,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,kBAAkB,IAAI,EAAE,EAAE,CAAC;YACvF,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpC,MAAM,OAAO,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACjG,IAAI,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC;gBAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACtG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}