@plolink/sdk 0.0.6 → 0.0.8

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.
@@ -108,8 +108,44 @@ interface GroupSummary {
108
108
  /** 题目数量 */
109
109
  questionCount: number;
110
110
  }
111
+ /**
112
+ * 创建心理评测会话参数
113
+ */
114
+ interface CreatePsychologyTestSessionParams {
115
+ /** 题组代码列表 */
116
+ groupCodes: string[];
117
+ /** 业务模块 */
118
+ businessModule: string;
119
+ /** 业务码 */
120
+ businessCode: string;
121
+ /** 业务ID */
122
+ businessId: string;
123
+ /** 是否需要AI分析 */
124
+ needAnalysis: boolean;
125
+ /** 分析提示词(needAnalysis为true时必填) */
126
+ analysisPrompt?: string;
127
+ }
128
+ /**
129
+ * 创建心理评测会话响应
130
+ */
131
+ interface CreatePsychologyTestSessionResponse {
132
+ /** 评测会话ID */
133
+ sessionId: string;
134
+ }
135
+ /**
136
+ * 获取会话题目响应
137
+ */
138
+ interface GetSessionQuestionsResponse {
139
+ /** 题目列表 */
140
+ questions: QuestionInfo[];
141
+ /** 总题数 */
142
+ totalCount: number;
143
+ /** 题组摘要(按题组代码分组) */
144
+ groupSummary: Record<string, GroupSummary>;
145
+ }
111
146
  /**
112
147
  * 发起心理评测参数
148
+ * @deprecated 请使用 CreatePsychologyTestSessionParams
113
149
  */
