@clue-ai/cli 0.0.8 → 0.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clue-ai/cli",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "clue-ai": "bin/clue-cli.mjs"
package/src/contracts.mjs CHANGED
@@ -2,163 +2,168 @@ import { createRequire } from "node:module";
2
2
 
3
3
  const require = createRequire(import.meta.url);
4
4
  const schemaPackage = require("./public-schema.cjs");
5
+
5
6
  const {
6
- clueInitToolRequestSchema,
7
- clueInitToolReportSchema,
8
- semanticSnapshotRequestSchema,
9
- semanticSnapshotResponseSchema,
7
+ clueInitToolRequestSchema,
8
+ clueInitToolReportSchema,
9
+ semanticSnapshotRequestSchema,
10
+ semanticSnapshotResponseSchema,
10
11
  } = schemaPackage;
11
12
 
12
13
  const formatSchemaError = (result, field) => {
13
- const issues = result.error.issues.map((issue) => {
14
- const path = issue.path.length ? issue.path.join(".") : field;
15
- return `${path}: ${issue.message}`;
16
- });
17
- return `${field} is invalid: ${issues.join("; ")}`;
14
+ const issues = result.error.issues.map((issue) => {
15
+ const path = issue.path.length ? issue.path.join(".") : field;
16
+ return `${path}: ${issue.message}`;
17
+ });
18
+ return `${field} is invalid: ${issues.join("; ")}`;
18
19
  };
19
20
 
20
21
  const parseWithSchema = (schema, input, field) => {
21
- const result = schema.safeParse(input);
22
- if (!result.success) {
23
- throw new Error(formatSchemaError(result, field));
24
- }
25
- return result.data;
22
+ const result = schema.safeParse(input);
23
+ if (!result.success) {
24
+ throw new Error(formatSchemaError(result, field));
25
+ }
26
+ return result.data;
26
27
  };
27
28
 
28
29
  const nonEmpty = (value, field) => {
29
- if (typeof value !== "string" || value.trim() === "") {
30
- throw new Error(`${field} is required`);
31
- }
32
- return value.trim();
30
+ if (typeof value !== "string" || value.trim() === "") {
31
+ throw new Error(`${field} is required`);
32
+ }
33
+ return value.trim();
33
34
  };
34
35
 
35
36
  const optionalNonEmpty = (value) =>
36
- typeof value === "string" && value.trim() ? value.trim() : null;
37
+ typeof value === "string" && value.trim() ? value.trim() : null;
37
38
 
38
39
  const stringArray = (value, field, { min = 0 } = {}) => {
39
- if (!Array.isArray(value)) {
40
- throw new Error(`${field} must be an array`);
41
- }
42
- const result = value.map((entry) => nonEmpty(entry, field));
43
- if (result.length < min) {
44
- throw new Error(`${field} must include at least ${min} item(s)`);
45
- }
46
- return [...new Set(result)];
40
+ if (!Array.isArray(value)) {
41
+ throw new Error(`${field} must be an array`);
42
+ }
43
+ const result = value.map((entry) => nonEmpty(entry, field));
44
+ if (result.length < min) {
45
+ throw new Error(`${field} must include at least ${min} item(s)`);
46
+ }
47
+ return [...new Set(result)];
47
48
  };
48
49
 
49
50
  export const validateInitRequest = (input) => {
50
- const parsed = parseWithSchema(
51
- clueInitToolRequestSchema,
52
- input,
53
- "init request",
54
- );
55
- return {
56
- ...parsed,
57
- allowed_source_paths: [...new Set(parsed.allowed_source_paths)],
58
- excluded_source_paths: [...new Set(parsed.excluded_source_paths ?? [])],
59
- };
51
+ const parsed = parseWithSchema(
52
+ clueInitToolRequestSchema,
53
+ input,
54
+ "init request",
55
+ );
56
+ return {
57
+ ...parsed,
58
+ allowed_source_paths: [...new Set(parsed.allowed_source_paths)],
59
+ excluded_source_paths: [...new Set(parsed.excluded_source_paths ?? [])],
60
+ };
60
61
  };
61
62
 
