@hyperfixi/patterns-reference 2.2.0 → 2.3.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.
@@ -1,4 +1,4 @@
1
- export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, d as getExamplesByCommand, e as getHighConfidenceTranslations, f as getHighQualityExamples, h as getLLMExamples, i as getLLMStats, j as getMostUsedExamples, k as getPatternById, l as getPatternStats, m as getPatternsByCategory, n as getPatternsByCommand, o as getTranslation, p as getTranslationStats, q as getTranslationsByLanguage, r as getVerifiedTranslations, s as getWordOrder, t as searchPatterns, u as updateQualityScore, v as verifyTranslation } from '../llm-DqcdT_IC.mjs';
1
+ export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, e as getExamplesByCommand, f as getHighConfidenceTranslations, h as getHighQualityExamples, i as getLLMExamples, j as getLLMStats, k as getMostUsedExamples, l as getPatternById, m as getPatternStats, n as getPatternsByCategory, o as getPatternsByCommand, p as getTranslation, q as getTranslationStats, r as getTranslationsByLanguage, s as getVerifiedTranslations, t as getWordOrder, u as searchPatterns, v as updateQualityScore, w as verifyTranslation } from '../llm-D_Mc5Uop.mjs';
2
2
  import { C as ConnectionOptions, r as PatternRole, i as Pattern, R as RoleType } from '../index-BqjfelDP.mjs';
3
3
  import { SemanticRole } from '@lokascript/semantic';
4
4
 
@@ -1,4 +1,4 @@
1
- export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, d as getExamplesByCommand, e as getHighConfidenceTranslations, f as getHighQualityExamples, h as getLLMExamples, i as getLLMStats, j as getMostUsedExamples, k as getPatternById, l as getPatternStats, m as getPatternsByCategory, n as getPatternsByCommand, o as getTranslation, p as getTranslationStats, q as getTranslationsByLanguage, r as getVerifiedTranslations, s as getWordOrder, t as searchPatterns, u as updateQualityScore, v as verifyTranslation } from '../llm-CFegbB6t.js';
1
+ export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, e as getExamplesByCommand, f as getHighConfidenceTranslations, h as getHighQualityExamples, i as getLLMExamples, j as getLLMStats, k as getMostUsedExamples, l as getPatternById, m as getPatternStats, n as getPatternsByCategory, o as getPatternsByCommand, p as getTranslation, q as getTranslationStats, r as getTranslationsByLanguage, s as getVerifiedTranslations, t as getWordOrder, u as searchPatterns, v as updateQualityScore, w as verifyTranslation } from '../llm-Cd3oNyVz.js';
2
2
  import { C as ConnectionOptions, r as PatternRole, i as Pattern, R as RoleType } from '../index-BqjfelDP.js';
3
3
  import { SemanticRole } from '@lokascript/semantic';
4
4
 
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { C as ConnectionOptions, a as Command, E as Expression, F as Feature, K as Keyword, S as SpecialSymbol, L as LanguageDocsStats, b as LanguageElementType, c as LanguageElement, d as LLMExample, P as PatternsReference } from './index-BqjfelDP.mjs';
2
2
  export { e as ClassifiedPattern, f as ComplexityLevel, D as DiscoveryResult, g as EngineCompat, h as ExpressionOperator, i as Pattern, j as PatternStats, k as SearchOptions, l as SyncOptions, m as SyncResult, T as TestOptions, n as Translation, o as TranslationMethod, V as ValidationOptions, p as ValidationResult, q as VerificationResult, W as WordOrder } from './index-BqjfelDP.mjs';
3
3
  import Database from 'better-sqlite3';
