@jini-ai/core 0.7.1 → 0.7.3-next.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/README.md +40 -12
- package/dist/admin-runtime/admin-api-error.d.ts +68 -0
- package/dist/admin-runtime/admin-api-error.js +72 -0
- package/dist/admin-runtime/admin-config-error.d.ts +8 -0
- package/dist/admin-runtime/admin-config-error.js +11 -0
- package/dist/admin-runtime/controller-store.d.ts +20 -0
- package/dist/admin-runtime/controller-store.js +32 -0
- package/dist/admin-runtime/index.d.ts +13 -0
- package/dist/admin-runtime/index.js +12 -0
- package/dist/admin-runtime/panel-access.d.ts +88 -0
- package/dist/admin-runtime/panel-access.js +76 -0
- package/dist/admin-runtime/query-suffix.d.ts +5 -0
- package/dist/admin-runtime/query-suffix.js +5 -0
- package/dist/agent-handles/element-handles.d.ts +134 -0
- package/dist/agent-handles/element-handles.js +45 -0
- package/dist/agent-handles/field-descriptor.d.ts +28 -0
- package/dist/agent-handles/field-descriptor.js +3 -0
- package/dist/agent-handles/handle.d.ts +109 -0
- package/dist/agent-handles/handle.js +109 -0
- package/dist/agent-handles/index.d.ts +9 -0
- package/dist/agent-handles/index.js +6 -0
- package/dist/agent-handles/list-handles.d.ts +46 -0
- package/dist/agent-handles/list-handles.js +67 -0
- package/dist/agent-handles/secret-attrs.d.ts +14 -0
- package/dist/agent-handles/secret-attrs.js +13 -0
- package/dist/approval-batch-chain.d.ts +45 -0
- package/dist/approval-batch-chain.js +75 -0
- package/dist/approval.d.ts +33 -14
- package/dist/approval.js +57 -43
- package/dist/batch-tool-inputs.js +24 -20
- package/dist/contracts/admin-module.d.ts +166 -0
- package/dist/contracts/admin-module.js +14 -0
- package/dist/contracts/agents/definition.d.ts +459 -0
- package/dist/contracts/agents/definition.js +2 -0
- package/dist/contracts/agents/index.d.ts +7 -0
- package/dist/contracts/agents/index.js +2 -0
- package/dist/contracts/agents/launch.d.ts +64 -0
- package/dist/contracts/agents/launch.js +2 -0
- package/dist/contracts/agents/model-catalog.d.ts +213 -0
- package/dist/contracts/agents/model-catalog.js +4 -0
- package/dist/contracts/agents/native-tool-policy.d.ts +42 -0
- package/dist/contracts/agents/native-tool-policy.js +2 -0
- package/dist/contracts/ai-trace/capture.d.ts +17 -0
- package/dist/contracts/ai-trace/capture.js +43 -0
- package/dist/contracts/ai-trace/classify.d.ts +12 -0
- package/dist/contracts/ai-trace/classify.js +16 -0
- package/dist/contracts/ai-trace/index.d.ts +13 -0
- package/dist/contracts/ai-trace/index.js +6 -0
- package/dist/contracts/ai-trace/recorder.d.ts +64 -0
- package/dist/contracts/ai-trace/recorder.js +283 -0
- package/dist/contracts/ai-trace/sinks.d.ts +51 -0
- package/dist/contracts/ai-trace/sinks.js +153 -0
- package/dist/contracts/ai-trace/types.d.ts +123 -0
- package/dist/contracts/ai-trace/types.js +17 -0
- package/dist/contracts/ai-trace/usage.d.ts +16 -0
- package/dist/contracts/ai-trace/usage.js +45 -0
- package/dist/contracts/blob.d.ts +31 -0
- package/dist/contracts/blob.js +10 -0
- package/dist/contracts/capabilities.d.ts +95 -0
- package/dist/contracts/capabilities.js +111 -0
- package/dist/contracts/charts.d.ts +75 -0
- package/dist/contracts/charts.js +4 -0
- package/dist/contracts/env.d.ts +96 -0
- package/dist/contracts/env.js +6 -0
- package/dist/contracts/events/change-set.d.ts +106 -0
- package/dist/contracts/events/change-set.js +2 -0
- package/dist/contracts/events/command.d.ts +118 -0
- package/dist/contracts/events/command.js +2 -0
- package/dist/contracts/events/ports.d.ts +172 -0
- package/dist/contracts/events/ports.js +2 -0
- package/dist/contracts/events.d.ts +5 -0
- package/dist/contracts/events.js +2 -0
- package/dist/contracts/forms.d.ts +110 -0
- package/dist/contracts/forms.js +4 -0
- package/dist/contracts/hosted-mcp/config.d.ts +19 -0
- package/dist/contracts/hosted-mcp/record.d.ts +61 -4
- package/dist/contracts/mail/email-sender.d.ts +118 -0
- package/dist/contracts/mail/email-sender.js +20 -0
- package/dist/contracts/mail/smtp-payload.d.ts +32 -0
- package/dist/contracts/mail/smtp-payload.js +2 -0
- package/dist/contracts/mail.d.ts +2 -0
- package/dist/contracts/mail.js +1 -1
- package/dist/contracts/observability.d.ts +232 -0
- package/dist/contracts/observability.js +27 -0
- package/dist/contracts/plugin-sdk.d.ts +186 -0
- package/dist/contracts/plugin-sdk.js +39 -0
- package/dist/contracts/runtime/command.d.ts +41 -0
- package/dist/contracts/runtime/command.js +60 -0
- package/dist/contracts/runtime/environment.d.ts +18 -0
- package/dist/contracts/runtime/environment.js +26 -0
- package/dist/contracts/runtime/file-lock.d.ts +94 -0
- package/dist/contracts/runtime/file-lock.js +25 -0
- package/dist/contracts/runtime/fs.d.ts +33 -0
- package/dist/contracts/runtime/fs.js +2 -0
- package/dist/contracts/runtime/http.d.ts +89 -0
- package/dist/contracts/runtime/http.js +2 -0
- package/dist/contracts/runtime/platform.d.ts +3 -0
- package/dist/contracts/runtime/platform.js +2 -0
- package/dist/contracts/runtime/process.d.ts +40 -0
- package/dist/contracts/runtime/process.js +31 -0
- package/dist/contracts/runtime/reader.d.ts +11 -0
- package/dist/contracts/runtime/reader.js +2 -0
- package/dist/contracts/runtime/terminal.d.ts +99 -0
- package/dist/contracts/runtime/terminal.js +2 -0
- package/dist/contracts/runtime/testing.d.ts +84 -0
- package/dist/contracts/runtime/testing.js +116 -0
- package/dist/contracts/runtime.d.ts +10 -0
- package/dist/contracts/runtime.js +10 -0
- package/dist/contracts/server/api-error.d.ts +43 -0
- package/dist/contracts/server/api-error.js +49 -0
- package/dist/contracts/server/auth.d.ts +20 -0
- package/dist/contracts/server/auth.js +21 -0
- package/dist/contracts/server/conformance.d.ts +25 -0
- package/dist/contracts/server/conformance.js +50 -0
- package/dist/contracts/server/json-route.d.ts +176 -0
- package/dist/contracts/server/json-route.js +155 -0
- package/dist/contracts/server/middleware.d.ts +35 -0
- package/dist/contracts/server/middleware.js +56 -0
- package/dist/contracts/server/origin.d.ts +44 -0
- package/dist/contracts/server/origin.js +32 -0
- package/dist/contracts/server/query.d.ts +16 -0
- package/dist/contracts/server/query.js +69 -0
- package/dist/contracts/server/rate-limit.d.ts +20 -0
- package/dist/contracts/server/rate-limit.js +8 -0
- package/dist/contracts/server/request-body.d.ts +26 -0
- package/dist/contracts/server/request-body.js +82 -0
- package/dist/contracts/server/result.d.ts +17 -0
- package/dist/contracts/server/result.js +5 -0
- package/dist/contracts/server/route-table.d.ts +54 -0
- package/dist/contracts/server/route-table.js +119 -0
- package/dist/contracts/server/same-origin-write.d.ts +18 -0
- package/dist/contracts/server/same-origin-write.js +31 -0
- package/dist/contracts/server/security-headers.d.ts +30 -0
- package/dist/contracts/server/security-headers.js +35 -0
- package/dist/contracts/server/sse.d.ts +82 -0
- package/dist/contracts/server/sse.js +103 -0
- package/dist/contracts/server/testing.d.ts +59 -0
- package/dist/contracts/server/testing.js +68 -0
- package/dist/contracts/server/verified-origin/configured-origin.d.ts +37 -0
- package/dist/contracts/server/verified-origin/configured-origin.js +103 -0
- package/dist/contracts/server/verified-origin/index.d.ts +7 -0
- package/dist/contracts/server/verified-origin/index.js +6 -0
- package/dist/contracts/server/verified-origin/loopback-host.d.ts +9 -0
- package/dist/contracts/server/verified-origin/loopback-host.js +17 -0
- package/dist/contracts/server/verified-origin/origin.d.ts +64 -0
- package/dist/contracts/server/verified-origin/origin.js +162 -0
- package/dist/contracts/server/verified-origin/ports.d.ts +38 -0
- package/dist/contracts/server/verified-origin/ports.js +2 -0
- package/dist/contracts/server/verified-origin/repo.memory.d.ts +32 -0
- package/dist/contracts/server/verified-origin/repo.memory.js +34 -0
- package/dist/contracts/server/verified-origin/site-path.d.ts +113 -0
- package/dist/contracts/server/verified-origin/site-path.js +188 -0
- package/dist/contracts/server/verified-origin/types.d.ts +33 -0
- package/dist/contracts/server/verified-origin/types.js +30 -0
- package/dist/contracts/server.d.ts +46 -2
- package/dist/contracts/server.js +17 -3
- package/dist/contracts/storage/kernel.d.ts +86 -0
- package/dist/contracts/storage/kernel.js +38 -0
- package/dist/contracts/storage/migration.d.ts +32 -0
- package/dist/contracts/storage/migration.js +2 -0
- package/dist/contracts/storage/rows.d.ts +33 -0
- package/dist/contracts/storage/rows.js +42 -0
- package/dist/contracts/storage/sqlite.d.ts +113 -0
- package/dist/contracts/storage/sqlite.js +8 -0
- package/dist/contracts/storage/values.d.ts +25 -0
- package/dist/contracts/storage/values.js +25 -0
- package/dist/contracts/storage.d.ts +8 -0
- package/dist/contracts/storage.js +6 -0
- package/dist/contracts/vault/invariants.d.ts +26 -0
- package/dist/contracts/vault/invariants.js +49 -0
- package/dist/contracts/vault.d.ts +1 -0
- package/dist/contracts/vault.js +1 -1
- package/dist/env/coercers.d.ts +21 -0
- package/dist/env/coercers.js +68 -0
- package/dist/env/describe-env-for-diagnostics.d.ts +16 -0
- package/dist/env/describe-env-for-diagnostics.js +23 -0
- package/dist/env/format-env-issue.d.ts +13 -0
- package/dist/env/format-env-issue.js +22 -0
- package/dist/env/parse-env.d.ts +24 -0
- package/dist/env/parse-env.js +102 -0
- package/dist/env/value-echo.d.ts +17 -0
- package/dist/env/value-echo.js +42 -0
- package/dist/errors/approved-cause.d.ts +36 -0
- package/dist/errors/approved-cause.js +17 -0
- package/dist/errors/bindings.d.ts +61 -0
- package/dist/errors/bindings.js +57 -0
- package/dist/errors/catalog.d.ts +84 -0
- package/dist/errors/catalog.js +151 -0
- package/dist/errors/disclosure.d.ts +48 -0
- package/dist/errors/disclosure.js +27 -0
- package/dist/errors/error-id.d.ts +26 -0
- package/dist/errors/error-id.js +23 -0
- package/dist/errors/idioms.d.ts +73 -0
- package/dist/errors/idioms.js +85 -0
- package/dist/errors/incident-text.d.ts +16 -0
- package/dist/errors/incident-text.js +77 -0
- package/dist/errors/reporter.d.ts +94 -0
- package/dist/errors/reporter.js +152 -0
- package/dist/errors/sentences.d.ts +68 -0
- package/dist/errors/sentences.js +93 -0
- package/dist/errors/testing.d.ts +50 -0
- package/dist/errors/testing.js +44 -0
- package/dist/fetch/cache.d.ts +12 -5
- package/dist/fetch/cache.js +46 -47
- package/dist/fetch/index.d.ts +1 -1
- package/dist/fetch/loader-read.d.ts +6 -2
- package/dist/fetch/loader-read.js +4 -4
- package/dist/format-error-for-log.d.ts +15 -0
- package/dist/format-error-for-log.js +55 -0
- package/dist/host-read-vocabulary.d.ts +47 -0
- package/dist/host-read-vocabulary.js +44 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -0
- package/dist/list-page.d.ts +93 -0
- package/dist/list-page.js +154 -0
- package/dist/model-facing-tool-errors.d.ts +67 -5
- package/dist/model-facing-tool-errors.js +155 -19
- package/dist/net/endpoint-policy.d.ts +39 -0
- package/dist/net/endpoint-policy.js +218 -0
- package/dist/net/fetch-timeouts.d.ts +38 -0
- package/dist/net/fetch-timeouts.js +31 -0
- package/dist/net/index.d.ts +4 -0
- package/dist/net/index.js +4 -0
- package/dist/net/loopback.d.ts +13 -0
- package/dist/net/loopback.js +39 -0
- package/dist/optimistic-concurrency.d.ts +183 -0
- package/dist/optimistic-concurrency.js +222 -0
- package/dist/primitives/errors.d.ts +9 -0
- package/dist/primitives/errors.js +12 -0
- package/dist/primitives/ids.d.ts +0 -2
- package/dist/primitives/ids.js +1 -4
- package/dist/primitives/index.d.ts +3 -0
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/logger.d.ts +36 -1
- package/dist/primitives/logger.js +125 -9
- package/dist/primitives/node-shape.d.ts +24 -0
- package/dist/primitives/node-shape.js +21 -0
- package/dist/primitives/time.d.ts +9 -2
- package/dist/primitives/time.js +4 -3
- package/dist/provider-registry.js +26 -20
- package/dist/records.d.ts +40 -7
- package/dist/records.js +37 -3
- package/dist/redact.d.ts +1 -84
- package/dist/redact.js +2 -826
- package/dist/redaction-collectors.d.ts +7 -0
- package/dist/redaction-collectors.js +152 -0
- package/dist/redaction-exact-secrets.d.ts +14 -0
- package/dist/redaction-exact-secrets.js +115 -0
- package/dist/redaction-labels.d.ts +14 -0
- package/dist/redaction-labels.js +156 -0
- package/dist/redaction-patterns.d.ts +54 -0
- package/dist/redaction-patterns.js +178 -0
- package/dist/redaction-spans.d.ts +31 -0
- package/dist/redaction-spans.js +83 -0
- package/dist/registration-kit.d.ts +1 -1
- package/dist/revision-conflict-error.d.ts +18 -0
- package/dist/revision-conflict-error.js +20 -0
- package/dist/secret-shapes.d.ts +50 -0
- package/dist/secret-shapes.js +105 -0
- package/dist/settings/agent-tools.js +22 -8
- package/dist/settings/agent-value-write-tools.d.ts +4 -1
- package/dist/settings/agent-value-write-tools.js +7 -6
- package/dist/settings/agent-writable-preferences.d.ts +3 -1
- package/dist/settings/agent-writable-preferences.js +1 -1
- package/dist/settings/agent-write-denylist.d.ts +7 -4
- package/dist/settings/agent-write-denylist.js +1 -1
- package/dist/settings/{express/cms-adapter.d.ts → cms-adapter.d.ts} +3 -2
- package/dist/settings/{express/cms-adapter.js → cms-adapter.js} +21 -11
- package/dist/settings/definitions-dispatch.js +3 -1
- package/dist/settings/ensure-definitions.js +3 -1
- package/dist/settings/errors.d.ts +1 -13
- package/dist/settings/errors.js +2 -15
- package/dist/settings/index.d.ts +11 -2
- package/dist/settings/index.js +10 -2
- package/dist/settings/purge-service.js +63 -86
- package/dist/settings/{express/contracts.d.ts → route-policy.d.ts} +53 -47
- package/dist/settings/{express/shared.js → route-policy.js} +1 -16
- package/dist/settings/settings.d.ts +19 -11
- package/dist/settings/settings.js +9 -11
- package/dist/settings/tool-registrations.d.ts +3 -3
- package/dist/settings/tool-registrations.js +130 -125
- package/dist/settings/types.d.ts +1 -1
- package/dist/settings/write-definition-rename.d.ts +37 -0
- package/dist/settings/write-definition-rename.js +119 -0
- package/dist/settings/write-definition-retype.d.ts +61 -0
- package/dist/settings/write-definition-retype.js +109 -0
- package/dist/settings/write-definition-status.d.ts +81 -0
- package/dist/settings/write-definition-status.js +121 -0
- package/dist/settings/write-reset.d.ts +34 -0
- package/dist/settings/write-reset.js +73 -0
- package/dist/settings/write-service.d.ts +16 -287
- package/dist/settings/write-service.js +49 -681
- package/dist/settings/write-value-revisions.d.ts +68 -0
- package/dist/settings/write-value-revisions.js +124 -0
- package/dist/settings/write-values.d.ts +96 -0
- package/dist/settings/write-values.js +83 -0
- package/dist/surface-exchanges.d.ts +2 -2
- package/dist/text/dictionary-translator.d.ts +19 -0
- package/dist/text/dictionary-translator.js +14 -0
- package/dist/text/format-byte-size.d.ts +25 -0
- package/dist/text/format-byte-size.js +25 -0
- package/dist/text/format-timestamp.d.ts +22 -0
- package/dist/text/format-timestamp.js +57 -0
- package/dist/text/index.d.ts +12 -0
- package/dist/text/index.js +9 -0
- package/dist/text/is-abort-error.d.ts +5 -0
- package/dist/text/is-abort-error.js +5 -0
- package/dist/text/mime.d.ts +5 -0
- package/dist/text/mime.js +21 -0
- package/dist/text/redact-urls.d.ts +7 -0
- package/dist/text/redact-urls.js +5 -0
- package/dist/text/resolve-active-tab-id.d.ts +13 -0
- package/dist/text/resolve-active-tab-id.js +15 -0
- package/dist/text/sanitize-untrusted-text.d.ts +1 -1
- package/dist/text/sanitize-untrusted-text.js +2 -1
- package/dist/text/tagged-text-suppression.d.ts +103 -0
- package/dist/text/tagged-text-suppression.js +143 -0
- package/dist/text/template-i18n.d.ts +37 -0
- package/dist/text/template-i18n.js +48 -0
- package/dist/tool-call-text.d.ts +59 -0
- package/dist/tool-call-text.js +62 -0
- package/dist/tool-input-envelope.js +8 -4
- package/dist/tool-input-normalization.js +8 -1
- package/dist/tool-input-repairs.d.ts +58 -0
- package/dist/tool-input-repairs.js +154 -0
- package/dist/tool-tokens.js +1 -1
- package/dist/user-facing-error.d.ts +1 -1
- package/dist/user-facing-error.js +3 -1
- package/package.json +234 -13
- package/dist/settings/express/contracts.js +0 -2
- package/dist/settings/express/http-request.d.ts +0 -33
- package/dist/settings/express/http-request.js +0 -50
- package/dist/settings/express/http.d.ts +0 -10
- package/dist/settings/express/http.js +0 -196
- package/dist/settings/express/index.d.ts +0 -5
- package/dist/settings/express/index.js +0 -4
- package/dist/settings/express/shared.d.ts +0 -68
- package/dist/settings/express/stream.d.ts +0 -24
- package/dist/settings/express/stream.js +0 -171
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createApprovalHandler, expandBatchContexts } from './approval.js';
|
|
2
|
+
import { DEFAULT_MAX_BATCH_ITEMS } from './batch-tool-inputs.js';
|
|
3
|
+
import { requireInputRecord } from './registration-kit.js';
|
|
4
|
+
import { ToolInputError } from './tool-input-errors.js';
|
|
5
|
+
/** The version an item runs with: its prepare-time pin, or the successor of the last item that
|
|
6
|
+
* wrote the same target in this call. */
|
|
7
|
+
function pinnedFor({ steps, entry, applied }) {
|
|
8
|
+
if (!applied)
|
|
9
|
+
return entry.prepared;
|
|
10
|
+
return steps.successor({ prepared: entry.prepared, committed: applied.committed, previous: applied.prepared });
|
|
11
|
+
}
|
|
12
|
+
/** Run the entries in order. A failed item skips the later items for its own target only. */
|
|
13
|
+
async function runChain({ steps, entries, noun }, options) {
|
|
14
|
+
const results = [];
|
|
15
|
+
const applied = new Map();
|
|
16
|
+
const failed = new Set();
|
|
17
|
+
for (const [index, entry] of entries.entries()) {
|
|
18
|
+
if (entry.ctx.signal.aborted)
|
|
19
|
+
throw abandoned();
|
|
20
|
+
const key = steps.targetKey({ prepared: entry.prepared });
|
|
21
|
+
if (failed.has(key)) {
|
|
22
|
+
results.push({ index, ok: false, error: `Skipped: an earlier change to this ${noun} in the same call failed.` });
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const prepared = pinnedFor({ steps, entry, applied: applied.get(key) });
|
|
27
|
+
const { output, committed } = await steps.run({ ctx: entry.ctx, prepared }, options);
|
|
28
|
+
applied.set(key, { prepared, committed });
|
|
29
|
+
results.push({ index, ok: true, result: output });
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
failed.add(key);
|
|
33
|
+
results.push({ index, ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return results;
|
|
37
|
+
}
|
|
38
|
+
/** The wording of the existing direct batch when the call is cancelled. */
|
|
39
|
+
function abandoned() {
|
|
40
|
+
return new ToolInputError({ message: 'This tool call was abandoned before the next change. Retry the remaining changes when ready.' });
|
|
41
|
+
}
|
|
42
|
+
/** A direct (never asking) batch whose items for the same target apply in order, each pinned to the
|
|
43
|
+
* version the batch's own previous write committed. Reuses the approval owner's input snapshot, item
|
|
44
|
+
* cap, duplicate detection and cancellation checks. A single call returns `run`'s output unchanged;
|
|
45
|
+
* a batch returns `{ batch: true, total, results }` so `batchOutcomeFor` reports partial failures.
|
|
46
|
+
* `createBatchApprovalHandler` is untouched: a person approved a description computed from the first bytes.
|
|
47
|
+
* @param optional.targetNoun What the target is called in the "Skipped" sentence. Default `target`.
|
|
48
|
+
* @throws ToolInputError for malformed, duplicate or over-cap batches and for cancellation; `prepare`
|
|
49
|
+
* failures propagate; a single call's `run` failure propagates; a batch item's failure is its result.
|
|
50
|
+
* @complexity O(input bytes) plus bounded host effects; no reads by core.
|
|
51
|
+
* @example createChainedBatchHandler({ prepare, run, targetKey, successor }, { targetNoun: 'file' });
|
|
52
|
+
*/
|
|
53
|
+
export function createChainedBatchHandler(required, { maxItems = DEFAULT_MAX_BATCH_ITEMS, targetNoun = 'target' } = {}) {
|
|
54
|
+
return createApprovalHandler({
|
|
55
|
+
prepare: async ({ ctx }, options) => {
|
|
56
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
57
|
+
if (!Object.hasOwn(input, 'items'))
|
|
58
|
+
return { batch: false, entries: [{ ctx, prepared: await required.prepare({ ctx }, options) }] };
|
|
59
|
+
const entries = [];
|
|
60
|
+
for (const itemCtx of expandBatchContexts({ ctx, input, maxItems }))
|
|
61
|
+
entries.push({ ctx: itemCtx, prepared: await required.prepare({ ctx: itemCtx }, options) });
|
|
62
|
+
return { batch: true, entries };
|
|
63
|
+
},
|
|
64
|
+
describe: () => ({ ask: false, description: undefined }),
|
|
65
|
+
askHuman: async () => { throw new Error('Direct batches have no approval transport'); },
|
|
66
|
+
notConfirmed: () => { throw abandoned(); },
|
|
67
|
+
run: async ({ prepared }, options) => {
|
|
68
|
+
if (!prepared.batch)
|
|
69
|
+
return (await required.run(prepared.entries[0], options)).output;
|
|
70
|
+
const results = await runChain({ steps: required, entries: prepared.entries, noun: targetNoun }, options);
|
|
71
|
+
return { batch: true, total: results.length, results };
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=approval-batch-chain.js.map
|
package/dist/approval.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import { type HumanConfirmer } from './registration-kit.js';
|
|
1
|
+
import { requireInputRecord, type HumanConfirmer } from './registration-kit.js';
|
|
2
2
|
import type { ToolExecutionContext, ToolExecutionOptions, ToolHandler, ToolRegistration } from './tool-registry.js';
|
|
3
|
+
import type { IdGenerator } from './primitives/ids.js';
|
|
4
|
+
/** Host-supplied timer port so the approval wait never touches ambient timers. */
|
|
5
|
+
export interface ApprovalSchedulerPort {
|
|
6
|
+
schedule(required: {
|
|
7
|
+
callback: () => void;
|
|
8
|
+
delayMs: number;
|
|
9
|
+
}): unknown;
|
|
10
|
+
cancel(required: {
|
|
11
|
+
handle: unknown;
|
|
12
|
+
}): void;
|
|
13
|
+
}
|
|
3
14
|
/** Maximum human approval wait for one invocation, independent of execution time. */
|
|
4
15
|
export declare const APPROVAL_WAIT_TIMEOUT_MS = 120000;
|
|
5
16
|
/** An exact access change. The host rechecks this revision and authority before applying it. */
|
|
@@ -125,6 +136,12 @@ export declare function createApprovalHandler<TPrepared, TDescription>(steps: Ap
|
|
|
125
136
|
export declare function createPreparedBatchHandler<TPrepared>(steps: Pick<ApprovalSteps<TPrepared, undefined>, 'prepare' | 'run'>, options?: {
|
|
126
137
|
maxItems?: number;
|
|
127
138
|
}): ToolHandler;
|
|
139
|
+
/** Expand `items` into one context per item (shared fields as defaults), validating cap, nesting and duplicates. */
|
|
140
|
+
export declare function expandBatchContexts({ ctx, input, maxItems }: {
|
|
141
|
+
ctx: ToolExecutionContext;
|
|
142
|
+
input: ReturnType<typeof requireInputRecord>;
|
|
143
|
+
maxItems: number;
|
|
144
|
+
}): ToolExecutionContext[];
|
|
128
145
|
/** Prepare every item before asking once for the complete batch. Reuses the single-call approval
|
|
129
146
|
* lifecycle, including its detached inputs, authenticated confirmer and abort checks.
|
|
130
147
|
* Single inputs preserve their result shape. Batch effects run in order and stop on the first
|
|
@@ -140,6 +157,13 @@ export declare function createBatchApprovalHandler<TPrepared, TDescription>({ st
|
|
|
140
157
|
}, { maxItems }?: {
|
|
141
158
|
maxItems?: number;
|
|
142
159
|
}): ToolHandler;
|
|
160
|
+
type ProposalSnapshot<TDescription> = {
|
|
161
|
+
pending: {
|
|
162
|
+
approvalId: string;
|
|
163
|
+
description: TDescription;
|
|
164
|
+
} | null;
|
|
165
|
+
error: string | null;
|
|
166
|
+
};
|
|
143
167
|
/** Page-local proposal transport for a browser that must return before its explicit reply arrives.
|
|
144
168
|
* It carries no principal or tool authorization: the host's execute port must re-check access.
|
|
145
169
|
* The private action is independent of the rendered snapshot; replies consume it before awaiting
|
|
@@ -147,29 +171,23 @@ export declare function createBatchApprovalHandler<TPrepared, TDescription>({ st
|
|
|
147
171
|
* @returns An observable transport for an app dialog and its authenticated reply entry point.
|
|
148
172
|
* @complexity O(description size) to detach the proposal; O(listeners) to publish a change.
|
|
149
173
|
*/
|
|
150
|
-
export declare function createApprovalProposalStore<TDescription>({ responseTool, messages }: {
|
|
174
|
+
export declare function createApprovalProposalStore<TDescription>({ responseTool, messages, ids, scheduler }: {
|
|
151
175
|
responseTool: string;
|
|
152
176
|
messages: {
|
|
153
177
|
closed: string;
|
|
154
178
|
pending: string;
|
|
155
179
|
missing: string;
|
|
156
180
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}): {
|
|
160
|
-
request: (
|
|
181
|
+
ids: IdGenerator;
|
|
182
|
+
scheduler: ApprovalSchedulerPort;
|
|
183
|
+
}, _optional?: {}): {
|
|
184
|
+
request: (required: {
|
|
161
185
|
description: TDescription;
|
|
162
186
|
signal: AbortSignal;
|
|
163
|
-
},
|
|
187
|
+
}, optional?: {
|
|
164
188
|
timeoutMs?: number;
|
|
165
189
|
}) => Promise<ApprovalAnswer>;
|
|
166
|
-
getSnapshot: (_required?: {}, _optional?: {}) =>
|
|
167
|
-
pending: {
|
|
168
|
-
approvalId: string;
|
|
169
|
-
description: TDescription;
|
|
170
|
-
} | null;
|
|
171
|
-
error: string | null;
|
|
172
|
-
};
|
|
190
|
+
getSnapshot: (_required?: {}, _optional?: {}) => ProposalSnapshot<TDescription>;
|
|
173
191
|
subscribe: ({ listener }: {
|
|
174
192
|
listener: () => void;
|
|
175
193
|
}, _optional?: {}) => () => void;
|
|
@@ -218,4 +236,5 @@ export declare function applyApprovalPolicy<TDescription>({ registration, classi
|
|
|
218
236
|
remembered?: RememberedApprovalPort;
|
|
219
237
|
context?: ApprovalContextPort;
|
|
220
238
|
}): ToolRegistration;
|
|
239
|
+
export {};
|
|
221
240
|
//# sourceMappingURL=approval.d.ts.map
|
package/dist/approval.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { humanConfirmedHandler, requireInputRecord } from './registration-kit.js';
|
|
2
2
|
import { ToolInputError } from './tool-registry.js';
|
|
3
|
+
import { describeErrorForLog } from './model-facing-tool-errors.js';
|
|
3
4
|
import { isNonArrayRecord } from './records.js';
|
|
4
5
|
/** Maximum human approval wait for one invocation, independent of execution time. */
|
|
5
6
|
export const APPROVAL_WAIT_TIMEOUT_MS = 120_000;
|
|
@@ -40,6 +41,16 @@ export async function resolveApproval({ signal, askHuman }, { onApprovalStateCha
|
|
|
40
41
|
}
|
|
41
42
|
/** The confirmer is always the run's own delegating principal, as a user. */
|
|
42
43
|
const confirmerOf = (ctx) => ({ id: ctx.principal.id, kind: 'user' });
|
|
44
|
+
/** Detach the input and actor identity so no later mutation by the caller reaches the approval. */
|
|
45
|
+
function detachToolContext({ ctx }) {
|
|
46
|
+
return { ...ctx, input: structuredClone(ctx.input), principal: { ...ctx.principal }, run: { ...ctx.run } };
|
|
47
|
+
}
|
|
48
|
+
/** Access plans carry a resource list the host renders; snapshot it so it cannot drift after review. */
|
|
49
|
+
function detachApprovalPlan({ plan }) {
|
|
50
|
+
return plan.kind === 'access'
|
|
51
|
+
? { ...structuredClone(plan), access: snapshotAccessApproval({ access: plan.access }) }
|
|
52
|
+
: plan;
|
|
53
|
+
}
|
|
43
54
|
/** Extend the branded human-confirm owner with descriptions and optional remembered grants.
|
|
44
55
|
* Inputs and actor identity are detached before any asynchronous port runs. No input field can
|
|
45
56
|
* approve an action; only the host transport or the bound grant store can answer. Abort checks
|
|
@@ -72,17 +83,14 @@ export function createApprovalHandler(steps, { remembered } = {}) {
|
|
|
72
83
|
};
|
|
73
84
|
return humanConfirmedHandler({
|
|
74
85
|
prepare: async ({ ctx }, options = {}) => {
|
|
75
|
-
const snapshot =
|
|
86
|
+
const snapshot = detachToolContext({ ctx });
|
|
76
87
|
if (snapshot.signal.aborted)
|
|
77
88
|
return { ctx: snapshot };
|
|
78
89
|
const value = await steps.prepare({ ctx: snapshot }, options);
|
|
79
90
|
if (snapshot.signal.aborted)
|
|
80
91
|
return { ctx: snapshot, value };
|
|
81
92
|
const description = await steps.describe({ ctx: snapshot, prepared: value }, options);
|
|
82
|
-
|
|
83
|
-
? { ...structuredClone(description), access: snapshotAccessApproval({ access: description.access }) }
|
|
84
|
-
: description;
|
|
85
|
-
return { ctx: snapshot, value, plan };
|
|
93
|
+
return { ctx: snapshot, value, plan: detachApprovalPlan({ plan: description }) };
|
|
86
94
|
},
|
|
87
95
|
askHuman: async ({ prepared }, options = {}) => {
|
|
88
96
|
const { ctx, plan } = prepared;
|
|
@@ -122,6 +130,24 @@ export function createPreparedBatchHandler(steps, options = {}) {
|
|
|
122
130
|
notConfirmed: ({ reason }) => { throw new ToolInputError({ message: `This tool call was ${reason} before the next change. Retry the remaining changes when ready.` }); },
|
|
123
131
|
}, combineDescriptions: () => undefined }, options);
|
|
124
132
|
}
|
|
133
|
+
/** Expand `items` into one context per item (shared fields as defaults), validating cap, nesting and duplicates. */
|
|
134
|
+
export function expandBatchContexts({ ctx, input, maxItems }) {
|
|
135
|
+
const { items, ...defaults } = input;
|
|
136
|
+
if (!Array.isArray(items) || items.length < 1 || items.length > maxItems) {
|
|
137
|
+
throw new ToolInputError({ message: `items must contain between 1 and ${maxItems} inputs.` });
|
|
138
|
+
}
|
|
139
|
+
const contexts = items.map(item => {
|
|
140
|
+
const fields = requireInputRecord({ input: item });
|
|
141
|
+
if (Object.hasOwn(fields, 'items'))
|
|
142
|
+
throw new ToolInputError({ message: 'Nested items batches are not supported.' });
|
|
143
|
+
return { ...ctx, input: { ...defaults, ...fields } };
|
|
144
|
+
});
|
|
145
|
+
// These boundary inputs are records; sorting their keys also catches reordered scalar ids.
|
|
146
|
+
const keys = contexts.map(({ input: itemInput }) => JSON.stringify(Object.entries(itemInput).sort(([a], [b]) => a.localeCompare(b))));
|
|
147
|
+
if (new Set(keys).size !== keys.length)
|
|
148
|
+
throw new ToolInputError({ message: 'Duplicate batch inputs are not allowed.' });
|
|
149
|
+
return contexts;
|
|
150
|
+
}
|
|
125
151
|
/** Prepare every item before asking once for the complete batch. Reuses the single-call approval
|
|
126
152
|
* lifecycle, including its detached inputs, authenticated confirmer and abort checks.
|
|
127
153
|
* Single inputs preserve their result shape. Batch effects run in order and stop on the first
|
|
@@ -135,20 +161,7 @@ export function createBatchApprovalHandler({ steps, combineDescriptions }, { max
|
|
|
135
161
|
const input = requireInputRecord({ input: ctx.input });
|
|
136
162
|
if (!Object.hasOwn(input, 'items'))
|
|
137
163
|
return { batch: false, entries: [{ ctx, prepared: await steps.prepare({ ctx }, options) }] };
|
|
138
|
-
const {
|
|
139
|
-
if (!Array.isArray(items) || items.length < 1 || items.length > maxItems) {
|
|
140
|
-
throw new ToolInputError({ message: `items must contain between 1 and ${maxItems} inputs.` });
|
|
141
|
-
}
|
|
142
|
-
const contexts = items.map(item => {
|
|
143
|
-
const fields = requireInputRecord({ input: item });
|
|
144
|
-
if (Object.hasOwn(fields, 'items'))
|
|
145
|
-
throw new ToolInputError({ message: 'Nested items batches are not supported.' });
|
|
146
|
-
return { ...ctx, input: { ...defaults, ...fields } };
|
|
147
|
-
});
|
|
148
|
-
// These boundary inputs are records; sorting their keys also catches reordered scalar ids.
|
|
149
|
-
const keys = contexts.map(({ input }) => JSON.stringify(Object.entries(input).sort(([a], [b]) => a.localeCompare(b))));
|
|
150
|
-
if (new Set(keys).size !== keys.length)
|
|
151
|
-
throw new ToolInputError({ message: 'Duplicate batch inputs are not allowed.' });
|
|
164
|
+
const contexts = expandBatchContexts({ ctx, input, maxItems });
|
|
152
165
|
const entries = [];
|
|
153
166
|
for (const itemCtx of contexts)
|
|
154
167
|
entries.push({ ctx: itemCtx, prepared: await steps.prepare({ ctx: itemCtx }, options) });
|
|
@@ -182,6 +195,27 @@ export function createBatchApprovalHandler({ steps, combineDescriptions }, { max
|
|
|
182
195
|
notConfirmed: ({ reason, prepared }) => steps.notConfirmed({ reason, prepared: prepared?.batch ? undefined : prepared?.entries[0]?.prepared }),
|
|
183
196
|
});
|
|
184
197
|
}
|
|
198
|
+
/** Park a call on a proposal store without publishing any assistant reply capability. The app
|
|
199
|
+
* dialog alone may decide it. Expiry/abort consume the proposal before resolving the waiter. */
|
|
200
|
+
async function requestAppDialogDecision({ proposer, scheduler, description, signal }, { timeoutMs = APPROVAL_WAIT_TIMEOUT_MS } = {}) {
|
|
201
|
+
const lifetime = new AbortController();
|
|
202
|
+
const abort = () => lifetime.abort();
|
|
203
|
+
if (signal.aborted)
|
|
204
|
+
return { confirmed: false, reason: 'abandoned' };
|
|
205
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
206
|
+
let expired = false;
|
|
207
|
+
const handle = scheduler.schedule({ callback: () => { expired = true; lifetime.abort(); }, delayMs: timeoutMs });
|
|
208
|
+
try {
|
|
209
|
+
return await resolveApproval({ signal: lifetime.signal, askHuman: () => new Promise(resolve => {
|
|
210
|
+
proposer.propose({ description, signal: lifetime.signal, execute: async () => undefined }, { humanOnly: true, decide: resolve });
|
|
211
|
+
}) }).then(answer => expired ? { confirmed: false, reason: 'expired' } : answer);
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
scheduler.cancel({ handle });
|
|
215
|
+
signal.removeEventListener('abort', abort);
|
|
216
|
+
lifetime.abort();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
185
219
|
/** Page-local proposal transport for a browser that must return before its explicit reply arrives.
|
|
186
220
|
* It carries no principal or tool authorization: the host's execute port must re-check access.
|
|
187
221
|
* The private action is independent of the rendered snapshot; replies consume it before awaiting
|
|
@@ -189,7 +223,7 @@ export function createBatchApprovalHandler({ steps, combineDescriptions }, { max
|
|
|
189
223
|
* @returns An observable transport for an app dialog and its authenticated reply entry point.
|
|
190
224
|
* @complexity O(description size) to detach the proposal; O(listeners) to publish a change.
|
|
191
225
|
*/
|
|
192
|
-
export function createApprovalProposalStore({ responseTool, messages
|
|
226
|
+
export function createApprovalProposalStore({ responseTool, messages, ids, scheduler }, _optional = {}) {
|
|
193
227
|
let snapshot = { pending: null, error: null };
|
|
194
228
|
let action = null;
|
|
195
229
|
let detach = null;
|
|
@@ -221,7 +255,7 @@ export function createApprovalProposalStore({ responseTool, messages }, { create
|
|
|
221
255
|
if (snapshot.pending)
|
|
222
256
|
throw new Error(messages.pending);
|
|
223
257
|
const frozenDescription = structuredClone(description);
|
|
224
|
-
const approvalId =
|
|
258
|
+
const approvalId = ids.newId();
|
|
225
259
|
action = { approvalId, execute, signal, humanOnly, ...(decide ? { decide } : {}) };
|
|
226
260
|
const abort = () => clear();
|
|
227
261
|
signal.addEventListener('abort', abort, { once: true });
|
|
@@ -242,32 +276,12 @@ export function createApprovalProposalStore({ responseTool, messages }, { create
|
|
|
242
276
|
return await prepared.execute();
|
|
243
277
|
}
|
|
244
278
|
catch (error) {
|
|
245
|
-
publish({ ...snapshot, error:
|
|
279
|
+
publish({ ...snapshot, error: `The approved action stopped with an error (${describeErrorForLog({ err: error })}).` });
|
|
246
280
|
throw error;
|
|
247
281
|
}
|
|
248
282
|
},
|
|
249
283
|
};
|
|
250
|
-
|
|
251
|
-
* dialog alone may decide it. Expiry/abort consume the proposal before resolving the waiter. */
|
|
252
|
-
async function request({ description, signal }, { timeoutMs = APPROVAL_WAIT_TIMEOUT_MS } = {}) {
|
|
253
|
-
const lifetime = new AbortController();
|
|
254
|
-
const abort = () => lifetime.abort();
|
|
255
|
-
if (signal.aborted)
|
|
256
|
-
return { confirmed: false, reason: 'abandoned' };
|
|
257
|
-
signal.addEventListener('abort', abort, { once: true });
|
|
258
|
-
let expired = false;
|
|
259
|
-
const timer = setTimeout(() => { expired = true; lifetime.abort(); }, timeoutMs);
|
|
260
|
-
try {
|
|
261
|
-
return await resolveApproval({ signal: lifetime.signal, askHuman: () => new Promise(resolve => {
|
|
262
|
-
store.propose({ description, signal: lifetime.signal, execute: async () => undefined }, { humanOnly: true, decide: resolve });
|
|
263
|
-
}) }).then(answer => expired ? { confirmed: false, reason: 'expired' } : answer);
|
|
264
|
-
}
|
|
265
|
-
finally {
|
|
266
|
-
clearTimeout(timer);
|
|
267
|
-
signal.removeEventListener('abort', abort);
|
|
268
|
-
lifetime.abort();
|
|
269
|
-
}
|
|
270
|
-
}
|
|
284
|
+
const request = (required, optional = {}) => requestAppDialogDecision({ proposer: store, scheduler, ...required }, optional);
|
|
271
285
|
return { ...store, request };
|
|
272
286
|
}
|
|
273
287
|
/** Apply a host classification through the same handler owner used by domain plans.
|
|
@@ -218,6 +218,29 @@ function summarizeBatchResults({ results, images }, _options = {}) {
|
|
|
218
218
|
const summary = { batch: true, outcome, ...(succeeded === 0 ? { isError: true } : {}), total: results.length, succeeded, failed: results.length - succeeded, results };
|
|
219
219
|
return images.length ? { ...summary, content: [{ type: 'text', text: JSON.stringify(summary) }, ...images] } : summary;
|
|
220
220
|
}
|
|
221
|
+
function planBatchRegistration({ registration, tool, descriptor, maxItems }) {
|
|
222
|
+
const toolId = registration.descriptor.id;
|
|
223
|
+
return {
|
|
224
|
+
...registration, descriptor: { ...descriptor,
|
|
225
|
+
description: `${registration.descriptor.description ?? ''}${BATCH_GUIDANCE_MARKER}${singleCallGuidance({ fields: batchItemRequiredFields({ inputSchema: descriptor.inputSchema }) })}up to ${maxItems} inputs are normalized before authorization and passed to the existing combined approval plan.`,
|
|
226
|
+
},
|
|
227
|
+
// The plan owns one confirmation. Normalize every merged item before the outer gate so
|
|
228
|
+
// its policy and planner receive the same targets; never execute items to preflight them.
|
|
229
|
+
normalizeInput: async ({ input }) => {
|
|
230
|
+
if (!Object.hasOwn(input, 'items'))
|
|
231
|
+
return normalizeSingleBatchInput({ input, registration });
|
|
232
|
+
const { items: rawItems, ...shared } = input;
|
|
233
|
+
const items = readItems({ items: rawItems, toolId, maxItems });
|
|
234
|
+
const normalized = [];
|
|
235
|
+
for (const item of items) {
|
|
236
|
+
const result = await normalizeBatchItem({ registration, defaults: tool.itemDefaults, shared, item });
|
|
237
|
+
tool.validateItem?.({ input: result.input });
|
|
238
|
+
normalized.push(result);
|
|
239
|
+
}
|
|
240
|
+
return { input: { items: normalized.map(item => item.input) }, notes: normalized.flatMap(item => item.notes) };
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
}
|
|
221
244
|
/**
|
|
222
245
|
* Wraps one registration so it also accepts `items`. Single calls retain their handler.
|
|
223
246
|
* Ordinary merged items re-enter the executor; plan batches normalize all items at the outer
|
|
@@ -239,26 +262,7 @@ export function withBatchInput({ registration, tool }, { mode = tool.mode ?? 'it
|
|
|
239
262
|
const maxItems = tool.maxItems ?? DEFAULT_MAX_BATCH_ITEMS;
|
|
240
263
|
const descriptor = batchDescriptorFor({ descriptor: registration.descriptor, tool });
|
|
241
264
|
if (mode === 'plan')
|
|
242
|
-
return {
|
|
243
|
-
...registration, descriptor: { ...descriptor,
|
|
244
|
-
description: `${registration.descriptor.description ?? ''}${BATCH_GUIDANCE_MARKER}${singleCallGuidance({ fields: batchItemRequiredFields({ inputSchema: descriptor.inputSchema }) })}up to ${maxItems} inputs are normalized before authorization and passed to the existing combined approval plan.`,
|
|
245
|
-
},
|
|
246
|
-
// The plan owns one confirmation. Normalize every merged item before the outer gate so
|
|
247
|
-
// its policy and planner receive the same targets; never execute items to preflight them.
|
|
248
|
-
normalizeInput: async ({ input }) => {
|
|
249
|
-
if (!Object.hasOwn(input, 'items'))
|
|
250
|
-
return normalizeSingleBatchInput({ input, registration });
|
|
251
|
-
const { items: rawItems, ...shared } = input;
|
|
252
|
-
const items = readItems({ items: rawItems, toolId, maxItems });
|
|
253
|
-
const normalized = [];
|
|
254
|
-
for (const item of items) {
|
|
255
|
-
const result = await normalizeBatchItem({ registration, defaults: tool.itemDefaults, shared, item });
|
|
256
|
-
tool.validateItem?.({ input: result.input });
|
|
257
|
-
normalized.push(result);
|
|
258
|
-
}
|
|
259
|
-
return { input: { items: normalized.map(item => item.input) }, notes: normalized.flatMap(item => item.notes) };
|
|
260
|
-
},
|
|
261
|
-
};
|
|
265
|
+
return planBatchRegistration({ registration, tool, descriptor, maxItems });
|
|
262
266
|
const original = registration.handler;
|
|
263
267
|
const itemRegistry = createToolRegistry({});
|
|
264
268
|
itemRegistry.register(registration);
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Admin-module descriptor vocabulary: the plain data a feature package exports so a host can
|
|
3
|
+
* register it with an admin shell, plus typed port tokens. Pure: no registry, no React, no I/O.
|
|
4
|
+
* The registry (`createAdmin`) lives in the admin package; a module package imports only this file.
|
|
5
|
+
*/
|
|
6
|
+
import { type Token } from '../token.js';
|
|
7
|
+
import type { ControllerStore } from '../admin-runtime/controller-store.js';
|
|
8
|
+
/** Admin port tokens are core tokens, frozen so a registered identity cannot be mutated after boot. */
|
|
9
|
+
export type AdminPortToken<T = unknown, Id extends string = string> = Token<T, Id>;
|
|
10
|
+
export declare function adminPort<T, const Id extends string = string>({ id }: {
|
|
11
|
+
id: Id;
|
|
12
|
+
}, { version }?: {
|
|
13
|
+
version?: number;
|
|
14
|
+
}): AdminPortToken<T, Id>;
|
|
15
|
+
export type PortMap = Readonly<Record<string, AdminPortToken>>;
|
|
16
|
+
export type PortValues<P extends PortMap> = {
|
|
17
|
+
readonly [K in keyof P]: P[K] extends AdminPortToken<infer T> ? T : never;
|
|
18
|
+
};
|
|
19
|
+
export interface AdminTab {
|
|
20
|
+
readonly label: string;
|
|
21
|
+
readonly params?: Readonly<Record<string, unknown>>;
|
|
22
|
+
readonly requires?: PortMap;
|
|
23
|
+
/** A tab depending on an unwired optional port is hidden, with a reason in describe(). */
|
|
24
|
+
readonly optional?: PortMap;
|
|
25
|
+
readonly permissions?: readonly string[];
|
|
26
|
+
readonly agentReachable?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface AdminPage {
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly label: string;
|
|
31
|
+
readonly nav?: {
|
|
32
|
+
readonly group: string;
|
|
33
|
+
readonly icon?: string;
|
|
34
|
+
};
|
|
35
|
+
readonly permissions?: readonly string[];
|
|
36
|
+
readonly agentReachable?: boolean;
|
|
37
|
+
readonly tabs: Readonly<Record<string, AdminTab>>;
|
|
38
|
+
}
|
|
39
|
+
export interface AdminModule {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly requires?: PortMap;
|
|
42
|
+
readonly optional?: PortMap;
|
|
43
|
+
readonly provides?: PortMap;
|
|
44
|
+
readonly pages: Readonly<Record<string, AdminPage>>;
|
|
45
|
+
readonly messages?: Readonly<Record<string, string>>;
|
|
46
|
+
readonly factories?: Readonly<Record<string, (required: {
|
|
47
|
+
ports: Readonly<Record<string, unknown>>;
|
|
48
|
+
permissions: readonly string[];
|
|
49
|
+
}, optional?: Record<string, never>) => unknown>>;
|
|
50
|
+
}
|
|
51
|
+
type Intersect<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never;
|
|
52
|
+
type TabPortValues<M extends AdminModule> = {
|
|
53
|
+
[P in keyof M['pages']]: {
|
|
54
|
+
[T in keyof M['pages'][P]['tabs']]: M['pages'][P]['tabs'][T] extends infer Tab ? Tab extends AdminTab ? PortValues<NonNullable<Tab['requires']>> & PortValues<NonNullable<Tab['optional']>> : {} : never;
|
|
55
|
+
}[keyof M['pages'][P]['tabs']];
|
|
56
|
+
}[keyof M['pages']];
|
|
57
|
+
export type ScopedPorts<M extends AdminModule> = PortValues<NonNullable<M['requires']>> & Partial<PortValues<NonNullable<M['optional']>> & Intersect<TabPortValues<M>>>;
|
|
58
|
+
export type TabId<M extends AdminModule> = M extends unknown ? {
|
|
59
|
+
[P in keyof M['pages'] & string]: `${M['id']}.${P}.${keyof M['pages'][P]['tabs'] & string}`;
|
|
60
|
+
}[keyof M['pages'] & string] : never;
|
|
61
|
+
export interface AdminDescription {
|
|
62
|
+
readonly modules: readonly string[];
|
|
63
|
+
readonly pages: readonly {
|
|
64
|
+
id: string;
|
|
65
|
+
path: string;
|
|
66
|
+
label: string;
|
|
67
|
+
visible: boolean;
|
|
68
|
+
agentReachable: boolean;
|
|
69
|
+
permissions: readonly string[];
|
|
70
|
+
grants: readonly string[];
|
|
71
|
+
nav?: AdminPage['nav'];
|
|
72
|
+
tabs: readonly {
|
|
73
|
+
id: string;
|
|
74
|
+
label: string;
|
|
75
|
+
visible: boolean;
|
|
76
|
+
reason: string | null;
|
|
77
|
+
params: Readonly<Record<string, unknown>>;
|
|
78
|
+
agentReachable: boolean;
|
|
79
|
+
}[];
|
|
80
|
+
}[];
|
|
81
|
+
readonly ports: readonly {
|
|
82
|
+
name: string;
|
|
83
|
+
token: string;
|
|
84
|
+
version: number;
|
|
85
|
+
source: 'host' | 'module';
|
|
86
|
+
}[];
|
|
87
|
+
}
|
|
88
|
+
export interface AdminInstance {
|
|
89
|
+
describe(required?: Record<string, never>, optional?: Record<string, never>): AdminDescription;
|
|
90
|
+
scope<M extends AdminModule>(required: {
|
|
91
|
+
module: M;
|
|
92
|
+
}, optional?: Record<string, never>): ScopedPorts<M>;
|
|
93
|
+
dispose(required?: Record<string, never>, optional?: Record<string, never>): void;
|
|
94
|
+
}
|
|
95
|
+
/** What the shell passes a module's tab view. */
|
|
96
|
+
export interface TabViewProps {
|
|
97
|
+
readonly params: Readonly<Record<string, unknown>>;
|
|
98
|
+
readonly permissions?: readonly string[];
|
|
99
|
+
}
|
|
100
|
+
/** What the shell passes a module's page. `Tab` is the renderer's tab component; core names no UI library. */
|
|
101
|
+
export interface ModulePageProps<Tab = unknown> {
|
|
102
|
+
readonly tabs: Readonly<Record<string, Tab>>;
|
|
103
|
+
readonly description: AdminDescription['pages'][number];
|
|
104
|
+
readonly requestedTab?: string;
|
|
105
|
+
readonly onTabChange?: (required: {
|
|
106
|
+
tab: string;
|
|
107
|
+
}, optional?: Record<string, never>) => void;
|
|
108
|
+
}
|
|
109
|
+
type ViewLoader = () => Promise<{
|
|
110
|
+
readonly default: unknown;
|
|
111
|
+
}>;
|
|
112
|
+
/** One lazy loader per page and per tab of the module. */
|
|
113
|
+
export type ModuleViews<M extends AdminModule> = {
|
|
114
|
+
readonly [P in keyof M['pages']]: {
|
|
115
|
+
readonly page: ViewLoader;
|
|
116
|
+
readonly tabs: {
|
|
117
|
+
readonly [T in keyof M['pages'][P]['tabs']]: ViewLoader;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
/** A module's bound views. `Page`, `Tab` and `Provider` are the renderer's component types. */
|
|
122
|
+
export interface ModuleBinding<M extends AdminModule, Page, Tab, Provider> {
|
|
123
|
+
readonly module: M;
|
|
124
|
+
readonly pages: {
|
|
125
|
+
readonly [P in keyof M['pages']]: {
|
|
126
|
+
readonly Page: Page;
|
|
127
|
+
readonly tabs: {
|
|
128
|
+
readonly [T in keyof M['pages'][P]['tabs']]: Tab;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
readonly Provider: Provider;
|
|
133
|
+
usePorts(required?: Record<string, never>, optional?: Record<string, never>): ScopedPorts<M>;
|
|
134
|
+
}
|
|
135
|
+
/** Creates the controller after commit, disposes it on cleanup, and reads its snapshot. */
|
|
136
|
+
export type UseAdminController = <C extends ControllerStore<unknown>>(required: {
|
|
137
|
+
create: () => C;
|
|
138
|
+
dependencies: readonly unknown[];
|
|
139
|
+
}, optional?: {
|
|
140
|
+
start?: (required: {
|
|
141
|
+
controller: C;
|
|
142
|
+
}, optional?: Record<string, never>) => void;
|
|
143
|
+
}) => {
|
|
144
|
+
controller: C | null;
|
|
145
|
+
snapshot: ReturnType<C['getSnapshot']> | null;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* The renderer helpers a module's screens receive from the host. Owner answer 2026-11-17 (J4):
|
|
149
|
+
* a module package states this contract and is injected with the implementation; it never imports
|
|
150
|
+
* one, so the host (which wires `@jini-ai/admin`'s React pair) decides which renderer runs.
|
|
151
|
+
* `bindReact` is a method so the implementation may take the renderer's own context type for
|
|
152
|
+
* `context`, the module's ports context (method parameters are checked bivariantly).
|
|
153
|
+
*/
|
|
154
|
+
export interface AdminModuleUi<Page, Tab, Provider> {
|
|
155
|
+
bindReact<const M extends AdminModule>(required: {
|
|
156
|
+
module: M;
|
|
157
|
+
views: ModuleViews<M>;
|
|
158
|
+
}, optional?: {
|
|
159
|
+
context?: object;
|
|
160
|
+
}): ModuleBinding<M, Page, Tab, Provider>;
|
|
161
|
+
readonly useController: UseAdminController;
|
|
162
|
+
}
|
|
163
|
+
/** Definition is data only; boot validates identities before any factory runs. */
|
|
164
|
+
export declare function defineAdminModule<const M extends AdminModule>(required: M, _optional?: Record<string, never>): M;
|
|
165
|
+
export {};
|
|
166
|
+
//# sourceMappingURL=admin-module.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Admin-module descriptor vocabulary: the plain data a feature package exports so a host can
|
|
3
|
+
* register it with an admin shell, plus typed port tokens. Pure: no registry, no React, no I/O.
|
|
4
|
+
* The registry (`createAdmin`) lives in the admin package; a module package imports only this file.
|
|
5
|
+
*/
|
|
6
|
+
import { token } from '../token.js';
|
|
7
|
+
export function adminPort({ id }, { version = 1 } = {}) {
|
|
8
|
+
return Object.freeze(token({ id }, { version }));
|
|
9
|
+
}
|
|
10
|
+
/** Definition is data only; boot validates identities before any factory runs. */
|
|
11
|
+
export function defineAdminModule(required, _optional = {}) {
|
|
12
|
+
return Object.freeze(required);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=admin-module.js.map
|