@fungi.computer/oyster 0.31.2 → 0.33.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.
Files changed (63) hide show
  1. package/README.md +59 -0
  2. package/dist/agent-computer-source.d.ts +1 -0
  3. package/dist/agent-computer-source.js +1 -0
  4. package/dist/app-test-copies.d.ts +87 -0
  5. package/dist/app-test-copies.js +170 -0
  6. package/dist/app-test-copy-page.d.ts +4 -0
  7. package/dist/app-test-copy-page.js +89 -0
  8. package/dist/apps/installation.js +19 -14
  9. package/dist/browser/operations.d.ts +1 -1
  10. package/dist/cloudflare.d.ts +68 -3
  11. package/dist/cloudflare.js +214 -3
  12. package/dist/embed-metafiles.js +2 -2
  13. package/dist/embed-scripts.js +2 -2
  14. package/dist/host.d.ts +16 -0
  15. package/dist/host.js +309 -1
  16. package/dist/installation-operations.d.ts +247 -8
  17. package/dist/installation-operations.js +145 -7
  18. package/dist/installation-recovery-page.d.ts +24 -0
  19. package/dist/installation-recovery-page.js +168 -0
  20. package/dist/older-oyster-store.d.ts +1 -1
  21. package/dist/older-oyster-store.js +2 -4
  22. package/dist/page/mount.d.ts +2 -101
  23. package/dist/page/mount.js +1 -22
  24. package/dist/page-config.d.ts +102 -0
  25. package/dist/page-config.js +24 -0
  26. package/dist/page-script.js +1 -1
  27. package/dist/platform-skills.generated.d.ts +11 -0
  28. package/dist/platform-skills.generated.js +16 -0
  29. package/dist/recovery-style.d.ts +5 -0
  30. package/dist/recovery-style.js +32 -0
  31. package/dist/standalone/agents.d.ts +1 -1
  32. package/dist/standalone/agents.js +1 -0
  33. package/dist/standalone/computer-skill-source.d.ts +13 -2
  34. package/dist/standalone/computer-skill-source.js +80 -6
  35. package/dist/standalone/workflow-host.d.ts +4 -4
  36. package/dist/standalone/workflows.d.ts +9 -9
  37. package/dist/storage-frame.d.ts +3 -3
  38. package/dist/upgrade/old-worker-http.d.ts +2 -0
  39. package/dist/upgrade/old-worker-http.js +22 -0
  40. package/dist/upgrade/old-worker-readonly.d.ts +14 -0
  41. package/dist/upgrade/old-worker-readonly.js +22 -0
  42. package/dist/upgrade/old-worker-sql.d.ts +10 -0
  43. package/dist/upgrade/old-worker-sql.js +68 -0
  44. package/dist/upgrade/old-worker-stream.d.ts +12 -0
  45. package/dist/upgrade/old-worker-stream.js +54 -0
  46. package/dist/upgrade/private-stage.d.ts +23 -0
  47. package/dist/upgrade/private-stage.js +109 -0
  48. package/dist/upgrade/standalone-001.d.ts +16 -0
  49. package/dist/upgrade/standalone-001.js +31 -0
  50. package/dist/upgrade/standalone-01.d.ts +37 -0
  51. package/dist/upgrade/standalone-01.js +55 -0
  52. package/dist/upgrade/standalone-02.d.ts +37 -0
  53. package/dist/upgrade/standalone-02.js +55 -0
  54. package/dist/workers.d.ts +16 -2
  55. package/dist/workers.js +117 -7
  56. package/docs/api/README.md +8 -3
  57. package/docs/api/apps.md +33 -33
  58. package/docs/api/cloudflare.md +57 -0
  59. package/docs/api/host.md +223 -14
  60. package/docs/api/page/mount.md +10 -78
  61. package/docs/api/workers-git.md +246 -1
  62. package/docs/api/workers.md +352 -14
  63. package/package.json +23 -10
package/dist/host.d.ts CHANGED
@@ -4,6 +4,8 @@ import type { WorkflowControl } from "./workflows.js";
4
4
  import type { ComputerControlPort } from "./computer-control-port.js";
5
5
  import { type InstallationOperations } from "./installation-operations.js";
6
6
  export type { InstallationOperations };
7
+ import { type AppTestCopy, type AppTestCopyAuthority } from "./app-test-copies.js";
8
+ export { appTestCopySchema, appTestCopyAuthoritySchema, type AppTestCopy, type AppTestCopyAuthority, } from "./app-test-copies.js";
7
9
  import type { KnapsackComputer } from "@fungi.computer/knapsack";
