@signalcore/ui 1.0.0-beta.1 → 1.0.0-beta.3

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 (138) hide show
  1. package/README.md +55 -22
  2. package/dist/AgentAbout.js +11 -4
  3. package/dist/AgentAbout.js.map +1 -1
  4. package/dist/AgentChat.d.ts +7 -1
  5. package/dist/AgentChat.js +154 -2
  6. package/dist/AgentChat.js.map +1 -1
  7. package/dist/AgentSpace.d.ts +12 -3
  8. package/dist/AgentSpace.js +53 -11
  9. package/dist/AgentSpace.js.map +1 -1
  10. package/dist/AgentTasks.js +2 -1
  11. package/dist/AgentTasks.js.map +1 -1
  12. package/dist/Threads.d.ts +73 -0
  13. package/dist/Threads.js +140 -0
  14. package/dist/Threads.js.map +1 -0
  15. package/dist/VoiceCall.js +1 -1
  16. package/dist/VoiceCall.js.map +1 -1
  17. package/dist/about.d.ts +34 -144
  18. package/dist/about.js +6 -8
  19. package/dist/about.js.map +1 -1
  20. package/dist/automation/cron.d.ts +1 -1
  21. package/dist/automation/cron.js.map +1 -1
  22. package/dist/automation/marks.js +13 -5
  23. package/dist/automation/marks.js.map +1 -1
  24. package/dist/automation/messages.d.ts +6 -0
  25. package/dist/automation/messages.js +7 -1
  26. package/dist/automation/messages.js.map +1 -1
  27. package/dist/automation/types.d.ts +25 -128
  28. package/dist/automation/types.js +36 -0
  29. package/dist/automation/types.js.map +1 -0
  30. package/dist/automation/when.d.ts +1 -1
  31. package/dist/automation/when.js +13 -1
  32. package/dist/automation/when.js.map +1 -1
  33. package/dist/blocks.d.ts +23 -1
  34. package/dist/browser.js +2 -2
  35. package/dist/browser.js.map +1 -1
  36. package/dist/call.d.ts +1 -1
  37. package/dist/call.js.map +1 -1
  38. package/dist/client.d.ts +14 -4
  39. package/dist/client.js +7 -2
  40. package/dist/client.js.map +1 -1
  41. package/dist/contract.d.ts +267 -0
  42. package/dist/credentials.js.map +1 -1
  43. package/dist/dev.js +1 -1
  44. package/dist/dev.js.map +1 -1
  45. package/dist/es.d.ts +2 -0
  46. package/dist/es.js +31 -4
  47. package/dist/es.js.map +1 -1
  48. package/dist/frames.d.ts +7 -1
  49. package/dist/frames.js.map +1 -1
  50. package/dist/index.d.ts +6 -5
  51. package/dist/index.js +6 -4
  52. package/dist/kit/AudioPlayer.js +1 -1
  53. package/dist/kit/AudioPlayer.js.map +1 -1
  54. package/dist/kit/Choices.js +1 -1
  55. package/dist/kit/Choices.js.map +1 -1
  56. package/dist/kit/FileField.js +1 -1
  57. package/dist/kit/FileField.js.map +1 -1
  58. package/dist/kit/Popover.js.map +1 -1
  59. package/dist/kit/Tile.d.ts +1 -1
  60. package/dist/kit/Tile.js +1 -1
  61. package/dist/kit/Tile.js.map +1 -1
  62. package/dist/kit/messages.d.ts +13 -0
  63. package/dist/kit/messages.js +7 -1
  64. package/dist/kit/messages.js.map +1 -1
  65. package/dist/kit/uploads.d.ts +2 -1
  66. package/dist/kit/uploads.js +1 -1
  67. package/dist/kit/uploads.js.map +1 -1
  68. package/dist/kit/waveform.js.map +1 -1
  69. package/dist/markdown.js.map +1 -1
  70. package/dist/marks.js +2 -3
  71. package/dist/marks.js.map +1 -1
  72. package/dist/surface/Form.js +1 -1
  73. package/dist/surface/Markdown.js +1 -1
  74. package/dist/surface/Markdown.js.map +1 -1
  75. package/dist/surface/Surface.js +43 -4
  76. package/dist/surface/Surface.js.map +1 -1
  77. package/dist/surface/scope.d.ts +1 -1
  78. package/dist/surface/scope.js.map +1 -1
  79. package/dist/surface/values.js +1 -1
  80. package/dist/surface/values.js.map +1 -1
  81. package/dist/tint.d.ts +1 -1
  82. package/dist/tint.js +1 -1
  83. package/dist/tint.js.map +1 -1
  84. package/dist/types.d.ts +11 -0
  85. package/dist/types.js.map +1 -1
  86. package/dist/useConversation.d.ts +2 -0
  87. package/dist/useConversation.js +16 -0
  88. package/dist/useConversation.js.map +1 -1
  89. package/dist/usePolled.js +1 -1
  90. package/dist/usePolled.js.map +1 -1
  91. package/dist/voice/webgl.js +1 -1
  92. package/dist/voice/webgl.js.map +1 -1
  93. package/dist/widget.js +17 -16
  94. package/package.json +1 -1
  95. package/src/AgentAbout.tsx +14 -3
  96. package/src/AgentChat.tsx +203 -1
  97. package/src/AgentSpace.tsx +89 -13
  98. package/src/AgentTasks.tsx +2 -2
  99. package/src/Threads.tsx +218 -0
  100. package/src/VoiceCall.tsx +1 -1
  101. package/src/about.ts +42 -144
  102. package/src/automation/cron.ts +1 -1
  103. package/src/automation/marks.tsx +13 -2
  104. package/src/automation/messages.ts +12 -0
  105. package/src/automation/types.ts +58 -118
  106. package/src/automation/when.ts +7 -1
  107. package/src/blocks.ts +25 -0
  108. package/src/browser.ts +4 -4
  109. package/src/call.ts +1 -1
  110. package/src/client.ts +26 -10
  111. package/src/contract.ts +1934 -0
  112. package/src/credentials.ts +2 -2
  113. package/src/dev.ts +1 -1
  114. package/src/es.ts +29 -0
  115. package/src/frames.ts +3 -1
  116. package/src/index.ts +10 -1
  117. package/src/kit/AudioPlayer.tsx +1 -1
  118. package/src/kit/Choices.tsx +1 -1
  119. package/src/kit/FileField.tsx +1 -1
  120. package/src/kit/Popover.tsx +1 -1
  121. package/src/kit/Tile.tsx +1 -1
  122. package/src/kit/messages.ts +20 -0
  123. package/src/kit/uploads.ts +2 -2
  124. package/src/kit/waveform.ts +1 -1
  125. package/src/markdown.ts +1 -1
  126. package/src/marks.tsx +3 -123
  127. package/src/styles.css +206 -0
  128. package/src/surface/Markdown.tsx +1 -1
  129. package/src/surface/Surface.tsx +53 -4
  130. package/src/surface/scope.ts +3 -1
  131. package/src/surface/values.ts +5 -5
  132. package/src/tint.ts +1 -1
  133. package/src/types.ts +11 -0
  134. package/src/useConversation.ts +10 -0
  135. package/src/usePolled.ts +2 -2
  136. package/src/voice/webgl.ts +1 -1
  137. package/src/widget/element.tsx +13 -4
  138. package/src/widget/widget.css +13 -0
