apps 0.0.1-beta.89 → 0.0.1-beta.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +27 -10
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-H6NFR354.js → chunk-36UFTECB.js} +6 -8
  4. package/js/{chunk-I46RIOKQ.js → chunk-5MDA7MKL.js} +14 -13
  5. package/js/{chunk-NQW2E44U.js → chunk-6XQLA5NC.js} +579 -81
  6. package/js/{chunk-6FUJH3T4.js → chunk-7PHHWYV4.js} +6 -5
  7. package/js/{chunk-7Z3NUCTP.js → chunk-DADXWWRZ.js} +24 -6
  8. package/js/{chunk-BZFFXNWA.js → chunk-I5C7FD5Z.js} +1 -1
  9. package/js/{chunk-EKZLPXHK.js → chunk-KUCCHNVY.js} +3 -3
  10. package/js/{chunk-ZK7JDZJS.js → chunk-PYQLOLOC.js} +2 -2
  11. package/js/{chunk-ELSILABS.js → chunk-WMD4NHXZ.js} +113 -73
  12. package/js/{chunk-JJH3MBAM.js → chunk-YNJ5CZMJ.js} +3 -2
  13. package/js/{chunk-5ZVAYXLT.js → chunk-YRGL4QEF.js} +1 -1
  14. package/js/{chunk-GLXEYET6.js → chunk-YWFUWTUJ.js} +12 -7
  15. package/js/client.js +1 -1
  16. package/js/contracts.js +37 -25
  17. package/js/effect.js +8 -9
  18. package/js/graphql.js +10 -11
  19. package/js/host.js +11 -13
  20. package/js/index.js +29 -31
  21. package/js/mcp/effect.js +9 -10
  22. package/js/mcp.js +11 -12
  23. package/js/openapi.js +9 -11
  24. package/js/skills.js +6 -6
  25. package/js/ui/contracts.js +1 -1
  26. package/js/ui/serving.js +5 -6
  27. package/package.json +1 -1
  28. package/runtime.json +1 -1
  29. package/types/apps/src/contracts/app.d.ts +51 -8
  30. package/types/apps/src/contracts/cache.d.ts +1 -1
  31. package/types/apps/src/contracts/context.d.ts +37 -8
  32. package/types/apps/src/contracts/events.d.ts +2 -1
  33. package/types/apps/src/contracts/host.d.ts +800 -4
  34. package/types/apps/src/contracts/operations.d.ts +6 -3
  35. package/types/apps/src/contracts/protocol-version.d.ts +1 -1
  36. package/types/apps/src/contracts/protocols/11.d.ts +1149 -0
  37. package/types/apps/src/contracts/protocols/12.d.ts +3310 -0
  38. package/types/apps/src/contracts/protocols/current.d.ts +4445 -1633
  39. package/types/apps/src/contracts/schedules.d.ts +7 -1
  40. package/types/apps/src/contracts/ui.d.ts +11 -15
  41. package/types/apps/src/contracts/webhooks.d.ts +24 -7
  42. package/types/apps/src/contracts/workflows.d.ts +13 -17
  43. package/types/apps/src/implementation/app.d.ts +41 -14
  44. package/types/apps/src/implementation/cache.d.ts +1 -1
  45. package/types/apps/src/implementation/events.d.ts +6 -1
  46. package/types/apps/src/implementation/failure-detail.d.ts +3 -2
  47. package/types/apps/src/implementation/operations.d.ts +40 -5
  48. package/types/apps/src/implementation/router-catalog.d.ts +4 -0
  49. package/types/apps/src/implementation/schedules.d.ts +39 -8
  50. package/types/apps/src/implementation/ui-serving.d.ts +2 -2
  51. package/types/apps/src/implementation/webhooks.d.ts +15 -6
  52. package/types/apps/src/implementation/workflow-context.d.ts +6 -2
  53. package/types/apps/src/implementation/workflows.d.ts +10 -3
  54. package/types/apps/src/index.d.ts +15 -9
  55. package/js/chunk-F2G534HD.js +0 -285
