@ziggy-ai/client-sdk 0.1.0 → 0.1.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.
Files changed (46) hide show
  1. package/dist/__tests__/analytics.test.d.ts +2 -0
  2. package/dist/__tests__/analytics.test.d.ts.map +1 -0
  3. package/dist/__tests__/app-client.test.d.ts +2 -0
  4. package/dist/__tests__/app-client.test.d.ts.map +1 -0
  5. package/dist/__tests__/callback-handler.test.d.ts +2 -0
  6. package/dist/__tests__/callback-handler.test.d.ts.map +1 -0
  7. package/dist/__tests__/connection.test.d.ts +2 -0
  8. package/dist/__tests__/connection.test.d.ts.map +1 -0
  9. package/dist/__tests__/context.test.d.ts +2 -0
  10. package/dist/__tests__/context.test.d.ts.map +1 -0
  11. package/dist/__tests__/errors.test.d.ts +2 -0
  12. package/dist/__tests__/errors.test.d.ts.map +1 -0
  13. package/dist/__tests__/stream-parser.test.d.ts +2 -0
  14. package/dist/__tests__/stream-parser.test.d.ts.map +1 -0
  15. package/dist/analytics.d.ts +22 -0
  16. package/dist/analytics.d.ts.map +1 -0
  17. package/dist/app.d.ts +60 -0
  18. package/dist/app.d.ts.map +1 -0
  19. package/dist/auth.d.ts +9 -0
  20. package/dist/auth.d.ts.map +1 -0
  21. package/dist/callback-handler.d.ts +64 -0
  22. package/dist/callback-handler.d.ts.map +1 -0
  23. package/dist/chat.d.ts +38 -0
  24. package/dist/chat.d.ts.map +1 -0
  25. package/dist/connection.d.ts +19 -0
  26. package/dist/connection.d.ts.map +1 -0
  27. package/dist/context.d.ts +35 -0
  28. package/dist/context.d.ts.map +1 -0
  29. package/dist/errors.d.ts +16 -0
  30. package/dist/errors.d.ts.map +1 -0
  31. package/dist/feedback.d.ts +29 -0
  32. package/dist/feedback.d.ts.map +1 -0
  33. package/dist/index.d.ts +45 -828
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +48 -15
  36. package/dist/quests.d.ts +38 -0
  37. package/dist/quests.d.ts.map +1 -0
  38. package/dist/session.d.ts +28 -0
  39. package/dist/session.d.ts.map +1 -0
  40. package/dist/stream-parser.d.ts +24 -0
  41. package/dist/stream-parser.d.ts.map +1 -0
  42. package/dist/tools.d.ts +22 -0
  43. package/dist/tools.d.ts.map +1 -0
  44. package/dist/types.d.ts +533 -0
  45. package/dist/types.d.ts.map +1 -0
  46. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,qBAAa,WAAW;IACtB,wBAAwB;IACxB,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,sBAAsB;IACtB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,6BAA6B;IAC7B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,qBAAqB;IACrB,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2B,EAC3B,4BAA4B,EAC5B,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
- // src/types.ts
1
+ // src/types.js
2
2
  var ZiggyError = class extends Error {
3
+ status;
4
+ code;
5
+ details;
3
6
  constructor(message, status, code, details) {
4
7
  super(message);
5
8
  this.status = status;
@@ -9,6 +12,7 @@ var ZiggyError = class extends Error {
9
12
  }
10
13
  };
11
14
  var ZiggyConnectionError = class extends ZiggyError {
15
+ retryable;
12
16
  constructor(message, retryable = true) {
13
17
  super(message, 0, "CONNECTION_ERROR");
14
18
  this.retryable = retryable;
@@ -16,7 +20,7 @@ var ZiggyConnectionError = class extends ZiggyError {
16
20
  }
17
21
  };
18
22
 
19
- // src/auth.ts
23
+ // src/auth.js
20
24
  function buildHeaders(config, extra) {
21
25
  return {
22
26
  "Content-Type": "application/json",
@@ -25,7 +29,7 @@ function buildHeaders(config, extra) {
25
29
  };
26
30
  }
27
31
 
28
- // src/connection.ts
32
+ // src/connection.js
29
33
  var Connection = class {
30
34
  config;
31
35
  constructor(config) {
@@ -59,14 +63,12 @@ var Connection = class {
59
63
  }
60
64
  return await response.json();
61
65
  } catch (error) {
62
- if (error instanceof ZiggyError) throw error;
66
+ if (error instanceof ZiggyError)
67
+ throw error;
63
68
  if (error instanceof DOMException && error.name === "AbortError") {
64
69
  throw new ZiggyConnectionError("Request timed out", true);
65
70
  }
66
- throw new ZiggyConnectionError(
67
- error instanceof Error ? error.message : "Connection failed",
68
- true
69
- );
71
+ throw new ZiggyConnectionError(error instanceof Error ? error.message : "Connection failed", true);
70
72
  } finally {
71
73
  clearTimeout(timer);
72
74
  }
@@ -95,11 +97,9 @@ var Connection = class {
95
97
  }
96
98
  return response;
97
99
  } catch (error) {
98
- if (error instanceof ZiggyError) throw error;
99
- throw new ZiggyConnectionError(
100
- error instanceof Error ? error.message : "Connection failed",
101
- true
102
- );
100
+ if (error instanceof ZiggyError)
101
+ throw error;
102
+ throw new ZiggyConnectionError(error instanceof Error ? error.message : "Connection failed", true);
103
103
  }
104
104
  }
105
105
  };
@@ -261,6 +261,39 @@ var ChatClient = class {
261
261
  yield event;
262
262
  }
263
263
  }
