@crewdle/web-sdk-types 1.0.13 → 1.0.14

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.
@@ -0,0 +1,89 @@
1
+ import { IJobParameters, IJobResult } from '../job';
2
+ /**
3
+ * The AI prompt source Enum
4
+ */
5
+ export declare enum PromptSource {
6
+ /**
7
+ * The prompt was generated by the AI.
8
+ */
9
+ AI = "ai",
10
+ /**
11
+ * The prompt was generated by a human.
12
+ */
13
+ Human = "human"
14
+ }
15
+ /**
16
+ * The AI prompt history Interface
17
+ * Represents the history of a prompt.
18
+ * @ignore
19
+ */
20
+ export interface IPromptHistory {
21
+ /**
22
+ * The source of the prompt.
23
+ */
24
+ source: PromptSource;
25
+ /**
26
+ * The prompt.
27
+ */
28
+ message: string;
29
+ }
30
+ export interface IPromptOptions {
31
+ /**
32
+ * The instructions for the AI job.
33
+ */
34
+ instructions?: string;
35
+ /**
36
+ * Whether to use RAG for the AI job.
37
+ */
38
+ useRAG?: boolean;
39
+ /**
40
+ * The context for the AI job.
41
+ */
42
+ context?: IPromptHistory[];
43
+ }
44
+ /**
45
+ * The AI job parameters Interface
46
+ * Parameters for AI job type.
47
+ * @ignore
48
+ */
49
+ export interface IJobParametersAI extends IJobParameters {
50
+ /**
51
+ * The prompt for the AI job.
52
+ */
53
+ prompt: string;
54
+ /**
55
+ * The instructions for the AI job.
56
+ */
57
+ instructions?: string;
58
+ /**
59
+ * Whether to use RAG for the AI job.
60
+ */
61
+ useRAG?: boolean;
62
+ /**
63
+ * The context for the AI job.
64
+ */
65
+ context?: IPromptHistory[];
66
+ }
67
+ /**
68
+ * The AI job result Interface
69
+ * Represents the result of an AI job.
70
+ * @ignore
71
+ */
72
+ export interface IJobResultAI extends IJobResult {
73
+ /**
74
+ * The output of the AI job.
75
+ */
76
+ output: string;
77
+ /**
78
+ * The tokens used by the AI job.
79
+ */
80
+ inputTokens?: number;
81
+ /**
82
+ * The tokens generated by the AI job.
83
+ */
84
+ outputTokens?: number;
85
+ /**
86
+ * The index of the output, in case of partial results.
87
+ */
88
+ index?: number;
89
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The AI prompt source Enum
3
+ */
4
+ export var PromptSource;
5
+ (function (PromptSource) {
6
+ /**
7
+ * The prompt was generated by the AI.
8
+ */
9
+ PromptSource["AI"] = "ai";
10
+ /**
11
+ * The prompt was generated by a human.
12
+ */
13
+ PromptSource["Human"] = "human";
14
+ })(PromptSource || (PromptSource = {}));
15
+ ;
16
+ ;
@@ -1,14 +1,21 @@
1
+ import { IPromptOptions } from '.';
1
2
  /**
2
3
  * Represents a context for a Generative AI service.
3
4
  * @category AI
4
5
  */
5
6
  export interface IGenerativeAIContext {
6
7
  /**
7
- * Prompt the Generative AI Context to start processing a prompt.
8
+ * Stream the response from the AI service.
8
9
  * @param prompt The prompt to start processing.
9
- * @returns The response from the AI service.
10
+ * @returns An async generator that yields the response.
10
11
  */
11
- prompt(prompt: string): AsyncGenerator<string>;
12
+ stream(prompt: string, options?: IPromptOptions): AsyncGenerator<string>;
13
+ /**
14
+ * Process the response from the AI service.
15
+ * @param prompt The prompt to start processing.
16
+ * @returns A promise that resolves with the response.
17
+ */
18
+ prompt(prompt: string, options?: IPromptOptions): Promise<string>;
12
19
  /**
13
20
  * Close the Generative AI Context.
14
21
  */
@@ -1,9 +1,10 @@
1
- import { IJob, IJobWorkerConnector, IJobResult } from '../job';
1
+ import { IJobRequest, IJobWorkerConnector, JobResponse } from '../job';
2
+ import { IJobParametersAI, IJobResultAI } from './GenerativeAI';
2
3
  /**
3
4
  * The generative AI worker connector interface.
4
5
  * @category Connector
5
6
  */
6
- export interface IGenerativeAIWorkerConnector extends IJobWorkerConnector {
7
+ export interface IGenerativeAIWorkerConnector extends IJobWorkerConnector<IJobParametersAI, IJobResultAI> {
7
8
  /**
8
9
  * Initialize the machine learning model.
9
10
  * @param llmModel The path to the LLM model.
@@ -26,7 +27,13 @@ export interface IGenerativeAIWorkerConnector extends IJobWorkerConnector {
26
27
  /**
27
28
  * Process a job.
28
29
  * @param job The job to process.
30
+ * @returns A promise that resolves with the job result.
31
+ */
32
+ processJob(job: IJobRequest<IJobParametersAI>): Promise<JobResponse<IJobResultAI>>;
33
+ /**
34
+ * Stream a job.
35
+ * @param job The job to stream.
29
36
  * @returns An async generator that yields the job result.
30
37
  */
31
- processJob(job: IJob): AsyncGenerator<IJobResult>;
38
+ processJobStream(job: IJobRequest<IJobParametersAI>): AsyncGenerator<JobResponse<IJobResultAI>>;
32
39
  }
@@ -1,3 +1,4 @@
1
+ export * from './GenerativeAI';
1
2
  export * from './GenerativeAIContext';
2
3
  export * from './GenerativeAIWorker';
3
4
  export * from './GenerativeAIWorkerConnector';
package/dist/ai/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './GenerativeAI';
1
2
  export * from './GenerativeAIContext';
2
3
  export * from './GenerativeAIWorker';
3
4
  export * from './GenerativeAIWorkerConnector';
package/dist/job/Job.d.ts CHANGED
@@ -1,9 +1,16 @@
1
1
  /**
2
- * IJob Interface
2
+ * Base IJobParameters Interface
3
+ * Allows providing parameters specific to the job type.
4
+ * @ignore
5
+ */
6
+ export interface IJobParameters {
7
+ }
8
+ /**
9
+ * Job request Interface
3
10
  * Represents a job to be executed by the JobService.
4
11
  * @ignore
5
12
  */
6
- export interface IJob {
13
+ export interface IJobRequest<T extends IJobParameters> {
7
14
  /**
8
15
  * The ID of the job.
9
16
  */
@@ -11,20 +18,30 @@ export interface IJob {
11
18
  /**
12
19
  * The parameters of the job.
13
20
  */
14
- parameters: JobParameters;
21
+ parameters: T;
15
22
  /**
16
23
  * The status of the job.
17
24
  */
18
25
  status?: JobStatus;
26
+ /**
27
+ * The type of the job.
28
+ */
29
+ jobType: JobType;
19
30
  }
20
31
  /**
21
32
  * JobType Enum
22
- * Provide this to create a job with a specific type.
33
+ * Represents the type of a job.
23
34
  * @ignore
24
35
  */
25
36
  export declare enum JobType {
26
- AI = 0,
27
- Other = 1
37
+ /**
38
+ * The job is expected to return a Promise with a result.
39
+ */
40
+ Job = "job",
41
+ /**
42
+ * The job is expected to return a stream iterator with results.
43
+ */
44
+ JobStream = "job-stream"
28
45
  }
29
46
  /**
30
47
  * JobStatus Enum
@@ -54,60 +71,53 @@ export declare enum JobStatus {
54
71
  Failed = "failed"
55
72
  }
56
73
  /**
57
- * Base IJobParameters Interface
58
- * Allows providing parameters specific to the job type.
59
- * @ignore
60
- */
61
- export interface IJobParameters {
62
- jobType: JobType;
63
- }
64
- /**
65
- * IJobParametersAI Interface
66
- * Parameters for AI job type.
74
+ * Base job result Interface
75
+ * Represents the result of a job.
67
76
  * @ignore
68
77
  */
69
- export interface IJobParametersAI extends IJobParameters {
70
- jobType: JobType.AI;
71
- prompt: string;
78
+ export interface IJobResult {
72
79
  }
73
80
  /**
74
- * JobParameters Type
75
- * Union of all job parameters interfaces.
76
- * @ignore
77
- */
78
- export type JobParameters = IJobParametersAI;
79
- /**
80
- * IJobResult Interface
81
- * Represents the result of a job.
81
+ * Job response Interface
82
+ * Represents the response from a job.
82
83
  * @ignore
83
84
  */
84
- export interface IJobResult {
85
+ export interface IJobResultResponse<T extends IJobResult> {
85
86
  /**
86
87
  * The ID of the job.
87
88
  */
88
89
  id: string;
89
90
  /**
90
- * The status of the job result.
91
+ * The status of the job.
91
92
  */
92
- status: JobStatus;
93
+ status: JobStatus.Partial | JobStatus.Completed;
93
94
  /**
94
95
  * The result of the job.
95
96
  */
96
- result: JobResult;
97
+ result: T;
97
98
  }
98
99
  /**
99
- * IJobResultAI Interface
100
- * Represents the result of an AI job.
100
+ * Job failed response Interface
101
+ * Represents a failed job response.
101
102
  * @ignore
102
103
  */
103
- export interface IJobResultAI {
104
- jobType: JobType.AI;
105
- output: string;
106
- index?: number;
104
+ export interface IJobFailedResponse {
105
+ /**
106
+ * The ID of the job.
107
+ */
108
+ id: string;
109
+ /**
110
+ * The status of the job.
111
+ */
112
+ status: JobStatus.Failed;
113
+ /**
114
+ * The error message.
115
+ */
116
+ message: string;
107
117
  }
108
118
  /**
109
- * JobResult Type
110
- * Union of all job result interfaces.
119
+ * Job response type
120
+ * Represents the response type from a job.
111
121
  * @ignore
112
122
  */
113
- export type JobResult = IJobResultAI;
123
+ export type JobResponse<T extends IJobResult> = IJobResultResponse<T> | IJobFailedResponse;
package/dist/job/Job.js CHANGED
@@ -1,12 +1,18 @@
1
1
  /**
2
2
  * JobType Enum
3
- * Provide this to create a job with a specific type.
3
+ * Represents the type of a job.
4
4
  * @ignore
5
5
  */
6
6
  export var JobType;
7
7
  (function (JobType) {
8
- JobType[JobType["AI"] = 0] = "AI";
9
- JobType[JobType["Other"] = 1] = "Other";
8
+ /**
9
+ * The job is expected to return a Promise with a result.
10
+ */
11
+ JobType["Job"] = "job";
12
+ /**
13
+ * The job is expected to return a stream iterator with results.
14
+ */
15
+ JobType["JobStream"] = "job-stream";
10
16
  })(JobType || (JobType = {}));
11
17
  /**
12
18
  * JobStatus Enum
@@ -1,28 +1,27 @@
1
1
  import type { Observable } from 'rxjs';
2
2
  import { IDataStream } from '../core/stream';
3
- import { IJob, IJobResult } from './Job';
3
+ import { IJobParameters, IJobRequest, IJobResult, JobResponse } from './Job';
4
4
  /**
5
5
  * The Job Dispatcher interface.
6
6
  * @ignore
7
7
  */
8
- export interface IJobDispatcher extends IDataStream {
8
+ export interface IJobDispatcher<T extends IJobParameters, U extends IJobResult> extends IDataStream {
9
9
  /**
10
10
  * Create a new job.
11
- * @param jobId The ID of the job.
12
- * @param parameters The parameters of the job.
11
+ * @param job The job to create.
13
12
  */
14
- createJob(job: IJob): Promise<Observable<IJobResult>>;
13
+ createJob(job: IJobRequest<T>): Promise<Observable<JobResponse<U>>>;
15
14
  /**
16
15
  * Get a job by ID.
17
16
  * @param id The ID of the job to get.
18
17
  * @returns The job.
19
18
  */
20
- getJob(id: string): IJob;
19
+ getJob(id: string): IJobRequest<T>;
21
20
  /**
22
21
  * Get all jobs.
23
22
  * @returns All jobs.
24
23
  */
25
- getJobs(): IJob[];
24
+ getJobs(): IJobRequest<T>[];
26
25
  /**
27
26
  * Close the Job Dispatcher.
28
27
  */
@@ -1,12 +1,17 @@
1
- import { IJob, IJobResult } from './Job';
1
+ import { IJobParameters, IJobRequest, IJobResult, JobResponse } from './Job';
2
2
  /**
3
3
  * The Job Worker Connector interface.
4
4
  * @ignore
5
5
  */
6
- export interface IJobWorkerConnector {
6
+ export interface IJobWorkerConnector<T extends IJobParameters, U extends IJobResult> {
7
7
  /**
8
8
  * Process a job.
9
9
  * @param job The job to process.
10
10
  */
11
- processJob(job: IJob): AsyncGenerator<IJobResult>;
11
+ processJob(job: IJobRequest<T>): Promise<JobResponse<U>>;
12
+ /**
13
+ * Process a job stream.
14
+ * @param job The job to process.
15
+ */
16
+ processJobStream(job: IJobRequest<T>): AsyncGenerator<JobResponse<U>>;
12
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewdle/web-sdk-types",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "The Crewdle Mist Web SDK public types and interfaces",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",