apps 0.0.1-beta.8 → 0.0.1-beta.81
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 +25 -22
- package/framework-reference.json +1 -1
- package/js/{chunk-72JNVHPK.js → chunk-4NFSABEA.js} +4 -3
- package/js/chunk-5FHWNLCI.js +88 -0
- package/js/chunk-5WGONRKQ.js +426 -0
- package/js/{chunk-M3B3DE4K.js → chunk-74YVXBKY.js} +463 -218
- package/js/chunk-CDXQDN7W.js +92 -0
- package/js/{chunk-UK573G7W.js → chunk-EOPQ727L.js} +87 -51
- package/js/{chunk-27F7W2LG.js → chunk-H2CJWXA3.js} +2 -2
- package/js/{chunk-JU7VHODU.js → chunk-H72MEDMN.js} +65 -10
- package/js/{chunk-FL2QR3XW.js → chunk-HJG4RBYM.js} +333 -69
- package/js/chunk-I6Q7ZPKJ.js +49 -0
- package/js/{chunk-CDL5PM2Q.js → chunk-IFJU5SYQ.js} +19082 -18402
- package/js/{chunk-VFZKSM3T.js → chunk-JPEUKEV4.js} +3 -3
- package/js/{chunk-5T57N25Q.js → chunk-KGCTYL2S.js} +511 -63
- package/js/{chunk-KUMBKVJD.js → chunk-KLYSEHUD.js} +2 -2
- package/js/{chunk-WLE7WX2U.js → chunk-NG56RPCA.js} +2348 -472
- package/js/chunk-OD3KFKZD.js +1617 -0
- package/js/{chunk-Z5M2LQOZ.js → chunk-OY47QPQY.js} +67 -55
- package/js/{chunk-57RKNWL2.js → chunk-PD6I2SDG.js} +4 -4
- package/js/chunk-PL5KOEZD.js +334 -0
- package/js/chunk-Q4IZAUIF.js +285 -0
- package/js/{chunk-RJDDBDSN.js → chunk-QWQM3CLH.js} +795 -177
- package/js/{chunk-RFVIONFX.js → chunk-TE25A7D6.js} +123 -44
- package/js/{chunk-IJX4CYZO.js → chunk-TUMGL2OC.js} +228 -264
- package/js/chunk-W6XCQAXP.js +171 -0
- package/js/chunk-WCGAO3X5.js +348 -0
- package/js/{chunk-IPI4MFSN.js → chunk-XBG7HHXC.js} +2 -2
- package/js/{chunk-CMYUWAX7.js → chunk-YQUG4CES.js} +126 -31
- package/js/{chunk-UESPOTUI.js → chunk-Z2SWTZCF.js} +861 -231
- package/js/client.js +142 -94
- package/js/contracts.js +127 -26
- package/js/effect.js +19 -19
- package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
- package/js/graphql.js +50 -40
- package/js/host.js +83 -58
- package/js/index.js +131 -46
- package/js/mcp/effect.js +23 -21
- package/js/mcp/stdio.js +44 -34
- package/js/mcp.js +76 -53
- package/js/openapi.js +4071 -1357
- package/js/react.js +2 -3
- package/js/skills/effect.js +6 -3
- package/js/skills.js +208 -81
- package/js/storage/facet.js +1 -540
- package/js/ui/auth/contracts.js +2 -2
- package/js/ui/auth.js +5 -5
- package/js/ui/contracts.js +5 -4
- package/js/ui/serving.js +8604 -223
- package/package.json +3 -4
- package/runtime.json +1 -1
- package/types/app-cache/src/contracts/cache.d.ts +18 -0
- package/types/app-cache/src/index.d.ts +34 -2
- package/types/apps/src/contracts/api-response-error.d.ts +4 -0
- package/types/apps/src/contracts/app.d.ts +7 -3
- package/types/apps/src/contracts/cache.d.ts +20 -0
- package/types/apps/src/contracts/context.d.ts +19 -11
- package/types/apps/src/contracts/elicitation.d.ts +23 -7
- package/types/apps/src/contracts/events.d.ts +93 -0
- package/types/apps/src/contracts/failure.d.ts +30 -1
- package/types/apps/src/contracts/graphql.d.ts +2 -1
- package/types/apps/src/contracts/host.d.ts +649 -17
- package/types/apps/src/contracts/live.d.ts +2 -0
- package/types/apps/src/contracts/mcp.d.ts +80 -10
- package/types/apps/src/contracts/network.d.ts +120 -0
- package/types/apps/src/contracts/openapi-compile.d.ts +82 -3
- package/types/apps/src/contracts/openapi.d.ts +41 -9
- package/types/apps/src/contracts/operations.d.ts +8 -4
- package/types/apps/src/contracts/placement.d.ts +102 -0
- package/types/apps/src/contracts/protocol-version.d.ts +2 -2
- package/types/apps/src/contracts/protocols/1.d.ts +733 -81
- package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
- package/types/apps/src/contracts/protocols/2.d.ts +69 -26
- package/types/apps/src/contracts/protocols/3.d.ts +133 -33
- package/types/apps/src/contracts/protocols/4.d.ts +122 -45
- package/types/apps/src/contracts/protocols/5.d.ts +157 -47
- package/types/apps/src/contracts/protocols/6.d.ts +1629 -0
- package/types/apps/src/contracts/protocols/7.d.ts +1785 -0
- package/types/apps/src/contracts/protocols/8.d.ts +1182 -0
- package/types/apps/src/contracts/protocols/9.d.ts +1104 -0
- package/types/apps/src/contracts/protocols/current.d.ts +3843 -0
- package/types/apps/src/contracts/protocols/oauth-6.d.ts +74 -0
- package/types/apps/src/contracts/protocols/oauth.d.ts +134 -0
- package/types/apps/src/contracts/provider-error.d.ts +9 -0
- package/types/apps/src/contracts/provider.d.ts +90 -6
- package/types/apps/src/contracts/skills.d.ts +50 -13
- package/types/apps/src/contracts/sql.d.ts +63 -0
- package/types/apps/src/contracts/ui.d.ts +37 -3
- package/types/apps/src/contracts/workflows.d.ts +6 -0
- package/types/apps/src/facet.d.ts +4 -5
- package/types/apps/src/host.d.ts +5 -0
- package/types/apps/src/implementation/account-router.d.ts +4 -3
- package/types/apps/src/implementation/authoring.d.ts +25 -5
- package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
- package/types/apps/src/implementation/cache.d.ts +28 -1
- package/types/apps/src/implementation/catalog-cache.d.ts +35 -4
- package/types/apps/src/implementation/elicitation.d.ts +18 -15
- package/types/apps/src/implementation/events.d.ts +59 -0
- package/types/apps/src/implementation/failure-detail.d.ts +25 -3
- package/types/apps/src/implementation/graphql-catalog.d.ts +3 -3
- package/types/apps/src/implementation/graphql.d.ts +4 -3
- package/types/apps/src/implementation/input-problems.d.ts +6 -2
- package/types/apps/src/implementation/invocation-timing.d.ts +18 -0
- package/types/apps/src/implementation/live.d.ts +2 -2
- package/types/apps/src/implementation/mcp-call.d.ts +6 -5
- package/types/apps/src/implementation/mcp-catalog.d.ts +6 -4
- package/types/apps/src/implementation/mcp-client.d.ts +17 -9
- package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
- package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
- package/types/apps/src/implementation/mcp.d.ts +20 -9
- package/types/apps/src/implementation/network.d.ts +16 -0
- package/types/apps/src/implementation/openapi-compile.d.ts +26 -6
- package/types/apps/src/implementation/openapi-document.d.ts +46 -19
- package/types/apps/src/implementation/openapi-names.d.ts +9 -4
- package/types/apps/src/implementation/openapi-request.d.ts +10 -2
- package/types/apps/src/implementation/openapi-source.d.ts +18 -0
- package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
- package/types/apps/src/implementation/operations.d.ts +17 -2
- package/types/apps/src/implementation/optimistic.d.ts +1 -1
- package/types/apps/src/implementation/placement.d.ts +60 -0
- package/types/apps/src/implementation/protocol-operations.d.ts +3 -0
- package/types/apps/src/implementation/provider-error.d.ts +28 -1
- package/types/apps/src/implementation/provider.d.ts +18 -3
- package/types/apps/src/implementation/query-commit.d.ts +1 -1
- package/types/apps/src/implementation/router-catalog.d.ts +11 -13
- package/types/apps/src/implementation/router.d.ts +16 -5
- package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
- package/types/apps/src/implementation/schema.d.ts +90 -10
- package/types/apps/src/implementation/skills.d.ts +18 -24
- package/types/apps/src/implementation/sql.d.ts +71 -0
- package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
- package/types/apps/src/implementation/ui-auth.d.ts +1 -1
- package/types/apps/src/implementation/ui-client.d.ts +2 -2
- package/types/apps/src/implementation/ui-document.d.ts +5 -0
- package/types/apps/src/implementation/ui-errors.d.ts +1 -1
- package/types/apps/src/implementation/ui-serving.d.ts +28 -9
- package/types/apps/src/implementation/ui-watch.d.ts +1 -1
- package/types/apps/src/implementation/upstream-error.d.ts +7 -0
- package/types/apps/src/implementation/webhooks.d.ts +1 -1
- package/types/apps/src/implementation/workflows.d.ts +1 -1
- package/types/apps/src/index.d.ts +55 -13
- package/types/apps/src/mcp.d.ts +20 -1
- package/types/apps/src/openapi.d.ts +1 -1
- package/types/apps/src/react.d.ts +1 -1
- package/types/apps/src/skills.d.ts +10 -8
- package/types/apps/src/ui-serving.d.ts +1 -1
- package/types/telemetry/src/app-records.d.ts +42 -0
- package/types/telemetry/src/browser-operations.d.ts +2 -2
- package/types/telemetry/src/browser.d.ts +8 -3
- package/types/telemetry/src/config.d.ts +2 -2
- package/types/telemetry/src/index.d.ts +2 -1
- package/types/telemetry/src/layer.d.ts +10 -4
- package/types/telemetry/src/measurements.d.ts +1 -1
- package/types/telemetry/src/ownership.d.ts +60 -0
- package/types/telemetry/src/recorded-failure.d.ts +29 -0
- package/types/telemetry/src/relay.d.ts +16 -6
- package/types/telemetry/src/span-attributes.d.ts +17 -1
- package/types/telemetry/src/transport.d.ts +8 -1
- package/types/utils/src/api-error.d.ts +55 -0
- package/types/utils/src/connection-failure.d.ts +33 -0
- package/types/utils/src/recorded-message.d.ts +18 -0
- package/types/utils/src/user-facing-error.d.ts +83 -0
- package/js/chunk-MKWZPDR6.js +0 -63
- package/js/chunk-N7YDVXYJ.js +0 -186
- package/js/chunk-NKLWZJLE.js +0 -172
- package/js/chunk-OCYUEU47.js +0 -224
- package/js/chunk-PJJ24GU7.js +0 -877
- package/js/chunk-PZB6T6KU.js +0 -19
- package/js/chunk-R3EV5FTO.js +0 -97
- package/js/chunk-YXQHV65J.js +0 -242
- package/js/chunk-ZQINWV4W.js +0 -630
- package/types/app-data/src/implementation/cursor.d.ts +0 -10
- package/types/app-data/src/implementation/index-key.d.ts +0 -7
- package/types/app-data/src/implementation/promise.d.ts +0 -68
- package/types/app-data/src/implementation/range.d.ts +0 -8
- package/types/app-data/src/implementation/schema.d.ts +0 -18
- package/types/app-data/src/implementation/sqlite.d.ts +0 -11
- package/types/app-data/src/index.d.ts +0 -4
- package/types/apps/src/contracts/storage.d.ts +0 -68
- package/types/apps/src/implementation/storage.d.ts +0 -15
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fixedRouter
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HJG4RBYM.js";
|
|
4
4
|
import {
|
|
5
5
|
nativeOperation,
|
|
6
6
|
operationDeclaration,
|
|
7
7
|
routerDeclaration
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-OY47QPQY.js";
|
|
9
9
|
|
|
10
10
|
// src/implementation/protocol-operations.ts
|
|
11
11
|
var protocolOperations = (operations, kinds = {}) => {
|
|
@@ -18,10 +18,11 @@ var protocolOperations = (operations, kinds = {}) => {
|
|
|
18
18
|
...operation.annotations === void 0 ? {} : { annotations: operation.annotations },
|
|
19
19
|
...operation._meta === void 0 ? {} : { _meta: operation._meta },
|
|
20
20
|
input: operation.input,
|
|
21
|
+
...operation.output === void 0 ? {} : { output: operation.output },
|
|
21
22
|
run: operation.run
|
|
22
23
|
};
|
|
23
24
|
const output = Object.getOwnPropertyDescriptor(operation, "outputSchema");
|
|
24
|
-
const withOutput = (target) => output === void 0 || output.get === void 0 && output.value === void 0 ? target : Object.defineProperty(target, "outputSchema", { ...output, enumerable: true });
|
|
25
|
+
const withOutput = (target) => operation.output !== void 0 || output === void 0 || output.get === void 0 && output.value === void 0 ? target : Object.defineProperty(target, "outputSchema", { ...output, enumerable: true });
|
|
25
26
|
declared[name] = operationDeclaration(withOutput({ ...native, kind }));
|
|
26
27
|
}
|
|
27
28
|
return declared;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Predicate_exports
|
|
3
|
+
} from "./chunk-IFJU5SYQ.js";
|
|
4
|
+
|
|
5
|
+
// ../utils/src/recorded-message.ts
|
|
6
|
+
var RecordedMessage = /* @__PURE__ */ Symbol.for("@executor-js/utils/RecordedMessage");
|
|
7
|
+
var recordedMessage = (error) => {
|
|
8
|
+
if (Predicate_exports.hasProperty(error, RecordedMessage)) {
|
|
9
|
+
const message = error[RecordedMessage];
|
|
10
|
+
return typeof message === "string" ? message : void 0;
|
|
11
|
+
}
|
|
12
|
+
return protocolErrorMessage(error) ?? sqlErrorMessage(error);
|
|
13
|
+
};
|
|
14
|
+
var jsonRpcMeanings = {
|
|
15
|
+
[-32700]: "Parse error",
|
|
16
|
+
[-32600]: "Invalid request",
|
|
17
|
+
[-32601]: "Method not found",
|
|
18
|
+
[-32602]: "Invalid params",
|
|
19
|
+
[-32603]: "Internal error",
|
|
20
|
+
[-32002]: "Resource not found"
|
|
21
|
+
};
|
|
22
|
+
var protocolErrorMessage = (error) => {
|
|
23
|
+
if (!Predicate_exports.isTagged(error, "ProtocolError") || !Predicate_exports.hasProperty(error, "code") || typeof error.code !== "number" || !Predicate_exports.hasProperty(error, "message") || !Predicate_exports.isString(error.message))
|
|
24
|
+
return void 0;
|
|
25
|
+
const code = error.code;
|
|
26
|
+
const refusal = /^Tool '.*' not found$/s.test(error.message) ? ": the requested tool does not exist" : error.message.startsWith("Invalid parameters for tool '") ? ": the tool's arguments failed validation" : "";
|
|
27
|
+
const meaning = jsonRpcMeanings[code];
|
|
28
|
+
const kind = meaning === void 0 ? "JSON-RPC error with an unlisted code" : `${meaning} (${code})`;
|
|
29
|
+
return kind + refusal;
|
|
30
|
+
};
|
|
31
|
+
var sqlReasons = /* @__PURE__ */ new Set([
|
|
32
|
+
"ConnectionError",
|
|
33
|
+
"AuthenticationError",
|
|
34
|
+
"AuthorizationError",
|
|
35
|
+
"SqlSyntaxError",
|
|
36
|
+
"UniqueViolation",
|
|
37
|
+
"ConstraintError",
|
|
38
|
+
"DeadlockError",
|
|
39
|
+
"SerializationError",
|
|
40
|
+
"LockTimeoutError",
|
|
41
|
+
"StatementTimeoutError",
|
|
42
|
+
"UnknownError"
|
|
43
|
+
]);
|
|
44
|
+
var sqlMessages = new Set(
|
|
45
|
+
[
|
|
46
|
+
"A pipelined query completed out of order",
|
|
47
|
+
"Connection closed",
|
|
48
|
+
"Connection closed during startup",
|
|
49
|
+
"Connection is closed",
|
|
50
|
+
"Connection timed out",
|
|
51
|
+
"Failed to connect",
|
|
52
|
+
"Failed to decode row",
|
|
53
|
+
"Failed to encode query",
|
|
54
|
+
"Failed to negotiate TLS",
|
|
55
|
+
"Failed to parse SSLRequest error response",
|
|
56
|
+
"Failed to parse server messages",
|
|
57
|
+
"Failed to parse server response",
|
|
58
|
+
"Failed to write query",
|
|
59
|
+
"Failed to write query batch",
|
|
60
|
+
"Invalid SSLRequest response",
|
|
61
|
+
"MD5 authentication failed",
|
|
62
|
+
"No password configured",
|
|
63
|
+
"Protocol desync",
|
|
64
|
+
"Query cancellation timed out",
|
|
65
|
+
"Query failed",
|
|
66
|
+
"SCRAM authentication failed",
|
|
67
|
+
"SCRAM exchange did not complete",
|
|
68
|
+
"SCRAM server verification failed",
|
|
69
|
+
"Server refused TLS",
|
|
70
|
+
"Socket error",
|
|
71
|
+
"Stream cancellation timed out",
|
|
72
|
+
"The server reported an error",
|
|
73
|
+
"Unsupported authentication method"
|
|
74
|
+
].map((message) => `PgConnection: ${message}`)
|
|
75
|
+
);
|
|
76
|
+
var sqlErrorMessage = (error) => {
|
|
77
|
+
if (!Predicate_exports.isTagged(error, "SqlError") || !Predicate_exports.hasProperty(error, "reason"))
|
|
78
|
+
return void 0;
|
|
79
|
+
const reason = error.reason;
|
|
80
|
+
const kind = Predicate_exports.hasProperty(reason, "_tag") && Predicate_exports.isString(reason._tag) && sqlReasons.has(reason._tag) ? reason._tag : "an unlisted kind";
|
|
81
|
+
const message = Predicate_exports.hasProperty(reason, "message") && Predicate_exports.isString(reason.message) && sqlMessages.has(reason.message) ? `: ${reason.message}` : "";
|
|
82
|
+
return `The database failed (${kind})${message}`;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
RecordedMessage,
|
|
87
|
+
recordedMessage
|
|
88
|
+
};
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import {
|
|
2
|
+
declaredOperations,
|
|
3
|
+
nativeOperation,
|
|
4
|
+
nativeRouter
|
|
5
|
+
} from "./chunk-OY47QPQY.js";
|
|
6
|
+
import {
|
|
7
|
+
fromPromise,
|
|
8
|
+
method
|
|
9
|
+
} from "./chunk-W6XCQAXP.js";
|
|
10
|
+
import {
|
|
11
|
+
EmittedEvent,
|
|
12
|
+
EventName,
|
|
13
|
+
Placement,
|
|
14
|
+
ScheduleTiming,
|
|
15
|
+
defaultEventLimits,
|
|
16
|
+
normalizePlacements,
|
|
17
|
+
placementFields,
|
|
18
|
+
renderPlacement
|
|
19
|
+
} from "./chunk-NG56RPCA.js";
|
|
20
|
+
import {
|
|
21
|
+
decoderOf,
|
|
22
|
+
isSchema,
|
|
23
|
+
jsonSchemaDocument,
|
|
24
|
+
schemaArgument
|
|
25
|
+
} from "./chunk-KGCTYL2S.js";
|
|
26
|
+
import {
|
|
27
|
+
JsonValue
|
|
28
|
+
} from "./chunk-H2CJWXA3.js";
|
|
29
|
+
import {
|
|
30
|
+
Effect_exports,
|
|
31
|
+
Result_exports,
|
|
32
|
+
Schema_exports
|
|
33
|
+
} from "./chunk-IFJU5SYQ.js";
|
|
34
|
+
|
|
35
|
+
// src/contracts/http.ts
|
|
36
|
+
var ResponseStatusError = class extends Schema_exports.TaggedError()(
|
|
37
|
+
"ResponseStatusError",
|
|
38
|
+
{ status: Schema_exports.Number }
|
|
39
|
+
) {
|
|
40
|
+
get message() {
|
|
41
|
+
return `Request failed with status ${this.status}`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var ResponseDecodeError = class extends Schema_exports.TaggedError()(
|
|
45
|
+
"ResponseDecodeError",
|
|
46
|
+
{}
|
|
47
|
+
) {
|
|
48
|
+
get message() {
|
|
49
|
+
return "Response body did not match the expected schema";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/implementation/placement.ts
|
|
54
|
+
var misuse = (name) => `${name} is a credential placement, not a string. Build placement values with t\`...\`, such as t\`Bearer \${token}\`, instead of an untagged template literal or string concatenation.`;
|
|
55
|
+
var NotAString = class {
|
|
56
|
+
#described;
|
|
57
|
+
constructor(described) {
|
|
58
|
+
this.#described = described;
|
|
59
|
+
}
|
|
60
|
+
[Symbol.toPrimitive]() {
|
|
61
|
+
throw new TypeError(misuse(this.#described));
|
|
62
|
+
}
|
|
63
|
+
toString() {
|
|
64
|
+
throw new TypeError(misuse(this.#described));
|
|
65
|
+
}
|
|
66
|
+
toJSON() {
|
|
67
|
+
throw new TypeError(misuse(this.#described));
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var FieldRef = class extends NotAString {
|
|
71
|
+
field;
|
|
72
|
+
constructor(field) {
|
|
73
|
+
super(`The field reference ${JSON.stringify(field)}`);
|
|
74
|
+
this.field = field;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var PlacementValue = class extends NotAString {
|
|
78
|
+
parts;
|
|
79
|
+
constructor(parts) {
|
|
80
|
+
super("A t`...` value");
|
|
81
|
+
this.parts = parts;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var partsOf = (input) => {
|
|
85
|
+
if (typeof input === "string") return input === "" ? [] : [input];
|
|
86
|
+
if (input instanceof FieldRef) return [{ field: input.field }];
|
|
87
|
+
if (input instanceof PlacementValue) return input.parts;
|
|
88
|
+
throw new TypeError(
|
|
89
|
+
`A credential placement interpolates text, a field reference, t\`...\` or base64(...), not ${typeof input}.`
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
var joined = (parts) => parts.reduce((all, part) => {
|
|
93
|
+
const last = all.at(-1);
|
|
94
|
+
if (typeof part === "string" && typeof last === "string") all[all.length - 1] = last + part;
|
|
95
|
+
else all.push(part);
|
|
96
|
+
return all;
|
|
97
|
+
}, []);
|
|
98
|
+
var t = (strings, ...values) => new PlacementValue(
|
|
99
|
+
joined(
|
|
100
|
+
strings.flatMap((text, index) => [
|
|
101
|
+
...partsOf(text),
|
|
102
|
+
...index < values.length ? partsOf(values[index]) : []
|
|
103
|
+
])
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
var base64 = (value2) => {
|
|
107
|
+
const inner = partsOf(value2).map((part) => {
|
|
108
|
+
if (typeof part === "object" && "base64" in part)
|
|
109
|
+
throw new TypeError("base64(...) cannot contain another base64(...).");
|
|
110
|
+
return part;
|
|
111
|
+
});
|
|
112
|
+
if (inner.length === 0) throw new TypeError("base64(...) needs a value.");
|
|
113
|
+
return new PlacementValue([{ base64: inner }]);
|
|
114
|
+
};
|
|
115
|
+
var value = (input) => {
|
|
116
|
+
const parts = partsOf(input);
|
|
117
|
+
if (parts.length === 0) throw new TypeError("A credential placement needs a value.");
|
|
118
|
+
return joined(parts);
|
|
119
|
+
};
|
|
120
|
+
var header = (name, input) => ({
|
|
121
|
+
in: "header",
|
|
122
|
+
name: name.toLowerCase(),
|
|
123
|
+
value: value(input)
|
|
124
|
+
});
|
|
125
|
+
var query = (name, input) => ({
|
|
126
|
+
in: "query",
|
|
127
|
+
name,
|
|
128
|
+
value: value(input)
|
|
129
|
+
});
|
|
130
|
+
var bearer = (token) => header("authorization", t`Bearer ${token}`);
|
|
131
|
+
var basic = (user, password) => header("authorization", t`Basic ${base64(t`${user}:${password}`)}`);
|
|
132
|
+
var declarePlacements = (method2, names, exposure, request) => {
|
|
133
|
+
const declared = new Set(names);
|
|
134
|
+
const refs = new Proxy(Object.fromEntries(names.map((name) => [name, new FieldRef(name)])), {
|
|
135
|
+
get: (target, key) => {
|
|
136
|
+
if (typeof key === "string" && !declared.has(key))
|
|
137
|
+
throw new TypeError(
|
|
138
|
+
`The ${method2} request references "${key}", which is not one of its fields: ${names.join(", ")}.`
|
|
139
|
+
);
|
|
140
|
+
return Reflect.get(target, key);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const returned = request(refs);
|
|
144
|
+
const placements = Array.isArray(returned) ? returned : [returned];
|
|
145
|
+
if (placements.length === 0) throw new TypeError(`The ${method2} request declares no placements.`);
|
|
146
|
+
if (!placements.every(Schema_exports.is(Placement)))
|
|
147
|
+
throw new TypeError(
|
|
148
|
+
`The ${method2} request must return header(...) or query(...) placements, or an array of them.`
|
|
149
|
+
);
|
|
150
|
+
for (const placement of placements) {
|
|
151
|
+
const fields = placementFields(placement);
|
|
152
|
+
for (const field of fields) {
|
|
153
|
+
if (!declared.has(field))
|
|
154
|
+
throw new TypeError(
|
|
155
|
+
`The ${method2} request references "${field}", which is not one of its fields: ${names.join(", ")}.`
|
|
156
|
+
);
|
|
157
|
+
if (exposure?.[field] === "raw")
|
|
158
|
+
throw new TypeError(
|
|
159
|
+
`The ${method2} request references the raw() field "${field}". App code reads raw fields as real values, so they are never placed; remove raw() or the reference.`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
if (![...fields].some((field) => exposure?.[field] === void 0))
|
|
163
|
+
throw new TypeError(
|
|
164
|
+
`The ${method2} request's ${placement.in} ${placement.name} references no secret field. A placement places a secret: reference a field that is not plain() or raw().`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
return normalizePlacements(placements);
|
|
168
|
+
};
|
|
169
|
+
var undeclared = (method2) => `The ${method2} account declares no request. Declare where its credentials go with request, such as request: ({ token }) => bearer(token), to use headers() and url().`;
|
|
170
|
+
var withPlacements = (account, placements) => {
|
|
171
|
+
const fields = typeof account.fields === "object" && account.fields !== null ? account.fields : {};
|
|
172
|
+
const render = (placement) => Result_exports.getOrThrowWith(
|
|
173
|
+
renderPlacement(placement, fields),
|
|
174
|
+
(error) => new TypeError(error.message)
|
|
175
|
+
);
|
|
176
|
+
const declared = () => {
|
|
177
|
+
if (placements === void 0 || placements.length === 0)
|
|
178
|
+
throw new TypeError(undeclared(account.method));
|
|
179
|
+
return placements;
|
|
180
|
+
};
|
|
181
|
+
return Object.defineProperties(account, {
|
|
182
|
+
headers: {
|
|
183
|
+
enumerable: false,
|
|
184
|
+
value: () => Object.fromEntries(
|
|
185
|
+
declared().filter((placement) => placement.in === "header").map((placement) => [placement.name, render(placement)])
|
|
186
|
+
)
|
|
187
|
+
},
|
|
188
|
+
url: {
|
|
189
|
+
enumerable: false,
|
|
190
|
+
value: (input) => {
|
|
191
|
+
const url = new URL(input);
|
|
192
|
+
for (const placement of declared())
|
|
193
|
+
if (placement.in === "query") url.searchParams.set(placement.name, render(placement));
|
|
194
|
+
return url.href;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/implementation/workflows.ts
|
|
201
|
+
var NativeWorkflow = /* @__PURE__ */ Symbol("apps.Workflow");
|
|
202
|
+
var workflow = (options, run) => ({
|
|
203
|
+
[NativeWorkflow]: {
|
|
204
|
+
input: decoderOf(schemaArgument(options.input, "The workflow input")),
|
|
205
|
+
...options.output === void 0 ? {} : { output: decoderOf(schemaArgument(options.output, "The workflow output")) },
|
|
206
|
+
...options.description === void 0 ? {} : { description: options.description },
|
|
207
|
+
// SAFETY: defineApp checks required context; the host supplies the pinned run's capabilities.
|
|
208
|
+
run: (context, input) => fromPromise(run, "workflow")(context, input)
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
var nativeWorkflow = (value2) => {
|
|
212
|
+
if (typeof value2 !== "object" || value2 === null || !(NativeWorkflow in value2)) return void 0;
|
|
213
|
+
return value2[NativeWorkflow];
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// src/implementation/events.ts
|
|
217
|
+
var Native = /* @__PURE__ */ Symbol("apps.Event");
|
|
218
|
+
var scalarTypes = /* @__PURE__ */ new Set(["string", "number", "integer", "boolean"]);
|
|
219
|
+
var isScalarSchema = (document) => {
|
|
220
|
+
const type = document.type;
|
|
221
|
+
if (typeof type === "string") return scalarTypes.has(type);
|
|
222
|
+
const choices = Array.isArray(document.enum) ? document.enum : "const" in document ? [document.const] : void 0;
|
|
223
|
+
return choices !== void 0 && choices.length > 0 && choices.every((value2) => ["string", "number", "boolean"].includes(typeof value2));
|
|
224
|
+
};
|
|
225
|
+
var event = (options) => {
|
|
226
|
+
const filters = options.filters ?? {};
|
|
227
|
+
const fieldDecoders = Object.fromEntries(
|
|
228
|
+
Object.entries(filters).map(([key, field]) => [
|
|
229
|
+
key,
|
|
230
|
+
decoderOf(schemaArgument(field, `The event filter ${JSON.stringify(key)}`))
|
|
231
|
+
])
|
|
232
|
+
);
|
|
233
|
+
for (const [key, decoder] of Object.entries(fieldDecoders)) {
|
|
234
|
+
const document = Effect_exports.runSync(jsonSchemaDocument(decoder));
|
|
235
|
+
if (!isScalarSchema(document))
|
|
236
|
+
throw new TypeError(
|
|
237
|
+
`The event filter ${JSON.stringify(key)} must be a string, number, boolean or literal`
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
[Native]: {
|
|
242
|
+
description: options.description,
|
|
243
|
+
filters: fieldDecoders,
|
|
244
|
+
payload: decoderOf(schemaArgument(options.payload, "The event payload"))
|
|
245
|
+
},
|
|
246
|
+
description: options.description,
|
|
247
|
+
filters,
|
|
248
|
+
payload: options.payload
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
var nativeEvent = (declaration) => typeof declaration === "object" && declaration !== null && Native in declaration ? declaration[Native] : void 0;
|
|
252
|
+
var declaredEvents = (events) => Effect_exports.forEach(
|
|
253
|
+
Object.entries(events),
|
|
254
|
+
([name, declared]) => Effect_exports.gen(function* () {
|
|
255
|
+
const filters = yield* jsonSchemaDocument(Schema_exports.Struct(declared.filters));
|
|
256
|
+
const payload = yield* jsonSchemaDocument(declared.payload);
|
|
257
|
+
return [name, { description: declared.description, filters, payload }];
|
|
258
|
+
})
|
|
259
|
+
).pipe(Effect_exports.map((entries) => Object.fromEntries(entries)));
|
|
260
|
+
var makeEmitter = (input) => ({
|
|
261
|
+
emit: (name, data, ...rest) => {
|
|
262
|
+
const options = rest[0] ?? {};
|
|
263
|
+
const declared = Object.hasOwn(input.events, name) ? input.events[name] : void 0;
|
|
264
|
+
if (declared === void 0) throw new TypeError(`This app declares no event named "${name}"`);
|
|
265
|
+
if (input.emitted.length >= defaultEventLimits.maxEventsPerInvocation)
|
|
266
|
+
throw new RangeError(
|
|
267
|
+
`An invocation can emit at most ${defaultEventLimits.maxEventsPerInvocation} events`
|
|
268
|
+
);
|
|
269
|
+
const payload = Schema_exports.decodeUnknownSync(declared.payload)(data);
|
|
270
|
+
const filters = Schema_exports.decodeUnknownSync(Schema_exports.Struct(declared.filters))(
|
|
271
|
+
options.filters ?? {}
|
|
272
|
+
);
|
|
273
|
+
const account = options.account ?? input.sourceAccount ?? (input.accounts.length === 1 ? input.accounts[0] : void 0) ?? null;
|
|
274
|
+
if (account === null && input.accounts.length > 1)
|
|
275
|
+
throw new TypeError(
|
|
276
|
+
"This invocation has several accounts; name the one the event came from with { account }"
|
|
277
|
+
);
|
|
278
|
+
if (account !== null && !input.accounts.includes(account))
|
|
279
|
+
throw new TypeError("The event's account is not one of this invocation's accounts");
|
|
280
|
+
const occurredAt = options.occurredAt === void 0 ? Date.now() : options.occurredAt instanceof Date ? options.occurredAt.getTime() : options.occurredAt;
|
|
281
|
+
const occurrence = Schema_exports.decodeUnknownSync(EmittedEvent)({
|
|
282
|
+
name: Schema_exports.decodeUnknownSync(EventName)(name),
|
|
283
|
+
id: options.id ?? crypto.randomUUID(),
|
|
284
|
+
occurredAt,
|
|
285
|
+
data: payload,
|
|
286
|
+
filters,
|
|
287
|
+
account
|
|
288
|
+
});
|
|
289
|
+
if (new TextEncoder().encode(JSON.stringify(occurrence.data)).byteLength > defaultEventLimits.maxDataBytes)
|
|
290
|
+
throw new RangeError(
|
|
291
|
+
`An event's data can be at most ${defaultEventLimits.maxDataBytes} bytes of JSON; send a summary and a tool to read the rest`
|
|
292
|
+
);
|
|
293
|
+
input.emitted.push(occurrence);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// src/implementation/app.ts
|
|
298
|
+
var InternalApp = /* @__PURE__ */ Symbol("apps.App");
|
|
299
|
+
var isApp = (value2) => typeof value2 === "object" && value2 !== null && InternalApp in value2;
|
|
300
|
+
var toEffectApp = (app) => app[InternalApp];
|
|
301
|
+
function rejectCatalogs(definition) {
|
|
302
|
+
if ("queries" in definition || "mutations" in definition)
|
|
303
|
+
throw new Error("Put queries and mutations in a router under tools");
|
|
304
|
+
}
|
|
305
|
+
function adaptDefinition(definition) {
|
|
306
|
+
rejectCatalogs(definition);
|
|
307
|
+
const webhooks = definition.webhooks === void 0 ? {} : {
|
|
308
|
+
// SAFETY: `Required` only where the optional method was just checked to be present.
|
|
309
|
+
webhooks: Object.fromEntries(
|
|
310
|
+
Object.entries(definition.webhooks).map(([name, webhook]) => [
|
|
311
|
+
name,
|
|
312
|
+
{
|
|
313
|
+
...webhook,
|
|
314
|
+
...webhook.register === void 0 ? {} : {
|
|
315
|
+
register: fromPromise(
|
|
316
|
+
method(webhook, "register"),
|
|
317
|
+
"webhook"
|
|
318
|
+
)
|
|
319
|
+
},
|
|
320
|
+
handle: fromPromise(method(webhook, "handle"), "webhook"),
|
|
321
|
+
...webhook.unregister === void 0 ? {} : {
|
|
322
|
+
unregister: fromPromise(
|
|
323
|
+
method(webhook, "unregister"),
|
|
324
|
+
"webhook"
|
|
325
|
+
)
|
|
326
|
+
},
|
|
327
|
+
..."config" in webhook && isSchema(webhook.config) ? { config: decoderOf(webhook.config) } : {},
|
|
328
|
+
..."state" in webhook && isSchema(webhook.state) ? { state: decoderOf(webhook.state) } : {}
|
|
329
|
+
}
|
|
330
|
+
])
|
|
331
|
+
)
|
|
332
|
+
};
|
|
333
|
+
const workflows = definition.workflows === void 0 ? {} : {
|
|
334
|
+
workflows: Object.fromEntries(
|
|
335
|
+
Object.entries(definition.workflows).map(([name, value2]) => {
|
|
336
|
+
const declared2 = nativeWorkflow(value2);
|
|
337
|
+
if (declared2 === void 0) throw new Error("Invalid workflow declaration");
|
|
338
|
+
return [name, declared2];
|
|
339
|
+
})
|
|
340
|
+
)
|
|
341
|
+
};
|
|
342
|
+
const root = definition.tools === void 0 ? void 0 : nativeRouter(definition.tools);
|
|
343
|
+
if (definition.tools !== void 0 && root === void 0)
|
|
344
|
+
throw new Error("tools must be a router");
|
|
345
|
+
const data = root === void 0 ? {} : { tools: root };
|
|
346
|
+
const declared = root?.kind === "router" ? declaredOperations(root) : [];
|
|
347
|
+
const mutations = /* @__PURE__ */ new Set();
|
|
348
|
+
for (const { operation } of declared) {
|
|
349
|
+
if (operation.kind !== "mutation") continue;
|
|
350
|
+
if (mutations.has(operation))
|
|
351
|
+
throw new Error("A mutation can be mounted at only one path in tools");
|
|
352
|
+
mutations.add(operation);
|
|
353
|
+
}
|
|
354
|
+
const schedules = definition.schedules === void 0 ? {} : {
|
|
355
|
+
schedules: Object.fromEntries(
|
|
356
|
+
Object.entries(definition.schedules).map(([name, schedule]) => {
|
|
357
|
+
const target = nativeOperation(schedule.operation);
|
|
358
|
+
const match = declared.find(
|
|
359
|
+
({ operation }) => operation === target && operation.kind === "mutation"
|
|
360
|
+
);
|
|
361
|
+
if (match === void 0)
|
|
362
|
+
throw new Error("A schedule must reference a mutation in this app's tools");
|
|
363
|
+
return [
|
|
364
|
+
name,
|
|
365
|
+
{
|
|
366
|
+
timing: Schema_exports.decodeUnknownSync(ScheduleTiming)(schedule.timing),
|
|
367
|
+
input: Schema_exports.decodeUnknownSync(JsonValue)(schedule.input),
|
|
368
|
+
tool: match.name
|
|
369
|
+
}
|
|
370
|
+
];
|
|
371
|
+
})
|
|
372
|
+
)
|
|
373
|
+
};
|
|
374
|
+
return {
|
|
375
|
+
...definition,
|
|
376
|
+
...webhooks,
|
|
377
|
+
...workflows,
|
|
378
|
+
...data,
|
|
379
|
+
...schedules
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
var defineApp = (requirements, definition) => {
|
|
383
|
+
if (typeof definition !== "function") rejectCatalogs(definition);
|
|
384
|
+
const evaluate = typeof definition === "function" ? definition : async () => definition;
|
|
385
|
+
const factory = fromPromise(evaluate, "factory");
|
|
386
|
+
const events = requirements.events === void 0 ? void 0 : Object.fromEntries(
|
|
387
|
+
Object.entries(requirements.events).map(([name, declared]) => {
|
|
388
|
+
const native2 = nativeEvent(declared);
|
|
389
|
+
if (native2 === void 0)
|
|
390
|
+
throw new TypeError(
|
|
391
|
+
`The event ${JSON.stringify(name)} must be declared with event()`
|
|
392
|
+
);
|
|
393
|
+
return [name, native2];
|
|
394
|
+
})
|
|
395
|
+
);
|
|
396
|
+
const native = {
|
|
397
|
+
accounts: requirements.accounts,
|
|
398
|
+
...events === void 0 ? {} : { events },
|
|
399
|
+
evaluate: (context) => factory(context).pipe(Effect_exports.map((value2) => adaptDefinition(value2)))
|
|
400
|
+
};
|
|
401
|
+
return {
|
|
402
|
+
[InternalApp]: native,
|
|
403
|
+
accounts: native.accounts,
|
|
404
|
+
evaluate: (context) => Effect_exports.runPromise(factory(context))
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
export {
|
|
409
|
+
ResponseStatusError,
|
|
410
|
+
ResponseDecodeError,
|
|
411
|
+
t,
|
|
412
|
+
base64,
|
|
413
|
+
header,
|
|
414
|
+
query,
|
|
415
|
+
bearer,
|
|
416
|
+
basic,
|
|
417
|
+
declarePlacements,
|
|
418
|
+
withPlacements,
|
|
419
|
+
workflow,
|
|
420
|
+
event,
|
|
421
|
+
declaredEvents,
|
|
422
|
+
makeEmitter,
|
|
423
|
+
isApp,
|
|
424
|
+
toEffectApp,
|
|
425
|
+
defineApp
|
|
426
|
+
};
|