wildcrane-artifact-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +32 -4
  2. package/dist/builtin/compare.json +15 -0
  3. package/dist/builtin/html.json +6 -0
  4. package/dist/builtin/image.json +1 -0
  5. package/dist/builtin/index.d.ts +2 -0
  6. package/dist/builtin/index.js +13 -0
  7. package/dist/builtin/markdown.json +9 -0
  8. package/dist/builtin/spritesheet.json +23 -0
  9. package/dist/builtin/storyboard.json +33 -0
  10. package/dist/builtin/studio.json +488 -0
  11. package/dist/builtin/tiled.json +11 -0
  12. package/dist/builtin/video.json +1 -0
  13. package/dist/index.d.ts +6 -0
  14. package/dist/index.js +1 -0
  15. package/dist/internal/asset-formats.d.ts +16 -0
  16. package/dist/internal/asset-formats.js +61 -0
  17. package/dist/internal/asset-store.d.ts +109 -0
  18. package/dist/internal/asset-store.js +5 -0
  19. package/dist/internal/collect.d.ts +43 -0
  20. package/dist/internal/collect.js +154 -0
  21. package/dist/internal/document.d.ts +7 -0
  22. package/dist/internal/document.js +9 -0
  23. package/dist/internal/file-references.d.ts +6 -0
  24. package/dist/internal/file-references.js +29 -0
  25. package/dist/internal/format/captions.d.ts +6 -0
  26. package/dist/internal/format/captions.js +31 -0
  27. package/dist/internal/format/compare.d.ts +34 -0
  28. package/dist/internal/format/compare.js +59 -0
  29. package/dist/internal/format/spritesheet.d.ts +25 -0
  30. package/dist/internal/format/spritesheet.js +50 -0
  31. package/dist/internal/format/storyboard.d.ts +8 -0
  32. package/dist/internal/format/storyboard.js +21 -0
  33. package/dist/internal/format/studio.d.ts +68 -0
  34. package/dist/internal/format/studio.js +58 -0
  35. package/dist/internal/hyperframe-document.d.ts +14 -0
  36. package/dist/internal/hyperframe-document.js +80 -0
  37. package/dist/internal/manifest.d.ts +48 -0
  38. package/dist/internal/manifest.js +102 -0
  39. package/dist/internal/markdown-code.d.ts +3 -0
  40. package/dist/internal/markdown-code.js +51 -0
  41. package/dist/internal/markdown-destinations.d.ts +7 -0
  42. package/dist/internal/markdown-destinations.js +52 -0
  43. package/dist/internal/mockup-tag.d.ts +194 -0
  44. package/dist/internal/mockup-tag.js +8 -0
  45. package/dist/internal/previews.d.ts +163 -0
  46. package/dist/internal/previews.js +798 -0
  47. package/dist/internal/references.d.ts +65 -0
  48. package/dist/internal/references.js +209 -0
  49. package/dist/internal/schema.d.ts +2 -0
  50. package/dist/internal/schema.js +83 -0
  51. package/dist/internal/storyboard.d.ts +84 -0
  52. package/dist/internal/storyboard.js +71 -0
  53. package/dist/internal/tags.d.ts +37 -0
  54. package/dist/internal/tags.js +66 -0
  55. package/dist/internal/task-assets.d.ts +122 -0
  56. package/dist/internal/task-assets.js +87 -0
  57. package/dist/internal/web-references.d.ts +21 -0
  58. package/dist/internal/web-references.js +162 -0
  59. package/package.json +2 -2
  60. package/src/builtin/compare.json +15 -0
  61. package/src/builtin/html.json +6 -0
  62. package/src/builtin/image.json +1 -0
  63. package/src/builtin/index.ts +15 -0
  64. package/src/builtin/markdown.json +9 -0
  65. package/src/builtin/spritesheet.json +23 -0
  66. package/src/builtin/storyboard.json +33 -0
  67. package/src/builtin/studio.json +488 -0
  68. package/src/builtin/tiled.json +11 -0
  69. package/src/builtin/video.json +1 -0
  70. package/src/index.ts +4 -0
  71. package/src/internal/asset-formats.ts +66 -0
  72. package/src/internal/asset-store.ts +41 -0
  73. package/src/internal/collect.ts +158 -0
  74. package/src/internal/document.ts +12 -0
  75. package/src/internal/file-references.ts +34 -0
  76. package/src/internal/format/captions.ts +34 -0
  77. package/src/internal/format/compare.ts +63 -0
  78. package/src/internal/format/spritesheet.ts +53 -0
  79. package/src/internal/format/storyboard.ts +22 -0
  80. package/src/internal/format/studio.ts +69 -0
  81. package/src/internal/hyperframe-document.ts +75 -0
  82. package/src/internal/manifest.ts +124 -0
  83. package/src/internal/markdown-code.ts +48 -0
  84. package/src/internal/markdown-destinations.ts +45 -0
  85. package/src/internal/mockup-tag.ts +128 -0
  86. package/src/internal/previews.ts +766 -0
  87. package/src/internal/references.ts +195 -0
  88. package/src/internal/schema.ts +69 -0
  89. package/src/internal/storyboard.ts +127 -0
  90. package/src/internal/tags.ts +94 -0
  91. package/src/internal/task-assets.ts +114 -0
  92. package/src/internal/web-references.ts +160 -0