8
10
  import type { TenantPrincipal } from "./tenant.js";
9
11
  import { type GillCall, type GillReply } from "@fungi.computer/gills";
@@ -33,6 +35,7 @@ import { type GitDoorTarget } from "./git.js";
33
35
  import type { AdmittedGit } from "./git-admission.js";
34
36
  import { type PageAssetLoader } from "./page-assets.js";
35
37
  import { type AppApi } from "@fungi.computer/puffball";
38
+ import type { AppMethodCallContext } from "@fungi.computer/puffball/app";
36
39
  export { ReleaseError, defaultAssetPolicy, parseRelease, resolveBackend, sha256, verifyRelease, type ArtifactStore, type VerifiedObjectCache, type VerifiedRelease, } from "./release.js";
37
40
  /** Stable actor identity for host storage and backend attribution. */
38
41
  export declare function oysterPrincipalId(principal: TenantPrincipal): string;
@@ -90,6 +93,19 @@ export type InstanceResult<T> = Readonly<{
90
93
  }>;
91
94
  /** One running App Instance, wherever the host runs it. */
92
95
  export type InstanceHandle = Readonly<{
96
+ /** Optional native App-only siblings; absence is an honest unavailable host. */
97
+ testCopies?: Readonly<{
98
+ /** Open a bounded snapshot or answer its retained creation request. */
99
+ open: (authority: AppTestCopyAuthority, requestId: string) => Promise<InstanceResult<AppTestCopy>>;
100
+ /** Observe the current sibling under fresh source and store fences. */
101
+ inspect: (authority: AppTestCopyAuthority) => Promise<InstanceResult<AppTestCopy | null>>;
102
+ /** Retire only the named resource; delayed discard cannot target a replacement. */
103
+ discard: (authority: AppTestCopyAuthority, copyId: string) => Promise<InstanceResult<boolean>>;
104
+ /** Serve the copied App backend without live host bindings. */
105
+ fetch: (authority: AppTestCopyAuthority, copyId: string, request: Request) => Promise<Response>;
106
+ /** Invoke one admitted declared method with owner attribution, not live grants. */
107
+ call: (authority: AppTestCopyAuthority, copyId: string, name: string, input: OysterJson, caller: AppMethodCallContext) => Promise<InstanceResult<AppMethodReply>>;
108
+ }>;
93
109
  /** Check lifecycle and construction without activating or changing Instance state. */
94
110
  prepare: (state: OwnerState, release: Release) => Promise<InstanceResult<UiBootCheckOutcome | null>>;
95
111
  /** Activate a complete owner state only after its registry selection commits. */
package/dist/host.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import { hostGateFacts, releaseCache } from "./internal/host-gate.js";
2
- import { InstallationOperationError, installationCommandIds, installationRequestIdSchema, installationWaitQuerySchema, maxSettlementWaitMs, } from "./installation-operations.js";
2
+ import { InstallationOperationError, installationCommandIds, installationRequestIdSchema, installationRecoverySelectionSchema, installationWaitQuerySchema, maxSettlementWaitMs, } from "./installation-operations.js";
3
3
  import { completedInstallationResponse, observeInstallation, InstallationObservationError, } from "./installation-client.js";
4
+ import { installationRecoveryFormSchema, appTestCopyDiscardFormSchema, installationRecoveryPage, } from "./installation-recovery-page.js";
5
+ import { sameOriginReadRequest, sameOriginRequest } from "./request-origin.js";
6
+ import { appTestCopySchema, } from "./app-test-copies.js";
7
+ import { appTestCopyPage } from "./app-test-copy-page.js";
8
+ export { appTestCopySchema, appTestCopyAuthoritySchema, } from "./app-test-copies.js";
4
9
  import { instanceRefusalBody, instanceRefusalStatus, } from "./instance-refusal.js";
5
10
  import { appSandbox } from "./app-sandbox.js";
6
11
  import { shellModuleAsset, shellModuleAssetPath, } from "@fungi.computer/puffball/assets";
@@ -658,6 +663,309 @@ export function oysterRouteTable(host) {
658
663
  ? admitted
659
664
  : Response.json(admitted, { status: 202 });
660
665
  });
