@dingdawg/sdk 2.0.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/dist/client.d.ts +126 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +302 -0
- package/dist/client.js.map +1 -0
- package/dist/durable.d.ts +162 -0
- package/dist/durable.d.ts.map +1 -0
- package/dist/durable.js +223 -0
- package/dist/durable.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +133 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -0
- package/src/__tests__/client.test.ts +576 -0
- package/src/__tests__/durable.test.ts +212 -0
- package/src/client.ts +461 -0
- package/src/durable.ts +347 -0
- package/src/index.ts +43 -0
- package/src/types.ts +178 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dingdawg/sdk — DingDawgClient
|
|
3
|
+
*
|
|
4
|
+
* The primary entry point for B2B2C partners embedding DingDawg agents.
|
|
5
|
+
*
|
|
6
|
+
* Design goals:
|
|
7
|
+
* - Zero runtime dependencies (Node 18+ built-in fetch only)
|
|
8
|
+
* - Full TypeScript types on all inputs and outputs
|
|
9
|
+
* - Typed error class so callers can catch + inspect failures
|
|
10
|
+
* - Grouped API namespaces: client.agent.* and client.billing.*
|
|
11
|
+
*/
|
|
12
|
+
import type { AgentRecord, BillingSummary, CreateAgentOptions, DingDawgClientOptions, MonthlyBillingSummary, PaginatedList, SendMessageOptions, TriggerResponse, ApiErrorBody, DingDawgApiErrorDetails } from "./types.js";
|
|
13
|
+
/**
|
|
14
|
+
* Thrown by all DingDawgClient methods when the API returns a non-2xx status.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* try {
|
|
19
|
+
* await client.agent.get("non-existent-id");
|
|
20
|
+
* } catch (err) {
|
|
21
|
+
* if (err instanceof DingDawgApiError) {
|
|
22
|
+
* console.error(err.status, err.body?.detail);
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class DingDawgApiError extends Error {
|
|
28
|
+
/** HTTP status code. */
|
|
29
|
+
readonly status: number;
|
|
30
|
+
/** Parsed error body from the API, or null if the body was not JSON. */
|
|
31
|
+
readonly body: ApiErrorBody | null;
|
|
32
|
+
constructor(details: DingDawgApiErrorDetails, message?: string);
|
|
33
|
+
}
|
|
34
|
+
/** Methods for managing agents. Available as `client.agent`. */
|
|
35
|
+
export interface AgentApi {
|
|
36
|
+
/**
|
|
37
|
+
* Create a new agent.
|
|
38
|
+
*
|
|
39
|
+
* @param opts - Agent creation options.
|
|
40
|
+
* @returns The newly created AgentRecord.
|
|
41
|
+
*/
|
|
42
|
+
create(opts: CreateAgentOptions): Promise<AgentRecord>;
|
|
43
|
+
/**
|
|
44
|
+
* List all agents belonging to the authenticated partner account.
|
|
45
|
+
*
|
|
46
|
+
* @param params - Optional pagination parameters.
|
|
47
|
+
* @returns Paginated list of AgentRecords.
|
|
48
|
+
*/
|
|
49
|
+
list(params?: {
|
|
50
|
+
limit?: number;
|
|
51
|
+
offset?: number;
|
|
52
|
+
}): Promise<PaginatedList<AgentRecord>>;
|
|
53
|
+
/**
|
|
54
|
+
* Get a single agent by ID.
|
|
55
|
+
*
|
|
56
|
+
* @param id - Agent UUID.
|
|
57
|
+
* @returns The AgentRecord.
|
|
58
|
+
*/
|
|
59
|
+
get(id: string): Promise<AgentRecord>;
|
|
60
|
+
/**
|
|
61
|
+
* Send a message to an agent via the trigger endpoint.
|
|
62
|
+
*
|
|
63
|
+
* @param agentId - Agent UUID.
|
|
64
|
+
* @param message - Message text or full options object.
|
|
65
|
+
* @returns The agent's reply and session information.
|
|
66
|
+
*/
|
|
67
|
+
sendMessage(agentId: string, message: string | SendMessageOptions): Promise<TriggerResponse>;
|
|
68
|
+
}
|
|
69
|
+
/** Methods for querying billing and usage. Available as `client.billing`. */
|
|
70
|
+
export interface BillingApi {
|
|
71
|
+
/**
|
|
72
|
+
* Get billing details for the current calendar month.
|
|
73
|
+
*
|
|
74
|
+
* @returns Monthly billing summary including line items and free-tier usage.
|
|
75
|
+
*/
|
|
76
|
+
currentMonth(): Promise<MonthlyBillingSummary>;
|
|
77
|
+
/**
|
|
78
|
+
* Get aggregate billing summary (lifetime + current month).
|
|
79
|
+
*
|
|
80
|
+
* @returns Full billing summary.
|
|
81
|
+
*/
|
|
82
|
+
summary(): Promise<BillingSummary>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* DingDawgClient — the single entry point for the DingDawg Agent SDK.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { DingDawgClient } from "@dingdawg/sdk";
|
|
90
|
+
*
|
|
91
|
+
* const client = new DingDawgClient({ apiKey: "dd_live_..." });
|
|
92
|
+
*
|
|
93
|
+
* const agent = await client.agent.create({
|
|
94
|
+
* name: "Support Bot",
|
|
95
|
+
* handle: "acme-support",
|
|
96
|
+
* agentType: "business",
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* const reply = await client.agent.sendMessage(agent.id, "Hello!");
|
|
100
|
+
* console.log(reply.reply);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare class DingDawgClient {
|
|
104
|
+
private readonly _apiKey;
|
|
105
|
+
private readonly _baseUrl;
|
|
106
|
+
/** Methods for managing agents. */
|
|
107
|
+
readonly agent: AgentApi;
|
|
108
|
+
/** Methods for querying billing and usage. */
|
|
109
|
+
readonly billing: BillingApi;
|
|
110
|
+
/**
|
|
111
|
+
* Create a new DingDawgClient instance.
|
|
112
|
+
*
|
|
113
|
+
* @param opts - Configuration options.
|
|
114
|
+
* @throws {TypeError} When apiKey is missing or empty.
|
|
115
|
+
*/
|
|
116
|
+
constructor(opts: DingDawgClientOptions);
|
|
117
|
+
/**
|
|
118
|
+
* Perform an authenticated JSON request.
|
|
119
|
+
*
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
private _request;
|
|
123
|
+
private _buildAgentApi;
|
|
124
|
+
private _buildBillingApi;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAcpB;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,wBAAwB;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;gBAEvB,OAAO,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,MAAM;CAa/D;AA+CD,gEAAgE;AAChE,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAEvD;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;IAExF;;;;;OAKG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAEtC;;;;;;OAMG;IACH,WAAW,CACT,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,kBAAkB,GACnC,OAAO,CAAC,eAAe,CAAC,CAAC;CAC7B;AAMD,6EAA6E;AAC7E,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,YAAY,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAE/C;;;;OAIG;IACH,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC;CACpC;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAEzB,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAE7B;;;;;OAKG;gBACS,IAAI,EAAE,qBAAqB;IAmBvC;;;;OAIG;YACW,QAAQ;IAuCtB,OAAO,CAAC,cAAc;IAgGtB,OAAO,CAAC,gBAAgB;CAgCzB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dingdawg/sdk — DingDawgClient
|
|
3
|
+
*
|
|
4
|
+
* The primary entry point for B2B2C partners embedding DingDawg agents.
|
|
5
|
+
*
|
|
6
|
+
* Design goals:
|
|
7
|
+
* - Zero runtime dependencies (Node 18+ built-in fetch only)
|
|
8
|
+
* - Full TypeScript types on all inputs and outputs
|
|
9
|
+
* - Typed error class so callers can catch + inspect failures
|
|
10
|
+
* - Grouped API namespaces: client.agent.* and client.billing.*
|
|
11
|
+
*/
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Default configuration
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
const DEFAULT_BASE_URL = "https://api.dingdawg.com";
|
|
16
|
+
const SDK_USER_AGENT = "@dingdawg/sdk/0.1.0";
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Typed error class
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* Thrown by all DingDawgClient methods when the API returns a non-2xx status.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* try {
|
|
26
|
+
* await client.agent.get("non-existent-id");
|
|
27
|
+
* } catch (err) {
|
|
28
|
+
* if (err instanceof DingDawgApiError) {
|
|
29
|
+
* console.error(err.status, err.body?.detail);
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export class DingDawgApiError extends Error {
|
|
35
|
+
/** HTTP status code. */
|
|
36
|
+
status;
|
|
37
|
+
/** Parsed error body from the API, or null if the body was not JSON. */
|
|
38
|
+
body;
|
|
39
|
+
constructor(details, message) {
|
|
40
|
+
const derived = message ??
|
|
41
|
+
details.body?.detail ??
|
|
42
|
+
details.body?.message ??
|
|
43
|
+
`DingDawg API error: HTTP ${details.status}`;
|
|
44
|
+
super(String(derived));
|
|
45
|
+
this.name = "DingDawgApiError";
|
|
46
|
+
this.status = details.status;
|
|
47
|
+
this.body = details.body;
|
|
48
|
+
// Maintains proper prototype chain in transpiled environments
|
|
49
|
+
Object.setPrototypeOf(this, DingDawgApiError.prototype);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Internal HTTP helpers
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
/**
|
|
56
|
+
* Parse a Response, throwing DingDawgApiError on non-2xx status.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
async function _parseResponse(resp) {
|
|
61
|
+
let body = null;
|
|
62
|
+
const contentType = resp.headers.get("content-type") ?? "";
|
|
63
|
+
if (contentType.includes("application/json")) {
|
|
64
|
+
try {
|
|
65
|
+
body = await resp.json();
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
body = null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
try {
|
|
73
|
+
body = await resp.text();
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
body = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!resp.ok) {
|
|
80
|
+
const errorBody = body !== null && typeof body === "object"
|
|
81
|
+
? body
|
|
82
|
+
: typeof body === "string"
|
|
83
|
+
? { detail: body }
|
|
84
|
+
: null;
|
|
85
|
+
throw new DingDawgApiError({ status: resp.status, body: errorBody });
|
|
86
|
+
}
|
|
87
|
+
return body;
|
|
88
|
+
}
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
// Main client class
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
/**
|
|
93
|
+
* DingDawgClient — the single entry point for the DingDawg Agent SDK.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { DingDawgClient } from "@dingdawg/sdk";
|
|
98
|
+
*
|
|
99
|
+
* const client = new DingDawgClient({ apiKey: "dd_live_..." });
|
|
100
|
+
*
|
|
101
|
+
* const agent = await client.agent.create({
|
|
102
|
+
* name: "Support Bot",
|
|
103
|
+
* handle: "acme-support",
|
|
104
|
+
* agentType: "business",
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* const reply = await client.agent.sendMessage(agent.id, "Hello!");
|
|
108
|
+
* console.log(reply.reply);
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export class DingDawgClient {
|
|
112
|
+
_apiKey;
|
|
113
|
+
_baseUrl;
|
|
114
|
+
/** Methods for managing agents. */
|
|
115
|
+
agent;
|
|
116
|
+
/** Methods for querying billing and usage. */
|
|
117
|
+
billing;
|
|
118
|
+
/**
|
|
119
|
+
* Create a new DingDawgClient instance.
|
|
120
|
+
*
|
|
121
|
+
* @param opts - Configuration options.
|
|
122
|
+
* @throws {TypeError} When apiKey is missing or empty.
|
|
123
|
+
*/
|
|
124
|
+
constructor(opts) {
|
|
125
|
+
if (!opts.apiKey || typeof opts.apiKey !== "string" || opts.apiKey.trim() === "") {
|
|
126
|
+
throw new TypeError("DingDawgClient: apiKey is required and must be a non-empty string");
|
|
127
|
+
}
|
|
128
|
+
this._apiKey = opts.apiKey.trim();
|
|
129
|
+
this._baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
130
|
+
// Bind namespace objects so methods can be destructured safely
|
|
131
|
+
this.agent = this._buildAgentApi();
|
|
132
|
+
this.billing = this._buildBillingApi();
|
|
133
|
+
}
|
|
134
|
+
// -------------------------------------------------------------------------
|
|
135
|
+
// Internal HTTP request
|
|
136
|
+
// -------------------------------------------------------------------------
|
|
137
|
+
/**
|
|
138
|
+
* Perform an authenticated JSON request.
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
async _request(method, path, body) {
|
|
143
|
+
const url = `${this._baseUrl}${path}`;
|
|
144
|
+
const headers = {
|
|
145
|
+
"Content-Type": "application/json",
|
|
146
|
+
"User-Agent": SDK_USER_AGENT,
|
|
147
|
+
Authorization: `Bearer ${this._apiKey}`,
|
|
148
|
+
"X-DingDawg-SDK": "1",
|
|
149
|
+
};
|
|
150
|
+
const init = { method, headers };
|
|
151
|
+
if (body !== undefined && method !== "GET") {
|
|
152
|
+
init.body = JSON.stringify(body);
|
|
153
|
+
}
|
|
154
|
+
let resp;
|
|
155
|
+
try {
|
|
156
|
+
resp = await fetch(url, init);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
// Network-level failure (DNS, connection refused, etc.)
|
|
160
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
161
|
+
throw new DingDawgApiError({ status: 0, body: { detail: `Network error: ${message}` } }, `Network error reaching DingDawg API: ${message}`);
|
|
162
|
+
}
|
|
163
|
+
return _parseResponse(resp);
|
|
164
|
+
}
|
|
165
|
+
// -------------------------------------------------------------------------
|
|
166
|
+
// Agent API builder
|
|
167
|
+
// -------------------------------------------------------------------------
|
|
168
|
+
_buildAgentApi() {
|
|
169
|
+
return {
|
|
170
|
+
create: async (opts) => {
|
|
171
|
+
const payload = {
|
|
172
|
+
name: opts.name,
|
|
173
|
+
handle: opts.handle,
|
|
174
|
+
agent_type: opts.agentType ?? "business",
|
|
175
|
+
industry_type: opts.industry,
|
|
176
|
+
system_prompt: opts.systemPrompt,
|
|
177
|
+
template_id: opts.templateId,
|
|
178
|
+
branding: opts.branding
|
|
179
|
+
? {
|
|
180
|
+
primary_color: opts.branding.primaryColor,
|
|
181
|
+
avatar_url: opts.branding.avatarUrl,
|
|
182
|
+
}
|
|
183
|
+
: undefined,
|
|
184
|
+
};
|
|
185
|
+
const raw = await this._request("POST", "/api/v2/partner/agents", payload);
|
|
186
|
+
return _normalizeAgent(raw);
|
|
187
|
+
},
|
|
188
|
+
list: async (params = {}) => {
|
|
189
|
+
const qs = new URLSearchParams();
|
|
190
|
+
if (params.limit !== undefined)
|
|
191
|
+
qs.set("limit", String(params.limit));
|
|
192
|
+
if (params.offset !== undefined)
|
|
193
|
+
qs.set("offset", String(params.offset));
|
|
194
|
+
const queryString = qs.toString();
|
|
195
|
+
const path = queryString
|
|
196
|
+
? `/api/v2/partner/agents?${queryString}`
|
|
197
|
+
: "/api/v2/partner/agents";
|
|
198
|
+
const raw = await this._request("GET", path);
|
|
199
|
+
const items = (raw["items"] ?? raw["agents"] ?? []);
|
|
200
|
+
return {
|
|
201
|
+
items: items.map(_normalizeAgent),
|
|
202
|
+
total: raw["total"] ?? items.length,
|
|
203
|
+
limit: raw["limit"] ?? (params.limit ?? 20),
|
|
204
|
+
offset: raw["offset"] ?? (params.offset ?? 0),
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
get: async (id) => {
|
|
208
|
+
const raw = await this._request("GET", `/api/v2/partner/agents/${encodeURIComponent(id)}`);
|
|
209
|
+
return _normalizeAgent(raw);
|
|
210
|
+
},
|
|
211
|
+
sendMessage: async (agentId, message) => {
|
|
212
|
+
const opts = typeof message === "string" ? { message } : message;
|
|
213
|
+
const payload = {
|
|
214
|
+
message: opts.message,
|
|
215
|
+
user_id: opts.userId,
|
|
216
|
+
session_id: opts.sessionId,
|
|
217
|
+
metadata: opts.metadata,
|
|
218
|
+
};
|
|
219
|
+
const raw = await this._request("POST", `/api/v1/agents/${encodeURIComponent(agentId)}/trigger`, payload);
|
|
220
|
+
const triggerResult = {
|
|
221
|
+
reply: String(raw["reply"] ?? raw["response"] ?? ""),
|
|
222
|
+
sessionId: String(raw["session_id"] ?? raw["sessionId"] ?? ""),
|
|
223
|
+
timestamp: String(raw["timestamp"] ?? new Date().toISOString()),
|
|
224
|
+
queued: raw["queued"] === true,
|
|
225
|
+
...(raw["model"] !== undefined ? { model: String(raw["model"]) } : {}),
|
|
226
|
+
};
|
|
227
|
+
return triggerResult;
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
// -------------------------------------------------------------------------
|
|
232
|
+
// Billing API builder
|
|
233
|
+
// -------------------------------------------------------------------------
|
|
234
|
+
_buildBillingApi() {
|
|
235
|
+
return {
|
|
236
|
+
currentMonth: async () => {
|
|
237
|
+
const raw = await this._request("GET", "/api/v2/partner/billing/current-month");
|
|
238
|
+
return _normalizeMonthlySummary(raw);
|
|
239
|
+
},
|
|
240
|
+
summary: async () => {
|
|
241
|
+
const raw = await this._request("GET", "/api/v2/partner/billing");
|
|
242
|
+
const currentMonth = _normalizeMonthlySummary(raw["current_month"] ?? {});
|
|
243
|
+
const billingSummaryResult = {
|
|
244
|
+
totalActions: raw["total_actions"] ?? 0,
|
|
245
|
+
totalCents: raw["total_cents"] ?? 0,
|
|
246
|
+
currentMonth,
|
|
247
|
+
...(raw["stripe_customer_id"] !== undefined
|
|
248
|
+
? { stripeCustomerId: String(raw["stripe_customer_id"]) }
|
|
249
|
+
: {}),
|
|
250
|
+
};
|
|
251
|
+
return billingSummaryResult;
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// ---------------------------------------------------------------------------
|
|
257
|
+
// Normalizer helpers (snake_case → camelCase)
|
|
258
|
+
// ---------------------------------------------------------------------------
|
|
259
|
+
function _normalizeAgent(raw) {
|
|
260
|
+
const branding = raw["branding"];
|
|
261
|
+
return {
|
|
262
|
+
id: String(raw["id"] ?? raw["agent_id"] ?? ""),
|
|
263
|
+
handle: String(raw["handle"] ?? ""),
|
|
264
|
+
name: String(raw["name"] ?? ""),
|
|
265
|
+
agentType: (raw["agent_type"] ?? raw["agentType"] ?? "business"),
|
|
266
|
+
industry: raw["industry_type"] !== undefined
|
|
267
|
+
? String(raw["industry_type"])
|
|
268
|
+
: raw["industry"] !== undefined
|
|
269
|
+
? String(raw["industry"])
|
|
270
|
+
: null,
|
|
271
|
+
status: (raw["status"] ?? "active"),
|
|
272
|
+
createdAt: String(raw["created_at"] ?? raw["createdAt"] ?? ""),
|
|
273
|
+
updatedAt: String(raw["updated_at"] ?? raw["updatedAt"] ?? ""),
|
|
274
|
+
...(branding
|
|
275
|
+
? {
|
|
276
|
+
branding: {
|
|
277
|
+
...(branding["primary_color"] !== undefined
|
|
278
|
+
? { primaryColor: String(branding["primary_color"]) }
|
|
279
|
+
: {}),
|
|
280
|
+
...(branding["avatar_url"] !== undefined
|
|
281
|
+
? { avatarUrl: String(branding["avatar_url"]) }
|
|
282
|
+
: {}),
|
|
283
|
+
},
|
|
284
|
+
}
|
|
285
|
+
: {}),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function _normalizeMonthlySummary(raw) {
|
|
289
|
+
const lineItemsRaw = Array.isArray(raw["line_items"]) ? raw["line_items"] : [];
|
|
290
|
+
return {
|
|
291
|
+
month: String(raw["month"] ?? ""),
|
|
292
|
+
totalActions: raw["total_actions"] ?? 0,
|
|
293
|
+
totalCents: raw["total_cents"] ?? 0,
|
|
294
|
+
freeActionsRemaining: raw["free_actions_remaining"] ?? 0,
|
|
295
|
+
lineItems: lineItemsRaw.map((item) => ({
|
|
296
|
+
action: String(item["action"] ?? ""),
|
|
297
|
+
count: item["count"] ?? 0,
|
|
298
|
+
costCents: item["cost_cents"] ?? 0,
|
|
299
|
+
})),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,MAAM,OAAO,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,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E;;;;GAI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,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"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dingdawg/sdk/durable — DurableDingDawgClient
|
|
3
|
+
*
|
|
4
|
+
* Extends DingDawgClient with DDAG v1 crash-proof execution:
|
|
5
|
+
* - invokeWithCheckpoint() — run agent step, get back a CID resume token
|
|
6
|
+
* - resume() — continue from a checkpoint CID (any machine)
|
|
7
|
+
* - getSoul() — retrieve an agent's IPFS-pinned identity
|
|
8
|
+
*
|
|
9
|
+
* What competitors don't have (in one SDK):
|
|
10
|
+
* ✅ Log-first WAL execution — crash = replay from log, never lose progress
|
|
11
|
+
* ✅ IPFS content-addressed checkpoints — stateless resume on any machine
|
|
12
|
+
* ✅ Exactly-once semantics — idempotency keys prevent double-execution
|
|
13
|
+
* ✅ Agent Soul persistence — identity survives crashes and migrations
|
|
14
|
+
* ✅ Memory class retention — A/B/C/D with IPFS anchoring for Class A
|
|
15
|
+
*/
|
|
16
|
+
import { DingDawgClient } from "./client.js";
|
|
17
|
+
import type { DingDawgClientOptions, SendMessageOptions, TriggerResponse } from "./types.js";
|
|
18
|
+
export declare enum AgentFSMState {
|
|
19
|
+
Idle = "idle",
|
|
20
|
+
Running = "running",
|
|
21
|
+
ToolPending = "tool_pending",
|
|
22
|
+
Verifying = "verifying",
|
|
23
|
+
Committing = "committing",
|
|
24
|
+
Remediating = "remediating",
|
|
25
|
+
Checkpointed = "checkpointed",
|
|
26
|
+
Resuming = "resuming",
|
|
27
|
+
Done = "done",
|
|
28
|
+
Failed = "failed"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A content-addressed checkpoint snapshot.
|
|
32
|
+
* Save `state_cid` — pass it to `resume()` to continue from this exact point.
|
|
33
|
+
*/
|
|
34
|
+
export interface CheckpointState {
|
|
35
|
+
/** Session this checkpoint belongs to. */
|
|
36
|
+
session_id: string;
|
|
37
|
+
/** Execution step index (0-based). */
|
|
38
|
+
step_index: number;
|
|
39
|
+
/**
|
|
40
|
+
* Content-addressed CID — the durable resume token.
|
|
41
|
+
* Format: "ipfs:<hash>" when IPFS is available, "sha256:<hex>" for local fallback.
|
|
42
|
+
*/
|
|
43
|
+
state_cid: string;
|
|
44
|
+
/** FSM state at checkpoint time. */
|
|
45
|
+
fsm_state: AgentFSMState;
|
|
46
|
+
/** ISO-8601 UTC timestamp. */
|
|
47
|
+
created_at: string;
|
|
48
|
+
}
|
|
49
|
+
/** IPFS-pinned agent identity — survives crashes, restarts, and migrations. */
|
|
50
|
+
export interface AgentSoul {
|
|
51
|
+
soul_id: string;
|
|
52
|
+
agent_id: string;
|
|
53
|
+
/** CID of the current serialised soul state. */
|
|
54
|
+
soul_cid: string;
|
|
55
|
+
/** Plain-text mission statement — never changes. */
|
|
56
|
+
mission: string;
|
|
57
|
+
/** Mutable preferences updated each session. */
|
|
58
|
+
learned_prefs: Record<string, unknown>;
|
|
59
|
+
created_at: string;
|
|
60
|
+
updated_at: string;
|
|
61
|
+
}
|
|
62
|
+
/** Options for a durable agent invocation. */
|
|
63
|
+
export interface DurableSession extends SendMessageOptions {
|
|
64
|
+
/**
|
|
65
|
+
* Resume from this checkpoint CID.
|
|
66
|
+
* When provided, the agent skips already-completed steps (exactly-once guarantee).
|
|
67
|
+
*/
|
|
68
|
+
resume_cid?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Caller-supplied idempotency key.
|
|
71
|
+
* If omitted the server derives one from (session_id + step_index + tool_name).
|
|
72
|
+
*/
|
|
73
|
+
idempotency_key?: string;
|
|
74
|
+
/** Checkpoint after every N steps (default: 1 — checkpoint every step). */
|
|
75
|
+
checkpoint_every?: number;
|
|
76
|
+
}
|
|
77
|
+
/** Response from a durable invocation — always includes a CID for future resume. */
|
|
78
|
+
export interface DurableResponse extends TriggerResponse {
|
|
79
|
+
/** Always returned — store this to resume after a crash. */
|
|
80
|
+
checkpoint_cid: string;
|
|
81
|
+
/** Current execution step index. */
|
|
82
|
+
step_index: number;
|
|
83
|
+
/** True when CHR PALP verification passed. */
|
|
84
|
+
verified: boolean;
|
|
85
|
+
/** IPFS CID of the CHR PALP proof (present only when verification ran). */
|
|
86
|
+
proof_cid?: string;
|
|
87
|
+
/** FSM state at response time. */
|
|
88
|
+
fsm_state: AgentFSMState;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* DurableDingDawgClient — crash-proof agent execution SDK.
|
|
92
|
+
*
|
|
93
|
+
* @example Basic durable invocation
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { DurableDingDawgClient } from "@dingdawg/sdk";
|
|
96
|
+
*
|
|
97
|
+
* const client = new DurableDingDawgClient({ apiKey: "dd_live_..." });
|
|
98
|
+
*
|
|
99
|
+
* const result = await client.invokeWithCheckpoint("acme-support", {
|
|
100
|
+
* message: "Run the quarterly compliance report",
|
|
101
|
+
* userId: "user_123",
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* // Save checkpoint_cid — if the process crashes, pass it to resume()
|
|
105
|
+
* console.log(result.checkpoint_cid); // "ipfs:Qm..." or "sha256:..."
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example Resume after crash
|
|
109
|
+
* ```ts
|
|
110
|
+
* const resumed = await client.resume("acme-support", savedCheckpointCid);
|
|
111
|
+
* // Agent continues from the exact step it left off — no re-execution
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare class DurableDingDawgClient extends DingDawgClient {
|
|
115
|
+
private readonly _durableApiKey;
|
|
116
|
+
private readonly _durableBaseUrl;
|
|
117
|
+
constructor(opts: DingDawgClientOptions);
|
|
118
|
+
private _durableRequest;
|
|
119
|
+
/**
|
|
120
|
+
* Invoke an agent with checkpoint support.
|
|
121
|
+
*
|
|
122
|
+
* The server journalises intent before execution and checkpoints state after.
|
|
123
|
+
* The returned `checkpoint_cid` is the durable resume token — store it.
|
|
124
|
+
* On crash, call `resume(handle, checkpoint_cid)` to continue without re-executing
|
|
125
|
+
* completed steps.
|
|
126
|
+
*
|
|
127
|
+
* @param agentHandle - Agent handle (e.g. "acme-support").
|
|
128
|
+
* @param opts - Message options + optional resume_cid, idempotency_key, checkpoint_every.
|
|
129
|
+
* @returns DurableResponse including checkpoint_cid, step_index, verified, fsm_state.
|
|
130
|
+
*/
|
|
131
|
+
invokeWithCheckpoint(agentHandle: string, opts: DurableSession): Promise<DurableResponse>;
|
|
132
|
+
/**
|
|
133
|
+
* Resume execution from a checkpoint CID.
|
|
134
|
+
*
|
|
135
|
+
* Stateless — can be called from any process, any machine.
|
|
136
|
+
* The server restores state from the CID, skips already-completed steps,
|
|
137
|
+
* and continues forward.
|
|
138
|
+
*
|
|
139
|
+
* @param agentHandle - Agent handle.
|
|
140
|
+
* @param checkpointCid - The CID returned by a previous invokeWithCheckpoint call.
|
|
141
|
+
* @returns DurableResponse with the next checkpoint_cid.
|
|
142
|
+
*/
|
|
143
|
+
resume(agentHandle: string, checkpointCid: string): Promise<DurableResponse>;
|
|
144
|
+
/**
|
|
145
|
+
* Retrieve an agent's soul — IPFS-pinned identity that survives all restarts.
|
|
146
|
+
*
|
|
147
|
+
* @param agentHandle - Agent handle.
|
|
148
|
+
* @returns AgentSoul with soul_cid, mission, and learned_prefs.
|
|
149
|
+
*/
|
|
150
|
+
getSoul(agentHandle: string): Promise<AgentSoul>;
|
|
151
|
+
/**
|
|
152
|
+
* Get the latest checkpoint for a session.
|
|
153
|
+
*
|
|
154
|
+
* Useful for polling long-running agent tasks.
|
|
155
|
+
*
|
|
156
|
+
* @param agentHandle - Agent handle.
|
|
157
|
+
* @param sessionId - Session ID.
|
|
158
|
+
* @returns CheckpointState or null if no checkpoint exists yet.
|
|
159
|
+
*/
|
|
160
|
+
getCheckpoint(agentHandle: string, sessionId: string): Promise<CheckpointState | null>;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=durable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["../src/durable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,cAAc,EAAoB,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EAEhB,MAAM,YAAY,CAAC;AAMpB,oBAAY,aAAa;IACvB,IAAI,SAAiB;IACrB,OAAO,YAAiB;IACxB,WAAW,iBAAkB;IAC7B,SAAS,cAAiB;IAC1B,UAAU,eAAiB;IAC3B,WAAW,gBAAiB;IAC5B,YAAY,iBAAiB;IAC7B,QAAQ,aAAiB;IACzB,IAAI,SAAiB;IACrB,MAAM,WAAiB;CACxB;AAMD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,SAAS,EAAE,aAAa,CAAC;IACzB,8BAA8B;IAC9B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,+EAA+E;AAC/E,MAAM,WAAW,S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