@plures/praxis 1.1.3 → 1.2.0

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.
@@ -0,0 +1,154 @@
1
+ import {
2
+ createPraxisEngine
3
+ } from "./chunk-VOMLVI6V.js";
4
+
5
+ // src/core/rules.ts
6
+ var PraxisRegistry = class {
7
+ rules = /* @__PURE__ */ new Map();
8
+ constraints = /* @__PURE__ */ new Map();
9
+ /**
10
+ * Register a rule
11
+ */
12
+ registerRule(descriptor) {
13
+ if (this.rules.has(descriptor.id)) {
14
+ throw new Error(`Rule with id "${descriptor.id}" already registered`);
15
+ }
16
+ this.rules.set(descriptor.id, descriptor);
17
+ }
18
+ /**
19
+ * Register a constraint
20
+ */
21
+ registerConstraint(descriptor) {
22
+ if (this.constraints.has(descriptor.id)) {
23
+ throw new Error(`Constraint with id "${descriptor.id}" already registered`);
24
+ }
25
+ this.constraints.set(descriptor.id, descriptor);
26
+ }
27
+ /**
28
+ * Register a module (all its rules and constraints)
29
+ */
30
+ registerModule(module) {
31
+ for (const rule of module.rules) {
32
+ this.registerRule(rule);
33
+ }
34
+ for (const constraint of module.constraints) {
35
+ this.registerConstraint(constraint);
36
+ }
37
+ }
38
+ /**
39
+ * Get a rule by ID
40
+ */
41
+ getRule(id) {
42
+ return this.rules.get(id);
43
+ }
44
+ /**
45
+ * Get a constraint by ID
46
+ */
47
+ getConstraint(id) {
48
+ return this.constraints.get(id);
49
+ }
50
+ /**
51
+ * Get all registered rule IDs
52
+ */
53
+ getRuleIds() {
54
+ return Array.from(this.rules.keys());
55
+ }
56
+ /**
57
+ * Get all registered constraint IDs
58
+ */
59
+ getConstraintIds() {
60
+ return Array.from(this.constraints.keys());
61
+ }
62
+ /**
63
+ * Get all rules
64
+ */
65
+ getAllRules() {
66
+ return Array.from(this.rules.values());
67
+ }
68
+ /**
69
+ * Get all constraints
70
+ */
71
+ getAllConstraints() {
72
+ return Array.from(this.constraints.values());
73
+ }
74
+ };
75
+
76
+ // src/core/reactive-engine.svelte.ts
77
+ import * as $ from "svelte/internal/client";
78
+ var ReactiveLogicEngine = class {
79
+ #state = (
80
+ // Use Svelte's $state rune for automatic reactivity
81
+ $.state($.proxy({ context: {}, facts: [], meta: {} }))
82
+ );
83
+ get state() {
84
+ return $.get(this.#state);
85
+ }
86
+ set state(value) {
87
+ $.set(this.#state, value, true);
88
+ }
89
+ _engine;
90
+ constructor(options) {
91
+ this.state.context = options.initialContext;
92
+ this.state.facts = options.initialFacts ?? [];
93
+ this.state.meta = options.initialMeta ?? {};
94
+ if (options.registry) {
95
+ this._engine = createPraxisEngine({
96
+ initialContext: options.initialContext,
97
+ registry: options.registry
98
+ });
99
+ } else {
100
+ this._engine = createPraxisEngine({
101
+ initialContext: options.initialContext,
102
+ registry: new PraxisRegistry()
103
+ });
104
+ }
105
+ }
106
+ /**
107
+ * Access the reactive context.
108
+ * In Svelte 5 components, changes to this object will automatically trigger updates.
109
+ */
110
+ get context() {
111
+ return this.state.context;
112
+ }
113
+ /**
114
+ * Access the reactive facts list.
115
+ */
116
+ get facts() {
117
+ return this.state.facts;
118
+ }
119
+ /**
120
+ * Access the reactive metadata.
121
+ */
122
+ get meta() {
123
+ return this.state.meta;
124
+ }
125
+ /**
126
+ * Apply a mutation to the state.
127
+ * Changes will automatically trigger Svelte reactivity.
128
+ *
129
+ * @param mutator A function that receives the state and modifies it.
130
+ */
131
+ apply(mutator) {
132
+ mutator(this.state);
133
+ }
134
+ /**
135
+ * Process events through the logic engine and update reactive state.
136
+ *
137
+ * @param events Events to process
138
+ */
139
+ step(events) {
140
+ const result = this._engine.step(events);
141
+ this.state.context = result.state.context;
142
+ this.state.facts = result.state.facts;
143
+ this.state.meta = result.state.meta ?? {};
144
+ }
145
+ };
146
+ function createReactiveEngine(options) {
147
+ return new ReactiveLogicEngine(options);
148
+ }
149
+
150
+ export {
151
+ PraxisRegistry,
152
+ ReactiveLogicEngine,
153
+ createReactiveEngine
154
+ };
@@ -1,77 +1,6 @@
1
1
  // src/core/protocol.ts
2
2
  var PRAXIS_PROTOCOL_VERSION = "1.0.0";
3
3
 
4
- // src/core/rules.ts
5
- var PraxisRegistry = class {
6
- rules = /* @__PURE__ */ new Map();
7
- constraints = /* @__PURE__ */ new Map();
8
- /**
9
- * Register a rule
10
- */
11
- registerRule(descriptor) {
12
- if (this.rules.has(descriptor.id)) {
13
- throw new Error(`Rule with id "${descriptor.id}" already registered`);
14
- }
15
- this.rules.set(descriptor.id, descriptor);
16
- }
17
- /**
18
- * Register a constraint
19
- */
20
- registerConstraint(descriptor) {
21
- if (this.constraints.has(descriptor.id)) {
22
- throw new Error(`Constraint with id "${descriptor.id}" already registered`);
23
- }
24
- this.constraints.set(descriptor.id, descriptor);
25
- }
26
- /**
27
- * Register a module (all its rules and constraints)
28
- */
29
- registerModule(module) {
30
- for (const rule of module.rules) {
31
- this.registerRule(rule);
32
- }
33
- for (const constraint of module.constraints) {
34
- this.registerConstraint(constraint);
35
- }
36
- }
37
- /**
38
- * Get a rule by ID
39
- */
40
- getRule(id) {
41
- return this.rules.get(id);
42
- }
43
- /**
44
- * Get a constraint by ID
45
- */
46
- getConstraint(id) {
47
- return this.constraints.get(id);
48
- }
49
- /**
50
- * Get all registered rule IDs
51
- */
52
- getRuleIds() {
53
- return Array.from(this.rules.keys());
54
- }
55
- /**
56
- * Get all registered constraint IDs
57
- */
58
- getConstraintIds() {
59
- return Array.from(this.constraints.keys());
60
- }
61
- /**
62
- * Get all rules
63
- */
64
- getAllRules() {
65
- return Array.from(this.rules.values());
66
- }
67
- /**
68
- * Get all constraints
69
- */
70
- getAllConstraints() {
71
- return Array.from(this.constraints.values());
72
- }
73
- };
74
-
75
4
  // src/core/engine.ts
76
5
  function safeClone(value) {
77
6
  if (value === null || typeof value !== "object") {
@@ -261,85 +190,8 @@ function createPraxisEngine(options) {
261
190
  return new LogicEngine(options);
262
191
  }
263
192
 
264
- // src/core/reactive-engine.svelte.ts
265
- import * as $ from "svelte/internal/client";
266
- var ReactiveLogicEngine = class {
267
- #state = (
268
- // Use Svelte's $state rune for automatic reactivity
269
- $.state($.proxy({ context: {}, facts: [], meta: {} }))
270
- );
271
- get state() {
272
- return $.get(this.#state);
273
- }
274
- set state(value) {
275
- $.set(this.#state, value, true);
276
- }
277
- _engine;
278
- constructor(options) {
279
- this.state.context = options.initialContext;
280
- this.state.facts = options.initialFacts ?? [];
281
- this.state.meta = options.initialMeta ?? {};
282
- if (options.registry) {
283
- this._engine = createPraxisEngine({
284
- initialContext: options.initialContext,
285
- registry: options.registry
286
- });
287
- } else {
288
- this._engine = createPraxisEngine({
289
- initialContext: options.initialContext,
290
- registry: new PraxisRegistry()
291
- });
292
- }
293
- }
294
- /**
295
- * Access the reactive context.
296
- * In Svelte 5 components, changes to this object will automatically trigger updates.
297
- */
298
- get context() {
299
- return this.state.context;
300
- }
301
- /**
302
- * Access the reactive facts list.
303
- */
304
- get facts() {
305
- return this.state.facts;
306
- }
307
- /**
308
- * Access the reactive metadata.
309
- */
310
- get meta() {
311
- return this.state.meta;
312
- }
313
- /**
314
- * Apply a mutation to the state.
315
- * Changes will automatically trigger Svelte reactivity.
316
- *
317
- * @param mutator A function that receives the state and modifies it.
318
- */
319
- apply(mutator) {
320
- mutator(this.state);
321
- }
322
- /**
323
- * Process events through the logic engine and update reactive state.
324
- *
325
- * @param events Events to process
326
- */
327
- step(events) {
328
- const result = this._engine.step(events);
329
- this.state.context = result.state.context;
330
- this.state.facts = result.state.facts;
331
- this.state.meta = result.state.meta ?? {};
332
- }
333
- };
334
- function createReactiveEngine(options) {
335
- return new ReactiveLogicEngine(options);
336
- }
337
-
338
193
  export {
339
194
  PRAXIS_PROTOCOL_VERSION,
340
- PraxisRegistry,
341
195
  LogicEngine,
342
- createPraxisEngine,
343
- ReactiveLogicEngine,
344
- createReactiveEngine
196
+ createPraxisEngine
345
197
  };
@@ -0,0 +1,8 @@
1
+ import {
2
+ LogicEngine,
3
+ createPraxisEngine
4
+ } from "./chunk-VOMLVI6V.js";
5
+ export {
6
+ LogicEngine,
7
+ createPraxisEngine
8
+ };
@@ -3161,4 +3161,133 @@ declare function attachTauriToEngine<TContext>(engine: LogicEngine<TContext>, ad
3161
3161
  */
3162
3162
  declare function generateTauriConfig(config: TauriAppConfig): Record<string, unknown>;
3163
3163
 
3164
- export { type ActivityState, type Actor, ActorManager, type CanvasDocument, type CanvasEdge, type CanvasEdgeStyle, type CanvasEditorConfig, type CanvasNode, type CanvasNodeStyle, type ComponentDefinition, ConstraintDescriptor, ConstraintFn, type ConstraintNode, type ConstraintSchema, type DefineConstraintOptions, type DefineModuleOptions, type DefineRuleOptions, type EventDefinition$1 as EventDefinition, type EventStreamEntry, type FactDefinition$1 as FactDefinition, ReactiveLogicEngine as FrameworkAgnosticReactiveEngine, type ReactiveEngineOptions as FrameworkAgnosticReactiveEngineOptions, type GeneratedDoc, type GeneratedPluresDBFile, type GraphEdge, type GuardianError, type GuardianResult, type GuardianWarning, InMemoryPraxisDB, type LifecycleState, type LoaderOptions, type LoaderResult, type LogicDefinition, LogicEngine, type ModelDefinition, type NodeBindings, type NodeDefinition, type OrchestrationDefinition, PRAXIS_PATHS, type PluresDBAdapter, type PluresDBAdapterConfig, type PluresDBAdapterOptions, PluresDBGenerator, type PluresDBGeneratorOptions, type PluresDBInstance, PluresDBPraxisAdapter, type PraxisDB, PraxisDBStore, type PraxisDBStoreOptions, PraxisEvent, PraxisFact, PraxisModule, PraxisRegistry, type PraxisSchema, PraxisSchemaRegistry, PraxisState, type RegistryGraph, RegistryIntrospector, type RegistrySchema, type RegistryStats, RuleDescriptor, RuleFn, type RuleNode, type RuleSchema, type StateChangeCallback, type StateDoc, type StateDocsConfig, StateDocsGenerator, type StateMachineDoc, type StoredSchema, type TauriAppConfig, type TauriBridge, type TauriCommand, type TauriEvent, type TauriFS, type TauriFileEntry, type TauriMenuItem, type TauriNotification, type TauriNotificationOptions, type TauriPlugin, type TauriPraxisAdapter, type TauriSecurityConfig, type TauriTray, type TauriUpdateConfig, type TauriUpdateInfo, type TauriWindowConfig, type TerminalNodeProps, type TransitionDoc, type UnsubscribeFn, type UnumAdapter, type UnumAdapterConfig, type UnumChannel, type UnumIdentity, type UnumMessage, type UnumStore, type ValidationError, type ValidationResult, attachTauriToEngine, attachToEngine, attachUnumToEngine, canvasToMermaid, canvasToSchema, canvasToYaml, createCanvasEditor, createReactiveEngine as createFrameworkAgnosticReactiveEngine, createInMemoryDB, createIntrospector, createMockTauriBridge, createPluresDB, createPluresDBAdapter, createPluresDBGenerator, createPraxisDBStore, createSchema, createSchemaRegistry, createSchemaTemplate, createStateDocsGenerator, createTauriPraxisAdapter, createTimerActor, createUnumAdapter, defineConstraint, defineEvent, defineFact, defineModule, defineRule, filterEvents, filterFacts, findEvent, findFact, generateDocs, generateId, generateTauriConfig, getEventPath, getFactPath, getSchemaPath, loadSchemaFromJson, loadSchemaFromYaml, registerSchema, schemaToCanvas, validateForGeneration, validateSchema, validateWithGuardian };
3164
+ /**
3165
+ * Unified Integration Helpers
3166
+ *
3167
+ * Convenience functions for setting up Praxis with all ecosystem integrations
3168
+ * (PluresDB, Unum, State-Docs, CodeCanvas) in a single call.
3169
+ */
3170
+
3171
+ /**
3172
+ * Configuration for unified Praxis application
3173
+ */
3174
+ interface UnifiedAppConfig<TContext = unknown> {
3175
+ /** Praxis registry with rules and constraints */
3176
+ registry: PraxisRegistry<TContext>;
3177
+ /** Initial context for the engine */
3178
+ initialContext: TContext;
3179
+ /** PluresDB instance (if not provided, creates in-memory DB) */
3180
+ db?: PraxisDB;
3181
+ /** Enable Unum for distributed communication */
3182
+ enableUnum?: boolean;
3183
+ /** Unum identity configuration (without id and createdAt which are auto-generated) */
3184
+ unumIdentity?: Omit<UnumIdentity, 'id' | 'createdAt'>;
3185
+ /** Enable State-Docs documentation generation */
3186
+ enableDocs?: boolean;
3187
+ /** State-Docs configuration */
3188
+ docsConfig?: {
3189
+ projectTitle: string;
3190
+ target?: string;
3191
+ };
3192
+ /** Praxis schema for CodeCanvas integration */
3193
+ schema?: PraxisSchema;
3194
+ }
3195
+ /**
3196
+ * Unified application instance with all integrations
3197
+ */
3198
+ interface UnifiedApp<TContext = unknown> {
3199
+ /** Praxis logic engine */
3200
+ engine: LogicEngine<TContext>;
3201
+ /** PluresDB adapter for persistence */
3202
+ pluresdb: PluresDBAdapter<TContext>;
3203
+ /** Unum adapter for distributed communication (if enabled) */
3204
+ unum?: UnumAdapter;
3205
+ /** Default Unum channel (if Unum enabled) */
3206
+ channel?: UnumChannel;
3207
+ /** State-Docs generator (if enabled) */
3208
+ docs?: StateDocsGenerator;
3209
+ /** CodeCanvas document (if schema provided) */
3210
+ canvas?: CanvasDocument;
3211
+ /** Generate documentation from current state */
3212
+ generateDocs?: () => GeneratedDoc[];
3213
+ /** Cleanup function to dispose all integrations */
3214
+ dispose: () => void;
3215
+ }
3216
+ /**
3217
+ * Create a unified Praxis application with all integrations
3218
+ *
3219
+ * This is a convenience function that sets up:
3220
+ * - Praxis logic engine
3221
+ * - PluresDB for persistence (auto-attaches to engine)
3222
+ * - Unum for distributed communication (optional)
3223
+ * - State-Docs for documentation generation (optional)
3224
+ * - CodeCanvas for visual schema editing (optional)
3225
+ *
3226
+ * @example
3227
+ * ```typescript
3228
+ * import { createUnifiedApp } from '@plures/praxis';
3229
+ *
3230
+ * const app = await createUnifiedApp({
3231
+ * registry: myRegistry,
3232
+ * initialContext: { count: 0 },
3233
+ * enableUnum: true,
3234
+ * unumIdentity: { name: 'node-1' },
3235
+ * enableDocs: true,
3236
+ * docsConfig: { projectTitle: 'My App' },
3237
+ * schema: mySchema,
3238
+ * });
3239
+ *
3240
+ * // Use the engine
3241
+ * app.engine.step([myEvent]);
3242
+ *
3243
+ * // Broadcast to other nodes
3244
+ * if (app.channel) {
3245
+ * await app.unum?.broadcastEvent(app.channel.id, myEvent);
3246
+ * }
3247
+ *
3248
+ * // Generate documentation
3249
+ * const docs = app.generateDocs?.();
3250
+ *
3251
+ * // Cleanup
3252
+ * app.dispose();
3253
+ * ```
3254
+ */
3255
+ declare function createUnifiedApp<TContext = unknown>(config: UnifiedAppConfig<TContext>): Promise<UnifiedApp<TContext>>;
3256
+ /**
3257
+ * Attach all available integrations to an existing Praxis engine
3258
+ *
3259
+ * This is useful when you already have an engine and want to add integrations.
3260
+ *
3261
+ * @example
3262
+ * ```typescript
3263
+ * import { createPraxisEngine, attachAllIntegrations } from '@plures/praxis';
3264
+ *
3265
+ * const engine = createPraxisEngine({ initialContext: {}, registry });
3266
+ *
3267
+ * const integrations = await attachAllIntegrations(engine, registry, {
3268
+ * enableUnum: true,
3269
+ * enableDocs: true,
3270
+ * });
3271
+ *
3272
+ * // Later cleanup
3273
+ * integrations.dispose();
3274
+ * ```
3275
+ */
3276
+ declare function attachAllIntegrations<TContext = unknown>(engine: LogicEngine<TContext>, registry: PraxisRegistry<TContext>, options?: {
3277
+ db?: PraxisDB;
3278
+ enableUnum?: boolean;
3279
+ unumIdentity?: Omit<UnumIdentity, 'id' | 'createdAt'>;
3280
+ enableDocs?: boolean;
3281
+ docsConfig?: {
3282
+ projectTitle: string;
3283
+ target?: string;
3284
+ };
3285
+ }): Promise<{
3286
+ pluresdb: PluresDBAdapter<TContext>;
3287
+ unum?: UnumAdapter;
3288
+ channel?: UnumChannel;
3289
+ docs?: StateDocsGenerator;
3290
+ dispose: () => void;
3291
+ }>;
3292
+
3293
+ export { type ActivityState, type Actor, ActorManager, type CanvasDocument, type CanvasEdge, type CanvasEdgeStyle, type CanvasEditorConfig, type CanvasNode, type CanvasNodeStyle, type ComponentDefinition, ConstraintDescriptor, ConstraintFn, type ConstraintNode, type ConstraintSchema, type DefineConstraintOptions, type DefineModuleOptions, type DefineRuleOptions, type EventDefinition$1 as EventDefinition, type EventStreamEntry, type FactDefinition$1 as FactDefinition, ReactiveLogicEngine as FrameworkAgnosticReactiveEngine, type ReactiveEngineOptions as FrameworkAgnosticReactiveEngineOptions, type GeneratedDoc, type GeneratedPluresDBFile, type GraphEdge, type GuardianError, type GuardianResult, type GuardianWarning, InMemoryPraxisDB, type LifecycleState, type LoaderOptions, type LoaderResult, type LogicDefinition, LogicEngine, type ModelDefinition, type NodeBindings, type NodeDefinition, type OrchestrationDefinition, PRAXIS_PATHS, type PluresDBAdapter, type PluresDBAdapterConfig, type PluresDBAdapterOptions, PluresDBGenerator, type PluresDBGeneratorOptions, type PluresDBInstance, PluresDBPraxisAdapter, type PraxisDB, PraxisDBStore, type PraxisDBStoreOptions, PraxisEvent, PraxisFact, PraxisModule, PraxisRegistry, type PraxisSchema, PraxisSchemaRegistry, PraxisState, type RegistryGraph, RegistryIntrospector, type RegistrySchema, type RegistryStats, RuleDescriptor, RuleFn, type RuleNode, type RuleSchema, type StateChangeCallback, type StateDoc, type StateDocsConfig, StateDocsGenerator, type StateMachineDoc, type StoredSchema, type TauriAppConfig, type TauriBridge, type TauriCommand, type TauriEvent, type TauriFS, type TauriFileEntry, type TauriMenuItem, type TauriNotification, type TauriNotificationOptions, type TauriPlugin, type TauriPraxisAdapter, type TauriSecurityConfig, type TauriTray, type TauriUpdateConfig, type TauriUpdateInfo, type TauriWindowConfig, type TerminalNodeProps, type TransitionDoc, type UnifiedApp, type UnifiedAppConfig, type UnsubscribeFn, type UnumAdapter, type UnumAdapterConfig, type UnumChannel, type UnumIdentity, type UnumMessage, type UnumStore, type ValidationError, type ValidationResult, attachAllIntegrations, attachTauriToEngine, attachToEngine, attachUnumToEngine, canvasToMermaid, canvasToSchema, canvasToYaml, createCanvasEditor, createReactiveEngine as createFrameworkAgnosticReactiveEngine, createInMemoryDB, createIntrospector, createMockTauriBridge, createPluresDB, createPluresDBAdapter, createPluresDBGenerator, createPraxisDBStore, createSchema, createSchemaRegistry, createSchemaTemplate, createStateDocsGenerator, createTauriPraxisAdapter, createTimerActor, createUnifiedApp, createUnumAdapter, defineConstraint, defineEvent, defineFact, defineModule, defineRule, filterEvents, filterFacts, findEvent, findFact, generateDocs, generateId, generateTauriConfig, getEventPath, getFactPath, getSchemaPath, loadSchemaFromJson, loadSchemaFromYaml, registerSchema, schemaToCanvas, validateForGeneration, validateSchema, validateWithGuardian };