@uibot/application 0.0.0-stage → 0.2.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/dist/collection-application.d.ts +3 -0
- package/dist/collection-application.js +25 -0
- package/dist/compose-system-prompt.d.ts +104 -0
- package/dist/composition.d.ts +24 -0
- package/dist/context-service.d.ts +42 -0
- package/dist/creation-annotations.d.ts +5 -0
- package/dist/creation-assets.d.ts +15 -0
- package/dist/creation-brand-http.d.ts +9 -0
- package/dist/creation-brand.d.ts +25 -0
- package/dist/creation-copy.d.ts +11 -0
- package/dist/creation-domains.d.ts +25 -0
- package/dist/creation-facts.d.ts +8 -0
- package/dist/creation-http-helpers.d.ts +35 -0
- package/dist/creation-http.d.ts +99 -0
- package/dist/creation-layout.d.ts +4 -0
- package/dist/creation-legacy-flat-spec.d.ts +42 -0
- package/dist/creation-prompt.d.ts +33 -0
- package/dist/creation-requirements.d.ts +6 -0
- package/dist/creation-routes.d.ts +26 -0
- package/dist/creation-runner.d.ts +20 -0
- package/dist/creation-spec-prompt.d.ts +3 -0
- package/dist/creation-store.d.ts +121 -0
- package/dist/creation-theme-http.d.ts +13 -0
- package/dist/creation-theme.d.ts +16 -0
- package/dist/creation-web-data-prompt.d.ts +15 -0
- package/dist/discovery-protocol.d.ts +25 -0
- package/dist/gap-orchestrator.d.ts +19 -0
- package/dist/grounded-brief.d.ts +37 -0
- package/dist/html-preview/config.d.ts +14 -0
- package/dist/html-preview/index.d.ts +11 -0
- package/dist/html-preview/link-interceptor.d.ts +10 -0
- package/dist/html-preview/proxy.d.ts +57 -0
- package/dist/html-preview/render.d.ts +39 -0
- package/dist/html-preview/routes.d.ts +27 -0
- package/dist/html-preview/session-store.d.ts +44 -0
- package/dist/hub-client.d.ts +25 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +819 -0
- package/dist/live-runtime-adapter.d.ts +11 -0
- package/dist/playground-session-http.d.ts +24 -0
- package/dist/prompt.d.ts +17 -0
- package/dist/resource-apply.d.ts +18 -0
- package/dist/runtime.d.ts +37 -0
- package/dist/studio-artifact-export-http.d.ts +52 -0
- package/dist/studio-compose-context.d.ts +47 -0
- package/dist/studio-compose-http.d.ts +31 -0
- package/dist/studio-design-http.d.ts +164 -0
- package/dist/studio-design-md-export-http.d.ts +11 -0
- package/dist/studio-http-shared.d.ts +34 -0
- package/dist/studio-http.d.ts +359 -0
- package/dist/studio-logo.d.ts +24 -0
- package/dist/studio-pages/agents-page.d.ts +48 -0
- package/dist/studio-pages/catalog-page.d.ts +22 -0
- package/dist/studio-pages/design-md-page.d.ts +55 -0
- package/dist/studio-pages/evolution-page.d.ts +111 -0
- package/dist/studio-pages/governance-page.d.ts +65 -0
- package/dist/studio-pages/index.d.ts +82 -0
- package/dist/studio-pages/models-page.d.ts +76 -0
- package/dist/studio-pages/operations-page.d.ts +61 -0
- package/dist/studio-pages/overview-page.d.ts +90 -0
- package/dist/studio-pages/plugins-page.d.ts +36 -0
- package/dist/studio-pages/shared.d.ts +25 -0
- package/dist/studio-pages/skills-page.d.ts +59 -0
- package/dist/studio-pages/spec-page.d.ts +33 -0
- package/dist/studio-project-design-http.d.ts +41 -0
- package/dist/studio-project-specs.d.ts +11 -0
- package/dist/studio-resource-index-http.d.ts +17 -0
- package/dist/studio-spec-recover-http.d.ts +45 -0
- package/dist/studio-spec-sync-http.d.ts +43 -0
- package/dist/studio.d.ts +64 -0
- package/dist/ui-craft-baseline.d.ts +14 -0
- package/package.json +49 -4
- package/README.md +0 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live runtime adapter — re-exported from `@uibot/runtime`.
|
|
3
|
+
*
|
|
4
|
+
* The implementation moved to the client-safe `@uibot/runtime` package so that
|
|
5
|
+
* Studio (a pure client that must never import this server-only `application`
|
|
6
|
+
* package) and `application` share one source instead of mirroring it. This
|
|
7
|
+
* module keeps `@uibot/application`'s public API backward-compatible: importers
|
|
8
|
+
* of `createLiveRuntimeAdapter` / `CreateLiveAdapterOptions` from
|
|
9
|
+
* `@uibot/application` continue to work unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export { createLiveRuntimeAdapter, type CreateLiveAdapterOptions, } from "@uibot/runtime";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface PlaygroundStoredSession {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
createdAt: number;
|
|
5
|
+
updatedAt: number;
|
|
6
|
+
state: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface PlaygroundSessionSummary {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
createdAt: number;
|
|
12
|
+
updatedAt: number;
|
|
13
|
+
messageCount: number;
|
|
14
|
+
pageCount: number;
|
|
15
|
+
}
|
|
16
|
+
export interface PlaygroundSessionIndex {
|
|
17
|
+
activeId: string | null;
|
|
18
|
+
sessions: PlaygroundSessionSummary[];
|
|
19
|
+
}
|
|
20
|
+
export interface CreateUIBotStudioPlaygroundSessionsHandlerOptions {
|
|
21
|
+
rootDir?: string;
|
|
22
|
+
basePath?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function createUIBotStudioPlaygroundSessionsHandler(options?: CreateUIBotStudioPlaygroundSessionsHandlerOptions): (request: Request) => Promise<Response>;
|
package/dist/prompt.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Catalog, CatalogEntry, ResourceMatch } from "@uibot/contracts";
|
|
2
|
+
export interface GenerateCatalogPromptOptions {
|
|
3
|
+
includeTemplates?: boolean;
|
|
4
|
+
maxComponents?: number;
|
|
5
|
+
language?: "zh" | "en";
|
|
6
|
+
compact?: boolean;
|
|
7
|
+
compactShapes?: boolean;
|
|
8
|
+
sharedProps?: boolean;
|
|
9
|
+
omitComponentDescriptions?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function formatComponent(entry: CatalogEntry, compact?: boolean, compactShapes?: boolean): string;
|
|
12
|
+
export declare function generateCatalogPrompt(catalog: Catalog, options?: GenerateCatalogPromptOptions): string;
|
|
13
|
+
/**
|
|
14
|
+
* Build a catalog section from intent-ranked resource matches instead of dumping
|
|
15
|
+
* the full component/template list.
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateResourceMatchCatalogPrompt(matches: readonly ResourceMatch[], catalog: Catalog, options?: GenerateCatalogPromptOptions): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { UIBotSpec, ResourceBuildPlan } from "@uibot/contracts";
|
|
2
|
+
export declare const RESOURCE_APPLY_ERROR_CODES: readonly ["resource-apply-gaps", "resource-apply-no-template", "resource-apply-ambiguous-template", "resource-apply-missing-yaml", "resource-apply-invalid-spec"];
|
|
3
|
+
export type ResourceApplyErrorCode = (typeof RESOURCE_APPLY_ERROR_CODES)[number];
|
|
4
|
+
export declare class ResourceApplyError extends Error {
|
|
5
|
+
readonly code: ResourceApplyErrorCode;
|
|
6
|
+
readonly detail: string;
|
|
7
|
+
readonly plan: ResourceBuildPlan;
|
|
8
|
+
constructor(code: ResourceApplyErrorCode, detail: string, plan: ResourceBuildPlan);
|
|
9
|
+
}
|
|
10
|
+
export interface MaterializeResourceBuildPlanInput {
|
|
11
|
+
plan: ResourceBuildPlan;
|
|
12
|
+
templateYamlById: Readonly<Record<string, string>>;
|
|
13
|
+
}
|
|
14
|
+
export interface MaterializeResourceBuildPlanResult {
|
|
15
|
+
plan: ResourceBuildPlan;
|
|
16
|
+
spec: UIBotSpec;
|
|
17
|
+
}
|
|
18
|
+
export declare function materializeResourceBuildPlan(input: MaterializeResourceBuildPlanInput): MaterializeResourceBuildPlanResult;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CapabilityDescriptor, Catalog, CompiledUIBotSpec, ComponentArtifact, CompileResult, UIBotSpec } from "@uibot/contracts";
|
|
2
|
+
import type { RenderPlanNode, RenderSpecOptions } from "@uibot/renderer-react";
|
|
3
|
+
import { type UIBotComposition } from "./composition.js";
|
|
4
|
+
import { type GapResolutionInstallResult, type GapResolutionResult } from "./gap-orchestrator.js";
|
|
5
|
+
import { type UIBotHubClient } from "./hub-client.js";
|
|
6
|
+
export interface CreateUIBotRuntimeOptions {
|
|
7
|
+
catalog: Catalog;
|
|
8
|
+
capabilities?: CapabilityDescriptor[];
|
|
9
|
+
hubClient?: UIBotHubClient;
|
|
10
|
+
workspaceRoot?: string;
|
|
11
|
+
artifactSource?: string;
|
|
12
|
+
installArtifact?: (artifact: ComponentArtifact) => Promise<GapResolutionInstallResult>;
|
|
13
|
+
shellTemplates?: Readonly<Record<string, UIBotSpec>>;
|
|
14
|
+
}
|
|
15
|
+
export interface UIBotRuntimeCompileResult {
|
|
16
|
+
catalog: Catalog;
|
|
17
|
+
composition: UIBotComposition;
|
|
18
|
+
compileResult: CompileResult;
|
|
19
|
+
installedArtifacts: GapResolutionResult["installedArtifacts"];
|
|
20
|
+
}
|
|
21
|
+
export interface RunUIBotRuntimeOptions extends RenderSpecOptions {
|
|
22
|
+
autoRecoverGaps?: boolean;
|
|
23
|
+
maxRecoveryIterations?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface RunUIBotRuntimeResult extends UIBotRuntimeCompileResult {
|
|
26
|
+
renderPlan: RenderPlanNode;
|
|
27
|
+
rendered: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface UIBotRuntime {
|
|
30
|
+
getCatalog(): Catalog;
|
|
31
|
+
getComposition(): UIBotComposition;
|
|
32
|
+
compile(spec: UIBotSpec): Promise<UIBotRuntimeCompileResult>;
|
|
33
|
+
recover(spec: UIBotSpec, maxIterations?: number): Promise<UIBotRuntimeCompileResult>;
|
|
34
|
+
render(spec: CompiledUIBotSpec, options?: RenderSpecOptions): unknown;
|
|
35
|
+
run(spec: UIBotSpec, options?: RunUIBotRuntimeOptions): Promise<RunUIBotRuntimeResult>;
|
|
36
|
+
}
|
|
37
|
+
export declare function createUIBotRuntime(options: CreateUIBotRuntimeOptions): UIBotRuntime;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical HTTP handler for Studio artifact export (v2.28 SC-3).
|
|
3
|
+
*
|
|
4
|
+
* Hosts (backend container, control-plane example, third-party) should call this
|
|
5
|
+
* instead of re-implementing validation + exportArtifact. Optional CORS and
|
|
6
|
+
* pptx image renderer stay host concerns via options.
|
|
7
|
+
*
|
|
8
|
+
* Request size is bounded here rather than delegated to the host: `source` is
|
|
9
|
+
* capped at 2 MiB, `files` at 256 entries / 8 MiB combined (see the constants
|
|
10
|
+
* below for why the two budgets are separate). Entry paths are checked here as
|
|
11
|
+
* well, so a path the exporter cannot place is a 400 instead of a 500 raised
|
|
12
|
+
* from inside the zip writer.
|
|
13
|
+
*/
|
|
14
|
+
import { type ArtifactExportInput, type ArtifactExportResult } from "@uibot/artifact-exporters";
|
|
15
|
+
export interface PptxImageRendererInput {
|
|
16
|
+
source: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
sourcePath?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface CreateUIBotStudioArtifactExportHandlerOptions {
|
|
21
|
+
/** Route path. Defaults to `/api/studio/artifacts/export`. */
|
|
22
|
+
path?: string;
|
|
23
|
+
/**
|
|
24
|
+
* When set, OPTIONS/POST responses include CORS headers.
|
|
25
|
+
* Space-separated allowlist; first origin is the default when request Origin
|
|
26
|
+
* is missing/not listed.
|
|
27
|
+
*/
|
|
28
|
+
studioOrigin?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Optional PPTX image-mode renderer. When absent, renderMode=image returns 501
|
|
31
|
+
* with code `pptx-image-renderer-unavailable` (no mock fallback).
|
|
32
|
+
*/
|
|
33
|
+
pptxImageRenderer?: (input: PptxImageRendererInput) => Promise<ArtifactExportResult | null>;
|
|
34
|
+
}
|
|
35
|
+
export interface ArtifactExportRequestBody {
|
|
36
|
+
format?: unknown;
|
|
37
|
+
renderMode?: unknown;
|
|
38
|
+
source?: unknown;
|
|
39
|
+
title?: unknown;
|
|
40
|
+
sourcePath?: unknown;
|
|
41
|
+
files?: unknown;
|
|
42
|
+
}
|
|
43
|
+
export type ArtifactExportValidateResult = {
|
|
44
|
+
ok: true;
|
|
45
|
+
value: ArtifactExportInput;
|
|
46
|
+
renderMode: "editable" | "image";
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
error: string;
|
|
50
|
+
};
|
|
51
|
+
export declare function validateArtifactExportBody(body: ArtifactExportRequestBody): ArtifactExportValidateResult;
|
|
52
|
+
export declare function createUIBotStudioArtifactExportHandler(options?: CreateUIBotStudioArtifactExportHandlerOptions): (req: Request) => Promise<Response | null>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Agent, Catalog, DesignMdSelector, SkillSelector } from "@uibot/contracts";
|
|
2
|
+
import type { ResourceQueryService } from "@uibot/registry";
|
|
3
|
+
import { type ComposedSystemPrompt } from "./compose-system-prompt.js";
|
|
4
|
+
/**
|
|
5
|
+
* Studio / Playground / design-handoff design-md token budget (chars/4 on body).
|
|
6
|
+
* Audit sizes: frontend-principles ≈1218, control-console lane guide, stripe ≈1821,
|
|
7
|
+
* vercel ≈1712, linear ≈1784, figma ≈832. `composeSystemPrompt` keeps a
|
|
8
|
+
* generic default of 2000; force-including frontend-principles leaves ~782,
|
|
9
|
+
* so stripe/vercel/linear cannot fit intact. 4500 fits house-style + one
|
|
10
|
+
* full brand guide. Callers of `composeStudioPrompt` inherit this default —
|
|
11
|
+
* do not rely on control-plane passing an override.
|
|
12
|
+
*/
|
|
13
|
+
export declare const STUDIO_MAX_DESIGN_MD_TOKENS = 4500;
|
|
14
|
+
export interface StudioComposeContext {
|
|
15
|
+
catalog: Catalog;
|
|
16
|
+
resourceQuery?: ResourceQueryService;
|
|
17
|
+
designMdSelector?: DesignMdSelector;
|
|
18
|
+
skillSelector?: SkillSelector;
|
|
19
|
+
agent?: Agent;
|
|
20
|
+
language?: "zh" | "en";
|
|
21
|
+
resourceSearchLimit?: number;
|
|
22
|
+
forceIncludeDesignMdIds?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Design-md token budget. Defaults to `STUDIO_MAX_DESIGN_MD_TOKENS` (4500)
|
|
25
|
+
* so house-style + one brand guide both survive `select()`.
|
|
26
|
+
*/
|
|
27
|
+
maxDesignMdTokens?: number;
|
|
28
|
+
/** Default true — durable UI Craft baseline in composeSystemPrompt. */
|
|
29
|
+
includeUiCraftBaseline?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ComposeStudioPromptInput {
|
|
32
|
+
intent: string;
|
|
33
|
+
/** Optional single design-md id from the Studio UI picker. */
|
|
34
|
+
designMdId?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Shared generation spine: intent → UI Craft + resource search + design-md + skills.
|
|
38
|
+
* Used by generate-stream, design handoff, and agent-run wiring.
|
|
39
|
+
* Defaults `forceIncludeDesignMdIds` to `frontend-principles` when omitted
|
|
40
|
+
* (pass `[]` to opt out). UI Craft baseline is always injected unless
|
|
41
|
+
* `includeUiCraftBaseline: false`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function composeStudioPrompt(context: StudioComposeContext, input: ComposeStudioPromptInput): ComposedSystemPrompt;
|
|
44
|
+
export declare function extractIntentFromMessages(messages: ReadonlyArray<{
|
|
45
|
+
role: string;
|
|
46
|
+
content: string;
|
|
47
|
+
}>): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface ComposeSpecDraft {
|
|
2
|
+
id: string;
|
|
3
|
+
/** YAML or JSON spec string */
|
|
4
|
+
spec: string;
|
|
5
|
+
updatedAt: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CreateUIBotStudioComposeHandlerOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Storage mode.
|
|
10
|
+
* - `"memory"` (default): drafts are stored in-process (lost on restart)
|
|
11
|
+
* - `"file"`: drafts are persisted to `draftDir` as `<id>.yaml`
|
|
12
|
+
*/
|
|
13
|
+
store?: "memory" | "file";
|
|
14
|
+
/**
|
|
15
|
+
* Root directory under which `.uibot/compose-drafts/` is created.
|
|
16
|
+
* Defaults to `process.cwd()`. Only used when `store === "file"`.
|
|
17
|
+
*/
|
|
18
|
+
draftRootDir?: string;
|
|
19
|
+
/** Base path prefix. Defaults to `"/api/studio/compose"` */
|
|
20
|
+
basePath?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Factory for Compose draft endpoints:
|
|
24
|
+
*
|
|
25
|
+
* - `GET {base}` → `{ drafts: ComposeSpecDraft[] }`
|
|
26
|
+
* - `GET {base}/:id` → `ComposeSpecDraft`
|
|
27
|
+
* - `POST {base}` → `ComposeSpecDraft` (body: `{ id?: string, spec: string }`)
|
|
28
|
+
*
|
|
29
|
+
* Controlled via `UIBOT_COMPOSE_STORE=memory|file` env or `options.store`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createUIBotStudioComposeHandler(options?: CreateUIBotStudioComposeHandlerOptions): (request: Request) => Promise<Response>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { Catalog, DesignMdSelector, ExecutionRuntime, ModelGenerateRequest, PrototypeSpec, VisualEvaluationEvidence } from "@uibot/contracts";
|
|
2
|
+
import { type ModelStreamEvent } from "./studio-http-shared.js";
|
|
3
|
+
export interface CreateUIBotStudioDesignPrototypeHandlerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Filesystem root under which prototypes are stored at
|
|
6
|
+
* `<allowedRoot>/.uibot/prototypes/<id>.json`. All filesystem writes are
|
|
7
|
+
* confined to this directory; any path-traversal attempt returns 400/403.
|
|
8
|
+
*/
|
|
9
|
+
allowedRoot: string;
|
|
10
|
+
/** Base path prefix. Defaults to "/api/studio". */
|
|
11
|
+
basePath?: string;
|
|
12
|
+
/** Now supplier override — test-only hook for deterministic `updatedAt`. */
|
|
13
|
+
_now?: () => string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Factory for the Design prototype CRUD endpoints (v2.14+):
|
|
17
|
+
*
|
|
18
|
+
* - `POST {base}/design/prototype` — create; 409 if id exists
|
|
19
|
+
* - `GET {base}/design/prototype` — list summaries (newest first)
|
|
20
|
+
* - `GET {base}/design/prototype/:id` — read
|
|
21
|
+
* - `PUT {base}/design/prototype/:id` — update (must exist)
|
|
22
|
+
* - `DELETE {base}/design/prototype/:id` — 204 on success, 404 if missing
|
|
23
|
+
*
|
|
24
|
+
* Security contract:
|
|
25
|
+
* - Ids must match `[a-zA-Z0-9_-]+` and ≤ 128 chars; everything else → 400.
|
|
26
|
+
* - The resolved file path must stay within `<allowedRoot>/.uibot/prototypes/`
|
|
27
|
+
* — belt-and-braces with the id regex.
|
|
28
|
+
* - Handler never fabricates data: parse failures return 500 with a
|
|
29
|
+
* structured error (per memory `feedback_no_mock_preview`).
|
|
30
|
+
*
|
|
31
|
+
* `updatedAt` is always stamped server-side on write; client-supplied values
|
|
32
|
+
* are ignored to keep the timestamp monotonic and trustworthy.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createUIBotStudioDesignPrototypeHandler(options: CreateUIBotStudioDesignPrototypeHandlerOptions): (request: Request) => Promise<Response>;
|
|
35
|
+
export interface DesignHandoffError {
|
|
36
|
+
/** Stable machine code for UI to branch on (e.g. `server-handler-dry-run-failed`). */
|
|
37
|
+
code: string;
|
|
38
|
+
/** Interaction id the error originated from, when applicable. */
|
|
39
|
+
interactionId?: string;
|
|
40
|
+
/** Human-readable message. */
|
|
41
|
+
message: string;
|
|
42
|
+
}
|
|
43
|
+
export type DesignHandoffVisualCritiqueSource = {
|
|
44
|
+
kind: "prototype";
|
|
45
|
+
prototypeId: string;
|
|
46
|
+
prototype: PrototypeSpec;
|
|
47
|
+
} | {
|
|
48
|
+
kind: "html" | "deck";
|
|
49
|
+
html: string;
|
|
50
|
+
title?: string;
|
|
51
|
+
designMdId?: string;
|
|
52
|
+
};
|
|
53
|
+
export interface DesignHandoffVisualCritiqueInput {
|
|
54
|
+
intent: string;
|
|
55
|
+
draftYaml: string;
|
|
56
|
+
source: DesignHandoffVisualCritiqueSource;
|
|
57
|
+
}
|
|
58
|
+
export type DesignHandoffVisualCritiqueResult = {
|
|
59
|
+
status: "scored";
|
|
60
|
+
evidence?: VisualEvaluationEvidence;
|
|
61
|
+
score: number;
|
|
62
|
+
reasoning?: string;
|
|
63
|
+
raw?: unknown;
|
|
64
|
+
} | {
|
|
65
|
+
status: "unavailable";
|
|
66
|
+
evidence?: VisualEvaluationEvidence;
|
|
67
|
+
reason?: string;
|
|
68
|
+
};
|
|
69
|
+
export type DesignHandoffVisualCritiqueProvider = (input: DesignHandoffVisualCritiqueInput) => Promise<DesignHandoffVisualCritiqueResult> | DesignHandoffVisualCritiqueResult;
|
|
70
|
+
export type DesignHandoffVisualCritiqueResponse = DesignHandoffVisualCritiqueResult & {
|
|
71
|
+
minScore?: number;
|
|
72
|
+
secondPass?: "skipped" | "rewritten" | "failed";
|
|
73
|
+
/**
|
|
74
|
+
* When a rewrite is performed, the outer fields reflect the SECOND-PASS score
|
|
75
|
+
* (matching the saved draft); `firstPass` preserves the original score that
|
|
76
|
+
* triggered the rewrite. When no rewrite happens, `firstPass` is absent and
|
|
77
|
+
* the outer fields are the only score.
|
|
78
|
+
*/
|
|
79
|
+
firstPass?: {
|
|
80
|
+
score: number;
|
|
81
|
+
reasoning?: string;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
export interface CreateUIBotStudioDesignHandoffHandlerOptions {
|
|
85
|
+
/**
|
|
86
|
+
* Read-only prototype lookup. Returning `null` → 404. Implementations should
|
|
87
|
+
* reject any traversal/invalid ids *inside* the storage adapter (same id
|
|
88
|
+
* regex as `createUIBotStudioDesignPrototypeHandler`).
|
|
89
|
+
*/
|
|
90
|
+
prototypeStorage: {
|
|
91
|
+
get(id: string): Promise<PrototypeSpec | null> | PrototypeSpec | null;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Persist the generated UIBotSpec YAML as a compose draft and return the
|
|
95
|
+
* assigned draft id. When `id` is `undefined`, the callee allocates one.
|
|
96
|
+
*/
|
|
97
|
+
saveComposeDraft: (id: string | undefined, spec: string) => {
|
|
98
|
+
id: string;
|
|
99
|
+
updatedAt: string;
|
|
100
|
+
} | Promise<{
|
|
101
|
+
id: string;
|
|
102
|
+
updatedAt: string;
|
|
103
|
+
}>;
|
|
104
|
+
catalog: Catalog;
|
|
105
|
+
modelRegistry: {
|
|
106
|
+
generateStream: (request: ModelGenerateRequest) => AsyncIterable<ModelStreamEvent>;
|
|
107
|
+
defaultModel?: string;
|
|
108
|
+
};
|
|
109
|
+
/** When provided, feeds into `composeStudioPrompt` for design-md injection. */
|
|
110
|
+
designMdSelector?: DesignMdSelector;
|
|
111
|
+
/**
|
|
112
|
+
* Design-md ids that `composeStudioPrompt` force-includes on every handoff,
|
|
113
|
+
* regardless of intent scoring. Defaults to `["frontend-principles"]` so the
|
|
114
|
+
* AI always sees the house style anchor; pass an explicit empty array to
|
|
115
|
+
* opt out, or override to anchor different entries.
|
|
116
|
+
*/
|
|
117
|
+
forceIncludeDesignMdIds?: string[];
|
|
118
|
+
/**
|
|
119
|
+
* Design-md token budget for handoff compose. Defaults to
|
|
120
|
+
* `STUDIO_MAX_DESIGN_MD_TOKENS` (4500) so force-include + one brand guide
|
|
121
|
+
* both fit. `composeSystemPrompt`'s generic default of 2000 is not used here.
|
|
122
|
+
*/
|
|
123
|
+
maxDesignMdTokens?: number;
|
|
124
|
+
/**
|
|
125
|
+
* Optional `execution:runtime` capability. When wired, every prototype
|
|
126
|
+
* `interaction` whose `executionTarget === "server"` gets a dry-run via
|
|
127
|
+
* `run()`; failures append a `server-handler-dry-run-failed` error to the
|
|
128
|
+
* response but **never** block draft generation. When omitted, dry-run is
|
|
129
|
+
* skipped silently — consistent with spec "未装配时降级".
|
|
130
|
+
*/
|
|
131
|
+
executionRuntime?: ExecutionRuntime;
|
|
132
|
+
/**
|
|
133
|
+
* Optional post-generation visual quality critique. The provider is DI-only:
|
|
134
|
+
* application does not import VLM, Chrome, or concrete model SDKs. Provider
|
|
135
|
+
* failures are reported as structured errors and never fabricate a score.
|
|
136
|
+
*/
|
|
137
|
+
visualCritique?: {
|
|
138
|
+
provider: DesignHandoffVisualCritiqueProvider;
|
|
139
|
+
minScore?: number;
|
|
140
|
+
rewriteOnLowScore?: boolean;
|
|
141
|
+
};
|
|
142
|
+
basePath?: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Factory for the Design handoff endpoint (v2.14+):
|
|
146
|
+
*
|
|
147
|
+
* - `POST {base}/design/handoff` with body `{ prototypeId, modelId? }`
|
|
148
|
+
* → `{ draftId, durationMs, errors }`
|
|
149
|
+
*
|
|
150
|
+
* Flow:
|
|
151
|
+
* 1. Load prototype via `prototypeStorage.get(prototypeId)` → 404 if missing.
|
|
152
|
+
* 2. Serialize prototype into a human-readable intent string.
|
|
153
|
+
* 3. `composeStudioPrompt({ catalog, intent, designMdSelector })`
|
|
154
|
+
* with the studio design-md token budget.
|
|
155
|
+
* 4. If `executionRuntime` is wired, dry-run every server-side handlerCode;
|
|
156
|
+
* failures go into `errors[]` but do not abort.
|
|
157
|
+
* 5. `modelRegistry.generateStream(...)` → accumulate `content` chunks.
|
|
158
|
+
* 6. `saveComposeDraft(undefined, yaml)` → return `draftId`.
|
|
159
|
+
*
|
|
160
|
+
* Failures follow memory `feedback_no_mock_preview`: any step error surfaces
|
|
161
|
+
* as a structured JSON response with a stable HTTP status (400 / 404 / 500 /
|
|
162
|
+
* 502) — never a fabricated draft.
|
|
163
|
+
*/
|
|
164
|
+
export declare function createUIBotStudioDesignHandoffHandler(options: CreateUIBotStudioDesignHandoffHandlerOptions): (request: Request) => Promise<Response>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP handler: export merged design-md registry as JSON map id→file (v2.28 SC-5).
|
|
3
|
+
*/
|
|
4
|
+
import type { DesignMdRegistry } from "@uibot/design-md";
|
|
5
|
+
export interface CreateUIBotStudioDesignMdExportHandlerOptions {
|
|
6
|
+
/** Returns the live design-md registry (merged layers). */
|
|
7
|
+
getRegistry: () => Pick<DesignMdRegistry, "list">;
|
|
8
|
+
/** Base path. Defaults to `/api/studio/design-md/export`. */
|
|
9
|
+
path?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function createUIBotStudioDesignMdExportHandler(options: CreateUIBotStudioDesignMdExportHandlerOptions): (req: Request) => Promise<Response | null>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ModelGenerateResult } from "@uibot/contracts";
|
|
2
|
+
/** Mirror of ModelStreamEvent from @uibot/model — kept inline to avoid cross-package dependency. */
|
|
3
|
+
export type ModelStreamEvent = {
|
|
4
|
+
type: "reasoning";
|
|
5
|
+
tokens: number;
|
|
6
|
+
chunk: string;
|
|
7
|
+
} | {
|
|
8
|
+
type: "content";
|
|
9
|
+
tokens: number;
|
|
10
|
+
chunk: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: "done";
|
|
13
|
+
result: ModelGenerateResult;
|
|
14
|
+
};
|
|
15
|
+
export type HttpHeadersInit = Headers | Record<string, string> | Array<[string, string]>;
|
|
16
|
+
export declare function json(body: unknown, status: number, headers?: HttpHeadersInit): Response;
|
|
17
|
+
/**
|
|
18
|
+
* Stable error contract for Studio HTTP handlers (v2.36): every error response
|
|
19
|
+
* carries a machine-readable `code` plus, when available, a `requestId` that is
|
|
20
|
+
* echoed in the body, in the `x-uibot-request-id` header, and — with `log: true`
|
|
21
|
+
* — in structured server logs so AI-generation failures can be correlated
|
|
22
|
+
* across requests.
|
|
23
|
+
*/
|
|
24
|
+
export interface ErrorResponseOptions {
|
|
25
|
+
/** Stable machine code for the UI to branch on (e.g. `generate-failed`). */
|
|
26
|
+
code?: string;
|
|
27
|
+
/** Correlation id echoed in the body, header, and server logs. */
|
|
28
|
+
requestId?: string;
|
|
29
|
+
/** When true, emits a `[studio-http] <code> status=<n> requestId=<id>` line. */
|
|
30
|
+
log?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function errorCodeForStatus(status: number): string;
|
|
33
|
+
export declare function errorResponseRaw(status: number, error: string, options?: ErrorResponseOptions): Response;
|
|
34
|
+
export declare function normalizeResourcesBasePath(base?: string): string;
|