@orgloop/core 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +51 -17
  2. package/dist/engine.d.ts +12 -26
  3. package/dist/engine.d.ts.map +1 -1
  4. package/dist/engine.js +61 -448
  5. package/dist/engine.js.map +1 -1
  6. package/dist/errors.d.ts +11 -0
  7. package/dist/errors.d.ts.map +1 -1
  8. package/dist/errors.js +22 -0
  9. package/dist/errors.js.map +1 -1
  10. package/dist/http.d.ts +19 -1
  11. package/dist/http.d.ts.map +1 -1
  12. package/dist/http.js +114 -2
  13. package/dist/http.js.map +1 -1
  14. package/dist/index.d.ts +9 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +8 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/logger.d.ts +5 -1
  19. package/dist/logger.d.ts.map +1 -1
  20. package/dist/logger.js +15 -5
  21. package/dist/logger.js.map +1 -1
  22. package/dist/module-instance.d.ts +76 -0
  23. package/dist/module-instance.d.ts.map +1 -0
  24. package/dist/module-instance.js +185 -0
  25. package/dist/module-instance.js.map +1 -0
  26. package/dist/prompt.d.ts +20 -0
  27. package/dist/prompt.d.ts.map +1 -0
  28. package/dist/prompt.js +35 -0
  29. package/dist/prompt.js.map +1 -0
  30. package/dist/registry.d.ts +23 -0
  31. package/dist/registry.d.ts.map +1 -0
  32. package/dist/registry.js +42 -0
  33. package/dist/registry.js.map +1 -0
  34. package/dist/runtime.d.ts +81 -0
  35. package/dist/runtime.d.ts.map +1 -0
  36. package/dist/runtime.js +522 -0
  37. package/dist/runtime.js.map +1 -0
  38. package/dist/scheduler.d.ts +11 -2
  39. package/dist/scheduler.d.ts.map +1 -1
  40. package/dist/scheduler.js +44 -6
  41. package/dist/scheduler.js.map +1 -1
  42. package/dist/transform.d.ts.map +1 -1
  43. package/dist/transform.js +45 -18
  44. package/dist/transform.js.map +1 -1
  45. package/package.json +2 -2
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Prompt file utilities — front matter parsing for launch prompts.
3
+ */
4
+ export interface StripFrontMatterResult {
5
+ /** Prompt content with front matter removed */
6
+ content: string;
7
+ /** Parsed YAML front matter metadata, or null if none found */
8
+ metadata: Record<string, unknown> | null;
9
+ }
10
+ /**
11
+ * Strip YAML front matter from prompt file content.
12
+ *
13
+ * Front matter must start at line 1 with `---`, contain YAML,
14
+ * and end with `---` on its own line. Everything after the closing
15
+ * delimiter is returned as the prompt content.
16
+ *
17
+ * Files without front matter are returned as-is with null metadata.
18
+ */
19
+ export declare function stripFrontMatter(raw: string): StripFrontMatterResult;
20
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,WAAW,sBAAsB;IACtC,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CACzC;AAID;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB,CAqBpE"}
package/dist/prompt.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Prompt file utilities — front matter parsing for launch prompts.
3
+ */
4
+ import yaml from 'js-yaml';
5
+ const FRONT_MATTER_RE = /^---[ \t]*\n([\s\S]*?\n)?---[ \t]*\n?/;
6
+ /**
7
+ * Strip YAML front matter from prompt file content.
8
+ *
9
+ * Front matter must start at line 1 with `---`, contain YAML,
10
+ * and end with `---` on its own line. Everything after the closing
11
+ * delimiter is returned as the prompt content.
12
+ *
13
+ * Files without front matter are returned as-is with null metadata.
14
+ */
15
+ export function stripFrontMatter(raw) {
16
+ const match = FRONT_MATTER_RE.exec(raw);
17
+ if (!match) {
18
+ return { content: raw, metadata: null };
19
+ }
20
+ const frontMatterYaml = (match[1] ?? '').replace(/\n$/, '');
21
+ const content = raw.slice(match[0].length);
22
+ let metadata = null;
23
+ try {
24
+ const parsed = yaml.load(frontMatterYaml);
25
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
26
+ metadata = parsed;
27
+ }
28
+ }
29
+ catch {
30
+ // Invalid YAML in front matter — treat as no metadata
31
+ metadata = null;
32
+ }
33
+ return { content, metadata };
34
+ }
35
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,IAAI,MAAM,SAAS,CAAC;AAS3B,MAAM,eAAe,GAAG,uCAAuC,CAAC;AAEhE;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC3C,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAE3C,IAAI,QAAQ,GAAmC,IAAI,CAAC;IACpD,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC1C,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACpE,QAAQ,GAAG,MAAiC,CAAC;QAC9C,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,sDAAsD;QACtD,QAAQ,GAAG,IAAI,CAAC;IACjB,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * ModuleRegistry — singleton registry for loaded module instances.
3
+ *
4
+ * Tracks all active modules by name. Names are unique — attempting to
5
+ * register a duplicate throws ModuleConflictError.
6
+ */
7
+ import type { ModuleInstance } from './module-instance.js';
8
+ export declare class ModuleRegistry {
9
+ private readonly modules;
10
+ /** Register a module. Throws ModuleConflictError if name already exists. */
11
+ register(module: ModuleInstance): void;
12
+ /** Unregister a module by name. Returns the removed instance or undefined. */
13
+ unregister(name: string): ModuleInstance | undefined;
14
+ /** Get a module by name. */
15
+ get(name: string): ModuleInstance | undefined;
16
+ /** Check if a module name is registered. */
17
+ has(name: string): boolean;
18
+ /** List all registered modules. */
19
+ list(): ModuleInstance[];
20
+ /** Get count of registered modules. */
21
+ get size(): number;
22
+ }
23
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,qBAAa,cAAc;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqC;IAE7D,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI;IAOtC,8EAA8E;IAC9E,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAQpD,4BAA4B;IAC5B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI7C,4CAA4C;IAC5C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,mCAAmC;IACnC,IAAI,IAAI,cAAc,EAAE;IAIxB,uCAAuC;IACvC,IAAI,IAAI,IAAI,MAAM,CAEjB;CACD"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * ModuleRegistry — singleton registry for loaded module instances.
3
+ *
4
+ * Tracks all active modules by name. Names are unique — attempting to
5
+ * register a duplicate throws ModuleConflictError.
6
+ */
7
+ import { ModuleConflictError } from './errors.js';
8
+ export class ModuleRegistry {
9
+ modules = new Map();
10
+ /** Register a module. Throws ModuleConflictError if name already exists. */
11
+ register(module) {
12
+ if (this.modules.has(module.name)) {
13
+ throw new ModuleConflictError(module.name, `Module "${module.name}" is already loaded`);
14
+ }
15
+ this.modules.set(module.name, module);
16
+ }
17
+ /** Unregister a module by name. Returns the removed instance or undefined. */
18
+ unregister(name) {
19
+ const module = this.modules.get(name);
20
+ if (module) {
21
+ this.modules.delete(name);
22
+ }
23
+ return module;
24
+ }
25
+ /** Get a module by name. */
26
+ get(name) {
27
+ return this.modules.get(name);
28
+ }
29
+ /** Check if a module name is registered. */
30
+ has(name) {
31
+ return this.modules.has(name);
32
+ }
33
+ /** List all registered modules. */
34
+ list() {
35
+ return [...this.modules.values()];
36
+ }
37
+ /** Get count of registered modules. */
38
+ get size() {
39
+ return this.modules.size;
40
+ }
41
+ }
42
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,OAAO,cAAc;IACT,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IAE7D,4EAA4E;IAC5E,QAAQ,CAAC,MAAsB;QAC9B,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,mBAAmB,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,MAAM,CAAC,IAAI,qBAAqB,CAAC,CAAC;QACzF,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,8EAA8E;IAC9E,UAAU,CAAC,IAAY;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,MAAM,EAAE,CAAC;YACZ,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED,4BAA4B;IAC5B,GAAG,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,4CAA4C;IAC5C,GAAG,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,mCAAmC;IACnC,IAAI;QACH,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,uCAAuC;IACvC,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC1B,CAAC;CACD"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Runtime — the long-lived host process.
3
+ *
4
+ * Owns shared infrastructure (bus, scheduler, logger, webhook server)
5
+ * and manages modules through a registry. Modules are loaded/unloaded
6
+ * independently without affecting each other.
7
+ */
8
+ import { EventEmitter } from 'node:events';
9
+ import type { ModuleStatus, OrgLoopEvent, RuntimeStatus } from '@orgloop/sdk';
10
+ import type { EventBus } from './bus.js';
11
+ import type { RuntimeControl } from './http.js';
12
+ import { LoggerManager } from './logger.js';
13
+ import type { ModuleConfig } from './module-instance.js';
14
+ import type { CheckpointStore } from './store.js';
15
+ export interface SourceCircuitBreakerOptions {
16
+ /** Consecutive failures before opening circuit (default: 5) */
17
+ failureThreshold?: number;
18
+ /** Backoff period in ms before retry when circuit is open (default: 60000) */
19
+ retryAfterMs?: number;
20
+ }
21
+ export interface RuntimeOptions {
22
+ /** Custom event bus (default: InMemoryBus) */
23
+ bus?: EventBus;
24
+ /** Shared logger manager (default: new LoggerManager) */
25
+ loggerManager?: LoggerManager;
26
+ /** HTTP port for webhook server and control API (default: 4800) */
27
+ httpPort?: number;
28
+ /** Circuit breaker options for source polling */
29
+ circuitBreaker?: SourceCircuitBreakerOptions;
30
+ /** Data directory for checkpoints and WAL */
31
+ dataDir?: string;
32
+ }
33
+ export interface LoadModuleOptions {
34
+ /** Pre-instantiated source connectors (keyed by source ID) */
35
+ sources?: Map<string, import('@orgloop/sdk').SourceConnector>;
36
+ /** Pre-instantiated actor connectors (keyed by actor ID) */
37
+ actors?: Map<string, import('@orgloop/sdk').ActorConnector>;
38
+ /** Pre-instantiated package transforms (keyed by transform name) */
39
+ transforms?: Map<string, import('@orgloop/sdk').Transform>;
40
+ /** Pre-instantiated loggers (keyed by logger name) */
41
+ loggers?: Map<string, import('@orgloop/sdk').Logger>;
42
+ /** Custom checkpoint store for this module */
43
+ checkpointStore?: CheckpointStore;
44
+ }
45
+ declare class Runtime extends EventEmitter implements RuntimeControl {
46
+ private readonly bus;
47
+ private readonly scheduler;
48
+ private readonly loggerManager;
49
+ private readonly registry;
50
+ private readonly webhookServer;
51
+ private running;
52
+ private httpStarted;
53
+ private startedAt;
54
+ private readonly httpPort;
55
+ private readonly dataDir?;
56
+ private readonly circuitBreakerOpts;
57
+ private readonly circuitRetryTimers;
58
+ private readonly moduleConfigs;
59
+ private readonly moduleLoadOptions;
60
+ constructor(options?: RuntimeOptions);
61
+ start(): Promise<void>;
62
+ /** Start the HTTP server for webhooks and control API. */
63
+ startHttpServer(): Promise<void>;
64
+ /** Whether the HTTP server is currently running. */
65
+ isHttpStarted(): boolean;
66
+ stop(): Promise<void>;
67
+ loadModule(config: ModuleConfig, options?: LoadModuleOptions): Promise<ModuleStatus>;
68
+ unloadModule(name: string): Promise<void>;
69
+ reloadModule(name: string): Promise<void>;
70
+ inject(event: OrgLoopEvent, moduleName?: string): Promise<void>;
71
+ private processEvent;
72
+ private deliverToActor;
73
+ private pollSource;
74
+ private scheduleCircuitRetry;
75
+ status(): RuntimeStatus;
76
+ listModules(): ModuleStatus[];
77
+ getModuleStatus(name: string): ModuleStatus | undefined;
78
+ private emitLog;
79
+ }
80
+ export { Runtime };
81
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EAGX,YAAY,EACZ,YAAY,EAEZ,aAAa,EAEb,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,sBAAsB,CAAC;AAMxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAOlD,MAAM,WAAW,2BAA2B;IAC3C,+DAA+D;IAC/D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC9B,8CAA8C;IAC9C,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,yDAAyD;IACzD,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,cAAc,CAAC,EAAE,2BAA2B,CAAC;IAC7C,6CAA6C;IAC7C,OAAO,CAAC,EAAE,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