264
+ /**
265
+ * Execute a support action by ID (non-streaming).
266
+ * Actions from trigger buttons and quick actions go through this method.
267
+ */
268
+ async action(request) {
269
+ const sessionId = this.sessionManager.sessionId;
270
+ if (!sessionId) throw new Error("No active session");
271
+ if (!this.userId) throw new Error("No user ID set");
272
+ return this.connection.request("POST", "/chat/action", {
273
+ sessionId,
274
+ userId: this.userId,
275
+ ...request
276
+ });
277
+ }
278
+ /**
279
+ * Execute a support action by ID (streaming).
280
+ * Returns an async iterable of structured stream events.
281
+ */
282
+ async *actionStream(request) {
283
+ const sessionId = this.sessionManager.sessionId;
284
+ if (!sessionId) throw new Error("No active session");
285
+ if (!this.userId) throw new Error("No user ID set");
286
+ const response = await this.connection.streamRequest("POST", "/chat/action/stream", {
287
+ sessionId,
288
+ userId: this.userId,
289
+ ...request
290
+ });
291
+ const tracker = new SequenceTracker();
292
+ for await (const event of parseNdjsonStream(response)) {
293
+ tracker.update(event);
294
+ yield event;
295
+ }
296
+ }
264
297
  /**
265
298
  * Resume an interrupted stream from a given sequence number.
266
299
  */
@@ -545,7 +578,7 @@ var AnalyticsClient = class {
545
578
  }
546
579
  };
547
580
 
