Reference
Reference for the Inskill.Session, Inskill.Utils, and Inskill.Server objects and the session global available to copilot scripts.
These objects are available to copilot scripts. For the objects available to scripts in dynamic steps and dynamic resources, see Dynamic Scripts.
Task Data
Scripts often deal with data coming from an asset, a scanned QR code, or the observation steps in a task. There is always an id object with pid (product_id), type, and sn if there is an asset. Under components is the pid of this product, then any other data, such as the model of this asset. In the simple case, an asset is a product 123 that has tasks to run:
"data": {
"id": {
"sn": "SN-222",
"type": "My Product",
"pid": "123"
},
"components": {
"123": {
"model": "X13"
}
}
}If a product has components that have tasks and their own data definitions, each component's data is nested under the product that contains it. Here product 123 has a component 456 that defines the model variable and some additional information:
"data": {
"id": {
"sn": "SN-222",
"type": "My Product",
"pid": "456"
},
"components": {
"123": {
"components": {
"456": {
"model": "A",
"pump": {"voltage": 120, "head": 12.5, "flow": 65},
"motor": {"voltage": 240, "speed": 1500, "power": 450}
}
}
}
}
}Reading this data from a script in product 456:
console.log(Inskill.Session.hasData("components.123.components.456.model")); // true
console.log(Inskill.Session.getData("components.123.components.456.model")); // "A"
console.log(Inskill.Session.getData("model")); // "A"
console.log(Inskill.Session.getData("head")); // 12.5
console.log(Inskill.Session.getData("pump")); // returns the pump object
console.log(Inskill.Session.getData("voltage")); // 120
console.log(Inskill.Session.getData("components.123.components.456.motor.voltage")); // 240
console.log(Inskill.Session.product_id); // 456
console.log(Inskill.Session.src_product_id); // 123
let path = `components.${Inskill.Session.product_id}.head`; // use backtick ` for quotesA script in a component doesn't know which copilot it is included in. Use product_id and src_product_id (see Properties): they are the same if the product is used alone, and different if one contains another. Components can be many levels deep, and a script won't know all the IDs in between.
Inskill.Session
Properties
- task - the name of the task
- product_id is the ID of the product running this script
- src_product_id is the ID of the product the user selected. This is the same as product_id if the task is in the same product. Say product 123 has a component 456 with a task "calibrate", the src_product_id will be 123 while the product_id will be 456. The script in product 456 will run when calibrate task runs. This is because component 456 may be a component of many other copilots so you want the script to handle its own tasks.
- account_id - the ID of the account the task ran in
- guid - the unique identifier of the session
- start - timestamp when the task started. unix style seconds since time began in 1970. Use the package
momentto format into readable string, etc. - end - timestamp when the task ended (optional, if task has ended)
- data - the raw set of data as an object
- code - handoff code (optional)
- language - the language used, in 2 letter code eg "en", "fr", "zh"
- step_count - the number of steps used in the task. Will be 0 for context augmentation
- gpt_summary - the InSkill GPT summary of the session, if one was generated
- solution_title - the title of the solution associated with the session, if any
- user_id - the ID of the user who ran the task
- user.email - the email address of the user who ran the task
hasData(path)
Inskill.Session.hasData(path) - where path refers to the name of a variable in the data set. Use to safely test if the path has a value without try/catch or checking for undefined.
if (Inskill.Session.hasData('pressure')) {
// do something with Inskill.Session.getData('pressure')
}
if (Inskill.Session.hasData('components.123.pressure')) {
// If the data path includes components
}getData(path) returns object
safely get the value of a variable, or null
The path can be the full path, such as components.123.components.456.model, or just the name of the variable, such as model. A name on its own is a search: if the name is used more than once, the first match is returned, so use the full path for duplicates. See Task Data.
setData(path, value)
set a variable in the task's data. There is an implied "components.product_id" prepended to the path provided, so setData("pump.flow", 87); will actually make a path "components.456.pump.flow" to store the value, if the product_id is 456.
removeData(path)
remove an existing variable, using the same implied path as setData() above.
getOwner()
Returns the signed-in user running the session, as an object with name and email.
var owner = Inskill.Session.getOwner();
console.log(owner.name, owner.email);hasAsset() bool
Returns true if the session has an asset that is known in the account the script runs in. An asset that exists in a customer's account but not in the supplier's returns false in the supplier's script.
if (Inskill.Session.hasAsset()) {
// the session has an asset in this account
}url(false)
Returns a general link that can view the session. Takes an optional options object. Set portal to true to get the web portal page that views the session instead. The portal link includes the account ID, and is only useful to a signed-in user with portal access.
Inskill.Session.url();
// https://expert.inskill.ai/session/<session_guid>
Inskill.Session.url({ portal: true });
// https://expert.inskill.ai/customer/#/ds/<account_id>?dsid=<session_guid>sendEmail(email, [body, subject, attachments])
send email to the to address. Default is json of the task. Include the body and subject to format the email to be readable
Inskill.Session.sendEmail("[email protected]");
let body = `Support escalation \n asset ${Inskill.Session.Asset.sn}`;
Inskill.Session.sendEmail("[email protected]", body, "Escalation"); To attach files, pass an array of attachments as the fourth argument. Each attachment is an object with a type, a name, and the file content as plain text: [{ type, name, content }].
userLog(message)
writes the message into userlog, can log escalations, tasks with problem conditions, etc.
createAsset(sn, [name])
Creates an asset with the serial number sn and the optional name, attaches it to the session, and returns it. If an asset with that serial number already exists, attaches and returns that asset instead.
The asset belongs to the copilot the script is part of. When the script belongs to a component, the asset belongs to the copilot that the component is part of: createAsset never creates a component asset. You can't choose a different copilot.
var asset = Inskill.Session.createAsset('SN-1001', 'Line 3 pump');Inskill.Session.Asset
Properties:
- sn (serial number) unique string identifier
- name
- product_id
- data
- url
- notes
- groups
hasData(path)
Just like the function above, but applied to the data set of the asset
if (Inskill.Session.Asset.hasData('pressure')) {
// do something with Inskill.Session.Asset.getData('pressure')
}getData(path)
Just like the function above, but applied to the data set of the asset
setData(path, value)
Just like the function above, but applied to the data set of the asset
removeData(path)
Just like the function above, but applied to the data set of the asset
merge(json)
Merges the provided JSON object into the asset's data. Existing values not in the object are kept.
replace(json)
Replaces the asset's data with the provided JSON object.
addNote(message)
Adds a note to the asset. Notes appear in the asset's notes.
addToGroup(name)
Adds the asset to the asset group with the given name.
removeFromGroup(name)
Removes the asset from the asset group with the given name.
Inskill.Utils
empty(obj)
returns true if an object has no value (null, undefined, empty string)
getData(path, object)
returns the value at path if it exists within the provided object, otherwise undefined
Use this to manipulate complex objects that aren't task or asset data. For example, if you make a web request and need to get data safely from its json response.
var reading = { pump: { flow: 87 } };
console.log(Inskill.Utils.getData('pump.flow', reading)); // 87
console.log(Inskill.Utils.getData('pump.head', reading)); // undefinedsetData(path, value, object)
Safely sets the value at the provided path in the object.
webRequest(options)
var options = {
method: 'GET', // GET, POST, PATCH, DELETE
url: 'https://weather.com/' + Inskill.Session.getData('zipcode'),
headers: {
'X-API-Key':'WEATHER_KEY'
},
data: {}
}
/** AWAIT */
var { error, body, response } = await Inskill.Utils.webRequest(options);
console.log(body);
session.done();
/*
// Alternatively, use a promise instead of await:
Inskill.Utils.webRequest(options).then(function({ error, response, body }) {
console.log(body);
session.done();
});
*/Call session.done() when the request finishes. See session.
session
session is a global that ends a script and returns its result.
CautionThis is the
sessionglobal, notInskill.Session.
done([result])
session.done([result])Ends the script and returns control to InSkill. Without it, the script engine can't tell when a script that waits on something has finished.
Call session.done():
- after
await Inskill.Utils.webRequest(...), or any other work the script waits on, such as a promise, MQTT, or a callback - inside
.then()when the script uses a promise, to signal that nothing is left to wait for - whenever you want to set the script's result
A script that waits on nothing doesn't need it and can simply return a value, but calling session.done() at the end of every script is the safer practice.
result (optional): the value the script returns, usually a short status such as OK or Failed. Any serializable value works. It appears in the result when you click Test Script. Event scripts (Context Augmentation and Session Finished) never need a result. A Script tool uses it to return data to InSkill GPT.
var { error, body, response } = await Inskill.Utils.webRequest({
method: 'GET',
url: 'https://example.com/api/' + Inskill.Session.getData('zipcode')
});
if (error) {
console.log(error);
session.done('Failed');
} else {
console.log(body);
session.done(response);
}Inskill.Server
production bool
true on expert.inskill.ai server, false on author.inskill.ai or any non-production server.
test Inskill.Server.production to use test data, for example
Updated 10 days ago