666
+ table.get("/recovery", owner("direct"), async (context) => {
667
+ const operations = host.installations.operations;
668
+ if (operations === undefined)
669
+ return noStoreRefusal(503, "Installation commands unavailable");
670
+ try {
671
+ let operation = null;
672
+ if (context.req.query("requestId") !== undefined) {
673
+ const key = installationRequestIdSchema.safeParse(context.req.query("requestId"));
674
+ const id = installationIdSchema.safeParse(context.req.query("installationId"));
675
+ if (!key.success || !id.success)
676
+ return noStoreRefusal(400, "Invalid rollback identity");
677
+ operation = await operations.read(key.data, id.data);
678
+ if (operation === null)
679
+ return noStoreRefusal(404, "Installation request not found");
680
+ }
681
+ const installations = (await host.installations.list()).filter((installation) => installation.status !== "deleted");
682
+ const entries = await Promise.all(installations.map(async (installation) => {
683
+ const entry = {
684
+ installation,
685
+ recovery: await operations.recovery(installation.installationId),
686
+ copy: null,
687
+ copyAuthority: null,
688
+ };
689
+ if (installation.status !== "enabled" ||
690
+ installation.instanceId === null)
691
+ return entry;
692
+ const copies = host.instances.get(installation.instanceId, limits).testCopies;
693
+ if (copies === undefined)
694
+ return entry;
695
+ const authority = {
696
+ selection: selectionOf(installation),
697
+ storeGeneration: await host.installations.generation(),
698
+ };
699
+ let observed;
700
+ try {
701
+ observed = await copies.inspect(authority);
702
+ }
703
+ catch (cause) {
704
+ // Optional copy observation must not take down rollback controls.
705
+ console.error("Oyster recovery: test copy unavailable", {
706
+ causeClass: causeClass(cause),
707
+ });
708
+ return entry;
709
+ }
710
+ return observed.ok
711
+ ? { ...entry, copy: observed.value, copyAuthority: authority }
712
+ : entry;
713
+ }));
714
+ const confirm = installationIdSchema.safeParse(context.req.query("confirm"));
715
+ return await installationRecoveryPage(entries, operation, confirm.success ? confirm.data : null);
716
+ }
717
+ catch (cause) {
718
+ if (cause instanceof InstallationOperationError)
719
+ return installationOperationRefusal(cause);
720
+ throw cause;
721
+ }
722
+ });
723
+ table.post("/recovery/:installationId/rollback", owner("direct"), async (context, { principal }) => {
724
+ if (!sameOriginRequest(context.req.raw))
725
+ return noStoreRefusal(403, "Same origin required");
726
+ const id = installationIdSchema.safeParse(context.req.param("installationId"));
727
+ if (!id.success)
728
+ return noStoreRefusal(400, "Invalid installation id");
729
+ let form;
730
+ try {
731
+ form = installationRecoveryFormSchema.parse(await context.req.parseBody());
732
+ }
733
+ catch {
734
+ return noStoreRefusal(400, "Invalid rollback request");
735
+ }
736
+ const operations = host.installations.operations;
737
+ if (operations === undefined)
738
+ return noStoreRefusal(503, "Installation commands unavailable");
739
+ try {
740
+ await operations.admit({
741
+ ...form,
742
+ installationId: id.data,
743
+ actor: principal.actor,
744
+ intent: "rollback",
745
+ origin: "owner-direct",
746
+ });
747
+ const query = new URLSearchParams({
748
+ installationId: id.data,
749
+ requestId: form.requestId,
750
+ });
751
+ return new Response(null, {
752
+ status: 303,
753
+ headers: {
754
+ Location: `/recovery?${query.toString()}`,
755
+ "Cache-Control": "no-store",
756
+ },
757
+ });
758
+ }
759
+ catch (cause) {
760
+ if (cause instanceof InstallationOperationError)
761
+ return installationOperationRefusal(cause);
762
+ throw cause;
763
+ }
764
+ }, {
765
+ middleware: [
766
+ bodyLimit({
767
+ maxSize: 64 * 1024,
768
+ onError: () => noStoreRefusal(413, "Recovery request too large"),
769
+ }),
770
+ ],
771
+ });
772
+ const copyOwner = async (context, principal) => {
773
+ // Provenance first: no installation or copy state answers a foreign page.
774
+ if (context.req.method === "GET"
775
+ ? !sameOriginReadRequest(context.req.raw)
776
+ : !sameOriginRequest(context.req.raw))
777
+ return noStoreRefusal(403, "Same origin required");
778
+ const id = installationIdSchema.safeParse(context.req.param("installationId"));
779
+ if (!id.success)
780
+ return noStoreRefusal(400, "Invalid installation id");
781
+ const installation = await host.installations.get(id.data);
782
+ if (installation?.status !== "enabled" || installation.instanceId === null)
783
+ return noStoreRefusal(404, "Enabled App Instance required");
784
+ const copies = host.instances.get(installation.instanceId, limits).testCopies;
785
+ if (copies === undefined)
786
+ return noStoreRefusal(503, "Native test copies unavailable");
787
+ return {
788
+ principal,
789
+ installation,
790
+ copies,
791
+ authority: {
792
+ selection: selectionOf(installation),
793
+ storeGeneration: await host.installations.generation(),
794
+ },
795
+ };
796
+ };
797
+ const copyForm = async (context, schema) => {
798
+ try {
799
+ return schema.parse(await context.req.parseBody());
800
+ }
801
+ catch {
802
+ return noStoreRefusal(400, "Invalid test copy request");
803
+ }
804
+ };
805
+ const copyBodyLimit = {
806
+ middleware: [
807
+ bodyLimit({
808
+ maxSize: 64 * 1024,
809
+ onError: () => noStoreRefusal(413, "Recovery request too large"),
810
+ }),
811
+ ],
812
+ };
813
+ table.post("/recovery/:installationId/test-copy", owner("direct"), async (context, { principal }) => {
814
+ const copyOwned = await copyOwner(context, principal);
815
+ if (copyOwned instanceof Response)
816
+ return copyOwned;
817
+ const form = await copyForm(context, installationRecoveryFormSchema);
818
+ if (form instanceof Response)
819
+ return form;
820
+ if (form.authorityVersion !==
821
+ copyOwned.authority.selection.authorityVersion ||
822
+ form.storeGeneration !== copyOwned.authority.storeGeneration)
823
+ return noStoreRefusal(409, "Stale copy authority");
824
+ const opened = await copyOwned.copies.open(copyOwned.authority, form.requestId);
825
+ if (!opened.ok)
826
+ return instanceRefusal(opened.code, opened.causeClass);
827
+ return new Response(null, {
828
+ status: 303,
829
+ headers: {
830
+ Location: `/recovery/${copyOwned.installation.installationId}/test-copy/${opened.value.copyId}`,
831
+ "Cache-Control": "no-store",
832
+ },
833
+ });
834
+ }, copyBodyLimit);
835
+ table.post("/recovery/:installationId/test-copy/:copyId/discard", owner("direct"), async (context, { principal }) => {
836
+ const copyOwned = await copyOwner(context, principal);
837
+ if (copyOwned instanceof Response)
838
+ return copyOwned;
839
+ const form = await copyForm(context, appTestCopyDiscardFormSchema);
840
+ if (form instanceof Response)
841
+ return form;
842
+ if (form.authorityVersion !==
843
+ copyOwned.authority.selection.authorityVersion ||
844
+ form.storeGeneration !== copyOwned.authority.storeGeneration ||
845
+ form.copyId !== context.req.param("copyId"))
846
+ return noStoreRefusal(409, "Stale copy authority");
847
+ const discarded = await copyOwned.copies.discard(copyOwned.authority, form.copyId);
848
+ if (!discarded.ok)
849
+ return instanceRefusal(discarded.code, discarded.causeClass);
850
+ return new Response(null, {
851
+ status: 303,
852
+ headers: { Location: "/recovery", "Cache-Control": "no-store" },
853
+ });
854
+ }, copyBodyLimit);
855
+ table.get("/recovery/:installationId/test-copy/:copyId", owner("direct"), async (context, { principal }) => {
856
+ const copyOwned = await copyOwner(context, principal);
857
+ if (copyOwned instanceof Response)
858
+ return copyOwned;
859
+ const observed = await copyOwned.copies.inspect(copyOwned.authority);
860
+ if (!observed.ok)
861
+ return instanceRefusal(observed.code, observed.causeClass);
862
+ if (observed.value?.copyId !== context.req.param("copyId"))
863
+ return noStoreRefusal(404, "Test copy expired or discarded");
864
+ return appTestCopyPage(copyOwned.installation.installationId, observed.value, (await releaseOf(copyOwned.installation.release)).declaration, (await assets()).page.path);
865
+ });
866
+ table.put("/recovery/:installationId/test-copy/:copyId/backend", owner("direct"), async (context, { principal }) => {
867
+ const copyOwned = await copyOwner(context, principal);
868
+ if (copyOwned instanceof Response)
869
+ return copyOwned;
870
+ const copyId = appTestCopySchema.shape.copyId.safeParse(context.req.param("copyId"));
871
+ if (!copyId.success)
872
+ return noStoreRefusal(400, "Invalid copy id");
873
+ const request = new Request("https://app.internal/", {
874
+ method: "PUT",
875
+ headers: {
876
+ "Content-Type": "text/plain",
877
+ [appBackendActorHeader]: oysterPrincipalId(copyOwned.principal),
878
+ },
879
+ body: await context.req.text(),
880
+ });
881
+ return copyOwned.copies.fetch(copyOwned.authority, copyId.data, request);
882
+ }, {
883
+ middleware: [
884
+ bodyLimit({
885
+ maxSize: maxBackendBody,
886
+ onError: () => noStoreRefusal(413, "Request too large"),
887
+ }),
888
+ ],
889
+ });
890
+ table.post("/recovery/:installationId/test-copy/:copyId/methods/:name", owner("direct"), async (context, { principal }) => {
891
+ const copyOwned = await copyOwner(context, principal);
892
+ if (copyOwned instanceof Response)
893
+ return copyOwned;
894
+ const copyId = appTestCopySchema.shape.copyId.safeParse(context.req.param("copyId"));
895
+ if (!copyId.success)
896
+ return noStoreRefusal(400, "Invalid copy id");
897
+ const release = await releaseOf(copyOwned.installation.release);
898
+ if (release.api === null)
899
+ return noStoreRefusal(404, "This App declares no methods");
900
+ let input;
901
+ try {
902
+ input = await methodInput(context.req.raw);
903
+ }
904
+ catch (error) {
905
+ return error instanceof MethodBodyTooLarge
906
+ ? noStoreRefusal(413, "Request too large")
907
+ : noStoreRefusal(400, "Method input must be JSON");
908
+ }
909
+ const name = context.req.param("name");
910
+ const admitted = admits(await gateFacts(copyOwned.installation, release, copyOwned.principal), { kind: "method", name, input, via: "ui" });
911
+ if (admitted.kind === "refused")
912
+ return noStoreRefusal(admitted.code === "invalid_input" ? 400 : 403, admitted.code);
913
+ const result = await copyOwned.copies.call(copyOwned.authority, copyId.data, name, input, invocationCallerContext(copyOwned.principal, null));
914
+ return result.ok
915
+ ? methodResponse(result.value)
916
+ : instanceRefusal(result.code, result.causeClass);
917
+ });
918
+ table.get("/api/installations/:installationId/recovery", owner("direct"), async (context) => {
919
+ if (!sameOriginReadRequest(context.req.raw))
920
+ return refusal(403, "Cross-origin recovery refused");
921
+ const id = installationIdSchema.safeParse(context.req.param("installationId"));
922
+ if (!id.success)
923
+ return refusal(400, "Invalid installation id");
924
+ const operations = host.installations.operations;
925
+ if (operations === undefined)
926
+ return refusal(503, "Installation commands unavailable");
927
+ try {
928
+ return Response.json(await operations.recovery(id.data));
929
+ }
930
+ catch (cause) {
931
+ if (cause instanceof InstallationOperationError)
932
+ return installationOperationRefusal(cause);
933
+ throw cause;
934
+ }
935
+ });
936
+ table.post("/api/installations/:installationId/rollback", owner("direct"), async (context, { principal }) => {
937
+ if (!sameOriginReadRequest(context.req.raw))
938
+ return refusal(403, "Cross-origin recovery refused");
939
+ const id = installationIdSchema.safeParse(context.req.param("installationId"));
940
+ const key = installationRequestIdSchema.safeParse(context.req.header("Idempotency-Key"));
941
+ if (!id.success || !key.success)
942
+ return refusal(400, "Invalid rollback identity");
943
+ let selection;
944
+ try {
945
+ selection = installationRecoverySelectionSchema.parse(await context.req.json());
946
+ }
947
+ catch {
948
+ return refusal(400, "Invalid rollback request");
949
+ }
950
+ const operations = host.installations.operations;
951
+ if (operations === undefined)
952
+ return refusal(503, "Installation commands unavailable");
953
+ try {
954
+ return Response.json(await operations.admit({
955
+ ...selection,
956
+ requestId: key.data,
957
+ installationId: id.data,
958
+ actor: principal.actor,
959
+ intent: "rollback",
960
+ origin: "owner-direct",
961
+ }), { status: 202 });
962
+ }
963
+ catch (cause) {
964
+ if (cause instanceof InstallationOperationError)
965
+ return installationOperationRefusal(cause);
966
+ throw cause;
967
+ }
968
+ });
661
969
  table.get("/api/installations/:installationId/status", owner("direct"), async (context) => {
662
970
  const key = installationRequestIdSchema.safeParse(context.req.query("requestId"));
663
971
  if (!key.success)