@copilotz/team 0.0.0-stage → 1.0.0-rc.34
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/LICENSE +21 -0
- package/README.md +49 -2
- package/WORDS.md +200 -0
- package/contract.d.ts +8 -0
- package/contract.js +8 -0
- package/mod.d.ts +25 -0
- package/mod.js +25 -0
- package/package.json +63 -4
- package/team/actions/agent.d.ts +4 -0
- package/team/actions/agent.js +179 -0
- package/team/actions/define.d.ts +1 -0
- package/team/actions/define.js +27 -0
- package/team/collections/agent.d.ts +132 -0
- package/team/collections/agent.js +75 -0
- package/team/contract.d.ts +10 -0
- package/team/contract.js +1 -0
- package/team/mod.d.ts +21 -0
- package/team/mod.js +49 -0
- package/team/shared/definition.d.ts +3 -0
- package/team/shared/definition.js +10 -0
- package/team/views/web/agent-add.d.ts +14 -0
- package/team/views/web/agent-add.js +48 -0
- package/team/views/web/agent-fields.d.ts +33 -0
- package/team/views/web/agent-fields.js +88 -0
- package/team/views/web/agent-known.d.ts +22 -0
- package/team/views/web/agent-known.js +61 -0
- package/team/views/web/agent-new.d.ts +24 -0
- package/team/views/web/agent-new.js +129 -0
- package/team/views/web/agent-palette.d.ts +19 -0
- package/team/views/web/agent-palette.js +203 -0
- package/team/views/web/agent-steps.d.ts +23 -0
- package/team/views/web/agent-steps.js +56 -0
- package/team/views/web/agent.d.ts +17 -0
- package/team/views/web/agent.js +257 -0
- package/team/views/web/agents.d.ts +48 -0
- package/team/views/web/agents.js +59 -0
- package/team/views/web/model-pick.d.ts +25 -0
- package/team/views/web/model-pick.js +39 -0
- package/team/views/web/model-picker.d.ts +57 -0
- package/team/views/web/model-picker.js +218 -0
- package/team/views/web/places.d.ts +24 -0
- package/team/views/web/places.js +10 -0
- package/team/views/web/style.d.ts +9 -0
- package/team/views/web/style.js +246 -0
- package/team/views/web/words.d.ts +5 -0
- package/team/views/web/words.js +211 -0
- package/team/web.d.ts +22 -0
- package/team/web.js +41 -0
- package/tiers/actions/choose.d.ts +2 -0
- package/tiers/actions/choose.js +98 -0
- package/tiers/actions/model.d.ts +1 -0
- package/tiers/actions/model.js +36 -0
- package/tiers/collections/choice.d.ts +48 -0
- package/tiers/collections/choice.js +59 -0
- package/tiers/contract.d.ts +19 -0
- package/tiers/contract.js +1 -0
- package/tiers/mod.d.ts +54 -0
- package/tiers/mod.js +92 -0
- package/tiers/shared/shown.d.ts +87 -0
- package/tiers/shared/shown.js +155 -0
- package/tiers/shared/tiers.d.ts +103 -0
- package/tiers/shared/tiers.js +129 -0
- package/tiers/views/web/org.d.ts +38 -0
- package/tiers/views/web/org.js +142 -0
- package/tiers/views/web/space.d.ts +43 -0
- package/tiers/views/web/space.js +103 -0
- package/tiers/views/web/style.d.ts +7 -0
- package/tiers/views/web/style.js +87 -0
- package/tiers/views/web/words.d.ts +21 -0
- package/tiers/views/web/words.js +49 -0
- package/tiers/web.d.ts +18 -0
- package/tiers/web.js +40 -0
- package/web.d.ts +14 -0
- package/web.js +14 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents people make, beside those the app declares (chat's `agents`
|
|
3
|
+
* resource): a name to call it by (`_id`, as `@maya`), what it's shown as,
|
|
4
|
+
* what it does, its instructions, model and tools. It belongs where it was
|
|
5
|
+
* made (`in`, a space with the access plugin): who manage that space change
|
|
6
|
+
* it; others meet it where it works. Its queries:
|
|
7
|
+
*
|
|
8
|
+
* - `known`: every agent the asker has met, to add one where they work:
|
|
9
|
+
* the app's, and those people made that belong to or work in a space
|
|
10
|
+
* they reach (the rules say);
|
|
11
|
+
* - `options`: what an agent can be made with: the app's tools and models.
|
|
12
|
+
*/
|
|
13
|
+
import { type Infer } from "copilotz";
|
|
14
|
+
declare const agentSchema: {
|
|
15
|
+
readonly type: "object";
|
|
16
|
+
readonly properties: {
|
|
17
|
+
/** What it's shown as ("Maya"); its `_id` is what it's called by. */
|
|
18
|
+
readonly name: {
|
|
19
|
+
readonly type: "string";
|
|
20
|
+
};
|
|
21
|
+
/** What it does, for people and for other agents deciding whom to message. */
|
|
22
|
+
readonly description: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
};
|
|
25
|
+
readonly instructions: {
|
|
26
|
+
readonly type: "string";
|
|
27
|
+
};
|
|
28
|
+
/** `"provider/model"` or an alias (see the models plugin). */
|
|
29
|
+
readonly model: {
|
|
30
|
+
readonly type: "string";
|
|
31
|
+
};
|
|
32
|
+
readonly effort: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
};
|
|
35
|
+
/** Names of `tools` resources it may call, and `send_message` to talk to others. */
|
|
36
|
+
readonly tools: {
|
|
37
|
+
readonly type: "array";
|
|
38
|
+
readonly items: {
|
|
39
|
+
readonly type: "string";
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/** An emoji it's shown with. */
|
|
43
|
+
readonly icon: {
|
|
44
|
+
readonly type: "string";
|
|
45
|
+
};
|
|
46
|
+
/** Where it was made: who manage that space change it. */
|
|
47
|
+
readonly in: {
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
};
|
|
50
|
+
/** Who made it: `person:ana`. */
|
|
51
|
+
readonly by: {
|
|
52
|
+
readonly type: "string";
|
|
53
|
+
};
|
|
54
|
+
readonly at: {
|
|
55
|
+
readonly type: "string";
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
readonly required: readonly ["name", "instructions", "model", "at"];
|
|
59
|
+
};
|
|
60
|
+
export declare const agent: {
|
|
61
|
+
schema: {
|
|
62
|
+
readonly type: "object";
|
|
63
|
+
readonly properties: {
|
|
64
|
+
/** What it's shown as ("Maya"); its `_id` is what it's called by. */
|
|
65
|
+
readonly name: {
|
|
66
|
+
readonly type: "string";
|
|
67
|
+
};
|
|
68
|
+
/** What it does, for people and for other agents deciding whom to message. */
|
|
69
|
+
readonly description: {
|
|
70
|
+
readonly type: "string";
|
|
71
|
+
};
|
|
72
|
+
readonly instructions: {
|
|
73
|
+
readonly type: "string";
|
|
74
|
+
};
|
|
75
|
+
/** `"provider/model"` or an alias (see the models plugin). */
|
|
76
|
+
readonly model: {
|
|
77
|
+
readonly type: "string";
|
|
78
|
+
};
|
|
79
|
+
readonly effort: {
|
|
80
|
+
readonly type: "string";
|
|
81
|
+
};
|
|
82
|
+
/** Names of `tools` resources it may call, and `send_message` to talk to others. */
|
|
83
|
+
readonly tools: {
|
|
84
|
+
readonly type: "array";
|
|
85
|
+
readonly items: {
|
|
86
|
+
readonly type: "string";
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/** An emoji it's shown with. */
|
|
90
|
+
readonly icon: {
|
|
91
|
+
readonly type: "string";
|
|
92
|
+
};
|
|
93
|
+
/** Where it was made: who manage that space change it. */
|
|
94
|
+
readonly in: {
|
|
95
|
+
readonly type: "string";
|
|
96
|
+
};
|
|
97
|
+
/** Who made it: `person:ana`. */
|
|
98
|
+
readonly by: {
|
|
99
|
+
readonly type: "string";
|
|
100
|
+
};
|
|
101
|
+
readonly at: {
|
|
102
|
+
readonly type: "string";
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
readonly required: readonly ["name", "instructions", "model", "at"];
|
|
106
|
+
};
|
|
107
|
+
events?: boolean;
|
|
108
|
+
records?: boolean;
|
|
109
|
+
durable?: false;
|
|
110
|
+
indexes?: string[][];
|
|
111
|
+
private?: string[];
|
|
112
|
+
queries?: Record<string, import("copilotz").QueryDef<{
|
|
113
|
+
[x: string]: unknown;
|
|
114
|
+
description?: string | undefined;
|
|
115
|
+
effort?: string | undefined;
|
|
116
|
+
tools?: string[] | undefined;
|
|
117
|
+
icon?: string | undefined;
|
|
118
|
+
in?: string | undefined;
|
|
119
|
+
by?: string | undefined;
|
|
120
|
+
name: string;
|
|
121
|
+
instructions: string;
|
|
122
|
+
model: string;
|
|
123
|
+
at: string;
|
|
124
|
+
} & {
|
|
125
|
+
_id: string;
|
|
126
|
+
}>> | undefined;
|
|
127
|
+
vectors?: string[];
|
|
128
|
+
};
|
|
129
|
+
export type AgentDoc = Infer<typeof agentSchema> & {
|
|
130
|
+
_id: string;
|
|
131
|
+
};
|
|
132
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents people make, beside those the app declares (chat's `agents`
|
|
3
|
+
* resource): a name to call it by (`_id`, as `@maya`), what it's shown as,
|
|
4
|
+
* what it does, its instructions, model and tools. It belongs where it was
|
|
5
|
+
* made (`in`, a space with the access plugin): who manage that space change
|
|
6
|
+
* it; others meet it where it works. Its queries:
|
|
7
|
+
*
|
|
8
|
+
* - `known`: every agent the asker has met, to add one where they work:
|
|
9
|
+
* the app's, and those people made that belong to or work in a space
|
|
10
|
+
* they reach (the rules say);
|
|
11
|
+
* - `options`: what an agent can be made with: the app's tools and models.
|
|
12
|
+
*/
|
|
13
|
+
import { defineCollection, people } from "copilotz";
|
|
14
|
+
import { agentsOf, SEND } from "copilotz/plugins/agents/contract";
|
|
15
|
+
import { definitionOf } from "../shared/definition.js";
|
|
16
|
+
const agentSchema = {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
/** What it's shown as ("Maya"); its `_id` is what it's called by. */
|
|
20
|
+
name: { type: "string" },
|
|
21
|
+
/** What it does, for people and for other agents deciding whom to message. */
|
|
22
|
+
description: { type: "string" },
|
|
23
|
+
instructions: { type: "string" },
|
|
24
|
+
/** `"provider/model"` or an alias (see the models plugin). */
|
|
25
|
+
model: { type: "string" },
|
|
26
|
+
effort: { type: "string" },
|
|
27
|
+
/** Names of `tools` resources it may call, and `send_message` to talk to others. */
|
|
28
|
+
tools: { type: "array", items: { type: "string" } },
|
|
29
|
+
/** An emoji it's shown with. */
|
|
30
|
+
icon: { type: "string" },
|
|
31
|
+
/** Where it was made: who manage that space change it. */
|
|
32
|
+
in: { type: "string" },
|
|
33
|
+
/** Who made it: `person:ana`. */
|
|
34
|
+
by: { type: "string" },
|
|
35
|
+
at: { type: "string" },
|
|
36
|
+
},
|
|
37
|
+
required: ["name", "instructions", "model", "at"],
|
|
38
|
+
};
|
|
39
|
+
export const agent = defineCollection({
|
|
40
|
+
schema: agentSchema,
|
|
41
|
+
queries: {
|
|
42
|
+
known: {
|
|
43
|
+
allow: people,
|
|
44
|
+
run: async (agents, _, ctx) => {
|
|
45
|
+
const known = { ...agentsOf(ctx) };
|
|
46
|
+
for (const doc of await agents.find({}, { sort: { name: 1 } })) {
|
|
47
|
+
known[doc._id] = definitionOf(doc);
|
|
48
|
+
}
|
|
49
|
+
return known;
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
options: {
|
|
53
|
+
allow: people,
|
|
54
|
+
run: async (_, __, ctx) => {
|
|
55
|
+
const tools = (ctx.resources.tools ?? {});
|
|
56
|
+
const declared = Object.values((ctx.resources.agents ?? {}));
|
|
57
|
+
const named = [
|
|
58
|
+
...new Set([
|
|
59
|
+
...declared.map((a) => a.model).filter((m) => typeof m === "string"),
|
|
60
|
+
...Object.keys(ctx.resources.model ?? {}),
|
|
61
|
+
]),
|
|
62
|
+
];
|
|
63
|
+
// Only those an agent can talk with (not a transcriber, an embedder).
|
|
64
|
+
const models = (await Promise.all(named.map((model) => ctx.call("models.check", { model, port: "llm" }).then(() => model, () => undefined)))).filter((model) => model !== undefined);
|
|
65
|
+
return {
|
|
66
|
+
tools: [
|
|
67
|
+
...Object.entries(tools).map(([name, t]) => ({ name, description: t.description })),
|
|
68
|
+
{ name: SEND, description: "Message other agents and people, and wait for replies" },
|
|
69
|
+
],
|
|
70
|
+
models,
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The team plugin's contract: the shape of an agent people made, and of the
|
|
3
|
+
* hints its model picker takes on the web. The rest is reached by name: its
|
|
4
|
+
* collection `agent`, its queries (`agent.known`, `agent.options`), its
|
|
5
|
+
* Actions (`agent.create`, `agent.update`, `agent.delete`, `agent.draft`),
|
|
6
|
+
* and on the web its View `model.pick` (team-web's): the picker an agent's
|
|
7
|
+
* model is chosen with, for other front ends' pages.
|
|
8
|
+
*/
|
|
9
|
+
export type { AgentDoc } from "./collections/agent.js";
|
|
10
|
+
export type { ModelPick } from "./views/web/model-pick.js";
|
package/team/contract.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/team/mod.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Team: agents people make, beside those the app declares in code. A
|
|
3
|
+
* person makes one (`agent.create`: a name to call it by, what it does,
|
|
4
|
+
* instructions they can have written for them with `agent.draft`, a model,
|
|
5
|
+
* tools, an emoji), changes it (`agent.update`) or removes it
|
|
6
|
+
* (`agent.delete`). Chat meets them through its `agentSources` resource
|
|
7
|
+
* (`agent.define`): they work like any agent, where they work.
|
|
8
|
+
*
|
|
9
|
+
* With the access plugin, an agent belongs to the space it was made in
|
|
10
|
+
* (`in`): only that space's managers change it, and it's read wherever
|
|
11
|
+
* it's a member; adding it to a space is the spaces plugin's (`member.set`,
|
|
12
|
+
* by a manager who has met it). Without it, every agent is everyone's.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* plugins: [models, chat, ...access, team, app]
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import { type Plugin } from "copilotz";
|
|
19
|
+
export * from "./contract.js";
|
|
20
|
+
export declare const team: Plugin;
|
|
21
|
+
export default team;
|
package/team/mod.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Team: agents people make, beside those the app declares in code. A
|
|
3
|
+
* person makes one (`agent.create`: a name to call it by, what it does,
|
|
4
|
+
* instructions they can have written for them with `agent.draft`, a model,
|
|
5
|
+
* tools, an emoji), changes it (`agent.update`) or removes it
|
|
6
|
+
* (`agent.delete`). Chat meets them through its `agentSources` resource
|
|
7
|
+
* (`agent.define`): they work like any agent, where they work.
|
|
8
|
+
*
|
|
9
|
+
* With the access plugin, an agent belongs to the space it was made in
|
|
10
|
+
* (`in`): only that space's managers change it, and it's read wherever
|
|
11
|
+
* it's a member; adding it to a space is the spaces plugin's (`member.set`,
|
|
12
|
+
* by a manager who has met it). Without it, every agent is everyone's.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* plugins: [models, chat, ...access, team, app]
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import { definePlugin, failure } from "copilotz";
|
|
19
|
+
import { createAgentAction, deleteAgentAction, draftAgentAction, updateAgentAction, } from "./actions/agent.js";
|
|
20
|
+
import { defineAgentsAction } from "./actions/define.js";
|
|
21
|
+
import { agent } from "./collections/agent.js";
|
|
22
|
+
export * from "./contract.js";
|
|
23
|
+
export const team = definePlugin({
|
|
24
|
+
name: "team",
|
|
25
|
+
requires: ["chat"],
|
|
26
|
+
collections: { agent },
|
|
27
|
+
actions: {
|
|
28
|
+
"agent.create": createAgentAction,
|
|
29
|
+
"agent.update": updateAgentAction,
|
|
30
|
+
"agent.delete": deleteAgentAction,
|
|
31
|
+
"agent.draft": draftAgentAction,
|
|
32
|
+
"agent.define": defineAgentsAction,
|
|
33
|
+
},
|
|
34
|
+
resources: {
|
|
35
|
+
// Chat asks it what an agent not in the app's code is.
|
|
36
|
+
agentSources: { team: { action: "agent.define" } },
|
|
37
|
+
// With the access plugin: an agent belongs where it was made, its managers change it,
|
|
38
|
+
// and it's read where it works.
|
|
39
|
+
shared: { agent: { member: "agent", write: "manage" } },
|
|
40
|
+
},
|
|
41
|
+
// An agent is a member of spaces, with its tools and model: its Actions check what it's given.
|
|
42
|
+
guard: (_actor, { collection, access, direct }) => {
|
|
43
|
+
if (collection === "agent" && direct && access === "write") {
|
|
44
|
+
throw failure("forbidden", "Agents change through their Actions.", { public: true });
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
export default team;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const definitionOf = (doc) => ({
|
|
2
|
+
instructions: doc.instructions,
|
|
3
|
+
model: doc.model,
|
|
4
|
+
...(doc.effort ? { effort: doc.effort } : {}),
|
|
5
|
+
...(doc.tools ? { tools: doc.tools } : {}),
|
|
6
|
+
...(doc.description ? { description: doc.description } : {}),
|
|
7
|
+
...(doc.name !== doc._id ? { name: doc.name } : {}),
|
|
8
|
+
...(doc.icon ? { icon: doc.icon } : {}),
|
|
9
|
+
...(doc.in ? { in: doc.in } : {}),
|
|
10
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adding an agent to a space (kind `agent.add`, item `{ _id }`, the space;
|
|
3
|
+
* hints `{ in, mode?, from? }`): the Agents tab of spaces' invite surface
|
|
4
|
+
* (the `spaceInvite` resource), and the command palette's "Add an agent"
|
|
5
|
+
* and "New agent". One the person has met that doesn't work there yet
|
|
6
|
+
* (`KnownAgents`), or a new one made there (`NewAgent`: at once when `mode`
|
|
7
|
+
* is "new", or when there's none to add; `from`, one of the app's agents to
|
|
8
|
+
* start from). For those who manage the space, while it's in use.
|
|
9
|
+
*/
|
|
10
|
+
import { type ReactNode } from "react";
|
|
11
|
+
import type { ViewContext } from "copilotz";
|
|
12
|
+
export declare const agentAddView: (item: {
|
|
13
|
+
_id?: string;
|
|
14
|
+
}, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Adding an agent to a space (kind `agent.add`, item `{ _id }`, the space;
|
|
4
|
+
* hints `{ in, mode?, from? }`): the Agents tab of spaces' invite surface
|
|
5
|
+
* (the `spaceInvite` resource), and the command palette's "Add an agent"
|
|
6
|
+
* and "New agent". One the person has met that doesn't work there yet
|
|
7
|
+
* (`KnownAgents`), or a new one made there (`NewAgent`: at once when `mode`
|
|
8
|
+
* is "new", or when there's none to add; `from`, one of the app's agents to
|
|
9
|
+
* start from). For those who manage the space, while it's in use.
|
|
10
|
+
*/
|
|
11
|
+
import { useState } from "react";
|
|
12
|
+
import { Notice, Skeleton } from "copilotz/web";
|
|
13
|
+
import { KnownAgents } from "./agent-known.js";
|
|
14
|
+
import { NewAgent } from "./agent-new.js";
|
|
15
|
+
import { manages, placeName } from "./places.js";
|
|
16
|
+
import { STYLE } from "./style.js";
|
|
17
|
+
import { say } from "./words.js";
|
|
18
|
+
export const agentAddView = (item, ctx) => {
|
|
19
|
+
const id = item._id ?? (typeof ctx.hints.in === "string" ? ctx.hints.in : "");
|
|
20
|
+
const places = ctx.db.collection("space").query("reached", {}).value;
|
|
21
|
+
const known = ctx.db.collection("agent").query("known", {}).value;
|
|
22
|
+
const here = ctx.db.collection("thread").query("agents", { in: id }).value;
|
|
23
|
+
const options = ctx.db.collection("agent").query("options", {}).value;
|
|
24
|
+
const style = _jsx("style", { href: "team-web", precedence: "copilotz", children: STYLE });
|
|
25
|
+
if (!places || !known || !here || !options) {
|
|
26
|
+
return (_jsxs("div", { className: "agent-add", "aria-busy": "true", children: [style, _jsx(Skeleton, { height: 56, radius: "lg" }), _jsx(Skeleton, { height: 56, radius: "lg" })] }));
|
|
27
|
+
}
|
|
28
|
+
const space = places.find((p) => p._id === id);
|
|
29
|
+
if (!space || !manages(space) || space.archived) {
|
|
30
|
+
return (_jsx(Notice, { tone: "neutral", icon: "lock", children: !space
|
|
31
|
+
? say("notYourSpace")
|
|
32
|
+
: space.archived
|
|
33
|
+
? say("archivedSpace", { place: placeName(space) })
|
|
34
|
+
: say("managersAdd", { place: placeName(space) }) }));
|
|
35
|
+
}
|
|
36
|
+
// Those they've met that don't work here yet: the app's first, then by name.
|
|
37
|
+
const others = Object.entries(known).filter(([key]) => !here.here.includes(key))
|
|
38
|
+
.sort(([a, x], [b, y]) => Number(!!x.in) - Number(!!y.in) ||
|
|
39
|
+
(x.name || a).localeCompare(y.name || b, undefined, { sensitivity: "base" }));
|
|
40
|
+
const from = typeof ctx.hints.from === "string" ? ctx.hints.from : undefined;
|
|
41
|
+
return (_jsxs(_Fragment, { children: [style, _jsx(AddAgent, { space: space, places: places, known: known, others: others, options: options, first: ctx.hints.mode === "new" || from || !others.length ? "new" : "known", from: from, call: ctx.call })] }));
|
|
42
|
+
};
|
|
43
|
+
function AddAgent({ space, places, known, others, options, first, from, call }) {
|
|
44
|
+
const [mode, setMode] = useState(first);
|
|
45
|
+
return (_jsx("div", { className: "agent-add", children: mode === "known"
|
|
46
|
+
? (_jsx(KnownAgents, { space: space, agents: others, places: places, call: call, onNew: () => setMode("new") }))
|
|
47
|
+
: (_jsx(NewAgent, { space: space, known: known, options: options, call: call, from: from, onBack: others.length ? () => setMode("known") : undefined })) }));
|
|
48
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an agent is, as a form: its emoji and name (and what it's called by,
|
|
3
|
+
* `@maya`), what it does, its instructions (written for the person from the
|
|
4
|
+
* two with `agent.draft` if they like: a moment on a real model, said so
|
|
5
|
+
* while it writes, and undone with a press), the model it thinks with, and
|
|
6
|
+
* the tools it may use (those it has, in a line; all of them to tick, on a
|
|
7
|
+
* press). Making an agent (`NewAgent`) and changing one (its page) show it;
|
|
8
|
+
* what's typed goes up as it changes (`onChange`, a patch).
|
|
9
|
+
*/
|
|
10
|
+
import { type ReactNode } from "react";
|
|
11
|
+
import { type Options } from "./agents.js";
|
|
12
|
+
type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
|
|
13
|
+
/** An agent being made or changed: its fields, as typed. */
|
|
14
|
+
export type Draft = {
|
|
15
|
+
name: string;
|
|
16
|
+
icon: string;
|
|
17
|
+
description: string;
|
|
18
|
+
instructions: string;
|
|
19
|
+
model: string;
|
|
20
|
+
tools: string[];
|
|
21
|
+
};
|
|
22
|
+
export declare function AgentFields({ value, onChange, options, handle, call, autoFocus, disabled }: {
|
|
23
|
+
value: Draft;
|
|
24
|
+
/** What changed: the form merges it into what's there. */
|
|
25
|
+
onChange(patch: Partial<Draft>): void;
|
|
26
|
+
options: Options;
|
|
27
|
+
/** What it's called by: its id, or what a new one will be (none until it's named). */
|
|
28
|
+
handle: string;
|
|
29
|
+
call: Call;
|
|
30
|
+
autoFocus?: boolean;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
}): ReactNode;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* What an agent is, as a form: its emoji and name (and what it's called by,
|
|
4
|
+
* `@maya`), what it does, its instructions (written for the person from the
|
|
5
|
+
* two with `agent.draft` if they like: a moment on a real model, said so
|
|
6
|
+
* while it writes, and undone with a press), the model it thinks with, and
|
|
7
|
+
* the tools it may use (those it has, in a line; all of them to tick, on a
|
|
8
|
+
* press). Making an agent (`NewAgent`) and changing one (its page) show it;
|
|
9
|
+
* what's typed goes up as it changes (`onChange`, a patch).
|
|
10
|
+
*/
|
|
11
|
+
import { useId, useState } from "react";
|
|
12
|
+
import { Avatar, Button, Checkbox, Field, Icon, Input, message, Skeleton, Spinner, Textarea, } from "copilotz/web";
|
|
13
|
+
import { ICONS } from "./agents.js";
|
|
14
|
+
import { ModelPicker } from "./model-picker.js";
|
|
15
|
+
import { say } from "./words.js";
|
|
16
|
+
/** How many tools the line shows before it counts the rest. */
|
|
17
|
+
const LINE = 6;
|
|
18
|
+
export function AgentFields({ value, onChange, options, handle, call, autoFocus, disabled }) {
|
|
19
|
+
const id = useId();
|
|
20
|
+
const own = !!value.icon && !ICONS.includes(value.icon);
|
|
21
|
+
return (_jsxs("div", { className: "agent-form", children: [_jsxs("div", { className: "agent-form-who", children: [value.name.trim() || value.icon
|
|
22
|
+
? _jsx(Avatar, { name: value.name.trim() || "?", kind: "agent", icon: value.icon, size: 56 })
|
|
23
|
+
: (_jsx("span", { className: "agent-face-empty", "aria-hidden": "true", children: _jsx(Icon, { name: "bot", size: 24 }) })), _jsx(Field, { label: say("fieldName"), className: "agent-form-name", hint: handle
|
|
24
|
+
? say.nodes("calledIn", { handle: _jsxs("b", { className: "agent-handle", children: ["@", handle] }) })
|
|
25
|
+
: say("nameHint"), children: (control) => (_jsx(Input, { ...control, value: value.name, maxLength: 60, placeholder: say("namePlaceholder"), autoComplete: "off", autoFocus: autoFocus, disabled: disabled, onChange: (event) => onChange({ name: event.target.value }) })) })] }), _jsxs("div", { className: "agent-form-field", role: "radiogroup", "aria-labelledby": `${id}-icon`, children: [_jsx("span", { id: `${id}-icon`, className: "agent-form-label", children: say("emoji") }), _jsxs("div", { className: "agent-icons", children: [_jsx("button", { type: "button", role: "radio", "aria-checked": !value.icon, "aria-label": say("noEmoji"), title: say("noEmoji"), className: "agent-icon agent-icon-none", disabled: disabled, onClick: () => onChange({ icon: "" }), children: (value.name.trim()[0] ?? "A").toUpperCase() }), ICONS.map((icon) => (_jsx("button", { type: "button", role: "radio", "aria-checked": value.icon === icon, className: "agent-icon", disabled: disabled, onClick: () => onChange({ icon }), children: icon }, icon))), _jsx(Input, { size: "sm", className: "agent-icon-own", "aria-label": say("anotherEmoji"), placeholder: say("otherEmoji"), value: own ? value.icon : "", maxLength: 16, autoComplete: "off", disabled: disabled, "data-chosen": own || undefined, onChange: (event) => onChange({ icon: event.target.value.trim() }) })] })] }), _jsx(Field, { label: say("fieldDoes"), hint: say("doesHint"), children: (control) => (_jsx(Textarea, { ...control, rows: 2, autoGrow: true, maxHeight: 160, maxLength: 500, value: value.description, placeholder: say("doesPlaceholder"), disabled: disabled, onChange: (event) => onChange({ description: event.target.value }) })) }), _jsx(Instructions, { value: value, onChange: onChange, call: call, disabled: disabled }), _jsx(Field, { label: say("model"), hint: say("modelHint"), children: (control) => (_jsx(ModelPicker, { id: control.id, value: value.model, call: call, disabled: disabled, onChange: (model) => onChange({ model }) })) }), _jsx(Tools, { value: value.tools, onChange: (tools) => onChange({ tools }), options: options })] }));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Its instructions: typed, or written for the person from its name and
|
|
29
|
+
* what it should do (`agent.draft`), which takes a moment on a real model:
|
|
30
|
+
* the box says so while it writes, and what it replaced comes back with Undo.
|
|
31
|
+
*/
|
|
32
|
+
function Instructions({ value, onChange, call, disabled }) {
|
|
33
|
+
const id = useId();
|
|
34
|
+
const [drafting, setDrafting] = useState(false);
|
|
35
|
+
const [error, setError] = useState();
|
|
36
|
+
const [before, setBefore] = useState();
|
|
37
|
+
const name = value.name.trim();
|
|
38
|
+
const ready = !!name && !!value.description.trim();
|
|
39
|
+
const draft = async () => {
|
|
40
|
+
setDrafting(true);
|
|
41
|
+
setError(undefined);
|
|
42
|
+
try {
|
|
43
|
+
const { instructions } = await call("agent.draft", {
|
|
44
|
+
name,
|
|
45
|
+
description: value.description.trim(),
|
|
46
|
+
...(value.model ? { model: value.model } : {}),
|
|
47
|
+
});
|
|
48
|
+
setBefore(value.instructions);
|
|
49
|
+
onChange({ instructions });
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
setError(message(e));
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
setDrafting(false);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return (_jsxs("div", { className: "agent-form-field", children: [_jsxs("div", { className: "agent-form-label-row", children: [_jsx("label", { className: "agent-form-label", htmlFor: id, children: say("instructions") }), _jsx(Button, { size: "sm", variant: "ghost", icon: "sparkles", className: "agent-draft", loading: drafting, disabled: !ready || disabled, title: ready ? undefined : say("sayNameFirst"), onClick: () => void draft(), children: value.instructions.trim() ? say("rewriteForMe") : say("writeForMe") })] }), _jsxs("div", { className: "agent-instructions", "data-busy": drafting || undefined, children: [_jsx(Textarea, { id: id, rows: 6, autoGrow: true, maxHeight: 420, maxLength: 20_000, value: value.instructions, readOnly: drafting, disabled: disabled, "aria-describedby": `${id}-note`, "aria-busy": drafting || undefined, placeholder: say("youArePlaceholder", { name: name || say("youAreDefaultName") }), onChange: (event) => {
|
|
59
|
+
setBefore(undefined);
|
|
60
|
+
onChange({ instructions: event.target.value });
|
|
61
|
+
} }), drafting
|
|
62
|
+
? (_jsxs("div", { className: "agent-drafting", role: "status", children: [_jsxs("span", { className: "agent-drafting-say", children: [_jsx(Spinner, { size: 13 }), say("writingFor", { name })] }), [92, 84, 96, 70, 88, 52].map((width, i) => (_jsx(Skeleton, { height: 11, width: `${width}%` }, i)))] }))
|
|
63
|
+
: null] }), _jsx("p", { id: `${id}-note`, className: "agent-form-note", children: error ? _jsx("span", { className: "agent-error", role: "alert", children: error }) : before !== undefined
|
|
64
|
+
? (_jsxs(_Fragment, { children: [say("draftNote"), " ", _jsx(Button, { variant: "link", size: "sm", className: "agent-undo", onClick: () => {
|
|
65
|
+
onChange({ instructions: before });
|
|
66
|
+
setBefore(undefined);
|
|
67
|
+
}, children: say("undo") })] }))
|
|
68
|
+
: ready || value.instructions.trim()
|
|
69
|
+
? say("instructionsHint")
|
|
70
|
+
: say("instructionsEmptyHint") })] }));
|
|
71
|
+
}
|
|
72
|
+
/** The tools it may use: those it has, in a line; all of them to tick, once opened. */
|
|
73
|
+
function Tools({ value, onChange, options }) {
|
|
74
|
+
const id = useId();
|
|
75
|
+
const [open, setOpen] = useState(false);
|
|
76
|
+
const offered = options.tools.map((t) => t.name);
|
|
77
|
+
const chosen = offered.filter((name) => value.includes(name));
|
|
78
|
+
const toggle = (name, on) => onChange(on ? [...new Set([...value, name])] : value.filter((t) => t !== name));
|
|
79
|
+
return (_jsxs("div", { className: "agent-form-field", role: "group", "aria-labelledby": `${id}-tools`, children: [_jsxs("div", { className: "agent-form-label-row", children: [_jsx("span", { id: `${id}-tools`, className: "agent-form-label", children: say.nodes("toolsLabel", {
|
|
80
|
+
count: (_jsx("span", { className: "agent-form-count", children: say("toolsOf", { chosen: chosen.length, offered: offered.length }) })),
|
|
81
|
+
}) }), _jsx(Button, { size: "sm", variant: "ghost", iconEnd: open ? undefined : "chevron-down", "aria-expanded": open, "aria-controls": `${id}-list`, onClick: () => setOpen(!open), children: open ? say("toolsChooseDone") : say("toolsChoose") })] }), open
|
|
82
|
+
? (_jsxs("div", { id: `${id}-list`, className: "agent-tools", children: [_jsxs("div", { className: "agent-tools-all", children: [_jsx(Button, { size: "sm", variant: "link", onClick: () => onChange(offered), children: say("toolsAll") }), _jsx(Button, { size: "sm", variant: "link", onClick: () => onChange([]), children: say("toolsNone") })] }), _jsx("ul", { children: options.tools.map((t) => (_jsx("li", { children: _jsx(Checkbox, { checked: value.includes(t.name), onChange: (event) => toggle(t.name, event.target.checked), label: _jsxs("span", { className: "agent-tool", children: [_jsx("code", { children: t.name }), _jsx("span", { children: t.description })] }) }) }, t.name))) })] }))
|
|
83
|
+
: (_jsx("p", { id: `${id}-list`, className: "agent-tools-line", children: chosen.length
|
|
84
|
+
? (_jsxs(_Fragment, { children: [chosen.slice(0, LINE).map((name) => _jsx("code", { children: name }, name)), chosen.length > LINE
|
|
85
|
+
? _jsx("span", { children: say("toolsMore", { count: chosen.length - LINE }) })
|
|
86
|
+
: null] }))
|
|
87
|
+
: _jsx("span", { children: say("noTools") }) }))] }));
|
|
88
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents someone has met, to add to a space: those that don't work there
|
|
3
|
+
* yet (the app's, and those people made where the person reaches), each by
|
|
4
|
+
* its emoji and names, what it does or where it belongs; found as they're
|
|
5
|
+
* typed; each added at once, in the role chosen for them (`member.set`),
|
|
6
|
+
* which says so. First in the list, making a new one instead.
|
|
7
|
+
*/
|
|
8
|
+
import { type ReactNode } from "react";
|
|
9
|
+
import type { Agent } from "copilotz/plugins/agents/contract";
|
|
10
|
+
import { type Place } from "./places.js";
|
|
11
|
+
type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
|
|
12
|
+
/** Where an agent comes from, in a few words. */
|
|
13
|
+
export declare const belongs: (agent: Agent, places: Place[]) => string;
|
|
14
|
+
export declare function KnownAgents({ space, agents, places, call, onNew }: {
|
|
15
|
+
space: Place;
|
|
16
|
+
/** The agents they've met that don't work here, by id. */
|
|
17
|
+
agents: [string, Agent][];
|
|
18
|
+
places: Place[];
|
|
19
|
+
call: Call;
|
|
20
|
+
onNew(): void;
|
|
21
|
+
}): ReactNode;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Agents someone has met, to add to a space: those that don't work there
|
|
4
|
+
* yet (the app's, and those people made where the person reaches), each by
|
|
5
|
+
* its emoji and names, what it does or where it belongs; found as they're
|
|
6
|
+
* typed; each added at once, in the role chosen for them (`member.set`),
|
|
7
|
+
* which says so. First in the list, making a new one instead.
|
|
8
|
+
*/
|
|
9
|
+
import { useId, useState } from "react";
|
|
10
|
+
import { Avatar, Button, Icon, Input, message, Select } from "copilotz/web";
|
|
11
|
+
import { AGENT_ROLES } from "copilotz/plugins/access/contract";
|
|
12
|
+
import { found, listed, shownAs } from "./agents.js";
|
|
13
|
+
import { placeName } from "./places.js";
|
|
14
|
+
import { say } from "./words.js";
|
|
15
|
+
/** Past this many, there's a field to find one. */
|
|
16
|
+
const FIND = 5;
|
|
17
|
+
/** Where an agent comes from, in a few words. */
|
|
18
|
+
export const belongs = (agent, places) => {
|
|
19
|
+
if (!agent.in)
|
|
20
|
+
return say("oneOfApps");
|
|
21
|
+
const home = places.find((p) => p._id === agent.in);
|
|
22
|
+
return home ? say("madeIn", { place: placeName(home) }) : say("madeInOther");
|
|
23
|
+
};
|
|
24
|
+
export function KnownAgents({ space, agents, places, call, onNew }) {
|
|
25
|
+
const id = useId();
|
|
26
|
+
const [search, setSearch] = useState("");
|
|
27
|
+
const [role, setRole] = useState("editor");
|
|
28
|
+
const [busy, setBusy] = useState();
|
|
29
|
+
const [error, setError] = useState();
|
|
30
|
+
const [added, setAdded] = useState([]);
|
|
31
|
+
const all = agents.map(([key, agent]) => ({ id: key, ...shownAs(key, agent), agent }));
|
|
32
|
+
const shown = found(all, search);
|
|
33
|
+
const where = placeName(space);
|
|
34
|
+
const add = async (agent, name) => {
|
|
35
|
+
setBusy(agent);
|
|
36
|
+
setError(undefined);
|
|
37
|
+
try {
|
|
38
|
+
await call("member.set", { space: space._id, member: { kind: "agent", id: agent }, role });
|
|
39
|
+
setAdded((now) => [...now, name]);
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
setError(message(e));
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
setBusy(undefined);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return (_jsxs("div", { className: "agent-known", children: [_jsxs("div", { className: "agent-known-tools", children: [agents.length > FIND
|
|
49
|
+
? (_jsxs(_Fragment, { children: [_jsx("label", { className: "copilotz-sr", htmlFor: `${id}-find`, children: say("findAgent") }), _jsx(Input, { id: `${id}-find`, type: "search", icon: "search", size: "sm", className: "agent-known-find", placeholder: say("findAgentKnown"), autoComplete: "off", autoFocus: true, value: search, onChange: (event) => setSearch(event.target.value) })] }))
|
|
50
|
+
: _jsx("p", { className: "agent-known-intro", children: say("knownIntro") }), _jsxs("label", { className: "agent-known-role", children: [_jsx("span", { children: say("addsAs") }), _jsx(Select, { size: "sm", value: role, onChange: (event) => setRole(event.target.value), children: AGENT_ROLES.map((r) => _jsx("option", { value: r.value, children: r.label }, r.value)) })] })] }), _jsxs("ul", { className: "agent-known-list", children: [_jsx("li", { children: _jsxs("button", { type: "button", className: "agent-known-row agent-known-new", onClick: onNew, children: [_jsx("span", { className: "agent-known-plus", children: _jsx(Icon, { name: "plus", size: 18 }) }), _jsxs("span", { className: "agent-known-text", children: [_jsx("span", { className: "agent-known-name", children: say("createNewAgent") }), _jsx("span", { className: "agent-known-what", children: say("createNewAgentBody") })] }), _jsx(Icon, { name: "chevron", size: 16 })] }) }), shown.map((a) => (_jsxs("li", { className: "agent-known-row", children: [_jsx(Avatar, { name: a.name, kind: "agent", icon: a.icon, size: 34 }), _jsxs("span", { className: "agent-known-text", children: [_jsxs("span", { className: "agent-known-name", children: [a.name, " ", _jsxs("span", { className: "agent-handle", children: ["@", a.id] }), _jsx("span", { className: "agent-known-from", children: belongs(a.agent, places) })] }), a.agent.description
|
|
51
|
+
? _jsx("span", { className: "agent-known-what", children: a.agent.description })
|
|
52
|
+
: null] }), _jsx(Button, { size: "sm", icon: "plus", loading: busy === a.id, disabled: !!busy && busy !== a.id, "aria-label": say("addAgentTo", { name: a.name, place: where }), onClick: () => void add(a.id, a.name), children: say("add") })] }, a.id)))] }), !shown.length
|
|
53
|
+
? (_jsx("p", { className: "agent-known-none", children: agents.length
|
|
54
|
+
? say("noneCalled", { search: search.trim() })
|
|
55
|
+
: say("allWorkHere", { place: where }) }))
|
|
56
|
+
: null, _jsx("p", { className: "agent-form-note", "aria-live": "polite", children: error
|
|
57
|
+
? _jsx("span", { className: "agent-error", role: "alert", children: error })
|
|
58
|
+
: added.length
|
|
59
|
+
? (_jsxs("span", { className: "agent-done", children: [_jsx(Icon, { name: "check", size: 14 }), say("worksNowNames", { names: listed(added), place: where, count: added.length })] }))
|
|
60
|
+
: AGENT_ROLES.find((r) => r.value === role)?.lets })] }));
|
|
61
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Making an agent in a space, for those who manage it: one calm form (its
|
|
3
|
+
* fields: `AgentFields`), what it may start from (one of the app's agents,
|
|
4
|
+
* `from`: its words, model and tools filled in), and the role it works in
|
|
5
|
+
* there. Made (`agent.create` there, then `member.set`), it says so, with
|
|
6
|
+
* what's next: have it answer new chats, open its page, or make another.
|
|
7
|
+
*/
|
|
8
|
+
import { type ReactNode } from "react";
|
|
9
|
+
import type { Agent } from "copilotz/plugins/agents/contract";
|
|
10
|
+
import { type Options } from "./agents.js";
|
|
11
|
+
import { type Place } from "./places.js";
|
|
12
|
+
type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
|
|
13
|
+
export declare function NewAgent({ space, known, options, call, from: first, onBack }: {
|
|
14
|
+
space: Place;
|
|
15
|
+
/** Every agent the person has met: the app's, to start from; and names taken. */
|
|
16
|
+
known: Record<string, Agent>;
|
|
17
|
+
options: Options;
|
|
18
|
+
call: Call;
|
|
19
|
+
/** One of the app's agents to start from. */
|
|
20
|
+
from?: string;
|
|
21
|
+
/** Back to the agents they know, when there are some to add. */
|
|
22
|
+
onBack?(): void;
|
|
23
|
+
}): ReactNode;
|
|
24
|
+
export {};
|