@krantho/api 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/dist/active-locales.d.ts +11 -0
- package/dist/active-locales.d.ts.map +1 -0
- package/dist/active-locales.js +31 -0
- package/dist/active-locales.js.map +1 -0
- package/dist/assistant/access.d.ts +25 -0
- package/dist/assistant/access.d.ts.map +1 -0
- package/dist/assistant/access.js +35 -0
- package/dist/assistant/access.js.map +1 -0
- package/dist/assistant/agent-loop.d.ts +31 -0
- package/dist/assistant/agent-loop.d.ts.map +1 -0
- package/dist/assistant/agent-loop.js +183 -0
- package/dist/assistant/agent-loop.js.map +1 -0
- package/dist/assistant/call-handler.d.ts +15 -0
- package/dist/assistant/call-handler.d.ts.map +1 -0
- package/dist/assistant/call-handler.js +24 -0
- package/dist/assistant/call-handler.js.map +1 -0
- package/dist/assistant/chat-handler.d.ts +8 -0
- package/dist/assistant/chat-handler.d.ts.map +1 -0
- package/dist/assistant/chat-handler.js +79 -0
- package/dist/assistant/chat-handler.js.map +1 -0
- package/dist/assistant/chat-request.d.ts +16 -0
- package/dist/assistant/chat-request.d.ts.map +1 -0
- package/dist/assistant/chat-request.js +59 -0
- package/dist/assistant/chat-request.js.map +1 -0
- package/dist/assistant/confirm-handler.d.ts +3 -0
- package/dist/assistant/confirm-handler.d.ts.map +1 -0
- package/dist/assistant/confirm-handler.js +39 -0
- package/dist/assistant/confirm-handler.js.map +1 -0
- package/dist/assistant/document-change.d.ts +22 -0
- package/dist/assistant/document-change.d.ts.map +1 -0
- package/dist/assistant/document-change.js +74 -0
- package/dist/assistant/document-change.js.map +1 -0
- package/dist/assistant/document-lock.d.ts +12 -0
- package/dist/assistant/document-lock.d.ts.map +1 -0
- package/dist/assistant/document-lock.js +14 -0
- package/dist/assistant/document-lock.js.map +1 -0
- package/dist/assistant/execute-action.d.ts +19 -0
- package/dist/assistant/execute-action.d.ts.map +1 -0
- package/dist/assistant/execute-action.js +167 -0
- package/dist/assistant/execute-action.js.map +1 -0
- package/dist/assistant/pending-action.d.ts +86 -0
- package/dist/assistant/pending-action.d.ts.map +1 -0
- package/dist/assistant/pending-action.js +104 -0
- package/dist/assistant/pending-action.js.map +1 -0
- package/dist/assistant/protocol.d.ts +120 -0
- package/dist/assistant/protocol.d.ts.map +1 -0
- package/dist/assistant/protocol.js +2 -0
- package/dist/assistant/protocol.js.map +1 -0
- package/dist/assistant/routes.d.ts +4 -0
- package/dist/assistant/routes.d.ts.map +1 -0
- package/dist/assistant/routes.js +10 -0
- package/dist/assistant/routes.js.map +1 -0
- package/dist/assistant/sse-stream.d.ts +15 -0
- package/dist/assistant/sse-stream.d.ts.map +1 -0
- package/dist/assistant/sse-stream.js +61 -0
- package/dist/assistant/sse-stream.js.map +1 -0
- package/dist/assistant/status-handler.d.ts +8 -0
- package/dist/assistant/status-handler.d.ts.map +1 -0
- package/dist/assistant/status-handler.js +39 -0
- package/dist/assistant/status-handler.js.map +1 -0
- package/dist/assistant/system-prompt.d.ts +18 -0
- package/dist/assistant/system-prompt.d.ts.map +1 -0
- package/dist/assistant/system-prompt.js +48 -0
- package/dist/assistant/system-prompt.js.map +1 -0
- package/dist/assistant/tool-registry.d.ts +19 -0
- package/dist/assistant/tool-registry.d.ts.map +1 -0
- package/dist/assistant/tool-registry.js +69 -0
- package/dist/assistant/tool-registry.js.map +1 -0
- package/dist/assistant/tools/action-tools.d.ts +4 -0
- package/dist/assistant/tools/action-tools.d.ts.map +1 -0
- package/dist/assistant/tools/action-tools.js +132 -0
- package/dist/assistant/tools/action-tools.js.map +1 -0
- package/dist/assistant/tools/aeo-tools.d.ts +4 -0
- package/dist/assistant/tools/aeo-tools.d.ts.map +1 -0
- package/dist/assistant/tools/aeo-tools.js +162 -0
- package/dist/assistant/tools/aeo-tools.js.map +1 -0
- package/dist/assistant/tools/define-tool.d.ts +55 -0
- package/dist/assistant/tools/define-tool.d.ts.map +1 -0
- package/dist/assistant/tools/define-tool.js +5 -0
- package/dist/assistant/tools/define-tool.js.map +1 -0
- package/dist/assistant/tools/draft-tools.d.ts +7 -0
- package/dist/assistant/tools/draft-tools.d.ts.map +1 -0
- package/dist/assistant/tools/draft-tools.js +105 -0
- package/dist/assistant/tools/draft-tools.js.map +1 -0
- package/dist/assistant/tools/draft-write.d.ts +49 -0
- package/dist/assistant/tools/draft-write.d.ts.map +1 -0
- package/dist/assistant/tools/draft-write.js +122 -0
- package/dist/assistant/tools/draft-write.js.map +1 -0
- package/dist/assistant/tools/faq-fit.d.ts +32 -0
- package/dist/assistant/tools/faq-fit.d.ts.map +1 -0
- package/dist/assistant/tools/faq-fit.js +96 -0
- package/dist/assistant/tools/faq-fit.js.map +1 -0
- package/dist/assistant/tools/read-tools.d.ts +13 -0
- package/dist/assistant/tools/read-tools.d.ts.map +1 -0
- package/dist/assistant/tools/read-tools.js +242 -0
- package/dist/assistant/tools/read-tools.js.map +1 -0
- package/dist/assistant/tools/seo-tools.d.ts +4 -0
- package/dist/assistant/tools/seo-tools.d.ts.map +1 -0
- package/dist/assistant/tools/seo-tools.js +152 -0
- package/dist/assistant/tools/seo-tools.js.map +1 -0
- package/dist/assistant/tools/support.d.ts +35 -0
- package/dist/assistant/tools/support.d.ts.map +1 -0
- package/dist/assistant/tools/support.js +63 -0
- package/dist/assistant/tools/support.js.map +1 -0
- package/dist/assistant/untrusted.d.ts +15 -0
- package/dist/assistant/untrusted.d.ts.map +1 -0
- package/dist/assistant/untrusted.js +27 -0
- package/dist/assistant/untrusted.js.map +1 -0
- package/dist/assistant/write-policy.d.ts +20 -0
- package/dist/assistant/write-policy.d.ts.map +1 -0
- package/dist/assistant/write-policy.js +32 -0
- package/dist/assistant/write-policy.js.map +1 -0
- package/dist/auth-tokens.d.ts +31 -0
- package/dist/auth-tokens.d.ts.map +1 -0
- package/dist/auth-tokens.js +35 -0
- package/dist/auth-tokens.js.map +1 -0
- package/dist/content-change.d.ts +16 -0
- package/dist/content-change.d.ts.map +1 -0
- package/dist/content-change.js +34 -0
- package/dist/content-change.js.map +1 -0
- package/dist/content-locks.d.ts +27 -0
- package/dist/content-locks.d.ts.map +1 -0
- package/dist/content-locks.js +40 -0
- package/dist/content-locks.js.map +1 -0
- package/dist/cookies.d.ts +19 -0
- package/dist/cookies.d.ts.map +1 -0
- package/dist/cookies.js +52 -0
- package/dist/cookies.js.map +1 -0
- package/dist/create-api-handlers.d.ts +128 -0
- package/dist/create-api-handlers.d.ts.map +1 -0
- package/dist/create-api-handlers.js +384 -0
- package/dist/create-api-handlers.js.map +1 -0
- package/dist/document-actions.d.ts +25 -0
- package/dist/document-actions.d.ts.map +1 -0
- package/dist/document-actions.js +157 -0
- package/dist/document-actions.js.map +1 -0
- package/dist/document-seo.d.ts +15 -0
- package/dist/document-seo.d.ts.map +1 -0
- package/dist/document-seo.js +41 -0
- package/dist/document-seo.js.map +1 -0
- package/dist/group-by-collection.d.ts +6 -0
- package/dist/group-by-collection.d.ts.map +1 -0
- package/dist/group-by-collection.js +11 -0
- package/dist/group-by-collection.js.map +1 -0
- package/dist/handlers/apply-metadata-defaults.d.ts +4 -0
- package/dist/handlers/apply-metadata-defaults.d.ts.map +1 -0
- package/dist/handlers/apply-metadata-defaults.js +108 -0
- package/dist/handlers/apply-metadata-defaults.js.map +1 -0
- package/dist/handlers/auth-callback.d.ts +4 -0
- package/dist/handlers/auth-callback.d.ts.map +1 -0
- package/dist/handlers/auth-callback.js +217 -0
- package/dist/handlers/auth-callback.js.map +1 -0
- package/dist/handlers/auth-capabilities.d.ts +4 -0
- package/dist/handlers/auth-capabilities.d.ts.map +1 -0
- package/dist/handlers/auth-capabilities.js +19 -0
- package/dist/handlers/auth-capabilities.js.map +1 -0
- package/dist/handlers/auth-login.d.ts +4 -0
- package/dist/handlers/auth-login.d.ts.map +1 -0
- package/dist/handlers/auth-login.js +60 -0
- package/dist/handlers/auth-login.js.map +1 -0
- package/dist/handlers/auth-logout.d.ts +4 -0
- package/dist/handlers/auth-logout.d.ts.map +1 -0
- package/dist/handlers/auth-logout.js +40 -0
- package/dist/handlers/auth-logout.js.map +1 -0
- package/dist/handlers/auth-me.d.ts +4 -0
- package/dist/handlers/auth-me.d.ts.map +1 -0
- package/dist/handlers/auth-me.js +54 -0
- package/dist/handlers/auth-me.js.map +1 -0
- package/dist/handlers/auth-oidc-login.d.ts +4 -0
- package/dist/handlers/auth-oidc-login.d.ts.map +1 -0
- package/dist/handlers/auth-oidc-login.js +51 -0
- package/dist/handlers/auth-oidc-login.js.map +1 -0
- package/dist/handlers/auth-refresh.d.ts +15 -0
- package/dist/handlers/auth-refresh.d.ts.map +1 -0
- package/dist/handlers/auth-refresh.js +82 -0
- package/dist/handlers/auth-refresh.js.map +1 -0
- package/dist/handlers/bulk-delete.d.ts +8 -0
- package/dist/handlers/bulk-delete.d.ts.map +1 -0
- package/dist/handlers/bulk-delete.js +72 -0
- package/dist/handlers/bulk-delete.js.map +1 -0
- package/dist/handlers/bulk-publish.d.ts +8 -0
- package/dist/handlers/bulk-publish.d.ts.map +1 -0
- package/dist/handlers/bulk-publish.js +48 -0
- package/dist/handlers/bulk-publish.js.map +1 -0
- package/dist/handlers/capabilities.d.ts +4 -0
- package/dist/handlers/capabilities.d.ts.map +1 -0
- package/dist/handlers/capabilities.js +44 -0
- package/dist/handlers/capabilities.js.map +1 -0
- package/dist/handlers/content-changes.d.ts +28 -0
- package/dist/handlers/content-changes.d.ts.map +1 -0
- package/dist/handlers/content-changes.js +160 -0
- package/dist/handlers/content-changes.js.map +1 -0
- package/dist/handlers/content-lock.d.ts +13 -0
- package/dist/handlers/content-lock.d.ts.map +1 -0
- package/dist/handlers/content-lock.js +109 -0
- package/dist/handlers/content-lock.js.map +1 -0
- package/dist/handlers/content-tree.d.ts +11 -0
- package/dist/handlers/content-tree.d.ts.map +1 -0
- package/dist/handlers/content-tree.js +28 -0
- package/dist/handlers/content-tree.js.map +1 -0
- package/dist/handlers/create-content.d.ts +4 -0
- package/dist/handlers/create-content.d.ts.map +1 -0
- package/dist/handlers/create-content.js +49 -0
- package/dist/handlers/create-content.js.map +1 -0
- package/dist/handlers/delete-content.d.ts +4 -0
- package/dist/handlers/delete-content.d.ts.map +1 -0
- package/dist/handlers/delete-content.js +17 -0
- package/dist/handlers/delete-content.js.map +1 -0
- package/dist/handlers/delete-runtime-field.d.ts +4 -0
- package/dist/handlers/delete-runtime-field.d.ts.map +1 -0
- package/dist/handlers/delete-runtime-field.js +43 -0
- package/dist/handlers/delete-runtime-field.js.map +1 -0
- package/dist/handlers/export-bundle.d.ts +13 -0
- package/dist/handlers/export-bundle.d.ts.map +1 -0
- package/dist/handlers/export-bundle.js +99 -0
- package/dist/handlers/export-bundle.js.map +1 -0
- package/dist/handlers/export-content.d.ts +7 -0
- package/dist/handlers/export-content.d.ts.map +1 -0
- package/dist/handlers/export-content.js +69 -0
- package/dist/handlers/export-content.js.map +1 -0
- package/dist/handlers/export-schema.d.ts +4 -0
- package/dist/handlers/export-schema.d.ts.map +1 -0
- package/dist/handlers/export-schema.js +13 -0
- package/dist/handlers/export-schema.js.map +1 -0
- package/dist/handlers/get-content.d.ts +4 -0
- package/dist/handlers/get-content.d.ts.map +1 -0
- package/dist/handlers/get-content.js +65 -0
- package/dist/handlers/get-content.js.map +1 -0
- package/dist/handlers/get-runtime-schema.d.ts +4 -0
- package/dist/handlers/get-runtime-schema.d.ts.map +1 -0
- package/dist/handlers/get-runtime-schema.js +17 -0
- package/dist/handlers/get-runtime-schema.js.map +1 -0
- package/dist/handlers/get-schema.d.ts +4 -0
- package/dist/handlers/get-schema.d.ts.map +1 -0
- package/dist/handlers/get-schema.js +87 -0
- package/dist/handlers/get-schema.js.map +1 -0
- package/dist/handlers/get-version.d.ts +4 -0
- package/dist/handlers/get-version.d.ts.map +1 -0
- package/dist/handlers/get-version.js +26 -0
- package/dist/handlers/get-version.js.map +1 -0
- package/dist/handlers/import-bundle.d.ts +4 -0
- package/dist/handlers/import-bundle.d.ts.map +1 -0
- package/dist/handlers/import-bundle.js +55 -0
- package/dist/handlers/import-bundle.js.map +1 -0
- package/dist/handlers/import-content.d.ts +4 -0
- package/dist/handlers/import-content.d.ts.map +1 -0
- package/dist/handlers/import-content.js +152 -0
- package/dist/handlers/import-content.js.map +1 -0
- package/dist/handlers/index.d.ts +87 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +87 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/list-collection.d.ts +8 -0
- package/dist/handlers/list-collection.d.ts.map +1 -0
- package/dist/handlers/list-collection.js +14 -0
- package/dist/handlers/list-collection.js.map +1 -0
- package/dist/handlers/list-collections.d.ts +4 -0
- package/dist/handlers/list-collections.d.ts.map +1 -0
- package/dist/handlers/list-collections.js +17 -0
- package/dist/handlers/list-collections.js.map +1 -0
- package/dist/handlers/list-content.d.ts +8 -0
- package/dist/handlers/list-content.d.ts.map +1 -0
- package/dist/handlers/list-content.js +22 -0
- package/dist/handlers/list-content.js.map +1 -0
- package/dist/handlers/list-query.d.ts +7 -0
- package/dist/handlers/list-query.d.ts.map +1 -0
- package/dist/handlers/list-query.js +36 -0
- package/dist/handlers/list-query.js.map +1 -0
- package/dist/handlers/list-versions.d.ts +4 -0
- package/dist/handlers/list-versions.d.ts.map +1 -0
- package/dist/handlers/list-versions.js +19 -0
- package/dist/handlers/list-versions.js.map +1 -0
- package/dist/handlers/llm-credential.d.ts +46 -0
- package/dist/handlers/llm-credential.d.ts.map +1 -0
- package/dist/handlers/llm-credential.js +68 -0
- package/dist/handlers/llm-credential.js.map +1 -0
- package/dist/handlers/llm-resolve.d.ts +45 -0
- package/dist/handlers/llm-resolve.d.ts.map +1 -0
- package/dist/handlers/llm-resolve.js +126 -0
- package/dist/handlers/llm-resolve.js.map +1 -0
- package/dist/handlers/llm-settings.d.ts +19 -0
- package/dist/handlers/llm-settings.d.ts.map +1 -0
- package/dist/handlers/llm-settings.js +209 -0
- package/dist/handlers/llm-settings.js.map +1 -0
- package/dist/handlers/media-bulk-delete.d.ts +4 -0
- package/dist/handlers/media-bulk-delete.d.ts.map +1 -0
- package/dist/handlers/media-bulk-delete.js +19 -0
- package/dist/handlers/media-bulk-delete.js.map +1 -0
- package/dist/handlers/media-bulk-update.d.ts +4 -0
- package/dist/handlers/media-bulk-update.d.ts.map +1 -0
- package/dist/handlers/media-bulk-update.js +25 -0
- package/dist/handlers/media-bulk-update.js.map +1 -0
- package/dist/handlers/media-delete.d.ts +4 -0
- package/dist/handlers/media-delete.d.ts.map +1 -0
- package/dist/handlers/media-delete.js +27 -0
- package/dist/handlers/media-delete.js.map +1 -0
- package/dist/handlers/media-duplicate.d.ts +4 -0
- package/dist/handlers/media-duplicate.d.ts.map +1 -0
- package/dist/handlers/media-duplicate.js +20 -0
- package/dist/handlers/media-duplicate.js.map +1 -0
- package/dist/handlers/media-folders.d.ts +12 -0
- package/dist/handlers/media-folders.d.ts.map +1 -0
- package/dist/handlers/media-folders.js +119 -0
- package/dist/handlers/media-folders.js.map +1 -0
- package/dist/handlers/media-get.d.ts +4 -0
- package/dist/handlers/media-get.d.ts.map +1 -0
- package/dist/handlers/media-get.js +16 -0
- package/dist/handlers/media-get.js.map +1 -0
- package/dist/handlers/media-image-info.d.ts +4 -0
- package/dist/handlers/media-image-info.d.ts.map +1 -0
- package/dist/handlers/media-image-info.js +32 -0
- package/dist/handlers/media-image-info.js.map +1 -0
- package/dist/handlers/media-image.d.ts +11 -0
- package/dist/handlers/media-image.d.ts.map +1 -0
- package/dist/handlers/media-image.js +116 -0
- package/dist/handlers/media-image.js.map +1 -0
- package/dist/handlers/media-info.d.ts +4 -0
- package/dist/handlers/media-info.d.ts.map +1 -0
- package/dist/handlers/media-info.js +18 -0
- package/dist/handlers/media-info.js.map +1 -0
- package/dist/handlers/media-list.d.ts +4 -0
- package/dist/handlers/media-list.d.ts.map +1 -0
- package/dist/handlers/media-list.js +14 -0
- package/dist/handlers/media-list.js.map +1 -0
- package/dist/handlers/media-register.d.ts +4 -0
- package/dist/handlers/media-register.d.ts.map +1 -0
- package/dist/handlers/media-register.js +57 -0
- package/dist/handlers/media-register.js.map +1 -0
- package/dist/handlers/media-replace.d.ts +9 -0
- package/dist/handlers/media-replace.d.ts.map +1 -0
- package/dist/handlers/media-replace.js +53 -0
- package/dist/handlers/media-replace.js.map +1 -0
- package/dist/handlers/media-tags.d.ts +4 -0
- package/dist/handlers/media-tags.d.ts.map +1 -0
- package/dist/handlers/media-tags.js +9 -0
- package/dist/handlers/media-tags.js.map +1 -0
- package/dist/handlers/media-update.d.ts +4 -0
- package/dist/handlers/media-update.d.ts.map +1 -0
- package/dist/handlers/media-update.js +64 -0
- package/dist/handlers/media-update.js.map +1 -0
- package/dist/handlers/media-upload.d.ts +4 -0
- package/dist/handlers/media-upload.d.ts.map +1 -0
- package/dist/handlers/media-upload.js +26 -0
- package/dist/handlers/media-upload.js.map +1 -0
- package/dist/handlers/media-usage.d.ts +9 -0
- package/dist/handlers/media-usage.d.ts.map +1 -0
- package/dist/handlers/media-usage.js +36 -0
- package/dist/handlers/media-usage.js.map +1 -0
- package/dist/handlers/migration-conflicts.d.ts +13 -0
- package/dist/handlers/migration-conflicts.d.ts.map +1 -0
- package/dist/handlers/migration-conflicts.js +55 -0
- package/dist/handlers/migration-conflicts.js.map +1 -0
- package/dist/handlers/migration-status.d.ts +4 -0
- package/dist/handlers/migration-status.d.ts.map +1 -0
- package/dist/handlers/migration-status.js +34 -0
- package/dist/handlers/migration-status.js.map +1 -0
- package/dist/handlers/publish-content.d.ts +9 -0
- package/dist/handlers/publish-content.d.ts.map +1 -0
- package/dist/handlers/publish-content.js +47 -0
- package/dist/handlers/publish-content.js.map +1 -0
- package/dist/handlers/publish-impact.d.ts +11 -0
- package/dist/handlers/publish-impact.d.ts.map +1 -0
- package/dist/handlers/publish-impact.js +44 -0
- package/dist/handlers/publish-impact.js.map +1 -0
- package/dist/handlers/resolve-page.d.ts +9 -0
- package/dist/handlers/resolve-page.d.ts.map +1 -0
- package/dist/handlers/resolve-page.js +105 -0
- package/dist/handlers/resolve-page.js.map +1 -0
- package/dist/handlers/restore-version.d.ts +4 -0
- package/dist/handlers/restore-version.d.ts.map +1 -0
- package/dist/handlers/restore-version.js +69 -0
- package/dist/handlers/restore-version.js.map +1 -0
- package/dist/handlers/runtime-metadata.d.ts +6 -0
- package/dist/handlers/runtime-metadata.d.ts.map +1 -0
- package/dist/handlers/runtime-metadata.js +82 -0
- package/dist/handlers/runtime-metadata.js.map +1 -0
- package/dist/handlers/save-runtime-field.d.ts +4 -0
- package/dist/handlers/save-runtime-field.d.ts.map +1 -0
- package/dist/handlers/save-runtime-field.js +108 -0
- package/dist/handlers/save-runtime-field.js.map +1 -0
- package/dist/handlers/search-content.d.ts +9 -0
- package/dist/handlers/search-content.d.ts.map +1 -0
- package/dist/handlers/search-content.js +40 -0
- package/dist/handlers/search-content.js.map +1 -0
- package/dist/handlers/seo-config.d.ts +16 -0
- package/dist/handlers/seo-config.d.ts.map +1 -0
- package/dist/handlers/seo-config.js +250 -0
- package/dist/handlers/seo-config.js.map +1 -0
- package/dist/handlers/seo-document.d.ts +24 -0
- package/dist/handlers/seo-document.d.ts.map +1 -0
- package/dist/handlers/seo-document.js +119 -0
- package/dist/handlers/seo-document.js.map +1 -0
- package/dist/handlers/seo-enrich-archetype.d.ts +71 -0
- package/dist/handlers/seo-enrich-archetype.d.ts.map +1 -0
- package/dist/handlers/seo-enrich-archetype.js +250 -0
- package/dist/handlers/seo-enrich-archetype.js.map +1 -0
- package/dist/handlers/seo-enrich-meta.d.ts +40 -0
- package/dist/handlers/seo-enrich-meta.d.ts.map +1 -0
- package/dist/handlers/seo-enrich-meta.js +121 -0
- package/dist/handlers/seo-enrich-meta.js.map +1 -0
- package/dist/handlers/seo-enrich-runner.d.ts +65 -0
- package/dist/handlers/seo-enrich-runner.d.ts.map +1 -0
- package/dist/handlers/seo-enrich-runner.js +192 -0
- package/dist/handlers/seo-enrich-runner.js.map +1 -0
- package/dist/handlers/seo-enrich.d.ts +10 -0
- package/dist/handlers/seo-enrich.d.ts.map +1 -0
- package/dist/handlers/seo-enrich.js +166 -0
- package/dist/handlers/seo-enrich.js.map +1 -0
- package/dist/handlers/seo-generate.d.ts +4 -0
- package/dist/handlers/seo-generate.d.ts.map +1 -0
- package/dist/handlers/seo-generate.js +31 -0
- package/dist/handlers/seo-generate.js.map +1 -0
- package/dist/handlers/seo-impact.d.ts +36 -0
- package/dist/handlers/seo-impact.d.ts.map +1 -0
- package/dist/handlers/seo-impact.js +137 -0
- package/dist/handlers/seo-impact.js.map +1 -0
- package/dist/handlers/seo-indexnow.d.ts +11 -0
- package/dist/handlers/seo-indexnow.d.ts.map +1 -0
- package/dist/handlers/seo-indexnow.js +15 -0
- package/dist/handlers/seo-indexnow.js.map +1 -0
- package/dist/handlers/seo-llms-txt.d.ts +26 -0
- package/dist/handlers/seo-llms-txt.d.ts.map +1 -0
- package/dist/handlers/seo-llms-txt.js +99 -0
- package/dist/handlers/seo-llms-txt.js.map +1 -0
- package/dist/handlers/seo-preview.d.ts +8 -0
- package/dist/handlers/seo-preview.d.ts.map +1 -0
- package/dist/handlers/seo-preview.js +49 -0
- package/dist/handlers/seo-preview.js.map +1 -0
- package/dist/handlers/seo-robots.d.ts +22 -0
- package/dist/handlers/seo-robots.d.ts.map +1 -0
- package/dist/handlers/seo-robots.js +48 -0
- package/dist/handlers/seo-robots.js.map +1 -0
- package/dist/handlers/seo-sitemap.d.ts +68 -0
- package/dist/handlers/seo-sitemap.d.ts.map +1 -0
- package/dist/handlers/seo-sitemap.js +178 -0
- package/dist/handlers/seo-sitemap.js.map +1 -0
- package/dist/handlers/seo-status.d.ts +4 -0
- package/dist/handlers/seo-status.d.ts.map +1 -0
- package/dist/handlers/seo-status.js +61 -0
- package/dist/handlers/seo-status.js.map +1 -0
- package/dist/handlers/seo-structured-data.d.ts +4 -0
- package/dist/handlers/seo-structured-data.d.ts.map +1 -0
- package/dist/handlers/seo-structured-data.js +18 -0
- package/dist/handlers/seo-structured-data.js.map +1 -0
- package/dist/handlers/site-config.d.ts +8 -0
- package/dist/handlers/site-config.d.ts.map +1 -0
- package/dist/handlers/site-config.js +26 -0
- package/dist/handlers/site-config.js.map +1 -0
- package/dist/handlers/site-preview.d.ts +10 -0
- package/dist/handlers/site-preview.d.ts.map +1 -0
- package/dist/handlers/site-preview.js +54 -0
- package/dist/handlers/site-preview.js.map +1 -0
- package/dist/handlers/site-settings.d.ts +17 -0
- package/dist/handlers/site-settings.d.ts.map +1 -0
- package/dist/handlers/site-settings.js +75 -0
- package/dist/handlers/site-settings.js.map +1 -0
- package/dist/handlers/snapshot-create.d.ts +4 -0
- package/dist/handlers/snapshot-create.d.ts.map +1 -0
- package/dist/handlers/snapshot-create.js +15 -0
- package/dist/handlers/snapshot-create.js.map +1 -0
- package/dist/handlers/snapshot-delete.d.ts +4 -0
- package/dist/handlers/snapshot-delete.d.ts.map +1 -0
- package/dist/handlers/snapshot-delete.js +21 -0
- package/dist/handlers/snapshot-delete.js.map +1 -0
- package/dist/handlers/snapshot-get.d.ts +4 -0
- package/dist/handlers/snapshot-get.d.ts.map +1 -0
- package/dist/handlers/snapshot-get.js +17 -0
- package/dist/handlers/snapshot-get.js.map +1 -0
- package/dist/handlers/snapshot-list.d.ts +4 -0
- package/dist/handlers/snapshot-list.d.ts.map +1 -0
- package/dist/handlers/snapshot-list.js +9 -0
- package/dist/handlers/snapshot-list.js.map +1 -0
- package/dist/handlers/snapshot-restore.d.ts +4 -0
- package/dist/handlers/snapshot-restore.d.ts.map +1 -0
- package/dist/handlers/snapshot-restore.js +27 -0
- package/dist/handlers/snapshot-restore.js.map +1 -0
- package/dist/handlers/translation-status.d.ts +9 -0
- package/dist/handlers/translation-status.d.ts.map +1 -0
- package/dist/handlers/translation-status.js +68 -0
- package/dist/handlers/translation-status.js.map +1 -0
- package/dist/handlers/update-content.d.ts +4 -0
- package/dist/handlers/update-content.d.ts.map +1 -0
- package/dist/handlers/update-content.js +66 -0
- package/dist/handlers/update-content.js.map +1 -0
- package/dist/handlers/user-create.d.ts +4 -0
- package/dist/handlers/user-create.d.ts.map +1 -0
- package/dist/handlers/user-create.js +38 -0
- package/dist/handlers/user-create.js.map +1 -0
- package/dist/handlers/user-delete.d.ts +4 -0
- package/dist/handlers/user-delete.d.ts.map +1 -0
- package/dist/handlers/user-delete.js +25 -0
- package/dist/handlers/user-delete.js.map +1 -0
- package/dist/handlers/user-get.d.ts +4 -0
- package/dist/handlers/user-get.d.ts.map +1 -0
- package/dist/handlers/user-get.js +22 -0
- package/dist/handlers/user-get.js.map +1 -0
- package/dist/handlers/user-list.d.ts +4 -0
- package/dist/handlers/user-list.d.ts.map +1 -0
- package/dist/handlers/user-list.js +28 -0
- package/dist/handlers/user-list.js.map +1 -0
- package/dist/handlers/user-permissions.d.ts +6 -0
- package/dist/handlers/user-permissions.d.ts.map +1 -0
- package/dist/handlers/user-permissions.js +42 -0
- package/dist/handlers/user-permissions.js.map +1 -0
- package/dist/handlers/user-update.d.ts +4 -0
- package/dist/handlers/user-update.d.ts.map +1 -0
- package/dist/handlers/user-update.js +54 -0
- package/dist/handlers/user-update.js.map +1 -0
- package/dist/handlers/validate-all.d.ts +4 -0
- package/dist/handlers/validate-all.d.ts.map +1 -0
- package/dist/handlers/validate-all.js +14 -0
- package/dist/handlers/validate-all.js.map +1 -0
- package/dist/handlers/version-retention.d.ts +6 -0
- package/dist/handlers/version-retention.d.ts.map +1 -0
- package/dist/handlers/version-retention.js +40 -0
- package/dist/handlers/version-retention.js.map +1 -0
- package/dist/handlers/webhook-deliveries.d.ts +4 -0
- package/dist/handlers/webhook-deliveries.d.ts.map +1 -0
- package/dist/handlers/webhook-deliveries.js +24 -0
- package/dist/handlers/webhook-deliveries.js.map +1 -0
- package/dist/handlers/webhook-retry.d.ts +11 -0
- package/dist/handlers/webhook-retry.d.ts.map +1 -0
- package/dist/handlers/webhook-retry.js +69 -0
- package/dist/handlers/webhook-retry.js.map +1 -0
- package/dist/head.d.ts +9 -0
- package/dist/head.d.ts.map +1 -0
- package/dist/head.js +28 -0
- package/dist/head.js.map +1 -0
- package/dist/hooks.d.ts +34 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +19 -0
- package/dist/hooks.js.map +1 -0
- package/dist/image-cache.d.ts +47 -0
- package/dist/image-cache.d.ts.map +1 -0
- package/dist/image-cache.js +112 -0
- package/dist/image-cache.js.map +1 -0
- package/dist/image-dimensions.d.ts +12 -0
- package/dist/image-dimensions.d.ts.map +1 -0
- package/dist/image-dimensions.js +129 -0
- package/dist/image-dimensions.js.map +1 -0
- package/dist/image-optimizer.d.ts +86 -0
- package/dist/image-optimizer.d.ts.map +1 -0
- package/dist/image-optimizer.js +206 -0
- package/dist/image-optimizer.js.map +1 -0
- package/dist/image-presets.d.ts +17 -0
- package/dist/image-presets.d.ts.map +1 -0
- package/dist/image-presets.js +50 -0
- package/dist/image-presets.js.map +1 -0
- package/dist/image-url.d.ts +26 -0
- package/dist/image-url.d.ts.map +1 -0
- package/dist/image-url.js +47 -0
- package/dist/image-url.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt.d.ts +54 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +114 -0
- package/dist/jwt.js.map +1 -0
- package/dist/locale-fallback.d.ts +18 -0
- package/dist/locale-fallback.d.ts.map +1 -0
- package/dist/locale-fallback.js +42 -0
- package/dist/locale-fallback.js.map +1 -0
- package/dist/media-library.d.ts +46 -0
- package/dist/media-library.d.ts.map +1 -0
- package/dist/media-library.js +231 -0
- package/dist/media-library.js.map +1 -0
- package/dist/media-reference-updater.d.ts +24 -0
- package/dist/media-reference-updater.d.ts.map +1 -0
- package/dist/media-reference-updater.js +124 -0
- package/dist/media-reference-updater.js.map +1 -0
- package/dist/media-references.d.ts +14 -0
- package/dist/media-references.d.ts.map +1 -0
- package/dist/media-references.js +25 -0
- package/dist/media-references.js.map +1 -0
- package/dist/merged-schema.d.ts +10 -0
- package/dist/merged-schema.d.ts.map +1 -0
- package/dist/merged-schema.js +21 -0
- package/dist/merged-schema.js.map +1 -0
- package/dist/middleware/auth.d.ts +21 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +82 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/oidc-state.d.ts +42 -0
- package/dist/oidc-state.d.ts.map +1 -0
- package/dist/oidc-state.js +72 -0
- package/dist/oidc-state.js.map +1 -0
- package/dist/oidc.d.ts +83 -0
- package/dist/oidc.d.ts.map +1 -0
- package/dist/oidc.js +226 -0
- package/dist/oidc.js.map +1 -0
- package/dist/openapi.d.ts +13 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +133 -0
- package/dist/openapi.js.map +1 -0
- package/dist/permissions.d.ts +37 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +69 -0
- package/dist/permissions.js.map +1 -0
- package/dist/plugins.d.ts +64 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +73 -0
- package/dist/plugins.js.map +1 -0
- package/dist/preview-token.d.ts +13 -0
- package/dist/preview-token.d.ts.map +1 -0
- package/dist/preview-token.js +45 -0
- package/dist/preview-token.js.map +1 -0
- package/dist/public-cache.d.ts +8 -0
- package/dist/public-cache.d.ts.map +1 -0
- package/dist/public-cache.js +8 -0
- package/dist/public-cache.js.map +1 -0
- package/dist/reference-resolver.d.ts +21 -0
- package/dist/reference-resolver.d.ts.map +1 -0
- package/dist/reference-resolver.js +128 -0
- package/dist/reference-resolver.js.map +1 -0
- package/dist/return-to.d.ts +7 -0
- package/dist/return-to.d.ts.map +1 -0
- package/dist/return-to.js +15 -0
- package/dist/return-to.js.map +1 -0
- package/dist/router.d.ts +14 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +51 -0
- package/dist/router.js.map +1 -0
- package/dist/runtime-field-checks.d.ts +11 -0
- package/dist/runtime-field-checks.d.ts.map +1 -0
- package/dist/runtime-field-checks.js +72 -0
- package/dist/runtime-field-checks.js.map +1 -0
- package/dist/save-document.d.ts +71 -0
- package/dist/save-document.d.ts.map +1 -0
- package/dist/save-document.js +213 -0
- package/dist/save-document.js.map +1 -0
- package/dist/seo-compose.d.ts +50 -0
- package/dist/seo-compose.d.ts.map +1 -0
- package/dist/seo-compose.js +104 -0
- package/dist/seo-compose.js.map +1 -0
- package/dist/seo-config-snapshot.d.ts +10 -0
- package/dist/seo-config-snapshot.d.ts.map +1 -0
- package/dist/seo-config-snapshot.js +16 -0
- package/dist/seo-config-snapshot.js.map +1 -0
- package/dist/seo-loader.d.ts +10 -0
- package/dist/seo-loader.d.ts.map +1 -0
- package/dist/seo-loader.js +14 -0
- package/dist/seo-loader.js.map +1 -0
- package/dist/seo-site-findings.d.ts +27 -0
- package/dist/seo-site-findings.d.ts.map +1 -0
- package/dist/seo-site-findings.js +87 -0
- package/dist/seo-site-findings.js.map +1 -0
- package/dist/seo-subsystem.d.ts +28 -0
- package/dist/seo-subsystem.d.ts.map +1 -0
- package/dist/seo-subsystem.js +62 -0
- package/dist/seo-subsystem.js.map +1 -0
- package/dist/seo-validation.d.ts +20 -0
- package/dist/seo-validation.d.ts.map +1 -0
- package/dist/seo-validation.js +96 -0
- package/dist/seo-validation.js.map +1 -0
- package/dist/types.d.ts +126 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.d.ts +107 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +199 -0
- package/dist/validators.js.map +1 -0
- package/dist/webhooks.d.ts +29 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +123 -0
- package/dist/webhooks.js.map +1 -0
- package/dist/workload-identity.d.ts +23 -0
- package/dist/workload-identity.d.ts.map +1 -0
- package/dist/workload-identity.js +145 -0
- package/dist/workload-identity.js.map +1 -0
- package/package.json +50 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Descoped
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ApiContext } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The site's active locales: the list an admin chose in Setup › Locales, else
|
|
4
|
+
* the configured ones. A stored locale the configuration no longer lists is
|
|
5
|
+
* left out, and the configuration's default locale is always active.
|
|
6
|
+
*/
|
|
7
|
+
export declare function activeLocales(ctx: ApiContext): Promise<{
|
|
8
|
+
locales: string[];
|
|
9
|
+
stored: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=active-locales.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-locales.d.ts","sourceRoot":"","sources":["../src/active-locales.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC;IAC5D,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,OAAO,CAAA;CAChB,CAAC,CAUD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The site's active locales: the list an admin chose in Setup › Locales, else
|
|
3
|
+
* the configured ones. A stored locale the configuration no longer lists is
|
|
4
|
+
* left out, and the configuration's default locale is always active.
|
|
5
|
+
*/
|
|
6
|
+
export async function activeLocales(ctx) {
|
|
7
|
+
const { defaultLocale, supportedLocales: configured } = ctx.config.site;
|
|
8
|
+
const stored = await ctx.siteSettingsAdapter?.getSetting('supportedLocales');
|
|
9
|
+
const chosen = stored ? storedLocales(stored) : null;
|
|
10
|
+
if (!chosen)
|
|
11
|
+
return { locales: [...configured], stored: false };
|
|
12
|
+
const kept = chosen.filter((locale) => configured.includes(locale));
|
|
13
|
+
return {
|
|
14
|
+
locales: kept.includes(defaultLocale) ? kept : [defaultLocale, ...kept],
|
|
15
|
+
stored: true,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** The stored list of locale codes, or null when the setting is not one */
|
|
19
|
+
function storedLocales(value) {
|
|
20
|
+
let parsed;
|
|
21
|
+
try {
|
|
22
|
+
parsed = JSON.parse(value);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (!Array.isArray(parsed))
|
|
28
|
+
return null;
|
|
29
|
+
return parsed.filter((locale) => typeof locale === 'string');
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=active-locales.js.map
|
|
@@ -0,0 +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,MAAM,KAAK,QAAQ,CAAC,CAAA;AAChF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ApiContext, ApiRequest, ApiResponse, AuthenticatedUser } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The signed-in user the assistant acts for, or the refusal: 401 without a
|
|
4
|
+
* user, or for the anonymous reader of a site with sign-in (who must not learn
|
|
5
|
+
* the provider or drive the model); 403 below `assistant.role`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function requireAssistantUser(ctx: ApiContext): {
|
|
8
|
+
ok: true;
|
|
9
|
+
user: AuthenticatedUser;
|
|
10
|
+
} | {
|
|
11
|
+
ok: false;
|
|
12
|
+
response: ApiResponse;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* 415 unless the request body is declared JSON. Any body is parsed as JSON on
|
|
16
|
+
* the way in, so without this a cross-site `text/plain` form post would reach
|
|
17
|
+
* the handler; a JSON request from another site needs a CORS preflight the API
|
|
18
|
+
* never grants.
|
|
19
|
+
*/
|
|
20
|
+
export declare function requireJsonBody(req: ApiRequest): ApiResponse | null;
|
|
21
|
+
declare const ROLE_ORDER: readonly ["admin", "editor", "viewer"];
|
|
22
|
+
/** The user's highest role — the only thing about the user the model is told */
|
|
23
|
+
export declare function highestRole(user: AuthenticatedUser): (typeof ROLE_ORDER)[number];
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/assistant/access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEzF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,UAAU,GACd;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,WAAW,CAAA;CAAE,CAQ9E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,CAKnE;AAED,QAAA,MAAM,UAAU,wCAAyC,CAAA;AAEzD,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,IAAI,EAAE,iBAAiB,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAEhF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { requireRole } from '../permissions.js';
|
|
2
|
+
/**
|
|
3
|
+
* The signed-in user the assistant acts for, or the refusal: 401 without a
|
|
4
|
+
* user, or for the anonymous reader of a site with sign-in (who must not learn
|
|
5
|
+
* the provider or drive the model); 403 below `assistant.role`.
|
|
6
|
+
*/
|
|
7
|
+
export function requireAssistantUser(ctx) {
|
|
8
|
+
const user = ctx.auth;
|
|
9
|
+
if (!user || (ctx.config.auth.mode !== 'none' && user.id === 'anonymous')) {
|
|
10
|
+
return { ok: false, response: { status: 401, body: { error: 'Authentication required' } } };
|
|
11
|
+
}
|
|
12
|
+
const denied = requireRole(user, ctx.config.assistant.role);
|
|
13
|
+
if (denied)
|
|
14
|
+
return { ok: false, response: denied };
|
|
15
|
+
return { ok: true, user };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 415 unless the request body is declared JSON. Any body is parsed as JSON on
|
|
19
|
+
* the way in, so without this a cross-site `text/plain` form post would reach
|
|
20
|
+
* the handler; a JSON request from another site needs a CORS preflight the API
|
|
21
|
+
* never grants.
|
|
22
|
+
*/
|
|
23
|
+
export function requireJsonBody(req) {
|
|
24
|
+
const contentType = req.headers?.['content-type'] ?? '';
|
|
25
|
+
const mediaType = contentType.split(';')[0]?.trim().toLowerCase();
|
|
26
|
+
if (mediaType === 'application/json')
|
|
27
|
+
return null;
|
|
28
|
+
return { status: 415, body: { error: 'Content-Type must be application/json' } };
|
|
29
|
+
}
|
|
30
|
+
const ROLE_ORDER = ['admin', 'editor', 'viewer'];
|
|
31
|
+
/** The user's highest role — the only thing about the user the model is told */
|
|
32
|
+
export function highestRole(user) {
|
|
33
|
+
return ROLE_ORDER.find((role) => user.roles.includes(role)) ?? 'viewer';
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.js","sourceRoot":"","sources":["../../src/assistant/access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,GAAe;IAEf,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;IACrB,IAAI,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,EAAE,KAAK,WAAW,CAAC,EAAE,CAAC;QAC1E,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE,EAAE,EAAE,CAAA;IAC7F,CAAC;IACD,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAC3D,IAAI,MAAM;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AAC3B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAe;IAC7C,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,CAAA;IACvD,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACjE,IAAI,SAAS,KAAK,kBAAkB;QAAE,OAAO,IAAI,CAAA;IACjD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,uCAAuC,EAAE,EAAE,CAAA;AAClF,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAA;AAEzD,gFAAgF;AAChF,MAAM,UAAU,WAAW,CAAC,IAAuB;IACjD,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAA;AACzE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ChatAdapter, ChatMessage } from '@krantho/ai';
|
|
2
|
+
import type { AssistantSection } from '@krantho/config';
|
|
3
|
+
import type { AssistantChatRequest } from './protocol.js';
|
|
4
|
+
import type { Emit } from './sse-stream.js';
|
|
5
|
+
import { type AssistantTool, type ToolOutcome, type ToolRunContext } from './tool-registry.js';
|
|
6
|
+
export interface AgentLoopOptions {
|
|
7
|
+
chat: ChatAdapter;
|
|
8
|
+
system: string;
|
|
9
|
+
/** The client's text turns, mapped to ChatMessages */
|
|
10
|
+
history: readonly ChatMessage[];
|
|
11
|
+
tools: readonly AssistantTool[];
|
|
12
|
+
run: Omit<ToolRunContext, 'spend'>;
|
|
13
|
+
limits: AssistantSection['limits'];
|
|
14
|
+
emit: Emit;
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The client's turns as chat messages, one to one; consecutive messages of the
|
|
19
|
+
* same role are merged with a blank line between (providers require alternation).
|
|
20
|
+
*/
|
|
21
|
+
export declare function toChatHistory(messages: AssistantChatRequest['messages']): ChatMessage[];
|
|
22
|
+
/** Validate a call's input with the tool's schema, then run it; a failure never ends the stream */
|
|
23
|
+
export declare function executeTool(tool: AssistantTool, input: Record<string, unknown>, run: ToolRunContext): Promise<ToolOutcome>;
|
|
24
|
+
/**
|
|
25
|
+
* The agent loop of one chat request: model turns streamed to the client, the
|
|
26
|
+
* tools they call run in order, bounded by turns, tool calls and tokens. The
|
|
27
|
+
* last allowed turn and every turn after the tool limit forbid tool calls, so
|
|
28
|
+
* the request ends with an answer.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runAgentLoop(o: AgentLoopOptions): Promise<void>;
|
|
31
|
+
//# sourceMappingURL=agent-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../../src/assistant/agent-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EAEX,WAAW,EAKZ,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,KAAK,EAAE,oBAAoB,EAAuB,MAAM,eAAe,CAAA;AAC9E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,cAAc,EAEpB,MAAM,oBAAoB,CAAA;AAG3B,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,sDAAsD;IACtD,OAAO,EAAE,SAAS,WAAW,EAAE,CAAA;IAC/B,KAAK,EAAE,SAAS,aAAa,EAAE,CAAA;IAC/B,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;IAClC,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAClC,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,WAAW,CAAA;CACpB;AAuBD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,oBAAoB,CAAC,UAAU,CAAC,GAAG,WAAW,EAAE,CAWvF;AAsED,mGAAmG;AACnG,wBAAsB,WAAW,CAC/B,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC,WAAW,CAAC,CAatB;AA8DD;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsCrE"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { toolDefinitions, } from './tool-registry.js';
|
|
2
|
+
import { failure } from './tools/support.js';
|
|
3
|
+
/**
|
|
4
|
+
* The client's turns as chat messages, one to one; consecutive messages of the
|
|
5
|
+
* same role are merged with a blank line between (providers require alternation).
|
|
6
|
+
*/
|
|
7
|
+
export function toChatHistory(messages) {
|
|
8
|
+
const history = [];
|
|
9
|
+
for (const message of messages) {
|
|
10
|
+
const last = history[history.length - 1];
|
|
11
|
+
if (last && last.role === message.role) {
|
|
12
|
+
last.content = `${last.content}\n\n${message.content}`;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
history.push({ role: message.role, content: message.content });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return history;
|
|
19
|
+
}
|
|
20
|
+
/** The provider's error as the user reads it; an unsupported model is named with its provider */
|
|
21
|
+
function errorMessage(chat, event) {
|
|
22
|
+
if (event.code !== 'tools_unsupported')
|
|
23
|
+
return event.message;
|
|
24
|
+
return `The model \`${chat.model}\` on \`${chat.provider}\` does not support tool use, which the assistant needs. Choose a model that does in Setup › AI provider, or set assistant.model.`;
|
|
25
|
+
}
|
|
26
|
+
function doneReason(stop) {
|
|
27
|
+
if (stop === 'max_tokens' || stop === 'refusal')
|
|
28
|
+
return stop;
|
|
29
|
+
return 'end_turn';
|
|
30
|
+
}
|
|
31
|
+
/** Count usage toward the budget; a turn reporting no input tokens is estimated from what was sent */
|
|
32
|
+
function countUsage(o, state, event, sentChars) {
|
|
33
|
+
state.inputTokens += event.inputTokens > 0 ? event.inputTokens : Math.ceil(sentChars / 4);
|
|
34
|
+
state.outputTokens += event.outputTokens;
|
|
35
|
+
o.emit({ type: 'usage', inputTokens: state.inputTokens, outputTokens: state.outputTokens });
|
|
36
|
+
}
|
|
37
|
+
/** Stream one model turn to the client; a provider error ends the request */
|
|
38
|
+
async function streamTurn(o, messages, definitions, state) {
|
|
39
|
+
const lastTurn = state.turns === o.limits.maxTurns;
|
|
40
|
+
const toolChoice = state.toolCalls >= o.limits.maxToolCalls || lastTurn ? 'none' : 'auto';
|
|
41
|
+
const request = {
|
|
42
|
+
system: o.system,
|
|
43
|
+
messages,
|
|
44
|
+
tools: definitions,
|
|
45
|
+
toolChoice,
|
|
46
|
+
maxTokens: o.limits.maxTokens,
|
|
47
|
+
signal: o.signal,
|
|
48
|
+
};
|
|
49
|
+
const sentChars = JSON.stringify([o.system, messages, definitions]).length;
|
|
50
|
+
let text = '';
|
|
51
|
+
const calls = [];
|
|
52
|
+
let stop = 'other';
|
|
53
|
+
let replay;
|
|
54
|
+
for await (const event of o.chat.stream(request)) {
|
|
55
|
+
if (event.type === 'text') {
|
|
56
|
+
// A turn after tool calls continues the answer: keep it apart from what the last turn said
|
|
57
|
+
if (text === '' && state.said)
|
|
58
|
+
o.emit({ type: 'text', text: '\n\n' });
|
|
59
|
+
text += event.text;
|
|
60
|
+
o.emit({ type: 'text', text: event.text });
|
|
61
|
+
}
|
|
62
|
+
else if (event.type === 'tool_call') {
|
|
63
|
+
calls.push(event.call);
|
|
64
|
+
}
|
|
65
|
+
else if (event.type === 'usage') {
|
|
66
|
+
countUsage(o, state, event, sentChars);
|
|
67
|
+
}
|
|
68
|
+
else if (event.type === 'stop') {
|
|
69
|
+
stop = event.reason;
|
|
70
|
+
replay = event.replay;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
o.emit({ type: 'error', code: event.code, message: errorMessage(o.chat, event) });
|
|
74
|
+
o.emit({ type: 'done', reason: event.code === 'aborted' ? 'aborted' : 'error' });
|
|
75
|
+
return { ok: false };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { ok: true, text, calls, stop, replay };
|
|
79
|
+
}
|
|
80
|
+
/** Validate a call's input with the tool's schema, then run it; a failure never ends the stream */
|
|
81
|
+
export async function executeTool(tool, input, run) {
|
|
82
|
+
const parsed = tool.input.safeParse(input);
|
|
83
|
+
if (!parsed.success) {
|
|
84
|
+
const issues = parsed.error.issues.map((issue) => `${issue.path.join('.') || '(input)'}: ${issue.message}`);
|
|
85
|
+
return failure(`Invalid arguments — ${issues.join('; ')}`);
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return await tool.run(parsed.data, run);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
return failure(err instanceof Error ? err.message : 'The tool failed');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** A result as the model receives it: JSON within the per-result limit */
|
|
95
|
+
function resultContent(result, limit) {
|
|
96
|
+
const content = JSON.stringify(result);
|
|
97
|
+
if (content.length <= limit)
|
|
98
|
+
return content;
|
|
99
|
+
return JSON.stringify({ ok: false, error: 'Result too large; narrow the request' });
|
|
100
|
+
}
|
|
101
|
+
function toolMessage(call, result, limit) {
|
|
102
|
+
return {
|
|
103
|
+
role: 'tool',
|
|
104
|
+
toolCallId: call.id,
|
|
105
|
+
content: resultContent(result, limit),
|
|
106
|
+
isError: result['ok'] === false,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** Run one tool call within the request's limits and report it to the client */
|
|
110
|
+
async function runToolCall(o, call, state) {
|
|
111
|
+
const limit = o.limits.toolResultChars;
|
|
112
|
+
if (state.toolCalls >= o.limits.maxToolCalls) {
|
|
113
|
+
return toolMessage(call, { ok: false, error: 'Tool limit reached for this request; answer with what you have.' }, limit);
|
|
114
|
+
}
|
|
115
|
+
if (call.inputError) {
|
|
116
|
+
return toolMessage(call, { ok: false, error: `Arguments were not a JSON object: ${call.inputError}` }, limit);
|
|
117
|
+
}
|
|
118
|
+
const tool = o.tools.find((candidate) => candidate.name === call.name);
|
|
119
|
+
if (!tool) {
|
|
120
|
+
const summary = `No tool named ${call.name}`;
|
|
121
|
+
o.emit({
|
|
122
|
+
type: 'activity',
|
|
123
|
+
activity: { id: call.id, tool: call.name, status: 'failed', summary, documents: [] },
|
|
124
|
+
});
|
|
125
|
+
return toolMessage(call, { ok: false, error: 'No such tool' }, limit);
|
|
126
|
+
}
|
|
127
|
+
state.toolCalls++;
|
|
128
|
+
const parsed = tool.input.safeParse(call.input);
|
|
129
|
+
const label = parsed.success ? tool.describe(parsed.data) : tool.name;
|
|
130
|
+
o.emit({ type: 'tool', id: call.id, tool: tool.name, label });
|
|
131
|
+
const spend = (usage) => {
|
|
132
|
+
state.inputTokens += usage.inputTokens;
|
|
133
|
+
state.outputTokens += usage.outputTokens;
|
|
134
|
+
};
|
|
135
|
+
const outcome = await executeTool(tool, call.input, { ...o.run, callId: call.id, spend });
|
|
136
|
+
o.emit({ type: 'activity', activity: { id: call.id, tool: tool.name, ...outcome.activity } });
|
|
137
|
+
return toolMessage(call, outcome.result, limit);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The agent loop of one chat request: model turns streamed to the client, the
|
|
141
|
+
* tools they call run in order, bounded by turns, tool calls and tokens. The
|
|
142
|
+
* last allowed turn and every turn after the tool limit forbid tool calls, so
|
|
143
|
+
* the request ends with an answer.
|
|
144
|
+
*/
|
|
145
|
+
export async function runAgentLoop(o) {
|
|
146
|
+
const messages = [...o.history];
|
|
147
|
+
const definitions = toolDefinitions(o.tools);
|
|
148
|
+
const state = { turns: 0, toolCalls: 0, inputTokens: 0, outputTokens: 0, said: false };
|
|
149
|
+
while (state.turns < o.limits.maxTurns) {
|
|
150
|
+
state.turns++;
|
|
151
|
+
if (o.signal.aborted) {
|
|
152
|
+
o.emit({ type: 'done', reason: 'aborted' });
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (state.inputTokens + state.outputTokens >= o.limits.maxRequestTokens) {
|
|
156
|
+
const message = 'The assistant used its token budget for this request. Ask again to continue.';
|
|
157
|
+
o.emit({ type: 'error', code: 'limit', message });
|
|
158
|
+
o.emit({ type: 'done', reason: 'limit' });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const turn = await streamTurn(o, messages, definitions, state);
|
|
162
|
+
if (!turn.ok)
|
|
163
|
+
return;
|
|
164
|
+
if (turn.text !== '')
|
|
165
|
+
state.said = true;
|
|
166
|
+
if (turn.calls.length === 0) {
|
|
167
|
+
o.emit({ type: 'done', reason: doneReason(turn.stop) });
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
messages.push({
|
|
171
|
+
role: 'assistant',
|
|
172
|
+
content: turn.text,
|
|
173
|
+
toolCalls: turn.calls,
|
|
174
|
+
replay: turn.replay,
|
|
175
|
+
});
|
|
176
|
+
for (const call of turn.calls)
|
|
177
|
+
messages.push(await runToolCall(o, call, state));
|
|
178
|
+
}
|
|
179
|
+
const message = `The assistant stopped after ${o.limits.maxTurns} steps. Ask again to continue.`;
|
|
180
|
+
o.emit({ type: 'error', code: 'limit', message });
|
|
181
|
+
o.emit({ type: 'done', reason: 'limit' });
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=agent-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-loop.js","sourceRoot":"","sources":["../../src/assistant/agent-loop.ts"],"names":[],"mappings":"AAYA,OAAO,EAIL,eAAe,GAChB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAmC5C;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,QAA0C;IACtE,MAAM,OAAO,GAAkB,EAAE,CAAA;IACjC,KAAK,MA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CAAC;YACZ,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,SAAS,EAAE,IAAI,CAAC,KAAK;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAA;QACF,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK;YAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;IACjF,CAAC;IAED,MAAM,OAAO,GAAG,+BAA+B,CAAC,CAAC,MAAM,CAAC,QAAQ,gCAAgC,CAAA;IAChG,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;IACjD,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;AAC3C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ApiContext, ApiHandler, ApiResponse } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Run a REST handler in-process with the request's authenticated context. The
|
|
4
|
+
* handlers called this way read only params, query and body.
|
|
5
|
+
*/
|
|
6
|
+
export declare function callHandler(handler: ApiHandler, ctx: ApiContext, req: {
|
|
7
|
+
params?: Record<string, string>;
|
|
8
|
+
query?: Record<string, string>;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
}): Promise<ApiResponse>;
|
|
11
|
+
/** The error message of a non-2xx handler response */
|
|
12
|
+
export declare function responseError(response: ApiResponse): string;
|
|
13
|
+
/** Whether a handler response is a success */
|
|
14
|
+
export declare function isSuccess(response: ApiResponse): boolean;
|
|
15
|
+
//# sourceMappingURL=call-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-handler.d.ts","sourceRoot":"","sources":["../../src/assistant/call-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEtE;;;GAGG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,UAAU,EACnB,GAAG,EAAE,UAAU,EACf,GAAG,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GACvF,OAAO,CAAC,WAAW,CAAC,CAYtB;AAED,sDAAsD;AACtD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,CAG3D;AAED,8CAA8C;AAC9C,wBAAgB,SAAS,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAExD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run a REST handler in-process with the request's authenticated context. The
|
|
3
|
+
* handlers called this way read only params, query and body.
|
|
4
|
+
*/
|
|
5
|
+
export function callHandler(handler, ctx, req) {
|
|
6
|
+
return handler({
|
|
7
|
+
method: 'POST',
|
|
8
|
+
path: '',
|
|
9
|
+
params: req.params ?? {},
|
|
10
|
+
query: req.query ?? {},
|
|
11
|
+
body: req.body,
|
|
12
|
+
headers: {},
|
|
13
|
+
}, ctx);
|
|
14
|
+
}
|
|
15
|
+
/** The error message of a non-2xx handler response */
|
|
16
|
+
export function responseError(response) {
|
|
17
|
+
const body = response.body;
|
|
18
|
+
return typeof body?.error === 'string' ? body.error : `Request failed (${response.status})`;
|
|
19
|
+
}
|
|
20
|
+
/** Whether a handler response is a success */
|
|
21
|
+
export function isSuccess(response) {
|
|
22
|
+
return response.status >= 200 && response.status < 300;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=call-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-handler.js","sourceRoot":"","sources":["../../src/assistant/call-handler.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,OAAmB,EACnB,GAAe,EACf,GAAwF;IAExF,OAAO,OAAO,CACZ;QACE,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,EAAE;QACR,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE;QACxB,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE;QACtB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,EAAE;KACZ,EACD,GAAG,CACJ,CAAA;AACH,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,aAAa,CAAC,QAAqB;IACjD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAkC,CAAA;IACxD,OAAO,OAAO,IAAI,EAAE,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,mBAAmB,QAAQ,CAAC,MAAM,GAAG,CAAA;AAC7F,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,SAAS,CAAC,QAAqB;IAC7C,OAAO,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAA;AACxD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApiHandler } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* POST /api/assistant/chat — run the agent loop for the user's conversation and
|
|
4
|
+
* stream its events (`text/event-stream`). Errors before the stream starts are
|
|
5
|
+
* JSON: 400/413 request, 401/403 access, 415 content type, 503 no model.
|
|
6
|
+
*/
|
|
7
|
+
export declare const assistantChat: ApiHandler;
|
|
8
|
+
//# sourceMappingURL=chat-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-handler.d.ts","sourceRoot":"","sources":["../../src/assistant/chat-handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAc,UAAU,EAAe,MAAM,aAAa,CAAA;AA2CtE;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,UAmC3B,CAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { llmCredentialLeaf } from '@krantho/config';
|
|
2
|
+
import { resolveChatAdapter } from '../handlers/llm-resolve.js';
|
|
3
|
+
import { getMergedSchema } from '../merged-schema.js';
|
|
4
|
+
import { highestRole, requireAssistantUser, requireJsonBody } from './access.js';
|
|
5
|
+
import { runAgentLoop, toChatHistory } from './agent-loop.js';
|
|
6
|
+
import { parseChatRequest } from './chat-request.js';
|
|
7
|
+
import { createEventStream, EVENT_STREAM_HEADERS } from './sse-stream.js';
|
|
8
|
+
import { buildSystemPrompt } from './system-prompt.js';
|
|
9
|
+
import { toolsForUser } from './tool-registry.js';
|
|
10
|
+
import { createFramer } from './untrusted.js';
|
|
11
|
+
import { WritePolicy } from './write-policy.js';
|
|
12
|
+
/** The chat adapter, or the 503 that says why the assistant cannot reach a model */
|
|
13
|
+
async function resolveChat(ctx, requested) {
|
|
14
|
+
let resolved;
|
|
15
|
+
try {
|
|
16
|
+
resolved = await resolveChatAdapter(ctx, ctx.config.assistant, requested);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
const error = err instanceof Error ? err.message : 'The LLM is not configured';
|
|
20
|
+
return { ok: false, response: { status: 503, body: { error, code: 'llm_unconfigured' } } };
|
|
21
|
+
}
|
|
22
|
+
if (resolved.credential === 'none' && resolved.chat.provider !== 'ollama') {
|
|
23
|
+
const { provider } = resolved.chat;
|
|
24
|
+
const env = llmCredentialLeaf(ctx.config.llm, provider)?.env;
|
|
25
|
+
const error = `No credential for ${provider}. Set ${env ?? 'its key'} in the environment, or save a key for it in Setup › AI provider.`;
|
|
26
|
+
return { ok: false, response: { status: 503, body: { error, code: 'llm_credential_missing' } } };
|
|
27
|
+
}
|
|
28
|
+
return { ok: true, resolved };
|
|
29
|
+
}
|
|
30
|
+
/** Each collection's field names, from its merged schema (code and runtime fields) */
|
|
31
|
+
async function collectionFields(ctx) {
|
|
32
|
+
const collections = [];
|
|
33
|
+
for (const [name, collectionDef] of ctx.contentConfig.collections) {
|
|
34
|
+
const schema = await getMergedSchema(collectionDef, ctx.adapter);
|
|
35
|
+
collections.push({ name, fields: Object.keys(schema.shape) });
|
|
36
|
+
}
|
|
37
|
+
return collections;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* POST /api/assistant/chat — run the agent loop for the user's conversation and
|
|
41
|
+
* stream its events (`text/event-stream`). Errors before the stream starts are
|
|
42
|
+
* JSON: 400/413 request, 401/403 access, 415 content type, 503 no model.
|
|
43
|
+
*/
|
|
44
|
+
export const assistantChat = async (req, ctx) => {
|
|
45
|
+
const access = requireAssistantUser(ctx);
|
|
46
|
+
if (!access.ok)
|
|
47
|
+
return access.response;
|
|
48
|
+
const notJson = requireJsonBody(req);
|
|
49
|
+
if (notJson)
|
|
50
|
+
return notJson;
|
|
51
|
+
const parsed = parseChatRequest(req.body, ctx);
|
|
52
|
+
if (!parsed.ok)
|
|
53
|
+
return parsed.response;
|
|
54
|
+
const chat = await resolveChat(ctx, parsed.value.provider);
|
|
55
|
+
if (!chat.ok)
|
|
56
|
+
return chat.response;
|
|
57
|
+
const system = buildSystemPrompt({
|
|
58
|
+
site: ctx.config.site,
|
|
59
|
+
role: highestRole(access.user),
|
|
60
|
+
context: parsed.value.context,
|
|
61
|
+
collections: await collectionFields(ctx),
|
|
62
|
+
today: new Date().toISOString().slice(0, 10),
|
|
63
|
+
});
|
|
64
|
+
const tools = toolsForUser(ctx);
|
|
65
|
+
const framer = createFramer();
|
|
66
|
+
const writes = new WritePolicy();
|
|
67
|
+
const body = createEventStream((emit, signal) => runAgentLoop({
|
|
68
|
+
chat: chat.resolved.chat,
|
|
69
|
+
system,
|
|
70
|
+
history: toChatHistory(parsed.value.messages),
|
|
71
|
+
tools,
|
|
72
|
+
run: { ctx, callId: '', writes, frame: framer.frame, signal },
|
|
73
|
+
limits: ctx.config.assistant.limits,
|
|
74
|
+
emit,
|
|
75
|
+
signal,
|
|
76
|
+
}), req.rawRequest?.signal);
|
|
77
|
+
return { status: 200, headers: { ...EVENT_STREAM_HEADERS }, body };
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=chat-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-handler.js","sourceRoot":"","sources":["../../src/assistant/chat-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAqB,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,oFAAoF;AACpF,KAAK,UAAU,WAAW,CACxB,GAAe,EACf,SAA6B;IAE7B,IAAI,QAAsB,CAAA;IAC1B,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IAC3E,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,MAAM,KAAK,GAAG,GAAG,YAAY,K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AAG,iBAAiB,CAC5B,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CACf,YAAY,CAAC;QACX,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;QACxB,MAAM;QACN,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC7C,KAAK;QACL,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE;QAC7D,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM;QACnC,IAAI;QACJ,MAAM;KACP,CAAC,EACJ,GAAG,CAAC,UAAU,EAAE,MAAM,CACvB,CAAA;IACD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,GAAG,oBAAoB,EAAE,EAAE,IAAI,EAAE,CAAA;AACpE,CAAC,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ApiContext, ApiResponse } from '../types.js';
|
|
2
|
+
import type { AssistantChatRequest } from './protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validate a chat request: a non-empty conversation of user and assistant text
|
|
5
|
+
* turns that starts and ends with the user (400), within the history and
|
|
6
|
+
* character limits (413). Only `messages`, `provider` and `context` are read — tool calls
|
|
7
|
+
* and tool results are never accepted from the client.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseChatRequest(body: unknown, ctx: ApiContext): {
|
|
10
|
+
ok: true;
|
|
11
|
+
value: AssistantChatRequest;
|
|
12
|
+
} | {
|
|
13
|
+
ok: false;
|
|
14
|
+
response: ApiResponse;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=chat-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-request.d.ts","sourceRoot":"","sources":["../../src/assistant/chat-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AA6BzD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,UAAU,GACd;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,oBAAoB,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,WAAW,CAAA;CAAE,CA+BlF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** A slug or locale as Studio's routes carry them */
|
|
2
|
+
const ROUTE_TOKEN = /^[A-Za-z0-9._-]{1,200}$/;
|
|
3
|
+
function badRequest(error) {
|
|
4
|
+
return { ok: false, response: { status: 400, body: { error } } };
|
|
5
|
+
}
|
|
6
|
+
function isMessage(value) {
|
|
7
|
+
if (!value || typeof value !== 'object')
|
|
8
|
+
return false;
|
|
9
|
+
const { role, content } = value;
|
|
10
|
+
return (role === 'user' || role === 'assistant') && typeof content === 'string' && content !== '';
|
|
11
|
+
}
|
|
12
|
+
/** The screen context, kept only when it names a collection that exists */
|
|
13
|
+
function parseContext(value, ctx) {
|
|
14
|
+
if (!value || typeof value !== 'object')
|
|
15
|
+
return undefined;
|
|
16
|
+
const { collection, slug, locale } = value;
|
|
17
|
+
if (typeof collection !== 'string' || !ctx.contentConfig.collections.has(collection)) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const token = (v) => typeof v === 'string' && ROUTE_TOKEN.test(v) ? v : undefined;
|
|
21
|
+
return { collection, slug: token(slug), locale: token(locale) };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Validate a chat request: a non-empty conversation of user and assistant text
|
|
25
|
+
* turns that starts and ends with the user (400), within the history and
|
|
26
|
+
* character limits (413). Only `messages`, `provider` and `context` are read — tool calls
|
|
27
|
+
* and tool results are never accepted from the client.
|
|
28
|
+
*/
|
|
29
|
+
export function parseChatRequest(body, ctx) {
|
|
30
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
31
|
+
return badRequest('Request body must be a JSON object');
|
|
32
|
+
}
|
|
33
|
+
const { messages, context, provider } = body;
|
|
34
|
+
if (!Array.isArray(messages) || messages.length === 0) {
|
|
35
|
+
return badRequest('messages must be a non-empty array');
|
|
36
|
+
}
|
|
37
|
+
if (!messages.every(isMessage)) {
|
|
38
|
+
return badRequest('Each message needs role "user" or "assistant" and non-empty text content');
|
|
39
|
+
}
|
|
40
|
+
if (messages[0]?.role !== 'user' || messages[messages.length - 1]?.role !== 'user') {
|
|
41
|
+
return badRequest('The conversation must start and end with a user message');
|
|
42
|
+
}
|
|
43
|
+
const limits = ctx.config.assistant.limits;
|
|
44
|
+
const chars = messages.reduce((sum, message) => sum + message.content.length, 0);
|
|
45
|
+
if (messages.length > limits.maxHistoryMessages || chars > limits.maxInputChars) {
|
|
46
|
+
const error = `The conversation is too long (at most ${limits.maxHistoryMessages} messages and ${limits.maxInputChars} characters)`;
|
|
47
|
+
return { ok: false, response: { status: 413, body: { error } } };
|
|
48
|
+
}
|
|
49
|
+
if (provider !== undefined && typeof provider !== 'string') {
|
|
50
|
+
return badRequest('provider must be a string');
|
|
51
|
+
}
|
|
52
|
+
const value = {
|
|
53
|
+
messages: messages.map(({ role, content }) => ({ role, content })),
|
|
54
|
+
provider,
|
|
55
|
+
context: parseContext(context, ctx),
|
|
56
|
+
};
|
|
57
|
+
return { ok: true, value };
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=chat-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-request.js","sourceRoot":"","sources":["../../src/assistant/chat-request.ts"],"names":[],"mappings":"AAKA,qDAAqD;AACrD,MAAM,WAAW,GAAG,yBAAyB,CAAA;AAE7C,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,EAAE,EAAE,EAAE,K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