insightfulpipe 0.3.0 → 0.4.1
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/CHANGELOG.md +71 -0
- package/README.md +31 -1
- package/package.json +1 -1
- package/src/api.js +36 -11
- package/src/cli/commands/auth.js +7 -2
- package/src/cli/commands/discovery.js +27 -17
- package/src/cli/commands/execution.js +7 -7
- package/src/cli/commands/skills.js +289 -175
- package/src/cli/errors.js +4 -1
- package/src/cli/program.js +2 -1
- package/src/config.js +16 -3
- package/src/http.js +1 -1
- package/src/output.js +161 -14
- package/src/skills/agents.js +5 -4
- package/src/skills/installer.js +57 -16
- package/src/skills/private.js +100 -0
- package/src/skills/records.js +72 -0
- package/src/skills/sources.js +108 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { fetchCatalog, fetchSkillFiles, getCatalogUrl, pageUrl, resolveSkill, skillKey } from './catalog.js';
|
|
2
|
+
import { validateBundle } from './installer.js';
|
|
3
|
+
import {
|
|
4
|
+
fetchPrivateCatalog,
|
|
5
|
+
fetchPrivateSkillFiles,
|
|
6
|
+
privateSourceUrl,
|
|
7
|
+
privateWorkspaceId,
|
|
8
|
+
resolvePrivateSkill,
|
|
9
|
+
validatePrivateBundle,
|
|
10
|
+
} from './private.js';
|
|
11
|
+
|
|
12
|
+
/** Where skills come from: the public library on the website, with no key, or a workspace's private
|
|
13
|
+
* skills from the app API, with the user's key. A command uses exactly one source and never falls back
|
|
14
|
+
* to the other; an installed skill goes back to the source its marker names. */
|
|
15
|
+
|
|
16
|
+
/** Markers written before 0.4.0 have no origin, and every one of those is public. */
|
|
17
|
+
export function markerOrigin(marker) {
|
|
18
|
+
return marker?.origin === 'private' ? 'private' : 'public';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A private marker's own category is never shown: it may have come with a cloned repository. */
|
|
22
|
+
export function markerLabel(marker) {
|
|
23
|
+
return markerOrigin(marker) === 'private' ? `private/${marker.slug}` : `${marker.category}/${marker.slug}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function publicSource(catalog) {
|
|
27
|
+
const installName = (skill) =>
|
|
28
|
+
catalog.skills.filter((other) => other.slug === skill.slug).length > 1 ? skillKey(skill) : skill.slug;
|
|
29
|
+
return {
|
|
30
|
+
origin: 'public',
|
|
31
|
+
skills: catalog.skills,
|
|
32
|
+
resolve: (name) => resolveSkill(name, catalog.skills),
|
|
33
|
+
find: (marker) => catalog.skills.find((skill) => skill.category === marker.category && skill.slug === marker.slug),
|
|
34
|
+
files: (skill) => fetchSkillFiles(skill.category, skill.slug),
|
|
35
|
+
validate: validateBundle,
|
|
36
|
+
installOptions: () => ({ origin: 'public', source: getCatalogUrl() }),
|
|
37
|
+
summarize: (skill) => ({
|
|
38
|
+
skill: skill.slug,
|
|
39
|
+
category: skill.category,
|
|
40
|
+
name: skill.displayName,
|
|
41
|
+
description: skill.description,
|
|
42
|
+
version: skill.version ?? null,
|
|
43
|
+
install: `insightfulpipe skills install ${installName(skill)}`,
|
|
44
|
+
page: pageUrl(skill),
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function privateSourceFor(workspaceId, skills) {
|
|
50
|
+
const installName = (skill) => (skills.filter((other) => other.slug === skill.slug).length > 1 ? skill.key : skill.slug);
|
|
51
|
+
return {
|
|
52
|
+
origin: 'private',
|
|
53
|
+
workspaceId,
|
|
54
|
+
skills,
|
|
55
|
+
resolve: (name) => resolvePrivateSkill(name, skills),
|
|
56
|
+
find: (marker) => skills.find((skill) => skill.key === marker.key),
|
|
57
|
+
files: (skill) => fetchPrivateSkillFiles(workspaceId, skill.key),
|
|
58
|
+
validate: validatePrivateBundle,
|
|
59
|
+
installOptions: (skill) => ({ origin: 'private', source: privateSourceUrl(), key: skill.key, workspaceId }),
|
|
60
|
+
summarize: (skill) => ({
|
|
61
|
+
skill: skill.slug,
|
|
62
|
+
key: skill.key,
|
|
63
|
+
category: skill.category,
|
|
64
|
+
name: skill.name,
|
|
65
|
+
description: skill.description ?? '',
|
|
66
|
+
data_source: skill.data_source || null,
|
|
67
|
+
version: skill.version ?? null,
|
|
68
|
+
install: `insightfulpipe skills install ${installName(skill)} --private --workspace ${workspaceId}`,
|
|
69
|
+
page: null,
|
|
70
|
+
}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function openPrivate(workspaceId) {
|
|
75
|
+
return privateSourceFor(workspaceId, await fetchPrivateCatalog(workspaceId));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The source a command was asked for: `--private` (with `--workspace` or the saved scope), else public. */
|
|
79
|
+
export async function openSource(opts) {
|
|
80
|
+
return opts.private ? openPrivate(privateWorkspaceId(opts)) : publicSource(await fetchCatalog());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function markerWorkspace(marker) {
|
|
84
|
+
const id = marker.workspace_id;
|
|
85
|
+
return Number.isInteger(id) && id > 0 ? id : null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function openForMarker(marker) {
|
|
89
|
+
if (markerOrigin(marker) === 'public') return openSource({});
|
|
90
|
+
const workspaceId = markerWorkspace(marker);
|
|
91
|
+
return workspaceId
|
|
92
|
+
? openPrivate(workspaceId)
|
|
93
|
+
: Promise.reject(new Error('Its marker names no workspace. Install it again with --private.'));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Opens each installed skill's own source once per command; a source that failed fails each of its skills. */
|
|
97
|
+
export function sourcesForMarkers() {
|
|
98
|
+
const opened = new Map();
|
|
99
|
+
return (marker) => {
|
|
100
|
+
const id = markerOrigin(marker) === 'private' ? `private:${markerWorkspace(marker) ?? 'none'}` : 'public';
|
|
101
|
+
if (!opened.has(id)) {
|
|
102
|
+
const pending = openForMarker(marker);
|
|
103
|
+
pending.catch(() => {});
|
|
104
|
+
opened.set(id, pending);
|
|
105
|
+
}
|
|
106
|
+
return opened.get(id);
|
|
107
|
+
};
|
|
108
|
+
}
|