spin

Version:
sha256:99b72dd
wit

key-value interface

store:resource {

An open key-value store

staticopen(label:string) → result<store, error>

Open the store with the specified label.

label must refer to a store allowed in the spin.toml manifest.

error::no-such-store will be raised if the label is not recognized.

get(key:string) → result<option<list<u8>>, error>

Get the value associated with the specified key

Returns ok(none) if the key does not exist.

set(key:string, value:list<u8>) → result<_, error>

Set the value associated with the specified key overwriting any existing value.

delete(key:string) → result<_, error>

Delete the tuple with the specified key

No error is raised if a tuple did not previously exist for key.

exists(key:string) → result<bool, error>

Return whether a tuple exists for the specified key

get-keys() → result<list<string>, error>

Return a list of all the keys

}

The set of errors which may be raised by functions in this interface

error:variant {
store-table-full

Too many stores have been opened simultaneously. Closing one or more stores prior to retrying may address this.

no-such-store

The host does not recognize the store label requested.

access-denied

The requesting component does not have access to the specified store (which may or may not exist).

other(string)

Some implementation-specific error has occurred (e.g. I/O)

}

llm interface

A WASI interface dedicated to performing inferencing for Large Language Models.

A Large Language Model.

inferencing-model:string

Inference request parameters

inferencing-params:record {
max-tokens: u32

The maximum tokens that should be inferred.

Note: the backing implementation may return less tokens.

repeat-penalty: f32

The amount the model should avoid repeating tokens.

repeat-penalty-last-n-token-count: u32

The number of tokens the model should apply the repeat penalty to.

temperature: f32

The randomness with which the next token is selected.

top-k: u32

The number of possible next tokens the model will choose from.

top-p: f32

The probability total of next tokens the model will choose from.

}

The set of errors which may be raised by functions in this interface

error:variant {
model-not-supported
runtime-error(string)
invalid-input(string)
}

Usage information related to the inferencing result

inferencing-usage:record {
prompt-token-count: u32

Number of tokens in the prompt

generated-token-count: u32

Number of tokens generated by the inferencing operation

}

An inferencing result

inferencing-result:record {
text: string

The text generated by the model TODO: this should be a stream

usage: inferencing-usage

Usage information about the inferencing request

}

The model used for generating embeddings

embedding-model:string

Usage related to an embeddings generation request

embeddings-usage:record {
prompt-token-count: u32

Number of tokens in the prompt

}

Result of generating embeddings

embeddings-result:record {
embeddings: list<list<f32>>

The embeddings generated by the request

usage: embeddings-usage

Usage related to the embeddings generation request

}
infer(model:inferencing-model, prompt:string, params:option<inferencing-params>) → result<inferencing-result, error>

Perform inferencing using the provided model and prompt with the given optional params

generate-embeddings(model:embedding-model, text:list<string>) → result<embeddings-result, error>

Generate embeddings for the supplied list of text

mqtt interface

Errors related to interacting with Mqtt

error:variant {
invalid-address

An invalid address string

too-many-connections

There are too many open connections

connection-failed(string)

Connection failure e.g. address not allowed.

other(string)

Some other error occurred

}

QoS for publishing Mqtt messages

qos:enum {
at-most-once
at-least-once
exactly-once
}
connection:resource {
staticopen(address:string, username:string, password:string, keep-alive-interval-in-secs:u64) → result<connection, error>

Open a connection to the Mqtt instance at address.

publish(topic:string, payload:payload, qos:qos) → result<_, error>

Publish an Mqtt message to the specified topic.

}

The message payload.

payload:list<u8>

rdbms-types interface

Errors related to interacting with a database.

error:variant {
connection-failed(string)
bad-parameter(string)
query-failed(string)
value-conversion-failed(string)
other(string)
}

Data types for a database column

db-data-type:enum {
boolean
int8
int16
int32
int64
uint8
uint16
uint32
uint64
floating32
floating64
str
binary
other
}

Database values

db-value:variant {
boolean(bool)
int8(s8)
int16(s16)
int32(s32)
int64(s64)
uint8(u8)
uint16(u16)
uint32(u32)
uint64(u64)
floating32(f32)
floating64(f64)
str(string)
binary(list<u8>)
db-null
unsupported
}

Values used in parameterized queries

