apps 0.0.1-beta.44 → 0.0.1-beta.46

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 (46) hide show
  1. package/framework-reference.json +1 -1
  2. package/js/{chunk-646JVUH4.js → chunk-3B2JAOSE.js} +23 -12
  3. package/js/{chunk-5SHUB37R.js → chunk-3UGDI2UI.js} +3 -3
  4. package/js/{chunk-7EBODVQJ.js → chunk-6QXPBJ5T.js} +14 -13
  5. package/js/{chunk-MGGMEGB2.js → chunk-7LGRK7TP.js} +2 -2
  6. package/js/{chunk-DZQYE626.js → chunk-7UUHJR2Q.js} +1 -1
  7. package/js/{chunk-4ZTVLEN6.js → chunk-CDXQDN7W.js} +1 -1
  8. package/js/{chunk-ELO5PRCO.js → chunk-CVAJ4F6O.js} +14 -1
  9. package/js/{chunk-CZGWW4NQ.js → chunk-JM7LOD2W.js} +187 -9
  10. package/js/{chunk-EJUK2NK5.js → chunk-KLYSEHUD.js} +1 -1
  11. package/js/{chunk-OTGUPKKK.js → chunk-LHCGND3R.js} +12 -46
  12. package/js/{chunk-EMHFXFTJ.js → chunk-LTDHQJ2Z.js} +53 -0
  13. package/js/{chunk-DRJRCHHO.js → chunk-OJ47HQVJ.js} +141 -63
  14. package/js/{chunk-MZH4J2PO.js → chunk-PD6I2SDG.js} +1 -1
  15. package/js/{chunk-KSGYJV46.js → chunk-TUMGL2OC.js} +1 -1
  16. package/js/{chunk-5GLC42LK.js → chunk-UM62MBJQ.js} +42 -24
  17. package/js/{chunk-V3RS2BK6.js → chunk-XK5I2XOI.js} +39 -29
  18. package/js/client.js +8 -8
  19. package/js/contracts.js +7 -3
  20. package/js/effect.js +11 -11
  21. package/js/graphql.js +20 -18
  22. package/js/host.js +76 -51
  23. package/js/index.js +21 -16
  24. package/js/mcp/effect.js +13 -13
  25. package/js/mcp/stdio.js +27 -22
  26. package/js/mcp.js +20 -18
  27. package/js/openapi.js +103 -77
  28. package/js/skills/effect.js +2 -2
  29. package/js/skills.js +50 -33
  30. package/js/ui/auth.js +3 -3
  31. package/js/ui/contracts.js +3 -3
  32. package/js/ui/serving.js +6 -6
  33. package/package.json +1 -1
  34. package/runtime.json +1 -1
  35. package/types/apps/src/contracts/host.d.ts +15 -0
  36. package/types/apps/src/host.d.ts +5 -0
  37. package/types/apps/src/implementation/authoring.d.ts +25 -5
  38. package/types/apps/src/implementation/cache.d.ts +4 -0
  39. package/types/apps/src/implementation/elicitation.d.ts +6 -3
  40. package/types/apps/src/implementation/invocation-timing.d.ts +16 -0
  41. package/types/apps/src/implementation/operations.d.ts +2 -2
  42. package/types/apps/src/implementation/router-catalog.d.ts +4 -4
  43. package/types/apps/src/implementation/workflows.d.ts +1 -1
  44. package/types/telemetry/src/index.d.ts +1 -0
  45. package/types/telemetry/src/ownership.d.ts +56 -0
  46. package/js/{chunk-LNSVJS2Q.js → chunk-EOPQ727L.js} +2 -2