62
63
  export const buildInitReport = ({
63
- request,
64
- lifecycleInsertions,
65
- requiredVariables = [],
66
- warnings = [],
64
+ request,
65
+ lifecycleInsertions,
66
+ requiredVariables = [],
67
+ warnings = [],
67
68
  }) =>
68
- parseWithSchema(
69
- clueInitToolReportSchema,
70
- {
71
- target_tool: request.target_tool,
72
- ci_workflow_path: request.ci_workflow_path,
73
- ci_workflow_added: true,
74
- required_secrets: ["CLUE_API_KEY", "CLUE_AI_PROVIDER_API_KEY"],
75
- required_variables: requiredVariables,
76
- lifecycle_insertions: lifecycleInsertions,
77
- semantic_generation_timing: "after_merge_ci",
78
- semantic_preview_generated: false,
79
- client_repo_generated_files_committed: false,
80
- clue_track_inserted: false,
81
- clue_dom_tag_inserted: false,
82
- allowed_source_paths: request.allowed_source_paths,
83
- excluded_source_paths: request.excluded_source_paths,
84
- warnings,
85
- },
86
- "init report",
87
- );
69
+ parseWithSchema(
70
+ clueInitToolReportSchema,
71
+ {
72
+ target_tool: request.target_tool,
73
+ ci_workflow_path: request.ci_workflow_path,
74
+ ci_workflow_added: true,
75
+ required_secrets: ["CLUE_API_KEY", "CLUE_AI_PROVIDER_API_KEY"],
76
+ required_variables: requiredVariables,
77
+ lifecycle_insertions: lifecycleInsertions,
78
+ semantic_generation_timing: "after_merge_ci",
79
+ semantic_preview_generated: false,
80
+ client_repo_generated_files_committed: false,
81
+ frontend_api_key_exposed: false,
82
+ browser_token_endpoint_required: true,
83
+ browser_token_provider_required: true,
84
+ browser_token_endpoint_path: "/api/v1/ingest/browser-tokens",
85
+ clue_track_inserted: false,
86
+ clue_dom_tag_inserted: false,
87
+ allowed_source_paths: request.allowed_source_paths,
88
+ excluded_source_paths: request.excluded_source_paths,
89
+ warnings,
90
+ },
91
+ "init report",
92
+ );
88
93
 
