@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.
@@ -0,0 +1,223 @@
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, DingDawgApiError } from "./client.js";
17
+ // ---------------------------------------------------------------------------
18
+ // FSM state enum (mirrors isg_agent/protocol/ddag_v1.py AgentFSMState)
19
+ // ---------------------------------------------------------------------------
20
+ export var AgentFSMState;
21
+ (function (AgentFSMState) {
22
+ AgentFSMState["Idle"] = "idle";
23
+ AgentFSMState["Running"] = "running";
24
+ AgentFSMState["ToolPending"] = "tool_pending";
25
+ AgentFSMState["Verifying"] = "verifying";
26
+ AgentFSMState["Committing"] = "committing";
27
+ AgentFSMState["Remediating"] = "remediating";
28
+ AgentFSMState["Checkpointed"] = "checkpointed";
29
+ AgentFSMState["Resuming"] = "resuming";
30
+ AgentFSMState["Done"] = "done";
31
+ AgentFSMState["Failed"] = "failed";
32
+ })(AgentFSMState || (AgentFSMState = {}));
33
+ // ---------------------------------------------------------------------------
34
+ // SDK version
35
+ // ---------------------------------------------------------------------------
36
+ const SDK_USER_AGENT_DURABLE = "@dingdawg/sdk-durable/2.0.0";
37
+ // ---------------------------------------------------------------------------
38
+ // DurableDingDawgClient
39
+ // ---------------------------------------------------------------------------
40
+ /**
41
+ * DurableDingDawgClient — crash-proof agent execution SDK.
42
+ *
43
+ * @example Basic durable invocation
44
+ * ```ts
45
+ * import { DurableDingDawgClient } from "@dingdawg/sdk";
46
+ *
47
+ * const client = new DurableDingDawgClient({ apiKey: "dd_live_..." });
48
+ *
49
+ * const result = await client.invokeWithCheckpoint("acme-support", {
50
+ * message: "Run the quarterly compliance report",
51
+ * userId: "user_123",
52
+ * });
53
+ *
54
+ * // Save checkpoint_cid — if the process crashes, pass it to resume()
55
+ * console.log(result.checkpoint_cid); // "ipfs:Qm..." or "sha256:..."
56
+ * ```
57
+ *
58
+ * @example Resume after crash
59
+ * ```ts
60
+ * const resumed = await client.resume("acme-support", savedCheckpointCid);
61
+ * // Agent continues from the exact step it left off — no re-execution
62
+ * ```
63
+ */
64
+ export class DurableDingDawgClient extends DingDawgClient {
65
+ _durableApiKey;
66
+ _durableBaseUrl;
67
+ constructor(opts) {
68
+ super(opts);
69
+ this._durableApiKey = opts.apiKey.trim();
70
+ this._durableBaseUrl = (opts.baseUrl ?? "https://api.dingdawg.com").replace(/\/$/, "");
71
+ }
72
+ // -------------------------------------------------------------------------
73
+ // Internal HTTP helper (mirrors DingDawgClient._request — kept private)
74
+ // -------------------------------------------------------------------------
75
+ async _durableRequest(method, path, body, extraHeaders) {
76
+ const url = `${this._durableBaseUrl}${path}`;
77
+ const headers = {
78
+ "Content-Type": "application/json",
79
+ "User-Agent": SDK_USER_AGENT_DURABLE,
80
+ Authorization: `Bearer ${this._durableApiKey}`,
81
+ "X-DingDawg-SDK": "2",
82
+ ...extraHeaders,
83
+ };
84
+ const init = {
85
+ method,
86
+ headers,
87
+ ...(body !== undefined && method !== "GET"
88
+ ? { body: JSON.stringify(body) }
89
+ : {}),
90
+ };
91
+ let resp;
92
+ try {
93
+ resp = await fetch(url, init);
94
+ }
95
+ catch (err) {
96
+ 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}`);
98
+ }
99
+ if (!resp.ok) {
100
+ let errBody = null;
101
+ try {
102
+ errBody = (await resp.json());
103
+ }
104
+ catch { /* non-JSON error */ }
105
+ throw new DingDawgApiError({ status: resp.status, body: errBody });
106
+ }
107
+ return (await resp.json());
108
+ }
109
+ // -------------------------------------------------------------------------
110
+ // Public durable API
111
+ // -------------------------------------------------------------------------
112
+ /**
113
+ * Invoke an agent with checkpoint support.
114
+ *
115
+ * The server journalises intent before execution and checkpoints state after.
116
+ * The returned `checkpoint_cid` is the durable resume token — store it.
117
+ * On crash, call `resume(handle, checkpoint_cid)` to continue without re-executing
118
+ * completed steps.
119
+ *
120
+ * @param agentHandle - Agent handle (e.g. "acme-support").
121
+ * @param opts - Message options + optional resume_cid, idempotency_key, checkpoint_every.
122
+ * @returns DurableResponse including checkpoint_cid, step_index, verified, fsm_state.
123
+ */
124
+ async invokeWithCheckpoint(agentHandle, opts) {
125
+ const payload = {
126
+ message: opts.message,
127
+ user_id: opts.userId,
128
+ session_id: opts.sessionId,
129
+ metadata: opts.metadata,
130
+ checkpoint_every: opts.checkpoint_every ?? 1,
131
+ };
132
+ if (opts.resume_cid !== undefined)
133
+ payload["resume_cid"] = opts.resume_cid;
134
+ if (opts.idempotency_key !== undefined)
135
+ payload["idempotency_key"] = opts.idempotency_key;
136
+ const extraHeaders = {};
137
+ if (opts.idempotency_key !== undefined) {
138
+ extraHeaders["Idempotency-Key"] = opts.idempotency_key;
139
+ }
140
+ const raw = await this._durableRequest("POST", `/api/v2/agents/${encodeURIComponent(agentHandle)}/durable/invoke`, payload, extraHeaders);
141
+ return _normalizeDurableResponse(raw);
142
+ }
143
+ /**
144
+ * Resume execution from a checkpoint CID.
145
+ *
146
+ * Stateless — can be called from any process, any machine.
147
+ * The server restores state from the CID, skips already-completed steps,
148
+ * and continues forward.
149
+ *
150
+ * @param agentHandle - Agent handle.
151
+ * @param checkpointCid - The CID returned by a previous invokeWithCheckpoint call.
152
+ * @returns DurableResponse with the next checkpoint_cid.
153
+ */
154
+ async resume(agentHandle, checkpointCid) {
155
+ const raw = await this._durableRequest("POST", `/api/v2/agents/${encodeURIComponent(agentHandle)}/durable/resume`, { checkpoint_cid: checkpointCid });
156
+ return _normalizeDurableResponse(raw);
157
+ }
158
+ /**
159
+ * Retrieve an agent's soul — IPFS-pinned identity that survives all restarts.
160
+ *
161
+ * @param agentHandle - Agent handle.
162
+ * @returns AgentSoul with soul_cid, mission, and learned_prefs.
163
+ */
164
+ async getSoul(agentHandle) {
165
+ const raw = await this._durableRequest("GET", `/api/v2/agents/${encodeURIComponent(agentHandle)}/soul`);
166
+ return {
167
+ soul_id: String(raw["soul_id"] ?? ""),
168
+ agent_id: String(raw["agent_id"] ?? ""),
169
+ soul_cid: String(raw["soul_cid"] ?? ""),
170
+ mission: String(raw["mission"] ?? ""),
171
+ learned_prefs: raw["learned_prefs"] ?? {},
172
+ created_at: String(raw["created_at"] ?? ""),
173
+ updated_at: String(raw["updated_at"] ?? ""),
174
+ };
175
+ }
176
+ /**
177
+ * Get the latest checkpoint for a session.
178
+ *
179
+ * Useful for polling long-running agent tasks.
180
+ *
181
+ * @param agentHandle - Agent handle.
182
+ * @param sessionId - Session ID.
183
+ * @returns CheckpointState or null if no checkpoint exists yet.
184
+ */
185
+ async getCheckpoint(agentHandle, sessionId) {
186
+ try {
187
+ const raw = await this._durableRequest("GET", `/api/v2/agents/${encodeURIComponent(agentHandle)}/durable/checkpoint/${encodeURIComponent(sessionId)}`);
188
+ return _normalizeCheckpointState(raw);
189
+ }
190
+ catch (err) {
191
+ if (err instanceof DingDawgApiError && err.status === 404)
192
+ return null;
193
+ throw err;
194
+ }
195
+ }
196
+ }
197
+ // ---------------------------------------------------------------------------
198
+ // Normalizers
199
+ // ---------------------------------------------------------------------------
200
+ function _normalizeDurableResponse(raw) {
201
+ return {
202
+ reply: String(raw["reply"] ?? raw["response"] ?? ""),
203
+ sessionId: String(raw["session_id"] ?? raw["sessionId"] ?? ""),
204
+ timestamp: String(raw["timestamp"] ?? new Date().toISOString()),
205
+ queued: raw["queued"] === true,
206
+ ...(raw["model"] !== undefined ? { model: String(raw["model"]) } : {}),
207
+ checkpoint_cid: String(raw["checkpoint_cid"] ?? ""),
208
+ step_index: raw["step_index"] ?? 0,
209
+ verified: raw["verified"] === true,
210
+ fsm_state: raw["fsm_state"] ?? AgentFSMState.Done,
211
+ ...(raw["proof_cid"] !== undefined ? { proof_cid: String(raw["proof_cid"]) } : {}),
212
+ };
213
+ }
214
+ function _normalizeCheckpointState(raw) {
215
+ return {
216
+ session_id: String(raw["session_id"] ?? ""),
217
+ step_index: raw["step_index"] ?? 0,
218
+ state_cid: String(raw["state_cid"] ?? ""),
219
+ fsm_state: raw["fsm_state"] ?? AgentFSMState.Idle,
220
+ created_at: String(raw["created_at"] ?? ""),
221
+ };
222
+ }
223
+ //# sourceMappingURL=durable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable.js","sourceRoot":"","sources":["../src/durable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQ/D,8EAA8E;AAC9E,uEAAuE;AACvE,8EAA8E;AAE9E,MAAM,CAAN,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,KAAb,aAAa,QAWxB;AAsED,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E,MAAM,sBAAsB,GAAG,6BAA6B,CAAC;AAE7D,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E;;;;;;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nD,UAAU,EAAG,GAAG,CAAC,YAAY,CAAY,IAAI,CAAC;QAC9C,QAAQ,EAAE,GAAG,CAAC,UAAU,CAAC,KAAK,IAAI;QAClC,SAAS,EAAG,GAAG,CAAC,WAAW,CAAmB,IAAI,aAAa,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"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @dingdawg/sdk — Public API
3
+ *
4
+ * Re-exports everything a partner integration needs:
5
+ * - DingDawgClient (main class)
6
+ * - DurableDingDawgClient (crash-proof execution — DDAG v1)
7
+ * - DingDawgApiError (typed error)
8
+ * - All TypeScript interfaces and types
9
+ */
10
+ export { DingDawgClient, DingDawgApiError } from "./client.js";
11
+ export type { DingDawgClientOptions, AgentType, AgentStatus, AgentBranding, CreateAgentOptions, AgentRecord, SendMessageOptions, TriggerResponse, BillingLineItem, MonthlyBillingSummary, BillingSummary, PaginatedList, ApiErrorBody, DingDawgApiErrorDetails, } from "./types.js";
12
+ export { DurableDingDawgClient, AgentFSMState } from "./durable.js";
13
+ export type { CheckpointState, AgentSoul, DurableSession, DurableResponse, } from "./durable.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/D,YAAY,EAEV,qBAAqB,EAErB,SAAS,EACT,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,WAAW,EAEX,kBAAkB,EAClB,eAAe,EAEf,eAAe,EACf,qBAAqB,EACrB,cAAc,EAEd,aAAa,EACb,YAAY,EACZ,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEpE,YAAY,EACV,eAAe,EACf,SAAS,EACT,cAAc,EACd,eAAe,GAChB,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @dingdawg/sdk — Public API
3
+ *
4
+ * Re-exports everything a partner integration needs:
5
+ * - DingDawgClient (main class)
6
+ * - DurableDingDawgClient (crash-proof execution — DDAG v1)
7
+ * - DingDawgApiError (typed error)
8
+ * - All TypeScript interfaces and types
9
+ */
10
+ export { DingDawgClient, DingDawgApiError } from "./client.js";
11
+ // DDAG v1 — Durable execution SDK
12
+ export { DurableDingDawgClient, AgentFSMState } from "./durable.js";
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAwB/D,kCAAkC;AAClC,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @dingdawg/sdk — TypeScript types for all request and response shapes.
3
+ *
4
+ * All interfaces are exported so partner integrations can type their own code.
5
+ * Zero runtime imports — types are erased at compile time.
6
+ */
7
+ /** Options passed to the DingDawgClient constructor. */
8
+ export interface DingDawgClientOptions {
9
+ /** API key issued via the DingDawg dashboard or partner program. */
10
+ apiKey: string;
11
+ /** Base URL of the DingDawg API. Defaults to https://api.dingdawg.com */
12
+ baseUrl?: string;
13
+ }
14
+ /** Structured API error returned by the DingDawg backend. */
15
+ export interface ApiErrorBody {
16
+ detail?: string;
17
+ message?: string;
18
+ code?: string;
19
+ [key: string]: unknown;
20
+ }
21
+ /** Error thrown when an API call fails with a non-2xx response. */
22
+ export interface DingDawgApiErrorDetails {
23
+ /** HTTP status code (e.g. 401, 422, 500). */
24
+ status: number;
25
+ /** Parsed error body from the API, if available. */
26
+ body: ApiErrorBody | null;
27
+ }
28
+ /** Agent type identifier. */
29
+ export type AgentType = "personal" | "business" | "b2b" | "a2a" | "compliance" | "enterprise" | "health" | "gaming";
30
+ /** Agent status values. */
31
+ export type AgentStatus = "active" | "inactive" | "suspended";
32
+ /** Branding configuration for an agent. */
33
+ export interface AgentBranding {
34
+ /** Hex color string (e.g. "#7C3AED"). */
35
+ primaryColor?: string;
36
+ /** Public URL to an avatar image. */
37
+ avatarUrl?: string;
38
+ }
39
+ /** Options for creating a new agent. */
40
+ export interface CreateAgentOptions {
41
+ /** Display name of the agent. */
42
+ name: string;
43
+ /** Unique handle (without @). Must be 3-32 alphanumeric + underscores. */
44
+ handle: string;
45
+ /** Agent type selector. Defaults to "business". */
46
+ agentType?: AgentType;
47
+ /** Sector / industry label (e.g. "restaurant", "gaming", "legal"). */
48
+ industry?: string;
49
+ /** System prompt / constitution text. */
50
+ systemPrompt?: string;
51
+ /** Template ID to initialise the agent from. */
52
+ templateId?: string;
53
+ /** Branding overrides. */
54
+ branding?: AgentBranding;
55
+ }
56
+ /** A deployed agent record returned by the API. */
57
+ export interface AgentRecord {
58
+ id: string;
59
+ handle: string;
60
+ name: string;
61
+ agentType: AgentType;
62
+ industry: string | null;
63
+ status: AgentStatus;
64
+ createdAt: string;
65
+ updatedAt: string;
66
+ /** Parsed branding config. Present on GET /agents/:id, may be absent in list. */
67
+ branding?: AgentBranding;
68
+ }
69
+ /** Options for sending a message to an agent via the trigger endpoint. */
70
+ export interface SendMessageOptions {
71
+ /** The message text to deliver. */
72
+ message: string;
73
+ /** User / customer identifier (for conversation continuity). */
74
+ userId?: string;
75
+ /** Session identifier to continue an existing conversation. */
76
+ sessionId?: string;
77
+ /** Arbitrary metadata forwarded to the agent runtime. */
78
+ metadata?: Record<string, unknown>;
79
+ }
80
+ /** Response returned after triggering an agent. */
81
+ export interface TriggerResponse {
82
+ /** The agent's reply text. */
83
+ reply: string;
84
+ /** Session ID (reuse to continue the conversation). */
85
+ sessionId: string;
86
+ /** ISO-8601 timestamp of the response. */
87
+ timestamp: string;
88
+ /** Model / provider used to generate the reply. */
89
+ model?: string;
90
+ /** True when the agent queued the message for async processing. */
91
+ queued?: boolean;
92
+ }
93
+ /** Line item in a billing period. */
94
+ export interface BillingLineItem {
95
+ /** Action / skill name (e.g. "crm_lookup", "email_send"). */
96
+ action: string;
97
+ /** Number of times this action was executed. */
98
+ count: number;
99
+ /** Cost in USD cents. */
100
+ costCents: number;
101
+ }
102
+ /** Billing summary for a single month. */
103
+ export interface MonthlyBillingSummary {
104
+ /** ISO-8601 month string (e.g. "2026-03"). */
105
+ month: string;
106
+ /** Total actions executed. */
107
+ totalActions: number;
108
+ /** Total charges in USD cents. */
109
+ totalCents: number;
110
+ /** Number of free-tier actions remaining (50 free/month). */
111
+ freeActionsRemaining: number;
112
+ /** Breakdown by action type. */
113
+ lineItems: BillingLineItem[];
114
+ }
115
+ /** Aggregate billing summary across all time. */
116
+ export interface BillingSummary {
117
+ /** Total lifetime actions. */
118
+ totalActions: number;
119
+ /** Total lifetime spend in USD cents. */
120
+ totalCents: number;
121
+ /** Current month billing. */
122
+ currentMonth: MonthlyBillingSummary;
123
+ /** Stripe customer ID if billing is set up. */
124
+ stripeCustomerId?: string;
125
+ }
126
+ /** Generic paginated list wrapper. */
127
+ export interface PaginatedList<T> {
128
+ items: T[];
129
+ total: number;
130
+ limit: number;
131
+ offset: number;
132
+ }
133
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,wDAAwD;AACxD,MAAM,WAAW,qBAAqB;IACpC,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAMD,6DAA6D;AAC7D,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,mEAAmE;AACnE,MAAM,WAAW,uBAAuB;IACtC,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;CAC3B;AAMD,6BAA6B;AAC7B,MAAM,MAAM,SAAS,GACjB,UAAU,GACV,UAAU,GACV,KAAK,GACL,KAAK,GACL,YAAY,GACZ,YAAY,GACZ,QAAQ,GACR,QAAQ,CAAC;AAEb,2BAA2B;AAC3B,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,CAAC;AAE9D,2CAA2C;AAC3C,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wCAAwC;AACxC,MAAM,WAAW,kBAAkB;IACjC,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb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,WAAW,eAAe;IAC9B,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACpC,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gCAAgC;IAChC,SAAS,EAAE,eAAe,EAAE,CAAC;CAC9B;AAED,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC7B,8BAA8B;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,YAAY,EAAE,qBAAqB,CAAC;IACpC,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAMD,sCAAsC;AACtC,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB"}
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @dingdawg/sdk — TypeScript types for all request and response shapes.
3
+ *
4
+ * All interfaces are exported so partner integrations can type their own code.
5
+ * Zero runtime imports — types are erased at compile time.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@dingdawg/sdk",
3
+ "version": "2.0.0",
4
+ "description": "DingDawg Agent SDK \u2014 durable AI agents with crash-proof exactly-once execution + IPFS checkpoints",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "test": "node --experimental-vm-modules node_modules/.bin/jest --testPathPattern='src/__tests__'",
21
+ "typecheck": "tsc --noEmit"
22
+ },
23
+ "keywords": [
24
+ "ai",
25
+ "agent",
26
+ "sdk",
27
+ "dingdawg",
28
+ "mcp",
29
+ "a2a",
30
+ "llm",
31
+ "b2b2c"
32
+ ],
33
+ "license": "MIT",
34
+ "author": "Innovative Systems Global LLC",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/dingdawg/sdk"
38
+ },
39
+ "files": [
40
+ "dist/",
41
+ "src/",
42
+ "README.md"
43
+ ],
44
+ "devDependencies": {
45
+ "@types/jest": "^29.5.14",
46
+ "@types/node": "^20.19.37",
47
+ "jest": "^29.7.0",
48
+ "ts-jest": "^29.4.6",
49
+ "typescript": "^5.9.3"
50
+ },
51
+ "jest": {
52
+ "preset": "ts-jest",
53
+ "testEnvironment": "node",
54
+ "extensionsToTreatAsEsm": [
55
+ ".ts"
56
+ ],
57
+ "moduleNameMapper": {
58
+ "^(\\.{1,2}/.*)\\.js$": "$1"
59
+ },
60
+ "transform": {
61
+ "^.+\\.tsx?$": [
62
+ "ts-jest",
63
+ {
64
+ "useESM": true
65
+ }
66
+ ]
67
+ }
68
+ }
69
+ }