@jaypie/testkit 1.2.3 → 1.2.7

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.
@@ -213,6 +213,7 @@ function createMockTool(nameOrCallOrOptions, callOrOptions) {
213
213
  // Constants for mock values
214
214
  const TAG$3 = "AWS";
215
215
  const getMessages = createMockWrappedFunction(original.getMessages, []);
216
+ const getS3FileBuffer = createMockFunction(async ({ bucket, key }) => Buffer.from(`_MOCK_S3_FILE_[${bucket}/${key}]`));
216
217
  const getSecret = createMockResolvedFunction("mock-secret-value");
217
218
  const sendMessage = createMockResolvedFunction({
218
219
  MessageId: "mock-message-id",
@@ -295,6 +296,7 @@ var aws = /*#__PURE__*/Object.freeze({
295
296
  formatSSE: formatSSE,
296
297
  getEnvSecret: getEnvSecret,
297
298
  getMessages: getMessages,
299
+ getS3FileBuffer: getS3FileBuffer,
298
300
  getSecret: getSecret,
299
301
  getSingletonMessage: getSingletonMessage,
300
302
  getTextractJob: getTextractJob,
@@ -591,6 +593,207 @@ var datadog = /*#__PURE__*/Object.freeze({
591
593
  submitMetricSet: submitMetricSet
592
594
  });
593
595
 
596
+ // Primary markers
597
+ const APEX$1 = "@"; // Root-level marker (DynamoDB prohibits empty strings)
598
+ const SEPARATOR$1 = "#"; // Composite key separator
599
+ // GSI names
600
+ const INDEX_ALIAS$1 = "indexAlias";
601
+ const INDEX_CLASS$1 = "indexClass";
602
+ const INDEX_OU$1 = "indexOu";
603
+ const INDEX_TYPE$1 = "indexType";
604
+ const INDEX_XID$1 = "indexXid";
605
+ // Index suffixes for soft state
606
+ const ARCHIVED_SUFFIX$1 = "#archived";
607
+ const DELETED_SUFFIX$1 = "#deleted";
608
+
609
+ /**
610
+ * Build the indexOu key for hierarchical queries
611
+ * @param ou - The organizational unit (APEX or "{parent.model}#{parent.id}")
612
+ * @param model - The entity model name
613
+ * @returns Composite key: "{ou}#{model}"
614
+ */
615
+ function buildIndexOu$1(ou, model) {
616
+ return `${ou}${SEPARATOR$1}${model}`;
617
+ }
618
+ /**
619
+ * Build the indexAlias key for human-friendly lookups
620
+ * @param ou - The organizational unit
621
+ * @param model - The entity model name
622
+ * @param alias - The human-friendly alias
623
+ * @returns Composite key: "{ou}#{model}#{alias}"
624
+ */
625
+ function buildIndexAlias$1(ou, model, alias) {
626
+ return `${ou}${SEPARATOR$1}${model}${SEPARATOR$1}${alias}`;
627
+ }
628
+ /**
629
+ * Build the indexClass key for category filtering
630
+ * @param ou - The organizational unit
631
+ * @param model - The entity model name
632
+ * @param recordClass - The category classification
633
+ * @returns Composite key: "{ou}#{model}#{class}"
634
+ */
635
+ function buildIndexClass$1(ou, model, recordClass) {
636
+ return `${ou}${SEPARATOR$1}${model}${SEPARATOR$1}${recordClass}`;
637
+ }
638
+ /**
639
+ * Build the indexType key for type filtering
640
+ * @param ou - The organizational unit
641
+ * @param model - The entity model name
642
+ * @param type - The type classification
643
+ * @returns Composite key: "{ou}#{model}#{type}"
644
+ */
645
+ function buildIndexType$1(ou, model, type) {
646
+ return `${ou}${SEPARATOR$1}${model}${SEPARATOR$1}${type}`;
647
+ }
648
+ /**
649
+ * Build the indexXid key for external ID lookups
650
+ * @param ou - The organizational unit
651
+ * @param model - The entity model name
652
+ * @param xid - The external ID
653
+ * @returns Composite key: "{ou}#{model}#{xid}"
654
+ */
655
+ function buildIndexXid$1(ou, model, xid) {
656
+ return `${ou}${SEPARATOR$1}${model}${SEPARATOR$1}${xid}`;
657
+ }
658
+ /**
659
+ * Calculate the organizational unit from a parent reference
660
+ * @param parent - Optional parent entity reference
661
+ * @returns APEX ("@") if no parent, otherwise "{parent.model}#{parent.id}"
662
+ */
663
+ function calculateOu$1(parent) {
664
+ if (!parent) {
665
+ return APEX$1;
666
+ }
667
+ return `${parent.model}${SEPARATOR$1}${parent.id}`;
668
+ }
669
+ /**
670
+ * Auto-populate GSI index keys on an entity
671
+ * - indexOu is always populated from ou + model
672
+ * - indexAlias is populated only when alias is present
673
+ * - indexClass is populated only when class is present
674
+ * - indexType is populated only when type is present
675
+ * - indexXid is populated only when xid is present
676
+ *
677
+ * @param entity - The entity to populate index keys for
678
+ * @param suffix - Optional suffix to append to all index keys (e.g., "#deleted", "#archived")
679
+ * @returns The entity with populated index keys
680
+ */
681
+ function indexEntity$1(entity, suffix = "") {
682
+ const result = { ...entity };
683
+ // indexOu is always set (from ou + model)
684
+ result.indexOu = buildIndexOu$1(entity.ou, entity.model) + suffix;
685
+ // Optional indexes - only set when the source field is present
686
+ if (entity.alias !== undefined) {
687
+ result.indexAlias =
688
+ buildIndexAlias$1(entity.ou, entity.model, entity.alias) + suffix;
689
+ }
690
+ if (entity.class !== undefined) {
691
+ result.indexClass =
692
+ buildIndexClass$1(entity.ou, entity.model, entity.class) + suffix;
693
+ }
694
+ if (entity.type !== undefined) {
695
+ result.indexType =
696
+ buildIndexType$1(entity.ou, entity.model, entity.type) + suffix;
697
+ }
698
+ if (entity.xid !== undefined) {
699
+ result.indexXid =
700
+ buildIndexXid$1(entity.ou, entity.model, entity.xid) + suffix;
701
+ }
702
+ return result;
703
+ }
704
+
705
+ // Re-export constants (no need to mock, just pass through)
706
+ const APEX = APEX$1;
707
+ const ARCHIVED_SUFFIX = ARCHIVED_SUFFIX$1;
708
+ const DELETED_SUFFIX = DELETED_SUFFIX$1;
709
+ const INDEX_ALIAS = INDEX_ALIAS$1;
710
+ const INDEX_CLASS = INDEX_CLASS$1;
711
+ const INDEX_OU = INDEX_OU$1;
712
+ const INDEX_TYPE = INDEX_TYPE$1;
713
+ const INDEX_XID = INDEX_XID$1;
714
+ const SEPARATOR = SEPARATOR$1;
715
+ // Key builder functions - use createMockFunction with typed implementations
716
+ const buildIndexAlias = createMockFunction((ou, model, alias) => buildIndexAlias$1(ou, model, alias));
717
+ const buildIndexClass = createMockFunction((ou, model, recordClass) => buildIndexClass$1(ou, model, recordClass));
718
+ const buildIndexOu = createMockFunction((ou, model) => buildIndexOu$1(ou, model));
719
+ const buildIndexType = createMockFunction((ou, model, type) => buildIndexType$1(ou, model, type));
720
+ const buildIndexXid = createMockFunction((ou, model, xid) => buildIndexXid$1(ou, model, xid));
721
+ const calculateOu = createMockFunction((parent) => calculateOu$1(parent));
722
+ const indexEntity = createMockFunction((entity, suffix) => indexEntity$1(entity, suffix));
723
+ // Client functions
724
+ const initClient = createMockFunction(() => {
725
+ // No-op in mock
726
+ });
727
+ const getDocClient = createMockFunction(() => ({
728
+ send: createMockResolvedFunction({ Items: [] }),
729
+ }));
730
+ const getTableName = createMockFunction(() => "mock-table");
731
+ const isInitialized = createMockFunction(() => true);
732
+ const resetClient = createMockFunction(() => {
733
+ // No-op in mock
734
+ });
735
+ // Entity operations - return mock data
736
+ const getEntity = createMockFunction(async () => null);
737
+ const putEntity = createMockFunction(async (params) => indexEntity$1(params.entity));
738
+ const updateEntity = createMockFunction(async (params) => ({
739
+ ...indexEntity$1(params.entity),
740
+ updatedAt: new Date().toISOString(),
741
+ }));
742
+ const deleteEntity = createMockFunction(async () => true);
743
+ const archiveEntity = createMockFunction(async () => true);
744
+ const destroyEntity = createMockFunction(async () => true);
745
+ // Query functions - return empty results by default (use object params)
746
+ const queryByOu = createMockFunction(async () => ({
747
+ items: [],
748
+ lastEvaluatedKey: undefined,
749
+ }));
750
+ const queryByAlias = createMockFunction(async () => null);
751
+ const queryByClass = createMockFunction(async () => ({
752
+ items: [],
753
+ lastEvaluatedKey: undefined,
754
+ }));
755
+ const queryByType = createMockFunction(async () => ({
756
+ items: [],
757
+ lastEvaluatedKey: undefined,
758
+ }));
759
+ const queryByXid = createMockFunction(async () => null);
760
+
761
+ var dynamodb = /*#__PURE__*/Object.freeze({
762
+ __proto__: null,
763
+ APEX: APEX,
764
+ ARCHIVED_SUFFIX: ARCHIVED_SUFFIX,
765
+ DELETED_SUFFIX: DELETED_SUFFIX,
766
+ INDEX_ALIAS: INDEX_ALIAS,
767
+ INDEX_CLASS: INDEX_CLASS,
768
+ INDEX_OU: INDEX_OU,
769
+ INDEX_TYPE: INDEX_TYPE,
770
+ INDEX_XID: INDEX_XID,
771
+ SEPARATOR: SEPARATOR,
772
+ archiveEntity: archiveEntity,
773
+ buildIndexAlias: buildIndexAlias,
774
+ buildIndexClass: buildIndexClass,
775
+ buildIndexOu: buildIndexOu,
776
+ buildIndexType: buildIndexType,
777
+ buildIndexXid: buildIndexXid,
778
+ calculateOu: calculateOu,
779
+ deleteEntity: deleteEntity,
780
+ destroyEntity: destroyEntity,
781
+ getDocClient: getDocClient,
782
+ getEntity: getEntity,
783
+ getTableName: getTableName,
784
+ indexEntity: indexEntity,
785
+ initClient: initClient,
786
+ isInitialized: isInitialized,
787
+ putEntity: putEntity,
788
+ queryByAlias: queryByAlias,
789
+ queryByClass: queryByClass,
790
+ queryByOu: queryByOu,
791
+ queryByType: queryByType,
792
+ queryByXid: queryByXid,
793
+ resetClient: resetClient,
794
+ updateEntity: updateEntity
795
+ });
796
+
594
797
  /* eslint-disable @typescript-eslint/no-unsafe-function-type */
595
798
  // Constants for mock values
596
799
  const TAG$1 = "EXPRESS";
@@ -858,6 +1061,7 @@ var lambda = /*#__PURE__*/Object.freeze({
858
1061
 
859
1062
  const LLM = original$3.LLM;
860
1063
  const mockOperate = createMockResolvedFunction({
1064
+ content: "_MOCK_OUTPUT_TEXT",
861
1065
  history: [
862
1066
  {
863
1067
  content: "_MOCK_USER_INPUT",
@@ -883,6 +1087,7 @@ const mockOperate = createMockResolvedFunction({
883
1087
  },
884
1088
  ],
885
1089
  provider: "_MOCK_PROVIDER",
1090
+ reasoning: [],
886
1091
  responses: [
887
1092
  {
888
1093
  id: "_MOCK_RESPONSE_ID",
@@ -904,7 +1109,6 @@ const mockOperate = createMockResolvedFunction({
904
1109
  model: "_MOCK_MODEL",
905
1110
  },
906
1111
  ],
907
- content: "_MOCK_OUTPUT_TEXT",
908
1112
  });
909
1113
  const mockSend = createMockResolvedFunction("_MOCK_LLM_RESPONSE");
910
1114
  const Llm = Object.assign(vi.fn().mockImplementation((providerName = "_MOCK_LLM_PROVIDER") => ({
@@ -949,6 +1153,12 @@ const GeminiProvider = createMockWrappedObject(original$3.GeminiProvider, {
949
1153
  const OpenRouterProvider = createMockWrappedObject(original$3.OpenRouterProvider, {
950
1154
  isClass: true,
951
1155
  });
1156
+ // Type guards and utilities - re-export from original (these are pure functions)
1157
+ const extractReasoning = original$3.extractReasoning;
1158
+ const isLlmOperateInput = original$3.isLlmOperateInput;
1159
+ const isLlmOperateInputContent = original$3.isLlmOperateInputContent;
1160
+ const isLlmOperateInputFile = original$3.isLlmOperateInputFile;
1161
+ const isLlmOperateInputImage = original$3.isLlmOperateInputImage;
952
1162
  // Tool collections
953
1163
  const toolkit = new original$3.JaypieToolkit([
954
1164
  random,
@@ -969,6 +1179,11 @@ var llm = /*#__PURE__*/Object.freeze({
969
1179
  LlmStreamChunkType: LlmStreamChunkType,
970
1180
  OpenRouterProvider: OpenRouterProvider,
971
1181
  Toolkit: Toolkit,
1182
+ extractReasoning: extractReasoning,
1183
+ isLlmOperateInput: isLlmOperateInput,
1184
+ isLlmOperateInputContent: isLlmOperateInputContent,
1185
+ isLlmOperateInputFile: isLlmOperateInputFile,
1186
+ isLlmOperateInputImage: isLlmOperateInputImage,
972
1187
  toolkit: toolkit,
973
1188
  tools: tools
974
1189
  });
@@ -1037,6 +1252,21 @@ var textract$1 = /*#__PURE__*/Object.freeze({
1037
1252
  });
1038
1253
 
1039
1254
  // Mock implementations for @jaypie/vocabulary
1255
+ // Status Type - re-export real values (no mocking needed)
1256
+ const STATUS_VALUES = [
1257
+ "canceled",
1258
+ "complete",
1259
+ "error",
1260
+ "pending",
1261
+ "processing",
1262
+ "queued",
1263
+ "sending",
1264
+ ];
1265
+ const StatusType = [...STATUS_VALUES];
1266
+ function isStatus(value) {
1267
+ return (typeof value === "string" &&
1268
+ STATUS_VALUES.includes(value));
1269
+ }
1040
1270
  /**
1041
1271
  * Mock implementation of lambdaServiceHandler
1042
1272
  * Mirrors the real implementation: wraps a service handler for Lambda with getMessages processing
@@ -1084,10 +1314,72 @@ const lambdaServiceHandler = createMockFunction((handlerOrConfig, options = {})
1084
1314
  validate: opts.validate,
1085
1315
  });
1086
1316
  });
1317
+ /**
1318
+ * Mock implementation of createLlmTool
1319
+ * Creates an LLM tool from a vocabulary service handler
1320
+ */
1321
+ const createLlmTool = createMockFunction((config) => {
1322
+ const { description, handler, message, name } = config;
1323
+ const toolName = name ?? handler.alias ?? "tool";
1324
+ const toolDescription = description ?? handler.description ?? "";
1325
+ const tool = {
1326
+ call: async (args) => {
1327
+ return handler(args);
1328
+ },
1329
+ description: toolDescription,
1330
+ name: toolName,
1331
+ parameters: {
1332
+ properties: {},
1333
+ required: [],
1334
+ type: "object",
1335
+ },
1336
+ type: "function",
1337
+ };
1338
+ if (message !== undefined) {
1339
+ tool.message = message;
1340
+ }
1341
+ return { tool };
1342
+ });
1343
+ /**
1344
+ * Mock implementation of inputToJsonSchema
1345
+ * Converts vocabulary input definitions to JSON Schema
1346
+ */
1347
+ const inputToJsonSchema = createMockFunction(() => ({
1348
+ properties: {},
1349
+ required: [],
1350
+ type: "object",
1351
+ }));
1352
+ /**
1353
+ * Mock implementation of registerMcpTool
1354
+ * Registers a vocabulary service handler as an MCP tool
1355
+ */
1356
+ const registerMcpTool = createMockFunction((config) => {
1357
+ const { description, handler, name, server } = config;
1358
+ const toolName = name ?? handler.alias ?? "tool";
1359
+ const toolDescription = description ?? handler.description ?? "";
1360
+ server.tool(toolName, toolDescription, {}, async (args) => {
1361
+ const result = await handler(args);
1362
+ return {
1363
+ content: [
1364
+ {
1365
+ text: result === undefined || result === null ? "" : String(result),
1366
+ type: "text",
1367
+ },
1368
+ ],
1369
+ };
1370
+ });
1371
+ return { name: toolName };
1372
+ });
1087
1373
 
1088
1374
  var vocabulary = /*#__PURE__*/Object.freeze({
1089
1375
  __proto__: null,
1090
- lambdaServiceHandler: lambdaServiceHandler
1376
+ STATUS_VALUES: STATUS_VALUES,
1377
+ StatusType: StatusType,
1378
+ createLlmTool: createLlmTool,
1379
+ inputToJsonSchema: inputToJsonSchema,
1380
+ isStatus: isStatus,
1381
+ lambdaServiceHandler: lambdaServiceHandler,
1382
+ registerMcpTool: registerMcpTool
1091
1383
  });
1092
1384
 
1093
1385
  // Import all mocks
@@ -1099,15 +1391,19 @@ const mock = {
1099
1391
  ...core,
1100
1392
  // Datadog module
1101
1393
  ...datadog,
1394
+ // DynamoDB module
1395
+ ...dynamodb,
1102
1396
  // Express module
1103
1397
  ...express,
1398
+ // Kit module
1104
1399
  ...kit,
1105
1400
  // Lambda module
1106
1401
  ...lambda,
1107
1402
  // LLM module
1108
1403
  ...llm,
1404
+ // Logger module
1109
1405
  ...logger,
1110
- // Mongoose module (now empty)
1406
+ // Mongoose module
1111
1407
  ...mongoose,
1112
1408
  // Textract module
1113
1409
  ...textract$1,
@@ -1115,5 +1411,5 @@ const mock = {
1115
1411
  ...vocabulary,
1116
1412
  };
1117
1413
 
1118
- export { BadGatewayError, BadRequestError, ConfigurationError, CorsError, DATADOG, EXPRESS, ForbiddenError, GatewayTimeoutError, GeminiProvider, GoneError, HTTP$1 as HTTP, IllogicalError, InternalError, JAYPIE, JaypieError, JaypieStream, JaypieToolkit, LLM, Llm, LlmMessageRole, LlmMessageType, LlmStreamChunkType, MarkdownPage, MethodNotAllowedError, MultiError, NotFoundError, NotImplementedError, OpenRouterProvider, PROJECT, ProjectError, ProjectMultiError, RejectedError, TeapotError, TooManyRequestsError, Toolkit, UnauthorizedError, UnavailableError, UnhandledError, UnreachableCodeError, badRequestRoute, cloneDeep, connect, connectFromSecretEnv, cors, createExpressStream, createJaypieStream, createLambdaStream, createLogger, mock as default, disconnect, echoRoute, envBoolean, envsKey, errorFromStatusCode, expressHandler, expressHttpCodeHandler, expressStreamHandler, forbiddenRoute, force, formatError, formatSSE, getEnvSecret, getHeaderFrom, getMessages, getObjectKeyCaseInsensitive, getSecret, getSingletonMessage, getTextractJob, goneRoute, hasDatadogEnv, isClass, isJaypieError, isLocalEnv, isNodeTestEnv, isProductionEnv, jaypieErrorFromStatus, jaypieHandler, lambdaHandler, lambdaServiceHandler, lambdaStreamHandler, loadEnvSecrets, methodNotAllowedRoute, noContentRoute, notFoundRoute, notImplementedRoute, placeholders, resolveValue, safeParseFloat, sendBatchMessages, sendMessage, sendTextractJob, sleep, streamToSSE, submitDistribution, submitMetric, submitMetricSet, textractJsonToMarkdown, toolkit, tools, uuid };
1414
+ export { APEX, ARCHIVED_SUFFIX, BadGatewayError, BadRequestError, ConfigurationError, CorsError, DATADOG, DELETED_SUFFIX, EXPRESS, ForbiddenError, GatewayTimeoutError, GeminiProvider, GoneError, HTTP$1 as HTTP, INDEX_ALIAS, INDEX_CLASS, INDEX_OU, INDEX_TYPE, INDEX_XID, IllogicalError, InternalError, JAYPIE, JaypieError, JaypieStream, JaypieToolkit, LLM, Llm, LlmMessageRole, LlmMessageType, LlmStreamChunkType, MarkdownPage, MethodNotAllowedError, MultiError, NotFoundError, NotImplementedError, OpenRouterProvider, PROJECT, ProjectError, ProjectMultiError, RejectedError, SEPARATOR, STATUS_VALUES, StatusType, TeapotError, TooManyRequestsError, Toolkit, UnauthorizedError, UnavailableError, UnhandledError, UnreachableCodeError, archiveEntity, badRequestRoute, buildIndexAlias, buildIndexClass, buildIndexOu, buildIndexType, buildIndexXid, calculateOu, cloneDeep, connect, connectFromSecretEnv, cors, createExpressStream, createJaypieStream, createLambdaStream, createLlmTool, createLogger, mock as default, deleteEntity, destroyEntity, disconnect, echoRoute, envBoolean, envsKey, errorFromStatusCode, expressHandler, expressHttpCodeHandler, expressStreamHandler, extractReasoning, forbiddenRoute, force, formatError, formatSSE, getDocClient, getEntity, getEnvSecret, getHeaderFrom, getMessages, getObjectKeyCaseInsensitive, getS3FileBuffer, getSecret, getSingletonMessage, getTableName, getTextractJob, goneRoute, hasDatadogEnv, indexEntity, initClient, inputToJsonSchema, isClass, isInitialized, isJaypieError, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, isLocalEnv, isNodeTestEnv, isProductionEnv, isStatus, jaypieErrorFromStatus, jaypieHandler, lambdaHandler, lambdaServiceHandler, lambdaStreamHandler, loadEnvSecrets, methodNotAllowedRoute, noContentRoute, notFoundRoute, notImplementedRoute, placeholders, putEntity, queryByAlias, queryByClass, queryByOu, queryByType, queryByXid, registerMcpTool, resetClient, resolveValue, safeParseFloat, sendBatchMessages, sendMessage, sendTextractJob, sleep, streamToSSE, submitDistribution, submitMetric, submitMetricSet, textractJsonToMarkdown, toolkit, tools, updateEntity, uuid };
1119
1415
  //# sourceMappingURL=index.js.map