apps 0.0.1-beta.9 → 0.0.1-beta.91
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 +56 -38
- package/framework-reference.json +1 -1
- package/js/chunk-3LEVTFD4.js +712 -0
- package/js/chunk-5FHWNLCI.js +88 -0
- package/js/{chunk-FL2QR3XW.js → chunk-5MDA7MKL.js} +338 -73
- package/js/chunk-6XQLA5NC.js +5047 -0
- package/js/{chunk-M3B3DE4K.js → chunk-74YVXBKY.js} +463 -218
- package/js/chunk-7PHHWYV4.js +335 -0
- package/js/chunk-DADXWWRZ.js +449 -0
- package/js/{chunk-27F7W2LG.js → chunk-DDHBUKXX.js} +18 -2
- package/js/{chunk-UK573G7W.js → chunk-EOPQ727L.js} +87 -51
- package/js/{chunk-5T57N25Q.js → chunk-GQ33QSNB.js} +583 -69
- package/js/{chunk-JU7VHODU.js → chunk-H72MEDMN.js} +65 -10
- package/js/chunk-I5C7FD5Z.js +171 -0
- package/js/{chunk-CDL5PM2Q.js → chunk-IFJU5SYQ.js} +19082 -18402
- package/js/{chunk-VFZKSM3T.js → chunk-JPEUKEV4.js} +3 -3
- package/js/{chunk-KUMBKVJD.js → chunk-KLYSEHUD.js} +2 -2
- package/js/{chunk-RFVIONFX.js → chunk-KUCCHNVY.js} +123 -44
- package/js/chunk-OD3KFKZD.js +1617 -0
- package/js/{chunk-57RKNWL2.js → chunk-PD6I2SDG.js} +4 -4
- package/js/{chunk-72JNVHPK.js → chunk-PYQLOLOC.js} +4 -3
- package/js/{chunk-ODEIDRGW.js → chunk-QWQM3CLH.js} +795 -176
- package/js/{chunk-IJX4CYZO.js → chunk-TUMGL2OC.js} +228 -264
- package/js/{chunk-IPI4MFSN.js → chunk-XBG7HHXC.js} +2 -2
- package/js/chunk-XPRZTLHD.js +1915 -0
- package/js/chunk-YNJ5CZMJ.js +93 -0
- package/js/chunk-YRGL4QEF.js +49 -0
- package/js/{chunk-Z5M2LQOZ.js → chunk-YWFUWTUJ.js} +113 -58
- package/js/client.js +142 -78
- package/js/contracts.js +142 -21
- package/js/effect.js +18 -19
- package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
- package/js/graphql.js +49 -40
- package/js/host.js +85 -62
- package/js/index.js +165 -70
- package/js/mcp/effect.js +21 -21
- package/js/mcp.js +76 -56
- package/js/openapi.js +4189 -1411
- 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 +8605 -225
- package/package.json +3 -8
- 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 +60 -11
- package/types/apps/src/contracts/cache.d.ts +20 -0
- package/types/apps/src/contracts/context.d.ts +60 -17
- package/types/apps/src/contracts/elicitation.d.ts +23 -7
- package/types/apps/src/contracts/events.d.ts +94 -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 +1446 -17
- package/types/apps/src/contracts/icons.d.ts +28 -0
- package/types/apps/src/contracts/live.d.ts +2 -0
- package/types/apps/src/contracts/mcp.d.ts +81 -20
- 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 +14 -7
- 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/11.d.ts +1149 -0
- package/types/apps/src/contracts/protocols/12.d.ts +3310 -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 +6669 -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/schedules.d.ts +7 -1
- package/types/apps/src/contracts/schema.d.ts +21 -0
- 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 +44 -14
- package/types/apps/src/contracts/webhooks.d.ts +24 -7
- package/types/apps/src/contracts/workflows.d.ts +19 -17
- 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/app.d.ts +41 -14
- 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 +29 -2
- 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 +64 -0
- package/types/apps/src/implementation/failure-detail.d.ts +28 -5
- 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-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 +28 -7
- 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 +23 -1
- package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
- package/types/apps/src/implementation/operations.d.ts +57 -7
- 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 +19 -4
- package/types/apps/src/implementation/query-commit.d.ts +1 -1
- package/types/apps/src/implementation/router-catalog.d.ts +20 -18
- package/types/apps/src/implementation/router.d.ts +24 -5
- package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
- package/types/apps/src/implementation/schedules.d.ts +39 -8
- package/types/apps/src/implementation/schema.d.ts +98 -11
- 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 +26 -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 +15 -6
- package/types/apps/src/implementation/workflow-context.d.ts +6 -2
- package/types/apps/src/implementation/workflows.d.ts +11 -4
- package/types/apps/src/index.d.ts +68 -19
- package/types/apps/src/mcp.d.ts +20 -1
- package/types/apps/src/openapi.d.ts +6 -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-7EK2JDX4.js +0 -299
- package/js/chunk-IKS2C5MQ.js +0 -224
- package/js/chunk-MKWZPDR6.js +0 -63
- package/js/chunk-N7YDVXYJ.js +0 -186
- package/js/chunk-NKLWZJLE.js +0 -172
- package/js/chunk-PJJ24GU7.js +0 -877
- package/js/chunk-PZB6T6KU.js +0 -19
- package/js/chunk-R3EV5FTO.js +0 -97
- package/js/chunk-SJFZCGXG.js +0 -1243
- package/js/chunk-WLE7WX2U.js +0 -2645
- package/js/chunk-YXQHV65J.js +0 -242
- package/js/chunk-ZQINWV4W.js +0 -630
- package/js/mcp/stdio.js +0 -128
- 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/mcp-stdio.d.ts +0 -4
- package/types/apps/src/implementation/storage.d.ts +0 -15
- package/types/apps/src/mcp-stdio.d.ts +0 -5
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import {
|
|
2
|
+
declaredOperations,
|
|
3
|
+
nativeOperation,
|
|
4
|
+
nativeRouter
|
|
5
|
+
} from "./chunk-YWFUWTUJ.js";
|
|
6
|
+
import {
|
|
7
|
+
fromPromise,
|
|
8
|
+
method
|
|
9
|
+
} from "./chunk-I5C7FD5Z.js";
|
|
10
|
+
import {
|
|
11
|
+
EmittedEvent,
|
|
12
|
+
EventName,
|
|
13
|
+
Placement,
|
|
14
|
+
ScheduleTiming,
|
|
15
|
+
appIconsProblem,
|
|
16
|
+
defaultEventLimits,
|
|
17
|
+
normalizePlacements,
|
|
18
|
+
placementFields,
|
|
19
|
+
renderPlacement
|
|
20
|
+
} from "./chunk-6XQLA5NC.js";
|
|
21
|
+
import {
|
|
22
|
+
decoderOf,
|
|
23
|
+
isSchema,
|
|
24
|
+
jsonSchemaDocument,
|
|
25
|
+
schemaArgument
|
|
26
|
+
} from "./chunk-GQ33QSNB.js";
|
|
27
|
+
import {
|
|
28
|
+
JsonValue
|
|
29
|
+
} from "./chunk-DDHBUKXX.js";
|
|
30
|
+
import {
|
|
31
|
+
Effect_exports,
|
|
32
|
+
Result_exports,
|
|
33
|
+
Schema_exports
|
|
34
|
+
} from "./chunk-IFJU5SYQ.js";
|
|
35
|
+
|
|
36
|
+
// src/contracts/http.ts
|
|
37
|
+
var ResponseStatusError = class extends Schema_exports.TaggedError()(
|
|
38
|
+
"ResponseStatusError",
|
|
39
|
+
{ status: Schema_exports.Number }
|
|
40
|
+
) {
|
|
41
|
+
get message() {
|
|
42
|
+
return `Request failed with status ${this.status}`;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var ResponseDecodeError = class extends Schema_exports.TaggedError()(
|
|
46
|
+
"ResponseDecodeError",
|
|
47
|
+
{}
|
|
48
|
+
) {
|
|
49
|
+
get message() {
|
|
50
|
+
return "Response body did not match the expected schema";
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/implementation/placement.ts
|
|
55
|
+
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.`;
|
|
56
|
+
var NotAString = class {
|
|
57
|
+
#described;
|
|
58
|
+
constructor(described) {
|
|
59
|
+
this.#described = described;
|
|
60
|
+
}
|
|
61
|
+
[Symbol.toPrimitive]() {
|
|
62
|
+
throw new TypeError(misuse(this.#described));
|
|
63
|
+
}
|
|
64
|
+
toString() {
|
|
65
|
+
throw new TypeError(misuse(this.#described));
|
|
66
|
+
}
|
|
67
|
+
toJSON() {
|
|
68
|
+
throw new TypeError(misuse(this.#described));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var FieldRef = class extends NotAString {
|
|
72
|
+
field;
|
|
73
|
+
constructor(field) {
|
|
74
|
+
super(`The field reference ${JSON.stringify(field)}`);
|
|
75
|
+
this.field = field;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var PlacementValue = class extends NotAString {
|
|
79
|
+
parts;
|
|
80
|
+
constructor(parts) {
|
|
81
|
+
super("A t`...` value");
|
|
82
|
+
this.parts = parts;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var partsOf = (input) => {
|
|
86
|
+
if (typeof input === "string") return input === "" ? [] : [input];
|
|
87
|
+
if (input instanceof FieldRef) return [{ field: input.field }];
|
|
88
|
+
if (input instanceof PlacementValue) return input.parts;
|
|
89
|
+
throw new TypeError(
|
|
90
|
+
`A credential placement interpolates text, a field reference, t\`...\` or base64(...), not ${typeof input}.`
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
var joined = (parts) => parts.reduce((all, part) => {
|
|
94
|
+
const last = all.at(-1);
|
|
95
|
+
if (typeof part === "string" && typeof last === "string") all[all.length - 1] = last + part;
|
|
96
|
+
else all.push(part);
|
|
97
|
+
return all;
|
|
98
|
+
}, []);
|
|
99
|
+
var t = (strings, ...values) => new PlacementValue(
|
|
100
|
+
joined(
|
|
101
|
+
strings.flatMap((text, index) => [
|
|
102
|
+
...partsOf(text),
|
|
103
|
+
...index < values.length ? partsOf(values[index]) : []
|
|
104
|
+
])
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
var base64 = (value2) => {
|
|
108
|
+
const inner = partsOf(value2).map((part) => {
|
|
109
|
+
if (typeof part === "object" && "base64" in part)
|
|
110
|
+
throw new TypeError("base64(...) cannot contain another base64(...).");
|
|
111
|
+
return part;
|
|
112
|
+
});
|
|
113
|
+
if (inner.length === 0) throw new TypeError("base64(...) needs a value.");
|
|
114
|
+
return new PlacementValue([{ base64: inner }]);
|
|
115
|
+
};
|
|
116
|
+
var value = (input) => {
|
|
117
|
+
const parts = partsOf(input);
|
|
118
|
+
if (parts.length === 0) throw new TypeError("A credential placement needs a value.");
|
|
119
|
+
return joined(parts);
|
|
120
|
+
};
|
|
121
|
+
var header = (name, input) => ({
|
|
122
|
+
in: "header",
|
|
123
|
+
name: name.toLowerCase(),
|
|
124
|
+
value: value(input)
|
|
125
|
+
});
|
|
126
|
+
var query = (name, input) => ({
|
|
127
|
+
in: "query",
|
|
128
|
+
name,
|
|
129
|
+
value: value(input)
|
|
130
|
+
});
|
|
131
|
+
var bearer = (token) => header("authorization", t`Bearer ${token}`);
|
|
132
|
+
var basic = (user, password) => header("authorization", t`Basic ${base64(t`${user}:${password}`)}`);
|
|
133
|
+
var declarePlacements = (method2, names, exposure, request) => {
|
|
134
|
+
const declared = new Set(names);
|
|
135
|
+
const refs = new Proxy(Object.fromEntries(names.map((name) => [name, new FieldRef(name)])), {
|
|
136
|
+
get: (target, key) => {
|
|
137
|
+
if (typeof key === "string" && !declared.has(key))
|
|
138
|
+
throw new TypeError(
|
|
139
|
+
`The ${method2} request references "${key}", which is not one of its fields: ${names.join(", ")}.`
|
|
140
|
+
);
|
|
141
|
+
return Reflect.get(target, key);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
const returned = request(refs);
|
|
145
|
+
const placements = Array.isArray(returned) ? returned : [returned];
|
|
146
|
+
if (placements.length === 0) throw new TypeError(`The ${method2} request declares no placements.`);
|
|
147
|
+
if (!placements.every(Schema_exports.is(Placement)))
|
|
148
|
+
throw new TypeError(
|
|
149
|
+
`The ${method2} request must return header(...) or query(...) placements, or an array of them.`
|
|
150
|
+
);
|
|
151
|
+
for (const placement of placements) {
|
|
152
|
+
const fields = placementFields(placement);
|
|
153
|
+
for (const field of fields) {
|
|
154
|
+
if (!declared.has(field))
|
|
155
|
+
throw new TypeError(
|
|
156
|
+
`The ${method2} request references "${field}", which is not one of its fields: ${names.join(", ")}.`
|
|
157
|
+
);
|
|
158
|
+
if (exposure?.[field] === "raw")
|
|
159
|
+
throw new TypeError(
|
|
160
|
+
`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.`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
if (![...fields].some((field) => exposure?.[field] === void 0))
|
|
164
|
+
throw new TypeError(
|
|
165
|
+
`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().`
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
return normalizePlacements(placements);
|
|
169
|
+
};
|
|
170
|
+
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().`;
|
|
171
|
+
var withPlacements = (account, placements) => {
|
|
172
|
+
const fields = typeof account.fields === "object" && account.fields !== null ? account.fields : {};
|
|
173
|
+
const render = (placement) => Result_exports.getOrThrowWith(
|
|
174
|
+
renderPlacement(placement, fields),
|
|
175
|
+
(error) => new TypeError(error.message)
|
|
176
|
+
);
|
|
177
|
+
const declared = () => {
|
|
178
|
+
if (placements === void 0 || placements.length === 0)
|
|
179
|
+
throw new TypeError(undeclared(account.method));
|
|
180
|
+
return placements;
|
|
181
|
+
};
|
|
182
|
+
return Object.defineProperties(account, {
|
|
183
|
+
headers: {
|
|
184
|
+
enumerable: false,
|
|
185
|
+
value: () => Object.fromEntries(
|
|
186
|
+
declared().filter((placement) => placement.in === "header").map((placement) => [placement.name, render(placement)])
|
|
187
|
+
)
|
|
188
|
+
},
|
|
189
|
+
url: {
|
|
190
|
+
enumerable: false,
|
|
191
|
+
value: (input) => {
|
|
192
|
+
const url = new URL(input);
|
|
193
|
+
for (const placement of declared())
|
|
194
|
+
if (placement.in === "query") url.searchParams.set(placement.name, render(placement));
|
|
195
|
+
return url.href;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/implementation/workflows.ts
|
|
202
|
+
var NativeWorkflow = /* @__PURE__ */ Symbol("apps.Workflow");
|
|
203
|
+
var workflow = (options, run) => ({
|
|
204
|
+
[NativeWorkflow]: {
|
|
205
|
+
input: decoderOf(schemaArgument(options.input, "The workflow input")),
|
|
206
|
+
...options.output === void 0 ? {} : { output: decoderOf(schemaArgument(options.output, "The workflow output")) },
|
|
207
|
+
...options.description === void 0 ? {} : { description: options.description },
|
|
208
|
+
// SAFETY: defineApp checks required context; the host supplies the pinned run's capabilities.
|
|
209
|
+
run: (context, input) => fromPromise(run, "workflow")(context, input)
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
var nativeWorkflow = (value2) => {
|
|
213
|
+
if (typeof value2 !== "object" || value2 === null || !(NativeWorkflow in value2)) return void 0;
|
|
214
|
+
return value2[NativeWorkflow];
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/implementation/events.ts
|
|
218
|
+
var Native = /* @__PURE__ */ Symbol("apps.Event");
|
|
219
|
+
var scalarTypes = /* @__PURE__ */ new Set(["string", "number", "integer", "boolean"]);
|
|
220
|
+
var isScalarSchema = (document) => {
|
|
221
|
+
const type = document.type;
|
|
222
|
+
if (typeof type === "string") return scalarTypes.has(type);
|
|
223
|
+
const choices = Array.isArray(document.enum) ? document.enum : "const" in document ? [document.const] : void 0;
|
|
224
|
+
return choices !== void 0 && choices.length > 0 && choices.every((value2) => ["string", "number", "boolean"].includes(typeof value2));
|
|
225
|
+
};
|
|
226
|
+
var event = (options) => {
|
|
227
|
+
const filters = options.filters ?? {};
|
|
228
|
+
const fieldDecoders = Object.fromEntries(
|
|
229
|
+
Object.entries(filters).map(([key, field]) => [
|
|
230
|
+
key,
|
|
231
|
+
decoderOf(schemaArgument(field, `The event filter ${JSON.stringify(key)}`))
|
|
232
|
+
])
|
|
233
|
+
);
|
|
234
|
+
for (const [key, decoder] of Object.entries(fieldDecoders)) {
|
|
235
|
+
const document = Effect_exports.runSync(jsonSchemaDocument(decoder));
|
|
236
|
+
if (!isScalarSchema(document))
|
|
237
|
+
throw new TypeError(
|
|
238
|
+
`The event filter ${JSON.stringify(key)} must be a string, number, boolean or literal`
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
[Native]: {
|
|
243
|
+
description: options.description,
|
|
244
|
+
filters: fieldDecoders,
|
|
245
|
+
payload: decoderOf(schemaArgument(options.payload, "The event payload"))
|
|
246
|
+
},
|
|
247
|
+
description: options.description,
|
|
248
|
+
filters,
|
|
249
|
+
payload: options.payload
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
var nativeEvent = (declaration) => typeof declaration === "object" && declaration !== null && Native in declaration ? declaration[Native] : void 0;
|
|
253
|
+
var declaredEvents = (events) => Effect_exports.forEach(
|
|
254
|
+
Object.entries(events),
|
|
255
|
+
([name, declared]) => Effect_exports.gen(function* () {
|
|
256
|
+
const filters = yield* jsonSchemaDocument(Schema_exports.Struct(declared.filters));
|
|
257
|
+
const payload = yield* jsonSchemaDocument(declared.payload);
|
|
258
|
+
return [name, { description: declared.description, filters, payload }];
|
|
259
|
+
})
|
|
260
|
+
).pipe(Effect_exports.map((entries) => Object.fromEntries(entries)));
|
|
261
|
+
var makeEmitter = (input) => ({
|
|
262
|
+
emit: (name, data, ...rest) => {
|
|
263
|
+
const options = rest[0] ?? {};
|
|
264
|
+
const declared = Object.hasOwn(input.events, name) ? input.events[name] : void 0;
|
|
265
|
+
if (declared === void 0) throw new TypeError(`This app declares no event named "${name}"`);
|
|
266
|
+
if (input.emitted.length >= defaultEventLimits.maxEventsPerInvocation)
|
|
267
|
+
throw new RangeError(
|
|
268
|
+
`An invocation can emit at most ${defaultEventLimits.maxEventsPerInvocation} events`
|
|
269
|
+
);
|
|
270
|
+
const payload = Schema_exports.decodeUnknownSync(declared.payload)(data);
|
|
271
|
+
const filters = Schema_exports.decodeUnknownSync(Schema_exports.Struct(declared.filters))(
|
|
272
|
+
options.filters ?? {}
|
|
273
|
+
);
|
|
274
|
+
const account = options.account ?? input.sourceAccount ?? (input.attributable.length === 1 ? input.attributable[0] : void 0) ?? null;
|
|
275
|
+
if (account === null && input.attributable.length > 1)
|
|
276
|
+
throw new TypeError(
|
|
277
|
+
"This invocation has several accounts; name the one the event came from with { account }"
|
|
278
|
+
);
|
|
279
|
+
if (account !== null && !input.accounts.includes(account))
|
|
280
|
+
throw new TypeError("The event's account is not one of this invocation's accounts");
|
|
281
|
+
const occurredAt = options.occurredAt === void 0 ? Date.now() : options.occurredAt instanceof Date ? options.occurredAt.getTime() : options.occurredAt;
|
|
282
|
+
const occurrence = Schema_exports.decodeUnknownSync(EmittedEvent)({
|
|
283
|
+
name: Schema_exports.decodeUnknownSync(EventName)(name),
|
|
284
|
+
id: options.id ?? crypto.randomUUID(),
|
|
285
|
+
occurredAt,
|
|
286
|
+
data: payload,
|
|
287
|
+
filters,
|
|
288
|
+
account
|
|
289
|
+
});
|
|
290
|
+
if (new TextEncoder().encode(JSON.stringify(occurrence.data)).byteLength > defaultEventLimits.maxDataBytes)
|
|
291
|
+
throw new RangeError(
|
|
292
|
+
`An event's data can be at most ${defaultEventLimits.maxDataBytes} bytes of JSON; send a summary and a tool to read the rest`
|
|
293
|
+
);
|
|
294
|
+
input.emitted.push(occurrence);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// src/implementation/app.ts
|
|
299
|
+
var InternalApp = /* @__PURE__ */ Symbol("apps.App");
|
|
300
|
+
var isApp = (value2) => typeof value2 === "object" && value2 !== null && InternalApp in value2;
|
|
301
|
+
var toEffectApp = (app) => app[InternalApp];
|
|
302
|
+
function rejectCatalogs(definition) {
|
|
303
|
+
if ("queries" in definition || "mutations" in definition)
|
|
304
|
+
throw new Error("Put queries and mutations in a router under tools");
|
|
305
|
+
}
|
|
306
|
+
function adaptDefinition(definition) {
|
|
307
|
+
rejectCatalogs(definition);
|
|
308
|
+
const webhooks = definition.webhooks === void 0 ? {} : {
|
|
309
|
+
// SAFETY: `Required` only where the optional method was just checked to be present.
|
|
310
|
+
webhooks: Object.fromEntries(
|
|
311
|
+
Object.entries(definition.webhooks).map(([name, webhook]) => [
|
|
312
|
+
name,
|
|
313
|
+
{
|
|
314
|
+
...webhook,
|
|
315
|
+
...webhook.register === void 0 ? {} : {
|
|
316
|
+
register: fromPromise(
|
|
317
|
+
method(webhook, "register"),
|
|
318
|
+
"webhook"
|
|
319
|
+
)
|
|
320
|
+
},
|
|
321
|
+
handle: fromPromise(method(webhook, "handle"), "webhook"),
|
|
322
|
+
...webhook.unregister === void 0 ? {} : {
|
|
323
|
+
unregister: fromPromise(
|
|
324
|
+
method(webhook, "unregister"),
|
|
325
|
+
"webhook"
|
|
326
|
+
)
|
|
327
|
+
},
|
|
328
|
+
..."config" in webhook && isSchema(webhook.config) ? { config: decoderOf(webhook.config) } : {},
|
|
329
|
+
..."state" in webhook && isSchema(webhook.state) ? { state: decoderOf(webhook.state) } : {}
|
|
330
|
+
}
|
|
331
|
+
])
|
|
332
|
+
)
|
|
333
|
+
};
|
|
334
|
+
const workflows = definition.workflows === void 0 ? {} : {
|
|
335
|
+
workflows: Object.fromEntries(
|
|
336
|
+
Object.entries(definition.workflows).map(([name, value2]) => {
|
|
337
|
+
const declared2 = nativeWorkflow(value2);
|
|
338
|
+
if (declared2 === void 0) throw new Error("Invalid workflow declaration");
|
|
339
|
+
return [name, declared2];
|
|
340
|
+
})
|
|
341
|
+
)
|
|
342
|
+
};
|
|
343
|
+
const root = definition.tools === void 0 ? void 0 : nativeRouter(definition.tools);
|
|
344
|
+
if (definition.tools !== void 0 && root === void 0)
|
|
345
|
+
throw new Error("tools must be a router");
|
|
346
|
+
const data = root === void 0 ? {} : { tools: root };
|
|
347
|
+
const declared = root?.kind === "router" ? declaredOperations(root) : [];
|
|
348
|
+
const mutations = /* @__PURE__ */ new Set();
|
|
349
|
+
for (const { operation } of declared) {
|
|
350
|
+
if (operation.kind !== "mutation") continue;
|
|
351
|
+
if (mutations.has(operation))
|
|
352
|
+
throw new Error("A mutation can be mounted at only one path in tools");
|
|
353
|
+
mutations.add(operation);
|
|
354
|
+
}
|
|
355
|
+
const schedules = definition.schedules === void 0 ? {} : {
|
|
356
|
+
schedules: Object.fromEntries(
|
|
357
|
+
Object.entries(definition.schedules).map(([name, schedule]) => {
|
|
358
|
+
const target = nativeOperation(schedule.operation);
|
|
359
|
+
const match = declared.find(
|
|
360
|
+
({ operation }) => operation === target && operation.kind === "mutation"
|
|
361
|
+
);
|
|
362
|
+
if (match === void 0)
|
|
363
|
+
throw new Error("A schedule must reference a mutation in this app's tools");
|
|
364
|
+
if (schedule.scope === "app" && match.operation.approval !== void 0)
|
|
365
|
+
throw new Error("An app schedule must reference a mutation without an approval");
|
|
366
|
+
return [
|
|
367
|
+
name,
|
|
368
|
+
{
|
|
369
|
+
...schedule.scope === "app" ? { scope: "app" } : {},
|
|
370
|
+
timing: Schema_exports.decodeUnknownSync(ScheduleTiming)(schedule.timing),
|
|
371
|
+
input: Schema_exports.decodeUnknownSync(JsonValue)(schedule.input),
|
|
372
|
+
tool: match.name
|
|
373
|
+
}
|
|
374
|
+
];
|
|
375
|
+
})
|
|
376
|
+
)
|
|
377
|
+
};
|
|
378
|
+
return {
|
|
379
|
+
...definition,
|
|
380
|
+
...webhooks,
|
|
381
|
+
...workflows,
|
|
382
|
+
...data,
|
|
383
|
+
...schedules
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function scopedSlots(requirements) {
|
|
387
|
+
if ("accounts" in requirements)
|
|
388
|
+
throw new TypeError(
|
|
389
|
+
"Declare account requirements by scope: user: { accounts } for each caller's accounts, app: { accounts } for the app's own"
|
|
390
|
+
);
|
|
391
|
+
const app = requirements.app?.accounts ?? {};
|
|
392
|
+
const user = requirements.user?.accounts ?? {};
|
|
393
|
+
for (const name of Object.keys(app))
|
|
394
|
+
if (Object.hasOwn(user, name))
|
|
395
|
+
throw new TypeError(
|
|
396
|
+
`The requirement ${JSON.stringify(name)} is declared as both an app and a user account; name them differently`
|
|
397
|
+
);
|
|
398
|
+
return { app, user };
|
|
399
|
+
}
|
|
400
|
+
var defineApp = (requirements, definition) => {
|
|
401
|
+
const accounts = scopedSlots(requirements);
|
|
402
|
+
if (typeof definition !== "function") rejectCatalogs(definition);
|
|
403
|
+
const evaluate = typeof definition === "function" ? definition : async () => definition;
|
|
404
|
+
const factory = fromPromise(evaluate, "factory");
|
|
405
|
+
const events = requirements.events === void 0 ? void 0 : Object.fromEntries(
|
|
406
|
+
Object.entries(requirements.events).map(([name, declared]) => {
|
|
407
|
+
const native2 = nativeEvent(declared);
|
|
408
|
+
if (native2 === void 0)
|
|
409
|
+
throw new TypeError(
|
|
410
|
+
`The event ${JSON.stringify(name)} must be declared with event()`
|
|
411
|
+
);
|
|
412
|
+
return [name, native2];
|
|
413
|
+
})
|
|
414
|
+
);
|
|
415
|
+
const iconsProblem = requirements.icons === void 0 ? void 0 : appIconsProblem(requirements.icons);
|
|
416
|
+
if (iconsProblem !== void 0)
|
|
417
|
+
throw new TypeError(`The app's icons are invalid: ${iconsProblem}`);
|
|
418
|
+
const native = {
|
|
419
|
+
accounts,
|
|
420
|
+
...events === void 0 ? {} : { events },
|
|
421
|
+
...requirements.icons === void 0 || requirements.icons.length === 0 ? {} : { icons: requirements.icons },
|
|
422
|
+
evaluate: (context) => factory(context).pipe(Effect_exports.map((value2) => adaptDefinition(value2)))
|
|
423
|
+
};
|
|
424
|
+
return {
|
|
425
|
+
[InternalApp]: native,
|
|
426
|
+
accounts: native.accounts,
|
|
427
|
+
evaluate: (context) => Effect_exports.runPromise(factory(context))
|
|
428
|
+
};
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
export {
|
|
432
|
+
ResponseStatusError,
|
|
433
|
+
ResponseDecodeError,
|
|
434
|
+
t,
|
|
435
|
+
base64,
|
|
436
|
+
header,
|
|
437
|
+
query,
|
|
438
|
+
bearer,
|
|
439
|
+
basic,
|
|
440
|
+
declarePlacements,
|
|
441
|
+
withPlacements,
|
|
442
|
+
workflow,
|
|
443
|
+
event,
|
|
444
|
+
declaredEvents,
|
|
445
|
+
makeEmitter,
|
|
446
|
+
isApp,
|
|
447
|
+
toEffectApp,
|
|
448
|
+
defineApp
|
|
449
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Schema_exports
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IFJU5SYQ.js";
|
|
4
4
|
|
|
5
5
|
// src/contracts/schema.ts
|
|
6
6
|
var JsonValue = Schema_exports.Json;
|
|
7
7
|
var JsonObject = Schema_exports.Record(Schema_exports.String, JsonValue);
|
|
8
8
|
var AccountId = Schema_exports.String.pipe(
|
|
9
|
-
Schema_exports.check(Schema_exports.
|
|
9
|
+
Schema_exports.check(Schema_exports.isStartingWith("acc_"), Schema_exports.isMinLength(5)),
|
|
10
10
|
Schema_exports.brand("acc")
|
|
11
11
|
);
|
|
12
12
|
var HttpUrl = Schema_exports.String.check(
|
|
@@ -19,6 +19,21 @@ var HttpUrl = Schema_exports.String.check(
|
|
|
19
19
|
}
|
|
20
20
|
})
|
|
21
21
|
);
|
|
22
|
+
var DeclarationIssue = Schema_exports.Struct({
|
|
23
|
+
path: Schema_exports.Array(Schema_exports.String),
|
|
24
|
+
message: Schema_exports.String
|
|
25
|
+
});
|
|
26
|
+
var DeclarationInvalid = class extends Schema_exports.TaggedError()(
|
|
27
|
+
"DeclarationInvalid",
|
|
28
|
+
{ declaration: Schema_exports.String, issues: Schema_exports.Array(DeclarationIssue) }
|
|
29
|
+
) {
|
|
30
|
+
get message() {
|
|
31
|
+
const problems = this.issues.map(
|
|
32
|
+
(issue) => issue.path.length === 0 ? issue.message : `${issue.path.join(".")}: ${issue.message}`
|
|
33
|
+
);
|
|
34
|
+
return `The ${this.declaration} declaration is invalid. ${problems.join("; ")}`;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
22
37
|
var ValidationError = class extends Schema_exports.TaggedError()("ValidationError", {}) {
|
|
23
38
|
get message() {
|
|
24
39
|
return "Value did not match the schema";
|
|
@@ -30,5 +45,6 @@ export {
|
|
|
30
45
|
JsonObject,
|
|
31
46
|
AccountId,
|
|
32
47
|
HttpUrl,
|
|
48
|
+
DeclarationInvalid,
|
|
33
49
|
ValidationError
|
|
34
50
|
};
|