@notis_ai/cli 0.2.0-beta.16.1 → 0.2.0-beta.161.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 (161) hide show
  1. package/README.md +435 -133
  2. package/bin/check-runtime.js +15 -0
  3. package/bin/notis.js +2 -0
  4. package/config/notis_app_boundary_rules.json +50 -0
  5. package/config/notis_app_design_rules.json +135 -0
  6. package/dist/agent-hooks/notis-agent-hook.mjs +19008 -0
  7. package/dist/base-skills/notis-apps/SKILL.md +70 -0
  8. package/dist/base-skills/notis-apps/references/architecture.md +164 -0
  9. package/dist/base-skills/notis-apps/references/context.md +81 -0
  10. package/dist/base-skills/notis-apps/references/design.md +165 -0
  11. package/dist/base-skills/notis-apps/references/reading.md +89 -0
  12. package/dist/base-skills/notis-apps/references/release.md +99 -0
  13. package/dist/base-skills/notis-apps/references/sdk.md +62 -0
  14. package/dist/base-skills/notis-apps/references/troubleshooting.md +23 -0
  15. package/dist/base-skills/notis-cli/SKILL.md +140 -0
  16. package/dist/base-skills/notis-cli/references/app-delivery.md +18 -0
  17. package/dist/base-skills/notis-cli/references/native-databases.md +20 -0
  18. package/dist/base-skills/notis-cli/references/tool-examples.md +56 -0
  19. package/dist/base-skills/notis-cli/references/troubleshooting.md +39 -0
  20. package/dist/base-skills/notis-query/SKILL.md +67 -0
  21. package/dist/base-skills/notis-query/references/database-discovery.md +59 -0
  22. package/dist/base-skills/notis-query/references/documents.md +50 -0
  23. package/dist/base-skills/notis-query/references/query.md +543 -0
  24. package/dist/skill-sync/index.js +1626 -0
  25. package/dist/skill-sync/index.js.map +7 -0
  26. package/dist/skill-sync-worker.mjs +2990 -0
  27. package/package.json +18 -7
  28. package/skills/notis-apps/cli.md +313 -0
  29. package/skills/notis-cli/AGENT_INSTRUCTIONS.md +39 -0
  30. package/skills/notis-onboarding/BRIEF.md +129 -0
  31. package/skills/notis-query/cli.md +39 -0
  32. package/src/agent-hook-entry.js +5 -0
  33. package/src/cli.js +294 -25
  34. package/src/command-specs/agents.js +392 -0
  35. package/src/command-specs/apps.js +1470 -202
  36. package/src/command-specs/auth.js +114 -137
  37. package/src/command-specs/diagnostics.js +729 -0
  38. package/src/command-specs/handover.js +374 -0
  39. package/src/command-specs/helpers.js +84 -82
  40. package/src/command-specs/index.js +25 -6
  41. package/src/command-specs/meta.js +150 -18
  42. package/src/command-specs/onboarding.js +290 -0
  43. package/src/command-specs/profile.js +358 -0
  44. package/src/command-specs/reports.js +86 -0
  45. package/src/command-specs/skills.js +75 -0
  46. package/src/command-specs/smoke.js +386 -0
  47. package/src/command-specs/tools.js +455 -139
  48. package/src/runtime/agent-browser.js +632 -0
  49. package/src/runtime/agent-memory-state.js +126 -0
  50. package/src/runtime/agent-setup.js +383 -0
  51. package/src/runtime/app-boundary-validator.js +404 -0
  52. package/src/runtime/app-changelog.js +79 -0
  53. package/src/runtime/app-platform.js +2633 -210
  54. package/src/runtime/app-registry-scaffolds.js +367 -0
  55. package/src/runtime/app-test-server.js +292 -0
  56. package/src/runtime/assets/store-screenshot-dark.png +0 -0
  57. package/src/runtime/auth-recovery.js +110 -0
  58. package/src/runtime/base-skills.d.ts +20 -0
  59. package/src/runtime/base-skills.js +167 -0
  60. package/src/runtime/channel.js +133 -0
  61. package/src/runtime/delegated-context.js +68 -0
  62. package/src/runtime/errors.js +1 -0
  63. package/src/runtime/git.js +233 -0
  64. package/src/runtime/login-listener.js +15 -0
  65. package/src/runtime/oauth.js +2622 -0
  66. package/src/runtime/output.js +37 -5
  67. package/src/runtime/ports.js +31 -0
  68. package/src/runtime/profiles.js +906 -55
  69. package/src/runtime/skill-sync/cloud-client.ts +99 -0
  70. package/src/runtime/skill-sync/index.ts +697 -0
  71. package/src/runtime/skill-sync/local-scanner.ts +1046 -0
  72. package/src/runtime/skill-sync/symlink-manager.ts +433 -0
  73. package/src/runtime/skill-sync/sync-plan.ts +22 -0
  74. package/src/runtime/skill-sync/types.ts +110 -0
  75. package/src/runtime/skill-sync/write-cloud-skill.ts +50 -0
  76. package/src/runtime/skill-sync-service.js +109 -0
  77. package/src/runtime/store-screenshot.js +143 -0
  78. package/src/runtime/sync-skills.d.ts +37 -0
  79. package/src/runtime/sync-skills.js +231 -0
  80. package/src/runtime/telemetry.js +92 -0
  81. package/src/runtime/transport.js +324 -45
  82. package/src/skill-sync-worker-entry.js +2 -0
  83. package/src/skill-sync-worker.js +50 -0
  84. package/template/.harness/index.html.tmpl +430 -0
  85. package/template/CHANGELOG.md +5 -0
  86. package/template/app/globals.css +28 -3
  87. package/template/app/layout.tsx +6 -3
  88. package/template/app/page.tsx +49 -42
  89. package/template/components/page-heading.tsx +23 -0
  90. package/template/components/ui/badge.tsx +7 -4
  91. package/template/components/ui/button.tsx +1 -1
  92. package/template/components/ui/card.tsx +24 -11
  93. package/template/components/ui/native-select.tsx +24 -0
  94. package/template/notis.config.ts +24 -6
  95. package/template/package-lock.json +3642 -0
  96. package/template/package.json +19 -16
  97. package/template/packages/{notis-sdk → sdk}/package.json +14 -4
  98. package/template/packages/sdk/src/agentContext.ts +36 -0
  99. package/template/packages/sdk/src/components/DocumentEditor.tsx +103 -0
  100. package/template/packages/sdk/src/components/Markdown.tsx +60 -0
  101. package/template/packages/sdk/src/components/MarkdownEditor.tsx +121 -0
  102. package/template/packages/sdk/src/components/MultiSelectActionBar.tsx +285 -0
  103. package/template/packages/sdk/src/components/MultiSelectCheckbox.tsx +97 -0
  104. package/template/packages/sdk/src/components/MultiSelectDragOverlay.tsx +39 -0
  105. package/template/packages/sdk/src/components/NotisCommentBoundary.tsx +172 -0
  106. package/template/packages/sdk/src/components/NotisSelectionBoundary.tsx +59 -0
  107. package/template/packages/sdk/src/components/ShortcutHints.tsx +56 -0
  108. package/template/packages/sdk/src/components/Skeleton.tsx +24 -0
  109. package/template/packages/sdk/src/config.ts +257 -0
  110. package/template/packages/sdk/src/documents.ts +256 -0
  111. package/template/packages/sdk/src/hooks/useActiveResource.ts +19 -0
  112. package/template/packages/sdk/src/hooks/useAgentContext.ts +23 -0
  113. package/template/packages/sdk/src/hooks/useCloudComputer.ts +64 -0
  114. package/template/packages/sdk/src/hooks/useCollectionInteractions.ts +836 -0
  115. package/template/packages/sdk/src/hooks/useDatabaseSchema.ts +49 -0
  116. package/template/packages/sdk/src/hooks/useDatabaseSubscription.ts +76 -0
  117. package/template/packages/sdk/src/hooks/useDocument.ts +43 -0
  118. package/template/packages/sdk/src/hooks/useDocuments.ts +84 -0
  119. package/template/packages/sdk/src/hooks/useHandover.ts +78 -0
  120. package/template/packages/sdk/src/hooks/useLongPressSelection.ts +79 -0
  121. package/template/packages/sdk/src/hooks/useMultiSelect.ts +95 -0
  122. package/template/packages/{notis-sdk → sdk}/src/hooks/useNotis.ts +10 -4
  123. package/template/packages/{notis-sdk → sdk}/src/hooks/useNotisNavigation.ts +11 -8
  124. package/template/packages/sdk/src/hooks/useQuery.ts +71 -0
  125. package/template/packages/sdk/src/hooks/useTool.ts +65 -0
  126. package/template/packages/sdk/src/hooks/useToolQuery.ts +12 -0
  127. package/template/packages/sdk/src/hooks/useTopBarSearch.ts +81 -0
  128. package/template/packages/sdk/src/hooks/useUpsertDocument.ts +95 -0
  129. package/template/packages/sdk/src/index.ts +161 -0
  130. package/template/packages/sdk/src/interactions/actions.ts +59 -0
  131. package/template/packages/sdk/src/interactions/shortcuts.tsx +694 -0
  132. package/template/packages/sdk/src/interactions/visibility.ts +13 -0
  133. package/template/packages/sdk/src/interactions.ts +45 -0
  134. package/template/packages/sdk/src/provider.tsx +44 -0
  135. package/template/packages/sdk/src/queryCache.ts +170 -0
  136. package/template/packages/sdk/src/runtime.ts +451 -0
  137. package/template/packages/sdk/src/styles.css +247 -0
  138. package/template/packages/sdk/src/tailwind.ts +66 -0
  139. package/template/packages/sdk/src/vite.ts +73 -0
  140. package/template/packages/{notis-sdk → sdk}/tsconfig.json +1 -0
  141. package/template/postcss.config.mjs +1 -1
  142. package/template/tailwind.config.ts +1 -6
  143. package/template/tsconfig.json +1 -0
  144. package/src/command-specs/db.js +0 -163
  145. package/src/runtime/app-preview-server.js +0 -312
  146. package/template/packages/notis-sdk/src/config.ts +0 -48
  147. package/template/packages/notis-sdk/src/helpers.ts +0 -131
  148. package/template/packages/notis-sdk/src/hooks/useAppState.ts +0 -50
  149. package/template/packages/notis-sdk/src/hooks/useCollectionItem.ts +0 -58
  150. package/template/packages/notis-sdk/src/hooks/useDatabase.ts +0 -87
  151. package/template/packages/notis-sdk/src/hooks/useDocument.ts +0 -61
  152. package/template/packages/notis-sdk/src/hooks/useTool.ts +0 -49
  153. package/template/packages/notis-sdk/src/hooks/useUpsertDocument.ts +0 -57
  154. package/template/packages/notis-sdk/src/index.ts +0 -47
  155. package/template/packages/notis-sdk/src/provider.tsx +0 -44
  156. package/template/packages/notis-sdk/src/runtime.ts +0 -159
  157. package/template/packages/notis-sdk/src/styles.css +0 -123
  158. package/template/packages/notis-sdk/src/vite.ts +0 -54
  159. /package/template/packages/{notis-sdk → sdk}/src/hooks/useBackend.ts +0 -0
  160. /package/template/packages/{notis-sdk → sdk}/src/hooks/useTools.ts +0 -0
  161. /package/template/packages/{notis-sdk → sdk}/src/ui.ts +0 -0
