@fungi.computer/agar 0.0.0-stage → 0.0.1

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 (159) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +766 -2
  3. package/dist/agent-message-meta.d.ts +74 -0
  4. package/dist/agent-message-meta.js +63 -0
  5. package/dist/agents.d.ts +170 -0
  6. package/dist/agents.js +218 -0
  7. package/dist/app-build-contract.d.ts +43 -0
  8. package/dist/app-build-contract.js +24 -0
  9. package/dist/apps.d.ts +66 -0
  10. package/dist/apps.js +47 -0
  11. package/dist/backend-declaration.d.ts +6 -0
  12. package/dist/backend-declaration.js +65 -0
  13. package/dist/backend-definition.d.ts +88 -0
  14. package/dist/backend-definition.js +158 -0
  15. package/dist/backend-refusal.d.ts +10 -0
  16. package/dist/backend-refusal.js +10 -0
  17. package/dist/backend.d.ts +30 -0
  18. package/dist/backend.js +28 -0
  19. package/dist/capabilities.d.ts +30 -0
  20. package/dist/capabilities.js +50 -0
  21. package/dist/channels.d.ts +142 -0
  22. package/dist/channels.js +97 -0
  23. package/dist/commands.d.ts +33 -0
  24. package/dist/commands.js +46 -0
  25. package/dist/computer-contracts.d.ts +73 -0
  26. package/dist/computer-contracts.js +57 -0
  27. package/dist/computer.d.ts +294 -0
  28. package/dist/computer.js +319 -0
  29. package/dist/connect.d.ts +11 -0
  30. package/dist/connect.js +211 -0
  31. package/dist/errors.d.ts +34 -0
  32. package/dist/errors.js +106 -0
  33. package/dist/failure.d.ts +2 -0
  34. package/dist/failure.js +9 -0
  35. package/dist/files.d.ts +25 -0
  36. package/dist/files.js +84 -0
  37. package/dist/game-servers.d.ts +530 -0
  38. package/dist/game-servers.js +244 -0
  39. package/dist/gills.d.ts +43 -0
  40. package/dist/gills.js +174 -0
  41. package/dist/git-commit.d.ts +143 -0
  42. package/dist/git-commit.js +251 -0
  43. package/dist/git-rpc.d.ts +310 -0
  44. package/dist/git-rpc.js +166 -0
  45. package/dist/git-steps.d.ts +579 -0
  46. package/dist/git-steps.js +804 -0
  47. package/dist/git-wire.d.ts +33 -0
  48. package/dist/git-wire.js +240 -0
  49. package/dist/git.d.ts +322 -0
  50. package/dist/git.js +98 -0
  51. package/dist/host.d.ts +97 -0
  52. package/dist/host.js +732 -0
  53. package/dist/inbox.d.ts +99 -0
  54. package/dist/inbox.js +184 -0
  55. package/dist/index.d.ts +31 -0
  56. package/dist/index.js +15 -0
  57. package/dist/inference.d.ts +17 -0
  58. package/dist/inference.js +115 -0
  59. package/dist/internal/app-error.d.ts +8 -0
  60. package/dist/internal/app-error.js +36 -0
  61. package/dist/internal/app-session.d.ts +8 -0
  62. package/dist/internal/app-session.js +551 -0
  63. package/dist/internal/back-inputs.d.ts +22 -0
  64. package/dist/internal/back-inputs.js +93 -0
  65. package/dist/internal/browser-bridge.d.ts +30 -0
  66. package/dist/internal/browser-bridge.js +203 -0
  67. package/dist/internal/capabilities.d.ts +13 -0
  68. package/dist/internal/capabilities.js +138 -0
  69. package/dist/internal/commands.d.ts +9 -0
  70. package/dist/internal/commands.js +257 -0
  71. package/dist/internal/disconnect-host.d.ts +7 -0
  72. package/dist/internal/disconnect-host.js +19 -0
  73. package/dist/internal/git-edit-tree.d.ts +6 -0
  74. package/dist/internal/git-edit-tree.js +46 -0
  75. package/dist/internal/memory-fs.d.ts +39 -0
  76. package/dist/internal/memory-fs.js +154 -0
  77. package/dist/internal/protocol.d.ts +116 -0
  78. package/dist/internal/protocol.js +6 -0
  79. package/dist/internal/query-feed.d.ts +23 -0
  80. package/dist/internal/query-feed.js +111 -0
  81. package/dist/internal/result.d.ts +22 -0
  82. package/dist/internal/result.js +61 -0
  83. package/dist/internal/rpc-contract.d.ts +24 -0
  84. package/dist/internal/rpc-contract.js +78 -0
  85. package/dist/internal/schemas.d.ts +307 -0
  86. package/dist/internal/schemas.js +524 -0
  87. package/dist/internal/store.d.ts +8 -0
  88. package/dist/internal/store.js +30 -0
  89. package/dist/internal/terminal-gate.d.ts +17 -0
  90. package/dist/internal/terminal-gate.js +94 -0
  91. package/dist/lifecycle.d.ts +44 -0
  92. package/dist/lifecycle.js +1 -0
  93. package/dist/marketplace.d.ts +159 -0
  94. package/dist/marketplace.js +102 -0
  95. package/dist/media-json.d.ts +181 -0
  96. package/dist/media-json.js +204 -0
  97. package/dist/media-library.d.ts +11 -0
  98. package/dist/media-library.js +15 -0
  99. package/dist/media-request-id.d.ts +7 -0
  100. package/dist/media-request-id.js +16 -0
  101. package/dist/media.d.ts +354 -0
  102. package/dist/media.js +654 -0
  103. package/dist/method-refusal.d.ts +64 -0
  104. package/dist/method-refusal.js +48 -0
  105. package/dist/pending.d.ts +10 -0
  106. package/dist/pending.js +10 -0
  107. package/dist/query.d.ts +76 -0
  108. package/dist/query.js +195 -0
  109. package/dist/react-mount.d.ts +23 -0
  110. package/dist/react-mount.js +108 -0
  111. package/dist/react.d.ts +41 -0
  112. package/dist/react.js +111 -0
  113. package/dist/read-copy.d.ts +103 -0
  114. package/dist/read-copy.js +195 -0
  115. package/dist/roles/files.d.ts +295 -0
  116. package/dist/roles/files.js +184 -0
  117. package/dist/root.d.ts +21 -0
  118. package/dist/root.js +1 -0
  119. package/dist/rpc.d.ts +1 -0
  120. package/dist/rpc.js +1 -0
  121. package/dist/status.d.ts +17 -0
  122. package/dist/status.js +50 -0
  123. package/dist/storage-wire.d.ts +167 -0
  124. package/dist/storage-wire.js +115 -0
  125. package/dist/storage.d.ts +72 -0
  126. package/dist/storage.js +143 -0
  127. package/dist/store.d.ts +11 -0
  128. package/dist/store.js +1 -0
  129. package/dist/test-kit/git.d.ts +31 -0
  130. package/dist/test-kit/git.js +174 -0
  131. package/dist/ui.d.ts +169 -0
  132. package/dist/ui.js +10 -0
  133. package/dist/window.d.ts +41 -0
  134. package/dist/window.js +15 -0
  135. package/dist/world.d.ts +16 -0
  136. package/dist/world.js +17 -0
  137. package/docs/api/README.md +28 -0
  138. package/docs/api/app-build-contract.md +113 -0
  139. package/docs/api/backend-declaration.md +62 -0
  140. package/docs/api/backend-definition.md +215 -0
  141. package/docs/api/backend.md +269 -0
  142. package/docs/api/errors.md +169 -0
  143. package/docs/api/files.md +91 -0
  144. package/docs/api/gills.md +164 -0
  145. package/docs/api/git-commit.md +279 -0
  146. package/docs/api/git-rpc.md +243 -0
  147. package/docs/api/git-steps.md +1010 -0
  148. package/docs/api/git-wire.md +197 -0
  149. package/docs/api/git.md +579 -0
  150. package/docs/api/index.md +2880 -0
  151. package/docs/api/media-json.md +507 -0
  152. package/docs/api/media-request-id.md +32 -0
  153. package/docs/api/modules.md +32 -0
  154. package/docs/api/query.md +253 -0
  155. package/docs/api/react.md +216 -0
  156. package/docs/api/read-copy.md +204 -0
  157. package/docs/api/rpc.md +128 -0
  158. package/docs/api/storage.md +620 -0
  159. package/package.json +197 -3
