flowstack-sdk 0.2.1 → 0.2.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.
- package/README.md +77 -0
- package/dist/api/index.d.mts +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +63 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/index.mjs +58 -1
- package/dist/api/index.mjs.map +1 -1
- package/dist/{index-BkACA2ls.d.mts → index-CUyJ5c2d.d.mts} +54 -1
- package/dist/{index-BkACA2ls.d.ts → index-CUyJ5c2d.d.ts} +54 -1
- package/dist/index.d.mts +77 -3
- package/dist/index.d.ts +77 -3
- package/dist/index.js +183 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -337,6 +337,63 @@ async function deleteDocuments(credentials, collection, filter, config, layer) {
|
|
|
337
337
|
config
|
|
338
338
|
);
|
|
339
339
|
}
|
|
340
|
+
function dmPairKey(a, b) {
|
|
341
|
+
return [a, b].sort().join("::");
|
|
342
|
+
}
|
|
343
|
+
function requireAppScope(config) {
|
|
344
|
+
const scope = config?.appScope;
|
|
345
|
+
if (!scope) {
|
|
346
|
+
throw new Error("Private messaging requires an app scope (built-app context).");
|
|
347
|
+
}
|
|
348
|
+
return scope;
|
|
349
|
+
}
|
|
350
|
+
async function listThreads(credentials, config) {
|
|
351
|
+
const scope = requireAppScope(config);
|
|
352
|
+
return flowstackFetch(
|
|
353
|
+
`/apps/${encodeURIComponent(scope)}/threads`,
|
|
354
|
+
{ credentials },
|
|
355
|
+
config
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
async function listMessages(credentials, withUserKey, options, config) {
|
|
359
|
+
const scope = requireAppScope(config);
|
|
360
|
+
const params = new URLSearchParams();
|
|
361
|
+
params.set("with", withUserKey);
|
|
362
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
363
|
+
if (options?.before) params.set("before", options.before);
|
|
364
|
+
return flowstackFetch(
|
|
365
|
+
`/apps/${encodeURIComponent(scope)}/messages?${params.toString()}`,
|
|
366
|
+
{ credentials },
|
|
367
|
+
config
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
async function sendMessage(credentials, toUserKey, body, config) {
|
|
371
|
+
const scope = requireAppScope(config);
|
|
372
|
+
return flowstackFetch(
|
|
373
|
+
`/apps/${encodeURIComponent(scope)}/messages`,
|
|
374
|
+
{ method: "POST", credentials, body: { to_user_key: toUserKey, body } },
|
|
375
|
+
config
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
async function openThread(credentials, withUserKey, config) {
|
|
379
|
+
const scope = requireAppScope(config);
|
|
380
|
+
const me = credentials.userId;
|
|
381
|
+
if (!me) throw new Error("openThread requires an authenticated user.");
|
|
382
|
+
const pk = dmPairKey(me, withUserKey);
|
|
383
|
+
return flowstackFetch(
|
|
384
|
+
`/apps/${encodeURIComponent(scope)}/threads/${encodeURIComponent(pk)}/consent`,
|
|
385
|
+
{ method: "POST", credentials },
|
|
386
|
+
config
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
async function markMessageRead(credentials, messageId, config) {
|
|
390
|
+
const scope = requireAppScope(config);
|
|
391
|
+
return flowstackFetch(
|
|
392
|
+
`/apps/${encodeURIComponent(scope)}/messages/${encodeURIComponent(messageId)}/read`,
|
|
393
|
+
{ method: "POST", credentials },
|
|
394
|
+
config
|
|
395
|
+
);
|
|
396
|
+
}
|
|
340
397
|
async function invokeTool(credentials, agentName, toolName, kwargs = {}, config) {
|
|
341
398
|
return flowstackFetch(
|
|
342
399
|
"/tool/invoke",
|
|
@@ -6171,6 +6228,124 @@ function useConnections() {
|
|
|
6171
6228
|
}, [credentials, config.baseUrl, config.tenantId, refresh]);
|
|
6172
6229
|
return { connections, isLoading, error, connect, disconnect, refresh };
|
|
6173
6230
|
}
|
|
6231
|
+
function useThreads(options) {
|
|
6232
|
+
const { credentials, config } = useFlowstack();
|
|
6233
|
+
const [threads, setThreads] = useState([]);
|
|
6234
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
6235
|
+
const [error, setError] = useState(null);
|
|
6236
|
+
const enabled = options?.enabled !== false;
|
|
6237
|
+
const clientConfig = {
|
|
6238
|
+
baseUrl: config.baseUrl,
|
|
6239
|
+
tenantId: config.tenantId,
|
|
6240
|
+
appScope: config.appScope
|
|
6241
|
+
};
|
|
6242
|
+
const refresh = useCallback(async () => {
|
|
6243
|
+
if (!credentials || !enabled) return;
|
|
6244
|
+
setIsLoading(true);
|
|
6245
|
+
setError(null);
|
|
6246
|
+
try {
|
|
6247
|
+
const res = await listThreads(credentials, clientConfig);
|
|
6248
|
+
if (res.ok && res.data) {
|
|
6249
|
+
setThreads(res.data.threads);
|
|
6250
|
+
} else {
|
|
6251
|
+
setError(res.error || "Failed to load threads");
|
|
6252
|
+
}
|
|
6253
|
+
} catch (err) {
|
|
6254
|
+
setError(err?.message || "Failed to load threads");
|
|
6255
|
+
} finally {
|
|
6256
|
+
setIsLoading(false);
|
|
6257
|
+
}
|
|
6258
|
+
}, [credentials, config.baseUrl, config.tenantId, config.appScope, enabled]);
|
|
6259
|
+
useEffect(() => {
|
|
6260
|
+
refresh();
|
|
6261
|
+
}, [refresh]);
|
|
6262
|
+
const intervalRef = useRef(null);
|
|
6263
|
+
useEffect(() => {
|
|
6264
|
+
if (!options?.refreshInterval || !enabled) return;
|
|
6265
|
+
intervalRef.current = setInterval(refresh, options.refreshInterval);
|
|
6266
|
+
return () => {
|
|
6267
|
+
if (intervalRef.current) clearInterval(intervalRef.current);
|
|
6268
|
+
};
|
|
6269
|
+
}, [options?.refreshInterval, enabled, refresh]);
|
|
6270
|
+
const openThread2 = useCallback(
|
|
6271
|
+
async (withUserKey) => {
|
|
6272
|
+
if (!credentials || !withUserKey) return null;
|
|
6273
|
+
const res = await openThread(credentials, withUserKey, clientConfig);
|
|
6274
|
+
if (res.ok && res.data) {
|
|
6275
|
+
await refresh();
|
|
6276
|
+
return res.data.status;
|
|
6277
|
+
}
|
|
6278
|
+
setError(res.error || "Failed to open thread");
|
|
6279
|
+
return null;
|
|
6280
|
+
},
|
|
6281
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6282
|
+
[credentials, config.baseUrl, config.tenantId, config.appScope, refresh]
|
|
6283
|
+
);
|
|
6284
|
+
return { threads, isLoading, error, refresh, openThread: openThread2 };
|
|
6285
|
+
}
|
|
6286
|
+
function useMessages(withUserKey, options) {
|
|
6287
|
+
const { credentials, config } = useFlowstack();
|
|
6288
|
+
const [messages, setMessages] = useState([]);
|
|
6289
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
6290
|
+
const [error, setError] = useState(null);
|
|
6291
|
+
const enabled = options?.enabled !== false && !!withUserKey;
|
|
6292
|
+
const clientConfig = {
|
|
6293
|
+
baseUrl: config.baseUrl,
|
|
6294
|
+
tenantId: config.tenantId,
|
|
6295
|
+
appScope: config.appScope
|
|
6296
|
+
};
|
|
6297
|
+
const refresh = useCallback(async () => {
|
|
6298
|
+
if (!credentials || !withUserKey || !enabled) return;
|
|
6299
|
+
setIsLoading(true);
|
|
6300
|
+
setError(null);
|
|
6301
|
+
try {
|
|
6302
|
+
const res = await listMessages(
|
|
6303
|
+
credentials,
|
|
6304
|
+
withUserKey,
|
|
6305
|
+
{ limit: options?.limit },
|
|
6306
|
+
clientConfig
|
|
6307
|
+
);
|
|
6308
|
+
if (res.ok && res.data) {
|
|
6309
|
+
setMessages(res.data.messages);
|
|
6310
|
+
} else {
|
|
6311
|
+
setError(res.error || "Failed to load messages");
|
|
6312
|
+
}
|
|
6313
|
+
} catch (err) {
|
|
6314
|
+
setError(err?.message || "Failed to load messages");
|
|
6315
|
+
} finally {
|
|
6316
|
+
setIsLoading(false);
|
|
6317
|
+
}
|
|
6318
|
+
}, [credentials, withUserKey, config.baseUrl, config.tenantId, config.appScope, enabled, options?.limit]);
|
|
6319
|
+
useEffect(() => {
|
|
6320
|
+
refresh();
|
|
6321
|
+
}, [refresh]);
|
|
6322
|
+
const intervalRef = useRef(null);
|
|
6323
|
+
useEffect(() => {
|
|
6324
|
+
if (!options?.refreshInterval || !enabled) return;
|
|
6325
|
+
intervalRef.current = setInterval(refresh, options.refreshInterval);
|
|
6326
|
+
return () => {
|
|
6327
|
+
if (intervalRef.current) clearInterval(intervalRef.current);
|
|
6328
|
+
};
|
|
6329
|
+
}, [options?.refreshInterval, enabled, refresh]);
|
|
6330
|
+
const send = useCallback(
|
|
6331
|
+
async (body) => {
|
|
6332
|
+
if (!credentials) throw new Error("Not authenticated");
|
|
6333
|
+
if (!withUserKey) throw new Error("No counterpart selected");
|
|
6334
|
+
if (!body || !body.trim()) return;
|
|
6335
|
+
setError(null);
|
|
6336
|
+
const res = await sendMessage(credentials, withUserKey, body, clientConfig);
|
|
6337
|
+
if (!res.ok) {
|
|
6338
|
+
const msg = res.error || "Failed to send message";
|
|
6339
|
+
setError(msg);
|
|
6340
|
+
throw new Error(msg);
|
|
6341
|
+
}
|
|
6342
|
+
await refresh();
|
|
6343
|
+
},
|
|
6344
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6345
|
+
[credentials, withUserKey, config.baseUrl, config.tenantId, config.appScope, refresh]
|
|
6346
|
+
);
|
|
6347
|
+
return { messages, isLoading, error, send, refresh };
|
|
6348
|
+
}
|
|
6174
6349
|
function normalizeVersion(raw) {
|
|
6175
6350
|
return {
|
|
6176
6351
|
version: raw.version || 0,
|
|
@@ -10605,6 +10780,6 @@ async function listLibraryItems(credentials, type, _options, config) {
|
|
|
10605
10780
|
}
|
|
10606
10781
|
}
|
|
10607
10782
|
|
|
10608
|
-
export { AdminGate, AgentFactory, AgentRegistry, AuthGuard, AuthPage, BrokeredLoginButton, CACHE_TTL, COLLECTION_CHANGED_EVENT, COLLECTION_LAYERS, CREDENTIAL_PURPOSES, ChatInterface, ChatPage, CreateWorkspaceModal, DEFAULT_PATTERNS, DEFAULT_PROVIDER_MODEL_SETTINGS, DashboardLayout, DatasetUploader, ErrorCodes, ErrorMessages, FlowstackError, FlowstackProvider, GoogleSignIn, IntentAnalyzer, LLM_PROVIDERS, LoginForm, MarkdownRenderer, MessageList, RecoveryActions, RegisterForm, WorkspaceSelector, addPiiAllowlistTerm, addSiteFile, analyzeWithRules, checkAdminPermissions, clearAllFlowstackData, clearCredentials, clearMessages, clearSelectedWorkspace, createCustomTemplate, createDataSource, createSite, createWorkspace, dataScienceTemplate, deleteCached, deleteDataSource, deleteDataset, deleteDocuments, deleteSite, deleteSiteVersion, deleteUser, deleteUserCollection, executeQuery, executeQueryWithConfig, exportUserCollection, extractEntities, flowstackFetch, generateMockId, getAgentTemplate, getCached, getCachedDatasets, getCachedReports, getCachedSites, getCachedVisualizations, getCachedWorkspaces, getConfigSummary, getConversationHistory, getDataset, getDatasetPreview, getItem, getModel, getPiiAllowlist, getPiiSettings, getSite, getSiteVersions, getSubagent, getUser, getUserActivity, getUserCollectionDocuments, getUserCollectionSchema, getUserCollections, getUserDataOverview, getUserStats, getWorkspace, googleLogin, importFromGitHub, insertDocuments, invalidateAllUserCache, invalidateDatasetsCache, invalidateReportsCache, invalidateSitesCache, invalidateVisualizationsCache, invalidateWorkspaceArtifacts, invalidateWorkspacesCache, invokeTool, isDevelopmentConfig, isFlowstackError, isProviderCredential, listAgents, listDataSources, listDatasets, listGitHubRepos, listLibraryItems, listModels, listReports, listScripts, listSites, listUsers, listVisualizations, listWorkspaces, loadCredentials, loadMessages, loadSelectedWorkspace, login, marketingTemplate, mockChatHistory, mockCredentials, mockDataSources, mockDatasets, mockDelay, mockManagedUsers, mockUser, mockUserActivity, mockUserStats, mockVisualizations, mockWorkspaces, parseSSELine, parseSSEStream, previewPiiMasking, processSSEStream, promoteSiteVersion, publishStagedSite, publishToGitHub, reactivateUser, register, removeItem, removePiiAllowlistTerm, removeSiteAlias, sanitizeMermaidCode, saveCredentials, saveMessages, saveSelectedWorkspace, setCached, setCachedDatasets, setCachedReports, setCachedSites, setCachedVisualizations, setCachedWorkspaces, setItem, setSiteAlias, splitContentSegments, supportTemplate, suspendUser, testDataSource, updateDocuments, updatePiiSettings, updateUser, uploadFile, useAdminProviderCredentials, useAgent, useAgents, useAuth, useAuthGuard, useAutomations, useCollection, useCollectionExplorer, useConnections, useConversation, useConversations, useCurrentSession, useDataOverview, useDataSources, useDatasets, useFlowstack, useFlowstackOptional, useFlowstackStatus, useIntegrations, useIntentAgent, useLibrary, useLibraryConversations, useLibrarySearch, useLibraryTrash, useModelPreference, useModels, useOllamaDetection, useProviderCredentials, usePublicCollection, useQuery, useRecentLibraryConversations, useReports, useSiteVersions, useSites, useSubagentInvoke, useSubagents, useToolInvocation, useUserCollections, useUserManagement, useVisualizations, useWorkspace, validateConfig, validateConfigOrThrow, withErrorHandling };
|
|
10783
|
+
export { AdminGate, AgentFactory, AgentRegistry, AuthGuard, AuthPage, BrokeredLoginButton, CACHE_TTL, COLLECTION_CHANGED_EVENT, COLLECTION_LAYERS, CREDENTIAL_PURPOSES, ChatInterface, ChatPage, CreateWorkspaceModal, DEFAULT_PATTERNS, DEFAULT_PROVIDER_MODEL_SETTINGS, DashboardLayout, DatasetUploader, ErrorCodes, ErrorMessages, FlowstackError, FlowstackProvider, GoogleSignIn, IntentAnalyzer, LLM_PROVIDERS, LoginForm, MarkdownRenderer, MessageList, RecoveryActions, RegisterForm, WorkspaceSelector, addPiiAllowlistTerm, addSiteFile, analyzeWithRules, checkAdminPermissions, clearAllFlowstackData, clearCredentials, clearMessages, clearSelectedWorkspace, createCustomTemplate, createDataSource, createSite, createWorkspace, dataScienceTemplate, deleteCached, deleteDataSource, deleteDataset, deleteDocuments, deleteSite, deleteSiteVersion, deleteUser, deleteUserCollection, dmPairKey, executeQuery, executeQueryWithConfig, exportUserCollection, extractEntities, flowstackFetch, generateMockId, getAgentTemplate, getCached, getCachedDatasets, getCachedReports, getCachedSites, getCachedVisualizations, getCachedWorkspaces, getConfigSummary, getConversationHistory, getDataset, getDatasetPreview, getItem, getModel, getPiiAllowlist, getPiiSettings, getSite, getSiteVersions, getSubagent, getUser, getUserActivity, getUserCollectionDocuments, getUserCollectionSchema, getUserCollections, getUserDataOverview, getUserStats, getWorkspace, googleLogin, importFromGitHub, insertDocuments, invalidateAllUserCache, invalidateDatasetsCache, invalidateReportsCache, invalidateSitesCache, invalidateVisualizationsCache, invalidateWorkspaceArtifacts, invalidateWorkspacesCache, invokeTool, isDevelopmentConfig, isFlowstackError, isProviderCredential, listAgents, listDataSources, listDatasets, listGitHubRepos, listLibraryItems, listMessages, listModels, listReports, listScripts, listSites, listThreads, listUsers, listVisualizations, listWorkspaces, loadCredentials, loadMessages, loadSelectedWorkspace, login, markMessageRead, marketingTemplate, mockChatHistory, mockCredentials, mockDataSources, mockDatasets, mockDelay, mockManagedUsers, mockUser, mockUserActivity, mockUserStats, mockVisualizations, mockWorkspaces, openThread, parseSSELine, parseSSEStream, previewPiiMasking, processSSEStream, promoteSiteVersion, publishStagedSite, publishToGitHub, reactivateUser, register, removeItem, removePiiAllowlistTerm, removeSiteAlias, sanitizeMermaidCode, saveCredentials, saveMessages, saveSelectedWorkspace, sendMessage, setCached, setCachedDatasets, setCachedReports, setCachedSites, setCachedVisualizations, setCachedWorkspaces, setItem, setSiteAlias, splitContentSegments, supportTemplate, suspendUser, testDataSource, updateDocuments, updatePiiSettings, updateUser, uploadFile, useAdminProviderCredentials, useAgent, useAgents, useAuth, useAuthGuard, useAutomations, useCollection, useCollectionExplorer, useConnections, useConversation, useConversations, useCurrentSession, useDataOverview, useDataSources, useDatasets, useFlowstack, useFlowstackOptional, useFlowstackStatus, useIntegrations, useIntentAgent, useLibrary, useLibraryConversations, useLibrarySearch, useLibraryTrash, useMessages, useModelPreference, useModels, useOllamaDetection, useProviderCredentials, usePublicCollection, useQuery, useRecentLibraryConversations, useReports, useSiteVersions, useSites, useSubagentInvoke, useSubagents, useThreads, useToolInvocation, useUserCollections, useUserManagement, useVisualizations, useWorkspace, validateConfig, validateConfigOrThrow, withErrorHandling };
|
|
10609
10784
|
//# sourceMappingURL=index.mjs.map
|
|
10610
10785
|
//# sourceMappingURL=index.mjs.map
|