@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.
Files changed (57) hide show
  1. package/README.md +138 -2
  2. package/dist/auth/errors.d.ts +10 -0
  3. package/dist/auth/errors.js +14 -0
  4. package/dist/auth/errors.js.map +1 -1
  5. package/dist/auth/index.d.ts +1 -0
  6. package/dist/auth/index.js +1 -0
  7. package/dist/auth/index.js.map +1 -1
  8. package/dist/auth/people/lookup.d.ts +32 -0
  9. package/dist/auth/people/lookup.js +81 -0
  10. package/dist/auth/people/lookup.js.map +1 -0
  11. package/dist/auth/prisma/prismaAuthStore.js +1 -6
  12. package/dist/auth/prisma/prismaAuthStore.js.map +1 -1
  13. package/dist/auth/revocationReasons.d.ts +4 -0
  14. package/dist/auth/revocationReasons.js +10 -0
  15. package/dist/auth/revocationReasons.js.map +1 -0
  16. package/dist/chat/tools/index.d.ts +38 -0
  17. package/dist/chat/tools/index.js +60 -0
  18. package/dist/chat/tools/index.js.map +1 -0
  19. package/dist/cli/auth-adopt.d.ts +13 -0
  20. package/dist/cli/auth-adopt.js +201 -0
  21. package/dist/cli/auth-adopt.js.map +1 -0
  22. package/dist/cli/auth-sync.js +2 -1
  23. package/dist/cli/auth-sync.js.map +1 -1
  24. package/dist/cli/sync-engine.d.ts +8 -0
  25. package/dist/cli/sync-engine.js +155 -21
  26. package/dist/cli/sync-engine.js.map +1 -1
  27. package/dist/flytebot/client.d.ts +66 -0
  28. package/dist/flytebot/client.js +377 -0
  29. package/dist/flytebot/client.js.map +1 -0
  30. package/dist/flytebot/env.d.ts +11 -0
  31. package/dist/flytebot/env.js +25 -0
  32. package/dist/flytebot/env.js.map +1 -0
  33. package/dist/flytebot/error.d.ts +36 -0
  34. package/dist/flytebot/error.js +60 -0
  35. package/dist/flytebot/error.js.map +1 -0
  36. package/dist/flytebot/index.d.ts +32 -0
  37. package/dist/flytebot/index.js +28 -0
  38. package/dist/flytebot/index.js.map +1 -0
  39. package/dist/flytebot/sse.d.ts +11 -0
  40. package/dist/flytebot/sse.js +55 -0
  41. package/dist/flytebot/sse.js.map +1 -0
  42. package/dist/flytebot/testing/fake.d.ts +77 -0
  43. package/dist/flytebot/testing/fake.js +399 -0
  44. package/dist/flytebot/testing/fake.js.map +1 -0
  45. package/dist/flytebot/testing/index.d.ts +18 -0
  46. package/dist/flytebot/testing/index.js +18 -0
  47. package/dist/flytebot/testing/index.js.map +1 -0
  48. package/dist/flytebot/webhook.d.ts +24 -0
  49. package/dist/flytebot/webhook.js +63 -0
  50. package/dist/flytebot/webhook.js.map +1 -0
  51. package/dist/spa-server/index.d.ts +8 -16
  52. package/dist/spa-server/index.js +36 -4
  53. package/dist/spa-server/index.js.map +1 -1
  54. package/package.json +17 -2
  55. package/prisma/fragments/auth.prisma +9 -3
  56. package/prisma/migrations/0004_app_kit_auth_init/migration.sql +74 -41
  57. package/prisma/migrations/manifest.json +1 -1