@@ -0,0 +1,204 @@
1
+ import { mediaRequestIds, mediaRequestIdSchema } from "./media-request-id.js";
2
+ import { AppError } from "./errors.js";
3
+ import { mediaModelSchema, mediaGenerationInputWireSchema, mediaGenerationSelectionSchema, mediaGenerationFailureSchema, mediaGenerationResultSchema, parseMediaGenerationInput, mediaGenerationReferenceSchema, } from "./media.js";
4
+ import * as Schema from "effect/Schema";
5
+ import { pendingSchema } from "./backend-definition.js";
6
+ import { RpcTarget as TransportRpcTarget } from "@fungi.computer/capnweb";
7
+ // Live RPC targets remain opaque in public declarations, as Agar host grants do.
8
+ const RpcTarget = TransportRpcTarget;
9
+ export { mediaGenerationReferenceSchema } from "./media.js";
10
+ /** Plain JSON catalog reply, decoded with Agar's Media model grammar. */
11
+ export const mediaGenerationDescriptionSchema = Schema.Struct({
12
+ /** Fixed Computer identity supplied by the host. */
13
+ computerId: mediaGenerationReferenceSchema.fields.computerId,
14
+ /** Whether the admitted host permits generation. */
15
+ canGenerate: Schema.Boolean,
16
+ /** Models supplied by the host catalog owner. */
17
+ models: Schema.Array(mediaModelSchema),
18
+ });
19
+ /** A generation call carries paths and a replay ID; the host supplies authority. */
20
+ export const mediaGenerationJsonRequestSchema = Schema.Struct({
21
+ /** Canonical replay identity reused for polling and restoration. */
22
+ requestId: Schema.String.pipe(Schema.check(Schema.makeFilter((value) => mediaRequestIdSchema.safeParse(value).success))),
23
+ ...mediaGenerationInputWireSchema.fields,
24
+ /** Agar-owned image and video selection, including path references. */
25
+ settings: mediaGenerationSelectionSchema,
26
+ });
27
+ /** A typed completion or refusal; no live attempt handles cross this boundary. */
28
+ export const mediaGenerationJsonOutcomeSchema = Schema.Union([
29
+ Schema.Struct({
30
+ /** Completed generation. */
31
+ kind: Schema.Literal("succeeded"),
32
+ /** Retained and saved host result. */
33
+ result: mediaGenerationResultSchema,
34
+ }),
35
+ Schema.Struct({
36
+ /** Refused or failed generation. */
37
+ kind: Schema.Literal("failed"),
38
+ /** Sanitized failure with truthful retry semantics. */
39
+ failure: mediaGenerationFailureSchema,
40
+ }),
41
+ ]);
42
+ /** Generate may also report Agar's canonical, bounded Pending result. */
43
+ export const mediaGenerationJsonReplySchema = Schema.Union([
44
+ mediaGenerationJsonOutcomeSchema,
45
+ Schema.declare((value) => pendingSchema.safeParse(value).success),
46
+ ]);
47
+ /** Page-side Agar handle over an admitted generic JSON method caller. */
48
+ export class MediaGeneration extends RpcTarget {
49
+ #signal;
50
+ #computerId;
51
+ #call;
52
+ #activeRequests = new Map();
53
+ constructor(call, computerId, signal) {
54
+ super();
55
+ this.#computerId = computerId;
56
+ this.#call = call;
57
+ this.#signal = signal;
58
+ }
59
+ /** Describe this handle's fixed Computer through the admitted JSON method. */
60
+ async describe() {
61
+ const description = decodeJson(mediaGenerationDescriptionSchema, await this.#call("describe", undefined, {
62
+ signal: accessSignal(this.#signal),
63
+ }));
64
+ if (description.computerId !== this.#computerId)
65
+ throw new AppError("Media generation unavailable", {
66
+ code: "IDENTITY",
67
+ retryable: false,
68
+ });
69
+ return description;
70
+ }
71
+ /** Issue a canonical replay identity for a new generation attempt. */
72
+ createAttempt() {
73
+ return Promise.resolve(this.#createAttempt(mediaRequestIds.request.generate()));
74
+ }
75
+ /** Resume the original Computer and canonical request without issuing a new ID. */
76
+ restoreAttempt(reference) {
77
+ const parsed = Schema.decodeUnknownSync(mediaGenerationReferenceSchema)(reference);
78
+ const requestId = mediaRequestIds.request.parse(parsed.requestId);
79
+ if (!requestId.ok || parsed.computerId !== this.#computerId)
80
+ throw new AppError("Media restore requires the original Computer and request", {
81
+ code: "IDENTITY",
82
+ retryable: false,
83
+ });
84
+ return Promise.resolve(this.#createAttempt(requestId.value));
85
+ }
86
+ /** Abort every active browser request belonging to this attempt. */
87
+ cancelAttempt(reference) {
88
+ const parsed = Schema.decodeUnknownSync(mediaGenerationReferenceSchema)(reference);
89
+ const requestId = mediaRequestIds.request.parse(parsed.requestId);
90
+ if (!requestId.ok || parsed.computerId !== this.#computerId)
91
+ throw new AppError("Media cancellation requires the original Computer and request", {
92
+ code: "IDENTITY",
93
+ retryable: false,
94
+ });
95
+ for (const controller of this.#activeRequests.get(requestId.value) ?? [])
96
+ controller.abort();
97
+ return this.#call("cancelAttempt", parsed, {
98
+ signal: accessSignal(this.#signal),
99
+ }).then((value) => {
100
+ decodeJson(Schema.Union([Schema.Null, Schema.Undefined]), value);
101
+ });
102
+ }
103
+ #createAttempt(requestId) {
104
+ return new MediaGenerationAttempt(this.#call, this.#computerId, this.#signal, requestId, this.#activeRequests);
105
+ }
106
+ }
107
+ /** One replayable host-issued Media attempt, sharing cancellation with its handle. */
108
+ export class MediaGenerationAttempt extends RpcTarget {
109
+ #computerId;
110
+ #signal;
111
+ #requestId;
112
+ #call;
113
+ #activeRequests;
114
+ constructor(call, computerId, signal, requestId, activeRequests) {
115
+ super();
116
+ this.#computerId = computerId;
117
+ this.#call = call;
118
+ this.#signal = signal;
119
+ this.#requestId = requestId;
120
+ this.#activeRequests = activeRequests;
121
+ }
122
+ /** Return the stable Computer and request identity for replay. */
123
+ reference() {
124
+ return Promise.resolve({
125
+ requestId: this.#requestId,
126
+ computerId: this.#computerId,
127
+ });
128
+ }
129
+ /** Save through the admitted host; poll pending work with the same replay identity. */
130
+ async generate(input) {
131
+ const controller = new AbortController();
132
+ let active = this.#activeRequests.get(this.#requestId);
133
+ if (active === undefined) {
134
+ active = new Set();
135
+ this.#activeRequests.set(this.#requestId, active);
136
+ }
137
+ active.add(controller);
138
+ const signal = this.#signal === undefined
139
+ ? controller.signal
140
+ : AbortSignal.any([this.#signal, controller.signal]);
141
+ try {
142
+ signal.throwIfAborted();
143
+ const request = Schema.decodeUnknownSync(Schema.Json)(decodeJson(mediaGenerationJsonRequestSchema, {
144
+ requestId: this.#requestId,
145
+ ...parseMediaGenerationInput(input),
146
+ }));
147
+ const post = async () => {
148
+ signal.throwIfAborted();
149
+ const reply = await this.#call("generate", request, { signal });
150
+ signal.throwIfAborted();
151
+ return decodeJson(mediaGenerationJsonReplySchema, reply);
152
+ };
153
+ let response = await post();
154
+ const deadline = Date.now() + backgroundGenerationMs;
155
+ while (response.kind === "pending" && Date.now() < deadline) {
156
+ await abortableDelay(response.retryAfterMs, signal);
157
+ response = await post();
158
+ }
159
+ if (response.kind === "pending")
160
+ return {
161
+ kind: "failed",
162
+ failure: {
163
+ message: "Media generation is still running; restore this request later to save it.",
164
+ code: "HOST_FAILURE",
165
+ retryable: true,
166
+ },
167
+ };
168
+ return response;
169
+ }
170
+ finally {
171
+ active.delete(controller);
172
+ if (active.size === 0)
173
+ this.#activeRequests.delete(this.#requestId);
174
+ }
175
+ }
176
+ }
177
+ /** How long the browser keeps checking one background (video) generation. */
178
+ const backgroundGenerationMs = 25 * 60_000;
179
+ function abortableDelay(milliseconds, signal) {
180
+ return new Promise((resolve, reject) => {
181
+ signal.throwIfAborted();
182
+ const timer = setTimeout(resolve, milliseconds);
183
+ signal.addEventListener("abort", () => {
184
+ clearTimeout(timer);
185
+ reject(signal.reason instanceof Error
186
+ ? signal.reason
187
+ : new Error("Media generation was cancelled"));
188
+ }, { once: true });
189
+ });
190
+ }
191
+ function decodeJson(schema, value) {
192
+ try {
193
+ return Schema.decodeUnknownSync(schema, { onExcessProperty: "error" })(value);
194
+ }
195
+ catch (cause) {
196
+ throw new AppError("The Media JSON method returned malformed data", {
197
+ cause,
198
+ code: "PROTOCOL",
199
+ retryable: false,
200
+ });
201
+ }
202
+ }
203
+ const idleAccessSignal = new AbortController().signal;
204
+ const accessSignal = (signal) => signal ?? idleAccessSignal;
@@ -0,0 +1,11 @@
1
+ import * as Schema from "effect/Schema";
2
+ /** A Media-role App exposes the selected library for one Computer to other granted Apps. */
3
+ export declare const mediaLibraryRequestSchema: Schema.Struct<{
4
+ readonly operation: Schema.Literal<"read-library">;
5
+ readonly computerId: Schema.NonEmptyString;
6
+ }>;
7
+ /** A bounded Computer directory shared by folder selection and library reads. */
8
+ export declare const mediaLibraryPathSchema: Schema.String;
9
+ export declare const mediaLibraryResponseSchema: Schema.Struct<{
10
+ readonly path: Schema.NullOr<Schema.String>;
11
+ }>;
@@ -0,0 +1,15 @@
1
+ import * as Schema from "effect/Schema";
2
+ /** A Media-role App exposes the selected library for one Computer to other granted Apps. */
3
+ export const mediaLibraryRequestSchema = Schema.Struct({
4
+ operation: Schema.Literal("read-library"),
5
+ computerId: Schema.NonEmptyString,
6
+ });
7
+ /** A bounded Computer directory shared by folder selection and library reads. */
8
+ export const mediaLibraryPathSchema = Schema.String.pipe(Schema.check(Schema.isMaxLength(4096)), Schema.check(Schema.makeFilter((path) => path.startsWith("/") &&
9
+ path !== "/" &&
10
+ !path.includes("\0") &&
11
+ !path.endsWith("/") &&
12
+ !path.split("/").some((segment) => segment === "." || segment === ".."))));
13
+ export const mediaLibraryResponseSchema = Schema.Struct({
14
+ path: Schema.NullOr(mediaLibraryPathSchema),
15
+ });
@@ -0,0 +1,7 @@
1
+ import * as z from "zod";
2
+ /** One canonical identity for a retryable Media operation. */
3
+ export declare const mediaRequestIds: Readonly<{
4
+ readonly request: import("@fungi.computer/cairn/id").IdCodec<"hub-media-request", "request", 1>;
5
+ }>;
6
+ /** Public wire grammar for the canonical retry identity, visible in App JSON schemas. */
7
+ export declare const mediaRequestIdSchema: z.ZodString;
@@ -0,0 +1,16 @@
1
+ import * as z from "zod";
2
+ import { defineIdFamily } from "@fungi.computer/cairn/id";
3
+ /** One canonical identity for a retryable Media operation. */
4
+ export const mediaRequestIds = defineIdFamily({
5
+ family: "hub-media-request",
6
+ version: 1,
7
+ kinds: {
8
+ /** Canonical request identity for exact replay. */
9
+ request: { prefix: "media_request" },
10
+ },
11
+ });
12
+ /** Public wire grammar for the canonical retry identity, visible in App JSON schemas. */
13
+ export const mediaRequestIdSchema = z
14
+ .string()
15
+ .length(35)
16
+ .regex(/^media_request_[a-z0-9]{21}$/);
@@ -0,0 +1,354 @@
1
+ import * as Schema from "effect/Schema";
2
+ export { mediaLibraryRequestSchema, mediaLibraryPathSchema, mediaLibraryResponseSchema, } from "./media-library.js";
3
+ import type { CapabilityContract, CapabilityDirectory } from "./capabilities.js";
4
+ import { AppError } from "./errors.js";
5
+ /**
6
+ * The Media owner decides Team, Installation, Release, Grant and Computer
7
+ * authority before issuing this handle. The App contributes only generation
8
+ * settings and selected destination/references. The IDs in those selections
9
+ * are not authority: the host revalidates every one against its current
10
+ * admitted Computer scope when it accepts a generation.
11
+ *
12
+ * The owner intentionally returns completed metadata. Operation state,
13
+ * provider identifiers and billing records remain owner facts. The exposed
14
+ * request reference identifies a replay; it grants no authority.
15
+ */
16
+ export type MediaGenerationInput = Readonly<{
17
+ destination: Readonly<{
18
+ path: string;
19
+ }>;
20
+ settings: MediaGenerationSelection;
21
+ }>;
22
+ /** The encodings a completed generation can be saved as. */
23
+ export type MediaOutputFormat = "png" | "jpeg" | "gif" | "webp" | "mp4";
24
+ /** Metadata for one completed generation: the saved destination, pixel
25
+ * dimensions, format, model used, and its cost. */
26
+ export type MediaGenerationResult = Readonly<{
27
+ bytes: number;
28
+ costMilliunits: number;
29
+ destination: Readonly<{
30
+ computerId: string;
31
+ path: string;
32
+ }>;
33
+ format: MediaOutputFormat;
34
+ height: number;
35
+ model: string;
36
+ width: number;
37
+ }>;
38
+ /** The host's typed reason a generation failed: code, message, retry truth
39
+ * and, when known, the stage that failed. */
40
+ export type MediaGenerationFailure = Schema.Schema.Type<typeof mediaGenerationFailureSchema>;
41
+ /** A decoded Media failure; null stage means the host could not identify it. */
42
+ export declare class MediaGenerationError extends AppError {
43
+ readonly stage: NonNullable<MediaGenerationFailure["stage"]> | null;
44
+ constructor(failure: MediaGenerationFailure);
45
+ }
46
+ /** Transport-safe result from the host-owned generation attempt. */
47
+ export type MediaGenerationOutcome = Readonly<{
48
+ kind: "succeeded";
49
+ result: MediaGenerationResult;
50
+ }> | Readonly<{
51
+ kind: "failed";
52
+ failure: MediaGenerationFailure;
53
+ }>;
54
+ /** Live object-capability shape supplied by the host. */
55
+ export type MediaGenerationHandle = {
56
+ /** Fetch the Computer scope, available models, and whether generation
57
+ * is currently allowed. */
58
+ describe(): Promise<Partial<Disposable> & {
59
+ readonly computerId: string;
60
+ readonly canGenerate: boolean;
61
+ readonly models: readonly MediaModel[];
62
+ }>;
63
+ /** Begin a new generation attempt on the host and return its handle. */
64
+ createAttempt(): Promise<MediaGenerationAttemptHandle>;
65
+ /** Resume a previously started attempt identified by its reference. */
66
+ restoreAttempt(reference: MediaGenerationReference): Promise<MediaGenerationAttemptHandle>;
67
+ /** Tell the host to stop an in-flight or pending attempt. */
68
+ cancelAttempt(reference: MediaGenerationReference): Promise<void>;
69
+ };
70
+ /** Host-supplied object-capability for one attempt, before Agar wraps it
71
+ * into the typed MediaGenerationAttempt. */
72
+ export type MediaGenerationAttemptHandle = Partial<Disposable> & {
73
+ /** Fetch this attempt's replay reference from the host. */
74
+ reference(): Promise<MediaGenerationReference & Partial<Disposable>>;
75
+ /** Ask the host to run generation for this attempt with the given
76
+ * input. */
77
+ generate(input: MediaGenerationInput): Promise<MediaGenerationOutcome & Partial<Disposable>>;
78
+ };
79
+ /** One generation attempt: a stable reference plus the ability to run
80
+ * (or retry) generation against it until disposed. */
81
+ export type MediaGenerationAttempt = Disposable & {
82
+ readonly reference: MediaGenerationReference;
83
+ /** Run generation for this attempt and return the saved result, or
84
+ * throw MediaGenerationError on failure; an abort signal cancels it. */
85
+ generate(input: MediaGenerationInput, options?: {
86
+ readonly signal?: AbortSignal;
87
+ }): Promise<MediaGenerationResult>;
88
+ };
89
+ /** The validated, App-facing handle returned by openMediaGeneration: the
90
+ * Computer's model catalog plus the ability to start or resume
91
+ * attempts. */
92
+ export type MediaGenerationSession = Readonly<{
93
+ computerId: string;
94
+ canGenerate: boolean;
95
+ models: readonly MediaModel[];
96
+ /** Start a fresh generation attempt scoped to this session's
97
+ * Computer. */
98
+ createAttempt(): Promise<MediaGenerationAttempt>;
99
+ /** Resume an attempt from a reference returned earlier in this
100
+ * session. */
101
+ restoreAttempt(reference: MediaGenerationReference): Promise<MediaGenerationAttempt>;
102
+ }>;
103
+ /** A replay identity, never an authorization capability. */
104
+ export declare const mediaGenerationReferenceSchema: Schema.Struct<{
105
+ readonly requestId: Schema.String;
106
+ readonly computerId: Schema.String;
107
+ }>;
108
+ /** An opaque replay identity for one attempt; it identifies a request,
109
+ * not an authorization to use it. */
110
+ export type MediaGenerationReference = Schema.Schema.Type<typeof mediaGenerationReferenceSchema>;
111
+ /** Video frame/reference role, interpreted by the host's model catalog. */
112
+ export declare const mediaVideoReferenceRoleSchema: Schema.Literals<readonly ["first-frame", "last-frame", "reference"]>;
113
+ /** One provider-independent frame/reference role. */
114
+ export type MediaVideoReferenceRole = Schema.Schema.Type<typeof mediaVideoReferenceRoleSchema>;
115
+ /** A supported wire resolution. The host refines it against the chosen model. */
116
+ export declare const mediaVideoResolutionSchema: Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>;
117
+ /** Provider-independent resolution selector. */
118
+ export type MediaVideoResolution = Schema.Schema.Type<typeof mediaVideoResolutionSchema>;
119
+ /** A supported wire aspect. The host refines it against the chosen model. */
120
+ export declare const mediaVideoAspectRatioSchema: Schema.Literals<readonly ["16:9", "4:3", "1:1", "3:4", "9:16", "21:9", "9:21"]>;
121
+ /** Provider-independent requested aspect selector. */
122
+ export type MediaVideoAspectRatio = Schema.Schema.Type<typeof mediaVideoAspectRatioSchema>;
123
+ /** Path-only video reference. The host supplies Computer authority. */
124
+ export declare const mediaVideoReferenceSchema: Schema.Struct<{
125
+ /** Computer-relative image path. */
126
+ readonly path: Schema.String;
127
+ /** First frame, last frame or reference-image mode. */
128
+ readonly role: Schema.Literals<readonly ["first-frame", "last-frame", "reference"]>;
129
+ }>;
130
+ /** One path-only video reference. */
131
+ export type MediaVideoReference = Schema.Schema.Type<typeof mediaVideoReferenceSchema>;
132
+ /** Host-described video capabilities and costs. This is wire grammar, not a catalog. */
133
+ export declare const mediaVideoModelSchema: Schema.Struct<{
134
+ /** Smallest duration; the durations list owns exact membership. */
135
+ readonly minSeconds: Schema.Number;
136
+ /** Largest duration. */
137
+ readonly maxSeconds: Schema.Number;
138
+ /** Default whole seconds. */
139
+ readonly defaultSeconds: Schema.Number;
140
+ /** Exact admitted duration values. */
141
+ readonly durations: Schema.$Array<Schema.Number>;
142
+ /** Provider translation family. */
143
+ readonly provider: Schema.Literals<readonly ["seedance", "veo", "minimax"]>;
144
+ /** Resolution/aspect selectors and nominal dimensions. */
145
+ readonly formats: Schema.$Array<Schema.Struct<{
146
+ /** Provider resolution selector. */
147
+ readonly resolution: Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>;
148
+ /** Requested aspect selector. */
149
+ readonly aspectRatio: Schema.Literals<readonly ["16:9", "4:3", "1:1", "3:4", "9:16", "21:9", "9:21"]>;
150
+ /** Nominal width, not measured MP4 dimensions. */
151
+ readonly width: Schema.Number;
152
+ /** Nominal height, not measured MP4 dimensions. */
153
+ readonly height: Schema.Number;
154
+ }>>;
155
+ /** Default resolution. */
156
+ readonly defaultResolution: Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>;
157
+ /** Default requested aspect. */
158
+ readonly defaultAspectRatio: Schema.Literals<readonly ["16:9", "4:3", "1:1", "3:4", "9:16", "21:9", "9:21"]>;
159
+ /** Audio default, or null when the provider default is undocumented. */
160
+ readonly defaultGenerateAudio: Schema.NullOr<Schema.Boolean>;
161
+ /** Host/provider prompt bound. */
162
+ readonly maxPromptLength: Schema.Number;
163
+ /** Roles admitted by this model. */
164
+ readonly referenceRoles: Schema.$Array<Schema.Literals<readonly ["first-frame", "last-frame", "reference"]>>;
165
+ /** Maximum images in reference-image mode. */
166
+ readonly maxReferenceImages: Schema.Number;
167
+ /** Resolutions admitting reference-image mode. */
168
+ readonly referenceResolutions: Schema.$Array<Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>>;
169
+ /** Host-described costs, where 1 USD is 100,000 milliunits. */
170
+ readonly prices: Schema.$Array<Schema.Struct<{
171
+ /** Billed provider resolution. */
172
+ readonly resolution: Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>;
173
+ /** Provider milliunits per silent output second. */
174
+ readonly silentMilliunitsPerSecond: Schema.Number;
175
+ /** Provider milliunits per output second with audio. */
176
+ readonly audioMilliunitsPerSecond: Schema.Number;
177
+ }>>;
178
+ }>;
179
+ /** Immutable host-described video metadata. */
180
+ export type MediaVideoModel = Schema.Schema.Type<typeof mediaVideoModelSchema>;
181
+ /** Validates one model row of the host's Media catalog. */
182
+ export declare const mediaModelSchema: Schema.Struct<{
183
+ readonly id: Schema.String;
184
+ readonly input: Schema.Struct<{
185
+ readonly defaultHeight: Schema.Number;
186
+ readonly defaultSteps: Schema.NullOr<Schema.Number>;
187
+ readonly defaultWidth: Schema.Number;
188
+ readonly dimensions: Schema.Literals<readonly ["none", "own"]>;
189
+ readonly maxDimension: Schema.NullOr<Schema.Number>;
190
+ readonly maxReferences: Schema.Number;
191
+ readonly maxSteps: Schema.NullOr<Schema.Number>;
192
+ readonly referenceField: Schema.NullOr<Schema.String>;
193
+ readonly steps: Schema.Literals<readonly ["steps", "num_steps", "fixed"]>;
194
+ readonly transport: Schema.Literals<readonly ["json", "multipart"]>;
195
+ }>;
196
+ readonly kind: Schema.Literals<readonly ["image", "video"]>;
197
+ readonly label: Schema.String;
198
+ readonly tier: Schema.Literals<readonly ["draft", "balanced", "premium", "max"]>;
199
+ readonly outputFormats: Schema.$Array<Schema.Literals<readonly ["png", "jpeg", "webp"]>>;
200
+ readonly sizes: Schema.NullOr<Schema.$Array<Schema.String>>;
201
+ readonly video: Schema.NullOr<Schema.Struct<{
202
+ /** Smallest duration; the durations list owns exact membership. */
203
+ readonly minSeconds: Schema.Number;
204
+ /** Largest duration. */
205
+ readonly maxSeconds: Schema.Number;
206
+ /** Default whole seconds. */
207
+ readonly defaultSeconds: Schema.Number;
208
+ /** Exact admitted duration values. */
209
+ readonly durations: Schema.$Array<Schema.Number>;
210
+ /** Provider translation family. */
211
+ readonly provider: Schema.Literals<readonly ["seedance", "veo", "minimax"]>;
212
+ /** Resolution/aspect selectors and nominal dimensions. */
213
+ readonly formats: Schema.$Array<Schema.Struct<{
214
+ /** Provider resolution selector. */
215
+ readonly resolution: Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>;
216
+ /** Requested aspect selector. */
217
+ readonly aspectRatio: Schema.Literals<readonly ["16:9", "4:3", "1:1", "3:4", "9:16", "21:9", "9:21"]>;
218
+ /** Nominal width, not measured MP4 dimensions. */
219
+ readonly width: Schema.Number;
220
+ /** Nominal height, not measured MP4 dimensions. */
221
+ readonly height: Schema.Number;
222
+ }>>;
223
+ /** Default resolution. */
224
+ readonly defaultResolution: Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>;
225
+ /** Default requested aspect. */
226
+ readonly defaultAspectRatio: Schema.Literals<readonly ["16:9", "4:3", "1:1", "3:4", "9:16", "21:9", "9:21"]>;
227
+ /** Audio default, or null when the provider default is undocumented. */
228
+ readonly defaultGenerateAudio: Schema.NullOr<Schema.Boolean>;
229
+ /** Host/provider prompt bound. */
230
+ readonly maxPromptLength: Schema.Number;
231
+ /** Roles admitted by this model. */
232
+ readonly referenceRoles: Schema.$Array<Schema.Literals<readonly ["first-frame", "last-frame", "reference"]>>;
233
+ /** Maximum images in reference-image mode. */
234
+ readonly maxReferenceImages: Schema.Number;
235
+ /** Resolutions admitting reference-image mode. */
236
+ readonly referenceResolutions: Schema.$Array<Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>>;
237
+ /** Host-described costs, where 1 USD is 100,000 milliunits. */
238
+ readonly prices: Schema.$Array<Schema.Struct<{
239
+ /** Billed provider resolution. */
240
+ readonly resolution: Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>;
241
+ /** Provider milliunits per silent output second. */
242
+ readonly silentMilliunitsPerSecond: Schema.Number;
243
+ /** Provider milliunits per output second with audio. */
244
+ readonly audioMilliunitsPerSecond: Schema.Number;
245
+ }>>;
246
+ }>>;
247
+ }>;
248
+ /** One generation model as the host describes it: identity, tier, input
249
+ * limits and supported output formats. The host owns the catalog. */
250
+ export type MediaModel = Schema.Schema.Type<typeof mediaModelSchema>;
251
+ /** The most reference images one generation request may name. */
252
+ export declare const MAX_MEDIA_REFERENCES = 4;
253
+ /**
254
+ * Validates the shape of an App's generation settings. Model-specific limits
255
+ * (sizes, steps, durations, reference counts) and defaults are the host's:
256
+ * it checks the selection against its catalog when it accepts a generation.
257
+ */
258
+ export declare const mediaGenerationSelectionSchema: Schema.Struct<{
259
+ readonly model: Schema.String;
260
+ readonly prompt: Schema.String;
261
+ readonly width: Schema.Number;
262
+ readonly height: Schema.Number;
263
+ readonly steps: Schema.optional<Schema.Number>;
264
+ readonly durationSeconds: Schema.optional<Schema.Number>;
265
+ readonly resolution: Schema.optional<Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>>;
266
+ readonly aspectRatio: Schema.optional<Schema.Literals<readonly ["16:9", "4:3", "1:1", "3:4", "9:16", "21:9", "9:21"]>>;
267
+ readonly generateAudio: Schema.optional<Schema.Boolean>;
268
+ readonly references: Schema.optional<Schema.$Array<Schema.Struct<{
269
+ readonly path: Schema.String;
270
+ readonly role: Schema.optional<Schema.Literals<readonly ["first-frame", "last-frame", "reference"]>>;
271
+ }>>>;
272
+ }>;
273
+ /** An App's generation settings: model, prompt, size and optional steps,
274
+ * duration and Computer-relative reference paths. */
275
+ export type MediaGenerationSelection = Schema.Schema.Type<typeof mediaGenerationSelectionSchema>;
276
+ /** Path-only video selection. Model defaults and combination refinements remain host-owned. */
277
+ export declare const mediaVideoSelectionSchema: Schema.Struct<{
278
+ /** Host catalog model identifier. */
279
+ readonly model: Schema.String;
280
+ /** Host-bounded prompt. */
281
+ readonly prompt: Schema.String;
282
+ /** Optional provider resolution selector. */
283
+ readonly resolution: Schema.optional<Schema.Literals<readonly ["480p", "720p", "768p", "1080p", "4k"]>>;
284
+ /** Optional requested aspect selector. */
285
+ readonly aspectRatio: Schema.optional<Schema.Literals<readonly ["16:9", "4:3", "1:1", "3:4", "9:16", "21:9", "9:21"]>>;
286
+ /** Whole seconds, 4 through 15; the host checks exact model membership. */
287
+ readonly durationSeconds: Schema.optional<Schema.Number>;
288
+ /** Explicit audio choice. The host owns omitted defaults. */
289
+ readonly generateAudio: Schema.optional<Schema.Boolean>;
290
+ /** At most four paths with explicit frame/reference roles. */
291
+ readonly references: Schema.optional<Schema.$Array<Schema.Struct<{
292
+ /** Computer-relative image path. */
293
+ readonly path: Schema.String;
294
+ /** First frame, last frame or reference-image mode. */
295
+ readonly role: Schema.Literals<readonly ["first-frame", "last-frame", "reference"]>;
296
+ }>>>;
297
+ }>;
298
+ /** App-selected video parameters without host authority or output-path claims. */
299
+ export type MediaVideoSelection = Schema.Schema.Type<typeof mediaVideoSelectionSchema>;
300
+ /** Public diagnostic stages a host may name when a generation fails. */
301
+ export declare const mediaFailureStages: readonly ["admission", "generation-authorization", "settings", "estimate", "billing", "operation", "provider", "normalization", "artifact", "destination-authorization", "destination-write"];
302
+ /** Validates a generation input envelope; settings are parsed separately. */
303
+ export declare const mediaGenerationInputWireSchema: Schema.Struct<{
304
+ readonly destination: Schema.Struct<{
305
+ readonly path: Schema.String;
306
+ }>;
307
+ readonly settings: Schema.Unknown;
308
+ }>;
309
+ /** Completed image or video metadata saved to a host-admitted destination. */
310
+ export declare const mediaGenerationResultSchema: Schema.Struct<{
311
+ readonly [Symbol.dispose]: Schema.optional<Schema.Unknown>;
312
+ readonly bytes: Schema.Number;
313
+ readonly costMilliunits: Schema.Number;
314
+ readonly destination: Schema.Struct<{
315
+ readonly computerId: Schema.String;
316
+ readonly path: Schema.String;
317
+ }>;
318
+ readonly format: Schema.Literals<readonly ["png", "jpeg", "gif", "webp", "mp4"]>;
319
+ readonly height: Schema.Number;
320
+ readonly model: Schema.String;
321
+ readonly width: Schema.Number;
322
+ }>;
323
+ /** Completed native MEDIA video result, with a host-admitted destination. */
324
+ export declare const mediaVideoResultSchema: Schema.Struct<{
325
+ /** Bounded fetched video encoding. */
326
+ readonly format: Schema.Literal<"mp4">;
327
+ readonly [Symbol.dispose]: Schema.optional<Schema.Unknown>;
328
+ readonly bytes: Schema.Number;
329
+ readonly costMilliunits: Schema.Number;
330
+ readonly destination: Schema.Struct<{
331
+ readonly computerId: Schema.String;
332
+ readonly path: Schema.String;
333
+ }>;
334
+ readonly height: Schema.Number;
335
+ readonly model: Schema.String;
336
+ readonly width: Schema.Number;
337
+ }>;
338
+ /** Completed video metadata. */
339
+ export type MediaVideoResult = Schema.Schema.Type<typeof mediaVideoResultSchema>;
340
+ /** Validates the typed failure a host reports for a generation attempt. */
341
+ export declare const mediaGenerationFailureSchema: Schema.Struct<{
342
+ readonly message: Schema.String;
343
+ readonly stage: Schema.optional<Schema.Literals<readonly ["admission", "generation-authorization", "settings", "estimate", "billing", "operation", "provider", "normalization", "artifact", "destination-authorization", "destination-write"]>>;
344
+ readonly code: Schema.Literals<readonly ["CANCELLED", "CAPABILITY_DENIED", "CAPABILITY_REVOKED", "DISCONNECTED", "HOST_FAILURE", "IDENTITY", "INSUFFICIENT_CREDIT", "INVALID_ARGUMENT", "PROTOCOL", "SAFETY_FILTER_REFUSED", "TIMEOUT"]>;
345
+ readonly retryable: Schema.Boolean;
346
+ }>;
347
+ /** Capability contract for generating Media (images or video). Apps
348
+ * declare it to request access; openMediaGeneration uses it to obtain
349
+ * the host's handle. */
350
+ export declare const mediaGeneration: CapabilityContract<MediaGenerationHandle>;
351
+ /** Decode and normalize a typed input envelope; storage parses the envelope first. */
352
+ export declare function parseMediaGenerationInput(input: Schema.Schema.Type<typeof mediaGenerationInputWireSchema>): MediaGenerationInput;
353
+ /** Discover the exact retained model catalog surfaced by the owner. */
354
+ export declare function openMediaGeneration(capabilities: CapabilityDirectory): Promise<MediaGenerationSession>;