oui-spec 0.12.0 → 0.13.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/dist/{chunk-C2IMSSJK.js → chunk-3EMDNYQD.js} +25 -4
- package/dist/chunk-3EMDNYQD.js.map +1 -0
- package/dist/{chunk-7KBAHAHV.js → chunk-O3C76FAO.js} +3 -3
- package/dist/{chunk-7KBAHAHV.js.map → chunk-O3C76FAO.js.map} +1 -1
- package/dist/{chunk-RPHHBP7C.cjs → chunk-XHJILEMN.cjs} +32 -32
- package/dist/{chunk-RPHHBP7C.cjs.map → chunk-XHJILEMN.cjs.map} +1 -1
- package/dist/{chunk-BLKQNZFC.cjs → chunk-YOJABWGB.cjs} +25 -3
- package/dist/chunk-YOJABWGB.cjs.map +1 -0
- package/dist/core/index.cjs +8 -8
- package/dist/core/index.d.cts +5 -5
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +2 -2
- package/dist/index.cjs +52 -48
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/react/index.d.cts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/spec/index.cjs +46 -42
- package/dist/spec/index.d.cts +10 -3
- package/dist/spec/index.d.ts +10 -3
- package/dist/spec/index.js +1 -1
- package/dist/{surface-runtime-Ca0oLhb4.d.cts → surface-runtime-BIekR9rL.d.cts} +2 -2
- package/dist/{surface-runtime-BixhN5CJ.d.ts → surface-runtime-DXEFMXK7.d.ts} +2 -2
- package/dist/transport/index.d.cts +3 -3
- package/dist/transport/index.d.ts +3 -3
- package/dist/{types-DLOa7CWj.d.ts → types-6doPwE6g.d.cts} +12 -3
- package/dist/{types-DLOa7CWj.d.cts → types-6doPwE6g.d.ts} +12 -3
- package/dist/{websocket-CoSpb5nB.d.cts → websocket-CCpPMZ5a.d.cts} +1 -1
- package/dist/{websocket-Bf7xMzs1.d.ts → websocket-DHbDDwvt.d.ts} +1 -1
- package/package.json +1 -1
- package/spec/OUI-SPEC-v0.1.md +10 -1
- package/dist/chunk-BLKQNZFC.cjs.map +0 -1
- package/dist/chunk-C2IMSSJK.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkYOJABWGB_cjs = require('./chunk-YOJABWGB.cjs');
|
|
4
4
|
var chunk2FFUDX2L_cjs = require('./chunk-2FFUDX2L.cjs');
|
|
5
5
|
|
|
6
6
|
// src/core/brand.ts
|
|
@@ -10,9 +10,9 @@ function brand(value) {
|
|
|
10
10
|
|
|
11
11
|
// src/core/define-surface.ts
|
|
12
12
|
function defineSurface(definition) {
|
|
13
|
-
if (definition.id ===
|
|
13
|
+
if (definition.id === chunkYOJABWGB_cjs.OUI_RUNTIME_SURFACE) {
|
|
14
14
|
throw new Error(
|
|
15
|
-
`[OUI] "${
|
|
15
|
+
`[OUI] "${chunkYOJABWGB_cjs.OUI_RUNTIME_SURFACE}" is the surface runtime's own id: give the surface another`
|
|
16
16
|
);
|
|
17
17
|
}
|
|
18
18
|
const actionIds = /* @__PURE__ */ new Set();
|
|
@@ -194,7 +194,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
194
194
|
const indexOf = (surface) => {
|
|
195
195
|
let index = indexes.get(surface);
|
|
196
196
|
if (!index)
|
|
197
|
-
indexes.set(surface, index =
|
|
197
|
+
indexes.set(surface, index = chunkYOJABWGB_cjs.surfaceIndex(manifestOf(surface)));
|
|
198
198
|
return index;
|
|
199
199
|
};
|
|
200
200
|
let nextKey = 1;
|
|
@@ -235,7 +235,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
235
235
|
return "it needs the user's approval, and the request carries none";
|
|
236
236
|
let hash;
|
|
237
237
|
try {
|
|
238
|
-
hash = await
|
|
238
|
+
hash = await chunkYOJABWGB_cjs.argsHash(request.params ?? {});
|
|
239
239
|
} catch (err) {
|
|
240
240
|
return `its params cannot be checked against an approval: ${err instanceof Error ? err.message : String(err)}`;
|
|
241
241
|
}
|
|
@@ -468,7 +468,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
470
|
async function withAttachments(action, params) {
|
|
471
|
-
const misplaced =
|
|
471
|
+
const misplaced = chunkYOJABWGB_cjs.misplacedAttachmentInputs(action?.input);
|
|
472
472
|
if (misplaced.length > 0) {
|
|
473
473
|
return {
|
|
474
474
|
error: {
|
|
@@ -477,7 +477,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
477
477
|
}
|
|
478
478
|
};
|
|
479
479
|
}
|
|
480
|
-
const wanted =
|
|
480
|
+
const wanted = chunkYOJABWGB_cjs.attachmentIdsIn(action?.input, params);
|
|
481
481
|
if (wanted.length === 0) return { resolved: params };
|
|
482
482
|
const resolver = options.attachments;
|
|
483
483
|
if (!resolver) {
|
|
@@ -490,10 +490,10 @@ function createSurfaceRuntime(options = {}) {
|
|
|
490
490
|
}
|
|
491
491
|
const resolved = { ...params };
|
|
492
492
|
const once = /* @__PURE__ */ new Map();
|
|
493
|
-
for (const { path, input } of
|
|
493
|
+
for (const { path, input } of chunkYOJABWGB_cjs.attachmentInputs(action?.input)) {
|
|
494
494
|
const value = params[path[0]];
|
|
495
495
|
const one = (id) => {
|
|
496
|
-
if (!
|
|
496
|
+
if (!chunkYOJABWGB_cjs.isAttachmentId(id))
|
|
497
497
|
return Promise.reject(
|
|
498
498
|
new Error(`"${String(id)}" is not an attachment's id.`)
|
|
499
499
|
);
|
|
@@ -530,7 +530,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
530
530
|
}
|
|
531
531
|
async function run(request) {
|
|
532
532
|
const startedAt = Date.now();
|
|
533
|
-
if (request.surfaceId ===
|
|
533
|
+
if (request.surfaceId === chunkYOJABWGB_cjs.OUI_RUNTIME_SURFACE)
|
|
534
534
|
return builtin(request, startedAt);
|
|
535
535
|
const entry = activeFor(request.surfaceId);
|
|
536
536
|
let result;
|
|
@@ -548,7 +548,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
548
548
|
const declared = entry.surface.actions.find(
|
|
549
549
|
(a) => a.id === request.actionId
|
|
550
550
|
);
|
|
551
|
-
const refusal = declared &&
|
|
551
|
+
const refusal = declared && chunkYOJABWGB_cjs.requiresApproval(declared.effect, declared.confirm) ? await approvalRefusal(request) : null;
|
|
552
552
|
result = refusal ? {
|
|
553
553
|
success: false,
|
|
554
554
|
error: {
|
|
@@ -603,18 +603,18 @@ function createSurfaceRuntime(options = {}) {
|
|
|
603
603
|
surfacesHash: page.surfacesHash
|
|
604
604
|
};
|
|
605
605
|
const fit = {};
|
|
606
|
-
const carried =
|
|
607
|
-
const dataLimit = answerBytes -
|
|
608
|
-
const dataBytes =
|
|
606
|
+
const carried = chunkYOJABWGB_cjs.jsonBytes(out.index ?? out.surfaces) >= answerBytes ? { ...out, index: void 0, surfaces: void 0 } : out;
|
|
607
|
+
const dataLimit = answerBytes - chunkYOJABWGB_cjs.jsonBytes({ ...carried, data: void 0 }) - OBSERVATION_FLOOR_BYTES;
|
|
608
|
+
const dataBytes = chunkYOJABWGB_cjs.jsonBytes(out.data);
|
|
609
609
|
if (dataBytes > Math.max(0, dataLimit)) {
|
|
610
610
|
delete out.data;
|
|
611
611
|
fit.data = { bytes: dataBytes, limit: Math.max(0, dataLimit) };
|
|
612
612
|
}
|
|
613
|
-
const fitted =
|
|
613
|
+
const fitted = chunkYOJABWGB_cjs.fitObservations(
|
|
614
614
|
page.observations,
|
|
615
615
|
Math.max(
|
|
616
616
|
0,
|
|
617
|
-
answerBytes -
|
|
617
|
+
answerBytes - chunkYOJABWGB_cjs.jsonBytes(
|
|
618
618
|
out.data === void 0 ? { ...carried, data: void 0 } : carried
|
|
619
619
|
)
|
|
620
620
|
)
|
|
@@ -635,7 +635,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
635
635
|
});
|
|
636
636
|
const refuse = (code, message) => done({ success: false, error: { code, message } });
|
|
637
637
|
const params = request.params ?? {};
|
|
638
|
-
if (request.actionId ===
|
|
638
|
+
if (request.actionId === chunkYOJABWGB_cjs.OUI_DESCRIBE_ACTION) {
|
|
639
639
|
const asked = params.actions;
|
|
640
640
|
if (!Array.isArray(asked) || asked.length === 0 || !asked.every(
|
|
641
641
|
(a) => a && typeof a === "object" && typeof a.surface === "string" && typeof a.action === "string"
|
|
@@ -656,7 +656,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
656
656
|
missing.push({ surface, action });
|
|
657
657
|
continue;
|
|
658
658
|
}
|
|
659
|
-
const size =
|
|
659
|
+
const size = chunkYOJABWGB_cjs.jsonBytes(definition);
|
|
660
660
|
if (definitions.length > 0 && bytes + size > answerBytes - OBSERVATION_FLOOR_BYTES) {
|
|
661
661
|
deferred.push({ surface, action });
|
|
662
662
|
continue;
|
|
@@ -673,7 +673,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
673
673
|
}
|
|
674
674
|
});
|
|
675
675
|
}
|
|
676
|
-
if (request.actionId ===
|
|
676
|
+
if (request.actionId === chunkYOJABWGB_cjs.OUI_READ_ACTION) {
|
|
677
677
|
const { surface, observation } = params;
|
|
678
678
|
const path = params.path === void 0 ? "" : params.path;
|
|
679
679
|
const offset = params.offset === void 0 ? 0 : params.offset;
|
|
@@ -700,7 +700,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
700
700
|
}
|
|
701
701
|
let value;
|
|
702
702
|
try {
|
|
703
|
-
value =
|
|
703
|
+
value = chunkYOJABWGB_cjs.atPointer(values.get(observation), path);
|
|
704
704
|
} catch (err) {
|
|
705
705
|
return refuse(
|
|
706
706
|
"INVALID_PARAMS",
|
|
@@ -720,7 +720,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
720
720
|
offset,
|
|
721
721
|
offset + limit
|
|
722
722
|
);
|
|
723
|
-
while (rows.length > 1 &&
|
|
723
|
+
while (rows.length > 1 && chunkYOJABWGB_cjs.jsonBytes(rows) > room)
|
|
724
724
|
rows = rows.slice(0, Math.ceil(rows.length / 2));
|
|
725
725
|
const next = offset + rows.length;
|
|
726
726
|
return done({
|
|
@@ -733,7 +733,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
733
733
|
}
|
|
734
734
|
});
|
|
735
735
|
}
|
|
736
|
-
const fitted =
|
|
736
|
+
const fitted = chunkYOJABWGB_cjs.fitObservations(
|
|
737
737
|
{ [surface]: { [observation]: value } },
|
|
738
738
|
room
|
|
739
739
|
);
|
|
@@ -748,7 +748,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
748
748
|
}
|
|
749
749
|
return refuse(
|
|
750
750
|
"ACTION_NOT_FOUND",
|
|
751
|
-
`The runtime answers "${
|
|
751
|
+
`The runtime answers "${chunkYOJABWGB_cjs.OUI_DESCRIBE_ACTION}" and "${chunkYOJABWGB_cjs.OUI_READ_ACTION}"; it has no "${request.actionId}".`
|
|
752
752
|
);
|
|
753
753
|
}
|
|
754
754
|
function answer(result, onReceived) {
|
|
@@ -801,20 +801,20 @@ function createSurfaceRuntime(options = {}) {
|
|
|
801
801
|
}
|
|
802
802
|
if (form === "index") {
|
|
803
803
|
const index = active.map((e) => indexOf(e.surface));
|
|
804
|
-
return { index, observations: obs, surfacesHash:
|
|
804
|
+
return { index, observations: obs, surfacesHash: chunkYOJABWGB_cjs.surfacesHash(index) };
|
|
805
805
|
}
|
|
806
806
|
const surfaces = active.map((e) => manifestOf(e.surface));
|
|
807
807
|
return {
|
|
808
808
|
surfaces,
|
|
809
809
|
observations: obs,
|
|
810
|
-
surfacesHash:
|
|
810
|
+
surfacesHash: chunkYOJABWGB_cjs.surfacesHash(surfaces)
|
|
811
811
|
};
|
|
812
812
|
}
|
|
813
813
|
function snapshot() {
|
|
814
814
|
const page = capture();
|
|
815
815
|
const offered = form === "index" ? { index: page.index } : { surfaces: page.surfaces };
|
|
816
|
-
const offeredBytes =
|
|
817
|
-
const fitted =
|
|
816
|
+
const offeredBytes = chunkYOJABWGB_cjs.jsonBytes(offered);
|
|
817
|
+
const fitted = chunkYOJABWGB_cjs.fitObservations(
|
|
818
818
|
page.observations,
|
|
819
819
|
offeredBytes >= snapshotBytes ? snapshotBytes : snapshotBytes - offeredBytes
|
|
820
820
|
);
|
|
@@ -937,7 +937,7 @@ function createSurfaceRuntime(options = {}) {
|
|
|
937
937
|
};
|
|
938
938
|
},
|
|
939
939
|
grantApproval(grant) {
|
|
940
|
-
if (!grant || typeof grant.approvalId !== "string" || !grant.approvalId || typeof grant.argsHash !== "string" || !
|
|
940
|
+
if (!grant || typeof grant.approvalId !== "string" || !grant.approvalId || typeof grant.argsHash !== "string" || !chunkYOJABWGB_cjs.ARGS_HASH_PATTERN.test(grant.argsHash) || !Number.isFinite(grant.expiresAt)) {
|
|
941
941
|
throw new Error(
|
|
942
942
|
"[OUI] grantApproval needs an approvalId, an args hash and an expiry"
|
|
943
943
|
);
|
|
@@ -1010,7 +1010,7 @@ async function resolveOne(resolver, id, input) {
|
|
|
1010
1010
|
}
|
|
1011
1011
|
if (typeof Blob !== "undefined" && got instanceof Blob) {
|
|
1012
1012
|
const name = got.name ?? id;
|
|
1013
|
-
if (!
|
|
1013
|
+
if (!chunkYOJABWGB_cjs.acceptsMediaType(input, got.type)) throw refuse(name, got.type);
|
|
1014
1014
|
return input.as === "text" ? await got.text() : got;
|
|
1015
1015
|
}
|
|
1016
1016
|
if (got && typeof got === "object" && typeof got.text === "string") {
|
|
@@ -1019,7 +1019,7 @@ async function resolveOne(resolver, id, input) {
|
|
|
1019
1019
|
throw new Error(
|
|
1020
1020
|
"The page's file area gave text where a file was expected."
|
|
1021
1021
|
);
|
|
1022
|
-
if (!
|
|
1022
|
+
if (!chunkYOJABWGB_cjs.acceptsMediaType(input, text.mediaType ?? ""))
|
|
1023
1023
|
throw refuse(text.name ?? id, text.mediaType);
|
|
1024
1024
|
return text.text;
|
|
1025
1025
|
}
|
|
@@ -1055,5 +1055,5 @@ exports.acceptCurrentTurn = acceptCurrentTurn;
|
|
|
1055
1055
|
exports.createOUI = createOUI;
|
|
1056
1056
|
exports.createSurfaceRuntime = createSurfaceRuntime;
|
|
1057
1057
|
exports.defineSurface = defineSurface;
|
|
1058
|
-
//# sourceMappingURL=chunk-
|
|
1059
|
-
//# sourceMappingURL=chunk-
|
|
1058
|
+
//# sourceMappingURL=chunk-XHJILEMN.cjs.map
|
|
1059
|
+
//# sourceMappingURL=chunk-XHJILEMN.cjs.map
|