apps 0.0.1-beta.46 → 0.0.1-beta.48

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 (32) hide show
  1. package/framework-reference.json +1 -1
  2. package/js/{chunk-XK5I2XOI.js → chunk-D45JTD6N.js} +2 -2
  3. package/js/{chunk-3B2JAOSE.js → chunk-GDYPM7RS.js} +102 -3
  4. package/js/{chunk-CVAJ4F6O.js → chunk-JY56GVSV.js} +81 -3
  5. package/js/{chunk-OJ47HQVJ.js → chunk-PO5NPRFT.js} +67 -14
  6. package/js/{chunk-7LGRK7TP.js → chunk-QKHTRD6G.js} +2 -2
  7. package/js/{chunk-3UGDI2UI.js → chunk-SVHI6AKV.js} +2 -2
  8. package/js/{chunk-LHCGND3R.js → chunk-X5U5KIWQ.js} +1 -1
  9. package/js/{chunk-6QXPBJ5T.js → chunk-YQD2MLFY.js} +2 -2
  10. package/js/contracts.js +19 -1
  11. package/js/effect.js +5 -5
  12. package/js/graphql.js +6 -6
  13. package/js/host.js +5 -5
  14. package/js/index.js +6 -4
  15. package/js/mcp/effect.js +7 -7
  16. package/js/mcp/stdio.js +7 -7
  17. package/js/mcp.js +8 -8
  18. package/js/openapi.js +4 -4
  19. package/package.json +1 -1
  20. package/runtime.json +1 -1
  21. package/types/apps/src/contracts/app.d.ts +2 -0
  22. package/types/apps/src/contracts/context.d.ts +8 -1
  23. package/types/apps/src/contracts/events.d.ts +93 -0
  24. package/types/apps/src/contracts/host.d.ts +6 -4
  25. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  26. package/types/apps/src/contracts/protocols/11.d.ts +1098 -0
  27. package/types/apps/src/implementation/account-router.d.ts +4 -3
  28. package/types/apps/src/implementation/events.d.ts +59 -0
  29. package/types/apps/src/implementation/operations.d.ts +5 -0
  30. package/types/apps/src/implementation/router.d.ts +7 -5
  31. package/types/apps/src/implementation/sql.d.ts +5 -0
  32. package/types/apps/src/index.d.ts +3 -1
