@roj-ai/shared 0.0.2

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.
Files changed (72) hide show
  1. package/dist/chat-protocol.d.ts +60 -0
  2. package/dist/chat-protocol.d.ts.map +1 -0
  3. package/dist/index.d.ts +13 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/lib/domain-utils.d.ts +16 -0
  6. package/dist/lib/domain-utils.d.ts.map +1 -0
  7. package/dist/lib/ids.d.ts +18 -0
  8. package/dist/lib/ids.d.ts.map +1 -0
  9. package/dist/lib/result.d.ts +26 -0
  10. package/dist/lib/result.d.ts.map +1 -0
  11. package/dist/projections/agent-detail-projection.d.ts +91 -0
  12. package/dist/projections/agent-detail-projection.d.ts.map +1 -0
  13. package/dist/projections/agent-registry.d.ts +16 -0
  14. package/dist/projections/agent-registry.d.ts.map +1 -0
  15. package/dist/projections/agent-tree-projection.d.ts +30 -0
  16. package/dist/projections/agent-tree-projection.d.ts.map +1 -0
  17. package/dist/projections/chat-debug.d.ts +34 -0
  18. package/dist/projections/chat-debug.d.ts.map +1 -0
  19. package/dist/projections/events.d.ts +9 -0
  20. package/dist/projections/events.d.ts.map +1 -0
  21. package/dist/projections/index.d.ts +22 -0
  22. package/dist/projections/index.d.ts.map +1 -0
  23. package/dist/projections/mailbox.d.ts +21 -0
  24. package/dist/projections/mailbox.d.ts.map +1 -0
  25. package/dist/projections/metrics.d.ts +30 -0
  26. package/dist/projections/metrics.d.ts.map +1 -0
  27. package/dist/projections/protocol-status.d.ts +9 -0
  28. package/dist/projections/protocol-status.d.ts.map +1 -0
  29. package/dist/projections/services-projection.d.ts +24 -0
  30. package/dist/projections/services-projection.d.ts.map +1 -0
  31. package/dist/projections/session-info.d.ts +19 -0
  32. package/dist/projections/session-info.d.ts.map +1 -0
  33. package/dist/projections/timeline.d.ts +26 -0
  34. package/dist/projections/timeline.d.ts.map +1 -0
  35. package/dist/projections/types.d.ts +182 -0
  36. package/dist/projections/types.d.ts.map +1 -0
  37. package/dist/rpc/client.d.ts +79 -0
  38. package/dist/rpc/client.d.ts.map +1 -0
  39. package/dist/rpc/index.d.ts +9 -0
  40. package/dist/rpc/index.d.ts.map +1 -0
  41. package/dist/src/api-types.d.ts +8 -0
  42. package/dist/src/index.d.ts +17 -0
  43. package/dist/src/rpc/admin-methods.d.ts +99 -0
  44. package/dist/src/rpc/client.d.ts +26 -0
  45. package/dist/src/rpc/definition.d.ts +39 -0
  46. package/dist/src/rpc/instance-methods.d.ts +94 -0
  47. package/dist/src/rpc/methods.d.ts +260 -0
  48. package/dist/src/rpc/server.d.ts +21 -0
  49. package/dist/src/workspace-config.d.ts +16 -0
  50. package/dist/tsconfig.tsbuildinfo +1 -0
  51. package/package.json +36 -0
  52. package/src/chat-protocol.ts +46 -0
  53. package/src/globals.d.ts +3 -0
  54. package/src/index.ts +82 -0
  55. package/src/lib/domain-utils.ts +26 -0
  56. package/src/lib/ids.ts +19 -0
  57. package/src/lib/result.ts +35 -0
  58. package/src/projections/agent-detail-projection.ts +623 -0
  59. package/src/projections/agent-registry.ts +37 -0
  60. package/src/projections/agent-tree-projection.ts +229 -0
  61. package/src/projections/chat-debug.ts +260 -0
  62. package/src/projections/events.ts +10 -0
  63. package/src/projections/index.ts +59 -0
  64. package/src/projections/mailbox.ts +113 -0
  65. package/src/projections/metrics.ts +111 -0
  66. package/src/projections/protocol-status.ts +23 -0
  67. package/src/projections/services-projection.ts +89 -0
  68. package/src/projections/session-info.ts +47 -0
  69. package/src/projections/timeline.ts +228 -0
  70. package/src/projections/types.ts +237 -0
  71. package/src/rpc/client.ts +188 -0
  72. package/src/rpc/index.ts +14 -0
