@almadar/sdk 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +72 -0
- package/README.md +63 -0
- package/dist/client/index.d.ts +58 -0
- package/dist/client/index.js +282 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +328 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +9 -0
- package/dist/react/index.js +49 -0
- package/dist/react/index.js.map +1 -0
- package/dist/server/index.d.ts +61 -0
- package/dist/server/index.js +280 -0
- package/dist/server/index.js.map +1 -0
- package/dist/types-BfWDIOGm.d.ts +145 -0
- package/package.json +100 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { lazy, forwardRef, useRef, useImperativeHandle, Suspense } from 'react';
|
|
2
|
+
import '@almadar/ui/index.css';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
export { useEventBus as useOrbBus } from '@almadar/ui/hooks';
|
|
5
|
+
|
|
6
|
+
// src/react/AlmadarApp.tsx
|
|
7
|
+
var OrbPreviewLazy = lazy(async () => {
|
|
8
|
+
const mod = await import('@almadar/ui/runtime');
|
|
9
|
+
return { default: mod.OrbPreview };
|
|
10
|
+
});
|
|
11
|
+
var BrowserPlaygroundLazy = lazy(async () => {
|
|
12
|
+
const mod = await import('@almadar/ui/runtime');
|
|
13
|
+
return { default: mod.BrowserPlayground };
|
|
14
|
+
});
|
|
15
|
+
var AlmadarApp = forwardRef(function AlmadarApp2(props, ref) {
|
|
16
|
+
const emitterRef = useRef(null);
|
|
17
|
+
useImperativeHandle(ref, () => ({
|
|
18
|
+
emit(event, payload) {
|
|
19
|
+
if (emitterRef.current === null) return;
|
|
20
|
+
emitterRef.current(event, payload);
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
const mode = props.mode ?? "static";
|
|
24
|
+
return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: mode === "mock" ? /* @__PURE__ */ jsx(
|
|
25
|
+
BrowserPlaygroundLazy,
|
|
26
|
+
{
|
|
27
|
+
schema: props.schema,
|
|
28
|
+
mode: "mock",
|
|
29
|
+
initialPagePath: props.initialPagePath,
|
|
30
|
+
height: props.height,
|
|
31
|
+
className: props.className
|
|
32
|
+
}
|
|
33
|
+
) : /* @__PURE__ */ jsx(
|
|
34
|
+
OrbPreviewLazy,
|
|
35
|
+
{
|
|
36
|
+
schema: props.schema,
|
|
37
|
+
mockData: props.data,
|
|
38
|
+
serverUrl: props.serverUrl,
|
|
39
|
+
initialPagePath: props.initialPagePath,
|
|
40
|
+
height: props.height,
|
|
41
|
+
className: props.className
|
|
42
|
+
}
|
|
43
|
+
) });
|
|
44
|
+
});
|
|
45
|
+
AlmadarApp.displayName = "AlmadarApp";
|
|
46
|
+
|
|
47
|
+
// src/client/errors.ts
|
|
48
|
+
var AlmadarError = class extends Error {
|
|
49
|
+
code;
|
|
50
|
+
details;
|
|
51
|
+
constructor(body) {
|
|
52
|
+
super(body.message);
|
|
53
|
+
this.name = "AlmadarError";
|
|
54
|
+
this.code = body.code;
|
|
55
|
+
this.details = body.details;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var ApiKeyError = class extends AlmadarError {
|
|
59
|
+
constructor(body) {
|
|
60
|
+
super(body);
|
|
61
|
+
this.name = "ApiKeyError";
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var RateLimitedError = class extends AlmadarError {
|
|
65
|
+
retryAfterSeconds;
|
|
66
|
+
constructor(body, retryAfterSeconds) {
|
|
67
|
+
super(body);
|
|
68
|
+
this.name = "RateLimitedError";
|
|
69
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var CatalogOutOfScopeError = class extends AlmadarError {
|
|
73
|
+
constructor(body) {
|
|
74
|
+
super(body);
|
|
75
|
+
this.name = "CatalogOutOfScopeError";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var ServerError = class extends AlmadarError {
|
|
79
|
+
constructor(body) {
|
|
80
|
+
super(body);
|
|
81
|
+
this.name = "ServerError";
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
function errorFromBody(body) {
|
|
85
|
+
switch (body.code) {
|
|
86
|
+
case 4001:
|
|
87
|
+
return new ApiKeyError(body);
|
|
88
|
+
case 4029:
|
|
89
|
+
return new RateLimitedError(body);
|
|
90
|
+
case 4040:
|
|
91
|
+
return new CatalogOutOfScopeError(body);
|
|
92
|
+
default:
|
|
93
|
+
return new ServerError(body);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/client/sseParser.ts
|
|
98
|
+
async function* parseSSE(stream) {
|
|
99
|
+
const reader = stream.getReader();
|
|
100
|
+
const decoder = new TextDecoder("utf-8");
|
|
101
|
+
let buffer = "";
|
|
102
|
+
let currentEvent = "";
|
|
103
|
+
let currentData = "";
|
|
104
|
+
try {
|
|
105
|
+
for (; ; ) {
|
|
106
|
+
const { value, done } = await reader.read();
|
|
107
|
+
if (done) break;
|
|
108
|
+
buffer += decoder.decode(value, { stream: true });
|
|
109
|
+
let newlineIdx;
|
|
110
|
+
while ((newlineIdx = indexOfNewline(buffer)) !== -1) {
|
|
111
|
+
const rawLine = buffer.slice(0, newlineIdx);
|
|
112
|
+
buffer = buffer.slice(newlineIdx + (buffer[newlineIdx] === "\r" && buffer[newlineIdx + 1] === "\n" ? 2 : 1));
|
|
113
|
+
if (rawLine === "") {
|
|
114
|
+
if (currentData !== "" || currentEvent !== "") {
|
|
115
|
+
yield { event: currentEvent, data: currentData };
|
|
116
|
+
currentEvent = "";
|
|
117
|
+
currentData = "";
|
|
118
|
+
}
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (rawLine.startsWith(":")) continue;
|
|
122
|
+
const colon = rawLine.indexOf(":");
|
|
123
|
+
const field = colon === -1 ? rawLine : rawLine.slice(0, colon);
|
|
124
|
+
const rawValue = colon === -1 ? "" : rawLine.slice(colon + 1);
|
|
125
|
+
const value2 = rawValue.startsWith(" ") ? rawValue.slice(1) : rawValue;
|
|
126
|
+
if (field === "event") {
|
|
127
|
+
currentEvent = value2;
|
|
128
|
+
} else if (field === "data") {
|
|
129
|
+
currentData = currentData === "" ? value2 : `${currentData}
|
|
130
|
+
${value2}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (currentData !== "" || currentEvent !== "") {
|
|
135
|
+
yield { event: currentEvent, data: currentData };
|
|
136
|
+
}
|
|
137
|
+
} finally {
|
|
138
|
+
reader.releaseLock();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function indexOfNewline(s) {
|
|
142
|
+
for (let i = 0; i < s.length; i += 1) {
|
|
143
|
+
const c = s[i];
|
|
144
|
+
if (c === "\n" || c === "\r") return i;
|
|
145
|
+
}
|
|
146
|
+
return -1;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/client/AlmadarClient.ts
|
|
150
|
+
var DEFAULT_BASE_URL = "https://api.almadar.io";
|
|
151
|
+
var POLL_BACKOFF_MS = [1e3, 2e3, 5e3, 1e4, 3e4];
|
|
152
|
+
var AlmadarClient = class {
|
|
153
|
+
apiKey;
|
|
154
|
+
baseUrl;
|
|
155
|
+
fetchImpl;
|
|
156
|
+
constructor(opts) {
|
|
157
|
+
if (!opts.apiKey || typeof opts.apiKey !== "string") {
|
|
158
|
+
throw new Error("AlmadarClient: opts.apiKey is required");
|
|
159
|
+
}
|
|
160
|
+
this.apiKey = opts.apiKey;
|
|
161
|
+
this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
162
|
+
this.fetchImpl = opts.fetch ?? globalThis.fetch;
|
|
163
|
+
if (typeof this.fetchImpl !== "function") {
|
|
164
|
+
throw new Error("AlmadarClient: no fetch available \u2014 pass opts.fetch for Node <18");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async generate(input) {
|
|
168
|
+
if (input.async === true) {
|
|
169
|
+
const handle = await this.requestJson("POST", "/api/v1/agent/generate", {
|
|
170
|
+
prompt: input.prompt,
|
|
171
|
+
endUserId: input.endUserId,
|
|
172
|
+
appId: input.appId,
|
|
173
|
+
async: true
|
|
174
|
+
});
|
|
175
|
+
assertString(handle.jobId, "AsyncJobHandle.jobId");
|
|
176
|
+
assertString(handle.statusUrl, "AsyncJobHandle.statusUrl");
|
|
177
|
+
return this.pollUntilComplete(handle, input.onEvent);
|
|
178
|
+
}
|
|
179
|
+
return this.streamGenerate(input);
|
|
180
|
+
}
|
|
181
|
+
async editSchema(appId, patch) {
|
|
182
|
+
if (!appId) throw new Error("AlmadarClient.editSchema: appId is required");
|
|
183
|
+
const schema = await this.requestJson("PUT", "/api/v1/agent/edit-schema", {
|
|
184
|
+
appId,
|
|
185
|
+
patch
|
|
186
|
+
});
|
|
187
|
+
assertString(schema.name, "OrbitalSchema.name");
|
|
188
|
+
return schema;
|
|
189
|
+
}
|
|
190
|
+
async compileToApp(schema, opts) {
|
|
191
|
+
const result = await this.requestJson("POST", "/api/v1/agent/compile", {
|
|
192
|
+
schema,
|
|
193
|
+
target: opts?.target,
|
|
194
|
+
shell: opts?.shell
|
|
195
|
+
});
|
|
196
|
+
assertString(result.downloadUrl, "CompileResult.downloadUrl");
|
|
197
|
+
assertString(result.expiresAt, "CompileResult.expiresAt");
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
async streamGenerate(input) {
|
|
201
|
+
const res = await this.fetchImpl(`${this.baseUrl}/api/v1/agent/generate`, {
|
|
202
|
+
method: "POST",
|
|
203
|
+
headers: this.headers({ accept: "text/event-stream", contentType: "application/json" }, input.endUserId),
|
|
204
|
+
body: JSON.stringify({
|
|
205
|
+
prompt: input.prompt,
|
|
206
|
+
endUserId: input.endUserId,
|
|
207
|
+
appId: input.appId
|
|
208
|
+
})
|
|
209
|
+
});
|
|
210
|
+
if (!res.ok) throw await this.errorFromResponse(res);
|
|
211
|
+
if (res.body === null) throw new Error("AlmadarClient.generate: server returned no body");
|
|
212
|
+
let final = null;
|
|
213
|
+
for await (const raw of parseSSE(res.body)) {
|
|
214
|
+
const event = parseAgentEvent(raw.event, raw.data);
|
|
215
|
+
if (event === null) continue;
|
|
216
|
+
input.onEvent?.(event);
|
|
217
|
+
if (event.type === "complete") {
|
|
218
|
+
final = { schema: event.schema, appId: event.appId };
|
|
219
|
+
} else if (event.type === "error") {
|
|
220
|
+
throw errorFromBody({ code: event.code ?? 500, message: event.message });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (final === null) {
|
|
224
|
+
throw new ServerError({ code: 500, message: "SSE stream ended without `complete` event" });
|
|
225
|
+
}
|
|
226
|
+
return final;
|
|
227
|
+
}
|
|
228
|
+
async pollUntilComplete(handle, onEvent) {
|
|
229
|
+
let attempt = 0;
|
|
230
|
+
for (; ; ) {
|
|
231
|
+
const delay = POLL_BACKOFF_MS[Math.min(attempt, POLL_BACKOFF_MS.length - 1)];
|
|
232
|
+
await sleep(delay);
|
|
233
|
+
attempt += 1;
|
|
234
|
+
const status = await this.requestJson("GET", handle.statusUrl);
|
|
235
|
+
assertString(status.state, "JobStatus.state");
|
|
236
|
+
if (status.events !== void 0 && onEvent !== void 0) {
|
|
237
|
+
for (const e of status.events) onEvent(e);
|
|
238
|
+
}
|
|
239
|
+
if (status.state === "complete") {
|
|
240
|
+
if (status.result === void 0) {
|
|
241
|
+
throw new ServerError({ code: 500, message: "Job complete but no result returned" });
|
|
242
|
+
}
|
|
243
|
+
return status.result;
|
|
244
|
+
}
|
|
245
|
+
if (status.state === "error") {
|
|
246
|
+
throw errorFromBody({
|
|
247
|
+
code: status.errorCode ?? 500,
|
|
248
|
+
message: status.errorMessage ?? "Job failed"
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async requestJson(method, path, body) {
|
|
254
|
+
const isAbsolute = path.startsWith("http://") || path.startsWith("https://");
|
|
255
|
+
const url = isAbsolute ? path : `${this.baseUrl}${path}`;
|
|
256
|
+
const init = {
|
|
257
|
+
method,
|
|
258
|
+
headers: this.headers({
|
|
259
|
+
accept: "application/json",
|
|
260
|
+
contentType: body !== void 0 ? "application/json" : void 0
|
|
261
|
+
})
|
|
262
|
+
};
|
|
263
|
+
if (body !== void 0) init.body = JSON.stringify(body);
|
|
264
|
+
const res = await this.fetchImpl(url, init);
|
|
265
|
+
if (!res.ok) throw await this.errorFromResponse(res);
|
|
266
|
+
const text = await res.text();
|
|
267
|
+
if (text === "") {
|
|
268
|
+
throw new ServerError({ code: 500, message: "Empty response body" });
|
|
269
|
+
}
|
|
270
|
+
const parsed = JSON.parse(text);
|
|
271
|
+
return parsed;
|
|
272
|
+
}
|
|
273
|
+
headers(opts, endUserId) {
|
|
274
|
+
const h = { authorization: `Bearer ${this.apiKey}` };
|
|
275
|
+
if (opts.accept !== void 0) h["accept"] = opts.accept;
|
|
276
|
+
if (opts.contentType !== void 0) h["content-type"] = opts.contentType;
|
|
277
|
+
if (endUserId !== void 0 && endUserId !== "") h["x-end-user-id"] = endUserId;
|
|
278
|
+
return h;
|
|
279
|
+
}
|
|
280
|
+
async errorFromResponse(res) {
|
|
281
|
+
const text = await res.text();
|
|
282
|
+
let body;
|
|
283
|
+
try {
|
|
284
|
+
const parsed = text === "" ? null : JSON.parse(text);
|
|
285
|
+
body = parsed !== null && typeof parsed.code === "number" && typeof parsed.message === "string" ? parsed : {
|
|
286
|
+
code: res.status,
|
|
287
|
+
message: res.statusText !== "" ? res.statusText : "HTTP error"
|
|
288
|
+
};
|
|
289
|
+
} catch {
|
|
290
|
+
body = { code: res.status, message: text !== "" ? text : res.statusText };
|
|
291
|
+
}
|
|
292
|
+
const retryAfter = res.headers.get("retry-after");
|
|
293
|
+
const err = errorFromBody(body);
|
|
294
|
+
if (err.name === "RateLimitedError" && retryAfter !== null) {
|
|
295
|
+
const seconds = Number(retryAfter);
|
|
296
|
+
if (Number.isFinite(seconds)) {
|
|
297
|
+
Object.defineProperty(err, "retryAfterSeconds", { value: seconds, enumerable: true });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return err;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
function parseAgentEvent(eventName, dataLine) {
|
|
304
|
+
if (dataLine === "") return null;
|
|
305
|
+
let payload;
|
|
306
|
+
try {
|
|
307
|
+
payload = JSON.parse(dataLine);
|
|
308
|
+
} catch {
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
if (payload === null || typeof payload !== "object") return null;
|
|
312
|
+
if (typeof payload.type === "string") return payload;
|
|
313
|
+
if (eventName === "") return null;
|
|
314
|
+
const synthesized = Object.assign(payload, { type: eventName });
|
|
315
|
+
return synthesized;
|
|
316
|
+
}
|
|
317
|
+
function assertString(v, name) {
|
|
318
|
+
if (typeof v !== "string" || v === "") {
|
|
319
|
+
throw new ServerError({ code: 500, message: `Malformed server response: ${name} is not a string` });
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function sleep(ms) {
|
|
323
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export { AlmadarApp, AlmadarClient, AlmadarError, ApiKeyError, CatalogOutOfScopeError, RateLimitedError, ServerError };
|
|
327
|
+
//# sourceMappingURL=index.js.map
|
|
328
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/AlmadarApp.tsx","../src/client/errors.ts","../src/client/sseParser.ts","../src/client/AlmadarClient.ts"],"names":["AlmadarApp"],"mappings":";;;;;;AAwBA,IAAM,cAAA,GAAiB,KAAK,YAAY;AACtC,EAAA,MAAM,GAAA,GAAM,MAAM,OAAO,qBAAqB,CAAA;AAC9C,EAAA,OAAO,EAAE,OAAA,EAAS,GAAA,CAAI,UAAA,EAAW;AACnC,CAAC,CAA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;AACF,IAAA,OAAA,GAAU,IAAA,CAAK,MAAM,QAAQ,CAAA;AAAA,EAC/B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,IAAI,OAAA,KAAY,IAAA,IAAQ,OAAO,OAAA,KAAY,UAAU,OAAO,IAAA;AAC5D,EAAA,IAAI,OAAO,OAAA,CAAQ,IAAA,KAAS,QAAA,EAAU,OAAO,OAAA;AAC7C,EAAA,IAAI,SAAA,KAAc,IAAI,OAAO,IAAA;AAG7B,EAAA,MAAM,cAA6C,MAAA,CAAO,MAAA,CAAO,SAAS,EAAE,IAAA,EAAM,WAAW,CAAA;AAC7F,EAAA,OAAO,WAAA;AACT;AAEA,SAAS,YAAA,CAAa,GAAuB,IAAA,EAAmC;AAC9E,EAAA,IAAI,OAAO,CAAA,KAAM,QAAA,IAAY,CAAA,KAAM,EAAA,EAAI;AACrC,IAAA,MAAM,IAAI,YAAY,EAAE,IAAA,EAAM,KAAK,OAAA,EAAS,CAAA,2BAAA,EAA8B,IAAI,CAAA,gBAAA,CAAA,EAAoB,CAAA;AAAA,EACpG;AACF;AAEA,SAAS,MAAM,EAAA,EAA2B;AACxC,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,YAAY,UAAA,CAAW,OAAA,EAAS,EAAE,CAAC,CAAA;AACzD","file":"index.js","sourcesContent":["'use client';\n\n/**\n * `<AlmadarApp />` — renders an orbital schema in the customer's React tree.\n *\n * Thin facade over `@almadar/ui`'s `OrbPreview` (server-backed) and\n * `BrowserPlayground` (in-browser mock server). The `mode` prop picks the\n * runtime path:\n * - `static`: pure OrbPreview with `mockData`\n * - `mock` : BrowserPlayground (in-browser server, faker-seeded)\n * - `server`: OrbPreview with `serverUrl`\n *\n * Lazy-imports the heavy runtime bundle so the SDK is import-cheap in Next.js\n * server components; the actual render happens client-side under a Suspense\n * boundary. CSS is imported as a side-effect at module load.\n */\n\nimport { lazy, forwardRef, Suspense, useImperativeHandle, useRef } from 'react';\nimport type { EventPayload } from '@almadar/core';\nimport type { AlmadarAppProps, AlmadarAppRef } from '../types';\n// Required global styles. Customers who self-manage Tailwind can import from\n// the (forthcoming) `@almadar/sdk/react/no-css` entry instead.\nimport '@almadar/ui/index.css';\n\nconst OrbPreviewLazy = lazy(async () => {\n const mod = await import('@almadar/ui/runtime');\n return { default: mod.OrbPreview };\n});\n\nconst BrowserPlaygroundLazy = lazy(async () => {\n const mod = await import('@almadar/ui/runtime');\n return { default: mod.BrowserPlayground };\n});\n\nexport const AlmadarApp = forwardRef<AlmadarAppRef, AlmadarAppProps>(function AlmadarApp(\n props,\n ref,\n) {\n const emitterRef = useRef<((event: string, payload?: EventPayload) => void) | null>(null);\n\n useImperativeHandle(ref, () => ({\n emit(event, payload) {\n if (emitterRef.current === null) return;\n emitterRef.current(event, payload);\n },\n }));\n\n const mode = props.mode ?? 'static';\n\n return (\n <Suspense fallback={null}>\n {mode === 'mock' ? (\n <BrowserPlaygroundLazy\n schema={props.schema}\n mode=\"mock\"\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n ) : (\n <OrbPreviewLazy\n schema={props.schema}\n mockData={props.data}\n serverUrl={props.serverUrl}\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n )}\n </Suspense>\n );\n});\n\nAlmadarApp.displayName = 'AlmadarApp';\n","/**\n * Typed SDK errors. Server emits a structured `ApiErrorBody`; the HTTP layer\n * maps the `code` to one of these subclasses. Customers `catch` by class.\n */\n\nimport type { ApiErrorBody } from '../types';\n\nexport class AlmadarError extends Error {\n readonly code: number;\n readonly details?: ApiErrorBody['details'];\n constructor(body: ApiErrorBody) {\n super(body.message);\n this.name = 'AlmadarError';\n this.code = body.code;\n this.details = body.details;\n }\n}\n\n/** 4001 — invalid, revoked, or missing API key. */\nexport class ApiKeyError extends AlmadarError {\n constructor(body: ApiErrorBody) {\n super(body);\n this.name = 'ApiKeyError';\n }\n}\n\n/** 4029 — team cap (feature counter) exceeded. Retry after a billing cycle. */\nexport class RateLimitedError extends AlmadarError {\n readonly retryAfterSeconds?: number;\n constructor(body: ApiErrorBody, retryAfterSeconds?: number) {\n super(body);\n this.name = 'RateLimitedError';\n this.retryAfterSeconds = retryAfterSeconds;\n }\n}\n\n/** 4040 — the team's behavior catalog (subset/replace mode) cannot serve the request. */\nexport class CatalogOutOfScopeError extends AlmadarError {\n constructor(body: ApiErrorBody) {\n super(body);\n this.name = 'CatalogOutOfScopeError';\n }\n}\n\n/** Anything else from the server with a recognized envelope but no specific subclass. */\nexport class ServerError extends AlmadarError {\n constructor(body: ApiErrorBody) {\n super(body);\n this.name = 'ServerError';\n }\n}\n\nexport function errorFromBody(body: ApiErrorBody): AlmadarError {\n switch (body.code) {\n case 4001:\n return new ApiKeyError(body);\n case 4029:\n return new RateLimitedError(body);\n case 4040:\n return new CatalogOutOfScopeError(body);\n default:\n return new ServerError(body);\n }\n}\n","/**\n * Minimal Server-Sent Events parser. Reads a `ReadableStream<Uint8Array>`\n * (the body of a `fetch` Response) and yields decoded events. Universal:\n * works in browser, Node 18+, Deno, Bun.\n *\n * Spec subset implemented:\n * - `event:` and `data:` fields\n * - dispatch on blank line\n * - newline-tolerant (CRLF + LF)\n * - skips comments (`:`-prefixed lines)\n *\n * Not implemented (we don't need them):\n * - `id:` / `retry:` fields\n * - reconnection / last-event-id\n */\n\nexport interface RawSseEvent {\n /** `event:` field value. Empty string when absent — matches the spec default. */\n event: string;\n /** Concatenated `data:` lines, joined by newlines. */\n data: string;\n}\n\nexport async function* parseSSE(\n stream: ReadableStream<Uint8Array>,\n): AsyncGenerator<RawSseEvent, void, void> {\n const reader = stream.getReader();\n const decoder = new TextDecoder('utf-8');\n let buffer = '';\n let currentEvent = '';\n let currentData = '';\n\n try {\n for (;;) {\n const { value, done } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n\n let newlineIdx: number;\n while ((newlineIdx = indexOfNewline(buffer)) !== -1) {\n const rawLine = buffer.slice(0, newlineIdx);\n buffer = buffer.slice(newlineIdx + (buffer[newlineIdx] === '\\r' && buffer[newlineIdx + 1] === '\\n' ? 2 : 1));\n\n if (rawLine === '') {\n if (currentData !== '' || currentEvent !== '') {\n yield { event: currentEvent, data: currentData };\n currentEvent = '';\n currentData = '';\n }\n continue;\n }\n if (rawLine.startsWith(':')) continue;\n\n const colon = rawLine.indexOf(':');\n const field = colon === -1 ? rawLine : rawLine.slice(0, colon);\n const rawValue = colon === -1 ? '' : rawLine.slice(colon + 1);\n const value2 = rawValue.startsWith(' ') ? rawValue.slice(1) : rawValue;\n\n if (field === 'event') {\n currentEvent = value2;\n } else if (field === 'data') {\n currentData = currentData === '' ? value2 : `${currentData}\\n${value2}`;\n }\n }\n }\n if (currentData !== '' || currentEvent !== '') {\n yield { event: currentEvent, data: currentData };\n }\n } finally {\n reader.releaseLock();\n }\n}\n\nfunction indexOfNewline(s: string): number {\n for (let i = 0; i < s.length; i += 1) {\n const c = s[i];\n if (c === '\\n' || c === '\\r') return i;\n }\n return -1;\n}\n","/**\n * `AlmadarClient` — server / Node-side HTTP client targeting `/api/v1/agent/*`.\n * Authenticates with a team-bound API key (`sk_*`) issued from\n * Studio's `/settings/sdk` panel. See `docs/Almadar_Studio_SDK.md` §5.\n *\n * Never instantiate this in a browser bundle — `apiKey` must never leave\n * the customer's server.\n */\n\nimport type { OrbitalSchema } from '@almadar/core';\nimport type {\n AgentEvent,\n AlmadarClientOptions,\n ApiErrorBody,\n AsyncJobHandle,\n CompileOptions,\n CompileResult,\n EditSchemaPatch,\n GenerateOptions,\n GenerateResult,\n} from '../types';\nimport { errorFromBody, ServerError } from './errors';\nimport { parseSSE } from './sseParser';\n\nconst DEFAULT_BASE_URL = 'https://api.almadar.io';\nconst POLL_BACKOFF_MS: readonly number[] = [1000, 2000, 5000, 10_000, 30_000];\n\ninterface JobStatus {\n state: 'pending' | 'complete' | 'error';\n events?: readonly AgentEvent[];\n result?: GenerateResult;\n errorCode?: number;\n errorMessage?: string;\n}\n\nexport class AlmadarClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(opts: AlmadarClientOptions) {\n if (!opts.apiKey || typeof opts.apiKey !== 'string') {\n throw new Error('AlmadarClient: opts.apiKey is required');\n }\n this.apiKey = opts.apiKey;\n this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '');\n this.fetchImpl = opts.fetch ?? globalThis.fetch;\n if (typeof this.fetchImpl !== 'function') {\n throw new Error('AlmadarClient: no fetch available — pass opts.fetch for Node <18');\n }\n }\n\n async generate(input: GenerateOptions): Promise<GenerateResult> {\n if (input.async === true) {\n const handle = await this.requestJson<AsyncJobHandle>('POST', '/api/v1/agent/generate', {\n prompt: input.prompt,\n endUserId: input.endUserId,\n appId: input.appId,\n async: true,\n });\n assertString(handle.jobId, 'AsyncJobHandle.jobId');\n assertString(handle.statusUrl, 'AsyncJobHandle.statusUrl');\n return this.pollUntilComplete(handle, input.onEvent);\n }\n return this.streamGenerate(input);\n }\n\n async editSchema(appId: string, patch: EditSchemaPatch): Promise<OrbitalSchema> {\n if (!appId) throw new Error('AlmadarClient.editSchema: appId is required');\n const schema = await this.requestJson<OrbitalSchema>('PUT', '/api/v1/agent/edit-schema', {\n appId,\n patch,\n });\n assertString(schema.name, 'OrbitalSchema.name');\n return schema;\n }\n\n async compileToApp(schema: OrbitalSchema, opts?: CompileOptions): Promise<CompileResult> {\n const result = await this.requestJson<CompileResult>('POST', '/api/v1/agent/compile', {\n schema,\n target: opts?.target,\n shell: opts?.shell,\n });\n assertString(result.downloadUrl, 'CompileResult.downloadUrl');\n assertString(result.expiresAt, 'CompileResult.expiresAt');\n return result;\n }\n\n private async streamGenerate(input: GenerateOptions): Promise<GenerateResult> {\n const res = await this.fetchImpl(`${this.baseUrl}/api/v1/agent/generate`, {\n method: 'POST',\n headers: this.headers({ accept: 'text/event-stream', contentType: 'application/json' }, input.endUserId),\n body: JSON.stringify({\n prompt: input.prompt,\n endUserId: input.endUserId,\n appId: input.appId,\n }),\n });\n if (!res.ok) throw await this.errorFromResponse(res);\n if (res.body === null) throw new Error('AlmadarClient.generate: server returned no body');\n\n let final: GenerateResult | null = null;\n for await (const raw of parseSSE(res.body)) {\n const event = parseAgentEvent(raw.event, raw.data);\n if (event === null) continue;\n input.onEvent?.(event);\n if (event.type === 'complete') {\n final = { schema: event.schema, appId: event.appId };\n } else if (event.type === 'error') {\n throw errorFromBody({ code: event.code ?? 500, message: event.message });\n }\n }\n if (final === null) {\n throw new ServerError({ code: 500, message: 'SSE stream ended without `complete` event' });\n }\n return final;\n }\n\n private async pollUntilComplete(\n handle: AsyncJobHandle,\n onEvent: GenerateOptions['onEvent'],\n ): Promise<GenerateResult> {\n let attempt = 0;\n for (;;) {\n const delay = POLL_BACKOFF_MS[Math.min(attempt, POLL_BACKOFF_MS.length - 1)];\n await sleep(delay);\n attempt += 1;\n const status = await this.requestJson<JobStatus>('GET', handle.statusUrl);\n assertString(status.state, 'JobStatus.state');\n if (status.events !== undefined && onEvent !== undefined) {\n for (const e of status.events) onEvent(e);\n }\n if (status.state === 'complete') {\n if (status.result === undefined) {\n throw new ServerError({ code: 500, message: 'Job complete but no result returned' });\n }\n return status.result;\n }\n if (status.state === 'error') {\n throw errorFromBody({\n code: status.errorCode ?? 500,\n message: status.errorMessage ?? 'Job failed',\n });\n }\n }\n }\n\n private async requestJson<T>(method: string, path: string, body?: object): Promise<T> {\n const isAbsolute = path.startsWith('http://') || path.startsWith('https://');\n const url = isAbsolute ? path : `${this.baseUrl}${path}`;\n const init: RequestInit = {\n method,\n headers: this.headers({\n accept: 'application/json',\n contentType: body !== undefined ? 'application/json' : undefined,\n }),\n };\n if (body !== undefined) init.body = JSON.stringify(body);\n const res = await this.fetchImpl(url, init);\n if (!res.ok) throw await this.errorFromResponse(res);\n const text = await res.text();\n if (text === '') {\n throw new ServerError({ code: 500, message: 'Empty response body' });\n }\n const parsed: T = JSON.parse(text);\n return parsed;\n }\n\n private headers(\n opts: { accept?: string; contentType?: string },\n endUserId?: string,\n ): Record<string, string> {\n const h: Record<string, string> = { authorization: `Bearer ${this.apiKey}` };\n if (opts.accept !== undefined) h['accept'] = opts.accept;\n if (opts.contentType !== undefined) h['content-type'] = opts.contentType;\n if (endUserId !== undefined && endUserId !== '') h['x-end-user-id'] = endUserId;\n return h;\n }\n\n private async errorFromResponse(res: Response): Promise<Error> {\n const text = await res.text();\n let body: ApiErrorBody;\n try {\n const parsed: ApiErrorBody | null = text === '' ? null : JSON.parse(text);\n body = parsed !== null && typeof parsed.code === 'number' && typeof parsed.message === 'string'\n ? parsed\n : {\n code: res.status,\n message: res.statusText !== '' ? res.statusText : 'HTTP error',\n };\n } catch {\n body = { code: res.status, message: text !== '' ? text : res.statusText };\n }\n const retryAfter = res.headers.get('retry-after');\n const err = errorFromBody(body);\n if (err.name === 'RateLimitedError' && retryAfter !== null) {\n const seconds = Number(retryAfter);\n if (Number.isFinite(seconds)) {\n Object.defineProperty(err, 'retryAfterSeconds', { value: seconds, enumerable: true });\n }\n }\n return err;\n }\n}\n\nfunction parseAgentEvent(eventName: string, dataLine: string): AgentEvent | null {\n if (dataLine === '') return null;\n let payload: AgentEvent | null;\n try {\n payload = JSON.parse(dataLine);\n } catch {\n return null;\n }\n if (payload === null || typeof payload !== 'object') return null;\n if (typeof payload.type === 'string') return payload;\n if (eventName === '') return null;\n // Server sent only an `event:` field name — write `type` onto the payload.\n // Mutating the parsed result is safe because we own it.\n const synthesized: AgentEvent & { type: string } = Object.assign(payload, { type: eventName });\n return synthesized;\n}\n\nfunction assertString(v: string | undefined, name: string): asserts v is string {\n if (typeof v !== 'string' || v === '') {\n throw new ServerError({ code: 500, message: `Malformed server response: ${name} is not a string` });\n }\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { a as AlmadarAppProps, b as AlmadarAppRef } from '../types-BfWDIOGm.js';
|
|
3
|
+
export { A as AgentEvent } from '../types-BfWDIOGm.js';
|
|
4
|
+
export { useEventBus as useOrbBus } from '@almadar/ui/hooks';
|
|
5
|
+
export { EntityData, EventPayload, OrbitalSchema } from '@almadar/core';
|
|
6
|
+
|
|
7
|
+
declare const AlmadarApp: react.ForwardRefExoticComponent<AlmadarAppProps & react.RefAttributes<AlmadarAppRef>>;
|
|
8
|
+
|
|
9
|
+
export { AlmadarApp, AlmadarAppProps, AlmadarAppRef };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { lazy, forwardRef, useRef, useImperativeHandle, Suspense } from 'react';
|
|
2
|
+
import '@almadar/ui/index.css';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
export { useEventBus as useOrbBus } from '@almadar/ui/hooks';
|
|
5
|
+
|
|
6
|
+
// src/react/AlmadarApp.tsx
|
|
7
|
+
var OrbPreviewLazy = lazy(async () => {
|
|
8
|
+
const mod = await import('@almadar/ui/runtime');
|
|
9
|
+
return { default: mod.OrbPreview };
|
|
10
|
+
});
|
|
11
|
+
var BrowserPlaygroundLazy = lazy(async () => {
|
|
12
|
+
const mod = await import('@almadar/ui/runtime');
|
|
13
|
+
return { default: mod.BrowserPlayground };
|
|
14
|
+
});
|
|
15
|
+
var AlmadarApp = forwardRef(function AlmadarApp2(props, ref) {
|
|
16
|
+
const emitterRef = useRef(null);
|
|
17
|
+
useImperativeHandle(ref, () => ({
|
|
18
|
+
emit(event, payload) {
|
|
19
|
+
if (emitterRef.current === null) return;
|
|
20
|
+
emitterRef.current(event, payload);
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
const mode = props.mode ?? "static";
|
|
24
|
+
return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: mode === "mock" ? /* @__PURE__ */ jsx(
|
|
25
|
+
BrowserPlaygroundLazy,
|
|
26
|
+
{
|
|
27
|
+
schema: props.schema,
|
|
28
|
+
mode: "mock",
|
|
29
|
+
initialPagePath: props.initialPagePath,
|
|
30
|
+
height: props.height,
|
|
31
|
+
className: props.className
|
|
32
|
+
}
|
|
33
|
+
) : /* @__PURE__ */ jsx(
|
|
34
|
+
OrbPreviewLazy,
|
|
35
|
+
{
|
|
36
|
+
schema: props.schema,
|
|
37
|
+
mockData: props.data,
|
|
38
|
+
serverUrl: props.serverUrl,
|
|
39
|
+
initialPagePath: props.initialPagePath,
|
|
40
|
+
height: props.height,
|
|
41
|
+
className: props.className
|
|
42
|
+
}
|
|
43
|
+
) });
|
|
44
|
+
});
|
|
45
|
+
AlmadarApp.displayName = "AlmadarApp";
|
|
46
|
+
|
|
47
|
+
export { AlmadarApp };
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/AlmadarApp.tsx"],"names":["AlmadarApp"],"mappings":";;;;;;AAwBA,IAAM,cAAA,GAAiB,KAAK,YAAY;AACtC,EAAA,MAAM,GAAA,GAAM,MAAM,OAAO,qBAAqB,CAAA;AAC9C,EAAA,OAAO,EAAE,OAAA,EAAS,GAAA,CAAI,UAAA,EAAW;AACnC,CAAC,CAAA;AAED,IAAM,qBAAA,GAAwB,KAAK,YAAY;AAC7C,EAAA,MAAM,GAAA,GAAM,MAAM,OAAO,qBAAqB,CAAA;AAC9C,EAAA,OAAO,EAAE,OAAA,EAAS,GAAA,CAAI,iBAAA,EAAkB;AAC1C,CAAC,CAAA;AAEM,IAAM,UAAA,GAAa,UAAA,CAA2C,SAASA,WAAAA,CAC5E,OACA,GAAA,EACA;AACA,EAAA,MAAM,UAAA,GAAa,OAAiE,IAAI,CAAA;AAExF,EAAA,mBAAA,CAAoB,KAAK,OAAO;AAAA,IAC9B,IAAA,CAAK,OAAO,OAAA,EAAS;AACnB,MAAA,IAAI,UAAA,CAAW,YAAY,IAAA,EAAM;AACjC,MAAA,UAAA,CAAW,OAAA,CAAQ,OAAO,OAAO,CAAA;AAAA,IACnC;AAAA,GACF,CAAE,CAAA;AAEF,EAAA,MAAM,IAAA,GAAO,MAAM,IAAA,IAAQ,QAAA;AAE3B,EAAA,uBACE,GAAA,CAAC,QAAA,EAAA,EAAS,QAAA,EAAU,IAAA,EACjB,mBAAS,MAAA,mBACR,GAAA;AAAA,IAAC,qBAAA;AAAA,IAAA;AAAA,MACC,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,IAAA,EAAK,MAAA;AAAA,MACL,iBAAiB,KAAA,CAAM,eAAA;AAAA,MACvB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,WAAW,KAAA,CAAM;AAAA;AAAA,GACnB,mBAEA,GAAA;AAAA,IAAC,cAAA;AAAA,IAAA;AAAA,MACC,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,UAAU,KAAA,CAAM,IAAA;AAAA,MAChB,WAAW,KAAA,CAAM,SAAA;AAAA,MACjB,iBAAiB,KAAA,CAAM,eAAA;AAAA,MACvB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,WAAW,KAAA,CAAM;AAAA;AAAA,GACnB,EAEJ,CAAA;AAEJ,CAAC;AAED,UAAA,CAAW,WAAA,GAAc,YAAA","file":"index.js","sourcesContent":["'use client';\n\n/**\n * `<AlmadarApp />` — renders an orbital schema in the customer's React tree.\n *\n * Thin facade over `@almadar/ui`'s `OrbPreview` (server-backed) and\n * `BrowserPlayground` (in-browser mock server). The `mode` prop picks the\n * runtime path:\n * - `static`: pure OrbPreview with `mockData`\n * - `mock` : BrowserPlayground (in-browser server, faker-seeded)\n * - `server`: OrbPreview with `serverUrl`\n *\n * Lazy-imports the heavy runtime bundle so the SDK is import-cheap in Next.js\n * server components; the actual render happens client-side under a Suspense\n * boundary. CSS is imported as a side-effect at module load.\n */\n\nimport { lazy, forwardRef, Suspense, useImperativeHandle, useRef } from 'react';\nimport type { EventPayload } from '@almadar/core';\nimport type { AlmadarAppProps, AlmadarAppRef } from '../types';\n// Required global styles. Customers who self-manage Tailwind can import from\n// the (forthcoming) `@almadar/sdk/react/no-css` entry instead.\nimport '@almadar/ui/index.css';\n\nconst OrbPreviewLazy = lazy(async () => {\n const mod = await import('@almadar/ui/runtime');\n return { default: mod.OrbPreview };\n});\n\nconst BrowserPlaygroundLazy = lazy(async () => {\n const mod = await import('@almadar/ui/runtime');\n return { default: mod.BrowserPlayground };\n});\n\nexport const AlmadarApp = forwardRef<AlmadarAppRef, AlmadarAppProps>(function AlmadarApp(\n props,\n ref,\n) {\n const emitterRef = useRef<((event: string, payload?: EventPayload) => void) | null>(null);\n\n useImperativeHandle(ref, () => ({\n emit(event, payload) {\n if (emitterRef.current === null) return;\n emitterRef.current(event, payload);\n },\n }));\n\n const mode = props.mode ?? 'static';\n\n return (\n <Suspense fallback={null}>\n {mode === 'mock' ? (\n <BrowserPlaygroundLazy\n schema={props.schema}\n mode=\"mock\"\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n ) : (\n <OrbPreviewLazy\n schema={props.schema}\n mockData={props.data}\n serverUrl={props.serverUrl}\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n )}\n </Suspense>\n );\n});\n\nAlmadarApp.displayName = 'AlmadarApp';\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { WorkspaceService } from '@almadar/workspace';
|
|
3
|
+
import { OrbitalSchema } from '@almadar/core';
|
|
4
|
+
import { ProviderConfig } from '@almadar/llm';
|
|
5
|
+
export { ProviderConfig } from '@almadar/llm';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `@almadar/sdk/server` — Express handler factories for the Almadar agent.
|
|
9
|
+
*
|
|
10
|
+
* Node-only. Never import this from browser or React code.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* import { createGenerateHandler, createEditHandler } from '@almadar/sdk/server';
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
interface GenerateHandlerOptions {
|
|
17
|
+
/** Open (or return) the workspace for this request. */
|
|
18
|
+
workspaceFactory: (req: Request) => Promise<WorkspaceService> | WorkspaceService;
|
|
19
|
+
/** LLM provider — defaults to `'deepseek'`. */
|
|
20
|
+
provider?: string;
|
|
21
|
+
/** LLM model — defaults to `'deepseek-v4-flash'`. */
|
|
22
|
+
model?: string;
|
|
23
|
+
/** Std-catalog scope forwarded to rabit. */
|
|
24
|
+
catalogScope?: {
|
|
25
|
+
mode: 'extend' | 'subset' | 'replace';
|
|
26
|
+
stdAllowList?: readonly string[];
|
|
27
|
+
};
|
|
28
|
+
/** Return explicit provider credentials for the given provider string. */
|
|
29
|
+
resolveProviderConfig?: (provider: string) => Promise<ProviderConfig | undefined> | ProviderConfig | undefined;
|
|
30
|
+
/** Called once with the final composed schema after a successful generate. */
|
|
31
|
+
onComplete?: (schema: OrbitalSchema, req: Request) => Promise<void> | void;
|
|
32
|
+
/** Derive a stable user id from the request — defaults to `'anonymous'`. */
|
|
33
|
+
userId?: (req: Request) => string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns an Express route handler that streams a rabit generation run as SSE.
|
|
37
|
+
*
|
|
38
|
+
* Body shape accepted:
|
|
39
|
+
* `{ prompt?: string; message?: string; provider?: string; model?: string; appId?: string }`
|
|
40
|
+
*
|
|
41
|
+
* SSE events emitted:
|
|
42
|
+
* `start` → trace fan-out → `complete | error | cancelled`
|
|
43
|
+
*/
|
|
44
|
+
declare function createGenerateHandler(opts: GenerateHandlerOptions): (req: Request, res: Response) => Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Returns an Express route handler that streams a contextual-edit run as SSE.
|
|
47
|
+
*
|
|
48
|
+
* Body shape accepted:
|
|
49
|
+
* `{ focus: EditFocus; instruction?: string; message?: string; provider?: string; model?: string }`
|
|
50
|
+
*
|
|
51
|
+
* The `focus` field must be a valid `EditFocus` (orbital + trait + patternType
|
|
52
|
+
* + path — see `@almadar/core`'s `EditFocus` type). The handler delegates
|
|
53
|
+
* entirely to `runContextualEdit` from `@almadar-io/rabit`.
|
|
54
|
+
*
|
|
55
|
+
* TODO: when `focus` is absent the handler falls back to a full-regeneration
|
|
56
|
+
* pass (`createGenerateHandler` semantics). Wire a dedicated delta-prompt edit
|
|
57
|
+
* path here once rabit exposes a `runDeltaEdit` entry point.
|
|
58
|
+
*/
|
|
59
|
+
declare function createEditHandler(opts: GenerateHandlerOptions): (req: Request, res: Response) => Promise<void>;
|
|
60
|
+
|
|
61
|
+
export { type GenerateHandlerOptions, createEditHandler, createGenerateHandler };
|