@@ -20,7 +20,7 @@ export interface AppDefinition<Context> {
20
20
  readonly tool: string;
21
21
  }>>;
22
22
  readonly webhooks?: Readonly<Record<string, {
23
- readonly account: string;
23
+ readonly account: WebhookAccount;
24
24
  readonly config: Schema.Decoder<unknown>;
25
25
  readonly state: Schema.Decoder<unknown>;
26
26
  readonly setup?: import("./webhook-protocol.js").ManualWebhookSetup;
@@ -29,11 +29,35 @@ export interface AppDefinition<Context> {
29
29
  readonly unregister?: Handler<Context>;
30
30
  }>>;
31
31
  }
32
+ /**
33
+ * Whose accounts a requirement or context names. App accounts are linked for everyone by the app's
34
+ * managers and fill the requirement for every caller and for the app's background work; user
35
+ * accounts are the caller's own links. App-scope work, such as an app schedule, has no caller.
36
+ */
37
+ export type AccountScope = "app" | "user";
38
+ /** The requirement a webhook's source account fills, in its scope. */
39
+ export type WebhookAccount = {
40
+ readonly app: string;
41
+ } | {
42
+ readonly user: string;
43
+ };
32
44
  /** Named requirements for one account or a collection from a provider. */
33
45
  export type AccountSlots = Readonly<Record<string, Provider<AuthMethods> | ManyAccounts<AuthMethods>>>;
46
+ /**
47
+ * An app's requirements by scope. A requirement name is unique across both scopes, so a host can
48
+ * name one requirement without its scope.
49
+ */
50
+ export interface ScopedSlots {
51
+ readonly app: AccountSlots;
52
+ readonly user: AccountSlots;
53
+ }
34
54
  type AccountsFor<Slot> = Slot extends ManyAccounts<infer Auth> ? readonly AccountOf<Provider<Auth>>[] : AccountOf<Slot>;