4
- export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, d as getExamplesByCommand, e as getHighConfidenceTranslations, f as getHighQualityExamples, h as getLLMExamples, i as getLLMStats, j as getMostUsedExamples, k as getPatternById, l as getPatternStats, m as getPatternsByCategory, n as getPatternsByCommand, o as getTranslation, p as getTranslationStats, q as getTranslationsByLanguage, r as getVerifiedTranslations, s as getWordOrder, t as searchPatterns, u as updateQualityScore, v as verifyTranslation } from './llm-DqcdT_IC.mjs';
4
+ export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, d as getBehaviorPatterns, e as getExamplesByCommand, f as getHighConfidenceTranslations, h as getHighQualityExamples, i as getLLMExamples, j as getLLMStats, k as getMostUsedExamples, l as getPatternById, m as getPatternStats, n as getPatternsByCategory, o as getPatternsByCommand, p as getTranslation, q as getTranslationStats, r as getTranslationsByLanguage, s as getVerifiedTranslations, t as getWordOrder, u as searchPatterns, v as updateQualityScore, w as verifyTranslation } from './llm-D_Mc5Uop.mjs';
5
5
  export { discoverPatterns, seedLLMExamples, syncTranslations, validateAllTranslations } from './sync/index.mjs';
6
6
  import '@lokascript/semantic';
7
7
 
@@ -32,6 +32,61 @@ declare function isConnected(): boolean;
32
32
  */
33
33
  declare function getCurrentDbPath(): string | null;
34
34
 
35
+ /**
36
+ * Behavior Loader — Load and register hyperscript behaviors from patterns-reference
37
+ *
38
+ * Queries the patterns database for behavior definitions, compiles them,
39
+ * and registers them with a LokaScript runtime instance.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * import { loadBehaviors } from '@hyperfixi/patterns-reference';
44
+ *
45
+ * // Load all behaviors
46
+ * const result = await loadBehaviors(window.hyperfixi);
47
+ * console.log('Loaded:', result.loaded);
48
+ *
49
+ * // Load specific behaviors
50
+ * const result = await loadBehaviors(runtime, { names: ['Toggleable', 'Draggable'] });
51
+ * ```
52
+ */
53
+
54
+ /**
55
+ * Minimal runtime interface required for behavior loading.
56
+ * Compatible with both HyperscriptAPI and the window.hyperfixi global.
57
+ */
58
+ interface BehaviorRuntime {
59
+ compileSync(code: string, options?: {
60
+ traditional?: boolean;
61
+ }): {
62
+ ok: boolean;
63
+ ast?: unknown;
64
+ errors?: unknown[];
65
+ };
66
+ execute(ast: unknown, ctx: unknown): Promise<void>;
67
+ createContext?(): {
68
+ locals: Map<string, unknown>;
69
+ globals: Map<string, unknown>;
70
+ };
71
+ }
72
+ interface LoadBehaviorsOptions {
73
+ /** Only load behaviors matching these names (e.g., ['Toggleable', 'Draggable']) */
74
+ names?: string[];
75
+ /** Database connection options */
76
+ connectionOptions?: ConnectionOptions;
77
+ }
78
+ interface LoadBehaviorsResult {
79
+ /** IDs of successfully loaded behavior patterns */
80
+ loaded: string[];
81
+ /** Error messages for behaviors that failed to compile */
82
+ errors: string[];
83
+ }
84
+ /**
85
+ * Load behavior definitions from patterns-reference and register them
86
+ * with a LokaScript runtime instance.
87
+ */
88
+ declare function loadBehaviors(runtime: BehaviorRuntime, options?: LoadBehaviorsOptions): Promise<LoadBehaviorsResult>;
89
+
35
90
  /**
36
91
  * Language Documentation API
37
92
  *
@@ -400,4 +455,4 @@ declare function createPatternsReference(options?: ConnectionOptions): PatternsR
400
455
  */
401
456
  declare const VERSION = "0.1.0";
402
457
 
