@lace-cloud/chat-core 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- import { RenderInput } from '@lace-cloud/proto';
2
1
  import { EditorPort, SourcePort, CommandsPort, CommandFailure, CanvasSource } from '@lace-cloud/canvas/engine';
3
2
 
4
3
  type ToolSchema = {
@@ -12,7 +11,7 @@ type ToolResult = {
12
11
  isError?: boolean;
13
12
  };
14
13
 
15
- type ToolHandler<R extends ToolResult = ToolResult> = (input: Record<string, unknown>) => Promise<R>;
14
+ type ToolHandler<R extends ToolResult = ToolResult> = (input: Record<string, unknown>, signal?: AbortSignal) => Promise<R>;
16
15
  type ToolRegistration<R extends ToolResult = ToolResult> = {
17
16
  schema: ToolSchema;
18
17
  handler: ToolHandler<R>;
@@ -25,227 +24,29 @@ interface ToolRegistry {
25
24
  }
26
25
  declare function createToolRegistry(): ToolRegistry;
27
26
 
28
- type DecisionKind = 'operation' | 'instance' | 'input' | 'module' | 'connection' | 'steps';
29
- declare const DECISION_KINDS: readonly DecisionKind[];
30
- declare const NONE_CANDIDATE_ID = "(none)";
31
- type Candidate = {
32
- readonly id: string;
33
- readonly kind: DecisionKind;
34
- readonly text: string;
35
- };
36
-
37
- type InstanceRole = 'instance' | 'source' | 'target';
38
- type InputState = 'not set' | 'set' | 'wired';
39
- type PinFacts = {
40
- readonly name: string;
41
- readonly description?: string;
42
- };
43
- type CandidateFacts = {
44
- readonly id: string;
45
- readonly kind: 'operation';
46
- } | {
47
- readonly id: string;
48
- readonly kind: 'steps';
49
- } | {
50
- readonly id: string;
51
- readonly kind: 'instance';
52
- readonly role: InstanceRole;
53
- readonly module: string;
54
- readonly inputs: readonly PinFacts[];
55
- readonly outputs: readonly PinFacts[];
56
- } | {
57
- readonly id: string;
58
- readonly kind: 'input';
59
- readonly instance: string;
60
- readonly module: string;
61
- readonly type: string;
62
- readonly required: boolean;
63
- readonly state: InputState;
64
- readonly description?: string;
65
- } | {
66
- readonly id: string;
67
- readonly kind: 'module';
68
- readonly displayName: string;
69
- readonly description: string;
70
- readonly system: string;
71
- readonly categories: readonly string[];
72
- } | {
73
- readonly id: string;
74
- readonly kind: 'connection';
75
- readonly source: string;
76
- readonly output: string;
77
- readonly target: string;
78
- readonly input: string;
79
- readonly score?: number;
80
- };
81
- declare function renderCandidate(facts: CandidateFacts): Candidate;
82
-
83
- declare const VALUE_PLACEHOLDER = "<value>";
84
- declare function renderRequest(request: string, values: readonly unknown[], statement?: string): string;
85
-
86
- type ChangeOutcome = 'reverted' | 'changed_again' | 'saved' | 'generated' | 'hand_edited';
87
- type OutcomeReport = {
88
- readonly event: ChangeOutcome;
89
- readonly question?: number;
90
- readonly candidate?: string;
91
- };
92
-
93
- type Took = 'named' | 'chat' | 'clm';
94
- type Question = {
95
- readonly kind: DecisionKind;
96
- readonly capture_id: string | null;
97
- readonly chat: string | null;
98
- readonly clm: {
99
- readonly id: string;
100
- readonly rightness: number;
101
- } | null;
102
- readonly took: Took;
103
- readonly taken: string | null;
104
- };
105
- type DecisionReport = {
106
- readonly id: string;
107
- readonly surface: 'canvas';
108
- readonly questions: readonly Question[];
109
- readonly applied: string | null;
110
- readonly asked: boolean;
111
- };
112
-
113
- type Transport = (path: `/api/v1/candidates/${string}`, init: {
114
- readonly method: 'POST';
115
- readonly body: unknown;
116
- }) => Promise<{
117
- readonly status: number;
118
- readonly body: unknown;
119
- }>;
120
- type RankRequest = {
121
- readonly request: string;
122
- readonly statement: string;
123
- readonly candidates: readonly Candidate[];
124
- };
125
- type Score = {
126
- readonly id: string;
127
- readonly score: number;
128
- readonly rightness: number;
129
- };
130
- type Threshold = {
131
- readonly from: number;
132
- };
133
- type Thresholds = Readonly<Partial<Record<DecisionKind, Threshold>>>;
134
- type Ranked = {
135
- readonly capture_id: string;
136
- readonly head: string;
137
- readonly scores: readonly Score[];
138
- readonly thresholds: Thresholds;
139
- };
140
-
141
- type Part = 'train' | 'calibration' | 'held_out';
142
- type Origin = 'real' | 'synthetic';
143
- type TrainingRow = {
144
- readonly request: string;
145
- readonly statement: string;
146
- readonly candidates: readonly Candidate[];
147
- readonly label: string;
148
- readonly part: Part;
149
- readonly origin: Origin;
150
- readonly turn: string;
151
- readonly chat: string | null;
152
- };
153
- type LabelledQuestion = {
154
- readonly kind: DecisionKind;
155
- readonly candidates: readonly Candidate[];
156
- readonly label: string;
157
- readonly chat: string | null;
158
- };
159
- type LabelledTurn = {
160
- readonly id: string;
161
- readonly request: string;
162
- readonly statement: string;
163
- readonly origin: Origin;
164
- readonly questions: readonly LabelledQuestion[];
165
- };
166
- declare function partOf(key: string): Part;
167
- declare function trainingRows(turn: LabelledTurn, part: Part): TrainingRow[];
168
-
169
- declare function sure(ranked: Ranked, kind: DecisionKind): boolean;
170
- type Readings = {
171
- readonly kind: DecisionKind;
172
- readonly chat: string | null;
173
- readonly ranked: Ranked | null;
174
- };
175
- type Composed = {
176
- readonly took: 'chat' | 'clm';
177
- readonly taken: string | null;
178
- readonly clm: {
179
- readonly id: string;
180
- readonly rightness: number;
181
- } | null;
182
- readonly differed: boolean;
183
- };
184
- declare function compose({ kind, chat, ranked }: Readings): Composed;
185
-
186
- type CanvasInput = RenderInput & {
187
- readonly sensitive: boolean;
188
- };
189
-
190
27
  type CanvasEditor = Pick<EditorPort, 'apply' | 'save' | 'generate' | 'wiringCandidates'>;
191
28
  type CanvasToolPorts = {
192
29
  readonly source: SourcePort;
193
30
  readonly editor: CanvasEditor;
194
31
  readonly commands: CommandsPort;
195
- readonly transport?: Transport;
196
32
  };
197
33
  type ModuleToolPorts = {
198
34
  readonly commands: CommandsPort;
199
35
  };
200
36
 
201
- type ChangeTarget = {
202
- readonly scope: string;
203
- readonly instance: string;
204
- readonly input?: string;
205
- };
206
- type InputBinding = {
207
- readonly mode: CanvasInput['mode'];
208
- readonly value?: unknown;
209
- readonly variable?: string;
210
- readonly expression?: string;
211
- readonly wiredSource?: string;
212
- };
213
- type InstancePresence = {
214
- readonly instance: string;
215
- readonly module: string;
216
- };
217
- type ChangeState = InputBinding | InstancePresence | null;
218
- type RecordQuestion = {
219
- readonly kind: DecisionKind;
220
- readonly candidates: readonly string[];
221
- };
222
- type ChangeRecord = {
223
- readonly id: string;
224
- readonly target: ChangeTarget;
225
- readonly before: ChangeState;
226
- readonly after: ChangeState;
227
- readonly revision?: number;
228
- readonly questions: readonly RecordQuestion[];
229
- readonly reported: boolean;
230
- };
231
-
232
37
  declare const canvasToolSchemas: readonly [ToolSchema, ToolSchema, ToolSchema, ToolSchema];
233
- type ChangeResult = ToolResult & {
234
- readonly applied: readonly ChangeRecord[];
235
- };
236
38
  type CanvasTools = readonly [
237
- ToolRegistration<ChangeResult>,
39
+ ToolRegistration,
238
40
  ToolRegistration,
239
41
  ToolRegistration,
240
42
  ToolRegistration
241
- ] & {
242
- readonly dispose: () => void;
243
- };
43
+ ];
244
44
  declare function canvasTools(ports: CanvasToolPorts): CanvasTools;
245
45
 
246
46
  declare const moduleToolSchemas: readonly [ToolSchema, ToolSchema, ToolSchema];
247
- type ModuleToolResult = ToolResult & {
248
- readonly failure?: CommandFailure;
47
+ type ModuleToolResult = ToolResult & Partial<ModuleToolData>;
48
+ type ModuleToolData = {
49
+ readonly failure: CommandFailure;
249
50
  };
250
51
  type ModuleTools = readonly [
251
52
  ToolRegistration<ModuleToolResult>,
@@ -254,11 +55,6 @@ type ModuleTools = readonly [
254
55
  ];
255
56
  declare function moduleTools({ commands }: ModuleToolPorts): ModuleTools;
256
57
 
257
- declare function changeOutcomes(record: ChangeRecord, frames: readonly CanvasSource[], own?: ReadonlySet<number>): {
258
- readonly record: ChangeRecord;
259
- readonly outcomes: OutcomeReport[];
260
- };
261
-
262
58
  declare function renderCanvas(source: CanvasSource): string;
263
59
 
264
- export { type Candidate, type CandidateFacts, type CanvasEditor, type CanvasToolPorts, type CanvasTools, type ChangeOutcome, type ChangeRecord, type ChangeResult, type ChangeState, type ChangeTarget, type Composed, DECISION_KINDS, type DecisionKind, type DecisionReport, type InputBinding, type InstancePresence, type LabelledQuestion, type LabelledTurn, type ModuleToolPorts, type ModuleToolResult, type ModuleTools, NONE_CANDIDATE_ID, type Origin, type OutcomeReport, type Part, type Question, type RankRequest, type Ranked, type Readings, type Score, type Threshold, type Thresholds, type Took, type ToolHandler, type ToolRegistration, type ToolRegistry, type ToolResult, type ToolSchema, type TrainingRow, type Transport, VALUE_PLACEHOLDER, canvasToolSchemas, canvasTools, changeOutcomes, compose, createToolRegistry, moduleToolSchemas, moduleTools, partOf, renderCandidate, renderCanvas, renderRequest, sure, trainingRows };
60
+ export { type CanvasEditor, type CanvasToolPorts, type CanvasTools, type ModuleToolPorts, type ModuleToolResult, type ModuleTools, type ToolHandler, type ToolRegistration, type ToolRegistry, type ToolResult, type ToolSchema, canvasToolSchemas, canvasTools, createToolRegistry, moduleToolSchemas, moduleTools, renderCanvas };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { RenderInput } from '@lace-cloud/proto';
2
1
  import { EditorPort, SourcePort, CommandsPort, CommandFailure, CanvasSource } from '@lace-cloud/canvas/engine';
3
2
 
4
3
  type ToolSchema = {
@@ -12,7 +11,7 @@ type ToolResult = {
12
11
  isError?: boolean;
13
12
  };
14
13
 
15
- type ToolHandler<R extends ToolResult = ToolResult> = (input: Record<string, unknown>) => Promise<R>;
14
+ type ToolHandler<R extends ToolResult = ToolResult> = (input: Record<string, unknown>, signal?: AbortSignal) => Promise<R>;
16
15
  type ToolRegistration<R extends ToolResult = ToolResult> = {
17
16
  schema: ToolSchema;
18
17
  handler: ToolHandler<R>;
@@ -25,227 +24,29 @@ interface ToolRegistry {
25
24
  }
26
25
  declare function createToolRegistry(): ToolRegistry;
27
26
 
28
- type DecisionKind = 'operation' | 'instance' | 'input' | 'module' | 'connection' | 'steps';
29
- declare const DECISION_KINDS: readonly DecisionKind[];
30
- declare const NONE_CANDIDATE_ID = "(none)";
31
- type Candidate = {
32
- readonly id: string;
33
- readonly kind: DecisionKind;
34
- readonly text: string;
35
- };
36
-
37
- type InstanceRole = 'instance' | 'source' | 'target';
38
- type InputState = 'not set' | 'set' | 'wired';
39
- type PinFacts = {
40
- readonly name: string;
41
- readonly description?: string;
42
- };
43
- type CandidateFacts = {
44
- readonly id: string;
45
- readonly kind: 'operation';
46
- } | {
47
- readonly id: string;
48
- readonly kind: 'steps';
49
- } | {
50
- readonly id: string;
51
- readonly kind: 'instance';
52
- readonly role: InstanceRole;
53
- readonly module: string;
54
- readonly inputs: readonly PinFacts[];
55
- readonly outputs: readonly PinFacts[];
56
- } | {
57
- readonly id: string;
58
- readonly kind: 'input';
59
- readonly instance: string;
60
- readonly module: string;
61
- readonly type: string;
62
- readonly required: boolean;
63
- readonly state: InputState;
64
- readonly description?: string;
65
- } | {
66
- readonly id: string;
67
- readonly kind: 'module';
68
- readonly displayName: string;
69
- readonly description: string;
70
- readonly system: string;
71
- readonly categories: readonly string[];
72
- } | {
73
- readonly id: string;
74
- readonly kind: 'connection';
75
- readonly source: string;
76
- readonly output: string;
77
- readonly target: string;
78
- readonly input: string;
79
- readonly score?: number;
80
- };
81
- declare function renderCandidate(facts: CandidateFacts): Candidate;
82
-
83
- declare const VALUE_PLACEHOLDER = "<value>";
84
- declare function renderRequest(request: string, values: readonly unknown[], statement?: string): string;
85
-
86
- type ChangeOutcome = 'reverted' | 'changed_again' | 'saved' | 'generated' | 'hand_edited';
87
- type OutcomeReport = {
88
- readonly event: ChangeOutcome;
89
- readonly question?: number;
90
- readonly candidate?: string;
91
- };
92
-
93
- type Took = 'named' | 'chat' | 'clm';
94
- type Question = {
95
- readonly kind: DecisionKind;
96
- readonly capture_id: string | null;
97
- readonly chat: string | null;
98
- readonly clm: {
99
- readonly id: string;
100
- readonly rightness: number;
101
- } | null;
102
- readonly took: Took;
103
- readonly taken: string | null;
104
- };
105
- type DecisionReport = {
106
- readonly id: string;
107
- readonly surface: 'canvas';
108
- readonly questions: readonly Question[];
109
- readonly applied: string | null;
110
- readonly asked: boolean;
111
- };
112
-
113
- type Transport = (path: `/api/v1/candidates/${string}`, init: {
114
- readonly method: 'POST';
115
- readonly body: unknown;
116
- }) => Promise<{
117
- readonly status: number;
118
- readonly body: unknown;
119
- }>;
120
- type RankRequest = {
121
- readonly request: string;
122
- readonly statement: string;
123
- readonly candidates: readonly Candidate[];
124
- };
125
- type Score = {
126
- readonly id: string;
127
- readonly score: number;
128
- readonly rightness: number;
129
- };
130
- type Threshold = {
131
- readonly from: number;
132
- };
133
- type Thresholds = Readonly<Partial<Record<DecisionKind, Threshold>>>;
134
- type Ranked = {
135
- readonly capture_id: string;
136
- readonly head: string;
137
- readonly scores: readonly Score[];
138
- readonly thresholds: Thresholds;
139
- };
140
-
141
- type Part = 'train' | 'calibration' | 'held_out';
142
- type Origin = 'real' | 'synthetic';
143
- type TrainingRow = {
144
- readonly request: string;
145
- readonly statement: string;
146
- readonly candidates: readonly Candidate[];
147
- readonly label: string;
148
- readonly part: Part;
149
- readonly origin: Origin;
150
- readonly turn: string;
151
- readonly chat: string | null;
152
- };
153
- type LabelledQuestion = {
154
- readonly kind: DecisionKind;
155
- readonly candidates: readonly Candidate[];
156
- readonly label: string;
157
- readonly chat: string | null;
158
- };
159
- type LabelledTurn = {
160
- readonly id: string;
161
- readonly request: string;
162
- readonly statement: string;
163
- readonly origin: Origin;
164
- readonly questions: readonly LabelledQuestion[];
165
- };
166
- declare function partOf(key: string): Part;
167
- declare function trainingRows(turn: LabelledTurn, part: Part): TrainingRow[];
168
-
169
- declare function sure(ranked: Ranked, kind: DecisionKind): boolean;
170
- type Readings = {
171
- readonly kind: DecisionKind;
172
- readonly chat: string | null;
173
- readonly ranked: Ranked | null;
174
- };
175
- type Composed = {
176
- readonly took: 'chat' | 'clm';
177
- readonly taken: string | null;
178
- readonly clm: {
179
- readonly id: string;
180
- readonly rightness: number;
181
- } | null;
182
- readonly differed: boolean;
183
- };
184
- declare function compose({ kind, chat, ranked }: Readings): Composed;
185
-
186
- type CanvasInput = RenderInput & {
187
- readonly sensitive: boolean;
188
- };
189
-
190
27
  type CanvasEditor = Pick<EditorPort, 'apply' | 'save' | 'generate' | 'wiringCandidates'>;
191
28
  type CanvasToolPorts = {
192
29
  readonly source: SourcePort;
193
30
  readonly editor: CanvasEditor;
194
31
  readonly commands: CommandsPort;
195
- readonly transport?: Transport;
196
32
  };
197
33
  type ModuleToolPorts = {
198
34
  readonly commands: CommandsPort;
199
35
  };
200
36
 
201
- type ChangeTarget = {
202
- readonly scope: string;
203
- readonly instance: string;
204
- readonly input?: string;
205
- };
206
- type InputBinding = {
207
- readonly mode: CanvasInput['mode'];
208
- readonly value?: unknown;
209
- readonly variable?: string;
210
- readonly expression?: string;
211
- readonly wiredSource?: string;
212
- };
213
- type InstancePresence = {
214
- readonly instance: string;
215
- readonly module: string;
216
- };
217
- type ChangeState = InputBinding | InstancePresence | null;
218
- type RecordQuestion = {
219
- readonly kind: DecisionKind;
220
- readonly candidates: readonly string[];
221
- };
222
- type ChangeRecord = {
223
- readonly id: string;
224
- readonly target: ChangeTarget;
225
- readonly before: ChangeState;
226
- readonly after: ChangeState;
227
- readonly revision?: number;
228
- readonly questions: readonly RecordQuestion[];
229
- readonly reported: boolean;
230
- };
231
-
232
37
  declare const canvasToolSchemas: readonly [ToolSchema, ToolSchema, ToolSchema, ToolSchema];
233
- type ChangeResult = ToolResult & {
234
- readonly applied: readonly ChangeRecord[];
235
- };
236
38
  type CanvasTools = readonly [
237
- ToolRegistration<ChangeResult>,
39
+ ToolRegistration,
238
40
  ToolRegistration,
239
41
  ToolRegistration,
240
42
  ToolRegistration
241
- ] & {
242
- readonly dispose: () => void;
243
- };
43
+ ];
244
44
  declare function canvasTools(ports: CanvasToolPorts): CanvasTools;
245
45
 
246
46
  declare const moduleToolSchemas: readonly [ToolSchema, ToolSchema, ToolSchema];
247
- type ModuleToolResult = ToolResult & {
248
- readonly failure?: CommandFailure;
47
+ type ModuleToolResult = ToolResult & Partial<ModuleToolData>;
48
+ type ModuleToolData = {
49
+ readonly failure: CommandFailure;
249
50
  };
250
51
  type ModuleTools = readonly [
251
52
  ToolRegistration<ModuleToolResult>,
@@ -254,11 +55,6 @@ type ModuleTools = readonly [
254
55
  ];
255
56
  declare function moduleTools({ commands }: ModuleToolPorts): ModuleTools;
256
57
 
257
- declare function changeOutcomes(record: ChangeRecord, frames: readonly CanvasSource[], own?: ReadonlySet<number>): {
258
- readonly record: ChangeRecord;
259
- readonly outcomes: OutcomeReport[];
260
- };
261
-
262
58
  declare function renderCanvas(source: CanvasSource): string;
263
59
 
264
- export { type Candidate, type CandidateFacts, type CanvasEditor, type CanvasToolPorts, type CanvasTools, type ChangeOutcome, type ChangeRecord, type ChangeResult, type ChangeState, type ChangeTarget, type Composed, DECISION_KINDS, type DecisionKind, type DecisionReport, type InputBinding, type InstancePresence, type LabelledQuestion, type LabelledTurn, type ModuleToolPorts, type ModuleToolResult, type ModuleTools, NONE_CANDIDATE_ID, type Origin, type OutcomeReport, type Part, type Question, type RankRequest, type Ranked, type Readings, type Score, type Threshold, type Thresholds, type Took, type ToolHandler, type ToolRegistration, type ToolRegistry, type ToolResult, type ToolSchema, type TrainingRow, type Transport, VALUE_PLACEHOLDER, canvasToolSchemas, canvasTools, changeOutcomes, compose, createToolRegistry, moduleToolSchemas, moduleTools, partOf, renderCandidate, renderCanvas, renderRequest, sure, trainingRows };
60
+ export { type CanvasEditor, type CanvasToolPorts, type CanvasTools, type ModuleToolPorts, type ModuleToolResult, type ModuleTools, type ToolHandler, type ToolRegistration, type ToolRegistry, type ToolResult, type ToolSchema, canvasToolSchemas, canvasTools, createToolRegistry, moduleToolSchemas, moduleTools, renderCanvas };