@@ -0,0 +1,56 @@
1
+ 'use client';
2
+
3
+ import React, { type CSSProperties, type ReactElement } from 'react';
4
+ import { shortcutDisplay } from '../interactions/shortcuts';
5
+
6
+ export interface ShortcutHint {
7
+ id: string;
8
+ keys: string;
9
+ label: string;
10
+ }
11
+
12
+ export interface ShortcutHintsProps {
13
+ shortcuts: ShortcutHint[];
14
+ className?: string;
15
+ style?: CSSProperties;
16
+ }
17
+
18
+ const listStyle: CSSProperties = {
19
+ display: 'flex',
20
+ flexWrap: 'wrap',
21
+ alignItems: 'center',
22
+ gap: '0.75rem',
23
+ color: 'hsl(var(--muted-foreground))',
24
+ fontSize: '12px',
25
+ };
26
+
27
+ const hintStyle: CSSProperties = {
28
+ display: 'inline-flex',
29
+ alignItems: 'center',
30
+ gap: '0.35rem',
31
+ };
32
+
33
+ const keyStyle: CSSProperties = {
34
+ minWidth: '20px',
35
+ border: '1px solid hsl(var(--border))',
36
+ borderRadius: '4px',
37
+ background: 'hsl(var(--muted))',
38
+ color: 'hsl(var(--foreground))',
39
+ padding: '1px 5px',
40
+ textAlign: 'center',
41
+ font: 'inherit',
42
+ };
43
+
44
+ export function ShortcutHints({ shortcuts, className, style }: ShortcutHintsProps): ReactElement | null {
45
+ if (shortcuts.length === 0) return null;
46
+ return (
47
+ <div aria-label="Keyboard shortcuts" className={className} style={{ ...listStyle, ...style }}>
48
+ {shortcuts.map((shortcut) => (
49
+ <span key={shortcut.id} style={hintStyle}>
50
+ <kbd style={keyStyle}>{shortcutDisplay(shortcut.keys)}</kbd>
51
+ <span>{shortcut.label}</span>
52
+ </span>
53
+ ))}
54
+ </div>
55
+ );
56
+ }
@@ -0,0 +1,24 @@
1
+ import type { CSSProperties } from 'react';
2
+
3
+ /** Content-shaped placeholder. Never use it to replace a successful cached result. */
4
+ export function Skeleton({ className, style }: { className?: string; style?: CSSProperties }) {
5
+ return <span aria-hidden="true" className={className} style={{ display: 'block', height: 16,
6
+ // Apps may define --muted as HSL channels or a complete CSS color. A
7
+ // neutral default remains visible with either token format and no theme.
8
+ borderRadius: 6, background: 'rgba(128,128,128,.18)', ...style }} />;
9
+ }
10
+
11
+ export function ViewSkeleton({ variant = 'table', rows = 5 }: {
12
+ variant?: 'table' | 'cards' | 'graph' | 'detail'; rows?: number;
13
+ }) {
14
+ return <div role="status" aria-label="Loading content" aria-busy="true" data-notis-content-skeleton
15
+ style={{ width: '100%', display: 'grid', gap: 16, padding: 24 }}>
16
+ <Skeleton style={{ width: '32%', height: 28 }} />
17
+ {variant === 'graph' ? <Skeleton style={{ height: 420 }} /> :
18
+ <div style={{ display: 'grid', gap: 12, gridTemplateColumns: variant === 'cards' ? 'repeat(auto-fit,minmax(180px,1fr))' : '1fr' }}>
19
+ {Array.from({ length: rows }, (_, index) => <Skeleton key={index}
20
+ style={{ height: variant === 'cards' ? 112 : variant === 'detail' ? 20 : 44,
21
+ width: variant === 'detail' && index === rows - 1 ? '65%' : '100%' }} />)}
22
+ </div>}
23
+ </div>;
24
+ }
@@ -0,0 +1,257 @@
1
+ /**
2
+ * Configuration utilities for notis.config.ts.
3
+ *
4
+ * Usage:
5
+ * ```ts
6
+ * // notis.config.ts
7
+ * import { defineNotisApp } from '@notis/sdk/config';
8
+ *
9
+ * export default defineNotisApp({
10
+ * name: 'My App',
11
+ * description: 'Does things',
12
+ * icon: 'phosphor:squares-four',
13
+ * databases: ['tasks'],
14
+ * routes: [
15
+ * {
16
+ * path: '/',
17
+ * slug: 'notes',
18
+ * name: 'Notes',
19
+ * default: true,
20
+ * collection: {
21
+ * database: 'notes',
22
+ * titleProperty: 'Name',
23
+ * parentProperty: 'Parent',
24
+ * sidebar: {
25
+ * mode: 'tree',
26
+ * allowCreate: true,
27
+ * },
28
+ * },
29
+ * },
30
+ * ],
31
+ * tools: [...],
32
+ * });
33
+ * ```
34
+ */
35
+
36
+ export interface NotisRouteConfig {
37
+ path: string;
38
+ slug: string;
39
+ name: string;
40
+ icon?: string;
41
+ parentSlug?: string | null;
42
+ default?: boolean;
43
+ /**
44
+ * Allow the host to address an app-owned resource on this route through the
45
+ * canonical `?resource=<id>` deep link. Read the incoming id with
46
+ * `useNotis().resourceId`.
47
+ */
48
+ resourceDeepLinks?: boolean;
49
+ exportName?: string;
50
+ collection?: {
51
+ database: string;
52
+ titleProperty: string;
53
+ parentProperty?: string | null;
54
+ sidebar?: {
55
+ mode: 'flat-list' | 'tree';
56
+ allowCreate: boolean;
57
+ };
58
+ };
59
+ }
60
+
61
+ export const NOTIS_APP_CATEGORIES = [
62
+ 'Productivity',
63
+ 'Sales & Marketing',
64
+ 'Operations',
65
+ 'Product & Engineering',
66
+ 'Personal',
67
+ ] as const;
68
+
69
+ export type NotisAppCategory = typeof NOTIS_APP_CATEGORIES[number];
70
+
71
+ export interface NotisAppDatabaseConfig {
72
+ /** Database slug, as declared by the app. */
73
+ slug: string;
74
+ /**
75
+ * Ship this database's rows to everyone who installs the app.
76
+ *
77
+ * Off by default: declaring a database publishes its STRUCTURE, never its
78
+ * content. Turn it on only for starter content that every installer should
79
+ * receive - a default folder tree, a set of templates - and never for a
80
+ * database that accumulates the author's own data.
81
+ */
82
+ seedDocuments?: boolean;
83
+ }
84
+
85
+ export interface NotisAppAuthor {
86
+ name: string;
87
+ handle?: string;
88
+ url?: string;
89
+ }
90
+
91
+ export interface NotisAppSkillConfig {
92
+ /** Stable source-owned key used by other app declarations. */
93
+ key: string;
94
+ /**
95
+ * Path to the skill, relative to notis.config.ts. Either a Markdown file
96
+ * (`./skills/onboarding.md`) or a directory holding SKILL.md plus its
97
+ * supporting files (`./skills/onboarding/`), which are packaged on deploy
98
+ * and materialized next to SKILL.md in the sandbox.
99
+ */
100
+ path: string;
101
+ /** User-facing name used for the installed skill. */
102
+ name: string;
103
+ description?: string;
104
+ }
105
+
106
+ export interface NotisAppOnboardingConfig {
107
+ /** Key of a skill declared in `skills`. */
108
+ skill: string;
109
+ /** Editable message placed in Notis when onboarding is opened. */
110
+ prompt: string;
111
+ }
112
+
113
+ export interface NotisAppScreenshotConfig {
114
+ /** Conventional metadata/screenshot-N.png source path. */
115
+ path: string;
116
+ /** Meaningful description used by the Store gallery and assistive technology. */
117
+ alt: string;
118
+ /** Route slug captured by `notis apps screenshot`. */
119
+ route?: string;
120
+ /**
121
+ * Named scenario from metadata/screenshot-fixtures.json. Its `tools` and
122
+ * `requests` override the file-level ones key by key for this capture, and
123
+ * its `actions` run once the route has mounted -- so one route can be shown
124
+ * in several states (populated, empty, a panel opened) without the states
125
+ * leaking into each other.
126
+ */
127
+ scenario?: string;
128
+ /** Optional CSS selector captured as the truthful focal region for this Store image. */
129
+ focus?: string;
130
+ /** Portal color scheme used while rendering this screenshot. Defaults to light. */
131
+ theme?: 'light' | 'dark';
132
+ }
133
+
134
+ /**
135
+ * Named accent tokens for an app's avatar. Keep in sync with the portal
136
+ * `ACCENT_NAMES` and the server `ACCENT_TOKENS`.
137
+ */
138
+ export const NOTIS_APP_ACCENTS = [
139
+ 'blue',
140
+ 'violet',
141
+ 'emerald',
142
+ 'amber',
143
+ 'rose',
144
+ 'sky',
145
+ 'fuchsia',
146
+ 'teal',
147
+ ] as const;
148
+
149
+ export type NotisAppAccent = typeof NOTIS_APP_ACCENTS[number];
150
+
151
+ export interface NotisAppCapabilities {
152
+ /**
153
+ * Read every database in the workspace, not only the ones this app declares
154
+ * in `databases` or created itself.
155
+ *
156
+ * An app runtime is otherwise sandboxed to its own databases, so a catalog or
157
+ * explorer app sees an empty list without this. `'read'` is the only accepted
158
+ * value and it never grants writes: `LOCAL_NOTIS_DATABASE_UPSERT_*` stays
159
+ * bound to the app's own databases.
160
+ */
161
+ workspaceDatabases?: 'read';
162
+
163
+ /**
164
+ * Read a few facts about the user's cloud computer: whether a sandbox exists
165
+ * and is running, and whether the GitHub CLI is signed in there.
166
+ *
167
+ * Without this an app has to infer them — the Workspaces app treated a
168
+ * configured repository as proof that `gh auth login` had happened, which
169
+ * cannot show an account name and cannot notice a revoked credential.
170
+ * `'read'` never creates, resumes or commands a sandbox. Read it with
171
+ * `useCloudComputer()`.
172
+ *
173
+ * `'shell'` additionally asks to command the cloud computer: it unlocks
174
+ * `LOCAL_NOTIS_RUN_SANDBOX_SHELL` and the sandbox file tools from this app's
175
+ * views (they are denied to every view otherwise), and implies the read
176
+ * facts. This is the same authority the user's own agent has on the sandbox,
177
+ * so the user is asked for it explicitly at install or in the Store grant
178
+ * step; declare it only when the app's core actions genuinely run there.
179
+ */
180
+ cloudComputer?: 'read' | 'shell';
181
+ }
182
+
183
+ /**
184
+ * Execution hint for a tool whose public name is generated by a provider.
185
+ *
186
+ * MCP public names may be truncated or deduplicated, so the upstream action
187
+ * cannot always be reconstructed from the final `LOCAL_MCP_*` name. Binding
188
+ * the two lets the host skip provider schema discovery on direct calls while
189
+ * the public name remains the user-approved permission boundary.
190
+ */
191
+ export interface NotisAppToolBinding {
192
+ /** Exact final name also present in `tools`. */
193
+ name: string;
194
+ /** Exact upstream MCP action name, for example `execute_sql`. */
195
+ providerToolName: string;
196
+ }
197
+
198
+ export interface NotisAppConfig {
199
+ /** URL-safe app slug. Existing apps may still use a display name here. */
200
+ name: string;
201
+ /** Human display title, Raycast-style. Falls back to `name`. */
202
+ title?: string;
203
+ description?: string;
204
+ /**
205
+ * App icon. A `phosphor:<name>` value (e.g. `phosphor:dice-five`) or
206
+ * `metadata/icon.png`. When unset, the app shows its two-letter initials.
207
+ */
208
+ icon?: string;
209
+ /**
210
+ * Optional accent color for the app avatar. One of {@link NOTIS_APP_ACCENTS}.
211
+ * When unset, a stable accent is derived automatically from the app id.
212
+ */
213
+ accent?: NotisAppAccent;
214
+ author?: NotisAppAuthor;
215
+ categories?: NotisAppCategory[];
216
+ tagline?: string;
217
+ /** @deprecated Add release entries to the root CHANGELOG.md instead. */
218
+ versionNotes?: string;
219
+ /** Editorial screenshot order and capture scenarios for the Store listing. */
220
+ screenshots?: NotisAppScreenshotConfig[];
221
+ /**
222
+ * Databases this app owns. A bare string publishes structure only; use the
223
+ * object form to opt a database into shipping its rows to installers.
224
+ */
225
+ databases?: (string | NotisAppDatabaseConfig)[];
226
+ /**
227
+ * Extra permissions the app asks for at install time. Everything here widens
228
+ * what the app can reach beyond its own data, so each one is surfaced to the
229
+ * user before they install.
230
+ */
231
+ capabilities?: NotisAppCapabilities;
232
+ routes?: NotisRouteConfig[];
233
+ /**
234
+ * Final tool names this app can call at runtime, enforced server-side. Use
235
+ * names returned by shared discovery, including native `LOCAL_NOTIS_*`,
236
+ * connected-service names such as `GMAIL_SEND_EMAIL`,
237
+ * `LOCAL_POSTFORME_*`, and `LOCAL_MCP_<SERVER>_<TOOL>`. App code calls
238
+ * each declared name directly with `useTool`; metered calls use the shared
239
+ * credit-cap and usage-billing path.
240
+ */
241
+ tools?: string[];
242
+ /** Optional execution bindings for provider-generated tool names. */
243
+ toolBindings?: NotisAppToolBinding[];
244
+ /** Skills shipped from this app's source tree. */
245
+ skills?: NotisAppSkillConfig[];
246
+ /** Optional onboarding entrypoint exposed from the app sidebar. */
247
+ onboarding?: NotisAppOnboardingConfig;
248
+ }
249
+
250
+ /**
251
+ * Identity function that provides type checking and autocomplete for the
252
+ * Notis app configuration. The returned object is read at build time by
253
+ * `notis apps build` to generate the manifest.
254
+ */
255
+ export function defineNotisApp(config: NotisAppConfig): NotisAppConfig {
256
+ return config;
257
+ }
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Document data helpers: normalize raw tool results (Notion-shaped property
3
+ * values, snake_case fields) into the SDK's `DocumentRecord`/`DatabaseProperty`
4
+ * shapes, and derive plain-text projections from typed content.
5
+ *
6
+ * These are pure functions — safe in any context (portal, dev harness, tests).
7
+ */
8
+
9
+ import type {
10
+ DatabaseProperty,
11
+ DatabasePropertyOption,
12
+ DatabasePropertyType,
13
+ DocumentContentType,
14
+ DocumentRecord,
15
+ SecretPropertyValue,
16
+ } from './runtime';
17
+
18
+ // ---------------------------------------------------------------------------
19
+ // Value primitives
20
+ // ---------------------------------------------------------------------------
21
+
22
+ export function isPresentString(value: unknown): value is string {
23
+ return typeof value === 'string' && value.trim().length > 0;
24
+ }
25
+
26
+ export function asRecord(value: unknown): Record<string, unknown> | null {
27
+ return value && typeof value === 'object' && !Array.isArray(value)
28
+ ? (value as Record<string, unknown>)
29
+ : null;
30
+ }
31
+
32
+ export function optionalString(value: unknown): string | null {
33
+ return isPresentString(value) ? value.trim() : null;
34
+ }
35
+
36
+ /** Flattens a Notion-shaped rich_text array (or plain string) to text. */
37
+ export function extractRichText(value: unknown): string {
38
+ if (typeof value === 'string') return value;
39
+ if (!Array.isArray(value)) return '';
40
+ return value
41
+ .map((item) => {
42
+ const record = asRecord(item);
43
+ const text = asRecord(record?.text);
44
+ return optionalString(text?.content) ?? optionalString(record?.plain_text) ?? '';
45
+ })
46
+ .join('');
47
+ }
48
+
49
+ /**
50
+ * Reads a `secret` property value. The platform only ever sends the pointer
51
+ * ({present, reference, status, metadata}), so this rebuilds it field by field
52
+ * rather than passing the payload through — an app can never surface secret
53
+ * material through this helper, whatever the server sent.
54
+ */
55
+ export function getSecretValue(value: unknown): SecretPropertyValue {
56
+ const record = asRecord(value);
57
+ const metadata = asRecord(record?.metadata);
58
+ return {
59
+ present: record?.present === true,
60
+ reference: optionalString(record?.reference),
61
+ status: optionalString(record?.status),
62
+ metadata,
63
+ };
64
+ }
65
+
66
+ /** Extracts the ids of a normalized relation property value. */
67
+ export function getRelationIds(value: unknown): string[] {
68
+ if (!Array.isArray(value)) return [];
69
+ return value.filter((item): item is string => isPresentString(item));
70
+ }
71
+
72
+ // ---------------------------------------------------------------------------
73
+ // Property + document normalization
74
+ // ---------------------------------------------------------------------------
75
+
76
+ /**
77
+ * Collapses a Notion-shaped property value ({type: 'select', select: {...}})
78
+ * into a plain JS value (string, string[], number, boolean, ...). Values that
79
+ * are already plain pass through unchanged.
80
+ */
81
+ export function normalizePropertyValue(value: unknown): unknown {
82
+ const record = asRecord(value);
83
+ if (!record) return value;
84
+
85
+ const type = optionalString(record.type);
86
+ if (!type) return value;
87
+
88
+ if (type === 'title') return extractRichText(record.title);
89
+ if (type === 'rich_text') return extractRichText(record.rich_text);
90
+ if (type === 'select' || type === 'status') {
91
+ return optionalString(asRecord(record[type])?.name) ?? record[type] ?? null;
92
+ }
93
+ if (type === 'multi_select') {
94
+ const items = Array.isArray(record.multi_select) ? record.multi_select : [];
95
+ return items.map((item) => optionalString(asRecord(item)?.name) ?? item).filter(Boolean);
96
+ }
97
+ if (type === 'relation') {
98
+ const items = Array.isArray(record.relation) ? record.relation : [];
99
+ return items.map((item) => optionalString(asRecord(item)?.id) ?? item).filter(Boolean);
100
+ }
101
+ if (type === 'date') return optionalString(asRecord(record.date)?.start) ?? record.date ?? null;
102
+ // Before the `type in record` fallthrough: a secret value has no `secret`
103
+ // key, so passing it through would hand the caller the raw payload.
104
+ if (type === 'secret') return getSecretValue(record);
105
+ if (type in record) return record[type];
106
+ return value;
107
+ }
108
+
109
+ function normalizeContentType(value: unknown): DocumentContentType | null {
110
+ return value === 'markdown' || value === 'file' || value === 'view' ? value : null;
111
+ }
112
+
113
+ /**
114
+ * Normalizes a raw document from a Notis database tool result
115
+ * (LOCAL_NOTIS_DATABASE_QUERY / GET_DOCUMENT / UPSERT_*) into a
116
+ * `DocumentRecord`: camelCases fields and collapses property values.
117
+ */
118
+ export function normalizeDocumentRecord(value: unknown): DocumentRecord {
119
+ const record = asRecord(value) ?? {};
120
+ const rawProperties = asRecord(record.properties) ?? {};
121
+ const properties: Record<string, unknown> = {};
122
+ for (const [key, propertyValue] of Object.entries(rawProperties)) {
123
+ properties[key] = normalizePropertyValue(propertyValue);
124
+ }
125
+
126
+ return {
127
+ id: optionalString(record.id) ?? '',
128
+ title: optionalString(record.title) ?? 'Untitled',
129
+ url: optionalString(record.url),
130
+ properties,
131
+ icon: optionalString(record.icon),
132
+ cover: optionalString(record.cover),
133
+ databaseSlug: optionalString(record.databaseSlug) ?? optionalString(record.database_slug) ?? undefined,
134
+ contentType: normalizeContentType(record.contentType ?? record.content_type),
135
+ fileType: optionalString(record.fileType) ?? optionalString(record.file_type),
136
+ contentBlocknote: Array.isArray(record.contentBlocknote)
137
+ ? (record.contentBlocknote as Array<Record<string, unknown>>)
138
+ : Array.isArray(record.content_blocknote)
139
+ ? (record.content_blocknote as Array<Record<string, unknown>>)
140
+ : null,
141
+ contentMarkdown: optionalString(record.contentMarkdown) ?? optionalString(record.content_markdown),
142
+ plainText: optionalString(record.plainText) ?? optionalString(record.plain_text),
143
+ viewType: optionalString(record.viewType) ?? optionalString(record.view_type),
144
+ viewState: asRecord(record.viewState) ?? asRecord(record.view_state),
145
+ viewRevision:
146
+ typeof (record.viewRevision ?? record.view_revision) === 'number'
147
+ ? Number(record.viewRevision ?? record.view_revision)
148
+ : null,
149
+ createdAt:
150
+ optionalString(record.createdAt)
151
+ ?? optionalString(record.created_at)
152
+ ?? optionalString(record.created_time),
153
+ lastEditedTime:
154
+ optionalString(record.lastEditedTime)
155
+ ?? optionalString(record.last_edited_time)
156
+ ?? optionalString(record.updated_at),
157
+ };
158
+ }
159
+
160
+ /** Normalizes a raw schema property from LOCAL_NOTIS_DATABASE_GET_DATABASE. */
161
+ export function normalizeDatabaseProperty(value: unknown): DatabaseProperty | null {
162
+ const record = asRecord(value);
163
+ const name = optionalString(record?.name);
164
+ if (!record || !name) return null;
165
+
166
+ const rawOptions = Array.isArray(record.options) ? record.options : [];
167
+ const options = rawOptions.flatMap((option): DatabasePropertyOption[] => {
168
+ const optionRecord = asRecord(option);
169
+ const optionName = optionalString(optionRecord?.name);
170
+ if (!optionRecord || !optionName) return [];
171
+ return [{
172
+ id: optionalString(optionRecord.id),
173
+ name: optionName,
174
+ color: optionalString(optionRecord.color),
175
+ order: typeof optionRecord.order === 'number' ? optionRecord.order : undefined,
176
+ }];
177
+ });
178
+
179
+ return {
180
+ id: optionalString(record.id),
181
+ name,
182
+ type: (optionalString(record.type) ?? 'rich_text') as DatabasePropertyType,
183
+ description: optionalString(record.description),
184
+ options,
185
+ };
186
+ }
187
+
188
+ // ---------------------------------------------------------------------------
189
+ // Plain-text projections
190
+ // ---------------------------------------------------------------------------
191
+
192
+ /** Strips markdown syntax to readable plain text (previews, search). */
193
+ export function markdownToPlainText(markdown: string): string {
194
+ return markdown
195
+ // fenced code blocks: keep the code, drop the fences
196
+ .replace(/```[^\n]*\n?/g, '')
197
+ // images: keep alt text
198
+ .replace(/!\[([^\]]*)\]\([^)]*\)/g, '$1')
199
+ // links: keep link text
200
+ .replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
201
+ // html tags
202
+ .replace(/<[^>]+>/g, ' ')
203
+ // headings, blockquotes, list markers, task boxes
204
+ .replace(/^\s{0,3}(#{1,6}\s+|>\s?|[-*+]\s+(\[[ xX]\]\s+)?|\d+\.\s+)/gm, '')
205
+ // emphasis / strikethrough / inline code
206
+ .replace(/(\*\*|__|[*_~`])/g, '')
207
+ // table separators and pipes
208
+ .replace(/^\s*\|?[-:| ]+\|?\s*$/gm, '')
209
+ .replace(/\|/g, ' ')
210
+ // horizontal rules
211
+ .replace(/^\s*([-*_]\s*){3,}$/gm, '')
212
+ .replace(/\s+/g, ' ')
213
+ .trim();
214
+ }
215
+
216
+ /** Flattens BlockNote block JSON to plain text. */
217
+ export function blockNoteToPlainText(blocks: unknown): string {
218
+ const segments: string[] = [];
219
+
220
+ function visit(node: unknown): void {
221
+ if (typeof node === 'string') {
222
+ if (node.trim()) segments.push(node.trim());
223
+ return;
224
+ }
225
+ if (Array.isArray(node)) {
226
+ node.forEach(visit);
227
+ return;
228
+ }
229
+ const record = asRecord(node);
230
+ if (!record) return;
231
+ if (typeof record.text === 'string' && record.text.trim()) {
232
+ segments.push(record.text.trim());
233
+ }
234
+ visit(record.content);
235
+ visit(record.children);
236
+ }
237
+
238
+ visit(blocks);
239
+ return segments.join(' ').replace(/\s+/g, ' ').trim();
240
+ }
241
+
242
+ /**
243
+ * Best-available plain-text preview for a document:
244
+ * plainText -> contentMarkdown -> contentBlocknote -> title.
245
+ */
246
+ export function getDocumentPreview(document: DocumentRecord): string {
247
+ if (isPresentString(document.plainText)) {
248
+ return document.plainText.replace(/\s+/g, ' ').trim();
249
+ }
250
+ if (isPresentString(document.contentMarkdown)) {
251
+ return markdownToPlainText(document.contentMarkdown);
252
+ }
253
+ const fromBlocks = blockNoteToPlainText(document.contentBlocknote);
254
+ if (fromBlocks) return fromBlocks;
255
+ return isPresentString(document.title) ? document.title : 'Untitled';
256
+ }
@@ -0,0 +1,19 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { useNotisRuntime } from '../provider';
3
+ import type { ContextResource } from '../runtime';
4
+
5
+ function stableResource(resource: ContextResource | null): string {
6
+ return JSON.stringify(resource);
7
+ }
8
+
9
+ /** Keep Notis aware of the resource currently open inside an app view. */
10
+ export function useActiveResource(resource: ContextResource | null): void {
11
+ const runtime = useNotisRuntime();
12
+ const signature = stableResource(resource);
13
+ const stable = useMemo(() => resource, [signature]);
14
+
15
+ useEffect(() => {
16
+ runtime?.publishActiveResource?.(stable);
17
+ return () => runtime?.publishActiveResource?.(null);
18
+ }, [runtime, stable]);
19
+ }
@@ -0,0 +1,23 @@
1
+ 'use client';
2
+ import { useMemo } from 'react';
3
+ import { useNotisRuntime } from '../provider';
4
+ import type { AgentContextItem } from '../agentContext';
5
+
6
+ /** Share context without owning storage, opening a new thread, or sending a message. */
7
+ export function useAgentContext() {
8
+ const runtime = useNotisRuntime();
9
+ return useMemo(() => ({
10
+ add(item: AgentContextItem): Promise<boolean> {
11
+ if (!runtime?.addContext) return Promise.reject(new Error('Chat context is unavailable in this host.'));
12
+ return runtime.addContext(item);
13
+ },
14
+ update(item: AgentContextItem): Promise<boolean> {
15
+ if (!runtime?.updateContext) return Promise.reject(new Error('Chat context is unavailable in this host.'));
16
+ return runtime.updateContext(item);
17
+ },
18
+ remove(id: string): Promise<boolean> {
19
+ if (!runtime?.removeContext) return Promise.reject(new Error('Chat context is unavailable in this host.'));
20
+ return runtime.removeContext(id);
21
+ },
22
+ }), [runtime]);
23
+ }