@framers/agentos-ext-google-cloud-stt 0.3.1 → 0.3.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/SKILL.md +2 -2
- package/dist/GoogleCloudSTTProvider.d.ts +8 -8
- package/dist/GoogleCloudSTTProvider.d.ts.map +1 -1
- package/dist/GoogleCloudSTTProvider.js +39 -22
- package/dist/GoogleCloudSTTProvider.js.map +1 -1
- package/manifest.json +1 -1
- package/package.json +1 -1
- package/src/GoogleCloudSTTProvider.ts +39 -20
package/SKILL.md
CHANGED
|
@@ -11,8 +11,8 @@ Batch speech-to-text recognition using Google Cloud Speech-to-Text V1 API.
|
|
|
11
11
|
## Setup
|
|
12
12
|
|
|
13
13
|
Provide credentials via the `GOOGLE_CLOUD_STT_CREDENTIALS` secret. Accepts either:
|
|
14
|
-
-
|
|
15
|
-
- A
|
|
14
|
+
- The service-account key itself, as JSON (any value that starts with `{`)
|
|
15
|
+
- A path to a service-account JSON key file (any other value)
|
|
16
16
|
|
|
17
17
|
Leave the secret unset to use Google's Application Default Credentials (`GOOGLE_APPLICATION_CREDENTIALS`, `gcloud auth application-default login`, or the metadata server on Google Cloud).
|
|
18
18
|
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* @file GoogleCloudSTTProvider.ts
|
|
3
3
|
* @description Batch speech-to-text provider backed by Google Cloud Speech-to-Text V1 API.
|
|
4
4
|
*
|
|
5
|
-
* Credentials are resolved from the constructor argument:
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
5
|
+
* Credentials are resolved from the constructor argument (see `clientOptionsFor`):
|
|
6
|
+
* - An empty string leaves the client on Application Default Credentials.
|
|
7
|
+
* - A string that starts with `{` is an inline service-account key, passed as `credentials`.
|
|
8
|
+
* - Any other string is a path to a service-account key file, passed as `keyFilename`.
|
|
9
9
|
*
|
|
10
10
|
* @module google-cloud-stt
|
|
11
11
|
*/
|
|
@@ -86,10 +86,10 @@ export declare class GoogleCloudSTTProvider {
|
|
|
86
86
|
/**
|
|
87
87
|
* Create a new {@link GoogleCloudSTTProvider}.
|
|
88
88
|
*
|
|
89
|
-
* @param credentials -
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
89
|
+
* @param credentials - The service-account key as JSON (a string that starts
|
|
90
|
+
* with `{`), a path to its key file, or an empty string, which leaves the
|
|
91
|
+
* client on Google's Application Default Credentials.
|
|
92
|
+
* @throws When `credentials` starts with `{` but is not valid JSON.
|
|
93
93
|
*/
|
|
94
94
|
constructor(credentials: string);
|
|
95
95
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoogleCloudSTTProvider.d.ts","sourceRoot":"","sources":["../src/GoogleCloudSTTProvider.ts"],"names":[],"mappings":"AACA;;;;;;;;;;GAUG;AAOH;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACxC,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,OAAO,EAAE,OAAO,CAAC;IACjB,2FAA2F;IAC3F,IAAI,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,QAAQ,CAAC,EAAE,0BAA0B,EAAE,CAAC;IACxC,mCAAmC;IACnC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,2FAA2F;IAC3F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;
|
|
1
|
+
{"version":3,"file":"GoogleCloudSTTProvider.d.ts","sourceRoot":"","sources":["../src/GoogleCloudSTTProvider.ts"],"names":[],"mappings":"AACA;;;;;;;;;;GAUG;AAOH;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACxC,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,OAAO,EAAE,OAAO,CAAC;IACjB,2FAA2F;IAC3F,IAAI,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,QAAQ,CAAC,EAAE,0BAA0B,EAAE,CAAC;IACxC,mCAAmC;IACnC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,2FAA2F;IAC3F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAgED;;;;;;GAMG;AACH,qBAAa,sBAAsB;IACjC,yEAAyE;IACzE,QAAQ,CAAC,EAAE,sBAAsB;IAEjC,oCAAoC;IACpC,QAAQ,CAAC,WAAW,iCAAiC;IAErD,6DAA6D;IAC7D,QAAQ,CAAC,iBAAiB,SAAS;IAEnC,wCAAwC;IACxC,OAAO,CAAC,OAAO,CAA6B;IAE5C,4FAA4F;IAC5F,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0B;IAEzD;;;;;;;OAOG;gBACS,WAAW,EAAE,MAAM;IAY/B;;;;;OAKG;YACW,UAAU;IAaxB;;;;OAIG;IACH,eAAe,IAAI,MAAM;IAIzB;;;;;;;;;;OAUG;IACG,UAAU,CACd,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,yBAAyB,CAAC;CA0CtC"}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* @file GoogleCloudSTTProvider.ts
|
|
4
4
|
* @description Batch speech-to-text provider backed by Google Cloud Speech-to-Text V1 API.
|
|
5
5
|
*
|
|
6
|
-
* Credentials are resolved from the constructor argument:
|
|
7
|
-
* -
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
6
|
+
* Credentials are resolved from the constructor argument (see `clientOptionsFor`):
|
|
7
|
+
* - An empty string leaves the client on Application Default Credentials.
|
|
8
|
+
* - A string that starts with `{` is an inline service-account key, passed as `credentials`.
|
|
9
|
+
* - Any other string is a path to a service-account key file, passed as `keyFilename`.
|
|
10
10
|
*
|
|
11
11
|
* @module google-cloud-stt
|
|
12
12
|
*/
|
|
@@ -43,6 +43,32 @@ function durationSeconds(duration) {
|
|
|
43
43
|
const seconds = Number(duration.seconds ?? 0) + Number(duration.nanos ?? 0) / 1e9;
|
|
44
44
|
return Number.isFinite(seconds) ? seconds : undefined;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Client options for a credentials string, decided by its content:
|
|
48
|
+
* - empty or blank: none, so the client finds Application Default Credentials;
|
|
49
|
+
* - starting with `{`: an inline service-account key, passed as `credentials`;
|
|
50
|
+
* - anything else: a path to a key file, passed as `keyFilename`.
|
|
51
|
+
*
|
|
52
|
+
* Every real key holds `/` (its https URLs) and `\` (the `\n` escapes in
|
|
53
|
+
* `private_key`), so those characters cannot tell a key from a path.
|
|
54
|
+
*
|
|
55
|
+
* @throws When the string starts with `{` but is not valid JSON. The message
|
|
56
|
+
* names GOOGLE_CLOUD_STT_CREDENTIALS and quotes none of the value.
|
|
57
|
+
*/
|
|
58
|
+
function clientOptionsFor(credentials) {
|
|
59
|
+
const text = credentials.trim();
|
|
60
|
+
if (!text)
|
|
61
|
+
return {};
|
|
62
|
+
if (!text.startsWith('{'))
|
|
63
|
+
return { keyFilename: text };
|
|
64
|
+
try {
|
|
65
|
+
return { credentials: JSON.parse(text) };
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// JSON.parse's message quotes the text near the error, and here that text is key material.
|
|
69
|
+
throw new Error('GOOGLE_CLOUD_STT_CREDENTIALS starts with "{" but is not valid JSON: give the whole service-account key, or a path to its file.');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
46
72
|
/**
|
|
47
73
|
* Google Cloud Speech-to-Text batch provider.
|
|
48
74
|
*
|
|
@@ -64,26 +90,17 @@ export class GoogleCloudSTTProvider {
|
|
|
64
90
|
/**
|
|
65
91
|
* Create a new {@link GoogleCloudSTTProvider}.
|
|
66
92
|
*
|
|
67
|
-
* @param credentials -
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
93
|
+
* @param credentials - The service-account key as JSON (a string that starts
|
|
94
|
+
* with `{`), a path to its key file, or an empty string, which leaves the
|
|
95
|
+
* client on Google's Application Default Credentials.
|
|
96
|
+
* @throws When `credentials` starts with `{` but is not valid JSON.
|
|
71
97
|
*/
|
|
72
98
|
constructor(credentials) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
else if (credentials.includes('/') || credentials.includes('\\')) {
|
|
80
|
-
// Treat as a file path.
|
|
81
|
-
this._clientOptions = { keyFilename: credentials };
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
// Treat as an inline JSON credentials object.
|
|
85
|
-
this._clientOptions = { credentials: JSON.parse(credentials) };
|
|
86
|
-
}
|
|
99
|
+
// An empty string gives no options: the Google client finds Application
|
|
100
|
+
// Default Credentials (GOOGLE_APPLICATION_CREDENTIALS, gcloud, or the
|
|
101
|
+
// metadata server) when it is first used, so the pack still loads without
|
|
102
|
+
// a configured secret.
|
|
103
|
+
this._clientOptions = clientOptionsFor(credentials);
|
|
87
104
|
}
|
|
88
105
|
// ---------------------------------------------------------------------------
|
|
89
106
|
// Private helpers
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoogleCloudSTTProvider.js","sourceRoot":"","sources":["../src/GoogleCloudSTTProvider.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;;;;;;GAUG;AAmEH,yDAAyD;AACzD,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,IAAI,CAAC,MAAM,IAAI,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,MAAM,CAAC;AACpH,CAAC;AAED,6DAA6D;AAC7D,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC;AACtE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,W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,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,OAAiB,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC;gBAC3G,KAAK,GAAG,CAAC,CAAC,OAAiB,CAAC;gBAC5B,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC;QAEd,OAAO;YACL,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YACxE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,IAAI,YAAY;YAChE,UAAU,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAChH,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,CAAC;YACP,QAAQ;YACR,gBAAgB,EAAE,UAAU;SAC7B,CAAC;IACJ,CAAC;CACF"}
|
package/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* @file GoogleCloudSTTProvider.ts
|
|
4
4
|
* @description Batch speech-to-text provider backed by Google Cloud Speech-to-Text V1 API.
|
|
5
5
|
*
|
|
6
|
-
* Credentials are resolved from the constructor argument:
|
|
7
|
-
* -
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
6
|
+
* Credentials are resolved from the constructor argument (see `clientOptionsFor`):
|
|
7
|
+
* - An empty string leaves the client on Application Default Credentials.
|
|
8
|
+
* - A string that starts with `{` is an inline service-account key, passed as `credentials`.
|
|
9
|
+
* - Any other string is a path to a service-account key file, passed as `keyFilename`.
|
|
10
10
|
*
|
|
11
11
|
* @module google-cloud-stt
|
|
12
12
|
*/
|
|
@@ -112,6 +112,32 @@ function durationSeconds(duration: { seconds?: unknown; nanos?: unknown } | null
|
|
|
112
112
|
return Number.isFinite(seconds) ? seconds : undefined;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Client options for a credentials string, decided by its content:
|
|
117
|
+
* - empty or blank: none, so the client finds Application Default Credentials;
|
|
118
|
+
* - starting with `{`: an inline service-account key, passed as `credentials`;
|
|
119
|
+
* - anything else: a path to a key file, passed as `keyFilename`.
|
|
120
|
+
*
|
|
121
|
+
* Every real key holds `/` (its https URLs) and `\` (the `\n` escapes in
|
|
122
|
+
* `private_key`), so those characters cannot tell a key from a path.
|
|
123
|
+
*
|
|
124
|
+
* @throws When the string starts with `{` but is not valid JSON. The message
|
|
125
|
+
* names GOOGLE_CLOUD_STT_CREDENTIALS and quotes none of the value.
|
|
126
|
+
*/
|
|
127
|
+
function clientOptionsFor(credentials: string): Record<string, unknown> {
|
|
128
|
+
const text = credentials.trim();
|
|
129
|
+
if (!text) return {};
|
|
130
|
+
if (!text.startsWith('{')) return { keyFilename: text };
|
|
131
|
+
try {
|
|
132
|
+
return { credentials: JSON.parse(text) as Record<string, unknown> };
|
|
133
|
+
} catch {
|
|
134
|
+
// JSON.parse's message quotes the text near the error, and here that text is key material.
|
|
135
|
+
throw new Error(
|
|
136
|
+
'GOOGLE_CLOUD_STT_CREDENTIALS starts with "{" but is not valid JSON: give the whole service-account key, or a path to its file.',
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
115
141
|
/**
|
|
116
142
|
* Google Cloud Speech-to-Text batch provider.
|
|
117
143
|
*
|
|
@@ -138,24 +164,17 @@ export class GoogleCloudSTTProvider {
|
|
|
138
164
|
/**
|
|
139
165
|
* Create a new {@link GoogleCloudSTTProvider}.
|
|
140
166
|
*
|
|
141
|
-
* @param credentials -
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
167
|
+
* @param credentials - The service-account key as JSON (a string that starts
|
|
168
|
+
* with `{`), a path to its key file, or an empty string, which leaves the
|
|
169
|
+
* client on Google's Application Default Credentials.
|
|
170
|
+
* @throws When `credentials` starts with `{` but is not valid JSON.
|
|
145
171
|
*/
|
|
146
172
|
constructor(credentials: string) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
} else if (credentials.includes('/') || credentials.includes('\\')) {
|
|
153
|
-
// Treat as a file path.
|
|
154
|
-
this._clientOptions = { keyFilename: credentials };
|
|
155
|
-
} else {
|
|
156
|
-
// Treat as an inline JSON credentials object.
|
|
157
|
-
this._clientOptions = { credentials: JSON.parse(credentials) as Record<string, unknown> };
|
|
158
|
-
}
|
|
173
|
+
// An empty string gives no options: the Google client finds Application
|
|
174
|
+
// Default Credentials (GOOGLE_APPLICATION_CREDENTIALS, gcloud, or the
|
|
175
|
+
// metadata server) when it is first used, so the pack still loads without
|
|
176
|
+
// a configured secret.
|
|
177
|
+
this._clientOptions = clientOptionsFor(credentials);
|
|
159
178
|
}
|
|
160
179
|
|
|
161
180
|
// ---------------------------------------------------------------------------
|