@yushaw/sanqian-sdk 0.3.21 → 0.3.23
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 +51 -1
- package/dist/index.browser.d.mts +15 -1
- package/dist/index.browser.d.ts +15 -1
- package/dist/index.browser.js +65 -16
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +65 -16
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +85 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.browser.mjs
CHANGED
|
@@ -967,7 +967,14 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
967
967
|
}
|
|
968
968
|
async doFullConnect() {
|
|
969
969
|
this.log("Starting connection (browser mode)...");
|
|
970
|
-
|
|
970
|
+
await this.ensureHttpReady();
|
|
971
|
+
const info = this.connectionInfo || this.config.connectionInfo;
|
|
972
|
+
if (!info) {
|
|
973
|
+
throw createSDKError(
|
|
974
|
+
"NOT_RUNNING" /* NOT_RUNNING */,
|
|
975
|
+
"Connection info not available in browser mode"
|
|
976
|
+
);
|
|
977
|
+
}
|
|
971
978
|
await this.connectWithInfo(info);
|
|
972
979
|
}
|
|
973
980
|
async updateTools(tools) {
|
|
@@ -1113,6 +1120,16 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1113
1120
|
const token = info?.token;
|
|
1114
1121
|
return token ? { "X-App-Token": token } : {};
|
|
1115
1122
|
}
|
|
1123
|
+
async ensureHttpReady() {
|
|
1124
|
+
const info = this.connectionInfo || this.config.connectionInfo;
|
|
1125
|
+
if (!info) {
|
|
1126
|
+
throw createSDKError(
|
|
1127
|
+
"NOT_RUNNING" /* NOT_RUNNING */,
|
|
1128
|
+
"Connection info not available for HTTP API in browser build"
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
1131
|
+
this.connectionInfo = info;
|
|
1132
|
+
}
|
|
1116
1133
|
/**
|
|
1117
1134
|
* Get the port number for the Sanqian backend
|
|
1118
1135
|
* @throws Error if not connected
|
|
@@ -1124,6 +1141,14 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1124
1141
|
}
|
|
1125
1142
|
return info.port;
|
|
1126
1143
|
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Get the HTTP base URL for Sanqian backend.
|
|
1146
|
+
*
|
|
1147
|
+
* @throws Error if connection info is not available
|
|
1148
|
+
*/
|
|
1149
|
+
getBaseUrl() {
|
|
1150
|
+
return this.getHttpBaseUrl();
|
|
1151
|
+
}
|
|
1127
1152
|
/**
|
|
1128
1153
|
* Get conversation messages via history API (aligned with main app history)
|
|
1129
1154
|
*/
|
|
@@ -1675,7 +1700,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1675
1700
|
// Channels
|
|
1676
1701
|
// ============================================
|
|
1677
1702
|
async listChannelPlugins() {
|
|
1678
|
-
await this.
|
|
1703
|
+
await this.ensureHttpReady();
|
|
1679
1704
|
const url = `${this.getHttpBaseUrl()}/api/channels/plugins`;
|
|
1680
1705
|
const response = await fetch(url, { headers: this.getHttpAuthHeaders() });
|
|
1681
1706
|
if (!response.ok) {
|
|
@@ -1684,7 +1709,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1684
1709
|
return response.json();
|
|
1685
1710
|
}
|
|
1686
1711
|
async listChannelAccounts() {
|
|
1687
|
-
await this.
|
|
1712
|
+
await this.ensureHttpReady();
|
|
1688
1713
|
const url = `${this.getHttpBaseUrl()}/api/channels/accounts`;
|
|
1689
1714
|
const response = await fetch(url, { headers: this.getHttpAuthHeaders() });
|
|
1690
1715
|
if (!response.ok) {
|
|
@@ -1693,7 +1718,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1693
1718
|
return response.json();
|
|
1694
1719
|
}
|
|
1695
1720
|
async createChannelAccount(req) {
|
|
1696
|
-
await this.
|
|
1721
|
+
await this.ensureHttpReady();
|
|
1697
1722
|
const url = `${this.getHttpBaseUrl()}/api/channels/accounts`;
|
|
1698
1723
|
const response = await fetch(url, {
|
|
1699
1724
|
method: "POST",
|
|
@@ -1707,7 +1732,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1707
1732
|
return response.json();
|
|
1708
1733
|
}
|
|
1709
1734
|
async getChannelAccount(id) {
|
|
1710
|
-
await this.
|
|
1735
|
+
await this.ensureHttpReady();
|
|
1711
1736
|
const url = `${this.getHttpBaseUrl()}/api/channels/accounts/${encodeURIComponent(id)}`;
|
|
1712
1737
|
const response = await fetch(url, { headers: this.getHttpAuthHeaders() });
|
|
1713
1738
|
if (!response.ok) {
|
|
@@ -1716,7 +1741,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1716
1741
|
return response.json();
|
|
1717
1742
|
}
|
|
1718
1743
|
async updateChannelAccount(id, req) {
|
|
1719
|
-
await this.
|
|
1744
|
+
await this.ensureHttpReady();
|
|
1720
1745
|
const url = `${this.getHttpBaseUrl()}/api/channels/accounts/${encodeURIComponent(id)}`;
|
|
1721
1746
|
const response = await fetch(url, {
|
|
1722
1747
|
method: "PUT",
|
|
@@ -1730,7 +1755,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1730
1755
|
return response.json();
|
|
1731
1756
|
}
|
|
1732
1757
|
async deleteChannelAccount(id) {
|
|
1733
|
-
await this.
|
|
1758
|
+
await this.ensureHttpReady();
|
|
1734
1759
|
const url = `${this.getHttpBaseUrl()}/api/channels/accounts/${encodeURIComponent(id)}`;
|
|
1735
1760
|
const response = await fetch(url, { method: "DELETE", headers: this.getHttpAuthHeaders() });
|
|
1736
1761
|
if (!response.ok) {
|
|
@@ -1738,7 +1763,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1738
1763
|
}
|
|
1739
1764
|
}
|
|
1740
1765
|
async startChannelAccount(id) {
|
|
1741
|
-
await this.
|
|
1766
|
+
await this.ensureHttpReady();
|
|
1742
1767
|
const url = `${this.getHttpBaseUrl()}/api/channels/accounts/${encodeURIComponent(id)}/start`;
|
|
1743
1768
|
const response = await fetch(url, { method: "POST", headers: this.getHttpAuthHeaders() });
|
|
1744
1769
|
if (!response.ok) {
|
|
@@ -1748,7 +1773,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1748
1773
|
return response.json();
|
|
1749
1774
|
}
|
|
1750
1775
|
async stopChannelAccount(id) {
|
|
1751
|
-
await this.
|
|
1776
|
+
await this.ensureHttpReady();
|
|
1752
1777
|
const url = `${this.getHttpBaseUrl()}/api/channels/accounts/${encodeURIComponent(id)}/stop`;
|
|
1753
1778
|
const response = await fetch(url, { method: "POST", headers: this.getHttpAuthHeaders() });
|
|
1754
1779
|
if (!response.ok) {
|
|
@@ -1757,7 +1782,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1757
1782
|
return response.json();
|
|
1758
1783
|
}
|
|
1759
1784
|
async getChannelStatus(id) {
|
|
1760
|
-
await this.
|
|
1785
|
+
await this.ensureHttpReady();
|
|
1761
1786
|
const url = `${this.getHttpBaseUrl()}/api/channels/accounts/${encodeURIComponent(id)}/status`;
|
|
1762
1787
|
const response = await fetch(url, { headers: this.getHttpAuthHeaders() });
|
|
1763
1788
|
if (!response.ok) {
|
|
@@ -1766,7 +1791,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1766
1791
|
return response.json();
|
|
1767
1792
|
}
|
|
1768
1793
|
async probeChannelAccount(id) {
|
|
1769
|
-
await this.
|
|
1794
|
+
await this.ensureHttpReady();
|
|
1770
1795
|
const url = `${this.getHttpBaseUrl()}/api/channels/accounts/${encodeURIComponent(id)}/probe`;
|
|
1771
1796
|
const response = await fetch(url, { method: "POST", headers: this.getHttpAuthHeaders() });
|
|
1772
1797
|
if (!response.ok) {
|
|
@@ -1775,8 +1800,32 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1775
1800
|
}
|
|
1776
1801
|
return response.json();
|
|
1777
1802
|
}
|
|
1803
|
+
async probeChannelConfig(req) {
|
|
1804
|
+
await this.ensureHttpReady();
|
|
1805
|
+
const url = `${this.getHttpBaseUrl()}/api/channels/probe-config`;
|
|
1806
|
+
const response = await fetch(url, {
|
|
1807
|
+
method: "POST",
|
|
1808
|
+
headers: { ...this.getHttpAuthHeaders(), "Content-Type": "application/json" },
|
|
1809
|
+
body: JSON.stringify(req)
|
|
1810
|
+
});
|
|
1811
|
+
if (!response.ok) {
|
|
1812
|
+
const detail = await response.text();
|
|
1813
|
+
throw createSDKError("REQUEST_FAILED" /* REQUEST_FAILED */, `Failed to probe channel config: ${detail}`);
|
|
1814
|
+
}
|
|
1815
|
+
return response.json();
|
|
1816
|
+
}
|
|
1817
|
+
async getChannelConfigSchema(channelType) {
|
|
1818
|
+
await this.ensureHttpReady();
|
|
1819
|
+
const url = `${this.getHttpBaseUrl()}/api/channels/plugins/${encodeURIComponent(channelType)}/config-schema`;
|
|
1820
|
+
const response = await fetch(url, { headers: this.getHttpAuthHeaders() });
|
|
1821
|
+
if (!response.ok) {
|
|
1822
|
+
const detail = await response.text();
|
|
1823
|
+
throw createSDKError("REQUEST_FAILED" /* REQUEST_FAILED */, `Failed to get channel config schema: ${detail}`);
|
|
1824
|
+
}
|
|
1825
|
+
return response.json();
|
|
1826
|
+
}
|
|
1778
1827
|
async listChannelBindings(accountId) {
|
|
1779
|
-
await this.
|
|
1828
|
+
await this.ensureHttpReady();
|
|
1780
1829
|
const params = accountId ? `?account_id=${encodeURIComponent(accountId)}` : "";
|
|
1781
1830
|
const url = `${this.getHttpBaseUrl()}/api/channels/bindings${params}`;
|
|
1782
1831
|
const response = await fetch(url, { headers: this.getHttpAuthHeaders() });
|
|
@@ -1786,7 +1835,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1786
1835
|
return response.json();
|
|
1787
1836
|
}
|
|
1788
1837
|
async createChannelBinding(req) {
|
|
1789
|
-
await this.
|
|
1838
|
+
await this.ensureHttpReady();
|
|
1790
1839
|
const url = `${this.getHttpBaseUrl()}/api/channels/bindings`;
|
|
1791
1840
|
const response = await fetch(url, {
|
|
1792
1841
|
method: "POST",
|
|
@@ -1800,7 +1849,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1800
1849
|
return response.json();
|
|
1801
1850
|
}
|
|
1802
1851
|
async updateChannelBinding(id, req) {
|
|
1803
|
-
await this.
|
|
1852
|
+
await this.ensureHttpReady();
|
|
1804
1853
|
const url = `${this.getHttpBaseUrl()}/api/channels/bindings/${encodeURIComponent(id)}`;
|
|
1805
1854
|
const response = await fetch(url, {
|
|
1806
1855
|
method: "PUT",
|
|
@@ -1814,7 +1863,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1814
1863
|
return response.json();
|
|
1815
1864
|
}
|
|
1816
1865
|
async deleteChannelBinding(id) {
|
|
1817
|
-
await this.
|
|
1866
|
+
await this.ensureHttpReady();
|
|
1818
1867
|
const url = `${this.getHttpBaseUrl()}/api/channels/bindings/${encodeURIComponent(id)}`;
|
|
1819
1868
|
const response = await fetch(url, { method: "DELETE", headers: this.getHttpAuthHeaders() });
|
|
1820
1869
|
if (!response.ok) {
|
|
@@ -1822,7 +1871,7 @@ var SanqianSDK = class _SanqianSDK {
|
|
|
1822
1871
|
}
|
|
1823
1872
|
}
|
|
1824
1873
|
async sendChannelMessage(req) {
|
|
1825
|
-
await this.
|
|
1874
|
+
await this.ensureHttpReady();
|
|
1826
1875
|
const url = `${this.getHttpBaseUrl()}/api/channels/send`;
|
|
1827
1876
|
const response = await fetch(url, {
|
|
1828
1877
|
method: "POST",
|