@flytedesk/app-kit 11.3.0 → 11.5.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.
Files changed (72) hide show
  1. package/README.md +128 -0
  2. package/dist/auth/guards.d.ts +4 -0
  3. package/dist/auth/guards.js +22 -0
  4. package/dist/auth/guards.js.map +1 -1
  5. package/dist/auth/index.d.ts +1 -1
  6. package/dist/auth/index.js +1 -1
  7. package/dist/auth/index.js.map +1 -1
  8. package/dist/auth/prisma/index.d.ts +1 -0
  9. package/dist/auth/prisma/index.js +2 -0
  10. package/dist/auth/prisma/index.js.map +1 -0
  11. package/dist/auth/prisma/prismaAuthStore.d.ts +181 -0
  12. package/dist/auth/prisma/prismaAuthStore.js +273 -0
  13. package/dist/auth/prisma/prismaAuthStore.js.map +1 -0
  14. package/dist/chat/tools/index.d.ts +38 -0
  15. package/dist/chat/tools/index.js +60 -0
  16. package/dist/chat/tools/index.js.map +1 -0
  17. package/dist/cli/auth-sync.d.ts +2 -0
  18. package/dist/cli/auth-sync.js +23 -0
  19. package/dist/cli/auth-sync.js.map +1 -0
  20. package/dist/flytebot/client.d.ts +66 -0
  21. package/dist/flytebot/client.js +377 -0
  22. package/dist/flytebot/client.js.map +1 -0
  23. package/dist/flytebot/env.d.ts +11 -0
  24. package/dist/flytebot/env.js +25 -0
  25. package/dist/flytebot/env.js.map +1 -0
  26. package/dist/flytebot/error.d.ts +36 -0
  27. package/dist/flytebot/error.js +60 -0
  28. package/dist/flytebot/error.js.map +1 -0
  29. package/dist/flytebot/index.d.ts +32 -0
  30. package/dist/flytebot/index.js +28 -0
  31. package/dist/flytebot/index.js.map +1 -0
  32. package/dist/flytebot/sse.d.ts +11 -0
  33. package/dist/flytebot/sse.js +55 -0
  34. package/dist/flytebot/sse.js.map +1 -0
  35. package/dist/flytebot/testing/fake.d.ts +77 -0
  36. package/dist/flytebot/testing/fake.js +399 -0
  37. package/dist/flytebot/testing/fake.js.map +1 -0
  38. package/dist/flytebot/testing/index.d.ts +18 -0
  39. package/dist/flytebot/testing/index.js +18 -0
  40. package/dist/flytebot/testing/index.js.map +1 -0
  41. package/dist/flytebot/webhook.d.ts +24 -0
  42. package/dist/flytebot/webhook.js +63 -0
  43. package/dist/flytebot/webhook.js.map +1 -0
  44. package/dist/repo-check/checkNarration.d.ts +13 -0
  45. package/dist/repo-check/checkNarration.js +346 -0
  46. package/dist/repo-check/checkNarration.js.map +1 -0
  47. package/dist/repo-check/checkNoNul.d.ts +3 -0
  48. package/dist/repo-check/checkNoNul.js +35 -0
  49. package/dist/repo-check/checkNoNul.js.map +1 -0
  50. package/dist/repo-check/cli.d.ts +9 -0
  51. package/dist/repo-check/cli.js +103 -0
  52. package/dist/repo-check/cli.js.map +1 -0
  53. package/dist/repo-check/config.d.ts +13 -0
  54. package/dist/repo-check/config.js +39 -0
  55. package/dist/repo-check/config.js.map +1 -0
  56. package/dist/repo-check/repoFiles.d.ts +8 -0
  57. package/dist/repo-check/repoFiles.js +44 -0
  58. package/dist/repo-check/repoFiles.js.map +1 -0
  59. package/dist/repo-check/repoHygiene.d.ts +5 -0
  60. package/dist/repo-check/repoHygiene.js +12 -0
  61. package/dist/repo-check/repoHygiene.js.map +1 -0
  62. package/dist/repo-check/scriptComments.d.ts +28 -0
  63. package/dist/repo-check/scriptComments.js +243 -0
  64. package/dist/repo-check/scriptComments.js.map +1 -0
  65. package/dist/spa-server/index.d.ts +25 -0
  66. package/dist/spa-server/index.js +35 -2
  67. package/dist/spa-server/index.js.map +1 -1
  68. package/package.json +26 -3
  69. package/prisma/fragments/auth.meta.json +4 -0
  70. package/prisma/fragments/auth.prisma +75 -0
  71. package/prisma/migrations/0004_app_kit_auth_init/migration.sql +47 -0
  72. package/prisma/migrations/manifest.json +7 -0
