@dual-os/notion-api 0.0.0-stage → 6.0.4

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.
Files changed (46) hide show
  1. package/LICENSE +4 -0
  2. package/Runner.js +5537 -0
  3. package/Runner.js.map +59 -0
  4. package/bundle-inventory.json +1 -0
  5. package/dist/_virtual/_rolldown/runtime.js +10 -0
  6. package/dist/_virtual/_rolldown/runtime.js.map +9 -0
  7. package/dist/auth.d.ts +37 -0
  8. package/dist/auth.d.ts.map +1 -0
  9. package/dist/auth.js +17 -0
  10. package/dist/auth.js.map +9 -0
  11. package/dist/generated/http.d.ts +81 -0
  12. package/dist/generated/http.d.ts.map +1 -0
  13. package/dist/generated/http.js +64 -0
  14. package/dist/generated/http.js.map +9 -0
  15. package/dist/generated/operations.d.ts +27637 -0
  16. package/dist/generated/operations.d.ts.map +1 -0
  17. package/dist/generated/operations.js +1162 -0
  18. package/dist/generated/operations.js.map +9 -0
  19. package/dist/generated/plugin.d.ts +261 -0
  20. package/dist/generated/plugin.d.ts.map +1 -0
  21. package/dist/generated/plugin.js +439 -0
  22. package/dist/generated/plugin.js.map +10 -0
  23. package/dist/triggers.d.ts +118 -0
  24. package/dist/triggers.d.ts.map +1 -0
  25. package/dist/triggers.js +17 -0
  26. package/dist/triggers.js.map +9 -0
  27. package/dual-plugin.json +1 -0
  28. package/licenses/@dual-os_sdk@0.9.0/LICENSE +4 -0
  29. package/licenses/@effect_platform-node-shared@4.1.2/LICENSE +21 -0
  30. package/licenses/@effect_platform-node@4.1.2/LICENSE +21 -0
  31. package/licenses/effect@4.1.2/LICENSE +21 -0
  32. package/package.json +1 -6
  33. package/plugin-1s0prvga.js +19134 -0
  34. package/plugin-1s0prvga.js.map +158 -0
  35. package/plugin-2jdfj02n.js +18 -0
  36. package/plugin-2jdfj02n.js.map +10 -0
  37. package/plugin-529jjg5q.js +1303 -0
  38. package/plugin-529jjg5q.js.map +18 -0
  39. package/plugin-7b963ree.js +167 -0
  40. package/plugin-7b963ree.js.map +10 -0
  41. package/plugin-d1qmasfk.js +62 -0
  42. package/plugin-d1qmasfk.js.map +10 -0
  43. package/plugin-v355veh7.js +105451 -0
  44. package/plugin-v355veh7.js.map +10 -0
  45. package/plugin.json +30 -0
  46. package/README.md +0 -3
