@40rty/ams-sdk 0.5.0 → 0.5.2

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 (24) hide show
  1. package/dist/index.js +816 -548
  2. package/dist/types/sdk/src/analytics/index.d.ts +1 -1
  3. package/dist/types/sdk/src/analytics/outbox.d.ts +2 -0
  4. package/dist/types/sdk/src/analytics/scope-context.d.ts +2 -0
  5. package/dist/types/sdk/src/analytics/scope.d.ts +7 -0
  6. package/dist/types/sdk/src/host/host-modules.d.ts +275 -36
  7. package/dist/types/spacestation/src/analytics/envelope.d.ts +24 -0
  8. package/dist/types/spacestation/src/attachment/attachment.d.ts +8 -5
  9. package/dist/types/spacestation/src/catalog/element-filled.d.ts +2 -2
  10. package/dist/types/spacestation/src/catalog/wire/index.d.ts +2 -0
  11. package/dist/types/spacestation/src/catalog/wire/package-bundle-ref.d.ts +30 -0
  12. package/dist/types/spacestation/src/catalog/wire/package-release.d.ts +20 -0
  13. package/dist/types/spacestation/src/catalog/wire/sdk-compat.d.ts +43 -0
  14. package/dist/types/spacestation/src/contracts/socket-ticket-param.d.ts +9 -0
  15. package/dist/types/spacestation/src/contracts/wire-protocol.d.ts +25 -0
  16. package/dist/types/spacestation/src/index.d.ts +5 -1
  17. package/dist/types/spacestation/src/space/agent-directive.d.ts +239 -0
  18. package/dist/types/spacestation/src/space/session-queue.d.ts +24 -24
  19. package/dist/types/spacestation/src/space/trace.d.ts +12 -12
  20. package/dist/types/spacestation/src/trace/trace-diagnostics.d.ts +8 -0
  21. package/dist/types/spacestation/src/trace/trace-events.d.ts +1 -0
  22. package/dist/types/spacestation/src/widgets/presence/index.d.ts +1 -1
  23. package/dist/types/spacestation/src/widgets/presence/scan.d.ts +21 -0
  24. package/package.json +1 -1
@@ -114,18 +114,29 @@ export declare const AnalyticsWireEventSchema: z.ZodObject<{
114
114
  sessionId: z.ZodString;
115
115
  kind: z.ZodString;
116
116
  payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
117
+ /**
118
+ * The agent turn whose canvas the event came from — stamped by the scope
119
+ * from the element the emit ran inside, never by the emit site; `null` when
120
+ * it ran outside any turn (the cart drawer, a root bridge). OPTIONAL because
121
+ * a bundle older than this field omits it, and the envelope's strip posture
122
+ * (header) is what keeps that bundle's batch alive. Lands in the typed
123
+ * `client_events.turn_id` column — the join to `agent_runs.turn_id`.
124
+ */
125
+ turnId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
117
126
  }, "strip", z.ZodTypeAny, {
118
127
  kind: string;
119
128
  payload: Record<string, unknown>;
120
129
  eventId: string;
121
130
  occurredAt: number;
122
131
  sessionId: string;
132
+ turnId?: string | null | undefined;
123
133
  }, {
124
134
  kind: string;
125
135
  payload: Record<string, unknown>;
126
136
  eventId: string;
127
137
  occurredAt: number;
128
138
  sessionId: string;
139
+ turnId?: string | null | undefined;
129
140
  }>;
130
141
  export type AnalyticsWireEvent = z.infer<typeof AnalyticsWireEventSchema>;
131
142
  /**
@@ -179,18 +190,29 @@ export declare const AnalyticsBatchSchema: z.ZodObject<{
179
190
  sessionId: z.ZodString;
180
191
  kind: z.ZodString;
181
192
  payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
193
+ /**
194
+ * The agent turn whose canvas the event came from — stamped by the scope
195
+ * from the element the emit ran inside, never by the emit site; `null` when
196
+ * it ran outside any turn (the cart drawer, a root bridge). OPTIONAL because
197
+ * a bundle older than this field omits it, and the envelope's strip posture
198
+ * (header) is what keeps that bundle's batch alive. Lands in the typed
199
+ * `client_events.turn_id` column — the join to `agent_runs.turn_id`.
200
+ */
201
+ turnId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
182
202
  }, "strip", z.ZodTypeAny, {
183
203
  kind: string;
184
204
  payload: Record<string, unknown>;
185
205
  eventId: string;
186
206
  occurredAt: number;
187
207
  sessionId: string;
208
+ turnId?: string | null | undefined;
188
209
  }, {
189
210
  kind: string;
190
211
  payload: Record<string, unknown>;
191
212
  eventId: string;
192
213
  occurredAt: number;
193
214
  sessionId: string;
215
+ turnId?: string | null | undefined;
194
216
  }>, "many">;
