apps 0.0.1-beta.44 → 0.0.1-beta.47
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/framework-reference.json +1 -1
- package/js/{chunk-DZQYE626.js → chunk-7UUHJR2Q.js} +1 -1
- package/js/{chunk-4ZTVLEN6.js → chunk-CDXQDN7W.js} +1 -1
- package/js/{chunk-V3RS2BK6.js → chunk-D45JTD6N.js} +39 -29
- package/js/chunk-GDYPM7RS.js +266 -0
- package/js/{chunk-CZGWW4NQ.js → chunk-JM7LOD2W.js} +187 -9
- package/js/{chunk-ELO5PRCO.js → chunk-JY56GVSV.js} +95 -4
- package/js/{chunk-EJUK2NK5.js → chunk-KLYSEHUD.js} +1 -1
- package/js/{chunk-EMHFXFTJ.js → chunk-LTDHQJ2Z.js} +53 -0
- package/js/{chunk-MZH4J2PO.js → chunk-PD6I2SDG.js} +1 -1
- package/js/{chunk-DRJRCHHO.js → chunk-PO5NPRFT.js} +204 -73
- package/js/{chunk-MGGMEGB2.js → chunk-QKHTRD6G.js} +2 -2
- package/js/{chunk-5SHUB37R.js → chunk-SVHI6AKV.js} +3 -3
- package/js/{chunk-KSGYJV46.js → chunk-TUMGL2OC.js} +1 -1
- package/js/{chunk-5GLC42LK.js → chunk-UM62MBJQ.js} +42 -24
- package/js/{chunk-OTGUPKKK.js → chunk-X5U5KIWQ.js} +12 -46
- package/js/{chunk-7EBODVQJ.js → chunk-YQD2MLFY.js} +14 -13
- package/js/client.js +8 -8
- package/js/contracts.js +25 -3
- package/js/effect.js +11 -11
- package/js/graphql.js +20 -18
- package/js/host.js +76 -51
- package/js/index.js +23 -16
- package/js/mcp/effect.js +13 -13
- package/js/mcp/stdio.js +27 -22
- package/js/mcp.js +20 -18
- package/js/openapi.js +103 -77
- package/js/skills/effect.js +2 -2
- package/js/skills.js +50 -33
- package/js/ui/auth.js +3 -3
- package/js/ui/contracts.js +3 -3
- package/js/ui/serving.js +6 -6
- package/package.json +1 -1
- package/runtime.json +1 -1
- package/types/apps/src/contracts/app.d.ts +2 -0
- package/types/apps/src/contracts/context.d.ts +8 -1
- package/types/apps/src/contracts/events.d.ts +93 -0
- package/types/apps/src/contracts/host.d.ts +21 -4
- package/types/apps/src/contracts/protocol-version.d.ts +2 -2
- package/types/apps/src/contracts/protocols/11.d.ts +1098 -0
- package/types/apps/src/host.d.ts +5 -0
- package/types/apps/src/implementation/authoring.d.ts +25 -5
- package/types/apps/src/implementation/cache.d.ts +4 -0
- package/types/apps/src/implementation/elicitation.d.ts +6 -3
- package/types/apps/src/implementation/events.d.ts +59 -0
- package/types/apps/src/implementation/invocation-timing.d.ts +16 -0
- package/types/apps/src/implementation/operations.d.ts +2 -2
- package/types/apps/src/implementation/router-catalog.d.ts +4 -4
- package/types/apps/src/implementation/sql.d.ts +5 -0
- package/types/apps/src/implementation/workflows.d.ts +1 -1
- package/types/apps/src/index.d.ts +2 -0
- package/types/telemetry/src/index.d.ts +1 -0
- package/types/telemetry/src/ownership.d.ts +56 -0
- package/js/chunk-646JVUH4.js +0 -156
- package/js/{chunk-LNSVJS2Q.js → chunk-EOPQ727L.js} +2 -2
package/types/apps/src/host.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
10
|
-
export
|
|
11
|
-
/**
|
|
12
|
-
|
|
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
|
-
/**
|
|
103
|
-
|
|
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,59 @@
|
|
|
1
|
+
/** Event declarations and the per-invocation emitter. Emitted events leave in the reply. */
|
|
2
|
+
import { Effect, Schema as EffectSchema } from "effect";
|
|
3
|
+
import { EmittedEvent, type AppEvent, type EmitOptions } from "../contracts/events.js";
|
|
4
|
+
import { type Fields, type Infer, type ObjectValue, type Schema } from "./schema.js";
|
|
5
|
+
declare const Native: unique symbol;
|
|
6
|
+
/** An event an app emits. Declare it in `defineApp`'s requirements under `events`. */
|
|
7
|
+
export interface EventDeclaration<F extends Fields, P extends Schema<unknown, boolean>> {
|
|
8
|
+
readonly [Native]: AppEvent;
|
|
9
|
+
readonly description: string;
|
|
10
|
+
readonly filters: F;
|
|
11
|
+
readonly payload: P;
|
|
12
|
+
}
|
|
13
|
+
/** Any declared event, for requirement constraints. */
|
|
14
|
+
export type AnyEventDeclaration = EventDeclaration<Fields, Schema<unknown, boolean>>;
|
|
15
|
+
/**
|
|
16
|
+
* Declare an event. `filters` are scalar fields subscribers can narrow on, such as a repository;
|
|
17
|
+
* every emitted occurrence supplies their values. `payload` describes each occurrence's data.
|
|
18
|
+
*/
|
|
19
|
+
export declare const event: <const F extends Fields = {}, P extends Schema<unknown, boolean> = Schema<unknown>>(options: {
|
|
20
|
+
readonly description: string;
|
|
21
|
+
readonly filters?: F;
|
|
22
|
+
readonly payload: P;
|
|
23
|
+
}) => EventDeclaration<F, P>;
|
|
24
|
+
/** The native declaration retained by an author event. */
|
|
25
|
+
export declare const nativeEvent: (declaration: unknown) => AppEvent | undefined;
|
|
26
|
+
/** JSON Schema for each declared event, as the host reads it from requirements. */
|
|
27
|
+
export declare const declaredEvents: (events: Readonly<Record<string, AppEvent>>) => Effect.Effect<{
|
|
28
|
+
readonly [x: string]: {
|
|
29
|
+
readonly description: string;
|
|
30
|
+
readonly filters: {
|
|
31
|
+
readonly [x: string]: EffectSchema.Json;
|
|
32
|
+
};
|
|
33
|
+
readonly payload: {
|
|
34
|
+
readonly [x: string]: EffectSchema.Json;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}, EffectSchema.SchemaError, never>;
|
|
38
|
+
/** Emit options typed by the event's filters: required exactly when it declares some. */
|
|
39
|
+
type OptionsFor<F extends Fields> = keyof F extends never ? [options?: Omit<EmitOptions<never>, "filters">] : [options: EmitOptions<ObjectValue<F>> & {
|
|
40
|
+
readonly filters: ObjectValue<F>;
|
|
41
|
+
}];
|
|
42
|
+
/** `ctx.events` in mutations and webhook handlers. */
|
|
43
|
+
export interface EventEmitter<Events extends Readonly<Record<string, AnyEventDeclaration>>> {
|
|
44
|
+
/**
|
|
45
|
+
* Record an occurrence. It is delivered only if this invocation succeeds. Invalid data, filters
|
|
46
|
+
* or options throw here, before anything is recorded.
|
|
47
|
+
*/
|
|
48
|
+
readonly emit: <Name extends keyof Events & string>(name: Name, data: Infer<Events[Name]["payload"]>, ...options: OptionsFor<Events[Name]["filters"]>) => void;
|
|
49
|
+
}
|
|
50
|
+
/** One invocation's buffer. The handler reads `emitted` only after the invocation succeeds. */
|
|
51
|
+
export declare const makeEmitter: (input: {
|
|
52
|
+
readonly events: Readonly<Record<string, AppEvent>>;
|
|
53
|
+
/** Every account ID bound to this invocation. */
|
|
54
|
+
readonly accounts: readonly string[];
|
|
55
|
+
/** The webhook's source account, which an emit names by default. */
|
|
56
|
+
readonly sourceAccount?: string;
|
|
57
|
+
readonly emitted: EmittedEvent[];
|
|
58
|
+
}) => EventEmitter<Readonly<Record<string, AnyEventDeclaration>>>;
|
|
59
|
+
export {};
|
|
@@ -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 {
|
|
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: {
|
|
@@ -22,6 +22,11 @@ export interface StepReplay {
|
|
|
22
22
|
export declare const authorSql: (storage: AppSqlStorage, options: {
|
|
23
23
|
readonly signal: AbortSignal;
|
|
24
24
|
readonly step?: StepReplay;
|
|
25
|
+
/**
|
|
26
|
+
* The invocation's emitted events. A transaction that rolls back also discards the events its
|
|
27
|
+
* callback emitted, so subscribers never hear of writes that did not commit.
|
|
28
|
+
*/
|
|
29
|
+
readonly emitted?: unknown[];
|
|
25
30
|
}) => {
|
|
26
31
|
reader: SqlReader;
|
|
27
32
|
writer: Sql;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Ordinary async workflow declarations, adapted once into native Effect handlers. */
|
|
2
|
-
import {
|
|
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;
|
|
@@ -59,6 +59,8 @@ export declare function oauth2<Response extends Schema<unknown, boolean>>(option
|
|
|
59
59
|
export type { AccountSlots } from "./contracts/app.js";
|
|
60
60
|
export type { AppRequirements, AppContext, QueryContext, MutationContext, WebhookContext, } from "./contracts/context.js";
|
|
61
61
|
export { type App, type AppDefinition, defineApp } from "./implementation/app.js";
|
|
62
|
+
export { event, type EventDeclaration, type EventEmitter } from "./implementation/events.js";
|
|
63
|
+
export type { EmitOptions } from "./contracts/events.js";
|
|
62
64
|
export type { Approval, ApprovalContext, ApprovalDecision } from "./approval.js";
|
|
63
65
|
type AuthorWebhook<Member, Config, State> = Member extends object ? Omit<PromiseMethods<Member>, "config" | "state"> & {
|
|
64
66
|
readonly config: Config;
|
|
@@ -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
|
+
};
|
package/js/chunk-646JVUH4.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declaredOperations,
|
|
3
|
-
fromPromise,
|
|
4
|
-
nativeOperation,
|
|
5
|
-
nativeRouter
|
|
6
|
-
} from "./chunk-OTGUPKKK.js";
|
|
7
|
-
import {
|
|
8
|
-
ScheduleTiming
|
|
9
|
-
} from "./chunk-ELO5PRCO.js";
|
|
10
|
-
import {
|
|
11
|
-
decoderOf,
|
|
12
|
-
isSchema,
|
|
13
|
-
schemaArgument
|
|
14
|
-
} from "./chunk-KGCTYL2S.js";
|
|
15
|
-
import {
|
|
16
|
-
JsonValue
|
|
17
|
-
} from "./chunk-H2CJWXA3.js";
|
|
18
|
-
import {
|
|
19
|
-
Effect_exports,
|
|
20
|
-
Schema_exports
|
|
21
|
-
} from "./chunk-IFJU5SYQ.js";
|
|
22
|
-
|
|
23
|
-
// src/contracts/http.ts
|
|
24
|
-
var ResponseStatusError = class extends Schema_exports.TaggedError()(
|
|
25
|
-
"ResponseStatusError",
|
|
26
|
-
{ status: Schema_exports.Number }
|
|
27
|
-
) {
|
|
28
|
-
get message() {
|
|
29
|
-
return `Request failed with status ${this.status}`;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
var ResponseDecodeError = class extends Schema_exports.TaggedError()(
|
|
33
|
-
"ResponseDecodeError",
|
|
34
|
-
{}
|
|
35
|
-
) {
|
|
36
|
-
get message() {
|
|
37
|
-
return "Response body did not match the expected schema";
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/implementation/workflows.ts
|
|
42
|
-
var NativeWorkflow = /* @__PURE__ */ Symbol("apps.Workflow");
|
|
43
|
-
var workflow = (options, run) => ({
|
|
44
|
-
[NativeWorkflow]: {
|
|
45
|
-
input: decoderOf(schemaArgument(options.input, "The workflow input")),
|
|
46
|
-
...options.output === void 0 ? {} : { output: decoderOf(schemaArgument(options.output, "The workflow output")) },
|
|
47
|
-
...options.description === void 0 ? {} : { description: options.description },
|
|
48
|
-
run: (context, input) => Effect_exports.tryPromise({
|
|
49
|
-
// SAFETY: defineApp checks required context; the host supplies the pinned run's capabilities.
|
|
50
|
-
try: () => run(context, input),
|
|
51
|
-
catch: (error) => error
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
var nativeWorkflow = (value) => {
|
|
56
|
-
if (typeof value !== "object" || value === null || !(NativeWorkflow in value)) return void 0;
|
|
57
|
-
return value[NativeWorkflow];
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// src/implementation/app.ts
|
|
61
|
-
var InternalApp = /* @__PURE__ */ Symbol("apps.App");
|
|
62
|
-
var isApp = (value) => typeof value === "object" && value !== null && InternalApp in value;
|
|
63
|
-
var toEffectApp = (app) => app[InternalApp];
|
|
64
|
-
function rejectCatalogs(definition) {
|
|
65
|
-
if ("queries" in definition || "mutations" in definition)
|
|
66
|
-
throw new Error("Put queries and mutations in a router under tools");
|
|
67
|
-
}
|
|
68
|
-
function adaptDefinition(definition) {
|
|
69
|
-
rejectCatalogs(definition);
|
|
70
|
-
const webhooks = definition.webhooks === void 0 ? {} : {
|
|
71
|
-
webhooks: Object.fromEntries(
|
|
72
|
-
Object.entries(definition.webhooks).map(([name, webhook]) => [
|
|
73
|
-
name,
|
|
74
|
-
{
|
|
75
|
-
...webhook,
|
|
76
|
-
...webhook.register === void 0 ? {} : { register: fromPromise(webhook.register) },
|
|
77
|
-
handle: fromPromise(webhook.handle),
|
|
78
|
-
...webhook.unregister === void 0 ? {} : { unregister: fromPromise(webhook.unregister) },
|
|
79
|
-
..."config" in webhook && isSchema(webhook.config) ? { config: decoderOf(webhook.config) } : {},
|
|
80
|
-
..."state" in webhook && isSchema(webhook.state) ? { state: decoderOf(webhook.state) } : {}
|
|
81
|
-
}
|
|
82
|
-
])
|
|
83
|
-
)
|
|
84
|
-
};
|
|
85
|
-
const workflows = definition.workflows === void 0 ? {} : {
|
|
86
|
-
workflows: Object.fromEntries(
|
|
87
|
-
Object.entries(definition.workflows).map(([name, value]) => {
|
|
88
|
-
const declared2 = nativeWorkflow(value);
|
|
89
|
-
if (declared2 === void 0) throw new Error("Invalid workflow declaration");
|
|
90
|
-
return [name, declared2];
|
|
91
|
-
})
|
|
92
|
-
)
|
|
93
|
-
};
|
|
94
|
-
const root = definition.tools === void 0 ? void 0 : nativeRouter(definition.tools);
|
|
95
|
-
if (definition.tools !== void 0 && root === void 0)
|
|
96
|
-
throw new Error("tools must be a router");
|
|
97
|
-
const data = root === void 0 ? {} : { tools: root };
|
|
98
|
-
const declared = root?.kind === "router" ? declaredOperations(root) : [];
|
|
99
|
-
const mutations = /* @__PURE__ */ new Set();
|
|
100
|
-
for (const { operation } of declared) {
|
|
101
|
-
if (operation.kind !== "mutation") continue;
|
|
102
|
-
if (mutations.has(operation))
|
|
103
|
-
throw new Error("A mutation can be mounted at only one path in tools");
|
|
104
|
-
mutations.add(operation);
|
|
105
|
-
}
|
|
106
|
-
const schedules = definition.schedules === void 0 ? {} : {
|
|
107
|
-
schedules: Object.fromEntries(
|
|
108
|
-
Object.entries(definition.schedules).map(([name, schedule]) => {
|
|
109
|
-
const target = nativeOperation(schedule.operation);
|
|
110
|
-
const match = declared.find(
|
|
111
|
-
({ operation }) => operation === target && operation.kind === "mutation"
|
|
112
|
-
);
|
|
113
|
-
if (match === void 0)
|
|
114
|
-
throw new Error("A schedule must reference a mutation in this app's tools");
|
|
115
|
-
return [
|
|
116
|
-
name,
|
|
117
|
-
{
|
|
118
|
-
timing: Schema_exports.decodeUnknownSync(ScheduleTiming)(schedule.timing),
|
|
119
|
-
input: Schema_exports.decodeUnknownSync(JsonValue)(schedule.input),
|
|
120
|
-
tool: match.name
|
|
121
|
-
}
|
|
122
|
-
];
|
|
123
|
-
})
|
|
124
|
-
)
|
|
125
|
-
};
|
|
126
|
-
return {
|
|
127
|
-
...definition,
|
|
128
|
-
...webhooks,
|
|
129
|
-
...workflows,
|
|
130
|
-
...data,
|
|
131
|
-
...schedules
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
var defineApp = (requirements, definition) => {
|
|
135
|
-
if (typeof definition !== "function") rejectCatalogs(definition);
|
|
136
|
-
const evaluate = typeof definition === "function" ? definition : async () => definition;
|
|
137
|
-
const factory = fromPromise(evaluate);
|
|
138
|
-
const native = {
|
|
139
|
-
accounts: requirements.accounts,
|
|
140
|
-
evaluate: (context) => factory(context).pipe(Effect_exports.map((value) => adaptDefinition(value)))
|
|
141
|
-
};
|
|
142
|
-
return {
|
|
143
|
-
[InternalApp]: native,
|
|
144
|
-
accounts: native.accounts,
|
|
145
|
-
evaluate: (context) => Effect_exports.runPromise(factory(context))
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
export {
|
|
150
|
-
ResponseStatusError,
|
|
151
|
-
ResponseDecodeError,
|
|
152
|
-
workflow,
|
|
153
|
-
isApp,
|
|
154
|
-
toEffectApp,
|
|
155
|
-
defineApp
|
|
156
|
-
};
|
|
@@ -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
|
};
|