@@ -0,0 +1,273 @@
1
+ /**
2
+ * `PrismaAuthStore` (AK-59): the one Prisma implementation of the `AuthStore` seam — the
3
+ * security-critical rotation, family revocation and locking logic every flytedesk ID app
4
+ * used to copy (sms-app's `authStore.ts` was the reference, Flytebot copied it verbatim).
5
+ *
6
+ * Typed against `PrismaAuthClient`, a structural client of just the models and methods
7
+ * used, never a generated client: each app passes its own `PrismaClient` generated from
8
+ * a schema holding `prisma/fragments/auth.prisma` (installed with `auth-sync init`).
9
+ */
10
+ import { acquireAdvisoryLock } from "../../postgres/index.js";
11
+ /** How long a lock (the IdP-session lock or the refresh-token-family lock) may wait for a
12
+ * competing holder before failing with Postgres 55P03 — comfortably under the
13
+ * transaction `timeout` below (which must exceed lock wait + one IdP call). */
14
+ const LOCK_TIMEOUT_MS = 5_000;
15
+ /**
16
+ * Options of every multi-statement transaction this store opens (`rotateRefreshToken`,
17
+ * `revokeFamily`, `withIdpSessionLock`) — defined once so the numbers can never drift.
18
+ *
19
+ * `timeout` bounds how long the transaction's OWN work may run once started: it must
20
+ * exceed `LOCK_TIMEOUT_MS` plus one IdP round trip (`idpRequestTimeoutMs`, default 5s),
21
+ * so a lock holder legitimately waiting on flytedesk-id is never killed by its own timeout.
22
+ *
23
+ * `maxWait` bounds only how long Prisma queues for a free POOLED CONNECTION before the
24
+ * transaction may start — deliberately 5s, not `timeout`'s 15s: a pool under contention
25
+ * (an IdP outage, a pile-up of lock waiters) should fail fast with Prisma's P2028 and
26
+ * let the caller answer 503, rather than queue 25+ requests 15s deep for a connection
27
+ * that may never free up in time to matter.
28
+ */
29
+ const AUTH_STORE_TRANSACTION_OPTIONS = {
30
+ timeout: 15_000,
31
+ maxWait: 5_000,
32
+ };
33
+ const REFRESH_TOKEN_FAMILY_LOCK_NAMESPACE = "refresh-token-family";
34
+ const IDP_SESSION_LOCK_NAMESPACE = "idp-session";
35
+ const REVOCATION_REASONS = [
36
+ "rotated",
37
+ "reuse_detected",
38
+ "signed_out",
39
+ "authorization_rejected",
40
+ ];
41
+ /** `IdpSessionLockedStore` bound to whichever client `db` is — the lock's own transaction
42
+ * inside `withIdpSessionLock`, so a lock holder never needs a second pooled connection. */
43
+ function idpSessionStoreOn(db) {
44
+ return {
45
+ async findIdpSession(id) {
46
+ const row = await db.idpSession.findUnique({ where: { id } });
47
+ if (!row)
48
+ return null;
49
+ return {
50
+ id: row.id,
51
+ subject: row.subject,
52
+ name: row.name,
53
+ email: row.email,
54
+ idpAccessToken: row.idpAccessToken,
55
+ idpAccessTokenExpiresAt: row.idpAccessTokenExpiresAt,
56
+ idpRefreshToken: row.idpRefreshToken,
57
+ idToken: row.idToken,
58
+ };
59
+ },
60
+ async updateIdpSession(id, patch) {
61
+ await db.idpSession.update({
62
+ where: { id },
63
+ data: {
64
+ idpAccessToken: patch.idpAccessToken,
65
+ idpAccessTokenExpiresAt: patch.idpAccessTokenExpiresAt,
66
+ idpRefreshToken: patch.idpRefreshToken,
67
+ },
68
+ });
69
+ },
70
+ };
71
+ }
72
+ function toRevocation(revokedAt, revokedReason) {
73
+ if (!revokedAt)
74
+ return null;
75
+ // The migration's CHECK constraint makes a revoked row without a reason impossible from
76
+ // any write this store makes; reaching it means a write bypassed this store, which must
77
+ // fail loudly rather than guess a reason (there is no safe default).
78
+ if (!revokedReason || !REVOCATION_REASONS.includes(revokedReason)) {
79
+ throw new Error(`RefreshToken revoked at ${revokedAt.toISOString()} carries ${revokedReason === null ? "no revokedReason" : `an unknown revokedReason "${revokedReason}"`}`);
80
+ }
81
+ return {
82
+ at: revokedAt,
83
+ reason: revokedReason,
84
+ };
85
+ }
86
+ function toRefreshTokenRow(row) {
87
+ return {
88
+ id: row.id,
89
+ familyId: row.familyId,
90
+ userId: row.userId,
91
+ idpSessionId: row.idpSessionId,
92
+ expiresAt: row.expiresAt,
93
+ ip: row.ip,
94
+ userAgent: row.userAgent,
95
+ revocation: toRevocation(row.revokedAt, row.revokedReason),
96
+ };
97
+ }
98
+ /** Prisma's "record to delete does not exist" error, recognised by code so this module
99
+ * needs no `@prisma/client` import. */
100
+ function isRecordNotFound(err) {
101
+ return (typeof err === "object" &&
102
+ err !== null &&
103
+ err.code === "P2025");
104
+ }
105
+ /**
106
+ * `withIdpSessionLock` hands its callback a store bound to the SAME transaction the
107
+ * advisory lock lives on; `rotateRefreshToken` is one atomic transaction end to end;
108
+ * `revokeFamily` takes the same per-family lock so it can never race a concurrent
109
+ * rotation. The advisory-lock primitive itself lives in `@flytedesk/app-kit/postgres`.
110
+ */
111
+ export class PrismaAuthStore {
112
+ prisma;
113
+ /** The pooled (unlocked) store — `POST {routePrefix}/refresh`'s initial read runs here,
114
+ * outside any lock; only reads/writes done WHILE holding `withIdpSessionLock` run on
115
+ * that lock's own transaction. */
116
+ pooled;
117
+ constructor(prisma) {
118
+ this.prisma = prisma;
119
+ this.pooled = idpSessionStoreOn(prisma);
120
+ }
121
+ findIdpSession(id) {
122
+ return this.pooled.findIdpSession(id);
123
+ }
124
+ updateIdpSession(id, patch) {
125
+ return this.pooled.updateIdpSession(id, patch);
126
+ }
127
+ async createRefreshToken(row) {
128
+ await this.prisma.refreshToken.create({
129
+ data: refreshTokenData(row, null),
130
+ });
131
+ }
132
+ async findRefreshTokenByHash(hash) {
133
+ const row = await this.prisma.refreshToken.findUnique({
134
+ where: { tokenHash: hash },
135
+ });
136
+ return row ? toRefreshTokenRow(row) : null;
137
+ }
138
+ /**
139
+ * Whether the IdP session is still signed in. Reuse detection and an authorization
140
+ * rejection revoke the family without deleting the session, so the session row existing
141
+ * proves nothing; a live refresh token (not revoked, not expired at `now`, the app's
142
+ * clock) of the session does. A sign-out deletes the session, cascading its tokens.
143
+ */
144
+ async findLiveRefreshTokenForSession(idpSessionId, now) {
145
+ const row = await this.prisma.refreshToken.findFirst({
146
+ where: { idpSessionId, revokedAt: null, expiresAt: { gt: now } },
147
+ orderBy: { createdAt: "desc" },
148
+ });
149
+ return row ? toRefreshTokenRow(row) : null;
150
+ }
151
+ /**
152
+ * One transaction — take the family lock, conditionally revoke `presentedId` with reason
153
+ * "rotated" (claims iff it was still live), and only then insert `successor`. `rotatedAt`
154
+ * (not `new Date()`) is persisted: the ONE-clock rule in `AuthStore`'s doc comment.
155
+ */
156
+ async rotateRefreshToken(presentedId, successor, rotatedAt) {
157
+ return this.prisma.$transaction(async (tx) => {
158
+ await lockFamily(tx, successor.familyId);
159
+ const claimed = await tx.refreshToken.updateMany({
160
+ where: { id: presentedId, revokedAt: null },
161
+ data: { revokedAt: rotatedAt, revokedReason: "rotated" },
162
+ });
163
+ if (claimed.count !== 1)
164
+ return false;
165
+ await tx.refreshToken.create({
166
+ data: refreshTokenData(successor, presentedId),
167
+ });
168
+ return true;
169
+ }, AUTH_STORE_TRANSACTION_OPTIONS);
170
+ }
171
+ /**
172
+ * Takes the SAME per-family lock as `rotateRefreshToken` before revoking, so whichever
173
+ * of a concurrent sign-out/rotation pair runs second sees the other's committed rows
174
+ * (under READ COMMITTED, skipping the lock lets a rotation's successor survive a revoke
175
+ * that started just before it committed). The reuse-detection audit write is in the SAME
176
+ * transaction as the revoke: a reuse is revoked AND audited, or neither.
177
+ */
178
+ async revokeFamily(familyId, reason, revokedAt) {
179
+ await this.prisma.$transaction(async (tx) => {
180
+ await lockFamily(tx, familyId);
181
+ await tx.refreshToken.updateMany({
182
+ where: { familyId, revokedAt: null },
183
+ data: { revokedAt, revokedReason: reason.type },
184
+ });
185
+ // An audit row only for reuse detection — the one reason that is a real, actionable
186
+ // security event (a replayed refresh token); the others are ordinary session
187
+ // lifecycle, already explained by the RefreshToken rows' own revocation.
188
+ if (reason.type === "reuse_detected") {
189
+ const rotation = reason.replayedToken.revocation;
190
+ if (!rotation) {
191
+ // The plugin raises `reuse_detected` only for a row it just read as revoked
192
+ // "rotated"; a null revocation means the row is not what the contract
193
+ // describes, and guessing a timestamp would misrecord a real security event.
194
+ throw new Error(`reuse_detected for family ${familyId}: replayedToken ${reason.replayedToken.id} carries no revocation`);
195
+ }
196
+ await tx.authAuditLog.create({
197
+ data: {
198
+ familyId,
199
+ reason: reason.type,
200
+ // The exact instant `rotateRefreshToken` persisted for this row — never
201
+ // re-derived from `reason.sinceRotatedMs`, which would drift by however long
202
+ // this request took to reach the revoke (and overflows a 32-bit column after
203
+ // ~24.8 idle days).
204
+ rotatedAt: rotation.at,
205
+ ip: reason.ip,
206
+ userAgent: reason.userAgent,
207
+ },
208
+ });
209
+ }
210
+ }, AUTH_STORE_TRANSACTION_OPTIONS);
211
+ }
212
+ async createIdpSession(row) {
213
+ return this.prisma.idpSession.create({
214
+ data: {
215
+ subject: row.subject,
216
+ name: row.name,
217
+ email: row.email,
218
+ idpAccessToken: row.idpAccessToken,
219
+ idpAccessTokenExpiresAt: row.idpAccessTokenExpiresAt,
220
+ idpRefreshToken: row.idpRefreshToken,
221
+ idToken: row.idToken,
222
+ },
223
+ select: { id: true },
224
+ });
225
+ }
226
+ async deleteIdpSession(id) {
227
+ // The row already being gone (P2025 — deleted concurrently, or never existed) is the
228
+ // one expected outcome. Every OTHER failure must reach the caller: the logout route
229
+ // surfaces it (502 `logout_store_failed`) instead of reporting "signed out" while the
230
+ // IdpSession row (and the IdP tokens it holds) leaked.
231
+ try {
232
+ await this.prisma.idpSession.delete({ where: { id } });
233
+ }
234
+ catch (err) {
235
+ if (isRecordNotFound(err))
236
+ return;
237
+ throw err;
238
+ }
239
+ }
240
+ /**
241
+ * `fn` is handed an `IdpSessionLockedStore` bound to the SAME transaction the advisory
242
+ * lock lives on, so a lock holder never needs a second pooled connection: one that had
243
+ * to reach back into the pool would let concurrent stale-session refreshes exhaust it
244
+ * and sign out every session still waiting once their number reached the pool's size.
245
+ *
246
+ * Residual risk (documented on the contract): if `updateIdpSession` or this transaction's
247
+ * commit fails after flytedesk-id already rotated its own refresh token, that new token
248
+ * is lost and the user must sign in again.
249
+ */
250
+ async withIdpSessionLock(sessionId, fn) {
251
+ return this.prisma.$transaction(async (tx) => {
252
+ await acquireAdvisoryLock(tx, { namespace: IDP_SESSION_LOCK_NAMESPACE, id: sessionId }, LOCK_TIMEOUT_MS);
253
+ return fn(idpSessionStoreOn(tx));
254
+ }, AUTH_STORE_TRANSACTION_OPTIONS);
255
+ }
256
+ }
257
+ function refreshTokenData(row, replacesId) {
258
+ return {
259
+ id: row.id,
260
+ familyId: row.familyId,
261
+ userId: row.userId,
262
+ tokenHash: row.tokenHash,
263
+ expiresAt: row.expiresAt,
264
+ idpSessionId: row.idpSessionId,
265
+ userAgent: row.userAgent,
266
+ ip: row.ip,
267
+ replacesId,
268
+ };
269
+ }
270
+ function lockFamily(tx, familyId) {
271
+ return acquireAdvisoryLock(tx, { namespace: REFRESH_TOKEN_FAMILY_LOCK_NAMESPACE, id: familyId }, LOCK_TIMEOUT_MS);
272
+ }
273
+ //# sourceMappingURL=prismaAuthStore.js.map
@@ -0,0 +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;AAEjD,MAAM,kBAAkB,GAAsB;IAC5C,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,wBAAwB;CACgB,CAAC;AAuG3C;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,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC9D,IAAI,CAAC,GAAG;gBAAE,OAAO,IAAI,CAAC;YACtB,OAAO;gBACL,EAAE,EAAE,GAAG,CAAC,EAAE;gBACV,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB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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,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,IAAI,CAAC,GAAG,CAAC;qBACT,MAAM,CAAC,kBAAkB,EAAE,QAAQ,CAAC;qBACpC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;YACrC,CAAC;YAED,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YAC7B,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAA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AAC,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,2 @@
1
+ #!/usr/bin/env node
2
+ export declare function main(argv: string[]): Promise<void>;
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * auth-sync — the CLI half of @flytedesk/app-kit/auth (DEC-39).
4
+ *
5
+ * A thin wrapper around the generalized sync engine in ./sync-engine.js — see that
6
+ * file's doc comment for the full subcommand reference (init/diff/apply/status) and
7
+ * how fragments/migrations/lock files work. This file only supplies the "auth"
8
+ * fragment name and the "auth-sync" bin name; trace-sync.ts/profile-sync.ts are the
9
+ * same wrapper for the trace/profile fragments.
10
+ */
11
+ import { isRunningAsMain, runSyncCli, SyncCliError } from "./sync-engine.js";
12
+ export async function main(argv) {
13
+ return runSyncCli(argv, { name: "auth", binName: "auth-sync" });
14
+ }
15
+ if (isRunningAsMain(import.meta.url)) {
16
+ main(process.argv.slice(2)).catch((err) => {
17
+ if (!(err instanceof SyncCliError)) {
18
+ console.error(err);
19
+ }
20
+ process.exitCode = process.exitCode ?? 1;
21
+ });
22
+ }
23
+ //# sourceMappingURL=auth-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-sync.js","sourceRoot":"","sources":["../../src/cli/auth-sync.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG;AACH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE7E,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAc;IACvC,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;AAClE,CAAC;AAED,IAAI,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACrC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;QACjD,IAAI,CAAC,CAAC,GAAG,YAAY,YAAY,CAAC,EAAE,CAAC;YACnC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { createRunRequest, llmRequest, type CreateRunResponse, type LlmResponse, type ProfileSummary, type Run, type RunEvent, type RunUsageResponse } from "@flytedesk/flytebot-contracts";
2
+ import type { z } from "zod";
3
+ export interface FlytebotClientOptions {
4
+ /** Flytebot's base URL, e.g. "https://flytebot.flytedesk.com". Its origin is the ID-token audience. */
5
+ baseUrl: string;
6
+ /**
7
+ * Returns a Google ID token for `audience`. Default: `google-auth-library` for the
8
+ * Cloud Run service account the process runs as. Inject a function in tests.
9
+ */
10
+ idToken?: (audience: string) => Promise<string>;
11
+ /** Per-request budget, including the response body; for a stream, the wait for the response headers. */
12
+ timeoutMs: number;
13
+ /** Retries after the first attempt, for network failures, timeouts, 5xx and 429. */
14
+ retries: number;
15
+ /** First retry delay; doubles each retry, jittered. A `Retry-After` header wins. Default 250. */
16
+ retryBaseDelayMs?: number;
17
+ /** A stream with no bytes (not even a ping) for this long is dropped and reconnected. Default 45000. */
18
+ streamIdleTimeoutMs?: number;
19
+ /** Default: global `fetch`. */
20
+ fetch?: typeof fetch;
21
+ }
22
+ type CreateRunInput = z.input<typeof createRunRequest> & {
23
+ /** Required: the app's own row id. A retry reuses it, so a launch is never duplicated. */
24
+ idempotencyKey: string;
25
+ };
26
+ export type CreateRunResult = CreateRunResponse & {
27
+ /** True when Flytebot answered with the original response to an earlier request with this key. */
28
+ replayed: boolean;
29
+ };
30
+ export type GenerateResult<T> = Omit<LlmResponse, "output"> & {
31
+ output: T;
32
+ };
33
+ export interface CallOptions {
34
+ signal?: AbortSignal;
35
+ }
36
+ export interface FlytebotClient {
37
+ llm: {
38
+ /** One structured answer from an `llm` profile, validated against `outputSchema`. */
39
+ generate<S extends z.ZodType>(request: z.input<typeof llmRequest>, outputSchema: S, options?: CallOptions & {
40
+ idempotencyKey?: string;
41
+ }): Promise<GenerateResult<z.output<S>>>;
42
+ /** The raw response, for an `llm` profile that answers in free text. */
43
+ generateText(request: z.input<typeof llmRequest>, options?: CallOptions & {
44
+ idempotencyKey?: string;
45
+ }): Promise<LlmResponse>;
46
+ };
47
+ runs: {
48
+ create(input: CreateRunInput, options?: CallOptions): Promise<CreateRunResult>;
49
+ get(id: string, options?: CallOptions): Promise<Run>;
50
+ usage(id: string, options?: CallOptions): Promise<RunUsageResponse>;
51
+ /**
52
+ * Every event of a run from `after` (exclusive), in order, once each. Reconnects with
53
+ * `Last-Event-ID` when the connection drops and ends after the terminal event.
54
+ */
55
+ stream(id: string, options?: CallOptions & {
56
+ after?: number;
57
+ }): AsyncGenerator<RunEvent>;
58
+ /** Always resolves with the run: cancelling a terminal run returns it unchanged. */
59
+ cancel(id: string, reason: string, options?: CallOptions): Promise<Run>;
60
+ };
61
+ profiles: {
62
+ get(name: string, options?: CallOptions): Promise<ProfileSummary>;
63
+ };
64
+ }
65
+ export declare function createFlytebotClient(options: FlytebotClientOptions): FlytebotClient;
66
+ export {};