ocean-crew 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -2
  3. package/THIRD_PARTY_NOTICES.md +159 -0
  4. package/client.js +31389 -0
  5. package/cordis.patch.yml +6 -0
  6. package/dist/host/chat/btw.js +436 -0
  7. package/dist/host/chat/channel.js +1241 -0
  8. package/dist/host/chat/chat-index.js +344 -0
  9. package/dist/host/chat/delivery.js +231 -0
  10. package/dist/host/chat/feed.js +165 -0
  11. package/dist/host/chat/handoffs.js +625 -0
  12. package/dist/host/chat/parts.js +2033 -0
  13. package/dist/host/chat/requests.js +155 -0
  14. package/dist/host/chat/resume.js +364 -0
  15. package/dist/host/chat/side.js +457 -0
  16. package/dist/host/chat/steer.js +346 -0
  17. package/dist/host/chat/turns.js +1457 -0
  18. package/dist/host/connectors/catalog.js +331 -0
  19. package/dist/host/connectors/gateway.js +339 -0
  20. package/dist/host/connectors/index.js +1235 -0
  21. package/dist/host/connectors/mail/index.js +912 -0
  22. package/dist/host/connectors/mail/presets.js +53 -0
  23. package/dist/host/connectors/mail/transport.js +519 -0
  24. package/dist/host/connectors/oauth.js +337 -0
  25. package/dist/host/core/constants.js +123 -0
  26. package/dist/host/core/diagnostics.js +310 -0
  27. package/dist/host/core/dsh-update.js +212 -0
  28. package/dist/host/core/events.js +16 -0
  29. package/dist/host/core/files.js +37 -0
  30. package/dist/host/core/folders.js +283 -0
  31. package/dist/host/core/home-lock.js +137 -0
  32. package/dist/host/core/links.js +52 -0
  33. package/dist/host/core/runtime.js +5 -0
  34. package/dist/host/core/store.js +662 -0
  35. package/dist/host/core/text.js +59 -0
  36. package/dist/host/core/thinking.js +60 -0
  37. package/dist/host/core/time-context.js +69 -0
  38. package/dist/host/core/update.js +466 -0
  39. package/dist/host/groups/calls.js +684 -0
  40. package/dist/host/groups/index.js +79 -0
  41. package/dist/host/groups/log.js +334 -0
  42. package/dist/host/groups/prompt.js +124 -0
  43. package/dist/host/groups/relay.js +489 -0
  44. package/dist/host/groups/round.js +992 -0
  45. package/dist/host/groups/tasks.js +217 -0
  46. package/dist/host/groups/tools.js +478 -0
  47. package/dist/host/groups/types.js +8 -0
  48. package/dist/host/im/format.js +228 -0
  49. package/dist/host/im/index.js +2461 -0
  50. package/dist/host/im/platforms/feishu.js +1134 -0
  51. package/dist/host/im/platforms/index.js +6 -0
  52. package/dist/host/im/platforms/media-type.js +70 -0
  53. package/dist/host/im/platforms/weixin.js +1117 -0
  54. package/dist/host/im/reaction.js +51 -0
  55. package/dist/host/im/supervisor.js +56 -0
  56. package/dist/host/team/agents.js +161 -0
  57. package/dist/host/team/models.js +427 -0
  58. package/dist/host/team/permissions.js +263 -0
  59. package/dist/host/team/privacy.js +108 -0
  60. package/dist/host/team/prompt.js +86 -0
  61. package/dist/host/team/providers.js +461 -0
  62. package/dist/host/team/roster.js +1011 -0
  63. package/dist/host/team/tools.js +1638 -0
  64. package/dist/host/work/approvals.js +290 -0
  65. package/dist/host/work/avatar-library.js +155 -0
  66. package/dist/host/work/avatar.js +132 -0
  67. package/dist/host/work/capabilities.js +862 -0
  68. package/dist/host/work/companion.js +306 -0
  69. package/dist/host/work/goal-skills.js +91 -0
  70. package/dist/host/work/goals.js +1337 -0
  71. package/dist/host/work/images.js +283 -0
  72. package/dist/host/work/learning.js +1021 -0
  73. package/dist/host/work/memory-pending.js +108 -0
  74. package/dist/host/work/memory.js +3237 -0
  75. package/dist/host/work/notify.js +146 -0
  76. package/dist/host/work/reset.js +43 -0
  77. package/dist/host/work/schedules.js +309 -0
  78. package/dist/host/work/secrets.js +702 -0
  79. package/dist/host/work/steward.js +166 -0
  80. package/dist/host/work/tts.js +192 -0
  81. package/dist/host/work/usage.js +84 -0
  82. package/dist/index.js +137 -0
  83. package/dist/shared/api.js +32 -0
  84. package/dist/shared/companion.js +110 -0
  85. package/dist/shared/config.js +3 -0
  86. package/dist/shared/coordination.js +6 -0
  87. package/dist/shared/group-replies.js +95 -0
  88. package/dist/shared/im-platforms.js +35 -0
  89. package/dist/shared/im.js +3 -0
  90. package/dist/shared/mentions.js +85 -0
  91. package/dist/shared/state.js +25 -0
  92. package/package.json +81 -5