package/README.md CHANGED
@@ -5,7 +5,7 @@ publish it to your WildCrane account. When an agent submits an artifact of that
5
5
  page draws it with your component.
6
6
 
7
7
  ```
8
- review.wildcrane.ai ──postMessage──▶ <hash>.wildcraneusercontent.com (your bundle)
8
+ app.wildcrane.ai ──postMessage──▶ <hash>.wildcraneusercontent.com (your bundle)
9
9
  holds the sign-in, sandboxed iframe, no network,
10
10
  validates and saves sees only the artifact it is handed
11
11
  ```
@@ -13,7 +13,7 @@ review.wildcrane.ai ──postMessage──▶ <hash>.wildcraneusercontent.com (
13
13
  - **Yours alone**: a component draws artifacts only on tasks your account started.
14
14
  - **No network**: `connect-src 'none'`, so not even `fetch` of your own files; bundle every script, style, font and image, and import data instead of fetching it.
15
15
  - **Saving**: only the account's owners get `readOnly: false`. A save becomes the artifact's
16
- next version and puts the checkpoint back up for review. Approving stays on the review page.
16
+ next version. Approving stays on the review page.
17
17
  - **Pinned**: an artifact version keeps the component version that was newest when it was
18
18
  written; publishing later changes nothing already submitted.
19
19
 
@@ -37,8 +37,26 @@ A folder of static files with `index.html` at its top, at most 10 MB, any framew
37
37
  - **`version`**: semver, published once.
38
38
  - **`types`**: the artifact types it draws, each `@<your GitHub handle>/<name>`, lowercase.
39
39
  - **`schema`**: optional JSON Schema every save must match. The review page checks `type`,
40
- `enum`, `const`, `properties`, `required`, `additionalProperties`, `items`, `minItems`,
40
+ `enum`, `const`, `anyOf`, `properties`, `required`, `additionalProperties`, `items`, `minItems`,
41
41
  `maxItems`, `minLength`, `maxLength`, `pattern`, `minimum` and `maximum`. A save is at most 256 KB.
42
+ - **`references`**: optional; where the content names other files of the task, so the page
43
+ hands them to you. `{ "json": "/path" }` is a field (`*` for every item), `{ "text": "regex" }`
44
+ the first group of each case-insensitive match in text content, split by `list` when set.
45
+
46
+ A subtitle track over its video, the video's artifact id in `video`:
47
+
48
+ ```json
49
+ {
50
+ "types": ["@your-handle/subtitles"],
51
+ "schema": { "type": "object", "required": ["video", "cues"] },
52
+ "references": [{ "json": "/video" }]
53
+ }
54
+ ```
55
+
56
+ ```js
57
+ const { data, contentType } = bridge.files[bridge.artifact.content.video];
58
+ video.src = URL.createObjectURL(new Blob([data], { type: contentType }));
59
+ ```
42
60
 
43
61
  ```sh
44
62
  npm install wildcrane-artifact-sdk
@@ -49,6 +67,7 @@ import { connect } from "wildcrane-artifact-sdk";
49
67
 
50
68
  const bridge = await connect();
51
69
  // bridge.artifact: { type, name, version, content } or { …, file: { data: ArrayBuffer, contentType } }
70
+ // bridge.files: { [reference]: { data, contentType } }, the files `references` point at
52
71
  // bridge.readOnly, bridge.locale ("zh" | "en"), bridge.theme ("light" | "dark")
53
72
  await bridge.save(next); // rejects with the reason, in bridge.locale
54
73
  bridge.onChange((ctx) => redraw(ctx));
@@ -65,7 +84,8 @@ WILDCRANE_API_KEY=wck_… npx wildcrane-artifact-sdk publish dist
65
84
 
66
85
  Every file in the folder but dot files goes into the bundle. With Vite, put the manifest in
67
86
  `public/` and publish `dist`. Then submit an artifact of your type:
68
- `POST /v1/tasks/{id}/artifacts { "type": "@your-handle/subtitles", "checkpoint": "…" }`.
87
+ `POST /v1/tasks/{id}/artifacts { "type": "@your-handle/subtitles" }`; it is reviewed with the
88
+ card's current phase.
69
89
  `GET /v1/components` lists what you published; `DELETE
70
90
  /v1/components/{name}/versions/{version}` removes a version, and artifacts pinned to it show that
71
91
  their preview cannot be drawn.
@@ -78,3 +98,11 @@ manifest, then `npm run example`.
78
98
  ## Develop
79
99
 
80
100
  `npm install`, then `npm run lint`.
101
+
102
+ ## 仓库内接入
103
+
104
+ - **组件清单**:内置组件的清单在 `src/builtin/*.json`,与第三方同一写法;SDK 只按清单的 `references` 与 `schema` 收集依赖、校验内容,不为内置类型单写规则。
105
+ - **依赖收集**:`src/internal/collect.ts` 从卡片正文出发走完可达图,按依赖顺序输出,文件里的问题记在该文件上;Runner 上传与 `akb raw validate` 共用它,文件读取与路径边界由调用方提供。
106
+ - **网页依赖**:页面引用的图片、字体各自上传一次,上传时引用改写为 artifact ID;审阅页把文件交给沙箱页面,由页面自建地址。
107
+ - **内置预览**:`src/internal/previews.ts` 通过 SDK `Context` 读取内容,按卡片清单固定版本并统一权限与错误;网页只提供鉴权服务和显示外框。
108
+ - **打包边界**:Runner 和网页直接打包内部源码;浏览器入口不依赖 Node,内部模块不属于公开 API,第三方继续使用 `connect()`。
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "compare",
3
+ "title": { "en": "Compare", "zh": "对比" },
4
+ "types": ["compare"],
5
+ "schema": {
6
+ "type": "object",
7
+ "required": ["a", "b"],
8
+ "properties": { "a": { "type": "string" }, "b": { "type": "string" } }
9
+ },
10
+ "references": [
11
+ { "json": "/a", "types": ["storyboard", "compare", "spritesheet", "studio"] },
12
+ { "json": "/b", "types": ["storyboard", "compare", "spritesheet", "studio"] },
13
+ { "json": "/shots", "types": ["storyboard", "compare", "spritesheet", "studio"] }
14
+ ]
15
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "html",
3
+ "title": { "en": "Page", "zh": "页面" },
4
+ "types": ["html"],
5
+ "references": [{ "web": "html" }]
6
+ }
@@ -0,0 +1 @@
1
+ { "name": "image", "title": { "en": "Image", "zh": "图片" }, "types": ["image"] }
@@ -0,0 +1,2 @@
1
+ declare const _default: unknown[];
2
+ export default _default;
@@ -0,0 +1,13 @@
1
+ // 内置组件的清单,与第三方的 wildcrane.component.json 同一写法。
2
+ import compare from './compare.json';
3
+ import html from './html.json';
4
+ import image from './image.json';
5
+ import markdown from './markdown.json';
6
+ import spritesheet from './spritesheet.json';
7
+ import storyboard from './storyboard.json';
8
+ import tiled from './tiled.json';
9
+ import video from './video.json';
10
+ import studio from './studio.json';
11
+ // akb 的打包把 JSON 当文本读入。
12
+ const read = (m) => (typeof m === 'string' ? JSON.parse(m) : m);
13
+ export default [html, image, video, markdown, storyboard, compare, studio, tiled, spritesheet].map(read);
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "markdown",
3
+ "title": { "en": "Document", "zh": "文档" },
4
+ "types": ["markdown"],
5
+ "references": [
6
+ { "markdown": "image" },
7
+ { "text": "<img\\b[^<>]*?\\ssrc\\s*=\\s*[\"']([^\"']+)[\"']" }
8
+ ]
9
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "spritesheet",
3
+ "title": { "en": "Sprite animation", "zh": "精灵动画" },
4
+ "types": ["spritesheet"],
5
+ "schema": {
6
+ "type": "object",
7
+ "required": ["frames", "meta"],
8
+ "properties": {
9
+ "frames": {
10
+ "anyOf": [
11
+ { "type": "array", "minItems": 1, "items": { "type": "object", "required": ["frame"] } },
12
+ { "type": "object", "additionalProperties": { "type": "object", "required": ["frame"] } }
13
+ ]
14
+ },
15
+ "meta": {
16
+ "type": "object",
17
+ "required": ["app", "image"],
18
+ "properties": { "app": { "type": "string", "pattern": "codeandweb\\.com/texturepacker" }, "image": { "type": "string" } }
19
+ }
20
+ }
21
+ },
22
+ "references": [{ "json": "/meta/image" }]
23
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "storyboard",
3
+ "title": { "en": "Storyboard", "zh": "分镜" },
4
+ "types": ["storyboard"],
5
+ "schema": {
6
+ "type": "object",
7
+ "anyOf": [{ "required": ["shots"] }, { "required": ["slides"] }],
8
+ "properties": {
9
+ "shots": {
10
+ "type": "array",
11
+ "items": {
12
+ "type": "object",
13
+ "properties": { "frames": { "type": "array", "items": { "type": "object", "properties": { "src": { "type": "string" } } } } }
14
+ }
15
+ },
16
+ "slides": {
17
+ "type": "array",
18
+ "items": {
19
+ "type": "object",
20
+ "properties": {
21
+ "preview": { "type": "object", "properties": { "src": { "type": "string" } } },
22
+ "assets": { "type": "array", "items": { "type": "string" } }
23
+ }
24
+ }
25
+ }
26
+ }
27
+ },
28
+ "references": [
29
+ { "json": "/shots/*/frames/*/src", "types": ["storyboard", "compare", "spritesheet", "studio"] },
30
+ { "json": "/slides/*/preview/src", "types": ["storyboard", "compare", "spritesheet", "studio"] },
31
+ { "json": "/slides/*/assets/*" }
32
+ ]
33
+ }