apps 0.0.1-beta.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/README.md +191 -0
- package/check-publish.mjs +10 -0
- package/framework-reference.json +1 -0
- package/js/chunk-22WRQZT7.js +389 -0
- package/js/chunk-2OTCEKL2.js +29480 -0
- package/js/chunk-36DNRFZQ.js +34 -0
- package/js/chunk-3ANFZFCV.js +1799 -0
- package/js/chunk-7JXHF5IF.js +138 -0
- package/js/chunk-BCSNKUAC.js +0 -0
- package/js/chunk-BKVL7XAJ.js +47 -0
- package/js/chunk-BPEFS4YF.js +1323 -0
- package/js/chunk-C24KEZXR.js +59 -0
- package/js/chunk-D6BKYP2L.js +877 -0
- package/js/chunk-EP6AEUZO.js +19 -0
- package/js/chunk-HP7E42X6.js +1719 -0
- package/js/chunk-KWTCHVLT.js +284 -0
- package/js/chunk-LOKGDT6B.js +28 -0
- package/js/chunk-MLKGABMK.js +9 -0
- package/js/chunk-OWD2YICM.js +2486 -0
- package/js/chunk-Q2FD5IBM.js +899 -0
- package/js/chunk-R6JMJSVT.js +590 -0
- package/js/chunk-SBKHUC5L.js +56 -0
- package/js/chunk-VFUZI3NY.js +75 -0
- package/js/chunk-W7Q5EOTS.js +4375 -0
- package/js/chunk-WIDTG42X.js +171 -0
- package/js/chunk-X3YBZCJW.js +246 -0
- package/js/chunk-YDR4CPJA.js +2357 -0
- package/js/client.js +1023 -0
- package/js/contracts.js +163 -0
- package/js/effect.js +44 -0
- package/js/graphql.js +392 -0
- package/js/host.js +193 -0
- package/js/index.js +284 -0
- package/js/mcp/effect.js +23 -0
- package/js/mcp/stdio.js +123 -0
- package/js/mcp.js +37 -0
- package/js/openapi.js +246 -0
- package/js/operations/approval.js +9 -0
- package/js/react.js +37 -0
- package/js/storage/facet.js +546 -0
- package/js/ui/auth/contracts.js +19 -0
- package/js/ui/auth.js +28 -0
- package/js/ui/contracts.js +24 -0
- package/js/ui/serving.js +286 -0
- package/package.json +116 -0
- package/runtime.json +1 -0
- package/types/app-data/src/contracts/database.d.ts +193 -0
- package/types/app-data/src/implementation/cursor.d.ts +10 -0
- package/types/app-data/src/implementation/index-key.d.ts +7 -0
- package/types/app-data/src/implementation/promise.d.ts +68 -0
- package/types/app-data/src/implementation/range.d.ts +8 -0
- package/types/app-data/src/implementation/schema.d.ts +33 -0
- package/types/app-data/src/implementation/sqlite.d.ts +11 -0
- package/types/app-data/src/index.d.ts +4 -0
- package/types/apps/src/approval.d.ts +10 -0
- package/types/apps/src/client.d.ts +5 -0
- package/types/apps/src/contracts/app.d.ts +58 -0
- package/types/apps/src/contracts/approval.d.ts +14 -0
- package/types/apps/src/contracts/context.d.ts +25 -0
- package/types/apps/src/contracts/elicitation.d.ts +86 -0
- package/types/apps/src/contracts/graphql.d.ts +102 -0
- package/types/apps/src/contracts/host.d.ts +568 -0
- package/types/apps/src/contracts/http.d.ts +20 -0
- package/types/apps/src/contracts/live.d.ts +26 -0
- package/types/apps/src/contracts/mcp.d.ts +93 -0
- package/types/apps/src/contracts/openapi.d.ts +105 -0
- package/types/apps/src/contracts/operations.d.ts +30 -0
- package/types/apps/src/contracts/optimistic.d.ts +22 -0
- package/types/apps/src/contracts/provider.d.ts +96 -0
- package/types/apps/src/contracts/schedules.d.ts +51 -0
- package/types/apps/src/contracts/schema.d.ts +20 -0
- package/types/apps/src/contracts/storage.d.ts +68 -0
- package/types/apps/src/contracts/tools.d.ts +11 -0
- package/types/apps/src/contracts/ui-auth.d.ts +28 -0
- package/types/apps/src/contracts/ui.d.ts +90 -0
- package/types/apps/src/contracts/webhook-protocol.d.ts +102 -0
- package/types/apps/src/contracts/webhooks.d.ts +53 -0
- package/types/apps/src/contracts/workflows.d.ts +277 -0
- package/types/apps/src/effect.d.ts +10 -0
- package/types/apps/src/facet.d.ts +5 -0
- package/types/apps/src/graphql.d.ts +10 -0
- package/types/apps/src/host.d.ts +16 -0
- package/types/apps/src/implementation/account-operations.d.ts +32 -0
- package/types/apps/src/implementation/app.d.ts +40 -0
- package/types/apps/src/implementation/authoring.d.ts +12 -0
- package/types/apps/src/implementation/elicitation.d.ts +103 -0
- package/types/apps/src/implementation/graphql.d.ts +5 -0
- package/types/apps/src/implementation/host.d.ts +3 -0
- package/types/apps/src/implementation/http.d.ts +5 -0
- package/types/apps/src/implementation/live.d.ts +18 -0
- package/types/apps/src/implementation/mcp-call.d.ts +19 -0
- package/types/apps/src/implementation/mcp-client.d.ts +50 -0
- package/types/apps/src/implementation/mcp-stdio.d.ts +4 -0
- package/types/apps/src/implementation/mcp-tools.d.ts +6 -0
- package/types/apps/src/implementation/mcp.d.ts +4 -0
- package/types/apps/src/implementation/openapi-request.d.ts +11 -0
- package/types/apps/src/implementation/openapi.d.ts +5 -0
- package/types/apps/src/implementation/operations.d.ts +65 -0
- package/types/apps/src/implementation/optimistic.d.ts +30 -0
- package/types/apps/src/implementation/protocol-operations.d.ts +24 -0
- package/types/apps/src/implementation/provider.d.ts +16 -0
- package/types/apps/src/implementation/query-commit.d.ts +10 -0
- package/types/apps/src/implementation/schedules.d.ts +16 -0
- package/types/apps/src/implementation/schema.d.ts +93 -0
- package/types/apps/src/implementation/storage.d.ts +13 -0
- package/types/apps/src/implementation/ui-auth.d.ts +13 -0
- package/types/apps/src/implementation/ui-client.d.ts +16 -0
- package/types/apps/src/implementation/ui-errors.d.ts +2 -0
- package/types/apps/src/implementation/ui-serving.d.ts +16 -0
- package/types/apps/src/implementation/ui-watch.d.ts +2 -0
- package/types/apps/src/implementation/webhooks.d.ts +29 -0
- package/types/apps/src/implementation/workflow-context.d.ts +8 -0
- package/types/apps/src/implementation/workflow-rpc.d.ts +5 -0
- package/types/apps/src/implementation/workflows.d.ts +27 -0
- package/types/apps/src/index.d.ts +58 -0
- package/types/apps/src/mcp-stdio.d.ts +8 -0
- package/types/apps/src/mcp.d.ts +10 -0
- package/types/apps/src/openapi.d.ts +10 -0
- package/types/apps/src/react.d.ts +7 -0
- package/types/apps/src/ui-auth.d.ts +3 -0
- package/types/apps/src/ui-serving.d.ts +3 -0
- package/types/telemetry/src/browser-operations.d.ts +16 -0
- package/types/telemetry/src/browser-performance.d.ts +11 -0
- package/types/telemetry/src/browser-request-timing.d.ts +2 -0
- package/types/telemetry/src/browser.d.ts +27 -0
- package/types/telemetry/src/config.d.ts +83 -0
- package/types/telemetry/src/context.d.ts +14 -0
- package/types/telemetry/src/index.d.ts +9 -0
- package/types/telemetry/src/layer.d.ts +7 -0
- package/types/telemetry/src/measurements.d.ts +8 -0
- package/types/telemetry/src/pending-span.d.ts +7 -0
- package/types/telemetry/src/relay.d.ts +28 -0
- package/types/telemetry/src/span-attributes.d.ts +29 -0
- package/types/telemetry/src/trace-context.d.ts +20 -0
- package/types/telemetry/src/transport.d.ts +6 -0
package/js/host.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAppHandler
|
|
3
|
+
} from "./chunk-Q2FD5IBM.js";
|
|
4
|
+
import "./chunk-X3YBZCJW.js";
|
|
5
|
+
import "./chunk-R6JMJSVT.js";
|
|
6
|
+
import "./chunk-C24KEZXR.js";
|
|
7
|
+
import {
|
|
8
|
+
HostAccountsInvalid,
|
|
9
|
+
HostInputInvalid,
|
|
10
|
+
HostResponse,
|
|
11
|
+
ResolvedAccounts,
|
|
12
|
+
TrustedToolApproval
|
|
13
|
+
} from "./chunk-22WRQZT7.js";
|
|
14
|
+
import {
|
|
15
|
+
ElicitationFailed,
|
|
16
|
+
ElicitationReply,
|
|
17
|
+
WorkflowFailure,
|
|
18
|
+
WorkflowRpcResult,
|
|
19
|
+
WorkflowRun,
|
|
20
|
+
WorkflowRunId,
|
|
21
|
+
WorkflowRunPage
|
|
22
|
+
} from "./chunk-HP7E42X6.js";
|
|
23
|
+
import "./chunk-7JXHF5IF.js";
|
|
24
|
+
import {
|
|
25
|
+
collectTelemetry,
|
|
26
|
+
withRemoteSpan
|
|
27
|
+
} from "./chunk-OWD2YICM.js";
|
|
28
|
+
import "./chunk-VFUZI3NY.js";
|
|
29
|
+
import "./chunk-W7Q5EOTS.js";
|
|
30
|
+
import "./chunk-BPEFS4YF.js";
|
|
31
|
+
import "./chunk-EP6AEUZO.js";
|
|
32
|
+
import "./chunk-36DNRFZQ.js";
|
|
33
|
+
import {
|
|
34
|
+
Cause_exports,
|
|
35
|
+
Effect_exports,
|
|
36
|
+
Redacted_exports,
|
|
37
|
+
Scheduler_exports,
|
|
38
|
+
Schema_exports
|
|
39
|
+
} from "./chunk-2OTCEKL2.js";
|
|
40
|
+
import "./chunk-MLKGABMK.js";
|
|
41
|
+
|
|
42
|
+
// src/implementation/workflow-rpc.ts
|
|
43
|
+
var isolatedWorkflowExecution = (run, deliver, signal) => {
|
|
44
|
+
const runId = Schema_exports.decodeUnknownSync(WorkflowRunId)(run);
|
|
45
|
+
const request = (input, callback) => Effect_exports.tryPromise({
|
|
46
|
+
try: () => deliver(input, callback),
|
|
47
|
+
catch: () => new WorkflowFailure({ reason: "engine", retryable: true })
|
|
48
|
+
}).pipe(
|
|
49
|
+
Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(WorkflowRpcResult)),
|
|
50
|
+
Effect_exports.mapError(() => new WorkflowFailure({ reason: "engine", retryable: true })),
|
|
51
|
+
Effect_exports.flatMap(
|
|
52
|
+
(reply) => reply.ok ? Effect_exports.succeed(reply.value) : Effect_exports.fail(reply.error)
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
return {
|
|
56
|
+
runId,
|
|
57
|
+
driver: {
|
|
58
|
+
do: (name, options, work) => Effect_exports.gen(function* () {
|
|
59
|
+
const services = yield* Effect_exports.context();
|
|
60
|
+
return yield* request(
|
|
61
|
+
{ operation: "do", name, options },
|
|
62
|
+
() => Effect_exports.runPromiseWith(services)(
|
|
63
|
+
work().pipe(
|
|
64
|
+
Effect_exports.matchCause({
|
|
65
|
+
onSuccess: (value) => ({ ok: true, value }),
|
|
66
|
+
onFailure: (cause) => {
|
|
67
|
+
const error = Cause_exports.squash(cause);
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
error: Schema_exports.is(WorkflowFailure)(error) ? error : new WorkflowFailure({ reason: "execution", retryable: true })
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}),
|
|
74
|
+
Effect_exports.flatMap(Schema_exports.encodeEffect(WorkflowRpcResult))
|
|
75
|
+
),
|
|
76
|
+
{ signal }
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
}),
|
|
80
|
+
sleep: (name, duration) => request({ operation: "sleep", name, duration }).pipe(Effect_exports.asVoid),
|
|
81
|
+
sleepUntil: (name, timestamp) => request({ operation: "until", name, timestamp }).pipe(Effect_exports.asVoid)
|
|
82
|
+
},
|
|
83
|
+
resolve: () => request({ operation: "context" }).pipe(
|
|
84
|
+
Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(ResolvedAccounts)),
|
|
85
|
+
Effect_exports.map((accounts) => ({ accounts: Redacted_exports.make(accounts) })),
|
|
86
|
+
Effect_exports.mapError(
|
|
87
|
+
(error) => Schema_exports.is(WorkflowFailure)(error) ? error : new WorkflowFailure({ reason: "credentials", retryable: false })
|
|
88
|
+
)
|
|
89
|
+
),
|
|
90
|
+
invoke: (input) => request({ operation: "invoke", ...input })
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
var isolatedWorkflowControls = (deliver) => {
|
|
94
|
+
const request = (input) => Effect_exports.tryPromise({
|
|
95
|
+
try: () => deliver(input),
|
|
96
|
+
catch: () => new WorkflowFailure({ reason: "engine", retryable: true })
|
|
97
|
+
}).pipe(
|
|
98
|
+
Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(WorkflowRpcResult)),
|
|
99
|
+
Effect_exports.mapError(() => new WorkflowFailure({ reason: "engine", retryable: true })),
|
|
100
|
+
Effect_exports.flatMap(
|
|
101
|
+
(result) => result.ok ? Effect_exports.succeed(result.value) : Effect_exports.fail(result.error)
|
|
102
|
+
)
|
|
103
|
+
);
|
|
104
|
+
const run = (input) => request(input).pipe(
|
|
105
|
+
Effect_exports.flatMap(
|
|
106
|
+
(value) => Schema_exports.decodeUnknownEffect(WorkflowRun)(value).pipe(
|
|
107
|
+
Effect_exports.mapError(() => new WorkflowFailure({ reason: "engine", retryable: true }))
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
return {
|
|
112
|
+
start: (input) => run({ operation: "start", ...input }),
|
|
113
|
+
get: (input) => run({ operation: "get", ...input }),
|
|
114
|
+
terminate: (input) => run({ operation: "terminate", ...input }),
|
|
115
|
+
list: (input) => request({ operation: "list", ...input }).pipe(
|
|
116
|
+
Effect_exports.flatMap(
|
|
117
|
+
(value) => Schema_exports.decodeUnknownEffect(WorkflowRunPage)(value).pipe(
|
|
118
|
+
Effect_exports.mapError(() => new WorkflowFailure({ reason: "engine", retryable: true }))
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/host.ts
|
|
126
|
+
var hostContext = (accounts, approval) => ({
|
|
127
|
+
...approval === void 0 ? {} : {
|
|
128
|
+
approval: Effect_exports.runSync(
|
|
129
|
+
Schema_exports.decodeUnknownEffect(TrustedToolApproval)(approval).pipe(
|
|
130
|
+
Effect_exports.mapError(() => new HostInputInvalid())
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
},
|
|
134
|
+
accounts: Effect_exports.runSync(
|
|
135
|
+
Schema_exports.decodeUnknownEffect(Schema_exports.RedactedFromValue(ResolvedAccounts))(accounts).pipe(
|
|
136
|
+
Effect_exports.mapError(() => new HostAccountsInvalid())
|
|
137
|
+
)
|
|
138
|
+
)
|
|
139
|
+
});
|
|
140
|
+
var createAppHandler2 = (app) => {
|
|
141
|
+
const handler = createAppHandler(app);
|
|
142
|
+
return (request, context) => {
|
|
143
|
+
const operation = handler(request, context).pipe(withRemoteSpan(request, "app.dispatch"));
|
|
144
|
+
return Effect_exports.runPromise(
|
|
145
|
+
context.telemetry === void 0 ? operation : operation.pipe(Effect_exports.provideContext(context.telemetry.context)),
|
|
146
|
+
{ signal: request.signal }
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
var createIsolatedAppHandler = (app) => {
|
|
151
|
+
const handler = createAppHandler(app);
|
|
152
|
+
return (request, context) => Effect_exports.runPromise(
|
|
153
|
+
Effect_exports.gen(function* () {
|
|
154
|
+
const { value, telemetry } = yield* collectTelemetry(
|
|
155
|
+
handler(request, context).pipe(withRemoteSpan(request, "app.dispatch"))
|
|
156
|
+
);
|
|
157
|
+
const body = yield* Effect_exports.promise(() => value.json()).pipe(
|
|
158
|
+
Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(HostResponse))
|
|
159
|
+
);
|
|
160
|
+
return Response.json({ ...body, telemetry }, { status: value.status });
|
|
161
|
+
}),
|
|
162
|
+
{
|
|
163
|
+
signal: request.signal,
|
|
164
|
+
// workerd delivers timers in order. A scheduler timer outside a transaction
|
|
165
|
+
// can block timers inside its closed input gate; microtasks avoid that queue.
|
|
166
|
+
scheduler: new Scheduler_exports.MixedScheduler("sync")
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
};
|
|
170
|
+
var isolatedElicitation = (deliver, lifetime) => (request) => Effect_exports.tryPromise({
|
|
171
|
+
try: () => deliver(request),
|
|
172
|
+
catch: () => {
|
|
173
|
+
lifetime.abort();
|
|
174
|
+
return new ElicitationFailed({ reason: "transport" });
|
|
175
|
+
}
|
|
176
|
+
}).pipe(
|
|
177
|
+
Effect_exports.flatMap(
|
|
178
|
+
(reply) => Schema_exports.decodeUnknownEffect(ElicitationReply)(reply).pipe(
|
|
179
|
+
Effect_exports.mapError(() => new ElicitationFailed({ reason: "transport" }))
|
|
180
|
+
)
|
|
181
|
+
),
|
|
182
|
+
Effect_exports.flatMap(
|
|
183
|
+
(reply) => reply.ok ? Effect_exports.succeed(reply.response) : Effect_exports.fail(reply.error)
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
export {
|
|
187
|
+
createAppHandler2 as createAppHandler,
|
|
188
|
+
createIsolatedAppHandler,
|
|
189
|
+
hostContext,
|
|
190
|
+
isolatedElicitation,
|
|
191
|
+
isolatedWorkflowControls,
|
|
192
|
+
isolatedWorkflowExecution
|
|
193
|
+
};
|
package/js/index.js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineApp,
|
|
3
|
+
defineDatabase,
|
|
4
|
+
table,
|
|
5
|
+
workflow
|
|
6
|
+
} from "./chunk-X3YBZCJW.js";
|
|
7
|
+
import "./chunk-R6JMJSVT.js";
|
|
8
|
+
import {
|
|
9
|
+
mutation,
|
|
10
|
+
nativeOperation,
|
|
11
|
+
operationDeclaration,
|
|
12
|
+
query,
|
|
13
|
+
withApproval
|
|
14
|
+
} from "./chunk-C24KEZXR.js";
|
|
15
|
+
import {
|
|
16
|
+
CalendarSchedule,
|
|
17
|
+
ElicitationFailed,
|
|
18
|
+
Interval,
|
|
19
|
+
NonRetryableError,
|
|
20
|
+
OAuth2AccessToken,
|
|
21
|
+
OAuth2Config,
|
|
22
|
+
OAuth2Method,
|
|
23
|
+
Provider,
|
|
24
|
+
ScheduleTiming,
|
|
25
|
+
SecretsMethod,
|
|
26
|
+
WorkflowFailure
|
|
27
|
+
} from "./chunk-HP7E42X6.js";
|
|
28
|
+
import "./chunk-7JXHF5IF.js";
|
|
29
|
+
import {
|
|
30
|
+
array,
|
|
31
|
+
boolean,
|
|
32
|
+
decoderOf,
|
|
33
|
+
id,
|
|
34
|
+
importedJsonSchema,
|
|
35
|
+
json,
|
|
36
|
+
jsonSchema,
|
|
37
|
+
literal,
|
|
38
|
+
nestJsonSchema,
|
|
39
|
+
number,
|
|
40
|
+
object,
|
|
41
|
+
parse,
|
|
42
|
+
record,
|
|
43
|
+
string,
|
|
44
|
+
userId,
|
|
45
|
+
withJsonSchemaDocument,
|
|
46
|
+
wrap
|
|
47
|
+
} from "./chunk-BPEFS4YF.js";
|
|
48
|
+
import "./chunk-EP6AEUZO.js";
|
|
49
|
+
import {
|
|
50
|
+
JsonObject,
|
|
51
|
+
JsonValue,
|
|
52
|
+
ValidationError
|
|
53
|
+
} from "./chunk-36DNRFZQ.js";
|
|
54
|
+
import {
|
|
55
|
+
Effect_exports,
|
|
56
|
+
Schema_exports
|
|
57
|
+
} from "./chunk-2OTCEKL2.js";
|
|
58
|
+
import "./chunk-MLKGABMK.js";
|
|
59
|
+
|
|
60
|
+
// src/contracts/http.ts
|
|
61
|
+
var ResponseStatusError = class extends Schema_exports.TaggedError()(
|
|
62
|
+
"ResponseStatusError",
|
|
63
|
+
{ status: Schema_exports.Number }
|
|
64
|
+
) {
|
|
65
|
+
get message() {
|
|
66
|
+
return `Request failed with status ${this.status}`;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var ResponseDecodeError = class extends Schema_exports.TaggedError()(
|
|
70
|
+
"ResponseDecodeError",
|
|
71
|
+
{}
|
|
72
|
+
) {
|
|
73
|
+
get message() {
|
|
74
|
+
return "Response body did not match the expected schema";
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/implementation/http.ts
|
|
79
|
+
var decodeJson = (response, schema) => Effect_exports.gen(function* () {
|
|
80
|
+
if (response.status < 200 || response.status >= 300) {
|
|
81
|
+
return yield* Effect_exports.fail(new ResponseStatusError({ status: response.status }));
|
|
82
|
+
}
|
|
83
|
+
const body = yield* response.json();
|
|
84
|
+
return yield* parse(schema, body).pipe(Effect_exports.mapError(() => new ResponseDecodeError()));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// src/implementation/provider.ts
|
|
88
|
+
var secrets = (options) => new SecretsMethod(options);
|
|
89
|
+
var oauth2 = (config, response) => parse(OAuth2Config, config).pipe(Effect_exports.map((config2) => new OAuth2Method({ config: config2, response })));
|
|
90
|
+
var defineProvider = (options) => new Provider(options);
|
|
91
|
+
|
|
92
|
+
// src/implementation/account-operations.ts
|
|
93
|
+
var inputDocument = (operation) => {
|
|
94
|
+
const imported = importedJsonSchema(operation.input);
|
|
95
|
+
if (imported !== void 0) return Schema_exports.decodeUnknownSync(JsonObject)(imported);
|
|
96
|
+
const document = Schema_exports.toJsonSchemaDocument(operation.input);
|
|
97
|
+
return Schema_exports.decodeUnknownSync(JsonObject)({ ...document.schema, $defs: document.definitions });
|
|
98
|
+
};
|
|
99
|
+
var combine = (kind, groups) => Object.fromEntries(
|
|
100
|
+
[...groups].map(([name, accounts]) => {
|
|
101
|
+
const variants = [...accounts.values()];
|
|
102
|
+
const first = variants[0];
|
|
103
|
+
if (first === void 0)
|
|
104
|
+
throw new Error("An account operation must have at least one account");
|
|
105
|
+
const select = (input2) => {
|
|
106
|
+
const operation = accounts.get(input2.accountId);
|
|
107
|
+
if (operation === void 0)
|
|
108
|
+
throw new Error("Account selection must be decoded before execution");
|
|
109
|
+
return operation;
|
|
110
|
+
};
|
|
111
|
+
const outputs = variants.flatMap(
|
|
112
|
+
(operation) => operation.outputSchema === void 0 ? [] : [operation.outputSchema]
|
|
113
|
+
);
|
|
114
|
+
const input = Schema_exports.Union(
|
|
115
|
+
[...accounts].map(
|
|
116
|
+
([accountId, operation]) => Schema_exports.Struct({ accountId: Schema_exports.Literal(accountId), input: operation.input })
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
const inputSchema = {
|
|
120
|
+
type: "object",
|
|
121
|
+
anyOf: [...accounts].map(([accountId, operation], index) => ({
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: {
|
|
124
|
+
accountId: { type: "string", const: accountId },
|
|
125
|
+
input: nestJsonSchema(inputDocument(operation), `#/anyOf/${index}/properties/input`)
|
|
126
|
+
},
|
|
127
|
+
required: ["accountId", "input"]
|
|
128
|
+
}))
|
|
129
|
+
};
|
|
130
|
+
return [
|
|
131
|
+
name,
|
|
132
|
+
operationDeclaration({
|
|
133
|
+
kind,
|
|
134
|
+
...first.description === void 0 ? {} : { description: first.description },
|
|
135
|
+
...first.title === void 0 ? {} : { title: first.title },
|
|
136
|
+
...first.annotations === void 0 || !variants.every(
|
|
137
|
+
(operation) => JSON.stringify(operation.annotations) === JSON.stringify(first.annotations)
|
|
138
|
+
) ? {} : { annotations: first.annotations },
|
|
139
|
+
...first._meta === void 0 || !variants.every(
|
|
140
|
+
(operation) => JSON.stringify(operation._meta) === JSON.stringify(first._meta)
|
|
141
|
+
) ? {} : { _meta: first._meta },
|
|
142
|
+
input: withJsonSchemaDocument(input, inputSchema),
|
|
143
|
+
...outputs.length !== variants.length ? {} : {
|
|
144
|
+
outputSchema: {
|
|
145
|
+
anyOf: outputs.map((output, index) => nestJsonSchema(output, `#/anyOf/${index}`))
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
approval: (context) => {
|
|
149
|
+
const operation = select(context.toolInput);
|
|
150
|
+
return operation.approval === void 0 ? Effect_exports.succeed("approved") : operation.approval({ ...context, toolInput: context.toolInput.input });
|
|
151
|
+
},
|
|
152
|
+
run: (context, input2) => {
|
|
153
|
+
const operation = select(input2);
|
|
154
|
+
return operation.run(context, input2.input).pipe(
|
|
155
|
+
Effect_exports.flatMap(
|
|
156
|
+
(output) => operation.output === void 0 ? Effect_exports.succeed(output) : Schema_exports.decodeUnknownEffect(operation.output)(output)
|
|
157
|
+
)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
];
|
|
162
|
+
})
|
|
163
|
+
);
|
|
164
|
+
var accountOperations = (accounts, discover, options) => Effect_exports.runPromise(
|
|
165
|
+
Effect_exports.gen(function* () {
|
|
166
|
+
const queries = /* @__PURE__ */ new Map();
|
|
167
|
+
const mutations = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const account of accounts) {
|
|
169
|
+
const operations = yield* Effect_exports.tryPromise({
|
|
170
|
+
try: () => discover(account),
|
|
171
|
+
catch: (error) => error
|
|
172
|
+
});
|
|
173
|
+
for (const [source, target] of [
|
|
174
|
+
[operations.queries, queries],
|
|
175
|
+
[operations.mutations, mutations]
|
|
176
|
+
]) {
|
|
177
|
+
for (const [name, declaration2] of Object.entries(source)) {
|
|
178
|
+
const operation = nativeOperation(declaration2);
|
|
179
|
+
if (operation === void 0)
|
|
180
|
+
return yield* Effect_exports.die(new Error("Expected a protocol operation"));
|
|
181
|
+
const group = target.get(name) ?? /* @__PURE__ */ new Map();
|
|
182
|
+
if (group.has(account.id))
|
|
183
|
+
return yield* Effect_exports.die(new Error("Account selections must be unique"));
|
|
184
|
+
group.set(account.id, operation);
|
|
185
|
+
target.set(name, group);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return { queries: combine("query", queries), mutations: combine("mutation", mutations) };
|
|
190
|
+
}),
|
|
191
|
+
options
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// src/contracts/app.ts
|
|
195
|
+
var NotImplemented = class extends Schema_exports.TaggedError()("NotImplemented", {
|
|
196
|
+
operation: Schema_exports.String
|
|
197
|
+
}) {
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/implementation/schedules.ts
|
|
201
|
+
var declaration = (timing, operation, input) => {
|
|
202
|
+
const native = nativeOperation(operation);
|
|
203
|
+
if (native === void 0 || native.kind !== "mutation")
|
|
204
|
+
throw new Error("A schedule must reference a mutation");
|
|
205
|
+
Schema_exports.decodeUnknownSync(native.input)(input);
|
|
206
|
+
return { operation, timing, input: Schema_exports.decodeUnknownSync(JsonValue)(input) };
|
|
207
|
+
};
|
|
208
|
+
var interval = (duration, operation, input) => {
|
|
209
|
+
const value = Schema_exports.decodeUnknownSync(Interval)(duration);
|
|
210
|
+
const milliseconds = value.seconds !== void 0 ? value.seconds * 1e3 : value.minutes !== void 0 ? value.minutes * 6e4 : value.hours * 36e5;
|
|
211
|
+
return declaration(
|
|
212
|
+
Schema_exports.decodeUnknownSync(ScheduleTiming)({ kind: "interval", milliseconds }),
|
|
213
|
+
operation,
|
|
214
|
+
input
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
var cron = (calendar, operation, input) => declaration(
|
|
218
|
+
{
|
|
219
|
+
kind: "cron",
|
|
220
|
+
calendar: Schema_exports.decodeUnknownSync(CalendarSchedule)({
|
|
221
|
+
...calendar,
|
|
222
|
+
timezone: calendar.timezone ?? "UTC"
|
|
223
|
+
})
|
|
224
|
+
},
|
|
225
|
+
operation,
|
|
226
|
+
input
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// src/index.ts
|
|
230
|
+
var OAuth2AccessToken2 = wrap(OAuth2AccessToken, false);
|
|
231
|
+
var secrets2 = (options) => secrets({ label: options.label, fields: decoderOf(options.fields) });
|
|
232
|
+
function oauth22(options) {
|
|
233
|
+
const { response = OAuth2AccessToken2, ...config } = options;
|
|
234
|
+
return Effect_exports.runSync(oauth2(config, decoderOf(response)));
|
|
235
|
+
}
|
|
236
|
+
var decodeJson2 = (response, schema) => {
|
|
237
|
+
const native = {
|
|
238
|
+
status: response.status,
|
|
239
|
+
json: () => Effect_exports.tryPromise({
|
|
240
|
+
try: () => response.json(),
|
|
241
|
+
catch: (error) => error
|
|
242
|
+
}).pipe(
|
|
243
|
+
Effect_exports.catch(
|
|
244
|
+
(error) => error instanceof SyntaxError ? Effect_exports.fail(new ResponseDecodeError()) : Effect_exports.die(error)
|
|
245
|
+
)
|
|
246
|
+
)
|
|
247
|
+
};
|
|
248
|
+
return Effect_exports.runPromise(decodeJson(native, decoderOf(schema)));
|
|
249
|
+
};
|
|
250
|
+
export {
|
|
251
|
+
ElicitationFailed,
|
|
252
|
+
NonRetryableError,
|
|
253
|
+
NotImplemented,
|
|
254
|
+
OAuth2AccessToken2 as OAuth2AccessToken,
|
|
255
|
+
ResponseDecodeError,
|
|
256
|
+
ResponseStatusError,
|
|
257
|
+
ValidationError,
|
|
258
|
+
WorkflowFailure,
|
|
259
|
+
accountOperations,
|
|
260
|
+
array,
|
|
261
|
+
boolean,
|
|
262
|
+
cron,
|
|
263
|
+
decodeJson2 as decodeJson,
|
|
264
|
+
defineApp,
|
|
265
|
+
defineDatabase,
|
|
266
|
+
defineProvider,
|
|
267
|
+
id,
|
|
268
|
+
interval,
|
|
269
|
+
json,
|
|
270
|
+
jsonSchema,
|
|
271
|
+
literal,
|
|
272
|
+
mutation,
|
|
273
|
+
number,
|
|
274
|
+
oauth22 as oauth2,
|
|
275
|
+
object,
|
|
276
|
+
query,
|
|
277
|
+
record,
|
|
278
|
+
secrets2 as secrets,
|
|
279
|
+
string,
|
|
280
|
+
table,
|
|
281
|
+
userId,
|
|
282
|
+
withApproval,
|
|
283
|
+
workflow
|
|
284
|
+
};
|
package/js/mcp/effect.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mcpToolsEffect
|
|
3
|
+
} from "../chunk-WIDTG42X.js";
|
|
4
|
+
import "../chunk-KWTCHVLT.js";
|
|
5
|
+
import "../chunk-BCSNKUAC.js";
|
|
6
|
+
import "../chunk-Q2FD5IBM.js";
|
|
7
|
+
import "../chunk-X3YBZCJW.js";
|
|
8
|
+
import "../chunk-R6JMJSVT.js";
|
|
9
|
+
import "../chunk-C24KEZXR.js";
|
|
10
|
+
import "../chunk-22WRQZT7.js";
|
|
11
|
+
import "../chunk-HP7E42X6.js";
|
|
12
|
+
import "../chunk-7JXHF5IF.js";
|
|
13
|
+
import "../chunk-OWD2YICM.js";
|
|
14
|
+
import "../chunk-VFUZI3NY.js";
|
|
15
|
+
import "../chunk-W7Q5EOTS.js";
|
|
16
|
+
import "../chunk-BPEFS4YF.js";
|
|
17
|
+
import "../chunk-EP6AEUZO.js";
|
|
18
|
+
import "../chunk-36DNRFZQ.js";
|
|
19
|
+
import "../chunk-2OTCEKL2.js";
|
|
20
|
+
import "../chunk-MLKGABMK.js";
|
|
21
|
+
export {
|
|
22
|
+
mcpToolsEffect
|
|
23
|
+
};
|
package/js/mcp/stdio.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
adaptMcpTools,
|
|
3
|
+
mcpClient,
|
|
4
|
+
mcpJsonSchemaValidator
|
|
5
|
+
} from "../chunk-KWTCHVLT.js";
|
|
6
|
+
import {
|
|
7
|
+
protocolOperations
|
|
8
|
+
} from "../chunk-LOKGDT6B.js";
|
|
9
|
+
import "../chunk-BCSNKUAC.js";
|
|
10
|
+
import "../chunk-Q2FD5IBM.js";
|
|
11
|
+
import "../chunk-X3YBZCJW.js";
|
|
12
|
+
import "../chunk-R6JMJSVT.js";
|
|
13
|
+
import "../chunk-C24KEZXR.js";
|
|
14
|
+
import {
|
|
15
|
+
McpError,
|
|
16
|
+
ProcessConfig
|
|
17
|
+
} from "../chunk-22WRQZT7.js";
|
|
18
|
+
import "../chunk-HP7E42X6.js";
|
|
19
|
+
import "../chunk-7JXHF5IF.js";
|
|
20
|
+
import "../chunk-OWD2YICM.js";
|
|
21
|
+
import "../chunk-VFUZI3NY.js";
|
|
22
|
+
import "../chunk-W7Q5EOTS.js";
|
|
23
|
+
import "../chunk-BPEFS4YF.js";
|
|
24
|
+
import "../chunk-EP6AEUZO.js";
|
|
25
|
+
import "../chunk-36DNRFZQ.js";
|
|
26
|
+
import {
|
|
27
|
+
Effect_exports,
|
|
28
|
+
Schema_exports
|
|
29
|
+
} from "../chunk-2OTCEKL2.js";
|
|
30
|
+
import "../chunk-MLKGABMK.js";
|
|
31
|
+
|
|
32
|
+
// src/implementation/mcp-stdio.ts
|
|
33
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
34
|
+
import { ErrorCode, McpError as ProtocolError } from "@modelcontextprotocol/sdk/types.js";
|
|
35
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
36
|
+
var OwnedTransport = class extends StdioClientTransport {
|
|
37
|
+
closing;
|
|
38
|
+
exited;
|
|
39
|
+
start() {
|
|
40
|
+
const previous = this.onclose;
|
|
41
|
+
this.exited = new Promise((resolve) => {
|
|
42
|
+
this.onclose = () => {
|
|
43
|
+
resolve();
|
|
44
|
+
previous?.();
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
return super.start();
|
|
48
|
+
}
|
|
49
|
+
close() {
|
|
50
|
+
return this.closing ??= (async () => {
|
|
51
|
+
const started = this.pid !== null;
|
|
52
|
+
await super.close();
|
|
53
|
+
if (started) await this.exited;
|
|
54
|
+
})();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var failure = (phase, error) => new McpError({
|
|
58
|
+
phase,
|
|
59
|
+
reason: error instanceof ProtocolError && error.code === ErrorCode.RequestTimeout ? "timeout" : "request"
|
|
60
|
+
});
|
|
61
|
+
function withClient(config, mode, use) {
|
|
62
|
+
return Effect_exports.scoped(
|
|
63
|
+
Effect_exports.gen(function* () {
|
|
64
|
+
const { client, transport } = yield* Effect_exports.acquireRelease(
|
|
65
|
+
Effect_exports.sync(() => ({
|
|
66
|
+
client: new Client(
|
|
67
|
+
{ name: "executor-app", version: "1" },
|
|
68
|
+
{
|
|
69
|
+
jsonSchemaValidator: mcpJsonSchemaValidator,
|
|
70
|
+
capabilities: mode === "call" ? { elicitation: { form: {} } } : {}
|
|
71
|
+
}
|
|
72
|
+
),
|
|
73
|
+
transport: new OwnedTransport({
|
|
74
|
+
command: config.command,
|
|
75
|
+
args: [...config.args],
|
|
76
|
+
env: { ...config.env },
|
|
77
|
+
...config.cwd === void 0 ? {} : { cwd: config.cwd },
|
|
78
|
+
stderr: "ignore"
|
|
79
|
+
})
|
|
80
|
+
})),
|
|
81
|
+
({ client: client2, transport: transport2 }) => Effect_exports.tryPromise(async () => {
|
|
82
|
+
try {
|
|
83
|
+
await client2.close();
|
|
84
|
+
} finally {
|
|
85
|
+
await transport2.close();
|
|
86
|
+
}
|
|
87
|
+
}).pipe(Effect_exports.withSpan("provider.mcp.close"), Effect_exports.orDie)
|
|
88
|
+
);
|
|
89
|
+
yield* Effect_exports.tryPromise({
|
|
90
|
+
try: (signal) => client.connect(transport, { signal, timeout: config.timeoutMs }),
|
|
91
|
+
catch: (error) => failure("connect", error)
|
|
92
|
+
}).pipe(Effect_exports.timeout(config.timeoutMs), Effect_exports.withSpan("provider.mcp.connect"));
|
|
93
|
+
return yield* use(client);
|
|
94
|
+
})
|
|
95
|
+
).pipe(
|
|
96
|
+
Effect_exports.withSpan("provider.mcp.session", {
|
|
97
|
+
attributes: { "mcp.transport": "stdio", "mcp.operation": mode }
|
|
98
|
+
}),
|
|
99
|
+
(operation) => mode === "discover" ? operation.pipe(Effect_exports.timeout(config.timeoutMs)) : operation,
|
|
100
|
+
Effect_exports.catchTag(
|
|
101
|
+
"TimeoutError",
|
|
102
|
+
() => Effect_exports.fail(new McpError({ phase: "transport", reason: "timeout" }))
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
var stdioToolsEffect = (input) => Effect_exports.gen(function* () {
|
|
107
|
+
const config = yield* Schema_exports.decodeUnknownEffect(ProcessConfig)(input).pipe(
|
|
108
|
+
Effect_exports.mapError(() => new McpError({ phase: "connect", reason: "invalid_input" }))
|
|
109
|
+
);
|
|
110
|
+
return yield* adaptMcpTools(
|
|
111
|
+
mcpClient((mode, use) => withClient(config, mode, use), config.timeoutMs, failure)
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// src/mcp-stdio.ts
|
|
116
|
+
var stdioOperations = (config, signal, kinds = {}) => Effect_exports.runPromise(
|
|
117
|
+
stdioToolsEffect(config).pipe(Effect_exports.map((tools) => protocolOperations(tools, kinds))),
|
|
118
|
+
signal === void 0 ? {} : { signal }
|
|
119
|
+
);
|
|
120
|
+
export {
|
|
121
|
+
McpError,
|
|
122
|
+
stdioOperations
|
|
123
|
+
};
|
package/js/mcp.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mcpToolsEffect
|
|
3
|
+
} from "./chunk-WIDTG42X.js";
|
|
4
|
+
import "./chunk-KWTCHVLT.js";
|
|
5
|
+
import {
|
|
6
|
+
protocolOperations
|
|
7
|
+
} from "./chunk-LOKGDT6B.js";
|
|
8
|
+
import "./chunk-BCSNKUAC.js";
|
|
9
|
+
import "./chunk-Q2FD5IBM.js";
|
|
10
|
+
import "./chunk-X3YBZCJW.js";
|
|
11
|
+
import "./chunk-R6JMJSVT.js";
|
|
12
|
+
import "./chunk-C24KEZXR.js";
|
|
13
|
+
import {
|
|
14
|
+
McpError
|
|
15
|
+
} from "./chunk-22WRQZT7.js";
|
|
16
|
+
import "./chunk-HP7E42X6.js";
|
|
17
|
+
import "./chunk-7JXHF5IF.js";
|
|
18
|
+
import "./chunk-OWD2YICM.js";
|
|
19
|
+
import "./chunk-VFUZI3NY.js";
|
|
20
|
+
import "./chunk-W7Q5EOTS.js";
|
|
21
|
+
import "./chunk-BPEFS4YF.js";
|
|
22
|
+
import "./chunk-EP6AEUZO.js";
|
|
23
|
+
import "./chunk-36DNRFZQ.js";
|
|
24
|
+
import {
|
|
25
|
+
Effect_exports
|
|
26
|
+
} from "./chunk-2OTCEKL2.js";
|
|
27
|
+
import "./chunk-MLKGABMK.js";
|
|
28
|
+
|
|
29
|
+
// src/mcp.ts
|
|
30
|
+
var mcpOperations = (options, kinds = {}) => Effect_exports.runPromise(
|
|
31
|
+
mcpToolsEffect(options).pipe(Effect_exports.map((operations) => protocolOperations(operations, kinds))),
|
|
32
|
+
options.signal === void 0 ? {} : { signal: options.signal }
|
|
33
|
+
);
|
|
34
|
+
export {
|
|
35
|
+
McpError,
|
|
36
|
+
mcpOperations
|
|
37
|
+
};
|