jsfe 1.7.8 → 1.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/forms/authoring.d.ts +10 -0
- package/dist/forms/authoring.d.ts.map +1 -0
- package/dist/forms/authoring.js +110 -0
- package/dist/forms/choice-flow.d.ts +0 -4
- package/dist/forms/choice-flow.d.ts.map +1 -1
- package/dist/forms/choice-flow.js +10 -14
- package/dist/forms/continuation-safety.d.ts.map +1 -1
- package/dist/forms/continuation-safety.js +2 -1
- package/dist/forms/contracts.d.ts +8 -4
- package/dist/forms/contracts.d.ts.map +1 -1
- package/dist/forms/contracts.js +46 -23
- package/dist/forms/declaration-capture.d.ts +7 -0
- package/dist/forms/declaration-capture.d.ts.map +1 -0
- package/dist/forms/declaration-capture.js +15 -0
- package/dist/forms/declarations.d.ts +20 -0
- package/dist/forms/declarations.d.ts.map +1 -0
- package/dist/forms/declarations.js +272 -0
- package/dist/forms/flows.d.ts.map +1 -1
- package/dist/forms/flows.js +47 -50
- package/dist/forms/identity-flows.js +8 -8
- package/dist/forms/index.d.ts +4 -0
- package/dist/forms/index.js +5 -1
- package/dist/forms/inspection.d.ts +12 -0
- package/dist/forms/inspection.d.ts.map +1 -0
- package/dist/forms/inspection.js +120 -0
- package/dist/forms/prompt-compiler.d.ts.map +1 -1
- package/dist/forms/prompt-compiler.js +5 -1
- package/dist/helpers/answer.d.ts +1 -1
- package/dist/helpers/answer.js +2 -2
- package/dist/helpers/contextual-response.d.ts +3 -0
- package/dist/helpers/contextual-response.d.ts.map +1 -1
- package/dist/helpers/contextual-response.js +7 -0
- package/dist/helpers/form-sources.js +1 -1
- package/dist/helpers/form-state.d.ts +1 -1
- package/dist/helpers/form-state.d.ts.map +1 -1
- package/dist/helpers/form-state.js +7 -5
- package/dist/helpers/index.d.ts +6 -5
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +4 -4
- package/dist/helpers/match-inputs.d.ts.map +1 -1
- package/dist/helpers/match-inputs.js +12 -40
- package/dist/helpers/money.d.ts +5 -3
- package/dist/helpers/money.d.ts.map +1 -1
- package/dist/helpers/money.js +25 -10
- package/dist/helpers/named-functions.d.ts +5 -0
- package/dist/helpers/named-functions.d.ts.map +1 -0
- package/dist/helpers/named-functions.js +54 -0
- package/dist/helpers/proposal-contract.js +4 -4
- package/dist/host/capabilities.d.ts.map +1 -1
- package/dist/host/capabilities.js +11 -3
- package/dist/host/registry-composition.d.ts.map +1 -1
- package/dist/host/registry-composition.js +9 -3
- package/dist/index.d.ts +15 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +80 -51
- package/dist/runtime-identity.js +1 -1
- package/docs/copilot-reference.md +336 -66
- package/docs/development-release.md +16 -1
- package/package.json +1 -2
- package/dist/helpers/semantic-input-prompt.d.ts +0 -2
- package/dist/helpers/semantic-input-prompt.d.ts.map +0 -1
- package/dist/helpers/semantic-input-prompt.js +0 -153
- package/dist/helpers/semantic-input.d.ts +0 -28
- package/dist/helpers/semantic-input.d.ts.map +0 -1
- package/dist/helpers/semantic-input.js +0 -47
- package/docs/forms.md +0 -271
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { compileFlowDeclarations } from './forms/declarations.js';
|
|
2
|
+
import { compileNamedFunctions } from './helpers/named-functions.js';
|
|
1
3
|
import { closeFormInstance } from './helpers/form-state.js';
|
|
2
|
-
import { validateSemanticInputStep, buildInputAssessment, normalizeInputAssessment } from './helpers/semantic-input.js';
|
|
3
4
|
import { validateContextualResponseStep } from './helpers/contextual-response.js';
|
|
4
5
|
import { validateFlowRecovery } from './host/flow-recovery.js';
|
|
5
6
|
import { ACTION_TOOLS } from './forms/action-tools.js';
|
|
@@ -2575,8 +2576,6 @@ async function playStep(currentFlowFrame, engine) {
|
|
|
2575
2576
|
return await handleSubFlowStep(currentFlowFrame, engine);
|
|
2576
2577
|
case 'SET':
|
|
2577
2578
|
return handleSetStep(currentFlowFrame, engine);
|
|
2578
|
-
case 'ASSESS-INPUT':
|
|
2579
|
-
return await handleAssessInputStep(currentFlowFrame, engine);
|
|
2580
2579
|
case 'SWITCH':
|
|
2581
2580
|
return await handleSwitchStep(currentFlowFrame, engine);
|
|
2582
2581
|
case 'CASE':
|
|
@@ -3908,43 +3907,6 @@ function addFlowContextGuidance(message, flowFrame, engine) {
|
|
|
3908
3907
|
return message + defaultSeparator + guidance;
|
|
3909
3908
|
}
|
|
3910
3909
|
}
|
|
3911
|
-
/** An explicitly declared field meaning is assessed separately from intent detection.
|
|
3912
|
-
* Clear the output before awaiting: a timeout or malformed verdict cannot retain an old acceptance.
|
|
3913
|
-
* The callback receives only this field's declared context; no account facts or unrelated history.
|
|
3914
|
-
*/
|
|
3915
|
-
async function handleAssessInputStep(frame, engine) {
|
|
3916
|
-
const step = frame.flowStepsStack.pop();
|
|
3917
|
-
const definition = engine.flowsMenu.find(flow => flow.id === frame.flowId || flow.name === frame.flowName);
|
|
3918
|
-
validateSemanticInputStep(step, definition);
|
|
3919
|
-
const variable = step.variable;
|
|
3920
|
-
frame.variables[variable] = { ok: false, disposition: 'retry', unavailable: true };
|
|
3921
|
-
const resolve = (text) => interpolateMessage(String(text ?? ''), frame.contextStack, frame.variables, engine);
|
|
3922
|
-
const input = resolve(step.value);
|
|
3923
|
-
const question = resolve(step.question);
|
|
3924
|
-
const purpose = resolve(step.purpose);
|
|
3925
|
-
const acceptance = resolve(step.acceptance);
|
|
3926
|
-
if (!input.trim()) {
|
|
3927
|
-
frame.variables[variable] = { ok: false, disposition: 'retry' };
|
|
3928
|
-
return 'Input assessment received an empty candidate';
|
|
3929
|
-
}
|
|
3930
|
-
if (!question.trim() || !purpose.trim() || !acceptance.trim()) {
|
|
3931
|
-
logger.warn(`ASSESS-INPUT step ${step.id || ''} could not validate its field; the input remains unaccepted`);
|
|
3932
|
-
return 'Input assessment requires a complete field context';
|
|
3933
|
-
}
|
|
3934
|
-
try {
|
|
3935
|
-
const assessment = buildInputAssessment({ value: input, question, purpose, acceptance });
|
|
3936
|
-
const schema = assessment.schema;
|
|
3937
|
-
const response = await fetchAiResponse(assessment.system, assessment.user, engine.aiCallback, engine.aiTimeOut, schema, { task: 'assess_input', input, question, purpose, acceptance });
|
|
3938
|
-
const result = normalizeInputAssessment(response);
|
|
3939
|
-
frame.variables[variable] = result;
|
|
3940
|
-
if ('unavailable' in result && result.unavailable === true)
|
|
3941
|
-
logger.warn(`ASSESS-INPUT step ${step.id || ''} could not validate its field; the input remains unaccepted`);
|
|
3942
|
-
}
|
|
3943
|
-
catch {
|
|
3944
|
-
logger.warn(`ASSESS-INPUT step ${step.id || ''} could not validate its field; the input remains unaccepted`);
|
|
3945
|
-
}
|
|
3946
|
-
return 'Input assessment completed';
|
|
3947
|
-
}
|
|
3948
3910
|
function handleSetStep(currentFlowFrame, engine) {
|
|
3949
3911
|
// Extract what we need from the currentFlowFrame
|
|
3950
3912
|
const step = currentFlowFrame.flowStepsStack.pop(); // This handler pops its own step
|
|
@@ -5456,6 +5418,9 @@ function createSimplifiedEvaluationContext(variables, contextStack, engine) {
|
|
|
5456
5418
|
Array,
|
|
5457
5419
|
JSON
|
|
5458
5420
|
};
|
|
5421
|
+
const functions = engine.getNamedFunctionNamespace();
|
|
5422
|
+
if (functions)
|
|
5423
|
+
context.fn = functions;
|
|
5459
5424
|
return context;
|
|
5460
5425
|
}
|
|
5461
5426
|
/**
|
|
@@ -6004,6 +5969,13 @@ async function processActivity(input, userId, engine) {
|
|
|
6004
5969
|
throw error;
|
|
6005
5970
|
}
|
|
6006
5971
|
const context = interpolateMessage(step.responseContext, frame.contextStack, frame.variables, engine).trim();
|
|
5972
|
+
if (declaration) {
|
|
5973
|
+
declaration.parameters = declaration.parameters.map((parameter) => ({ ...parameter, description: interpolateMessage(parameter.description, frame.contextStack, frame.variables, engine).trim() }));
|
|
5974
|
+
if (declaration.parameters.some((parameter) => !parameter.description)) {
|
|
5975
|
+
guardedRoutingFailed = true;
|
|
5976
|
+
throw new Error('Contextual response parameter description resolved empty');
|
|
5977
|
+
}
|
|
5978
|
+
}
|
|
6007
5979
|
const continuation = { id: '__jsfe_continue_current__', name: 'ContinueCurrent', version: '1.0.0', primary: true, steps: [], ...(declaration ? { parameters: declaration.parameters } : {}), description: `The caller is responding to the requested ${context} or reports that the requested information is invalid, unknown or unavailable; datos incorrectos o inválidos, no lo sé, no lo tengo, no puedo dar el dato. Includes asking how to provide the requested information. Not a different service request or unrelated question; choose its workflow when offered, otherwise None for the host.` };
|
|
6008
5980
|
let selected;
|
|
6009
5981
|
try {
|
|
@@ -6013,6 +5985,12 @@ async function processActivity(input, userId, engine) {
|
|
|
6013
5985
|
guardedRoutingFailed = true;
|
|
6014
5986
|
throw error;
|
|
6015
5987
|
}
|
|
5988
|
+
// A contextual handoff must not restart its own live workflow without new input.
|
|
5989
|
+
// The host has the broader dialogue needed to clarify this otherwise empty re-entry.
|
|
5990
|
+
if (selected && selected.flow.id !== continuation.id && !Object.keys(selected.parameters || {}).length && engine.flowStacks.flat().some(active => active.flowId === selected.flow.id)) {
|
|
5991
|
+
selected = null;
|
|
5992
|
+
detected = null;
|
|
5993
|
+
}
|
|
6016
5994
|
if (selected?.flow.id === continuation.id) {
|
|
6017
5995
|
if (declaration)
|
|
6018
5996
|
frame.variables[declaration.variable] = structuredClone(selected.parameters || {});
|
|
@@ -6301,6 +6279,53 @@ export class WorkflowEngine {
|
|
|
6301
6279
|
}
|
|
6302
6280
|
cargo;
|
|
6303
6281
|
flowsMenu;
|
|
6282
|
+
sourceFlowDeclarations;
|
|
6283
|
+
namedFunctionNamespaces = new Map();
|
|
6284
|
+
/** A detached authoring copy; engine compilation and validation never become editor source. */
|
|
6285
|
+
getFlowDeclarations() {
|
|
6286
|
+
return cloneFlowValue(this.sourceFlowDeclarations);
|
|
6287
|
+
}
|
|
6288
|
+
/** Engine-only lexical helpers for the current definition, never persisted in session variables. */
|
|
6289
|
+
getNamedFunctionNamespace() {
|
|
6290
|
+
if (!this.namedFunctionNamespaces.size)
|
|
6291
|
+
return undefined;
|
|
6292
|
+
const stack = this.flowStacks[this.flowStacks.length - 1] || [];
|
|
6293
|
+
const current = stack[stack.length - 1];
|
|
6294
|
+
if (!current)
|
|
6295
|
+
return undefined;
|
|
6296
|
+
const definition = this.flowsMenu.find(flow => flow.id === current.flowId);
|
|
6297
|
+
const namespaceFor = (flow) => {
|
|
6298
|
+
const source = flow?.metadata?.declaration?.source;
|
|
6299
|
+
return typeof source === 'string' ? this.namedFunctionNamespaces.get(source) : undefined;
|
|
6300
|
+
};
|
|
6301
|
+
// Generated workers retain the authoring source. A declared worker with no helpers
|
|
6302
|
+
// cannot accidentally borrow similarly named functions from an unrelated caller.
|
|
6303
|
+
if (definition?.metadata?.declaration?.version === 1)
|
|
6304
|
+
return namespaceFor(definition);
|
|
6305
|
+
const parameters = new Set((definition?.parameters || []).map(parameter => parameter.name));
|
|
6306
|
+
for (const name of ['form', 'rf_form', 'owner', 'form_instance', 'parent_form']) {
|
|
6307
|
+
if (!parameters.has(name))
|
|
6308
|
+
continue;
|
|
6309
|
+
const value = current.variables?.[name];
|
|
6310
|
+
if (typeof value !== 'string' || !value)
|
|
6311
|
+
continue;
|
|
6312
|
+
const state = this.cargo?.forms?.[value];
|
|
6313
|
+
// An explicit form owner is authoritative, including a missing/retired owner.
|
|
6314
|
+
// Never substitute a newer caller's similarly named functions for that scope.
|
|
6315
|
+
if (!state)
|
|
6316
|
+
return undefined;
|
|
6317
|
+
const owner = this.flowsMenu.find(flow => flow.id === state.definition);
|
|
6318
|
+
return namespaceFor(owner);
|
|
6319
|
+
}
|
|
6320
|
+
// Provider/form system workers may evaluate templates authored by their caller.
|
|
6321
|
+
// Search this active stack only: paused and newer sessions never supply a scope.
|
|
6322
|
+
for (let index = stack.length - 2; index >= 0; index--) {
|
|
6323
|
+
const caller = this.flowsMenu.find(flow => flow.id === stack[index].flowId);
|
|
6324
|
+
if (caller?.metadata?.declaration?.version === 1)
|
|
6325
|
+
return namespaceFor(caller);
|
|
6326
|
+
}
|
|
6327
|
+
return undefined;
|
|
6328
|
+
}
|
|
6304
6329
|
toolsRegistry;
|
|
6305
6330
|
APPROVED_FUNCTIONS;
|
|
6306
6331
|
sessionId;
|
|
@@ -6409,11 +6434,13 @@ export class WorkflowEngine {
|
|
|
6409
6434
|
hostLogger = hostLogger || logger; // Fallback to global fake logger if none provided
|
|
6410
6435
|
logger = withPiiRedaction(hostLogger); // Assign to global logger (a SAY-GET's `pii` answer never reaches it)
|
|
6411
6436
|
this.aiCallback = aiCallback;
|
|
6412
|
-
|
|
6437
|
+
this.sourceFlowDeclarations = cloneFlowValue(flowsMenu);
|
|
6438
|
+
const compiledFlows = compileFlowDeclarations(cloneFlowValue(this.sourceFlowDeclarations), { tools: toolsRegistry });
|
|
6439
|
+
for (const flow of compiledFlows) {
|
|
6413
6440
|
if (flow.safetyRevision !== undefined && (typeof flow.safetyRevision !== 'string' || !flow.safetyRevision.trim() || flow.safetyRevision !== flow.safetyRevision.trim()))
|
|
6414
6441
|
throw new Error('Invalid safetyRevision for flow ' + flow.id);
|
|
6415
6442
|
}
|
|
6416
|
-
this.flowsMenu = applyWraps(
|
|
6443
|
+
this.flowsMenu = applyWraps(compiledFlows);
|
|
6417
6444
|
if (toolsRegistry.some(tool => ACTION_TOOLS.some(internal => internal.id === tool.id)))
|
|
6418
6445
|
throw new Error('Internal JSFE action tool identities are reserved');
|
|
6419
6446
|
this.toolsRegistry = [...toolsRegistry, ...ACTION_TOOLS];
|
|
@@ -6430,6 +6457,16 @@ export class WorkflowEngine {
|
|
|
6430
6457
|
? await this.actionJournal.complete({ sessionId: this.sessionId, record, action, outcome, checkpoint: resumableActionSession(this.sessionContext, this.flowsMenu, await this.getActionRecoveryIdentity()) })
|
|
6431
6458
|
: { status: 'unknown', outcome: { status: 'unknown', reason: 'durable_journal_unavailable' } }),
|
|
6432
6459
|
};
|
|
6460
|
+
for (const flow of this.flowsMenu) {
|
|
6461
|
+
if (flow.metadata?.declaration?.version !== 1 || !flow.functions)
|
|
6462
|
+
continue;
|
|
6463
|
+
const functions = compileNamedFunctions(flow.functions, { approvedFunctions: this.APPROVED_FUNCTIONS, label: flow.id });
|
|
6464
|
+
if (!functions)
|
|
6465
|
+
continue;
|
|
6466
|
+
if (Object.prototype.hasOwnProperty.call(flow.variables || {}, 'fn') || (flow.parameters || []).some(parameter => parameter.name === 'fn') || Object.prototype.hasOwnProperty.call(this.APPROVED_FUNCTIONS, 'fn') || Object.prototype.hasOwnProperty.call(globalVariables || {}, 'fn'))
|
|
6467
|
+
throw new Error('Named functions ' + flow.id + ': fn is a reserved evaluation namespace');
|
|
6468
|
+
this.namedFunctionNamespaces.set(flow.id, functions);
|
|
6469
|
+
}
|
|
6433
6470
|
this.globalVariables = globalVariables ? { ...globalVariables } : {}; // Copy global variables to prevent external mutations
|
|
6434
6471
|
this.aiTimeOut = aiTimeOut ?? 2000; // Default to 2000ms (2 seconds)
|
|
6435
6472
|
// if validateOnInit is not provided, default to true
|
|
@@ -7372,7 +7409,7 @@ export class WorkflowEngine {
|
|
|
7372
7409
|
return;
|
|
7373
7410
|
}
|
|
7374
7411
|
// Validate step type
|
|
7375
|
-
const validStepTypes = ['SAY', 'SAY-GET', 'SET', 'SWITCH', 'CASE', 'CALL-TOOL', 'FLOW', 'RETURN', 'END', 'DISPATCH'
|
|
7412
|
+
const validStepTypes = ['SAY', 'SAY-GET', 'SET', 'SWITCH', 'CASE', 'CALL-TOOL', 'FLOW', 'RETURN', 'END', 'DISPATCH'];
|
|
7376
7413
|
if (!validStepTypes.includes(step.type)) {
|
|
7377
7414
|
state.errors.push(`Step "${step.id}" in flow "${flowDef.name}" has invalid type: ${step.type}`);
|
|
7378
7415
|
return;
|
|
@@ -7388,14 +7425,6 @@ export class WorkflowEngine {
|
|
|
7388
7425
|
case 'SET':
|
|
7389
7426
|
this._validateSetStep(step, flowDef, state, opts, currentScope);
|
|
7390
7427
|
break;
|
|
7391
|
-
case 'ASSESS-INPUT':
|
|
7392
|
-
try {
|
|
7393
|
-
validateSemanticInputStep(step, flowDef);
|
|
7394
|
-
}
|
|
7395
|
-
catch (error) {
|
|
7396
|
-
state.errors.push(`ASSESS-INPUT step "${step.id}" in flow "${flowDef.name}": ${error.message}`);
|
|
7397
|
-
}
|
|
7398
|
-
break;
|
|
7399
7428
|
case 'SWITCH':
|
|
7400
7429
|
this._validateSwitchStep(step, flowDef, state, opts, currentScope);
|
|
7401
7430
|
break;
|
package/dist/runtime-identity.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const JSFE_RUNTIME_FINGERPRINT = "sha256:
|
|
1
|
+
export const JSFE_RUNTIME_FINGERPRINT = "sha256:2e03bdc05fb1c013135fc03411f3ba77e58b0316d8cb49e9f9b49e86b9b0de17";
|