@flytedesk/app-kit 11.4.0 → 12.0.0
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/README.md +138 -2
- package/dist/auth/errors.d.ts +10 -0
- package/dist/auth/errors.js +14 -0
- package/dist/auth/errors.js.map +1 -1
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.js +1 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/people/lookup.d.ts +32 -0
- package/dist/auth/people/lookup.js +81 -0
- package/dist/auth/people/lookup.js.map +1 -0
- package/dist/auth/prisma/prismaAuthStore.js +1 -6
- package/dist/auth/prisma/prismaAuthStore.js.map +1 -1
- package/dist/auth/revocationReasons.d.ts +4 -0
- package/dist/auth/revocationReasons.js +10 -0
- package/dist/auth/revocationReasons.js.map +1 -0
- package/dist/chat/tools/index.d.ts +38 -0
- package/dist/chat/tools/index.js +60 -0
- package/dist/chat/tools/index.js.map +1 -0
- package/dist/cli/auth-adopt.d.ts +13 -0
- package/dist/cli/auth-adopt.js +201 -0
- package/dist/cli/auth-adopt.js.map +1 -0
- package/dist/cli/auth-sync.js +2 -1
- package/dist/cli/auth-sync.js.map +1 -1
- package/dist/cli/sync-engine.d.ts +8 -0
- package/dist/cli/sync-engine.js +155 -21
- package/dist/cli/sync-engine.js.map +1 -1
- package/dist/flytebot/client.d.ts +66 -0
- package/dist/flytebot/client.js +377 -0
- package/dist/flytebot/client.js.map +1 -0
- package/dist/flytebot/env.d.ts +11 -0
- package/dist/flytebot/env.js +25 -0
- package/dist/flytebot/env.js.map +1 -0
- package/dist/flytebot/error.d.ts +36 -0
- package/dist/flytebot/error.js +60 -0
- package/dist/flytebot/error.js.map +1 -0
- package/dist/flytebot/index.d.ts +32 -0
- package/dist/flytebot/index.js +28 -0
- package/dist/flytebot/index.js.map +1 -0
- package/dist/flytebot/sse.d.ts +11 -0
- package/dist/flytebot/sse.js +55 -0
- package/dist/flytebot/sse.js.map +1 -0
- package/dist/flytebot/testing/fake.d.ts +77 -0
- package/dist/flytebot/testing/fake.js +399 -0
- package/dist/flytebot/testing/fake.js.map +1 -0
- package/dist/flytebot/testing/index.d.ts +18 -0
- package/dist/flytebot/testing/index.js +18 -0
- package/dist/flytebot/testing/index.js.map +1 -0
- package/dist/flytebot/webhook.d.ts +24 -0
- package/dist/flytebot/webhook.js +63 -0
- package/dist/flytebot/webhook.js.map +1 -0
- package/dist/spa-server/index.d.ts +8 -16
- package/dist/spa-server/index.js +36 -4
- package/dist/spa-server/index.js.map +1 -1
- package/package.json +17 -2
- package/prisma/fragments/auth.prisma +9 -3
- package/prisma/migrations/0004_app_kit_auth_init/migration.sql +74 -41
- package/prisma/migrations/manifest.json +1 -1
package/README.md
CHANGED
|
@@ -105,14 +105,26 @@ from app to app):
|
|
|
105
105
|
the session lock. It takes the app's own generated Prisma client (typed structurally,
|
|
106
106
|
so no generated client is imported). Install its models with `npx auth-sync init`
|
|
107
107
|
(`prisma/fragments/auth.prisma`: `IdpSession`, `RefreshToken`, `AuthAuditLog`), then
|
|
108
|
-
`new PrismaAuthStore(prisma)` is the `store` above.
|
|
108
|
+
`new PrismaAuthStore(prisma)` is the `store` above. In an app that uses Prisma migrate
|
|
109
|
+
(`prisma/migrations/migration_lock.toml`), `auth-sync` writes no SQL into
|
|
110
|
+
`prisma/migrations` and runs none: create the tables with `prisma migrate dev
|
|
111
|
+
--create-only` and append the two CHECK statements `auth-sync init` prints (Prisma
|
|
112
|
+
cannot express them). An app that already has its own auth tables runs
|
|
113
|
+
`npx auth-sync adopt --map=adopt.json` instead, which writes a Prisma migration renaming
|
|
114
|
+
its tables, columns, keys and indexes to the fragment's with every row kept
|
|
115
|
+
(`{"tables": {"app_kit_idp_session": "sessions", "app_kit_refresh_token": "refresh_tokens",
|
|
116
|
+
"app_kit_auth_audit_log": "auth_audit_logs"}, "columns": {"app_kit_refresh_token":
|
|
117
|
+
{"idp_session_id": "session_id"}}}`, columns only where the name differs).
|
|
109
118
|
- **The any-of-these-permissions guard**: `requireAnyPermission("chat", "admin")` from
|
|
110
119
|
`@flytedesk/app-kit/auth`, beside `requirePermission` (which wants all keys). It
|
|
111
120
|
refuses with the same 401/503/403 bodies.
|
|
112
121
|
- **The SPA cache policy**: hashed assets `public, max-age=31536000, immutable`,
|
|
113
122
|
`index.html` and every SPA-fallback route `no-cache`. `createSpaServer` and the
|
|
114
123
|
`spa-server` bin apply it; a Fastify app that serves its own SPA registers
|
|
115
|
-
`spaCachePolicy` from `@flytedesk/app-kit/spa-server`
|
|
124
|
+
`spaCachePolicy` from `@flytedesk/app-kit/spa-server` with `{ dir }` (the directory it
|
|
125
|
+
serves) inside a scope that holds only its SPA routes. Only a real file in `dir` under
|
|
126
|
+
the asset prefix is immutable: a fallback page served for a missing `/assets/old.js` is
|
|
127
|
+
`no-cache`.
|
|
116
128
|
|
|
117
129
|
Its `AuthStore` persists `IdpSessionRow.idToken`, which is sent back to flytedesk ID as the
|
|
118
130
|
logout's `id_token_hint`. That is what lets flytedesk ID end its session without a
|
|
@@ -185,6 +197,27 @@ An `AuthStore` implementer must provide `findLiveRefreshTokenForSession(idpSessi
|
|
|
185
197
|
now)`: a refresh-token row of that session with `revocation === null` and
|
|
186
198
|
`expiresAt > now`, else `null`. `now` is the app's clock, as for every other store method.
|
|
187
199
|
|
|
200
|
+
### Looking up people (name, email, avatar)
|
|
201
|
+
|
|
202
|
+
An app's server finds people in flytedesk ID's directory with its own service principal
|
|
203
|
+
(it needs the app permission `people.lookup`), reusing a `createServiceTokenSource` from
|
|
204
|
+
`@flytedesk/app-kit/auth/service`:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import { lookupPeopleBySubs, lookupSubByEmail } from "@flytedesk/app-kit/auth";
|
|
208
|
+
|
|
209
|
+
const dir = { issuer, appId, tokens }; // tokens: ServiceTokenSource
|
|
210
|
+
const people = await lookupPeopleBySubs(dir, subs); // [{ sub, name, email, avatarUrl | null }]
|
|
211
|
+
const sub = await lookupSubByEmail(dir, "ada@example.com"); // sub | null
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
- Unknown subs are absent from the result; duplicates are sent once; lists over 100 are
|
|
215
|
+
split into several calls (a failing call rejects the whole lookup).
|
|
216
|
+
- `lookupSubByEmail` matches a verified email exactly, case-insensitively.
|
|
217
|
+
- A refused credential throws `PeopleDirectoryRefusedError` (or `ServiceTokenRefusedError`
|
|
218
|
+
from the token exchange); an unreachable flytedesk ID, 5xx, 429 or bad body throws
|
|
219
|
+
`IdpUnavailableError` (`IdpTimeoutError` on timeout). A failure never returns `[]` or `null`.
|
|
220
|
+
|
|
188
221
|
### What an app must not build
|
|
189
222
|
|
|
190
223
|
Everything below is app-kit's:
|
|
@@ -618,6 +651,109 @@ The job's MCP tools module (`app-kit-chat-mcp --tools <path>`) need not register
|
|
|
618
651
|
tool: a module that builds `kit.createChatMcpProtocol({ serverName, tools })` with only
|
|
619
652
|
its own tools is served as it is.
|
|
620
653
|
|
|
654
|
+
## Flytebot (`@flytedesk/app-kit/flytebot`)
|
|
655
|
+
|
|
656
|
+
Flytebot is the service that runs flytedesk's agents and structured LLM calls. An app
|
|
657
|
+
reaches it with a Google ID token of its Cloud Run service account (audience: Flytebot's
|
|
658
|
+
origin); no shared secret exists. Wire types come from `@flytedesk/flytebot-contracts`.
|
|
659
|
+
|
|
660
|
+
```ts
|
|
661
|
+
import { createFlytebotClient, parseFlytebotEnv, verifyTerminalWebhook } from "@flytedesk/app-kit/flytebot";
|
|
662
|
+
|
|
663
|
+
const env = parseFlytebotEnv(process.env); // FLYTEBOT_URL, FLYTEBOT_SERVICE_ACCOUNT
|
|
664
|
+
const flytebot = createFlytebotClient({
|
|
665
|
+
baseUrl: env.flytebotUrl,
|
|
666
|
+
timeoutMs: 15_000,
|
|
667
|
+
retries: 3, // network failures, timeouts, 5xx and 429, with the SAME idempotency key
|
|
668
|
+
// idToken: (audience) => ..., // default: google-auth-library; inject one in tests
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
// one structured answer (an `llm` profile), validated against your zod schema
|
|
672
|
+
const { output, usage, costUsd } = await flytebot.llm.generate(
|
|
673
|
+
{ profile: "goal-judgment", messages, actor },
|
|
674
|
+
outputZodSchema,
|
|
675
|
+
);
|
|
676
|
+
|
|
677
|
+
// an agent run; the key is your own row id, so a retried launch never starts a second run
|
|
678
|
+
const { run } = await flytebot.runs.create({
|
|
679
|
+
profile: "audience-chat",
|
|
680
|
+
conversation: { externalRef: conversationId },
|
|
681
|
+
task,
|
|
682
|
+
actor,
|
|
683
|
+
tools: { "sms-app-chat": { bearer } }, // the per-run bearer for your MCP server
|
|
684
|
+
webhook: { url },
|
|
685
|
+
idempotencyKey: dispatchId,
|
|
686
|
+
});
|
|
687
|
+
for await (const event of flytebot.runs.stream(run.id, { signal })) {
|
|
688
|
+
// in order, once each; reconnects with Last-Event-ID; ends after the terminal event
|
|
689
|
+
}
|
|
690
|
+
await flytebot.runs.get(run.id);
|
|
691
|
+
await flytebot.runs.usage(run.id);
|
|
692
|
+
await flytebot.runs.cancel(run.id, "user pressed stop"); // idempotent
|
|
693
|
+
await flytebot.profiles.get("planner-chat"); // model and effort pickers
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
Every failure is a `FlytebotError` with `code` (the service's error code, or
|
|
697
|
+
`network_error`, `timeout`, `aborted`, `invalid_response`), `httpStatus` (null when no
|
|
698
|
+
response arrived), `retryable` and `requestId`. A `409 conversation_busy` carries
|
|
699
|
+
`details.activeRunId`.
|
|
700
|
+
|
|
701
|
+
The terminal webhook route verifies the call before it trusts the body:
|
|
702
|
+
|
|
703
|
+
```ts
|
|
704
|
+
const run = await verifyTerminalWebhook(request, {
|
|
705
|
+
flytebotServiceAccount: env.flytebotServiceAccount,
|
|
706
|
+
audienceOrigin: "https://my-app.flytedesk.com", // the origin of the webhook URL you gave Flytebot
|
|
707
|
+
});
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
It accepts only a Google-signed, unexpired ID token addressed to `audienceOrigin` whose
|
|
711
|
+
verified email is the Flytebot service account; anything else throws a
|
|
712
|
+
`FlytebotError` with code `unauthenticated` (answer 401). The route must be idempotent on
|
|
713
|
+
`(run.id, run.status)`: delivery is at-least-once.
|
|
714
|
+
|
|
715
|
+
### Testing against the fake
|
|
716
|
+
|
|
717
|
+
`@flytedesk/app-kit/flytebot/testing` is an in-process Flytebot that speaks the contract:
|
|
718
|
+
|
|
719
|
+
```ts
|
|
720
|
+
const fake = createFakeFlytebot();
|
|
721
|
+
await fake.start();
|
|
722
|
+
const flytebot = createFlytebotClient({ baseUrl: fake.url, idToken: async () => "t", timeoutMs: 1_000, retries: 2 });
|
|
723
|
+
|
|
724
|
+
fake.scriptRun({ events: [{ type: "text", messageId: "m1", delta: "hi" }], terminal: { status: "timeout" } });
|
|
725
|
+
fake.scriptRun({ hold: true }); // stays running: fake.emit(runId, ...) then fake.finish(runId)
|
|
726
|
+
fake.scriptRun({ events, dropStreamAfter: 3 }); // cuts the first stream to exercise reconnect
|
|
727
|
+
fake.failNext({ match: "POST /v1/runs", code: "unavailable" }); // a 503, then success
|
|
728
|
+
fake.setLlm("goal-judgment", { output: { achieved: true } });
|
|
729
|
+
fake.requests; // every request, with headers and parsed body
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
Any terminal status and any error code can be scripted; it also enforces one active run per
|
|
733
|
+
conversation and replays an idempotency key.
|
|
734
|
+
|
|
735
|
+
### Serving your tools to Flytebot (`@flytedesk/app-kit/chat/tools`)
|
|
736
|
+
|
|
737
|
+
`createRemoteMcpPlugin` serves your `AppRegisteredTool`s (and `createReplyTool`, unchanged)
|
|
738
|
+
over MCP streamable HTTP from your own API process. `authenticate` runs on every request and
|
|
739
|
+
returns your context for the bearer, or `null` (401); `tools(context)` builds that request's
|
|
740
|
+
tools, so a handler sees the context through its closure.
|
|
741
|
+
|
|
742
|
+
```ts
|
|
743
|
+
await app.register(
|
|
744
|
+
createRemoteMcpPlugin({
|
|
745
|
+
serverName: "sms-app-chat",
|
|
746
|
+
authenticate: async (bearer) => findRunningTurnByToken(bearer),
|
|
747
|
+
tools: (turn) => [createReplyTool({ description, deliver: (reply) => recordReply(turn, reply) })],
|
|
748
|
+
}),
|
|
749
|
+
{ prefix: "/mcp/chat" },
|
|
750
|
+
);
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
A handler that throws is logged and reported to the agent as a tool error (`Tool "x"
|
|
754
|
+
failed.`); a validation error you return as `{ ok: false, retryable: false }` is read by the
|
|
755
|
+
model, and a retryable one is a JSON-RPC error.
|
|
756
|
+
|
|
621
757
|
## Tests
|
|
622
758
|
|
|
623
759
|
`npm run check` is the full gate: lint, typecheck, build, unit tests, integration tests
|
package/dist/auth/errors.d.ts
CHANGED
|
@@ -54,6 +54,16 @@ export declare class ServiceTokenRefusedError extends IdpError {
|
|
|
54
54
|
/** The body's `error_description`, when it carried one. */
|
|
55
55
|
description: string | undefined);
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* flytedesk ID's people directory (`/apps/:appId/people/...`) refused a call with a 4xx
|
|
59
|
+
* other than 429: 401 (no or a bad service access token) or 403 (a person's token, the
|
|
60
|
+
* wrong `aud`, or the app permission `people.lookup` missing). A verdict about this
|
|
61
|
+
* caller, not an outage: retrying the same call will not help.
|
|
62
|
+
*/
|
|
63
|
+
export declare class PeopleDirectoryRefusedError extends IdpError {
|
|
64
|
+
readonly status: number;
|
|
65
|
+
constructor(message: string, status: number);
|
|
66
|
+
}
|
|
57
67
|
/** The injected AuthStore (findIdpSession/updateIdpSession/deleteIdpSession/...) threw —
|
|
58
68
|
* a storage-layer failure (DB down, constraint violation, ...), never to be confused
|
|
59
69
|
* with "no session found" (which is a legitimate, expected outcome, not an error). */
|
package/dist/auth/errors.js
CHANGED
|
@@ -71,6 +71,20 @@ export class ServiceTokenRefusedError extends IdpError {
|
|
|
71
71
|
this.name = "ServiceTokenRefusedError";
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* flytedesk ID's people directory (`/apps/:appId/people/...`) refused a call with a 4xx
|
|
76
|
+
* other than 429: 401 (no or a bad service access token) or 403 (a person's token, the
|
|
77
|
+
* wrong `aud`, or the app permission `people.lookup` missing). A verdict about this
|
|
78
|
+
* caller, not an outage: retrying the same call will not help.
|
|
79
|
+
*/
|
|
80
|
+
export class PeopleDirectoryRefusedError extends IdpError {
|
|
81
|
+
status;
|
|
82
|
+
constructor(message, status) {
|
|
83
|
+
super(message);
|
|
84
|
+
this.status = status;
|
|
85
|
+
this.name = "PeopleDirectoryRefusedError";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
74
88
|
/** The injected AuthStore (findIdpSession/updateIdpSession/deleteIdpSession/...) threw —
|
|
75
89
|
* a storage-layer failure (DB down, constraint violation, ...), never to be confused
|
|
76
90
|
* with "no session found" (which is a legitimate, expected outcome, not an error). */
|
package/dist/auth/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/auth/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,mFAAmF;AACnF,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGf;IAFlB,YACE,OAAe,EACC,KAAe;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,UAAK,GAAL,KAAK,CAAU;QAG/B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED;;sBAEsB;AACtB,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;IAC/C,YAAY,OAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAgB,SAAQ,mBAAmB;IACtD,YAAY,OAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IA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C"}
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -57,3 +57,4 @@ export { AUTH_REQUEST_DEADLINE_MS, AUTH_ROUTE_PREFIX, AUTH_ROUTE_SEGMENTS, AUTH_
|
|
|
57
57
|
export { IdpError, IdpUnavailableError, IdpTimeoutError, IdpAccessRevokedError, AuthStoreError, OidcHttpError, OidcTokenError, ServiceTokenRefusedError, classifyIdpError, } from "./errors.js";
|
|
58
58
|
export { generatePkce, randomState, type PkcePair } from "./pkce.js";
|
|
59
59
|
export { generateRefreshToken, hashRefreshToken, signAccessToken, verifyAccessToken, type AccessTokenClaims, } from "./tokens.js";
|
|
60
|
+
export { lookupPeopleBySubs, lookupSubByEmail, PEOPLE_LOOKUP_BATCH_SIZE, PeopleDirectoryRefusedError, type DirectoryPerson, type PeopleDirectoryOptions, } from "./people/lookup.js";
|
package/dist/auth/index.js
CHANGED
|
@@ -54,4 +54,5 @@ export { AUTH_REQUEST_DEADLINE_MS, AUTH_ROUTE_PREFIX, AUTH_ROUTE_SEGMENTS, AUTH_
|
|
|
54
54
|
export { IdpError, IdpUnavailableError, IdpTimeoutError, IdpAccessRevokedError, AuthStoreError, OidcHttpError, OidcTokenError, ServiceTokenRefusedError, classifyIdpError, } from "./errors.js";
|
|
55
55
|
export { generatePkce, randomState } from "./pkce.js";
|
|
56
56
|
export { generateRefreshToken, hashRefreshToken, signAccessToken, verifyAccessToken, } from "./tokens.js";
|
|
57
|
+
export { lookupPeopleBySubs, lookupSubByEmail, PEOPLE_LOOKUP_BATCH_SIZE, PeopleDirectoryRefusedError, } from "./people/lookup.js";
|
|
57
58
|
//# sourceMappingURL=index.js.map
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,OAAO,EAAE,YAAY,EAAE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AAc,EACd,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAiB,MAAM,WAAW,CAAC;AAErE,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAElB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,2BAA2B,GAG5B,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ServiceTokenSource } from "../service/index.js";
|
|
2
|
+
export { PeopleDirectoryRefusedError } from "../errors.js";
|
|
3
|
+
/** The directory accepts 1 to 100 subs per call. */
|
|
4
|
+
export declare const PEOPLE_LOOKUP_BATCH_SIZE = 100;
|
|
5
|
+
export interface DirectoryPerson {
|
|
6
|
+
sub: string;
|
|
7
|
+
name: string;
|
|
8
|
+
email: string;
|
|
9
|
+
avatarUrl: string | null;
|
|
10
|
+
}
|
|
11
|
+
export interface PeopleDirectoryOptions {
|
|
12
|
+
/** flytedesk ID's issuer URL (no trailing slash). */
|
|
13
|
+
issuer: string;
|
|
14
|
+
/** The flytedesk ID app id the service tokens are for. */
|
|
15
|
+
appId: string;
|
|
16
|
+
/** The app's service token source (`createServiceTokenSource`). */
|
|
17
|
+
tokens: ServiceTokenSource;
|
|
18
|
+
/** Default `globalThis.fetch`. */
|
|
19
|
+
fetch?: typeof fetch;
|
|
20
|
+
/** Bounds each request. Default `DEFAULT_IDP_REQUEST_TIMEOUT_MS` (5s). */
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Name, email and avatar for each known `sub`; unknown subs are absent. Duplicate subs
|
|
25
|
+
* are sent once; more than 100 are split into several calls. Throws
|
|
26
|
+
* `PeopleDirectoryRefusedError` (credential refused), `IdpTimeoutError` /
|
|
27
|
+
* `IdpUnavailableError` (flytedesk ID unreachable, 5xx, 429, bad body), or
|
|
28
|
+
* `ServiceTokenRefusedError` from the token source; a failing batch rejects the whole call.
|
|
29
|
+
*/
|
|
30
|
+
export declare function lookupPeopleBySubs(options: PeopleDirectoryOptions, subs: readonly string[]): Promise<DirectoryPerson[]>;
|
|
31
|
+
/** The `sub` of the person with this verified email (exact, case-insensitive), or null. */
|
|
32
|
+
export declare function lookupSubByEmail(options: PeopleDirectoryOptions, email: string): Promise<string | null>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side lookups in flytedesk ID's people directory (FD-247), called as the app's
|
|
3
|
+
* own service principal: `POST {issuer}/apps/:appId/people/lookup` (subs -> name, email,
|
|
4
|
+
* avatar) and `POST {issuer}/apps/:appId/people/by-email` (verified email -> sub).
|
|
5
|
+
* The caller supplies the `ServiceTokenSource` from `@flytedesk/app-kit/auth/service`
|
|
6
|
+
* (its principal needs the app permission `people.lookup`). Never imports Fastify.
|
|
7
|
+
*/
|
|
8
|
+
import { IdpUnavailableError, PeopleDirectoryRefusedError, } from "../errors.js";
|
|
9
|
+
import { DEFAULT_IDP_REQUEST_TIMEOUT_MS, idpFetch } from "../idpFetch.js";
|
|
10
|
+
export { PeopleDirectoryRefusedError } from "../errors.js";
|
|
11
|
+
/** The directory accepts 1 to 100 subs per call. */
|
|
12
|
+
export const PEOPLE_LOOKUP_BATCH_SIZE = 100;
|
|
13
|
+
async function post(options, route, body) {
|
|
14
|
+
if (options.issuer.length === 0 || options.issuer.endsWith("/")) {
|
|
15
|
+
throw new Error(`people directory: issuer must have no trailing slash, got ${JSON.stringify(options.issuer)}`);
|
|
16
|
+
}
|
|
17
|
+
const path = `/apps/${encodeURIComponent(options.appId)}/people/${route}`;
|
|
18
|
+
const res = await idpFetch(`${options.issuer}${path}`, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
Accept: "application/json",
|
|
23
|
+
Authorization: `Bearer ${await options.tokens.accessToken()}`,
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify(body),
|
|
26
|
+
}, path, options.timeoutMs ?? DEFAULT_IDP_REQUEST_TIMEOUT_MS, options.fetch);
|
|
27
|
+
if (res.status >= 400 && res.status < 500 && res.status !== 429) {
|
|
28
|
+
throw new PeopleDirectoryRefusedError(`flytedesk-id refused ${path} (${res.status})`, res.status);
|
|
29
|
+
}
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
throw new IdpUnavailableError(`flytedesk-id ${path} returned ${res.status}`);
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
return await res.json();
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
throw new IdpUnavailableError(`flytedesk-id ${path} answered a body that is not JSON`, err);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function malformed(path) {
|
|
41
|
+
return new IdpUnavailableError(`flytedesk-id people/${path} answered an unexpected body`);
|
|
42
|
+
}
|
|
43
|
+
function parsePerson(value) {
|
|
44
|
+
const p = value;
|
|
45
|
+
if (typeof p !== "object" || p === null ||
|
|
46
|
+
typeof p.sub !== "string" || typeof p.name !== "string" || typeof p.email !== "string" ||
|
|
47
|
+
!(p.avatarUrl === null || typeof p.avatarUrl === "string")) {
|
|
48
|
+
throw malformed("lookup");
|
|
49
|
+
}
|
|
50
|
+
return { sub: p.sub, name: p.name, email: p.email, avatarUrl: p.avatarUrl };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Name, email and avatar for each known `sub`; unknown subs are absent. Duplicate subs
|
|
54
|
+
* are sent once; more than 100 are split into several calls. Throws
|
|
55
|
+
* `PeopleDirectoryRefusedError` (credential refused), `IdpTimeoutError` /
|
|
56
|
+
* `IdpUnavailableError` (flytedesk ID unreachable, 5xx, 429, bad body), or
|
|
57
|
+
* `ServiceTokenRefusedError` from the token source; a failing batch rejects the whole call.
|
|
58
|
+
*/
|
|
59
|
+
export async function lookupPeopleBySubs(options, subs) {
|
|
60
|
+
const unique = [...new Set(subs)];
|
|
61
|
+
const people = [];
|
|
62
|
+
for (let i = 0; i < unique.length; i += PEOPLE_LOOKUP_BATCH_SIZE) {
|
|
63
|
+
const body = await post(options, "lookup", { subs: unique.slice(i, i + PEOPLE_LOOKUP_BATCH_SIZE) });
|
|
64
|
+
const list = body?.people;
|
|
65
|
+
if (!Array.isArray(list))
|
|
66
|
+
throw malformed("lookup");
|
|
67
|
+
people.push(...list.map(parsePerson));
|
|
68
|
+
}
|
|
69
|
+
return people;
|
|
70
|
+
}
|
|
71
|
+
/** The `sub` of the person with this verified email (exact, case-insensitive), or null. */
|
|
72
|
+
export async function lookupSubByEmail(options, email) {
|
|
73
|
+
const body = await post(options, "by-email", { email });
|
|
74
|
+
const sub = body?.sub;
|
|
75
|
+
if (sub === null)
|
|
76
|
+
return null;
|
|
77
|
+
if (typeof sub !== "string")
|
|
78
|
+
throw malformed("by-email");
|
|
79
|
+
return sub;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup.js","sourceRoot":"","sources":["../../../src/auth/people/lookup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAEL,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,8BAA8B,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3D,oDAAoD;AACpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAsB5C,KAAK,UAAU,IAAI,CAAC,OAA+B,EAAE,KAAa,EAAE,IAAa;IAC/E,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAChE,MAAM,IAA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AC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC;QACpD,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,2FAA2F;AAC3F,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAA+B,EAAE,KAAa;IACnF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACxD,MAAM,GAAG,GAAI,IAAiC,EAAE,GAAG,CAAC;IACpD,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,MAAM,SAAS,CAAC,UAAU,CAAC,CAAC;IACzD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* used, never a generated client: each app passes its own `PrismaClient` generated from
|
|
8
8
|
* a schema holding `prisma/fragments/auth.prisma` (installed with `auth-sync init`).
|
|
9
9
|
*/
|
|
10
|
+
import { REVOCATION_REASONS } from "../revocationReasons.js";
|
|
10
11
|
import { acquireAdvisoryLock } from "../../postgres/index.js";
|
|
11
12
|
/** How long a lock (the IdP-session lock or the refresh-token-family lock) may wait for a
|
|
12
13
|
* competing holder before failing with Postgres 55P03 — comfortably under the
|
|
@@ -32,12 +33,6 @@ const AUTH_STORE_TRANSACTION_OPTIONS = {
|
|
|
32
33
|
};
|
|
33
34
|
const REFRESH_TOKEN_FAMILY_LOCK_NAMESPACE = "refresh-token-family";
|
|
34
35
|
const IDP_SESSION_LOCK_NAMESPACE = "idp-session";
|
|
35
|
-
const REVOCATION_REASONS = [
|
|
36
|
-
"rotated",
|
|
37
|
-
"reuse_detected",
|
|
38
|
-
"signed_out",
|
|
39
|
-
"authorization_rejected",
|
|
40
|
-
];
|
|
41
36
|
/** `IdpSessionLockedStore` bound to whichever client `db` is — the lock's own transaction
|
|
42
37
|
* inside `withIdpSessionLock`, so a lock holder never needs a second pooled connection. */
|
|
43
38
|
function idpSessionStoreOn(db) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prismaAuthStore.js","sourceRoot":"","sources":["../../../src/auth/prisma/prismaAuthStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAa9D;;gFAEgF;AAChF,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;;;;;;;;;;;GAaG;AACH,MAAM,8BAA8B,GAAG;IACrC,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,KAAK;CACN,CAAC;AAEX,MAAM,mCAAmC,GAAG,sBAAsB,CAAC;AACnE,MAAM,0BAA0B,GAAG,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"prismaAuthStore.js","sourceRoot":"","sources":["../../../src/auth/prisma/prismaAuthStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAa9D;;gFAEgF;AAChF,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;;;;;;;;;;;GAaG;AACH,MAAM,8BAA8B,GAAG;IACrC,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,KAAK;CACN,CAAC;AAEX,MAAM,mCAAmC,GAAG,sBAAsB,CAAC;AACnE,MAAM,0BAA0B,GAAG,aAAa,CAAC;AAwGjD;4FAC4F;AAC5F,SAAS,iBAAiB,CAAC,EAE1B;IACC,OAAO;QACL,KAAK,CAAC,cAAc,CAAC,EAAU;YAC7B,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,K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AAO,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC;QACnC,CAAC,EAAE,8BAA8B,CAAC,CAAC;IACrC,CAAC;CACF;AAED,SAAS,gBAAgB,CACvB,GAA4B,EAC5B,UAAyB;IAEzB,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,UAAU;KACX,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CACjB,EAAyB,EACzB,QAAgB;IAEhB,OAAO,mBAAmB,CACxB,EAAE,EACF,EAAE,SAAS,EAAE,mCAAmC,EAAE,EAAE,EAAE,QAAQ,EAAE,EAChE,eAAe,CAChB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The one list of values `revoked_reason` may hold (AK-63): `PrismaAuthStore` validates
|
|
2
|
+
* reads against it and the fragment's CHECK constraint and `auth-sync adopt` are built
|
|
3
|
+
* from it. */
|
|
4
|
+
export const REVOCATION_REASONS = [
|
|
5
|
+
"rotated",
|
|
6
|
+
"reuse_detected",
|
|
7
|
+
"signed_out",
|
|
8
|
+
"authorization_rejected",
|
|
9
|
+
];
|
|
10
|
+
//# sourceMappingURL=revocationReasons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revocationReasons.js","sourceRoot":"","sources":["../../src/auth/revocationReasons.ts"],"names":[],"mappings":"AAEA;;eAEe;AACf,MAAM,CAAC,MAAM,kBAAkB,GAAsB;IACnD,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,wBAAwB;CACgB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@flytedesk/app-kit/chat/tools`: serve an app's agent tools to Flytebot over MCP
|
|
3
|
+
* streamable HTTP (PLAN-10 architecture section 6), from the app's own API process.
|
|
4
|
+
*
|
|
5
|
+
* Flytebot's runner calls this endpoint with the per-run bearer the app sent in
|
|
6
|
+
* `runs.create({ tools })`. The plugin authenticates that bearer on every request, builds
|
|
7
|
+
* the tool list for the context it resolves to, and hands the JSON-RPC message to the same
|
|
8
|
+
* `createChatMcpProtocol` the stdio server uses: `AppRegisteredTool` and `createReplyTool`
|
|
9
|
+
* are reused unchanged, only the transport is new.
|
|
10
|
+
*
|
|
11
|
+
* await app.register(
|
|
12
|
+
* createRemoteMcpPlugin({
|
|
13
|
+
* serverName: "sms-app-chat",
|
|
14
|
+
* authenticate: async (bearer) => findRunningTurnByToken(bearer), // context or null
|
|
15
|
+
* tools: (turn) => [createReplyTool({ description, deliver: (reply) => recordReply(turn, reply) })],
|
|
16
|
+
* }),
|
|
17
|
+
* { prefix: "/mcp/chat" },
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* The context reaches a tool through the closure `tools(context)` builds, so a handler
|
|
21
|
+
* never reads a bearer or a global.
|
|
22
|
+
*/
|
|
23
|
+
import type { FastifyPluginAsync } from "fastify";
|
|
24
|
+
import type { AppRegisteredTool } from "../types.js";
|
|
25
|
+
export interface RemoteMcpPluginOptions<Context> {
|
|
26
|
+
/** Advertised in `initialize`'s `serverInfo.name`; also the key the app gives `runs.create({ tools })`. */
|
|
27
|
+
serverName: string;
|
|
28
|
+
serverVersion?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve a bearer to the app's context for that run, or null when the bearer is not a
|
|
31
|
+
* live run's (the request is then refused 401 before any tool runs). Called on every
|
|
32
|
+
* request. A throw is a server error, never an allow.
|
|
33
|
+
*/
|
|
34
|
+
authenticate: (bearer: string) => Context | null | Promise<Context | null>;
|
|
35
|
+
/** The tools this request's context may call. */
|
|
36
|
+
tools: (context: Context) => AppRegisteredTool[];
|
|
37
|
+
}
|
|
38
|
+
export declare function createRemoteMcpPlugin<Context>(options: RemoteMcpPluginOptions<Context>): FastifyPluginAsync;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createChatMcpProtocol } from "../mcp-protocol.js";
|
|
2
|
+
const INVALID_REQUEST = -32600;
|
|
3
|
+
export function createRemoteMcpPlugin(options) {
|
|
4
|
+
return async (fastify) => {
|
|
5
|
+
fastify.post("/", async (request, reply) => {
|
|
6
|
+
const match = /^Bearer (\S+)$/i.exec(request.headers.authorization ?? "");
|
|
7
|
+
const context = match === null ? null : await options.authenticate(match[1]);
|
|
8
|
+
if (context === null) {
|
|
9
|
+
return reply
|
|
10
|
+
.code(401)
|
|
11
|
+
.header("www-authenticate", "Bearer")
|
|
12
|
+
.send({ error: "unauthorized" });
|
|
13
|
+
}
|
|
14
|
+
const message = request.body;
|
|
15
|
+
if (message === null || typeof message !== "object" || Array.isArray(message)) {
|
|
16
|
+
return reply.code(400).send({
|
|
17
|
+
jsonrpc: "2.0",
|
|
18
|
+
id: null,
|
|
19
|
+
error: { code: INVALID_REQUEST, message: "The body must be one JSON-RPC message object." },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
// A tool that throws is reported to the model as a tool error and logged here, so
|
|
23
|
+
// an internal message never reaches the agent and one bad tool never drops the endpoint.
|
|
24
|
+
const tools = options.tools(context).map((tool) => ({
|
|
25
|
+
...tool,
|
|
26
|
+
async handler(args) {
|
|
27
|
+
try {
|
|
28
|
+
return await tool.handler(args);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
request.log.error({ err: error, tool: tool.name }, "MCP tool handler threw");
|
|
32
|
+
return {
|
|
33
|
+
ok: false,
|
|
34
|
+
retryable: false,
|
|
35
|
+
message: `Tool "${tool.name}" failed.`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
}));
|
|
40
|
+
const response = await createChatMcpProtocol({
|
|
41
|
+
serverName: options.serverName,
|
|
42
|
+
serverVersion: options.serverVersion,
|
|
43
|
+
tools,
|
|
44
|
+
}).handleMessage(message);
|
|
45
|
+
if (response === null)
|
|
46
|
+
return reply.code(202).send();
|
|
47
|
+
return reply.send(response);
|
|
48
|
+
});
|
|
49
|
+
// Streamable HTTP lets a server decline the optional GET (server-initiated stream)
|
|
50
|
+
// and DELETE (session end); this server is stateless, so it does.
|
|
51
|
+
for (const method of ["GET", "DELETE"]) {
|
|
52
|
+
fastify.route({
|
|
53
|
+
method,
|
|
54
|
+
url: "/",
|
|
55
|
+
handler: async (_request, reply) => reply.code(405).header("allow", "POST").send({ error: "method_not_allowed" }),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/chat/tools/index.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAiB3D,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC;AAE/B,MAAM,UAAU,qBAAqB,CACnC,OAAwC;IAExC,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;YACzC,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;YAC1E,MAAM,OAAO,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;YAC9E,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBACrB,OAAO,KAAK;qBACT,IAA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AC,UAAU;gBAC9B,aAAa,EAAE,OAAO,CAAC,aAAa;gBACpC,KAAK;aACN,CAAC,CAAC,aAAa,CAAC,OAAkC,CAAC,CAAC;YAErD,IAAI,QAAQ,KAAK,IAAI;gBAAE,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YACrD,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,mFAAmF;QACnF,kEAAkE;QAClE,KAAK,MAAM,MAAM,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAU,EAAE,CAAC;YAChD,OAAO,CAAC,KAAK,CAAC;gBACZ,MAAM;gBACN,GAAG,EAAE,GAAG;gBACR,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,CACjC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC;aAChF,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the app's existing tables and columns are, keyed by the FRAGMENT's names:
|
|
3
|
+
* `tables` names every fragment table's current name; `columns[<fragment table>]` maps a
|
|
4
|
+
* fragment column to the app's column only where the two differ.
|
|
5
|
+
*/
|
|
6
|
+
export interface AdoptMapping {
|
|
7
|
+
tables: Record<string, string>;
|
|
8
|
+
columns?: Record<string, Record<string, string>>;
|
|
9
|
+
}
|
|
10
|
+
/** Reads and validates the mapping file; every problem is a thrown Error naming it. */
|
|
11
|
+
export declare function readAdoptMapping(file: string): AdoptMapping;
|
|
12
|
+
/** The migration SQL for `mapping`: the app's tables become the fragment's. */
|
|
13
|
+
export declare function buildAdoptSql(mapping: AdoptMapping): string;
|