@@ -0,0 +1,1303 @@
1
+ // @bun
2
+ import {
3
+ __exportAll2
4
+ } from "./plugin-2jdfj02n.js";
5
+ import {
6
+ dual,
7
+ identity,
8
+ pipe,
9
+ flow,
10
+ isString,
11
+ isObject,
12
+ hasProperty,
13
+ equals,
14
+ PipeInspectableProto,
15
+ Number2,
16
+ mapInput,
17
+ none,
18
+ some,
19
+ isNone,
20
+ match2,
21
+ getOrElse,
22
+ orElse,
23
+ fromNullishOr,
24
+ fromUndefinedOr,
25
+ getOrNull,
26
+ getOrUndefined,
27
+ liftThrowable,
28
+ map,
29
+ flatMap,
30
+ filter,
31
+ liftPredicate,
32
+ Reference,
33
+ succeed,
34
+ fail,
35
+ failVoid,
36
+ fromOption,
37
+ try_,
38
+ isSuccess,
39
+ match3,
40
+ fromEntries,
41
+ toEntries,
42
+ has,
43
+ map2,
44
+ ensure,
45
+ append,
46
+ isArray,
47
+ isReadonlyArrayNonEmpty,
48
+ getUnsafe2,
49
+ headNonEmpty,
50
+ findFirst,
51
+ sort,
52
+ zip,
53
+ contains2,
54
+ empty,
55
+ map3,
56
+ flatMap2,
57
+ filterMap,
58
+ filter2,
59
+ reduce,
60
+ fromNullishOr2,
61
+ every,
62
+ join,
63
+ millis,
64
+ TaggedClass,
65
+ TaggedError,
66
+ increment,
67
+ toLowerCase,
68
+ replace,
69
+ trim,
70
+ slice,
71
+ isEmpty,
72
+ isNonEmpty,
73
+ split,
74
+ startsWith,
75
+ endsWith,
76
+ match4,
77
+ replaceAll,
78
+ isEffect,
79
+ forEach,
80
+ promise,
81
+ succeed4,
82
+ suspend,
83
+ sync,
84
+ void_2,
85
+ gen,
86
+ fail5,
87
+ withFiber,
88
+ fromOption2,
89
+ flatMap3,
90
+ result,
91
+ map4,
92
+ mapError,
93
+ orDie,
94
+ ignore,
95
+ serviceOption,
96
+ provideService,
97
+ scoped,
98
+ acquireRelease,
99
+ fnUntraced,
100
+ fn,
101
+ encode,
102
+ encode2,
103
+ decode,
104
+ makeZoned,
105
+ make3,
106
+ toUtc,
107
+ toDateUtc,
108
+ toEpochMillis,
109
+ formatIso,
110
+ formatIsoOffset,
111
+ empty2,
112
+ empty3,
113
+ InvalidValue,
114
+ compose,
115
+ transform,
116
+ transformEffect,
117
+ is,
118
+ decodeUnknownEffect,
119
+ decodeOption,
120
+ encodeEffect,
121
+ isSchema,
122
+ optionalKey,
123
+ optional,
124
+ toType,
125
+ Literal,
126
+ Unknown,
127
+ String3,
128
+ Boolean2,
129
+ Struct,
130
+ Record,
131
+ StructWithRest,
132
+ ArraySchema,
133
+ Literals,
134
+ NullOr,
135
+ decodeTo,
136
+ Int,
137
+ Natural,
138
+ NonEmptyString,
139
+ Defect,
140
+ fromJsonString,
141
+ Uint8ArrayFromBase64,
142
+ TaggedError2,
143
+ toEquivalence,
144
+ Json,
145
+ make5,
146
+ get2,
147
+ set,
148
+ update,
149
+ fromEffect,
150
+ fromIterable3,
151
+ paginate,
152
+ unwrap2,
153
+ mapEffect,
154
+ flatMap4,
155
+ filterMap2,
156
+ decodeText,
157
+ runCollect,
158
+ runHead,
159
+ value2,
160
+ discriminatorsExhaustive,
161
+ empty5,
162
+ HttpClientError,
163
+ InvalidUrlError,
164
+ makeWith,
165
+ post,
166
+ put,
167
+ del,
168
+ setMethod,
169
+ setHeader,
170
+ setHeaders,
171
+ bearerToken,
172
+ setUrl,
173
+ setUrlParam,
174
+ setBody,
175
+ bodyUint8Array,
176
+ bodyJsonUnsafe,
177
+ bodyFormDataRecord,
178
+ HttpClient,
179
+ transformResponse,
180
+ filterStatusOk,
181
+ mapRequest,
182
+ mapRequestEffect,
183
+ RequestInit,
184
+ __exportAll3,
185
+ ActionHandlerError,
186
+ fromHttpClientFailure,
187
+ AuthMethod_exports,
188
+ Schema,
189
+ Key,
190
+ Event,
191
+ commandSchema,
192
+ Service2,
193
+ File3,
194
+ read,
195
+ write
196
+ } from "./plugin-1s0prvga.js";
197
+
198
+ // ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/internal/random.js
199
+ var Random = /* @__PURE__ */ Reference("effect/Random", {
200
+ defaultValue: () => ({
201
+ nextIntUnsafe() {
202
+ return Math.floor(Math.random() * (Number.MAX_SAFE_INTEGER - Number.MIN_SAFE_INTEGER + 1)) + Number.MIN_SAFE_INTEGER;
203
+ },
204
+ nextDoubleUnsafe() {
205
+ return Math.random();
206
+ }
207
+ })
208
+ });
209
+
210
+ // ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/Random.js
211
+ var Random2 = Random;
212
+ var randomWith = (f) => withFiber((fiber) => succeed4(f(fiber.getRef(Random2))));
213
+ var nextInt = /* @__PURE__ */ randomWith((r) => r.nextIntUnsafe());
214
+
215
+ // ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/Boolean.js
216
+ var Boolean = globalThis.Boolean;
217
+ var match = /* @__PURE__ */ dual(2, (value, options) => value ? options.onTrue() : options.onFalse());
218
+
219
+ // ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/Ref.js
220
+ var TypeId = "~effect/Ref";
221
+ var RefProto = {
222
+ [TypeId]: {
223
+ _A: identity
224
+ },
225
+ ...PipeInspectableProto,
226
+ toJSON() {
227
+ return {
228
+ _id: "Ref",
229
+ ref: this.ref
230
+ };
231
+ }
232
+ };
233
+ var makeUnsafe = (value) => {
234
+ const self = Object.create(RefProto);
235
+ self.ref = make5(value);
236
+ return self;
237
+ };
238
+ var make = (value) => sync(() => makeUnsafe(value));
239
+ var get = (self) => sync(() => self.ref.current);
240
+ var set2 = /* @__PURE__ */ dual(2, (self, value) => sync(() => set(self.ref, value)));
241
+ var getAndUpdate = /* @__PURE__ */ dual(2, (self, f) => sync(() => {
242
+ const current = self.ref.current;
243
+ self.ref.current = f(current);
244
+ return current;
245
+ }));
246
+
247
+ // ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/encoding/Sse.js
248
+ var SseErrorTypeId = "~effect/encoding/Sse/SseError";
249
+
250
+ class EventTooLarge extends (/* @__PURE__ */ TaggedError("EventTooLarge")) {
251
+ get message() {
252
+ return `Pending SSE event exceeded the maximum size of ${this.maxEventSize}`;
253
+ }
254
+ }
255
+
256
+ class SseError extends (/* @__PURE__ */ TaggedError("SseError")) {
257
+ [SseErrorTypeId] = SseErrorTypeId;
258
+ get message() {
259
+ return this.reason.message;
260
+ }
261
+ }
262
+ var defaultMaxEventSize = 10 * 1024 * 1024;
263
+ function makeParser(onParse, options) {
264
+ const maxEventSize = options?.maxEventSize ?? defaultMaxEventSize;
265
+ const dispatchEmptyNamedEvents = options?.dispatchEmptyNamedEvents === true;
266
+ let isFirstChunk;
267
+ let pending;
268
+ let pendingLength;
269
+ let discardTrailingNewline;
270
+ let generation = 0;
271
+ let lastEventId;
272
+ let eventName;
273
+ let data;
274
+ reset();
275
+ return {
276
+ feed,
277
+ reset
278
+ };
279
+ function reset() {
280
+ generation++;
281
+ isFirstChunk = true;
282
+ pending = [];
283
+ pendingLength = 0;
284
+ discardTrailingNewline = false;
285
+ lastEventId = undefined;
286
+ eventName = undefined;
287
+ data = "";
288
+ }
289
+ function feed(chunk) {
290
+ if (chunk.length === 0)
291
+ return;
292
+ if (isFirstChunk && chunk.startsWith(BOM)) {
293
+ chunk = chunk.slice(BOM.length);
294
+ }
295
+ isFirstChunk = false;
296
+ const length = chunk.length;
297
+ const currentGeneration = generation;
298
+ let position = 0;
299
+ while (position < length) {
300
+ if (discardTrailingNewline) {
301
+ discardTrailingNewline = false;
302
+ if (chunk.charCodeAt(position) === LF) {
303
+ ++position;
304
+ continue;
305
+ }
306
+ }
307
+ let lineEnd = position;
308
+ while (lineEnd < length) {
309
+ const code = chunk.charCodeAt(lineEnd);
310
+ if (code === CR || code === LF)
311
+ break;
312
+ ++lineEnd;
313
+ }
314
+ if (lineEnd === length) {
315
+ pending.push(chunk.slice(position));
316
+ pendingLength += length - position;
317
+ break;
318
+ }
319
+ discardTrailingNewline = chunk.charCodeAt(lineEnd) === CR;
320
+ let line = chunk.slice(position, lineEnd);
321
+ if (pending.length > 0) {
322
+ pending.push(line);
323
+ line = pending.join("");
324
+ pending = [];
325
+ pendingLength = 0;
326
+ }
327
+ parseLine(line);
328
+ if (generation !== currentGeneration) {
329
+ return;
330
+ }
331
+ position = lineEnd + 1;
332
+ }
333
+ if (pendingLength + data.length > maxEventSize) {
334
+ const error = new SseError({
335
+ reason: new EventTooLarge({
336
+ maxEventSize
337
+ })
338
+ });
339
+ reset();
340
+ return error;
341
+ }
342
+ }
343
+ function parseLine(line) {
344
+ if (line.length === 0) {
345
+ const named = eventName !== undefined && eventName !== "";
346
+ const event = eventName || "message";
347
+ const eventData = data;
348
+ eventName = undefined;
349
+ data = "";
350
+ if (eventData.length > 0 || dispatchEmptyNamedEvents && named) {
351
+ onParse({
352
+ _tag: "Event",
353
+ id: lastEventId,
354
+ event,
355
+ data: eventData.slice(0, -1)
356
+ });
357
+ }
358
+ return;
359
+ }
360
+ const colon = line.indexOf(":");
361
+ let field = line;
362
+ let value = "";
363
+ if (colon >= 0) {
364
+ field = line.slice(0, colon);
365
+ value = line.slice(line.charCodeAt(colon + 1) === SPACE ? colon + 2 : colon + 1);
366
+ }
367
+ if (field === "data") {
368
+ data += value + `
369
+ `;
370
+ } else if (field === "event") {
371
+ eventName = value;
372
+ } else if (field === "id" && !value.includes("\x00")) {
373
+ lastEventId = value;
374
+ } else if (field === "retry" && /^\d+$/.test(value)) {
375
+ const retry = parseInt(value, 10);
376
+ onParse(new Retry({
377
+ duration: millis(retry),
378
+ lastEventId
379
+ }));
380
+ }
381
+ }
382
+ }
383
+ var BOM = "\uFEFF";
384
+ var LF = 10;
385
+ var CR = 13;
386
+ var SPACE = 32;
387
+ var RetryTypeId = "~effect/encoding/Sse/Retry";
388
+
389
+ class Retry extends (/* @__PURE__ */ TaggedClass("Retry")) {
390
+ [RetryTypeId] = RetryTypeId;
391
+ static is(u) {
392
+ return hasProperty(u, RetryTypeId);
393
+ }
394
+ static filter(u) {
395
+ return Retry.is(u) ? succeed(u) : fail(u);
396
+ }
397
+ }
398
+
399
+ // ../../../../node_modules/.bun/@dual-os+sdk@0.9.0+a827849ded09603e/node_modules/@dual-os/sdk/dist/AgentChannelConformance.js
400
+ var Command = commandSchema(Json);
401
+ var Fixture = Struct({
402
+ activate: Command,
403
+ channelId: Key,
404
+ connectionId: optionalKey(Key),
405
+ deactivate: Command,
406
+ definitionSettings: Json,
407
+ deliver: Command,
408
+ deploymentSettings: Json,
409
+ receive: Command
410
+ });
411
+ var ConformanceError = class extends TaggedError2()("AgentChannelConformanceError", {
412
+ command: Literals([
413
+ "activate",
414
+ "deactivate",
415
+ "receive",
416
+ "deliver"
417
+ ]),
418
+ rule: Literals([
419
+ "command_kind",
420
+ "stable_result",
421
+ "stable_events",
422
+ "boundary_rejection"
423
+ ])
424
+ }) {
425
+ };
426
+ var run = fn("AgentChannelConformance.run")(function* (input) {
427
+ const fixture = yield* decodeUnknownEffect(Fixture)(input, { onExcessProperty: "error" });
428
+ const runtime = yield* Service2;
429
+ const definition = yield* runtime.getAgentChannel({ channelId: fixture.channelId });
430
+ const { activate, receive, deliver, deactivate, ...config } = fixture;
431
+ const { connectionId: _connectionId, ...withoutConnection } = config;
432
+ const probes = [
433
+ {
434
+ code: "invalid_input",
435
+ input: {
436
+ ...config,
437
+ channelId: "",
438
+ command: activate
439
+ }
440
+ },
441
+ {
442
+ input: {
443
+ ...config,
444
+ channelId: "conformance/missing/channel",
445
+ command: activate
446
+ },
447
+ code: "not_found"
448
+ },
449
+ {
450
+ code: "invalid_input",
451
+ input: {
452
+ ...config,
453
+ command: {
454
+ ...activate,
455
+ operationKey: ""
456
+ }
457
+ }
458
+ },
459
+ {
460
+ code: "invalid_input",
461
+ input: {
462
+ ...config,
463
+ agent: { id: "synthetic-authority" },
464
+ command: activate
465
+ }
466
+ },
467
+ {
468
+ code: "invalid_auth",
469
+ input: definition.authMethods.length === 0 ? {
470
+ ...config,
471
+ command: activate,
472
+ connectionId: "unexpected"
473
+ } : {
474
+ ...withoutConnection,
475
+ command: activate
476
+ }
477
+ }
478
+ ];
479
+ for (const probe of probes) {
480
+ const outcome = yield* suspend(() => runtime.executeAgentChannel(probe.input)).pipe(result);
481
+ if (outcome._tag !== "Failure" || outcome.failure.code !== probe.code)
482
+ return yield* new ConformanceError({
483
+ command: "activate",
484
+ rule: "boundary_rejection"
485
+ });
486
+ }
487
+ const commands = [
488
+ ["activate", activate],
489
+ ["receive", receive],
490
+ ["deliver", deliver],
491
+ ["deactivate", deactivate]
492
+ ];
493
+ for (const [kind, command] of commands)
494
+ if (command.kind !== kind)
495
+ return yield* new ConformanceError({
496
+ command: kind,
497
+ rule: "command_kind"
498
+ });
499
+ const activated = yield* acquireRelease(runtime.executeAgentChannel({
500
+ ...config,
501
+ command: activate
502
+ }), (result2) => runtime.executeAgentChannel({
503
+ ...config,
504
+ command: {
505
+ ...deactivate,
506
+ ...result2.kind === "activate" ? {
507
+ installationKey: result2.installationKey,
508
+ state: result2.state
509
+ } : {}
510
+ }
511
+ }).pipe(orDie));
512
+ for (const [kind, command] of commands) {
513
+ const first = kind === "activate" ? activated : yield* runtime.executeAgentChannel({
514
+ ...config,
515
+ command
516
+ });
517
+ if (kind === "deliver" && definition.features.deliveryMode === "at-most-once")
518
+ continue;
519
+ const second = yield* runtime.executeAgentChannel({
520
+ ...config,
521
+ command
522
+ });
523
+ const firstJson = yield* decodeUnknownEffect(Json)(first);
524
+ const secondJson = yield* decodeUnknownEffect(Json)(second);
525
+ if (!toEquivalence(Json)(firstJson, secondJson))
526
+ return yield* new ConformanceError({
527
+ command: kind,
528
+ rule: "stable_result"
529
+ });
530
+ if (kind === "receive") {
531
+ const nextReceipt = yield* runtime.executeAgentChannel({
532
+ ...config,
533
+ command: {
534
+ ...command,
535
+ operationKey: `${command.operationKey.slice(0, 500)}:replay`
536
+ }
537
+ });
538
+ if (first.kind !== "receive" || nextReceipt.kind !== "receive" || !toEquivalence(ArraySchema(Event))(first.events, nextReceipt.events))
539
+ return yield* new ConformanceError({
540
+ command: kind,
541
+ rule: "stable_events"
542
+ });
543
+ }
544
+ }
545
+ }, scoped);
546
+
547
+ // ../../../../node_modules/.bun/@dual-os+sdk@0.9.0+a827849ded09603e/node_modules/@dual-os/sdk/dist/Mcp.js
548
+ var McpError = class extends TaggedError2()("McpError", {
549
+ cause: optional(Defect()),
550
+ message: String3
551
+ }) {
552
+ };
553
+ var protocolVersion = "2025-06-18";
554
+ var Implementation = Struct({
555
+ name: String3,
556
+ title: optionalKey(String3),
557
+ version: String3
558
+ });
559
+ var Tool = Struct({
560
+ annotations: optionalKey(Struct({ title: optionalKey(String3) })),
561
+ description: optionalKey(String3),
562
+ inputSchema: Record(String3, Unknown),
563
+ name: String3,
564
+ outputSchema: optionalKey(Record(String3, Unknown)),
565
+ title: optionalKey(String3)
566
+ });
567
+ var ListToolsResult = Struct({
568
+ nextCursor: optionalKey(String3),
569
+ tools: ArraySchema(Tool)
570
+ });
571
+ var ContentBlock = StructWithRest(Struct({
572
+ text: optionalKey(String3),
573
+ type: String3
574
+ }), [Record(String3, Unknown)]);
575
+ var CallToolResult = Struct({
576
+ content: ArraySchema(ContentBlock),
577
+ isError: optionalKey(Boolean2),
578
+ structuredContent: optionalKey(Unknown)
579
+ });
580
+ var InitializeResult = Struct({
581
+ protocolVersion: String3,
582
+ serverInfo: Implementation
583
+ });
584
+ var Message = Struct({
585
+ error: optionalKey(Struct({ message: String3 })),
586
+ id: optionalKey(Unknown),
587
+ result: optionalKey(Unknown)
588
+ });
589
+ var responseTo = fnUntraced(function* (id, method, response) {
590
+ const payloads = match(pipe(response.headers["content-type"] ?? "", startsWith("text/event-stream")), {
591
+ onFalse: () => fromEffect(response.text),
592
+ onTrue: () => unwrap2(sync(() => {
593
+ const events = make5(empty());
594
+ const parser = makeParser((event) => {
595
+ if (event._tag === "Event")
596
+ update(events, append(event.data));
597
+ });
598
+ return pipe(response.stream, decodeText(), mapEffect((chunk) => {
599
+ const error = parser.feed(chunk);
600
+ if (error !== undefined)
601
+ return fail5(McpError.make({
602
+ cause: error,
603
+ message: error.message
604
+ }));
605
+ const ready = get2(events);
606
+ set(events, empty());
607
+ return succeed4(ready);
608
+ }), flatMap4(fromIterable3));
609
+ }))
610
+ });
611
+ const found = yield* pipe(payloads, filterMap2((payload) => fromOption(filter(decodeOption(fromJsonString(Message))(payload), (message) => message.id === id && (message.result !== undefined || message.error !== undefined)), () => payload)), runHead);
612
+ return yield* fromOption2(found, () => McpError.make({ message: `${method} got no response` }));
613
+ });
614
+ var connect = fn("Mcp.connect")(function* (client, endpoint, headers) {
615
+ const checked = filterStatusOk(client);
616
+ const post2 = fnUntraced(function* (version, session, body) {
617
+ return yield* checked.execute(pipe(post(endpoint), setHeaders({
618
+ ...headers,
619
+ accept: "application/json, text/event-stream",
620
+ "mcp-protocol-version": version,
621
+ ...match2(session, {
622
+ onNone: () => ({}),
623
+ onSome: (id) => ({ "mcp-session-id": id })
624
+ })
625
+ }), bodyJsonUnsafe({
626
+ jsonrpc: "2.0",
627
+ ...body
628
+ })));
629
+ });
630
+ const call = fnUntraced(function* (version, session, id, method, params) {
631
+ const response = yield* post2(version, session, {
632
+ id,
633
+ method,
634
+ params
635
+ });
636
+ const message = yield* responseTo(id, method, response);
637
+ if (message.error !== undefined)
638
+ return yield* McpError.make({ message: `${method}: ${message.error.message}` });
639
+ return {
640
+ result: message.result,
641
+ session: orElse(fromNullishOr(response.headers["mcp-session-id"]), () => session)
642
+ };
643
+ });
644
+ const negotiatedVersion = yield* make(protocolVersion);
645
+ const initialized = yield* acquireRelease(call(protocolVersion, none(), 0, "initialize", {
646
+ capabilities: {},
647
+ clientInfo: {
648
+ name: "dual",
649
+ version: "1"
650
+ },
651
+ protocolVersion
652
+ }), (opened) => match2(opened.session, {
653
+ onNone: () => void_2,
654
+ onSome: (id) => flatMap3(get(negotiatedVersion), (version) => ignore(client.execute(pipe(del(endpoint), setHeaders({
655
+ ...headers,
656
+ "mcp-protocol-version": version,
657
+ "mcp-session-id": id
658
+ })))))
659
+ }));
660
+ const server = yield* decodeUnknownEffect(InitializeResult)(initialized.result);
661
+ if (server.protocolVersion !== protocolVersion && server.protocolVersion !== "2025-03-26")
662
+ return yield* McpError.make({ message: `Unsupported MCP protocol version ${server.protocolVersion}` });
663
+ yield* set2(negotiatedVersion, server.protocolVersion);
664
+ yield* post2(server.protocolVersion, initialized.session, { method: "notifications/initialized" });
665
+ const ids = yield* make(1);
666
+ return {
667
+ request: fn("Mcp.request")(function* (method, params) {
668
+ return (yield* call(server.protocolVersion, initialized.session, yield* getAndUpdate(ids, increment), method, params)).result;
669
+ }),
670
+ server: server.serverInfo
671
+ };
672
+ });
673
+ var listTools = fn("Mcp.listTools")(function* (client, endpoint, headers) {
674
+ const session = yield* connect(client, endpoint, headers);
675
+ const tools = yield* runCollect(paginate({}, fnUntraced(function* (params) {
676
+ const page = yield* decodeUnknownEffect(ListToolsResult)(yield* session.request("tools/list", params));
677
+ return [page.tools, map(fromUndefinedOr(page.nextCursor), (cursor) => ({ cursor }))];
678
+ })));
679
+ return {
680
+ server: session.server,
681
+ tools
682
+ };
683
+ }, scoped);
684
+
685
+ // ../../../../node_modules/.bun/@dual-os+sdk@0.9.0+a827849ded09603e/node_modules/@dual-os/sdk/dist/Http.js
686
+ var Http_exports = /* @__PURE__ */ __exportAll3({
687
+ Base64FromFile: () => Base64FromFile2,
688
+ Base64UrlFromFile: () => Base64UrlFromFile2,
689
+ DataUriFromFile: () => DataUriFromFile2,
690
+ DateTimeFromRfc2822: () => DateTimeFromRfc28222,
691
+ DateTimeFromUnixSeconds: () => DateTimeFromUnixSeconds2,
692
+ File: () => File2,
693
+ FileFromBase64: () => FileFromBase642,
694
+ FileFromBase64Url: () => FileFromBase64Url2,
695
+ FileFromDataUri: () => FileFromDataUri2,
696
+ Http: () => Http_exports,
697
+ Rfc2822FromDateTime: () => Rfc2822FromDateTime2,
698
+ UnixSecondsFromDateTime: () => UnixSecondsFromDateTime2,
699
+ continuation: () => continuation2,
700
+ decoded: () => decoded2,
701
+ form: () => form2,
702
+ literal: () => literal2,
703
+ make: () => make2,
704
+ params: () => params2,
705
+ path: () => path2,
706
+ preauthenticated: () => preauthenticated2,
707
+ segments: () => segments2,
708
+ withFile: () => withFile,
709
+ withForm: () => withForm
710
+ });
711
+ function preserveJsonProperties(value, input) {
712
+ if (equals(value, input))
713
+ return value;
714
+ if (isArray(value) && isArray(input))
715
+ for (const entry of zip(value, input))
716
+ preserveJsonProperties(entry[0], entry[1]);
717
+ else if (isObject(value) && isObject(input))
718
+ for (const entry of toEntries(input))
719
+ if (has(value, entry[0]))
720
+ preserveJsonProperties(value[entry[0]], entry[1]);
721
+ else
722
+ Object.defineProperty(value, entry[0], {
723
+ configurable: true,
724
+ enumerable: true,
725
+ value: entry[1],
726
+ writable: true
727
+ });
728
+ return value;
729
+ }
730
+ function decodeResponse(output) {
731
+ return flow(succeed4, flatMap3((input) => pipe(decodeUnknownEffect(output)(input), map4((value) => preserveJsonProperties(value, input)))));
732
+ }
733
+ var File2 = Struct({
734
+ _tag: optionalKey(Literal("ToolFile")),
735
+ contentBase64: Uint8ArrayFromBase64,
736
+ contentType: optionalKey(NullOr(String3)),
737
+ filename: optionalKey(NullOr(String3)),
738
+ sizeBytes: optionalKey(Natural)
739
+ }).annotate({ description: "A ToolFile, such as the result of a download, passed unchanged; or its contentBase64 with an optional contentType and filename." });
740
+ var signatures = [
741
+ ["image/jpeg", [[0, [
742
+ 255,
743
+ 216,
744
+ 255
745
+ ]]]],
746
+ ["image/png", [[0, [
747
+ 137,
748
+ 80,
749
+ 78,
750
+ 71
751
+ ]]]],
752
+ ["image/gif", [[0, [
753
+ 71,
754
+ 73,
755
+ 70,
756
+ 56
757
+ ]]]],
758
+ ["image/webp", [[0, [
759
+ 82,
760
+ 73,
761
+ 70,
762
+ 70
763
+ ]], [8, [
764
+ 87,
765
+ 69,
766
+ 66,
767
+ 80
768
+ ]]]],
769
+ ["application/pdf", [[0, [
770
+ 37,
771
+ 80,
772
+ 68,
773
+ 70
774
+ ]]]],
775
+ ["application/zip", [[0, [
776
+ 80,
777
+ 75,
778
+ 3,
779
+ 4
780
+ ]]]]
781
+ ];
782
+ var utf8 = new TextDecoder("utf-8", { fatal: true });
783
+ function sniff(bytes) {
784
+ return pipe(findFirst(signatures, (signature) => every(signature[1], (part) => every(part[1], (byte, index) => bytes[part[0] + index] === byte))), map((signature) => signature[0]), orElse(() => liftPredicate("text/plain", () => isSuccess(try_(() => utf8.decode(bytes))))), getOrNull);
785
+ }
786
+ function toolFile(bytes, declared, filename) {
787
+ return {
788
+ _tag: "ToolFile",
789
+ contentBase64: encode(bytes),
790
+ contentType: declared === null || pipe(declared, startsWith("application/octet-stream")) ? sniff(bytes) ?? declared : declared,
791
+ filename,
792
+ sizeBytes: bytes.byteLength
793
+ };
794
+ }
795
+ function invalid(expected, value, options) {
796
+ return fail5(new InvalidValue({ expected }, value, options));
797
+ }
798
+ function decodeBytes(text, options) {
799
+ return match3(decode(pipe(text, replaceAll("+", "-"), replaceAll("/", "_"))), {
800
+ onFailure: () => invalid("a Base64 or Base64Url string", text, options),
801
+ onSuccess: (bytes) => succeed4(bytes)
802
+ });
803
+ }
804
+ function contentOf(carrier) {
805
+ return transformEffect((text, options) => {
806
+ if (carrier !== "data-uri")
807
+ return map4(decodeBytes(text, options), (bytes) => ({
808
+ bytes,
809
+ contentType: null
810
+ }));
811
+ return match2(pipe(text, match4(/^data:([^;,]*)(?:;[^;,]*)*;base64,(.*)$/su)), {
812
+ onNone: () => invalid("a Base64 data URI", text, options),
813
+ onSome: (parts) => map4(decodeBytes(getUnsafe2(parts, 2), options), (bytes) => ({
814
+ bytes,
815
+ contentType: pipe(getUnsafe2(parts, 1), liftPredicate(isNonEmpty), getOrNull)
816
+ }))
817
+ });
818
+ });
819
+ }
820
+ function textOf(carrier, content) {
821
+ if (carrier === "base64")
822
+ return encode(content.bytes);
823
+ if (carrier === "base64url")
824
+ return encode2(content.bytes);
825
+ return `data:${content.contentType ?? sniff(content.bytes) ?? "application/octet-stream"};base64,${encode(content.bytes)}`;
826
+ }
827
+ function fileFrom(carrier) {
828
+ return String3.pipe(decodeTo(Schema, {
829
+ decode: compose(contentOf(carrier), transform((content) => toolFile(content.bytes, content.contentType, null))),
830
+ encode: transformEffect((file, options) => map4(decodeBytes(file.contentBase64, options), (bytes) => textOf(carrier, {
831
+ bytes,
832
+ contentType: file.contentType
833
+ })))
834
+ }));
835
+ }
836
+ function encodedFrom(carrier) {
837
+ return File2.pipe(decodeTo(String3, {
838
+ decode: transform((file) => textOf(carrier, {
839
+ bytes: file.contentBase64,
840
+ contentType: file.contentType ?? null
841
+ })),
842
+ encode: compose(contentOf(carrier), transform((content) => ({
843
+ contentBase64: content.bytes,
844
+ contentType: content.contentType
845
+ })))
846
+ }));
847
+ }
848
+ var FileFromBase642 = fileFrom("base64");
849
+ var FileFromBase64Url2 = fileFrom("base64url");
850
+ var Base64FromFile2 = encodedFrom("base64");
851
+ var Base64UrlFromFile2 = encodedFrom("base64url");
852
+ var FileFromDataUri2 = fileFrom("data-uri");
853
+ var DataUriFromFile2 = encodedFrom("data-uri");
854
+ var DateTimeText = String3.annotate({ format: "date-time" });
855
+ var rfc3339 = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.\d+)?(?:Z|([+-]\d{2}:\d{2}))$/u;
856
+ function rfc3339Instant(text) {
857
+ return pipe(fromNullishOr(rfc3339.exec(text)), flatMap((match5) => filter(makeZoned(text, { timeZone: match5[2] ?? "+00:00" }), (zoned) => startsWith(match5[1] ?? "")(formatIsoOffset(zoned)))), map(toUtc));
858
+ }
859
+ function instants(wire, expected, read, write) {
860
+ const fromWire = transformEffect((value, options) => match2(read(value), {
861
+ onNone: () => invalid(expected, value, options),
862
+ onSome: (instant) => succeed4(formatIso(instant))
863
+ }));
864
+ const toWire = transformEffect((text, options) => match2(rfc3339Instant(text), {
865
+ onNone: () => invalid("an ISO 8601 date-time", text, options),
866
+ onSome: (instant) => succeed4(write(instant))
867
+ }));
868
+ return {
869
+ input: pipe(DateTimeText, decodeTo(wire, {
870
+ decode: toWire,
871
+ encode: fromWire
872
+ })),
873
+ output: pipe(wire, decodeTo(DateTimeText, {
874
+ decode: fromWire,
875
+ encode: toWire
876
+ }))
877
+ };
878
+ }
879
+ var unixSeconds = instants(Int, "Unix seconds", (seconds) => map(make3(seconds * 1000), toUtc), (instant) => Math.floor(toEpochMillis(instant) / 1000));
880
+ var rfc2822 = instants(String3, "an RFC 2822 date-time", (text) => map(make3(text), toUtc), (instant) => toDateUtc(instant).toUTCString());
881
+ var DateTimeFromUnixSeconds2 = unixSeconds.output;
882
+ var UnixSecondsFromDateTime2 = unixSeconds.input;
883
+ var DateTimeFromRfc28222 = rfc2822.output;
884
+ var Rfc2822FromDateTime2 = rfc2822.input;
885
+ function decoded2(wire) {
886
+ return {
887
+ _tag: "Decoded",
888
+ wire
889
+ };
890
+ }
891
+ var GraphqlResponse = Struct({
892
+ data: optionalKey(NullOr(Record(String3, Unknown))),
893
+ errors: optionalKey(ArraySchema(StructWithRest(Struct({ message: String3 }), [Record(String3, Unknown)])))
894
+ });
895
+ function coerce(value) {
896
+ return isObject(value) ? JSON.stringify(value) : `${value}`;
897
+ }
898
+ function path2(value) {
899
+ return encodeURIComponent(coerce(value));
900
+ }
901
+ function literal2(value) {
902
+ return path2(pipe(coerce(value), replaceAll("'", "''")));
903
+ }
904
+ function segments2(value) {
905
+ return join(map3(split(coerce(value), "/"), encodeURIComponent), "/");
906
+ }
907
+ function deepObject(name, value) {
908
+ if (isArray(value))
909
+ return flatMap2(value, (item, index) => deepObject(`${name}[${index}]`, item));
910
+ if (isObject(value))
911
+ return flatMap2(toEntries(value), (entry) => deepObject(`${name}[${entry[0]}]`, entry[1]));
912
+ return value === undefined ? [] : [[name, coerce(value)]];
913
+ }
914
+ function params2(fields, joined = [], deep = [], exploded = []) {
915
+ return flatMap2(toEntries(fields), (field) => {
916
+ if (field[1] === undefined)
917
+ return [];
918
+ if (contains2(deep, field[0]))
919
+ return deepObject(field[0], field[1]);
920
+ const values = field[1];
921
+ if (contains2(exploded, field[0]) && isObject(values) && !isArray(values))
922
+ return filterMap(toEntries(values), (entry) => entry[1] === undefined ? failVoid : succeed([entry[0], coerce(entry[1])]));
923
+ if (!isArray(values))
924
+ return [[field[0], coerce(values)]];
925
+ const separator = findFirst(joined, (entry) => {
926
+ const pair = isString(entry) ? [entry, ","] : entry;
927
+ return pair[0] === field[0] ? some(pair[1]) : none();
928
+ });
929
+ return match2(separator, {
930
+ onNone: () => map3(values, (item) => [field[0], coerce(item)]),
931
+ onSome: (value) => [[field[0], join(map3(values, coerce), value)]]
932
+ });
933
+ });
934
+ }
935
+ function filePart(bytes, name, contentType) {
936
+ return new globalThis.File([new Uint8Array(bytes)], name, { type: contentType });
937
+ }
938
+ function form2(payload) {
939
+ return map2(payload, (value, name) => map3(ensure(value), (item) => {
940
+ if (item === undefined)
941
+ return;
942
+ if (!is(File2)(item))
943
+ return coerce(item);
944
+ return filePart(item.contentBase64, item.filename ?? name, item.contentType ?? "application/octet-stream");
945
+ }));
946
+ }
947
+ function fileFailed(error) {
948
+ return ActionHandlerError.make({
949
+ cause: error,
950
+ message: error.message
951
+ });
952
+ }
953
+ function readFile(file) {
954
+ return pipe(read(file), mapError(fileFailed));
955
+ }
956
+ var withFile = fnUntraced(function* (request, file) {
957
+ return bodyUint8Array(request, yield* readFile(file), file.contentType);
958
+ });
959
+ var withForm = fnUntraced(function* (request, payload) {
960
+ return bodyFormDataRecord(request, fromEntries(yield* forEach(toEntries(payload), (field) => map4(forEach(filter2(ensure(field[1]), (item) => item !== undefined), (item) => gen(function* () {
961
+ if (!is(File3)(item))
962
+ return coerce(item);
963
+ return filePart(yield* readFile(item), item.name, item.contentType);
964
+ })), (parts) => [field[0], parts]))));
965
+ });
966
+ function mediaBytes(media) {
967
+ if (is(File3)(media))
968
+ return map4(readFile(media), (bytes) => ({
969
+ bytes,
970
+ contentType: media.contentType
971
+ }));
972
+ return succeed4({
973
+ bytes: media.contentBase64,
974
+ contentType: getOrNull(fromNullishOr(media.contentType))
975
+ });
976
+ }
977
+ function isSafeUrl(value, origin) {
978
+ if (!URL.canParse(value))
979
+ return false;
980
+ const url = new URL(value);
981
+ return url.protocol === "https:" && url.username === "" && url.password === "" && (origin === undefined || url.origin === origin);
982
+ }
983
+ function refused(message) {
984
+ return fail5(ActionHandlerError.make({ message }));
985
+ }
986
+ function continuation2(request, nextLink) {
987
+ if (nextLink === undefined)
988
+ return succeed4(request);
989
+ const declared = new URL(request.url);
990
+ const next = URL.canParse(nextLink) ? new URL(nextLink) : undefined;
991
+ if (next === undefined || !isSafeUrl(nextLink) || next.pathname !== declared.pathname)
992
+ return refused("A continuation URL must be an HTTPS link to the same operation path");
993
+ return succeed4(makeWith(request.method, `${declared.origin}${next.pathname}${next.search}`, empty3, none(), request.headers, empty5));
994
+ }
995
+ function preauthenticated2(method, url, ...steps) {
996
+ if (!isSafeUrl(url))
997
+ return refused("An upload session requires a preauthenticated HTTPS URL");
998
+ return succeed4(reduce(steps, method(url), (request, step) => step(request)));
999
+ }
1000
+ function failure(error) {
1001
+ return is(ActionHandlerError)(error) ? error : fromHttpClientFailure(error);
1002
+ }
1003
+ function redirect(response) {
1004
+ const location = response.headers["location"];
1005
+ if (response.status < 300 || response.status >= 400 || location === undefined)
1006
+ return;
1007
+ const sent = response.request;
1008
+ const url = new URL(location, sent.url);
1009
+ const request = response.status === 303 && sent.method !== "GET" && sent.method !== "HEAD" || (response.status === 301 || response.status === 302) && sent.method === "POST" ? setBody(setMethod(sent, "GET"), empty5) : sent;
1010
+ return url.origin === new URL(sent.url).origin ? setUrl(request, url) : setUrl(makeWith(request.method, "", empty3, none(), empty2, request.body), url);
1011
+ }
1012
+ function follow(client, response, redirects) {
1013
+ const next = redirect(response);
1014
+ return next === undefined || redirects === 10 ? succeed4(response) : flatMap3(client.execute(next), (result) => follow(client, result, redirects + 1));
1015
+ }
1016
+ function dispositionName(header) {
1017
+ if (header === undefined)
1018
+ return;
1019
+ const encoded = pipe(match4(/(?:^|;)\s*filename\*\s*=\s*UTF-8'[^']*'([^;]+)/iu)(header), flatMap((match5) => fromUndefinedOr(match5[1])));
1020
+ const decoded = pipe(encoded, flatMap((value) => liftThrowable(() => decodeURIComponent(trim(value)))()));
1021
+ return getOrElse(decoded, () => pipe(match4(/(?:^|;)\s*filename\s*=\s*(?:"((?:\\.|[^"\\])*)"|([^;]*))/iu)(header), flatMap((match5) => orElse(map(fromUndefinedOr(match5[1]), (name) => replace(/\\(.)/gu, "$1")(name)), () => map(fromUndefinedOr(match5[2]), trim))), getOrUndefined));
1022
+ }
1023
+ var read2 = fnUntraced(function* (response, body) {
1024
+ if (body === "json")
1025
+ return yield* response.json;
1026
+ if (body === "text")
1027
+ return yield* response.text;
1028
+ if (body === "void")
1029
+ return {};
1030
+ if (body === "unknown") {
1031
+ const text = yield* response.text;
1032
+ if (isEmpty(trim(text)))
1033
+ return null;
1034
+ return getOrElse(decodeOption(fromJsonString(Json))(text), () => text);
1035
+ }
1036
+ const bytes = new Uint8Array(yield* response.arrayBuffer);
1037
+ const name = dispositionName(response.headers["content-disposition"]);
1038
+ if (body === "file")
1039
+ return yield* pipe(write({
1040
+ bytes,
1041
+ contentType: getOrNull(fromUndefinedOr(response.headers["content-type"])),
1042
+ name: name ?? "file"
1043
+ }), mapError(fileFailed));
1044
+ return toolFile(bytes, response.headers["content-type"] ?? null, name ?? null);
1045
+ });
1046
+ function make2(auth) {
1047
+ const { authorize, checkResponse = () => void_2 } = auth;
1048
+ const send = fnUntraced(function* (context, request) {
1049
+ const base = yield* HttpClient;
1050
+ const uploadPolicy = context === undefined ? auth.preauthenticatedUploadUrl : undefined;
1051
+ const client = uploadPolicy === undefined ? base : mapRequestEffect(base, (outgoing) => isSafeUrl(outgoing.url) && is(uploadPolicy)(outgoing.url) ? succeed4(outgoing) : fail5(new HttpClientError({ reason: new InvalidUrlError({
1052
+ description: "The upload URL is not an approved provider HTTPS destination",
1053
+ request: outgoing
1054
+ }) })));
1055
+ const transport = transformResponse(client, flatMap3((response) => follow(client, response, 0)));
1056
+ const execution = (context === undefined ? transport : authorize(transport, context)).execute(isEffect(request) ? yield* request : request);
1057
+ const options = yield* serviceOption(RequestInit);
1058
+ const response = yield* match(uploadPolicy !== undefined, {
1059
+ onFalse: () => execution,
1060
+ onTrue: () => provideService(execution, RequestInit, {
1061
+ ...getOrElse(options, () => ({})),
1062
+ redirect: "manual"
1063
+ })
1064
+ });
1065
+ if (response.status < 200 || response.status >= 300)
1066
+ return yield* fail5({
1067
+ cause: yield* response.text,
1068
+ response
1069
+ });
1070
+ yield* checkResponse(response);
1071
+ return response;
1072
+ });
1073
+ function endpoint(contract, run) {
1074
+ if (!isSchema(contract.output)) {
1075
+ const wire = contract.output.wire;
1076
+ return {
1077
+ input: contract.input,
1078
+ output: toType(wire),
1079
+ run: (input, context) => run(input, context, wire),
1080
+ wire
1081
+ };
1082
+ }
1083
+ const output = contract.output;
1084
+ return {
1085
+ input: contract.input,
1086
+ output,
1087
+ run: (input, context) => run(input, context, output)
1088
+ };
1089
+ }
1090
+ function execute(context, output, request, body) {
1091
+ return pipe(send(context, request), flatMap3((response) => read2(response, body)), flatMap3(decodeResponse(output)), mapError(failure));
1092
+ }
1093
+ const variants = fnUntraced(function* (context, output, request, declared, media) {
1094
+ const response = yield* send(context, request);
1095
+ const exact = flatMap2(declared, (variant) => variant.status === undefined ? [] : [variant.status]);
1096
+ const contentType = pipe(response.headers["content-type"] ?? "", split(";"), headNonEmpty, trim, toLowerCase);
1097
+ const ordered = sort(declared, mapInput(Number2, (variant) => {
1098
+ if (variant.body === "void" || variant.body === "unknown")
1099
+ return 3;
1100
+ if (variant.contentType === "*/*")
1101
+ return 2;
1102
+ return pipe(variant.contentType, endsWith("/*")) ? 1 : 0;
1103
+ }));
1104
+ const variant = findFirst(ordered, (candidate) => {
1105
+ if (!(candidate.status === undefined ? !contains2(exact, response.status) : candidate.status === response.status))
1106
+ return false;
1107
+ if (media !== undefined)
1108
+ return (candidate.body === "binary" || candidate.body === "file") === media;
1109
+ if (candidate.body === "void" || candidate.body === "unknown" || candidate.contentType === "*/*")
1110
+ return true;
1111
+ if (pipe(candidate.contentType, endsWith("/*")))
1112
+ return pipe(contentType, startsWith(pipe(candidate.contentType, slice(0, -1))));
1113
+ return contentType === candidate.contentType;
1114
+ });
1115
+ if (isNone(variant))
1116
+ return yield* fail5({
1117
+ cause: "The API returned an undeclared successful response",
1118
+ response
1119
+ });
1120
+ const headers = flatMap2(variant.value.headers ?? [], (name) => {
1121
+ const value = response.headers[toLowerCase(name)];
1122
+ return value === undefined ? [] : [[name, value]];
1123
+ });
1124
+ return yield* decodeResponse(output)({
1125
+ body: yield* read2(response, variant.value.body),
1126
+ contentType: variant.value.contentType,
1127
+ status: response.status,
1128
+ ...variant.value.headers === undefined ? {} : { headers: fromEntries(headers) }
1129
+ });
1130
+ }, mapError(failure));
1131
+ return {
1132
+ endpoint,
1133
+ execute,
1134
+ googleUpload: fnUntraced(function* (context, output, request, payload, options) {
1135
+ const client = authorize(yield* HttpClient, context);
1136
+ const media = "media" in payload ? yield* mediaBytes(payload.media) : undefined;
1137
+ const size = "totalBytes" in payload ? payload.totalBytes : media?.bytes.byteLength ?? 0;
1138
+ if (size < 0 || options.maxSize !== undefined && size > options.maxSize)
1139
+ return yield* refused("The upload size is outside the API's declared limit");
1140
+ const origin = new URL(request.url).origin;
1141
+ if (payload.mode === "start") {
1142
+ if (options.resumable === undefined)
1143
+ return yield* refused("This API has no resumable upload protocol");
1144
+ const response = yield* client.execute(pipe(setUrl(request, options.resumable), setUrlParam("uploadType", "resumable"), setHeaders({
1145
+ "x-upload-content-length": `${size}`,
1146
+ "x-upload-content-type": payload.contentType
1147
+ }), bodyJsonUnsafe(payload.metadata ?? {})));
1148
+ if (response.status < 200 || response.status >= 300)
1149
+ return yield* fail5({
1150
+ cause: yield* response.text,
1151
+ response
1152
+ });
1153
+ const sessionUrl = response.headers["location"];
1154
+ if (sessionUrl === undefined || !isSafeUrl(sessionUrl, origin))
1155
+ return yield* fail5({
1156
+ cause: "The API returned an invalid upload session URL",
1157
+ response
1158
+ });
1159
+ return yield* decodeResponse(output)({
1160
+ nextOffset: 0,
1161
+ sessionUrl,
1162
+ state: "pending"
1163
+ });
1164
+ }
1165
+ if (payload.mode === "chunk" || payload.mode === "status") {
1166
+ if (!isSafeUrl(payload.sessionUrl, origin))
1167
+ return yield* refused("The upload session URL must use the API's HTTPS origin");
1168
+ const bytes = media?.bytes ?? /* @__PURE__ */ new Uint8Array;
1169
+ const end = payload.mode === "chunk" ? payload.offset + bytes.byteLength : 0;
1170
+ if (payload.mode === "chunk" && (payload.offset < 0 || bytes.byteLength === 0 || end > size || end < size && bytes.byteLength % 262144 !== 0))
1171
+ return yield* refused("Upload chunks must fit the total size and use 256 KiB multiples except for the final chunk");
1172
+ const response = yield* client.execute(pipe(put(payload.sessionUrl), bodyUint8Array(bytes, media?.contentType ?? "application/octet-stream"), setHeader("content-range", payload.mode === "status" ? `bytes */${size}` : `bytes ${payload.offset}-${end - 1}/${size}`)));
1173
+ if (response.status === 308) {
1174
+ const range = response.headers["range"];
1175
+ if (range !== undefined && !/^bytes=0-\d+$/u.test(range))
1176
+ return yield* fail5({
1177
+ cause: "The API returned an invalid upload range",
1178
+ response
1179
+ });
1180
+ const nextOffset = range === undefined ? 0 : Number(pipe(range, slice(8))) + 1;
1181
+ if (nextOffset > size)
1182
+ return yield* fail5({
1183
+ cause: "The API returned an upload offset beyond the total size",
1184
+ response
1185
+ });
1186
+ return yield* decodeResponse(output)({
1187
+ nextOffset,
1188
+ sessionUrl: payload.sessionUrl,
1189
+ state: "pending"
1190
+ });
1191
+ }
1192
+ if (response.status < 200 || response.status >= 300)
1193
+ return yield* fail5({
1194
+ cause: yield* response.text,
1195
+ response
1196
+ });
1197
+ return yield* decodeResponse(output)({
1198
+ resource: yield* response.json,
1199
+ state: "complete"
1200
+ });
1201
+ }
1202
+ const selected = setUrlParam(request, "uploadType", payload.mode);
1203
+ const bytes = media?.bytes ?? /* @__PURE__ */ new Uint8Array;
1204
+ const contentType = media?.contentType ?? "application/octet-stream";
1205
+ const boundary = `dual-${yield* nextInt}-${yield* nextInt}`;
1206
+ const metadata = payload.mode === "multipart" ? yield* encodeEffect(fromJsonString(Unknown))(payload.metadata) : "";
1207
+ const body = payload.mode === "media" ? bodyUint8Array(selected, bytes, contentType) : bodyUint8Array(selected, new Uint8Array(yield* promise(() => new Blob([
1208
+ `--${boundary}\r
1209
+ Content-Type: application/json; charset=UTF-8\r
1210
+ \r
1211
+ ${metadata}\r
1212
+ --${boundary}\r
1213
+ Content-Type: ${contentType}\r
1214
+ \r
1215
+ `,
1216
+ new Uint8Array(bytes),
1217
+ `\r
1218
+ --${boundary}--\r
1219
+ `
1220
+ ]).arrayBuffer())), `multipart/related; boundary=${boundary}`);
1221
+ const response = yield* client.execute(body);
1222
+ if (response.status < 200 || response.status >= 300)
1223
+ return yield* fail5({
1224
+ cause: yield* response.text,
1225
+ response
1226
+ });
1227
+ return yield* decodeResponse(output)({
1228
+ resource: yield* response.json,
1229
+ state: "complete"
1230
+ });
1231
+ }, mapError(failure)),
1232
+ graphql: fnUntraced(function* (context, output, request, field) {
1233
+ const response = yield* send(context, request);
1234
+ const body = yield* decodeUnknownEffect(GraphqlResponse)(yield* response.json);
1235
+ if (body.errors !== undefined && isReadonlyArrayNonEmpty(body.errors))
1236
+ return yield* ActionHandlerError.make({
1237
+ details: body.errors,
1238
+ message: join(map3(body.errors, (error) => error.message), "; ")
1239
+ });
1240
+ return yield* decodeResponse(output)(body.data?.[field]);
1241
+ }, mapError(failure)),
1242
+ mcp: fnUntraced(function* (context, output, server, tool, args, structured) {
1243
+ const connection = yield* connect(authorize(yield* HttpClient, context), server, {});
1244
+ const result = yield* decodeUnknownEffect(CallToolResult)(yield* connection.request("tools/call", {
1245
+ arguments: args,
1246
+ name: tool
1247
+ }));
1248
+ if (result.isError === true)
1249
+ return yield* ActionHandlerError.make({
1250
+ details: result.content,
1251
+ message: join(flatMap2(result.content, (block) => fromNullishOr2(block.text)), `
1252
+ `)
1253
+ });
1254
+ return yield* decodeResponse(output)(match(structured, {
1255
+ onFalse: () => ({ content: result.content }),
1256
+ onTrue: () => result.structuredContent
1257
+ }));
1258
+ }, scoped, mapError((error) => is(McpError)(error) ? ActionHandlerError.make({ message: error.message }) : failure(error))),
1259
+ variants
1260
+ };
1261
+ }
1262
+
1263
+ // dist/auth.js
1264
+ var auth_exports2 = /* @__PURE__ */ __exportAll2({
1265
+ Auth: () => auth_exports2,
1266
+ authMethods: () => authMethods2,
1267
+ authorize: () => authorize2
1268
+ });
1269
+ var authMethods2 = [AuthMethod_exports.make("api-token", {
1270
+ description: "Authenticate with a Notion internal integration token sent as a bearer token",
1271
+ name: "Notion internal integration token",
1272
+ schema: Struct({ token: NonEmptyString })
1273
+ }), AuthMethod_exports.oauth2("oauth2", {
1274
+ authorizationParams: { owner: "user" },
1275
+ authorizationUrl: "https://api.notion.com/v1/oauth/authorize",
1276
+ client: (options) => ({
1277
+ authentication: "basic",
1278
+ clientId: options.setup.clientId,
1279
+ clientSecret: options.setup.clientSecret
1280
+ }),
1281
+ description: "Authenticate with Notion through a public integration using OAuth2",
1282
+ material: AuthMethod_exports.OAuth2TokenMaterial,
1283
+ name: "Notion OAuth2",
1284
+ pkce: false,
1285
+ scopes: [],
1286
+ setup: Struct({
1287
+ clientId: String3,
1288
+ clientSecret: String3
1289
+ }),
1290
+ tokenHeaders: { "Notion-Version": "2026-03-11" },
1291
+ tokenRequestEncoding: "json",
1292
+ tokenUrl: "https://api.notion.com/v1/oauth/token"
1293
+ })];
1294
+ function authorize2(client, context) {
1295
+ return pipe(value2(context.auth.current), discriminatorsExhaustive("methodId")({
1296
+ "api-token": (binding) => mapRequest(client, bearerToken(binding.value.token)),
1297
+ oauth2: (binding) => mapRequest(client, bearerToken(binding.value.accessToken))
1298
+ }), mapRequest(setHeader("Notion-Version", "2026-03-11")));
1299
+ }
1300
+ export { match, Http_exports, File2, FileFromBase642, FileFromBase64Url2, Base64FromFile2, Base64UrlFromFile2, FileFromDataUri2, DataUriFromFile2, DateTimeFromUnixSeconds2, UnixSecondsFromDateTime2, DateTimeFromRfc28222, Rfc2822FromDateTime2, decoded2, path2, literal2, segments2, params2, form2, continuation2, preauthenticated2, auth_exports2, authMethods2, authorize2 };
1301
+
1302
+ //# debugId=A074507D9F5318F264756E2164756E21
1303
+ //# sourceMappingURL=plugin-529jjg5q.js.map