@wappy_ai/core 0.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.
Files changed (43) hide show
  1. package/dist/clock.d.ts +8 -0
  2. package/dist/clock.js +17 -0
  3. package/dist/index.d.ts +12 -0
  4. package/dist/index.js +12 -0
  5. package/dist/interfaces.d.ts +92 -0
  6. package/dist/interfaces.js +1 -0
  7. package/dist/logger.d.ts +7 -0
  8. package/dist/logger.js +6 -0
  9. package/dist/registry.d.ts +26 -0
  10. package/dist/registry.js +40 -0
  11. package/dist/schemas.d.ts +285 -0
  12. package/dist/schemas.js +149 -0
  13. package/dist/semver.d.ts +1 -0
  14. package/dist/semver.js +34 -0
  15. package/dist/setup-manifest.d.ts +20 -0
  16. package/dist/setup-manifest.js +19 -0
  17. package/dist/state/drift.d.ts +9 -0
  18. package/dist/state/drift.js +13 -0
  19. package/dist/state/errors.d.ts +14 -0
  20. package/dist/state/errors.js +26 -0
  21. package/dist/state/index.d.ts +11 -0
  22. package/dist/state/index.js +11 -0
  23. package/dist/state/io.d.ts +11 -0
  24. package/dist/state/io.js +54 -0
  25. package/dist/state/load.d.ts +23 -0
  26. package/dist/state/load.js +23 -0
  27. package/dist/state/lock.d.ts +19 -0
  28. package/dist/state/lock.js +85 -0
  29. package/dist/state/manifest.d.ts +18 -0
  30. package/dist/state/manifest.js +25 -0
  31. package/dist/state/migrations.d.ts +11 -0
  32. package/dist/state/migrations.js +28 -0
  33. package/dist/state/reset.d.ts +15 -0
  34. package/dist/state/reset.js +19 -0
  35. package/dist/state/schema.d.ts +73 -0
  36. package/dist/state/schema.js +56 -0
  37. package/dist/state/step-runner.d.ts +24 -0
  38. package/dist/state/step-runner.js +42 -0
  39. package/dist/state/version-skew.d.ts +9 -0
  40. package/dist/state/version-skew.js +7 -0
  41. package/dist/tracer.d.ts +16 -0
  42. package/dist/tracer.js +13 -0
  43. package/package.json +44 -0
