@flue/sdk 0.3.11 → 0.4.1

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.
@@ -1,7 +1,10 @@
1
- import { O as SessionStore, S as ProvidersConfig, T as SessionData, v as ModelConfig } from "./types-DGpyKMFm.mjs";
1
+ import { A as SessionStore, D as SessionData, v as ModelConfig } from "./types-BAmV4f3Q.mjs";
2
2
  import { FlueContextConfig, FlueContextInternal, createFlueContext } from "./client.mjs";
3
+ import { a as AgentHandler, c as RunHandlerFn, l as StartWebhookFn, n as configureFlueRuntime, o as CreateContextFn, r as createDefaultFlueApp, s as HandleAgentOptions, t as FlueRuntime, u as handleAgentRequest } from "./flue-app-CG8i4wNG.mjs";
3
4
  import { bashFactoryToSessionEnv } from "./sandbox.mjs";
4
- import { getModel } from "@mariozechner/pi-ai";
5
+ import { Api, Model } from "@mariozechner/pi-ai";
6
+ import { AgentMessage } from "@mariozechner/pi-agent-core";
7
+
5
8
  //#region src/session.d.ts
6
9
  /** In-memory session store. Sessions persist for the lifetime of the process. */
7
10
  declare class InMemorySessionStore implements SessionStore {
@@ -11,277 +14,11 @@ declare class InMemorySessionStore implements SessionStore {
11
14
  delete(id: string): Promise<void>;
12
15
  }
13
16
  //#endregion
14
- //#region src/errors.d.ts
15
- /**
16
- * Concrete error classes thrown by Flue.
17
- *
18
- * This file is the *vocabulary* of errors in Flue. Every error the framework
19
- * throws has a class here. The framework scaffolding (base class, renderers,
20
- * type guards, request-parsing helpers) lives in `error-utils.ts`.
21
- *
22
- * ──── Why this file exists ────────────────────────────────────────────────
23
- *
24
- * Concentrating every error in one file is deliberate. When all errors are
25
- * visible together, it's easy to:
26
- *
27
- * - Keep message tone and detail level consistent across the codebase.
28
- * - Notice duplicates ("oh, we already have an error for this case").
29
- * - Establish norms by example — when adding a new error, look at the
30
- * neighbors above and copy the pattern.
31
- *
32
- * Application code throughout the codebase should reach for one of these
33
- * classes rather than constructing a `FlueError` ad hoc. If no existing class
34
- * fits, add one here. That's the entire convention.
35
- *
36
- * ──── Two audiences: caller vs. developer ─────────────────────────────────
37
- *
38
- * The reader of an error message is one of two distinct audiences:
39
- *
40
- * - The *caller*: an HTTP client. Possibly third-party, possibly hostile,
41
- * possibly an end user who shouldn't even know we're built on Flue.
42
- * Sees `message` and `details` always.
43
- *
44
- * - The *developer*: the human running the service (`flue dev`, `flue run`,
45
- * local debugging). Sees `dev` in addition, but only when the server is
46
- * running in local/dev mode (gated by `FLUE_MODE=local`).
47
- *
48
- * Every error class must classify its prose by audience. The required-but-
49
- * possibly-empty shape of both `details` and `dev` is the discipline:
50
- * forgetting either field is a TypeScript error, and writing `''` is a
51
- * deliberate "I have nothing for that audience" decision.
52
- *
53
- * Concretely:
54
- *
55
- * - `message` One sentence. Caller-safe. Always rendered.
56
- * - `details` Longer caller-safe prose. About the request itself, the
57
- * contract, what the caller can do to fix it. Always
58
- * rendered. NEVER includes:
59
- * - sibling/neighbor enumeration (leaks namespace)
60
- * - filesystem paths or "agents/" / "skills/" / etc.
61
- * (leaks framework internals)
62
- * - source-code-level fix instructions ("add ... to your
63
- * agent definition") (caller can't act on these)
64
- * - build-time or runtime mechanics
65
- * - `dev` Longer dev-audience prose. Available alternatives,
66
- * filesystem layout, framework guidance, source-code-level
67
- * fix instructions. Rendered ONLY when FLUE_MODE=local.
68
- *
69
- * When in doubt, put information in `dev`. The default is conservative.
70
- *
71
- * ──── Conventions for new error classes ───────────────────────────────────
72
- *
73
- * - Class name: PascalCase, suffixed with `Error`. E.g. `AgentNotFoundError`.
74
- * - The class owns its `type` constant (snake_case). Set once in the
75
- * subclass constructor, never passed by callers. Renaming the wire type
76
- * is then a one-line change.
77
- * - Constructor takes ONLY structured input data (the values used to build
78
- * the message). The constructor assembles `message`, `details`, and
79
- * `dev` from that data, so call sites never reinvent phrasing.
80
- * - `details` and `dev` are both required strings. Pass `''` only when
81
- * there's genuinely nothing more to say for that audience.
82
- * - For HTTP errors, the class sets its own `status` (and `headers` where
83
- * relevant). Callers do not pick HTTP status codes ad-hoc.
84
- *
85
- * Worked example (matches `AgentNotFoundError` below):
86
- *
87
- * new AgentNotFoundError({ name, available });
88
- * // builds:
89
- * // message: `Agent "foo" is not registered.`
90
- * // details: `Verify the agent name is correct.`
91
- * // dev: `Available agents: "echo", "greeter". Agents are
92
- * // loaded from the workspace's "agents/" directory at
93
- * // build time. ...`
94
- *
95
- * The wire response in production omits `dev`; in `flue dev` / `flue run`
96
- * it includes `dev`. That separation is what lets the dev field be richly
97
- * helpful without leaking namespace state to public callers.
98
- *
99
- * Counter-example to avoid:
100
- *
101
- * class AgentNotFoundError extends FlueHttpError {
102
- * constructor(message: string) { // ✗ free-form
103
- * super({ // ✗ wrong type
104
- * type: 'agent_error',
105
- * message,
106
- * details: 'Available: "x", "y", "z"', // ✗ leaks names
107
- * dev: '', // ✗ wasted channel
108
- * status: 500, // ✗ wrong status
109
- * });
110
- * }
111
- * }
112
- *
113
- * The structured-constructor pattern below is what prevents that drift.
114
- */
115
- interface FlueErrorOptions {
116
- /**
117
- * Stable, machine-readable identifier (snake_case). Set once per subclass.
118
- * Callers don't pass this — the subclass constructor does.
119
- */
120
- type: string;
121
- /**
122
- * One-sentence summary of what went wrong. Caller-safe — always rendered
123
- * on the wire.
124
- */
125
- message: string;
126
- /**
127
- * Caller-audience longer-form explanation. Always rendered on the wire.
128
- *
129
- * Must be safe to expose to any HTTP client, including third-party or
130
- * hostile callers. Do NOT include sibling enumeration, filesystem paths,
131
- * framework-internal mechanics, or source-code fix instructions — those
132
- * belong in `dev`.
133
- *
134
- * Required: pass `''` only when there's genuinely nothing more to say to
135
- * the caller. The required-but-possibly-empty shape is intentional — it
136
- * forces a deliberate decision rather than a thoughtless omission.
137
- */
138
- details: string;
139
- /**
140
- * Developer-audience longer-form explanation. Rendered on the wire ONLY
141
- * when the server is running in local/dev mode (FLUE_MODE=local).
142
- *
143
- * Use this for everything that helps the developer running the service
144
- * but shouldn't reach a public caller: available alternatives, filesystem
145
- * paths, framework guidance, source-code fix instructions, configuration
146
- * hints.
147
- *
148
- * Required: pass `''` only when there's genuinely nothing dev-specific
149
- * to add (e.g. a malformed-JSON error has nothing to say to the dev that
150
- * isn't already in `details`).
151
- */
152
- dev: string;
153
- /**
154
- * Optional structured machine-readable data. Use only when downstream
155
- * tooling genuinely benefits — most errors should leave this unset.
156
- */
157
- meta?: Record<string, unknown>;
158
- /**
159
- * The underlying error, when wrapping. Logged server-side; never sent
160
- * over the wire.
161
- */
162
- cause?: unknown;
163
- }
164
- /**
165
- * Base class for every error Flue throws. Do not instantiate directly in
166
- * application code — extend it via a subclass below. If a use case isn't
167
- * covered, add a new subclass here rather than throwing a raw `FlueError`.
168
- */
169
- declare class FlueError extends Error {
170
- readonly type: string;
171
- readonly details: string;
172
- readonly dev: string;
173
- readonly meta: Record<string, unknown> | undefined;
174
- readonly cause: unknown;
175
- constructor(options: FlueErrorOptions);
176
- }
177
- interface FlueHttpErrorOptions extends FlueErrorOptions {
178
- /** HTTP status code (4xx or 5xx). */
179
- status: number;
180
- /** Additional response headers (e.g. `Allow` for 405). */
181
- headers?: Record<string, string>;
182
- }
183
- /**
184
- * Base class for HTTP-layer errors. Adds `status` and optional `headers`.
185
- * Subclasses set these in the `super({...})` call so the call site doesn't
186
- * have to think about HTTP semantics.
187
- */
188
- declare class FlueHttpError extends FlueError {
189
- readonly status: number;
190
- readonly headers: Record<string, string> | undefined;
191
- constructor(options: FlueHttpErrorOptions);
192
- }
193
- declare class MethodNotAllowedError extends FlueHttpError {
194
- constructor({
195
- method,
196
- allowed
197
- }: {
198
- method: string;
199
- allowed: readonly string[];
200
- });
201
- }
202
- declare class AgentNotFoundError extends FlueHttpError {
203
- constructor({
204
- name,
205
- available
206
- }: {
207
- name: string;
208
- available: readonly string[];
209
- });
210
- }
211
- declare class RouteNotFoundError extends FlueHttpError {
212
- constructor({
213
- method,
214
- path
215
- }: {
216
- method: string;
217
- path: string;
218
- });
219
- }
220
- declare class InvalidRequestError extends FlueHttpError {
221
- constructor({
222
- reason
223
- }: {
224
- reason: string;
225
- });
226
- }
227
- //#endregion
228
- //#region src/error-utils.d.ts
229
- /**
230
- * Render any thrown value into a `Response` with the canonical Flue error
231
- * envelope. Unknown / non-Flue errors are logged in full and rendered as a
232
- * generic 500 with no message leaked.
233
- */
234
- declare function toHttpResponse(err: unknown): Response;
235
- /**
236
- * Render any thrown value into a JSON string suitable for the `data:` line of
237
- * an SSE `error` event. Same envelope as `toHttpResponse`. Unknown / non-Flue
238
- * errors are logged and replaced with a generic envelope.
239
- */
240
- declare function toSseData(err: unknown): string;
241
- /**
242
- * Parse a request body as JSON. Returns `{}` for genuinely empty bodies
243
- * (Content-Length: 0 or missing) so that webhook agents which don't accept
244
- * a payload can be invoked without one.
245
- *
246
- * Throws `UnsupportedMediaTypeError` if a body is present without
247
- * `application/json` content-type, and `InvalidJsonError` if the body is
248
- * present but unparseable.
249
- */
250
- declare function parseJsonBody(request: Request): Promise<unknown>;
251
- /**
252
- * Validate that a request targeting `/agents/<name>/<id>` is well-formed:
253
- * method is POST, agent name is registered, and (optionally) the agent is
254
- * webhook-accessible. Throws the appropriate FlueHttpError on any failure.
255
- *
256
- * Path/id validation is light: we reject empty or whitespace-only segments
257
- * but otherwise let the URL parser's segment splitting be the source of
258
- * truth. The Cloudflare partyserver layer additionally enforces shape via
259
- * `routeAgentRequest`; the Node Hono layer via route patterns.
260
- */
261
- interface ValidateAgentRequestOptions {
262
- method: string;
263
- name: string;
264
- id: string;
265
- registeredAgents: readonly string[];
266
- webhookAgents: readonly string[];
267
- /**
268
- * If true, skip the webhook-accessibility check. Used by `flue run` /
269
- * dev local mode where trigger-less agents are also invokable.
270
- */
271
- allowNonWebhook?: boolean;
272
- }
273
- declare function validateAgentRequest(opts: ValidateAgentRequestOptions): void;
274
- //#endregion
275
17
  //#region src/internal.d.ts
276
18
  /**
277
- * Resolve a `provider/model-id` string into a pi-ai `Model` object.
278
- * Lives here (rather than in the generated entry point) so that user
279
- * projects don't have to declare `@mariozechner/pi-ai` as a direct
280
- * dependency — wrangler's bundler resolves bare specifiers from the entry
281
- * file's location, which on pnpm-isolated installs doesn't see Flue's
282
- * transitive deps. Centralizing the resolver here keeps `_entry.ts`
283
- * dependency-free apart from `@flue/sdk/*`.
19
+ * Resolve `provider/model-id` to a pi-ai Model. Registered URL prefixes win
20
+ * over pi-ai's catalog; configureProvider settings patch the resolved Model.
284
21
  */
285
- declare function resolveModel(model: ModelConfig | undefined, providers?: ProvidersConfig): ReturnType<typeof getModel> | undefined;
22
+ declare function resolveModel(model: ModelConfig | undefined): Model<Api> | undefined;
286
23
  //#endregion
287
- export { AgentNotFoundError, type FlueContextConfig, type FlueContextInternal, InMemorySessionStore, InvalidRequestError, MethodNotAllowedError, RouteNotFoundError, bashFactoryToSessionEnv, createFlueContext, parseJsonBody, resolveModel, toHttpResponse, toSseData, validateAgentRequest };
24
+ export { type AgentHandler, type CreateContextFn, type FlueContextConfig, type FlueContextInternal, type FlueRuntime, type HandleAgentOptions, InMemorySessionStore, type RunHandlerFn, type StartWebhookFn, bashFactoryToSessionEnv, configureFlueRuntime, createDefaultFlueApp, createFlueContext, handleAgentRequest, resolveModel };