@@ -1,146 +1,86 @@
1
1
  /**
2
2
  * An agent's automations and their runs, as the API gives them (v3/AUTOMATIONS.md): what starts
3
- * each one, the steps its code names, the table it moves, and every run with its record. Written
4
- * by hand, one to one with the API's answers; times are ISO 8601 in UTC.
3
+ * each one, the steps its code names, the table it moves, and every run with its record. The
4
+ * contract's own types (`contract.ts`, generated from the API's); times are ISO 8601 in UTC.
5
5
  */
6
6
 
7
+ import type * as C from "../contract";
8
+
7
9
  /**
8
10
  * What a step uses, as the manifest reads it from the code before any run: an app, the model,
9
11
  * the agent, the owner's inbox, a message to a contact on a channel (`sc.send`), a table, the web.
10
12
  */
11
- export interface Use {
12
- kind: "app" | "ai" | "agent" | "notify" | "send" | "data" | "http";
13
- /** An app's: the connection's name (its alias). */
14
- app: string | null;
15
- /** An app's: its display name. */
16
- title: string | null;
17
- /** An app's: its logo (https), when known. */
18
- icon: string | null;
19
- }
13
+ export type Use = C.Use;
20
14
 
21
15
  /** A step of the code (`sc.step("…")`), in the code's order, with what it uses. */
