@liveblocks/node 3.4.2 → 3.5.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.
- package/dist/index.cjs +281 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +238 -1
- package/dist/index.d.ts +238 -1
- package/dist/index.js +281 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ var _core = require('@liveblocks/core');
|
|
|
3
3
|
|
|
4
4
|
// src/version.ts
|
|
5
5
|
var PKG_NAME = "@liveblocks/node";
|
|
6
|
-
var PKG_VERSION = "3.
|
|
6
|
+
var PKG_VERSION = "3.5.1";
|
|
7
7
|
var PKG_FORMAT = "cjs";
|
|
8
8
|
|
|
9
9
|
// src/client.ts
|
|
@@ -282,6 +282,29 @@ function inflateRoomData(room) {
|
|
|
282
282
|
lastConnectionAt
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
|
+
function inflateAiCopilot(copilot) {
|
|
286
|
+
return {
|
|
287
|
+
...copilot,
|
|
288
|
+
createdAt: new Date(copilot.createdAt),
|
|
289
|
+
updatedAt: new Date(copilot.updatedAt),
|
|
290
|
+
lastUsedAt: copilot.lastUsedAt ? new Date(copilot.lastUsedAt) : void 0
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function inflateKnowledgeSource(source) {
|
|
294
|
+
return {
|
|
295
|
+
...source,
|
|
296
|
+
createdAt: new Date(source.createdAt),
|
|
297
|
+
updatedAt: new Date(source.updatedAt),
|
|
298
|
+
lastIndexedAt: new Date(source.lastIndexedAt)
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function inflateWebKnowledgeSourceLink(link) {
|
|
302
|
+
return {
|
|
303
|
+
...link,
|
|
304
|
+
createdAt: new Date(link.createdAt),
|
|
305
|
+
lastIndexedAt: new Date(link.lastIndexedAt)
|
|
306
|
+
};
|
|
307
|
+
}
|
|
285
308
|
var Liveblocks = class {
|
|
286
309
|
#secret;
|
|
287
310
|
#baseUrl;
|
|
@@ -1711,6 +1734,263 @@ var Liveblocks = class {
|
|
|
1711
1734
|
throw await LiveblocksError.from(res);
|
|
1712
1735
|
}
|
|
1713
1736
|
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Returns a paginated list of AI copilots. The copilots are returned sorted by creation date, from newest to oldest.
|
|
1739
|
+
* @param params.limit (optional) A limit on the number of copilots to return. The limit can range between 1 and 100, and defaults to 20.
|
|
1740
|
+
* @param params.startingAfter (optional) A cursor used for pagination. You get the value from the response of the previous page.
|
|
1741
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1742
|
+
* @returns A paginated list of AI copilots.
|
|
1743
|
+
*/
|
|
1744
|
+
async getAiCopilots(params = {}, options) {
|
|
1745
|
+
const res = await this.#get(
|
|
1746
|
+
_core.url`/v2/ai/copilots`,
|
|
1747
|
+
{
|
|
1748
|
+
limit: params.limit,
|
|
1749
|
+
startingAfter: params.startingAfter
|
|
1750
|
+
},
|
|
1751
|
+
options
|
|
1752
|
+
);
|
|
1753
|
+
if (!res.ok) {
|
|
1754
|
+
throw await LiveblocksError.from(res);
|
|
1755
|
+
}
|
|
1756
|
+
const page = await res.json();
|
|
1757
|
+
return {
|
|
1758
|
+
...page,
|
|
1759
|
+
data: page.data.map(inflateAiCopilot)
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
/**
|
|
1763
|
+
* Creates an AI copilot.
|
|
1764
|
+
* @param params The parameters to create the copilot with.
|
|
1765
|
+
* @returns The created copilot.
|
|
1766
|
+
*/
|
|
1767
|
+
async createAiCopilot(params, options) {
|
|
1768
|
+
const res = await this.#post(_core.url`/v2/ai/copilots`, params, options);
|
|
1769
|
+
if (!res.ok) {
|
|
1770
|
+
throw await LiveblocksError.from(res);
|
|
1771
|
+
}
|
|
1772
|
+
const data = await res.json();
|
|
1773
|
+
return inflateAiCopilot(data);
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Returns an AI copilot with the given id.
|
|
1777
|
+
* @param copilotId The id of the copilot to return.
|
|
1778
|
+
* @returns The copilot with the given id.
|
|
1779
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1780
|
+
*/
|
|
1781
|
+
async getAiCopilot(copilotId, options) {
|
|
1782
|
+
const res = await this.#get(
|
|
1783
|
+
_core.url`/v2/ai/copilots/${copilotId}`,
|
|
1784
|
+
void 0,
|
|
1785
|
+
options
|
|
1786
|
+
);
|
|
1787
|
+
if (!res.ok) {
|
|
1788
|
+
throw await LiveblocksError.from(res);
|
|
1789
|
+
}
|
|
1790
|
+
const data = await res.json();
|
|
1791
|
+
return inflateAiCopilot(data);
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Updates an AI copilot with the given id.
|
|
1795
|
+
* @param copilotId The id of the copilot to update.
|
|
1796
|
+
* @param params The parameters to update the copilot with.
|
|
1797
|
+
* @returns The updated copilot.
|
|
1798
|
+
*/
|
|
1799
|
+
async updateAiCopilot(copilotId, params, options) {
|
|
1800
|
+
const res = await this.#post(
|
|
1801
|
+
_core.url`/v2/ai/copilots/${copilotId}`,
|
|
1802
|
+
params,
|
|
1803
|
+
options
|
|
1804
|
+
);
|
|
1805
|
+
if (!res.ok) {
|
|
1806
|
+
throw await LiveblocksError.from(res);
|
|
1807
|
+
}
|
|
1808
|
+
const data = await res.json();
|
|
1809
|
+
return inflateAiCopilot(data);
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Deletes an AI copilot with the given id. A deleted copilot is no longer accessible from the API or the dashboard and it cannot be restored.
|
|
1813
|
+
* @param copilotId The id of the copilot to delete.
|
|
1814
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1815
|
+
*/
|
|
1816
|
+
async deleteAiCopilot(copilotId, options) {
|
|
1817
|
+
const res = await this.#delete(_core.url`/v2/ai/copilots/${copilotId}`, options);
|
|
1818
|
+
if (!res.ok) {
|
|
1819
|
+
throw await LiveblocksError.from(res);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Creates a web knowledge source.
|
|
1824
|
+
* @param params.url The URL of the web knowledge source.
|
|
1825
|
+
* @param params.type The type of the web knowledge source: "individual_link", "crawl" or "sitemap".
|
|
1826
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1827
|
+
* @returns The id of the created web knowledge source.
|
|
1828
|
+
*/
|
|
1829
|
+
async createWebKnowledgeSource(params, options) {
|
|
1830
|
+
const res = await this.#post(
|
|
1831
|
+
_core.url`/v2/ai/copilots/${params.copilotId}/knowledge/web`,
|
|
1832
|
+
params,
|
|
1833
|
+
options
|
|
1834
|
+
);
|
|
1835
|
+
if (!res.ok) {
|
|
1836
|
+
throw await LiveblocksError.from(res);
|
|
1837
|
+
}
|
|
1838
|
+
const data = await res.json();
|
|
1839
|
+
return data;
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Creates a file knowledge source.
|
|
1843
|
+
* @param params.copilotId The id of the copilot.
|
|
1844
|
+
* @param params.name The name of the file knowledge source.
|
|
1845
|
+
* @param params.file The file to create the knowledge source from.
|
|
1846
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1847
|
+
* @returns The id of the created file knowledge source.
|
|
1848
|
+
*/
|
|
1849
|
+
async createFileKnowledgeSource(params, options) {
|
|
1850
|
+
const fetch = await fetchPolyfill();
|
|
1851
|
+
const res = await fetch(
|
|
1852
|
+
_core.urljoin.call(void 0,
|
|
1853
|
+
this.#baseUrl,
|
|
1854
|
+
_core.url`/v2/ai/copilots/${params.copilotId}/knowledge/file/${params.file.name}`
|
|
1855
|
+
),
|
|
1856
|
+
{
|
|
1857
|
+
method: "PUT",
|
|
1858
|
+
body: params.file,
|
|
1859
|
+
headers: {
|
|
1860
|
+
Authorization: `Bearer ${this.#secret}`,
|
|
1861
|
+
"Content-Type": params.file.type,
|
|
1862
|
+
"Content-Length": String(params.file.size)
|
|
1863
|
+
},
|
|
1864
|
+
signal: _optionalChain([options, 'optionalAccess', _35 => _35.signal])
|
|
1865
|
+
}
|
|
1866
|
+
);
|
|
1867
|
+
if (!res.ok) {
|
|
1868
|
+
throw await LiveblocksError.from(res);
|
|
1869
|
+
}
|
|
1870
|
+
const data = await res.json();
|
|
1871
|
+
return data;
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* Deletes a file knowledge source.
|
|
1875
|
+
* @param params.copilotId The id of the copilot.
|
|
1876
|
+
* @param params.knowledgeSourceId The id of the knowledge source to delete.
|
|
1877
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1878
|
+
*/
|
|
1879
|
+
async deleteFileKnowledgeSource(params, options) {
|
|
1880
|
+
const res = await this.#delete(
|
|
1881
|
+
_core.url`/v2/ai/copilots/${params.copilotId}/knowledge/file/${params.knowledgeSourceId}`,
|
|
1882
|
+
options
|
|
1883
|
+
);
|
|
1884
|
+
if (!res.ok) {
|
|
1885
|
+
throw await LiveblocksError.from(res);
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
/**
|
|
1889
|
+
* Deletes a web knowledge source.
|
|
1890
|
+
* @param params.copilotId The id of the copilot.
|
|
1891
|
+
* @param params.knowledgeSourceId The id of the knowledge source to delete.
|
|
1892
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1893
|
+
*/
|
|
1894
|
+
async deleteWebKnowledgeSource(params, options) {
|
|
1895
|
+
const res = await this.#delete(
|
|
1896
|
+
_core.url`/v2/ai/copilots/${params.copilotId}/knowledge/web/${params.knowledgeSourceId}`,
|
|
1897
|
+
options
|
|
1898
|
+
);
|
|
1899
|
+
if (!res.ok) {
|
|
1900
|
+
throw await LiveblocksError.from(res);
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
/**
|
|
1904
|
+
* Returns a paginated list of knowledge sources.
|
|
1905
|
+
* @param params.copilotId The id of the copilot.
|
|
1906
|
+
* @param params.limit (optional) A limit on the number of knowledge sources to return. The limit can range between 1 and 100, and defaults to 20.
|
|
1907
|
+
* @param params.startingAfter (optional) A cursor used for pagination. You get the value from the response of the previous page.
|
|
1908
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1909
|
+
* @returns A paginated list of knowledge sources.
|
|
1910
|
+
*/
|
|
1911
|
+
async getKnowledgeSources(params, options) {
|
|
1912
|
+
const res = await this.#get(
|
|
1913
|
+
_core.url`/v2/ai/copilots/${params.copilotId}/knowledge`,
|
|
1914
|
+
{
|
|
1915
|
+
limit: params.limit,
|
|
1916
|
+
startingAfter: params.startingAfter
|
|
1917
|
+
},
|
|
1918
|
+
options
|
|
1919
|
+
);
|
|
1920
|
+
if (!res.ok) {
|
|
1921
|
+
throw await LiveblocksError.from(res);
|
|
1922
|
+
}
|
|
1923
|
+
const page = await res.json();
|
|
1924
|
+
return {
|
|
1925
|
+
...page,
|
|
1926
|
+
data: page.data.map(inflateKnowledgeSource)
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
/**
|
|
1930
|
+
* Returns a knowledge source with the given id.
|
|
1931
|
+
* @param params.copilotId The id of the copilot.
|
|
1932
|
+
* @param params.knowledgeSourceId The id of the knowledge source to return.
|
|
1933
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1934
|
+
* @returns The knowledge source.
|
|
1935
|
+
*/
|
|
1936
|
+
async getKnowledgeSource(params, options) {
|
|
1937
|
+
const res = await this.#get(
|
|
1938
|
+
_core.url`/v2/ai/copilots/${params.copilotId}/knowledge/${params.knowledgeSourceId}`,
|
|
1939
|
+
void 0,
|
|
1940
|
+
options
|
|
1941
|
+
);
|
|
1942
|
+
if (!res.ok) {
|
|
1943
|
+
throw await LiveblocksError.from(res);
|
|
1944
|
+
}
|
|
1945
|
+
const data = await res.json();
|
|
1946
|
+
return inflateKnowledgeSource(data);
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* Returns the content of a file knowledge source.
|
|
1950
|
+
* @param params.copilotId The id of the copilot.
|
|
1951
|
+
* @param params.knowledgeSourceId The id of the knowledge source.
|
|
1952
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1953
|
+
* @returns The content of the file knowledge source.
|
|
1954
|
+
*/
|
|
1955
|
+
async getFileKnowledgeSourceMarkdown(params, options) {
|
|
1956
|
+
const res = await this.#get(
|
|
1957
|
+
_core.url`/v2/ai/copilots/${params.copilotId}/knowledge/file/${params.knowledgeSourceId}`,
|
|
1958
|
+
void 0,
|
|
1959
|
+
options
|
|
1960
|
+
);
|
|
1961
|
+
if (!res.ok) {
|
|
1962
|
+
throw await LiveblocksError.from(res);
|
|
1963
|
+
}
|
|
1964
|
+
const data = await res.json();
|
|
1965
|
+
return data.content;
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* Returns a paginated list of web knowledge source links.
|
|
1969
|
+
* @param params.copilotId The id of the copilot.
|
|
1970
|
+
* @param params.knowledgeSourceId The id of the knowledge source.
|
|
1971
|
+
* @param params.limit (optional) A limit on the number of links to return. The limit can range between 1 and 100, and defaults to 20.
|
|
1972
|
+
* @param params.startingAfter (optional) A cursor used for pagination. You get the value from the response of the previous page.
|
|
1973
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1974
|
+
* @returns A paginated list of web knowledge source links.
|
|
1975
|
+
*/
|
|
1976
|
+
async getWebKnowledgeSourceLinks(params, options) {
|
|
1977
|
+
const res = await this.#get(
|
|
1978
|
+
_core.url`/v2/ai/copilots/${params.copilotId}/knowledge/web/${params.knowledgeSourceId}/links`,
|
|
1979
|
+
{
|
|
1980
|
+
limit: params.limit,
|
|
1981
|
+
startingAfter: params.startingAfter
|
|
1982
|
+
},
|
|
1983
|
+
options
|
|
1984
|
+
);
|
|
1985
|
+
if (!res.ok) {
|
|
1986
|
+
throw await LiveblocksError.from(res);
|
|
1987
|
+
}
|
|
1988
|
+
const page = await res.json();
|
|
1989
|
+
return {
|
|
1990
|
+
...page,
|
|
1991
|
+
data: page.data.map(inflateWebKnowledgeSourceLink)
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1714
1994
|
};
|
|
1715
1995
|
var LiveblocksError = class _LiveblocksError extends Error {
|
|
1716
1996
|
|