35
- /** Current credentials for one invocation. Never retained in source or build output. */
36
- export interface BoundContext<Slots extends AccountSlots> {
55
+ /** One scope's current accounts, by requirement. */
56
+ export type BoundAccounts<Slots extends AccountSlots> = {
57
+ readonly [Slot in keyof Slots]: AccountsFor<Slots[Slot]>;
58
+ };
59
+ /** Invocation capabilities every context has, whatever its accounts. */
60
+ export interface InvocationServices {
37
61
  /** Explicit app/build-scoped caching. Account-specific loaders opt into forAccount. */
38
62
  readonly cache: import("./cache.js").AppCache;
39
63
  /** Text files retained in this deployment. Paths are package-relative, never host filesystem paths. */
@@ -50,18 +74,37 @@ export interface BoundContext<Slots extends AccountSlots> {
50
74
  readonly fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
51
75
  /** Host cancellation for this invocation. Pass it to fetch and other interruptible APIs. */
52
76
  readonly signal: AbortSignal;
53
- readonly accounts: {
54
- readonly [Slot in keyof Slots]: AccountsFor<Slots[Slot]>;
77
+ }
78
+ /** The app's own accounts, linked for everyone by its managers. Every invocation has them. */
79
+ export interface AppAccountsContext<Slots extends AccountSlots> {
80
+ readonly app: {
81
+ readonly accounts: BoundAccounts<Slots>;
82
+ };
83
+ }
84
+ /** The caller's own linked accounts. App-scope work has no caller, so it has none. */
85
+ export interface UserAccountsContext<Slots extends AccountSlots> {
86
+ readonly user: {
87
+ readonly accounts: BoundAccounts<Slots>;
55
88
  };
56
89
  }
57
- /** The host evaluates this factory fresh with the configured app's selected accounts. */
58
- export interface App<Slots extends AccountSlots, Def extends AppDefinition<never>> {
90
+ /**
91
+ * Current credentials for one invocation. Never retained in source or build output. A context of
92
+ * the `"app"` scope has no `user`: it serves work without a caller, such as an app schedule.
93
+ */
94
+ export type BoundContext<Slots extends ScopedSlots, Scope extends AccountScope = "user"> = InvocationServices & AppAccountsContext<Slots["app"]> & ([Scope] extends ["user"] ? UserAccountsContext<Slots["user"]> : unknown);
95
+ /**
96
+ * What the app factory receives: the app's accounts, and the caller's when the invocation has a
97
+ * caller. App-scope work evaluates the factory without `user`.
98
+ */
99
+ export type EvaluationContext<Slots extends ScopedSlots> = BoundContext<Slots, "app"> & Partial<UserAccountsContext<Slots["user"]>>;
100
+ /** The host evaluates this factory fresh with the invocation's accounts. */
101
+ export interface App<Slots extends ScopedSlots, Def extends AppDefinition<never>> {
59
102
  readonly accounts: Slots;
60
103
  /** Declared beside the accounts, so a host lists them without evaluating the app. */
61
104
  readonly events?: Readonly<Record<string, import("./events.js").AppEvent>>;
62
105
  /** Declared beside the accounts and checked when the module loads. */
63
106
  readonly icons?: import("./icons.js").AppIcons;
64
- readonly evaluate: (context: BoundContext<Slots>) => Effect.Effect<Def, unknown>;
107
+ readonly evaluate: (context: EvaluationContext<Slots>) => Effect.Effect<Def, unknown>;
65
108
  }
66
109
  declare const NotImplemented_base: Schema.Class<NotImplemented, Schema.TaggedStruct<"NotImplemented", {
67
110
  readonly operation: Schema.String;
@@ -52,7 +52,7 @@ export type AccountCredential<Credential extends object> = ({
52
52
  } & {
53
53
  readonly [Field in keyof Credential]?: undefined;
54
54
  }) | ({
55
- /** The selected account, as `accounts.<slot>` provides it. */
55
+ /** The selected account, as `ctx.app.accounts.<slot>` or `ctx.user.accounts.<slot>` provides it. */
56
56
  readonly account: {
57
57
  readonly id: string;
58
58
  };
@@ -1,12 +1,23 @@
1
1
  /** Public handler contexts derive capabilities from one shared requirements declaration. */
2
2
  import type { WorkflowControls } from "./workflows.js";
3
- import type { AccountSlots, BoundContext } from "./app.js";
3
+ import type { AccountScope, AccountSlots, BoundContext } from "./app.js";
4
4
  import type { Sql, SqlReader } from "./sql.js";
5
5
  import type { AnyEventDeclaration, EventEmitter } from "../implementation/events.js";
6
6
  import type { AppIcon } from "./icons.js";
7
- /** Requirements are pure values; selected accounts and SQL access belong to invocations. */
7
+ /**
8
+ * Requirements are pure values; bound accounts and SQL access belong to invocations. `app` names the
9
+ * accounts the app's managers link for every caller and for background work, `user` the accounts
10
+ * each caller links. A requirement name is used once across both.
11
+ */
8
12
  export interface AppRequirements {
9
- readonly accounts: AccountSlots;
13
+ readonly app?: {
14
+ readonly accounts: AccountSlots;
15
+ };
16
+ readonly user?: {
17
+ readonly accounts: AccountSlots;
18
+ };
19
+ /** Removed: declare `user: { accounts }` for the caller's accounts or `app: { accounts }`. */
20
+ readonly accounts?: never;
10
21
  /** Events this app emits, by name, such as `issue.opened`. */
11
22
  readonly events?: Readonly<Record<string, AnyEventDeclaration>>;
12
23
  /**
@@ -15,6 +26,15 @@ export interface AppRequirements {
15
26
  */
16
27
  readonly icons?: ReadonlyArray<AppIcon>;
17
28
  }
29
+ /** One scope's requirements; none when the app declares none in it. */
30
+ type ScopeSlots<Requirements, Scope extends AccountScope> = Scope extends keyof Requirements ? NonNullable<Requirements[Scope]> extends {
31
+ readonly accounts: infer Slots extends AccountSlots;
32
+ } ? Slots : Record<never, never> : Record<never, never>;
33
+ /** An app's requirements by scope, as contexts bind them. */
34
+ export type RequirementSlots<Requirements extends AppRequirements> = {
35
+ readonly app: ScopeSlots<Requirements, "app">;
36
+ readonly user: ScopeSlots<Requirements, "user">;
37
+ };
18
38
  /** The emitter for an app's declared events. */
19
39
  type EventsContext<Requirements extends AppRequirements> = {
20
40
  readonly events: EventEmitter<NonNullable<Requirements["events"]>>;
@@ -26,14 +46,23 @@ type EventsContext<Requirements extends AppRequirements> = {
26
46
  type StorageContext<Writable extends boolean> = {
27
47
  readonly sql: Writable extends true ? Sql : SqlReader;
28
48
  };
29
- /** Context available during dynamic app evaluation; storage opens only for handlers. */
30
- export type AppContext<Requirements extends AppRequirements = AppRequirements> = BoundContext<Requirements["accounts"]>;
49
+ /**
50
+ * Context available during dynamic app evaluation; storage opens only for handlers. `ctx.app.accounts`
51
+ * holds the app's accounts and `ctx.user.accounts` the caller's. With the `"app"` scope there is no
52
+ * `user`: app schedules and app-account webhooks run without a caller.
53
+ */
54
+ export type AppContext<Requirements extends AppRequirements = AppRequirements, Scope extends AccountScope = "user"> = BoundContext<RequirementSlots<Requirements>, Scope>;
31
55
  /** Interactive query context; declared storage exposes only read methods. */
32
- export type QueryContext<Requirements extends AppRequirements = AppRequirements> = AppContext<Requirements> & StorageContext<false>;
56
+ export type QueryContext<Requirements extends AppRequirements = AppRequirements, Scope extends AccountScope = "user"> = AppContext<Requirements, Scope> & StorageContext<false>;
33
57
  /** Interactive mutation context; outside calls happen between SQL transactions, never inside one. */
34
- export type MutationContext<Requirements extends AppRequirements = AppRequirements> = Omit<AppContext<Requirements>, "workflows"> & {
58
+ export type MutationContext<Requirements extends AppRequirements = AppRequirements, Scope extends AccountScope = "user"> = Omit<AppContext<Requirements, Scope>, "workflows"> & {
35
59
  readonly workflows: WorkflowControls;
36
60
  } & StorageContext<true> & EventsContext<Requirements>;
61
+ /**
62
+ * The context of a mutation whose handler declares no parameters. It uses no context, so it may run
63
+ * as the app, such as from an app schedule, where `user` is absent.
64
+ */
65
+ export type AnyScopeMutationContext<Requirements extends AppRequirements = AppRequirements> = MutationContext<Requirements, "app"> & Partial<Pick<MutationContext<Requirements>, "user">>;
37
66
  /** Background webhook context has account and storage access without interactive input. */
38
- export type WebhookContext<Requirements extends AppRequirements = AppRequirements> = Omit<MutationContext<Requirements>, "elicit">;
67
+ export type WebhookContext<Requirements extends AppRequirements = AppRequirements, Scope extends AccountScope = "user"> = Omit<MutationContext<Requirements, Scope>, "elicit">;
39
68
  export {};
@@ -87,7 +87,8 @@ export interface EmitOptions<Filters> {
87
87
  readonly occurredAt?: Date | number | undefined;
88
88
  /**
89
89
  * The ID of the account the event came from. A webhook handler defaults to its source account,
90
- * and an invocation with exactly one account to that account. Name it when there are several.
90
+ * and an invocation with exactly one of the caller's accounts to that account; the app's own
91
+ * accounts never count. Name it when there are several.
91
92
  */
92
93
  readonly account?: string | undefined;
93
94
  }