195
217
  }, "strip", z.ZodTypeAny, {
196
218
  scopeId: string;
@@ -204,6 +226,7 @@ export declare const AnalyticsBatchSchema: z.ZodObject<{
204
226
  eventId: string;
205
227
  occurredAt: number;
206
228
  sessionId: string;
229
+ turnId?: string | null | undefined;
207
230
  }[];
208
231
  }, {
209
232
  scopeId: string;
@@ -217,6 +240,7 @@ export declare const AnalyticsBatchSchema: z.ZodObject<{
217
240
  eventId: string;
218
241
  occurredAt: number;
219
242
  sessionId: string;
243
+ turnId?: string | null | undefined;
220
244
  }[];
221
245
  }>;
222
246
  export type AnalyticsBatch = z.infer<typeof AnalyticsBatchSchema>;
@@ -5,7 +5,9 @@
5
5
  * Transport: upload-on-attach → reference. The bytes are uploaded to storage
6
6
  * the moment the visitor attaches the file; only this lightweight `AttachmentRef`
7
7
  * rides the `prompt` signal, so send-time / TTFT stays clean. The agent resolves
8
- * the bytes at turn start and inlines them as image/file parts.
8
+ * the bytes at turn start BY `id`, from storage under its own session, and
9
+ * inlines them as image/file parts. It never fetches `url`: that came from the
10
+ * visitor, and fetching it made the server an SSRF proxy.
9
11
  *
10
12
  * One home for the allow-list: both the composer (accept attribute + client
11
13
  * pre-check), the upload endpoint (server validation), and any agent-side guard
@@ -26,12 +28,13 @@ export declare function isImageAttachment(mime: string): boolean;
26
28
  * A stored attachment, returned by `POST /sessions/:id/attachments` and carried
27
29
  * on the `prompt` signal payload (`attachments: AttachmentRef[]`).
28
30
  *
29
- * `url` is a fetchable location for the bytes (Supabase Storage). The agent
30
- * fetches it at turn start; the composer never renders `url` for image previews
31
+ * `id` is what the server resolves the bytes by. `url` is a signed Supabase
32
+ * Storage link handed back to the uploader and kept on the wire for engines
33
+ * that already parse it; no server reads it, and the composer never renders it
31
34
  * (it shows the local object URL it already holds).
32
35
  */
