@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,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the LLM helper library — the lingua franca every
|
|
3
|
+
* `LLMProvider` adapter (Anthropic, OpenAI, future Bedrock / Vertex /
|
|
4
|
+
* local-Ollama) translates to and from. Adapters own provider-specific
|
|
5
|
+
* SDK shapes; the framework never sees them.
|
|
6
|
+
*
|
|
7
|
+
* Designed for the v4 plan §G surface: `complete`, `streamComplete`,
|
|
8
|
+
* structured outputs (Zod schema → typed `T`), tool calling, agent
|
|
9
|
+
* loop, embeddings, token counting, streaming through Hono `streamSSE`.
|
|
10
|
+
*
|
|
11
|
+
* Type-only — no runtime imports.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* One conversational turn. The role identifies the speaker; content is
|
|
16
|
+
* either a single text string (the common case) or an ordered array of
|
|
17
|
+
* `MessageContentPart`s (mixed text + tool-use + tool-result + image
|
|
18
|
+
* parts, used for tool-calling and multi-modal flows).
|
|
19
|
+
*
|
|
20
|
+
* `system` messages are *not* in the array — providers handle them as a
|
|
21
|
+
* top-level option (`opts.system`) per their respective API conventions.
|
|
22
|
+
* Mixing them in here would force every adapter to scan the array and
|
|
23
|
+
* extract them, which is ceremony.
|
|
24
|
+
*/
|
|
25
|
+
export interface Message {
|
|
26
|
+
role: "user" | "assistant" | "tool";
|
|
27
|
+
content: string | MessageContentPart[];
|
|
28
|
+
/** Optional name for tool-result messages (echoes the tool name). */
|
|
29
|
+
name?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type MessageContentPart = TextPart | ToolUsePart | ToolResultPart | ImagePart;
|
|
33
|
+
|
|
34
|
+
export interface TextPart {
|
|
35
|
+
type: "text";
|
|
36
|
+
text: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ToolUsePart {
|
|
40
|
+
type: "tool_use";
|
|
41
|
+
/** Adapter-issued tool-call ID; passed back in the matching `ToolResultPart`. */
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
/** Parsed JSON object. Adapters parse the provider's raw string for us. */
|
|
45
|
+
input: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ToolResultPart {
|
|
49
|
+
type: "tool_result";
|
|
50
|
+
/** ID of the originating `ToolUsePart`. */
|
|
51
|
+
toolUseId: string;
|
|
52
|
+
/** Stringified result; adapters serialize objects via JSON.stringify. */
|
|
53
|
+
content: string;
|
|
54
|
+
/** True if the tool handler threw — providers handle errors differently. */
|
|
55
|
+
isError?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ImagePart {
|
|
59
|
+
type: "image";
|
|
60
|
+
/** Base64-encoded bytes (no data: prefix). */
|
|
61
|
+
data: string;
|
|
62
|
+
mediaType: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Top-level options to a single non-streaming completion request.
|
|
67
|
+
* Provider-specific tunables (e.g., Anthropic `top_k`, OpenAI
|
|
68
|
+
* `frequency_penalty`) ride along in `providerOptions` so they don't
|
|
69
|
+
* pollute the cross-provider surface.
|
|
70
|
+
*/
|
|
71
|
+
export interface CompleteOptions {
|
|
72
|
+
model: string;
|
|
73
|
+
messages: Message[];
|
|
74
|
+
/** Top-level system prompt. Providers pass it as their dedicated field. */
|
|
75
|
+
system?: string;
|
|
76
|
+
/** Caller-defined ceiling. Adapters apply provider-specific defaults if omitted. */
|
|
77
|
+
maxTokens?: number;
|
|
78
|
+
/** 0–1; adapters clamp / translate to provider scales. */
|
|
79
|
+
temperature?: number;
|
|
80
|
+
/** Tool definitions the model may invoke. */
|
|
81
|
+
tools?: ToolDefinition[];
|
|
82
|
+
/**
|
|
83
|
+
* Force a specific tool, allow any tool, or disable tool use entirely.
|
|
84
|
+
* Mirrors Anthropic / OpenAI "tool_choice" semantics.
|
|
85
|
+
*/
|
|
86
|
+
toolChoice?: ToolChoice;
|
|
87
|
+
/** Stop sequences. */
|
|
88
|
+
stopSequences?: string[];
|
|
89
|
+
/** AbortSignal — adapters wire to the SDK's abort path. */
|
|
90
|
+
signal?: AbortSignal;
|
|
91
|
+
/**
|
|
92
|
+
* Pass-through for provider-specific options the unified surface
|
|
93
|
+
* doesn't yet model. Adapters merge into the provider request.
|
|
94
|
+
*/
|
|
95
|
+
providerOptions?: Record<string, unknown>;
|
|
96
|
+
/** Request-tagging for observability / cost-tracking integrations. */
|
|
97
|
+
metadata?: Record<string, string>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type ToolChoice =
|
|
101
|
+
| { type: "auto" }
|
|
102
|
+
| { type: "any" }
|
|
103
|
+
| { type: "none" }
|
|
104
|
+
| { type: "tool"; name: string };
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Structural tool definition. The library's `defineTool({...})` factory
|
|
108
|
+
* (later commit) produces these from a Zod schema + handler; adapters
|
|
109
|
+
* forward the JSON Schema as-is.
|
|
110
|
+
*/
|
|
111
|
+
export interface ToolDefinition {
|
|
112
|
+
name: string;
|
|
113
|
+
description: string;
|
|
114
|
+
/** JSON Schema (Draft 7+) describing the tool's input. */
|
|
115
|
+
inputSchema: Record<string, unknown>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Result of a non-streaming completion. The `content` array preserves
|
|
120
|
+
* every part the model emitted (text + tool-use + …) in order; callers
|
|
121
|
+
* filter for what they need. `text` is a convenience join of all text
|
|
122
|
+
* parts.
|
|
123
|
+
*/
|
|
124
|
+
export interface CompleteResult {
|
|
125
|
+
/** Provider's stable identifier for this response (e.g. for retries). */
|
|
126
|
+
id: string;
|
|
127
|
+
model: string;
|
|
128
|
+
content: MessageContentPart[];
|
|
129
|
+
/** Convenience: concatenated text parts. */
|
|
130
|
+
text: string;
|
|
131
|
+
/** Why the model stopped — normalized across providers. */
|
|
132
|
+
stopReason: StopReason;
|
|
133
|
+
/** Stop sequence that triggered, when stopReason === "stop_sequence". */
|
|
134
|
+
stopSequence?: string;
|
|
135
|
+
usage: TokenUsage;
|
|
136
|
+
/** Pass-through for provider-specific extras (e.g. caching metadata). */
|
|
137
|
+
providerExtras?: Record<string, unknown>;
|
|
138
|
+
/**
|
|
139
|
+
* The untranslated provider SDK response — escape hatch for native
|
|
140
|
+
* fields the unified surface drops (thinking blocks, citations,
|
|
141
|
+
* server-tool use, …). Shape is provider-specific; cast at the use site.
|
|
142
|
+
*/
|
|
143
|
+
raw?: unknown;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type StopReason =
|
|
147
|
+
| "end_turn"
|
|
148
|
+
| "max_tokens"
|
|
149
|
+
| "stop_sequence"
|
|
150
|
+
| "tool_use"
|
|
151
|
+
| "content_filter"
|
|
152
|
+
| "unknown";
|
|
153
|
+
|
|
154
|
+
export interface TokenUsage {
|
|
155
|
+
inputTokens: number;
|
|
156
|
+
outputTokens: number;
|
|
157
|
+
/** Provider-supported cache reads (Anthropic prompt caching). */
|
|
158
|
+
cacheReadInputTokens?: number;
|
|
159
|
+
cacheCreationInputTokens?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Reasoning/thinking tokens billed as output (OpenAI o-series
|
|
162
|
+
* `completion_tokens_details.reasoning_tokens`; Anthropic extended
|
|
163
|
+
* thinking). Present only when the provider reports it.
|
|
164
|
+
*/
|
|
165
|
+
reasoningTokens?: number;
|
|
166
|
+
/** The untranslated provider usage object — escape hatch for fields not modeled here. */
|
|
167
|
+
raw?: unknown;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Streaming events. Adapters translate each provider's stream protocol
|
|
172
|
+
* (Anthropic SSE event-types, OpenAI delta chunks) into this set.
|
|
173
|
+
*
|
|
174
|
+
* Event order on a successful turn:
|
|
175
|
+
* 1. one `start` (model id + initial usage if available)
|
|
176
|
+
* 2. zero-or-more `text_delta` (incremental content tokens)
|
|
177
|
+
* 3. zero-or-more `tool_use_start` + `tool_input_delta` + `tool_use_end`
|
|
178
|
+
* groups (one per tool call the model emits)
|
|
179
|
+
* 4. one `stop` (stopReason + final usage)
|
|
180
|
+
*
|
|
181
|
+
* Errors throw out of the iterator — no `error` event variant; callers
|
|
182
|
+
* use try/catch or `for await` rejection.
|
|
183
|
+
*/
|
|
184
|
+
export type StreamEvent =
|
|
185
|
+
| StreamStartEvent
|
|
186
|
+
| StreamTextDeltaEvent
|
|
187
|
+
| StreamToolUseStartEvent
|
|
188
|
+
| StreamToolInputDeltaEvent
|
|
189
|
+
| StreamToolUseEndEvent
|
|
190
|
+
| StreamStopEvent;
|
|
191
|
+
|
|
192
|
+
export interface StreamStartEvent {
|
|
193
|
+
type: "start";
|
|
194
|
+
id: string;
|
|
195
|
+
model: string;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface StreamTextDeltaEvent {
|
|
199
|
+
type: "text_delta";
|
|
200
|
+
/** The new token(s) to append. */
|
|
201
|
+
delta: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface StreamToolUseStartEvent {
|
|
205
|
+
type: "tool_use_start";
|
|
206
|
+
/** Adapter-issued ID for matching `tool_input_delta` / `tool_use_end`. */
|
|
207
|
+
id: string;
|
|
208
|
+
name: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface StreamToolInputDeltaEvent {
|
|
212
|
+
type: "tool_input_delta";
|
|
213
|
+
id: string;
|
|
214
|
+
/** Partial JSON string; concatenate to reconstruct the full input. */
|
|
215
|
+
partialJson: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export interface StreamToolUseEndEvent {
|
|
219
|
+
type: "tool_use_end";
|
|
220
|
+
id: string;
|
|
221
|
+
/** Parsed input — adapter does the JSON.parse once the tool_use closes. */
|
|
222
|
+
input: Record<string, unknown>;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface StreamStopEvent {
|
|
226
|
+
type: "stop";
|
|
227
|
+
stopReason: StopReason;
|
|
228
|
+
stopSequence?: string;
|
|
229
|
+
usage: TokenUsage;
|
|
230
|
+
/** Pass-through for provider-specific extras on the final event (parity with `CompleteResult`). */
|
|
231
|
+
providerExtras?: Record<string, unknown>;
|
|
232
|
+
/** The untranslated final provider event/message — streaming escape hatch (parity with `CompleteResult.raw`). */
|
|
233
|
+
raw?: unknown;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Streaming-request options. Same shape as `CompleteOptions` minus the
|
|
238
|
+
* `signal` (kept) — kept identical to make swapping `complete` /
|
|
239
|
+
* `streamComplete` mechanical.
|
|
240
|
+
*/
|
|
241
|
+
export type StreamCompleteOptions = CompleteOptions;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Embeddings — vector representation of input text(s). One adapter call
|
|
245
|
+
* may embed multiple inputs in a single batch.
|
|
246
|
+
*/
|
|
247
|
+
export interface EmbedOptions {
|
|
248
|
+
model: string;
|
|
249
|
+
/** One or more strings to embed. Adapters may chunk into provider-permitted batch sizes. */
|
|
250
|
+
inputs: string[];
|
|
251
|
+
signal?: AbortSignal;
|
|
252
|
+
providerOptions?: Record<string, unknown>;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface EmbedResult {
|
|
256
|
+
model: string;
|
|
257
|
+
/** One vector per input, in the same order. */
|
|
258
|
+
embeddings: number[][];
|
|
259
|
+
usage: { inputTokens: number };
|
|
260
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { ChunkingStrategy } from "./strategies/ChunkingStrategy.js";
|
|
2
|
+
import { FixedLengthChunkingStrategy } from "./strategies/FixedLengthChunkingStrategy.js";
|
|
3
|
+
import { SemanticChunkingStrategy } from "./strategies/SemanticChunkingStrategy.js";
|
|
4
|
+
import { SlidingWindowChunkingStrategy } from "./strategies/SlidingWindowChunkingStrategy.js";
|
|
5
|
+
import type {
|
|
6
|
+
ChunkingOptions,
|
|
7
|
+
FixedLengthChunkingOptions,
|
|
8
|
+
SemanticChunkingOptions,
|
|
9
|
+
SlidingWindowChunkingOptions,
|
|
10
|
+
TextChunk,
|
|
11
|
+
} from "./types/index.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Service for chunking documents for embedding using various strategies
|
|
15
|
+
*/
|
|
16
|
+
export class ChunkingService {
|
|
17
|
+
private strategy: ChunkingStrategy;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new ChunkingService with the specified strategy
|
|
21
|
+
* @param strategy - The chunking strategy to use
|
|
22
|
+
*/
|
|
23
|
+
constructor(strategy: ChunkingStrategy) {
|
|
24
|
+
this.strategy = strategy;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Chunks the given text using the configured strategy
|
|
29
|
+
* @param text - The text to chunk
|
|
30
|
+
* @returns An array of text chunks
|
|
31
|
+
*/
|
|
32
|
+
async chunk(text: string): Promise<TextChunk[]> {
|
|
33
|
+
if (!text || text.trim().length === 0) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return await this.strategy.chunk(text);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Sets a new chunking strategy
|
|
42
|
+
* @param strategy - The new strategy to use
|
|
43
|
+
*/
|
|
44
|
+
setStrategy(strategy: ChunkingStrategy): void {
|
|
45
|
+
this.strategy = strategy;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Factory method to create a ChunkingService with fixed length strategy
|
|
50
|
+
* @param options - Configuration options for fixed length chunking
|
|
51
|
+
* @returns A new ChunkingService instance
|
|
52
|
+
*/
|
|
53
|
+
static createWithFixedLength(options: FixedLengthChunkingOptions): ChunkingService {
|
|
54
|
+
const strategy = new FixedLengthChunkingStrategy(options);
|
|
55
|
+
return new ChunkingService(strategy);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Factory method to create a ChunkingService with sliding window strategy
|
|
60
|
+
* @param options - Configuration options for sliding window chunking
|
|
61
|
+
* @returns A new ChunkingService instance
|
|
62
|
+
*/
|
|
63
|
+
static createWithSlidingWindow(options: SlidingWindowChunkingOptions): ChunkingService {
|
|
64
|
+
const strategy = new SlidingWindowChunkingStrategy(options);
|
|
65
|
+
return new ChunkingService(strategy);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Factory method to create a ChunkingService with semantic strategy
|
|
70
|
+
* Industry Best Practice: Use for RAG and embedding applications requiring semantic coherence
|
|
71
|
+
*
|
|
72
|
+
* @param options - Configuration options for semantic chunking
|
|
73
|
+
* @returns A new ChunkingService instance
|
|
74
|
+
*/
|
|
75
|
+
static createWithSemantic(options: SemanticChunkingOptions): ChunkingService {
|
|
76
|
+
const strategy = new SemanticChunkingStrategy(options);
|
|
77
|
+
return new ChunkingService(strategy);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Factory method to create a ChunkingService with the appropriate strategy based on options
|
|
82
|
+
* @param options - Configuration options for chunking
|
|
83
|
+
* @returns A new ChunkingService instance
|
|
84
|
+
*/
|
|
85
|
+
static create(options: ChunkingOptions): ChunkingService {
|
|
86
|
+
if ("overlapTokens" in options) {
|
|
87
|
+
return ChunkingService.createWithSlidingWindow(options);
|
|
88
|
+
} else if ("minTokens" in options || "mergeSmallChunks" in options) {
|
|
89
|
+
return ChunkingService.createWithSemantic(options as SemanticChunkingOptions);
|
|
90
|
+
} else {
|
|
91
|
+
return ChunkingService.createWithFixedLength(options);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Cleanup method to dispose of the strategy if needed
|
|
97
|
+
*/
|
|
98
|
+
dispose(): void {
|
|
99
|
+
if ("dispose" in this.strategy && typeof this.strategy.dispose === "function") {
|
|
100
|
+
(this.strategy as any).dispose();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# `libraries/chunking/` — Document chunking for RAG
|
|
2
|
+
|
|
3
|
+
Document chunking primitives for preparing text for embedding and Retrieval-Augmented Generation (RAG). Strategy-pattern API with three interchangeable algorithms.
|
|
4
|
+
|
|
5
|
+
> **Install via**: `ship-api add -l chunking`. Pulls in `tiktoken` for OpenAI-compatible token counts.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Three Chunking Strategies**:
|
|
10
|
+
- **Fixed Length** — Simple, fast chunking for prototyping
|
|
11
|
+
- **Sliding Window** — Overlapping chunks with intelligent boundary detection
|
|
12
|
+
- **Semantic** — Structure-aware chunking (recommended for production)
|
|
13
|
+
- **Accurate Token Counting** — Uses tiktoken for OpenAI-compatible token counts
|
|
14
|
+
- **Strategy Pattern** — Swap strategies at runtime without changing client code
|
|
15
|
+
- **Structure-Aware** — Preserves code blocks, lists, headers, and paragraphs
|
|
16
|
+
- **TypeScript** — Full type safety with exported interfaces
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { ChunkingService } from "@sixthsummit/ship-api/libraries/chunking";
|
|
22
|
+
|
|
23
|
+
// Semantic chunking (recommended for production RAG)
|
|
24
|
+
const service = ChunkingService.createWithSemantic({
|
|
25
|
+
maxTokens: 512,
|
|
26
|
+
minTokens: 100,
|
|
27
|
+
mergeSmallChunks: true,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const chunks = await service.chunk(document);
|
|
31
|
+
|
|
32
|
+
for (const chunk of chunks) {
|
|
33
|
+
console.log(`Chunk ${chunk.chunkIndex}: ${chunk.tokenCount} tokens`);
|
|
34
|
+
// Send to your embedding service...
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
service.dispose(); // Always clean up
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Strategies at a Glance
|
|
41
|
+
|
|
42
|
+
| Strategy | Speed | Quality | Overlap | Best For |
|
|
43
|
+
| ------------------ | ------- | ------- | ------- | ------------------------------- |
|
|
44
|
+
| **Fixed Length** | Fastest | Basic | No | Prototyping, uniform text |
|
|
45
|
+
| **Sliding Window** | Medium | Good | Yes | Narrative content, articles |
|
|
46
|
+
| **Semantic** | Slower | Best | No | Production RAG, structured docs |
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
// Sliding Window — overlapping chunks with boundary detection
|
|
50
|
+
const service = ChunkingService.createWithSlidingWindow({
|
|
51
|
+
maxTokens: 512,
|
|
52
|
+
overlapTokens: 80,
|
|
53
|
+
preferParagraphBoundaries: true,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Fixed Length — simple token-based splitting
|
|
57
|
+
const service = ChunkingService.createWithFixedLength({
|
|
58
|
+
maxTokens: 512,
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Output Format
|
|
63
|
+
|
|
64
|
+
Every strategy returns an array of `TextChunk` objects:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
interface TextChunk {
|
|
68
|
+
content: string; // The text content
|
|
69
|
+
startIndex: number; // Character position in original document
|
|
70
|
+
endIndex: number; // End character position
|
|
71
|
+
tokenCount: number; // Token count (via tiktoken)
|
|
72
|
+
chunkIndex: number; // Sequential chunk number (0-indexed)
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
Comprehensive documentation is available in the [`docs/`](docs/) folder:
|
|
79
|
+
|
|
80
|
+
| Document | Description |
|
|
81
|
+
| -------------------------------------------------- | ----------------------------------------------------------- |
|
|
82
|
+
| **[Quick Start](docs/quick-start.md)** | Get started in 5 minutes |
|
|
83
|
+
| **[Strategies Guide](docs/strategies.md)** | Deep dive into each strategy with algorithms and comparison |
|
|
84
|
+
| **[API Reference](docs/api-reference.md)** | Complete class, method, and type documentation |
|
|
85
|
+
| **[Configuration](docs/configuration.md)** | All options, tuning, and embedding model alignment |
|
|
86
|
+
| **[Best Practices](docs/best-practices.md)** | Production guidance, advanced techniques, and pitfalls |
|
|
87
|
+
| **[Code Organization](docs/code-organization.md)** | Architecture, conventions, and creating custom strategies |
|
|
88
|
+
| **[Troubleshooting](docs/troubleshooting.md)** | Common issues and solutions |
|
|
89
|
+
| **[Documentation Index](docs/index.md)** | Full navigation hub |
|
|
90
|
+
|
|
91
|
+
## Installation
|
|
92
|
+
|
|
93
|
+
Add the library to your ShipAPI project:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx ship-api add chunking --lib
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This installs the library files and the `tiktoken` dependency.
|
|
100
|
+
|
|
101
|
+
## Requirements
|
|
102
|
+
|
|
103
|
+
- Node.js >= 22
|
|
104
|
+
- tiktoken (installed automatically via CLI)
|