@jini-ai/core 0.7.2 → 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/CHANGELOG.md +0 -2
- 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,13 @@
|
|
|
1
|
+
/** Keep an allowed selection or choose the allowed default/first id; an empty list keeps defaultId. */
|
|
2
|
+
/**
|
|
3
|
+
* URL query values can come from stale bookmarks or typos; validating against allowed ids prevents
|
|
4
|
+
* a blank panel. The default is supplied by the caller because some screens compute it from settings.
|
|
5
|
+
* Validate that default too: a computed default can widen the type to string, letting drift from
|
|
6
|
+
* the allowed list type-check successfully. For a nonempty list, the first id keeps the fallback valid.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveActiveTabId<T extends string>({ tabId, validIds, defaultId }: {
|
|
9
|
+
tabId: string | null | undefined;
|
|
10
|
+
validIds: readonly T[];
|
|
11
|
+
defaultId: T;
|
|
12
|
+
}, _options?: {}): T;
|
|
13
|
+
//# sourceMappingURL=resolve-active-tab-id.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// URL-owned screens retain their own tab lists and defaults. Pages mirrors local state
|
|
2
|
+
// to the URL to avoid navigation over eagerly fetched data; tab-manifest enumerability is a separate decision.
|
|
3
|
+
/** Keep an allowed selection or choose the allowed default/first id; an empty list keeps defaultId. */
|
|
4
|
+
/**
|
|
5
|
+
* URL query values can come from stale bookmarks or typos; validating against allowed ids prevents
|
|
6
|
+
* a blank panel. The default is supplied by the caller because some screens compute it from settings.
|
|
7
|
+
* Validate that default too: a computed default can widen the type to string, letting drift from
|
|
8
|
+
* the allowed list type-check successfully. For a nonempty list, the first id keeps the fallback valid.
|
|
9
|
+
*/
|
|
10
|
+
export function resolveActiveTabId({ tabId, validIds, defaultId }, _options = {}) {
|
|
11
|
+
const ids = validIds;
|
|
12
|
+
const safeDefault = ids.includes(defaultId) ? defaultId : (validIds[0] ?? defaultId);
|
|
13
|
+
return tabId && ids.includes(tabId) ? tabId : safeDefault;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=resolve-active-tab-id.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SecretRedactionOptions } from "../
|
|
1
|
+
import { type SecretRedactionOptions } from "../redaction-patterns.js";
|
|
2
2
|
/**
|
|
3
3
|
* Strip ANSI/terminal escape sequences (CSI `ESC [ ... final-byte`, OSC `ESC ] ... BEL-or-ST`,
|
|
4
4
|
* and bare ESC-prefixed bytes) plus other C0/C1 control characters from `text`. Written as an
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { redactSecrets
|
|
1
|
+
import { redactSecrets } from "../redact.js";
|
|
2
|
+
import { LABELED_SECRET_RE, OPAQUE_TOKEN_RE, NON_SECRET_TOKEN_RE } from "../redaction-patterns.js";
|
|
2
3
|
/**
|
|
3
4
|
* @module redact
|
|
4
5
|
*
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/text/tagged-text-suppression
|
|
3
|
+
*
|
|
4
|
+
* A streaming-text state machine that suppresses a tagged block (matched by
|
|
5
|
+
* caller-supplied open/close patterns) from user-visible output while it's
|
|
6
|
+
* still arriving — used to hide an artifact's raw markup from chat prose
|
|
7
|
+
* while it streams in, without buffering the whole response first. Ported
|
|
8
|
+
* from OD's `apps/daemon/src/artifacts/text-suppression.ts`.
|
|
9
|
+
*/
|
|
10
|
+
/** A single streamed text delta event. */
|
|
11
|
+
export type StreamTextEvent = {
|
|
12
|
+
readonly type: 'text_delta';
|
|
13
|
+
readonly delta: string;
|
|
14
|
+
};
|
|
15
|
+
/** A sink for a streamed text delta event. */
|
|
16
|
+
export type StreamEventSink = (event: StreamTextEvent) => void;
|
|
17
|
+
/** A stateful stripper that buffers possible tag starts across streamed text deltas. */
|
|
18
|
+
export interface ArtifactTextSuppressor {
|
|
19
|
+
/** Feeds the next text delta through the suppressor and returns the visible portion. */
|
|
20
|
+
strip(required: {
|
|
21
|
+
text: string;
|
|
22
|
+
}): string;
|
|
23
|
+
/** Drains a pending candidate, or returns an empty string inside a suppressed block. */
|
|
24
|
+
flush(): string;
|
|
25
|
+
/** Whether a tagged block is currently being suppressed. */
|
|
26
|
+
isSuppressing(): boolean;
|
|
27
|
+
/** Whether a possible tag start is buffered but not yet resolved. */
|
|
28
|
+
hasPendingCandidate(): boolean;
|
|
29
|
+
/** A snapshot of the suppression counters. */
|
|
30
|
+
stats(): ArtifactTextSuppressorStats;
|
|
31
|
+
}
|
|
32
|
+
/** Diagnostic counters describing an `ArtifactTextSuppressor`'s cumulative activity. */
|
|
33
|
+
export interface ArtifactTextSuppressorStats {
|
|
34
|
+
readonly suppressedChars: number;
|
|
35
|
+
readonly suppressedChunks: number;
|
|
36
|
+
readonly openedBlocks: number;
|
|
37
|
+
readonly closedBlocks: number;
|
|
38
|
+
readonly pendingCandidateChars: number;
|
|
39
|
+
readonly suppressing: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** The largest suffix searched for a possible tag start. */
|
|
42
|
+
export declare const MAX_CANDIDATE_LENGTH = 512;
|
|
43
|
+
/** The open/close patterns a suppressor matches; see {@link createTaggedTextSuppressor}. */
|
|
44
|
+
export interface TaggedTextMatchers {
|
|
45
|
+
openRe: RegExp;
|
|
46
|
+
closeRe: RegExp;
|
|
47
|
+
isPossibleOpen: (required: {
|
|
48
|
+
text: string;
|
|
49
|
+
}) => boolean;
|
|
50
|
+
isPossibleClose: (required: {
|
|
51
|
+
text: string;
|
|
52
|
+
}) => boolean;
|
|
53
|
+
}
|
|
54
|
+
/** The public, generic name for an artifact-compatible text suppressor. */
|
|
55
|
+
export type TaggedTextSuppressor = ArtifactTextSuppressor;
|
|
56
|
+
/**
|
|
57
|
+
* Builds a suppressor for a tagged block delimited by `openRe`/`closeRe`.
|
|
58
|
+
* `isPossibleOpen`/`isPossibleClose` decide whether a trailing `<...`
|
|
59
|
+
* fragment (with no closing `>` yet) *could* still become a match once more
|
|
60
|
+
* text arrives — this is what lets the suppressor hold back a
|
|
61
|
+
* not-yet-decidable tail across streaming chunk boundaries instead of
|
|
62
|
+
* either emitting a tag fragment early or hanging indefinitely on a `<` that
|
|
63
|
+
* turns out to be unrelated text.
|
|
64
|
+
*
|
|
65
|
+
* Builds a stateful `ArtifactTextSuppressor` for one open/close tag pair.
|
|
66
|
+
* The agent-runtime counterpart described itself this way: Shared implementation behind both
|
|
67
|
+
* `createDsmlArtifactTextSuppressor` and `createToolCallTextSuppressor`.
|
|
68
|
+
*
|
|
69
|
+
* @param required.openRe - Matches a complete opening tag.
|
|
70
|
+
* @param required.closeRe - Matches a complete closing tag.
|
|
71
|
+
* @param required.isPossibleOpen - Returns `true` when a trailing fragment could
|
|
72
|
+
* still grow into a complete opening tag on the next delta.
|
|
73
|
+
* @param required.isPossibleClose - Same, for the closing tag.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createTaggedTextSuppressor(required: TaggedTextMatchers, _optional?: Record<string, never>): ArtifactTextSuppressor;
|
|
76
|
+
/**
|
|
77
|
+
* Feeds `text` through `suppressor` and emits a `text_delta` on `onEvent` only when something survives. Returns whether an event was emitted.
|
|
78
|
+
* Runs `text` through `suppressor` and, if any visible text survives,
|
|
79
|
+
* forwards it to `onEvent` as a `text_delta`.
|
|
80
|
+
*
|
|
81
|
+
* @param required.suppressor - The suppressor to strip `text` through.
|
|
82
|
+
* @param required.onEvent - Sink invoked with a `text_delta` event when output survives.
|
|
83
|
+
* @param required.text - The raw text delta to strip.
|
|
84
|
+
* @returns `true` when a `text_delta` was emitted, `false` otherwise.
|
|
85
|
+
*/
|
|
86
|
+
export declare function emitWithTextSuppressor({ suppressor, onEvent, text }: {
|
|
87
|
+
suppressor: ArtifactTextSuppressor;
|
|
88
|
+
onEvent: StreamEventSink;
|
|
89
|
+
text: string;
|
|
90
|
+
}, _optional?: Record<string, never>): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Finds the start index of the rightmost `<`-prefixed suffix of `text` that
|
|
93
|
+
* could still grow into a complete tag matched by `predicate`, scanning back
|
|
94
|
+
* at most `MAX_CANDIDATE_LENGTH` characters. Returns `-1` when no such suffix
|
|
95
|
+
* exists.
|
|
96
|
+
*/
|
|
97
|
+
export declare function possibleTagStart({ text, predicate }: {
|
|
98
|
+
text: string;
|
|
99
|
+
predicate: (required: {
|
|
100
|
+
text: string;
|
|
101
|
+
}) => boolean;
|
|
102
|
+
}, _optional?: Record<string, never>): number;
|
|
103
|
+
//# sourceMappingURL=tagged-text-suppression.d.ts.map
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/text/tagged-text-suppression
|
|
3
|
+
*
|
|
4
|
+
* A streaming-text state machine that suppresses a tagged block (matched by
|
|
5
|
+
* caller-supplied open/close patterns) from user-visible output while it's
|
|
6
|
+
* still arriving — used to hide an artifact's raw markup from chat prose
|
|
7
|
+
* while it streams in, without buffering the whole response first. Ported
|
|
8
|
+
* from OD's `apps/daemon/src/artifacts/text-suppression.ts`.
|
|
9
|
+
*/
|
|
10
|
+
/** The largest suffix searched for a possible tag start. */
|
|
11
|
+
export const MAX_CANDIDATE_LENGTH = 512;
|
|
12
|
+
function noteSuppressed({ state, text }, _optional = {}) {
|
|
13
|
+
if (text.length <= 0)
|
|
14
|
+
return;
|
|
15
|
+
state.suppressedChars += text.length;
|
|
16
|
+
state.suppressedChunks += 1;
|
|
17
|
+
}
|
|
18
|
+
/** Inside a block: hide everything up to and including the close tag, holding back a possible close-tag tail. */
|
|
19
|
+
function stripInsideBlock({ state, matchers, current }, _optional = {}) {
|
|
20
|
+
const close = matchers.closeRe.exec(current);
|
|
21
|
+
if (!close || close.index === undefined) {
|
|
22
|
+
const closeCandidateStart = possibleTagStart({ text: current, predicate: matchers.isPossibleClose });
|
|
23
|
+
if (closeCandidateStart !== -1) {
|
|
24
|
+
state.candidate = current.slice(closeCandidateStart);
|
|
25
|
+
noteSuppressed({ state, text: current.slice(0, closeCandidateStart) });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
noteSuppressed({ state, text: current });
|
|
29
|
+
}
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
state.suppressing = false;
|
|
33
|
+
const end = close.index + close[0].length;
|
|
34
|
+
state.closedBlocks += 1;
|
|
35
|
+
noteSuppressed({ state, text: current.slice(0, end) });
|
|
36
|
+
return stripText({ state, matchers, text: current.slice(end) });
|
|
37
|
+
}
|
|
38
|
+
/** Outside a block: emit text before an open tag (then suppress from it), or hold back a possible open-tag tail. */
|
|
39
|
+
function stripOutsideBlock({ state, matchers, current }, _optional = {}) {
|
|
40
|
+
const open = matchers.openRe.exec(current);
|
|
41
|
+
if (open && open.index !== undefined) {
|
|
42
|
+
state.suppressing = true;
|
|
43
|
+
state.openedBlocks += 1;
|
|
44
|
+
const prefix = current.slice(0, open.index);
|
|
45
|
+
const tail = current.slice(open.index + open[0].length);
|
|
46
|
+
noteSuppressed({ state, text: open[0] });
|
|
47
|
+
return `${prefix}${stripText({ state, matchers, text: tail })}`;
|
|
48
|
+
}
|
|
49
|
+
const candidateStart = possibleTagStart({ text: current, predicate: matchers.isPossibleOpen });
|
|
50
|
+
if (candidateStart === -1)
|
|
51
|
+
return current;
|
|
52
|
+
state.candidate = current.slice(candidateStart);
|
|
53
|
+
return current.slice(0, candidateStart);
|
|
54
|
+
}
|
|
55
|
+
/** One `strip` step: prepend the held-back candidate, then run the branch for the current mode. */
|
|
56
|
+
function stripText({ state, matchers, text }, _optional = {}) {
|
|
57
|
+
const current = `${state.candidate}${text}`;
|
|
58
|
+
state.candidate = '';
|
|
59
|
+
return state.suppressing
|
|
60
|
+
? stripInsideBlock({ state, matchers, current })
|
|
61
|
+
: stripOutsideBlock({ state, matchers, current });
|
|
62
|
+
}
|
|
63
|
+
function flushCandidate({ state }, _optional = {}) {
|
|
64
|
+
const text = state.candidate;
|
|
65
|
+
state.candidate = '';
|
|
66
|
+
return state.suppressing ? '' : text;
|
|
67
|
+
}
|
|
68
|
+
function statsOf({ state }, _optional = {}) {
|
|
69
|
+
return {
|
|
70
|
+
suppressedChars: state.suppressedChars,
|
|
71
|
+
suppressedChunks: state.suppressedChunks,
|
|
72
|
+
openedBlocks: state.openedBlocks,
|
|
73
|
+
closedBlocks: state.closedBlocks,
|
|
74
|
+
pendingCandidateChars: state.candidate.length,
|
|
75
|
+
suppressing: state.suppressing,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Builds a suppressor for a tagged block delimited by `openRe`/`closeRe`.
|
|
80
|
+
* `isPossibleOpen`/`isPossibleClose` decide whether a trailing `<...`
|
|
81
|
+
* fragment (with no closing `>` yet) *could* still become a match once more
|
|
82
|
+
* text arrives — this is what lets the suppressor hold back a
|
|
83
|
+
* not-yet-decidable tail across streaming chunk boundaries instead of
|
|
84
|
+
* either emitting a tag fragment early or hanging indefinitely on a `<` that
|
|
85
|
+
* turns out to be unrelated text.
|
|
86
|
+
*
|
|
87
|
+
* Builds a stateful `ArtifactTextSuppressor` for one open/close tag pair.
|
|
88
|
+
* The agent-runtime counterpart described itself this way: Shared implementation behind both
|
|
89
|
+
* `createDsmlArtifactTextSuppressor` and `createToolCallTextSuppressor`.
|
|
90
|
+
*
|
|
91
|
+
* @param required.openRe - Matches a complete opening tag.
|
|
92
|
+
* @param required.closeRe - Matches a complete closing tag.
|
|
93
|
+
* @param required.isPossibleOpen - Returns `true` when a trailing fragment could
|
|
94
|
+
* still grow into a complete opening tag on the next delta.
|
|
95
|
+
* @param required.isPossibleClose - Same, for the closing tag.
|
|
96
|
+
*/
|
|
97
|
+
export function createTaggedTextSuppressor(required, _optional = {}) {
|
|
98
|
+
const state = { suppressing: false, candidate: '', suppressedChars: 0, suppressedChunks: 0, openedBlocks: 0, closedBlocks: 0 };
|
|
99
|
+
return {
|
|
100
|
+
strip: ({ text }) => stripText({ state, matchers: required, text }),
|
|
101
|
+
flush: () => flushCandidate({ state }),
|
|
102
|
+
isSuppressing: () => state.suppressing,
|
|
103
|
+
hasPendingCandidate: () => state.candidate.length > 0,
|
|
104
|
+
stats: () => statsOf({ state }),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Feeds `text` through `suppressor` and emits a `text_delta` on `onEvent` only when something survives. Returns whether an event was emitted.
|
|
109
|
+
* Runs `text` through `suppressor` and, if any visible text survives,
|
|
110
|
+
* forwards it to `onEvent` as a `text_delta`.
|
|
111
|
+
*
|
|
112
|
+
* @param required.suppressor - The suppressor to strip `text` through.
|
|
113
|
+
* @param required.onEvent - Sink invoked with a `text_delta` event when output survives.
|
|
114
|
+
* @param required.text - The raw text delta to strip.
|
|
115
|
+
* @returns `true` when a `text_delta` was emitted, `false` otherwise.
|
|
116
|
+
*/
|
|
117
|
+
export function emitWithTextSuppressor({ suppressor, onEvent, text }, _optional = {}) {
|
|
118
|
+
const delta = suppressor.strip({ text });
|
|
119
|
+
if (!delta)
|
|
120
|
+
return false;
|
|
121
|
+
onEvent({ type: 'text_delta', delta });
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Finds the start index of the rightmost `<`-prefixed suffix of `text` that
|
|
126
|
+
* could still grow into a complete tag matched by `predicate`, scanning back
|
|
127
|
+
* at most `MAX_CANDIDATE_LENGTH` characters. Returns `-1` when no such suffix
|
|
128
|
+
* exists.
|
|
129
|
+
*/
|
|
130
|
+
export function possibleTagStart({ text, predicate }, _optional = {}) {
|
|
131
|
+
const min = Math.max(0, text.length - MAX_CANDIDATE_LENGTH);
|
|
132
|
+
let index = text.lastIndexOf('<');
|
|
133
|
+
while (index >= min) {
|
|
134
|
+
const tail = text.slice(index);
|
|
135
|
+
if (predicate({ text: tail }))
|
|
136
|
+
return index;
|
|
137
|
+
if (index === 0)
|
|
138
|
+
break;
|
|
139
|
+
index = text.lastIndexOf('<', index - 1);
|
|
140
|
+
}
|
|
141
|
+
return -1;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=tagged-text-suppression.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Parameterized messages belong in locale data too: branching on locale in every interpolation
|
|
2
|
+
* helper would require editing every caller to add a language, instead of adding templates. */
|
|
3
|
+
export declare function interpolate({ template, vars }: {
|
|
4
|
+
template: string;
|
|
5
|
+
vars: Record<string, string | number>;
|
|
6
|
+
}, _options?: {}): string;
|
|
7
|
+
/**
|
|
8
|
+
* Split around placeholders when values must be rendered as nodes, such as inline code naming
|
|
9
|
+
* a destructive action's target; plain string interpolation cannot insert those nodes.
|
|
10
|
+
* Missing/mistyped locale tokens collapse the remaining text into one segment, followed by
|
|
11
|
+
* empty segments, so a translation defect does not crash its dialog.
|
|
12
|
+
*/
|
|
13
|
+
/** Returns tokens.length + 1 segments in token order; callers interleave their node values. */
|
|
14
|
+
export declare function splitOnPlaceholders({ template, tokens }: {
|
|
15
|
+
template: string;
|
|
16
|
+
tokens: readonly string[];
|
|
17
|
+
}, _options?: {}): string[];
|
|
18
|
+
/** Only singular versus other; this is not full CLDR pluralization. Languages needing more than
|
|
19
|
+
* two forms require a richer mechanism rather than being forced into these two templates. */
|
|
20
|
+
export declare function pickPlural({ count, forms }: {
|
|
21
|
+
count: number;
|
|
22
|
+
forms: {
|
|
23
|
+
one: string;
|
|
24
|
+
other: string;
|
|
25
|
+
};
|
|
26
|
+
}, _options?: {}): string;
|
|
27
|
+
/** Resolve caller-owned locale data, defaulting to English or an explicit fallback.
|
|
28
|
+
* Own-property lookup prevents constructor/toString/__proto__ locale names from returning
|
|
29
|
+
* prototype objects, which would throw when passed to a string interpolator.
|
|
30
|
+
* @throws When neither the requested entry nor a fallback is defined. */
|
|
31
|
+
export declare function localeEntry<T>({ table, locale }: {
|
|
32
|
+
table: Readonly<Record<string, T>>;
|
|
33
|
+
locale: string;
|
|
34
|
+
}, { fallback }?: {
|
|
35
|
+
fallback?: T;
|
|
36
|
+
}): T;
|
|
37
|
+
//# sourceMappingURL=template-i18n.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Parameterized messages belong in locale data too: branching on locale in every interpolation
|
|
2
|
+
* helper would require editing every caller to add a language, instead of adding templates. */
|
|
3
|
+
export function interpolate({ template, vars }, _options = {}) {
|
|
4
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => {
|
|
5
|
+
return key in vars ? String(vars[key]) : match;
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Split around placeholders when values must be rendered as nodes, such as inline code naming
|
|
10
|
+
* a destructive action's target; plain string interpolation cannot insert those nodes.
|
|
11
|
+
* Missing/mistyped locale tokens collapse the remaining text into one segment, followed by
|
|
12
|
+
* empty segments, so a translation defect does not crash its dialog.
|
|
13
|
+
*/
|
|
14
|
+
/** Returns tokens.length + 1 segments in token order; callers interleave their node values. */
|
|
15
|
+
export function splitOnPlaceholders({ template, tokens }, _options = {}) {
|
|
16
|
+
const segments = [];
|
|
17
|
+
let rest = template;
|
|
18
|
+
for (const token of tokens) {
|
|
19
|
+
const index = rest.indexOf(token);
|
|
20
|
+
if (index === -1) {
|
|
21
|
+
segments.push(rest);
|
|
22
|
+
rest = "";
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
segments.push(rest.slice(0, index));
|
|
26
|
+
rest = rest.slice(index + token.length);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
segments.push(rest);
|
|
30
|
+
return segments;
|
|
31
|
+
}
|
|
32
|
+
/** Only singular versus other; this is not full CLDR pluralization. Languages needing more than
|
|
33
|
+
* two forms require a richer mechanism rather than being forced into these two templates. */
|
|
34
|
+
export function pickPlural({ count, forms }, _options = {}) {
|
|
35
|
+
return count === 1 ? forms.one : forms.other;
|
|
36
|
+
}
|
|
37
|
+
/** Resolve caller-owned locale data, defaulting to English or an explicit fallback.
|
|
38
|
+
* Own-property lookup prevents constructor/toString/__proto__ locale names from returning
|
|
39
|
+
* prototype objects, which would throw when passed to a string interpolator.
|
|
40
|
+
* @throws When neither the requested entry nor a fallback is defined. */
|
|
41
|
+
export function localeEntry({ table, locale }, { fallback = table.en } = {}) {
|
|
42
|
+
const entry = Object.hasOwn(table, locale) ? (table[locale] ?? fallback) : fallback;
|
|
43
|
+
if (entry === undefined) {
|
|
44
|
+
throw new Error(`No locale entry for "${locale}" and no English or explicit fallback`);
|
|
45
|
+
}
|
|
46
|
+
return entry;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=template-i18n.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain-words sentences the model reads about how to call a tool. One builder per sentence, so the
|
|
3
|
+
* daemon route and an MCP host that name the same mistake say it the same way. Pure text: no I/O,
|
|
4
|
+
* no ids minted, no clock, no `node:` import.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The sentence for a tool id that is not registered.
|
|
8
|
+
*
|
|
9
|
+
* `candidates` are the registered ids closest to what the caller typed (the caller ranks them; this
|
|
10
|
+
* function only words them). The sentence never says the call was denied: nothing was refused, the
|
|
11
|
+
* tool does not exist.
|
|
12
|
+
*
|
|
13
|
+
* @param required.toolId - The id the caller used, shown verbatim in quotes.
|
|
14
|
+
* @param required.candidates - Closest registered ids, closest first; empty for none.
|
|
15
|
+
* @returns `There is no tool named "x". Closest names: a, b. Find tools with search_tools.` or, with no candidates,
|
|
16
|
+
* `There is no tool named "x". Find tools with search_tools.`
|
|
17
|
+
* @complexity O(c) for c candidates; no effects.
|
|
18
|
+
*/
|
|
19
|
+
export declare function unknownToolSentence({ toolId, candidates }: {
|
|
20
|
+
readonly toolId: string;
|
|
21
|
+
readonly candidates: readonly string[];
|
|
22
|
+
}, _optional?: Record<string, never>): string;
|
|
23
|
+
/**
|
|
24
|
+
* The sentence for an id that names a group of tools, not one tool. The caller lists only members its own
|
|
25
|
+
* registry holds; this function only words them. Like {@link unknownToolSentence} it never says the call was
|
|
26
|
+
* denied: nothing was refused and nothing ran.
|
|
27
|
+
*
|
|
28
|
+
* @param required.familyId - The group id the caller used, shown verbatim in quotes.
|
|
29
|
+
* @param required.members - The registered member ids to call instead, in the order to show them.
|
|
30
|
+
* @returns `"fam" is a group of tools, not one tool. Call one of: fam.a, fam.b.`
|
|
31
|
+
* @complexity O(m) for m members; no effects.
|
|
32
|
+
*/
|
|
33
|
+
export declare function toolFamilySentence({ familyId, members }: {
|
|
34
|
+
readonly familyId: string;
|
|
35
|
+
readonly members: readonly string[];
|
|
36
|
+
}, _optional?: Record<string, never>): string;
|
|
37
|
+
/**
|
|
38
|
+
* How to call one tool, written the way the model must type it.
|
|
39
|
+
*
|
|
40
|
+
* A published tool is called by its wire name (the name the transport assigned, which is not always its
|
|
41
|
+
* registry id: ids with dots, hyphens or over the length limit are published as `tool_<readable>_<hash>`).
|
|
42
|
+
* Any other tool is called through the gateway, which takes the registry id. The two forms never mix: the
|
|
43
|
+
* wire name appears only in the first, the registry id only inside the gateway call.
|
|
44
|
+
*
|
|
45
|
+
* @param required.toolId - The registry id; used only in the gateway form.
|
|
46
|
+
* @param optional.wireName - The name the publisher assigned; present means "call it directly".
|
|
47
|
+
* @param optional.readOnly - A read-only tool goes through the read-only gateway.
|
|
48
|
+
* @param optional.input - Arguments to show; omitted, the direct form has none and the gateway form shows `{}`.
|
|
49
|
+
* @returns `name`, `name({...})`, or `execute_delegated_tool({"toolId":"id","input":{...}})`.
|
|
50
|
+
* @complexity O(s) for s bytes of serialized input; no effects.
|
|
51
|
+
*/
|
|
52
|
+
export declare function toolCallText({ toolId }: {
|
|
53
|
+
readonly toolId: string;
|
|
54
|
+
}, { wireName, readOnly, input }?: {
|
|
55
|
+
readonly wireName?: string;
|
|
56
|
+
readonly readOnly?: boolean;
|
|
57
|
+
readonly input?: unknown;
|
|
58
|
+
}): string;
|
|
59
|
+
//# sourceMappingURL=tool-call-text.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain-words sentences the model reads about how to call a tool. One builder per sentence, so the
|
|
3
|
+
* daemon route and an MCP host that name the same mistake say it the same way. Pure text: no I/O,
|
|
4
|
+
* no ids minted, no clock, no `node:` import.
|
|
5
|
+
*/
|
|
6
|
+
/** The fixed tail of every unknown-tool answer: where the model finds a real id. */
|
|
7
|
+
const DISCOVERY_SENTENCE = 'Find tools with search_tools.';
|
|
8
|
+
/**
|
|
9
|
+
* The sentence for a tool id that is not registered.
|
|
10
|
+
*
|
|
11
|
+
* `candidates` are the registered ids closest to what the caller typed (the caller ranks them; this
|
|
12
|
+
* function only words them). The sentence never says the call was denied: nothing was refused, the
|
|
13
|
+
* tool does not exist.
|
|
14
|
+
*
|
|
15
|
+
* @param required.toolId - The id the caller used, shown verbatim in quotes.
|
|
16
|
+
* @param required.candidates - Closest registered ids, closest first; empty for none.
|
|
17
|
+
* @returns `There is no tool named "x". Closest names: a, b. Find tools with search_tools.` or, with no candidates,
|
|
18
|
+
* `There is no tool named "x". Find tools with search_tools.`
|
|
19
|
+
* @complexity O(c) for c candidates; no effects.
|
|
20
|
+
*/
|
|
21
|
+
export function unknownToolSentence({ toolId, candidates }, _optional = {}) {
|
|
22
|
+
const closest = candidates.length > 0 ? ` Closest names: ${candidates.join(', ')}.` : '';
|
|
23
|
+
return `There is no tool named "${toolId}".${closest} ${DISCOVERY_SENTENCE}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The sentence for an id that names a group of tools, not one tool. The caller lists only members its own
|
|
27
|
+
* registry holds; this function only words them. Like {@link unknownToolSentence} it never says the call was
|
|
28
|
+
* denied: nothing was refused and nothing ran.
|
|
29
|
+
*
|
|
30
|
+
* @param required.familyId - The group id the caller used, shown verbatim in quotes.
|
|
31
|
+
* @param required.members - The registered member ids to call instead, in the order to show them.
|
|
32
|
+
* @returns `"fam" is a group of tools, not one tool. Call one of: fam.a, fam.b.`
|
|
33
|
+
* @complexity O(m) for m members; no effects.
|
|
34
|
+
*/
|
|
35
|
+
export function toolFamilySentence({ familyId, members }, _optional = {}) {
|
|
36
|
+
return `"${familyId}" is a group of tools, not one tool. Call one of: ${members.join(', ')}.`;
|
|
37
|
+
}
|
|
38
|
+
/** The two gateway tools a caller falls back to when a tool is not published as its own tool. */
|
|
39
|
+
const GATEWAY_TOOL = 'execute_delegated_tool';
|
|
40
|
+
const READONLY_GATEWAY_TOOL = 'execute_readonly_delegated_tool';
|
|
41
|
+
/**
|
|
42
|
+
* How to call one tool, written the way the model must type it.
|
|
43
|
+
*
|
|
44
|
+
* A published tool is called by its wire name (the name the transport assigned, which is not always its
|
|
45
|
+
* registry id: ids with dots, hyphens or over the length limit are published as `tool_<readable>_<hash>`).
|
|
46
|
+
* Any other tool is called through the gateway, which takes the registry id. The two forms never mix: the
|
|
47
|
+
* wire name appears only in the first, the registry id only inside the gateway call.
|
|
48
|
+
*
|
|
49
|
+
* @param required.toolId - The registry id; used only in the gateway form.
|
|
50
|
+
* @param optional.wireName - The name the publisher assigned; present means "call it directly".
|
|
51
|
+
* @param optional.readOnly - A read-only tool goes through the read-only gateway.
|
|
52
|
+
* @param optional.input - Arguments to show; omitted, the direct form has none and the gateway form shows `{}`.
|
|
53
|
+
* @returns `name`, `name({...})`, or `execute_delegated_tool({"toolId":"id","input":{...}})`.
|
|
54
|
+
* @complexity O(s) for s bytes of serialized input; no effects.
|
|
55
|
+
*/
|
|
56
|
+
export function toolCallText({ toolId }, { wireName, readOnly = false, input } = {}) {
|
|
57
|
+
if (wireName !== undefined)
|
|
58
|
+
return input === undefined ? wireName : `${wireName}(${JSON.stringify(input)})`;
|
|
59
|
+
const gateway = readOnly ? READONLY_GATEWAY_TOOL : GATEWAY_TOOL;
|
|
60
|
+
return `${gateway}(${JSON.stringify({ toolId, input: input ?? {} })})`;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=tool-call-text.js.map
|
|
@@ -20,6 +20,13 @@ export function decodeToolInputObject({ input }, _options = {}) {
|
|
|
20
20
|
throw new ToolInputError({ message: 'The delegated input must be a JSON object. Send the tool fields inside an object.' });
|
|
21
21
|
return decoded;
|
|
22
22
|
}
|
|
23
|
+
/** True when the schema is an explicit object contract without an `input` property of its own. */
|
|
24
|
+
function schemaCannotOwnInput({ schema }, _options = {}) {
|
|
25
|
+
if (!record(schema) || schema.type !== 'object')
|
|
26
|
+
return false;
|
|
27
|
+
const properties = schema.properties ?? {};
|
|
28
|
+
return record(properties) && !Object.hasOwn(properties, 'input');
|
|
29
|
+
}
|
|
23
30
|
/** Remove one delegated envelope only when the tool contract cannot own an `input` field.
|
|
24
31
|
* Mixed fields and schemas without an explicit object contract retain ordinary validation.
|
|
25
32
|
* @returns The original value or decoded inner object; never mutates caller arguments.
|
|
@@ -27,10 +34,7 @@ export function decodeToolInputObject({ input }, _options = {}) {
|
|
|
27
34
|
* @example unwrapToolInputEnvelope({ input: { input: '{}' }, schema: { type: 'object', properties: {} } });
|
|
28
35
|
*/
|
|
29
36
|
export function unwrapToolInputEnvelope({ input, schema }, _options = {}) {
|
|
30
|
-
if (!record(input) || !
|
|
31
|
-
return input;
|
|
32
|
-
const properties = schema.properties ?? {};
|
|
33
|
-
if (!record(properties) || Object.hasOwn(properties, 'input'))
|
|
37
|
+
if (!record(input) || !schemaCannotOwnInput({ schema }))
|
|
34
38
|
return input;
|
|
35
39
|
if (Object.keys(input).length !== 1 || !Object.hasOwn(input, 'input'))
|
|
36
40
|
return input;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isNonArrayRecord } from './records.js';
|
|
2
2
|
import { ToolInputError, ToolInputNormalizationError } from './tool-input-errors.js';
|
|
3
3
|
import { unwrapToolInputEnvelope } from './tool-input-envelope.js';
|
|
4
|
+
import { clampDeclaredBounds } from './tool-input-repairs.js';
|
|
4
5
|
export { ToolInputNormalizationError } from './tool-input-errors.js';
|
|
5
6
|
const object = (value) => isNonArrayRecord({ value });
|
|
6
7
|
const keyShape = (key) => key.replace(/[_-]/g, '').toLowerCase();
|
|
@@ -140,6 +141,9 @@ function normalizeEntry({ key, raw, shape, sources, step }) {
|
|
|
140
141
|
walk.notes.push(`${location}→${target}`);
|
|
141
142
|
const parentPrefix = path ? `${path}.` : '';
|
|
142
143
|
const value = normalizeValue({ value: raw, schema: shape.properties[target], step: { path: `${parentPrefix}${target}`, depth: depth + 1, walk } });
|
|
144
|
+
return rememberNormalizedEntry({ key, target, value }, sources);
|
|
145
|
+
}
|
|
146
|
+
function rememberNormalizedEntry({ key, target, value }, sources) {
|
|
143
147
|
const previous = sources.get(target);
|
|
144
148
|
if (previous !== undefined && !Object.is(previous.value, value))
|
|
145
149
|
throw new ToolInputError({ message: `Conflicting inputs '${previous.key}' and '${key}' both name '${target}'. Send only '${target}'.` });
|
|
@@ -217,7 +221,10 @@ async function normalizeWithinGate({ input, registration }) {
|
|
|
217
221
|
}
|
|
218
222
|
if (isObjectTool(schema) && !object(normalized))
|
|
219
223
|
throw new ToolInputError({ message: `${registration.descriptor.id}: normalization must produce one input object.` });
|
|
220
|
-
|
|
224
|
+
const final = walkRoot({ input: normalized, schema, notes, validateClosed: true, keysOnly: false });
|
|
225
|
+
// After number coercion, so a string "8300" gets the coercion note and then the clamp's note.
|
|
226
|
+
const clamped = clampDeclaredBounds({ input: final, inputSchema: schema });
|
|
227
|
+
return { input: clamped.input, notes: [...notes, ...clamped.notes] };
|
|
221
228
|
}
|
|
222
229
|
/** Keep result shapes intact and make rewrite notes visible in plain and MCP tool results. */
|
|
223
230
|
export function withNormalizationNotes({ output, notes }, _options = {}) {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moves each out-of-range number of an opted-in property to its nearest declared bound.
|
|
3
|
+
*
|
|
4
|
+
* Only a finite number is repaired; a non-integer for an integer property, a string and anything
|
|
5
|
+
* else is returned as given and refused by the tool's own validation as before. The note names the
|
|
6
|
+
* property and the bound, never the caller's value.
|
|
7
|
+
*
|
|
8
|
+
* @param required.input - The already-normalized input (strings already coerced to numbers).
|
|
9
|
+
* @param required.inputSchema - The tool's input schema.
|
|
10
|
+
* @returns The input to run with (a copy; the argument is never mutated) and one note per repair.
|
|
11
|
+
* @complexity O(p) for p schema properties visited, to depth 6; no effects.
|
|
12
|
+
*/
|
|
13
|
+
export declare function clampDeclaredBounds({ input, inputSchema }: {
|
|
14
|
+
readonly input: unknown;
|
|
15
|
+
readonly inputSchema: unknown;
|
|
16
|
+
}, _optional?: Record<string, never>): {
|
|
17
|
+
input: unknown;
|
|
18
|
+
notes: readonly string[];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Throws when a schema declares a repair the call-time code would silently ignore: `clamp` that is
|
|
22
|
+
* not a boolean, `clamp: true` on a property that is not numeric or has no bound, or `obtainFrom`
|
|
23
|
+
* that is not a non-empty string. A registry-wide
|
|
24
|
+
* gate calls this for every published schema so a mistyped declaration fails in CI, not in a run.
|
|
25
|
+
*
|
|
26
|
+
* @param required.inputSchema - The tool's input schema.
|
|
27
|
+
* @throws Error naming the property path (`clamp on 'page.size' …`, `obtainFrom on 'themeId' …`).
|
|
28
|
+
* @complexity O(p) for p schema properties visited, to depth 6; no effects.
|
|
29
|
+
*/
|
|
30
|
+
export declare function assertRepairKeywords({ inputSchema }: {
|
|
31
|
+
readonly inputSchema: unknown;
|
|
32
|
+
}, _optional?: Record<string, never>): void;
|
|
33
|
+
/** One required property the input lacks, and the tool its schema names as the place valid values come from. */
|
|
34
|
+
export interface MissingArgumentGuidance {
|
|
35
|
+
readonly property: string;
|
|
36
|
+
readonly toolId: string;
|
|
37
|
+
/** The same words on every path that gives this guidance. */
|
|
38
|
+
readonly sentence: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The guidance for each required top-level property that the input lacks and whose schema declares
|
|
42
|
+
* `obtainFrom`: the tool that lists its valid values. A tool the caller cannot see is never named,
|
|
43
|
+
* and a present property or one without `obtainFrom` gets nothing. Reads the schema only; the
|
|
44
|
+
* caller decides which failure the guidance belongs to.
|
|
45
|
+
*
|
|
46
|
+
* @param required.inputSchema - The tool's input schema.
|
|
47
|
+
* @param required.input - The input the call carried; one that is not an object has no properties.
|
|
48
|
+
* @param optional.isKnownTool - Whether the caller can see a tool id; omitted means every id is visible.
|
|
49
|
+
* @returns One entry per such property, in the schema's `required` order; empty when there is nothing to say.
|
|
50
|
+
* @complexity O(r) for r required properties; no effects, no mutation.
|
|
51
|
+
*/
|
|
52
|
+
export declare function missingArgumentGuidance({ inputSchema, input }: {
|
|
53
|
+
readonly inputSchema: unknown;
|
|
54
|
+
readonly input: unknown;
|
|
55
|
+
}, { isKnownTool }?: {
|
|
56
|
+
readonly isKnownTool?: (toolId: string) => boolean;
|
|
57
|
+
}): readonly MissingArgumentGuidance[];
|
|
58
|
+
//# sourceMappingURL=tool-input-repairs.d.ts.map
|