@fabrika/canvas-kernel 0.1.45 → 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.
Files changed (66) hide show
  1. package/README.md +33 -67
  2. package/index.ts +19 -83
  3. package/package.json +68 -72
  4. package/src/client/AnnotationProvider.tsx +227 -268
  5. package/src/client/AnnotationSidebar.tsx +392 -338
  6. package/src/client/FileIcon.tsx +106 -65
  7. package/src/client/PlanRenderer.tsx +607 -551
  8. package/src/client/RenderErrorContext.ts +7 -7
  9. package/src/client/ResponsePreview.tsx +192 -173
  10. package/src/client/annotationDom.ts +43 -97
  11. package/src/client/annotationDraft.ts +98 -92
  12. package/src/client/appContext.tsx +40 -40
  13. package/src/client/components/Callout.tsx +20 -20
  14. package/src/client/components/Checklist.tsx +28 -28
  15. package/src/client/components/Choice.tsx +178 -159
  16. package/src/client/components/CodeBlock.tsx +26 -26
  17. package/src/client/components/Diff.tsx +17 -17
  18. package/src/client/components/FilePreview.tsx +99 -74
  19. package/src/client/components/Image.tsx +41 -39
  20. package/src/client/components/Markdown.tsx +33 -32
  21. package/src/client/components/Mermaid.tsx +592 -542
  22. package/src/client/components/Note.tsx +8 -8
  23. package/src/client/components/Priority.tsx +11 -11
  24. package/src/client/components/ResponseNote.tsx +17 -15
  25. package/src/client/components/Section.tsx +28 -26
  26. package/src/client/components/Table.tsx +34 -29
  27. package/src/client/components/Task.tsx +58 -60
  28. package/src/client/components/UserInput.tsx +169 -152
  29. package/src/client/components/index.ts +16 -16
  30. package/src/client/components/renderMarkdownChildren.tsx +86 -68
  31. package/src/client/diffLines.ts +51 -39
  32. package/src/client/generateMarkdown.ts +197 -191
  33. package/src/client/hostContext.tsx +34 -34
  34. package/src/client/index.ts +43 -125
  35. package/src/client/preact-all.ts +4 -4
  36. package/src/client/runtime.ts +58 -111
  37. package/src/client/styles.css +1 -74
  38. package/src/engine/compiler.ts +316 -313
  39. package/src/engine/paths.ts +44 -44
  40. package/src/engine/session.ts +623 -618
  41. package/src/engine/watcher.ts +63 -60
  42. package/src/engine/websocket.ts +123 -121
  43. package/annotate.ts +0 -94
  44. package/daemon.ts +0 -46
  45. package/src/client/AnnotationDraftFooter.tsx +0 -76
  46. package/src/client/AnnotationEditor.tsx +0 -320
  47. package/src/client/AnnotationList.tsx +0 -190
  48. package/src/client/Popover.tsx +0 -361
  49. package/src/client/SessionContext.tsx +0 -3
  50. package/src/client/annotationContext.ts +0 -130
  51. package/src/client/annotationMarkdown.ts +0 -102
  52. package/src/client/annotationTarget.ts +0 -73
  53. package/src/client/blockTarget.ts +0 -127
  54. package/src/client/highlightRange.ts +0 -262
  55. package/src/client/popoverPosition.ts +0 -46
  56. package/src/client/regionTarget.ts +0 -180
  57. package/src/client/testing/dom.ts +0 -74
  58. package/src/client/textTarget.ts +0 -31
  59. package/src/client/useRegionAnnotation.tsx +0 -188
  60. package/src/client/useTextAnnotation.tsx +0 -194
  61. package/src/client/utils.ts +0 -33
  62. package/src/engine/channel.ts +0 -278
  63. package/src/engine/http-utils.ts +0 -14
  64. package/src/engine/lifecycle.ts +0 -302
  65. package/src/engine/router.ts +0 -16
  66. package/src/engine/waiter.ts +0 -188
