pi-harness-runtime 1.1.335 → 1.1.337
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/index.ts +21 -12
- package/package.json +1 -1
- package/packages/a2a-adapter/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/architecture-generator/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-refactor/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/cache-strategy/package.json +1 -1
- package/packages/capability-registry/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/cli-plugin-sdk/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/clipboard-plugin/package.json +1 -1
- package/packages/code-generation/package.json +1 -1
- package/packages/code-review/package.json +1 -1
- package/packages/codex-adapter/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/connection-runtime/dist/index.d.ts +11 -0
- package/packages/connection-runtime/dist/index.js +11 -0
- package/packages/connection-runtime/dist/registry.d.ts +69 -0
- package/packages/connection-runtime/dist/registry.js +117 -0
- package/packages/connection-runtime/dist/supervisor.d.ts +89 -0
- package/packages/connection-runtime/dist/supervisor.js +169 -0
- package/packages/connection-runtime/dist/types.d.ts +70 -0
- package/packages/connection-runtime/dist/types.js +16 -0
- package/packages/connection-runtime/package.json +24 -0
- package/packages/connection-runtime/src/index.ts +12 -0
- package/packages/connection-runtime/src/registry.ts +142 -0
- package/packages/connection-runtime/src/supervisor.ts +224 -0
- package/packages/connection-runtime/src/types.ts +88 -0
- package/packages/context-compiler/package.json +1 -1
- package/packages/context-discovery/package.json +1 -1
- package/packages/context-manager/package.json +1 -1
- package/packages/contracts/dist/approvals.d.ts +273 -0
- package/packages/contracts/dist/approvals.js +93 -0
- package/packages/contracts/dist/base.d.ts +78 -0
- package/packages/contracts/dist/base.js +82 -0
- package/packages/contracts/dist/events.d.ts +99 -0
- package/packages/contracts/dist/events.js +65 -0
- package/packages/contracts/dist/index.d.ts +20 -0
- package/packages/contracts/dist/index.js +20 -0
- package/packages/contracts/dist/jobs.d.ts +234 -0
- package/packages/contracts/dist/jobs.js +79 -0
- package/packages/contracts/dist/notifications.d.ts +317 -0
- package/packages/contracts/dist/notifications.js +85 -0
- package/packages/contracts/dist/projects.d.ts +171 -0
- package/packages/contracts/dist/projects.js +62 -0
- package/packages/contracts/dist/sessions.d.ts +226 -0
- package/packages/contracts/dist/sessions.js +82 -0
- package/packages/contracts/package.json +24 -0
- package/packages/contracts/src/approvals.ts +115 -0
- package/packages/contracts/src/base.ts +126 -0
- package/packages/contracts/src/events.ts +78 -0
- package/packages/contracts/src/index.ts +21 -0
- package/packages/contracts/src/jobs.ts +101 -0
- package/packages/contracts/src/notifications.ts +104 -0
- package/packages/contracts/src/projects.ts +81 -0
- package/packages/contracts/src/sessions.ts +104 -0
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/cost-optimizer/package.json +1 -1
- package/packages/dependency-analyzer/package.json +1 -1
- package/packages/django-plugin/package.json +1 -1
- package/packages/doc-generator/package.json +1 -1
- package/packages/durable-review/package.json +1 -1
- package/packages/e2e-tester/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/evaluation-runner/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-sink/dist/index.d.ts +12 -0
- package/packages/event-sink/dist/index.js +12 -0
- package/packages/event-sink/dist/outbox.d.ts +51 -0
- package/packages/event-sink/dist/outbox.js +88 -0
- package/packages/event-sink/dist/projection.d.ts +41 -0
- package/packages/event-sink/dist/projection.js +62 -0
- package/packages/event-sink/dist/sink.d.ts +81 -0
- package/packages/event-sink/dist/sink.js +106 -0
- package/packages/event-sink/package.json +28 -0
- package/packages/event-sink/src/index.ts +15 -0
- package/packages/event-sink/src/outbox.ts +119 -0
- package/packages/event-sink/src/projection.ts +84 -0
- package/packages/event-sink/src/sink.ts +167 -0
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/feedback-collector/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/framework-detector/package.json +1 -1
- package/packages/framework-plugin-sdk/package.json +1 -1
- package/packages/frappe-plugin/package.json +1 -1
- package/packages/generic-web-plugin/package.json +1 -1
- package/packages/health-monitor/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/knowledge-graph/package.json +1 -1
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/laravel-plugin/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/mcp-adapter/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/milestone-manager/package.json +1 -1
- package/packages/model-registry/package.json +1 -1
- package/packages/nextjs-plugin/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/observability/package.json +1 -1
- package/packages/okf-indexer/package.json +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/permission-mode/dist/checker.d.ts +66 -0
- package/packages/permission-mode/dist/checker.js +64 -0
- package/packages/permission-mode/dist/index.d.ts +12 -0
- package/packages/permission-mode/dist/index.js +11 -0
- package/packages/permission-mode/dist/manager.d.ts +65 -0
- package/packages/permission-mode/dist/manager.js +91 -0
- package/packages/permission-mode/dist/mode.d.ts +31 -0
- package/packages/permission-mode/dist/mode.js +47 -0
- package/packages/permission-mode/package.json +24 -0
- package/packages/permission-mode/src/checker.ts +103 -0
- package/packages/permission-mode/src/index.ts +13 -0
- package/packages/permission-mode/src/manager.ts +154 -0
- package/packages/permission-mode/src/mode.ts +73 -0
- package/packages/privilege-broker/package.json +1 -1
- package/packages/project-analyzer/package.json +1 -1
- package/packages/project-bootstrap/package.json +1 -1
- package/packages/projection-engine/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/prompt-versioning/package.json +1 -1
- package/packages/provider-adapter-sdk/package.json +1 -1
- package/packages/provider-router/package.json +1 -1
- package/packages/provider-selector/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/rate-limiter/package.json +1 -1
- package/packages/react-vite-plugin/package.json +1 -1
- package/packages/relay/dist/client.d.ts +53 -0
- package/packages/relay/dist/client.js +95 -0
- package/packages/relay/dist/index.d.ts +9 -0
- package/packages/relay/dist/index.js +8 -0
- package/packages/relay/dist/server.d.ts +58 -0
- package/packages/relay/dist/server.js +93 -0
- package/packages/relay/dist/types.d.ts +35 -0
- package/packages/relay/dist/types.js +4 -0
- package/packages/relay/package.json +24 -0
- package/packages/relay/src/client.ts +119 -0
- package/packages/relay/src/index.ts +10 -0
- package/packages/relay/src/server.ts +120 -0
- package/packages/relay/src/types.ts +38 -0
- package/packages/release-manager/package.json +1 -1
- package/packages/requirement-compiler/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/scheduler/package.json +1 -1
- package/packages/scheduler-adapter/package.json +1 -1
- package/packages/session/package.json +1 -1
- package/packages/session-api/package.json +1 -1
- package/packages/session-export/package.json +1 -1
- package/packages/shared-context/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skill-registry/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/sprint-planner/package.json +1 -1
- package/packages/subscription-engine/package.json +1 -1
- package/packages/task-compiler/package.json +1 -1
- package/packages/telegram/package.json +1 -1
- package/packages/tencentdb-memory/package.json +1 -1
- package/packages/tencentdb-sync/package.json +1 -1
- package/packages/test-data-generator/package.json +1 -1
- package/packages/test-generator/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/token-optimizer/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/workflow-events/package.json +1 -1
- package/packages/workspace-scanner/package.json +1 -1
- package/packages/worktree/package.json +1 -1
- package/packages/write-review/package.json +1 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Job schemas for pi-harness
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { Timestamp, UUID, NonEmptyString } from './base.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Job status
|
|
10
|
+
*/
|
|
11
|
+
export const JobStatus = z.enum([
|
|
12
|
+
'pending',
|
|
13
|
+
'running',
|
|
14
|
+
'completed',
|
|
15
|
+
'failed',
|
|
16
|
+
'cancelled',
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export type JobStatus = z.infer<typeof JobStatus>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Job priority
|
|
23
|
+
*/
|
|
24
|
+
export const JobPriority = z.enum(['low', 'normal', 'high', 'urgent']);
|
|
25
|
+
|
|
26
|
+
export type JobPriority = z.infer<typeof JobPriority>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Job definition
|
|
30
|
+
*/
|
|
31
|
+
export const Job = z.object({
|
|
32
|
+
id: UUID,
|
|
33
|
+
type: NonEmptyString,
|
|
34
|
+
status: JobStatus,
|
|
35
|
+
priority: JobPriority.default('normal'),
|
|
36
|
+
workspaceId: z.string(),
|
|
37
|
+
sessionId: z.string().optional(),
|
|
38
|
+
requirement: NonEmptyString,
|
|
39
|
+
result: z.unknown().optional(),
|
|
40
|
+
error: z.string().optional(),
|
|
41
|
+
progress: z.number().min(0).max(100).default(0),
|
|
42
|
+
createdAt: Timestamp,
|
|
43
|
+
startedAt: Timestamp.optional(),
|
|
44
|
+
completedAt: Timestamp.optional(),
|
|
45
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export type Job = z.infer<typeof Job>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Job creation input
|
|
52
|
+
*/
|
|
53
|
+
export const JobCreate = z.object({
|
|
54
|
+
type: NonEmptyString,
|
|
55
|
+
priority: JobPriority.default('normal'),
|
|
56
|
+
workspaceId: z.string(),
|
|
57
|
+
sessionId: z.string().optional(),
|
|
58
|
+
requirement: NonEmptyString,
|
|
59
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export type JobCreate = z.infer<typeof JobCreate>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Job update input
|
|
66
|
+
*/
|
|
67
|
+
export const JobUpdate = z.object({
|
|
68
|
+
status: JobStatus.optional(),
|
|
69
|
+
progress: z.number().min(0).max(100).optional(),
|
|
70
|
+
result: z.unknown().optional(),
|
|
71
|
+
error: z.string().optional(),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export type JobUpdate = z.infer<typeof JobUpdate>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Job filter
|
|
78
|
+
*/
|
|
79
|
+
export const JobFilter = z.object({
|
|
80
|
+
workspaceId: z.string().optional(),
|
|
81
|
+
sessionId: z.string().optional(),
|
|
82
|
+
status: z.union([JobStatus, z.array(JobStatus)]).optional(),
|
|
83
|
+
priority: JobPriority.optional(),
|
|
84
|
+
since: Timestamp.optional(),
|
|
85
|
+
until: Timestamp.optional(),
|
|
86
|
+
limit: z.number().int().positive().max(100).default(50),
|
|
87
|
+
cursor: z.string().optional(),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export type JobFilter = z.infer<typeof JobFilter>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Job list response
|
|
94
|
+
*/
|
|
95
|
+
export const JobList = z.object({
|
|
96
|
+
items: z.array(Job),
|
|
97
|
+
nextCursor: z.string().optional(),
|
|
98
|
+
total: z.number().optional(),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export type JobList = z.infer<typeof JobList>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification schemas for pi-harness
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { Timestamp, UUID, NonEmptyString } from './base.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Notification channel
|
|
10
|
+
*/
|
|
11
|
+
export const NotificationChannel = z.enum([
|
|
12
|
+
'telegram',
|
|
13
|
+
'email',
|
|
14
|
+
'webhook',
|
|
15
|
+
'desktop',
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
export type NotificationChannel = z.infer<typeof NotificationChannel>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Notification priority
|
|
22
|
+
*/
|
|
23
|
+
export const NotificationPriority = z.enum(['low', 'normal', 'high', 'urgent']);
|
|
24
|
+
|
|
25
|
+
export type NotificationPriority = z.infer<typeof NotificationPriority>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Notification definition
|
|
29
|
+
*/
|
|
30
|
+
export const Notification = z.object({
|
|
31
|
+
id: UUID,
|
|
32
|
+
event: NonEmptyString,
|
|
33
|
+
channel: NotificationChannel,
|
|
34
|
+
priority: NotificationPriority.default('normal'),
|
|
35
|
+
workspaceId: z.string().optional(),
|
|
36
|
+
sessionId: z.string().optional(),
|
|
37
|
+
jobId: z.string().optional(),
|
|
38
|
+
title: NonEmptyString,
|
|
39
|
+
message: NonEmptyString,
|
|
40
|
+
data: z.record(z.string(), z.unknown()).optional(),
|
|
41
|
+
buttons: z.array(z.object({
|
|
42
|
+
text: NonEmptyString,
|
|
43
|
+
action: NonEmptyString,
|
|
44
|
+
targetId: z.string().optional(),
|
|
45
|
+
url: z.string().url().optional(),
|
|
46
|
+
})).optional(),
|
|
47
|
+
sentAt: Timestamp.optional(),
|
|
48
|
+
readAt: Timestamp.optional(),
|
|
49
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export type Notification = z.infer<typeof Notification>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Notification creation input
|
|
56
|
+
*/
|
|
57
|
+
export const NotificationCreate = z.object({
|
|
58
|
+
event: NonEmptyString,
|
|
59
|
+
channel: NotificationChannel.default('telegram'),
|
|
60
|
+
priority: NotificationPriority.default('normal'),
|
|
61
|
+
workspaceId: z.string().optional(),
|
|
62
|
+
sessionId: z.string().optional(),
|
|
63
|
+
jobId: z.string().optional(),
|
|
64
|
+
title: NonEmptyString,
|
|
65
|
+
message: NonEmptyString,
|
|
66
|
+
data: z.record(z.string(), z.unknown()).optional(),
|
|
67
|
+
buttons: z.array(z.object({
|
|
68
|
+
text: NonEmptyString,
|
|
69
|
+
action: NonEmptyString,
|
|
70
|
+
targetId: z.string().optional(),
|
|
71
|
+
url: z.string().url().optional(),
|
|
72
|
+
})).optional(),
|
|
73
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export type NotificationCreate = z.infer<typeof NotificationCreate>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Notification filter
|
|
80
|
+
*/
|
|
81
|
+
export const NotificationFilter = z.object({
|
|
82
|
+
workspaceId: z.string().optional(),
|
|
83
|
+
sessionId: z.string().optional(),
|
|
84
|
+
jobId: z.string().optional(),
|
|
85
|
+
channel: NotificationChannel.optional(),
|
|
86
|
+
priority: NotificationPriority.optional(),
|
|
87
|
+
since: Timestamp.optional(),
|
|
88
|
+
until: Timestamp.optional(),
|
|
89
|
+
limit: z.number().int().positive().max(100).default(50),
|
|
90
|
+
cursor: z.string().optional(),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export type NotificationFilter = z.infer<typeof NotificationFilter>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Notification list response
|
|
97
|
+
*/
|
|
98
|
+
export const NotificationList = z.object({
|
|
99
|
+
items: z.array(Notification),
|
|
100
|
+
nextCursor: z.string().optional(),
|
|
101
|
+
total: z.number().optional(),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export type NotificationList = z.infer<typeof NotificationList>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project schemas for pi-harness
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { Timestamp, UUID, NonEmptyString } from './base.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Project status
|
|
10
|
+
*/
|
|
11
|
+
export const ProjectStatus = z.enum([
|
|
12
|
+
'active',
|
|
13
|
+
'archived',
|
|
14
|
+
'deleted',
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
export type ProjectStatus = z.infer<typeof ProjectStatus>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Project definition
|
|
21
|
+
*/
|
|
22
|
+
export const Project = z.object({
|
|
23
|
+
id: UUID,
|
|
24
|
+
name: NonEmptyString,
|
|
25
|
+
path: NonEmptyString,
|
|
26
|
+
status: ProjectStatus.default('active'),
|
|
27
|
+
workspaceId: z.string(),
|
|
28
|
+
createdAt: Timestamp,
|
|
29
|
+
updatedAt: Timestamp,
|
|
30
|
+
lastAccessedAt: Timestamp.optional(),
|
|
31
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type Project = z.infer<typeof Project>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Project creation input
|
|
38
|
+
*/
|
|
39
|
+
export const ProjectCreate = z.object({
|
|
40
|
+
name: NonEmptyString,
|
|
41
|
+
path: NonEmptyString,
|
|
42
|
+
workspaceId: z.string(),
|
|
43
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export type ProjectCreate = z.infer<typeof ProjectCreate>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Project update input
|
|
50
|
+
*/
|
|
51
|
+
export const ProjectUpdate = z.object({
|
|
52
|
+
name: NonEmptyString.optional(),
|
|
53
|
+
status: ProjectStatus.optional(),
|
|
54
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export type ProjectUpdate = z.infer<typeof ProjectUpdate>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Project filter
|
|
61
|
+
*/
|
|
62
|
+
export const ProjectFilter = z.object({
|
|
63
|
+
workspaceId: z.string().optional(),
|
|
64
|
+
status: ProjectStatus.optional(),
|
|
65
|
+
search: z.string().optional(),
|
|
66
|
+
limit: z.number().int().positive().max(100).default(50),
|
|
67
|
+
cursor: z.string().optional(),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export type ProjectFilter = z.infer<typeof ProjectFilter>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Project list response
|
|
74
|
+
*/
|
|
75
|
+
export const ProjectList = z.object({
|
|
76
|
+
items: z.array(Project),
|
|
77
|
+
nextCursor: z.string().optional(),
|
|
78
|
+
total: z.number().optional(),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export type ProjectList = z.infer<typeof ProjectList>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session schemas for pi-harness
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { Timestamp, UUID, NonEmptyString } from './base.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Session status
|
|
10
|
+
*/
|
|
11
|
+
export const SessionStatus = z.enum([
|
|
12
|
+
'active',
|
|
13
|
+
'idle',
|
|
14
|
+
'suspended',
|
|
15
|
+
'ended',
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
export type SessionStatus = z.infer<typeof SessionStatus>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Session type
|
|
22
|
+
*/
|
|
23
|
+
export const SessionType = z.enum([
|
|
24
|
+
'interactive',
|
|
25
|
+
'batch',
|
|
26
|
+
'background',
|
|
27
|
+
'review',
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
export type SessionType = z.infer<typeof SessionType>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Session definition
|
|
34
|
+
*/
|
|
35
|
+
export const Session = z.object({
|
|
36
|
+
id: UUID,
|
|
37
|
+
type: SessionType,
|
|
38
|
+
status: SessionStatus,
|
|
39
|
+
workspaceId: z.string(),
|
|
40
|
+
provider: NonEmptyString,
|
|
41
|
+
model: z.string().optional(),
|
|
42
|
+
startedAt: Timestamp,
|
|
43
|
+
endedAt: Timestamp.optional(),
|
|
44
|
+
lastActivityAt: Timestamp.optional(),
|
|
45
|
+
promptTokens: z.number().int().nonnegative().default(0),
|
|
46
|
+
completionTokens: z.number().int().nonnegative().default(0),
|
|
47
|
+
cost: z.number().nonnegative().default(0),
|
|
48
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export type Session = z.infer<typeof Session>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Session creation input
|
|
55
|
+
*/
|
|
56
|
+
export const SessionCreate = z.object({
|
|
57
|
+
type: SessionType.default('interactive'),
|
|
58
|
+
workspaceId: z.string(),
|
|
59
|
+
provider: NonEmptyString,
|
|
60
|
+
model: z.string().optional(),
|
|
61
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export type SessionCreate = z.infer<typeof SessionCreate>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Session update input
|
|
68
|
+
*/
|
|
69
|
+
export const SessionUpdate = z.object({
|
|
70
|
+
status: SessionStatus.optional(),
|
|
71
|
+
lastActivityAt: Timestamp.optional(),
|
|
72
|
+
promptTokens: z.number().int().nonnegative().optional(),
|
|
73
|
+
completionTokens: z.number().int().nonnegative().optional(),
|
|
74
|
+
cost: z.number().nonnegative().optional(),
|
|
75
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export type SessionUpdate = z.infer<typeof SessionUpdate>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Session filter
|
|
82
|
+
*/
|
|
83
|
+
export const SessionFilter = z.object({
|
|
84
|
+
workspaceId: z.string().optional(),
|
|
85
|
+
type: SessionType.optional(),
|
|
86
|
+
status: SessionStatus.optional(),
|
|
87
|
+
since: Timestamp.optional(),
|
|
88
|
+
until: Timestamp.optional(),
|
|
89
|
+
limit: z.number().int().positive().max(100).default(50),
|
|
90
|
+
cursor: z.string().optional(),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export type SessionFilter = z.infer<typeof SessionFilter>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Session list response
|
|
97
|
+
*/
|
|
98
|
+
export const SessionList = z.object({
|
|
99
|
+
items: z.array(Session),
|
|
100
|
+
nextCursor: z.string().optional(),
|
|
101
|
+
total: z.number().optional(),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export type SessionList = z.infer<typeof SessionList>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Sink - Atomic Event Sourcing
|
|
3
|
+
*
|
|
4
|
+
* Inspired by T3Code's orchestrator event sourcing:
|
|
5
|
+
* - Commands serialize to event log
|
|
6
|
+
* - EventSink commits events + projections + outbox effects atomically
|
|
7
|
+
* - EffectWorker performs side effects AFTER intent commits
|
|
8
|
+
* - Command acknowledgement = intent committed, not work finished
|
|
9
|
+
*/
|
|
10
|
+
export { EventSink } from './sink.js';
|
|
11
|
+
export { ProjectionStore } from './projection.js';
|
|
12
|
+
export { OutboxWorker } from './outbox.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Sink - Atomic Event Sourcing
|
|
3
|
+
*
|
|
4
|
+
* Inspired by T3Code's orchestrator event sourcing:
|
|
5
|
+
* - Commands serialize to event log
|
|
6
|
+
* - EventSink commits events + projections + outbox effects atomically
|
|
7
|
+
* - EffectWorker performs side effects AFTER intent commits
|
|
8
|
+
* - Command acknowledgement = intent committed, not work finished
|
|
9
|
+
*/
|
|
10
|
+
export { EventSink } from './sink.js';
|
|
11
|
+
export { ProjectionStore } from './projection.js';
|
|
12
|
+
export { OutboxWorker } from './outbox.js';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outbox Worker
|
|
3
|
+
*
|
|
4
|
+
* Processes outbox entries after events are committed.
|
|
5
|
+
* Side effects are performed asynchronously.
|
|
6
|
+
*/
|
|
7
|
+
import type { OutboxEntry } from './sink.js';
|
|
8
|
+
/**
|
|
9
|
+
* Effect handler function
|
|
10
|
+
*/
|
|
11
|
+
export type EffectHandler = (payload: unknown) => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Outbox Worker options
|
|
14
|
+
*/
|
|
15
|
+
export interface OutboxWorkerOptions {
|
|
16
|
+
/** Maximum retry attempts */
|
|
17
|
+
maxRetries?: number;
|
|
18
|
+
/** Retry delay in ms */
|
|
19
|
+
retryDelay?: number;
|
|
20
|
+
/** Effect handlers */
|
|
21
|
+
handlers?: Record<string, EffectHandler>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Outbox Worker
|
|
25
|
+
*
|
|
26
|
+
* Processes pending outbox entries and executes their effects.
|
|
27
|
+
*/
|
|
28
|
+
export declare class OutboxWorker {
|
|
29
|
+
private maxRetries;
|
|
30
|
+
private retryDelay;
|
|
31
|
+
private handlers;
|
|
32
|
+
private running;
|
|
33
|
+
private interval?;
|
|
34
|
+
constructor(options?: OutboxWorkerOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Register an effect handler
|
|
37
|
+
*/
|
|
38
|
+
register(effect: string, handler: EffectHandler): void;
|
|
39
|
+
/**
|
|
40
|
+
* Start processing outbox
|
|
41
|
+
*/
|
|
42
|
+
start(getPending: () => Promise<OutboxEntry[]>, updateStatus: (id: string, status: OutboxEntry['status'], error?: string) => Promise<void>, pollInterval?: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Stop processing
|
|
45
|
+
*/
|
|
46
|
+
stop(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Check if running
|
|
49
|
+
*/
|
|
50
|
+
isRunning(): boolean;
|
|
51
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outbox Worker
|
|
3
|
+
*
|
|
4
|
+
* Processes outbox entries after events are committed.
|
|
5
|
+
* Side effects are performed asynchronously.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Outbox Worker
|
|
9
|
+
*
|
|
10
|
+
* Processes pending outbox entries and executes their effects.
|
|
11
|
+
*/
|
|
12
|
+
export class OutboxWorker {
|
|
13
|
+
maxRetries;
|
|
14
|
+
retryDelay;
|
|
15
|
+
handlers = new Map();
|
|
16
|
+
running = false;
|
|
17
|
+
interval;
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
this.maxRetries = options.maxRetries ?? 3;
|
|
20
|
+
this.retryDelay = options.retryDelay ?? 1000;
|
|
21
|
+
if (options.handlers) {
|
|
22
|
+
for (const [name, handler] of Object.entries(options.handlers)) {
|
|
23
|
+
this.handlers.set(name, handler);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Register an effect handler
|
|
29
|
+
*/
|
|
30
|
+
register(effect, handler) {
|
|
31
|
+
this.handlers.set(effect, handler);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Start processing outbox
|
|
35
|
+
*/
|
|
36
|
+
start(getPending, updateStatus, pollInterval = 1000) {
|
|
37
|
+
if (this.running)
|
|
38
|
+
return;
|
|
39
|
+
this.running = true;
|
|
40
|
+
this.interval = setInterval(async () => {
|
|
41
|
+
if (!this.running)
|
|
42
|
+
return;
|
|
43
|
+
try {
|
|
44
|
+
const entries = await getPending();
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
if (!this.running)
|
|
47
|
+
break;
|
|
48
|
+
if (entry.attempts >= this.maxRetries) {
|
|
49
|
+
await updateStatus(entry.id, 'failed', 'Max retries exceeded');
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const handler = this.handlers.get(entry.effect);
|
|
53
|
+
if (!handler) {
|
|
54
|
+
await updateStatus(entry.id, 'failed', `No handler for effect: ${entry.effect}`);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await updateStatus(entry.id, 'processing');
|
|
59
|
+
await handler(entry.payload);
|
|
60
|
+
await updateStatus(entry.id, 'completed');
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
await updateStatus(entry.id, 'failed', String(error));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('[OutboxWorker] Error processing outbox:', error);
|
|
69
|
+
}
|
|
70
|
+
}, pollInterval);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Stop processing
|
|
74
|
+
*/
|
|
75
|
+
stop() {
|
|
76
|
+
this.running = false;
|
|
77
|
+
if (this.interval) {
|
|
78
|
+
clearInterval(this.interval);
|
|
79
|
+
this.interval = undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if running
|
|
84
|
+
*/
|
|
85
|
+
isRunning() {
|
|
86
|
+
return this.running;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Projection Store
|
|
3
|
+
*
|
|
4
|
+
* Maintains materialized views of events for efficient queries.
|
|
5
|
+
* Projections are updated atomically with events.
|
|
6
|
+
*/
|
|
7
|
+
import type { StoredEvent } from './sink.js';
|
|
8
|
+
/**
|
|
9
|
+
* Projection function type
|
|
10
|
+
*/
|
|
11
|
+
export type ProjectionFn<T> = (state: T | null, event: StoredEvent) => T;
|
|
12
|
+
/**
|
|
13
|
+
* Projection Store
|
|
14
|
+
*/
|
|
15
|
+
export declare class ProjectionStore {
|
|
16
|
+
private projections;
|
|
17
|
+
/**
|
|
18
|
+
* Register a projection
|
|
19
|
+
*/
|
|
20
|
+
register<T>(projection: {
|
|
21
|
+
name: string;
|
|
22
|
+
initialState: T;
|
|
23
|
+
reduce: ProjectionFn<T>;
|
|
24
|
+
}): void;
|
|
25
|
+
/**
|
|
26
|
+
* Apply events to all projections
|
|
27
|
+
*/
|
|
28
|
+
apply(events: StoredEvent[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Get projection state
|
|
31
|
+
*/
|
|
32
|
+
get<T>(name: string): T | null;
|
|
33
|
+
/**
|
|
34
|
+
* Reset projection to initial state
|
|
35
|
+
*/
|
|
36
|
+
reset(name: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* List all projection names
|
|
39
|
+
*/
|
|
40
|
+
list(): string[];
|
|
41
|
+
}
|