@almadar/sdk 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -5
- package/dist/{AlmadarApp-DgwtnIRy.d.ts → AlmadarApp-mS7H6kiA.d.ts} +1 -1
- package/dist/client/index.d.ts +20 -4
- package/dist/client/index.js +118 -53
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +120 -55
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +2 -2
- package/dist/react/index.js.map +1 -1
- package/dist/server/express.js +113 -52
- package/dist/server/express.js.map +1 -1
- package/dist/server/hono.js +113 -52
- package/dist/server/hono.js.map +1 -1
- package/dist/server/index.js +113 -52
- package/dist/server/index.js.map +1 -1
- package/dist/types-CVGXdQRM.d.ts +193 -0
- package/package.json +9 -7
- package/dist/types-C6RJADoY.d.ts +0 -125
package/dist/index.js
CHANGED
|
@@ -109,8 +109,8 @@ function AlmadarApp(props) {
|
|
|
109
109
|
useEffect(() => {
|
|
110
110
|
setControlledSchema(parsedSchema);
|
|
111
111
|
}, [parsedSchema]);
|
|
112
|
-
const
|
|
113
|
-
const
|
|
112
|
+
const showControls = props.showControls ?? (props.exposedTiers !== void 0 && props.exposedTiers.length > 0 && mode !== "server");
|
|
113
|
+
const effectiveSchema = showControls ? controlledSchema : parsedSchema;
|
|
114
114
|
const preview = mode === "mock" ? /* @__PURE__ */ jsx(
|
|
115
115
|
BrowserPlaygroundLazy,
|
|
116
116
|
{
|
|
@@ -157,6 +157,52 @@ function AlmadarApp(props) {
|
|
|
157
157
|
}
|
|
158
158
|
AlmadarApp.displayName = "AlmadarApp";
|
|
159
159
|
|
|
160
|
+
// src/types.ts
|
|
161
|
+
var CATALOG_MODES = ["extend", "subset", "replace"];
|
|
162
|
+
function isGenerateMetaOrganism(value) {
|
|
163
|
+
if (value === null || typeof value !== "object") return false;
|
|
164
|
+
const v = value;
|
|
165
|
+
if (typeof v.name !== "string") return false;
|
|
166
|
+
return v.source === "factory" || v.source === "free-lolo";
|
|
167
|
+
}
|
|
168
|
+
function isGenerateMetaCacheVerdict(value) {
|
|
169
|
+
if (value === null) return true;
|
|
170
|
+
if (typeof value !== "object") return false;
|
|
171
|
+
const v = value;
|
|
172
|
+
if (v.verdict !== "hit" && v.verdict !== "miss") return false;
|
|
173
|
+
return v.chosen === null || typeof v.chosen === "string";
|
|
174
|
+
}
|
|
175
|
+
function isGenerateMeta(value) {
|
|
176
|
+
if (value === null || typeof value !== "object") return false;
|
|
177
|
+
const v = value;
|
|
178
|
+
if (v.tier !== "confirmed" && v.tier !== "hit" && v.tier !== "miss") return false;
|
|
179
|
+
if (!Array.isArray(v.organisms) || !v.organisms.every(isGenerateMetaOrganism)) return false;
|
|
180
|
+
if (!Array.isArray(v.demoted) || !v.demoted.every((d) => typeof d === "string")) return false;
|
|
181
|
+
if (!isGenerateMetaCacheVerdict(v.cacheVerdict)) return false;
|
|
182
|
+
return typeof v.durationMs === "number";
|
|
183
|
+
}
|
|
184
|
+
var API_ERROR_CODES = {
|
|
185
|
+
INVALID_REQUEST: 4e3,
|
|
186
|
+
API_KEY: 4001,
|
|
187
|
+
ORIGIN_FORBIDDEN: 4003,
|
|
188
|
+
EDIT_CONFIRM_REQUIRED: 4009,
|
|
189
|
+
RATE_LIMITED: 4029,
|
|
190
|
+
CATALOG_OUT_OF_SCOPE: 4040,
|
|
191
|
+
PIN_UNKNOWN_ORGANISM: 4041,
|
|
192
|
+
PIN_OUT_OF_SCOPE: 4042,
|
|
193
|
+
PIN_CONFLICT: 4043,
|
|
194
|
+
PIN_UNKNOWN_KNOB: 4044,
|
|
195
|
+
PIN_ORBITAL_REQUIRED: 4045,
|
|
196
|
+
ASYNC_UNSUPPORTED: 4060,
|
|
197
|
+
FOCUS_STALE: 4090,
|
|
198
|
+
SERVER: 5e3,
|
|
199
|
+
GENERATION_FAILED: 5001,
|
|
200
|
+
RUNTIME: 5002,
|
|
201
|
+
WORKSPACE_OPEN: 5003,
|
|
202
|
+
AI_UNCONFIGURED: 5030
|
|
203
|
+
};
|
|
204
|
+
var STREAM_ERROR_CODES = ["failed", "runtime", "workspace_open", "ai_unconfigured", "focus_stale"];
|
|
205
|
+
|
|
160
206
|
// src/client/errors.ts
|
|
161
207
|
var AlmadarError = class extends Error {
|
|
162
208
|
code;
|
|
@@ -194,18 +240,68 @@ var ServerError = class extends AlmadarError {
|
|
|
194
240
|
this.name = "ServerError";
|
|
195
241
|
}
|
|
196
242
|
};
|
|
243
|
+
var PinError = class extends AlmadarError {
|
|
244
|
+
constructor(body) {
|
|
245
|
+
super(body);
|
|
246
|
+
this.name = "PinError";
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
var AsyncUnsupportedError = class extends AlmadarError {
|
|
250
|
+
constructor(body) {
|
|
251
|
+
super(body);
|
|
252
|
+
this.name = "AsyncUnsupportedError";
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
var GenerationFailedError = class extends AlmadarError {
|
|
256
|
+
constructor(body) {
|
|
257
|
+
super(body);
|
|
258
|
+
this.name = "GenerationFailedError";
|
|
259
|
+
}
|
|
260
|
+
};
|
|
197
261
|
function errorFromBody(body) {
|
|
198
262
|
switch (body.code) {
|
|
199
|
-
case
|
|
263
|
+
case API_ERROR_CODES.API_KEY:
|
|
200
264
|
return new ApiKeyError(body);
|
|
201
|
-
case
|
|
265
|
+
case API_ERROR_CODES.RATE_LIMITED:
|
|
202
266
|
return new RateLimitedError(body);
|
|
203
|
-
case
|
|
267
|
+
case API_ERROR_CODES.CATALOG_OUT_OF_SCOPE:
|
|
204
268
|
return new CatalogOutOfScopeError(body);
|
|
269
|
+
case API_ERROR_CODES.PIN_UNKNOWN_ORGANISM:
|
|
270
|
+
case API_ERROR_CODES.PIN_OUT_OF_SCOPE:
|
|
271
|
+
case API_ERROR_CODES.PIN_CONFLICT:
|
|
272
|
+
case API_ERROR_CODES.PIN_UNKNOWN_KNOB:
|
|
273
|
+
case API_ERROR_CODES.PIN_ORBITAL_REQUIRED:
|
|
274
|
+
return new PinError(body);
|
|
275
|
+
case API_ERROR_CODES.ASYNC_UNSUPPORTED:
|
|
276
|
+
return new AsyncUnsupportedError(body);
|
|
277
|
+
case API_ERROR_CODES.GENERATION_FAILED:
|
|
278
|
+
return new GenerationFailedError(body);
|
|
205
279
|
default:
|
|
206
280
|
return new ServerError(body);
|
|
207
281
|
}
|
|
208
282
|
}
|
|
283
|
+
function isStreamErrorCode(code) {
|
|
284
|
+
if (code === void 0) return false;
|
|
285
|
+
return STREAM_ERROR_CODES.some((c) => c === code);
|
|
286
|
+
}
|
|
287
|
+
function streamErrorFromEvent(data) {
|
|
288
|
+
const message = data.error;
|
|
289
|
+
if (!isStreamErrorCode(data.code)) {
|
|
290
|
+
return new ServerError({ code: API_ERROR_CODES.SERVER, message });
|
|
291
|
+
}
|
|
292
|
+
switch (data.code) {
|
|
293
|
+
case "failed":
|
|
294
|
+
return new GenerationFailedError({ code: API_ERROR_CODES.GENERATION_FAILED, message });
|
|
295
|
+
case "ai_unconfigured":
|
|
296
|
+
return new ServerError({ code: API_ERROR_CODES.AI_UNCONFIGURED, message });
|
|
297
|
+
case "workspace_open":
|
|
298
|
+
return new ServerError({ code: API_ERROR_CODES.WORKSPACE_OPEN, message });
|
|
299
|
+
case "focus_stale":
|
|
300
|
+
return new ServerError({ code: API_ERROR_CODES.FOCUS_STALE, message });
|
|
301
|
+
case "runtime":
|
|
302
|
+
return new ServerError({ code: API_ERROR_CODES.RUNTIME, message });
|
|
303
|
+
}
|
|
304
|
+
}
|
|
209
305
|
|
|
210
306
|
// src/client/sseParser.ts
|
|
211
307
|
async function* parseSSE(stream) {
|
|
@@ -261,7 +357,6 @@ function indexOfNewline(s) {
|
|
|
261
357
|
|
|
262
358
|
// src/client/AlmadarClient.ts
|
|
263
359
|
var DEFAULT_BASE_URL = "https://studio.almadar.io";
|
|
264
|
-
var POLL_BACKOFF_MS = [1e3, 2e3, 5e3, 1e4, 3e4];
|
|
265
360
|
var AlmadarClient = class {
|
|
266
361
|
apiKey;
|
|
267
362
|
baseUrl;
|
|
@@ -279,19 +374,10 @@ var AlmadarClient = class {
|
|
|
279
374
|
}
|
|
280
375
|
async generate(input) {
|
|
281
376
|
if (input.async === true) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
appId: input.appId,
|
|
286
|
-
async: true,
|
|
287
|
-
provider: input.provider,
|
|
288
|
-
model: input.model,
|
|
289
|
-
catalogMode: input.catalogMode,
|
|
290
|
-
stdAllowList: input.stdAllowList
|
|
377
|
+
throw new AsyncUnsupportedError({
|
|
378
|
+
code: API_ERROR_CODES.ASYNC_UNSUPPORTED,
|
|
379
|
+
message: "AlmadarClient has no async job surface. Omit `async` (or pass false) and consume the streaming response via `onEvent` instead."
|
|
291
380
|
});
|
|
292
|
-
assertString(handle.jobId, "AsyncJobHandle.jobId");
|
|
293
|
-
assertString(handle.statusUrl, "AsyncJobHandle.statusUrl");
|
|
294
|
-
return this.pollUntilComplete(handle, input.onEvent);
|
|
295
381
|
}
|
|
296
382
|
return this.streamGenerate(input);
|
|
297
383
|
}
|
|
@@ -325,56 +411,35 @@ var AlmadarClient = class {
|
|
|
325
411
|
provider: input.provider,
|
|
326
412
|
model: input.model,
|
|
327
413
|
catalogMode: input.catalogMode,
|
|
328
|
-
stdAllowList: input.stdAllowList
|
|
414
|
+
stdAllowList: input.stdAllowList,
|
|
415
|
+
pin: input.pin
|
|
329
416
|
})
|
|
330
417
|
});
|
|
331
418
|
if (!res.ok) throw await this.errorFromResponse(res);
|
|
332
419
|
if (res.body === null) throw new Error("AlmadarClient.generate: server returned no body");
|
|
333
420
|
let final = null;
|
|
421
|
+
let meta;
|
|
334
422
|
for await (const raw of parseSSE(res.body)) {
|
|
335
423
|
const event = parseSseEvent(raw.data);
|
|
336
424
|
if (event === null) continue;
|
|
337
425
|
input.onEvent?.(event);
|
|
338
|
-
if (event.type === "
|
|
426
|
+
if (event.type === "generation_meta") {
|
|
427
|
+
meta = event.data;
|
|
428
|
+
} else if (event.type === "complete") {
|
|
339
429
|
if (event.data.schema === void 0) {
|
|
340
|
-
throw new ServerError({ code:
|
|
430
|
+
throw new ServerError({ code: API_ERROR_CODES.SERVER, message: "`complete` event did not contain a schema" });
|
|
341
431
|
}
|
|
342
432
|
const schema = parseOrbitalSchema(event.data.schema);
|
|
343
|
-
final = { schema, appId: event.data.appId };
|
|
433
|
+
final = { schema, appId: event.data.appId, meta };
|
|
344
434
|
} else if (event.type === "error") {
|
|
345
|
-
throw
|
|
435
|
+
throw streamErrorFromEvent(event.data);
|
|
346
436
|
}
|
|
347
437
|
}
|
|
348
438
|
if (final === null) {
|
|
349
|
-
throw new ServerError({ code:
|
|
439
|
+
throw new ServerError({ code: API_ERROR_CODES.SERVER, message: "SSE stream ended without `complete` event" });
|
|
350
440
|
}
|
|
351
441
|
return final;
|
|
352
442
|
}
|
|
353
|
-
async pollUntilComplete(handle, onEvent) {
|
|
354
|
-
let attempt = 0;
|
|
355
|
-
for (; ; ) {
|
|
356
|
-
const delay = POLL_BACKOFF_MS[Math.min(attempt, POLL_BACKOFF_MS.length - 1)];
|
|
357
|
-
await sleep(delay);
|
|
358
|
-
attempt += 1;
|
|
359
|
-
const status = await this.requestJson("GET", handle.statusUrl);
|
|
360
|
-
assertString(status.state, "JobStatus.state");
|
|
361
|
-
if (status.events !== void 0 && onEvent !== void 0) {
|
|
362
|
-
for (const e of status.events) onEvent(e);
|
|
363
|
-
}
|
|
364
|
-
if (status.state === "complete") {
|
|
365
|
-
if (status.result === void 0) {
|
|
366
|
-
throw new ServerError({ code: 500, message: "Job complete but no result returned" });
|
|
367
|
-
}
|
|
368
|
-
return status.result;
|
|
369
|
-
}
|
|
370
|
-
if (status.state === "error") {
|
|
371
|
-
throw errorFromBody({
|
|
372
|
-
code: status.errorCode ?? 500,
|
|
373
|
-
message: status.errorMessage ?? "Job failed"
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
443
|
async requestJson(method, path, body) {
|
|
379
444
|
const isAbsolute = path.startsWith("http://") || path.startsWith("https://");
|
|
380
445
|
const url = isAbsolute ? path : `${this.baseUrl}${path}`;
|
|
@@ -390,7 +455,7 @@ var AlmadarClient = class {
|
|
|
390
455
|
if (!res.ok) throw await this.errorFromResponse(res);
|
|
391
456
|
const text = await res.text();
|
|
392
457
|
if (text === "") {
|
|
393
|
-
throw new ServerError({ code:
|
|
458
|
+
throw new ServerError({ code: API_ERROR_CODES.SERVER, message: "Empty response body" });
|
|
394
459
|
}
|
|
395
460
|
const parsed = JSON.parse(text);
|
|
396
461
|
return parsed;
|
|
@@ -435,17 +500,17 @@ function parseSseEvent(dataLine) {
|
|
|
435
500
|
}
|
|
436
501
|
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) return null;
|
|
437
502
|
if (typeof payload.type !== "string" || typeof payload.timestamp !== "number") return null;
|
|
503
|
+
if (payload.type === "generation_meta") {
|
|
504
|
+
return isGenerateMeta(payload.data) ? { type: "generation_meta", data: payload.data, timestamp: payload.timestamp } : null;
|
|
505
|
+
}
|
|
438
506
|
return payload;
|
|
439
507
|
}
|
|
440
508
|
function assertString(v, name) {
|
|
441
509
|
if (typeof v !== "string" || v === "") {
|
|
442
|
-
throw new ServerError({ code:
|
|
510
|
+
throw new ServerError({ code: API_ERROR_CODES.SERVER, message: `Malformed server response: ${name} is not a string` });
|
|
443
511
|
}
|
|
444
512
|
}
|
|
445
|
-
function sleep(ms) {
|
|
446
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
447
|
-
}
|
|
448
513
|
|
|
449
|
-
export { AlmadarApp, AlmadarClient, AlmadarError, ApiKeyError, CatalogOutOfScopeError, RateLimitedError, ServerError };
|
|
514
|
+
export { API_ERROR_CODES, AlmadarApp, AlmadarClient, AlmadarError, ApiKeyError, AsyncUnsupportedError, CATALOG_MODES, CatalogOutOfScopeError, GenerationFailedError, PinError, RateLimitedError, STREAM_ERROR_CODES, ServerError, isGenerateMeta, streamErrorFromEvent };
|
|
450
515
|
//# sourceMappingURL=index.js.map
|
|
451
516
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react/OrbitalConfigPanel.tsx","../src/react/AlmadarApp.tsx","../src/client/errors.ts","../src/client/sseParser.ts","../src/client/AlmadarClient.ts"],"names":["parseSchema","useMemo","useState","jsx","jsxs"],"mappings":";;;;;;;;AA4BA,SAAS,YAAY,MAAA,EAA+C;AAClE,EAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,IAAA,OAAO,IAAA,CAAK,MAAM,MAAM,CAAA;AAAA,EAC1B;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,UAAa,KAAA,EAAa;AACjC,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAA;AACzC;AAEA,SAAS,gBAAgB,MAAA,EAAwD;AAC/E,EAAA,IAAI,CAAC,MAAA,EAAQ,QAAA,EAAU,OAAO,IAAA;AAC9B,EAAA,KAAA,MAAW,OAAA,IAAW,OAAO,QAAA,EAAU;AACrC,IAAA,KAAA,MAAW,QAAA,IAAY,OAAA,CAAQ,MAAA,IAAU,EAAC,EAAG;AAC3C,MAAA,IAAI,OAAO,QAAA,KAAa,QAAA,IAAY,QAAA,KAAa,IAAA,EAAM;AACvD,MAAA,MAAM,KAAA,GAAQ,QAAA;AACd,MAAA,IAAI,KAAA,CAAM,UAAU,MAAA,CAAO,IAAA,CAAK,MAAM,MAAM,CAAA,CAAE,SAAS,CAAA,EAAG;AACxD,QAAA,MAAM,IAAA,GAAO,UAAU,KAAA,IAAS,OAAO,MAAM,IAAA,KAAS,QAAA,GAAW,MAAM,IAAA,GAAO,QAAA;AAC9E,QAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,KAA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,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 * OrbitalConfigPanel — auto-derived control rail for an orbital schema.\n *\n * Finds the first trait that declares a non-empty `config`, filters its fields\n * by the consumer-supplied `exposedTiers`, and renders `@almadar/ui`'s\n * `PropertyInspector`. Every control change deep-clones the schema, writes the\n * new value into the matching field's `default`, and emits the mutated schema\n * so the host can pass it to `OrbPreview`.\n */\n\nimport React, { useMemo, useState } from 'react';\nimport type {\n ConfigFieldDeclaration,\n DeclaredTraitConfig,\n OrbitalSchema,\n Trait,\n TraitConfigValue,\n} from '@almadar/core';\nimport { PropertyInspector } from '@almadar/ui/components';\nimport { Stack, Box, Typography } from '@almadar/ui/components';\n\ninterface ConfigTraitTarget {\n name: string;\n config: DeclaredTraitConfig;\n}\n\nfunction parseSchema(schema: string | OrbitalSchema): OrbitalSchema {\n if (typeof schema === 'string') {\n return JSON.parse(schema) as OrbitalSchema;\n }\n return schema;\n}\n\nfunction deepClone<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T;\n}\n\nfunction findConfigTrait(schema: OrbitalSchema | null): ConfigTraitTarget | null {\n if (!schema?.orbitals) return null;\n for (const orbital of schema.orbitals) {\n for (const traitRef of orbital.traits ?? []) {\n if (typeof traitRef !== 'object' || traitRef === null) continue;\n const trait = traitRef as Trait | { ref?: string; config?: DeclaredTraitConfig };\n if (trait.config && Object.keys(trait.config).length > 0) {\n const name = 'name' in trait && typeof trait.name === 'string' ? trait.name : 'Config';\n return { name, config: trait.config };\n }\n }\n }\n return null;\n}\n\nfunction applyConfigOverride(\n schema: OrbitalSchema,\n field: string,\n value: TraitConfigValue,\n): OrbitalSchema {\n const next = deepClone(schema);\n for (const orbital of next.orbitals ?? []) {\n for (const traitRef of orbital.traits ?? []) {\n if (typeof traitRef !== 'object' || traitRef === null) continue;\n const trait = traitRef as { config?: Record<string, ConfigFieldDeclaration> };\n if (trait.config && field in trait.config) {\n trait.config[field] = { ...trait.config[field], default: value };\n return next;\n }\n }\n }\n return next;\n}\n\nexport interface OrbitalConfigPanelProps {\n schema: string | OrbitalSchema;\n exposedTiers?: string[];\n position?: 'right' | 'bottom';\n onSchemaChange?: (schema: OrbitalSchema) => void;\n}\n\nexport function OrbitalConfigPanel({\n schema,\n exposedTiers,\n position = 'right',\n onSchemaChange,\n}: OrbitalConfigPanelProps): React.ReactElement | null {\n const parsed = useMemo(() => parseSchema(schema), [schema]);\n const target = useMemo(() => findConfigTrait(parsed), [parsed]);\n const [values, setValues] = useState<Record<string, TraitConfigValue>>({});\n\n if (!target) return null;\n\n const sortedConfig: DeclaredTraitConfig = Object.fromEntries(\n Object.entries(target.config).sort(([a], [b]) => a.localeCompare(b)),\n );\n\n const handleChange = (field: string, value: TraitConfigValue): void => {\n setValues((prev) => ({ ...prev, [field]: value }));\n const nextSchema = applyConfigOverride(parsed, field, value);\n onSchemaChange?.(nextSchema);\n };\n\n const handleReset = (): void => {\n setValues({});\n onSchemaChange?.(parsed);\n };\n\n const isHorizontal = position === 'bottom';\n\n return (\n <Box\n className={`${\n isHorizontal ? 'w-full border-t' : 'h-full w-80 flex-shrink-0 border-l'\n } border-border bg-card p-3 overflow-y-auto`}\n >\n <Stack direction=\"vertical\" gap=\"sm\">\n <Typography variant=\"caption\" weight=\"bold\" color=\"muted\">\n Controls\n </Typography>\n <PropertyInspector\n title={target.name}\n config={sortedConfig}\n values={values}\n onChange={handleChange}\n onReset={handleReset}\n tiers={exposedTiers}\n />\n </Stack>\n </Box>\n );\n}\n\nOrbitalConfigPanel.displayName = 'OrbitalConfigPanel';\n","'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, Suspense, useEffect, useMemo, useState } from 'react';\nimport type { AlmadarAppProps } from '../types';\nimport type { OrbitalSchema } from '@almadar/core';\nimport { OrbitalConfigPanel } from './OrbitalConfigPanel';\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\nfunction parseSchema(schema: string | OrbitalSchema): OrbitalSchema {\n if (typeof schema === 'string') {\n return JSON.parse(schema) as OrbitalSchema;\n }\n return schema;\n}\n\nexport function AlmadarApp(props: AlmadarAppProps) {\n const mode = props.mode ?? 'static';\n const parsedSchema = useMemo(() => parseSchema(props.schema), [props.schema]);\n const [controlledSchema, setControlledSchema] = useState<OrbitalSchema>(parsedSchema);\n\n // Reset controlled schema when the incoming schema changes.\n useEffect(() => {\n setControlledSchema(parsedSchema);\n }, [parsedSchema]);\n\n const effectiveSchema = props.exposedTiers && mode !== 'server' ? controlledSchema : parsedSchema;\n const showControls = props.exposedTiers && props.exposedTiers.length > 0 && mode !== 'server';\n\n const preview = mode === 'mock' ? (\n <BrowserPlaygroundLazy\n schema={effectiveSchema}\n mode=\"mock\"\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n ) : (\n <OrbPreviewLazy\n schema={effectiveSchema}\n mockData={props.data}\n serverUrl={props.serverUrl}\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n );\n\n if (!showControls) {\n return (\n <Suspense fallback={null}>\n {preview}\n </Suspense>\n );\n }\n\n const isBottom = props.controlsPosition === 'bottom';\n\n return (\n <Suspense fallback={null}>\n <div\n className={`flex ${isBottom ? 'flex-col' : 'flex-row'} w-full h-full`}\n style={{ height: props.height }}\n >\n <div className=\"flex-1 min-w-0\">\n {preview}\n </div>\n <OrbitalConfigPanel\n schema={parsedSchema}\n exposedTiers={props.exposedTiers}\n position={props.controlsPosition}\n onSchemaChange={setControlledSchema}\n />\n </div>\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 { parseOrbitalSchema, type OrbitalSchema, type SSEEvent } from '@almadar/core';\nimport type {\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://studio.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 SSEEvent[];\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 provider: input.provider,\n model: input.model,\n catalogMode: input.catalogMode,\n stdAllowList: input.stdAllowList,\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 provider: input.provider,\n model: input.model,\n catalogMode: input.catalogMode,\n stdAllowList: input.stdAllowList,\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 = parseSseEvent(raw.data);\n if (event === null) continue;\n input.onEvent?.(event);\n if (event.type === 'complete') {\n if (event.data.schema === undefined) {\n throw new ServerError({ code: 500, message: '`complete` event did not contain a schema' });\n }\n const schema = parseOrbitalSchema(event.data.schema);\n final = { schema, appId: event.data.appId };\n } else if (event.type === 'error') {\n throw errorFromBody({ code: 500, message: event.data.error });\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\n/**\n * Parse one SSE `data:` line into the canonical `SSEEvent` union.\n * The server is the trusted emitter, so we validate only the envelope\n * (object with string `type` and numeric `timestamp`) and cast to the\n * discriminated union. Malformed lines are ignored.\n */\nfunction parseSseEvent(dataLine: string): SSEEvent | null {\n if (dataLine === '') return null;\n let payload;\n try {\n payload = JSON.parse(dataLine);\n } catch {\n return null;\n }\n if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) return null;\n if (typeof payload.type !== 'string' || typeof payload.timestamp !== 'number') return null;\n return payload as SSEEvent;\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"]}
|
|
1
|
+
{"version":3,"sources":["../src/react/OrbitalConfigPanel.tsx","../src/react/AlmadarApp.tsx","../src/types.ts","../src/client/errors.ts","../src/client/sseParser.ts","../src/client/AlmadarClient.ts"],"names":["parseSchema","useMemo","useState","jsx","jsxs"],"mappings":";;;;;;;;AA4BA,SAAS,YAAY,MAAA,EAA+C;AAClE,EAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,IAAA,OAAO,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IAAI,CAAA,gBAAA,CAAA,EAAoB,CAAA;AAAA,EACvH;AACF","file":"index.js","sourcesContent":["'use client';\n\n/**\n * OrbitalConfigPanel — auto-derived control rail for an orbital schema.\n *\n * Finds the first trait that declares a non-empty `config`, filters its fields\n * by the consumer-supplied `exposedTiers`, and renders `@almadar/ui`'s\n * `PropertyInspector`. Every control change deep-clones the schema, writes the\n * new value into the matching field's `default`, and emits the mutated schema\n * so the host can pass it to `OrbPreview`.\n */\n\nimport React, { useMemo, useState } from 'react';\nimport type {\n ConfigFieldDeclaration,\n DeclaredTraitConfig,\n OrbitalSchema,\n Trait,\n TraitConfigValue,\n} from '@almadar/core';\nimport { PropertyInspector } from '@almadar/ui/components';\nimport { Stack, Box, Typography } from '@almadar/ui/components';\n\ninterface ConfigTraitTarget {\n name: string;\n config: DeclaredTraitConfig;\n}\n\nfunction parseSchema(schema: string | OrbitalSchema): OrbitalSchema {\n if (typeof schema === 'string') {\n return JSON.parse(schema) as OrbitalSchema;\n }\n return schema;\n}\n\nfunction deepClone<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T;\n}\n\nfunction findConfigTrait(schema: OrbitalSchema | null): ConfigTraitTarget | null {\n if (!schema?.orbitals) return null;\n for (const orbital of schema.orbitals) {\n for (const traitRef of orbital.traits ?? []) {\n if (typeof traitRef !== 'object' || traitRef === null) continue;\n const trait = traitRef as Trait | { ref?: string; config?: DeclaredTraitConfig };\n if (trait.config && Object.keys(trait.config).length > 0) {\n const name = 'name' in trait && typeof trait.name === 'string' ? trait.name : 'Config';\n return { name, config: trait.config };\n }\n }\n }\n return null;\n}\n\nfunction applyConfigOverride(\n schema: OrbitalSchema,\n field: string,\n value: TraitConfigValue,\n): OrbitalSchema {\n const next = deepClone(schema);\n for (const orbital of next.orbitals ?? []) {\n for (const traitRef of orbital.traits ?? []) {\n if (typeof traitRef !== 'object' || traitRef === null) continue;\n const trait = traitRef as { config?: Record<string, ConfigFieldDeclaration> };\n if (trait.config && field in trait.config) {\n trait.config[field] = { ...trait.config[field], default: value };\n return next;\n }\n }\n }\n return next;\n}\n\nexport interface OrbitalConfigPanelProps {\n schema: string | OrbitalSchema;\n exposedTiers?: string[];\n position?: 'right' | 'bottom';\n onSchemaChange?: (schema: OrbitalSchema) => void;\n}\n\nexport function OrbitalConfigPanel({\n schema,\n exposedTiers,\n position = 'right',\n onSchemaChange,\n}: OrbitalConfigPanelProps): React.ReactElement | null {\n const parsed = useMemo(() => parseSchema(schema), [schema]);\n const target = useMemo(() => findConfigTrait(parsed), [parsed]);\n const [values, setValues] = useState<Record<string, TraitConfigValue>>({});\n\n if (!target) return null;\n\n const sortedConfig: DeclaredTraitConfig = Object.fromEntries(\n Object.entries(target.config).sort(([a], [b]) => a.localeCompare(b)),\n );\n\n const handleChange = (field: string, value: TraitConfigValue): void => {\n setValues((prev) => ({ ...prev, [field]: value }));\n const nextSchema = applyConfigOverride(parsed, field, value);\n onSchemaChange?.(nextSchema);\n };\n\n const handleReset = (): void => {\n setValues({});\n onSchemaChange?.(parsed);\n };\n\n const isHorizontal = position === 'bottom';\n\n return (\n <Box\n className={`${\n isHorizontal ? 'w-full border-t' : 'h-full w-80 flex-shrink-0 border-l'\n } border-border bg-card p-3 overflow-y-auto`}\n >\n <Stack direction=\"vertical\" gap=\"sm\">\n <Typography variant=\"caption\" weight=\"bold\" color=\"muted\">\n Controls\n </Typography>\n <PropertyInspector\n title={target.name}\n config={sortedConfig}\n values={values}\n onChange={handleChange}\n onReset={handleReset}\n tiers={exposedTiers}\n />\n </Stack>\n </Box>\n );\n}\n\nOrbitalConfigPanel.displayName = 'OrbitalConfigPanel';\n","'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, Suspense, useEffect, useMemo, useState } from 'react';\nimport type { AlmadarAppProps } from '../types';\nimport type { OrbitalSchema } from '@almadar/core';\nimport { OrbitalConfigPanel } from './OrbitalConfigPanel';\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\nfunction parseSchema(schema: string | OrbitalSchema): OrbitalSchema {\n if (typeof schema === 'string') {\n return JSON.parse(schema) as OrbitalSchema;\n }\n return schema;\n}\n\nexport function AlmadarApp(props: AlmadarAppProps) {\n const mode = props.mode ?? 'static';\n const parsedSchema = useMemo(() => parseSchema(props.schema), [props.schema]);\n const [controlledSchema, setControlledSchema] = useState<OrbitalSchema>(parsedSchema);\n\n // Reset controlled schema when the incoming schema changes.\n useEffect(() => {\n setControlledSchema(parsedSchema);\n }, [parsedSchema]);\n\n const showControls =\n props.showControls ?? (props.exposedTiers !== undefined && props.exposedTiers.length > 0 && mode !== 'server');\n const effectiveSchema = showControls ? controlledSchema : parsedSchema;\n\n const preview = mode === 'mock' ? (\n <BrowserPlaygroundLazy\n schema={effectiveSchema}\n mode=\"mock\"\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n ) : (\n <OrbPreviewLazy\n schema={effectiveSchema}\n mockData={props.data}\n serverUrl={props.serverUrl}\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n );\n\n if (!showControls) {\n return (\n <Suspense fallback={null}>\n {preview}\n </Suspense>\n );\n }\n\n const isBottom = props.controlsPosition === 'bottom';\n\n return (\n <Suspense fallback={null}>\n <div\n className={`flex ${isBottom ? 'flex-col' : 'flex-row'} w-full h-full`}\n style={{ height: props.height }}\n >\n <div className=\"flex-1 min-w-0\">\n {preview}\n </div>\n <OrbitalConfigPanel\n schema={parsedSchema}\n exposedTiers={props.exposedTiers}\n position={props.controlsPosition}\n onSchemaChange={setControlledSchema}\n />\n </div>\n </Suspense>\n );\n}\n\nAlmadarApp.displayName = 'AlmadarApp';\n","/**\n * Public SDK types. Canonical schema / payload types come from `@almadar/core`;\n * the SDK adds the HTTP-layer option shapes and re-exports the canonical SSE\n * event union.\n */\n\nimport type { EntityData, EventPayload, OrbitalSchema, SSEEvent } from '@almadar/core';\n\nexport type { EntityData, EventPayload, OrbitalSchema, SSEEvent };\n\n/**\n * Typed request envelope for `createGenerateHandler`.\n * Body shape: `{ prompt: string; endUserId?: string; appId?: string }`\n */\nexport interface GenerateRequest {\n prompt?: string;\n /** Alias accepted alongside `prompt`. */\n message?: string;\n endUserId?: string;\n appId?: string;\n}\n\n/**\n * Typed request envelope for `createEditHandler`.\n * Body shape: `{ appId: string; patch: EditSchemaPatch }`\n */\nexport interface EditSchemaRequest {\n appId?: string;\n patch?: EditSchemaPatch;\n}\n\n/**\n * Server-emitted error envelope. `code` maps to the SDK error subclasses:\n * 4001 → ApiKeyError, 4029 → RateLimitedError, 4040 → CatalogOutOfScopeError,\n * 4041-4045 → PinError, 4060 → AsyncUnsupportedError, 5001 → GenerationFailedError.\n * See `API_ERROR_CODES` for the full code table.\n */\nexport interface ApiErrorBody {\n code: number;\n message: string;\n details?: EventPayload;\n}\n\nexport const CATALOG_MODES = ['extend', 'subset', 'replace'] as const;\nexport type CatalogMode = (typeof CATALOG_MODES)[number];\n\n/**\n * Pin generation to a specific organism (and, when the organism has more than\n * one factory orbital, the orbital to use). `knobs` fills factory config.\n */\nexport interface GeneratePin {\n organism: string;\n /** Required iff the organism has more than one orbital. */\n orbital?: string;\n appName?: string;\n knobs?: Record<string, string | number | boolean>;\n}\n\n/** Which cache tier served the generation — L1 confirmed factory HIT, HIT-fail demote, or free-compose MISS. */\nexport type GenerationTier = 'confirmed' | 'hit' | 'miss';\n\nexport interface GenerateMetaOrganism {\n name: string;\n source: 'factory' | 'free-lolo';\n}\n\nexport interface GenerateMeta {\n tier: GenerationTier;\n organisms: GenerateMetaOrganism[];\n /** Organism names that HIT-failed and were demoted to free-compose. */\n demoted: string[];\n cacheVerdict: { verdict: 'hit' | 'miss'; chosen: string | null } | null;\n durationMs: number;\n}\n\nexport interface GenerationMetaEvent {\n type: 'generation_meta';\n data: GenerateMeta;\n timestamp: number;\n}\n\n/** Canonical SSE events plus the SDK-only `generation_meta` summary event. */\nexport type GenerateStreamEvent = SSEEvent | GenerationMetaEvent;\n\nfunction isGenerateMetaOrganism(value: unknown): value is GenerateMetaOrganism {\n if (value === null || typeof value !== 'object') return false;\n const v = value as { name?: unknown; source?: unknown };\n if (typeof v.name !== 'string') return false;\n return v.source === 'factory' || v.source === 'free-lolo';\n}\n\nfunction isGenerateMetaCacheVerdict(value: unknown): value is GenerateMeta['cacheVerdict'] {\n if (value === null) return true;\n if (typeof value !== 'object') return false;\n const v = value as { verdict?: unknown; chosen?: unknown };\n if (v.verdict !== 'hit' && v.verdict !== 'miss') return false;\n return v.chosen === null || typeof v.chosen === 'string';\n}\n\n/** Runtime guard for the `generation_meta` SSE payload — the zero-cast bridge from JSON. */\nexport function isGenerateMeta(value: unknown): value is GenerateMeta {\n if (value === null || typeof value !== 'object') return false;\n const v = value as {\n tier?: unknown;\n organisms?: unknown;\n demoted?: unknown;\n cacheVerdict?: unknown;\n durationMs?: unknown;\n };\n if (v.tier !== 'confirmed' && v.tier !== 'hit' && v.tier !== 'miss') return false;\n if (!Array.isArray(v.organisms) || !v.organisms.every(isGenerateMetaOrganism)) return false;\n if (!Array.isArray(v.demoted) || !v.demoted.every((d) => typeof d === 'string')) return false;\n if (!isGenerateMetaCacheVerdict(v.cacheVerdict)) return false;\n return typeof v.durationMs === 'number';\n}\n\nexport const API_ERROR_CODES = {\n INVALID_REQUEST: 4000,\n API_KEY: 4001,\n ORIGIN_FORBIDDEN: 4003,\n EDIT_CONFIRM_REQUIRED: 4009,\n RATE_LIMITED: 4029,\n CATALOG_OUT_OF_SCOPE: 4040,\n PIN_UNKNOWN_ORGANISM: 4041,\n PIN_OUT_OF_SCOPE: 4042,\n PIN_CONFLICT: 4043,\n PIN_UNKNOWN_KNOB: 4044,\n PIN_ORBITAL_REQUIRED: 4045,\n ASYNC_UNSUPPORTED: 4060,\n FOCUS_STALE: 4090,\n SERVER: 5000,\n GENERATION_FAILED: 5001,\n RUNTIME: 5002,\n WORKSPACE_OPEN: 5003,\n AI_UNCONFIGURED: 5030,\n} as const;\nexport type ApiErrorCode = (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES];\n\n/** `error` event `code` values on the generate SSE stream. */\nexport const STREAM_ERROR_CODES = ['failed', 'runtime', 'workspace_open', 'ai_unconfigured', 'focus_stale'] as const;\nexport type StreamErrorCode = (typeof STREAM_ERROR_CODES)[number];\n\nexport interface GenerateOptions {\n prompt: string;\n endUserId?: string;\n appId?: string;\n /** Streaming callback for canonical SSE events plus the SDK's `generation_meta` summary. */\n onEvent?: (event: GenerateStreamEvent) => void;\n /**\n * The client has no async job surface: passing `true` throws\n * `AsyncUnsupportedError` (code 4060) before any network call is made.\n * For long-running generations use the default streaming mode with `onEvent`.\n */\n async?: boolean;\n /**\n * Agent provider override (e.g. 'deepseek', 'openai').\n * Omit to use the server's default.\n */\n provider?: string;\n /**\n * Agent model override (e.g. 'deepseek-chat').\n * Omit to use the server's default.\n */\n model?: string;\n /**\n * Behavior catalog mode — 'subset' narrows generation to stdAllowList.\n * Server-specific; omit if the agent does not support it.\n */\n catalogMode?: CatalogMode;\n /**\n * Allow-list of std behavior names. Requires a server that supports catalog\n * narrowing (e.g. the builder Rabit/Studio agent).\n */\n stdAllowList?: string[];\n /** Pin generation to a specific organism/orbital instead of free-composing. */\n pin?: GeneratePin;\n}\n\nexport interface GenerateResult {\n schema: OrbitalSchema;\n appId?: string;\n /** Absent for third-party servers built with `createGenerateHandler` that don't emit `generation_meta`. */\n meta?: GenerateMeta;\n}\n\n/**\n * Body of a `PUT /api/v1/agent/edit-schema`. Strictly structural; the SDK\n * does not deep-type the patch — that's the server's job. Field types are\n * `EventPayload`-compatible so callers can't sneak in arbitrary objects.\n */\nexport interface EditSchemaPatch {\n orbital?: string;\n traitOverrides?: EventPayload;\n config?: EventPayload;\n}\n\nexport interface CompileOptions {\n target?: 'express' | 'hono';\n shell?: 'typescript' | 'python' | 'mobile';\n}\n\nexport interface CompileResult {\n downloadUrl: string;\n expiresAt: string;\n}\n\nexport interface AlmadarClientOptions {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof fetch;\n}\n\n/**\n * Props for `<AlmadarApp />` — renders an orbital schema. The runtime mode\n * decides whether effects (persist/fetch/call-service) hit a backend or stay\n * mocked in-browser.\n */\nexport interface AlmadarAppProps {\n schema: OrbitalSchema;\n /**\n * - `static`: pure client-side, no server effects. Use with `data`.\n * - `mock` (default): in-browser fake server, faker-seeded if `data` is undefined.\n * - `server`: real backend at `serverUrl`.\n */\n mode?: 'static' | 'mock' | 'server';\n /** Seed data keyed by entity name (canonical `EntityData` shape). */\n data?: EntityData;\n /** Required when `mode === 'server'`. */\n serverUrl?: string;\n initialPagePath?: string;\n height?: string;\n className?: string;\n /**\n * Tiers of config knobs to surface as auto-derived controls. When provided,\n * a control rail is rendered next to the app. Omit to hide controls.\n * Common values: `['presentation']`, `['presentation', 'domain']`.\n */\n exposedTiers?: string[];\n /** Where to render the auto-derived controls rail. Default: 'right'. */\n controlsPosition?: 'right' | 'bottom';\n /**\n * Explicit override for whether the config-controls rail renders. When\n * omitted, falls back to legacy behavior: `exposedTiers` non-empty and\n * `mode !== 'server'`.\n */\n showControls?: boolean;\n}\n\n/**\n * Props for `<OrbitalConfigPanel />` — low-level control rail used by\n * `<AlmadarApp />` when `exposedTiers` is set.\n */\nexport interface OrbitalConfigPanelProps {\n schema: string | OrbitalSchema;\n exposedTiers?: string[];\n position?: 'right' | 'bottom';\n onSchemaChange?: (schema: OrbitalSchema) => void;\n}\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 { API_ERROR_CODES, STREAM_ERROR_CODES } from '../types';\nimport type { ApiErrorBody, StreamErrorCode } 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\n/** 4041-4045 — pin resolution failed: unknown organism, out-of-scope, conflicting pins, unknown knob, or a missing required orbital. */\nexport class PinError extends AlmadarError {\n constructor(body: ApiErrorBody) {\n super(body);\n this.name = 'PinError';\n }\n}\n\n/** 4060 — `generate({ async: true })` has no server-side job surface; use the default streaming mode instead. */\nexport class AsyncUnsupportedError extends AlmadarError {\n constructor(body: ApiErrorBody) {\n super(body);\n this.name = 'AsyncUnsupportedError';\n }\n}\n\n/** 5001 — generation failed server-side. */\nexport class GenerationFailedError extends AlmadarError {\n constructor(body: ApiErrorBody) {\n super(body);\n this.name = 'GenerationFailedError';\n }\n}\n\nexport function errorFromBody(body: ApiErrorBody): AlmadarError {\n switch (body.code) {\n case API_ERROR_CODES.API_KEY:\n return new ApiKeyError(body);\n case API_ERROR_CODES.RATE_LIMITED:\n return new RateLimitedError(body);\n case API_ERROR_CODES.CATALOG_OUT_OF_SCOPE:\n return new CatalogOutOfScopeError(body);\n case API_ERROR_CODES.PIN_UNKNOWN_ORGANISM:\n case API_ERROR_CODES.PIN_OUT_OF_SCOPE:\n case API_ERROR_CODES.PIN_CONFLICT:\n case API_ERROR_CODES.PIN_UNKNOWN_KNOB:\n case API_ERROR_CODES.PIN_ORBITAL_REQUIRED:\n return new PinError(body);\n case API_ERROR_CODES.ASYNC_UNSUPPORTED:\n return new AsyncUnsupportedError(body);\n case API_ERROR_CODES.GENERATION_FAILED:\n return new GenerationFailedError(body);\n default:\n return new ServerError(body);\n }\n}\n\nfunction isStreamErrorCode(code: string | undefined): code is StreamErrorCode {\n if (code === undefined) return false;\n return STREAM_ERROR_CODES.some((c) => c === code);\n}\n\n/** Maps a `generate` SSE `error` event's `{ error, code }` payload to a typed SDK error. */\nexport function streamErrorFromEvent(data: { error: string; code?: string }): AlmadarError {\n const message = data.error;\n if (!isStreamErrorCode(data.code)) {\n return new ServerError({ code: API_ERROR_CODES.SERVER, message });\n }\n switch (data.code) {\n case 'failed':\n return new GenerationFailedError({ code: API_ERROR_CODES.GENERATION_FAILED, message });\n case 'ai_unconfigured':\n return new ServerError({ code: API_ERROR_CODES.AI_UNCONFIGURED, message });\n case 'workspace_open':\n return new ServerError({ code: API_ERROR_CODES.WORKSPACE_OPEN, message });\n case 'focus_stale':\n return new ServerError({ code: API_ERROR_CODES.FOCUS_STALE, message });\n case 'runtime':\n return new ServerError({ code: API_ERROR_CODES.RUNTIME, message });\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 { parseOrbitalSchema, type OrbitalSchema, type SSEEvent } from '@almadar/core';\nimport { API_ERROR_CODES, isGenerateMeta } from '../types';\nimport type {\n AlmadarClientOptions,\n ApiErrorBody,\n CompileOptions,\n CompileResult,\n EditSchemaPatch,\n GenerateMeta,\n GenerateOptions,\n GenerateResult,\n GenerateStreamEvent,\n} from '../types';\nimport { AsyncUnsupportedError, errorFromBody, ServerError, streamErrorFromEvent } from './errors';\nimport { parseSSE } from './sseParser';\n\nconst DEFAULT_BASE_URL = 'https://studio.almadar.io';\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 throw new AsyncUnsupportedError({\n code: API_ERROR_CODES.ASYNC_UNSUPPORTED,\n message: 'AlmadarClient has no async job surface. Omit `async` (or pass false) and consume the streaming response via `onEvent` instead.',\n });\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 provider: input.provider,\n model: input.model,\n catalogMode: input.catalogMode,\n stdAllowList: input.stdAllowList,\n pin: input.pin,\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 let meta: GenerateMeta | undefined;\n for await (const raw of parseSSE(res.body)) {\n const event = parseSseEvent(raw.data);\n if (event === null) continue;\n input.onEvent?.(event);\n if (event.type === 'generation_meta') {\n meta = event.data;\n } else if (event.type === 'complete') {\n if (event.data.schema === undefined) {\n throw new ServerError({ code: API_ERROR_CODES.SERVER, message: '`complete` event did not contain a schema' });\n }\n const schema = parseOrbitalSchema(event.data.schema);\n final = { schema, appId: event.data.appId, meta };\n } else if (event.type === 'error') {\n throw streamErrorFromEvent(event.data);\n }\n }\n if (final === null) {\n throw new ServerError({ code: API_ERROR_CODES.SERVER, message: 'SSE stream ended without `complete` event' });\n }\n return final;\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: API_ERROR_CODES.SERVER, 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\n/**\n * Parse one SSE `data:` line into the `GenerateStreamEvent` union. The server\n * is the trusted emitter, so we validate only the envelope (object with\n * string `type` and numeric `timestamp`) and cast to the canonical `SSEEvent`\n * union — except `generation_meta`, which is SDK-only and goes through the\n * `isGenerateMeta` runtime guard instead of a cast. Malformed lines are ignored.\n */\nfunction parseSseEvent(dataLine: string): GenerateStreamEvent | null {\n if (dataLine === '') return null;\n let payload;\n try {\n payload = JSON.parse(dataLine);\n } catch {\n return null;\n }\n if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) return null;\n if (typeof payload.type !== 'string' || typeof payload.timestamp !== 'number') return null;\n if (payload.type === 'generation_meta') {\n return isGenerateMeta(payload.data)\n ? { type: 'generation_meta', data: payload.data, timestamp: payload.timestamp }\n : null;\n }\n return payload as SSEEvent;\n}\n\nfunction assertString(v: string | undefined, name: string): asserts v is string {\n if (typeof v !== 'string' || v === '') {\n throw new ServerError({ code: API_ERROR_CODES.SERVER, message: `Malformed server response: ${name} is not a string` });\n }\n}\n"]}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { A as AlmadarApp } from '../AlmadarApp-
|
|
1
|
+
export { A as AlmadarApp } from '../AlmadarApp-mS7H6kiA.js';
|
|
2
2
|
import react__default from 'react';
|
|
3
3
|
import { OrbitalSchema } from '@almadar/core';
|
|
4
4
|
export { EntityData, EventPayload, OrbitalSchema, SSEEvent } from '@almadar/core';
|
|
5
5
|
export { useEventBus as useOrbBus } from '@almadar/ui/hooks';
|
|
6
|
-
export {
|
|
6
|
+
export { a as AlmadarAppProps, O as OrbitalConfigPanelProps } from '../types-CVGXdQRM.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* OrbitalConfigPanel — auto-derived control rail for an orbital schema.
|
package/dist/react/index.js
CHANGED
|
@@ -108,8 +108,8 @@ function AlmadarApp(props) {
|
|
|
108
108
|
useEffect(() => {
|
|
109
109
|
setControlledSchema(parsedSchema);
|
|
110
110
|
}, [parsedSchema]);
|
|
111
|
-
const
|
|
112
|
-
const
|
|
111
|
+
const showControls = props.showControls ?? (props.exposedTiers !== void 0 && props.exposedTiers.length > 0 && mode !== "server");
|
|
112
|
+
const effectiveSchema = showControls ? controlledSchema : parsedSchema;
|
|
113
113
|
const preview = mode === "mock" ? /* @__PURE__ */ jsx(
|
|
114
114
|
BrowserPlaygroundLazy,
|
|
115
115
|
{
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/OrbitalConfigPanel.tsx","../../src/react/AlmadarApp.tsx"],"names":["parseSchema","useMemo","useState","jsx","jsxs"],"mappings":";;;;;;;AA4BA,SAAS,YAAY,MAAA,EAA+C;AAClE,EAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,IAAA,OAAO,IAAA,CAAK,MAAM,MAAM,CAAA;AAAA,EAC1B;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,UAAa,KAAA,EAAa;AACjC,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAA;AACzC;AAEA,SAAS,gBAAgB,MAAA,EAAwD;AAC/E,EAAA,IAAI,CAAC,MAAA,EAAQ,QAAA,EAAU,OAAO,IAAA;AAC9B,EAAA,KAAA,MAAW,OAAA,IAAW,OAAO,QAAA,EAAU;AACrC,IAAA,KAAA,MAAW,QAAA,IAAY,OAAA,CAAQ,MAAA,IAAU,EAAC,EAAG;AAC3C,MAAA,IAAI,OAAO,QAAA,KAAa,QAAA,IAAY,QAAA,KAAa,IAAA,EAAM;AACvD,MAAA,MAAM,KAAA,GAAQ,QAAA;AACd,MAAA,IAAI,KAAA,CAAM,UAAU,MAAA,CAAO,IAAA,CAAK,MAAM,MAAM,CAAA,CAAE,SAAS,CAAA,EAAG;AACxD,QAAA,MAAM,IAAA,GAAO,UAAU,KAAA,IAAS,OAAO,MAAM,IAAA,KAAS,QAAA,GAAW,MAAM,IAAA,GAAO,QAAA;AAC9E,QAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,KAAA,CAAM,MAAA,EAAO;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,IAAA;AACT;AAEA,SAAS,mBAAA,CACP,MAAA,EACA,KAAA,EACA,KAAA,EACe;AACf,EAAA,MAAM,IAAA,GAAO,UAAU,MAAM,CAAA;A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OrbitalConfigPanel — auto-derived control rail for an orbital schema.\n *\n * Finds the first trait that declares a non-empty `config`, filters its fields\n * by the consumer-supplied `exposedTiers`, and renders `@almadar/ui`'s\n * `PropertyInspector`. Every control change deep-clones the schema, writes the\n * new value into the matching field's `default`, and emits the mutated schema\n * so the host can pass it to `OrbPreview`.\n */\n\nimport React, { useMemo, useState } from 'react';\nimport type {\n ConfigFieldDeclaration,\n DeclaredTraitConfig,\n OrbitalSchema,\n Trait,\n TraitConfigValue,\n} from '@almadar/core';\nimport { PropertyInspector } from '@almadar/ui/components';\nimport { Stack, Box, Typography } from '@almadar/ui/components';\n\ninterface ConfigTraitTarget {\n name: string;\n config: DeclaredTraitConfig;\n}\n\nfunction parseSchema(schema: string | OrbitalSchema): OrbitalSchema {\n if (typeof schema === 'string') {\n return JSON.parse(schema) as OrbitalSchema;\n }\n return schema;\n}\n\nfunction deepClone<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T;\n}\n\nfunction findConfigTrait(schema: OrbitalSchema | null): ConfigTraitTarget | null {\n if (!schema?.orbitals) return null;\n for (const orbital of schema.orbitals) {\n for (const traitRef of orbital.traits ?? []) {\n if (typeof traitRef !== 'object' || traitRef === null) continue;\n const trait = traitRef as Trait | { ref?: string; config?: DeclaredTraitConfig };\n if (trait.config && Object.keys(trait.config).length > 0) {\n const name = 'name' in trait && typeof trait.name === 'string' ? trait.name : 'Config';\n return { name, config: trait.config };\n }\n }\n }\n return null;\n}\n\nfunction applyConfigOverride(\n schema: OrbitalSchema,\n field: string,\n value: TraitConfigValue,\n): OrbitalSchema {\n const next = deepClone(schema);\n for (const orbital of next.orbitals ?? []) {\n for (const traitRef of orbital.traits ?? []) {\n if (typeof traitRef !== 'object' || traitRef === null) continue;\n const trait = traitRef as { config?: Record<string, ConfigFieldDeclaration> };\n if (trait.config && field in trait.config) {\n trait.config[field] = { ...trait.config[field], default: value };\n return next;\n }\n }\n }\n return next;\n}\n\nexport interface OrbitalConfigPanelProps {\n schema: string | OrbitalSchema;\n exposedTiers?: string[];\n position?: 'right' | 'bottom';\n onSchemaChange?: (schema: OrbitalSchema) => void;\n}\n\nexport function OrbitalConfigPanel({\n schema,\n exposedTiers,\n position = 'right',\n onSchemaChange,\n}: OrbitalConfigPanelProps): React.ReactElement | null {\n const parsed = useMemo(() => parseSchema(schema), [schema]);\n const target = useMemo(() => findConfigTrait(parsed), [parsed]);\n const [values, setValues] = useState<Record<string, TraitConfigValue>>({});\n\n if (!target) return null;\n\n const sortedConfig: DeclaredTraitConfig = Object.fromEntries(\n Object.entries(target.config).sort(([a], [b]) => a.localeCompare(b)),\n );\n\n const handleChange = (field: string, value: TraitConfigValue): void => {\n setValues((prev) => ({ ...prev, [field]: value }));\n const nextSchema = applyConfigOverride(parsed, field, value);\n onSchemaChange?.(nextSchema);\n };\n\n const handleReset = (): void => {\n setValues({});\n onSchemaChange?.(parsed);\n };\n\n const isHorizontal = position === 'bottom';\n\n return (\n <Box\n className={`${\n isHorizontal ? 'w-full border-t' : 'h-full w-80 flex-shrink-0 border-l'\n } border-border bg-card p-3 overflow-y-auto`}\n >\n <Stack direction=\"vertical\" gap=\"sm\">\n <Typography variant=\"caption\" weight=\"bold\" color=\"muted\">\n Controls\n </Typography>\n <PropertyInspector\n title={target.name}\n config={sortedConfig}\n values={values}\n onChange={handleChange}\n onReset={handleReset}\n tiers={exposedTiers}\n />\n </Stack>\n </Box>\n );\n}\n\nOrbitalConfigPanel.displayName = 'OrbitalConfigPanel';\n","'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, Suspense, useEffect, useMemo, useState } from 'react';\nimport type { AlmadarAppProps } from '../types';\nimport type { OrbitalSchema } from '@almadar/core';\nimport { OrbitalConfigPanel } from './OrbitalConfigPanel';\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\nfunction parseSchema(schema: string | OrbitalSchema): OrbitalSchema {\n if (typeof schema === 'string') {\n return JSON.parse(schema) as OrbitalSchema;\n }\n return schema;\n}\n\nexport function AlmadarApp(props: AlmadarAppProps) {\n const mode = props.mode ?? 'static';\n const parsedSchema = useMemo(() => parseSchema(props.schema), [props.schema]);\n const [controlledSchema, setControlledSchema] = useState<OrbitalSchema>(parsedSchema);\n\n // Reset controlled schema when the incoming schema changes.\n useEffect(() => {\n setControlledSchema(parsedSchema);\n }, [parsedSchema]);\n\n const effectiveSchema = props.exposedTiers && mode !== 'server' ? controlledSchema : parsedSchema;\n const showControls = props.exposedTiers && props.exposedTiers.length > 0 && mode !== 'server';\n\n const preview = mode === 'mock' ? (\n <BrowserPlaygroundLazy\n schema={effectiveSchema}\n mode=\"mock\"\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n ) : (\n <OrbPreviewLazy\n schema={effectiveSchema}\n mockData={props.data}\n serverUrl={props.serverUrl}\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n );\n\n if (!showControls) {\n return (\n <Suspense fallback={null}>\n {preview}\n </Suspense>\n );\n }\n\n const isBottom = props.controlsPosition === 'bottom';\n\n return (\n <Suspense fallback={null}>\n <div\n className={`flex ${isBottom ? 'flex-col' : 'flex-row'} w-full h-full`}\n style={{ height: props.height }}\n >\n <div className=\"flex-1 min-w-0\">\n {preview}\n </div>\n <OrbitalConfigPanel\n schema={parsedSchema}\n exposedTiers={props.exposedTiers}\n position={props.controlsPosition}\n onSchemaChange={setControlledSchema}\n />\n </div>\n </Suspense>\n );\n}\n\nAlmadarApp.displayName = 'AlmadarApp';\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/react/OrbitalConfigPanel.tsx","../../src/react/AlmadarApp.tsx"],"names":["parseSchema","useMemo","useState","jsx","jsxs"],"mappings":";;;;;;;AA4BA,SAAS,YAAY,MAAA,EAA+C;AAClE,EAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,IAAA,OAAO,IAAA,CAAK,MAAM,MAAM,CAAA;AAAA,EAC1B;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,UAAa,KAAA,EAAa;AACjC,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAA;AACzC;AAEA,SAAS,gBAAgB,MAAA,EAAwD;AAC/E,EAAA,IAAI,CAAC,MAAA,EAAQ,QAAA,EAAU,OAAO,IAAA;AAC9B,EAAA,KAAA,MAAW,OAAA,IAAW,OAAO,QAAA,EAAU;AACrC,IAAA,KAAA,MAAW,QAAA,IAAY,OAAA,CAAQ,MAAA,IAAU,EAAC,EAAG;AAC3C,MAAA,IAAI,OAAO,QAAA,KAAa,QAAA,IAAY,QAAA,KAAa,IAAA,EAAM;AACvD,MAAA,MAAM,KAAA,GAAQ,QAAA;AACd,MAAA,IAAI,KAAA,CAAM,UAAU,MAAA,CAAO,IAAA,CAAK,MAAM,MAAM,CAAA,CAAE,SAAS,CAAA,EAAG;AACxD,QAAA,MAAM,IAAA,GAAO,UAAU,KAAA,IAAS,OAAO,MAAM,IAAA,KAAS,QAAA,GAAW,MAAM,IAAA,GAAO,QAAA;AAC9E,QAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,KAAA,CAAM,MA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AM,YAAA;AAAA,YACpB,UAAU,KAAA,CAAM,gBAAA;AAAA,YAChB,cAAA,EAAgB;AAAA;AAAA;AAClB;AAAA;AAAA,GACF,EACF,CAAA;AAEJ;AAEA,UAAA,CAAW,WAAA,GAAc,YAAA","file":"index.js","sourcesContent":["'use client';\n\n/**\n * OrbitalConfigPanel — auto-derived control rail for an orbital schema.\n *\n * Finds the first trait that declares a non-empty `config`, filters its fields\n * by the consumer-supplied `exposedTiers`, and renders `@almadar/ui`'s\n * `PropertyInspector`. Every control change deep-clones the schema, writes the\n * new value into the matching field's `default`, and emits the mutated schema\n * so the host can pass it to `OrbPreview`.\n */\n\nimport React, { useMemo, useState } from 'react';\nimport type {\n ConfigFieldDeclaration,\n DeclaredTraitConfig,\n OrbitalSchema,\n Trait,\n TraitConfigValue,\n} from '@almadar/core';\nimport { PropertyInspector } from '@almadar/ui/components';\nimport { Stack, Box, Typography } from '@almadar/ui/components';\n\ninterface ConfigTraitTarget {\n name: string;\n config: DeclaredTraitConfig;\n}\n\nfunction parseSchema(schema: string | OrbitalSchema): OrbitalSchema {\n if (typeof schema === 'string') {\n return JSON.parse(schema) as OrbitalSchema;\n }\n return schema;\n}\n\nfunction deepClone<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T;\n}\n\nfunction findConfigTrait(schema: OrbitalSchema | null): ConfigTraitTarget | null {\n if (!schema?.orbitals) return null;\n for (const orbital of schema.orbitals) {\n for (const traitRef of orbital.traits ?? []) {\n if (typeof traitRef !== 'object' || traitRef === null) continue;\n const trait = traitRef as Trait | { ref?: string; config?: DeclaredTraitConfig };\n if (trait.config && Object.keys(trait.config).length > 0) {\n const name = 'name' in trait && typeof trait.name === 'string' ? trait.name : 'Config';\n return { name, config: trait.config };\n }\n }\n }\n return null;\n}\n\nfunction applyConfigOverride(\n schema: OrbitalSchema,\n field: string,\n value: TraitConfigValue,\n): OrbitalSchema {\n const next = deepClone(schema);\n for (const orbital of next.orbitals ?? []) {\n for (const traitRef of orbital.traits ?? []) {\n if (typeof traitRef !== 'object' || traitRef === null) continue;\n const trait = traitRef as { config?: Record<string, ConfigFieldDeclaration> };\n if (trait.config && field in trait.config) {\n trait.config[field] = { ...trait.config[field], default: value };\n return next;\n }\n }\n }\n return next;\n}\n\nexport interface OrbitalConfigPanelProps {\n schema: string | OrbitalSchema;\n exposedTiers?: string[];\n position?: 'right' | 'bottom';\n onSchemaChange?: (schema: OrbitalSchema) => void;\n}\n\nexport function OrbitalConfigPanel({\n schema,\n exposedTiers,\n position = 'right',\n onSchemaChange,\n}: OrbitalConfigPanelProps): React.ReactElement | null {\n const parsed = useMemo(() => parseSchema(schema), [schema]);\n const target = useMemo(() => findConfigTrait(parsed), [parsed]);\n const [values, setValues] = useState<Record<string, TraitConfigValue>>({});\n\n if (!target) return null;\n\n const sortedConfig: DeclaredTraitConfig = Object.fromEntries(\n Object.entries(target.config).sort(([a], [b]) => a.localeCompare(b)),\n );\n\n const handleChange = (field: string, value: TraitConfigValue): void => {\n setValues((prev) => ({ ...prev, [field]: value }));\n const nextSchema = applyConfigOverride(parsed, field, value);\n onSchemaChange?.(nextSchema);\n };\n\n const handleReset = (): void => {\n setValues({});\n onSchemaChange?.(parsed);\n };\n\n const isHorizontal = position === 'bottom';\n\n return (\n <Box\n className={`${\n isHorizontal ? 'w-full border-t' : 'h-full w-80 flex-shrink-0 border-l'\n } border-border bg-card p-3 overflow-y-auto`}\n >\n <Stack direction=\"vertical\" gap=\"sm\">\n <Typography variant=\"caption\" weight=\"bold\" color=\"muted\">\n Controls\n </Typography>\n <PropertyInspector\n title={target.name}\n config={sortedConfig}\n values={values}\n onChange={handleChange}\n onReset={handleReset}\n tiers={exposedTiers}\n />\n </Stack>\n </Box>\n );\n}\n\nOrbitalConfigPanel.displayName = 'OrbitalConfigPanel';\n","'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, Suspense, useEffect, useMemo, useState } from 'react';\nimport type { AlmadarAppProps } from '../types';\nimport type { OrbitalSchema } from '@almadar/core';\nimport { OrbitalConfigPanel } from './OrbitalConfigPanel';\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\nfunction parseSchema(schema: string | OrbitalSchema): OrbitalSchema {\n if (typeof schema === 'string') {\n return JSON.parse(schema) as OrbitalSchema;\n }\n return schema;\n}\n\nexport function AlmadarApp(props: AlmadarAppProps) {\n const mode = props.mode ?? 'static';\n const parsedSchema = useMemo(() => parseSchema(props.schema), [props.schema]);\n const [controlledSchema, setControlledSchema] = useState<OrbitalSchema>(parsedSchema);\n\n // Reset controlled schema when the incoming schema changes.\n useEffect(() => {\n setControlledSchema(parsedSchema);\n }, [parsedSchema]);\n\n const showControls =\n props.showControls ?? (props.exposedTiers !== undefined && props.exposedTiers.length > 0 && mode !== 'server');\n const effectiveSchema = showControls ? controlledSchema : parsedSchema;\n\n const preview = mode === 'mock' ? (\n <BrowserPlaygroundLazy\n schema={effectiveSchema}\n mode=\"mock\"\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n ) : (\n <OrbPreviewLazy\n schema={effectiveSchema}\n mockData={props.data}\n serverUrl={props.serverUrl}\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n );\n\n if (!showControls) {\n return (\n <Suspense fallback={null}>\n {preview}\n </Suspense>\n );\n }\n\n const isBottom = props.controlsPosition === 'bottom';\n\n return (\n <Suspense fallback={null}>\n <div\n className={`flex ${isBottom ? 'flex-col' : 'flex-row'} w-full h-full`}\n style={{ height: props.height }}\n >\n <div className=\"flex-1 min-w-0\">\n {preview}\n </div>\n <OrbitalConfigPanel\n schema={parsedSchema}\n exposedTiers={props.exposedTiers}\n position={props.controlsPosition}\n onSchemaChange={setControlledSchema}\n />\n </div>\n </Suspense>\n );\n}\n\nAlmadarApp.displayName = 'AlmadarApp';\n"]}
|