@squadbase/vite-server 0.1.17-dev.24af54e → 0.1.17-dev.423ee34
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/cli/index.js +4873 -1073
- package/dist/connectors/airtable-oauth.js +78 -11
- package/dist/connectors/airtable.js +74 -11
- package/dist/connectors/amplitude.js +38 -11
- package/dist/connectors/anthropic.js +4 -2
- package/dist/connectors/asana.js +67 -13
- package/dist/connectors/attio.js +60 -16
- package/dist/connectors/aws-billing.js +38 -11
- package/dist/connectors/azure-sql.js +64 -13
- package/dist/connectors/backlog-api-key.js +70 -18
- package/dist/connectors/clickup.js +80 -13
- package/dist/connectors/cosmosdb.js +42 -15
- package/dist/connectors/customerio.js +39 -12
- package/dist/connectors/dbt.js +716 -28
- package/dist/connectors/freshdesk.js +112 -11
- package/dist/connectors/freshsales.js +38 -11
- package/dist/connectors/freshservice.js +38 -11
- package/dist/connectors/gamma.js +47 -20
- package/dist/connectors/gemini.js +4 -2
- package/dist/connectors/github.js +42 -15
- package/dist/connectors/gmail-oauth.js +38 -13
- package/dist/connectors/gmail.js +34 -7
- package/dist/connectors/google-ads.js +38 -11
- package/dist/connectors/google-analytics-oauth.js +182 -28
- package/dist/connectors/google-analytics.js +653 -104
- package/dist/connectors/google-audit-log.js +34 -7
- package/dist/connectors/google-calendar-oauth.js +91 -18
- package/dist/connectors/google-calendar.js +91 -14
- package/dist/connectors/google-docs.js +38 -13
- package/dist/connectors/google-drive.js +60 -13
- package/dist/connectors/google-search-console-oauth.js +156 -20
- package/dist/connectors/google-sheets.js +36 -9
- package/dist/connectors/google-slides.js +38 -13
- package/dist/connectors/grafana.js +75 -13
- package/dist/connectors/hubspot-oauth.js +69 -12
- package/dist/connectors/hubspot.js +55 -12
- package/dist/connectors/influxdb.js +38 -11
- package/dist/connectors/intercom-oauth.js +100 -15
- package/dist/connectors/intercom.js +42 -15
- package/dist/connectors/jdbc.js +36 -9
- package/dist/connectors/jira-api-key.js +98 -14
- package/dist/connectors/kintone-api-token.js +96 -21
- package/dist/connectors/kintone.js +84 -14
- package/dist/connectors/linear.js +84 -15
- package/dist/connectors/linkedin-ads.js +71 -17
- package/dist/connectors/mailchimp-oauth.js +36 -9
- package/dist/connectors/mailchimp.js +36 -9
- package/dist/connectors/meta-ads-oauth.js +63 -17
- package/dist/connectors/meta-ads.js +65 -17
- package/dist/connectors/mixpanel.js +38 -11
- package/dist/connectors/monday.js +39 -12
- package/dist/connectors/mongodb.js +38 -11
- package/dist/connectors/notion-oauth.js +88 -14
- package/dist/connectors/notion.js +90 -14
- package/dist/connectors/openai.js +4 -2
- package/dist/connectors/oracle.js +78 -20
- package/dist/connectors/outlook-oauth.js +48 -23
- package/dist/connectors/powerbi-oauth.js +321 -49
- package/dist/connectors/salesforce.js +72 -12
- package/dist/connectors/semrush.js +374 -52
- package/dist/connectors/sentry.js +66 -13
- package/dist/connectors/shopify-oauth.js +71 -13
- package/dist/connectors/shopify.js +38 -11
- package/dist/connectors/sqlserver.js +64 -13
- package/dist/connectors/stripe-api-key.js +96 -18
- package/dist/connectors/stripe-oauth.js +98 -22
- package/dist/connectors/supabase.js +55 -11
- package/dist/connectors/tableau.js +262 -92
- package/dist/connectors/tiktok-ads.js +67 -19
- package/dist/connectors/wix-store.js +38 -11
- package/dist/connectors/zendesk-oauth.js +83 -15
- package/dist/connectors/zendesk.js +42 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4902 -1077
- package/dist/main.js +4891 -1071
- package/dist/vite-plugin.js +4871 -1071
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ var init_parameter_definition = __esm({
|
|
|
16
16
|
type;
|
|
17
17
|
secret;
|
|
18
18
|
required;
|
|
19
|
+
isDeprecated;
|
|
19
20
|
constructor(config) {
|
|
20
21
|
this.slug = config.slug;
|
|
21
22
|
this.name = config.name;
|
|
@@ -24,6 +25,7 @@ var init_parameter_definition = __esm({
|
|
|
24
25
|
this.type = config.type;
|
|
25
26
|
this.secret = config.secret;
|
|
26
27
|
this.required = config.required;
|
|
28
|
+
this.isDeprecated = config.isDeprecated ?? false;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Get the parameter value from a ConnectorConnectionObject.
|
|
@@ -267,7 +269,7 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
267
269
|
/**
|
|
268
270
|
* Create tools for connections that belong to this connector.
|
|
269
271
|
* Filters connections by connectorKey internally.
|
|
270
|
-
* Returns tools keyed as
|
|
272
|
+
* Returns tools keyed as `connector_${connectorKey}_${toolName}`.
|
|
271
273
|
*/
|
|
272
274
|
createTools(connections, config, opts) {
|
|
273
275
|
const myConnections = connections.filter(
|
|
@@ -277,7 +279,7 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
277
279
|
for (const t of Object.values(this.tools)) {
|
|
278
280
|
const tool = t.createTool(myConnections, config);
|
|
279
281
|
const originalToModelOutput = tool.toModelOutput;
|
|
280
|
-
result[
|
|
282
|
+
result[`connector_${this.connectorKey}_${t.name}`] = {
|
|
281
283
|
...tool,
|
|
282
284
|
toModelOutput: async (options) => {
|
|
283
285
|
if (!originalToModelOutput) {
|
|
@@ -333,19 +335,34 @@ async function runSetupFlow(flow, params, ctx, config) {
|
|
|
333
335
|
};
|
|
334
336
|
let state = flow.initialState();
|
|
335
337
|
let answerIdx = 0;
|
|
338
|
+
const pendingParameterUpdates = [];
|
|
336
339
|
for (const step of flow.steps) {
|
|
337
340
|
const ans = ctx.answers[answerIdx];
|
|
338
341
|
if (ans && ans.questionSlug === step.slug) {
|
|
339
342
|
state = step.applyAnswer(state, ans.answer);
|
|
343
|
+
if (step.toParameterUpdates) {
|
|
344
|
+
pendingParameterUpdates.push(...step.toParameterUpdates(state));
|
|
345
|
+
}
|
|
340
346
|
answerIdx += 1;
|
|
341
347
|
continue;
|
|
342
348
|
}
|
|
349
|
+
const resolvedAllowFreeText = step.allowFreeText !== void 0 ? step.allowFreeText : true;
|
|
343
350
|
if (step.type === "text") {
|
|
351
|
+
if (step.fetchOptions) {
|
|
352
|
+
const options2 = await step.fetchOptions(state, runtime);
|
|
353
|
+
if (options2.length === 0) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
344
357
|
return {
|
|
345
358
|
type: "nextQuestion",
|
|
346
359
|
questionSlug: step.slug,
|
|
347
360
|
question: step.question[ctx.language],
|
|
348
|
-
questionType: "text"
|
|
361
|
+
questionType: "text",
|
|
362
|
+
allowFreeText: resolvedAllowFreeText,
|
|
363
|
+
...pendingParameterUpdates.length > 0 && {
|
|
364
|
+
parameterUpdates: pendingParameterUpdates
|
|
365
|
+
}
|
|
349
366
|
};
|
|
350
367
|
}
|
|
351
368
|
const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
|
|
@@ -357,11 +374,21 @@ async function runSetupFlow(flow, params, ctx, config) {
|
|
|
357
374
|
questionSlug: step.slug,
|
|
358
375
|
question: step.question[ctx.language],
|
|
359
376
|
questionType: step.type,
|
|
360
|
-
options
|
|
377
|
+
options,
|
|
378
|
+
allowFreeText: resolvedAllowFreeText,
|
|
379
|
+
...pendingParameterUpdates.length > 0 && {
|
|
380
|
+
parameterUpdates: pendingParameterUpdates
|
|
381
|
+
}
|
|
361
382
|
};
|
|
362
383
|
}
|
|
363
384
|
const dataInvestigationResult = await flow.finalize(state, runtime);
|
|
364
|
-
return {
|
|
385
|
+
return {
|
|
386
|
+
type: "fulfilled",
|
|
387
|
+
dataInvestigationResult,
|
|
388
|
+
...pendingParameterUpdates.length > 0 && {
|
|
389
|
+
parameterUpdates: pendingParameterUpdates
|
|
390
|
+
}
|
|
391
|
+
};
|
|
365
392
|
}
|
|
366
393
|
async function resolveSetupSelection(params) {
|
|
367
394
|
const { selected, allSentinel, fetchAll, limit } = params;
|
|
@@ -815,9 +842,9 @@ var mongodbConnector = new ConnectorPlugin({
|
|
|
815
842
|
systemPrompt: {
|
|
816
843
|
en: `### Tools
|
|
817
844
|
|
|
818
|
-
- \`
|
|
819
|
-
- \`
|
|
820
|
-
- \`
|
|
845
|
+
- \`connector_mongodb_listCollections\`: Lists all collections in the database. Use this first to explore available data.
|
|
846
|
+
- \`connector_mongodb_find\`: Finds documents in a collection with optional filter, projection, sort, and limit. Use for data sampling and querying specific documents. Pass filter, projection, and sort as JSON strings.
|
|
847
|
+
- \`connector_mongodb_aggregate\`: Runs a MongoDB aggregation pipeline on a collection. Use for complex data analysis, grouping, joining, and transformations. Pass pipeline as a JSON string.
|
|
821
848
|
|
|
822
849
|
### Business Logic
|
|
823
850
|
|
|
@@ -870,9 +897,9 @@ export default async function handler(_c: Context) {
|
|
|
870
897
|
- Always include limit in find queries and $limit in aggregation pipelines`,
|
|
871
898
|
ja: `### \u30C4\u30FC\u30EB
|
|
872
899
|
|
|
873
|
-
- \`
|
|
874
|
-
- \`
|
|
875
|
-
- \`
|
|
900
|
+
- \`connector_mongodb_listCollections\`: \u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u5185\u306E\u30B3\u30EC\u30AF\u30B7\u30E7\u30F3\u4E00\u89A7\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u30C7\u30FC\u30BF\u63A2\u7D22\u306E\u6700\u521D\u306E\u30B9\u30C6\u30C3\u30D7\u3068\u3057\u3066\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002
|
|
901
|
+
- \`connector_mongodb_find\`: \u30B3\u30EC\u30AF\u30B7\u30E7\u30F3\u5185\u306E\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u691C\u7D22\u3057\u307E\u3059\u3002\u30D5\u30A3\u30EB\u30BF\u30FC\u3001\u30D7\u30ED\u30B8\u30A7\u30AF\u30B7\u30E7\u30F3\u3001\u30BD\u30FC\u30C8\u3001\u5236\u9650\u3092\u30AA\u30D7\u30B7\u30E7\u30F3\u3067\u6307\u5B9A\u53EF\u80FD\u3002\u30C7\u30FC\u30BF\u306E\u30B5\u30F3\u30D7\u30EA\u30F3\u30B0\u3084\u7279\u5B9A\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306E\u30AF\u30A8\u30EA\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002filter\u3001projection\u3001sort\u306FJSON\u6587\u5B57\u5217\u3067\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\u3002
|
|
902
|
+
- \`connector_mongodb_aggregate\`: \u30B3\u30EC\u30AF\u30B7\u30E7\u30F3\u4E0A\u3067MongoDB\u96C6\u7D04\u30D1\u30A4\u30D7\u30E9\u30A4\u30F3\u3092\u5B9F\u884C\u3057\u307E\u3059\u3002\u8907\u96D1\u306A\u30C7\u30FC\u30BF\u5206\u6790\u3001\u30B0\u30EB\u30FC\u30D7\u5316\u3001\u7D50\u5408\u3001\u5909\u63DB\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002pipeline\u306FJSON\u6587\u5B57\u5217\u3067\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\u3002
|
|
876
903
|
|
|
877
904
|
### Business Logic
|
|
878
905
|
|
|
@@ -118,7 +118,7 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
118
118
|
/**
|
|
119
119
|
* Create tools for connections that belong to this connector.
|
|
120
120
|
* Filters connections by connectorKey internally.
|
|
121
|
-
* Returns tools keyed as
|
|
121
|
+
* Returns tools keyed as `connector_${connectorKey}_${toolName}`.
|
|
122
122
|
*/
|
|
123
123
|
createTools(connections, config, opts) {
|
|
124
124
|
const myConnections = connections.filter(
|
|
@@ -128,7 +128,7 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
128
128
|
for (const t of Object.values(this.tools)) {
|
|
129
129
|
const tool = t.createTool(myConnections, config);
|
|
130
130
|
const originalToModelOutput = tool.toModelOutput;
|
|
131
|
-
result[
|
|
131
|
+
result[`connector_${this.connectorKey}_${t.name}`] = {
|
|
132
132
|
...tool,
|
|
133
133
|
toModelOutput: async (options) => {
|
|
134
134
|
if (!originalToModelOutput) {
|
|
@@ -184,19 +184,34 @@ async function runSetupFlow(flow, params, ctx, config) {
|
|
|
184
184
|
};
|
|
185
185
|
let state = flow.initialState();
|
|
186
186
|
let answerIdx = 0;
|
|
187
|
+
const pendingParameterUpdates = [];
|
|
187
188
|
for (const step of flow.steps) {
|
|
188
189
|
const ans = ctx.answers[answerIdx];
|
|
189
190
|
if (ans && ans.questionSlug === step.slug) {
|
|
190
191
|
state = step.applyAnswer(state, ans.answer);
|
|
192
|
+
if (step.toParameterUpdates) {
|
|
193
|
+
pendingParameterUpdates.push(...step.toParameterUpdates(state));
|
|
194
|
+
}
|
|
191
195
|
answerIdx += 1;
|
|
192
196
|
continue;
|
|
193
197
|
}
|
|
198
|
+
const resolvedAllowFreeText = step.allowFreeText !== void 0 ? step.allowFreeText : true;
|
|
194
199
|
if (step.type === "text") {
|
|
200
|
+
if (step.fetchOptions) {
|
|
201
|
+
const options2 = await step.fetchOptions(state, runtime);
|
|
202
|
+
if (options2.length === 0) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
195
206
|
return {
|
|
196
207
|
type: "nextQuestion",
|
|
197
208
|
questionSlug: step.slug,
|
|
198
209
|
question: step.question[ctx.language],
|
|
199
|
-
questionType: "text"
|
|
210
|
+
questionType: "text",
|
|
211
|
+
allowFreeText: resolvedAllowFreeText,
|
|
212
|
+
...pendingParameterUpdates.length > 0 && {
|
|
213
|
+
parameterUpdates: pendingParameterUpdates
|
|
214
|
+
}
|
|
200
215
|
};
|
|
201
216
|
}
|
|
202
217
|
const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
|
|
@@ -208,11 +223,21 @@ async function runSetupFlow(flow, params, ctx, config) {
|
|
|
208
223
|
questionSlug: step.slug,
|
|
209
224
|
question: step.question[ctx.language],
|
|
210
225
|
questionType: step.type,
|
|
211
|
-
options
|
|
226
|
+
options,
|
|
227
|
+
allowFreeText: resolvedAllowFreeText,
|
|
228
|
+
...pendingParameterUpdates.length > 0 && {
|
|
229
|
+
parameterUpdates: pendingParameterUpdates
|
|
230
|
+
}
|
|
212
231
|
};
|
|
213
232
|
}
|
|
214
233
|
const dataInvestigationResult = await flow.finalize(state, runtime);
|
|
215
|
-
return {
|
|
234
|
+
return {
|
|
235
|
+
type: "fulfilled",
|
|
236
|
+
dataInvestigationResult,
|
|
237
|
+
...pendingParameterUpdates.length > 0 && {
|
|
238
|
+
parameterUpdates: pendingParameterUpdates
|
|
239
|
+
}
|
|
240
|
+
};
|
|
216
241
|
}
|
|
217
242
|
async function resolveSetupSelection(params) {
|
|
218
243
|
const { selected, allSentinel, fetchAll, limit } = params;
|
|
@@ -370,13 +395,13 @@ var notionOauthOnboarding = new ConnectorOnboarding({
|
|
|
370
395
|
- Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
|
|
371
396
|
},
|
|
372
397
|
dataOverviewInstructions: {
|
|
373
|
-
en: `1. Call
|
|
374
|
-
2. For each database found, call
|
|
375
|
-
3. Call
|
|
398
|
+
en: `1. Call connector_notion-oauth_request with POST /search and { "page_size": 5 } to discover available pages and databases
|
|
399
|
+
2. For each database found, call connector_notion-oauth_request with POST /databases/{database_id}/query and { "page_size": 5 } to sample records
|
|
400
|
+
3. Call connector_notion-oauth_request with GET /users to list workspace members
|
|
376
401
|
4. Explore page content with GET /blocks/{page_id}/children as needed`,
|
|
377
|
-
ja: `1.
|
|
378
|
-
2. \u898B\u3064\u304B\u3063\u305F\u5404\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u306B\u3064\u3044\u3066\
|
|
379
|
-
3.
|
|
402
|
+
ja: `1. connector_notion-oauth_request \u3067 POST /search \u3092 { "page_size": 5 } \u3067\u547C\u3073\u51FA\u3057\u3001\u5229\u7528\u53EF\u80FD\u306A\u30DA\u30FC\u30B8\u3068\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u3092\u691C\u51FA
|
|
403
|
+
2. \u898B\u3064\u304B\u3063\u305F\u5404\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u306B\u3064\u3044\u3066\u3001connector_notion-oauth_request \u3067 POST /databases/{database_id}/query \u3092 { "page_size": 5 } \u3067\u547C\u3073\u51FA\u3057\u3001\u30EC\u30B3\u30FC\u30C9\u3092\u30B5\u30F3\u30D7\u30EA\u30F3\u30B0
|
|
404
|
+
3. connector_notion-oauth_request \u3067 GET /users \u3092\u547C\u3073\u51FA\u3057\u3001\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u30E1\u30F3\u30D0\u30FC\u3092\u4E00\u89A7\u8868\u793A
|
|
380
405
|
4. \u5FC5\u8981\u306B\u5FDC\u3058\u3066 GET /blocks/{page_id}/children \u3067\u30DA\u30FC\u30B8\u30B3\u30F3\u30C6\u30F3\u30C4\u3092\u63A2\u7D22`
|
|
381
406
|
}
|
|
382
407
|
});
|
|
@@ -440,6 +465,38 @@ async function getDatabase(proxyFetch, databaseId) {
|
|
|
440
465
|
}
|
|
441
466
|
return await res.json();
|
|
442
467
|
}
|
|
468
|
+
async function queryDatabaseSample(proxyFetch, databaseId) {
|
|
469
|
+
try {
|
|
470
|
+
const res = await apiFetch(proxyFetch, `/databases/${databaseId}/query`, {
|
|
471
|
+
method: "POST",
|
|
472
|
+
body: JSON.stringify({ page_size: 3 })
|
|
473
|
+
});
|
|
474
|
+
if (!res.ok) return [];
|
|
475
|
+
const data = await res.json();
|
|
476
|
+
return data.results ?? [];
|
|
477
|
+
} catch {
|
|
478
|
+
return [];
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function formatPropertyValue(prop) {
|
|
482
|
+
if (prop == null || typeof prop !== "object") return "";
|
|
483
|
+
const p = prop;
|
|
484
|
+
const t = p.type ?? "";
|
|
485
|
+
const v = p[t];
|
|
486
|
+
if (v == null) return "";
|
|
487
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean")
|
|
488
|
+
return String(v);
|
|
489
|
+
if (Array.isArray(v)) {
|
|
490
|
+
if (v.length === 0) return "";
|
|
491
|
+
const first = v[0];
|
|
492
|
+
return first.plain_text ?? first.name ?? `[${v.length} items]`;
|
|
493
|
+
}
|
|
494
|
+
if (typeof v === "object") {
|
|
495
|
+
const o = v;
|
|
496
|
+
return o.name ?? o.plain_text ?? o.start ?? JSON.stringify(v).slice(0, 30);
|
|
497
|
+
}
|
|
498
|
+
return String(v);
|
|
499
|
+
}
|
|
443
500
|
var notionOauthSetupFlow = {
|
|
444
501
|
initialState: () => ({}),
|
|
445
502
|
steps: [
|
|
@@ -484,11 +541,28 @@ var notionOauthSetupFlow = {
|
|
|
484
541
|
sections.push(`### Database: ${title}`, "", `- id: \`${db.id}\``, "");
|
|
485
542
|
sections.push("| Property | Type |");
|
|
486
543
|
sections.push("|----------|------|");
|
|
487
|
-
|
|
544
|
+
const propEntries = Object.entries(db.properties ?? {});
|
|
545
|
+
for (const [name, def] of propEntries) {
|
|
488
546
|
const escapedName = name.replace(/\|/g, "\\|");
|
|
489
547
|
sections.push(`| ${escapedName} | ${def?.type ?? "-"} |`);
|
|
490
548
|
}
|
|
491
549
|
sections.push("");
|
|
550
|
+
const pages = await queryDatabaseSample(rt.config.proxyFetch, dbId);
|
|
551
|
+
if (pages.length > 0) {
|
|
552
|
+
const sampleProps = propEntries.slice(0, 5).map(([n]) => n);
|
|
553
|
+
if (sampleProps.length > 0) {
|
|
554
|
+
sections.push(`#### Sample pages (${pages.length})`, "");
|
|
555
|
+
sections.push(`| ${sampleProps.join(" | ")} |`);
|
|
556
|
+
sections.push(`| ${sampleProps.map(() => "---").join(" | ")} |`);
|
|
557
|
+
for (const page of pages) {
|
|
558
|
+
const cells = sampleProps.map(
|
|
559
|
+
(n) => formatPropertyValue(page.properties?.[n]).replace(/\|/g, "\\|")
|
|
560
|
+
);
|
|
561
|
+
sections.push(`| ${cells.join(" | ")} |`);
|
|
562
|
+
}
|
|
563
|
+
sections.push("");
|
|
564
|
+
}
|
|
565
|
+
}
|
|
492
566
|
}
|
|
493
567
|
return sections.join("\n");
|
|
494
568
|
}
|
|
@@ -518,7 +592,7 @@ var notionOauthConnector = new ConnectorPlugin({
|
|
|
518
592
|
systemPrompt: {
|
|
519
593
|
en: `### Tools
|
|
520
594
|
|
|
521
|
-
- \`
|
|
595
|
+
- \`connector_notion-oauth_request\`: The only way to call the Notion API. Use it to search pages and databases, query database records, retrieve page content and blocks, and manage workspace data. Authentication is configured automatically via OAuth. Notion-Version header is set automatically. Pagination uses cursor-based \`start_cursor\` and \`page_size\` (max 100) with \`has_more\` and \`next_cursor\` in the response.
|
|
522
596
|
|
|
523
597
|
### Notion API Reference
|
|
524
598
|
|
|
@@ -568,7 +642,7 @@ const data = await res.json();
|
|
|
568
642
|
\`\`\``,
|
|
569
643
|
ja: `### \u30C4\u30FC\u30EB
|
|
570
644
|
|
|
571
|
-
- \`
|
|
645
|
+
- \`connector_notion-oauth_request\`: Notion API\u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\u3002\u30DA\u30FC\u30B8\u3084\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u306E\u691C\u7D22\u3001\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u30EC\u30B3\u30FC\u30C9\u306E\u30AF\u30A8\u30EA\u3001\u30DA\u30FC\u30B8\u30B3\u30F3\u30C6\u30F3\u30C4\u3084\u30D6\u30ED\u30C3\u30AF\u306E\u53D6\u5F97\u3001\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u30C7\u30FC\u30BF\u306E\u7BA1\u7406\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002OAuth\u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002Notion-Version\u30D8\u30C3\u30C0\u30FC\u3082\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002\u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u306F\u30EC\u30B9\u30DD\u30F3\u30B9\u306E \`has_more\` \u3068 \`next_cursor\` \u306B\u3088\u308B\u30AB\u30FC\u30BD\u30EB\u30D9\u30FC\u30B9\u3067\u3001\`start_cursor\` \u3068 \`page_size\`\uFF08\u6700\u5927100\uFF09\u3092\u4F7F\u7528\u3057\u307E\u3059\u3002
|
|
572
646
|
|
|
573
647
|
### Notion API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
|
|
574
648
|
|
|
@@ -16,6 +16,7 @@ var init_parameter_definition = __esm({
|
|
|
16
16
|
type;
|
|
17
17
|
secret;
|
|
18
18
|
required;
|
|
19
|
+
isDeprecated;
|
|
19
20
|
constructor(config) {
|
|
20
21
|
this.slug = config.slug;
|
|
21
22
|
this.name = config.name;
|
|
@@ -24,6 +25,7 @@ var init_parameter_definition = __esm({
|
|
|
24
25
|
this.type = config.type;
|
|
25
26
|
this.secret = config.secret;
|
|
26
27
|
this.required = config.required;
|
|
28
|
+
this.isDeprecated = config.isDeprecated ?? false;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Get the parameter value from a ConnectorConnectionObject.
|
|
@@ -282,7 +284,7 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
282
284
|
/**
|
|
283
285
|
* Create tools for connections that belong to this connector.
|
|
284
286
|
* Filters connections by connectorKey internally.
|
|
285
|
-
* Returns tools keyed as
|
|
287
|
+
* Returns tools keyed as `connector_${connectorKey}_${toolName}`.
|
|
286
288
|
*/
|
|
287
289
|
createTools(connections, config, opts) {
|
|
288
290
|
const myConnections = connections.filter(
|
|
@@ -292,7 +294,7 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
292
294
|
for (const t of Object.values(this.tools)) {
|
|
293
295
|
const tool = t.createTool(myConnections, config);
|
|
294
296
|
const originalToModelOutput = tool.toModelOutput;
|
|
295
|
-
result[
|
|
297
|
+
result[`connector_${this.connectorKey}_${t.name}`] = {
|
|
296
298
|
...tool,
|
|
297
299
|
toModelOutput: async (options) => {
|
|
298
300
|
if (!originalToModelOutput) {
|
|
@@ -348,19 +350,34 @@ async function runSetupFlow(flow, params, ctx, config) {
|
|
|
348
350
|
};
|
|
349
351
|
let state = flow.initialState();
|
|
350
352
|
let answerIdx = 0;
|
|
353
|
+
const pendingParameterUpdates = [];
|
|
351
354
|
for (const step of flow.steps) {
|
|
352
355
|
const ans = ctx.answers[answerIdx];
|
|
353
356
|
if (ans && ans.questionSlug === step.slug) {
|
|
354
357
|
state = step.applyAnswer(state, ans.answer);
|
|
358
|
+
if (step.toParameterUpdates) {
|
|
359
|
+
pendingParameterUpdates.push(...step.toParameterUpdates(state));
|
|
360
|
+
}
|
|
355
361
|
answerIdx += 1;
|
|
356
362
|
continue;
|
|
357
363
|
}
|
|
364
|
+
const resolvedAllowFreeText = step.allowFreeText !== void 0 ? step.allowFreeText : true;
|
|
358
365
|
if (step.type === "text") {
|
|
366
|
+
if (step.fetchOptions) {
|
|
367
|
+
const options2 = await step.fetchOptions(state, runtime);
|
|
368
|
+
if (options2.length === 0) {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
359
372
|
return {
|
|
360
373
|
type: "nextQuestion",
|
|
361
374
|
questionSlug: step.slug,
|
|
362
375
|
question: step.question[ctx.language],
|
|
363
|
-
questionType: "text"
|
|
376
|
+
questionType: "text",
|
|
377
|
+
allowFreeText: resolvedAllowFreeText,
|
|
378
|
+
...pendingParameterUpdates.length > 0 && {
|
|
379
|
+
parameterUpdates: pendingParameterUpdates
|
|
380
|
+
}
|
|
364
381
|
};
|
|
365
382
|
}
|
|
366
383
|
const options = step.fetchOptions ? await step.fetchOptions(state, runtime) : [];
|
|
@@ -372,11 +389,21 @@ async function runSetupFlow(flow, params, ctx, config) {
|
|
|
372
389
|
questionSlug: step.slug,
|
|
373
390
|
question: step.question[ctx.language],
|
|
374
391
|
questionType: step.type,
|
|
375
|
-
options
|
|
392
|
+
options,
|
|
393
|
+
allowFreeText: resolvedAllowFreeText,
|
|
394
|
+
...pendingParameterUpdates.length > 0 && {
|
|
395
|
+
parameterUpdates: pendingParameterUpdates
|
|
396
|
+
}
|
|
376
397
|
};
|
|
377
398
|
}
|
|
378
399
|
const dataInvestigationResult = await flow.finalize(state, runtime);
|
|
379
|
-
return {
|
|
400
|
+
return {
|
|
401
|
+
type: "fulfilled",
|
|
402
|
+
dataInvestigationResult,
|
|
403
|
+
...pendingParameterUpdates.length > 0 && {
|
|
404
|
+
parameterUpdates: pendingParameterUpdates
|
|
405
|
+
}
|
|
406
|
+
};
|
|
380
407
|
}
|
|
381
408
|
async function resolveSetupSelection(params) {
|
|
382
409
|
const { selected, allSentinel, fetchAll, limit } = params;
|
|
@@ -397,13 +424,13 @@ var AUTH_TYPES = {
|
|
|
397
424
|
// ../connectors/src/connectors/notion/setup.ts
|
|
398
425
|
var notionOnboarding = new ConnectorOnboarding({
|
|
399
426
|
dataOverviewInstructions: {
|
|
400
|
-
en: `1. Call
|
|
401
|
-
2. For each database found, call
|
|
402
|
-
3. Call
|
|
427
|
+
en: `1. Call connector_notion_request with POST /search and { "page_size": 5 } to discover available pages and databases
|
|
428
|
+
2. For each database found, call connector_notion_request with POST /databases/{database_id}/query and { "page_size": 5 } to sample records and understand the schema
|
|
429
|
+
3. Call connector_notion_request with GET /users to list workspace members
|
|
403
430
|
4. Explore page content with GET /blocks/{page_id}/children as needed`,
|
|
404
|
-
ja: `1.
|
|
405
|
-
2. \u898B\u3064\u304B\u3063\u305F\u5404\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u306B\u3064\u3044\u3066\
|
|
406
|
-
3.
|
|
431
|
+
ja: `1. connector_notion_request \u3067 POST /search \u3092 { "page_size": 5 } \u3067\u547C\u3073\u51FA\u3057\u3001\u5229\u7528\u53EF\u80FD\u306A\u30DA\u30FC\u30B8\u3068\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u3092\u691C\u51FA
|
|
432
|
+
2. \u898B\u3064\u304B\u3063\u305F\u5404\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u306B\u3064\u3044\u3066\u3001connector_notion_request \u3067 POST /databases/{database_id}/query \u3092 { "page_size": 5 } \u3067\u547C\u3073\u51FA\u3057\u3001\u30EC\u30B3\u30FC\u30C9\u306E\u30B5\u30F3\u30D7\u30EA\u30F3\u30B0\u3068\u30B9\u30AD\u30FC\u30DE\u306E\u628A\u63E1\u3092\u884C\u3046
|
|
433
|
+
3. connector_notion_request \u3067 GET /users \u3092\u547C\u3073\u51FA\u3057\u3001\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u30E1\u30F3\u30D0\u30FC\u3092\u4E00\u89A7\u8868\u793A
|
|
407
434
|
4. \u5FC5\u8981\u306B\u5FDC\u3058\u3066 GET /blocks/{page_id}/children \u3067\u30DA\u30FC\u30B8\u30B3\u30F3\u30C6\u30F3\u30C4\u3092\u63A2\u7D22`
|
|
408
435
|
}
|
|
409
436
|
});
|
|
@@ -467,6 +494,38 @@ async function getDatabase(params, databaseId) {
|
|
|
467
494
|
}
|
|
468
495
|
return await res.json();
|
|
469
496
|
}
|
|
497
|
+
async function queryDatabaseSample(params, databaseId) {
|
|
498
|
+
try {
|
|
499
|
+
const res = await apiFetch(params, `/databases/${databaseId}/query`, {
|
|
500
|
+
method: "POST",
|
|
501
|
+
body: JSON.stringify({ page_size: 3 })
|
|
502
|
+
});
|
|
503
|
+
if (!res.ok) return [];
|
|
504
|
+
const data = await res.json();
|
|
505
|
+
return data.results ?? [];
|
|
506
|
+
} catch {
|
|
507
|
+
return [];
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function formatPropertyValue(prop) {
|
|
511
|
+
if (prop == null || typeof prop !== "object") return "";
|
|
512
|
+
const p = prop;
|
|
513
|
+
const t = p.type ?? "";
|
|
514
|
+
const v = p[t];
|
|
515
|
+
if (v == null) return "";
|
|
516
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean")
|
|
517
|
+
return String(v);
|
|
518
|
+
if (Array.isArray(v)) {
|
|
519
|
+
if (v.length === 0) return "";
|
|
520
|
+
const first = v[0];
|
|
521
|
+
return first.plain_text ?? first.name ?? `[${v.length} items]`;
|
|
522
|
+
}
|
|
523
|
+
if (typeof v === "object") {
|
|
524
|
+
const o = v;
|
|
525
|
+
return o.name ?? o.plain_text ?? o.start ?? JSON.stringify(v).slice(0, 30);
|
|
526
|
+
}
|
|
527
|
+
return String(v);
|
|
528
|
+
}
|
|
470
529
|
var notionSetupFlow = {
|
|
471
530
|
initialState: () => ({}),
|
|
472
531
|
steps: [
|
|
@@ -511,11 +570,28 @@ var notionSetupFlow = {
|
|
|
511
570
|
sections.push(`### Database: ${title}`, "", `- id: \`${db.id}\``, "");
|
|
512
571
|
sections.push("| Property | Type |");
|
|
513
572
|
sections.push("|----------|------|");
|
|
514
|
-
|
|
573
|
+
const propEntries = Object.entries(db.properties ?? {});
|
|
574
|
+
for (const [name, def] of propEntries) {
|
|
515
575
|
const escapedName = name.replace(/\|/g, "\\|");
|
|
516
576
|
sections.push(`| ${escapedName} | ${def?.type ?? "-"} |`);
|
|
517
577
|
}
|
|
518
578
|
sections.push("");
|
|
579
|
+
const pages = await queryDatabaseSample(rt.params, dbId);
|
|
580
|
+
if (pages.length > 0) {
|
|
581
|
+
const sampleProps = propEntries.slice(0, 5).map(([n]) => n);
|
|
582
|
+
if (sampleProps.length > 0) {
|
|
583
|
+
sections.push(`#### Sample pages (${pages.length})`, "");
|
|
584
|
+
sections.push(`| ${sampleProps.join(" | ")} |`);
|
|
585
|
+
sections.push(`| ${sampleProps.map(() => "---").join(" | ")} |`);
|
|
586
|
+
for (const page of pages) {
|
|
587
|
+
const cells = sampleProps.map(
|
|
588
|
+
(n) => formatPropertyValue(page.properties?.[n]).replace(/\|/g, "\\|")
|
|
589
|
+
);
|
|
590
|
+
sections.push(`| ${cells.join(" | ")} |`);
|
|
591
|
+
}
|
|
592
|
+
sections.push("");
|
|
593
|
+
}
|
|
594
|
+
}
|
|
519
595
|
}
|
|
520
596
|
return sections.join("\n");
|
|
521
597
|
}
|
|
@@ -616,7 +692,7 @@ var notionConnector = new ConnectorPlugin({
|
|
|
616
692
|
systemPrompt: {
|
|
617
693
|
en: `### Tools
|
|
618
694
|
|
|
619
|
-
- \`
|
|
695
|
+
- \`connector_notion_request\`: The only way to call the Notion REST API. Use it to search pages and databases, query database records, retrieve page content and blocks, and manage workspace data. Authentication (Bearer token) and Notion-Version header are configured automatically. Pagination uses cursor-based \`start_cursor\` and \`page_size\` (max 100) with \`has_more\` and \`next_cursor\` in the response.
|
|
620
696
|
|
|
621
697
|
### Business Logic
|
|
622
698
|
|
|
@@ -686,7 +762,7 @@ export default async function handler(c: Context) {
|
|
|
686
762
|
- Properties with more than 25 items (e.g., people, relation) need the property endpoint for full data`,
|
|
687
763
|
ja: `### \u30C4\u30FC\u30EB
|
|
688
764
|
|
|
689
|
-
- \`
|
|
765
|
+
- \`connector_notion_request\`: Notion REST API\u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\u3002\u30DA\u30FC\u30B8\u3084\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u306E\u691C\u7D22\u3001\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u30EC\u30B3\u30FC\u30C9\u306E\u30AF\u30A8\u30EA\u3001\u30DA\u30FC\u30B8\u30B3\u30F3\u30C6\u30F3\u30C4\u3084\u30D6\u30ED\u30C3\u30AF\u306E\u53D6\u5F97\u3001\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u30C7\u30FC\u30BF\u306E\u7BA1\u7406\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u8A8D\u8A3C\uFF08Bearer\u30C8\u30FC\u30AF\u30F3\uFF09\u3068Notion-Version\u30D8\u30C3\u30C0\u30FC\u306F\u81EA\u52D5\u7684\u306B\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002\u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u306F\u30EC\u30B9\u30DD\u30F3\u30B9\u306E \`has_more\` \u3068 \`next_cursor\` \u306B\u3088\u308B\u30AB\u30FC\u30BD\u30EB\u30D9\u30FC\u30B9\u3067\u3001\`start_cursor\` \u3068 \`page_size\`\uFF08\u6700\u5927100\uFF09\u3092\u4F7F\u7528\u3057\u307E\u3059\u3002
|
|
690
766
|
|
|
691
767
|
### Business Logic
|
|
692
768
|
|
|
@@ -16,6 +16,7 @@ var init_parameter_definition = __esm({
|
|
|
16
16
|
type;
|
|
17
17
|
secret;
|
|
18
18
|
required;
|
|
19
|
+
isDeprecated;
|
|
19
20
|
constructor(config) {
|
|
20
21
|
this.slug = config.slug;
|
|
21
22
|
this.name = config.name;
|
|
@@ -24,6 +25,7 @@ var init_parameter_definition = __esm({
|
|
|
24
25
|
this.type = config.type;
|
|
25
26
|
this.secret = config.secret;
|
|
26
27
|
this.required = config.required;
|
|
28
|
+
this.isDeprecated = config.isDeprecated ?? false;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Get the parameter value from a ConnectorConnectionObject.
|
|
@@ -142,7 +144,7 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
142
144
|
/**
|
|
143
145
|
* Create tools for connections that belong to this connector.
|
|
144
146
|
* Filters connections by connectorKey internally.
|
|
145
|
-
* Returns tools keyed as
|
|
147
|
+
* Returns tools keyed as `connector_${connectorKey}_${toolName}`.
|
|
146
148
|
*/
|
|
147
149
|
createTools(connections, config, opts) {
|
|
148
150
|
const myConnections = connections.filter(
|
|
@@ -152,7 +154,7 @@ var ConnectorPlugin = class _ConnectorPlugin {
|
|
|
152
154
|
for (const t of Object.values(this.tools)) {
|
|
153
155
|
const tool = t.createTool(myConnections, config);
|
|
154
156
|
const originalToModelOutput = tool.toModelOutput;
|
|
155
|
-
result[
|
|
157
|
+
result[`connector_${this.connectorKey}_${t.name}`] = {
|
|
156
158
|
...tool,
|
|
157
159
|
toModelOutput: async (options) => {
|
|
158
160
|
if (!originalToModelOutput) {
|