parameter-value:variant {
boolean(bool)
int8(s8)
int16(s16)
int32(s32)
int64(s64)
uint8(u8)
uint16(u16)
uint32(u32)
uint64(u64)
floating32(f32)
floating64(f64)
str(string)
binary(list<u8>)
db-null
}

A database column

column:record {
name: string
data-type: db-data-type
}

A database row

row:list<db-value>

A set of database rows

row-set:record {
columns: list<column>
rows: list<row>
}

mysql interface

Imported Types
fermyon:spin/rdbms-types.{parameter-value}
fermyon:spin/rdbms-types.{row-set}
fermyon:spin/rdbms-types.{error}
connection:resource {

A connection to a MySQL database.

staticopen(address:string) → result<connection, error>

Open a connection to the MySQL instance at address.

query(statement:string, params:list<parameter-value>) → result<row-set, error>

query the database: select

execute(statement:string, params:list<parameter-value>) → result<_, error>

execute command to the database: insert, update, delete

}

postgres interface

Imported Types
fermyon:spin/rdbms-types.{parameter-value}
fermyon:spin/rdbms-types.{row-set}
fermyon:spin/rdbms-types.{error}
connection:resource {

A connection to a postgres database.

staticopen(address:string) → result<connection, error>

Open a connection to the Postgres instance at address.

query(statement:string, params:list<parameter-value>) → result<row-set, error>

Query the database.

execute(statement:string, params:list<parameter-value>) → result<u64, error>

Execute command to the database.

}

redis interface

Errors related to interacting with Redis

error:variant {
invalid-address

An invalid address string

too-many-connections

There are too many open connections

type-error

A retrieved value was not of the correct type

other(string)

Some other error occurred

}
connection:resource {
staticopen(address:string) → result<connection, error>

Open a connection to the Redis instance at address.

publish(channel:string, payload:payload) → result<_, error>

Publish a Redis message to the specified channel.

get(key:string) → result<option<payload>, error>

Get the value of a key.

set(key:string, value:payload) → result<_, error>

Set key to value.

If key already holds a value, it is overwritten.

incr(key:string) → result<s64, error>

Increments the number stored at key by one.

If the key does not exist, it is set to 0 before performing the operation. An error::type-error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer.

del(keys:list<string>) → result<u32, error>

Removes the specified keys.

A key is ignored if it does not exist. Returns the number of keys deleted.

sadd(key:string, values:list<string>) → result<u32, error>

Add the specified values to the set named key, returning the number of newly-added values.

smembers(key:string) → result<list<string>, error>

Retrieve the contents of the set named key.

srem(key:string, values:list<string>) → result<u32, error>

Remove the specified values from the set named key, returning the number of newly-removed values.

execute(command:string, arguments:list<redis-parameter>) → result<list<redis-result>, error>

Execute an arbitrary Redis command and receive the result.

}

The message payload.

payload:list<u8>

A parameter type for the general-purpose execute function.

redis-parameter:variant {
int64(s64)
binary(payload)
}

A return type for the general-purpose execute function.

redis-result:variant {
nil
status(string)
int64(s64)
binary(payload)
}

sqlite interface

connection:resource {

A handle to an open sqlite instance

staticopen(database:string) → result<connection, error>

Open a connection to a named database instance.

If database is "default", the default instance is opened.

error::no-such-database will be raised if the name is not recognized.

execute(statement:string, parameters:list<value>) → result<query-result, error>

Execute a statement returning back data if there is any

}

The set of errors which may be raised by functions in this interface

error:variant {
no-such-database

The host does not recognize the database name requested.

access-denied

The requesting component does not have access to the specified database (which may or may not exist).

invalid-connection

The provided connection is not valid

database-full

The database has reached its capacity

io(string)

Some implementation-specific error has occurred (e.g. I/O)

}

A single column's result from a database query

value:variant {
integer(s64)
real(f64)
text(string)
blob(list<u8>)
null
}

A set of values for each of the columns in a query-result

row-result:record {
values: list<value>
}

A result of a query

query-result:record {
columns: list<string>

The names of the columns retrieved in the query

rows: list<row-result>

the row results each containing the values for all the columns for a given row

}

variables interface

The set of errors which may be raised by functions in this interface.

error:variant {
invalid-name(string)

The provided variable name is invalid.

undefined(string)

The provided variable is undefined.

provider(string)

A variables provider specific error has occurred.

other(string)

Some implementation-specific error has occurred.

}
get(name:string) → result<string, error>

Get an application variable value for the current component.

The name must match one defined in in the component manifest.