@struere/cli 0.1.0
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/dist/commands/build.d.ts +3 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +61 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/deploy.d.ts +3 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +147 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +500 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +251 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +19 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/logs.d.ts +3 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +103 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/state.d.ts +3 -0
- package/dist/commands/state.d.ts.map +1 -0
- package/dist/commands/state.js +71 -0
- package/dist/commands/state.js.map +1 -0
- package/dist/commands/test.d.ts +3 -0
- package/dist/commands/test.d.ts.map +1 -0
- package/dist/commands/test.js +188 -0
- package/dist/commands/test.js.map +1 -0
- package/dist/commands/validate.d.ts +3 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +71 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/commands/whoami.d.ts +3 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +69 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1703 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/agent.d.ts +3 -0
- package/dist/utils/agent.d.ts.map +1 -0
- package/dist/utils/agent.js +25 -0
- package/dist/utils/agent.js.map +1 -0
- package/dist/utils/api.d.ts +147 -0
- package/dist/utils/api.d.ts.map +1 -0
- package/dist/utils/api.js +102 -0
- package/dist/utils/api.js.map +1 -0
- package/dist/utils/config.d.ts +3 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +43 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/credentials.d.ts +23 -0
- package/dist/utils/credentials.d.ts.map +1 -0
- package/dist/utils/credentials.js +51 -0
- package/dist/utils/credentials.js.map +1 -0
- package/dist/utils/validate.d.ts +3 -0
- package/dist/utils/validate.d.ts.map +1 -0
- package/dist/utils/validate.js +79 -0
- package/dist/utils/validate.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO;KACJ,IAAI,CAAC,SAAS,CAAC;KACf,WAAW,CAAC,iDAAiD,CAAC;KAC9D,OAAO,CAAC,OAAO,CAAC,CAAA;AAEnB,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;AAChC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;AACjC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;AAEjC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;AAC9B,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;AAChC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AAC/B,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;AACjC,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAA;AACnC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AAC/B,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;AAEhC,OAAO,CAAC,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/utils/agent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CA0BjE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
export async function loadAgent(cwd) {
|
|
3
|
+
const agentPath = join(cwd, 'src/agent.ts');
|
|
4
|
+
try {
|
|
5
|
+
const module = await import(agentPath);
|
|
6
|
+
const agent = module.default || module;
|
|
7
|
+
if (!agent.name) {
|
|
8
|
+
throw new Error('Agent must have a name');
|
|
9
|
+
}
|
|
10
|
+
if (!agent.version) {
|
|
11
|
+
throw new Error('Agent must have a version');
|
|
12
|
+
}
|
|
13
|
+
if (!agent.systemPrompt) {
|
|
14
|
+
throw new Error('Agent must have a systemPrompt');
|
|
15
|
+
}
|
|
16
|
+
return agent;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error instanceof Error && error.message.includes('Cannot find module')) {
|
|
20
|
+
throw new Error(`Agent not found at ${agentPath}`);
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/utils/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAG3B,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAW;IACzC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IAE3C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAA;QACtC,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAA;QAEtC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;QAC3C,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC9C,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,KAAoB,CAAA;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC;YAC3E,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAA;QACpD,CAAC;QACD,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export declare function getApiUrl(): string;
|
|
2
|
+
export declare function getGatewayUrl(): string;
|
|
3
|
+
export declare function getSyncUrl(): string;
|
|
4
|
+
export declare class ApiClient {
|
|
5
|
+
private baseUrl;
|
|
6
|
+
constructor(baseUrl?: string);
|
|
7
|
+
private request;
|
|
8
|
+
login(email: string, password: string): Promise<{
|
|
9
|
+
token: string;
|
|
10
|
+
user: {
|
|
11
|
+
id: string;
|
|
12
|
+
email: string;
|
|
13
|
+
name: string;
|
|
14
|
+
organizationId: string;
|
|
15
|
+
role: string;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
signup(email: string, name: string, password: string): Promise<{
|
|
19
|
+
token: string;
|
|
20
|
+
user: {
|
|
21
|
+
id: string;
|
|
22
|
+
email: string;
|
|
23
|
+
name: string;
|
|
24
|
+
organizationId: string;
|
|
25
|
+
role: string;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
getMe(): Promise<{
|
|
29
|
+
user: {
|
|
30
|
+
id: string;
|
|
31
|
+
email: string;
|
|
32
|
+
name: string;
|
|
33
|
+
organizationId: string;
|
|
34
|
+
role: string;
|
|
35
|
+
};
|
|
36
|
+
organization: {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
slug: string;
|
|
40
|
+
plan: string;
|
|
41
|
+
};
|
|
42
|
+
}>;
|
|
43
|
+
refreshToken(): Promise<{
|
|
44
|
+
token: string;
|
|
45
|
+
}>;
|
|
46
|
+
listAgents(): Promise<{
|
|
47
|
+
agents: Array<{
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
slug: string;
|
|
51
|
+
description: string | null;
|
|
52
|
+
status: string;
|
|
53
|
+
currentVersionId: string | null;
|
|
54
|
+
createdAt: string;
|
|
55
|
+
updatedAt: string;
|
|
56
|
+
}>;
|
|
57
|
+
}>;
|
|
58
|
+
createAgent(data: {
|
|
59
|
+
name: string;
|
|
60
|
+
slug: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
}): Promise<{
|
|
63
|
+
agent: {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
slug: string;
|
|
67
|
+
status: string;
|
|
68
|
+
};
|
|
69
|
+
}>;
|
|
70
|
+
getAgent(agentId: string): Promise<{
|
|
71
|
+
agent: {
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
slug: string;
|
|
75
|
+
status: string;
|
|
76
|
+
currentVersionId: string | null;
|
|
77
|
+
};
|
|
78
|
+
versions: Array<{
|
|
79
|
+
id: string;
|
|
80
|
+
version: string;
|
|
81
|
+
status: string;
|
|
82
|
+
deployedAt: string;
|
|
83
|
+
}>;
|
|
84
|
+
}>;
|
|
85
|
+
deployAgent(agentId: string, data: {
|
|
86
|
+
bundle: string;
|
|
87
|
+
version: string;
|
|
88
|
+
environment: 'preview' | 'staging' | 'production';
|
|
89
|
+
metadata: {
|
|
90
|
+
modelProvider: string;
|
|
91
|
+
modelName: string;
|
|
92
|
+
toolCount: number;
|
|
93
|
+
bundleSize: number;
|
|
94
|
+
};
|
|
95
|
+
}): Promise<{
|
|
96
|
+
deployment: {
|
|
97
|
+
id: string;
|
|
98
|
+
agentId: string;
|
|
99
|
+
versionId: string;
|
|
100
|
+
version: string;
|
|
101
|
+
environment: string;
|
|
102
|
+
url: string;
|
|
103
|
+
status: string;
|
|
104
|
+
};
|
|
105
|
+
}>;
|
|
106
|
+
createApiKey(data: {
|
|
107
|
+
name: string;
|
|
108
|
+
permissions: string[];
|
|
109
|
+
}): Promise<{
|
|
110
|
+
apiKey: {
|
|
111
|
+
id: string;
|
|
112
|
+
name: string;
|
|
113
|
+
key: string;
|
|
114
|
+
keyPrefix: string;
|
|
115
|
+
permissions: string[];
|
|
116
|
+
};
|
|
117
|
+
}>;
|
|
118
|
+
listApiKeys(): Promise<{
|
|
119
|
+
apiKeys: Array<{
|
|
120
|
+
id: string;
|
|
121
|
+
name: string;
|
|
122
|
+
keyPrefix: string;
|
|
123
|
+
permissions: string[];
|
|
124
|
+
lastUsedAt: string | null;
|
|
125
|
+
createdAt: string;
|
|
126
|
+
}>;
|
|
127
|
+
}>;
|
|
128
|
+
getUsage(period?: 'hour' | 'day' | 'week' | 'month'): Promise<{
|
|
129
|
+
period: string;
|
|
130
|
+
startDate: string;
|
|
131
|
+
endDate: string;
|
|
132
|
+
summary: {
|
|
133
|
+
executions: number;
|
|
134
|
+
inputTokens: number;
|
|
135
|
+
outputTokens: number;
|
|
136
|
+
totalTokens: number;
|
|
137
|
+
avgDurationMs: number;
|
|
138
|
+
successRate: number;
|
|
139
|
+
};
|
|
140
|
+
}>;
|
|
141
|
+
}
|
|
142
|
+
export declare class ApiError extends Error {
|
|
143
|
+
code: string;
|
|
144
|
+
status: number;
|
|
145
|
+
constructor(message: string, code: string, status: number);
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/utils/api.ts"],"names":[],"mappings":"AAMA,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAQ;gBAEX,OAAO,CAAC,EAAE,MAAM;YAId,OAAO;IAqCf,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;eAEhC,MAAM;cACP;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,cAAc,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE;;IAOrF,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;eAE/C,MA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YACzB,SAAS,EAAE,MAAM,CAAA;SAClB,CAAC;;IAIA,QAAQ,CAAC,MAAM,GAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,OAAe;gBAEpD,MAAM;mBACH,MAAM;iBACR,MAAM;iBACN;YACP,UAAU,EAAE,MAAM,CAAA;YAClB,WAAW,EAAE,MAAM,CAAA;YACnB,YAAY,EAAE,MAAM,CAAA;YACpB,WAAW,EAAE,MAAM,CAAA;YACnB,aAAa,EAAE,MAAM,CAAA;YACrB,WAAW,EAAE,MAAM,CAAA;SACpB;;CAGN;AAED,qBAAa,QAAS,SAAQ,KAAK;IAGxB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;gBAFrB,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;CAKxB"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getToken, getApiKey } from './credentials';
|
|
2
|
+
const DEFAULT_API_URL = 'https://api.struere.dev';
|
|
3
|
+
const DEFAULT_GATEWAY_URL = 'https://gateway.struere.dev';
|
|
4
|
+
const DEFAULT_SYNC_URL = 'wss://sync.struere.dev';
|
|
5
|
+
export function getApiUrl() {
|
|
6
|
+
return process.env.STRUERE_API_URL || DEFAULT_API_URL;
|
|
7
|
+
}
|
|
8
|
+
export function getGatewayUrl() {
|
|
9
|
+
return process.env.STRUERE_GATEWAY_URL || DEFAULT_GATEWAY_URL;
|
|
10
|
+
}
|
|
11
|
+
export function getSyncUrl() {
|
|
12
|
+
return process.env.STRUERE_SYNC_URL || DEFAULT_SYNC_URL;
|
|
13
|
+
}
|
|
14
|
+
export class ApiClient {
|
|
15
|
+
baseUrl;
|
|
16
|
+
constructor(baseUrl) {
|
|
17
|
+
this.baseUrl = baseUrl || getApiUrl();
|
|
18
|
+
}
|
|
19
|
+
async request(path, options = {}) {
|
|
20
|
+
const token = getToken();
|
|
21
|
+
const apiKey = getApiKey();
|
|
22
|
+
const headers = {
|
|
23
|
+
'Content-Type': 'application/json',
|
|
24
|
+
...(options.headers || {})
|
|
25
|
+
};
|
|
26
|
+
if (token) {
|
|
27
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
28
|
+
}
|
|
29
|
+
else if (apiKey) {
|
|
30
|
+
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
31
|
+
}
|
|
32
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
33
|
+
...options,
|
|
34
|
+
headers
|
|
35
|
+
});
|
|
36
|
+
const data = await response.json();
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const error = data;
|
|
39
|
+
throw new ApiError(error.error?.message || `HTTP ${response.status}`, error.error?.code || 'UNKNOWN_ERROR', response.status);
|
|
40
|
+
}
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
async login(email, password) {
|
|
44
|
+
return this.request('/v1/auth/login', {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
body: JSON.stringify({ email, password })
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async signup(email, name, password) {
|
|
50
|
+
return this.request('/v1/auth/signup', {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
body: JSON.stringify({ email, name, password })
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async getMe() {
|
|
56
|
+
return this.request('/v1/auth/me');
|
|
57
|
+
}
|
|
58
|
+
async refreshToken() {
|
|
59
|
+
return this.request('/v1/auth/refresh', { method: 'POST' });
|
|
60
|
+
}
|
|
61
|
+
async listAgents() {
|
|
62
|
+
return this.request('/v1/agents');
|
|
63
|
+
}
|
|
64
|
+
async createAgent(data) {
|
|
65
|
+
return this.request('/v1/agents', {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
body: JSON.stringify(data)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async getAgent(agentId) {
|
|
71
|
+
return this.request(`/v1/agents/${agentId}`);
|
|
72
|
+
}
|
|
73
|
+
async deployAgent(agentId, data) {
|
|
74
|
+
return this.request(`/v1/deployments/agents/${agentId}/deploy`, {
|
|
75
|
+
method: 'POST',
|
|
76
|
+
body: JSON.stringify(data)
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async createApiKey(data) {
|
|
80
|
+
return this.request('/v1/api-keys', {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
body: JSON.stringify(data)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async listApiKeys() {
|
|
86
|
+
return this.request('/v1/api-keys');
|
|
87
|
+
}
|
|
88
|
+
async getUsage(period = 'day') {
|
|
89
|
+
return this.request(`/v1/usage?period=${period}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export class ApiError extends Error {
|
|
93
|
+
code;
|
|
94
|
+
status;
|
|
95
|
+
constructor(message, code, status) {
|
|
96
|
+
super(message);
|
|
97
|
+
this.code = code;
|
|
98
|
+
this.status = status;
|
|
99
|
+
this.name = 'ApiError';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/utils/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEnD,MAAM,eAAe,GAAG,yBAAyB,CAAA;AACjD,MAAM,mBAAmB,GAAG,6BAA6B,CAAA;AACzD,MAAM,gBAAgB,GAAG,wBAAwB,CAAA;AAEjD,MAAM,UAAU,SAAS;IACvB,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,eAAe,CAAA;AACvD,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,mBAAmB,CAAA;AAC/D,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,gBAAgB,CAAA;AACzD,CAAC;AAED,MAAM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AC,IAA6C;QAC9D,OAAO,IAAI,CAAC,OAAO,CAQhB,cAAc,EAAE;YACjB,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC,OAAO,CAShB,cAAc,CAAC,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,SAA4C,KAAK;QAC9D,OAAO,IAAI,CAAC,OAAO,CAYhB,oBAAoB,MAAM,EAAE,CAAC,CAAA;IAClC,CAAC;CACF;AAED,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGxB;IACA;IAHT,YACE,OAAe,EACR,IAAY,EACZ,MAAc;QAErB,KAAK,CAAC,OAAO,CAAC,CAAA;QAHP,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;QAGrB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAkBpD,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CA0BtE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
const defaultConfig = {
|
|
3
|
+
port: 3000,
|
|
4
|
+
host: 'localhost',
|
|
5
|
+
cors: {
|
|
6
|
+
origins: ['http://localhost:3000'],
|
|
7
|
+
credentials: true,
|
|
8
|
+
},
|
|
9
|
+
logging: {
|
|
10
|
+
level: 'info',
|
|
11
|
+
format: 'pretty',
|
|
12
|
+
},
|
|
13
|
+
auth: {
|
|
14
|
+
type: 'none',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export async function loadConfig(cwd) {
|
|
18
|
+
const configPath = join(cwd, 'af.config.ts');
|
|
19
|
+
try {
|
|
20
|
+
const module = await import(configPath);
|
|
21
|
+
const config = module.default || module;
|
|
22
|
+
return {
|
|
23
|
+
...defaultConfig,
|
|
24
|
+
...config,
|
|
25
|
+
cors: {
|
|
26
|
+
...defaultConfig.cors,
|
|
27
|
+
...config.cors,
|
|
28
|
+
},
|
|
29
|
+
logging: {
|
|
30
|
+
...defaultConfig.logging,
|
|
31
|
+
...config.logging,
|
|
32
|
+
},
|
|
33
|
+
auth: {
|
|
34
|
+
...defaultConfig.auth,
|
|
35
|
+
...config.auth,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return defaultConfig;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAG3B,MAAM,aAAa,GAAoB;IACrC,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE;QACJ,OAAO,EAAE,CAAC,uBAAuB,CAAC;QAClC,WAAW,EAAE,IAAI;KAClB;IACD,OAAO,EAAE;QACP,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,QAAQ;KACjB;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;KACb;CACF,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW;IAC1C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IAE5C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAA;QACvC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAA;QAEvC,OAAO;YACL,GAAG,aAAa;YAChB,GAAG,MAAM;YACT,IAAI,EAAE;gBACJ,GAAG,aAAa,CAAC,IAAI;gBACrB,GAAG,MAAM,CAAC,IAAI;aACf;YACD,OAAO,EAAE;gBACP,GAAG,aAAa,CAAC,OAAO;gBACxB,GAAG,MAAM,CAAC,OAAO;aAClB;YACD,IAAI,EAAE;gBACJ,GAAG,aAAa,CAAC,IAAI;gBACrB,GAAG,MAAM,CAAC,IAAI;aACf;SACF,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,aAAa,CAAA;IACtB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface Credentials {
|
|
2
|
+
token: string;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
user: {
|
|
5
|
+
id: string;
|
|
6
|
+
email: string;
|
|
7
|
+
name: string;
|
|
8
|
+
organizationId: string;
|
|
9
|
+
};
|
|
10
|
+
organization: {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
slug: string;
|
|
14
|
+
};
|
|
15
|
+
expiresAt: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function saveCredentials(credentials: Credentials): void;
|
|
18
|
+
export declare function loadCredentials(): Credentials | null;
|
|
19
|
+
export declare function clearCredentials(): void;
|
|
20
|
+
export declare function getApiKey(): string | null;
|
|
21
|
+
export declare function getToken(): string | null;
|
|
22
|
+
export declare function isLoggedIn(): boolean;
|
|
23
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/utils/credentials.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAA;QACV,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;QACZ,cAAc,EAAE,MAAM,CAAA;KACvB,CAAA;IACD,YAAY,EAAE;QACZ,EAAE,EAAE,MAAM,CAAA;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IACD,SAAS,EAAE,MAAM,CAAA;CAClB;AAWD,wBAAgB,eAAe,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAG9D;AAED,wBAAgB,eAAe,IAAI,WAAW,GAAG,IAAI,CAkBpD;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAIvC;AAED,wBAAgB,SAAS,IAAI,MAAM,GAAG,IAAI,CAMzC;AAED,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAGxC;AAED,wBAAgB,UAAU,IAAI,OAAO,CAEpC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { homedir } from 'os';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from 'fs';
|
|
4
|
+
const CONFIG_DIR = join(homedir(), '.struere');
|
|
5
|
+
const CREDENTIALS_FILE = join(CONFIG_DIR, 'credentials.json');
|
|
6
|
+
function ensureConfigDir() {
|
|
7
|
+
if (!existsSync(CONFIG_DIR)) {
|
|
8
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function saveCredentials(credentials) {
|
|
12
|
+
ensureConfigDir();
|
|
13
|
+
writeFileSync(CREDENTIALS_FILE, JSON.stringify(credentials, null, 2), { mode: 0o600 });
|
|
14
|
+
}
|
|
15
|
+
export function loadCredentials() {
|
|
16
|
+
if (!existsSync(CREDENTIALS_FILE)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const data = readFileSync(CREDENTIALS_FILE, 'utf-8');
|
|
21
|
+
const credentials = JSON.parse(data);
|
|
22
|
+
if (new Date(credentials.expiresAt) < new Date()) {
|
|
23
|
+
clearCredentials();
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return credentials;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function clearCredentials() {
|
|
33
|
+
if (existsSync(CREDENTIALS_FILE)) {
|
|
34
|
+
unlinkSync(CREDENTIALS_FILE);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function getApiKey() {
|
|
38
|
+
const credentials = loadCredentials();
|
|
39
|
+
if (credentials?.apiKey) {
|
|
40
|
+
return credentials.apiKey;
|
|
41
|
+
}
|
|
42
|
+
return process.env.STRUERE_API_KEY || null;
|
|
43
|
+
}
|
|
44
|
+
export function getToken() {
|
|
45
|
+
const credentials = loadCredentials();
|
|
46
|
+
return credentials?.token || null;
|
|
47
|
+
}
|
|
48
|
+
export function isLoggedIn() {
|
|
49
|
+
return loadCredentials() !== null;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/utils/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAmBnF,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,CAAC,CAAA;AAC9C,MAAM,gBAAgB,GAAG,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAA;AAE7D,SAAS,eAAe;IACtB,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,I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AE,KAAK,IAAI,IAAI,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,eAAe,EAAE,KAAK,IAAI,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/utils/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,eAAe,CAAA;AAE/D,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,EAAE,CA+D1D"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export function validateAgent(agent) {
|
|
2
|
+
const errors = [];
|
|
3
|
+
if (!agent.name) {
|
|
4
|
+
errors.push('Agent name is required');
|
|
5
|
+
}
|
|
6
|
+
else if (!/^[a-z0-9-]+$/.test(agent.name)) {
|
|
7
|
+
errors.push('Agent name must be lowercase alphanumeric with hyphens only');
|
|
8
|
+
}
|
|
9
|
+
if (!agent.version) {
|
|
10
|
+
errors.push('Agent version is required');
|
|
11
|
+
}
|
|
12
|
+
else if (!/^\d+\.\d+\.\d+/.test(agent.version)) {
|
|
13
|
+
errors.push('Agent version must follow semver format (e.g., 1.0.0)');
|
|
14
|
+
}
|
|
15
|
+
if (!agent.systemPrompt) {
|
|
16
|
+
errors.push('System prompt is required');
|
|
17
|
+
}
|
|
18
|
+
else if (typeof agent.systemPrompt === 'string' && agent.systemPrompt.trim().length === 0) {
|
|
19
|
+
errors.push('System prompt cannot be empty');
|
|
20
|
+
}
|
|
21
|
+
if (agent.model) {
|
|
22
|
+
const validProviders = ['anthropic', 'openai', 'google', 'custom'];
|
|
23
|
+
if (!validProviders.includes(agent.model.provider)) {
|
|
24
|
+
errors.push(`Invalid model provider: ${agent.model.provider}`);
|
|
25
|
+
}
|
|
26
|
+
if (!agent.model.name) {
|
|
27
|
+
errors.push('Model name is required when model is specified');
|
|
28
|
+
}
|
|
29
|
+
if (agent.model.temperature !== undefined) {
|
|
30
|
+
if (agent.model.temperature < 0 || agent.model.temperature > 2) {
|
|
31
|
+
errors.push('Model temperature must be between 0 and 2');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (agent.model.maxTokens !== undefined) {
|
|
35
|
+
if (agent.model.maxTokens < 1) {
|
|
36
|
+
errors.push('Model maxTokens must be at least 1');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (agent.tools) {
|
|
41
|
+
for (const tool of agent.tools) {
|
|
42
|
+
const toolErrors = validateTool(tool);
|
|
43
|
+
errors.push(...toolErrors);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (agent.state) {
|
|
47
|
+
const validStorage = ['memory', 'redis', 'postgres', 'custom'];
|
|
48
|
+
if (!validStorage.includes(agent.state.storage)) {
|
|
49
|
+
errors.push(`Invalid state storage: ${agent.state.storage}`);
|
|
50
|
+
}
|
|
51
|
+
if (agent.state.ttl !== undefined && agent.state.ttl < 0) {
|
|
52
|
+
errors.push('State TTL must be non-negative');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return errors;
|
|
56
|
+
}
|
|
57
|
+
function validateTool(tool) {
|
|
58
|
+
const errors = [];
|
|
59
|
+
if (!tool.name) {
|
|
60
|
+
errors.push('Tool name is required');
|
|
61
|
+
}
|
|
62
|
+
else if (!/^[a-z_][a-z0-9_]*$/.test(tool.name)) {
|
|
63
|
+
errors.push(`Tool name "${tool.name}" must be snake_case`);
|
|
64
|
+
}
|
|
65
|
+
if (!tool.description) {
|
|
66
|
+
errors.push(`Tool "${tool.name || 'unknown'}" requires a description`);
|
|
67
|
+
}
|
|
68
|
+
if (!tool.parameters) {
|
|
69
|
+
errors.push(`Tool "${tool.name || 'unknown'}" requires parameters definition`);
|
|
70
|
+
}
|
|
71
|
+
else if (tool.parameters.type !== 'object') {
|
|
72
|
+
errors.push(`Tool "${tool.name || 'unknown'}" parameters type must be "object"`);
|
|
73
|
+
}
|
|
74
|
+
if (typeof tool.handler !== 'function') {
|
|
75
|
+
errors.push(`Tool "${tool.name || 'unknown'}" requires a handler function`);
|
|
76
|
+
}
|
|
77
|
+
return errors;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/utils/validate.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,aAAa,CAAC,KAAkB;IAC9C,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAChB,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IACvC,CAAC;SAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5C,MAAM,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAA;IAC5E,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;IAC1C,CAAC;SAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACjD,MAAM,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAA;IACtE,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;QACxB,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;IAC1C,CAAC;SAAM,IAAI,OAAO,KAAK,CAAC,YAAY,KAAK,QAAQ,IAAI,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5F,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,QAAQ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CAAC;QACvC,MAAM,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,IAAI,SAAS,+BAA+B,CAAC,CAAA;IAC7E,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@struere/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tool for developing, testing, and deploying AI agents",
|
|
5
|
+
"keywords": ["ai", "agents", "cli", "developer-tools", "llm"],
|
|
6
|
+
"author": "struere",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/struere/struere.git",
|
|
14
|
+
"directory": "packages/cli"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://struere.dev",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/struere/struere/issues"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"bin": {
|
|
22
|
+
"struere": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"files": ["dist"],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node --external commander --external chalk --external ora --external chokidar --external yaml --external @struere/runtime && chmod +x ./dist/index.js",
|
|
28
|
+
"dev": "tsc --watch",
|
|
29
|
+
"test": "bun test"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@struere/core": "^0.1.0",
|
|
33
|
+
"@struere/runtime": "^0.1.0",
|
|
34
|
+
"chalk": "^5.3.0",
|
|
35
|
+
"chokidar": "^3.5.3",
|
|
36
|
+
"commander": "^12.0.0",
|
|
37
|
+
"ora": "^8.0.0",
|
|
38
|
+
"yaml": "^2.3.4"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"bun-types": "^1.0.0",
|
|
42
|
+
"typescript": "^5.3.0"
|
|
43
|
+
}
|
|
44
|
+
}
|