@assemblyline-agents/audio 5.0.9 → 6.0.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.
- package/README.md +24 -14
- package/ai.assemblyline/index.cjs +116 -0
- package/ai.assemblyline/providers/media-openai-audio-transcription.json +24 -0
- package/ai.assemblyline/providers/media-openrouter-audio-transcription.json +23 -0
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -15
- package/dist/index.js.map +1 -1
- package/dist/openai.d.ts +34 -0
- package/dist/openai.d.ts.map +1 -0
- package/dist/openai.js +122 -0
- package/dist/openai.js.map +1 -0
- package/dist/openrouter.d.ts +2 -10
- package/dist/openrouter.d.ts.map +1 -1
- package/dist/openrouter.js +15 -125
- package/dist/openrouter.js.map +1 -1
- package/dist/shared.d.ts +39 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +134 -0
- package/dist/shared.js.map +1 -0
- package/package.json +7 -4
- package/plugin.json +10 -0
package/README.md
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
# `@assemblyline-agents/audio`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reusable, channel-scoped pre-model audio processing for Assembly Line agents.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { openRouterAudioTranscription } from "@assemblyline-agents/audio";
|
|
5
|
+
Attachment-capable channel profiles select this package automatically. Photon,
|
|
6
|
+
Slack, Telegram, and Teams use OpenRouter transcription by default:
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
8
|
+
```yaml
|
|
9
|
+
channels: [photon]
|
|
12
10
|
```
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
Override or disable audio inside the channel:
|
|
13
|
+
|
|
14
|
+
```yaml
|
|
15
|
+
channels:
|
|
16
|
+
photon:
|
|
17
|
+
audio: openai
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Set `OPENROUTER_API_KEY` for the default profile. Its default model is
|
|
15
21
|
`openai/whisper-large-v3-turbo`; override it with
|
|
16
|
-
`OPENROUTER_AUDIO_TRANSCRIPTION_MODEL` or
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
`OPENROUTER_AUDIO_TRANSCRIPTION_MODEL` or channel options. The OpenAI profile
|
|
23
|
+
uses `OPENAI_API_KEY` and defaults to `gpt-4o-mini-transcribe`; override it with
|
|
24
|
+
`OPENAI_AUDIO_TRANSCRIPTION_MODEL`.
|
|
25
|
+
|
|
26
|
+
Successful transcripts are stored in the configured private blob adapter and
|
|
27
|
+
reused by attachment hash. Transcript text is supplied to the model as
|
|
28
|
+
untrusted derived context and is not copied into run audit events.
|
|
20
29
|
|
|
21
30
|
Apple CAF voice notes are converted to M4A with the package's bounded FFmpeg
|
|
22
|
-
binary before they are sent to
|
|
23
|
-
not modified. M4A and
|
|
31
|
+
binary before they are sent to the selected transcription provider. The
|
|
32
|
+
original private attachment is not modified. M4A and other provider-supported
|
|
33
|
+
formats are sent unchanged.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
"providers": {
|
|
3
|
+
"openrouter": {
|
|
4
|
+
"definition": "@assemblyline-agents/audio",
|
|
5
|
+
"name": "openrouter",
|
|
6
|
+
"role": "media",
|
|
7
|
+
"kind": "openrouter-audio-transcription",
|
|
8
|
+
"contract": "./ai.assemblyline/providers/media-openrouter-audio-transcription.json",
|
|
9
|
+
"configSchema": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"additionalProperties": false,
|
|
12
|
+
"properties": {
|
|
13
|
+
"model": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"minLength": 1
|
|
16
|
+
},
|
|
17
|
+
"fallbackModels": {
|
|
18
|
+
"type": "array",
|
|
19
|
+
"items": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"minLength": 1
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"language": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"minLength": 1
|
|
27
|
+
},
|
|
28
|
+
"endpoint": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"minLength": 1
|
|
31
|
+
},
|
|
32
|
+
"modelMetadataKey": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"minLength": 1
|
|
35
|
+
},
|
|
36
|
+
"title": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"minLength": 1
|
|
39
|
+
},
|
|
40
|
+
"referer": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"minLength": 1
|
|
43
|
+
},
|
|
44
|
+
"maxBytes": {
|
|
45
|
+
"type": "integer",
|
|
46
|
+
"minimum": 1
|
|
47
|
+
},
|
|
48
|
+
"maxAttachments": {
|
|
49
|
+
"type": "integer",
|
|
50
|
+
"minimum": 1
|
|
51
|
+
},
|
|
52
|
+
"timeoutMs": {
|
|
53
|
+
"type": "integer",
|
|
54
|
+
"minimum": 1
|
|
55
|
+
},
|
|
56
|
+
"maxResponseBytes": {
|
|
57
|
+
"type": "integer",
|
|
58
|
+
"minimum": 1
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"openai": {
|
|
64
|
+
"definition": "@assemblyline-agents/audio",
|
|
65
|
+
"name": "openai",
|
|
66
|
+
"role": "media",
|
|
67
|
+
"kind": "openai-audio-transcription",
|
|
68
|
+
"contract": "./ai.assemblyline/providers/media-openai-audio-transcription.json",
|
|
69
|
+
"configSchema": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"additionalProperties": false,
|
|
72
|
+
"properties": {
|
|
73
|
+
"model": {
|
|
74
|
+
"type": "string",
|
|
75
|
+
"minLength": 1
|
|
76
|
+
},
|
|
77
|
+
"fallbackModels": {
|
|
78
|
+
"type": "array",
|
|
79
|
+
"items": {
|
|
80
|
+
"type": "string",
|
|
81
|
+
"minLength": 1
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"language": {
|
|
85
|
+
"type": "string",
|
|
86
|
+
"minLength": 1
|
|
87
|
+
},
|
|
88
|
+
"endpoint": {
|
|
89
|
+
"type": "string",
|
|
90
|
+
"minLength": 1
|
|
91
|
+
},
|
|
92
|
+
"modelMetadataKey": {
|
|
93
|
+
"type": "string",
|
|
94
|
+
"minLength": 1
|
|
95
|
+
},
|
|
96
|
+
"maxBytes": {
|
|
97
|
+
"type": "integer",
|
|
98
|
+
"minimum": 1
|
|
99
|
+
},
|
|
100
|
+
"maxAttachments": {
|
|
101
|
+
"type": "integer",
|
|
102
|
+
"minimum": 1
|
|
103
|
+
},
|
|
104
|
+
"timeoutMs": {
|
|
105
|
+
"type": "integer",
|
|
106
|
+
"minimum": 1
|
|
107
|
+
},
|
|
108
|
+
"maxResponseBytes": {
|
|
109
|
+
"type": "integer",
|
|
110
|
+
"minimum": 1
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "openai-audio-transcription",
|
|
3
|
+
"role": "media",
|
|
4
|
+
"packageName": "@assemblyline-agents/audio",
|
|
5
|
+
"capabilities": [
|
|
6
|
+
"audio-transcription",
|
|
7
|
+
"attachment-context",
|
|
8
|
+
"durable-transcript-cache"
|
|
9
|
+
],
|
|
10
|
+
"requiredConfig": [],
|
|
11
|
+
"optionalConfig": [
|
|
12
|
+
"OPENAI_AUDIO_TRANSCRIPTION_MODEL",
|
|
13
|
+
"OPENAI_AUDIO_TRANSCRIPTION_FALLBACK_MODELS",
|
|
14
|
+
"OPENAI_AUDIO_TRANSCRIPTION_LANGUAGE",
|
|
15
|
+
"OPENAI_AUDIO_TRANSCRIPTION_ENDPOINT",
|
|
16
|
+
"ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_BYTES",
|
|
17
|
+
"ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_ATTACHMENTS",
|
|
18
|
+
"ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_TIMEOUT_MS"
|
|
19
|
+
],
|
|
20
|
+
"requiredCredentials": [
|
|
21
|
+
"OPENAI_API_KEY"
|
|
22
|
+
],
|
|
23
|
+
"optionalCredentials": []
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "openrouter-audio-transcription",
|
|
3
|
+
"role": "media",
|
|
4
|
+
"packageName": "@assemblyline-agents/audio",
|
|
5
|
+
"capabilities": [
|
|
6
|
+
"audio-transcription",
|
|
7
|
+
"attachment-context",
|
|
8
|
+
"durable-transcript-cache"
|
|
9
|
+
],
|
|
10
|
+
"requiredConfig": [],
|
|
11
|
+
"optionalConfig": [
|
|
12
|
+
"OPENROUTER_AUDIO_TRANSCRIPTION_MODEL",
|
|
13
|
+
"OPENROUTER_AUDIO_TRANSCRIPTION_FALLBACK_MODELS",
|
|
14
|
+
"OPENROUTER_AUDIO_TRANSCRIPTION_LANGUAGE",
|
|
15
|
+
"ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_BYTES",
|
|
16
|
+
"ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_ATTACHMENTS",
|
|
17
|
+
"ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_TIMEOUT_MS"
|
|
18
|
+
],
|
|
19
|
+
"requiredCredentials": [
|
|
20
|
+
"OPENROUTER_API_KEY"
|
|
21
|
+
],
|
|
22
|
+
"optionalCredentials": []
|
|
23
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
import type { AdapterProviderMetadata as PluginAdapterProviderMetadata } from "@assemblyline-agents/core";
|
|
1
2
|
import { type ProviderModule } from "@assemblyline-agents/core";
|
|
3
|
+
import { type OpenAIAudioTranscriberOptions } from "./openai.js";
|
|
2
4
|
import { type OpenRouterAudioTranscriberOptions } from "./openrouter.js";
|
|
5
|
+
export { OpenAIAudioTranscriber, type OpenAIAudioTranscriberOptions, type OpenAIAudioTranscriptionResult } from "./openai.js";
|
|
3
6
|
export { OpenRouterAudioTranscriber, type OpenRouterAudioTranscriberOptions, type OpenRouterAudioTranscriptionResult } from "./openrouter.js";
|
|
4
|
-
export declare const OPENROUTER_AUDIO_TRANSCRIPTION_PROVIDER_METADATA:
|
|
5
|
-
|
|
6
|
-
role: "media";
|
|
7
|
-
packageName: string;
|
|
8
|
-
requiredCredentials: string[];
|
|
9
|
-
optionalConfig: string[];
|
|
10
|
-
capabilities: string[];
|
|
11
|
-
};
|
|
7
|
+
export declare const OPENROUTER_AUDIO_TRANSCRIPTION_PROVIDER_METADATA: PluginAdapterProviderMetadata;
|
|
8
|
+
export declare const OPENAI_AUDIO_TRANSCRIPTION_PROVIDER_METADATA: PluginAdapterProviderMetadata;
|
|
12
9
|
export declare function openRouterAudioTranscription(options?: OpenRouterAudioTranscriberOptions): import("@assemblyline-agents/core").AdapterDefinition;
|
|
10
|
+
export declare function openAIAudioTranscription(options?: OpenAIAudioTranscriberOptions): import("@assemblyline-agents/core").AdapterDefinition;
|
|
13
11
|
export declare const assemblyLineProvider: ProviderModule;
|
|
14
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAA8B,KAAK,iCAAiC,EAAE,MAAM,iBAAiB,CAAC;AAErG,OAAO,EACL,0BAA0B,EAC1B,KAAK,iCAAiC,EACtC,KAAK,kCAAkC,EACxC,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,gDAAgD
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,IAAI,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAG1G,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAA0B,KAAK,6BAA6B,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EAA8B,KAAK,iCAAiC,EAAE,MAAM,iBAAiB,CAAC;AAErG,OAAO,EACL,sBAAsB,EACtB,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,EACpC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,0BAA0B,EAC1B,KAAK,iCAAiC,EACtC,KAAK,kCAAkC,EACxC,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,gDAAgD,EAA4E,6BAA6B,CAAC;AAEvK,eAAO,MAAM,4CAA4C,EAAwE,6BAA6B,CAAC;AAE/J,wBAAgB,4BAA4B,CAAC,OAAO,GAAE,iCAAsC,yDAM3F;AAED,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,6BAAkC,yDAMnF;AAED,eAAO,MAAM,oBAAoB,EAAE,cAuBlC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
+
import providerContract_media_openrouter_audio_transcription_json from "../ai.assemblyline/providers/media-openrouter-audio-transcription.json" with { type: "json" };
|
|
2
|
+
import providerContract_media_openai_audio_transcription_json from "../ai.assemblyline/providers/media-openai-audio-transcription.json" with { type: "json" };
|
|
1
3
|
import { adapter } from "@assemblyline-agents/core";
|
|
4
|
+
import { OpenAIAudioTranscriber } from "./openai.js";
|
|
2
5
|
import { OpenRouterAudioTranscriber } from "./openrouter.js";
|
|
6
|
+
export { OpenAIAudioTranscriber } from "./openai.js";
|
|
3
7
|
export { OpenRouterAudioTranscriber } from "./openrouter.js";
|
|
4
|
-
export const OPENROUTER_AUDIO_TRANSCRIPTION_PROVIDER_METADATA =
|
|
5
|
-
|
|
6
|
-
role: "media",
|
|
7
|
-
packageName: "@assemblyline-agents/audio",
|
|
8
|
-
requiredCredentials: ["OPENROUTER_API_KEY"],
|
|
9
|
-
optionalConfig: [
|
|
10
|
-
"OPENROUTER_AUDIO_TRANSCRIPTION_MODEL",
|
|
11
|
-
"OPENROUTER_AUDIO_TRANSCRIPTION_FALLBACK_MODELS",
|
|
12
|
-
"OPENROUTER_AUDIO_TRANSCRIPTION_LANGUAGE",
|
|
13
|
-
"ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_BYTES",
|
|
14
|
-
"ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_ATTACHMENTS",
|
|
15
|
-
"ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_TIMEOUT_MS"
|
|
16
|
-
],
|
|
17
|
-
capabilities: ["audio-transcription", "attachment-context", "durable-transcript-cache"]
|
|
18
|
-
};
|
|
8
|
+
export const OPENROUTER_AUDIO_TRANSCRIPTION_PROVIDER_METADATA = providerContract_media_openrouter_audio_transcription_json;
|
|
9
|
+
export const OPENAI_AUDIO_TRANSCRIPTION_PROVIDER_METADATA = providerContract_media_openai_audio_transcription_json;
|
|
19
10
|
export function openRouterAudioTranscription(options = {}) {
|
|
20
11
|
return adapter("openrouter-audio-transcription", options, { package: "@assemblyline-agents/audio" });
|
|
21
12
|
}
|
|
13
|
+
export function openAIAudioTranscription(options = {}) {
|
|
14
|
+
return adapter("openai-audio-transcription", options, { package: "@assemblyline-agents/audio" });
|
|
15
|
+
}
|
|
22
16
|
export const assemblyLineProvider = {
|
|
23
17
|
providers: [
|
|
18
|
+
{
|
|
19
|
+
metadata: OPENAI_AUDIO_TRANSCRIPTION_PROVIDER_METADATA,
|
|
20
|
+
create(ctx) {
|
|
21
|
+
return new OpenAIAudioTranscriber({
|
|
22
|
+
options: ctx.options,
|
|
23
|
+
env: ctx.env,
|
|
24
|
+
fetch: ctx.fetch
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
},
|
|
24
28
|
{
|
|
25
29
|
metadata: OPENROUTER_AUDIO_TRANSCRIPTION_PROVIDER_METADATA,
|
|
26
30
|
create(ctx) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,0DAA0D,MAAM,wEAAwE,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACtK,OAAO,sDAAsD,MAAM,oEAAoE,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC9J,OAAO,EAAE,OAAO,EAAwC,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAsC,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,0BAA0B,EAA0C,MAAM,iBAAiB,CAAC;AAErG,OAAO,EACL,sBAAsB,EAGvB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,0BAA0B,EAG3B,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,MAAM,gDAAgD,GAAG,0DAAsG,CAAC;AAEvK,MAAM,CAAC,MAAM,4CAA4C,GAAG,sDAAkG,CAAC;AAE/J,MAAM,UAAU,4BAA4B,CAAC,UAA6C,EAAE;IAC1F,OAAO,OAAO,CACZ,gCAAgC,EAChC,OAAgC,EAChC,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,UAAyC,EAAE;IAClF,OAAO,OAAO,CACZ,4BAA4B,EAC5B,OAAgC,EAChC,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAmB;IAClD,SAAS,EAAE;QACT;YACE,QAAQ,EAAE,4CAA4C;YACtD,MAAM,CAAC,GAAG;gBACR,OAAO,IAAI,sBAAsB,CAAC;oBAChC,OAAO,EAAE,GAAG,CAAC,OAAwC;oBACrD,GAAG,EAAE,GAAG,CAAC,GAAG;oBACZ,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB,CAAC,CAAC;YACL,CAAC;SACF;QACD;YACE,QAAQ,EAAE,gDAAgD;YAC1D,MAAM,CAAC,GAAG;gBACR,OAAO,IAAI,0BAA0B,CAAC;oBACpC,OAAO,EAAE,GAAG,CAAC,OAA4C;oBACzD,GAAG,EAAE,GAAG,CAAC,GAAG;oBACZ,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB,CAAC,CAAC;YACL,CAAC;SACF;KACF;CACF,CAAC"}
|
package/dist/openai.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { JsonObject } from "@assemblyline-agents/core";
|
|
2
|
+
import type { MediaProcessor, MediaProcessorAttachment, MediaProcessorInput, MediaProcessorResult } from "@assemblyline-agents/runtime";
|
|
3
|
+
import { type CommonAudioTranscriberOptions } from "./shared.js";
|
|
4
|
+
export interface OpenAIAudioTranscriberOptions extends CommonAudioTranscriberOptions {
|
|
5
|
+
}
|
|
6
|
+
export interface OpenAIAudioTranscriptionResult {
|
|
7
|
+
text: string;
|
|
8
|
+
model: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class OpenAIAudioTranscriber implements MediaProcessor {
|
|
11
|
+
readonly id = "openai-audio-transcription";
|
|
12
|
+
readonly maxAttachments: number;
|
|
13
|
+
readonly maxBytes: number;
|
|
14
|
+
private readonly options;
|
|
15
|
+
private readonly env;
|
|
16
|
+
private readonly fetch;
|
|
17
|
+
constructor(input?: {
|
|
18
|
+
options?: OpenAIAudioTranscriberOptions;
|
|
19
|
+
env?: Record<string, string | undefined>;
|
|
20
|
+
fetch?: typeof fetch;
|
|
21
|
+
});
|
|
22
|
+
matches(input: MediaProcessorAttachment): boolean;
|
|
23
|
+
cacheKey(input: MediaProcessorAttachment): string;
|
|
24
|
+
process(input: MediaProcessorInput): Promise<MediaProcessorResult>;
|
|
25
|
+
failureContext(input: MediaProcessorAttachment, error: string): JsonObject;
|
|
26
|
+
private failed;
|
|
27
|
+
private transcribe;
|
|
28
|
+
private models;
|
|
29
|
+
private language;
|
|
30
|
+
private endpoint;
|
|
31
|
+
private timeoutMs;
|
|
32
|
+
private maxResponseBytes;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../src/openai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAkBL,KAAK,6BAA6B,EACnC,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,6BAA8B,SAAQ,6BAA6B;CAAG;AAEvF,MAAM,WAAW,8BAA8B;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,sBAAuB,YAAW,cAAc;IAC3D,QAAQ,CAAC,EAAE,gCAAgC;IAC3C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IACxD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAqC;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAEzB,KAAK,GAAE;QACjB,OAAO,CAAC,EAAE,6BAA6B,CAAC;QACxC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;QACzC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;KACjB;IAoBN,OAAO,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO;IAIjD,QAAQ,CAAC,KAAK,EAAE,wBAAwB,GAAG,MAAM;IAS3C,OAAO,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAYxE,cAAc,CAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU;IAI1E,OAAO,CAAC,MAAM;YAIA,UAAU;IAsCxB,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,SAAS;IAUjB,OAAO,CAAC,gBAAgB;CAGzB"}
|
package/dist/openai.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { isCafAudio } from "./caf.js";
|
|
2
|
+
import { audioAttachmentMatches, boundedInteger, CAF_PREPROCESSING_VERSION, DEFAULT_AUDIO_MAX_ATTACHMENTS, DEFAULT_AUDIO_MAX_BYTES, DEFAULT_AUDIO_MAX_RESPONSE_BYTES, DEFAULT_AUDIO_TIMEOUT_MS, envNumber, failedAudioContext, failedAudioResult, isRecord, preparedAudio, processedAudioResult, readJson, retryableStatus, safeAudioError, stringValue } from "./shared.js";
|
|
3
|
+
const DEFAULT_ENDPOINT = "https://api.openai.com/v1/audio/transcriptions";
|
|
4
|
+
const DEFAULT_MODEL = "gpt-4o-mini-transcribe";
|
|
5
|
+
const DEFAULT_FALLBACK_MODELS = ["whisper-1"];
|
|
6
|
+
const OPENAI_AUDIO_FORMATS = new Set(["flac", "m4a", "mp3", "mp4", "mpeg", "mpga", "ogg", "wav", "webm"]);
|
|
7
|
+
export class OpenAIAudioTranscriber {
|
|
8
|
+
id = "openai-audio-transcription";
|
|
9
|
+
maxAttachments;
|
|
10
|
+
maxBytes;
|
|
11
|
+
options;
|
|
12
|
+
env;
|
|
13
|
+
fetch;
|
|
14
|
+
constructor(input = {}) {
|
|
15
|
+
this.options = input.options ?? {};
|
|
16
|
+
this.env = input.env ?? {};
|
|
17
|
+
this.fetch = input.fetch ?? globalThis.fetch.bind(globalThis);
|
|
18
|
+
this.maxAttachments = boundedInteger(this.options.maxAttachments, envNumber(this.env, "ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_ATTACHMENTS", "OPENAI_AUDIO_TRANSCRIPTION_MAX_ATTACHMENTS"), DEFAULT_AUDIO_MAX_ATTACHMENTS, 1, 10);
|
|
19
|
+
this.maxBytes = boundedInteger(this.options.maxBytes, envNumber(this.env, "ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_BYTES", "OPENAI_AUDIO_TRANSCRIPTION_MAX_BYTES"), DEFAULT_AUDIO_MAX_BYTES, 1, 50 * 1024 * 1024);
|
|
20
|
+
}
|
|
21
|
+
matches(input) {
|
|
22
|
+
return audioAttachmentMatches(input);
|
|
23
|
+
}
|
|
24
|
+
cacheKey(input) {
|
|
25
|
+
return JSON.stringify({
|
|
26
|
+
endpoint: this.endpoint(),
|
|
27
|
+
models: this.models(input),
|
|
28
|
+
language: this.language() || null,
|
|
29
|
+
preprocessing: isCafAudio(input.filename, input.mimeType) ? CAF_PREPROCESSING_VERSION : null
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async process(input) {
|
|
33
|
+
if (input.bytes.byteLength === 0)
|
|
34
|
+
return this.failed(input, "The voice note was empty.");
|
|
35
|
+
const apiKey = this.env.OPENAI_API_KEY?.trim();
|
|
36
|
+
if (!apiKey)
|
|
37
|
+
return this.failed(input, "Voice transcription is not configured.");
|
|
38
|
+
try {
|
|
39
|
+
return processedAudioResult(input, "openai", await this.transcribe(input, apiKey));
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return this.failed(input, safeAudioError(error));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
failureContext(input, error) {
|
|
46
|
+
return failedAudioContext(input, safeAudioError(error));
|
|
47
|
+
}
|
|
48
|
+
failed(input, error) {
|
|
49
|
+
return failedAudioResult(input, "openai", error);
|
|
50
|
+
}
|
|
51
|
+
async transcribe(input, apiKey) {
|
|
52
|
+
const models = this.models(input);
|
|
53
|
+
const prepared = await preparedAudio(input, this.maxBytes, this.timeoutMs());
|
|
54
|
+
if (!OPENAI_AUDIO_FORMATS.has(prepared.format)) {
|
|
55
|
+
throw new Error(`Unsupported OpenAI voice-note format: ${prepared.format}.`);
|
|
56
|
+
}
|
|
57
|
+
let lastError;
|
|
58
|
+
for (const model of models) {
|
|
59
|
+
try {
|
|
60
|
+
const body = new FormData();
|
|
61
|
+
body.append("file", new Blob([exactArrayBuffer(prepared.bytes)], { type: prepared.mimeType }), prepared.filename);
|
|
62
|
+
body.append("model", model);
|
|
63
|
+
body.append("response_format", "json");
|
|
64
|
+
if (this.language())
|
|
65
|
+
body.append("language", this.language());
|
|
66
|
+
const response = await this.fetch(this.endpoint(), {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: { authorization: `Bearer ${apiKey}` },
|
|
69
|
+
body,
|
|
70
|
+
signal: AbortSignal.timeout(this.timeoutMs())
|
|
71
|
+
});
|
|
72
|
+
const payload = await readJson(response, this.maxResponseBytes(), "OpenAI");
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
const error = new Error(`OpenAI transcription failed with HTTP ${response.status}.`);
|
|
75
|
+
if (!retryableStatus(response.status))
|
|
76
|
+
throw error;
|
|
77
|
+
lastError = error;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const text = isRecord(payload) && typeof payload.text === "string" ? payload.text.trim() : "";
|
|
81
|
+
if (!text)
|
|
82
|
+
throw new Error("OpenAI returned an empty transcription.");
|
|
83
|
+
return { text, model };
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
throw lastError ?? new Error("OpenAI could not transcribe the audio attachment.");
|
|
90
|
+
}
|
|
91
|
+
models(input) {
|
|
92
|
+
const metadataModel = this.options.modelMetadataKey
|
|
93
|
+
? stringValue(input.metadata[this.options.modelMetadataKey])
|
|
94
|
+
: "";
|
|
95
|
+
const primary = metadataModel || this.options.model || this.env.OPENAI_AUDIO_TRANSCRIPTION_MODEL || DEFAULT_MODEL;
|
|
96
|
+
const configuredFallbacks = this.options.fallbackModels ?? splitModels(this.env.OPENAI_AUDIO_TRANSCRIPTION_FALLBACK_MODELS);
|
|
97
|
+
const fallbacks = configuredFallbacks.length > 0 ? configuredFallbacks : DEFAULT_FALLBACK_MODELS;
|
|
98
|
+
return [...new Set([primary, ...fallbacks].map(stripOpenAIPrefix).map((value) => value.trim()).filter(Boolean))];
|
|
99
|
+
}
|
|
100
|
+
language() {
|
|
101
|
+
return this.options.language?.trim() || this.env.OPENAI_AUDIO_TRANSCRIPTION_LANGUAGE?.trim() || "";
|
|
102
|
+
}
|
|
103
|
+
endpoint() {
|
|
104
|
+
return this.options.endpoint?.trim() || this.env.OPENAI_AUDIO_TRANSCRIPTION_ENDPOINT?.trim() || DEFAULT_ENDPOINT;
|
|
105
|
+
}
|
|
106
|
+
timeoutMs() {
|
|
107
|
+
return boundedInteger(this.options.timeoutMs, envNumber(this.env, "ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_TIMEOUT_MS", "OPENAI_AUDIO_TRANSCRIPTION_TIMEOUT_MS"), DEFAULT_AUDIO_TIMEOUT_MS, 5_000, 180_000);
|
|
108
|
+
}
|
|
109
|
+
maxResponseBytes() {
|
|
110
|
+
return boundedInteger(this.options.maxResponseBytes, undefined, DEFAULT_AUDIO_MAX_RESPONSE_BYTES, 1_024, 2 * 1024 * 1024);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function exactArrayBuffer(bytes) {
|
|
114
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
115
|
+
}
|
|
116
|
+
function splitModels(value) {
|
|
117
|
+
return value?.split(",").map((model) => model.trim()).filter(Boolean) ?? [];
|
|
118
|
+
}
|
|
119
|
+
function stripOpenAIPrefix(model) {
|
|
120
|
+
return model.trim().replace(/^openai\//u, "");
|
|
121
|
+
}
|
|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AAC,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,mCAAmC,EAAE,IAAI,EAAE,IAAI,gBAAgB,CAAC;IACnH,CAAC;IAEO,SAAS;QACf,OAAO,cAAc,CACnB,IAAI,CAAC,OAAO,CAAC,SAAS,EACtB,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,8CAA8C,EAAE,uCAAuC,CAAC,EAC5G,wBAAwB,EACxB,KAAK,EACL,OAAO,CACR,CAAC;IACJ,CAAC;IAEO,gBAAgB;QACtB,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,SAAS,EAAE,gCAAgC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IAC5H,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,KAAiB;IACzC,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAgB,CAAC;AAClG,CAAC;AAED,SAAS,WAAW,CAAC,KAAyB;IAC5C,OAAO,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;AAC9E,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/openrouter.d.ts
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import type { JsonObject } from "@assemblyline-agents/core";
|
|
2
2
|
import type { MediaProcessor, MediaProcessorAttachment, MediaProcessorInput, MediaProcessorResult } from "@assemblyline-agents/runtime";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
fallbackModels?: string[];
|
|
6
|
-
language?: string;
|
|
7
|
-
endpoint?: string;
|
|
3
|
+
import { type CommonAudioTranscriberOptions } from "./shared.js";
|
|
4
|
+
export interface OpenRouterAudioTranscriberOptions extends CommonAudioTranscriberOptions {
|
|
8
5
|
title?: string;
|
|
9
6
|
referer?: string;
|
|
10
|
-
modelMetadataKey?: string;
|
|
11
|
-
maxBytes?: number;
|
|
12
|
-
maxAttachments?: number;
|
|
13
|
-
timeoutMs?: number;
|
|
14
|
-
maxResponseBytes?: number;
|
|
15
7
|
}
|
|
16
8
|
export interface OpenRouterAudioTranscriptionResult {
|
|
17
9
|
text: string;
|
package/dist/openrouter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openrouter.d.ts","sourceRoot":"","sources":["../src/openrouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"openrouter.d.ts","sourceRoot":"","sources":["../src/openrouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAkBL,KAAK,6BAA6B,EACnC,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,iCAAkC,SAAQ,6BAA6B;IACtF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kCAAkC;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,0BAA2B,YAAW,cAAc;IAC/D,QAAQ,CAAC,EAAE,oCAAoC;IAC/C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAC5D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAqC;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAEzB,KAAK,GAAE;QACjB,OAAO,CAAC,EAAE,iCAAiC,CAAC;QAC5C,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;QACzC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;KACjB;IAoBN,OAAO,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO;IAIjD,QAAQ,CAAC,KAAK,EAAE,wBAAwB,GAAG,MAAM;IAS3C,OAAO,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAaxE,cAAc,CAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU;IAI1E,OAAO,CAAC,MAAM;YAIA,UAAU;IA0CxB,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,SAAS;IAUjB,OAAO,CAAC,gBAAgB;CAGzB"}
|
package/dist/openrouter.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isCafAudio } from "./caf.js";
|
|
2
|
+
import { audioAttachmentMatches, boundedInteger, CAF_PREPROCESSING_VERSION, DEFAULT_AUDIO_MAX_ATTACHMENTS, DEFAULT_AUDIO_MAX_BYTES, DEFAULT_AUDIO_MAX_RESPONSE_BYTES, DEFAULT_AUDIO_TIMEOUT_MS, envNumber, failedAudioContext, failedAudioResult, isRecord, preparedAudio, processedAudioResult, readJson, retryableStatus, safeAudioError, stringValue } from "./shared.js";
|
|
2
3
|
const DEFAULT_ENDPOINT = "https://openrouter.ai/api/v1/audio/transcriptions";
|
|
3
4
|
const DEFAULT_MODEL = "openai/whisper-large-v3-turbo";
|
|
4
5
|
const DEFAULT_FALLBACK_MODELS = ["openai/whisper-large-v3", "openai/whisper-1"];
|
|
5
|
-
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
6
|
-
const DEFAULT_MAX_RESPONSE_BYTES = 512 * 1024;
|
|
7
|
-
const DEFAULT_MAX_AUDIO_BYTES = 25 * 1024 * 1024;
|
|
8
|
-
const DEFAULT_MAX_AUDIO_ATTACHMENTS = 4;
|
|
9
|
-
const CAF_PREPROCESSING_VERSION = "caf-to-m4a-v1";
|
|
10
6
|
export class OpenRouterAudioTranscriber {
|
|
11
7
|
id = "openrouter-audio-transcription";
|
|
12
8
|
maxAttachments;
|
|
@@ -18,15 +14,11 @@ export class OpenRouterAudioTranscriber {
|
|
|
18
14
|
this.options = input.options ?? {};
|
|
19
15
|
this.env = input.env ?? {};
|
|
20
16
|
this.fetch = input.fetch ?? globalThis.fetch.bind(globalThis);
|
|
21
|
-
this.maxAttachments = boundedInteger(this.options.maxAttachments, envNumber(this.env, "ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_ATTACHMENTS", "OPENROUTER_AUDIO_TRANSCRIPTION_MAX_ATTACHMENTS"),
|
|
22
|
-
this.maxBytes = boundedInteger(this.options.maxBytes, envNumber(this.env, "ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_BYTES", "OPENROUTER_AUDIO_TRANSCRIPTION_MAX_BYTES"),
|
|
17
|
+
this.maxAttachments = boundedInteger(this.options.maxAttachments, envNumber(this.env, "ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_ATTACHMENTS", "OPENROUTER_AUDIO_TRANSCRIPTION_MAX_ATTACHMENTS"), DEFAULT_AUDIO_MAX_ATTACHMENTS, 1, 10);
|
|
18
|
+
this.maxBytes = boundedInteger(this.options.maxBytes, envNumber(this.env, "ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_MAX_BYTES", "OPENROUTER_AUDIO_TRANSCRIPTION_MAX_BYTES"), DEFAULT_AUDIO_MAX_BYTES, 1, 50 * 1024 * 1024);
|
|
23
19
|
}
|
|
24
20
|
matches(input) {
|
|
25
|
-
|
|
26
|
-
return true;
|
|
27
|
-
if (stringValue(input.attachment.kind).toLowerCase() === "audio")
|
|
28
|
-
return true;
|
|
29
|
-
return /\.(?:aac|caf|flac|m4a|mp3|mp4|ogg|wav|webm)$/iu.test(input.filename);
|
|
21
|
+
return audioAttachmentMatches(input);
|
|
30
22
|
}
|
|
31
23
|
cacheKey(input) {
|
|
32
24
|
return JSON.stringify({
|
|
@@ -44,47 +36,21 @@ export class OpenRouterAudioTranscriber {
|
|
|
44
36
|
return this.failed(input, "Voice transcription is not configured.");
|
|
45
37
|
try {
|
|
46
38
|
const result = await this.transcribe(input, apiKey);
|
|
47
|
-
return
|
|
48
|
-
status: "processed",
|
|
49
|
-
context: {
|
|
50
|
-
audioTranscriptions: [{
|
|
51
|
-
status: "transcribed",
|
|
52
|
-
source: "untrusted_user_audio",
|
|
53
|
-
attachmentId: stringValue(input.attachment.id) || input.filename,
|
|
54
|
-
filename: input.filename,
|
|
55
|
-
mimeType: input.mimeType,
|
|
56
|
-
model: result.model,
|
|
57
|
-
text: result.text
|
|
58
|
-
}]
|
|
59
|
-
},
|
|
60
|
-
audit: {
|
|
61
|
-
provider: "openrouter",
|
|
62
|
-
model: result.model,
|
|
63
|
-
sourceSize: input.bytes.byteLength
|
|
64
|
-
}
|
|
65
|
-
};
|
|
39
|
+
return processedAudioResult(input, "openrouter", result);
|
|
66
40
|
}
|
|
67
41
|
catch (error) {
|
|
68
|
-
return this.failed(input,
|
|
42
|
+
return this.failed(input, safeAudioError(error));
|
|
69
43
|
}
|
|
70
44
|
}
|
|
71
45
|
failureContext(input, error) {
|
|
72
|
-
return
|
|
46
|
+
return failedAudioContext(input, safeAudioError(error));
|
|
73
47
|
}
|
|
74
48
|
failed(input, error) {
|
|
75
|
-
return
|
|
76
|
-
status: "failed",
|
|
77
|
-
context: failedContext(input, error),
|
|
78
|
-
audit: { provider: "openrouter", reason: error }
|
|
79
|
-
};
|
|
49
|
+
return failedAudioResult(input, "openrouter", error);
|
|
80
50
|
}
|
|
81
51
|
async transcribe(input, apiKey) {
|
|
82
52
|
const models = this.models(input);
|
|
83
|
-
const
|
|
84
|
-
const bytes = caf
|
|
85
|
-
? await convertCafToM4a(input.bytes, { maxBytes: this.maxBytes, timeoutMs: this.timeoutMs() })
|
|
86
|
-
: input.bytes;
|
|
87
|
-
const format = caf ? "m4a" : audioFormat(input.filename, input.mimeType);
|
|
53
|
+
const prepared = await preparedAudio(input, this.maxBytes, this.timeoutMs());
|
|
88
54
|
let lastError;
|
|
89
55
|
for (const model of models) {
|
|
90
56
|
try {
|
|
@@ -99,14 +65,14 @@ export class OpenRouterAudioTranscriber {
|
|
|
99
65
|
body: JSON.stringify({
|
|
100
66
|
model,
|
|
101
67
|
input_audio: {
|
|
102
|
-
data: Buffer.from(bytes).toString("base64"),
|
|
103
|
-
format
|
|
68
|
+
data: Buffer.from(prepared.bytes).toString("base64"),
|
|
69
|
+
format: prepared.format
|
|
104
70
|
},
|
|
105
71
|
...(this.language() ? { language: this.language() } : {})
|
|
106
72
|
}),
|
|
107
73
|
signal: AbortSignal.timeout(this.timeoutMs())
|
|
108
74
|
});
|
|
109
|
-
const payload = await readJson(response, this.maxResponseBytes());
|
|
75
|
+
const payload = await readJson(response, this.maxResponseBytes(), "OpenRouter");
|
|
110
76
|
if (!response.ok) {
|
|
111
77
|
const error = new Error(`OpenRouter transcription failed with HTTP ${response.status}.`);
|
|
112
78
|
if (!retryableStatus(response.status))
|
|
@@ -141,92 +107,16 @@ export class OpenRouterAudioTranscriber {
|
|
|
141
107
|
return this.options.endpoint?.trim() || DEFAULT_ENDPOINT;
|
|
142
108
|
}
|
|
143
109
|
timeoutMs() {
|
|
144
|
-
return boundedInteger(this.options.timeoutMs, envNumber(this.env, "ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_TIMEOUT_MS", "OPENROUTER_AUDIO_TRANSCRIPTION_TIMEOUT_MS"),
|
|
110
|
+
return boundedInteger(this.options.timeoutMs, envNumber(this.env, "ASSEMBLY_LINE_AUDIO_TRANSCRIPTION_TIMEOUT_MS", "OPENROUTER_AUDIO_TRANSCRIPTION_TIMEOUT_MS"), DEFAULT_AUDIO_TIMEOUT_MS, 5_000, 180_000);
|
|
145
111
|
}
|
|
146
112
|
maxResponseBytes() {
|
|
147
|
-
return boundedInteger(this.options.maxResponseBytes, undefined,
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function failedContext(input, error) {
|
|
151
|
-
return {
|
|
152
|
-
audioTranscriptions: [{
|
|
153
|
-
status: "failed",
|
|
154
|
-
source: "untrusted_user_audio",
|
|
155
|
-
attachmentId: stringValue(input.attachment.id) || input.filename,
|
|
156
|
-
filename: input.filename,
|
|
157
|
-
mimeType: input.mimeType,
|
|
158
|
-
error
|
|
159
|
-
}]
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function audioFormat(filename, mimeType) {
|
|
163
|
-
const extension = filename.toLowerCase().split(".").at(-1) ?? "";
|
|
164
|
-
if (["wav", "mp3", "flac", "m4a", "ogg", "webm", "aac"].includes(extension))
|
|
165
|
-
return extension;
|
|
166
|
-
if (extension === "mp4")
|
|
167
|
-
return "m4a";
|
|
168
|
-
const normalized = mimeType.toLowerCase().split(";")[0]?.trim();
|
|
169
|
-
if (normalized === "audio/wav" || normalized === "audio/x-wav")
|
|
170
|
-
return "wav";
|
|
171
|
-
if (normalized === "audio/mpeg" || normalized === "audio/mp3")
|
|
172
|
-
return "mp3";
|
|
173
|
-
if (normalized === "audio/flac")
|
|
174
|
-
return "flac";
|
|
175
|
-
if (normalized === "audio/mp4" || normalized === "audio/x-m4a")
|
|
176
|
-
return "m4a";
|
|
177
|
-
if (normalized === "audio/ogg")
|
|
178
|
-
return "ogg";
|
|
179
|
-
if (normalized === "audio/webm")
|
|
180
|
-
return "webm";
|
|
181
|
-
if (normalized === "audio/aac")
|
|
182
|
-
return "aac";
|
|
183
|
-
throw new Error(`Unsupported voice-note format: ${mimeType || filename || "unknown"}.`);
|
|
184
|
-
}
|
|
185
|
-
async function readJson(response, maxBytes) {
|
|
186
|
-
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
187
|
-
if (bytes.byteLength > maxBytes)
|
|
188
|
-
throw new Error("OpenRouter transcription response was too large.");
|
|
189
|
-
try {
|
|
190
|
-
return JSON.parse(new TextDecoder().decode(bytes));
|
|
191
|
-
}
|
|
192
|
-
catch {
|
|
193
|
-
return {};
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function boundedInteger(first, second, fallback, min, max) {
|
|
197
|
-
for (const value of [first, second]) {
|
|
198
|
-
if (Number.isInteger(value) && value !== undefined && value >= min && value <= max)
|
|
199
|
-
return value;
|
|
113
|
+
return boundedInteger(this.options.maxResponseBytes, undefined, DEFAULT_AUDIO_MAX_RESPONSE_BYTES, 1_024, 2 * 1024 * 1024);
|
|
200
114
|
}
|
|
201
|
-
return fallback;
|
|
202
|
-
}
|
|
203
|
-
function envNumber(env, primary, alias) {
|
|
204
|
-
const raw = env[primary] ?? env[alias];
|
|
205
|
-
if (!raw?.trim())
|
|
206
|
-
return undefined;
|
|
207
|
-
const parsed = Number(raw);
|
|
208
|
-
return Number.isInteger(parsed) ? parsed : undefined;
|
|
209
115
|
}
|
|
210
116
|
function splitModels(value) {
|
|
211
117
|
return value?.split(",").map((model) => model.trim()).filter(Boolean) ?? [];
|
|
212
118
|
}
|
|
213
|
-
function retryableStatus(status) {
|
|
214
|
-
return status === 408 || status === 409 || status === 425 || status === 429 || status >= 500;
|
|
215
|
-
}
|
|
216
119
|
function stripOpenRouterPrefix(model) {
|
|
217
120
|
return model.trim().replace(/^openrouter\//u, "");
|
|
218
121
|
}
|
|
219
|
-
function safeError(error) {
|
|
220
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
221
|
-
if (/not configured|unsupported|empty|unavailable|size limit|exceeded|HTTP \d{3}|too large/iu.test(message)) {
|
|
222
|
-
return message.slice(0, 240);
|
|
223
|
-
}
|
|
224
|
-
return "Voice transcription failed before the agent turn started.";
|
|
225
|
-
}
|
|
226
|
-
function stringValue(value) {
|
|
227
|
-
return typeof value === "string" ? value.trim() : "";
|
|
228
|
-
}
|
|
229
|
-
function isRecord(value) {
|
|
230
|
-
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
231
|
-
}
|
|
232
122
|
//# sourceMappingURL=openrouter.js.map
|
package/dist/openrouter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openrouter.js","sourceRoot":"","sources":["../src/openrouter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"openrouter.js","sourceRoot":"","sources":["../src/openrouter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,yBAAyB,EACzB,6BAA6B,EAC7B,uBAAuB,EACvB,gCAAgC,EAChC,wBAAwB,EACxB,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EACjB,QAAQ,EACR,aAAa,EACb,oBAAoB,EACpB,QAAQ,EACR,eAAe,EACf,cAAc,EACd,WAAW,EAEZ,MAAM,aAAa,CAAC;AAErB,MAAM,gBAAgB,GAAG,mDAAmD,CAAC;AAC7E,MAAM,aAAa,GAAG,+BAA+B,CAAC;AACtD,MAAM,uBAAuB,GAAG,CAAC,yBAAyB,EAAE,kBAAkB,CAAC,CAAC;AAWhF,MAAM,OAAO,0BAA0B;IAC5B,EAAE,GAAG,gCAAgC,CAAC;IACtC,cAAc,CAAS;IACvB,QAAQ,CAAS;IACT,OAAO,CAAoC;IAC3C,GAAG,CAAqC;IACxC,KAAK,CAAe;IAErC,YAAY,QAIR,EA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AAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACvH,CAAC;IAEO,QAAQ;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,uCAAuC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACzG,CAAC;IAEO,QAAQ;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,gBAAgB,CAAC;IAC3D,CAAC;IAEO,SAAS;QACf,OAAO,cAAc,CACnB,IAAI,CAAC,OAAO,CAAC,SAAS,EACtB,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,8CAA8C,EAAE,2CAA2C,CAAC,EAChH,wBAAwB,EACxB,KAAK,EACL,OAAO,CACR,CAAC;IACJ,CAAC;IAEO,gBAAgB;QACtB,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,SAAS,EAAE,gCAAgC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IAC5H,CAAC;CACF;AAED,SAAS,WAAW,CAAC,KAAyB;IAC5C,OAAO,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;AAC9E,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAa;IAC1C,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AACpD,CAAC"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { JsonObject } from "@assemblyline-agents/core";
|
|
2
|
+
import type { MediaProcessorAttachment, MediaProcessorInput, MediaProcessorResult } from "@assemblyline-agents/runtime";
|
|
3
|
+
export declare const DEFAULT_AUDIO_TIMEOUT_MS = 60000;
|
|
4
|
+
export declare const DEFAULT_AUDIO_MAX_RESPONSE_BYTES: number;
|
|
5
|
+
export declare const DEFAULT_AUDIO_MAX_BYTES: number;
|
|
6
|
+
export declare const DEFAULT_AUDIO_MAX_ATTACHMENTS = 4;
|
|
7
|
+
export declare const CAF_PREPROCESSING_VERSION = "caf-to-m4a-v1";
|
|
8
|
+
export interface CommonAudioTranscriberOptions {
|
|
9
|
+
model?: string;
|
|
10
|
+
fallbackModels?: string[];
|
|
11
|
+
language?: string;
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
modelMetadataKey?: string;
|
|
14
|
+
maxBytes?: number;
|
|
15
|
+
maxAttachments?: number;
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
maxResponseBytes?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function audioAttachmentMatches(input: MediaProcessorAttachment): boolean;
|
|
20
|
+
export declare function preparedAudio(input: MediaProcessorInput, maxBytes: number, timeoutMs: number): Promise<{
|
|
21
|
+
bytes: Uint8Array;
|
|
22
|
+
format: string;
|
|
23
|
+
filename: string;
|
|
24
|
+
mimeType: string;
|
|
25
|
+
}>;
|
|
26
|
+
export declare function processedAudioResult(input: MediaProcessorInput, provider: string, result: {
|
|
27
|
+
text: string;
|
|
28
|
+
model: string;
|
|
29
|
+
}): MediaProcessorResult;
|
|
30
|
+
export declare function failedAudioResult(input: MediaProcessorAttachment, provider: string, error: string): MediaProcessorResult;
|
|
31
|
+
export declare function failedAudioContext(input: MediaProcessorAttachment, error: string): JsonObject;
|
|
32
|
+
export declare function readJson(response: Response, maxBytes: number, provider: string): Promise<unknown>;
|
|
33
|
+
export declare function boundedInteger(first: number | undefined, second: number | undefined, fallback: number, min: number, max: number): number;
|
|
34
|
+
export declare function envNumber(env: Record<string, string | undefined>, primary: string, alias: string): number | undefined;
|
|
35
|
+
export declare function retryableStatus(status: number): boolean;
|
|
36
|
+
export declare function safeAudioError(error: unknown): string;
|
|
37
|
+
export declare function stringValue(value: unknown): string;
|
|
38
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
39
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EACV,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,8BAA8B,CAAC;AAGtC,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAC/C,eAAO,MAAM,gCAAgC,QAAa,CAAC;AAC3D,eAAO,MAAM,uBAAuB,QAAmB,CAAC;AACxD,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAC/C,eAAO,MAAM,yBAAyB,kBAAkB,CAAC;AAEzD,MAAM,WAAW,6BAA6B;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAI/E;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,mBAAmB,EAC1B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IA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
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { convertCafToM4a, isCafAudio } from "./caf.js";
|
|
2
|
+
export const DEFAULT_AUDIO_TIMEOUT_MS = 60_000;
|
|
3
|
+
export const DEFAULT_AUDIO_MAX_RESPONSE_BYTES = 512 * 1024;
|
|
4
|
+
export const DEFAULT_AUDIO_MAX_BYTES = 25 * 1024 * 1024;
|
|
5
|
+
export const DEFAULT_AUDIO_MAX_ATTACHMENTS = 4;
|
|
6
|
+
export const CAF_PREPROCESSING_VERSION = "caf-to-m4a-v1";
|
|
7
|
+
export function audioAttachmentMatches(input) {
|
|
8
|
+
if (input.mimeType.startsWith("audio/"))
|
|
9
|
+
return true;
|
|
10
|
+
if (stringValue(input.attachment.kind).toLowerCase() === "audio")
|
|
11
|
+
return true;
|
|
12
|
+
return /\.(?:aac|caf|flac|m4a|mp3|mp4|mpeg|mpga|ogg|wav|webm)$/iu.test(input.filename);
|
|
13
|
+
}
|
|
14
|
+
export async function preparedAudio(input, maxBytes, timeoutMs) {
|
|
15
|
+
if (!isCafAudio(input.filename, input.mimeType)) {
|
|
16
|
+
return {
|
|
17
|
+
bytes: input.bytes,
|
|
18
|
+
format: audioFormat(input.filename, input.mimeType),
|
|
19
|
+
filename: input.filename,
|
|
20
|
+
mimeType: input.mimeType
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
bytes: await convertCafToM4a(input.bytes, { maxBytes, timeoutMs }),
|
|
25
|
+
format: "m4a",
|
|
26
|
+
filename: `${input.filename.replace(/\.caf$/iu, "") || "voice-note"}.m4a`,
|
|
27
|
+
mimeType: "audio/mp4"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function processedAudioResult(input, provider, result) {
|
|
31
|
+
return {
|
|
32
|
+
status: "processed",
|
|
33
|
+
context: {
|
|
34
|
+
audioTranscriptions: [{
|
|
35
|
+
status: "transcribed",
|
|
36
|
+
source: "untrusted_user_audio",
|
|
37
|
+
attachmentId: stringValue(input.attachment.id) || input.filename,
|
|
38
|
+
filename: input.filename,
|
|
39
|
+
mimeType: input.mimeType,
|
|
40
|
+
model: result.model,
|
|
41
|
+
text: result.text
|
|
42
|
+
}]
|
|
43
|
+
},
|
|
44
|
+
audit: {
|
|
45
|
+
provider,
|
|
46
|
+
model: result.model,
|
|
47
|
+
sourceSize: input.bytes.byteLength
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function failedAudioResult(input, provider, error) {
|
|
52
|
+
return {
|
|
53
|
+
status: "failed",
|
|
54
|
+
context: failedAudioContext(input, error),
|
|
55
|
+
audit: { provider, reason: error }
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function failedAudioContext(input, error) {
|
|
59
|
+
return {
|
|
60
|
+
audioTranscriptions: [{
|
|
61
|
+
status: "failed",
|
|
62
|
+
source: "untrusted_user_audio",
|
|
63
|
+
attachmentId: stringValue(input.attachment.id) || input.filename,
|
|
64
|
+
filename: input.filename,
|
|
65
|
+
mimeType: input.mimeType,
|
|
66
|
+
error
|
|
67
|
+
}]
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export async function readJson(response, maxBytes, provider) {
|
|
71
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
72
|
+
if (bytes.byteLength > maxBytes)
|
|
73
|
+
throw new Error(`${provider} transcription response was too large.`);
|
|
74
|
+
try {
|
|
75
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export function boundedInteger(first, second, fallback, min, max) {
|
|
82
|
+
for (const value of [first, second]) {
|
|
83
|
+
if (Number.isInteger(value) && value !== undefined && value >= min && value <= max)
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
return fallback;
|
|
87
|
+
}
|
|
88
|
+
export function envNumber(env, primary, alias) {
|
|
89
|
+
const raw = env[primary] ?? env[alias];
|
|
90
|
+
if (!raw?.trim())
|
|
91
|
+
return undefined;
|
|
92
|
+
const parsed = Number(raw);
|
|
93
|
+
return Number.isInteger(parsed) ? parsed : undefined;
|
|
94
|
+
}
|
|
95
|
+
export function retryableStatus(status) {
|
|
96
|
+
return status === 408 || status === 409 || status === 425 || status === 429 || status >= 500;
|
|
97
|
+
}
|
|
98
|
+
export function safeAudioError(error) {
|
|
99
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
100
|
+
if (/not configured|unsupported|empty|unavailable|size limit|exceeded|HTTP \d{3}|too large/iu.test(message)) {
|
|
101
|
+
return message.slice(0, 240);
|
|
102
|
+
}
|
|
103
|
+
return "Voice transcription failed before the agent turn started.";
|
|
104
|
+
}
|
|
105
|
+
export function stringValue(value) {
|
|
106
|
+
return typeof value === "string" ? value.trim() : "";
|
|
107
|
+
}
|
|
108
|
+
export function isRecord(value) {
|
|
109
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
110
|
+
}
|
|
111
|
+
function audioFormat(filename, mimeType) {
|
|
112
|
+
const extension = filename.toLowerCase().split(".").at(-1) ?? "";
|
|
113
|
+
if (["wav", "mp3", "flac", "m4a", "ogg", "webm", "aac", "mpeg", "mpga"].includes(extension))
|
|
114
|
+
return extension;
|
|
115
|
+
if (extension === "mp4")
|
|
116
|
+
return "m4a";
|
|
117
|
+
const normalized = mimeType.toLowerCase().split(";")[0]?.trim();
|
|
118
|
+
if (normalized === "audio/wav" || normalized === "audio/x-wav")
|
|
119
|
+
return "wav";
|
|
120
|
+
if (normalized === "audio/mpeg" || normalized === "audio/mp3")
|
|
121
|
+
return "mp3";
|
|
122
|
+
if (normalized === "audio/flac")
|
|
123
|
+
return "flac";
|
|
124
|
+
if (normalized === "audio/mp4" || normalized === "audio/x-m4a")
|
|
125
|
+
return "m4a";
|
|
126
|
+
if (normalized === "audio/ogg")
|
|
127
|
+
return "ogg";
|
|
128
|
+
if (normalized === "audio/webm")
|
|
129
|
+
return "webm";
|
|
130
|
+
if (normalized === "audio/aac")
|
|
131
|
+
return "aac";
|
|
132
|
+
throw new Error(`Unsupported voice-note format: ${mimeType || filename || "unknown"}.`);
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEvD,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAC/C,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAG,GAAG,IAAI,CAAC;AAC3D,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACxD,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,yBAAyB,GAAG,eAAe,CAAC;AAczD,MAAM,UAAU,sBAAsB,CAAC,KAA+B;IACpE,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACrD,IAAI,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAC9E,OAAO,0DAA0D,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACzF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAA0B,EAC1B,QAAgB,EAChB,SAAiB;IAEjB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChD,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;YACn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
|
@@ -13,12 +13,14 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"ffmpeg-static": "^5.3.0",
|
|
16
|
-
"@assemblyline-agents/core": "
|
|
17
|
-
"@assemblyline-agents/runtime": "
|
|
16
|
+
"@assemblyline-agents/core": "6.0.0",
|
|
17
|
+
"@assemblyline-agents/runtime": "6.0.0"
|
|
18
18
|
},
|
|
19
19
|
"description": "Pre-model audio processing adapters for Assembly Line agents.",
|
|
20
20
|
"files": [
|
|
21
|
-
"dist"
|
|
21
|
+
"dist",
|
|
22
|
+
"plugin.json",
|
|
23
|
+
"ai.assemblyline"
|
|
22
24
|
],
|
|
23
25
|
"license": "MIT",
|
|
24
26
|
"repository": {
|
|
@@ -36,6 +38,7 @@
|
|
|
36
38
|
"agents",
|
|
37
39
|
"audio",
|
|
38
40
|
"speech-to-text",
|
|
41
|
+
"openai",
|
|
39
42
|
"openrouter"
|
|
40
43
|
],
|
|
41
44
|
"publishConfig": {
|