@terreno/ai 57.21.0 → 58.0.0-beta.2
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/AGENTS.md +20 -18
- package/CHANGELOG.md +89 -0
- package/biome.jsonc +2 -2
- package/dist/aiApp.d.ts +5 -2
- package/dist/aiApp.js +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/models/gptHistory.js +2 -0
- package/dist/routes/files.d.ts +7 -1
- package/dist/routes/files.js +62 -13
- package/dist/routes/gptHistories.js +8 -2
- package/dist/service/chatTurn.js +5 -0
- package/dist/service/vertex.d.ts +5 -2
- package/dist/types/index.d.ts +4 -0
- package/package.json +13 -12
- package/src/aiApp.test.ts +21 -1
- package/src/aiApp.ts +6 -3
- package/src/index.ts +1 -1
- package/src/isolated/gptStream.isolated.ts +2 -2
- package/src/models/gptHistory.test.ts +2 -2
- package/src/models/gptHistory.ts +9 -1
- package/src/routes/files.test.ts +121 -0
- package/src/routes/files.ts +90 -15
- package/src/routes/gpt.test.ts +14 -2
- package/src/routes/gptActions.test.ts +3 -3
- package/src/routes/gptApprovals.test.ts +1 -1
- package/src/routes/gptFiles.test.ts +1 -1
- package/src/routes/gptHistories.test.ts +2 -2
- package/src/routes/gptHistories.ts +59 -55
- package/src/routes/gptHistoriesSync.test.ts +230 -0
- package/src/routes/routes.test.ts +6 -5
- package/src/service/chatTurn.ts +5 -0
- package/src/service/vertex.test.ts +1 -1
- package/src/service/vertex.ts +7 -4
- package/src/types/index.ts +4 -0
package/AGENTS.md
CHANGED
|
@@ -21,7 +21,7 @@ deploy.
|
|
|
21
21
|
|
|
22
22
|
- **api/** - REST API framework built on Express/Mongoose (`@terreno/api`)
|
|
23
23
|
- **ui/** - React Native UI component library (`@terreno/ui`)
|
|
24
|
-
- **
|
|
24
|
+
- **syncdb/** - Frontend data layer: local-first collections, request client + generated API hooks, auth session, flags (`@terreno/syncdb`)
|
|
25
25
|
- **admin-backend/** - Admin panel backend plugin for @terreno/api (`@terreno/admin-backend`)
|
|
26
26
|
- **admin-frontend/** - Admin panel frontend screens for @terreno/api backends (`@terreno/admin-frontend`)
|
|
27
27
|
- **mcp-server/** - MCP server for AI assistant integration (`@terreno/mcp`, bins `terreno-mcp` / `terreno-mcp-local`)
|
|
@@ -68,13 +68,13 @@ The three core packages form a complete full-stack framework:
|
|
|
68
68
|
|
|
|
69
69
|
/openapi.json
|
|
70
70
|
|
|
|
71
|
-
|
|
71
|
+
terreno-syncdb-codegen
|
|
72
72
|
|
|
|
73
73
|
FRONTEND
|
|
74
|
-
@terreno/
|
|
75
|
-
- Generated hooks
|
|
76
|
-
-
|
|
77
|
-
-
|
|
74
|
+
@terreno/syncdb
|
|
75
|
+
- Generated request hooks + local-first collection hooks
|
|
76
|
+
- SessionProvider / useSession (Better Auth or JWT)
|
|
77
|
+
- Shared auth provider with refresh on 401
|
|
78
78
|
+
|
|
79
79
|
@terreno/ui
|
|
80
80
|
- React Native components (Box, Button, TextField, etc.)
|
|
@@ -85,12 +85,12 @@ The three core packages form a complete full-stack framework:
|
|
|
85
85
|
|
|
86
86
|
1. **Backend (api)**: Define Mongoose models, use `modelRouter` to create CRUD endpoints with permissions
|
|
87
87
|
2. **OpenAPI Generation**: `setupServer` automatically generates `/openapi.json`
|
|
88
|
-
3. **SDK Codegen**: Frontend runs `bun run sdk`
|
|
89
|
-
4. **Frontend (
|
|
88
|
+
3. **SDK Codegen**: Frontend runs `bun run sdk` (`terreno-syncdb-codegen --api-out` → `store/apiSdk.ts`) and `bun run sync-sdk` (→ `store/syncDbSdk.ts`)
|
|
89
|
+
4. **Frontend (syncdb + ui)**: Use `useQuery` / `useMutate` for synced collections and generated hooks for other routes. `@terreno/rtk` and Redux were removed in Terreno 58.
|
|
90
90
|
|
|
91
91
|
## Example Apps (Keep These Updated!)
|
|
92
92
|
|
|
93
|
-
The `example-frontend/` and `example-backend/` directories serve as both documentation and integration tests. When adding features to api, ui, or
|
|
93
|
+
The `example-frontend/` and `example-backend/` directories serve as both documentation and integration tests. When adding features to api, ui, or syncdb:
|
|
94
94
|
|
|
95
95
|
1. **Add examples** demonstrating new features
|
|
96
96
|
2. **Update SDK** after backend changes: `cd example-frontend && bun run sdk`
|
|
@@ -290,26 +290,28 @@ Modals:
|
|
|
290
290
|
- Don't use raw `View`/`Text` when `Box`/@terreno/ui `Text` are available
|
|
291
291
|
- Don't forget loading and error states
|
|
292
292
|
- Don't use `style` prop when equivalent props exist (`padding`, `margin`)
|
|
293
|
-
- Never modify `
|
|
293
|
+
- Never modify generated `store/apiSdk.ts` or `store/syncDbSdk.ts` manually
|
|
294
294
|
|
|
295
|
-
### @terreno/
|
|
295
|
+
### @terreno/syncdb
|
|
296
296
|
|
|
297
|
-
|
|
297
|
+
Frontend data, request, and session layer:
|
|
298
298
|
|
|
299
|
-
- **
|
|
300
|
-
- **
|
|
301
|
-
- **
|
|
299
|
+
- **createSyncDb** + `useQuery` / `useMutate`: Local-first collection CRUD
|
|
300
|
+
- **createApiClient** + generated `store/apiSdk.ts` hooks: Every non-synced route
|
|
301
|
+
- **SessionProvider** / **useSession**: Better Auth (or `jwtAuthAdapter`) session state
|
|
302
302
|
|
|
303
303
|
Key imports:
|
|
304
304
|
```typescript
|
|
305
|
-
import {
|
|
305
|
+
import {createApiClient} from "@terreno/syncdb/api";
|
|
306
|
+
import {SessionProvider, useSession} from "@terreno/syncdb/auth";
|
|
307
|
+
import {useMutate, useQuery} from "@terreno/syncdb/react";
|
|
306
308
|
```
|
|
307
309
|
|
|
308
|
-
Always use generated SDK hooks - never use `axios` or `
|
|
310
|
+
Always use generated SDK hooks or syncdb hooks - never use `axios` or `fetch` directly:
|
|
309
311
|
|
|
310
312
|
```typescript
|
|
311
313
|
// Correct
|
|
312
|
-
import {useGetYourRouteQuery} from "@/store/
|
|
314
|
+
import {useGetYourRouteQuery} from "@/store/apiSdk";
|
|
313
315
|
const {data, isLoading, error} = useGetYourRouteQuery({id: "value"});
|
|
314
316
|
|
|
315
317
|
// Wrong - don't use axios directly
|
package/CHANGELOG.md
CHANGED
|
@@ -20,6 +20,95 @@ Upgrade notes for consumer action live in [`mcp-server/src/docs/upgrades/`](mcp-
|
|
|
20
20
|
|
|
21
21
|
Unreleased changes live in [`changelog/unreleased/`](changelog/unreleased/). Add one Markdown file per feature (see that directory's README) instead of editing this section.
|
|
22
22
|
|
|
23
|
+
## [58.0.0-beta.2] - 2026-11-03
|
|
24
|
+
|
|
25
|
+
Upgrade note: [`mcp-server/src/docs/upgrades/58.0.0-beta.2.md`](mcp-server/src/docs/upgrades/58.0.0-beta.2.md).
|
|
26
|
+
|
|
27
|
+
### Breaking
|
|
28
|
+
|
|
29
|
+
- Terreno 58 targets Expo SDK 58 (`~58.0.14`), React Native `0.88.0`, and React `19.3.0`. `@terreno/ui` peers `react-native` `0.88.0`. Native catalog moves with the SDK: `react-native-gesture-handler` `~3.3.0`, `react-native-reanimated` `4.7.1` + `react-native-worklets` `0.13.0`, `react-native-screens` `~4.30.0`, `react-native-webview` `14.0.1`, `@sentry/react-native` `~8.28.0`, `@shopify/flash-list` `2.3.2`, `@shopify/react-native-skia` `2.14.0`. Rebuild dev clients and store binaries.
|
|
30
|
+
- Expo Router 58: set `export const unstable_settings = {initialRouteName}` on the layout instead of passing `initialRouteName` to `<Slot>` / navigators. `SidebarNavigation` ignores the prop.
|
|
31
|
+
- Expo Router 58 static rendering: a custom `app/+html.tsx` must render `headNodes` and `bodyNodes` from `useServerDocumentContext()` (`expo-router/html`), or exported pages ship without their JavaScript. `example-frontend` is updated.
|
|
32
|
+
- React Native 0.88 generated types: type refs as `ViewInstance`, `TextInstance`, `ScrollViewInstance`, and `TextInputInstance` (`Box.scrollRef`, `TextField.inputRef`, `Text` `ref`).
|
|
33
|
+
- `create-terreno-app` scaffolds Expo `~58.0.14`, React Native `0.88.0`, and React `19.3.0`.
|
|
34
|
+
- The Terreno 58 native module baseline lands in `example-frontend` and `demo`: `@stripe/stripe-react-native` 0.81.0, `react-native-purchases` and `react-native-purchases-ui` 10.12.2, `expo-device`, `expo-crypto`, `expo-local-authentication`, `expo-system-ui`, and `expo-build-properties` (Android Kotlin 2.2.21 and `compileSdkVersion` 37 pins). Rebuild every dev client and store binary. `react-native-otp-verify` is left out because it does not support the New Architecture. The demo has a hidden **Native Modules** page that shows each module's version and whether the running binary links it. See the 58.0.0 upgrade note.
|
|
35
|
+
- `TerrenoApp` turns HTTP rate limiting on by default. Omitting `rateLimit` now mounts the limiter with the memory store (auth 20 / 15 min, api 600 / 15 min). Pass `rateLimit: false` to turn it off. On Cloud Run pass `rateLimit: {trustProxy: 1}` so unauthenticated traffic keys by client IP. See the 58.0.0 upgrade note.
|
|
36
|
+
- `@terreno/admin-frontend` no longer takes an RTK `api`. The `api` prop is removed from every admin component (`AdminProvider`, `AdminShellLayout`, `AdminHome`, `AdminModelList`, `AdminModelTable`, `AdminModelForm`, `AdminScreenRouter`, `ConfigurationScreen`, `DocumentStorageBrowser`, `ConsentHistory`, comms, jobs, org, consent, and announcement screens, and widget props), and admin hooks drop their `api` argument (`useAdminConfig(apiBase)`, `useAdminScripts(apiBase)`, `useAdminRoles(apiBase)`, `useConfigurationApi({basePath})`, `useDocumentStorageApi(basePath)`, `useConsentHistory(baseUrl)`, `useOrganizationsApi(basePath)`, `useCommsDashboardApi()`, `useJobsDashboardApi()`, and the `useAiObservability*Api()` hooks).
|
|
37
|
+
- `useAdminApi(api, routePath, modelName)` is removed. Use `useAdminModelApi(routePath, modelName)`, which keeps the same hook names and calls the same `/admin/{routePath}` URLs through the admin fetch client. `AdminApi`, `EndpointBuilder`, and admin `injectEndpoints` are gone; `@reduxjs/toolkit` and `react-redux` are no longer peers of admin-frontend.
|
|
38
|
+
- `AdminProvider` is now the required auth binding for every admin request, including ObjectId and API-only model CRUD. Cookie SPAs pass `credentials="same-origin"`; embedded apps pass `apiOrigin` and `getAuthHeaders`. Product screens that reuse admin components wrap them in `AdminProvider`. See the 58.0.0 upgrade guide.
|
|
39
|
+
- Removed the legacy RTK realtime path. Use `sync` on `modelRouter` with `@terreno/syncdb` for live collection updates. `RealtimeApp`, `SyncApp`, socket auth, `sync:delta`, and admin `admin:model.changed` events are unchanged. See the 58.0.0 upgrade note.
|
|
40
|
+
- `@terreno/api`: `modelRouter` no longer accepts `realtime` (now a TypeScript error), and the change stream no longer emits the `sync` websocket event. Removed `RealtimeConfig`, `RealtimeEvent`, `DocumentSubscription`, `QuerySubscription`, `registerRealtime`, `getRealtimeRegistry`, `findRegistryEntryByCollection`, `findRegistryEntryByRoutePath`, `updateRealtimeRegistryOptions`, `clearRealtimeRegistry`, `RealtimeRegistryEntry`, the query-subscription store (`addQuerySubscription`, `removeQuerySubscription`, `removeAllSocketQueries`, `getQuerySubscriptionsForCollection`, `computeQueryId`, `clearQueryStore`), and `MAX_MODEL_SUBSCRIPTIONS` / `MAX_DOCUMENT_SUBSCRIPTIONS` / `MAX_QUERY_SUBSCRIPTIONS`. Sockets no longer handle `subscribe:model`, `subscribe:document`, or `subscribe:query`.
|
|
41
|
+
- `@terreno/rtk`: removed `realtimeList`, `realtimeDocument`, `setRealtimeSocket`, `getRealtimeSocket`, `useSyncConnection`, and the `RealtimeEvent` type. The rest of `@terreno/rtk` (including `useSocketConnection` and `useRealtimeDebug`) is removed in the same release; see `remove-rtk.md`.
|
|
42
|
+
- Removed `@terreno/rtk` and every Redux dependency (`@reduxjs/toolkit`, `react-redux`, `redux-persist`, `@rtk-query/codegen-openapi`). `@terreno/rtk` is not published for 58. `@terreno/syncdb` is the only frontend data, request, and session layer. Follow `docs/how-to/migrate-rtk-to-syncdb.md`, which maps every removed export to its replacement, and the 58.0.0 upgrade note.
|
|
43
|
+
- `@terreno/syncdb` adds `@terreno/syncdb/api` (`createApiClient`, `ApiError`), request hooks in `@terreno/syncdb/react` (`ApiClientProvider`, `useApiQuery`, `useLazyApiQuery`, `useApiMutation`, `useSocketEvent`), `@terreno/syncdb/config` (`baseUrl`, `baseWebsocketsUrl`, `appHeaders`), `@terreno/syncdb/auth` (`createBetterAuthClient`, `SessionProvider`, `useSession`, `jwtAuthAdapter`, `useJwtAuth`, token-expiry helpers), `@terreno/syncdb/flags` (`useFeatureFlags`, `useTerrenoFeatureFlags` on the sync socket), `@terreno/syncdb/app` (`useUpgradeCheck`, `hasPermission`, `canOpenAdminPage`, `installDevConsoleLogger`, `useMCPTools`), and `@terreno/syncdb/buildNumber`.
|
|
44
|
+
- `terreno-syncdb-codegen --api-out` generates typed hooks for every non-synced OpenAPI operation (same names as the RTK codegen), replacing `@rtk-query/codegen-openapi`. `bun run sdk` writes `store/apiSdk.ts`.
|
|
45
|
+
- `@terreno/ui` `ConsentNavigator`, `AnnouncementNavigator`, `useConsentForms`, `useSubmitConsent`, `useAnnouncements`, and `useAcknowledgeAnnouncement` take a request `client` instead of an RTK `api`.
|
|
46
|
+
- `GptHistory` (`gpt/histories`) is a synced collection and keeps its ObjectId `_id` (no migration). `McpServiceToken` (`mcp/service-tokens`, read-only) is a synced collection with String ids; run `mcpServiceTokenStringIdsMigration` (`@terreno/api`) before deploying 58 frontends.
|
|
47
|
+
- `create-terreno-app`, the `terreno_bootstrap` prompt, and the `terreno_generate_screen` tool scaffold apps without Redux or `@terreno/rtk`. The terreno-mcp-local `get_rtk_state` tool, the MCP resource `terreno://docs/rtk`, and `terreno state --slice rtk` are removed; use `get_syncdb_state` and `terreno state`.
|
|
48
|
+
|
|
49
|
+
### Added
|
|
50
|
+
|
|
51
|
+
- `DataTable` columns size themselves when `width` is omitted. Each auto column starts at the wider of its header and its content (sampled from at most 50 rows, measured with a canvas on web and estimated on native), clamped to 80–360px, and auto columns grow to fill the table's container. Columns that set `width` keep it. `DataTableColumn.width` is now optional.
|
|
52
|
+
- `@terreno/syncdb` `createSyncDb({idFormats})` mints 24-hex ObjectIds for a collection set to `"objectId"`, so a model that keeps Mongoose's default ObjectId `_id` can sync without migrating its ids. `mutate()` throws on an explicit non-hex id for such a collection. `generateObjectId` and the `SyncIdFormat` type are exported.
|
|
53
|
+
- Sync `validation` nacks carry an optional `reason`: `invalid_id` when an ObjectId-keyed collection gets a non-hex id (rejected before the mutation is claimed), and `id_collision` when a create names an `_id` another document holds. A collision never touches the existing document and its message never names the holder. The ledger records the reason (`SyncMutation.nackReason`) so a redelivery replays it.
|
|
54
|
+
- `GET /sync/entities` leaves out non-hex ids for an ObjectId-keyed model instead of answering 400, so a rejected create queued for repair cannot fail the rest of the repair batch.
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- The repository's agent rules now generate with rulesync 17 (up from 9). The root rule `.rulesync/rules/00-root.md` now generates `AGENTS.md`, which Devin and other AGENTS.md readers load, in place of `.devin/rules/00-root.md`. Never edit `AGENTS.md` by hand: edit the root rule and run `bun run rules`. The examples that existed only in the old hand-edited `AGENTS.md` (syncdb and RTK SDK usage) moved into the root rule, so `CLAUDE.md`, the Cursor root rule, and Copilot instructions get them too. Links in the root rule now resolve from the repository root. Generated Copilot hooks use the portable `command` field. Generated Copilot subagents no longer list `agent/runSubagent` as their only tool, so they get every default tool. Generated skills carry their `license`, `disable-model-invocation`, and Devin `triggers` frontmatter.
|
|
59
|
+
- `@terreno/syncdb/auth` `SessionProvider`: `logout()` no longer clears the session before the server answers. The session stays in the state until `authClient.signOut()` finishes (`signOutTimeoutMs`, default 10 seconds), and then it is cleared. Meanwhile the new `isSigningOut` state (`useSession().isSigningOut`) is true; `isLoading` is left alone, so a navigator gated on it keeps its screen. Before, a login screen that opened at once could find the still-live session and sign the user straight back in. A sign-out that fails or times out checks the session first. A session that is still live, or a cookie or native session the server cannot be asked about, stays signed in, and `error` is set to `SIGN_OUT_FAILED_MESSAGE` ("Couldn't sign out. Check your connection and try again."). A web bearer client, which drops its token before the request leaves, ends signed out. The global `auth/logout` action (a refused session) now ends signed out even when the sign-out request fails. With `apisToReset` (57.17.0), `logout()` purges the cache when the session clears, not when it is dispatched: a purge at dispatch refetched every mounted screen mid-sign-out, and a refetch that could not reach the server answered 401 and signed the user out even though the sign-out failed. A failed sign-out keeps both the session and the cache. The global `auth/logout` action still purges at once (only the first of several in flight) and again when the session clears. A sign-in for another user that lands while a sign-out is in flight is kept; a sign-out that started signed out asks `getSession` first, so a restore of the session it revoked is cleared. Show `selectBetterAuthIsSigningOut` on the sign-out control and `selectBetterAuthError` after a failed sign-out.
|
|
60
|
+
|
|
61
|
+
### Removed
|
|
62
|
+
|
|
63
|
+
- `@terreno/ui` no longer exports the `Filter` and `FilterProps` aliases deprecated in 57.7.0. Import `DropdownPanel` and `DropdownPanelProps` instead. `FilterSelectMenu`, `FilterBoolean`, `FilterAccordion`, and `FilterChangesBadge` keep their names.
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- `@terreno/syncdb`: logging out while `syncDb.start()` is still running no longer loses local writes or logs errors. `start()` now resolves the web encryption key from `GET /sync/key` before it loads the store, so the flush in `stop()` never needs the network after the session has ended. A `stop()` or `signOut()` call now cancels a `start()` that is running or queued ahead of it, so the transport never connects without a session. A failed key fetch is now retried on the next save instead of failing every save for the rest of the session.
|
|
68
|
+
|
|
69
|
+
## [58.0.0-beta.1] - 2026-11-02
|
|
70
|
+
|
|
71
|
+
Upgrade note: [`mcp-server/src/docs/upgrades/58.0.0-beta.1.md`](mcp-server/src/docs/upgrades/58.0.0-beta.1.md).
|
|
72
|
+
|
|
73
|
+
### Breaking
|
|
74
|
+
|
|
75
|
+
- Terreno 58 targets Expo SDK 58 (`~58.0.14`), React Native `0.88.0`, and React `19.3.0`. `@terreno/ui` peers `react-native` `0.88.0`. Native catalog moves with the SDK: `react-native-gesture-handler` `~3.3.0`, `react-native-reanimated` `4.7.1` + `react-native-worklets` `0.13.0`, `react-native-screens` `~4.30.0`, `react-native-webview` `14.0.1`, `@sentry/react-native` `~8.28.0`, `@shopify/flash-list` `2.3.2`, `@shopify/react-native-skia` `2.14.0`. Rebuild dev clients and store binaries.
|
|
76
|
+
- Expo Router 58: set `export const unstable_settings = {initialRouteName}` on the layout instead of passing `initialRouteName` to `<Slot>` / navigators. `SidebarNavigation` ignores the prop.
|
|
77
|
+
- Expo Router 58 static rendering: a custom `app/+html.tsx` must render `headNodes` and `bodyNodes` from `useServerDocumentContext()` (`expo-router/html`), or exported pages ship without their JavaScript. `example-frontend` is updated.
|
|
78
|
+
- React Native 0.88 generated types: type refs as `ViewInstance`, `TextInstance`, `ScrollViewInstance`, and `TextInputInstance` (`Box.scrollRef`, `TextField.inputRef`, `Text` `ref`).
|
|
79
|
+
- `create-terreno-app` scaffolds Expo `~58.0.14`, React Native `0.88.0`, and React `19.3.0`.
|
|
80
|
+
- The Terreno 58 native module baseline lands in `example-frontend` and `demo`: `@stripe/stripe-react-native` 0.81.0, `react-native-purchases` and `react-native-purchases-ui` 10.12.2, `expo-device`, `expo-crypto`, `expo-local-authentication`, `expo-system-ui`, and `expo-build-properties` (Android Kotlin 2.2.21 and `compileSdkVersion` 37 pins). Rebuild every dev client and store binary. `react-native-otp-verify` is left out because it does not support the New Architecture. The demo has a hidden **Native Modules** page that shows each module's version and whether the running binary links it. See the 58.0.0 upgrade note.
|
|
81
|
+
- `TerrenoApp` turns HTTP rate limiting on by default. Omitting `rateLimit` now mounts the limiter with the memory store (auth 20 / 15 min, api 600 / 15 min). Pass `rateLimit: false` to turn it off. On Cloud Run pass `rateLimit: {trustProxy: 1}` so unauthenticated traffic keys by client IP. See the 58.0.0 upgrade note.
|
|
82
|
+
- `@terreno/admin-frontend` no longer takes an RTK `api`. The `api` prop is removed from every admin component (`AdminProvider`, `AdminShellLayout`, `AdminHome`, `AdminModelList`, `AdminModelTable`, `AdminModelForm`, `AdminScreenRouter`, `ConfigurationScreen`, `DocumentStorageBrowser`, `ConsentHistory`, comms, jobs, org, consent, and announcement screens, and widget props), and admin hooks drop their `api` argument (`useAdminConfig(apiBase)`, `useAdminScripts(apiBase)`, `useAdminRoles(apiBase)`, `useConfigurationApi({basePath})`, `useDocumentStorageApi(basePath)`, `useConsentHistory(baseUrl)`, `useOrganizationsApi(basePath)`, `useCommsDashboardApi()`, `useJobsDashboardApi()`, and the `useAiObservability*Api()` hooks).
|
|
83
|
+
- `useAdminApi(api, routePath, modelName)` is removed. Use `useAdminModelApi(routePath, modelName)`, which keeps the same hook names and calls the same `/admin/{routePath}` URLs through the admin fetch client. `AdminApi`, `EndpointBuilder`, and admin `injectEndpoints` are gone; `@reduxjs/toolkit` and `react-redux` are no longer peers of admin-frontend.
|
|
84
|
+
- `AdminProvider` is now the required auth binding for every admin request, including ObjectId and API-only model CRUD. Cookie SPAs pass `credentials="same-origin"`; embedded apps pass `apiOrigin` and `getAuthHeaders`. Product screens that reuse admin components wrap them in `AdminProvider`. See the 58.0.0 upgrade guide.
|
|
85
|
+
- Removed the legacy RTK realtime path. Use `sync` on `modelRouter` with `@terreno/syncdb` for live collection updates. `RealtimeApp`, `SyncApp`, socket auth, `sync:delta`, and admin `admin:model.changed` events are unchanged. See the 58.0.0 upgrade note.
|
|
86
|
+
- `@terreno/api`: `modelRouter` no longer accepts `realtime` (now a TypeScript error), and the change stream no longer emits the `sync` websocket event. Removed `RealtimeConfig`, `RealtimeEvent`, `DocumentSubscription`, `QuerySubscription`, `registerRealtime`, `getRealtimeRegistry`, `findRegistryEntryByCollection`, `findRegistryEntryByRoutePath`, `updateRealtimeRegistryOptions`, `clearRealtimeRegistry`, `RealtimeRegistryEntry`, the query-subscription store (`addQuerySubscription`, `removeQuerySubscription`, `removeAllSocketQueries`, `getQuerySubscriptionsForCollection`, `computeQueryId`, `clearQueryStore`), and `MAX_MODEL_SUBSCRIPTIONS` / `MAX_DOCUMENT_SUBSCRIPTIONS` / `MAX_QUERY_SUBSCRIPTIONS`. Sockets no longer handle `subscribe:model`, `subscribe:document`, or `subscribe:query`.
|
|
87
|
+
- `@terreno/rtk`: removed `realtimeList`, `realtimeDocument`, `setRealtimeSocket`, `getRealtimeSocket`, `useSyncConnection`, and the `RealtimeEvent` type. The rest of `@terreno/rtk` (including `useSocketConnection` and `useRealtimeDebug`) is removed in the same release; see `remove-rtk.md`.
|
|
88
|
+
- Removed `@terreno/rtk` and every Redux dependency (`@reduxjs/toolkit`, `react-redux`, `redux-persist`, `@rtk-query/codegen-openapi`). `@terreno/rtk` is not published for 58. `@terreno/syncdb` is the only frontend data, request, and session layer. Follow `docs/how-to/migrate-rtk-to-syncdb.md`, which maps every removed export to its replacement, and the 58.0.0 upgrade note.
|
|
89
|
+
- `@terreno/syncdb` adds `@terreno/syncdb/api` (`createApiClient`, `ApiError`), request hooks in `@terreno/syncdb/react` (`ApiClientProvider`, `useApiQuery`, `useLazyApiQuery`, `useApiMutation`, `useSocketEvent`), `@terreno/syncdb/config` (`baseUrl`, `baseWebsocketsUrl`, `appHeaders`), `@terreno/syncdb/auth` (`createBetterAuthClient`, `SessionProvider`, `useSession`, `jwtAuthAdapter`, `useJwtAuth`, token-expiry helpers), `@terreno/syncdb/flags` (`useFeatureFlags`, `useTerrenoFeatureFlags` on the sync socket), `@terreno/syncdb/app` (`useUpgradeCheck`, `hasPermission`, `canOpenAdminPage`, `installDevConsoleLogger`, `useMCPTools`), and `@terreno/syncdb/buildNumber`.
|
|
90
|
+
- `terreno-syncdb-codegen --api-out` generates typed hooks for every non-synced OpenAPI operation (same names as the RTK codegen), replacing `@rtk-query/codegen-openapi`. `bun run sdk` writes `store/apiSdk.ts`.
|
|
91
|
+
- `@terreno/ui` `ConsentNavigator`, `AnnouncementNavigator`, `useConsentForms`, `useSubmitConsent`, `useAnnouncements`, and `useAcknowledgeAnnouncement` take a request `client` instead of an RTK `api`.
|
|
92
|
+
- `GptHistory` (`gpt/histories`) and `McpServiceToken` (`mcp/service-tokens`, read-only) are synced collections with String ids. Run the `gptHistoryStringIdsMigration` (`@terreno/ai`) and `mcpServiceTokenStringIdsMigration` (`@terreno/api`) before deploying 58 frontends.
|
|
93
|
+
- `create-terreno-app`, the `terreno_bootstrap` prompt, and the `terreno_generate_screen` tool scaffold apps without Redux or `@terreno/rtk`. The terreno-mcp-local `get_rtk_state` tool, the MCP resource `terreno://docs/rtk`, and `terreno state --slice rtk` are removed; use `get_syncdb_state` and `terreno state`.
|
|
94
|
+
|
|
95
|
+
### Added
|
|
96
|
+
|
|
97
|
+
- `DataTable` columns size themselves when `width` is omitted. Each auto column starts at the wider of its header and its content (sampled from at most 50 rows, measured with a canvas on web and estimated on native), clamped to 80–360px, and auto columns grow to fill the table's container. Columns that set `width` keep it. `DataTableColumn.width` is now optional.
|
|
98
|
+
|
|
99
|
+
### Changed
|
|
100
|
+
|
|
101
|
+
- The repository's agent rules now generate with rulesync 17 (up from 9). The root rule `.rulesync/rules/00-root.md` now generates `AGENTS.md`, which Devin and other AGENTS.md readers load, in place of `.devin/rules/00-root.md`. Never edit `AGENTS.md` by hand: edit the root rule and run `bun run rules`. The examples that existed only in the old hand-edited `AGENTS.md` (syncdb and RTK SDK usage) moved into the root rule, so `CLAUDE.md`, the Cursor root rule, and Copilot instructions get them too. Links in the root rule now resolve from the repository root. Generated Copilot hooks use the portable `command` field. Generated Copilot subagents no longer list `agent/runSubagent` as their only tool, so they get every default tool. Generated skills carry their `license`, `disable-model-invocation`, and Devin `triggers` frontmatter.
|
|
102
|
+
- `@terreno/syncdb/auth` `SessionProvider`: `logout()` no longer clears the session before the server answers. The session stays in the state until `authClient.signOut()` finishes (`signOutTimeoutMs`, default 10 seconds), and then it is cleared. Meanwhile the new `isSigningOut` state (`useSession().isSigningOut`) is true; `isLoading` is left alone, so a navigator gated on it keeps its screen. Before, a login screen that opened at once could find the still-live session and sign the user straight back in. A sign-out that fails or times out checks the session first. A session that is still live, or a cookie or native session the server cannot be asked about, stays signed in, and `error` is set to `SIGN_OUT_FAILED_MESSAGE` ("Couldn't sign out. Check your connection and try again."). A web bearer client, which drops its token before the request leaves, ends signed out. The global `auth/logout` action (a refused session) now ends signed out even when the sign-out request fails. With `apisToReset` (57.17.0), `logout()` purges the cache when the session clears, not when it is dispatched: a purge at dispatch refetched every mounted screen mid-sign-out, and a refetch that could not reach the server answered 401 and signed the user out even though the sign-out failed. A failed sign-out keeps both the session and the cache. The global `auth/logout` action still purges at once (only the first of several in flight) and again when the session clears. A sign-in for another user that lands while a sign-out is in flight is kept; a sign-out that started signed out asks `getSession` first, so a restore of the session it revoked is cleared. Show `selectBetterAuthIsSigningOut` on the sign-out control and `selectBetterAuthError` after a failed sign-out.
|
|
103
|
+
|
|
104
|
+
### Removed
|
|
105
|
+
|
|
106
|
+
- `@terreno/ui` no longer exports the `Filter` and `FilterProps` aliases deprecated in 57.7.0. Import `DropdownPanel` and `DropdownPanelProps` instead. `FilterSelectMenu`, `FilterBoolean`, `FilterAccordion`, and `FilterChangesBadge` keep their names.
|
|
107
|
+
|
|
108
|
+
### Fixed
|
|
109
|
+
|
|
110
|
+
- `@terreno/syncdb`: logging out while `syncDb.start()` is still running no longer loses local writes or logs errors. `start()` now resolves the web encryption key from `GET /sync/key` before it loads the store, so the flush in `stop()` never needs the network after the session has ended. A `stop()` or `signOut()` call now cancels a `start()` that is running or queued ahead of it, so the transport never connects without a session. A failed key fetch is now retried on the next save instead of failing every save for the rest of the session.
|
|
111
|
+
|
|
23
112
|
## [57.21.0] - 2026-11-01
|
|
24
113
|
|
|
25
114
|
Upgrade note: [`mcp-server/src/docs/upgrades/57.21.0.md`](mcp-server/src/docs/upgrades/57.21.0.md).
|
package/biome.jsonc
CHANGED
package/dist/aiApp.d.ts
CHANGED
|
@@ -32,7 +32,10 @@ export interface AiAppOptions {
|
|
|
32
32
|
maxSteps?: number;
|
|
33
33
|
/** MCP service for connecting to external tool servers. */
|
|
34
34
|
mcpService?: MCPService;
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* OpenAPI options passed through to route builders for spec generation. Defaults to the
|
|
37
|
+
* OpenAPI instance TerrenoApp passes to `register`.
|
|
38
|
+
*/
|
|
36
39
|
openApiOptions?: Record<string, unknown>;
|
|
37
40
|
/**
|
|
38
41
|
* Mount the `/gpt/projects` routes, which register the `Project` model. Defaults to `true`;
|
|
@@ -75,5 +78,5 @@ export interface AiAppOptions {
|
|
|
75
78
|
export declare class AiApp implements TerrenoPlugin {
|
|
76
79
|
private options;
|
|
77
80
|
constructor(options: AiAppOptions);
|
|
78
|
-
register(app: express.Application): void;
|
|
81
|
+
register(app: express.Application, openApi?: unknown): void;
|
|
79
82
|
}
|
package/dist/aiApp.js
CHANGED
|
@@ -38,9 +38,10 @@ class AiApp {
|
|
|
38
38
|
constructor(options) {
|
|
39
39
|
this.options = options;
|
|
40
40
|
}
|
|
41
|
-
register(app) {
|
|
41
|
+
register(app, openApi) {
|
|
42
42
|
const router = app;
|
|
43
|
-
const { aiService, asks, createModelFn, createServerModelFn, demoMode, fileStorageService, fileUploadsEnabled, gcsBucket, maxSteps, mcpService,
|
|
43
|
+
const { aiService, asks, createModelFn, createServerModelFn, demoMode, fileStorageService, fileUploadsEnabled, gcsBucket, maxSteps, mcpService, projects, titleModelId, toolChoice, tools, } = this.options;
|
|
44
|
+
const openApiOptions = this.options.openApiOptions ?? (openApi ? { openApi } : undefined);
|
|
44
45
|
const hasFileRoutes = Boolean(fileStorageService && gcsBucket);
|
|
45
46
|
const chat = {
|
|
46
47
|
aiService,
|
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export { buildObservabilityStatus, buildPlaygroundAiStatus, isLocalObservability
|
|
|
31
31
|
export type { ControlPrimary, ObservabilityAiServiceFactory, ObservabilityAppOptions, ObservabilityCapability, ObservabilityControlConfig, ObservabilityGenerateClient, ObservabilityPlugin, ObservabilityRequestAiServiceFactory, PromptRegistry, ReviewQueue, ScoreRecord, ScoreSink, SpanRecord, TraceExportResult, TraceRecord, TraceSink, } from "./observability/types";
|
|
32
32
|
export { DEFAULT_OBSERVABILITY_CONTROL, resolveObservabilityControl, validateObservabilityConfig, } from "./observability/types";
|
|
33
33
|
export { addAiRequestsExplorerRoutes } from "./routes/aiRequestsExplorer";
|
|
34
|
-
export { addFileRoutes } from "./routes/files";
|
|
34
|
+
export { addFileRoutes, type FileStorageServiceSource } from "./routes/files";
|
|
35
35
|
export { addGptRoutes } from "./routes/gpt";
|
|
36
36
|
export { addGptHistoryRoutes } from "./routes/gptHistories";
|
|
37
37
|
export { addMcpRoutes } from "./routes/mcp";
|
|
@@ -160,6 +160,8 @@ gptHistorySchema.plugin(api_1.createdUpdatedPlugin);
|
|
|
160
160
|
gptHistorySchema.plugin(api_1.isDeletedPlugin);
|
|
161
161
|
gptHistorySchema.plugin(api_1.findOneOrNone);
|
|
162
162
|
gptHistorySchema.plugin(api_1.findExactlyOne);
|
|
163
|
+
// Stamps a per-stream _syncSeq on every write; required by the /gpt/histories sync config.
|
|
164
|
+
gptHistorySchema.plugin(api_1.syncPlugin);
|
|
163
165
|
// Virtual ownerId alias so Permissions.IsOwner works with userId field
|
|
164
166
|
gptHistorySchema.virtual("ownerId").get(function () {
|
|
165
167
|
return this.userId;
|
package/dist/routes/files.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type express from "express";
|
|
2
2
|
import type { FileStorageService } from "../service/fileStorage";
|
|
3
3
|
import type { FileRouteOptions } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* A storage service, or a function that returns the current one. Pass a function when storage
|
|
6
|
+
* can be configured or cleared at runtime: the routes stay mounted (and documented in OpenAPI)
|
|
7
|
+
* and answer 503 while it returns `undefined`.
|
|
8
|
+
*/
|
|
9
|
+
export type FileStorageServiceSource = FileStorageService | (() => FileStorageService | undefined);
|
|
4
10
|
export declare const addFileRoutes: (router: express.Router, options: FileRouteOptions & {
|
|
5
|
-
fileStorageService:
|
|
11
|
+
fileStorageService: FileStorageServiceSource;
|
|
6
12
|
}) => void;
|
package/dist/routes/files.js
CHANGED
|
@@ -25,8 +25,27 @@ const gcsKeyParam = (req) => {
|
|
|
25
25
|
return Array.isArray(param) ? param.join("/") : param;
|
|
26
26
|
};
|
|
27
27
|
const requestUserId = (req) => req.user?._id;
|
|
28
|
+
const resolveFileStorageService = (source) => {
|
|
29
|
+
const service = typeof source === "function" ? source() : source;
|
|
30
|
+
if (!service) {
|
|
31
|
+
throw new api_1.APIError({ status: 503, title: "File storage is not configured" });
|
|
32
|
+
}
|
|
33
|
+
return service;
|
|
34
|
+
};
|
|
35
|
+
const uploadResultSchema = {
|
|
36
|
+
filename: { type: "string" },
|
|
37
|
+
gcsKey: {
|
|
38
|
+
description: "Storage key; GET or DELETE /files/<gcsKey> reads or removes the file",
|
|
39
|
+
type: "string",
|
|
40
|
+
},
|
|
41
|
+
id: { description: "The FileAttachment id", type: "string" },
|
|
42
|
+
mimeType: { type: "string" },
|
|
43
|
+
size: { description: "Size in bytes", type: "number" },
|
|
44
|
+
url: { type: "string" },
|
|
45
|
+
};
|
|
28
46
|
const addFileRoutes = (router, options) => {
|
|
29
|
-
const {
|
|
47
|
+
const { maxFileSize = DEFAULT_MAX_FILE_SIZE } = options;
|
|
48
|
+
const fileStorageService = () => resolveFileStorageService(options.fileStorageService);
|
|
30
49
|
const upload = (0, multer_1.default)({
|
|
31
50
|
fileFilter: (_req, file, cb) => {
|
|
32
51
|
if (ALLOWED_MIME_TYPES.has(file.mimetype)) {
|
|
@@ -41,27 +60,43 @@ const addFileRoutes = (router, options) => {
|
|
|
41
60
|
});
|
|
42
61
|
router.post("/files/upload", [
|
|
43
62
|
(0, api_1.authenticateMiddleware)(),
|
|
63
|
+
// Fail before multer buffers the upload when no storage is configured.
|
|
64
|
+
(_req, _res, next) => {
|
|
65
|
+
try {
|
|
66
|
+
fileStorageService();
|
|
67
|
+
next();
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
next(error);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
44
73
|
upload.single("file"),
|
|
45
74
|
(0, api_1.createOpenApiBuilder)(options.openApiOptions ?? {})
|
|
46
75
|
.withTags(["files"])
|
|
47
76
|
.withSummary("Upload a file")
|
|
77
|
+
.withDescription(`Send the file as multipart/form-data in the \`file\` field. Allowed types: ${[
|
|
78
|
+
...ALLOWED_MIME_TYPES,
|
|
79
|
+
].join(", ")}. Maximum size: ${maxFileSize} bytes.`)
|
|
80
|
+
.withRequestBody({ file: { format: "binary", required: true, type: "string" } }, { mediaType: "multipart/form-data" })
|
|
48
81
|
.withResponse(200, {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
82
|
+
data: {
|
|
83
|
+
properties: uploadResultSchema,
|
|
84
|
+
required: Object.keys(uploadResultSchema),
|
|
85
|
+
type: "object",
|
|
86
|
+
},
|
|
87
|
+
}, { required: ["data"] })
|
|
88
|
+
// Multer puts the file on req.file, not req.body, so JSON body validation must stay off.
|
|
89
|
+
.withValidation({ enabled: false })
|
|
56
90
|
.build(),
|
|
57
91
|
], (0, api_1.asyncHandler)(async (req, res) => {
|
|
58
92
|
await (0, fileUploadsGate_1.assertFileUploadsEnabled)(req, options.fileUploadsEnabled);
|
|
93
|
+
const storage = fileStorageService();
|
|
59
94
|
const file = req.file;
|
|
60
95
|
const userId = requestUserId(req);
|
|
61
96
|
if (!file) {
|
|
62
97
|
throw new api_1.APIError({ status: 400, title: "No file provided" });
|
|
63
98
|
}
|
|
64
|
-
const result = await
|
|
99
|
+
const result = await storage.upload({
|
|
65
100
|
buffer: file.buffer,
|
|
66
101
|
filename: file.originalname,
|
|
67
102
|
mimeType: file.mimetype,
|
|
@@ -75,9 +110,16 @@ const addFileRoutes = (router, options) => {
|
|
|
75
110
|
.withTags(["files"])
|
|
76
111
|
.withSummary("Get file URL")
|
|
77
112
|
.withPathParameter("gcsKey", { type: "string" })
|
|
78
|
-
.withResponse(200, {
|
|
113
|
+
.withResponse(200, {
|
|
114
|
+
data: {
|
|
115
|
+
properties: { url: { description: "Signed URL for the file", type: "string" } },
|
|
116
|
+
required: ["url"],
|
|
117
|
+
type: "object",
|
|
118
|
+
},
|
|
119
|
+
}, { required: ["data"] })
|
|
79
120
|
.build(),
|
|
80
121
|
], (0, api_1.asyncHandler)(async (req, res) => {
|
|
122
|
+
const storage = fileStorageService();
|
|
81
123
|
const gcsKey = gcsKeyParam(req);
|
|
82
124
|
// Another user's file is "not found", so keys cannot be probed.
|
|
83
125
|
const attachment = await fileAttachment_1.FileAttachment.findOneOrNone({
|
|
@@ -88,7 +130,7 @@ const addFileRoutes = (router, options) => {
|
|
|
88
130
|
if (!attachment) {
|
|
89
131
|
throw new api_1.APIError({ status: 404, title: "File not found" });
|
|
90
132
|
}
|
|
91
|
-
const url = await
|
|
133
|
+
const url = await storage.getSignedUrl(gcsKey);
|
|
92
134
|
return res.json({ data: { url } });
|
|
93
135
|
}));
|
|
94
136
|
router.delete("/files/*gcsKey", [
|
|
@@ -97,9 +139,16 @@ const addFileRoutes = (router, options) => {
|
|
|
97
139
|
.withTags(["files"])
|
|
98
140
|
.withSummary("Delete a file")
|
|
99
141
|
.withPathParameter("gcsKey", { type: "string" })
|
|
100
|
-
.withResponse(200, {
|
|
142
|
+
.withResponse(200, {
|
|
143
|
+
data: {
|
|
144
|
+
properties: { success: { type: "boolean" } },
|
|
145
|
+
required: ["success"],
|
|
146
|
+
type: "object",
|
|
147
|
+
},
|
|
148
|
+
}, { required: ["data"] })
|
|
101
149
|
.build(),
|
|
102
150
|
], (0, api_1.asyncHandler)(async (req, res) => {
|
|
151
|
+
const storage = fileStorageService();
|
|
103
152
|
const gcsKey = gcsKeyParam(req);
|
|
104
153
|
const userId = requestUserId(req);
|
|
105
154
|
const attachment = await fileAttachment_1.FileAttachment.findOneOrNone({ deleted: false, gcsKey });
|
|
@@ -109,7 +158,7 @@ const addFileRoutes = (router, options) => {
|
|
|
109
158
|
if (attachment.userId.toString() !== userId.toString()) {
|
|
110
159
|
throw new api_1.APIError({ status: 403, title: "Not authorized to delete this file" });
|
|
111
160
|
}
|
|
112
|
-
await
|
|
161
|
+
await storage.delete(gcsKey);
|
|
113
162
|
return res.json({ data: { success: true } });
|
|
114
163
|
}));
|
|
115
164
|
};
|
|
@@ -7,6 +7,8 @@ const luxon_1 = require("luxon");
|
|
|
7
7
|
const gptHistory_1 = require("../models/gptHistory");
|
|
8
8
|
const asks_1 = require("../service/asks");
|
|
9
9
|
const chatTurn_1 = require("../service/chatTurn");
|
|
10
|
+
/** Route path of the history CRUD; the sync collection tag is this path without the slash. */
|
|
11
|
+
const GPT_HISTORIES_PATH = "/gpt/histories";
|
|
10
12
|
/**
|
|
11
13
|
* Only the chat turn writes `pendingAsk`: it holds messages replayed verbatim to the model, so a
|
|
12
14
|
* client must not be able to plant or edit one, including through dotted paths.
|
|
@@ -237,7 +239,9 @@ const addGptHistoryRoutes = (router, options) => {
|
|
|
237
239
|
if (headlessChat) {
|
|
238
240
|
(0, asks_1.assertNoReservedToolNames)(headlessChat.tools);
|
|
239
241
|
}
|
|
240
|
-
|
|
242
|
+
// The three-argument form registers the collection, so SyncApp serves it to @terreno/syncdb
|
|
243
|
+
// clients as the `gpt/histories` collection on the caller's owner stream.
|
|
244
|
+
const registration = (0, api_1.modelRouter)(GPT_HISTORIES_PATH, gptHistory_1.GptHistory, {
|
|
241
245
|
...openApiOptions,
|
|
242
246
|
...routerOptions,
|
|
243
247
|
...(headlessChat ? headlessActions({ chat: headlessChat, routerOptions }) : {}),
|
|
@@ -278,7 +282,9 @@ const addGptHistoryRoutes = (router, options) => {
|
|
|
278
282
|
: withClientPendingAsk(serialized));
|
|
279
283
|
},
|
|
280
284
|
sort: "-updated",
|
|
285
|
+
sync: { scope: { field: "userId", type: "owner" } },
|
|
281
286
|
validation: withCallerUserId(routerOptions.validation),
|
|
282
|
-
})
|
|
287
|
+
});
|
|
288
|
+
router.use(registration.path, registration.router);
|
|
283
289
|
};
|
|
284
290
|
exports.addGptHistoryRoutes = addGptHistoryRoutes;
|
package/dist/service/chatTurn.js
CHANGED
|
@@ -155,6 +155,11 @@ const loadHistory = async ({ historyId, projectId, userId, }) => {
|
|
|
155
155
|
if (!historyId) {
|
|
156
156
|
return new gptHistory_1.GptHistory({ prompts: [], userId, ...(projectId ? { projectId } : {}) });
|
|
157
157
|
}
|
|
158
|
+
// The id arrives as the ObjectId's hex string. An object here would be read as a query
|
|
159
|
+
// operator, and any other string would surface as a CastError 500.
|
|
160
|
+
if (typeof historyId !== "string" || !/^[0-9a-fA-F]{24}$/.test(historyId)) {
|
|
161
|
+
throw new api_1.APIError({ status: 400, title: "historyId is not valid" });
|
|
162
|
+
}
|
|
158
163
|
const history = await gptHistory_1.GptHistory.findById(historyId);
|
|
159
164
|
if (!history) {
|
|
160
165
|
throw new api_1.APIError({ status: 404, title: "History not found" });
|
package/dist/service/vertex.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ImageModelV4, LanguageModelV4 } from "@ai-sdk/provider";
|
|
1
2
|
import type { ImageModel, LanguageModel } from "ai";
|
|
2
3
|
/**
|
|
3
4
|
* Helper for Google's Vertex AI provider, now part of the "Gemini Enterprise Agent Platform"
|
|
@@ -16,8 +17,10 @@ import type { ImageModel, LanguageModel } from "ai";
|
|
|
16
17
|
export declare const DEFAULT_VERTEX_LOCATION = "global";
|
|
17
18
|
/** Provider returned by `@ai-sdk/google-vertex` `createVertex`. */
|
|
18
19
|
export interface VertexLanguageModelProvider {
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
/** `@ai-sdk/google-vertex` v4+ returns `LanguageModelV4`; older `ai` majors still type `LanguageModel` as v2/v3 only. */
|
|
21
|
+
(modelId: string): LanguageModel | LanguageModelV4;
|
|
22
|
+
/** `@ai-sdk/google-vertex` v4+ returns `ImageModelV4`; older `ai` majors still type `ImageModel` as v2/v3 only. */
|
|
23
|
+
image: (modelId: string) => ImageModel | ImageModelV4;
|
|
21
24
|
}
|
|
22
25
|
interface VertexModule {
|
|
23
26
|
createVertex: (opts: {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -113,6 +113,10 @@ interface GptHistoryPendingAskState {
|
|
|
113
113
|
}
|
|
114
114
|
/** The ask a history is waiting on. At most one per history. */
|
|
115
115
|
export type GptHistoryPendingAsk = Ask & GptHistoryPendingAskState;
|
|
116
|
+
/**
|
|
117
|
+
* Synced through @terreno/syncdb with the default ObjectId `_id`; sync clients that create
|
|
118
|
+
* histories configure `idFormats: {"gpt/histories": "objectId"}`.
|
|
119
|
+
*/
|
|
116
120
|
export interface GptHistoryDocument extends mongoose.Document<mongoose.Types.ObjectId> {
|
|
117
121
|
created: Date;
|
|
118
122
|
deleted: boolean;
|
package/package.json
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
"url": "https://github.com/TerrenoLabs/terreno/issues"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@ai-sdk/mcp": "^
|
|
7
|
+
"@ai-sdk/mcp": "^2.0.57",
|
|
8
8
|
"@google-cloud/storage": "^7.15.0",
|
|
9
9
|
"@langfuse/client": "^5.0.1",
|
|
10
10
|
"@langfuse/otel": "^5.0.1",
|
|
11
11
|
"@opentelemetry/api": "^1.9.0",
|
|
12
|
-
"@opentelemetry/sdk-node": "0.
|
|
13
|
-
"@terreno/blocks": "
|
|
12
|
+
"@opentelemetry/sdk-node": "0.222.0",
|
|
13
|
+
"@terreno/blocks": "58.0.0-beta.2",
|
|
14
14
|
"ai": "^6.0.97",
|
|
15
15
|
"ajv": "8.20.0",
|
|
16
16
|
"csv-parse": "^6.1.0",
|
|
17
|
-
"google-auth-library": "^
|
|
17
|
+
"google-auth-library": "^11.1.0",
|
|
18
18
|
"luxon": "^3.7.2",
|
|
19
19
|
"multer": "2.2.0",
|
|
20
20
|
"sanitize-html": "^2.17.0"
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"description": "Provider-agnostic AI service with streaming chat, request logging, and admin tools — part of Terreno, the batteries-included TypeScript framework for universal apps.",
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@biomejs/biome": "^2.3.6",
|
|
25
|
-
"@terreno/admin-backend": "
|
|
26
|
-
"@terreno/api": "
|
|
27
|
-
"@terreno/jobs": "
|
|
28
|
-
"@terreno/test": "
|
|
25
|
+
"@terreno/admin-backend": "58.0.0-beta.2",
|
|
26
|
+
"@terreno/api": "58.0.0-beta.2",
|
|
27
|
+
"@terreno/jobs": "58.0.0-beta.2",
|
|
28
|
+
"@terreno/test": "58.0.0-beta.2",
|
|
29
29
|
"@types/bun": "^1.4.0",
|
|
30
30
|
"@types/express": "^5.0.6",
|
|
31
31
|
"@types/luxon": "^3.7.1",
|
|
@@ -135,9 +135,10 @@
|
|
|
135
135
|
"main": "dist/index.js",
|
|
136
136
|
"name": "@terreno/ai",
|
|
137
137
|
"peerDependencies": {
|
|
138
|
-
"@ai-sdk/google-vertex": "^
|
|
139
|
-
"@
|
|
140
|
-
"@terreno/
|
|
138
|
+
"@ai-sdk/google-vertex": "^5.0.92",
|
|
139
|
+
"@ai-sdk/provider": "^4.0.26",
|
|
140
|
+
"@terreno/api": "58.0.0-beta.2",
|
|
141
|
+
"@terreno/jobs": "58.0.0-beta.2",
|
|
141
142
|
"mongoose": "^8.0.0 || ^9.0.0"
|
|
142
143
|
},
|
|
143
144
|
"peerDependenciesMeta": {
|
|
@@ -170,5 +171,5 @@
|
|
|
170
171
|
"typecheck": "tsc -p tsconfig.typecheck.json"
|
|
171
172
|
},
|
|
172
173
|
"types": "dist/index.d.ts",
|
|
173
|
-
"version": "
|
|
174
|
+
"version": "58.0.0-beta.2"
|
|
174
175
|
}
|
package/src/aiApp.test.ts
CHANGED
|
@@ -55,7 +55,7 @@ describe("AiApp", () => {
|
|
|
55
55
|
|
|
56
56
|
afterEach(async () => {
|
|
57
57
|
await AIRequest.deleteMany({});
|
|
58
|
-
await GptHistory.deleteMany({});
|
|
58
|
+
await GptHistory.collection.deleteMany({});
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
const authAsUser = async (app: express.Application) => {
|
|
@@ -356,4 +356,24 @@ describe("AiApp", () => {
|
|
|
356
356
|
const servers = await agent.get("/mcp/servers");
|
|
357
357
|
expect(servers.status).not.toBe(404);
|
|
358
358
|
});
|
|
359
|
+
it("documents its routes with the OpenAPI instance TerrenoApp passes to register", async () => {
|
|
360
|
+
const {AIService} = await import("./service/aiService.js");
|
|
361
|
+
const aiService = new AIService({model: createMockModel() as unknown as LanguageModel});
|
|
362
|
+
const fileStorageService = {
|
|
363
|
+
delete: mock(async () => {}),
|
|
364
|
+
getSignedUrl: mock(async () => "https://example.com/signed"),
|
|
365
|
+
upload: mock(async () => {
|
|
366
|
+
throw new Error("not called");
|
|
367
|
+
}),
|
|
368
|
+
} as unknown as FileStorageService;
|
|
369
|
+
const app = new TerrenoApp({skipListen: true, userModel: terrenoUserModel})
|
|
370
|
+
.register(new AiApp({aiService, fileStorageService, gcsBucket: "bucket"}))
|
|
371
|
+
.build();
|
|
372
|
+
|
|
373
|
+
const res = await supertest(app).get("/openapi.json").expect(200);
|
|
374
|
+
expect(res.body.paths["/files/upload"]?.post?.requestBody?.content).toHaveProperty(
|
|
375
|
+
"multipart/form-data"
|
|
376
|
+
);
|
|
377
|
+
expect(res.body.paths["/gpt/prompt"]?.post).toBeDefined();
|
|
378
|
+
});
|
|
359
379
|
});
|
package/src/aiApp.ts
CHANGED
|
@@ -40,7 +40,10 @@ export interface AiAppOptions {
|
|
|
40
40
|
maxSteps?: number;
|
|
41
41
|
/** MCP service for connecting to external tool servers. */
|
|
42
42
|
mcpService?: MCPService;
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* OpenAPI options passed through to route builders for spec generation. Defaults to the
|
|
45
|
+
* OpenAPI instance TerrenoApp passes to `register`.
|
|
46
|
+
*/
|
|
44
47
|
openApiOptions?: Record<string, unknown>;
|
|
45
48
|
/**
|
|
46
49
|
* Mount the `/gpt/projects` routes, which register the `Project` model. Defaults to `true`;
|
|
@@ -88,7 +91,7 @@ export class AiApp implements TerrenoPlugin {
|
|
|
88
91
|
this.options = options;
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
register(app: express.Application): void {
|
|
94
|
+
register(app: express.Application, openApi?: unknown): void {
|
|
92
95
|
const router = app;
|
|
93
96
|
const {
|
|
94
97
|
aiService,
|
|
@@ -101,13 +104,13 @@ export class AiApp implements TerrenoPlugin {
|
|
|
101
104
|
gcsBucket,
|
|
102
105
|
maxSteps,
|
|
103
106
|
mcpService,
|
|
104
|
-
openApiOptions,
|
|
105
107
|
projects,
|
|
106
108
|
titleModelId,
|
|
107
109
|
toolChoice,
|
|
108
110
|
tools,
|
|
109
111
|
} = this.options;
|
|
110
112
|
|
|
113
|
+
const openApiOptions = this.options.openApiOptions ?? (openApi ? {openApi} : undefined);
|
|
111
114
|
const hasFileRoutes = Boolean(fileStorageService && gcsBucket);
|
|
112
115
|
const chat = {
|
|
113
116
|
aiService,
|