548
- // src/app.ts
581
+ // src/app.js
549
582
  var AppClient = class {
550
583
  connection;
551
584
  constructor(connection) {
@@ -624,7 +657,7 @@ var AppClient = class {
624
657
  }
625
658
  };
626
659
 
627
- // src/callback-handler.ts
660
+ // src/callback-handler.js
628
661
  var CallbackHandler = class {
629
662
  handlers = /* @__PURE__ */ new Map();
630
663
  /**
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Quest tracking module.
3
+ */
4
+ import type { Connection } from './connection.js';
5
+ import type { Quest, StreamEvent, CreateQuestRequest, UpdateQuestRequest, UpdateQuestStepRequest } from './types.js';
6
+ export declare class QuestClient {
7
+ private connection;
8
+ constructor(connection: Connection);
9
+ /**
10
+ * Create a new quest.
11
+ */
12
+ create(request: CreateQuestRequest): Promise<Quest>;
13
+ /**
14
+ * Get quest status.
15
+ */
16
+ get(questId: string): Promise<Quest>;
17
+ /**
18
+ * Update quest status, context, or result.
19
+ */
20
+ update(questId: string, updates: UpdateQuestRequest): Promise<Quest>;
21
+ /**
22
+ * Update a specific quest step.
23
+ */
24
+ updateStep(questId: string, stepId: string, updates: UpdateQuestStepRequest): Promise<Quest>;
25
+ /**
26
+ * Cancel a quest.
27
+ */
28
+ cancel(questId: string): Promise<Quest>;
29
+ /**
30
+ * List quests for a session.
31
+ */
32
+ list(sessionId: string): Promise<Quest[]>;
33
+ /**
34
+ * Stream quest updates with optional resumption.
35
+ */
36
+ stream(questId: string, afterSeq?: number): AsyncGenerator<StreamEvent, void, undefined>;
37
+ }
38
+ //# sourceMappingURL=quests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quests.d.ts","sourceRoot":"","sources":["../src/quests.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAGpB,qBAAa,WAAW;IACtB,OAAO,CAAC,UAAU,CAAa;gBAEnB,UAAU,EAAE,UAAU;IAIlC;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,KAAK,CAAC;IASzD;;OAEG;IACG,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAK1C;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,KAAK,CAAC;IAS1E;;OAEG;IACG,UAAU,CACd,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,KAAK,CAAC;IASjB;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAI7C;;OAEG;IACG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAQ/C;;OAEG;IACI,MAAM,CACX,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,GAChB,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,SAAS,CAAC;CAWhD"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Session management module.
3
+ */
4
+ import type { Connection } from './connection.js';
5
+ import type { ZiggyClientConfig, CreateSessionRequest, SessionResponse, ContextPushRequest, ContextPushResponse } from './types.js';
6
+ export declare class SessionManager {
7
+ private connection;
8
+ private appId;
9
+ private _sessionId;
10
+ private _conversationId;
11
+ constructor(connection: Connection, config: ZiggyClientConfig);
12
+ get sessionId(): string | null;
13
+ get conversationId(): string | null;
14
+ /**
15
+ * Create or resume a session.
16
+ * Replaces 4 separate calls (brand + context + triggers + actions).
17
+ */
18
+ create(request: CreateSessionRequest): Promise<SessionResponse>;
19
+ /**
20
+ * Push context update (delta merge) with piggybacked trigger evaluation.
21
+ */
22
+ pushContext(userId: string, context: Record<string, unknown>, events?: ContextPushRequest['events']): Promise<ContextPushResponse>;
23
+ /**
24
+ * End the current session.
25
+ */
26
+ destroy(): Promise<void>;
27
+ }
28
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,qBAAa,cAAc;IACzB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,eAAe,CAAuB;gBAElC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,iBAAiB;IAK7D,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAE7B;IAED,IAAI,cAAc,IAAI,MAAM,GAAG,IAAI,CAElC;IAED;;;OAGG;IACG,MAAM,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC;IAarE;;OAEG;IACG,WAAW,CACf,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,MAAM,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GACpC,OAAO,CAAC,mBAAmB,CAAC;IAY/B;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAO/B"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * NDJSON Stream Parser
3
+ *
4
+ * Parses newline-delimited JSON streams with sequence tracking
5
+ * and reconnection support.
6
+ */
7
+ import type { StreamEvent } from './types.js';
8
+ /**
9
+ * Parse an ndjson Response body into an async iterable of StreamEvents.
10
+ * Tracks the last seen sequence number for reconnection.
11
+ */
12
+ export declare function parseNdjsonStream(response: Response): AsyncGenerator<StreamEvent, void, undefined>;
13
+ /**
14
+ * Track last seen sequence number from a stream.
15
+ */
16
+ export declare class SequenceTracker {
17
+ private _lastSeq;
18
+ private _streamId;
19
+ get lastSeq(): number;
20
+ get streamId(): string | null;
21
+ update(event: StreamEvent): void;
22
+ reset(): void;
23
+ }
24
+ //# sourceMappingURL=stream-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-parser.d.ts","sourceRoot":"","sources":["../src/stream-parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;GAGG;AACH,wBAAuB,iBAAiB,CACtC,QAAQ,EAAE,QAAQ,GACjB,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,SAAS,CAAC,CA8C9C;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,SAAS,CAAuB;IAExC,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,QAAQ,IAAI,MAAM,GAAG,IAAI,CAE5B;IAED,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAShC,KAAK,IAAI,IAAI;CAId"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Tool invocation module.
3
+ */
4
+ import type { Connection } from './connection.js';
5
+ import type { SessionManager } from './session.js';
6
+ import type { ToolInvokeResponse, StreamEvent } from './types.js';
7
+ export declare class ToolClient {
8
+ private connection;
9
+ private sessionManager;
10
+ private userId;
11
+ constructor(connection: Connection, sessionManager: SessionManager);
12
+ setUserId(userId: string): void;
13
+ /**
14
+ * Invoke a tool (non-streaming).
15
+ */
16
+ invoke(toolId: string, input?: Record<string, unknown>): Promise<ToolInvokeResponse>;
17
+ /**
18
+ * Invoke a tool with streaming (for long-running tools).
19
+ */
20
+ invokeStream(toolId: string, input?: Record<string, unknown>): AsyncGenerator<StreamEvent, void, undefined>;
21
+ }
22
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGlE,qBAAa,UAAU;IACrB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,MAAM,CAAuB;gBAEzB,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc;IAKlE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAa1F;;OAEG;IACI,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,SAAS,CAAC;CAgBnH"}