@aitoroses/telar 0.0.0 → 0.1.0
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 +453 -3
- package/dist/compile.d.ts +48 -0
- package/dist/compile.js +1238 -0
- package/dist/contract.d.ts +109 -0
- package/dist/contract.js +497 -0
- package/dist/evaluator.d.ts +23 -0
- package/dist/evaluator.js +40 -0
- package/dist/guide.d.ts +8 -0
- package/dist/guide.js +16 -0
- package/dist/install.d.ts +104 -0
- package/dist/install.js +402 -0
- package/dist/iso.d.ts +8 -0
- package/dist/iso.js +68 -0
- package/dist/node/build.d.ts +1 -0
- package/dist/node/build.js +34 -0
- package/dist/node/telar-module.d.ts +2 -0
- package/dist/node/telar-module.js +28 -0
- package/dist/observer.d.ts +47 -0
- package/dist/observer.js +53 -0
- package/dist/pieces.d.ts +230 -0
- package/dist/pieces.js +178 -0
- package/dist/powers.d.ts +46 -0
- package/dist/powers.js +126 -0
- package/dist/protocol.d.ts +212 -0
- package/dist/protocol.js +236 -0
- package/dist/query.d.ts +67 -0
- package/dist/query.js +102 -0
- package/dist/read.d.ts +37 -0
- package/dist/read.js +27 -0
- package/dist/runner.d.ts +112 -0
- package/dist/runner.js +134 -0
- package/dist/scenario/builder.d.ts +25 -0
- package/dist/scenario/builder.js +603 -0
- package/dist/scenario/templates.d.ts +35 -0
- package/dist/scenario/templates.js +64 -0
- package/dist/scenario/types.d.ts +441 -0
- package/dist/scenario/types.js +10 -0
- package/dist/scenario/validate.d.ts +7 -0
- package/dist/scenario/validate.js +19 -0
- package/dist/scenario.d.ts +4 -0
- package/dist/scenario.js +4 -0
- package/dist/schema.d.ts +219 -0
- package/dist/schema.js +221 -0
- package/dist/seating.d.ts +49 -0
- package/dist/seating.js +26 -0
- package/dist/send-hook.d.ts +46 -0
- package/dist/send-hook.js +123 -0
- package/dist/show.d.ts +34 -0
- package/dist/show.js +1 -0
- package/dist/source.d.ts +85 -0
- package/dist/source.js +104 -0
- package/dist/spec.d.ts +20 -0
- package/dist/spec.js +17 -0
- package/dist/standard-schema.d.ts +21 -0
- package/dist/standard-schema.js +1 -0
- package/dist/std/accuracy.d.ts +12 -0
- package/dist/std/accuracy.js +122 -0
- package/dist/std/ack.d.ts +14 -0
- package/dist/std/ack.js +43 -0
- package/dist/std/actions.d.ts +106 -0
- package/dist/std/actions.js +154 -0
- package/dist/std/brief.d.ts +36 -0
- package/dist/std/brief.js +78 -0
- package/dist/std/claude-code.d.ts +9 -0
- package/dist/std/claude-code.js +106 -0
- package/dist/std/compare.d.ts +29 -0
- package/dist/std/compare.js +36 -0
- package/dist/std/git-workspace.d.ts +44 -0
- package/dist/std/git-workspace.js +184 -0
- package/dist/std/judgment.d.ts +85 -0
- package/dist/std/judgment.js +462 -0
- package/dist/std/observe-command.d.ts +23 -0
- package/dist/std/observe-command.js +151 -0
- package/dist/std/observe-github-checks.d.ts +26 -0
- package/dist/std/observe-github-checks.js +299 -0
- package/dist/std/observe-http-status.d.ts +27 -0
- package/dist/std/observe-http-status.js +181 -0
- package/dist/std/plan.d.ts +7 -0
- package/dist/std/plan.js +28 -0
- package/dist/std/queries.d.ts +31 -0
- package/dist/std/queries.js +318 -0
- package/dist/std/reading.d.ts +17 -0
- package/dist/std/reading.js +88 -0
- package/dist/std/schedule.d.ts +19 -0
- package/dist/std/schedule.js +122 -0
- package/dist/std.d.ts +15 -0
- package/dist/std.js +15 -0
- package/dist/types.d.ts +366 -0
- package/dist/types.js +1 -0
- package/dist/values.d.ts +81 -0
- package/dist/values.js +129 -0
- package/package.json +62 -5
package/dist/show.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** A case as `telar.show/1` renders it, and as `read` returns it. */
|
|
2
|
+
export interface ShowCase {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly protocol: string;
|
|
5
|
+
readonly parent: string | null;
|
|
6
|
+
readonly scope: string | null;
|
|
7
|
+
readonly state: string;
|
|
8
|
+
readonly phase: "open" | "final-pending-effects" | "closed" | "cancelled";
|
|
9
|
+
readonly data: Readonly<Record<string, unknown>>;
|
|
10
|
+
}
|
|
11
|
+
/** The key a seat is bound by, as `telar.show/1` renders it. */
|
|
12
|
+
export type ShowSeatBinding = {
|
|
13
|
+
readonly kind: "case";
|
|
14
|
+
readonly case: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: "all";
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "field";
|
|
19
|
+
readonly field: string;
|
|
20
|
+
readonly value: string;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: "ancestor";
|
|
23
|
+
readonly protocol: string;
|
|
24
|
+
readonly case: string;
|
|
25
|
+
};
|
|
26
|
+
/** A seat as `telar.show/1` renders it, and as `read` returns it. `holder` is what its runner last reported. */
|
|
27
|
+
export interface ShowSeat {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly role: string;
|
|
30
|
+
readonly binding: ShowSeatBinding;
|
|
31
|
+
readonly labels: Readonly<Record<string, string>>;
|
|
32
|
+
readonly phase: "active" | "closed";
|
|
33
|
+
readonly holder?: Readonly<Record<string, string>> | undefined;
|
|
34
|
+
}
|
package/dist/show.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { WorldPowers } from "./powers.js";
|
|
2
|
+
import { type RunnerOptionValidation } from "./runner.js";
|
|
3
|
+
import type { StandardSchema } from "./standard-schema.js";
|
|
4
|
+
export type SourceId = `${string}/source/${string}/${number}`;
|
|
5
|
+
/** One schema per field of the event data. The host merges these fields into the opened case's data. */
|
|
6
|
+
export type SourceEventFields = Readonly<Record<string, StandardSchema>>;
|
|
7
|
+
export type SourceEventData<Fields extends SourceEventFields> = {
|
|
8
|
+
readonly [K in keyof Fields]: Fields[K] extends StandardSchema<infer O> ? O : never;
|
|
9
|
+
};
|
|
10
|
+
export interface SourceEvent<Data> {
|
|
11
|
+
readonly key: string;
|
|
12
|
+
readonly at: string;
|
|
13
|
+
readonly data: Data;
|
|
14
|
+
}
|
|
15
|
+
export interface SourceLast {
|
|
16
|
+
readonly key: string;
|
|
17
|
+
readonly at: string;
|
|
18
|
+
}
|
|
19
|
+
export interface SourcePollInput<Options> {
|
|
20
|
+
readonly now: string;
|
|
21
|
+
readonly last?: SourceLast;
|
|
22
|
+
readonly options: Options;
|
|
23
|
+
}
|
|
24
|
+
export interface DefineSourceInput<Id extends SourceId, Options, Fields extends SourceEventFields> {
|
|
25
|
+
readonly id: Id;
|
|
26
|
+
readonly options: StandardSchema<Options>;
|
|
27
|
+
readonly event: Fields;
|
|
28
|
+
readonly poll: (input: SourcePollInput<Options>, powers: WorldPowers) => readonly SourceEvent<SourceEventData<Fields>>[];
|
|
29
|
+
}
|
|
30
|
+
export interface SourceEventIssue {
|
|
31
|
+
readonly key: string;
|
|
32
|
+
readonly message: string;
|
|
33
|
+
}
|
|
34
|
+
export interface SourcePollReply {
|
|
35
|
+
readonly events: readonly SourceEvent<Readonly<Record<string, unknown>>>[];
|
|
36
|
+
readonly invalid: readonly SourceEventIssue[];
|
|
37
|
+
}
|
|
38
|
+
export interface AnySource {
|
|
39
|
+
readonly id: SourceId;
|
|
40
|
+
readonly eventFields: readonly string[];
|
|
41
|
+
readonly admitOptions: (raw: unknown) => RunnerOptionValidation<unknown>;
|
|
42
|
+
readonly dispatch: (args: unknown, powers: WorldPowers) => SourcePollReply;
|
|
43
|
+
}
|
|
44
|
+
export interface Source<Id extends SourceId = SourceId, Options = Readonly<Record<string, unknown>>, Fields extends SourceEventFields = SourceEventFields> extends AnySource {
|
|
45
|
+
readonly id: Id;
|
|
46
|
+
readonly options: StandardSchema<Options>;
|
|
47
|
+
readonly event: Fields;
|
|
48
|
+
readonly poll: DefineSourceInput<Id, Options, Fields>["poll"];
|
|
49
|
+
}
|
|
50
|
+
export type SourceIdOf<S> = S extends {
|
|
51
|
+
readonly id: infer Id extends SourceId;
|
|
52
|
+
} ? Id : never;
|
|
53
|
+
export type SourceOptionsOf<S> = S extends {
|
|
54
|
+
readonly options: StandardSchema<infer O>;
|
|
55
|
+
} ? O : never;
|
|
56
|
+
export type SourceFieldsOf<S> = S extends {
|
|
57
|
+
readonly event: infer F;
|
|
58
|
+
} ? keyof F & string : never;
|
|
59
|
+
export interface AnySourceChoice {
|
|
60
|
+
readonly source: string;
|
|
61
|
+
readonly options?: unknown;
|
|
62
|
+
readonly opens: {
|
|
63
|
+
readonly protocol: string;
|
|
64
|
+
readonly data?: Readonly<Record<string, unknown>>;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export type SourceChoice<Sources extends readonly AnySource[]> = AnySource extends Sources[number] ? AnySourceChoice : Sources[number] extends infer S ? S extends AnySource ? {
|
|
68
|
+
readonly source: SourceIdOf<S>;
|
|
69
|
+
readonly options?: SourceOptionsOf<S> | undefined;
|
|
70
|
+
readonly opens: {
|
|
71
|
+
readonly protocol: string;
|
|
72
|
+
readonly data?: (Readonly<Record<string, unknown>> & {
|
|
73
|
+
readonly [K in SourceFieldsOf<S>]?: never;
|
|
74
|
+
}) | undefined;
|
|
75
|
+
};
|
|
76
|
+
} : never : never;
|
|
77
|
+
/** The team config's source instances, by name, each a choice among the installation's sources. */
|
|
78
|
+
export type SourcesConfig<Sources extends readonly AnySource[] = readonly []> = Readonly<Record<string, SourceChoice<Sources>>>;
|
|
79
|
+
export declare class SourceError extends Error {
|
|
80
|
+
readonly name: string;
|
|
81
|
+
readonly code: string;
|
|
82
|
+
constructor(code: string, message: string);
|
|
83
|
+
}
|
|
84
|
+
export declare function isValidSourceId(id: string): boolean;
|
|
85
|
+
export declare function defineSource<const Id extends SourceId, Options, const Fields extends SourceEventFields>(input: DefineSourceInput<Id, Options, Fields>): Source<Id, Options, Fields>;
|
package/dist/source.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { formatIsoUtc, parseIsoUtc } from "./iso.js";
|
|
2
|
+
import { validateStandard } from "./runner.js";
|
|
3
|
+
export class SourceError extends Error {
|
|
4
|
+
name = "SourceError";
|
|
5
|
+
code;
|
|
6
|
+
constructor(code, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const SOURCE_ID_RE = /^[a-z][a-z0-9.-]*\/source\/[a-z][a-z0-9-]*\/[1-9][0-9]*$/;
|
|
12
|
+
export function isValidSourceId(id) {
|
|
13
|
+
return SOURCE_ID_RE.test(id);
|
|
14
|
+
}
|
|
15
|
+
function isRec(value) {
|
|
16
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
function issueText(issues) {
|
|
19
|
+
const first = issues[0];
|
|
20
|
+
if (first === undefined)
|
|
21
|
+
return "invalid";
|
|
22
|
+
return first.path.length > 0 ? `${first.path.join(".")}: ${first.message}` : first.message;
|
|
23
|
+
}
|
|
24
|
+
function decodeData(id, fields, raw) {
|
|
25
|
+
if (!isRec(raw))
|
|
26
|
+
return "data must be an object";
|
|
27
|
+
const extra = Object.keys(raw).find((k) => !(k in fields));
|
|
28
|
+
if (extra !== undefined)
|
|
29
|
+
return `data.${extra} is not a declared event field`;
|
|
30
|
+
const out = {};
|
|
31
|
+
for (const [name, schema] of Object.entries(fields)) {
|
|
32
|
+
const checked = validateStandard(schema, raw[name]);
|
|
33
|
+
if (checked.ok === "async") {
|
|
34
|
+
throw new SourceError("INVALID_SOURCE", `source ${id} event.${name} must validate synchronously`);
|
|
35
|
+
}
|
|
36
|
+
if (!checked.ok)
|
|
37
|
+
return `data.${name}: ${issueText(checked.issues)}`;
|
|
38
|
+
out[name] = checked.value;
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
function readLast(raw) {
|
|
43
|
+
if (!isRec(raw) || typeof raw["key"] !== "string" || typeof raw["at"] !== "string") {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return { key: raw["key"], at: raw["at"] };
|
|
47
|
+
}
|
|
48
|
+
function decodeEvents(id, fields, now, events) {
|
|
49
|
+
const nowMs = parseIsoUtc(now) ?? Number.NEGATIVE_INFINITY;
|
|
50
|
+
const valid = [];
|
|
51
|
+
const invalid = [];
|
|
52
|
+
for (const event of events) {
|
|
53
|
+
const key = typeof event.key === "string" ? event.key : "";
|
|
54
|
+
if (key.length === 0) {
|
|
55
|
+
invalid.push({ key: "", message: "an event needs a non-empty key" });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const at = typeof event.at === "string" ? parseIsoUtc(event.at) : undefined;
|
|
59
|
+
if (at === undefined || at > nowMs) {
|
|
60
|
+
invalid.push({ key, message: `at must be an ISO-UTC instant no later than ${now}` });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const data = decodeData(id, fields, event.data);
|
|
64
|
+
if (typeof data === "string")
|
|
65
|
+
invalid.push({ key, message: data });
|
|
66
|
+
else
|
|
67
|
+
valid.push({ key, at: formatIsoUtc(at), data });
|
|
68
|
+
}
|
|
69
|
+
return { events: valid, invalid };
|
|
70
|
+
}
|
|
71
|
+
export function defineSource(input) {
|
|
72
|
+
if (!isValidSourceId(input.id)) {
|
|
73
|
+
throw new SourceError("INVALID_SOURCE", `source id ${JSON.stringify(input.id)} must match <installation>/source/<name>/<v>`);
|
|
74
|
+
}
|
|
75
|
+
const admitOptions = (raw) => {
|
|
76
|
+
const checked = validateStandard(input.options, raw === undefined ? {} : raw);
|
|
77
|
+
if (checked.ok === "async") {
|
|
78
|
+
throw new SourceError("INVALID_SOURCE", `source ${input.id} options must validate synchronously`);
|
|
79
|
+
}
|
|
80
|
+
return checked;
|
|
81
|
+
};
|
|
82
|
+
const dispatch = (args, powers) => {
|
|
83
|
+
const now = isRec(args) ? args["now"] : undefined;
|
|
84
|
+
if (typeof now !== "string" || parseIsoUtc(now) === undefined) {
|
|
85
|
+
throw new SourceError("INVALID_INPUT", "source:poll requires now as an ISO-UTC instant");
|
|
86
|
+
}
|
|
87
|
+
const options = admitOptions(isRec(args) ? args["options"] : undefined);
|
|
88
|
+
if (!options.ok) {
|
|
89
|
+
throw new SourceError("INVALID_SOURCE", issueText(options.issues));
|
|
90
|
+
}
|
|
91
|
+
const last = readLast(isRec(args) ? args["last"] : undefined);
|
|
92
|
+
const events = input.poll({ now, ...(last !== undefined ? { last } : {}), options: options.value }, powers);
|
|
93
|
+
return decodeEvents(input.id, input.event, now, events);
|
|
94
|
+
};
|
|
95
|
+
return Object.freeze({
|
|
96
|
+
id: input.id,
|
|
97
|
+
options: input.options,
|
|
98
|
+
event: input.event,
|
|
99
|
+
eventFields: Object.freeze(Object.keys(input.event)),
|
|
100
|
+
poll: input.poll,
|
|
101
|
+
admitOptions,
|
|
102
|
+
dispatch,
|
|
103
|
+
});
|
|
104
|
+
}
|
package/dist/spec.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { PluginCallError, defineInstallation, type AdmissionProblem, type ConfiguredInstallation, type DeclareFrame, type DefineInstallationInput, type DefinedInstallation, type InstallationCallReply, type InstallationConfigBase, type InstallationTest, type SeatingFor, type SourcesFor, type TrailProof, } from "./install.js";
|
|
2
|
+
export { SpecCompileError, compile, installation, type Installation, type InstallationInput, type RosterInput, } from "./compile.js";
|
|
3
|
+
export { guide, type Guide } from "./guide.js";
|
|
4
|
+
export { mergeSeating, type InstalledRunnerChoice, type RoleSeating, type RoleSeatingBase, type RunnerChoice, type RunnerOptions, type SeatBindingChoice, type SeatKey, type SeatRunner, type Seating, } from "./seating.js";
|
|
5
|
+
export { RunnerError, defineRunner, isValidRunnerId, validateRunnerOptions, type AnyRunner, type DefineRunnerInput, type Runner, type RunnerEndInput, type RunnerId, type RunnerIdOf, type RunnerHolder, type RunnerOptionIssue, type RunnerOptionValidation, type RunnerOptionsOf, type RunnerPoint, type RunnerPollInput, type RunnerReadings, type RunnerReport, type RunnerSeatRef, type RunnerState, type RunnerWakeInput, type RunnerWork, type StandardValidation, validateStandard, } from "./runner.js";
|
|
6
|
+
export type { StandardSchema, StandardSchemaIssue, StandardSchemaIssuePath, StandardSchemaResult, } from "./standard-schema.js";
|
|
7
|
+
export { formatIsoUtc, parseIsoUtc, zoneOffset } from "./iso.js";
|
|
8
|
+
export { ObserverError, defineObserver, isValidObserverId, type AnyObserver, type DefineObserverInput, type Evidence, type EvidenceRef, type ObserveInput, type Observed, type Observer, type ObserverId, } from "./observer.js";
|
|
9
|
+
export { PowerError, hostWorldPowers, type WorldHttpMethod, type WorldNetworkRequest, type WorldNetworkResponse, type WorldPowers, type WorldProcessRequest, type WorldProcessResult, } from "./powers.js";
|
|
10
|
+
export { fakeRead, type FakeReadSeat, type Read, type ReadSeatsFilter } from "./read.js";
|
|
11
|
+
export { SourceError, defineSource, isValidSourceId, type AnySource, type DefineSourceInput, type Source, type SourceEvent, type SourceEventData, type SourceEventFields, type SourceChoice, type SourceEventIssue, type SourceFieldsOf, type SourceIdOf, type SourceOptionsOf, type SourcesConfig, type SourceId, type SourceLast, type SourcePollInput, type SourcePollReply, } from "./source.js";
|
|
12
|
+
export { EvaluatorError, defineEvaluator, isValidEvaluatorId, type AnyEvaluator, type Evaluation, type EvaluatorArgs, type EvaluatorId, type Evaluator, type StdEvaluatorId, } from "./evaluator.js";
|
|
13
|
+
export { QueryError, bindQuery, decodeQueryRows, defineQuery, type NoQueryArgs, type Query, type QueryArg, type QueryArgInput, type QueryArgs, type QueryBinding, type QueryParam, type QueryRowIssue, type QueryRowIssuePath, type QueryRowResult, type QueryRowSchema, } from "./query.js";
|
|
14
|
+
export { ack, ActionError, bound, check, defineAction, defineClass, isValidActionId, message, msg, openOnMiss, redeliver, role, roleBrief, roleView, type AckDef, type Action, type ActionId, type AnyAction, type AnyAuthClass, type AnyCheck, type AnyMessageKind, type AnyNamedBound, type AnyRole, type ArgsForContract, type AuthClass, type BoundByFieldInput, type BoundSpecInput, type CallActionEffectNode, type Check, type CheckNeedNode, type DelegationInput, type InlineBound, type MessageArgRef, type MessageKind, type MissActionDef, type MissArgInput, type NamedBound, type ProtocolTarget, type Role, type RunnableAction, type RoleBriefOverride, type RoleViewOverride, type SeatLabelsDef, type StepBoundInput, } from "./pieces.js";
|
|
15
|
+
export { answer, anyOf, append, authorize, boundReached, childrenEnded, childrenEndedIn, childrenIn, emit, openChild, protocol, protocolRef, received, set, step, withGuide, type AnswerNeedOpts, type AnyProtocol, type AnyProtocolRef, type AnyStep, type ChildFilterInput, type Effect, type FieldHandlesOfProtocolData, type Need, type Protocol, type ProtocolAckOverride, type ProtocolDataInput, type ProtocolRef, type SeatLabelReq, type Step, } from "./protocol.js";
|
|
16
|
+
export { contract, t, type AnnotationsInput, type AnyContract, type AnyFieldSchemaEntry, type AnyStructContract, type AnyStructType, type AnyTaggedStruct, type AnyTypeDef, type AnyUnionType, type ArrayOpts, type BooleanOpts, type Brand, type Contract, type FieldHandlesOf, type FieldSchemaMap, type FlattenedUnionType, type Infer, type InferStruct, type NumberOpts, type OptionalType, type StringOpts, type StructContract, type StructGuideOpts, type StructOpts, type StructType, type TaggedGuideOpts, type TaggedOpts, type TaggedStructType, type TypeDef, type UnionMemberInput, type UnionOpts, type UnionType, type VariantsOf, } from "./schema.js";
|
|
17
|
+
export type { ActionDecl, ArgValue, Audience, BoundByFieldDecl, BoundDecl, BoundRefDecl, BriefPiece, CheckDecl, CheckObserveDecl, ChildFilterDecl, ClassDecl, DelegationDecl, EffectDecl, EffortLevel, EngineManagedFieldPolicy, FallbackSeatBindingDecl, FieldByFieldDecl, GitGrantDecl, GranteeGrantsDecl, HooksDecl, HttpMethod, JsonObject, JsonPrimitive, JsonValue, MessageDecl, MessageFieldName, MissActionDecl, MissArgDecl, NeedDecl, NetworkGrantDecl, NetworkScheme, NonEmpty, ProcessGrantDecl, ProtocolDecl, RecordMode, RootGrantDecl, RoleBindingDecl, RoleDecl, RosterDecl, SchemaAnnotations, SeatBindingDecl, SeatLabelNeedDecl, SeatLabelsDecl, SpecAckDecl, StepBoundDecl, StepDecl, StructFieldDecl, TelarSpecV1, TypeSchema, ViewKind, ViewPolicyDecl, } from "./types.js";
|
|
18
|
+
export { cause, engine, field, fields, fromAnswer, literal, seat, type AnswerRef, type AnyArgRef, type ArgInput, type ArgMapInput, type CauseRef, type EngineByFieldOpts, type EngineDigestOpts, type EngineFieldDef, type EngineFieldOpts, type FieldRef, type FieldTable, type LiteralRef, type ProtocolFieldEntry, type ProtocolFieldMap, type RecordInput, type SeatRef, } from "./values.js";
|
|
19
|
+
export { decodeSendHookArgs, decodeSendVerdict, type SendHookArgs, type SendHookCase, type SendHookSeat, type SendHookSubject, type SendOrigin, type SendVerdict, } from "./send-hook.js";
|
|
20
|
+
export type { ShowCase, ShowSeat, ShowSeatBinding } from "./show.js";
|
package/dist/spec.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { PluginCallError, defineInstallation, } from "./install.js";
|
|
2
|
+
export { SpecCompileError, compile, installation, } from "./compile.js";
|
|
3
|
+
export { guide } from "./guide.js";
|
|
4
|
+
export { mergeSeating, } from "./seating.js";
|
|
5
|
+
export { RunnerError, defineRunner, isValidRunnerId, validateRunnerOptions, validateStandard, } from "./runner.js";
|
|
6
|
+
export { formatIsoUtc, parseIsoUtc, zoneOffset } from "./iso.js";
|
|
7
|
+
export { ObserverError, defineObserver, isValidObserverId, } from "./observer.js";
|
|
8
|
+
export { PowerError, hostWorldPowers, } from "./powers.js";
|
|
9
|
+
export { fakeRead } from "./read.js";
|
|
10
|
+
export { SourceError, defineSource, isValidSourceId, } from "./source.js";
|
|
11
|
+
export { EvaluatorError, defineEvaluator, isValidEvaluatorId, } from "./evaluator.js";
|
|
12
|
+
export { QueryError, bindQuery, decodeQueryRows, defineQuery, } from "./query.js";
|
|
13
|
+
export { ack, ActionError, bound, check, defineAction, defineClass, isValidActionId, message, msg, openOnMiss, redeliver, role, roleBrief, roleView, } from "./pieces.js";
|
|
14
|
+
export { answer, anyOf, append, authorize, boundReached, childrenEnded, childrenEndedIn, childrenIn, emit, openChild, protocol, protocolRef, received, set, step, withGuide, } from "./protocol.js";
|
|
15
|
+
export { contract, t, } from "./schema.js";
|
|
16
|
+
export { cause, engine, field, fields, fromAnswer, literal, seat, } from "./values.js";
|
|
17
|
+
export { decodeSendHookArgs, decodeSendVerdict, } from "./send-hook.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type StandardSchemaIssuePath = readonly (PropertyKey | {
|
|
2
|
+
readonly key: PropertyKey;
|
|
3
|
+
})[];
|
|
4
|
+
export interface StandardSchemaIssue {
|
|
5
|
+
readonly message: string;
|
|
6
|
+
readonly path?: StandardSchemaIssuePath | undefined;
|
|
7
|
+
}
|
|
8
|
+
export type StandardSchemaResult<Output> = {
|
|
9
|
+
readonly value: Output;
|
|
10
|
+
readonly issues?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
readonly issues: readonly StandardSchemaIssue[];
|
|
13
|
+
};
|
|
14
|
+
/** A Standard Schema (v1). An Effect schema becomes one through `Schema.toStandardSchemaV1`. */
|
|
15
|
+
export interface StandardSchema<Output = unknown> {
|
|
16
|
+
readonly "~standard": {
|
|
17
|
+
readonly version: 1;
|
|
18
|
+
readonly vendor: string;
|
|
19
|
+
readonly validate: (value: unknown) => StandardSchemaResult<Output> | PromiseLike<StandardSchemaResult<Output>>;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Query } from "../query.js";
|
|
2
|
+
export interface JudgmentAccuracyRow {
|
|
3
|
+
readonly question: string;
|
|
4
|
+
readonly questionVersion: string;
|
|
5
|
+
readonly rung: number;
|
|
6
|
+
readonly labelled: number;
|
|
7
|
+
readonly correct: number;
|
|
8
|
+
readonly unlabelled: number;
|
|
9
|
+
readonly accuracy: number | null;
|
|
10
|
+
}
|
|
11
|
+
/** Per question, version and rung: how many confident answers a later override labelled, and how many it confirmed. */
|
|
12
|
+
export declare const judgmentAccuracy: Query<JudgmentAccuracyRow>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { defineQuery } from "../query.js";
|
|
2
|
+
const COLUMNS = new Set([
|
|
3
|
+
"question",
|
|
4
|
+
"questionVersion",
|
|
5
|
+
"rung",
|
|
6
|
+
"labelled",
|
|
7
|
+
"correct",
|
|
8
|
+
"unlabelled",
|
|
9
|
+
"accuracy",
|
|
10
|
+
]);
|
|
11
|
+
function isRec(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
function nonEmpty(row, key, issues) {
|
|
15
|
+
const value = row[key];
|
|
16
|
+
if (typeof value === "string" && value.length > 0)
|
|
17
|
+
return value;
|
|
18
|
+
issues.push({ message: "expected a non-empty string", path: [key] });
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
function count(row, key, issues) {
|
|
22
|
+
const value = row[key];
|
|
23
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0)
|
|
24
|
+
return value;
|
|
25
|
+
issues.push({ message: "expected a count", path: [key] });
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
function ratio(row, issues) {
|
|
29
|
+
const value = row["accuracy"];
|
|
30
|
+
if (value === null || (typeof value === "number" && value >= 0 && value <= 1))
|
|
31
|
+
return value;
|
|
32
|
+
issues.push({ message: "expected null or a number from 0 to 1", path: ["accuracy"] });
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const rowSchema = {
|
|
36
|
+
"~standard": {
|
|
37
|
+
version: 1,
|
|
38
|
+
vendor: "telar.std",
|
|
39
|
+
validate: (value) => {
|
|
40
|
+
if (!isRec(value))
|
|
41
|
+
return { issues: [{ message: "expected an object" }] };
|
|
42
|
+
const issues = Object.keys(value)
|
|
43
|
+
.filter((key) => !COLUMNS.has(key))
|
|
44
|
+
.map((key) => ({ message: "unexpected column", path: [key] }));
|
|
45
|
+
const row = {
|
|
46
|
+
question: nonEmpty(value, "question", issues),
|
|
47
|
+
questionVersion: nonEmpty(value, "questionVersion", issues),
|
|
48
|
+
rung: count(value, "rung", issues),
|
|
49
|
+
labelled: count(value, "labelled", issues),
|
|
50
|
+
correct: count(value, "correct", issues),
|
|
51
|
+
unlabelled: count(value, "unlabelled", issues),
|
|
52
|
+
accuracy: ratio(value, issues),
|
|
53
|
+
};
|
|
54
|
+
return issues.length > 0 ? { issues } : { value: row };
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
const SQL = `
|
|
59
|
+
WITH answers AS (
|
|
60
|
+
SELECT f.case_id AS judgment,
|
|
61
|
+
json_extract(f.payload, '$.value.question') AS question,
|
|
62
|
+
json_extract(f.payload, '$.value.questionVersion') AS questionVersion,
|
|
63
|
+
json_extract(f.payload, '$.value.rung') AS rung,
|
|
64
|
+
json_extract(f.payload, '$.value.option') AS option,
|
|
65
|
+
json_extract(f.payload, '$.value.probability') AS probability
|
|
66
|
+
FROM facts f
|
|
67
|
+
WHERE f.kind = 'case-data-recorded'
|
|
68
|
+
AND json_extract(f.payload, '$.field') = 'answers'
|
|
69
|
+
AND json_extract(f.payload, '$.mode') = 'append'
|
|
70
|
+
AND json_extract(f.payload, '$.value.probability') IS NOT NULL
|
|
71
|
+
),
|
|
72
|
+
predictions AS (
|
|
73
|
+
SELECT a.* FROM answers a
|
|
74
|
+
WHERE a.probability >= (
|
|
75
|
+
SELECT json_extract(c.payload, '$.args.params.thresholds[' || a.rung || ']')
|
|
76
|
+
FROM facts c
|
|
77
|
+
WHERE c.kind = 'check-observed' AND c.case_id = a.judgment
|
|
78
|
+
AND json_extract(c.payload, '$.check') = a.question || '.policy'
|
|
79
|
+
LIMIT 1
|
|
80
|
+
)
|
|
81
|
+
),
|
|
82
|
+
overrides AS (
|
|
83
|
+
SELECT json_extract(o.payload, '$.data.judgment') AS judgment,
|
|
84
|
+
json_extract(o.payload, '$.protocol') AS protocol,
|
|
85
|
+
closed.seq AS closedSeq,
|
|
86
|
+
(SELECT json_extract(d.payload, '$.value') FROM facts d
|
|
87
|
+
WHERE d.case_id = o.case_id AND d.kind = 'case-data-recorded'
|
|
88
|
+
AND json_extract(d.payload, '$.field') = 'option'
|
|
89
|
+
ORDER BY d.seq DESC LIMIT 1) AS truth
|
|
90
|
+
FROM facts o
|
|
91
|
+
JOIN facts closed ON closed.case_id = o.case_id AND closed.kind = 'case-closed'
|
|
92
|
+
WHERE o.kind = 'case-opened' AND json_extract(o.payload, '$.data.judgment') IS NOT NULL
|
|
93
|
+
),
|
|
94
|
+
latest AS (
|
|
95
|
+
SELECT o.judgment, o.protocol, o.truth FROM overrides o
|
|
96
|
+
WHERE o.closedSeq = (
|
|
97
|
+
SELECT MAX(x.closedSeq) FROM overrides x
|
|
98
|
+
WHERE x.judgment = o.judgment AND x.protocol = o.protocol
|
|
99
|
+
)
|
|
100
|
+
),
|
|
101
|
+
labelled AS (
|
|
102
|
+
SELECT p.question, p.questionVersion, p.rung, p.option, l.truth
|
|
103
|
+
FROM predictions p
|
|
104
|
+
LEFT JOIN latest l ON l.judgment = p.judgment AND l.protocol = p.question || '-override'
|
|
105
|
+
)
|
|
106
|
+
SELECT question, questionVersion, rung,
|
|
107
|
+
SUM(truth IS NOT NULL) AS labelled,
|
|
108
|
+
SUM(truth IS NOT NULL AND truth = option) AS correct,
|
|
109
|
+
SUM(truth IS NULL) AS unlabelled,
|
|
110
|
+
CASE WHEN SUM(truth IS NOT NULL) = 0 THEN NULL
|
|
111
|
+
ELSE 1.0 * SUM(truth IS NOT NULL AND truth = option) / SUM(truth IS NOT NULL) END
|
|
112
|
+
AS accuracy
|
|
113
|
+
FROM labelled
|
|
114
|
+
GROUP BY question, questionVersion, rung
|
|
115
|
+
ORDER BY question, questionVersion, rung
|
|
116
|
+
`;
|
|
117
|
+
/** Per question, version and rung: how many confident answers a later override labelled, and how many it confirmed. */
|
|
118
|
+
export const judgmentAccuracy = defineQuery({
|
|
119
|
+
name: "judgment-accuracy",
|
|
120
|
+
sql: SQL,
|
|
121
|
+
row: rowSchema,
|
|
122
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type AnyContract, type AnyRole, type Contract, type MissActionDef, type NonEmpty, type Protocol, type ProtocolTarget, type TaggedStructType, type TypeDef } from "../spec.js";
|
|
2
|
+
export declare const HOUR_MS: 3600000;
|
|
3
|
+
export declare function defaultMissPolicy(missedAckTarget: ProtocolTarget, responsible: AnyRole): readonly [MissActionDef, MissActionDef];
|
|
4
|
+
export declare const missedAckAnswer: Contract<"missed-ack-answer", TaggedStructType<"Handled", {
|
|
5
|
+
readonly note: TypeDef<string>;
|
|
6
|
+
}>, {
|
|
7
|
+
readonly _tag: "Handled";
|
|
8
|
+
readonly note: string;
|
|
9
|
+
}, "Handled">;
|
|
10
|
+
export declare function missedAckProtocol(def: {
|
|
11
|
+
readonly name?: string | undefined;
|
|
12
|
+
readonly responsible: AnyRole | NonEmpty<AnyRole>;
|
|
13
|
+
readonly answerShape?: AnyContract | undefined;
|
|
14
|
+
}): Protocol<string, "open" | "handling" | "closed", "closed">;
|
package/dist/std/ack.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { answer, contract, engine, fields, fromAnswer, msg, openOnMiss, protocol, redeliver, set, step, t, } from "../spec.js";
|
|
2
|
+
import { ENGINEERING_TEXT_MAX, engineeringText } from "./brief.js";
|
|
3
|
+
export const HOUR_MS = 3_600_000;
|
|
4
|
+
export function defaultMissPolicy(missedAckTarget, responsible) {
|
|
5
|
+
return Object.freeze([
|
|
6
|
+
redeliver(),
|
|
7
|
+
openOnMiss(missedAckTarget, {
|
|
8
|
+
for: responsible,
|
|
9
|
+
data: {
|
|
10
|
+
message: msg.id,
|
|
11
|
+
messageKind: msg.kind,
|
|
12
|
+
toRole: msg.toRole,
|
|
13
|
+
},
|
|
14
|
+
}),
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
export const missedAckAnswer = contract("missed-ack-answer", t.tagged("Handled", {
|
|
18
|
+
note: engineeringText(ENGINEERING_TEXT_MAX, "How the missed acknowledgement was handled"),
|
|
19
|
+
}));
|
|
20
|
+
export function missedAckProtocol(def) {
|
|
21
|
+
const nonEmpty = t.string({ nonEmpty: true });
|
|
22
|
+
const data = fields({
|
|
23
|
+
message: nonEmpty,
|
|
24
|
+
messageKind: nonEmpty,
|
|
25
|
+
toRole: nonEmpty,
|
|
26
|
+
note: engine(t.optional(engineeringText())),
|
|
27
|
+
});
|
|
28
|
+
return protocol(def.name ?? "missed-ack", {
|
|
29
|
+
states: ["open", "handling", "closed"],
|
|
30
|
+
start: "open",
|
|
31
|
+
final: ["closed"],
|
|
32
|
+
data,
|
|
33
|
+
steps: [
|
|
34
|
+
step("start", { from: "open", to: "handling" }),
|
|
35
|
+
step("handle", {
|
|
36
|
+
from: "handling",
|
|
37
|
+
to: "closed",
|
|
38
|
+
needs: [answer(def.responsible, def.answerShape ?? missedAckAnswer)],
|
|
39
|
+
then: [set(data.note, fromAnswer("note"))],
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type Action, type RunnableAction } from "../pieces.js";
|
|
2
|
+
import { type Contract, type FieldSchemaMap, type OptionalType, type StructContract, type TypeDef } from "../schema.js";
|
|
3
|
+
type Str = TypeDef<string>;
|
|
4
|
+
type Int = TypeDef<number>;
|
|
5
|
+
type Opt<T> = OptionalType<TypeDef<T>>;
|
|
6
|
+
type In<F extends FieldSchemaMap> = StructContract<string, F>;
|
|
7
|
+
type ProcessIn = {
|
|
8
|
+
readonly executable: Str;
|
|
9
|
+
readonly args: Opt<readonly string[]>;
|
|
10
|
+
readonly cwd: Opt<string>;
|
|
11
|
+
};
|
|
12
|
+
type ProcessOut = {
|
|
13
|
+
readonly exitCode: Int;
|
|
14
|
+
readonly stdout: Str;
|
|
15
|
+
readonly stderr: Str;
|
|
16
|
+
};
|
|
17
|
+
type GitFetchIn = {
|
|
18
|
+
readonly repoDir: Str;
|
|
19
|
+
readonly remote: Opt<string>;
|
|
20
|
+
readonly rev: Str;
|
|
21
|
+
};
|
|
22
|
+
type GitFetchOut = {
|
|
23
|
+
readonly fetched: Str;
|
|
24
|
+
readonly stdout: Str;
|
|
25
|
+
};
|
|
26
|
+
type GitGrepCountIn = {
|
|
27
|
+
readonly repoDir: Str;
|
|
28
|
+
readonly pattern: Str;
|
|
29
|
+
readonly paths: Opt<readonly string[]>;
|
|
30
|
+
};
|
|
31
|
+
type GitGrepCountRow = {
|
|
32
|
+
readonly file: string;
|
|
33
|
+
readonly count: number;
|
|
34
|
+
};
|
|
35
|
+
type NetworkIn = {
|
|
36
|
+
readonly scheme: Opt<"http" | "https">;
|
|
37
|
+
readonly authority: Str;
|
|
38
|
+
readonly method: Opt<"GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE">;
|
|
39
|
+
readonly path: Str;
|
|
40
|
+
readonly body: Opt<string>;
|
|
41
|
+
readonly secretRef: Opt<string>;
|
|
42
|
+
};
|
|
43
|
+
type NetworkOut = {
|
|
44
|
+
readonly status: Int;
|
|
45
|
+
readonly body: Str;
|
|
46
|
+
};
|
|
47
|
+
type ReadingPin = {
|
|
48
|
+
readonly branch: string;
|
|
49
|
+
readonly head: string;
|
|
50
|
+
};
|
|
51
|
+
type GitPushIn = {
|
|
52
|
+
readonly repoDir: Str;
|
|
53
|
+
readonly repo: Str;
|
|
54
|
+
readonly branch: Str;
|
|
55
|
+
readonly remote: Opt<string>;
|
|
56
|
+
readonly refspec: Opt<string>;
|
|
57
|
+
readonly force: Opt<boolean>;
|
|
58
|
+
readonly openReadingHeads: Opt<readonly ReadingPin[]>;
|
|
59
|
+
};
|
|
60
|
+
type GitPushOut = {
|
|
61
|
+
readonly repo: Str;
|
|
62
|
+
readonly remote: Str;
|
|
63
|
+
readonly branch: Str;
|
|
64
|
+
readonly localHead: Str;
|
|
65
|
+
readonly stdout: Str;
|
|
66
|
+
readonly stderr: Str;
|
|
67
|
+
};
|
|
68
|
+
type GithubApiIn = {
|
|
69
|
+
readonly apiScheme: Opt<"http" | "https">;
|
|
70
|
+
readonly apiAuthority: Opt<string>;
|
|
71
|
+
readonly secretRef: Opt<string>;
|
|
72
|
+
};
|
|
73
|
+
type GithubChecksIn = GithubApiIn & {
|
|
74
|
+
readonly repo: Str;
|
|
75
|
+
readonly head: Str;
|
|
76
|
+
};
|
|
77
|
+
type GithubCheckRow = {
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly state: "green" | "pending" | "failed";
|
|
80
|
+
};
|
|
81
|
+
type GithubMergeIn = GithubApiIn & {
|
|
82
|
+
readonly repo: Str;
|
|
83
|
+
readonly pr: Int;
|
|
84
|
+
readonly head: Str;
|
|
85
|
+
readonly method: Opt<"merge" | "squash" | "rebase">;
|
|
86
|
+
readonly requiredChecks: Opt<readonly string[]>;
|
|
87
|
+
readonly requiredReadings: Opt<number>;
|
|
88
|
+
readonly readingHeads: Opt<readonly string[]>;
|
|
89
|
+
};
|
|
90
|
+
type GithubMergeOut = {
|
|
91
|
+
readonly merged: TypeDef<boolean>;
|
|
92
|
+
readonly sha: Str;
|
|
93
|
+
readonly message: Str;
|
|
94
|
+
};
|
|
95
|
+
/** The std actions. `process`, `gitFetch` and `gitGrepCount` run in the installation; list them in `defineInstallation({ actions })`. The rest run in the host. */
|
|
96
|
+
export interface StdActions {
|
|
97
|
+
readonly process: RunnableAction<"telar.std/action/process/1", In<ProcessIn>, StructContract<string, ProcessOut>>;
|
|
98
|
+
readonly gitFetch: RunnableAction<"telar.std/action/git-fetch/1", In<GitFetchIn>, StructContract<string, GitFetchOut>>;
|
|
99
|
+
readonly gitGrepCount: RunnableAction<"telar.std/action/git-grep-count/1", In<GitGrepCountIn>, Contract<string, TypeDef<readonly GitGrepCountRow[]>, readonly GitGrepCountRow[]>>;
|
|
100
|
+
readonly network: Action<"telar.std/action/network/1", In<NetworkIn>, StructContract<string, NetworkOut>>;
|
|
101
|
+
readonly gitPush: Action<"telar.std/action/git-push/1", In<GitPushIn>, StructContract<string, GitPushOut>>;
|
|
102
|
+
readonly githubChecks: Action<"telar.std/action/github-checks/1", In<GithubChecksIn>, Contract<string, TypeDef<readonly GithubCheckRow[]>, readonly GithubCheckRow[]>>;
|
|
103
|
+
readonly githubMerge: Action<"telar.std/action/github-merge/1", In<GithubMergeIn>, StructContract<string, GithubMergeOut>>;
|
|
104
|
+
}
|
|
105
|
+
export declare const stdActions: StdActions;
|
|
106
|
+
export {};
|