@sorbetai/plugins 0.0.0-stage → 0.1.0-alpha.16

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.
@@ -0,0 +1,185 @@
1
+ import { H as JsonValueSchema } from "./object-borrow-C81Gj5tq.js";
2
+ import * as s from "@earendil-works/pi-schema";
3
+ import { compile, decodeWith } from "@sorbetai/schema";
4
+ import { isBoolean } from "es-toolkit";
5
+
6
+ //#region src/remote/protocol.ts
7
+ const FacetAddressSchema = s.obj({
8
+ namespace: s.str({ minLength: 1 }),
9
+ typeId: s.str({ minLength: 1 }),
10
+ version: s.int({ minimum: 1 }),
11
+ key: JsonValueSchema
12
+ }, { open: false });
13
+ const FacetContractSchema = s.obj({
14
+ id: s.str({ minLength: 1 }),
15
+ version: s.int({ minimum: 1 }),
16
+ key: s.map(JsonValueSchema),
17
+ methods: s.map(s.obj({
18
+ input: s.map(JsonValueSchema),
19
+ output: s.map(JsonValueSchema)
20
+ }, { open: false }))
21
+ }, { open: false });
22
+ const HandleSchema = { handle: s.str({ minLength: 1 }) };
23
+ const FacetRequestSchema = s.union([
24
+ s.obj({ action: s.lit("hello") }, { open: false }),
25
+ s.obj({ action: s.lit("catalog") }, { open: false }),
26
+ s.obj({
27
+ action: s.lit("acquire"),
28
+ acquisitionId: s.str({ minLength: 1 }),
29
+ address: FacetAddressSchema,
30
+ contract: FacetContractSchema
31
+ }, { open: false }),
32
+ s.obj({
33
+ action: s.lit("lookup"),
34
+ facetId: s.str({ minLength: 1 }),
35
+ acquisitionId: s.str({ minLength: 1 })
36
+ }, { open: false }),
37
+ s.obj({
38
+ action: s.lit("abandon"),
39
+ facetId: s.str({ minLength: 1 }),
40
+ acquisitionId: s.str({ minLength: 1 })
41
+ }, { open: false }),
42
+ s.obj({
43
+ action: s.lit("rehold"),
44
+ facetId: s.str({ minLength: 1 }),
45
+ ...HandleSchema
46
+ }, { open: false }),
47
+ s.obj({
48
+ action: s.lit("call"),
49
+ ...HandleSchema,
50
+ method: s.str({ minLength: 1 }),
51
+ input: JsonValueSchema
52
+ }, { open: false }),
53
+ s.obj({
54
+ action: s.lit("states"),
55
+ ...HandleSchema
56
+ }, { open: false }),
57
+ s.obj({
58
+ action: s.lit("watch"),
59
+ ...HandleSchema,
60
+ name: s.str({ minLength: 1 }),
61
+ after: s.opt(s.int({
62
+ minimum: 0,
63
+ maximum: Number.MAX_SAFE_INTEGER
64
+ }))
65
+ }, { open: false }),
66
+ s.obj({
67
+ action: s.lit("release"),
68
+ acquisitionId: s.str({ minLength: 1 }),
69
+ ...HandleSchema
70
+ }, { open: false })
71
+ ]);
72
+ const FacetIdentitySchema = s.obj({
73
+ facetId: s.str({ minLength: 1 }),
74
+ namespace: s.str({ minLength: 1 }),
75
+ resumable: s.bool()
76
+ }, { open: false });
77
+ const FacetStateSchema = s.obj({
78
+ name: s.str({ minLength: 1 }),
79
+ schema: JsonValueSchema,
80
+ version: s.int({ minimum: 1 }),
81
+ revision: s.int({
82
+ minimum: 0,
83
+ maximum: Number.MAX_SAFE_INTEGER
84
+ }),
85
+ value: JsonValueSchema
86
+ }, { open: false });
87
+ const FacetCatalogSchema = s.obj({
88
+ namespace: s.str({ minLength: 1 }),
89
+ types: s.arr(s.obj({
90
+ contract: FacetContractSchema,
91
+ availability: s.union([s.lit("available"), s.lit("ambiguous")])
92
+ }, { open: true })),
93
+ instances: s.arr(FacetAddressSchema)
94
+ }, { open: false });
95
+ const FacetReplySchema = s.union([s.obj({
96
+ ok: s.lit(true),
97
+ value: JsonValueSchema
98
+ }, { open: false }), s.obj({
99
+ ok: s.lit(false),
100
+ code: s.union([
101
+ s.lit("unavailable"),
102
+ s.lit("denied"),
103
+ s.lit("invalid-request"),
104
+ s.lit("execution-failed"),
105
+ s.lit("outcome-unknown")
106
+ ]),
107
+ message: s.str()
108
+ }, { open: false })]);
109
+ const RequestDecoder = compile(FacetRequestSchema);
110
+ const ReplyDecoder = compile(FacetReplySchema);
111
+ /** Decode peer data at transport ingress; internal consumers adopt this typed reply. */
112
+ const decodeObjectFacetReply = (input) => decodeWith(ReplyDecoder, input);
113
+ /** Decode peer data before reserving or dispatching an Object operation. */
114
+ const decodeObjectFacetRequest = (input) => decodeWith(RequestDecoder, input);
115
+ /** A transport may use this only when it knows the request was not dispatched. */
116
+ var ObjectFacetUnavailableError = class extends Error {
117
+ code = "object-facet-unavailable";
118
+ constructor(message, options) {
119
+ super(message, options);
120
+ this.name = "ObjectFacetUnavailableError";
121
+ }
122
+ };
123
+ const UnavailableFacetSchema = s.obj({ code: s.lit("object-facet-unavailable") }, { open: true });
124
+
125
+ //#endregion
126
+ //#region src/contributions/data-schema.ts
127
+ const Kind = s.union([
128
+ s.lit("object"),
129
+ s.lit("array"),
130
+ s.lit("string"),
131
+ s.lit("number"),
132
+ s.lit("integer"),
133
+ s.lit("boolean"),
134
+ s.lit("null")
135
+ ]);
136
+ const Size = s.int({ minimum: 0 });
137
+ const Child = s.unknown();
138
+ const Branches = s.arr(Child);
139
+ const schemaValidator = compile(s.obj({
140
+ type: s.opt(s.union([Kind, s.arr(Kind)])),
141
+ title: s.opt(s.str()),
142
+ description: s.opt(s.str()),
143
+ default: s.opt(JsonValueSchema),
144
+ examples: s.opt(s.arr(JsonValueSchema)),
145
+ enum: s.opt(s.arr(JsonValueSchema)),
146
+ const: s.opt(JsonValueSchema),
147
+ properties: s.opt(s.map(Child)),
148
+ required: s.opt(s.arr(s.str())),
149
+ additionalProperties: s.opt(s.union([s.bool(), Child])),
150
+ items: s.opt(Child),
151
+ anyOf: s.opt(Branches),
152
+ oneOf: s.opt(Branches),
153
+ allOf: s.opt(Branches),
154
+ not: s.opt(Child),
155
+ minLength: s.opt(Size),
156
+ maxLength: s.opt(Size),
157
+ minItems: s.opt(Size),
158
+ maxItems: s.opt(Size),
159
+ uniqueItems: s.opt(s.bool()),
160
+ minProperties: s.opt(Size),
161
+ maxProperties: s.opt(Size),
162
+ minimum: s.opt(s.num()),
163
+ maximum: s.opt(s.num()),
164
+ exclusiveMinimum: s.opt(s.num()),
165
+ exclusiveMaximum: s.opt(s.num()),
166
+ multipleOf: s.opt(s.num({ exclusiveMinimum: 0 }))
167
+ }, { open: false }));
168
+ function validateDataSchema(input) {
169
+ const pending = [input];
170
+ while (pending.length > 0) {
171
+ const schema = decodeWith(schemaValidator, pending.pop());
172
+ for (const child of Object.values(schema.properties ?? {})) pending.push(child);
173
+ for (const branches of [
174
+ schema.anyOf,
175
+ schema.oneOf,
176
+ schema.allOf
177
+ ]) for (const child of branches ?? []) pending.push(child);
178
+ if (schema.items !== void 0) pending.push(schema.items);
179
+ if (schema.not !== void 0) pending.push(schema.not);
180
+ if (schema.additionalProperties !== void 0 && !isBoolean(schema.additionalProperties)) pending.push(schema.additionalProperties);
181
+ }
182
+ }
183
+
184
+ //#endregion
185
+ export { FacetStateSchema as a, decodeObjectFacetReply as c, FacetIdentitySchema as i, decodeObjectFacetRequest as l, FacetAddressSchema as n, ObjectFacetUnavailableError as o, FacetCatalogSchema as r, UnavailableFacetSchema as s, validateDataSchema as t };
@@ -0,0 +1,178 @@
1
+ import { B as PluginObjects, N as ObjectCatalog, P as ObjectContractDescriptor, j as ObjectAddress, l as PluginToolRegistration } from "./context-i4UGSmNB.js";
2
+ import * as s from "@earendil-works/pi-schema";
3
+ import * as _sorbetai_schema0 from "@sorbetai/schema";
4
+ import * as Effect from "effect/Effect";
5
+ import * as ensure_error1 from "ensure-error";
6
+ import * as Scope from "effect/Scope";
7
+ import * as Semaphore from "effect/Semaphore";
8
+
9
+ //#region src/remote/protocol.d.ts
10
+
11
+ declare const FacetRequestSchema: s.Schema<{
12
+ action: "hello";
13
+ } | {
14
+ action: "catalog";
15
+ } | {
16
+ action: "acquire";
17
+ acquisitionId: string;
18
+ address: {
19
+ namespace: string;
20
+ typeId: string;
21
+ version: number;
22
+ key: string | number | boolean | _sorbetai_schema0.JsonArray | _sorbetai_schema0.JsonObject | null;
23
+ };
24
+ contract: ObjectContractDescriptor;
25
+ } | {
26
+ action: "lookup";
27
+ facetId: string;
28
+ acquisitionId: string;
29
+ } | {
30
+ action: "abandon";
31
+ facetId: string;
32
+ acquisitionId: string;
33
+ } | {
34
+ handle: string;
35
+ action: "rehold";
36
+ facetId: string;
37
+ } | {
38
+ method: string;
39
+ input: string | number | boolean | _sorbetai_schema0.JsonArray | _sorbetai_schema0.JsonObject | null;
40
+ handle: string;
41
+ action: "call";
42
+ } | {
43
+ handle: string;
44
+ action: "states";
45
+ } | {
46
+ name: string;
47
+ handle: string;
48
+ action: "watch";
49
+ after?: number | undefined;
50
+ } | {
51
+ handle: string;
52
+ action: "release";
53
+ acquisitionId: string;
54
+ }>;
55
+ type FacetRequest = s.Static<typeof FacetRequestSchema>;
56
+ declare const FacetReplySchema: s.Schema<{
57
+ ok: true;
58
+ value: string | number | boolean | _sorbetai_schema0.JsonArray | _sorbetai_schema0.JsonObject | null;
59
+ } | {
60
+ ok: false;
61
+ code: "unavailable" | "denied" | "invalid-request" | "execution-failed" | "outcome-unknown";
62
+ message: string;
63
+ }>;
64
+ type FacetReply = s.Static<typeof FacetReplySchema>;
65
+ /** Decode peer data at transport ingress; internal consumers adopt this typed reply. */
66
+ declare const decodeObjectFacetReply: (input: unknown) => {
67
+ ok: true;
68
+ value: string | number | boolean | _sorbetai_schema0.JsonArray | _sorbetai_schema0.JsonObject | null;
69
+ } | {
70
+ ok: false;
71
+ code: "unavailable" | "denied" | "invalid-request" | "execution-failed" | "outcome-unknown";
72
+ message: string;
73
+ };
74
+ /** Decode peer data before reserving or dispatching an Object operation. */
75
+ declare const decodeObjectFacetRequest: (input: unknown) => {
76
+ action: "hello";
77
+ } | {
78
+ action: "catalog";
79
+ } | {
80
+ action: "acquire";
81
+ acquisitionId: string;
82
+ address: {
83
+ namespace: string;
84
+ typeId: string;
85
+ version: number;
86
+ key: string | number | boolean | _sorbetai_schema0.JsonArray | _sorbetai_schema0.JsonObject | null;
87
+ };
88
+ contract: ObjectContractDescriptor;
89
+ } | {
90
+ action: "lookup";
91
+ facetId: string;
92
+ acquisitionId: string;
93
+ } | {
94
+ action: "abandon";
95
+ facetId: string;
96
+ acquisitionId: string;
97
+ } | {
98
+ handle: string;
99
+ action: "rehold";
100
+ facetId: string;
101
+ } | {
102
+ method: string;
103
+ input: string | number | boolean | _sorbetai_schema0.JsonArray | _sorbetai_schema0.JsonObject | null;
104
+ handle: string;
105
+ action: "call";
106
+ } | {
107
+ handle: string;
108
+ action: "states";
109
+ } | {
110
+ name: string;
111
+ handle: string;
112
+ action: "watch";
113
+ after?: number | undefined;
114
+ } | {
115
+ handle: string;
116
+ action: "release";
117
+ acquisitionId: string;
118
+ };
119
+ /** A transport may use this only when it knows the request was not dispatched. */
120
+ declare class ObjectFacetUnavailableError extends Error {
121
+ readonly code = "object-facet-unavailable";
122
+ constructor(message: string, options?: ErrorOptions);
123
+ }
124
+ //#endregion
125
+ //#region src/remote/client.d.ts
126
+ /** A connection is owned by the client Scope. The transport decodes peer replies once at
127
+ * ingress. Rejection after dispatch must never trigger replay. */
128
+ interface ObjectFacetTransport {
129
+ readonly signal: AbortSignal;
130
+ request(request: FacetRequest, signal: AbortSignal): Promise<FacetReply>;
131
+ close(): Promise<void>;
132
+ }
133
+ /** Owns one transport and its holds. Lost acquisition replies close that connection so its
134
+ * owner releases provisional holds; this entry point never reconnects or replays a request. */
135
+ declare const makeRemoteObjectClient: (transport: ObjectFacetTransport) => Effect.Effect<Readonly<{
136
+ objects: Readonly<PluginObjects>;
137
+ objectCapabilities: Readonly<{
138
+ catalog: () => Effect.Effect<ObjectCatalog, Error | ensure_error1.NonError, never>;
139
+ bind: (address: ObjectAddress, method: string, metadata: Pick<PluginToolRegistration, "name" | "description">) => Effect.Effect<{
140
+ tool: Readonly<PluginToolRegistration>;
141
+ borrow: Effect.Effect<void, ensure_error1.NonError, Scope.Scope>;
142
+ }, Error, Scope.Scope>;
143
+ }>;
144
+ }>, never, Scope.Scope>;
145
+ //#endregion
146
+ //#region src/remote/facet.d.ts
147
+ type ObjectFacetPermission = {
148
+ readonly action: 'discover';
149
+ readonly contract: ObjectContractDescriptor;
150
+ } | {
151
+ readonly action: 'inspect' | 'acquire' | 'rehold';
152
+ readonly address: ObjectAddress;
153
+ } | {
154
+ readonly action: 'call';
155
+ readonly address: ObjectAddress;
156
+ readonly method: string;
157
+ } | {
158
+ readonly action: 'observe';
159
+ readonly address: ObjectAddress;
160
+ readonly name?: string;
161
+ };
162
+ interface ObjectFacetOptions {
163
+ /** Bound by the Host to the authenticated connection; the wire cannot supply a principal. */
164
+ readonly authorize: (permission: ObjectFacetPermission) => Effect.Effect<boolean, Error>;
165
+ readonly createId: () => string;
166
+ /** Resumable holds belong to the Host's Facet Scope across authenticated connections.
167
+ * The Host must reuse this facet only for the same principal and close its Scope explicitly. */
168
+ readonly lifetime?: 'connection' | 'resumable';
169
+ }
170
+ /** Scoped opaque holds borrow the origin's existing instances and generations. */
171
+ declare const makeObjectFacet: (objects: PluginObjects, options: ObjectFacetOptions) => Effect.Effect<Readonly<{
172
+ resumable: boolean;
173
+ close: Effect.Effect<void, Error, never>;
174
+ request: (input: FacetRequest, admission?: Semaphore.Semaphore) => Effect.Effect<FacetReply>;
175
+ }>, never, Scope.Scope>;
176
+ type ObjectFacet = Effect.Success<ReturnType<typeof makeObjectFacet>>;
177
+ //#endregion
178
+ export { ObjectFacetTransport as a, FacetRequest as c, decodeObjectFacetRequest as d, makeObjectFacet as i, ObjectFacetUnavailableError as l, ObjectFacetOptions as n, makeRemoteObjectClient as o, ObjectFacetPermission as r, FacetReply as s, ObjectFacet as t, decodeObjectFacetReply as u };