Skip to content
Thyme Docs

Runtime Integrations

The SDK exposes smaller modules for tools that inspect releases or host tasks. Ordinary task code should use defineTask.

Package subpaths

ImportExports
@thyme-labs/sdk/archive-readerdecompressTask, DecompressResult
@thyme-labs/sdk/lifecycleCallback names, type guard, metadata filter, LifecycleCallbackName
@thyme-labs/sdk/schema-extractorextractSchemaFromTask
@thyme-labs/sdk/task-runtimeCLOUD_TASK_RUNNER_SOURCE, TASK_RUNTIME_OUTPUT_PREFIXES

The package is ESM. These subpaths avoid pulling the root module's Node crypto archive writer into an isolate or browser integration.

Source-schema extraction

import { extractSchemaFromTask } from '@thyme-labs/sdk/schema-extractor'
 
const jsonSchema = extractSchemaFromTask(sourceText)
if (jsonSchema !== null) {
  const metadata = JSON.parse(jsonSchema)
  // Use metadata to build an argument form.
}

Signature: extractSchemaFromTask(taskCode: string): string | null. It returns serialized JSON Schema metadata, not a Zod instance. It scans source without executing the task.

Supported declarations include schema: z.object({ ... }) and a reference to a locally declared const object schema. The scanner handles nested objects, arrays, comments, regex literals, and optional/default chains.

Zod sourceExtracted metadata
z.string(), z.number(), z.boolean()Corresponding primitive type.
z.address()String with a 40-hex-digit EVM-address pattern.
z.bigint(), z.coerce.bigint()Decimal string with an integer pattern.
z.object, z.array, z.recordNested properties, array items, or additional-properties schema.
z.enum, z.literal, z.union, z.tupleEnum, constant, alternatives, or positional items.
z.coerce.number()Number target type.
.optional(), .default(), .nullish()Field removed from the required list.
.default(literal)Representable default included in metadata.

Extraction is best effort. It does not model every Zod method, refinement, transform, imported schema, dynamic expression, or computed field. Unknown base types may appear as strings; even a valid empty z.object({}) returns null. The CLI warns when a declared schema cannot be extracted. Runtime validation by defineTask remains authoritative.

Runtime protocol

import {
  CLOUD_TASK_RUNNER_SOURCE,
  TASK_RUNTIME_OUTPUT_PREFIXES,
} from '@thyme-labs/sdk/task-runtime'

CLOUD_TASK_RUNNER_SOURCE is a Deno wrapper string that imports ./task.js. The Flow backend supplies arguments, secrets, account, RPC, and storage, and chooses the run or callback phase.

InputPurpose
TASK_ARGSJSON arguments, default {}.
THYME_ACCOUNTRequired valid execution address.
RPC_URLPublic-client transport.
THYME_SECRETS_JSONInjected secret map.
THYME_STORAGE_INPUT_PATH / THYME_STORAGE_JSONStorage file takes precedence over inline JSON.
THYME_STORAGE_OUTPUT_PATHWrite produced storage to a file instead of stdout when supplied.
THYME_PHASErun by default, or callback.
THYME_CALLBACK / THYME_CALLBACK_PAYLOADCallback name and JSON payload in callback phase.

These are host integration inputs, not variables task authors configure in the Console.

Prefix constantValue
namespace__THYME_
log__THYME_LOG__
result__THYME_RESULT__
storage__THYME_STORAGE__
stats__THYME_STATS__
callbacks__THYME_CALLBACKS__

The wrappers use the markers for JSON records on stdout. Not every phase emits every marker; a callback phase produces logs and storage, not a new task result. Hosts must validate results and storage and enforce their own permissions, isolation, size limits, and persistence semantics. Importing the wrapper string does not create a sandbox.