@dingdawg/sdk 2.0.0 → 2.0.2
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/dist/client.cjs +307 -0
- package/dist/client.js +7 -2
- package/dist/client.js.map +1 -1
- package/dist/durable.cjs +227 -0
- package/dist/durable.js +12 -8
- package/dist/durable.js.map +1 -1
- package/dist/index.cjs +20 -0
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/types.cjs +9 -0
- package/dist/types.js +2 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
- package/src/durable.ts +1 -1
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dingdawg/sdk — DingDawgClient
|
|
4
|
+
*
|
|
5
|
+
* The primary entry point for B2B2C partners embedding DingDawg agents.
|
|
6
|
+
*
|
|
7
|
+
* Design goals:
|
|
8
|
+
* - Zero runtime dependencies (Node 18+ built-in fetch only)
|
|
9
|
+
* - Full TypeScript types on all inputs and outputs
|
|
10
|
+
* - Typed error class so callers can catch + inspect failures
|
|
11
|
+
* - Grouped API namespaces: client.agent.* and client.billing.*
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.DingDawgClient = exports.DingDawgApiError = void 0;
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Default configuration
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
const DEFAULT_BASE_URL = "https://api.dingdawg.com";
|
|
19
|
+
const SDK_USER_AGENT = "@dingdawg/sdk/0.1.0";
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Typed error class
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
/**
|
|
24
|
+
* Thrown by all DingDawgClient methods when the API returns a non-2xx status.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* try {
|
|
29
|
+
* await client.agent.get("non-existent-id");
|
|
30
|
+
* } catch (err) {
|
|
31
|
+
* if (err instanceof DingDawgApiError) {
|
|
32
|
+
* console.error(err.status, err.body?.detail);
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
class DingDawgApiError extends Error {
|
|
38
|
+
/** HTTP status code. */
|
|
39
|
+
status;
|
|
40
|
+
/** Parsed error body from the API, or null if the body was not JSON. */
|
|
41
|
+
body;
|
|
42
|
+
constructor(details, message) {
|
|
43
|
+
const derived = message ??
|
|
44
|
+
details.body?.detail ??
|
|
45
|
+
details.body?.message ??
|
|
46
|
+
`DingDawg API error: HTTP ${details.status}`;
|
|
47
|
+
super(String(derived));
|
|
48
|
+
this.name = "DingDawgApiError";
|
|
49
|
+
this.status = details.status;
|
|
50
|
+
this.body = details.body;
|
|
51
|
+
// Maintains proper prototype chain in transpiled environments
|
|
52
|
+
Object.setPrototypeOf(this, DingDawgApiError.prototype);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.DingDawgApiError = DingDawgApiError;
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// Internal HTTP helpers
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
/**
|
|
60
|
+
* Parse a Response, throwing DingDawgApiError on non-2xx status.
|
|
61
|
+
*
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
async function _parseResponse(resp) {
|
|
65
|
+
let body = null;
|
|
66
|
+
const contentType = resp.headers.get("content-type") ?? "";
|
|
67
|
+
if (contentType.includes("application/json")) {
|
|
68
|
+
try {
|
|
69
|
+
body = await resp.json();
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
body = null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
try {
|
|
77
|
+
body = await resp.text();
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
body = null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!resp.ok) {
|
|
84
|
+
const errorBody = body !== null && typeof body === "object"
|
|
85
|
+
? body
|
|
86
|
+
: typeof body === "string"
|
|
87
|
+
? { detail: body }
|
|
88
|
+
: null;
|
|
89
|
+
throw new DingDawgApiError({ status: resp.status, body: errorBody });
|
|
90
|
+
}
|
|
91
|
+
return body;
|
|
92
|
+
}
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
// Main client class
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
/**
|
|
97
|
+
* DingDawgClient — the single entry point for the DingDawg Agent SDK.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { DingDawgClient } from "@dingdawg/sdk";
|
|
102
|
+
*
|
|
103
|
+
* const client = new DingDawgClient({ apiKey: "dd_live_..." });
|
|
104
|
+
*
|
|
105
|
+
* const agent = await client.agent.create({
|
|
106
|
+
* name: "Support Bot",
|
|
107
|
+
* handle: "acme-support",
|
|
108
|
+
* agentType: "business",
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* const reply = await client.agent.sendMessage(agent.id, "Hello!");
|
|
112
|
+
* console.log(reply.reply);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
class DingDawgClient {
|
|
116
|
+
_apiKey;
|
|
117
|
+
_baseUrl;
|
|
118
|
+
/** Methods for managing agents. */
|
|
119
|
+
agent;
|
|
120
|
+
/** Methods for querying billing and usage. */
|
|
121
|
+
billing;
|
|
122
|
+
/**
|
|
123
|
+
* Create a new DingDawgClient instance.
|
|
124
|
+
*
|
|
125
|
+
* @param opts - Configuration options.
|
|
126
|
+
* @throws {TypeError} When apiKey is missing or empty.
|
|
127
|
+
*/
|
|
128
|
+
constructor(opts) {
|
|
129
|
+
if (!opts.apiKey || typeof opts.apiKey !== "string" || opts.apiKey.trim() === "") {
|
|
130
|
+
throw new TypeError("DingDawgClient: apiKey is required and must be a non-empty string");
|
|
131
|
+
}
|
|
132
|
+
this._apiKey = opts.apiKey.trim();
|
|
133
|
+
this._baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
134
|
+
// Bind namespace objects so methods can be destructured safely
|
|
135
|
+
this.agent = this._buildAgentApi();
|
|
136
|
+
this.billing = this._buildBillingApi();
|
|
137
|
+
}
|
|
138
|
+
// -------------------------------------------------------------------------
|
|
139
|
+
// Internal HTTP request
|
|
140
|
+
// -------------------------------------------------------------------------
|
|
141
|
+
/**
|
|
142
|
+
* Perform an authenticated JSON request.
|
|
143
|
+
*
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
async _request(method, path, body) {
|
|
147
|
+
const url = `${this._baseUrl}${path}`;
|
|
148
|
+
const headers = {
|
|
149
|
+
"Content-Type": "application/json",
|
|
150
|
+
"User-Agent": SDK_USER_AGENT,
|
|
151
|
+
Authorization: `Bearer ${this._apiKey}`,
|
|
152
|
+
"X-DingDawg-SDK": "1",
|
|
153
|
+
};
|
|
154
|
+
const init = { method, headers };
|
|
155
|
+
if (body !== undefined && method !== "GET") {
|
|
156
|
+
init.body = JSON.stringify(body);
|
|
157
|
+
}
|
|
158
|
+
let resp;
|
|
159
|
+
try {
|
|
160
|
+
resp = await fetch(url, init);
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
// Network-level failure (DNS, connection refused, etc.)
|
|
164
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
165
|
+
throw new DingDawgApiError({ status: 0, body: { detail: `Network error: ${message}` } }, `Network error reaching DingDawg API: ${message}`);
|
|
166
|
+
}
|
|
167
|
+
return _parseResponse(resp);
|
|
168
|
+
}
|
|
169
|
+
// -------------------------------------------------------------------------
|
|
170
|
+
// Agent API builder
|
|
171
|
+
// -------------------------------------------------------------------------
|
|
172
|
+
_buildAgentApi() {
|
|
173
|
+
return {
|
|
174
|
+
create: async (opts) => {
|
|
175
|
+
const payload = {
|
|
176
|
+
name: opts.name,
|
|
177
|
+
handle: opts.handle,
|
|
178
|
+
agent_type: opts.agentType ?? "business",
|
|
179
|
+
industry_type: opts.industry,
|
|
180
|
+
system_prompt: opts.systemPrompt,
|
|
181
|
+
template_id: opts.templateId,
|
|
182
|
+
branding: opts.branding
|
|
183
|
+
? {
|
|
184
|
+
primary_color: opts.branding.primaryColor,
|
|
185
|
+
avatar_url: opts.branding.avatarUrl,
|
|
186
|
+
}
|
|
187
|
+
: undefined,
|
|
188
|
+
};
|
|
189
|
+
const raw = await this._request("POST", "/api/v2/partner/agents", payload);
|
|
190
|
+
return _normalizeAgent(raw);
|
|
191
|
+
},
|
|
192
|
+
list: async (params = {}) => {
|
|
193
|
+
const qs = new URLSearchParams();
|
|
194
|
+
if (params.limit !== undefined)
|
|
195
|
+
qs.set("limit", String(params.limit));
|
|
196
|
+
if (params.offset !== undefined)
|
|
197
|
+
qs.set("offset", String(params.offset));
|
|
198
|
+
const queryString = qs.toString();
|
|
199
|
+
const path = queryString
|
|
200
|
+
? `/api/v2/partner/agents?${queryString}`
|
|
201
|
+
: "/api/v2/partner/agents";
|
|
202
|
+
const raw = await this._request("GET", path);
|
|
203
|
+
const items = (raw["items"] ?? raw["agents"] ?? []);
|
|
204
|
+
return {
|
|
205
|
+
items: items.map(_normalizeAgent),
|
|
206
|
+
total: raw["total"] ?? items.length,
|
|
207
|
+
limit: raw["limit"] ?? (params.limit ?? 20),
|
|
208
|
+
offset: raw["offset"] ?? (params.offset ?? 0),
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
get: async (id) => {
|
|
212
|
+
const raw = await this._request("GET", `/api/v2/partner/agents/${encodeURIComponent(id)}`);
|
|
213
|
+
return _normalizeAgent(raw);
|
|
214
|
+
},
|
|
215
|
+
sendMessage: async (agentId, message) => {
|
|
216
|
+
const opts = typeof message === "string" ? { message } : message;
|
|
217
|
+
const payload = {
|
|
218
|
+
message: opts.message,
|
|
219
|
+
user_id: opts.userId,
|
|
220
|
+
session_id: opts.sessionId,
|
|
221
|
+
metadata: opts.metadata,
|
|
222
|
+
};
|
|
223
|
+
const raw = await this._request("POST", `/api/v1/agents/${encodeURIComponent(agentId)}/trigger`, payload);
|
|
224
|
+
const triggerResult = {
|
|
225
|
+
reply: String(raw["reply"] ?? raw["response"] ?? ""),
|
|
226
|
+
sessionId: String(raw["session_id"] ?? raw["sessionId"] ?? ""),
|
|
227
|
+
timestamp: String(raw["timestamp"] ?? new Date().toISOString()),
|
|
228
|
+
queued: raw["queued"] === true,
|
|
229
|
+
...(raw["model"] !== undefined ? { model: String(raw["model"]) } : {}),
|
|
230
|
+
};
|
|
231
|
+
return triggerResult;
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
// -------------------------------------------------------------------------
|
|
236
|
+
// Billing API builder
|
|
237
|
+
// -------------------------------------------------------------------------
|
|
238
|
+
_buildBillingApi() {
|
|
239
|
+
return {
|
|
240
|
+
currentMonth: async () => {
|
|
241
|
+
const raw = await this._request("GET", "/api/v2/partner/billing/current-month");
|
|
242
|
+
return _normalizeMonthlySummary(raw);
|
|
243
|
+
},
|
|
244
|
+
summary: async () => {
|
|
245
|
+
const raw = await this._request("GET", "/api/v2/partner/billing");
|
|
246
|
+
const currentMonth = _normalizeMonthlySummary(raw["current_month"] ?? {});
|
|
247
|
+
const billingSummaryResult = {
|
|
248
|
+
totalActions: raw["total_actions"] ?? 0,
|
|
249
|
+
totalCents: raw["total_cents"] ?? 0,
|
|
250
|
+
currentMonth,
|
|
251
|
+
...(raw["stripe_customer_id"] !== undefined
|
|
252
|
+
? { stripeCustomerId: String(raw["stripe_customer_id"]) }
|
|
253
|
+
: {}),
|
|
254
|
+
};
|
|
255
|
+
return billingSummaryResult;
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
exports.DingDawgClient = DingDawgClient;
|
|
261
|
+
// ---------------------------------------------------------------------------
|
|
262
|
+
// Normalizer helpers (snake_case → camelCase)
|
|
263
|
+
// ---------------------------------------------------------------------------
|
|
264
|
+
function _normalizeAgent(raw) {
|
|
265
|
+
const branding = raw["branding"];
|
|
266
|
+
return {
|
|
267
|
+
id: String(raw["id"] ?? raw["agent_id"] ?? ""),
|
|
268
|
+
handle: String(raw["handle"] ?? ""),
|
|
269
|
+
name: String(raw["name"] ?? ""),
|
|
270
|
+
agentType: (raw["agent_type"] ?? raw["agentType"] ?? "business"),
|
|
271
|
+
industry: raw["industry_type"] !== undefined
|
|
272
|
+
? String(raw["industry_type"])
|
|
273
|
+
: raw["industry"] !== undefined
|
|
274
|
+
? String(raw["industry"])
|
|
275
|
+
: null,
|
|
276
|
+
status: (raw["status"] ?? "active"),
|
|
277
|
+
createdAt: String(raw["created_at"] ?? raw["createdAt"] ?? ""),
|
|
278
|
+
updatedAt: String(raw["updated_at"] ?? raw["updatedAt"] ?? ""),
|
|
279
|
+
...(branding
|
|
280
|
+
? {
|
|
281
|
+
branding: {
|
|
282
|
+
...(branding["primary_color"] !== undefined
|
|
283
|
+
? { primaryColor: String(branding["primary_color"]) }
|
|
284
|
+
: {}),
|
|
285
|
+
...(branding["avatar_url"] !== undefined
|
|
286
|
+
? { avatarUrl: String(branding["avatar_url"]) }
|
|
287
|
+
: {}),
|
|
288
|
+
},
|
|
289
|
+
}
|
|
290
|
+
: {}),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function _normalizeMonthlySummary(raw) {
|
|
294
|
+
const lineItemsRaw = Array.isArray(raw["line_items"]) ? raw["line_items"] : [];
|
|
295
|
+
return {
|
|
296
|
+
month: String(raw["month"] ?? ""),
|
|
297
|
+
totalActions: raw["total_actions"] ?? 0,
|
|
298
|
+
totalCents: raw["total_cents"] ?? 0,
|
|
299
|
+
freeActionsRemaining: raw["free_actions_remaining"] ?? 0,
|
|
300
|
+
lineItems: lineItemsRaw.map((item) => ({
|
|
301
|
+
action: String(item["action"] ?? ""),
|
|
302
|
+
count: item["count"] ?? 0,
|
|
303
|
+
costCents: item["cost_cents"] ?? 0,
|
|
304
|
+
})),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=client.js.map
|
package/dist/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @dingdawg/sdk — DingDawgClient
|
|
3
4
|
*
|
|
@@ -9,6 +10,8 @@
|
|
|
9
10
|
* - Typed error class so callers can catch + inspect failures
|
|
10
11
|
* - Grouped API namespaces: client.agent.* and client.billing.*
|
|
11
12
|
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.DingDawgClient = exports.DingDawgApiError = void 0;
|
|
12
15
|
// ---------------------------------------------------------------------------
|
|
13
16
|
// Default configuration
|
|
14
17
|
// ---------------------------------------------------------------------------
|
|
@@ -31,7 +34,7 @@ const SDK_USER_AGENT = "@dingdawg/sdk/0.1.0";
|
|
|
31
34
|
* }
|
|
32
35
|
* ```
|
|
33
36
|
*/
|
|
34
|
-
|
|
37
|
+
class DingDawgApiError extends Error {
|
|
35
38
|
/** HTTP status code. */
|
|
36
39
|
status;
|
|
37
40
|
/** Parsed error body from the API, or null if the body was not JSON. */
|
|
@@ -49,6 +52,7 @@ export class DingDawgApiError extends Error {
|
|
|
49
52
|
Object.setPrototypeOf(this, DingDawgApiError.prototype);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
55
|
+
exports.DingDawgApiError = DingDawgApiError;
|
|
52
56
|
// ---------------------------------------------------------------------------
|
|
53
57
|
// Internal HTTP helpers
|
|
54
58
|
// ---------------------------------------------------------------------------
|
|
@@ -108,7 +112,7 @@ async function _parseResponse(resp) {
|
|
|
108
112
|
* console.log(reply.reply);
|
|
109
113
|
* ```
|
|
110
114
|
*/
|
|
111
|
-
|
|
115
|
+
class DingDawgClient {
|
|
112
116
|
_apiKey;
|
|
113
117
|
_baseUrl;
|
|
114
118
|
/** Methods for managing agents. */
|
|
@@ -253,6 +257,7 @@ export class DingDawgClient {
|
|
|
253
257
|
};
|
|
254
258
|
}
|
|
255
259
|
}
|
|
260
|
+
exports.DingDawgClient = DingDawgClient;
|
|
256
261
|
// ---------------------------------------------------------------------------
|
|
257
262
|
// Normalizer helpers (snake_case → camelCase)
|
|
258
263
|
// ---------------------------------------------------------------------------
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAeH,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAEpD,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAE7C,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E;;;;;;;;;;;;;GAaG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACzC,wBAAwB;IACf,MAAM,CAAS;IACxB,wEAAwE;IAC/D,IAAI,CAAsB;IAEnC,YAAY,OAAgC,EAAE,OAAgB;QAC5D,MAAM,OAAO,GACX,OAAO;YACP,OAAO,CAAC,IAAI,EAAE,MAAM;YACpB,OAAO,CAAC,IAAI,EAAE,OAAO;YACrB,4BAA4B,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/C,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,8DAA8D;QAC9D,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,S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AO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAE/E,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACjC,YAAY,EAAG,GAAG,CAAC,eAAe,CAAY,IAAI,CAAC;QACnD,UAAU,EAAG,GAAG,CAAC,aAAa,CAAY,IAAI,CAAC;QAC/C,oBAAoB,EAAG,GAAG,CAAC,wBAAwB,CAAY,IAAI,CAAC;QACpE,SAAS,EAAG,YAA0C,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACpE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACpC,KAAK,EAAG,IAAI,CAAC,OAAO,CAAY,IAAI,CAAC;YACrC,SAAS,EAAG,IAAI,CAAC,YAAY,CAAY,IAAI,CAAC;SAC/C,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
|
package/dist/durable.cjs
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dingdawg/sdk/durable — DurableDingDawgClient
|
|
4
|
+
*
|
|
5
|
+
* Extends DingDawgClient with DDAG v1 crash-proof execution:
|
|
6
|
+
* - invokeWithCheckpoint() — run agent step, get back a CID resume token
|
|
7
|
+
* - resume() — continue from a checkpoint CID (any machine)
|
|
8
|
+
* - getSoul() — retrieve an agent's IPFS-pinned identity
|
|
9
|
+
*
|
|
10
|
+
* What competitors don't have (in one SDK):
|
|
11
|
+
* ✅ Log-first WAL execution — crash = replay from log, never lose progress
|
|
12
|
+
* ✅ IPFS content-addressed checkpoints — stateless resume on any machine
|
|
13
|
+
* ✅ Exactly-once semantics — idempotency keys prevent double-execution
|
|
14
|
+
* ✅ Agent Soul persistence — identity survives crashes and migrations
|
|
15
|
+
* ✅ Memory class retention — A/B/C/D with IPFS anchoring for Class A
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.DurableDingDawgClient = exports.AgentFSMState = void 0;
|
|
19
|
+
const client_js_1 = require("./client");
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// FSM state enum — matches the DDAG v1 protocol state machine
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
var AgentFSMState;
|
|
24
|
+
(function (AgentFSMState) {
|
|
25
|
+
AgentFSMState["Idle"] = "idle";
|
|
26
|
+
AgentFSMState["Running"] = "running";
|
|
27
|
+
AgentFSMState["ToolPending"] = "tool_pending";
|
|
28
|
+
AgentFSMState["Verifying"] = "verifying";
|
|
29
|
+
AgentFSMState["Committing"] = "committing";
|
|
30
|
+
AgentFSMState["Remediating"] = "remediating";
|
|
31
|
+
AgentFSMState["Checkpointed"] = "checkpointed";
|
|
32
|
+
AgentFSMState["Resuming"] = "resuming";
|
|
33
|
+
AgentFSMState["Done"] = "done";
|
|
34
|
+
AgentFSMState["Failed"] = "failed";
|
|
35
|
+
})(AgentFSMState || (exports.AgentFSMState = AgentFSMState = {}));
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// SDK version
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
const SDK_USER_AGENT_DURABLE = "@dingdawg/sdk-durable/2.0.0";
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// DurableDingDawgClient
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
/**
|
|
44
|
+
* DurableDingDawgClient — crash-proof agent execution SDK.
|
|
45
|
+
*
|
|
46
|
+
* @example Basic durable invocation
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { DurableDingDawgClient } from "@dingdawg/sdk";
|
|
49
|
+
*
|
|
50
|
+
* const client = new DurableDingDawgClient({ apiKey: "dd_live_..." });
|
|
51
|
+
*
|
|
52
|
+
* const result = await client.invokeWithCheckpoint("acme-support", {
|
|
53
|
+
* message: "Run the quarterly compliance report",
|
|
54
|
+
* userId: "user_123",
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Save checkpoint_cid — if the process crashes, pass it to resume()
|
|
58
|
+
* console.log(result.checkpoint_cid); // "ipfs:Qm..." or "sha256:..."
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example Resume after crash
|
|
62
|
+
* ```ts
|
|
63
|
+
* const resumed = await client.resume("acme-support", savedCheckpointCid);
|
|
64
|
+
* // Agent continues from the exact step it left off — no re-execution
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
class DurableDingDawgClient extends client_js_1.DingDawgClient {
|
|
68
|
+
_durableApiKey;
|
|
69
|
+
_durableBaseUrl;
|
|
70
|
+
constructor(opts) {
|
|
71
|
+
super(opts);
|
|
72
|
+
this._durableApiKey = opts.apiKey.trim();
|
|
73
|
+
this._durableBaseUrl = (opts.baseUrl ?? "https://api.dingdawg.com").replace(/\/$/, "");
|
|
74
|
+
}
|
|
75
|
+
// -------------------------------------------------------------------------
|
|
76
|
+
// Internal HTTP helper (mirrors DingDawgClient._request — kept private)
|
|
77
|
+
// -------------------------------------------------------------------------
|
|
78
|
+
async _durableRequest(method, path, body, extraHeaders) {
|
|
79
|
+
const url = `${this._durableBaseUrl}${path}`;
|
|
80
|
+
const headers = {
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
"User-Agent": SDK_USER_AGENT_DURABLE,
|
|
83
|
+
Authorization: `Bearer ${this._durableApiKey}`,
|
|
84
|
+
"X-DingDawg-SDK": "2",
|
|
85
|
+
...extraHeaders,
|
|
86
|
+
};
|
|
87
|
+
const init = {
|
|
88
|
+
method,
|
|
89
|
+
headers,
|
|
90
|
+
...(body !== undefined && method !== "GET"
|
|
91
|
+
? { body: JSON.stringify(body) }
|
|
92
|
+
: {}),
|
|
93
|
+
};
|
|
94
|
+
let resp;
|
|
95
|
+
try {
|
|
96
|
+
resp = await fetch(url, init);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
100
|
+
throw new client_js_1.DingDawgApiError({ status: 0, body: { detail: `Network error: ${msg}` } }, `Network error reaching DingDawg API: ${msg}`);
|
|
101
|
+
}
|
|
102
|
+
if (!resp.ok) {
|
|
103
|
+
let errBody = null;
|
|
104
|
+
try {
|
|
105
|
+
errBody = (await resp.json());
|
|
106
|
+
}
|
|
107
|
+
catch { /* non-JSON error */ }
|
|
108
|
+
throw new client_js_1.DingDawgApiError({ status: resp.status, body: errBody });
|
|
109
|
+
}
|
|
110
|
+
return (await resp.json());
|
|
111
|
+
}
|
|
112
|
+
// -------------------------------------------------------------------------
|
|
113
|
+
// Public durable API
|
|
114
|
+
// -------------------------------------------------------------------------
|
|
115
|
+
/**
|
|
116
|
+
* Invoke an agent with checkpoint support.
|
|
117
|
+
*
|
|
118
|
+
* The server journalises intent before execution and checkpoints state after.
|
|
119
|
+
* The returned `checkpoint_cid` is the durable resume token — store it.
|
|
120
|
+
* On crash, call `resume(handle, checkpoint_cid)` to continue without re-executing
|
|
121
|
+
* completed steps.
|
|
122
|
+
*
|
|
123
|
+
* @param agentHandle - Agent handle (e.g. "acme-support").
|
|
124
|
+
* @param opts - Message options + optional resume_cid, idempotency_key, checkpoint_every.
|
|
125
|
+
* @returns DurableResponse including checkpoint_cid, step_index, verified, fsm_state.
|
|
126
|
+
*/
|
|
127
|
+
async invokeWithCheckpoint(agentHandle, opts) {
|
|
128
|
+
const payload = {
|
|
129
|
+
message: opts.message,
|
|
130
|
+
user_id: opts.userId,
|
|
131
|
+
session_id: opts.sessionId,
|
|
132
|
+
metadata: opts.metadata,
|
|
133
|
+
checkpoint_every: opts.checkpoint_every ?? 1,
|
|
134
|
+
};
|
|
135
|
+
if (opts.resume_cid !== undefined)
|
|
136
|
+
payload["resume_cid"] = opts.resume_cid;
|
|
137
|
+
if (opts.idempotency_key !== undefined)
|
|
138
|
+
payload["idempotency_key"] = opts.idempotency_key;
|
|
139
|
+
const extraHeaders = {};
|
|
140
|
+
if (opts.idempotency_key !== undefined) {
|
|
141
|
+
extraHeaders["Idempotency-Key"] = opts.idempotency_key;
|
|
142
|
+
}
|
|
143
|
+
const raw = await this._durableRequest("POST", `/api/v2/agents/${encodeURIComponent(agentHandle)}/durable/invoke`, payload, extraHeaders);
|
|
144
|
+
return _normalizeDurableResponse(raw);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Resume execution from a checkpoint CID.
|
|
148
|
+
*
|
|
149
|
+
* Stateless — can be called from any process, any machine.
|
|
150
|
+
* The server restores state from the CID, skips already-completed steps,
|
|
151
|
+
* and continues forward.
|
|
152
|
+
*
|
|
153
|
+
* @param agentHandle - Agent handle.
|
|
154
|
+
* @param checkpointCid - The CID returned by a previous invokeWithCheckpoint call.
|
|
155
|
+
* @returns DurableResponse with the next checkpoint_cid.
|
|
156
|
+
*/
|
|
157
|
+
async resume(agentHandle, checkpointCid) {
|
|
158
|
+
const raw = await this._durableRequest("POST", `/api/v2/agents/${encodeURIComponent(agentHandle)}/durable/resume`, { checkpoint_cid: checkpointCid });
|
|
159
|
+
return _normalizeDurableResponse(raw);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Retrieve an agent's soul — IPFS-pinned identity that survives all restarts.
|
|
163
|
+
*
|
|
164
|
+
* @param agentHandle - Agent handle.
|
|
165
|
+
* @returns AgentSoul with soul_cid, mission, and learned_prefs.
|
|
166
|
+
*/
|
|
167
|
+
async getSoul(agentHandle) {
|
|
168
|
+
const raw = await this._durableRequest("GET", `/api/v2/agents/${encodeURIComponent(agentHandle)}/soul`);
|
|
169
|
+
return {
|
|
170
|
+
soul_id: String(raw["soul_id"] ?? ""),
|
|
171
|
+
agent_id: String(raw["agent_id"] ?? ""),
|
|
172
|
+
soul_cid: String(raw["soul_cid"] ?? ""),
|
|
173
|
+
mission: String(raw["mission"] ?? ""),
|
|
174
|
+
learned_prefs: raw["learned_prefs"] ?? {},
|
|
175
|
+
created_at: String(raw["created_at"] ?? ""),
|
|
176
|
+
updated_at: String(raw["updated_at"] ?? ""),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get the latest checkpoint for a session.
|
|
181
|
+
*
|
|
182
|
+
* Useful for polling long-running agent tasks.
|
|
183
|
+
*
|
|
184
|
+
* @param agentHandle - Agent handle.
|
|
185
|
+
* @param sessionId - Session ID.
|
|
186
|
+
* @returns CheckpointState or null if no checkpoint exists yet.
|
|
187
|
+
*/
|
|
188
|
+
async getCheckpoint(agentHandle, sessionId) {
|
|
189
|
+
try {
|
|
190
|
+
const raw = await this._durableRequest("GET", `/api/v2/agents/${encodeURIComponent(agentHandle)}/durable/checkpoint/${encodeURIComponent(sessionId)}`);
|
|
191
|
+
return _normalizeCheckpointState(raw);
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
if (err instanceof client_js_1.DingDawgApiError && err.status === 404)
|
|
195
|
+
return null;
|
|
196
|
+
throw err;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.DurableDingDawgClient = DurableDingDawgClient;
|
|
201
|
+
// ---------------------------------------------------------------------------
|
|
202
|
+
// Normalizers
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
function _normalizeDurableResponse(raw) {
|
|
205
|
+
return {
|
|
206
|
+
reply: String(raw["reply"] ?? raw["response"] ?? ""),
|
|
207
|
+
sessionId: String(raw["session_id"] ?? raw["sessionId"] ?? ""),
|
|
208
|
+
timestamp: String(raw["timestamp"] ?? new Date().toISOString()),
|
|
209
|
+
queued: raw["queued"] === true,
|
|
210
|
+
...(raw["model"] !== undefined ? { model: String(raw["model"]) } : {}),
|
|
211
|
+
checkpoint_cid: String(raw["checkpoint_cid"] ?? ""),
|
|
212
|
+
step_index: raw["step_index"] ?? 0,
|
|
213
|
+
verified: raw["verified"] === true,
|
|
214
|
+
fsm_state: raw["fsm_state"] ?? AgentFSMState.Done,
|
|
215
|
+
...(raw["proof_cid"] !== undefined ? { proof_cid: String(raw["proof_cid"]) } : {}),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function _normalizeCheckpointState(raw) {
|
|
219
|
+
return {
|
|
220
|
+
session_id: String(raw["session_id"] ?? ""),
|
|
221
|
+
step_index: raw["step_index"] ?? 0,
|
|
222
|
+
state_cid: String(raw["state_cid"] ?? ""),
|
|
223
|
+
fsm_state: raw["fsm_state"] ?? AgentFSMState.Idle,
|
|
224
|
+
created_at: String(raw["created_at"] ?? ""),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=durable.js.map
|
package/dist/durable.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @dingdawg/sdk/durable — DurableDingDawgClient
|
|
3
4
|
*
|
|
@@ -13,11 +14,13 @@
|
|
|
13
14
|
* ✅ Agent Soul persistence — identity survives crashes and migrations
|
|
14
15
|
* ✅ Memory class retention — A/B/C/D with IPFS anchoring for Class A
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.DurableDingDawgClient = exports.AgentFSMState = void 0;
|
|
19
|
+
const client_js_1 = require("./client.js");
|
|
17
20
|
// ---------------------------------------------------------------------------
|
|
18
|
-
// FSM state enum
|
|
21
|
+
// FSM state enum — matches the DDAG v1 protocol state machine
|
|
19
22
|
// ---------------------------------------------------------------------------
|
|
20
|
-
|
|
23
|
+
var AgentFSMState;
|
|
21
24
|
(function (AgentFSMState) {
|
|
22
25
|
AgentFSMState["Idle"] = "idle";
|
|
23
26
|
AgentFSMState["Running"] = "running";
|
|
@@ -29,7 +32,7 @@ export var AgentFSMState;
|
|
|
29
32
|
AgentFSMState["Resuming"] = "resuming";
|
|
30
33
|
AgentFSMState["Done"] = "done";
|
|
31
34
|
AgentFSMState["Failed"] = "failed";
|
|
32
|
-
})(AgentFSMState || (AgentFSMState = {}));
|
|
35
|
+
})(AgentFSMState || (exports.AgentFSMState = AgentFSMState = {}));
|
|
33
36
|
// ---------------------------------------------------------------------------
|
|
34
37
|
// SDK version
|
|
35
38
|
// ---------------------------------------------------------------------------
|
|
@@ -61,7 +64,7 @@ const SDK_USER_AGENT_DURABLE = "@dingdawg/sdk-durable/2.0.0";
|
|
|
61
64
|
* // Agent continues from the exact step it left off — no re-execution
|
|
62
65
|
* ```
|
|
63
66
|
*/
|
|
64
|
-
|
|
67
|
+
class DurableDingDawgClient extends client_js_1.DingDawgClient {
|
|
65
68
|
_durableApiKey;
|
|
66
69
|
_durableBaseUrl;
|
|
67
70
|
constructor(opts) {
|
|
@@ -94,7 +97,7 @@ export class DurableDingDawgClient extends DingDawgClient {
|
|
|
94
97
|
}
|
|
95
98
|
catch (err) {
|
|
96
99
|
const msg = err instanceof Error ? err.message : String(err);
|
|
97
|
-
throw new DingDawgApiError({ status: 0, body: { detail: `Network error: ${msg}` } }, `Network error reaching DingDawg API: ${msg}`);
|
|
100
|
+
throw new client_js_1.DingDawgApiError({ status: 0, body: { detail: `Network error: ${msg}` } }, `Network error reaching DingDawg API: ${msg}`);
|
|
98
101
|
}
|
|
99
102
|
if (!resp.ok) {
|
|
100
103
|
let errBody = null;
|
|
@@ -102,7 +105,7 @@ export class DurableDingDawgClient extends DingDawgClient {
|
|
|
102
105
|
errBody = (await resp.json());
|
|
103
106
|
}
|
|
104
107
|
catch { /* non-JSON error */ }
|
|
105
|
-
throw new DingDawgApiError({ status: resp.status, body: errBody });
|
|
108
|
+
throw new client_js_1.DingDawgApiError({ status: resp.status, body: errBody });
|
|
106
109
|
}
|
|
107
110
|
return (await resp.json());
|
|
108
111
|
}
|
|
@@ -188,12 +191,13 @@ export class DurableDingDawgClient extends DingDawgClient {
|
|
|
188
191
|
return _normalizeCheckpointState(raw);
|
|
189
192
|
}
|
|
190
193
|
catch (err) {
|
|
191
|
-
if (err instanceof DingDawgApiError && err.status === 404)
|
|
194
|
+
if (err instanceof client_js_1.DingDawgApiError && err.status === 404)
|
|
192
195
|
return null;
|
|
193
196
|
throw err;
|
|
194
197
|
}
|
|
195
198
|
}
|
|
196
199
|
}
|
|
200
|
+
exports.DurableDingDawgClient = DurableDingDawgClient;
|
|
197
201
|
// ---------------------------------------------------------------------------
|
|
198
202
|
// Normalizers
|
|
199
203
|
// ---------------------------------------------------------------------------
|
package/dist/durable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable.js","sourceRoot":"","sources":["../src/durable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"durable.js","sourceRoot":"","sources":["../src/durable.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,2CAA+D;AAQ/D,8EAA8E;AAC9E,8DAA8D;AAC9D,8EAA8E;AAE9E,IAAY,aAWX;AAXD,WAAY,aAAa;IACvB,8BAAqB,CAAA;IACrB,oCAAwB,CAAA;IACxB,6CAA6B,CAAA;IAC7B,wCAA0B,CAAA;IAC1B,0CAA2B,CAAA;IAC3B,4CAA4B,CAAA;IAC5B,8CAA6B,CAAA;IAC7B,sCAAyB,CAAA;IACzB,8BAAqB,CAAA;IACrB,kCAAuB,CAAA;AACzB,CAAC,EAXW,aAAa,6BAAb,aAAa,QAWxB;AAsED,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E,MAAM,sBAAsB,GAAG,6BAA6B,CAAC;AAE7D,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,qBAAsB,SAAQ,0BAAc;IACtC,cAAc,CAAS;IACvB,eAAe,CAAS;IAEzC,YAAY,IAA2B;QACrC,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,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a,CAAC,IAAI;QACpE,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACnF,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB,CAAC,GAA4B;IAC7D,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QAC3C,UAAU,EAAG,GAAG,CAAC,YAAY,CAAY,IAAI,CAAC;QAC9C,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QACzC,SAAS,EAAG,GAAG,CAAC,WAAW,CAAmB,IAAI,aAAa,CAAC,IAAI;QACpE,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;KAC5C,CAAC;AACJ,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dingdawg/sdk — Public API
|
|
4
|
+
*
|
|
5
|
+
* Re-exports everything a partner integration needs:
|
|
6
|
+
* - DingDawgClient (main class)
|
|
7
|
+
* - DurableDingDawgClient (crash-proof execution — DDAG v1)
|
|
8
|
+
* - DingDawgApiError (typed error)
|
|
9
|
+
* - All TypeScript interfaces and types
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AgentFSMState = exports.DurableDingDawgClient = exports.DingDawgApiError = exports.DingDawgClient = void 0;
|
|
13
|
+
var client_js_1 = require("./client");
|
|
14
|
+
Object.defineProperty(exports, "DingDawgClient", { enumerable: true, get: function () { return client_js_1.DingDawgClient; } });
|
|
15
|
+
Object.defineProperty(exports, "DingDawgApiError", { enumerable: true, get: function () { return client_js_1.DingDawgApiError; } });
|
|
16
|
+
// DDAG v1 — Durable execution SDK
|
|
17
|
+
var durable_js_1 = require("./durable");
|
|
18
|
+
Object.defineProperty(exports, "DurableDingDawgClient", { enumerable: true, get: function () { return durable_js_1.DurableDingDawgClient; } });
|
|
19
|
+
Object.defineProperty(exports, "AgentFSMState", { enumerable: true, get: function () { return durable_js_1.AgentFSMState; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @dingdawg/sdk — Public API
|
|
3
4
|
*
|
|
@@ -7,7 +8,13 @@
|
|
|
7
8
|
* - DingDawgApiError (typed error)
|
|
8
9
|
* - All TypeScript interfaces and types
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AgentFSMState = exports.DurableDingDawgClient = exports.DingDawgApiError = exports.DingDawgClient = void 0;
|
|
13
|
+
var client_js_1 = require("./client.js");
|
|
14
|
+
Object.defineProperty(exports, "DingDawgClient", { enumerable: true, get: function () { return client_js_1.DingDawgClient; } });
|
|
15
|
+
Object.defineProperty(exports, "DingDawgApiError", { enumerable: true, get: function () { return client_js_1.DingDawgApiError; } });
|
|
11
16
|
// DDAG v1 — Durable execution SDK
|
|
12
|
-
|
|
17
|
+
var durable_js_1 = require("./durable.js");
|
|
18
|
+
Object.defineProperty(exports, "DurableDingDawgClient", { enumerable: true, get: function () { return durable_js_1.DurableDingDawgClient; } });
|
|
19
|
+
Object.defineProperty(exports, "AgentFSMState", { enumerable: true, get: function () { return durable_js_1.AgentFSMState; } });
|
|
13
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAEH,yCAA+D;AAAtD,2GAAA,cAAc,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAwBzC,kCAAkC;AAClC,2CAAoE;AAA3D,mHAAA,qBAAqB,OAAA;AAAE,2GAAA,aAAa,OAAA"}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dingdawg/sdk — TypeScript types for all request and response shapes.
|
|
4
|
+
*
|
|
5
|
+
* All interfaces are exported so partner integrations can type their own code.
|
|
6
|
+
* Zero runtime imports — types are erased at compile time.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
package/dist/types.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @dingdawg/sdk — TypeScript types for all request and response shapes.
|
|
3
4
|
*
|
|
4
5
|
* All interfaces are exported so partner integrations can type their own code.
|
|
5
6
|
* Zero runtime imports — types are erased at compile time.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
9
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dingdawg/sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "DingDawg Agent SDK \u2014 durable AI agents with crash-proof exactly-once execution + IPFS checkpoints",
|
|
5
|
-
"
|
|
6
|
-
"main": "./dist/index.js",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
7
6
|
"module": "./dist/index.js",
|
|
8
7
|
"types": "./dist/index.d.ts",
|
|
9
8
|
"exports": {
|
|
10
9
|
".": {
|
|
11
10
|
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
12
|
"types": "./dist/index.d.ts"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"node": ">=18"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "tsc",
|
|
19
|
+
"build": "tsc && tsc -p tsconfig.cjs.json && node scripts/postbuild.js",
|
|
20
20
|
"test": "node --experimental-vm-modules node_modules/.bin/jest --testPathPattern='src/__tests__'",
|
|
21
21
|
"typecheck": "tsc --noEmit"
|
|
22
22
|
},
|
package/src/durable.ts
CHANGED
|
@@ -23,7 +23,7 @@ import type {
|
|
|
23
23
|
} from "./types.js";
|
|
24
24
|
|
|
25
25
|
// ---------------------------------------------------------------------------
|
|
26
|
-
// FSM state enum
|
|
26
|
+
// FSM state enum — matches the DDAG v1 protocol state machine
|
|
27
27
|
// ---------------------------------------------------------------------------
|
|
28
28
|
|
|
29
29
|
export enum AgentFSMState {
|