22
- export interface Step {
23
- name: string;
24
- uses: Use[];
25
- }
16
+ export type Step = C.Step;
26
17
 
27
- /** What starts an automation: a time (cron, on a zone's clock), a call to its URL, an app's event. */
28
- export interface Trigger {
29
- kind: "schedule" | "webhook" | "event";
30
- /** Five-field cron. */
31
- schedule: string | null;
32
- /** IANA zone. */
33
- timezone: string | null;
34
- /** The webhook's full URL. */
35
- url: string | null;
36
- /** An event's app: the connection's name, its display name, its logo. */
37
- app: string | null;
38
- app_title: string | null;
39
- /** The provider's event slug, and the event in words when the provider gives them. */
40
- event: string | null;
41
- event_title: string | null;
42
- icon: string | null;
43
- }
18
+ /** What starts an automation: a time (cron, on a zone's clock), a call to its URL, an app's
19
+ * event, one of the platform's. */
20
+ export type Trigger = C.TriggerView;
44
21
 
45
- /** The table an automation moves, as counts of its rows per value of one field. */
46
- export interface Board {
47
- table: string;
48
- /** The table's title. */
49
- title: string;
50
- /** The field the rows are counted by. */
51
- field: string;
52
- /** Per value, biggest first, at most 8. */
53
- counts: { value: string; count: number }[];
54
- }
22
+ /** The table an automation moves, as counts of its rows per value of one field (biggest first,
23
+ * at most 8). */
24
+ export type Board = C.Board;
55
25
 
56
- export type RunStatus = "running" | "waiting" | "done" | "failed" | "skipped";
26
+ export type RunStatus = C.RunOut["status"];
57
27
 
58
- /** What started a run: its time, a call, an app's event, the agent in a chat, a test. */
59
- export type RunBy = "schedule" | "webhook" | "event" | "agent" | "test";
28
+ /** What started a run: its time, a call, an app's event, the platform, the agent, a test. */
29
+ export type RunBy = C.RunOut["by"];
60
30
 
61
31
  /** One start of an automation, whatever started it. */
62
- export interface Run {
63
- id: string;
64
- agent_id: string;
65
- /** The automation's name. */
66
- automation: string;
67
- /** The automation's title when it ran. */
68
- title: string;
69
- by: RunBy;
70
- /** Started by the agent: the conversation it was asked in. */
71
- conversation_id: string | null;
72
- status: RunStatus;
73
- /** What the code returned: the run's one line. */
74
- summary: string | null;
75
- /** Why it failed, in words, naming the step: "Paró en «…»: …". */
76
- error: string | null;
77
- /** A test: what would change the world was recorded, not done. */
78
- dry: boolean;
79
- started_at: string;
80
- ended_at: string | null;
81
- tokens_in: number;
82
- tokens_out: number;
83
- /** The conversations it opened. */
84
- opened: string[];
85
- }
32
+ export type Run = C.RunOut;
86
33
 
87
34
  /** One call of a run's record, in the order it was made. */
88
- export interface RunStep {
89
- seq: number;
90
- /** The `sc.step` it ran in. */
91
- step: string | null;
92
- /**
93
- * `tool:<app>.<TOOL>` · `ai` · `notify` · `send` · `agent.start` · `data.find` · `data.add` ·
94
- * `data.update` · `http` · `files.search` · `memory.remember` · `memory.recall`.
95
- */
96
- call: string;
97
- /** Both trimmed. */
98
- input: unknown;
99
- output: unknown;
100
- error: string | null;
101
- ms: number;
102
- at: string;
103
- /** A test's write: recorded, not done. */
104
- would: boolean;
105
- }
35
+ export type RunStep = C.RunStepOut;
106
36
 
