@notis_ai/cli 0.2.0-beta.19.1 → 0.2.0-beta.196.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 (216) hide show
  1. package/README.md +822 -135
  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/config/portal-route-roots.json +48 -0
  7. package/dist/agent-hooks/notis-agent-hook.mjs +45587 -0
  8. package/dist/base-skills/notis-apps/SKILL.md +93 -0
  9. package/dist/base-skills/notis-apps/references/architecture.md +114 -0
  10. package/dist/base-skills/notis-apps/references/context.md +81 -0
  11. package/dist/base-skills/notis-apps/references/design.md +97 -0
  12. package/dist/base-skills/notis-apps/references/memory.md +58 -0
  13. package/dist/base-skills/notis-apps/references/reading.md +67 -0
  14. package/dist/base-skills/notis-apps/references/release.md +107 -0
  15. package/dist/base-skills/notis-apps/references/sdk.md +116 -0
  16. package/dist/base-skills/notis-apps/references/troubleshooting.md +24 -0
  17. package/dist/base-skills/notis-apps/references/views.md +142 -0
  18. package/dist/base-skills/notis-cli/SKILL.md +154 -0
  19. package/dist/base-skills/notis-cli/references/app-delivery.md +19 -0
  20. package/dist/base-skills/notis-cli/references/intelligence.md +94 -0
  21. package/dist/base-skills/notis-cli/references/native-databases.md +21 -0
  22. package/dist/base-skills/notis-cli/references/tool-examples.md +56 -0
  23. package/dist/base-skills/notis-cli/references/troubleshooting.md +39 -0
  24. package/dist/base-skills/notis-query/SKILL.md +41 -0
  25. package/dist/base-skills/notis-query/references/database-discovery.md +60 -0
  26. package/dist/base-skills/notis-query/references/documents.md +63 -0
  27. package/dist/base-skills/notis-query/references/query.md +76 -0
  28. package/{template/packages/notis-sdk → dist/sdk}/package.json +14 -4
  29. package/dist/sdk/src/agentContext.ts +36 -0
  30. package/dist/sdk/src/bundleModule.ts +79 -0
  31. package/dist/sdk/src/components/Dialog.tsx +46 -0
  32. package/dist/sdk/src/components/DocumentEditor.tsx +106 -0
  33. package/dist/sdk/src/components/DocumentPage.tsx +141 -0
  34. package/dist/sdk/src/components/Markdown.tsx +60 -0
  35. package/dist/sdk/src/components/MarkdownEditor.tsx +121 -0
  36. package/dist/sdk/src/components/MultiSelectActionBar.tsx +285 -0
  37. package/dist/sdk/src/components/MultiSelectCheckbox.tsx +97 -0
  38. package/dist/sdk/src/components/MultiSelectDragOverlay.tsx +39 -0
  39. package/dist/sdk/src/components/NotisCommentBoundary.tsx +172 -0
  40. package/dist/sdk/src/components/NotisSelectionBoundary.tsx +59 -0
  41. package/dist/sdk/src/components/RecordComponents.tsx +33 -0
  42. package/dist/sdk/src/components/RenderChartData.tsx +19 -0
  43. package/dist/sdk/src/components/ShortcutHints.tsx +56 -0
  44. package/dist/sdk/src/components/Skeleton.tsx +24 -0
  45. package/dist/sdk/src/config.ts +239 -0
  46. package/dist/sdk/src/documents.ts +258 -0
  47. package/dist/sdk/src/hooks/useAction.ts +28 -0
  48. package/dist/sdk/src/hooks/useActiveResource.ts +19 -0
  49. package/dist/sdk/src/hooks/useAgentContext.ts +23 -0
  50. package/dist/sdk/src/hooks/useCloudComputer.ts +95 -0
  51. package/dist/sdk/src/hooks/useCloudComputerShell.ts +114 -0
  52. package/dist/sdk/src/hooks/useCollectionInteractions.ts +838 -0
  53. package/dist/sdk/src/hooks/useDatabaseSchema.ts +49 -0
  54. package/dist/sdk/src/hooks/useDatabaseSubscription.ts +76 -0
  55. package/dist/sdk/src/hooks/useDocument.ts +43 -0
  56. package/dist/sdk/src/hooks/useDocuments.ts +84 -0
  57. package/dist/sdk/src/hooks/useHandover.ts +78 -0
  58. package/dist/sdk/src/hooks/useLongPressSelection.ts +79 -0
  59. package/dist/sdk/src/hooks/useMultiSelect.ts +95 -0
  60. package/dist/sdk/src/hooks/useNativeDocumentBody.ts +50 -0
  61. package/dist/sdk/src/hooks/useNativeDocuments.ts +83 -0
  62. package/dist/sdk/src/hooks/useNotis.ts +42 -0
  63. package/dist/sdk/src/hooks/useNotisNavigation.ts +67 -0
  64. package/dist/sdk/src/hooks/useQuery.ts +74 -0
  65. package/dist/sdk/src/hooks/useTool.ts +65 -0
  66. package/dist/sdk/src/hooks/useToolQuery.ts +12 -0
  67. package/dist/sdk/src/hooks/useTopBarSearch.ts +81 -0
  68. package/dist/sdk/src/hooks/useUpsertDocument.ts +95 -0
  69. package/dist/sdk/src/hooks/useViewParams.ts +121 -0
  70. package/dist/sdk/src/hooks/useViewerReads.ts +129 -0
  71. package/dist/sdk/src/index.ts +200 -0
  72. package/dist/sdk/src/interactions/actions.ts +59 -0
  73. package/dist/sdk/src/interactions/shortcuts.tsx +740 -0
  74. package/dist/sdk/src/interactions/visibility.ts +13 -0
  75. package/dist/sdk/src/interactions.ts +45 -0
  76. package/dist/sdk/src/nativeData.ts +39 -0
  77. package/dist/sdk/src/presentation.tsx +82 -0
  78. package/dist/sdk/src/provider.tsx +49 -0
  79. package/dist/sdk/src/queryCache.ts +172 -0
  80. package/dist/sdk/src/queryErrors.ts +51 -0
  81. package/dist/sdk/src/runtime.ts +603 -0
  82. package/dist/sdk/src/space.ts +425 -0
  83. package/dist/sdk/src/styles.css +290 -0
  84. package/dist/sdk/src/tailwind.ts +66 -0
  85. package/dist/sdk/src/vite.ts +83 -0
  86. package/dist/skill-sync/index.js +2143 -0
  87. package/dist/skill-sync/index.js.map +7 -0
  88. package/dist/skill-sync-worker.mjs +3487 -0
  89. package/dist/space-harness/host.js +66 -0
  90. package/dist/view-renderer/dist/host.css +1 -0
  91. package/dist/view-renderer/dist/host.js +1042 -0
  92. package/dist/view-renderer/dist/theme.css +73 -0
  93. package/dist/view-renderer/src/dom.js +180 -0
  94. package/dist/view-renderer/src/errors.js +8 -0
  95. package/dist/view-renderer/src/host.tsx +173 -0
  96. package/dist/view-renderer/src/index.js +4 -0
  97. package/dist/view-renderer/src/pool.js +76 -0
  98. package/dist/view-renderer/src/remote-broker.js +59 -0
  99. package/dist/view-renderer/src/renderer.js +201 -0
  100. package/package.json +25 -8
  101. package/skills/notis-apps/cli.md +406 -0
  102. package/skills/notis-cli/AGENT_INSTRUCTIONS.md +39 -0
  103. package/skills/notis-onboarding/BRIEF.md +133 -0
  104. package/skills/notis-query/cli.md +39 -0
  105. package/src/agent-hook-entry.js +5 -0
  106. package/src/cli.js +294 -25
  107. package/src/command-specs/agents.js +392 -0
  108. package/src/command-specs/apps.js +1476 -203
  109. package/src/command-specs/auth.js +114 -137
  110. package/src/command-specs/diagnostics.js +730 -0
  111. package/src/command-specs/files.js +29 -0
  112. package/src/command-specs/handover.js +374 -0
  113. package/src/command-specs/helpers.js +86 -82
  114. package/src/command-specs/index.js +31 -6
  115. package/src/command-specs/meta.js +150 -18
  116. package/src/command-specs/onboarding.js +290 -0
  117. package/src/command-specs/profile.js +358 -0
  118. package/src/command-specs/skills.js +304 -0
  119. package/src/command-specs/smoke.js +386 -0
  120. package/src/command-specs/spaces.js +572 -0
  121. package/src/command-specs/tools.js +455 -139
  122. package/src/command-specs/views.js +69 -0
  123. package/src/runtime/agent-browser.js +700 -0
  124. package/src/runtime/agent-memory-state.js +126 -0
  125. package/src/runtime/agent-setup.js +383 -0
  126. package/src/runtime/app-boundary-validator.js +407 -0
  127. package/src/runtime/app-changelog.js +79 -0
  128. package/src/runtime/app-data-literals.js +82 -0
  129. package/src/runtime/app-platform.js +2752 -237
  130. package/src/runtime/app-registry-scaffolds.js +367 -0
  131. package/src/runtime/app-test-server.js +293 -0
  132. package/src/runtime/assets/store-screenshot-dark.png +0 -0
  133. package/src/runtime/auth-recovery.js +110 -0
  134. package/src/runtime/base-skills.d.ts +20 -0
  135. package/src/runtime/base-skills.js +167 -0
  136. package/src/runtime/channel.js +133 -0
  137. package/src/runtime/confined-space-build.js +74 -0
  138. package/src/runtime/confined-space-verify.js +49 -0
  139. package/src/runtime/delegated-context.js +68 -0
  140. package/src/runtime/errors.js +1 -0
  141. package/src/runtime/git.js +233 -0
  142. package/src/runtime/login-listener.js +15 -0
  143. package/src/runtime/native-record-files.js +47 -0
  144. package/src/runtime/oauth.js +2622 -0
  145. package/src/runtime/output.js +37 -5
  146. package/src/runtime/ports.js +31 -0
  147. package/src/runtime/profiles.js +906 -55
  148. package/src/runtime/retired-sdk-files.js +20 -0
  149. package/src/runtime/screenshot-framing.js +85 -0
  150. package/src/runtime/skill-sync/cloud-client.ts +121 -0
  151. package/src/runtime/skill-sync/index.ts +905 -0
  152. package/src/runtime/skill-sync/local-scanner.ts +1259 -0
  153. package/src/runtime/skill-sync/native-identity.ts +102 -0
  154. package/src/runtime/skill-sync/native-plan.ts +59 -0
  155. package/src/runtime/skill-sync/symlink-manager.ts +433 -0
  156. package/src/runtime/skill-sync/sync-plan.ts +54 -0
  157. package/src/runtime/skill-sync/types.ts +157 -0
  158. package/src/runtime/skill-sync/write-cloud-skill.ts +50 -0
  159. package/src/runtime/skill-sync-service.js +109 -0
  160. package/src/runtime/source-root.js +32 -0
  161. package/src/runtime/space-collection-scaffold.js +66 -0
  162. package/src/runtime/space-database-structures.js +229 -0
  163. package/src/runtime/space-fixture-broker.js +50 -0
  164. package/src/runtime/space-lock.js +337 -0
  165. package/src/runtime/space-platform.js +105 -0
  166. package/src/runtime/space-source.js +281 -0
  167. package/src/runtime/space-test-server.js +327 -0
  168. package/src/runtime/space-verification.js +89 -0
  169. package/src/runtime/space-verify-browser-worker.js +51 -0
  170. package/src/runtime/space-view-manifest.js +254 -0
  171. package/src/runtime/store-screenshot.js +146 -0
  172. package/src/runtime/sync-skills.d.ts +37 -0
  173. package/src/runtime/sync-skills.js +231 -0
  174. package/src/runtime/telemetry.js +92 -0
  175. package/src/runtime/transport.js +331 -45
  176. package/src/runtime/view-render.js +49 -0
  177. package/src/skill-sync-worker-entry.js +2 -0
  178. package/src/skill-sync-worker.js +50 -0
  179. package/src/space-harness-host.ts +103 -0
  180. package/template/.harness/index.html.tmpl +435 -0
  181. package/template/CHANGELOG.md +5 -0
  182. package/template/app/globals.css +29 -3
  183. package/template/app/layout.tsx +6 -3
  184. package/template/app/page.tsx +49 -42
  185. package/template/components/page-heading.tsx +23 -0
  186. package/template/components/ui/badge.tsx +7 -4
  187. package/template/components/ui/button.tsx +1 -1
  188. package/template/components/ui/card.tsx +24 -11
  189. package/template/components/ui/native-select.tsx +24 -0
  190. package/template/notis.config.ts +24 -6
  191. package/template/package-lock.json +3642 -0
  192. package/template/package.json +19 -16
  193. package/template/postcss.config.mjs +1 -1
  194. package/template/tailwind.config.ts +1 -6
  195. package/template/tsconfig.json +1 -0
  196. package/src/command-specs/db.js +0 -163
  197. package/src/runtime/app-preview-server.js +0 -312
  198. package/template/packages/notis-sdk/src/config.ts +0 -48
  199. package/template/packages/notis-sdk/src/helpers.ts +0 -131
  200. package/template/packages/notis-sdk/src/hooks/useAppState.ts +0 -50
  201. package/template/packages/notis-sdk/src/hooks/useCollectionItem.ts +0 -58
  202. package/template/packages/notis-sdk/src/hooks/useDatabase.ts +0 -87
  203. package/template/packages/notis-sdk/src/hooks/useDocument.ts +0 -61
  204. package/template/packages/notis-sdk/src/hooks/useNotis.ts +0 -31
  205. package/template/packages/notis-sdk/src/hooks/useNotisNavigation.ts +0 -49
  206. package/template/packages/notis-sdk/src/hooks/useTool.ts +0 -49
  207. package/template/packages/notis-sdk/src/hooks/useUpsertDocument.ts +0 -57
  208. package/template/packages/notis-sdk/src/index.ts +0 -47
  209. package/template/packages/notis-sdk/src/provider.tsx +0 -44
  210. package/template/packages/notis-sdk/src/runtime.ts +0 -159
  211. package/template/packages/notis-sdk/src/styles.css +0 -123
  212. package/template/packages/notis-sdk/src/vite.ts +0 -54
  213. package/template/packages/notis-sdk/tsconfig.json +0 -15
  214. /package/{template/packages/notis-sdk → dist/sdk}/src/hooks/useBackend.ts +0 -0
  215. /package/{template/packages/notis-sdk → dist/sdk}/src/hooks/useTools.ts +0 -0
  216. /package/{template/packages/notis-sdk → dist/sdk}/src/ui.ts +0 -0
