@notis_ai/cli 0.2.24 → 0.2.26
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.
- package/README.md +186 -5
- package/config/notis_app_design_rules.json +36 -14
- package/config/portal-route-roots.json +1 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +2784 -541
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/references/intelligence.md +1 -1
- package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-query/SKILL.md +0 -1
- package/dist/base-skills/notis-query/references/documents.md +7 -0
- package/dist/base-skills/notis-query/references/query.md +1 -0
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +96 -24
- package/dist/base-skills/notis-spaces/references/architecture.md +4 -3
- package/dist/base-skills/notis-spaces/references/design.md +37 -18
- package/dist/base-skills/notis-spaces/references/reading.md +8 -1
- package/dist/base-skills/notis-spaces/references/reports.md +6 -6
- package/dist/base-skills/notis-spaces/references/sdk.md +71 -7
- package/dist/base-skills/notis-spaces/references/store.md +22 -13
- package/dist/base-skills/notis-spaces/references/views.md +99 -6
- package/dist/sdk/package.json +3 -0
- package/dist/sdk/src/cloudComputerWords.ts +53 -0
- package/dist/sdk/src/components/Audience.tsx +76 -0
- package/dist/sdk/src/components/DocumentPage.tsx +15 -4
- package/dist/sdk/src/components/MarkdownEditor.tsx +44 -14
- package/dist/sdk/src/components/MultiSelectActionBar.tsx +16 -5
- package/dist/sdk/src/components/Skeleton.tsx +162 -6
- package/dist/sdk/src/hooks/useAction.ts +12 -2
- package/dist/sdk/src/hooks/useAgentQueue.ts +125 -0
- package/dist/sdk/src/hooks/useCloudComputerJob.ts +142 -0
- package/dist/sdk/src/hooks/useCloudComputerService.ts +388 -0
- package/dist/sdk/src/hooks/useCloudComputerShell.ts +95 -7
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +40 -2
- package/dist/sdk/src/hooks/useItemThread.ts +58 -0
- package/dist/sdk/src/hooks/useMarqueeSelection.ts +6 -1
- package/dist/sdk/src/hooks/useNativeDocuments.ts +61 -8
- package/dist/sdk/src/hooks/useNotisNavigation.ts +31 -8
- package/dist/sdk/src/hooks/useQuery.ts +67 -10
- package/dist/sdk/src/hooks/useViewParams.ts +47 -11
- package/dist/sdk/src/index.ts +31 -4
- package/dist/sdk/src/interactions.ts +2 -0
- package/dist/sdk/src/nativeData.ts +2 -0
- package/dist/sdk/src/optimisticRows.ts +329 -0
- package/dist/sdk/src/perf.ts +188 -0
- package/dist/sdk/src/provider.tsx +2 -1
- package/dist/sdk/src/queryCache.ts +366 -17
- package/dist/sdk/src/runtime.ts +55 -4
- package/dist/sdk/src/skeleton.ts +103 -0
- package/dist/sdk/src/space.ts +662 -28
- package/dist/sdk/src/spacePublicUI.ts +36 -0
- package/dist/sdk/src/ui/engine/step.ts +54 -0
- package/dist/sdk/src/ui/icons.tsx +3 -1
- package/dist/sdk/src/words/shell.ts +1 -0
- package/dist/skill-sync/index.js +7 -2
- package/dist/skill-sync-worker.mjs +40 -26
- package/dist/space-harness/host.js +272 -105
- package/dist/space-sdk/dist/chunk-BWHAORT4.js +5 -0
- package/dist/space-sdk/dist/index.js +9 -4
- package/dist/space-sdk/dist/ui.js +12 -12
- package/dist/space-sdk/package.json +3 -0
- package/dist/space-sdk/src/cloudComputerWords.d.ts +34 -0
- package/dist/space-sdk/src/components/Audience.d.ts +46 -0
- package/dist/space-sdk/src/components/DocumentPage.d.ts +3 -1
- package/dist/space-sdk/src/components/MarkdownEditor.d.ts +21 -0
- package/dist/space-sdk/src/components/MultiSelectActionBar.d.ts +5 -1
- package/dist/space-sdk/src/components/Skeleton.d.ts +7 -2
- package/dist/space-sdk/src/hooks/useAction.d.ts +8 -1
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +61 -0
- package/dist/space-sdk/src/hooks/useCloudComputerJob.d.ts +35 -0
- package/dist/space-sdk/src/hooks/useCloudComputerService.d.ts +75 -0
- package/dist/space-sdk/src/hooks/useCloudComputerShell.d.ts +36 -3
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +6 -0
- package/dist/space-sdk/src/hooks/useItemThread.d.ts +32 -0
- package/dist/space-sdk/src/hooks/useMarqueeSelection.d.ts +2 -1
- package/dist/space-sdk/src/hooks/useNativeDocumentBody.d.ts +1 -0
- package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +20 -5
- package/dist/space-sdk/src/hooks/useNotisNavigation.d.ts +11 -2
- package/dist/space-sdk/src/hooks/useQuery.d.ts +24 -2
- package/dist/space-sdk/src/hooks/useViewParams.d.ts +2 -0
- package/dist/space-sdk/src/index.d.ts +24 -4
- package/dist/space-sdk/src/nativeData.d.ts +6 -0
- package/dist/space-sdk/src/queryCache.d.ts +97 -2
- package/dist/space-sdk/src/runtime.d.ts +53 -4
- package/dist/space-sdk/src/skeleton.d.ts +42 -0
- package/dist/space-sdk/src/space.ts +662 -28
- package/dist/space-sdk/src/tailwind-candidates.d.ts +754 -5
- package/dist/space-sdk/src/ui/cloud/CloudComputerFrame.d.ts +29 -0
- package/dist/space-sdk/src/ui/cloud/CloudComputerWaking.d.ts +20 -0
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +15 -2
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +50 -0
- package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +64 -0
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +49 -1
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +26 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +82 -0
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +34 -4
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +67 -0
- package/dist/space-sdk/src/ui/engine/index.d.ts +2 -2
- package/dist/space-sdk/src/ui/engine/step.d.ts +9 -0
- package/dist/space-sdk/src/ui/fields/fields.d.ts +2 -1
- package/dist/space-sdk/src/ui/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/layout/Panels.d.ts +9 -2
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +42 -0
- package/dist/space-sdk/src/ui/layout/index.d.ts +2 -1
- package/dist/space-sdk/src/ui/layout/panelMath.d.ts +11 -2
- package/dist/space-sdk/src/ui/list/ListReader.d.ts +38 -7
- package/dist/space-sdk/src/ui/list/Row.d.ts +4 -0
- package/dist/space-sdk/src/ui/list/SelectionBar.d.ts +9 -4
- package/dist/space-sdk/src/ui/list/useListKeys.d.ts +4 -0
- package/dist/space-sdk/src/words/shell.ts +1 -0
- package/dist/view-renderer/dist/host.js +355 -188
- package/dist/view-renderer/dist/theme.css +1 -1
- package/dist/view-renderer/src/host.tsx +4 -1
- package/dist/view-renderer/src/index.js +3 -0
- package/dist/view-renderer/src/pool.js +8 -4
- package/dist/view-renderer/src/renderer.js +92 -23
- package/dist/view-renderer/src/skeleton.js +450 -0
- package/package.json +4 -4
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +8 -4
- package/skills/notis-onboarding/BRIEF.md +15 -9
- package/skills/notis-spaces/cli.md +43 -4
- package/src/command-specs/auth.js +5 -3
- package/src/command-specs/cc.js +410 -0
- package/src/command-specs/computer.js +320 -0
- package/src/command-specs/diagnostics.js +2 -13
- package/src/command-specs/documents.js +22 -4
- package/src/command-specs/index.js +7 -0
- package/src/command-specs/onboarding.js +127 -7
- package/src/command-specs/skills.js +2 -2
- package/src/command-specs/spaces.js +162 -30
- package/src/command-specs/tools.js +26 -8
- package/src/command-specs/views.js +4 -1
- package/src/runtime/agent-setup.js +20 -2
- package/src/runtime/app-boundary-validator.js +2 -1
- package/src/runtime/app-platform.js +13 -0
- package/src/runtime/auth-recovery.js +5 -0
- package/src/runtime/channel.js +16 -2
- package/src/runtime/cloud-transfer.js +587 -0
- package/src/runtime/computer-ssh.js +127 -0
- package/src/runtime/oauth.js +50 -4
- package/src/runtime/skill-sync/index.ts +20 -1
- package/src/runtime/skill-sync/local-scanner.ts +1 -0
- package/src/runtime/skill-sync/types.ts +2 -0
- package/src/runtime/space-audience.js +94 -0
- package/src/runtime/space-collection-scaffold.js +2 -1
- package/src/runtime/space-fixture-broker.js +2 -1
- package/src/runtime/space-lock.js +1 -4
- package/src/runtime/space-platform.js +18 -2
- package/src/runtime/space-source.js +105 -7
- package/src/runtime/space-test-server.js +13 -2
- package/src/runtime/space-verification.js +99 -6
- package/src/runtime/space-view-manifest.js +22 -4
- package/src/runtime/sync-skills.js +24 -20
- package/src/runtime/transport.js +19 -0
- package/src/runtime/view-render.js +2 -2
- package/template/.harness/index.html.tmpl +1 -1
- package/dist/skill-sync/index.js.map +0 -7
- package/dist/space-sdk/dist/chunk-SVZATGZB.js +0 -5
package/dist/sdk/src/space.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Portable Space source contracts. Grants and account identities are host-owned. */
|
|
2
|
-
import type { NotisRuntime, ToolInputSchema } from './runtime';
|
|
2
|
+
import type { HandoverPayload, NotisRuntime, NotisRuntimeUI, SubscribeDatabaseOptions, ToolInputSchema } from './runtime';
|
|
3
3
|
import type { NativeFilter, NativeMutationReceipt, NativeQuery } from './nativeData';
|
|
4
4
|
import { SdkQueryError, type QueryErrorKey } from './queryErrors';
|
|
5
5
|
|
|
@@ -10,6 +10,8 @@ export interface SpaceActionTemplate {
|
|
|
10
10
|
tool: string;
|
|
11
11
|
inputs: ToolInputSchema;
|
|
12
12
|
arguments: Record<string, SpaceJson>;
|
|
13
|
+
/** Only the Space's editors can call it; the public never sees it. Default: public. */
|
|
14
|
+
editorsOnly?: true;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -25,11 +27,85 @@ export const SPACE_VIEWER_READ_OPERATIONS: Readonly<Record<SpaceViewerReadOperat
|
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* Space cloud computer access, declared as `cloudComputer` in `defineSpace`.
|
|
28
|
-
* `read`: facts
|
|
29
|
-
* cloud computer, after that viewer allows it; never on a Site, a link or an
|
|
30
|
+
* `read`: facts and the Space folder. `shell`: also commands, background jobs, file writes and services.
|
|
31
|
+
* Always the signed-in viewer's own cloud computer, after that viewer allows it; never on a Site, a link or an
|
|
32
|
+
* agent render.
|
|
30
33
|
*/
|
|
31
34
|
export type SpaceCloudComputerLevel = 'read' | 'shell';
|
|
32
|
-
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* One agent a Space's database changes wake, declared in `defineSpace({ agents })`.
|
|
38
|
+
* `thread`: `best_match` (the person's thread linked to the item, else a new one linked to it) or `space`
|
|
39
|
+
* (one thread per Space and person). `runtime`: hosted (`notis`) or a coding agent on the person's Cloud
|
|
40
|
+
* Computer. `wake: 'sent'` wakes only for replies to and answers on the agent's own comments.
|
|
41
|
+
* `columns` renames the comment columns read (defaults: Thread, Deck, Answer, Author).
|
|
42
|
+
*/
|
|
43
|
+
export interface SpaceAgentDeclaration {
|
|
44
|
+
id: string;
|
|
45
|
+
on: { database: string; event?: 'created' | 'changed' };
|
|
46
|
+
thread?: 'best_match' | 'space';
|
|
47
|
+
runtime?: 'notis' | 'cloud_computer';
|
|
48
|
+
skill?: string;
|
|
49
|
+
wake?: 'all' | 'sent';
|
|
50
|
+
columns?: { thread?: string; scope?: string; answer?: string; author?: string };
|
|
51
|
+
}
|
|
52
|
+
/** The thread an item (a record, or the Space itself) continues, from the Space's thread rule. */
|
|
53
|
+
export interface SpaceItemThread {
|
|
54
|
+
/** Null when nothing matches yet: the first message creates the thread and links it to the item. */
|
|
55
|
+
thread_id: string | null;
|
|
56
|
+
rule: 'best_match' | 'space';
|
|
57
|
+
/** How closely the thread matches: record, view_params, view, space; null when none. */
|
|
58
|
+
level: 'record' | 'view_params' | 'view' | 'space' | null;
|
|
59
|
+
}
|
|
60
|
+
/** One Space agent's latest wake-up for the viewer (`useAgentQueue`). */
|
|
61
|
+
export interface SpaceAgentQueue {
|
|
62
|
+
status: 'idle' | 'queued' | 'working' | 'waiting' | 'failed' | 'done';
|
|
63
|
+
thread_id: string | null;
|
|
64
|
+
/** Items waiting in the quiet window or held for approval. */
|
|
65
|
+
pending: number;
|
|
66
|
+
/** True until the viewer allows this exact version's agents to wake their threads. */
|
|
67
|
+
approval_required: boolean;
|
|
68
|
+
updated_at: string | null;
|
|
69
|
+
}
|
|
70
|
+
export interface SpaceAgentsStatus {
|
|
71
|
+
declared: string[];
|
|
72
|
+
approved: boolean;
|
|
73
|
+
queue?: SpaceAgentQueue;
|
|
74
|
+
}
|
|
75
|
+
/** Space-only transport of the thread resolver and the agents' queue. */
|
|
76
|
+
export interface SpaceThreadsTransport {
|
|
77
|
+
resolve(input?: { recordKey?: string }): Promise<SpaceItemThread>;
|
|
78
|
+
/** Open a thread in the host's side chat, optionally with an unsent draft. */
|
|
79
|
+
open(threadId: string, options?: { draft?: string }): Promise<boolean>;
|
|
80
|
+
agentStatus(agentId: string, scope?: string): Promise<SpaceAgentsStatus>;
|
|
81
|
+
approveAgents(): Promise<{ approved: boolean; released: number }>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A long-running program the Space keeps up on the viewer's cloud computer while the page is on screen (a dev
|
|
85
|
+
* server, a media server). It runs with `bash -lc`, listens on `127.0.0.1:$PORT`, and gets `HOST`,
|
|
86
|
+
* `NOTIS_SPACE_DIR`, `NOTIS_SPACE_ID` and `NOTIS_SERVICE_ID`. Reach it with `useCloudComputerService(id)`.
|
|
87
|
+
*/
|
|
88
|
+
export interface SpaceCloudComputerService {
|
|
89
|
+
/** `/^[a-z][a-z0-9-]{0,39}$/`, unique in the Space. */
|
|
90
|
+
id: string;
|
|
91
|
+
/** Non-empty, at most 4096 characters. */
|
|
92
|
+
command: string;
|
|
93
|
+
/** A machine path (relative to /vercel/sandbox or absolute inside it) or `{ space: '<rel>' }` in the Space folder. Default: the Space folder. */
|
|
94
|
+
cwd?: string | { space: string };
|
|
95
|
+
/** Readiness path, starting with `/`; default `/`. */
|
|
96
|
+
ready?: string;
|
|
97
|
+
}
|
|
98
|
+
/** The object form of `cloudComputer`; `'read'` and `'shell'` mean `{ access: <level> }`. */
|
|
99
|
+
export interface SpaceCloudComputerDeclaration {
|
|
100
|
+
access: SpaceCloudComputerLevel;
|
|
101
|
+
/** Needs `access: 'shell'`; at most 4. */
|
|
102
|
+
services?: readonly SpaceCloudComputerService[];
|
|
103
|
+
}
|
|
104
|
+
export type SpaceCloudComputerJobOperation = 'job.status' | 'job.logs' | 'job.cancel';
|
|
105
|
+
/** A direct transfer session: the host uses these for `upload({ file })`; a page never calls them itself. */
|
|
106
|
+
export type SpaceCloudComputerTransferOperation = 'transfer.begin' | 'transfer.status' | 'transfer.commit' | 'transfer.abort';
|
|
107
|
+
export type SpaceCloudComputerOperation = 'facts' | 'run' | 'upload' | SpaceCloudComputerJobOperation | 'service.lease'
|
|
108
|
+
| 'service.access' | 'folder' | SpaceCloudComputerTransferOperation | 'import';
|
|
33
109
|
export interface SpaceCloudComputerStatus {
|
|
34
110
|
level: SpaceCloudComputerLevel;
|
|
35
111
|
approved: boolean;
|
|
@@ -47,7 +123,13 @@ export interface SpaceCloudComputerRelease {
|
|
|
47
123
|
copied: boolean;
|
|
48
124
|
}
|
|
49
125
|
export interface SpaceCloudComputerRunInput {
|
|
50
|
-
command: string;
|
|
126
|
+
command: string;
|
|
127
|
+
/** A machine path, or `{ space: '<rel>' }` inside the Space folder (`''` is its root). Without it a run starts in /vercel/sandbox. */
|
|
128
|
+
cwd?: string | { space: string };
|
|
129
|
+
/** With `detach`, bounds the background job: 1000 to 21600000 (6 h), default 3600000. */
|
|
130
|
+
timeout_ms?: number; max_output_length?: number;
|
|
131
|
+
/** Start the command as a background job and answer at once with `job_id` and `job`. */
|
|
132
|
+
detach?: boolean;
|
|
51
133
|
/**
|
|
52
134
|
* One key per run, kept when the page retries that run: a key that already reached the cloud computer is
|
|
53
135
|
* never run again (`cloud_computer_already_ran`). The host makes one when absent and keeps it for a retry
|
|
@@ -58,28 +140,204 @@ export interface SpaceCloudComputerRunInput {
|
|
|
58
140
|
export interface SpaceCloudComputerRunResult {
|
|
59
141
|
status?: 'success' | 'error' | string; stdout?: string; stderr?: string; exit_code?: number;
|
|
60
142
|
message?: string; code?: string; truncated?: boolean;
|
|
143
|
+
/** A detached run: the background job it started. */
|
|
144
|
+
job_id?: string; job?: SpaceCloudComputerJobStatus;
|
|
145
|
+
}
|
|
146
|
+
/** `lost`: the cloud computer stopped or forgot the job before it ended. */
|
|
147
|
+
export type JobState = 'running' | 'succeeded' | 'failed' | 'cancelled' | 'timed_out' | 'lost';
|
|
148
|
+
export interface SpaceCloudComputerJobStatus {
|
|
149
|
+
job_id: string; status: JobState; exit_code: number | null; started_at: string | null; ended_at: string | null; log_bytes: number;
|
|
61
150
|
}
|
|
151
|
+
export interface SpaceCloudComputerJobInput {
|
|
152
|
+
job_id: string;
|
|
153
|
+
/** `job.logs`: the first byte to read (default 0). */
|
|
154
|
+
offset?: number;
|
|
155
|
+
/** `job.logs`: 1 to 200000 bytes (default 65536). */
|
|
156
|
+
max_bytes?: number;
|
|
157
|
+
}
|
|
158
|
+
export interface SpaceCloudComputerJobLogs {
|
|
159
|
+
job_id: string; status: JobState; text: string; offset: number; next_offset: number;
|
|
160
|
+
/** The job ended and every byte was read. */
|
|
161
|
+
eof: boolean;
|
|
162
|
+
}
|
|
163
|
+
export type SpaceCloudComputerJobResult<O extends SpaceCloudComputerJobOperation> =
|
|
164
|
+
O extends 'job.logs' ? SpaceCloudComputerJobLogs : SpaceCloudComputerJobStatus;
|
|
165
|
+
export interface SpaceCloudComputerLeaseInput {
|
|
166
|
+
service: string;
|
|
167
|
+
/** `true` renews the lease for 120 s and starts the service when needed; `false` stops renewing it. */
|
|
168
|
+
visible: boolean;
|
|
169
|
+
/** One id per view instance, kept for its life: 8 to 100 of `A-Z a-z 0-9 . _ : -`. */
|
|
170
|
+
holder: string;
|
|
171
|
+
}
|
|
172
|
+
export interface SpaceCloudComputerLeaseResult {
|
|
173
|
+
service: string;
|
|
174
|
+
status: 'starting' | 'ready' | 'failed' | 'released';
|
|
175
|
+
lease_expires_at: string | null;
|
|
176
|
+
/** While starting: ask again after this many seconds. */
|
|
177
|
+
retry_after_seconds: number | null;
|
|
178
|
+
/**
|
|
179
|
+
* While failed: a stable reason and what went wrong. While starting, `restoring` means the machine runs but is still
|
|
180
|
+
* restoring its files after a pause (it can take minutes), and `launching` that the service runs on the machine and is
|
|
181
|
+
* getting ready (the machine's own bound decides, so the view keeps waiting).
|
|
182
|
+
*/
|
|
183
|
+
reason?: string; message?: string;
|
|
184
|
+
/** The gate that serves the service, and the Bearer pass for it; null until the gate is on. */
|
|
185
|
+
gate_url: string | null;
|
|
186
|
+
pass: string | null;
|
|
187
|
+
pass_expires_at: string | null;
|
|
188
|
+
price: { hourly_usd: number | null; size: string | null };
|
|
189
|
+
}
|
|
190
|
+
export interface SpaceCloudComputerAccessInput {
|
|
191
|
+
service: string;
|
|
192
|
+
/** Service file paths (each starting with `/`, no query) to open in a media element: up to 50, one link each. */
|
|
193
|
+
media?: string[];
|
|
194
|
+
/** A one-time code the service frame exchanges for its own session. */
|
|
195
|
+
frame?: boolean;
|
|
196
|
+
/** With `frame`: where the frame lands. A root path (`/`) serves the service from the gate root. */
|
|
197
|
+
path?: string;
|
|
198
|
+
}
|
|
199
|
+
/** One file of one service for ten minutes; seeking (Range) works. */
|
|
200
|
+
export interface SpaceCloudComputerMediaLink { path: string; url: string; expires_at: string }
|
|
201
|
+
/** Load `frame` in an iframe; when it posts `notis-gate-ready`, post `{ type: 'notis-gate-code', code }` to it. */
|
|
202
|
+
export interface SpaceCloudComputerFrameCode { frame: string; action: string; code: string; next: string; expires_at: string }
|
|
203
|
+
export interface SpaceCloudComputerAccessResult {
|
|
204
|
+
service: string; gate_url: string | null; media: SpaceCloudComputerMediaLink[]; frame: SpaceCloudComputerFrameCode | null;
|
|
205
|
+
}
|
|
206
|
+
/** The folder this Space works in on the cloud computer: `mapped` when the person mapped it to an existing folder. */
|
|
207
|
+
export interface SpaceCloudComputerFolder { path: string; canonical_path: string; mapped: boolean }
|
|
62
208
|
export interface SpaceCloudComputerUploadInput {
|
|
63
209
|
path: string; content: string; content_encoding?: 'base64' | 'utf-8'; overwrite?: boolean; mode?: number;
|
|
64
210
|
/** As for a run: one key per upload, kept when retrying it. */
|
|
65
211
|
request_id?: string;
|
|
66
212
|
}
|
|
67
213
|
export interface SpaceCloudComputerUploadResult { status?: string; path?: string; size?: number; message?: string; code?: string }
|
|
68
|
-
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* A file a signed-in Editor attaches from a view to a database's files column (a comment's picture), uploaded
|
|
217
|
+
* before the row that holds it is written. Stored privately in the EU: the row keeps `file`, and every read of
|
|
218
|
+
* the row signs it for an hour, so it opens only for people (and agents) who can read that row.
|
|
219
|
+
*/
|
|
220
|
+
export interface SpaceFileUploadInput {
|
|
221
|
+
/** The database binding alias the view declares (its `resources` key). */
|
|
222
|
+
database: string;
|
|
223
|
+
/** The files column the reference goes into. */
|
|
224
|
+
column: string;
|
|
225
|
+
file: Blob;
|
|
226
|
+
/** The file's name with its extension. Default: the File's own name. */
|
|
227
|
+
name?: string;
|
|
228
|
+
/** One key per file: the same file sent again after an uncertain answer keeps it. Default: a new key per call. */
|
|
229
|
+
requestId?: string;
|
|
230
|
+
/** Bytes sent so far, for a progress bar. */
|
|
231
|
+
onProgress?(sent: number, total: number): void;
|
|
232
|
+
signal?: AbortSignal;
|
|
233
|
+
}
|
|
234
|
+
/** What a files column stores. */
|
|
235
|
+
export interface SpaceFileReference { name: string; url: string }
|
|
236
|
+
export interface SpaceFileUploadResult {
|
|
237
|
+
/** Write this into the files column with the row's insert or update. */
|
|
238
|
+
file: SpaceFileReference;
|
|
239
|
+
/** A signed address to show the file before the row is read back (an hour), or null. */
|
|
240
|
+
previewUrl: string | null;
|
|
241
|
+
sizeBytes: number; contentType: string; sha256: string; requestId: string;
|
|
242
|
+
}
|
|
243
|
+
/** The database column takes files from this view, with the limits the host enforces. */
|
|
244
|
+
export interface SpaceFilesCheck { available: true; maxBytes: number; extensions: string[] }
|
|
245
|
+
/**
|
|
246
|
+
* Codes a file upload fails with: `space_file_too_large`, `space_file_type_unsupported`, `space_file_empty`,
|
|
247
|
+
* `space_file_column_missing`, `space_file_write_required`, `space_file_unconfirmed` (try again),
|
|
248
|
+
* `space_file_offline` (no answer), `sign_in_required`, `editor_required`, or another server code.
|
|
249
|
+
*/
|
|
250
|
+
export class SpaceFileError extends Error {
|
|
251
|
+
constructor(message: string, public readonly code: string, public readonly status = 0) {
|
|
252
|
+
super(message); this.name = 'SpaceFileError';
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** Host transport for files attached from a view. Absent on Sites, previews, verification harnesses and older hosts. */
|
|
256
|
+
export interface SpaceFilesTransport {
|
|
257
|
+
check(database: string, column: string): Promise<SpaceFilesCheck>;
|
|
258
|
+
upload(input: SpaceFileUploadInput): Promise<SpaceFileUploadResult>;
|
|
259
|
+
}
|
|
260
|
+
/** Extensions a files column accepts from a view, before the host's own check answers. */
|
|
261
|
+
export const SPACE_FILE_EXTENSIONS: readonly string[] = Object.freeze(['png', 'jpg', 'jpeg', 'gif', 'webp', 'pdf', 'docx',
|
|
262
|
+
'xlsx', 'pptx', 'odt', 'ods', 'odp', 'doc', 'xls', 'ppt', 'rtf', 'txt', 'md', 'csv', 'tsv', 'json']);
|
|
263
|
+
export const SPACE_FILE_MAX_BYTES = 8 * 1024 * 1024;
|
|
264
|
+
/**
|
|
265
|
+
* A file the page holds (a `File` from an input or a drop, or any `Blob`) for the Space folder. Above 1 MiB its
|
|
266
|
+
* parts go straight from the browser to the cloud computer, never through Notis servers; the machine checks its
|
|
267
|
+
* sha256 before it replaces the file at `dest`.
|
|
268
|
+
*/
|
|
269
|
+
export interface SpaceCloudComputerFileUpload {
|
|
270
|
+
file: Blob;
|
|
271
|
+
/** `{ space: 'files/clip.mp4' }`: the file's path inside the Space folder. */
|
|
272
|
+
dest: { space: string };
|
|
273
|
+
/** Called as the file is read, sent and put in place. */
|
|
274
|
+
onProgress?(progress: SpaceCloudComputerUploadProgress): void;
|
|
275
|
+
/** Aborting cancels the upload and drops the parts already sent. */
|
|
276
|
+
signal?: AbortSignal;
|
|
277
|
+
}
|
|
278
|
+
export interface SpaceCloudComputerUploadProgress {
|
|
279
|
+
/** `preparing`: reading the file for its sha256. `finishing`: the machine checks it and puts it in place. */
|
|
280
|
+
phase: 'preparing' | 'sending' | 'finishing' | 'done';
|
|
281
|
+
path: string; sent_bytes: number; total_bytes: number;
|
|
282
|
+
}
|
|
283
|
+
export interface SpaceCloudComputerFileUploadResult {
|
|
284
|
+
status: 'success'; path: string; size: number; sha256: string;
|
|
285
|
+
/** Present when the file went through a direct transfer session. */
|
|
286
|
+
session_id?: string;
|
|
287
|
+
}
|
|
288
|
+
/** Have the cloud computer download a public `http(s)` URL itself into the Space folder. */
|
|
289
|
+
export interface SpaceCloudComputerImportInput {
|
|
290
|
+
url: string;
|
|
291
|
+
/** `{ space: 'files/data.zip' }`: the file's path inside the Space folder. */
|
|
292
|
+
dest: { space: string };
|
|
293
|
+
/** When given, the download must match it. */
|
|
294
|
+
sha256?: string;
|
|
295
|
+
/** Default true. */
|
|
296
|
+
overwrite?: boolean;
|
|
297
|
+
/** As for a run: one key per import, kept when retrying it. */
|
|
298
|
+
request_id?: string;
|
|
299
|
+
}
|
|
300
|
+
export interface SpaceCloudComputerImportResult {
|
|
301
|
+
status?: 'success' | 'error' | string; path?: string; size?: number; sha256?: string;
|
|
302
|
+
/** Bytes a previous unfinished download of the same URL had already fetched. */
|
|
303
|
+
resumed_from?: number;
|
|
304
|
+
code?: string; message?: string; retryable?: boolean;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Host transport. Approval is only ever given in host UI the person clicks; the view can only ask. `lease`, `job`
|
|
308
|
+
* and `folder` are absent from hosts that predate them.
|
|
309
|
+
*/
|
|
69
310
|
export interface SpaceCloudComputerTransport {
|
|
70
311
|
status(): Promise<SpaceCloudComputerStatus>;
|
|
71
312
|
requestApproval(): Promise<SpaceCloudComputerStatus>;
|
|
72
313
|
facts(options?: { refresh?: boolean }): Promise<import('./runtime').CloudComputerFacts>;
|
|
73
314
|
run(input: SpaceCloudComputerRunInput): Promise<SpaceCloudComputerRunResult>;
|
|
74
315
|
upload(input: SpaceCloudComputerUploadInput): Promise<SpaceCloudComputerUploadResult>;
|
|
316
|
+
lease?(input: SpaceCloudComputerLeaseInput): Promise<SpaceCloudComputerLeaseResult>;
|
|
317
|
+
/** Media links and frame codes for a ready service: what an element that cannot send a header needs. */
|
|
318
|
+
access?(input: SpaceCloudComputerAccessInput): Promise<SpaceCloudComputerAccessResult>;
|
|
319
|
+
job?<O extends SpaceCloudComputerJobOperation>(operation: O, input: SpaceCloudComputerJobInput): Promise<SpaceCloudComputerJobResult<O>>;
|
|
320
|
+
folder?(): Promise<SpaceCloudComputerFolder>;
|
|
321
|
+
/** A file from the page into the Space folder (`upload({ file })`); absent from hosts that predate it. */
|
|
322
|
+
sendFile?(input: SpaceCloudComputerFileUpload): Promise<SpaceCloudComputerFileUploadResult>;
|
|
323
|
+
importUrl?(input: SpaceCloudComputerImportInput): Promise<SpaceCloudComputerImportResult>;
|
|
75
324
|
}
|
|
76
325
|
export const SPACE_CLOUD_COMPUTER_OPERATIONS: Readonly<Record<SpaceCloudComputerOperation, SpaceCloudComputerLevel>> = Object.freeze({
|
|
77
|
-
facts: 'read', run: 'shell', upload: 'shell',
|
|
326
|
+
facts: 'read', run: 'shell', upload: 'shell', 'job.status': 'shell', 'job.logs': 'shell', 'job.cancel': 'shell',
|
|
327
|
+
'service.lease': 'shell', 'service.access': 'shell', folder: 'read', 'transfer.begin': 'shell', 'transfer.status': 'shell',
|
|
328
|
+
'transfer.commit': 'shell', 'transfer.abort': 'shell', import: 'shell',
|
|
78
329
|
});
|
|
79
330
|
export function spaceCloudComputerAllows(level: SpaceCloudComputerLevel | undefined, operation: SpaceCloudComputerOperation): boolean {
|
|
80
|
-
const needed = SPACE_CLOUD_COMPUTER_OPERATIONS[operation];
|
|
331
|
+
const needed = Object.hasOwn(SPACE_CLOUD_COMPUTER_OPERATIONS, operation) ? SPACE_CLOUD_COMPUTER_OPERATIONS[operation] : null;
|
|
332
|
+
if (!needed) return false;
|
|
81
333
|
return level === 'shell' || (level === 'read' && needed === 'read');
|
|
82
334
|
}
|
|
335
|
+
/** The access level of a `cloudComputer` declaration in either form, or null. */
|
|
336
|
+
export function spaceCloudComputerAccess(declaration: SpaceCloudComputerLevel | SpaceCloudComputerDeclaration | null | undefined):
|
|
337
|
+
SpaceCloudComputerLevel | null {
|
|
338
|
+
const level = typeof declaration === 'string' ? declaration : declaration?.access;
|
|
339
|
+
return level === 'read' || level === 'shell' ? level : null;
|
|
340
|
+
}
|
|
83
341
|
|
|
84
342
|
/** A link the viewer can use (R10); unavailable links are never returned. */
|
|
85
343
|
export interface SpaceViewerLink { space_id: string; space_name: string | null; binding_id: string; alias: string | null }
|
|
@@ -131,15 +389,23 @@ export interface SpaceDatabaseCreate {
|
|
|
131
389
|
schema: Record<string, SpaceJson>;
|
|
132
390
|
starterRows?: Array<Record<string, SpaceJson>>;
|
|
133
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Database columns only the Space's editors read and write, by property name. The server leaves them out of every
|
|
394
|
+
* row the public reads through this Space and refuses public writes to them.
|
|
395
|
+
*/
|
|
396
|
+
export type SpaceResourceColumns = Record<string, { editorsOnly: true }>;
|
|
134
397
|
export type SpaceResourceReference = {
|
|
135
398
|
kind: 'database' | 'document' | 'skill' | 'automation';
|
|
136
399
|
/** Portable resource key, resolved against this profile's explicit bindings. */
|
|
137
400
|
key: string;
|
|
138
401
|
create?: never;
|
|
402
|
+
/** Database resources only. */
|
|
403
|
+
columns?: SpaceResourceColumns;
|
|
139
404
|
} | {
|
|
140
405
|
kind: 'database';
|
|
141
406
|
create: SpaceDatabaseCreate;
|
|
142
407
|
key?: never;
|
|
408
|
+
columns?: SpaceResourceColumns;
|
|
143
409
|
};
|
|
144
410
|
|
|
145
411
|
/** Optional V4 marker. Presentations always require path, description and memory at build time. */
|
|
@@ -169,6 +435,8 @@ export interface SpaceViewParam {
|
|
|
169
435
|
page?: { where: NativeFilter };
|
|
170
436
|
/** IANA timezone for relative dates/periods (UTC if omitted). */
|
|
171
437
|
timezone?: string;
|
|
438
|
+
/** Only editors can set it; for the public it is dropped like an unknown param. A required one needs a default. */
|
|
439
|
+
editorsOnly?: true;
|
|
172
440
|
}
|
|
173
441
|
/**
|
|
174
442
|
* Notis data the view lists: exactly this native filter over a declared database, with `{param}`,
|
|
@@ -177,8 +445,8 @@ export interface SpaceViewParam {
|
|
|
177
445
|
export type SpaceViewFilter = { and: SpaceViewFilter[] } | { or: SpaceViewFilter[] }
|
|
178
446
|
| (Extract<NativeFilter, { field: unknown }> & { /** Apply only when this boolean param is true. */ when?: string });
|
|
179
447
|
export type SpaceShows =
|
|
180
|
-
| { database: string; where: SpaceViewFilter | Record<string, never>; open?: string }
|
|
181
|
-
| { about: string; services?: readonly string[] };
|
|
448
|
+
| { database: string; where: SpaceViewFilter | Record<string, never>; open?: string; /** Editors only. Default: public. */ editorsOnly?: true }
|
|
449
|
+
| { about: string; services?: readonly string[]; editorsOnly?: true };
|
|
182
450
|
/** When view snapshots go to memory: on render, on a UTC cron (fixed minute), or after changes settle. */
|
|
183
451
|
export type SpaceMemorySnapshot = 'on_render' | { scheduled: string } | { on_change: { debounceSeconds: number } };
|
|
184
452
|
/** What this view sends to memory; records follow their database's main view. See the memory guide. */
|
|
@@ -208,6 +476,8 @@ export interface SpaceShownResult {
|
|
|
208
476
|
params: Record<string, unknown>;
|
|
209
477
|
/** The list database's schema revision: pass it as `schemaRevision` to a declared row write. */
|
|
210
478
|
schema_revision?: number;
|
|
479
|
+
/** The list database's column names, in schema order (hosts that send them): write only columns it has. */
|
|
480
|
+
property_names?: string[];
|
|
211
481
|
[key: string]: unknown;
|
|
212
482
|
}
|
|
213
483
|
/** Input of a `markdown` module's default export (V8 renders). */
|
|
@@ -218,6 +488,12 @@ export interface SpaceMarkdownInput {
|
|
|
218
488
|
|
|
219
489
|
export interface SpaceDefinition {
|
|
220
490
|
name: string;
|
|
491
|
+
/**
|
|
492
|
+
* The whole view is for the Space's editors: for the public it does not exist (missing from navigation, its
|
|
493
|
+
* address is the Site's not-found). Lists, actions, params and database columns take their own `editorsOnly`.
|
|
494
|
+
* Anything unmarked is public, for reads and writes alike.
|
|
495
|
+
*/
|
|
496
|
+
editorsOnly?: true;
|
|
221
497
|
/** Optional marker (2); omitting it does not waive a presentation's required declarations. */
|
|
222
498
|
specVersion?: typeof SPACE_VIEW_SPEC_VERSION;
|
|
223
499
|
/** Words used in this view's links, such as `notes` or `seo/keywords`. */
|
|
@@ -232,6 +508,7 @@ export interface SpaceDefinition {
|
|
|
232
508
|
/** Source-relative module whose default export `(input: SpaceMarkdownInput) => string` renders this view as Markdown. */
|
|
233
509
|
markdown?: string;
|
|
234
510
|
description?: string;
|
|
511
|
+
/** Required to deploy or preview: `phosphor:<kebab-name>` (for example `phosphor:calendar-check`) or an https image URL. */
|
|
235
512
|
icon?: string;
|
|
236
513
|
accent?: string;
|
|
237
514
|
/** No entry means a container; it needs no dummy JavaScript artifact. */
|
|
@@ -250,9 +527,16 @@ export interface SpaceDefinition {
|
|
|
250
527
|
viewerReads?: SpaceViewerReadFamily[];
|
|
251
528
|
/**
|
|
252
529
|
* Reviewable declaration that this page uses each signed-in viewer's own cloud computer
|
|
253
|
-
* (`read`: facts; `shell`: commands and file writes), once that viewer allows it.
|
|
530
|
+
* (`read`: facts; `shell`: commands, jobs and file writes), once that viewer allows it. The object form adds
|
|
531
|
+
* `services` the page keeps up while it is on screen.
|
|
254
532
|
*/
|
|
255
|
-
cloudComputer?: SpaceCloudComputerLevel;
|
|
533
|
+
cloudComputer?: SpaceCloudComputerLevel | SpaceCloudComputerDeclaration;
|
|
534
|
+
/**
|
|
535
|
+
* Agents this Space's database changes wake. A person's new comment, reply or answer wakes their own
|
|
536
|
+
* thread for the item (or, for a reply to an agent's comment, that agent's thread) after a quiet
|
|
537
|
+
* moment, once that person allowed this Space's agents. Agents' own writes never wake anything.
|
|
538
|
+
*/
|
|
539
|
+
agents?: SpaceAgentDeclaration[];
|
|
256
540
|
collection?: { database: string; titleProperty: string; parentProperty?: string; allowCreate?: boolean };
|
|
257
541
|
/** Reproducible source dependencies not discovered by the module graph. */
|
|
258
542
|
sourceIncludes?: string[];
|
|
@@ -277,16 +561,53 @@ export interface SpaceActionDescriptor {
|
|
|
277
561
|
readOnly: boolean;
|
|
278
562
|
}
|
|
279
563
|
|
|
564
|
+
/** Who the Space is drawn for: its editors, or the public (Site and link visitors, signed-in people who cannot edit). */
|
|
565
|
+
export type SpaceAudience = 'editor' | 'public';
|
|
566
|
+
/** What the published view marks editor-only; sent to editors only. */
|
|
567
|
+
export interface SpaceEditorsOnly {
|
|
568
|
+
view?: true;
|
|
569
|
+
shows?: string[];
|
|
570
|
+
actions?: string[];
|
|
571
|
+
params?: string[];
|
|
572
|
+
/** Database binding alias to its editor-only property names. */
|
|
573
|
+
columns?: Record<string, string[]>;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* The editor-only column names a definition declares on one database resource:
|
|
578
|
+
* `EditorOnlyColumns<typeof definition, 'tickets'>`.
|
|
579
|
+
*/
|
|
580
|
+
export type EditorOnlyColumns<D extends Pick<SpaceDefinition, 'resources'>, A extends keyof NonNullable<D['resources']>> =
|
|
581
|
+
NonNullable<D['resources']>[A] extends { columns: infer C } ? Extract<{ [K in keyof C]: C[K] extends { editorsOnly: true } ? K : never }[keyof C], string>
|
|
582
|
+
: never;
|
|
583
|
+
/**
|
|
584
|
+
* A row as one audience reads it: for the public, the editor-only columns are absent from `properties` (or from the
|
|
585
|
+
* row itself when it has no `properties`). `AudienceRow<Row, EditorOnlyColumns<typeof definition, 'tickets'>>`.
|
|
586
|
+
*/
|
|
587
|
+
export type AudienceRow<Row, Cols extends string, A extends SpaceAudience = 'public'> = A extends 'editor' ? Row
|
|
588
|
+
: Row extends { properties: infer P } ? Omit<Row, 'properties'> & { properties: Omit<P, Cols> } : Omit<Row, Cols>;
|
|
589
|
+
|
|
280
590
|
export interface SpaceRuntimeDescriptor {
|
|
281
591
|
id: string;
|
|
282
592
|
revision: number;
|
|
283
593
|
/** Opaque host identity includes actor/link, record context and live policy version. */
|
|
284
594
|
cacheScope: string;
|
|
595
|
+
/** Who the server drew this descriptor for. Absent on older servers, which means `public`. */
|
|
596
|
+
audience?: SpaceAudience;
|
|
597
|
+
/** Editors only: what this view marks editor-only, so the host can offer View as the public. */
|
|
598
|
+
editorsOnly?: SpaceEditorsOnly;
|
|
599
|
+
/**
|
|
600
|
+
* Host-set: an editor is viewing this Space as the public. The SDK applies the public floors in the page
|
|
601
|
+
* (editor-only lists, actions, params and columns gone); anything still allowed runs as the editor.
|
|
602
|
+
*/
|
|
603
|
+
viewAs?: 'public';
|
|
285
604
|
navigation?: string[];
|
|
286
605
|
/** Declared viewer reads; present only for a signed-in viewer, never on a Site. */
|
|
287
606
|
viewerReads?: SpaceViewerReadFamily[];
|
|
288
607
|
/** Declared cloud computer access; present only for a signed-in Editor, never on a Site. */
|
|
289
608
|
cloudComputer?: SpaceCloudComputerLevel;
|
|
609
|
+
/** Declared cloud computer service ids; present only for a signed-in Editor, never on a Site. */
|
|
610
|
+
cloudComputerServices?: string[];
|
|
290
611
|
/** V4: declared URL params (never a record param's `page` rule), list names and chrome of the executable revision. */
|
|
291
612
|
params?: Record<string, Omit<SpaceViewParam, 'page'>>;
|
|
292
613
|
shows?: Record<string, SpaceShownDescriptor>;
|
|
@@ -312,6 +633,13 @@ export interface SpaceActionOptions {
|
|
|
312
633
|
* and the batch calls `queryClient.invalidate()` once at the end. Hosts that predate it ignore it.
|
|
313
634
|
*/
|
|
314
635
|
deferRefresh?: boolean;
|
|
636
|
+
/**
|
|
637
|
+
* A cached read (`dedupe`) that must show the provider's current answer even while the view opens
|
|
638
|
+
* (a check made right before a send, say). Without it, a signed-in host may first answer a provider
|
|
639
|
+
* read with the person's last result of that exact read, then refresh the view with the provider's
|
|
640
|
+
* answer a moment later. Hosts that predate it ignore it.
|
|
641
|
+
*/
|
|
642
|
+
fresh?: boolean;
|
|
315
643
|
}
|
|
316
644
|
|
|
317
645
|
export type SpaceDocumentBodyRequest = {
|
|
@@ -333,7 +661,10 @@ export interface SpaceActionFailureDetails {
|
|
|
333
661
|
receiptId?: string;
|
|
334
662
|
status?: string;
|
|
335
663
|
pendingRequestIds?: string[];
|
|
336
|
-
/**
|
|
664
|
+
/**
|
|
665
|
+
* Why a settled action failed, when the host knows a stable reason: `read_timeout` (a read its time limit stopped)
|
|
666
|
+
* or `rate_limited` (the provider refused the call for sending too fast; it did not run, so retry after a few seconds).
|
|
667
|
+
*/
|
|
337
668
|
code?: string;
|
|
338
669
|
}
|
|
339
670
|
|
|
@@ -383,11 +714,174 @@ export function spaceQueryKey(runtime: NotisRuntime | null, key: readonly unknow
|
|
|
383
714
|
if (!space?.cacheScope || space.id !== runtime.resource.id || space.revision !== runtime.resource.revision) {
|
|
384
715
|
throw new Error('The host must provide this Space revision and access context.');
|
|
385
716
|
}
|
|
386
|
-
|
|
717
|
+
// Viewing as the public reads other rows than editing: never share their cache entries.
|
|
718
|
+
return ['space', space.id, space.revision, space.cacheScope, ...(space.viewAs === 'public' ? ['view-as-public'] : []), ...key];
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/** Who the page is drawn for: `editor` only for an editor who is not viewing the Space as the public. */
|
|
722
|
+
export function spaceAudience(space: SpaceRuntimeDescriptor | null | undefined): SpaceAudience {
|
|
723
|
+
return space?.audience === 'editor' && space.viewAs !== 'public' ? 'editor' : 'public';
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/** Whether the person is an editor who could view this Space as the public (the view marks something editor-only). */
|
|
727
|
+
export function spaceMarksEditorsOnly(space: SpaceRuntimeDescriptor | null | undefined): boolean {
|
|
728
|
+
const marks = space?.editorsOnly;
|
|
729
|
+
if (space?.audience !== 'editor' || !marks) return false;
|
|
730
|
+
return Boolean(marks.view || marks.shows?.length || marks.actions?.length || marks.params?.length
|
|
731
|
+
|| Object.values(marks.columns ?? {}).some(columns => columns.length));
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
const without = <T>(record: Record<string, T> | undefined, names: readonly string[] | undefined): Record<string, T> | undefined =>
|
|
735
|
+
record && names?.length ? Object.fromEntries(Object.entries(record).filter(([name]) => !names.includes(name))) : record;
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* The descriptor the public receives, computed from an editor's: editor-only lists, actions, params and the row
|
|
739
|
+
* operations backed by them removed, and the signed-in-only reads a Site never gets. Same floors as the server.
|
|
740
|
+
*/
|
|
741
|
+
export function publicSpaceDescriptor(space: SpaceRuntimeDescriptor): SpaceRuntimeDescriptor {
|
|
742
|
+
const marks = space.editorsOnly ?? {};
|
|
743
|
+
const actions = without(space.actions, marks.actions) ?? {};
|
|
744
|
+
const bindings = Object.fromEntries(Object.entries(space.bindings ?? {}).map(([alias, binding]) => [alias, binding.operations
|
|
745
|
+
? { ...binding, operations: Object.fromEntries(Object.entries(binding.operations).filter(([, id]) => Boolean(id && Object.hasOwn(actions, id)))) }
|
|
746
|
+
: binding]));
|
|
747
|
+
const { editorsOnly: _marks, viewerReads: _reads, cloudComputer: _computer, ...rest } = space;
|
|
748
|
+
return { ...rest, audience: 'public', actions, bindings,
|
|
749
|
+
...(space.shows ? { shows: without(space.shows, marks.shows) } : {}),
|
|
750
|
+
...(space.params ? { params: without(space.params, marks.params) } : {}) };
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
const fold = (name: string) => name.toLowerCase();
|
|
754
|
+
const isRecord = (value: unknown): value is Record<string, unknown> => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* The editor-only columns of what one read or write touches, while an editor views the Space as the public.
|
|
758
|
+
* `hidden`: folded property names (a declared name may also be a property id, which the server accepts).
|
|
759
|
+
* `ids`: property ids known to be editor-only (learned from a schema or `runtime.databases`).
|
|
760
|
+
* `title`: the database's title column is editor-only, so the row's `title` is too.
|
|
761
|
+
*/
|
|
762
|
+
interface ColumnFloor {
|
|
763
|
+
hidden: ReadonlySet<string>;
|
|
764
|
+
ids: ReadonlySet<string>;
|
|
765
|
+
title: boolean;
|
|
766
|
+
/** Told the real names of the editor-only properties a row carried, and whether its title was one of them. */
|
|
767
|
+
seen?: (names: readonly string[], title: boolean) => void;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Whether the row's title is the value of an editor-only column. Rows do not name their title property, but they
|
|
772
|
+
* carry it among their properties under its name: an editor-only property holding exactly the row's title is taken
|
|
773
|
+
* to be the title column. A coincidence over-strips the title, which the preview accepts.
|
|
774
|
+
*/
|
|
775
|
+
function titleColumnHidden(row: Record<string, unknown>, hidden: ReadonlySet<string>): boolean {
|
|
776
|
+
const { title, properties } = row;
|
|
777
|
+
return typeof title === 'string' && title !== '' && isRecord(properties)
|
|
778
|
+
&& Object.entries(properties).some(([name, value]) => hidden.has(fold(name)) && value === title);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/** One row (or record) as the public reads it, the server's floor (`ColumnFloor.row` in space_audience.py). */
|
|
782
|
+
function floorRow<T>(row: T, floor: ColumnFloor): T {
|
|
783
|
+
if (!isRecord(row) || !floor.hidden.size) return row;
|
|
784
|
+
const result: Record<string, unknown> = { ...row };
|
|
785
|
+
const title = floor.title || titleColumnHidden(row, floor.hidden);
|
|
786
|
+
const named: string[] = [];
|
|
787
|
+
const visible = (fields: Record<string, unknown>) => Object.fromEntries(Object.entries(fields).filter(([name]) => {
|
|
788
|
+
const hidden = floor.hidden.has(fold(name)) || floor.ids.has(name);
|
|
789
|
+
if (hidden) named.push(name);
|
|
790
|
+
return !hidden;
|
|
791
|
+
}));
|
|
792
|
+
let nested = false;
|
|
793
|
+
for (const field of ['properties', 'property_states']) {
|
|
794
|
+
const fields = result[field];
|
|
795
|
+
if (isRecord(fields)) { nested = true; result[field] = visible(fields); }
|
|
796
|
+
}
|
|
797
|
+
// A row without `properties` carries its columns itself (see AudienceRow).
|
|
798
|
+
if (!nested) {
|
|
799
|
+
const kept = visible(result);
|
|
800
|
+
for (const key of Object.keys(result)) if (!Object.hasOwn(kept, key)) delete result[key];
|
|
801
|
+
}
|
|
802
|
+
if (title) delete result.title;
|
|
803
|
+
floor.seen?.(named, title);
|
|
804
|
+
return result as T;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/** A schema the public reads: the editor-only properties gone, their ids and title learned for later checks. */
|
|
808
|
+
function floorSchema(schema: Record<string, unknown>, floor: ColumnFloor, learn: (ids: string[], names: string[], title: boolean) => void) {
|
|
809
|
+
const properties = schema.properties;
|
|
810
|
+
if (!isRecord(properties)) return schema;
|
|
811
|
+
const ids = Object.entries(properties).filter(([id, property]) => floor.hidden.has(fold(id)) || floor.ids.has(id)
|
|
812
|
+
|| (isRecord(property) && typeof property.name === 'string' && floor.hidden.has(fold(property.name)))).map(([id]) => id);
|
|
813
|
+
if (!ids.length) return schema;
|
|
814
|
+
const names = ids.map(id => properties[id]).filter(isRecord).map(property => property.name).filter((name): name is string => typeof name === 'string');
|
|
815
|
+
learn(ids, names, typeof schema.title_property_id === 'string' && ids.includes(schema.title_property_id));
|
|
816
|
+
return { ...schema, properties: Object.fromEntries(Object.entries(properties).filter(([id]) => !ids.includes(id))),
|
|
817
|
+
...(Array.isArray(schema.property_order) ? { property_order: schema.property_order.filter(id => !ids.includes(id as string)) } : {}) };
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* A native answer as the public reads it: its rows, its single `row`, `record` or `document`, a record read that is
|
|
822
|
+
* the row itself, and its schema (the server's `ColumnFloor.result`).
|
|
823
|
+
*/
|
|
824
|
+
function floorResult<T>(value: T, floor: ColumnFloor, learn: (ids: string[], names: string[], title: boolean) => void = () => {}): T {
|
|
825
|
+
if (!floor.hidden.size) return value;
|
|
826
|
+
if (Array.isArray(value)) return value.map(row => floorRow(row, floor)) as T;
|
|
827
|
+
if (!isRecord(value)) return value;
|
|
828
|
+
let title = floor.title;
|
|
829
|
+
let result: Record<string, unknown> = { ...value };
|
|
830
|
+
if (isRecord(result.schema)) {
|
|
831
|
+
result.schema = floorSchema(result.schema, floor, (ids, names, hiddenTitle) => { title ||= hiddenTitle; learn(ids, names, hiddenTitle); });
|
|
832
|
+
}
|
|
833
|
+
const rows = { ...floor, title };
|
|
834
|
+
if (Array.isArray(result.rows)) result.rows = result.rows.map(row => floorRow(row, rows));
|
|
835
|
+
for (const name of ['row', 'record', 'document']) if (isRecord(result[name])) result[name] = floorRow(result[name], rows);
|
|
836
|
+
if (isRecord(result.properties) && ('record_key' in result || 'id' in result)) result = floorRow(result, rows);
|
|
837
|
+
return result as T;
|
|
387
838
|
}
|
|
388
839
|
|
|
389
|
-
/**
|
|
390
|
-
export function
|
|
840
|
+
/** Rows with these properties removed (matched case-insensitively), as the server sends them to the public. */
|
|
841
|
+
export function withoutEditorColumns<T>(rows: readonly T[], columns: readonly string[]): T[] {
|
|
842
|
+
if (!columns.length) return rows.slice();
|
|
843
|
+
const floor: ColumnFloor = { hidden: new Set(columns.map(fold)), ids: new Set(), title: false };
|
|
844
|
+
return rows.map(row => floorRow(row, floor));
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Whether a read or write names an editor-only column: a `property` or `property_id` reference anywhere (filters,
|
|
849
|
+
* sorts, search, aggregate, projection), a written `properties` key, and the title (`{column: 'title'}` or a
|
|
850
|
+
* `columns.title` write) once the title column is known to be editor-only.
|
|
851
|
+
*
|
|
852
|
+
* A `property_id` is matched against the ids learned from a schema or `runtime.databases`; the Space descriptor itself
|
|
853
|
+
* carries no schema, so before one is learned only an id equal to a declared editor-only name (the server accepts an
|
|
854
|
+
* exact id there) is refused, and an id of an editor-only column declared by name is not.
|
|
855
|
+
*/
|
|
856
|
+
function namesEditorColumn(value: unknown, floor: ColumnFloor): boolean {
|
|
857
|
+
if (Array.isArray(value)) return value.some(item => namesEditorColumn(item, floor));
|
|
858
|
+
if (!isRecord(value)) return false;
|
|
859
|
+
const { property, property_id: propertyId, column, properties: written, columns } = value;
|
|
860
|
+
if (typeof property === 'string' && floor.hidden.has(fold(property))) return true;
|
|
861
|
+
if (typeof propertyId === 'string' && (floor.ids.has(propertyId) || floor.hidden.has(fold(propertyId)))) return true;
|
|
862
|
+
if (floor.title && column === 'title') return true;
|
|
863
|
+
// A row write names its columns as the keys of `properties`.
|
|
864
|
+
if (isRecord(written) && Object.keys(written).some(name => floor.hidden.has(fold(name)) || floor.ids.has(name))) return true;
|
|
865
|
+
if (floor.title && isRecord(columns) && Object.hasOwn(columns, 'title')) return true;
|
|
866
|
+
return Object.values(value).some(item => namesEditorColumn(item, floor));
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/** Host record components held to the public floor; `columns` reads the editor-only names known at render time. */
|
|
870
|
+
export type SpacePublicRecordUI = (ui: NotisRuntimeUI, columns: () => readonly string[]) => NotisRuntimeUI;
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* SDK defense in depth. The host/server independently reject these transports.
|
|
874
|
+
* With `space.viewAs === 'public'` it also applies the public floors in the page (View as the public): the
|
|
875
|
+
* descriptor the public would receive, editor-only lists and actions refused, editor-only columns left out of every
|
|
876
|
+
* row the page can read (actions, lists, document bodies, the collection item, host record components) and refused
|
|
877
|
+
* in every read or write that names them. Actions still run as the editor, so this floor is what keeps the preview
|
|
878
|
+
* true; real public visitors are held to it by the server.
|
|
879
|
+
*
|
|
880
|
+
* `options.publicRecordUI` holds the host record components to the floor (the provider passes the React one). Without
|
|
881
|
+
* it, the host components that draw a record's properties are left out while viewing as the public.
|
|
882
|
+
*/
|
|
883
|
+
export function guardSpaceRuntime(runtime: NotisRuntime | null, onProtocolError?: (error: Error) => void,
|
|
884
|
+
options: { publicRecordUI?: SpacePublicRecordUI } = {}): NotisRuntime | null {
|
|
391
885
|
if (runtime?.resource?.kind !== 'space') return runtime;
|
|
392
886
|
spaceQueryKey(runtime, []);
|
|
393
887
|
const protocolError = (message: string, key?: QueryErrorKey) => {
|
|
@@ -397,25 +891,132 @@ export function guardSpaceRuntime(runtime: NotisRuntime | null, onProtocolError?
|
|
|
397
891
|
const deny = async (): Promise<never> => { throw protocolError('Use a declared Space action; account-wide tool and backend calls are unavailable.'); };
|
|
398
892
|
const callAction = runtime.callAction;
|
|
399
893
|
if (!callAction) throw new Error('This host needs the current Space action protocol.');
|
|
400
|
-
const
|
|
894
|
+
const asPublic = runtime.space!.viewAs === 'public';
|
|
895
|
+
const space = asPublic ? publicSpaceDescriptor(runtime.space!) : runtime.space!;
|
|
896
|
+
const viewerRead = asPublic ? undefined : runtime.viewerRead;
|
|
401
897
|
const shown = runtime.shown;
|
|
402
|
-
const cloudComputer = runtime.spaceCloudComputer;
|
|
403
|
-
const cloudLevel =
|
|
898
|
+
const cloudComputer = asPublic ? undefined : runtime.spaceCloudComputer;
|
|
899
|
+
const cloudLevel = space.cloudComputer;
|
|
404
900
|
const guardedCloud = (operation: SpaceCloudComputerOperation) => {
|
|
405
901
|
if (!cloudComputer || !spaceCloudComputerAllows(cloudLevel, operation)) {
|
|
406
|
-
throw protocolError(operation === 'facts' ? 'This Space does not use the
|
|
902
|
+
throw protocolError(operation === 'facts' || operation === 'folder' ? 'This Space does not use the Cloud Computer.'
|
|
407
903
|
: 'This Space does not declare cloudComputer: shell.');
|
|
408
904
|
}
|
|
409
905
|
return cloudComputer;
|
|
410
906
|
};
|
|
411
|
-
|
|
907
|
+
// Hosts that predate services, jobs or the folder do not offer them.
|
|
908
|
+
const lease = cloudComputer?.lease, access = cloudComputer?.access, job = cloudComputer?.job, folder = cloudComputer?.folder;
|
|
909
|
+
const sendFile = cloudComputer?.sendFile, importUrl = cloudComputer?.importUrl;
|
|
910
|
+
const declaredService = (service: unknown) => {
|
|
911
|
+
const declared = runtime.space!.cloudComputerServices;
|
|
912
|
+
if (typeof service !== 'string' || !Array.isArray(declared) || !declared.includes(service)) {
|
|
913
|
+
throw protocolError('This Space does not declare that Cloud Computer service.');
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
const undeclared = (key?: QueryErrorKey) => protocolError('This action is not declared by the published Space.', key);
|
|
917
|
+
const columnRefused = (key?: QueryErrorKey) => protocolError('The public cannot read or write this column.', key);
|
|
918
|
+
|
|
919
|
+
// View as the public: what is editor-only, by binding alias, plus what the page learns while it reads.
|
|
920
|
+
const hiddenColumns = asPublic ? runtime.space!.editorsOnly?.columns ?? {} : {};
|
|
921
|
+
const declared = (alias?: string): readonly string[] => alias === undefined ? Object.values(hiddenColumns).flat()
|
|
922
|
+
: (Object.hasOwn(hiddenColumns, alias) ? hiddenColumns[alias] : undefined) ?? [];
|
|
923
|
+
const anyHidden = new Set(declared().map(fold));
|
|
924
|
+
/** Real names of editor-only properties seen in rows and schemas, for the host components that match names exactly. */
|
|
925
|
+
const observed = new Set<string>();
|
|
926
|
+
/** Editor-only property ids, learned from schemas and `runtime.databases`. */
|
|
927
|
+
const hiddenIds = new Set<string>();
|
|
928
|
+
/** Aliases whose title column is editor-only; `titleSomewhere` when a database names no alias. */
|
|
929
|
+
const hiddenTitles = new Set<string>();
|
|
930
|
+
let titleSomewhere = false;
|
|
931
|
+
if (anyHidden.size) {
|
|
932
|
+
for (const database of runtime.databases ?? []) {
|
|
933
|
+
const alias = database?.slug && Object.hasOwn(hiddenColumns, database.slug) ? database.slug : undefined;
|
|
934
|
+
const hidden = alias === undefined ? anyHidden : new Set(declared(alias).map(fold));
|
|
935
|
+
for (const property of database?.properties ?? []) {
|
|
936
|
+
if (!property?.name || !(hidden.has(fold(property.name)) || (property.id && hidden.has(fold(property.id))))) continue;
|
|
937
|
+
if (property.id) hiddenIds.add(property.id);
|
|
938
|
+
observed.add(property.name);
|
|
939
|
+
if (property.type === 'title') { if (alias === undefined) titleSomewhere = true; else hiddenTitles.add(alias); }
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* The floor of one database (`alias`), or of every database when the alias is unknown or ambiguous: an action can
|
|
945
|
+
* then return rows of any of them, so the union of their editor-only columns is left out (over-stripping is safe).
|
|
946
|
+
*/
|
|
947
|
+
const floorOf = (alias: string | undefined): ColumnFloor => {
|
|
948
|
+
const hidden = alias === undefined ? anyHidden : new Set(declared(alias).map(fold));
|
|
949
|
+
return { hidden, ids: hiddenIds,
|
|
950
|
+
title: hidden.size > 0 && (titleSomewhere || (alias === undefined ? hiddenTitles.size > 0 : hiddenTitles.has(alias))),
|
|
951
|
+
seen: (names, title) => {
|
|
952
|
+
for (const name of names) observed.add(name);
|
|
953
|
+
if (title && alias !== undefined) hiddenTitles.add(alias);
|
|
954
|
+
} };
|
|
955
|
+
};
|
|
956
|
+
const learnOf = (alias: string | undefined) => (ids: string[], names: string[], title: boolean) => {
|
|
957
|
+
for (const id of ids) hiddenIds.add(id);
|
|
958
|
+
for (const name of names) observed.add(name);
|
|
959
|
+
if (title) { if (alias === undefined) titleSomewhere = true; else hiddenTitles.add(alias); }
|
|
960
|
+
};
|
|
961
|
+
/** The one binding an action belongs to (one of its row operations); undefined when none or several. */
|
|
962
|
+
const aliasOfAction = (actionId: string) => {
|
|
963
|
+
const aliases = Object.entries(space.bindings ?? {}).filter(([, binding]) =>
|
|
964
|
+
binding.operations && Object.values(binding.operations).includes(actionId)).map(([alias]) => alias);
|
|
965
|
+
return aliases.length === 1 ? aliases[0] : undefined;
|
|
966
|
+
};
|
|
967
|
+
const declaredBinding = (alias: unknown): alias is string => typeof alias === 'string' && Object.hasOwn(space.bindings ?? {}, alias);
|
|
968
|
+
const documentBody = runtime.documentBody;
|
|
969
|
+
const subscribeDatabase = runtime.subscribeDatabase;
|
|
970
|
+
const draftHandover = runtime.draftHandover;
|
|
971
|
+
const collectionItem = runtime.context?.collectionItem;
|
|
972
|
+
|
|
973
|
+
const publicFloors: Partial<NotisRuntime> = !asPublic ? {} : {
|
|
974
|
+
// Document bodies are not columns, but the read and write actions must be the public's, and the title is a column.
|
|
975
|
+
...(documentBody ? { documentBody: async (request: SpaceDocumentBodyRequest): Promise<SpaceDocumentBodyResult> => {
|
|
976
|
+
const actionIds = isRecord(request) ? [request.readAction, ...(request.operation === 'save' ? [request.writeAction] : [])] : [];
|
|
977
|
+
if (!actionIds.length || !declaredBinding(request.binding)
|
|
978
|
+
|| actionIds.some(id => typeof id !== 'string' || !Object.hasOwn(space.actions, id))) throw undeclared();
|
|
979
|
+
const result = await documentBody(request);
|
|
980
|
+
// The answer does not say which column is the title: it is left out once the page has learned that.
|
|
981
|
+
return request.operation === 'read' && floorOf(request.binding).title && isRecord(result) && 'content_markdown' in result
|
|
982
|
+
? { ...result, title: null } : result;
|
|
983
|
+
} } : {}),
|
|
984
|
+
// A change signal carries no rows; only the public descriptor's databases have one.
|
|
985
|
+
...(subscribeDatabase ? { subscribeDatabase: (slug: string, onChange: () => void, config?: SubscribeDatabaseOptions) => {
|
|
986
|
+
if (!declaredBinding(slug) || space.bindings[slug].kind !== 'database') { config?.onStatusChange?.(false); return () => {}; }
|
|
987
|
+
return subscribeDatabase(slug, onChange, config);
|
|
988
|
+
} } : {}),
|
|
989
|
+
// The selected row goes to the editor's own Manager draft, never to the page; its read must be the public's.
|
|
990
|
+
...(draftHandover ? { draftHandover: async (payload: HandoverPayload) => {
|
|
991
|
+
const record = payload && typeof payload === 'object' ? payload.record : undefined;
|
|
992
|
+
if (record && (!declaredBinding(record.binding) || typeof record.readAction !== 'string'
|
|
993
|
+
|| !Object.hasOwn(space.actions, record.readAction))) throw undeclared();
|
|
994
|
+
return draftHandover(payload);
|
|
995
|
+
} } : {}),
|
|
996
|
+
...(anyHidden.size && isRecord(collectionItem) ? { context: { ...runtime.context, collectionItem: (() => {
|
|
997
|
+
const item = floorRow(collectionItem, floorOf(undefined));
|
|
998
|
+
return { ...item, title: typeof item.title === 'string' ? item.title : '' };
|
|
999
|
+
})() } } : {}),
|
|
1000
|
+
// Host record components read and write with the editor's authority: hold what they draw to the floor.
|
|
1001
|
+
...(anyHidden.size && runtime.ui ? { ui: options.publicRecordUI
|
|
1002
|
+
? options.publicRecordUI(runtime.ui, () => [...new Set([...declared(), ...observed])])
|
|
1003
|
+
: { ...runtime.ui, DocumentEditor: undefined, DocumentPage: undefined, RecordProperties: undefined } } : {}),
|
|
1004
|
+
};
|
|
1005
|
+
|
|
1006
|
+
return Object.freeze({ ...runtime, space, callTool: deny, request: deny, listTools: deny, ...publicFloors,
|
|
412
1007
|
shown: shown ? async function guardedShown<TResult>(name: string, params: Record<string, unknown> = {},
|
|
413
1008
|
options: SpaceShownOptions = {}): Promise<TResult> {
|
|
414
|
-
const list =
|
|
1009
|
+
const list = space.shows && Object.hasOwn(space.shows, name) ? space.shows[name] : null;
|
|
415
1010
|
if (!list || !('database' in list)) throw protocolError('This view does not declare that list with a filter.', 'listUnavailable');
|
|
416
|
-
return shown<TResult>(name, params, options);
|
|
1011
|
+
if (!asPublic) return shown<TResult>(name, params, options);
|
|
1012
|
+
const visible = space.params ? Object.fromEntries(Object.entries(params).filter(([param]) => Object.hasOwn(space.params!, param))) : params;
|
|
1013
|
+
const floor = floorOf(list.database);
|
|
1014
|
+
// The declared filter may read an editor-only column; the caller's sorts may not.
|
|
1015
|
+
if (floor.hidden.size && namesEditorColumn(options, floor)) throw columnRefused('readUnavailable');
|
|
1016
|
+
return floorResult(await shown<TResult>(name, visible, options), floor, learnOf(list.database));
|
|
417
1017
|
} : undefined,
|
|
418
1018
|
handover: undefined,
|
|
1019
|
+
...(asPublic ? { spaceFiles: undefined } : {}),
|
|
419
1020
|
// The legacy facts hook keeps working in a Space that declares the cloud computer.
|
|
420
1021
|
cloudComputerFacts: cloudComputer && cloudLevel ? async (options?: { refresh?: boolean }) => guardedCloud('facts').facts(options) : undefined,
|
|
421
1022
|
spaceCloudComputer: cloudComputer && cloudLevel ? Object.freeze({
|
|
@@ -424,19 +1025,52 @@ export function guardSpaceRuntime(runtime: NotisRuntime | null, onProtocolError?
|
|
|
424
1025
|
facts: async (options?: { refresh?: boolean }) => guardedCloud('facts').facts(options),
|
|
425
1026
|
run: async (input: SpaceCloudComputerRunInput) => guardedCloud('run').run(input),
|
|
426
1027
|
upload: async (input: SpaceCloudComputerUploadInput) => guardedCloud('upload').upload(input),
|
|
427
|
-
|
|
1028
|
+
lease: lease ? async (input: SpaceCloudComputerLeaseInput) => {
|
|
1029
|
+
guardedCloud('service.lease');
|
|
1030
|
+
declaredService(input?.service);
|
|
1031
|
+
return lease.call(cloudComputer, input);
|
|
1032
|
+
} : undefined,
|
|
1033
|
+
access: access ? async (input: SpaceCloudComputerAccessInput) => {
|
|
1034
|
+
guardedCloud('service.access');
|
|
1035
|
+
declaredService(input?.service);
|
|
1036
|
+
return access.call(cloudComputer, input);
|
|
1037
|
+
} : undefined,
|
|
1038
|
+
job: job ? async <O extends SpaceCloudComputerJobOperation>(operation: O, input: SpaceCloudComputerJobInput) => {
|
|
1039
|
+
if (operation !== 'job.status' && operation !== 'job.logs' && operation !== 'job.cancel') {
|
|
1040
|
+
throw protocolError('Choose a supported Cloud Computer job operation.');
|
|
1041
|
+
}
|
|
1042
|
+
guardedCloud(operation);
|
|
1043
|
+
return cloudComputer.job!<O>(operation, input);
|
|
1044
|
+
} : undefined,
|
|
1045
|
+
folder: folder ? async () => { guardedCloud('folder'); return folder.call(cloudComputer); } : undefined,
|
|
1046
|
+
sendFile: sendFile ? async (input: SpaceCloudComputerFileUpload) => {
|
|
1047
|
+
guardedCloud('transfer.begin');
|
|
1048
|
+
return sendFile.call(cloudComputer, input);
|
|
1049
|
+
} : undefined,
|
|
1050
|
+
importUrl: importUrl ? async (input: SpaceCloudComputerImportInput) => {
|
|
1051
|
+
guardedCloud('import');
|
|
1052
|
+
return importUrl.call(cloudComputer, input);
|
|
1053
|
+
} : undefined,
|
|
1054
|
+
} satisfies SpaceCloudComputerTransport) : undefined,
|
|
428
1055
|
viewerRead: viewerRead ? async function guardedViewerRead<TResult>(operation: SpaceViewerReadOperation,
|
|
429
1056
|
input: Record<string, unknown> = {}): Promise<TResult> {
|
|
430
1057
|
const family = Object.hasOwn(SPACE_VIEWER_READ_OPERATIONS, operation) ? SPACE_VIEWER_READ_OPERATIONS[operation] : null;
|
|
431
1058
|
if (!family) throw protocolError('Viewer reads never change data. Choose a supported read.', 'readUnavailable');
|
|
432
|
-
if (!
|
|
1059
|
+
if (!space.viewerReads?.includes(family)) throw protocolError(`This Space does not declare viewer reads of ${family}.`, 'readUnavailable');
|
|
433
1060
|
return viewerRead<TResult>(operation, input);
|
|
434
1061
|
} : undefined,
|
|
435
1062
|
async callAction<TResult>(id: string, inputs: Record<string, unknown> = {}, options: SpaceActionOptions = {}): Promise<TResult> {
|
|
436
|
-
const descriptor = Object.hasOwn(
|
|
437
|
-
if (!descriptor) throw
|
|
1063
|
+
const descriptor = Object.hasOwn(space.actions, id) ? space.actions[id] : null;
|
|
1064
|
+
if (!descriptor) throw undeclared(options.readOnly || options.dedupe ? 'actionUnavailable' : undefined);
|
|
438
1065
|
if ((options.readOnly || options.dedupe) && !descriptor.readOnly) throw protocolError('A write action cannot run as a cached read.', 'readUnavailable');
|
|
439
|
-
return callAction<TResult>(id, inputs, options);
|
|
1066
|
+
if (!asPublic) return callAction<TResult>(id, inputs, options);
|
|
1067
|
+
// A row operation of one binding reads that binding; a named action, or one several bindings share, any of them.
|
|
1068
|
+
const alias = aliasOfAction(id);
|
|
1069
|
+
const floor = floorOf(alias);
|
|
1070
|
+
// Every input is checked, not only `request`: a named action's inputs may carry a filter or a row write too.
|
|
1071
|
+
// A template that maps a plain input onto an editor-only column cannot be seen from here; the server refuses it.
|
|
1072
|
+
if (floor.hidden.size && namesEditorColumn(inputs, floor)) throw columnRefused(options.readOnly || options.dedupe ? 'readUnavailable' : undefined);
|
|
1073
|
+
return floorResult(await callAction<TResult>(id, inputs, options), floor, learnOf(alias));
|
|
440
1074
|
},
|
|
441
1075
|
});
|
|
442
1076
|
}
|