@pellux/goodvibes-sdk 0.19.6 → 0.19.8

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 (169) hide show
  1. package/dist/_internal/contracts/index.d.ts +1 -0
  2. package/dist/_internal/contracts/index.d.ts.map +1 -1
  3. package/dist/_internal/contracts/index.js +2 -0
  4. package/dist/_internal/contracts/types.d.ts +4 -0
  5. package/dist/_internal/contracts/types.d.ts.map +1 -1
  6. package/dist/_internal/contracts/zod-schemas/accounts.d.ts +81 -0
  7. package/dist/_internal/contracts/zod-schemas/accounts.d.ts.map +1 -0
  8. package/dist/_internal/contracts/zod-schemas/accounts.js +47 -0
  9. package/dist/_internal/contracts/zod-schemas/auth.d.ts +42 -0
  10. package/dist/_internal/contracts/zod-schemas/auth.d.ts.map +1 -0
  11. package/dist/_internal/contracts/zod-schemas/auth.js +29 -0
  12. package/dist/_internal/contracts/zod-schemas/events.d.ts +37 -0
  13. package/dist/_internal/contracts/zod-schemas/events.d.ts.map +1 -0
  14. package/dist/_internal/contracts/zod-schemas/events.js +26 -0
  15. package/dist/_internal/contracts/zod-schemas/index.d.ts +9 -0
  16. package/dist/_internal/contracts/zod-schemas/index.d.ts.map +1 -0
  17. package/dist/_internal/contracts/zod-schemas/index.js +4 -0
  18. package/dist/_internal/contracts/zod-schemas/session.d.ts +22 -0
  19. package/dist/_internal/contracts/zod-schemas/session.d.ts.map +1 -0
  20. package/dist/_internal/contracts/zod-schemas/session.js +19 -0
  21. package/dist/_internal/daemon/api-router.d.ts.map +1 -1
  22. package/dist/_internal/daemon/api-router.js +0 -1
  23. package/dist/_internal/daemon/automation.d.ts.map +1 -1
  24. package/dist/_internal/daemon/channel-route-types.d.ts.map +1 -1
  25. package/dist/_internal/daemon/channel-routes.d.ts.map +1 -1
  26. package/dist/_internal/daemon/context.d.ts.map +1 -1
  27. package/dist/_internal/daemon/control-routes.d.ts.map +1 -1
  28. package/dist/_internal/daemon/http-policy.d.ts.map +1 -1
  29. package/dist/_internal/daemon/http-policy.js +0 -1
  30. package/dist/_internal/daemon/integration-route-types.d.ts.map +1 -1
  31. package/dist/_internal/daemon/integration-routes.d.ts.map +1 -1
  32. package/dist/_internal/daemon/knowledge-route-types.d.ts.map +1 -1
  33. package/dist/_internal/daemon/knowledge-routes.d.ts.map +1 -1
  34. package/dist/_internal/daemon/knowledge-routes.js +5 -4
  35. package/dist/_internal/daemon/media-route-types.d.ts.map +1 -1
  36. package/dist/_internal/daemon/media-routes.d.ts.map +1 -1
  37. package/dist/_internal/daemon/operator.d.ts.map +1 -1
  38. package/dist/_internal/daemon/remote-routes.d.ts.map +1 -1
  39. package/dist/_internal/daemon/remote.d.ts.map +1 -1
  40. package/dist/_internal/daemon/route-helpers.d.ts.map +1 -1
  41. package/dist/_internal/daemon/runtime-automation-routes.d.ts.map +1 -1
  42. package/dist/_internal/daemon/runtime-route-types.d.ts +14 -1
  43. package/dist/_internal/daemon/runtime-route-types.d.ts.map +1 -1
  44. package/dist/_internal/daemon/runtime-routes.d.ts.map +1 -1
  45. package/dist/_internal/daemon/runtime-session-routes.d.ts.map +1 -1
  46. package/dist/_internal/daemon/runtime-session-routes.js +0 -2
  47. package/dist/_internal/daemon/sessions.d.ts.map +1 -1
  48. package/dist/_internal/daemon/system-route-types.d.ts.map +1 -1
  49. package/dist/_internal/daemon/system-routes.d.ts.map +1 -1
  50. package/dist/_internal/daemon/tasks.d.ts.map +1 -1
  51. package/dist/_internal/daemon/telemetry-routes.d.ts.map +1 -1
  52. package/dist/_internal/errors/daemon-error-contract.d.ts.map +1 -1
  53. package/dist/_internal/errors/index.d.ts +2 -2
  54. package/dist/_internal/errors/index.js +2 -2
  55. package/dist/_internal/operator/client-core.d.ts.map +1 -1
  56. package/dist/_internal/operator/client-core.js +8 -2
  57. package/dist/_internal/operator/client.d.ts +7 -0
  58. package/dist/_internal/operator/client.d.ts.map +1 -1
  59. package/dist/_internal/operator/client.js +32 -1
  60. package/dist/_internal/peer/client-core.d.ts.map +1 -1
  61. package/dist/_internal/platform/agents/orchestrator.d.ts +7 -0
  62. package/dist/_internal/platform/agents/orchestrator.d.ts.map +1 -1
  63. package/dist/_internal/platform/agents/orchestrator.js +8 -0
  64. package/dist/_internal/platform/auth/android-keystore-token-store.d.ts +110 -0
  65. package/dist/_internal/platform/auth/android-keystore-token-store.d.ts.map +1 -0
  66. package/dist/_internal/platform/auth/android-keystore-token-store.js +164 -0
  67. package/dist/_internal/platform/auth/auto-refresh-middleware.d.ts +46 -0
  68. package/dist/_internal/platform/auth/auto-refresh-middleware.d.ts.map +1 -0
  69. package/dist/_internal/platform/auth/auto-refresh-middleware.js +155 -0
  70. package/dist/_internal/platform/auth/auto-refresh.d.ts +123 -0
  71. package/dist/_internal/platform/auth/auto-refresh.d.ts.map +1 -0
  72. package/dist/_internal/platform/auth/auto-refresh.js +236 -0
  73. package/dist/_internal/platform/auth/expo-secure-token-store.d.ts +82 -0
  74. package/dist/_internal/platform/auth/expo-secure-token-store.d.ts.map +1 -0
  75. package/dist/_internal/platform/auth/expo-secure-token-store.js +135 -0
  76. package/dist/_internal/platform/auth/index.d.ts +3 -0
  77. package/dist/_internal/platform/auth/index.d.ts.map +1 -1
  78. package/dist/_internal/platform/auth/index.js +2 -0
  79. package/dist/_internal/platform/auth/ios-keychain-token-store.d.ts +88 -0
  80. package/dist/_internal/platform/auth/ios-keychain-token-store.d.ts.map +1 -0
  81. package/dist/_internal/platform/auth/ios-keychain-token-store.js +147 -0
  82. package/dist/_internal/platform/auth/session-manager.d.ts +2 -0
  83. package/dist/_internal/platform/auth/session-manager.d.ts.map +1 -1
  84. package/dist/_internal/platform/auth/session-manager.js +9 -1
  85. package/dist/_internal/platform/auth/token-store.d.ts +13 -0
  86. package/dist/_internal/platform/auth/token-store.d.ts.map +1 -1
  87. package/dist/_internal/platform/auth/token-store.js +23 -0
  88. package/dist/_internal/platform/companion/companion-chat-manager.d.ts +64 -11
  89. package/dist/_internal/platform/companion/companion-chat-manager.d.ts.map +1 -1
  90. package/dist/_internal/platform/companion/companion-chat-manager.js +158 -12
  91. package/dist/_internal/platform/companion/companion-chat-persistence.d.ts +33 -0
  92. package/dist/_internal/platform/companion/companion-chat-persistence.d.ts.map +1 -0
  93. package/dist/_internal/platform/companion/companion-chat-persistence.js +115 -0
  94. package/dist/_internal/platform/companion/companion-chat-rate-limiter.d.ts +47 -0
  95. package/dist/_internal/platform/companion/companion-chat-rate-limiter.d.ts.map +1 -0
  96. package/dist/_internal/platform/companion/companion-chat-rate-limiter.js +117 -0
  97. package/dist/_internal/platform/companion/companion-chat-types.d.ts +2 -4
  98. package/dist/_internal/platform/companion/companion-chat-types.d.ts.map +1 -1
  99. package/dist/_internal/platform/companion/companion-chat-types.js +2 -4
  100. package/dist/_internal/platform/companion/index.d.ts +4 -0
  101. package/dist/_internal/platform/companion/index.d.ts.map +1 -1
  102. package/dist/_internal/platform/companion/index.js +2 -0
  103. package/dist/_internal/platform/daemon/facade-composition.d.ts.map +1 -1
  104. package/dist/_internal/platform/daemon/facade-composition.js +5 -0
  105. package/dist/_internal/platform/daemon/facade.d.ts.map +1 -1
  106. package/dist/_internal/platform/daemon/facade.js +3 -0
  107. package/dist/_internal/platform/daemon/http/runtime-route-types.d.ts +0 -7
  108. package/dist/_internal/platform/daemon/http/runtime-route-types.d.ts.map +1 -1
  109. package/dist/_internal/platform/state/db.d.ts.map +1 -1
  110. package/dist/_internal/platform/state/db.js +0 -1
  111. package/dist/_internal/platform/state/sqlite-store.d.ts.map +1 -1
  112. package/dist/_internal/platform/state/sqlite-store.js +0 -1
  113. package/dist/_internal/platform/version.js +1 -1
  114. package/dist/_internal/transport-core/client-transport.d.ts.map +1 -1
  115. package/dist/_internal/transport-core/event-envelope.d.ts.map +1 -1
  116. package/dist/_internal/transport-core/event-feeds.d.ts.map +1 -1
  117. package/dist/_internal/transport-core/index.d.ts +5 -0
  118. package/dist/_internal/transport-core/index.d.ts.map +1 -1
  119. package/dist/_internal/transport-core/index.js +3 -0
  120. package/dist/_internal/transport-core/middleware.d.ts +76 -0
  121. package/dist/_internal/transport-core/middleware.d.ts.map +1 -0
  122. package/dist/_internal/transport-core/middleware.js +67 -0
  123. package/dist/_internal/transport-core/observer.d.ts +53 -0
  124. package/dist/_internal/transport-core/observer.d.ts.map +1 -0
  125. package/dist/_internal/transport-core/observer.js +26 -0
  126. package/dist/_internal/transport-core/otel.d.ts +64 -0
  127. package/dist/_internal/transport-core/otel.d.ts.map +1 -0
  128. package/dist/_internal/transport-core/otel.js +149 -0
  129. package/dist/_internal/transport-direct/index.d.ts.map +1 -1
  130. package/dist/_internal/transport-direct/index.js +0 -1
  131. package/dist/_internal/transport-http/contract-client.d.ts +11 -1
  132. package/dist/_internal/transport-http/contract-client.d.ts.map +1 -1
  133. package/dist/_internal/transport-http/contract-client.js +18 -4
  134. package/dist/_internal/transport-http/http-core.d.ts +27 -1
  135. package/dist/_internal/transport-http/http-core.d.ts.map +1 -1
  136. package/dist/_internal/transport-http/http-core.js +180 -12
  137. package/dist/_internal/transport-http/http.d.ts +3 -3
  138. package/dist/_internal/transport-http/http.d.ts.map +1 -1
  139. package/dist/_internal/transport-http/http.js +2 -2
  140. package/dist/_internal/transport-http/index.d.ts +4 -2
  141. package/dist/_internal/transport-http/index.d.ts.map +1 -1
  142. package/dist/_internal/transport-http/index.js +2 -1
  143. package/dist/_internal/transport-http/paths.js +1 -1
  144. package/dist/_internal/transport-http/reconnect.d.ts +2 -0
  145. package/dist/_internal/transport-http/reconnect.d.ts.map +1 -1
  146. package/dist/_internal/transport-http/reconnect.js +4 -2
  147. package/dist/_internal/transport-http/retry.d.ts +15 -0
  148. package/dist/_internal/transport-http/retry.d.ts.map +1 -1
  149. package/dist/_internal/transport-http/retry.js +19 -0
  150. package/dist/_internal/transport-realtime/domain-events.d.ts.map +1 -1
  151. package/dist/_internal/transport-realtime/runtime-events.d.ts +10 -3
  152. package/dist/_internal/transport-realtime/runtime-events.d.ts.map +1 -1
  153. package/dist/_internal/transport-realtime/runtime-events.js +73 -8
  154. package/dist/auth.d.ts +38 -3
  155. package/dist/auth.d.ts.map +1 -1
  156. package/dist/auth.js +68 -3
  157. package/dist/client.d.ts +61 -2
  158. package/dist/client.d.ts.map +1 -1
  159. package/dist/client.js +64 -3
  160. package/dist/expo.d.ts +1 -0
  161. package/dist/expo.d.ts.map +1 -1
  162. package/dist/expo.js +1 -0
  163. package/dist/observer/index.d.ts +16 -25
  164. package/dist/observer/index.d.ts.map +1 -1
  165. package/dist/platform/runtime/transports/http.js +1 -1
  166. package/dist/react-native.d.ts +2 -0
  167. package/dist/react-native.d.ts.map +1 -1
  168. package/dist/react-native.js +2 -0
  169. package/package.json +16 -3
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-core/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AACnF,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-core/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AACnF,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,YAAY,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC"}
@@ -1,3 +1,6 @@
1
1
  export { createEventEnvelope } from './event-envelope.js';
