Functions
Declare each Function's access mode in the schema 2 or 3 manifest:
functions:
- name: summarize
entrypoint: functions/summarize/index.ts
access: user
- name: status-probe
entrypoint: functions/status-probe/index.ts
access: public
- name: hourly-maintenance
entrypoint: functions/hourly-maintenance/index.ts
access: systemThe SDK reads these declarations and selects authentication automatically. Application code never chooses a bearer mode. system is for cron, queue-consumer, inbound-email, and other platform-only invocation; browser call and stream reject it with FUNCTION_SYSTEM_ONLY before sending the Function request.
functions.call(name, input?)
Sends one JSON input and returns the parsed JSON or text value. A 204 response returns undefined.
const result = await opencloud.functions.call("summarize", { itemId });
renderSummary(result);A Function declared with access: user throws AUTH_REQUIRED before the call when there is no current user. A declared name that does not exist throws FUNCTION_NOT_DECLARED; a system Function throws FUNCTION_SYSTEM_ONLY.
functions.stream(name, input?)
Returns a byte stream after validating the response:
const stream = await opencloud.functions.stream("export-report", { itemId });
const reader = stream.getReader();
const decoder = new TextDecoder();
for (;;) {
const { done, value } = await reader.read();
if (done) break;
appendText(decoder.decode(value, { stream: true }));
}The result is ReadableStream<Uint8Array>, not a raw Response.
Do not call /functions/v1, attach authorization headers, or create separate public/private invocation helpers. Use call for parsed output and stream only when the Function intentionally returns streaming bytes.
Background queues are available only inside Functions through the @opencloud/server jobs capability. They are not part of the browser SDK. See Functions, background jobs, and cron for queue declarations, delivery semantics, and diagnostics.
With paired SDK 2.4.0, an authenticated producer Function may delegate selected private files to its queue consumer:
await jobs.enqueue("index-document", { fileId }, {
idempotencyKey: `index:${fileId}:${revisionId}`,
files: { read: [fileId] },
});
// In the declared system consumer:
const pdf = await files.download(fileId);Keep files.access: user. Select one to sixteen file UUIDs, at most 128 MiB aggregate and within existing per-file limits. The platform checks current producer access, normalizes selection for idempotency and pins the actual content generation. Replacing a file, including identical bytes, causes the existing job to fail with FILE_INPUT_CHANGED; a new revision needs a new key. Grants last at most 14 days and each attempt has a bounded read window. Browser logout alone does not cancel a job, but subsequent reads still require current file, principal, app and retained domain/token access. Consumers remain system Functions with user: null; delegation adds no metadata, list, mutation, onward-delegation or user-data authority. Calls without files retain existing behavior. These APIs belong to the server Function context, not the browser.
Schema-3 app routes can expose a declared Function at an app URL. The server SDK 2.3.0 and later http context supplies path parameters and ordered query values for those requests. Ordinary browser call and stream continue to use the logical Function name and JSON input; their http context is null. A private app's admission rules apply to Function routes even when the Function is declared public.