33
36
  export interface AttachmentRef {
34
- /** Server-minted id, unique within the session. */
37
+ /** Server-minted UUID, unique within the session — the storage key under it. */
35
38
  id: string;
36
39
  /** Validated MIME type — always one of `ALLOWED_ATTACHMENT_TYPES`. */
37
40
  mimeType: string;
@@ -39,7 +42,7 @@ export interface AttachmentRef {
39
42
  name: string;
40
43
  /** Byte length — within `MAX_ATTACHMENT_BYTES`. */
41
44
  size: number;
42
- /** Fetchable bytes location (Supabase Storage public/signed URL). */
45
+ /** Signed Supabase Storage URL for the uploader. Never fetched server-side. */
43
46
  url: string;
44
47
  }
45
48
  export declare const AttachmentRefSchema: z.ZodObject<{
@@ -35,8 +35,8 @@ export interface ElementFilledOptions {
35
35
  * NEVER from a component-name or prop-name hardcode (IV.1: the catalog is the
36
36
  * single source of truth):
37
37
  *
38
- * - a `resolved()` entity-ref path is absent / holds no refs (a productGrid
39
- * with no products), or
38
+ * - a REQUIRED `resolved()` entity-ref path is absent / holds no refs (a
39
+ * productGrid with no products) — an optional one never blanks it, or
40
40
  * - a required (non-optional) non-entity prop is absent / empty (an
41
41
  * editorialText with no `paragraphs`, a `pullQuote` with no `quote`).
42
42
  *
@@ -3,4 +3,6 @@ export { schemaToWire, UnsupportedSchemaError } from './schema-to-wire';
3
3
  export { schemaFromWire } from './schema-from-wire';
4
4
  export { WireCatalogSchema, WireCatalogEntrySchema, catalogToWire, catalogFromWire, type WireCatalog, type WireCatalogEntry, } from './catalog-wire';
5
5
  export { PackageReleaseSchema, draftSourceId, isDraftSource, releasePreviewSourceId, parseReleasePreview, type PackageRelease } from './package-release';
6
+ export { SDK_VERSION_PATTERN, SdkVersionSchema, OLDEST_SUPPORTED_SDK, SDK_SHIMS, compareSdkVersions, sdkShimsFor, sdkWindowProblem, type SdkShim, } from './sdk-compat';
7
+ export { PackageBundleRefSchema, type PackageBundleRef } from './package-bundle-ref';
6
8
  export { BRAND_MARK_TYPES, BRAND_MARK_SLOTS, BRAND_MARK_MAX_BYTES, BrandMarkSchema, BrandMarkImageSchema, SpaceBrandMarkSchema, type BrandMark, type BrandMarkFile, type BrandMarkUpload, type BrandMarkStored, type BrandMarkSlot, type BrandMarkType, type BrandMarkImage, type SpaceBrandMark, } from './brand-mark';
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Where one published source's components are served from — immutable URLs in
4
+ * object storage — as the api hands it to a page and the page to the renderer.
5
+ */
6
+ export declare const PackageBundleRefSchema: z.ZodObject<{
7
+ sourceId: z.ZodString;
8
+ js: z.ZodString;
9
+ css: z.ZodString;
10
+ /** The brand's name for itself, and its package's version. */
11
+ label: z.ZodString;
12
+ version: z.ZodString;
13
+ /** The sdk the bundle was built against (`PackageRelease.builtWithSdk`) — absent for a legacy release. Picks its compat shims. */
14
+ builtWithSdk: z.ZodOptional<z.ZodString>;
15
+ }, "strip", z.ZodTypeAny, {
16
+ label: string;
17
+ sourceId: string;
18
+ version: string;
19
+ js: string;
20
+ css: string;
21
+ builtWithSdk?: string | undefined;
22
+ }, {
23
+ label: string;
24
+ sourceId: string;
25
+ version: string;
26
+ js: string;
27
+ css: string;
28
+ builtWithSdk?: string | undefined;
29
+ }>;
30
+ export type PackageBundleRef = z.infer<typeof PackageBundleRefSchema>;
@@ -17,6 +17,14 @@ export declare const PackageReleaseSchema: z.ZodObject<{
17
17
  version: z.ZodString;
18
18
  /** What this release changed, in the publisher's words (`forty publish --message`) — shown in the console's version list. */
19
19
  description: z.ZodOptional<z.ZodString>;
20
+ /**
21
+ * The `@40rty/ams-sdk` version the brand project resolved when `forty
22
+ * publish` built this release. A bundle takes the sdk from the page at
23
+ * runtime, so this is what tells the platform which compat shims it needs
24
+ * and whether it can host it at all (`sdk-compat.ts`). Absent on releases
25
+ * published before the stamp existed — those are legacy.
26
+ */
27
+ builtWithSdk: z.ZodOptional<z.ZodString>;
20
28
  catalog: z.ZodRecord<z.ZodString, z.ZodObject<{
21
29
  type: z.ZodString;
22
30
  propsSchema: z.ZodOptional<z.ZodType<import("./wire-schema").WireSchema, z.ZodTypeDef, import("./wire-schema").WireSchema>>;
@@ -313,6 +321,14 @@ export declare const PackageReleaseSchema: z.ZodObject<{
313
321
  order: number;
314
322
  content: string;
315
323
  }>, "many">>;
324
+ /**
325
+ * The brand's SPACE prompt — its `prompts/space.md`, verbatim: sections split
326
+ * by `<!-- section:<id> -->` markers, the same format as the platform's
327
+ * `prompts/spaces/<slug>.md`, which it replaces for any space bound to this
328
+ * package. How the brand speaks, what it sells and what it never claims ship
329
+ * with the brand, and a release changes them with no platform deploy.
330
+ */
331
+ spacePrompt: z.ZodOptional<z.ZodString>;
316
332
  /**
317
333
  * Opaque per-vertical extension data (`BrandDefinition.config`): the
318
334
  * platform stays vertical-agnostic and the vertical's own code reads its keys.
@@ -366,6 +382,7 @@ export declare const PackageReleaseSchema: z.ZodObject<{
366
382
  manifests: Record<string, string>;
367
383
  config?: Record<string, unknown> | undefined;
368
384
  description?: string | undefined;
385
+ builtWithSdk?: string | undefined;
369
386
  bundle?: {
370
387
  js: string;
371
388
  css: string;
@@ -408,6 +425,7 @@ export declare const PackageReleaseSchema: z.ZodObject<{
408
425
  order: number;
409
426
  content: string;
410
427
  }[] | undefined;
428
+ spacePrompt?: string | undefined;
411
429
  draft?: {
412
430
  of: string;
413
431
  space: string;
@@ -446,6 +464,7 @@ export declare const PackageReleaseSchema: z.ZodObject<{
446
464
  manifests: Record<string, string>;
447
465
  config?: Record<string, unknown> | undefined;
448
466
  description?: string | undefined;
467
+ builtWithSdk?: string | undefined;
449
468
  bundle?: {
450
469
  js: string;
451
470
  css: string;
@@ -488,6 +507,7 @@ export declare const PackageReleaseSchema: z.ZodObject<{
488
507
  order: number;
489
508
  content: string;
490
509
  }[] | undefined;
510
+ spacePrompt?: string | undefined;
491
511
  draft?: {
492
512
  of: string;
493
513
  space: string;
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The version contract between a PUBLISHED bundle and the platform that hosts
4
+ * it. A bundle takes `@40rty/ams-sdk` from the page at runtime (the host module
5
+ * map), so it runs against whatever sdk the platform serves today — not the one
6
+ * it was built with. `forty publish` stamps the release with the sdk version the
7
+ * brand project resolved (`builtWithSdk`); this module is the ONE place that
8
+ * says which stamps the platform can host and which compat shims each needs.
9
+ *
10
+ * A release with no stamp predates the stamp: it is LEGACY, treated as the
11
+ * oldest supported sdk — admitted, and given every shim.
12
+ */
13
+ /** A published sdk version: `1.2.3` or `1.2.3-next.4`. */
14
+ export declare const SDK_VERSION_PATTERN: RegExp;
15
+ export declare const SdkVersionSchema: z.ZodString;
16
+ /**
17
+ * The oldest sdk a release may be built against and still be bound to a space.
18
+ * The upper bound is the platform's own sdk version — a bundle built against a
19
+ * newer sdk calls exports this platform does not have.
20
+ */
21
+ export declare const OLDEST_SUPPORTED_SDK = "0.3.0";
22
+ /**
23
+ * Every compat shim the host map applies, and the sdk version it stops being
24
+ * needed at. A shim is deleted once no live release is below its `below`
25
+ * (`GET /admin/package-sdk` answers that).
26
+ */
27
+ export declare const SDK_SHIMS: {
28
+ /** sdk ≤ 0.3 called the vertical verbs on `useCanvasActions()` — `legacy-canvas-actions.ts`. */
29
+ readonly legacyCanvasActions: {
30
+ readonly below: "0.4.0";
31
+ };
32
+ };
33
+ export type SdkShim = keyof typeof SDK_SHIMS;
34
+ /** Semver order of two sdk versions (prerelease below its release). Negative when `a` is older. */
35
+ export declare function compareSdkVersions(a: string, b: string): number;
36
+ /** The shims a bundle built against `builtWithSdk` needs. Unstamped = legacy = every shim. */
37
+ export declare function sdkShimsFor(builtWithSdk: string | undefined): SdkShim[];
38
+ /**
39
+ * Why a release built against `builtWithSdk` cannot be bound to a space on a
40
+ * platform serving `platformSdk` — `null` when it can. Unstamped releases are
41
+ * admitted: they are legacy, and legacy keeps working until a deliberate cutoff.
42
+ */
43
+ export declare function sdkWindowProblem(builtWithSdk: string | undefined, platformSdk: string): string | null;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The query parameter a visitor socket upgrade carries its socket ticket on.
3
+ *
4
+ * A wire contract between every dialer (the engine, the pre-hydration boot dial,
5
+ * the CLI) and the api's upgrade gate, so it lives here once. A browser
6
+ * WebSocket cannot set headers, which is why it rides the URL; the ticket is
7
+ * single-purpose and expires in seconds (`@fourty/platform/socket-ticket`).
8
+ */
9
+ export declare const SOCKET_TICKET_PARAM = "ticket";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The visitor/trace socket's protocol version — the contract between every
3
+ * engine ever published (`/embed/engine/:version`, served forever) and the api
4
+ * it talks to today. ONE number for the whole socket: the frames the engine
5
+ * sends and the `TraceEvent` union it reads.
6
+ *
7
+ * Bump `WIRE_PROTOCOL_VERSION` when a change would make an older engine
8
+ * mis-render (a variant renamed or reshaped, a frame it must send). Raise
9
+ * `MIN_WIRE_PROTOCOL_VERSION` only as the deliberate cutoff, once the older
10
+ * engines are gone: the api then closes their sockets with
11
+ * `WIRE_PROTOCOL_UNSUPPORTED_CLOSE` instead of letting them mis-render.
12
+ *
13
+ * An upgrade that carries NO version is an engine built before this contract.
14
+ * It is admitted (and logged) until the cutoff — see `docs/adr/0006`.
15
+ */
16
+ export declare const WIRE_PROTOCOL_VERSION = 1;
17
+ export declare const MIN_WIRE_PROTOCOL_VERSION = 1;
18
+ /** The query parameter the upgrade carries the version on, beside the socket ticket. */
19
+ export declare const WIRE_PROTOCOL_PARAM = "protocol";
20
+ /**
21
+ * The close code a refused engine receives, right after the upgrade — a refusal
22
+ * BEFORE the upgrade is an HTTP status a browser WebSocket never shows its page.
23
+ * The close reason says which versions the api accepts.
24
+ */
25
+ export declare const WIRE_PROTOCOL_UNSUPPORTED_CLOSE = 4426;
@@ -31,7 +31,7 @@ export { isElementUnfilled, rendersNothing } from './catalog/element-filled';
31
31
  export { carriesShapeToken } from './catalog/shape-tokens';
32
32
  export { applySinglePatch } from './layout/apply-patch';
33
33
  export { derivePropsDoc } from './catalog/derive-props-doc';
34
- export { WireSchemaSchema, WireCatalogSchema, WireCatalogEntrySchema, schemaToWire, schemaFromWire, catalogToWire, catalogFromWire, UnsupportedSchemaError, PackageReleaseSchema, draftSourceId, isDraftSource, releasePreviewSourceId, parseReleasePreview, BRAND_MARK_TYPES, BRAND_MARK_SLOTS, BRAND_MARK_MAX_BYTES, BrandMarkSchema, BrandMarkImageSchema, SpaceBrandMarkSchema, type BrandMark, type BrandMarkFile, type BrandMarkUpload, type BrandMarkStored, type BrandMarkSlot, type BrandMarkType, type BrandMarkImage, type SpaceBrandMark, type PackageRelease, type WireSchema, type WireCatalog, type WireCatalogEntry, } from './catalog/wire';
34
+ export { WireSchemaSchema, WireCatalogSchema, WireCatalogEntrySchema, schemaToWire, schemaFromWire, catalogToWire, catalogFromWire, UnsupportedSchemaError, PackageReleaseSchema, draftSourceId, isDraftSource, releasePreviewSourceId, parseReleasePreview, SDK_VERSION_PATTERN, SdkVersionSchema, OLDEST_SUPPORTED_SDK, SDK_SHIMS, compareSdkVersions, sdkShimsFor, sdkWindowProblem, type SdkShim, PackageBundleRefSchema, type PackageBundleRef, BRAND_MARK_TYPES, BRAND_MARK_SLOTS, BRAND_MARK_MAX_BYTES, BrandMarkSchema, BrandMarkImageSchema, SpaceBrandMarkSchema, type BrandMark, type BrandMarkFile, type BrandMarkUpload, type BrandMarkStored, type BrandMarkSlot, type BrandMarkType, type BrandMarkImage, type SpaceBrandMark, type PackageRelease, type WireSchema, type WireCatalog, type WireCatalogEntry, } from './catalog/wire';
35
35
  export { LateBoundValueSchema, DirectiveValueSchema, ProjectionDirectiveSchema, ProjectionPreferencesSchema, ProjectionSetPayloadSchema, PROJECTION_SET_SIGNAL, isLateBound, isActiveDirective, projectCollection, type LateBoundValue, type DirectiveValue, type ProjectionDirective, type ProjectionPreferences, type ProjectionSetPayload, type ProjectionAccessors, } from './projection/projection';
36
36
  export { VIEW_FOCUS_ELEMENT_SIGNAL, FocusElementPayloadSchema, type FocusElementPayload, } from './focus/focus';
37
37
  export { VIEW_EXTEND_SIGNAL, VIEW_EXHAUSTED_SIGNAL, ViewExtendPayloadSchema, CONTINUATION_ENABLED, type ViewExtendPayload, } from './view/continuation';
@@ -41,11 +41,15 @@ export { ALLOWED_ATTACHMENT_TYPES, MAX_ATTACHMENT_BYTES, isAllowedAttachmentType
41
41
  export { ENTRY_CONTEXT_MAX_VALUE_CHARS, ENTRY_CONTEXT_MAX_KEYS, ENTRY_CONTEXT_MAX_NAMESPACES, ENTRY_CONTEXT_MAX_NAME_CHARS, EntryContextValueSchema, EntryContextNamespaceSchema, EntryContextSchema, type EntryContext, } from './contracts/entry-context';
42
42
  export { ARRIVAL_MAX_VALUE_CHARS, SURFACES, SurfaceSchema, type Surface, CLICK_ID_KINDS, ClickIdKindSchema, type ClickIdKind, VISITOR_ID_DURABILITIES, VisitorIdDurabilitySchema, type VisitorIdDurability, TRAFFIC_BUCKETS, TrafficBucketSchema, type TrafficBucket, SessionArrivalSchema, type SessionArrival, type RecordedSessionArrival, } from './contracts/session-arrival';
43
43
  export { ARRIVAL_PARAMS, REFERRER_HOST_PARAM, arrivalFromParams, arrivalToParams, type ArrivalEvidence, } from './contracts/session-arrival-params';
44
+ export { SOCKET_TICKET_PARAM } from './contracts/socket-ticket-param';
45
+ export { WIRE_PROTOCOL_VERSION, MIN_WIRE_PROTOCOL_VERSION, WIRE_PROTOCOL_PARAM, WIRE_PROTOCOL_UNSUPPORTED_CLOSE, } from './contracts/wire-protocol';
44
46
  export { type AttributeDef, type AttributeRegistry, type AttributeScopeBucket, type AttributeScopeConfig, AttributeDefSchema, AttributeScopeBucketSchema, AttributeScopeConfigSchema, EXTRAS_PREFIX, } from './catalog/attribute-registry';
45
47
  export { resolveScope, normalizeAttributeField, scopedAttributeKey, scopeOfAttributeKey, } from './catalog/attribute-scope';
46
48
  export type { Space, SpaceName, CreateSpaceInput, UpdateSpaceInput, SpaceConnector, UpsertSpaceConnectorInput } from './space/space';
47
49
  export type { HostedApp, SpaceConfig, SpaceWithConfig, VisitorAccess } from './space/space-config';
48
50
  export type { ConnectorDescriptor, ConnectorFieldDescriptor } from './space/connector';
51
+ export { AgentDirectiveSchema, SpaceAgentDirectiveSchema, SpaceAgentDirectiveListItemSchema, UpdateAgentDirectiveInputSchema, ReorderAgentDirectivesInputSchema, AGENT_DIRECTIVE_KINDS, AGENT_DIRECTIVE_SEVERITIES, AGENT_DIRECTIVE_SOURCES, AGENT_DIRECTIVE_STATUSES, MAX_ACTIVE_AGENT_DIRECTIVES, } from './space/agent-directive';
52
+ export type { AgentDirective, SpaceAgentDirective, SpaceAgentDirectiveListItem, UpdateAgentDirectiveInput, } from './space/agent-directive';
49
53
  export { DEFAULT_SPACE_CONFIG, DEFAULT_VISITOR_ACCESS, VISITOR_ACCESS, visitorAccessOf, } from './space/space-config';
50
54
  export type { ThemePackageOption, BrandDefinition, BrandPromptSection } from './space/workspace-catalog';
51
55
  export { COMPONENT_SOURCE, THEME_PACKAGE, THEME_CLASS, COMPONENT_SOURCE_DEFAULT_THEME, WORKSPACE_THEME_PACKAGES, } from './space/workspace-catalog';
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Space agent directives — the wire contract of the store that holds everything
3
+ * a space's agent has been TAUGHT (`space_agent_directives`).
4
+ *
5
+ * ONE definition, shared by the api routes that write the store, the console
6
+ * that edits it and the agent that renders it — so the three cannot disagree
7
+ * about what a directive is. The agent's render side is
8
+ * `@fourty/agent`'s `agent-directives.ts`.
9
+ *
10
+ * A directive is the same thing to the agent whoever taught it: the space
11
+ * owner, an operator, or a lesson mined from what worked with the space's
12
+ * visitors. `source` and the lifecycle fields are for the people reviewing the
13
+ * list; only `AgentDirective` reaches the prompt.
14
+ */
15
+ import { z } from 'zod';
16
+ /** At most this many ACTIVE directives per space — a product decision fixed for
17
+ * v1. Prose is where a cap rots silently: nothing throws when a thirteenth rule
18
+ * is pasted in, the prompt just gets longer. */
19
+ export declare const MAX_ACTIVE_AGENT_DIRECTIVES = 12;
20
+ /** What KIND of directive — how an evidence report tells a preference from a
21
+ * promise. */
22
+ export declare const AGENT_DIRECTIVE_KINDS: readonly ["preference", "pairing", "order of things", "promise", "threshold"];
23
+ /** What a miss costs. Read in the prompt as "a miss is <severity>". */
24
+ export declare const AGENT_DIRECTIVE_SEVERITIES: readonly ["a missed opportunity", "a problem", "unacceptable"];
25
+ /** Who taught the agent this. Never rendered into the prompt. */
26
+ export declare const AGENT_DIRECTIVE_SOURCES: readonly ["owner", "operator", "session-lesson"];
27
+ /** Where a directive is in its life. Only `active` reaches the agent; a mined
28
+ * lesson arrives `proposed` and waits for a person. */
29
+ export declare const AGENT_DIRECTIVE_STATUSES: readonly ["proposed", "active", "rejected", "retired"];
30
+ /**
31
+ * One directive's CONTENT — what the agent receives, and what a person writes.
32
+ */
33
+ export declare const AgentDirectiveSchema: z.ZodObject<{
34
+ name: z.ZodString;
35
+ kind: z.ZodEnum<["preference", "pairing", "order of things", "promise", "threshold"]>;
36
+ severity: z.ZodEnum<["a missed opportunity", "a problem", "unacceptable"]>;
37
+ /** No bare URL: a URL is a hallucination surface, and a handle is not a
38
+ * product name. */
39
+ text: z.ZodEffects<z.ZodString, string, string>;
40
+ }, "strict", z.ZodTypeAny, {
41
+ kind: "promise" | "preference" | "pairing" | "order of things" | "threshold";
42
+ name: string;
43
+ text: string;
44
+ severity: "a missed opportunity" | "a problem" | "unacceptable";
45
+ }, {
46
+ kind: "promise" | "preference" | "pairing" | "order of things" | "threshold";
47
+ name: string;
48
+ text: string;
49
+ severity: "a missed opportunity" | "a problem" | "unacceptable";
50
+ }>;
51
+ export type AgentDirective = z.infer<typeof AgentDirectiveSchema>;
52
+ /** One stored directive, as the console lists it. */
53
+ export declare const SpaceAgentDirectiveSchema: z.ZodObject<{
54
+ id: z.ZodString;
55
+ position: z.ZodNumber;
56
+ name: z.ZodString;
57
+ kind: z.ZodEnum<["preference", "pairing", "order of things", "promise", "threshold"]>;
58
+ severity: z.ZodEnum<["a missed opportunity", "a problem", "unacceptable"]>;
59
+ text: z.ZodString;
60
+ source: z.ZodEnum<["owner", "operator", "session-lesson"]>;
61
+ status: z.ZodEnum<["proposed", "active", "rejected", "retired"]>;
62
+ /** Who wrote it; null for a lesson the system proposed. */
63
+ createdBy: z.ZodNullable<z.ZodString>;
64
+ /** Why a mined lesson was proposed; null for a directive a person wrote. */
65
+ evidence: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
66
+ decidedBy: z.ZodNullable<z.ZodString>;
67
+ decidedAt: z.ZodNullable<z.ZodString>;
68
+ createdAt: z.ZodString;
69
+ }, "strip", z.ZodTypeAny, {
70
+ status: "proposed" | "active" | "rejected" | "retired";
71
+ kind: "promise" | "preference" | "pairing" | "order of things" | "threshold";
72
+ id: string;
73
+ name: string;
74
+ text: string;
75
+ source: "owner" | "operator" | "session-lesson";
76
+ severity: "a missed opportunity" | "a problem" | "unacceptable";
77
+ position: number;
78
+ createdBy: string | null;
79
+ evidence: Record<string, unknown> | null;
80
+ decidedBy: string | null;
81
+ decidedAt: string | null;
82
+ createdAt: string;
83
+ }, {
84
+ status: "proposed" | "active" | "rejected" | "retired";
85
+ kind: "promise" | "preference" | "pairing" | "order of things" | "threshold";
86
+ id: string;
87
+ name: string;
88
+ text: string;
89
+ source: "owner" | "operator" | "session-lesson";
90
+ severity: "a missed opportunity" | "a problem" | "unacceptable";
91
+ position: number;
92
+ createdBy: string | null;
93
+ evidence: Record<string, unknown> | null;
94
+ decidedBy: string | null;
95
+ decidedAt: string | null;
96
+ createdAt: string;
97
+ }>;
98
+ export type SpaceAgentDirective = z.infer<typeof SpaceAgentDirectiveSchema>;
99
+ /**
100
+ * A directive as the console LISTS it — with `impact` for an active learned
101
+ * one: its topic's acted turns before activation against since. Null for
102
+ * anything not measurable (a person's directive, or a lesson not yet active).
103
+ */
104
+ export declare const SpaceAgentDirectiveListItemSchema: z.ZodObject<{
105
+ id: z.ZodString;
106
+ position: z.ZodNumber;
107
+ name: z.ZodString;
108
+ kind: z.ZodEnum<["preference", "pairing", "order of things", "promise", "threshold"]>;
109
+ severity: z.ZodEnum<["a missed opportunity", "a problem", "unacceptable"]>;
110
+ text: z.ZodString;
111
+ source: z.ZodEnum<["owner", "operator", "session-lesson"]>;
112
+ status: z.ZodEnum<["proposed", "active", "rejected", "retired"]>;
113
+ /** Who wrote it; null for a lesson the system proposed. */
114
+ createdBy: z.ZodNullable<z.ZodString>;
115
+ /** Why a mined lesson was proposed; null for a directive a person wrote. */
116
+ evidence: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
117
+ decidedBy: z.ZodNullable<z.ZodString>;
118
+ decidedAt: z.ZodNullable<z.ZodString>;
119
+ createdAt: z.ZodString;
120
+ } & {
121
+ impact: z.ZodNullable<z.ZodObject<{
122
+ before: z.ZodObject<{
123
+ turns: z.ZodNumber;
124
+ acted: z.ZodNumber;
125
+ }, "strip", z.ZodTypeAny, {
126
+ turns: number;
127
+ acted: number;
128
+ }, {
129
+ turns: number;
130
+ acted: number;
131
+ }>;
132
+ after: z.ZodObject<{
133
+ turns: z.ZodNumber;
134
+ acted: z.ZodNumber;
135
+ }, "strip", z.ZodTypeAny, {
136
+ turns: number;
137
+ acted: number;
138
+ }, {
139
+ turns: number;
140
+ acted: number;
141
+ }>;
142
+ }, "strip", z.ZodTypeAny, {
143
+ before: {
144
+ turns: number;
145
+ acted: number;
146
+ };
147
+ after: {
148
+ turns: number;
149
+ acted: number;
150
+ };
151
+ }, {
152
+ before: {
153
+ turns: number;
154
+ acted: number;
155
+ };
156
+ after: {
157
+ turns: number;
158
+ acted: number;
159
+ };
160
+ }>>;
161
+ }, "strip", z.ZodTypeAny, {
162
+ status: "proposed" | "active" | "rejected" | "retired";
163
+ kind: "promise" | "preference" | "pairing" | "order of things" | "threshold";
164
+ id: string;
165
+ name: string;
166
+ text: string;
167
+ source: "owner" | "operator" | "session-lesson";
168
+ severity: "a missed opportunity" | "a problem" | "unacceptable";
169
+ position: number;
170
+ createdBy: string | null;
171
+ evidence: Record<string, unknown> | null;
172
+ decidedBy: string | null;
173
+ decidedAt: string | null;
174
+ createdAt: string;
175
+ impact: {
176
+ before: {
177
+ turns: number;
178
+ acted: number;
179
+ };
180
+ after: {
181
+ turns: number;
182
+ acted: number;
183
+ };
184
+ } | null;
185
+ }, {
186
+ status: "proposed" | "active" | "rejected" | "retired";
187
+ kind: "promise" | "preference" | "pairing" | "order of things" | "threshold";
188
+ id: string;
189
+ name: string;
190
+ text: string;
191
+ source: "owner" | "operator" | "session-lesson";
192
+ severity: "a missed opportunity" | "a problem" | "unacceptable";
193
+ position: number;
194
+ createdBy: string | null;
195
+ evidence: Record<string, unknown> | null;
196
+ decidedBy: string | null;
197
+ decidedAt: string | null;
198
+ createdAt: string;
199
+ impact: {
200
+ before: {
201
+ turns: number;
202
+ acted: number;
203
+ };
204
+ after: {
205
+ turns: number;
206
+ acted: number;
207
+ };
208
+ } | null;
209
+ }>;
210
+ export type SpaceAgentDirectiveListItem = z.infer<typeof SpaceAgentDirectiveListItemSchema>;
211
+ /** An edit: content and/or a status move. A person never sets `source`. */
212
+ export declare const UpdateAgentDirectiveInputSchema: z.ZodObject<{
213
+ name: z.ZodOptional<z.ZodString>;
214
+ kind: z.ZodOptional<z.ZodEnum<["preference", "pairing", "order of things", "promise", "threshold"]>>;
215
+ severity: z.ZodOptional<z.ZodEnum<["a missed opportunity", "a problem", "unacceptable"]>>;
216
+ text: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
217
+ status: z.ZodOptional<z.ZodEnum<["proposed", "active", "rejected", "retired"]>>;
218
+ }, "strict", z.ZodTypeAny, {
219
+ status?: "proposed" | "active" | "rejected" | "retired" | undefined;
220
+ kind?: "promise" | "preference" | "pairing" | "order of things" | "threshold" | undefined;
221
+ name?: string | undefined;
222
+ text?: string | undefined;
223
+ severity?: "a missed opportunity" | "a problem" | "unacceptable" | undefined;
224
+ }, {
225
+ status?: "proposed" | "active" | "rejected" | "retired" | undefined;
226
+ kind?: "promise" | "preference" | "pairing" | "order of things" | "threshold" | undefined;
227
+ name?: string | undefined;
228
+ text?: string | undefined;
229
+ severity?: "a missed opportunity" | "a problem" | "unacceptable" | undefined;
230
+ }>;
231
+ export type UpdateAgentDirectiveInput = z.infer<typeof UpdateAgentDirectiveInputSchema>;
232
+ /** The active list's new order — every active directive's id, once. */
233
+ export declare const ReorderAgentDirectivesInputSchema: z.ZodObject<{
234
+ ids: z.ZodArray<z.ZodString, "many">;
235
+ }, "strict", z.ZodTypeAny, {
236
+ ids: string[];
237
+ }, {
238
+ ids: string[];
239
+ }>;