@jini-ai/agent-plugins 0.7.3-next.2 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +22 -4
- package/calendly/README.md +29 -0
- package/calendly/mcp.json +1 -1
- package/cloudflare/lib/assets.mjs +1 -1
- package/cloudflare/lib/cms-forms.mjs +1 -1
- package/core/persistent-state.d.ts +4 -1
- package/core/persistent-state.js +55 -21
- package/dist/admin-surfaces/callback-field-inbox.d.ts +1 -6
- package/dist/admin-surfaces/connections/connections.d.ts +2 -6
- package/dist/admin-surfaces/connections/index.d.ts +3 -2
- package/dist/admin-surfaces/index.d.ts +3 -1
- package/dist/connect/access-token-tool.d.ts +1 -1
- package/dist/connect/access-token-tool.js +1 -1
- package/dist/connect/catalog.d.ts +26 -0
- package/dist/connect/catalog.js +42 -0
- package/dist/connect/connect-tool.d.ts +2 -294
- package/dist/connect/connect-tool.js +2 -53
- package/dist/connect/contracts.d.ts +257 -0
- package/dist/connect/contracts.js +2 -0
- package/dist/connect/credential-cards.d.ts +2 -0
- package/dist/connect/credential-cards.js +7 -4
- package/dist/connect/credential-save-tool.js +2 -3
- package/dist/connect/grant-signed-in-defaults.js +1 -1
- package/dist/connect/host-deps.d.ts +32 -0
- package/dist/connect/host-deps.js +35 -0
- package/dist/connect/import-access-token.js +1 -1
- package/dist/connect/index.d.ts +7 -2
- package/dist/connect/index.js +5 -2
- package/dist/connect/installed-plugin.d.ts +28 -0
- package/dist/connect/installed-plugin.js +19 -0
- package/dist/connect/new-site-agent-plugin-tokens.d.ts +88 -0
- package/dist/connect/new-site-agent-plugin-tokens.js +107 -0
- package/dist/connect/plugin-host/index.d.ts +1 -2
- package/dist/connect/plugin-host/index.js +18 -9
- package/dist/connect/token-sign-in.d.ts +1 -14
- package/dist/connect/token-sign-in.js +4 -23
- package/dist/core/export-props.d.ts +10 -0
- package/dist/core/export-props.js +31 -0
- package/dist/core/folder-zip-error.d.ts +5 -0
- package/dist/core/folder-zip-error.js +8 -0
- package/dist/core/host-incompatible-error.d.ts +8 -0
- package/dist/core/host-incompatible-error.js +9 -0
- package/dist/core/identity-namespace.d.ts +27 -16
- package/dist/core/identity-namespace.js +25 -22
- package/dist/core/plugin-display-name.d.ts +7 -0
- package/dist/core/plugin-display-name.js +11 -0
- package/dist/core/provider-plugin-link.d.ts +7 -0
- package/dist/core/provider-plugin-link.js +5 -0
- package/dist/{connect → core}/token-map.d.ts +11 -1
- package/dist/{connect → core}/token-map.js +15 -0
- package/dist/core/token-sign-in-list.d.ts +18 -0
- package/dist/core/token-sign-in-list.js +23 -0
- package/dist/core/update-error.d.ts +8 -0
- package/dist/core/update-error.js +9 -0
- package/dist/{lifecycle → core}/update-plan.d.ts +1 -1
- package/dist/ffmpeg-transcode/adapter.d.ts +74 -0
- package/dist/ffmpeg-transcode/adapter.js +155 -0
- package/dist/folder-zip-node.d.ts +2 -1
- package/dist/folder-zip-node.js +6 -5
- package/dist/folder-zip.d.ts +0 -4
- package/dist/folder-zip.js +1 -7
- package/dist/index.d.ts +3 -1
- package/dist/lifecycle/activation.d.ts +39 -3
- package/dist/lifecycle/activation.js +467 -418
- package/dist/lifecycle/automatic-use-offer.d.ts +62 -0
- package/dist/lifecycle/automatic-use-offer.js +52 -0
- package/dist/lifecycle/automatic-use.d.ts +33 -1
- package/dist/lifecycle/automatic-use.js +159 -38
- package/dist/lifecycle/bundled-source-archive.d.ts +1 -1
- package/dist/lifecycle/capability-projection.d.ts +0 -1
- package/dist/lifecycle/capability-projection.js +92 -23
- package/dist/lifecycle/compatibility-metadata.d.ts +1 -0
- package/dist/lifecycle/compatibility-metadata.js +6 -1
- package/dist/lifecycle/compatibility.d.ts +1 -8
- package/dist/lifecycle/compatibility.js +1 -8
- package/dist/lifecycle/credential-card-metadata.d.ts +2 -2
- package/dist/lifecycle/exports.d.ts +2 -45
- package/dist/lifecycle/exports.js +1 -30
- package/dist/lifecycle/host-tools/identity.d.ts +5 -4
- package/dist/lifecycle/host-tools/identity.js +5 -5
- package/dist/lifecycle/host-tools/ports.d.ts +10 -1
- package/dist/lifecycle/host-tools/search-tool.js +18 -8
- package/dist/lifecycle/host-tools/skill-tool.js +1 -1
- package/dist/lifecycle/index.d.ts +20 -17
- package/dist/lifecycle/index.js +5 -4
- package/dist/lifecycle/install-from-url.d.ts +1 -2
- package/dist/lifecycle/install.d.ts +4 -34
- package/dist/lifecycle/install.js +3 -3
- package/dist/lifecycle/installed-package-index.d.ts +1 -1
- package/dist/lifecycle/installed-package-index.js +4 -4
- package/dist/lifecycle/layout.d.ts +21 -25
- package/dist/lifecycle/layout.js +79 -0
- package/dist/lifecycle/manifest.d.ts +10 -7
- package/dist/lifecycle/manifest.js +20 -15
- package/dist/lifecycle/mcp-provisioning.d.ts +1 -1
- package/dist/lifecycle/metadata.d.ts +6 -3
- package/dist/lifecycle/metadata.js +2 -1
- package/dist/lifecycle/package-paths.js +59 -56
- package/dist/lifecycle/persistent-state.d.ts +10 -1
- package/dist/lifecycle/persistent-state.js +4 -2
- package/dist/lifecycle/ports.d.ts +18 -6
- package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +2 -14
- package/dist/lifecycle/retire-bundled.d.ts +1 -1
- package/dist/lifecycle/search-projection.d.ts +17 -3
- package/dist/lifecycle/search-projection.js +8 -8
- package/dist/lifecycle/search.d.ts +1 -0
- package/dist/lifecycle/search.js +2 -2
- package/dist/lifecycle/seed-bundled.d.ts +86 -1
- package/dist/lifecycle/seed-bundled.js +48 -84
- package/dist/lifecycle/set-enabled.d.ts +1 -13
- package/dist/lifecycle/set-enabled.js +11 -7
- package/dist/lifecycle/trusted-plugin-files.d.ts +1 -1
- package/dist/lifecycle/trusted-plugin-files.js +33 -30
- package/dist/lifecycle/types.d.ts +13 -34
- package/dist/lifecycle/uninstall.d.ts +1 -33
- package/dist/lifecycle/update-store.d.ts +0 -7
- package/dist/lifecycle/update-store.js +1 -8
- package/dist/lifecycle/update.d.ts +1 -1
- package/dist/lifecycle/update.js +60 -10
- package/dist/lifecycle/yauzl-archive-reader.d.ts +7 -2
- package/dist/lifecycle/yauzl-archive-reader.js +11 -6
- package/dist/manifest.d.ts +4 -8
- package/dist/react/AgentPluginDetailsModal.d.ts +187 -0
- package/dist/react/AgentPluginDetailsModal.js +29 -0
- package/dist/react/agent-plugin-install-port.d.ts +24 -0
- package/dist/react/agent-plugin-install-port.js +15 -0
- package/dist/react/installed-skills-composer-source.d.ts +60 -0
- package/dist/react/installed-skills-composer-source.js +111 -0
- package/dist/react/use-agent-plugins.hooks.d.ts +211 -0
- package/dist/react/use-agent-plugins.hooks.js +128 -0
- package/dist/site/activation-effects.d.ts +17 -0
- package/dist/site/activation-effects.js +31 -0
- package/dist/site/admin-surfaces/capabilities.d.ts +29 -0
- package/dist/site/admin-surfaces/capabilities.js +30 -0
- package/dist/site/admin-surfaces/delivery-bindings.d.ts +81 -0
- package/dist/site/admin-surfaces/delivery-bindings.js +161 -0
- package/dist/site/admin-surfaces/forms.d.ts +28 -0
- package/dist/site/admin-surfaces/forms.js +29 -0
- package/dist/site/admin-surfaces/handlers.d.ts +61 -0
- package/dist/site/admin-surfaces/handlers.js +35 -0
- package/dist/site/admin-surfaces/public-config.d.ts +12 -0
- package/dist/site/admin-surfaces/public-config.js +28 -0
- package/dist/site/analytics-provider-registry.d.ts +87 -0
- package/dist/site/analytics-provider-registry.js +87 -0
- package/dist/site/archive-reader-abi.d.ts +35 -0
- package/dist/site/archive-reader-abi.js +25 -0
- package/dist/site/auth-schemes.d.ts +110 -0
- package/dist/site/auth-schemes.js +119 -0
- package/dist/site/automatic-agent-plugins.d.ts +200 -0
- package/dist/site/automatic-agent-plugins.js +277 -0
- package/dist/site/bundled-contribution-sources.d.ts +24 -0
- package/dist/site/bundled-contribution-sources.js +17 -0
- package/dist/site/bundled-id-upgrade.d.ts +115 -0
- package/dist/site/bundled-id-upgrade.js +169 -0
- package/dist/site/customize-tool.d.ts +39 -0
- package/dist/site/customize-tool.js +31 -0
- package/dist/site/deploy-split-activation.d.ts +28 -0
- package/dist/site/deploy-split-activation.js +21 -0
- package/dist/site/exports/diagnostics.d.ts +37 -0
- package/dist/site/exports/diagnostics.js +55 -0
- package/dist/site/exports/runtime.d.ts +54 -0
- package/dist/site/exports/runtime.js +196 -0
- package/dist/site/exports/source.d.ts +42 -0
- package/dist/site/exports/source.js +58 -0
- package/dist/site/host-plugin-guidance.d.ts +137 -0
- package/dist/site/host-plugin-guidance.js +223 -0
- package/dist/site/host-signals.d.ts +78 -0
- package/dist/site/host-signals.js +83 -0
- package/dist/site/install-tool.d.ts +69 -0
- package/dist/site/install-tool.js +192 -0
- package/dist/site/install-upload.d.ts +175 -0
- package/dist/site/install-upload.js +324 -0
- package/dist/site/memory-i18n.d.ts +5 -0
- package/dist/site/memory-i18n.js +176 -0
- package/dist/site/memory.d.ts +80 -0
- package/dist/site/memory.js +83 -0
- package/dist/site/plugin-memory.d.ts +80 -0
- package/dist/site/plugin-memory.js +86 -0
- package/dist/site/provider-plugin-link.d.ts +112 -0
- package/dist/site/provider-plugin-link.js +100 -0
- package/dist/site/retired-plugin-tool-aliases.d.ts +40 -0
- package/dist/site/retired-plugin-tool-aliases.js +41 -0
- package/dist/site/service-ports.d.ts +108 -0
- package/dist/site/service-ports.js +2 -0
- package/dist/site/set-enabled.d.ts +80 -0
- package/dist/site/set-enabled.js +42 -0
- package/dist/site/soon-lock.d.ts +83 -0
- package/dist/site/soon-lock.js +78 -0
- package/dist/site/supersession.d.ts +61 -0
- package/dist/site/supersession.js +122 -0
- package/dist/site/uninstall-tool.d.ts +136 -0
- package/dist/site/uninstall-tool.js +203 -0
- package/dist/site/update-effects.d.ts +47 -0
- package/dist/site/update-effects.js +49 -0
- package/ffmpeg-transcode/plugin.json +16 -0
- package/github/source-control/backup-push.mjs +66 -46
- package/github/source-control/commit-site.mjs +112 -65
- package/github/source-control/write-files.mjs +86 -53
- package/github-pages/targets/github-pages.mjs +294 -233
- package/google-workspace/form-destinations/mapping.mjs +15 -7
- package/google-workspace/form-destinations/sheets.mjs +4 -2
- package/google-workspace/plugin.json +1 -0
- package/kuinetic/CHANGELOG.md +4 -0
- package/kuinetic/plugin.json +4 -1
- package/kuinetic/skills/kuinetic/SKILL.md +1 -2
- package/package.json +295 -18
- package/persistent-state.d.ts +4 -1
- package/resend/adapters/resend.mjs +5 -2
- package/resend/plugin.json +1 -1
- package/s3-compatible/jini-deploy-targets.json +1 -1
- package/s3-compatible/object-stores/s3-compatible.mjs +27 -4
- package/s3-compatible/targets/s3-compatible.mjs +3 -3
- package/site-import/plugin.json +3 -3
- package/site-import/skills/site-import/SKILL.md +62 -54
- package/site-import/skills/site-import/references/content-mapping.md +26 -20
- package/slide-design/plugin.json +1 -1
- package/slide-design/skills/slide-design/SKILL.md +8 -2
- package/ui-ux-design/CHANGELOG.md +6 -0
- package/ui-ux-design/plugin.json +1 -1
- package/ui-ux-design/skills/gstack-design/SKILL.md +6 -6
- package/ui-ux-design/skills/ui-ux-design/SKILL.md +3 -2
- package/ui-ux-design/skills/ui-ux-design/references/chrome-mobile-test-matrix.md +14 -12
- package/ui-ux-design/skills/ui-ux-design/references/ui-loop.md +16 -17
- package/vercel/NOTES.md +2 -1
- package/vercel/object-stores/vercel-blob.mjs +3 -4
- package/vercel/targets/vercel.mjs +425 -351
- package/core/commerce-server.d.ts +0 -2
- package/core/commerce-server.mjs +0 -2
- package/dist/admin-surfaces/connections/ports.d.ts +0 -110
- package/dist/admin-surfaces/connections/ports.js +0 -2
- /package/dist/{lifecycle → core}/install-errors.d.ts +0 -0
- /package/dist/{lifecycle → core}/install-errors.js +0 -0
- /package/dist/{lifecycle → core}/update-plan.js +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Scope, replay and refusal rules for guidance offers; the controller owns delivery state. */
|
|
2
|
+
import type { AgentPluginGuidanceAttempt, AgentPluginGuidanceOffer } from '@jini-ai/core/contracts/site/daemon';
|
|
3
|
+
export type GuidanceAttemptLiveness = (required: AgentPluginGuidanceAttempt, optional?: {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
}) => Promise<boolean>;
|
|
6
|
+
/** The one current offer of a logical-turn controller, plus its recorded commit once made. */
|
|
7
|
+
export interface StoredGuidanceOffer {
|
|
8
|
+
readonly scope: AgentPluginGuidanceAttempt;
|
|
9
|
+
offerId: string;
|
|
10
|
+
readonly offer: Omit<AgentPluginGuidanceOffer, 'offerId'>;
|
|
11
|
+
/** Display names of the offered full sections, in draft order. */
|
|
12
|
+
readonly offered: ReadonlyMap<string, string>;
|
|
13
|
+
/** Pins the offer saw; they enter the delivered set only when a commit succeeds. */
|
|
14
|
+
readonly loaded: readonly string[];
|
|
15
|
+
readonly isAttemptLive: GuidanceAttemptLiveness;
|
|
16
|
+
committed?: {
|
|
17
|
+
readonly ids: readonly string[];
|
|
18
|
+
readonly result: {
|
|
19
|
+
readonly guidanceIds: readonly string[];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export declare const GUIDANCE_REPLAY_REFUSAL = "This guidance choice was already recorded for this turn.";
|
|
24
|
+
/** A plain-words refusal; callers must not record any part of the choice after it. */
|
|
25
|
+
export declare function refuseGuidance({ reason }: {
|
|
26
|
+
reason: 'not-current' | 'replay' | 'unoffered' | 'unavailable' | 'cancelled';
|
|
27
|
+
}, _options?: {}): never;
|
|
28
|
+
export declare function guidanceScopeKey({ scope }: {
|
|
29
|
+
scope: AgentPluginGuidanceAttempt;
|
|
30
|
+
}, _options?: {}): string;
|
|
31
|
+
export declare function sameGuidanceScope({ left, right }: {
|
|
32
|
+
left: AgentPluginGuidanceAttempt;
|
|
33
|
+
right: AgentPluginGuidanceAttempt;
|
|
34
|
+
}, _options?: {}): boolean;
|
|
35
|
+
/** A replaced scope, or an older attempt of the current run, can never offer again. O(1). */
|
|
36
|
+
export declare function isRetiredGuidanceScope({ scope, current, retired }: {
|
|
37
|
+
scope: AgentPluginGuidanceAttempt;
|
|
38
|
+
current: StoredGuidanceOffer | undefined;
|
|
39
|
+
retired: ReadonlySet<string>;
|
|
40
|
+
}, _options?: {}): boolean;
|
|
41
|
+
/** Replays compare as sets: the same ids in another order are the same choice. O(n log n). */
|
|
42
|
+
export declare function sameGuidanceChoice({ left, right }: {
|
|
43
|
+
left: readonly string[];
|
|
44
|
+
right: readonly string[];
|
|
45
|
+
}, _options?: {}): boolean;
|
|
46
|
+
/** Only unique ids from this offer's full sections may be committed. O(n). */
|
|
47
|
+
export declare function assertOfferedChoice({ stored, deliveredIds }: {
|
|
48
|
+
stored: StoredGuidanceOffer;
|
|
49
|
+
deliveredIds: readonly string[];
|
|
50
|
+
}, _options?: {}): void;
|
|
51
|
+
/** The commit must name the stored scope and offer exactly. @returns The matching stored offer. */
|
|
52
|
+
export declare function currentGuidanceOffer({ stored, scope, offerId }: {
|
|
53
|
+
stored: StoredGuidanceOffer | undefined;
|
|
54
|
+
scope: AgentPluginGuidanceAttempt;
|
|
55
|
+
offerId: string;
|
|
56
|
+
}, _options?: {}): StoredGuidanceOffer;
|
|
57
|
+
/** The host's authoritative fence; an abort during the check also refuses. */
|
|
58
|
+
export declare function assertAttemptLive({ stored, signal }: {
|
|
59
|
+
stored: StoredGuidanceOffer;
|
|
60
|
+
signal?: AbortSignal | undefined;
|
|
61
|
+
}, _options?: {}): Promise<void>;
|
|
62
|
+
//# sourceMappingURL=automatic-use-offer.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const GUIDANCE_REPLAY_REFUSAL = 'This guidance choice was already recorded for this turn.';
|
|
2
|
+
const NOT_CURRENT = 'This guidance offer is no longer current for this turn.';
|
|
3
|
+
/** A plain-words refusal; callers must not record any part of the choice after it. */
|
|
4
|
+
export function refuseGuidance({ reason }, _options = {}) {
|
|
5
|
+
const messages = {
|
|
6
|
+
'not-current': NOT_CURRENT,
|
|
7
|
+
replay: GUIDANCE_REPLAY_REFUSAL,
|
|
8
|
+
unoffered: 'This guidance choice includes plugins that were not offered for this turn.',
|
|
9
|
+
unavailable: 'A selected plugin is no longer available, so no guidance was recorded.',
|
|
10
|
+
cancelled: 'Recording this guidance choice was cancelled.',
|
|
11
|
+
};
|
|
12
|
+
throw new Error(messages[reason]);
|
|
13
|
+
}
|
|
14
|
+
export function guidanceScopeKey({ scope }, _options = {}) {
|
|
15
|
+
return JSON.stringify([scope.runId, scope.attempt, scope.principalId]);
|
|
16
|
+
}
|
|
17
|
+
export function sameGuidanceScope({ left, right }, _options = {}) {
|
|
18
|
+
return guidanceScopeKey({ scope: left }) === guidanceScopeKey({ scope: right });
|
|
19
|
+
}
|
|
20
|
+
/** A replaced scope, or an older attempt of the current run, can never offer again. O(1). */
|
|
21
|
+
export function isRetiredGuidanceScope({ scope, current, retired }, _options = {}) {
|
|
22
|
+
if (retired.has(guidanceScopeKey({ scope })))
|
|
23
|
+
return true;
|
|
24
|
+
return !!current && current.scope.runId === scope.runId && scope.attempt < current.scope.attempt;
|
|
25
|
+
}
|
|
26
|
+
/** Replays compare as sets: the same ids in another order are the same choice. O(n log n). */
|
|
27
|
+
export function sameGuidanceChoice({ left, right }, _options = {}) {
|
|
28
|
+
const normalize = (ids) => JSON.stringify([...new Set(ids)].sort());
|
|
29
|
+
return normalize(left) === normalize(right);
|
|
30
|
+
}
|
|
31
|
+
/** Only unique ids from this offer's full sections may be committed. O(n). */
|
|
32
|
+
export function assertOfferedChoice({ stored, deliveredIds }, _options = {}) {
|
|
33
|
+
if (new Set(deliveredIds).size !== deliveredIds.length || deliveredIds.some(id => !stored.offered.has(id)))
|
|
34
|
+
refuseGuidance({ reason: 'unoffered' });
|
|
35
|
+
}
|
|
36
|
+
/** The commit must name the stored scope and offer exactly. @returns The matching stored offer. */
|
|
37
|
+
export function currentGuidanceOffer({ stored, scope, offerId }, _options = {}) {
|
|
38
|
+
if (!stored || stored.offerId !== offerId || !sameGuidanceScope({ left: stored.scope, right: scope }))
|
|
39
|
+
refuseGuidance({ reason: 'not-current' });
|
|
40
|
+
return stored;
|
|
41
|
+
}
|
|
42
|
+
/** The host's authoritative fence; an abort during the check also refuses. */
|
|
43
|
+
export async function assertAttemptLive({ stored, signal }, _options = {}) {
|
|
44
|
+
if (signal?.aborted)
|
|
45
|
+
refuseGuidance({ reason: 'cancelled' });
|
|
46
|
+
const live = await stored.isAttemptLive(stored.scope, signal ? { signal } : {});
|
|
47
|
+
if (signal?.aborted)
|
|
48
|
+
refuseGuidance({ reason: 'cancelled' });
|
|
49
|
+
if (!live)
|
|
50
|
+
refuseGuidance({ reason: 'not-current' });
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=automatic-use-offer.js.map
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import type { AgentPluginSearchCandidate, AgentPluginSearchMatch } from './search.js';
|
|
3
3
|
import type { AgentPluginSkillRequest, ResolveAgentPluginRefsResult } from './resolve-agent-plugin-refs.js';
|
|
4
4
|
import type { AgentPluginLifecyclePorts } from './ports.js';
|
|
5
|
+
import type { AgentPluginGuidanceAttempt, AgentPluginGuidanceOffer } from '@jini-ai/core/contracts/site/daemon';
|
|
6
|
+
import { type GuidanceAttemptLiveness } from './automatic-use-offer.js';
|
|
5
7
|
export type ChatAgentPlugins = 'auto' | 'ask' | 'off';
|
|
6
8
|
export declare const DEFAULT_CHAT_AGENT_PLUGINS: ChatAgentPlugins;
|
|
7
9
|
/** Browser-owned, per-conversation state. Clearing it deliberately permits a fresh question. */
|
|
@@ -36,7 +38,9 @@ export interface AutomaticAgentPluginPorts {
|
|
|
36
38
|
/** Must recheck activation/trust and return real guidance, never a pointer to unopened guidance. */
|
|
37
39
|
resolve(input: {
|
|
38
40
|
pluginId: string;
|
|
39
|
-
} & AgentPluginSkillRequest, options?:
|
|
41
|
+
} & AgentPluginSkillRequest, options?: {
|
|
42
|
+
allowInactiveGuidance?: boolean;
|
|
43
|
+
}): Promise<ResolveAgentPluginRefsResult>;
|
|
40
44
|
/** Only a principal-bound human exchange may return action=auto. */
|
|
41
45
|
ask(input: {
|
|
42
46
|
matches: readonly AutomaticAgentPluginMatch[];
|
|
@@ -67,6 +71,22 @@ type PrepareInput = {
|
|
|
67
71
|
export declare function readChatAgentPluginState({ value }: {
|
|
68
72
|
value: unknown;
|
|
69
73
|
}, _options?: {}): ChatAgentPluginState;
|
|
74
|
+
type OfferInput = {
|
|
75
|
+
query: string;
|
|
76
|
+
loaded?: readonly string[];
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
};
|
|
79
|
+
type OfferRequired = {
|
|
80
|
+
scope: AgentPluginGuidanceAttempt;
|
|
81
|
+
offerId: string;
|
|
82
|
+
input: OfferInput;
|
|
83
|
+
isAttemptLive: GuidanceAttemptLiveness;
|
|
84
|
+
};
|
|
85
|
+
type CommitRequired = {
|
|
86
|
+
scope: AgentPluginGuidanceAttempt;
|
|
87
|
+
offerId: string;
|
|
88
|
+
deliveredIds: readonly string[];
|
|
89
|
+
};
|
|
70
90
|
/** Create one run's preparation owner. Calls serialize so parallel tool writes share one question.
|
|
71
91
|
* @param required Host effects and the person's mode; browser state is advisory selection only.
|
|
72
92
|
* @returns prepare(): a relevance note or capability guidance; load(): a truthful admission/delivery outcome.
|
|
@@ -89,6 +109,18 @@ export declare function createAutomaticAgentPluginUse({ mode, state: initialStat
|
|
|
89
109
|
pluginId: string;
|
|
90
110
|
signal?: AbortSignal;
|
|
91
111
|
} & AgentPluginSkillRequest, _options?: {}) => Promise<AutomaticAgentPluginLoadResult>;
|
|
112
|
+
/** Draft guidance for one live attempt without recording delivery; the host injects the offer id and liveness check.
|
|
113
|
+
* @example const draft = await controller.offer({ scope, offerId, input: { query }, isAttemptLive });
|
|
114
|
+
*/
|
|
115
|
+
offer: (required: OfferRequired, _optional?: {}) => Promise<AgentPluginGuidanceOffer>;
|
|
116
|
+
/** Record the offered ids the host actually delivered; a same-choice replay returns the cached result.
|
|
117
|
+
* @example await controller.commit({ scope, offerId, deliveredIds: ['plugin-a'] });
|
|
118
|
+
*/
|
|
119
|
+
commit: (required: CommitRequired, optional?: {
|
|
120
|
+
signal?: AbortSignal;
|
|
121
|
+
}) => Promise<{
|
|
122
|
+
readonly guidanceIds: readonly string[];
|
|
123
|
+
}>;
|
|
92
124
|
};
|
|
93
125
|
export {};
|
|
94
126
|
//# sourceMappingURL=automatic-use.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { agentVisiblePluginCandidate } from './search-projection.js';
|
|
2
|
+
import { assertAttemptLive, assertOfferedChoice, currentGuidanceOffer, guidanceScopeKey, isRetiredGuidanceScope, refuseGuidance, sameGuidanceChoice, sameGuidanceScope, } from './automatic-use-offer.js';
|
|
2
3
|
export const DEFAULT_CHAT_AGENT_PLUGINS = 'auto';
|
|
3
4
|
const MAX_AUTOMATIC_GUIDANCE_BYTES = 8 * 1024;
|
|
4
5
|
const MAX_QUERY_GUIDANCE_BYTES = 24 * 1024;
|
|
@@ -7,15 +8,19 @@ function describeMatch({ plugin }, _options = {}) {
|
|
|
7
8
|
return { id: plugin.pluginId, name: (plugin.displayName ?? plugin.pluginId).replace(/\s+/g, ' '),
|
|
8
9
|
why: (plugin.summary ?? plugin.description ?? `Provides ${(plugin.provides ?? plugin.keywords).join(', ')}`).split(/[\n.]/)[0].replace(/\s+/g, ' ').slice(0, 180) };
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/** `drafted` names full sections an offer carries but has not recorded; they leave the catalog too. */
|
|
12
|
+
function enabledPluginCatalog({ ctx, candidates, drafted }, _options = {}) {
|
|
13
|
+
// Installed/enabled is not consent: saved Ask selections may omit ids without excluding them.
|
|
14
|
+
const admitted = ctx.mode === 'ask' ? candidates.filter(plugin => ctx.state.decision?.asked === true && ctx.state.decision.selected.includes(plugin.pluginId)) : candidates;
|
|
15
|
+
const rows = [...admitted].filter(plugin => !ctx.state.excluded.includes(plugin.pluginId) && !ctx.delivered.has(plugin.pluginId) && !drafted.includes(plugin.pluginId))
|
|
12
16
|
.sort((a, b) => a.pluginId.localeCompare(b.pluginId));
|
|
13
17
|
return rows.length ? 'Enabled agent plugins (load one before acting on its part):\n' + rows.map(plugin => catalogRow({ ctx, plugin })).join('\n') : '';
|
|
14
18
|
}
|
|
15
19
|
function catalogRow({ ctx, plugin }, _options = {}) {
|
|
16
20
|
const { id, name, why } = describeMatch({ plugin });
|
|
17
|
-
const pointer = ctx.ports.formatPluginToolPointer?.({ pluginId: id, file: 'SKILL.md' }) ??
|
|
18
|
-
|
|
21
|
+
const pointer = ctx.ports.formatPluginToolPointer?.({ pluginId: id, file: 'SKILL.md' }) ?? "use the current host's plugin guidance reader";
|
|
22
|
+
const cue = (plugin.keywords.length ? plugin.keywords : plugin.skills.length ? plugin.skills.map(skill => skill.summary || skill.name) : plugin.provides ?? []).slice(0, 8).join(', ').replace(/\s+/g, ' ').slice(0, 180);
|
|
23
|
+
return `- ${name} (${id}): ${why}` + (cue ? `\n Use for: ${cue}` : '') + `\n Load: ${pointer}`;
|
|
19
24
|
}
|
|
20
25
|
/** A guarded capability admits its providers outright; a query is ranked for relevance. */
|
|
21
26
|
function rankCandidates({ candidates, input, ports }, _options = {}) {
|
|
@@ -23,15 +28,17 @@ function rankCandidates({ candidates, input, ports }, _options = {}) {
|
|
|
23
28
|
const admit = (plugins) => plugins.map(plugin => ({ ...plugin, score: 4 }));
|
|
24
29
|
if (capabilities)
|
|
25
30
|
return admit(candidates.filter(plugin => plugin.provides?.some(capability => capabilities.includes(capability))));
|
|
26
|
-
return
|
|
31
|
+
return ports.rank({ query: input.query ?? '', candidates, limit: candidates.length }, {});
|
|
27
32
|
}
|
|
28
33
|
function withRequiredProviders({ ranked, candidates }, _options = {}) {
|
|
29
34
|
const top = ranked[0];
|
|
30
35
|
if (!top)
|
|
31
36
|
return ranked;
|
|
37
|
+
const companions = (top.companions ?? []).flatMap(id => candidates.filter(plugin => plugin.enabled && plugin.pluginId === id).map(plugin => ranked.find(match => match.pluginId === id) ?? { ...plugin, score: 4 }));
|
|
32
38
|
const required = candidates.filter(plugin => plugin.enabled && plugin.provides?.some(capability => top.requires?.includes(capability)))
|
|
39
|
+
.sort((a, b) => a.pluginId.localeCompare(b.pluginId))
|
|
33
40
|
.map(plugin => ranked.find(match => match.pluginId === plugin.pluginId) ?? { ...plugin, score: 4 });
|
|
34
|
-
const ordered = [top, ...required, ...ranked];
|
|
41
|
+
const ordered = [top, ...companions, ...required, ...ranked];
|
|
35
42
|
return ordered.filter((plugin, index) => ordered.findIndex(match => match.pluginId === plugin.pluginId) === index);
|
|
36
43
|
}
|
|
37
44
|
/** Validate the request's small browser state; malformed state means no previous decision.
|
|
@@ -85,11 +92,11 @@ async function askConsent({ ctx, matches }, { signal } = {}) {
|
|
|
85
92
|
* Explicit content requests retain safe resolver refusals so the model can correct its request;
|
|
86
93
|
* thrown host diagnostics remain private. Failures stay retryable. O(1) bookkeeping.
|
|
87
94
|
*/
|
|
88
|
-
async function resolveOneGuidance(ctx, { plugin, ...request }, { signal } = {}) {
|
|
95
|
+
async function resolveOneGuidance(ctx, { plugin, ...request }, { signal, ...options } = {}) {
|
|
89
96
|
if (signal?.aborted)
|
|
90
97
|
return { status: 'cancelled', guidance: '' };
|
|
91
98
|
try {
|
|
92
|
-
const result = await ctx.ports.resolve({ pluginId: plugin.pluginId, ...request },
|
|
99
|
+
const result = await ctx.ports.resolve({ pluginId: plugin.pluginId, ...request }, options);
|
|
93
100
|
if (!result.ok)
|
|
94
101
|
return { status: result.code ?? 'unavailable', guidance: request.skill !== undefined || request.file !== undefined ? result.reason : '' };
|
|
95
102
|
if (!result.promptPrefix.trim())
|
|
@@ -107,6 +114,7 @@ function recordDelivery({ ctx, plugin, result }) {
|
|
|
107
114
|
ctx.delivered.set(plugin.pluginId, plugin.displayName ?? plugin.pluginId);
|
|
108
115
|
}
|
|
109
116
|
/** Bound automatic attachments before recording delivery; explicit loads retain complete text.
|
|
117
|
+
* The bounded sections land in a draft; recording delivery is the caller's separate step.
|
|
110
118
|
* O(p*b) in resolved plugins and guidance bytes; a deferred plugin remains retryable.
|
|
111
119
|
*/
|
|
112
120
|
async function resolveGuidance({ ctx, matches }, { budget, signal } = {}) {
|
|
@@ -116,15 +124,17 @@ async function resolveGuidance({ ctx, matches }, { budget, signal } = {}) {
|
|
|
116
124
|
const result = await resolveOneGuidance(ctx, { plugin: match }, { signal });
|
|
117
125
|
if (result.status !== 'loaded')
|
|
118
126
|
return undefined;
|
|
119
|
-
|
|
127
|
+
const bytes = new TextEncoder().encode(result.guidance).length + (budget !== undefined && guidance.length ? 2 : 0);
|
|
128
|
+
if (bytes > (budget ?? MAX_AUTOMATIC_GUIDANCE_BYTES)) {
|
|
129
|
+
if (budget !== undefined)
|
|
130
|
+
return undefined;
|
|
120
131
|
const pointer = ctx.ports.formatPluginToolPointer?.({ pluginId: match.pluginId, skill: match.pluginId, file: 'SKILL.md' });
|
|
121
132
|
const howToLoad = pointer === undefined ? '' : ` Load the full instructions with ${pointer}; use the same call with file '<relative path>' for supporting references.`;
|
|
122
|
-
return `Agent Plugin '${match.pluginId}' guidance is deferred because it exceeds the automatic byte limit.${howToLoad}
|
|
133
|
+
return { plugin: match, full: false, text: `Agent Plugin '${match.pluginId}' guidance is deferred because it exceeds the automatic byte limit.${howToLoad}` };
|
|
123
134
|
}
|
|
124
|
-
recordDelivery({ ctx, plugin: match, result });
|
|
125
135
|
if (budget !== undefined)
|
|
126
|
-
budget -=
|
|
127
|
-
return result.guidance;
|
|
136
|
+
budget -= bytes;
|
|
137
|
+
return { plugin: match, full: true, text: result.guidance };
|
|
128
138
|
};
|
|
129
139
|
for (const match of matches) {
|
|
130
140
|
if (signal?.aborted)
|
|
@@ -165,47 +175,69 @@ async function prepare({ ctx, input }) {
|
|
|
165
175
|
ctx.alreadyLoaded.add(id);
|
|
166
176
|
if (ctx.mode === 'off' || input.signal?.aborted)
|
|
167
177
|
return '';
|
|
168
|
-
const installed =
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
const { installed, candidates } = await admittedCatalog(ctx);
|
|
179
|
+
pruneUnavailablePins({ ctx, pinned: ctx.alreadyLoaded, candidates });
|
|
180
|
+
const matches = await consentedMatches({ ctx, candidates, input, pinned: ctx.alreadyLoaded });
|
|
181
|
+
const sections = await preparedGuidance({ ctx, matches, input, pinned: ctx.alreadyLoaded });
|
|
182
|
+
// Obtaining consent and resolving bytes do not prove full guidance was selected for delivery;
|
|
183
|
+
// one-shot preparation selects every full section it drafted, so it records them all here.
|
|
184
|
+
for (const section of sections)
|
|
185
|
+
if (section.full)
|
|
186
|
+
recordDelivery({ ctx, plugin: section.plugin, result: { status: 'loaded', guidance: section.text } });
|
|
175
187
|
rememberDelivery(ctx);
|
|
176
188
|
await publishUsage(ctx);
|
|
177
|
-
return withPluginNotes({ ctx, input, installed, candidates, result });
|
|
189
|
+
return withPluginNotes({ ctx, input, installed, candidates, result: joinSections({ sections }), drafted: [] });
|
|
190
|
+
}
|
|
191
|
+
/** Installed packages minus exclusions, and the enabled subset automatic use may draft from. */
|
|
192
|
+
async function admittedCatalog(ctx) {
|
|
193
|
+
const installed = (await ctx.ports.list({}, {})).filter(plugin => !ctx.state.excluded.includes(plugin.pluginId));
|
|
194
|
+
return { installed, candidates: installed.filter(plugin => plugin.enabled) };
|
|
195
|
+
}
|
|
196
|
+
/** Pins whose plugin is no longer enabled stop counting as delivered. O(p*c). */
|
|
197
|
+
function pruneUnavailablePins({ pinned, candidates }) {
|
|
198
|
+
for (const id of pinned)
|
|
199
|
+
if (!candidates.some(plugin => plugin.pluginId === id))
|
|
200
|
+
pinned.delete(id);
|
|
201
|
+
}
|
|
202
|
+
function joinSections({ sections }) {
|
|
203
|
+
return sections.map(section => section.text).join('\n\n');
|
|
178
204
|
}
|
|
179
205
|
/** Appends the enabled-plugin catalog and the off-plugin note to the prepared guidance. */
|
|
180
|
-
function withPluginNotes({ ctx, input, installed, candidates, result }) {
|
|
206
|
+
function withPluginNotes({ ctx, input, installed, candidates, result, drafted }) {
|
|
181
207
|
// Preflight never resolves off packages implicitly. A catalog line offers an explicit read;
|
|
182
208
|
// its setup guidance may explain whether enabling or credentials are needed.
|
|
183
209
|
const off = offPluginNote(ctx, { catalog: installed, input });
|
|
184
|
-
const catalog = input.query !== undefined && !input.capabilities?.length ? enabledPluginCatalog({ ctx, candidates }) : '';
|
|
210
|
+
const catalog = input.query !== undefined && !input.capabilities?.length ? enabledPluginCatalog({ ctx, candidates: candidates.filter(plugin => !input.loaded?.includes(plugin.pluginId)), drafted }) : '';
|
|
185
211
|
return [result, catalog, off].filter(Boolean).join('\n\n');
|
|
186
212
|
}
|
|
187
213
|
/** Rank enabled candidates, drop plugins this run already has, then apply the person's consent. */
|
|
188
|
-
async function consentedMatches({ ctx, candidates, input }) {
|
|
214
|
+
async function consentedMatches({ ctx, candidates, input, pinned }) {
|
|
189
215
|
const ranked = rankCandidates({ candidates, input, ports: ctx.ports });
|
|
190
216
|
// Owner decision 2026-10-18: no per-chat plugin count; the relevance threshold and vendor gate decide.
|
|
191
|
-
const
|
|
192
|
-
|
|
217
|
+
const planned = input.capabilities ? ranked : withRequiredProviders({ ranked, candidates });
|
|
218
|
+
const relevant = planned.filter(plugin => !ctx.delivered.has(plugin.pluginId) && !input.loaded?.includes(plugin.pluginId) && (!pinned.has(plugin.pluginId) || !!input.query));
|
|
219
|
+
const consented = await applyConsent({ ctx, matches: relevant }, { signal: input.signal });
|
|
220
|
+
const topAccepted = consented.some(plugin => plugin.pluginId === ranked[0]?.pluginId);
|
|
221
|
+
return consented.filter(plugin => topAccepted || !ranked[0]?.companions?.includes(plugin.pluginId) || ranked.some(match => match.pluginId === plugin.pluginId));
|
|
193
222
|
}
|
|
194
223
|
/** Capability calls resolve every match; a query resolves the top and required providers. */
|
|
195
|
-
async function preparedGuidance({ ctx, matches, input }) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return
|
|
224
|
+
async function preparedGuidance({ ctx, matches, input, pinned }) {
|
|
225
|
+
if (input.capabilities?.length)
|
|
226
|
+
return resolveGuidance({ ctx, matches }, { signal: input.signal });
|
|
227
|
+
return resolveGuidance({ ctx, matches: primaryMatch({ matches, input, pinned }) }, { budget: MAX_QUERY_GUIDANCE_BYTES, signal: input.signal });
|
|
199
228
|
}
|
|
200
229
|
/** The top match and required providers a fresh, unbounded query preflight delivers in full; otherwise none. */
|
|
201
|
-
function primaryMatch({
|
|
202
|
-
|
|
230
|
+
function primaryMatch({ matches, input, pinned }) {
|
|
231
|
+
// The argument-size skip applies only to legacy one-shot preparation: an offer carries no
|
|
232
|
+
// maxPromptArgBytes because the launcher sizes the full and catalog variants itself.
|
|
233
|
+
if (!(input.maxPromptArgBytes === undefined && input.query && !input.loaded?.length && !pinned.has(matches[0]?.pluginId ?? '')))
|
|
203
234
|
return [];
|
|
204
235
|
const [top, ...rest] = matches;
|
|
205
236
|
if (!top)
|
|
206
237
|
return [];
|
|
207
|
-
const
|
|
208
|
-
|
|
238
|
+
const companions = rest.filter(plugin => top.companions?.includes(plugin.pluginId) && !pinned.has(plugin.pluginId));
|
|
239
|
+
const additional = rest.filter(plugin => !top.companions?.includes(plugin.pluginId) && !pinned.has(plugin.pluginId));
|
|
240
|
+
return [top, ...companions, ...additional.slice(0, 3)];
|
|
209
241
|
}
|
|
210
242
|
/** Rank readable metadata for off plugins; never load their tools or guidance implicitly. O(p*t). */
|
|
211
243
|
function offPluginNote(ctx, { catalog, input }) {
|
|
@@ -243,7 +275,7 @@ async function loadPermitted(ctx, { plugin, ...request }, { signal } = {}) {
|
|
|
243
275
|
await publishUsage(ctx);
|
|
244
276
|
return { status: 'excluded', guidance: '' };
|
|
245
277
|
}
|
|
246
|
-
let result = await resolveOneGuidance(ctx, { plugin, ...request }, { signal });
|
|
278
|
+
let result = await resolveOneGuidance(ctx, { plugin, ...request }, { signal, ...(!plugin.enabled ? { allowInactiveGuidance: true } : {}) });
|
|
247
279
|
if (!plugin.enabled && result.status === 'loaded') {
|
|
248
280
|
result = { status: 'installed-but-inactive', guidance: `Plugin '${plugin.pluginId}' is off; its tools are unavailable.\n\n${result.guidance}` };
|
|
249
281
|
}
|
|
@@ -253,7 +285,88 @@ async function loadPermitted(ctx, { plugin, ...request }, { signal } = {}) {
|
|
|
253
285
|
await publishUsage(ctx);
|
|
254
286
|
return result;
|
|
255
287
|
}
|
|
256
|
-
/**
|
|
288
|
+
/** Draft or reuse this attempt's offer. It may ask for consent or save Auto, but records and publishes nothing.
|
|
289
|
+
* A newer attempt retires the older scope first, so that scope can never commit or offer again.
|
|
290
|
+
*/
|
|
291
|
+
async function offer(ctx, { scope, offerId, input, isAttemptLive }) {
|
|
292
|
+
const current = ctx.offer;
|
|
293
|
+
if (isRetiredGuidanceScope({ scope, current, retired: ctx.retired }))
|
|
294
|
+
refuseGuidance({ reason: 'not-current' });
|
|
295
|
+
if (!(await isAttemptLive(scope, input.signal ? { signal: input.signal } : {})))
|
|
296
|
+
refuseGuidance({ reason: 'not-current' });
|
|
297
|
+
if (current && sameGuidanceScope({ left: current.scope, right: scope })) {
|
|
298
|
+
if (current.offerId !== offerId && current.committed)
|
|
299
|
+
refuseGuidance({ reason: 'not-current' });
|
|
300
|
+
current.offerId = offerId;
|
|
301
|
+
return { offerId, ...current.offer };
|
|
302
|
+
}
|
|
303
|
+
if (current)
|
|
304
|
+
ctx.retired.add(guidanceScopeKey({ scope: current.scope }));
|
|
305
|
+
ctx.offer = undefined;
|
|
306
|
+
const draft = await draftOffer(ctx, { input });
|
|
307
|
+
ctx.offer = { scope: { runId: scope.runId, attempt: scope.attempt, principalId: scope.principalId }, offerId, isAttemptLive, ...draft };
|
|
308
|
+
return { offerId, ...draft.offer };
|
|
309
|
+
}
|
|
310
|
+
/** The legacy query draft without its argument-size skip; pins are read, not added to the delivered set. */
|
|
311
|
+
async function draftOffer(ctx, { input }) {
|
|
312
|
+
const loaded = [...(input.loaded ?? [])];
|
|
313
|
+
if (ctx.mode === 'off' || input.signal?.aborted)
|
|
314
|
+
return { loaded, offered: new Map(), offer: { fullSections: [], fullPrefix: '', catalogPrefix: '' } };
|
|
315
|
+
const { installed, candidates } = await admittedCatalog(ctx);
|
|
316
|
+
const pinned = new Set([...ctx.alreadyLoaded, ...loaded]);
|
|
317
|
+
pruneUnavailablePins({ ctx, pinned, candidates });
|
|
318
|
+
const query = { query: input.query, ...(input.loaded ? { loaded: input.loaded } : {}), ...(input.signal ? { signal: input.signal } : {}) };
|
|
319
|
+
const matches = await consentedMatches({ ctx, candidates, input: query, pinned });
|
|
320
|
+
const sections = await preparedGuidance({ ctx, matches, input: query, pinned });
|
|
321
|
+
// Obtaining consent and resolving bytes do not prove full guidance was selected for delivery;
|
|
322
|
+
// only a matching commit records the sections the host actually delivered.
|
|
323
|
+
const full = sections.filter(section => section.full);
|
|
324
|
+
const notes = (kept, drafted) => withPluginNotes({ ctx, input: query, installed, candidates, result: joinSections({ sections: kept }), drafted });
|
|
325
|
+
return { loaded, offered: new Map(full.map(({ plugin }) => [plugin.pluginId, plugin.displayName ?? plugin.pluginId])), offer: {
|
|
326
|
+
fullSections: full.map(({ plugin, text }) => ({ pluginId: plugin.pluginId, text })),
|
|
327
|
+
fullPrefix: notes(sections, full.map(({ plugin }) => plugin.pluginId)),
|
|
328
|
+
catalogPrefix: notes(sections.filter(section => !section.full), []),
|
|
329
|
+
} };
|
|
330
|
+
}
|
|
331
|
+
/** Record exactly the delivered ids of the current offer, all or nothing.
|
|
332
|
+
* The live-attempt check is the last await before recording, inside the serialized queue.
|
|
333
|
+
*/
|
|
334
|
+
async function commit(ctx, { scope, offerId, deliveredIds }, { signal } = {}) {
|
|
335
|
+
const stored = currentGuidanceOffer({ stored: ctx.offer, scope, offerId });
|
|
336
|
+
if (stored.committed) {
|
|
337
|
+
if (!sameGuidanceChoice({ left: stored.committed.ids, right: deliveredIds }))
|
|
338
|
+
refuseGuidance({ reason: 'replay' });
|
|
339
|
+
await assertAttemptLive({ stored, signal });
|
|
340
|
+
return stored.committed.result;
|
|
341
|
+
}
|
|
342
|
+
assertOfferedChoice({ stored, deliveredIds });
|
|
343
|
+
const { candidates, selected } = await recheckAdmission(ctx, { deliveredIds, signal });
|
|
344
|
+
await assertAttemptLive({ stored, signal });
|
|
345
|
+
for (const id of stored.loaded)
|
|
346
|
+
ctx.alreadyLoaded.add(id);
|
|
347
|
+
if (ctx.mode !== 'off')
|
|
348
|
+
pruneUnavailablePins({ ctx, pinned: ctx.alreadyLoaded, candidates });
|
|
349
|
+
for (const plugin of selected)
|
|
350
|
+
recordDelivery({ ctx, plugin, result: { status: 'loaded', guidance: '' } });
|
|
351
|
+
rememberDelivery(ctx);
|
|
352
|
+
const result = { guidanceIds: currentGuidanceIds(ctx) };
|
|
353
|
+
stored.committed = { ids: [...deliveredIds], result };
|
|
354
|
+
await publishUsage(ctx);
|
|
355
|
+
return result;
|
|
356
|
+
}
|
|
357
|
+
/** Selected ids must still be enabled and not excluded; one unavailable id refuses the whole choice. */
|
|
358
|
+
async function recheckAdmission(ctx, { deliveredIds, signal }) {
|
|
359
|
+
if (signal?.aborted)
|
|
360
|
+
refuseGuidance({ reason: 'cancelled' });
|
|
361
|
+
const { candidates } = await admittedCatalog(ctx);
|
|
362
|
+
const selected = deliveredIds.map(id => candidates.find(plugin => plugin.pluginId === id) ?? refuseGuidance({ reason: 'unavailable' }));
|
|
363
|
+
return { candidates, selected };
|
|
364
|
+
}
|
|
365
|
+
/** Pinned or delivered ids this run can truthfully claim, minus later exclusions. */
|
|
366
|
+
function currentGuidanceIds(ctx) {
|
|
367
|
+
return [...new Set([...ctx.alreadyLoaded, ...ctx.delivered.keys()])].filter(id => !ctx.state.excluded.includes(id));
|
|
368
|
+
}
|
|
369
|
+
/** Share one queue between preflight, offers, commits, explicit reads and simultaneous guarded writes. */
|
|
257
370
|
function enqueue({ ctx, operation }) {
|
|
258
371
|
const next = ctx.queue.then(operation);
|
|
259
372
|
ctx.queue = next.catch(() => undefined);
|
|
@@ -268,11 +381,11 @@ function enqueue({ ctx, operation }) {
|
|
|
268
381
|
export function createAutomaticAgentPluginUse({ mode, state: initialState, ports }, _options = {}) {
|
|
269
382
|
const state = readChatAgentPluginState({ value: initialState });
|
|
270
383
|
const ctx = {
|
|
271
|
-
mode, state, ports, delivered: new Map(), publishedSize: undefined, queue: Promise.resolve(),
|
|
384
|
+
mode, state, ports, delivered: new Map(), publishedSize: undefined, queue: Promise.resolve(), offer: undefined, retired: new Set(),
|
|
272
385
|
alreadyLoaded: new Set(mode === 'off' ? [] : state.decision?.delivered?.filter(id => !state.excluded.includes(id))),
|
|
273
386
|
};
|
|
274
387
|
return {
|
|
275
|
-
guidanceIds: (_required, _options = {}) =>
|
|
388
|
+
guidanceIds: (_required, _options = {}) => currentGuidanceIds(ctx),
|
|
276
389
|
/** Suggest relevant metadata for a query; capability calls load only their providers. */
|
|
277
390
|
prepare: (input, _options = {}) => enqueue({ ctx, operation: () => prepare({ ctx, input }) }),
|
|
278
391
|
/** Resolve one active, permitted id and publish usage only after real guidance is read.
|
|
@@ -280,6 +393,14 @@ export function createAutomaticAgentPluginUse({ mode, state: initialState, ports
|
|
|
280
393
|
* @example await controller.load({ pluginId: 'my-plugin' });
|
|
281
394
|
*/
|
|
282
395
|
load: (input, _options = {}) => enqueue({ ctx, operation: () => load(ctx, input) }),
|
|
396
|
+
/** Draft guidance for one live attempt without recording delivery; the host injects the offer id and liveness check.
|
|
397
|
+
* @example const draft = await controller.offer({ scope, offerId, input: { query }, isAttemptLive });
|
|
398
|
+
*/
|
|
399
|
+
offer: (required, _optional = {}) => enqueue({ ctx, operation: () => offer(ctx, required) }),
|
|
400
|
+
/** Record the offered ids the host actually delivered; a same-choice replay returns the cached result.
|
|
401
|
+
* @example await controller.commit({ scope, offerId, deliveredIds: ['plugin-a'] });
|
|
402
|
+
*/
|
|
403
|
+
commit: (required, optional = {}) => enqueue({ ctx, operation: () => commit(ctx, required, optional) }),
|
|
283
404
|
};
|
|
284
405
|
}
|
|
285
406
|
//# sourceMappingURL=automatic-use.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AgentPluginArchiveReaderPort } from "./install.js";
|
|
2
1
|
import type { AgentPluginLifecyclePorts } from "./ports.js";
|
|
2
|
+
import type { AgentPluginArchiveReaderPort } from "@jini-ai/core/contracts/site/agent-plugins-lifecycle";
|
|
3
3
|
export interface PackedAgentPluginArchive {
|
|
4
4
|
/** Bundled archive bytes, or a 32-byte canonical token requiring the paired archiveReader. */
|
|
5
5
|
readonly bytes: Uint8Array;
|