quidproquo-actionprocessor-node 0.1.14 → 0.1.15
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/lib/commonjs/actionProcessor/core/dynamicFunctions/getDynamicFunctionsExecuteActionProcessor.d.ts +2 -0
- package/lib/commonjs/actionProcessor/core/dynamicFunctions/getDynamicFunctionsExecuteActionProcessor.js +85 -0
- package/lib/commonjs/actionProcessor/core/dynamicFunctions/getDynamicFunctionsExecuteActionProcessor.js.map +1 -0
- package/lib/commonjs/actionProcessor/core/dynamicFunctions/index.d.ts +2 -0
- package/lib/commonjs/actionProcessor/core/dynamicFunctions/index.js +18 -0
- package/lib/commonjs/actionProcessor/core/dynamicFunctions/index.js.map +1 -0
- package/lib/commonjs/actionProcessor/core/index.d.ts +1 -0
- package/lib/commonjs/actionProcessor/core/index.js +4 -2
- package/lib/commonjs/actionProcessor/core/index.js.map +1 -1
- package/lib/esm/actionProcessor/core/dynamicFunctions/getDynamicFunctionsExecuteActionProcessor.d.ts +2 -0
- package/lib/esm/actionProcessor/core/dynamicFunctions/getDynamicFunctionsExecuteActionProcessor.js +70 -0
- package/lib/esm/actionProcessor/core/dynamicFunctions/getDynamicFunctionsExecuteActionProcessor.js.map +1 -0
- package/lib/esm/actionProcessor/core/dynamicFunctions/index.d.ts +2 -0
- package/lib/esm/actionProcessor/core/dynamicFunctions/index.js +5 -0
- package/lib/esm/actionProcessor/core/dynamicFunctions/index.js.map +1 -0
- package/lib/esm/actionProcessor/core/index.d.ts +1 -0
- package/lib/esm/actionProcessor/core/index.js +4 -1
- package/lib/esm/actionProcessor/core/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getDynamicFunctionsExecuteActionProcessor = void 0;
|
|
13
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
14
|
+
const crypto_1 = require("crypto");
|
|
15
|
+
const getDateNow = () => new Date().toISOString();
|
|
16
|
+
// The member execution contract: a member returning an iterable iterator (a sync
|
|
17
|
+
// generator - the shape of every qpq story) is driven through the runtime as a
|
|
18
|
+
// logged sub-story; anything else is a plain result, awaited if it is a promise.
|
|
19
|
+
const isStoryIterator = (value) => {
|
|
20
|
+
const candidate = value;
|
|
21
|
+
return typeof (candidate === null || candidate === void 0 ? void 0 : candidate.next) === 'function' && typeof (candidate === null || candidate === void 0 ? void 0 : candidate[Symbol.iterator]) === 'function';
|
|
22
|
+
};
|
|
23
|
+
const getErrorMessage = (error) => (error instanceof Error ? error.message : String(error));
|
|
24
|
+
const getProcessExecute = (qpqConfig) => {
|
|
25
|
+
const moduleName = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
26
|
+
return (payload, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const dynamicFunctions = quidproquo_core_1.qpqCoreUtils.getAllDynamicFunctions(qpqConfig);
|
|
28
|
+
const dynamicFunctionsSetting = dynamicFunctions.find((f) => f.dynamicFunctionsName === payload.dynamicFunctionsName);
|
|
29
|
+
if (!dynamicFunctionsSetting) {
|
|
30
|
+
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.DynamicFunctionsExecuteErrorTypeEnum.DynamicFunctionsNotFound, `Dynamic functions not found: [${payload.dynamicFunctionsName}]`);
|
|
31
|
+
}
|
|
32
|
+
const functionsObject = yield dynamicModuleLoader(dynamicFunctionsSetting.runtime);
|
|
33
|
+
if (!functionsObject) {
|
|
34
|
+
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.DynamicFunctionsExecuteErrorTypeEnum.ModuleLoadFailed, `Unable to dynamically load dynamic functions: [${payload.dynamicFunctionsName}]`);
|
|
35
|
+
}
|
|
36
|
+
// Own enumerable function properties only - the registered object IS the callable
|
|
37
|
+
// surface, nothing is reachable through its prototype.
|
|
38
|
+
const members = functionsObject;
|
|
39
|
+
const member = Object.prototype.hasOwnProperty.call(members, payload.functionName) ? members[payload.functionName] : undefined;
|
|
40
|
+
if (typeof member !== 'function') {
|
|
41
|
+
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.DynamicFunctionsExecuteErrorTypeEnum.FunctionNotFound, `Function not found: [${payload.dynamicFunctionsName}.${payload.functionName}]`);
|
|
42
|
+
}
|
|
43
|
+
let invocationResult;
|
|
44
|
+
try {
|
|
45
|
+
invocationResult = member(...payload.args);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.DynamicFunctionsExecuteErrorTypeEnum.FunctionThrew, `[${payload.dynamicFunctionsName}.${payload.functionName}] threw: ${getErrorMessage(error)}`);
|
|
49
|
+
}
|
|
50
|
+
if (isStoryIterator(invocationResult)) {
|
|
51
|
+
const resolveStory = (0, quidproquo_core_1.createRuntime)(qpqConfig, {
|
|
52
|
+
context: session.context,
|
|
53
|
+
localContext: session.localContext,
|
|
54
|
+
depth: (session.depth || 0) + 1,
|
|
55
|
+
decodedAccessToken: session.decodedAccessToken,
|
|
56
|
+
correlation: session.correlation,
|
|
57
|
+
// Dynamic function members run WITHIN the caller's function - carry its
|
|
58
|
+
// globals so stories can read route config (same rule as inline functions).
|
|
59
|
+
functionGlobals: session.functionGlobals,
|
|
60
|
+
}, () => __awaiter(void 0, void 0, void 0, function* () { return actionProcessors; }), getDateNow, logger, `${moduleName}::${(0, crypto_1.randomUUID)()}`, quidproquo_core_1.QpqRuntimeType.EXECUTE_STORY, dynamicModuleLoader, dynamicFunctionsSetting.runtime, [], streamRegistry);
|
|
61
|
+
// The member was already invoked to discover it is a story; the thunk hands
|
|
62
|
+
// the live iterator to the runtime without invoking it a second time.
|
|
63
|
+
const storyResult = yield resolveStory(() => invocationResult, []);
|
|
64
|
+
if (storyResult.error) {
|
|
65
|
+
return (0, quidproquo_core_1.actionResultError)(storyResult.error.errorType, storyResult.error.errorText, storyResult.error.errorStack
|
|
66
|
+
? `${payload.dynamicFunctionsName}.${payload.functionName} -> [${storyResult.error.errorStack}]`
|
|
67
|
+
: `${payload.dynamicFunctionsName}.${payload.functionName}`);
|
|
68
|
+
}
|
|
69
|
+
return (0, quidproquo_core_1.actionResult)(storyResult.result);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return (0, quidproquo_core_1.actionResult)((yield invocationResult));
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.DynamicFunctionsExecuteErrorTypeEnum.FunctionThrew, `[${payload.dynamicFunctionsName}.${payload.functionName}] threw: ${getErrorMessage(error)}`);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const getDynamicFunctionsExecuteActionProcessor = (qpqConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
return ({
|
|
81
|
+
[quidproquo_core_1.DynamicFunctionsActionType.Execute]: getProcessExecute(qpqConfig),
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
exports.getDynamicFunctionsExecuteActionProcessor = getDynamicFunctionsExecuteActionProcessor;
|
|
85
|
+
//# sourceMappingURL=getDynamicFunctionsExecuteActionProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDynamicFunctionsExecuteActionProcessor.js","sourceRoot":"","sources":["../../../../../src/actionProcessor/core/dynamicFunctions/getDynamicFunctionsExecuteActionProcessor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAoByB;AAEzB,mCAAoC;AAEpC,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAElD,iFAAiF;AACjF,+EAA+E;AAC/E,iFAAiF;AACjF,MAAM,eAAe,GAAG,CAAC,KAAc,EAAiC,EAAE;IACxE,MAAM,SAAS,GAAG,KAAkE,CAAC;IAErF,OAAO,OAAO,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,CAAA,KAAK,UAAU,IAAI,OAAO,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAG,MAAM,CAAC,QAAQ,CAAC,CAAA,KAAK,UAAU,CAAC;AACrG,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAE7G,MAAM,iBAAiB,GAAG,CAAI,SAAoB,EAA6C,EAAE;IAC/F,MAAM,UAAU,GAAG,8BAAY,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC;IAEpE,OAAO,CACL,OAA6C,EAC7C,OAAqB,EACrB,gBAAqC,EACrC,MAAiB,EACjB,aAAkC,EAClC,mBAAwC,EACxC,cAA8B,EAChB,EAAE;QAChB,MAAM,gBAAgB,GAAG,8BAAY,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QACxE,MAAM,uBAAuB,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,oBAAoB,KAAK,OAAO,CAAC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AI,CAAC,MAAM,gBAAgB,CAAM,CAAC,CAAC;QACxD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAA,mCAAiB,EACtB,sDAAoC,CAAC,aAAa,EAClD,IAAI,OAAO,CAAC,oBAAoB,IAAI,OAAO,CAAC,YAAY,YAAY,eAAe,CAAC,KAAK,CAAC,EAAE,CAC7F,CAAC;QACJ,CAAC;IACH,CAAC,CAAA,CAAC;AACJ,CAAC,CAAC;AAEK,MAAM,yCAAyC,GAAgC,CAAO,SAAoB,EAAgC,EAAE;IAAC,OAAA,CAAC;QACnJ,CAAC,4CAA0B,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC;KACnE,CAAC,CAAA;EAAA,CAAC;AAFU,QAAA,yCAAyC,6CAEnD","sourcesContent":["import {\n ActionProcessorList,\n ActionProcessorListResolver,\n actionResult,\n actionResultError,\n AskResponse,\n createRuntime,\n DynamicFunctionsActionType,\n DynamicFunctionsExecuteActionPayload,\n DynamicFunctionsExecuteActionProcessor,\n DynamicFunctionsExecuteErrorTypeEnum,\n DynamicModuleLoader,\n Nullable,\n QPQConfig,\n qpqCoreUtils,\n QpqLogger,\n QpqRuntimeType,\n StorySession,\n StorySessionUpdater,\n StreamRegistry,\n} from 'quidproquo-core';\n\nimport { randomUUID } from 'crypto';\n\nconst getDateNow = () => new Date().toISOString();\n\n// The member execution contract: a member returning an iterable iterator (a sync\n// generator - the shape of every qpq story) is driven through the runtime as a\n// logged sub-story; anything else is a plain result, awaited if it is a promise.\nconst isStoryIterator = (value: unknown): value is AskResponse<unknown> => {\n const candidate = value as Nullable<{ next?: unknown; [Symbol.iterator]?: unknown }>;\n\n return typeof candidate?.next === 'function' && typeof candidate?.[Symbol.iterator] === 'function';\n};\n\nconst getErrorMessage = (error: unknown): string => (error instanceof Error ? error.message : String(error));\n\nconst getProcessExecute = <R>(qpqConfig: QPQConfig): DynamicFunctionsExecuteActionProcessor<R> => {\n const moduleName = qpqCoreUtils.getApplicationModuleName(qpqConfig);\n\n return async (\n payload: DynamicFunctionsExecuteActionPayload,\n session: StorySession,\n actionProcessors: ActionProcessorList,\n logger: QpqLogger,\n updateSession: StorySessionUpdater,\n dynamicModuleLoader: DynamicModuleLoader,\n streamRegistry: StreamRegistry,\n ): Promise<any> => {\n const dynamicFunctions = qpqCoreUtils.getAllDynamicFunctions(qpqConfig);\n const dynamicFunctionsSetting = dynamicFunctions.find((f) => f.dynamicFunctionsName === payload.dynamicFunctionsName);\n\n if (!dynamicFunctionsSetting) {\n return actionResultError(\n DynamicFunctionsExecuteErrorTypeEnum.DynamicFunctionsNotFound,\n `Dynamic functions not found: [${payload.dynamicFunctionsName}]`,\n );\n }\n\n const functionsObject = await dynamicModuleLoader(dynamicFunctionsSetting.runtime);\n\n if (!functionsObject) {\n return actionResultError(\n DynamicFunctionsExecuteErrorTypeEnum.ModuleLoadFailed,\n `Unable to dynamically load dynamic functions: [${payload.dynamicFunctionsName}]`,\n );\n }\n\n // Own enumerable function properties only - the registered object IS the callable\n // surface, nothing is reachable through its prototype.\n const members = functionsObject as Record<string, unknown>;\n const member = Object.prototype.hasOwnProperty.call(members, payload.functionName) ? members[payload.functionName] : undefined;\n\n if (typeof member !== 'function') {\n return actionResultError(\n DynamicFunctionsExecuteErrorTypeEnum.FunctionNotFound,\n `Function not found: [${payload.dynamicFunctionsName}.${payload.functionName}]`,\n );\n }\n\n let invocationResult: unknown;\n try {\n invocationResult = member(...payload.args);\n } catch (error) {\n return actionResultError(\n DynamicFunctionsExecuteErrorTypeEnum.FunctionThrew,\n `[${payload.dynamicFunctionsName}.${payload.functionName}] threw: ${getErrorMessage(error)}`,\n );\n }\n\n if (isStoryIterator(invocationResult)) {\n const resolveStory = createRuntime(\n qpqConfig,\n {\n context: session.context,\n localContext: session.localContext,\n depth: (session.depth || 0) + 1,\n decodedAccessToken: session.decodedAccessToken,\n correlation: session.correlation,\n // Dynamic function members run WITHIN the caller's function - carry its\n // globals so stories can read route config (same rule as inline functions).\n functionGlobals: session.functionGlobals,\n },\n async () => actionProcessors,\n getDateNow,\n logger,\n `${moduleName}::${randomUUID()}`,\n QpqRuntimeType.EXECUTE_STORY,\n dynamicModuleLoader,\n dynamicFunctionsSetting.runtime,\n [],\n streamRegistry,\n );\n\n // The member was already invoked to discover it is a story; the thunk hands\n // the live iterator to the runtime without invoking it a second time.\n const storyResult = await resolveStory(() => invocationResult, []);\n\n if (storyResult.error) {\n return actionResultError(\n storyResult.error.errorType,\n storyResult.error.errorText,\n storyResult.error.errorStack\n ? `${payload.dynamicFunctionsName}.${payload.functionName} -> [${storyResult.error.errorStack}]`\n : `${payload.dynamicFunctionsName}.${payload.functionName}`,\n );\n }\n\n return actionResult<R>(storyResult.result);\n }\n\n try {\n return actionResult<R>((await invocationResult) as R);\n } catch (error) {\n return actionResultError(\n DynamicFunctionsExecuteErrorTypeEnum.FunctionThrew,\n `[${payload.dynamicFunctionsName}.${payload.functionName}] threw: ${getErrorMessage(error)}`,\n );\n }\n };\n};\n\nexport const getDynamicFunctionsExecuteActionProcessor: ActionProcessorListResolver = async (qpqConfig: QPQConfig): Promise<ActionProcessorList> => ({\n [DynamicFunctionsActionType.Execute]: getProcessExecute(qpqConfig),\n});\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getDynamicFunctionsActionProcessor = void 0;
|
|
13
|
+
const getDynamicFunctionsExecuteActionProcessor_1 = require("./getDynamicFunctionsExecuteActionProcessor");
|
|
14
|
+
const getDynamicFunctionsActionProcessor = (qpqConfig, dynamicModuleLoader) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
return (Object.assign({}, (yield (0, getDynamicFunctionsExecuteActionProcessor_1.getDynamicFunctionsExecuteActionProcessor)(qpqConfig, dynamicModuleLoader))));
|
|
16
|
+
});
|
|
17
|
+
exports.getDynamicFunctionsActionProcessor = getDynamicFunctionsActionProcessor;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/actionProcessor/core/dynamicFunctions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,2GAAwG;AAEjG,MAAM,kCAAkC,GAAgC,CAC7E,SAAoB,EACpB,mBAAwC,EACV,EAAE;IAAC,OAAA,mBAC9B,CAAC,MAAM,IAAA,qFAAyC,EAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC,EACpF,CAAA;EAAA,CAAC;AALU,QAAA,kCAAkC,sCAK5C","sourcesContent":["import { ActionProcessorList, ActionProcessorListResolver, DynamicModuleLoader, QPQConfig } from 'quidproquo-core';\n\nimport { getDynamicFunctionsExecuteActionProcessor } from './getDynamicFunctionsExecuteActionProcessor';\n\nexport const getDynamicFunctionsActionProcessor: ActionProcessorListResolver = async (\n qpqConfig: QPQConfig,\n dynamicModuleLoader: DynamicModuleLoader,\n): Promise<ActionProcessorList> => ({\n ...(await getDynamicFunctionsExecuteActionProcessor(qpqConfig, dynamicModuleLoader)),\n});\n"]}
|
|
@@ -25,16 +25,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.getCoreActionProcessor = void 0;
|
|
27
27
|
const quidproquo_actionprocessor_js_1 = require("quidproquo-actionprocessor-js");
|
|
28
|
+
const dynamicFunctions_1 = require("./dynamicFunctions");
|
|
28
29
|
const inlineFunction_1 = require("./inlineFunction");
|
|
29
30
|
const stream_1 = require("./stream");
|
|
30
31
|
// The shared core processors (config, context, claudeAi, date, error, guid, log,
|
|
31
32
|
// math, network, platform, system, customActions) are owned by
|
|
32
33
|
// quidproquo-actionprocessor-js. Node builds on top of js and only adds the
|
|
33
|
-
// processors that need a Node runtime (stream, inlineFunction).
|
|
34
|
+
// processors that need a Node runtime (stream, inlineFunction, dynamicFunctions).
|
|
35
|
+
__exportStar(require("./dynamicFunctions"), exports);
|
|
34
36
|
__exportStar(require("./inlineFunction"), exports);
|
|
35
37
|
__exportStar(require("./stream"), exports);
|
|
36
38
|
const getCoreActionProcessor = (qpqConfig, dynamicModuleLoader) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
return (Object.assign(Object.assign(Object.assign({}, (yield (0, quidproquo_actionprocessor_js_1.getCoreActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, stream_1.getStreamActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, inlineFunction_1.getInlineFunctionActionProcessor)(qpqConfig, dynamicModuleLoader))));
|
|
39
|
+
return (Object.assign(Object.assign(Object.assign(Object.assign({}, (yield (0, quidproquo_actionprocessor_js_1.getCoreActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, stream_1.getStreamActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, inlineFunction_1.getInlineFunctionActionProcessor)(qpqConfig, dynamicModuleLoader))), (yield (0, dynamicFunctions_1.getDynamicFunctionsActionProcessor)(qpqConfig, dynamicModuleLoader))));
|
|
38
40
|
});
|
|
39
41
|
exports.getCoreActionProcessor = getCoreActionProcessor;
|
|
40
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/actionProcessor/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iFAAmG;AAGnG,qDAAoE;AACpE,qCAAoD;AAEpD,iFAAiF;AACjF,+DAA+D;AAC/D,4EAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/actionProcessor/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iFAAmG;AAGnG,yDAAwE;AACxE,qDAAoE;AACpE,qCAAoD;AAEpD,iFAAiF;AACjF,+DAA+D;AAC/D,4EAA4E;AAC5E,kFAAkF;AAClF,qDAAmC;AACnC,mDAAiC;AACjC,2CAAyB;AAElB,MAAM,sBAAsB,GAAgC,CACjE,SAAoB,EACpB,mBAAwC,EACV,EAAE;IAAC,OAAA,6DAC9B,CAAC,MAAM,IAAA,sDAAwB,EAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC,GAChE,CAAC,MAAM,IAAA,iCAAwB,EAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC,GAChE,CAAC,MAAM,IAAA,iDAAgC,EAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC,GACxE,CAAC,MAAM,IAAA,qDAAkC,EAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC,EAC7E,CAAA;EAAA,CAAC;AARU,QAAA,sBAAsB,0BAQhC","sourcesContent":["import { getCoreActionProcessor as getJsCoreActionProcessor } from 'quidproquo-actionprocessor-js';\nimport { ActionProcessorList, ActionProcessorListResolver, DynamicModuleLoader, QPQConfig } from 'quidproquo-core';\n\nimport { getDynamicFunctionsActionProcessor } from './dynamicFunctions';\nimport { getInlineFunctionActionProcessor } from './inlineFunction';\nimport { getStreamActionProcessor } from './stream';\n\n// The shared core processors (config, context, claudeAi, date, error, guid, log,\n// math, network, platform, system, customActions) are owned by\n// quidproquo-actionprocessor-js. Node builds on top of js and only adds the\n// processors that need a Node runtime (stream, inlineFunction, dynamicFunctions).\nexport * from './dynamicFunctions';\nexport * from './inlineFunction';\nexport * from './stream';\n\nexport const getCoreActionProcessor: ActionProcessorListResolver = async (\n qpqConfig: QPQConfig,\n dynamicModuleLoader: DynamicModuleLoader,\n): Promise<ActionProcessorList> => ({\n ...(await getJsCoreActionProcessor(qpqConfig, dynamicModuleLoader)),\n ...(await getStreamActionProcessor(qpqConfig, dynamicModuleLoader)),\n ...(await getInlineFunctionActionProcessor(qpqConfig, dynamicModuleLoader)),\n ...(await getDynamicFunctionsActionProcessor(qpqConfig, dynamicModuleLoader)),\n});\n"]}
|
package/lib/esm/actionProcessor/core/dynamicFunctions/getDynamicFunctionsExecuteActionProcessor.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { actionResult, actionResultError, createRuntime, DynamicFunctionsActionType, DynamicFunctionsExecuteErrorTypeEnum, qpqCoreUtils, QpqRuntimeType, } from 'quidproquo-core';
|
|
2
|
+
import { randomUUID } from 'crypto';
|
|
3
|
+
const getDateNow = () => new Date().toISOString();
|
|
4
|
+
// The member execution contract: a member returning an iterable iterator (a sync
|
|
5
|
+
// generator - the shape of every qpq story) is driven through the runtime as a
|
|
6
|
+
// logged sub-story; anything else is a plain result, awaited if it is a promise.
|
|
7
|
+
const isStoryIterator = (value) => {
|
|
8
|
+
const candidate = value;
|
|
9
|
+
return typeof candidate?.next === 'function' && typeof candidate?.[Symbol.iterator] === 'function';
|
|
10
|
+
};
|
|
11
|
+
const getErrorMessage = (error) => (error instanceof Error ? error.message : String(error));
|
|
12
|
+
const getProcessExecute = (qpqConfig) => {
|
|
13
|
+
const moduleName = qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
14
|
+
return async (payload, session, actionProcessors, logger, updateSession, dynamicModuleLoader, streamRegistry) => {
|
|
15
|
+
const dynamicFunctions = qpqCoreUtils.getAllDynamicFunctions(qpqConfig);
|
|
16
|
+
const dynamicFunctionsSetting = dynamicFunctions.find((f) => f.dynamicFunctionsName === payload.dynamicFunctionsName);
|
|
17
|
+
if (!dynamicFunctionsSetting) {
|
|
18
|
+
return actionResultError(DynamicFunctionsExecuteErrorTypeEnum.DynamicFunctionsNotFound, `Dynamic functions not found: [${payload.dynamicFunctionsName}]`);
|
|
19
|
+
}
|
|
20
|
+
const functionsObject = await dynamicModuleLoader(dynamicFunctionsSetting.runtime);
|
|
21
|
+
if (!functionsObject) {
|
|
22
|
+
return actionResultError(DynamicFunctionsExecuteErrorTypeEnum.ModuleLoadFailed, `Unable to dynamically load dynamic functions: [${payload.dynamicFunctionsName}]`);
|
|
23
|
+
}
|
|
24
|
+
// Own enumerable function properties only - the registered object IS the callable
|
|
25
|
+
// surface, nothing is reachable through its prototype.
|
|
26
|
+
const members = functionsObject;
|
|
27
|
+
const member = Object.prototype.hasOwnProperty.call(members, payload.functionName) ? members[payload.functionName] : undefined;
|
|
28
|
+
if (typeof member !== 'function') {
|
|
29
|
+
return actionResultError(DynamicFunctionsExecuteErrorTypeEnum.FunctionNotFound, `Function not found: [${payload.dynamicFunctionsName}.${payload.functionName}]`);
|
|
30
|
+
}
|
|
31
|
+
let invocationResult;
|
|
32
|
+
try {
|
|
33
|
+
invocationResult = member(...payload.args);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return actionResultError(DynamicFunctionsExecuteErrorTypeEnum.FunctionThrew, `[${payload.dynamicFunctionsName}.${payload.functionName}] threw: ${getErrorMessage(error)}`);
|
|
37
|
+
}
|
|
38
|
+
if (isStoryIterator(invocationResult)) {
|
|
39
|
+
const resolveStory = createRuntime(qpqConfig, {
|
|
40
|
+
context: session.context,
|
|
41
|
+
localContext: session.localContext,
|
|
42
|
+
depth: (session.depth || 0) + 1,
|
|
43
|
+
decodedAccessToken: session.decodedAccessToken,
|
|
44
|
+
correlation: session.correlation,
|
|
45
|
+
// Dynamic function members run WITHIN the caller's function - carry its
|
|
46
|
+
// globals so stories can read route config (same rule as inline functions).
|
|
47
|
+
functionGlobals: session.functionGlobals,
|
|
48
|
+
}, async () => actionProcessors, getDateNow, logger, `${moduleName}::${randomUUID()}`, QpqRuntimeType.EXECUTE_STORY, dynamicModuleLoader, dynamicFunctionsSetting.runtime, [], streamRegistry);
|
|
49
|
+
// The member was already invoked to discover it is a story; the thunk hands
|
|
50
|
+
// the live iterator to the runtime without invoking it a second time.
|
|
51
|
+
const storyResult = await resolveStory(() => invocationResult, []);
|
|
52
|
+
if (storyResult.error) {
|
|
53
|
+
return actionResultError(storyResult.error.errorType, storyResult.error.errorText, storyResult.error.errorStack
|
|
54
|
+
? `${payload.dynamicFunctionsName}.${payload.functionName} -> [${storyResult.error.errorStack}]`
|
|
55
|
+
: `${payload.dynamicFunctionsName}.${payload.functionName}`);
|
|
56
|
+
}
|
|
57
|
+
return actionResult(storyResult.result);
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return actionResult((await invocationResult));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return actionResultError(DynamicFunctionsExecuteErrorTypeEnum.FunctionThrew, `[${payload.dynamicFunctionsName}.${payload.functionName}] threw: ${getErrorMessage(error)}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export const getDynamicFunctionsExecuteActionProcessor = async (qpqConfig) => ({
|
|
68
|
+
[DynamicFunctionsActionType.Execute]: getProcessExecute(qpqConfig),
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=getDynamicFunctionsExecuteActionProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDynamicFunctionsExecuteActionProcessor.js","sourceRoot":"","sources":["../../../../../src/actionProcessor/core/dynamicFunctions/getDynamicFunctionsExecuteActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACZ,iBAAiB,EAEjB,aAAa,EACb,0BAA0B,EAG1B,oCAAoC,EAIpC,YAAY,EAEZ,cAAc,GAIf,MAAM,iBAAiB,CAAC;AAE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M,CAAC,MAAM,yCAAyC,GAAgC,KAAK,EAAE,SAAoB,EAAgC,EAAE,CAAC,CAAC;IACnJ,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC;CACnE,CAAC,CAAC","sourcesContent":["import {\n ActionProcessorList,\n ActionProcessorListResolver,\n actionResult,\n actionResultError,\n AskResponse,\n createRuntime,\n DynamicFunctionsActionType,\n DynamicFunctionsExecuteActionPayload,\n DynamicFunctionsExecuteActionProcessor,\n DynamicFunctionsExecuteErrorTypeEnum,\n DynamicModuleLoader,\n Nullable,\n QPQConfig,\n qpqCoreUtils,\n QpqLogger,\n QpqRuntimeType,\n StorySession,\n StorySessionUpdater,\n StreamRegistry,\n} from 'quidproquo-core';\n\nimport { randomUUID } from 'crypto';\n\nconst getDateNow = () => new Date().toISOString();\n\n// The member execution contract: a member returning an iterable iterator (a sync\n// generator - the shape of every qpq story) is driven through the runtime as a\n// logged sub-story; anything else is a plain result, awaited if it is a promise.\nconst isStoryIterator = (value: unknown): value is AskResponse<unknown> => {\n const candidate = value as Nullable<{ next?: unknown; [Symbol.iterator]?: unknown }>;\n\n return typeof candidate?.next === 'function' && typeof candidate?.[Symbol.iterator] === 'function';\n};\n\nconst getErrorMessage = (error: unknown): string => (error instanceof Error ? error.message : String(error));\n\nconst getProcessExecute = <R>(qpqConfig: QPQConfig): DynamicFunctionsExecuteActionProcessor<R> => {\n const moduleName = qpqCoreUtils.getApplicationModuleName(qpqConfig);\n\n return async (\n payload: DynamicFunctionsExecuteActionPayload,\n session: StorySession,\n actionProcessors: ActionProcessorList,\n logger: QpqLogger,\n updateSession: StorySessionUpdater,\n dynamicModuleLoader: DynamicModuleLoader,\n streamRegistry: StreamRegistry,\n ): Promise<any> => {\n const dynamicFunctions = qpqCoreUtils.getAllDynamicFunctions(qpqConfig);\n const dynamicFunctionsSetting = dynamicFunctions.find((f) => f.dynamicFunctionsName === payload.dynamicFunctionsName);\n\n if (!dynamicFunctionsSetting) {\n return actionResultError(\n DynamicFunctionsExecuteErrorTypeEnum.DynamicFunctionsNotFound,\n `Dynamic functions not found: [${payload.dynamicFunctionsName}]`,\n );\n }\n\n const functionsObject = await dynamicModuleLoader(dynamicFunctionsSetting.runtime);\n\n if (!functionsObject) {\n return actionResultError(\n DynamicFunctionsExecuteErrorTypeEnum.ModuleLoadFailed,\n `Unable to dynamically load dynamic functions: [${payload.dynamicFunctionsName}]`,\n );\n }\n\n // Own enumerable function properties only - the registered object IS the callable\n // surface, nothing is reachable through its prototype.\n const members = functionsObject as Record<string, unknown>;\n const member = Object.prototype.hasOwnProperty.call(members, payload.functionName) ? members[payload.functionName] : undefined;\n\n if (typeof member !== 'function') {\n return actionResultError(\n DynamicFunctionsExecuteErrorTypeEnum.FunctionNotFound,\n `Function not found: [${payload.dynamicFunctionsName}.${payload.functionName}]`,\n );\n }\n\n let invocationResult: unknown;\n try {\n invocationResult = member(...payload.args);\n } catch (error) {\n return actionResultError(\n DynamicFunctionsExecuteErrorTypeEnum.FunctionThrew,\n `[${payload.dynamicFunctionsName}.${payload.functionName}] threw: ${getErrorMessage(error)}`,\n );\n }\n\n if (isStoryIterator(invocationResult)) {\n const resolveStory = createRuntime(\n qpqConfig,\n {\n context: session.context,\n localContext: session.localContext,\n depth: (session.depth || 0) + 1,\n decodedAccessToken: session.decodedAccessToken,\n correlation: session.correlation,\n // Dynamic function members run WITHIN the caller's function - carry its\n // globals so stories can read route config (same rule as inline functions).\n functionGlobals: session.functionGlobals,\n },\n async () => actionProcessors,\n getDateNow,\n logger,\n `${moduleName}::${randomUUID()}`,\n QpqRuntimeType.EXECUTE_STORY,\n dynamicModuleLoader,\n dynamicFunctionsSetting.runtime,\n [],\n streamRegistry,\n );\n\n // The member was already invoked to discover it is a story; the thunk hands\n // the live iterator to the runtime without invoking it a second time.\n const storyResult = await resolveStory(() => invocationResult, []);\n\n if (storyResult.error) {\n return actionResultError(\n storyResult.error.errorType,\n storyResult.error.errorText,\n storyResult.error.errorStack\n ? `${payload.dynamicFunctionsName}.${payload.functionName} -> [${storyResult.error.errorStack}]`\n : `${payload.dynamicFunctionsName}.${payload.functionName}`,\n );\n }\n\n return actionResult<R>(storyResult.result);\n }\n\n try {\n return actionResult<R>((await invocationResult) as R);\n } catch (error) {\n return actionResultError(\n DynamicFunctionsExecuteErrorTypeEnum.FunctionThrew,\n `[${payload.dynamicFunctionsName}.${payload.functionName}] threw: ${getErrorMessage(error)}`,\n );\n }\n };\n};\n\nexport const getDynamicFunctionsExecuteActionProcessor: ActionProcessorListResolver = async (qpqConfig: QPQConfig): Promise<ActionProcessorList> => ({\n [DynamicFunctionsActionType.Execute]: getProcessExecute(qpqConfig),\n});\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { getDynamicFunctionsExecuteActionProcessor } from './getDynamicFunctionsExecuteActionProcessor';
|
|
2
|
+
export const getDynamicFunctionsActionProcessor = async (qpqConfig, dynamicModuleLoader) => ({
|
|
3
|
+
...(await getDynamicFunctionsExecuteActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
4
|
+
});
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/actionProcessor/core/dynamicFunctions/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yCAAyC,EAAE,MAAM,6CAA6C,CAAC;AAExG,MAAM,CAAC,MAAM,kCAAkC,GAAgC,KAAK,EAClF,SAAoB,EACpB,mBAAwC,EACV,EAAE,CAAC,CAAC;IAClC,GAAG,CAAC,MAAM,yCAAyC,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;CACrF,CAAC,CAAC","sourcesContent":["import { ActionProcessorList, ActionProcessorListResolver, DynamicModuleLoader, QPQConfig } from 'quidproquo-core';\n\nimport { getDynamicFunctionsExecuteActionProcessor } from './getDynamicFunctionsExecuteActionProcessor';\n\nexport const getDynamicFunctionsActionProcessor: ActionProcessorListResolver = async (\n qpqConfig: QPQConfig,\n dynamicModuleLoader: DynamicModuleLoader,\n): Promise<ActionProcessorList> => ({\n ...(await getDynamicFunctionsExecuteActionProcessor(qpqConfig, dynamicModuleLoader)),\n});\n"]}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { getCoreActionProcessor as getJsCoreActionProcessor } from 'quidproquo-actionprocessor-js';
|
|
2
|
+
import { getDynamicFunctionsActionProcessor } from './dynamicFunctions';
|
|
2
3
|
import { getInlineFunctionActionProcessor } from './inlineFunction';
|
|
3
4
|
import { getStreamActionProcessor } from './stream';
|
|
4
5
|
// The shared core processors (config, context, claudeAi, date, error, guid, log,
|
|
5
6
|
// math, network, platform, system, customActions) are owned by
|
|
6
7
|
// quidproquo-actionprocessor-js. Node builds on top of js and only adds the
|
|
7
|
-
// processors that need a Node runtime (stream, inlineFunction).
|
|
8
|
+
// processors that need a Node runtime (stream, inlineFunction, dynamicFunctions).
|
|
9
|
+
export * from './dynamicFunctions';
|
|
8
10
|
export * from './inlineFunction';
|
|
9
11
|
export * from './stream';
|
|
10
12
|
export const getCoreActionProcessor = async (qpqConfig, dynamicModuleLoader) => ({
|
|
11
13
|
...(await getJsCoreActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
12
14
|
...(await getStreamActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
13
15
|
...(await getInlineFunctionActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
16
|
+
...(await getDynamicFunctionsActionProcessor(qpqConfig, dynamicModuleLoader)),
|
|
14
17
|
});
|
|
15
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/actionProcessor/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAGnG,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAEpD,iFAAiF;AACjF,+DAA+D;AAC/D,4EAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/actionProcessor/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAGnG,OAAO,EAAE,kCAAkC,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAEpD,iFAAiF;AACjF,+DAA+D;AAC/D,4EAA4E;AAC5E,kFAAkF;AAClF,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AAEzB,MAAM,CAAC,MAAM,sBAAsB,GAAgC,KAAK,EACtE,SAAoB,EACpB,mBAAwC,EACV,EAAE,CAAC,CAAC;IAClC,GAAG,CAAC,MAAM,wBAAwB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;IACnE,GAAG,CAAC,MAAM,wBAAwB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;IACnE,GAAG,CAAC,MAAM,gCAAgC,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;IAC3E,GAAG,CAAC,MAAM,kCAAkC,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;CAC9E,CAAC,CAAC","sourcesContent":["import { getCoreActionProcessor as getJsCoreActionProcessor } from 'quidproquo-actionprocessor-js';\nimport { ActionProcessorList, ActionProcessorListResolver, DynamicModuleLoader, QPQConfig } from 'quidproquo-core';\n\nimport { getDynamicFunctionsActionProcessor } from './dynamicFunctions';\nimport { getInlineFunctionActionProcessor } from './inlineFunction';\nimport { getStreamActionProcessor } from './stream';\n\n// The shared core processors (config, context, claudeAi, date, error, guid, log,\n// math, network, platform, system, customActions) are owned by\n// quidproquo-actionprocessor-js. Node builds on top of js and only adds the\n// processors that need a Node runtime (stream, inlineFunction, dynamicFunctions).\nexport * from './dynamicFunctions';\nexport * from './inlineFunction';\nexport * from './stream';\n\nexport const getCoreActionProcessor: ActionProcessorListResolver = async (\n qpqConfig: QPQConfig,\n dynamicModuleLoader: DynamicModuleLoader,\n): Promise<ActionProcessorList> => ({\n ...(await getJsCoreActionProcessor(qpqConfig, dynamicModuleLoader)),\n ...(await getStreamActionProcessor(qpqConfig, dynamicModuleLoader)),\n ...(await getInlineFunctionActionProcessor(qpqConfig, dynamicModuleLoader)),\n ...(await getDynamicFunctionsActionProcessor(qpqConfig, dynamicModuleLoader)),\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quidproquo-actionprocessor-node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/esm/index.js",
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@anthropic-ai/sdk": "^0.19.1",
|
|
36
36
|
"@jridgewell/trace-mapping": "^0.3.25",
|
|
37
|
-
"quidproquo-actionprocessor-js": "0.1.
|
|
38
|
-
"quidproquo-core": "0.1.
|
|
39
|
-
"quidproquo-webserver": "0.1.
|
|
37
|
+
"quidproquo-actionprocessor-js": "0.1.15",
|
|
38
|
+
"quidproquo-core": "0.1.15",
|
|
39
|
+
"quidproquo-webserver": "0.1.15",
|
|
40
40
|
"uuidv7": "^1.0.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@jridgewell/gen-mapping": "^0.3.13",
|
|
44
44
|
"@types/node": "^22.13.13",
|
|
45
|
-
"quidproquo-tsconfig": "0.1.
|
|
45
|
+
"quidproquo-tsconfig": "0.1.15",
|
|
46
46
|
"typescript": "^5.8.2"
|
|
47
47
|
}
|
|
48
48
|
}
|