@@ -0,0 +1,24 @@
1
+ import { type Clock } from "../clock.js";
2
+ import { type State } from "./schema.js";
3
+ export interface StepDef {
4
+ id: string;
5
+ part: string;
6
+ run: () => Promise<void> | void;
7
+ }
8
+ export interface StepResult {
9
+ id: string;
10
+ status: "done" | "failed";
11
+ error?: string;
12
+ /** true if the step was already `done` in state and run() was not called again. */
13
+ skipped: boolean;
14
+ }
15
+ /** Idempotent: a step already `done` is skipped, never re-run. Persists status either way. */
16
+ export declare function runStep(state: State, def: StepDef, clock?: Pick<Clock, "now">): Promise<{
17
+ state: State;
18
+ result: StepResult;
19
+ }>;
20
+ /** Runs steps in order, resuming from the first not-yet-done one; stops (without running later steps) on the first failure. */
21
+ export declare function runSteps(state: State, defs: StepDef[], clock?: Pick<Clock, "now">): Promise<{
22
+ state: State;
23
+ results: StepResult[];
24
+ }>;
@@ -0,0 +1,42 @@
1
+ import { systemClock } from "../clock.js";
2
+ import { stepKey } from "./schema.js";
3
+ function upsertStep(steps, next) {
4
+ const key = stepKey(next);
5
+ const i = steps.findIndex((s) => stepKey(s) === key);
6
+ if (i === -1)
7
+ return [...steps, next];
8
+ const copy = [...steps];
9
+ copy[i] = next;
10
+ return copy;
11
+ }
12
+ /** Idempotent: a step already `done` is skipped, never re-run. Persists status either way. */
13
+ export async function runStep(state, def, clock = systemClock) {
14
+ const key = stepKey(def);
15
+ const existing = state.steps.find((s) => stepKey(s) === key);
16
+ if (existing?.status === "done") {
17
+ return { state, result: { id: def.id, status: "done", skipped: true } };
18
+ }
19
+ try {
20
+ await def.run();
21
+ const steps = upsertStep(state.steps, { id: def.id, part: def.part, status: "done" });
22
+ return { state: { ...state, steps, lastStep: def.id, updatedAt: clock.now() }, result: { id: def.id, status: "done", skipped: false } };
23
+ }
24
+ catch (e) {
25
+ const error = e instanceof Error ? e.message : String(e);
26
+ const steps = upsertStep(state.steps, { id: def.id, part: def.part, status: "failed", error });
27
+ return { state: { ...state, steps, lastStep: def.id, updatedAt: clock.now() }, result: { id: def.id, status: "failed", error, skipped: false } };
28
+ }
29
+ }
30
+ /** Runs steps in order, resuming from the first not-yet-done one; stops (without running later steps) on the first failure. */
31
+ export async function runSteps(state, defs, clock = systemClock) {
32
+ let current = state;
33
+ const results = [];
34
+ for (const def of defs) {
35
+ const { state: next, result } = await runStep(current, def, clock);
36
+ current = next;
37
+ results.push(result);
38
+ if (result.status === "failed")
39
+ break;
40
+ }
41
+ return { state: current, results };
42
+ }
@@ -0,0 +1,9 @@
1
+ export interface VersionSkewWarning {
2
+ part: string;
3
+ message: string;
4
+ }
5
+ /** Core/part version skew check (SPEC §10) — pure, returns warnings; the CLI decides how to surface them. */
6
+ export declare function checkVersionSkew(coreVersion: string, parts: {
7
+ name: string;
8
+ coreVersionRange: string;
9
+ }[]): VersionSkewWarning[];
@@ -0,0 +1,7 @@
1
+ import { satisfiesRange } from "../semver.js";
2
+ /** Core/part version skew check (SPEC §10) — pure, returns warnings; the CLI decides how to surface them. */
3
+ export function checkVersionSkew(coreVersion, parts) {
4
+ return parts
5
+ .filter((p) => !satisfiesRange(coreVersion, p.coreVersionRange))
6
+ .map((p) => ({ part: p.name, message: `${p.name} requires core ${p.coreVersionRange}, running ${coreVersion}` }));
7
+ }
@@ -0,0 +1,16 @@
1
+ import { type Clock } from "./clock.js";
2
+ /** Systems a canonical trace (SPEC §9) can touch. */
3
+ export type TracedSystem = "whatsapp" | "memory" | "router" | "skill" | "rag" | "tools" | "llm";
4
+ export interface TraceEvent {
5
+ system: TracedSystem;
6
+ event: string;
7
+ data?: unknown;
8
+ at: number;
9
+ }
10
+ export interface Tracer {
11
+ record(system: TracedSystem, event: string, data?: unknown): void;
12
+ /** Set of systems touched so far — spine tests assert this exactly (B5). */
13
+ touched(): Set<TracedSystem>;
14
+ events(): TraceEvent[];
15
+ }
16
+ export declare function createInMemoryTracer(clock?: Pick<Clock, "now">): Tracer;
package/dist/tracer.js ADDED
@@ -0,0 +1,13 @@
1
+ import { systemClock } from "./clock.js";
2
+ export function createInMemoryTracer(clock = systemClock) {
3
+ const events = [];
4
+ const touched = new Set();
5
+ return {
6
+ record(system, event, data) {
7
+ touched.add(system);
8
+ events.push({ system, event, data, at: clock.now() });
9
+ },
10
+ touched: () => new Set(touched),
11
+ events: () => [...events],
12
+ };
13
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@wappy_ai/core",
3
+ "version": "0.1.0",
4
+ "description": "Shared contracts (Tool, Memory, MessageChannel, SmartMessage) for building a WhatsApp AI agent. The interfaces every Wappy package implements.",
5
+ "keywords": [
6
+ "whatsapp",
7
+ "whatsapp-bot",
8
+ "ai-agent",
9
+ "agent-framework",
10
+ "llm",
11
+ "chatbot",
12
+ "typescript"
13
+ ],
14
+ "homepage": "https://github.com/csr1010/wappy-kit#readme",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/csr1010/wappy-kit.git",
18
+ "directory": "packages/core"
19
+ },
20
+ "bugs": "https://github.com/csr1010/wappy-kit/issues",
21
+ "license": "MIT",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "type": "module",
26
+ "main": "dist/index.js",
27
+ "types": "dist/index.d.ts",
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "scripts": {
32
+ "build": "tsc -p tsconfig.json",
33
+ "typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
34
+ "test": "vitest run --passWithNoTests"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^26.6.2",
38
+ "typescript": "^6.0.3",
39
+ "vitest": "^5.0.1"
40
+ },
41
+ "dependencies": {
42
+ "zod": "^4.6.5"
43
+ }
44
+ }