V0.38.2 library packages (#235)

Co-authored-by: gobha <jasafpro@gmail.com>
Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
2026-03-25 14:09:05 +00:00
committed by xcaliber
parent 6943c91f40
commit 2136535176
22 changed files with 1233 additions and 6 deletions

View File

@@ -1,5 +1,95 @@
# Changelog
## [0.38.2.0] — 2026-03-25
### Summary
Library Packages. Reusable Starlark libraries that extensions can declare
as dependencies and load at runtime via `lib.require()`. Libraries export
functions, run with their own permission context, and are protected from
uninstall while active consumers exist. Includes a `test-tool` admin
endpoint for invoking extension tool calls without the AI chat loop.
### Added
- **Schema:** `ext_dependencies` table with `(consumer_id, library_id)`
composite PK, `version_spec` and `resolved_ver` columns. SQLite
migration also rebuilds `packages` table to add `'library'` to the
type CHECK constraint (SQLite cannot ALTER constraints).
(`server/database/migrations/023_ext_dependencies.sql`,
`server/database/migrations/sqlite/023_ext_dependencies.sql`)
- **Model:** `ExtDependency` struct with `ConsumerID`, `LibraryID`,
`VersionSpec`, `ResolvedVer`.
(`server/models/ext_dependency.go`)
- **Store:** `DependencyStore` interface — `Create`, `DeleteByConsumer`,
`ListByConsumer`, `ListByLibrary`, `ListAll`. Postgres and SQLite
implementations.
(`server/store/interfaces.go`, `postgres/ext_dependency.go`,
`sqlite/ext_dependency.go`)
- **Handlers:** Dependency admin endpoints:
- `GET /admin/packages/:id/dependencies` — list consumer's deps
- `GET /admin/packages/:id/consumers` — list library's consumers
- `GET /admin/dependencies` — full dependency graph
(`server/handlers/dependencies.go`)
- **Test-tool endpoint:** `POST /admin/packages/:id/test-tool` — invokes
a starlark extension's `on_tool_call` entry point directly for testing.
(`server/handlers/packages.go`)
- **Starlark module:** `lib.require(id)` — loads a declared library
dependency, executes its script with library-scoped permissions,
extracts manifest exports, freezes into a cached struct. Per-invocation
cache and cycle detection.
(`server/sandbox/lib_module.go`)
- **Install validation:** Library packages require `exports` array,
must not have `tools`, `pipes`, or `route`. Consumer `dependencies`
map validated against installed active libraries. Dependency records
created on install, cleaned up on consumer uninstall. Libraries with
active consumers return 409 on delete.
(`server/handlers/packages.go`)
- **SDK:** `sw.api.admin.packages.dependencies(id)`,
`sw.api.admin.packages.consumers(id)` domain methods.
(`src/js/sw/sdk/api-domains.js`)
- **ICD:** Extension dependencies section with all endpoint specs.
(`docs/ICD/extensions.md`)
- **OpenAPI:** Dependency endpoint schemas and `test-tool` endpoint.
(`server/static/openapi.yaml`)
- **SDK test runner:** `dependencies` domain — 8 tests covering library
install, dependency creation, consumer listing, uninstall protection,
cleanup, and library deletion.
(`packages/sdk-test-runner/js/domains/dependencies.js`)
### Changed
- **Runner:** `ExecPackage` creates a `libContext` per invocation and
passes it through `buildModulesWithLibCtx`. The `lib` module is always
injected (no permission required). Multi-file `packageLoader` reused
for library scripts.
(`server/sandbox/runner.go`)
- **Packages handler:** Install flow extended with dependency resolution
and `ext_dependencies` record creation. Delete flow checks for active
consumers before allowing library removal.
(`server/handlers/packages.go`)
### Design Notes
- `lib.require()` was originally `lib.load()` but `load` is a reserved
keyword in Starlark (used for `load("module.star", "symbol")`). Renamed
to `require` to avoid parser conflicts.
- Libraries run with their **own** permission context, not the consumer's.
A consumer without `api.http` can still call a library that uses
`http.get()` — the library's permissions are evaluated independently.
- The `test-tool` endpoint enables E2E testing of Starlark extensions
without a configured LLM provider.
### Files
- **8 created:** `lib_module.go`, `dependencies.go`, `ext_dependency.go`
(model), `ext_dependency.go` (pg), `ext_dependency.go` (sqlite),
`023_ext_dependencies.sql` (×2), `dependencies.js` (SDK runner)
- **11 modified:** `packages.go`, `runner.go`, `main.go`, `interfaces.go`,
`stores.go` (×2), `api-domains.js`, `openapi.yaml`, `extensions.md`,
`packages.js`, `main.js` (SDK runner)
- **+1,141 lines** (737 new files + 404 modified)
## [0.38.1.0] — 2026-03-25
### Summary