114
150
  interface InitiatePsychologyTestParams {
115
151
  /** 题组代码列表 */
@@ -127,6 +163,7 @@ interface InitiatePsychologyTestParams {
127
163
  }
128
164
  /**
129
165
  * 发起心理评测响应
166
+ * @deprecated 请使用 CreatePsychologyTestSessionResponse + GetSessionQuestionsResponse
130
167
  */
131
168
  interface InitiatePsychologyTestResponse {
132
169
  /** 评测会话ID */
@@ -482,18 +519,20 @@ declare class PsychologyTest {
482
519
  private client;
483
520
  constructor(client: PlolinkClient);
484
521
  /**
485
- * 发起心理评测
522
+ * 创建心理评测会话
486
523
  *
487
524
  * @description
488
- * 根据题组代码列表发起心理评测会话,系统会自动生成打乱后的题目列表并返回。
525
+ * 创建心理评测会话记录(不返回题目)。
526
+ * 创建后需要调用 getSessionQuestions() 获取题目列表。
489
527
  *
490
- * @param params - 发起评测参数
491
- * @returns 评测会话信息,包含会话ID和题目列表
492
- * @throws {PlolinkError} 当参数验证失败或发起失败时抛出
528
+ * @param params - 创建会话参数
529
+ * @returns 会话信息,包含会话ID
530
+ * @throws {PlolinkError} 当参数验证失败或创建失败时抛出
493
531
  *
494
532
  * @example
495
533
  * ```typescript
496
- * const result = await client.psychologyTest.initiate({
534
+ * // 1. 创建会话
535
+ * const { sessionId } = await client.psychologyTest.createTestSession({
497
536
  * groupCodes: ['family_parenting', 'disc'],
498
537
  * businessModule: 'talent_assessment',
499
538
  * businessCode: 'job_match',
@@ -502,16 +541,59 @@ declare class PsychologyTest {
502
541
  * analysisPrompt: '请结合家庭养育方式和DISC行为模式,分析候选人的性格特点。'
503
542
  * });
504
543
  *
505
- * console.log(`评测会话ID: ${result.sessionId}`);
506
- * console.log(`共 ${result.totalCount} 道题目`);
507
- * console.log('题组摘要:', result.groupSummary);
544
+ * console.log(`评测会话已创建: ${sessionId}`);
545
+ *
546
+ * // 2. 获取题目
547
+ * const questions = await client.psychologyTest.getSessionQuestions(sessionId);
548
+ * ```
549
+ */
550
+ createTestSession(params: CreatePsychologyTestSessionParams): Promise<CreatePsychologyTestSessionResponse>;
551
+ /**
552
+ * 获取会话题目
553
+ *
554
+ * @description
555
+ * 获取心理评测会话的题目列表(动态生成,每次调用都会重新打乱题目顺序)。
556
+ *
557
+ * @param sessionId - 评测会话ID
558
+ * @returns 题目列表和题组摘要
559
+ * @throws {PlolinkError} 当会话不存在或获取失败时抛出
560
+ *
561
+ * @example
562
+ * ```typescript
563
+ * const questions = await client.psychologyTest.getSessionQuestions('clxxxx789012');
564
+ *
565
+ * console.log(`共 ${questions.totalCount} 道题目`);
566
+ * console.log('题组摘要:', questions.groupSummary);
508
567
  *
509
568
  * // 展示题目
510
- * result.questions.forEach((q, index) => {
569
+ * questions.questions.forEach((q, index) => {
511
570
  * console.log(`题目 ${index + 1}: ${q.content}`);
512
571
  * });
513
572
  * ```
514
573
  */
574
+ getSessionQuestions(sessionId: string): Promise<GetSessionQuestionsResponse>;
575
+ /**
576
+ * 发起心理评测(已废弃)
577
+ *
578
+ * @deprecated 此方法已废弃,将在 v2.0 中移除。请使用 createTestSession() + getSessionQuestions() 替代。
579
+ *
580
+ * @description
581
+ * 根据题组代码列表发起心理评测会话,系统会自动生成打乱后的题目列表并返回。
582
+ *
583
+ * **迁移建议**:
584
+ * ```typescript
585
+ * // 旧方式(已废弃)
586
+ * const result = await client.psychologyTest.initiate(params);
587
+ *
588
+ * // 新方式(推荐)
589
+ * const { sessionId } = await client.psychologyTest.createTestSession(params);
590
+ * const result = await client.psychologyTest.getSessionQuestions(sessionId);
591
+ * ```
592
+ *
593
+ * @param params - 发起评测参数
594
+ * @returns 评测会话信息,包含会话ID和题目列表
595
+ * @throws {PlolinkError} 当参数验证失败或发起失败时抛出
596
+ */
515
597
  initiate(params: InitiatePsychologyTestParams): Promise<InitiatePsychologyTestResponse>;
516
598
  /**
517
599
  * 提交心理评测
@@ -108,8 +108,44 @@ interface GroupSummary {
108
108
  /** 题目数量 */
109
109
  questionCount: number;
110
110
  }
111
+ /**
112
+ * 创建心理评测会话参数
113
+ */
114
+ interface CreatePsychologyTestSessionParams {
115
+ /** 题组代码列表 */
116
+ groupCodes: string[];
117
+ /** 业务模块 */
118
+ businessModule: string;
119
+ /** 业务码 */
120
+ businessCode: string;
121
+ /** 业务ID */
122
+ businessId: string;
123
+ /** 是否需要AI分析 */
124
+ needAnalysis: boolean;
125
+ /** 分析提示词(needAnalysis为true时必填) */
126
+ analysisPrompt?: string;
127
+ }
128
+ /**
129
+ * 创建心理评测会话响应
130
+ */
131
+ interface CreatePsychologyTestSessionResponse {
132
+ /** 评测会话ID */
133
+ sessionId: string;
134
+ }
135
+ /**
136
+ * 获取会话题目响应
137
+ */
138
+ interface GetSessionQuestionsResponse {
139
+ /** 题目列表 */
140
+ questions: QuestionInfo[];
141
+ /** 总题数 */
142
+ totalCount: number;
143
+ /** 题组摘要(按题组代码分组) */
144
+ groupSummary: Record<string, GroupSummary>;
145
+ }
111
146
  /**
112
147
  * 发起心理评测参数
148
+ * @deprecated 请使用 CreatePsychologyTestSessionParams
113
149
  */
114
150
  interface InitiatePsychologyTestParams {
115
151
  /** 题组代码列表 */
@@ -127,6 +163,7 @@ interface InitiatePsychologyTestParams {
127
163
  }
128
164
  /**
129
165
  * 发起心理评测响应
166
+ * @deprecated 请使用 CreatePsychologyTestSessionResponse + GetSessionQuestionsResponse
130
167
  */
131
168
  interface InitiatePsychologyTestResponse {
132
169
  /** 评测会话ID */
@@ -482,18 +519,20 @@ declare class PsychologyTest {
482
519
  private client;
483
520
  constructor(client: PlolinkClient);
484
521
  /**
485
- * 发起心理评测
522
+ * 创建心理评测会话
486
523
  *
487
524
  * @description
488
- * 根据题组代码列表发起心理评测会话,系统会自动生成打乱后的题目列表并返回。
525
+ * 创建心理评测会话记录(不返回题目)。
526
+ * 创建后需要调用 getSessionQuestions() 获取题目列表。
489
527
  *
490
- * @param params - 发起评测参数
491
- * @returns 评测会话信息,包含会话ID和题目列表
492
- * @throws {PlolinkError} 当参数验证失败或发起失败时抛出
528
+ * @param params - 创建会话参数
529
+ * @returns 会话信息,包含会话ID
530
+ * @throws {PlolinkError} 当参数验证失败或创建失败时抛出
493
531
  *
494
532
  * @example
495
533
  * ```typescript
496
- * const result = await client.psychologyTest.initiate({
534
+ * // 1. 创建会话
535
+ * const { sessionId } = await client.psychologyTest.createTestSession({
497
536
  * groupCodes: ['family_parenting', 'disc'],
498
537
  * businessModule: 'talent_assessment',
499
538
  * businessCode: 'job_match',
@@ -502,16 +541,59 @@ declare class PsychologyTest {
502
541
  * analysisPrompt: '请结合家庭养育方式和DISC行为模式,分析候选人的性格特点。'
503
542
  * });
504
543
  *
505
- * console.log(`评测会话ID: ${result.sessionId}`);
506
- * console.log(`共 ${result.totalCount} 道题目`);
507
- * console.log('题组摘要:', result.groupSummary);
544
+ * console.log(`评测会话已创建: ${sessionId}`);
545
+ *
546
+ * // 2. 获取题目
547
+ * const questions = await client.psychologyTest.getSessionQuestions(sessionId);
548
+ * ```
549
+ */
550
+ createTestSession(params: CreatePsychologyTestSessionParams): Promise<CreatePsychologyTestSessionResponse>;
551
+ /**
552
+ * 获取会话题目
553
+ *
554
+ * @description
555
+ * 获取心理评测会话的题目列表(动态生成,每次调用都会重新打乱题目顺序)。
556
+ *
557
+ * @param sessionId - 评测会话ID
558
+ * @returns 题目列表和题组摘要
559
+ * @throws {PlolinkError} 当会话不存在或获取失败时抛出
560
+ *
561
+ * @example
562
+ * ```typescript
563
+ * const questions = await client.psychologyTest.getSessionQuestions('clxxxx789012');
564
+ *
565
+ * console.log(`共 ${questions.totalCount} 道题目`);
566
+ * console.log('题组摘要:', questions.groupSummary);
508
567
  *
509
568
  * // 展示题目
510
- * result.questions.forEach((q, index) => {
569
+ * questions.questions.forEach((q, index) => {
511
570
  * console.log(`题目 ${index + 1}: ${q.content}`);
512
571
  * });
513
572
  * ```
514
573
  */
574
+ getSessionQuestions(sessionId: string): Promise<GetSessionQuestionsResponse>;
575
+ /**
576
+ * 发起心理评测(已废弃)
577
+ *
578
+ * @deprecated 此方法已废弃,将在 v2.0 中移除。请使用 createTestSession() + getSessionQuestions() 替代。
579
+ *
580
+ * @description
581
+ * 根据题组代码列表发起心理评测会话,系统会自动生成打乱后的题目列表并返回。
582
+ *
583
+ * **迁移建议**:
584
+ * ```typescript
585
+ * // 旧方式(已废弃)
586
+ * const result = await client.psychologyTest.initiate(params);
587
+ *
588
+ * // 新方式(推荐)
589
+ * const { sessionId } = await client.psychologyTest.createTestSession(params);
590
+ * const result = await client.psychologyTest.getSessionQuestions(sessionId);
591
+ * ```
592
+ *
593
+ * @param params - 发起评测参数
594
+ * @returns 评测会话信息,包含会话ID和题目列表
595
+ * @throws {PlolinkError} 当参数验证失败或发起失败时抛出
596
+ */
515
597
  initiate(params: InitiatePsychologyTestParams): Promise<InitiatePsychologyTestResponse>;
516
598
  /**
517
599
  * 提交心理评测
package/dist/index.cjs CHANGED
@@ -198,18 +198,20 @@ var PsychologyTest = class {
198
198
  this.client = client;
199
199
  }
200
200
  /**
201
- * 发起心理评测
201
+ * 创建心理评测会话
202
202
  *
203
203
  * @description
204
- * 根据题组代码列表发起心理评测会话,系统会自动生成打乱后的题目列表并返回。
204
+ * 创建心理评测会话记录(不返回题目)。
205
+ * 创建后需要调用 getSessionQuestions() 获取题目列表。
205
206
  *
206
- * @param params - 发起评测参数
207
- * @returns 评测会话信息,包含会话ID和题目列表
208
- * @throws {PlolinkError} 当参数验证失败或发起失败时抛出
207
+ * @param params - 创建会话参数
208
+ * @returns 会话信息,包含会话ID
209
+ * @throws {PlolinkError} 当参数验证失败或创建失败时抛出
209
210
  *
210
211
  * @example
211
212
  * ```typescript
212
- * const result = await client.psychologyTest.initiate({
213
+ * // 1. 创建会话
214
+ * const { sessionId } = await client.psychologyTest.createTestSession({
213
215
  * groupCodes: ['family_parenting', 'disc'],
214
216
  * businessModule: 'talent_assessment',
215
217
  * businessCode: 'job_match',
@@ -218,18 +220,118 @@ var PsychologyTest = class {
218
220
  * analysisPrompt: '请结合家庭养育方式和DISC行为模式,分析候选人的性格特点。'
219
221
  * });
220
222
  *
221
- * console.log(`评测会话ID: ${result.sessionId}`);
222
- * console.log(`共 ${result.totalCount} 道题目`);
223
- * console.log('题组摘要:', result.groupSummary);
223
+ * console.log(`评测会话已创建: ${sessionId}`);
224
+ *
225
+ * // 2. 获取题目
226
+ * const questions = await client.psychologyTest.getSessionQuestions(sessionId);
227
+ * ```
228
+ */
229
+ async createTestSession(params) {
230
+ this.client.logger.info("Creating psychology test session", {
231
+ groupCodes: params.groupCodes,
232
+ businessModule: params.businessModule,
233
+ businessCode: params.businessCode,
234
+ needAnalysis: params.needAnalysis
235
+ });
236
+ if (!params.groupCodes || params.groupCodes.length === 0) {
237
+ throw new chunkY3UJVC2L_cjs.PlolinkError(
238
+ "groupCodes is required and cannot be empty",
239
+ "VALIDATION_ERROR"
240
+ );
241
+ }
242
+ if (!params.businessModule || !params.businessCode || !params.businessId) {
243
+ throw new chunkY3UJVC2L_cjs.PlolinkError(
244
+ "businessModule, businessCode, and businessId are required",
245
+ "VALIDATION_ERROR"
246
+ );
247
+ }
248
+ if (params.needAnalysis && !params.analysisPrompt) {
249
+ throw new chunkY3UJVC2L_cjs.PlolinkError(
250
+ "analysisPrompt is required when needAnalysis is true",
251
+ "VALIDATION_ERROR"
252
+ );
253
+ }
254
+ try {
255
+ const response = await this.client.axiosInstance.post(
256
+ "/api/v1/psychology/test-sessions",
257
+ params
258
+ );
259
+ this.client.logger.info("Psychology test session created successfully", {
260
+ sessionId: response.sessionId
261
+ });
262
+ return response;
263
+ } catch (error) {
264
+ this.client.logger.error("Failed to create psychology test session", { error });
265
+ throw error;
266
+ }
267
+ }
268
+ /**
269
+ * 获取会话题目
270
+ *
271
+ * @description
272
+ * 获取心理评测会话的题目列表(动态生成,每次调用都会重新打乱题目顺序)。
273
+ *
274
+ * @param sessionId - 评测会话ID
275
+ * @returns 题目列表和题组摘要
276
+ * @throws {PlolinkError} 当会话不存在或获取失败时抛出
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * const questions = await client.psychologyTest.getSessionQuestions('clxxxx789012');
281
+ *
282
+ * console.log(`共 ${questions.totalCount} 道题目`);
283
+ * console.log('题组摘要:', questions.groupSummary);
224
284
  *
225
285
  * // 展示题目
226
- * result.questions.forEach((q, index) => {
286
+ * questions.questions.forEach((q, index) => {
227
287
  * console.log(`题目 ${index + 1}: ${q.content}`);
228
288
  * });
229
289
  * ```
230
290
  */
291
+ async getSessionQuestions(sessionId) {
292
+ this.client.logger.info("Getting session questions", { sessionId });
293
+ if (!sessionId) {
294
+ throw new chunkY3UJVC2L_cjs.PlolinkError("sessionId is required", "VALIDATION_ERROR");
295
+ }
296
+ try {
297
+ const response = await this.client.axiosInstance.get(
298
+ `/api/v1/psychology/test-sessions/${sessionId}/questions`
299
+ );
300
+ this.client.logger.info("Session questions retrieved successfully", {
301
+ sessionId,
302
+ totalCount: response.totalCount
303
+ });
304
+ return response;
305
+ } catch (error) {
306
+ this.client.logger.error("Failed to get session questions", { error, sessionId });
307
+ throw error;
308
+ }
309
+ }
310
+ /**
311
+ * 发起心理评测(已废弃)
312
+ *
313
+ * @deprecated 此方法已废弃,将在 v2.0 中移除。请使用 createTestSession() + getSessionQuestions() 替代。
314
+ *
315
+ * @description
316
+ * 根据题组代码列表发起心理评测会话,系统会自动生成打乱后的题目列表并返回。
317
+ *
318
+ * **迁移建议**:
319
+ * ```typescript
320
+ * // 旧方式(已废弃)
321
+ * const result = await client.psychologyTest.initiate(params);
322
+ *
323
+ * // 新方式(推荐)
324
+ * const { sessionId } = await client.psychologyTest.createTestSession(params);
325
+ * const result = await client.psychologyTest.getSessionQuestions(sessionId);
326
+ * ```
327
+ *
328
+ * @param params - 发起评测参数
329
+ * @returns 评测会话信息,包含会话ID和题目列表
330
+ * @throws {PlolinkError} 当参数验证失败或发起失败时抛出
331
+ */
231
332
  async initiate(params) {
232
- this.client.logger.info("Initiating psychology test", {
333
+ this.client.logger.warn("Using deprecated initiate() method. Please use createTestSession() + getSessionQuestions() instead.");
334
+ this.client.logger.info("Initiating psychology test (deprecated)", {
233
335
  groupCodes: params.groupCodes,
234
336
  businessModule: params.businessModule,
235
337
  businessCode: params.businessCode,
@@ -254,11 +356,13 @@ var PsychologyTest = class {
254
356
  );
255
357
  }
256
358
  try {
257
- const response = await this.client.axiosInstance.post(
258
- "/api/v1/psychology/test-sessions/initiate",
259
- params
260
- );
261
- this.client.logger.info("Psychology test initiated successfully", {
359
+ const { sessionId } = await this.createTestSession(params);
360
+ const questionsData = await this.getSessionQuestions(sessionId);
361
+ const response = {
362
+ sessionId,
363
+ ...questionsData
364
+ };
365
+ this.client.logger.info("Psychology test initiated successfully (deprecated)", {
262
366
  sessionId: response.sessionId,
263
367
  totalCount: response.totalCount
264
368
  });