@tool-bridge/server 0.16.0 → 0.17.0
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/{airtable-S3T4TAN7.js → airtable-NOSOMOVB.js} +106 -114
- package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-BHIJ4LW5.js} +25 -16
- package/dist/{amap-LGVGNPML.js → amap-QRLP4TWZ.js} +114 -123
- package/dist/{anthropic-27RFZO35.js → anthropic-IEOI36EV.js} +34 -56
- package/dist/{apify-6WLYAIAS.js → apify-3CCYTQVK.js} +31 -49
- package/dist/{brave_search-K2SVJ66F.js → brave_search-PZNYDQG7.js} +52 -77
- package/dist/chunk-JXHMDBAY.js +45 -0
- package/dist/chunk-LMLX3DJF.js +50 -0
- package/dist/{chunk-YB2FLNWI.js → chunk-RVWZN3CI.js} +2103 -1775
- package/dist/{chunk-BB6ZLMTU.js → chunk-TLNUIPFZ.js} +492 -300
- package/dist/chunk-U5UHT7CX.js +977 -0
- package/dist/chunk-U67V476Y.js +35 -0
- package/dist/chunk-WW2IMPQK.js +283 -0
- package/dist/{chunk-VK3V2WTY.js → chunk-YASUMV2K.js} +4 -6
- package/dist/{circleci-WV3ITU7Q.js → circleci-VSJ4O5FC.js} +36 -55
- package/dist/{clerk-NFQEFKS4.js → clerk-CC2JZBZI.js} +60 -80
- package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-PJEBSEYQ.js} +90 -113
- package/dist/{cohere-5KEW7LWT.js → cohere-KBACYSPF.js} +33 -49
- package/dist/{confluence-SZE63S46.js → confluence-2PX3O7G5.js} +79 -115
- package/dist/{convertapi-QPG2JC5K.js → convertapi-BVOTD2PJ.js} +13 -16
- package/dist/{currencyapi-UO2APQRY.js → currencyapi-6ZQ2VNQ7.js} +30 -53
- package/dist/{deepseek-LJELIMM3.js → deepseek-MB3WVVTB.js} +30 -38
- package/dist/{docker_hub-2MFXSBOF.js → docker_hub-7CLQL2IJ.js} +141 -157
- package/dist/{dropbox-GQYNTTVA.js → dropbox-VFYDVUNK.js} +134 -141
- package/dist/{dub-KI2LHXST.js → dub-QN3EETJY.js} +61 -93
- package/dist/{e2b-WO6ISY3C.js → e2b-NKC3Y776.js} +39 -69
- package/dist/{exa-IZ7B3BPT.js → exa-KKZ6F25K.js} +49 -77
- package/dist/{fal_ai-LTMF36GJ.js → fal_ai-25LYJD2O.js} +37 -44
- package/dist/{feishu-WM7SLSFD.js → feishu-NRT55B3Q.js} +4 -6
- package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-3W3XXUG4.js} +4 -5
- package/dist/{figma-2Z274VQZ.js → figma-4FLP35TC.js} +56 -81
- package/dist/{firehydrant-IFI4R65V.js → firehydrant-BLXPLZ3X.js} +40 -53
- package/dist/{fixer-BCCZEB3D.js → fixer-4OR62TGE.js} +31 -43
- package/dist/{fly-755FXYB5.js → fly-MYCKOZZK.js} +50 -66
- package/dist/{front-4FZKKXXK.js → front-3DFYVMF3.js} +43 -66
- package/dist/{geocodio-WYKDJ3DP.js → geocodio-CXMD6VKA.js} +37 -63
- package/dist/{ghost-5BNQTCOH.js → ghost-4UUE737W.js} +51 -57
- package/dist/{github-ULELF5VX.js → github-WFS2ON2N.js} +48 -41
- package/dist/{gmail-G34WT64J.js → gmail-KW7FXA7A.js} +26 -36
- package/dist/{googlecalendar-BQU255SC.js → googlecalendar-AMH5JQMC.js} +57 -78
- package/dist/{googledocs-HPCNQXYJ.js → googledocs-R5VA6CKD.js} +14 -22
- package/dist/{grafana-VOV24FIC.js → grafana-IT6DWIVB.js} +95 -122
- package/dist/{graphhopper-D5RXW6AP.js → graphhopper-TYFDJZWC.js} +32 -46
- package/dist/index.d.ts +57 -50
- package/dist/index.js +4 -3
- package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-GJ4HXVXO.js} +35 -42
- package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-OAGR6PRF.js} +40 -60
- package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-BCKAMDGL.js} +30 -42
- package/dist/{jina_ai-E6UXFV2P.js → jina_ai-N3NXRVIZ.js} +32 -58
- package/dist/{jira-ZDSXGQ6W.js → jira-CHLBKWLO.js} +116 -126
- package/dist/{langsmith-TIFJRREW.js → langsmith-OIKOTPY3.js} +101 -121
- package/dist/{lemlist-DASEMJMA.js → lemlist-VAKYPKS3.js} +57 -68
- package/dist/{linear-KE6UP4SP.js → linear-Q6QTPJ5R.js} +109 -118
- package/dist/{logsnag-IMNDN4R5.js → logsnag-SQOQBTES.js} +31 -48
- package/dist/main.js +103 -102
- package/dist/{mattermost-HHHMUXQA.js → mattermost-G2KBEICM.js} +45 -62
- package/dist/{mem0-D2FGGOIY.js → mem0-D2FPLYDX.js} +72 -98
- package/dist/{memos-4OVIGFPH.js → memos-76PTWV5V.js} +68 -122
- package/dist/{metabase-33WCX5YD.js → metabase-TWSIDVBM.js} +47 -60
- package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-TP7TQUEJ.js} +35 -40
- package/dist/{mother_duck-M6VWS2VH.js → mother_duck-UXY5THYU.js} +42 -62
- package/dist/{ngrok-Z2PKQBHH.js → ngrok-RZW2ISJK.js} +42 -58
- package/dist/{notes-SS4RPC4K.js → notes-B2I6FWK2.js} +3 -5
- package/dist/{notion-FJCNQ6I7.js → notion-QOKRUE6M.js} +83 -97
- package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-ODLFWEJ7.js} +35 -39
- package/dist/{openai-JODZ4GKT.js → openai-ZPBPPPGT.js} +51 -55
- package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-EOI5UJKT.js} +61 -79
- package/dist/{openrouter-Q5XXEJZ7.js → openrouter-BUWLF3BG.js} +41 -55
- package/dist/{outline-RT2EHJ2X.js → outline-NXS3QRXO.js} +89 -104
- package/dist/{paddle-OF2V7GAC.js → paddle-T4MSKQ76.js} +34 -49
- package/dist/{perplexity-LNZEWLHG.js → perplexity-WW5N2LW7.js} +33 -50
- package/dist/{pinecone-JSJIXZYN.js → pinecone-RY5AZPQM.js} +65 -91
- package/dist/{pipedrive-D4CKVUXR.js → pipedrive-OHYQNZTU.js} +37 -59
- package/dist/{polar-M7ZYP6UR.js → polar-XZIAHXS5.js} +43 -53
- package/dist/{posthog-YV7CZOH4.js → posthog-DTPTWORY.js} +58 -77
- package/dist/{postmark-KYHLECRG.js → postmark-F4UCQKC3.js} +52 -71
- package/dist/{prerender-HCMHBKV2.js → prerender-P3Y2MLIC.js} +32 -50
- package/dist/{pubmed-WYVLCCN3.js → pubmed-RHU3GXFB.js} +28 -60
- package/dist/{railway-TWIRD5KR.js → railway-VB6SRLI6.js} +32 -39
- package/dist/{readwise-UZ467IQ7.js → readwise-DIMSKJZR.js} +62 -78
- package/dist/{render-MECUC5CC.js → render-XCCDCEEK.js} +48 -64
- package/dist/{replicate-A5MEK3SW.js → replicate-IUEOQ4JC.js} +41 -58
- package/dist/{resend-BC6EAWJQ.js → resend-N5MJZH5E.js} +27 -37
- package/dist/{rootly-ZM3QDUIS.js → rootly-25T4NBTU.js} +64 -76
- package/dist/{scrapfly-WAML42QJ.js → scrapfly-PK4XFXUA.js} +45 -51
- package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-ITPBMWQU.js} +25 -33
- package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-5U6ZYPKR.js} +29 -47
- package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-BJGCI2MU.js} +37 -56
- package/dist/{sentry-OKBPSTDM.js → sentry-63IC263P.js} +66 -85
- package/dist/{shodan-PPC6DYU4.js → shodan-2WBIFHFN.js} +42 -53
- package/dist/{shopify-EWGUHBXO.js → shopify-XLLJRAGM.js} +32 -49
- package/dist/{stripe-6RPDPC5W.js → stripe-WLVCY3UN.js} +4 -5
- package/dist/{supabase-SK7DQ42N.js → supabase-BKNZ35ER.js} +69 -88
- package/dist/{tavily-YCG5VQMH.js → tavily-YFSDEUTL.js} +37 -62
- package/dist/{telegram-2OES5FYB.js → telegram-FC35W74G.js} +168 -177
- package/dist/{telnyx-POOSBBR4.js → telnyx-MI32XZUG.js} +30 -50
- package/dist/{todoist-M7YD6YSS.js → todoist-4ZFJKZC6.js} +77 -89
- package/dist/{trello-IS6V5W3E.js → trello-UOGFNMK4.js} +108 -122
- package/dist/{turso-RCFHUFVH.js → turso-YTSTW3ZS.js} +52 -64
- package/dist/{twilio-OS2RXFGO.js → twilio-XAJDFUQH.js} +48 -55
- package/dist/{umami-PQ2SJ2LN.js → umami-ZVIUBPAI.js} +49 -69
- package/dist/{unsplash-C6BPZO4E.js → unsplash-IU3PLDNS.js} +35 -52
- package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-3EYJW7SY.js} +28 -40
- package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-PJG2ASRU.js} +11 -12
- package/dist/{v2ex-R4JWTEHN.js → v2ex-KFQWWGFC.js} +36 -61
- package/dist/{vercel-FZVYUOQD.js → vercel-I2ZDOQRL.js} +124 -150
- package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
- package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-BNXOJMB6.js} +26 -34
- package/dist/{wordpress-XRWGO6LG.js → wordpress-36D7BSMP.js} +87 -104
- package/dist/{workos-WR4NKOYL.js → workos-6X4JJRRC.js} +37 -56
- package/dist/{zhihu-BKZIB3WA.js → zhihu-CIXKCHIU.js} +35 -57
- package/package.json +5 -5
- package/dist/chunk-2O27H4Y2.js +0 -183
- package/dist/chunk-GKX72JMJ.js +0 -378
- package/dist/chunk-MLKGABMK.js +0 -9
|
@@ -1,118 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-WW2IMPQK.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
compactDefined,
|
|
7
|
+
trimmedText
|
|
8
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
9
|
import {
|
|
2
10
|
createProviderPlugin,
|
|
3
11
|
requireApiKey,
|
|
4
12
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
13
|
+
} from "./chunk-YASUMV2K.js";
|
|
14
|
+
import "./chunk-U5UHT7CX.js";
|
|
10
15
|
import {
|
|
11
16
|
TBError,
|
|
12
17
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-RVWZN3CI.js";
|
|
19
|
+
import "./chunk-U67V476Y.js";
|
|
15
20
|
|
|
16
21
|
// ../plugins/src/mem0/api.ts
|
|
17
22
|
var SERVICE = "mem0";
|
|
18
23
|
var API_BASE = "https://api.mem0.ai";
|
|
19
|
-
|
|
20
|
-
if (typeof value !== "string") return void 0;
|
|
21
|
-
const trimmed = value.trim();
|
|
22
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
23
|
-
}
|
|
24
|
-
function record(value) {
|
|
25
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
26
|
-
}
|
|
27
|
-
function compact(input) {
|
|
28
|
-
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
|
|
29
|
-
}
|
|
24
|
+
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
30
25
|
function requireText(value, field) {
|
|
31
|
-
const result =
|
|
26
|
+
const result = trimmedText(value);
|
|
32
27
|
if (result === void 0) throw new TBError("invalid_argument", `${field} \u662F\u5FC5\u586B\u7684`);
|
|
33
28
|
return result;
|
|
34
29
|
}
|
|
35
|
-
function errorMessage(
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
payload = record(JSON.parse(body));
|
|
40
|
-
} catch {
|
|
41
|
-
return body;
|
|
42
|
-
}
|
|
43
|
-
if (payload === void 0) return body;
|
|
30
|
+
function errorMessage(value, status) {
|
|
31
|
+
if (typeof value === "string") return value === "" ? `Mem0 \u8FD4\u56DE HTTP ${status}` : value;
|
|
32
|
+
const payload = asJsonObject(value);
|
|
33
|
+
if (payload === void 0) return `Mem0 \u8FD4\u56DE HTTP ${status}`;
|
|
44
34
|
const detail = payload.detail;
|
|
45
35
|
if (typeof detail === "string" && detail !== "") return detail;
|
|
46
36
|
if (Array.isArray(detail)) {
|
|
47
|
-
const parts = detail.map((item) => typeof
|
|
37
|
+
const parts = detail.map((item) => typeof asJsonObject(item)?.msg === "string" ? asJsonObject(item)?.msg : void 0).filter((item) => item !== void 0 && item !== "");
|
|
48
38
|
if (parts.length > 0) return parts.join("; ");
|
|
49
39
|
}
|
|
50
40
|
if (typeof payload.message === "string" && payload.message !== "") return payload.message;
|
|
51
41
|
if (typeof payload.error === "string" && payload.error !== "") return payload.error;
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
function buildUrl(path, query) {
|
|
55
|
-
const url = new URL(`${API_BASE}${path}`);
|
|
56
|
-
for (const [key, value] of Object.entries(query ?? {})) {
|
|
57
|
-
if (value === void 0) continue;
|
|
58
|
-
url.searchParams.set(key, String(value));
|
|
59
|
-
}
|
|
60
|
-
return url.toString();
|
|
42
|
+
return `Mem0 \u8FD4\u56DE HTTP ${status}`;
|
|
61
43
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
authorization: `Token ${requireApiKey(ctx, SERVICE)}`,
|
|
66
|
-
accept: "application/json"
|
|
67
|
-
};
|
|
68
|
-
if (input.body !== void 0) headers["content-type"] = "application/json";
|
|
69
|
-
return guardedFetch(buildUrl(input.path, input.query), {
|
|
44
|
+
function execute(ctx, input) {
|
|
45
|
+
return http.request({
|
|
46
|
+
path: input.path,
|
|
70
47
|
method: input.method ?? "GET",
|
|
71
|
-
|
|
72
|
-
|
|
48
|
+
query: Object.entries(input.query ?? {}),
|
|
49
|
+
headers: {
|
|
50
|
+
accept: "application/json",
|
|
51
|
+
// Token 而非 Bearer —— Mem0 用的是 DRF 的 TokenAuthentication。
|
|
52
|
+
authorization: `Token ${requireApiKey(ctx, SERVICE)}`
|
|
53
|
+
},
|
|
54
|
+
...input.body === void 0 ? {} : { json: input.body },
|
|
55
|
+
invalidJson: "text",
|
|
56
|
+
mapError: ({ data, status }) => upstreamError(status, errorMessage(data, status))
|
|
73
57
|
});
|
|
74
58
|
}
|
|
75
59
|
async function request(ctx, input) {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
return JSON.parse(body);
|
|
82
|
-
} catch {
|
|
83
|
-
return { raw: body };
|
|
60
|
+
const result = await execute(ctx, input);
|
|
61
|
+
if (result.bodyKind === "empty") return {};
|
|
62
|
+
if (result.bodyKind === "invalid-json" || result.bodyKind === "text") {
|
|
63
|
+
return { raw: result.data };
|
|
84
64
|
}
|
|
65
|
+
return result.data;
|
|
85
66
|
}
|
|
86
67
|
function addMemories(input, ctx) {
|
|
87
|
-
const memory =
|
|
68
|
+
const memory = trimmedText(input.memory);
|
|
88
69
|
if (memory === void 0 && !Array.isArray(input.messages)) {
|
|
89
70
|
throw new TBError("invalid_argument", "\u5FC5\u987B\u63D0\u4F9B memory \u6216 messages");
|
|
90
71
|
}
|
|
91
72
|
return request(ctx, {
|
|
92
73
|
method: "POST",
|
|
93
74
|
path: "/v1/memories/",
|
|
94
|
-
body:
|
|
75
|
+
body: compactDefined({
|
|
95
76
|
memory,
|
|
96
77
|
messages: input.messages,
|
|
97
|
-
user_id:
|
|
98
|
-
agent_id:
|
|
99
|
-
app_id:
|
|
100
|
-
run_id:
|
|
101
|
-
org_id:
|
|
102
|
-
project_id:
|
|
103
|
-
metadata:
|
|
104
|
-
custom_categories:
|
|
78
|
+
user_id: trimmedText(input.user_id),
|
|
79
|
+
agent_id: trimmedText(input.agent_id),
|
|
80
|
+
app_id: trimmedText(input.app_id),
|
|
81
|
+
run_id: trimmedText(input.run_id),
|
|
82
|
+
org_id: trimmedText(input.org_id),
|
|
83
|
+
project_id: trimmedText(input.project_id),
|
|
84
|
+
metadata: asJsonObject(input.metadata),
|
|
85
|
+
custom_categories: asJsonObject(input.custom_categories),
|
|
105
86
|
enable_graph: input.enable_graph,
|
|
106
87
|
infer: input.infer,
|
|
107
88
|
async_mode: input.async_mode,
|
|
108
|
-
output_format:
|
|
109
|
-
version:
|
|
110
|
-
custom_instructions:
|
|
89
|
+
output_format: trimmedText(input.output_format),
|
|
90
|
+
version: trimmedText(input.version),
|
|
91
|
+
custom_instructions: trimmedText(input.custom_instructions),
|
|
111
92
|
immutable: input.immutable,
|
|
112
93
|
timestamp: input.timestamp,
|
|
113
|
-
expiration_date:
|
|
114
|
-
includes:
|
|
115
|
-
excludes:
|
|
94
|
+
expiration_date: trimmedText(input.expiration_date),
|
|
95
|
+
includes: trimmedText(input.includes),
|
|
96
|
+
excludes: trimmedText(input.excludes)
|
|
116
97
|
})
|
|
117
98
|
});
|
|
118
99
|
}
|
|
@@ -120,12 +101,12 @@ function getMemories(input, ctx) {
|
|
|
120
101
|
return request(ctx, {
|
|
121
102
|
method: "POST",
|
|
122
103
|
path: "/v2/memories/",
|
|
123
|
-
body:
|
|
124
|
-
filters:
|
|
104
|
+
body: compactDefined({
|
|
105
|
+
filters: asJsonObject(input.filters),
|
|
125
106
|
page: input.page,
|
|
126
107
|
page_size: input.page_size,
|
|
127
|
-
org_id:
|
|
128
|
-
project_id:
|
|
108
|
+
org_id: trimmedText(input.org_id),
|
|
109
|
+
project_id: trimmedText(input.project_id)
|
|
129
110
|
})
|
|
130
111
|
});
|
|
131
112
|
}
|
|
@@ -133,17 +114,17 @@ function searchMemories(input, ctx) {
|
|
|
133
114
|
return request(ctx, {
|
|
134
115
|
method: "POST",
|
|
135
116
|
path: "/v2/memories/search/",
|
|
136
|
-
body:
|
|
117
|
+
body: compactDefined({
|
|
137
118
|
query: requireText(input.query, "query"),
|
|
138
|
-
filters:
|
|
119
|
+
filters: asJsonObject(input.filters),
|
|
139
120
|
top_k: input.top_k,
|
|
140
121
|
rerank: input.rerank,
|
|
141
122
|
threshold: input.threshold,
|
|
142
123
|
fields: input.fields,
|
|
143
124
|
keyword_search: input.keyword_search,
|
|
144
125
|
filter_memories: input.filter_memories,
|
|
145
|
-
org_id:
|
|
146
|
-
project_id:
|
|
126
|
+
org_id: trimmedText(input.org_id),
|
|
127
|
+
project_id: trimmedText(input.project_id)
|
|
147
128
|
})
|
|
148
129
|
});
|
|
149
130
|
}
|
|
@@ -153,35 +134,28 @@ function getMemory(input, ctx) {
|
|
|
153
134
|
}
|
|
154
135
|
function updateMemory(input, ctx) {
|
|
155
136
|
const memoryId = requireText(input.memory_id, "memory_id");
|
|
156
|
-
const value =
|
|
157
|
-
const metadata =
|
|
137
|
+
const value = trimmedText(input.text);
|
|
138
|
+
const metadata = asJsonObject(input.metadata);
|
|
158
139
|
if (value === void 0 && metadata === void 0) {
|
|
159
140
|
throw new TBError("invalid_argument", "\u5FC5\u987B\u63D0\u4F9B text \u6216 metadata");
|
|
160
141
|
}
|
|
161
142
|
return request(ctx, {
|
|
162
143
|
method: "PUT",
|
|
163
144
|
path: `/v1/memories/${encodeURIComponent(memoryId)}/`,
|
|
164
|
-
body:
|
|
145
|
+
body: compactDefined({ text: value, metadata })
|
|
165
146
|
});
|
|
166
147
|
}
|
|
167
148
|
async function deleteMemory(input, ctx) {
|
|
168
149
|
const memoryId = requireText(input.memory_id, "memory_id");
|
|
169
|
-
const
|
|
150
|
+
const result = await execute(ctx, {
|
|
170
151
|
method: "DELETE",
|
|
171
152
|
path: `/v1/memories/${encodeURIComponent(memoryId)}/`
|
|
172
153
|
});
|
|
173
|
-
const
|
|
174
|
-
if (!response.ok) throw upstreamError(response.status, errorMessage(body, response.status));
|
|
175
|
-
let payload;
|
|
176
|
-
try {
|
|
177
|
-
payload = body === "" ? void 0 : record(JSON.parse(body));
|
|
178
|
-
} catch {
|
|
179
|
-
payload = void 0;
|
|
180
|
-
}
|
|
154
|
+
const payload = result.bodyKind === "json" ? asJsonObject(result.data) : void 0;
|
|
181
155
|
return {
|
|
182
156
|
memory_id: memoryId,
|
|
183
157
|
deleted: true,
|
|
184
|
-
message:
|
|
158
|
+
message: trimmedText(payload?.message) ?? "Memory deleted successfully!"
|
|
185
159
|
};
|
|
186
160
|
}
|
|
187
161
|
function getMemoryHistory(input, ctx) {
|
|
@@ -192,9 +166,9 @@ function getEvents(input, ctx) {
|
|
|
192
166
|
return request(ctx, {
|
|
193
167
|
path: "/v1/events/",
|
|
194
168
|
query: {
|
|
195
|
-
event_type:
|
|
196
|
-
start_date:
|
|
197
|
-
end_date:
|
|
169
|
+
event_type: trimmedText(input.event_type),
|
|
170
|
+
start_date: trimmedText(input.start_date),
|
|
171
|
+
end_date: trimmedText(input.end_date),
|
|
198
172
|
page: input.page,
|
|
199
173
|
page_size: input.page_size
|
|
200
174
|
}
|
|
@@ -205,8 +179,8 @@ function getEvent(input, ctx) {
|
|
|
205
179
|
return request(ctx, { path: `/v1/event/${encodeURIComponent(eventId)}/` });
|
|
206
180
|
}
|
|
207
181
|
function getUsers(input, ctx) {
|
|
208
|
-
const orgId =
|
|
209
|
-
const projectId =
|
|
182
|
+
const orgId = trimmedText(input.org_id);
|
|
183
|
+
const projectId = trimmedText(input.project_id);
|
|
210
184
|
if (orgId === void 0 !== (projectId === void 0)) {
|
|
211
185
|
throw new TBError("invalid_argument", "org_id \u4E0E project_id \u5FC5\u987B\u540C\u65F6\u63D0\u4F9B\u6216\u540C\u65F6\u7701\u7565");
|
|
212
186
|
}
|
|
@@ -1,24 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bytesToBase64,
|
|
3
|
+
readBoundedResponseBytes
|
|
4
|
+
} from "./chunk-LMLX3DJF.js";
|
|
5
|
+
import {
|
|
6
|
+
createProviderHttpClient
|
|
7
|
+
} from "./chunk-WW2IMPQK.js";
|
|
8
|
+
import {
|
|
9
|
+
asJsonObject,
|
|
10
|
+
compactDefined,
|
|
11
|
+
trimmedText
|
|
12
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
13
|
import {
|
|
2
14
|
createProviderPlugin,
|
|
3
15
|
requireApiKey,
|
|
4
16
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-YASUMV2K.js";
|
|
6
18
|
import {
|
|
7
19
|
assertPublicHttpUrl,
|
|
8
20
|
guardedFetch
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-GKX72JMJ.js";
|
|
21
|
+
} from "./chunk-U5UHT7CX.js";
|
|
11
22
|
import {
|
|
12
23
|
TBError,
|
|
13
24
|
external_exports
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-RVWZN3CI.js";
|
|
26
|
+
import "./chunk-U67V476Y.js";
|
|
16
27
|
|
|
17
28
|
// ../plugins/src/memos/api.ts
|
|
18
29
|
var SERVICE = "memos";
|
|
19
30
|
var API_SUFFIX = "/api/v1";
|
|
20
31
|
var ATTACHMENT_MAX_BYTES = 20 * 1024 * 1024;
|
|
21
|
-
var
|
|
32
|
+
var http = createProviderHttpClient({ service: SERVICE });
|
|
22
33
|
var UPDATE_MASKS = [
|
|
23
34
|
["content", "content"],
|
|
24
35
|
["visibility", "visibility"],
|
|
@@ -27,29 +38,16 @@ var UPDATE_MASKS = [
|
|
|
27
38
|
["createTime", "create_time"],
|
|
28
39
|
["location", "location"]
|
|
29
40
|
];
|
|
30
|
-
function record(value) {
|
|
31
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
32
|
-
}
|
|
33
|
-
function text(value) {
|
|
34
|
-
if (typeof value !== "string") return void 0;
|
|
35
|
-
const trimmed = value.trim();
|
|
36
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
37
|
-
}
|
|
38
41
|
function requireText(value, field) {
|
|
39
|
-
const result =
|
|
42
|
+
const result = trimmedText(value);
|
|
40
43
|
if (result === void 0) throw new TBError("invalid_argument", `${field} is required.`);
|
|
41
44
|
return result;
|
|
42
45
|
}
|
|
43
|
-
function compact(input) {
|
|
44
|
-
return Object.fromEntries(
|
|
45
|
-
Object.entries(input).filter(([, value]) => value !== void 0)
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
46
|
function responseError(message) {
|
|
49
47
|
return new TBError("unavailable", message, { retryable: true });
|
|
50
48
|
}
|
|
51
49
|
function requireResponseObject(value, operation) {
|
|
52
|
-
const object =
|
|
50
|
+
const object = asJsonObject(value);
|
|
53
51
|
if (object === void 0) throw responseError(`Memos ${operation} response did not include an object`);
|
|
54
52
|
return object;
|
|
55
53
|
}
|
|
@@ -63,7 +61,7 @@ function configError(message) {
|
|
|
63
61
|
function resolveBaseUrl(ctx) {
|
|
64
62
|
const configured = ctx.config?.baseUrl;
|
|
65
63
|
if (configured !== void 0 && typeof configured !== "string") throw configError("\u5FC5\u987B\u662F\u5B57\u7B26\u4E32");
|
|
66
|
-
const candidate =
|
|
64
|
+
const candidate = trimmedText(configured);
|
|
67
65
|
if (candidate === void 0) {
|
|
68
66
|
throw configError(
|
|
69
67
|
"\u662F\u5FC5\u914D\u9879:\u7ED9\u6302\u8F7D\u8282\u70B9\u914D providerConfig.baseUrl \u6307\u5411\u4F60\u7684 Memos \u5B9E\u4F8B(\u5982 https://memos.example.com)\u3002Memos \u53EA\u6709\u81EA\u5EFA\u5B9E\u4F8B,\u6CA1\u6709\u516C\u5171\u7F3A\u7701\u5730\u5740"
|
|
@@ -96,86 +94,34 @@ function resourcePath(name, collection) {
|
|
|
96
94
|
}
|
|
97
95
|
return `/${collection}/${encodeURIComponent(id)}`;
|
|
98
96
|
}
|
|
99
|
-
function readPayload(response, body) {
|
|
100
|
-
if (body.trim() === "") return null;
|
|
101
|
-
try {
|
|
102
|
-
return JSON.parse(body);
|
|
103
|
-
} catch {
|
|
104
|
-
if (response.ok) throw responseError("Memos returned invalid JSON");
|
|
105
|
-
return body;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
97
|
function errorMessage(payload) {
|
|
109
|
-
const direct =
|
|
98
|
+
const direct = trimmedText(payload);
|
|
110
99
|
if (direct !== void 0) return direct;
|
|
111
|
-
return
|
|
100
|
+
return trimmedText(asJsonObject(payload)?.message) ?? "Memos request failed";
|
|
112
101
|
}
|
|
113
102
|
async function request(target, input) {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
130
|
-
payload = readPayload(response, await response.text());
|
|
131
|
-
} catch (error) {
|
|
132
|
-
if (error instanceof TBError) throw error;
|
|
133
|
-
const detail = error instanceof Error ? error.message : "unknown network error";
|
|
134
|
-
throw upstreamError(502, `Memos ${input.path} request failed: ${detail}`);
|
|
135
|
-
}
|
|
136
|
-
if (!response.ok) throw upstreamError(response.status, errorMessage(payload));
|
|
137
|
-
return payload;
|
|
103
|
+
const result = await http.request({
|
|
104
|
+
baseUrl: `${target.baseUrl}/`,
|
|
105
|
+
path: input.path,
|
|
106
|
+
method: input.method ?? "GET",
|
|
107
|
+
query: Object.entries(input.query ?? {}),
|
|
108
|
+
headers: { accept: "application/json", authorization: `Bearer ${target.apiKey}` },
|
|
109
|
+
...input.body === void 0 ? {} : { json: input.body },
|
|
110
|
+
invalidJsonMessage: "Memos returned invalid JSON",
|
|
111
|
+
mapError: ({ data, status }) => upstreamError(status, errorMessage(data)),
|
|
112
|
+
mapTransportError: ({ message }) => upstreamError(
|
|
113
|
+
502,
|
|
114
|
+
`Memos ${input.path} request failed: ${message ?? "unknown network error"}`
|
|
115
|
+
)
|
|
116
|
+
});
|
|
117
|
+
return result.data === void 0 ? null : result.data;
|
|
138
118
|
}
|
|
139
119
|
async function readBoundedBytes(response) {
|
|
140
120
|
const tooLarge = () => new TBError(
|
|
141
121
|
"invalid_argument",
|
|
142
122
|
`fileUrl \u6307\u5411\u7684\u6587\u4EF6\u8D85\u8FC7 ${ATTACHMENT_MAX_BYTES} \u5B57\u8282\u7684\u4E0A\u9650`
|
|
143
123
|
);
|
|
144
|
-
|
|
145
|
-
if (Number.isFinite(declared) && declared > ATTACHMENT_MAX_BYTES) throw tooLarge();
|
|
146
|
-
const body = response.body;
|
|
147
|
-
if (body === null) {
|
|
148
|
-
const bytes2 = new Uint8Array(await response.arrayBuffer());
|
|
149
|
-
if (bytes2.byteLength > ATTACHMENT_MAX_BYTES) throw tooLarge();
|
|
150
|
-
return bytes2;
|
|
151
|
-
}
|
|
152
|
-
const reader = body.getReader();
|
|
153
|
-
const chunks = [];
|
|
154
|
-
let total = 0;
|
|
155
|
-
for (; ; ) {
|
|
156
|
-
const { done, value } = await reader.read();
|
|
157
|
-
if (done) break;
|
|
158
|
-
total += value.byteLength;
|
|
159
|
-
if (total > ATTACHMENT_MAX_BYTES) {
|
|
160
|
-
await reader.cancel();
|
|
161
|
-
throw tooLarge();
|
|
162
|
-
}
|
|
163
|
-
chunks.push(value);
|
|
164
|
-
}
|
|
165
|
-
const bytes = new Uint8Array(total);
|
|
166
|
-
let offset = 0;
|
|
167
|
-
for (const chunk of chunks) {
|
|
168
|
-
bytes.set(chunk, offset);
|
|
169
|
-
offset += chunk.byteLength;
|
|
170
|
-
}
|
|
171
|
-
return bytes;
|
|
172
|
-
}
|
|
173
|
-
function base64(bytes) {
|
|
174
|
-
let binary = "";
|
|
175
|
-
for (let offset = 0; offset < bytes.length; offset += BASE64_CHUNK) {
|
|
176
|
-
binary += String.fromCharCode(...bytes.subarray(offset, offset + BASE64_CHUNK));
|
|
177
|
-
}
|
|
178
|
-
return btoa(binary);
|
|
124
|
+
return readBoundedResponseBytes(response, { maxBytes: ATTACHMENT_MAX_BYTES, tooLarge });
|
|
179
125
|
}
|
|
180
126
|
async function downloadAttachment(fileUrl, declaredType) {
|
|
181
127
|
let response;
|
|
@@ -188,7 +134,7 @@ async function downloadAttachment(fileUrl, declaredType) {
|
|
|
188
134
|
}
|
|
189
135
|
if (!response.ok) throw upstreamError(502, `failed to fetch fileUrl: ${response.status}`);
|
|
190
136
|
const bytes = await readBoundedBytes(response);
|
|
191
|
-
const responseType =
|
|
137
|
+
const responseType = trimmedText(response.headers.get("content-type")?.split(";", 1)[0]);
|
|
192
138
|
return { bytes, mimeType: declaredType ?? responseType ?? "application/octet-stream" };
|
|
193
139
|
}
|
|
194
140
|
async function createMemo(input, ctx) {
|
|
@@ -196,11 +142,11 @@ async function createMemo(input, ctx) {
|
|
|
196
142
|
method: "POST",
|
|
197
143
|
path: "/memos",
|
|
198
144
|
// memoId 是**query** 参数而不是 body 字段(Memos 的 AIP 风格:资源 id 走 query)。
|
|
199
|
-
query:
|
|
200
|
-
body:
|
|
145
|
+
query: compactDefined({ memoId: trimmedText(input.memoId) }),
|
|
146
|
+
body: compactDefined({
|
|
201
147
|
content: input.content,
|
|
202
|
-
visibility:
|
|
203
|
-
createTime:
|
|
148
|
+
visibility: trimmedText(input.visibility),
|
|
149
|
+
createTime: trimmedText(input.createTime),
|
|
204
150
|
pinned: input.pinned,
|
|
205
151
|
location: input.location
|
|
206
152
|
})
|
|
@@ -210,19 +156,19 @@ async function createMemo(input, ctx) {
|
|
|
210
156
|
async function listMemos(input, ctx) {
|
|
211
157
|
const payload = requireResponseObject(await request(resolveTarget(ctx), {
|
|
212
158
|
path: "/memos",
|
|
213
|
-
query:
|
|
159
|
+
query: compactDefined({
|
|
214
160
|
pageSize: input.pageSize,
|
|
215
|
-
pageToken:
|
|
216
|
-
state:
|
|
217
|
-
orderBy:
|
|
218
|
-
filter:
|
|
161
|
+
pageToken: trimmedText(input.pageToken),
|
|
162
|
+
state: trimmedText(input.state),
|
|
163
|
+
orderBy: trimmedText(input.orderBy),
|
|
164
|
+
filter: trimmedText(input.filter),
|
|
219
165
|
showDeleted: input.showDeleted
|
|
220
166
|
})
|
|
221
167
|
}), "list memos");
|
|
222
168
|
return {
|
|
223
169
|
// 一页都没有时 Memos 干脆不给 `memos` 键,补成空数组;非数组则是上游坏了。
|
|
224
170
|
memos: requireResponseObjects(payload.memos ?? [], "list memos"),
|
|
225
|
-
nextPageToken:
|
|
171
|
+
nextPageToken: trimmedText(payload.nextPageToken) ?? null
|
|
226
172
|
};
|
|
227
173
|
}
|
|
228
174
|
async function getMemo(input, ctx) {
|
|
@@ -240,7 +186,7 @@ async function updateMemo(input, ctx) {
|
|
|
240
186
|
method: "PATCH",
|
|
241
187
|
path: resourcePath(name, "memos"),
|
|
242
188
|
query: { updateMask: updateMask.join(",") },
|
|
243
|
-
body:
|
|
189
|
+
body: compactDefined({
|
|
244
190
|
name,
|
|
245
191
|
content: input.content,
|
|
246
192
|
visibility: input.visibility,
|
|
@@ -257,22 +203,22 @@ async function deleteMemo(input, ctx) {
|
|
|
257
203
|
await request(resolveTarget(ctx), {
|
|
258
204
|
method: "DELETE",
|
|
259
205
|
path: resourcePath(name, "memos"),
|
|
260
|
-
query:
|
|
206
|
+
query: compactDefined({ force: input.force })
|
|
261
207
|
});
|
|
262
208
|
return { deleted: true, name };
|
|
263
209
|
}
|
|
264
210
|
async function uploadAttachment(input, ctx) {
|
|
265
211
|
const target = resolveTarget(ctx);
|
|
266
|
-
const source = await downloadAttachment(requireText(input.fileUrl, "fileUrl"),
|
|
212
|
+
const source = await downloadAttachment(requireText(input.fileUrl, "fileUrl"), trimmedText(input.type));
|
|
267
213
|
const payload = await request(target, {
|
|
268
214
|
method: "POST",
|
|
269
215
|
path: "/attachments",
|
|
270
|
-
query:
|
|
271
|
-
body:
|
|
216
|
+
query: compactDefined({ attachmentId: trimmedText(input.attachmentId) }),
|
|
217
|
+
body: compactDefined({
|
|
272
218
|
filename: requireText(input.filename, "filename"),
|
|
273
|
-
content:
|
|
219
|
+
content: bytesToBase64(source.bytes),
|
|
274
220
|
type: source.mimeType,
|
|
275
|
-
memo:
|
|
221
|
+
memo: trimmedText(input.memo)
|
|
276
222
|
})
|
|
277
223
|
});
|
|
278
224
|
return { attachment: requireResponseObject(payload, "upload attachment") };
|
|
@@ -280,16 +226,16 @@ async function uploadAttachment(input, ctx) {
|
|
|
280
226
|
async function listAttachments(input, ctx) {
|
|
281
227
|
const payload = requireResponseObject(await request(resolveTarget(ctx), {
|
|
282
228
|
path: "/attachments",
|
|
283
|
-
query:
|
|
229
|
+
query: compactDefined({
|
|
284
230
|
pageSize: input.pageSize,
|
|
285
|
-
pageToken:
|
|
286
|
-
filter:
|
|
287
|
-
orderBy:
|
|
231
|
+
pageToken: trimmedText(input.pageToken),
|
|
232
|
+
filter: trimmedText(input.filter),
|
|
233
|
+
orderBy: trimmedText(input.orderBy)
|
|
288
234
|
})
|
|
289
235
|
}), "list attachments");
|
|
290
236
|
return {
|
|
291
237
|
attachments: requireResponseObjects(payload.attachments ?? [], "list attachments"),
|
|
292
|
-
nextPageToken:
|
|
238
|
+
nextPageToken: trimmedText(payload.nextPageToken) ?? null
|
|
293
239
|
};
|
|
294
240
|
}
|
|
295
241
|
async function getAttachment(input, ctx) {
|
|
@@ -306,11 +252,11 @@ async function listMemoAttachments(input, ctx) {
|
|
|
306
252
|
const name = requireText(input.name, "name");
|
|
307
253
|
const payload = requireResponseObject(await request(resolveTarget(ctx), {
|
|
308
254
|
path: `${resourcePath(name, "memos")}/attachments`,
|
|
309
|
-
query:
|
|
255
|
+
query: compactDefined({ pageSize: input.pageSize, pageToken: trimmedText(input.pageToken) })
|
|
310
256
|
}), "list memo attachments");
|
|
311
257
|
return {
|
|
312
258
|
attachments: requireResponseObjects(payload.attachments ?? [], "list memo attachments"),
|
|
313
|
-
nextPageToken:
|
|
259
|
+
nextPageToken: trimmedText(payload.nextPageToken) ?? null
|
|
314
260
|
};
|
|
315
261
|
}
|
|
316
262
|
async function setMemoAttachments(input, ctx) {
|
|
@@ -331,23 +277,23 @@ async function getCurrentUser(_input, ctx) {
|
|
|
331
277
|
async function listUsers(input, ctx) {
|
|
332
278
|
const payload = requireResponseObject(await request(resolveTarget(ctx), {
|
|
333
279
|
path: "/users",
|
|
334
|
-
query:
|
|
280
|
+
query: compactDefined({
|
|
335
281
|
pageSize: input.pageSize,
|
|
336
|
-
pageToken:
|
|
337
|
-
filter:
|
|
282
|
+
pageToken: trimmedText(input.pageToken),
|
|
283
|
+
filter: trimmedText(input.filter),
|
|
338
284
|
showDeleted: input.showDeleted
|
|
339
285
|
})
|
|
340
286
|
}), "list users");
|
|
341
287
|
return {
|
|
342
288
|
users: requireResponseObjects(payload.users ?? [], "list users"),
|
|
343
|
-
nextPageToken:
|
|
289
|
+
nextPageToken: trimmedText(payload.nextPageToken) ?? null
|
|
344
290
|
};
|
|
345
291
|
}
|
|
346
292
|
async function getUser(input, ctx) {
|
|
347
293
|
const path = resourcePath(requireText(input.name, "name"), "users");
|
|
348
294
|
const payload = await request(resolveTarget(ctx), {
|
|
349
295
|
path,
|
|
350
|
-
query:
|
|
296
|
+
query: compactDefined({ readMask: trimmedText(input.readMask) })
|
|
351
297
|
});
|
|
352
298
|
return { user: requireResponseObject(payload, "get user") };
|
|
353
299
|
}
|