@@ -0,0 +1,60 @@
1
+ import { errorEnvelope } from "@flytedesk/flytebot-contracts";
2
+ /** The one error every Flytebot client call throws. An app maps `retryable` to its UI wording. */
3
+ export class FlytebotError extends Error {
4
+ code;
5
+ httpStatus;
6
+ retryable;
7
+ requestId;
8
+ details;
9
+ retryAfterMs;
10
+ constructor(init) {
11
+ super(init.message, init.cause === undefined ? undefined : { cause: init.cause });
12
+ this.name = "FlytebotError";
13
+ this.code = init.code;
14
+ this.httpStatus = init.httpStatus;
15
+ this.retryable = init.retryable;
16
+ this.requestId = init.requestId;
17
+ this.details = init.details;
18
+ this.retryAfterMs = init.retryAfterMs ?? null;
19
+ }
20
+ }
21
+ /**
22
+ * Build the error for a non-2xx response. A body that is the service's envelope gives
23
+ * code, message, requestId and retryable verbatim; any other body (a proxy's 502 page)
24
+ * is a `unavailable` error that is retryable exactly when the status is 5xx or 429.
25
+ */
26
+ export function errorFromResponse(status, headers, body) {
27
+ const headerRequestId = headers.get("x-request-id");
28
+ const retryAfterMs = parseRetryAfter(headers.get("retry-after"));
29
+ const parsed = errorEnvelope.safeParse(body);
30
+ if (parsed.success) {
31
+ const { code, message, requestId, retryable, details } = parsed.data.error;
32
+ return new FlytebotError({
33
+ code,
34
+ message,
35
+ httpStatus: status,
36
+ retryable,
37
+ requestId: requestId || headerRequestId,
38
+ details,
39
+ retryAfterMs,
40
+ });
41
+ }
42
+ return new FlytebotError({
43
+ code: "unavailable",
44
+ message: `Flytebot answered HTTP ${status} without an error envelope`,
45
+ httpStatus: status,
46
+ retryable: status >= 500 || status === 429,
47
+ requestId: headerRequestId,
48
+ retryAfterMs,
49
+ });
50
+ }
51
+ function parseRetryAfter(value) {
52
+ if (value === null)
53
+ return undefined;
54
+ const seconds = Number(value);
55
+ if (Number.isFinite(seconds) && seconds >= 0)
56
+ return seconds * 1000;
57
+ const date = Date.parse(value);
58
+ return Number.isNaN(date) ? undefined : Math.max(0, date - Date.now());
59
+ }
60
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/flytebot/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,+BAA+B,CAAC;AA4B9E,kGAAkG;AAClG,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,CAAoB;IACxB,UAAU,CAAgB;IAC1B,SAAS,CAAU;IACnB,SAAS,CAAgB;IACzB,OAAO,CAAsC;IAC7C,YAAY,CAAgB;IAErC,YAAY,IAAuB;QACjC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAClF,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAA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AM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC;QAAE,OAAO,OAAO,GAAG,IAAI,CAAC;IACpE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The Flytebot client (PLAN-10, AK-55): how a flytedesk app asks Flytebot to run an
3
+ * agent or answer one structured question.
4
+ *
5
+ * const flytebot = createFlytebotClient({ baseUrl: env.flytebotUrl, timeoutMs: 15_000, retries: 3 });
6
+ *
7
+ * // a structured answer
8
+ * const { output } = await flytebot.llm.generate({ profile: "goal-judgment", messages, actor }, outputSchema);
9
+ *
10
+ * // an agent run; the idempotency key is the app's own row id, so a retry never starts a second run
11
+ * const { run } = await flytebot.runs.create({
12
+ * profile: "audience-chat", conversation: { externalRef: conversationId }, task, actor,
13
+ * tools: { "sms-app-chat": { bearer } }, webhook: { url }, idempotencyKey: dispatchId,
14
+ * });
15
+ * for await (const event of flytebot.runs.stream(run.id)) { ... } // ends after the terminal event
16
+ *
17
+ * // the terminal webhook route
18
+ * const terminalRun = await verifyTerminalWebhook(request, { flytebotServiceAccount, audienceOrigin });
19
+ *
20
+ * Wire types come from `@flytedesk/flytebot-contracts`. `@flytedesk/app-kit/flytebot/testing`
21
+ * has an in-process fake of the service.
22
+ */
23
+ export { createFlytebotClient } from "./client.js";
24
+ export type { CallOptions, CreateRunResult, FlytebotClient, FlytebotClientOptions, GenerateResult, } from "./client.js";
25
+ export { FlytebotError } from "./error.js";
26
+ export type { FlytebotErrorCode, FlytebotErrorInit } from "./error.js";
27
+ export { parseFlytebotEnv, FlytebotEnvError } from "./env.js";
28
+ export type { FlytebotEnv } from "./env.js";
29
+ export { verifyTerminalWebhook } from "./webhook.js";
30
+ export type { VerifyTerminalWebhookOptions, WebhookRequest, } from "./webhook.js";
31
+ export { isTerminalStatus } from "@flytedesk/flytebot-contracts";
32
+ export type { Run, RunEvent, RunStatus, TerminalStatus, RunUsageResponse, ProfileSummary, LlmResponse, ActorRef, ErrorCode, } from "@flytedesk/flytebot-contracts";
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The Flytebot client (PLAN-10, AK-55): how a flytedesk app asks Flytebot to run an
3
+ * agent or answer one structured question.
4
+ *
5
+ * const flytebot = createFlytebotClient({ baseUrl: env.flytebotUrl, timeoutMs: 15_000, retries: 3 });
6
+ *
7
+ * // a structured answer
8
+ * const { output } = await flytebot.llm.generate({ profile: "goal-judgment", messages, actor }, outputSchema);
9
+ *
10
+ * // an agent run; the idempotency key is the app's own row id, so a retry never starts a second run
11
+ * const { run } = await flytebot.runs.create({
12
+ * profile: "audience-chat", conversation: { externalRef: conversationId }, task, actor,
13
+ * tools: { "sms-app-chat": { bearer } }, webhook: { url }, idempotencyKey: dispatchId,
14
+ * });
15
+ * for await (const event of flytebot.runs.stream(run.id)) { ... } // ends after the terminal event
16
+ *
17
+ * // the terminal webhook route
18
+ * const terminalRun = await verifyTerminalWebhook(request, { flytebotServiceAccount, audienceOrigin });
19
+ *
20
+ * Wire types come from `@flytedesk/flytebot-contracts`. `@flytedesk/app-kit/flytebot/testing`
21
+ * has an in-process fake of the service.
22
+ */
23
+ export { createFlytebotClient } from "./client.js";
24
+ export { FlytebotError } from "./error.js";
25
+ export { parseFlytebotEnv, FlytebotEnvError } from "./env.js";
26
+ export { verifyTerminalWebhook } from "./webhook.js";
27
+ export { isTerminalStatus } from "@flytedesk/flytebot-contracts";
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/flytebot/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAQnD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAKrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,11 @@
1
+ export interface SseFrame {
2
+ id: string | null;
3
+ event: string | null;
4
+ data: string;
5
+ }
6
+ /**
7
+ * Parse a Server-Sent Events byte stream into frames. Comment lines (": ping") are
8
+ * dropped; a frame is dispatched at its blank line, and a frame with no `data` line is
9
+ * dropped, per the SSE spec. The stream ending mid-frame drops that partial frame.
10
+ */
11
+ export declare function parseSse(body: ReadableStream<Uint8Array>): AsyncGenerator<SseFrame>;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Parse a Server-Sent Events byte stream into frames. Comment lines (": ping") are
3
+ * dropped; a frame is dispatched at its blank line, and a frame with no `data` line is
4
+ * dropped, per the SSE spec. The stream ending mid-frame drops that partial frame.
5
+ */
6
+ export async function* parseSse(body) {
7
+ const decoder = new TextDecoder();
8
+ const reader = body.getReader();
9
+ let buffer = "";
10
+ let id = null;
11
+ let event = null;
12
+ let data = [];
13
+ try {
14
+ for (;;) {
15
+ const { value, done } = await reader.read();
16
+ if (done)
17
+ return;
18
+ buffer += decoder.decode(value, { stream: true });
19
+ let newline;
20
+ while ((newline = buffer.search(/\r\n|\n|\r/)) !== -1) {
21
+ const terminator = buffer.startsWith("\r\n", newline) ? 2 : 1;
22
+ const line = buffer.slice(0, newline);
23
+ // A lone "\r" at the buffer's end may be the first half of "\r\n": wait.
24
+ if (buffer[newline] === "\r" && newline + 1 === buffer.length)
25
+ break;
26
+ buffer = buffer.slice(newline + terminator);
27
+ if (line === "") {
28
+ if (data.length > 0)
29
+ yield { id, event, data: data.join("\n") };
30
+ id = null;
31
+ event = null;
32
+ data = [];
33
+ continue;
34
+ }
35
+ if (line.startsWith(":"))
36
+ continue;
37
+ const colon = line.indexOf(":");
38
+ const field = colon === -1 ? line : line.slice(0, colon);
39
+ let content = colon === -1 ? "" : line.slice(colon + 1);
40
+ if (content.startsWith(" "))
41
+ content = content.slice(1);
42
+ if (field === "id")
43
+ id = content;
44
+ else if (field === "event")
45
+ event = content;
46
+ else if (field === "data")
47
+ data.push(content);
48
+ }
49
+ }
50
+ }
51
+ finally {
52
+ await reader.cancel().catch(() => undefined);
53
+ }
54
+ }
55
+ //# sourceMappingURL=sse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/flytebot/sse.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,QAAQ,CAC7B,IAAgC;IAEhC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAChC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,EAAE,GAAkB,IAAI,CAAC;IAC7B,IAAI,KAAK,GAAkB,IAAI,CAAC;IAChC,IAAI,IAAI,GAAa,EAAE,CAAC;IACxB,IAAI,CAAC;QACH,SAAS,CAAC;YACR,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI;gBAAE,OAAO;YACjB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,IAAI,OAAe,CAAC;YACpB,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,EA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AAC,CAAC,CAAC,CAAC;gBACxD,IAAI,KAAK,KAAK,IAAI;oBAAE,EAAE,GAAG,OAAO,CAAC;qBAC5B,IAAI,KAAK,KAAK,OAAO;oBAAE,KAAK,GAAG,OAAO,CAAC;qBACvC,IAAI,KAAK,KAAK,MAAM;oBAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { type ErrorCode, type LlmRequest, type ProfileSummary, type Run, type RunErrorCode, type RunEvent, type TerminalStatus, type TokenUsage } from "@flytedesk/flytebot-contracts";
2
+ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
3
+ type EventBody = DistributiveOmit<RunEvent, "seq" | "at">;
4
+ /** An event a script adds between `started` and the terminal. `seq` and `at` are the fake's. */
5
+ export type ScriptedEvent = Extract<EventBody, {
6
+ type: "text" | "tool_call" | "tool_result" | "usage";
7
+ }>;
8
+ export interface RunScript {
9
+ /** Events between `started` and the terminal. Default: none. */
10
+ events?: ScriptedEvent[];
11
+ /** How the run ends. Default: `completed` with result text "done". */
12
+ terminal?: {
13
+ status: TerminalStatus;
14
+ resultText?: string | null;
15
+ error?: {
16
+ code: RunErrorCode;
17
+ message: string;
18
+ } | null;
19
+ };
20
+ usage?: TokenUsage;
21
+ costUsd?: number;
22
+ /** Keep the run `running` after its scripted events until `finish(runId)`. */
23
+ hold?: boolean;
24
+ /** Close the first event-stream connection after this many frames, to exercise reconnect. */
25
+ dropStreamAfter?: number;
26
+ }
27
+ export interface ScriptedFailure {
28
+ /** "METHOD /path" as the fake sees it, e.g. "POST /v1/runs"; a string must match exactly. */
29
+ match: string | RegExp;
30
+ code: ErrorCode;
31
+ /** Default: the code's status from the contract. */
32
+ status?: number;
33
+ /** Default: the code's retryability from the contract. */
34
+ retryable?: boolean;
35
+ /** How many matching requests fail before requests succeed again. Default 1. */
36
+ times?: number;
37
+ retryAfterSeconds?: number;
38
+ details?: Record<string, unknown>;
39
+ }
40
+ export type LlmAnswer = {
41
+ output: unknown;
42
+ text?: string;
43
+ } | ((request: LlmRequest) => {
44
+ output: unknown;
45
+ text?: string;
46
+ });
47
+ export interface RecordedRequest {
48
+ method: string;
49
+ path: string;
50
+ /** Header names lowercased. */
51
+ headers: Record<string, string | string[] | undefined>;
52
+ body: unknown;
53
+ }
54
+ export interface FakeFlytebot {
55
+ /** Listen on a free 127.0.0.1 port. */
56
+ start(): Promise<void>;
57
+ stop(): Promise<void>;
58
+ /** Base URL to give `createFlytebotClient`. */
59
+ readonly url: string;
60
+ /** Every request received, in order, including the ones a scripted failure refused. */
61
+ readonly requests: readonly RecordedRequest[];
62
+ /** The next created run follows this script. Scripts queue in order. */
63
+ scriptRun(script: RunScript): void;
64
+ /** Answer matching requests with an error, `times` times. */
65
+ failNext(failure: ScriptedFailure): void;
66
+ /** What `POST /v1/llm` answers for a profile. An unknown profile is `profile_not_found`. */
67
+ setLlm(profile: string, answer: LlmAnswer): void;
68
+ /** What `GET /v1/profiles/:name` answers. An unknown profile is `profile_not_found`. */
69
+ setProfile(summary: ProfileSummary): void;
70
+ /** Add an event to a held run. */
71
+ emit(runId: string, event: ScriptedEvent): void;
72
+ /** End a held run (default: completed). */
73
+ finish(runId: string, terminal?: NonNullable<RunScript["terminal"]>): void;
74
+ getRun(runId: string): Run;
75
+ }
76
+ export declare function createFakeFlytebot(): FakeFlytebot;
77
+ export {};