107
37
  /** A run with its record (`GET /runs/{id}`). */
108
- export type RunRecord = Run & { steps: RunStep[] };
38
+ export type RunRecord = C.RunDetailOut;
109
39
 
110
- export type AutomationState = "active" | "paused" | "failing";
40
+ export type AutomationState = C.AutomationOut["state"];
111
41
 
112
42
  /** One automation: `automations/<name>.py` in the agent's folder, with its trigger and its state. */
113
- export interface Automation {
114
- /** Its trigger's id. */
115
- id: string;
116
- agent_id: string;
117
- /** Its file's name; unique per agent. */
118
- name: string;
119
- title: string;
120
- /** What it does, in the owner's words. */
121
- summary: string;
122
- trigger: Trigger;
123
- on: boolean;
124
- next_run_at: string | null;
125
- steps: Step[];
126
- board: Board | null;
127
- /** `failing`: its last finished real run failed. */
128
- state: AutomationState;
129
- /** Its newest run, tests included. */
130
- last_run: Run | null;
131
- }
43
+ export type Automation = C.AutomationOut;
132
44
 
133
45
  /** An automation with its newest runs (`GET /agents/{id}/automations/{name}`: 20; in a block: 5). */
134
- export type AutomationView = Automation & { runs: Run[] };
46
+ export type AutomationView = C.AutomationDetailOut;
135
47
 
136
48
  /**
137
- * A task the agent runs for one contact (`GET /agents/{id}/tasks`): set up in words in a
138
- * conversation with them, read as an automation is (its instruction is its `summary`, its trigger
139
- * a schedule: a cron line, or none for a task once at `next_run_at`), with its newest five runs.
49
+ * A task the agent runs for one contact (`GET /agents/{id}/tasks`): an instance of an automation
50
+ * for contacts (`automation`), or of the platform's instruction (its words in `inputs`), on a
51
+ * schedule (a cron line, or once at `next_run_at`), with its newest five runs.
140
52
  */
141
- export type Task = AutomationView & {
142
- contact_id: string;
143
- /** The conversation it runs in: the one it was set up in. */
144
- conversation_id: string | null;
145
- created_at: string;
146
- };
53
+ export type Task = C.TaskOut;
54
+
55
+ /** A task as the automation card draws it, from what it is: its words its summary, its trigger
56
+ * its schedule, failing when its last finished real run failed. */
57
+ export function taskCard(task: Task): AutomationView {
58
+ const ended = task.runs.filter((run) => run.status !== "running" && run.status !== "waiting");
59
+ const last = ended.find((run) => !run.dry);
60
+ const words = task.inputs["instruction"];
61
+ return {
62
+ id: task.id,
63
+ agent_id: task.agent_id,
64
+ name: task.automation ?? "instruction",
65
+ title: task.title,
66
+ summary: typeof words === "string" ? words : "",
67
+ trigger: {
68
+ kind: "schedule",
69
+ schedule: task.schedule,
70
+ timezone: task.timezone,
71
+ url: null,
72
+ app: null,
73
+ app_title: null,
74
+ event: null,
75
+ event_title: null,
76
+ icon: null,
77
+ },
78
+ on: task.on,
79
+ next_run_at: task.next_run_at,
80
+ steps: [],
81
+ board: null,
82
+ state: !task.on ? "paused" : last?.status === "failed" ? "failing" : "active",
83
+ last_run: task.runs[0] ?? null,
84
+ runs: task.runs,
85
+ };
86
+ }
@@ -24,7 +24,7 @@ export interface When {
24
24
  timed: boolean;
25
25
  }
26
26
 