@@ -119,6 +119,21 @@ export declare const HostDataError: Schema.Union<readonly [typeof OpenapiRespons
119
119
  export declare const ToolResultObservation: Context.Reference<{
120
120
  readonly failed: () => void;
121
121
  }>;
122
+ /**
123
+ * One tool invocation's own timing, on the isolate's clock: how long it ran, and how much of that
124
+ * it waited on upstream providers, waited on elicitation answers and ran the app's authored code.
125
+ * Each instant counts once, so the rest is Executor's own time. The isolated handler returns it
126
+ * beside the result so the host can add the other isolates' parts.
127
+ */
128
+ export declare const InvocationTiming: Schema.Struct<{
129
+ readonly elapsedMs: Schema.Finite;
130
+ readonly upstreamMs: Schema.Finite;
131
+ readonly elicitationMs: Schema.Finite;
132
+ readonly authoredMs: Schema.Finite;
133
+ }>;
134
+ export type InvocationTiming = typeof InvocationTiming.Type;
135
+ /** Receives the invocation's timing once it is over; hosts that do not return it ignore it. */
136
+ export declare const InvocationTimingSink: Context.Reference<(timing: InvocationTiming) => void>;
122
137
  /** Native handler; context comes from host authority, never from request content. */
123
138
  export type AppHandler = (request: Request, context: HostContext) => Effect.Effect<Response>;
124
139
  export { type AppOperation, type OperationContext } from "./operations.js";
@@ -6,6 +6,11 @@ export { isolatedCacheSession } from "./implementation/cache-session.js";
6
6
  export declare const hostContext: (accounts: ResolvedAccountsInput, approval?: unknown) => HostContext;
7
7
  /** Portable Promise handler. Invoke only after the host has authorized and resolved accounts. */
8
8
  export declare const createAppHandler: (app: unknown) => ((request: Request, context: HostContext) => Promise<Response>);
9
+ /**
10
+ * The clock this framework's spans read, in nanoseconds. The runtime's bridge times the isolate's
11
+ * whole dispatch with it, so that time and the invocation's own timing share one clock.
12
+ */
13
+ export declare const isolatedClock: () => bigint;
9
14
  /** Isolates return bounded, telemetry beside the protocol result; no exporter secret enters app code. */
10
15
  export declare const createIsolatedAppHandler: (app: unknown) => (request: Request, context: HostContext) => Promise<Response>;
11
16
  /**
@@ -1,12 +1,32 @@
1
1
  /** Small, explicit adapters between authored callbacks and native Effect operations. */
2
- import { Effect } from "effect";
2
+ import { Effect, type Context } from "effect";
3
3
  /** Project one Effect operation into its author-facing Promise signature. */
4
4
  export type PromiseMethod<Method> = Method extends (...args: infer Args) => Effect.Effect<infer A, infer _E> ? (...args: Args) => Promise<A> : Method;
5
5
  /** Project only an object's methods; data and schema types are not recursively rewritten. */
6
6
  export type PromiseMethods<T> = {
7
7
  readonly [Key in keyof T]: PromiseMethod<T[Key]>;
8
8
  };
9
- /** Reuse a framework callback's cancellation-bound Effect, or adapt an ordinary async callback. */
10
- export declare const fromPromise: <Args extends readonly unknown[], A>(callback: (...args: Args) => Promise<A>) => ((...args: Args) => Effect.Effect<A, unknown>);
11
- /** Bind cancellation once so Promise callers and native framework callers run the same operation. */
12
- export declare const toPromise: <Args extends readonly unknown[], A, E>(operation: (...args: Args) => Effect.Effect<A, E>, signal?: AbortSignal) => ((...args: Args) => Promise<A>);
9
+ /** Which of the app's callbacks runs, recorded on the `app.code` span around it. */
10
+ export type AppCode = "factory" | "router" | "approval" | "handler" | "loader" | "cache" | "webhook" | "check" | "skills" | "elicitation" | "workflow" | "step";
11
+ /**
12
+ * Run `effect` as the app's own code. Its time is the app's, except for work it starts for
13
+ * Executor, an upstream or a person, which opens its own boundary inside.
14
+ */
15
+ export declare const appCode: (code: AppCode) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, import("effect/Tracer").ParentSpan>>;
16
+ /**
17
+ * Reuse a framework callback's cancellation-bound Effect, or run an ordinary async callback as the
18
+ * app's code. Every callback an app supplies enters the framework here, so its time is the app's.
19
+ */
20
+ export declare const fromPromise: <Args extends readonly unknown[], A>(callback: (...args: Args) => Promise<A>, code: AppCode) => ((...args: Args) => Effect.Effect<A, unknown>);
21
+ /**
22
+ * `target[key]`, called on `target`. A method read off its object as a bare value loses its
23
+ * receiver, so an app's method, such as one of its cache's, enters `fromPromise` through this.
24
+ */
25
+ export declare const method: <K extends PropertyKey, T extends { readonly [P in K]: (...args: never) => unknown; }>(target: T, key: K) => T[K];
26
+ /**
27
+ * Bind cancellation once so Promise callers and native framework callers run the same operation.
28
+ * `signalOf` is the signal, or reads it from each call's arguments, such as a loader's `context.signal`.
29
+ */
30
+ export declare const toPromise: <Args extends readonly unknown[], A, E>(operation: (...args: Args) => Effect.Effect<A, E>, signalOf?: AbortSignal | ((...args: Args) => AbortSignal),
31
+ /** Services a Promise call runs with, such as its invocation's telemetry. */
32
+ services?: Context.Context<never>) => ((...args: Args) => Promise<A>);
@@ -1,8 +1,12 @@
1
+ /** Bind the portable Effect cache to an app invocation's author API. */
2
+ import { type Context } from "effect";
1
3
  import type { AppCache, HostCache } from "../contracts/cache.js";
2
4
  import type { ResolvedAccounts } from "../contracts/host.js";
3
5
  /** Missing host support is explicit on use; ordinary apps do not need cache support. */
4
6
  export declare const unavailableCache: HostCache;
5
7
  /** Account scopes are derived from trusted current bindings. Loaders get a fresh owned HTTP signal. */
6
8
  export declare const authorCache: (host: HostCache, accounts: ResolvedAccounts, signal: AbortSignal,
9
+ /** The invocation's telemetry, which Promise calls from authored code run in. */
10
+ telemetry: Context.Context<never>,
7
11
  /** The invocation's trusted deadline. Waiting on another caller's load never runs past it. */
8
12
  deadline?: number) => AppCache;
@@ -1,5 +1,5 @@
1
1
  /** Validate both sides of a tool's form and bind delivery to its invocation lifetime. */
2
- import { Effect, Schema } from "effect";
2
+ import { Effect, Schema, type Context } from "effect";
3
3
  import { ElicitationFailed, type ElicitationHandler, type Elicit } from "../contracts/elicitation.js";
4
4
  /** Parse a form and retain its response parser, so invalid answers can be rejected before consuming a host continuation. */
5
5
  export declare const prepareElicitation: (input: unknown) => Effect.Effect<{
@@ -99,5 +99,8 @@ export declare const prepareElicitation: (input: unknown) => Effect.Effect<{
99
99
  } | undefined;
100
100
  }, ElicitationFailed, never>;
101
101
  }, ElicitationFailed, never>;
