human2ai 0.1.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/LICENSE +21 -0
- package/README.md +120 -0
- package/assets/quaternius/License_Standard.txt +22 -0
- package/assets/quaternius/README.md +31 -0
- package/assets/quaternius/Superhero_Female_FullBody.bin +0 -0
- package/assets/quaternius/Superhero_Female_FullBody.gltf +2056 -0
- package/assets/quaternius/Superhero_Male_FullBody.bin +0 -0
- package/assets/quaternius/Superhero_Male_FullBody.gltf +2018 -0
- package/dist/cli/integration.d.ts +39 -0
- package/dist/cli/integration.js +466 -0
- package/dist/cli/integration.js.map +1 -0
- package/dist/cli/main.d.ts +17 -0
- package/dist/cli/main.js +1455 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/database/composition-session-repository.d.ts +37 -0
- package/dist/database/composition-session-repository.js +147 -0
- package/dist/database/composition-session-repository.js.map +1 -0
- package/dist/database/draft-version-errors.d.ts +29 -0
- package/dist/database/draft-version-errors.js +47 -0
- package/dist/database/draft-version-errors.js.map +1 -0
- package/dist/database/draft-version-store.d.ts +30 -0
- package/dist/database/draft-version-store.js +168 -0
- package/dist/database/draft-version-store.js.map +1 -0
- package/dist/database/image-asset-repository.d.ts +37 -0
- package/dist/database/image-asset-repository.js +101 -0
- package/dist/database/image-asset-repository.js.map +1 -0
- package/dist/database/image-input.d.ts +15 -0
- package/dist/database/image-input.js +28 -0
- package/dist/database/image-input.js.map +1 -0
- package/dist/database/migrate.d.ts +4 -0
- package/dist/database/migrate.js +45 -0
- package/dist/database/migrate.js.map +1 -0
- package/dist/database/project-session-repository.d.ts +72 -0
- package/dist/database/project-session-repository.js +291 -0
- package/dist/database/project-session-repository.js.map +1 -0
- package/dist/database/spatial-session-repository.d.ts +26 -0
- package/dist/database/spatial-session-repository.js +44 -0
- package/dist/database/spatial-session-repository.js.map +1 -0
- package/dist/database/style-library-repository.d.ts +70 -0
- package/dist/database/style-library-repository.js +290 -0
- package/dist/database/style-library-repository.js.map +1 -0
- package/dist/database/svg-input.d.ts +1 -0
- package/dist/database/svg-input.js +77 -0
- package/dist/database/svg-input.js.map +1 -0
- package/dist/database/ui-sketch-session-repository.d.ts +19 -0
- package/dist/database/ui-sketch-session-repository.js +35 -0
- package/dist/database/ui-sketch-session-repository.js.map +1 -0
- package/dist/domain/canvas-layer-order.d.ts +6 -0
- package/dist/domain/canvas-layer-order.js +40 -0
- package/dist/domain/canvas-layer-order.js.map +1 -0
- package/dist/domain/canvas-node-metadata.d.ts +20 -0
- package/dist/domain/canvas-node-metadata.js +17 -0
- package/dist/domain/canvas-node-metadata.js.map +1 -0
- package/dist/domain/canvas-states.d.ts +8 -0
- package/dist/domain/canvas-states.js +23 -0
- package/dist/domain/canvas-states.js.map +1 -0
- package/dist/domain/composition/analysis.d.ts +104 -0
- package/dist/domain/composition/analysis.js +337 -0
- package/dist/domain/composition/analysis.js.map +1 -0
- package/dist/domain/composition/camera-reference.d.ts +24 -0
- package/dist/domain/composition/camera-reference.js +34 -0
- package/dist/domain/composition/camera-reference.js.map +1 -0
- package/dist/domain/composition/draft.d.ts +50 -0
- package/dist/domain/composition/draft.js +609 -0
- package/dist/domain/composition/draft.js.map +1 -0
- package/dist/domain/composition/frame.d.ts +23 -0
- package/dist/domain/composition/frame.js +154 -0
- package/dist/domain/composition/frame.js.map +1 -0
- package/dist/domain/composition/geometry.d.ts +15 -0
- package/dist/domain/composition/geometry.js +262 -0
- package/dist/domain/composition/geometry.js.map +1 -0
- package/dist/domain/composition/index.d.ts +13 -0
- package/dist/domain/composition/index.js +10 -0
- package/dist/domain/composition/index.js.map +1 -0
- package/dist/domain/composition/layers.d.ts +4 -0
- package/dist/domain/composition/layers.js +12 -0
- package/dist/domain/composition/layers.js.map +1 -0
- package/dist/domain/composition/records.d.ts +14 -0
- package/dist/domain/composition/records.js +2 -0
- package/dist/domain/composition/records.js.map +1 -0
- package/dist/domain/composition/refinement/engine.d.ts +12 -0
- package/dist/domain/composition/refinement/engine.js +521 -0
- package/dist/domain/composition/refinement/engine.js.map +1 -0
- package/dist/domain/composition/refinement/relations.d.ts +16 -0
- package/dist/domain/composition/refinement/relations.js +293 -0
- package/dist/domain/composition/refinement/relations.js.map +1 -0
- package/dist/domain/composition/refinement/types.d.ts +181 -0
- package/dist/domain/composition/refinement/types.js +2 -0
- package/dist/domain/composition/refinement/types.js.map +1 -0
- package/dist/domain/composition/render.d.ts +5 -0
- package/dist/domain/composition/render.js +169 -0
- package/dist/domain/composition/render.js.map +1 -0
- package/dist/domain/composition/states.d.ts +9 -0
- package/dist/domain/composition/states.js +104 -0
- package/dist/domain/composition/states.js.map +1 -0
- package/dist/domain/composition/types.d.ts +149 -0
- package/dist/domain/composition/types.js +2 -0
- package/dist/domain/composition/types.js.map +1 -0
- package/dist/domain/composition/workflow.d.ts +15 -0
- package/dist/domain/composition/workflow.js +77 -0
- package/dist/domain/composition/workflow.js.map +1 -0
- package/dist/domain/fingerprint.d.ts +2 -0
- package/dist/domain/fingerprint.js +25 -0
- package/dist/domain/fingerprint.js.map +1 -0
- package/dist/domain/session/canvas-edit-history.d.ts +17 -0
- package/dist/domain/session/canvas-edit-history.js +53 -0
- package/dist/domain/session/canvas-edit-history.js.map +1 -0
- package/dist/domain/session/capabilities.d.ts +16 -0
- package/dist/domain/session/capabilities.js +84 -0
- package/dist/domain/session/capabilities.js.map +1 -0
- package/dist/domain/session/draft-version.d.ts +41 -0
- package/dist/domain/session/draft-version.js +2 -0
- package/dist/domain/session/draft-version.js.map +1 -0
- package/dist/domain/session/index.d.ts +5 -0
- package/dist/domain/session/index.js +3 -0
- package/dist/domain/session/index.js.map +1 -0
- package/dist/domain/session/types.d.ts +23 -0
- package/dist/domain/session/types.js +2 -0
- package/dist/domain/session/types.js.map +1 -0
- package/dist/domain/spatial/assets/quaternius-female-rig.json +799 -0
- package/dist/domain/spatial/assets/quaternius-rig.json +799 -0
- package/dist/domain/spatial/assets/quaternius-superhero-female.json +1 -0
- package/dist/domain/spatial/assets/quaternius-superhero.json +1 -0
- package/dist/domain/spatial/camera-box.d.ts +13 -0
- package/dist/domain/spatial/camera-box.js +52 -0
- package/dist/domain/spatial/camera-box.js.map +1 -0
- package/dist/domain/spatial/geometric-model.d.ts +4 -0
- package/dist/domain/spatial/geometric-model.js +101 -0
- package/dist/domain/spatial/geometric-model.js.map +1 -0
- package/dist/domain/spatial/hands.d.ts +36 -0
- package/dist/domain/spatial/hands.js +128 -0
- package/dist/domain/spatial/hands.js.map +1 -0
- package/dist/domain/spatial/index.d.ts +30 -0
- package/dist/domain/spatial/index.js +381 -0
- package/dist/domain/spatial/index.js.map +1 -0
- package/dist/domain/spatial/kinematics.d.ts +27 -0
- package/dist/domain/spatial/kinematics.js +285 -0
- package/dist/domain/spatial/kinematics.js.map +1 -0
- package/dist/domain/spatial/lighting.d.ts +35 -0
- package/dist/domain/spatial/lighting.js +173 -0
- package/dist/domain/spatial/lighting.js.map +1 -0
- package/dist/domain/spatial/model.d.ts +5 -0
- package/dist/domain/spatial/model.js +193 -0
- package/dist/domain/spatial/model.js.map +1 -0
- package/dist/domain/spatial/morph.d.ts +3 -0
- package/dist/domain/spatial/morph.js +187 -0
- package/dist/domain/spatial/morph.js.map +1 -0
- package/dist/domain/spatial/proportions.d.ts +46 -0
- package/dist/domain/spatial/proportions.js +59 -0
- package/dist/domain/spatial/proportions.js.map +1 -0
- package/dist/domain/spatial/reference-lines.d.ts +6 -0
- package/dist/domain/spatial/reference-lines.js +58 -0
- package/dist/domain/spatial/reference-lines.js.map +1 -0
- package/dist/domain/spatial/scene-cache.d.ts +15 -0
- package/dist/domain/spatial/scene-cache.js +69 -0
- package/dist/domain/spatial/scene-cache.js.map +1 -0
- package/dist/domain/spatial/scene.d.ts +8 -0
- package/dist/domain/spatial/scene.js +69 -0
- package/dist/domain/spatial/scene.js.map +1 -0
- package/dist/domain/spatial/types.d.ts +187 -0
- package/dist/domain/spatial/types.js +5 -0
- package/dist/domain/spatial/types.js.map +1 -0
- package/dist/domain/style/index.d.ts +1 -0
- package/dist/domain/style/index.js +2 -0
- package/dist/domain/style/index.js.map +1 -0
- package/dist/domain/style/prompt-summary.d.ts +2 -0
- package/dist/domain/style/prompt-summary.js +11 -0
- package/dist/domain/style/prompt-summary.js.map +1 -0
- package/dist/domain/style/types.d.ts +32 -0
- package/dist/domain/style/types.js +3 -0
- package/dist/domain/style/types.js.map +1 -0
- package/dist/domain/ui-sketch/draft.d.ts +12 -0
- package/dist/domain/ui-sketch/draft.js +424 -0
- package/dist/domain/ui-sketch/draft.js.map +1 -0
- package/dist/domain/ui-sketch/geometry.d.ts +7 -0
- package/dist/domain/ui-sketch/geometry.js +11 -0
- package/dist/domain/ui-sketch/geometry.js.map +1 -0
- package/dist/domain/ui-sketch/groups.d.ts +5 -0
- package/dist/domain/ui-sketch/groups.js +40 -0
- package/dist/domain/ui-sketch/groups.js.map +1 -0
- package/dist/domain/ui-sketch/index.d.ts +8 -0
- package/dist/domain/ui-sketch/index.js +8 -0
- package/dist/domain/ui-sketch/index.js.map +1 -0
- package/dist/domain/ui-sketch/layers.d.ts +4 -0
- package/dist/domain/ui-sketch/layers.js +11 -0
- package/dist/domain/ui-sketch/layers.js.map +1 -0
- package/dist/domain/ui-sketch/render.d.ts +2 -0
- package/dist/domain/ui-sketch/render.js +58 -0
- package/dist/domain/ui-sketch/render.js.map +1 -0
- package/dist/domain/ui-sketch/standardize.d.ts +17 -0
- package/dist/domain/ui-sketch/standardize.js +139 -0
- package/dist/domain/ui-sketch/standardize.js.map +1 -0
- package/dist/domain/ui-sketch/states.d.ts +5 -0
- package/dist/domain/ui-sketch/states.js +21 -0
- package/dist/domain/ui-sketch/states.js.map +1 -0
- package/dist/domain/ui-sketch/types.d.ts +73 -0
- package/dist/domain/ui-sketch/types.js +2 -0
- package/dist/domain/ui-sketch/types.js.map +1 -0
- package/dist/server/app.d.ts +18 -0
- package/dist/server/app.js +108 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/image-content-type-parser.d.ts +2 -0
- package/dist/server/image-content-type-parser.js +5 -0
- package/dist/server/image-content-type-parser.js.map +1 -0
- package/dist/server/routes/composition-sessions.d.ts +3 -0
- package/dist/server/routes/composition-sessions.js +190 -0
- package/dist/server/routes/composition-sessions.js.map +1 -0
- package/dist/server/routes/draft-version-routes.d.ts +10 -0
- package/dist/server/routes/draft-version-routes.js +201 -0
- package/dist/server/routes/draft-version-routes.js.map +1 -0
- package/dist/server/routes/image-assets.d.ts +3 -0
- package/dist/server/routes/image-assets.js +114 -0
- package/dist/server/routes/image-assets.js.map +1 -0
- package/dist/server/routes/project-sessions.d.ts +48 -0
- package/dist/server/routes/project-sessions.js +305 -0
- package/dist/server/routes/project-sessions.js.map +1 -0
- package/dist/server/routes/spatial-sessions.d.ts +3 -0
- package/dist/server/routes/spatial-sessions.js +80 -0
- package/dist/server/routes/spatial-sessions.js.map +1 -0
- package/dist/server/routes/style-library.d.ts +3 -0
- package/dist/server/routes/style-library.js +308 -0
- package/dist/server/routes/style-library.js.map +1 -0
- package/dist/server/routes/ui-sketch-sessions.d.ts +3 -0
- package/dist/server/routes/ui-sketch-sessions.js +14 -0
- package/dist/server/routes/ui-sketch-sessions.js.map +1 -0
- package/dist/server/runtime.d.ts +30 -0
- package/dist/server/runtime.js +123 -0
- package/dist/server/runtime.js.map +1 -0
- package/dist/server/spatial-render.d.ts +5 -0
- package/dist/server/spatial-render.js +360 -0
- package/dist/server/spatial-render.js.map +1 -0
- package/dist/server/start.d.ts +1 -0
- package/dist/server/start.js +3 -0
- package/dist/server/start.js.map +1 -0
- package/licenses/THIRD-PARTY-NOTICES.txt +16664 -0
- package/licenses/YisiUI-LICENSE +21 -0
- package/locales/en/common.json +671 -0
- package/migrations/0001_projects_and_sessions.sql +45 -0
- package/migrations/0002_composition_versions_and_refinements.sql +26 -0
- package/migrations/0003_ui_sketch_draft_versions.sql +12 -0
- package/migrations/0004_image_assets.sql +16 -0
- package/migrations/0005_style_library.sql +31 -0
- package/migrations/0006_session_styles.sql +6 -0
- package/migrations/0007_svg_image_assets.sql +19 -0
- package/migrations/0008_spatial_spaces.sql +20 -0
- package/package.json +82 -0
- package/schemas/composition-draft.schema.json +234 -0
- package/schemas/composition-refinement-plan.schema.json +758 -0
- package/schemas/spatial-draft.schema.json +517 -0
- package/schemas/spatial-operations.schema.json +1082 -0
- package/schemas/ui-layout-standardization-plan.schema.json +29 -0
- package/schemas/ui-sketch-draft.schema.json +197 -0
- package/skills/human2ai/SKILL.md +149 -0
- package/skills/human2ai/agents/openai.yaml +3 -0
- package/skills/human2ai/references/composition-projection.md +170 -0
- package/skills/human2ai/references/composition.md +79 -0
- package/skills/human2ai/references/spatial.md +188 -0
- package/skills/human2ai/references/svg-images.md +27 -0
- package/skills/human2ai/references/ui-layout.md +100 -0
- package/web/out/404/index.html +1 -0
- package/web/out/404.html +1 -0
- package/web/out/__next.__PAGE__.txt +26 -0
- package/web/out/__next._full.txt +21 -0
- package/web/out/__next._tree.txt +4 -0
- package/web/out/_next/static/TV-jgcACg6HANZAMZTE2S/_buildManifest.js +1 -0
- package/web/out/_next/static/TV-jgcACg6HANZAMZTE2S/_ssgManifest.js +1 -0
- package/web/out/_next/static/chunks/130-9fadd0432daff55d.js +1 -0
- package/web/out/_next/static/chunks/158-eb00456e1bab68b3.js +52 -0
- package/web/out/_next/static/chunks/20-0801fc297cda2a7a.js +1 -0
- package/web/out/_next/static/chunks/248-d4a79649dae2a3f8.js +259 -0
- package/web/out/_next/static/chunks/678-1305cadf8254d814.js +1 -0
- package/web/out/_next/static/chunks/728-eb8b667f79229443.js +1 -0
- package/web/out/_next/static/chunks/83607670-bc1279370476e59f.js +1 -0
- package/web/out/_next/static/chunks/app/_global-error/page-5eece43b8152c414.js +1 -0
- package/web/out/_next/static/chunks/app/_not-found/page-c0cd75ac39fbf9cf.js +1 -0
- package/web/out/_next/static/chunks/app/composition/page-051ee2fabb12110a.js +1 -0
- package/web/out/_next/static/chunks/app/layout-745ca27ef8830f4f.js +1 -0
- package/web/out/_next/static/chunks/app/page-0027378a269a6168.js +1 -0
- package/web/out/_next/static/chunks/app/spatial/page-266dedc81784d4f6.js +1 -0
- package/web/out/_next/static/chunks/app/styles/page-d5cb83af828ea9ed.js +1 -0
- package/web/out/_next/static/chunks/app/ui-sketch/page-2a8436e05a05c618.js +1 -0
- package/web/out/_next/static/chunks/c3f2cda1-9e279dab137b7272.js +342 -0
- package/web/out/_next/static/chunks/c7879cf7-7873c8afd9c9c666.js +1 -0
- package/web/out/_next/static/chunks/framework-6eacf80ec1e4c887.js +1 -0
- package/web/out/_next/static/chunks/main-5ee8fd93319f955c.js +5 -0
- package/web/out/_next/static/chunks/main-app-0cf10803ab17c700.js +1 -0
- package/web/out/_next/static/chunks/next/dist/client/components/builtin/app-error-5eece43b8152c414.js +1 -0
- package/web/out/_next/static/chunks/next/dist/client/components/builtin/forbidden-5eece43b8152c414.js +1 -0
- package/web/out/_next/static/chunks/next/dist/client/components/builtin/global-error-728204b7cccc4ed2.js +1 -0
- package/web/out/_next/static/chunks/next/dist/client/components/builtin/not-found-5eece43b8152c414.js +1 -0
- package/web/out/_next/static/chunks/next/dist/client/components/builtin/unauthorized-5eece43b8152c414.js +1 -0
- package/web/out/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/web/out/_next/static/chunks/webpack-97ae63c0e0b2a512.js +1 -0
- package/web/out/_next/static/css/3b7982b41ed8eccd.css +4 -0
- package/web/out/_next/static/css/81ae71f1d3e9a866.css +1 -0
- package/web/out/_next/static/css/8c3843f4951fa9f6.css +5 -0
- package/web/out/_next/static/css/c739d0131cdcc891.css +1 -0
- package/web/out/_next/static/css/ce1b4bb3ad3c6073.css +1 -0
- package/web/out/_next/static/css/db96ae2e88545d96.css +1 -0
- package/web/out/_not-found/__next._full.txt +18 -0
- package/web/out/_not-found/__next._not-found.__PAGE__.txt +24 -0
- package/web/out/_not-found/__next._tree.txt +3 -0
- package/web/out/_not-found/index.html +1 -0
- package/web/out/_not-found/index.txt +18 -0
- package/web/out/composition/__next._full.txt +25 -0
- package/web/out/composition/__next._tree.txt +6 -0
- package/web/out/composition/__next.composition.__PAGE__.txt +31 -0
- package/web/out/composition/index.html +1 -0
- package/web/out/composition/index.txt +25 -0
- package/web/out/index.html +1 -0
- package/web/out/index.txt +21 -0
- package/web/out/spatial/__next._full.txt +23 -0
- package/web/out/spatial/__next._tree.txt +4 -0
- package/web/out/spatial/__next.spatial.__PAGE__.txt +29 -0
- package/web/out/spatial/index.html +1 -0
- package/web/out/spatial/index.txt +23 -0
- package/web/out/styles/__next._full.txt +23 -0
- package/web/out/styles/__next._tree.txt +4 -0
- package/web/out/styles/__next.styles.__PAGE__.txt +29 -0
- package/web/out/styles/index.html +1 -0
- package/web/out/styles/index.txt +23 -0
- package/web/out/ui-sketch/__next._full.txt +25 -0
- package/web/out/ui-sketch/__next._tree.txt +6 -0
- package/web/out/ui-sketch/__next.ui-sketch.__PAGE__.txt +31 -0
- package/web/out/ui-sketch/index.html +1 -0
- package/web/out/ui-sketch/index.txt +25 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { createReadStream } from "node:fs";
|
|
2
|
+
import { InvalidStyleError, InvalidStyleReferenceError, StyleNotFoundError, StyleReferenceNotFoundError, StyleRevisionConflictError, } from "../../database/style-library-repository.js";
|
|
3
|
+
import { STYLE_CATEGORIES, } from "../../domain/style/index.js";
|
|
4
|
+
import { RevisionConflictError, SessionNotFoundError } from "../../database/project-session-repository.js";
|
|
5
|
+
import { MAX_STYLE_PROMPT_SUMMARY_LENGTH } from "../../domain/style/prompt-summary.js";
|
|
6
|
+
import { sessionSchema } from "./project-sessions.js";
|
|
7
|
+
const styleParamsSchema = {
|
|
8
|
+
type: "object",
|
|
9
|
+
additionalProperties: false,
|
|
10
|
+
required: ["styleId"],
|
|
11
|
+
properties: { styleId: { type: "string", minLength: 1 } },
|
|
12
|
+
};
|
|
13
|
+
const referenceParamsSchema = {
|
|
14
|
+
type: "object",
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
required: ["styleId", "referenceId"],
|
|
17
|
+
properties: {
|
|
18
|
+
styleId: { type: "string", minLength: 1 },
|
|
19
|
+
referenceId: { type: "string", minLength: 1 },
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const referenceImageSchema = {
|
|
23
|
+
type: "object",
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
required: [
|
|
26
|
+
"id",
|
|
27
|
+
"styleId",
|
|
28
|
+
"originalFilename",
|
|
29
|
+
"mimeType",
|
|
30
|
+
"byteSize",
|
|
31
|
+
"width",
|
|
32
|
+
"height",
|
|
33
|
+
"position",
|
|
34
|
+
"createdAt",
|
|
35
|
+
],
|
|
36
|
+
properties: {
|
|
37
|
+
id: { type: "string" },
|
|
38
|
+
styleId: { type: "string" },
|
|
39
|
+
originalFilename: { type: "string" },
|
|
40
|
+
mimeType: { enum: ["image/png", "image/jpeg", "image/webp"] },
|
|
41
|
+
byteSize: { type: "integer", minimum: 1 },
|
|
42
|
+
width: { type: "integer", minimum: 1 },
|
|
43
|
+
height: { type: "integer", minimum: 1 },
|
|
44
|
+
position: { type: "integer", minimum: 0 },
|
|
45
|
+
createdAt: { type: "string" },
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
const styleSchema = {
|
|
49
|
+
type: "object",
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
required: [
|
|
52
|
+
"id",
|
|
53
|
+
"name",
|
|
54
|
+
"category",
|
|
55
|
+
"creatorType",
|
|
56
|
+
"description",
|
|
57
|
+
"promptSummary",
|
|
58
|
+
"referenceImages",
|
|
59
|
+
"revision",
|
|
60
|
+
"createdAt",
|
|
61
|
+
"updatedAt",
|
|
62
|
+
],
|
|
63
|
+
properties: {
|
|
64
|
+
id: { type: "string" },
|
|
65
|
+
name: { type: "string" },
|
|
66
|
+
category: { enum: STYLE_CATEGORIES },
|
|
67
|
+
creatorType: { enum: ["user", "agent"] },
|
|
68
|
+
description: { type: "string" },
|
|
69
|
+
promptSummary: { type: "string" },
|
|
70
|
+
referenceImages: { type: "array", items: referenceImageSchema },
|
|
71
|
+
revision: { type: "integer", minimum: 1 },
|
|
72
|
+
createdAt: { type: "string" },
|
|
73
|
+
updatedAt: { type: "string" },
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const errorSchema = {
|
|
77
|
+
type: "object",
|
|
78
|
+
additionalProperties: false,
|
|
79
|
+
required: ["code", "message"],
|
|
80
|
+
properties: {
|
|
81
|
+
code: { type: "string" },
|
|
82
|
+
message: { type: "string" },
|
|
83
|
+
actualRevision: { type: "integer", minimum: 1 },
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
const createStyleBodySchema = {
|
|
87
|
+
type: "object",
|
|
88
|
+
additionalProperties: false,
|
|
89
|
+
required: ["name", "category", "description"],
|
|
90
|
+
properties: {
|
|
91
|
+
name: { type: "string", minLength: 1, maxLength: 200 },
|
|
92
|
+
category: { enum: STYLE_CATEGORIES },
|
|
93
|
+
description: { type: "string", minLength: 1, maxLength: 20_000 },
|
|
94
|
+
promptSummary: { type: "string", minLength: 1, maxLength: MAX_STYLE_PROMPT_SUMMARY_LENGTH },
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
export function registerStyleLibraryRoutes(server, repository) {
|
|
98
|
+
const sessionStyleSchema = {
|
|
99
|
+
type: "object", additionalProperties: false, required: ["session", "style"],
|
|
100
|
+
properties: { session: sessionSchema, style: { anyOf: [styleSchema, { type: "null" }] } },
|
|
101
|
+
};
|
|
102
|
+
const sessionParams = {
|
|
103
|
+
type: "object", additionalProperties: false, required: ["sessionId"],
|
|
104
|
+
properties: { sessionId: { type: "string", minLength: 1 } },
|
|
105
|
+
};
|
|
106
|
+
server.get("/api/v1/sessions/:sessionId/style", { schema: { params: sessionParams, response: { 200: sessionStyleSchema, 404: errorSchema } } }, async (request, reply) => execute(reply, 200, () => repository.getSessionStyle(request.params.sessionId)));
|
|
107
|
+
server.patch("/api/v1/sessions/:sessionId/style", { schema: {
|
|
108
|
+
params: sessionParams,
|
|
109
|
+
body: {
|
|
110
|
+
type: "object", additionalProperties: false, required: ["styleId", "expectedRevision"],
|
|
111
|
+
properties: {
|
|
112
|
+
styleId: { anyOf: [{ type: "string", minLength: 1 }, { type: "null" }] },
|
|
113
|
+
expectedRevision: { type: "integer", minimum: 1 },
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
response: { 200: sessionStyleSchema, 404: errorSchema, 409: errorSchema },
|
|
117
|
+
} }, async (request, reply) => execute(reply, 200, () => repository.bindSessionStyle(request.params.sessionId, request.body)));
|
|
118
|
+
server.get("/api/v1/styles", {
|
|
119
|
+
schema: {
|
|
120
|
+
response: {
|
|
121
|
+
200: {
|
|
122
|
+
type: "object",
|
|
123
|
+
additionalProperties: false,
|
|
124
|
+
required: ["styles"],
|
|
125
|
+
properties: { styles: { type: "array", items: styleSchema } },
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
}, async () => ({ styles: repository.listStyles() }));
|
|
130
|
+
registerCreateStyleRoute(server, repository, "/api/v1/styles", "user");
|
|
131
|
+
registerCreateStyleRoute(server, repository, "/api/v1/agent/styles", "agent");
|
|
132
|
+
server.get("/api/v1/styles/:styleId", {
|
|
133
|
+
schema: {
|
|
134
|
+
params: styleParamsSchema,
|
|
135
|
+
response: { 200: styleSchema, 404: errorSchema },
|
|
136
|
+
},
|
|
137
|
+
}, async (request, reply) => execute(reply, 200, () => (repository.getStyle(request.params.styleId))));
|
|
138
|
+
server.get("/api/v1/agent/styles/:styleId/context", {
|
|
139
|
+
schema: {
|
|
140
|
+
params: styleParamsSchema,
|
|
141
|
+
response: {
|
|
142
|
+
200: {
|
|
143
|
+
type: "object",
|
|
144
|
+
additionalProperties: false,
|
|
145
|
+
required: ["referenceImages", "description"],
|
|
146
|
+
properties: {
|
|
147
|
+
referenceImages: {
|
|
148
|
+
type: "array",
|
|
149
|
+
items: {
|
|
150
|
+
type: "object",
|
|
151
|
+
additionalProperties: false,
|
|
152
|
+
required: ["url"],
|
|
153
|
+
properties: { url: { type: "string" } },
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
description: { type: "string" },
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
404: errorSchema,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
}, async (request, reply) => execute(reply, 200, () => {
|
|
163
|
+
const style = repository.getStyle(request.params.styleId);
|
|
164
|
+
return {
|
|
165
|
+
referenceImages: style.referenceImages.map((reference) => ({
|
|
166
|
+
url: styleReferenceContentPath(style.id, reference.id),
|
|
167
|
+
})),
|
|
168
|
+
description: style.description,
|
|
169
|
+
};
|
|
170
|
+
}));
|
|
171
|
+
server.patch("/api/v1/styles/:styleId", {
|
|
172
|
+
schema: {
|
|
173
|
+
params: styleParamsSchema,
|
|
174
|
+
body: {
|
|
175
|
+
type: "object",
|
|
176
|
+
additionalProperties: false,
|
|
177
|
+
required: ["expectedRevision"],
|
|
178
|
+
anyOf: [
|
|
179
|
+
{ required: ["name"] },
|
|
180
|
+
{ required: ["category"] },
|
|
181
|
+
{ required: ["description"] },
|
|
182
|
+
{ required: ["promptSummary"] },
|
|
183
|
+
],
|
|
184
|
+
properties: {
|
|
185
|
+
expectedRevision: { type: "integer", minimum: 1 },
|
|
186
|
+
name: { type: "string", minLength: 1, maxLength: 200 },
|
|
187
|
+
category: { enum: STYLE_CATEGORIES },
|
|
188
|
+
description: { type: "string", minLength: 1, maxLength: 20_000 },
|
|
189
|
+
promptSummary: { type: "string", minLength: 1, maxLength: MAX_STYLE_PROMPT_SUMMARY_LENGTH },
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
response: {
|
|
193
|
+
200: styleSchema,
|
|
194
|
+
400: errorSchema,
|
|
195
|
+
404: errorSchema,
|
|
196
|
+
409: errorSchema,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
}, async (request, reply) => execute(reply, 200, () => (repository.updateStyle(request.params.styleId, request.body))));
|
|
200
|
+
server.delete("/api/v1/styles/:styleId", {
|
|
201
|
+
schema: {
|
|
202
|
+
params: styleParamsSchema,
|
|
203
|
+
body: revisionBodySchema,
|
|
204
|
+
response: { 400: errorSchema, 404: errorSchema, 409: errorSchema },
|
|
205
|
+
},
|
|
206
|
+
}, async (request, reply) => execute(reply, 204, () => (repository.deleteStyle(request.params.styleId, request.body))));
|
|
207
|
+
server.post("/api/v1/styles/:styleId/references", {
|
|
208
|
+
schema: {
|
|
209
|
+
params: styleParamsSchema,
|
|
210
|
+
querystring: {
|
|
211
|
+
type: "object",
|
|
212
|
+
additionalProperties: false,
|
|
213
|
+
required: ["filename", "expectedRevision"],
|
|
214
|
+
properties: {
|
|
215
|
+
filename: { type: "string", minLength: 1, maxLength: 255 },
|
|
216
|
+
expectedRevision: { type: "integer", minimum: 1 },
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
response: {
|
|
220
|
+
201: styleSchema,
|
|
221
|
+
400: errorSchema,
|
|
222
|
+
404: errorSchema,
|
|
223
|
+
409: errorSchema,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
}, async (request, reply) => execute(reply, 201, () => (repository.addReferenceImage(request.params.styleId, {
|
|
227
|
+
filename: request.query.filename,
|
|
228
|
+
expectedRevision: request.query.expectedRevision,
|
|
229
|
+
data: request.body,
|
|
230
|
+
}))));
|
|
231
|
+
server.delete("/api/v1/styles/:styleId/references/:referenceId", {
|
|
232
|
+
schema: {
|
|
233
|
+
params: referenceParamsSchema,
|
|
234
|
+
body: revisionBodySchema,
|
|
235
|
+
response: {
|
|
236
|
+
200: styleSchema,
|
|
237
|
+
400: errorSchema,
|
|
238
|
+
404: errorSchema,
|
|
239
|
+
409: errorSchema,
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
}, async (request, reply) => execute(reply, 200, () => (repository.deleteReferenceImage(request.params.styleId, request.params.referenceId, request.body))));
|
|
243
|
+
server.get("/api/v1/styles/:styleId/references/:referenceId/content", {
|
|
244
|
+
schema: {
|
|
245
|
+
params: referenceParamsSchema,
|
|
246
|
+
response: { 404: errorSchema },
|
|
247
|
+
},
|
|
248
|
+
}, async (request, reply) => {
|
|
249
|
+
try {
|
|
250
|
+
const { reference, filePath } = repository.getReferenceImage(request.params.styleId, request.params.referenceId);
|
|
251
|
+
return reply
|
|
252
|
+
.header("cache-control", "private, max-age=31536000, immutable")
|
|
253
|
+
.header("content-length", reference.byteSize)
|
|
254
|
+
.type(reference.mimeType)
|
|
255
|
+
.send(createReadStream(filePath));
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
return sendStyleError(reply, error);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
const revisionBodySchema = {
|
|
263
|
+
type: "object",
|
|
264
|
+
additionalProperties: false,
|
|
265
|
+
required: ["expectedRevision"],
|
|
266
|
+
properties: { expectedRevision: { type: "integer", minimum: 1 } },
|
|
267
|
+
};
|
|
268
|
+
function registerCreateStyleRoute(server, repository, pathname, creatorType) {
|
|
269
|
+
server.post(pathname, {
|
|
270
|
+
schema: {
|
|
271
|
+
body: createStyleBodySchema,
|
|
272
|
+
response: { 201: styleSchema, 400: errorSchema },
|
|
273
|
+
},
|
|
274
|
+
}, async (request, reply) => execute(reply, 201, () => (repository.createStyle({ ...request.body, creatorType }))));
|
|
275
|
+
}
|
|
276
|
+
async function execute(reply, successStatus, action) {
|
|
277
|
+
try {
|
|
278
|
+
const result = await action();
|
|
279
|
+
return successStatus === 204
|
|
280
|
+
? reply.code(204).send()
|
|
281
|
+
: reply.code(successStatus).send(result);
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
return sendStyleError(reply, error);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function sendStyleError(reply, error) {
|
|
288
|
+
if (error instanceof StyleRevisionConflictError || error instanceof RevisionConflictError) {
|
|
289
|
+
return reply.code(409).send({
|
|
290
|
+
code: error.code,
|
|
291
|
+
message: error.message,
|
|
292
|
+
actualRevision: error.actualRevision,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (error instanceof StyleNotFoundError
|
|
296
|
+
|| error instanceof StyleReferenceNotFoundError
|
|
297
|
+
|| error instanceof SessionNotFoundError) {
|
|
298
|
+
return reply.code(404).send({ code: error.code, message: error.message });
|
|
299
|
+
}
|
|
300
|
+
if (error instanceof InvalidStyleError || error instanceof InvalidStyleReferenceError) {
|
|
301
|
+
return reply.code(400).send({ code: error.code, message: error.message });
|
|
302
|
+
}
|
|
303
|
+
throw error;
|
|
304
|
+
}
|
|
305
|
+
function styleReferenceContentPath(styleId, referenceId) {
|
|
306
|
+
return `/api/v1/styles/${encodeURIComponent(styleId)}/references/${encodeURIComponent(referenceId)}/content`;
|
|
307
|
+
}
|
|
308
|
+
//# sourceMappingURL=style-library.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-library.js","sourceRoot":"","sources":["../../../src/server/routes/style-library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAI3C,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAE1B,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,GAC3B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACL,gBAAgB,GAGjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAC3G,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAkCtD,MAAM,iBAAiB,GAAG;IACxB,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,QAAQ,EAAE,CAAC,SAAS,CAAC;IACrB,UAAU,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE;CACj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CAAC;AACd,CAAC;AAED,SAAS,yBAAyB,CAAC,OAAe,EAAE,WAAmB;IACrE,OAAO,kBAAkB,kBAAkB,CAAC,OAAO,CAAC,eAAe,kBAAkB,CAAC,WAAW,CAAC,UAAU,CAAC;AAC/G,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import uiSketchDraftSchema from "../../../schemas/ui-sketch-draft.schema.json" with {
|
|
2
|
+
type: "json"
|
|
3
|
+
};
|
|
4
|
+
import { registerDraftVersionRoutes } from "./draft-version-routes.js";
|
|
5
|
+
const { $schema: _draftDialect, ...fastifyUiSketchDraftSchema } = uiSketchDraftSchema;
|
|
6
|
+
export function registerUiSketchSessionRoutes(server, repository) {
|
|
7
|
+
server.addSchema(fastifyUiSketchDraftSchema);
|
|
8
|
+
registerDraftVersionRoutes(server, {
|
|
9
|
+
routePrefix: "/api/v1/sessions/:sessionId/ui-sketch",
|
|
10
|
+
draftSchema: { $ref: uiSketchDraftSchema.$id },
|
|
11
|
+
repository,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=ui-sketch-sessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-sketch-sessions.js","sourceRoot":"","sources":["../../../src/server/routes/ui-sketch-sessions.ts"],"names":[],"mappings":"AAEA,OAAO,mBAAmB,MAAM,8CAA8C,CAAC;IAC7E,IAAI,EAAE,MAAM;CACb,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAEvE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,0BAA0B,EAAE,GAC7D,mBAAmB,CAAC;AAEtB,MAAM,UAAU,6BAA6B,CAC3C,MAAuB,EACvB,UAAqC;IAErC,MAAM,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAC7C,0BAA0B,CAAC,MAAM,EAAE;QACjC,WAAW,EAAE,uCAAuC;QACpD,WAAW,EAAE,EAAE,IAAI,EAAE,mBAAmB,CAAC,GAAG,EAAE;QAC9C,UAAU;KACX,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FastifyInstance, FastifyServerOptions } from "fastify";
|
|
2
|
+
export interface StartServerOptions {
|
|
3
|
+
artifactsDirectory?: string;
|
|
4
|
+
databasePath?: string;
|
|
5
|
+
host?: string;
|
|
6
|
+
logger?: FastifyServerOptions["logger"];
|
|
7
|
+
migrationsDirectory?: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
webDirectory?: string;
|
|
10
|
+
}
|
|
11
|
+
export type CreateServerOptions = Omit<StartServerOptions, "host" | "port">;
|
|
12
|
+
export interface RunningHuman2AiServer {
|
|
13
|
+
host: string;
|
|
14
|
+
port: number;
|
|
15
|
+
server: FastifyInstance;
|
|
16
|
+
url: string;
|
|
17
|
+
}
|
|
18
|
+
export type Human2AiWebStartResult = ({
|
|
19
|
+
status: "started";
|
|
20
|
+
} & RunningHuman2AiServer) | {
|
|
21
|
+
status: "already-running";
|
|
22
|
+
url: string;
|
|
23
|
+
};
|
|
24
|
+
export interface StartWebOptions extends StartServerOptions {
|
|
25
|
+
fetch?: typeof fetch;
|
|
26
|
+
}
|
|
27
|
+
export declare function startHuman2AiServer(options?: StartServerOptions): Promise<RunningHuman2AiServer>;
|
|
28
|
+
export declare function startHuman2AiWeb(options?: StartWebOptions): Promise<Human2AiWebStartResult>;
|
|
29
|
+
export declare function isHuman2AiServiceRunning(serviceUrl: string, fetcher?: typeof fetch): Promise<boolean>;
|
|
30
|
+
export declare function createHuman2AiServer(options?: CreateServerOptions): FastifyInstance;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { mkdirSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { CompositionSessionRepository } from "../database/composition-session-repository.js";
|
|
6
|
+
import { ImageAssetRepository } from "../database/image-asset-repository.js";
|
|
7
|
+
import { openDatabase } from "../database/migrate.js";
|
|
8
|
+
import { ProjectSessionRepository } from "../database/project-session-repository.js";
|
|
9
|
+
import { StyleLibraryRepository } from "../database/style-library-repository.js";
|
|
10
|
+
import { UiSketchSessionRepository } from "../database/ui-sketch-session-repository.js";
|
|
11
|
+
import { SpatialSessionRepository } from "../database/spatial-session-repository.js";
|
|
12
|
+
import { HUMAN2AI_SERVICE_CAPABILITIES, buildServer } from "./app.js";
|
|
13
|
+
const DEFAULT_PORT = 4179;
|
|
14
|
+
const DEFAULT_HOST = "127.0.0.1";
|
|
15
|
+
const DEFAULT_WEB_DIRECTORY = fileURLToPath(new URL("../../web/out", import.meta.url));
|
|
16
|
+
const REQUIRED_SERVICE_CAPABILITIES = HUMAN2AI_SERVICE_CAPABILITIES;
|
|
17
|
+
export async function startHuman2AiServer(options = {}) {
|
|
18
|
+
const host = options.host ?? DEFAULT_HOST;
|
|
19
|
+
const port = resolvePort(options.port ?? process.env.HUMAN2AI_PORT ?? DEFAULT_PORT);
|
|
20
|
+
const server = createHuman2AiServer(options);
|
|
21
|
+
try {
|
|
22
|
+
const url = await server.listen({ host, port });
|
|
23
|
+
const actualPort = new URL(url).port;
|
|
24
|
+
return {
|
|
25
|
+
host,
|
|
26
|
+
port: Number(actualPort),
|
|
27
|
+
server,
|
|
28
|
+
url,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
await server.close().catch(() => undefined);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export async function startHuman2AiWeb(options = {}) {
|
|
37
|
+
const { fetch: fetcher = globalThis.fetch, ...serverOptions } = options;
|
|
38
|
+
const host = serverOptions.host ?? DEFAULT_HOST;
|
|
39
|
+
const port = resolvePort(serverOptions.port ?? process.env.HUMAN2AI_PORT ?? DEFAULT_PORT);
|
|
40
|
+
const expectedUrl = `http://${host}:${port}`;
|
|
41
|
+
if (port !== 0) {
|
|
42
|
+
const serviceStatus = await inspectHuman2AiService(expectedUrl, fetcher);
|
|
43
|
+
if (serviceStatus === "compatible") {
|
|
44
|
+
return { status: "already-running", url: expectedUrl };
|
|
45
|
+
}
|
|
46
|
+
if (serviceStatus === "incompatible") {
|
|
47
|
+
throw new Error(`The Human2AI service at ${expectedUrl} does not support the required APIs. Stop it and restart Human2AI.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const running = await startHuman2AiServer({
|
|
51
|
+
...serverOptions,
|
|
52
|
+
host,
|
|
53
|
+
port,
|
|
54
|
+
webDirectory: serverOptions.webDirectory ?? DEFAULT_WEB_DIRECTORY,
|
|
55
|
+
});
|
|
56
|
+
return { status: "started", ...running };
|
|
57
|
+
}
|
|
58
|
+
export async function isHuman2AiServiceRunning(serviceUrl, fetcher = globalThis.fetch) {
|
|
59
|
+
return (await inspectHuman2AiService(serviceUrl, fetcher)) === "compatible";
|
|
60
|
+
}
|
|
61
|
+
async function inspectHuman2AiService(serviceUrl, fetcher) {
|
|
62
|
+
try {
|
|
63
|
+
const response = await fetcher(new URL("/api/v1/health", serviceUrl), {
|
|
64
|
+
signal: AbortSignal.timeout(1_000),
|
|
65
|
+
});
|
|
66
|
+
if (!response.ok)
|
|
67
|
+
return "unavailable";
|
|
68
|
+
const payload = (await response.json());
|
|
69
|
+
if (payload.service !== "human2ai" || payload.status !== "ok") {
|
|
70
|
+
return "unavailable";
|
|
71
|
+
}
|
|
72
|
+
const capabilities = payload.capabilities;
|
|
73
|
+
return Array.isArray(capabilities)
|
|
74
|
+
&& REQUIRED_SERVICE_CAPABILITIES.every((capability) => (capabilities.includes(capability)))
|
|
75
|
+
? "compatible"
|
|
76
|
+
: "incompatible";
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return "unavailable";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function createHuman2AiServer(options = {}) {
|
|
83
|
+
const databasePath = options.databasePath ??
|
|
84
|
+
process.env.HUMAN2AI_DATABASE_PATH ??
|
|
85
|
+
join(homedir(), ".human2ai", "human2ai.sqlite");
|
|
86
|
+
const migrationsDirectory = options.migrationsDirectory ??
|
|
87
|
+
fileURLToPath(new URL("../../migrations", import.meta.url));
|
|
88
|
+
const artifactsDirectory = options.artifactsDirectory
|
|
89
|
+
?? process.env.HUMAN2AI_ARTIFACTS_PATH
|
|
90
|
+
?? join(dirname(databasePath === ":memory:" ? join(homedir(), ".human2ai", "human2ai.sqlite") : databasePath), "artifacts");
|
|
91
|
+
if (databasePath !== ":memory:") {
|
|
92
|
+
mkdirSync(dirname(databasePath), { recursive: true, mode: 0o700 });
|
|
93
|
+
}
|
|
94
|
+
const database = openDatabase(databasePath, migrationsDirectory);
|
|
95
|
+
let databaseClosed = false;
|
|
96
|
+
const closeDatabase = () => {
|
|
97
|
+
if (databaseClosed)
|
|
98
|
+
return;
|
|
99
|
+
databaseClosed = true;
|
|
100
|
+
database.close();
|
|
101
|
+
};
|
|
102
|
+
const server = buildServer({ logger: options.logger ?? false }, {
|
|
103
|
+
compositionSessions: new CompositionSessionRepository(database),
|
|
104
|
+
imageAssets: new ImageAssetRepository(database, artifactsDirectory),
|
|
105
|
+
projectSessions: new ProjectSessionRepository(database),
|
|
106
|
+
styleLibrary: new StyleLibraryRepository(database, artifactsDirectory),
|
|
107
|
+
uiSketchSessions: new UiSketchSessionRepository(database),
|
|
108
|
+
spatialSessions: new SpatialSessionRepository(database),
|
|
109
|
+
webDirectory: options.webDirectory,
|
|
110
|
+
});
|
|
111
|
+
server.addHook("onClose", async () => {
|
|
112
|
+
closeDatabase();
|
|
113
|
+
});
|
|
114
|
+
return server;
|
|
115
|
+
}
|
|
116
|
+
function resolvePort(input) {
|
|
117
|
+
const port = typeof input === "number" ? input : Number(input);
|
|
118
|
+
if (!Number.isInteger(port) || port < 0 || port > 65_535) {
|
|
119
|
+
throw new Error(`Invalid HUMAN2AI_PORT: ${String(input)}`);
|
|
120
|
+
}
|
|
121
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,EAAE,EACnC;QACE,mBAAmB,EAAE,IAAI,4BAA4B,CAAC,QAAQ,CAAC;QAC/D,WAAW,EAAE,IAAI,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,CAAC;QACnE,eAAe,EAAE,IAAI,wBAAwB,CAAC,QAAQ,CAAC;QACvD,YAAY,EAAE,IAAI,sBAAsB,CAAC,QAAQ,EAAE,kBAAkB,CAAC;QACtE,gBAAgB,EAAE,IAAI,yBAAyB,CAAC,QAAQ,CAAC;QACzD,eAAe,EAAE,IAAI,wBAAwB,CAAC,QAAQ,CAAC;QACvD,YAAY,EAAE,OAAO,CAAC,YAAY;KACnC,CACF,CAAC;IAEF,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;QACnC,aAAa,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,KAAsB;IACzC,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,MAAM,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createOutputCamera } from "../domain/spatial/scene.ts";
|
|
2
|
+
import type { SpatialCamera, SpatialDraft, SpatialRenderPass } from "../domain/spatial/types.ts";
|
|
3
|
+
import { type SpatialBoxView, type SpatialCameraBox } from "../domain/spatial/types.ts";
|
|
4
|
+
export declare function renderSpatialPng(draft: SpatialDraft, source: SpatialCamera, pass?: SpatialRenderPass, outputCamera?: ReturnType<typeof createOutputCamera>): Promise<Buffer>;
|
|
5
|
+
export declare function renderSpatialCameraBoxPng(draft: SpatialDraft, box: SpatialCameraBox, view?: SpatialBoxView, pass?: SpatialRenderPass): Promise<Buffer>;
|