@@ -0,0 +1,108 @@
1
+ // The record of a memory change that is about to be published.
2
+ //
3
+ // A change touches more than one file (the entry, the Index that links a topic, the
4
+ // change log), and each of them is written on its own, so an interruption can leave
5
+ // half of it done: an entry without its row in the change log, a topic without its
6
+ // link. This keeps the record of what the change will do, so the change can be
7
+ // finished later instead of being half done.
8
+ //
9
+ // The record is written before the change is published, and it is what accepts the
10
+ // change: before the record is there, nothing has changed. It holds the files to
11
+ // write, the files to remove, and the row that goes with them in the change log, so
12
+ // finishing a change later is the same work as publishing it in the first place.
13
+ import { readFileSync } from "node:fs";
14
+ import { join, relative, resolve, sep } from "node:path";
15
+ // The record inside the memory folder.
16
+ export const PENDING_FILE = "pending.json";
17
+ // A record that cannot be read or understood stops the memory: what it would have
18
+ // changed is unknown, so nothing goes on until it is fixed.
19
+ const PENDING = "memory/pending";
20
+ // A change is one entry, so its record stays small; a larger one was not written by
21
+ // this.
22
+ const MAX_BYTES = 1_048_576;
23
+ export function pendingPath(root) {
24
+ return join(root, PENDING_FILE);
25
+ }
26
+ // A path inside the memory folder, as the record holds it: relative, so the folder
27
+ // can be moved, and never outside it.
28
+ export function inside(root, path) {
29
+ const base = resolve(root);
30
+ const full = resolve(base, path);
31
+ if (full !== base && !full.startsWith(base + sep))
32
+ throw new Error(`the path ${path} is outside the memory folder`);
33
+ return full;
34
+ }
35
+ // The path of a file in the memory folder, as the record holds it.
36
+ export function relativePath(root, path) {
37
+ return relative(resolve(root), resolve(path)).split(sep).join("/");
38
+ }
39
+ // The record of a change: what it does, and the row that goes with it.
40
+ export function record({ id, time, op, scope, steps, row }) {
41
+ return { id, time, op, scope, steps, row: { time, id, ...row } };
42
+ }
43
+ // The record of a change, as it is written down. A record that would be too large is
44
+ // refused: the memory folder holds one change at a time, and a record that cannot be
45
+ // read back would stop the memory for good. The size is the same one the read side
46
+ // uses, so a record that is written can always be read.
47
+ export function serialize(record) {
48
+ const text = JSON.stringify(record);
49
+ const size = Buffer.byteLength(text);
50
+ if (size > MAX_BYTES) {
51
+ throw Object.assign(new Error(`The memory change is too large to record (${size} of ${MAX_BYTES} bytes). Make the memory file smaller first.`), { code: "memory/too-large" });
52
+ }
53
+ return text;
54
+ }
55
+ // The record waiting to be finished, if there is one. A record that cannot be read
56
+ // or understood is an error, not an empty record: the change it holds is unknown,
57
+ // and a change that is half done must not be passed over.
58
+ export function read(root) {
59
+ const path = pendingPath(root);
60
+ let text;
61
+ try {
62
+ text = readFileSync(path, "utf8");
63
+ }
64
+ catch (error) {
65
+ if (error?.code === "ENOENT")
66
+ return undefined;
67
+ const code = error?.code ?? error?.message;
68
+ throw Object.assign(new Error(`${PENDING_FILE} could not be read (${code})`), { code: PENDING });
69
+ }
70
+ if (Buffer.byteLength(text) > MAX_BYTES) {
71
+ throw Object.assign(new Error(`${PENDING_FILE} is larger than a memory change record`), { code: PENDING });
72
+ }
73
+ let value;
74
+ try {
75
+ value = JSON.parse(text);
76
+ }
77
+ catch (error) {
78
+ throw Object.assign(new Error(`${PENDING_FILE} is not readable (${error.message})`), {
79
+ code: PENDING,
80
+ });
81
+ }
82
+ if (!wellFormed(value)) {
83
+ throw Object.assign(new Error(`${PENDING_FILE} is not a memory change record`), { code: PENDING });
84
+ }
85
+ return value;
86
+ }
87
+ const wellFormed = (value) => {
88
+ if (value === null || typeof value !== "object" || Array.isArray(value))
89
+ return false;
90
+ const record = value;
91
+ if (typeof record.id !== "string" || record.id === "")
92
+ return false;
93
+ if (typeof record.op !== "string" || typeof record.scope !== "string")
94
+ return false;
95
+ if (!Array.isArray(record.steps) || record.steps.length === 0)
96
+ return false;
97
+ if (!record.steps.every((step) => step !== null &&
98
+ typeof step === "object" &&
99
+ typeof step.path === "string" &&
100
+ step.path !== "" &&
101
+ (step.action === "remove"
102
+ ? step.text === undefined
103
+ : step.action === "write" && typeof step.text === "string")))
104
+ return false;
105
+ if (record.row === null || typeof record.row !== "object" || Array.isArray(record.row))
106
+ return false;
107
+ return typeof record.row.id === "string" && record.row.id !== "";
108
+ };