@@ -57,6 +57,8 @@ export interface BoundContext<Slots extends AccountSlots> {
57
57
  /** The host evaluates this factory fresh with the configured app's selected accounts. */
58
58
  export interface App<Slots extends AccountSlots, Def extends AppDefinition<never>> {
59
59
  readonly accounts: Slots;
60
+ /** Declared beside the accounts, so a host lists them without evaluating the app. */
61
+ readonly events?: Readonly<Record<string, import("./events.js").AppEvent>>;
60
62
  readonly evaluate: (context: BoundContext<Slots>) => Effect.Effect<Def, unknown>;
61
63
  }
62
64
  declare const NotImplemented_base: Schema.Class<NotImplemented, Schema.TaggedStruct<"NotImplemented", {
@@ -2,10 +2,17 @@
2
2
  import type { WorkflowControls } from "./workflows.js";
3
3
  import type { AccountSlots, BoundContext } from "./app.js";
4
4
  import type { Sql, SqlReader } from "./sql.js";
5
+ import type { AnyEventDeclaration, EventEmitter } from "../implementation/events.js";
5
6
  /** Requirements are pure values; selected accounts and SQL access belong to invocations. */
6
7
  export interface AppRequirements {
7
8
  readonly accounts: AccountSlots;
9
+ /** Events this app emits, by name, such as `issue.opened`. */
10
+ readonly events?: Readonly<Record<string, AnyEventDeclaration>>;
8
11
  }
12
+ /** The emitter for an app's declared events. */
13
+ type EventsContext<Requirements extends AppRequirements> = {
14
+ readonly events: EventEmitter<NonNullable<Requirements["events"]>>;
15
+ };
9
16
  /**
10
17
  * Every handler has `ctx.sql`. The app's database exists once the build has SQL files in
11
18
  * `migrations/`; before that, any statement fails and says so.
@@ -20,7 +27,7 @@ export type QueryContext<Requirements extends AppRequirements = AppRequirements>
20
27
  /** Interactive mutation context; outside calls happen between SQL transactions, never inside one. */
21
28
  export type MutationContext<Requirements extends AppRequirements = AppRequirements> = Omit<AppContext<Requirements>, "workflows"> & {
22
29
  readonly workflows: WorkflowControls;
23
- } & StorageContext<true>;
30
+ } & StorageContext<true> & EventsContext<Requirements>;
24
31
  /** Background webhook context has account and storage access without interactive input. */
25
32
  export type WebhookContext<Requirements extends AppRequirements = AppRequirements> = Omit<MutationContext<Requirements>, "elicit">;
26
33
  export {};
@@ -0,0 +1,93 @@
1
+ /**
2
+ * App events. An app declares the events it emits beside its account requirements, so a host
3
+ * reads them without evaluating the app. Handlers emit occurrences; the host keeps them only
4
+ * when the invocation that emitted them succeeds, then delivers them to its subscribers.
5
+ */
6
+ import { Schema } from "effect";
7
+ /** Dotted lower-case words, such as `issue.opened`. Hosts prefix them with the app's slug. */
8
+ export declare const EventName: Schema.String;
9
+ export type EventName = typeof EventName.Type;
10
+ /** A filter value: subscribers match an occurrence by equal scalars. */
11
+ export declare const EventFilterValue: Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>;
12
+ export type EventFilterValue = typeof EventFilterValue.Type;
13
+ /** Size and count limits for events; bytes are UTF-8 bytes of the JSON text. */
14
+ export declare const EventLimits: Schema.Struct<{
15
+ /** An occurrence's `data`, leaving room under a 256 KiB delivery for its envelope. */
16
+ readonly maxDataBytes: Schema.Int;
17
+ readonly maxEventsPerInvocation: Schema.Int;
18
+ readonly maxDescriptionLength: Schema.Int;
19
+ readonly maxIdLength: Schema.Int;
20
+ }>;
21
+ export type EventLimits = typeof EventLimits.Type;
22
+ export declare const defaultEventLimits: {
23
+ readonly maxDataBytes: number;
24
+ readonly maxEventsPerInvocation: number;
25
+ readonly maxDescriptionLength: number;
26
+ readonly maxIdLength: number;
27
+ };
28
+ /** One event as the host reads it from an app's requirements. Both schemas are JSON Schema. */
29
+ export declare const DeclaredEvent: Schema.Struct<{
30
+ readonly description: Schema.String;
31
+ /** An object of scalar fields. Subscribers may name any of them to narrow an event. */
32
+ readonly filters: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
33
+ /** The shape of each occurrence's `data`. */
34
+ readonly payload: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
35
+ }>;
36
+ export type DeclaredEvent = typeof DeclaredEvent.Type;
37
+ /** An app's declared events, by name. */
38
+ export declare const DeclaredEvents: Schema.$Record<Schema.String, Schema.Struct<{
39
+ readonly description: Schema.String;
40
+ /** An object of scalar fields. Subscribers may name any of them to narrow an event. */
41
+ readonly filters: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
42
+ /** The shape of each occurrence's `data`. */
43
+ readonly payload: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
44
+ }>>;
45
+ export type DeclaredEvents = typeof DeclaredEvents.Type;
46
+ /**
47
+ * One occurrence an invocation emitted. `id` is the stable identifier subscribers deduplicate on,
48
+ * such as the provider's delivery ID. `account` is the account the event came from, or null for
49
+ * an app without accounts.
50
+ */
51
+ export declare const EmittedEvent: Schema.Struct<{
52
+ readonly name: Schema.String;
53
+ readonly id: Schema.String;
54
+ /** Milliseconds since the epoch when the event happened. */
55
+ readonly occurredAt: Schema.Int;
56
+ readonly data: Schema.Codec<Schema.Json, Schema.Json, never, never>;
57
+ readonly filters: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>;
58
+ readonly account: Schema.NullOr<Schema.brand<Schema.String, "acc">>;
59
+ }>;
60
+ export type EmittedEvent = typeof EmittedEvent.Type;
61
+ /** What a successful invocation emitted, in order. */
62
+ export declare const EmittedEvents: Schema.$Array<Schema.Struct<{
63
+ readonly name: Schema.String;
64
+ readonly id: Schema.String;
65
+ /** Milliseconds since the epoch when the event happened. */
66
+ readonly occurredAt: Schema.Int;
67
+ readonly data: Schema.Codec<Schema.Json, Schema.Json, never, never>;
68
+ readonly filters: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean]>>;
69
+ readonly account: Schema.NullOr<Schema.brand<Schema.String, "acc">>;
70
+ }>>;
71
+ /** Native event declaration. Filters are named scalar fields; the payload is any JSON schema. */
72
+ export interface AppEvent {
73
+ readonly description: string;
74
+ readonly filters: Readonly<Record<string, Schema.Decoder<unknown>>>;
75
+ readonly payload: Schema.Decoder<unknown>;
76
+ }
77
+ /** Options for one emitted occurrence. */
78
+ export interface EmitOptions<Filters> {
79
+ /** Values subscribers filter on. Required when the event declares filters. */
80
+ readonly filters?: Filters;
81
+ /**
82
+ * A stable identifier, such as the provider's delivery or record ID, so a repeated delivery of
83
+ * the same upstream event is not delivered twice. Defaults to a random ID.
84
+ */
85
+ readonly id?: string | undefined;
86
+ /** When the event happened. Defaults to now. */
87
+ readonly occurredAt?: Date | number | undefined;
88
+ /**
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.
91
+ */
92
+ readonly account?: string | undefined;
93
+ }
@@ -19,6 +19,7 @@ import { ElicitationFailed, type ElicitationHandler } from "./elicitation.js";
19
19
  export { ElicitationLimits, defaultElicitationLimits, FormElicitation, ElicitationResponse, ElicitationReply, ElicitationFailed, type ElicitationHandler, ApprovalElicitation, ApprovalResponse, approvalElicitation, } from "./elicitation.js";
