@ultrst-armada/kloks 1.23.0 → 1.24.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/.krusbl-release-attestation.json +3 -3
- package/package.json +1 -1
- package/packages/backend/dist/ai-routing/index.js +2 -2
- package/packages/backend/dist/{chunk-OB65KZ2M.js → chunk-SJD574XG.js} +4 -4
- package/packages/backend/dist/index.js +10 -10
- package/packages/backend/dist/krnl-ai-services.js +3 -3
- package/packages/semantic-runtime/dist/index.d.ts +132 -2
- package/packages/semantic-runtime/dist/index.js +300 -8
- package/packages/services/dist/index.d.ts +71 -1
- package/packages/services/dist/index.js +125 -0
- package/packages/backend/dist/{chunk-PT6J6UEU.js → chunk-YAAGIU2H.js} +3 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
3
|
"packageName": "@ultrst-armada/kloks",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"sourceCommit": "
|
|
4
|
+
"version": "1.24.0",
|
|
5
|
+
"sourceCommit": "82fd096f94e5ba9bd491c21fca1863b29be14e70",
|
|
6
6
|
"releaseWorkflow": "npm Release",
|
|
7
|
-
"workflowRunId": "
|
|
7
|
+
"workflowRunId": "41218118420"
|
|
8
8
|
}
|
package/package.json
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
failoverExecutionEngine,
|
|
7
7
|
healthCheckService,
|
|
8
8
|
metricsLogger
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-YAAGIU2H.js";
|
|
10
|
+
import "../chunk-SLR6SIEU.js";
|
|
10
11
|
import "../chunk-LMWXONZG.js";
|
|
11
12
|
import "../chunk-P7H6TIEA.js";
|
|
12
|
-
import "../chunk-SLR6SIEU.js";
|
|
13
13
|
import "../chunk-MAMK4GDH.js";
|
|
14
14
|
import "../chunk-JSQZAFBU.js";
|
|
15
15
|
import "../chunk-QGM4M3NI.js";
|
|
@@ -10,16 +10,16 @@ import {
|
|
|
10
10
|
} from "./chunk-GCTQY24J.js";
|
|
11
11
|
import {
|
|
12
12
|
failoverExecutionEngine
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-YAAGIU2H.js";
|
|
14
|
+
import {
|
|
15
|
+
aiProviderService
|
|
16
|
+
} from "./chunk-SLR6SIEU.js";
|
|
14
17
|
import {
|
|
15
18
|
modelCatalog
|
|
16
19
|
} from "./chunk-LMWXONZG.js";
|
|
17
20
|
import {
|
|
18
21
|
keyStore
|
|
19
22
|
} from "./chunk-P7H6TIEA.js";
|
|
20
|
-
import {
|
|
21
|
-
aiProviderService
|
|
22
|
-
} from "./chunk-SLR6SIEU.js";
|
|
23
23
|
|
|
24
24
|
// src/krnl-ai-services.ts
|
|
25
25
|
var AIProviderServiceDefinition = createServiceDefinition({
|
|
@@ -35,15 +35,15 @@ import {
|
|
|
35
35
|
syncWorkspace,
|
|
36
36
|
workingWorkspaceService
|
|
37
37
|
} from "./chunk-6DNGLKAV.js";
|
|
38
|
-
import {
|
|
39
|
-
validateToolInput
|
|
40
|
-
} from "./chunk-6GQNYRD6.js";
|
|
41
38
|
import {
|
|
42
39
|
BaseApiRoute,
|
|
43
40
|
createSSEResponse,
|
|
44
41
|
withAuth,
|
|
45
42
|
withCors
|
|
46
43
|
} from "./chunk-TWCEVES2.js";
|
|
44
|
+
import {
|
|
45
|
+
validateToolInput
|
|
46
|
+
} from "./chunk-6GQNYRD6.js";
|
|
47
47
|
import {
|
|
48
48
|
AdminGuard,
|
|
49
49
|
BaseAccountProvider,
|
|
@@ -138,7 +138,7 @@ import {
|
|
|
138
138
|
AIRoutingServiceFacade,
|
|
139
139
|
AIToolServiceDefinition,
|
|
140
140
|
AIToolServiceFacade
|
|
141
|
-
} from "./chunk-
|
|
141
|
+
} from "./chunk-SJD574XG.js";
|
|
142
142
|
import {
|
|
143
143
|
MCPEngine,
|
|
144
144
|
ToolManagerService,
|
|
@@ -269,8 +269,8 @@ import {
|
|
|
269
269
|
performInference
|
|
270
270
|
} from "./chunk-GCTQY24J.js";
|
|
271
271
|
import "./chunk-IN3WRHXE.js";
|
|
272
|
-
import "./chunk-UU6M3L3O.js";
|
|
273
272
|
import "./chunk-LV55WKZR.js";
|
|
273
|
+
import "./chunk-UU6M3L3O.js";
|
|
274
274
|
import "./chunk-WVDSMTW3.js";
|
|
275
275
|
import {
|
|
276
276
|
FailoverExecutionEngine,
|
|
@@ -279,7 +279,11 @@ import {
|
|
|
279
279
|
failoverExecutionEngine,
|
|
280
280
|
healthCheckService,
|
|
281
281
|
metricsLogger
|
|
282
|
-
} from "./chunk-
|
|
282
|
+
} from "./chunk-YAAGIU2H.js";
|
|
283
|
+
import {
|
|
284
|
+
AIProviderService,
|
|
285
|
+
aiProviderService
|
|
286
|
+
} from "./chunk-SLR6SIEU.js";
|
|
283
287
|
import {
|
|
284
288
|
EndpointRefresher,
|
|
285
289
|
ModelCatalogService,
|
|
@@ -296,10 +300,6 @@ import {
|
|
|
296
300
|
keysStorage,
|
|
297
301
|
validateApiKey
|
|
298
302
|
} from "./chunk-P7H6TIEA.js";
|
|
299
|
-
import {
|
|
300
|
-
AIProviderService,
|
|
301
|
-
aiProviderService
|
|
302
|
-
} from "./chunk-SLR6SIEU.js";
|
|
303
303
|
import {
|
|
304
304
|
AITransportClient
|
|
305
305
|
} from "./chunk-MAMK4GDH.js";
|
|
@@ -11,14 +11,14 @@ import {
|
|
|
11
11
|
AIRoutingServiceFacade,
|
|
12
12
|
AIToolServiceDefinition,
|
|
13
13
|
AIToolServiceFacade
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-SJD574XG.js";
|
|
15
15
|
import "./chunk-U4HUGPRH.js";
|
|
16
16
|
import "./chunk-MWSYNRNZ.js";
|
|
17
17
|
import "./chunk-GCTQY24J.js";
|
|
18
|
-
import "./chunk-
|
|
18
|
+
import "./chunk-YAAGIU2H.js";
|
|
19
|
+
import "./chunk-SLR6SIEU.js";
|
|
19
20
|
import "./chunk-LMWXONZG.js";
|
|
20
21
|
import "./chunk-P7H6TIEA.js";
|
|
21
|
-
import "./chunk-SLR6SIEU.js";
|
|
22
22
|
import "./chunk-MAMK4GDH.js";
|
|
23
23
|
import "./chunk-JSQZAFBU.js";
|
|
24
24
|
import "./chunk-QGM4M3NI.js";
|
|
@@ -6,6 +6,11 @@ interface JsonSchema {
|
|
|
6
6
|
required?: string[];
|
|
7
7
|
[key: string]: unknown;
|
|
8
8
|
}
|
|
9
|
+
interface SemanticValueDescriptor {
|
|
10
|
+
semanticType: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
constraints?: Record<string, unknown>;
|
|
13
|
+
}
|
|
9
14
|
interface CapabilityDescriptor {
|
|
10
15
|
id: string;
|
|
11
16
|
name: string;
|
|
@@ -14,6 +19,7 @@ interface CapabilityDescriptor {
|
|
|
14
19
|
inputSchema?: JsonSchema;
|
|
15
20
|
outputSchema?: JsonSchema;
|
|
16
21
|
requirements?: RequirementTemplate[];
|
|
22
|
+
provides?: SemanticValueDescriptor[];
|
|
17
23
|
examples?: unknown[];
|
|
18
24
|
sideEffects?: 'read' | 'compute' | 'write' | 'external' | 'irreversible';
|
|
19
25
|
metadata?: Record<string, unknown>;
|
|
@@ -34,6 +40,7 @@ interface Requirement {
|
|
|
34
40
|
sourceCapability: string;
|
|
35
41
|
sourceField?: string;
|
|
36
42
|
constraints?: Record<string, unknown>;
|
|
43
|
+
value?: unknown;
|
|
37
44
|
}
|
|
38
45
|
interface RuntimeContext {
|
|
39
46
|
applicationId: string;
|
|
@@ -98,6 +105,11 @@ interface Task {
|
|
|
98
105
|
result?: unknown;
|
|
99
106
|
error?: string;
|
|
100
107
|
}
|
|
108
|
+
interface SemanticPlan {
|
|
109
|
+
intent?: string;
|
|
110
|
+
nodes: Omit<TaskNode, 'status'>[];
|
|
111
|
+
requirements?: Requirement[];
|
|
112
|
+
}
|
|
101
113
|
|
|
102
114
|
declare class CapabilityRegistry {
|
|
103
115
|
private readonly items;
|
|
@@ -106,6 +118,7 @@ declare class CapabilityRegistry {
|
|
|
106
118
|
get(id: string): CapabilityDescriptor | undefined;
|
|
107
119
|
list(): CapabilityDescriptor[];
|
|
108
120
|
findBySemanticType(semanticType: string): CapabilityDescriptor[];
|
|
121
|
+
findProviders(semanticType: string): CapabilityDescriptor[];
|
|
109
122
|
}
|
|
110
123
|
|
|
111
124
|
interface KnowledgeResolver {
|
|
@@ -123,12 +136,25 @@ interface ResolutionResult {
|
|
|
123
136
|
value?: unknown;
|
|
124
137
|
source?: string;
|
|
125
138
|
reason?: string;
|
|
139
|
+
capabilityId?: string;
|
|
126
140
|
}
|
|
127
141
|
interface RequirementSource {
|
|
128
142
|
canResolve(requirement: Requirement, context: AgentContext): Promise<boolean>;
|
|
129
143
|
resolve(requirement: Requirement, context: AgentContext): Promise<unknown>;
|
|
130
144
|
name: string;
|
|
131
145
|
}
|
|
146
|
+
interface RequirementCapabilityExecutor {
|
|
147
|
+
execute(capability: CapabilityDescriptor, input: unknown, context: AgentContext): Promise<unknown>;
|
|
148
|
+
}
|
|
149
|
+
declare class CapabilityRequirementSource implements RequirementSource {
|
|
150
|
+
private readonly registry;
|
|
151
|
+
private readonly executor;
|
|
152
|
+
readonly name = "capability-execution";
|
|
153
|
+
constructor(registry: CapabilityRegistry, executor: RequirementCapabilityExecutor);
|
|
154
|
+
canResolve(requirement: Requirement): Promise<boolean>;
|
|
155
|
+
resolve(requirement: Requirement, context: AgentContext): Promise<unknown>;
|
|
156
|
+
private executeProvider;
|
|
157
|
+
}
|
|
132
158
|
declare class RequirementResolver {
|
|
133
159
|
private readonly registry;
|
|
134
160
|
private readonly sources;
|
|
@@ -151,8 +177,9 @@ declare class TaskRuntime {
|
|
|
151
177
|
private readonly events?;
|
|
152
178
|
private readonly store;
|
|
153
179
|
constructor(store?: TaskStore, events?: TaskEventSink | undefined);
|
|
154
|
-
create(request: string, parentTaskId?: string, contextId?:
|
|
180
|
+
create(request: string, parentTaskId?: string, contextId?: string): Task;
|
|
155
181
|
get(id: string): Task | undefined;
|
|
182
|
+
list(): Task[];
|
|
156
183
|
transition(id: string, status: TaskStatus): Task;
|
|
157
184
|
addRequirement(id: string, requirement: TaskContext['requirements'][number]): Task;
|
|
158
185
|
addArtifact(id: string, artifact: Artifact): Task;
|
|
@@ -209,4 +236,107 @@ declare class CapabilityExecutionRuntime {
|
|
|
209
236
|
execute(capability: CapabilityDescriptor, input: unknown, context: AgentContext, executor: CapabilityExecutor): Promise<ExecutionResult>;
|
|
210
237
|
}
|
|
211
238
|
|
|
212
|
-
|
|
239
|
+
interface SemanticPlanner {
|
|
240
|
+
plan(request: string, context: AgentContext): Promise<SemanticPlan>;
|
|
241
|
+
}
|
|
242
|
+
interface SemanticExecutionAdapter {
|
|
243
|
+
execute(capability: CapabilityDescriptor, input: unknown, context: AgentContext): Promise<unknown>;
|
|
244
|
+
}
|
|
245
|
+
type OrchestrationResult = {
|
|
246
|
+
status: 'completed';
|
|
247
|
+
task: Task;
|
|
248
|
+
output: unknown[];
|
|
249
|
+
} | {
|
|
250
|
+
status: 'input-required';
|
|
251
|
+
task: Task;
|
|
252
|
+
requirements: Requirement[];
|
|
253
|
+
} | {
|
|
254
|
+
status: 'failed';
|
|
255
|
+
task: Task;
|
|
256
|
+
error: string;
|
|
257
|
+
};
|
|
258
|
+
declare class SemanticOrchestrator {
|
|
259
|
+
private readonly capabilities;
|
|
260
|
+
private readonly tasks;
|
|
261
|
+
private readonly requirements;
|
|
262
|
+
private readonly planner;
|
|
263
|
+
private readonly executor;
|
|
264
|
+
private readonly authorization?;
|
|
265
|
+
readonly graphs: TaskGraphRuntime;
|
|
266
|
+
constructor(capabilities: CapabilityRegistry, tasks: TaskRuntime, requirements: RequirementResolver, planner: SemanticPlanner, executor: SemanticExecutionAdapter, authorization?: AuthorizationPolicy | undefined);
|
|
267
|
+
run(task: Task, context: AgentContext): Promise<OrchestrationResult>;
|
|
268
|
+
private resolveInput;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
interface ConversationMessage {
|
|
272
|
+
id: string;
|
|
273
|
+
role: 'user' | 'agent' | 'system';
|
|
274
|
+
content: string;
|
|
275
|
+
taskId?: string;
|
|
276
|
+
createdAt: string;
|
|
277
|
+
}
|
|
278
|
+
interface Conversation {
|
|
279
|
+
id: string;
|
|
280
|
+
messages: ConversationMessage[];
|
|
281
|
+
taskIds: string[];
|
|
282
|
+
}
|
|
283
|
+
interface ConversationStore {
|
|
284
|
+
get(id: string): Conversation | undefined;
|
|
285
|
+
set(conversation: Conversation): void;
|
|
286
|
+
}
|
|
287
|
+
interface ConversationInputResolver {
|
|
288
|
+
resolve(input: string, requirement: Requirement, context: AgentContext): Promise<unknown>;
|
|
289
|
+
}
|
|
290
|
+
interface ConversationRuntimeOptions {
|
|
291
|
+
tasks: TaskRuntime;
|
|
292
|
+
orchestrator: SemanticOrchestrator;
|
|
293
|
+
buildContext: (taskId: string, conversationId: string) => Promise<AgentContext>;
|
|
294
|
+
inputResolver: ConversationInputResolver;
|
|
295
|
+
store?: ConversationStore;
|
|
296
|
+
}
|
|
297
|
+
declare class ConversationRuntime {
|
|
298
|
+
private readonly options;
|
|
299
|
+
private readonly store;
|
|
300
|
+
constructor(options: ConversationRuntimeOptions);
|
|
301
|
+
send(input: string, conversationId?: string, taskId?: string): Promise<OrchestrationResult>;
|
|
302
|
+
get(id: string): Conversation | undefined;
|
|
303
|
+
private getOrCreate;
|
|
304
|
+
private describe;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
interface WorkspaceFileAdapter {
|
|
308
|
+
readFile(workspaceId: string, path: string): Promise<string | Uint8Array>;
|
|
309
|
+
writeFile(workspaceId: string, path: string, content: string): Promise<unknown>;
|
|
310
|
+
deleteFile(workspaceId: string, path: string): Promise<unknown>;
|
|
311
|
+
listFiles(workspaceId: string, path: string): Promise<readonly {
|
|
312
|
+
name: string;
|
|
313
|
+
path: string;
|
|
314
|
+
isFolder?: boolean;
|
|
315
|
+
}[]>;
|
|
316
|
+
}
|
|
317
|
+
declare class WorkspaceTaskStore implements TaskStore {
|
|
318
|
+
private readonly workspace;
|
|
319
|
+
private readonly workspaceId;
|
|
320
|
+
private readonly root;
|
|
321
|
+
private readonly items;
|
|
322
|
+
constructor(workspace: WorkspaceFileAdapter, workspaceId: string, root?: string);
|
|
323
|
+
hydrate(): Promise<Task[]>;
|
|
324
|
+
get(id: string): Task | undefined;
|
|
325
|
+
set(task: Task): void;
|
|
326
|
+
list(): Task[];
|
|
327
|
+
delete(id: string): Promise<void>;
|
|
328
|
+
}
|
|
329
|
+
declare class WorkspaceConversationStore implements ConversationStore {
|
|
330
|
+
private readonly workspace;
|
|
331
|
+
private readonly workspaceId;
|
|
332
|
+
private readonly root;
|
|
333
|
+
private readonly items;
|
|
334
|
+
constructor(workspace: WorkspaceFileAdapter, workspaceId: string, root?: string);
|
|
335
|
+
hydrate(): Promise<Conversation[]>;
|
|
336
|
+
get(id: string): Conversation | undefined;
|
|
337
|
+
set(conversation: Conversation): void;
|
|
338
|
+
list(): Conversation[];
|
|
339
|
+
delete(id: string): Promise<void>;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export { type AgentCard, type AgentContext, AgentRegistry, type Artifact, type AuthorizationDecision, type AuthorizationPolicy, type CapabilityDescriptor, CapabilityExecutionRuntime, type CapabilityExecutor, type CapabilityKind, CapabilityRegistry, CapabilityRequirementSource, ContextResolver, type Conversation, type ConversationInputResolver, type ConversationMessage, ConversationRuntime, type ConversationRuntimeOptions, type ConversationStore, type ExecutionResult, type JsonSchema, type KnowledgeContext, type KnowledgeResolver, type OrchestrationResult, type Requirement, type RequirementCapabilityExecutor, RequirementResolver, type RequirementSource, type RequirementTemplate, type ResolutionResult, type RuntimeContext, type SemanticExecutionAdapter, SemanticOrchestrator, type SemanticPlan, type SemanticPlanner, type SemanticRequest, type SemanticValueDescriptor, type Task, type TaskContext, type TaskEventSink, type TaskGraph, TaskGraphRuntime, type TaskNode, TaskRuntime, type TaskStatus, type TaskStore, WorkspaceConversationStore, type WorkspaceFileAdapter, WorkspaceTaskStore, createSemanticRequest };
|
|
@@ -15,7 +15,14 @@ var CapabilityRegistry = class {
|
|
|
15
15
|
return [...this.items.values()];
|
|
16
16
|
}
|
|
17
17
|
findBySemanticType(semanticType) {
|
|
18
|
-
return this.list().filter(
|
|
18
|
+
return this.list().filter(
|
|
19
|
+
(c) => (c.requirements ?? []).some((r) => r.semanticType === semanticType) || (c.provides ?? []).some((p) => p.semanticType === semanticType)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
findProviders(semanticType) {
|
|
23
|
+
return this.list().filter(
|
|
24
|
+
(c) => (c.provides ?? []).some((p) => p.semanticType === semanticType)
|
|
25
|
+
);
|
|
19
26
|
}
|
|
20
27
|
};
|
|
21
28
|
|
|
@@ -34,6 +41,43 @@ var ContextResolver = class {
|
|
|
34
41
|
};
|
|
35
42
|
|
|
36
43
|
// src/resolution.ts
|
|
44
|
+
var CapabilityRequirementSource = class {
|
|
45
|
+
constructor(registry, executor) {
|
|
46
|
+
this.registry = registry;
|
|
47
|
+
this.executor = executor;
|
|
48
|
+
}
|
|
49
|
+
registry;
|
|
50
|
+
executor;
|
|
51
|
+
name = "capability-execution";
|
|
52
|
+
async canResolve(requirement) {
|
|
53
|
+
return this.registry.findProviders(requirement.semanticType).length > 0;
|
|
54
|
+
}
|
|
55
|
+
async resolve(requirement, context) {
|
|
56
|
+
const candidates = this.registry.findProviders(requirement.semanticType);
|
|
57
|
+
if (candidates.length === 0) throw new Error(`No capability provides ${requirement.semanticType}`);
|
|
58
|
+
return this.executeProvider(candidates[0], context, /* @__PURE__ */ new Set([candidates[0].id]));
|
|
59
|
+
}
|
|
60
|
+
async executeProvider(capability, context, visiting) {
|
|
61
|
+
const input = {};
|
|
62
|
+
for (const template of capability.requirements ?? []) {
|
|
63
|
+
if (!template.required) continue;
|
|
64
|
+
const existing = context.task.requirements.find((r) => r.semanticType === template.semanticType && r.value !== void 0);
|
|
65
|
+
if (existing) {
|
|
66
|
+
input[template.sourceField ?? template.id] = existing.value;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const providers = this.registry.findProviders(template.semanticType).filter((candidate) => !visiting.has(candidate.id));
|
|
70
|
+
if (!providers.length)
|
|
71
|
+
throw new Error(`CAPABILITY_REQUIRES_EXECUTION:${capability.id}:${template.semanticType}`);
|
|
72
|
+
const provider = providers[0];
|
|
73
|
+
visiting.add(provider.id);
|
|
74
|
+
const value = await this.executeProvider(provider, context, visiting);
|
|
75
|
+
input[template.sourceField ?? template.id] = value;
|
|
76
|
+
visiting.delete(provider.id);
|
|
77
|
+
}
|
|
78
|
+
return this.executor.execute(capability, input, context);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
37
81
|
var RequirementResolver = class {
|
|
38
82
|
constructor(registry, sources = []) {
|
|
39
83
|
this.registry = registry;
|
|
@@ -42,14 +86,17 @@ var RequirementResolver = class {
|
|
|
42
86
|
registry;
|
|
43
87
|
sources;
|
|
44
88
|
async resolve(requirement, context) {
|
|
89
|
+
if (requirement.value !== void 0)
|
|
90
|
+
return { resolved: true, value: requirement.value, source: "task-context" };
|
|
45
91
|
for (const source of this.sources) {
|
|
46
92
|
if (await source.canResolve(requirement, context))
|
|
47
93
|
return { resolved: true, value: await source.resolve(requirement, context), source: source.name };
|
|
48
94
|
}
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
return { resolved: false, reason: "CAPABILITY_REQUIRES_EXECUTION", source: candidates[0].id };
|
|
95
|
+
const providers = this.registry.findProviders(requirement.semanticType);
|
|
96
|
+
if (providers.length) return { resolved: false, reason: "CAPABILITY_REQUIRES_EXECUTION", source: providers[0].id, capabilityId: providers[0].id };
|
|
97
|
+
const candidates = this.registry.list().filter((capability) => capability.inputSchema?.properties?.[requirement.sourceField ?? ""] !== void 0);
|
|
98
|
+
if (candidates.length) return { resolved: false, reason: "CAPABILITY_REQUIRES_EXECUTION", source: candidates[0].id, capabilityId: candidates[0].id };
|
|
99
|
+
return { resolved: false, reason: "NO_INTERNAL_RESOLUTION" };
|
|
53
100
|
}
|
|
54
101
|
};
|
|
55
102
|
|
|
@@ -73,9 +120,9 @@ var TaskRuntime = class {
|
|
|
73
120
|
}
|
|
74
121
|
events;
|
|
75
122
|
store;
|
|
76
|
-
create(request, parentTaskId, contextId
|
|
123
|
+
create(request, parentTaskId, contextId) {
|
|
77
124
|
const id = crypto.randomUUID();
|
|
78
|
-
const context = { taskId: id, parentTaskId, request, requirements: [], artifacts: [], contextId };
|
|
125
|
+
const context = { taskId: id, parentTaskId, request, requirements: [], artifacts: [], contextId: contextId ?? crypto.randomUUID() };
|
|
79
126
|
const task = { id, status: "submitted", request, context };
|
|
80
127
|
this.store.set(task);
|
|
81
128
|
this.events?.emit({ type: "task.created", task });
|
|
@@ -84,6 +131,9 @@ var TaskRuntime = class {
|
|
|
84
131
|
get(id) {
|
|
85
132
|
return this.store.get(id);
|
|
86
133
|
}
|
|
134
|
+
list() {
|
|
135
|
+
return this.store.list();
|
|
136
|
+
}
|
|
87
137
|
transition(id, status) {
|
|
88
138
|
const task = this.mustGet(id);
|
|
89
139
|
task.status = status;
|
|
@@ -93,7 +143,9 @@ var TaskRuntime = class {
|
|
|
93
143
|
}
|
|
94
144
|
addRequirement(id, requirement) {
|
|
95
145
|
const task = this.mustGet(id);
|
|
96
|
-
task.context.requirements.
|
|
146
|
+
const existing = task.context.requirements.find((r) => r.id === requirement.id);
|
|
147
|
+
if (existing) Object.assign(existing, requirement);
|
|
148
|
+
else task.context.requirements.push(requirement);
|
|
97
149
|
task.status = "input-required";
|
|
98
150
|
this.store.set(task);
|
|
99
151
|
this.events?.emit({ type: "task.requirement", task });
|
|
@@ -193,13 +245,253 @@ var CapabilityExecutionRuntime = class {
|
|
|
193
245
|
return { artifact: { id: crypto.randomUUID(), type: capability.outputSchema?.type ?? "application/json", value, producer: capability.id, taskId: context.task.taskId, provenance: { capabilityId: capability.id } } };
|
|
194
246
|
}
|
|
195
247
|
};
|
|
248
|
+
|
|
249
|
+
// src/orchestrator.ts
|
|
250
|
+
var SemanticOrchestrator = class {
|
|
251
|
+
constructor(capabilities, tasks, requirements, planner, executor, authorization) {
|
|
252
|
+
this.capabilities = capabilities;
|
|
253
|
+
this.tasks = tasks;
|
|
254
|
+
this.requirements = requirements;
|
|
255
|
+
this.planner = planner;
|
|
256
|
+
this.executor = executor;
|
|
257
|
+
this.authorization = authorization;
|
|
258
|
+
}
|
|
259
|
+
capabilities;
|
|
260
|
+
tasks;
|
|
261
|
+
requirements;
|
|
262
|
+
planner;
|
|
263
|
+
executor;
|
|
264
|
+
authorization;
|
|
265
|
+
graphs = new TaskGraphRuntime();
|
|
266
|
+
async run(task, context) {
|
|
267
|
+
this.tasks.transition(task.id, "working");
|
|
268
|
+
try {
|
|
269
|
+
const plan = await this.planner.plan(task.request, context);
|
|
270
|
+
task.context.intent = plan.intent;
|
|
271
|
+
if (plan.requirements?.length) for (const requirement of plan.requirements) {
|
|
272
|
+
const existing = task.context.requirements.find((r) => r.id === requirement.id);
|
|
273
|
+
if (existing) Object.assign(existing, { ...requirement, value: existing.value });
|
|
274
|
+
else task.context.requirements.push(requirement);
|
|
275
|
+
}
|
|
276
|
+
for (const requirement of task.context.requirements) {
|
|
277
|
+
if (!requirement.required || requirement.value !== void 0) continue;
|
|
278
|
+
const resolved = await this.requirements.resolve(requirement, context);
|
|
279
|
+
if (resolved.resolved) {
|
|
280
|
+
requirement.value = resolved.value;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
this.tasks.addRequirement(task.id, requirement);
|
|
284
|
+
return { status: "input-required", task: this.tasks.get(task.id), requirements: [requirement] };
|
|
285
|
+
}
|
|
286
|
+
const graph = this.graphs.create(task.id, plan.nodes);
|
|
287
|
+
const outputs = [];
|
|
288
|
+
while (true) {
|
|
289
|
+
const ready = this.graphs.ready(graph.id);
|
|
290
|
+
if (ready.length === 0) break;
|
|
291
|
+
await Promise.all(ready.map(async (node) => {
|
|
292
|
+
const capability = this.capabilities.get(node.capabilityId);
|
|
293
|
+
if (!capability) throw new Error(`Unknown capability: ${node.capabilityId}`);
|
|
294
|
+
const input = this.resolveInput(node.input, task.context.requirements);
|
|
295
|
+
const executionResult = this.authorization ? await new CapabilityExecutionRuntime(this.authorization).execute(capability, input, context, this.executor) : await new CapabilityExecutionRuntime().execute(capability, input, context, this.executor);
|
|
296
|
+
this.tasks.addArtifact(task.id, executionResult.artifact);
|
|
297
|
+
outputs.push(executionResult.artifact.value);
|
|
298
|
+
this.graphs.transition(graph.id, node.id, "completed");
|
|
299
|
+
}));
|
|
300
|
+
}
|
|
301
|
+
const unfinished = graph.nodes.some((n) => n.status !== "completed");
|
|
302
|
+
if (unfinished) throw new Error("TASK_GRAPH_STALLED");
|
|
303
|
+
task.result = outputs.length === 1 ? outputs[0] : outputs;
|
|
304
|
+
this.tasks.transition(task.id, "completed");
|
|
305
|
+
return { status: "completed", task: this.tasks.get(task.id), output: outputs };
|
|
306
|
+
} catch (error) {
|
|
307
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
308
|
+
task.error = message;
|
|
309
|
+
this.tasks.transition(task.id, "failed");
|
|
310
|
+
return { status: "failed", task: this.tasks.get(task.id), error: message };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
resolveInput(input, requirements) {
|
|
314
|
+
if (!input || typeof input !== "object") return input;
|
|
315
|
+
const values = new Map(requirements.map((r) => [r.id, r.value]));
|
|
316
|
+
const visit = (value) => {
|
|
317
|
+
if (typeof value === "string" && value.startsWith("$requirement:"))
|
|
318
|
+
return values.get(value.slice("$requirement:".length));
|
|
319
|
+
if (Array.isArray(value)) return value.map(visit);
|
|
320
|
+
if (value && typeof value === "object")
|
|
321
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, visit(v)]));
|
|
322
|
+
return value;
|
|
323
|
+
};
|
|
324
|
+
return visit(input);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// src/conversation.ts
|
|
329
|
+
var MemoryConversationStore = class {
|
|
330
|
+
items = /* @__PURE__ */ new Map();
|
|
331
|
+
get(id) {
|
|
332
|
+
return this.items.get(id);
|
|
333
|
+
}
|
|
334
|
+
set(conversation) {
|
|
335
|
+
this.items.set(conversation.id, conversation);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
var ConversationRuntime = class {
|
|
339
|
+
constructor(options) {
|
|
340
|
+
this.options = options;
|
|
341
|
+
this.store = options.store ?? new MemoryConversationStore();
|
|
342
|
+
}
|
|
343
|
+
options;
|
|
344
|
+
store;
|
|
345
|
+
async send(input, conversationId, taskId) {
|
|
346
|
+
const conversation = this.getOrCreate(conversationId);
|
|
347
|
+
let task = taskId ? this.options.tasks.get(taskId) : void 0;
|
|
348
|
+
if (!task && conversation.taskIds.length > 0) {
|
|
349
|
+
const lastTaskId = conversation.taskIds[conversation.taskIds.length - 1];
|
|
350
|
+
const candidate = this.options.tasks.get(lastTaskId);
|
|
351
|
+
if (candidate && candidate.status === "input-required") task = candidate;
|
|
352
|
+
}
|
|
353
|
+
const activeTask = task ?? this.options.tasks.create(input, void 0, conversation.id);
|
|
354
|
+
if (!task) conversation.taskIds.push(activeTask.id);
|
|
355
|
+
conversation.messages.push({
|
|
356
|
+
id: crypto.randomUUID(),
|
|
357
|
+
role: "user",
|
|
358
|
+
content: input,
|
|
359
|
+
taskId: activeTask.id,
|
|
360
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
361
|
+
});
|
|
362
|
+
this.store.set(conversation);
|
|
363
|
+
const context = await this.options.buildContext(activeTask.id, conversation.id);
|
|
364
|
+
if (task && activeTask.status === "input-required") {
|
|
365
|
+
const requirement = activeTask.context.requirements.find((r) => r.required && r.value === void 0);
|
|
366
|
+
if (requirement) {
|
|
367
|
+
requirement.value = await this.options.inputResolver.resolve(input, requirement, context);
|
|
368
|
+
activeTask.status = "submitted";
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
const result = await this.options.orchestrator.run(activeTask, context);
|
|
372
|
+
conversation.messages.push({
|
|
373
|
+
id: crypto.randomUUID(),
|
|
374
|
+
role: "agent",
|
|
375
|
+
content: this.describe(result),
|
|
376
|
+
taskId: activeTask.id,
|
|
377
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
378
|
+
});
|
|
379
|
+
this.store.set(conversation);
|
|
380
|
+
return result;
|
|
381
|
+
}
|
|
382
|
+
get(id) {
|
|
383
|
+
return this.store.get(id);
|
|
384
|
+
}
|
|
385
|
+
getOrCreate(id) {
|
|
386
|
+
if (id) {
|
|
387
|
+
const existing = this.store.get(id);
|
|
388
|
+
if (existing) return existing;
|
|
389
|
+
}
|
|
390
|
+
const conversation = { id: id ?? crypto.randomUUID(), messages: [], taskIds: [] };
|
|
391
|
+
this.store.set(conversation);
|
|
392
|
+
return conversation;
|
|
393
|
+
}
|
|
394
|
+
describe(result) {
|
|
395
|
+
if (result.status === "completed") return "Task completed.";
|
|
396
|
+
if (result.status === "input-required")
|
|
397
|
+
return result.requirements.map((r) => r.description).join(" ");
|
|
398
|
+
return `Task failed: ${result.error}`;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
// src/workspaceStore.ts
|
|
403
|
+
function text(value) {
|
|
404
|
+
return typeof value === "string" ? value : Buffer.from(value).toString("utf8");
|
|
405
|
+
}
|
|
406
|
+
function safe(id) {
|
|
407
|
+
return id.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
408
|
+
}
|
|
409
|
+
var WorkspaceTaskStore = class {
|
|
410
|
+
constructor(workspace, workspaceId, root = "SEMANTIC/tasks") {
|
|
411
|
+
this.workspace = workspace;
|
|
412
|
+
this.workspaceId = workspaceId;
|
|
413
|
+
this.root = root;
|
|
414
|
+
}
|
|
415
|
+
workspace;
|
|
416
|
+
workspaceId;
|
|
417
|
+
root;
|
|
418
|
+
items = /* @__PURE__ */ new Map();
|
|
419
|
+
async hydrate() {
|
|
420
|
+
const entries = await this.workspace.listFiles(this.workspaceId, this.root);
|
|
421
|
+
for (const entry of entries) {
|
|
422
|
+
if (entry.isFolder || !entry.name.endsWith(".json")) continue;
|
|
423
|
+
try {
|
|
424
|
+
const task = JSON.parse(text(await this.workspace.readFile(this.workspaceId, entry.path)));
|
|
425
|
+
this.items.set(task.id, task);
|
|
426
|
+
} catch {
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return this.list();
|
|
430
|
+
}
|
|
431
|
+
get(id) {
|
|
432
|
+
return this.items.get(id);
|
|
433
|
+
}
|
|
434
|
+
set(task) {
|
|
435
|
+
this.items.set(task.id, task);
|
|
436
|
+
void this.workspace.writeFile(this.workspaceId, `${this.root}/${safe(task.id)}.json`, JSON.stringify(task, null, 2));
|
|
437
|
+
}
|
|
438
|
+
list() {
|
|
439
|
+
return [...this.items.values()];
|
|
440
|
+
}
|
|
441
|
+
async delete(id) {
|
|
442
|
+
this.items.delete(id);
|
|
443
|
+
await this.workspace.deleteFile(this.workspaceId, `${this.root}/${safe(id)}.json`);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
var WorkspaceConversationStore = class {
|
|
447
|
+
constructor(workspace, workspaceId, root = "SEMANTIC/conversations") {
|
|
448
|
+
this.workspace = workspace;
|
|
449
|
+
this.workspaceId = workspaceId;
|
|
450
|
+
this.root = root;
|
|
451
|
+
}
|
|
452
|
+
workspace;
|
|
453
|
+
workspaceId;
|
|
454
|
+
root;
|
|
455
|
+
items = /* @__PURE__ */ new Map();
|
|
456
|
+
async hydrate() {
|
|
457
|
+
const entries = await this.workspace.listFiles(this.workspaceId, this.root);
|
|
458
|
+
for (const entry of entries) {
|
|
459
|
+
if (entry.isFolder || !entry.name.endsWith(".json")) continue;
|
|
460
|
+
try {
|
|
461
|
+
const conversation = JSON.parse(text(await this.workspace.readFile(this.workspaceId, entry.path)));
|
|
462
|
+
this.items.set(conversation.id, conversation);
|
|
463
|
+
} catch {
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return this.list();
|
|
467
|
+
}
|
|
468
|
+
get(id) {
|
|
469
|
+
return this.items.get(id);
|
|
470
|
+
}
|
|
471
|
+
set(conversation) {
|
|
472
|
+
this.items.set(conversation.id, conversation);
|
|
473
|
+
void this.workspace.writeFile(this.workspaceId, `${this.root}/${safe(conversation.id)}.json`, JSON.stringify(conversation, null, 2));
|
|
474
|
+
}
|
|
475
|
+
list() {
|
|
476
|
+
return [...this.items.values()];
|
|
477
|
+
}
|
|
478
|
+
async delete(id) {
|
|
479
|
+
this.items.delete(id);
|
|
480
|
+
await this.workspace.deleteFile(this.workspaceId, `${this.root}/${safe(id)}.json`);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
196
483
|
export {
|
|
197
484
|
AgentRegistry,
|
|
198
485
|
CapabilityExecutionRuntime,
|
|
199
486
|
CapabilityRegistry,
|
|
487
|
+
CapabilityRequirementSource,
|
|
200
488
|
ContextResolver,
|
|
489
|
+
ConversationRuntime,
|
|
201
490
|
RequirementResolver,
|
|
491
|
+
SemanticOrchestrator,
|
|
202
492
|
TaskGraphRuntime,
|
|
203
493
|
TaskRuntime,
|
|
494
|
+
WorkspaceConversationStore,
|
|
495
|
+
WorkspaceTaskStore,
|
|
204
496
|
createSemanticRequest
|
|
205
497
|
};
|
|
@@ -454,6 +454,76 @@ declare const krnlSystemDbClientServiceFacade: {
|
|
|
454
454
|
execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
|
|
455
455
|
};
|
|
456
456
|
|
|
457
|
+
interface GitHubVcsProviderOptions {
|
|
458
|
+
token: string;
|
|
459
|
+
apiBaseUrl?: string;
|
|
460
|
+
}
|
|
461
|
+
interface GitHubFile {
|
|
462
|
+
path: string;
|
|
463
|
+
content: string;
|
|
464
|
+
sha?: string;
|
|
465
|
+
}
|
|
466
|
+
declare class GitHubVcsProvider {
|
|
467
|
+
private readonly options;
|
|
468
|
+
readonly id = "github";
|
|
469
|
+
private readonly apiBaseUrl;
|
|
470
|
+
constructor(options: GitHubVcsProviderOptions);
|
|
471
|
+
private request;
|
|
472
|
+
getRepository(repository: string): Promise<unknown>;
|
|
473
|
+
createBranch(repository: string, branch: string, sha: string): Promise<unknown>;
|
|
474
|
+
getFile(repository: string, path: string, ref?: string): Promise<GitHubFile>;
|
|
475
|
+
writeFile(repository: string, file: GitHubFile, message: string, branch: string): Promise<unknown>;
|
|
476
|
+
createPullRequest(repository: string, title: string, body: string, head: string, base?: string): Promise<unknown>;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
interface LocalExecutionRequest {
|
|
480
|
+
command: string;
|
|
481
|
+
cwd?: string;
|
|
482
|
+
environment?: Readonly<Record<string, string>>;
|
|
483
|
+
timeoutMs?: number;
|
|
484
|
+
}
|
|
485
|
+
interface LocalExecutionResult {
|
|
486
|
+
executionId: string;
|
|
487
|
+
status: "succeeded" | "failed" | "timed-out";
|
|
488
|
+
exitCode?: number;
|
|
489
|
+
stdout: string;
|
|
490
|
+
stderr: string;
|
|
491
|
+
}
|
|
492
|
+
declare class LocalExecutionProvider {
|
|
493
|
+
readonly id = "local";
|
|
494
|
+
execute(request: LocalExecutionRequest): Promise<LocalExecutionResult>;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
interface Workspace {
|
|
498
|
+
id: string;
|
|
499
|
+
root: string;
|
|
500
|
+
}
|
|
501
|
+
declare class LocalWorkspaceProvider {
|
|
502
|
+
readonly id = "local-workspace";
|
|
503
|
+
private readonly workspaces;
|
|
504
|
+
create(prefix?: string): Promise<Workspace>;
|
|
505
|
+
get(workspaceId: string): Workspace;
|
|
506
|
+
destroy(workspaceId: string): Promise<void>;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
interface VerificationStep {
|
|
510
|
+
id: string;
|
|
511
|
+
name: string;
|
|
512
|
+
command: string;
|
|
513
|
+
cwd?: string;
|
|
514
|
+
}
|
|
515
|
+
interface VerificationReport {
|
|
516
|
+
id: string;
|
|
517
|
+
status: "passed" | "failed";
|
|
518
|
+
checks: readonly LocalExecutionResult[];
|
|
519
|
+
}
|
|
520
|
+
declare class CommandVerificationProvider {
|
|
521
|
+
private readonly execution;
|
|
522
|
+
readonly id = "command-verification";
|
|
523
|
+
constructor(execution?: LocalExecutionProvider);
|
|
524
|
+
verify(steps: readonly VerificationStep[]): Promise<VerificationReport>;
|
|
525
|
+
}
|
|
526
|
+
|
|
457
527
|
interface ServiceFacade<TState extends Record<string, unknown> = Record<string, unknown>, TEvents extends Record<string, unknown> = Record<string, unknown>> {
|
|
458
528
|
readonly id: string;
|
|
459
529
|
readonly name: string;
|
|
@@ -510,4 +580,4 @@ declare const krnlServiceDDefinition: ServiceDefinition<Record<string, unknown>,
|
|
|
510
580
|
declare const krnlServiceDFacade: ServiceFacade<Record<string, unknown>, Record<string, unknown>>;
|
|
511
581
|
declare const krnlExposeServiceD: typeof exposeServiceD;
|
|
512
582
|
|
|
513
|
-
export { AuthClientServiceDefinition, AuthClientServiceFacade, type AuthListener, AuthService, AuthServiceUISchema, CLEAN_DATABASE_CLUSTER, type CounterState, DEFAULT_CONNECTIONS, type EcosystemServiceCategory, type IAuthStore, type MathInput, MonacoIdeServiceDefinition, MonacoIdeServiceFacade, type ProtocolExposureHandle, STORAGE_KEY_CONNECTIONS, ServiceADefinition, ServiceAFacade, ServiceBDefinition, ServiceBFacade, ServiceCDefinition, ServiceCFacade, ServiceDDefinition, ServiceDFacade, type ServiceFacade, type SrklAccount, SrklAccountClient, type SrklAccountClientOptions, type SrklAccountManifest, type SrklAccountSyncResult, StorageClientServiceDefinition, StorageClientServiceFacade, StorageService, StorageServiceUISchema, SystemDbClientServiceDefinition, SystemDbClientServiceFacade, SystemDbService, SystemDbServiceUISchema, type SystemEnvironmentStatus, type SystemTelemetry, type TelemetryEvents, UIAuthoringServiceDefinition, UIAuthoringServiceFacade, authService, clearSession, createMonacoIdeService, createServiceB, createServiceC, createSrklAccountClient, createUIAuthoringService, createWorkspace, deleteWorkspace, exposeServiceD, fetchWorkspaces, krnlAuthClientServiceDefinition, krnlAuthClientServiceFacade, krnlCreateServiceB, krnlCreateServiceC, krnlExposeServiceD, krnlServiceADefinition, krnlServiceAFacade, krnlServiceBDefinition, krnlServiceBFacade, krnlServiceCDefinition, krnlServiceCFacade, krnlServiceDDefinition, krnlServiceDFacade, krnlStorageClientServiceDefinition, krnlStorageClientServiceFacade, krnlSystemDbClientServiceDefinition, krnlSystemDbClientServiceFacade, loadDatabase, loginAdmin, loginUser, mergeSrklAccounts, persistDatabase, register, restoreSession, setActiveWorkspace, setSession, storageService, systemDbService, updateWorkspace, verifyPassword };
|
|
583
|
+
export { AuthClientServiceDefinition, AuthClientServiceFacade, type AuthListener, AuthService, AuthServiceUISchema, CLEAN_DATABASE_CLUSTER, CommandVerificationProvider, type CounterState, DEFAULT_CONNECTIONS, type EcosystemServiceCategory, type GitHubFile, GitHubVcsProvider, type GitHubVcsProviderOptions, type IAuthStore, LocalExecutionProvider, type LocalExecutionRequest, type LocalExecutionResult, LocalWorkspaceProvider, type MathInput, MonacoIdeServiceDefinition, MonacoIdeServiceFacade, type ProtocolExposureHandle, STORAGE_KEY_CONNECTIONS, ServiceADefinition, ServiceAFacade, ServiceBDefinition, ServiceBFacade, ServiceCDefinition, ServiceCFacade, ServiceDDefinition, ServiceDFacade, type ServiceFacade, type SrklAccount, SrklAccountClient, type SrklAccountClientOptions, type SrklAccountManifest, type SrklAccountSyncResult, StorageClientServiceDefinition, StorageClientServiceFacade, StorageService, StorageServiceUISchema, SystemDbClientServiceDefinition, SystemDbClientServiceFacade, SystemDbService, SystemDbServiceUISchema, type SystemEnvironmentStatus, type SystemTelemetry, type TelemetryEvents, UIAuthoringServiceDefinition, UIAuthoringServiceFacade, type VerificationReport, type VerificationStep, type Workspace, authService, clearSession, createMonacoIdeService, createServiceB, createServiceC, createSrklAccountClient, createUIAuthoringService, createWorkspace, deleteWorkspace, exposeServiceD, fetchWorkspaces, krnlAuthClientServiceDefinition, krnlAuthClientServiceFacade, krnlCreateServiceB, krnlCreateServiceC, krnlExposeServiceD, krnlServiceADefinition, krnlServiceAFacade, krnlServiceBDefinition, krnlServiceBFacade, krnlServiceCDefinition, krnlServiceCFacade, krnlServiceDDefinition, krnlServiceDFacade, krnlStorageClientServiceDefinition, krnlStorageClientServiceFacade, krnlSystemDbClientServiceDefinition, krnlSystemDbClientServiceFacade, loadDatabase, loginAdmin, loginUser, mergeSrklAccounts, persistDatabase, register, restoreSession, setActiveWorkspace, setSession, storageService, systemDbService, updateWorkspace, verifyPassword };
|
|
@@ -2787,6 +2787,127 @@ var krnlStorageClientServiceFacade = StorageClientServiceFacade;
|
|
|
2787
2787
|
var krnlSystemDbClientServiceDefinition = SystemDbClientServiceDefinition;
|
|
2788
2788
|
var krnlSystemDbClientServiceFacade = SystemDbClientServiceFacade;
|
|
2789
2789
|
|
|
2790
|
+
// src/engineering/github-vcs-provider.ts
|
|
2791
|
+
var GitHubVcsProvider = class {
|
|
2792
|
+
constructor(options) {
|
|
2793
|
+
this.options = options;
|
|
2794
|
+
this.apiBaseUrl = options.apiBaseUrl ?? "https://api.github.com";
|
|
2795
|
+
}
|
|
2796
|
+
options;
|
|
2797
|
+
id = "github";
|
|
2798
|
+
apiBaseUrl;
|
|
2799
|
+
async request(path2, init = {}) {
|
|
2800
|
+
const response = await fetch(this.apiBaseUrl + path2, {
|
|
2801
|
+
...init,
|
|
2802
|
+
headers: {
|
|
2803
|
+
accept: "application/vnd.github+json",
|
|
2804
|
+
authorization: `Bearer ${this.options.token}`,
|
|
2805
|
+
"x-github-api-version": "2022-11-28",
|
|
2806
|
+
"content-type": "application/json",
|
|
2807
|
+
...init.headers ?? {}
|
|
2808
|
+
}
|
|
2809
|
+
});
|
|
2810
|
+
if (!response.ok) throw new Error(`GitHub API ${response.status}: ${await response.text()}`);
|
|
2811
|
+
return response.status === 204 ? void 0 : await response.json();
|
|
2812
|
+
}
|
|
2813
|
+
getRepository(repository) {
|
|
2814
|
+
return this.request(`/repos/${repository}`);
|
|
2815
|
+
}
|
|
2816
|
+
createBranch(repository, branch, sha) {
|
|
2817
|
+
return this.request(`/repos/${repository}/git/refs`, { method: "POST", body: JSON.stringify({ ref: `refs/heads/${branch}`, sha }) });
|
|
2818
|
+
}
|
|
2819
|
+
getFile(repository, path2, ref) {
|
|
2820
|
+
const query = ref ? `?ref=${encodeURIComponent(ref)}` : "";
|
|
2821
|
+
return this.request(`/repos/${repository}/contents/${path2}${query}`);
|
|
2822
|
+
}
|
|
2823
|
+
writeFile(repository, file, message, branch) {
|
|
2824
|
+
return this.request(`/repos/${repository}/contents/${file.path}`, { method: "PUT", body: JSON.stringify({ message, content: Buffer.from(file.content, "utf8").toString("base64"), sha: file.sha, branch }) });
|
|
2825
|
+
}
|
|
2826
|
+
createPullRequest(repository, title, body, head, base = "main") {
|
|
2827
|
+
return this.request(`/repos/${repository}/pulls`, { method: "POST", body: JSON.stringify({ title, body, head, base }) });
|
|
2828
|
+
}
|
|
2829
|
+
};
|
|
2830
|
+
|
|
2831
|
+
// src/engineering/local-execution-provider.ts
|
|
2832
|
+
import { spawn } from "child_process";
|
|
2833
|
+
var LocalExecutionProvider = class {
|
|
2834
|
+
id = "local";
|
|
2835
|
+
async execute(request) {
|
|
2836
|
+
const executionId = crypto.randomUUID();
|
|
2837
|
+
return new Promise((resolve) => {
|
|
2838
|
+
const child = spawn("sh", ["-lc", request.command], {
|
|
2839
|
+
cwd: request.cwd,
|
|
2840
|
+
env: { ...process.env, ...request.environment ?? {} }
|
|
2841
|
+
});
|
|
2842
|
+
let stdout = "";
|
|
2843
|
+
let stderr = "";
|
|
2844
|
+
let settled = false;
|
|
2845
|
+
let timer;
|
|
2846
|
+
const finish = (result) => {
|
|
2847
|
+
if (settled) return;
|
|
2848
|
+
settled = true;
|
|
2849
|
+
if (timer) clearTimeout(timer);
|
|
2850
|
+
resolve(result);
|
|
2851
|
+
};
|
|
2852
|
+
child.stdout.on("data", (chunk2) => {
|
|
2853
|
+
stdout += chunk2.toString();
|
|
2854
|
+
});
|
|
2855
|
+
child.stderr.on("data", (chunk2) => {
|
|
2856
|
+
stderr += chunk2.toString();
|
|
2857
|
+
});
|
|
2858
|
+
child.on("error", (error) => finish({ executionId, status: "failed", exitCode: void 0, stdout, stderr: stderr + error.message }));
|
|
2859
|
+
child.on("close", (code) => finish({ executionId, status: code === 0 ? "succeeded" : "failed", exitCode: code ?? void 0, stdout, stderr }));
|
|
2860
|
+
if (request.timeoutMs && request.timeoutMs > 0) timer = setTimeout(() => {
|
|
2861
|
+
child.kill("SIGTERM");
|
|
2862
|
+
finish({ executionId, status: "timed-out", stdout, stderr });
|
|
2863
|
+
}, request.timeoutMs);
|
|
2864
|
+
});
|
|
2865
|
+
}
|
|
2866
|
+
};
|
|
2867
|
+
|
|
2868
|
+
// src/engineering/workspace-provider.ts
|
|
2869
|
+
import { mkdtemp, rm } from "fs/promises";
|
|
2870
|
+
import { tmpdir } from "os";
|
|
2871
|
+
import { join } from "path";
|
|
2872
|
+
var LocalWorkspaceProvider = class {
|
|
2873
|
+
id = "local-workspace";
|
|
2874
|
+
workspaces = /* @__PURE__ */ new Map();
|
|
2875
|
+
async create(prefix = "krusbl-") {
|
|
2876
|
+
const root = await mkdtemp(join(tmpdir(), prefix));
|
|
2877
|
+
const workspace = { id: crypto.randomUUID(), root };
|
|
2878
|
+
this.workspaces.set(workspace.id, workspace);
|
|
2879
|
+
return workspace;
|
|
2880
|
+
}
|
|
2881
|
+
get(workspaceId) {
|
|
2882
|
+
const workspace = this.workspaces.get(workspaceId);
|
|
2883
|
+
if (!workspace) throw new Error(`Unknown workspace: ${workspaceId}`);
|
|
2884
|
+
return workspace;
|
|
2885
|
+
}
|
|
2886
|
+
async destroy(workspaceId) {
|
|
2887
|
+
const workspace = this.get(workspaceId);
|
|
2888
|
+
await rm(workspace.root, { recursive: true, force: true });
|
|
2889
|
+
this.workspaces.delete(workspaceId);
|
|
2890
|
+
}
|
|
2891
|
+
};
|
|
2892
|
+
|
|
2893
|
+
// src/engineering/verification-provider.ts
|
|
2894
|
+
var CommandVerificationProvider = class {
|
|
2895
|
+
constructor(execution = new LocalExecutionProvider()) {
|
|
2896
|
+
this.execution = execution;
|
|
2897
|
+
}
|
|
2898
|
+
execution;
|
|
2899
|
+
id = "command-verification";
|
|
2900
|
+
async verify(steps) {
|
|
2901
|
+
const checks = [];
|
|
2902
|
+
for (const step of steps) {
|
|
2903
|
+
const result = await this.execution.execute({ command: step.command, cwd: step.cwd });
|
|
2904
|
+
checks.push(result);
|
|
2905
|
+
if (result.status !== "succeeded") return { id: crypto.randomUUID(), status: "failed", checks };
|
|
2906
|
+
}
|
|
2907
|
+
return { id: crypto.randomUUID(), status: "passed", checks };
|
|
2908
|
+
}
|
|
2909
|
+
};
|
|
2910
|
+
|
|
2790
2911
|
// src/index.ts
|
|
2791
2912
|
var ServiceADefinition = createServiceDefinition({
|
|
2792
2913
|
id: "kloks.service.a",
|
|
@@ -3012,7 +3133,11 @@ export {
|
|
|
3012
3133
|
AuthService,
|
|
3013
3134
|
AuthServiceUISchema,
|
|
3014
3135
|
CLEAN_DATABASE_CLUSTER,
|
|
3136
|
+
CommandVerificationProvider,
|
|
3015
3137
|
DEFAULT_CONNECTIONS,
|
|
3138
|
+
GitHubVcsProvider,
|
|
3139
|
+
LocalExecutionProvider,
|
|
3140
|
+
LocalWorkspaceProvider,
|
|
3016
3141
|
MonacoIdeServiceDefinition,
|
|
3017
3142
|
MonacoIdeServiceFacade,
|
|
3018
3143
|
STORAGE_KEY_CONNECTIONS,
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
aiProviderService
|
|
3
|
+
} from "./chunk-SLR6SIEU.js";
|
|
1
4
|
import {
|
|
2
5
|
modelCatalog,
|
|
3
6
|
modelHealthService
|
|
@@ -5,9 +8,6 @@ import {
|
|
|
5
8
|
import {
|
|
6
9
|
keyStore
|
|
7
10
|
} from "./chunk-P7H6TIEA.js";
|
|
8
|
-
import {
|
|
9
|
-
aiProviderService
|
|
10
|
-
} from "./chunk-SLR6SIEU.js";
|
|
11
11
|
|
|
12
12
|
// src/ai-routing/metricsLogger.ts
|
|
13
13
|
var MetricsLogger = class {
|