@cadraos/sdk 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat/index.cjs +57 -5
- package/dist/chat/index.cjs.map +1 -1
- package/dist/chat/index.d.cts +14 -0
- package/dist/chat/index.d.ts +14 -0
- package/dist/chat/index.js +57 -5
- package/dist/chat/index.js.map +1 -1
- package/dist/index.cjs +57 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +57 -5
- package/dist/index.js.map +1 -1
- package/dist/kanban/index.cjs +57 -5
- package/dist/kanban/index.cjs.map +1 -1
- package/dist/kanban/index.d.cts +14 -0
- package/dist/kanban/index.d.ts +14 -0
- package/dist/kanban/index.js +57 -5
- package/dist/kanban/index.js.map +1 -1
- package/dist/teams/index.cjs +57 -5
- package/dist/teams/index.cjs.map +1 -1
- package/dist/teams/index.d.cts +14 -0
- package/dist/teams/index.d.ts +14 -0
- package/dist/teams/index.js +57 -5
- package/dist/teams/index.js.map +1 -1
- package/package.json +15 -16
package/dist/chat/index.d.cts
CHANGED
|
@@ -1832,6 +1832,8 @@ interface HttpClientConfig {
|
|
|
1832
1832
|
retry: RetryConfig;
|
|
1833
1833
|
/** Custom headers */
|
|
1834
1834
|
headers?: Record<string, string>;
|
|
1835
|
+
/** Optional fetch implementation — inject `expo/fetch` for React Native streaming. Defaults to global fetch. */
|
|
1836
|
+
fetch?: typeof fetch;
|
|
1835
1837
|
}
|
|
1836
1838
|
/**
|
|
1837
1839
|
* Request options
|
|
@@ -2483,6 +2485,8 @@ interface RemoteAgentCreateInput {
|
|
|
2483
2485
|
name: string;
|
|
2484
2486
|
description?: string;
|
|
2485
2487
|
adapterType: string;
|
|
2488
|
+
/** Bind the agent to a specific runner (e.g. a Cadra Desktop install). */
|
|
2489
|
+
defaultRunnerId?: number | null;
|
|
2486
2490
|
executionTargetKind?: RemoteAgentExecutionTargetKind;
|
|
2487
2491
|
adapterConfig?: Record<string, unknown>;
|
|
2488
2492
|
inputSchema?: Record<string, unknown>;
|
|
@@ -2493,6 +2497,8 @@ interface RemoteAgentUpdateInput {
|
|
|
2493
2497
|
name?: string;
|
|
2494
2498
|
description?: string;
|
|
2495
2499
|
adapterType?: string;
|
|
2500
|
+
/** Re-bind the agent to a specific runner. */
|
|
2501
|
+
defaultRunnerId?: number | null;
|
|
2496
2502
|
executionTargetKind?: RemoteAgentExecutionTargetKind;
|
|
2497
2503
|
adapterConfig?: Record<string, unknown>;
|
|
2498
2504
|
inputSchema?: Record<string, unknown>;
|
|
@@ -2856,6 +2862,8 @@ interface StreamConfig {
|
|
|
2856
2862
|
token?: string;
|
|
2857
2863
|
tokenProvider?: () => Promise<string>;
|
|
2858
2864
|
orgId: number;
|
|
2865
|
+
/** Optional fetch implementation — inject `expo/fetch` for React Native streaming. Defaults to global fetch. */
|
|
2866
|
+
fetch?: typeof fetch;
|
|
2859
2867
|
}
|
|
2860
2868
|
|
|
2861
2869
|
/**
|
|
@@ -4183,6 +4191,8 @@ interface CadraClientOptionsApiKey {
|
|
|
4183
4191
|
maxRetries?: number;
|
|
4184
4192
|
/** Custom headers to include in all requests */
|
|
4185
4193
|
headers?: Record<string, string>;
|
|
4194
|
+
/** Optional fetch implementation — inject `expo/fetch` for React Native streaming. Defaults to global fetch. */
|
|
4195
|
+
fetch?: typeof fetch;
|
|
4186
4196
|
}
|
|
4187
4197
|
/**
|
|
4188
4198
|
* Client options for OAuth token authentication
|
|
@@ -4200,6 +4210,8 @@ interface CadraClientOptionsToken {
|
|
|
4200
4210
|
maxRetries?: number;
|
|
4201
4211
|
/** Custom headers to include in all requests */
|
|
4202
4212
|
headers?: Record<string, string>;
|
|
4213
|
+
/** Optional fetch implementation — inject `expo/fetch` for React Native streaming. Defaults to global fetch. */
|
|
4214
|
+
fetch?: typeof fetch;
|
|
4203
4215
|
}
|
|
4204
4216
|
/**
|
|
4205
4217
|
* Client options for token provider authentication
|
|
@@ -4217,6 +4229,8 @@ interface CadraClientOptionsTokenProvider {
|
|
|
4217
4229
|
maxRetries?: number;
|
|
4218
4230
|
/** Custom headers to include in all requests */
|
|
4219
4231
|
headers?: Record<string, string>;
|
|
4232
|
+
/** Optional fetch implementation — inject `expo/fetch` for React Native streaming. Defaults to global fetch. */
|
|
4233
|
+
fetch?: typeof fetch;
|
|
4220
4234
|
}
|
|
4221
4235
|
/**
|
|
4222
4236
|
* All client options
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -1832,6 +1832,8 @@ interface HttpClientConfig {
|
|
|
1832
1832
|
retry: RetryConfig;
|
|
1833
1833
|
/** Custom headers */
|
|
1834
1834
|
headers?: Record<string, string>;
|
|
1835
|
+
/** Optional fetch implementation — inject `expo/fetch` for React Native streaming. Defaults to global fetch. */
|
|
1836
|
+
fetch?: typeof fetch;
|
|
1835
1837
|
}
|
|
1836
1838
|
/**
|
|
1837
1839
|
* Request options
|
|
@@ -2483,6 +2485,8 @@ interface RemoteAgentCreateInput {
|
|
|
2483
2485
|
name: string;
|
|
2484
2486
|
description?: string;
|
|
2485
2487
|
adapterType: string;
|
|
2488
|
+
/** Bind the agent to a specific runner (e.g. a Cadra Desktop install). */
|
|
2489
|
+
defaultRunnerId?: number | null;
|
|
2486
2490
|
executionTargetKind?: RemoteAgentExecutionTargetKind;
|
|
2487
2491
|
adapterConfig?: Record<string, unknown>;
|
|
2488
2492
|
inputSchema?: Record<string, unknown>;
|
|
@@ -2493,6 +2497,8 @@ interface RemoteAgentUpdateInput {
|
|
|
2493
2497
|
name?: string;
|
|
2494
2498
|
description?: string;
|
|
2495
2499
|
adapterType?: string;
|
|
2500
|
+
/** Re-bind the agent to a specific runner. */
|
|
2501
|
+
defaultRunnerId?: number | null;
|
|
2496
2502
|
executionTargetKind?: RemoteAgentExecutionTargetKind;
|
|
2497
2503
|
adapterConfig?: Record<string, unknown>;
|
|
2498
2504
|
inputSchema?: Record<string, unknown>;
|
|
@@ -2856,6 +2862,8 @@ interface StreamConfig {
|
|
|
2856
2862
|
token?: string;
|
|
2857
2863
|
tokenProvider?: () => Promise<string>;
|
|
2858
2864
|
orgId: number;
|
|
2865
|
+
/** Optional fetch implementation — inject `expo/fetch` for React Native streaming. Defaults to global fetch. */
|
|
2866
|
+
fetch?: typeof fetch;
|
|
2859
2867
|
}
|
|
2860
2868
|
|
|
2861
2869
|
/**
|
|
@@ -4183,6 +4191,8 @@ interface CadraClientOptionsApiKey {
|
|
|
4183
4191
|
maxRetries?: number;
|
|
4184
4192
|
/** Custom headers to include in all requests */
|
|
4185
4193
|
headers?: Record<string, string>;
|
|
4194
|
+
/** Optional fetch implementation — inject `expo/fetch` for React Native streaming. Defaults to global fetch. */
|
|
4195
|
+
fetch?: typeof fetch;
|
|
4186
4196
|
}
|
|
4187
4197
|
/**
|
|
4188
4198
|
* Client options for OAuth token authentication
|
|
@@ -4200,6 +4210,8 @@ interface CadraClientOptionsToken {
|
|
|
4200
4210
|
maxRetries?: number;
|
|
4201
4211
|
/** Custom headers to include in all requests */
|
|
4202
4212
|
headers?: Record<string, string>;
|
|
4213
|
+
/** Optional fetch implementation — inject `expo/fetch` for React Native streaming. Defaults to global fetch. */
|
|
4214
|
+
fetch?: typeof fetch;
|
|
4203
4215
|
}
|
|
4204
4216
|
/**
|
|
4205
4217
|
* Client options for token provider authentication
|
|
@@ -4217,6 +4229,8 @@ interface CadraClientOptionsTokenProvider {
|
|
|
4217
4229
|
maxRetries?: number;
|
|
4218
4230
|
/** Custom headers to include in all requests */
|
|
4219
4231
|
headers?: Record<string, string>;
|
|
4232
|
+
/** Optional fetch implementation — inject `expo/fetch` for React Native streaming. Defaults to global fetch. */
|
|
4233
|
+
fetch?: typeof fetch;
|
|
4220
4234
|
}
|
|
4221
4235
|
/**
|
|
4222
4236
|
* All client options
|
package/dist/chat/index.js
CHANGED
|
@@ -300,7 +300,8 @@ var HttpClient = class {
|
|
|
300
300
|
const controller = new AbortController();
|
|
301
301
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
302
302
|
try {
|
|
303
|
-
const
|
|
303
|
+
const doFetch = this.config.fetch ?? fetch;
|
|
304
|
+
const response = await doFetch(url, {
|
|
304
305
|
method: options.method,
|
|
305
306
|
headers,
|
|
306
307
|
body: options.body !== void 0 ? JSON.stringify(options.body) : void 0,
|
|
@@ -432,7 +433,8 @@ var SSEClient = class {
|
|
|
432
433
|
console.log("[SDK:SSE] Auth header:", this.config.authHeader ? `${this.config.authHeader.substring(0, 30)}...` : "MISSING");
|
|
433
434
|
console.log("[SDK:SSE] Org ID:", this.config.orgId);
|
|
434
435
|
try {
|
|
435
|
-
const
|
|
436
|
+
const doFetch = this.config.fetch ?? fetch;
|
|
437
|
+
const response = await doFetch(this.config.url, {
|
|
436
438
|
method: "GET",
|
|
437
439
|
headers: {
|
|
438
440
|
"Authorization": this.config.authHeader,
|
|
@@ -680,6 +682,15 @@ var ExecutionStreamControllerImpl = class {
|
|
|
680
682
|
sseClient = null;
|
|
681
683
|
status = "connecting";
|
|
682
684
|
reconnectAttempts = 0;
|
|
685
|
+
// CAD-39 / webchat dual-plane create-connect race. `hasConnected` flips true on
|
|
686
|
+
// the first successful SSE open; `notFoundRetries` bounds retries of a 404
|
|
687
|
+
// encountered BEFORE we ever connect (the run row is persisted slightly AFTER
|
|
688
|
+
// the client opens the stream — the norm on the webchat path where msg-api owns
|
|
689
|
+
// the executionId and cadra persists the agent_executions row via an async
|
|
690
|
+
// worker callback). See handleConnectionError.
|
|
691
|
+
hasConnected = false;
|
|
692
|
+
notFoundRetries = 0;
|
|
693
|
+
maxConnectRaceRetries = 3;
|
|
683
694
|
seenEventIds = /* @__PURE__ */ new Set();
|
|
684
695
|
_lastEventId = null;
|
|
685
696
|
activityTimeoutId = null;
|
|
@@ -808,6 +819,7 @@ var ExecutionStreamControllerImpl = class {
|
|
|
808
819
|
url,
|
|
809
820
|
authHeader: `Bearer ${authToken}`,
|
|
810
821
|
orgId: this.options.orgId,
|
|
822
|
+
fetch: this.options.fetch,
|
|
811
823
|
onEvent: (event) => this.handleEvent(event),
|
|
812
824
|
onError: (error) => {
|
|
813
825
|
console.error("[SDK:StreamController] SSE error:", error);
|
|
@@ -818,6 +830,8 @@ var ExecutionStreamControllerImpl = class {
|
|
|
818
830
|
if (connected) {
|
|
819
831
|
this.status = "connected";
|
|
820
832
|
this.reconnectAttempts = 0;
|
|
833
|
+
this.hasConnected = true;
|
|
834
|
+
this.notFoundRetries = 0;
|
|
821
835
|
this.resetActivityTimeout();
|
|
822
836
|
}
|
|
823
837
|
this.emit("connectionChange", { connected, usingFallback: false });
|
|
@@ -1107,6 +1121,38 @@ var ExecutionStreamControllerImpl = class {
|
|
|
1107
1121
|
return;
|
|
1108
1122
|
}
|
|
1109
1123
|
const msg = error instanceof Error ? error.message : String(error);
|
|
1124
|
+
const isNotFound = /\b404\b/.test(msg);
|
|
1125
|
+
const isAuthFailure = /\b40[13]\b/.test(msg) || /INVALID_API_KEY|INVALID_REQUEST/.test(msg);
|
|
1126
|
+
if (isNotFound && !isAuthFailure && !this.hasConnected) {
|
|
1127
|
+
if (this.notFoundRetries < this.maxConnectRaceRetries) {
|
|
1128
|
+
this.notFoundRetries++;
|
|
1129
|
+
this.status = "reconnecting";
|
|
1130
|
+
const delay = Math.min(
|
|
1131
|
+
this.config.reconnectBaseDelayMs * this.notFoundRetries,
|
|
1132
|
+
this.config.reconnectMaxDelayMs
|
|
1133
|
+
);
|
|
1134
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1135
|
+
if (this.status === "closed") {
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
try {
|
|
1139
|
+
await this.connectSSE();
|
|
1140
|
+
} catch (retryError) {
|
|
1141
|
+
await this.handleConnectionError(retryError);
|
|
1142
|
+
}
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
if (this.pollingEnabled) {
|
|
1146
|
+
if (this.sseClient) {
|
|
1147
|
+
this.sseClient.disconnect();
|
|
1148
|
+
this.sseClient = null;
|
|
1149
|
+
}
|
|
1150
|
+
this.status = "fallback_polling";
|
|
1151
|
+
this.emit("connectionChange", { connected: false, usingFallback: true });
|
|
1152
|
+
this.startPolling();
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1110
1156
|
if (/\b4\d\d\b/.test(msg) || /INVALID_API_KEY|INVALID_REQUEST/.test(msg)) {
|
|
1111
1157
|
if (this.sseClient) {
|
|
1112
1158
|
this.sseClient.disconnect();
|
|
@@ -1485,6 +1531,7 @@ var AgentsAPI = class extends BaseResourceAPI {
|
|
|
1485
1531
|
apiKey: config.apiKey,
|
|
1486
1532
|
tokenProvider: config.tokenProvider,
|
|
1487
1533
|
orgId: config.orgId,
|
|
1534
|
+
fetch: config.fetch,
|
|
1488
1535
|
getExecution: (id) => this.getExecution(id)
|
|
1489
1536
|
});
|
|
1490
1537
|
console.log("[SDK:Agents] Stream controller created - caller must call connect() after registering listeners");
|
|
@@ -1531,6 +1578,7 @@ var AgentsAPI = class extends BaseResourceAPI {
|
|
|
1531
1578
|
apiKey: config.apiKey,
|
|
1532
1579
|
tokenProvider: config.tokenProvider,
|
|
1533
1580
|
orgId: config.orgId,
|
|
1581
|
+
fetch: config.fetch,
|
|
1534
1582
|
getExecution: (id) => this.getExecution(id)
|
|
1535
1583
|
});
|
|
1536
1584
|
console.log("[SDK:Agents] Stream controller created for existing execution - caller must call connect() after registering listeners");
|
|
@@ -2379,6 +2427,7 @@ var SessionsAPI = class extends BaseResourceAPI {
|
|
|
2379
2427
|
baseUrl: config.baseUrl,
|
|
2380
2428
|
apiKey: config.apiKey,
|
|
2381
2429
|
orgId: config.orgId,
|
|
2430
|
+
fetch: config.fetch,
|
|
2382
2431
|
getExecution: (id) => this.getExecution(id)
|
|
2383
2432
|
});
|
|
2384
2433
|
await controller.connect();
|
|
@@ -3033,7 +3082,8 @@ var CadraClient = class {
|
|
|
3033
3082
|
baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
|
|
3034
3083
|
orgId: options.orgId,
|
|
3035
3084
|
timeout: options.timeout ?? DEFAULT_TIMEOUT,
|
|
3036
|
-
headers: options.headers
|
|
3085
|
+
headers: options.headers,
|
|
3086
|
+
fetch: options.fetch
|
|
3037
3087
|
};
|
|
3038
3088
|
if ("apiKey" in options) {
|
|
3039
3089
|
this.config.apiKey = options.apiKey;
|
|
@@ -3054,7 +3104,8 @@ var CadraClient = class {
|
|
|
3054
3104
|
orgId: this.config.orgId,
|
|
3055
3105
|
timeout: this.config.timeout,
|
|
3056
3106
|
retry: retryConfig,
|
|
3057
|
-
headers: this.config.headers
|
|
3107
|
+
headers: this.config.headers,
|
|
3108
|
+
fetch: this.config.fetch
|
|
3058
3109
|
};
|
|
3059
3110
|
this.httpClient = new HttpClient(httpConfig);
|
|
3060
3111
|
const getStreamConfig = () => ({
|
|
@@ -3062,7 +3113,8 @@ var CadraClient = class {
|
|
|
3062
3113
|
apiKey: this.config.apiKey,
|
|
3063
3114
|
token: this.config.token,
|
|
3064
3115
|
tokenProvider: this.config.tokenProvider,
|
|
3065
|
-
orgId: this.config.orgId
|
|
3116
|
+
orgId: this.config.orgId,
|
|
3117
|
+
fetch: this.config.fetch
|
|
3066
3118
|
});
|
|
3067
3119
|
this.agents = new AgentsAPI(this.httpClient, getStreamConfig);
|
|
3068
3120
|
this.skills = new SkillsAPI(this.httpClient);
|