403
- export { Command, ConnectionOptions, DatabasePatternsProvider, Expression, Feature, type IntegrationResult, Keyword, LLMExample, type LLMExampleRecord, LanguageDocsStats, LanguageElement, LanguageElementType, type PatternEntry, PatternsReference, type PatternsSource, type SemanticIntegrationOptions, SpecialSymbol, VERSION, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllSpecialSymbols, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultProvider, getExpressionByName, getExpressionsByCategory, getFeatureByName, getKeywordByName, getLLMExampleStats, getLanguageDocsStats, getSpecialSymbolByName, getSupportedLanguages, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, trackExampleUsage, uninitializeSemanticIntegration };
458
+ export { type BehaviorRuntime, Command, ConnectionOptions, DatabasePatternsProvider, Expression, Feature, type IntegrationResult, Keyword, LLMExample, type LLMExampleRecord, LanguageDocsStats, LanguageElement, LanguageElementType, type LoadBehaviorsOptions, type LoadBehaviorsResult, type PatternEntry, PatternsReference, type PatternsSource, type SemanticIntegrationOptions, SpecialSymbol, VERSION, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllSpecialSymbols, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultProvider, getExpressionByName, getExpressionsByCategory, getFeatureByName, getKeywordByName, getLLMExampleStats, getLanguageDocsStats, getSpecialSymbolByName, getSupportedLanguages, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, loadBehaviors, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, trackExampleUsage, uninitializeSemanticIntegration };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { C as ConnectionOptions, a as Command, E as Expression, F as Feature, K as Keyword, S as SpecialSymbol, L as LanguageDocsStats, b as LanguageElementType, c as LanguageElement, d as LLMExample, P as PatternsReference } from './index-BqjfelDP.js';
2
2
  export { e as ClassifiedPattern, f as ComplexityLevel, D as DiscoveryResult, g as EngineCompat, h as ExpressionOperator, i as Pattern, j as PatternStats, k as SearchOptions, l as SyncOptions, m as SyncResult, T as TestOptions, n as Translation, o as TranslationMethod, V as ValidationOptions, p as ValidationResult, q as VerificationResult, W as WordOrder } from './index-BqjfelDP.js';
3
3
  import Database from 'better-sqlite3';
4
- export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, d as getExamplesByCommand, e as getHighConfidenceTranslations, f as getHighQualityExamples, h as getLLMExamples, i as getLLMStats, j as getMostUsedExamples, k as getPatternById, l as getPatternStats, m as getPatternsByCategory, n as getPatternsByCommand, o as getTranslation, p as getTranslationStats, q as getTranslationsByLanguage, r as getVerifiedTranslations, s as getWordOrder, t as searchPatterns, u as updateQualityScore, v as verifyTranslation } from './llm-CFegbB6t.js';
4
+ export { a as addLLMExample, b as buildFewShotContext, g as getAllPatterns, c as getAllTranslations, d as getBehaviorPatterns, e as getExamplesByCommand, f as getHighConfidenceTranslations, h as getHighQualityExamples, i as getLLMExamples, j as getLLMStats, k as getMostUsedExamples, l as getPatternById, m as getPatternStats, n as getPatternsByCategory, o as getPatternsByCommand, p as getTranslation, q as getTranslationStats, r as getTranslationsByLanguage, s as getVerifiedTranslations, t as getWordOrder, u as searchPatterns, v as updateQualityScore, w as verifyTranslation } from './llm-Cd3oNyVz.js';
5
5
  export { discoverPatterns, seedLLMExamples, syncTranslations, validateAllTranslations } from './sync/index.js';
6
6
  import '@lokascript/semantic';
7
7
 
@@ -32,6 +32,61 @@ declare function isConnected(): boolean;
32
32
  */
33
33
  declare function getCurrentDbPath(): string | null;
34
34
 
