@epochtm/sdk 0.1.4

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/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # `@epochtm/sdk`
2
+
3
+ Epoch TypeScript SDK for institution runtime continuity in agentic products.
4
+
5
+ Use the SDK to turn model turns into structured memory contracts and inject continuity context before execution.
6
+
7
+ ## Why teams use it
8
+
9
+ - Build an institution runtime for agents, not a chat-memory patch
10
+ - Persist structured memory contracts after each turn
11
+ - Inject context before model runs with inspectable behavior
12
+ - Keep continuity portable across SDK, MCP, and HTTP flows
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm i @epochtm/sdk
18
+ ```
19
+
20
+ ## Quickstart
21
+
22
+ ```ts
23
+ import { createEpochClient } from "@epochtm/sdk";
24
+
25
+ const epoch = createEpochClient({
26
+ apiKey: process.env.EPOCH_API_KEY!,
27
+ baseUrl: "https://api.memoryostm.dev",
28
+ });
29
+
30
+ const pre = await memory.beforeModel({
31
+ userId: "u_123",
32
+ question: "What should I build next?",
33
+ project: "memoryos",
34
+ });
35
+
36
+ await memory.afterModel({
37
+ userId: "u_123",
38
+ threadId: "thread-1",
39
+ contract: {
40
+ goal: "Ship MCP contract support",
41
+ decisions: ["Use contract-only ingest path in afterModel"],
42
+ next_actions: ["Add MCP + SDK contract tests"],
43
+ },
44
+ enforceContract: true,
45
+ });
46
+ ```
47
+
48
+ ## APIs
49
+
50
+ - `beforeModel(input)` for retrieval/resume context injection
51
+ - `afterModel(input)` for message or contract ingest
52
+ - `resume(input)` for project continuity summaries
53
+ - `handoff(input)` for human/agent handoff packages
54
+
55
+ ## Notes
56
+
57
+ - `afterModel` requires a non-empty `message` or a `contract`
58
+ - `afterModel` returns `contractFieldCount` when contract fields are present
59
+ - `afterModel` returns backend `traceId` for per-run tracing
60
+ - `afterModel` returns `governanceApplied` with effective mode, TTL, redaction, and pinning
@@ -0,0 +1,90 @@
1
+ import { AfterModelInput, AfterModelResult, BeforeModelInput, BeforeModelResult, HandoffInput, HandoffResult, MemoryIgnitionBriefInput, MemoryIgnitionActionInput, MemoryIgnitionActionResult, MemoryIgnitionHandoffInput, MemoryIgnitionOutcomeInput, MemoryIgnitionRiskCheckInput, MemoryIgnitionRiskCheckResult, MemoryIgnitionSendNowInput, MemoryIgnitionSendNowResult, MemoryIgnitionStandardInheritancePackage, MemoryExperienceFailurePatternsResult, MemoryExperienceLessonsResult, MemoryExperienceQueryInput, MemoryExperienceRootCausesResult, MemoryExperienceRecommendationResult, MemoryExperienceSimilarityResult, MemoryExperienceSearchResult, MemoryTraceProofResult, EpochConfig, ResumeInput, ResumeResult } from "./types";
2
+ export declare class EpochClient {
3
+ private apiKey;
4
+ private baseUrl;
5
+ constructor(config: EpochConfig);
6
+ private request;
7
+ /**
8
+ * Create the standard MemoryIgnition inheritance package before an agent acts.
9
+ */
10
+ createBrief(input: MemoryIgnitionBriefInput): Promise<BeforeModelResult>;
11
+ /**
12
+ * Return only the canonical Standard Inheritance Package that API, SDK, and MCP agents should consume.
13
+ */
14
+ createInheritancePackage(input: MemoryIgnitionBriefInput): Promise<MemoryIgnitionStandardInheritancePackage>;
15
+ /**
16
+ * Format and record a Send Now event for a target agent or runtime.
17
+ */
18
+ sendNow(input: MemoryIgnitionSendNowInput): Promise<MemoryIgnitionSendNowResult>;
19
+ /**
20
+ * Prepare and guard one proposed action before the agent uses a tool or edits files.
21
+ */
22
+ beforeAction(input: MemoryIgnitionActionInput): Promise<MemoryIgnitionActionResult>;
23
+ /**
24
+ * Re-check risk while an agent is acting, using current files/action/tool context.
25
+ */
26
+ duringAction(input: MemoryIgnitionActionInput): Promise<MemoryIgnitionActionResult>;
27
+ /**
28
+ * Check risk, approvals, required tests, and trace proof before tool use.
29
+ */
30
+ riskCheck(input: MemoryIgnitionRiskCheckInput): Promise<MemoryIgnitionRiskCheckResult>;
31
+ /**
32
+ * Save an agent outcome so future agents inherit what worked and failed.
33
+ */
34
+ saveOutcome(input: MemoryIgnitionOutcomeInput): Promise<AfterModelResult>;
35
+ /**
36
+ * Create a MemoryIgnition handoff package for another future agent.
37
+ */
38
+ createHandoff(input: MemoryIgnitionHandoffInput): Promise<HandoffResult>;
39
+ /**
40
+ * Inspect why a memory can be inherited.
41
+ */
42
+ getTraceProof(memoryId: string): Promise<MemoryTraceProofResult>;
43
+ private buildExperienceQueryPath;
44
+ /**
45
+ * Search verified Mission Control experiences.
46
+ */
47
+ searchExperiences(input?: MemoryExperienceQueryInput): Promise<MemoryExperienceSearchResult>;
48
+ /**
49
+ * List reusable lessons extracted from verified PR missions.
50
+ */
51
+ listExperienceLessons(input?: MemoryExperienceQueryInput): Promise<MemoryExperienceLessonsResult>;
52
+ /**
53
+ * List recurring failure patterns extracted from verified PR missions.
54
+ */
55
+ listFailurePatterns(input?: MemoryExperienceQueryInput): Promise<MemoryExperienceFailurePatternsResult>;
56
+ /**
57
+ * List root causes extracted from verified PR missions.
58
+ */
59
+ listRootCauses(input?: MemoryExperienceQueryInput): Promise<MemoryExperienceRootCausesResult>;
60
+ /**
61
+ * Find similar verified experiences to a specific mission or query.
62
+ */
63
+ findSimilarExperiences(input?: MemoryExperienceQueryInput & {
64
+ experienceId?: string;
65
+ repository?: string;
66
+ }): Promise<MemoryExperienceSimilarityResult>;
67
+ /**
68
+ * Build experience-backed recommendations for the next verification or fix.
69
+ */
70
+ getExperienceRecommendations(input?: MemoryExperienceQueryInput & {
71
+ repository?: string;
72
+ }): Promise<MemoryExperienceRecommendationResult>;
73
+ /**
74
+ * Creates the standard MemoryIgnition inheritance package before calling an agent.
75
+ */
76
+ beforeModel(input: BeforeModelInput): Promise<BeforeModelResult>;
77
+ /**
78
+ * Processes messages after the LLM response to extract and save memories.
79
+ */
80
+ afterModel(input: AfterModelInput): Promise<AfterModelResult>;
81
+ /**
82
+ * Specific endpoint for resuming a project thread.
83
+ */
84
+ resume(input: ResumeInput): Promise<ResumeResult>;
85
+ /**
86
+ * Specific endpoint for generating a handoff.
87
+ */
88
+ handoff(input: HandoffInput): Promise<HandoffResult>;
89
+ }
90
+ export declare function createEpochClient(config: EpochConfig): EpochClient;
package/dist/index.js ADDED
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EpochClient = void 0;
4
+ exports.createEpochClient = createEpochClient;
5
+ class EpochClient {
6
+ constructor(config) {
7
+ this.apiKey = config.apiKey;
8
+ this.baseUrl = (config.baseUrl ?? "http://localhost:3011").replace(/\/$/, "");
9
+ }
10
+ async request(path, options = {}) {
11
+ const url = `${this.baseUrl}${path}`;
12
+ const headers = {
13
+ "Content-Type": "application/json",
14
+ Authorization: `Bearer ${this.apiKey}`,
15
+ ...options.headers,
16
+ };
17
+ const response = await fetch(url, {
18
+ ...options,
19
+ headers,
20
+ });
21
+ if (!response.ok) {
22
+ const error = await response.json().catch(() => ({ message: "Unknown error" }));
23
+ throw new Error(`MemoryOS API Error: ${error.message || response.statusText}`);
24
+ }
25
+ const result = await response.json();
26
+ return result.data ?? result;
27
+ }
28
+ /**
29
+ * Create the standard MemoryIgnition inheritance package before an agent acts.
30
+ */
31
+ async createBrief(input) {
32
+ return this.request("/api/memory/memoryignition/brief", {
33
+ method: "POST",
34
+ body: JSON.stringify(input),
35
+ });
36
+ }
37
+ /**
38
+ * Return only the canonical Standard Inheritance Package that API, SDK, and MCP agents should consume.
39
+ */
40
+ async createInheritancePackage(input) {
41
+ const brief = await this.createBrief(input);
42
+ return brief.standard_inheritance_package;
43
+ }
44
+ /**
45
+ * Format and record a Send Now event for a target agent or runtime.
46
+ */
47
+ async sendNow(input) {
48
+ return this.request("/api/memory/memoryignition/send-now", {
49
+ method: "POST",
50
+ body: JSON.stringify(input),
51
+ });
52
+ }
53
+ /**
54
+ * Prepare and guard one proposed action before the agent uses a tool or edits files.
55
+ */
56
+ async beforeAction(input) {
57
+ return this.request("/api/memory/memoryignition/before-action", {
58
+ method: "POST",
59
+ body: JSON.stringify(input),
60
+ });
61
+ }
62
+ /**
63
+ * Re-check risk while an agent is acting, using current files/action/tool context.
64
+ */
65
+ async duringAction(input) {
66
+ return this.request("/api/memory/memoryignition/during-action", {
67
+ method: "POST",
68
+ body: JSON.stringify(input),
69
+ });
70
+ }
71
+ /**
72
+ * Check risk, approvals, required tests, and trace proof before tool use.
73
+ */
74
+ async riskCheck(input) {
75
+ return this.request("/api/memory/memoryignition/risk-check", {
76
+ method: "POST",
77
+ body: JSON.stringify(input),
78
+ });
79
+ }
80
+ /**
81
+ * Save an agent outcome so future agents inherit what worked and failed.
82
+ */
83
+ async saveOutcome(input) {
84
+ return this.request("/api/memory/memoryignition/outcome", {
85
+ method: "POST",
86
+ body: JSON.stringify(input),
87
+ });
88
+ }
89
+ /**
90
+ * Create a MemoryIgnition handoff package for another future agent.
91
+ */
92
+ async createHandoff(input) {
93
+ return this.request("/api/memory/memoryignition/handoff", {
94
+ method: "POST",
95
+ body: JSON.stringify(input),
96
+ });
97
+ }
98
+ /**
99
+ * Inspect why a memory can be inherited.
100
+ */
101
+ async getTraceProof(memoryId) {
102
+ return this.request(`/api/memory/memory/${encodeURIComponent(memoryId)}/trace-proof`);
103
+ }
104
+ buildExperienceQueryPath(path, input = {}) {
105
+ const params = new URLSearchParams();
106
+ if (typeof input.query === "string" && input.query.trim().length > 0) {
107
+ params.set("query", input.query.trim());
108
+ }
109
+ if (typeof input.limit === "number" && Number.isFinite(input.limit)) {
110
+ params.set("limit", String(input.limit));
111
+ }
112
+ if (input.verdict) {
113
+ params.set("verdict", input.verdict);
114
+ }
115
+ const queryString = params.toString();
116
+ return queryString.length > 0 ? `${path}?${queryString}` : path;
117
+ }
118
+ /**
119
+ * Search verified Mission Control experiences.
120
+ */
121
+ async searchExperiences(input = {}) {
122
+ return this.request(this.buildExperienceQueryPath("/api/experience/search", input));
123
+ }
124
+ /**
125
+ * List reusable lessons extracted from verified PR missions.
126
+ */
127
+ async listExperienceLessons(input = {}) {
128
+ return this.request(this.buildExperienceQueryPath("/api/experience/lessons", input));
129
+ }
130
+ /**
131
+ * List recurring failure patterns extracted from verified PR missions.
132
+ */
133
+ async listFailurePatterns(input = {}) {
134
+ return this.request(this.buildExperienceQueryPath("/api/experience/failure-patterns", input));
135
+ }
136
+ /**
137
+ * List root causes extracted from verified PR missions.
138
+ */
139
+ async listRootCauses(input = {}) {
140
+ return this.request(this.buildExperienceQueryPath("/api/experience/root-causes", input));
141
+ }
142
+ /**
143
+ * Find similar verified experiences to a specific mission or query.
144
+ */
145
+ async findSimilarExperiences(input = {}) {
146
+ const path = this.buildExperienceQueryPath("/api/experience/similar", input);
147
+ const params = new URLSearchParams(path.includes("?") ? path.split("?")[1] : "");
148
+ if (typeof input.experienceId === "string" && input.experienceId.trim().length > 0) {
149
+ params.set("experienceId", input.experienceId.trim());
150
+ }
151
+ if (typeof input.repository === "string" && input.repository.trim().length > 0) {
152
+ params.set("repository", input.repository.trim());
153
+ }
154
+ const query = params.toString();
155
+ return this.request(query.length > 0 ? `/api/experience/similar?${query}` : "/api/experience/similar");
156
+ }
157
+ /**
158
+ * Build experience-backed recommendations for the next verification or fix.
159
+ */
160
+ async getExperienceRecommendations(input = {}) {
161
+ const path = this.buildExperienceQueryPath("/api/experience/recommendations", input);
162
+ const params = new URLSearchParams(path.includes("?") ? path.split("?")[1] : "");
163
+ if (typeof input.repository === "string" && input.repository.trim().length > 0) {
164
+ params.set("repository", input.repository.trim());
165
+ }
166
+ const query = params.toString();
167
+ return this.request(query.length > 0 ? `/api/experience/recommendations?${query}` : "/api/experience/recommendations");
168
+ }
169
+ /**
170
+ * Creates the standard MemoryIgnition inheritance package before calling an agent.
171
+ */
172
+ async beforeModel(input) {
173
+ return this.createBrief(input);
174
+ }
175
+ /**
176
+ * Processes messages after the LLM response to extract and save memories.
177
+ */
178
+ async afterModel(input) {
179
+ const hasMessage = typeof input.message === "string" && input.message.trim().length > 0;
180
+ const hasContract = Boolean(input.contract);
181
+ const hasOutcome = Boolean(input.outcome?.trim() || input.modelResponse?.trim());
182
+ if (!hasMessage && !hasContract && !hasOutcome) {
183
+ throw new Error("afterModel requires a non-empty message, outcome, model response, or memory contract.");
184
+ }
185
+ return this.saveOutcome(input);
186
+ }
187
+ /**
188
+ * Specific endpoint for resuming a project thread.
189
+ */
190
+ async resume(input) {
191
+ return this.request("/api/v1/memory/resume", {
192
+ method: "POST",
193
+ body: JSON.stringify(input),
194
+ });
195
+ }
196
+ /**
197
+ * Specific endpoint for generating a handoff.
198
+ */
199
+ async handoff(input) {
200
+ return this.request("/api/v1/memory/handoff", {
201
+ method: "POST",
202
+ body: JSON.stringify(input),
203
+ });
204
+ }
205
+ }
206
+ exports.EpochClient = EpochClient;
207
+ function createEpochClient(config) {
208
+ return new EpochClient(config);
209
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EpochClient = void 0;
4
+ exports.createEpochClient = createEpochClient;
5
+ class EpochClient {
6
+ constructor(config) {
7
+ this.apiKey = config.apiKey;
8
+ this.baseUrl = (config.baseUrl ?? "http://localhost:3011").replace(/\/$/, "");
9
+ }
10
+ async request(path, options = {}) {
11
+ const url = `${this.baseUrl}${path}`;
12
+ const headers = {
13
+ "Content-Type": "application/json",
14
+ Authorization: `Bearer ${this.apiKey}`,
15
+ ...options.headers,
16
+ };
17
+ const response = await fetch(url, {
18
+ ...options,
19
+ headers,
20
+ });
21
+ if (!response.ok) {
22
+ const error = await response.json().catch(() => ({ message: "Unknown error" }));
23
+ throw new Error(`MemoryOS API Error: ${error.message || response.statusText}`);
24
+ }
25
+ const result = await response.json();
26
+ return result.data ?? result;
27
+ }
28
+ /**
29
+ * Create the standard MemoryIgnition inheritance package before an agent acts.
30
+ */
31
+ async createBrief(input) {
32
+ return this.request("/api/memory/memoryignition/brief", {
33
+ method: "POST",
34
+ body: JSON.stringify(input),
35
+ });
36
+ }
37
+ /**
38
+ * Return only the canonical Standard Inheritance Package that API, SDK, and MCP agents should consume.
39
+ */
40
+ async createInheritancePackage(input) {
41
+ const brief = await this.createBrief(input);
42
+ return brief.standard_inheritance_package;
43
+ }
44
+ /**
45
+ * Format and record a Send Now event for a target agent or runtime.
46
+ */
47
+ async sendNow(input) {
48
+ return this.request("/api/memory/memoryignition/send-now", {
49
+ method: "POST",
50
+ body: JSON.stringify(input),
51
+ });
52
+ }
53
+ /**
54
+ * Prepare and guard one proposed action before the agent uses a tool or edits files.
55
+ */
56
+ async beforeAction(input) {
57
+ return this.request("/api/memory/memoryignition/before-action", {
58
+ method: "POST",
59
+ body: JSON.stringify(input),
60
+ });
61
+ }
62
+ /**
63
+ * Re-check risk while an agent is acting, using current files/action/tool context.
64
+ */
65
+ async duringAction(input) {
66
+ return this.request("/api/memory/memoryignition/during-action", {
67
+ method: "POST",
68
+ body: JSON.stringify(input),
69
+ });
70
+ }
71
+ /**
72
+ * Check risk, approvals, required tests, and trace proof before tool use.
73
+ */
74
+ async riskCheck(input) {
75
+ return this.request("/api/memory/memoryignition/risk-check", {
76
+ method: "POST",
77
+ body: JSON.stringify(input),
78
+ });
79
+ }
80
+ /**
81
+ * Save an agent outcome so future agents inherit what worked and failed.
82
+ */
83
+ async saveOutcome(input) {
84
+ return this.request("/api/memory/memoryignition/outcome", {
85
+ method: "POST",
86
+ body: JSON.stringify(input),
87
+ });
88
+ }
89
+ /**
90
+ * Create a MemoryIgnition handoff package for another future agent.
91
+ */
92
+ async createHandoff(input) {
93
+ return this.request("/api/memory/memoryignition/handoff", {
94
+ method: "POST",
95
+ body: JSON.stringify(input),
96
+ });
97
+ }
98
+ /**
99
+ * Inspect why a memory can be inherited.
100
+ */
101
+ async getTraceProof(memoryId) {
102
+ return this.request(`/api/memory/memory/${encodeURIComponent(memoryId)}/trace-proof`);
103
+ }
104
+ buildExperienceQueryPath(path, input = {}) {
105
+ const params = new URLSearchParams();
106
+ if (typeof input.query === "string" && input.query.trim().length > 0) {
107
+ params.set("query", input.query.trim());
108
+ }
109
+ if (typeof input.limit === "number" && Number.isFinite(input.limit)) {
110
+ params.set("limit", String(input.limit));
111
+ }
112
+ if (input.verdict) {
113
+ params.set("verdict", input.verdict);
114
+ }
115
+ const queryString = params.toString();
116
+ return queryString.length > 0 ? `${path}?${queryString}` : path;
117
+ }
118
+ /**
119
+ * Search verified Mission Control experiences.
120
+ */
121
+ async searchExperiences(input = {}) {
122
+ return this.request(this.buildExperienceQueryPath("/api/experience/search", input));
123
+ }
124
+ /**
125
+ * List reusable lessons extracted from verified PR missions.
126
+ */
127
+ async listExperienceLessons(input = {}) {
128
+ return this.request(this.buildExperienceQueryPath("/api/experience/lessons", input));
129
+ }
130
+ /**
131
+ * List recurring failure patterns extracted from verified PR missions.
132
+ */
133
+ async listFailurePatterns(input = {}) {
134
+ return this.request(this.buildExperienceQueryPath("/api/experience/failure-patterns", input));
135
+ }
136
+ /**
137
+ * List root causes extracted from verified PR missions.
138
+ */
139
+ async listRootCauses(input = {}) {
140
+ return this.request(this.buildExperienceQueryPath("/api/experience/root-causes", input));
141
+ }
142
+ /**
143
+ * Find similar verified experiences to a specific mission or query.
144
+ */
145
+ async findSimilarExperiences(input = {}) {
146
+ const path = this.buildExperienceQueryPath("/api/experience/similar", input);
147
+ const params = new URLSearchParams(path.includes("?") ? path.split("?")[1] : "");
148
+ if (typeof input.experienceId === "string" && input.experienceId.trim().length > 0) {
149
+ params.set("experienceId", input.experienceId.trim());
150
+ }
151
+ if (typeof input.repository === "string" && input.repository.trim().length > 0) {
152
+ params.set("repository", input.repository.trim());
153
+ }
154
+ const query = params.toString();
155
+ return this.request(query.length > 0 ? `/api/experience/similar?${query}` : "/api/experience/similar");
156
+ }
157
+ /**
158
+ * Build experience-backed recommendations for the next verification or fix.
159
+ */
160
+ async getExperienceRecommendations(input = {}) {
161
+ const path = this.buildExperienceQueryPath("/api/experience/recommendations", input);
162
+ const params = new URLSearchParams(path.includes("?") ? path.split("?")[1] : "");
163
+ if (typeof input.repository === "string" && input.repository.trim().length > 0) {
164
+ params.set("repository", input.repository.trim());
165
+ }
166
+ const query = params.toString();
167
+ return this.request(query.length > 0 ? `/api/experience/recommendations?${query}` : "/api/experience/recommendations");
168
+ }
169
+ /**
170
+ * Creates the standard MemoryIgnition inheritance package before calling an agent.
171
+ */
172
+ async beforeModel(input) {
173
+ return this.createBrief(input);
174
+ }
175
+ /**
176
+ * Processes messages after the LLM response to extract and save memories.
177
+ */
178
+ async afterModel(input) {
179
+ const hasMessage = typeof input.message === "string" && input.message.trim().length > 0;
180
+ const hasContract = Boolean(input.contract);
181
+ const hasOutcome = Boolean(input.outcome?.trim() || input.modelResponse?.trim());
182
+ if (!hasMessage && !hasContract && !hasOutcome) {
183
+ throw new Error("afterModel requires a non-empty message, outcome, model response, or memory contract.");
184
+ }
185
+ return this.saveOutcome(input);
186
+ }
187
+ /**
188
+ * Specific endpoint for resuming a project thread.
189
+ */
190
+ async resume(input) {
191
+ return this.request("/api/v1/memory/resume", {
192
+ method: "POST",
193
+ body: JSON.stringify(input),
194
+ });
195
+ }
196
+ /**
197
+ * Specific endpoint for generating a handoff.
198
+ */
199
+ async handoff(input) {
200
+ return this.request("/api/v1/memory/handoff", {
201
+ method: "POST",
202
+ body: JSON.stringify(input),
203
+ });
204
+ }
205
+ }
206
+ exports.EpochClient = EpochClient;
207
+ function createEpochClient(config) {
208
+ return new EpochClient(config);
209
+ }