@@ -1,131 +0,0 @@
1
- /**
2
- * Property extraction helpers for Notis DocumentRecord properties.
3
- *
4
- * Document properties come back in Notion-style nested shapes. These helpers
5
- * normalize them into simple JS values regardless of the shape.
6
- */
7
-
8
- import type { DocumentRecord } from './runtime';
9
-
10
- type Obj = Record<string, unknown>;
11
-
12
- /** Extract a string from a title, rich_text, or plain text property. */
13
- export function extractText(val: unknown): string {
14
- if (typeof val === 'string') return val;
15
- if (val && typeof val === 'object') {
16
- const obj = val as Obj;
17
- if (typeof obj.content === 'string') return obj.content;
18
- if (typeof obj.plain_text === 'string') return obj.plain_text;
19
- if (Array.isArray(obj.title)) {
20
- return obj.title.map((t: Obj) => extractText(t?.text || t)).join('');
21
- }
22
- if (Array.isArray(obj.rich_text)) {
23
- return obj.rich_text.map((t: Obj) => extractText(t?.text || t)).join('');
24
- }
25
- if (obj.text) return extractText(obj.text);
26
- }
27
- return '';
28
- }
29
-
30
- /** Extract a string from a select or status property. */
31
- export function extractSelect(val: unknown): string {
32
- if (typeof val === 'string') return val;
33
- if (val && typeof val === 'object') {
34
- const obj = val as Obj;
35
- if (obj.select && typeof obj.select === 'object') {
36
- return (obj.select as Obj).name as string || '';
37
- }
38
- if (obj.status && typeof obj.status === 'object') {
39
- return (obj.status as Obj).name as string || '';
40
- }
41
- if (typeof obj.name === 'string') return obj.name;
42
- }
43
- return '';
44
- }
45
-
46
- /** Extract a date string from a date property. */
47
- export function extractDate(val: unknown): string {
48
- if (typeof val === 'string') return val;
49
- if (val && typeof val === 'object') {
50
- const obj = val as Obj;
51
- if (obj.date && typeof obj.date === 'object') {
52
- return (obj.date as Obj).start as string || '';
53
- }
54
- if (typeof obj.start === 'string') return obj.start;
55
- }
56
- return '';
57
- }
58
-
59
- /** Extract a number from a number property. */
60
- export function extractNumber(val: unknown): number | null {
61
- if (typeof val === 'number') return val;
62
- if (val && typeof val === 'object') {
63
- const obj = val as Obj;
64
- if (typeof obj.number === 'number') return obj.number;
65
- }
66
- return null;
67
- }
68
-
69
- /** Extract a boolean from a checkbox property. */
70
- export function extractCheckbox(val: unknown): boolean {
71
- if (typeof val === 'boolean') return val;
72
- if (val && typeof val === 'object') {
73
- const obj = val as Obj;
74
- if (typeof obj.checkbox === 'boolean') return obj.checkbox;
75
- }
76
- return false;
77
- }
78
-
79
- /** Extract multi-select values as a string array. */
80
- export function extractMultiSelect(val: unknown): string[] {
81
- if (Array.isArray(val)) {
82
- return val
83
- .map((v) => {
84
- if (typeof v === 'string') return v;
85
- if (v && typeof v === 'object' && typeof (v as Obj).name === 'string') return (v as Obj).name as string;
86
- return '';
87
- })
88
- .filter(Boolean);
89
- }
90
- if (val && typeof val === 'object') {
91
- const obj = val as Obj;
92
- if (Array.isArray(obj.multi_select)) return extractMultiSelect(obj.multi_select);
93
- }
94
- if (typeof val === 'string' && val) return [val];
95
- return [];
96
- }
97
-
98
- /** Extract relation IDs from a relation property. */
99
- export function extractRelation(val: unknown): string[] {
100
- if (Array.isArray(val)) {
101
- return val
102
- .map((v) => {
103
- if (typeof v === 'string') return v;
104
- if (v && typeof v === 'object' && typeof (v as Obj).id === 'string') return (v as Obj).id as string;
105
- return '';
106
- })
107
- .filter(Boolean);
108
- }
109
- if (val && typeof val === 'object') {
110
- const obj = val as Obj;
111
- if (Array.isArray(obj.relation)) return extractRelation(obj.relation);
112
- }
113
- if (typeof val === 'string' && val) return [val];
114
- return [];
115
- }
116
-
117
- /**
118
- * Extract display title from a document. Falls back through several property
119
- * names and shapes to find a human-readable title.
120
- */
121
- export function docTitle(doc: DocumentRecord): string {
122
- const t = doc.title;
123
- if (t && !/^[0-9a-f]{8}-[0-9a-f]{4}/.test(t)) return t;
124
- const p = doc.properties || {};
125
- const name = p.Name ?? p.name ?? p.Title ?? p.title;
126
- if (name) {
127
- const extracted = extractText(name);
128
- if (extracted) return extracted;
129
- }
130
- return t || 'Untitled';
131
- }
@@ -1,50 +0,0 @@
1
- 'use client';
2
-
3
- import { useCallback, useState } from 'react';
4
- import { useNotisRuntime } from '../provider';
5
-
6
- /**
7
- * Persist app-level state per user per app using localStorage.
8
- *
9
- * ```tsx
10
- * const [order, setOrder] = useAppState<string[]>('task-order', []);
11
- * ```
12
- *
13
- * State is scoped by `app.id` so different apps don't collide.
14
- * Falls back to defaultValue when localStorage is unavailable.
15
- */
16
- export function useAppState<T>(key: string, defaultValue: T): [T, (value: T | ((prev: T) => T)) => void] {
17
- const runtime = useNotisRuntime();
18
- const appId = runtime?.app?.id || '_unknown';
19
- const storageKey = `notis-app-state:${appId}:${key}`;
20
-
21
- const [value, setValueInternal] = useState<T>(() => {
22
- if (typeof window === 'undefined') return defaultValue;
23
- try {
24
- const stored = localStorage.getItem(storageKey);
25
- if (stored !== null) return JSON.parse(stored) as T;
26
- } catch {
27
- // Ignore parse errors or storage unavailable
28
- }
29
- return defaultValue;
30
- });
31
-
32
- const setValue = useCallback(
33
- (newValue: T | ((prev: T) => T)) => {
34
- setValueInternal((prev) => {
35
- const resolved = typeof newValue === 'function'
36
- ? (newValue as (prev: T) => T)(prev)
37
- : newValue;
38
- try {
39
- localStorage.setItem(storageKey, JSON.stringify(resolved));
40
- } catch {
41
- // Ignore quota errors
42
- }
43
- return resolved;
44
- });
45
- },
46
- [storageKey],
47
- );
48
-
49
- return [value, setValue];
50
- }
@@ -1,58 +0,0 @@
1
- 'use client';
2
-
3
- import { useEffect, useState } from 'react';
4
- import { useNotisRuntime } from '../provider';
5
- import type { CollectionItem } from '../runtime';
6
-
7
- interface UseCollectionResult {
8
- /** Items in the collection (from the bound database). */
9
- items: CollectionItem[];
10
- loading: boolean;
11
- error: Error | null;
12
- }
13
-
14
- /**
15
- * List collection items for the current route. Only meaningful on routes
16
- * that have a `collection` binding in `notis.config.ts`.
17
- *
18
- * ```tsx
19
- * const { items, loading } = useCollectionItems();
20
- * ```
21
- */
22
- export function useCollectionItems(): UseCollectionResult {
23
- const runtime = useNotisRuntime();
24
- const [items, setItems] = useState<CollectionItem[]>([]);
25
- const [loading, setLoading] = useState(true);
26
- const [error, setError] = useState<Error | null>(null);
27
-
28
- useEffect(() => {
29
- if (!runtime) {
30
- setLoading(false);
31
- return;
32
- }
33
-
34
- let cancelled = false;
35
- setLoading(true);
36
-
37
- runtime
38
- .listCollectionItems()
39
- .then((result) => {
40
- if (!cancelled) {
41
- setItems(result.items);
42
- setLoading(false);
43
- }
44
- })
45
- .catch((err) => {
46
- if (!cancelled) {
47
- setError(err instanceof Error ? err : new Error(String(err)));
48
- setLoading(false);
49
- }
50
- });
51
-
52
- return () => {
53
- cancelled = true;
54
- };
55
- }, [runtime]);
56
-
57
- return { items, loading, error };
58
- }
@@ -1,87 +0,0 @@
1
- 'use client';
2
-
3
- import { useCallback, useEffect, useState } from 'react';
4
- import { useNotisRuntime } from '../provider';
5
- import type { DocumentRecord, QueryFilter } from '../runtime';
6
-
7
- interface UseDatabaseOptions {
8
- filter?: QueryFilter;
9
- pageSize?: number;
10
- offset?: number;
11
- /** Set to false to skip the initial fetch. */
12
- enabled?: boolean;
13
- }
14
-
15
- interface UseDatabaseResult {
16
- documents: DocumentRecord[];
17
- loading: boolean;
18
- error: Error | null;
19
- refetch: () => void;
20
- }
21
-
22
- /**
23
- * Query documents from a Notis database owned by this app.
24
- *
25
- * ```tsx
26
- * const { documents, loading } = useDatabase('transactions', {
27
- * filter: { sorts: [{ property: 'date', direction: 'desc' }] },
28
- * pageSize: 20,
29
- * });
30
- * ```
31
- */
32
- export function useDatabase(
33
- databaseSlug: string,
34
- options: UseDatabaseOptions = {},
35
- ): UseDatabaseResult {
36
- const runtime = useNotisRuntime();
37
- const [documents, setDocuments] = useState<DocumentRecord[]>([]);
38
- const [loading, setLoading] = useState(true);
39
- const [error, setError] = useState<Error | null>(null);
40
- const [fetchKey, setFetchKey] = useState(0);
41
-
42
- const enabled = options.enabled !== false;
43
-
44
- const refetch = useCallback(() => {
45
- setFetchKey((k) => k + 1);
46
- }, []);
47
-
48
- useEffect(() => {
49
- if (!runtime || !enabled) {
50
- setLoading(false);
51
- return;
52
- }
53
-
54
- let cancelled = false;
55
- setLoading(true);
56
- setError(null);
57
-
58
- runtime
59
- .queryDatabase({
60
- databaseSlug,
61
- query: {
62
- ...options.filter,
63
- page_size: options.pageSize,
64
- },
65
- offset: options.offset,
66
- })
67
- .then((result) => {
68
- if (!cancelled) {
69
- setDocuments(result.documents);
70
- setLoading(false);
71
- }
72
- })
73
- .catch((err) => {
74
- if (!cancelled) {
75
- setError(err instanceof Error ? err : new Error(String(err)));
76
- setLoading(false);
77
- }
78
- });
79
-
80
- return () => {
81
- cancelled = true;
82
- };
83
- // eslint-disable-next-line react-hooks/exhaustive-deps
84
- }, [runtime, databaseSlug, fetchKey, enabled]);
85
-
86
- return { documents, loading, error, refetch };
87
- }
@@ -1,61 +0,0 @@
1
- 'use client';
2
-
3
- import { useCallback, useEffect, useState } from 'react';
4
- import { useNotisRuntime } from '../provider';
5
- import type { DocumentRecord } from '../runtime';
6
-
7
- interface UseDocumentResult {
8
- document: DocumentRecord | null;
9
- loading: boolean;
10
- error: Error | null;
11
- refetch: () => void;
12
- }
13
-
14
- /**
15
- * Fetch a single document by ID.
16
- *
17
- * ```tsx
18
- * const { document, loading } = useDocument(documentId);
19
- * ```
20
- */
21
- export function useDocument(documentId: string | null | undefined): UseDocumentResult {
22
- const runtime = useNotisRuntime();
23
- const [document, setDocument] = useState<DocumentRecord | null>(null);
24
- const [loading, setLoading] = useState(true);
25
- const [error, setError] = useState<Error | null>(null);
26
- const [fetchKey, setFetchKey] = useState(0);
27
-
28
- const refetch = useCallback(() => setFetchKey((k) => k + 1), []);
29
-
30
- useEffect(() => {
31
- if (!runtime || !documentId) {
32
- setLoading(false);
33
- return;
34
- }
35
-
36
- let cancelled = false;
37
- setLoading(true);
38
- setError(null);
39
-
40
- runtime
41
- .getDocument({ documentId })
42
- .then((result) => {
43
- if (!cancelled) {
44
- setDocument(result);
45
- setLoading(false);
46
- }
47
- })
48
- .catch((err) => {
49
- if (!cancelled) {
50
- setError(err instanceof Error ? err : new Error(String(err)));
51
- setLoading(false);
52
- }
53
- });
54
-
55
- return () => {
56
- cancelled = true;
57
- };
58
- }, [runtime, documentId, fetchKey]);
59
-
60
- return { document, loading, error, refetch };
61
- }
@@ -1,31 +0,0 @@
1
- 'use client';
2
-
3
- import { useNotisRuntime } from '../provider';
4
- import type { AppDescriptor, RouteDescriptor, DatabaseDescriptor } from '../runtime';
5
-
6
- interface NotisContext {
7
- /** App metadata (id, name, icon, description). Null before runtime loads. */
8
- app: AppDescriptor | null;
9
- /** Current route descriptor. Null before runtime loads. */
10
- route: RouteDescriptor | null;
11
- /** Databases declared by this app. Empty before runtime loads. */
12
- databases: DatabaseDescriptor[];
13
- /** Whether the runtime is loaded and available. */
14
- ready: boolean;
15
- }
16
-
17
- /**
18
- * Access app-level metadata: the app descriptor, current route, and declared
19
- * databases. Returns safe defaults when the runtime isn't available (SSR or
20
- * during `next dev` without preview).
21
- */
22
- export function useNotis(): NotisContext {
23
- const runtime = useNotisRuntime();
24
-
25
- return {
26
- app: runtime?.app ?? null,
27
- route: runtime?.route ?? null,
28
- databases: runtime?.databases ?? [],
29
- ready: runtime !== null,
30
- };
31
- }
@@ -1,49 +0,0 @@
1
- 'use client';
2
-
3
- import { useCallback } from 'react';
4
- import { useNotisRuntime } from '../provider';
5
-
6
- interface NavigationActions {
7
- /** Navigate to a route within the app by its path. */
8
- toRoute: (path: string) => void;
9
- /** Navigate to a document detail view. */
10
- toDocument: (documentId: string) => void;
11
- /** Navigate to the app's default route. */
12
- toApp: () => void;
13
- }
14
-
15
- /**
16
- * Navigation helpers for moving between routes and documents within the app.
17
- * When rendered inside the portal, uses the runtime.navigate() bridge.
18
- * In local preview, falls back to window.location.
19
- *
20
- * ```tsx
21
- * const nav = useNotisNavigation();
22
- * nav.toRoute('/settings');
23
- * ```
24
- */
25
- export function useNotisNavigation(): NavigationActions {
26
- const runtime = useNotisRuntime();
27
-
28
- const toRoute = useCallback((path: string) => {
29
- if (runtime?.navigate) {
30
- runtime.navigate({ kind: 'route', path });
31
- } else if (typeof window !== 'undefined') {
32
- window.location.href = path;
33
- }
34
- }, [runtime]);
35
-
36
- const toDocument = useCallback((documentId: string) => {
37
- if (runtime?.navigate) {
38
- runtime.navigate({ kind: 'document', documentId });
39
- }
40
- }, [runtime]);
41
-
42
- const toApp = useCallback(() => {
43
- if (runtime?.navigate) {
44
- runtime.navigate({ kind: 'app' });
45
- }
46
- }, [runtime]);
47
-
48
- return { toRoute, toDocument, toApp };
49
- }
@@ -1,49 +0,0 @@
1
- 'use client';
2
-
3
- import { useCallback, useState } from 'react';
4
- import { useNotisRuntime } from '../provider';
5
-
6
- interface UseToolResult {
7
- call: (args?: Record<string, unknown>) => Promise<unknown>;
8
- loading: boolean;
9
- error: Error | null;
10
- }
11
-
12
- /**
13
- * Call a specific Notis tool by name.
14
- *
15
- * ```tsx
16
- * const { call, loading } = useTool('notis_web_search');
17
- * const result = await call({ query: 'latest news' });
18
- * ```
19
- */
20
- export function useTool(toolName: string): UseToolResult {
21
- const runtime = useNotisRuntime();
22
- const [loading, setLoading] = useState(false);
23
- const [error, setError] = useState<Error | null>(null);
24
-
25
- const call = useCallback(
26
- async (args?: Record<string, unknown>): Promise<unknown> => {
27
- if (!runtime) {
28
- throw new Error('Notis runtime not available. Ensure NotisProvider is mounted.');
29
- }
30
-
31
- setLoading(true);
32
- setError(null);
33
-
34
- try {
35
- const result = await runtime.callTool(toolName, args);
36
- return result;
37
- } catch (err) {
38
- const e = err instanceof Error ? err : new Error(String(err));
39
- setError(e);
40
- throw e;
41
- } finally {
42
- setLoading(false);
43
- }
44
- },
45
- [runtime, toolName],
46
- );
47
-
48
- return { call, loading, error };
49
- }
@@ -1,57 +0,0 @@
1
- 'use client';
2
-
3
- import { useCallback, useState } from 'react';
4
- import { useNotisRuntime } from '../provider';
5
- import type { DocumentRecord } from '../runtime';
6
-
7
- interface UpsertArgs {
8
- databaseSlug: string;
9
- documentId?: string;
10
- title?: string;
11
- properties?: Record<string, unknown>;
12
- }
13
-
14
- interface UseUpsertDocumentResult {
15
- upsert: (args: UpsertArgs) => Promise<DocumentRecord>;
16
- loading: boolean;
17
- error: Error | null;
18
- }
19
-
20
- /**
21
- * Create or update a document in a Notis database.
22
- *
23
- * ```tsx
24
- * const { upsert, loading } = useUpsertDocument();
25
- * await upsert({ databaseSlug: 'tasks', title: 'New task', properties: { status: 'Open' } });
26
- * ```
27
- */
28
- export function useUpsertDocument(): UseUpsertDocumentResult {
29
- const runtime = useNotisRuntime();
30
- const [loading, setLoading] = useState(false);
31
- const [error, setError] = useState<Error | null>(null);
32
-
33
- const upsert = useCallback(
34
- async (args: UpsertArgs): Promise<DocumentRecord> => {
35
- if (!runtime) {
36
- throw new Error('Notis runtime not available. Ensure NotisProvider is mounted.');
37
- }
38
-
39
- setLoading(true);
40
- setError(null);
41
-
42
- try {
43
- const result = await runtime.upsertDocument(args);
44
- return result.document;
45
- } catch (err) {
46
- const e = err instanceof Error ? err : new Error(String(err));
47
- setError(e);
48
- throw e;
49
- } finally {
50
- setLoading(false);
51
- }
52
- },
53
- [runtime],
54
- );
55
-
56
- return { upsert, loading, error };
57
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * @notis/sdk - The Notis App SDK
3
- *
4
- * Public API for building Notis apps. Import hooks and the provider from
5
- * this entrypoint. For configuration, use `@notis/sdk/config`. For the
6
- * Vite config builder, use `@notis/sdk/vite`.
7
- */
8
-
9
- // Provider
10
- export { NotisProvider, useNotisRuntime } from './provider';
11
-
12
- // Hooks
13
- export { useNotis } from './hooks/useNotis';
14
- export { useDatabase } from './hooks/useDatabase';
15
- export { useDocument } from './hooks/useDocument';
16
- export { useUpsertDocument } from './hooks/useUpsertDocument';
17
- export { useTool } from './hooks/useTool';
18
- export { useTools } from './hooks/useTools';
19
- export { useCollectionItems } from './hooks/useCollectionItem';
20
- export { useNotisNavigation } from './hooks/useNotisNavigation';
21
- export { useBackend } from './hooks/useBackend';
22
- export { useAppState } from './hooks/useAppState';
23
-
24
- // Property extraction helpers
25
- export {
26
- extractText,
27
- extractSelect,
28
- extractDate,
29
- extractNumber,
30
- extractCheckbox,
31
- extractMultiSelect,
32
- extractRelation,
33
- docTitle,
34
- } from './helpers';
35
-
36
- // Types (re-exported for convenience)
37
- export type {
38
- AppDescriptor,
39
- CollectionItem,
40
- DatabaseDescriptor,
41
- DatabaseProperty,
42
- DocumentRecord,
43
- NotisRuntime,
44
- QueryFilter,
45
- RouteDescriptor,
46
- ToolDescriptor,
47
- } from './runtime';
@@ -1,44 +0,0 @@
1
- 'use client';
2
-
3
- import React, { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
4
- import type { NotisRuntime } from './runtime';
5
- import { getRuntime } from './runtime';
6
-
7
- const NotisContext = createContext<NotisRuntime | null>(null);
8
-
9
- /**
10
- * Provides the Notis runtime context to all child components. Place this in
11
- * your root layout so that hooks like useDatabase, useTool, etc. can access
12
- * the platform bridge.
13
- *
14
- * During `next dev` (no runtime injected), hooks return safe defaults (empty
15
- * arrays, null values). During `notis apps preview` and in the portal, the
16
- * runtime is fully functional.
17
- */
18
- export function NotisProvider({ children, runtime }: { children: ReactNode; runtime?: NotisRuntime | null }) {
19
- const [resolvedRuntime, setResolvedRuntime] = useState<NotisRuntime | null>(runtime ?? null);
20
-
21
- useEffect(() => {
22
- // If runtime was passed as a prop (portal component rendering), use it directly.
23
- // Otherwise fall back to window.__NOTIS_RUNTIME__ (local dev / preview).
24
- if (runtime !== undefined) {
25
- setResolvedRuntime(runtime);
26
- } else {
27
- setResolvedRuntime(getRuntime());
28
- }
29
- }, [runtime]);
30
-
31
- return (
32
- <NotisContext.Provider value={resolvedRuntime}>
33
- {children}
34
- </NotisContext.Provider>
35
- );
36
- }
37
-
38
- /**
39
- * Returns the raw NotisRuntime or null if not yet available.
40
- * Prefer the typed hooks (useDatabase, useTool, etc.) over this.
41
- */
42
- export function useNotisRuntime(): NotisRuntime | null {
43
- return useContext(NotisContext);
44
- }