20
20
  export { McpClientLimits, defaultMcpClientLimits } from "./mcp.js";
21
21
  export * from "./webhook-protocol.js";
22
+ export * from "./events.js";
22
23
  export { AccountId, HttpUrl } from "./schema.js";
23
24
  export { OAuthClientAuth, OAuthSecretClientAuth, OAuthTokenRequestFormat, OAuthTokenResponse, } from "./provider.js";
24
25
  /**
@@ -36,15 +37,16 @@ export { protocol7, AccountCheckCommand, CredentialHost } from "./protocols/7.js
36
37
  export { protocol8 } from "./protocols/8.js";
37
38
  export { protocol9 } from "./protocols/9.js";
38
39
  export { protocol10, MigrateCommand, MigrateResult } from "./protocols/10.js";
40
+ export { protocol11 } from "./protocols/11.js";
39
41
  export { AccountCheckResult, AccountInfo } from "./provider.js";
40
- import { HostAccountsInvalid, HostDeclarationInvalid, HostEvaluationFailed, HostInputInvalid, HostKindMismatch, HostOperationFailed, HostOperationNotFound, HostOutputInvalid, HostRequestInvalid, HostToolApprovalRequired, HostToolBlocked, HostToolNotFound, HostToolPolicyFailed, McpError, SkillLoadFailed, SkillSources, type InvocationDeadline, ResolvedAccounts, type SkillCatalogResponse, type TrustedToolApproval } from "./protocols/10.js";
41
- export { DeclaredRequirements, HostRequest } from "./protocols/10.js";
42
+ import { HostAccountsInvalid, HostDeclarationInvalid, HostEvaluationFailed, HostInputInvalid, HostKindMismatch, HostOperationFailed, HostOperationNotFound, HostOutputInvalid, HostRequestInvalid, HostToolApprovalRequired, HostToolBlocked, HostToolNotFound, HostToolPolicyFailed, McpError, SkillLoadFailed, SkillSources, type InvocationDeadline, ResolvedAccounts, type SkillCatalogResponse, type TrustedToolApproval } from "./protocols/11.js";
43
+ export { DeclaredRequirements, HostRequest } from "./protocols/11.js";
42
44
  /**
43
45
  * The MCP and skill loader failures as they cross the host boundary. Apps throw the author-facing
44
46
  * classes from `apps/mcp` and `apps/skills`.
45
47
  */
46
- export { McpError, SkillLoadFailed } from "./protocols/10.js";
47
- export { DeclaredAuthMethod, DeclaredProvider, ResolvedAccount, ResolvedAccounts, TrustedToolApproval, InvocationDeadline, HostedTool, HostedToolSummary, HostRouterError, HostedRouter, HostedCatalog, HostedCatalogSummary, SkillSources, SkillCatalogResponse, HostRequestInvalid, HostAccountsInvalid, HostDeclarationInvalid, HostEvaluationFailed, HostOperationNotFound, HostOperationFailed, HostToolNotFound, HostKindMismatch, InputProblem, maxInputProblems, HostInputInvalid, HostToolBlocked, HostToolApprovalRequired, HostToolPolicyFailed, HostOutputInvalid, HostError, HostResponse, HostInvocation, } from "./protocols/10.js";
48
+ export { McpError, SkillLoadFailed } from "./protocols/11.js";
49
+ export { DeclaredAuthMethod, DeclaredProvider, ResolvedAccount, ResolvedAccounts, TrustedToolApproval, InvocationDeadline, HostedTool, HostedToolSummary, HostRouterError, HostedRouter, HostedCatalog, HostedCatalogSummary, SkillSources, SkillCatalogResponse, HostRequestInvalid, HostAccountsInvalid, HostDeclarationInvalid, HostEvaluationFailed, HostOperationNotFound, HostOperationFailed, HostToolNotFound, HostKindMismatch, InputProblem, maxInputProblems, HostInputInvalid, HostToolBlocked, HostToolApprovalRequired, HostToolPolicyFailed, HostOutputInvalid, HostError, HostResponse, HostInvocation, } from "./protocols/11.js";
48
50
  /** Raw host inputs; the host boundary parses and redacts these immediately. */
49
51
  export type ResolvedAccountsInput = typeof ResolvedAccounts.Encoded;
50
52
  /** Trusted invocation context, supplied separately from the Request. */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The host protocol this framework speaks. It is written into `runtime.json` and every host
3
- * snapshot. Released protocols are frozen: see `protocols/10.ts` and notes/apps-publishing.md.
3
+ * snapshot. Released protocols are frozen: see `protocols/11.ts` and notes/apps-publishing.md.
4
4
  * This file has no imports so the package build script can read it directly.
5
5
  */
6
- export declare const frameworkProtocol = 10;
6
+ export declare const frameworkProtocol = 11;