35
+ /**
36
+ * Behavior Loader — Load and register hyperscript behaviors from patterns-reference
37
+ *
38
+ * Queries the patterns database for behavior definitions, compiles them,
39
+ * and registers them with a LokaScript runtime instance.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * import { loadBehaviors } from '@hyperfixi/patterns-reference';
44
+ *
45
+ * // Load all behaviors
46
+ * const result = await loadBehaviors(window.hyperfixi);
47
+ * console.log('Loaded:', result.loaded);
48
+ *
49
+ * // Load specific behaviors
50
+ * const result = await loadBehaviors(runtime, { names: ['Toggleable', 'Draggable'] });
51
+ * ```
52
+ */
53
+
54
+ /**
55
+ * Minimal runtime interface required for behavior loading.
56
+ * Compatible with both HyperscriptAPI and the window.hyperfixi global.
57
+ */
58
+ interface BehaviorRuntime {
59
+ compileSync(code: string, options?: {
60
+ traditional?: boolean;
61
+ }): {
62
+ ok: boolean;
63
+ ast?: unknown;
64
+ errors?: unknown[];
65
+ };
66
+ execute(ast: unknown, ctx: unknown): Promise<void>;
67
+ createContext?(): {
68
+ locals: Map<string, unknown>;
69
+ globals: Map<string, unknown>;
70
+ };
71
+ }
72
+ interface LoadBehaviorsOptions {
73
+ /** Only load behaviors matching these names (e.g., ['Toggleable', 'Draggable']) */
74
+ names?: string[];
75
+ /** Database connection options */
76
+ connectionOptions?: ConnectionOptions;
77
+ }
78
+ interface LoadBehaviorsResult {
79
+ /** IDs of successfully loaded behavior patterns */
80
+ loaded: string[];
81
+ /** Error messages for behaviors that failed to compile */
82
+ errors: string[];
83
+ }
84
+ /**
85
+ * Load behavior definitions from patterns-reference and register them
86
+ * with a LokaScript runtime instance.
87
+ */
88
+ declare function loadBehaviors(runtime: BehaviorRuntime, options?: LoadBehaviorsOptions): Promise<LoadBehaviorsResult>;
89
+
35
90
  /**
36
91
  * Language Documentation API
37
92
  *
@@ -400,4 +455,4 @@ declare function createPatternsReference(options?: ConnectionOptions): PatternsR
400
455
  */
401
456
  declare const VERSION = "0.1.0";
402
457
 
403
- export { Command, ConnectionOptions, DatabasePatternsProvider, Expression, Feature, type IntegrationResult, Keyword, LLMExample, type LLMExampleRecord, LanguageDocsStats, LanguageElement, LanguageElementType, type PatternEntry, PatternsReference, type PatternsSource, type SemanticIntegrationOptions, SpecialSymbol, VERSION, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllSpecialSymbols, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultProvider, getExpressionByName, getExpressionsByCategory, getFeatureByName, getKeywordByName, getLLMExampleStats, getLanguageDocsStats, getSpecialSymbolByName, getSupportedLanguages, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, trackExampleUsage, uninitializeSemanticIntegration };
458
+ export { type BehaviorRuntime, Command, ConnectionOptions, DatabasePatternsProvider, Expression, Feature, type IntegrationResult, Keyword, LLMExample, type LLMExampleRecord, LanguageDocsStats, LanguageElement, LanguageElementType, type LoadBehaviorsOptions, type LoadBehaviorsResult, type PatternEntry, PatternsReference, type PatternsSource, type SemanticIntegrationOptions, SpecialSymbol, VERSION, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllSpecialSymbols, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultProvider, getExpressionByName, getExpressionsByCategory, getFeatureByName, getKeywordByName, getLLMExampleStats, getLanguageDocsStats, getSpecialSymbolByName, getSupportedLanguages, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, loadBehaviors, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, trackExampleUsage, uninitializeSemanticIntegration };
package/dist/index.js CHANGED
@@ -154,6 +154,9 @@ async function getPatternStats(connOptions) {
154
154
  avgConfidence: avgConfResult.avg || 0
155
155
  };
156
156
  }
