glirastes 0.3.0 → 0.3.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 +63 -0
- package/README.md +146 -9
- package/codegen/package.json +5 -0
- package/dist/cjs/codegen/asset-sync.d.ts +20 -0
- package/dist/cjs/codegen/asset-sync.js +28 -0
- package/dist/cjs/codegen/coverage.d.ts +66 -0
- package/dist/cjs/codegen/coverage.js +408 -0
- package/dist/cjs/codegen/endpoint-scanner.d.ts +16 -0
- package/dist/cjs/codegen/endpoint-scanner.js +197 -0
- package/dist/cjs/codegen/format.d.ts +17 -0
- package/dist/cjs/codegen/format.js +34 -0
- package/dist/cjs/codegen/fs-utils.d.ts +45 -0
- package/dist/cjs/codegen/fs-utils.js +165 -0
- package/dist/cjs/codegen/index.d.ts +13 -0
- package/dist/cjs/codegen/index.js +33 -0
- package/dist/cjs/codegen/mcp-generator.d.ts +50 -0
- package/dist/cjs/codegen/mcp-generator.js +803 -0
- package/dist/cjs/codegen/module-generator.d.ts +11 -0
- package/dist/cjs/codegen/module-generator.js +353 -0
- package/dist/cjs/codegen/nestjs-scanner.d.ts +43 -0
- package/dist/cjs/codegen/nestjs-scanner.js +241 -0
- package/dist/cjs/codegen/output-recommender.d.ts +23 -0
- package/dist/cjs/codegen/output-recommender.js +33 -0
- package/dist/cjs/codegen/scaffolder.d.ts +36 -0
- package/dist/cjs/codegen/scaffolder.js +262 -0
- package/dist/cjs/codegen/skill-generator.d.ts +49 -0
- package/dist/cjs/codegen/skill-generator.js +967 -0
- package/dist/cjs/codegen/types.d.ts +52 -0
- package/dist/cjs/codegen/types.js +16 -0
- package/dist/cjs/codegen/ui-scanner.d.ts +24 -0
- package/dist/cjs/codegen/ui-scanner.js +202 -0
- package/dist/cjs/codegen/validator.d.ts +35 -0
- package/dist/cjs/codegen/validator.js +292 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/openapi/index.d.ts +78 -0
- package/dist/cjs/openapi/index.js +347 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/react/audio-worklet-processor.d.ts +16 -0
- package/dist/cjs/react/audio-worklet-processor.js +27 -0
- package/dist/cjs/react/bridges/rest-session-bridge.d.ts +113 -0
- package/dist/cjs/react/bridges/rest-session-bridge.js +209 -0
- package/dist/cjs/react/components/ai-chat-panel.d.ts +12 -0
- package/dist/cjs/react/components/ai-chat-panel.js +67 -0
- package/dist/cjs/react/components/ai-trigger-button.d.ts +2 -0
- package/dist/cjs/react/components/ai-trigger-button.js +239 -0
- package/dist/cjs/react/components/approval-card.d.ts +9 -0
- package/dist/cjs/react/components/approval-card.js +24 -0
- package/dist/cjs/react/components/bulk-approval-card.d.ts +9 -0
- package/dist/cjs/react/components/bulk-approval-card.js +36 -0
- package/dist/cjs/react/components/chat-input.d.ts +10 -0
- package/dist/cjs/react/components/chat-input.js +60 -0
- package/dist/cjs/react/components/chat-window.d.ts +2 -0
- package/dist/cjs/react/components/chat-window.js +134 -0
- package/dist/cjs/react/components/confirm-dialog.d.ts +32 -0
- package/dist/cjs/react/components/confirm-dialog.js +48 -0
- package/dist/cjs/react/components/floating-chat-ui.d.ts +90 -0
- package/dist/cjs/react/components/floating-chat-ui.js +163 -0
- package/dist/cjs/react/components/mention-chip.d.ts +16 -0
- package/dist/cjs/react/components/mention-chip.js +42 -0
- package/dist/cjs/react/components/mention-input.d.ts +8 -0
- package/dist/cjs/react/components/mention-input.js +117 -0
- package/dist/cjs/react/components/message-bubble.d.ts +11 -0
- package/dist/cjs/react/components/message-bubble.js +171 -0
- package/dist/cjs/react/components/message-list.d.ts +8 -0
- package/dist/cjs/react/components/message-list.js +52 -0
- package/dist/cjs/react/components/pipeline-timeline.d.ts +7 -0
- package/dist/cjs/react/components/pipeline-timeline.js +72 -0
- package/dist/cjs/react/components/recording-bar.d.ts +2 -0
- package/dist/cjs/react/components/recording-bar.js +81 -0
- package/dist/cjs/react/components/recording-controls.d.ts +18 -0
- package/dist/cjs/react/components/recording-controls.js +38 -0
- package/dist/cjs/react/components/rich-mention-input.d.ts +2 -0
- package/dist/cjs/react/components/rich-mention-input.js +571 -0
- package/dist/cjs/react/components/session-switcher.d.ts +14 -0
- package/dist/cjs/react/components/session-switcher.js +133 -0
- package/dist/cjs/react/components/suggestion-bar.d.ts +9 -0
- package/dist/cjs/react/components/suggestion-bar.js +47 -0
- package/dist/cjs/react/components/suggestion-chip.d.ts +9 -0
- package/dist/cjs/react/components/suggestion-chip.js +14 -0
- package/dist/cjs/react/components/voice-input-addon.d.ts +13 -0
- package/dist/cjs/react/components/voice-input-addon.js +31 -0
- package/dist/cjs/react/components/voice-input-button.d.ts +2 -0
- package/dist/cjs/react/components/voice-input-button.js +55 -0
- package/dist/cjs/react/components/wavesurfer-loader.d.ts +5 -0
- package/dist/cjs/react/components/wavesurfer-loader.js +36 -0
- package/dist/cjs/react/hooks/use-ai-chat.d.ts +22 -0
- package/dist/cjs/react/hooks/use-ai-chat.js +51 -0
- package/dist/cjs/react/hooks/use-approvals.d.ts +23 -0
- package/dist/cjs/react/hooks/use-approvals.js +63 -0
- package/dist/cjs/react/hooks/use-deepgram-transcription.d.ts +2 -0
- package/dist/cjs/react/hooks/use-deepgram-transcription.js +329 -0
- package/dist/cjs/react/hooks/use-drag-resize-panel.d.ts +48 -0
- package/dist/cjs/react/hooks/use-drag-resize-panel.js +308 -0
- package/dist/cjs/react/hooks/use-draggable-position.d.ts +25 -0
- package/dist/cjs/react/hooks/use-draggable-position.js +134 -0
- package/dist/cjs/react/hooks/use-keyboard-shortcut.d.ts +20 -0
- package/dist/cjs/react/hooks/use-keyboard-shortcut.js +93 -0
- package/dist/cjs/react/hooks/use-mentions.d.ts +23 -0
- package/dist/cjs/react/hooks/use-mentions.js +42 -0
- package/dist/cjs/react/hooks/use-suggestions.d.ts +22 -0
- package/dist/cjs/react/hooks/use-suggestions.js +39 -0
- package/dist/cjs/react/index.d.ts +43 -0
- package/dist/cjs/react/index.js +111 -0
- package/dist/cjs/react/provider/ai-chat-provider.d.ts +45 -0
- package/dist/cjs/react/provider/ai-chat-provider.js +1024 -0
- package/dist/cjs/react/provider/chat-context.d.ts +84 -0
- package/dist/cjs/react/provider/chat-context.js +13 -0
- package/dist/cjs/react/template.d.ts +84 -0
- package/dist/cjs/react/template.js +90 -0
- package/dist/cjs/react/themes.d.ts +24 -0
- package/dist/cjs/react/themes.js +273 -0
- package/dist/cjs/react/transports/langgraph/index.d.ts +2 -0
- package/dist/cjs/react/transports/langgraph/index.js +8 -0
- package/dist/cjs/react/transports/langgraph/langgraph-ai-chat.d.ts +62 -0
- package/dist/cjs/react/transports/langgraph/langgraph-ai-chat.js +94 -0
- package/dist/cjs/react/transports/langgraph.d.ts +71 -0
- package/dist/cjs/react/transports/langgraph.js +369 -0
- package/dist/cjs/react/transports/vercel/index.d.ts +2 -0
- package/dist/cjs/react/transports/vercel/index.js +8 -0
- package/dist/cjs/react/transports/vercel/vercel-ai-chat.d.ts +49 -0
- package/dist/cjs/react/transports/vercel/vercel-ai-chat.js +81 -0
- package/dist/cjs/react/transports/vercel.d.ts +30 -0
- package/dist/cjs/react/transports/vercel.js +69 -0
- package/dist/cjs/react/types.d.ts +760 -0
- package/dist/cjs/react/types.js +2 -0
- package/dist/cjs/react/ui.d.ts +73 -0
- package/dist/cjs/react/ui.js +183 -0
- package/dist/cjs/react/utils/create-approval-description.d.ts +53 -0
- package/dist/cjs/react/utils/create-approval-description.js +122 -0
- package/dist/cjs/react/utils/create-tool-result-handler.d.ts +90 -0
- package/dist/cjs/react/utils/create-tool-result-handler.js +168 -0
- package/dist/cjs/react/utils/mention-markup.d.ts +13 -0
- package/dist/cjs/react/utils/mention-markup.js +117 -0
- package/dist/cjs/react/utils/merge-pipeline-steps.d.ts +19 -0
- package/dist/cjs/react/utils/merge-pipeline-steps.js +81 -0
- package/dist/cjs/react/utils/sanitize-stored-messages.d.ts +23 -0
- package/dist/cjs/react/utils/sanitize-stored-messages.js +52 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat-auth.guard.d.ts +10 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat-auth.guard.js +42 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat-module-options.interface.d.ts +32 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat-module-options.interface.js +4 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.controller.d.ts +11 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.controller.js +80 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.module.d.ts +9 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.module.js +119 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.service.d.ts +13 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.service.js +131 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/ai-chat-request.dto.d.ts +7 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/ai-chat-request.dto.js +52 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/chat-message-part.dto.d.ts +19 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/chat-message-part.dto.js +108 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/chat-message.dto.d.ts +8 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/chat-message.dto.js +59 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/index.d.ts +3 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/index.js +9 -0
- package/dist/cjs/server/adapters/nestjs/chat/index.d.ts +3 -0
- package/dist/cjs/server/adapters/nestjs/chat/index.js +9 -0
- package/dist/cjs/server/adapters/nestjs/chat/speech-stream.gateway.d.ts +4 -0
- package/dist/cjs/server/adapters/nestjs/chat/speech-stream.gateway.js +73 -0
- package/dist/cjs/server/adapters/nestjs/chat/ws-loader.d.ts +5 -0
- package/dist/cjs/server/adapters/nestjs/chat/ws-loader.js +72 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-module.decorator.d.ts +6 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-module.decorator.js +13 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-param.decorator.d.ts +5 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-param.decorator.js +15 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-tool.decorator.d.ts +6 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-tool.decorator.js +22 -0
- package/dist/cjs/server/adapters/nestjs/decorators/constants.d.ts +4 -0
- package/dist/cjs/server/adapters/nestjs/decorators/constants.js +7 -0
- package/dist/cjs/server/adapters/nestjs/index.d.ts +14 -0
- package/dist/cjs/server/adapters/nestjs/index.js +42 -0
- package/dist/cjs/server/adapters/nestjs/metadata.d.ts +39 -0
- package/dist/cjs/server/adapters/nestjs/metadata.js +36 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools-explorer.service.d.ts +36 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools-explorer.service.js +159 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools.module.d.ts +37 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools.module.js +44 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools.service.d.ts +28 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools.service.js +41 -0
- package/dist/cjs/server/adapters/nestjs/scanner/nestjs-scanner.d.ts +16 -0
- package/dist/cjs/server/adapters/nestjs/scanner/nestjs-scanner.js +117 -0
- package/dist/cjs/server/adapters/nestjs/scanner/schema-builder.d.ts +26 -0
- package/dist/cjs/server/adapters/nestjs/scanner/schema-builder.js +259 -0
- package/dist/cjs/server/adapters/nestjs/swagger.d.ts +7 -0
- package/dist/cjs/server/adapters/nestjs/swagger.js +39 -0
- package/dist/cjs/server/adapters/nextjs/context-helpers.d.ts +22 -0
- package/dist/cjs/server/adapters/nextjs/context-helpers.js +60 -0
- package/dist/cjs/server/adapters/nextjs/create-ai-chat-handler.d.ts +94 -0
- package/dist/cjs/server/adapters/nextjs/create-ai-chat-handler.js +965 -0
- package/dist/cjs/server/adapters/nextjs/filter-fallback-error.d.ts +11 -0
- package/dist/cjs/server/adapters/nextjs/filter-fallback-error.js +41 -0
- package/dist/cjs/server/adapters/nextjs/index.d.ts +8 -0
- package/dist/cjs/server/adapters/nextjs/index.js +22 -0
- package/dist/cjs/server/adapters/nextjs/prepare-model-messages.d.ts +58 -0
- package/dist/cjs/server/adapters/nextjs/prepare-model-messages.js +114 -0
- package/dist/cjs/server/adapters/nextjs/sanitize-model-messages.d.ts +64 -0
- package/dist/cjs/server/adapters/nextjs/sanitize-model-messages.js +489 -0
- package/dist/cjs/server/adapters/nextjs/server-action-helper.d.ts +7 -0
- package/dist/cjs/server/adapters/nextjs/server-action-helper.js +40 -0
- package/dist/cjs/server/adapters/nextjs/types.d.ts +246 -0
- package/dist/cjs/server/adapters/nextjs/types.js +2 -0
- package/dist/cjs/server/adapters/nextjs/with-ai-tool.d.ts +9 -0
- package/dist/cjs/server/adapters/nextjs/with-ai-tool.js +12 -0
- package/dist/cjs/server/core/followup-tool.d.ts +9 -0
- package/dist/cjs/server/core/followup-tool.js +82 -0
- package/dist/cjs/server/core/index.d.ts +139 -0
- package/dist/cjs/server/core/index.js +818 -0
- package/dist/cjs/server/core/intent-classifier.d.ts +94 -0
- package/dist/cjs/server/core/intent-classifier.js +324 -0
- package/dist/cjs/server/core/model-selector.d.ts +12 -0
- package/dist/cjs/server/core/model-selector.js +48 -0
- package/dist/cjs/server/core/module-router.d.ts +14 -0
- package/dist/cjs/server/core/module-router.js +110 -0
- package/dist/cjs/server/core/zod-compact.d.ts +18 -0
- package/dist/cjs/server/core/zod-compact.js +129 -0
- package/dist/cjs/server/index.d.ts +6 -0
- package/dist/cjs/server/index.js +28 -0
- package/dist/cjs/server/lancer/cache.d.ts +9 -0
- package/dist/cjs/server/lancer/cache.js +33 -0
- package/dist/cjs/server/lancer/client.d.ts +2 -0
- package/dist/cjs/server/lancer/client.js +279 -0
- package/dist/cjs/server/lancer/errors.d.ts +13 -0
- package/dist/cjs/server/lancer/errors.js +21 -0
- package/dist/cjs/server/lancer/index.d.ts +3 -0
- package/dist/cjs/server/lancer/index.js +7 -0
- package/dist/cjs/server/lancer/telemetry-buffer.d.ts +15 -0
- package/dist/cjs/server/lancer/telemetry-buffer.js +64 -0
- package/dist/cjs/server/lancer/types.d.ts +201 -0
- package/dist/cjs/server/lancer/types.js +5 -0
- package/dist/cjs/server/pii-shield/aegis-detector.d.ts +26 -0
- package/dist/cjs/server/pii-shield/aegis-detector.js +26 -0
- package/dist/cjs/server/pii-shield/create-pii-shield.d.ts +2 -0
- package/dist/cjs/server/pii-shield/create-pii-shield.js +191 -0
- package/dist/cjs/server/pii-shield/deep-walk.d.ts +1 -0
- package/dist/cjs/server/pii-shield/deep-walk.js +19 -0
- package/dist/cjs/server/pii-shield/fake-data.d.ts +5 -0
- package/dist/cjs/server/pii-shield/fake-data.js +170 -0
- package/dist/cjs/server/pii-shield/index.d.ts +4 -0
- package/dist/cjs/server/pii-shield/index.js +9 -0
- package/dist/cjs/server/pii-shield/leakage.d.ts +1 -0
- package/dist/cjs/server/pii-shield/leakage.js +15 -0
- package/dist/cjs/server/pii-shield/session-mapping.d.ts +12 -0
- package/dist/cjs/server/pii-shield/session-mapping.js +70 -0
- package/dist/cjs/server/pipeline.d.ts +26 -0
- package/dist/cjs/server/pipeline.js +127 -0
- package/dist/cjs/server/testing/approvals.d.ts +11 -0
- package/dist/cjs/server/testing/approvals.js +41 -0
- package/dist/cjs/server/testing/combination.d.ts +3 -0
- package/dist/cjs/server/testing/combination.js +83 -0
- package/dist/cjs/server/testing/create-test-suite.d.ts +29 -0
- package/dist/cjs/server/testing/create-test-suite.js +81 -0
- package/dist/cjs/server/testing/edge-cases.d.ts +8 -0
- package/dist/cjs/server/testing/edge-cases.js +277 -0
- package/dist/cjs/server/testing/guardrails.d.ts +14 -0
- package/dist/cjs/server/testing/guardrails.js +152 -0
- package/dist/cjs/server/testing/helpers.d.ts +14 -0
- package/dist/cjs/server/testing/helpers.js +119 -0
- package/dist/cjs/server/testing/index.d.ts +12 -0
- package/dist/cjs/server/testing/index.js +37 -0
- package/dist/cjs/server/testing/mock-executor.d.ts +8 -0
- package/dist/cjs/server/testing/mock-executor.js +40 -0
- package/dist/cjs/server/testing/regression.d.ts +7 -0
- package/dist/cjs/server/testing/regression.js +27 -0
- package/dist/cjs/server/testing/routing.d.ts +12 -0
- package/dist/cjs/server/testing/routing.js +63 -0
- package/dist/cjs/server/testing/schema-consistency.d.ts +6 -0
- package/dist/cjs/server/testing/schema-consistency.js +56 -0
- package/dist/cjs/server/testing/smoke.d.ts +11 -0
- package/dist/cjs/server/testing/smoke.js +64 -0
- package/dist/cjs/server/testing/types.d.ts +156 -0
- package/dist/cjs/server/testing/types.js +2 -0
- package/dist/cjs/types.d.ts +696 -0
- package/dist/cjs/types.js +91 -0
- package/dist/cli/commands/install-skills.d.ts +17 -0
- package/dist/cli/commands/install-skills.js +185 -0
- package/dist/cli/commands/install-skills.js.map +1 -0
- package/dist/cli/index.js +25 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/react/components/ai-trigger-button.js +4 -6
- package/dist/react/components/ai-trigger-button.js.map +1 -1
- package/dist/react/components/recording-bar.js +4 -6
- package/dist/react/components/recording-bar.js.map +1 -1
- package/dist/react/components/wavesurfer-loader.d.ts +5 -0
- package/dist/react/components/wavesurfer-loader.js +34 -0
- package/dist/react/components/wavesurfer-loader.js.map +1 -0
- package/dist/server/adapters/nestjs/chat/ai-chat.module.d.ts +1 -1
- package/dist/server/adapters/nestjs/chat/ai-chat.module.js +3 -2
- package/dist/server/adapters/nestjs/chat/ai-chat.module.js.map +1 -1
- package/dist/server/adapters/nestjs/chat/speech-stream.gateway.d.ts +1 -1
- package/dist/server/adapters/nestjs/chat/speech-stream.gateway.js +10 -8
- package/dist/server/adapters/nestjs/chat/speech-stream.gateway.js.map +1 -1
- package/dist/server/adapters/nestjs/chat/ws-loader.d.ts +5 -0
- package/dist/server/adapters/nestjs/chat/ws-loader.js +37 -0
- package/dist/server/adapters/nestjs/chat/ws-loader.js.map +1 -0
- package/openapi/package.json +5 -0
- package/package.json +59 -16
- package/react/langgraph/package.json +5 -0
- package/react/package.json +5 -0
- package/react/vercel/package.json +5 -0
- package/server/nestjs/package.json +5 -0
- package/server/nextjs/package.json +5 -0
- package/server/package.json +5 -0
- package/server/testing/package.json +5 -0
- package/skills/README.md +107 -0
- package/skills/building-glirastes-chat-ui/SKILL.md +378 -0
- package/skills/integrating-glirastes-nestjs/SKILL.md +346 -0
- package/skills/integrating-glirastes-nextjs/SKILL.md +306 -0
- package/skills/integrating-glirastes-nextjs-with-nestjs-backend/SKILL.md +359 -0
- package/skills/maintaining-glirastes-tools/SKILL.md +463 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zodToCompactDescription = zodToCompactDescription;
|
|
4
|
+
/**
|
|
5
|
+
* Convert a Zod schema to a compact TypeScript-like description string.
|
|
6
|
+
*
|
|
7
|
+
* Used to auto-generate "Returns: ..." suffixes for AI tool descriptions,
|
|
8
|
+
* so the LLM knows the response shape without bloating the system prompt.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* zodToCompactDescription(z.object({
|
|
12
|
+
* tasks: z.array(z.object({ id: z.string(), title: z.string() })),
|
|
13
|
+
* total: z.number(),
|
|
14
|
+
* }))
|
|
15
|
+
* // → '{ tasks: Array<{ id: string, title: string }>, total: number }'
|
|
16
|
+
*
|
|
17
|
+
* @param schema - Any Zod schema
|
|
18
|
+
* @param maxDepth - Maximum nesting depth before collapsing to "..." (default: 3)
|
|
19
|
+
*/
|
|
20
|
+
function zodToCompactDescription(schema, maxDepth = 3) {
|
|
21
|
+
return describeSchema(schema, 0, maxDepth);
|
|
22
|
+
}
|
|
23
|
+
function describeSchema(schema, depth, maxDepth) {
|
|
24
|
+
if (depth >= maxDepth)
|
|
25
|
+
return '...';
|
|
26
|
+
const def = schema._def;
|
|
27
|
+
const typeName = def?.typeName;
|
|
28
|
+
switch (typeName) {
|
|
29
|
+
case 'ZodString':
|
|
30
|
+
return 'string';
|
|
31
|
+
case 'ZodNumber':
|
|
32
|
+
return 'number';
|
|
33
|
+
case 'ZodBoolean':
|
|
34
|
+
return 'boolean';
|
|
35
|
+
case 'ZodDate':
|
|
36
|
+
return 'string'; // Dates serialize as strings in JSON
|
|
37
|
+
case 'ZodLiteral':
|
|
38
|
+
return JSON.stringify(def.value);
|
|
39
|
+
case 'ZodNull':
|
|
40
|
+
return 'null';
|
|
41
|
+
case 'ZodUndefined':
|
|
42
|
+
return 'undefined';
|
|
43
|
+
case 'ZodAny':
|
|
44
|
+
return 'any';
|
|
45
|
+
case 'ZodUnknown':
|
|
46
|
+
return 'unknown';
|
|
47
|
+
case 'ZodVoid':
|
|
48
|
+
return 'void';
|
|
49
|
+
case 'ZodEnum':
|
|
50
|
+
return def.values
|
|
51
|
+
.map((v) => `"${v}"`)
|
|
52
|
+
.join(' | ');
|
|
53
|
+
case 'ZodNativeEnum':
|
|
54
|
+
return Object.values(def.values)
|
|
55
|
+
.filter((v) => typeof v === 'string')
|
|
56
|
+
.map((v) => `"${v}"`)
|
|
57
|
+
.join(' | ');
|
|
58
|
+
case 'ZodArray':
|
|
59
|
+
return `Array<${describeSchema(def.type, depth + 1, maxDepth)}>`;
|
|
60
|
+
case 'ZodObject': {
|
|
61
|
+
const shape = def.shape();
|
|
62
|
+
const entries = Object.entries(shape);
|
|
63
|
+
if (entries.length === 0)
|
|
64
|
+
return '{}';
|
|
65
|
+
const fields = entries.map(([key, value]) => {
|
|
66
|
+
const optional = isOptional(value);
|
|
67
|
+
const desc = describeSchema(unwrap(value), depth + 1, maxDepth);
|
|
68
|
+
const nullable = isNullable(value);
|
|
69
|
+
const suffix = nullable ? ' | null' : '';
|
|
70
|
+
return `${key}${optional ? '?' : ''}: ${desc}${suffix}`;
|
|
71
|
+
});
|
|
72
|
+
return `{ ${fields.join(', ')} }`;
|
|
73
|
+
}
|
|
74
|
+
case 'ZodRecord':
|
|
75
|
+
return `Record<string, ${describeSchema(def.valueType, depth + 1, maxDepth)}>`;
|
|
76
|
+
case 'ZodUnion':
|
|
77
|
+
case 'ZodDiscriminatedUnion': {
|
|
78
|
+
const options = def.options;
|
|
79
|
+
return options
|
|
80
|
+
.map((o) => describeSchema(o, depth + 1, maxDepth))
|
|
81
|
+
.join(' | ');
|
|
82
|
+
}
|
|
83
|
+
case 'ZodTuple': {
|
|
84
|
+
const items = def.items;
|
|
85
|
+
return `[${items.map((i) => describeSchema(i, depth + 1, maxDepth)).join(', ')}]`;
|
|
86
|
+
}
|
|
87
|
+
case 'ZodNullable':
|
|
88
|
+
return `${describeSchema(def.innerType, depth, maxDepth)} | null`;
|
|
89
|
+
case 'ZodOptional':
|
|
90
|
+
case 'ZodDefault':
|
|
91
|
+
return describeSchema(def.innerType, depth, maxDepth);
|
|
92
|
+
case 'ZodEffects':
|
|
93
|
+
return describeSchema(def.schema, depth, maxDepth);
|
|
94
|
+
default:
|
|
95
|
+
return 'unknown';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Unwrap ZodOptional / ZodNullable / ZodDefault / ZodEffects to the inner schema. */
|
|
99
|
+
function unwrap(schema) {
|
|
100
|
+
const def = schema._def;
|
|
101
|
+
const typeName = def?.typeName;
|
|
102
|
+
if (typeName === 'ZodOptional' ||
|
|
103
|
+
typeName === 'ZodNullable' ||
|
|
104
|
+
typeName === 'ZodDefault') {
|
|
105
|
+
return unwrap(def.innerType);
|
|
106
|
+
}
|
|
107
|
+
if (typeName === 'ZodEffects') {
|
|
108
|
+
return unwrap(def.schema);
|
|
109
|
+
}
|
|
110
|
+
return schema;
|
|
111
|
+
}
|
|
112
|
+
function isOptional(schema) {
|
|
113
|
+
const def = schema._def;
|
|
114
|
+
const typeName = def?.typeName;
|
|
115
|
+
if (typeName === 'ZodOptional' || typeName === 'ZodDefault')
|
|
116
|
+
return true;
|
|
117
|
+
if (typeName === 'ZodNullable')
|
|
118
|
+
return isOptional(def.innerType);
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
function isNullable(schema) {
|
|
122
|
+
const def = schema._def;
|
|
123
|
+
const typeName = def?.typeName;
|
|
124
|
+
if (typeName === 'ZodNullable')
|
|
125
|
+
return true;
|
|
126
|
+
if (typeName === 'ZodOptional' || typeName === 'ZodDefault')
|
|
127
|
+
return isNullable(def.innerType);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './core/index.js';
|
|
2
|
+
export * from './pipeline.js';
|
|
3
|
+
export * from './lancer/index.js';
|
|
4
|
+
export { createPiiShield } from './pii-shield/index.js';
|
|
5
|
+
export { createAegisDetector } from './pii-shield/index.js';
|
|
6
|
+
export type { AegisLike } from './pii-shield/index.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createAegisDetector = exports.createPiiShield = void 0;
|
|
18
|
+
// Server core (includes native telemetry forwarding via TelemetrySink interface)
|
|
19
|
+
__exportStar(require("./core/index.js"), exports);
|
|
20
|
+
// AI pipeline (multi-stage: guardrails → classify → route → model select)
|
|
21
|
+
__exportStar(require("./pipeline.js"), exports);
|
|
22
|
+
// Lancer (platform client) — createLancer, ServiceBlockedError, types
|
|
23
|
+
__exportStar(require("./lancer/index.js"), exports);
|
|
24
|
+
// PII shield
|
|
25
|
+
var index_js_1 = require("./pii-shield/index.js");
|
|
26
|
+
Object.defineProperty(exports, "createPiiShield", { enumerable: true, get: function () { return index_js_1.createPiiShield; } });
|
|
27
|
+
var index_js_2 = require("./pii-shield/index.js");
|
|
28
|
+
Object.defineProperty(exports, "createAegisDetector", { enumerable: true, get: function () { return index_js_2.createAegisDetector; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Simple in-memory Map cache with TTL
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Cache = void 0;
|
|
7
|
+
class Cache {
|
|
8
|
+
ttl;
|
|
9
|
+
store = new Map();
|
|
10
|
+
constructor(ttl) {
|
|
11
|
+
this.ttl = ttl;
|
|
12
|
+
}
|
|
13
|
+
set(key, value) {
|
|
14
|
+
this.store.set(key, { value, expiresAt: Date.now() + this.ttl });
|
|
15
|
+
}
|
|
16
|
+
get(key) {
|
|
17
|
+
const entry = this.store.get(key);
|
|
18
|
+
if (!entry)
|
|
19
|
+
return undefined;
|
|
20
|
+
if (Date.now() > entry.expiresAt) {
|
|
21
|
+
this.store.delete(key);
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return entry.value;
|
|
25
|
+
}
|
|
26
|
+
delete(key) {
|
|
27
|
+
this.store.delete(key);
|
|
28
|
+
}
|
|
29
|
+
clear() {
|
|
30
|
+
this.store.clear();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Cache = Cache;
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// createLancer — factory for the Lancer platform client
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createLancer = createLancer;
|
|
7
|
+
const cache_js_1 = require("./cache.js");
|
|
8
|
+
const errors_js_1 = require("./errors.js");
|
|
9
|
+
const telemetry_buffer_js_1 = require("./telemetry-buffer.js");
|
|
10
|
+
const DEFAULT_BASE_URL = 'https://api.glirastes.chainmatics.io';
|
|
11
|
+
const DEFAULT_CACHE_TTL = 60_000;
|
|
12
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
13
|
+
/** Built-in action per service when nothing is explicitly configured. */
|
|
14
|
+
const SERVICE_DEFAULT_ACTIONS = {
|
|
15
|
+
warden: 'fallback',
|
|
16
|
+
primus: 'fallback',
|
|
17
|
+
aegis: 'fallback',
|
|
18
|
+
proctor: 'silent', // telemetry-only service — failures are always silent
|
|
19
|
+
config: 'fallback',
|
|
20
|
+
approvals: 'fallback',
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Call `fn`; on failure resolve the degradation action for `service` and act:
|
|
24
|
+
* - 'fallback': call onDegraded (if set) and return `fallback`.
|
|
25
|
+
* - 'silent': return `fallback` without calling onDegraded.
|
|
26
|
+
* - 'block': throw ServiceBlockedError (propagates to the caller).
|
|
27
|
+
*
|
|
28
|
+
* Resolution order: onServiceUnavailable callback > degradation defaults > built-in default.
|
|
29
|
+
*/
|
|
30
|
+
async function callWithFallback(fn, fallback, service, cfg) {
|
|
31
|
+
try {
|
|
32
|
+
return await fn();
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
36
|
+
// 1. Start from static default
|
|
37
|
+
let action = cfg.defaults?.[service] ?? SERVICE_DEFAULT_ACTIONS[service];
|
|
38
|
+
// 2. Let the dynamic callback override (last word)
|
|
39
|
+
if (cfg.onServiceUnavailable) {
|
|
40
|
+
action = await cfg.onServiceUnavailable({ service, error });
|
|
41
|
+
}
|
|
42
|
+
if (action === 'block') {
|
|
43
|
+
throw new errors_js_1.ServiceBlockedError(service, error);
|
|
44
|
+
}
|
|
45
|
+
if (action === 'fallback') {
|
|
46
|
+
cfg.onDegraded?.();
|
|
47
|
+
}
|
|
48
|
+
// 'silent': return fallback without notifying
|
|
49
|
+
return fallback;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function createLancer(config) {
|
|
53
|
+
const baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
54
|
+
const cacheTtl = config.cache?.ttl ?? DEFAULT_CACHE_TTL;
|
|
55
|
+
const maxRetries = config.retry?.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
56
|
+
const agentId = config.agentId;
|
|
57
|
+
const agentType = config.agentType;
|
|
58
|
+
const headers = {
|
|
59
|
+
'Content-Type': 'application/json',
|
|
60
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
61
|
+
...(agentId ? { 'X-Agent-Id': agentId } : {}),
|
|
62
|
+
...(agentType ? { 'X-Agent-Type': agentType } : {}),
|
|
63
|
+
};
|
|
64
|
+
const cache = new cache_js_1.Cache(cacheTtl);
|
|
65
|
+
const telemetryBuffer = new telemetry_buffer_js_1.TelemetryBuffer(`${baseUrl}/v1/proctor/events`, headers, maxRetries);
|
|
66
|
+
// Track config ETags per cache-key for conditional requests
|
|
67
|
+
const etags = new Map();
|
|
68
|
+
// Shared degradation config — built once, reused by every callWithFallback call.
|
|
69
|
+
const degradationCfg = {
|
|
70
|
+
defaults: config.degradation,
|
|
71
|
+
onServiceUnavailable: config.onServiceUnavailable,
|
|
72
|
+
onDegraded: config.onDegraded,
|
|
73
|
+
};
|
|
74
|
+
// ------ API helpers ------------------------------------------------------
|
|
75
|
+
async function apiFetch(path, init) {
|
|
76
|
+
let lastError;
|
|
77
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
78
|
+
try {
|
|
79
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
80
|
+
...init,
|
|
81
|
+
headers: { ...headers, ...init?.headers },
|
|
82
|
+
});
|
|
83
|
+
if (!res.ok)
|
|
84
|
+
throw new Error(`HTTP ${res.status}`);
|
|
85
|
+
return (await res.json());
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
lastError = err;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
throw lastError;
|
|
92
|
+
}
|
|
93
|
+
// ------ Primus namespace (intent classification) -------------------------
|
|
94
|
+
const primus = {
|
|
95
|
+
async classify(message, modules, locale) {
|
|
96
|
+
const moduleIds = modules.map(m => m.moduleId);
|
|
97
|
+
return callWithFallback(() => apiFetch('/v1/primus/classify', {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
body: JSON.stringify({ message, modules: moduleIds, ...(locale && { locale }) }),
|
|
100
|
+
}), { moduleId: '', confidence: 0, modelTier: 'standard' }, 'primus', degradationCfg);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
// ------ Warden namespace (guardrail checks) ------------------------------
|
|
104
|
+
const warden = {
|
|
105
|
+
async check(input, policies) {
|
|
106
|
+
// Map Glirastes response (policy -> rule) so SDK interface matches
|
|
107
|
+
const result = await callWithFallback(async () => {
|
|
108
|
+
const raw = await apiFetch('/v1/warden/check', {
|
|
109
|
+
method: 'POST',
|
|
110
|
+
body: JSON.stringify({ input, policies }),
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
passed: raw.passed,
|
|
114
|
+
violations: raw.violations.map(v => ({
|
|
115
|
+
rule: v.policy,
|
|
116
|
+
severity: v.severity,
|
|
117
|
+
message: v.message,
|
|
118
|
+
})),
|
|
119
|
+
};
|
|
120
|
+
}, { passed: true, violations: [] }, 'warden', degradationCfg);
|
|
121
|
+
return result;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
// ------ Aegis namespace (PII detection) ----------------------------------
|
|
125
|
+
const aegis = {
|
|
126
|
+
async analyze(text, options) {
|
|
127
|
+
return callWithFallback(() => apiFetch('/v1/aegis/analyze', {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
body: JSON.stringify({
|
|
130
|
+
text,
|
|
131
|
+
locales: options?.locales,
|
|
132
|
+
mode: options?.mode ?? 'pseudonymize',
|
|
133
|
+
sessionId: options?.sessionId,
|
|
134
|
+
}),
|
|
135
|
+
}), { entities: [], anonymized: text, mappingToken: null }, 'aegis', degradationCfg);
|
|
136
|
+
},
|
|
137
|
+
async rehydrate(text, mappingToken) {
|
|
138
|
+
const result = await callWithFallback(() => apiFetch('/v1/aegis/rehydrate', {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
body: JSON.stringify({ text, mappingToken }),
|
|
141
|
+
}), { rehydrated: text }, 'aegis', degradationCfg);
|
|
142
|
+
return result.rehydrated;
|
|
143
|
+
},
|
|
144
|
+
async checkLeakage(text, mappingToken, locales) {
|
|
145
|
+
return callWithFallback(() => apiFetch('/v1/aegis/check-leakage', {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
body: JSON.stringify({ text, mappingToken, locales }),
|
|
148
|
+
}), { leaked: false, entities: [], totalDetected: 0, filteredAsKnown: 0 }, 'aegis', degradationCfg);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
// ------ Config namespace -------------------------------------------------
|
|
152
|
+
const configNs = {
|
|
153
|
+
async fetch(modules) {
|
|
154
|
+
const cacheKey = `config:fetch:${modules.sort().join(',')}`;
|
|
155
|
+
const cached = cache.get(cacheKey);
|
|
156
|
+
if (cached)
|
|
157
|
+
return cached;
|
|
158
|
+
const extraHeaders = {};
|
|
159
|
+
const etag = etags.get(cacheKey);
|
|
160
|
+
if (etag)
|
|
161
|
+
extraHeaders['If-None-Match'] = etag;
|
|
162
|
+
const result = await callWithFallback(async () => {
|
|
163
|
+
let lastError;
|
|
164
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
165
|
+
try {
|
|
166
|
+
const res = await fetch(`${baseUrl}/v1/config?modules=${modules.join(',')}`, {
|
|
167
|
+
method: 'GET',
|
|
168
|
+
headers: { ...headers, ...extraHeaders },
|
|
169
|
+
});
|
|
170
|
+
if (res.status === 304) {
|
|
171
|
+
const prev = cache.get(cacheKey);
|
|
172
|
+
return prev ?? { modules: {} };
|
|
173
|
+
}
|
|
174
|
+
if (!res.ok)
|
|
175
|
+
throw new Error(`HTTP ${res.status}`);
|
|
176
|
+
const body = (await res.json());
|
|
177
|
+
const newEtag = res.headers.get('etag');
|
|
178
|
+
if (newEtag)
|
|
179
|
+
etags.set(cacheKey, newEtag);
|
|
180
|
+
return body;
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
lastError = err;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
throw lastError;
|
|
187
|
+
}, { modules: {} }, 'config', degradationCfg);
|
|
188
|
+
cache.set(cacheKey, result);
|
|
189
|
+
return result;
|
|
190
|
+
},
|
|
191
|
+
async reportModels(models) {
|
|
192
|
+
try {
|
|
193
|
+
await apiFetch('/v1/config/models/defaults', {
|
|
194
|
+
method: 'POST',
|
|
195
|
+
body: JSON.stringify({ models }),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
// Fire-and-forget: silently ignore errors
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
// ------ Telemetry namespace ----------------------------------------------
|
|
204
|
+
const telemetry = {
|
|
205
|
+
emit(event) {
|
|
206
|
+
const enrichedEvent = agentId
|
|
207
|
+
? {
|
|
208
|
+
...event,
|
|
209
|
+
actor: {
|
|
210
|
+
...event.actor,
|
|
211
|
+
agentId,
|
|
212
|
+
...(agentType ? { agentType } : {}),
|
|
213
|
+
},
|
|
214
|
+
}
|
|
215
|
+
: event;
|
|
216
|
+
telemetryBuffer.add(enrichedEvent);
|
|
217
|
+
},
|
|
218
|
+
async flush() {
|
|
219
|
+
// TelemetrySink contract: flush must never throw.
|
|
220
|
+
// Errors are already handled inside TelemetryBuffer (events re-queued).
|
|
221
|
+
try {
|
|
222
|
+
await telemetryBuffer.flush();
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
// Silently ignore — telemetry is fire-and-forget
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
// ------ Approvals namespace -----------------------------------------------
|
|
230
|
+
const approvals = {
|
|
231
|
+
async check(req) {
|
|
232
|
+
return callWithFallback(() => apiFetch('/v1/approvals/check', {
|
|
233
|
+
method: 'POST',
|
|
234
|
+
body: JSON.stringify(req),
|
|
235
|
+
}), { required: true, requestId: null, status: 'local-fallback' }, 'approvals', degradationCfg);
|
|
236
|
+
},
|
|
237
|
+
async decide(requestId, decision) {
|
|
238
|
+
return callWithFallback(() => apiFetch(`/v1/approvals/pending/${requestId}/decide`, {
|
|
239
|
+
method: 'POST',
|
|
240
|
+
body: JSON.stringify(decision),
|
|
241
|
+
}), { ok: false }, 'approvals', degradationCfg);
|
|
242
|
+
},
|
|
243
|
+
async resolve(req) {
|
|
244
|
+
return callWithFallback(() => apiFetch('/v1/approvals/resolve', {
|
|
245
|
+
method: 'POST',
|
|
246
|
+
body: JSON.stringify(req),
|
|
247
|
+
}), { resolved: false }, 'approvals', degradationCfg);
|
|
248
|
+
},
|
|
249
|
+
hashInput(args) {
|
|
250
|
+
// Deterministic JSON hash: recursively sort keys, stringify, then hash
|
|
251
|
+
const sortKeys = (_, v) => v && typeof v === 'object' && !Array.isArray(v)
|
|
252
|
+
? Object.keys(v).sort().reduce((o, k) => {
|
|
253
|
+
o[k] = v[k];
|
|
254
|
+
return o;
|
|
255
|
+
}, {})
|
|
256
|
+
: v;
|
|
257
|
+
const sorted = JSON.stringify(args, sortKeys);
|
|
258
|
+
let hash = 0;
|
|
259
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
260
|
+
const char = sorted.charCodeAt(i);
|
|
261
|
+
hash = ((hash << 5) - hash + char) | 0;
|
|
262
|
+
}
|
|
263
|
+
return hash.toString(36);
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
// ------ Public surface ---------------------------------------------------
|
|
267
|
+
return {
|
|
268
|
+
primus,
|
|
269
|
+
warden,
|
|
270
|
+
aegis,
|
|
271
|
+
config: configNs,
|
|
272
|
+
telemetry,
|
|
273
|
+
approvals,
|
|
274
|
+
destroy() {
|
|
275
|
+
telemetryBuffer.destroy();
|
|
276
|
+
cache.clear();
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LancerServiceName } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown by the Lancer client when a service is unreachable and the configured
|
|
4
|
+
* degradation action for that service is 'block'.
|
|
5
|
+
*
|
|
6
|
+
* Consumers (e.g. server-pro pipeline) should catch this error and treat the
|
|
7
|
+
* request as blocked rather than falling back silently.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ServiceBlockedError extends Error {
|
|
10
|
+
readonly service: LancerServiceName;
|
|
11
|
+
readonly cause: Error | undefined;
|
|
12
|
+
constructor(service: LancerServiceName, cause?: Error);
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceBlockedError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Thrown by the Lancer client when a service is unreachable and the configured
|
|
6
|
+
* degradation action for that service is 'block'.
|
|
7
|
+
*
|
|
8
|
+
* Consumers (e.g. server-pro pipeline) should catch this error and treat the
|
|
9
|
+
* request as blocked rather than falling back silently.
|
|
10
|
+
*/
|
|
11
|
+
class ServiceBlockedError extends Error {
|
|
12
|
+
service;
|
|
13
|
+
cause;
|
|
14
|
+
constructor(service, cause) {
|
|
15
|
+
super(`Service '${service}' blocked the request due to degradation policy`);
|
|
16
|
+
this.service = service;
|
|
17
|
+
this.name = 'ServiceBlockedError';
|
|
18
|
+
this.cause = cause;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.ServiceBlockedError = ServiceBlockedError;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createLancer } from './client.js';
|
|
2
|
+
export { ServiceBlockedError } from './errors.js';
|
|
3
|
+
export type { AegisNamespace, AnalyzeOptions, AnalyzeResult, ApprovalCheckResult, ApprovalDecideResult, ApprovalResolveResult, ApprovalsNamespace, CheckResult, ClassifyResult, ConfigNamespace, ConfigResult, DegradationAction, DegradationContext, DegradationDefaults, Lancer, LancerConfig, LancerServiceName, LeakageResult, OnServiceUnavailable, PiiEntity, PrimusNamespace, PromptOverride, TelemetryEvent, TelemetryNamespace, Violation, WardenNamespace, } from './types.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceBlockedError = exports.createLancer = void 0;
|
|
4
|
+
var client_js_1 = require("./client.js");
|
|
5
|
+
Object.defineProperty(exports, "createLancer", { enumerable: true, get: function () { return client_js_1.createLancer; } });
|
|
6
|
+
var errors_js_1 = require("./errors.js");
|
|
7
|
+
Object.defineProperty(exports, "ServiceBlockedError", { enumerable: true, get: function () { return errors_js_1.ServiceBlockedError; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TelemetryEvent } from './types.js';
|
|
2
|
+
export declare class TelemetryBuffer {
|
|
3
|
+
private readonly endpoint;
|
|
4
|
+
private readonly headers;
|
|
5
|
+
private readonly maxRetries;
|
|
6
|
+
private buffer;
|
|
7
|
+
private timer;
|
|
8
|
+
constructor(endpoint: string, headers: Record<string, string>, maxRetries: number);
|
|
9
|
+
/** Add an event to the buffer. Auto-flushes at threshold. */
|
|
10
|
+
add(event: TelemetryEvent): void;
|
|
11
|
+
/** Flush buffered events to the Proctor API. */
|
|
12
|
+
flush(): Promise<void>;
|
|
13
|
+
/** Tear down the auto-flush interval. */
|
|
14
|
+
destroy(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Telemetry event buffer — batches events and flushes to the Proctor API
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TelemetryBuffer = void 0;
|
|
7
|
+
const FLUSH_THRESHOLD = 50;
|
|
8
|
+
const FLUSH_INTERVAL_MS = 5_000;
|
|
9
|
+
class TelemetryBuffer {
|
|
10
|
+
endpoint;
|
|
11
|
+
headers;
|
|
12
|
+
maxRetries;
|
|
13
|
+
buffer = [];
|
|
14
|
+
timer = null;
|
|
15
|
+
constructor(endpoint, headers, maxRetries) {
|
|
16
|
+
this.endpoint = endpoint;
|
|
17
|
+
this.headers = headers;
|
|
18
|
+
this.maxRetries = maxRetries;
|
|
19
|
+
this.timer = setInterval(() => {
|
|
20
|
+
if (this.buffer.length > 0)
|
|
21
|
+
this.flush().catch(() => { });
|
|
22
|
+
}, FLUSH_INTERVAL_MS);
|
|
23
|
+
}
|
|
24
|
+
/** Add an event to the buffer. Auto-flushes at threshold. */
|
|
25
|
+
add(event) {
|
|
26
|
+
this.buffer.push(event);
|
|
27
|
+
if (this.buffer.length >= FLUSH_THRESHOLD) {
|
|
28
|
+
this.flush().catch(() => { });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Flush buffered events to the Proctor API. */
|
|
32
|
+
async flush() {
|
|
33
|
+
if (this.buffer.length === 0)
|
|
34
|
+
return;
|
|
35
|
+
const batch = this.buffer.splice(0);
|
|
36
|
+
let lastError;
|
|
37
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
38
|
+
try {
|
|
39
|
+
const res = await fetch(this.endpoint, {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: this.headers,
|
|
42
|
+
body: JSON.stringify({ events: batch }),
|
|
43
|
+
});
|
|
44
|
+
if (res.ok)
|
|
45
|
+
return;
|
|
46
|
+
lastError = new Error(`HTTP ${res.status}`);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
lastError = err;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// All retries exhausted — push events back to the buffer
|
|
53
|
+
this.buffer.unshift(...batch);
|
|
54
|
+
throw lastError;
|
|
55
|
+
}
|
|
56
|
+
/** Tear down the auto-flush interval. */
|
|
57
|
+
destroy() {
|
|
58
|
+
if (this.timer) {
|
|
59
|
+
clearInterval(this.timer);
|
|
60
|
+
this.timer = null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.TelemetryBuffer = TelemetryBuffer;
|