89
94
  export const validateSemanticCiRequest = (input) => ({
90
- project_key: nonEmpty(input.project_key, "project_key"),
91
- environment: nonEmpty(input.environment, "environment"),
92
- service_key: nonEmpty(input.service_key, "service_key"),
93
- repository: {
94
- provider: nonEmpty(input.repository?.provider, "repository.provider"),
95
- repository_id: nonEmpty(
96
- input.repository?.repository_id,
97
- "repository.repository_id",
98
- ),
99
- ...(optionalNonEmpty(input.repository?.owner)
100
- ? { owner: optionalNonEmpty(input.repository.owner) }
101
- : {}),
102
- ...(optionalNonEmpty(input.repository?.name)
103
- ? { name: optionalNonEmpty(input.repository.name) }
104
- : {}),
105
- ...(optionalNonEmpty(input.repository?.default_branch)
106
- ? { default_branch: optionalNonEmpty(input.repository.default_branch) }
107
- : {}),
108
- merge_commit: nonEmpty(
109
- input.repository?.merge_commit,
110
- "repository.merge_commit",
111
- ),
112
- ...(optionalNonEmpty(input.repository?.merged_at)
113
- ? { merged_at: optionalNonEmpty(input.repository.merged_at) }
114
- : {}),
115
- ...(input.repository?.pull_request_number === undefined ||
116
- input.repository?.pull_request_number === null
117
- ? {}
118
- : { pull_request_number: input.repository.pull_request_number }),
119
- ...(optionalNonEmpty(input.repository?.workflow_run_id)
120
- ? { workflow_run_id: optionalNonEmpty(input.repository.workflow_run_id) }
121
- : {}),
122
- },
123
- service: {
124
- service_key: nonEmpty(
125
- input.service?.service_key ?? input.service_key,
126
- "service.service_key",
127
- ),
128
- root_path: input.service?.root_path ?? null,
129
- framework: input.service?.framework ?? "fastapi",
130
- language: input.service?.language ?? "python",
131
- },
132
- allowed_source_paths: stringArray(
133
- input.allowed_source_paths,
134
- "allowed_source_paths",
135
- { min: 1 },
136
- ),
137
- excluded_source_paths: stringArray(
138
- input.excluded_source_paths ?? [],
139
- "excluded_source_paths",
140
- ),
141
- clue_api_base_url: nonEmpty(input.clue_api_base_url, "clue_api_base_url"),
142
- ai_provider_base_url: null,
143
- ai_provider: optionalNonEmpty(input.ai_provider),
144
- ai_model: optionalNonEmpty(input.ai_model),
95
+ project_key: nonEmpty(input.project_key, "project_key"),
96
+ environment: nonEmpty(input.environment, "environment"),
97
+ service_key: nonEmpty(input.service_key, "service_key"),
98
+ repository: {
99
+ provider: nonEmpty(input.repository?.provider, "repository.provider"),
100
+ repository_id: nonEmpty(
101
+ input.repository?.repository_id,
102
+ "repository.repository_id",
103
+ ),
104
+ ...(optionalNonEmpty(input.repository?.owner)
105
+ ? { owner: optionalNonEmpty(input.repository.owner) }
106
+ : {}),
107
+ ...(optionalNonEmpty(input.repository?.name)
108
+ ? { name: optionalNonEmpty(input.repository.name) }
109
+ : {}),
110
+ ...(optionalNonEmpty(input.repository?.default_branch)
111
+ ? { default_branch: optionalNonEmpty(input.repository.default_branch) }
112
+ : {}),
113
+ merge_commit: nonEmpty(
114
+ input.repository?.merge_commit,
115
+ "repository.merge_commit",
116
+ ),
117
+ ...(optionalNonEmpty(input.repository?.merged_at)
118
+ ? { merged_at: optionalNonEmpty(input.repository.merged_at) }
119
+ : {}),
120
+ ...(input.repository?.pull_request_number === undefined ||
121
+ input.repository?.pull_request_number === null
122
+ ? {}
123
+ : { pull_request_number: input.repository.pull_request_number }),
124
+ ...(optionalNonEmpty(input.repository?.workflow_run_id)
125
+ ? { workflow_run_id: optionalNonEmpty(input.repository.workflow_run_id) }
126
+ : {}),
127
+ },
128
+ service: {
129
+ service_key: nonEmpty(
130
+ input.service?.service_key ?? input.service_key,
131
+ "service.service_key",
132
+ ),
133
+ root_path: input.service?.root_path ?? null,
134
+ framework: input.service?.framework ?? "fastapi",
135
+ language: input.service?.language ?? "python",
136
+ },
137
+ allowed_source_paths: stringArray(
138
+ input.allowed_source_paths,
139
+ "allowed_source_paths",
140
+ { min: 1 },
141
+ ),
142
+ excluded_source_paths: stringArray(
143
+ input.excluded_source_paths ?? [],
144
+ "excluded_source_paths",
145
+ ),
146
+ clue_api_base_url: nonEmpty(input.clue_api_base_url, "clue_api_base_url"),
147
+ ai_provider_base_url: null,
148
+ ai_provider: optionalNonEmpty(input.ai_provider),
149
+ ai_model: optionalNonEmpty(input.ai_model),
145
150
  });
146
151
 
147
152
  export const buildOperationSourceKey = (method, pathTemplate) =>
148
- `route.${method.toUpperCase()}.${pathTemplate}`;
153
+ `route.${method.toUpperCase()}.${pathTemplate}`;
149
154
 
150
155
  export const validateSemanticSnapshotRequest = (input) => {
151
- return parseWithSchema(
152
- semanticSnapshotRequestSchema,
153
- input,
154
- "semantic snapshot",
155
- );
156
+ return parseWithSchema(
157
+ semanticSnapshotRequestSchema,
158
+ input,
159
+ "semantic snapshot",
160
+ );
156
161
  };
157
162
 
158
163
  export const validateSemanticSnapshotResponse = (input) => {
159
- return parseWithSchema(
160
- semanticSnapshotResponseSchema,
161
- input,
162
- "semantic snapshot response",
163
- );
164
+ return parseWithSchema(
165
+ semanticSnapshotResponseSchema,
166
+ input,
167
+ "semantic snapshot response",
168
+ );
164
169
  };