@signalcore/ui 1.0.0-beta.0 → 1.0.0-beta.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.
- package/README.md +8 -1
- package/dist/AgentAbout.js +7 -4
- package/dist/AgentAbout.js.map +1 -1
- package/dist/AgentChat.js +10 -2
- package/dist/AgentChat.js.map +1 -1
- package/dist/AgentTasks.js +2 -1
- package/dist/AgentTasks.js.map +1 -1
- package/dist/VoiceCall.js +1 -1
- package/dist/VoiceCall.js.map +1 -1
- package/dist/about.d.ts +34 -144
- package/dist/about.js +6 -8
- package/dist/about.js.map +1 -1
- package/dist/automation/cron.d.ts +1 -1
- package/dist/automation/cron.js.map +1 -1
- package/dist/automation/marks.js +7 -3
- package/dist/automation/marks.js.map +1 -1
- package/dist/automation/messages.d.ts +2 -0
- package/dist/automation/messages.js +2 -0
- package/dist/automation/messages.js.map +1 -1
- package/dist/automation/types.d.ts +25 -128
- package/dist/automation/types.js +36 -0
- package/dist/automation/types.js.map +1 -0
- package/dist/automation/when.d.ts +1 -1
- package/dist/automation/when.js +5 -1
- package/dist/automation/when.js.map +1 -1
- package/dist/blocks.d.ts +23 -1
- package/dist/browser.js +2 -2
- package/dist/browser.js.map +1 -1
- package/dist/call.d.ts +1 -1
- package/dist/call.js.map +1 -1
- package/dist/contract.d.ts +262 -0
- package/dist/credentials.js.map +1 -1
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/es.js +9 -1
- package/dist/es.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/kit/AudioPlayer.js +1 -1
- package/dist/kit/AudioPlayer.js.map +1 -1
- package/dist/kit/Choices.js +1 -1
- package/dist/kit/Choices.js.map +1 -1
- package/dist/kit/FileField.js +1 -1
- package/dist/kit/FileField.js.map +1 -1
- package/dist/kit/Popover.js.map +1 -1
- package/dist/kit/Tile.d.ts +1 -1
- package/dist/kit/Tile.js +1 -1
- package/dist/kit/Tile.js.map +1 -1
- package/dist/kit/messages.d.ts +13 -0
- package/dist/kit/messages.js +7 -1
- package/dist/kit/messages.js.map +1 -1
- package/dist/kit/uploads.d.ts +2 -1
- package/dist/kit/uploads.js +1 -1
- package/dist/kit/uploads.js.map +1 -1
- package/dist/kit/waveform.js.map +1 -1
- package/dist/markdown.js.map +1 -1
- package/dist/marks.js +2 -3
- package/dist/marks.js.map +1 -1
- package/dist/surface/Markdown.js +1 -1
- package/dist/surface/Markdown.js.map +1 -1
- package/dist/surface/Surface.js +43 -4
- package/dist/surface/Surface.js.map +1 -1
- package/dist/surface/scope.d.ts +1 -1
- package/dist/surface/scope.js.map +1 -1
- package/dist/surface/values.js +1 -1
- package/dist/surface/values.js.map +1 -1
- package/dist/tint.d.ts +1 -1
- package/dist/tint.js +1 -1
- package/dist/tint.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.js.map +1 -1
- package/dist/usePolled.js +1 -1
- package/dist/usePolled.js.map +1 -1
- package/dist/voice/webgl.js +1 -1
- package/dist/voice/webgl.js.map +1 -1
- package/dist/widget.js +14 -14
- package/package.json +1 -1
- package/src/AgentAbout.tsx +10 -3
- package/src/AgentChat.tsx +20 -3
- package/src/AgentTasks.tsx +2 -2
- package/src/VoiceCall.tsx +1 -1
- package/src/about.ts +42 -144
- package/src/automation/cron.ts +1 -1
- package/src/automation/marks.tsx +6 -2
- package/src/automation/messages.ts +4 -0
- package/src/automation/types.ts +58 -118
- package/src/automation/when.ts +3 -1
- package/src/blocks.ts +25 -0
- package/src/browser.ts +4 -4
- package/src/call.ts +1 -1
- package/src/contract.ts +1720 -0
- package/src/credentials.ts +2 -2
- package/src/dev.ts +1 -1
- package/src/es.ts +8 -0
- package/src/index.ts +2 -0
- package/src/kit/AudioPlayer.tsx +1 -1
- package/src/kit/Choices.tsx +1 -1
- package/src/kit/FileField.tsx +1 -1
- package/src/kit/Popover.tsx +1 -1
- package/src/kit/Tile.tsx +1 -1
- package/src/kit/messages.ts +20 -0
- package/src/kit/uploads.ts +2 -2
- package/src/kit/waveform.ts +1 -1
- package/src/markdown.ts +1 -1
- package/src/marks.tsx +3 -123
- package/src/styles.css +24 -0
- package/src/surface/Markdown.tsx +1 -1
- package/src/surface/Surface.tsx +53 -4
- package/src/surface/scope.ts +3 -1
- package/src/surface/values.ts +5 -5
- package/src/tint.ts +1 -1
- package/src/types.ts +8 -0
- package/src/usePolled.ts +2 -2
- package/src/voice/webgl.ts +1 -1
package/dist/VoiceCall.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoiceCall.js","names":[],"sources":["../src/VoiceCall.tsx"],"sourcesContent":["import {\n MicrophoneIcon,\n MicrophoneSlashIcon,\n PhoneDisconnectIcon,\n SpeakerHighIcon,\n} from \"@phosphor-icons/react\";\nimport { useEffect, useRef, useState, type ReactNode, type RefObject } from \"react\";\n\nimport {\n durationOf,\n keyBelongsElsewhere,\n lookOf,\n orbOf,\n type CallEndedBy,\n type CallLook,\n type CallProblem,\n type CallState,\n} from \"./call\";\nimport { classes } from \"./classes\";\nimport { Button } from \"./kit/Button\";\nimport { KitProvider, type KitClassNames, type KitPart } from \"./kit/context\";\nimport type { AgentTint } from \"./tint\";\nimport { useCall, type CallJoin } from \"./useCall\";\nimport { Orb } from \"./voice/Orb\";\nimport type { OrbStyle } from \"./voice/orbs\";\n\n/** How big the orb is drawn: large, in the middle, with room for it to grow when the voice is loud. */\nconst ORB_SIZE = 280;\n\n/** The orb's level where nobody it follows is speaking. */\nconst SILENT = (): number => 0;\n\n/** The words a call says; a host gives its own, in its language. */\nexport interface VoiceCallMessages {\n /** The call's name, for those who can't see it. */\n call: (name: string) => string;\n /** What the call is doing, in a word or two. */\n states: Readonly<Record<Exclude<CallLook, \"problem\">, string>>;\n /** Under the state while the call connects. */\n calling: (name: string) => string;\n /** Why the call ended, before how long it lasted. */\n ended: Readonly<Record<CallEndedBy, (name: string) => string>>;\n /** Why the call never began, and what the person can do about it. */\n problems: Readonly<Record<CallProblem, { title: (name: string) => string; help: string }>>;\n mute: string;\n hangUp: string;\n /** Under the controls, where there is a keyboard. */\n keys: string;\n /** Under the controls while the microphone is off. */\n muted: string;\n /** The browser held the agent's voice until a press: the button that lets it play. */\n hear: (name: string) => string;\n}\n\nexport const VOICE_CALL_MESSAGES: VoiceCallMessages = {\n call: (name) => `Call with ${name}`,\n states: {\n connecting: \"Connecting…\",\n listening: \"Listening\",\n thinking: \"Thinking\",\n speaking: \"Speaking\",\n reconnecting: \"Reconnecting…\",\n ended: \"Call ended\",\n },\n calling: (name) => `Calling ${name}`,\n ended: {\n person: () => \"You hung up\",\n agent: (name) => `${name} hung up`,\n limit: () => \"It reached its longest time\",\n dropped: () => \"The line dropped\",\n },\n problems: {\n denied: {\n title: () => \"The microphone isn't allowed\",\n help: \"Allow the microphone for this page (the icon beside the address) and call again.\",\n },\n nomic: {\n title: () => \"No microphone\",\n help: \"Plug one in, or pick another in your system's sound settings, and call again.\",\n },\n inuse: {\n title: () => \"The microphone is busy\",\n help: \"Another app is using it. Close it and call again.\",\n },\n unsupported: {\n title: () => \"This browser can't call\",\n help: \"Open this page over https in a recent Chrome, Edge, Safari or Firefox.\",\n },\n off: {\n title: () => \"Calls aren't set up\",\n help: \"Calls are turned on where your agents work. Ask whoever set it up.\",\n },\n builder: {\n title: (name) => `${name} doesn't take calls`,\n help: \"A squad's builder only writes. Call one of the squad's agents.\",\n },\n refused: {\n title: (name) => `${name} can't take this call`,\n help: \"Try again in a moment.\",\n },\n failed: {\n title: (name) => `Couldn't call ${name}`,\n help: \"Check your connection and try again.\",\n },\n unanswered: {\n title: (name) => `${name} isn't answering`,\n help: \"Calls aren't being taken right now. Try again in a moment.\",\n },\n },\n mute: \"Mute\",\n hangUp: \"Hang up\",\n keys: \"Space mutes and unmutes\",\n muted: \"Your microphone is off\",\n hear: (name) => `Hear ${name}`,\n};\n\n/** The call's parts, by the class each carries; `classNames` adds a host's own under the same keys. */\nexport type VoiceCallPart =\n | \"sc-call\"\n | `sc-call--${CallLook}`\n | `sc-call--${AgentTint}`\n | \"sc-call--on\"\n | \"sc-call--muted\"\n | \"sc-call__stage\"\n | \"sc-call__orb\"\n | \"sc-call__state\"\n | \"sc-call__line\"\n | \"sc-call__sound\"\n | \"sc-call__controls\"\n | \"sc-call__control\"\n | \"sc-call__mute\"\n | \"sc-call__hangup\"\n | \"sc-call__hint\"\n | \"sc-call__captions\"\n | \"sc-call__after\";\n\nexport interface VoiceCallProps {\n /**\n * Where to join: LiveKit's address and a token for the call's room (our API's\n * `client.conversations.call(agentId)` answers both, `client.agents.call(id)` for the owner's\n * test). Called once, when the call starts, after the microphone is open.\n */\n connect: () => Promise<CallJoin>;\n /** The agent's name, for the words that say it. */\n name: string;\n /**\n * The agent's own tint (`agentTint(id)`), worn by the call's chrome: the orb's shader paints its\n * own colours, and the still orb that stands in where there is no WebGL wears it.\n */\n tint?: AgentTint | undefined;\n /** How the orb is drawn: `\"wave\"` (the default) or `\"fluid-dots\"`. */\n orb?: OrbStyle | undefined;\n /** The orb's diameter in pixels: 280 by default, less for a call in a small panel. */\n orbSize?: number | undefined;\n /**\n * Why the call ended as the API keeps it, once the host has read it (`endedByReason` of its\n * conversation's call): what the end says when the agent's side closed the room (its goodbye,\n * or its longest time), which the room doesn't tell. Until then the end says how long it was.\n */\n endedBy?: CallEndedBy | null | undefined;\n messages?: Partial<VoiceCallMessages> | undefined;\n /** The host's classes for the call's parts and the kit's (the orb's `sc-orb…`, the buttons'). */\n classNames?: Partial<Record<VoiceCallPart | KitPart, string>> | undefined;\n /**\n * The call is over, once: it ended (`answered`: the agent took it; `problem` null), or it\n * couldn't begin (`problem`: why, which the call shows until the host takes it away).\n */\n onEnd?: ((answered: boolean, problem: CallProblem | null) => void) | undefined;\n /** The agent took the call: its time counts from now. Once. */\n onAnswer?: (() => void) | undefined;\n /** What the host offers once the call is over, in place of the controls: call again, write. */\n after?: ReactNode;\n /** What is being said, drawn by the host under the orb while the call is on (`sc-call__captions`). */\n captions?: ReactNode;\n}\n\n/**\n * A voice call with an agent, the one a customer has on the phone: the call starts when it\n * mounts and ends when it unmounts. The orb, large in the middle, rests while the line is found,\n * moves with whoever speaks (the agent's voice while it speaks, the person's while it listens),\n * calms while the agent thinks, and fades once the call is over; under it what the call\n * is doing in a word, its time, and the two controls a phone has, mute and hang up. A microphone\n * that can't be used, or a call that can't be made (the API's refusal among them), says why in\n * words and what to do; an end says who ended it (the room's own word, or the API's: `endedBy`)\n * and how long it lasted.\n *\n * Space mutes and unmutes from anywhere that isn't a field or a control of the page's own.\n * Escape never hangs up: it is the key that closes things, pressed by reflex, and a call ended\n * by accident can't be taken back, so ending one is the red button's alone. The orb stands\n * still under reduced motion, one frame per state: the words say the rest.\n */\nexport function VoiceCall(props: VoiceCallProps) {\n return (\n <KitProvider classNames={props.classNames as KitClassNames}>\n <Call {...props} />\n </KitProvider>\n );\n}\n\nfunction Call({\n connect,\n name,\n tint = \"sky\",\n orb: style,\n orbSize = ORB_SIZE,\n endedBy,\n messages,\n classNames,\n onEnd,\n onAnswer,\n after,\n captions,\n}: VoiceCallProps) {\n const words = { ...VOICE_CALL_MESSAGES, ...messages };\n const root = useRef<HTMLElement>(null);\n const sink = useRef<HTMLDivElement>(null);\n const call = useCall(connect, { sink });\n const { state } = call;\n const look = lookOf(state);\n const orb = orbOf(look);\n const over = state.stage === \"over\";\n const seconds = useSeconds(state);\n\n useSpace(root, !over, () => {\n call.mute();\n });\n // The call takes the keyboard as it opens, so Space is its from the start; and again once over,\n // when the control that had it is gone, so the host's offers are the next stop.\n useEffect(() => {\n root.current?.focus({ preventScroll: true });\n }, [over]);\n // The host's ears as it last gave them.\n const told = useRef({ onEnd, onAnswer });\n useEffect(() => {\n told.current = { onEnd, onAnswer };\n });\n const answered = state.answeredAt !== null;\n useEffect(() => {\n if (answered) told.current.onAnswer?.();\n }, [answered]);\n useEffect(() => {\n if (over) told.current.onEnd?.(answered, state.problem);\n }, [over]);\n\n const { headline, line } = wordsOf(state, look, seconds, words, name, endedBy ?? null);\n const modifiers: VoiceCallPart[] = [`sc-call--${look}`, `sc-call--${tint}`];\n if (!over) modifiers.push(\"sc-call--on\");\n if (state.muted && !over) modifiers.push(\"sc-call--muted\");\n\n return (\n <section\n ref={root}\n tabIndex={-1}\n aria-label={words.call(name)}\n part=\"call\"\n className={`sc ${classes(classNames, \"sc-call\", ...modifiers)}`}\n >\n <div className={classes(classNames, \"sc-call__stage\")}>\n <Orb\n state={orb.state}\n level={orb.follows === null ? SILENT : call.meter[orb.follows]}\n size={orbSize}\n style={style}\n label={headline}\n className={classes(classNames, \"sc-call__orb\")}\n />\n <p role=\"status\" part=\"call-state\" className={classes(classNames, \"sc-call__state\")}>\n <span key={headline}>{headline}</span>\n </p>\n <p part=\"call-line\" className={classes(classNames, \"sc-call__line\")}>\n {line}\n </p>\n </div>\n {captions !== undefined && !over && (\n <div part=\"captions\" className={classes(classNames, \"sc-call__captions\")}>\n {captions}\n </div>\n )}\n {state.silenced && !over && (\n <Button\n size=\"sm\"\n icon={SpeakerHighIcon}\n onClick={call.hear}\n className={classes(classNames, \"sc-call__sound\")}\n >\n {words.hear(name)}\n </Button>\n )}\n {over ? (\n after !== undefined && (\n <div part=\"call-after\" className={classes(classNames, \"sc-call__after\")}>\n {after}\n </div>\n )\n ) : (\n <>\n <div part=\"call-controls\" className={classes(classNames, \"sc-call__controls\")}>\n <div className={classes(classNames, \"sc-call__control\")}>\n <Button\n icon={state.muted ? MicrophoneSlashIcon : MicrophoneIcon}\n aria-label={words.mute}\n aria-pressed={state.muted}\n disabled={state.stage === \"opening\"}\n onClick={() => {\n call.mute();\n }}\n part=\"mute\"\n className={classes(classNames, \"sc-call__mute\")}\n />\n <span aria-hidden>{words.mute}</span>\n </div>\n <div className={classes(classNames, \"sc-call__control\")}>\n <Button\n tone=\"danger\"\n icon={PhoneDisconnectIcon}\n aria-label={words.hangUp}\n onClick={call.hangUp}\n part=\"hang-up\"\n className={classes(classNames, \"sc-call__hangup\")}\n />\n <span aria-hidden>{words.hangUp}</span>\n </div>\n </div>\n <p\n data-keys={state.muted ? undefined : \"\"}\n className={classes(classNames, \"sc-call__hint\")}\n >\n {state.muted ? words.muted : words.keys}\n </p>\n </>\n )}\n {/* The agent's voice plays from here. */}\n <div ref={sink} hidden />\n </section>\n );\n}\n\n/**\n * What the call says: what it is doing (or why it couldn't begin), and under it who is being\n * called, the time, how it ended (as the room knows it, else as the API said: `endedBy`) and how\n * long it lasted, or what to do.\n */\nfunction wordsOf(\n state: CallState,\n look: CallLook,\n seconds: number,\n words: VoiceCallMessages,\n name: string,\n endedBy: CallEndedBy | null,\n): { headline: string; line: string } {\n if (look === \"problem\" && state.problem !== null) {\n const problem = words.problems[state.problem];\n return { headline: problem.title(name), line: problem.help };\n }\n const headline = look === \"problem\" ? \"\" : words.states[look];\n if (state.end !== null) {\n const by = state.end.by ?? endedBy;\n const lasted = durationOf(state.end.seconds);\n // Why it ended says it ended; how long it lasted, under it.\n return { headline: by === null ? headline : words.ended[by](name), line: lasted };\n }\n return {\n headline,\n line: state.answeredAt === null ? words.calling(name) : durationOf(seconds),\n };\n}\n\n/** The call's time in whole seconds: counting while it is on, held once it is over. */\nfunction useSeconds(state: CallState): number {\n const [now, setNow] = useState(() => Date.now());\n const counting = state.answeredAt !== null && state.stage !== \"over\";\n useEffect(() => {\n if (!counting) return undefined;\n const tick = setInterval(() => {\n setNow(Date.now());\n }, 500);\n return () => {\n clearInterval(tick);\n };\n }, [counting]);\n if (state.end !== null) return state.end.seconds;\n if (state.answeredAt === null) return 0;\n return Math.max(0, Math.floor((now - state.answeredAt) / 1000));\n}\n\n/**\n * Space mutes and unmutes while `active`, wherever it doesn't belong to something else (a field,\n * a control of the page's own). Taken whole, down and up: the page doesn't scroll, and a control\n * of the call that has the focus is not pressed by it.\n */\nfunction useSpace(root: RefObject<HTMLElement | null>, active: boolean, toggle: () => void) {\n const latest = useRef(toggle);\n useEffect(() => {\n latest.current = toggle;\n });\n useEffect(() => {\n if (!active) return undefined;\n const onKey = (event: KeyboardEvent) => {\n if (event.key !== \" \" || event.ctrlKey || event.metaKey || event.altKey) return;\n if (event.defaultPrevented || keyBelongsElsewhere(event.target, root.current)) return;\n event.preventDefault();\n if (event.type === \"keydown\" && !event.repeat) latest.current();\n };\n window.addEventListener(\"keydown\", onKey);\n window.addEventListener(\"keyup\", onKey);\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n window.removeEventListener(\"keyup\", onKey);\n };\n }, [active, root]);\n}\n"],"mappings":";;;;;;;;;;;AA2BA,MAAM,WAAW;;AAGjB,MAAM,eAAuB;AAwB7B,MAAa,sBAAyC;CACpD,OAAO,SAAS,aAAa;CAC7B,QAAQ;EACN,YAAY;EACZ,WAAW;EACX,UAAU;EACV,UAAU;EACV,cAAc;EACd,OAAO;CACT;CACA,UAAU,SAAS,WAAW;CAC9B,OAAO;EACL,cAAc;EACd,QAAQ,SAAS,GAAG,KAAK;EACzB,aAAa;EACb,eAAe;CACjB;CACA,UAAU;EACR,QAAQ;GACN,aAAa;GACb,MAAM;EACR;EACA,OAAO;GACL,aAAa;GACb,MAAM;EACR;EACA,OAAO;GACL,aAAa;GACb,MAAM;EACR;EACA,aAAa;GACX,aAAa;GACb,MAAM;EACR;EACA,KAAK;GACH,aAAa;GACb,MAAM;EACR;EACA,SAAS;GACP,QAAQ,SAAS,GAAG,KAAK;GACzB,MAAM;EACR;EACA,SAAS;GACP,QAAQ,SAAS,GAAG,KAAK;GACzB,MAAM;EACR;EACA,QAAQ;GACN,QAAQ,SAAS,iBAAiB;GAClC,MAAM;EACR;EACA,YAAY;GACV,QAAQ,SAAS,GAAG,KAAK;GACzB,MAAM;EACR;CACF;CACA,MAAM;CACN,QAAQ;CACR,MAAM;CACN,OAAO;CACP,OAAO,SAAS,QAAQ;AAC1B;;;;;;;;;;;;;;;;AA6EA,SAAgB,UAAU,OAAuB;CAC/C,OACE,oBAAC,aAAD;EAAa,YAAY,MAAM;EAC7B,UAAA,oBAAC,MAAD,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WAAW,OAA0B;CAC5C,MAAM,CAAC,KAAK,UAAU,eAAe,KAAK,IAAI,CAAC;CAC/C,MAAM,WAAW,MAAM,eAAe,QAAQ,MAAM,UAAU;CAC9D,gBAAgB;EACd,IAAI,CAAC,UAAU,OAAO,KAAA;EACtB,MAAM,OAAO,kBAAkB;GAC7B,OAAO,KAAK,IAAI,CAAC;EACnB,GAAG,GAAG;EACN,aAAa;GACX,cAAc,IAAI;EACpB;CACF,GAAG,CAAC,QAAQ,CAAC;CACb,IAAI,MAAM,QAAQ,MAAM,OAAO,MAAM,IAAI;CACzC,IAAI,MAAM,eAAe,MAAM,OAAO;CACtC,OAAO,KAAK,IAAI,GAAG,KAAK,OAAO,MAAM,MAAM,cAAc,GAAI,CAAC;AAChE;;;;;;AAOA,SAAS,SAAS,MAAqC,QAAiB,QAAoB;CAC1F,MAAM,SAAS,OAAO,MAAM;CAC5B,gBAAgB;EACd,OAAO,UAAU;CACnB,CAAC;CACD,gBAAgB;EACd,IAAI,CAAC,QAAQ,OAAO,KAAA;EACpB,MAAM,SAAS,UAAyB;GACtC,IAAI,MAAM,QAAQ,OAAO,MAAM,WAAW,MAAM,WAAW,MAAM,QAAQ;GACzE,IAAI,MAAM,oBAAoB,oBAAoB,MAAM,QAAQ,KAAK,OAAO,GAAG;GAC/E,MAAM,eAAe;GACrB,IAAI,MAAM,SAAS,aAAa,CAAC,MAAM,QAAQ,OAAO,QAAQ;EAChE;EACA,OAAO,iBAAiB,WAAW,KAAK;EACxC,OAAO,iBAAiB,SAAS,KAAK;EACtC,aAAa;GACX,OAAO,oBAAoB,WAAW,KAAK;GAC3C,OAAO,oBAAoB,SAAS,KAAK;EAC3C;CACF,GAAG,CAAC,QAAQ,IAAI,CAAC;AACnB"}
|
|
1
|
+
{"version":3,"file":"VoiceCall.js","names":[],"sources":["../src/VoiceCall.tsx"],"sourcesContent":["import {\n MicrophoneIcon,\n MicrophoneSlashIcon,\n PhoneDisconnectIcon,\n SpeakerHighIcon,\n} from \"@phosphor-icons/react\";\nimport { useEffect, useRef, useState, type ReactNode, type RefObject } from \"react\";\n\nimport {\n durationOf,\n keyBelongsElsewhere,\n lookOf,\n orbOf,\n type CallEndedBy,\n type CallLook,\n type CallProblem,\n type CallState,\n} from \"./call\";\nimport { classes } from \"./classes\";\nimport { Button } from \"./kit/Button\";\nimport { KitProvider, type KitClassNames, type KitPart } from \"./kit/context\";\nimport type { AgentTint } from \"./tint\";\nimport { useCall, type CallJoin } from \"./useCall\";\nimport { Orb } from \"./voice/Orb\";\nimport type { OrbStyle } from \"./voice/orbs\";\n\n/** How big the orb is drawn: large, in the middle, with room for it to grow when the voice is loud. */\nconst ORB_SIZE = 280;\n\n/** The orb's level where nobody it follows is speaking. */\nconst SILENT = (): number => 0;\n\n/** The words a call says; a host gives its own, in its language. */\nexport interface VoiceCallMessages {\n /** The call's name, for those who can't see it. */\n call: (name: string) => string;\n /** What the call is doing, in a word or two. */\n states: Readonly<Record<Exclude<CallLook, \"problem\">, string>>;\n /** Under the state while the call connects. */\n calling: (name: string) => string;\n /** Why the call ended, before how long it lasted. */\n ended: Readonly<Record<CallEndedBy, (name: string) => string>>;\n /** Why the call never began, and what the person can do about it. */\n problems: Readonly<Record<CallProblem, { title: (name: string) => string; help: string }>>;\n mute: string;\n hangUp: string;\n /** Under the controls, where there is a keyboard. */\n keys: string;\n /** Under the controls while the microphone is off. */\n muted: string;\n /** The browser held the agent's voice until a press: the button that lets it play. */\n hear: (name: string) => string;\n}\n\nexport const VOICE_CALL_MESSAGES: VoiceCallMessages = {\n call: (name) => `Call with ${name}`,\n states: {\n connecting: \"Connecting…\",\n listening: \"Listening\",\n thinking: \"Thinking\",\n speaking: \"Speaking\",\n reconnecting: \"Reconnecting…\",\n ended: \"Call ended\",\n },\n calling: (name) => `Calling ${name}`,\n ended: {\n person: () => \"You hung up\",\n agent: (name) => `${name} hung up`,\n limit: () => \"It reached its longest time\",\n dropped: () => \"The line dropped\",\n },\n problems: {\n denied: {\n title: () => \"The microphone isn't allowed\",\n help: \"Allow the microphone for this page (the icon beside the address) and call again.\",\n },\n nomic: {\n title: () => \"No microphone\",\n help: \"Plug one in, or pick another in your system's sound settings, and call again.\",\n },\n inuse: {\n title: () => \"The microphone is busy\",\n help: \"Another app is using it. Close it and call again.\",\n },\n unsupported: {\n title: () => \"This browser can't call\",\n help: \"Open this page over https in a recent Chrome, Edge, Safari or Firefox.\",\n },\n off: {\n title: () => \"Calls aren't set up\",\n help: \"Calls are turned on where your agents work. Ask whoever set it up.\",\n },\n builder: {\n title: (name) => `${name} doesn't take calls`,\n help: \"The builder only writes. Call one of the agents.\",\n },\n refused: {\n title: (name) => `${name} can't take this call`,\n help: \"Try again in a moment.\",\n },\n failed: {\n title: (name) => `Couldn't call ${name}`,\n help: \"Check your connection and try again.\",\n },\n unanswered: {\n title: (name) => `${name} isn't answering`,\n help: \"Calls aren't being taken right now. Try again in a moment.\",\n },\n },\n mute: \"Mute\",\n hangUp: \"Hang up\",\n keys: \"Space mutes and unmutes\",\n muted: \"Your microphone is off\",\n hear: (name) => `Hear ${name}`,\n};\n\n/** The call's parts, by the class each carries; `classNames` adds a host's own under the same keys. */\nexport type VoiceCallPart =\n | \"sc-call\"\n | `sc-call--${CallLook}`\n | `sc-call--${AgentTint}`\n | \"sc-call--on\"\n | \"sc-call--muted\"\n | \"sc-call__stage\"\n | \"sc-call__orb\"\n | \"sc-call__state\"\n | \"sc-call__line\"\n | \"sc-call__sound\"\n | \"sc-call__controls\"\n | \"sc-call__control\"\n | \"sc-call__mute\"\n | \"sc-call__hangup\"\n | \"sc-call__hint\"\n | \"sc-call__captions\"\n | \"sc-call__after\";\n\nexport interface VoiceCallProps {\n /**\n * Where to join: LiveKit's address and a token for the call's room (our API's\n * `client.conversations.call(agentId)` answers both, `client.agents.call(id)` for the owner's\n * test). Called once, when the call starts, after the microphone is open.\n */\n connect: () => Promise<CallJoin>;\n /** The agent's name, for the words that say it. */\n name: string;\n /**\n * The agent's own tint (`agentTint(id)`), worn by the call's chrome: the orb's shader paints its\n * own colours, and the still orb that stands in where there is no WebGL wears it.\n */\n tint?: AgentTint | undefined;\n /** How the orb is drawn: `\"wave\"` (the default) or `\"fluid-dots\"`. */\n orb?: OrbStyle | undefined;\n /** The orb's diameter in pixels: 280 by default, less for a call in a small panel. */\n orbSize?: number | undefined;\n /**\n * Why the call ended as the API keeps it, once the host has read it (`endedByReason` of its\n * conversation's call): what the end says when the agent's side closed the room (its goodbye,\n * or its longest time), which the room doesn't tell. Until then the end says how long it was.\n */\n endedBy?: CallEndedBy | null | undefined;\n messages?: Partial<VoiceCallMessages> | undefined;\n /** The host's classes for the call's parts and the kit's (the orb's `sc-orb…`, the buttons'). */\n classNames?: Partial<Record<VoiceCallPart | KitPart, string>> | undefined;\n /**\n * The call is over, once: it ended (`answered`: the agent took it; `problem` null), or it\n * couldn't begin (`problem`: why, which the call shows until the host takes it away).\n */\n onEnd?: ((answered: boolean, problem: CallProblem | null) => void) | undefined;\n /** The agent took the call: its time counts from now. Once. */\n onAnswer?: (() => void) | undefined;\n /** What the host offers once the call is over, in place of the controls: call again, write. */\n after?: ReactNode;\n /** What is being said, drawn by the host under the orb while the call is on (`sc-call__captions`). */\n captions?: ReactNode;\n}\n\n/**\n * A voice call with an agent, the one a customer has on the phone: the call starts when it\n * mounts and ends when it unmounts. The orb, large in the middle, rests while the line is found,\n * moves with whoever speaks (the agent's voice while it speaks, the person's while it listens),\n * calms while the agent thinks, and fades once the call is over; under it what the call\n * is doing in a word, its time, and the two controls a phone has, mute and hang up. A microphone\n * that can't be used, or a call that can't be made (the API's refusal among them), says why in\n * words and what to do; an end says who ended it (the room's own word, or the API's: `endedBy`)\n * and how long it lasted.\n *\n * Space mutes and unmutes from anywhere that isn't a field or a control of the page's own.\n * Escape never hangs up: it is the key that closes things, pressed by reflex, and a call ended\n * by accident can't be taken back, so ending one is the red button's alone. The orb stands\n * still under reduced motion, one frame per state: the words say the rest.\n */\nexport function VoiceCall(props: VoiceCallProps) {\n return (\n <KitProvider classNames={props.classNames as KitClassNames}>\n <Call {...props} />\n </KitProvider>\n );\n}\n\nfunction Call({\n connect,\n name,\n tint = \"sky\",\n orb: style,\n orbSize = ORB_SIZE,\n endedBy,\n messages,\n classNames,\n onEnd,\n onAnswer,\n after,\n captions,\n}: VoiceCallProps) {\n const words = { ...VOICE_CALL_MESSAGES, ...messages };\n const root = useRef<HTMLElement>(null);\n const sink = useRef<HTMLDivElement>(null);\n const call = useCall(connect, { sink });\n const { state } = call;\n const look = lookOf(state);\n const orb = orbOf(look);\n const over = state.stage === \"over\";\n const seconds = useSeconds(state);\n\n useSpace(root, !over, () => {\n call.mute();\n });\n // The call takes the keyboard as it opens, so Space is its from the start; and again once over,\n // when the control that had it is gone, so the host's offers are the next stop.\n useEffect(() => {\n root.current?.focus({ preventScroll: true });\n }, [over]);\n // The host's ears as it last gave them.\n const told = useRef({ onEnd, onAnswer });\n useEffect(() => {\n told.current = { onEnd, onAnswer };\n });\n const answered = state.answeredAt !== null;\n useEffect(() => {\n if (answered) told.current.onAnswer?.();\n }, [answered]);\n useEffect(() => {\n if (over) told.current.onEnd?.(answered, state.problem);\n }, [over]);\n\n const { headline, line } = wordsOf(state, look, seconds, words, name, endedBy ?? null);\n const modifiers: VoiceCallPart[] = [`sc-call--${look}`, `sc-call--${tint}`];\n if (!over) modifiers.push(\"sc-call--on\");\n if (state.muted && !over) modifiers.push(\"sc-call--muted\");\n\n return (\n <section\n ref={root}\n tabIndex={-1}\n aria-label={words.call(name)}\n part=\"call\"\n className={`sc ${classes(classNames, \"sc-call\", ...modifiers)}`}\n >\n <div className={classes(classNames, \"sc-call__stage\")}>\n <Orb\n state={orb.state}\n level={orb.follows === null ? SILENT : call.meter[orb.follows]}\n size={orbSize}\n style={style}\n label={headline}\n className={classes(classNames, \"sc-call__orb\")}\n />\n <p role=\"status\" part=\"call-state\" className={classes(classNames, \"sc-call__state\")}>\n <span key={headline}>{headline}</span>\n </p>\n <p part=\"call-line\" className={classes(classNames, \"sc-call__line\")}>\n {line}\n </p>\n </div>\n {captions !== undefined && !over && (\n <div part=\"captions\" className={classes(classNames, \"sc-call__captions\")}>\n {captions}\n </div>\n )}\n {state.silenced && !over && (\n <Button\n size=\"sm\"\n icon={SpeakerHighIcon}\n onClick={call.hear}\n className={classes(classNames, \"sc-call__sound\")}\n >\n {words.hear(name)}\n </Button>\n )}\n {over ? (\n after !== undefined && (\n <div part=\"call-after\" className={classes(classNames, \"sc-call__after\")}>\n {after}\n </div>\n )\n ) : (\n <>\n <div part=\"call-controls\" className={classes(classNames, \"sc-call__controls\")}>\n <div className={classes(classNames, \"sc-call__control\")}>\n <Button\n icon={state.muted ? MicrophoneSlashIcon : MicrophoneIcon}\n aria-label={words.mute}\n aria-pressed={state.muted}\n disabled={state.stage === \"opening\"}\n onClick={() => {\n call.mute();\n }}\n part=\"mute\"\n className={classes(classNames, \"sc-call__mute\")}\n />\n <span aria-hidden>{words.mute}</span>\n </div>\n <div className={classes(classNames, \"sc-call__control\")}>\n <Button\n tone=\"danger\"\n icon={PhoneDisconnectIcon}\n aria-label={words.hangUp}\n onClick={call.hangUp}\n part=\"hang-up\"\n className={classes(classNames, \"sc-call__hangup\")}\n />\n <span aria-hidden>{words.hangUp}</span>\n </div>\n </div>\n <p\n data-keys={state.muted ? undefined : \"\"}\n className={classes(classNames, \"sc-call__hint\")}\n >\n {state.muted ? words.muted : words.keys}\n </p>\n </>\n )}\n {/* The agent's voice plays from here. */}\n <div ref={sink} hidden />\n </section>\n );\n}\n\n/**\n * What the call says: what it is doing (or why it couldn't begin), and under it who is being\n * called, the time, how it ended (as the room knows it, else as the API said: `endedBy`) and how\n * long it lasted, or what to do.\n */\nfunction wordsOf(\n state: CallState,\n look: CallLook,\n seconds: number,\n words: VoiceCallMessages,\n name: string,\n endedBy: CallEndedBy | null,\n): { headline: string; line: string } {\n if (look === \"problem\" && state.problem !== null) {\n const problem = words.problems[state.problem];\n return { headline: problem.title(name), line: problem.help };\n }\n const headline = look === \"problem\" ? \"\" : words.states[look];\n if (state.end !== null) {\n const by = state.end.by ?? endedBy;\n const lasted = durationOf(state.end.seconds);\n // Why it ended says it ended; how long it lasted, under it.\n return { headline: by === null ? headline : words.ended[by](name), line: lasted };\n }\n return {\n headline,\n line: state.answeredAt === null ? words.calling(name) : durationOf(seconds),\n };\n}\n\n/** The call's time in whole seconds: counting while it is on, held once it is over. */\nfunction useSeconds(state: CallState): number {\n const [now, setNow] = useState(() => Date.now());\n const counting = state.answeredAt !== null && state.stage !== \"over\";\n useEffect(() => {\n if (!counting) return undefined;\n const tick = setInterval(() => {\n setNow(Date.now());\n }, 500);\n return () => {\n clearInterval(tick);\n };\n }, [counting]);\n if (state.end !== null) return state.end.seconds;\n if (state.answeredAt === null) return 0;\n return Math.max(0, Math.floor((now - state.answeredAt) / 1000));\n}\n\n/**\n * Space mutes and unmutes while `active`, wherever it doesn't belong to something else (a field,\n * a control of the page's own). Taken whole, down and up: the page doesn't scroll, and a control\n * of the call that has the focus is not pressed by it.\n */\nfunction useSpace(root: RefObject<HTMLElement | null>, active: boolean, toggle: () => void) {\n const latest = useRef(toggle);\n useEffect(() => {\n latest.current = toggle;\n });\n useEffect(() => {\n if (!active) return undefined;\n const onKey = (event: KeyboardEvent) => {\n if (event.key !== \" \" || event.ctrlKey || event.metaKey || event.altKey) return;\n if (event.defaultPrevented || keyBelongsElsewhere(event.target, root.current)) return;\n event.preventDefault();\n if (event.type === \"keydown\" && !event.repeat) latest.current();\n };\n window.addEventListener(\"keydown\", onKey);\n window.addEventListener(\"keyup\", onKey);\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n window.removeEventListener(\"keyup\", onKey);\n };\n }, [active, root]);\n}\n"],"mappings":";;;;;;;;;;;AA2BA,MAAM,WAAW;;AAGjB,MAAM,eAAuB;AAwB7B,MAAa,sBAAyC;CACpD,OAAO,SAAS,aAAa;CAC7B,QAAQ;EACN,YAAY;EACZ,WAAW;EACX,UAAU;EACV,UAAU;EACV,cAAc;EACd,OA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,MAAqC,QAAiB,QAAoB;CAC1F,MAAM,SAAS,OAAO,MAAM;CAC5B,gBAAgB;EACd,OAAO,UAAU;CACnB,CAAC;CACD,gBAAgB;EACd,IAAI,CAAC,QAAQ,OAAO,KAAA;EACpB,MAAM,SAAS,UAAyB;GACtC,IAAI,MAAM,QAAQ,OAAO,MAAM,WAAW,MAAM,WAAW,MAAM,QAAQ;GACzE,IAAI,MAAM,oBAAoB,oBAAoB,MAAM,QAAQ,KAAK,OAAO,GAAG;GAC/E,MAAM,eAAe;GACrB,IAAI,MAAM,SAAS,aAAa,CAAC,MAAM,QAAQ,OAAO,QAAQ;EAChE;EACA,OAAO,iBAAiB,WAAW,KAAK;EACxC,OAAO,iBAAiB,SAAS,KAAK;EACtC,aAAa;GACX,OAAO,oBAAoB,WAAW,KAAK;GAC3C,OAAO,oBAAoB,SAAS,KAAK;EAC3C;CACF,GAAG,CAAC,QAAQ,IAAI,CAAC;AACnB"}
|
package/dist/about.d.ts
CHANGED
|
@@ -1,85 +1,24 @@
|
|
|
1
|
+
import { About as About$1, AboutOut as AboutOut$1, ActionRowOut, Does as Does$1, FactAsk, FactAutomation, FactChannel, FactConnection, FactDevice, FactFile, FactKey, FactTable, Facts as Facts$1, MemoryOut } from "./contract.js";
|
|
1
2
|
import { formatSize } from "./kit/numbers.js";
|
|
2
3
|
//#region src/about.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Qué puede: what an agent says about itself and the facts it rests on (`GET /agents/{id}/about`,
|
|
5
|
-
* `POST /agents/{id}/describe`). The words are the model's, written from the agent's folder and
|
|
6
|
-
* stale the moment it changes; the facts are the platform's, read each time.
|
|
7
|
-
*/
|
|
8
4
|
/** The marks the package draws (a topic's, an automation's kind, a note's tone). */
|
|
9
5
|
export declare const ICONS: readonly ["message", "phone", "mail", "calendar", "clock", "search", "file", "table", "bell", "hand", "user", "globe", "code", "lock", "cart", "card", "map", "check", "warning", "sparkle"];
|
|
10
6
|
export type Icon = (typeof ICONS)[number];
|
|
11
|
-
/** One automation as the agent tells it: what it does then, and when. */
|
|
12
|
-
export
|
|
13
|
-
/** The automation's id. */
|
|
14
|
-
automation: string;
|
|
15
|
-
text: string;
|
|
16
|
-
/** When it runs, the way a person says it: "Cada día a las 8:00". */
|
|
17
|
-
when: string;
|
|
18
|
-
}
|
|
7
|
+
/** One automation as the agent tells it: what it does then, and when ("Cada día a las 8:00"). */
|
|
8
|
+
export type Does = Does$1;
|
|
19
9
|
/** What the agent says about itself: a lead, what it does, what it asks leave for. */
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export type
|
|
27
|
-
|
|
28
|
-
name: string;
|
|
29
|
-
description: string;
|
|
30
|
-
source: ActionSource;
|
|
31
|
-
on: boolean;
|
|
32
|
-
needs_approval: boolean;
|
|
33
|
-
destructive: boolean;
|
|
34
|
-
/** Its input as the model gets it (JSON Schema); left out by an API from before. */
|
|
35
|
-
input_schema?: Readonly<Record<string, unknown>> | undefined;
|
|
36
|
-
}
|
|
37
|
-
export type AutomationKind = "schedule" | "webhook" | "event";
|
|
38
|
-
/** Something the agent does on its own: at a time, when another system calls, on an event. */
|
|
39
|
-
export interface AutomationFact {
|
|
40
|
-
id: string;
|
|
41
|
-
/** Its file's name, `automations/<name>.py`: how its page is reached. */
|
|
42
|
-
name: string;
|
|
43
|
-
kind: AutomationKind;
|
|
44
|
-
title: string;
|
|
45
|
-
/** What it does, in the owner's words. */
|
|
46
|
-
summary: string;
|
|
47
|
-
/** The same words, for a reader of the older shape. */
|
|
48
|
-
say: string;
|
|
49
|
-
/** A cron line and its time zone, for one that runs at a time. */
|
|
50
|
-
schedule?: string | null | undefined;
|
|
51
|
-
timezone?: string | null | undefined;
|
|
52
|
-
/** Where another system calls it, for a webhook (a path on the API). */
|
|
53
|
-
url?: string | null | undefined;
|
|
54
|
-
/** For one on an app's event: the app (the connection's name), the event as its provider
|
|
55
|
-
* names it, and the app as its mark is drawn (`composio:gmail`, the provider's logo). */
|
|
56
|
-
app?: string | null | undefined;
|
|
57
|
-
/** The app as people write it (`Google Calendar`). */
|
|
58
|
-
app_title?: string | null | undefined;
|
|
59
|
-
event?: string | null | undefined;
|
|
60
|
-
provider?: string | undefined;
|
|
61
|
-
icon?: string | null | undefined;
|
|
62
|
-
/** Off: declared, but it doesn't run. */
|
|
63
|
-
on: boolean;
|
|
64
|
-
next_run_at?: string | null | undefined;
|
|
65
|
-
}
|
|
10
|
+
export type About = About$1;
|
|
11
|
+
/** One of its actions: where it comes from, whether it is on and asks first, its input. */
|
|
12
|
+
export type ActionFact = ActionRowOut;
|
|
13
|
+
export type AutomationKind = FactAutomation["kind"];
|
|
14
|
+
/** Something the agent does on its own: at a time, when another system calls, on an app's event
|
|
15
|
+
* (with the app's name and mark), on a message. */
|
|
16
|
+
export type AutomationFact = FactAutomation;
|
|
17
|
+
/** Who brings an app: one of the providers, an MCP server, the business's own API. */
|
|
66
18
|
export type Provider = "arcade" | "composio" | "mcp" | "api";
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/** The app, as the provider names it (`gmail`). */
|
|
71
|
-
toolkit?: string | undefined;
|
|
72
|
-
/** The app as people write it (`Google Calendar`). */
|
|
73
|
-
title?: string | undefined;
|
|
74
|
-
/** pending · active · error · disconnected */
|
|
75
|
-
status?: string | undefined;
|
|
76
|
-
/** The provider's names of what the agent may do in it (`Gmail.SendEmail`). */
|
|
77
|
-
actions: string[];
|
|
78
|
-
/** What the provider calls each of them for people (`List Events`), when it says. */
|
|
79
|
-
titles?: Readonly<Record<string, string>> | undefined;
|
|
80
|
-
/** A URL to the app's own mark, when the provider gives one. */
|
|
81
|
-
icon?: string | null | undefined;
|
|
82
|
-
}
|
|
19
|
+
/** An app it was given: its name and mark, and its tools, with their names for people
|
|
20
|
+
* (`titles`) and as the model calls them (`called`). */
|
|
21
|
+
export type ConnectionFact = FactConnection;
|
|
83
22
|
/** An app of the agent's as people write it: its provider's name, else its alias made words. */
|
|
84
23
|
export declare const appTitle: (connection: ConnectionFact) => string;
|
|
85
24
|
/** A tool of an app as people read it: its provider's name for it, else its own made words. */
|
|
@@ -91,7 +30,10 @@ export declare function toolName(action: string): string;
|
|
|
91
30
|
* as the model calls it, `gmail__GMAIL_SEND_EMAIL`, is "Send email (Gmail)".
|
|
92
31
|
*/
|
|
93
32
|
export declare function actionWords(name: string): string;
|
|
94
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* `gmail` + `Gmail.SendEmail` → `gmail__Gmail_SendEmail`: the tool the model is given.
|
|
35
|
+
* @deprecated The facts say it: `ConnectionFact.called`.
|
|
36
|
+
*/
|
|
95
37
|
export declare const generatedName: (alias: string, action: string) => string;
|
|
96
38
|
/**
|
|
97
39
|
* The tools the agent's apps give it, by the names the model calls them, in words: the
|
|
@@ -100,76 +42,24 @@ export declare const generatedName: (alias: string, action: string) => string;
|
|
|
100
42
|
*/
|
|
101
43
|
export declare function appSteps(connections: readonly ConnectionFact[]): Record<string, string>;
|
|
102
44
|
export type ChannelKind = "whatsapp" | "instagram" | "email" | "sms" | "web" | "phone";
|
|
103
|
-
export
|
|
104
|
-
kind: ChannelKind;
|
|
105
|
-
name: string;
|
|
106
|
-
status: string;
|
|
107
|
-
}
|
|
45
|
+
export type ChannelFact = FactChannel;
|
|
108
46
|
/** A file the agent can read: its own, or one of the organization's, shared with every agent. */
|
|
109
|
-
export
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
/** The organization's, not the agent's own. */
|
|
115
|
-
shared: boolean;
|
|
116
|
-
}
|
|
117
|
-
/** A line the agent kept with `remember`. */
|
|
118
|
-
export interface MemoryFact {
|
|
119
|
-
id: string;
|
|
120
|
-
/** The agent that keeps it; the contact it is about, when it is about one. */
|
|
121
|
-
agent_id?: string | undefined;
|
|
122
|
-
contact_id?: string | null | undefined;
|
|
123
|
-
text: string;
|
|
124
|
-
created_at: string;
|
|
125
|
-
}
|
|
126
|
-
/** A key the agent may use: its own, or one of the organization's, shared with every agent. */
|
|
127
|
-
export interface VaultFact {
|
|
128
|
-
name: string;
|
|
129
|
-
/** The hosts it may be sent to. */
|
|
130
|
-
hosts?: string[] | undefined;
|
|
131
|
-
/** The organization's, not the agent's own. */
|
|
132
|
-
shared?: boolean | undefined;
|
|
133
|
-
}
|
|
47
|
+
export type FileFact = FactFile;
|
|
48
|
+
/** A line the agent kept with `remember`: its own, or about the contact it names. */
|
|
49
|
+
export type MemoryFact = MemoryOut;
|
|
50
|
+
/** A key the agent may use: its own, or one of the organization's its access gives it. */
|
|
51
|
+
export type VaultFact = FactKey;
|
|
134
52
|
/** A table of the organization's the agent may read or write (an agenda, the clients). */
|
|
135
|
-
export
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
export
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
export type DeviceKind = "extension" | "installer";
|
|
146
|
-
export interface DeviceFact {
|
|
147
|
-
kind: DeviceKind;
|
|
148
|
-
name: string;
|
|
149
|
-
status: string;
|
|
150
|
-
}
|
|
151
|
-
/** What the agent has, every list present from day one; one whose phase has not come is empty. */
|
|
152
|
-
export interface Facts {
|
|
153
|
-
actions: ActionFact[];
|
|
154
|
-
automations: AutomationFact[];
|
|
155
|
-
connections: ConnectionFact[];
|
|
156
|
-
channels: ChannelFact[];
|
|
157
|
-
/** Its own first, then the organization's shared. */
|
|
158
|
-
files: FileFact[];
|
|
159
|
-
/** Newest first. */
|
|
160
|
-
memories: MemoryFact[];
|
|
161
|
-
vault: VaultFact[];
|
|
162
|
-
data: DataFact[];
|
|
163
|
-
asks: AskFact[];
|
|
164
|
-
devices: DeviceFact[];
|
|
165
|
-
}
|
|
166
|
-
export interface AboutOut {
|
|
167
|
-
/** Null until the agent has written about itself once. */
|
|
168
|
-
about: About | null;
|
|
169
|
-
/** When the words were written; null when the folder changed since, so they are stale. */
|
|
170
|
-
about_at: string | null;
|
|
171
|
-
facts: Facts;
|
|
172
|
-
}
|
|
53
|
+
export type DataFact = FactTable;
|
|
54
|
+
export type AskFact = FactAsk;
|
|
55
|
+
export type DeviceKind = FactDevice["kind"];
|
|
56
|
+
export type DeviceFact = FactDevice;
|
|
57
|
+
/** What the agent has, every list present from day one; one whose phase has not come is empty:
|
|
58
|
+
* its files its own first, its memories newest first. */
|
|
59
|
+
export type Facts = Facts$1;
|
|
60
|
+
/** What it says (null until written once; `about_at` null when the folder changed since, so the
|
|
61
|
+
* words are stale) and the facts. */
|
|
62
|
+
export type AboutOut = AboutOut$1;
|
|
173
63
|
/**
|
|
174
64
|
* What the panel lists of the facts beside what the agent does on its own, gathered into a few
|
|
175
65
|
* things an owner reads at a glance: the apps it uses, its tools, what it knows (files and
|
package/dist/about.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { formatSize } from "./kit/numbers.js";
|
|
2
2
|
//#region src/about.ts
|
|
3
|
-
/**
|
|
4
|
-
* Qué puede: what an agent says about itself and the facts it rests on (`GET /agents/{id}/about`,
|
|
5
|
-
* `POST /agents/{id}/describe`). The words are the model's, written from the agent's folder and
|
|
6
|
-
* stale the moment it changes; the facts are the platform's, read each time.
|
|
7
|
-
*/
|
|
8
3
|
/** The marks the package draws (a topic's, an automation's kind, a note's tone). */
|
|
9
4
|
const ICONS = [
|
|
10
5
|
"message",
|
|
@@ -29,7 +24,7 @@ const ICONS = [
|
|
|
29
24
|
"sparkle"
|
|
30
25
|
];
|
|
31
26
|
/** An app of the agent's as people write it: its provider's name, else its alias made words. */
|
|
32
|
-
const appTitle = (connection) => connection.title
|
|
27
|
+
const appTitle = (connection) => connection.title || toolName(connection.name);
|
|
33
28
|
/** A tool of an app as people read it: its provider's name for it, else its own made words. */
|
|
34
29
|
const toolTitle = (connection, action) => connection.titles?.[action] ?? toolName(action);
|
|
35
30
|
/** A tool of an app as a person reads it: `Gmail.SendEmail` is "Send email". */
|
|
@@ -49,7 +44,10 @@ function actionWords(name) {
|
|
|
49
44
|
}
|
|
50
45
|
/** The longest name the model takes for a tool (`app/connections` cuts there too). */
|
|
51
46
|
const MAX_TOOL_NAME = 64;
|
|
52
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* `gmail` + `Gmail.SendEmail` → `gmail__Gmail_SendEmail`: the tool the model is given.
|
|
49
|
+
* @deprecated The facts say it: `ConnectionFact.called`.
|
|
50
|
+
*/
|
|
53
51
|
const generatedName = (alias, action) => `${alias}__${action.replace(/[^A-Za-z0-9_]/g, "_")}`.slice(0, MAX_TOOL_NAME);
|
|
54
52
|
/**
|
|
55
53
|
* The tools the agent's apps give it, by the names the model calls them, in words: the
|
|
@@ -57,7 +55,7 @@ const generatedName = (alias, action) => `${alias}__${action.replace(/[^A-Za-z0-
|
|
|
57
55
|
* read them (`ChatMessages.steps`).
|
|
58
56
|
*/
|
|
59
57
|
function appSteps(connections) {
|
|
60
|
-
return Object.fromEntries(connections.flatMap((connection) => connection.actions.map((action) => [generatedName(connection.name, action), `${toolTitle(connection, action)} (${appTitle(connection)})`])));
|
|
58
|
+
return Object.fromEntries(connections.flatMap((connection) => connection.actions.map((action) => [connection.called[action] ?? generatedName(connection.name, action), `${toolTitle(connection, action)} (${appTitle(connection)})`])));
|
|
61
59
|
}
|
|
62
60
|
/** The topics in the order the panel lists them. */
|
|
63
61
|
const TOPICS = [
|
package/dist/about.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"about.js","names":[],"sources":["../src/about.ts"],"sourcesContent":["/**\n * Qué puede: what an agent says about itself and the facts it rests on (`GET /agents/{id}/about`,\n * `POST /agents/{id}/describe`). The words are the model's, written from the agent's folder and\n * stale the moment it changes; the facts are the platform's, read each time.\n */\n\n/** The marks the package draws (a topic's, an automation's kind, a note's tone). */\nexport const ICONS = [\n \"message\",\n \"phone\",\n \"mail\",\n \"calendar\",\n \"clock\",\n \"search\",\n \"file\",\n \"table\",\n \"bell\",\n \"hand\",\n \"user\",\n \"globe\",\n \"code\",\n \"lock\",\n \"cart\",\n \"card\",\n \"map\",\n \"check\",\n \"warning\",\n \"sparkle\",\n] as const;\n\nexport type Icon = (typeof ICONS)[number];\n\n/** One automation as the agent tells it: what it does then, and when. */\nexport interface Does {\n /** The automation's id. */\n automation: string;\n text: string;\n /** When it runs, the way a person says it: \"Cada día a las 8:00\". */\n when: string;\n}\n\n/** What the agent says about itself: a lead, what it does, what it asks leave for. */\nexport interface About {\n /** Two or three sentences, first person, in the owner's language. */\n summary: string;\n does: Does[];\n asks: string[];\n}\n\nexport type ActionSource = \"default\" | \"library\" | \"own\";\n\nexport interface ActionFact {\n name: string;\n description: string;\n source: ActionSource;\n on: boolean;\n needs_approval: boolean;\n destructive: boolean;\n /** Its input as the model gets it (JSON Schema); left out by an API from before. */\n input_schema?: Readonly<Record<string, unknown>> | undefined;\n}\n\nexport type AutomationKind = \"schedule\" | \"webhook\" | \"event\";\n\n/** Something the agent does on its own: at a time, when another system calls, on an event. */\nexport interface AutomationFact {\n id: string;\n /** Its file's name, `automations/<name>.py`: how its page is reached. */\n name: string;\n kind: AutomationKind;\n title: string;\n /** What it does, in the owner's words. */\n summary: string;\n /** The same words, for a reader of the older shape. */\n say: string;\n /** A cron line and its time zone, for one that runs at a time. */\n schedule?: string | null | undefined;\n timezone?: string | null | undefined;\n /** Where another system calls it, for a webhook (a path on the API). */\n url?: string | null | undefined;\n /** For one on an app's event: the app (the connection's name), the event as its provider\n * names it, and the app as its mark is drawn (`composio:gmail`, the provider's logo). */\n app?: string | null | undefined;\n /** The app as people write it (`Google Calendar`). */\n app_title?: string | null | undefined;\n event?: string | null | undefined;\n provider?: string | undefined;\n icon?: string | null | undefined;\n /** Off: declared, but it doesn't run. */\n on: boolean;\n next_run_at?: string | null | undefined;\n}\n\nexport type Provider = \"arcade\" | \"composio\" | \"mcp\" | \"api\";\n\nexport interface ConnectionFact {\n provider: Provider;\n name: string;\n /** The app, as the provider names it (`gmail`). */\n toolkit?: string | undefined;\n /** The app as people write it (`Google Calendar`). */\n title?: string | undefined;\n /** pending · active · error · disconnected */\n status?: string | undefined;\n /** The provider's names of what the agent may do in it (`Gmail.SendEmail`). */\n actions: string[];\n /** What the provider calls each of them for people (`List Events`), when it says. */\n titles?: Readonly<Record<string, string>> | undefined;\n /** A URL to the app's own mark, when the provider gives one. */\n icon?: string | null | undefined;\n}\n\n/** An app of the agent's as people write it: its provider's name, else its alias made words. */\nexport const appTitle = (connection: ConnectionFact): string =>\n connection.title ?? toolName(connection.name);\n\n/** A tool of an app as people read it: its provider's name for it, else its own made words. */\nexport const toolTitle = (connection: ConnectionFact, action: string): string =>\n connection.titles?.[action] ?? toolName(action);\n\n/** A tool of an app as a person reads it: `Gmail.SendEmail` is \"Send email\". */\nexport function toolName(action: string): string {\n const bare = action.slice(action.lastIndexOf(\".\") + 1);\n const words = bare\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/_/g, \" \")\n .toLowerCase();\n return words.charAt(0).toUpperCase() + words.slice(1);\n}\n\n/**\n * An action's name made words, for one nobody named: `ver_hoja` is \"Ver hoja\"; an app's tool\n * as the model calls it, `gmail__GMAIL_SEND_EMAIL`, is \"Send email (Gmail)\".\n */\nexport function actionWords(name: string): string {\n const split = name.indexOf(\"__\");\n if (split < 0) return toolName(name);\n const tool = name.slice(split + 2);\n const bare = tool.slice(tool.indexOf(\"_\") + 1) || tool;\n return `${toolName(bare)} (${toolName(name.slice(0, split))})`;\n}\n\n/** The longest name the model takes for a tool (`app/connections` cuts there too). */\nconst MAX_TOOL_NAME = 64;\n\n/** `gmail` + `Gmail.SendEmail` → `gmail__Gmail_SendEmail`: the tool the model is given. */\nexport const generatedName = (alias: string, action: string): string =>\n `${alias}__${action.replace(/[^A-Za-z0-9_]/g, \"_\")}`.slice(0, MAX_TOOL_NAME);\n\n/**\n * The tools the agent's apps give it, by the names the model calls them, in words: the\n * provider's for the tool and the app's (\"List Events (Google Calendar)\"), as a chat's steps\n * read them (`ChatMessages.steps`).\n */\nexport function appSteps(connections: readonly ConnectionFact[]): Record<string, string> {\n return Object.fromEntries(\n connections.flatMap((connection) =>\n connection.actions.map((action) => [\n generatedName(connection.name, action),\n `${toolTitle(connection, action)} (${appTitle(connection)})`,\n ]),\n ),\n );\n}\n\nexport type ChannelKind = \"whatsapp\" | \"instagram\" | \"email\" | \"sms\" | \"web\" | \"phone\";\n\nexport interface ChannelFact {\n kind: ChannelKind;\n name: string;\n status: string;\n}\n\n/** A file the agent can read: its own, or one of the organization's, shared with every agent. */\nexport interface FileFact {\n path: string;\n size: number;\n /** Text, Markdown, JSON, YAML or PDF, read by `search_files`; anything else is only kept. */\n searchable: boolean;\n /** The organization's, not the agent's own. */\n shared: boolean;\n}\n\n/** A line the agent kept with `remember`. */\nexport interface MemoryFact {\n id: string;\n /** The agent that keeps it; the contact it is about, when it is about one. */\n agent_id?: string | undefined;\n contact_id?: string | null | undefined;\n text: string;\n created_at: string;\n}\n\n/** A key the agent may use: its own, or one of the organization's, shared with every agent. */\nexport interface VaultFact {\n name: string;\n /** The hosts it may be sent to. */\n hosts?: string[] | undefined;\n /** The organization's, not the agent's own. */\n shared?: boolean | undefined;\n}\n\n/** A table of the organization's the agent may read or write (an agenda, the clients). */\nexport interface DataFact {\n table: string;\n /** Its name for people, when it has one. */\n title?: string | null | undefined;\n can: string[];\n}\n\nexport interface AskFact {\n agent_id: string;\n name: string;\n}\n\nexport type DeviceKind = \"extension\" | \"installer\";\n\nexport interface DeviceFact {\n kind: DeviceKind;\n name: string;\n status: string;\n}\n\n/** What the agent has, every list present from day one; one whose phase has not come is empty. */\nexport interface Facts {\n actions: ActionFact[];\n automations: AutomationFact[];\n connections: ConnectionFact[];\n channels: ChannelFact[];\n /** Its own first, then the organization's shared. */\n files: FileFact[];\n /** Newest first. */\n memories: MemoryFact[];\n vault: VaultFact[];\n data: DataFact[];\n asks: AskFact[];\n devices: DeviceFact[];\n}\n\nexport interface AboutOut {\n /** Null until the agent has written about itself once. */\n about: About | null;\n /** When the words were written; null when the folder changed since, so they are stale. */\n about_at: string | null;\n facts: Facts;\n}\n\n/**\n * What the panel lists of the facts beside what the agent does on its own, gathered into a few\n * things an owner reads at a glance: the apps it uses, its tools, what it knows (files and\n * tables), what it has learned, where it works (channels and devices), and its keys.\n */\nexport type Topic = \"apps\" | \"tools\" | \"knowledge\" | \"learning\" | \"channels\" | \"keys\";\n\n/** The topics in the order the panel lists them. */\nexport const TOPICS: readonly Topic[] = [\n \"apps\",\n \"tools\",\n \"knowledge\",\n \"learning\",\n \"channels\",\n \"keys\",\n];\n\n/** An automation with what the agent said about it, when it said something. */\nexport interface Told {\n automation: AutomationFact;\n line: Does | undefined;\n}\n\n/**\n * The agent's automations, in their order, each with the agent's line about it (matched by id):\n * one added since the words were written has none yet, and a line for one since removed is\n * dropped.\n */\nexport function automationsOf(about: About | null, facts: Facts): Told[] {\n const lines = new Map((about?.does ?? []).map((line) => [line.automation, line]));\n return facts.automations.map((automation) => ({ automation, line: lines.get(automation.id) }));\n}\n\n/** How many things a topic holds: the tools that are on, the rest whole. */\nexport function countOf(topic: Topic, facts: Facts): number {\n return namesOf(topic, facts, (action) => action.name).length;\n}\n\n/**\n * The names of what a topic holds, in order, as its row in the panel previews them: an app by its\n * name, a tool by `label` (the host's words for the shipped ones), a file by its path and a table\n * by its title, what it learned by the line itself.\n */\nexport function namesOf(\n topic: Topic,\n facts: Facts,\n label: (action: ActionFact) => string,\n): string[] {\n switch (topic) {\n case \"apps\":\n return facts.connections.map(appTitle);\n case \"tools\":\n return facts.actions.filter((action) => action.on).map(label);\n case \"knowledge\":\n return [\n ...facts.files.map((file) => file.path),\n ...facts.data.map((table) => table.title ?? table.table),\n ];\n case \"learning\":\n return facts.memories.map((memory) => memory.text);\n case \"channels\":\n return [\n ...facts.channels.map((channel) => channel.name),\n ...facts.devices.map((device) => device.name),\n ];\n case \"keys\":\n return facts.vault.map((secret) => secret.name);\n }\n}\n\nexport type AboutState = \"writing\" | \"stale\" | \"fresh\";\n\n/**\n * Which state the words are in: `writing` while there are none yet or the agent is writing them\n * anew (`loading`), `stale` when the agent changed since it wrote them, `fresh` otherwise.\n */\nexport function aboutState(\n about: About | null,\n aboutAt: string | null,\n loading: boolean,\n): AboutState {\n if (about === null || loading) return \"writing\";\n return aboutAt === null ? \"stale\" : \"fresh\";\n}\n\n/** A file's size as people read it (the kit's, where the file chips draw it). */\nexport { formatSize } from \"./kit/numbers\";\n\n/** How a status reads beside its words: working, broken, or neither. */\nexport type StatusTone = \"on\" | \"off\" | \"quiet\";\n\nconst ON: ReadonlySet<string> = new Set([\"live\", \"active\", \"connected\", \"on\", \"ready\", \"online\"]);\nconst OFF: ReadonlySet<string> = new Set([\n \"failed\",\n \"error\",\n \"disconnected\",\n \"off\",\n \"expired\",\n \"broken\",\n]);\n\n/** The tone of a channel's or a device's status, from the words the platform uses for it. */\nexport function toneOf(status: string): StatusTone {\n const word = status.trim().toLowerCase();\n if (ON.has(word)) return \"on\";\n if (OFF.has(word)) return \"off\";\n return \"quiet\";\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,QAAQ;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAqFA,MAAa,YAAY,eACvB,WAAW,SAAS,SAAS,WAAW,IAAI;;AAG9C,MAAa,aAAa,YAA4B,WACpD,WAAW,SAAS,WAAW,SAAS,MAAM;;AAGhD,SAAgB,SAAS,QAAwB;CAE/C,MAAM,QADO,OAAO,MAAM,OAAO,YAAY,GAAG,IAAI,CACnC,CAAC,CACf,QAAQ,sBAAsB,OAAO,CAAC,CACtC,QAAQ,MAAM,GAAG,CAAC,CAClB,YAAY;CACf,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,MAAM,CAAC;AACtD;;;;;AAMA,SAAgB,YAAY,MAAsB;CAChD,MAAM,QAAQ,KAAK,QAAQ,IAAI;CAC/B,IAAI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AI,GACtC,GAAG,MAAM,KAAK,KAAK,UAAU,MAAM,SAAS,MAAM,KAAK,CACzD;EACF,KAAK,YACH,OAAO,MAAM,SAAS,KAAK,WAAW,OAAO,IAAI;EACnD,KAAK,YACH,OAAO,CACL,GAAG,MAAM,SAAS,KAAK,YAAY,QAAQ,IAAI,GAC/C,GAAG,MAAM,QAAQ,KAAK,WAAW,OAAO,IAAI,CAC9C;EACF,KAAK,QACH,OAAO,MAAM,MAAM,KAAK,WAAW,OAAO,IAAI;CAClD;AACF;;;;;AAQA,SAAgB,WACd,OACA,SACA,SACY;CACZ,IAAI,UAAU,QAAQ,SAAS,OAAO;CACtC,OAAO,YAAY,OAAO,UAAU;AACtC;AAQA,MAAM,qBAA0B,IAAI,IAAI;CAAC;CAAQ;CAAU;CAAa;CAAM;CAAS;AAAQ,CAAC;AAChG,MAAM,sBAA2B,IAAI,IAAI;CACvC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAgB,OAAO,QAA4B;CACjD,MAAM,OAAO,OAAO,KAAK,CAAC,CAAC,YAAY;CACvC,IAAI,GAAG,IAAI,IAAI,GAAG,OAAO;CACzB,IAAI,IAAI,IAAI,IAAI,GAAG,OAAO;CAC1B,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"about.js","names":[],"sources":["../src/about.ts"],"sourcesContent":["/**\n * Qué puede: what an agent says about itself and the facts it rests on (`GET /agents/{id}/about`,\n * `POST /agents/{id}/describe`). The words are the model's, written from the agent's folder and\n * stale the moment it changes; the facts are the platform's, read each time. Their types are the\n * contract's (`contract.ts`).\n */\n\nimport type * as C from \"./contract\";\n\n/** The marks the package draws (a topic's, an automation's kind, a note's tone). */\nexport const ICONS = [\n \"message\",\n \"phone\",\n \"mail\",\n \"calendar\",\n \"clock\",\n \"search\",\n \"file\",\n \"table\",\n \"bell\",\n \"hand\",\n \"user\",\n \"globe\",\n \"code\",\n \"lock\",\n \"cart\",\n \"card\",\n \"map\",\n \"check\",\n \"warning\",\n \"sparkle\",\n] as const;\n\nexport type Icon = (typeof ICONS)[number];\n\n/** One automation as the agent tells it: what it does then, and when (\"Cada día a las 8:00\"). */\nexport type Does = C.Does;\n\n/** What the agent says about itself: a lead, what it does, what it asks leave for. */\nexport type About = C.About;\n\nexport type ActionSource = C.ActionRowOut[\"source\"];\n\n/** One of its actions: where it comes from, whether it is on and asks first, its input. */\nexport type ActionFact = C.ActionRowOut;\n\nexport type AutomationKind = C.FactAutomation[\"kind\"];\n\n/** Something the agent does on its own: at a time, when another system calls, on an app's event\n * (with the app's name and mark), on a message. */\nexport type AutomationFact = C.FactAutomation;\n\n/** Who brings an app: one of the providers, an MCP server, the business's own API. */\nexport type Provider = \"arcade\" | \"composio\" | \"mcp\" | \"api\";\n\n/** An app it was given: its name and mark, and its tools, with their names for people\n * (`titles`) and as the model calls them (`called`). */\nexport type ConnectionFact = C.FactConnection;\n\n/** An app of the agent's as people write it: its provider's name, else its alias made words. */\nexport const appTitle = (connection: ConnectionFact): string =>\n connection.title || toolName(connection.name);\n\n/** A tool of an app as people read it: its provider's name for it, else its own made words. */\nexport const toolTitle = (connection: ConnectionFact, action: string): string =>\n connection.titles?.[action] ?? toolName(action);\n\n/** A tool of an app as a person reads it: `Gmail.SendEmail` is \"Send email\". */\nexport function toolName(action: string): string {\n const bare = action.slice(action.lastIndexOf(\".\") + 1);\n const words = bare\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/_/g, \" \")\n .toLowerCase();\n return words.charAt(0).toUpperCase() + words.slice(1);\n}\n\n/**\n * An action's name made words, for one nobody named: `ver_hoja` is \"Ver hoja\"; an app's tool\n * as the model calls it, `gmail__GMAIL_SEND_EMAIL`, is \"Send email (Gmail)\".\n */\nexport function actionWords(name: string): string {\n const split = name.indexOf(\"__\");\n if (split < 0) return toolName(name);\n const tool = name.slice(split + 2);\n const bare = tool.slice(tool.indexOf(\"_\") + 1) || tool;\n return `${toolName(bare)} (${toolName(name.slice(0, split))})`;\n}\n\n/** The longest name the model takes for a tool (`app/connections` cuts there too). */\nconst MAX_TOOL_NAME = 64;\n\n/**\n * `gmail` + `Gmail.SendEmail` → `gmail__Gmail_SendEmail`: the tool the model is given.\n * @deprecated The facts say it: `ConnectionFact.called`.\n */\nexport const generatedName = (alias: string, action: string): string =>\n `${alias}__${action.replace(/[^A-Za-z0-9_]/g, \"_\")}`.slice(0, MAX_TOOL_NAME);\n\n/**\n * The tools the agent's apps give it, by the names the model calls them, in words: the\n * provider's for the tool and the app's (\"List Events (Google Calendar)\"), as a chat's steps\n * read them (`ChatMessages.steps`).\n */\nexport function appSteps(connections: readonly ConnectionFact[]): Record<string, string> {\n return Object.fromEntries(\n connections.flatMap((connection) =>\n connection.actions.map((action) => [\n connection.called[action] ?? generatedName(connection.name, action),\n `${toolTitle(connection, action)} (${appTitle(connection)})`,\n ]),\n ),\n );\n}\n\nexport type ChannelKind = \"whatsapp\" | \"instagram\" | \"email\" | \"sms\" | \"web\" | \"phone\";\n\nexport type ChannelFact = C.FactChannel;\n\n/** A file the agent can read: its own, or one of the organization's, shared with every agent. */\nexport type FileFact = C.FactFile;\n\n/** A line the agent kept with `remember`: its own, or about the contact it names. */\nexport type MemoryFact = C.MemoryOut;\n\n/** A key the agent may use: its own, or one of the organization's its access gives it. */\nexport type VaultFact = C.FactKey;\n\n/** A table of the organization's the agent may read or write (an agenda, the clients). */\nexport type DataFact = C.FactTable;\n\nexport type AskFact = C.FactAsk;\n\nexport type DeviceKind = C.FactDevice[\"kind\"];\n\nexport type DeviceFact = C.FactDevice;\n\n/** What the agent has, every list present from day one; one whose phase has not come is empty:\n * its files its own first, its memories newest first. */\nexport type Facts = C.Facts;\n\n/** What it says (null until written once; `about_at` null when the folder changed since, so the\n * words are stale) and the facts. */\nexport type AboutOut = C.AboutOut;\n\n/**\n * What the panel lists of the facts beside what the agent does on its own, gathered into a few\n * things an owner reads at a glance: the apps it uses, its tools, what it knows (files and\n * tables), what it has learned, where it works (channels and devices), and its keys.\n */\nexport type Topic = \"apps\" | \"tools\" | \"knowledge\" | \"learning\" | \"channels\" | \"keys\";\n\n/** The topics in the order the panel lists them. */\nexport const TOPICS: readonly Topic[] = [\n \"apps\",\n \"tools\",\n \"knowledge\",\n \"learning\",\n \"channels\",\n \"keys\",\n];\n\n/** An automation with what the agent said about it, when it said something. */\nexport interface Told {\n automation: AutomationFact;\n line: Does | undefined;\n}\n\n/**\n * The agent's automations, in their order, each with the agent's line about it (matched by id):\n * one added since the words were written has none yet, and a line for one since removed is\n * dropped.\n */\nexport function automationsOf(about: About | null, facts: Facts): Told[] {\n const lines = new Map((about?.does ?? []).map((line) => [line.automation, line]));\n return facts.automations.map((automation) => ({ automation, line: lines.get(automation.id) }));\n}\n\n/** How many things a topic holds: the tools that are on, the rest whole. */\nexport function countOf(topic: Topic, facts: Facts): number {\n return namesOf(topic, facts, (action) => action.name).length;\n}\n\n/**\n * The names of what a topic holds, in order, as its row in the panel previews them: an app by its\n * name, a tool by `label` (the host's words for the shipped ones), a file by its path and a table\n * by its title, what it learned by the line itself.\n */\nexport function namesOf(\n topic: Topic,\n facts: Facts,\n label: (action: ActionFact) => string,\n): string[] {\n switch (topic) {\n case \"apps\":\n return facts.connections.map(appTitle);\n case \"tools\":\n return facts.actions.filter((action) => action.on).map(label);\n case \"knowledge\":\n return [\n ...facts.files.map((file) => file.path),\n ...facts.data.map((table) => table.title ?? table.table),\n ];\n case \"learning\":\n return facts.memories.map((memory) => memory.text);\n case \"channels\":\n return [\n ...facts.channels.map((channel) => channel.name),\n ...facts.devices.map((device) => device.name),\n ];\n case \"keys\":\n return facts.vault.map((secret) => secret.name);\n }\n}\n\nexport type AboutState = \"writing\" | \"stale\" | \"fresh\";\n\n/**\n * Which state the words are in: `writing` while there are none yet or the agent is writing them\n * anew (`loading`), `stale` when the agent changed since it wrote them, `fresh` otherwise.\n */\nexport function aboutState(\n about: About | null,\n aboutAt: string | null,\n loading: boolean,\n): AboutState {\n if (about === null || loading) return \"writing\";\n return aboutAt === null ? \"stale\" : \"fresh\";\n}\n\n/** A file's size as people read it (the kit's, where the file chips draw it). */\nexport { formatSize } from \"./kit/numbers\";\n\n/** How a status reads beside its words: working, broken, or neither. */\nexport type StatusTone = \"on\" | \"off\" | \"quiet\";\n\nconst ON: ReadonlySet<string> = new Set([\"live\", \"active\", \"connected\", \"on\", \"ready\", \"online\"]);\nconst OFF: ReadonlySet<string> = new Set([\n \"failed\",\n \"error\",\n \"disconnected\",\n \"off\",\n \"expired\",\n \"broken\",\n]);\n\n/** The tone of a channel's or a device's status, from the words the platform uses for it. */\nexport function toneOf(status: string): StatusTone {\n const word = status.trim().toLowerCase();\n if (ON.has(word)) return \"on\";\n if (OFF.has(word)) return \"off\";\n return \"quiet\";\n}\n"],"mappings":";;;AAUA,MAAa,QAAQ;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AA6BA,MAAa,YAAY,eACvB,WAAW,SAAS,SAAS,WAAW,IAAI;;AAG9C,MAAa,aAAa,YAA4B,WACpD,WAAW,SAAS,WAAW,SAAS,MAAM;;AAGhD,SAAgB,SAAS,QAAwB;CAE/C,MAAM,QADO,OAAO,MAAM,OAAO,YAAY,GAAG,IAAI,CACnC,CAAC,CACf,QAAQ,sBAAsB,OAAO,CAAC,CACtC,QAAQ,MAAM,GAAG,CAAC,CAClB,YAAY;CACf,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,MAAM,CAAC;AACtD;;;;;AAMA,SAAgB,YAAY,MAAsB;CAChD,MAAM,QAAQ,KAAK,QAAQ,IAAI;CAC/B,IAAI,QAAQ,GAAG,OAAO,SAAS,IAAI;CACnC,MAAM,OAAO,KAAK,MAAM,QAAQ,CAAC;CAEjC,OAAO,GAAG,SADG,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,IAC3B,EAAE,IAAI,SAAS,KAAK,MAAM,GAA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AAS,KAAK,YAAY,QAAQ,IAAI,GAC/C,GAAG,MAAM,QAAQ,KAAK,WAAW,OAAO,IAAI,CAC9C;EACF,KAAK,QACH,OAAO,MAAM,MAAM,KAAK,WAAW,OAAO,IAAI;CAClD;AACF;;;;;AAQA,SAAgB,WACd,OACA,SACA,SACY;CACZ,IAAI,UAAU,QAAQ,SAAS,OAAO;CACtC,OAAO,YAAY,OAAO,UAAU;AACtC;AAQA,MAAM,qBAA0B,IAAI,IAAI;CAAC;CAAQ;CAAU;CAAa;CAAM;CAAS;AAAQ,CAAC;AAChG,MAAM,sBAA2B,IAAI,IAAI;CACvC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAgB,OAAO,QAA4B;CACjD,MAAM,OAAO,OAAO,KAAK,CAAC,CAAC,YAAY;CACvC,IAAI,GAAG,IAAI,IAAI,GAAG,OAAO;CACzB,IAAI,IAAI,IAAI,IAAI,GAAG,OAAO;CAC1B,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/automation/cron.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* A schedule's cron line, read into what it fires at: the moments of a day (
|
|
3
|
+
* A schedule's cron line, read into what it fires at: the moments of a day (the agents' day, an
|
|
4
4
|
* automation's next runs) and the sentence that says it (`whenOf`). Five fields (minute, hour,
|
|
5
5
|
* day of the month, month, day of the week) with `*`, lists, ranges, steps and English names, as
|
|
6
6
|
* the API's croniter reads them; anything past that is not read (null).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cron.js","names":[],"sources":["../../src/automation/cron.ts"],"sourcesContent":["/**\n * A schedule's cron line, read into what it fires at: the moments of a day (a squad's day, an\n * automation's next runs) and the sentence that says it (`whenOf`). Five fields (minute, hour,\n * day of the month, month, day of the week) with `*`, lists, ranges, steps and English names, as\n * the API's croniter reads them; anything past that is not read (null).\n */\n\nexport interface Cron {\n minutes: ReadonlySet<number>;\n hours: ReadonlySet<number>;\n /** Day of the month, 1–31. */\n days: ReadonlySet<number>;\n /** 1–12. */\n months: ReadonlySet<number>;\n /** 0–6, Sunday 0. */\n weekdays: ReadonlySet<number>;\n /** Left open (`*`): cron's rule for days reads which of the two narrows them. */\n anyDay: boolean;\n anyWeekday: boolean;\n}\n\ninterface Field {\n min: number;\n max: number;\n names?: readonly string[];\n}\n\nconst MONTH_NAMES = [\n \"jan\",\n \"feb\",\n \"mar\",\n \"apr\",\n \"may\",\n \"jun\",\n \"jul\",\n \"aug\",\n \"sep\",\n \"oct\",\n \"nov\",\n \"dec\",\n] as const;\nconst WEEKDAY_NAMES = [\"sun\", \"mon\", \"tue\", \"wed\", \"thu\", \"fri\", \"sat\"] as const;\n\nconst FIELDS: readonly Field[] = [\n { min: 0, max: 59 },\n { min: 0, max: 23 },\n { min: 1, max: 31 },\n { min: 1, max: 12, names: MONTH_NAMES },\n { min: 0, max: 7, names: WEEKDAY_NAMES },\n];\n\n/** One value of a field: a number in its bounds, or one of its names (`mon`, `jan`). */\nfunction valueOf(text: string, field: Field): number | null {\n const named = field.names?.indexOf(text.toLowerCase()) ?? -1;\n if (named >= 0) return named + field.min;\n if (!/^\\d+$/.test(text)) return null;\n const value = Number(text);\n return value >= field.min && value <= field.max ? value : null;\n}\n\n/** A field's values: `*`, `5`, `1-5`, `*` every 15, `8-18` every 2, `mon-fri`, and lists of them. */\nfunction parseField(text: string, field: Field): number[] | null {\n const values = new Set<number>();\n for (const part of text.split(\",\")) {\n const [range = \"\", stepText] = part.split(\"/\");\n const step = stepText === undefined ? 1 : Number(stepText);\n if (!Number.isInteger(step) || step < 1) return null;\n let from: number | null;\n let to: number | null;\n if (range === \"*\") {\n [from, to] = [field.min, field.max];\n } else {\n const [first = \"\", last] = range.split(\"-\");\n from = valueOf(first, field);\n // \"8/2\" runs from 8 to the end of the field, as cron reads it.\n to = last !== undefined ? valueOf(last, field) : stepText !== undefined ? field.max : from;\n }\n if (from === null || to === null || from > to) return null;\n for (let value = from; value <= to; value += step) values.add(value);\n }\n return [...values];\n}\n\n/** A cron line of five fields, or null when it is anything else. */\nexport function parseCron(line: string): Cron | null {\n const texts = line.trim().split(/\\s+/);\n if (texts.length !== 5) return null;\n const [minutes, hours, days, months, weekdays] = texts.map((text, at) => {\n const field = FIELDS[at];\n return field ? parseField(text, field) : null;\n });\n if (!minutes || !hours || !days || !months || !weekdays) return null;\n return {\n minutes: new Set(minutes),\n hours: new Set(hours),\n days: new Set(days),\n months: new Set(months),\n // 7 is Sunday too.\n weekdays: new Set(weekdays.map((day) => day % 7)),\n anyDay: texts[2]?.startsWith(\"*\") ?? false,\n anyWeekday: texts[4]?.startsWith(\"*\") ?? false,\n };\n}\n\n/** A moment as a zone's clock reads it. */\nexport interface Wall {\n minute: number;\n hour: number;\n day: number;\n month: number;\n weekday: number;\n}\n\n/**\n * Whether the line fires at that minute. Days follow cron's rule: when both the day of the month\n * and the day of the week are narrowed, either one is enough.\n */\nexport function fires(cron: Cron, at: Wall): boolean {\n if (!cron.minutes.has(at.minute) || !cron.hours.has(at.hour) || !cron.months.has(at.month)) {\n return false;\n }\n const day = cron.days.has(at.day);\n const weekday = cron.weekdays.has(at.weekday);\n if (cron.anyDay && cron.anyWeekday) return true;\n if (cron.anyDay) return weekday;\n if (cron.anyWeekday) return day;\n return day || weekday;\n}\n\nconst MINUTE = 60_000;\n/** How often the zone's offset is read again: a quarter of an hour meets every zone's changes. */\nconst QUARTER = 15 * MINUTE;\n\nconst clocks = new Map<string, Intl.DateTimeFormat>();\n\n/** The zone's clock, kept; an unknown zone reads as UTC, the API's default. */\nfunction clockOf(zone: string): Intl.DateTimeFormat {\n let clock = clocks.get(zone);\n if (!clock) {\n const options: Intl.DateTimeFormatOptions = {\n hourCycle: \"h23\",\n year: \"numeric\",\n month: \"numeric\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n second: \"numeric\",\n };\n try {\n clock = new Intl.DateTimeFormat(\"en-US\", { ...options, timeZone: zone });\n } catch {\n clock = new Intl.DateTimeFormat(\"en-US\", { ...options, timeZone: \"UTC\" });\n }\n clocks.set(zone, clock);\n }\n return clock;\n}\n\n/** How far the zone's clock is ahead of UTC at a moment, in milliseconds. */\nexport function offsetOf(zone: string, at: Date): number {\n const parts = clockOf(zone).formatToParts(at);\n const part = (type: Intl.DateTimeFormatPartTypes) =>\n Number(parts.find((each) => each.type === type)?.value ?? 0);\n const wall = Date.UTC(\n part(\"year\"),\n part(\"month\") - 1,\n part(\"day\"),\n part(\"hour\") % 24,\n part(\"minute\"),\n part(\"second\"),\n );\n return wall - Math.floor(at.getTime() / 1000) * 1000;\n}\n\n/** Every moment in [from, to) the line fires at, read on the clock of `zone`. */\nexport function occurrences(cron: Cron, zone: string, from: Date, to: Date): Date[] {\n const out: Date[] = [];\n let quarter = Number.NaN;\n let offset = 0;\n for (let at = Math.ceil(from.getTime() / MINUTE) * MINUTE; at < to.getTime(); at += MINUTE) {\n if (Math.floor(at / QUARTER) !== quarter) {\n quarter = Math.floor(at / QUARTER);\n offset = offsetOf(zone, new Date(at));\n }\n const wall = new Date(at + offset);\n const fired = fires(cron, {\n minute: wall.getUTCMinutes(),\n hour: wall.getUTCHours(),\n day: wall.getUTCDate(),\n month: wall.getUTCMonth() + 1,\n weekday: wall.getUTCDay(),\n });\n if (fired) out.push(new Date(at));\n }\n return out;\n}\n"],"mappings":";AA2CA,MAAM,SAA2B;CAC/B;EAAE,KAAK;EAAG,KAAK;CAAG;CAClB;EAAE,KAAK;EAAG,KAAK;CAAG;CAClB;EAAE,KAAK;EAAG,KAAK;CAAG;CAClB;EAAE,KAAK;EAAG,KAAK;EAAI,OAAO;GAnB1B;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EAQoC;CAAE;CACtC;EAAE,KAAK;EAAG,KAAK;EAAG,OAAO;GAPJ;GAAO;GAAO;GAAO;GAAO;GAAO;GAAO;EAO1B;CAAE;AACzC;;AAGA,SAAS,QAAQ,MAAc,OAA6B;CAC1D,MAAM,QA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,UAAU;GAAM,CAAC;EAC1E;EACA,OAAO,IAAI,MAAM,KAAK;CACxB;CACA,OAAO;AACT;;AAGA,SAAgB,SAAS,MAAc,IAAkB;CACvD,MAAM,QAAQ,QAAQ,IAAI,CAAC,CAAC,cAAc,EAAE;CAC5C,MAAM,QAAQ,SACZ,OAAO,MAAM,MAAM,SAAS,KAAK,SAAS,IAAI,CAAC,EAAE,SAAS,CAAC;CAS7D,OARa,KAAK,IAChB,KAAK,MAAM,GACX,KAAK,OAAO,IAAI,GAChB,KAAK,KAAK,GACV,KAAK,MAAM,IAAI,IACf,KAAK,QAAQ,GACb,KAAK,QAAQ,CAEL,IAAI,KAAK,MAAM,GAAG,QAAQ,IAAI,GAAI,IAAI;AAClD;;AAGA,SAAgB,YAAY,MAAY,MAAc,MAAY,IAAkB;CAClF,MAAM,MAAc,CAAC;CACrB,IAAI,UAAU;CACd,IAAI,SAAS;CACb,KAAK,IAAI,KAAK,KAAK,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,QAAQ,KAAK,GAAG,QAAQ,GAAG,MAAM,QAAQ;EAC1F,IAAI,KAAK,MAAM,KAAK,OAAO,MAAM,SAAS;GACxC,UAAU,KAAK,MAAM,KAAK,OAAO;GACjC,SAAS,SAAS,MAAM,IAAI,KAAK,EAAE,CAAC;EACtC;EACA,MAAM,OAAO,IAAI,KAAK,KAAK,MAAM;EAQjC,IAPc,MAAM,MAAM;GACxB,QAAQ,KAAK,cAAc;GAC3B,MAAM,KAAK,YAAY;GACvB,KAAK,KAAK,WAAW;GACrB,OAAO,KAAK,YAAY,IAAI;GAC5B,SAAS,KAAK,UAAU;EAC1B,CACQ,GAAG,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC;CAClC;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"cron.js","names":[],"sources":["../../src/automation/cron.ts"],"sourcesContent":["/**\n * A schedule's cron line, read into what it fires at: the moments of a day (the agents' day, an\n * automation's next runs) and the sentence that says it (`whenOf`). Five fields (minute, hour,\n * day of the month, month, day of the week) with `*`, lists, ranges, steps and English names, as\n * the API's croniter reads them; anything past that is not read (null).\n */\n\nexport interface Cron {\n minutes: ReadonlySet<number>;\n hours: ReadonlySet<number>;\n /** Day of the month, 1–31. */\n days: ReadonlySet<number>;\n /** 1–12. */\n months: ReadonlySet<number>;\n /** 0–6, Sunday 0. */\n weekdays: ReadonlySet<number>;\n /** Left open (`*`): cron's rule for days reads which of the two narrows them. */\n anyDay: boolean;\n anyWeekday: boolean;\n}\n\ninterface Field {\n min: number;\n max: number;\n names?: readonly string[];\n}\n\nconst MONTH_NAMES = [\n \"jan\",\n \"feb\",\n \"mar\",\n \"apr\",\n \"may\",\n \"jun\",\n \"jul\",\n \"aug\",\n \"sep\",\n \"oct\",\n \"nov\",\n \"dec\",\n] as const;\nconst WEEKDAY_NAMES = [\"sun\", \"mon\", \"tue\", \"wed\", \"thu\", \"fri\", \"sat\"] as const;\n\nconst FIELDS: readonly Field[] = [\n { min: 0, max: 59 },\n { min: 0, max: 23 },\n { min: 1, max: 31 },\n { min: 1, max: 12, names: MONTH_NAMES },\n { min: 0, max: 7, names: WEEKDAY_NAMES },\n];\n\n/** One value of a field: a number in its bounds, or one of its names (`mon`, `jan`). */\nfunction valueOf(text: string, field: Field): number | null {\n const named = field.names?.indexOf(text.toLowerCase()) ?? -1;\n if (named >= 0) return named + field.min;\n if (!/^\\d+$/.test(text)) return null;\n const value = Number(text);\n return value >= field.min && value <= field.max ? value : null;\n}\n\n/** A field's values: `*`, `5`, `1-5`, `*` every 15, `8-18` every 2, `mon-fri`, and lists of them. */\nfunction parseField(text: string, field: Field): number[] | null {\n const values = new Set<number>();\n for (const part of text.split(\",\")) {\n const [range = \"\", stepText] = part.split(\"/\");\n const step = stepText === undefined ? 1 : Number(stepText);\n if (!Number.isInteger(step) || step < 1) return null;\n let from: number | null;\n let to: number | null;\n if (range === \"*\") {\n [from, to] = [field.min, field.max];\n } else {\n const [first = \"\", last] = range.split(\"-\");\n from = valueOf(first, field);\n // \"8/2\" runs from 8 to the end of the field, as cron reads it.\n to = last !== undefined ? valueOf(last, field) : stepText !== undefined ? field.max : from;\n }\n if (from === null || to === null || from > to) return null;\n for (let value = from; value <= to; value += step) values.add(value);\n }\n return [...values];\n}\n\n/** A cron line of five fields, or null when it is anything else. */\nexport function parseCron(line: string): Cron | null {\n const texts = line.trim().split(/\\s+/);\n if (texts.length !== 5) return null;\n const [minutes, hours, days, months, weekdays] = texts.map((text, at) => {\n const field = FIELDS[at];\n return field ? parseField(text, field) : null;\n });\n if (!minutes || !hours || !days || !months || !weekdays) return null;\n return {\n minutes: new Set(minutes),\n hours: new Set(hours),\n days: new Set(days),\n months: new Set(months),\n // 7 is Sunday too.\n weekdays: new Set(weekdays.map((day) => day % 7)),\n anyDay: texts[2]?.startsWith(\"*\") ?? false,\n anyWeekday: texts[4]?.startsWith(\"*\") ?? false,\n };\n}\n\n/** A moment as a zone's clock reads it. */\nexport interface Wall {\n minute: number;\n hour: number;\n day: number;\n month: number;\n weekday: number;\n}\n\n/**\n * Whether the line fires at that minute. Days follow cron's rule: when both the day of the month\n * and the day of the week are narrowed, either one is enough.\n */\nexport function fires(cron: Cron, at: Wall): boolean {\n if (!cron.minutes.has(at.minute) || !cron.hours.has(at.hour) || !cron.months.has(at.month)) {\n return false;\n }\n const day = cron.days.has(at.day);\n const weekday = cron.weekdays.has(at.weekday);\n if (cron.anyDay && cron.anyWeekday) return true;\n if (cron.anyDay) return weekday;\n if (cron.anyWeekday) return day;\n return day || weekday;\n}\n\nconst MINUTE = 60_000;\n/** How often the zone's offset is read again: a quarter of an hour meets every zone's changes. */\nconst QUARTER = 15 * MINUTE;\n\nconst clocks = new Map<string, Intl.DateTimeFormat>();\n\n/** The zone's clock, kept; an unknown zone reads as UTC, the API's default. */\nfunction clockOf(zone: string): Intl.DateTimeFormat {\n let clock = clocks.get(zone);\n if (!clock) {\n const options: Intl.DateTimeFormatOptions = {\n hourCycle: \"h23\",\n year: \"numeric\",\n month: \"numeric\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n second: \"numeric\",\n };\n try {\n clock = new Intl.DateTimeFormat(\"en-US\", { ...options, timeZone: zone });\n } catch {\n clock = new Intl.DateTimeFormat(\"en-US\", { ...options, timeZone: \"UTC\" });\n }\n clocks.set(zone, clock);\n }\n return clock;\n}\n\n/** How far the zone's clock is ahead of UTC at a moment, in milliseconds. */\nexport function offsetOf(zone: string, at: Date): number {\n const parts = clockOf(zone).formatToParts(at);\n const part = (type: Intl.DateTimeFormatPartTypes) =>\n Number(parts.find((each) => each.type === type)?.value ?? 0);\n const wall = Date.UTC(\n part(\"year\"),\n part(\"month\") - 1,\n part(\"day\"),\n part(\"hour\") % 24,\n part(\"minute\"),\n part(\"second\"),\n );\n return wall - Math.floor(at.getTime() / 1000) * 1000;\n}\n\n/** Every moment in [from, to) the line fires at, read on the clock of `zone`. */\nexport function occurrences(cron: Cron, zone: string, from: Date, to: Date): Date[] {\n const out: Date[] = [];\n let quarter = Number.NaN;\n let offset = 0;\n for (let at = Math.ceil(from.getTime() / MINUTE) * MINUTE; at < to.getTime(); at += MINUTE) {\n if (Math.floor(at / QUARTER) !== quarter) {\n quarter = Math.floor(at / QUARTER);\n offset = offsetOf(zone, new Date(at));\n }\n const wall = new Date(at + offset);\n const fired = fires(cron, {\n minute: wall.getUTCMinutes(),\n hour: wall.getUTCHours(),\n day: wall.getUTCDate(),\n month: wall.getUTCMonth() + 1,\n weekday: wall.getUTCDay(),\n });\n if (fired) out.push(new Date(at));\n }\n return out;\n}\n"],"mappings":";AA2CA,MAAM,SAA2B;CAC/B;EAAE,KAAK;EAAG,KAAK;CAAG;CAClB;EAAE,KAAK;EAAG,KAAK;CAAG;CAClB;EAAE,KAAK;EAAG,KAAK;CAAG;CAClB;EAAE,KAAK;EAAG,KAAK;EAAI,OAAO;GAnB1B;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EAQoC;CAAE;CACtC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ACT"}
|
package/dist/automation/marks.js
CHANGED
|
@@ -27,9 +27,11 @@ function AppMark({ name, icon, size, apps }) {
|
|
|
27
27
|
}
|
|
28
28
|
const KINDS = {
|
|
29
29
|
schedule: ClockIcon,
|
|
30
|
-
webhook: WebhooksLogoIcon
|
|
30
|
+
webhook: WebhooksLogoIcon,
|
|
31
|
+
platform: ChatCircleIcon
|
|
31
32
|
};
|
|
32
|
-
/** What starts an automation, as a mark: a clock, a webhook, the app whose event it
|
|
33
|
+
/** What starts an automation, as a mark: a clock, a webhook, a message, the app whose event it
|
|
34
|
+
* waits for. */
|
|
33
35
|
function TriggerMark({ trigger, size, apps }) {
|
|
34
36
|
if (trigger.kind !== "event") return /* @__PURE__ */ jsx(Mark, {
|
|
35
37
|
icon: KINDS[trigger.kind],
|
|
@@ -47,10 +49,12 @@ function TriggerMark({ trigger, size, apps }) {
|
|
|
47
49
|
apps
|
|
48
50
|
});
|
|
49
51
|
}
|
|
50
|
-
/** What started a run: its time, a call, its app's event, a chat with the agent, a
|
|
52
|
+
/** What started a run: its time, a call, its app's event, a message, a chat with the agent, a
|
|
53
|
+
* test. */
|
|
51
54
|
const BY = {
|
|
52
55
|
schedule: ClockIcon,
|
|
53
56
|
webhook: WebhooksLogoIcon,
|
|
57
|
+
platform: ChatCircleIcon,
|
|
54
58
|
agent: ChatCircleIcon,
|
|
55
59
|
test: FlaskIcon
|
|
56
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marks.js","names":[],"sources":["../../src/automation/marks.tsx"],"sourcesContent":["import {\n BellIcon,\n BrainIcon,\n ChatCircleIcon,\n ChatTextIcon,\n ChatsCircleIcon,\n ClockIcon,\n FileTextIcon,\n FlaskIcon,\n GlobeIcon,\n LightningIcon,\n SparkleIcon,\n TableIcon,\n WebhooksLogoIcon,\n type Icon,\n} from \"@phosphor-icons/react\";\nimport type { ReactNode } from \"react\";\n\nimport type { AppDirectory } from \"../AgentAbout\";\nimport { Mark } from \"../kit/Mark\";\nimport { sentOn } from \"./record\";\nimport type { RunBy, RunStep, Trigger, Use } from \"./types\";\n\n/** Only an https logo is loaded: never a script, never a local file. */\nconst https = (url: string | null): url is string => url !== null && /^https:\\/\\//i.test(url);\n\n/**\n * An app's mark: the host's logo when it draws apps (`apps`), else the logo the API gives, else\n * the app's initial; each bare, as `Mark` draws it.\n */\nexport function AppMark({\n name,\n icon,\n size,\n apps,\n}: {\n name: string;\n icon: string | null;\n size: number;\n apps: AppDirectory | undefined;\n}) {\n if (apps !== undefined) return <>{apps.logo({ provider: \"\", name, icon, size })}</>;\n if (https(icon)) return <Mark src={icon} size={size} />;\n return (\n <Mark size={size}>\n <span>{name.trim().charAt(0).toUpperCase() || \"?\"}</span>\n </Mark>\n );\n}\n\nconst KINDS: Readonly<Record<Exclude<Trigger[\"kind\"], \"event\">, Icon>> = {\n schedule: ClockIcon,\n webhook: WebhooksLogoIcon,\n};\n\n/** What starts an automation, as a mark: a clock, a webhook, the app whose event it waits for. */\nexport function TriggerMark({\n trigger,\n size,\n apps,\n}: {\n trigger: Trigger;\n size: number;\n apps: AppDirectory | undefined;\n}) {\n if (trigger.kind !== \"event\") return <Mark icon={KINDS[trigger.kind]} size={size} />;\n const name = trigger.app_title ?? trigger.app;\n if (name === null) return <Mark icon={LightningIcon} size={size} />;\n return <AppMark name={name} icon={trigger.icon} size={size} apps={apps} />;\n}\n\n/** What started a run: its time, a call, its app's event, a chat with the agent, a test. */\nconst BY: Readonly<Record<Exclude<RunBy, \"event\">, Icon>> = {\n schedule: ClockIcon,\n webhook: WebhooksLogoIcon,\n agent: ChatCircleIcon,\n test: FlaskIcon,\n};\n\nexport function ByMark({\n by,\n trigger,\n size,\n apps,\n}: {\n by: RunBy;\n /** The automation's, for an event's app; none, a plain mark. */\n trigger: Trigger | null;\n size: number;\n apps: AppDirectory | undefined;\n}) {\n if (by !== \"event\") return <Mark icon={BY[by]} size={size} />;\n return trigger === null ? (\n <Mark icon={LightningIcon} size={size} />\n ) : (\n <TriggerMark trigger={trigger} size={size} apps={apps} />\n );\n}\n\n/**\n * What a step uses, other than an app: the model, the agent, the inbox, a message on a channel, a\n * table, the web.\n */\nexport const USES: Readonly<Record<Exclude<Use[\"kind\"], \"app\">, Icon>> = {\n ai: SparkleIcon,\n agent: ChatsCircleIcon,\n notify: BellIcon,\n send: ChatTextIcon,\n data: TableIcon,\n http: GlobeIcon,\n};\n\n/** A call of a run's record, by what it reached; an app's tool by the app's mark. */\nconst CALLS: Readonly<Record<string, Icon>> = {\n ai: SparkleIcon,\n notify: BellIcon,\n send: ChatTextIcon,\n \"agent.start\": ChatsCircleIcon,\n \"data.find\": TableIcon,\n \"data.add\": TableIcon,\n \"data.update\": TableIcon,\n http: GlobeIcon,\n \"files.search\": FileTextIcon,\n \"files.read\": FileTextIcon,\n \"files.write\": FileTextIcon,\n \"files.list\": FileTextIcon,\n \"memory.remember\": BrainIcon,\n \"memory.recall\": BrainIcon,\n};\n\nexport function callMark(\n step: RunStep,\n app: { name: string; icon: string | null } | null,\n apps: AppDirectory | undefined,\n size: number,\n): ReactNode {\n if (app !== null) return <AppMark name={app.name} icon={app.icon} size={size} apps={apps} />;\n // A message sent on a channel: the channel's brand, when the host draws brands and it is known.\n const channel = step.call === \"send\" ? sentOn(step) : null;\n if (channel !== null && apps !== undefined) {\n return apps.logo({ provider: channel, name: channel, size });\n }\n return <Mark icon={CALLS[step.call] ?? LightningIcon} size={size} />;\n}\n"],"mappings":";;;;;;AAwBA,MAAM,SAAS,QAAsC,QAAQ,QAAQ,eAAe,KAAK,GAAG;;;;;AAM5F,SAAgB,QAAQ,EACtB,MACA,MACA,MACA,QAMC;CACD,IAAI,SAAS,KAAA,GAAW,OAAO,oBAAA,UAAA,EAAA,UAAG,KAAK,KAAK;EAAE,UAAU;EAAI;EAAM;EAAM;CAAK,CAAC,EAAI,CAAA;CAClF,IAAI,MAAM,IAAI,GAAG,OAAO,oBAAC,MAAD;EAAM,KAAK;EAAY;CAAO,CAAA;CACtD,OACE,oBAAC,MAAD;EAAY;EACV,UAAA,oBAAC,QAAD,EAAA,UAAO,KAAK,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,KAAK,IAAU,CAAA;CACpD,CAAA;AAEV;AAEA,MAAM,QAAmE;CACvE,UAAU;CACV,SAAS;
|
|
1
|
+
{"version":3,"file":"marks.js","names":[],"sources":["../../src/automation/marks.tsx"],"sourcesContent":["import {\n BellIcon,\n BrainIcon,\n ChatCircleIcon,\n ChatTextIcon,\n ChatsCircleIcon,\n ClockIcon,\n FileTextIcon,\n FlaskIcon,\n GlobeIcon,\n LightningIcon,\n SparkleIcon,\n TableIcon,\n WebhooksLogoIcon,\n type Icon,\n} from \"@phosphor-icons/react\";\nimport type { ReactNode } from \"react\";\n\nimport type { AppDirectory } from \"../AgentAbout\";\nimport { Mark } from \"../kit/Mark\";\nimport { sentOn } from \"./record\";\nimport type { RunBy, RunStep, Trigger, Use } from \"./types\";\n\n/** Only an https logo is loaded: never a script, never a local file. */\nconst https = (url: string | null): url is string => url !== null && /^https:\\/\\//i.test(url);\n\n/**\n * An app's mark: the host's logo when it draws apps (`apps`), else the logo the API gives, else\n * the app's initial; each bare, as `Mark` draws it.\n */\nexport function AppMark({\n name,\n icon,\n size,\n apps,\n}: {\n name: string;\n icon: string | null;\n size: number;\n apps: AppDirectory | undefined;\n}) {\n if (apps !== undefined) return <>{apps.logo({ provider: \"\", name, icon, size })}</>;\n if (https(icon)) return <Mark src={icon} size={size} />;\n return (\n <Mark size={size}>\n <span>{name.trim().charAt(0).toUpperCase() || \"?\"}</span>\n </Mark>\n );\n}\n\nconst KINDS: Readonly<Record<Exclude<Trigger[\"kind\"], \"event\">, Icon>> = {\n schedule: ClockIcon,\n webhook: WebhooksLogoIcon,\n platform: ChatCircleIcon,\n};\n\n/** What starts an automation, as a mark: a clock, a webhook, a message, the app whose event it\n * waits for. */\nexport function TriggerMark({\n trigger,\n size,\n apps,\n}: {\n trigger: Trigger;\n size: number;\n apps: AppDirectory | undefined;\n}) {\n if (trigger.kind !== \"event\") return <Mark icon={KINDS[trigger.kind]} size={size} />;\n const name = trigger.app_title ?? trigger.app;\n if (name === null) return <Mark icon={LightningIcon} size={size} />;\n return <AppMark name={name} icon={trigger.icon} size={size} apps={apps} />;\n}\n\n/** What started a run: its time, a call, its app's event, a message, a chat with the agent, a\n * test. */\nconst BY: Readonly<Record<Exclude<RunBy, \"event\">, Icon>> = {\n schedule: ClockIcon,\n webhook: WebhooksLogoIcon,\n platform: ChatCircleIcon,\n agent: ChatCircleIcon,\n test: FlaskIcon,\n};\n\nexport function ByMark({\n by,\n trigger,\n size,\n apps,\n}: {\n by: RunBy;\n /** The automation's, for an event's app; none, a plain mark. */\n trigger: Trigger | null;\n size: number;\n apps: AppDirectory | undefined;\n}) {\n if (by !== \"event\") return <Mark icon={BY[by]} size={size} />;\n return trigger === null ? (\n <Mark icon={LightningIcon} size={size} />\n ) : (\n <TriggerMark trigger={trigger} size={size} apps={apps} />\n );\n}\n\n/**\n * What a step uses, other than an app: the model, the agent, the inbox, a message on a channel, a\n * table, the web.\n */\nexport const USES: Readonly<Record<Exclude<Use[\"kind\"], \"app\">, Icon>> = {\n ai: SparkleIcon,\n agent: ChatsCircleIcon,\n notify: BellIcon,\n send: ChatTextIcon,\n data: TableIcon,\n http: GlobeIcon,\n};\n\n/** A call of a run's record, by what it reached; an app's tool by the app's mark. */\nconst CALLS: Readonly<Record<string, Icon>> = {\n ai: SparkleIcon,\n notify: BellIcon,\n send: ChatTextIcon,\n \"agent.start\": ChatsCircleIcon,\n \"data.find\": TableIcon,\n \"data.add\": TableIcon,\n \"data.update\": TableIcon,\n http: GlobeIcon,\n \"files.search\": FileTextIcon,\n \"files.read\": FileTextIcon,\n \"files.write\": FileTextIcon,\n \"files.list\": FileTextIcon,\n \"memory.remember\": BrainIcon,\n \"memory.recall\": BrainIcon,\n};\n\nexport function callMark(\n step: RunStep,\n app: { name: string; icon: string | null } | null,\n apps: AppDirectory | undefined,\n size: number,\n): ReactNode {\n if (app !== null) return <AppMark name={app.name} icon={app.icon} size={size} apps={apps} />;\n // A message sent on a channel: the channel's brand, when the host draws brands and it is known.\n const channel = step.call === \"send\" ? sentOn(step) : null;\n if (channel !== null && apps !== undefined) {\n return apps.logo({ provider: channel, name: channel, size });\n }\n return <Mark icon={CALLS[step.call] ?? LightningIcon} size={size} />;\n}\n"],"mappings":";;;;;;AAwBA,MAAM,SAAS,QAAsC,QAAQ,QAAQ,eAAe,KAAK,GAAG;;;;;AAM5F,SAAgB,QAAQ,EACtB,MACA,MACA,MACA,QAMC;CACD,IAAI,SAAS,KAAA,GAAW,OAAO,oBAAA,UAAA,EAAA,UAAG,KAAK,KAAK;EAAE,UAAU;EAAI;EAAM;EAAM;CAAK,CAAC,EAAI,CAAA;CAClF,IAAI,MAAM,IAAI,GAAG,OAAO,oBAAC,MAAD;EAAM,KAAK;EAAY;CAAO,CAAA;CACtD,OACE,oBAAC,MAAD;EAAY;EACV,UAAA,oBAAC,QAAD,EAAA,UAAO,KAAK,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,KAAK,IAAU,CAAA;CACpD,CAAA;AAEV;AAEA,MAAM,QAAmE;CACvE,UAAU;CACV,SAAS;CACT,UAAU;AACZ;;;AAIA,SAAgB,YAAY,EAC1B,SACA,MACA,QAKC;CACD,IAAI,QAAQ,SAAS,SAAS,OAAO,oBAAC,MAAD;EAAM,MAAM,MAAM,QAAQ;EAAa;CAAO,CAAA;CACnF,MAAM,OAAO,QAAQ,aAAa,QAAQ;CAC1C,IAAI,SAAS,MAAM,OAAO,oBAAC,MAAD;EAAM,MAAM;EAAqB;CAAO,CAAA;CAClE,OAAO,oBAAC,SAAD;EAAe;EAAM,MAAM,QAAQ;EAAY;EAAY;CAAO,CAAA;AAC3E;;;AAIA,MAAM,KAAsD;CAC1D,UAAU;CACV,SAAS;CACT,UAAU;CACV,OAAO;CACP,MAAM;AACR;AAEA,SAAgB,OAAO,EACrB,IACA,SACA,MACA,QAOC;CACD,IAAI,OAAO,SAAS,OAAO,oBAAC,MAAD;EAAM,MAAM,GAAG;EAAW;CAAO,CAAA;CAC5D,OAAO,YAAY,OACjB,oBAAC,MAAD;EAAM,MAAM;EAAqB;CAAO,CAAA,IAExC,oBAAC,aAAD;EAAsB;EAAe;EAAY;CAAO,CAAA;AAE5D;;;;;AAMA,MAAa,OAA4D;CACvE,IAAI;CACJ,OAAO;CACP,QAAQ;CACR,MAAM;CACN,MAAM;CACN,MAAM;AACR;;AAGA,MAAM,QAAwC;CAC5C,IAAI;CACJ,QAAQ;CACR,MAAM;CACN,eAAe;CACf,aAAa;CACb,YAAY;CACZ,eAAe;CACf,MAAM;CACN,gBAAgB;CAChB,cAAc;CACd,eAAe;CACf,cAAc;CACd,mBAAmB;CACnB,iBAAiB;AACnB;AAEA,SAAgB,SACd,MACA,KACA,MACA,MACW;CACX,IAAI,QAAQ,MAAM,OAAO,oBAAC,SAAD;EAAS,MAAM,IAAI;EAAM,MAAM,IAAI;EAAY;EAAY;CAAO,CAAA;CAE3F,MAAM,UAAU,KAAK,SAAS,SAAS,OAAO,IAAI,IAAI;CACtD,IAAI,YAAY,QAAQ,SAAS,KAAA,GAC/B,OAAO,KAAK,KAAK;EAAE,UAAU;EAAS,MAAM;EAAS;CAAK,CAAC;CAE7D,OAAO,oBAAC,MAAD;EAAM,MAAM,MAAM,KAAK,SAAS;EAAqB;CAAO,CAAA;AACrE"}
|
|
@@ -67,6 +67,8 @@ export interface AutomationMessages {
|
|
|
67
67
|
/** What another kind of trigger waits for. */
|
|
68
68
|
webhook: string;
|
|
69
69
|
event: (app: string | null, event: string | null) => string;
|
|
70
|
+
/** One of the platform's events: a contact's message stored on a channel. */
|
|
71
|
+
platform: string;
|
|
70
72
|
/** When it runs next, after when it runs: the day, and the time when the line doesn't say it. */
|
|
71
73
|
next: (day: DayRef, time: string | null) => string;
|
|
72
74
|
/** How it stands, on its pill. */
|
|
@@ -13,6 +13,7 @@ const AUTOMATION_MESSAGES = {
|
|
|
13
13
|
on: (often, days) => `${often}, ${days.charAt(0).toLowerCase()}${days.slice(1)}`,
|
|
14
14
|
custom: "On a schedule of its own",
|
|
15
15
|
webhook: "When another system calls it",
|
|
16
|
+
platform: "When a message arrives",
|
|
16
17
|
event: (app, event) => event ? `When ${event} in ${app ?? "an app"}` : `On an event in ${app ?? "an app"}`,
|
|
17
18
|
next: (day, time) => {
|
|
18
19
|
const at = time === null ? "" : ` at ${time}`;
|
|
@@ -54,6 +55,7 @@ const AUTOMATION_MESSAGES = {
|
|
|
54
55
|
schedule: "scheduled",
|
|
55
56
|
webhook: "webhook",
|
|
56
57
|
event: app ? `${app} event` : "event",
|
|
58
|
+
platform: "a message",
|
|
57
59
|
agent: "you asked in the chat",
|
|
58
60
|
test: "test"
|
|
59
61
|
})[by],
|