Skip to content
Merged

T8 #1633

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions complete/completion_oafp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ F_in__in_snmp_insnmptimeout_=1
F_in__in_snmp_insnmpretries_=1
F_in__in_snmp_insnmpsec_=1
F_in__in_toml=0
F_in__in_toon=0
F_in__in_xls=0
F_in__in_xls_inxlssheet_=1
F_in__in_xls_inxlsevalformulas_=1
Expand Down Expand Up @@ -227,6 +228,7 @@ F_out__out_template_templatedata_=1
F_out__out_template_templatetmpl_=1
F_out__out_text=0
F_out__out_toml=0
F_out__out_toon=0
F_out__out_tree=0
F_out__out_xls=0
F_out__out_xls_xlsfile_=1
Expand Down Expand Up @@ -458,6 +460,7 @@ if [ $# -gt 0 ]; then
if [ "${arg#insnmpretries=}" != "$arg" ]; then FFOUND=1; F_in__in_snmp_insnmpretries_=0; fi
if [ "${arg#insnmpsec=}" != "$arg" ]; then FFOUND=1; F_in__in_snmp_insnmpsec_=0; fi
if [ "$arg" = "in=toml" ]; then FFOUND=1; F_in__in_toml=1; F_in_=0; fi
if [ "$arg" = "in=toon" ]; then FFOUND=1; F_in__in_toon=1; F_in_=0; fi
if [ "$arg" = "in=xls" ]; then FFOUND=1; F_in__in_xls=1; F_in_=0; fi
if [ "${arg#inxlssheet=}" != "$arg" ]; then FFOUND=1; F_in__in_xls_inxlssheet_=0; fi
if [ "${arg#inxlsevalformulas=}" != "$arg" ]; then FFOUND=1; F_in__in_xls_inxlsevalformulas_=0; fi
Expand Down Expand Up @@ -577,6 +580,7 @@ if [ $# -gt 0 ]; then
if [ "${arg#templatetmpl=}" != "$arg" ]; then FFOUND=1; F_out__out_template_templatetmpl_=0; fi
if [ "$arg" = "out=text" ]; then FFOUND=1; F_out__out_text=1; F_out_=0; fi
if [ "$arg" = "out=toml" ]; then FFOUND=1; F_out__out_toml=1; F_out_=0; fi
if [ "$arg" = "out=toon" ]; then FFOUND=1; F_out__out_toon=1; F_out_=0; fi
if [ "$arg" = "out=tree" ]; then FFOUND=1; F_out__out_tree=1; F_out_=0; fi
if [ "$arg" = "out=xls" ]; then FFOUND=1; F_out__out_xls=1; F_out_=0; fi
if [ "${arg#xlsfile=}" != "$arg" ]; then FFOUND=1; F_out__out_xls_xlsfile_=0; fi
Expand Down Expand Up @@ -809,6 +813,7 @@ if [ $F_in_ -eq 1 ]; then
echo "in=sql One or more SQLs statements to AST -Abstract Syntax Tree- or beautified SQL"
echo "in=snmp Retrieves data from a SNMP device"
echo "in=toml TOML format"
echo "in=toon TOON format"
echo "in=xls A XLSx compatible file -requires file=abc.xlsx-"
echo "in=xml An XML format -auto-detected-"
echo "in=yaml A YAML format -auto-detected-"
Expand Down Expand Up @@ -1141,6 +1146,7 @@ if [ $F_out_ -eq 1 ]; then
echo "out=template A Handlebars template format"
echo "out=text A string text format"
echo "out=toml A TOML format -arrays will have outkey=list-"
echo "out=toon A TOON format"
echo "out=tree A tree-like format"
echo "out=xls A XLSx output format"
echo "out=xml An XML format"
Expand Down
4 changes: 4 additions & 0 deletions complete/completion_oafp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ complete:
desc: JSON/SLON map with SNMPv3 security options
- name: in=toml
desc: TOML format
- name: in=toon
desc: TOON format
- name: in=xls
desc: A XLSx compatible file -requires file=abc.xlsx-
opts:
Expand Down Expand Up @@ -500,6 +502,8 @@ complete:
desc: A string text format
- name: out=toml
desc: A TOML format -arrays will have outkey=list-
- name: out=toon
desc: A TOON format
- name: out=tree
desc: A tree-like format
- name: out=xls
Expand Down
69 changes: 35 additions & 34 deletions js/oafp.js

Large diffs are not rendered by default.

45 changes: 44 additions & 1 deletion js/openaf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4728,6 +4728,7 @@ var $from = function(a) {
* at(arrayIndex)\
* to_numSpace(num, space), from_numSpace(num, space)\
* to_kyaml(obj), from_kyaml(str)\
* to_toon(obj), from_toon(str)\
* to_base64(str), from_base64(str)\
* to_xml(obj), from_xml(str)\
*
Expand Down Expand Up @@ -4932,6 +4933,14 @@ const $path = function(aObj, aPath, customFunctions) {
_func: ar => ar[0].replace(new RegExp(ar[1], ar[2]), ar[3]),
_signature: [ { types: [ jmespath.types.string ] }, { types: [ jmespath.types.string ] }, { types: [ jmespath.types.string ] }, { types: [ jmespath.types.string ] } ]
},
to_toon: {
_func: ar => af.toTOON(ar[0]),
_signature: [ { types: [ jmespath.types.any ] } ]
},
from_toon: {
_func: ar => af.fromTOON(ar[0]),
_signature: [ { types: [ jmespath.types.string ] } ]
},
trim: {
_func: ar => ar[0].trim(),
_signature: [ { types: [ jmespath.types.string ] } ]
Expand Down Expand Up @@ -9985,6 +9994,17 @@ const loadJSYAML = function() {
loadCompiledLib("js-yaml_js", __, __, true)
}

/**
* <odoc>
* <key>loadTOON()</key>
* Loads the TOON image encoding/decoding library.
* </odoc>
*/
const loadTOON = function() {
if (isUnDef(global.toon) || global.toon.decode || global.toon.encode)
global.toon = require(getOpenAFJar() + "::js/toon.js")
}

/**
* <odoc>
* <key>loadOAFP()</key>
Expand Down Expand Up @@ -10183,7 +10203,6 @@ AF.prototype.setInteractiveTerminal = () => isDef(__con) ? __con.getTerminal().s
* </odoc>
*/
AF.prototype.unsetInteractiveTerminal = () => isDef(__con) ? __con.getTerminal().settings.set("icanon echo") : __

/**
* <odoc>
* <key>AF.toYAML(aJson, multiDoc, sanitize, shouldColor) : String</key>
Expand Down Expand Up @@ -10382,6 +10401,28 @@ AF.prototype.toKYAML = function(aJson, multiDoc, sanitize, shouldColor, perEntry
return colored
}

/**
* <odoc>
* <key>AF.toTOON(aObj) : String</key>
* Tries to convert aObj into a TOON string.
* </odoc>
*/
AF.prototype.toTOON = function(aObj) {
loadTOON()
return toon.encode(aObj)
}

/**
* <odoc>
* <key>AF.fromTOON(aTOONStr) : Object</key>
* Tries to parse aTOONStr into a javascript object.
* </odoc>
*/
AF.prototype.fromTOON = function(aTOONStr) {
loadTOON()
return toon.decode(aTOONStr)
}

/**
* <odoc>
* <key>AF.fromYAML(aYaml) : Object</key>
Expand Down Expand Up @@ -14640,6 +14681,8 @@ const $output = function(aObj, args, aFunc, shouldReturn) {
__ansiColorFlag = true
__conConsole = true
return fnP(af.toYAML(res, __, true, true))
case "toon":
return fnP(af.toTOON(res))
case "table":
if (isMap(res)) res = [res]
if (isArray(res)) return fnP(printTable(res, __, __, __conAnsi, (__conAnsi || isDef(this.__codepage) ? "utf" : __)))
Expand Down
23 changes: 23 additions & 0 deletions js/owrap.ai.js
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,20 @@ OpenWrap.ai.prototype.gpt.prototype.jsonPromptWithStats = function(aPrompt, aMod
return { response: parsed, stats: this.getLastStats() }
}

/**
* <odoc>
* <key>ow.ai.gpt.jsonPromptWithStatsRaw(aPrompt, aModel, aTemperature, tools) : Map</key>
* Executes jsonPrompt and returns the raw response, parsed response, and statistics ({ response, raw, stats }).
* </odoc>
*/
OpenWrap.ai.prototype.gpt.prototype.jsonPromptWithStatsRaw = function(aPrompt, aModel, aTemperature, tools) {
this.setInstructions("json")

var out = this.model.prompt(aPrompt, aModel, aTemperature, true, tools)
var parsed = isString(out) ? jsonParse(out, __, __, true) : out
return { response: parsed, raw: out, stats: this.getLastStats() }
}

/**
* <odoc>
* <key>ow.ai.gpt.booleanPrompt(aPrompt, aModel, aTemperature, tools) : boolean</key>
Expand Down Expand Up @@ -2283,6 +2297,15 @@ global.$gpt = function(aModel) {
promptJSONWithStats: (aPrompt, aModel, aTemperature, tools) => {
return _g.jsonPromptWithStats(aPrompt, aModel, aTemperature, tools)
},
/**
* <odoc>
* <key>$gpt.promptJSONWithStatsRaw(aPrompt, aModel, aTemperature)</key>
* Tries to prompt aPrompt (a string or an array of strings) and aModel (defaults to the one provided on the constructor) returning a map with the raw response, parsed JSON response, and statistics ({ response, raw, stats }).
* </odoc>
*/
promptJSONWithStatsRaw: (aPrompt, aModel, aTemperature, tools) => {
return _g.jsonPromptWithStatsRaw(aPrompt, aModel, aTemperature, tools)
},
/**
* <odoc>
* <key>$gpt.iniPrompt(aPrompt, aRole, aModel, aTemperature) : String</key>
Expand Down
2 changes: 1 addition & 1 deletion js/owrap.oJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -2878,7 +2878,7 @@ OpenWrap.oJob.prototype.addJob = function(aJobsCh, _aName, _jobDeps, _jobType, _
aJobTypeArgs.shell = _$(aJobTypeArgs.shell, "aJobTypeArgs.shell").isString().default("powershell");
}
var m = parent.__langs[aJobTypeArgs.lang]
if (isDef(aJobTypeArgs.lang) && isUnDef(m) && ["javascript", "oaf", "js"].indexOf(aJobTypeArgs.lang) === -1) throw "Language '" + aJobTypeArgs.lang + "' not supported or defined for job '" + aName + "'."
if (isDef(aJobTypeArgs.lang) && isUnDef(m) && ["javascript", "oaf", "js", "python"].indexOf(aJobTypeArgs.lang) === -1) throw "Language '" + aJobTypeArgs.lang + "' not supported or defined for job '" + aName + "'."
if (isDef(m) && isUnDef(aJobTypeArgs.returnRE) && isDef(m.returnRE)) aJobTypeArgs.returnRE = m.returnRE
if (isDef(m) && isUnDef(aJobTypeArgs.returnFn) && isDef(m.returnFn)) aJobTypeArgs.returnFn = m.returnFn

Expand Down
2 changes: 2 additions & 0 deletions js/owrap.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ OpenWrap.template.prototype.__addHelpers = function(aHB) {
* - $toYAML -- returns the YAML version of the parameter\
* - $toKYAML -- returns the KYAML version fo the parameter\
* - $toJSON -- returns the JSON version of the parameter\
* - $toTOON -- returns the TOON version of the parameter\
* - $env -- returns the current environment variable identified by the parameter\
* - $escape -- returns an escaped version of the parameter\
* - $acolor -- returns an ansi color (first argument) escape sequence of the string parameter (second argument)\
Expand Down Expand Up @@ -151,6 +152,7 @@ OpenWrap.template.prototype.addOpenAFHelpers = function() {
toYAML: af.toYAML,
toKYAML: af.toKYAML,
toJSON: stringify,
toTOON: s => af.toTOON(af),
ptree: r => printTree(r),
pmap: r => printMap(r),
pbar: (v, m, min, size, indicator, space) => ow.format.string.progress(v, isMap(m) ? __ : m, isMap(min) ? __ : min, isMap(size) ? __ : size, isMap(indicator) ? __ : indicator, isMap(space) ? __ : space),
Expand Down
2 changes: 1 addition & 1 deletion js/repack.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ if (createTmp) {
"del %SRC% >nul 2>&1",
//"if errorlevel 1 goto wait",
"set OAF_JARGS=\"-Xshare:dump -XX:SharedArchiveFile=%DIR%.shared.oaf %OAF_JARGS%\"",
"\"%DIR%oaf.bat\" -c \"ow.loadOJob();loadOAFP();ow.loadSec();loadLodash();loadFuse();ow.loadFormat();ow.loadObj();ow.loadServer();loadUnderscore();ow.loadMetrics();loadJSYAML();ow.loadPython();ow.loadTemplate();loadHandlebars();__initializeCon();loadCompiledLib('jmespath_js');oafp({data:'()'});oJobRun({todo:[]})\"",
"\"%DIR%oaf.bat\" -c \"ow.loadOJob();loadOAFP();loadTOON();loadJSYAML();loadPy();ow.loadSec();loadLodash();loadFuse();ow.loadFormat();ow.loadObj();ow.loadServer();loadUnderscore();ow.loadMetrics();loadJSYAML();ow.loadPython();ow.loadTemplate();loadHandlebars();__initializeCon();loadCompiledLib('jmespath_js');oafp({data:'()'});oJobRun({todo:[]})\"",
"del /F /Q \"%~f0\" >nul 2>&1"
].join("\r\n")
io.writeFileString(_updBat, _bat)
Expand Down
Loading
Loading