102
- /** Bind a validated interaction to the live invocation; transport adapters share its form parser. */
103
- export declare const makeElicit: (handler: ElicitationHandler | undefined, signal: AbortSignal) => Elicit;
102
+ /**
103
+ * Bind a validated interaction to the live invocation; transport adapters share its form parser.
104
+ * Authored code's Promise calls run in the invocation's telemetry, like framework callers.
105
+ */
106
+ export declare const makeElicit: (handler: ElicitationHandler | undefined, signal: AbortSignal, telemetry: Context.Context<never>) => Elicit;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Divide a tool invocation's time, on its own isolate's clock, by who the work belonged to:
3
+ * Executor, the app's authored code, upstream providers, or a person answering an elicitation.
4
+ * Each boundary declares its owner where the work starts (see `owned`); the invocation's own span is
5
+ * Executor's. The host adds the other isolates' parts.
6
+ */
7
+ import { Effect } from "effect";
8
+ /** The span `makeElicit` opens while a person answers. */
9
+ export declare const elicitationWaitSpan = "app.elicitation.wait";
10
+ /** The span around each workflow control an app calls, which Executor answers. */
11
+ export declare const workflowControlSpan = "app.workflow.control";
12
+ /**
13
+ * Run a tool operation in its `app.<operation>` span and time it from the span's own start to its
14
+ * own end. The span records each part, and the isolated handler returns them to the host.
15
+ */
16
+ export declare const timedInvocation: (operation: "call" | "query" | "mutate") => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, import("effect/Tracer").ParentSpan>>;
@@ -1,5 +1,5 @@
1
1
  /** Pure operation declarations. Only the author callback crosses the Promise boundary. */
2
- import { Effect, Schema as EffectSchema } from "effect";
2
+ import { Schema as EffectSchema } from "effect";
3
3
  import type { AppOperation } from "../contracts/operations.js";
4
4
  import type { AppContext, QueryContext, MutationContext } from "../contracts/context.js";
5
5
  import type { Approval } from "../approval.js";
@@ -64,7 +64,7 @@ export interface OperationOptions<Input, Output> {
64
64
  }
65
65
  /** Adapt metadata and approval without running user code. */
