@lssm/lib.personalization 0.3.1 → 1.41.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -11
- package/dist/contracts/src/docs/PUBLISHING.docblock.js +76 -0
- package/dist/contracts/src/docs/accessibility_wcag_compliance_specs.docblock.js +350 -0
- package/dist/contracts/src/docs/index.js +1 -0
- package/dist/contracts/src/docs/presentations.js +1 -0
- package/dist/contracts/src/docs/registry.js +1 -0
- package/dist/contracts/src/docs/tech/PHASE_1_QUICKSTART.docblock.js +383 -0
- package/dist/contracts/src/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +68 -0
- package/dist/contracts/src/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +140 -0
- package/dist/contracts/src/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +86 -0
- package/dist/contracts/src/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +1 -0
- package/dist/contracts/src/docs/tech/auth/better-auth-nextjs.docblock.js +58 -0
- package/dist/contracts/src/docs/tech/contracts/openapi-export.docblock.js +38 -0
- package/dist/contracts/src/docs/tech/lifecycle-stage-system.docblock.js +213 -0
- package/dist/contracts/src/docs/tech/llm/llm-integration.docblock.js +289 -0
- package/dist/contracts/src/docs/tech/mcp-endpoints.docblock.js +1 -0
- package/dist/contracts/src/docs/tech/presentation-runtime.docblock.js +1 -0
- package/dist/contracts/src/docs/tech/schema/README.docblock.js +262 -0
- package/dist/contracts/src/docs/tech/studio/learning-events.docblock.js +1 -0
- package/dist/contracts/src/docs/tech/studio/learning-journeys.docblock.js +57 -0
- package/dist/contracts/src/docs/tech/studio/platform-admin-panel.docblock.js +63 -0
- package/dist/contracts/src/docs/tech/studio/project-access-teams.docblock.js +36 -0
- package/dist/contracts/src/docs/tech/studio/project-routing.docblock.js +1 -0
- package/dist/contracts/src/docs/tech/studio/sandbox-unlogged.docblock.js +20 -0
- package/dist/contracts/src/docs/tech/studio/team-invitations.docblock.js +65 -0
- package/dist/contracts/src/docs/tech/studio/workspace-ops.docblock.js +1 -0
- package/dist/contracts/src/docs/tech/studio/workspaces.docblock.js +41 -0
- package/dist/contracts/src/docs/tech/telemetry-ingest.docblock.js +122 -0
- package/dist/contracts/src/docs/tech/templates/runtime.docblock.js +1 -0
- package/dist/contracts/src/docs/tech/vscode-extension.docblock.js +68 -0
- package/dist/contracts/src/docs/tech/workflows/overview.docblock.js +1 -0
- package/dist/docs/behavior-tracking.docblock.js +80 -0
- package/dist/docs/index.js +1 -0
- package/dist/docs/overlay-engine.docblock.js +81 -0
- package/dist/docs/workflow-composition.docblock.js +66 -0
- package/dist/index.js +1 -1
- package/dist/types.js +0 -0
- package/package.json +31 -8
- package/dist/adapter.d.ts +0 -21
- package/dist/analyzer.d.ts +0 -22
- package/dist/index.d.ts +0 -6
- package/dist/store.d.ts +0 -20
- package/dist/tracker.d.ts +0 -52
- package/dist/types.d.ts +0 -58
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import{registerDocBlocks as e}from"../registry.js";e([{id:`docs.tech.telemetry.ingest`,title:`Telemetry Ingest Endpoint`,summary:`Server-side telemetry ingestion for ContractSpec clients (VS Code extension, CLI, etc.).`,kind:`reference`,visibility:`internal`,route:`/docs/tech/telemetry/ingest`,tags:[`telemetry`,`api`,`posthog`,`analytics`],body:`# Telemetry Ingest Endpoint
|
|
2
|
+
|
|
3
|
+
The ContractSpec API provides a telemetry ingest endpoint for clients to send product analytics events.
|
|
4
|
+
|
|
5
|
+
## Endpoint
|
|
6
|
+
|
|
7
|
+
\`\`\`
|
|
8
|
+
POST /api/telemetry/ingest
|
|
9
|
+
\`\`\`
|
|
10
|
+
|
|
11
|
+
## Request
|
|
12
|
+
|
|
13
|
+
\`\`\`json
|
|
14
|
+
{
|
|
15
|
+
"event": "contractspec.vscode.command_run",
|
|
16
|
+
"distinct_id": "client-uuid",
|
|
17
|
+
"properties": {
|
|
18
|
+
"command": "validate"
|
|
19
|
+
},
|
|
20
|
+
"timestamp": "2024-01-15T10:30:00.000Z"
|
|
21
|
+
}
|
|
22
|
+
\`\`\`
|
|
23
|
+
|
|
24
|
+
### Headers
|
|
25
|
+
|
|
26
|
+
| Header | Description |
|
|
27
|
+
|--------|-------------|
|
|
28
|
+
| \`x-contractspec-client-id\` | Optional client identifier (used as fallback for distinct_id) |
|
|
29
|
+
| \`Content-Type\` | Must be \`application/json\` |
|
|
30
|
+
|
|
31
|
+
### Body
|
|
32
|
+
|
|
33
|
+
| Field | Type | Required | Description |
|
|
34
|
+
|-------|------|----------|-------------|
|
|
35
|
+
| \`event\` | string | Yes | Event name (e.g., \`contractspec.vscode.activated\`) |
|
|
36
|
+
| \`distinct_id\` | string | Yes | Anonymous client identifier |
|
|
37
|
+
| \`properties\` | object | No | Event properties |
|
|
38
|
+
| \`timestamp\` | string | No | ISO 8601 timestamp |
|
|
39
|
+
|
|
40
|
+
## Response
|
|
41
|
+
|
|
42
|
+
\`\`\`json
|
|
43
|
+
{
|
|
44
|
+
"success": true
|
|
45
|
+
}
|
|
46
|
+
\`\`\`
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
The endpoint requires \`POSTHOG_PROJECT_KEY\` environment variable to be set. If not configured, events are accepted but not forwarded.
|
|
51
|
+
|
|
52
|
+
| Environment Variable | Description | Default |
|
|
53
|
+
|---------------------|-------------|---------|
|
|
54
|
+
| \`POSTHOG_HOST\` | PostHog host URL | \`https://eu.posthog.com\` |
|
|
55
|
+
| \`POSTHOG_PROJECT_KEY\` | PostHog project API key | (required) |
|
|
56
|
+
|
|
57
|
+
## Privacy
|
|
58
|
+
|
|
59
|
+
- No PII is collected or stored
|
|
60
|
+
- \`distinct_id\` is an anonymous client-generated UUID
|
|
61
|
+
- File paths and source code are never included in events
|
|
62
|
+
- Respects VS Code telemetry settings on the client side
|
|
63
|
+
|
|
64
|
+
## Events
|
|
65
|
+
|
|
66
|
+
### Extension Events
|
|
67
|
+
|
|
68
|
+
| Event | Description | Properties |
|
|
69
|
+
|-------|-------------|------------|
|
|
70
|
+
| \`contractspec.vscode.activated\` | Extension activated | \`version\` |
|
|
71
|
+
| \`contractspec.vscode.command_run\` | Command executed | \`command\` |
|
|
72
|
+
| \`contractspec.vscode.mcp_call\` | MCP call made | \`endpoint\`, \`tool\` |
|
|
73
|
+
|
|
74
|
+
### API Events
|
|
75
|
+
|
|
76
|
+
| Event | Description | Properties |
|
|
77
|
+
|-------|-------------|------------|
|
|
78
|
+
| \`contractspec.api.mcp_request\` | MCP request processed | \`endpoint\`, \`method\`, \`success\`, \`duration_ms\` |
|
|
79
|
+
`},{id:`docs.tech.telemetry.hybrid`,title:`Hybrid Telemetry Model`,summary:`How ContractSpec clients choose between direct PostHog and API-routed telemetry.`,kind:`usage`,visibility:`internal`,route:`/docs/tech/telemetry/hybrid`,tags:[`telemetry`,`architecture`,`posthog`],body:`# Hybrid Telemetry Model
|
|
80
|
+
|
|
81
|
+
ContractSpec uses a hybrid telemetry model where clients can send events either directly to PostHog or via the API server.
|
|
82
|
+
|
|
83
|
+
## Decision Flow
|
|
84
|
+
|
|
85
|
+
\`\`\`
|
|
86
|
+
Is contractspec.api.baseUrl configured?
|
|
87
|
+
├── Yes → Send via /api/telemetry/ingest
|
|
88
|
+
└── No → Is posthogProjectKey configured?
|
|
89
|
+
├── Yes → Send directly to PostHog
|
|
90
|
+
└── No → Telemetry disabled
|
|
91
|
+
\`\`\`
|
|
92
|
+
|
|
93
|
+
## Benefits
|
|
94
|
+
|
|
95
|
+
### Direct PostHog
|
|
96
|
+
- No server dependency
|
|
97
|
+
- Works offline (with batching)
|
|
98
|
+
- Lower latency
|
|
99
|
+
|
|
100
|
+
### Via API
|
|
101
|
+
- Centralized key management (no client-side keys)
|
|
102
|
+
- Server-side enrichment and validation
|
|
103
|
+
- Rate limiting and abuse prevention
|
|
104
|
+
- Easier migration to other providers
|
|
105
|
+
|
|
106
|
+
## Recommendation
|
|
107
|
+
|
|
108
|
+
- **Development**: Use direct PostHog with a dev project key
|
|
109
|
+
- **Production**: Route via API for better governance
|
|
110
|
+
|
|
111
|
+
## Future: OpenTelemetry
|
|
112
|
+
|
|
113
|
+
The current PostHog implementation is behind a simple interface that can be swapped for OpenTelemetry:
|
|
114
|
+
|
|
115
|
+
\`\`\`typescript
|
|
116
|
+
interface TelemetryClient {
|
|
117
|
+
send(event: TelemetryEvent): Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
\`\`\`
|
|
120
|
+
|
|
121
|
+
This allows future migration without changing client code.
|
|
122
|
+
`}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{registerDocBlocks as e}from"../../registry.js";e([{id:`docs.tech.templates.runtime`,title:`ContractSpec Template Runtime (Phase 9)`,summary:`Phase 9 introduces a full local-first runtime for templates so anyone can preview apps directly in the browser without provisioning any infrastructure.`,kind:`reference`,visibility:`public`,route:`/docs/tech/templates/runtime`,tags:[`tech`,`templates`,`runtime`],body:"## ContractSpec Template Runtime (Phase 9)\n\nPhase 9 introduces a full local-first runtime for templates so anyone can preview apps directly in the browser without provisioning any infrastructure.\n\n### Building Blocks\n\n- **Local database** – `@lssm/lib.runtime-local` wraps `sql.js` (SQLite WASM) and `IndexedDB` so we can seed demo data, run migrations, and persist state between sessions. Tests point the runtime to `node_modules/sql.js/dist` so CI doesn’t need a browser.\n- **Local GraphQL** – `LocalGraphQLClient` wires Apollo Client + SchemaLink to resolvers for tasks, messaging, and i18n recipes. All `/templates`, `/studio`, and `/sandbox` previews use those resolvers so we never call remote APIs during demos.\n- **Template registry + installer** – `.../templates/registry.ts` stores the catalog (todos, messaging, recipes). `TemplateInstaller` can seed the runtime (`install`) or export a base64 snapshot via the new `saveTemplateToStudio` mutation.\n- **TemplateShell** – Shared UI wrapper that creates a `TemplateRuntimeProvider`, shows `LocalDataIndicator`, and (optionally) surfaces the new `SaveToStudioButton`.\n\n### Runtime Flows\n\n1. `/templates` now opens a modal that renders `TemplateShell` for each template. Users can explore without leaving the marketing site.\n2. `/studio` switches to a tabbed mini-app (Projects, Canvas, Specs, Deploy) to showcase Studio surfaces with mock data. Visitors see a **preview** shell, while authenticated users (Better Auth via Sigil) unlock full persistence, versioning, and deployment controls.\n3. `/sandbox` lets visitors pick a template and mode (Playground, Spec Editor, Visual Builder). The console at the bottom streams runtime events for transparency.\n\n### GraphQL Mutations\n\n- `saveTemplateToStudio(input: SaveTemplateInput!): SaveTemplateResult!` writes a placeholder project + spec so that templates installed from the sandbox appear in Studio. The mutation is intentionally simple right now: it records which template was imported, stores metadata, and returns `{ projectId, status: 'QUEUED' }` for the UI.\n- `saveCanvasDraft(input: SaveCanvasDraftInput!): CanvasVersion!` snapshots the current Visual Builder nodes to a draft version tied to a canvas overlay. Inputs include `canvasId`, arbitrary `nodes` JSON, and an optional `label`. The resolver enforces org/org access before calling `CanvasVersionManager`.\n- `deployCanvasVersion(input: DeployCanvasVersionInput!): CanvasVersion!` promotes a previously saved draft (`versionId`) to the deployed state. The returned object includes `status`, `nodes`, `createdAt`, and `createdBy` for UI timelines.\n- `undoCanvasVersion(input: UndoCanvasInput!): CanvasVersion` rewinds the visual builder to the prior snapshot (returns `null` when history is empty) so Studio’s toolbar can surface “Undo” without shelling out to local storage.\n\n### Studio GraphQL endpoint\n\n- The landing app exposes the Studio schema at `/api/studio/graphql` via Yoga so React Query hooks (`useStudioProjects`, `useCreateStudioProject`, `useDeployStudioProject`, etc.) can talk to the bundle without spinning up a separate server.\n\n### Spec Editor typing\n\n- Studio’s spec editor now preloads Monaco with ambient declarations for `@lssm/lib.contracts` and `zod`, so snippets receive autocomplete and inline errors even before the spec ships to the backend. The helper lives in `presentation/components/studio/organisms/monaco-spec-types.ts` and registers the extra libs once per browser session via `monaco.languages.typescript.typescriptDefaults.addExtraLib`.\n- Compiler options are aligned with our frontend toolchain (ES2020 + React JSX) which means drafts written in the editor behave like the compiled artifacts that flow through Studio pipelines.\n\n### Spec templates\n\n- Selecting a spec type now injects a ready-to-edit scaffold (capability, workflow, policy, dataview, component) so authors start from a canonical layout instead of a blank file. Templates live alongside `SpecEditor.tsx`, and we only overwrite the content when the previous value is empty or when the author explicitly switches types via the dropdown.\n\n### Spec preview\n\n- The validation side panel now embeds a `SpecPreview` widget that shows validation errors alongside transport artifacts (GraphQL schema, REST endpoints, component summaries) once a preview run completes. Tabs let authors toggle between “Validation” and “Artifacts,” mirroring the UX described in the Studio plan.\n\n### Testing\n\n- `src/templates/__tests__/runtime.test.ts` covers todos CRUD, messaging delivery, and recipe locale switching through the local GraphQL API.\n- Studio infrastructure tests live in `src/__tests__/e2e/project-lifecycle.test.ts` and continue to exercise project creation + deploy flows.\n\n### Next Steps\n\nFuture templates can register their React components via `registerTemplateComponents(templateId, components)` so TemplateShell can render them automatically. When new templates are added, remember to:\n\n1. Update the registry entry (schema + tags).\n2. Register components inside `presentation/components/templates`.\n3. Document the template under `docs/templates/`.\n\n\n\n\n\n"}]);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import{registerDocBlocks as e}from"../registry.js";e([{id:`docs.tech.vscode.extension`,title:`ContractSpec VS Code Extension`,summary:`VS Code extension for spec-first development with validation, scaffolding, and MCP integration.`,kind:`reference`,visibility:`public`,route:`/docs/tech/vscode/extension`,tags:[`vscode`,`extension`,`tooling`,`dx`],body:`# ContractSpec VS Code Extension
|
|
2
|
+
|
|
3
|
+
The ContractSpec VS Code extension provides spec-first development tooling directly in your editor.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Real-time Validation**: Get instant feedback on spec errors and warnings as you save files
|
|
8
|
+
- **Build/Scaffold**: Generate handler and component skeletons from specs (no AI required)
|
|
9
|
+
- **Spec Explorer**: List and navigate all specs in your workspace
|
|
10
|
+
- **Dependency Analysis**: Visualize spec dependencies and detect cycles
|
|
11
|
+
- **MCP Integration**: Search ContractSpec documentation via Model Context Protocol
|
|
12
|
+
- **Snippets**: Code snippets for common ContractSpec patterns
|
|
13
|
+
|
|
14
|
+
## Commands
|
|
15
|
+
|
|
16
|
+
| Command | Description |
|
|
17
|
+
|---------|-------------|
|
|
18
|
+
| \`ContractSpec: Validate Current Spec\` | Validate the currently open spec file |
|
|
19
|
+
| \`ContractSpec: Validate All Specs\` | Validate all spec files in the workspace |
|
|
20
|
+
| \`ContractSpec: Build/Scaffold\` | Generate handler/component from the current spec |
|
|
21
|
+
| \`ContractSpec: List All Specs\` | Show all specs in the workspace |
|
|
22
|
+
| \`ContractSpec: Analyze Dependencies\` | Analyze and visualize spec dependencies |
|
|
23
|
+
| \`ContractSpec: Search Docs (MCP)\` | Search documentation via MCP |
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
| Setting | Description | Default |
|
|
28
|
+
|---------|-------------|---------|
|
|
29
|
+
| \`contractspec.api.baseUrl\` | Base URL for ContractSpec API (enables MCP + remote telemetry) | \`""\` |
|
|
30
|
+
| \`contractspec.telemetry.posthogHost\` | PostHog host URL for direct telemetry | \`"https://eu.posthog.com"\` |
|
|
31
|
+
| \`contractspec.telemetry.posthogProjectKey\` | PostHog project key for direct telemetry | \`""\` |
|
|
32
|
+
| \`contractspec.validation.onSave\` | Run validation on save | \`true\` |
|
|
33
|
+
| \`contractspec.validation.onOpen\` | Run validation on open | \`true\` |
|
|
34
|
+
|
|
35
|
+
## Architecture
|
|
36
|
+
|
|
37
|
+
The extension uses:
|
|
38
|
+
- \`@lssm/module.contractspec-workspace\` for pure analysis + templates
|
|
39
|
+
- \`@lssm/bundle.contractspec-workspace\` for workspace services + adapters
|
|
40
|
+
|
|
41
|
+
This allows the extension to work without requiring the CLI to be installed.
|
|
42
|
+
|
|
43
|
+
## Telemetry
|
|
44
|
+
|
|
45
|
+
The extension uses a hybrid telemetry approach:
|
|
46
|
+
1. If \`contractspec.api.baseUrl\` is configured → send to API \`/api/telemetry/ingest\`
|
|
47
|
+
2. Otherwise → send directly to PostHog (if project key configured)
|
|
48
|
+
|
|
49
|
+
Telemetry respects VS Code's telemetry settings. No file paths, source code, or PII is collected.
|
|
50
|
+
`},{id:`docs.tech.vscode.snippets`,title:`ContractSpec Snippets`,summary:`Code snippets for common ContractSpec patterns in VS Code.`,kind:`reference`,visibility:`public`,route:`/docs/tech/vscode/snippets`,tags:[`vscode`,`snippets`,`dx`],body:`# ContractSpec Snippets
|
|
51
|
+
|
|
52
|
+
The VS Code extension includes snippets for common ContractSpec patterns.
|
|
53
|
+
|
|
54
|
+
## Available Snippets
|
|
55
|
+
|
|
56
|
+
| Prefix | Description |
|
|
57
|
+
|--------|-------------|
|
|
58
|
+
| \`contractspec-command\` | Create a new command (write operation) |
|
|
59
|
+
| \`contractspec-query\` | Create a new query (read-only operation) |
|
|
60
|
+
| \`contractspec-event\` | Create a new event |
|
|
61
|
+
| \`contractspec-docblock\` | Create a new DocBlock |
|
|
62
|
+
| \`contractspec-telemetry\` | Create a new TelemetrySpec |
|
|
63
|
+
| \`contractspec-presentation\` | Create a new Presentation |
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
Type the prefix in a TypeScript file and press Tab to expand the snippet. Tab through the placeholders to fill in your values.
|
|
68
|
+
`}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{registerDocBlocks as e}from"../../registry.js";e([{id:`docs.tech.workflows.overview`,title:`WorkflowSpec Overview`,summary:"WorkflowSpec provides a declarative, versioned format for long-running flows that mix automation and human review. Specs stay inside `@lssm/lib.contracts` (`src/workflow/spec.ts`) so the same definition powers runtime execution, documentation, and future generation.",kind:`reference`,visibility:`public`,route:`/docs/tech/workflows/overview`,tags:[`tech`,`workflows`,`overview`],body:"# WorkflowSpec Overview\n\n## Purpose\n\nWorkflowSpec provides a declarative, versioned format for long-running flows that mix automation and human review. Specs stay inside `@lssm/lib.contracts` (`src/workflow/spec.ts`) so the same definition powers runtime execution, documentation, and future generation.\n\n## Core Types\n\n- `WorkflowMeta`: ownership metadata (`title`, `domain`, `owners`, `tags`, `stability`) plus `name` and `version`.\n- `WorkflowDefinition`:\n - `entryStepId?`: optional explicit entry point (defaults to first step).\n - `steps[]`: ordered list of `Step` descriptors.\n - `transitions[]`: directed edges between steps with optional expressions.\n - `sla?`: aggregated timing hints for the overall flow or per-step budgets.\n - `compensation?`: fallback operations executed when a workflow is rolled back or fails.\n- `Step`:\n - `type`: `human`, `automation`, or `decision`.\n - `action`: references either a `ContractSpec` (`operation`) or `FormSpec` (`form`).\n - Optional `guard`, `timeoutMs`, and retry policy (`maxAttempts`, `backoff`, `delayMs`, `maxDelayMs?`).\n - `requiredIntegrations?`: integration slot ids that must be bound before the step may execute.\n - `requiredCapabilities?`: `CapabilityRef[]` that must be enabled in the resolved app config.\n- `Transition`: `from` → `to` with optional `condition` string (simple data expressions).\n\n## Registry & Validation\n\n- `WorkflowRegistry` (`src/workflow/spec.ts`) stores specs by key `<name>.v<version>` and exposes `register`, `list`, and `get`.\n- `validateWorkflowSpec()` (`src/workflow/validation.ts`) checks:\n - Duplicate step IDs.\n - Unknown `from`/`to` transitions.\n - Empty guards/conditions.\n - Reachability from the entry step.\n - Cycles in the graph.\n - Operation/Form references against provided registries.\n- `assertWorkflowSpecValid()` wraps validation and throws `WorkflowValidationError` when errors remain.\n\n## Runtime\n\n- `WorkflowRunner` (`src/workflow/runner.ts`) executes workflows and coordinates steps.\n - `start(name, version?, initialData?)` returns a `workflowId`.\n - `executeStep(workflowId, input?)` runs the current step (automation or human).\n - `getState(workflowId)` retrieves the latest state snapshot.\n - `cancel(workflowId)` marks the workflow as cancelled.\n - `preFlightCheck(name, version?, resolvedConfig?)` evaluates integration/capability requirements before the workflow starts.\n - Throws `WorkflowPreFlightError` if required integration slots are unbound or required capabilities are disabled.\n- `StateStore` (`src/workflow/state.ts`) abstracts persistence. V1 ships with:\n - `InMemoryStateStore` (`src/workflow/adapters/memory-store.ts`) for tests/dev.\n - Placeholder factories for file/database adapters (`adapters/file-adapter.ts`, `adapters/db-adapter.ts`).\n- Guard evaluation: expression guards run through `evaluateExpression()` (`src/workflow/expression.ts`); custom policy guards can be provided via `guardEvaluator`.\n- Events: the runner emits `workflow.started`, `workflow.step_completed`, `workflow.step_failed`, and `workflow.cancelled` through the optional `eventEmitter`.\n- React bindings (`@lssm/lib.presentation-runtime-react`):\n - `useWorkflow` hook (polls state, exposes `executeStep`, `cancel`, `refresh`).\n - `WorkflowStepper` progress indicator using design-system Stepper.\n - `WorkflowStepRenderer` helper to render human/automation/decision steps with sensible fallbacks.\n\n## Authoring Checklist\n\n1. Reuse existing operations/forms; create new specs when missing.\n2. Prefer explicit `entryStepId` for clarity (especially with decision branches).\n3. Give automation steps an `operation` and human steps a `form` (warnings surface otherwise).\n4. Use short, meaningful step IDs (`submit`, `review`, `finalize`) to simplify analytics.\n5. Keep guard expressions deterministic; complex policy logic should move to PolicySpec (Phase 2).\n\n## Testing\n\n- Add unit tests for new workflows via `assertWorkflowSpecValid`.\n- Use the new Vitest suites (`validation.test.ts`, `expression.test.ts`, `runner.test.ts`) as examples.\n- CLI support will arrive in Phase 1 PR 3 (`contractspec create --type workflow`).\n\n## Tooling\n\n- `contractspec create --type workflow` scaffolds a WorkflowSpec with interactive prompts.\n- `contractspec build <spec.workflow.ts>` generates a runner scaffold (`.runner.ts`) wired to `WorkflowRunner` and the in-memory store.\n- `contractspec validate` understands `.workflow.ts` files and checks core structure (meta, steps, transitions).\n\n## Next Steps (Non-MVP)\n\n- Persistence adapters (database/file) for workflow state (Phase 2).\n- React bindings (`useWorkflow`, `WorkflowStepper`) and presentation-runtime integration (PR 3).\n- Policy engine integration (`guard.type === 'policy'` validated against PolicySpec).\n- Telemetry hooks for step execution metrics.\n\n"}]);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import{registerDocBlocks as e}from"../contracts/src/docs/registry.js";import"../contracts/src/docs/index.js";const t=[{id:`docs.personalization.behavior-tracking`,title:`Behavior Tracking`,summary:"`@lssm/lib.personalization` provides primitives to observe how tenants/users interact with specs and turn that telemetry into personalization insights.",kind:`reference`,visibility:`public`,route:`/docs/personalization/behavior-tracking`,tags:[`personalization`,`behavior-tracking`],body:`# Behavior Tracking
|
|
2
|
+
|
|
3
|
+
\`@lssm/lib.personalization\` provides primitives to observe how tenants/users interact with specs and turn that telemetry into personalization insights.
|
|
4
|
+
|
|
5
|
+
## Tracker
|
|
6
|
+
|
|
7
|
+
\`\`\`ts
|
|
8
|
+
import { createBehaviorTracker } from '@lssm/lib.personalization';
|
|
9
|
+
import { InMemoryBehaviorStore } from '@lssm/lib.personalization/store';
|
|
10
|
+
|
|
11
|
+
const tracker = createBehaviorTracker({
|
|
12
|
+
store: new InMemoryBehaviorStore(),
|
|
13
|
+
context: { tenantId: ctx.tenant.id, userId: ctx.identity.userId },
|
|
14
|
+
autoFlushIntervalMs: 5000,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
tracker.trackFieldAccess({ operation: 'billing.createOrder', field: 'internalNotes' });
|
|
18
|
+
tracker.trackFeatureUsage({ feature: 'workflow-editor', action: 'opened' });
|
|
19
|
+
tracker.trackWorkflowStep({ workflow: 'invoice-approval', step: 'review', status: 'entered' });
|
|
20
|
+
\`\`\`
|
|
21
|
+
|
|
22
|
+
All events are buffered and flushed either when the buffer hits 25 entries or when \`autoFlushIntervalMs\` elapses. Tracked metrics flow to OpenTelemetry via the meter/counter built into the tracker.
|
|
23
|
+
|
|
24
|
+
## Analyzer
|
|
25
|
+
|
|
26
|
+
\`\`\`ts
|
|
27
|
+
import { BehaviorAnalyzer } from '@lssm/lib.personalization/analyzer';
|
|
28
|
+
|
|
29
|
+
const analyzer = new BehaviorAnalyzer(store, { fieldInactivityThreshold: 2 });
|
|
30
|
+
const insights = await analyzer.analyze({ tenantId: 'acme', userId: 'manager-42', windowMs: 7 * 24 * 60 * 60 * 1000 });
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
{
|
|
34
|
+
unusedFields: ['internalNotes'],
|
|
35
|
+
suggestedHiddenFields: ['internalNotes'],
|
|
36
|
+
frequentlyUsedFields: ['customerReference', 'items'],
|
|
37
|
+
workflowBottlenecks: [{ workflow: 'invoice-approval', step: 'finance-review', dropRate: 0.6 }],
|
|
38
|
+
layoutPreference: 'table'
|
|
39
|
+
}
|
|
40
|
+
*/
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
Use the analyzer output with the overlay adapter to generate suggestions automatically.
|
|
44
|
+
|
|
45
|
+
## Adapter
|
|
46
|
+
|
|
47
|
+
\`\`\`ts
|
|
48
|
+
import { insightsToOverlaySuggestion } from '@lssm/lib.personalization/adapter';
|
|
49
|
+
|
|
50
|
+
const overlay = insightsToOverlaySuggestion(insights, {
|
|
51
|
+
overlayId: 'acme-order-form',
|
|
52
|
+
tenantId: 'acme',
|
|
53
|
+
capability: 'billing.createOrder',
|
|
54
|
+
});
|
|
55
|
+
\`\`\`
|
|
56
|
+
|
|
57
|
+
When the adapter returns an overlay spec, pass it to the overlay engine to register or sign it.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
`}];e(t);export{t as personalization_behavior_tracking_DocBlocks};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./behavior-tracking.docblock.js";import"./overlay-engine.docblock.js";import"./workflow-composition.docblock.js";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import{registerDocBlocks as e}from"../contracts/src/docs/registry.js";import"../contracts/src/docs/index.js";const t=[{id:`docs.personalization.overlay-engine`,title:`Overlay Engine`,summary:"`@lssm/lib.overlay-engine` is the canonical runtime for OverlaySpecs. It validates specs, tracks scope precedence, and exposes hooks for React renderers.",kind:`reference`,visibility:`public`,route:`/docs/personalization/overlay-engine`,tags:[`personalization`,`overlay-engine`],body:`# Overlay Engine
|
|
2
|
+
|
|
3
|
+
\`@lssm/lib.overlay-engine\` is the canonical runtime for OverlaySpecs. It validates specs, tracks scope precedence, and exposes hooks for React renderers.
|
|
4
|
+
|
|
5
|
+
## Key APIs
|
|
6
|
+
|
|
7
|
+
- \`defineOverlay(spec)\` – helper to keep specs typed.
|
|
8
|
+
- \`OverlayRegistry\` – register signed overlays and retrieve them per context.
|
|
9
|
+
- \`OverlayEngine\` – apply overlays to renderable targets, emit audit events, and merge modifications deterministically.
|
|
10
|
+
- \`signOverlay(spec, privateKey)\` – Ed25519/RSA-PSS signer.
|
|
11
|
+
- \`verifyOverlaySignature(overlay)\` – verify public key signatures.
|
|
12
|
+
- \`useOverlay(engine, params)\` – client hook that returns \`{ target, overlaysApplied }\`.
|
|
13
|
+
|
|
14
|
+
## Scope Precedence
|
|
15
|
+
|
|
16
|
+
Registrations are sorted by specificity:
|
|
17
|
+
|
|
18
|
+
1. Tenant overlays
|
|
19
|
+
2. Role overlays
|
|
20
|
+
3. User overlays
|
|
21
|
+
4. Device overlays
|
|
22
|
+
|
|
23
|
+
Less specific overlays run first; more specific overlays override later.
|
|
24
|
+
|
|
25
|
+
## Example
|
|
26
|
+
|
|
27
|
+
\`\`\`ts
|
|
28
|
+
const registry = new OverlayRegistry();
|
|
29
|
+
const engine = new OverlayEngine({
|
|
30
|
+
registry,
|
|
31
|
+
audit: (event) => auditLogService.record(event),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const overlay = defineOverlay({
|
|
35
|
+
overlayId: 'acme-order-form',
|
|
36
|
+
version: '1.0.0',
|
|
37
|
+
appliesTo: {
|
|
38
|
+
capability: 'billing.createOrder',
|
|
39
|
+
tenantId: 'acme',
|
|
40
|
+
},
|
|
41
|
+
modifications: [
|
|
42
|
+
{ type: 'hideField', field: 'internalNotes' },
|
|
43
|
+
{ type: 'renameLabel', field: 'customerReference', newLabel: 'PO Number' },
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const signedOverlay = await signOverlay(overlay, privateKeyPem);
|
|
48
|
+
registry.register(signedOverlay);
|
|
49
|
+
|
|
50
|
+
const result = engine.apply({
|
|
51
|
+
target: { fields: baseFields },
|
|
52
|
+
capability: 'billing.createOrder',
|
|
53
|
+
tenantId: 'acme',
|
|
54
|
+
userId: 'manager-7',
|
|
55
|
+
});
|
|
56
|
+
\`\`\`
|
|
57
|
+
|
|
58
|
+
\`result.target.fields\` now carries the hidden and renamed outputs ready for rendering.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
`}];e(t);export{t as personalization_overlay_engine_DocBlocks};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import{registerDocBlocks as e}from"../contracts/src/docs/registry.js";import"../contracts/src/docs/index.js";const t=[{id:`docs.personalization.workflow-composition`,title:`Workflow Composition`,summary:"`@lssm/lib.workflow-composer` composes base WorkflowSpecs with tenant/role/device-specific extensions.",kind:`reference`,visibility:`public`,route:`/docs/personalization/workflow-composition`,tags:[`personalization`,`workflow-composition`],body:`# Workflow Composition
|
|
2
|
+
|
|
3
|
+
\`@lssm/lib.workflow-composer\` composes base WorkflowSpecs with tenant/role/device-specific extensions.
|
|
4
|
+
|
|
5
|
+
## Extensions
|
|
6
|
+
|
|
7
|
+
\`\`\`ts
|
|
8
|
+
import { WorkflowComposer } from '@lssm/lib.workflow-composer';
|
|
9
|
+
import { approvalStepTemplate } from '@lssm/lib.workflow-composer/templates';
|
|
10
|
+
|
|
11
|
+
const composer = new WorkflowComposer();
|
|
12
|
+
|
|
13
|
+
composer.register({
|
|
14
|
+
workflow: 'billing.invoiceApproval',
|
|
15
|
+
tenantId: 'acme',
|
|
16
|
+
priority: 10,
|
|
17
|
+
customSteps: [
|
|
18
|
+
{
|
|
19
|
+
after: 'validate-invoice',
|
|
20
|
+
inject: approvalStepTemplate({
|
|
21
|
+
id: 'acme-legal-review',
|
|
22
|
+
label: 'Legal Review (ACME)',
|
|
23
|
+
description: 'Tenant-specific compliance step.',
|
|
24
|
+
}),
|
|
25
|
+
transitionTo: 'final-approval',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
hiddenSteps: ['internal-audit'],
|
|
29
|
+
});
|
|
30
|
+
\`\`\`
|
|
31
|
+
|
|
32
|
+
## Compose
|
|
33
|
+
|
|
34
|
+
\`\`\`ts
|
|
35
|
+
const runtimeSpec = composer.compose({
|
|
36
|
+
base: BaseInvoiceWorkflow,
|
|
37
|
+
tenantId: 'acme',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
workflowRunner.execute(runtimeSpec, ctx);
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
The composer uses anchor references (\`after\`/\`before\`) to place injected steps and cleans up transitions when steps are hidden.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
`}];e(t);export{t as personalization_workflow_composition_DocBlocks};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{insightsToOverlaySuggestion as e,insightsToWorkflowAdaptations as t}from"./adapter.js";import{BehaviorAnalyzer as n}from"./analyzer.js";import{InMemoryBehaviorStore as r}from"./store.js";import{BehaviorTracker as i,createBehaviorTracker as a}from"./tracker.js";import"./docs/index.js";export{n as BehaviorAnalyzer,i as BehaviorTracker,r as InMemoryBehaviorStore,a as createBehaviorTracker,e as insightsToOverlaySuggestion,t as insightsToWorkflowAdaptations};
|
package/dist/types.js
ADDED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lssm/lib.personalization",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.41.1",
|
|
4
4
|
"description": "Behavior tracking, analysis, and adaptation helpers for ContractSpec personalization.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
14
|
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
15
|
+
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
15
16
|
"build": "bun build:bundle && bun build:types",
|
|
16
17
|
"build:bundle": "tsdown",
|
|
17
18
|
"build:types": "tsc --noEmit",
|
|
@@ -23,24 +24,46 @@
|
|
|
23
24
|
"test": "bun run"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@lssm/lib.bus": "1.
|
|
27
|
-
"@lssm/lib.overlay-engine": "
|
|
27
|
+
"@lssm/lib.bus": "1.41.1",
|
|
28
|
+
"@lssm/lib.overlay-engine": "1.41.1",
|
|
28
29
|
"@opentelemetry/api": "^1.9.0"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
31
32
|
"@opentelemetry/api": "^1.9.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@lssm/tool.tsdown": "
|
|
35
|
-
"@lssm/tool.typescript": "
|
|
36
|
-
"tsdown": "^0.
|
|
35
|
+
"@lssm/tool.tsdown": "1.41.1",
|
|
36
|
+
"@lssm/tool.typescript": "1.41.1",
|
|
37
|
+
"tsdown": "^0.17.4",
|
|
37
38
|
"typescript": "^5.9.3"
|
|
38
39
|
},
|
|
39
40
|
"exports": {
|
|
40
|
-
".": "./
|
|
41
|
+
".": "./src/index.ts",
|
|
42
|
+
"./adapter": "./src/adapter.ts",
|
|
43
|
+
"./analyzer": "./src/analyzer.ts",
|
|
44
|
+
"./docs": "./src/docs/index.ts",
|
|
45
|
+
"./docs/behavior-tracking.docblock": "./src/docs/behavior-tracking.docblock.ts",
|
|
46
|
+
"./docs/overlay-engine.docblock": "./src/docs/overlay-engine.docblock.ts",
|
|
47
|
+
"./docs/workflow-composition.docblock": "./src/docs/workflow-composition.docblock.ts",
|
|
48
|
+
"./store": "./src/store.ts",
|
|
49
|
+
"./tracker": "./src/tracker.ts",
|
|
50
|
+
"./types": "./src/types.ts",
|
|
41
51
|
"./*": "./*"
|
|
42
52
|
},
|
|
43
53
|
"publishConfig": {
|
|
44
|
-
"access": "public"
|
|
54
|
+
"access": "public",
|
|
55
|
+
"exports": {
|
|
56
|
+
".": "./dist/index.js",
|
|
57
|
+
"./adapter": "./dist/adapter.js",
|
|
58
|
+
"./analyzer": "./dist/analyzer.js",
|
|
59
|
+
"./docs": "./dist/docs/index.js",
|
|
60
|
+
"./docs/behavior-tracking.docblock": "./dist/docs/behavior-tracking.docblock.js",
|
|
61
|
+
"./docs/overlay-engine.docblock": "./dist/docs/overlay-engine.docblock.js",
|
|
62
|
+
"./docs/workflow-composition.docblock": "./dist/docs/workflow-composition.docblock.js",
|
|
63
|
+
"./store": "./dist/store.js",
|
|
64
|
+
"./tracker": "./dist/tracker.js",
|
|
65
|
+
"./types": "./dist/types.js",
|
|
66
|
+
"./*": "./*"
|
|
67
|
+
}
|
|
45
68
|
}
|
|
46
69
|
}
|
package/dist/adapter.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BehaviorInsights } from "./types.js";
|
|
2
|
-
import { OverlaySpec } from "@lssm/lib.overlay-engine";
|
|
3
|
-
|
|
4
|
-
//#region src/adapter.d.ts
|
|
5
|
-
interface OverlaySuggestionOptions {
|
|
6
|
-
overlayId: string;
|
|
7
|
-
tenantId: string;
|
|
8
|
-
capability: string;
|
|
9
|
-
userId?: string;
|
|
10
|
-
role?: string;
|
|
11
|
-
version?: string;
|
|
12
|
-
}
|
|
13
|
-
interface WorkflowAdaptation {
|
|
14
|
-
workflow: string;
|
|
15
|
-
step: string;
|
|
16
|
-
note: string;
|
|
17
|
-
}
|
|
18
|
-
declare function insightsToOverlaySuggestion(insights: BehaviorInsights, options: OverlaySuggestionOptions): OverlaySpec | null;
|
|
19
|
-
declare function insightsToWorkflowAdaptations(insights: BehaviorInsights): WorkflowAdaptation[];
|
|
20
|
-
//#endregion
|
|
21
|
-
export { OverlaySuggestionOptions, WorkflowAdaptation, insightsToOverlaySuggestion, insightsToWorkflowAdaptations };
|
package/dist/analyzer.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { BehaviorInsights } from "./types.js";
|
|
2
|
-
import { BehaviorStore } from "./store.js";
|
|
3
|
-
|
|
4
|
-
//#region src/analyzer.d.ts
|
|
5
|
-
interface BehaviorAnalyzerOptions {
|
|
6
|
-
fieldInactivityThreshold?: number;
|
|
7
|
-
minSamples?: number;
|
|
8
|
-
}
|
|
9
|
-
interface AnalyzeParams {
|
|
10
|
-
tenantId: string;
|
|
11
|
-
userId?: string;
|
|
12
|
-
role?: string;
|
|
13
|
-
windowMs?: number;
|
|
14
|
-
}
|
|
15
|
-
declare class BehaviorAnalyzer {
|
|
16
|
-
private readonly store;
|
|
17
|
-
private readonly options;
|
|
18
|
-
constructor(store: BehaviorStore, options?: BehaviorAnalyzerOptions);
|
|
19
|
-
analyze(params: AnalyzeParams): Promise<BehaviorInsights>;
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
export { AnalyzeParams, BehaviorAnalyzer, BehaviorAnalyzerOptions };
|
package/dist/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { BehaviorEvent, BehaviorEventBase, BehaviorEventType, BehaviorInsights, BehaviorQuery, BehaviorSummary, FeatureUsageEvent, FieldAccessEvent, WorkflowStepEvent } from "./types.js";
|
|
2
|
-
import { BehaviorStore, InMemoryBehaviorStore } from "./store.js";
|
|
3
|
-
import { BehaviorTracker, BehaviorTrackerContext, BehaviorTrackerOptions, TrackFeatureUsageInput, TrackFieldAccessInput, TrackWorkflowStepInput, createBehaviorTracker } from "./tracker.js";
|
|
4
|
-
import { AnalyzeParams, BehaviorAnalyzer, BehaviorAnalyzerOptions } from "./analyzer.js";
|
|
5
|
-
import { OverlaySuggestionOptions, WorkflowAdaptation, insightsToOverlaySuggestion, insightsToWorkflowAdaptations } from "./adapter.js";
|
|
6
|
-
export { AnalyzeParams, BehaviorAnalyzer, BehaviorAnalyzerOptions, BehaviorEvent, BehaviorEventBase, BehaviorEventType, BehaviorInsights, BehaviorQuery, BehaviorStore, BehaviorSummary, BehaviorTracker, BehaviorTrackerContext, BehaviorTrackerOptions, FeatureUsageEvent, FieldAccessEvent, InMemoryBehaviorStore, OverlaySuggestionOptions, TrackFeatureUsageInput, TrackFieldAccessInput, TrackWorkflowStepInput, WorkflowAdaptation, WorkflowStepEvent, createBehaviorTracker, insightsToOverlaySuggestion, insightsToWorkflowAdaptations };
|
package/dist/store.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { BehaviorEvent, BehaviorQuery, BehaviorSummary } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/store.d.ts
|
|
4
|
-
interface BehaviorStore {
|
|
5
|
-
record(event: BehaviorEvent): Promise<void> | void;
|
|
6
|
-
bulkRecord(events: BehaviorEvent[]): Promise<void> | void;
|
|
7
|
-
query(query: BehaviorQuery): Promise<BehaviorEvent[]>;
|
|
8
|
-
summarize(query: BehaviorQuery): Promise<BehaviorSummary>;
|
|
9
|
-
clear?(): Promise<void> | void;
|
|
10
|
-
}
|
|
11
|
-
declare class InMemoryBehaviorStore implements BehaviorStore {
|
|
12
|
-
private events;
|
|
13
|
-
record(event: BehaviorEvent): Promise<void>;
|
|
14
|
-
bulkRecord(events: BehaviorEvent[]): Promise<void>;
|
|
15
|
-
query(query: BehaviorQuery): Promise<BehaviorEvent[]>;
|
|
16
|
-
summarize(query: BehaviorQuery): Promise<BehaviorSummary>;
|
|
17
|
-
clear(): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { BehaviorStore, InMemoryBehaviorStore };
|
package/dist/tracker.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { BehaviorStore } from "./store.js";
|
|
2
|
-
|
|
3
|
-
//#region src/tracker.d.ts
|
|
4
|
-
interface BehaviorTrackerContext {
|
|
5
|
-
tenantId: string;
|
|
6
|
-
userId?: string;
|
|
7
|
-
role?: string;
|
|
8
|
-
device?: string;
|
|
9
|
-
metadata?: Record<string, unknown>;
|
|
10
|
-
}
|
|
11
|
-
interface BehaviorTrackerOptions {
|
|
12
|
-
store: BehaviorStore;
|
|
13
|
-
context: BehaviorTrackerContext;
|
|
14
|
-
tracerName?: string;
|
|
15
|
-
autoFlushIntervalMs?: number;
|
|
16
|
-
bufferSize?: number;
|
|
17
|
-
}
|
|
18
|
-
interface TrackFieldAccessInput {
|
|
19
|
-
operation: string;
|
|
20
|
-
field: string;
|
|
21
|
-
metadata?: Record<string, unknown>;
|
|
22
|
-
}
|
|
23
|
-
interface TrackFeatureUsageInput {
|
|
24
|
-
feature: string;
|
|
25
|
-
action: 'opened' | 'completed' | 'dismissed';
|
|
26
|
-
metadata?: Record<string, unknown>;
|
|
27
|
-
}
|
|
28
|
-
interface TrackWorkflowStepInput {
|
|
29
|
-
workflow: string;
|
|
30
|
-
step: string;
|
|
31
|
-
status: 'entered' | 'completed' | 'skipped' | 'errored';
|
|
32
|
-
metadata?: Record<string, unknown>;
|
|
33
|
-
}
|
|
34
|
-
declare class BehaviorTracker {
|
|
35
|
-
private readonly store;
|
|
36
|
-
private readonly context;
|
|
37
|
-
private readonly tracer;
|
|
38
|
-
private readonly counter;
|
|
39
|
-
private buffer;
|
|
40
|
-
private readonly bufferSize;
|
|
41
|
-
private flushTimer?;
|
|
42
|
-
constructor(options: BehaviorTrackerOptions);
|
|
43
|
-
trackFieldAccess(input: TrackFieldAccessInput): void;
|
|
44
|
-
trackFeatureUsage(input: TrackFeatureUsageInput): void;
|
|
45
|
-
trackWorkflowStep(input: TrackWorkflowStepInput): void;
|
|
46
|
-
flush(): Promise<void>;
|
|
47
|
-
dispose(): Promise<void>;
|
|
48
|
-
private enqueue;
|
|
49
|
-
}
|
|
50
|
-
declare const createBehaviorTracker: (options: BehaviorTrackerOptions) => BehaviorTracker;
|
|
51
|
-
//#endregion
|
|
52
|
-
export { BehaviorTracker, BehaviorTrackerContext, BehaviorTrackerOptions, TrackFeatureUsageInput, TrackFieldAccessInput, TrackWorkflowStepInput, createBehaviorTracker };
|