@@ -0,0 +1,260 @@
1
+ import type { SandboxState } from '../api-types';
2
+ export interface CreateInstanceInput {
3
+ templateSlug: string;
4
+ bundleSlug?: string;
5
+ bundleRevisionId?: string;
6
+ name: string;
7
+ vcsType?: 'github' | 'gitLocal' | 'none';
8
+ metadata?: Record<string, unknown>;
9
+ autoCreateSession?: {
10
+ presetId: string;
11
+ blocking?: boolean;
12
+ initialPrompt?: string;
13
+ resourceIds?: string[];
14
+ fileIds?: string[];
15
+ };
16
+ }
17
+ export interface CreateInstanceOutput {
18
+ instanceId: string;
19
+ status: 'created' | 'initializing' | 'ready';
20
+ sessionId?: string;
21
+ wsToken?: string;
22
+ }
23
+ export interface GetInstanceInput {
24
+ instanceId: string;
25
+ }
26
+ export interface GetInstanceOutput {
27
+ instanceId: string;
28
+ name: string;
29
+ status: string;
30
+ templateSlug: string;
31
+ bundleSlug: string;
32
+ bundleRevisionId: string;
33
+ vcsType: string;
34
+ metadata: Record<string, unknown> | null;
35
+ createdAt: string;
36
+ }
37
+ export interface GetInstanceStatusInput {
38
+ instanceId: string;
39
+ }
40
+ export interface GetInstanceStatusOutput {
41
+ instanceId: string;
42
+ status: string;
43
+ sandbox: {
44
+ state: SandboxState;
45
+ e2bId?: string;
46
+ lastActivityAt?: string;
47
+ } | null;
48
+ sessions: Array<{
49
+ id: string;
50
+ presetId: string | null;
51
+ status: string;
52
+ createdAt: string;
53
+ }>;
54
+ lifecycleEvents: Array<{
55
+ event: string;
56
+ detail?: string;
57
+ createdAt: string;
58
+ }>;
59
+ serviceUrls: Array<{
60
+ code: string;
61
+ sessionId: string | null;
62
+ serviceType: string | null;
63
+ port: number;
64
+ }>;
65
+ }
66
+ export interface ArchiveInstanceInput {
67
+ instanceId: string;
68
+ }
69
+ export interface ArchiveInstanceOutput {
70
+ ok: boolean;
71
+ }
72
+ export interface ListInstancesInput {
73
+ limit?: number;
74
+ offset?: number;
75
+ }
76
+ export interface ListInstancesOutput {
77
+ instances: GetInstanceOutput[];
78
+ total: number;
79
+ }
80
+ export interface CreateSessionInput {
81
+ instanceId: string;
82
+ presetId: string;
83
+ blocking?: boolean;
84
+ origin?: string;
85
+ expiresIn?: number;
86
+ }
87
+ export interface CreateSessionOutput {
88
+ sessionId: string;
89
+ status: 'creating' | 'active';
90
+ wsToken?: string;
91
+ }
92
+ export interface ListSessionsInput {
93
+ instanceId: string;
94
+ }
95
+ export interface ListSessionsOutput {
96
+ sessions: Array<{
97
+ id: string;
98
+ presetId: string | null;
99
+ status: string;
100
+ createdAt: string;
101
+ }>;
102
+ }
103
+ export interface PublishSessionInput {
104
+ instanceId: string;
105
+ sessionId: string;
106
+ }
107
+ export interface PublishSessionOutput {
108
+ ok: boolean;
109
+ pushed: boolean;
110
+ commitSha?: string;
111
+ error?: string;
112
+ }
113
+ export interface CreateInstanceTokenInput {
114
+ instanceId: string;
115
+ origin?: string;
116
+ expiresIn?: number;
117
+ meta?: Record<string, unknown>;
118
+ }
119
+ export interface CreateInstanceTokenOutput {
120
+ token: string;
121
+ expiresAt: string;
122
+ }
123
+ export interface ListBundlesInput {
124
+ limit?: number;
125
+ offset?: number;
126
+ }
127
+ export interface ListBundlesOutput {
128
+ bundles: Array<{
129
+ id: string;
130
+ slug: string;
131
+ name: string | null;
132
+ description: string | null;
133
+ latestRevision: {
134
+ id: string;
135
+ version: string | null;
136
+ r2Key: string;
137
+ createdAt: string;
138
+ } | null;
139
+ createdAt: string;
140
+ }>;
141
+ }
142
+ export interface DeleteBundleInput {
143
+ bundleId?: string;
144
+ bundleSlug?: string;
145
+ }
146
+ export interface DeleteBundleOutput {
147
+ ok: boolean;
148
+ }
149
+ export interface CreateResourceInput {
150
+ slug: string;
151
+ name?: string;
152
+ description?: string;
153
+ fileId: string;
154
+ label?: string;
155
+ }
156
+ export interface CreateResourceOutput {
157
+ resourceId: string;
158
+ revisionId: string;
159
+ }
160
+ export interface AddResourceRevisionInput {
161
+ resourceId?: string;
162
+ resourceSlug?: string;
163
+ fileId: string;
164
+ label?: string;
165
+ }
166
+ export interface AddResourceRevisionOutput {
167
+ revisionId: string;
168
+ }
169
+ export interface GetResourceInput {
170
+ resourceId?: string;
171
+ resourceSlug?: string;
172
+ }
173
+ export interface GetResourceOutput {
174
+ id: string;
175
+ slug: string;
176
+ name: string | null;
177
+ description: string | null;
178
+ latestRevision: {
179
+ id: string;
180
+ label: string | null;
181
+ file: {
182
+ id: string;
183
+ filename: string;
184
+ mimeType: string;
185
+ size: number;
186
+ };
187
+ createdAt: string;
188
+ } | null;
189
+ createdAt: string;
190
+ }
191
+ export interface ListResourcesInput {
192
+ limit?: number;
193
+ offset?: number;
194
+ }
195
+ export interface ListResourcesOutput {
196
+ resources: GetResourceOutput[];
197
+ }
198
+ export interface DeleteResourceInput {
199
+ resourceId: string;
200
+ }
201
+ export interface DeleteResourceOutput {
202
+ ok: boolean;
203
+ }
204
+ export interface PauseSandboxInput {
205
+ instanceId: string;
206
+ sandboxId: string;
207
+ }
208
+ export interface ResumeSandboxInput {
209
+ instanceId: string;
210
+ sandboxId: string;
211
+ }
212
+ export interface TerminateSandboxInput {
213
+ instanceId: string;
214
+ sandboxId: string;
215
+ }
216
+ export interface RestartAgentInput {
217
+ instanceId: string;
218
+ sandboxId: string;
219
+ }
220
+ export interface GetAgentLogsInput {
221
+ instanceId: string;
222
+ sandboxId: string;
223
+ lines?: number;
224
+ }
225
+ export interface GetAgentLogsOutput {
226
+ logs: string;
227
+ truncated: boolean;
228
+ }
229
+ export interface SandboxActionOutput {
230
+ ok: boolean;
231
+ }
232
+ export interface GetServiceUrlInput {
233
+ instanceId: string;
234
+ sessionId: string;
235
+ serviceType: string;
236
+ }
237
+ export interface GetServiceUrlOutput {
238
+ url: string | null;
239
+ }
240
+ export declare const platformMethods: {
241
+ 'instances.create': import("./definition").MethodDef<CreateInstanceInput, CreateInstanceOutput>;
242
+ 'instances.get': import("./definition").MethodDef<GetInstanceInput, GetInstanceOutput>;
243
+ 'instances.list': import("./definition").MethodDef<ListInstancesInput, ListInstancesOutput>;
244
+ 'instances.status': import("./definition").MethodDef<GetInstanceStatusInput, GetInstanceStatusOutput>;
245
+ 'instances.archive': import("./definition").MethodDef<ArchiveInstanceInput, ArchiveInstanceOutput>;
246
+ 'sessions.create': import("./definition").MethodDef<CreateSessionInput, CreateSessionOutput>;
247
+ 'sessions.list': import("./definition").MethodDef<ListSessionsInput, ListSessionsOutput>;
248
+ 'sessions.publish': import("./definition").MethodDef<PublishSessionInput, PublishSessionOutput>;
249
+ 'tokens.create': import("./definition").MethodDef<CreateInstanceTokenInput, CreateInstanceTokenOutput>;
250
+ 'services.getUrl': import("./definition").MethodDef<GetServiceUrlInput, GetServiceUrlOutput>;
251
+ 'bundles.list': import("./definition").MethodDef<ListBundlesInput, ListBundlesOutput>;
252
+ 'bundles.delete': import("./definition").MethodDef<DeleteBundleInput, DeleteBundleOutput>;
253
+ 'resources.create': import("./definition").MethodDef<CreateResourceInput, CreateResourceOutput>;
254
+ 'resources.addRevision': import("./definition").MethodDef<AddResourceRevisionInput, AddResourceRevisionOutput>;
255
+ 'resources.get': import("./definition").MethodDef<GetResourceInput, GetResourceOutput>;
256
+ 'resources.list': import("./definition").MethodDef<ListResourcesInput, ListResourcesOutput>;
257
+ 'resources.delete': import("./definition").MethodDef<DeleteResourceInput, DeleteResourceOutput>;
258
+ };
259
+ export type PlatformMethods = typeof platformMethods;
260
+ export type PlatformMethodName = keyof PlatformMethods;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Type-safe RPC server handler.
3
+ * Maps method names to handler functions, dispatches incoming requests.
4
+ *
5
+ * Usage:
6
+ * const router = createRpcRouter(platformMethods, {
7
+ * 'instances.create': async (input, ctx) => { ... },
8
+ * 'instances.get': async (input, ctx) => { ... },
9
+ * })
10
+ * // In Hono route:
11
+ * app.post('/rpc', (c) => router.handle(c.req.json(), ctx))
12
+ */
13
+ import type { MethodDef, MethodInput, MethodOutput, RpcRequest, RpcResponse } from './definition';
14
+ export type MethodHandler<Methods extends Record<string, MethodDef>, M extends keyof Methods, Ctx> = (input: MethodInput<Methods, M>, ctx: Ctx) => Promise<MethodOutput<Methods, M>>;
15
+ export type MethodHandlers<Methods extends Record<string, MethodDef>, Ctx> = {
16
+ [M in keyof Methods]: MethodHandler<Methods, M, Ctx>;
17
+ };
18
+ export interface RpcRouter<Ctx> {
19
+ handle(request: RpcRequest, ctx: Ctx): Promise<RpcResponse>;
20
+ }
21
+ export declare function createRpcRouter<Methods extends Record<string, MethodDef>, Ctx>(_methods: Methods, handlers: MethodHandlers<Methods, Ctx>): RpcRouter<Ctx>;
@@ -0,0 +1,16 @@
1
+ export interface WorkspaceConfig {
2
+ instanceId: string;
3
+ organizationId: string;
4
+ e2bTemplateId: string;
5
+ agentBundleR2Key: string;
6
+ idleTimeoutMs: number;
7
+ llmProvider: 'openrouter';
8
+ llmApiKey?: string;
9
+ llmKeyStrategy: 'platform-managed' | 'org-provided';
10
+ vcsType: 'github' | 'git-local' | 'none';
11
+ githubOrg?: string;
12
+ githubInstallationId?: number;
13
+ workerUrl: string;
14
+ environment: 'production' | 'development';
15
+ e2bApiKey?: string;
16
+ }
@@ -0,0 +1 @@
1
+ {"fileNames":["../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2023.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2024.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2023.array.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2023.collection.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2023.intl.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2024.collection.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2024.object.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2024.promise.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2024.regexp.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2024.string.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.array.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.collection.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.disposable.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.promise.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.decorators.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.iterator.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.float16.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.error.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../src/api-types.ts","../src/workspace-config.ts","../src/rpc/definition.ts","../src/rpc/methods.ts","../src/rpc/admin-methods.ts","../src/rpc/instance-methods.ts","../src/rpc/server.ts","../src/rpc/client.ts","../src/index.ts","../../../node_modules/.bun/@types+react@19.2.14/node_modules/@types/react/global.d.ts","../../../node_modules/.bun/csstype@3.2.3/node_modules/csstype/index.d.ts","../../../node_modules/.bun/@types+react@19.2.14/node_modules/@types/react/index.d.ts","../../../node_modules/.bun/@types+react-dom@19.2.3+273cdfb19a04c3e9/node_modules/@types/react-dom/index.d.ts"],"fileIdsList":[[93],[91,92],[82,83,84,85,86,87,88,89],[84,85],[84],[82,84]],"fileInfos":[{"version":"c430d44666289dae81f30fa7b2edebf186ecc91a2d4c71266ea6ae76388792e1","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","impliedFormat":1},{"version":"feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","impliedFormat":1},{"version":"ee7bad0c15b58988daa84371e0b89d313b762ab83cb5b31b8a2d1162e8eb41c2","impliedFormat":1},{"version":"27bdc30a0e32783366a5abeda841bc22757c1797de8681bbe81fbc735eeb1c10","impliedFormat":1},{"version":"8fd575e12870e9944c7e1d62e1f5a73fcf23dd8d3a321f2a2c74c20d022283fe","impliedFormat":1},{"version":"2ab096661c711e4a81cc464fa1e6feb929a54f5340b46b0a07ac6bbf857471f0","impliedFormat":1},{"version":"080941d9f9ff9307f7e27a83bcd888b7c8270716c39af943532438932ec1d0b9","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"fb0f136d372979348d59b3f5020b4cdb81b5504192b1cacff5d1fbba29378aa1","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"a680117f487a4d2f30ea46f1b4b7f58bef1480456e18ba53ee85c2746eeca012","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"d6d7ae4d1f1f3772e2a3cde568ed08991a8ae34a080ff1151af28b7f798e22ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true,"impliedFormat":1},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true,"impliedFormat":1},{"version":"52ada8e0b6e0482b728070b7639ee42e83a9b1c22d205992756fe020fd9f4a47","affectsGlobalScope":true,"impliedFormat":1},{"version":"3bdefe1bfd4d6dee0e26f928f93ccc128f1b64d5d501ff4a8cf3c6371200e5e6","affectsGlobalScope":true,"impliedFormat":1},{"version":"59fb2c069260b4ba00b5643b907ef5d5341b167e7d1dbf58dfd895658bda2867","affectsGlobalScope":true,"impliedFormat":1},{"version":"639e512c0dfc3fad96a84caad71b8834d66329a1f28dc95e3946c9b58176c73a","affectsGlobalScope":true,"impliedFormat":1},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true,"impliedFormat":1},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true,"impliedFormat":1},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true,"impliedFormat":1},{"version":"959d36cddf5e7d572a65045b876f2956c973a586da58e5d26cde519184fd9b8a","affectsGlobalScope":true,"impliedFormat":1},{"version":"965f36eae237dd74e6cca203a43e9ca801ce38824ead814728a2807b1910117d","affectsGlobalScope":true,"impliedFormat":1},{"version":"3925a6c820dcb1a06506c90b1577db1fdbf7705d65b62b99dce4be75c637e26b","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a3d63ef2b853447ec4f749d3f368ce642264246e02911fcb1590d8c161b8005","affectsGlobalScope":true,"impliedFormat":1},{"version":"8cdf8847677ac7d20486e54dd3fcf09eda95812ac8ace44b4418da1bbbab6eb8","affectsGlobalScope":true,"impliedFormat":1},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true,"impliedFormat":1},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true,"impliedFormat":1},{"version":"b4b67b1a91182421f5df999988c690f14d813b9850b40acd06ed44691f6727ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"df83c2a6c73228b625b0beb6669c7ee2a09c914637e2d35170723ad49c0f5cd4","affectsGlobalScope":true,"impliedFormat":1},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e3c06ea092138bf9fa5e874a1fdbc9d54805d074bee1de31b99a11e2fec239d","affectsGlobalScope":true,"impliedFormat":1},{"version":"87dc0f382502f5bbce5129bdc0aea21e19a3abbc19259e0b43ae038a9fc4e326","affectsGlobalScope":true,"impliedFormat":1},{"version":"b1cb28af0c891c8c96b2d6b7be76bd394fddcfdb4709a20ba05a7c1605eea0f9","affectsGlobalScope":true,"impliedFormat":1},{"version":"2fef54945a13095fdb9b84f705f2b5994597640c46afeb2ce78352fab4cb3279","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac77cb3e8c6d3565793eb90a8373ee8033146315a3dbead3bde8db5eaf5e5ec6","affectsGlobalScope":true,"impliedFormat":1},{"version":"56e4ed5aab5f5920980066a9409bfaf53e6d21d3f8d020c17e4de584d29600ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ece9f17b3866cc077099c73f4983bddbcb1dc7ddb943227f1ec070f529dedd1","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a6282c8827e4b9a95f4bf4f5c205673ada31b982f50572d27103df8ceb8013c","affectsGlobalScope":true,"impliedFormat":1},{"version":"1c9319a09485199c1f7b0498f2988d6d2249793ef67edda49d1e584746be9032","affectsGlobalScope":true,"impliedFormat":1},{"version":"e3a2a0cee0f03ffdde24d89660eba2685bfbdeae955a6c67e8c4c9fd28928eeb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811c71eee4aa0ac5f7adf713323a5c41b0cf6c4e17367a34fbce379e12bbf0a4","affectsGlobalScope":true,"impliedFormat":1},{"version":"51ad4c928303041605b4d7ae32e0c1ee387d43a24cd6f1ebf4a2699e1076d4fa","affectsGlobalScope":true,"impliedFormat":1},{"version":"60037901da1a425516449b9a20073aa03386cce92f7a1fd902d7602be3a7c2e9","affectsGlobalScope":true,"impliedFormat":1},{"version":"d4b1d2c51d058fc21ec2629fff7a76249dec2e36e12960ea056e3ef89174080f","affectsGlobalScope":true,"impliedFormat":1},{"version":"22adec94ef7047a6c9d1af3cb96be87a335908bf9ef386ae9fd50eeb37f44c47","affectsGlobalScope":true,"impliedFormat":1},{"version":"196cb558a13d4533a5163286f30b0509ce0210e4b316c56c38d4c0fd2fb38405","affectsGlobalScope":true,"impliedFormat":1},{"version":"73f78680d4c08509933daf80947902f6ff41b6230f94dd002ae372620adb0f60","affectsGlobalScope":true,"impliedFormat":1},{"version":"c5239f5c01bcfa9cd32f37c496cf19c61d69d37e48be9de612b541aac915805b","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"a62d677c6545309e8bf241ae6c956bef7289ed38a2870b62648c9fc4b5e40af3","signature":"65a732c94ddffbafbbb31213217e1cf2b611559b08cea03b4f2a9ac8a9777508"},{"version":"acf4c258f624f37b1d953b448c58d7879caafe0f5cc585a5803f96f82ae0a218","signature":"fd4d03d9d7f3c53c158b70259194241fa7daf2426ac4e2509ee653c41564ecc1"},{"version":"6a2ea758ffd37104fa848c0fcaee4048c06a36b805cff6144ffa319c04c746ca","signature":"db6e707dca8c41a4075a46ad0dd0f3316f3ae3e94b24e18af03e306882bcd55a"},{"version":"fc22da682c4388341a2d72f74c1d9fdf394bec421c3543ae285260c7504b44aa","signature":"3820c4d36614dc037ce5eac11e3d849d2d2676be0fd7a415aa1a8b64ea0531f6"},{"version":"7b6a42b8e7eee4e39e73859d3be4f858e2647cec8717672cffa5a6f6e4b3e7c6","signature":"f1d192d10119d6081c7e9140ce42b2b75f8e1715d3c14bc5a0fca843824ce610"},{"version":"976da496464a1c5c1341f157fc27d9e479da21da2c9cacb767a94052f9fee759","signature":"3d7eaf443a87c8c915c92e4448308d27e87f907d9b7d36f0079fbf448817f054"},{"version":"4b3ec4756028548f23c2e6b2673b7197cc22b62fd573f6df027cff6f697f2523","signature":"796f2bfcf870c8a6eb70d4fb19694fd906b2665a3c4b6a31f79d117bce8b9305"},{"version":"154e564880397cde2d9f2412b97dd322882cac3a071399c345f1babc82352af7","signature":"93da24fc10757ed71346965f115f7cbf79e985fc7f184f2add183e63bf5858f7"},{"version":"662af4ab00bc605124c5003316c555f0177b4e522eae766c7a82fcd66043bd2a","signature":"772639f9050a45558835d9222f9dc37f45e4dbaf19b30501a2c96e48cd15ed8a"},{"version":"7e29f41b158de217f94cb9676bf9cbd0cd9b5a46e1985141ed36e075c52bf6ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac51dd7d31333793807a6abaa5ae168512b6131bd41d9c5b98477fc3b7800f9f","impliedFormat":1},{"version":"dc0a7f107690ee5cd8afc8dbf05c4df78085471ce16bdd9881642ec738bc81fe","impliedFormat":1},{"version":"be1cc4d94ea60cbe567bc29ed479d42587bf1e6cba490f123d329976b0fe4ee5","impliedFormat":1}],"root":[[82,90]],"options":{"composite":true,"declaration":true,"emitDeclarationOnly":true,"module":99,"noImplicitAny":true,"outDir":"./","skipLibCheck":true,"strict":true,"target":99},"referencedMap":[[94,1],[93,2],[90,3],[86,4],[89,5],[87,4],[85,6],[88,5]],"latestChangedDtsFile":"./src/index.d.ts","version":"5.9.3"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@roj-ai/shared",
3
+ "version": "0.0.2",
4
+ "type": "module",
5
+ "main": "./src/index.ts",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./src/index.ts",
10
+ "default": "./src/index.ts"
11
+ },
12
+ "./rpc": {
13
+ "types": "./dist/rpc/index.d.ts",
14
+ "import": "./src/rpc/index.ts",
15
+ "default": "./src/rpc/index.ts"
16
+ }
17
+ },
18
+ "files": [
19
+ "src",
20
+ "dist"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "scripts": {
26
+ "type-check": "tsc --noEmit"
27
+ },
28
+ "dependencies": {
29
+ "zod": "^4.1.12"
30
+ },
31
+ "devDependencies": {
32
+ "@roj-ai/sdk": "^0.0.2",
33
+ "typescript": "^5.7.2"
34
+ },
35
+ "types": "./dist/index.d.ts"
36
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Chat protocol types — shared between agent-server and platform SDK.
3
+ *
4
+ * Defines the shape of chat messages and ask_user input types.
5
+ */
6
+ import type { ChatMessageId } from './lib/ids.js'
7
+
8
+ export interface UserChatMessage {
9
+ type: 'user_message'
10
+ messageId: ChatMessageId
11
+ content: string
12
+ timestamp: number
13
+ }
14
+
15
+ export interface AgentChatMessage {
16
+ type: 'agent_message'
17
+ messageId: ChatMessageId
18
+ content: string
19
+ format: 'text' | 'markdown'
20
+ timestamp: number
21
+ }
22
+
23
+ export interface AskUserChatMessage {
24
+ type: 'ask_user'
25
+ questionId: ChatMessageId
26
+ question: string
27
+ inputType: AskUserInputType
28
+ answered: boolean
29
+ answer?: unknown
30
+ timestamp: number
31
+ }
32
+
33
+ export type ChatMessage = UserChatMessage | AgentChatMessage | AskUserChatMessage
34
+
35
+ export type AskUserOption = {
36
+ value: string
37
+ label: string
38
+ description?: string
39
+ }
40
+
41
+ export type AskUserInputType =
42
+ | { type: 'text'; placeholder?: string; multiline?: boolean }
43
+ | { type: 'single_choice'; options: AskUserOption[] }
44
+ | { type: 'multi_choice'; options: AskUserOption[]; minSelect?: number; maxSelect?: number }
45
+ | { type: 'rating'; min: number; max: number; labels?: { min?: string; max?: string } }
46
+ | { type: 'confirm'; confirmLabel?: string; cancelLabel?: string }
@@ -0,0 +1,3 @@
1
+ // Ambient types for fetch API — available in Node 18+, Bun, and browsers,
2
+ // but not included in the default ES2022 lib.
3
+ declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>
package/src/index.ts ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @roj-ai/shared
3
+ *
4
+ * Shared projections and utilities for Roj packages.
5
+ * Pure functions with no runtime dependencies beyond @roj-ai/sdk types.
6
+ */
7
+
8
+ // ID constructors (branded types — compile-time only)
9
+ export { AgentId, ChatMessageId, SessionId } from './lib/ids.js'
10
+ export type { AgentId as AgentIdType, ChatMessageId as ChatMessageIdType, SessionId as SessionIdType } from './lib/ids.js'
11
+
12
+ // Chat protocol types
13
+ export type {
14
+ AgentChatMessage,
15
+ AskUserChatMessage,
16
+ AskUserInputType,
17
+ AskUserOption,
18
+ ChatMessage,
19
+ UserChatMessage,
20
+ } from './chat-protocol.js'
21
+
22
+ // Domain utilities
23
+ export { contentToString, isDomainEvent } from './lib/domain-utils.js'
24
+
25
+ // Projections
26
+ export {
27
+ applyEventToAgentDetail,
28
+ applyEventToAgentRegistry,
29
+ applyEventToAgentTree,
30
+ applyEventToChatDebug,
31
+ applyEventToMailbox,
32
+ applyEventToMetrics,
33
+ applyEventToServices,
34
+ applyEventToSessionInfo,
35
+ applyEventToTimeline,
36
+ buildAgentTreeFromProjection,
37
+ createAgentDetailProjectionState,
38
+ createAgentRegistryState,
39
+ createAgentTreeProjectionState,
40
+ createChatDebugState,
41
+ createMailboxState,
42
+ createMetricsState,
43
+ createServicesProjectionState,
44
+ createSessionInfoState,
45
+ createTimelineState,
46
+ getAgentDetail,
47
+ getAgentName,
48
+ getChatDebugMessages,
49
+ getMailboxMessages,
50
+ getTimelineItems,
51
+ metricsStateToResponse,
52
+ toProtocolStatus,
53
+ } from './projections/index.js'
54
+
55
+ export type {
56
+ AgentDetailProjectionState,
57
+ AgentRegistryState,
58
+ AgentTreeNode,
59
+ AgentTreeProjectionState,
60
+ AssistantConversationMessageView,
61
+ ChatDebugState,
62
+ ConversationMessageView,
63
+ DebugChatMessage,
64
+ GetAgentDetailResponse,
65
+ GetEventsResponse,
66
+ GetMetricsResponse,
67
+ GlobalMailboxMessage,
68
+ MailboxMessageView,
69
+ MailboxState,
70
+ MetricsState,
71
+ ProjectionEvent,
72
+ ServiceEntry,
73
+ ServicesProjectionState,
74
+ ServiceStatus,
75
+ SessionInfoState,
76
+ SystemConversationMessageView,
77
+ TimelineItem,
78
+ TimelineState,
79
+ ToolCallView,
80
+ ToolConversationMessageView,
81
+ UserConversationMessageView,
82
+ } from './projections/index.js'
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Domain utility functions for client-side use.
3
+ */
4
+
5
+ import type { DomainEvent } from '@roj-ai/sdk'
6
+
7
+ /**
8
+ * Type guard to check if an unknown value is a DomainEvent.
9
+ */
10
+ export const isDomainEvent = (event: unknown): event is DomainEvent =>
11
+ typeof event === 'object'
12
+ && event !== null
13
+ && 'type' in event
14
+ && 'sessionId' in event
15
+ && 'timestamp' in event
16
+
17
+ /**
18
+ * Helper to normalize content to string (for display/logging).
19
+ */
20
+ export const contentToString = (content: string | Array<{ type: string; text?: string }>): string => {
21
+ if (typeof content === 'string') return content
22
+ return content
23
+ .filter((c): c is { type: 'text'; text: string } => c.type === 'text')
24
+ .map((c) => c.text)
25
+ .join('\n')
26
+ }
package/src/lib/ids.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Branded ID types and constructors.
3
+ *
4
+ * Uses Zod brands for structural compatibility with agent-server types.
5
+ * These are the canonical definitions — other packages import from here.
6
+ */
7
+ import z from 'zod/v4'
8
+
9
+ const sessionIdSchema = z.string().brand('SessionId')
10
+ export type SessionId = z.infer<typeof sessionIdSchema>
11
+ export const SessionId = (id: string): SessionId => id as SessionId
12
+
13
+ const agentIdSchema = z.string().brand('AgentId')
14
+ export type AgentId = z.infer<typeof agentIdSchema>
15
+ export const AgentId = (id: string): AgentId => id as AgentId
16
+
17
+ const chatMessageIdSchema = z.string().brand('ChatMessageId')
18
+ export type ChatMessageId = z.infer<typeof chatMessageIdSchema>
19
+ export const ChatMessageId = (id: string): ChatMessageId => id as ChatMessageId
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Result type for explicit error handling without exceptions.
3
+ * Inspired by Rust/Go approach.
4
+ */
5
+
6
+ export type Result<T, E = Error> =
7
+ | { ok: true; value: T }
8
+ | { ok: false; error: E }
9
+
10
+ // Constructors
11
+ export const Ok = <T>(value: T): Result<T, never> => ({ ok: true, value })
12
+ export const Err = <E>(error: E): Result<never, E> => ({ ok: false, error })
13
+
14
+ // Type guards
15
+ export const isOk = <T, E>(result: Result<T, E>): result is { ok: true; value: T } => result.ok
16
+ export const isErr = <T, E>(result: Result<T, E>): result is { ok: false; error: E } => !result.ok
17
+
18
+ // Helper functions
19
+ export const mapResult = <T, U, E>(
20
+ result: Result<T, E>,
21
+ fn: (value: T) => U,
22
+ ): Result<U, E> => result.ok ? Ok(fn(result.value)) : result
23
+
24
+ export const flatMapResult = <T, U, E>(
25
+ result: Result<T, E>,
26
+ fn: (value: T) => Result<U, E>,
27
+ ): Result<U, E> => result.ok ? fn(result.value) : result
28
+
29
+ // Unwrap functions
30
+ export const unwrapOr = <T, E>(result: Result<T, E>, defaultValue: T): T => result.ok ? result.value : defaultValue
31
+
32
+ export const unwrapOrThrow = <T, E>(result: Result<T, E>): T => {
33
+ if (result.ok) return result.value
34
+ throw result.error
35
+ }