@almadar/core 1.0.18 → 2.1.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.
- package/LICENSE +21 -72
- package/README.md +25 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +136 -1
- package/dist/types/index.js +17 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +6 -5
package/dist/types/index.d.ts
CHANGED
|
@@ -345,6 +345,18 @@ interface ValidationMeta {
|
|
|
345
345
|
* Types for app summaries, stats, and save operations.
|
|
346
346
|
*/
|
|
347
347
|
|
|
348
|
+
/**
|
|
349
|
+
* GitHub repository link metadata stored in Firestore.
|
|
350
|
+
* Enables GitHub as the source of truth for schema files.
|
|
351
|
+
*/
|
|
352
|
+
interface GitHubLink {
|
|
353
|
+
repoUrl: string;
|
|
354
|
+
owner: string;
|
|
355
|
+
repo: string;
|
|
356
|
+
defaultBranch: string;
|
|
357
|
+
connectedAt: number;
|
|
358
|
+
schemaFile?: string;
|
|
359
|
+
}
|
|
348
360
|
/**
|
|
349
361
|
* Dashboard stats derived from schema.
|
|
350
362
|
*/
|
|
@@ -371,6 +383,7 @@ interface AppSummary {
|
|
|
371
383
|
};
|
|
372
384
|
domainContext?: unknown;
|
|
373
385
|
hasValidationErrors: boolean;
|
|
386
|
+
github?: GitHubLink;
|
|
374
387
|
}
|
|
375
388
|
/**
|
|
376
389
|
* Options for saving a schema.
|
|
@@ -420,6 +433,128 @@ interface ValidationDocument {
|
|
|
420
433
|
validatedAt: number;
|
|
421
434
|
}
|
|
422
435
|
|
|
436
|
+
/**
|
|
437
|
+
* Service Contract Types
|
|
438
|
+
*
|
|
439
|
+
* Formalizes the two public surfaces of an Almadar service:
|
|
440
|
+
* 1. Call-Service Contract — what the .orb schema can invoke on the TypeScript package
|
|
441
|
+
* 2. Event Contract — what events enter/leave the service
|
|
442
|
+
*
|
|
443
|
+
* Plus internal-but-standardized patterns:
|
|
444
|
+
* 3. StoreContract — database abstraction boundary
|
|
445
|
+
* 4. LazyService — singleton lifecycle pattern
|
|
446
|
+
*
|
|
447
|
+
* @packageDocumentation
|
|
448
|
+
*/
|
|
449
|
+
/**
|
|
450
|
+
* Action definition for a service contract.
|
|
451
|
+
* Each action has typed params and a typed result.
|
|
452
|
+
*/
|
|
453
|
+
interface ServiceAction {
|
|
454
|
+
params: Record<string, unknown>;
|
|
455
|
+
result: unknown;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* What `["call-service", "name", "action", {...}]` actually calls at runtime.
|
|
459
|
+
* Each service defines its action map as a Record<string, ServiceAction>.
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* type LLMActions = {
|
|
464
|
+
* generate: {
|
|
465
|
+
* params: { userPrompt: string; model: string; maxTokens: number };
|
|
466
|
+
* result: { content: string; tokensUsed: number; latencyMs: number };
|
|
467
|
+
* };
|
|
468
|
+
* };
|
|
469
|
+
*
|
|
470
|
+
* class LLMService implements ServiceContract<LLMActions> {
|
|
471
|
+
* async execute(action, params) { ... }
|
|
472
|
+
* }
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
interface ServiceContract<Actions extends Record<string, ServiceAction>> {
|
|
476
|
+
execute<A extends keyof Actions & string>(action: A, params: Actions[A]["params"]): Promise<Actions[A]["result"]>;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Event contract — what events the service emits/listens with typed payloads.
|
|
480
|
+
* Derived from the `.orb` schema's `emits` and `listens` declarations.
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* type LLMEventMap = {
|
|
485
|
+
* AGENT_LLM_REQUEST: { requestId: string; prompt: string };
|
|
486
|
+
* LLM_RESPONSE: { requestId: string; content: string; tokensUsed: number };
|
|
487
|
+
* LLM_ERROR: { requestId: string; error: string };
|
|
488
|
+
* };
|
|
489
|
+
*
|
|
490
|
+
* const events: ServiceEvents<LLMEventMap> = getEventBus();
|
|
491
|
+
* events.emit('LLM_RESPONSE', { requestId: '1', content: '...', tokensUsed: 42 });
|
|
492
|
+
* ```
|
|
493
|
+
*/
|
|
494
|
+
interface ServiceEvents<EventMap extends Record<string, Record<string, unknown>>> {
|
|
495
|
+
emit<E extends keyof EventMap & string>(event: E, payload: EventMap[E]): void;
|
|
496
|
+
on<E extends keyof EventMap & string>(event: E, handler: (payload: EventMap[E]) => void): () => void;
|
|
497
|
+
}
|
|
498
|
+
/** Filter operator for store queries. */
|
|
499
|
+
type StoreFilterOp = "==" | "!=" | "<" | "<=" | ">" | ">=" | "in" | "not-in" | "contains";
|
|
500
|
+
/** A single filter clause for store queries. */
|
|
501
|
+
interface StoreFilter<T> {
|
|
502
|
+
field: keyof T & string;
|
|
503
|
+
op: StoreFilterOp;
|
|
504
|
+
value: unknown;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Database abstraction boundary. Services receive `StoreContract<T>`,
|
|
508
|
+
* not raw database clients. Swappable per database engine.
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```typescript
|
|
512
|
+
* interface LLMRequest { id: string; prompt: string; status: string }
|
|
513
|
+
*
|
|
514
|
+
* class FirestoreLLMRequestStore implements StoreContract<LLMRequest> {
|
|
515
|
+
* async getById(id) { ... }
|
|
516
|
+
* async create(data) { ... }
|
|
517
|
+
* async update(id, data) { ... }
|
|
518
|
+
* async delete(id) { ... }
|
|
519
|
+
* async query(filters) { ... }
|
|
520
|
+
* }
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
|
523
|
+
interface StoreContract<T extends {
|
|
524
|
+
id: string;
|
|
525
|
+
}> {
|
|
526
|
+
getById(id: string): Promise<T | null>;
|
|
527
|
+
create(data: Omit<T, "id">): Promise<T>;
|
|
528
|
+
update(id: string, data: Partial<T>): Promise<T>;
|
|
529
|
+
delete(id: string): Promise<void>;
|
|
530
|
+
query(filters: StoreFilter<T>[]): Promise<T[]>;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Standardized singleton lifecycle. Replaces ad-hoc
|
|
534
|
+
* `let x = null; export function getX()` patterns.
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```typescript
|
|
538
|
+
* const llmClient = createLazyService(() => new LLMClient({ apiKey: process.env.LLM_KEY }));
|
|
539
|
+
*
|
|
540
|
+
* // In request handler:
|
|
541
|
+
* const client = llmClient.get(); // created on first call, cached after
|
|
542
|
+
*
|
|
543
|
+
* // In test teardown:
|
|
544
|
+
* llmClient.reset(); // next get() creates a fresh instance
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
interface LazyService<T> {
|
|
548
|
+
/** Get the singleton instance (creates on first call). */
|
|
549
|
+
get(): T;
|
|
550
|
+
/** Reset the singleton (next get() creates fresh). For test isolation. */
|
|
551
|
+
reset(): void;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Create a lazy singleton from a factory function.
|
|
555
|
+
*/
|
|
556
|
+
declare function createLazyService<T>(factory: () => T): LazyService<T>;
|
|
557
|
+
|
|
423
558
|
/**
|
|
424
559
|
* Shared Intermediate Representation Types
|
|
425
560
|
*
|
|
@@ -688,4 +823,4 @@ declare function createResolvedField(field: {
|
|
|
688
823
|
}): ResolvedField;
|
|
689
824
|
declare function isResolvedIR(ir: unknown): ir is ResolvedIR;
|
|
690
825
|
|
|
691
|
-
export { type AppSummary, BINDING_CONTEXT_RULES, BINDING_DOCS, type BindingContext, BindingSchema, type CategorizedRemovals, type ChangeAuthor, type ChangeSetDocument, type ChangeSummary, type CreateFlow, DEFAULT_INTERACTION_MODELS, type DeleteFlow, type EditFlow, type HistoryMeta, type InteractionModel, type InteractionModelInput, InteractionModelSchema, type ListInteraction, type OperatorName, type PageContentReduction, PatternTypeSchema, type ResolvedEntity, type ResolvedEntityBinding, type ResolvedField, type ResolvedIR, type ResolvedNavigation, type ResolvedPage, type ResolvedPattern, type ResolvedSection, type ResolvedSectionEvent, type ResolvedTrait, type ResolvedTraitBinding, type ResolvedTraitDataEntity, type ResolvedTraitEvent, type ResolvedTraitGuard, type ResolvedTraitListener, type ResolvedTraitState, type ResolvedTraitTick, type ResolvedTraitTransition, type ResolvedTraitUIBinding, SExpr, type SaveOptions, type SaveResult, type SchemaChange, type SnapshotDocument, type StatsView, type TransitionFrom, type ValidationDocument, type ValidationIssue, type ValidationMeta, type ValidationResults, type ViewFlow, createEmptyResolvedPage, createEmptyResolvedTrait, createResolvedField, getAllOperators, getAllPatternTypes, getBindingExamples, getInteractionModelForDomain, inferTsType, isResolvedIR, validateBindingInContext };
|
|
826
|
+
export { type AppSummary, BINDING_CONTEXT_RULES, BINDING_DOCS, type BindingContext, BindingSchema, type CategorizedRemovals, type ChangeAuthor, type ChangeSetDocument, type ChangeSummary, type CreateFlow, DEFAULT_INTERACTION_MODELS, type DeleteFlow, type EditFlow, type GitHubLink, type HistoryMeta, type InteractionModel, type InteractionModelInput, InteractionModelSchema, type LazyService, type ListInteraction, type OperatorName, type PageContentReduction, PatternTypeSchema, type ResolvedEntity, type ResolvedEntityBinding, type ResolvedField, type ResolvedIR, type ResolvedNavigation, type ResolvedPage, type ResolvedPattern, type ResolvedSection, type ResolvedSectionEvent, type ResolvedTrait, type ResolvedTraitBinding, type ResolvedTraitDataEntity, type ResolvedTraitEvent, type ResolvedTraitGuard, type ResolvedTraitListener, type ResolvedTraitState, type ResolvedTraitTick, type ResolvedTraitTransition, type ResolvedTraitUIBinding, SExpr, type SaveOptions, type SaveResult, type SchemaChange, type ServiceAction, type ServiceContract, type ServiceEvents, type SnapshotDocument, type StatsView, type StoreContract, type StoreFilter, type StoreFilterOp, type TransitionFrom, type ValidationDocument, type ValidationIssue, type ValidationMeta, type ValidationResults, type ViewFlow, createEmptyResolvedPage, createEmptyResolvedTrait, createLazyService, createResolvedField, getAllOperators, getAllPatternTypes, getBindingExamples, getInteractionModelForDomain, inferTsType, isResolvedIR, validateBindingInContext };
|
package/dist/types/index.js
CHANGED
|
@@ -1124,6 +1124,22 @@ function getAllPatternTypes() {
|
|
|
1124
1124
|
return [...PATTERN_TYPES];
|
|
1125
1125
|
}
|
|
1126
1126
|
|
|
1127
|
+
// src/service-types.ts
|
|
1128
|
+
function createLazyService(factory) {
|
|
1129
|
+
let instance = null;
|
|
1130
|
+
return {
|
|
1131
|
+
get() {
|
|
1132
|
+
if (instance === null) {
|
|
1133
|
+
instance = factory();
|
|
1134
|
+
}
|
|
1135
|
+
return instance;
|
|
1136
|
+
},
|
|
1137
|
+
reset() {
|
|
1138
|
+
instance = null;
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1127
1143
|
// src/types/ir.ts
|
|
1128
1144
|
function createEmptyResolvedTrait(name, source) {
|
|
1129
1145
|
return {
|
|
@@ -1186,6 +1202,6 @@ function isResolvedIR(ir) {
|
|
|
1186
1202
|
return typeof r.appName === "string" && r.traits instanceof Map && r.pages instanceof Map;
|
|
1187
1203
|
}
|
|
1188
1204
|
|
|
1189
|
-
export { AGENT_DOMAIN_CATEGORIES, ALLOWED_CUSTOM_COMPONENTS, AgentDomainCategorySchema, AnimationDefSchema, AssetMapSchema, AssetMappingSchema, BINDING_CONTEXT_RULES, BINDING_DOCS, BindingSchema, CORE_BINDINGS, ComputedEventContractSchema, ComputedEventListenerSchema, CustomPatternDefinitionSchema, CustomPatternMapSchema, DEFAULT_INTERACTION_MODELS, DesignPreferencesSchema, DesignTokensSchema, DomainCategorySchema, DomainContextSchema, DomainVocabularySchema, ENTITY_ROLES, EffectSchema, EntityFieldSchema, EntityPersistenceSchema, EntityRefSchema, EntityRefStringSchema, EntityRoleSchema, EntitySchema, EntitySemanticRoleSchema, EventListenerSchema, EventPayloadFieldSchema, EventSchema, EventScopeSchema, EventSemanticRoleSchema, EventSourceSchema, ExpressionSchema, FieldFormatSchema, FieldSchema, FieldTypeSchema, GAME_TYPES, GameSubCategorySchema, GameTypeSchema, GuardSchema, InteractionModelSchema, McpServiceDefSchema, NodeClassificationSchema, OrbitalConfigSchema, OrbitalDefinitionSchema, OrbitalEntitySchema, OrbitalPageSchema, OrbitalPageStrictSchema, OrbitalSchemaSchema, OrbitalTraitRefSchema, OrbitalUnitSchema, OrbitalSchema as OrbitalZodSchema, PageRefObjectSchema, PageRefSchema, PageRefStringSchema, PageSchema, PageTraitRefSchema, PatternTypeSchema, PayloadFieldSchema, RelatedLinkSchema, RelationConfigSchema, RequiredFieldSchema, ResolvedAssetSchema, RestAuthConfigSchema, RestServiceDefSchema, SERVICE_TYPES, SExprAtomSchema, SExprSchema, SemanticAssetRefSchema, ServiceDefinitionSchema, ServiceRefSchema, ServiceRefStringSchema, ServiceTypeSchema, SocketEventsSchema, SocketServiceDefSchema, StateMachineSchema, StateSchema, StateSemanticRoleSchema, SuggestedGuardSchema, ThemeDefinitionSchema, ThemeRefSchema, ThemeRefStringSchema, ThemeTokensSchema, ThemeVariantSchema, TraitCategorySchema, TraitDataEntitySchema, TraitEntityFieldSchema, TraitEventContractSchema, TraitEventListenerSchema, TraitRefSchema, TraitReferenceSchema, TraitSchema, TraitTickSchema, TransitionSchema, UISlotSchema, UI_SLOTS, UXHintsSchema, UseDeclarationSchema, UserPersonaSchema, VISUAL_STYLES, ViewTypeSchema, VisualStyleSchema, callService, collectBindings, createAssetKey, createEmptyResolvedPage, createEmptyResolvedTrait, createResolvedField, deriveCollection, despawn, doEffects, emit, findService, getAllOperators, getAllPatternTypes, getArgs, getBindingExamples, getDefaultAnimationsForRole, getInteractionModelForDomain, getOperator, getServiceNames, getTraitConfig, getTraitName, hasService, inferTsType, isBinding, isCircuitEvent, isEffect, isEntityReference, isImportedTraitRef, isInlineTrait, isMcpService, isOrbitalDefinition, isPageReference, isPageReferenceObject, isPageReferenceString, isResolvedIR, isRestService, isRuntimeEntity, isSExpr, isSExprAtom, isSExprCall, isSExprEffect, isServiceReference, isSingletonEntity, isSocketService, isThemeReference, isValidBinding, navigate, normalizeTraitRef, notify, parseAssetKey, parseBinding, parseEntityRef, parseImportedTraitRef, parseOrbitalSchema, parsePageRef, parseServiceRef, persist, renderUI, safeParseOrbitalSchema, set, sexpr, spawn, validateAssetAnimations, validateBindingInContext, walkSExpr };
|
|
1205
|
+
export { AGENT_DOMAIN_CATEGORIES, ALLOWED_CUSTOM_COMPONENTS, AgentDomainCategorySchema, AnimationDefSchema, AssetMapSchema, AssetMappingSchema, BINDING_CONTEXT_RULES, BINDING_DOCS, BindingSchema, CORE_BINDINGS, ComputedEventContractSchema, ComputedEventListenerSchema, CustomPatternDefinitionSchema, CustomPatternMapSchema, DEFAULT_INTERACTION_MODELS, DesignPreferencesSchema, DesignTokensSchema, DomainCategorySchema, DomainContextSchema, DomainVocabularySchema, ENTITY_ROLES, EffectSchema, EntityFieldSchema, EntityPersistenceSchema, EntityRefSchema, EntityRefStringSchema, EntityRoleSchema, EntitySchema, EntitySemanticRoleSchema, EventListenerSchema, EventPayloadFieldSchema, EventSchema, EventScopeSchema, EventSemanticRoleSchema, EventSourceSchema, ExpressionSchema, FieldFormatSchema, FieldSchema, FieldTypeSchema, GAME_TYPES, GameSubCategorySchema, GameTypeSchema, GuardSchema, InteractionModelSchema, McpServiceDefSchema, NodeClassificationSchema, OrbitalConfigSchema, OrbitalDefinitionSchema, OrbitalEntitySchema, OrbitalPageSchema, OrbitalPageStrictSchema, OrbitalSchemaSchema, OrbitalTraitRefSchema, OrbitalUnitSchema, OrbitalSchema as OrbitalZodSchema, PageRefObjectSchema, PageRefSchema, PageRefStringSchema, PageSchema, PageTraitRefSchema, PatternTypeSchema, PayloadFieldSchema, RelatedLinkSchema, RelationConfigSchema, RequiredFieldSchema, ResolvedAssetSchema, RestAuthConfigSchema, RestServiceDefSchema, SERVICE_TYPES, SExprAtomSchema, SExprSchema, SemanticAssetRefSchema, ServiceDefinitionSchema, ServiceRefSchema, ServiceRefStringSchema, ServiceTypeSchema, SocketEventsSchema, SocketServiceDefSchema, StateMachineSchema, StateSchema, StateSemanticRoleSchema, SuggestedGuardSchema, ThemeDefinitionSchema, ThemeRefSchema, ThemeRefStringSchema, ThemeTokensSchema, ThemeVariantSchema, TraitCategorySchema, TraitDataEntitySchema, TraitEntityFieldSchema, TraitEventContractSchema, TraitEventListenerSchema, TraitRefSchema, TraitReferenceSchema, TraitSchema, TraitTickSchema, TransitionSchema, UISlotSchema, UI_SLOTS, UXHintsSchema, UseDeclarationSchema, UserPersonaSchema, VISUAL_STYLES, ViewTypeSchema, VisualStyleSchema, callService, collectBindings, createAssetKey, createEmptyResolvedPage, createEmptyResolvedTrait, createLazyService, createResolvedField, deriveCollection, despawn, doEffects, emit, findService, getAllOperators, getAllPatternTypes, getArgs, getBindingExamples, getDefaultAnimationsForRole, getInteractionModelForDomain, getOperator, getServiceNames, getTraitConfig, getTraitName, hasService, inferTsType, isBinding, isCircuitEvent, isEffect, isEntityReference, isImportedTraitRef, isInlineTrait, isMcpService, isOrbitalDefinition, isPageReference, isPageReferenceObject, isPageReferenceString, isResolvedIR, isRestService, isRuntimeEntity, isSExpr, isSExprAtom, isSExprCall, isSExprEffect, isServiceReference, isSingletonEntity, isSocketService, isThemeReference, isValidBinding, navigate, normalizeTraitRef, notify, parseAssetKey, parseBinding, parseEntityRef, parseImportedTraitRef, parseOrbitalSchema, parsePageRef, parseServiceRef, persist, renderUI, safeParseOrbitalSchema, set, sexpr, spawn, validateAssetAnimations, validateBindingInContext, walkSExpr };
|
|
1190
1206
|
//# sourceMappingURL=index.js.map
|
|
1191
1207
|
//# sourceMappingURL=index.js.map
|