2
2
  export { createRuntimeEventFeed, createRuntimeEventFeeds } from './event-feeds.js';
3
3
  export { createClientTransport } from './client-transport.js';
4
+ export { invokeTransportObserver } from './observer.js';
5
+ export { composeMiddleware } from './middleware.js';
6
+ export { injectTraceparent, injectTraceparentAsync } from './otel.js';
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Transport middleware (Koa-style) for the HTTP transport layer.
3
+ *
4
+ * Middleware functions wrap the real fetch call and receive a mutable context
5
+ * object. Calling `next()` executes the next middleware in the chain (or the
6
+ * real fetch at the end). After `await next()` returns, `ctx.response` and
7
+ * `ctx.durationMs` are populated; `ctx.error` is set if the fetch threw.
8
+ *
9
+ * @example
10
+ * sdk.use(async (ctx, next) => {
11
+ * console.log('->', ctx.method, ctx.url);
12
+ * await next();
13
+ * console.log('<-', ctx.response?.status, ctx.durationMs, 'ms');
14
+ * });
15
+ */
16
+ /**
17
+ * Mutable context object passed through the middleware chain.
18
+ * Fields are populated progressively: request fields are set before the chain
19
+ * runs; response fields are set after the real fetch resolves.
20
+ */
21
+ export interface TransportContext {
22
+ /** HTTP method (uppercased). */
23
+ method: string;
24
+ /** Fully-qualified request URL. */
25
+ url: string;
26
+ /** Request headers (mutable — middleware may add/override). */
27
+ headers: Record<string, string>;
28
+ /** Request body (undefined for GET/HEAD). */
29
+ body: unknown;
30
+ /** Per-request options forwarded from the caller. */
31
+ options: {
32
+ readonly signal?: AbortSignal;
33
+ readonly retry?: unknown;
34
+ [key: string]: unknown;
35
+ };
36
+ /** AbortSignal for the request. Propagated from caller options. */
37
+ signal?: AbortSignal;
38
+ /** The HTTP response object — set after `next()` resolves successfully. */
39
+ response?: Response;
40
+ /** Round-trip duration in milliseconds — set after `next()` resolves. */
41
+ durationMs?: number;
42
+ /** Error thrown by the fetch or a downstream middleware — set on failure. */
43
+ error?: unknown;
44
+ /**
45
+ * Set to `true` when the error originated from within the middleware chain
46
+ * (as opposed to from the real fetch). Used by the transport to wrap
47
+ * middleware errors as `SDKError{kind:'unknown'}`.
48
+ */
49
+ middlewareError?: boolean;
50
+ /**
51
+ * Name (or index) of the middleware that was active when the error occurred.
52
+ * Set alongside `middlewareError` for error identity in cause objects.
53
+ */
54
+ activeMiddlewareName?: string;
55
+ }
56
+ /**
57
+ * A transport middleware function.
58
+ *
59
+ * @param ctx - Shared mutable context for the request/response cycle.
60
+ * @param next - Calls the next middleware (or the real fetch at the end).
61
+ */
62
+ export type TransportMiddleware = (ctx: TransportContext, next: () => Promise<void>) => Promise<void>;
63
+ /**
64
+ * Build a composed middleware executor from an ordered array of middleware.
65
+ * The last item in the chain calls the real fetch via `innerFetch`.
66
+ *
67
+ * Returns a function that:
68
+ * 1. Mutates `ctx.headers` with any header overrides from middleware.
69
+ * 2. Calls through the chain.
70
+ * 3. Sets `ctx.response`, `ctx.durationMs`, or `ctx.error` on the context.
71
+ *
72
+ * @param middleware - Ordered list of middleware functions.
73
+ * @param innerFetch - The real fetch call wrapped at the end of the chain.
74
+ */
75
+ export declare function composeMiddleware(middleware: readonly TransportMiddleware[], innerFetch: (ctx: TransportContext) => Promise<Response>): (ctx: TransportContext) => Promise<void>;
76
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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C,CAsC1C"}
@@ -0,0 +1,67 @@
1
+ // Synced from packages/transport-core/src/middleware.ts
2
+ /**
3
+ * Transport middleware (Koa-style) for the HTTP transport layer.
4
+ *
5
+ * Middleware functions wrap the real fetch call and receive a mutable context
6
+ * object. Calling `next()` executes the next middleware in the chain (or the
7
+ * real fetch at the end). After `await next()` returns, `ctx.response` and
8
+ * `ctx.durationMs` are populated; `ctx.error` is set if the fetch threw.
9
+ *
10
+ * @example
11
+ * sdk.use(async (ctx, next) => {
12
+ * console.log('->', ctx.method, ctx.url);
13
+ * await next();
14
+ * console.log('<-', ctx.response?.status, ctx.durationMs, 'ms');
15
+ * });
16
+ */
17
+ /**
18
+ * Build a composed middleware executor from an ordered array of middleware.
19
+ * The last item in the chain calls the real fetch via `innerFetch`.
20
+ *
21
+ * Returns a function that:
22
+ * 1. Mutates `ctx.headers` with any header overrides from middleware.
23
+ * 2. Calls through the chain.
24
+ * 3. Sets `ctx.response`, `ctx.durationMs`, or `ctx.error` on the context.
25
+ *
26
+ * @param middleware - Ordered list of middleware functions.
27
+ * @param innerFetch - The real fetch call wrapped at the end of the chain.
28
+ */
29
+ export function composeMiddleware(middleware, innerFetch) {
30
+ return async (ctx) => {
31
+ let index = -1;
32
+ const dispatch = async (i) => {
33
+ if (i <= index) {
34
+ throw new Error('next() called multiple times in transport middleware');
35
+ }
36
+ index = i;
37
+ if (i < middleware.length) {
38
+ const mw = middleware[i];
39
+ const mwName = mw.name || String(i);
40
+ ctx.activeMiddlewareName = mwName;
41
+ try {
42
+ await mw(ctx, () => dispatch(i + 1));
43
+ }
44
+ catch (err) {
45
+ // Mark that the error originated from this middleware (not the real fetch).
46
+ ctx.middlewareError = true;
47
+ ctx.activeMiddlewareName = mwName;
48
+ throw err;
49
+ }
50
+ }
51
+ else {
52
+ // End of chain — execute the real fetch.
53
+ const sendAt = Date.now();
54
+ try {
55
+ ctx.response = await innerFetch(ctx);
56
+ ctx.durationMs = Date.now() - sendAt;
57
+ }
58
+ catch (err) {
59
+ ctx.error = err;
60
+ ctx.durationMs = Date.now() - sendAt;
61
+ throw err;
62
+ }
63
+ }
64
+ };
65
+ await dispatch(0);
66
+ };
67
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * TransportObserver — first-class observability interface at the transport layer.
3
+ *
4
+ * Defined here (transport-core) so that HTTP and realtime sibling transports can
5
+ * accept it through their shared options types without depending on the SDK layer.
6
+ * `SDKObserver` in `@pellux/goodvibes-sdk` extends this interface and adds
7
+ * SDK-level callbacks (`onEvent`, `onAuthTransition`).
8
+ *
9
+ * All methods are optional. Observer exceptions are always swallowed via
10
+ * `invokeObserver` — they must never propagate into transport control flow.
11
+ */
12
+ /**
13
+ * Transport activity metadata surfaced at request/response boundaries.
14
+ */
15
+ export interface TransportActivityInfo {
16
+ /** Direction: `'send'` before the request, `'recv'` after a response. */
17
+ readonly direction: 'send' | 'recv';
18
+ /** The full URL of the request. */
19
+ readonly url: string;
20
+ /** HTTP response status code (only present on `'recv'`). */
21
+ readonly status?: number;
22
+ /** Round-trip duration in milliseconds (only present on `'recv'`). */
23
+ readonly durationMs?: number;
24
+ /** Transport kind. */
25
+ readonly kind?: 'http' | 'sse' | 'ws';
26
+ }
27
+ /**
28
+ * Minimal observer interface at the transport layer.
29
+ *
30
+ * Implement any subset; the SDK works identically whether an observer is
31
+ * present or not. All call sites are wrapped in a silent try/catch.
32
+ */
33
+ export interface TransportObserver {
34
+ /**
35
+ * Called when the SDK catches and is about to rethrow a transport error.
36
+ * The error is still rethrown; this is notification only.
37
+ */
38
+ onError?(err: Error): void;
39
+ /**
40
+ * Called at HTTP/SSE/WebSocket transport boundaries.
41
+ * - `'send'` fires before the request is dispatched.
42
+ * - `'recv'` fires after a response is received (status + duration included).
43
+ */
44
+ onTransportActivity?(activity: TransportActivityInfo): void;
45
+ }
46
+ /**
47
+ * Safely invoke an observer method. Observer errors are swallowed so they
48
+ * never disrupt transport control flow.
49
+ *
50
+ * @param fn - Zero-argument thunk wrapping the observer call.
51
+ */
52
+ export declare function invokeTransportObserver(fn: () => void): void;
53
+ //# sourceMappingURL=observer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observer.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-core/observer.ts"],"names":[],"mappings":"AACA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,mCAAmC;IACnC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;CACvC;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC;IAE3B;;;;OAIG;IACH,mBAAmB,CAAC,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI,CAAC;CAC7D;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAM5D"}
@@ -0,0 +1,26 @@
1
+ // Synced from packages/transport-core/src/observer.ts
2
+ /**
3
+ * TransportObserver — first-class observability interface at the transport layer.
4
+ *
5
+ * Defined here (transport-core) so that HTTP and realtime sibling transports can
6
+ * accept it through their shared options types without depending on the SDK layer.
7
+ * `SDKObserver` in `@pellux/goodvibes-sdk` extends this interface and adds
8
+ * SDK-level callbacks (`onEvent`, `onAuthTransition`).
9
+ *
10
+ * All methods are optional. Observer exceptions are always swallowed via
11
+ * `invokeObserver` — they must never propagate into transport control flow.
12
+ */
13
+ /**
14
+ * Safely invoke an observer method. Observer errors are swallowed so they
15
+ * never disrupt transport control flow.
16
+ *
17
+ * @param fn - Zero-argument thunk wrapping the observer call.
18
+ */
19
+ export function invokeTransportObserver(fn) {
20
+ try {
21
+ fn();
22
+ }
23
+ catch {
24
+ // Observer errors must not propagate into transport logic.
25
+ }
26
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * OpenTelemetry traceparent/tracestate propagation helper.
3
+ *
4
+ * Zero-dependency: detects `@opentelemetry/api` at runtime.
5
+ * If OTel is absent, all functions are no-ops.
6
+ *
7
+ * Dynamic detection uses an indirect import pattern to prevent bundlers
8
+ * (esbuild, Rollup, Miniflare/workerd) from flagging the import as an
9
+ * unresolvable dynamic specifier. The module name is never a literal in
10
+ * any import() call that the bundler sees.
11
+ *
12
+ * W3C Trace Context spec: https://www.w3.org/TR/trace-context/
13
+ */
14
+ interface SpanContext {
15
+ traceId: string;
16
+ spanId: string;
17
+ traceFlags: number;
18
+ traceState?: {
19
+ serialize(): string;
20
+ } | null;
21
+ }
22
+ interface Span {
23
+ spanContext(): SpanContext;
24
+ }
25
+ interface OtelApi {
26
+ trace: {
27
+ getActiveSpan(): Span | undefined;
28
+ };
29
+ }
30
+ /**
31
+ * Set the OTel module override for testing. Pass `undefined` to clear.
32
+ * Calling this bypasses dynamic import and require-based detection.
33
+ *
34
+ * @internal — for testing only, do NOT use in production code.
35
+ */
36
+ export declare function setOtelModuleOverride(api: OtelApi | null | undefined): void;
37
+ /**
38
+ * Get the current OTel module override (for test inspection).
39
+ * @internal
40
+ */
41
+ export declare function getOtelModuleOverride(): OtelApi | null | undefined;
42
+ /**
43
+ * Reset both the module-level cache and the test injection seam.
44
+ * Call this in `afterEach` when using `setOtelModuleOverride` in tests.
45
+ *
46
+ * @internal — for testing only.
47
+ */
48
+ export declare function __resetOtelCache(): void;
49
+ /**
50
+ * Inject W3C Trace Context headers (`traceparent`, `tracestate`) if an active
51
+ * OTel span is available. Synchronous; uses require-based detection.
52
+ *
53
+ * @param headers - Mutable header record to augment in-place.
54
+ */
55
+ export declare function injectTraceparent(headers: Record<string, string>): void;
56
+ /**
57
+ * Async variant — probes OTel via dynamic import on first call, then caches.
58
+ * Use for SSE/WS connection setup where async is acceptable.
59
+ *
60
+ * @param headers - Mutable header record to augment in-place.
61
+ */
62
+ export declare function injectTraceparentAsync(headers: Record<string, string>): Promise<void>;
63
+ export {};
64
+ //# sourceMappingURL=otel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-core/otel.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;GAYG;AAEH,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE;QAAE,SAAS,IAAI,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CAC7C;AAED,UAAU,IAAI;IACZ,WAAW,IAAI,WAAW,CAAC;CAC5B;AAED,UAAU,OAAO;IACf,KAAK,EAAE;QACL,aAAa,IAAI,IAAI,GAAG,SAAS,CAAC;KACnC,CAAC;CACH;AAQD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAE3E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,GAAG,IAAI,GAAG,SAAS,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC;AAkDD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAgBvE;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB3F"}
@@ -0,0 +1,149 @@
1
+ // Synced from packages/transport-core/src/otel.ts
2
+ /**
3
+ * OpenTelemetry traceparent/tracestate propagation helper.
4
+ *
5
+ * Zero-dependency: detects `@opentelemetry/api` at runtime.
6
+ * If OTel is absent, all functions are no-ops.
7
+ *
8
+ * Dynamic detection uses an indirect import pattern to prevent bundlers
9
+ * (esbuild, Rollup, Miniflare/workerd) from flagging the import as an
10
+ * unresolvable dynamic specifier. The module name is never a literal in
11
+ * any import() call that the bundler sees.
12
+ *
13
+ * W3C Trace Context spec: https://www.w3.org/TR/trace-context/
14
+ */
15
+ /** Cached result of OTel detection. `null` = not available. `undefined` = not yet probed. */
16
+ let otelApi = undefined;
17
+ /** Internal override value for the test injection seam. */
18
+ let _otelModuleOverride = undefined;
19
+ /**
20
+ * Set the OTel module override for testing. Pass `undefined` to clear.
21
+ * Calling this bypasses dynamic import and require-based detection.
22
+ *
23
+ * @internal — for testing only, do NOT use in production code.
24
+ */
25
+ export function setOtelModuleOverride(api) {
26
+ _otelModuleOverride = api;
27
+ }
28
+ /**
29
+ * Get the current OTel module override (for test inspection).
30
+ * @internal
31
+ */
32
+ export function getOtelModuleOverride() {
33
+ return _otelModuleOverride;
34
+ }
35
+ /**
36
+ * Reset both the module-level cache and the test injection seam.
37
+ * Call this in `afterEach` when using `setOtelModuleOverride` in tests.
38
+ *
39
+ * @internal — for testing only.
40
+ */
41
+ export function __resetOtelCache() {
42
+ otelApi = undefined;
43
+ _otelModuleOverride = undefined;
44
+ }
45
+ /**
46
+ * Dynamic import that is opaque to bundlers.
47
+ * `new Function(...)` is not statically analysed for import() specifiers.
48
+ */
49
+ function dynamicImport(moduleName) {
50
+ // Using Function constructor prevents bundler static analysis of import().
51
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
52
+ return new Function('m', 'return import(m)')(moduleName);
53
+ }
54
+ async function probeOtel() {
55
+ // Test injection seam takes highest priority.
56
+ if (_otelModuleOverride !== undefined)
57
+ return _otelModuleOverride;
58
+ if (otelApi !== undefined)
59
+ return otelApi;
60
+ try {
61
+ const mod = await dynamicImport('@opentelemetry/api');
62
+ otelApi = mod;
63
+ }
64
+ catch {
65
+ otelApi = null;
66
+ }
67
+ return otelApi;
68
+ }
69
+ function probeOtelSync() {
70
+ // Test injection seam takes highest priority.
71
+ if (_otelModuleOverride !== undefined)
72
+ return _otelModuleOverride;
73
+ if (otelApi !== undefined)
74
+ return otelApi;
75
+ try {
76
+ // Use globalThis.require via indirect reference to avoid bundler module resolution.
77
+ const nodeRequire = typeof globalThis !== 'undefined'
78
+ ? globalThis.require
79
+ : undefined;
80
+ if (typeof nodeRequire === 'function') {
81
+ otelApi = nodeRequire('@opentelemetry/api');
82
+ }
83
+ else {
84
+ otelApi = null;
85
+ }
86
+ }
87
+ catch {
88
+ otelApi = null;
89
+ }
90
+ return otelApi;
91
+ }
92
+ function buildTraceparent(ctx) {
93
+ const flags = (ctx.traceFlags & 0xff).toString(16).padStart(2, '0');
94
+ return `00-${ctx.traceId}-${ctx.spanId}-${flags}`;
95
+ }
96
+ /**
97
+ * Inject W3C Trace Context headers (`traceparent`, `tracestate`) if an active
98
+ * OTel span is available. Synchronous; uses require-based detection.
99
+ *
100
+ * @param headers - Mutable header record to augment in-place.
101
+ */
102
+ export function injectTraceparent(headers) {
103
+ const api = probeOtelSync();
104
+ if (!api)
105
+ return;
106
+ try {
107
+ const span = api.trace.getActiveSpan();
108
+ if (!span)
109
+ return;
110
+ const ctx = span.spanContext();
111
+ if (!ctx.traceId || !ctx.spanId)
112
+ return;
113
+ headers['traceparent'] = buildTraceparent(ctx);
114
+ const traceState = ctx.traceState?.serialize();
115
+ if (traceState) {
116
+ headers['tracestate'] = traceState;
117
+ }
118
+ }
119
+ catch {
120
+ // Never let OTel errors propagate into transport logic.
121
+ }
122
+ }
123
+ /**
124
+ * Async variant — probes OTel via dynamic import on first call, then caches.
125
+ * Use for SSE/WS connection setup where async is acceptable.
126
+ *
127
+ * @param headers - Mutable header record to augment in-place.
128
+ */
129
+ export async function injectTraceparentAsync(headers) {
130
+ const api = await probeOtel();
131
+ if (!api)
132
+ return;
133
+ try {
134
+ const span = api.trace.getActiveSpan();
135
+ if (!span)
136
+ return;
137
+ const ctx = span.spanContext();
138
+ if (!ctx.traceId || !ctx.spanId)
139
+ return;
140
+ headers['traceparent'] = buildTraceparent(ctx);
141
+ const traceState = ctx.traceState?.serialize();
142
+ if (traceState) {
143
+ headers['tracestate'] = traceState;
144
+ }
145
+ }
146
+ catch {
147
+ // Never let OTel errors propagate into transport logic.
148
+ }
149
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-direct/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEzF,MAAM,MAAM,qBAAqB,CAAC,SAAS,EAAE,KAAK,IAAI,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;AAElG,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,KAAK,EAC1D,QAAQ,EAAE,SAAS,EACnB,IAAI,EAAE,KAAK,GACV,qBAAqB,CAAC,SAAS,EAAE,KAAK,CAAC,CAEzC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-direct/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEzF,MAAM,MAAM,qBAAqB,CAAC,SAAS,EAAE,KAAK,IAAI,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;AAElG,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,KAAK,EAC1D,QAAQ,EAAE,SAAS,EACnB,IAAI,EAAE,KAAK,GACV,qBAAqB,CAAC,SAAS,EAAE,KAAK,CAAC,CAEzC"}
@@ -1,5 +1,4 @@
1
1
  // Synced from packages/transport-direct/src/index.ts
2
- // Extracted from legacy source: src/runtime/transports/direct-client.ts
3
2
  import { createClientTransport } from '../transport-core/index.js';
4
3
  export function createDirectClientTransport(operator, peer) {
5
4
  return createClientTransport('direct', operator, peer);
@@ -1,3 +1,4 @@
1
+ import type { ZodType } from 'zod/v4';
1
2
  import type { HttpTransport } from './http.js';
2
3
  import { type ServerSentEventHandlers } from './sse-stream.js';
3
4
  export interface ContractRouteDefinition {
@@ -6,16 +7,25 @@ export interface ContractRouteDefinition {
6
7
  }
7
8
  export interface ContractRouteLike {
8
9
  readonly id: string;
10
+ /** When true, this route is safe to retry on 5xx even for mutating HTTP verbs. */
11
+ readonly idempotent?: boolean;
9
12
  }
10
13
  export interface ContractInvokeOptions {
11
14
  readonly signal?: AbortSignal;
12
15
  readonly headers?: HeadersInit;
16
+ /**
17
+ * Optional Zod v4 schema to validate the parsed response body against.
18
+ * When provided, a failed parse throws a {@link ContractError} with
19
+ * field-level detail: operation, field path, expected type, and a
20
+ * recovery hint.
21
+ */
22
+ readonly responseSchema?: ZodType<any>;
13
23
  }
14
24
  export interface ContractStreamOptions extends ContractInvokeOptions {
15
25
  readonly handlers: ServerSentEventHandlers;
16
26
  }
17
27
  export declare function buildContractInput(primaryKey: string, primaryValue: string, input?: Record<string, unknown>): Record<string, unknown>;
18
28
  export declare function requireContractRoute<TRoute extends ContractRouteLike>(routes: readonly TRoute[], routeId: string, kind: string): TRoute;
19
- export declare function invokeContractRoute<T = unknown>(transport: HttpTransport, route: ContractRouteDefinition, input?: Record<string, unknown>, options?: ContractInvokeOptions): Promise<T>;
29
+ export declare function invokeContractRoute<T = unknown>(transport: HttpTransport, route: ContractRouteDefinition & ContractRouteLike, input?: Record<string, unknown>, options?: ContractInvokeOptions): Promise<T>;
20
30
  export declare function openContractRouteStream(transport: HttpTransport, route: ContractRouteDefinition, input: Record<string, unknown> | undefined, options: ContractStreamOptions): Promise<() => void>;
21
31
  //# sourceMappingURL=contract-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract-client.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-http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AAM,GACX,MAAM,CAMR;AAED,wBAAsB,mBAAmB,CAAC,CAAC,GAAG,OAAO,EACnD,SAAS,EAAE,aAAa,EACxB,KAAK,EAAE,uBAAuB,GAAG,iBAAiB,EAClD,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,CAAC,CAAC,CAyBZ;AAED,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,aAAa,EACxB,KAAK,EAAE,uBAAuB,EAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC1C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,MAAM,IAAI,CAAC,CAYrB"}
@@ -1,5 +1,5 @@
1
1
  // Synced from packages/transport-http/src/contract-client.ts
2
- import { GoodVibesSdkError } from '../errors/index.js';
2
+ import { ContractError, GoodVibesSdkError } from '../errors/index.js';
3
3
  import { openServerSentEventStream } from './sse-stream.js';
4
4
  export function buildContractInput(primaryKey, primaryValue, input) {
5
5
  return {
@@ -10,18 +10,32 @@ export function buildContractInput(primaryKey, primaryValue, input) {
10
10
  export function requireContractRoute(routes, routeId, kind) {
11
11
  const route = routes.find((candidate) => candidate.id === routeId);
12
12
  if (!route) {
13
- throw new GoodVibesSdkError(`Unknown ${kind} "${routeId}"`, { category: 'contract', source: 'contract', recoverable: false });
13
+ throw new GoodVibesSdkError(`Unknown ${kind} "${routeId}". Verify the method/route id is correct and that your contract manifest is up to date.`, { category: 'contract', source: 'contract', recoverable: false });
14
14
  }
15
15
  return route;
16
16
  }
17
- export function invokeContractRoute(transport, route, input, options = {}) {
17
+ export async function invokeContractRoute(transport, route, input, options = {}) {
18
18
  const resolved = transport.resolveContractRequest(route.method, route.path, input);
19
- return transport.requestJson(resolved.url, {
19
+ const body = await transport.requestJson(resolved.url, {
20
20
  method: resolved.method,
21
21
  body: resolved.body,
22
22
  headers: options.headers,
23
23
  signal: options.signal,
24
+ methodId: route.id,
25
+ idempotent: route.idempotent === true,
24
26
  });
27
+ if (options.responseSchema) {
28
+ const result = options.responseSchema.safeParse(body);
29
+ if (!result.success) {
30
+ const issue = result.error.issues[0];
31
+ const fieldPath = issue ? issue.path.join('.') || '(root)' : '(unknown)';
32
+ const expected = issue ? issue.expected ?? issue.code : 'unknown';
33
+ const received = issue ? issue.received ?? 'unknown' : 'unknown';
34
+ throw new ContractError(`Response validation failed for "${route.method} ${route.path}": field "${fieldPath}" expected ${expected} but received ${received}. Ensure the server is running a compatible version of the GoodVibes daemon.`, { source: 'contract' });
35
+ }
36
+ return result.data;
37
+ }
38
+ return body;
25
39
  }
26
40
  export async function openContractRouteStream(transport, route, input, options) {
27
41
  const resolved = transport.resolveContractRequest(route.method, route.path, input);
@@ -2,13 +2,21 @@ import { HttpStatusError } from '../errors/index.js';
2
2
  import { type AuthTokenResolver, type HeaderResolver } from './auth.js';
3
3
  import { type HttpRetryPolicy } from './retry.js';
4
4
  import { type TransportPaths } from './paths.js';
5
- export type { HttpRetryPolicy } from './retry.js';
5
+ import { type TransportMiddleware, type TransportObserver } from '../transport-core/index.js';
6
+ export type { HttpRetryPolicy, PerMethodRetryPolicy } from './retry.js';
7
+ export type { TransportContext, TransportMiddleware } from '../transport-core/index.js';
6
8
  export type JsonValue = string | number | boolean | null | {
7
9
  readonly [key: string]: JsonValue;
8
10
  } | readonly JsonValue[];
9
11
  export type JsonObject = {
10
12
  readonly [key: string]: JsonValue;
11
13
  };
14
+ /**
15
+ * Generate a UUID v4 idempotency key.
16
+ * Uses `crypto.randomUUID()` when available (Bun, browsers, Workers, Node 14.17+).
17
+ * Falls back to a manual RFC 4122 v4 implementation otherwise.
18
+ */
19
+ export declare function generateIdempotencyKey(): string;
12
20
  export interface HttpJsonTransportOptions {
13
21
  readonly baseUrl: string;
14
22
  readonly authToken?: string | null;
@@ -18,6 +26,9 @@ export interface HttpJsonTransportOptions {
18
26
  readonly headers?: HeadersInit;
19
27
  readonly getHeaders?: HeaderResolver;
20
28
  readonly retry?: HttpRetryPolicy;
29
+ readonly observer?: TransportObserver;
30
+ /** Middleware chain applied to every HTTP request/response cycle. */
31
+ readonly middleware?: readonly TransportMiddleware[];
21
32
  }
22
33
  export interface HttpJsonRequestOptions {
23
34
  readonly method?: string;
@@ -25,6 +36,19 @@ export interface HttpJsonRequestOptions {
25
36
  readonly headers?: HeadersInit;
26
37
  readonly signal?: AbortSignal;
27
38
  readonly retry?: false | HttpRetryPolicy;
39
+ /**
40
+ * Contract method / endpoint ID used to look up per-method retry policy overrides.
41
+ * Populated automatically by `invokeContractRoute`; callers outside the contract
42
+ * layer may also set this to opt into `perMethodPolicy` overrides.
43
+ */
44
+ readonly methodId?: string;
45
+ /**
46
+ * When `true`, this call is considered idempotent even if the HTTP verb is a
47
+ * mutating method (POST/PUT/PATCH/DELETE). Enables retry-on-5xx for the call.
48
+ * Populated automatically from `contract.idempotent`; takes lower precedence
49
+ * than an explicit `perMethodPolicy` override.
50
+ */
51
+ readonly idempotent?: boolean;
28
52
  }
29
53
  export interface ResolvedContractRequest {
30
54
  readonly url: string;
@@ -48,6 +72,8 @@ export interface HttpJsonTransport {
48
72
  getAuthToken(): Promise<string | null>;
49
73
  requestJson<T>(pathOrUrl: string, options?: HttpJsonRequestOptions): Promise<T>;
50
74
  resolveContractRequest(method: string, path: string, input?: Record<string, unknown>): ResolvedContractRequest;
75
+ /** Append a middleware to the transport's middleware chain. */
76
+ use(middleware: TransportMiddleware): void;
51
77
  }
52
78
  export declare function createTransportError(status: number, url: string, method: string, body: unknown, retryAfterMs?: number): HttpStatusError & {
53
79
  readonly transport: TransportJsonError;
@@ -1 +1 @@
1
- {"version":3,"file":"http-core.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-http/http-core.ts"],"names":[],"mappings":"AACA,OAAO,EAAqC,eAAe,EAAyB,MAAM,oBAAoB,CAAC;AAE/G,OAAO,EAAsE,KAAK,iBAAiB,EAAE,KAAK,cAAc,EAAE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