package/README.md CHANGED
@@ -1,73 +1,39 @@
1
1
  # @fabrika/canvas-kernel
2
2
 
3
- The reusable half of [Agent Canvas](https://github.com/contember/agent-canvas): a
4
- host-agnostic SDK for building annotatable, agent-driven canvases.
5
-
3
+ The canvas SDK from [Agent Canvas](https://github.com/contember/agent-canvas).
6
4
  Ships as **TypeScript sources**, not a build artifact. It is written for Bun and
7
- consumed by bundlers, so a host typechecks the kernel under its own flags and can
8
- read every line it depends on.
9
-
10
- ## Rings
11
-
12
- A host takes only the rings it needs. Each has its own entry point, and the
13
- entries are ordered by how much they assume:
14
-
15
- | Entry | What it holds | Assumes |
16
- |---|---|---|
17
- | `@fabrika/canvas-kernel/daemon` | WebSocket channel, CLI waiter, process lifecycle, router, paths | Nothing about canvases |
18
- | `@fabrika/canvas-kernel/annotate` | Annotation state and drafts, list + draft footer, editor and popovers, locator strategies (text, block, region), `renderAnnotation` | A DOM |
19
- | `@fabrika/canvas-kernel/server` | JSX compiler, session/revision store, watcher, the canvas WS vocabulary | A canvas |
20
- | `@fabrika/canvas-kernel/client` | The annotation ring plus `PlanRenderer`, `AnnotationSidebar`, `generateMarkdown`, revision contexts, component library | A canvas |
21
-
22
- Taking `/daemon` alone costs nothing at runtime — no canvas code is reachable
23
- from it.
24
-
25
- ## Example: a daemon that is not a canvas
26
-
27
- ```ts
28
- import { createNotificationChannel, browserFrame } from '@fabrika/canvas-kernel/daemon'
29
-
30
- const channel = createNotificationChannel({
31
- roleOf: (ws) => ws.data.role, // 'browser' | 'wait'
32
- topicOf: (ws) => ws.data.sessionId,
33
- waiterPolicy: 'keep-open',
34
- frames: [
35
- browserFrame(isSubmit, async (frame, topic) => {
36
- topic.relayToWaiters(frame)
37
- }),
38
- ],
39
- })
40
-
41
- Bun.serve({ fetch: handler, websocket: channel.handlers })
42
- ```
43
-
44
- The channel knows about two socket roles keyed by an opaque topic string. The
45
- frame vocabulary is the host's — the kernel never learns what a "submission" is.
46
-
47
- ## Annotation locators
48
-
49
- An annotation points at something via an `AnnotationTarget<L>`, a strategy that
50
- owns one locator shape end to end:
51
-
52
- ```ts
53
- export interface AnnotationTarget<L extends object> {
54
- readonly kind: string
55
- parse(snippet: string): L | null
56
- format(locator: L): string
57
- find(locator: L, root: ParentNode): HTMLElement | null
58
- restore?(locator: L, root: HTMLElement, ann: TargetAnnotation): void
59
- describe?(locator: L): string
60
- }
61
- ```
62
-
63
- Three ship: text ranges, document blocks, and rectangular regions of an image.
64
- Creation and lookup read the same selector, so an annotation minted where the
65
- lookup does not scan is not expressible.
66
-
67
- ## Versioning
68
-
69
- Released in lockstep with the `agent-canvas` package — same repository, same
70
- commit, same version number. Pin exactly.
5
+ consumed by bundlers, so a host typechecks it under its own flags.
6
+
7
+ Canvas-specific functionality over `@fabrika/daemon-kit` and
8
+ `@fabrika/annotations`:
9
+
10
+ | Entry | Responsibility |
11
+ | --------------------------- | -------------------------------------------------------------------------------------- |
12
+ | `/server` (also `.`) | JSX compilation, sessions/revisions, watcher, canvas WS protocol and paths |
13
+ | `/client` | Renderer, canvas draft persistence, responses, revision contexts, sidebar and feedback |
14
+ | `/components` | Interactive canvas component library |
15
+ | `/runtime` | Canvas contexts shared by compiled documents and the host |
16
+ | `/styles.css`, `/theme.css` | Canvas styling and theme |
17
+
18
+ ## Migration from 0.1.x
19
+
20
+ - Replace `/daemon` imports with `@fabrika/daemon-kit`.
21
+ - Import daemon helpers previously reexported from `/server` directly from
22
+ `@fabrika/daemon-kit`. `createCanvasPaths` remains canvas-specific.
23
+ - Replace `/annotate` imports with `@fabrika/annotations`.
24
+ - Import annotation UI, locator strategies, marks and utilities previously
25
+ reexported from `/client` directly from `@fabrika/annotations`.
26
+ - The canvas `/client` `AnnotationProvider` and `PersistedState` still own
27
+ revisions, responses and feedback entries. The standalone annotations provider
28
+ instead takes `scope`, `loadState(scope)` and `saveState(scope, state)` and uses
29
+ `AnnotationState` with only annotations and a general note.
30
+ - Standalone annotation hosts use `AnnotationHostContext` and `AnnotationHost`,
31
+ without `loadCanvasModule`. Canvas hosts keep `CanvasHostContext`.
32
+ - Multi-bundle hosts must build and externalize `@fabrika/annotations/runtime`
33
+ in addition to `#canvas/runtime`, with one import-map entry for each.
34
+
35
+ The removed entries are not compatibility reexports. All packages release in
36
+ lockstep with exact internal dependency pins.
71
37
 
72
38
  ## License
73
39
 
package/index.ts CHANGED
@@ -1,84 +1,20 @@
1
- // @fabrika/canvas-kernel — server entry.
2
- //
3
- // The host-agnostic canvas engine: compile pipeline, session/revision store,
4
- // JSX watcher, WebSocket notification channel, daemon lifecycle, CLI waiter,
5
- // router, and the on-disk layout.
6
- // Imports nothing from preact/DOM, so a Bun.serve daemon can pull it in without
7
- // dragging the browser bundle along.
8
- //
9
- // The browser-facing surface (components + annotation runtime) is exposed
10
- // separately through the package `imports`/`exports` maps as `#canvas/components`
11
- // and `#canvas/runtime`.
12
-
13
- // --- Compile pipeline (JSX -> Bun.build) -----------------------------------
14
- export { compileJsx, compilePlan, KERNEL_COMPONENTS } from "./src/engine/compiler";
1
+ export { compileJsx, compilePlan, KERNEL_COMPONENTS } from './src/engine/compiler'
2
+ export type { CanvasComponents, CanvasComponentSpec, CompileOptions, CompileResult } from './src/engine/compiler'
3
+ export { createCanvasPaths } from './src/engine/paths'
4
+ export type { CanvasPaths, CanvasPathsConfig } from './src/engine/paths'
5
+ export { SessionManager } from './src/engine/session'
15
6
  export type {
16
- CompileResult,
17
- CompileOptions,
18
- CanvasComponents,
19
- CanvasComponentSpec,
20
- } from "./src/engine/compiler";
21
-
22
- // --- Session / revision / feedback store -----------------------------------
23
- export { SessionManager } from "./src/engine/session";
24
- export type {
25
- SessionData,
26
- RevisionInfo,
27
- CanvasFileInfo,
28
- CanvasScope,
29
- DiffStats,
30
- SecretResolution,
31
- RemoteFeedbackEntry,
32
- RemoteAnnotation,
33
- ShareEntry,
34
- } from "./src/engine/session";
35
-
36
- // --- WebSocket notification channel (host-agnostic) ------------------------
37
- export { createNotificationChannel, browserFrame } from "./src/engine/channel";
38
- export type {
39
- ChannelRole,
40
- ChannelSocket,
41
- TopicChannel,
42
- RelayOptions,
43
- BrowserFrameHandler,
44
- NotificationChannel,
45
- NotificationChannelOptions,
46
- } from "./src/engine/channel";
47
-
48
- // --- WebSocket feedback protocol (canvas vocabulary) -----------------------
49
- export { createWebSocketManager } from "./src/engine/websocket";
50
- export type { WSData, CanvasSocket, WebSocketManagerOptions } from "./src/engine/websocket";
51
-
52
- // --- CLI waiter ------------------------------------------------------------
53
- export { waitForEvent, WaitError } from "./src/engine/waiter";
54
- export type { WaiterSocket, WaitVerdict, WaitOptions, WaitMessages, WaitFailure } from "./src/engine/waiter";
55
-
56
- // --- Daemon process lifecycle ----------------------------------------------
57
- export { createDaemonLifecycle, DaemonStartError } from "./src/engine/lifecycle";
58
- export type {
59
- DaemonLifecycle,
60
- DaemonLifecycleConfig,
61
- DaemonHealth,
62
- DaemonHealthUp,
63
- DaemonHealthDown,
64
- DaemonPid,
65
- DaemonStopResult,
66
- DaemonStopReason,
67
- DaemonEvent,
68
- DaemonTimeouts,
69
- } from "./src/engine/lifecycle";
70
-
71
- // --- JSX watcher -----------------------------------------------------------
72
- export { watchSession, unwatchSession, unwatchAll } from "./src/engine/watcher";
73
- export type { WatchOptions } from "./src/engine/watcher";
74
-
75
- // --- Router ----------------------------------------------------------------
76
- export { dispatch } from "./src/engine/router";
77
- export type { Route, RouteHandler } from "./src/engine/router";
78
-
79
- // --- HTTP helpers ----------------------------------------------------------
80
- export { jsonResponse, corsHeaders } from "./src/engine/http-utils";
81
-
82
- // --- On-disk layout --------------------------------------------------------
83
- export { createCanvasPaths } from "./src/engine/paths";
84
- export type { CanvasPaths, CanvasPathsConfig } from "./src/engine/paths";
7
+ CanvasFileInfo,
8
+ CanvasScope,
9
+ DiffStats,
10
+ RemoteAnnotation,
11
+ RemoteFeedbackEntry,
12
+ RevisionInfo,
13
+ SecretResolution,
14
+ SessionData,
15
+ ShareEntry,
16
+ } from './src/engine/session'
17
+ export { unwatchAll, unwatchSession, watchSession } from './src/engine/watcher'
18
+ export type { WatchOptions } from './src/engine/watcher'
19
+ export { createWebSocketManager } from './src/engine/websocket'
20
+ export type { CanvasSocket, WebSocketManagerOptions, WSData } from './src/engine/websocket'
package/package.json CHANGED
@@ -1,74 +1,70 @@
1
1
  {
2
- "name": "@fabrika/canvas-kernel",
3
- "version": "0.1.45",
4
- "type": "module",
5
- "description": "Host-agnostic canvas SDK: a daemon runtime (WebSocket channel, CLI waiter, process lifecycle), a locator-agnostic annotation surface, and the canvas engine (JSX→Bun.build compiler, session/revision store, watcher).",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/contember/agent-canvas",
10
- "directory": "packages/canvas-kernel"
11
- },
12
- "publishConfig": {
13
- "access": "public"
14
- },
15
- "files": [
16
- "index.ts",
17
- "daemon.ts",
18
- "annotate.ts",
19
- "src",
20
- "!src/**/*.test.ts"
21
- ],
22
- "main": "./index.ts",
23
- "types": "./index.ts",
24
- "exports": {
25
- ".": {
26
- "types": "./index.ts",
27
- "default": "./index.ts"
28
- },
29
- "./server": {
30
- "types": "./index.ts",
31
- "default": "./index.ts"
32
- },
33
- "./daemon": {
34
- "types": "./daemon.ts",
35
- "default": "./daemon.ts"
36
- },
37
- "./client": {
38
- "types": "./src/client/index.ts",
39
- "default": "./src/client/index.ts"
40
- },
41
- "./annotate": {
42
- "types": "./annotate.ts",
43
- "default": "./annotate.ts"
44
- },
45
- "./components": {
46
- "types": "./src/client/components/index.ts",
47
- "default": "./src/client/components/index.ts"
48
- },
49
- "./runtime": {
50
- "types": "./src/client/runtime.ts",
51
- "default": "./src/client/runtime.ts"
52
- },
53
- "./client/*": "./src/client/*",
54
- "./engine/*": "./src/engine/*",
55
- "./styles.css": "./src/client/styles.css",
56
- "./theme.css": "./src/client/theme.css"
57
- },
58
- "imports": {
59
- "#canvas/components": "./src/client/components/index.ts",
60
- "#canvas/runtime": "./src/client/runtime.ts"
61
- },
62
- "dependencies": {
63
- "marked": "^17.0.4",
64
- "mermaid-parser-bundle": "^0.1.2",
65
- "preact": "^10.25.0",
66
- "preact-render-to-string": "^6.6.6"
67
- },
68
- "devDependencies": {
69
- "@happy-dom/global-registrator": "^20.11.2",
70
- "@types/react": "^18.3.12",
71
- "@types/react-dom": "^18.3.1",
72
- "happy-dom": "^20.11.2"
73
- }
2
+ "name": "@fabrika/canvas-kernel",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "Canvas JSX compiler, session/revision store, renderer and interactive component library.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/contember/fabrika-platform.git",
10
+ "directory": "packages/canvas-kernel"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "files": [
16
+ "index.ts",
17
+ "src",
18
+ "!src/**/*.test.ts",
19
+ "!src/**/*.test.tsx"
20
+ ],
21
+ "exports": {
22
+ ".": {
23
+ "bun": "./index.ts",
24
+ "types": "./index.ts",
25
+ "default": "./index.ts"
26
+ },
27
+ "./server": {
28
+ "bun": "./index.ts",
29
+ "types": "./index.ts",
30
+ "default": "./index.ts"
31
+ },
32
+ "./client": {
33
+ "bun": "./src/client/index.ts",
34
+ "types": "./src/client/index.ts",
35
+ "default": "./src/client/index.ts"
36
+ },
37
+ "./components": {
38
+ "bun": "./src/client/components/index.ts",
39
+ "types": "./src/client/components/index.ts",
40
+ "default": "./src/client/components/index.ts"
41
+ },
42
+ "./runtime": {
43
+ "bun": "./src/client/runtime.ts",
44
+ "types": "./src/client/runtime.ts",
45
+ "default": "./src/client/runtime.ts"
46
+ },
47
+ "./styles.css": "./src/client/styles.css",
48
+ "./theme.css": "./src/client/theme.css"
49
+ },
50
+ "imports": {
51
+ "#canvas/components": "./src/client/components/index.ts",
52
+ "#canvas/runtime": "./src/client/runtime.ts"
53
+ },
54
+ "scripts": {
55
+ "typecheck": "tsc --noEmit",
56
+ "test": "bun test"
57
+ },
58
+ "dependencies": {
59
+ "@fabrika/annotations": "^0.2.0",
60
+ "@fabrika/daemon-kit": "^0.2.0",
61
+ "marked": "^17.0.4",
62
+ "mermaid-parser-bundle": "^0.1.2",
63
+ "preact": "^10.25.0",
64
+ "preact-render-to-string": "^6.6.6"
65
+ },
66
+ "peerDependencies": {
67
+ "react": ">=18",
68
+ "react-dom": ">=18"
69
+ }
74
70
  }