@spektrum-ai/sdk 0.0.1

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 ADDED
@@ -0,0 +1,3 @@
1
+ # Spektrum TypeScript SDK
2
+
3
+ Spektrum is a Vibe Coding SDK that generates applications from requests and returns a URL to the deployed app.
@@ -0,0 +1,138 @@
1
+ type SpektrumSDKOptions = {
2
+ apiKey?: string;
3
+ endpoint?: string;
4
+ };
5
+ type CreateProjectResponse = {
6
+ id: string;
7
+ owner: string;
8
+ name?: string;
9
+ description?: string;
10
+ };
11
+ declare enum ActivityType {
12
+ COMMENT_LEFT = "COMMENT_LEFT",
13
+ DESCRIPTION_UPDATED = "DESCRIPTION_UPDATED",
14
+ FINISHED_WORK = "FINISHED_WORK",
15
+ STARTED_WORK = "STARTED_WORK",
16
+ TASK_CREATED = "TASK_CREATED",
17
+ TITLE_UPDATED = "TITLE_UPDATED"
18
+ }
19
+ type CommentLeftMetadata = {
20
+ authorId: string;
21
+ commentText: string;
22
+ };
23
+ type CommentLeftActivity = {
24
+ id: string;
25
+ type: ActivityType.COMMENT_LEFT;
26
+ projectId: string;
27
+ taskId: string;
28
+ userId: string;
29
+ occurredAt: string;
30
+ metadata: CommentLeftMetadata;
31
+ };
32
+ type DescriptionUpdatedMetadata = {
33
+ message: string;
34
+ oldDescription: string;
35
+ newDescription: string;
36
+ };
37
+ type DescriptionUpdatedActivity = {
38
+ id: string;
39
+ type: ActivityType.DESCRIPTION_UPDATED;
40
+ projectId: string;
41
+ taskId: string;
42
+ userId: string;
43
+ occurredAt: string;
44
+ metadata: DescriptionUpdatedMetadata;
45
+ };
46
+ type FinishedWorkMetadata = {
47
+ workerId: string;
48
+ message: string;
49
+ };
50
+ type FinishedWorkActivity = {
51
+ id: string;
52
+ type: ActivityType.FINISHED_WORK;
53
+ projectId: string;
54
+ taskId: string;
55
+ userId: string;
56
+ occurredAt: string;
57
+ metadata: FinishedWorkMetadata;
58
+ };
59
+ type StartedWorkMetadata = {
60
+ workerId: string;
61
+ message: string;
62
+ };
63
+ type StartedWorkActivity = {
64
+ id: string;
65
+ type: ActivityType.STARTED_WORK;
66
+ projectId: string;
67
+ taskId: string;
68
+ userId: string;
69
+ occurredAt: string;
70
+ metadata: StartedWorkMetadata;
71
+ };
72
+ type TaskCreatedMetadata = {
73
+ message: string;
74
+ title: string;
75
+ description: string;
76
+ };
77
+ type TaskCreatedActivity = {
78
+ id: string;
79
+ type: ActivityType.TASK_CREATED;
80
+ projectId: string;
81
+ taskId: string;
82
+ userId: string;
83
+ occurredAt: string;
84
+ metadata: TaskCreatedMetadata;
85
+ };
86
+ type TitleUpdatedMetadata = {
87
+ message: string;
88
+ oldTitle: string;
89
+ newTitle: string;
90
+ };
91
+ type TitleUpdatedActivity = {
92
+ id: string;
93
+ type: ActivityType.TITLE_UPDATED;
94
+ projectId: string;
95
+ taskId: string;
96
+ userId: string;
97
+ occurredAt: string;
98
+ metadata: TitleUpdatedMetadata;
99
+ };
100
+ type ActivityMetadata = CommentLeftMetadata | DescriptionUpdatedMetadata | FinishedWorkMetadata | StartedWorkMetadata | TaskCreatedMetadata | TitleUpdatedMetadata;
101
+ type Activity = CommentLeftActivity | DescriptionUpdatedActivity | FinishedWorkActivity | StartedWorkActivity | TaskCreatedActivity | TitleUpdatedActivity;
102
+ declare enum TaskStatus {
103
+ TODO = "Todo",
104
+ WORK_IN_PROGRESS = "Work in progress",
105
+ DONE = "Done"
106
+ }
107
+ type Task = {
108
+ id: string;
109
+ title: string;
110
+ description: string;
111
+ projectId: string;
112
+ created: string;
113
+ updated: string | null;
114
+ status: TaskStatus;
115
+ activities: Activity[];
116
+ };
117
+ type CreateTaskResponse = Task;
118
+ type LeaveCommentResponse = Task;
119
+
120
+ declare class SpektrumSDK {
121
+ private readonly endpoint;
122
+ private readonly apiKey;
123
+ constructor(options?: SpektrumSDKOptions);
124
+ private request;
125
+ createProject(owner: string): Promise<CreateProjectResponse>;
126
+ createTask(projectId: string, title: string, description: string): Promise<CreateTaskResponse>;
127
+ leaveComment(taskId: string, commentText: string, authorId: string): Promise<LeaveCommentResponse>;
128
+ getAppUrl(projectId: string): Promise<string>;
129
+ codeAndDeploy(task: Task): Promise<void>;
130
+ }
131
+
132
+ declare class SpektrumError extends Error {
133
+ readonly status: number;
134
+ readonly body?: unknown | undefined;
135
+ constructor(message: string, status: number, body?: unknown | undefined);
136
+ }
137
+
138
+ export { type Activity, type ActivityMetadata, ActivityType, type CommentLeftActivity, type CommentLeftMetadata, type CreateProjectResponse, type CreateTaskResponse, type DescriptionUpdatedActivity, type DescriptionUpdatedMetadata, type FinishedWorkActivity, type FinishedWorkMetadata, type LeaveCommentResponse, SpektrumError, SpektrumSDK, type SpektrumSDKOptions, type StartedWorkActivity, type StartedWorkMetadata, type Task, type TaskCreatedActivity, type TaskCreatedMetadata, TaskStatus, type TitleUpdatedActivity, type TitleUpdatedMetadata };
@@ -0,0 +1,138 @@
1
+ type SpektrumSDKOptions = {
2
+ apiKey?: string;
3
+ endpoint?: string;
4
+ };
5
+ type CreateProjectResponse = {
6
+ id: string;
7
+ owner: string;
8
+ name?: string;
9
+ description?: string;
10
+ };
11
+ declare enum ActivityType {
12
+ COMMENT_LEFT = "COMMENT_LEFT",
13
+ DESCRIPTION_UPDATED = "DESCRIPTION_UPDATED",
14
+ FINISHED_WORK = "FINISHED_WORK",
15
+ STARTED_WORK = "STARTED_WORK",
16
+ TASK_CREATED = "TASK_CREATED",
17
+ TITLE_UPDATED = "TITLE_UPDATED"
18
+ }
19
+ type CommentLeftMetadata = {
20
+ authorId: string;
21
+ commentText: string;
22
+ };
23
+ type CommentLeftActivity = {
24
+ id: string;
25
+ type: ActivityType.COMMENT_LEFT;
26
+ projectId: string;
27
+ taskId: string;
28
+ userId: string;
29
+ occurredAt: string;
30
+ metadata: CommentLeftMetadata;
31
+ };
32
+ type DescriptionUpdatedMetadata = {
33
+ message: string;
34
+ oldDescription: string;
35
+ newDescription: string;
36
+ };
37
+ type DescriptionUpdatedActivity = {
38
+ id: string;
39
+ type: ActivityType.DESCRIPTION_UPDATED;
40
+ projectId: string;
41
+ taskId: string;
42
+ userId: string;
43
+ occurredAt: string;
44
+ metadata: DescriptionUpdatedMetadata;
45
+ };
46
+ type FinishedWorkMetadata = {
47
+ workerId: string;
48
+ message: string;
49
+ };
50
+ type FinishedWorkActivity = {
51
+ id: string;
52
+ type: ActivityType.FINISHED_WORK;
53
+ projectId: string;
54
+ taskId: string;
55
+ userId: string;
56
+ occurredAt: string;
57
+ metadata: FinishedWorkMetadata;
58
+ };
59
+ type StartedWorkMetadata = {
60
+ workerId: string;
61
+ message: string;
62
+ };
63
+ type StartedWorkActivity = {
64
+ id: string;
65
+ type: ActivityType.STARTED_WORK;
66
+ projectId: string;
67
+ taskId: string;
68
+ userId: string;
69
+ occurredAt: string;
70
+ metadata: StartedWorkMetadata;
71
+ };
72
+ type TaskCreatedMetadata = {
73
+ message: string;
74
+ title: string;
75
+ description: string;
76
+ };
77
+ type TaskCreatedActivity = {
78
+ id: string;
79
+ type: ActivityType.TASK_CREATED;
80
+ projectId: string;
81
+ taskId: string;
82
+ userId: string;
83
+ occurredAt: string;
84
+ metadata: TaskCreatedMetadata;
85
+ };
86
+ type TitleUpdatedMetadata = {
87
+ message: string;
88
+ oldTitle: string;
89
+ newTitle: string;
90
+ };
91
+ type TitleUpdatedActivity = {
92
+ id: string;
93
+ type: ActivityType.TITLE_UPDATED;
94
+ projectId: string;
95
+ taskId: string;
96
+ userId: string;
97
+ occurredAt: string;
98
+ metadata: TitleUpdatedMetadata;
99
+ };
100
+ type ActivityMetadata = CommentLeftMetadata | DescriptionUpdatedMetadata | FinishedWorkMetadata | StartedWorkMetadata | TaskCreatedMetadata | TitleUpdatedMetadata;
101
+ type Activity = CommentLeftActivity | DescriptionUpdatedActivity | FinishedWorkActivity | StartedWorkActivity | TaskCreatedActivity | TitleUpdatedActivity;
102
+ declare enum TaskStatus {
103
+ TODO = "Todo",
104
+ WORK_IN_PROGRESS = "Work in progress",
105
+ DONE = "Done"
106
+ }
107
+ type Task = {
108
+ id: string;
109
+ title: string;
110
+ description: string;
111
+ projectId: string;
112
+ created: string;
113
+ updated: string | null;
114
+ status: TaskStatus;
115
+ activities: Activity[];
116
+ };
117
+ type CreateTaskResponse = Task;
118
+ type LeaveCommentResponse = Task;
119
+
120
+ declare class SpektrumSDK {
121
+ private readonly endpoint;
122
+ private readonly apiKey;
123
+ constructor(options?: SpektrumSDKOptions);
124
+ private request;
125
+ createProject(owner: string): Promise<CreateProjectResponse>;
126
+ createTask(projectId: string, title: string, description: string): Promise<CreateTaskResponse>;
127
+ leaveComment(taskId: string, commentText: string, authorId: string): Promise<LeaveCommentResponse>;
128
+ getAppUrl(projectId: string): Promise<string>;
129
+ codeAndDeploy(task: Task): Promise<void>;
130
+ }
131
+
132
+ declare class SpektrumError extends Error {
133
+ readonly status: number;
134
+ readonly body?: unknown | undefined;
135
+ constructor(message: string, status: number, body?: unknown | undefined);
136
+ }
137
+
138
+ export { type Activity, type ActivityMetadata, ActivityType, type CommentLeftActivity, type CommentLeftMetadata, type CreateProjectResponse, type CreateTaskResponse, type DescriptionUpdatedActivity, type DescriptionUpdatedMetadata, type FinishedWorkActivity, type FinishedWorkMetadata, type LeaveCommentResponse, SpektrumError, SpektrumSDK, type SpektrumSDKOptions, type StartedWorkActivity, type StartedWorkMetadata, type Task, type TaskCreatedActivity, type TaskCreatedMetadata, TaskStatus, type TitleUpdatedActivity, type TitleUpdatedMetadata };
package/dist/index.js ADDED
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ActivityType: () => ActivityType,
24
+ SpektrumError: () => SpektrumError,
25
+ SpektrumSDK: () => SpektrumSDK,
26
+ TaskStatus: () => TaskStatus
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/errors.ts
31
+ var SpektrumError = class extends Error {
32
+ constructor(message, status, body) {
33
+ super(message);
34
+ this.status = status;
35
+ this.body = body;
36
+ this.name = "SpektrumError";
37
+ }
38
+ };
39
+
40
+ // src/spektrum-sdk.ts
41
+ var DEFAULT_ENDPOINT = "https://platform.jigjoy.ai";
42
+ function readEnv(name) {
43
+ var _a, _b;
44
+ return (_b = (_a = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : _a.env) == null ? void 0 : _b[name];
45
+ }
46
+ var SpektrumSDK = class {
47
+ constructor(options = {}) {
48
+ var _a, _b, _c;
49
+ const endpoint = (_b = (_a = options.endpoint) != null ? _a : readEnv("SPEKTRUM_ENDPOINT")) != null ? _b : DEFAULT_ENDPOINT;
50
+ const apiKey = (_c = options.apiKey) != null ? _c : readEnv("SPEKTRUM_API_KEY");
51
+ if (!apiKey) {
52
+ throw new Error(
53
+ "Missing SPEKTRUM_API_KEY. Set it in your environment or pass { apiKey } to the constructor."
54
+ );
55
+ }
56
+ this.endpoint = endpoint.replace(/\/+$/, "");
57
+ this.apiKey = apiKey;
58
+ }
59
+ async request(path, init) {
60
+ var _a;
61
+ const res = await fetch(`${this.endpoint}${path}`, {
62
+ ...init,
63
+ headers: {
64
+ "content-type": "application/json",
65
+ "x-api-key": this.apiKey,
66
+ ...(_a = init.headers) != null ? _a : {}
67
+ }
68
+ });
69
+ const text = await res.text();
70
+ const body = text ? safeJson(text) : void 0;
71
+ if (!res.ok) {
72
+ throw new SpektrumError(`Request failed: ${res.status}`, res.status, body);
73
+ }
74
+ return body;
75
+ }
76
+ async createProject(owner) {
77
+ return this.request(`/planning/project`, {
78
+ method: "POST",
79
+ body: JSON.stringify({ owner })
80
+ });
81
+ }
82
+ async createTask(projectId, title, description) {
83
+ return this.request(`/planning/task`, {
84
+ method: "POST",
85
+ body: JSON.stringify({ projectId, title, description })
86
+ });
87
+ }
88
+ async leaveComment(taskId, commentText, authorId) {
89
+ return this.request(`/planning/task/leave-comment`, {
90
+ method: "POST",
91
+ body: JSON.stringify({ taskId, commentText, authorId })
92
+ });
93
+ }
94
+ async getAppUrl(projectId) {
95
+ const response = await this.request(
96
+ `/deployment/projects/${projectId}/environments/DEV/entry-point`,
97
+ { method: "GET" }
98
+ );
99
+ return response.publicAppUrl;
100
+ }
101
+ async codeAndDeploy(task) {
102
+ await this.request(`/ai/module/development`, {
103
+ method: "POST",
104
+ body: JSON.stringify({ task })
105
+ });
106
+ }
107
+ };
108
+ function safeJson(text) {
109
+ try {
110
+ return JSON.parse(text);
111
+ } catch (e) {
112
+ return text;
113
+ }
114
+ }
115
+
116
+ // src/types.ts
117
+ var ActivityType = /* @__PURE__ */ ((ActivityType2) => {
118
+ ActivityType2["COMMENT_LEFT"] = "COMMENT_LEFT";
119
+ ActivityType2["DESCRIPTION_UPDATED"] = "DESCRIPTION_UPDATED";
120
+ ActivityType2["FINISHED_WORK"] = "FINISHED_WORK";
121
+ ActivityType2["STARTED_WORK"] = "STARTED_WORK";
122
+ ActivityType2["TASK_CREATED"] = "TASK_CREATED";
123
+ ActivityType2["TITLE_UPDATED"] = "TITLE_UPDATED";
124
+ return ActivityType2;
125
+ })(ActivityType || {});
126
+ var TaskStatus = /* @__PURE__ */ ((TaskStatus2) => {
127
+ TaskStatus2["TODO"] = "Todo";
128
+ TaskStatus2["WORK_IN_PROGRESS"] = "Work in progress";
129
+ TaskStatus2["DONE"] = "Done";
130
+ return TaskStatus2;
131
+ })(TaskStatus || {});
132
+ // Annotate the CommonJS export names for ESM import in node:
133
+ 0 && (module.exports = {
134
+ ActivityType,
135
+ SpektrumError,
136
+ SpektrumSDK,
137
+ TaskStatus
138
+ });
139
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/spektrum-sdk.ts","../src/types.ts"],"sourcesContent":["export * from \"./spektrum-sdk\"\nexport * from \"./errors\"\nexport * from \"./types\"\n","export class SpektrumError extends Error {\n constructor(\n message: string,\n public readonly status: number,\n public readonly body?: unknown\n ) {\n super(message)\n this.name = \"SpektrumError\"\n }\n }\n ","import { SpektrumError } from \"./errors\"\nimport type {\n SpektrumSDKOptions,\n CreateProjectResponse,\n CreateTaskResponse,\n LeaveCommentResponse,\n Task,\n} from \"./types\"\n\nconst DEFAULT_ENDPOINT = \"https://platform.jigjoy.ai\"\n\nfunction readEnv(name: string): string | undefined {\n // Works in Node. In browsers this is usually undefined (unless bundled/injected).\n return (globalThis as any)?.process?.env?.[name]\n}\n\nexport class SpektrumSDK {\n private readonly endpoint: string\n private readonly apiKey: string\n\n constructor(options: SpektrumSDKOptions = {}) {\n const endpoint = options.endpoint ?? readEnv(\"SPEKTRUM_ENDPOINT\") ?? DEFAULT_ENDPOINT\n const apiKey = options.apiKey ?? readEnv(\"SPEKTRUM_API_KEY\")\n\n if (!apiKey) {\n throw new Error(\n \"Missing SPEKTRUM_API_KEY. Set it in your environment or pass { apiKey } to the constructor.\"\n )\n }\n\n this.endpoint = endpoint.replace(/\\/+$/, \"\")\n this.apiKey = apiKey\n }\n\n private async request<T>(path: string, init: RequestInit): Promise<T> {\n const res = await fetch(`${this.endpoint}${path}`, {\n ...init,\n headers: {\n \"content-type\": \"application/json\",\n \"x-api-key\": this.apiKey,\n ...(init.headers ?? {}),\n },\n })\n\n const text = await res.text()\n const body = text ? safeJson(text) : undefined\n\n if (!res.ok) {\n throw new SpektrumError(`Request failed: ${res.status}`, res.status, body)\n }\n\n return body as T\n }\n\n async createProject(owner: string): Promise<CreateProjectResponse> {\n return this.request(`/planning/project`, {\n method: \"POST\",\n body: JSON.stringify({ owner }),\n })\n }\n\n async createTask(projectId: string, title: string, description: string): Promise<CreateTaskResponse> {\n return this.request(`/planning/task`, {\n method: \"POST\",\n body: JSON.stringify({ projectId, title, description }),\n })\n }\n\n async leaveComment(taskId: string, commentText: string, authorId: string): Promise<LeaveCommentResponse> {\n return this.request(`/planning/task/leave-comment`, {\n method: \"POST\",\n body: JSON.stringify({ taskId, commentText, authorId }),\n })\n }\n\n async getAppUrl(projectId: string): Promise<string> {\n const response = await this.request<{\n moduleId: string\n assetBaseUrl: string\n publicAppUrl: string\n }>(\n `/deployment/projects/${projectId}/environments/DEV/entry-point`,\n { method: \"GET\" }\n )\n \n return response.publicAppUrl\n }\n \n\n async codeAndDeploy(task: Task): Promise<void> {\n await this.request(`/ai/module/development`, {\n method: \"POST\",\n body: JSON.stringify({ task }),\n })\n }\n \n}\n\nfunction safeJson(text: string) {\n try {\n return JSON.parse(text)\n } catch {\n return text\n }\n}\n","export type SpektrumSDKOptions = {\n\tapiKey?: string\n\tendpoint?: string\n}\n\nexport type CreateProjectResponse = {\n\tid: string\n\towner: string\n\tname?: string\n\tdescription?: string\n}\n\nexport enum ActivityType {\n\tCOMMENT_LEFT = \"COMMENT_LEFT\",\n\tDESCRIPTION_UPDATED = \"DESCRIPTION_UPDATED\",\n\tFINISHED_WORK = \"FINISHED_WORK\",\n\tSTARTED_WORK = \"STARTED_WORK\",\n\tTASK_CREATED = \"TASK_CREATED\",\n\tTITLE_UPDATED = \"TITLE_UPDATED\",\n}\n\nexport type CommentLeftMetadata = {\n\tauthorId: string\n\tcommentText: string\n}\n\nexport type CommentLeftActivity = {\n\tid: string\n\ttype: ActivityType.COMMENT_LEFT\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: CommentLeftMetadata\n}\n\nexport type DescriptionUpdatedMetadata = {\n\tmessage: string\n\toldDescription: string\n\tnewDescription: string\n}\n\nexport type DescriptionUpdatedActivity = {\n\tid: string\n\ttype: ActivityType.DESCRIPTION_UPDATED\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: DescriptionUpdatedMetadata\n}\n\nexport type FinishedWorkMetadata = {\n\tworkerId: string\n\tmessage: string\n}\n\nexport type FinishedWorkActivity = {\n\tid: string\n\ttype: ActivityType.FINISHED_WORK\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: FinishedWorkMetadata\n}\n\nexport type StartedWorkMetadata = {\n\tworkerId: string\n\tmessage: string\n}\n\nexport type StartedWorkActivity = {\n\tid: string\n\ttype: ActivityType.STARTED_WORK\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: StartedWorkMetadata\n}\n\nexport type TaskCreatedMetadata = {\n\tmessage: string\n\ttitle: string\n\tdescription: string\n}\n\nexport type TaskCreatedActivity = {\n\tid: string\n\ttype: ActivityType.TASK_CREATED\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: TaskCreatedMetadata\n}\n\nexport type TitleUpdatedMetadata = {\n\tmessage: string\n\toldTitle: string\n\tnewTitle: string\n}\n\nexport type TitleUpdatedActivity = {\n\tid: string\n\ttype: ActivityType.TITLE_UPDATED\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: TitleUpdatedMetadata\n}\n\nexport type ActivityMetadata =\n\t| CommentLeftMetadata\n\t| DescriptionUpdatedMetadata\n\t| FinishedWorkMetadata\n\t| StartedWorkMetadata\n\t| TaskCreatedMetadata\n\t| TitleUpdatedMetadata\n\nexport type Activity =\n\t| CommentLeftActivity\n\t| DescriptionUpdatedActivity\n\t| FinishedWorkActivity\n\t| StartedWorkActivity\n\t| TaskCreatedActivity\n\t| TitleUpdatedActivity\n\nexport enum TaskStatus {\n\tTODO = \"Todo\",\n\tWORK_IN_PROGRESS = \"Work in progress\",\n\tDONE = \"Done\",\n}\n\nexport type Task = {\n\tid: string\n\ttitle: string\n\tdescription: string\n\tprojectId: string\n\tcreated: string\n\tupdated: string | null\n\tstatus: TaskStatus\n\tactivities: Activity[]\n}\n\nexport type CreateTaskResponse = Task\nexport type LeaveCommentResponse = Task\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACrC,YACE,SACgB,QACA,MAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACAF,IAAM,mBAAmB;AAEzB,SAAS,QAAQ,MAAkC;AAXnD;AAaE,UAAQ,oDAAoB,YAApB,mBAA6B,QAA7B,mBAAmC;AAC7C;AAEO,IAAM,cAAN,MAAkB;AAAA,EAIvB,YAAY,UAA8B,CAAC,GAAG;AApBhD;AAqBI,UAAM,YAAW,mBAAQ,aAAR,YAAoB,QAAQ,mBAAmB,MAA/C,YAAoD;AACrE,UAAM,UAAS,aAAQ,WAAR,YAAkB,QAAQ,kBAAkB;AAE3D,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,SAAK,WAAW,SAAS,QAAQ,QAAQ,EAAE;AAC3C,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAc,QAAW,MAAc,MAA+B;AAlCxE;AAmCI,UAAM,MAAM,MAAM,MAAM,GAAG,KAAK,QAAQ,GAAG,IAAI,IAAI;AAAA,MACjD,GAAG;AAAA,MACH,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,aAAa,KAAK;AAAA,QAClB,IAAI,UAAK,YAAL,YAAgB,CAAC;AAAA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AL,kBAAKA,kBAAL;AACN,EAAAA,cAAA,kBAAe;AACf,EAAAA,cAAA,yBAAsB;AACtB,EAAAA,cAAA,mBAAgB;AAChB,EAAAA,cAAA,kBAAe;AACf,EAAAA,cAAA,kBAAe;AACf,EAAAA,cAAA,mBAAgB;AANL,SAAAA;AAAA,GAAA;AAsHL,IAAK,aAAL,kBAAKC,gBAAL;AACN,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,sBAAmB;AACnB,EAAAA,YAAA,UAAO;AAHI,SAAAA;AAAA,GAAA;","names":["ActivityType","TaskStatus"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,109 @@
1
+ // src/errors.ts
2
+ var SpektrumError = class extends Error {
3
+ constructor(message, status, body) {
4
+ super(message);
5
+ this.status = status;
6
+ this.body = body;
7
+ this.name = "SpektrumError";
8
+ }
9
+ };
10
+
11
+ // src/spektrum-sdk.ts
12
+ var DEFAULT_ENDPOINT = "https://platform.jigjoy.ai";
13
+ function readEnv(name) {
14
+ var _a, _b;
15
+ return (_b = (_a = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : _a.env) == null ? void 0 : _b[name];
16
+ }
17
+ var SpektrumSDK = class {
18
+ constructor(options = {}) {
19
+ var _a, _b, _c;
20
+ const endpoint = (_b = (_a = options.endpoint) != null ? _a : readEnv("SPEKTRUM_ENDPOINT")) != null ? _b : DEFAULT_ENDPOINT;
21
+ const apiKey = (_c = options.apiKey) != null ? _c : readEnv("SPEKTRUM_API_KEY");
22
+ if (!apiKey) {
23
+ throw new Error(
24
+ "Missing SPEKTRUM_API_KEY. Set it in your environment or pass { apiKey } to the constructor."
25
+ );
26
+ }
27
+ this.endpoint = endpoint.replace(/\/+$/, "");
28
+ this.apiKey = apiKey;
29
+ }
30
+ async request(path, init) {
31
+ var _a;
32
+ const res = await fetch(`${this.endpoint}${path}`, {
33
+ ...init,
34
+ headers: {
35
+ "content-type": "application/json",
36
+ "x-api-key": this.apiKey,
37
+ ...(_a = init.headers) != null ? _a : {}
38
+ }
39
+ });
40
+ const text = await res.text();
41
+ const body = text ? safeJson(text) : void 0;
42
+ if (!res.ok) {
43
+ throw new SpektrumError(`Request failed: ${res.status}`, res.status, body);
44
+ }
45
+ return body;
46
+ }
47
+ async createProject(owner) {
48
+ return this.request(`/planning/project`, {
49
+ method: "POST",
50
+ body: JSON.stringify({ owner })
51
+ });
52
+ }
53
+ async createTask(projectId, title, description) {
54
+ return this.request(`/planning/task`, {
55
+ method: "POST",
56
+ body: JSON.stringify({ projectId, title, description })
57
+ });
58
+ }
59
+ async leaveComment(taskId, commentText, authorId) {
60
+ return this.request(`/planning/task/leave-comment`, {
61
+ method: "POST",
62
+ body: JSON.stringify({ taskId, commentText, authorId })
63
+ });
64
+ }
65
+ async getAppUrl(projectId) {
66
+ const response = await this.request(
67
+ `/deployment/projects/${projectId}/environments/DEV/entry-point`,
68
+ { method: "GET" }
69
+ );
70
+ return response.publicAppUrl;
71
+ }
72
+ async codeAndDeploy(task) {
73
+ await this.request(`/ai/module/development`, {
74
+ method: "POST",
75
+ body: JSON.stringify({ task })
76
+ });
77
+ }
78
+ };
79
+ function safeJson(text) {
80
+ try {
81
+ return JSON.parse(text);
82
+ } catch (e) {
83
+ return text;
84
+ }
85
+ }
86
+
87
+ // src/types.ts
88
+ var ActivityType = /* @__PURE__ */ ((ActivityType2) => {
89
+ ActivityType2["COMMENT_LEFT"] = "COMMENT_LEFT";
90
+ ActivityType2["DESCRIPTION_UPDATED"] = "DESCRIPTION_UPDATED";
91
+ ActivityType2["FINISHED_WORK"] = "FINISHED_WORK";
92
+ ActivityType2["STARTED_WORK"] = "STARTED_WORK";
93
+ ActivityType2["TASK_CREATED"] = "TASK_CREATED";
94
+ ActivityType2["TITLE_UPDATED"] = "TITLE_UPDATED";
95
+ return ActivityType2;
96
+ })(ActivityType || {});
97
+ var TaskStatus = /* @__PURE__ */ ((TaskStatus2) => {
98
+ TaskStatus2["TODO"] = "Todo";
99
+ TaskStatus2["WORK_IN_PROGRESS"] = "Work in progress";
100
+ TaskStatus2["DONE"] = "Done";
101
+ return TaskStatus2;
102
+ })(TaskStatus || {});
103
+ export {
104
+ ActivityType,
105
+ SpektrumError,
106
+ SpektrumSDK,
107
+ TaskStatus
108
+ };
109
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/spektrum-sdk.ts","../src/types.ts"],"sourcesContent":["export class SpektrumError extends Error {\n constructor(\n message: string,\n public readonly status: number,\n public readonly body?: unknown\n ) {\n super(message)\n this.name = \"SpektrumError\"\n }\n }\n ","import { SpektrumError } from \"./errors\"\nimport type {\n SpektrumSDKOptions,\n CreateProjectResponse,\n CreateTaskResponse,\n LeaveCommentResponse,\n Task,\n} from \"./types\"\n\nconst DEFAULT_ENDPOINT = \"https://platform.jigjoy.ai\"\n\nfunction readEnv(name: string): string | undefined {\n // Works in Node. In browsers this is usually undefined (unless bundled/injected).\n return (globalThis as any)?.process?.env?.[name]\n}\n\nexport class SpektrumSDK {\n private readonly endpoint: string\n private readonly apiKey: string\n\n constructor(options: SpektrumSDKOptions = {}) {\n const endpoint = options.endpoint ?? readEnv(\"SPEKTRUM_ENDPOINT\") ?? DEFAULT_ENDPOINT\n const apiKey = options.apiKey ?? readEnv(\"SPEKTRUM_API_KEY\")\n\n if (!apiKey) {\n throw new Error(\n \"Missing SPEKTRUM_API_KEY. Set it in your environment or pass { apiKey } to the constructor.\"\n )\n }\n\n this.endpoint = endpoint.replace(/\\/+$/, \"\")\n this.apiKey = apiKey\n }\n\n private async request<T>(path: string, init: RequestInit): Promise<T> {\n const res = await fetch(`${this.endpoint}${path}`, {\n ...init,\n headers: {\n \"content-type\": \"application/json\",\n \"x-api-key\": this.apiKey,\n ...(init.headers ?? {}),\n },\n })\n\n const text = await res.text()\n const body = text ? safeJson(text) : undefined\n\n if (!res.ok) {\n throw new SpektrumError(`Request failed: ${res.status}`, res.status, body)\n }\n\n return body as T\n }\n\n async createProject(owner: string): Promise<CreateProjectResponse> {\n return this.request(`/planning/project`, {\n method: \"POST\",\n body: JSON.stringify({ owner }),\n })\n }\n\n async createTask(projectId: string, title: string, description: string): Promise<CreateTaskResponse> {\n return this.request(`/planning/task`, {\n method: \"POST\",\n body: JSON.stringify({ projectId, title, description }),\n })\n }\n\n async leaveComment(taskId: string, commentText: string, authorId: string): Promise<LeaveCommentResponse> {\n return this.request(`/planning/task/leave-comment`, {\n method: \"POST\",\n body: JSON.stringify({ taskId, commentText, authorId }),\n })\n }\n\n async getAppUrl(projectId: string): Promise<string> {\n const response = await this.request<{\n moduleId: string\n assetBaseUrl: string\n publicAppUrl: string\n }>(\n `/deployment/projects/${projectId}/environments/DEV/entry-point`,\n { method: \"GET\" }\n )\n \n return response.publicAppUrl\n }\n \n\n async codeAndDeploy(task: Task): Promise<void> {\n await this.request(`/ai/module/development`, {\n method: \"POST\",\n body: JSON.stringify({ task }),\n })\n }\n \n}\n\nfunction safeJson(text: string) {\n try {\n return JSON.parse(text)\n } catch {\n return text\n }\n}\n","export type SpektrumSDKOptions = {\n\tapiKey?: string\n\tendpoint?: string\n}\n\nexport type CreateProjectResponse = {\n\tid: string\n\towner: string\n\tname?: string\n\tdescription?: string\n}\n\nexport enum ActivityType {\n\tCOMMENT_LEFT = \"COMMENT_LEFT\",\n\tDESCRIPTION_UPDATED = \"DESCRIPTION_UPDATED\",\n\tFINISHED_WORK = \"FINISHED_WORK\",\n\tSTARTED_WORK = \"STARTED_WORK\",\n\tTASK_CREATED = \"TASK_CREATED\",\n\tTITLE_UPDATED = \"TITLE_UPDATED\",\n}\n\nexport type CommentLeftMetadata = {\n\tauthorId: string\n\tcommentText: string\n}\n\nexport type CommentLeftActivity = {\n\tid: string\n\ttype: ActivityType.COMMENT_LEFT\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: CommentLeftMetadata\n}\n\nexport type DescriptionUpdatedMetadata = {\n\tmessage: string\n\toldDescription: string\n\tnewDescription: string\n}\n\nexport type DescriptionUpdatedActivity = {\n\tid: string\n\ttype: ActivityType.DESCRIPTION_UPDATED\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: DescriptionUpdatedMetadata\n}\n\nexport type FinishedWorkMetadata = {\n\tworkerId: string\n\tmessage: string\n}\n\nexport type FinishedWorkActivity = {\n\tid: string\n\ttype: ActivityType.FINISHED_WORK\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: FinishedWorkMetadata\n}\n\nexport type StartedWorkMetadata = {\n\tworkerId: string\n\tmessage: string\n}\n\nexport type StartedWorkActivity = {\n\tid: string\n\ttype: ActivityType.STARTED_WORK\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: StartedWorkMetadata\n}\n\nexport type TaskCreatedMetadata = {\n\tmessage: string\n\ttitle: string\n\tdescription: string\n}\n\nexport type TaskCreatedActivity = {\n\tid: string\n\ttype: ActivityType.TASK_CREATED\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: TaskCreatedMetadata\n}\n\nexport type TitleUpdatedMetadata = {\n\tmessage: string\n\toldTitle: string\n\tnewTitle: string\n}\n\nexport type TitleUpdatedActivity = {\n\tid: string\n\ttype: ActivityType.TITLE_UPDATED\n\tprojectId: string\n\ttaskId: string\n\tuserId: string\n\toccurredAt: string\n\tmetadata: TitleUpdatedMetadata\n}\n\nexport type ActivityMetadata =\n\t| CommentLeftMetadata\n\t| DescriptionUpdatedMetadata\n\t| FinishedWorkMetadata\n\t| StartedWorkMetadata\n\t| TaskCreatedMetadata\n\t| TitleUpdatedMetadata\n\nexport type Activity =\n\t| CommentLeftActivity\n\t| DescriptionUpdatedActivity\n\t| FinishedWorkActivity\n\t| StartedWorkActivity\n\t| TaskCreatedActivity\n\t| TitleUpdatedActivity\n\nexport enum TaskStatus {\n\tTODO = \"Todo\",\n\tWORK_IN_PROGRESS = \"Work in progress\",\n\tDONE = \"Done\",\n}\n\nexport type Task = {\n\tid: string\n\ttitle: string\n\tdescription: string\n\tprojectId: string\n\tcreated: string\n\tupdated: string | null\n\tstatus: TaskStatus\n\tactivities: Activity[]\n}\n\nexport type CreateTaskResponse = Task\nexport type LeaveCommentResponse = Task\n"],"mappings":";AAAO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACrC,YACE,SACgB,QACA,MAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACAF,IAAM,mBAAmB;AAEzB,SAAS,QAAQ,MAAkC;AAXnD;AAaE,UAAQ,oDAAoB,YAApB,mBAA6B,QAA7B,mBAAmC;AAC7C;AAEO,IAAM,cAAN,MAAkB;AAAA,EAIvB,YAAY,UAA8B,CAAC,GAAG;AApBhD;AAqBI,UAAM,YAAW,mBAAQ,aAAR,YAAoB,QAAQ,mBAAmB,MAA/C,YAAoD;AACrE,UAAM,UAAS,aAAQ,WAAR,YAAkB,QAAQ,kBAAkB;AAE3D,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,SAAK,WAAW,SAAS,QAAQ,QAAQ,EAAE;AAC3C,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAc,QAAW,MAAc,MAA+B;AAlCxE;AAmCI,UAAM,MAAM,MAAM,MAAM,GAAG,KAAK,QAAQ,GAAG,IAAI,IAAI;AAAA,MACjD,GAAG;AAAA,MACH,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,aAAa,KAAK;AAAA,QAClB,IAAI,UAAK,YAAL,YAAgB,CAAC;AAAA,MACvB;AAAA,IACF,CAAC;AAED,UAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAM,OAAO,OAAO,SAAS,IAAI,IAAI;AAErC,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,IAAI,cAAc,mBAAmB,IAAI,MAAM,IAAI,IAAI,QAAQ,IAAI;AAAA,I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IAAK,aAAL,kBAAKC,gBAAL;AACN,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,sBAAmB;AACnB,EAAAA,YAAA,UAAO;AAHI,SAAAA;AAAA,GAAA;","names":["ActivityType","TaskStatus"]}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@spektrum-ai/sdk",
3
+ "version": "0.0.1",
4
+ "description": "The SDK for ai coding",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/jigjoy-ai/spektrum-sdk.git"
17
+ },
18
+ "author": "Miodrag Vilotijević",
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "dev": "tsup --watch",
22
+ "prepublishOnly": "npm run build",
23
+ "format": "prettier --write \"src/**/*.{ts,tsx}\""
24
+ },
25
+ "keywords": [],
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "@types/node": "^24.3.0",
29
+ "prettier": "^3.7.4",
30
+ "tsup": "^8.0.2",
31
+ "typescript": "^5.3.3"
32
+ }
33
+ }