66
66
  export declare const operationOptions: <Input, Output>(options: OperationOptions<Input, Output>) => {
67
- approval?: (context: Parameters<Approval<Input>>[0]) => Effect.Effect<"approved" | "denied" | "user-approval", unknown, never>;
67
+ approval?: (context: Parameters<Approval<Input>>[0]) => import("effect/Effect").Effect<"approved" | "denied" | "user-approval", unknown, never>;
68
68
  input: EffectSchema.Decoder<Input, never>;
69
69
  _meta?: {
70
70
  readonly [x: string]: EffectSchema.Json;
@@ -29,6 +29,7 @@ export declare const routerSkillName: (path: string) => string;
29
29
  export declare const operationSummary: (name: string, router: string, operation: AppOperation, schedules?: readonly OperationSchedule[]) => Effect.Effect<{
30
30
  readonly description: string;
31
31
  readonly name: string;
32
+ readonly router?: string;
32
33
  readonly title?: string;
33
34
  readonly annotations?: {
34
35
  readonly title?: string;
@@ -52,7 +53,6 @@ export declare const operationSummary: (name: string, router: string, operation:
52
53
  readonly input: Schema.Json;
53
54
  }[];
54
55
  readonly readOnly?: boolean;
55
- readonly router?: string;
56
56
  readonly tags?: readonly string[];
57
57
  }, HostDeclarationInvalid, never>;
58
58
  /** A declared operation's full description, including rendered schemas. */
@@ -65,6 +65,7 @@ export declare const operationDescription: (name: string, router: string, operat
65
65
  readonly _meta?: {
66
66
  readonly [x: string]: Schema.Json;
67
67
  };
68
+ readonly router?: string;
68
69
  readonly title?: string;
69
70
  readonly annotations?: {
70
71
  readonly title?: string;
@@ -91,7 +92,6 @@ export declare const operationDescription: (name: string, router: string, operat
91
92
  readonly input: Schema.Json;
92
93
  }[];
93
94
  readonly readOnly?: boolean;
94
- readonly router?: string;
95
95
  readonly tags?: readonly string[];
96
96
  }, HostDeclarationInvalid, never>;
97
97
  /**
@@ -128,6 +128,7 @@ export declare const readCatalog: (root: AppRouter | DynamicRouter | undefined,
128
128
  readonly _meta?: {
129
129
  readonly [x: string]: Schema.Json;
130
130
  };
131
+ readonly router?: string;
131
132
  readonly title?: string;
132
133
  readonly annotations?: {
133
134
  readonly title?: string;
@@ -154,11 +155,11 @@ export declare const readCatalog: (root: AppRouter | DynamicRouter | undefined,
154
155
  readonly input: Schema.Json;
155
156
  }[];
156
157
  readonly readOnly?: boolean;
157
- readonly router?: string;
158
158
  readonly tags?: readonly string[];
159
159
  } | {
160
160
  readonly description: string;
161
161
  readonly name: string;
162
+ readonly router?: string;
162
163
  readonly title?: string;
163
164
  readonly annotations?: {
164
165
  readonly title?: string;
@@ -182,7 +183,6 @@ export declare const readCatalog: (root: AppRouter | DynamicRouter | undefined,
182
183
  readonly input: Schema.Json;
183
184
  }[];
184
185
  readonly readOnly?: boolean;
185
- readonly router?: string;
186
186
  readonly tags?: readonly string[];
187
187
  })[];
188
188
  routers: {
@@ -1,5 +1,5 @@
1
1
  /** Ordinary async workflow declarations, adapted once into native Effect handlers. */
2
- import { type Schema as EffectSchema } from "effect";
2
+ import type { Schema as EffectSchema } from "effect";
3
3
  import type { AppWorkflow, WorkflowContext } from "../contracts/workflows.js";
4
4
  import { type Schema } from "./schema.js";
5
5
  declare const NativeWorkflow: unique symbol;
@@ -5,5 +5,6 @@ export { captureTelemetry, traceHeaders, withRemoteSpan, invocationFetch, type I
5
5
  export { collectTelemetry, forwardTelemetry, makeTelemetryForwarder, TelemetryBatch, } from "./relay.js";
6
6
  export { TraceContext, currentTraceContext, externalTrace, traceLinks } from "./trace-context.js";
7
7
  export { pendingSpan } from "./pending-span.js";
8
+ export { makeOwnershipAccounting, measuredSpan, owned, ownedBy, ownerAttribute, type Owner, type SpanMeasure, } from "./ownership.js";
8
9
  export { recordWorkerMeasurements } from "./measurements.js";
9
10
  export { allowlistedSpans, httpSpanAttributeAllowlist, spanAttributeAllowed, } from "./span-attributes.js";
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Who a span's work belongs to, and how a measured span's time divides among them. A span that
3
+ * starts work for someone other than its caller declares the owner with `ownedBy`; any other span
4
+ * works for whoever its parent works for. Each instant then belongs to the innermost boundary in
5
+ * progress, so Executor's work inside an upstream session stays Executor's, and an app's callback
6
+ * inside Executor's cache stays the app's.
7
+ *
8
+ * Workers clocks advance only on I/O, so durations are comparable within one isolate and not across
9
+ * isolates: each isolate measures its own part, and the spans that already bracket the work define
10
+ * it, so the accounting and the trace agree.
11
+ */
12
+ import { Context, Effect, Tracer } from "effect";
13
+ /**
14
+ * Executor's own work; the app's authored code; waiting on an upstream provider; or waiting on a
15
+ * person's answer.
16
+ */
17
+ export type Owner = "executor" | "app" | "upstream" | "person";
18
+ /** The attribute that shows a boundary's owner in the trace; the telemetry tracer sets it. */
19
+ export declare const ownerAttribute = "executor.owner";
20
+ /** The owner a span declared when it started, if it is an ownership boundary. */
21
+ export declare const declaredOwner: (annotations: Context.Context<never>) => Owner | undefined;
22
+ /**
23
+ * Options for a span whose work belongs to `owner`. Every ownership boundary uses them, at the point
24
+ * the work starts: provider requests and sessions are the upstream's, Executor's services called by
25
+ * an app are Executor's, an app's callbacks are the app's, and waiting for an answer is the person's.
26
+ */
27
+ export declare const ownedBy: (owner: Owner, options?: Tracer.SpanOptionsNoTrace) => Tracer.SpanOptionsNoTrace;
28
+ /** Run `effect` in span `name`, owned by `owner`. */
29
+ export declare const owned: (owner: Owner, name: string, options?: Tracer.SpanOptionsNoTrace) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
30
+ /** What a measured span does with its work and its end. */
31
+ export interface SpanMeasure {
32
+ /** Wraps the work inside the span, for example to observe the spans it opens. */
33
+ readonly around?: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
34
+ /** Receives the span's end, before the span ends, to record what it measured on it. */
35
+ readonly end: (end: bigint, span: Tracer.Span) => void;
36
+ }
37
+ /**
38
+ * Run `effect` in span `name`, measured by `measure` from the span's own start to its own end, so
39
+ * the span's duration and the measurement share both boundaries.
40
+ */
41
+ export declare const measuredSpan: (name: string, options: Tracer.SpanOptionsNoTrace, measure: (start: bigint) => SpanMeasure) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>;
42
+ /**
43
+ * Divide a window that starts at `origin`, whose own work is `owner`'s, among owners. At each
44
+ * instant, the work in progress is the innermost span of each branch: a span with no child still
45
+ * open. Its owner takes the instant. With nothing open inside the window, `owner` takes it. Spans
46
+ * are counted as they open and end, in constant time each, and only spans still open are kept.
47
+ */
48
+ export declare const makeOwnershipAccounting: (origin: bigint, owner: Owner) => {
49
+ /** Run `effect` with the spans it opens observed, including spans it hands to later work. */
50
+ observe: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
51
+ /**
52
+ * Close the window at `end` and return its milliseconds by owner, each instant counted once.
53
+ * Spans still open count up to `end`; spans that open or end afterwards are ignored.
54
+ */
55
+ read: (end: bigint) => Readonly<Record<Owner, number>>;
56
+ };
@@ -4392,8 +4392,6 @@ export {
4392
4392
  bodyFormData,
4393
4393
  HttpClientRequest_exports,
4394
4394
  fromWeb2 as fromWeb,
4395
- HttpServerResponse_exports,
4396
- HttpServerRequest_exports,
4397
4395
  HttpTraceContext_exports,
4398
4396
  HttpClient,
4399
4397
  transformResponse,
@@ -4406,6 +4404,8 @@ export {
4406
4404
  TracerPropagationEnabled,
4407
4405
  layerMergedContext,
4408
4406
  HttpClient_exports,
4407
+ HttpServerResponse_exports,
4408
+ HttpServerRequest_exports,
4409
4409
  prefixPath,
4410
4410
  fromLiteral
4411
4411
  };