@sixthsummit/ship-api 0.0.0-stage → 4.1.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 +605 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +58 -2
- package/cli/commands/add.js +537 -0
- package/cli/commands/contract.js +2 -0
- package/cli/commands/create.js +250 -0
- package/cli/commands/dev.js +227 -0
- package/cli/commands/doctor.js +286 -0
- package/cli/commands/generate.js +937 -0
- package/cli/commands/graph.js +2 -0
- package/cli/commands/migrate-orm.js +1171 -0
- package/cli/commands/update.js +37 -0
- package/cli/ship-api.js +285 -0
- package/lib/app/auth/AuthProvider.d.ts +91 -0
- package/lib/app/auth/AuthProvider.d.ts.map +1 -0
- package/lib/app/auth/AuthProvider.js +13 -0
- package/lib/app/auth/AuthProvider.js.map +1 -0
- package/lib/app/auth/adapters/firebase.d.ts +79 -0
- package/lib/app/auth/adapters/firebase.d.ts.map +1 -0
- package/lib/app/auth/adapters/firebase.js +122 -0
- package/lib/app/auth/adapters/firebase.js.map +1 -0
- package/lib/app/auth/adapters/jwtCookie.d.ts +55 -0
- package/lib/app/auth/adapters/jwtCookie.d.ts.map +1 -0
- package/lib/app/auth/adapters/jwtCookie.js +120 -0
- package/lib/app/auth/adapters/jwtCookie.js.map +1 -0
- package/lib/app/auth/index.d.ts +8 -0
- package/lib/app/auth/index.d.ts.map +1 -0
- package/lib/app/auth/index.js +7 -0
- package/lib/app/auth/index.js.map +1 -0
- package/lib/app/auth/jwt/AuthFlow.d.ts +94 -0
- package/lib/app/auth/jwt/AuthFlow.d.ts.map +1 -0
- package/lib/app/auth/jwt/AuthFlow.js +127 -0
- package/lib/app/auth/jwt/AuthFlow.js.map +1 -0
- package/lib/app/auth/jwt/DrizzleRefreshTokenStore.d.ts +80 -0
- package/lib/app/auth/jwt/DrizzleRefreshTokenStore.d.ts.map +1 -0
- package/lib/app/auth/jwt/DrizzleRefreshTokenStore.js +134 -0
- package/lib/app/auth/jwt/DrizzleRefreshTokenStore.js.map +1 -0
- package/lib/app/auth/jwt/JwtSigner.d.ts +123 -0
- package/lib/app/auth/jwt/JwtSigner.d.ts.map +1 -0
- package/lib/app/auth/jwt/JwtSigner.js +118 -0
- package/lib/app/auth/jwt/JwtSigner.js.map +1 -0
- package/lib/app/auth/jwt/RefreshTokenStore.d.ts +97 -0
- package/lib/app/auth/jwt/RefreshTokenStore.d.ts.map +1 -0
- package/lib/app/auth/jwt/RefreshTokenStore.js +122 -0
- package/lib/app/auth/jwt/RefreshTokenStore.js.map +1 -0
- package/lib/app/auth/permissionDefinition.d.ts +20 -0
- package/lib/app/auth/permissionDefinition.d.ts.map +1 -0
- package/lib/app/auth/permissionDefinition.js +2 -0
- package/lib/app/auth/permissionDefinition.js.map +1 -0
- package/lib/app/context/RequestContext.d.ts +59 -0
- package/lib/app/context/RequestContext.d.ts.map +1 -0
- package/lib/app/context/RequestContext.js +25 -0
- package/lib/app/context/RequestContext.js.map +1 -0
- package/lib/app/db/QueryOptions.d.ts +82 -0
- package/lib/app/db/QueryOptions.d.ts.map +1 -0
- package/lib/app/db/QueryOptions.js +37 -0
- package/lib/app/db/QueryOptions.js.map +1 -0
- package/lib/app/db/baseFields.d.ts +60 -0
- package/lib/app/db/baseFields.d.ts.map +1 -0
- package/lib/app/db/baseFields.js +54 -0
- package/lib/app/db/baseFields.js.map +1 -0
- package/lib/app/db/buildWhere.d.ts +22 -0
- package/lib/app/db/buildWhere.d.ts.map +1 -0
- package/lib/app/db/buildWhere.js +75 -0
- package/lib/app/db/buildWhere.js.map +1 -0
- package/lib/app/db/client.d.ts +111 -0
- package/lib/app/db/client.d.ts.map +1 -0
- package/lib/app/db/client.js +99 -0
- package/lib/app/db/client.js.map +1 -0
- package/lib/app/db/tenantScoped.d.ts +59 -0
- package/lib/app/db/tenantScoped.d.ts.map +1 -0
- package/lib/app/db/tenantScoped.js +54 -0
- package/lib/app/db/tenantScoped.js.map +1 -0
- package/lib/app/db/transaction.d.ts +58 -0
- package/lib/app/db/transaction.d.ts.map +1 -0
- package/lib/app/db/transaction.js +106 -0
- package/lib/app/db/transaction.js.map +1 -0
- package/lib/app/health/HealthCheck.d.ts +121 -0
- package/lib/app/health/HealthCheck.d.ts.map +1 -0
- package/lib/app/health/HealthCheck.js +151 -0
- package/lib/app/health/HealthCheck.js.map +1 -0
- package/lib/app/health/redisHealthCheck.d.ts +14 -0
- package/lib/app/health/redisHealthCheck.d.ts.map +1 -0
- package/lib/app/health/redisHealthCheck.js +21 -0
- package/lib/app/health/redisHealthCheck.js.map +1 -0
- package/lib/app/lifecycle/Bootstrapper.d.ts +92 -0
- package/lib/app/lifecycle/Bootstrapper.d.ts.map +1 -0
- package/lib/app/lifecycle/Bootstrapper.js +99 -0
- package/lib/app/lifecycle/Bootstrapper.js.map +1 -0
- package/lib/app/registry/routes.d.ts +89 -0
- package/lib/app/registry/routes.d.ts.map +1 -0
- package/lib/app/registry/routes.js +72 -0
- package/lib/app/registry/routes.js.map +1 -0
- package/lib/app/services/DrizzleEntityService.d.ts +123 -0
- package/lib/app/services/DrizzleEntityService.d.ts.map +1 -0
- package/lib/app/services/DrizzleEntityService.js +342 -0
- package/lib/app/services/DrizzleEntityService.js.map +1 -0
- package/lib/app/services/RedisProvider.d.ts +52 -0
- package/lib/app/services/RedisProvider.d.ts.map +1 -0
- package/lib/app/services/RedisProvider.js +75 -0
- package/lib/app/services/RedisProvider.js.map +1 -0
- package/lib/app/services/cache/Cache.d.ts +70 -0
- package/lib/app/services/cache/Cache.d.ts.map +1 -0
- package/lib/app/services/cache/Cache.js +18 -0
- package/lib/app/services/cache/Cache.js.map +1 -0
- package/lib/app/services/cache/InMemoryCache.d.ts +35 -0
- package/lib/app/services/cache/InMemoryCache.d.ts.map +1 -0
- package/lib/app/services/cache/InMemoryCache.js +76 -0
- package/lib/app/services/cache/InMemoryCache.js.map +1 -0
- package/lib/app/services/cache/RedisCache.d.ts +99 -0
- package/lib/app/services/cache/RedisCache.d.ts.map +1 -0
- package/lib/app/services/cache/RedisCache.js +150 -0
- package/lib/app/services/cache/RedisCache.js.map +1 -0
- package/lib/app/services/cache/cached.d.ts +30 -0
- package/lib/app/services/cache/cached.d.ts.map +1 -0
- package/lib/app/services/cache/cached.js +38 -0
- package/lib/app/services/cache/cached.js.map +1 -0
- package/lib/app/services/cache/index.d.ts +5 -0
- package/lib/app/services/cache/index.d.ts.map +1 -0
- package/lib/app/services/cache/index.js +4 -0
- package/lib/app/services/cache/index.js.map +1 -0
- package/lib/app/services/cron/defineCron.d.ts +57 -0
- package/lib/app/services/cron/defineCron.d.ts.map +1 -0
- package/lib/app/services/cron/defineCron.js +15 -0
- package/lib/app/services/cron/defineCron.js.map +1 -0
- package/lib/app/services/cron/index.d.ts +2 -0
- package/lib/app/services/cron/index.d.ts.map +1 -0
- package/lib/app/services/cron/index.js +2 -0
- package/lib/app/services/cron/index.js.map +1 -0
- package/lib/app/services/hooks/LifecycleHooks.d.ts +61 -0
- package/lib/app/services/hooks/LifecycleHooks.d.ts.map +1 -0
- package/lib/app/services/hooks/LifecycleHooks.js +85 -0
- package/lib/app/services/hooks/LifecycleHooks.js.map +1 -0
- package/lib/app/services/jobs/JobsManager.d.ts +67 -0
- package/lib/app/services/jobs/JobsManager.d.ts.map +1 -0
- package/lib/app/services/jobs/JobsManager.js +121 -0
- package/lib/app/services/jobs/JobsManager.js.map +1 -0
- package/lib/app/services/jobs/bullBoard.d.ts +72 -0
- package/lib/app/services/jobs/bullBoard.d.ts.map +1 -0
- package/lib/app/services/jobs/bullBoard.js +96 -0
- package/lib/app/services/jobs/bullBoard.js.map +1 -0
- package/lib/app/services/jobs/defineJob.d.ts +81 -0
- package/lib/app/services/jobs/defineJob.d.ts.map +1 -0
- package/lib/app/services/jobs/defineJob.js +49 -0
- package/lib/app/services/jobs/defineJob.js.map +1 -0
- package/lib/app/services/jobs/index.d.ts +4 -0
- package/lib/app/services/jobs/index.d.ts.map +1 -0
- package/lib/app/services/jobs/index.js +4 -0
- package/lib/app/services/jobs/index.js.map +1 -0
- package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.d.ts +23 -0
- package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.d.ts.map +1 -0
- package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.js +51 -0
- package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.js.map +1 -0
- package/lib/app/services/rateLimit/RateLimitBackend.d.ts +41 -0
- package/lib/app/services/rateLimit/RateLimitBackend.d.ts.map +1 -0
- package/lib/app/services/rateLimit/RateLimitBackend.js +19 -0
- package/lib/app/services/rateLimit/RateLimitBackend.js.map +1 -0
- package/lib/app/services/rateLimit/RedisSlidingWindowBackend.d.ts +16 -0
- package/lib/app/services/rateLimit/RedisSlidingWindowBackend.d.ts.map +1 -0
- package/lib/app/services/rateLimit/RedisSlidingWindowBackend.js +80 -0
- package/lib/app/services/rateLimit/RedisSlidingWindowBackend.js.map +1 -0
- package/lib/app/services/rateLimit/index.d.ts +4 -0
- package/lib/app/services/rateLimit/index.d.ts.map +1 -0
- package/lib/app/services/rateLimit/index.js +3 -0
- package/lib/app/services/rateLimit/index.js.map +1 -0
- package/lib/app/services/storage/DiskStorageAdapter.d.ts +62 -0
- package/lib/app/services/storage/DiskStorageAdapter.d.ts.map +1 -0
- package/lib/app/services/storage/DiskStorageAdapter.js +295 -0
- package/lib/app/services/storage/DiskStorageAdapter.js.map +1 -0
- package/lib/app/services/storage/GCSStorageAdapter.d.ts +44 -0
- package/lib/app/services/storage/GCSStorageAdapter.d.ts.map +1 -0
- package/lib/app/services/storage/GCSStorageAdapter.js +133 -0
- package/lib/app/services/storage/GCSStorageAdapter.js.map +1 -0
- package/lib/app/services/storage/S3StorageAdapter.d.ts +57 -0
- package/lib/app/services/storage/S3StorageAdapter.d.ts.map +1 -0
- package/lib/app/services/storage/S3StorageAdapter.js +162 -0
- package/lib/app/services/storage/S3StorageAdapter.js.map +1 -0
- package/lib/app/services/storage/StorageService.d.ts +88 -0
- package/lib/app/services/storage/StorageService.d.ts.map +1 -0
- package/lib/app/services/storage/StorageService.js +18 -0
- package/lib/app/services/storage/StorageService.js.map +1 -0
- package/lib/app/services/storage/index.d.ts +5 -0
- package/lib/app/services/storage/index.d.ts.map +1 -0
- package/lib/app/services/storage/index.js +4 -0
- package/lib/app/services/storage/index.js.map +1 -0
- package/lib/app/utils/ContextValidators.d.ts +46 -0
- package/lib/app/utils/ContextValidators.d.ts.map +1 -0
- package/lib/app/utils/ContextValidators.js +81 -0
- package/lib/app/utils/ContextValidators.js.map +1 -0
- package/lib/app/utils/defineEnv.d.ts +80 -0
- package/lib/app/utils/defineEnv.d.ts.map +1 -0
- package/lib/app/utils/defineEnv.js +95 -0
- package/lib/app/utils/defineEnv.js.map +1 -0
- package/lib/client.d.ts +139 -0
- package/lib/client.d.ts.map +1 -0
- package/lib/client.js +98 -0
- package/lib/client.js.map +1 -0
- package/lib/contract/application.d.ts +3 -0
- package/lib/contract/application.d.ts.map +1 -0
- package/lib/contract/application.js +2 -0
- package/lib/contract/application.js.map +1 -0
- package/lib/contract/client.d.ts +3 -0
- package/lib/contract/client.d.ts.map +1 -0
- package/lib/contract/client.js +3 -0
- package/lib/contract/client.js.map +1 -0
- package/lib/contract/index.d.ts +3 -0
- package/lib/contract/index.d.ts.map +1 -0
- package/lib/contract/index.js +3 -0
- package/lib/contract/index.js.map +1 -0
- package/lib/contract/manifest.d.ts +3 -0
- package/lib/contract/manifest.d.ts.map +1 -0
- package/lib/contract/manifest.js +2 -0
- package/lib/contract/manifest.js.map +1 -0
- package/lib/contract/openapi.d.ts +3 -0
- package/lib/contract/openapi.d.ts.map +1 -0
- package/lib/contract/openapi.js +3 -0
- package/lib/contract/openapi.js.map +1 -0
- package/lib/contract/project.d.ts +3 -0
- package/lib/contract/project.d.ts.map +1 -0
- package/lib/contract/project.js +3 -0
- package/lib/contract/project.js.map +1 -0
- package/lib/contract/schema.d.ts +3 -0
- package/lib/contract/schema.d.ts.map +1 -0
- package/lib/contract/schema.js +3 -0
- package/lib/contract/schema.js.map +1 -0
- package/lib/drizzle/index.d.ts +3 -0
- package/lib/drizzle/index.d.ts.map +1 -0
- package/lib/drizzle/index.js +3 -0
- package/lib/drizzle/index.js.map +1 -0
- package/lib/hono/auth.d.ts +6 -0
- package/lib/hono/auth.d.ts.map +1 -0
- package/lib/hono/auth.js +54 -0
- package/lib/hono/auth.js.map +1 -0
- package/lib/hono/index.d.ts +4 -0
- package/lib/hono/index.d.ts.map +1 -0
- package/lib/hono/index.js +4 -0
- package/lib/hono/index.js.map +1 -0
- package/lib/http/app/createApp.d.ts +132 -0
- package/lib/http/app/createApp.d.ts.map +1 -0
- package/lib/http/app/createApp.js +215 -0
- package/lib/http/app/createApp.js.map +1 -0
- package/lib/http/app/devRoutes.d.ts +31 -0
- package/lib/http/app/devRoutes.d.ts.map +1 -0
- package/lib/http/app/devRoutes.js +145 -0
- package/lib/http/app/devRoutes.js.map +1 -0
- package/lib/http/app/errors.d.ts +45 -0
- package/lib/http/app/errors.d.ts.map +1 -0
- package/lib/http/app/errors.js +93 -0
- package/lib/http/app/errors.js.map +1 -0
- package/lib/http/app/health.d.ts +66 -0
- package/lib/http/app/health.d.ts.map +1 -0
- package/lib/http/app/health.js +104 -0
- package/lib/http/app/health.js.map +1 -0
- package/lib/http/errors/AppError.d.ts +10 -0
- package/lib/http/errors/AppError.d.ts.map +1 -0
- package/lib/http/errors/AppError.js +19 -0
- package/lib/http/errors/AppError.js.map +1 -0
- package/lib/http/errors/AuthenticationError.d.ts +8 -0
- package/lib/http/errors/AuthenticationError.d.ts.map +1 -0
- package/lib/http/errors/AuthenticationError.js +10 -0
- package/lib/http/errors/AuthenticationError.js.map +1 -0
- package/lib/http/errors/AuthorizationError.d.ts +8 -0
- package/lib/http/errors/AuthorizationError.d.ts.map +1 -0
- package/lib/http/errors/AuthorizationError.js +10 -0
- package/lib/http/errors/AuthorizationError.js.map +1 -0
- package/lib/http/errors/BadRequestError.d.ts +8 -0
- package/lib/http/errors/BadRequestError.d.ts.map +1 -0
- package/lib/http/errors/BadRequestError.js +10 -0
- package/lib/http/errors/BadRequestError.js.map +1 -0
- package/lib/http/errors/ConflictError.d.ts +8 -0
- package/lib/http/errors/ConflictError.d.ts.map +1 -0
- package/lib/http/errors/ConflictError.js +10 -0
- package/lib/http/errors/ConflictError.js.map +1 -0
- package/lib/http/errors/InternalServerError.d.ts +8 -0
- package/lib/http/errors/InternalServerError.d.ts.map +1 -0
- package/lib/http/errors/InternalServerError.js +10 -0
- package/lib/http/errors/InternalServerError.js.map +1 -0
- package/lib/http/errors/NotFoundError.d.ts +8 -0
- package/lib/http/errors/NotFoundError.d.ts.map +1 -0
- package/lib/http/errors/NotFoundError.js +10 -0
- package/lib/http/errors/NotFoundError.js.map +1 -0
- package/lib/http/errors/RateLimitError.d.ts +13 -0
- package/lib/http/errors/RateLimitError.d.ts.map +1 -0
- package/lib/http/errors/RateLimitError.js +16 -0
- package/lib/http/errors/RateLimitError.js.map +1 -0
- package/lib/http/errors/ServiceUnavailableError.d.ts +8 -0
- package/lib/http/errors/ServiceUnavailableError.d.ts.map +1 -0
- package/lib/http/errors/ServiceUnavailableError.js +10 -0
- package/lib/http/errors/ServiceUnavailableError.js.map +1 -0
- package/lib/http/errors/ValidationError.d.ts +9 -0
- package/lib/http/errors/ValidationError.d.ts.map +1 -0
- package/lib/http/errors/ValidationError.js +12 -0
- package/lib/http/errors/ValidationError.js.map +1 -0
- package/lib/http/errors/index.d.ts +11 -0
- package/lib/http/errors/index.d.ts.map +1 -0
- package/lib/http/errors/index.js +12 -0
- package/lib/http/errors/index.js.map +1 -0
- package/lib/http/middleware/apiKey.d.ts +9 -0
- package/lib/http/middleware/apiKey.d.ts.map +1 -0
- package/lib/http/middleware/apiKey.js +71 -0
- package/lib/http/middleware/apiKey.js.map +1 -0
- package/lib/http/middleware/csrf.d.ts +63 -0
- package/lib/http/middleware/csrf.d.ts.map +1 -0
- package/lib/http/middleware/csrf.js +169 -0
- package/lib/http/middleware/csrf.js.map +1 -0
- package/lib/http/middleware/httpLogger.d.ts +39 -0
- package/lib/http/middleware/httpLogger.d.ts.map +1 -0
- package/lib/http/middleware/httpLogger.js +118 -0
- package/lib/http/middleware/httpLogger.js.map +1 -0
- package/lib/http/middleware/idempotency.d.ts +48 -0
- package/lib/http/middleware/idempotency.d.ts.map +1 -0
- package/lib/http/middleware/idempotency.js +180 -0
- package/lib/http/middleware/idempotency.js.map +1 -0
- package/lib/http/middleware/rateLimit.d.ts +105 -0
- package/lib/http/middleware/rateLimit.d.ts.map +1 -0
- package/lib/http/middleware/rateLimit.js +84 -0
- package/lib/http/middleware/rateLimit.js.map +1 -0
- package/lib/http/middleware/requireAuth.d.ts +58 -0
- package/lib/http/middleware/requireAuth.d.ts.map +1 -0
- package/lib/http/middleware/requireAuth.js +63 -0
- package/lib/http/middleware/requireAuth.js.map +1 -0
- package/lib/http/middleware/requirePermission.d.ts +23 -0
- package/lib/http/middleware/requirePermission.d.ts.map +1 -0
- package/lib/http/middleware/requirePermission.js +50 -0
- package/lib/http/middleware/requirePermission.js.map +1 -0
- package/lib/http/middleware/resolveTenant.d.ts +41 -0
- package/lib/http/middleware/resolveTenant.d.ts.map +1 -0
- package/lib/http/middleware/resolveTenant.js +17 -0
- package/lib/http/middleware/resolveTenant.js.map +1 -0
- package/lib/http/streaming/sse.d.ts +31 -0
- package/lib/http/streaming/sse.d.ts.map +1 -0
- package/lib/http/streaming/sse.js +11 -0
- package/lib/http/streaming/sse.js.map +1 -0
- package/lib/http/streaming/streamLLM.d.ts +94 -0
- package/lib/http/streaming/streamLLM.d.ts.map +1 -0
- package/lib/http/streaming/streamLLM.js +94 -0
- package/lib/http/streaming/streamLLM.js.map +1 -0
- package/lib/http/utils/authCookies.d.ts +74 -0
- package/lib/http/utils/authCookies.d.ts.map +1 -0
- package/lib/http/utils/authCookies.js +102 -0
- package/lib/http/utils/authCookies.js.map +1 -0
- package/lib/http/utils/clientIp.d.ts +85 -0
- package/lib/http/utils/clientIp.d.ts.map +1 -0
- package/lib/http/utils/clientIp.js +249 -0
- package/lib/http/utils/clientIp.js.map +1 -0
- package/lib/http/utils/index.d.ts +4 -0
- package/lib/http/utils/index.d.ts.map +1 -0
- package/lib/http/utils/index.js +5 -0
- package/lib/http/utils/index.js.map +1 -0
- package/lib/http/utils/metaTags.d.ts +49 -0
- package/lib/http/utils/metaTags.d.ts.map +1 -0
- package/lib/http/utils/metaTags.js +32 -0
- package/lib/http/utils/metaTags.js.map +1 -0
- package/lib/http/utils/publicSuffix.d.ts +34 -0
- package/lib/http/utils/publicSuffix.d.ts.map +1 -0
- package/lib/http/utils/publicSuffix.js +276 -0
- package/lib/http/utils/publicSuffix.js.map +1 -0
- package/lib/http/utils/uploads.d.ts +92 -0
- package/lib/http/utils/uploads.d.ts.map +1 -0
- package/lib/http/utils/uploads.js +126 -0
- package/lib/http/utils/uploads.js.map +1 -0
- package/lib/http/utils/validate.d.ts +41 -0
- package/lib/http/utils/validate.d.ts.map +1 -0
- package/lib/http/utils/validate.js +55 -0
- package/lib/http/utils/validate.js.map +1 -0
- package/lib/http/utils/webhooks.d.ts +63 -0
- package/lib/http/utils/webhooks.d.ts.map +1 -0
- package/lib/http/utils/webhooks.js +133 -0
- package/lib/http/utils/webhooks.js.map +1 -0
- package/lib/http/ws/auth.d.ts +46 -0
- package/lib/http/ws/auth.d.ts.map +1 -0
- package/lib/http/ws/auth.js +123 -0
- package/lib/http/ws/auth.js.map +1 -0
- package/lib/index.d.ts +80 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +61 -0
- package/lib/index.js.map +1 -0
- package/lib/kernel/index.d.ts +3 -0
- package/lib/kernel/index.d.ts.map +1 -0
- package/lib/kernel/index.js +3 -0
- package/lib/kernel/index.js.map +1 -0
- package/lib/libraries/.gitkeep +0 -0
- package/lib/libraries/ai/CHANGELOG.md +17 -0
- package/lib/libraries/ai/README.md +164 -0
- package/lib/libraries/ai/adapters/AnthropicAdapter.ts +382 -0
- package/lib/libraries/ai/adapters/LLMProvider.ts +76 -0
- package/lib/libraries/ai/adapters/OpenAIAdapter.ts +466 -0
- package/lib/libraries/ai/experimental/index.ts +20 -0
- package/lib/libraries/ai/index.ts +128 -0
- package/lib/libraries/ai/library.json +19 -0
- package/lib/libraries/ai/loop/agentLoop.ts +377 -0
- package/lib/libraries/ai/prompts/definePrompt.ts +0 -0
- package/lib/libraries/ai/rag/retrieveAndAnswer.ts +177 -0
- package/lib/libraries/ai/streaming/streamLLM.ts +94 -0
- package/lib/libraries/ai/structured/completeStructured.ts +143 -0
- package/lib/libraries/ai/tokens/Tokenizer.ts +216 -0
- package/lib/libraries/ai/tools/defineTool.ts +208 -0
- package/lib/libraries/ai/types.ts +260 -0
- package/lib/libraries/chunking/ChunkingService.ts +103 -0
- package/lib/libraries/chunking/README.md +104 -0
- package/lib/libraries/chunking/docs/api-reference.md +549 -0
- package/lib/libraries/chunking/docs/best-practices.md +321 -0
- package/lib/libraries/chunking/docs/code-organization.md +538 -0
- package/lib/libraries/chunking/docs/configuration.md +418 -0
- package/lib/libraries/chunking/docs/index.md +236 -0
- package/lib/libraries/chunking/docs/quick-start.md +298 -0
- package/lib/libraries/chunking/docs/strategies.md +407 -0
- package/lib/libraries/chunking/docs/summary.md +258 -0
- package/lib/libraries/chunking/docs/troubleshooting.md +527 -0
- package/lib/libraries/chunking/index.ts +17 -0
- package/lib/libraries/chunking/library.json +16 -0
- package/lib/libraries/chunking/strategies/ChunkingStrategy.ts +13 -0
- package/lib/libraries/chunking/strategies/FixedLengthChunkingStrategy.ts +88 -0
- package/lib/libraries/chunking/strategies/SemanticChunkingStrategy.ts +389 -0
- package/lib/libraries/chunking/strategies/SlidingWindowChunkingStrategy.ts +258 -0
- package/lib/libraries/chunking/types/index.ts +63 -0
- package/lib/libraries/email/EmailService.ts +591 -0
- package/lib/libraries/email/README.md +777 -0
- package/lib/libraries/email/TemplateRegistry.ts +148 -0
- package/lib/libraries/email/TemplateRenderer.ts +273 -0
- package/lib/libraries/email/index.ts +4 -0
- package/lib/libraries/email/initializeEmailService.ts +60 -0
- package/lib/libraries/email/library.json +12 -0
- package/lib/libraries/email/types/EmailAddress.ts +4 -0
- package/lib/libraries/email/types/EmailAttachment.ts +11 -0
- package/lib/libraries/email/types/EmailTag.ts +9 -0
- package/lib/libraries/email/types/EmailTemplate.ts +124 -0
- package/lib/libraries/email/types/SendBatchEmailsOptions.ts +9 -0
- package/lib/libraries/email/types/SendBatchEmailsResult.ts +9 -0
- package/lib/libraries/email/types/SendEmailOptions.ts +33 -0
- package/lib/libraries/email/types/SendEmailResult.ts +9 -0
- package/lib/libraries/email/types/index.ts +8 -0
- package/lib/libraries/weaviate/QueryBuilder.ts +292 -0
- package/lib/libraries/weaviate/README.md +284 -0
- package/lib/libraries/weaviate/Weaviate.ts +1419 -0
- package/lib/libraries/weaviate/WeaviateConfig.ts +268 -0
- package/lib/libraries/weaviate/docs/.gitkeep +1 -0
- package/lib/libraries/weaviate/docs/API_REFERENCE.md +1067 -0
- package/lib/libraries/weaviate/docs/CONFIGURATION.md +320 -0
- package/lib/libraries/weaviate/docs/ERROR_HANDLING.md +271 -0
- package/lib/libraries/weaviate/docs/MULTI_TENANCY.md +348 -0
- package/lib/libraries/weaviate/docs/PERFORMANCE.md +602 -0
- package/lib/libraries/weaviate/docs/PLUGIN_DEVELOPMENT.md +547 -0
- package/lib/libraries/weaviate/docs/QUICK_START.md +443 -0
- package/lib/libraries/weaviate/docs/README.md +269 -0
- package/lib/libraries/weaviate/docs/SCHEMA_GUIDE.md +630 -0
- package/lib/libraries/weaviate/docs/WEAVIATE_README.md +520 -0
- package/lib/libraries/weaviate/errors/WeaviateError.ts +92 -0
- package/lib/libraries/weaviate/errors/index.ts +1 -0
- package/lib/libraries/weaviate/index.ts +35 -0
- package/lib/libraries/weaviate/library.json +26 -0
- package/lib/libraries/weaviate/plugins/index.ts +2 -0
- package/lib/libraries/weaviate/schemas/SchemaRegistry.ts +284 -0
- package/lib/libraries/weaviate/schemas/index.ts +2 -0
- package/lib/libraries/weaviate/types/BM25SearchOptions.ts +9 -0
- package/lib/libraries/weaviate/types/ExtendedWeaviateClient.ts +7 -0
- package/lib/libraries/weaviate/types/HybridSearchOptions.ts +11 -0
- package/lib/libraries/weaviate/types/MultiTenancy.ts +81 -0
- package/lib/libraries/weaviate/types/Plugin.ts +17 -0
- package/lib/libraries/weaviate/types/SchemaConfig.ts +25 -0
- package/lib/libraries/weaviate/types/SearchMethod.ts +8 -0
- package/lib/libraries/weaviate/types/SearchOptions.ts +16 -0
- package/lib/libraries/weaviate/types/SearchRequest.ts +19 -0
- package/lib/libraries/weaviate/types/SearchResult.ts +16 -0
- package/lib/libraries/weaviate/types/SearchableField.ts +87 -0
- package/lib/libraries/weaviate/types/VectorIndexConfig.ts +19 -0
- package/lib/libraries/weaviate/types/VectorSearchOptions.ts +18 -0
- package/lib/libraries/weaviate/types/VectorizerConfig.ts +8 -0
- package/lib/libraries/weaviate/types/index.ts +29 -0
- package/lib/libraries/weaviate/utils/TenantContextManager.ts +94 -0
- package/lib/modules/accounts/index.ts +47 -0
- package/lib/modules/accounts/module.json +15 -0
- package/lib/modules/accounts/permissions.ts +33 -0
- package/lib/modules/accounts/routes.ts +200 -0
- package/lib/modules/accounts/schema.ts +219 -0
- package/lib/modules/accounts/services/AccountService.ts +44 -0
- package/lib/modules/accounts/validation/schemas.ts +70 -0
- package/lib/modules/oauth/adapters/GmailOAuthAdapter.ts +35 -0
- package/lib/modules/oauth/adapters/GoogleOAuthAdapter.ts +278 -0
- package/lib/modules/oauth/adapters/MicrosoftOAuthAdapter.ts +269 -0
- package/lib/modules/oauth/adapters/MockOAuthAdapter.ts +138 -0
- package/lib/modules/oauth/adapters/OAuthAdapter.ts +211 -0
- package/lib/modules/oauth/adapters/OAuthAdapterRegistry.ts +77 -0
- package/lib/modules/oauth/adapters/OutlookOAuthAdapter.ts +38 -0
- package/lib/modules/oauth/index.ts +79 -0
- package/lib/modules/oauth/module.json +23 -0
- package/lib/modules/oauth/permissions.ts +39 -0
- package/lib/modules/oauth/routes.ts +497 -0
- package/lib/modules/oauth/schema.ts +127 -0
- package/lib/modules/oauth/services/OAuthConnectionService.ts +147 -0
- package/lib/modules/oauth/state.ts +234 -0
- package/lib/modules/oauth/stateJtiCache.ts +85 -0
- package/lib/modules/oauth/verifyIdToken.ts +178 -0
- package/lib/modules/outbox/EventEmitter.ts +106 -0
- package/lib/modules/outbox/OutboxDrainer.ts +163 -0
- package/lib/modules/outbox/handlers/EventHandler.ts +115 -0
- package/lib/modules/outbox/index.ts +43 -0
- package/lib/modules/outbox/module.json +15 -0
- package/lib/modules/outbox/permissions.ts +36 -0
- package/lib/modules/outbox/routes.ts +219 -0
- package/lib/modules/outbox/schema.ts +207 -0
- package/lib/modules/outbox/services/OutboxEventService.ts +223 -0
- package/lib/observability/logger.d.ts +30 -0
- package/lib/observability/logger.d.ts.map +1 -0
- package/lib/observability/logger.js +110 -0
- package/lib/observability/logger.js.map +1 -0
- package/lib/observability/metrics.d.ts +3 -0
- package/lib/observability/metrics.d.ts.map +1 -0
- package/lib/observability/metrics.js +3 -0
- package/lib/observability/metrics.js.map +1 -0
- package/lib/observability/otel.d.ts +3 -0
- package/lib/observability/otel.d.ts.map +1 -0
- package/lib/observability/otel.js +3 -0
- package/lib/observability/otel.js.map +1 -0
- package/lib/observability/safeErrorFields.d.ts +14 -0
- package/lib/observability/safeErrorFields.d.ts.map +1 -0
- package/lib/observability/safeErrorFields.js +14 -0
- package/lib/observability/safeErrorFields.js.map +1 -0
- package/lib/observability/tracing.d.ts +3 -0
- package/lib/observability/tracing.d.ts.map +1 -0
- package/lib/observability/tracing.js +3 -0
- package/lib/observability/tracing.js.map +1 -0
- package/lib/package.json +4 -0
- package/lib/testing.d.ts +3 -0
- package/lib/testing.d.ts.map +1 -0
- package/lib/testing.js +3 -0
- package/lib/testing.js.map +1 -0
- package/package.json +193 -3
- package/templates/default/.claude/agents/qa-brief.md +106 -0
- package/templates/default/.claude/commands/sherpa-brief.md +23 -0
- package/templates/default/.cursor/rules/api.mdc +80 -0
- package/templates/default/.cursor/rules/commits.mdc +88 -0
- package/templates/default/.cursor/rules/security.mdc +92 -0
- package/templates/default/.cursor/rules/testing.mdc +123 -0
- package/templates/default/.cursor/rules/typescript.mdc +86 -0
- package/templates/default/.env.example +79 -0
- package/templates/default/.github/workflows/sherpa-brief.yml +180 -0
- package/templates/default/AGENTS.md +166 -0
- package/templates/default/CLAUDE.md +17 -0
- package/templates/default/README.md +97 -0
- package/templates/default/_gitignore +27 -0
- package/templates/default/docker-compose.yml +83 -0
- package/templates/default/drizzle.config.ts +34 -0
- package/templates/default/eslint.config.mjs +106 -0
- package/templates/default/package.json +57 -0
- package/templates/default/ship-api.config.ts +21 -0
- package/templates/default/src/client.ts +34 -0
- package/templates/default/src/config/modules.ts +23 -0
- package/templates/default/src/db/schema.ts +26 -0
- package/templates/default/src/environment.ts +81 -0
- package/templates/default/src/index.test.ts +53 -0
- package/templates/default/src/index.ts +11 -0
- package/templates/default/src/instrumentation.ts +13 -0
- package/templates/default/src/server.ts +90 -0
- package/templates/default/tsconfig.json +24 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
# Chunking Library - API Reference
|
|
2
|
+
|
|
3
|
+
Complete API documentation for the chunking library.
|
|
4
|
+
|
|
5
|
+
## ChunkingService
|
|
6
|
+
|
|
7
|
+
The main entry point for document chunking. Uses the Strategy pattern to delegate chunking logic to pluggable strategy implementations.
|
|
8
|
+
|
|
9
|
+
### Constructor
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
constructor(strategy: ChunkingStrategy)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Creates a new `ChunkingService` with the specified strategy.
|
|
16
|
+
|
|
17
|
+
**Parameters:**
|
|
18
|
+
|
|
19
|
+
| Parameter | Type | Description |
|
|
20
|
+
|-----------|------|-------------|
|
|
21
|
+
| `strategy` | `ChunkingStrategy` | The chunking strategy implementation to use |
|
|
22
|
+
|
|
23
|
+
**Example:**
|
|
24
|
+
```typescript
|
|
25
|
+
const strategy = new SemanticChunkingStrategy({ maxTokens: 512 });
|
|
26
|
+
const service = new ChunkingService(strategy);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### chunk()
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
async chunk(text: string): Promise<TextChunk[]>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Chunks the given text using the configured strategy.
|
|
38
|
+
|
|
39
|
+
**Parameters:**
|
|
40
|
+
|
|
41
|
+
| Parameter | Type | Description |
|
|
42
|
+
|-----------|------|-------------|
|
|
43
|
+
| `text` | `string` | The text to chunk |
|
|
44
|
+
|
|
45
|
+
**Returns:** `Promise<TextChunk[]>` - Array of text chunks
|
|
46
|
+
|
|
47
|
+
**Behavior:**
|
|
48
|
+
- Returns an empty array if `text` is empty, null, or contains only whitespace
|
|
49
|
+
- Delegates to the configured strategy for actual chunking
|
|
50
|
+
- All strategies are async-compatible
|
|
51
|
+
|
|
52
|
+
**Example:**
|
|
53
|
+
```typescript
|
|
54
|
+
const chunks = await service.chunk(documentText);
|
|
55
|
+
|
|
56
|
+
for (const chunk of chunks) {
|
|
57
|
+
console.log(`Chunk ${chunk.chunkIndex}: ${chunk.tokenCount} tokens`);
|
|
58
|
+
console.log(chunk.content);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### setStrategy()
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
setStrategy(strategy: ChunkingStrategy): void
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Replaces the current chunking strategy at runtime.
|
|
71
|
+
|
|
72
|
+
**Parameters:**
|
|
73
|
+
|
|
74
|
+
| Parameter | Type | Description |
|
|
75
|
+
|-----------|------|-------------|
|
|
76
|
+
| `strategy` | `ChunkingStrategy` | The new strategy to use |
|
|
77
|
+
|
|
78
|
+
**Example:**
|
|
79
|
+
```typescript
|
|
80
|
+
// Start with semantic
|
|
81
|
+
const service = ChunkingService.createWithSemantic({ maxTokens: 512 });
|
|
82
|
+
const structuredChunks = await service.chunk(markdownDoc);
|
|
83
|
+
|
|
84
|
+
// Switch to sliding window for different content
|
|
85
|
+
service.setStrategy(
|
|
86
|
+
new SlidingWindowChunkingStrategy({ maxTokens: 512, overlapTokens: 80 })
|
|
87
|
+
);
|
|
88
|
+
const narrativeChunks = await service.chunk(articleText);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
> **Note:** The previous strategy is not automatically disposed. If you need to free resources, call `dispose()` before switching, or dispose the old strategy manually.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
### dispose()
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
dispose(): void
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Cleans up resources held by the current strategy (primarily the tiktoken encoder).
|
|
102
|
+
|
|
103
|
+
**Important:** Always call `dispose()` when you're done with the service to free the native tiktoken encoder memory.
|
|
104
|
+
|
|
105
|
+
**Example:**
|
|
106
|
+
```typescript
|
|
107
|
+
const service = ChunkingService.createWithSemantic({ maxTokens: 512 });
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const chunks = await service.chunk(text);
|
|
111
|
+
// Process chunks...
|
|
112
|
+
} finally {
|
|
113
|
+
service.dispose();
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Static Factory Methods
|
|
120
|
+
|
|
121
|
+
### static createWithFixedLength()
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
static createWithFixedLength(options: FixedLengthChunkingOptions): ChunkingService
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Creates a `ChunkingService` with the Fixed Length strategy.
|
|
128
|
+
|
|
129
|
+
**Parameters:**
|
|
130
|
+
|
|
131
|
+
| Parameter | Type | Description |
|
|
132
|
+
|-----------|------|-------------|
|
|
133
|
+
| `options` | `FixedLengthChunkingOptions` | Configuration options |
|
|
134
|
+
|
|
135
|
+
**Example:**
|
|
136
|
+
```typescript
|
|
137
|
+
const service = ChunkingService.createWithFixedLength({
|
|
138
|
+
maxTokens: 512,
|
|
139
|
+
encoding: "cl100k_base",
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
### static createWithSlidingWindow()
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
static createWithSlidingWindow(options: SlidingWindowChunkingOptions): ChunkingService
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Creates a `ChunkingService` with the Sliding Window strategy.
|
|
152
|
+
|
|
153
|
+
**Parameters:**
|
|
154
|
+
|
|
155
|
+
| Parameter | Type | Description |
|
|
156
|
+
|-----------|------|-------------|
|
|
157
|
+
| `options` | `SlidingWindowChunkingOptions` | Configuration options |
|
|
158
|
+
|
|
159
|
+
**Example:**
|
|
160
|
+
```typescript
|
|
161
|
+
const service = ChunkingService.createWithSlidingWindow({
|
|
162
|
+
maxTokens: 512,
|
|
163
|
+
overlapTokens: 80,
|
|
164
|
+
preferParagraphBoundaries: true,
|
|
165
|
+
minChunkRatio: 0.5,
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
### static createWithSemantic()
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
static createWithSemantic(options: SemanticChunkingOptions): ChunkingService
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Creates a `ChunkingService` with the Semantic strategy. **Recommended for production RAG applications.**
|
|
178
|
+
|
|
179
|
+
**Parameters:**
|
|
180
|
+
|
|
181
|
+
| Parameter | Type | Description |
|
|
182
|
+
|-----------|------|-------------|
|
|
183
|
+
| `options` | `SemanticChunkingOptions` | Configuration options |
|
|
184
|
+
|
|
185
|
+
**Example:**
|
|
186
|
+
```typescript
|
|
187
|
+
const service = ChunkingService.createWithSemantic({
|
|
188
|
+
maxTokens: 512,
|
|
189
|
+
minTokens: 100,
|
|
190
|
+
mergeSmallChunks: true,
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### static create()
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
static create(options: ChunkingOptions): ChunkingService
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Auto-detects the appropriate strategy based on which options are provided.
|
|
203
|
+
|
|
204
|
+
**Detection Logic:**
|
|
205
|
+
|
|
206
|
+
| Options Present | Strategy Selected |
|
|
207
|
+
|-----------------|-------------------|
|
|
208
|
+
| `overlapTokens` | Sliding Window |
|
|
209
|
+
| `minTokens` or `mergeSmallChunks` | Semantic |
|
|
210
|
+
| Only `maxTokens` | Fixed Length |
|
|
211
|
+
|
|
212
|
+
**Parameters:**
|
|
213
|
+
|
|
214
|
+
| Parameter | Type | Description |
|
|
215
|
+
|-----------|------|-------------|
|
|
216
|
+
| `options` | `ChunkingOptions` | Configuration options (union type) |
|
|
217
|
+
|
|
218
|
+
**Example:**
|
|
219
|
+
```typescript
|
|
220
|
+
// Auto-detects Sliding Window
|
|
221
|
+
const sw = ChunkingService.create({ maxTokens: 512, overlapTokens: 80 });
|
|
222
|
+
|
|
223
|
+
// Auto-detects Semantic
|
|
224
|
+
const sem = ChunkingService.create({ maxTokens: 512, minTokens: 100 });
|
|
225
|
+
|
|
226
|
+
// Auto-detects Fixed Length
|
|
227
|
+
const fl = ChunkingService.create({ maxTokens: 512 });
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Strategy Interfaces
|
|
233
|
+
|
|
234
|
+
### ChunkingStrategy
|
|
235
|
+
|
|
236
|
+
Base interface that all chunking strategies must implement.
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
interface ChunkingStrategy {
|
|
240
|
+
chunk(text: string): Promise<TextChunk[]>;
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
| Method | Parameters | Returns | Description |
|
|
245
|
+
|--------|-----------|---------|-------------|
|
|
246
|
+
| `chunk` | `text: string` | `Promise<TextChunk[]>` | Chunks the text according to the strategy |
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Strategy Implementations
|
|
251
|
+
|
|
252
|
+
### FixedLengthChunkingStrategy
|
|
253
|
+
|
|
254
|
+
Splits text into non-overlapping chunks of a specified token count.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
class FixedLengthChunkingStrategy implements ChunkingStrategy {
|
|
258
|
+
constructor(options: FixedLengthChunkingOptions);
|
|
259
|
+
chunk(text: string): Promise<TextChunk[]>;
|
|
260
|
+
dispose(): void;
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Algorithm:**
|
|
265
|
+
1. Tokenize entire text using tiktoken
|
|
266
|
+
2. Split tokens into groups of `maxTokens`
|
|
267
|
+
3. Decode each group back to text
|
|
268
|
+
4. Calculate character indices
|
|
269
|
+
|
|
270
|
+
**Characteristics:**
|
|
271
|
+
- Fastest strategy (~100-200ms per 10KB)
|
|
272
|
+
- Precise token counting
|
|
273
|
+
- No overlap between chunks
|
|
274
|
+
- May split mid-sentence or mid-word
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
### SlidingWindowChunkingStrategy
|
|
279
|
+
|
|
280
|
+
Creates overlapping chunks with intelligent boundary detection.
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
class SlidingWindowChunkingStrategy implements ChunkingStrategy {
|
|
284
|
+
constructor(options: SlidingWindowChunkingOptions);
|
|
285
|
+
chunk(text: string): Promise<TextChunk[]>;
|
|
286
|
+
dispose(): void;
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**Constructor Validation:**
|
|
291
|
+
- Throws `Error` if `overlapTokens >= maxTokens`
|
|
292
|
+
- Throws `Error` if `minChunkRatio` is outside 0.1-0.9 range
|
|
293
|
+
|
|
294
|
+
**Algorithm:**
|
|
295
|
+
1. Tokenize text
|
|
296
|
+
2. Create windows with `stepSize = maxTokens - overlapTokens`
|
|
297
|
+
3. For each window:
|
|
298
|
+
- Try to end at paragraph boundary (if `preferParagraphBoundaries`)
|
|
299
|
+
- Fall back to sentence boundary
|
|
300
|
+
- Validate against `minChunkRatio`
|
|
301
|
+
- Protect code blocks from splitting
|
|
302
|
+
4. Return overlapping chunks
|
|
303
|
+
|
|
304
|
+
**Boundary Detection:**
|
|
305
|
+
- **Paragraphs:** Double newlines (`\n\s*\n`)
|
|
306
|
+
- **Sentences:** Handles abbreviations (Dr., Mr., Mrs., Ph.D.), decimal numbers, URLs, email addresses, quotation marks, ellipsis
|
|
307
|
+
|
|
308
|
+
**Characteristics:**
|
|
309
|
+
- Medium speed (~150-300ms per 10KB)
|
|
310
|
+
- Configurable overlap for context preservation
|
|
311
|
+
- Respects paragraph and sentence boundaries
|
|
312
|
+
- Protects code blocks from splitting
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
### SemanticChunkingStrategy
|
|
317
|
+
|
|
318
|
+
Structure-aware chunking that preserves document semantics.
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
class SemanticChunkingStrategy implements ChunkingStrategy {
|
|
322
|
+
constructor(options: SemanticChunkingOptions);
|
|
323
|
+
chunk(text: string): Promise<TextChunk[]>;
|
|
324
|
+
dispose(): void;
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
**Constructor Validation:**
|
|
329
|
+
- Throws `Error` if `minTokens >= maxTokens`
|
|
330
|
+
|
|
331
|
+
**Algorithm:**
|
|
332
|
+
1. **Parse** document into semantic units (priority order):
|
|
333
|
+
- Code blocks (fenced with triple backticks)
|
|
334
|
+
- Numbered lists
|
|
335
|
+
- Bullet lists (-, *, +, bullet)
|
|
336
|
+
- Headers (ATX `#` and Setext `===`/`---`)
|
|
337
|
+
- Paragraphs
|
|
338
|
+
2. **Group** units into chunks respecting `maxTokens`
|
|
339
|
+
- If a single unit exceeds `maxTokens`, split it by sentences
|
|
340
|
+
3. **Merge** small chunks (if `mergeSmallChunks` enabled)
|
|
341
|
+
- Chunks under `minTokens` are combined with adjacent chunks
|
|
342
|
+
|
|
343
|
+
**Recognized Structures:**
|
|
344
|
+
|
|
345
|
+
| Structure | Pattern | Priority |
|
|
346
|
+
|-----------|---------|----------|
|
|
347
|
+
| Code blocks | `` ```...``` `` | Highest (never split) |
|
|
348
|
+
| Numbered lists | `1. item\n2. item` | High |
|
|
349
|
+
| Bullet lists | `- item\n- item` | High |
|
|
350
|
+
| Headers | `# Title` or `Title\n===` | Medium |
|
|
351
|
+
| Paragraphs | Text separated by blank lines | Normal |
|
|
352
|
+
|
|
353
|
+
**Characteristics:**
|
|
354
|
+
- Highest quality output
|
|
355
|
+
- Slower (~200-400ms per 10KB)
|
|
356
|
+
- Preserves document hierarchy and meaning
|
|
357
|
+
- Automatic small chunk merging
|
|
358
|
+
- Best for RAG retrieval accuracy
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## Type Definitions
|
|
363
|
+
|
|
364
|
+
### TextChunk
|
|
365
|
+
|
|
366
|
+
The output type for all chunking operations.
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
interface TextChunk {
|
|
370
|
+
/** The text content of the chunk */
|
|
371
|
+
content: string;
|
|
372
|
+
/** The starting character index in the original document */
|
|
373
|
+
startIndex: number;
|
|
374
|
+
/** The ending character index in the original document */
|
|
375
|
+
endIndex: number;
|
|
376
|
+
/** The token count of the chunk */
|
|
377
|
+
tokenCount: number;
|
|
378
|
+
/** The chunk number (0-indexed) */
|
|
379
|
+
chunkIndex: number;
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
| Property | Type | Description |
|
|
384
|
+
|----------|------|-------------|
|
|
385
|
+
| `content` | `string` | The actual text content |
|
|
386
|
+
| `startIndex` | `number` | Character position where this chunk starts in the original document |
|
|
387
|
+
| `endIndex` | `number` | Character position where this chunk ends in the original document |
|
|
388
|
+
| `tokenCount` | `number` | Number of tokens in this chunk (using configured encoding) |
|
|
389
|
+
| `chunkIndex` | `number` | Sequential chunk number, starting from 0 |
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
### FixedLengthChunkingOptions
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
interface FixedLengthChunkingOptions {
|
|
397
|
+
/** The maximum number of tokens per chunk */
|
|
398
|
+
maxTokens: number;
|
|
399
|
+
/** The encoding to use for token counting (default: 'cl100k_base') */
|
|
400
|
+
encoding?: string;
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
| Property | Type | Required | Default | Description |
|
|
405
|
+
|----------|------|----------|---------|-------------|
|
|
406
|
+
| `maxTokens` | `number` | Yes | - | Maximum tokens per chunk |
|
|
407
|
+
| `encoding` | `string` | No | `'cl100k_base'` | Token encoding name |
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
### SlidingWindowChunkingOptions
|
|
412
|
+
|
|
413
|
+
```typescript
|
|
414
|
+
interface SlidingWindowChunkingOptions {
|
|
415
|
+
/** The maximum number of tokens per chunk */
|
|
416
|
+
maxTokens: number;
|
|
417
|
+
/** The number of overlapping tokens between chunks */
|
|
418
|
+
overlapTokens: number;
|
|
419
|
+
/** The encoding to use for token counting (default: 'cl100k_base') */
|
|
420
|
+
encoding?: string;
|
|
421
|
+
/** Minimum chunk size as a ratio of maxTokens (default: 0.5) */
|
|
422
|
+
minChunkRatio?: number;
|
|
423
|
+
/** Prefer paragraph boundaries over sentence boundaries (default: true) */
|
|
424
|
+
preferParagraphBoundaries?: boolean;
|
|
425
|
+
}
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
| Property | Type | Required | Default | Description |
|
|
429
|
+
|----------|------|----------|---------|-------------|
|
|
430
|
+
| `maxTokens` | `number` | Yes | - | Maximum tokens per chunk |
|
|
431
|
+
| `overlapTokens` | `number` | Yes | - | Tokens overlapping between adjacent chunks |
|
|
432
|
+
| `encoding` | `string` | No | `'cl100k_base'` | Token encoding name |
|
|
433
|
+
| `minChunkRatio` | `number` | No | `0.5` | Minimum chunk size ratio (0.1 - 0.9) |
|
|
434
|
+
| `preferParagraphBoundaries` | `boolean` | No | `true` | Try paragraph boundaries before sentence |
|
|
435
|
+
|
|
436
|
+
**Constraints:**
|
|
437
|
+
- `overlapTokens` must be less than `maxTokens`
|
|
438
|
+
- `minChunkRatio` must be between 0.1 and 0.9
|
|
439
|
+
|
|
440
|
+
---
|
|
441
|
+
|
|
442
|
+
### SemanticChunkingOptions
|
|
443
|
+
|
|
444
|
+
```typescript
|
|
445
|
+
interface SemanticChunkingOptions {
|
|
446
|
+
/** The maximum number of tokens per chunk */
|
|
447
|
+
maxTokens: number;
|
|
448
|
+
/** The minimum number of tokens per chunk (default: 100) */
|
|
449
|
+
minTokens?: number;
|
|
450
|
+
/** The encoding to use for token counting (default: 'cl100k_base') */
|
|
451
|
+
encoding?: string;
|
|
452
|
+
/** Whether to merge small chunks with adjacent chunks (default: true) */
|
|
453
|
+
mergeSmallChunks?: boolean;
|
|
454
|
+
}
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
| Property | Type | Required | Default | Description |
|
|
458
|
+
|----------|------|----------|---------|-------------|
|
|
459
|
+
| `maxTokens` | `number` | Yes | - | Maximum tokens per chunk |
|
|
460
|
+
| `minTokens` | `number` | No | `100` | Minimum tokens per chunk |
|
|
461
|
+
| `encoding` | `string` | No | `'cl100k_base'` | Token encoding name |
|
|
462
|
+
| `mergeSmallChunks` | `boolean` | No | `true` | Auto-merge chunks below minTokens |
|
|
463
|
+
|
|
464
|
+
**Constraints:**
|
|
465
|
+
- `minTokens` must be less than `maxTokens`
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
### ChunkingOptions
|
|
470
|
+
|
|
471
|
+
Union type for all option interfaces. Used with `ChunkingService.create()` for auto-detection.
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
type ChunkingOptions =
|
|
475
|
+
| FixedLengthChunkingOptions
|
|
476
|
+
| SlidingWindowChunkingOptions
|
|
477
|
+
| SemanticChunkingOptions;
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
---
|
|
481
|
+
|
|
482
|
+
## Exports
|
|
483
|
+
|
|
484
|
+
All public types and classes are exported from the library's main `index.ts`:
|
|
485
|
+
|
|
486
|
+
```typescript
|
|
487
|
+
// Classes
|
|
488
|
+
export { ChunkingService } from "./ChunkingService.js";
|
|
489
|
+
export { FixedLengthChunkingStrategy } from "./strategies/FixedLengthChunkingStrategy.js";
|
|
490
|
+
export { SlidingWindowChunkingStrategy } from "./strategies/SlidingWindowChunkingStrategy.js";
|
|
491
|
+
export { SemanticChunkingStrategy } from "./strategies/SemanticChunkingStrategy.js";
|
|
492
|
+
|
|
493
|
+
// Interfaces
|
|
494
|
+
export type { ChunkingStrategy } from "./strategies/ChunkingStrategy.js";
|
|
495
|
+
|
|
496
|
+
// Types
|
|
497
|
+
export type {
|
|
498
|
+
TextChunk,
|
|
499
|
+
ChunkingOptions,
|
|
500
|
+
FixedLengthChunkingOptions,
|
|
501
|
+
SlidingWindowChunkingOptions,
|
|
502
|
+
SemanticChunkingOptions,
|
|
503
|
+
} from "./types/index.js";
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
---
|
|
507
|
+
|
|
508
|
+
## Error Handling
|
|
509
|
+
|
|
510
|
+
### Construction Errors
|
|
511
|
+
|
|
512
|
+
| Error | Cause | Strategy |
|
|
513
|
+
|-------|-------|----------|
|
|
514
|
+
| `overlapTokens must be less than maxTokens` | `overlapTokens >= maxTokens` | Sliding Window |
|
|
515
|
+
| `minChunkRatio must be between 0.1 and 0.9` | Out of range ratio | Sliding Window |
|
|
516
|
+
| `minTokens must be less than maxTokens` | `minTokens >= maxTokens` | Semantic |
|
|
517
|
+
|
|
518
|
+
### Runtime Behavior
|
|
519
|
+
|
|
520
|
+
| Scenario | Behavior |
|
|
521
|
+
|----------|----------|
|
|
522
|
+
| Empty or whitespace-only text | Returns `[]` (empty array) |
|
|
523
|
+
| Invalid encoding name | Falls back to `gpt-3.5-turbo` encoding |
|
|
524
|
+
| Text shorter than `maxTokens` | Returns single chunk |
|
|
525
|
+
| Single semantic unit exceeds `maxTokens` | Split by sentences (Semantic) |
|
|
526
|
+
|
|
527
|
+
### Resource Cleanup
|
|
528
|
+
|
|
529
|
+
```typescript
|
|
530
|
+
// Always dispose to free native resources
|
|
531
|
+
const service = ChunkingService.createWithSemantic({ maxTokens: 512 });
|
|
532
|
+
try {
|
|
533
|
+
const chunks = await service.chunk(text);
|
|
534
|
+
return chunks;
|
|
535
|
+
} finally {
|
|
536
|
+
service.dispose();
|
|
537
|
+
}
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
> **Warning:** Failing to call `dispose()` will leak the tiktoken encoder's native memory. In long-running applications, always use try/finally or equivalent cleanup patterns.
|
|
541
|
+
|
|
542
|
+
---
|
|
543
|
+
|
|
544
|
+
## Related Documentation
|
|
545
|
+
|
|
546
|
+
- [Quick Start Guide](quick-start.md)
|
|
547
|
+
- [Strategies Guide](strategies.md)
|
|
548
|
+
- [Configuration Guide](configuration.md)
|
|
549
|
+
- [Troubleshooting](troubleshooting.md)
|