27
- /** A trigger in words: its schedule as a sentence, a webhook's call, an app's event. */
27
+ /** A trigger in words: its schedule as a sentence, a webhook's call, an app's event, a message. */
28
28
  export function whenOf(trigger: Trigger, words: AutomationMessages, code: string): When {
29
29
  switch (trigger.kind) {
30
30
  case "schedule":
@@ -33,6 +33,12 @@ export function whenOf(trigger: Trigger, words: AutomationMessages, code: string
33
33
  : scheduleOf(trigger.schedule, words, code);
34
34
  case "webhook":
35
35
  return { text: words.webhook, timed: false };
36
+ case "platform":
37
+ return { text: words.platform, timed: false };
38
+ case "manual":
39
+ return { text: words.manual, timed: false };
40
+ case "after":
41
+ return { text: words.after(trigger.after ?? null), timed: false };
36
42
  case "event":
37
43
  return {
38
44
  text: words.event(trigger.app_title ?? trigger.app, trigger.event_title),
package/src/blocks.ts CHANGED
@@ -100,6 +100,30 @@ export interface AutomationBlock {
100
100
  view: AutomationView | null;
101
101
  }
102
102
 
103
+ /**
104
+ * How the connection an app's card asked for stands: its name and logo, and where the person
105
+ * authorizes it while it waits for them.
106
+ */
107
+ export interface ConnectView {
108
+ title: string;
109
+ icon: string | null;
110
+ status: "pending" | "active" | "error" | "disconnected";
111
+ url: string | null;
112
+ }
113
+
114
+ /**
115
+ * An app for the person to connect, drawn by the platform alone (the agent's `connect_app`,
116
+ * never composed): its name and logo, the line the agent wrote of what it will do with it, and
117
+ * the button that opens its consent page; the API fills in `connection`, and the card changes
118
+ * live as it does (waiting, working, failed). Null while there is none yet.
119
+ */
120
+ export interface ConnectBlock {
121
+ type: "connect";
122
+ app: string;
123
+ purpose: string;
124
+ connection: ConnectView | null;
125
+ }
126
+
103
127
  // --- Action -------------------------------------------------------------------------------
104
128
 
105
129
  /** One thing the person can do: pressing it sends `action`, or, with `url`, opens that page. */
@@ -238,6 +262,7 @@ export type Block =
238
262
  | ImageBlock
239
263
  | AutomationBlock
240
264
  | FileBlock
265
+ | ConnectBlock
241
266
  | ButtonBlock
242
267
  | ChoiceBlock
243
268
  | FormBlock;
package/src/browser.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  import type { BrowserFrame, BrowserInput, Message } from "./types";
7
7
 
8
8
  /** The action that hands the person the browser; the turn waits on it until they give it back. */
9
- export const HAND_OVER = "browser_hand_over";
9
+ const HAND_OVER = "browser_hand_over";
10
10
 
11
11
  /**
12
12
  * The browser's screen as it comes: the latest picture, and whoever watches. Kept out of the
@@ -66,7 +66,7 @@ export function siteOf(url: string): { host: string; rest: string } {
66
66
  }
67
67
  }
68
68
 
69
- export interface Size {
69
+ interface Size {
70
70
  width: number;
71
71
  height: number;
72
72
  }
@@ -86,7 +86,7 @@ export function pointOf(
86
86
  }
87
87
 
88
88
  /** DevTools' mask of the keys held with another: Alt 1, Ctrl 2, Meta 4, Shift 8. */
89
- export function modifiersOf(event: {
89
+ function modifiersOf(event: {
90
90
  altKey: boolean;
91
91
  ctrlKey: boolean;
92
92
  metaKey: boolean;
@@ -268,7 +268,7 @@ export function bytesOf(base64: string): Uint8Array<ArrayBuffer> {
268
268
  }
269
269
 
270
270
  /** Draws a picture on a canvas, unless a newer one comes while it is still being decoded. */
271
- export interface Painter {
271
+ interface Painter {
272
272
  paint: (jpeg: string) => void;
273
273
  dispose: () => void;
274
274
  }
package/src/call.ts CHANGED
@@ -34,7 +34,7 @@ export type CallProblem =
34
34
  | "unsupported"
35
35
  /** Calls aren't set up where the agent works (the API refused with `no_calls`). */
36
36
  | "off"
37
- /** The agent takes no calls: a squad's builder (`builder`). */
37
+ /** The agent takes no calls: the builder (`builder`). */
38
38
  | "builder"
39
39
  /** The API wouldn't make the call, for any other reason it named. */
40
40
  | "refused"
package/src/client.ts CHANGED
@@ -127,8 +127,10 @@ export interface Client {
127
127
  /** Takes one memory from it. */
128
128
  forget: (id: string, memoryId: string) => Promise<void>;
129
129
  /**
130
- * The owner's call with the agent, from the browser (v3/VOICE.md): the call and its
131
- * conversation (a test) made now, and where to join it (`VoiceCall`'s `connect`).
130
+ * The owner's call with the agent, from our own app (v3/VOICE.md): the call and its
131
+ * conversation (a test) made now, and where to join it (`VoiceCall`'s `connect`). App only:
132
+ * it is `/api`'s, signed in by the owner's cookie, and 404s on `/v1`; a host's page calls with
133
+ * `conversations.call(agentId)`.
132
134
  */
133
135
  call: (id: string) => Promise<CallToken>;
134
136
  };
@@ -169,8 +171,14 @@ export interface Client {
169
171
  conversations: {
170
172
  /** One conversation with its messages. */
171
173
  get: (id: string) => Promise<ConversationDetail>;
172
- /** A new conversation with an agent. */
173
- start: (agentId: string) => Promise<Conversation>;
174
+ /** The agent's conversations, newest first: a person's own only, each with what is unread. */
175
+ list: (agentId: string) => Promise<Conversation[]>;
176
+ /** A new conversation with an agent, titled when given. */
177
+ start: (agentId: string, options?: { title?: string | undefined }) => Promise<Conversation>;
178
+ /** How far the person has read it: all of it, now. */
179
+ read: (id: string) => Promise<Conversation>;
180
+ /** Its title, as the person gives it. */
181
+ rename: (id: string, title: string) => Promise<Conversation>;
174
182
  /** The files that arrived in a conversation: attached, sent through a form. */
175
183
  files: (id: string) => Promise<ConversationFile[]>;
176
184
  /**
@@ -201,6 +209,10 @@ export interface Client {
201
209
 
202
210
  const seg = encodeURIComponent;
203
211
 
212
+ /** A request's JSON body. */
213
+ const body = (value: unknown): Blob =>
214
+ new Blob([JSON.stringify(value)], { type: "application/json" });
215
+
204
216
  /** A file's path in a URL: each name of it encoded, the slashes between them kept. */
205
217
  const filePath = (path: string): string => path.split("/").map(seg).join("/");
206
218
 
@@ -357,11 +369,7 @@ export function createClient(options: ClientOptions): Client {
357
369
  tasks: {
358
370
  list: (agentId) => json("GET", `/agents/${seg(agentId)}/tasks`),
359
371
  switch: (agentId, taskId, on) =>
360
- json(
361
- "PATCH",
362
- `/agents/${seg(agentId)}/tasks/${seg(taskId)}`,
363
- new Blob([JSON.stringify({ on })], { type: "application/json" }),
364
- ),
372
+ json("PATCH", `/agents/${seg(agentId)}/tasks/${seg(taskId)}`, body({ on })),
365
373
  remove: (agentId, taskId) => run("DELETE", `/agents/${seg(agentId)}/tasks/${seg(taskId)}`),
366
374
  },
367
375
  channels: {
@@ -370,7 +378,15 @@ export function createClient(options: ClientOptions): Client {
370
378
  },
371
379
  conversations: {
372
380
  get: (id) => json("GET", `/conversations/${seg(id)}`),
373
- start: (agentId) => json("POST", `/agents/${seg(agentId)}/conversations`),
381
+ list: (agentId) => json("GET", `/agents/${seg(agentId)}/conversations`),
382
+ start: (agentId, { title } = {}) =>
383
+ json(
384
+ "POST",
385
+ `/agents/${seg(agentId)}/conversations`,
386
+ title === undefined ? undefined : body({ title }),
387
+ ),
388
+ read: (id) => json("POST", `/conversations/${seg(id)}/read`, body({})),
389
+ rename: (id, title) => json("PATCH", `/conversations/${seg(id)}`, body({ title })),
374
390
  files: (id) => json("GET", `/conversations/${seg(id)}/files`),
375
391
  upload: (id, file, options) => sendFile(`/conversations/${seg(id)}/files`, file, options),
376
392
  play: async (id, fileId) => {