157
+ async function getBehaviorPatterns(options) {
158
+ return getPatternsByCategory("behavior", options);
159
+ }
157
160
  function mapRowToPattern(row) {
158
161
  return {
159
162
  id: row.id,
@@ -188,6 +191,34 @@ function inferDifficulty(code) {
188
191
  return "advanced";
189
192
  }
190
193
 
194
+ // src/api/behavior-loader.ts
195
+ async function loadBehaviors(runtime, options) {
196
+ const patterns = await getBehaviorPatterns(options?.connectionOptions);
197
+ const filtered = options?.names ? patterns.filter((p) => options.names.some((name) => p.rawCode.includes(`behavior ${name}(`))) : patterns;
198
+ const loaded = [];
199
+ const errors = [];
200
+ for (const pattern of filtered) {
201
+ const result = runtime.compileSync(pattern.rawCode, { traditional: true });
202
+ if (result.ok && result.ast) {
203
+ try {
204
+ const ctx = runtime.createContext?.() ?? {
205
+ locals: /* @__PURE__ */ new Map(),
206
+ globals: /* @__PURE__ */ new Map()
207
+ };
208
+ await runtime.execute(result.ast, ctx);
209
+ loaded.push(pattern.id);
210
+ } catch (err) {
211
+ errors.push(
212
+ `${pattern.id}: execute failed \u2014 ${err instanceof Error ? err.message : String(err)}`
213
+ );
214
+ }
215
+ } else {
216
+ errors.push(`${pattern.id}: compile failed \u2014 ${JSON.stringify(result.errors)}`);
217
+ }
218
+ }
219
+ return { loaded, errors };
220
+ }
221
+
191
222
  // src/api/translations.ts
192
223
  async function getTranslation(patternId, language, options) {
193
224
  const db = getDatabase({ ...options, readonly: true });
@@ -1264,6 +1295,7 @@ exports.getAllKeywords = getAllKeywords;
1264
1295
  exports.getAllPatterns = getAllPatterns;
1265
1296
  exports.getAllSpecialSymbols = getAllSpecialSymbols;
1266
1297
  exports.getAllTranslations = getAllTranslations;
1298
+ exports.getBehaviorPatterns = getBehaviorPatterns;
1267
1299
  exports.getBridgeProvider = getBridgeProvider;
1268
1300
  exports.getCommandByName = getCommandByName;
1269
1301
  exports.getCurrentDbPath = getCurrentDbPath;
@@ -1296,6 +1328,7 @@ exports.initializeSemanticIntegration = initializeSemanticIntegration;
1296
1328
  exports.isConnected = isConnected;
1297
1329
  exports.isDatabaseAvailable = isDatabaseAvailable;
1298
1330
  exports.isSemanticIntegrationInitialized = isSemanticIntegrationInitialized;
1331
+ exports.loadBehaviors = loadBehaviors;
1299
1332
  exports.queryPatterns = queryPatterns;
1300
1333
  exports.queryPatternsForCommand = queryPatternsForCommand;
1301
1334
  exports.resetConnection = resetConnection;
package/dist/index.mjs CHANGED
@@ -146,6 +146,9 @@ async function getPatternStats(connOptions) {
146
146
  avgConfidence: avgConfResult.avg || 0
147
147
  };
148
148
  }
149
+ async function getBehaviorPatterns(options) {
150
+ return getPatternsByCategory("behavior", options);
151
+ }
149
152
  function mapRowToPattern(row) {
150
153
  return {
151
154
  id: row.id,
@@ -180,6 +183,34 @@ function inferDifficulty(code) {
180
183
  return "advanced";
181
184
  }
182
185
 
186
+ // src/api/behavior-loader.ts
187
+ async function loadBehaviors(runtime, options) {
188
+ const patterns = await getBehaviorPatterns(options?.connectionOptions);
189
+ const filtered = options?.names ? patterns.filter((p) => options.names.some((name) => p.rawCode.includes(`behavior ${name}(`))) : patterns;
190
+ const loaded = [];
191
+ const errors = [];
192
+ for (const pattern of filtered) {
193
+ const result = runtime.compileSync(pattern.rawCode, { traditional: true });
194
+ if (result.ok && result.ast) {
195
+ try {
196
+ const ctx = runtime.createContext?.() ?? {
197
+ locals: /* @__PURE__ */ new Map(),
198
+ globals: /* @__PURE__ */ new Map()
199
+ };
200
+ await runtime.execute(result.ast, ctx);
201
+ loaded.push(pattern.id);
202
+ } catch (err) {
203
+ errors.push(
204
+ `${pattern.id}: execute failed \u2014 ${err instanceof Error ? err.message : String(err)}`
205
+ );
206
+ }
207
+ } else {
208
+ errors.push(`${pattern.id}: compile failed \u2014 ${JSON.stringify(result.errors)}`);
209
+ }
210
+ }
211
+ return { loaded, errors };
212
+ }
213
+
183
214
  // src/api/translations.ts
184
215
  async function getTranslation(patternId, language, options) {
185
216
  const db = getDatabase({ ...options, readonly: true });
@@ -1237,4 +1268,4 @@ function createPatternsReference(options) {
1237
1268
  }
1238
1269
  var VERSION = "0.1.0";
1239
1270
 
1240
- export { DatabasePatternsProvider, VERSION, addLLMExample, buildFewShotContext, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, discoverPatterns, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllPatterns, getAllSpecialSymbols, getAllTranslations, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultProvider, getExamplesByCommand, getExpressionByName, getExpressionsByCategory, getFeatureByName, getHighConfidenceTranslations, getHighQualityExamples, getKeywordByName, getLLMExampleStats, getLLMExamples, getLLMStats, getLanguageDocsStats, getMostUsedExamples, getPatternById, getPatternStats, getPatternsByCategory, getPatternsByCommand, getSpecialSymbolByName, getSupportedLanguages, getTranslation, getTranslationStats, getTranslationsByLanguage, getVerifiedTranslations, getWordOrder, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, searchPatterns, seedLLMExamples, syncTranslations, trackExampleUsage, uninitializeSemanticIntegration, updateQualityScore, validateAllTranslations, verifyTranslation };
1271
+ export { DatabasePatternsProvider, VERSION, addLLMExample, buildFewShotContext, buildFewShotContextSync, closeDatabase, createLLMAdapter, createPatternsProvider, createPatternsReference, discoverPatterns, findExamplesByCommand, findRelevantExamples, getAllCommands, getAllExpressions, getAllFeatures, getAllKeywords, getAllPatterns, getAllSpecialSymbols, getAllTranslations, getBehaviorPatterns, getBridgeProvider, getCommandByName, getCurrentDbPath, getDatabase, getDefaultProvider, getExamplesByCommand, getExpressionByName, getExpressionsByCategory, getFeatureByName, getHighConfidenceTranslations, getHighQualityExamples, getKeywordByName, getLLMExampleStats, getLLMExamples, getLLMStats, getLanguageDocsStats, getMostUsedExamples, getPatternById, getPatternStats, getPatternsByCategory, getPatternsByCommand, getSpecialSymbolByName, getSupportedLanguages, getTranslation, getTranslationStats, getTranslationsByLanguage, getVerifiedTranslations, getWordOrder, initializeSemanticIntegration, isConnected, isDatabaseAvailable, isSemanticIntegrationInitialized, loadBehaviors, queryPatterns, queryPatternsForCommand, resetConnection, resetDefaultProvider, searchCommands, searchLanguageElements, searchPatterns, seedLLMExamples, syncTranslations, trackExampleUsage, uninitializeSemanticIntegration, updateQualityScore, validateAllTranslations, verifyTranslation };
@@ -30,6 +30,14 @@ declare function getAllPatterns(searchOptions?: SearchOptions, connOptions?: Con
30
30
  * Get pattern statistics.
31
31
  */
32
32
  declare function getPatternStats(connOptions?: ConnectionOptions): Promise<PatternStats>;
33
+ /**
34
+ * Get behavior definition patterns.
35
+ *
36
+ * Returns patterns with feature='behavior' — these are installable
37
+ * behavior definitions (behavior Name(params) ... end) that can be
38
+ * compiled and registered with a LokaScript runtime.
39
+ */
40
+ declare function getBehaviorPatterns(options?: ConnectionOptions): Promise<Pattern[]>;
33
41
 
34
42
  /**
35
43
  * Translation Operations API
@@ -120,4 +128,4 @@ declare function getLLMStats(options?: ConnectionOptions): Promise<{
120
128
  totalUsage: number;
121
129
  }>;
122
130
 
123
- export { addLLMExample as a, buildFewShotContext as b, getAllTranslations as c, getExamplesByCommand as d, getHighConfidenceTranslations as e, getHighQualityExamples as f, getAllPatterns as g, getLLMExamples as h, getLLMStats as i, getMostUsedExamples as j, getPatternById as k, getPatternStats as l, getPatternsByCategory as m, getPatternsByCommand as n, getTranslation as o, getTranslationStats as p, getTranslationsByLanguage as q, getVerifiedTranslations as r, getWordOrder as s, searchPatterns as t, updateQualityScore as u, verifyTranslation as v };
131
+ export { addLLMExample as a, buildFewShotContext as b, getAllTranslations as c, getBehaviorPatterns as d, getExamplesByCommand as e, getHighConfidenceTranslations as f, getAllPatterns as g, getHighQualityExamples as h, getLLMExamples as i, getLLMStats as j, getMostUsedExamples as k, getPatternById as l, getPatternStats as m, getPatternsByCategory as n, getPatternsByCommand as o, getTranslation as p, getTranslationStats as q, getTranslationsByLanguage as r, getVerifiedTranslations as s, getWordOrder as t, searchPatterns as u, updateQualityScore as v, verifyTranslation as w };
@@ -30,6 +30,14 @@ declare function getAllPatterns(searchOptions?: SearchOptions, connOptions?: Con
30
30
  * Get pattern statistics.
31
31
  */
32
32
  declare function getPatternStats(connOptions?: ConnectionOptions): Promise<PatternStats>;
33
+ /**
34
+ * Get behavior definition patterns.
35
+ *
36
+ * Returns patterns with feature='behavior' — these are installable
37
+ * behavior definitions (behavior Name(params) ... end) that can be
38
+ * compiled and registered with a LokaScript runtime.
39
+ */
40
+ declare function getBehaviorPatterns(options?: ConnectionOptions): Promise<Pattern[]>;
33
41
 
34
42
  /**
35
43
  * Translation Operations API
@@ -120,4 +128,4 @@ declare function getLLMStats(options?: ConnectionOptions): Promise<{
120
128
  totalUsage: number;
121
129
  }>;
122
130
 
123
- export { addLLMExample as a, buildFewShotContext as b, getAllTranslations as c, getExamplesByCommand as d, getHighConfidenceTranslations as e, getHighQualityExamples as f, getAllPatterns as g, getLLMExamples as h, getLLMStats as i, getMostUsedExamples as j, getPatternById as k, getPatternStats as l, getPatternsByCategory as m, getPatternsByCommand as n, getTranslation as o, getTranslationStats as p, getTranslationsByLanguage as q, getVerifiedTranslations as r, getWordOrder as s, searchPatterns as t, updateQualityScore as u, verifyTranslation as v };
131
+ export { addLLMExample as a, buildFewShotContext as b, getAllTranslations as c, getBehaviorPatterns as d, getExamplesByCommand as e, getHighConfidenceTranslations as f, getAllPatterns as g, getHighQualityExamples as h, getLLMExamples as i, getLLMStats as j, getMostUsedExamples as k, getPatternById as l, getPatternStats as m, getPatternsByCategory as n, getPatternsByCommand as o, getTranslation as p, getTranslationStats as q, getTranslationsByLanguage as r, getVerifiedTranslations as s, getWordOrder as t, searchPatterns as u, updateQualityScore as v, verifyTranslation as w };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperfixi/patterns-reference",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Queryable patterns database for hyperscript with multilingual translations and LLM support",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Behavior Loader — Load and register hyperscript behaviors from patterns-reference
3
+ *
4
+ * Queries the patterns database for behavior definitions, compiles them,
5
+ * and registers them with a LokaScript runtime instance.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { loadBehaviors } from '@hyperfixi/patterns-reference';
10
+ *
11
+ * // Load all behaviors
12
+ * const result = await loadBehaviors(window.hyperfixi);
13
+ * console.log('Loaded:', result.loaded);
14
+ *
15
+ * // Load specific behaviors
16
+ * const result = await loadBehaviors(runtime, { names: ['Toggleable', 'Draggable'] });
17
+ * ```
18
+ */
19
+
20
+ import { getBehaviorPatterns } from './patterns';
21
+ import type { ConnectionOptions } from '../types';
22
+
23
+ /**
24
+ * Minimal runtime interface required for behavior loading.
25
+ * Compatible with both HyperscriptAPI and the window.hyperfixi global.
26
+ */
27
+ export interface BehaviorRuntime {
28
+ compileSync(
29
+ code: string,
30
+ options?: { traditional?: boolean }
31
+ ): { ok: boolean; ast?: unknown; errors?: unknown[] };
32
+ execute(ast: unknown, ctx: unknown): Promise<void>;
33
+ createContext?(): { locals: Map<string, unknown>; globals: Map<string, unknown> };
34
+ }
35
+
36
+ export interface LoadBehaviorsOptions {
37
+ /** Only load behaviors matching these names (e.g., ['Toggleable', 'Draggable']) */
38
+ names?: string[];
39
+ /** Database connection options */
40
+ connectionOptions?: ConnectionOptions;
41
+ }
42
+
43
+ export interface LoadBehaviorsResult {
44
+ /** IDs of successfully loaded behavior patterns */
45
+ loaded: string[];
46
+ /** Error messages for behaviors that failed to compile */
47
+ errors: string[];
48
+ }
49
+
50
+ /**
51
+ * Load behavior definitions from patterns-reference and register them
52
+ * with a LokaScript runtime instance.
53
+ */
54
+ export async function loadBehaviors(
55
+ runtime: BehaviorRuntime,
56
+ options?: LoadBehaviorsOptions
57
+ ): Promise<LoadBehaviorsResult> {
58
+ const patterns = await getBehaviorPatterns(options?.connectionOptions);
59
+
60
+ const filtered = options?.names
61
+ ? patterns.filter(p => options.names!.some(name => p.rawCode.includes(`behavior ${name}(`)))
62
+ : patterns;
63
+
64
+ const loaded: string[] = [];
65
+ const errors: string[] = [];
66
+
67
+ for (const pattern of filtered) {
68
+ const result = runtime.compileSync(pattern.rawCode, { traditional: true });
69
+ if (result.ok && result.ast) {
70
+ try {
71
+ const ctx = runtime.createContext?.() ?? {
72
+ locals: new Map(),
73
+ globals: new Map(),
74
+ };
75
+ await runtime.execute(result.ast, ctx);
76
+ loaded.push(pattern.id);
77
+ } catch (err) {
78
+ errors.push(
79
+ `${pattern.id}: execute failed — ${err instanceof Error ? err.message : String(err)}`
80
+ );
81
+ }
82
+ } else {
83
+ errors.push(`${pattern.id}: compile failed — ${JSON.stringify(result.errors)}`);
84
+ }
85
+ }
86
+
87
+ return { loaded, errors };
88
+ }
@@ -222,6 +222,17 @@ export async function getPatternStats(connOptions?: ConnectionOptions): Promise<
222
222
  };
223
223
  }
224
224
 
225
+ /**
226
+ * Get behavior definition patterns.
227
+ *
228
+ * Returns patterns with feature='behavior' — these are installable
229
+ * behavior definitions (behavior Name(params) ... end) that can be
230
+ * compiled and registered with a LokaScript runtime.
231
+ */
232
+ export async function getBehaviorPatterns(options?: ConnectionOptions): Promise<Pattern[]> {
233
+ return getPatternsByCategory('behavior', options);
234
+ }
235
+
225
236
  // =============================================================================
226
237
  // Helper Functions
227
238
  // =============================================================================
package/src/index.ts CHANGED
@@ -97,8 +97,17 @@ export {
97
97
  searchPatterns,
98
98
  getAllPatterns,
99
99
  getPatternStats,
100
+ getBehaviorPatterns,
100
101
  } from './api/patterns';
101
102
 
103
+ // Behavior Loader
104
+ export { loadBehaviors } from './api/behavior-loader';
105
+ export type {
106
+ BehaviorRuntime,
107
+ LoadBehaviorsOptions,
108
+ LoadBehaviorsResult,
109
+ } from './api/behavior-loader';
110
+
102
111
  // Translations
103
112
  export {
104
113
  getTranslation,