Skip to content

Commit 3b038cd

Browse files
committed
refactor(canvas): move freeform authoring contract to @posthog/shared
Relocate the freeform canvas authoring contract — the system-prompt builder (freeformSystemPromptFor), the import whitelist, the starter scaffold, and the freeform template id — from @posthog/core into @posthog/shared, so @posthog/agent can consume it (for the canvas_checkout tool) without a core↔agent package cycle. Pure move: @posthog/core/canvas/{canvasTemplates,freeformSchemas,freeformWhitelist, freeformStarter} now re-export from @posthog/shared, so existing consumers are unchanged. Generated-By: PostHog Code Task-Id: 2ed89933-091b-446c-af91-5cc72d939b3b
1 parent a0f9a42 commit 3b038cd

13 files changed

Lines changed: 192 additions & 171 deletions

packages/core/src/canvas/canvasTemplates.ts

Lines changed: 4 additions & 158 deletions
Large diffs are not rendered by default.

packages/core/src/canvas/canvasTemplatesService.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
import { freeformSystemPromptFor } from "@posthog/shared/canvas-freeform-prompt";
12
import { injectable } from "inversify";
2-
import {
3-
BUILT_IN_TEMPLATES,
4-
type CanvasTemplate,
5-
freeformSystemPromptFor,
6-
} from "./canvasTemplates";
3+
import { BUILT_IN_TEMPLATES, type CanvasTemplate } from "./canvasTemplates";
74
import type { ICanvasTemplatesService } from "./services";
85
import type { CanvasTemplateSummary } from "./templateSchemas";
96

packages/core/src/canvas/dashboardsService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { AuthService } from "@posthog/core/auth/auth";
22
import { AUTH_SERVICE } from "@posthog/core/auth/auth.module";
3+
import { FREEFORM_TEMPLATE_ID } from "@posthog/shared/canvas-freeform-prompt";
34
import { inject, injectable } from "inversify";
45
import type {
56
DashboardFileMeta,
@@ -11,7 +12,7 @@ import {
1112
type DesktopFsClient,
1213
type FsEntryBase,
1314
} from "./desktopFsClient";
14-
import { FREEFORM_TEMPLATE_ID, type FreeformVersion } from "./freeformSchemas";
15+
import type { FreeformVersion } from "./freeformSchemas";
1516
import { fetchCurrentUser } from "./posthogApi";
1617

1718
// Desktop file-system "type" tag for a dashboard entry. Channels are `folder`

packages/core/src/canvas/freeformSchemas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { z } from "zod";
22

33
// The template id for freeform-React canvases. Stored on a canvas's meta so the
44
// generation path can resolve the right system prompt.
5-
export const FREEFORM_TEMPLATE_ID = "freeform";
65

76
// A single point in a freeform canvas's edit history. Every agent turn appends
8-
// one full-file snapshot (Q7: full-file rewrite); the user can revert to any of
7+
// one full-file snapshot (the agent edits a local scratch copy incrementally,
8+
// then publishes the finished file wholesale); the user can revert to any of
99
// them and the `currentVersionId` pointer is what publishes. We keep whole-file
1010
// snapshots rather than diffs because canvases are small and a snapshot can
1111
// never fail to reconstruct.

packages/shared/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
"types": "./dist/index.d.ts",
99
"import": "./dist/index.js"
1010
},
11+
"./canvas-freeform-prompt": {
12+
"types": "./dist/canvas-freeform-prompt.d.ts",
13+
"import": "./dist/canvas-freeform-prompt.js"
14+
},
15+
"./canvas-freeform-whitelist": {
16+
"types": "./dist/canvas-freeform-whitelist.d.ts",
17+
"import": "./dist/canvas-freeform-whitelist.js"
18+
},
19+
"./canvas-freeform-starter": {
20+
"types": "./dist/canvas-freeform-starter.d.ts",
21+
"import": "./dist/canvas-freeform-starter.js"
22+
},
1123
"./analytics-events": {
1224
"types": "./dist/analytics-events.d.ts",
1325
"import": "./dist/analytics-events.js"

packages/shared/src/canvas-freeform-prompt.ts

Lines changed: 162 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.

packages/core/src/canvas/freeformWhitelist.test.ts renamed to packages/shared/src/canvas-freeform-whitelist.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
buildImportMap,
44
checkFreeformImports,
55
FREEFORM_WHITELIST,
6-
} from "./freeformWhitelist";
6+
} from "./canvas-freeform-whitelist";
77

88
describe("checkFreeformImports", () => {
99
it("accepts whitelisted imports", () => {
File renamed without changes.

packages/shared/tsup.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export default defineConfig({
55
"src/index.ts",
66
"src/agent-platform-types.ts",
77
"src/analytics-events.ts",
8+
"src/canvas-freeform-prompt.ts",
9+
"src/canvas-freeform-starter.ts",
10+
"src/canvas-freeform-whitelist.ts",
811
"src/constants.ts",
912
"src/deeplink.ts",
1013
"src/dismissalReasons.ts",

0 commit comments

Comments
 (0)