@sixb/client 0.0.1

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 (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +193 -0
  3. package/dist/actions.d.ts +61 -0
  4. package/dist/actions.d.ts.map +1 -0
  5. package/dist/agent-streams.d.ts +72 -0
  6. package/dist/agent-streams.d.ts.map +1 -0
  7. package/dist/api.d.ts +54 -0
  8. package/dist/api.d.ts.map +1 -0
  9. package/dist/browser.d.ts +41 -0
  10. package/dist/browser.d.ts.map +1 -0
  11. package/dist/browser.js +174 -0
  12. package/dist/browser.js.map +10 -0
  13. package/dist/chunk-05yz32g0.js +240 -0
  14. package/dist/chunk-05yz32g0.js.map +10 -0
  15. package/dist/chunk-2d7239yx.js +1181 -0
  16. package/dist/chunk-2d7239yx.js.map +17 -0
  17. package/dist/chunk-3g6ad4jc.js +147 -0
  18. package/dist/chunk-3g6ad4jc.js.map +10 -0
  19. package/dist/chunk-aw8rcsq3.js +145 -0
  20. package/dist/chunk-aw8rcsq3.js.map +10 -0
  21. package/dist/chunk-ctsdm59b.js +1477 -0
  22. package/dist/chunk-ctsdm59b.js.map +19 -0
  23. package/dist/chunk-fxrh83wy.js +180 -0
  24. package/dist/chunk-fxrh83wy.js.map +12 -0
  25. package/dist/chunk-pey7nh0d.js +123 -0
  26. package/dist/chunk-pey7nh0d.js.map +10 -0
  27. package/dist/chunk-trpg18dp.js +3 -0
  28. package/dist/chunk-trpg18dp.js.map +9 -0
  29. package/dist/events-builder.d.ts +218 -0
  30. package/dist/events-builder.d.ts.map +1 -0
  31. package/dist/events-hooks.d.ts +50 -0
  32. package/dist/events-hooks.d.ts.map +1 -0
  33. package/dist/events-model.d.ts +12 -0
  34. package/dist/events-model.d.ts.map +1 -0
  35. package/dist/events-provider.d.ts +56 -0
  36. package/dist/events-provider.d.ts.map +1 -0
  37. package/dist/events-transport.d.ts +62 -0
  38. package/dist/events-transport.d.ts.map +1 -0
  39. package/dist/events.d.ts +5 -0
  40. package/dist/events.d.ts.map +1 -0
  41. package/dist/file.d.ts +27 -0
  42. package/dist/file.d.ts.map +1 -0
  43. package/dist/generated/@tanstack/react-query.gen.d.ts +17064 -0
  44. package/dist/generated/@tanstack/react-query.gen.d.ts.map +1 -0
  45. package/dist/generated/client/client.gen.d.ts +3 -0
  46. package/dist/generated/client/client.gen.d.ts.map +1 -0
  47. package/dist/generated/client/index.d.ts +9 -0
  48. package/dist/generated/client/index.d.ts.map +1 -0
  49. package/dist/generated/client/types.gen.d.ts +118 -0
  50. package/dist/generated/client/types.gen.d.ts.map +1 -0
  51. package/dist/generated/client/utils.gen.d.ts +34 -0
  52. package/dist/generated/client/utils.gen.d.ts.map +1 -0
  53. package/dist/generated/client.gen.d.ts +13 -0
  54. package/dist/generated/client.gen.d.ts.map +1 -0
  55. package/dist/generated/core/auth.gen.d.ts +19 -0
  56. package/dist/generated/core/auth.gen.d.ts.map +1 -0
  57. package/dist/generated/core/bodySerializer.gen.d.ts +26 -0
  58. package/dist/generated/core/bodySerializer.gen.d.ts.map +1 -0
  59. package/dist/generated/core/params.gen.d.ts +44 -0
  60. package/dist/generated/core/params.gen.d.ts.map +1 -0
  61. package/dist/generated/core/pathSerializer.gen.d.ts +34 -0
  62. package/dist/generated/core/pathSerializer.gen.d.ts.map +1 -0
  63. package/dist/generated/core/queryKeySerializer.gen.d.ts +19 -0
  64. package/dist/generated/core/queryKeySerializer.gen.d.ts.map +1 -0
  65. package/dist/generated/core/serverSentEvents.gen.d.ts +72 -0
  66. package/dist/generated/core/serverSentEvents.gen.d.ts.map +1 -0
  67. package/dist/generated/core/types.gen.d.ts +79 -0
  68. package/dist/generated/core/types.gen.d.ts.map +1 -0
  69. package/dist/generated/core/utils.gen.d.ts +20 -0
  70. package/dist/generated/core/utils.gen.d.ts.map +1 -0
  71. package/dist/generated/index.d.ts +3 -0
  72. package/dist/generated/index.d.ts.map +1 -0
  73. package/dist/generated/sdk.gen.d.ts +464 -0
  74. package/dist/generated/sdk.gen.d.ts.map +1 -0
  75. package/dist/generated/types.gen.d.ts +7672 -0
  76. package/dist/generated/types.gen.d.ts.map +1 -0
  77. package/dist/hooks.d.ts +123 -0
  78. package/dist/hooks.d.ts.map +1 -0
  79. package/dist/hooks.js +3179 -0
  80. package/dist/hooks.js.map +16 -0
  81. package/dist/index.d.ts +11 -0
  82. package/dist/index.d.ts.map +1 -0
  83. package/dist/index.js +329 -0
  84. package/dist/index.js.map +9 -0
  85. package/dist/logs-builder.d.ts +59 -0
  86. package/dist/logs-builder.d.ts.map +1 -0
  87. package/dist/logs-hooks.d.ts +30 -0
  88. package/dist/logs-hooks.d.ts.map +1 -0
  89. package/dist/logs-transport.d.ts +38 -0
  90. package/dist/logs-transport.d.ts.map +1 -0
  91. package/dist/logs.d.ts +7 -0
  92. package/dist/logs.d.ts.map +1 -0
  93. package/dist/logs.js +22 -0
  94. package/dist/logs.js.map +9 -0
  95. package/dist/models.d.ts +126 -0
  96. package/dist/models.d.ts.map +1 -0
  97. package/dist/models.js +252 -0
  98. package/dist/models.js.map +9 -0
  99. package/dist/query-hooks.d.ts +365 -0
  100. package/dist/query-hooks.d.ts.map +1 -0
  101. package/dist/query.d.ts +27 -0
  102. package/dist/query.d.ts.map +1 -0
  103. package/dist/query.js +15 -0
  104. package/dist/query.js.map +9 -0
  105. package/dist/sha256.d.ts +15 -0
  106. package/dist/sha256.d.ts.map +1 -0
  107. package/dist/telemetry-events.d.ts +25 -0
  108. package/dist/telemetry-events.d.ts.map +1 -0
  109. package/dist/tsconfig.json +5 -0
  110. package/dist/useAgentRunStream.d.ts +21 -0
  111. package/dist/useAgentRunStream.d.ts.map +1 -0
  112. package/dist/ws-socket.d.ts +45 -0
  113. package/dist/ws-socket.d.ts.map +1 -0
  114. package/package.json +105 -0
  115. package/src/actions.ts +310 -0
  116. package/src/agent-streams.ts +275 -0
  117. package/src/api.ts +229 -0
  118. package/src/browser.ts +267 -0
  119. package/src/events-builder.ts +735 -0
  120. package/src/events-hooks.ts +233 -0
  121. package/src/events-model.ts +40 -0
  122. package/src/events-provider.ts +161 -0
  123. package/src/events-transport.ts +193 -0
  124. package/src/events.ts +6 -0
  125. package/src/file.ts +367 -0
  126. package/src/generated/@tanstack/react-query.gen.ts +3876 -0
  127. package/src/generated/client/client.gen.ts +288 -0
  128. package/src/generated/client/index.ts +25 -0
  129. package/src/generated/client/types.gen.ts +209 -0
  130. package/src/generated/client/utils.gen.ts +316 -0
  131. package/src/generated/client.gen.ts +18 -0
  132. package/src/generated/core/auth.gen.ts +41 -0
  133. package/src/generated/core/bodySerializer.gen.ts +84 -0
  134. package/src/generated/core/params.gen.ts +169 -0
  135. package/src/generated/core/pathSerializer.gen.ts +171 -0
  136. package/src/generated/core/queryKeySerializer.gen.ts +117 -0
  137. package/src/generated/core/serverSentEvents.gen.ts +243 -0
  138. package/src/generated/core/types.gen.ts +104 -0
  139. package/src/generated/core/utils.gen.ts +140 -0
  140. package/src/generated/index.ts +672 -0
  141. package/src/generated/sdk.gen.ts +1984 -0
  142. package/src/generated/types.gen.ts +9049 -0
  143. package/src/hooks.ts +404 -0
  144. package/src/index.ts +18 -0
  145. package/src/logs-builder.ts +171 -0
  146. package/src/logs-hooks.ts +112 -0
  147. package/src/logs-transport.ts +112 -0
  148. package/src/logs.ts +15 -0
  149. package/src/models.ts +420 -0
  150. package/src/query-hooks.ts +1021 -0
  151. package/src/query.ts +175 -0
  152. package/src/sha256.ts +159 -0
  153. package/src/telemetry-events.ts +71 -0
  154. package/src/useAgentRunStream.ts +62 -0
  155. package/src/ws-socket.ts +202 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,KAAK,EAEV,kBAAkB,EAClB,mBAAmB,EAKnB,4BAA4B,EAC7B,MAAM,kBAAkB,CAAA;AAGzB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,uBAAuB,CAAA;AAE9B,YAAY,EAAE,gBAAgB,EAAE,CAAA;AAEhC,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,CAAA;gBAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,SAAS,gBAAgB,EAAO;CAKtE;AAED,MAAM,WAAW,sBAAsB;IACrC,sFAAsF;IACtF,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAKD,KAAK,2BAA2B,CAAC,WAAW,SAAS,4BAA4B,IAC7E,WAAW,GACX,OAAO,CAAC,iBAAiB,CAAC,MAAM,iBAAiB,CAAC,EAAE,4BAA4B,CAAC,CAAA;AAErF,MAAM,MAAM,wBAAwB,CAAC,WAAW,SAAS,4BAA4B,IACnF,kBAAkB,CAAC,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC,CAAA;AAExF,wBAAgB,OAAO,CAAC,WAAW,SAAS,4BAA4B,EACtE,UAAU,EAAE,WAAW,EACvB,OAAO,CAAC,EAAE,sBAAsB,GAC/B;IAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC,WAAW,CAAC,CAAA;CAAE,CAQxD;AAED,wBAAgB,uBAAuB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAoD5E"}
package/dist/query.js ADDED
@@ -0,0 +1,15 @@
1
+ // @bun
2
+ import {
3
+ SixbQueryError,
4
+ createHttpQueryExecutor,
5
+ objects
6
+ } from "./chunk-pey7nh0d.js";
7
+ import"./chunk-aw8rcsq3.js";
8
+ import"./chunk-ctsdm59b.js";
9
+ export {
10
+ objects,
11
+ createHttpQueryExecutor,
12
+ SixbQueryError
13
+ };
14
+
15
+ //# debugId=B73068822CC17C4E64756E2164756E21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "B73068822CC17C4E64756E2164756E21",
8
+ "names": []
9
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Zero-dependency streaming SHA-256 (FIPS 180-4).
3
+ *
4
+ * `SubtleCrypto.digest` has no incremental API, so hashing a file through it
5
+ * means buffering the whole file in memory before hashing. This implementation
6
+ * absorbs data one chunk at a time, keeping peak memory bounded to a single
7
+ * slice — letting the client hash multi-gigabyte uploads without OOM. Output is
8
+ * byte-identical to `crypto.subtle.digest("SHA-256", ...)`.
9
+ */
10
+ /**
11
+ * Streams `file` through SHA-256 in `chunkBytes`-sized slices and returns the
12
+ * `sha256:<hex>` digest used for content-addressed blob identity.
13
+ */
14
+ export declare function computeStreamingBlobDigest(file: Blob, chunkBytes?: number): Promise<`sha256:${string}`>;
15
+ //# sourceMappingURL=sha256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwIH;;;GAGG;AACH,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,IAAI,EACV,UAAU,SAAkB,GAC3B,OAAO,CAAC,UAAU,MAAM,EAAE,CAAC,CAO7B"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Telemetry overlay model (exported via `@sixb/client` and `/hooks`).
3
+ *
4
+ * A normalized "latest value" shape derived from a `telemetry.appended` event,
5
+ * shared by `useLatest`/`useLatestByObject` and the apps that render live
6
+ * telemetry. Previously copy-pasted byte-for-byte across every app's
7
+ * `lib/telemetryEvents.ts`; it lives here once.
8
+ */
9
+ import type { SixbEventOfType } from "./events-model";
10
+ export interface TelemetryUpdate {
11
+ readonly type: "telemetryUpdate";
12
+ readonly projectId: string;
13
+ readonly projectName: string;
14
+ readonly objectTypeId: string;
15
+ readonly objectId: string;
16
+ readonly propertyId: string;
17
+ readonly value: number | string | boolean;
18
+ readonly timestamp: string;
19
+ readonly quality: "good" | "uncertain" | "bad";
20
+ readonly unit?: string;
21
+ }
22
+ export declare function telemetryUpdateFromEvent(event: SixbEventOfType<"telemetry.appended">): TelemetryUpdate;
23
+ export declare function objectIdAliases(objectId: string): readonly string[];
24
+ export declare function telemetryUpdateKey(projectId: string, objectId: string, propertyId: string): string;
25
+ //# sourceMappingURL=telemetry-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-events.d.ts","sourceRoot":"","sources":["../src/telemetry-events.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAGrD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAA;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,KAAK,CAAA;IAC9C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,eAAe,CAAC,oBAAoB,CAAC,GAC3C,eAAe,CAajB;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAKnE;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,MAAM,CAER"}
@@ -0,0 +1,5 @@
1
+ // Written by scripts/build-package.ts, and published on purpose.
2
+ // Bun applies the nearest tsconfig paths map to every import it resolves, node_modules
3
+ // included. An empty map here keeps a consumer's aliases from sending a module in this
4
+ // directory back into a second copy of its own source.
5
+ { "compilerOptions": { "paths": {} } }
@@ -0,0 +1,21 @@
1
+ import { type AgentRunSnapshot, type AgentRunStreamEvent } from "./agent-streams";
2
+ import type { ReconnectingSocketState } from "./ws-socket";
3
+ export interface UseAgentRunStreamOptions {
4
+ readonly runId?: string | null;
5
+ readonly afterCursor?: string;
6
+ readonly enabled?: boolean;
7
+ readonly reconnect?: boolean;
8
+ readonly reconnectDelayMs?: number;
9
+ readonly onEvent?: (event: AgentRunStreamEvent, cursor: string) => void;
10
+ readonly onRunSnapshot?: (run: AgentRunSnapshot) => void;
11
+ readonly onError?: (message: string) => void;
12
+ }
13
+ export type UseAgentRunStreamResult = ReconnectingSocketState;
14
+ /**
15
+ * React binding over {@link createAgentRunSocket}: opens the run's stream while enabled and mirrors
16
+ * the transport's connection state into React state. Callbacks are read through refs so re-renders
17
+ * with new callback identities never tear the socket down; the socket is re-created only when a
18
+ * subscription-defining option (runId/afterCursor/enabled/reconnect) changes.
19
+ */
20
+ export declare function useAgentRunStream(options: UseAgentRunStreamOptions): UseAgentRunStreamResult;
21
+ //# sourceMappingURL=useAgentRunStream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAgentRunStream.d.ts","sourceRoot":"","sources":["../src/useAgentRunStream.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EAEzB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAE1D,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACvE,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,CAAA;IACxD,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAC7C;AAED,MAAM,MAAM,uBAAuB,GAAG,uBAAuB,CAAA;AAI7D;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,uBAAuB,CAgC5F"}
@@ -0,0 +1,45 @@
1
+ export interface ReconnectingSocketState {
2
+ readonly connected: boolean;
3
+ readonly reconnecting: boolean;
4
+ readonly error: string | null;
5
+ }
6
+ /** Handed to `onMessage` so a stream-level error frame updates socket state + notifies the caller. */
7
+ export interface ReconnectingSocketErrorSink {
8
+ reportError(message: string): void;
9
+ }
10
+ export interface ReconnectingSocketOptions {
11
+ readonly url: string;
12
+ /** Built before every connection; useful for one-shot WebSocket tickets. */
13
+ readonly protocols?: () => readonly string[] | Promise<readonly string[]>;
14
+ /** Decide whether a failed async connection setup should be retried. */
15
+ readonly shouldReconnectAfterSetupError?: (error: unknown) => boolean;
16
+ readonly reconnect?: boolean;
17
+ readonly reconnectDelayMs?: number;
18
+ /** Built fresh for each subscription so it can carry the latest resume cursor. */
19
+ readonly subscribeMessage: () => unknown;
20
+ /**
21
+ * Optional protocol-level readiness check. When provided, defer the subscribe
22
+ * frame until an inbound message passes this check. Without it, subscribe as
23
+ * soon as the websocket opens.
24
+ */
25
+ readonly subscribeWhen?: (data: unknown) => boolean;
26
+ /** Inbound message that marks the protocol handshake as complete. */
27
+ readonly readyWhen?: (data: unknown) => boolean;
28
+ /** Close and reconnect when `readyWhen` does not pass within this duration. */
29
+ readonly readyTimeoutMs?: number;
30
+ readonly readyTimeoutMessage?: string;
31
+ /** Handle one inbound message; call `sink.reportError` for stream-level error frames. */
32
+ readonly onMessage: (data: unknown, sink: ReconnectingSocketErrorSink) => void;
33
+ /** Message surfaced when the socket itself errors (connection failure). */
34
+ readonly connectionErrorMessage: string;
35
+ readonly onError?: (message: string) => void;
36
+ readonly onStateChange?: (state: ReconnectingSocketState) => void;
37
+ }
38
+ export interface ReconnectingSocket {
39
+ /** Stop reconnecting and close the underlying WebSocket. */
40
+ close(): void;
41
+ }
42
+ export declare function createReconnectingSocket(options: ReconnectingSocketOptions): ReconnectingSocket;
43
+ /** Build the `ws(s)://.../<path>` URL for a Sixb WebSocket stream from the client's API base URL. */
44
+ export declare function createSixbWebSocketUrl(path: string, baseUrl?: string): string;
45
+ //# sourceMappingURL=ws-socket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws-socket.d.ts","sourceRoot":"","sources":["../src/ws-socket.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAED,sGAAsG;AACtG,MAAM,WAAW,2BAA2B;IAC1C,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CACnC;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAA;IACzE,wEAAwE;IACxE,QAAQ,CAAC,8BAA8B,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAClC,kFAAkF;IAClF,QAAQ,CAAC,gBAAgB,EAAE,MAAM,OAAO,CAAA;IACxC;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAA;IACnD,qEAAqE;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAA;IAC/C,+EAA+E;IAC/E,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAA;IACrC,yFAAyF;IACzF,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,2BAA2B,KAAK,IAAI,CAAA;IAC9E,2EAA2E;IAC3E,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAA;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5C,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAA;CAClE;AAED,MAAM,WAAW,kBAAkB;IACjC,4DAA4D;IAC5D,KAAK,IAAI,IAAI,CAAA;CACd;AAQD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,kBAAkB,CA6H/F;AAED,qGAAqG;AACrG,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAO7E"}
package/package.json ADDED
@@ -0,0 +1,105 @@
1
+ {
2
+ "name": "@sixb/client",
3
+ "version": "0.0.1",
4
+ "description": "Type-safe SDK for Sixb API with TanStack Query hooks",
5
+ "keywords": [
6
+ "sixb",
7
+ "bun",
8
+ "sdk",
9
+ "react",
10
+ "tanstack-query"
11
+ ],
12
+ "homepage": "https://sixb.ai",
13
+ "bugs": {
14
+ "url": "https://github.com/sixb-ai/sixb/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/sixb-ai/sixb.git",
19
+ "directory": "packages/client"
20
+ },
21
+ "author": "Sixb contributors",
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "bun": "./src/index.ts",
29
+ "import": "./dist/index.js",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./browser": {
33
+ "types": "./dist/browser.d.ts",
34
+ "bun": "./src/browser.ts",
35
+ "import": "./dist/browser.js",
36
+ "default": "./dist/browser.js"
37
+ },
38
+ "./logs": {
39
+ "types": "./dist/logs.d.ts",
40
+ "bun": "./src/logs.ts",
41
+ "import": "./dist/logs.js",
42
+ "default": "./dist/logs.js"
43
+ },
44
+ "./hooks": {
45
+ "types": "./dist/hooks.d.ts",
46
+ "bun": "./src/hooks.ts",
47
+ "import": "./dist/hooks.js",
48
+ "default": "./dist/hooks.js"
49
+ },
50
+ "./models": {
51
+ "types": "./dist/models.d.ts",
52
+ "bun": "./src/models.ts",
53
+ "import": "./dist/models.js",
54
+ "default": "./dist/models.js"
55
+ },
56
+ "./query": {
57
+ "types": "./dist/query.d.ts",
58
+ "bun": "./src/query.ts",
59
+ "import": "./dist/query.js",
60
+ "default": "./dist/query.js"
61
+ }
62
+ },
63
+ "scripts": {
64
+ "generate": "openapi-ts",
65
+ "typecheck": "tsc --noEmit",
66
+ "build": "bun ../../scripts/build-package.ts",
67
+ "prepack": "bun run build"
68
+ },
69
+ "dependencies": {
70
+ "@sixb/core": "0.0.1"
71
+ },
72
+ "peerDependencies": {
73
+ "@tanstack/react-query": "^5.0.0",
74
+ "react": "^18.0.0 || ^19.0.0"
75
+ },
76
+ "peerDependenciesMeta": {
77
+ "@tanstack/react-query": {
78
+ "optional": true
79
+ },
80
+ "react": {
81
+ "optional": true
82
+ }
83
+ },
84
+ "devDependencies": {
85
+ "@hey-api/openapi-ts": "0.90.10",
86
+ "@tanstack/react-query": "^5.0.0",
87
+ "@types/bun": "latest",
88
+ "@types/react": "^19.0.0",
89
+ "react": "^19.0.0",
90
+ "typescript": "^5.7.0"
91
+ },
92
+ "license": "MIT",
93
+ "engines": {
94
+ "bun": ">=1.3.0"
95
+ },
96
+ "publishConfig": {
97
+ "access": "public"
98
+ },
99
+ "files": [
100
+ "dist",
101
+ "src",
102
+ "README.md",
103
+ "LICENSE"
104
+ ]
105
+ }
package/src/actions.ts ADDED
@@ -0,0 +1,310 @@
1
+ import { events } from "./events-builder"
2
+ import type { Client } from "./generated/client"
3
+ import { getActionRun, type Options, requestAction } from "./generated/sdk.gen"
4
+ import type {
5
+ GetActionRunResponse,
6
+ RequestActionData,
7
+ RequestActionResponse,
8
+ } from "./generated/types.gen"
9
+
10
+ const DEFAULT_ACTION_WAIT_TIMEOUT_MS = 60_000
11
+ const DEFAULT_ACTION_WAIT_FALLBACK_POLL_MS = 10_000
12
+ const DEFAULT_ACTION_WAIT_DISCONNECTED_POLL_MS = 1_000
13
+
14
+ export type ActionRunDetail = GetActionRunResponse
15
+ export type ActionRunTerminalFailureStatus = Extract<
16
+ ActionRunDetail["status"],
17
+ "failed" | "cancelled"
18
+ >
19
+
20
+ export interface ActionWaitOptions {
21
+ readonly timeoutMs?: number
22
+ /** Slow safety check while the event socket is healthy. */
23
+ readonly fallbackPollIntervalMs?: number
24
+ /** Faster storage check while the event socket is disconnected or reconnecting. */
25
+ readonly disconnectedPollIntervalMs?: number
26
+ readonly signal?: AbortSignal
27
+ /**
28
+ * When true, failed and cancelled terminal runs reject the promise. This is
29
+ * the default because it maps naturally to mutation error states.
30
+ */
31
+ readonly rejectOnTerminalFailure?: boolean
32
+ }
33
+
34
+ export interface WaitForActionRunInput extends ActionWaitOptions {
35
+ readonly runId: string
36
+ readonly client?: Client
37
+ }
38
+
39
+ export type RequestActionAndWaitInput = Options<RequestActionData> &
40
+ ActionWaitOptions & {
41
+ readonly onRequested?: (response: RequestActionResponse) => void | Promise<void>
42
+ }
43
+
44
+ export class ActionRunFailedError extends Error {
45
+ readonly name = "ActionRunFailedError"
46
+ readonly run: ActionRunDetail
47
+ readonly runId: string
48
+ readonly actionId: string
49
+ readonly status: ActionRunTerminalFailureStatus
50
+ readonly subject: ActionRunDetail["subject"]
51
+ readonly error: ActionRunDetail["error"]
52
+
53
+ constructor(run: ActionRunDetail & { readonly status: ActionRunTerminalFailureStatus }) {
54
+ super(run.error?.message ?? `Action run '${run.id}' finished with status '${run.status}'.`)
55
+ this.run = run
56
+ this.runId = run.id
57
+ this.actionId = run.actionId
58
+ this.status = run.status
59
+ this.subject = run.subject
60
+ this.error = run.error
61
+ }
62
+ }
63
+
64
+ export class ActionRunTimeoutError extends Error {
65
+ readonly name = "ActionRunTimeoutError"
66
+ readonly runId: string
67
+ readonly timeoutMs: number
68
+
69
+ constructor(params: { readonly runId: string; readonly timeoutMs: number }) {
70
+ super(`Action run '${params.runId}' did not finish within ${params.timeoutMs}ms.`)
71
+ this.runId = params.runId
72
+ this.timeoutMs = params.timeoutMs
73
+ }
74
+ }
75
+
76
+ export async function requestActionAndWait(
77
+ input: RequestActionAndWaitInput
78
+ ): Promise<ActionRunDetail> {
79
+ const {
80
+ timeoutMs,
81
+ fallbackPollIntervalMs,
82
+ disconnectedPollIntervalMs,
83
+ rejectOnTerminalFailure,
84
+ onRequested,
85
+ ...requestOptions
86
+ } = input
87
+
88
+ const response = await requestAction<true>({
89
+ ...requestOptions,
90
+ throwOnError: true,
91
+ })
92
+ await onRequested?.(response.data)
93
+
94
+ return waitForActionRun({
95
+ runId: response.data.runId,
96
+ client: input.client,
97
+ signal: input.signal,
98
+ timeoutMs,
99
+ fallbackPollIntervalMs,
100
+ disconnectedPollIntervalMs,
101
+ rejectOnTerminalFailure,
102
+ })
103
+ }
104
+
105
+ /**
106
+ * Wait for a durable action run to reach a terminal status.
107
+ *
108
+ * Flow:
109
+ * 1. Fetch the run detail immediately, so very fast actions that finished
110
+ * before the event socket opened are still observed.
111
+ * 2. Treat action terminal events as wakeups, then fetch the run detail again;
112
+ * the detail endpoint is the source of truth and carries commit diff data.
113
+ * 3. Keep a slow safety poll while the socket is healthy, and use a faster
114
+ * fallback poll only while the socket is disconnected or reconnecting.
115
+ */
116
+ export function waitForActionRun(input: WaitForActionRunInput): Promise<ActionRunDetail> {
117
+ const timeoutMs = input.timeoutMs ?? DEFAULT_ACTION_WAIT_TIMEOUT_MS
118
+ const fallbackPollIntervalMs =
119
+ input.fallbackPollIntervalMs ?? DEFAULT_ACTION_WAIT_FALLBACK_POLL_MS
120
+ const disconnectedPollIntervalMs =
121
+ input.disconnectedPollIntervalMs ?? DEFAULT_ACTION_WAIT_DISCONNECTED_POLL_MS
122
+ const rejectOnTerminalFailure = input.rejectOnTerminalFailure ?? true
123
+ const signal = input.signal
124
+ const startedAt = Date.now()
125
+
126
+ if (signal?.aborted) {
127
+ return Promise.reject(signal.reason ?? new Error("aborted"))
128
+ }
129
+
130
+ return new Promise<ActionRunDetail>((resolve, reject) => {
131
+ let timeoutTimer: ReturnType<typeof setTimeout> | undefined
132
+ let pollTimer: ReturnType<typeof setTimeout> | undefined
133
+ let unsubscribeFromTerminalEvents: (() => void) | undefined
134
+ let settled = false
135
+ let checking = false
136
+ let checkRequested = false
137
+ let socketHealthy = false
138
+
139
+ const clearTimer = (timer: ReturnType<typeof setTimeout> | undefined) => {
140
+ if (timer) clearTimeout(timer)
141
+ }
142
+
143
+ const cleanup = () => {
144
+ if (settled) return
145
+ settled = true
146
+ clearTimer(timeoutTimer)
147
+ clearTimer(pollTimer)
148
+ unsubscribeFromTerminalEvents?.()
149
+ signal?.removeEventListener("abort", onAbort)
150
+ }
151
+
152
+ const rejectWith = (error: unknown) => {
153
+ cleanup()
154
+ reject(error)
155
+ }
156
+
157
+ const resolveWith = (run: ActionRunDetail) => {
158
+ cleanup()
159
+ if (rejectOnTerminalFailure && isTerminalFailureRun(run)) {
160
+ reject(new ActionRunFailedError(run))
161
+ return
162
+ }
163
+ resolve(run)
164
+ }
165
+
166
+ const currentPollIntervalMs = () =>
167
+ socketHealthy ? fallbackPollIntervalMs : disconnectedPollIntervalMs
168
+
169
+ const schedulePoll = () => {
170
+ if (settled || pollTimer) return
171
+ pollTimer = setTimeout(() => {
172
+ pollTimer = undefined
173
+ void check()
174
+ }, currentPollIntervalMs())
175
+ }
176
+
177
+ const reschedulePoll = () => {
178
+ if (settled) return
179
+ clearTimer(pollTimer)
180
+ pollTimer = undefined
181
+ schedulePoll()
182
+ }
183
+
184
+ const wakeAndCheck = () => {
185
+ clearTimer(pollTimer)
186
+ pollTimer = undefined
187
+ void check()
188
+ }
189
+
190
+ const check = async () => {
191
+ if (settled) return
192
+ if (checking) {
193
+ checkRequested = true
194
+ return
195
+ }
196
+ checking = true
197
+ try {
198
+ const run = await fetchActionRun(input.runId, {
199
+ client: input.client,
200
+ signal,
201
+ })
202
+ if (run && isTerminalActionRun(run)) {
203
+ resolveWith(run)
204
+ return
205
+ }
206
+ schedulePoll()
207
+ } catch (error) {
208
+ rejectWith(error)
209
+ } finally {
210
+ checking = false
211
+ if (!settled && checkRequested) {
212
+ checkRequested = false
213
+ wakeAndCheck()
214
+ }
215
+ }
216
+ }
217
+
218
+ const onAbort = () => {
219
+ rejectWith(signal?.reason ?? new Error("aborted"))
220
+ }
221
+
222
+ timeoutTimer = setTimeout(
223
+ () => {
224
+ rejectWith(new ActionRunTimeoutError({ runId: input.runId, timeoutMs }))
225
+ },
226
+ Math.max(0, timeoutMs - (Date.now() - startedAt))
227
+ )
228
+
229
+ signal?.addEventListener("abort", onAbort, { once: true })
230
+
231
+ unsubscribeFromTerminalEvents = events
232
+ .actions({ client: input.client })
233
+ .run(input.runId)
234
+ .terminal()
235
+ .subscribe(
236
+ () => {
237
+ wakeAndCheck()
238
+ },
239
+ {
240
+ // Event delivery is only a wakeup path. Polling `getActionRun` remains
241
+ // authoritative, so transient WebSocket failures should not reject.
242
+ onError: () => undefined,
243
+ onStateChange: (state) => {
244
+ const nextSocketHealthy = state.connected && !state.reconnecting && !state.error
245
+ if (nextSocketHealthy !== socketHealthy) {
246
+ socketHealthy = nextSocketHealthy
247
+ // The subscription baseline may have been captured after a fast
248
+ // action completed. Check storage once at acknowledgement so a
249
+ // terminal event skipped by that baseline cannot strand the wait
250
+ // on the slow safety poll.
251
+ if (socketHealthy) {
252
+ wakeAndCheck()
253
+ } else {
254
+ reschedulePoll()
255
+ }
256
+ }
257
+ },
258
+ }
259
+ )
260
+
261
+ void check()
262
+ })
263
+ }
264
+
265
+ export function isTerminalActionRun(run: Pick<ActionRunDetail, "status">): boolean {
266
+ return run.status === "succeeded" || isTerminalFailureRun(run)
267
+ }
268
+
269
+ function isTerminalFailureRun(
270
+ run: Pick<ActionRunDetail, "status">
271
+ ): run is ActionRunDetail & { readonly status: ActionRunTerminalFailureStatus } {
272
+ return run.status === "failed" || run.status === "cancelled"
273
+ }
274
+
275
+ async function fetchActionRun(
276
+ runId: string,
277
+ options: {
278
+ readonly client?: Client
279
+ readonly signal?: AbortSignal
280
+ }
281
+ ): Promise<ActionRunDetail | null> {
282
+ const result = await getActionRun({
283
+ client: options.client,
284
+ path: { runId },
285
+ signal: options.signal,
286
+ throwOnError: false,
287
+ })
288
+
289
+ if (result.data) {
290
+ return result.data
291
+ }
292
+
293
+ if (result.response.status === 404) {
294
+ return null
295
+ }
296
+
297
+ throw toActionRunRequestError(result.error, runId)
298
+ }
299
+
300
+ function toActionRunRequestError(error: unknown, runId: string): Error {
301
+ if (error instanceof Error) {
302
+ return error
303
+ }
304
+
305
+ if (error && typeof error === "object" && "error" in error) {
306
+ return new Error(String((error as { readonly error?: unknown }).error))
307
+ }
308
+
309
+ return new Error(`[SixbClient] Failed to fetch action run '${runId}'.`)
310
+ }